Commit 1e2391b9 authored by yupeng's avatar yupeng Committed by Stefan Bader

net: call sk_dst_reset when set SO_DONTROUTE

BugLink: https://bugs.launchpad.net/bugs/1818797

[ Upstream commit 0fbe82e6 ]

after set SO_DONTROUTE to 1, the IP layer should not route packets if
the dest IP address is not in link scope. But if the socket has cached
the dst_entry, such packets would be routed until the sk_dst_cache
expires. So we should clean the sk_dst_cache when a user set
SO_DONTROUTE option. Below are server/client python scripts which
could reprodue this issue:

server side code:

==========================================================================
import socket
import struct
import time

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 9000))
s.listen(1)
sock, addr = s.accept()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_DONTROUTE, struct.pack('i', 1))
while True:
    sock.send(b'foo')
    time.sleep(1)
==========================================================================

client side code:
==========================================================================
import socket
import time

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('server_address', 9000))
while True:
    data = s.recv(1024)
    print(data)
==========================================================================
Signed-off-by: default avataryupeng <yupeng0921@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 649b4734
...@@ -733,6 +733,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -733,6 +733,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
break; break;
case SO_DONTROUTE: case SO_DONTROUTE:
sock_valbool_flag(sk, SOCK_LOCALROUTE, valbool); sock_valbool_flag(sk, SOCK_LOCALROUTE, valbool);
sk_dst_reset(sk);
break; break;
case SO_BROADCAST: case SO_BROADCAST:
sock_valbool_flag(sk, SOCK_BROADCAST, valbool); sock_valbool_flag(sk, SOCK_BROADCAST, valbool);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment