Bug 260119 - [sctp] Not inheriting the DSCP/TOS socket option
Summary: [sctp] Not inheriting the DSCP/TOS socket option
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Michael Tuexen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-29 14:31 UTC by Albin
Modified: 2021-12-10 10:48 UTC (History)
2 users (show)

See Also:
tuexen: mfc-stable13+


Attachments
Test files for reproducing the issue (4.31 KB, application/x-zip-compressed)
2021-11-29 14:33 UTC, Albin
no flags Details
Pcaps for different DSCP/TOS scenarios (6.96 KB, application/x-zip-compressed)
2021-11-29 14:34 UTC, Albin
no flags Details
Pcaps for DSCP/TOS after fixes (2.51 KB, application/x-zip-compressed)
2021-12-05 12:15 UTC, Albin
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Albin 2021-11-29 14:31:42 UTC
I noticed that when setting DSCP/TOS on a server socket, it doesn't get inherited to socket from accept(). This is not stated anywhere in any RFCs as far as I know, but it is not consistent with how TCP sockets behaves.

There might be other socket options that are affected. I have made a summary for DSCP/TOS at least:

FreeBSD 12.2:
IPv4 TCP:  Not inherited
IPv6 TCP:  Inherited
IPv4 SCTP: Not inherited
IPv6 SCTP: Not inherited

FreeBSD 13.0:
IPv4 TCP:  Inherited
IPv6 TCP:  Inherited
IPv4 SCTP: Not inherited
IPv6 SCTP: Not inherited

Linux (lksctp):
IPv4 TCP:  Inherited
IPv6 TCP:  Inherited
IPv4 SCTP: Not inherited
IPv6 SCTP: Inherited

Seems like this was changed for IPV4 TCP between FreeBSD 12.2 and 13.0. I cannot find any ticket for that, but I think that the same design choice could be considered for SCTP as well.
Comment 1 Albin 2021-11-29 14:33:36 UTC
Created attachment 229794 [details]
Test files for reproducing the issue

I added some tests if it helps. They can be compiled using:
g++ -o client client.cpp utils.cpp
g++ -o server server.cpp utils.cpp

I have tested it in VMs with the SCTP module enabled. I have also added alias addresses to the loopback interface so that I could run both the server and client over the loopback interface.

These alias addresess were added:
127.0.0.2
127.0.0.3
127.0.0.4
127.0.0.5
127.0.0.6
127.0.0.7
::2
::3
::4
::5
::6
::7

The test can be started using:
./server --poll --ipv4 --sctp --test-dscp
./client --poll --ipv4 --sctp --test-dscp

IPv6 as well as TCP can be tested as well to compare the behavior.
Comment 2 Albin 2021-11-29 14:34:47 UTC
Created attachment 229795 [details]
Pcaps for different DSCP/TOS scenarios
Comment 3 commit-hook freebsd_committer 2021-12-03 21:45:01 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d79676fb1368f5acac5fd182363ea3f46fb3bd93

commit d79676fb1368f5acac5fd182363ea3f46fb3bd93
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-12-03 21:40:52 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2021-12-03 21:44:01 +0000

    sctp: inherit IP level socket options from listening socket

    Ensure that TTL and TOS values set on a listener get inheritet
    to the accepted sockets.

    PR:             260119
    MFC after:      1 week

 sys/netinet/sctp_pcb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
Comment 4 Michael Tuexen freebsd_committer 2021-12-03 21:55:20 UTC
The issue should be fixed.

Please note that setting the DSCP using the SCTP specific API as defined in
https://datatracker.ietf.org/doc/html/rfc6458#section-8.1.12
by using the IPPROTO_SCTP level socket option SCTP_PEER_ADDR_PARAMS should work on all SCTP implementations. The interaction with IPPROTO_IP and IPPROTO_IPV6 level socket options is not well defined...
Comment 5 commit-hook freebsd_committer 2021-12-04 18:17:20 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=54912d47b629807cefaed5b65a8f4e6d9bbbdbcf

commit 54912d47b629807cefaed5b65a8f4e6d9bbbdbcf
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-12-04 18:13:28 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2021-12-04 18:16:18 +0000

    sctp: unbreak NOINET6 builds.

    PR:             260119
    Reported by:    kostikbel
    MFC after:      1 week

 sys/netinet/sctp_pcb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
Comment 6 Albin 2021-12-05 12:15:50 UTC
Created attachment 229925 [details]
Pcaps for DSCP/TOS after fixes

I have tested this with your fixes and it works great. Thank you for the help!

I will check out the SCTP_PEER_ADDR_PARAMS socket option.
Comment 7 commit-hook freebsd_committer 2021-12-10 10:42:22 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=89bbc849888546bf8cd74c8356de70bc38cced8b

commit 89bbc849888546bf8cd74c8356de70bc38cced8b
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-12-03 21:40:52 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2021-12-10 10:40:59 +0000

    sctp: inherit IP level socket options from listening socket

    Ensure that TTL and TOS values set on a listener get inheritet
    to the accepted sockets.

    PR:             260119
    MFC after:      1 week

    (cherry picked from commit d79676fb1368f5acac5fd182363ea3f46fb3bd93)

 sys/netinet/sctp_pcb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
Comment 8 commit-hook freebsd_committer 2021-12-10 10:42:23 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c5f3adcce3862cb800d64ae8fd332183ba6eb268

commit c5f3adcce3862cb800d64ae8fd332183ba6eb268
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-12-04 18:13:28 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2021-12-10 10:41:44 +0000

    sctp: unbreak NOINET6 builds.

    PR:             260119
    Reported by:    kostikbel
    MFC after:      1 week

    (cherry picked from commit 54912d47b629807cefaed5b65a8f4e6d9bbbdbcf)

 sys/netinet/sctp_pcb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)