Skip to content

Commit 0615efd

Browse files
committed
sys::socket adding Linux packet filtering on ipv4/ipv6/loopback traffics
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 33efb1a commit 0615efd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ 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+
#[allow(non_upper_case_globals)]
218+
#[cfg(target_endian = "big")]
219+
EthIp = libc::ETH_P_IP as i32,
220+
/// Packet filter on IPv6 traffic
221+
#[cfg(linux_android)]
222+
EthIpv6 = (libc::ETH_P_IPV6 as u16).to_be() as i32,
212223
/// ICMP protocol ([icmp(7)](https://man7.org/linux/man-pages/man7/icmp.7.html))
213224
Icmp = libc::IPPROTO_ICMP,
214225
/// ICMPv6 protocol (ICMP over IPv6)
@@ -241,6 +252,14 @@ impl SockProtocol {
241252
#[cfg(apple_targets)]
242253
#[allow(non_upper_case_globals)]
243254
pub const KextEvent: SockProtocol = SockProtocol::Icmp; // Matches libc::SYSPROTO_EVENT
255+
256+
/// Packet filter on IPv4 traffic
257+
// NOTE: placed here due to conflict (little endian arch) with SockProtocol::NetLinkISCI
258+
#[cfg(linux_android)]
259+
#[allow(non_upper_case_globals)]
260+
#[cfg(target_endian = "little")]
261+
pub const EthIp: SockProtocol = unsafe { std::mem::transmute::<i32, SockProtocol>((libc::ETH_P_IP as u16).to_be() as i32) };
262+
244263
}
245264
#[cfg(linux_android)]
246265
libc_bitflags! {

0 commit comments

Comments
 (0)