Skip to content

Commit 266566d

Browse files
committed
freebsd/netlink: hide feature between "future-freebsd-netlink" flag
To allow the "Netlink on FreeBSD" feature to be usable before 0.3 gets released, this builds on top of both the netlink feature patch from rust-lang#3201 if explicitely requested through a feature flag, but by default provides the ifmib constants where they are located in previous 0.2 releases. Since this relies on creating the netlink constants in a separate module, and it seems we cannot check those automatically, avoids testing them. Signed-off-by: Yann Dirson <yann.dirson@vates.fr>
1 parent 6fcd7d2 commit 266566d

File tree

4 files changed

+110
-99
lines changed

4 files changed

+110
-99
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ align = []
177177

178178
# use_std is deprecated, use `std` instead
179179
use_std = ['std']
180+
# get Netlink support on FreeBSD, but with breaking API change,
181+
# see https://github.com/rust-lang/libc/pull/3367
182+
future-freebsd-netlink = []
180183

181184
[workspace]
182185
members = [

libc-test/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,9 @@ fn test_freebsd(target: &str) {
27952795
| "CTRL_ATTR_MCAST_GRP_UNSPEC"
27962796
| "CTRL_ATTR_MCAST_GRP_NAME"
27972797
| "CTRL_ATTR_MCAST_GRP_ID"
2798-
if Some(13) > freebsd_ver =>
2798+
if env!("CARGO_PKG_VERSION_MAJOR") == "0"
2799+
&& env!("CARGO_PKG_VERSION_MINOR") == "2"
2800+
|| Some(13) > freebsd_ver =>
27992801
{
28002802
true
28012803
}

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

Lines changed: 9 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,104 +2560,6 @@ pub const SO_TS_MONOTONIC: c_int = 3;
25602560
pub const SO_TS_DEFAULT: c_int = SO_TS_REALTIME_MICRO;
25612561
pub const SO_TS_CLOCK_MAX: c_int = SO_TS_MONOTONIC;
25622562

2563-
/// netlink constants
2564-
2565-
// sys/socket.h
2566-
pub const AF_NETLINK: c_int = 38;
2567-
pub const PF_NETLINK: c_int = AF_NETLINK;
2568-
2569-
// netlink/netlink.h
2570-
pub const SOL_NETLINK: c_int = 270;
2571-
pub const NETLINK_ADD_MEMBERSHIP: c_int = 1;
2572-
pub const NETLINK_DROP_MEMBERSHIP: c_int = 2;
2573-
pub const NETLINK_PKTINFO: c_int = 3;
2574-
pub const NETLINK_BROADCAST_ERROR: c_int = 4;
2575-
pub const NETLINK_NO_ENOBUFS: c_int = 5;
2576-
pub const NETLINK_RX_RING: c_int = 6;
2577-
pub const NETLINK_TX_RING: c_int = 7;
2578-
pub const NETLINK_LISTEN_ALL_NSID: c_int = 8;
2579-
pub const NETLINK_LIST_MEMBERSHIPS: c_int = 9;
2580-
pub const NETLINK_CAP_ACK: c_int = 10;
2581-
pub const NETLINK_EXT_ACK: c_int = 11;
2582-
pub const NETLINK_GET_STRICT_CHK: c_int = 12;
2583-
//
2584-
pub const NLM_F_REQUEST: c_int = 0x01;
2585-
pub const NLM_F_MULTI: c_int = 0x02;
2586-
pub const NLM_F_ACK: c_int = 0x04;
2587-
pub const NLM_F_ECHO: c_int = 0x08;
2588-
pub const NLM_F_DUMP_INTR: c_int = 0x10;
2589-
pub const NLM_F_DUMP_FILTERED: c_int = 0x20;
2590-
//
2591-
pub const NLM_F_ROOT: c_int = 0x100;
2592-
pub const NLM_F_MATCH: c_int = 0x200;
2593-
pub const NLM_F_ATOMIC: c_int = 0x400;
2594-
pub const NLM_F_DUMP: c_int = NLM_F_ROOT | NLM_F_MATCH;
2595-
//
2596-
pub const NLM_F_REPLACE: c_int = 0x100;
2597-
pub const NLM_F_EXCL: c_int = 0x200;
2598-
pub const NLM_F_CREATE: c_int = 0x400;
2599-
pub const NLM_F_APPEND: c_int = 0x800;
2600-
//
2601-
pub const NLM_F_NONREC: c_int = 0x100;
2602-
//
2603-
pub const NLM_F_CAPPED: c_int = 0x100;
2604-
pub const NLM_F_ACK_TLVS: c_int = 0x200;
2605-
//
2606-
pub const NLMSG_NOOP: c_int = 0x1;
2607-
pub const NLMSG_ERROR: c_int = 0x2;
2608-
pub const NLMSG_DONE: c_int = 0x3;
2609-
pub const NLMSG_OVERRUN: c_int = 0x4;
2610-
//
2611-
pub const NETLINK_ROUTE: c_int = 0;
2612-
pub const NETLINK_UNUSED: c_int = 1;
2613-
pub const NETLINK_USERSOCK: c_int = 2;
2614-
pub const NETLINK_FIREWALL: c_int = 3;
2615-
pub const NETLINK_SOCK_DIAG: c_int = 4;
2616-
pub const NETLINK_NFLOG: c_int = 5;
2617-
pub const NETLINK_XFRM: c_int = 6;
2618-
pub const NETLINK_SELINUX: c_int = 7;
2619-
pub const NETLINK_ISCSI: c_int = 8;
2620-
pub const NETLINK_AUDIT: c_int = 9;
2621-
pub const NETLINK_FIB_LOOKUP: c_int = 10;
2622-
pub const NETLINK_CONNECTOR: c_int = 11;
2623-
pub const NETLINK_NETFILTER: c_int = 12;
2624-
pub const NETLINK_IP6_FW: c_int = 13;
2625-
pub const NETLINK_DNRTMSG: c_int = 14;
2626-
pub const NETLINK_KOBJECT_UEVENT: c_int = 15;
2627-
pub const NETLINK_GENERIC: c_int = 16;
2628-
//
2629-
const NL_ITEM_ALIGN_SIZE: c_int = 4; // mem::size_of::<u32>(); FIXME accept new dep?
2630-
pub const NLMSG_ALIGNTO: c_int = NL_ITEM_ALIGN_SIZE;
2631-
2632-
// netlink/netlink_generic.h
2633-
pub const CTRL_CMD_UNSPEC: c_int = 0;
2634-
pub const CTRL_CMD_NEWFAMILY: c_int = 1;
2635-
pub const CTRL_CMD_DELFAMILY: c_int = 2;
2636-
pub const CTRL_CMD_GETFAMILY: c_int = 3;
2637-
pub const CTRL_CMD_NEWOPS: c_int = 4;
2638-
pub const CTRL_CMD_DELOPS: c_int = 5;
2639-
pub const CTRL_CMD_GETOPS: c_int = 6;
2640-
pub const CTRL_CMD_NEWMCAST_GRP: c_int = 7;
2641-
pub const CTRL_CMD_DELMCAST_GRP: c_int = 8;
2642-
pub const CTRL_CMD_GETMCAST_GRP: c_int = 9;
2643-
pub const CTRL_CMD_GETPOLICY: c_int = 10;
2644-
//
2645-
pub const CTRL_ATTR_UNSPEC: c_int = 0;
2646-
pub const CTRL_ATTR_FAMILY_ID: c_int = 1;
2647-
pub const CTRL_ATTR_FAMILY_NAME: c_int = 2;
2648-
pub const CTRL_ATTR_VERSION: c_int = 3;
2649-
pub const CTRL_ATTR_HDRSIZE: c_int = 4;
2650-
pub const CTRL_ATTR_MAXATTR: c_int = 5;
2651-
pub const CTRL_ATTR_OPS: c_int = 6;
2652-
pub const CTRL_ATTR_MCAST_GROUPS: c_int = 7;
2653-
pub const CTRL_ATTR_POLICY: c_int = 8;
2654-
pub const CTRL_ATTR_OP_POLICY: c_int = 9;
2655-
pub const CTRL_ATTR_OP: c_int = 10;
2656-
//
2657-
pub const CTRL_ATTR_MCAST_GRP_UNSPEC: c_int = 0;
2658-
pub const CTRL_ATTR_MCAST_GRP_NAME: c_int = 1;
2659-
pub const CTRL_ATTR_MCAST_GRP_ID: c_int = 2;
2660-
26612563
pub const LOCAL_CREDS: c_int = 2;
26622564
pub const LOCAL_CREDS_PERSISTENT: c_int = 3;
26632565
pub const LOCAL_CONNWAIT: c_int = 4;
@@ -5279,3 +5181,12 @@ cfg_if! {
52795181

52805182
// sys/net/if_mib.h
52815183
pub mod ifmib;
5184+
5185+
cfg_if! {
5186+
if #[cfg(feature = "future-freebsd-netlink")] {
5187+
mod netlink;
5188+
pub use self::netlink::*;
5189+
} else {
5190+
pub use ifmib::*;
5191+
}
5192+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// sys/socket.h
2+
pub const AF_NETLINK: c_int = 38;
3+
pub const PF_NETLINK: c_int = AF_NETLINK;
4+
5+
// netlink/netlink.h
6+
pub const SOL_NETLINK: c_int = 270;
7+
pub const NETLINK_ADD_MEMBERSHIP: c_int = 1;
8+
pub const NETLINK_DROP_MEMBERSHIP: c_int = 2;
9+
pub const NETLINK_PKTINFO: c_int = 3;
10+
pub const NETLINK_BROADCAST_ERROR: c_int = 4;
11+
pub const NETLINK_NO_ENOBUFS: c_int = 5;
12+
pub const NETLINK_RX_RING: c_int = 6;
13+
pub const NETLINK_TX_RING: c_int = 7;
14+
pub const NETLINK_LISTEN_ALL_NSID: c_int = 8;
15+
pub const NETLINK_LIST_MEMBERSHIPS: c_int = 9;
16+
pub const NETLINK_CAP_ACK: c_int = 10;
17+
pub const NETLINK_EXT_ACK: c_int = 11;
18+
pub const NETLINK_GET_STRICT_CHK: c_int = 12;
19+
//
20+
pub const NLM_F_REQUEST: c_int = 0x01;
21+
pub const NLM_F_MULTI: c_int = 0x02;
22+
pub const NLM_F_ACK: c_int = 0x04;
23+
pub const NLM_F_ECHO: c_int = 0x08;
24+
pub const NLM_F_DUMP_INTR: c_int = 0x10;
25+
pub const NLM_F_DUMP_FILTERED: c_int = 0x20;
26+
//
27+
pub const NLM_F_ROOT: c_int = 0x100;
28+
pub const NLM_F_MATCH: c_int = 0x200;
29+
pub const NLM_F_ATOMIC: c_int = 0x400;
30+
pub const NLM_F_DUMP: c_int = NLM_F_ROOT | NLM_F_MATCH;
31+
//
32+
pub const NLM_F_REPLACE: c_int = 0x100;
33+
pub const NLM_F_EXCL: c_int = 0x200;
34+
pub const NLM_F_CREATE: c_int = 0x400;
35+
pub const NLM_F_APPEND: c_int = 0x800;
36+
//
37+
pub const NLM_F_NONREC: c_int = 0x100;
38+
//
39+
pub const NLM_F_CAPPED: c_int = 0x100;
40+
pub const NLM_F_ACK_TLVS: c_int = 0x200;
41+
//
42+
pub const NLMSG_NOOP: c_int = 0x1;
43+
pub const NLMSG_ERROR: c_int = 0x2;
44+
pub const NLMSG_DONE: c_int = 0x3;
45+
pub const NLMSG_OVERRUN: c_int = 0x4;
46+
//
47+
pub const NETLINK_ROUTE: c_int = 0;
48+
pub const NETLINK_UNUSED: c_int = 1;
49+
pub const NETLINK_USERSOCK: c_int = 2;
50+
pub const NETLINK_FIREWALL: c_int = 3;
51+
pub const NETLINK_SOCK_DIAG: c_int = 4;
52+
pub const NETLINK_NFLOG: c_int = 5;
53+
pub const NETLINK_XFRM: c_int = 6;
54+
pub const NETLINK_SELINUX: c_int = 7;
55+
pub const NETLINK_ISCSI: c_int = 8;
56+
pub const NETLINK_AUDIT: c_int = 9;
57+
pub const NETLINK_FIB_LOOKUP: c_int = 10;
58+
pub const NETLINK_CONNECTOR: c_int = 11;
59+
pub const NETLINK_NETFILTER: c_int = 12;
60+
pub const NETLINK_IP6_FW: c_int = 13;
61+
pub const NETLINK_DNRTMSG: c_int = 14;
62+
pub const NETLINK_KOBJECT_UEVENT: c_int = 15;
63+
pub const NETLINK_GENERIC: c_int = 16;
64+
//
65+
const NL_ITEM_ALIGN_SIZE: c_int = 4; // mem::size_of::<u32>(); FIXME accept new dep?
66+
pub const NLMSG_ALIGNTO: c_int = NL_ITEM_ALIGN_SIZE;
67+
68+
// netlink/netlink_generic.h
69+
pub const CTRL_CMD_UNSPEC: c_int = 0;
70+
pub const CTRL_CMD_NEWFAMILY: c_int = 1;
71+
pub const CTRL_CMD_DELFAMILY: c_int = 2;
72+
pub const CTRL_CMD_GETFAMILY: c_int = 3;
73+
pub const CTRL_CMD_NEWOPS: c_int = 4;
74+
pub const CTRL_CMD_DELOPS: c_int = 5;
75+
pub const CTRL_CMD_GETOPS: c_int = 6;
76+
pub const CTRL_CMD_NEWMCAST_GRP: c_int = 7;
77+
pub const CTRL_CMD_DELMCAST_GRP: c_int = 8;
78+
pub const CTRL_CMD_GETMCAST_GRP: c_int = 9;
79+
pub const CTRL_CMD_GETPOLICY: c_int = 10;
80+
//
81+
pub const CTRL_ATTR_UNSPEC: c_int = 0;
82+
pub const CTRL_ATTR_FAMILY_ID: c_int = 1;
83+
pub const CTRL_ATTR_FAMILY_NAME: c_int = 2;
84+
pub const CTRL_ATTR_VERSION: c_int = 3;
85+
pub const CTRL_ATTR_HDRSIZE: c_int = 4;
86+
pub const CTRL_ATTR_MAXATTR: c_int = 5;
87+
pub const CTRL_ATTR_OPS: c_int = 6;
88+
pub const CTRL_ATTR_MCAST_GROUPS: c_int = 7;
89+
pub const CTRL_ATTR_POLICY: c_int = 8;
90+
pub const CTRL_ATTR_OP_POLICY: c_int = 9;
91+
pub const CTRL_ATTR_OP: c_int = 10;
92+
//
93+
pub const CTRL_ATTR_MCAST_GRP_UNSPEC: c_int = 0;
94+
pub const CTRL_ATTR_MCAST_GRP_NAME: c_int = 1;
95+
pub const CTRL_ATTR_MCAST_GRP_ID: c_int = 2;

0 commit comments

Comments
 (0)