Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieving TOS value on a TCP socket

I have a scenario where a client opens a TCP connection to a server after setting some IP TOS value (setsockopt(.., IP_TOS, ..). On the server I want to retrieve the received TOS value and set that on the socket so that the received TOS is reflected back on server-client packets.

The problem is, on the server side, how can I retrieve the TOS value received from the client? I can assume that the client will not change the TOS value during the entire session, so it is sufficient to get and set the TOS value once initially.

Setting IP_RECVTOS and using ancillary data works for UDP but not for TCP sockets. How can something similar be achieved on TCP sockets? getsockopt(2) with SO_PRIORITY or IP_TOS returns the configured values on the local socket. So if I did a setsockopt() locally then the getsockopt() reflects that value. It is not reflecting what is received on the network.

like image 811
SanjayT Avatar asked Jan 05 '12 01:01

SanjayT


1 Answers

The TOS value could change for every TCP datagram received.

So it's not a constant option to the receiving TCP socket.

From the latter one could conclude that it's not possible for the receiver to pull a value for TOS from the receiving TCP socket in terms of an option which's value might be read using getsockopt().

As there is no such feature like "ancillary messages" available for TCP the only way I see to find out what the sender set as TOS is to directly inspect the received TCP datagram's headers.

like image 126
alk Avatar answered Oct 20 '22 05:10

alk