JFLib

netpkt/ipv6.rs#

Source: lib/netpkt/ipv6.rs

ipv6 -- the IPv6 fixed header (RFC 8200), the walk over extension headers, the fragment
header, fragmentation and reassembly

  Ipv6View::parse(b)    version 6, payload length within the buffer
  Ipv6View::parse_truncated(b)   a packet that may be cut after its header (the quote inside
                        an ICMPv6 error): payload() ends at the end of the buffer
  Ipv6Hdr { .. }        write(out, payload_len), push_onto(&mut Pkt)
  upper_layer(v)        (next header, offset in the payload) after hop-by-hop, routing,
                        fragment and destination options headers
  ext_headers(v)        the extension headers in order (type, offset, length, next header);
                        None for a malformed chain
  FragHdr / frag(v)     the fragment header (offset in bytes, more fragments, identification)
                        and where it sits
  fragment(pkt, mtu, id)  fragments of at most `mtu` bytes with a fragment header (RFC 8200
                        4.5: the unfragmentable part -- the header, hop-by-hop and routing
                        headers -- in front of each); None when even one 8-byte unit does
                        not fit
  Reassembly6           collects the fragments of one packet; overlapping fragments drop the
                        whole packet (RFC 5722); no timers: the caller expires it after 60 s
  dec_hop_limit(pkt)    hop limit - 1 in place (IPv6 has no header checksum)

ICMPv6 and Neighbor Discovery are in icmpv6.rs; the addresses of ND (solicited-node groups,
EUI-64 interface identifiers, multicast MACs) in addr.rs.
IPV6_HDR: usize = 40
/// the minimum link MTU of IPv6 (RFC 8200 5)
MIN_MTU: usize = 1280
/// the length of the fragment header
FRAG_HDR: usize = 8
NH_HOPOPT: u8 = 0
NH_TCP: u8 = 6
NH_UDP: u8 = 17
NH_ROUTING: u8 = 43
NH_FRAGMENT: u8 = 44
NH_ESP: u8 = 50
NH_AH: u8 = 51
NH_ICMPV6: u8 = 58
NH_NONE: u8 = 59
NH_DSTOPTS: u8 = 60
  • fn ext_name(nh: u8) -> Option<&'static str> a name for an extension header type ("Hop-by-Hop Options", "Fragment", ...)

  • struct Ipv6View<'a> a received IPv6 packet

impl<'a> Ipv6View<'a>

  • fn parse(b: &'a [u8]) -> Option<Ipv6View<'a>>

  • fn parse_truncated(b: &'a [u8]) -> Option<Ipv6View<'a>> a packet that may be cut after its header (the quote inside an ICMPv6 error)

  • fn is_truncated(&self) -> bool fewer bytes than the payload length are present

  • fn traffic_class(&self) -> u8

  • fn flow_label(&self) -> u32

  • fn payload_len(&self) -> usize

  • fn next_header(&self) -> u8

  • fn hop_limit(&self) -> u8

  • fn src(&self) -> Ipv6

  • fn dst(&self) -> Ipv6

  • fn payload(&self) -> &'a [u8] the payload up to the payload length (or the end of a truncated quote)

  • fn packet(&self) -> &'a [u8] header and payload, without trailing padding

  • fn upper_layer(v: &Ipv6View) -> Option<(u8, usize)> the upper-layer protocol and its offset in the payload, after the extension headers; None for a malformed chain

  • struct ExtHdr one extension header of a packet

    • kind: u8 -- its type (the Next Header value that announced it)
    • off: usize -- offset and length in the payload
    • len: usize
    • next: u8 -- the Next Header field it carries
  • fn ext_headers(v: &Ipv6View) -> Option<Vec<ExtHdr>> the extension headers of a packet in order; None for a malformed chain

  • struct FragHdr the fragment header of a packet

    • next: u8
    • offset: usize -- the offset of the fragment's data in bytes (a multiple of 8)
    • more: bool
    • id: u32

impl FragHdr

  • fn read(b: &[u8]) -> FragHdr

  • fn write(&self, out: &mut [u8])

  • fn frag(v: &Ipv6View) -> Option<(FragHdr, usize)> the fragment header of a packet and its offset in the payload (None: not a fragment)

  • fn fragment(packet: &[u8], mtu: usize, id: u32) -> Option<Vec<Vec<u8>>> splits a packet into fragments of at most mtu bytes (RFC 8200 4.5); a packet that fits comes back alone. None when the packet is malformed, is a fragment already, or not even one 8-byte unit of data fits.

  • fn dec_hop_limit(pkt: &mut [u8]) -> u8 lowers the hop limit by one in place; the new value

  • enum ReasmErr why a fragment could not be taken (the receiver answers the first two with a Parameter Problem, RFC 8200 4.5)

    • BadLength -- a fragment with more to come whose data is not a multiple of 8 bytes (pointer: the Payload Length field)
    • TooLong -- offset and length go beyond 65535 bytes (pointer: the Fragment Offset field)
    • Overlap -- it overlaps a fragment already held: the whole packet is dropped (RFC 5722)
  • struct Reassembly6 the fragments of one packet (key: source, destination, identification)

  • fn reassembly_key(v: &Ipv6View, f: &FragHdr) -> (Ipv6, Ipv6, u32) the reassembly key of a fragment

impl Reassembly6

  • fn new() -> Reassembly6

  • fn add(&mut self, v: &Ipv6View, f: &FragHdr, at: usize) -> Result<Option<Vec<u8>>, ReasmErr> adds a fragment (at: the offset of its fragment header in the payload); Ok(Some(the complete packet)) when all parts are there

  • fn has_first(&self) -> bool the first fragment (offset 0) is here: a timeout is answered with Time Exceeded

  • fn first_packet(&self) -> Option<Vec<u8>> the source and header of the first fragment (what a timeout's error quotes)

  • fn collected(&self) -> usize bytes collected so far

  • struct Ipv6Hdr an IPv6 fixed header to write

    • traffic_class: u8
    • flow_label: u32
    • next_header: u8
    • hop_limit: u8
    • src: Ipv6
    • dst: Ipv6

impl Ipv6Hdr

  • const LEN: usize = IPV6_HDR
  • fn new(src: Ipv6, dst: Ipv6, next_header: u8, hop_limit: u8) -> Ipv6Hdr
  • fn read(v: &Ipv6View) -> Ipv6Hdr
  • fn write(&self, out: &mut [u8], payload_len: usize)
  • fn push_onto(&self, p: &mut Pkt)
  • fn packet(&self, payload: &[u8]) -> Vec<u8> header + payload as a new packet

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