-
Notifications
You must be signed in to change notification settings - Fork 1.1k
adding ethhdr type for linux/android for proper packet filtering. #4239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3230,6 +3230,7 @@ epoll_create1 | |
epoll_ctl | ||
epoll_event | ||
epoll_wait | ||
ethhdr | ||
eventfd | ||
eventfd_read | ||
eventfd_write | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -588,6 +588,7 @@ dlmopen | |
eaccess | ||
endutxent | ||
epoll_pwait2 | ||
ethhdr | ||
euidaccess | ||
execveat | ||
explicit_bzero | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ pub type __u16 = c_ushort; | |
pub type __s16 = c_short; | ||
pub type __u32 = c_uint; | ||
pub type __s32 = c_int; | ||
pub type __be16 = __u16; | ||
|
||
// linux/elf.h | ||
|
||
|
@@ -638,6 +639,15 @@ s_no_extra_traits! { | |
pub ifc_len: c_int, | ||
pub ifc_ifcu: __c_anonymous_ifc_ifcu, | ||
} | ||
|
||
// linux/if_ether.h | ||
|
||
#[repr(C, packed)] | ||
pub struct ethhdr { | ||
pub h_dest: [c_uchar; crate::ETH_ALEN as usize], | ||
pub h_source: [c_uchar; crate::ETH_ALEN as usize], | ||
pub h_proto: crate::__be16, | ||
} | ||
} | ||
|
||
cfg_if! { | ||
|
@@ -1020,6 +1030,33 @@ cfg_if! { | |
.finish() | ||
} | ||
} | ||
|
||
impl Eq for ethhdr {} | ||
|
||
impl PartialEq for ethhdr { | ||
fn eq(&self, other: ðhdr) -> bool { | ||
self.h_dest | ||
.iter() | ||
.zip(other.h_dest.iter()) | ||
.all(|(a, b)| a == b) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you not want them to compare equal if they have the same CStr value, but different null trailing bytes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note that those fields represent mac addresses not as strings (note they re unsigned char). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, my bad, you're correct. |
||
&& self | ||
.h_source | ||
.iter() | ||
.zip(other.h_source.iter()) | ||
.all(|(a, b)| a == b) | ||
&& self.h_proto == other.h_proto | ||
} | ||
} | ||
|
||
impl fmt::Debug for ethhdr { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_struct("ethhdr") | ||
.field("h_dest", &self.h_dest) | ||
.field("h_source", &self.h_source) | ||
.field("h_proto", &{ self.h_proto }) | ||
.finish() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing proto field |
||
} | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
PartialEq
definition appears to lack a check on theh_proto
field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not forget but until I solve the alignment issue in some platforms and as I was playing with the h_proto type I do not bother with it just yet (still a draft).