diff options
Diffstat (limited to 'freebsd/sys/net/if_edsc.c')
-rw-r--r-- | freebsd/sys/net/if_edsc.c | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/freebsd/sys/net/if_edsc.c b/freebsd/sys/net/if_edsc.c index 6bb80fdb..d90f072a 100644 --- a/freebsd/sys/net/if_edsc.c +++ b/freebsd/sys/net/if_edsc.c @@ -48,10 +48,14 @@ #include <net/bpf.h> /* bpf(9) */ #include <net/ethernet.h> /* Ethernet related constants and types */ -#include <net/if.h> /* basic part of ifnet(9) */ +#include <net/if.h> +#include <net/if_var.h> /* basic part of ifnet(9) */ #include <net/if_clone.h> /* network interface cloning */ #include <net/if_types.h> /* IFT_ETHER and friends */ #include <net/if_var.h> /* kernel-only part of ifnet(9) */ +#include <net/vnet.h> + +static const char edscname[] = "edsc"; /* * Software configuration of an interface specific to this device type. @@ -66,9 +70,10 @@ struct edsc_softc { }; /* - * Simple cloning methods. - * IFC_SIMPLE_DECLARE() expects precisely these names. + * Attach to the interface cloning framework. */ +static VNET_DEFINE(struct if_clone *, edsc_cloner); +#define V_edsc_cloner VNET(edsc_cloner) static int edsc_clone_create(struct if_clone *, int, caddr_t); static void edsc_clone_destroy(struct ifnet *); @@ -83,15 +88,7 @@ static void edsc_start(struct ifnet *ifp); /* * We'll allocate softc instances from this. */ -static MALLOC_DEFINE(M_EDSC, "edsc", "Ethernet discard interface"); - -/* - * Attach to the interface cloning framework under the name of "edsc". - * The second argument is the number of units to be created from - * the outset. It's also the minimum number of units allowed. - * We don't want any units created as soon as the driver is loaded. - */ -IFC_SIMPLE_DECLARE(edsc, 0); +static MALLOC_DEFINE(M_EDSC, edscname, "Ethernet discard interface"); /* * Create an interface instance. @@ -118,7 +115,7 @@ edsc_clone_create(struct if_clone *ifc, int unit, caddr_t params) /* * Get a name for this particular interface in its ifnet structure. */ - if_initname(ifp, ifc->ifc_name, unit); + if_initname(ifp, edscname, unit); /* * Typical Ethernet interface flags: we can do broadcast and @@ -298,8 +295,8 @@ edsc_start(struct ifnet *ifp) /* * Update the interface counters. */ - ifp->if_obytes += m->m_pkthdr.len; - ifp->if_opackets++; + if_inc_counter(ifp, IFCOUNTER_OBYTES, m->m_pkthdr.len); + if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); /* * Finally, just drop the packet. @@ -314,6 +311,36 @@ edsc_start(struct ifnet *ifp) */ } +static void +vnet_edsc_init(const void *unused __unused) +{ + + /* + * Connect to the network interface cloning framework. + * The last argument is the number of units to be created + * from the outset. It's also the minimum number of units + * allowed. We don't want any units created as soon as the + * driver is loaded. + */ + V_edsc_cloner = if_clone_simple(edscname, edsc_clone_create, + edsc_clone_destroy, 0); +} +VNET_SYSINIT(vnet_edsc_init, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY, + vnet_edsc_init, NULL); + +static void +vnet_edsc_uninit(const void *unused __unused) +{ + + /* + * Disconnect from the cloning framework. + * Existing interfaces will be disposed of properly. + */ + if_clone_detach(V_edsc_cloner); +} +VNET_SYSUNINIT(vnet_edsc_uninit, SI_SUB_INIT_IF, SI_ORDER_ANY, + vnet_edsc_uninit, NULL); + /* * This function provides handlers for module events, namely load and unload. */ @@ -323,20 +350,8 @@ edsc_modevent(module_t mod, int type, void *data) switch (type) { case MOD_LOAD: - /* - * Connect to the network interface cloning framework. - */ - if_clone_attach(&edsc_cloner); - break; - case MOD_UNLOAD: - /* - * Disconnect from the cloning framework. - * Existing interfaces will be disposed of properly. - */ - if_clone_detach(&edsc_cloner); break; - default: /* * There are other event types, but we don't handle them. |