Lines Matching +full:interface +full:- +full:node
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 1999-2001, Vitaly V Belekhov
80 /* Node private data */
82 struct ifnet *ifp; /* per-interface network data */
85 int unit; /* Interface unit number */
86 node_p node; /* Our netgraph node */ member
91 /* Interface methods */
108 /* Node type descriptor */
127 INTERFACE STUFF
131 * Process an ioctl for the virtual interface
136 const priv_p priv = (priv_p)ifp->if_softc; in ng_eiface_ioctl()
154 * If the interface is marked up and stopped, then start it. in ng_eiface_ioctl()
157 if (ifp->if_flags & IFF_UP) { in ng_eiface_ioctl()
158 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { in ng_eiface_ioctl()
159 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE); in ng_eiface_ioctl()
160 ifp->if_drv_flags |= IFF_DRV_RUNNING; in ng_eiface_ioctl()
163 if (ifp->if_drv_flags & IFF_DRV_RUNNING) in ng_eiface_ioctl()
164 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | in ng_eiface_ioctl()
169 /* Set the interface MTU */ in ng_eiface_ioctl()
171 if (ifr->ifr_mtu > NG_EIFACE_MTU_MAX || in ng_eiface_ioctl()
172 ifr->ifr_mtu < NG_EIFACE_MTU_MIN) in ng_eiface_ioctl()
175 ifp->if_mtu = ifr->ifr_mtu; in ng_eiface_ioctl()
181 error = ifmedia_ioctl(ifp, ifr, &priv->media, command); in ng_eiface_ioctl()
204 struct ifnet *ifp = sc->ifp; in ng_eiface_init()
206 ifp->if_drv_flags |= IFF_DRV_RUNNING; in ng_eiface_init()
207 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; in ng_eiface_init()
213 * be the only code running in this node at this time.
216 ng_eiface_start2(node_p node, hook_p hook, void *arg1, int arg2) in ng_eiface_start2() argument
219 const priv_p priv = (priv_p)ifp->if_softc; in ng_eiface_start2()
223 /* Check interface flags */ in ng_eiface_start2()
225 if (!((ifp->if_flags & IFF_UP) && in ng_eiface_start2()
226 (ifp->if_drv_flags & IFF_DRV_RUNNING))) in ng_eiface_start2()
233 IF_DEQUEUE(&ifp->if_snd, m); in ng_eiface_start2()
249 if (ifp->if_flags & IFF_MONITOR) { in ng_eiface_start2()
260 CURVNET_SET_QUIET(priv->node->nd_vnet); in ng_eiface_start2()
261 NG_SEND_DATA_ONLY(error, priv->ether, m); in ng_eiface_start2()
272 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; in ng_eiface_start2()
278 * This routine is called to deliver a packet out the interface.
293 const priv_p priv = (priv_p)ifp->if_softc; in ng_eiface_start()
296 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) in ng_eiface_start()
299 ifp->if_drv_flags |= IFF_DRV_OACTIVE; in ng_eiface_start()
301 if (ng_send_fn(priv->node, NULL, &ng_eiface_start2, ifp, 0) != 0) in ng_eiface_start()
302 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; in ng_eiface_start()
307 * Display an ioctl to the virtual interface
332 ifp->if_xname, in ng_eiface_print_ioctl()
346 const priv_p priv = (priv_p)ifp->if_softc; in ng_eiface_mediachange()
347 struct ifmedia *ifm = &priv->media; in ng_eiface_mediachange()
349 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) in ng_eiface_mediachange()
351 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) in ng_eiface_mediachange()
352 ifp->if_baudrate = ifmedia_baudrate(IFM_ETHER | IFM_1000_T); in ng_eiface_mediachange()
354 ifp->if_baudrate = ifmedia_baudrate(ifm->ifm_media); in ng_eiface_mediachange()
362 const priv_p priv = (priv_p)ifp->if_softc; in ng_eiface_mediastatus()
363 struct ifmedia *ifm = &priv->media; in ng_eiface_mediastatus()
365 if (ifm->ifm_cur->ifm_media == (IFM_ETHER | IFM_AUTO) && in ng_eiface_mediastatus()
366 (priv->link_status & IFM_ACTIVE)) in ng_eiface_mediastatus()
367 ifmr->ifm_active = IFM_ETHER | IFM_1000_T | IFM_FDX; in ng_eiface_mediastatus()
369 ifmr->ifm_active = ifm->ifm_cur->ifm_media; in ng_eiface_mediastatus()
370 ifmr->ifm_status = priv->link_status; in ng_eiface_mediastatus()
376 NETGRAPH NODE STUFF
380 * Constructor for a node
383 ng_eiface_constructor(node_p node) in ng_eiface_constructor() argument
389 /* Allocate node and interface private structures */ in ng_eiface_constructor()
391 ifp = priv->ifp = if_alloc(IFT_ETHER); in ng_eiface_constructor()
394 ifp->if_softc = priv; in ng_eiface_constructor()
396 /* Get an interface unit number */ in ng_eiface_constructor()
397 priv->unit = alloc_unr(V_ng_eiface_unit); in ng_eiface_constructor()
399 /* Link together node and private info */ in ng_eiface_constructor()
400 NG_NODE_SET_PRIVATE(node, priv); in ng_eiface_constructor()
401 priv->node = node; in ng_eiface_constructor()
403 /* Initialize interface structure */ in ng_eiface_constructor()
404 if_initname(ifp, NG_EIFACE_EIFACE_NAME, priv->unit); in ng_eiface_constructor()
405 ifp->if_init = ng_eiface_init; in ng_eiface_constructor()
406 ifp->if_output = ether_output; in ng_eiface_constructor()
407 ifp->if_start = ng_eiface_start; in ng_eiface_constructor()
408 ifp->if_ioctl = ng_eiface_ioctl; in ng_eiface_constructor()
409 ifp->if_snd.ifq_maxlen = ifqmaxlen; in ng_eiface_constructor()
410 ifp->if_flags = (IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST); in ng_eiface_constructor()
411 ifp->if_capabilities = IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU; in ng_eiface_constructor()
412 ifp->if_capenable = IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU; in ng_eiface_constructor()
413 ifmedia_init(&priv->media, 0, ng_eiface_mediachange, in ng_eiface_constructor()
415 ifmedia_add(&priv->media, IFM_ETHER | IFM_10_T, 0, NULL); in ng_eiface_constructor()
416 ifmedia_add(&priv->media, IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL); in ng_eiface_constructor()
417 ifmedia_add(&priv->media, IFM_ETHER | IFM_100_TX, 0, NULL); in ng_eiface_constructor()
418 ifmedia_add(&priv->media, IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL); in ng_eiface_constructor()
419 ifmedia_add(&priv->media, IFM_ETHER | IFM_1000_T, 0, NULL); in ng_eiface_constructor()
420 ifmedia_add(&priv->media, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL); in ng_eiface_constructor()
421 ifmedia_add(&priv->media, IFM_ETHER | IFM_10G_T | IFM_FDX, 0, NULL); in ng_eiface_constructor()
422 ifmedia_add(&priv->media, IFM_ETHER | IFM_AUTO, 0, NULL); in ng_eiface_constructor()
423 ifmedia_set(&priv->media, IFM_ETHER | IFM_AUTO); in ng_eiface_constructor()
424 priv->link_status = IFM_AVALID; in ng_eiface_constructor()
426 /* Give this node the same name as the interface (if possible) */ in ng_eiface_constructor()
427 if (ng_name_node(node, ifp->if_xname) != 0) in ng_eiface_constructor()
429 ifp->if_xname); in ng_eiface_constructor()
431 /* Attach the interface */ in ng_eiface_constructor()
434 ifp->if_baudrate = ifmedia_baudrate(IFM_ETHER | IFM_1000_T); in ng_eiface_constructor()
444 ng_eiface_newhook(node_p node, hook_p hook, const char *name) in ng_eiface_newhook() argument
446 priv_p priv = NG_NODE_PRIVATE(node); in ng_eiface_newhook()
447 struct ifnet *ifp = priv->ifp; in ng_eiface_newhook()
451 if (priv->ether != NULL) in ng_eiface_newhook()
453 priv->ether = hook; in ng_eiface_newhook()
454 NG_HOOK_SET_PRIVATE(hook, &priv->ether); in ng_eiface_newhook()
457 priv->link_status |= IFM_ACTIVE; in ng_eiface_newhook()
458 CURVNET_SET_QUIET(ifp->if_vnet); in ng_eiface_newhook()
469 ng_eiface_rcvmsg(node_p node, item_p item, hook_p lasthook) in ng_eiface_rcvmsg() argument
471 const priv_p priv = NG_NODE_PRIVATE(node); in ng_eiface_rcvmsg()
472 struct ifnet *const ifp = priv->ifp; in ng_eiface_rcvmsg()
478 switch (msg->header.typecookie) { in ng_eiface_rcvmsg()
480 switch (msg->header.cmd) { in ng_eiface_rcvmsg()
483 if (msg->header.arglen != ETHER_ADDR_LEN) { in ng_eiface_rcvmsg()
487 error = if_setlladdr(priv->ifp, in ng_eiface_rcvmsg()
488 (u_char *)msg->data, ETHER_ADDR_LEN); in ng_eiface_rcvmsg()
498 strlcpy(resp->data, ifp->if_xname, IFNAMSIZ); in ng_eiface_rcvmsg()
511 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) in ng_eiface_rcvmsg()
512 buflen += SA_SIZE(ifa->ifa_addr); in ng_eiface_rcvmsg()
521 ptr = resp->data; in ng_eiface_rcvmsg()
522 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { in ng_eiface_rcvmsg()
523 const int len = SA_SIZE(ifa->ifa_addr); in ng_eiface_rcvmsg()
527 ifp->if_xname); in ng_eiface_rcvmsg()
530 bcopy(ifa->ifa_addr, ptr, len); in ng_eiface_rcvmsg()
532 buflen -= len; in ng_eiface_rcvmsg()
544 CURVNET_SET_QUIET(ifp->if_vnet); in ng_eiface_rcvmsg()
545 switch (msg->header.cmd) { in ng_eiface_rcvmsg()
547 priv->link_status |= IFM_ACTIVE; in ng_eiface_rcvmsg()
551 priv->link_status &= ~IFM_ACTIVE; in ng_eiface_rcvmsg()
563 NG_RESPOND_MSG(error, node, item, resp); in ng_eiface_rcvmsg()
575 struct ifnet *const ifp = priv->ifp; in ng_eiface_rcvdata()
581 if (!((ifp->if_flags & IFF_UP) && in ng_eiface_rcvdata()
582 (ifp->if_drv_flags & IFF_DRV_RUNNING))) { in ng_eiface_rcvdata()
587 if (m->m_len < ETHER_HDR_LEN) { in ng_eiface_rcvdata()
593 /* Note receiving interface */ in ng_eiface_rcvdata()
594 m->m_pkthdr.rcvif = ifp; in ng_eiface_rcvdata()
596 /* Update interface stats */ in ng_eiface_rcvdata()
599 (*ifp->if_input)(ifp, m); in ng_eiface_rcvdata()
609 ng_eiface_rmnode(node_p node) in ng_eiface_rmnode() argument
611 const priv_p priv = NG_NODE_PRIVATE(node); in ng_eiface_rmnode()
612 struct ifnet *const ifp = priv->ifp; in ng_eiface_rmnode()
615 * the ifnet may be in a different vnet than the netgraph node, in ng_eiface_rmnode()
618 CURVNET_SET_QUIET(ifp->if_vnet); in ng_eiface_rmnode()
620 ifmedia_removeall(&priv->media); in ng_eiface_rmnode()
623 free_unr(V_ng_eiface_unit, priv->unit); in ng_eiface_rmnode()
625 NG_NODE_SET_PRIVATE(node, NULL); in ng_eiface_rmnode()
626 NG_NODE_UNREF(node); in ng_eiface_rmnode()
638 priv->ether = NULL; in ng_eiface_disconnect()
639 priv->link_status &= ~IFM_ACTIVE; in ng_eiface_disconnect()
640 CURVNET_SET_QUIET(priv->ifp->if_vnet); in ng_eiface_disconnect()
641 if_link_state_change(priv->ifp, LINK_STATE_DOWN); in ng_eiface_disconnect()
647 * Handle loading and unloading for this node type.