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) -> boolfewer bytes than the payload length are presentfn traffic_class(&self) -> u8fn flow_label(&self) -> u32fn payload_len(&self) -> usizefn next_header(&self) -> u8fn hop_limit(&self) -> u8fn src(&self) -> Ipv6fn dst(&self) -> Ipv6fn 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 paddingfn 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 chainstruct ExtHdrone extension header of a packetkind: u8-- its type (the Next Header value that announced it)off: usize-- offset and length in the payloadlen: usizenext: 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 chainstruct FragHdrthe fragment header of a packetnext: u8offset: usize-- the offset of the fragment's data in bytes (a multiple of 8)more: boolid: u32
impl FragHdr
fn read(b: &[u8]) -> FragHdrfn 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 mostmtubytes (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]) -> u8lowers the hop limit by one in place; the new valueenum ReasmErrwhy 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 Reassembly6the 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() -> Reassembly6fn 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 therefn has_first(&self) -> boolthe first fragment (offset 0) is here: a timeout is answered with Time Exceededfn first_packet(&self) -> Option<Vec<u8>>the source and header of the first fragment (what a timeout's error quotes)fn collected(&self) -> usizebytes collected so farstruct Ipv6Hdran IPv6 fixed header to writetraffic_class: u8flow_label: u32next_header: u8hop_limit: u8src: Ipv6dst: Ipv6
impl Ipv6Hdr
const LEN: usize = IPV6_HDRfn new(src: Ipv6, dst: Ipv6, next_header: u8, hop_limit: u8) -> Ipv6Hdrfn read(v: &Ipv6View) -> Ipv6Hdrfn 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