MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_iface_constructor

Function ng_iface_constructor

freebsd/netgraph/ng_iface.c:519–572  ·  view source on GitHub ↗

* Constructor for a node */

Source from the content-addressed store, hash-verified

517 * Constructor for a node
518 */
519static int
520ng_iface_constructor(node_p node)
521{
522 struct ifnet *ifp;
523 priv_p priv;
524
525 /* Allocate node and interface private structures */
526 priv = malloc(sizeof(*priv), M_NETGRAPH_IFACE, M_WAITOK | M_ZERO);
527 ifp = if_alloc(IFT_PROPVIRTUAL);
528 if (ifp == NULL) {
529 free(priv, M_NETGRAPH_IFACE);
530 return (ENOMEM);
531 }
532
533 rm_init(&priv->lock, "ng_iface private rmlock");
534
535 /* Link them together */
536 ifp->if_softc = priv;
537 priv->ifp = ifp;
538
539 /* Get an interface unit number */
540 priv->unit = alloc_unr(V_ng_iface_unit);
541
542 /* Link together node and private info */
543 NG_NODE_SET_PRIVATE(node, priv);
544 priv->node = node;
545
546 /* Initialize interface structure */
547 if_initname(ifp, NG_IFACE_IFACE_NAME, priv->unit);
548 ifp->if_output = ng_iface_output;
549 ifp->if_start = ng_iface_start;
550 ifp->if_ioctl = ng_iface_ioctl;
551 ifp->if_mtu = NG_IFACE_MTU_DEFAULT;
552 ifp->if_flags = (IFF_SIMPLEX|IFF_POINTOPOINT|IFF_NOARP|IFF_MULTICAST);
553 ifp->if_type = IFT_PROPVIRTUAL; /* XXX */
554 ifp->if_addrlen = 0; /* XXX */
555 ifp->if_hdrlen = 0; /* XXX */
556 ifp->if_baudrate = 64000; /* XXX */
557 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
558 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
559 IFQ_SET_READY(&ifp->if_snd);
560
561 /* Give this node the same name as the interface (if possible) */
562 if (ng_name_node(node, ifp->if_xname) != 0)
563 log(LOG_WARNING, "%s: can't acquire netgraph name\n",
564 ifp->if_xname);
565
566 /* Attach the interface */
567 if_attach(ifp);
568 bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
569
570 /* Done */
571 return (0);
572}
573
574/*
575 * Give our ok for a hook to be added

Callers

nothing calls this directly

Calls 10

mallocFunction · 0.85
if_allocFunction · 0.85
alloc_unrFunction · 0.85
if_initnameFunction · 0.85
if_attachFunction · 0.85
bpfattachFunction · 0.85
ng_name_nodeFunction · 0.70
freeFunction · 0.50
rm_initFunction · 0.50
logFunction · 0.50

Tested by

no test coverage detected