STANAG 5066 SIS

STANAG 5066 SIS, the Subnetwork Interface Sublayer of annex A (Edition 4, draft v1.6 published by Isode), added in 11.6.0 (#122) as part of the defense lot (#125): the layer that connects applications to an HF radio node, for links beyond the horizon, over TCP 5066. It carries notably ACP 142 (P_MUL) and the military messaging of STANAG 4406 annex E. The module is packet_parser::parse::application::protocols::stanag5066.

The unit is the S_PDU: the preamble 90 EB, a version byte, two bytes of primitive size and the type of the primitive, one of 27, each decoded into typed values. The decoder is stateless, like GIOP: it decodes the first S_PDU of a TCP segment, accepts one that overflows the segment, and says where the next one starts.

Detection: TCP 5066 only

#![allow(unused)]
fn main() {
// among the port rules, after IKE, ESP and NAT-keepalive: TCP 5066 on either side
port_rule(ApplicationProtocol::Stanag5066, Guard::Tcp, is_stanag5066_tcp_port, ProbeId::Stanag5066),
}

with the probe

#![allow(unused)]
fn main() {
ProbeId::Stanag5066 => SisPdu::try_from(payload).is_ok(),
}

TCP 5066 is the IANA port (stanag-5066) and the one Wireshark registers. There is no blind rule: the preamble 90 EB 00, a type and a size are three fixed bytes and two constraints, too little to probe every TCP segment with. A node on another port is declared with ParseConfig::decode_as(port, DecodeAsProtocol::Stanag5066), which maps to the same probe behind the same TCP guard, (ApplicationProtocol::Stanag5066, Guard::Tcp, ProbeId::Stanag5066), evaluated before the table like every Decode As port. classify_payload called with no port (None, None) never answers STANAG 5066. Since 11.7.0 the probe judges the whole payload, as every probe does except the four text protocols (#185). Until 11.6.0 it saw only the first 18 KiB (PROBE_CAP), and a first S_PDU that ran past that bound was judged as a truncated one.

The guard on a real S_PDU moved to port 5067 (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn off_tcp_5066_an_s_pdu_needs_decode_as() {
        let mut raw = hex::decode(SIS_ACP142_REQUEST_HEX).unwrap();
        // Rewrite the TCP destination port, after 14 bytes of Ethernet and 20
        // of IPv4, from 5066 to 5067; `parse` does not verify the checksum.
        raw[36..38].copy_from_slice(&5067u16.to_be_bytes());

        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        let transport = flow.transport.as_ref().unwrap();
        assert_eq!(
            (transport.source_port, transport.destination_port),
            (Some(41778), Some(5067))
        );
        // Still an S_PDU, but off port 5066 no rule runs the SIS probe, and
        // no other probe accepts it.
        assert!(SisPdu::try_from(transport.payload.unwrap()).is_ok());
        assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "Unknown");

        let config = ParseConfig::new().decode_as(5067, DecodeAsProtocol::Stanag5066);
        let flow = parse_with(LinkType::ETHERNET, &raw, &config).unwrap();
        assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "STANAG 5066");
    }
}

The S_PDU

The S_BIND_REQUEST of frame 25 of S5066-HFChat-1.pcap, 32 bits per row: the sync preamble 90 EB, version 0, a primitive size of 4, the PDU type 1, then the primitive itself, SAP 5 (HF Chat) and rank 1 in one byte, the service type byte 0x14 (ARQ, node delivery confirmation) and an unused byte; SisPdu keeps the SisHeader, the named type and the typed primitive.

#![allow(unused)]
fn main() {
#[non_exhaustive]
pub struct SisHeader {
    pub version: u8,
    /// Size of the primitive, type included.
    pub primitive_size: u16,
    pub pdu_type: u8,
}

#[non_exhaustive]
pub struct SisPdu<'a> {
    pub header: SisHeader,
    pub pdu_type: PduType,          // the named type
    pub primitive: SisPrimitive<'a>,
    /// The segment does not hold the whole announced primitive: the S_PDU
    /// goes on in the next segment.
    pub truncated: bool,
    // bytes of this S_PDU present in the buffer, read with consumed()
}
}
BytesFieldNote
0–1preamble90 EB, not kept
2version0, the only one defined
3–4primitive_sizetype included: the S_PDU is 5 + primitive_size bytes
5pdu_type1 to 27; SisPdu::pdu_type is the PduType
6–the primitiveprimitive_size − 1 bytes, decoded into SisPrimitive

A bind, as an HF Chat client and its node exchange it (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn a_bind_request_and_its_acceptance() {
        let raw = hex::decode(SIS_BIND_REQUEST_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        let transport = flow.transport.as_ref().unwrap();
        assert_eq!(transport.destination_port, Some(5066));
        assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "STANAG 5066");

        let payload = transport.payload.unwrap();
        assert_eq!(&payload[..2], &[0x90, 0xeb]); // the preamble
        let request = SisPdu::try_from(payload).unwrap();
        assert_eq!(request.pdu_type, stanag5066::PduType::BindRequest);
        assert_eq!(request.header.version, 0);
        assert_eq!(request.header.primitive_size, 4); // type included
        assert_eq!(request.header.pdu_type, 1);
        assert!(!request.truncated);
        // 5 bytes of header and 4 of primitive: the whole segment.
        assert_eq!(request.consumed(), 9);
        assert_eq!(request.consumed(), payload.len());

        let SisPrimitive::Bind {
            sap_id,
            rank,
            service_type,
        } = request.primitive
        else {
            panic!("expected a Bind primitive, got {:?}", request.primitive);
        };
        assert_eq!((sap_id, rank), (5, 1)); // SAP 5: HF Chat, for tshark
        assert_eq!(service_type.transmission_mode, 1); // ARQ
        assert_eq!(service_type.delivery_confirmation, 1); // by the node
        assert!(service_type.in_order_delivery);
        assert!(!service_type.extended);

        // Frame 26, the node's answer: SAP 5 is bound, with an MTU of 250 bytes.
        let raw = hex::decode(SIS_BIND_ACCEPTED_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        let payload = flow.transport.as_ref().unwrap().payload.unwrap();
        let accepted = SisPdu::try_from(payload).unwrap();
        assert_eq!(accepted.pdu_type, stanag5066::PduType::BindAccepted);
        assert_eq!(
            accepted.primitive,
            SisPrimitive::BindAccepted {
                sap_id: 5,
                mtu: 250
            }
        );
    }
}

Twenty-seven primitives, eight variants

Neighbouring primitives share a variant: the hard links (6 to 13), the management messages (18, 19), the data primitives and their confirmations (20 to 27).

#![allow(unused)]
fn main() {
#[non_exhaustive]
pub enum SisPrimitive<'a> {
    /// S_BIND_REQUEST.
    Bind { sap_id: u8, rank: u8, service_type: ServiceType },
    /// S_BIND_ACCEPTED.
    BindAccepted { sap_id: u8, mtu: u16 },
    /// S_BIND_REJECTED and S_UNBIND_INDICATION.
    Rejected { reason: u8 },
    /// S_HARD_LINK_*: `reason` for REJECTED, TERMINATED and REJECT,
    /// `remote_status` for ESTABLISHED and INDICATION; TERMINATE only
    /// carries the address.
    HardLink {
        reason: Option<u8>,
        remote_status: Option<u8>,
        link_type: Option<u8>,      // two bits
        priority: Option<u8>,       // two bits
        remote_sap_id: Option<u8>,
        remote_node: NodeAddress,
    },
    /// S_SUBNET_AVAILABILITY.
    SubnetAvailability { status: u8, reason: u8 },
    /// S_MANAGEMENT_MESSAGE_REQUEST and INDICATION.
    Management { message_type: u8, body: &'a [u8] },
    /// S_UNIDATA_* and S_EXPEDITED_UNIDATA_*: `priority` for the requests and
    /// indications that are not expedited, `reason` for the rejections,
    /// `service_type`, `minimum_retransmissions` and `time_to_live` for the
    /// requests, `transmission_mode`, `source_sap_id` and `source` for the
    /// indications.
    Unidata {
        priority: Option<u8>,
        reason: Option<u8>,
        destination_sap_id: u8,
        destination: NodeAddress,
        service_type: Option<ServiceType>,
        minimum_retransmissions: Option<u8>,
        /// Twenty bits, LSB 2 s.
        time_to_live: Option<u32>,
        transmission_mode: Option<u8>,
        source_sap_id: Option<u8>,
        source: Option<NodeAddress>,
        /// Announced size of the U_PDU.
        u_pdu_size: u16,
        /// The U_PDU present in the segment: shorter than `u_pdu_size`
        /// when the S_PDU is truncated.
        u_pdu: &'a [u8],
    },
    /// S_UNBIND_REQUEST, S_DATAFLOW_ON, S_DATAFLOW_OFF, S_KEEP_ALIVE.
    Empty,
}
}

The fixed fields of each type must be present, within the announced size and within the segment, or the S_PDU is PrimitiveTooShort; the minimum counts the bytes after the type byte.

CodePduTypeSisPrimitiveFixed bytes
1BindRequestBind3
2UnbindRequestEmpty0
3BindAcceptedBindAccepted3
4, 5BindRejected, UnbindIndicationRejected1
6, 12HardLinkEstablish, HardLinkAcceptHardLink: type, priority, remote SAP, node5
7HardLinkTerminateHardLink: node only4
8, 11HardLinkEstablished, HardLinkIndicationHardLink: remote_status first6
9, 10, 13HardLinkRejected, HardLinkTerminated, HardLinkRejectHardLink: reason first6
14SubnetAvailabilitySubnetAvailability2
15, 16, 17DataflowOn, DataflowOff, KeepAliveEmpty0
18, 19ManagementMessageRequest, ManagementMessageIndicationManagement1
20, 24UnidataRequest, ExpeditedUnidataRequestUnidata11
21, 25UnidataIndication, ExpeditedUnidataIndicationUnidata12
22, 26UnidataRequestConfirm, ExpeditedUnidataRequestConfirmUnidata7
23, 27UnidataRequestRejected, ExpeditedUnidataRequestRejectedUnidata7

A bind request puts the SAP, the service access point the client binds to, in the high nibble of byte 6 and the rank in the low one, then the service type in byte 7; an acceptance puts the SAP in the high nibble of byte 6 and the MTU in bytes 7–8. The hard links other than S_HARD_LINK_TERMINATE pack their link type (two bits), priority (two bits) and remote SAP (four bits) in one byte, preceded by the status or the reason when the type has one, and followed by the node address; S_HARD_LINK_TERMINATE carries the node address alone.

Data primitives (20 to 27)

The data primitives are the traffic itself. Their layout, in bytes of the S_PDU:

FieldRequests 20, 24Indications 21, 25Confirmations, rejections 22, 23, 26, 27
priority, high nibble6 (20 only)6 (21 only)—
reason, high nibble——6 (23, 27 only)
destination_sap_id, low nibble666
destination7–107–107–10
service_type11——
minimum_retransmissions, high nibble12——
time_to_live, 20 bits12–14——
transmission_mode (high nibble), source_sap_id (low)—11—
source—12–15—
u_pdu_size15–1616–1711–12
u_pdu17–18–13–

The time_to_live is raw, in units of two seconds (tshark labels it "x2 seconds"). Two records recur:

#![allow(unused)]
fn main() {
#[non_exhaustive]
pub struct NodeAddress {
    /// Announced size, in half-bytes.
    pub size: u8,
    pub group: bool,
    /// The 28 address bits, 0x0a324202 for 10.50.66.2.
    pub address: u32,
    /// The four bytes, as they are.
    pub raw: [u8; 4],
}

#[non_exhaustive]
pub struct ServiceType {
    /// Four bits: 1 ARQ, 2 non-ARQ (broadcast), 3 non-ARQ with errors.
    pub transmission_mode: u8,
    /// Two bits: 0 none, 1 confirmation by the node, 2 by the client.
    pub delivery_confirmation: u8,
    /// The delivery-order bit is zero: in-order delivery.
    pub in_order_delivery: bool,
    /// An extended field follows.
    pub extended: bool,
    pub raw: u8,
}
}

A node address is read on four bytes, like tshark does: three bits of size, one group bit, 28 bits of address. Its Display is tshark's dotted notation, the 29 low bits of the four bytes, group bit included, written like an IPv4 address.

The U_PDU of a complete S_PDU must be exactly u_pdu_size bytes, with one tolerance: an indication (21, 25) may carry four more, the counters a Rockwell Collins node (v2.1 and earlier) inserts before the U_PDU, which the decoder skips like tshark. Any other size is PrimitiveTooShort, even a longer U_PDU: expected is then the announced size and actual the bytes found. An indication in transmission mode 3, non-ARQ with errors, puts two lists before its U_PDU, the errored blocks then the missing ones, each a two-byte count followed by four bytes per block; the decoder skips them to reach the U_PDU.

An S_UNIDATA_REQUEST carrying ACP 142 (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn a_unidata_request_carrying_acp_142() {
        let raw = hex::decode(SIS_ACP142_REQUEST_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "STANAG 5066");

        let payload = flow.transport.as_ref().unwrap().payload.unwrap();
        let request = SisPdu::try_from(payload).unwrap();
        assert_eq!(request.pdu_type, stanag5066::PduType::UnidataRequest);
        assert_eq!(request.header.primitive_size, 50);
        assert!(!request.truncated);
        assert_eq!(request.consumed(), payload.len()); // 55 bytes

        let SisPrimitive::Unidata {
            priority,
            reason,
            destination_sap_id,
            destination,
            service_type,
            minimum_retransmissions,
            time_to_live,
            source,
            u_pdu_size,
            u_pdu,
            ..
        } = request.primitive
        else {
            panic!("expected a Unidata primitive, got {:?}", request.primitive);
        };
        assert_eq!((priority, reason), (Some(0), None)); // a request has no reason
        assert_eq!(destination_sap_id, 2); // for tshark, the STANAG 4406 annex E client
        assert_eq!(destination.to_string(), "10.50.66.2");
        assert_eq!((destination.size, destination.group), (7, false));
        assert_eq!(destination.address, 0x0a32_4202);
        assert_eq!(service_type.unwrap().transmission_mode, 2); // non-ARQ
        assert_eq!((minimum_retransmissions, time_to_live), (Some(0), Some(0)));
        assert!(source.is_none()); // only indications name a source
        assert_eq!((u_pdu_size, u_pdu.len()), (38, 38));
        // The U_PDU stays raw: an ACP 142 message behind a client transport
        // header whose application identifier is 0x2000.
        assert_eq!(&u_pdu[4..6], &[0x20, 0x00]);
    }
}

Stateless: one S_PDU at a time

An S_PDU and a TCP segment have no reason to coincide: one S_PDU may be split over several segments, and one segment may hold several S_PDUs. The HF Chat client and node of the corpus send every data primitive in two segments, its header and fixed fields then its U_PDU, even when the whole S_PDU is only 29 bytes; the ACP 142 capture packs three S_PDUs of 2 065 bytes into one segment. With no reassembly, the decoder follows four rules:

  1. An S_PDU that overflows its segment is accepted and flagged truncated. Its fixed fields are decoded, and u_pdu is what the segment holds, possibly nothing. The fixed fields must all be there: a segment that cuts them is PrimitiveTooShort, truncated or not.
  2. A continuation segment is not SIS. It does not start with the preamble, so try_from refuses it (InvalidPreamble, or Truncated below six bytes), and the segment is labelled by whatever else matches: "Unknown", for the five of the corpus.
  3. What follows a complete S_PDU must start another one: nothing, or as many bytes of 90 EB 00 as remain, up to three. Anything else is UnexpectedTrailingBytes, and the segment is not labelled STANAG 5066.
  4. consumed() says where the next S_PDU starts: the bytes of this S_PDU present in the buffer, header included, which for a truncated S_PDU is the whole buffer. A caller reads the next S_PDU at &payload[pdu.consumed()..].

An S_UNIDATA_INDICATION split over two segments (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn a_split_s_pdu_is_decoded_on_its_first_segment() {
        let raw = hex::decode(SIS_INDICATION_FIRST_SEGMENT_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "STANAG 5066");

        let payload = flow.transport.as_ref().unwrap().payload.unwrap();
        let indication = SisPdu::try_from(payload).unwrap();
        assert_eq!(indication.pdu_type, stanag5066::PduType::UnidataIndication);
        // 5 + 30 = 35 bytes announced, 18 in this segment.
        assert_eq!(indication.header.primitive_size, 30);
        assert_eq!(payload.len(), 18);
        assert!(indication.truncated);
        assert_eq!(indication.consumed(), 18);

        // The fixed fields are all in this segment, the U_PDU is not.
        let SisPrimitive::Unidata {
            priority,
            destination_sap_id,
            destination,
            transmission_mode,
            source_sap_id,
            source,
            u_pdu_size,
            u_pdu,
            ..
        } = indication.primitive
        else {
            panic!("expected a Unidata primitive, got {:?}", indication.primitive);
        };
        assert_eq!((priority, destination_sap_id), (Some(0), 5));
        assert_eq!(destination.to_string(), "5.100.100.2");
        assert_eq!((transmission_mode, source_sap_id), (Some(1), Some(5))); // ARQ
        assert_eq!(source.unwrap().to_string(), "5.100.100.1");
        assert_eq!(u_pdu_size, 17);
        assert!(u_pdu.is_empty());

        // Frame 30, the next segment: the 17 bytes of the U_PDU. Without a
        // preamble they are not an S_PDU, and the segment stays "Unknown".
        let raw = hex::decode(SIS_INDICATION_CONTINUATION_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        let payload = flow.transport.as_ref().unwrap().payload.unwrap();
        assert_eq!(payload, b"<0> Hello there.\n");
        assert_eq!(
            SisPdu::try_from(payload),
            Err(Stanag5066ParseError::InvalidPreamble(*b"<0"))
        );
        assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "Unknown");
    }
}

and the only segment of the corpus that holds several S_PDUs, three S_UNIDATA_REQUESTs walked with consumed (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn consumed_walks_the_s_pdus_of_a_segment() {
        let raw = hex::decode(SIS_THREE_REQUESTS_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "STANAG 5066");
        let payload = flow.transport.as_ref().unwrap().payload.unwrap();
        assert_eq!(payload.len(), 6195);

        // `try_from` decodes the first S_PDU; `consumed` says where the next
        // one starts.
        let mut rest = payload;
        let mut lengths = Vec::new();
        while !rest.is_empty() {
            let pdu = SisPdu::try_from(rest).unwrap();
            assert_eq!(pdu.pdu_type, stanag5066::PduType::UnidataRequest);
            assert!(!pdu.truncated);
            let SisPrimitive::Unidata {
                destination,
                u_pdu_size,
                u_pdu,
                ..
            } = pdu.primitive
            else {
                panic!("expected a Unidata primitive, got {:?}", pdu.primitive);
            };
            assert_eq!(destination.to_string(), "10.50.66.2");
            assert_eq!((u_pdu_size, u_pdu.len()), (2048, 2048));
            lengths.push(pdu.consumed());
            rest = &rest[pdu.consumed()..];
        }
        assert_eq!(lengths, [2065, 2065, 2065]);
    }
}

Validations

All of them are Stanag5066ParseError, in packet_parser::errors::application::stanag5066:

ErrorWhen
Truncated { expected, actual }fewer than 6 bytes, the header and the type
InvalidPreamble([u8; 2])the first two bytes are not 90 EB
UnsupportedVersion(u8)a version other than 0
EmptyPrimitivea primitive_size of 0, which cannot hold the type
ReservedPduType(u8)a type other than 1 to 27
PrimitiveTooShort { pdu_type, expected, actual }the fixed fields of the type are missing, or a complete S_PDU holds a U_PDU of another size than announced
UnexpectedTrailingBytes { trailing }after a complete S_PDU, bytes that do not start 90 EB 00

Like every application decoder, a failure is not a corruption: the segment goes on to the next rules of the table, and nothing goes to corrupted.

Oracle: 34 segments, without reassembly

The golden test tests/stanag5066_golden.rs runs the four captures of pcaps_exemple/protocols/stanag5066/ and compares every segment with tshark 4.6.6 without TCP reassembly (tcp.desegment_tcp_streams:FALSE), the view of a stateless parser, frozen in tests/data/stanag5066_tshark_oracle.tsv by tools/stanag5066_oracle.sh: S_PDU types, primitive sizes, node addresses, SAPs, U_PDU sizes, transmission modes, TTLs, ranks, MTUs and reasons. The 34 segments where tshark sees SIS are labelled "STANAG 5066" and decoded alike, 36 S_PDUs of 13 of the 27 types; the 5 continuation segments, where tshark sees no SIS without reassembly, come out "Unknown"; 5 S_PDUs split between two segments are decoded on their first one and flagged truncated, three in S5066-HFChat-1.pcap (an indication, a request, a confirmation) and two in S5066-HFChat-Rejected.pcap (a request, a rejection). The other 47 frames are TCP segments without payload.

CaptureFrames (with an S_PDU)ContentOrigin
S5066-HFChat-1.pcap44 (6)an HF Chat client and its node, the NATO C3 Agency test bench, 2005Wireshark wiki
S5066-HFChat-Rejected.pcap19 (5)the same bench, an S_UNIDATA_REQUEST rejected with reason 3Wireshark wiki
S5066-Expedited.pcap13 (13)expedited data and hard links on the loopback, 2006Wireshark wiki
wireshark_10827_sis_acp142.pcap10 (10)ACP 142 over SIS on the loopback, 2015Wireshark issue 10827

In the golden histogram of the whole corpus, "STANAG 5066" went from 0 to 34 with 11.6.0, all taken from "Unknown". The fuzz target parse_stanag5066 runs nightly: no panic, and every S_PDU it decodes consumes no more than the input, borrows its U_PDU from the input, and, when truncated, consumes the rest of it.

What is left out

The limits every protocol shares, reassembly and checksums among them, are on the Limits page. The ones below are this protocol's own.

  • No reassembly: the U_PDU of a split S_PDU is what its first segment holds, and the continuation segments come out "Unknown". A caller that tracks the TCP stream has u_pdu_size to rebuild it.
  • The U_PDU stays raw: the ACP 142 (P_MUL) or STANAG 4406 annex E message it carries, behind its client transport header, is not decoded; neither is the body of a management message.
  • Skipped, not exposed: the block lists of an indication in mode 3, and the minimum number of retransmissions that follows the service type of an S_BIND_REQUEST (the data requests do expose theirs).
  • Values are numbers: SAP identifiers, reasons and statuses are not named.
  • The DTS layer below the SIS is out of scope: the wiki's DTS captures are LINKTYPE 237, which the crate does not read, or DTS encapsulated on TCP 5067 to 5069, which is not SIS.