JFLib

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 checksum

  • fn typ(&self) -> u8

  • fn code(&self) -> u8

  • fn checksum(&self) -> u16

  • fn checksum_ok(&self, src: Ipv6, dst: Ipv6) -> bool the checksum over the pseudo header of src and dst and the whole message

  • fn checksum_want(&self, src: Ipv6, dst: Ipv6) -> u16 the 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) -> u16

  • fn seq(&self) -> u16

  • fn value(&self) -> u32 the MTU of Packet Too Big, the pointer of Parameter Problem

  • fn 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) -> usize

  • fn is_empty(&self) -> bool

  • fn is_error(&self) -> bool an error message (types 0 to 127, RFC 4443 2.1)

  • fn is_nd(&self) -> bool a message of Neighbor Discovery

  • fn 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 Icmp6 an ICMPv6 message with the 8-byte header (echo and the errors) to write

    • EchoRequest { 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) -> Icmp6

  • fn type_code(&self) -> (u8, u8)

  • fn is_error(&self) -> bool

  • fn encode(&self, src: Ipv6, dst: Ipv6, body: &[u8]) -> Vec<u8> header + body with the checksum over the pseudo header

  • fn push_v6(&self, p: &mut Pkt, src: Ipv6, dst: Ipv6) prepends the header (the packet's content is the body) with the checksum

  • struct Ra the fixed fields of a Router Advertisement (RFC 4861 4.2; the preference bits of RFC 4191)

    • hop_limit: u8 -- 0: unspecified
    • managed: bool -- addresses from DHCPv6 (M) / other settings from DHCPv6 (O)
    • other: bool
    • prf: u8 -- default router preference: 0 medium, 1 high, 3 low (2 is reserved, read as medium)
    • lifetime: u16 -- seconds; 0: not a default router
    • reachable: u32 -- milliseconds; 0: unspecified
    • retrans: u32
  • struct PrefixInfo a prefix information option (RFC 4861 4.6.2)

    • len: u8
    • on_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 ever
    • preferred: u32
    • prefix: Ipv6
  • enum NdOpt an option of an ND message

    • SrcLla(Mac)
    • TgtLla(Mac)
    • Prefix(PrefixInfo)
    • Redirected(Vec<u8>) -- what a redirect carries of the redirected packet
    • Mtu(u32)
    • Other(u8, Vec<u8>) -- any other option: its type and its bytes after type and length

impl NdOpt

  • fn kind(&self) -> u8

  • enum NdMsg the message of ND

    • RouterSolicit
    • RouterAdvert(Ra)
    • NeighborSolicit { target: Ipv6 }
    • NeighborAdvert { router: bool, solicited: bool, override_: bool, target: Ipv6 }
    • Redirect { target: Ipv6, dst: Ipv6 }
  • enum NdErr why a receiver drops an ND message (RFC 4861 6.1, 7.1, 8.1)

    • Code(u8) -- the ICMP code is not 0
    • Short -- shorter than the message's fixed part
    • BadOption -- an option with length 0, or one that runs past the end
    • Multicast -- a group address as the target of NS / NA or as the destination of a redirect
    • NotNd -- not an ND type
    • HopLimit -- the hop limit is not 255: the message did not come from this link
    • Source -- a router advertisement or redirect from an address that is not link-local
    • DadDest -- an address detection probe (unspecified source) not sent to a solicited-node group
    • SourceLla -- an unspecified source with a source link-layer address option
    • SolicitedToGroup -- a solicited advertisement sent to a group

impl NdErr

  • fn text(&self) -> &'static str the reason in the words of capture tools (English)

  • struct Nd a Neighbor Discovery message with its options

    • msg: NdMsg
    • opts: Vec<NdOpt>
  • fn options(b: &[u8]) -> Result<Vec<(NdOpt, usize, usize)>, NdErr> the options of b (the bytes after the fixed part): each with its offset and length in b; Err when one has length 0 or runs past the end

  • fn 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>) -> Nd

  • fn rs(src_lla: Option<Mac>) -> Nd a Router Solicitation (with the sender's MAC unless it has no address yet)

  • fn ns(target: Ipv6, src_lla: Option<Mac>) -> Nd a Neighbor Solicitation (DAD probes carry no source link-layer address)

  • fn na(target: Ipv6, router: bool, solicited: bool, override_: bool, tgt_lla: Option<Mac>) -> Nd a Neighbor Advertisement

  • fn parse(v: &Icmp6View) -> Result<Nd, NdErr> reads an ND message (the checks RFC 4861 makes on the message itself)

  • fn typ(&self) -> u8

  • fn encode(&self, src: Ipv6, dst: Ipv6) -> Vec<u8> the message with its checksum

  • fn src_lla(&self) -> Option<Mac> the source link-layer address option

  • fn tgt_lla(&self) -> Option<Mac> the target link-layer address option

  • fn prefixes(&self) -> impl Iterator<Item = &PrefixInfo> the prefix information options

  • fn mtu(&self) -> Option<u32> the MTU option

  • fn 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 taken

  • fn name(typ: u8, code: u8) -> &'static str a name of an ICMPv6 type and code as capture tools write it

Source: docs/API.md in the JFLib repository.