Expand description
Generic raw IP protocol-N server.
This is the generic home for IP protocols that have no other — GRE (47), ESP (50),
AH (51), SCTP (132), and anything else the operator names by number. It binds one
SOCK_RAW socket for one operator-chosen IP protocol number, decodes the IP header
(which is generic: the same twenty bytes whatever rides on top), surfaces the payload as
opaque bytes, and lets the model decide what to do.
§The rule that defines this module
There is no per-protocol branching here, and there must never be. No
match protocol_number { 47 => parse_gre(), 50 => parse_esp(), .. }. The moment this file
knows about GRE specifically it has become the wrong thing, and the next change adds ESP,
then L2TP, and it is the centralized per-protocol logic CLAUDE.md’s decentralization rule
forbids. A protocol that deserves real parsing deserves its own module under src/server/.
The one table keyed by protocol number is ip_protocol_name, and it maps a number to the
IANA name so the model is told “47 (GRE)” rather than “47”. A name is not behaviour: no
code path branches on it, and adding an entry cannot change what the server does.
§Layout
The decoder is deliberately split from the transport: decode_ip_packet and its
helpers are pure functions over a byte slice with no I/O, no state and no privilege, so
they are tested against literal packet bytes (tests/server/rawip/e2e_test.rs). The
transport below is the part that has never been executed — a raw socket needs root.
Modules§
- actions
- Actions, events and metadata for the generic raw IP protocol-N server.
Structs§
- Decoded
Packet - A decoded packet: its header, and the payload that followed it.
- Ipv4
Header - The IPv4 header fields, decoded (RFC 791 §3.1).
- Ipv6
Header - The fixed IPv6 header fields, decoded (RFC 8200 §3).
- RawIp
Config - The operator’s configuration, parsed from the declared startup parameters.
- RawIp
Server - Generic raw IP protocol-N server.
Enums§
- IpDecode
Error - Why a buffer could not be read as an IP packet.
- IpHeader
- A decoded IP header, either version.
- IpVersion
- Which IP version the socket speaks.
- Payload
Encoding - How a payload is represented in an event or an action.
- RawIp
Transport - Which transport carries packets to this server.
Constants§
- EVENT_
PAYLOAD_ LIMIT - How much of the payload is placed in the event handed to the model.
- IPV4_
MIN_ HEADER_ LEN - Minimum length of an IPv4 header, in bytes (RFC 791 §3.1).
- IPV6_
HEADER_ LEN - Length of the fixed IPv6 header, in bytes (RFC 8200 §3).
Functions§
- decode_
ip_ packet - Decode an IP header and split off its payload.
- decode_
payload - Turn action payload text into the exact bytes to put on the wire.
- encode_
payload_ for_ event - Choose how to show an opaque payload to the model, and say which was chosen.
- ip_
protocol_ name - The IANA name for an IP protocol number, where one is well known.
- packet_
event_ data - Build the
rawip_packet_receivedevent body for a decoded packet.