packet-dissector
A Rust crate for layered network packet parsing with registry-based protocol chaining.
Installation
Add to your Cargo.toml:
[]
= "0.2"
Features
- Zero-copy on the normal path — dissectors borrow directly from
&[u8]slices when parsing a single packet; TCP reassembly and decrypted-payload paths copy into auxiliary storage - Extensible — add new protocols by implementing the
Dissectortrait - Layered dissection — automatic chaining from Ethernet through IP, TCP/UDP, to application protocols
- Safe Rust — minimal
unsafein the registry only, documented with// SAFETY:comments - Modular — enable only the protocols you need via feature flags
Supported Protocols
The set of built-in dissectors is feature-gated and keeps growing. Representative protocols include:
| Category | Protocols |
|---|---|
| L2 | Ethernet II, Linux SLL, Linux SLL2, 802.1Q VLAN, 802.1ad QinQ (up to 2 VLAN tags), ARP, LACP, LLDP, STP |
| L3 / routing | IPv4, IPv6, IPv6 extension headers (Hop-by-Hop, Routing, Fragment, Destination Options, Mobility), ICMP, ICMPv6, IGMP, OSPF, VRRP, IS-IS, AH, ESP, SRv6, GRE, MPLS |
| L4 / tunneling | TCP, UDP, SCTP, L2TP, L2TPv3, GENEVE, VXLAN |
| Application / control | DNS, mDNS, DHCP, DHCPv6, HTTP/1.1, HTTP/2, SIP, Diameter, NTP, BFD, BGP, TLS, PPP, RADIUS, RTP, QUIC, STUN |
| 3GPP | GTPv1-U, GTPv2-C, PFCP, NAS5G, NGAP |
See crates/packet-dissector/Cargo.toml and crates/packet-dissector/src/lib.rs
for the current feature-gated protocol list.
Feature Flags
All built-in dissectors are enabled by default. Disable default-features to
select only what you need:
# All protocols (default)
= "0.2"
# Only Ethernet + IPv4 + TCP
= { = "0.2", = false, = ["ethernet", "ipv4", "tcp"] }
# Convenience groups
= { = "0.2", = false, = ["layer2", "layer3", "layer4"] }
Representative feature flags:
- Link layer:
ethernet,linux_sll,linux_sll2,arp,lacp,lldp,stp - Network / routing:
ipv4,ipv6,icmp,icmpv6,igmp,ospf,vrrp,isis,ah,esp,ike,srv6,gre,mpls - Transport / tunneling:
tcp,udp,sctp,l2tp,l2tpv3,geneve,vxlan - Application / control:
dns,mdns,dhcp,dhcpv6,http,http2,sip,diameter,ntp,bfd,bgp,tls,ppp,radius,rtp,quic,stun - 3GPP:
gtpv1u,gtpv2c,pfcp,nas5g,ngap esp-decryptenables ESP payload decryption support
Convenience groups:
layer2 = ["ethernet", "linux_sll", "linux_sll2", "arp", "lacp", "lldp", "stp", "ppp"]layer3 = ["ipv4", "ipv6", "icmp", "icmpv6", "igmp", "srv6"]layer4 = ["tcp", "udp", "sctp"]application = ["dns", "mdns", "dhcp", "dhcpv6", "http", "http2", "sip", "diameter", "ntp", "radius", "rtp", "tls", "quic", "stun"]tunneling = ["gre", "geneve", "vxlan", "l2tp", "l2tpv3", "mpls"]routing = ["ospf", "isis", "bgp", "bfd", "vrrp"]ipsec = ["ah", "esp", "ike"]3gpp = ["gtpv1u", "gtpv2c", "pfcp", "nas5g", "ngap"]
For the authoritative, exhaustive list, see
crates/packet-dissector/Cargo.toml.
Quick Start
use DissectorRegistry;
use DissectBuffer;
use FieldValue;
// Build a registry with all built-in dissectors
let registry = default;
// An Ethernet + IPv4 + UDP packet (minimal example)
let packet_bytes: & = &;
let mut buf = new;
registry.dissect.unwrap;
assert_eq!; // Ethernet, IPv4, UDP
assert_eq!;
assert_eq!;
assert_eq!;
let udp = buf.layer_by_name.unwrap;
let src_port = buf.field_by_name.unwrap;
assert_eq!;
Adding a Custom Dissector
Implement the Dissector trait and register it. For external crates, depend on
packet-dissector-core for the trait and types:
use ;
use PacketError;
use FieldDescriptor;
use DissectBuffer;
;
Documentation
Full API documentation is available on docs.rs.
See crates/packet-dissector/examples/ for runnable examples:
- parse_packet — parse a raw packet and inspect layers/fields
- custom_dissector — implement and register a custom protocol dissector
License
Licensed under either of
at your option.