games/quiz: add another president answer section and update data
[dragonfly.git] / sys / netgraph / ether / ng_ether.c
blob682c63b3ab7c7dfd885f8f9efe8645005f1cebef
2 /*
3 * ng_ether.c
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.
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.
37 * Authors: Archie Cobbs <archie@freebsd.org>
38 * Julian Elischer <julian@freebsd.org>
40 * $FreeBSD: src/sys/netgraph/ng_ether.c,v 1.2.2.13 2002/07/02 20:10:25 archie Exp $
41 * $DragonFly: src/sys/netgraph/ether/ng_ether.c,v 1.17 2008/07/27 10:06:57 sephe Exp $
45 * ng_ether(4) netgraph node type
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/mbuf.h>
53 #include <sys/errno.h>
54 #include <sys/syslog.h>
55 #include <sys/socket.h>
56 #include <sys/thread2.h>
58 #include <net/if.h>
59 #include <net/if_types.h>
60 #include <net/if_arp.h>
61 #include <net/if_var.h>
62 #include <net/ethernet.h>
64 #include <netgraph/ng_message.h>
65 #include <netgraph/netgraph.h>
66 #include <netgraph/ng_parse.h>
67 #include "ng_ether.h"
69 #define IFP2AC(IFP) ((struct arpcom *)IFP)
70 #define IFP2NG(ifp) (IFP2AC((ifp))->ac_netgraph)
72 /* Per-node private data */
73 struct private {
74 struct ifnet *ifp; /* associated interface */
75 hook_p upper; /* upper hook connection */
76 hook_p lower; /* lower OR orphan hook connection */
77 u_char lowerOrphan; /* whether lower is lower or orphan */
78 u_char autoSrcAddr; /* always overwrite source address */
79 u_char promisc; /* promiscuous mode enabled */
80 u_long hwassist; /* hardware checksum capabilities */
82 typedef struct private *priv_p;
84 /* Functional hooks called from if_ethersubr.c */
85 static void ng_ether_input(struct ifnet *ifp, struct mbuf **mp);
86 static void ng_ether_input_orphan(struct ifnet *ifp,
87 struct mbuf *m, const struct ether_header *eh);
88 static int ng_ether_output(struct ifnet *ifp, struct mbuf **mp);
89 static void ng_ether_attach(struct ifnet *ifp);
90 static void ng_ether_detach(struct ifnet *ifp);
92 /* Other functions */
93 static void ng_ether_input2(node_p node,
94 struct mbuf **mp, const struct ether_header *eh);
95 static int ng_ether_glueback_header(struct mbuf **mp,
96 const struct ether_header *eh);
97 static int ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta);
98 static int ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta);
100 /* Netgraph node methods */
101 static ng_constructor_t ng_ether_constructor;
102 static ng_rcvmsg_t ng_ether_rcvmsg;
103 static ng_shutdown_t ng_ether_rmnode;
104 static ng_newhook_t ng_ether_newhook;
105 static ng_rcvdata_t ng_ether_rcvdata;
106 static ng_disconnect_t ng_ether_disconnect;
107 static int ng_ether_mod_event(module_t mod, int event, void *data);
109 /* Parse type for an Ethernet address */
110 static ng_parse_t ng_enaddr_parse;
111 static ng_unparse_t ng_enaddr_unparse;
112 const struct ng_parse_type ng_ether_enaddr_type = {
113 NULL,
114 NULL,
115 NULL,
116 ng_enaddr_parse,
117 ng_enaddr_unparse,
118 NULL, /* no such thing as a "default" EN address */
122 /* List of commands and how to convert arguments to/from ASCII */
123 static const struct ng_cmdlist ng_ether_cmdlist[] = {
125 NGM_ETHER_COOKIE,
126 NGM_ETHER_GET_IFNAME,
127 "getifname",
128 NULL,
129 &ng_parse_string_type
132 NGM_ETHER_COOKIE,
133 NGM_ETHER_GET_IFINDEX,
134 "getifindex",
135 NULL,
136 &ng_parse_int32_type
139 NGM_ETHER_COOKIE,
140 NGM_ETHER_GET_ENADDR,
141 "getenaddr",
142 NULL,
143 &ng_ether_enaddr_type
146 NGM_ETHER_COOKIE,
147 NGM_ETHER_SET_ENADDR,
148 "setenaddr",
149 &ng_ether_enaddr_type,
150 NULL
153 NGM_ETHER_COOKIE,
154 NGM_ETHER_GET_PROMISC,
155 "getpromisc",
156 NULL,
157 &ng_parse_int32_type
160 NGM_ETHER_COOKIE,
161 NGM_ETHER_SET_PROMISC,
162 "setpromisc",
163 &ng_parse_int32_type,
164 NULL
167 NGM_ETHER_COOKIE,
168 NGM_ETHER_GET_AUTOSRC,
169 "getautosrc",
170 NULL,
171 &ng_parse_int32_type
174 NGM_ETHER_COOKIE,
175 NGM_ETHER_SET_AUTOSRC,
176 "setautosrc",
177 &ng_parse_int32_type,
178 NULL
180 { 0 }
183 static struct ng_type ng_ether_typestruct = {
184 NG_VERSION,
185 NG_ETHER_NODE_TYPE,
186 ng_ether_mod_event,
187 ng_ether_constructor,
188 ng_ether_rcvmsg,
189 ng_ether_rmnode,
190 ng_ether_newhook,
191 NULL,
192 NULL,
193 ng_ether_rcvdata,
194 ng_ether_rcvdata,
195 ng_ether_disconnect,
196 ng_ether_cmdlist,
198 NETGRAPH_INIT(ether, &ng_ether_typestruct);
200 /******************************************************************
201 ETHERNET FUNCTION HOOKS
202 ******************************************************************/
205 * Handle a packet that has come in on an interface. We get to
206 * look at it here before any upper layer protocols do.
208 static void
209 ng_ether_input(struct ifnet *ifp, struct mbuf **mp)
211 const node_p node = IFP2NG(ifp);
212 const priv_p priv = node->private;
214 /* If "lower" hook not connected, let packet continue */
215 if (priv->lower == NULL || priv->lowerOrphan)
216 return;
217 ng_ether_input2(node, mp, NULL);
221 * Handle a packet that has come in on an interface, and which
222 * does not match any of our known protocols (an ``orphan'').
224 static void
225 ng_ether_input_orphan(struct ifnet *ifp,
226 struct mbuf *m, const struct ether_header *eh)
228 const node_p node = IFP2NG(ifp);
229 const priv_p priv = node->private;
231 /* If "orphan" hook not connected, let packet continue */
232 if (priv->lower == NULL || !priv->lowerOrphan) {
233 m_freem(m);
234 return;
236 ng_ether_input2(node, &m, eh);
237 if (m != NULL)
238 m_freem(m);
242 * Handle a packet that has come in on an interface.
243 * The Ethernet header has already been detached from the mbuf,
244 * so we have to put it back.
246 * NOTE: this function will get called at splimp()
248 static void
249 ng_ether_input2(node_p node, struct mbuf **mp, const struct ether_header *eh)
251 const priv_p priv = node->private;
252 meta_p meta = NULL;
253 int error;
255 /* Glue Ethernet header back on */
256 if (eh != NULL && (error = ng_ether_glueback_header(mp, eh)) != 0)
257 return;
259 /* Send out lower/orphan hook */
260 ng_queue_data(priv->lower, *mp, meta);
261 *mp = NULL;
265 * Handle a packet that is going out on an interface.
266 * The Ethernet header is already attached to the mbuf.
268 static int
269 ng_ether_output(struct ifnet *ifp, struct mbuf **mp)
271 const node_p node = IFP2NG(ifp);
272 const priv_p priv = node->private;
273 meta_p meta = NULL;
274 int error = 0;
276 /* If "upper" hook not connected, let packet continue */
277 if (priv->upper == NULL)
278 return (0);
280 /* Send it out "upper" hook */
281 NG_SEND_DATA(error, priv->upper, *mp, meta);
282 *mp = NULL;
283 return (error);
287 * A new Ethernet interface has been attached.
288 * Create a new node for it, etc.
290 static void
291 ng_ether_attach(struct ifnet *ifp)
293 char name[IFNAMSIZ + 1];
294 priv_p priv;
295 node_p node;
297 /* Create node */
298 KASSERT(!IFP2NG(ifp), ("%s: node already exists?", __func__));
299 strlcpy(name, ifp->if_xname, sizeof(name));
300 if (ng_make_node_common(&ng_ether_typestruct, &node) != 0) {
301 log(LOG_ERR, "%s: can't %s for %s\n",
302 __func__, "create node", name);
303 return;
306 /* Allocate private data */
307 MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
308 if (priv == NULL) {
309 log(LOG_ERR, "%s: can't %s for %s\n",
310 __func__, "allocate memory", name);
311 ng_unref(node);
312 return;
314 node->private = priv;
315 priv->ifp = ifp;
316 IFP2NG(ifp) = node;
317 priv->autoSrcAddr = 1;
318 priv->hwassist = ifp->if_hwassist;
320 /* Try to give the node the same name as the interface */
321 if (ng_name_node(node, name) != 0) {
322 log(LOG_WARNING, "%s: can't name node %s\n",
323 __func__, name);
328 * An Ethernet interface is being detached.
329 * Destroy its node.
331 static void
332 ng_ether_detach(struct ifnet *ifp)
334 const node_p node = IFP2NG(ifp);
335 priv_p priv;
337 if (node == NULL) /* no node (why not?), ignore */
338 return;
339 ng_rmnode(node); /* break all links to other nodes */
340 node->flags |= NG_INVALID;
341 ng_unname(node); /* free name (and its reference) */
342 IFP2NG(ifp) = NULL; /* detach node from interface */
343 priv = node->private; /* free node private info */
344 bzero(priv, sizeof(*priv));
345 FREE(priv, M_NETGRAPH);
346 node->private = NULL;
347 ng_unref(node); /* free node itself */
351 * Optimization for gluing the Ethernet header back onto
352 * the front of an incoming packet.
354 static int
355 ng_ether_glueback_header(struct mbuf **mp, const struct ether_header *eh)
357 struct mbuf *m = *mp;
358 int error = 0;
361 * Optimize for the case where the header is already in place
362 * at the front of the mbuf. This is actually quite likely
363 * because many Ethernet drivers generate packets this way.
365 if (eh == mtod(m, struct ether_header *) - 1) {
366 m->m_len += sizeof(*eh);
367 m->m_data -= sizeof(*eh);
368 m->m_pkthdr.len += sizeof(*eh);
369 goto done;
372 /* Prepend the header back onto the front of the mbuf */
373 M_PREPEND(m, sizeof(*eh), MB_DONTWAIT);
374 if (m == NULL) {
375 error = ENOBUFS;
376 goto done;
379 /* Copy header into front of mbuf */
380 bcopy(eh, mtod(m, void *), sizeof(*eh));
382 done:
383 /* Done */
384 *mp = m;
385 return error;
388 /******************************************************************
389 NETGRAPH NODE METHODS
390 ******************************************************************/
393 * It is not possible or allowable to create a node of this type.
394 * Nodes get created when the interface is attached (or, when
395 * this node type's KLD is loaded).
397 static int
398 ng_ether_constructor(node_p *nodep)
400 return (EINVAL);
404 * Check for attaching a new hook.
406 static int
407 ng_ether_newhook(node_p node, hook_p hook, const char *name)
409 const priv_p priv = node->private;
410 u_char orphan = priv->lowerOrphan;
411 hook_p *hookptr;
413 /* Divert hook is an alias for lower */
414 if (strcmp(name, NG_ETHER_HOOK_DIVERT) == 0)
415 name = NG_ETHER_HOOK_LOWER;
417 /* Which hook? */
418 if (strcmp(name, NG_ETHER_HOOK_UPPER) == 0)
419 hookptr = &priv->upper;
420 else if (strcmp(name, NG_ETHER_HOOK_LOWER) == 0) {
421 hookptr = &priv->lower;
422 orphan = 0;
423 } else if (strcmp(name, NG_ETHER_HOOK_ORPHAN) == 0) {
424 hookptr = &priv->lower;
425 orphan = 1;
426 } else
427 return (EINVAL);
429 /* Check if already connected (shouldn't be, but doesn't hurt) */
430 if (*hookptr != NULL)
431 return (EISCONN);
433 /* Disable hardware checksums while 'upper' hook is connected */
434 if (hookptr == &priv->upper)
435 priv->ifp->if_hwassist = 0;
437 /* OK */
438 *hookptr = hook;
439 priv->lowerOrphan = orphan;
440 return (0);
444 * Receive an incoming control message.
446 static int
447 ng_ether_rcvmsg(node_p node, struct ng_mesg *msg,
448 const char *retaddr, struct ng_mesg **rptr)
450 const priv_p priv = node->private;
451 struct ng_mesg *resp = NULL;
452 int error = 0;
454 switch (msg->header.typecookie) {
455 case NGM_ETHER_COOKIE:
456 switch (msg->header.cmd) {
457 case NGM_ETHER_GET_IFNAME:
458 NG_MKRESPONSE(resp, msg, IFNAMSIZ + 1, M_NOWAIT);
459 if (resp == NULL) {
460 error = ENOMEM;
461 break;
463 strlcpy(resp->data, priv->ifp->if_xname, IFNAMSIZ);
464 break;
465 case NGM_ETHER_GET_IFINDEX:
466 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
467 if (resp == NULL) {
468 error = ENOMEM;
469 break;
471 *((u_int32_t *)resp->data) = priv->ifp->if_index;
472 break;
473 case NGM_ETHER_GET_ENADDR:
474 NG_MKRESPONSE(resp, msg, ETHER_ADDR_LEN, M_NOWAIT);
475 if (resp == NULL) {
476 error = ENOMEM;
477 break;
479 bcopy((IFP2AC(priv->ifp))->ac_enaddr,
480 resp->data, ETHER_ADDR_LEN);
481 break;
482 case NGM_ETHER_SET_ENADDR:
484 if (msg->header.arglen != ETHER_ADDR_LEN) {
485 error = EINVAL;
486 break;
488 error = if_setlladdr(priv->ifp,
489 (u_char *)msg->data, ETHER_ADDR_LEN);
490 break;
492 case NGM_ETHER_GET_PROMISC:
493 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
494 if (resp == NULL) {
495 error = ENOMEM;
496 break;
498 *((u_int32_t *)resp->data) = priv->promisc;
499 break;
500 case NGM_ETHER_SET_PROMISC:
502 u_char want;
504 if (msg->header.arglen != sizeof(u_int32_t)) {
505 error = EINVAL;
506 break;
508 want = !!*((u_int32_t *)msg->data);
509 if (want ^ priv->promisc) {
510 if ((error = ifpromisc(priv->ifp, want)) != 0)
511 break;
512 priv->promisc = want;
514 break;
516 case NGM_ETHER_GET_AUTOSRC:
517 NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
518 if (resp == NULL) {
519 error = ENOMEM;
520 break;
522 *((u_int32_t *)resp->data) = priv->autoSrcAddr;
523 break;
524 case NGM_ETHER_SET_AUTOSRC:
525 if (msg->header.arglen != sizeof(u_int32_t)) {
526 error = EINVAL;
527 break;
529 priv->autoSrcAddr = !!*((u_int32_t *)msg->data);
530 break;
531 default:
532 error = EINVAL;
533 break;
535 break;
536 default:
537 error = EINVAL;
538 break;
540 if (rptr)
541 *rptr = resp;
542 else if (resp != NULL)
543 FREE(resp, M_NETGRAPH);
544 FREE(msg, M_NETGRAPH);
545 return (error);
549 * Receive data on a hook.
551 static int
552 ng_ether_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
554 const node_p node = hook->node;
555 const priv_p priv = node->private;
557 if (hook == priv->lower)
558 return ng_ether_rcv_lower(node, m, meta);
559 if (hook == priv->upper)
560 return ng_ether_rcv_upper(node, m, meta);
561 panic("%s: weird hook", __func__);
565 * Handle an mbuf received on the "lower" hook.
567 static int
568 ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta)
570 const priv_p priv = node->private;
571 struct ifnet *const ifp = priv->ifp;
572 int error;
574 /* Discard meta info */
575 NG_FREE_META(meta);
577 /* Check whether interface is ready for packets */
578 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
579 m_freem(m);
580 return (ENETDOWN);
583 /* Make sure header is fully pulled up */
584 if (m->m_pkthdr.len < sizeof(struct ether_header)) {
585 m_freem(m);
586 return (EINVAL);
588 if (m->m_len < sizeof(struct ether_header)
589 && (m = m_pullup(m, sizeof(struct ether_header))) == NULL)
590 return (ENOBUFS);
592 /* Drop in the MAC address if desired */
593 if (priv->autoSrcAddr) {
595 /* Make the mbuf writable if it's not already */
596 if (!M_WRITABLE(m)
597 && (m = m_pullup(m, sizeof(struct ether_header))) == NULL)
598 return (ENOBUFS);
600 /* Overwrite source MAC address */
601 bcopy((IFP2AC(ifp))->ac_enaddr,
602 mtod(m, struct ether_header *)->ether_shost,
603 ETHER_ADDR_LEN);
606 /* Send it on its way */
607 error = ether_output_frame(ifp, m);
608 return (error);
612 * Handle an mbuf received on the "upper" hook.
614 static int
615 ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta)
617 const priv_p priv = node->private;
619 /* Discard meta info */
620 NG_FREE_META(meta);
622 /* Check length and pull off header */
623 if (m->m_pkthdr.len < ETHER_HDR_LEN) {
624 m_freem(m);
625 return (EINVAL);
627 if (m->m_len < ETHER_HDR_LEN &&
628 (m = m_pullup(m, ETHER_HDR_LEN)) == NULL)
629 return (ENOBUFS);
631 m->m_pkthdr.rcvif = priv->ifp;
634 * XXX
635 * Since frame processing is run in netisr0,
636 * 'm' may _not_ even on its target CPU.
638 /* Route packet back in */
639 ether_demux_oncpu(priv->ifp, m);
640 return (0);
644 * Shutdown node. This resets the node but does not remove it.
646 static int
647 ng_ether_rmnode(node_p node)
649 const priv_p priv = node->private;
651 ng_cutlinks(node);
652 node->flags &= ~NG_INVALID; /* bounce back to life */
653 if (priv->promisc) { /* disable promiscuous mode */
654 ifpromisc(priv->ifp, 0);
655 priv->promisc = 0;
657 priv->autoSrcAddr = 1; /* reset auto-src-addr flag */
658 return (0);
662 * Hook disconnection.
664 static int
665 ng_ether_disconnect(hook_p hook)
667 const priv_p priv = hook->node->private;
669 if (hook == priv->upper) {
670 priv->upper = NULL;
671 priv->ifp->if_hwassist = priv->hwassist; /* restore h/w csum */
672 } else if (hook == priv->lower) {
673 priv->lower = NULL;
674 priv->lowerOrphan = 0;
675 } else
676 panic("%s: weird hook", __func__);
677 if (hook->node->numhooks == 0)
678 ng_rmnode(hook->node); /* reset node */
679 return (0);
682 static int
683 ng_enaddr_parse(const struct ng_parse_type *type,
684 const char *s, int *const off, const u_char *const start,
685 u_char *const buf, int *const buflen)
687 char *eptr;
688 u_long val;
689 int i;
691 if (*buflen < ETHER_ADDR_LEN)
692 return (ERANGE);
693 for (i = 0; i < ETHER_ADDR_LEN; i++) {
694 val = strtoul(s + *off, &eptr, 16);
695 if (val > 0xff || eptr == s + *off)
696 return (EINVAL);
697 buf[i] = (u_char)val;
698 *off = (eptr - s);
699 if (i < ETHER_ADDR_LEN - 1) {
700 if (*eptr != ':')
701 return (EINVAL);
702 (*off)++;
705 *buflen = ETHER_ADDR_LEN;
706 return (0);
709 static int
710 ng_enaddr_unparse(const struct ng_parse_type *type,
711 const u_char *data, int *off, char *cbuf, int cbuflen)
713 int len;
715 len = ksnprintf(cbuf, cbuflen, "%02x:%02x:%02x:%02x:%02x:%02x",
716 data[*off], data[*off + 1], data[*off + 2],
717 data[*off + 3], data[*off + 4], data[*off + 5]);
718 if (len >= cbuflen)
719 return (ERANGE);
720 *off += ETHER_ADDR_LEN;
721 return (0);
724 /******************************************************************
725 INITIALIZATION
726 ******************************************************************/
729 * Handle loading and unloading for this node type.
731 static int
732 ng_ether_mod_event(module_t mod, int event, void *data)
734 struct ifnet *ifp;
735 int error = 0;
737 crit_enter();
738 switch (event) {
739 case MOD_LOAD:
741 /* Register function hooks */
742 if (ng_ether_attach_p != NULL) {
743 error = EEXIST;
744 break;
746 ng_ether_attach_p = ng_ether_attach;
747 ng_ether_detach_p = ng_ether_detach;
748 ng_ether_output_p = ng_ether_output;
749 ng_ether_input_p = ng_ether_input;
750 ng_ether_input_orphan_p = ng_ether_input_orphan;
752 /* Create nodes for any already-existing Ethernet interfaces */
753 TAILQ_FOREACH(ifp, &ifnet, if_link) {
754 if (ifp->if_type == IFT_ETHER ||
755 ifp->if_type == IFT_L2VLAN)
756 ng_ether_attach(ifp);
758 break;
760 case MOD_UNLOAD:
763 * Note that the base code won't try to unload us until
764 * all nodes have been removed, and that can't happen
765 * until all Ethernet interfaces are removed. In any
766 * case, we know there are no nodes left if the action
767 * is MOD_UNLOAD, so there's no need to detach any nodes.
770 /* Unregister function hooks */
771 ng_ether_attach_p = NULL;
772 ng_ether_detach_p = NULL;
773 ng_ether_output_p = NULL;
774 ng_ether_input_p = NULL;
775 ng_ether_input_orphan_p = NULL;
776 break;
778 default:
779 error = EOPNOTSUPP;
780 break;
782 crit_exit();
783 return (error);