NG_PPP(4)
ng_ppp π the PPP protocol netgraph node type (this is NG_PPP(4), bestie, from the Kernel Interfaces Manual)
okay so. sit down. grab a snack. we're doing netgraph PPP and honestly? it's giving iconic. β¨
SYNOPSIS π
#include <sys/types.h>
#include <netgraph/ng_ppp.h>
DESCRIPTION π
So the ppp node type does the multiplexing for the PPP protocol. That's the whole vibe. But here's the thing β it only deals with packets that actually contain data. All the protocol negotiation and control packets? It doesn't touch those. It forwards them straight to a separate controlling entity, like a user-land daemon. π«Ά
And the way that this slaps is that it combines the fast dispatch of kernel implementations with the configuration flexibility of a user-land implementation. Best of both worlds, no cap.
The PPP node type directly supports:
- multi-link PPP
- Van Jacobson compression
- PPP compression
- PPP encryption
- and the IP, IPX, and AppleTalk protocols
One single PPP node = one PPP multi-link bundle. That's the mapping, periodt. π
There's a separate hook for each PPP link in the bundle, plus a bunch of hooks for the directly supported protocols. For compression and encryption you need separate attached nodes to do the actual work β the node type you use obviously depends on which algorithm got negotiated. There's also a bypass hook which handles any protocol the node doesn't directly support. That includes all the control protocols: LCP, IPCP, CCP, etc. Typically this node gets connected to a user-land daemon via a ng_socket(4) type node. π¦
ENABLING FUNCTIONALITY β
Generally speaking, the PPP node enables a specific link or functionality when:
- a
NGM_PPP_SET_CONFIGmessage has been received which enables it, and - the corresponding hook(s) are connected.
This lets the controlling entity use either method β (a) or (b), or both β to control the node's behavior. And lowkey the cool part: when a link is connected but disabled, traffic can still flow on the link via the bypass hook (see below π).
LINK HOOKS π₯
During normal operation, the individual PPP links are connected to hooks link0, link1, etc. Up to NG_PPP_MAX_LINKS links are supported. These device-independent hooks transmit and receive full PPP frames, which include the PPP protocol, address, control, and information fields β but no checksum or other link-specific fields. π
On outgoing frames, when protocol compression has been enabled and the protocol number is suitable for compression, the protocol field gets compressed (i.e., sent as one byte instead of two). Either compressed or uncompressed protocol fields are accepted on incoming frames. Similarly, if address and control field compression has been enabled for the link, the address and control fields will be omitted β except for LCP frames, as required by the standards. Incoming frames have the address and control fields stripped automatically if present. π
Since all negotiation is handled outside the PPP node, the links should not be connected and enabled until the corresponding link has reached the network phase (i.e., LCP negotiation and authentication have completed successfully) and the PPP node has been informed of the link parameters via the NGM_PPP_LINK_CONFIG message. Don't skip that step, bestie.
When a link is connected but disabled, all received frames are forwarded directly out thebypasshook, and conversely, frames may be transmitted via thebypasshook as well. This mode is appropriate for the link authentication phase. As soon as the link is enabled, the PPP node will begin processing frames received on the link.
COMPRESSION AND ENCRYPTION πΈ
Compression is supported via two hooks: compress and decompress. You can turn compression and decompression on by toggling the enableCompression and enableDecompression fields of the node configuration structure (see below). π§
- If
enableCompressionis set toNG_PPP_COMPRESS_SIMPLE, then all outgoing frames are sent to thecompresshook and all packets received on this hook are expected to be compressed, so theCOMPDtag is put on them unconditionally. - If
enableCompressionis set toNG_PPP_COMPRESS_FULL, then packets received on thecompresshook are resent as is. The compressor node should put the tag, if the packet was compressed. - If
enableDecompressionis set toNG_PPP_DECOMPRESS_SIMPLE, then the node will sent to thedecompresshook only those frames that are marked with theCOMPDtag. - If
enableDecompressionis set toNG_PPP_DECOMPRESS_FULL, then the node will sent all incoming packets to thedecompresshook. - Compression and decompression can be completely disabled by setting the
enableCompressionandenableDecompressionfields toNG_PPP_COMPRESS_NONEandNG_PPP_DECOMPRESS_NONE, respectively.
Encryption works exactly analogously via the encrypt and decrypt nodes. Data is always compressed before being encrypted, and decrypted before being decompressed. Order matters, queen. π
Only bundle-level compression and encryption is directly supported; link-level compression and encryption can be handled transparently by downstream nodes.
VAN JACOBSON COMPRESSION π
When all of the vjc_ip, vjc_vjcomp, vjc_vjuncomp, and vjc_vjip hooks are connected, and the corresponding configuration flag is enabled, Van Jacobson compression and/or decompression will become active. Normally these hooks connect to the corresponding hooks of a single ng_vjc(4) node. The PPP node is compatible with the "pass through" modes of the ng_vjc(4) node type. β¨
BYPASS HOOK π
When a frame is received on a link with an unsupported protocol β or a protocol which is disabled, or for which the corresponding hook is unconnected β the PPP node forwards the frame out the bypass hook, prepended with a four byte prefix. π¬
That prefix is:
- the first two bytes = the link number on which the frame was received (in network order). For such frames received over the bundle (i.e., encapsulated in the multi-link protocol), the special link number
NG_PPP_BUNDLE_LINKNUMis used. - then the two byte PPP protocol number (also in network order). The PPP protocol number is two bytes long even if the original frame was protocol compressed.
Conversely, any data written to the bypass hook is assumed to be in this same format. The four byte header is stripped off, the PPP protocol number is prepended (possibly compressed), and the frame is delivered over the desired link. If the link number is NG_PPP_BUNDLE_LINKNUM, the frame will be delivered over the multi-link bundle; or, if multi-link is disabled, over the (single) PPP link. π«
Typically when the controlling entity receives an unexpected packet on the bypass hook it responds either by dropping the frame (if it is not ready for the protocol) or with an LCP protocol reject (if it does not recognize or expect the protocol). π
MULTILINK OPERATION π₯
To enable multi-link PPP, the corresponding configuration flag must be set and at least one link connected. The PPP node will not allow more than one link to be connected if multi-link is not enabled, nor will it allow certain multi-link settings to be changed while multi-link operation is active (e.g., short sequence number header format). So like... set it up right the first time, bestie. π
Since packets are sent as fragments across multiple individual links, it is important that when a link goes down the PPP node is notified immediately β either by disconnecting the corresponding hook or disabling the link via the NGM_PPP_SET_CONFIG control message. Don't leave it hanging. π
Each link has configuration parameters for:
- latency (specified in milliseconds)
- bandwidth (specified in tens of bytes per second)
The PPP node can be configured for round-robin or optimized packet delivery.
round-robin delivery π¦
When configured for round-robin delivery, the latency and bandwidth values are ignored and the PPP node simply sends each frame as a single fragment, alternating frames across all the links in the bundle.
- advantage: even if one link fails silently, some packets will still get through.
- disadvantage: sub-optimal overall bundle latency, which is important for interactive response time, and sub-optimal overall bundle bandwidth when links with different bandwidths exist in the same bundle.
optimal delivery β
When configured for optimal delivery, the PPP node distributes the packet across the links in a way that minimizes the time it takes for the completed packet to be received by the far end. This involves taking into account each link's latency, bandwidth, and current queue length. Therefore these numbers should be configured as accurately as possible.
The algorithm does require some computation, so may not be appropriate for very slow machines and/or very fast links. π
As a special case: if all links have identical latency and bandwidth, then the above algorithm is disabled (because it is unnecessary) and the PPP node simply fragments frames into equal sized portions across all of the links. It's giving "why try when it's already perfect". π
HOOKS π«Ά
This node type supports the following hooks:
link<N>β Individual PPP link number <N>compressβ Connection to compression enginedecompressβ Connection to decompression engineencryptβ Connection to encryption enginedecryptβ Connection to decryption enginevjc_ipβ Connection tong_vjc(4)iphookvjc_vjcompβ Connection tong_vjc(4)vjcomphookvjc_vjuncompβ Connection tong_vjc(4)vjuncomphookvjc_vjipβ Connection tong_vjc(4)vjiphookinetβ IP packet dataipv6β IPv6 packet dataatalkβ AppleTalk packet dataipxβ IPX packet databypassβ Bypass hook; frames have a four byte header consisting of a link number and a PPP protocol number.
ποΈ CONTROL MESSAGES ποΈ
okay so this node type is so chill with the generic control messages β it accepts all of those, plus these extra ones, which are the ones that actually do stuff:
NGM_PPP_SET_CONFIG(setconfig) β bestie this is THE one. it configures literally every aspect of the node. we're talking enabling multi-link PPP, encryption, compression, Van Jacobson compression, and IP, IPv6, AppleTalk and IPX packet delivery. it also handles per-link config β enabling the link, setting latency and bandwidth parameters, enabling protocol field compression. π
β οΈ huge caveat alert: no link or functionality is active until the corresponding hook is also connected. so like, setting it doesn't do it. connect the hook or it's giving nothing.
this command takes a struct ng_ppp_node_conf as an argument:
/* Per-link config structure */
struct ng_ppp_link_conf {
u_char enableLink; /* enable this link */
u_char enableProtoComp;/* enable protocol field compression */
u_char enableACFComp; /* enable addr/ctrl field compression */
uint16_t mru; /* peer MRU */
uint32_t latency; /* link latency (in milliseconds) */
uint32_t bandwidth; /* link bandwidth (in bytes/sec/10) */
};
/* Bundle config structure */
struct ng_ppp_bund_conf {
uint16_t mrru; /* multilink peer MRRU */
u_char enableMultilink; /* enable multilink */
u_char recvShortSeq; /* recv multilink short seq # */
u_char xmitShortSeq; /* xmit multilink short seq # */
u_char enableRoundRobin; /* xmit whole packets */
u_char enableIP; /* enable IP data flow */
u_char enableIPv6; /* enable IPv6 data flow */
u_char enableAtalk; /* enable AppleTalk data flow */
u_char enableIPX; /* enable IPX data flow */
u_char enableCompression; /* enable PPP compression */
u_char enableDecompression; /* enable PPP decompression */
u_char enableEncryption; /* enable PPP encryption */
u_char enableDecryption; /* enable PPP decryption */
u_char enableVJCompression; /* enable VJ compression */
u_char enableVJDecompression; /* enable VJ decompression */
};
struct ng_ppp_node_conf {
struct ng_ppp_bund_conf bund;
struct ng_ppp_link_conf links[NG_PPP_MAX_LINKS];
};
NGM_PPP_GET_CONFIG(getconfig) β hands you the current config back, as astruct ng_ppp_node_conf. it's giving receipts β¨NGM_PPP_GET_LINK_STATS(getstats) β takes a two byte link number as an argument and returns astruct ng_ppp_link_statstuffed with statistics for that link. oh and heads up,NG_PPP_BUNDLE_LINKNUMis a valid link number that corresponds to the multi-link bundle πNGM_PPP_GET_LINK_STATS64(getstats64) β same asNGM_PPP_GET_LINK_STATSexcept it returnsstruct ng_ppp_link_stat64with 64bit counters. more numbers, no downside πNGM_PPP_CLR_LINK_STATS(clrstats) β takes a two byte link number as an argument and clears the statistics for that link. bye stats π«ΆNGM_PPP_GETCLR_LINK_STATS(getclrstats) β same asNGM_PPP_GET_LINK_STATS, but it also atomically clears the statistics too. get it and yeet it in one move, obsessed πNGM_PPP_GETCLR_LINK_STATS64(getclrstats64) β same asNGM_PPP_GETCLR_LINK_STATSbut returnsstruct ng_ppp_link_stat64with 64bit counters.
also, and this is lowkey the cutest part: this node type also accepts the control messages accepted by the ng_vjc(4) node type. when it receives those, they just get forwarded to the adjacent ng_vjc(4) node, if there is one. super handy when the individual PPP links are able to generate NGM_VJC_RECV_ERROR messages (peep ng_vjc(4) for the description of that) π
π SHUTDOWN π
this node shuts down when it gets a NGM_SHUTDOWN control message, or when all hooks have been disconnected. it's the "everyone left the group chat" situation fr fr π
π SEE ALSO π
netgraph(4),ng_async(4),ng_iface(4),ng_mppc(4),ng_pppoe(4),ng_vjc(4),ngctl(8)- W. Simpson, The Point-to-Point Protocol (PPP), RFC 1661.
- K. Sklower, B. Lloyd, G. McGregor, D. Carr, and T. Coradetti, The PPP Multilink Protocol (MP), RFC 1990.
π HISTORY π
the ng_ppp node type was implemented in FreeBSD 4.0. a legend, an icon, the moment β¨
π AUTHORS π
Archie Cobbs <archie@FreeBSD.org> β thank you for your service, king π
and that's the whole page bestie!! this Debian build of the page is dated November 13, 2012, and the source is the Debian ng_ppp(4) manpage β go forth and configure responsibly ππ
π¦
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1996-1999 Whistle Communications, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms