Skip to content

Commit 63a10d6

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 63a10d6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/sys/socket/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ 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 IPv6 traffic
216+
#[cfg(linux_android)]
217+
EthIpv6 = (libc::ETH_P_IPV6 as u16).to_be() as i32,
212218
/// ICMP protocol ([icmp(7)](https://man7.org/linux/man-pages/man7/icmp.7.html))
213219
Icmp = libc::IPPROTO_ICMP,
214220
/// ICMPv6 protocol (ICMP over IPv6)
@@ -241,6 +247,12 @@ impl SockProtocol {
241247
#[cfg(apple_targets)]
242248
#[allow(non_upper_case_globals)]
243249
pub const KextEvent: SockProtocol = SockProtocol::Icmp; // Matches libc::SYSPROTO_EVENT
250+
251+
/// Packet filter on IPv4 traffic
252+
/// NOTE: placed here due to conflict (little endian arch) with SockProtocol::NetLinkISCI
253+
#[cfg(linux_android)]
254+
#[allow(non_upper_case_globals)]
255+
pub const EthIp: SockProtocol = unsafe { std::mem::transmute::<i32, SockProtocol>((libc::ETH_P_IP as u16).to_be() as i32) };
244256
}
245257
#[cfg(linux_android)]
246258
libc_bitflags! {

0 commit comments

Comments
 (0)