-
Notifications
You must be signed in to change notification settings - Fork 1.3k
freebsd(13.2): add netlink/netlink.h support
#5326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2455,6 +2455,94 @@ fn test_android(t: &Target) { | |
| } | ||
|
|
||
| fn test_freebsd(t: &Target) { | ||
| // Ensures we have only one place where the `netlink/netlink.h` constants | ||
| // are checked in. This is used both when generating the full test suite, | ||
| // and when generating the `netlink`-specific test suite. | ||
| #[inline] | ||
| fn is_netlink_const(it: &ctest::Const) -> bool { | ||
| matches!( | ||
| it.ident(), | ||
| "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" | ||
| | "SOL_NETLINK" | ||
| | "NETLINK_ADD_MEMBERSHIP" | ||
| | "NETLINK_DROP_MEMBERSHIP" | ||
| | "NETLINK_PKTINFO" | ||
| | "NETLINK_BROADCAST_ERROR" | ||
| | "NETLINK_NO_ENOBUFS" | ||
| | "NETLINK_RX_RING" | ||
| | "NETLINK_TX_RING" | ||
| | "NETLINK_LISTEN_ALL_NSID" | ||
| | "NETLINK_LIST_MEMBERSHIPS" | ||
| | "NETLINK_CAP_ACK" | ||
| | "NETLINK_EXT_ACK" | ||
| | "NETLINK_GET_STRICT_CHK" | ||
| | "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" | ||
| | "NETLINK_FIREWALL" | ||
| | "NETLINK_SOCK_DIAG" | ||
| | "NETLINK_NFLOG" | ||
| | "NETLINK_XFRM" | ||
| | "NETLINK_SELINUX" | ||
| | "NETLINK_ISCSI" | ||
| | "NETLINK_AUDIT" | ||
| | "NETLINK_FIB_LOOKUP" | ||
| | "NETLINK_CONNECTOR" | ||
| | "NETLINK_NETFILTER" | ||
| | "NETLINK_IP6_FW" | ||
| | "NETLINK_DNRTMSG" | ||
| | "NETLINK_KOBJECT_UEVENT" | ||
| | "NETLINK_GENERIC" | ||
| | "NL_ITEM_ALIGN_SIZE" | ||
| | "NLMSG_ALIGNTO" | ||
| ) | ||
| } | ||
|
|
||
| assert!(t.freebsd()); | ||
| let mut cfg = ctest_cfg(); | ||
|
|
||
|
|
@@ -2502,6 +2590,28 @@ fn test_freebsd(t: &Target) { | |
| let freebsd14 = matches!(freebsd_ver, Some(n) if n >= 14); | ||
| let freebsd15 = matches!(freebsd_ver, Some(n) if n >= 15); | ||
|
|
||
| let mut netlink_cfg = cfg.clone(); | ||
| headers!(netlink_cfg, "netlink/netlink.h",); | ||
| netlink_cfg | ||
| .skip_struct(|ty| !matches!(ty.ident(), "sockaddr_nl")) | ||
| .skip_const(|c| !is_netlink_const(c)) | ||
| .skip_union(|_| true) | ||
| .skip_alias(|_| true) | ||
| .skip_static(|_| true) | ||
| .skip_fn(|_| true) | ||
| .skip_c_enum(|_| true); | ||
| ctest::generate_test(&mut netlink_cfg, "../src/lib.rs", "netlink_ctest_output.rs").unwrap(); | ||
|
|
||
| // We must restore the above sure-skips because `TestGenerator` shares skips | ||
| // between cloned instances (here `cfg` and `netlink_cfg`.) | ||
| cfg.skip_struct(|_| false) | ||
| .skip_const(|_| false) | ||
| .skip_union(|_| false) | ||
| .skip_alias(|_| false) | ||
| .skip_static(|_| false) | ||
| .skip_fn(|_| false) | ||
| .skip_c_enum(|_| false); | ||
|
|
||
| headers!( | ||
| cfg, | ||
| "aio.h", | ||
|
|
@@ -2674,6 +2784,10 @@ fn test_freebsd(t: &Target) { | |
|
|
||
| cfg.skip_const(move |constant| { | ||
| match constant.ident() { | ||
| // `netlink/netlink.h` constants. These are tests in a separate ctest | ||
| // invocation. | ||
| _ if is_netlink_const(constant) => true, | ||
|
|
||
| // These constants were introduced in FreeBSD 13: | ||
| "F_ADD_SEALS" | "F_GET_SEALS" | "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | ||
| | "F_SEAL_WRITE" | ||
|
|
@@ -2959,6 +3073,10 @@ fn test_freebsd(t: &Target) { | |
|
|
||
| cfg.skip_struct(move |struct_| { | ||
| match struct_.ident() { | ||
| // This is tested in a separate ctest invocation because some symbols | ||
| // `netlink/netlink.h` conflict with some other symbols from `net/if_mib.h`. | ||
| "sockaddr_nl" => true, | ||
|
Comment on lines
+3076
to
+3078
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this one needed still? I think we should be checking a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's still needed. Footnotes |
||
|
|
||
| // `procstat` is a private struct | ||
| "procstat" => true, | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #![allow(deprecated)] | ||
| #![allow(unused)] | ||
|
|
||
| #[cfg(target_os = "freebsd")] | ||
| #[allow(unused_imports)] | ||
| use libc::{ | ||
| netlink::*, | ||
| netlink_generic::*, | ||
| }; | ||
|
|
||
| #[cfg(target_os = "freebsd")] | ||
| include!(concat!(env!("OUT_DIR"), "/netlink_ctest_output.rs")); | ||
|
|
||
| #[cfg(not(target_os = "freebsd"))] | ||
| fn main() { | ||
| println!("PASSED 0 tests"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,5 +5,6 @@ | |
|
|
||
| pub(crate) mod net; | ||
| pub(crate) mod netinet6; | ||
| pub mod netlink; | ||
| pub(crate) mod sys; | ||
| pub(crate) mod unistd; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| //! Directory: `netlink/` | ||
| //! | ||
| //! <https://github.com/freebsd/freebsd-src/tree/main/sys/netlink> | ||
|
|
||
| pub mod netlink; | ||
| pub mod netlink_generic; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| //! Header: `netlink/netlink.h` | ||
| //! | ||
| //! <https://github.com/freebsd/freebsd-src/blob/df9d6403caa6426e92f5e100602f4d2be474bbae/sys/netlink/netlink.h> | ||
|
|
||
| use crate::prelude::*; | ||
|
|
||
| s! { | ||
| pub struct sockaddr_nl { | ||
| pub nl_len: u8, | ||
| pub nl_family: crate::sa_family_t, | ||
| nl_pad: Padding<u16>, | ||
| pub nl_pid: u32, | ||
| pub nl_groups: u32, | ||
| } | ||
| } | ||
|
|
||
| pub const SOL_NETLINK: c_int = 270; | ||
| pub const NETLINK_ADD_MEMBERSHIP: c_int = 1; | ||
| pub const NETLINK_DROP_MEMBERSHIP: c_int = 2; | ||
| pub const NETLINK_PKTINFO: c_int = 3; | ||
| pub const NETLINK_BROADCAST_ERROR: c_int = 4; | ||
| pub const NETLINK_NO_ENOBUFS: c_int = 5; | ||
| pub const NETLINK_RX_RING: c_int = 6; | ||
| pub const NETLINK_TX_RING: c_int = 7; | ||
| pub const NETLINK_LISTEN_ALL_NSID: c_int = 8; | ||
| 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 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; | ||
| pub const NETLINK_FIREWALL: c_int = 3; | ||
| pub const NETLINK_SOCK_DIAG: c_int = 4; | ||
| pub const NETLINK_NFLOG: c_int = 5; | ||
| pub const NETLINK_XFRM: c_int = 6; | ||
| pub const NETLINK_SELINUX: c_int = 7; | ||
| pub const NETLINK_ISCSI: c_int = 8; | ||
| pub const NETLINK_AUDIT: c_int = 9; | ||
| pub const NETLINK_FIB_LOOKUP: c_int = 10; | ||
| pub const NETLINK_CONNECTOR: c_int = 11; | ||
| pub const NETLINK_NETFILTER: c_int = 12; | ||
| 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; | ||
|
|
||
| pub const NL_ITEM_ALIGN_SIZE: c_int = size_of::<u32>() as c_int; | ||
| pub const NLMSG_ALIGNTO: c_int = NL_ITEM_ALIGN_SIZE; |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sharing skips isn't intentional, why does this happen?
View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A prior review comment 1 mentioned a recent patch that allows sharing skips
between instances of
TestGenerator. I assumed you wanted me to use the nowshallow copy semantics of that type to avoid calling anew
ctest_cfg()fornetlink_cfg.This then needs resetting to the "defaults," because otherwise some skipping
functions that we do call with
netlink_cfgbut not withcfgend up affectingcfg.Footnotes
https://github.com/rust-lang/libc/pull/5326#discussion_r3747219428 ↩