1 2/* 3 * ng_ether.c 4 * 5 * Copyright (c) 1996-2000 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and 9 * redistribution of this software, in source or object code forms, with or 10 * without modifications are expressly permitted by Whistle Communications; 11 * provided, however, that: 12 * 1. Any and all reproductions of the source or object code must include the 13 * copyright notice above and the following disclaimer of warranties; and 14 * 2. No rights are granted, in any manner or form, to use Whistle 15 * Communications, Inc. trademarks, including the mark "WHISTLE 16 * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 17 * such appears in the above copyright notice or in the software. 18 * 19 * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 20 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 21 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 22 * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 24 * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 25 * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 26 * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 27 * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 28 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Authors: Archie Cobbs <archie@freebsd.org> 38 * Julian Elischer <julian@freebsd.org> 39 *
| 1 2/* 3 * ng_ether.c 4 * 5 * Copyright (c) 1996-2000 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and 9 * redistribution of this software, in source or object code forms, with or 10 * without modifications are expressly permitted by Whistle Communications; 11 * provided, however, that: 12 * 1. Any and all reproductions of the source or object code must include the 13 * copyright notice above and the following disclaimer of warranties; and 14 * 2. No rights are granted, in any manner or form, to use Whistle 15 * Communications, Inc. trademarks, including the mark "WHISTLE 16 * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 17 * such appears in the above copyright notice or in the software. 18 * 19 * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 20 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 21 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 22 * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 24 * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 25 * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 26 * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 27 * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 28 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Authors: Archie Cobbs <archie@freebsd.org> 38 * Julian Elischer <julian@freebsd.org> 39 *
|
40 * $FreeBSD: head/sys/netgraph/ng_ether.c 128376 2004-04-18 01:15:32Z luigi $
| 40 * $FreeBSD: head/sys/netgraph/ng_ether.c 129281 2004-05-16 19:31:35Z archie $
|
41 */ 42 43/* 44 * ng_ether(4) netgraph node type 45 */ 46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/kernel.h> 50#include <sys/malloc.h> 51#include <sys/mbuf.h> 52#include <sys/errno.h> 53#include <sys/syslog.h> 54#include <sys/socket.h> 55 56#include <net/if.h> 57#include <net/if_types.h> 58#include <net/if_arp.h> 59#include <net/if_var.h> 60#include <net/ethernet.h> 61 62#include <netgraph/ng_message.h> 63#include <netgraph/netgraph.h> 64#include <netgraph/ng_parse.h> 65#include <netgraph/ng_ether.h> 66 67#define IFP2NG(ifp) ((struct ng_node *)((struct arpcom *)(ifp))->ac_netgraph) 68 69/* Per-node private data */ 70struct private { 71 struct ifnet *ifp; /* associated interface */ 72 hook_p upper; /* upper hook connection */
| 41 */ 42 43/* 44 * ng_ether(4) netgraph node type 45 */ 46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/kernel.h> 50#include <sys/malloc.h> 51#include <sys/mbuf.h> 52#include <sys/errno.h> 53#include <sys/syslog.h> 54#include <sys/socket.h> 55 56#include <net/if.h> 57#include <net/if_types.h> 58#include <net/if_arp.h> 59#include <net/if_var.h> 60#include <net/ethernet.h> 61 62#include <netgraph/ng_message.h> 63#include <netgraph/netgraph.h> 64#include <netgraph/ng_parse.h> 65#include <netgraph/ng_ether.h> 66 67#define IFP2NG(ifp) ((struct ng_node *)((struct arpcom *)(ifp))->ac_netgraph) 68 69/* Per-node private data */ 70struct private { 71 struct ifnet *ifp; /* associated interface */ 72 hook_p upper; /* upper hook connection */
|
73 hook_p lower; /* lower OR orphan hook connection */ 74 u_char lowerOrphan; /* whether lower is lower or orphan */
| 73 hook_p lower; /* lower hook connection */ 74 hook_p orphan; /* orphan hook connection */
|
75 u_char autoSrcAddr; /* always overwrite source address */ 76 u_char promisc; /* promiscuous mode enabled */ 77 u_long hwassist; /* hardware checksum capabilities */ 78 u_int flags; /* flags e.g. really die */ 79}; 80typedef struct private *priv_p; 81 82/* Hook pointers used by if_ethersubr.c to callback to netgraph */ 83extern void (*ng_ether_input_p)(struct ifnet *ifp, struct mbuf **mp); 84extern void (*ng_ether_input_orphan_p)(struct ifnet *ifp, struct mbuf *m); 85extern int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp); 86extern void (*ng_ether_attach_p)(struct ifnet *ifp); 87extern void (*ng_ether_detach_p)(struct ifnet *ifp); 88 89/* Functional hooks called from if_ethersubr.c */ 90static void ng_ether_input(struct ifnet *ifp, struct mbuf **mp); 91static void ng_ether_input_orphan(struct ifnet *ifp, struct mbuf *m); 92static int ng_ether_output(struct ifnet *ifp, struct mbuf **mp); 93static void ng_ether_attach(struct ifnet *ifp); 94static void ng_ether_detach(struct ifnet *ifp); 95 96/* Other functions */
| 75 u_char autoSrcAddr; /* always overwrite source address */ 76 u_char promisc; /* promiscuous mode enabled */ 77 u_long hwassist; /* hardware checksum capabilities */ 78 u_int flags; /* flags e.g. really die */ 79}; 80typedef struct private *priv_p; 81 82/* Hook pointers used by if_ethersubr.c to callback to netgraph */ 83extern void (*ng_ether_input_p)(struct ifnet *ifp, struct mbuf **mp); 84extern void (*ng_ether_input_orphan_p)(struct ifnet *ifp, struct mbuf *m); 85extern int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp); 86extern void (*ng_ether_attach_p)(struct ifnet *ifp); 87extern void (*ng_ether_detach_p)(struct ifnet *ifp); 88 89/* Functional hooks called from if_ethersubr.c */ 90static void ng_ether_input(struct ifnet *ifp, struct mbuf **mp); 91static void ng_ether_input_orphan(struct ifnet *ifp, struct mbuf *m); 92static int ng_ether_output(struct ifnet *ifp, struct mbuf **mp); 93static void ng_ether_attach(struct ifnet *ifp); 94static void ng_ether_detach(struct ifnet *ifp); 95 96/* Other functions */
|
97static void ng_ether_input2(node_p node, struct mbuf **mp);
| |
98static int ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta); 99static int ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta); 100 101/* Netgraph node methods */ 102static ng_constructor_t ng_ether_constructor; 103static ng_rcvmsg_t ng_ether_rcvmsg; 104static ng_shutdown_t ng_ether_shutdown; 105static ng_newhook_t ng_ether_newhook; 106static ng_connect_t ng_ether_connect; 107static ng_rcvdata_t ng_ether_rcvdata; 108static ng_disconnect_t ng_ether_disconnect; 109static int ng_ether_mod_event(module_t mod, int event, void *data); 110 111/* List of commands and how to convert arguments to/from ASCII */ 112static const struct ng_cmdlist ng_ether_cmdlist[] = { 113 { 114 NGM_ETHER_COOKIE, 115 NGM_ETHER_GET_IFNAME, 116 "getifname", 117 NULL, 118 &ng_parse_string_type 119 }, 120 { 121 NGM_ETHER_COOKIE, 122 NGM_ETHER_GET_IFINDEX, 123 "getifindex", 124 NULL, 125 &ng_parse_int32_type 126 }, 127 { 128 NGM_ETHER_COOKIE, 129 NGM_ETHER_GET_ENADDR, 130 "getenaddr", 131 NULL, 132 &ng_parse_enaddr_type 133 }, 134 { 135 NGM_ETHER_COOKIE, 136 NGM_ETHER_SET_ENADDR, 137 "setenaddr", 138 &ng_parse_enaddr_type, 139 NULL 140 }, 141 { 142 NGM_ETHER_COOKIE, 143 NGM_ETHER_GET_PROMISC, 144 "getpromisc", 145 NULL, 146 &ng_parse_int32_type 147 }, 148 { 149 NGM_ETHER_COOKIE, 150 NGM_ETHER_SET_PROMISC, 151 "setpromisc", 152 &ng_parse_int32_type, 153 NULL 154 }, 155 { 156 NGM_ETHER_COOKIE, 157 NGM_ETHER_GET_AUTOSRC, 158 "getautosrc", 159 NULL, 160 &ng_parse_int32_type 161 }, 162 { 163 NGM_ETHER_COOKIE, 164 NGM_ETHER_SET_AUTOSRC, 165 "setautosrc", 166 &ng_parse_int32_type, 167 NULL 168 }, 169 { 0 } 170}; 171 172static struct ng_type ng_ether_typestruct = { 173 NG_ABI_VERSION, 174 NG_ETHER_NODE_TYPE, 175 ng_ether_mod_event, 176 ng_ether_constructor, 177 ng_ether_rcvmsg, 178 ng_ether_shutdown, 179 ng_ether_newhook, 180 NULL, 181 ng_ether_connect, 182 ng_ether_rcvdata, 183 ng_ether_disconnect, 184 ng_ether_cmdlist, 185}; 186MODULE_VERSION(ng_ether, 1); 187NETGRAPH_INIT(ether, &ng_ether_typestruct); 188 189/****************************************************************** 190 ETHERNET FUNCTION HOOKS 191******************************************************************/ 192 193/* 194 * Handle a packet that has come in on an interface. We get to 195 * look at it here before any upper layer protocols do. 196 * 197 * NOTE: this function will get called at splimp() 198 */ 199static void 200ng_ether_input(struct ifnet *ifp, struct mbuf **mp) 201{ 202 const node_p node = IFP2NG(ifp); 203 const priv_p priv = NG_NODE_PRIVATE(node);
| 97static int ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta); 98static int ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta); 99 100/* Netgraph node methods */ 101static ng_constructor_t ng_ether_constructor; 102static ng_rcvmsg_t ng_ether_rcvmsg; 103static ng_shutdown_t ng_ether_shutdown; 104static ng_newhook_t ng_ether_newhook; 105static ng_connect_t ng_ether_connect; 106static ng_rcvdata_t ng_ether_rcvdata; 107static ng_disconnect_t ng_ether_disconnect; 108static int ng_ether_mod_event(module_t mod, int event, void *data); 109 110/* List of commands and how to convert arguments to/from ASCII */ 111static const struct ng_cmdlist ng_ether_cmdlist[] = { 112 { 113 NGM_ETHER_COOKIE, 114 NGM_ETHER_GET_IFNAME, 115 "getifname", 116 NULL, 117 &ng_parse_string_type 118 }, 119 { 120 NGM_ETHER_COOKIE, 121 NGM_ETHER_GET_IFINDEX, 122 "getifindex", 123 NULL, 124 &ng_parse_int32_type 125 }, 126 { 127 NGM_ETHER_COOKIE, 128 NGM_ETHER_GET_ENADDR, 129 "getenaddr", 130 NULL, 131 &ng_parse_enaddr_type 132 }, 133 { 134 NGM_ETHER_COOKIE, 135 NGM_ETHER_SET_ENADDR, 136 "setenaddr", 137 &ng_parse_enaddr_type, 138 NULL 139 }, 140 { 141 NGM_ETHER_COOKIE, 142 NGM_ETHER_GET_PROMISC, 143 "getpromisc", 144 NULL, 145 &ng_parse_int32_type 146 }, 147 { 148 NGM_ETHER_COOKIE, 149 NGM_ETHER_SET_PROMISC, 150 "setpromisc", 151 &ng_parse_int32_type, 152 NULL 153 }, 154 { 155 NGM_ETHER_COOKIE, 156 NGM_ETHER_GET_AUTOSRC, 157 "getautosrc", 158 NULL, 159 &ng_parse_int32_type 160 }, 161 { 162 NGM_ETHER_COOKIE, 163 NGM_ETHER_SET_AUTOSRC, 164 "setautosrc", 165 &ng_parse_int32_type, 166 NULL 167 }, 168 { 0 } 169}; 170 171static struct ng_type ng_ether_typestruct = { 172 NG_ABI_VERSION, 173 NG_ETHER_NODE_TYPE, 174 ng_ether_mod_event, 175 ng_ether_constructor, 176 ng_ether_rcvmsg, 177 ng_ether_shutdown, 178 ng_ether_newhook, 179 NULL, 180 ng_ether_connect, 181 ng_ether_rcvdata, 182 ng_ether_disconnect, 183 ng_ether_cmdlist, 184}; 185MODULE_VERSION(ng_ether, 1); 186NETGRAPH_INIT(ether, &ng_ether_typestruct); 187 188/****************************************************************** 189 ETHERNET FUNCTION HOOKS 190******************************************************************/ 191 192/* 193 * Handle a packet that has come in on an interface. We get to 194 * look at it here before any upper layer protocols do. 195 * 196 * NOTE: this function will get called at splimp() 197 */ 198static void 199ng_ether_input(struct ifnet *ifp, struct mbuf **mp) 200{ 201 const node_p node = IFP2NG(ifp); 202 const priv_p priv = NG_NODE_PRIVATE(node);
|
| 203 int error;
|
204 205 /* If "lower" hook not connected, let packet continue */
| 204 205 /* If "lower" hook not connected, let packet continue */
|
206 if (priv->lower == NULL || priv->lowerOrphan)
| 206 if (priv->lower == NULL)
|
207 return;
| 207 return;
|
208 ng_ether_input2(node, mp);
| 208 NG_SEND_DATA_ONLY(error, priv->lower, *mp); /* sets *mp = NULL */
|
209} 210 211/* 212 * Handle a packet that has come in on an interface, and which 213 * does not match any of our known protocols (an ``orphan''). 214 * 215 * NOTE: this function will get called at splimp() 216 */ 217static void 218ng_ether_input_orphan(struct ifnet *ifp, struct mbuf *m) 219{ 220 const node_p node = IFP2NG(ifp); 221 const priv_p priv = NG_NODE_PRIVATE(node);
| 209} 210 211/* 212 * Handle a packet that has come in on an interface, and which 213 * does not match any of our known protocols (an ``orphan''). 214 * 215 * NOTE: this function will get called at splimp() 216 */ 217static void 218ng_ether_input_orphan(struct ifnet *ifp, struct mbuf *m) 219{ 220 const node_p node = IFP2NG(ifp); 221 const priv_p priv = NG_NODE_PRIVATE(node);
|
| 222 int error;
|
222
| 223
|
223 /* If "orphan" hook not connected, let packet continue */ 224 if (priv->lower == NULL || !priv->lowerOrphan) {
| 224 /* If "orphan" hook not connected, discard packet */ 225 if (priv->orphan == NULL) {
|
225 m_freem(m); 226 return; 227 }
| 226 m_freem(m); 227 return; 228 }
|
228 ng_ether_input2(node, &m); 229 if (m != NULL) 230 m_freem(m);
| 229 NG_SEND_DATA_ONLY(error, priv->orphan, m);
|
231} 232 233/*
| 230} 231 232/*
|
234 * Handle a packet that has come in on an ethernet interface. 235 * The Ethernet header has already been detached from the mbuf, 236 * so we have to put it back. 237 * 238 * NOTE: this function will get called at splimp() 239 */ 240static void 241ng_ether_input2(node_p node, struct mbuf **mp) 242{ 243 const priv_p priv = NG_NODE_PRIVATE(node); 244 int error; 245 246 /* Send out lower/orphan hook */ 247 NG_SEND_DATA_ONLY(error, priv->lower, *mp); 248 *mp = NULL; 249} 250 251/*
| |
252 * Handle a packet that is going out on an interface. 253 * The Ethernet header is already attached to the mbuf. 254 */ 255static int 256ng_ether_output(struct ifnet *ifp, struct mbuf **mp) 257{ 258 const node_p node = IFP2NG(ifp); 259 const priv_p priv = NG_NODE_PRIVATE(node); 260 int error = 0; 261 262 /* If "upper" hook not connected, let packet continue */ 263 if (priv->upper == NULL) 264 return (0); 265 266 /* Send it out "upper" hook */ 267 NG_SEND_DATA_ONLY(error, priv->upper, *mp); 268 return (error); 269} 270 271/* 272 * A new Ethernet interface has been attached. 273 * Create a new node for it, etc. 274 */ 275static void 276ng_ether_attach(struct ifnet *ifp) 277{ 278 priv_p priv; 279 node_p node; 280 281 /* Create node */ 282 KASSERT(!IFP2NG(ifp), ("%s: node already exists?", __func__)); 283 if (ng_make_node_common(&ng_ether_typestruct, &node) != 0) { 284 log(LOG_ERR, "%s: can't %s for %s\n", 285 __func__, "create node", ifp->if_xname); 286 return; 287 } 288 289 /* Allocate private data */ 290 MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO); 291 if (priv == NULL) { 292 log(LOG_ERR, "%s: can't %s for %s\n", 293 __func__, "allocate memory", ifp->if_xname); 294 NG_NODE_UNREF(node); 295 return; 296 } 297 NG_NODE_SET_PRIVATE(node, priv); 298 priv->ifp = ifp; 299 IFP2NG(ifp) = node; 300 priv->autoSrcAddr = 1; 301 priv->hwassist = ifp->if_hwassist; 302 303 /* Try to give the node the same name as the interface */ 304 if (ng_name_node(node, ifp->if_xname) != 0) { 305 log(LOG_WARNING, "%s: can't name node %s\n", 306 __func__, ifp->if_xname); 307 } 308} 309 310/* 311 * An Ethernet interface is being detached. 312 * REALLY Destroy its node. 313 */ 314static void 315ng_ether_detach(struct ifnet *ifp) 316{ 317 const node_p node = IFP2NG(ifp); 318 const priv_p priv = NG_NODE_PRIVATE(node); 319 320 if (node == NULL) /* no node (why not?), ignore */ 321 return; 322 NG_NODE_REALLY_DIE(node); /* Force real removal of node */ 323 /* 324 * We can't assume the ifnet is still around when we run shutdown 325 * So zap it now. XXX We HOPE that anything running at this time 326 * handles it (as it should in the non netgraph case). 327 */ 328 IFP2NG(ifp) = NULL; 329 priv->ifp = NULL; /* XXX race if interrupted an output packet */ 330 ng_rmnode_self(node); /* remove all netgraph parts */ 331} 332 333/****************************************************************** 334 NETGRAPH NODE METHODS 335******************************************************************/ 336 337/* 338 * It is not possible or allowable to create a node of this type. 339 * Nodes get created when the interface is attached (or, when 340 * this node type's KLD is loaded). 341 */ 342static int 343ng_ether_constructor(node_p node) 344{ 345 return (EINVAL); 346} 347 348/* 349 * Check for attaching a new hook. 350 */ 351static int 352ng_ether_newhook(node_p node, hook_p hook, const char *name) 353{ 354 const priv_p priv = NG_NODE_PRIVATE(node);
| 233 * Handle a packet that is going out on an interface. 234 * The Ethernet header is already attached to the mbuf. 235 */ 236static int 237ng_ether_output(struct ifnet *ifp, struct mbuf **mp) 238{ 239 const node_p node = IFP2NG(ifp); 240 const priv_p priv = NG_NODE_PRIVATE(node); 241 int error = 0; 242 243 /* If "upper" hook not connected, let packet continue */ 244 if (priv->upper == NULL) 245 return (0); 246 247 /* Send it out "upper" hook */ 248 NG_SEND_DATA_ONLY(error, priv->upper, *mp); 249 return (error); 250} 251 252/* 253 * A new Ethernet interface has been attached. 254 * Create a new node for it, etc. 255 */ 256static void 257ng_ether_attach(struct ifnet *ifp) 258{ 259 priv_p priv; 260 node_p node; 261 262 /* Create node */ 263 KASSERT(!IFP2NG(ifp), ("%s: node already exists?", __func__)); 264 if (ng_make_node_common(&ng_ether_typestruct, &node) != 0) { 265 log(LOG_ERR, "%s: can't %s for %s\n", 266 __func__, "create node", ifp->if_xname); 267 return; 268 } 269 270 /* Allocate private data */ 271 MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO); 272 if (priv == NULL) { 273 log(LOG_ERR, "%s: can't %s for %s\n", 274 __func__, "allocate memory", ifp->if_xname); 275 NG_NODE_UNREF(node); 276 return; 277 } 278 NG_NODE_SET_PRIVATE(node, priv); 279 priv->ifp = ifp; 280 IFP2NG(ifp) = node; 281 priv->autoSrcAddr = 1; 282 priv->hwassist = ifp->if_hwassist; 283 284 /* Try to give the node the same name as the interface */ 285 if (ng_name_node(node, ifp->if_xname) != 0) { 286 log(LOG_WARNING, "%s: can't name node %s\n", 287 __func__, ifp->if_xname); 288 } 289} 290 291/* 292 * An Ethernet interface is being detached. 293 * REALLY Destroy its node. 294 */ 295static void 296ng_ether_detach(struct ifnet *ifp) 297{ 298 const node_p node = IFP2NG(ifp); 299 const priv_p priv = NG_NODE_PRIVATE(node); 300 301 if (node == NULL) /* no node (why not?), ignore */ 302 return; 303 NG_NODE_REALLY_DIE(node); /* Force real removal of node */ 304 /* 305 * We can't assume the ifnet is still around when we run shutdown 306 * So zap it now. XXX We HOPE that anything running at this time 307 * handles it (as it should in the non netgraph case). 308 */ 309 IFP2NG(ifp) = NULL; 310 priv->ifp = NULL; /* XXX race if interrupted an output packet */ 311 ng_rmnode_self(node); /* remove all netgraph parts */ 312} 313 314/****************************************************************** 315 NETGRAPH NODE METHODS 316******************************************************************/ 317 318/* 319 * It is not possible or allowable to create a node of this type. 320 * Nodes get created when the interface is attached (or, when 321 * this node type's KLD is loaded). 322 */ 323static int 324ng_ether_constructor(node_p node) 325{ 326 return (EINVAL); 327} 328 329/* 330 * Check for attaching a new hook. 331 */ 332static int 333ng_ether_newhook(node_p node, hook_p hook, const char *name) 334{ 335 const priv_p priv = NG_NODE_PRIVATE(node);
|
355 u_char orphan = priv->lowerOrphan;
| |
356 hook_p *hookptr; 357 358 /* Divert hook is an alias for lower */ 359 if (strcmp(name, NG_ETHER_HOOK_DIVERT) == 0) 360 name = NG_ETHER_HOOK_LOWER; 361 362 /* Which hook? */ 363 if (strcmp(name, NG_ETHER_HOOK_UPPER) == 0) 364 hookptr = &priv->upper;
| 336 hook_p *hookptr; 337 338 /* Divert hook is an alias for lower */ 339 if (strcmp(name, NG_ETHER_HOOK_DIVERT) == 0) 340 name = NG_ETHER_HOOK_LOWER; 341 342 /* Which hook? */ 343 if (strcmp(name, NG_ETHER_HOOK_UPPER) == 0) 344 hookptr = &priv->upper;
|
365 else if (strcmp(name, NG_ETHER_HOOK_LOWER) == 0) {
| 345 else if (strcmp(name, NG_ETHER_HOOK_LOWER) == 0)
|
366 hookptr = &priv->lower;
| 346 hookptr = &priv->lower;
|
367 orphan = 0; 368 } else if (strcmp(name, NG_ETHER_HOOK_ORPHAN) == 0) { 369 hookptr = &priv->lower; 370 orphan = 1; 371 } else
| 347 else if (strcmp(name, NG_ETHER_HOOK_ORPHAN) == 0) 348 hookptr = &priv->orphan; 349 else
|
372 return (EINVAL); 373 374 /* Check if already connected (shouldn't be, but doesn't hurt) */ 375 if (*hookptr != NULL) 376 return (EISCONN); 377 378 /* Disable hardware checksums while 'upper' hook is connected */ 379 if (hookptr == &priv->upper) 380 priv->ifp->if_hwassist = 0; 381 382 /* OK */ 383 *hookptr = hook;
| 350 return (EINVAL); 351 352 /* Check if already connected (shouldn't be, but doesn't hurt) */ 353 if (*hookptr != NULL) 354 return (EISCONN); 355 356 /* Disable hardware checksums while 'upper' hook is connected */ 357 if (hookptr == &priv->upper) 358 priv->ifp->if_hwassist = 0; 359 360 /* OK */ 361 *hookptr = hook;
|
384 priv->lowerOrphan = orphan;
| |
385 return (0); 386} 387 388/* 389 * Hooks are attached, adjust to force queueing. 390 * We don't really care which hook it is. 391 * they should all be queuing for outgoing data. 392 */ 393static int 394ng_ether_connect(hook_p hook) 395{ 396 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook)); 397 return (0); 398} 399 400/* 401 * Receive an incoming control message. 402 */ 403static int 404ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook) 405{ 406 const priv_p priv = NG_NODE_PRIVATE(node); 407 struct ng_mesg *resp = NULL; 408 int error = 0; 409 struct ng_mesg *msg; 410 411 NGI_GET_MSG(item, msg); 412 switch (msg->header.typecookie) { 413 case NGM_ETHER_COOKIE: 414 switch (msg->header.cmd) { 415 case NGM_ETHER_GET_IFNAME: 416 NG_MKRESPONSE(resp, msg, IFNAMSIZ + 1, M_NOWAIT); 417 if (resp == NULL) { 418 error = ENOMEM; 419 break; 420 } 421 strlcpy(resp->data, priv->ifp->if_xname, IFNAMSIZ + 1); 422 break; 423 case NGM_ETHER_GET_IFINDEX: 424 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT); 425 if (resp == NULL) { 426 error = ENOMEM; 427 break; 428 } 429 *((u_int32_t *)resp->data) = priv->ifp->if_index; 430 break; 431 case NGM_ETHER_GET_ENADDR: 432 NG_MKRESPONSE(resp, msg, ETHER_ADDR_LEN, M_NOWAIT); 433 if (resp == NULL) { 434 error = ENOMEM; 435 break; 436 } 437 bcopy((IFP2AC(priv->ifp))->ac_enaddr, 438 resp->data, ETHER_ADDR_LEN); 439 break; 440 case NGM_ETHER_SET_ENADDR: 441 { 442 if (msg->header.arglen != ETHER_ADDR_LEN) { 443 error = EINVAL; 444 break; 445 } 446 error = if_setlladdr(priv->ifp, 447 (u_char *)msg->data, ETHER_ADDR_LEN); 448 break; 449 } 450 case NGM_ETHER_GET_PROMISC: 451 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT); 452 if (resp == NULL) { 453 error = ENOMEM; 454 break; 455 } 456 *((u_int32_t *)resp->data) = priv->promisc; 457 break; 458 case NGM_ETHER_SET_PROMISC: 459 { 460 u_char want; 461 462 if (msg->header.arglen != sizeof(u_int32_t)) { 463 error = EINVAL; 464 break; 465 } 466 want = !!*((u_int32_t *)msg->data); 467 if (want ^ priv->promisc) { 468 if ((error = ifpromisc(priv->ifp, want)) != 0) 469 break; 470 priv->promisc = want; 471 } 472 break; 473 } 474 case NGM_ETHER_GET_AUTOSRC: 475 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT); 476 if (resp == NULL) { 477 error = ENOMEM; 478 break; 479 } 480 *((u_int32_t *)resp->data) = priv->autoSrcAddr; 481 break; 482 case NGM_ETHER_SET_AUTOSRC: 483 if (msg->header.arglen != sizeof(u_int32_t)) { 484 error = EINVAL; 485 break; 486 } 487 priv->autoSrcAddr = !!*((u_int32_t *)msg->data); 488 break; 489 default: 490 error = EINVAL; 491 break; 492 } 493 break; 494 default: 495 error = EINVAL; 496 break; 497 } 498 NG_RESPOND_MSG(error, node, item, resp); 499 NG_FREE_MSG(msg); 500 return (error); 501} 502 503/* 504 * Receive data on a hook. 505 */ 506static int 507ng_ether_rcvdata(hook_p hook, item_p item) 508{ 509 const node_p node = NG_HOOK_NODE(hook); 510 const priv_p priv = NG_NODE_PRIVATE(node); 511 struct mbuf *m; 512 meta_p meta; 513 514 NGI_GET_M(item, m); 515 NGI_GET_META(item, meta); 516 NG_FREE_ITEM(item);
| 362 return (0); 363} 364 365/* 366 * Hooks are attached, adjust to force queueing. 367 * We don't really care which hook it is. 368 * they should all be queuing for outgoing data. 369 */ 370static int 371ng_ether_connect(hook_p hook) 372{ 373 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook)); 374 return (0); 375} 376 377/* 378 * Receive an incoming control message. 379 */ 380static int 381ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook) 382{ 383 const priv_p priv = NG_NODE_PRIVATE(node); 384 struct ng_mesg *resp = NULL; 385 int error = 0; 386 struct ng_mesg *msg; 387 388 NGI_GET_MSG(item, msg); 389 switch (msg->header.typecookie) { 390 case NGM_ETHER_COOKIE: 391 switch (msg->header.cmd) { 392 case NGM_ETHER_GET_IFNAME: 393 NG_MKRESPONSE(resp, msg, IFNAMSIZ + 1, M_NOWAIT); 394 if (resp == NULL) { 395 error = ENOMEM; 396 break; 397 } 398 strlcpy(resp->data, priv->ifp->if_xname, IFNAMSIZ + 1); 399 break; 400 case NGM_ETHER_GET_IFINDEX: 401 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT); 402 if (resp == NULL) { 403 error = ENOMEM; 404 break; 405 } 406 *((u_int32_t *)resp->data) = priv->ifp->if_index; 407 break; 408 case NGM_ETHER_GET_ENADDR: 409 NG_MKRESPONSE(resp, msg, ETHER_ADDR_LEN, M_NOWAIT); 410 if (resp == NULL) { 411 error = ENOMEM; 412 break; 413 } 414 bcopy((IFP2AC(priv->ifp))->ac_enaddr, 415 resp->data, ETHER_ADDR_LEN); 416 break; 417 case NGM_ETHER_SET_ENADDR: 418 { 419 if (msg->header.arglen != ETHER_ADDR_LEN) { 420 error = EINVAL; 421 break; 422 } 423 error = if_setlladdr(priv->ifp, 424 (u_char *)msg->data, ETHER_ADDR_LEN); 425 break; 426 } 427 case NGM_ETHER_GET_PROMISC: 428 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT); 429 if (resp == NULL) { 430 error = ENOMEM; 431 break; 432 } 433 *((u_int32_t *)resp->data) = priv->promisc; 434 break; 435 case NGM_ETHER_SET_PROMISC: 436 { 437 u_char want; 438 439 if (msg->header.arglen != sizeof(u_int32_t)) { 440 error = EINVAL; 441 break; 442 } 443 want = !!*((u_int32_t *)msg->data); 444 if (want ^ priv->promisc) { 445 if ((error = ifpromisc(priv->ifp, want)) != 0) 446 break; 447 priv->promisc = want; 448 } 449 break; 450 } 451 case NGM_ETHER_GET_AUTOSRC: 452 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT); 453 if (resp == NULL) { 454 error = ENOMEM; 455 break; 456 } 457 *((u_int32_t *)resp->data) = priv->autoSrcAddr; 458 break; 459 case NGM_ETHER_SET_AUTOSRC: 460 if (msg->header.arglen != sizeof(u_int32_t)) { 461 error = EINVAL; 462 break; 463 } 464 priv->autoSrcAddr = !!*((u_int32_t *)msg->data); 465 break; 466 default: 467 error = EINVAL; 468 break; 469 } 470 break; 471 default: 472 error = EINVAL; 473 break; 474 } 475 NG_RESPOND_MSG(error, node, item, resp); 476 NG_FREE_MSG(msg); 477 return (error); 478} 479 480/* 481 * Receive data on a hook. 482 */ 483static int 484ng_ether_rcvdata(hook_p hook, item_p item) 485{ 486 const node_p node = NG_HOOK_NODE(hook); 487 const priv_p priv = NG_NODE_PRIVATE(node); 488 struct mbuf *m; 489 meta_p meta; 490 491 NGI_GET_M(item, m); 492 NGI_GET_META(item, meta); 493 NG_FREE_ITEM(item);
|
517 if (hook == priv->lower)
| 494 if (hook == priv->lower || hook == priv->orphan)
|
518 return ng_ether_rcv_lower(node, m, meta); 519 if (hook == priv->upper) 520 return ng_ether_rcv_upper(node, m, meta); 521 panic("%s: weird hook", __func__);
| 495 return ng_ether_rcv_lower(node, m, meta); 496 if (hook == priv->upper) 497 return ng_ether_rcv_upper(node, m, meta); 498 panic("%s: weird hook", __func__);
|
522#ifdef RESTARTABLE_PANICS /* so we don;t get an error msg in LINT */
| 499#ifdef RESTARTABLE_PANICS /* so we don't get an error msg in LINT */
|
523 return NULL; 524#endif 525} 526 527/*
| 500 return NULL; 501#endif 502} 503 504/*
|
528 * Handle an mbuf received on the "lower" hook.
| 505 * Handle an mbuf received on the "lower" or "orphan" hook.
|
529 */ 530static int 531ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta) 532{ 533 const priv_p priv = NG_NODE_PRIVATE(node); 534 struct ifnet *const ifp = priv->ifp; 535 536 /* Discard meta info */ 537 NG_FREE_META(meta); 538 539 /* Check whether interface is ready for packets */ 540 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) { 541 NG_FREE_M(m); 542 return (ENETDOWN); 543 } 544 545 /* Make sure header is fully pulled up */ 546 if (m->m_pkthdr.len < sizeof(struct ether_header)) { 547 NG_FREE_M(m); 548 return (EINVAL); 549 } 550 if (m->m_len < sizeof(struct ether_header) 551 && (m = m_pullup(m, sizeof(struct ether_header))) == NULL) 552 return (ENOBUFS); 553 554 /* Drop in the MAC address if desired */ 555 if (priv->autoSrcAddr) { 556 557 /* Make the mbuf writable if it's not already */ 558 if (!M_WRITABLE(m) 559 && (m = m_pullup(m, sizeof(struct ether_header))) == NULL) 560 return (ENOBUFS); 561 562 /* Overwrite source MAC address */ 563 bcopy((IFP2AC(ifp))->ac_enaddr, 564 mtod(m, struct ether_header *)->ether_shost, 565 ETHER_ADDR_LEN); 566 } 567 568 /* Send it on its way */ 569 return ether_output_frame(ifp, m); 570} 571 572/* 573 * Handle an mbuf received on the "upper" hook. 574 */ 575static int 576ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta) 577{ 578 const priv_p priv = NG_NODE_PRIVATE(node); 579 580 /* Discard meta info */ 581 NG_FREE_META(meta); 582 583 m->m_pkthdr.rcvif = priv->ifp; 584 585 /* Route packet back in */ 586 ether_demux(priv->ifp, m); 587 return (0); 588} 589 590/* 591 * Shutdown node. This resets the node but does not remove it 592 * unless the REALLY_DIE flag is set. 593 */ 594static int 595ng_ether_shutdown(node_p node) 596{ 597 const priv_p priv = NG_NODE_PRIVATE(node); 598 599 if (node->nd_flags & NG_REALLY_DIE) { 600 /* 601 * WE came here because the ethernet card is being unloaded, 602 * so stop being persistant. 603 * Actually undo all the things we did on creation. 604 * Assume the ifp has already been freed. 605 */ 606 NG_NODE_SET_PRIVATE(node, NULL); 607 FREE(priv, M_NETGRAPH); 608 NG_NODE_UNREF(node); /* free node itself */ 609 return (0); 610 } 611 if (priv->promisc) { /* disable promiscuous mode */ 612 (void)ifpromisc(priv->ifp, 0); 613 priv->promisc = 0; 614 } 615 priv->autoSrcAddr = 1; /* reset auto-src-addr flag */ 616 node->nd_flags &= ~NG_INVALID; /* Signal ng_rmnode we are persisant */ 617 return (0); 618} 619 620/* 621 * Hook disconnection. 622 */ 623static int 624ng_ether_disconnect(hook_p hook) 625{ 626 const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); 627 628 if (hook == priv->upper) { 629 priv->upper = NULL; 630 if (priv->ifp != NULL) /* restore h/w csum */ 631 priv->ifp->if_hwassist = priv->hwassist;
| 506 */ 507static int 508ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta) 509{ 510 const priv_p priv = NG_NODE_PRIVATE(node); 511 struct ifnet *const ifp = priv->ifp; 512 513 /* Discard meta info */ 514 NG_FREE_META(meta); 515 516 /* Check whether interface is ready for packets */ 517 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) { 518 NG_FREE_M(m); 519 return (ENETDOWN); 520 } 521 522 /* Make sure header is fully pulled up */ 523 if (m->m_pkthdr.len < sizeof(struct ether_header)) { 524 NG_FREE_M(m); 525 return (EINVAL); 526 } 527 if (m->m_len < sizeof(struct ether_header) 528 && (m = m_pullup(m, sizeof(struct ether_header))) == NULL) 529 return (ENOBUFS); 530 531 /* Drop in the MAC address if desired */ 532 if (priv->autoSrcAddr) { 533 534 /* Make the mbuf writable if it's not already */ 535 if (!M_WRITABLE(m) 536 && (m = m_pullup(m, sizeof(struct ether_header))) == NULL) 537 return (ENOBUFS); 538 539 /* Overwrite source MAC address */ 540 bcopy((IFP2AC(ifp))->ac_enaddr, 541 mtod(m, struct ether_header *)->ether_shost, 542 ETHER_ADDR_LEN); 543 } 544 545 /* Send it on its way */ 546 return ether_output_frame(ifp, m); 547} 548 549/* 550 * Handle an mbuf received on the "upper" hook. 551 */ 552static int 553ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta) 554{ 555 const priv_p priv = NG_NODE_PRIVATE(node); 556 557 /* Discard meta info */ 558 NG_FREE_META(meta); 559 560 m->m_pkthdr.rcvif = priv->ifp; 561 562 /* Route packet back in */ 563 ether_demux(priv->ifp, m); 564 return (0); 565} 566 567/* 568 * Shutdown node. This resets the node but does not remove it 569 * unless the REALLY_DIE flag is set. 570 */ 571static int 572ng_ether_shutdown(node_p node) 573{ 574 const priv_p priv = NG_NODE_PRIVATE(node); 575 576 if (node->nd_flags & NG_REALLY_DIE) { 577 /* 578 * WE came here because the ethernet card is being unloaded, 579 * so stop being persistant. 580 * Actually undo all the things we did on creation. 581 * Assume the ifp has already been freed. 582 */ 583 NG_NODE_SET_PRIVATE(node, NULL); 584 FREE(priv, M_NETGRAPH); 585 NG_NODE_UNREF(node); /* free node itself */ 586 return (0); 587 } 588 if (priv->promisc) { /* disable promiscuous mode */ 589 (void)ifpromisc(priv->ifp, 0); 590 priv->promisc = 0; 591 } 592 priv->autoSrcAddr = 1; /* reset auto-src-addr flag */ 593 node->nd_flags &= ~NG_INVALID; /* Signal ng_rmnode we are persisant */ 594 return (0); 595} 596 597/* 598 * Hook disconnection. 599 */ 600static int 601ng_ether_disconnect(hook_p hook) 602{ 603 const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); 604 605 if (hook == priv->upper) { 606 priv->upper = NULL; 607 if (priv->ifp != NULL) /* restore h/w csum */ 608 priv->ifp->if_hwassist = priv->hwassist;
|
632 } else if (hook == priv->lower) {
| 609 } else if (hook == priv->lower)
|
633 priv->lower = NULL;
| 610 priv->lower = NULL;
|
634 priv->lowerOrphan = 0; 635 } else
| 611 else if (hook == priv->orphan) 612 priv->orphan = NULL; 613 else
|
636 panic("%s: weird hook", __func__); 637 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) 638 && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) 639 ng_rmnode_self(NG_HOOK_NODE(hook)); /* reset node */ 640 return (0); 641} 642 643/****************************************************************** 644 INITIALIZATION 645******************************************************************/ 646 647/* 648 * Handle loading and unloading for this node type. 649 */ 650static int 651ng_ether_mod_event(module_t mod, int event, void *data) 652{ 653 struct ifnet *ifp; 654 int error = 0; 655 int s; 656 657 s = splnet(); 658 switch (event) { 659 case MOD_LOAD: 660 661 /* Register function hooks */ 662 if (ng_ether_attach_p != NULL) { 663 error = EEXIST; 664 break; 665 } 666 ng_ether_attach_p = ng_ether_attach; 667 ng_ether_detach_p = ng_ether_detach; 668 ng_ether_output_p = ng_ether_output; 669 ng_ether_input_p = ng_ether_input; 670 ng_ether_input_orphan_p = ng_ether_input_orphan; 671 672 /* Create nodes for any already-existing Ethernet interfaces */ 673 IFNET_RLOCK(); 674 TAILQ_FOREACH(ifp, &ifnet, if_link) { 675 if (ifp->if_type == IFT_ETHER 676 || ifp->if_type == IFT_L2VLAN) 677 ng_ether_attach(ifp); 678 } 679 IFNET_RUNLOCK(); 680 break; 681 682 case MOD_UNLOAD: 683 684 /* 685 * Note that the base code won't try to unload us until 686 * all nodes have been removed, and that can't happen 687 * until all Ethernet interfaces are removed. In any 688 * case, we know there are no nodes left if the action 689 * is MOD_UNLOAD, so there's no need to detach any nodes. 690 */ 691 692 /* Unregister function hooks */ 693 ng_ether_attach_p = NULL; 694 ng_ether_detach_p = NULL; 695 ng_ether_output_p = NULL; 696 ng_ether_input_p = NULL; 697 ng_ether_input_orphan_p = NULL; 698 break; 699 700 default: 701 error = EOPNOTSUPP; 702 break; 703 } 704 splx(s); 705 return (error); 706} 707
| 614 panic("%s: weird hook", __func__); 615 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) 616 && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) 617 ng_rmnode_self(NG_HOOK_NODE(hook)); /* reset node */ 618 return (0); 619} 620 621/****************************************************************** 622 INITIALIZATION 623******************************************************************/ 624 625/* 626 * Handle loading and unloading for this node type. 627 */ 628static int 629ng_ether_mod_event(module_t mod, int event, void *data) 630{ 631 struct ifnet *ifp; 632 int error = 0; 633 int s; 634 635 s = splnet(); 636 switch (event) { 637 case MOD_LOAD: 638 639 /* Register function hooks */ 640 if (ng_ether_attach_p != NULL) { 641 error = EEXIST; 642 break; 643 } 644 ng_ether_attach_p = ng_ether_attach; 645 ng_ether_detach_p = ng_ether_detach; 646 ng_ether_output_p = ng_ether_output; 647 ng_ether_input_p = ng_ether_input; 648 ng_ether_input_orphan_p = ng_ether_input_orphan; 649 650 /* Create nodes for any already-existing Ethernet interfaces */ 651 IFNET_RLOCK(); 652 TAILQ_FOREACH(ifp, &ifnet, if_link) { 653 if (ifp->if_type == IFT_ETHER 654 || ifp->if_type == IFT_L2VLAN) 655 ng_ether_attach(ifp); 656 } 657 IFNET_RUNLOCK(); 658 break; 659 660 case MOD_UNLOAD: 661 662 /* 663 * Note that the base code won't try to unload us until 664 * all nodes have been removed, and that can't happen 665 * until all Ethernet interfaces are removed. In any 666 * case, we know there are no nodes left if the action 667 * is MOD_UNLOAD, so there's no need to detach any nodes. 668 */ 669 670 /* Unregister function hooks */ 671 ng_ether_attach_p = NULL; 672 ng_ether_detach_p = NULL; 673 ng_ether_output_p = NULL; 674 ng_ether_input_p = NULL; 675 ng_ether_input_orphan_p = NULL; 676 break; 677 678 default: 679 error = EOPNOTSUPP; 680 break; 681 } 682 splx(s); 683 return (error); 684} 685
|