Skip to content

Commit 4d98ade

Browse files
committed
fixup! WIP Netlink support for FreeBSD 13.2 and later
More defines, in use by neli
1 parent 9afbd10 commit 4d98ade

File tree

2 files changed

+164
-7
lines changed

2 files changed

+164
-7
lines changed

libc-test/build.rs

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,11 @@ fn test_freebsd(target: &str) {
19531953
// Required for making freebsd11_stat available in the headers
19541954
cfg.define("_WANT_FREEBSD11_STAT", None);
19551955

1956+
let freebsd12 = match freebsd_ver {
1957+
Some(n) if n >= 12 => true,
1958+
_ => false,
1959+
};
1960+
19561961
let freebsd13 = match freebsd_ver {
19571962
Some(n) if n >= 13 => true,
19581963
_ => false,
@@ -1999,6 +2004,8 @@ fn test_freebsd(target: &str) {
19992004
"netinet/tcp.h",
20002005
"netinet/udp.h",
20012006
[freebsd13]:"netlink/netlink.h",
2007+
[freebsd13]:"netlink/netlink_generic.h",
2008+
[freebsd12]:"pcap/nflog.h",
20022009
"poll.h",
20032010
"pthread.h",
20042011
"pthread_np.h",
@@ -2227,7 +2234,9 @@ fn test_freebsd(target: &str) {
22272234
"SCM_CREDS2" | "LOCAL_CREDS_PERSISTENT" if Some(13) > freebsd_ver => true,
22282235

22292236
// Added in FreeBSD 13.2
2230-
"SOL_NETLINK"
2237+
"AF_NETLINK"
2238+
| "PF_NETLINK"
2239+
| "SOL_NETLINK"
22312240
| "NETLINK_ADD_MEMBERSHIP"
22322241
| "NETLINK_DROP_MEMBERSHIP"
22332242
| "NETLINK_PKTINFO"
@@ -2240,8 +2249,27 @@ fn test_freebsd(target: &str) {
22402249
| "NETLINK_CAP_ACK"
22412250
| "NETLINK_EXT_ACK"
22422251
| "NETLINK_GET_STRICT_CHK"
2243-
| "AF_NETLINK"
2244-
| "PF_NETLINK"
2252+
| "NLM_F_REQUEST"
2253+
| "NLM_F_MULTI"
2254+
| "NLM_F_ACK"
2255+
| "NLM_F_ECHO"
2256+
| "NLM_F_DUMP_INTR"
2257+
| "NLM_F_DUMP_FILTERED"
2258+
| "NLM_F_ROOT"
2259+
| "NLM_F_MATCH"
2260+
| "NLM_F_ATOMIC"
2261+
| "NLM_F_DUMP"
2262+
| "NLM_F_REPLACE"
2263+
| "NLM_F_EXCL"
2264+
| "NLM_F_CREATE"
2265+
| "NLM_F_APPEND"
2266+
| "NLM_F_NONREC"
2267+
| "NLM_F_CAPPED"
2268+
| "NLM_F_ACK_TLVS"
2269+
| "NLMSG_NOOP"
2270+
| "NLMSG_ERROR"
2271+
| "NLMSG_DONE"
2272+
| "NLMSG_OVERRUN"
22452273
| "NETLINK_ROUTE"
22462274
| "NETLINK_UNUSED"
22472275
| "NETLINK_USERSOCK"
@@ -2259,11 +2287,59 @@ fn test_freebsd(target: &str) {
22592287
| "NETLINK_DNRTMSG"
22602288
| "NETLINK_KOBJECT_UEVENT"
22612289
| "NETLINK_GENERIC"
2290+
| "NLMSG_ALIGNTO"
2291+
| "CTRL_CMD_UNSPEC"
2292+
| "CTRL_CMD_NEWFAMILY"
2293+
| "CTRL_CMD_DELFAMILY"
2294+
| "CTRL_CMD_GETFAMILY"
2295+
| "CTRL_CMD_NEWOPS"
2296+
| "CTRL_CMD_DELOPS"
2297+
| "CTRL_CMD_GETOPS"
2298+
| "CTRL_CMD_NEWMCAST_GRP"
2299+
| "CTRL_CMD_DELMCAST_GRP"
2300+
| "CTRL_CMD_GETMCAST_GRP"
2301+
| "CTRL_CMD_GETPOLICY"
2302+
| "CTRL_ATTR_UNSPEC"
2303+
| "CTRL_ATTR_FAMILY_ID"
2304+
| "CTRL_ATTR_FAMILY_NAME"
2305+
| "CTRL_ATTR_VERSION"
2306+
| "CTRL_ATTR_HDRSIZE"
2307+
| "CTRL_ATTR_MAXATTR"
2308+
| "CTRL_ATTR_OPS"
2309+
| "CTRL_ATTR_MCAST_GROUPS"
2310+
| "CTRL_ATTR_POLICY"
2311+
| "CTRL_ATTR_OP_POLICY"
2312+
| "CTRL_ATTR_OP"
2313+
| "CTRL_ATTR_MCAST_GRP_UNSPEC"
2314+
| "CTRL_ATTR_MCAST_GRP_NAME"
2315+
| "CTRL_ATTR_MCAST_GRP_ID"
22622316
if Some(13) > freebsd_ver =>
22632317
{
22642318
true
22652319
}
22662320

2321+
"NFULA_PACKET_HDR"
2322+
| "NFULA_MARK"
2323+
| "NFULA_TIMESTAMP"
2324+
| "NFULA_IFINDEX_INDEV"
2325+
| "NFULA_IFINDEX_OUTDEV"
2326+
| "NFULA_IFINDEX_PHYSINDEV"
2327+
| "NFULA_IFINDEX_PHYSOUTDEV"
2328+
| "NFULA_HWADDR"
2329+
| "NFULA_PAYLOAD"
2330+
| "NFULA_PREFIX"
2331+
| "NFULA_UID"
2332+
| "NFULA_SEQ"
2333+
| "NFULA_SEQ_GLOBAL"
2334+
| "NFULA_GID"
2335+
| "NFULA_HWTYPE"
2336+
| "NFULA_HWHEADER"
2337+
| "NFULA_HWLEN"
2338+
if Some(12) > freebsd_ver =>
2339+
{
2340+
true
2341+
}
2342+
22672343
// Added in FreeBSD 14
22682344
"SPACECTL_DEALLOC" if Some(14) > freebsd_ver => true,
22692345

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

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,6 +3064,12 @@ pub const SO_TS_DEFAULT: ::c_int = SO_TS_REALTIME_MICRO;
30643064
pub const SO_TS_CLOCK_MAX: ::c_int = SO_TS_MONOTONIC;
30653065

30663066
/// netlink constants
3067+
3068+
// sys/socket.h
3069+
pub const AF_NETLINK: ::c_int = 38;
3070+
pub const PF_NETLINK: ::c_int = AF_NETLINK;
3071+
3072+
// netlink/netlink.h
30673073
pub const SOL_NETLINK: ::c_int = 270;
30683074
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
30693075
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
@@ -3077,10 +3083,34 @@ pub const NETLINK_LIST_MEMBERSHIPS: ::c_int = 9;
30773083
pub const NETLINK_CAP_ACK: ::c_int = 10;
30783084
pub const NETLINK_EXT_ACK: ::c_int = 11;
30793085
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-
3086+
//
3087+
pub const NLM_F_REQUEST: ::c_int = 0x01;
3088+
pub const NLM_F_MULTI: ::c_int = 0x02;
3089+
pub const NLM_F_ACK: ::c_int = 0x04;
3090+
pub const NLM_F_ECHO: ::c_int = 0x08;
3091+
pub const NLM_F_DUMP_INTR: ::c_int = 0x10;
3092+
pub const NLM_F_DUMP_FILTERED: ::c_int = 0x20;
3093+
//
3094+
pub const NLM_F_ROOT: ::c_int = 0x100;
3095+
pub const NLM_F_MATCH: ::c_int = 0x200;
3096+
pub const NLM_F_ATOMIC: ::c_int = 0x400;
3097+
pub const NLM_F_DUMP: ::c_int = NLM_F_ROOT | NLM_F_MATCH;
3098+
//
3099+
pub const NLM_F_REPLACE: ::c_int = 0x100;
3100+
pub const NLM_F_EXCL: ::c_int = 0x200;
3101+
pub const NLM_F_CREATE: ::c_int = 0x400;
3102+
pub const NLM_F_APPEND: ::c_int = 0x800;
3103+
//
3104+
pub const NLM_F_NONREC: ::c_int = 0x100;
3105+
//
3106+
pub const NLM_F_CAPPED: ::c_int = 0x100;
3107+
pub const NLM_F_ACK_TLVS: ::c_int = 0x200;
3108+
//
3109+
pub const NLMSG_NOOP: ::c_int = 0x1;
3110+
pub const NLMSG_ERROR: ::c_int = 0x2;
3111+
pub const NLMSG_DONE: ::c_int = 0x3;
3112+
pub const NLMSG_OVERRUN: ::c_int = 0x4;
3113+
//
30843114
pub const NETLINK_ROUTE: ::c_int = 0;
30853115
pub const NETLINK_UNUSED: ::c_int = 1;
30863116
pub const NETLINK_USERSOCK: ::c_int = 2;
@@ -3098,6 +3128,57 @@ pub const NETLINK_IP6_FW: ::c_int = 13;
30983128
pub const NETLINK_DNRTMSG: ::c_int = 14;
30993129
pub const NETLINK_KOBJECT_UEVENT: ::c_int = 15;
31003130
pub const NETLINK_GENERIC: ::c_int = 16;
3131+
//
3132+
const NL_ITEM_ALIGN_SIZE: ::c_int = 4; // mem::size_of::<u32>(); FIXME accept new dep?
3133+
pub const NLMSG_ALIGNTO: ::c_int = NL_ITEM_ALIGN_SIZE;
3134+
3135+
// netlink/netlink_generic.h
3136+
pub const CTRL_CMD_UNSPEC: ::c_int = 0;
3137+
pub const CTRL_CMD_NEWFAMILY: ::c_int = 1;
3138+
pub const CTRL_CMD_DELFAMILY: ::c_int = 2;
3139+
pub const CTRL_CMD_GETFAMILY: ::c_int = 3;
3140+
pub const CTRL_CMD_NEWOPS: ::c_int = 4;
3141+
pub const CTRL_CMD_DELOPS: ::c_int = 5;
3142+
pub const CTRL_CMD_GETOPS: ::c_int = 6;
3143+
pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7;
3144+
pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8;
3145+
pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9;
3146+
pub const CTRL_CMD_GETPOLICY: ::c_int = 10;
3147+
//
3148+
pub const CTRL_ATTR_UNSPEC: ::c_int = 0;
3149+
pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1;
3150+
pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2;
3151+
pub const CTRL_ATTR_VERSION: ::c_int = 3;
3152+
pub const CTRL_ATTR_HDRSIZE: ::c_int = 4;
3153+
pub const CTRL_ATTR_MAXATTR: ::c_int = 5;
3154+
pub const CTRL_ATTR_OPS: ::c_int = 6;
3155+
pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7;
3156+
pub const CTRL_ATTR_POLICY: ::c_int = 8;
3157+
pub const CTRL_ATTR_OP_POLICY: ::c_int = 9;
3158+
pub const CTRL_ATTR_OP: ::c_int = 10;
3159+
//
3160+
pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0;
3161+
pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1;
3162+
pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2;
3163+
3164+
// pcap/nflog.h
3165+
pub const NFULA_PACKET_HDR: ::c_int = 1;
3166+
pub const NFULA_MARK: ::c_int = 2;
3167+
pub const NFULA_TIMESTAMP: ::c_int = 3;
3168+
pub const NFULA_IFINDEX_INDEV: ::c_int = 4;
3169+
pub const NFULA_IFINDEX_OUTDEV: ::c_int = 5;
3170+
pub const NFULA_IFINDEX_PHYSINDEV: ::c_int = 6;
3171+
pub const NFULA_IFINDEX_PHYSOUTDEV: ::c_int = 7;
3172+
pub const NFULA_HWADDR: ::c_int = 8;
3173+
pub const NFULA_PAYLOAD: ::c_int = 9;
3174+
pub const NFULA_PREFIX: ::c_int = 10;
3175+
pub const NFULA_UID: ::c_int = 11;
3176+
pub const NFULA_SEQ: ::c_int = 12;
3177+
pub const NFULA_SEQ_GLOBAL: ::c_int = 13;
3178+
pub const NFULA_GID: ::c_int = 14;
3179+
pub const NFULA_HWTYPE: ::c_int = 15;
3180+
pub const NFULA_HWHEADER: ::c_int = 16;
3181+
pub const NFULA_HWLEN: ::c_int = 17;
31013182

31023183
pub const LOCAL_CREDS: ::c_int = 2;
31033184
pub const LOCAL_CREDS_PERSISTENT: ::c_int = 3;

0 commit comments

Comments
 (0)