Discussion:
IP_RECVTOS
Michael Tuexen
2012-06-05 20:33:54 UTC
Permalink
Dear all,

there is currently no way to receive the TOS byte of a received UDP/IPv4 packet.
The attached patch adds a socket option (IP_RECVTOS) which you can use
to get a cmsg of type (IP_RECVTOS) which contains the TOS byte. Much like
IP_RECVTTL does for TTL. Any comments/objections? If there are none, I would
like to commit this to head soon.

Best regards
Michael
Adrian Chadd
2012-06-05 21:37:31 UTC
Permalink
Hi,

can you please wrap this up in a PR so it's not lost?

thanks,


Adrian
Post by Michael Tuexen
Dear all,
there is currently no way to receive the TOS byte of a received UDP/IPv4 packet.
The attached patch adds a socket option (IP_RECVTOS) which you can use
to get a cmsg of type (IP_RECVTOS) which contains the TOS byte. Much like
IP_RECVTTL does for TTL. Any comments/objections? If there are none, I would
like to commit this to head soon.
Best regards
Michael
_______________________________________________
http://lists.freebsd.org/mailman/listinfo/freebsd-net
Michael Tuexen
2012-06-05 22:11:08 UTC
Permalink
Post by Adrian Chadd
Hi,
can you please wrap this up in a PR so it's not lost?
Why should it get lost? If there are no objections, I'll commit it. If there
are, we'll see if we can resolve it.

Best regards
Michael
Post by Adrian Chadd
thanks,
Adrian
Post by Michael Tuexen
Dear all,
there is currently no way to receive the TOS byte of a received UDP/IPv4 packet.
The attached patch adds a socket option (IP_RECVTOS) which you can use
to get a cmsg of type (IP_RECVTOS) which contains the TOS byte. Much like
IP_RECVTTL does for TTL. Any comments/objections? If there are none, I would
like to commit this to head soon.
Best regards
Michael
_______________________________________________
http://lists.freebsd.org/mailman/listinfo/freebsd-net
Adrian Chadd
2012-06-06 06:50:46 UTC
Permalink
Post by Michael Tuexen
Why should it get lost? If there are no objections, I'll commit it. If there
are, we'll see if we can resolve it.
Oh sweet, you can do that? Yes, I really would like to see this
particular feature in FreeBSD.

Thanks so much for coding it up!

Do you think it's worth adding an example or two which uses this?



Adrian
Michael Tuexen
2012-06-06 07:20:37 UTC
Permalink
Post by Adrian Chadd
Post by Michael Tuexen
Why should it get lost? If there are no objections, I'll commit it. If there
are, we'll see if we can resolve it.
Oh sweet, you can do that? Yes, I really would like to see this
particular feature in FreeBSD.
Thanks so much for coding it up!
Do you think it's worth adding an example or two which uses this?
Not sure how to add an example, but I've also a paragraph going into
man ip:

If the IP_RECVTOS option is enabled on a SOCK_DGRAM socket, the
recvmsg(2) call will return the IP TOS (type of service) field for a UDP
datagram. The msg_control field in the msghdr structure points to a
buffer that contains a cmsghdr structure followed by the TOS. The cms-
ghdr fields have the following values:

cmsg_len = CMSG_LEN(sizeof(u_char))
cmsg_level = IPPROTO_IP
cmsg_type = IP_RECVTOS

Best regards
Michael
Post by Adrian Chadd
Adrian
Adrian Chadd
2012-06-06 08:15:24 UTC
Permalink
Well,

* Is it usable on a TCP socket?
* Is it usable on an outbound TCP socket (ie, where the receive end
has set the ToS bits on the received ToS), regardless of what you've
set for the sending ToS?
* Does the receive TOS change during the lifetime of a TCP connection?
If so, can this fetch it?
* Example code? :)



Adrian
Michael Tuexen
2012-06-06 10:34:43 UTC
Permalink
Post by Adrian Chadd
Well,
* Is it usable on a TCP socket?
No. The main application (I see) is to access the ECN bits. In the TCP case,
ECN is handled in the kernel, so there is no need to deal with them in
userland.
On the other hand, TCP is byte stream oriented, so I don't see any packet
boundaries. However, the TOS is per packet. Much like the TTL. This is also
limited to SOCK_DGRAM.
Post by Adrian Chadd
* Is it usable on an outbound TCP socket (ie, where the receive end
has set the ToS bits on the received ToS), regardless of what you've
set for the sending ToS?
You can use the IP_TOS socket option for outgoing traffic.
Post by Adrian Chadd
* Does the receive TOS change during the lifetime of a TCP connection?
The sender can change it.
Post by Adrian Chadd
If so, can this fetch it?
No. The IP_RECVTOS is similar to the IPV6_RECVTCLASS socket option.
Post by Adrian Chadd
* Example code? :)
Attached.

Best regards
Michael
Adrian Chadd
2012-06-06 17:17:56 UTC
Permalink
Hi,

For TCP, I've seen the network layer change things (eg setting bits on
incoming traffic to mark which interface it came in on), so you can't
guarantee the outbound ToS == inbound ToS.



Adrian
Michael Tuexen
2012-06-06 17:54:26 UTC
Permalink
Post by Adrian Chadd
Hi,
For TCP, I've seen the network layer change things (eg setting bits on
incoming traffic to mark which interface it came in on), so you can't
guarantee the outbound ToS == inbound ToS.
I've not said that inbound == outbound... I just wanted to make clear
that there is a socket option of setting the TOS byte for outgoing
traffic. The TCP stack might overwrite the ECN bits...

I need the IP_RECVTOS functionality for implementing a transport stack supporting
ECN in userland, actually running the SCTP kernel sources (with some glue code)
in userland on top of UDP...

Best regards
Michael
Post by Adrian Chadd
Adrian
Philip Prindeville
2012-06-06 19:13:02 UTC
Permalink
Post by Michael Tuexen
Post by Adrian Chadd
Hi,
For TCP, I've seen the network layer change things (eg setting bits on
incoming traffic to mark which interface it came in on), so you can't
guarantee the outbound ToS == inbound ToS.
I've not said that inbound == outbound... I just wanted to make clear
that there is a socket option of setting the TOS byte for outgoing
traffic. The TCP stack might overwrite the ECN bits...
I need the IP_RECVTOS functionality for implementing a transport stack supporting
ECN in userland, actually running the SCTP kernel sources (with some glue code)
in userland on top of UDP...
Best regards
Michael
What about UDT? Can you patch that as well?

For certain services (like backups or AFP), it might be useful for a server to be able to detect a QoS-friendly client and reciprocate in kind.

-Philip
Michael Tuexen
2012-06-07 07:27:14 UTC
Permalink
Post by Philip Prindeville
Post by Michael Tuexen
Post by Adrian Chadd
Hi,
For TCP, I've seen the network layer change things (eg setting bits on
incoming traffic to mark which interface it came in on), so you can't
guarantee the outbound ToS == inbound ToS.
I've not said that inbound == outbound... I just wanted to make clear
that there is a socket option of setting the TOS byte for outgoing
traffic. The TCP stack might overwrite the ECN bits...
I need the IP_RECVTOS functionality for implementing a transport stack supporting
ECN in userland, actually running the SCTP kernel sources (with some glue code)
in userland on top of UDP...
Best regards
Michael
What about UDT? Can you patch that as well?
The UDT implementation can use IP_RECVTOS option, however I don't have the
time to look into this for the UDT implementation.

Best regards
Michael
Post by Philip Prindeville
For certain services (like backups or AFP), it might be useful for a server to be able to detect a QoS-friendly client and reciprocate in kind.
-Philip
_______________________________________________
http://lists.freebsd.org/mailman/listinfo/freebsd-net
Adrian Chadd
2012-06-06 22:18:07 UTC
Permalink
*nod* sure, I just want to be sure that it's clearly documented what
the option does.

If it just does UDP for now and not TCP, then so be it, as long as
it's documented that way.



Adrian
Michael Tuexen
2012-06-07 07:29:42 UTC
Permalink
Post by Adrian Chadd
*nod* sure, I just want to be sure that it's clearly documented what
the option does.
If it just does UDP for now and not TCP, then so be it, as long as
it's documented that way.
I think the suggested modification to the man page of IP, which I sent
earlier to list, makes this clear.

Best regards
Michael
Post by Adrian Chadd
Adrian
Philip Prindeville
2012-06-07 18:24:44 UTC
Permalink
It might be nice to add a semantic that says, "when accepting connections, match their TOS"... possibly adding ranges of permitted TOS values.
Post by Adrian Chadd
*nod* sure, I just want to be sure that it's clearly documented what
the option does.
If it just does UDP for now and not TCP, then so be it, as long as
it's documented that way.
Adrian
Michael Tuexen
2012-06-07 20:09:14 UTC
Permalink
Post by Philip Prindeville
It might be nice to add a semantic that says, "when accepting connections, match their TOS"... possibly adding ranges of permitted TOS values.
... I would leave the matching to the application.
However, the suggested patch only supports UDP sockets.

Best regards
Michael
Post by Philip Prindeville
Post by Adrian Chadd
*nod* sure, I just want to be sure that it's clearly documented what
the option does.
If it just does UDP for now and not TCP, then so be it, as long as
it's documented that way.
Adrian
_______________________________________________
http://lists.freebsd.org/mailman/listinfo/freebsd-net
Loading...