NG_ONE2MANY(4)

πŸ’… ng_one2many β€” packet multiplexing netgraph node type πŸ’…

okay bestie, welcome to the ng_one2many page, straight out of the Kernel Interfaces Manual. sit down, grab a strawberry πŸ“, we're gonna talk about packet multiplexing and it's gonna be adorable.


✨ SYNOPSIS ✨

#include <sys/types.h>
#include <netgraph/ng_one2many.h>

🌸 DESCRIPTION 🌸

so one2many is literally the chillest little mechanism for routing packets over several links, one-to-many style β€” and in the reverse direction, many-to-one, because it contains multitudes πŸ’œ. there's a single hook called one, and then a whole squad of hooks called many0, many1, etc.

the vibe check: packets that show up on any of the many hooks get forwarded out the one hook. packets that show up on the one hook get forwarded out one or more of the many hooks β€” and which hook(s) get the honor is decided by the node's configured transmit algorithm. and no cap: packets are not altered in any way. not a single byte touched. iconic behavior, honestly. πŸ‘‘

each of the connected many links can be considered up or down. packets are never delivered out a many hook that's down. it's giving "no entry, we're closed" 🚫. how a link gets determined to be up or down depends on the node's configured link failure detection algorithm.

now, before an interface or link can be plumbed into a group, its status must be marked as being "up". this is normally set up during the initial boot stages by rc.conf(5). it's also possible to change an interface's status to "up" by using the ifconfig(8) utility. slay. πŸ’…


πŸ¦‹ TRANSMIT ALGORITHMS πŸ¦‹

  • NG_ONE2MANY_XMIT_ROUNDROBIN β€” packets are delivered out the many hooks in sequential order. each packet goes out on a different many hook. taking turns, as one does. πŸŽ€
  • NG_ONE2MANY_XMIT_ALL β€” packets are delivered out all the many hooks. each packet goes out each many hook. it's giving "invite the whole group chat". πŸ’–
  • NG_ONE2MANY_XMIT_FAILOVER β€” packets are delivered out the first active many hook. main character energy, one link at a time. ⭐

in the future other algorithms may be added as well. πŸ‘€


the node distinguishes between active and failed links. data is sent only to active links. the following link failure detection algorithms are available:

  • NG_ONE2MANY_FAIL_MANUAL β€” the node is explicitly told which of the links are up via the NGM_ONE2MANY_SET_CONFIG control message (see below). newly connected links are down until configured otherwise. no assumptions, just receipts. πŸ“‹
  • NG_ONE2MANY_FAIL_NOTIFY β€” the node listens to flow control message from many hooks, and considers link failed if NGM_LINK_IS_DOWN is received. if the NGM_LINK_IS_UP message is received, node considers link active. so basically it's just listening to the gossip. πŸ™ˆ

in the future other algorithms may be added as well. 🌈

when all links are considered failed, node sends the NGM_LINK_IS_DOWN message towards the one hook. when at least one link comes up, node sends the NGM_LINK_IS_UP message towards the one hook. it's keeping everyone posted, fr fr. πŸ’¬


πŸŽ€ HOOKS πŸŽ€

this node type supports up to NG_ONE2MANY_MAX_LINKS hooks named many0, many1, etc., plus a single hook named one.


πŸ’… CONTROL MESSAGES πŸ’…

this node type supports the generic control messages, plus the following:

  • NGM_ONE2MANY_SET_CONFIG (setconfig) β€” sets the node configuration using a struct ng_one2many_link_config as the control message argument:
/* Node configuration structure */
struct ng_one2many_config {
  uint32_t    xmitAlg;        /* how to distribute packets */
  uint32_t    failAlg;        /* how to detect link failure */
  u_char      enabledLinks[NG_ONE2MANY_MAX_LINKS];
};

currently, the valid settings for the xmitAlg field are NG_ONE2MANY_XMIT_ROUNDROBIN (default) or NG_ONE2MANY_XMIT_ALL. the valid settings for failAlg are NG_ONE2MANY_FAIL_MANUAL (default) or NG_ONE2MANY_FAIL_NOTIFY. defaults are your friends, bestie. 🫢

  • NGM_ONE2MANY_GET_CONFIG (getconfig) β€” returns the current node configuration in a struct ng_one2many_link_config. tell me everything, no gatekeeping. πŸ‘‘
  • NGM_ONE2MANY_GET_STATS (getstats) β€” this command takes a 32 bit link number as an argument and returns a struct ng_one2many_link_stats containing statistics for the corresponding many link, which may or may not be currently connected:
/* Statistics structure (one for each link) */
struct ng_one2many_link_stats {
  uint64_t   recvOctets;     /* total octets rec'd on link */
  uint64_t   recvPackets;    /* total pkts rec'd on link */
  uint64_t   xmitOctets;     /* total octets xmit'd on link */
  uint64_t   xmitPackets;    /* total pkts xmit'd on link */
  uint64_t   memoryFailures; /* times couldn't get mem or mbuf */
};

to access statistics for the one link, use the link number -1. yes, negative one. it's quirky like that. 😭

  • NGM_ONE2MANY_CLR_STATS (clrstats) β€” this command takes a 32 bit link number as an argument and clears the statistics for that link. fresh start, we love a reset. ✨
  • NGM_ONE2MANY_GETCLR_STATS (getclrstats) β€” same as NGM_ONE2MANY_GET_STATS, but also atomically clears the statistics for the link as well. grab and wipe in one flawless motion. πŸ’€

🌈 SHUTDOWN 🌈

this node shuts down upon receipt of a NGM_SHUTDOWN control message, or when all hooks have been disconnected. bye bestie, it was real. πŸ¦‹


⭐ EXAMPLES ⭐

the following commands will set up Ethernet interfaces fxp0 to deliver packets alternating over the physical interfaces corresponding to networking interfaces fxp0 through fxp3:

# Plumb nodes together

ngctl mkpeer fxp0: one2many upper one
ngctl connect fxp0: fxp0:upper lower many0
ngctl connect fxp1: fxp0:upper lower many1
ngctl connect fxp2: fxp0:upper lower many2
ngctl connect fxp3: fxp0:upper lower many3

# Allow fxp1 through fxp3 to xmit/recv fxp0 frames

ngctl msg fxp1: setpromisc 1
ngctl msg fxp2: setpromisc 1
ngctl msg fxp3: setpromisc 1
ngctl msg fxp1: setautosrc 0
ngctl msg fxp2: setautosrc 0
ngctl msg fxp3: setautosrc 0

# Configure all four links as up

ngctl msg fxp0:upper \
  setconfig "{ xmitAlg=1 failAlg=1 enabledLinks=[ 1 1 1 1 ] }"

# Bring up interface

ifconfig fxp0 192.168.1.1 netmask 0xfffffffc

with a similar setup on a peer machine (using the address 192.168.1.2), a point-to-point Ethernet connection with four times normal bandwidth is achieved. four times!! ate and left no crumbs. πŸ”₯


πŸ‘‘ SEE ALSO πŸ‘‘

netgraph(4), ng_bridge(4), ng_ether(4), ng_hub(4), ifconfig(8), ngctl(8)


πŸ’œ HISTORY πŸ’œ

the ng_one2many node type was implemented in FreeBSD 4.2. vintage, but make it fashion. πŸŽ€


πŸ“ AUTHORS πŸ“

the one2many netgraph node (with round-robin algorithm) was written by Archie Cobbs <archie@FreeBSD.org>. the all algorithm was added by Rogier R. Mulhuijzen <drwilco@drwilco.net>. legends, both of them. 🫢


πŸ’€ BUGS πŸ’€

more transmit and link failure algorithms should be supported. a good candidate is Cisco's Etherchannel. noted, bestie, adding it to the list. πŸ“


and that's the whole page, babes β€” this one's from the Debian crew, dated November 13, 2012, and it lives in section 4 of the manual (kernel interfaces, if you were wondering). go forth and multiplex responsibly. mwah πŸ’‹

πŸ“¦ where this page comes from