nix
nix copied to clipboard
feat: add support for DSCP and TTL / Hop Limit
What does this PR do
This PR improves the support for setting and retrieving of IP headers values for
- Incoming packets IPv4 TTL (IP_RECVTTL)
- Incoming packets IPv6 Hop Limit (IPV6_RECVHOPLIMIT)
- Outgoing and incoming packets IPv4 DSCP (IP_TOS)
- Outgoing and incoming packets IPv6 DSCP (IPV6_RECVTCLASS)
It includes the socket options and the appropriate control messages for sendmsg and recvmsg.
Note: I am not 100% sure I understand correctly the cfg values and feature flags of nix, so they could be set wrongly in the PR.
Checklist:
- [x] I have read
CONTRIBUTING.md - [x] I have written necessary tests and rustdoc comments
- [x] A change log has been added if this PR modifies nix's API
Hi, thanks for the PR! Sorry for the late response!
Note: I am not 100% sure I understand correctly the cfg values and feature flags of nix, so they could be set wrongly in the PR.
For the cfg for targets (OSes), see https://github.com/nix-rust/nix/blob/5fde28e209032e1714e726b3c38ac787315a6e52/build.rs#L20-L27
Hi, thanks for the PR! Sorry for the late response!
Thanks a lot for the review and don't worry about the timing :)
I'll address the comments and publish a new version!
Note: I am not 100% sure I understand correctly the cfg values and feature flags of nix, so they could be set wrongly in the PR.
For the cfg for targets (OSes), see
https://github.com/nix-rust/nix/blob/5fde28e209032e1714e726b3c38ac787315a6e52/build.rs#L20-L27
The code we have right now does not build on freebsd 14 because
error[E0531]: cannot find unit struct, unit variant or constant `IP_RECVTTL` in crate `libc`
--> src/sys/socket/mod.rs:1018:38
|
1018 | (libc::IPPROTO_IP, libc::IP_RECVTTL) => {
| ^^^^^^^^^^ help: a constant with a similar name exists: `IP_RECVTOS`
|
::: /.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.155/src/unix/bsd/freebsdlike/freebsd/mod.rs:3685:1
|
3685 | pub const IP_RECVTOS: ::c_int = 68;
| ----------------------------- similarly named constant `IP_RECVTOS` defined here
I think we need to enable RECVTTL only on linux.
The code we have right now does not build on freebsd 14 because
error[E0531]: cannot find unit struct, unit variant or constant `IP_RECVTTL` in crate `libc` --> src/sys/socket/mod.rs:1018:38 | 1018 | (libc::IPPROTO_IP, libc::IP_RECVTTL) => { | ^^^^^^^^^^ help: a constant with a similar name exists: `IP_RECVTOS` | ::: /.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.155/src/unix/bsd/freebsdlike/freebsd/mod.rs:3685:1 | 3685 | pub const IP_RECVTOS: ::c_int = 68; | ----------------------------- similarly named constant `IP_RECVTOS` defined hereI think we need to enable RECVTTL only on linux.
On FreeBSD, IP_RECVTTL should be used, it is available on FreeBSD, our CI says it does not exist because the Rust libc crate does not include it, we need to add this constant to the libc crate.
Update: PR filed https://github.com/rust-lang/libc/pull/3750
Update: PR merged, we can use the libc from git now:
libc = { git = "https://github.com/rust-lang/libc", branch = "libc-0.2", features = ["extra_traits"] }
I am moving this back to draft, while I find some time to finish to implement the changes and fix all the tests.
HI @crisidev, would you like to finish this? That type thing should be easy to deal with as we know the type used by the OS kernel:)
Hey, sorry, life got in the middle.. I'd love to finish this, but I am finally on holidays for a couple of weeks. I will be able to restart working on this in the second week of August if that's ok..
but I am finally on holidays for a couple of weeks. I will be able to restart working on this in the second week of August if that's ok..
Yeah, that is totally fine, enjoy you holiday, we all have a life😁
but I am finally on holidays for a couple of weeks. I will be able to restart working on this in the second week of August if that's ok..
Yeah, that is totally fine, enjoy you holiday, we all have a life😁
I found some time during a lazy Sunday and I am trying to finish this 😄
CI is making my life very hard right now, I'll try to fix it and move this to non draft.
I think I am done fixing CI issues. I had to disable the tests for IPTOS / IPV6TCLASS on mips since they return bogus values and I don't have a good way to troubleshoot it.
@SteveLauC first of all, thanks for all the patient comments, I really appreciate the help. I think this is ready for review now!
Well, sorry for so many comments, I hope they won't affect your holiday:)
Most of them are trivial
cfgissues, so should be easy to fix
Please don't you worry about this. I am quite new to this crate and without your help, I would be able to make a meaningful contribution. At the end, you did most of the work, I am really glad this is moving forward thanks to your help.
I'll try to fix everything today, I think it start to look good, apologies for the mess I did with cfg flags.
I think I could use another review now :)
Thanks!