netpkt/icmpv6.rs#
Source: lib/netpkt/icmpv6.rs
icmpv6 -- ICMP for IPv6 (RFC 4443) and the messages of Neighbor Discovery (RFC 4861)
Icmp6View::parse(b) type, code, checksum (checksum_ok over the IPv6 pseudo header, RFC
4443 2.3), the 4 bytes after it, the body; quoted() for the packet
an error message carries
Icmp6 EchoRequest / EchoReply { id, seq }, DestUnreach { code },
PacketTooBig { mtu }, TimeExceeded { code }, ParamProblem { code,
pointer }, Other; encode(src, dst, body) and push_v6(&mut Pkt, src,
dst) with the checksum
Nd { msg, opts } RouterSolicit, RouterAdvert(Ra), NeighborSolicit { target },
NeighborAdvert { router, solicited, override_, target },
Redirect { target, dst } with their options (NdOpt: source / target
link-layer address, prefix information, redirected header, MTU, any
other kept as bytes); Nd::parse checks what RFC 4861 asks a receiver
to check in the message itself (code 0, lengths, no option of length
0, no group as target); hop limit 255, the checksum and the rules
that need the addresses are the caller's (check_ip)
Nd::encode(src, dst) the message with its checksum
error_quote(packet) what an error quotes: as much of the offending packet as fits into
an ICMPv6 packet of the minimum MTU (1280 bytes, RFC 4443 2.4 (c))
name(type, code) "Echo (ping) request", "Neighbor Solicitation", "Time Exceeded (hop
limit exceeded in transit)", ... (the wording of capture tools)
The multicast addresses and MACs of ND are Ipv6::solicited_node, Ipv6::ALL_NODES,
ALL_ROUTERS and Mac::of_ipv6_multicast (addr.rs); interface identifiers Mac::eui64.
/// type, code, checksum and the 4 bytes every message has after them
ICMPV6_HDR: usize = 8
T_DEST_UNREACH: u8 = 1
T_PACKET_TOO_BIG: u8 = 2
T_TIME_EXCEEDED: u8 = 3
T_PARAM_PROBLEM: u8 = 4
T_ECHO_REQUEST: u8 = 128
T_ECHO_REPLY: u8 = 129
T_MLD_QUERY: u8 = 130
T_MLD_REPORT: u8 = 131
T_MLD_DONE: u8 = 132
T_ROUTER_SOLICIT: u8 = 133
T_ROUTER_ADVERT: u8 = 134
T_NEIGHBOR_SOLICIT: u8 = 135
T_NEIGHBOR_ADVERT: u8 = 136
T_REDIRECT: u8 = 137
T_MLD2_REPORT: u8 = 143
/// codes of Destination Unreachable
UNREACH_NO_ROUTE: u8 = 0
UNREACH_ADMIN: u8 = 1
UNREACH_BEYOND_SCOPE: u8 = 2
UNREACH_ADDR: u8 = 3
UNREACH_PORT: u8 = 4
UNREACH_POLICY: u8 = 5
UNREACH_REJECT: u8 = 6
/// codes of Time Exceeded
EXCEEDED_HOP_LIMIT: u8 = 0
EXCEEDED_REASSEMBLY: u8 = 1
/// codes of Parameter Problem
PARAM_HEADER: u8 = 0
PARAM_NEXT_HEADER: u8 = 1
PARAM_OPTION: u8 = 2
/// ND option types (RFC 4861 4.6)
OPT_SRC_LLA: u8 = 1
OPT_TGT_LLA: u8 = 2
OPT_PREFIX: u8 = 3
OPT_REDIRECTED: u8 = 4
OPT_MTU: u8 = 5
/// the lifetime that never ends (prefix information, RFC 4861 4.6.2)
INFINITE: u32 = 0xFFFF_FFFF
struct Icmp6View<'a>a received ICMPv6 message
impl<'a> Icmp6View<'a>
fn parse(b: &'a [u8]) -> Option<Icmp6View<'a>>at least type, code and checksumfn typ(&self) -> u8fn code(&self) -> u8fn checksum(&self) -> u16fn checksum_ok(&self, src: Ipv6, dst: Ipv6) -> boolthe checksum over the pseudo header ofsrcanddstand the whole messagefn checksum_want(&self, src: Ipv6, dst: Ipv6) -> u16the checksum the message should carry (for a dissector's "should be")fn rest(&self) -> [u8; 4]the 4 bytes after the checksum (zeros when the message is shorter)fn id(&self) -> u16fn seq(&self) -> u16fn value(&self) -> u32the MTU of Packet Too Big, the pointer of Parameter Problemfn body(&self) -> &'a [u8]what follows the first 8 bytes (an error's quote, an echo's data)fn bytes(&self) -> &'a [u8]fn len(&self) -> usizefn is_empty(&self) -> boolfn is_error(&self) -> boolan error message (types 0 to 127, RFC 4443 2.1)fn is_nd(&self) -> boola message of Neighbor Discoveryfn quoted(&self) -> Option<Ipv6View<'a>>the packet an error message quotes (cut where the quote ends)fn error_quote(packet: &[u8]) -> &[u8]as much of the offending packet as an error may quote: the error packet stays within the minimum MTU of 1280 bytes (40 bytes IPv6, 8 bytes ICMPv6, at most 1232 of the packet)enum Icmp6an ICMPv6 message with the 8-byte header (echo and the errors) to writeEchoRequest { id: u16, seq: u16 }EchoReply { id: u16, seq: u16 }DestUnreach { code: u8 }PacketTooBig { mtu: u32 }TimeExceeded { code: u8 }ParamProblem { code: u8, pointer: u32 }Other { typ: u8, code: u8, rest: [u8; 4] }
impl Icmp6
fn read(v: &Icmp6View) -> Icmp6fn type_code(&self) -> (u8, u8)fn is_error(&self) -> boolfn encode(&self, src: Ipv6, dst: Ipv6, body: &[u8]) -> Vec<u8>header + body with the checksum over the pseudo headerfn push_v6(&self, p: &mut Pkt, src: Ipv6, dst: Ipv6)prepends the header (the packet's content is the body) with the checksumstruct Rathe fixed fields of a Router Advertisement (RFC 4861 4.2; the preference bits of RFC 4191)hop_limit: u8-- 0: unspecifiedmanaged: bool-- addresses from DHCPv6 (M) / other settings from DHCPv6 (O)other: boolprf: u8-- default router preference: 0 medium, 1 high, 3 low (2 is reserved, read as medium)lifetime: u16-- seconds; 0: not a default routerreachable: u32-- milliseconds; 0: unspecifiedretrans: u32
struct PrefixInfoa prefix information option (RFC 4861 4.6.2)len: u8on_link: bool-- the prefix is on the link (L)auto: bool-- addresses may be formed from it (A, RFC 4862)valid: u32-- seconds, INFINITE for everpreferred: u32prefix: Ipv6
enum NdOptan option of an ND messageSrcLla(Mac)TgtLla(Mac)Prefix(PrefixInfo)Redirected(Vec<u8>)-- what a redirect carries of the redirected packetMtu(u32)Other(u8, Vec<u8>)-- any other option: its type and its bytes after type and length
impl NdOpt
fn kind(&self) -> u8enum NdMsgthe message of NDRouterSolicitRouterAdvert(Ra)NeighborSolicit { target: Ipv6 }NeighborAdvert { router: bool, solicited: bool, override_: bool, target: Ipv6 }Redirect { target: Ipv6, dst: Ipv6 }
enum NdErrwhy a receiver drops an ND message (RFC 4861 6.1, 7.1, 8.1)Code(u8)-- the ICMP code is not 0Short-- shorter than the message's fixed partBadOption-- an option with length 0, or one that runs past the endMulticast-- a group address as the target of NS / NA or as the destination of a redirectNotNd-- not an ND typeHopLimit-- the hop limit is not 255: the message did not come from this linkSource-- a router advertisement or redirect from an address that is not link-localDadDest-- an address detection probe (unspecified source) not sent to a solicited-node groupSourceLla-- an unspecified source with a source link-layer address optionSolicitedToGroup-- a solicited advertisement sent to a group
impl NdErr
fn text(&self) -> &'static strthe reason in the words of capture tools (English)struct Nda Neighbor Discovery message with its optionsmsg: NdMsgopts: Vec<NdOpt>
fn options(b: &[u8]) -> Result<Vec<(NdOpt, usize, usize)>, NdErr>the options ofb(the bytes after the fixed part): each with its offset and length inb; Err when one has length 0 or runs past the endfn fixed_len(typ: u8) -> Option<usize>the length of the fixed part of an ND message type
impl Nd
fn new(msg: NdMsg, opts: Vec<NdOpt>) -> Ndfn rs(src_lla: Option<Mac>) -> Nda Router Solicitation (with the sender's MAC unless it has no address yet)fn ns(target: Ipv6, src_lla: Option<Mac>) -> Nda Neighbor Solicitation (DAD probes carry no source link-layer address)fn na(target: Ipv6, router: bool, solicited: bool, override_: bool, tgt_lla: Option<Mac>) -> Nda Neighbor Advertisementfn parse(v: &Icmp6View) -> Result<Nd, NdErr>reads an ND message (the checks RFC 4861 makes on the message itself)fn typ(&self) -> u8fn encode(&self, src: Ipv6, dst: Ipv6) -> Vec<u8>the message with its checksumfn src_lla(&self) -> Option<Mac>the source link-layer address optionfn tgt_lla(&self) -> Option<Mac>the target link-layer address optionfn prefixes(&self) -> impl Iterator<Item = &PrefixInfo>the prefix information optionsfn mtu(&self) -> Option<u32>the MTU optionfn check_ip(&self, src: Ipv6, dst: Ipv6, hop_limit: u8) -> Option<NdErr>the rules of RFC 4861 that need the packet's addresses and hop limit: hop limit 255 for every message, a link-local source for RA and redirect, an unspecified source only with a solicited-node destination and without a source link-layer address (NS) or without it (RS), solicited NA never to a group; None when the message may be takenfn name(typ: u8, code: u8) -> &'static stra name of an ICMPv6 type and code as capture tools write it