Ethernet, IPv4, UDP, and TCP packet builders plus IPv4, CIDR, LPM key, and 16-byte packed RingBuf event codecs.
All network header fields use standard network byte order (big-endian) while
LPM prefix lengths and RingBuf event metadata fields (plug_id, action)
use little-endian bpfel encoding to match the kernel data plane.
Summary
Functions
Decodes a numeric 16-bit event action code back to an action atom.
Decodes a 16-byte packed RingBuf event binary into a map.
Returns the numeric 16-bit event action code for an action atom.
Encodes a compact 16-byte RingBuf packet event matching the kernel data plane
layout:
<<plug_id::16-little, action::16-little, ipv4_src::32-big, ipv4_dst::32-big, sport::16-big, dport::16-big>>.
Encodes a CIDR string or {ip, prefixlen} into the 8-byte kernel
BPF_MAP_TYPE_LPM_TRIE IPv4 key: <<prefixlen::32-little, ipv4::32-big>>.
Ensures an IPv4/IPv6 packet carries a leading 14-byte Ethernet header (used
when feeding raw L3 packets into Linux BPF_PROG_TEST_RUN for cgroup_skb,
where the kernel calls eth_type_trans to strip 14 bytes before entering
the cgroup_skb program).
Formats a 4-byte IPv4 binary as a dotted-quad string.
Builds an Ethernet + IPv4 packet binary.
Builds an Ethernet + IPv6 packet binary.
Masks a 4-byte IPv4 binary to prefixlen leading bits (0..32).
Parses an IPv4 CIDR string ("10.0.0.0/8") or {ip, prefixlen} tuple into
{:ok, {masked_ipv4_bin, prefixlen}}.
Parses an IPv4 address from a dotted string, 4-tuple, 4-byte binary, or unsigned 32-bit integer into a 4-byte network-order binary.
Like parse_ipv4/1, raising ArgumentError on invalid input.
Returns a raw packet binary or constructs a zero-filled raw frame of :size
bytes (optionally overriding :ethertype when size >= 14).
Strips a leading 14-byte IPv4/IPv6 Ethernet header from a frame so it can be
inspected directly as an L3 packet (as seen by cgroup_skb hooks).
Builds an Ethernet + IPv6 + TCP packet binary.
Builds an Ethernet + IPv4 + TCP packet binary.
Builds an Ethernet + IPv6 + TCP packet carrying a TLS ClientHello payload.
Builds an Ethernet + IPv4 + TCP packet carrying a TLS ClientHello payload.
Builds a raw TLS ClientHello record binary for testing SNI, ECH, PQ, and segmented ClientHello handling.
Builds an Ethernet + IPv4 + UDP packet binary.
Wraps an Ethernet frame with an 802.1Q VLAN tag (tpid defaults to 0x8100).
Functions
Decodes a numeric 16-bit event action code back to an action atom.
Decodes a 16-byte packed RingBuf event binary into a map.
Returns the numeric 16-bit event action code for an action atom.
Encodes a compact 16-byte RingBuf packet event matching the kernel data plane
layout:
<<plug_id::16-little, action::16-little, ipv4_src::32-big, ipv4_dst::32-big, sport::16-big, dport::16-big>>.
Encodes a CIDR string or {ip, prefixlen} into the 8-byte kernel
BPF_MAP_TYPE_LPM_TRIE IPv4 key: <<prefixlen::32-little, ipv4::32-big>>.
Ensures an IPv4/IPv6 packet carries a leading 14-byte Ethernet header (used
when feeding raw L3 packets into Linux BPF_PROG_TEST_RUN for cgroup_skb,
where the kernel calls eth_type_trans to strip 14 bytes before entering
the cgroup_skb program).
Formats a 4-byte IPv4 binary as a dotted-quad string.
Builds an Ethernet + IPv4 packet binary.
Options:
:src- source IPv4 address (string, 4-tuple, 4-byte binary, or u32):dst- destination IPv4 address:proto- IPv4 protocol byte (default17for UDP):ihl- IPv4 IHL in 32-bit words (default5; values< 5construct intentionally malformed headers for testing):version- IPv4 version nibble (default4):ttl- IPv4 TTL byte (default64):ethertype- 16-bit EtherType (default0x0800):src_mac- 6-byte source MAC address:dst_mac- 6-byte destination MAC address:payload- L4 payload binary (default<<>>)
Builds an Ethernet + IPv6 packet binary.
Options:
:src- source IPv6 address (string, 8-tuple, or 16-byte binary):dst- destination IPv6 address (string, 8-tuple, or 16-byte binary):proto- IPv6 Next Header byte (default6for TCP):hop_limit- IPv6 Hop Limit byte (default64):vlan- optional 802.1Q VLAN ID (0..4095):payload- L4 payload binary (default<<>>)
Masks a 4-byte IPv4 binary to prefixlen leading bits (0..32).
Parses an IPv4 CIDR string ("10.0.0.0/8") or {ip, prefixlen} tuple into
{:ok, {masked_ipv4_bin, prefixlen}}.
Parses an IPv4 address from a dotted string, 4-tuple, 4-byte binary, or unsigned 32-bit integer into a 4-byte network-order binary.
Like parse_ipv4/1, raising ArgumentError on invalid input.
Returns a raw packet binary or constructs a zero-filled raw frame of :size
bytes (optionally overriding :ethertype when size >= 14).
Strips a leading 14-byte IPv4/IPv6 Ethernet header from a frame so it can be
inspected directly as an L3 packet (as seen by cgroup_skb hooks).
Returns bin unchanged when it is already a raw L3 IPv4/IPv6 packet or does
not carry an Ethernet IPv4 (0x0800) / IPv6 (0x86DD) header.
Builds an Ethernet + IPv6 + TCP packet binary.
Builds an Ethernet + IPv4 + TCP packet binary.
Accepts all ipv4/1 options plus:
:sport- source TCP port (default54321):dport- destination TCP port (default443):seq- TCP sequence number (default1):ack- TCP acknowledgment number (default0):flags- TCP flags byte (default0x02SYN):window- TCP window size (default65535):payload- TCP payload binary (default<<>>)
Builds an Ethernet + IPv6 + TCP packet carrying a TLS ClientHello payload.
Builds an Ethernet + IPv4 + TCP packet carrying a TLS ClientHello payload.
pkt = MaeBPF.Packet.tls_client_hello(sni: "evil.example.com")Accepts all tcp/1 options (:flags defaults to 0x18 PSH+ACK, :dport
defaults to 443) plus all tls_client_hello_payload/1 options (:sni,
:ech, :ech_before_sni, :extra_extensions, :trailing_extensions,
:split_before_sni, :truncate_to).
Builds a raw TLS ClientHello record binary for testing SNI, ECH, PQ, and segmented ClientHello handling.
payload = MaeBPF.Packet.tls_client_hello_payload(sni: "evil.example.com")Options:
:sni- hostname string (ornilto omit the SNI extension):ech- include TLS extension0xFE0D(defaultfalse):ech_before_sni- place0xFE0Dbefore0x0000(defaultfalse):extra_extensions- list of{type_u16, data_bin}prepended before SNI:trailing_extensions- list of{type_u16, data_bin}appended after SNI:omit_extensions_header- omit the 2-byte extensions length when no extensions are present (defaultfalse):split_before_sni- truncate the TLS record just before the SNI extension while keeping the full announced TLS record length (defaultfalse):truncate_to- explicit maximum byte length of the returned TLS record
Builds an Ethernet + IPv4 + UDP packet binary.
Accepts all ipv4/1 options plus:
:sport- source UDP port (default54321):dport- destination UDP port (default53):payload- UDP payload binary (default<<>>)
Wraps an Ethernet frame with an 802.1Q VLAN tag (tpid defaults to 0x8100).