-
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
Open
dybucc
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
dybucc:freebsd-netlink
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2471,6 +2471,94 @@ fn test_android(target: &str) { | |
| } | ||
|
|
||
| fn test_freebsd(target: &str) { | ||
| // 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!(target.contains("freebsd")); | ||
| let mut cfg = ctest_cfg(); | ||
|
|
||
|
|
@@ -2518,6 +2606,28 @@ fn test_freebsd(target: &str) { | |
| 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", | ||
|
|
@@ -2690,6 +2800,10 @@ fn test_freebsd(target: &str) { | |
|
|
||
| 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" | ||
|
|
@@ -2986,6 +3100,10 @@ fn test_freebsd(target: &str) { | |
|
|
||
| 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
+3103
to
+3105
Contributor
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 |
||
|
|
||
| // `procstat` is a private struct | ||
| "procstat" => true, | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #![allow(deprecated)] | ||
| #![allow(dead_code)] | ||
|
|
||
| #[cfg(target_os = "freebsd")] | ||
| #[allow(unused_imports)] | ||
| use libc::netlink::{ | ||
| 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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //! Header: `netlink/netlink_generic.h` | ||
| //! | ||
| //! <https://github.com/freebsd/freebsd-src/blob/df9d6403caa6426e92f5e100602f4d2be474bbae/sys/netlink/netlink_generic.h> | ||
|
|
||
| use crate::prelude::*; | ||
|
|
||
| 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; | ||
|
Comment on lines
+7
to
+33
Contributor
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. I think these aren't in the semver file |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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