if_edsc.c (167896) | if_edsc.c (241610) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * From: @(#)if_loop.c 8.1 (Berkeley) 6/10/93 | 1/*- 2 * Copyright (c) 1982, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * From: @(#)if_loop.c 8.1 (Berkeley) 6/10/93 |
30 * $FreeBSD: head/sys/net/if_edsc.c 167896 2007-03-26 09:05:10Z yar $ | 30 * $FreeBSD: head/sys/net/if_edsc.c 241610 2012-10-16 13:37:54Z glebius $ |
31 */ 32 33/* 34 * Discard interface driver for protocol testing and timing. 35 * Mimics an Ethernet device so that VLANs can be attached to it etc. 36 */ 37 38#include <sys/param.h> /* types, important constants */ --- 7 unchanged lines hidden (view full) --- 46 47#include <net/bpf.h> /* bpf(9) */ 48#include <net/ethernet.h> /* Ethernet related constants and types */ 49#include <net/if.h> /* basic part of ifnet(9) */ 50#include <net/if_clone.h> /* network interface cloning */ 51#include <net/if_types.h> /* IFT_ETHER and friends */ 52#include <net/if_var.h> /* kernel-only part of ifnet(9) */ 53 | 31 */ 32 33/* 34 * Discard interface driver for protocol testing and timing. 35 * Mimics an Ethernet device so that VLANs can be attached to it etc. 36 */ 37 38#include <sys/param.h> /* types, important constants */ --- 7 unchanged lines hidden (view full) --- 46 47#include <net/bpf.h> /* bpf(9) */ 48#include <net/ethernet.h> /* Ethernet related constants and types */ 49#include <net/if.h> /* basic part of ifnet(9) */ 50#include <net/if_clone.h> /* network interface cloning */ 51#include <net/if_types.h> /* IFT_ETHER and friends */ 52#include <net/if_var.h> /* kernel-only part of ifnet(9) */ 53 |
54static const char edscname[] = "edsc"; 55 |
|
54/* 55 * Software configuration of an interface specific to this device type. 56 */ 57struct edsc_softc { 58 struct ifnet *sc_ifp; /* ptr to generic interface configuration */ 59 60 /* 61 * A non-null driver can keep various things here, for instance, 62 * the hardware revision, cached values of write-only registers, etc. 63 */ 64}; 65 66/* | 56/* 57 * Software configuration of an interface specific to this device type. 58 */ 59struct edsc_softc { 60 struct ifnet *sc_ifp; /* ptr to generic interface configuration */ 61 62 /* 63 * A non-null driver can keep various things here, for instance, 64 * the hardware revision, cached values of write-only registers, etc. 65 */ 66}; 67 68/* |
67 * Simple cloning methods. 68 * IFC_SIMPLE_DECLARE() expects precisely these names. | 69 * Attach to the interface cloning framework. |
69 */ | 70 */ |
71static struct if_clone *edsc_cloner; |
|
70static int edsc_clone_create(struct if_clone *, int, caddr_t); 71static void edsc_clone_destroy(struct ifnet *); 72 73/* 74 * Interface driver methods. 75 */ 76static void edsc_init(void *dummy); 77/* static void edsc_input(struct ifnet *ifp, struct mbuf *m); would be here */ 78static int edsc_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); 79static void edsc_start(struct ifnet *ifp); 80 81/* 82 * We'll allocate softc instances from this. 83 */ | 72static int edsc_clone_create(struct if_clone *, int, caddr_t); 73static void edsc_clone_destroy(struct ifnet *); 74 75/* 76 * Interface driver methods. 77 */ 78static void edsc_init(void *dummy); 79/* static void edsc_input(struct ifnet *ifp, struct mbuf *m); would be here */ 80static int edsc_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); 81static void edsc_start(struct ifnet *ifp); 82 83/* 84 * We'll allocate softc instances from this. 85 */ |
84static MALLOC_DEFINE(M_EDSC, "edsc", "Ethernet discard interface"); | 86static MALLOC_DEFINE(M_EDSC, edscname, "Ethernet discard interface"); |
85 86/* | 87 88/* |
87 * Attach to the interface cloning framework under the name of "edsc". 88 * The second argument is the number of units to be created from 89 * the outset. It's also the minimum number of units allowed. 90 * We don't want any units created as soon as the driver is loaded. 91 */ 92IFC_SIMPLE_DECLARE(edsc, 0); 93 94/* | |
95 * Create an interface instance. 96 */ 97static int 98edsc_clone_create(struct if_clone *ifc, int unit, caddr_t params) 99{ 100 struct edsc_softc *sc; 101 struct ifnet *ifp; 102 static u_char eaddr[ETHER_ADDR_LEN]; /* 0:0:0:0:0:0 */ --- 8 unchanged lines hidden (view full) --- 111 return (ENOSPC); 112 } 113 114 ifp->if_softc = sc; 115 116 /* 117 * Get a name for this particular interface in its ifnet structure. 118 */ | 89 * Create an interface instance. 90 */ 91static int 92edsc_clone_create(struct if_clone *ifc, int unit, caddr_t params) 93{ 94 struct edsc_softc *sc; 95 struct ifnet *ifp; 96 static u_char eaddr[ETHER_ADDR_LEN]; /* 0:0:0:0:0:0 */ --- 8 unchanged lines hidden (view full) --- 105 return (ENOSPC); 106 } 107 108 ifp->if_softc = sc; 109 110 /* 111 * Get a name for this particular interface in its ifnet structure. 112 */ |
119 if_initname(ifp, ifc->ifc_name, unit); | 113 if_initname(ifp, edscname, unit); |
120 121 /* 122 * Typical Ethernet interface flags: we can do broadcast and 123 * multicast but can't hear our own broadcasts or multicasts. 124 */ 125 ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX; 126 127 /* --- 190 unchanged lines hidden (view full) --- 318static int 319edsc_modevent(module_t mod, int type, void *data) 320{ 321 322 switch (type) { 323 case MOD_LOAD: 324 /* 325 * Connect to the network interface cloning framework. | 114 115 /* 116 * Typical Ethernet interface flags: we can do broadcast and 117 * multicast but can't hear our own broadcasts or multicasts. 118 */ 119 ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX; 120 121 /* --- 190 unchanged lines hidden (view full) --- 312static int 313edsc_modevent(module_t mod, int type, void *data) 314{ 315 316 switch (type) { 317 case MOD_LOAD: 318 /* 319 * Connect to the network interface cloning framework. |
320 * The last argument is the number of units to be created 321 * from the outset. It's also the minimum number of units 322 * allowed. We don't want any units created as soon as the 323 * driver is loaded. |
|
326 */ | 324 */ |
327 if_clone_attach(&edsc_cloner); | 325 edsc_cloner = if_clone_simple(edscname, edsc_clone_create, 326 edsc_clone_destroy, 0); |
328 break; 329 330 case MOD_UNLOAD: 331 /* 332 * Disconnect from the cloning framework. 333 * Existing interfaces will be disposed of properly. 334 */ | 327 break; 328 329 case MOD_UNLOAD: 330 /* 331 * Disconnect from the cloning framework. 332 * Existing interfaces will be disposed of properly. 333 */ |
335 if_clone_detach(&edsc_cloner); | 334 if_clone_detach(edsc_cloner); |
336 break; 337 338 default: 339 /* 340 * There are other event types, but we don't handle them. 341 * See module(9). 342 */ 343 return (EOPNOTSUPP); 344 } 345 return (0); 346} 347 348static moduledata_t edsc_mod = { 349 "if_edsc", /* name */ 350 edsc_modevent, /* event handler */ 351 NULL /* additional data */ 352}; 353 354DECLARE_MODULE(if_edsc, edsc_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); | 335 break; 336 337 default: 338 /* 339 * There are other event types, but we don't handle them. 340 * See module(9). 341 */ 342 return (EOPNOTSUPP); 343 } 344 return (0); 345} 346 347static moduledata_t edsc_mod = { 348 "if_edsc", /* name */ 349 edsc_modevent, /* event handler */ 350 NULL /* additional data */ 351}; 352 353DECLARE_MODULE(if_edsc, edsc_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); |