Skip to content

Commit 1b01e71

Browse files
authored
Merge pull request #118 from baxterjo/baxterjo/add-traffic-class-support-ipv6
Add Traffic class support for IPv6
2 parents dca1be5 + 2bfe416 commit 1b01e71

File tree

21 files changed

+881
-372
lines changed

21 files changed

+881
-372
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Seeds for failure cases proptest has generated in the past. It is
2+
# automatically read and these particular cases re-run before any
3+
# novel cases are generated.
4+
#
5+
# It is recommended to check this file in to source control so that
6+
# everyone who runs the test benefits from these saved cases.
7+
cc fc12b54abbe610c4344c9f792ab4c501830e658c699e926cebafc50e5c156975 # shrinks to source_ip = [0, 0, 0, 0], dest_ip = [0, 0, 0, 0], ttl = 0, ok_payload_len = 0, err_payload_len = 65516

etherparse/src/compositions_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl<'a> ComponentTest<'a> {
713713
proptest! {
714714
///Test that all known packet compositions are parsed correctly.
715715
#[test]
716-
// #[cfg_attr(miri, ignore)] // vec allocation reduces miri runspeed too much
716+
// #[cfg_attr(miri, ignore)] // vec allocation reduces miri run-speed too much
717717
fn test_compositions(ref eth in ethernet_2_unknown(),
718718
ref vlan0 in vlan_single_unknown(),
719719
ref vlan1 in vlan_single_unknown(),
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use core::{cmp::Eq, cmp::PartialEq, fmt::Debug, hash::Hash};
2+
3+
/// Error if an unknown value is passed to [`crate::IpDscpKnown::try_from_ip_dscp`].
4+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
5+
pub struct IpDscpUnknownValueError {
6+
/// Unknown DSCP value that caused the error.
7+
pub value: u8,
8+
}
9+
10+
impl core::fmt::Display for IpDscpUnknownValueError {
11+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
12+
write!(f, "Error DSCP value '{}' is not known.", self.value)
13+
}
14+
}
15+
16+
#[cfg(feature = "std")]
17+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
18+
impl std::error::Error for IpDscpUnknownValueError {
19+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
20+
None
21+
}
22+
}
23+
24+
#[cfg(test)]
25+
mod test {
26+
use super::*;
27+
use std::{collections::hash_map::DefaultHasher, error::Error, format, hash::Hasher};
28+
29+
#[test]
30+
fn fmt() {
31+
assert_eq!(
32+
format!("{}", IpDscpUnknownValueError { value: 3 }),
33+
"Error DSCP value '3' is not known."
34+
);
35+
}
36+
37+
#[test]
38+
fn dbg() {
39+
assert_eq!(
40+
format!("{:?}", IpDscpUnknownValueError { value: 3 }),
41+
format!("IpDscpUnknownValueError {{ value: {} }}", 3)
42+
);
43+
}
44+
45+
#[test]
46+
fn clone_eq_hash() {
47+
let err = IpDscpUnknownValueError { value: 3 };
48+
assert_eq!(err, err.clone());
49+
let hash_a = {
50+
let mut hasher = DefaultHasher::new();
51+
err.hash(&mut hasher);
52+
hasher.finish()
53+
};
54+
let hash_b = {
55+
let mut hasher = DefaultHasher::new();
56+
err.clone().hash(&mut hasher);
57+
hasher.finish()
58+
};
59+
assert_eq!(hash_a, hash_b);
60+
}
61+
62+
#[cfg(feature = "std")]
63+
#[test]
64+
fn source() {
65+
assert!(IpDscpUnknownValueError { value: 3 }.source().is_none());
66+
}
67+
}

etherparse/src/err/ip/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ mod headers_write_error;
1717
#[cfg(feature = "std")]
1818
pub use headers_write_error::*;
1919

20+
pub mod ip_dscp_unknown_value_error;
21+
pub use ip_dscp_unknown_value_error::*;
22+
2023
mod lax_header_slice_error;
2124
pub use lax_header_slice_error::*;
2225

etherparse/src/err/value_type.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ pub enum ValueType {
66
VlanId,
77
/// VLAN PCP (Priority Code Point) field in a [`crate::SingleVlanHeader`].
88
VlanPcp,
9-
/// MACsec association number (present in the [`crate::MacSecHeader`]).
9+
/// MACsec association number (present in the [`crate::MacsecHeader`]).
1010
MacsecAn,
11-
/// MACsec short length (present in the [`crate::MacSecHeader`]).
11+
/// MACsec short length (present in the [`crate::MacsecHeader`]).
1212
MacsecShortLen,
1313
/// IP Fragment offset present in the IPv4 header and
1414
/// IPv6 fragmentation header.
1515
IpFragmentOffset,
16-
/// IPv4 Header DSCP (Differentiated Services Code Point) field
17-
/// present in an [`crate::Ipv4Header`].
18-
Ipv4Dscp,
19-
/// IPv4 Header ECN (Explicit Congestion Notification) field
20-
/// present in an [`crate::Ipv4Header`].
21-
Ipv4Ecn,
16+
/// IPv4 & IPv6 Header DSCP (Differentiated Services Code Point) field
17+
/// present in an [`crate::Ipv4Header`] or [`crate::Ipv6Header`].
18+
IpDscp,
19+
/// IPv6 & IPv6 Header ECN (Explicit Congestion Notification) field
20+
/// present in an [`crate::Ipv4Header`] or [`crate::Ipv6Header`].
21+
IpEcn,
2222
/// IPv6 Header Flow Label field present in [`crate::Ipv6Header`].
2323
Ipv6FlowLabel,
2424
/// IPv4 Header "total length" field based on the payload
@@ -54,8 +54,8 @@ impl core::fmt::Display for ValueType {
5454
MacsecAn => write!(f, "MACsec AN (Association Number)"),
5555
MacsecShortLen => write!(f, "MACsec SL (Short Length)"),
5656
IpFragmentOffset => write!(f, "IP Fragment Offset"),
57-
Ipv4Dscp => write!(f, "IPv4 DSCP (Differentiated Services Code Point)"),
58-
Ipv4Ecn => write!(f, "IPv4 ECN (Explicit Congestion Notification)"),
57+
IpDscp => write!(f, "IPv4 DSCP (Differentiated Services Code Point)"),
58+
IpEcn => write!(f, "IPv4 ECN (Explicit Congestion Notification)"),
5959
Ipv6FlowLabel => write!(f, "IPv6 Flow Label"),
6060
Ipv4PayloadLength => write!(f, "IPv4 Header 'Payload Length' (sets 'Total Length')"),
6161
Ipv6PayloadLength => write!(f, "IPv6 Header 'Payload Length'"),
@@ -102,11 +102,11 @@ mod test {
102102
assert_eq!("IP Fragment Offset", &format!("{}", IpFragmentOffset));
103103
assert_eq!(
104104
"IPv4 DSCP (Differentiated Services Code Point)",
105-
&format!("{}", Ipv4Dscp)
105+
&format!("{}", IpDscp)
106106
);
107107
assert_eq!(
108108
"IPv4 ECN (Explicit Congestion Notification)",
109-
&format!("{}", Ipv4Ecn)
109+
&format!("{}", IpEcn)
110110
);
111111
assert_eq!("IPv6 Flow Label", &format!("{}", Ipv6FlowLabel));
112112
assert_eq!(

etherparse/src/lax_sliced_packet_cursor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'a> LaxSlicedPacketCursor<'a> {
135135
len_source: self.len_source,
136136
payload: vlan_payload.payload,
137137
};
138-
// SAFETY: Safe, as the if at the startt verifies that there is still
138+
// SAFETY: Safe, as the if at the start verifies that there is still
139139
// space in link_exts.
140140
unsafe {
141141
self.result
@@ -165,7 +165,7 @@ impl<'a> LaxSlicedPacketCursor<'a> {
165165

166166
self.offset += macsec.header.header_len();
167167
let macsec_payload = macsec.payload.clone();
168-
// SAFETY: Safe, as the if at the startt verifies that there is still
168+
// SAFETY: Safe, as the if at the start verifies that there is still
169169
// space in link_exts.
170170
unsafe {
171171
self.result

etherparse/src/link/macsec_an.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::err::ValueTooBigError;
22

33
/// 2 bit unsigned integer containing the "MACsec association number".
4-
/// (present in the [`crate::MacSecHeader`]).
4+
/// (present in the [`crate::MacsecHeader`]).
55
///
66
/// Identifies up to four SAs within the context of an SC.
77
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]

etherparse/src/link/macsec_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl MacsecHeader {
5858
}
5959
}
6060

61-
/// Try creating a [`MacSecHeaderSlice`] from a slice containing the
61+
/// Try creating a [`MacsecHeaderSlice`] from a slice containing the
6262
/// MACsec header & next ether type.
6363
pub fn from_slice(slice: &[u8]) -> Result<MacsecHeader, err::macsec::HeaderSliceError> {
6464
MacsecHeaderSlice::from_slice(slice).map(|v| v.to_header())

etherparse/src/link/macsec_header_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct MacsecHeaderSlice<'a> {
1010
}
1111

1212
impl<'a> MacsecHeaderSlice<'a> {
13-
/// Try creating a [`MacSecHeaderSlice`] from a slice containing the
13+
/// Try creating a [`MacsecHeaderSlice`] from a slice containing the
1414
/// MACsec header & next ether type.
1515
pub fn from_slice(
1616
slice: &'a [u8],
@@ -270,7 +270,7 @@ impl<'a> MacsecHeaderSlice<'a> {
270270
}
271271

272272
/// Decodes all MacSecHeader values and returns them as a
273-
/// [`crate::MacSecHeader`].
273+
/// [`crate::MacsecHeader`].
274274
#[inline]
275275
pub fn to_header(&self) -> MacsecHeader {
276276
MacsecHeader {

etherparse/src/link/macsec_short_len.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::err::ValueTooBigError;
22

33
/// 6 bit unsigned integer containing the "MACsec short length".
4-
/// (present in the [`crate::MacSecHeader`]).
4+
/// (present in the [`crate::MacsecHeader`]).
55
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
66
pub struct MacsecShortLen(u8);
77

@@ -70,7 +70,7 @@ impl MacsecShortLen {
7070

7171
/// Creates an [`MacsecShortLen`] from a length and automatically
7272
/// defaults to zero if too big. This mirrors the expected behavior
73-
/// of the `short_len` field in the [`MacsecHeader`].
73+
/// of the `short_len` field in the [`crate::MacsecHeader`].
7474
///
7575
/// # Example
7676
/// ```

0 commit comments

Comments
 (0)