Skip to content

Commit 017fb07

Browse files
committed
WIP Netlink support for FreeBSD 13.2 and later
NOTE: This is an early subset of the Netlink interface. Signed-off-by: Yann Dirson <[email protected]>
1 parent 92a5d3e commit 017fb07

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

libc-test/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,7 @@ fn test_freebsd(target: &str) {
19981998
"netinet/sctp.h",
19991999
"netinet/tcp.h",
20002000
"netinet/udp.h",
2001+
[freebsd13]:"netlink/netlink.h",
20012002
"poll.h",
20022003
"pthread.h",
20032004
"pthread_np.h",

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

+72
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,14 @@ s_no_extra_traits! {
13611361
pub sdl_data: [::c_char; 46],
13621362
}
13631363

1364+
pub struct sockaddr_nl {
1365+
pub nl_len: ::c_uchar,
1366+
pub nl_family: ::sa_family_t,
1367+
nl_pad: ::c_ushort,
1368+
pub nl_pid: u32,
1369+
pub nl_groups: u32
1370+
}
1371+
13641372
pub struct mq_attr {
13651373
pub mq_flags: ::c_long,
13661374
pub mq_maxmsg: ::c_long,
@@ -1774,6 +1782,34 @@ cfg_if! {
17741782
}
17751783
}
17761784

1785+
impl PartialEq for sockaddr_nl {
1786+
fn eq(&self, other: &sockaddr_nl) -> bool {
1787+
self.nl_len == other.nl_len &&
1788+
self.nl_family == other.nl_family &&
1789+
self.nl_pid == other.nl_pid &&
1790+
self.nl_groups == other.nl_groups
1791+
}
1792+
}
1793+
impl Eq for sockaddr_nl {}
1794+
impl ::fmt::Debug for sockaddr_nl {
1795+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1796+
f.debug_struct("sockaddr_nl")
1797+
.field("nl_len", &self.nl_len)
1798+
.field("nl_family", &self.nl_family)
1799+
.field("nl_pid", &self.nl_pid)
1800+
.field("nl_groups", &self.nl_groups)
1801+
.finish()
1802+
}
1803+
}
1804+
impl ::hash::Hash for sockaddr_nl {
1805+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1806+
self.nl_len.hash(state);
1807+
self.nl_family.hash(state);
1808+
self.nl_pid.hash(state);
1809+
self.nl_groups.hash(state);
1810+
}
1811+
}
1812+
17771813
impl PartialEq for mq_attr {
17781814
fn eq(&self, other: &mq_attr) -> bool {
17791815
self.mq_flags == other.mq_flags &&
@@ -3027,6 +3063,42 @@ pub const SO_TS_MONOTONIC: ::c_int = 3;
30273063
pub const SO_TS_DEFAULT: ::c_int = SO_TS_REALTIME_MICRO;
30283064
pub const SO_TS_CLOCK_MAX: ::c_int = SO_TS_MONOTONIC;
30293065

3066+
/// netlink constants
3067+
pub const SOL_NETLINK: ::c_int = 270;
3068+
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
3069+
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
3070+
pub const NETLINK_PKTINFO: ::c_int = 3;
3071+
pub const NETLINK_BROADCAST_ERROR: ::c_int = 4;
3072+
pub const NETLINK_NO_ENOBUFS: ::c_int = 5;
3073+
pub const NETLINK_RX_RING: ::c_int = 6;
3074+
pub const NETLINK_TX_RING: ::c_int = 7;
3075+
pub const NETLINK_LISTEN_ALL_NSID: ::c_int = 8;
3076+
pub const NETLINK_LIST_MEMBERSHIPS: ::c_int = 9;
3077+
pub const NETLINK_CAP_ACK: ::c_int = 10;
3078+
pub const NETLINK_EXT_ACK: ::c_int = 11;
3079+
pub const NETLINK_GET_STRICT_CHK: ::c_int = 12;
3080+
3081+
pub const AF_NETLINK: ::c_int = 38;
3082+
pub const PF_NETLINK: ::c_int = AF_NETLINK;
3083+
3084+
pub const NETLINK_ROUTE: ::c_int = 0;
3085+
pub const NETLINK_UNUSED: ::c_int = 1;
3086+
pub const NETLINK_USERSOCK: ::c_int = 2;
3087+
pub const NETLINK_FIREWALL: ::c_int = 3;
3088+
pub const NETLINK_SOCK_DIAG: ::c_int = 4;
3089+
pub const NETLINK_NFLOG: ::c_int = 5;
3090+
pub const NETLINK_XFRM: ::c_int = 6;
3091+
pub const NETLINK_SELINUX: ::c_int = 7;
3092+
pub const NETLINK_ISCSI: ::c_int = 8;
3093+
pub const NETLINK_AUDIT: ::c_int = 9;
3094+
pub const NETLINK_FIB_LOOKUP: ::c_int = 10;
3095+
pub const NETLINK_CONNECTOR: ::c_int = 11;
3096+
pub const NETLINK_NETFILTER: ::c_int = 12;
3097+
pub const NETLINK_IP6_FW: ::c_int = 13;
3098+
pub const NETLINK_DNRTMSG: ::c_int = 14;
3099+
pub const NETLINK_KOBJECT_UEVENT: ::c_int = 15;
3100+
pub const NETLINK_GENERIC: ::c_int = 16;
3101+
30303102
pub const LOCAL_CREDS: ::c_int = 2;
30313103
pub const LOCAL_CREDS_PERSISTENT: ::c_int = 3;
30323104
pub const LOCAL_CONNWAIT: ::c_int = 4;

0 commit comments

Comments
 (0)