Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,7 @@ fn test_freebsd(target: &str) {
"memstat.h",
"mqueue.h",
"net/bpf.h",
"net/ethernet.h",
"net/if.h",
"net/if_arp.h",
"net/if_dl.h",
Expand Down
13 changes: 13 additions & 0 deletions libc-test/semver/freebsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ ERA_T_FMT
EREMOTE
ERPCMISMATCH
ESOCKTNOSUPPORT
ETHER_ADDR_LEN
ETHER_CRC_LEN
ETHER_HDR_LEN
ETHER_IS_BROADCAST
ETHER_IS_IPV6_MULTICAST
ETHER_IS_MULTICAST
ETHER_IS_ZERO
ETHER_MIN_LEN
ETHER_MAX_LEN
ETHER_MAX_LEN_JUMBO
ETHER_TYPE_LEN
ETOOMANYREFS
EUSERS
EVFILT_AIO
Expand Down Expand Up @@ -1917,6 +1928,8 @@ endpwent
endservent
endutxent
erand48
ether_addr
ether_header
eui64_aton
eui64_hostton
eui64_ntoa
Expand Down
121 changes: 121 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,18 @@ s_no_extra_traits! {
pub rcv: crate::xktls_session_onedir,
pub snd: crate::xktls_session_onedir,
}

#[repr(packed)]
pub struct ether_header {
pub ether_dhost: [crate::u_char; ETHER_ADDR_LEN as usize],
pub ether_shost: [crate::u_char; ETHER_ADDR_LEN as usize],
pub ether_type: crate::u_short,
}

#[repr(packed)]
pub struct ether_addr {
pub octet: [crate::u_char; ETHER_ADDR_LEN as usize],
}
}

cfg_if! {
Expand Down Expand Up @@ -2332,6 +2344,77 @@ cfg_if! {
self.kf_path.hash(state);
}
}

impl fmt::Debug for ucontext_t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ucontext_t")
.field("uc_sigmask", &self.uc_sigmask)
.field("uc_mcontext", &self.uc_mcontext)
.field("uc_link", &self.uc_link)
.field("uc_stack", &self.uc_stack)
.field("uc_flags", &self.uc_flags)
.finish()
}
}

// FIXME(msrv): `derive` on packed structs cannot be used below 1.67
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds to me like a compelling reason to raise the main branch's MSRV. Why is it currently set to 1.63?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.63 is what Debian stable currently ships so it is a pretty common baseline in the ecosystem. In a few months Trixie will be released 1.83 (or higher) so we will probably be able to do another bump (not that high, but at least above 1.63).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stumbled across this again because considering a MSRV bump: what exactly happened at 1.67? Derive on packed structs seems to work all the way down to 1.0 https://rust.godbolt.org/z/qqPsT46zr.

Derive on packed structs without Copy is a newer feature as of 1.69, but everything we have is Copy anyway


impl PartialEq for ether_header {
fn eq(&self, other: &ether_header) -> bool {
self.ether_dhost
.iter()
.zip(other.ether_dhost.iter())
.all(|(a, b)| a == b)
&& self
.ether_dhost
.iter()
.zip(other.ether_shost.iter())
.all(|(a, b)| a == b)
&& self.ether_type == other.ether_type
}
}

impl Eq for ether_header {}
impl fmt::Debug for ether_header {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ether_header")
.field("ether_dhost", &{ self.ether_dhost })
.field("ether_shost", &{ self.ether_shost })
.field("ether_type", &{ self.ether_type })
.finish()
}
}

impl hash::Hash for ether_header {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
{ self.ether_dhost }.hash(state);
{ self.ether_shost }.hash(state);
{ self.ether_type }.hash(state);
}
}

impl PartialEq for ether_addr {
fn eq(&self, other: &ether_addr) -> bool {
self.octet
.iter()
.zip(other.octet.iter())
.all(|(a, b)| a == b)
}
}

impl Eq for ether_addr {}
impl fmt::Debug for ether_addr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ether_addr")
.field("octet", &{ self.octet })
.finish()
}
}
impl hash::Hash for ether_addr {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
{ self.octet }.hash(state);
}
}
}
}

Expand Down Expand Up @@ -4431,6 +4514,16 @@ pub const RTM_VERSION: c_int = 5;

pub const RTAX_MAX: c_int = 8;

// net/ethernet.h

pub const ETHER_ADDR_LEN: c_int = 6;
pub const ETHER_TYPE_LEN: c_int = 2;
pub const ETHER_CRC_LEN: c_int = 4;
pub const ETHER_HDR_LEN: c_int = ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN;
pub const ETHER_MIN_LEN: c_int = 64;
pub const ETHER_MAX_LEN: c_int = 1518;
pub const ETHER_MAX_LEN_JUMBO: c_int = 9018;

// sys/signal.h
pub const SIGTHR: c_int = 32;
pub const SIGLWP: c_int = SIGTHR;
Expand Down Expand Up @@ -4742,6 +4835,34 @@ f! {
pub fn PROT_MAX_EXTRACT(x: c_int) -> c_int {
(x >> 16) & (crate::PROT_READ | crate::PROT_WRITE | crate::PROT_EXEC)
}

pub {const} fn ETHER_IS_MULTICAST(addr: *mut u_char) -> bool {
(*addr.add(0)) & 0x01 != 0x00
}

pub {const} fn ETHER_IS_IPV6_MULTICAST(addr: *mut u_char) -> bool {
(*addr.add(0)) == 0x33 && (*addr.add(1)) == 0x33
}

pub {const} fn ETHER_IS_BROADCAST(addr: *mut u_char) -> bool {
(*addr.add(0))
& (*addr.add(1))
& (*addr.add(2))
& (*addr.add(3))
& (*addr.add(4))
& (*addr.add(5))
== 0xff
}

pub {const} fn ETHER_IS_ZERO(addr: *mut u_char) -> bool {
(*addr.add(0))
| (*addr.add(1))
| (*addr.add(2))
| (*addr.add(3))
| (*addr.add(4))
| (*addr.add(5))
== 0x00
}
}

safe_f! {
Expand Down
Loading