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

tcp,udp: set TOS (TCLASS) for IPv6 sockets #1218

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

maximilianfridrich
Copy link
Contributor

No description provided.

@sreimers
Copy link
Member

Unsure if IPV6_TCLASS is available on windows.

https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options

I think some other systems also does not support this, so something like this Check should be added:

#if defined(IPV6_TCLASS)
...

@maximilianfridrich
Copy link
Contributor Author

Good point. Thank you @sreimers. Done.

@sreimers sreimers added this to the v3.19.0 milestone Dec 4, 2024
@alfredh
Copy link
Contributor

alfredh commented Dec 7, 2024

Would it be possible to add a small testcase for TOS ?

it would be enough with a simple testcase with UDP/TCP socket, set the TOS fields,
sends a couple of packets in a loop.

@maximilianfridrich
Copy link
Contributor Author

I will look into it.

@sreimers sreimers marked this pull request as draft December 11, 2024 10:26
@maximilianfridrich maximilianfridrich force-pushed the tos_ipv6 branch 3 times, most recently from 1cff992 to d037a5f Compare December 12, 2024 14:57
@maximilianfridrich
Copy link
Contributor Author

@alfredh I managed to create a working test with a custom UDP listener which uses recvmsg and struct cmsghdr to obtain information from the incoming IP packets. However, it turns out that this low-level socket stuff (< layer 4) is very platform dependent and I did not manage to write a test which works on all supported platforms (Windows, MAC).

I don't think it is worth putting a ton of time into this, since this new IPv6 addition is very simple and unlikely to break things (in part thanks to the #ifdefs.).

I hope this is okay. Attached is a patch with my working test (works on Linux).
test-udp-Add-TOS-test.patch.txt

@maximilianfridrich maximilianfridrich marked this pull request as ready for review December 12, 2024 14:59
src/udp/udp.c Outdated Show resolved Hide resolved
@sreimers
Copy link
Member

However, it turns out that this low-level socket stuff

It's enough to ensure tos functions are executed, no need for real low level packet checks.

@maximilianfridrich
Copy link
Contributor Author

It's enough to ensure tos functions are executed, no need for real low level packet checks.

Thank you, I just realized that there could be value in that too and I have just added tests for that. Done.

test/udp.c Outdated Show resolved Hide resolved
@maximilianfridrich maximilianfridrich force-pushed the tos_ipv6 branch 2 times, most recently from 8203057 to 5921fee Compare December 12, 2024 15:42
@maximilianfridrich
Copy link
Contributor Author

Seems like the setsockopt call fails on some Windows systems. Do you have any idea @sreimers ?

Probably the

#if defined(IPV6_TCLASS) && !defined(WIN32)

is not restrictive enough.

@sreimers
Copy link
Member

Seems like the setsockopt call fails on some Windows systems. Do you have any idea @sreimers ?

Will try to reproduce.

@alfredh
Copy link
Contributor

alfredh commented Dec 12, 2024

A simple test sending some packets with TOS set is better than nothing ...
No need to inspect incoming IP-packets ...


err = tcp_settos(tt->ts, 184);
err |= tcp_settos(tt->ts, 120);
TEST_ERR(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

why is TOS set on the same tcp server two times ?

is the TOS field working for TCP server or connection ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why is TOS set on the same tcp server two times ?

Mistake, removed.

is the TOS field working for TCP server or connection ?

In this test, it is set for all incoming connections on the listening (server) TCP socket. With tcp_conn_settos we could also set it per connection.

test/udp.c Outdated Show resolved Hide resolved
@maximilianfridrich
Copy link
Contributor Author

Probably the #if defined(IPV6_TCLASS) && !defined(WIN32) is not restrictive enough.

Actually, the test fails already in the IPv4 case, so I guess the TOS setting functions have never worked reliably on Windows systems. It turns out that per default, Windows does not allow applications to set the TOS value (if I understand this resource correctly).

Should I simply skip the test for Windows systems, since the outcome is dependent on the Windows registry settings? Or does anyone have a better idea how to proceed?

@alfredh
Copy link
Contributor

alfredh commented Dec 16, 2024

It should be fine to skip that test for Windows...

@maximilianfridrich
Copy link
Contributor Author

It should be fine to skip that test for Windows...

Done. Let me know if it's okay the way I did it.

@alfredh
Copy link
Contributor

alfredh commented Dec 18, 2024

looks good to me ... should we merge it ?

@maximilianfridrich
Copy link
Contributor Author

Yes, I'm all for it.

@sreimers sreimers merged commit a6825bd into baresip:main Dec 18, 2024
38 checks passed
@maximilianfridrich maximilianfridrich deleted the tos_ipv6 branch December 19, 2024 06:26
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