Skip to content

Commit

Permalink
sys::socket adding Linux packet filtering on ipv4/ipv6/loopback traffics
Browse files Browse the repository at this point in the history
Respectively `sys::socket::SockProtocol::EthIp`,
`sys::socket::SockProtocol::EthIpv6` and
`sys::socket::SockProtocol::EthLoop` if we want more refined
filtering as opposed to the existing `sys::socket::SockProtocol::EthAll`
which captures everything.
  • Loading branch information
devnexen committed Jan 12, 2025
1 parent 33efb1a commit 0615efd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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```
19 changes: 19 additions & 0 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ 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)]
#[allow(non_upper_case_globals)]
#[cfg(target_endian = "big")]
EthIp = libc::ETH_P_IP as i32,
/// 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 +252,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

0 comments on commit 0615efd

Please sign in to comment.