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

Setting TOS/DSCP when using Reverse Mode (--tos with -R) #638

Closed
brandon-shannon opened this issue Sep 13, 2017 · 10 comments · Fixed by #1427
Closed

Setting TOS/DSCP when using Reverse Mode (--tos with -R) #638

brandon-shannon opened this issue Sep 13, 2017 · 10 comments · Fixed by #1427
Assignees
Labels
bug:tos Issues related to issues with TOS/DSCP bits bug

Comments

@brandon-shannon
Copy link

brandon-shannon commented Sep 13, 2017

Context

  • Version of iperf3: 3.0.11

  • Hardware: Macbook Pro

Bug Report

  • ACTUAL Behavior
    When doing a Reverse test (-R), the --tos value isn't used to tag traffic from the server to the client, making the TOS setting irrelevant. Only traffic from the client to the server is tagged, but on a reverse test that's not the important bit.

  • EXPECTED Behavior
    Packets sent from server to client would be tagged correctly.

  • Steps to Reproduce

  1. iperf3 -c 104.131.128.139 -p 2222 --tos 72 -R
  2. Look at the packets in WireShark
@brandon-shannon
Copy link
Author

For what it's worth, I can see that the client tells the server the ToS/DSCP value to use. It looks like the server just doesn't do it. Here's a capture using UDP via WireShark.

{"udp":true,"omit":0,"time":10,"parallel":1,"reverse":true,"len":1448,"bandwidth":1048576,"pacing_timer":1000,"TOS":184,"client_version":"3.2"}

@gwbrown
Copy link

gwbrown commented Sep 17, 2017

This is an odd bug. If an iperf server is started in its default dual IPv6/IPv4 mode, the server will fail to set the appropriate DSCP value on outgoing packets in IPv4 streams. A workaround is to set the -4 flag on the server to force IPv4-only mode if you are running IPv4 tests.

In detail, the socket on the server is opened in IPv6 mode in order to be able to accept both IPv6 and IPv4 connections per this comment in iperf_tcp.c. When the server goes to set the DSCP option on the socket for a specific test here in iperf_api.c, it detects that the socket is an IPv6 socket and sets the appropriate IPv6 option even when a test is using IPv4. I've done some testing, and if iperf_api.c is modified to attempt to set both the IPv6 and IPv4 DSCP options when the socket is detected as IPv6, the behavior will be correct (although if the connection is really an IPv6 connection, the call to set the appropriate IPv4 option will fail).

I'm going to do some more testing and intend to submit a pull request with this fix.

@bmah888
Copy link
Contributor

bmah888 commented Sep 18, 2017

Thanks @brandon-shannon and @gwbrown for reporting and looking into this!

I haven't had a chance to try reproducing the problem yet, but this sounds reasonable. Just to confirm, this but was originally reported against iperf-3.0.11 but it's also occurring on 3.2, correct?

@bmah888 bmah888 added the bug label Sep 18, 2017
@brandon-shannon
Copy link
Author

That is correct. We upgraded and tried a second time to see if it had been addressed. It is still an issue in 3.2.

@bmah888
Copy link
Contributor

bmah888 commented Sep 18, 2017

OK, thanks for verifying. I tested this behavior on a couple of (dual-stack) VMs and I've been able to reproduce the problem. Along the way I discovered issue #639, which I would encourage you to watch out for when testing any solutions for this bug. I think the solution for #639 is pretty straightforward but I won't be able to look at this for a little while.

@O-ring
Copy link

O-ring commented May 22, 2019

this bug is also present in 3.6 version running on Linux kernel 64bit

@FireballDWF
Copy link

In #889 I added a comment showing where this scenario works as expected when --udp is specified, but not when default of TCP packets used.

@bmah888 bmah888 added the bug:tos Issues related to issues with TOS/DSCP bits label Jul 6, 2020
@SirAchmed
Copy link

Hi, it's 2020 and I'm still facing this issue on iperf3 3.7 on macOS even with the -4 flag. Anyone managed to find a solution or a workaround?

@disprosium8
Copy link
Contributor

I looked into this briefly and the issue does indeed seem to stem from allowing v4 connections on v6 sockets and IPV6_TCLASS setsockopt not applying to v4 connections on a v6 socket domain. If we check for mapped IPv4 addresses as per RFC4291 and then use IP_TOS setsockopt the TOS/DSCP get set on the reverse connection as expected. I have an ugly way to do this in 4995680 that works but needs a more elegant approach. I have not found a clean solution yet other than forcing v4 with -4 flag.

@bmah888
Copy link
Contributor

bmah888 commented Jan 15, 2021

@disprosium8 : Agreed this is kinda ugly, but there might not be any better way. There does not appear to be any kind of pre-defined predicate that you can use to look for a mapped IPv4 address. If you have a fixed version of the test (like you implied in the comment) I'd be happy to just have you roll with that.

disprosium8 added a commit to disprosium8/iperf that referenced this issue Feb 19, 2021
begins to address (esnet#889) by also setting TOS/DSCP on TCP 3-way
handshake.
@bmah888 bmah888 linked a pull request Nov 23, 2022 that will close this issue
swlars added a commit that referenced this issue Nov 23, 2022
Fixes issue #638. Allow setting of TOS/DHCP for reverse tests. Thanks to @disprosium8 for the initial patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:tos Issues related to issues with TOS/DSCP bits bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants