wire: Add the FailureType for IPv6 ext hdr options
Add the FailureType enumeration that can be acquired from a IPv6 extension header option which determines the required action if the extension header option type is not known or is not supported. Closes: #204 Approved by: whitequarkv0.7.x
parent
5bc3ec35a5
commit
435292cc35
|
@ -21,6 +21,41 @@ impl fmt::Display for Type {
|
|||
}
|
||||
}
|
||||
|
||||
enum_with_unknown! {
|
||||
/// Action required when parsing the given IPv6 Extension
|
||||
/// Header Option Type fails
|
||||
pub doc enum FailureType(u8) {
|
||||
/// Skip this option and continue processing the packet
|
||||
Skip = 0b00000000,
|
||||
/// Discard the containing packet
|
||||
Discard = 0b01000000,
|
||||
/// Discard the containing packet and notify the sender
|
||||
DiscardSendAll = 0b10000000,
|
||||
/// Discard the containing packet and only notify the sender
|
||||
/// if the sender is a unicast address
|
||||
DiscardSendUnicast = 0b11000000,
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FailureType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&FailureType::Skip => write!(f, "skip"),
|
||||
&FailureType::Discard => write!(f, "discard"),
|
||||
&FailureType::DiscardSendAll => write!(f, "discard and send error"),
|
||||
&FailureType::DiscardSendUnicast => write!(f, "discard and send error if unicast"),
|
||||
&FailureType::Unknown(id) => write!(f, "Unknown({})", id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Type> for FailureType {
|
||||
fn from(other: Type) -> FailureType {
|
||||
let raw: u8 = other.into();
|
||||
Self::from(raw & 0b11000000u8)
|
||||
}
|
||||
}
|
||||
|
||||
/// A read/write wrapper around an IPv6 Extension Header Option.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Ipv6Option<T: AsRef<[u8]>> {
|
||||
|
@ -374,4 +409,18 @@ mod test {
|
|||
repr.emit(&mut opt);
|
||||
assert_eq!(opt.into_inner(), &IPV6OPTION_BYTES_UNKNOWN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_failure_type() {
|
||||
let mut failure_type: FailureType = Type::Pad1.into();
|
||||
assert_eq!(failure_type, FailureType::Skip);
|
||||
failure_type = Type::PadN.into();
|
||||
assert_eq!(failure_type, FailureType::Skip);
|
||||
failure_type = Type::Unknown(0b01000001).into();
|
||||
assert_eq!(failure_type, FailureType::Discard);
|
||||
failure_type = Type::Unknown(0b10100000).into();
|
||||
assert_eq!(failure_type, FailureType::DiscardSendAll);
|
||||
failure_type = Type::Unknown(0b11000100).into();
|
||||
assert_eq!(failure_type, FailureType::DiscardSendUnicast);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue