Skip to content

sys::socket adding Linux packet filtering on ipv4/ipv6/loopback traffics #2581

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 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changelog/2581.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ```sys::socket::SockProtocol::EthIp```, ```sys::socket::SockProtocol::EthIpv6```, ```sys::socket::SockProtocol::EthLoop```
18 changes: 18 additions & 0 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ pub enum SockProtocol {
// The protocol number is fed into the socket syscall in network byte order.
#[cfg(linux_android)]
EthAll = (libc::ETH_P_ALL as u16).to_be() as i32,
#[cfg(linux_android)]
/// Packet filter on loopback traffic
EthLoop = (libc::ETH_P_LOOP as u16).to_be() as i32,
/// Packet filter on IPv4 traffic
#[cfg(linux_android)]
#[cfg(target_endian = "big")]
EthIp = libc::ETH_P_IP,
/// Packet filter on IPv6 traffic
#[cfg(linux_android)]
EthIpv6 = (libc::ETH_P_IPV6 as u16).to_be() as i32,
/// ICMP protocol ([icmp(7)](https://man7.org/linux/man-pages/man7/icmp.7.html))
Icmp = libc::IPPROTO_ICMP,
/// ICMPv6 protocol (ICMP over IPv6)
Expand Down Expand Up @@ -241,6 +251,14 @@ impl SockProtocol {
#[cfg(apple_targets)]
#[allow(non_upper_case_globals)]
pub const KextEvent: SockProtocol = SockProtocol::Icmp; // Matches libc::SYSPROTO_EVENT

/// Packet filter on IPv4 traffic
// NOTE: placed here due to conflict (little endian arch) with SockProtocol::NetLinkISCI
#[cfg(linux_android)]
#[allow(non_upper_case_globals)]
#[cfg(target_endian = "little")]
pub const EthIp: SockProtocol = unsafe { std::mem::transmute::<i32, SockProtocol>((libc::ETH_P_IP as u16).to_be() as i32) };

}
#[cfg(linux_android)]
libc_bitflags! {
Expand Down
Loading