Skip to content

Commit 56e3d51

Browse files
authored
Merge pull request #1301 from GyulyVGC/igmp
Add support for IGMP
2 parents fd56567 + c537aea commit 56e3d51

21 files changed

Lines changed: 186 additions & 91 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All Sniffnet releases with the relative changes are documented in this file.
44

55
## [UNRELEASED]
66
- IPFIX collector capabilities: receive and analyze network traffic from remote devices ([#1270](https://github.com/GyulyVGC/sniffnet/pull/1270) — fixes [#303](https://github.com/GyulyVGC/sniffnet/issues/303))
7+
- Added support for IGMP connections and messages ([#1301](https://github.com/GyulyVGC/sniffnet/pull/1301) — fixes [#1269](https://github.com/GyulyVGC/sniffnet/issues/1269))
78
- Show output file path in Overview page when exporting a PCAP file ([`3f2c42c`](https://github.com/GyulyVGC/sniffnet/pull/1290/commits/3f2c42c70f06d5d29ddad80dde956281c6705511))
89
- Fix the app freezing and exhausting memory when importing a PCAP file containing a large time gap between consecutive packets ([`4605ec7`](https://github.com/GyulyVGC/sniffnet/pull/1290/commits/4605ec717bbaf8fa34268805814d5585f084201e))
910
- Restrict the PCAP export file to have a valid PCAP extension, so that files of other types can't be overwritten ([`5b4801b`](https://github.com/GyulyVGC/sniffnet/pull/1290/commits/5b4801b438ff1c7968cfac423a8e8585778309a8))

CONTRIBUTING.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ For this reason, you're encouraged to read the following points before submittin
88
4. reuse existing code and libraries where possible, and keep your PR small and focused, prioritizing quality over quantity
99
5. if you end up adding a UI-facing sentence, make sure to internationalize it by adding a method to the `src/translations` module with the corresponding English translation (only add other languages if you natively speak them)
1010
6. if you end up modifying the `Sniffer` struct, include the new field in the `Conf` struct if it has to be persisted across runs of the app, or else consider cleaning it up in `Sniffer::reset()` if it has to be reset at every capture session
11-
7. include unit tests to assert the implementation is sound (if applicable), and make sure that `cargo test`, `cargo clippy -- -D warnings`, and `cargo fmt --all -- --check` all pass
12-
8. be sure to update the `CHANGELOG.md` file `[UNRELEASED]` section with a one-line description of the change, including a link to the corresponding PR and issue if applicable (following the format of the existing entries)
13-
9. be mindful that reviewing the PR may take a while, especially if it introduces substantial changes
14-
10. be mindful that the contribution can still be rejected at our discretion (even if it satisfies all the points above) if it doesn't align with the project's vision or if it introduces unnecessary complexity
11+
7. if you end up modifying or creating a library in the `lib` folder, make sure to bump its version, update its own `CHANGELOG.md`, and update `Cargo.toml`'s dependencies and workspace members accordingly
12+
8. include unit tests to assert the implementation is sound (if applicable), and make sure that `cargo test`, `cargo clippy -- -D warnings`, and `cargo fmt --all -- --check` all pass
13+
9. be sure to update the `CHANGELOG.md` file `[UNRELEASED]` section with a one-line description of the change, including a link to the corresponding PR and issue if applicable (following the format of the existing entries)
14+
10. be mindful that reviewing the PR may take a while, especially if it introduces substantial changes
15+
11. be mindful that the contribution can still be rejected at our discretion (even if it satisfies all the points above) if it doesn't align with the project's vision or if it introduces unnecessary complexity
1516

1617
You can read the [_Build from source_](https://github.com/GyulyVGC/sniffnet/wiki/Build-from-source) Wiki page to learn how to set up the development environment, and the [_Code of Conduct_](https://github.com/GyulyVGC/sniffnet/blob/main/CODE_OF_CONDUCT.md) for the expected behavior in the community.
1718

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ workspace = true
4444

4545
[dependencies]
4646

47-
sniffnet-packet-parser = { path = "lib/sniffnet-packet-parser", version = "0.1.0" }
47+
sniffnet-packet-parser = { path = "lib/sniffnet-packet-parser", version = "0.2.0" }
4848

4949
pcap.workspace = true
5050

@@ -90,7 +90,7 @@ serial_test = { version = "4.0.1", default-features = false }
9090

9191
[build-dependencies]
9292

93-
sniffnet-packet-parser = { path = "lib/sniffnet-packet-parser", version = "0.1.0", default-features = false }
93+
sniffnet-packet-parser = { path = "lib/sniffnet-packet-parser", version = "0.2.0", default-features = false }
9494

9595
phf_codegen = "0.14.0"
9696
phf_shared = "0.14.0"

lib/sniffnet-packet-parser/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
All `sniffnet-packet-parser` releases with the relative changes are documented in this file.
44

5+
## [UNRELEASED]
6+
### Added
7+
- IGMP support ([#1301](https://github.com/GyulyVGC/sniffnet/pull/1301))
8+
59
## [0.1.0] - 2026-09-02
610
- Initial release of `sniffnet-packet-parser`, the network packet parser for Sniffnet

lib/sniffnet-packet-parser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sniffnet-packet-parser"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "Network packet parser for Sniffnet"
55
readme = "README.md"
66
keywords = ["network", "packet", "sniffer", "parser", "pcap"]

lib/sniffnet-packet-parser/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Powered by [`etherparse`](https://github.com/JulianSchmid/etherparse).
1010
- `UDP`
1111
- `ICMPv4`
1212
- `ICMPv6`
13+
- `IGMP`
1314
- `ARP`
1415

1516
## Supported link types

lib/sniffnet-packet-parser/src/headers.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::igmp_type::IgmpType;
12
use crate::link_type::LinkType;
23
use crate::{ArpType, IcmpType, Protocol};
34
use etherparse::{EtherType, LaxPacketHeaders};
@@ -36,6 +37,8 @@ pub struct TransportInfo {
3637
pub protocol: Protocol,
3738
/// ICMP message type, if the packet is an ICMP packet.
3839
pub icmp_type: Option<IcmpType>,
40+
/// IGMP message type, if the packet is an IGMP packet.
41+
pub igmp_type: Option<IgmpType>,
3942
}
4043

4144
#[must_use]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use std::fmt::{Display, Formatter};
2+
3+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
4+
/// The IGMP message type.
5+
pub enum IgmpType {
6+
MembershipQuery,
7+
MembershipReportV1,
8+
MembershipReportV2,
9+
MembershipReportV3,
10+
LeaveGroup,
11+
Dvmrp,
12+
Pim,
13+
CiscoTrace,
14+
MulticastTracerouteResponse,
15+
MulticastTraceroute,
16+
MulticastRouterAdvertisement,
17+
MulticastRouterSolicitation,
18+
MulticastRouterTermination,
19+
Unknown,
20+
}
21+
22+
impl IgmpType {
23+
#[must_use]
24+
pub(crate) fn from_etherparse(igmp_type: &etherparse::IgmpType) -> IgmpType {
25+
match igmp_type {
26+
etherparse::IgmpType::MembershipQuery(_)
27+
| etherparse::IgmpType::MembershipQueryWithSources(_) => IgmpType::MembershipQuery,
28+
etherparse::IgmpType::MembershipReportV1(_) => IgmpType::MembershipReportV1,
29+
etherparse::IgmpType::MembershipReportV2(_) => IgmpType::MembershipReportV2,
30+
etherparse::IgmpType::MembershipReportV3(_) => IgmpType::MembershipReportV3,
31+
etherparse::IgmpType::LeaveGroup(_) => IgmpType::LeaveGroup,
32+
etherparse::IgmpType::Unknown(h) => match h.igmp_type {
33+
0x13 => IgmpType::Dvmrp,
34+
0x14 => IgmpType::Pim,
35+
0x15 => IgmpType::CiscoTrace,
36+
0x1e => IgmpType::MulticastTracerouteResponse,
37+
0x1f => IgmpType::MulticastTraceroute,
38+
0x30 => IgmpType::MulticastRouterAdvertisement,
39+
0x31 => IgmpType::MulticastRouterSolicitation,
40+
0x32 => IgmpType::MulticastRouterTermination,
41+
_ => IgmpType::Unknown,
42+
},
43+
}
44+
}
45+
}
46+
47+
impl Display for IgmpType {
48+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49+
write!(
50+
f,
51+
"{}",
52+
match self {
53+
IgmpType::MembershipQuery => "Membership Query",
54+
IgmpType::MembershipReportV1 => "Membership Report v1",
55+
IgmpType::MembershipReportV2 => "Membership Report v2",
56+
IgmpType::MembershipReportV3 => "Membership Report v3",
57+
IgmpType::LeaveGroup => "Leave Group",
58+
IgmpType::Dvmrp => "DVMRP",
59+
IgmpType::Pim => "PIM v1",
60+
IgmpType::CiscoTrace => "Cisco Trace",
61+
IgmpType::MulticastTracerouteResponse => "Multicast Traceroute Response",
62+
IgmpType::MulticastTraceroute => "Multicast Traceroute",
63+
IgmpType::MulticastRouterAdvertisement => "Multicast Router Advertisement",
64+
IgmpType::MulticastRouterSolicitation => "Multicast Router Solicitation",
65+
IgmpType::MulticastRouterTermination => "Multicast Router Termination",
66+
IgmpType::Unknown => "?",
67+
}
68+
)
69+
}
70+
}

lib/sniffnet-packet-parser/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ mod headers;
77
#[cfg(feature = "full")]
88
mod icmp_type;
99
#[cfg(feature = "full")]
10+
mod igmp_type;
11+
#[cfg(feature = "full")]
1012
mod link_type;
1113
#[cfg(feature = "full")]
1214
mod packet;
@@ -19,6 +21,8 @@ pub use headers::{LinkInfo, NetInfo, TransportInfo};
1921
#[cfg(feature = "full")]
2022
pub use icmp_type::{IcmpType, IcmpTypeV4, IcmpTypeV6};
2123
#[cfg(feature = "full")]
24+
pub use igmp_type::IgmpType;
25+
#[cfg(feature = "full")]
2226
pub use link_type::LinkType;
2327
#[cfg(feature = "full")]
2428
pub use packet::ParsedPacket;

0 commit comments

Comments
 (0)