NG_IFACE(4)

πŸ’… NG_IFACE(4) β€” bestie edition πŸ’…

okay so this is the manual page for ng_iface, and it lives in the Kernel Interfaces Manual section of the docs (that's the (4) energy, iykyk). it's giving netgraph node type realness. let's get into it 🫢


✨ NAME ✨

ng_iface β€” the interface netgraph node type. yes bestie, it's a whole node type. iconic behavior.


✨ SYNOPSIS ✨

#include <netgraph/ng_iface.h>

that's it. that's the whole vibe. go include the header and slay πŸ’–


✨ DESCRIPTION ✨

so an iface node is literally two things at once: a netgraph node AND a system networking interface. main character duality fr fr πŸ‘‘

the way that when an iface node gets created, a brand new interface just appears, and you can reach it with ifconfig(8). these iface node interfaces are named ng0, ng1, etc. when a node gets shut down, the matching interface goes away too, and that interface name becomes available again for future iface nodes to snatch up β€” new nodes always take the first unused interface, no cap. and the node itself gets the same name as its interface, unless that name already exists, in which case the node just stays unnamed. awkward but okay πŸ™ˆ

an iface node has a single hook corresponding to each supported protocol. packets you transmit via the interface flow out the corresponding protocol-specific hook. and same energy the other way: packets received on a hook show up on the interface as packets received into the corresponding protocol stack. the currently supported protocols are IP and IPv6 ✨

an iface node can be configured as a point-to-point interface or a broadcast interface. lowkey important: the configuration can only be changed when the interface is down. and the default mode is point-to-point, periodt.

also iface nodes support the Berkeley Packet Filter (BPF). we love to see it πŸŽ€


πŸ¦‹ HOOKS πŸ¦‹

this node type supports the following hooks, bestie:

  • inet β€” transmission and reception of IP packets.
  • inet6 β€” transmission and reception of IPv6 packets.

two hooks, both gorgeous, both thriving 🌸


πŸ’Œ CONTROL MESSAGES πŸ’Œ

this node type supports the generic control messages, plus these lil guys:

  • NGM_IFACE_GET_IFNAME (getifname) β€” returns the name of the associated interface as a NUL-terminated ASCII string. normally this is the same as the name of the node.
  • NGM_IFACE_GET_IFINDEX (getifindex) β€” returns the global index of the associated interface as a 32 bit integer.
  • NGM_IFACE_POINT2POINT (point2point) β€” sets the interface to point-to-point mode. the interface must not currently be up.
  • NGM_IFACE_BROADCAST (broadcast) β€” sets the interface to broadcast mode. the interface must not currently be up.
⚠️ notice how both mode-setting messages need the interface to be DOWN first? yeah. try it while it's up and it's not gonna work, bestie. take it down first πŸ’…

πŸ’€ SHUTDOWN πŸ’€

this node shuts down upon receipt of a NGM_SHUTDOWN control message. the associated interface gets removed and becomes available for use by future iface nodes. bye bye, you were gorgeous 🫢

and here's the plot twist: unlike most other node types, an iface node does not go away when all hooks have been disconnected. nope. it needs an explicit NGM_SHUTDOWN control message. it's clingy like that 😭


🌈 ALTQ Support 🌈

the ng_iface interface supports the ALTQ bandwidth management feature. BUT β€” and this is the important part, don't skip it β€” ng_iface is a special case, since it is not a physical interface with limited bandwidth. 🚨

so one should not turn ALTQ on ng_iface if the latter corresponds to some tunneled connection, e.g. PPPoE or PPTP. in that case, ALTQ should be configured on the interface that is used to transmit the encapsulated packets. but! in case when your graph ends up with some kind of serial line, either synchronous or modem, the ng_iface is the right place to turn ALTQ on. so basically: know your graph, bestie 🧚


πŸŽ€ Nesting πŸŽ€

ng_iface supports nesting, which is a configuration when traffic of one ng_iface interface flows through the other. the default maximum allowed nesting level is 2. it can be changed at runtime by setting the sysctl(8) variable net.graph.iface.max_nesting to the desired level of nesting.

levels, bestie. levels πŸ’œ


πŸ‘€ SEE ALSO πŸ‘€

altq(4), bpf(4), netgraph(4), ng_cisco(4), ifconfig(8), ngctl(8) sysctl

go read those too, they're all part of the lore πŸ“š


⭐ HISTORY ⭐

the iface node type was implemented in FreeBSD 4.0. ancient. legendary. still serving πŸ’…


πŸ‘‘ AUTHORS πŸ‘‘

Archie Cobbs <archie@FreeBSD.org> β€” thank you for your service, king 🫑


and that's the whole page, bestie! this one came from the Debian build of the docs, dated July 31, 2020. mwah, go configure something cute πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from