summaryrefslogtreecommitdiff
path: root/src/protocol/ipv6.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol/ipv6.rs')
-rw-r--r--src/protocol/ipv6.rs58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/protocol/ipv6.rs b/src/protocol/ipv6.rs
index c32d21b..639c023 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,7 +280,7 @@ mod tests {
0xff, /* Payload */
];
- let expectation = Ipv6Header {
+ let expectation = IPv6Header {
version: 6,
dsc: 0,
ecn: 0,
@@ -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,7 +350,7 @@ mod tests {
0xff, /* Payload */
];
- let expectation = Ipv6Header {
+ let expectation = IPv6Header {
version: 6,
dsc: 0,
ecn: 0,
@@ -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,7 +458,7 @@ mod tests {
0xff, /* Payload */
];
- let expectation = Ipv6Header {
+ let expectation = IPv6Header {
version: 6,
dsc: 0,
ecn: 0,
@@ -473,22 +473,22 @@ mod tests {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003,
),
extensions: vec![
- Ipv6Extension {
+ IPv6Extension {
next_header: IPProtocol::IPV6DEST,
ext_length: 8,
data: vec![0x01, 0x04, 0x00, 0x00, 0x00, 0x00],
},
- Ipv6Extension {
+ IPv6Extension {
next_header: IPProtocol::IPV6ROUTING,
ext_length: 8,
data: vec![0x01, 0x04, 0x00, 0x00, 0x00, 0x00],
},
- Ipv6Extension {
+ 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 {