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