net: ensure unbound stream socket to be chosen when not in a VRF
The commit a04a480d43
("net: Require exact match for TCP socket
lookups if dif is l3mdev") only ensures that the correct socket is
selected for packets in a VRF. However, there is no guarantee that
the unbound socket will be selected for packets when not in a VRF.
By checking for a device match in compute_score() also for the case
when there is no bound device and attaching a score to this, the
unbound socket is selected. And if a failure is returned when there
is no device match, this ensures that bound sockets are never selected,
even if there is no unbound socket.
Signed-off-by: Mike Manning <mmanning@vyatta.att-mail.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Tested-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
3c82a21f43
commit
e78190581a
@@ -235,6 +235,7 @@ static inline int compute_score(struct sock *sk, struct net *net,
|
||||
{
|
||||
int score = -1;
|
||||
struct inet_sock *inet = inet_sk(sk);
|
||||
bool dev_match;
|
||||
|
||||
if (net_eq(sock_net(sk), net) && inet->inet_num == hnum &&
|
||||
!ipv6_only_sock(sk)) {
|
||||
@@ -245,15 +246,12 @@ static inline int compute_score(struct sock *sk, struct net *net,
|
||||
return -1;
|
||||
score += 4;
|
||||
}
|
||||
if (sk->sk_bound_dev_if || exact_dif) {
|
||||
bool dev_match = (sk->sk_bound_dev_if == dif ||
|
||||
sk->sk_bound_dev_if == sdif);
|
||||
dev_match = inet_sk_bound_dev_eq(net, sk->sk_bound_dev_if,
|
||||
dif, sdif);
|
||||
if (!dev_match)
|
||||
return -1;
|
||||
score += 4;
|
||||
|
||||
if (!dev_match)
|
||||
return -1;
|
||||
if (sk->sk_bound_dev_if)
|
||||
score += 4;
|
||||
}
|
||||
if (sk->sk_incoming_cpu == raw_smp_processor_id())
|
||||
score++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user