Skip to content

Add netfilter constants to Linux #911

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

Merged
merged 1 commit into from
Jan 31, 2018
Merged

Conversation

faern
Copy link
Contributor

@faern faern commented Jan 30, 2018

Constants and enums from netfilter.h and nf_tables.h.

I was not really sure what to do with the enums, for example nf_tables_msg_types. But since I could not find a C enum mapped into a Rust enum in this crate I assumed you wanted them as constants instead.

I also wanted to get the nf_inet_addr union in here. But I did not find any unions in this crate so I was not sure how you would prefer it represented.

There are of course a billion more netfilter constants and types to map. But this is a good start.

@alexcrichton
Copy link
Member

Thanks! Looksl ike CI may be failing though?

@faern faern force-pushed the add-netfilter branch 2 times, most recently from 87591a5 to 5739364 Compare January 30, 2018 16:13
@faern
Copy link
Contributor Author

faern commented Jan 30, 2018

Yup. Was trying to figure out why.
Do you happen to know why the netlink definitions are not included under musl? Can't I communicate over netlink if I statically link? 😕

@faern faern force-pushed the add-netfilter branch 3 times, most recently from 29db4bc to 7a8a5ec Compare January 30, 2018 17:00
@alexcrichton
Copy link
Member

Hm I wonder if it's a missing header file? I'm not too familiar with netlink unfortunately :(

In any case it should be fine to only define the constants on glibc (but still linux) if necessary!

@faern faern force-pushed the add-netfilter branch 2 times, most recently from 907219e to b4d6885 Compare January 30, 2018 21:59
@faern
Copy link
Contributor Author

faern commented Jan 30, 2018

Yes, it seems nf_tables.h is not available with musl. Why, I don't know, but I'm going to skip it for now at least.

Now there is a lot of duplication between Linux and Android. But I don't find any other place where you share values between them, so I guess this is the preferred method.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jan 31, 2018

📌 Commit 4d5ed47 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jan 31, 2018

⌛ Testing commit 4d5ed47 with merge c9e67b8...

bors added a commit that referenced this pull request Jan 31, 2018
Add netfilter constants to Linux

Constants and enums from [`netfilter.h`] and [`nf_tables.h`].

I was not really sure what to do with the enums, for example `nf_tables_msg_types`. But since I could not find a C enum mapped into a Rust enum in this crate I assumed you wanted them as constants instead.

I also wanted to get the `nf_inet_addr` union in here. But I did not find any unions in this crate so I was not sure how you would prefer it represented.

There are of course a billion more netfilter constants and types to map. But this is a good start.

[`netfilter.h`]: https://github.com/torvalds/linux/blob/ead751507de86d90fa250431e9990a8b881f713c/include/uapi/linux/netfilter.h
[`nf_tables.h`]: https://github.com/torvalds/linux/blob/ead751507de86d90fa250431e9990a8b881f713c/include/uapi/linux/netfilter/nf_tables.h
@bors
Copy link
Contributor

bors commented Jan 31, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing c9e67b8 to master...

@bors bors merged commit 4d5ed47 into rust-lang:master Jan 31, 2018
@faern faern deleted the add-netfilter branch January 31, 2018 09:16
bors added a commit that referenced this pull request Feb 26, 2018
Add netfilter/nftables fields

Adding a few missing `NF_` constants to more complete the story around that header. Then most importantly add a lot of `NFT_` constants needed in my nftables library. Some were added back in #911, but as the library grew I realized I needed more constants.
bors added a commit that referenced this pull request Apr 30, 2021
Make netfilter constants available for musl Linux targets

The netfilter constants added in #911 and #926 are currently only available for Linux targets using glibc because they weren't available in the musl-sanitized kernel headers at the time these PRs were made.

With current versions of the sanitized headers, these constants are available, and this PR moves them to `unix/linux_like/linux/mod.rs` so that they can be used on targets using musl libc.

The kernel header version currently set in `ci/install_musl.sh` already supports these constants, but has different values for e.g. `NFT_TABLE_MAXNAMELEN` than the ones that were already defined for glibc. It seems like the maximum name length for various netfilter objects has been changed in the kernel (the respective commits are [1](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/uapi/linux/netfilter/nf_tables.h?id=e46abbcc05aa8a16b0e7f5c94e86d11af9aa2770) [2](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/uapi/linux/netfilter/nf_tables.h?id=b7263e071aba736cea9e71cdf2e76dfa7aebd039) [3](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/uapi/linux/netfilter/nf_tables.h?id=387454901bd62022ac1b04e15bd8d4fcc60bbed4) and [4](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/uapi/linux/netfilter/nf_tables.h?id=615095752100748e221028fc96163c2b78185ae4)). To match these values with the ones that were already defined, this PR also updates the used kernel header version in `ci/install_musl.sh`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants