Skip to content
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

*BSD: Add ioctls for BPF/network interface operations #3838

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nathaniel-bennett
Copy link
Contributor

@nathaniel-bennett nathaniel-bennett commented Aug 16, 2024

Adds a few additional structs for BPF operations (bpf_version, bpf_stat, bpf_zbuf) as well as ioctl constants. Adds constants used for creating/manipulating network interfaces via ioctls.

Resolves #3626

@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2024

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2024

Some changes occurred in OpenBSD module

cc @semarie

Some changes occurred in OpenBSD module

cc @semarie

Copy link
Contributor

@semarie semarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on OpenBSD, the test suite fails, see the remark inlined.

else, some values seems wrong:

bad SIOCAIFADDR_IN6 value at byte 2: rust: 32 (0x20) != c 128 (0x80)
bad SIOCDIFADDR_IN6 value at byte 3: rust: 128 (0x80) != c 129 (0x81)
bad SIOCSIFBRDADDR value at byte 3: rust: 192 (0xc0) != c 128 (0x80)
bad SIOCSIFFLAGS value at byte 3: rust: 192 (0xc0) != c 128 (0x80)
bad SIOCAIFADDR value at byte 2: rust: 32 (0x20) != c 64 (0x40)
bad SIOCIFCREATE value at byte 3: rust: 192 (0xc0) != c 128 (0x80)

src/unix/bsd/netbsdlike/openbsd/mod.rs Show resolved Hide resolved
src/unix/bsd/netbsdlike/openbsd/mod.rs Show resolved Hide resolved
src/unix/bsd/netbsdlike/mod.rs Outdated Show resolved Hide resolved
libc-test/semver/openbsd.txt Outdated Show resolved Hide resolved
libc-test/semver/openbsd.txt Show resolved Hide resolved
@nathaniel-bennett
Copy link
Contributor Author

Resolves #3626

Copy link
Contributor

@semarie semarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. still some fixes needed.

libc-test/semver/openbsd.txt Show resolved Hide resolved
src/unix/bsd/netbsdlike/mod.rs Outdated Show resolved Hide resolved
@tgross35
Copy link
Contributor

tgross35 commented Aug 17, 2024

@semarie you may want to put up a proposal at some point in rust-lang/rust to promote one of the OpenBSD targets to Tier2 if there is sufficient demand, not sure if that has been brought up before. This would let us start testing it in CI here.

Copy link
Contributor

@semarie semarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for OpenBSD. thanks !

@nathaniel-bennett
Copy link
Contributor Author

@rustbot label stable-nominated

@rustbot rustbot added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Aug 21, 2024
@nathaniel-bennett
Copy link
Contributor Author

Looks like this has been approved by semarie, just needs to be merged @tgross35

@tgross35
Copy link
Contributor

tgross35 commented Sep 1, 2024

This is labeled S-waiting-on-review so it is already in my queue. I am just trying to get the branch branches better in sync and fix some testing things before I merge more new features (and this is a bigger-ish change, anything where I need to dig through multiple platforms' headers to cross check takes forever. If you have links to headers or docs that helps a ton!)

@nathaniel-bennett
Copy link
Contributor Author

Here are all the applicable header files for this PR:

Header file for MacOS SIO* const definitions:
https://github.com/apple-open-source/macos/blob/47164d22c8d9bbf590e605d0a77fcae4fd35bea0/xnu/bsd/sys/sockio.h

Header file for MacOS BIO* const, bpf_* struct definitions:
https://github.com/apple-open-source/macos/blob/47164d22c8d9bbf590e605d0a77fcae4fd35bea0/xnu/bsd/net/bpf.h#L170

Header file for MacOS RTA_*/RTAX_* definitions:
https://github.com/apple-open-source/macos/blob/47164d22c8d9bbf590e605d0a77fcae4fd35bea0/xnu/bsd/net/route.h#L238

Header file for MacOS SIO*_IN6 const definitions:
https://github.com/apple-open-source/macos/blob/47164d22c8d9bbf590e605d0a77fcae4fd35bea0/xnu/bsd/netinet6/in6_var.h#L588

Header file for MacOS u_int typedef:
https://github.com/apple-open-source/macos/blob/47164d22c8d9bbf590e605d0a77fcae4fd35bea0/xnu/bsd/sys/_types/_u_int.h#L28

Header file for DragonFly BIO* const, bpf_* struct definitions:
https://github.com/DragonFlyBSD/DragonFlyBSD/blob/83e7061fc08c2bcaeaaa75ad86aff4605a2904ea/sys/net/bpf.h#L104

Header file for DragonFly RTA_*/RTAX_* const definitions:
https://github.com/DragonFlyBSD/DragonFlyBSD/blob/83e7061fc08c2bcaeaaa75ad86aff4605a2904ea/sys/net/route.h#L277

Header file for DragonFly SIO* const definitions:
https://github.com/DragonFlyBSD/DragonFlyBSD/blob/83e7061fc08c2bcaeaaa75ad86aff4605a2904ea/sys/sys/sockio.h#L39

Header file for DragonFly SIO*_IN6 const definitions:
https://github.com/DragonFlyBSD/DragonFlyBSD/blob/83e7061fc08c2bcaeaaa75ad86aff4605a2904ea/sys/netinet6/in6_var.h#L406

Header file for FreeBSD BIO* const, bpf_* struct definitions:
https://github.com/freebsd/freebsd-src/blob/2b7f2890a812eb09dccaa8069483566a3b292338/sys/net/bpf.h#L120

Header file for FreeBSD RTA_*/RTAX_* const definitions:
https://github.com/freebsd/freebsd-src/blob/2b7f2890a812eb09dccaa8069483566a3b292338/sys/net/route.h#L318

Header file for FreeBSD SIO* const definitions:
https://github.com/freebsd/freebsd-src/blob/2b7f2890a812eb09dccaa8069483566a3b292338/sys/sys/sockio.h#L70

Header file for FreeBSD SIO*_IN6 const definitions:
https://github.com/openbsd/src/blob/202e2461a0d9a8e3abe70503423141a09ea1c4f4/sys/netinet6/in6_var.h#L272

Header file for OpenBSD BIO* const, bpf_* struct definitions:
https://github.com/openbsd/src/blob/202e2461a0d9a8e3abe70503423141a09ea1c4f4/sys/net/bpf.h#L114

Header file for OpenBSD RTA_*/RTAX_* const definitions:
https://github.com/openbsd/src/blob/202e2461a0d9a8e3abe70503423141a09ea1c4f4/sys/net/route.h#L310

Header file for OpenBSD SIO* const definitions:
https://github.com/openbsd/src/blob/202e2461a0d9a8e3abe70503423141a09ea1c4f4/sys/sys/sockio.h#L41

Header file for OpenBSD SIO*_IN6 const definitions:
https://github.com/openbsd/src/blob/202e2461a0d9a8e3abe70503423141a09ea1c4f4/sys/netinet6/in6_var.h#L272

Header file for NetBSD BIO* const, bpf_* struct definitions:
https://github.com/NetBSD/src/blob/c973030f42bbf6ada20cd8850b840349a4971a75/sys/net/bpf.h#L109

Header file for NetBSD RTA_*/RTAX_* const definitions:
https://github.com/NetBSD/src/blob/c973030f42bbf6ada20cd8850b840349a4971a75/sys/net/route.h#L325

Header files for NetBSD SIO* const definitions:
https://github.com/NetBSD/src/blob/c973030f42bbf6ada20cd8850b840349a4971a75/sys/sys/sockio.h#L128

Header files for NetBSD SIO*_IN6 const definitions:
https://github.com/NetBSD/src/blob/c973030f42bbf6ada20cd8850b840349a4971a75/sys/netinet6/in6_var.h#L383

Compiling these has made me realize I put a lot more into this PR than I initially thought (scope creep from adding MacOS-only definitions to including all BSD variants)--sorry about the premature ping! This should definitely take some time to review.

@nathaniel-bennett nathaniel-bennett marked this pull request as draft October 1, 2024 12:33
@nathaniel-bennett
Copy link
Contributor Author

I've converted this to a draft as I discovered that different flavors of BSD have differing sizes for ifreq and similar structs. A portion of the value of ioctl codes are meant to convey the size of the struct they are passing, so those won't work. I found this out after setting up CI for OpenBSD/NetBSD/DragonFlyBSD on a Rust library I'm writing.

I'll eventually get around to adding the _IOC, _IOW and _IOWR macros as constant functions in this PR, and then defining the values of IOCTL keys based on that.

@bors
Copy link
Contributor

bors commented Oct 15, 2024

☔ The latest upstream changes (presumably #3945) made this pull request unmergeable. Please resolve the merge conflicts.

@tgross35
Copy link
Contributor

I think this has some work left based on the above, or is there something specific needed from me?

I'll eventually get around to adding the _IOC, _IOW and _IOWR macros as constant functions in this PR, and then defining the values of IOCTL keys based on that.

We should get these with #3865, assuming that lands in the near future.

@rustbot author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author stable-nominated This PR should be considered for cherry-pick to libc's stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing SIOC ioctl constants on MacOS
5 participants