Application

The application layer is where the rule "the port never decides alone" is put to the test, and where most of the design decisions of the crate were taken after real captures proved a naive approach wrong.

A classification, not a decode

#![allow(unused)]
fn main() {
pub struct Application {
    pub protocol: ApplicationProtocol,   // Dns, Tls, Http, Unknown...
}
}

PacketFlow::application is a label. It says which protocol the transport payload looks like, not what the message contains. Since 12.0.0 the label is an enum, ApplicationProtocol, #[non_exhaustive], with one variant per label: a match on it is checked by the compiler, where 11.x compared strings (application_protocol: &'static str). It is Copy, so classification still costs no allocation. protocol.label() gives the text the crate has always written, byte for byte ("DNS", "IEC 104", "BACnet/IP"); Display and the JSON output write that text, under the key application_protocol as before, and FromStr reads it back, refusing a text that is no label (UnknownApplicationLabel). ApplicationProtocol::ALL lists the 60 labels of the crate: the 52 of the dispatch table, the six tunnels, Stp and Unknown.

Since 13.0.0 one more variant, Custom(&'static str), carries the label of a parser added by the caller. It is not in ALL, and FromStr does not build it: the text alone does not say which parser gave it. ParseConfig::application_protocol (13.1.0) reads a label back with the configuration that produced it, Custom included. A variant that carries data takes away the discriminants of the others, so a cast protocol as u8 no longer compiles. The rewrite of a 11.x match is in MIGRATION-12.md, that of a cast in MIGRATION-13.md, in the crate repository.

For the actual decode, every protocol has a module under packet_parser::parse::application::protocols (except ESP, whose EspPacket is a transport decoder, in packet_parser::parse::transport::protocols::esp), and every one of them is a TryFrom<&[u8]> with its own struct and error:

#![allow(unused)]
fn main() {
use packet_parser::parse::application::protocols::dns::DnsPacket;

if let Some(transport) = &flow.transport
    && let Some(payload) = transport.payload
    && let Ok(dns) = DnsPacket::try_from(payload)
{
    // counts: questions, answers, authority records, additional records
    println!("{} questions, {} answers", dns.header.counts[0], dns.header.counts[1]);
}
}

Why separate the two? Because the label is the thing every consumer needs on every packet (a flow matrix, a protocol histogram), and it must be cheap and stateless. Decoding DNS names or TLS extensions allocates and only some consumers need it.

Supported protocols

The Protocols page has one row per label: its detection route, its page, its oracle and the release it arrived in.

The dispatch table gives 52 labels: DNS (plus its mDNS and LLMNR forms), TLS, SNMP, NTP, DHCP, DHCPv6, HTTP (requests and, since 11.7.0, responses), MQTT, PostgreSQL, FTP, SMTP, NNTP, SSH (identification string only), SSDP, NetBIOS (NBNS, NBSS), OpenVPN, Modbus/TCP and UMAS (and, since 12.0.0, Modbus over UDP 502), EtherNet/IP, OPC UA, S7Comm, COTP, AMS, GIOP, SRVLOC, ASTERIX (eleven categories), QUIC, Bitcoin, PTP (IEEE 1588, on UDP 319/320), and, since 11.6.0, DNP3, IEC 60870-5-104, BACnet/IP, RADIUS, RDP, WireGuard, DIS, STANAG 5066 SIS, RTPS, IKE, and ESP inside UDP 4500 with its one-byte NAT-keepalive; since 11.8.0, Valmet DNA, the proprietary process network of Metso and Valmet distributed control systems; since 13.0.0, Java RMI; since 13.2.0, SIP; since 13.3.0, NMF, DCE/RPC, RTCP, and CAPWAP for the datagrams its tunnel does not peel. STP gets its label from the link layer (see below).

One label has a decoder and no rule: RTP, new in 13.3.0, is given on a port declared with Decode As and nowhere else. Its header has two fixed bits, too few for a rule that would not name other traffic.

Some protocols are decoded below the table and get no label: PTP straight over Ethernet (EtherType 0x88F7), GOOSE (0x88B8) and LLDP (0x88CC) are internet layers, and native ESP, IP protocol 50, is a transport layer whose SPI and sequence number are in TransportDetails::Esp, with no application payload, like ICMP.

A probed payload that matches nothing is labelled "Unknown". An empty payload (a pure ACK) is not probed at all and application stays None.

How the label is chosen: one ordered table

The words of this chapter, probe, rule, guard, blind, terminal port, are defined in the Glossary.

The first version of the crate was a cascade of if XxxPacket::try_from(payload).is_ok() { return "Xxx" }, spread over two files, with port guards applied unevenly and one override where the port beat the content. Three problems showed up on real traffic:

  • false positives: NTP probed on TCP labelled TLS encrypted alerts "NTP" (0x15 is a plausible LI/VN/mode byte); a BOOTP packet looked like an SLP header; FTP/SMTP/NNTP replies are byte-for-byte identical;
  • double probing: the same parser ran twice on the same payload (once port-guarded, once blind);
  • pathological cost: a 64 KiB GRO segment was fully parsed by every probe in the cascade.

The dispatch is now one ordered table, RULES, in src/parse/dispatch/rules.rs (src/parse/dispatch.rs until 11.8.2 split it into rules.rs, probes.rs, ports.rs and tests.rs). Each rule has:

#![allow(unused)]
fn main() {
struct Rule {
    label: ApplicationProtocol,
    guard: Guard,                              // Tcp, Udp or Any: the transports the RFC allows
    ports: Option<fn(Option<u16>) -> bool>,    // optional port guard (either port)
    ports_veto: Option<fn(Option<u16>) -> bool>, // ports on which the rule must NOT fire
    probe: ProbeId,                            // the content check
    terminal_on_port: bool,                    // port reserved by RFC: the verdict is final
}
}

and the invariants are:

  1. A rule with a port guard labels only if port and content agree. The port alone never decides. OPC UA on port 4840 is still checked by OpcuaPacket::try_from.

  2. Every probe runs at most once per payload. Failures are memoized by ProbeId in a bitmask, one bit of a u128 for each of the 74 probes (a u64 until 12.1.0, which had 59): a rule sharing a probe with an earlier one (port-priority then blind fallback) never re-runs it.

  3. A probe judges the bytes its decoder will read; only the text probes stop at PROBE_CAP (Limits). Since 11.7.0 every other probe runs on the real payload (#184, #185): most decoders want it tiled to the last byte (SNMP, Modbus/TCP, ASTERIX, DIS, RTPS...) or covered by a declared length that must fit in it (NBSS, DNS over TCP, TLS...), and a prefix proves neither. The probes of the four text protocols, FTP, SMTP, NNTP and HTTP, keep the cap, PROBE_CAP = 18 432 bytes (18 KiB). They validate their text over its whole length: in UTF-8 for FTP and SMTP, the first line in UTF-8 and the octets of what follows for NNTP, the head in UTF-8 for HTTP. The fuzz oracle of FTP, SMTP and NNTP off their ports, fuzz/oracles/text_protocols.rs, copies the cap so that it judges the same bytes as their probes. What lies beyond the cap is not seen: a text message is judged on its first 18 432 bytes alone.

    Before 11.7.0, 43 of the 57 probes read only that prefix, the bound that #20 put on the cost of 64 KiB GRO segments. Beyond the prefix, a probe could label what its decoder refuses, or miss a complete message:

    PayloadBefore 11.7.0The fault
    an SNMP GetResponse of 18 432 bytes followed by a hundred null bytes"SNMP"the decoder refuses it
    an exact DNS response of 20 041 bytes"Unknown"a complete message, missed
    a TLS 1.2 record of 18 437 bytes, the maximum of RFC 5246 §6.2.3"Unknown"a complete message, missed

    Reading everything keeps the cost linear. A UDP payload is bounded by its datagram, and on TCP each decoder stops at its first structural error. The measures, in release:

    InputCostSource
    a 60 000-byte TCP segment, through parse()at most 31 µs#185
    65 505 bytes of ASTERIX records2.7 ms, 3.8 times the cost of the 18 432 bytes of the cap#184
    the worst DNS case: a 255-byte name pointed at by 10 871 questions, in 65 497 bytes39 ms#184

    The bound on names is what keeps the DNS cost linear (see Tightening a blind probe). No label of the corpus moved: apart from six RTPS datagrams, already read whole, none of its 210 captures carries a payload longer than the cap.

  4. The order of the table is the priority, inspectable, testable, and locked by a golden snapshot over the reference captures.

One rule of the table: the transport payload, a TLS ClientHello on TCP 54322 to 443, passes the transport guard, then the port guard, then the content probe, and gets the label TLS; a failed gate moves on to the next rule, the last rule falls through to Unknown, an empty payload is not probed

Each rule is three gates in a row, and a payload stops at the first rule whose three gates open. The TLS rule has no port guard, so its second gate always opens: the ClientHello is labelled by its content, whatever the port. A probe that fails is not re-run by a later rule that shares it. Two outcomes do not come from a rule: an empty payload is never probed (application: None), and a payload no rule matched is "Unknown", except on the terminal mDNS and LLMNR ports, where a failed probe ends the search with None (rules 14 and 15 below).

Reading the table

In 13.3.0 the table has 78 rules in two blocks: the 45 rules of the port block, then a blind cascade of 33. 12.0.0 had 65, 40 then 25. Thirteen rules came in with 13.x:

ReleaseRulesWhy
13.0.035 and 67, Java RMI on TCP 1099, then blind after GIOPthe new decoder (#313)
13.1.03, DHCP on UDP 67 and 68a DHCP message whose secs equals the datagram length came out DIS, even from 68 to 67 (#294)
13.1.04 and 5, SRVLOC on UDP and TCP 427an SLPv1 SrvTypeRqst of 20 bytes came out RADIUS on UDP 427 (#294)
13.1.024, QUIC long header of any version on UDP 443a Version Negotiation or a reserved version came out Unknown (#299)
13.1.057, EtherNet/IP on UDPthe blind EtherNet/IP rule split in two: on TCP, several complete messages may tile a segment (#288)
13.1.065, SSH after other linesa server may send lines before its banner (RFC 4253 §4.2); this rule comes after HTTP (#307)
13.2.063, SIP, blind on TCP and UDP, before HTTPthe new decoder (#342)
13.3.074, CAPWAP on UDP 5246 and 5247the datagrams the tunnel does not peel were "Unknown" (#355)
13.3.075, RTCP, blind on UDPthe new decoder (#354)
13.3.076, NMF, blind on TCPthe new decoder (#352)
13.3.077, DCE/RPC, blind on TCP, before MQTTthe new decoder (#356)

Every rule from DHCP on is therefore lower than in an edition of the book for 12.x: compare rules by label, not by number. The port block also holds four rules without a port guard that must come early: the blind S7Comm rule, which must beat COTP even on port 102, and the three rules that recognize FTP, SMTP and NNTP off their ports. The reverse exists since 13.3.0: the cascade holds one rule with a port guard, CAPWAP, placed after every UDP probe that has a signature so that a datagram which merely drew 5246 or 5247 as its source port keeps its own label. The source writes a rule with one of two constructors, or with the whole struct when a field differs from their defaults:

#![allow(unused)]
fn main() {
static RULES: &[Rule] = &[
    port_rule(ApplicationProtocol::Snmp, Guard::Udp, is_snmp_udp_port, ProbeId::Snmp),
    port_rule(ApplicationProtocol::Dhcpv6, Guard::Udp, is_dhcpv6_udp_port, ProbeId::Dhcpv6),
    rule(ApplicationProtocol::S7Comm, Guard::Tcp, ProbeId::S7Comm),
    // ...
    Rule {
        label: ApplicationProtocol::Ftp,
        guard: Guard::Tcp,
        ports: None,
        ports_veto: Some(is_text_protocol_port),
        probe: ProbeId::FtpUnambiguous,
        terminal_on_port: false,
    },
    // ...
    port_rule(ApplicationProtocol::Ntp, Guard::Udp, is_ntp_udp_port, ProbeId::Ntp),
    // --- blind cascade, with the transport guards the RFCs impose ---
    rule(ApplicationProtocol::Ntp, Guard::Udp, ProbeId::NtpBlind),
    // ...
    rule(ApplicationProtocol::Mqtt, Guard::Tcp, ProbeId::Mqtt),
];
}

Since 12.0.0 the label of a rule is a variant of ApplicationProtocol, where 11.x wrote the text: a rule cannot give a label the enum does not have. The tables below show the text, label().

Here is the whole table, in order. A port guard matches when either port of the segment or datagram is in its list; a veto skips the rule when either port is in the veto list. Every probe reads the whole payload, except the text probes of rules 8 to 13, 63 and 64, which read its first PROBE_CAP bytes (invariant 3).

Port rules

#LabelGuardPortsProbeIdThe probe
1SNMPUdp161, 162SnmpSnmpPacket::try_from
2DHCPv6Udp546, 547Dhcpv6Dhcpv6Packet::try_from
3DHCPUdp67, 68DhcpDhcpPacket::try_from
4SRVLOCUdp427SrvlocSrvlocPacket::try_from
5SRVLOCTcp427Srvlocthe same probe
6S7CommTcpnoneS7CommS7CommPacket::try_from: TPKT, COTP DT and S7 header together
7COTPTcp102CotpTpkta COTP TPDU behind the first TPKT header (cotp_from_tpkt)
8FTPTcp21FtpFtpMessage::try_from, first PROBE_CAP bytes
9SMTPTcp25, 587SmtpSmtpMessage::try_from, first PROBE_CAP bytes
10NNTPTcp119NntpNntpMessage::try_from, first PROBE_CAP bytes
11FTPTcpvetoed on 21, 25, 587, 119FtpUnambiguousa complete command whose verb only FTP has: RETR, STOR, PASV, APPE, RNFR, RNTO, MKD, CDUP, EPSV, EPRT, NLST; first PROBE_CAP bytes
12SMTPTcpvetoed on 21, 25, 587, 119SmtpUnambiguousa complete command whose verb only SMTP has: EHLO, HELO, MAIL, RCPT; first PROBE_CAP bytes
13NNTPTcpvetoed on 21, 25, 587, 119NntpUnambiguousa complete command whose verb only NNTP has: ARTICLE, XOVER, XHDR, IHAVE, LISTGROUP, NEWGROUPS, NEWNEWS; first PROBE_CAP bytes
14mDNSUdp5353, terminalMdnsDnsPacket::try_from_mdns
15LLMNRUdp5355, terminalLlmnrDnsPacket::try_from_llmnr
16SSDPUdp1900SsdpSsdpPacket::try_from
17NBNSUdp137NbnsNbnsPacket::try_from
18NBSSTcp139, 445NbssNbssPacket::try_from
19OpenVPNUdp1194OpenVpnUdpOpenVpnPacket::try_from
20OpenVPNTcp1194OpenVpnTcpOpenVpnPacket::from_tcp_stream: the length-prefixed form
21AMSTcp48898AmsTcpAmsPacket::try_from_tcp: the 6-byte AMS/TCP header, then the first AMS message
22AMSUdp48899AmsAmsPacket::try_from: a bare AMS header
23QUICUdp443QuicShortHeaderis_plausible_short_header: the 1-RTT header is opaque by design
24QUICUdp443QuicLongHeaderPortQuicPacket::is_port_match: QUIC v1 and Version Negotiation read whole, any other version by its invariants (RFC 8999 §5.1)
25OPC UATcp4840, 12001OpcuaOpcuaPacket::try_from: the last chunk may be partial, or cut in its header
26DNSTcp53DnsTcpDnsPacket::try_from_tcp: the length-prefixed form
27DNSUdp53DnsDnsPacket::try_from: the datagram form
28PTPUdp319, 320PtpPtpPacket::try_from_udp
29DISUdp3000DisLenientDisPacket::try_from_lenient
30RADIUSUdp1812, 1813, 1645, 1646, 3799RadiusRadiusPacket::try_from
31BACnet/IPUdp47808 to 47823BacnetBacnetPacket::try_from
32Valmet DNAUdp2517, 4516, 4517ValmetDnaValmetDnaPacket::is_port_udp_match: a coherent header, with a known family at its exact size or an unknown one, or the 42-byte beacon (TimeBeacon)
33RDPTcp3389RdpRdpPacket::try_from
34IEC 104Tcp2404Iec104Iec104Packet::try_from
35Java RMITcp1099JavaRmiJavaRmiPacket::try_from: any JRMP message, the one-byte ones, the DgcAck and the ProtocolAck included
36PostgreSQLTcp5432PostgresqlPortis_plausible_postgresql_payload: a decode of compatible shape
37IKEUdp500, 4500IkeIkePacket::from_udp, bare or behind the non-ESP marker
38ESPUdp4500EspNatTUdpEncapsulation::classify finds ESP and EspPacket::try_from accepts it
39NAT-keepaliveUdp4500NatKeepaliveUdpEncapsulation::classify finds the one byte 0xFF
40STANAG 5066Tcp5066Stanag5066SisPdu::try_from
41UMASTcp502UmasUmasPacket::is_tcp_match: MBAP headers that tile the segment, each of function 0x5A with a UMAS header
42ModbusTCPTcp502ModbusTcpModbusTcpPacket::try_from: the envelope alone
43ModbusUDPUdp502ModbusTcprule 42's probe
44WireGuardUdp51820WireGuardPortWireGuardPacket::is_port_udp_match
45NTPUdp123NtpNtpPacket::try_from: the decoder alone

Blind cascade

#LabelGuardPortsProbeIdThe probe
46NTPUdpnoneNtpBlindNtpPacket::is_blind_udp_match
47RTPSUdpnoneRtpsmagic RTPS or RTPX, then RtpsPacket::try_from
48Valmet DNAUdpnoneValmetDnaBlindValmetDnaPacket::is_blind_udp_match: one of the two known message families, at its exact size
49ASTERIXUdpnoneAsterixAsterixPacket::try_from
50DISUdpnoneDisDisPacket::try_from: the PDUs tile the datagram
51DNP3AnynoneDnp3Dnp3Packet::try_from
52RADIUSUdpnoneRadiusrule 30's probe
53BACnet/IPUdpnoneBacnetrule 31's probe
54BitcoinTcpnoneBitcoinBitcoinPacket::is_tcp_match: complete messages that tile the segment, all on the network of the first
55OPC UATcpnoneOpcuaBlindOpcuaPacket::is_blind_tcp_match: chunks that tile the segment, the last one partial of at most 16 MiB
56EtherNet/IPTcpnoneEthernetIpTcpEtherNetIpPacket::is_tcp_match: complete messages that tile the segment
57EtherNet/IPUdpnoneEthernetIpEtherNetIpPacket::try_from: one message, whose length covers the datagram
58PostgreSQLTcpnonePostgresqlis_likely_postgresql_payload: compatible shape and a strong proof
59DNSUdpnoneDnsBlindDnsPacket::is_blind_udp_match
60SNMPAnynoneSnmprule 1's probe
61TLSTcpnoneTlsTlsPacket::try_from
62SSHTcpnoneSsha segment that starts with SSH-, then SshPacket::try_from
63SIPAnynoneSipmay_start_sip, then SipMessage::try_from: a complete head and the five mandatory headers, first PROBE_CAP bytes
64HTTPTcpnoneHttpHttpRequest::try_from or HttpResponse::try_from, first PROBE_CAP bytes
65SSHTcpnoneSshAfterLinesSshPacket::try_from: the banner after other lines of text, at most 1 024 bytes of them (SSH_MAX_PRELUDE_LENGTH)
66GIOPTcpnoneGiopmagic GIOP, then GiopPacket::try_from
67Java RMITcpnoneJavaRmiBlindJavaRmiPacket::try_from and is_self_identifying: a stream header, a Call or a Return
68DHCPUdpnoneDhcprule 3's probe
69SRVLOCAnynoneSrvlocrule 4's probe
70UMASTcpnoneUmasrule 41's probe
71ModbusTCPTcpnoneModbusTcpBlindModbusTcpPacket::is_blind_tcp_match
72QUICUdpnoneQuicLongHeaderQuicPacket::is_blind_udp_match: a QUIC v1 long header, whose length fits in the datagram
73WireGuardUdpnoneWireGuardBlindWireGuardPacket::is_blind_udp_match
74CAPWAPUdp5246, 5247Capwapis_capwap_packet: a CAPWAP header of RFC 5415, or the DTLS preamble and a DTLS 1.0 or 1.2 record
75RTCPUdpnoneRtcpBlindRtcpCompound::is_blind_match: packets that tile the datagram, the first a Sender or a Receiver Report, or one feedback packet alone
76NMFTcpnoneNmfBlindNmfSegment::is_blind_match: records that tile the segment, opened by a preamble or by a sized envelope in binary XML
77DCE/RPCTcpnoneDceRpcDceRpcPdu::is_blind_match: a PDU, followed by nothing or by a second PDU
78MQTTTcpnoneMqttMqttPacket::try_from

Seven probes serve more than one rule. Srvloc serves three, its UDP and TCP ports and the blind rule (4, 5, 69), and ModbusTcp two, port 502 on TCP and on UDP (42, 43). Five others serve a port rule that gives them priority and a blind rule further down: Snmp (1, 60), Dhcp (3, 68), Radius (30, 52), Bacnet (31, 53) and Umas (41, 70). A failure on the port is memoized, so the blind rule does not run it again. Some probes are crate-internal: cotp_from_tpkt, is_capwap_packet, the three verb checks, is_plausible_short_header, the is_blind_*, is_port_* and is_tcp_match functions and the two PostgreSQL predicates. A consumer reaches them through parse, which is where the label is decided. In the real file most lines carry a comment that says why they are there, often with the issue, the capture frame or the RFC section behind them. That is the point of a table over a cascade: the semantics of the order are written down and cannot silently move.

Three detection routes

When choosing where a new protocol goes, the question is: can a valid payload of this protocol also be a valid payload of another protocol the crate already detect, or of arbitrary text?

RouteWhenExample
Blind probe (rule)the bytes identify themselves: literal marker (HTTP/, GIOP, SSH-, RTPS), CRCs (DNP3), tight binary header with plausible values (DNS, NTP), announced lengths that must cover the payload exactly (RADIUS, BACnet/IP, and PostgreSQL, which also wants a message of strong evidence), or a structure that must tile the datagram to the last byte (ASTERIX, DIS)rule(ApplicationProtocol::Tls, Guard::Tcp, ..)
Port-guarded (port_rule)the signature is weak or ambiguous even with perfect checks: identical reply syntax (FTP/SMTP/NNTP), loose headers (DHCPv6, AMS, COTP, QUIC short header, PTP, IEC 104, STANAG 5066, IKE), a stack other protocols share (RDP: TPKT, COTP and MCS are also T.120's), relaxed validation (mDNS)port_rule(ApplicationProtocol::Ftp, Guard::Tcp, is_ftp_tcp_port, ..)
Strong signature with transport constraintrecognizable off-port, but only defined on one transportS7Comm: the full TPKT + COTP-DT + S7 envelope is probed on any TCP port, and the same bytes on UDP never yield the label

Whatever the route, the transport guard is always there: the RFC says on which transport a protocol exists, and probing it elsewhere only produces false positives.

A protocol with a standard port and a signature strong enough elsewhere takes two routes at once, one rule each. With one probe, the port rule only gives it priority over the cascade: SNMP, DHCP, SRVLOC, RADIUS, BACnet/IP and UMAS. DHCP and SRVLOC got theirs in 13.1.0, when DIS and RADIUS, earlier in the cascade, took some of their messages. With two probes, the port rule keeps a lenient decoder and the blind rule a stricter one, because the standard port carries real traffic that no blind probe could prove: DNS on UDP 53 (Dns, DnsBlind, below), NTP on 123 (Ntp, NtpBlind), Modbus/TCP on 502 (ModbusTcp, ModbusTcpBlind), PostgreSQL on 5432 (PostgresqlPort, Postgresql), DIS on 3000 (DisLenient, Dis), WireGuard on 51820 (WireGuardPort, WireGuardBlind) and Valmet DNA on UDP 2517, 4516 and 4517, ports observed on a process network rather than registered (ValmetDna, ValmetDnaBlind). Since 13.x, OPC UA on 4840 and 12001 (Opcua, OpcuaBlind) and Java RMI on 1099 (JavaRmi, JavaRmiBlind) join them. NTP, Modbus/TCP and PostgreSQL have their section below.

Three protocols have more than one rule for another reason:

ProtocolRulesWhy
QUIC23 and 24 on UDP 443, 72 on any UDP portthe opaque short header and a long header of any version only on 443; off it, the long header of QUIC v1 alone
SSH62 before HTTP, 65 after ita segment that starts with its banner is tried first; a banner behind other lines comes after HTTP, so that an HTTP response whose body quotes a banner stays HTTP
EtherNet/IP56 on TCP, 57 on UDPTCP may put several messages in a segment; a UDP datagram carries one

Tightening a blind probe

A blind probe is only as good as the captures it has been confronted with. The defense corpus added in 11.4.0 showed two probes accepting traffic that was not theirs:

  • SRVLOC: 829 PTPv2 Delay_Req messages were labelled SRVLOC. Their header has exactly the shape of an SLPv1 one (version 1, a SrvRply function, a length equal to the datagram). The SLPv1 language field must now be a two-letter ASCII ISO 639 code (RFC 2165 §7); anything else is SrvlocPacketParseError::InvalidLanguageCode.
  • DNS: off port 53, any UDP datagram whose first twelve bytes formed a plausible empty header was DNS, among them 37 datagrams of a radar stream. The blind rule now runs its own probe, ProbeId::DnsBlind: the sections must consume the datagram exactly and carry at least one question or record. Port 53 keeps the tolerant decoder, so the two DNS rules no longer share a probe.

In both cases the rule kept its place in the table; what changed is what the probe demands. Both corrections only removed labels: in 11.4.0 the 866 frames concerned came out as "Unknown", and the golden histogram moved on those frames and nowhere else. The 829 Delay_Req have had their own label since 11.5.0, "PTP", from the port rule of UDP 319; the 37 radar datagrams are still "Unknown".

11.6.0 did the same for two blind rules that ran a whole decoder, NTP (#164) and Modbus/TCP (#167), and split them as DNS had been split: the tolerant decoder now runs in a port rule on the standard port, where the labels of the corpus did not move, and the blind rule has a stricter probe of its own. The NTP and Modbus/TCP sections give the details.

11.7.0 came back to the DNS blind probe (#184, #196). The probe judged only the first PROBE_CAP bytes, with two consequences:

  • Sections that ended exactly at byte 18 432 were enough, whatever followed. A hundred null bytes after a response still came out "DNS", although the probe demands sections that consume the datagram exactly.
  • An exact response of 20 041 bytes stayed "Unknown".

The probe now reads the whole datagram, as the NTP blind probe does (invariant 3).

Reading more needed a bound. The length of a domain name was not limited, and each name pointing to the same QNAME read it again in full, in a time quadratic in the size of the message. A forged response of 18 425 bytes, with a QNAME of 4 602 labels and 767 records pointing to it, cost 193 ms to DnsPacket::try_from, and came out "DNS".

A name is now at most 255 bytes on the wire, pointers followed (RFC 1035 §3.1). A longer one makes DnsPacket::try_from fail in a few microseconds, and its mDNS, LLMNR and TCP variants with it. The error is DnsQueryParseError::OutOfBoundParse, the one of a name that runs past the message. tshark shows such a name as <Name too long> and goes on; the crate no longer labels the message. No frame of the corpus changed. The DNS page has the rules.

ASTERIX, whose data blocks must tile the datagram, was judged on the same prefix. It has read the whole datagram since #184.

13.1.0 tightened two more probes, after a review of the decoders against their specifications (#288). Both read only the start of a TCP segment:

ProbeBefore 13.1.0Since 13.1.0
UMAS (rules 41, 70)the first MBAP header alone: a UMAS header followed by text came out "UMAS" on any TCP portMBAP headers that tile the segment, each of function 0x5A with a UMAS header (#295)
OPC UA, blind (rule 55)three letters of message type and one of chunk type: CLOCK 12:00:00 came out "OPC UA"chunks that tile the segment, the last one partial of at most 16 MiB, OPCUA_BLIND_MAX_PARTIAL_SIZE (#296)

The 181 UMAS frames and the 187 OPC UA frames of the corpus kept their labels.

Two probes went the other way, because TCP does not keep the boundaries of messages. EtherNet/IP and Bitcoin wanted the declared length to cover the whole segment: two RegisterSession, or verack then ping, in one segment came out "Unknown", even on TCP 44818. Since 13.1.0 complete messages that tile the segment are recognized, each one valid, as PostgreSQL and OPC UA already were. A last message cut by the end of the segment is still refused, as these probes are blind. The decoders did not change: TryFrom reads one message.

On its ports, OPC UA accepts the reverse case: a complete chunk followed by 1 to 7 bytes of the next one, cut by TCP in its header. Those bytes must start one of the seven message types, HEL, ACK, ERR, RHE, OPN, MSG or CLO. 13.1.0 let them in (#296); 13.1.1 checks them from the first byte, where 13.1.0 checked nothing below three bytes (#333, found by the nightly fuzz).

The reverse defect exists too, a parser refusing its own traffic, and 11.5.0 fixed one in SRVLOC (#131): the Char Encoding field of an SLPv1 header was read on one byte instead of two (RFC 2165 §7), which shifted everything after it, the XID and, in a DAAdvert, the error code, URL and scope list; the 26 SLPv1 DAAdvert of a real capture came out "Unknown". The header now has SrvlocHeaderV1::char_encoding (u16, the IANA MIBenum, 106 for UTF-8); the old single-byte encoding is deprecated, a change that on its own calls for a minor version, not a patch. 11.6.0 fixed four more, all with real frames: NTP replies refused because of the client's clock (#161), timestamps without their era (#162), reference ids and polls an implementation does send (#165), and the PostgreSQL p message of every password or SCRAM authentication (#98).

The same review fixed parsers that refused their own traffic in 13.0.0 and 13.1.0. Each fault left a valid message "Unknown", often on the protocol's own port:

ProtocolThe refused trafficIssue
NBNSthe negative response to a name query (rcode 3), and the refresh with opcode 9#292
DHCPv6Relay-Forward and Relay-Reply were read with the client header; their 34-byte header is now Dhcpv6Packet::relay#289
AMSon TCP 48898 the 6-byte AMS/TCP header before each message (AmsPacket::try_from_tcp)#290
MQTTfour valid MQTT 5 forms, AUTH (type 15) among them#291
TLSa record of version 3.0, which RFC 5246 lets a client send#300
Bitcointhe real regtest magic, and Testnet4; two magics of no network were accepted#301
SNMPa Counter64 of 263 or more, 9 bytes in BER#304
FTP, SMTP, NNTPa segment cut between CR and LF#305
FTP, NNTPstandard verbs: XPWD, XMKD, XRMD, XCUP, XCWD, LPSV, ADAT, CCC, MIC, CONF, ENC, LANG, HOST; STARTTLS, CHECK, TAKETHIS#306
SSHlines before the banner#307
COTPa class 0 CR that announces a TPDU of 4 096 or 8 192 bytes, which a real IEC 61850 station sends#298
DHCPhlen 0 over InfiniBand and IEEE 1394, and BOOTP with a null vend area#303
SRVLOCan error reply stopped after its code, and SLPv1 strings in Latin-1 or UCS-2#302
DNSa label that is not UTF-8, and on TCP a response without a question (AXFR)#297
QUICVersion Negotiation and reserved versions on UDP 443#299
LLMNRZ bits set, and the RCODE of a query, which a receiver must ignore#288

QUIC also lost a field it could not read. Header protection (RFC 9001 §5.4) masks the packet number and its length in an Initial, a 0-RTT or a Handshake packet, so packet_number is always None since 13.0.0 (#293). The DNS, LLMNR and TLS changes are on their pages.

"Decode As"

Port guards mean a server on a non-standard port is invisible to a port-guarded rule. ParseConfig::decode_as(port, DecodeAsProtocol::Xxx) declares extra ports, and parse_with applies them. Declared ports are evaluated before the table, with the same three constraints: port and content, the protocol's transport guard, and failures memoized like the table's. Ports the table marks terminal (mDNS 5353, LLMNR 5355) cannot be overridden: the caller extends the guards, never replaces them.

DecodeAsProtocol is #[non_exhaustive]. It had twenty variants in 11.5.0, Ptp the last; 11.6.0 adds seven at its end, Stanag5066, Dis, Ike, Esp, Rdp, Iec104 and WireGuard, 11.8.0 one more, ValmetDna, 12.0.0 another, ModbusUdp, 13.0.0 JavaRmi, 13.2.0 Sip, and 13.3.0 Rtp, Nmf and Rtcp: 34 in all. Each variant resolves to a label, a transport guard and a probe, and a unit test of dispatch/tests.rs checks that the label and the probe are those of a rule of the table, so that the two lists cannot drift apart. Three variants run a more lenient probe than the table does, and the test checks the stricter twin instead: WireGuard, Nmf and Rtcp. For Rtp it checks the opposite, that the table has no rule with that label:

VariantLabelGuardProbeId
FtpFTPTcpFtp
SmtpSMTPTcpSmtp
NntpNNTPTcpNntp
CotpCOTPTcpCotpTpkt
DnsDNSTcp on TCP, Udp otherwiseDnsTcp on TCP, Dns otherwise
MdnsmDNSUdpMdns
LlmnrLLMNRUdpLlmnr
SsdpSSDPUdpSsdp
NbnsNBNSUdpNbns
NbssNBSSTcpNbss
SnmpSNMPAnySnmp
Dhcpv6DHCPv6UdpDhcpv6
OpcUaOPC UATcpOpcua
PostgreSqlPostgreSQLTcpPostgresqlPort
ModbusTcpModbusTCPTcpModbusTcp
EthernetIpEtherNet/IPTcp on TCP, Any otherwiseEthernetIpTcp on TCP, EthernetIp otherwise
AmsAMSTcp on TCP, Any otherwiseAmsTcp on TCP, Ams otherwise
QuicShortHeaderQUICUdpQuicShortHeader
OpenVpnOpenVPNTcp on TCP, Udp otherwiseOpenVpnTcp on TCP, OpenVpnUdp otherwise
PtpPTPUdpPtp
Stanag5066STANAG 5066TcpStanag5066
DisDISUdpDisLenient
IkeIKEUdpIke
EspESPUdpEspNatT
RdpRDPTcpRdp
Iec104IEC 104TcpIec104
WireGuardWireGuardUdpWireGuard
ValmetDnaValmet DNAUdpValmetDna
ModbusUdpModbusUDPUdpModbusTcp
JavaRmiJava RMITcpJavaRmi
SipSIPAnySip
RtpRTPUdpRtp
NmfNMFTcpNmf
RtcpRTCPUdpRtcp

A declared port gets the probe of the protocol's standard port: the compatible shape of PostgreSQL on 5432, the lenient reading of DIS on 3000, the envelope of Modbus/TCP on 502, the AMS/TCP header of 48898 on TCP, every message family and the beacon of Valmet DNA on 2517, 4516 and 4517. WireGuard goes further than the 51820 rule: its probe, WireGuardPacket::try_from, accepts the reserved bytes whatever the message type, where the port rule wants them null in a cookie or a data message, 51820 being a port that any peer can draw at random. Nmf and Rtcp do the same with their blind rules: on a declared port the decoder alone decides, so the one-byte records of NMF and an RTCP datagram that does not open with a report are named. Rtp has no rule to be more lenient than: a declared port is its only route. Because declared ports come before the table, a declared port names the protocol of everything its probe accepts: on a port declared ModbusTcp, a UMAS frame is "ModbusTCP" (see Modbus/TCP and UMAS).

Since 12.1.0, DecodeAsProtocol::ALL is every variant, in declaration order: the list a caller shows when it lets its user bind a protocol to a port (#274). The enum and ALL are written by one macro from one list, as ApplicationProtocol and its own ALL are, so a variant cannot be missing from it. Three lists were written by hand until then, the one of the dispatch tests and those of the fuzz targets parse_packetflow and policy_dispatch; in 11.8.0 the fuzz one lacked ValmetDna. All three now read ALL (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn decode_as_all_is_the_list_a_caller_offers_for_a_port() {
        // Every variant, in declaration order: what a "Decode As" menu shows.
        let offered: Vec<String> = DecodeAsProtocol::ALL
            .iter()
            .map(|protocol| format!("{protocol:?}"))
            .collect();
        assert_eq!(offered.len(), 34);
        assert_eq!(offered.first().map(String::as_str), Some("Ftp"));
        assert_eq!(offered.last().map(String::as_str), Some("Rtcp"));

        // The entry the user picks goes to `decode_as` as it is.
        let picked = DecodeAsProtocol::ALL[0];
        assert_eq!(picked, DecodeAsProtocol::Ftp);
        let _config = ParseConfig::new().decode_as(2121, picked);
    }
}

The nineteen labels of the table without a variant are all given by a rule without a port guard, which probes any port, except two: NAT-keepalive, which only UDP 4500 knows, and CAPWAP, which only UDP 5246 and 5247 know. For NTP, whose port rule is more tolerant than its blind probe, this means that off port 123 the strict probe is the only way to the label.

Parsers added by the caller

Since 13.0.0 the caller can add parsers for protocols the crate does not decode, in Rust or, since 13.1.0, as rules in a TOML file. They run after the table, on a TCP or UDP payload that it left "Unknown": they never take a frame from the crate. Their label is ApplicationProtocol::Custom. The Custom parsers and rules chapter describes both.

STP: the one label without a transport

A Spanning Tree BPDU has no L3, so it can never reach this table. The pipeline checks it from the link layer (802.3 length field, bridge group address, LLC 42-42-03, valid BPDU) and labels the flow "STP" when every other layer is None.

Tunnels take the label

When the transport payload is a recognized encapsulation (CAPWAP, VXLAN, Geneve, GTP-U) the outer flow's Application::protocol is the tunnel name, and the real conversation is in inner. CAPWAP also keeps its name when there is nothing to peel, through rule 74. Next chapter.