Skip to content

Commit

Permalink
WIP Netlink support for FreeBSD 13.2 and later
Browse files Browse the repository at this point in the history
NOTE: This is an early subset of the Netlink interface.

Signed-off-by: Yann Dirson <[email protected]>
  • Loading branch information
ydirson committed Aug 18, 2023
1 parent 92a5d3e commit 017fb07
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,7 @@ fn test_freebsd(target: &str) {
"netinet/sctp.h",
"netinet/tcp.h",
"netinet/udp.h",
[freebsd13]:"netlink/netlink.h",
"poll.h",
"pthread.h",
"pthread_np.h",
Expand Down
72 changes: 72 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,14 @@ s_no_extra_traits! {
pub sdl_data: [::c_char; 46],
}

pub struct sockaddr_nl {
pub nl_len: ::c_uchar,
pub nl_family: ::sa_family_t,
nl_pad: ::c_ushort,
pub nl_pid: u32,
pub nl_groups: u32
}

pub struct mq_attr {
pub mq_flags: ::c_long,
pub mq_maxmsg: ::c_long,
Expand Down Expand Up @@ -1774,6 +1782,34 @@ cfg_if! {
}
}

impl PartialEq for sockaddr_nl {
fn eq(&self, other: &sockaddr_nl) -> bool {
self.nl_len == other.nl_len &&
self.nl_family == other.nl_family &&
self.nl_pid == other.nl_pid &&
self.nl_groups == other.nl_groups
}
}
impl Eq for sockaddr_nl {}
impl ::fmt::Debug for sockaddr_nl {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sockaddr_nl")
.field("nl_len", &self.nl_len)
.field("nl_family", &self.nl_family)
.field("nl_pid", &self.nl_pid)
.field("nl_groups", &self.nl_groups)
.finish()
}
}
impl ::hash::Hash for sockaddr_nl {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.nl_len.hash(state);
self.nl_family.hash(state);
self.nl_pid.hash(state);
self.nl_groups.hash(state);
}
}

impl PartialEq for mq_attr {
fn eq(&self, other: &mq_attr) -> bool {
self.mq_flags == other.mq_flags &&
Expand Down Expand Up @@ -3027,6 +3063,42 @@ pub const SO_TS_MONOTONIC: ::c_int = 3;
pub const SO_TS_DEFAULT: ::c_int = SO_TS_REALTIME_MICRO;
pub const SO_TS_CLOCK_MAX: ::c_int = SO_TS_MONOTONIC;

/// netlink constants
pub const SOL_NETLINK: ::c_int = 270;
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
pub const NETLINK_PKTINFO: ::c_int = 3;
pub const NETLINK_BROADCAST_ERROR: ::c_int = 4;
pub const NETLINK_NO_ENOBUFS: ::c_int = 5;
pub const NETLINK_RX_RING: ::c_int = 6;
pub const NETLINK_TX_RING: ::c_int = 7;
pub const NETLINK_LISTEN_ALL_NSID: ::c_int = 8;
pub const NETLINK_LIST_MEMBERSHIPS: ::c_int = 9;
pub const NETLINK_CAP_ACK: ::c_int = 10;
pub const NETLINK_EXT_ACK: ::c_int = 11;
pub const NETLINK_GET_STRICT_CHK: ::c_int = 12;

pub const AF_NETLINK: ::c_int = 38;
pub const PF_NETLINK: ::c_int = AF_NETLINK;

pub const NETLINK_ROUTE: ::c_int = 0;
pub const NETLINK_UNUSED: ::c_int = 1;
pub const NETLINK_USERSOCK: ::c_int = 2;
pub const NETLINK_FIREWALL: ::c_int = 3;
pub const NETLINK_SOCK_DIAG: ::c_int = 4;
pub const NETLINK_NFLOG: ::c_int = 5;
pub const NETLINK_XFRM: ::c_int = 6;
pub const NETLINK_SELINUX: ::c_int = 7;
pub const NETLINK_ISCSI: ::c_int = 8;
pub const NETLINK_AUDIT: ::c_int = 9;
pub const NETLINK_FIB_LOOKUP: ::c_int = 10;
pub const NETLINK_CONNECTOR: ::c_int = 11;
pub const NETLINK_NETFILTER: ::c_int = 12;
pub const NETLINK_IP6_FW: ::c_int = 13;
pub const NETLINK_DNRTMSG: ::c_int = 14;
pub const NETLINK_KOBJECT_UEVENT: ::c_int = 15;
pub const NETLINK_GENERIC: ::c_int = 16;

pub const LOCAL_CREDS: ::c_int = 2;
pub const LOCAL_CREDS_PERSISTENT: ::c_int = 3;
pub const LOCAL_CONNWAIT: ::c_int = 4;
Expand Down

0 comments on commit 017fb07

Please sign in to comment.