Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spelling errors in packet builder #79

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

* `SlicedPacket` & `PacketHeaders` now also verify the total_length and payload length fields present in the IPv4 & IPv6 header. This means the `*from_slice*` methods newly throw an error not enough data is present and also newly limit the resulting payload size.
* Removed `ReadError::Ipv6TooManyHeaderExtensions` error when calling `Ipv6Header::skip_all_header_extensions` and `Ipv6Header::skip_all_header_extensions_in_slice`.
* The slice returned by `IpHeader::from_slice`is now the payload of the IP packet (determined by the length specified in the IP header). Previously whatever was left over from the input slice after parsing the IP header and extensions was returned. Now the slice length is limited based on the "payload lenght" field (IPv6) or "total length" field IPv4.
* `Ipv4Header::from_slice` no longer verfies that the `total_len` has enough data to contain the header itself. This check is done when the complete packet is parsed. The check was removed as the `total_len` is sometimes set at a later stage (e.g. in the kernel) in some systems and I would still like to enable people to at least decode the header even if the total length was not yet set.
* The slice returned by `IpHeader::from_slice`is now the payload of the IP packet (determined by the length specified in the IP header). Previously whatever was left over from the input slice after parsing the IP header and extensions was returned. Now the slice length is limited based on the "payload length" field (IPv6) or "total length" field IPv4.
* `Ipv4Header::from_slice` no longer verifies that the `total_len` has enough data to contain the header itself. This check is done when the complete packet is parsed. The check was removed as the `total_len` is sometimes set at a later stage (e.g. in the kernel) in some systems and I would still like to enable people to at least decode the header even if the total length was not yet set.

### Breaking Changes:

Expand All @@ -38,7 +38,7 @@
### Bugfixes

* `PacketHeaders::from_ip_slice` now only tries to decode the transport layer if the packet is not fragmented. Previously it would also try to decode the transport layer even if the packet contained only a fragment.
* The IPv6 extension header skipping functions were previously checking that the slice length is at least 2 before checking if an extension header is even present. If less then two bytes were present an error was returned. This was wrong behavior, as there are no gurantees for other protocols that there are 2 bytes of data present. A check has been added, that validates the header type before checking the slice length. The following functions were corrected:
* The IPv6 extension header skipping functions were previously checking that the slice length is at least 2 before checking if an extension header is even present. If less then two bytes were present an error was returned. This was wrong behavior, as there are no guarantees for other protocols that there are 2 bytes of data present. A check has been added, that validates the header type before checking the slice length. The following functions were corrected:
* `Ipv6Header::skip_header_extension_in_slice`
* `Ipv6Header::skip_all_header_extensions_in_slice`

Expand Down Expand Up @@ -86,7 +86,7 @@

## 0.10.1: Corrected Fragmentation Handling, Additional IP Extension Headers Support & Qualitiy of Life Improvements

With this version the support for IPv6 gets extended and bugs in the parsing of fragmented packets as well as authentification headers are fixed. Additionally a bunch of performance improvements are included and new methods have been added (e.g. the method `to_bytes` for headers with static sizes).
With this version the support for IPv6 gets extended and bugs in the parsing of fragmented packets as well as authentication headers are fixed. Additionally a bunch of performance improvements are included and new methods have been added (e.g. the method `to_bytes` for headers with static sizes).

It has been almost two years since the last update and I think it is fair to say that I underestimated the effort it would take to introduce partial support for IPv6 extension headers. As it was so long sice the last update a bunch of changes have piled on. This also means there are some breaking changes in this version.

Expand All @@ -96,7 +96,7 @@ Special thanks to @Bren2010 for reporting the errors with fragmented packets.

### Extension headers added to `IpHeader` & `InternetSlice`

With the added support for authentification headers (for both IPV4 and IPV6) and additional IPV6 extension headers support a place to store the results when parsing headers or slicing them had be chosen. After some though I decided to put the results into the enum values as a second argument.
With the added support for authentication headers (for both IPV4 and IPV6) and additional IPV6 extension headers support a place to store the results when parsing headers or slicing them had be chosen. After some though I decided to put the results into the enum values as a second argument.

So the signature of `IpHeader` has changed from

Expand Down Expand Up @@ -136,7 +136,7 @@ pub enum InternetSlice<'a> {

### `source()` & `destination()` return static arrays:

Previously when slicing packets the the methods for accessing the `source` & `destionation` returned a slice reference:
Previously when slicing packets the the methods for accessing the `source` & `destination` returned a slice reference:

```rust

Expand Down Expand Up @@ -226,14 +226,14 @@ will no longer use `ip_header.protocol` in their checksum calculations.

### General:

* Corrected decoding & handling of authentification headers & encapsulating security payload for IPv6 packets.
* Corrected decoding & handling of authentication headers & encapsulating security payload for IPv6 packets.
* Added support for authentifaction headers in IPv4 packets.
* Corrected handling of fragmented packets. `InternetSlice::from_*` & `PacketHeaders::from_*` no longer try to decode packets that have been flaged as fragmented (IPv4 & IPv6). Thanks to @Bren2010 for making a PR & noticing the issue.
* Added support for parsing "IPv6 Fragment Headers" & "Authentification Headers"
* Added support for parsing "IPv6 Fragment Headers" & "authentication Headers"
JulianSchmid marked this conversation as resolved.
Show resolved Hide resolved

### Fixed bugs:

* The length field in authentification fields was assumed to be in 8 octet units (same as hop-by-hop options header & the routing header). This was incorrect, the length field is in 4 octet units and the code has been corrected to support this.
* The length field in authentication fields was assumed to be in 8 octet units (same as hop-by-hop options header & the routing header). This was incorrect, the length field is in 4 octet units and the code has been corrected to support this.
* For the "Encapsulating Security Payload header" it was incorrectly assumed, that the basic build up is the same as for the other header extensions (with a next_header & header length field at the start of the header). Parsing of packets will now stop as soon as a "Encapsulating Security Payload header" is encountered.

### Breaking API changes:
Expand Down
4 changes: 2 additions & 2 deletions etherparse/examples/read_by_slicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ fn main() {
let builder = PacketBuilder::ethernet2(
//source mac
[1, 2, 3, 4, 5, 6],
//destionation mac
//destination mac
[7, 8, 9, 10, 11, 12],
)
.ipv4(
//source ip
[192, 168, 1, 1],
//desitionation ip
//destination ip
[192, 168, 1, 2],
//time to life
20,
Expand Down
4 changes: 2 additions & 2 deletions etherparse/examples/write_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ fn main() {
//setup the packet headers
let builder = PacketBuilder::ethernet2(
[1, 2, 3, 4, 5, 6], //source mac
[7, 8, 9, 10, 11, 12], //destionation mac
[7, 8, 9, 10, 11, 12], //destination mac
)
.ipv4(
[192, 168, 1, 1], //source ip
[192, 168, 1, 2], //desitionation ip
[192, 168, 1, 2], //destination ip
20, //time to life
)
.tcp(
Expand Down
4 changes: 2 additions & 2 deletions etherparse/examples/write_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ fn main() {
//setup the packet headers
let builder = PacketBuilder::ethernet2(
[1, 2, 3, 4, 5, 6], //source mac
[7, 8, 9, 10, 11, 12], //destionation mac
[7, 8, 9, 10, 11, 12], //destination mac
)
.ipv4(
[192, 168, 1, 1], //source ip
[192, 168, 1, 2], //desitionation ip
[192, 168, 1, 2], //destination ip
20, //time to life
)
.udp(
Expand Down
18 changes: 9 additions & 9 deletions etherparse/src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Sum16BitWords {
}

/// Converts summed up words from an u32 to an u16 ones complement
/// with 0 beeing replaced by 0xffff (usefull for TCP and UDP).
/// with 0 being replaced by 0xffff (useful for TCP and UDP).
///
/// This kind of checksum is used in TCP and UDP headers.
#[inline]
Expand All @@ -129,7 +129,7 @@ impl Sum16BitWords {
}

/// Converts summed up words from an u32 to an u16 ones complement
/// with 0 beeing replaced by 0xffff (usefull for TCP and UDP).
/// with 0 being replaced by 0xffff (useful for TCP and UDP).
///
/// This kind of checksum is used in TCP and UDP headers.
#[inline]
Expand Down Expand Up @@ -318,7 +318,7 @@ pub mod u32_16bit_word {
sum = add_2bytes(
sum,
// SAFETY:
// If check gurantees there to be at least
// If check guarantees there to be at least
// 2 bytes.
unsafe {
[
Expand All @@ -334,7 +334,7 @@ pub mod u32_16bit_word {
sum = add_2bytes(
sum,
// SAFETY:
// If check gurantees there to be at least
// If check guarantees there to be at least
// 2 bytes.
unsafe { [*slice.get_unchecked(slice.len() - 1), 0] },
);
Expand All @@ -344,7 +344,7 @@ pub mod u32_16bit_word {
sum
}

/// Converts summed up words from an u32 to an u16 with 0 beeing replaced by 0xffff (usefull
/// Converts summed up words from an u32 to an u16 with 0 being replaced by 0xffff (useful
/// for TCP and UDP headers).
///
/// This kind of checksum is used in TCP and udp headers.
Expand Down Expand Up @@ -606,7 +606,7 @@ pub mod u64_16bit_word {
sum = add_4bytes(
sum,
// SAFETY:
// If check gurantees there to be at least
// If check guarantees there to be at least
// 2 bytes.
unsafe {
[
Expand All @@ -629,7 +629,7 @@ pub mod u64_16bit_word {
sum = add_2bytes(
sum,
// SAFETY:
// If check gurantees there to be at least
// If check guarantees there to be at least
// 2 bytes.
unsafe {
[
Expand All @@ -645,7 +645,7 @@ pub mod u64_16bit_word {
sum = add_2bytes(
sum,
// SAFETY:
// If check gurantees there to be at least
// If check guarantees there to be at least
// 2 bytes.
unsafe { [*slice.get_unchecked(slice.len() - 1), 0] },
);
Expand All @@ -655,7 +655,7 @@ pub mod u64_16bit_word {
sum
}

/// Converts summed up words from an u64 to an u16 with 0 beeing replaced by 0xffff (usefull
/// Converts summed up words from an u64 to an u16 with 0 being replaced by 0xffff (useful
/// for TCP and UDP headers).
///
/// This kind of checksum is used in TCP and udp headers.
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/err/double_vlan/header_read_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::HeaderError;
#[cfg(feature = "std")]
#[derive(Debug)]
pub enum HeaderReadError {
/// IO error was encoutered while reading header.
/// IO error was encountered while reading header.
Io(std::io::Error),

/// Error caused by the contents of the header.
Expand Down
4 changes: 2 additions & 2 deletions etherparse/src/err/from_slice_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::*;
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum FromSliceError {
/// Error when parsing had to be aborted because of a length error (usually
/// not enough data beeing available).
/// not enough data being available).
Len(LenError),

/// Error while parsing a double vlan header.
Expand All @@ -15,7 +15,7 @@ pub enum FromSliceError {
/// Error while parsing a IP header.
Ip(ip::HeaderError),

/// Error while parsing a IP authentification header.
/// Error while parsing a IP authentication header.
IpAuth(ip_auth::HeaderError),

/// Error while parsing a IPv4 header.
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/err/io/limited_read_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::err::LenError;
#[derive(Debug)]
#[cfg(feature = "std")]
pub enum LimitedReadError {
/// IO error was encoutered while reading header or
/// IO error was encountered while reading header or
/// expected packet contents.
Io(std::io::Error),

Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/err/ip/header_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum HeaderError {
ihl: u8,
},

/// Error in the IPv4 extension headers (only authentification header).
/// Error in the IPv4 extension headers (only authentication header).
Ipv4Ext(err::ip_auth::HeaderError),

/// Error in the IPv6 extension headers.
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/err/ip/header_read_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::err::LenError;
#[cfg(feature = "std")]
#[derive(Debug)]
pub enum HeaderReadError {
/// IO error was encoutered while reading header.
/// IO error was encountered while reading header.
Io(std::io::Error),

/// Errors caused by conflicts with the lengths defined
Expand Down
8 changes: 4 additions & 4 deletions etherparse/src/err/ip_auth/header_error.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/// Errors that can be encountered while decoding an IP
/// authentification header.
/// authentication header.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum HeaderError {
/// Error when the payload length is zero and therefor
/// too small to contain the minimum fields of the IP
/// authentification itelf.
/// authentication itself.
ZeroPayloadLen,
}

impl core::fmt::Display for HeaderError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use HeaderError::*;
match self {
ZeroPayloadLen => write!(f, "IP Authentification Header Error: Payload Length too small (0). The payload length must be at least 1."),
ZeroPayloadLen => write!(f, "IP Authentication Header Error: Payload Length too small (0). The payload length must be at least 1."),
}
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ mod tests {
#[test]
fn fmt() {
assert_eq!(
"IP Authentification Header Error: Payload Length too small (0). The payload length must be at least 1.",
"IP Authentication Header Error: Payload Length too small (0). The payload length must be at least 1.",
format!("{}", ZeroPayloadLen)
);
}
Expand Down
8 changes: 4 additions & 4 deletions etherparse/src/err/ip_auth/header_limited_read_error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::HeaderError;
use crate::err::LenError;

/// Error when decoding an IP authentification header via a `std::io::Read` source.
/// Error when decoding an IP authentication header via a `std::io::Read` source.
#[cfg(feature = "std")]
#[derive(Debug)]
pub enum HeaderLimitedReadError {
/// IO error was encoutered while reading header.
/// IO error was encountered while reading header.
Io(std::io::Error),

/// Error when parsing had to be aborted because a
Expand Down Expand Up @@ -58,7 +58,7 @@ impl core::fmt::Display for HeaderLimitedReadError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use HeaderLimitedReadError::*;
match self {
Io(err) => write!(f, "IP Authentification Header IO Error: {}", err),
Io(err) => write!(f, "IP Authentication Header IO Error: {}", err),
Len(err) => err.fmt(f),
Content(err) => err.fmt(f),
}
Expand Down Expand Up @@ -101,7 +101,7 @@ mod test {
"failed to fill whole buffer",
);
assert_eq!(
format!("IP Authentification Header IO Error: {}", err),
format!("IP Authentication Header IO Error: {}", err),
format!("{}", Io(err))
);
}
Expand Down
8 changes: 4 additions & 4 deletions etherparse/src/err/ip_auth/header_read_error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::HeaderError;

/// Error when decoding an IP authentification header via a `std::io::Read` source.
/// Error when decoding an IP authentication header via a `std::io::Read` source.
#[cfg(feature = "std")]
#[derive(Debug)]
pub enum HeaderReadError {
/// IO error was encoutered while reading header.
/// IO error was encountered while reading header.
Io(std::io::Error),

/// Error caused by the contents of the header.
Expand Down Expand Up @@ -41,7 +41,7 @@ impl core::fmt::Display for HeaderReadError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use HeaderReadError::*;
match self {
Io(err) => write!(f, "IP Authentification Header IO Error: {}", err),
Io(err) => write!(f, "IP Authentication Header IO Error: {}", err),
Content(value) => value.fmt(f),
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ mod test {
"failed to fill whole buffer",
);
assert_eq!(
format!("IP Authentification Header IO Error: {}", err),
format!("IP Authentication Header IO Error: {}", err),
format!("{}", Io(err))
);
}
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/err/ip_auth/header_slice_error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::HeaderError;
use crate::err::LenError;

/// Error when decoding an IP authentification header from a slice.
/// Error when decoding an IP authentication header from a slice.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum HeaderSliceError {
/// Error when an length error is encountered (e.g. unexpected
Expand Down
14 changes: 7 additions & 7 deletions etherparse/src/err/ip_auth/icv_len_error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Error when creating an [`crate::IpAuthHeader`] and the
/// length of the raw ICV is non representable in an IP authentification
/// length of the raw ICV is non representable in an IP authentication
/// header.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum IcvLenError {
Expand All @@ -8,8 +8,8 @@ pub enum IcvLenError {
TooBig(usize),

/// Error when the ICV length can not be represented
/// as a multiple of 4-bytes in the authentification header
/// (`0 == raw_icv.len() % 4` is not fullfilled).
/// as a multiple of 4-bytes in the authentication header
/// (`0 == raw_icv.len() % 4` is not fulfilled).
Unaligned(usize),
}

Expand All @@ -18,9 +18,9 @@ impl core::fmt::Display for IcvLenError {
use IcvLenError::*;
match self {
TooBig(size) =>
write!(f, "Error the IP authentification header ICV length is too large. The ICV size ({} bytes) is larger then what can be be represented by the 'payload len' field in an IP authentification header.", size),
write!(f, "Error the IP authentication header ICV length is too large. The ICV size ({} bytes) is larger then what can be be represented by the 'payload len' field in an IP authentication header.", size),
Unaligned(size) =>
write!(f, "Error the IP authentification header ICV length of {} bytes is not a multiple of 4. This is required as the payload length field can only express lengths in multiple of 4 bytes.", size),
write!(f, "Error the IP authentication header ICV length of {} bytes is not a multiple of 4. This is required as the payload length field can only express lengths in multiple of 4 bytes.", size),
}
}
}
Expand Down Expand Up @@ -68,11 +68,11 @@ mod tests {
#[test]
fn fmt() {
assert_eq!(
"Error the IP authentification header ICV length is too large. The ICV size (4000 bytes) is larger then what can be be represented by the 'payload len' field in an IP authentification header.",
"Error the IP authentication header ICV length is too large. The ICV size (4000 bytes) is larger then what can be be represented by the 'payload len' field in an IP authentication header.",
format!("{}", TooBig(4000))
);
assert_eq!(
"Error the IP authentification header ICV length of 12 bytes is not a multiple of 4. This is required as the payload length field can only express lengths in multiple of 4 bytes.",
"Error the IP authentication header ICV length of 12 bytes is not a multiple of 4. This is required as the payload length field can only express lengths in multiple of 4 bytes.",
format!("{}", Unaligned(12))
);
}
Expand Down
Loading
Loading