xref: /freebsd/sys/netgraph/ng_eiface.c (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  *
5  * Copyright (c) 1999-2001, Vitaly V Belekhov
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice unmodified, this list of conditions, and the following
13  *    disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #include <sys/param.h>
34 #include <sys/eventhandler.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/kernel.h>
38 #include <sys/malloc.h>
39 #include <sys/mbuf.h>
40 #include <sys/errno.h>
41 #include <sys/proc.h>
42 #include <sys/sockio.h>
43 #include <sys/socket.h>
44 #include <sys/syslog.h>
45 
46 #include <net/if.h>
47 #include <net/if_var.h>
48 #include <net/if_media.h>
49 #include <net/if_private.h>
50 #include <net/if_types.h>
51 #include <net/netisr.h>
52 #include <net/route.h>
53 #include <net/vnet.h>
54 
55 #include <netgraph/ng_message.h>
56 #include <netgraph/netgraph.h>
57 #include <netgraph/ng_parse.h>
58 #include <netgraph/ng_eiface.h>
59 
60 #include <net/bpf.h>
61 #include <net/ethernet.h>
62 #include <net/if_arp.h>
63 
64 static const struct ng_cmdlist ng_eiface_cmdlist[] = {
65 	{
66 	  NGM_EIFACE_COOKIE,
67 	  NGM_EIFACE_GET_IFNAME,
68 	  "getifname",
69 	  NULL,
70 	  &ng_parse_string_type
71 	},
72 	{
73 	  NGM_EIFACE_COOKIE,
74 	  NGM_EIFACE_SET,
75 	  "set",
76 	  &ng_parse_enaddr_type,
77 	  NULL
78 	},
79 	{ 0 }
80 };
81 
82 /* Node private data */
83 struct ng_eiface_private {
84 	struct ifnet	*ifp;		/* per-interface network data */
85 	struct ifmedia	media;		/* (fake) media information */
86 	int		link_status;	/* fake */
87 	int		unit;		/* Interface unit number */
88 	node_p		node;		/* Our netgraph node */
89 	hook_p		ether;		/* Hook for ethernet stream */
90 };
91 typedef struct ng_eiface_private *priv_p;
92 
93 /* Interface methods */
94 static void	ng_eiface_init(void *xsc);
95 static void	ng_eiface_start(struct ifnet *ifp);
96 static int	ng_eiface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
97 #ifdef DEBUG
98 static void	ng_eiface_print_ioctl(struct ifnet *ifp, int cmd, caddr_t data);
99 #endif
100 
101 /* Netgraph methods */
102 static int		ng_eiface_mod_event(module_t, int, void *);
103 static ng_constructor_t	ng_eiface_constructor;
104 static ng_rcvmsg_t	ng_eiface_rcvmsg;
105 static ng_shutdown_t	ng_eiface_rmnode;
106 static ng_newhook_t	ng_eiface_newhook;
107 static ng_rcvdata_t	ng_eiface_rcvdata;
108 static ng_disconnect_t	ng_eiface_disconnect;
109 
110 /* Node type descriptor */
111 static struct ng_type typestruct = {
112 	.version =	NG_ABI_VERSION,
113 	.name =		NG_EIFACE_NODE_TYPE,
114 	.mod_event =	ng_eiface_mod_event,
115 	.constructor =	ng_eiface_constructor,
116 	.rcvmsg =	ng_eiface_rcvmsg,
117 	.shutdown =	ng_eiface_rmnode,
118 	.newhook =	ng_eiface_newhook,
119 	.rcvdata =	ng_eiface_rcvdata,
120 	.disconnect =	ng_eiface_disconnect,
121 	.cmdlist =	ng_eiface_cmdlist
122 };
123 NETGRAPH_INIT(eiface, &typestruct);
124 
125 VNET_DEFINE_STATIC(struct unrhdr *, ng_eiface_unit);
126 #define	V_ng_eiface_unit		VNET(ng_eiface_unit)
127 
128 /************************************************************************
129 			INTERFACE STUFF
130  ************************************************************************/
131 
132 /*
133  * Process an ioctl for the virtual interface
134  */
135 static int
136 ng_eiface_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
137 {
138 	const priv_p priv = (priv_p)ifp->if_softc;
139 	struct ifreq *const ifr = (struct ifreq *)data;
140 	int error = 0;
141 
142 #ifdef DEBUG
143 	ng_eiface_print_ioctl(ifp, command, data);
144 #endif
145 	switch (command) {
146 	/* These two are mostly handled at a higher layer */
147 	case SIOCSIFADDR:
148 		error = ether_ioctl(ifp, command, data);
149 		break;
150 	case SIOCGIFADDR:
151 		break;
152 
153 	/* Set flags */
154 	case SIOCSIFFLAGS:
155 		/*
156 		 * If the interface is marked up and stopped, then start it.
157 		 * If it is marked down and running, then stop it.
158 		 */
159 		if (ifp->if_flags & IFF_UP) {
160 			if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
161 				ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE);
162 				ifp->if_drv_flags |= IFF_DRV_RUNNING;
163 			}
164 		} else {
165 			if (ifp->if_drv_flags & IFF_DRV_RUNNING)
166 				ifp->if_drv_flags &= ~(IFF_DRV_RUNNING |
167 				    IFF_DRV_OACTIVE);
168 		}
169 		break;
170 
171 	/* Set the interface MTU */
172 	case SIOCSIFMTU:
173 		if (ifr->ifr_mtu > NG_EIFACE_MTU_MAX ||
174 		    ifr->ifr_mtu < NG_EIFACE_MTU_MIN)
175 			error = EINVAL;
176 		else
177 			ifp->if_mtu = ifr->ifr_mtu;
178 		break;
179 
180 	/* (Fake) media type manipulation */
181 	case SIOCSIFMEDIA:
182 	case SIOCGIFMEDIA:
183 		error = ifmedia_ioctl(ifp, ifr, &priv->media, command);
184 		break;
185 
186 	/* Stuff that's not supported */
187 	case SIOCADDMULTI:
188 	case SIOCDELMULTI:
189 		error = 0;
190 		break;
191 	case SIOCSIFPHYS:
192 		error = EOPNOTSUPP;
193 		break;
194 
195 	default:
196 		error = EINVAL;
197 		break;
198 	}
199 	return (error);
200 }
201 
202 static void
203 ng_eiface_init(void *xsc)
204 {
205 	priv_p sc = xsc;
206 	struct ifnet *ifp = sc->ifp;
207 
208 	ifp->if_drv_flags |= IFF_DRV_RUNNING;
209 	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
210 }
211 
212 /*
213  * We simply relay the packet to the "ether" hook, if it is connected.
214  * We have been through the netgraph locking and are guaranteed to
215  * be the only code running in this node at this time.
216  */
217 static void
218 ng_eiface_start2(node_p node, hook_p hook, void *arg1, int arg2)
219 {
220 	struct ifnet *ifp = arg1;
221 	const priv_p priv = (priv_p)ifp->if_softc;
222 	int error = 0;
223 	struct mbuf *m;
224 
225 	/* Check interface flags */
226 
227 	if (!((ifp->if_flags & IFF_UP) &&
228 	    (ifp->if_drv_flags & IFF_DRV_RUNNING)))
229 		return;
230 
231 	for (;;) {
232 		/*
233 		 * Grab a packet to transmit.
234 		 */
235 		IF_DEQUEUE(&ifp->if_snd, m);
236 
237 		/* If there's nothing to send, break. */
238 		if (m == NULL)
239 			break;
240 
241 		/* Peel the mbuf off any stale tags */
242 		m_tag_delete_chain(m, NULL);
243 
244 		/*
245 		 * Berkeley packet filter.
246 		 * Pass packet to bpf if there is a listener.
247 		 * XXX is this safe? locking?
248 		 */
249 		BPF_MTAP(ifp, m);
250 
251 		if (ifp->if_flags & IFF_MONITOR) {
252 			if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
253 			m_freem(m);
254 			continue;
255 		}
256 
257 		/*
258 		 * Send packet; if hook is not connected, mbuf will get
259 		 * freed.
260 		 */
261 		NG_OUTBOUND_THREAD_REF();
262 		NG_SEND_DATA_ONLY(error, priv->ether, m);
263 		NG_OUTBOUND_THREAD_UNREF();
264 
265 		/* Update stats */
266 		if (error == 0)
267 			if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
268 		else
269 			if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
270 	}
271 
272 	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
273 
274 	return;
275 }
276 
277 /*
278  * This routine is called to deliver a packet out the interface.
279  * We simply queue the netgraph version to be called when netgraph locking
280  * allows it to happen.
281  * Until we know what the rest of the networking code is doing for
282  * locking, we don't know how we will interact with it.
283  * Take comfort from the fact that the ifnet struct is part of our
284  * private info and can't go away while we are queued.
285  * [Though we don't know it is still there now....]
286  * it is possible we don't gain anything from this because
287  * we would like to get the mbuf and queue it as data
288  * somehow, but we can't and if we did would we solve anything?
289  */
290 static void
291 ng_eiface_start(struct ifnet *ifp)
292 {
293 	const priv_p priv = (priv_p)ifp->if_softc;
294 
295 	/* Don't do anything if output is active */
296 	if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
297 		return;
298 
299 	ifp->if_drv_flags |= IFF_DRV_OACTIVE;
300 
301 	if (ng_send_fn(priv->node, NULL, &ng_eiface_start2, ifp, 0) != 0)
302 		ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
303 }
304 
305 #ifdef DEBUG
306 /*
307  * Display an ioctl to the virtual interface
308  */
309 
310 static void
311 ng_eiface_print_ioctl(struct ifnet *ifp, int command, caddr_t data)
312 {
313 	char *str;
314 
315 	switch (command & IOC_DIRMASK) {
316 	case IOC_VOID:
317 		str = "IO";
318 		break;
319 	case IOC_OUT:
320 		str = "IOR";
321 		break;
322 	case IOC_IN:
323 		str = "IOW";
324 		break;
325 	case IOC_INOUT:
326 		str = "IORW";
327 		break;
328 	default:
329 		str = "IO??";
330 	}
331 	log(LOG_DEBUG, "%s: %s('%c', %d, char[%d])\n",
332 	    ifp->if_xname,
333 	    str,
334 	    IOCGROUP(command),
335 	    command & 0xff,
336 	    IOCPARM_LEN(command));
337 }
338 #endif /* DEBUG */
339 
340 /*
341  * ifmedia stuff
342  */
343 static int
344 ng_eiface_mediachange(struct ifnet *ifp)
345 {
346 	const priv_p priv = (priv_p)ifp->if_softc;
347 	struct ifmedia *ifm = &priv->media;
348 
349 	if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
350 		return (EINVAL);
351 	if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO)
352 		ifp->if_baudrate = ifmedia_baudrate(IFM_ETHER | IFM_1000_T);
353 	else
354 		ifp->if_baudrate = ifmedia_baudrate(ifm->ifm_media);
355 
356 	return (0);
357 }
358 
359 static void
360 ng_eiface_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
361 {
362 	const priv_p priv = (priv_p)ifp->if_softc;
363 	struct ifmedia *ifm = &priv->media;
364 
365 	if (ifm->ifm_cur->ifm_media == (IFM_ETHER | IFM_AUTO) &&
366 	    (priv->link_status & IFM_ACTIVE))
367 		ifmr->ifm_active = IFM_ETHER | IFM_1000_T | IFM_FDX;
368 	else
369 		ifmr->ifm_active = ifm->ifm_cur->ifm_media;
370 	ifmr->ifm_status = priv->link_status;
371 
372 	return;
373 }
374 
375 /************************************************************************
376 			NETGRAPH NODE STUFF
377  ************************************************************************/
378 
379 /*
380  * Constructor for a node
381  */
382 static int
383 ng_eiface_constructor(node_p node)
384 {
385 	struct ifnet *ifp;
386 	priv_p priv;
387 	struct ether_addr eaddr;
388 
389 	/* Allocate node and interface private structures */
390 	priv = malloc(sizeof(*priv), M_NETGRAPH, M_WAITOK | M_ZERO);
391 
392 	ifp = priv->ifp = if_alloc(IFT_ETHER);
393 	if (ifp == NULL) {
394 		free(priv, M_NETGRAPH);
395 		return (ENOSPC);
396 	}
397 
398 	/* Link them together */
399 	ifp->if_softc = priv;
400 
401 	/* Get an interface unit number */
402 	priv->unit = alloc_unr(V_ng_eiface_unit);
403 
404 	/* Link together node and private info */
405 	NG_NODE_SET_PRIVATE(node, priv);
406 	priv->node = node;
407 
408 	/* Initialize interface structure */
409 	if_initname(ifp, NG_EIFACE_EIFACE_NAME, priv->unit);
410 	ifp->if_init = ng_eiface_init;
411 	ifp->if_output = ether_output;
412 	ifp->if_start = ng_eiface_start;
413 	ifp->if_ioctl = ng_eiface_ioctl;
414 	ifp->if_snd.ifq_maxlen = ifqmaxlen;
415 	ifp->if_flags = (IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST);
416 	ifp->if_capabilities = IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU;
417 	ifp->if_capenable = IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU;
418 	ifmedia_init(&priv->media, 0, ng_eiface_mediachange,
419 	    ng_eiface_mediastatus);
420 	ifmedia_add(&priv->media, IFM_ETHER | IFM_10_T, 0, NULL);
421 	ifmedia_add(&priv->media, IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL);
422 	ifmedia_add(&priv->media, IFM_ETHER | IFM_100_TX, 0, NULL);
423 	ifmedia_add(&priv->media, IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL);
424 	ifmedia_add(&priv->media, IFM_ETHER | IFM_1000_T, 0, NULL);
425 	ifmedia_add(&priv->media, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
426 	ifmedia_add(&priv->media, IFM_ETHER | IFM_10G_T | IFM_FDX, 0, NULL);
427 	ifmedia_add(&priv->media, IFM_ETHER | IFM_AUTO, 0, NULL);
428 	ifmedia_set(&priv->media, IFM_ETHER | IFM_AUTO);
429 	priv->link_status = IFM_AVALID;
430 
431 	/* Give this node the same name as the interface (if possible) */
432 	if (ng_name_node(node, ifp->if_xname) != 0)
433 		log(LOG_WARNING, "%s: can't acquire netgraph name\n",
434 		    ifp->if_xname);
435 
436 	/* Attach the interface */
437 	ether_gen_addr(ifp, &eaddr);
438 	ether_ifattach(ifp, eaddr.octet);
439 	ifp->if_baudrate = ifmedia_baudrate(IFM_ETHER | IFM_1000_T);
440 
441 	/* Done */
442 	return (0);
443 }
444 
445 /*
446  * Give our ok for a hook to be added
447  */
448 static int
449 ng_eiface_newhook(node_p node, hook_p hook, const char *name)
450 {
451 	priv_p priv = NG_NODE_PRIVATE(node);
452 	struct ifnet *ifp = priv->ifp;
453 
454 	if (strcmp(name, NG_EIFACE_HOOK_ETHER))
455 		return (EPFNOSUPPORT);
456 	if (priv->ether != NULL)
457 		return (EISCONN);
458 	priv->ether = hook;
459 	NG_HOOK_SET_PRIVATE(hook, &priv->ether);
460 	NG_HOOK_SET_TO_INBOUND(hook);
461 
462 	priv->link_status |= IFM_ACTIVE;
463 	CURVNET_SET_QUIET(ifp->if_vnet);
464 	if_link_state_change(ifp, LINK_STATE_UP);
465 	CURVNET_RESTORE();
466 
467 	return (0);
468 }
469 
470 /*
471  * Receive a control message
472  */
473 static int
474 ng_eiface_rcvmsg(node_p node, item_p item, hook_p lasthook)
475 {
476 	const priv_p priv = NG_NODE_PRIVATE(node);
477 	struct ifnet *const ifp = priv->ifp;
478 	struct ng_mesg *resp = NULL;
479 	int error = 0;
480 	struct ng_mesg *msg;
481 
482 	NGI_GET_MSG(item, msg);
483 	switch (msg->header.typecookie) {
484 	case NGM_EIFACE_COOKIE:
485 		switch (msg->header.cmd) {
486 		case NGM_EIFACE_SET:
487 		    {
488 			if (msg->header.arglen != ETHER_ADDR_LEN) {
489 				error = EINVAL;
490 				break;
491 			}
492 			error = if_setlladdr(priv->ifp,
493 			    (u_char *)msg->data, ETHER_ADDR_LEN);
494 			break;
495 		    }
496 
497 		case NGM_EIFACE_GET_IFNAME:
498 			NG_MKRESPONSE(resp, msg, IFNAMSIZ, M_NOWAIT);
499 			if (resp == NULL) {
500 				error = ENOMEM;
501 				break;
502 			}
503 			strlcpy(resp->data, ifp->if_xname, IFNAMSIZ);
504 			break;
505 
506 		case NGM_EIFACE_GET_IFADDRS:
507 		    {
508 			struct epoch_tracker et;
509 			struct ifaddr *ifa;
510 			caddr_t ptr;
511 			int buflen;
512 
513 			/* Determine size of response and allocate it */
514 			buflen = 0;
515 			NET_EPOCH_ENTER(et);
516 			CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
517 				buflen += SA_SIZE(ifa->ifa_addr);
518 			NG_MKRESPONSE(resp, msg, buflen, M_NOWAIT);
519 			if (resp == NULL) {
520 				NET_EPOCH_EXIT(et);
521 				error = ENOMEM;
522 				break;
523 			}
524 
525 			/* Add addresses */
526 			ptr = resp->data;
527 			CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
528 				const int len = SA_SIZE(ifa->ifa_addr);
529 
530 				if (buflen < len) {
531 					log(LOG_ERR, "%s: len changed?\n",
532 					    ifp->if_xname);
533 					break;
534 				}
535 				bcopy(ifa->ifa_addr, ptr, len);
536 				ptr += len;
537 				buflen -= len;
538 			}
539 			NET_EPOCH_EXIT(et);
540 			break;
541 		    }
542 
543 		default:
544 			error = EINVAL;
545 			break;
546 		} /* end of inner switch() */
547 		break;
548 	case NGM_FLOW_COOKIE:
549 		CURVNET_SET_QUIET(ifp->if_vnet);
550 		switch (msg->header.cmd) {
551 		case NGM_LINK_IS_UP:
552 			priv->link_status |= IFM_ACTIVE;
553 			if_link_state_change(ifp, LINK_STATE_UP);
554 			break;
555 		case NGM_LINK_IS_DOWN:
556 			priv->link_status &= ~IFM_ACTIVE;
557 			if_link_state_change(ifp, LINK_STATE_DOWN);
558 			break;
559 		default:
560 			break;
561 		}
562 		CURVNET_RESTORE();
563 		break;
564 	default:
565 		error = EINVAL;
566 		break;
567 	}
568 	NG_RESPOND_MSG(error, node, item, resp);
569 	NG_FREE_MSG(msg);
570 	return (error);
571 }
572 
573 /*
574  * Receive data from a hook. Pass the packet to the ether_input routine.
575  */
576 static int
577 ng_eiface_rcvdata(hook_p hook, item_p item)
578 {
579 	const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
580 	struct ifnet *const ifp = priv->ifp;
581 	struct mbuf *m;
582 
583 	NGI_GET_M(item, m);
584 	NG_FREE_ITEM(item);
585 
586 	if (!((ifp->if_flags & IFF_UP) &&
587 	    (ifp->if_drv_flags & IFF_DRV_RUNNING))) {
588 		NG_FREE_M(m);
589 		return (ENETDOWN);
590 	}
591 
592 	if (m->m_len < ETHER_HDR_LEN) {
593 		m = m_pullup(m, ETHER_HDR_LEN);
594 		if (m == NULL)
595 			return (EINVAL);
596 	}
597 
598 	/* Note receiving interface */
599 	m->m_pkthdr.rcvif = ifp;
600 
601 	/* Update interface stats */
602 	if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
603 
604 	(*ifp->if_input)(ifp, m);
605 
606 	/* Done */
607 	return (0);
608 }
609 
610 /*
611  * Shutdown processing.
612  */
613 static int
614 ng_eiface_rmnode(node_p node)
615 {
616 	const priv_p priv = NG_NODE_PRIVATE(node);
617 	struct ifnet *const ifp = priv->ifp;
618 
619 	/*
620 	 * the ifnet may be in a different vnet than the netgraph node,
621 	 * hence we have to change the current vnet context here.
622 	 */
623 	CURVNET_SET_QUIET(ifp->if_vnet);
624 	ether_ifdetach(ifp);
625 	ifmedia_removeall(&priv->media);
626 	if_free(ifp);
627 	CURVNET_RESTORE();
628 	free_unr(V_ng_eiface_unit, priv->unit);
629 	free(priv, M_NETGRAPH);
630 	NG_NODE_SET_PRIVATE(node, NULL);
631 	NG_NODE_UNREF(node);
632 	return (0);
633 }
634 
635 /*
636  * Hook disconnection
637  */
638 static int
639 ng_eiface_disconnect(hook_p hook)
640 {
641 	const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
642 
643 	priv->ether = NULL;
644 	priv->link_status &= ~IFM_ACTIVE;
645 	CURVNET_SET_QUIET(priv->ifp->if_vnet);
646 	if_link_state_change(priv->ifp, LINK_STATE_DOWN);
647 	CURVNET_RESTORE();
648 	return (0);
649 }
650 
651 /*
652  * Handle loading and unloading for this node type.
653  */
654 static int
655 ng_eiface_mod_event(module_t mod, int event, void *data)
656 {
657 	int error = 0;
658 
659 	switch (event) {
660 	case MOD_LOAD:
661 	case MOD_UNLOAD:
662 		break;
663 	default:
664 		error = EOPNOTSUPP;
665 		break;
666 	}
667 	return (error);
668 }
669 
670 static void
671 vnet_ng_eiface_init(const void *unused)
672 {
673 
674 	V_ng_eiface_unit = new_unrhdr(0, 0xffff, NULL);
675 }
676 VNET_SYSINIT(vnet_ng_eiface_init, SI_SUB_PSEUDO, SI_ORDER_ANY,
677     vnet_ng_eiface_init, NULL);
678 
679 static void
680 vnet_ng_eiface_uninit(const void *unused)
681 {
682 
683 	delete_unrhdr(V_ng_eiface_unit);
684 }
685 VNET_SYSUNINIT(vnet_ng_eiface_uninit, SI_SUB_INIT_IF, SI_ORDER_ANY,
686    vnet_ng_eiface_uninit, NULL);
687