Skip to content

Commit

Permalink
fixup! WIP Netlink support for FreeBSD 13.2 and later
Browse files Browse the repository at this point in the history
More defines, in use by neli
  • Loading branch information
ydirson committed Sep 14, 2023
1 parent 9afbd10 commit 4d98ade
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 7 deletions.
82 changes: 79 additions & 3 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,11 @@ fn test_freebsd(target: &str) {
// Required for making freebsd11_stat available in the headers
cfg.define("_WANT_FREEBSD11_STAT", None);

let freebsd12 = match freebsd_ver {
Some(n) if n >= 12 => true,
_ => false,
};

let freebsd13 = match freebsd_ver {
Some(n) if n >= 13 => true,
_ => false,
Expand Down Expand Up @@ -1999,6 +2004,8 @@ fn test_freebsd(target: &str) {
"netinet/tcp.h",
"netinet/udp.h",
[freebsd13]:"netlink/netlink.h",
[freebsd13]:"netlink/netlink_generic.h",
[freebsd12]:"pcap/nflog.h",
"poll.h",
"pthread.h",
"pthread_np.h",
Expand Down Expand Up @@ -2227,7 +2234,9 @@ fn test_freebsd(target: &str) {
"SCM_CREDS2" | "LOCAL_CREDS_PERSISTENT" if Some(13) > freebsd_ver => true,

// Added in FreeBSD 13.2
"SOL_NETLINK"
"AF_NETLINK"
| "PF_NETLINK"
| "SOL_NETLINK"
| "NETLINK_ADD_MEMBERSHIP"
| "NETLINK_DROP_MEMBERSHIP"
| "NETLINK_PKTINFO"
Expand All @@ -2240,8 +2249,27 @@ fn test_freebsd(target: &str) {
| "NETLINK_CAP_ACK"
| "NETLINK_EXT_ACK"
| "NETLINK_GET_STRICT_CHK"
| "AF_NETLINK"
| "PF_NETLINK"
| "NLM_F_REQUEST"
| "NLM_F_MULTI"
| "NLM_F_ACK"
| "NLM_F_ECHO"
| "NLM_F_DUMP_INTR"
| "NLM_F_DUMP_FILTERED"
| "NLM_F_ROOT"
| "NLM_F_MATCH"
| "NLM_F_ATOMIC"
| "NLM_F_DUMP"
| "NLM_F_REPLACE"
| "NLM_F_EXCL"
| "NLM_F_CREATE"
| "NLM_F_APPEND"
| "NLM_F_NONREC"
| "NLM_F_CAPPED"
| "NLM_F_ACK_TLVS"
| "NLMSG_NOOP"
| "NLMSG_ERROR"
| "NLMSG_DONE"
| "NLMSG_OVERRUN"
| "NETLINK_ROUTE"
| "NETLINK_UNUSED"
| "NETLINK_USERSOCK"
Expand All @@ -2259,11 +2287,59 @@ fn test_freebsd(target: &str) {
| "NETLINK_DNRTMSG"
| "NETLINK_KOBJECT_UEVENT"
| "NETLINK_GENERIC"
| "NLMSG_ALIGNTO"
| "CTRL_CMD_UNSPEC"
| "CTRL_CMD_NEWFAMILY"
| "CTRL_CMD_DELFAMILY"
| "CTRL_CMD_GETFAMILY"
| "CTRL_CMD_NEWOPS"
| "CTRL_CMD_DELOPS"
| "CTRL_CMD_GETOPS"
| "CTRL_CMD_NEWMCAST_GRP"
| "CTRL_CMD_DELMCAST_GRP"
| "CTRL_CMD_GETMCAST_GRP"
| "CTRL_CMD_GETPOLICY"
| "CTRL_ATTR_UNSPEC"
| "CTRL_ATTR_FAMILY_ID"
| "CTRL_ATTR_FAMILY_NAME"
| "CTRL_ATTR_VERSION"
| "CTRL_ATTR_HDRSIZE"
| "CTRL_ATTR_MAXATTR"
| "CTRL_ATTR_OPS"
| "CTRL_ATTR_MCAST_GROUPS"
| "CTRL_ATTR_POLICY"
| "CTRL_ATTR_OP_POLICY"
| "CTRL_ATTR_OP"
| "CTRL_ATTR_MCAST_GRP_UNSPEC"
| "CTRL_ATTR_MCAST_GRP_NAME"
| "CTRL_ATTR_MCAST_GRP_ID"
if Some(13) > freebsd_ver =>
{
true
}

"NFULA_PACKET_HDR"
| "NFULA_MARK"
| "NFULA_TIMESTAMP"
| "NFULA_IFINDEX_INDEV"
| "NFULA_IFINDEX_OUTDEV"
| "NFULA_IFINDEX_PHYSINDEV"
| "NFULA_IFINDEX_PHYSOUTDEV"
| "NFULA_HWADDR"
| "NFULA_PAYLOAD"
| "NFULA_PREFIX"
| "NFULA_UID"
| "NFULA_SEQ"
| "NFULA_SEQ_GLOBAL"
| "NFULA_GID"
| "NFULA_HWTYPE"
| "NFULA_HWHEADER"
| "NFULA_HWLEN"
if Some(12) > freebsd_ver =>
{
true
}

// Added in FreeBSD 14
"SPACECTL_DEALLOC" if Some(14) > freebsd_ver => true,

Expand Down
89 changes: 85 additions & 4 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,12 @@ pub const SO_TS_DEFAULT: ::c_int = SO_TS_REALTIME_MICRO;
pub const SO_TS_CLOCK_MAX: ::c_int = SO_TS_MONOTONIC;

/// netlink constants

// sys/socket.h
pub const AF_NETLINK: ::c_int = 38;
pub const PF_NETLINK: ::c_int = AF_NETLINK;

// netlink/netlink.h
pub const SOL_NETLINK: ::c_int = 270;
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
Expand All @@ -3077,10 +3083,34 @@ 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 NLM_F_REQUEST: ::c_int = 0x01;
pub const NLM_F_MULTI: ::c_int = 0x02;
pub const NLM_F_ACK: ::c_int = 0x04;
pub const NLM_F_ECHO: ::c_int = 0x08;
pub const NLM_F_DUMP_INTR: ::c_int = 0x10;
pub const NLM_F_DUMP_FILTERED: ::c_int = 0x20;
//
pub const NLM_F_ROOT: ::c_int = 0x100;
pub const NLM_F_MATCH: ::c_int = 0x200;
pub const NLM_F_ATOMIC: ::c_int = 0x400;
pub const NLM_F_DUMP: ::c_int = NLM_F_ROOT | NLM_F_MATCH;
//
pub const NLM_F_REPLACE: ::c_int = 0x100;
pub const NLM_F_EXCL: ::c_int = 0x200;
pub const NLM_F_CREATE: ::c_int = 0x400;
pub const NLM_F_APPEND: ::c_int = 0x800;
//
pub const NLM_F_NONREC: ::c_int = 0x100;
//
pub const NLM_F_CAPPED: ::c_int = 0x100;
pub const NLM_F_ACK_TLVS: ::c_int = 0x200;
//
pub const NLMSG_NOOP: ::c_int = 0x1;
pub const NLMSG_ERROR: ::c_int = 0x2;
pub const NLMSG_DONE: ::c_int = 0x3;
pub const NLMSG_OVERRUN: ::c_int = 0x4;
//
pub const NETLINK_ROUTE: ::c_int = 0;
pub const NETLINK_UNUSED: ::c_int = 1;
pub const NETLINK_USERSOCK: ::c_int = 2;
Expand All @@ -3098,6 +3128,57 @@ 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;
//
const NL_ITEM_ALIGN_SIZE: ::c_int = 4; // mem::size_of::<u32>(); FIXME accept new dep?
pub const NLMSG_ALIGNTO: ::c_int = NL_ITEM_ALIGN_SIZE;

// netlink/netlink_generic.h
pub const CTRL_CMD_UNSPEC: ::c_int = 0;
pub const CTRL_CMD_NEWFAMILY: ::c_int = 1;
pub const CTRL_CMD_DELFAMILY: ::c_int = 2;
pub const CTRL_CMD_GETFAMILY: ::c_int = 3;
pub const CTRL_CMD_NEWOPS: ::c_int = 4;
pub const CTRL_CMD_DELOPS: ::c_int = 5;
pub const CTRL_CMD_GETOPS: ::c_int = 6;
pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7;
pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8;
pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9;
pub const CTRL_CMD_GETPOLICY: ::c_int = 10;
//
pub const CTRL_ATTR_UNSPEC: ::c_int = 0;
pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1;
pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2;
pub const CTRL_ATTR_VERSION: ::c_int = 3;
pub const CTRL_ATTR_HDRSIZE: ::c_int = 4;
pub const CTRL_ATTR_MAXATTR: ::c_int = 5;
pub const CTRL_ATTR_OPS: ::c_int = 6;
pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7;
pub const CTRL_ATTR_POLICY: ::c_int = 8;
pub const CTRL_ATTR_OP_POLICY: ::c_int = 9;
pub const CTRL_ATTR_OP: ::c_int = 10;
//
pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0;
pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1;
pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2;

// pcap/nflog.h
pub const NFULA_PACKET_HDR: ::c_int = 1;
pub const NFULA_MARK: ::c_int = 2;
pub const NFULA_TIMESTAMP: ::c_int = 3;
pub const NFULA_IFINDEX_INDEV: ::c_int = 4;
pub const NFULA_IFINDEX_OUTDEV: ::c_int = 5;
pub const NFULA_IFINDEX_PHYSINDEV: ::c_int = 6;
pub const NFULA_IFINDEX_PHYSOUTDEV: ::c_int = 7;
pub const NFULA_HWADDR: ::c_int = 8;
pub const NFULA_PAYLOAD: ::c_int = 9;
pub const NFULA_PREFIX: ::c_int = 10;
pub const NFULA_UID: ::c_int = 11;
pub const NFULA_SEQ: ::c_int = 12;
pub const NFULA_SEQ_GLOBAL: ::c_int = 13;
pub const NFULA_GID: ::c_int = 14;
pub const NFULA_HWTYPE: ::c_int = 15;
pub const NFULA_HWHEADER: ::c_int = 16;
pub const NFULA_HWLEN: ::c_int = 17;

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

0 comments on commit 4d98ade

Please sign in to comment.