freebsd(13.2): add netlink/netlink.h support - #5326
Conversation
This comment has been minimized.
This comment has been minimized.
653f197 to
0b6bb29
Compare
This comment has been minimized.
This comment has been minimized.
|
The API looks fine from a quick skim, but since there is no hurry, I think it may be worth trying to add support to ctest first so the tricky test setup isn't needed. (It's useful otherwise too.) Sketched some of that up at #5344 |
|
Noted. Since you already pinged some contributor on that issue, I'll wait and |
|
Could you try adding a separate |
|
Either author or blocked, depending on whether that works. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a6a6a8d to
266acdf
Compare
This comment has been minimized.
This comment has been minimized.
| @@ -0,0 +1,6 @@ | |||
| //! Directory: `netlink/` | |||
| //! | |||
| //! <https://github.com/freebsd/freebsd-src/tree/df9d6403caa6426e92f5e100602f4d2be474bbae/sys/netlink> | |||
There was a problem hiding this comment.
Fyi, no need to permalink these kind of files since we do want to see updates, and the file locations are usually stable enough. As long as there's a permalink in the commit message to show us what it actually looked like at that point in time.
There was a problem hiding this comment.
You mean the files for the upstream directories only, or also the files
referring to the upstream header files?
There was a problem hiding this comment.
For any of the files in new, regular links rather than permalinks are fine. Just makes it easier to see the most recent version without them going out of sync.
|
It seems having separate invocations gets the job done just fine. Still, that Those seem to me like they're going to need extending (though it's notably less |
This comment has been minimized.
This comment has been minimized.
|
I haven't tried this but do things just work™️ if the semver tests have lines like |
7f883df to
1306298
Compare
This comment has been minimized.
This comment has been minimized.
net/netlink.h supportnetlink/netlink.h support
4608465 to
b0e2869
Compare
This comment has been minimized.
This comment has been minimized.
@tgross35 They do. Just cleaned up commit history as all tests seem to pass now. |
2b52cf7 to
30133e0
Compare
| pub(crate) use freebsd::*; | ||
| // FIXME(1.0,remove): glob reexport should be the default. | ||
| pub use freebsd::netlink; | ||
| pub(crate) use freebsd::{ | ||
| net, | ||
| netinet6, | ||
| sys, | ||
| unistd, | ||
| }; |
There was a problem hiding this comment.
There was a problem hiding this comment.
Not quite, but something similar does work. The current reexports have been
changed to instead have first the "regular" modules, followed by a reexport of
the freebsd::netlink module.
The latter itself contains two submodules, netlink and netlink_generic,
which are now also used in the SemVer tests, as well as being the only ones
exposed to downstream crates.
There was a problem hiding this comment.
I think it would be preferable to have a single module since that's how most of the crate is. If there's no easy then it would be fine with just:
pub mod netlink {
use super::freebsd;
pub use freebsd::netlink::*;
pub use freebsd::netlink_generic::*;
}There was a problem hiding this comment.
Done. For the sake of keeping a close matching between our module tree and
upstream's directory tree under sys, I've gone with the above solution.
| netlink::netlink::NETLINK_ADD_MEMBERSHIP | ||
| netlink::netlink::NETLINK_AUDIT | ||
| netlink::netlink::NETLINK_BROADCAST_ERROR | ||
| netlink::netlink::NETLINK_CAP_ACK | ||
| netlink::netlink::NETLINK_CONNECTOR | ||
| netlink::netlink::NETLINK_DNRTMSG | ||
| netlink::netlink::NETLINK_DROP_MEMBERSHIP | ||
| netlink::netlink::NETLINK_EXT_ACK | ||
| netlink::netlink::NETLINK_FIB_LOOKUP | ||
| netlink::netlink::NETLINK_FIREWALL | ||
| netlink::netlink::NETLINK_GENERIC | ||
| netlink::netlink::NETLINK_GET_STRICT_CHK | ||
| netlink::netlink::NETLINK_IP6_FW | ||
| netlink::netlink::NETLINK_ISCSI | ||
| netlink::netlink::NETLINK_KOBJECT_UEVENT | ||
| netlink::netlink::NETLINK_LISTEN_ALL_NSID | ||
| netlink::netlink::NETLINK_LIST_MEMBERSHIPS | ||
| netlink::netlink::NETLINK_NETFILTER | ||
| netlink::netlink::NETLINK_NFLOG | ||
| netlink::netlink::NETLINK_NO_ENOBUFS | ||
| netlink::netlink::NETLINK_PKTINFO | ||
| netlink::netlink::NETLINK_ROUTE | ||
| netlink::netlink::NETLINK_RX_RING | ||
| netlink::netlink::NETLINK_SELINUX | ||
| netlink::netlink::NETLINK_SOCK_DIAG | ||
| netlink::netlink::NETLINK_TX_RING | ||
| netlink::netlink::NETLINK_UNUSED | ||
| netlink::netlink::NETLINK_USERSOCK | ||
| netlink::netlink::NETLINK_XFRM | ||
| netlink::netlink::NLMSG_ALIGNTO | ||
| netlink::netlink::NLMSG_DONE | ||
| netlink::netlink::NLMSG_ERROR | ||
| netlink::netlink::NLMSG_NOOP | ||
| netlink::netlink::NLMSG_OVERRUN | ||
| netlink::netlink::NLM_F_ACK | ||
| netlink::netlink::NLM_F_ACK_TLVS | ||
| netlink::netlink::NLM_F_APPEND | ||
| netlink::netlink::NLM_F_ATOMIC | ||
| netlink::netlink::NLM_F_CAPPED | ||
| netlink::netlink::NLM_F_CREATE | ||
| netlink::netlink::NLM_F_DUMP | ||
| netlink::netlink::NLM_F_DUMP_FILTERED | ||
| netlink::netlink::NLM_F_DUMP_INTR | ||
| netlink::netlink::NLM_F_ECHO | ||
| netlink::netlink::NLM_F_EXCL | ||
| netlink::netlink::NLM_F_MATCH | ||
| netlink::netlink::NLM_F_MULTI | ||
| netlink::netlink::NLM_F_NONREC | ||
| netlink::netlink::NLM_F_REPLACE | ||
| netlink::netlink::NLM_F_REQUEST | ||
| netlink::netlink::NLM_F_ROOT | ||
| netlink::netlink::NL_ITEM_ALIGN_SIZE | ||
| netlink::netlink::SOL_NETLINK |
There was a problem hiding this comment.
It would be better if we can keep all this directly within a netlink module. In the exports, perhaps an in-file mod netlink { pub use ... }
There was a problem hiding this comment.
I believe that's now fixed. The freebsd::netlink module exposed both netlink
and netlink_generic submodules, so I instead changed the reexport in
src/new/mod.rs to have the inner two modules exported.
Not everything is within a single netlink module, but at least we have a
shortened path.
| 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); |
There was a problem hiding this comment.
Sharing skips isn't intentional, why does this happen?
There was a problem hiding this comment.
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 now
shallow copy semantics of that type to avoid calling anew ctest_cfg() for
netlink_cfg.
This then needs resetting to the "defaults," because otherwise some skipping
functions that we do call with netlink_cfg but not with cfg end up affecting
cfg.
Footnotes
There was a problem hiding this comment.
Sort of, but there's no shallow copy. I guess the Rc<dyn Fn()> might look that way but it's just letting closures be used from multiple places like function pointers - it's not like cloning to a TestGenerator then adding skips to one means that the other TestGenerator gets those same skips.
(The pattern for something like that would be field: Rc<RefCell<Box<dyn Fn()>>> or field: Rc<RefCell<Vec<Box<dyn Fn()>>>.)
So you can delete the .skip_union(|_| false) ...
There was a problem hiding this comment.
Done, but I've still got questions.
How is there not? TestGenerator automatically derives Clone and that would
make the inner Vec<Skip> use its Clone implementation, which itself depends
on the Clone impl of Skip. Skip is just an alias to a Rc<...>, so it
would call into the Clone impl for Rc<T: ?Sized>, which will yield a shallow
copy of T.
Granted, you'd still need some form of interior mutability to change those
skips, but I don't think skips are made to be "modified" once "registered."
What am I missing?
30133e0 to
f9649f6
Compare
This comment has been minimized.
This comment has been minimized.
f9649f6 to
1654258
Compare
This comment has been minimized.
This comment has been minimized.
1654258 to
4d8855f
Compare
This comment has been minimized.
This comment has been minimized.
745bf15 to
be6cc74
Compare
|
@rustbot ready |
There was a problem hiding this comment.
Cc @asomers, could you take a look when you get the chance?
| 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); |
There was a problem hiding this comment.
Sort of, but there's no shallow copy. I guess the Rc<dyn Fn()> might look that way but it's just letting closures be used from multiple places like function pointers - it's not like cloning to a TestGenerator then adding skips to one means that the other TestGenerator gets those same skips.
(The pattern for something like that would be field: Rc<RefCell<Box<dyn Fn()>>> or field: Rc<RefCell<Vec<Box<dyn Fn()>>>.)
So you can delete the .skip_union(|_| false) ...
| let mut netlink_cfg = cfg.clone(); | ||
| headers!(netlink_cfg, "netlink/netlink.h",); | ||
| netlink_cfg | ||
| .skip_struct(|ty| !matches!(ty.ident(), "sockaddr_nl")) |
There was a problem hiding this comment.
Nit: put this in a is_netlink_struct function. Not super useful on its own but it's consistent with is_netlink_const and easier to expand if needed, and will the "sockaddr_nl" => true, more obvious.
| @@ -0,0 +1,6 @@ | |||
| //! Directory: `netlink/` | |||
| //! | |||
| //! <https://github.com/freebsd/freebsd-src/tree/df9d6403caa6426e92f5e100602f4d2be474bbae/sys/netlink> | |||
There was a problem hiding this comment.
For any of the files in new, regular links rather than permalinks are fine. Just makes it easier to see the most recent version without them going out of sync.
| 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; |
There was a problem hiding this comment.
Looks like these could all be c_enum! to match source
| pub(crate) use freebsd::*; | ||
| // FIXME(1.0,remove): glob reexport should be the default. | ||
| pub use freebsd::netlink; | ||
| pub(crate) use freebsd::{ | ||
| net, | ||
| netinet6, | ||
| sys, | ||
| unistd, | ||
| }; |
There was a problem hiding this comment.
I think it would be preferable to have a single module since that's how most of the crate is. If there's no easy then it would be fine with just:
pub mod netlink {
use super::freebsd;
pub use freebsd::netlink::*;
pub use freebsd::netlink_generic::*;
}This is an early subset of the Netlink interface, but it proves sufficient for monitoring changes in IP addresses. Coverage can be extended later as needed. See [^1] and [^2]. [^1]: <https://github.com/freebsd/freebsd-src/blob/df9d6403caa6426e92f5e100602f4d2be474bbae/sys/netlink/netlink.h> [^2]: <https://github.com/freebsd/freebsd-src/blob/df9d6403caa6426e92f5e100602f4d2be474bbae/sys/netlink/netlink_generic.h> A small workaround has been necessary in the SemVer tests to ensure we get the right paths to the public submodules for the `netlink/netlink.h` and `netlink/netling_generic.h` interfaces. Those symbols now are prepended a `netlink` super module path. Signed-off-by: Yann Dirson <yann.dirson@vates.fr> Co-authored-by: Yann Dirson <yann.dirson@vates.fr>
Add specific test for `netlink/netlink.h` bindings. This is necessary to avoid conflicts with the bindings for `net/if_mib.h`. libc-test now builds two different `TestGenerator` instances. One of the instances builds tests for the same set of bindings as before this patchset, while the other builds tests only for the `netlink/netlink.h` bindings.
be6cc74 to
09bbab3
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Description
This PR updates #3201 with merge conflicts resolved and follows the new plan at
1.
The patch adds support for
netlink.hinterfaces in OpenBSD, where there's anitem resolution conflict if we expose the Rust bindings alongside those of
if_mib.h. This set of APIs is "scoped" in C because they live on separateheaders. In rust-lang/libc, we reexport all items at the root crate level, which
makes item resolution fail.
Note this depends on #5325. It won't pass tests but it will build. This is
because the test templates will gather all items in a single file, so item
resolution fails. We can't really skip these items altogether from the tests, so
it may just be necessary to extend
ctestto allow skipping module-specificRust items.
Checklist
libc-test/semverhave been updated*LASTor*MAXhave the standarddoc comment
cargo test -p libc-test --target mytarget); especiallyrelevant for platforms that may not be checked in CI
@rustbot label +stable-nominated
Footnotes
https://github.com/rust-lang/libc/pull/3201#issuecomment-4736374182 ↩