net: support marking accepting TCP sockets
authorLorenzo Colitti <lorenzo@google.com>
Wed, 26 Mar 2014 04:03:12 +0000 (13:03 +0900)
committerJohn Stultz <john.stultz@linaro.org>
Tue, 16 Feb 2016 21:51:43 +0000 (13:51 -0800)
commitd3bdc5a2122fffb635a1c7323a25fe3578d0cc23
tree0fc9530e3adb51d6cc24acb384f434f9f877013b
parent72fc8653dc090a65c330ffd7bf3e7dda1271ffe0
net: support marking accepting TCP sockets

When using mark-based routing, sockets returned from accept()
may need to be marked differently depending on the incoming
connection request.

This is the case, for example, if different socket marks identify
different networks: a listening socket may want to accept
connections from all networks, but each connection should be
marked with the network that the request came in on, so that
subsequent packets are sent on the correct network.

This patch adds a sysctl to mark TCP sockets based on the fwmark
of the incoming SYN packet. If enabled, and an unmarked socket
receives a SYN, then the SYN packet's fwmark is written to the
connection's inet_request_sock, and later written back to the
accepted socket when the connection is established.  If the
socket already has a nonzero mark, then the behaviour is the same
as it is today, i.e., the listening socket's fwmark is used.

Black-box tested using user-mode linux:

- IPv4/IPv6 SYN+ACK, FIN, etc. packets are routed based on the
  mark of the incoming SYN packet.
- The socket returned by accept() is marked with the mark of the
  incoming SYN packet.
- Tested with syncookies=1 and syncookies=2.

Change-Id: I26bc1eceefd2c588d73b921865ab70e4645ade57
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
Documentation/networking/ip-sysctl.txt