NG_ASYNC(4)

πŸ’– NG_ASYNC β€” the asynchronous framing netgraph node type πŸ’–

okay bestie, sit down, hydrate, and let me tell you about this lil kernel interfaces manual page (yes it's a 4-section page, we love a system call adjacent moment) πŸ¦‹


✨ NAME ✨

ng_async β€” the asynchronous framing netgraph node type, periodt πŸ‘‘


✨ SYNOPSIS ✨

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

like, that's the whole vibe. two includes. slay. πŸ’…


✨ DESCRIPTION ✨

so the async node type does a conversion, bestie β€” it turns synchronous frames into asynchronous frames and back again, exactly how the PPP protocol defines it in RFC 1662. 🌈

asynchronous framing uses flag bytes and octet-stuffing to fake a frame-oriented connection on top of an octet-oriented asynchronous serial line. it's giving "pretending to be something you're not" and honestly? iconic.

here's how the two hooks work:

  • the node transmits and receives asynchronous data on the async hook. mbuf boundaries of incoming data are ignored (they don't matter, they're not the main character). once a complete packet has been received, it gets decoded, stripped of all its framing bytes, and transmitted out the sync hook as a single frame. clean. ✨
  • the node transmits and receives synchronous frames on the sync hook. packets received on this hook get encoded as asynchronous frames and sent out on async. received packets should start with the address and control fields, or the PPP protocol field if address and control field compression is employed, and they should contain no checksum field. 🫢
  • ok and this part is important: if the first four bytes are 0xff 0x03 0xc0 0x21 (that's an LCP protocol frame, iykyk) then complete control character escaping is enabled for that frame. why? because in PPP, LCP packets are always sent with no address and control field compression and all control characters escaped. no cap. πŸ”₯

this node also supports "flag sharing" for packets transmitted on async β€” it's an optimization where the trailing flag byte of one frame gets shared with the opening flag byte of the next. so efficient, so cute. but bestie, listen: flag sharing between frames is disabled after one second of transmit idle time. the vibe expires. ⏰


✨ HOOKS ✨

this node type supports the following hooks, and there are exactly two, so pay attention:

  • async β€” the asynchronous connection. typically this hook would be connected to a ng_tty(4) node, which handles transmission of serial data over a tty device. πŸ’œ
  • sync β€” the synchronous connection. this hook sends and receives synchronous frames. for PPP, these frames should contain address, control, and protocol fields, but no checksum field. typically this hook would be connected to an individual link hook of a ng_ppp(4) type node. πŸŽ€

✨ CONTROL MESSAGES ✨

this node type supports the generic control messages, plus the following ones. get ready, there's a struct. 🧚

  • NGM_ASYNC_CMD_SET_CONFIG (setconfig) β€” sets the node configuration, which is described by a struct ng_async_cfg:
struct ng_async_cfg {
        u_char    enabled;  /* Turn encoding on/off */
        uint16_t  amru;     /* Max receive async frame length */
        uint16_t  smru;     /* Max receive sync frame length */
        uint32_t  accm;     /* ACCM encoding */
};

let me break the fields down for you, bestie, one by one:

  • the enabled field turns all encoding/decoding functions on or off (default disabled). when it's disabled, the node operates in a simple "pass through" mode. lowkey just vibing. πŸ™ˆ
  • the amru and smru fields are the asynchronous and synchronous MRU (maximum receive unit) values, respectively. they both default to 1600. and heads up: the async MRU applies to the incoming frame length after asynchronous decoding, not before. ✨
  • the accm field is the asynchronous character control map, which controls the escaping of characters 0x00 through 0x1f (default 0xffffffff). yes that's a lot of escaping. yes it's on purpose. πŸ’…
  • NGM_ASYNC_CMD_GET_CONFIG (getconfig) β€” this command returns the current configuration structure. simple. iconic. πŸ‘‘
  • NGM_ASYNC_CMD_GET_STATS (getstats) β€” this command returns a struct ng_async_stat containing node statistics for packet, octet, and error counts. numbers, we love numbers. πŸ”₯
  • NGM_ASYNC_CMD_CLR_STATS (clrstats) β€” clears the node statistics. bye bye data. 🌸

✨ SHUTDOWN ✨

this node shuts down upon receipt of a NGM_SHUTDOWN control message, or when all hooks have been disconnected. that's it, that's the whole exit strategy. πŸ’€


✨ SEE ALSO ✨

go read your RFCs, bestie, they're free and they're good for you πŸ“šβœ¨


✨ HISTORY ✨

the ng_async node type was implemented in FreeBSD 4.0. a classic. a legend. 🫢


✨ AUTHORS ✨

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


and that's the whole page!! this lil slice of the Debian manual, dated November 13, 2012, was brought to you by the fine folks over at Debian β€” so go forth, wire up your async and sync hooks, and frame some packets responsibly πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from