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