Skip to content

Commit

Permalink
Fix the ipv6 option structure
Browse files Browse the repository at this point in the history
The IPv6 Option representation layer structure includes the type value
as the raw u8. This should be stored as the Type enum.
  • Loading branch information
dlrobertson committed Jun 5, 2018
1 parent 2363f97 commit fed0600
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/wire/ipv6option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub enum Repr<'a> {
Pad1,
PadN(u8),
Unknown {
type_: u8,
type_: Type,
length: u8,
data: &'a [u8]
},
Expand All @@ -235,9 +235,9 @@ impl<'a> Repr<'a> {
Ok(Repr::Pad1),
Type::PadN =>
Ok(Repr::PadN(opt.data_len())),
Type::Unknown(type_) => {
unknown_type @ Type::Unknown(_) => {
Ok(Repr::Unknown {
type_: type_,
type_: unknown_type,
length: opt.data_len(),
data: opt.data(),
})
Expand Down Expand Up @@ -272,7 +272,7 @@ impl<'a> Repr<'a> {
}
}
&Repr::Unknown{ type_, length, data } => {
opt.set_option_type(Type::Unknown(type_));
opt.set_option_type(type_);
opt.set_data_len(length);
opt.data_mut().copy_from_slice(&data[..length as usize]);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'a> fmt::Display for Repr<'a> {
&Repr::PadN(len) =>
write!(f, "{} length={} ", Type::PadN, len),
&Repr::Unknown{ type_, length, .. } =>
write!(f, "{} length={} ", Type::Unknown(type_), length),
write!(f, "{} length={} ", type_, length),

&Repr::__Nonexhaustive => unreachable!()
}
Expand Down Expand Up @@ -436,7 +436,7 @@ mod test {
let data = [0u8; 3];
let opt = Ipv6Option::new(&IPV6OPTION_BYTES_UNKNOWN);
let unknown = Repr::parse(&opt).unwrap();
assert_eq!(unknown, Repr::Unknown { type_: 255, length: 3, data: &data});
assert_eq!(unknown, Repr::Unknown { type_: Type::Unknown(255), length: 3, data: &data});
}

#[test]
Expand All @@ -454,7 +454,7 @@ mod test {
assert_eq!(opt.into_inner(), &IPV6OPTION_BYTES_PADN);

let data = [0u8; 3];
let repr = Repr::Unknown { type_: 255, length: 3, data: &data };
let repr = Repr::Unknown { type_: Type::Unknown(255), length: 3, data: &data };
let mut bytes = [254u8; 5]; // don't assume bytes are initialized to zero
let mut opt = Ipv6Option::new(&mut bytes);
repr.emit(&mut opt);
Expand Down Expand Up @@ -493,7 +493,8 @@ mod test {
(2, Ok(Repr::PadN(2))) => continue,
(3, Ok(Repr::PadN(0))) => continue,
(4, Ok(Repr::Pad1)) => continue,
(5, Ok(Repr::Unknown { type_: 0x11, length: 0, .. })) => continue,
(5, Ok(Repr::Unknown { type_: Type::Unknown(0x11), length: 0, .. })) =>
continue,
(6, Err(Error::Truncated)) => continue,
(i, res) => panic!("Unexpected option `{:?}` at index {}", res, i),
}
Expand Down

0 comments on commit fed0600

Please sign in to comment.