Skip to content

Commit f210e11

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 <[email protected]>
1 parent 121aada commit f210e11

File tree

4 files changed

+110
-99
lines changed

4 files changed

+110
-99
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ extra_traits = []
141141
const-extern-fn = []
142142
# use_std is deprecated, use `std` instead
143143
use_std = ['std']
144+
# get Netlink support on FreeBSD, but with breaking API change,
145+
# see https://github.com/rust-lang/libc/pull/3367
146+
future-freebsd-netlink = []
144147

145148
[workspace]
146149
members = ["libc-test"]

libc-test/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,9 @@ fn test_freebsd(target: &str) {
24282428
| "CTRL_ATTR_MCAST_GRP_UNSPEC"
24292429
| "CTRL_ATTR_MCAST_GRP_NAME"
24302430
| "CTRL_ATTR_MCAST_GRP_ID"
2431-
if Some(13) > freebsd_ver =>
2431+
if env!("CARGO_PKG_VERSION_MAJOR") == "0"
2432+
&& env!("CARGO_PKG_VERSION_MINOR") == "2"
2433+
|| Some(13) > freebsd_ver =>
24322434
{
24332435
true
24342436
}

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

+9-98
Original file line numberDiff line numberDiff line change
@@ -3097,104 +3097,6 @@ pub const SO_TS_MONOTONIC: ::c_int = 3;
30973097
pub const SO_TS_DEFAULT: ::c_int = SO_TS_REALTIME_MICRO;
30983098
pub const SO_TS_CLOCK_MAX: ::c_int = SO_TS_MONOTONIC;
30993099

3100-
/// netlink constants
3101-
3102-
// sys/socket.h
3103-
pub const AF_NETLINK: ::c_int = 38;
3104-
pub const PF_NETLINK: ::c_int = AF_NETLINK;
3105-
3106-
// netlink/netlink.h
3107-
pub const SOL_NETLINK: ::c_int = 270;
3108-
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
3109-
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
3110-
pub const NETLINK_PKTINFO: ::c_int = 3;
3111-
pub const NETLINK_BROADCAST_ERROR: ::c_int = 4;
3112-
pub const NETLINK_NO_ENOBUFS: ::c_int = 5;
3113-
pub const NETLINK_RX_RING: ::c_int = 6;
3114-
pub const NETLINK_TX_RING: ::c_int = 7;
3115-
pub const NETLINK_LISTEN_ALL_NSID: ::c_int = 8;
3116-
pub const NETLINK_LIST_MEMBERSHIPS: ::c_int = 9;
3117-
pub const NETLINK_CAP_ACK: ::c_int = 10;
3118-
pub const NETLINK_EXT_ACK: ::c_int = 11;
3119-
pub const NETLINK_GET_STRICT_CHK: ::c_int = 12;
3120-
//
3121-
pub const NLM_F_REQUEST: ::c_int = 0x01;
3122-
pub const NLM_F_MULTI: ::c_int = 0x02;
3123-
pub const NLM_F_ACK: ::c_int = 0x04;
3124-
pub const NLM_F_ECHO: ::c_int = 0x08;
3125-
pub const NLM_F_DUMP_INTR: ::c_int = 0x10;
3126-
pub const NLM_F_DUMP_FILTERED: ::c_int = 0x20;
3127-
//
3128-
pub const NLM_F_ROOT: ::c_int = 0x100;
3129-
pub const NLM_F_MATCH: ::c_int = 0x200;
3130-
pub const NLM_F_ATOMIC: ::c_int = 0x400;
3131-
pub const NLM_F_DUMP: ::c_int = NLM_F_ROOT | NLM_F_MATCH;
3132-
//
3133-
pub const NLM_F_REPLACE: ::c_int = 0x100;
3134-
pub const NLM_F_EXCL: ::c_int = 0x200;
3135-
pub const NLM_F_CREATE: ::c_int = 0x400;
3136-
pub const NLM_F_APPEND: ::c_int = 0x800;
3137-
//
3138-
pub const NLM_F_NONREC: ::c_int = 0x100;
3139-
//
3140-
pub const NLM_F_CAPPED: ::c_int = 0x100;
3141-
pub const NLM_F_ACK_TLVS: ::c_int = 0x200;
3142-
//
3143-
pub const NLMSG_NOOP: ::c_int = 0x1;
3144-
pub const NLMSG_ERROR: ::c_int = 0x2;
3145-
pub const NLMSG_DONE: ::c_int = 0x3;
3146-
pub const NLMSG_OVERRUN: ::c_int = 0x4;
3147-
//
3148-
pub const NETLINK_ROUTE: ::c_int = 0;
3149-
pub const NETLINK_UNUSED: ::c_int = 1;
3150-
pub const NETLINK_USERSOCK: ::c_int = 2;
3151-
pub const NETLINK_FIREWALL: ::c_int = 3;
3152-
pub const NETLINK_SOCK_DIAG: ::c_int = 4;
3153-
pub const NETLINK_NFLOG: ::c_int = 5;
3154-
pub const NETLINK_XFRM: ::c_int = 6;
3155-
pub const NETLINK_SELINUX: ::c_int = 7;
3156-
pub const NETLINK_ISCSI: ::c_int = 8;
3157-
pub const NETLINK_AUDIT: ::c_int = 9;
3158-
pub const NETLINK_FIB_LOOKUP: ::c_int = 10;
3159-
pub const NETLINK_CONNECTOR: ::c_int = 11;
3160-
pub const NETLINK_NETFILTER: ::c_int = 12;
3161-
pub const NETLINK_IP6_FW: ::c_int = 13;
3162-
pub const NETLINK_DNRTMSG: ::c_int = 14;
3163-
pub const NETLINK_KOBJECT_UEVENT: ::c_int = 15;
3164-
pub const NETLINK_GENERIC: ::c_int = 16;
3165-
//
3166-
const NL_ITEM_ALIGN_SIZE: ::c_int = 4; // mem::size_of::<u32>(); FIXME accept new dep?
3167-
pub const NLMSG_ALIGNTO: ::c_int = NL_ITEM_ALIGN_SIZE;
3168-
3169-
// netlink/netlink_generic.h
3170-
pub const CTRL_CMD_UNSPEC: ::c_int = 0;
3171-
pub const CTRL_CMD_NEWFAMILY: ::c_int = 1;
3172-
pub const CTRL_CMD_DELFAMILY: ::c_int = 2;
3173-
pub const CTRL_CMD_GETFAMILY: ::c_int = 3;
3174-
pub const CTRL_CMD_NEWOPS: ::c_int = 4;
3175-
pub const CTRL_CMD_DELOPS: ::c_int = 5;
3176-
pub const CTRL_CMD_GETOPS: ::c_int = 6;
3177-
pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7;
3178-
pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8;
3179-
pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9;
3180-
pub const CTRL_CMD_GETPOLICY: ::c_int = 10;
3181-
//
3182-
pub const CTRL_ATTR_UNSPEC: ::c_int = 0;
3183-
pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1;
3184-
pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2;
3185-
pub const CTRL_ATTR_VERSION: ::c_int = 3;
3186-
pub const CTRL_ATTR_HDRSIZE: ::c_int = 4;
3187-
pub const CTRL_ATTR_MAXATTR: ::c_int = 5;
3188-
pub const CTRL_ATTR_OPS: ::c_int = 6;
3189-
pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7;
3190-
pub const CTRL_ATTR_POLICY: ::c_int = 8;
3191-
pub const CTRL_ATTR_OP_POLICY: ::c_int = 9;
3192-
pub const CTRL_ATTR_OP: ::c_int = 10;
3193-
//
3194-
pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0;
3195-
pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1;
3196-
pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2;
3197-
31983100
pub const LOCAL_CREDS: ::c_int = 2;
31993101
pub const LOCAL_CREDS_PERSISTENT: ::c_int = 3;
32003102
pub const LOCAL_CONNWAIT: ::c_int = 4;
@@ -5841,3 +5743,12 @@ cfg_if! {
58415743

58425744
// sys/net/if_mib.h
58435745
pub mod ifmib;
5746+
5747+
cfg_if! {
5748+
if #[cfg(feature = "future-freebsd-netlink")] {
5749+
mod netlink;
5750+
pub use self::netlink::*;
5751+
} else {
5752+
pub use ifmib::*;
5753+
}
5754+
}
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)