Skip to content

Commit 69678bc

Browse files
Paolo Abenidavem330
authored andcommitted
udp: fix SO_BINDTODEVICE
Damir reported a breakage of SO_BINDTODEVICE for UDP sockets. In absence of VRF devices, after commit fb74c27 ("net: ipv4: add second dif to udp socket lookups") the dif mismatch isn't fatal anymore for UDP socket lookup with non null sk_bound_dev_if, breaking SO_BINDTODEVICE semantics. This changeset addresses the issue making the dif match mandatory again in the above scenario. Reported-by: Damir Mansurov <[email protected]> Fixes: fb74c27 ("net: ipv4: add second dif to udp socket lookups") Fixes: 1801b57 ("net: ipv6: add second dif to udp socket lookups") Signed-off-by: Paolo Abeni <[email protected]> Acked-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0e8411e commit 69678bc

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

net/ipv4/udp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ static int compute_score(struct sock *sk, struct net *net,
401401
bool dev_match = (sk->sk_bound_dev_if == dif ||
402402
sk->sk_bound_dev_if == sdif);
403403

404-
if (exact_dif && !dev_match)
404+
if (!dev_match)
405405
return -1;
406-
if (sk->sk_bound_dev_if && dev_match)
406+
if (sk->sk_bound_dev_if)
407407
score += 4;
408408
}
409409

net/ipv6/udp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ static int compute_score(struct sock *sk, struct net *net,
148148
bool dev_match = (sk->sk_bound_dev_if == dif ||
149149
sk->sk_bound_dev_if == sdif);
150150

151-
if (exact_dif && !dev_match)
151+
if (!dev_match)
152152
return -1;
153-
if (sk->sk_bound_dev_if && dev_match)
153+
if (sk->sk_bound_dev_if)
154154
score++;
155155
}
156156

0 commit comments

Comments
 (0)