diff options
Diffstat (limited to 'src/protocol/ipv6.rs')
| -rw-r--r-- | src/protocol/ipv6.rs | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/protocol/ipv6.rs b/src/protocol/ipv6.rs index 5a30847..c32d21b 100644 --- a/src/protocol/ipv6.rs +++ b/src/protocol/ipv6.rs @@ -60,14 +60,14 @@ use std::net::Ipv6Addr; */ #[derive(Clone, Debug, PartialEq, Eq)] -pub struct IPv6Extension { +pub struct Ipv6Extension { pub next_header: IPProtocol, pub ext_length: u8, // Extension total Length pub data: Vec<u8>, // Extension data length (ext_length - 2) } #[derive(Clone, Debug, PartialEq, Eq)] -pub struct IPv6Header { +pub struct Ipv6Header { pub version: u8, // 4 bit pub dsc: u8, // Differentiated Services Codepoint: 6 bit pub ecn: u8, // Explicit Congestion Notification: 2 bit @@ -77,7 +77,7 @@ pub struct IPv6Header { pub hop_limit: u8, pub source_address: Ipv6Addr, pub dest_address: Ipv6Addr, - pub extensions: Vec<IPv6Extension>, + pub extensions: Vec<Ipv6Extension>, } /****************************************************************************** @@ -97,7 +97,7 @@ fn address_v6_decode(input: &[u8]) -> IResult<&[u8], Ipv6Addr> { Ok((input, Ipv6Addr::from(<[u8; 16]>::try_from(ipv6).unwrap()))) } -fn extension_decode(input: &[u8], curr_proto: IPProtocol) -> IResult<&[u8], IPv6Extension> { +fn extension_decode(input: &[u8], curr_proto: IPProtocol) -> IResult<&[u8], Ipv6Extension> { let (input, next_header) = IPProtocol::decode(input)?; let (input, mut ext_length) = number::streaming::be_u8(input)?; @@ -117,7 +117,7 @@ fn extension_decode(input: &[u8], curr_proto: IPProtocol) -> IResult<&[u8], IPv6 Ok(( input, - IPv6Extension { + Ipv6Extension { next_header, ext_length, data: data.to_vec(), @@ -125,9 +125,9 @@ fn extension_decode(input: &[u8], curr_proto: IPProtocol) -> IResult<&[u8], IPv6 )) } -impl Decode for IPv6Header { - type Iterm = IPv6Header; - fn decode(input: &[u8]) -> IResult<&[u8], IPv6Header> { +impl Decode for Ipv6Header { + type Iterm = Ipv6Header; + fn decode(input: &[u8]) -> IResult<&[u8], Ipv6Header> { let (input, ver_tc) = half_byte_decode(input)?; let (input, tc_fl) = half_byte_decode(input)?; let (input, fl): (_, u32) = @@ -150,7 +150,7 @@ impl Decode for IPv6Header { Ok(( remain, - IPv6Header { + Ipv6Header { version: ver_tc.0, dsc: (ver_tc.1 << 2) + ((tc_fl.0 & 0b1100) >> 2), ecn: tc_fl.0 & 0b11, @@ -172,8 +172,8 @@ impl Decode for IPv6Header { #[cfg(test)] mod tests { - use super::IPv6Extension; - use super::IPv6Header; + use super::Ipv6Extension; + use super::Ipv6Header; use crate::protocol::codec::Decode; use crate::protocol::ip::IPProtocol; use std::net::Ipv6Addr; @@ -210,7 +210,7 @@ mod tests { 0xff, /* Payload */ ]; - let expectation = IPv6Header { + let expectation = Ipv6Header { version: 6, dsc: 0, ecn: 0, @@ -227,10 +227,10 @@ mod tests { extensions: Vec::new(), }; - assert_eq!(IPv6Header::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(Ipv6Header::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = IPv6Header::decode(&bytes); + let result = Ipv6Header::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { @@ -280,13 +280,13 @@ mod tests { 0xff, /* Payload */ ]; - let expectation = IPv6Header { + let expectation = Ipv6Header { version: 6, dsc: 0, ecn: 0, flow_label: 0, length: 36, - next_header: IPProtocol::IPV6_HOP_HDR, + next_header: IPProtocol::IPV6HOP, hop_limit: 1, source_address: Ipv6Addr::new( 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -294,17 +294,17 @@ mod tests { dest_address: Ipv6Addr::new( 0xff02, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0016, ), - extensions: vec![IPv6Extension { + extensions: vec![Ipv6Extension { next_header: IPProtocol::ICMP6, ext_length: 8, data: vec![0x05, 0x02, 0x00, 0x00, 0x01, 0x00], }], }; - assert_eq!(IPv6Header::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(Ipv6Header::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = IPv6Header::decode(&bytes); + let result = Ipv6Header::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { @@ -350,13 +350,13 @@ mod tests { 0xff, /* Payload */ ]; - let expectation = IPv6Header { + let expectation = Ipv6Header { version: 6, dsc: 0, ecn: 0, flow_label: 0, length: 32, - next_header: IPProtocol::IPV6_ROUTING_HDR, + next_header: IPProtocol::IPV6ROUTING, hop_limit: 4, source_address: Ipv6Addr::new( 0x2200, 0x0000, 0x0000, 0x0244, 0x0212, 0x3fff, 0xfeae, 0x22f7, @@ -364,7 +364,7 @@ mod tests { dest_address: Ipv6Addr::new( 0x2200, 0x0000, 0x0000, 0x0240, 0x0002, 0x0000, 0x0000, 0x0004, ), - extensions: vec![IPv6Extension { + extensions: vec![Ipv6Extension { next_header: IPProtocol::ICMP6, ext_length: 24, data: vec![ @@ -374,10 +374,10 @@ mod tests { }], }; - assert_eq!(IPv6Header::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(Ipv6Header::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = IPv6Header::decode(&bytes); + let result = Ipv6Header::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { @@ -458,13 +458,13 @@ mod tests { 0xff, /* Payload */ ]; - let expectation = IPv6Header { + let expectation = Ipv6Header { version: 6, dsc: 0, ecn: 0, flow_label: 0, length: 32, - next_header: IPProtocol::IPV6_HOP_HDR, + next_header: IPProtocol::IPV6HOP, hop_limit: 64, source_address: Ipv6Addr::new( 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, @@ -473,22 +473,22 @@ mod tests { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, ), extensions: vec![ - IPv6Extension { - next_header: IPProtocol::IPV6_DEST_HDR, + Ipv6Extension { + next_header: IPProtocol::IPV6DEST, ext_length: 8, data: vec![0x01, 0x04, 0x00, 0x00, 0x00, 0x00], }, - IPv6Extension { - next_header: IPProtocol::IPV6_ROUTING_HDR, + Ipv6Extension { + next_header: IPProtocol::IPV6ROUTING, ext_length: 8, data: vec![0x01, 0x04, 0x00, 0x00, 0x00, 0x00], }, - IPv6Extension { - next_header: IPProtocol::IPV6_FRAGMENT_HDR, + Ipv6Extension { + next_header: IPProtocol::IPV6FRAGMENT, ext_length: 8, data: vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x00], }, - IPv6Extension { + Ipv6Extension { next_header: IPProtocol::Other(59), ext_length: 8, data: vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x00], @@ -496,10 +496,10 @@ mod tests { ], }; - assert_eq!(IPv6Header::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(Ipv6Header::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = IPv6Header::decode(&bytes); + let result = Ipv6Header::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { |
