//! Explicit first-version policy: no IPv4 fragment reassembly or fragment //! queues. A checksum-validated header is required before this decision. use turkos_ipv4_packet::packet::Packet; #[derive(Clone,Copy,Debug,PartialEq,Eq)] #[repr(u64)] pub enum Error { FragmentUnsupported=1, ReservedFlag=2 } #[derive(Clone,Copy,Debug,PartialEq,Eq)] pub struct Datagram<'a> { packet:Packet<'a> } impl<'a> Datagram<'a> { pub fn parse(packet:Packet<'a>)->Result{ if packet.flags_offset()&0x8000!=0{return Err(Error::ReservedFlag);} if packet.flags_offset()&0x3fff!=0{return Err(Error::FragmentUnsupported);} Ok(Self{packet}) } pub fn packet(&self)->Packet<'a>{self.packet} pub fn payload(&self)->&'a[u8]{self.packet.payload()} pub fn deliver(packet:Packet<'a>,sink:impl FnOnce(Self)->R)->Result{let datagram=Self::parse(packet)?;Ok(sink(datagram))} }