From 4044a3f8f3b8deecc1b6b7e7750100fcaf010e52 Mon Sep 17 00:00:00 2001 From: "David S. Miller" Date: Tue, 7 Oct 2003 18:33:00 -0700 Subject: [PATCH] [UDP/TCP]: Fix binding conflict tests wrt. SO_BINDTODEVICE. --- net/ipv4/tcp_ipv4.c | 4 +++- net/ipv4/udp.c | 4 +++- net/ipv6/tcp_ipv6.c | 5 ++++- net/ipv6/udp.c | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 4529c0f2c8235..67ec90ce3d05e 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -188,7 +188,9 @@ static inline int tcp_bind_conflict(struct sock *sk, struct tcp_bind_bucket *tb) sk_for_each_bound(sk2, node, &tb->owners) { if (sk != sk2 && !ipv6_only_sock(sk2) && - sk->sk_bound_dev_if == sk2->sk_bound_dev_if) { + (!sk->sk_bound_dev_if || + !sk2->sk_bound_dev_if || + sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) { if (!reuse || !sk2->sk_reuse || sk2->sk_state == TCP_LISTEN) { struct inet_opt *inet2 = inet_sk(sk2); diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 2762e05487614..c0e4710a18c2e 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -176,7 +176,9 @@ gotit: if (inet2->num == snum && sk2 != sk && !ipv6_only_sock(sk2) && - sk2->sk_bound_dev_if == sk->sk_bound_dev_if && + (!sk2->bound_dev_if || + !sk->bound_dev_if || + sk2->sk_bound_dev_if == sk->sk_bound_dev_if) && (!inet2->rcv_saddr || !inet->rcv_saddr || inet2->rcv_saddr == inet->rcv_saddr) && diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index fc1b3e8837d9f..0e1ca9018f8ca 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -101,7 +101,10 @@ static inline int tcp_v6_bind_conflict(struct sock *sk, /* We must walk the whole port owner list in this case. -DaveM */ sk_for_each_bound(sk2, node, &tb->owners) { - if (sk != sk2 && sk->sk_bound_dev_if == sk2->sk_bound_dev_if && + if (sk != sk2 && + (!sk->sk_bound_dev_if || + !sk2->sk_bound_dev_if || + sk->sk_bound_dev_if == sk2->sk_bound_dev_if) && (!sk->sk_reuse || !sk2->sk_reuse || sk2->sk_state == TCP_LISTEN) && ipv6_rcv_saddr_equal(sk, sk2)) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 2ee6d5e557341..87f282f2f9cfc 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -112,7 +112,9 @@ gotit: &udp_hash[snum & (UDP_HTABLE_SIZE - 1)]) { if (inet_sk(sk2)->num == snum && sk2 != sk && - sk2->sk_bound_dev_if == sk->sk_bound_dev_if && + (!sk2->sk_bound_dev_if || + !sk->sk_bound_dev_if || + sk2->sk_bound_dev_if == sk->sk_bound_dev_if) && (!sk2->sk_reuse || !sk->sk_reuse) && ipv6_rcv_saddr_equal(sk, sk2)) goto fail; -- 2.53.0