Expand description
Pure ICMPv6 Neighbour Discovery (RFC 4861) codec.
Everything in this file is a pure function over plain values: it opens no socket, reads no
configuration and touches no global state. That is the whole design. NDP’s real transport is a
raw ICMPv6 socket, which needs root or CAP_NET_RAW, and nothing in this repository has that —
so the transport can never be executed here, but the packet format can be, and is, checked
against literal bytes in tests/server/ndp/codec_test.rs.
This is the bluetooth_ble_beacon split the root CLAUDE.md describes: message construction
is pure and exhaustively tested; the platform transport is a thin layer over it that has never
run. metadata().notes says both.
§Message layouts (RFC 4861 §4)
Every one starts with the ICMPv6 header of RFC 4443 §2.1 — type, code, checksum — and every one of the five NDP types uses code 0. Options, when present, always follow.
Router Solicitation (133) type code cksum | reserved(4) | options
Router Advertisement (134) type code cksum | hop(1) flags(1) lifetime(2)
| reachable(4) | retrans(4) | options
Neighbour Solicit. (135) type code cksum | reserved(4) | target(16) | options
Neighbour Advert. (136) type code cksum | flags(4) | target(16) | options
Redirect (137) type code cksum | reserved(4) | target(16) | dest(16) | options§Two things implementations get wrong, both pinned by literal-byte tests
- Option length is in units of 8 octets, not octets (RFC 4861 §4.6). A Prefix Information
option is 32 octets on the wire and its length field reads
4. Writing32there produces an option a real stack walks straight past the end of, and it is the classic NDP bug. - The ICMPv6 checksum covers an IPv6 pseudo-header (RFC 4443 §2.3, RFC 8200 §8.1) — the source address, the destination address, the upper-layer length and next header 58. It is therefore not computable from the ICMPv6 bytes alone, which is why every encode entry point on this type demands both addresses. A codec that computes it over the message only produces packets every conforming receiver silently drops.
§No bytes cross the LLM boundary
Addresses go in and out as IPv6 strings, link-layer addresses as "00:11:22:33:44:55",
flags as booleans, lifetimes as seconds. There is no way to hand this codec a hex blob and
there is deliberately no action parameter that would accept one.
Structs§
- Prefix
Information - A Prefix Information option’s contents (RFC 4861 §4.6.2).
- Router
Advertisement - The body of a Router Advertisement (RFC 4861 §4.2).
- Send
Request - A validated request to transmit one NDP message.
Enums§
- NdpMessage
- One of the five Neighbour Discovery messages, decoded.
- NdpOption
- One Neighbour Discovery option.
Constants§
- ADDRESSED_
PREFIX_ LEN - How many octets of addressing precede the ICMPv6 message on the UDP test transport.
- ALL_
NODES_ MULTICAST ff02::1, the all-nodes link-local multicast group: where an unsolicited Router Advertisement goes.- ALL_
ROUTERS_ MULTICAST ff02::2, the all-routers link-local multicast group: where a Router Solicitation goes.- LIFETIME_
INFINITE - A lifetime of
0xffffffffmeans “for ever” in a Prefix Information option and in RDNSS. - NA_
FLAG_ OVERRIDE - NA_
FLAG_ ROUTER - Neighbour Advertisement flags (RFC 4861 §4.4) — the top three bits of a 32-bit field.
- NA_
FLAG_ SOLICITED - NDP_
CODE - RFC 4861 §4: all five NDP messages use ICMPv6 code 0, and a receiver discards anything else.
- NDP_
HOP_ LIMIT - RFC 4861 §11.2: every NDP message is sent with an IPv6 Hop Limit of 255 and a receiver discards one that arrives with anything less. That is the protocol’s entire defence against an off-link attacker — it cannot be forged, because a router decrements.
- NEXT_
HEADER_ ICMP V6 - IPv6 “Next Header” value for ICMPv6 (RFC 4443 §1). The pseudo-header carries this, not 0.
- OPT_MTU
- OPT_
PREFIX_ INFORMATION - OPT_
RDNSS - OPT_
SOURCE_ LINK_ LAYER_ ADDRESS - Option types (RFC 4861 §4.6, RFC 8106 §5.1 for RDNSS).
- OPT_
TARGET_ LINK_ LAYER_ ADDRESS - PREFIX_
FLAG_ AUTONOMOUS - PREFIX_
FLAG_ ON_ LINK - Prefix Information flags (RFC 4861 §4.6.2).
- RA_
FLAG_ MANAGED - Router Advertisement flags (RFC 4861 §4.2).
- RA_
FLAG_ OTHER - TYPE_
NEIGHBOR_ ADVERTISEMENT - TYPE_
NEIGHBOR_ SOLICITATION - TYPE_
REDIRECT - TYPE_
ROUTER_ ADVERTISEMENT - TYPE_
ROUTER_ SOLICITATION
Functions§
- decode_
addressed - The inverse of
encode_addressed. - decode_
options - Decode a run of options.
- encode_
addressed - Wrap an ICMPv6 message with the two addresses its checksum was computed over.
- format_
mac - Render six octets as lowercase colon-separated hex.
- icmpv6_
checksum - The ICMPv6 checksum over the IPv6 pseudo-header of RFC 8200 §8.1 plus
message. - parse_
mac - Parse
aa:bb:cc:dd:ee:ff(also accepting-,.and space separators) into six octets. - solicited_
node_ multicast - The solicited-node multicast address for a target (RFC 4291 §2.7.1):
ff02::1:ff00:0/104with the target’s low 24 bits appended. - verify_
checksum - Verify the checksum a message carries against the addresses it was sent between.
- write_
checksum - Compute the checksum for
messageand write it into its header.