Lines Matching +full:interface +full:- +full:node

6 /*-
7 * Copyright (c) 1996-2000 Whistle Communications, Inc.
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
44 * ng_ether(4) netgraph node type
76 #define IFP2NG(ifp) ((ifp)->if_l2com)
78 /* Per-node private data */
80 struct ifnet *ifp; /* associated interface */
108 static int ng_ether_rcv_lower(hook_p node, item_p item);
109 static int ng_ether_rcv_upper(hook_p node, item_p item);
111 /* Netgraph node methods */
241 * Handle a packet that has come in on an interface. We get to
247 const node_p node = IFP2NG(ifp); in ng_ether_input() local
248 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_input()
252 if (priv->lower == NULL) in ng_ether_input()
254 NG_SEND_DATA_ONLY(error, priv->lower, *mp); /* sets *mp = NULL */ in ng_ether_input()
258 * Handle a packet that has come in on an interface, and which
264 const node_p node = IFP2NG(ifp); in ng_ether_input_orphan() local
265 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_input_orphan()
269 if (priv->orphan == NULL) { in ng_ether_input_orphan()
273 NG_SEND_DATA_ONLY(error, priv->orphan, m); in ng_ether_input_orphan()
277 * Handle a packet that is going out on an interface.
283 const node_p node = IFP2NG(ifp); in ng_ether_output() local
284 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_output()
288 if (priv->upper == NULL) in ng_ether_output()
293 NG_SEND_DATA_ONLY(error, priv->upper, *mp); in ng_ether_output()
299 * A new Ethernet interface has been attached.
300 * Create a new node for it, etc.
307 node_p node; in ng_ether_attach() local
310 * Do not create / attach an ether node to this ifnet if in ng_ether_attach()
311 * a netgraph node with the same name already exists. in ng_ether_attach()
316 ng_ether_sanitize_ifname(ifp->if_xname, name); in ng_ether_attach()
317 if ((node = ng_name2noderef(NULL, name)) != NULL) { in ng_ether_attach()
318 NG_NODE_UNREF(node); in ng_ether_attach()
322 /* Create node */ in ng_ether_attach()
323 KASSERT(!IFP2NG(ifp), ("%s: node already exists?", __func__)); in ng_ether_attach()
324 if (ng_make_node_common(&ng_ether_typestruct, &node) != 0) { in ng_ether_attach()
326 __func__, "create node", ifp->if_xname); in ng_ether_attach()
334 __func__, "allocate memory", ifp->if_xname); in ng_ether_attach()
335 NG_NODE_UNREF(node); in ng_ether_attach()
338 NG_NODE_SET_PRIVATE(node, priv); in ng_ether_attach()
339 priv->ifp = ifp; in ng_ether_attach()
340 IFP2NG(ifp) = node; in ng_ether_attach()
341 priv->hwassist = ifp->if_hwassist; in ng_ether_attach()
343 /* Try to give the node the same name as the interface */ in ng_ether_attach()
344 if (ng_name_node(node, name) != 0) in ng_ether_attach()
345 log(LOG_WARNING, "%s: can't name node %s\n", __func__, name); in ng_ether_attach()
349 * An Ethernet interface is being detached.
350 * REALLY Destroy its node.
355 const node_p node = IFP2NG(ifp); in ng_ether_detach() local
356 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_detach()
358 taskqueue_drain(taskqueue_swi, &ifp->if_linktask); in ng_ether_detach()
359 NG_NODE_REALLY_DIE(node); /* Force real removal of node */ in ng_ether_detach()
366 priv->ifp = NULL; /* XXX race if interrupted an output packet */ in ng_ether_detach()
367 ng_rmnode_self(node); /* remove all netgraph parts */ in ng_ether_detach()
377 const node_p node = IFP2NG(ifp); in ng_ether_link_state() local
378 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_link_state()
389 if (priv->lower != NULL) { in ng_ether_link_state()
392 NG_SEND_MSG_HOOK(dummy_error, node, msg, priv->lower, 0); in ng_ether_link_state()
394 if (priv->orphan != NULL) { in ng_ether_link_state()
397 NG_SEND_MSG_HOOK(dummy_error, node, msg, priv->orphan, 0); in ng_ether_link_state()
402 * Interface arrival notification handler.
404 * o a new interface arrives
405 * o an existing interface got renamed
413 node_p node; in ng_ether_ifnet_arrival_event() local
416 if (ifp->if_type != IFT_ETHER && in ng_ether_ifnet_arrival_event()
417 ifp->if_type != IFT_L2VLAN && in ng_ether_ifnet_arrival_event()
418 ifp->if_type != IFT_BRIDGE) in ng_ether_ifnet_arrival_event()
422 * Just return if it's a new interface without an ng_ether companion. in ng_ether_ifnet_arrival_event()
424 node = IFP2NG(ifp); in ng_ether_ifnet_arrival_event()
425 if (node == NULL) in ng_ether_ifnet_arrival_event()
428 /* Try to give the node the same name as the new interface name */ in ng_ether_ifnet_arrival_event()
429 ng_ether_sanitize_ifname(ifp->if_xname, name); in ng_ether_ifnet_arrival_event()
430 if (ng_name_node(node, name) != 0) in ng_ether_ifnet_arrival_event()
431 log(LOG_WARNING, "%s: can't re-name node %s\n", __func__, name); in ng_ether_ifnet_arrival_event()
435 NETGRAPH NODE METHODS
439 * It is not possible or allowable to create a node of this type.
440 * Nodes get created when the interface is attached (or, when
441 * this node type's KLD is loaded).
444 ng_ether_constructor(node_p node) in ng_ether_constructor() argument
453 ng_ether_newhook(node_p node, hook_p hook, const char *name) in ng_ether_newhook() argument
455 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_newhook()
464 hookptr = &priv->upper; in ng_ether_newhook()
468 hookptr = &priv->lower; in ng_ether_newhook()
471 hookptr = &priv->orphan; in ng_ether_newhook()
481 if (hookptr == &priv->upper) in ng_ether_newhook()
482 priv->ifp->if_hwassist = 0; in ng_ether_newhook()
493 ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook) in ng_ether_rcvmsg() argument
495 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_rcvmsg()
501 switch (msg->header.typecookie) { in ng_ether_rcvmsg()
503 switch (msg->header.cmd) { in ng_ether_rcvmsg()
510 strlcpy(resp->data, priv->ifp->if_xname, IFNAMSIZ); in ng_ether_rcvmsg()
518 *((u_int32_t *)resp->data) = priv->ifp->if_index; in ng_ether_rcvmsg()
526 bcopy(IF_LLADDR(priv->ifp), in ng_ether_rcvmsg()
527 resp->data, ETHER_ADDR_LEN); in ng_ether_rcvmsg()
531 if (msg->header.arglen != ETHER_ADDR_LEN) { in ng_ether_rcvmsg()
535 error = if_setlladdr(priv->ifp, in ng_ether_rcvmsg()
536 (u_char *)msg->data, ETHER_ADDR_LEN); in ng_ether_rcvmsg()
545 *((u_int32_t *)resp->data) = priv->promisc; in ng_ether_rcvmsg()
551 if (msg->header.arglen != sizeof(u_int32_t)) { in ng_ether_rcvmsg()
555 want = !!*((u_int32_t *)msg->data); in ng_ether_rcvmsg()
556 if (want ^ priv->promisc) { in ng_ether_rcvmsg()
557 if ((error = ifpromisc(priv->ifp, want)) != 0) in ng_ether_rcvmsg()
559 priv->promisc = want; in ng_ether_rcvmsg()
569 *((u_int32_t *)resp->data) = priv->autoSrcAddr; in ng_ether_rcvmsg()
572 if (msg->header.arglen != sizeof(u_int32_t)) { in ng_ether_rcvmsg()
576 priv->autoSrcAddr = !!*((u_int32_t *)msg->data); in ng_ether_rcvmsg()
584 if (msg->header.arglen != ETHER_ADDR_LEN) { in ng_ether_rcvmsg()
592 bcopy((void *)msg->data, LLADDR(&sa_dl), in ng_ether_rcvmsg()
602 ifma = if_findmulti(priv->ifp, in ng_ether_rcvmsg()
608 error = if_addmulti(priv->ifp, in ng_ether_rcvmsg()
617 if (msg->header.arglen != ETHER_ADDR_LEN) { in ng_ether_rcvmsg()
625 bcopy((void *)msg->data, LLADDR(&sa_dl), in ng_ether_rcvmsg()
627 error = if_delmulti(priv->ifp, in ng_ether_rcvmsg()
632 ng_ether_detach(priv->ifp); in ng_ether_rcvmsg()
643 NG_RESPOND_MSG(error, node, item, resp); in ng_ether_rcvmsg()
650 * Since we use per-hook recveive methods this should never be called.
667 const node_p node = NG_HOOK_NODE(hook); in ng_ether_rcv_lower() local
668 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_rcv_lower()
669 struct ifnet *const ifp = priv->ifp; in ng_ether_rcv_lower()
674 /* Check whether interface is ready for packets */ in ng_ether_rcv_lower()
676 if (!((ifp->if_flags & IFF_UP) && in ng_ether_rcv_lower()
677 (ifp->if_drv_flags & IFF_DRV_RUNNING))) { in ng_ether_rcv_lower()
683 if (m->m_pkthdr.len < sizeof(struct ether_header)) { in ng_ether_rcv_lower()
687 if (m->m_len < sizeof(struct ether_header) in ng_ether_rcv_lower()
692 if (priv->autoSrcAddr) { in ng_ether_rcv_lower()
700 mtod(m, struct ether_header *)->ether_shost, in ng_ether_rcv_lower()
715 const node_p node = NG_HOOK_NODE(hook); in ng_ether_rcv_upper() local
716 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_rcv_upper()
717 struct ifnet *ifp = priv->ifp; in ng_ether_rcv_upper()
723 if (m->m_pkthdr.len < sizeof(struct ether_header)) { in ng_ether_rcv_upper()
727 if (m->m_len < sizeof(struct ether_header) && in ng_ether_rcv_upper()
731 m->m_pkthdr.rcvif = ifp; in ng_ether_rcv_upper()
734 if (ifp->if_bridge) { in ng_ether_rcv_upper()
746 * Shutdown node. This resets the node but does not remove it
750 ng_ether_shutdown(node_p node) in ng_ether_shutdown() argument
752 const priv_p priv = NG_NODE_PRIVATE(node); in ng_ether_shutdown()
754 if (node->nd_flags & NGF_REALLY_DIE) { in ng_ether_shutdown()
759 NG_NODE_SET_PRIVATE(node, NULL); in ng_ether_shutdown()
760 if (priv->ifp != NULL) in ng_ether_shutdown()
761 IFP2NG(priv->ifp) = NULL; in ng_ether_shutdown()
763 NG_NODE_UNREF(node); /* free node itself */ in ng_ether_shutdown()
766 if (priv->promisc) { /* disable promiscuous mode */ in ng_ether_shutdown()
767 (void)ifpromisc(priv->ifp, 0); in ng_ether_shutdown()
768 priv->promisc = 0; in ng_ether_shutdown()
770 NG_NODE_REVIVE(node); /* Signal ng_rmnode we are persisant */ in ng_ether_shutdown()
783 if (hook == priv->upper) { in ng_ether_disconnect()
784 priv->upper = NULL; in ng_ether_disconnect()
785 if (priv->ifp != NULL) /* restore h/w csum */ in ng_ether_disconnect()
786 priv->ifp->if_hwassist = priv->hwassist; in ng_ether_disconnect()
787 } else if (hook == priv->lower) in ng_ether_disconnect()
788 priv->lower = NULL; in ng_ether_disconnect()
789 else if (hook == priv->orphan) in ng_ether_disconnect()
790 priv->orphan = NULL; in ng_ether_disconnect()
795 ng_rmnode_self(NG_HOOK_NODE(hook)); /* reset node */ in ng_ether_disconnect()
804 * Handle loading and unloading for this node type.
869 /* Create nodes for any already-existing Ethernet interfaces. */ in vnet_ng_ether_init()
872 if (ifp->if_type == IFT_ETHER || in vnet_ng_ether_init()
873 ifp->if_type == IFT_L2VLAN || in vnet_ng_ether_init()
874 ifp->if_type == IFT_BRIDGE) in vnet_ng_ether_init()