Skip to content

Commit 55f537d

Browse files
committed
adding ethhdr type for linux/android for proper packet filtering.
1 parent 4abcd81 commit 55f537d

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

libc-test/semver/android.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,7 @@ epoll_create1
32303230
epoll_ctl
32313231
epoll_event
32323232
epoll_wait
3233+
ethhdr
32333234
eventfd
32343235
eventfd_read
32353236
eventfd_write

libc-test/semver/linux.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,7 @@ epoll_params
37223722
epoll_pwait
37233723
epoll_wait
37243724
erand48
3725+
ethhdr
37253726
eventfd
37263727
eventfd_read
37273728
eventfd_write

src/unix/linux_like/android/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub type __u16 = c_ushort;
3434
pub type __s16 = c_short;
3535
pub type __u32 = c_uint;
3636
pub type __s32 = c_int;
37+
pub type __be16 = __u16;
3738

3839
// linux/elf.h
3940

@@ -638,6 +639,13 @@ s_no_extra_traits! {
638639
pub ifc_len: c_int,
639640
pub ifc_ifcu: __c_anonymous_ifc_ifcu,
640641
}
642+
643+
#[repr(C)]
644+
pub struct ethhdr {
645+
pub h_dest: [c_uchar; crate::ETH_ALEN as usize],
646+
pub h_source: [c_uchar; crate::ETH_ALEN as usize],
647+
pub h_proto: crate::__be16,
648+
}
641649
}
642650

643651
cfg_if! {
@@ -1020,6 +1028,33 @@ cfg_if! {
10201028
.finish()
10211029
}
10221030
}
1031+
1032+
impl Eq for ethhdr {}
1033+
1034+
impl PartialEq for ethhdr {
1035+
fn eq(&self, other: &ethhdr) -> bool {
1036+
self.h_dest
1037+
.iter()
1038+
.zip(other.h_dest.iter())
1039+
.all(|(a, b)| a == b)
1040+
&& self
1041+
.h_source
1042+
.iter()
1043+
.zip(other.h_source.iter())
1044+
.all(|(a, b)| a == b)
1045+
&& self.h_proto == other.h_proto
1046+
}
1047+
}
1048+
1049+
impl fmt::Debug for ethhdr {
1050+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1051+
f.debug_struct("ethhdr")
1052+
.field("h_dest", &self.h_dest)
1053+
.field("h_source", &self.h_source)
1054+
.field("h_proto", &{ self.h_proto })
1055+
.finish()
1056+
}
1057+
}
10231058
}
10241059
}
10251060

src/unix/linux_like/linux/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub type __u16 = c_ushort;
2828
pub type __s16 = c_short;
2929
pub type __u32 = c_uint;
3030
pub type __s32 = c_int;
31+
pub type __be16 = __u16;
3132

3233
pub type Elf32_Half = u16;
3334
pub type Elf32_Word = u32;
@@ -1784,6 +1785,13 @@ s_no_extra_traits! {
17841785
pub request: xsk_tx_metadata_request,
17851786
pub completion: xsk_tx_metadata_completion,
17861787
}
1788+
1789+
#[repr(C)]
1790+
pub struct ethhdr {
1791+
pub h_dest: [c_uchar; crate::ETH_ALEN as usize],
1792+
pub h_source: [c_uchar; crate::ETH_ALEN as usize],
1793+
pub h_proto: crate::__be16,
1794+
}
17871795
}
17881796

17891797
cfg_if! {
@@ -2211,6 +2219,33 @@ cfg_if! {
22112219
.finish()
22122220
}
22132221
}
2222+
2223+
impl Eq for ethhdr {}
2224+
2225+
impl PartialEq for ethhdr {
2226+
fn eq(&self, other: &ethhdr) -> bool {
2227+
self.h_dest
2228+
.iter()
2229+
.zip(other.h_dest.iter())
2230+
.all(|(a, b)| a == b)
2231+
&& self
2232+
.h_source
2233+
.iter()
2234+
.zip(other.h_source.iter())
2235+
.all(|(a, b)| a == b)
2236+
&& self.h_proto == other.h_proto
2237+
}
2238+
}
2239+
2240+
impl fmt::Debug for ethhdr {
2241+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2242+
f.debug_struct("ethhdr")
2243+
.field("h_dest", &self.h_dest)
2244+
.field("h_source", &self.h_source)
2245+
.field("h_proto", &{ self.h_proto })
2246+
.finish()
2247+
}
2248+
}
22142249
}
22152250
}
22162251

0 commit comments

Comments
 (0)