-
Notifications
You must be signed in to change notification settings - Fork 66
IGMPv1 header support #142
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e0522c2
Add IGMPv1 header with reserved-byte preservation, layer integration,…
4e70a57
Add RFC1112 to README as reference
JulianSchmid 098f36a
Add RFC 1112 to crate doc index
JulianSchmid ae32a8b
Reworked IGMP header to support multiple IGMP versions
JulianSchmid 507c3cc
Resolved review comments
JulianSchmid 2450868
Resolved cargo doc warnings
JulianSchmid 09d91cf
Replaced RFC 3376 refernces with RFC 9776
JulianSchmid b863d90
Adapt the implementation to rfc 9776
JulianSchmid 3a4f6d6
IGMP: Introduced "unknown" type and removed error
JulianSchmid 84d144d
Applied fmt
JulianSchmid 5eb371a
Ressolved cargo doc warning
JulianSchmid c5e93d6
Fix type in UnknownHeader diagram
JulianSchmid 5b0bd63
Add report group record types
JulianSchmid bbbee48
IGMP: Flagged type smaller then 64bits with copy
JulianSchmid 3d2dee2
Fix docstring warnings
JulianSchmid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /// A group address in an IGMP packet. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| pub struct GroupAddress { | ||
| pub octets: [u8; 4], | ||
| } | ||
|
|
||
| impl GroupAddress { | ||
| pub fn new(address: [u8; 4]) -> Self { | ||
| Self { octets: address } | ||
| } | ||
|
|
||
| pub fn is_zero(&self) -> bool { | ||
| [0, 0, 0, 0] == self.octets | ||
| } | ||
| } | ||
|
|
||
| impl From<GroupAddress> for [u8; 4] { | ||
| fn from(value: GroupAddress) -> Self { | ||
| value.octets | ||
| } | ||
| } | ||
|
|
||
| impl From<[u8; 4]> for GroupAddress { | ||
| fn from(value: [u8; 4]) -> Self { | ||
| GroupAddress { octets: value } | ||
| } | ||
| } | ||
|
|
||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
| #[cfg(feature = "std")] | ||
| impl From<std::net::Ipv4Addr> for GroupAddress { | ||
| fn from(value: std::net::Ipv4Addr) -> Self { | ||
| GroupAddress { | ||
| octets: value.octets(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||
| #[cfg(feature = "std")] | ||
| impl From<GroupAddress> for std::net::Ipv4Addr { | ||
| fn from(value: GroupAddress) -> Self { | ||
| std::net::Ipv4Addr::new( | ||
| value.octets[0], | ||
| value.octets[1], | ||
| value.octets[2], | ||
| value.octets[3], | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod test { | ||
| use super::*; | ||
| use alloc::format; | ||
| use proptest::prelude::*; | ||
|
|
||
| #[test] | ||
| fn test_is_zero() { | ||
| assert!(GroupAddress::new([0, 0, 0, 0]).is_zero()); | ||
| assert!(!GroupAddress::new([1, 0, 0, 0]).is_zero()); | ||
| assert!(!GroupAddress::new([0, 1, 0, 0]).is_zero()); | ||
| assert!(!GroupAddress::new([0, 0, 1, 0]).is_zero()); | ||
| assert!(!GroupAddress::new([0, 0, 0, 1]).is_zero()); | ||
| } | ||
|
|
||
| proptest! { | ||
| #[test] | ||
| fn from_array_to_group_address_roundtrip(octets in any::<[u8;4]>()) { | ||
| let addr = GroupAddress::from(octets); | ||
| prop_assert_eq!(addr.octets, octets); | ||
|
|
||
| let back: [u8;4] = addr.into(); | ||
| prop_assert_eq!(back, octets); | ||
| } | ||
| } | ||
|
|
||
| proptest! { | ||
| #[test] | ||
| fn from_group_address_to_array_roundtrip(octets in any::<[u8;4]>()) { | ||
| let addr = GroupAddress { octets }; | ||
| let arr: [u8;4] = addr.into(); | ||
| prop_assert_eq!(arr, octets); | ||
|
|
||
| let back = GroupAddress::from(arr); | ||
| prop_assert_eq!(back, addr); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| proptest! { | ||
| #[test] | ||
| fn from_ipv4addr_to_group_address_roundtrip(octets in any::<[u8;4]>()) { | ||
| let ip = std::net::Ipv4Addr::from(octets); | ||
| let addr = GroupAddress::from(ip); | ||
| prop_assert_eq!(addr.octets, octets); | ||
|
|
||
| let back: std::net::Ipv4Addr = addr.into(); | ||
| prop_assert_eq!(back.octets(), octets); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| use crate::igmp::GroupAddress; | ||
|
|
||
| /// A leave group message type (introduced in IGMPv2). | ||
| /// | ||
| /// ```text | ||
| /// 0 1 2 3 | ||
| /// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
| /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| /// | Type = 0x11 | 0 | Checksum | | ||
| /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| /// | Group Address | | ||
| /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| /// ``` | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| pub struct LeaveGroupType { | ||
| /// The IP multicast group address of the group being left. | ||
| pub group_address: GroupAddress, | ||
| } | ||
|
|
||
| impl LeaveGroupType { | ||
| /// Number of bytes/octets an [`LeaveGroupType`] takes up in serialized form. | ||
| pub const LEN: usize = 8; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /// Max response code (specifies the maximum time allowed before | ||
| /// sending a responding report in IGMPv3). | ||
| /// | ||
| /// The actual time allowed, called the Max | ||
| /// Resp Time, is represented in units of 1/10 second and is derived from | ||
| /// the Max Resp Code as follows: | ||
| /// | ||
| /// If Max Resp Code < 128, Max Resp Time = Max Resp Code | ||
| /// | ||
| /// If Max Resp Code >= 128, Max Resp Code represents a floating-point | ||
| /// value as follows: | ||
| /// | ||
| /// ```text | ||
| /// 0 1 2 3 4 5 6 7 | ||
| /// +-+-+-+-+-+-+-+-+ | ||
| /// |1| exp | mant | | ||
| /// +-+-+-+-+-+-+-+-+ | ||
| /// ``` | ||
| /// | ||
| /// Max Resp Time = (mant | 0x10) << (exp + 3) | ||
| /// | ||
| /// Small values of Max Resp Time allow IGMPv3 routers to tune the "leave | ||
| /// latency" (the time between the moment the last host leaves a group | ||
| /// and the moment the routing protocol is notified that there are no | ||
| /// more members). Larger values, especially in the exponential range, | ||
| /// allow tuning of the burstiness of IGMP traffic on a network. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| pub struct MaxResponseCode(pub u8); | ||
|
|
||
| impl MaxResponseCode { | ||
| /// Returns the max response time in 10th seconds (converts raw value). | ||
| pub fn as_10th_secs(&self) -> u16 { | ||
| if 0 != self.0 & 0b1000_0000 { | ||
| u16::from((self.0 & 0b0000_1111) | 0x10) << u16::from(((self.0 & 0b0111_0000) >> 4) + 3) | ||
| } else { | ||
| u16::from(self.0) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use proptest::prelude::*; | ||
| use std::format; | ||
|
|
||
| proptest! { | ||
| #[test] | ||
| fn as_10th_secs_linear_range(raw in 0u8..=0b0111_1111u8) { | ||
| prop_assert_eq!(MaxResponseCode(raw).as_10th_secs(), u16::from(raw)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn as_10th_secs_exponential_range(mant in 0u8..=0b1111, exp in 0u8..=0b111u8) { | ||
| let raw = 0b1000_0000 | (exp << 4) | mant; | ||
| let expected = u16::from(mant | 0x10) << u16::from(exp + 3); | ||
| prop_assert_eq!(MaxResponseCode(raw).as_10th_secs(), expected); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| use crate::igmp::GroupAddress; | ||
|
|
||
| /// IGMPv1/IGMPv2 Membership Query message type. | ||
| /// | ||
| /// IGMPv1 & IGMPv2 can be distinguished via the `max_response_time` field: | ||
| /// | ||
| /// * For IGMPv1 the `max_response_time` field is set to zero | ||
| /// * For IGMPv2 the `max_response_time` field is set to NOT zero | ||
| /// | ||
| /// ```text | ||
| /// 0 1 2 3 | ||
| /// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
| /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| /// | Type = 0x11 | Max Resp Time | Checksum | | ||
| /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| /// | Group Address | | ||
| /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| /// ``` | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| pub struct MembershipQueryType { | ||
| /// The maximum response time for the membership report | ||
| /// (only for IGMPv2, set to 0 for IGMPv1). | ||
| /// | ||
| /// Specifies the maximum allowed time before sending a | ||
| /// responding report in units of 1/10 second. | ||
| /// | ||
| /// For IGMPv1, this field is always set to zero. | ||
| pub max_response_time: u8, | ||
|
|
||
| /// The group address being queried. | ||
| /// | ||
| /// Set to zero for general queries, to learn which groups | ||
| /// have members on an attached network. Filled for group-specific | ||
| /// queries to learn if a particular group has members on an | ||
| /// attached network. | ||
| /// | ||
| /// For IGMPv1, this field is always set to zero. | ||
| pub group_address: GroupAddress, | ||
| } | ||
|
|
||
| impl MembershipQueryType { | ||
| /// Number of bytes/octets an [`MembershipQueryType`] takes up in serialized form. | ||
| pub const LEN: usize = 8; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.