]> git.baikalelectronics.ru Git - kernel.git/commit
net: support marking accepting TCP sockets
authorLorenzo Colitti <lorenzo@google.com>
Tue, 13 May 2014 17:17:35 +0000 (10:17 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 13 May 2014 22:35:09 +0000 (18:35 -0400)
commit7c9e98a19869f31aa54afee8b69e3933fad006d4
treeb8040290a249b8242767c1bb7f433deb40b4e6e0
parent5082e40f127daf56709af38d148a39454d6e02a2
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.

Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/inet_sock.h
include/net/netns/ipv4.h
net/ipv4/inet_connection_sock.c
net/ipv4/syncookies.c
net/ipv4/sysctl_net_ipv4.c
net/ipv4/tcp_ipv4.c
net/ipv6/inet6_connection_sock.c
net/ipv6/syncookies.c
net/ipv6/tcp_ipv6.c