Skip to content

Commit f64ef18

Browse files
committed
WIP Netlink support for FreeBSD 13.2
NOTE: This is an early subset of the Netlink interface. FIXME: Netlink support starts with 13.2, but for now we activate it for all minor release of v13. Signed-off-by: Yann Dirson <[email protected]>
1 parent 95ce1ff commit f64ef18

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

libc-test/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,7 @@ fn test_freebsd(target: &str) {
19451945
"netinet/sctp.h",
19461946
"netinet/tcp.h",
19471947
"netinet/udp.h",
1948+
[freebsd13]:"netlink/netlink.h",
19481949
"poll.h",
19491950
"pthread.h",
19501951
"pthread_np.h",

src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs

+72
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ s_no_extra_traits! {
277277
pub vn_mode: u16,
278278
pub vn_devname: [::c_char; ::SPECNAMELEN as usize + 1],
279279
}
280+
281+
pub struct sockaddr_nl {
282+
pub nl_len: ::c_uchar,
283+
pub nl_family: ::sa_family_t,
284+
nl_pad: ::c_ushort,
285+
pub nl_pid: u32,
286+
pub nl_groups: u32
287+
}
280288
}
281289

282290
cfg_if! {
@@ -447,6 +455,34 @@ cfg_if! {
447455
self_vn_devname.hash(state);
448456
}
449457
}
458+
459+
impl PartialEq for sockaddr_nl {
460+
fn eq(&self, other: &sockaddr_nl) -> bool {
461+
self.nl_len == other.nl_len &&
462+
self.nl_family == other.nl_family &&
463+
self.nl_pid == other.nl_pid &&
464+
self.nl_groups == other.nl_groups
465+
}
466+
}
467+
impl Eq for sockaddr_nl {}
468+
impl ::fmt::Debug for sockaddr_nl {
469+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
470+
f.debug_struct("sockaddr_nl")
471+
.field("nl_len", &self.nl_len)
472+
.field("nl_family", &self.nl_family)
473+
.field("nl_pid", &self.nl_pid)
474+
.field("nl_groups", &self.nl_groups)
475+
.finish()
476+
}
477+
}
478+
impl ::hash::Hash for sockaddr_nl {
479+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
480+
self.nl_len.hash(state);
481+
self.nl_family.hash(state);
482+
self.nl_pid.hash(state);
483+
self.nl_groups.hash(state);
484+
}
485+
}
450486
}
451487
}
452488

@@ -468,6 +504,42 @@ pub const DOMAINSET_POLICY_INTERLEAVE: ::c_int = 4;
468504

469505
pub const MINCORE_SUPER: ::c_int = 0x20;
470506

507+
/// netlink constants
508+
pub const SOL_NETLINK: ::c_int = 270;
509+
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
510+
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
511+
pub const NETLINK_PKTINFO: ::c_int = 3;
512+
pub const NETLINK_BROADCAST_ERROR: ::c_int = 4;
513+
pub const NETLINK_NO_ENOBUFS: ::c_int = 5;
514+
pub const NETLINK_RX_RING: ::c_int = 6;
515+
pub const NETLINK_TX_RING: ::c_int = 7;
516+
pub const NETLINK_LISTEN_ALL_NSID: ::c_int = 8;
517+
pub const NETLINK_LIST_MEMBERSHIPS: ::c_int = 9;
518+
pub const NETLINK_CAP_ACK: ::c_int = 10;
519+
pub const NETLINK_EXT_ACK: ::c_int = 11;
520+
pub const NETLINK_GET_STRICT_CHK: ::c_int = 12;
521+
522+
pub const AF_NETLINK: ::c_int = 38;
523+
pub const PF_NETLINK: ::c_int = AF_NETLINK;
524+
525+
pub const NETLINK_ROUTE: ::c_int = 0;
526+
pub const NETLINK_UNUSED: ::c_int = 1;
527+
pub const NETLINK_USERSOCK: ::c_int = 2;
528+
pub const NETLINK_FIREWALL: ::c_int = 3;
529+
pub const NETLINK_SOCK_DIAG: ::c_int = 4;
530+
pub const NETLINK_NFLOG: ::c_int = 5;
531+
pub const NETLINK_XFRM: ::c_int = 6;
532+
pub const NETLINK_SELINUX: ::c_int = 7;
533+
pub const NETLINK_ISCSI: ::c_int = 8;
534+
pub const NETLINK_AUDIT: ::c_int = 9;
535+
pub const NETLINK_FIB_LOOKUP: ::c_int = 10;
536+
pub const NETLINK_CONNECTOR: ::c_int = 11;
537+
pub const NETLINK_NETFILTER: ::c_int = 12;
538+
pub const NETLINK_IP6_FW: ::c_int = 13;
539+
pub const NETLINK_DNRTMSG: ::c_int = 14;
540+
pub const NETLINK_KOBJECT_UEVENT: ::c_int = 15;
541+
pub const NETLINK_GENERIC: ::c_int = 16;
542+
471543
safe_f! {
472544
pub {const} fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t {
473545
let major = major as ::dev_t;

src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs

+72
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ s_no_extra_traits! {
277277
pub vn_mode: u16,
278278
pub vn_devname: [::c_char; ::SPECNAMELEN as usize + 1],
279279
}
280+
281+
pub struct sockaddr_nl {
282+
pub nl_len: ::c_uchar,
283+
pub nl_family: ::sa_family_t,
284+
nl_pad: ::c_ushort,
285+
pub nl_pid: u32,
286+
pub nl_groups: u32
287+
}
280288
}
281289

282290
cfg_if! {
@@ -447,6 +455,34 @@ cfg_if! {
447455
self_vn_devname.hash(state);
448456
}
449457
}
458+
459+
impl PartialEq for sockaddr_nl {
460+
fn eq(&self, other: &sockaddr_nl) -> bool {
461+
self.nl_len == other.nl_len &&
462+
self.nl_family == other.nl_family &&
463+
self.nl_pid == other.nl_pid &&
464+
self.nl_groups == other.nl_groups
465+
}
466+
}
467+
impl Eq for sockaddr_nl {}
468+
impl ::fmt::Debug for sockaddr_nl {
469+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
470+
f.debug_struct("sockaddr_nl")
471+
.field("nl_len", &self.nl_len)
472+
.field("nl_family", &self.nl_family)
473+
.field("nl_pid", &self.nl_pid)
474+
.field("nl_groups", &self.nl_groups)
475+
.finish()
476+
}
477+
}
478+
impl ::hash::Hash for sockaddr_nl {
479+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
480+
self.nl_len.hash(state);
481+
self.nl_family.hash(state);
482+
self.nl_pid.hash(state);
483+
self.nl_groups.hash(state);
484+
}
485+
}
450486
}
451487
}
452488

@@ -468,6 +504,42 @@ pub const DOMAINSET_POLICY_INTERLEAVE: ::c_int = 4;
468504

469505
pub const MINCORE_SUPER: ::c_int = 0x60;
470506

507+
/// netlink constants
508+
pub const SOL_NETLINK: ::c_int = 270;
509+
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
510+
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
511+
pub const NETLINK_PKTINFO: ::c_int = 3;
512+
pub const NETLINK_BROADCAST_ERROR: ::c_int = 4;
513+
pub const NETLINK_NO_ENOBUFS: ::c_int = 5;
514+
pub const NETLINK_RX_RING: ::c_int = 6;
515+
pub const NETLINK_TX_RING: ::c_int = 7;
516+
pub const NETLINK_LISTEN_ALL_NSID: ::c_int = 8;
517+
pub const NETLINK_LIST_MEMBERSHIPS: ::c_int = 9;
518+
pub const NETLINK_CAP_ACK: ::c_int = 10;
519+
pub const NETLINK_EXT_ACK: ::c_int = 11;
520+
pub const NETLINK_GET_STRICT_CHK: ::c_int = 12;
521+
522+
pub const AF_NETLINK: ::c_int = 38;
523+
pub const PF_NETLINK: ::c_int = AF_NETLINK;
524+
525+
pub const NETLINK_ROUTE: ::c_int = 0;
526+
pub const NETLINK_UNUSED: ::c_int = 1;
527+
pub const NETLINK_USERSOCK: ::c_int = 2;
528+
pub const NETLINK_FIREWALL: ::c_int = 3;
529+
pub const NETLINK_SOCK_DIAG: ::c_int = 4;
530+
pub const NETLINK_NFLOG: ::c_int = 5;
531+
pub const NETLINK_XFRM: ::c_int = 6;
532+
pub const NETLINK_SELINUX: ::c_int = 7;
533+
pub const NETLINK_ISCSI: ::c_int = 8;
534+
pub const NETLINK_AUDIT: ::c_int = 9;
535+
pub const NETLINK_FIB_LOOKUP: ::c_int = 10;
536+
pub const NETLINK_CONNECTOR: ::c_int = 11;
537+
pub const NETLINK_NETFILTER: ::c_int = 12;
538+
pub const NETLINK_IP6_FW: ::c_int = 13;
539+
pub const NETLINK_DNRTMSG: ::c_int = 14;
540+
pub const NETLINK_KOBJECT_UEVENT: ::c_int = 15;
541+
pub const NETLINK_GENERIC: ::c_int = 16;
542+
471543
safe_f! {
472544
pub {const} fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t {
473545
let major = major as ::dev_t;

0 commit comments

Comments
 (0)