Skip to main content

Module rawip

Module rawip 

Source
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§

DecodedPacket
A decoded packet: its header, and the payload that followed it.
Ipv4Header
The IPv4 header fields, decoded (RFC 791 §3.1).
Ipv6Header
The fixed IPv6 header fields, decoded (RFC 8200 §3).
RawIpConfig
The operator’s configuration, parsed from the declared startup parameters.
RawIpServer
Generic raw IP protocol-N server.

Enums§

IpDecodeError
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.
PayloadEncoding
How a payload is represented in an event or an action.
RawIpTransport
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_received event body for a decoded packet.