nix icon indicating copy to clipboard operation
nix copied to clipboard

feat: add support for DSCP and TTL / Hop Limit

Open crisidev opened this issue 1 year ago • 5 comments
trafficstars

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

crisidev avatar Jun 03 '24 17:06 crisidev

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

SteveLauC avatar Jun 10 '24 12:06 SteveLauC

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

crisidev avatar Jun 11 '24 09:06 crisidev

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.

crisidev avatar Jun 14 '24 13:06 crisidev

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.

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"] }

SteveLauC avatar Jun 15 '24 08:06 SteveLauC

I am moving this back to draft, while I find some time to finish to implement the changes and fix all the tests.

crisidev avatar Jun 17 '24 11:06 crisidev

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:)

SteveLauC avatar Jul 20 '24 01:07 SteveLauC

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..

crisidev avatar Jul 20 '24 12:07 crisidev

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😁

SteveLauC avatar Jul 20 '24 13:07 SteveLauC

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.

crisidev avatar Jul 21 '24 15:07 crisidev

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.

crisidev avatar Jul 21 '24 15:07 crisidev

@SteveLauC first of all, thanks for all the patient comments, I really appreciate the help. I think this is ready for review now!

crisidev avatar Jul 21 '24 16:07 crisidev

Well, sorry for so many comments, I hope they won't affect your holiday:)

Most of them are trivial cfg issues, 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.

crisidev avatar Jul 22 '24 08:07 crisidev

I think I could use another review now :)

crisidev avatar Jul 22 '24 15:07 crisidev

Thanks!

SteveLauC avatar Jul 22 '24 23:07 SteveLauC