Skip to content

Commit 34bb802

Browse files
authored
sys::socket adding Linux packet filtering on ipv4/ipv6/loopback traffics (#2581)
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.
1 parent 020e6b4 commit 34bb802

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

changelog/2581.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ```sys::socket::SockProtocol::EthIp```, ```sys::socket::SockProtocol::EthIpv6```, ```sys::socket::SockProtocol::EthLoop```

src/sys/socket/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ pub enum SockProtocol {
209209
// The protocol number is fed into the socket syscall in network byte order.
210210
#[cfg(linux_android)]
211211
EthAll = (libc::ETH_P_ALL as u16).to_be() as i32,
212+
#[cfg(linux_android)]
213+
/// Packet filter on loopback traffic
214+
EthLoop = (libc::ETH_P_LOOP as u16).to_be() as i32,
215+
/// Packet filter on IPv4 traffic
216+
#[cfg(linux_android)]
217+
#[cfg(target_endian = "big")]
218+
EthIp = libc::ETH_P_IP,
219+
/// Packet filter on IPv6 traffic
220+
#[cfg(linux_android)]
221+
EthIpv6 = (libc::ETH_P_IPV6 as u16).to_be() as i32,
212222
/// ICMP protocol ([icmp(7)](https://man7.org/linux/man-pages/man7/icmp.7.html))
213223
Icmp = libc::IPPROTO_ICMP,
214224
/// ICMPv6 protocol (ICMP over IPv6)
@@ -241,6 +251,14 @@ impl SockProtocol {
241251
#[cfg(apple_targets)]
242252
#[allow(non_upper_case_globals)]
243253
pub const KextEvent: SockProtocol = SockProtocol::Icmp; // Matches libc::SYSPROTO_EVENT
254+
255+
/// Packet filter on IPv4 traffic
256+
// NOTE: placed here due to conflict (little endian arch) with SockProtocol::NetLinkISCI
257+
#[cfg(linux_android)]
258+
#[allow(non_upper_case_globals)]
259+
#[cfg(target_endian = "little")]
260+
pub const EthIp: SockProtocol = unsafe { std::mem::transmute::<i32, SockProtocol>((libc::ETH_P_IP as u16).to_be() as i32) };
261+
244262
}
245263
#[cfg(linux_android)]
246264
libc_bitflags! {

0 commit comments

Comments
 (0)