Deleted Added
full compact
0a1
> /* $FreeBSD: head/sys/contrib/pf/net/if_pfsync.c 126261 2004-02-26 02:34:12Z mlaier $ */
28a30,35
> #if defined(__FreeBSD__) && __FreeBSD__ >= 5
> #include "opt_inet.h"
> #include "opt_inet6.h"
> #endif
>
> #if !defined(__FreeBSD__)
30a38,43
> #elif __FreeBSD__ >= 5
> #include "opt_bpf.h"
> #define NBPFILTER DEV_BPF
> #include "opt_pf.h"
> #define NPFSYNC DEV_PFSYNC
> #endif
36a50,54
> #if defined(__FreeBSD__)
> #include <sys/kernel.h>
> #include <sys/malloc.h>
> #include <sys/sockio.h>
> #else
38a57
> #endif
59a79,82
> #if defined(__FreeBSD__)
> #define PFSYNCNAME "pfsync"
> #endif
>
69a93
> #if !defined(__FreeBSD__)
70a95
> #endif
71a97,100
> #if defined(__FreeBSD__)
> void pfsync_clone_destroy(struct ifnet *);
> int pfsync_clone_create(struct if_clone *, int);
> #else
72a102
> #endif
82a113
> #if !defined(__FreeBSD__)
83a115
> #endif
84a117,122
> #if defined(__FreeBSD__)
> static MALLOC_DEFINE(M_PFSYNC, PFSYNCNAME, "Packet Filter State Sync. Interface");
> static LIST_HEAD(pfsync_list, pfsync_softc) pfsync_list;
> struct if_clone pfsync_cloner = IF_CLONE_INITIALIZER(PFSYNCNAME,
> pfsync_clone_create, pfsync_clone_destroy, 1, IF_MAXUNIT);
>
85a124,186
> pfsync_clone_destroy(struct ifnet *ifp)
> {
> struct pfsync_softc *sc;
>
> sc = ifp->if_softc;
> callout_stop(&sc->sc_tmo);
>
> /*
> * Does we really need this?
> */
> IF_DRAIN(&ifp->if_snd);
>
> #if NBPFILTER > 0
> bpfdetach(ifp);
> #endif
> if_detach(ifp);
> LIST_REMOVE(sc, sc_next);
> free(sc, M_PFSYNC);
> }
> #endif /* __FreeBSD__ */
>
> #if defined(__FreeBSD__)
> int
> pfsync_clone_create(struct if_clone *ifc, int unit)
> {
> struct pfsync_softc *sc;
>
> MALLOC(sc, struct pfsync_softc *, sizeof(*sc), M_PFSYNC,
> M_WAITOK|M_ZERO);
>
> sc->sc_count = 8;
> #if (__FreeBSD_version < 501113)
> sc->sc_if.if_name = PFSYNCNAME;
> sc->sc_if.if_unit = unit;
> #else
> if_initname(&sc->sc_if, ifc->ifc_name, unit);
> #endif
> sc->sc_if.if_ioctl = pfsyncioctl;
> sc->sc_if.if_output = pfsyncoutput;
> sc->sc_if.if_start = pfsyncstart;
> sc->sc_if.if_type = IFT_PFSYNC;
> sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen;
> sc->sc_if.if_hdrlen = PFSYNC_HDRLEN;
> sc->sc_if.if_baudrate = IF_Mbps(100);
> sc->sc_if.if_softc = sc;
> pfsync_setmtu(sc, MCLBYTES);
> /*
> * XXX
> * The 2nd arg. 0 to callout_init(9) shoule be set to CALLOUT_MPSAFE
> * if Gaint lock is removed from the network stack.
> */
> callout_init(&sc->sc_tmo, 0);
> if_attach(&sc->sc_if);
>
> LIST_INSERT_HEAD(&pfsync_list, sc, sc_next);
> #if NBPFILTER > 0
> bpfattach(&sc->sc_if, DLT_PFSYNC, PFSYNC_HDRLEN);
> #endif
>
> return (0);
> }
> #else /* !__FreeBSD__ */
> void
111a213
> #endif
119a222,226
> #if defined(__FreeBSD__) && defined(ALTQ)
> struct ifaltq *ifq;
> #else
> struct ifqueue *ifq;
> #endif
121a229,231
> #if defined(__FreeBSD__)
> ifq = &ifp->if_snd;
> #endif
123a234,239
> #if defined(__FreeBSD__)
> IF_LOCK(ifq);
> _IF_DROP(ifq);
> _IF_DEQUEUE(ifq, m);
> IF_UNLOCK(ifq);
> #else
125a242
> #endif
194a312
> #if !defined(__FreeBSD__)
195a314
> #endif
225a345,348
> #if defined(__FreeBSD__)
> callout_reset(&sc->sc_tmo, hz, pfsync_timeout,
> LIST_FIRST(&pfsync_list));
> #else
226a350
> #endif
230a355,358
> /*
> * XXX: This function should be called with PF_LOCK held as it references
> * pf_state.
> */
235a364,366
> #if defined(__FreeBSD__)
> struct pfsync_softc *sc = LIST_FIRST(&pfsync_list);
> #else
238a370
> #endif
248a381,390
> #if defined(__FreeBSD__)
> /*
> * XXX
> * If we need to check mutex owned, PF_LOCK should be
> * declared in pflog.ko. :-(
> *
> * PF_LOCK_ASSERT();
> */
> KASSERT((!LIST_EMPTY(&pfsync_list)), ("pfsync: no interface"));
> #endif
280a423,425
> #if defined(__FreeBSD__)
> secs = time_second;
> #else
281a427
> #endif
312a459,461
> #if defined(__FreeBSD__)
> struct pfsync_softc *sc = LIST_FIRST(&pfsync_list);
> #else
314a464
> #endif
334a485
> /* We don't need PF_LOCK/PF_UNLOCK here! */
346a498,500
> #if defined(__FreeBSD__)
> callout_stop(&sc->sc_tmo);
> #else
347a502
> #endif
350a506,508
> #if defined(__FreeBSD__)
> KASSERT(m != NULL, ("pfsync_sendout: null mbuf"));
> #endif
359a518,558
>
>
> #if defined(__FreeBSD__)
> static int
> pfsync_modevent(module_t mod, int type, void *data)
> {
> int error = 0;
>
> switch (type) {
> case MOD_LOAD:
> LIST_INIT(&pfsync_list);
> if_clone_attach(&pfsync_cloner);
> printf("pfsync: $Name: $\n");
> break;
>
> case MOD_UNLOAD:
> if_clone_detach(&pfsync_cloner);
> while (!LIST_EMPTY(&pfsync_list))
> pfsync_clone_destroy(
> &LIST_FIRST(&pfsync_list)->sc_if);
> break;
>
> default:
> error = EINVAL;
> break;
> }
>
> return error;
> }
>
> static moduledata_t pfsync_mod = {
> "pfsync",
> pfsync_modevent,
> 0
> };
>
> #define PFSYNC_MODVER 1
>
> DECLARE_MODULE(pfsync, pfsync_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
> MODULE_VERSION(pfsync, PFSYNC_MODVER);
> #endif /* __FreeBSD__ */