Skip to content

linux: add missing SOL_* constants #228

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ fn main() {
cfg.header("linux/netlink.h");
cfg.header("linux/magic.h");

if !android {
cfg.header("netinet/udp.h");
cfg.header("netipx/ipx.h");
cfg.header("netax25/ax25.h");
cfg.header("netatalk/at.h");
cfg.header("netrose/rose.h");
cfg.header("netrom/netrom.h");
}

if !mips {
cfg.header("linux/quota.h");
}
Expand Down Expand Up @@ -289,6 +298,24 @@ fn main() {
"FILE_ATTRIBUTE_INTEGRITY_STREAM" |
"ERROR_NOTHING_TO_TERMINATE" if mingw => true,

// these are not in musl
"SOL_NETLINK" |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not in musl or glibc and should be removed from this list. Will handle.

"SOL_UDP" |
"SOL_AX25" |
"SOL_ATALK" |
"SOL_NETROM" |
"SOL_IPX" |
"SOL_ROSE" if musl => true,
Copy link
Member

Choose a reason for hiding this comment

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

Could these constants be perhaps non-MUSL? I guess they're defined in the kernel so the MUSL definitions shouldn't change in theory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bionic seems to be the only libc implementation that takes a reasonable approach (automating) to keeping constants like this from the kernel reasonably up-to-date (it would be nice if this crate could move toward a similar approach for appropriate items).

These constants get passed straight to the kernel and I do not see any potential conflict with musl. The kernel takes modification of constants like this very seriously, so I believe the risk of inclusion is extremely low. Without definitions like this in libc, they must be defined by downstream crates (possibly inconsistently).

I don't think that the failure of musl/glibc to provide a complete set of constants to the operating system should prevent us from doing so.


// these are not in glibc or musl yet (but they are in android)
"SOL_SCTP" |
"SOL_UDPLITE" |
"SOL_NETBEUI" |
"SOL_LLC" |
"SOL_DCCP" |
"SOL_NETLINK" |
"SOL_TIPC" if linux => true,
Copy link
Member

Choose a reason for hiding this comment

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

Hm I'm a little wary of including constants that aren't in glibc or musl yet. Perhaps these could be android-only for now? Or should we update glibc to start verifying them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working with glibc to verify these seems like it might be a reasonable approach although they probably move forward at a snails pace for fear of breaking existing code that has already defined constants missing from its headers (I found several major projects defining SOL_NETLINK themselves, some without an #ifndef check). That is, I think the lack of definition of these constants might have less to do with stability and more to do with the inability to have nice things when working in C.

Another angle would be to verify some definitions against the kernel headers. I don't see a good way of mixing glibc headers and kernel headers together, but having a separate set of tests which verify against kernel sources might have some legs.

Copy link
Member

Choose a reason for hiding this comment

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

Hm ok, I'm largely just wary to include such a large set of constants in the ignore list. This'd mean that they're never validated, and I don't necessarily trust architectures like MIPS to have all the same values for all the constants. It's ok if they're not tested on MUSL, but they should be tested somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. I'll see what I can come up with. I would be fine with dropping all of these as well except SOL_NETLINK if it comes to that. They are tested in Android, so there is some validation going on (but we do not validate Android on non-ARM).

Copy link
Member

Choose a reason for hiding this comment

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

Ok, sounds good to me!


"SIG_IGN" => true, // sighandler_t weirdness

// types on musl are defined a little differently
Expand Down
25 changes: 25 additions & 0 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,31 @@ pub const ST_IMMUTABLE: ::c_ulong = 512;
pub const ST_NOATIME: ::c_ulong = 1024;
pub const ST_NODIRATIME: ::c_ulong = 2048;

pub const SOL_IP: ::c_int = 0;
pub const SOL_TCP: ::c_int = 6;
pub const SOL_UDP: ::c_int = 17;
pub const SOL_IPV6: ::c_int = 41;
pub const SOL_ICMPV6: ::c_int = 58;
pub const SOL_SCTP: ::c_int = 132;
pub const SOL_UDPLITE: ::c_int = 136;
pub const SOL_RAW: ::c_int = 255;
pub const SOL_IPX: ::c_int = 256;
pub const SOL_AX25: ::c_int = 257;
pub const SOL_ATALK: ::c_int = 258;
pub const SOL_NETROM: ::c_int = 259;
pub const SOL_ROSE: ::c_int = 260;
pub const SOL_DECNET: ::c_int = 261;
pub const SOL_X25: ::c_int = 262;
pub const SOL_PACKET: ::c_int = 263;
pub const SOL_ATM: ::c_int = 264;
pub const SOL_AAL: ::c_int = 265;
pub const SOL_IRDA: ::c_int = 266;
pub const SOL_NETBEUI: ::c_int = 267;
pub const SOL_LLC: ::c_int = 268;
pub const SOL_DCCP: ::c_int = 269;
pub const SOL_NETLINK: ::c_int = 270;
pub const SOL_TIPC: ::c_int = 271;

pub const RTLD_NEXT: *mut ::c_void = -1i64 as *mut ::c_void;
pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void;
pub const RTLD_NODELETE: ::c_int = 0x1000;
Expand Down