* [PATCH net-next 1/4] l2tp: remove redundant addr_len check in l2tp_ip_bind()
2017-01-06 19:03 [PATCH net-next 0/4] l2tp: cleanup socket lookup code in l2tp_ip and l2tp_ip6 Guillaume Nault
@ 2017-01-06 19:03 ` Guillaume Nault
2017-01-06 19:03 ` [PATCH net-next 2/4] l2tp: make __l2tp_ip*_bind_lookup() parameters 'const' Guillaume Nault
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Guillaume Nault @ 2017-01-06 19:03 UTC (permalink / raw)
To: netdev; +Cc: James Chapman, Chris Elston
addr_len's value has already been verified at this point.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
---
net/l2tp/l2tp_ip.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 3d73278b86ca..992761e721af 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -258,7 +258,7 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
if (!sock_flag(sk, SOCK_ZAPPED))
goto out;
- if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_l2tpip))
+ if (sk->sk_state != TCP_CLOSE)
goto out;
chk_addr_ret = inet_addr_type(net, addr->l2tp_addr.s_addr);
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net-next 2/4] l2tp: make __l2tp_ip*_bind_lookup() parameters 'const'
2017-01-06 19:03 [PATCH net-next 0/4] l2tp: cleanup socket lookup code in l2tp_ip and l2tp_ip6 Guillaume Nault
2017-01-06 19:03 ` [PATCH net-next 1/4] l2tp: remove redundant addr_len check in l2tp_ip_bind() Guillaume Nault
@ 2017-01-06 19:03 ` Guillaume Nault
2017-01-06 19:03 ` [PATCH net-next 3/4] l2tp: remove useless NULL check in __l2tp_ip*_bind_lookup() Guillaume Nault
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Guillaume Nault @ 2017-01-06 19:03 UTC (permalink / raw)
To: netdev; +Cc: James Chapman, Chris Elston
Add const qualifier wherever possible for __l2tp_ip_bind_lookup() and
__l2tp_ip6_bind_lookup().
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
---
net/l2tp/l2tp_ip.c | 4 ++--
net/l2tp/l2tp_ip6.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 992761e721af..e5686bf898f7 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -53,8 +53,8 @@ static struct sock *__l2tp_ip_bind_lookup(const struct net *net, __be32 laddr,
struct sock *sk;
sk_for_each_bound(sk, &l2tp_ip_bind_table) {
- struct inet_sock *inet = inet_sk(sk);
- struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk);
+ const struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk);
+ const struct inet_sock *inet = inet_sk(sk);
if (l2tp == NULL)
continue;
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 331ccf5a7bad..2f6be6ddc8cb 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -57,8 +57,8 @@ static inline struct l2tp_ip6_sock *l2tp_ip6_sk(const struct sock *sk)
return (struct l2tp_ip6_sock *)sk;
}
-static struct sock *__l2tp_ip6_bind_lookup(struct net *net,
- struct in6_addr *laddr,
+static struct sock *__l2tp_ip6_bind_lookup(const struct net *net,
+ const struct in6_addr *laddr,
const struct in6_addr *raddr,
int dif, u32 tunnel_id)
{
@@ -67,7 +67,7 @@ static struct sock *__l2tp_ip6_bind_lookup(struct net *net,
sk_for_each_bound(sk, &l2tp_ip6_bind_table) {
const struct in6_addr *sk_laddr = inet6_rcv_saddr(sk);
const struct in6_addr *sk_raddr = &sk->sk_v6_daddr;
- struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk);
+ const struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk);
if (l2tp == NULL)
continue;
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net-next 3/4] l2tp: remove useless NULL check in __l2tp_ip*_bind_lookup()
2017-01-06 19:03 [PATCH net-next 0/4] l2tp: cleanup socket lookup code in l2tp_ip and l2tp_ip6 Guillaume Nault
2017-01-06 19:03 ` [PATCH net-next 1/4] l2tp: remove redundant addr_len check in l2tp_ip_bind() Guillaume Nault
2017-01-06 19:03 ` [PATCH net-next 2/4] l2tp: make __l2tp_ip*_bind_lookup() parameters 'const' Guillaume Nault
@ 2017-01-06 19:03 ` Guillaume Nault
2017-01-06 19:03 ` [PATCH net-next 4/4] l2tp: rework socket comparison " Guillaume Nault
2017-01-07 3:19 ` [PATCH net-next 0/4] l2tp: cleanup socket lookup code in l2tp_ip and l2tp_ip6 David Miller
4 siblings, 0 replies; 6+ messages in thread
From: Guillaume Nault @ 2017-01-06 19:03 UTC (permalink / raw)
To: netdev; +Cc: James Chapman, Chris Elston
If "l2tp" was NULL, that'd mean "sk" is NULL too. This can't happen
since "sk" is returned by sk_for_each_bound().
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
---
net/l2tp/l2tp_ip.c | 3 ---
net/l2tp/l2tp_ip6.c | 3 ---
2 files changed, 6 deletions(-)
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index e5686bf898f7..499d3cdbfbc8 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -56,9 +56,6 @@ static struct sock *__l2tp_ip_bind_lookup(const struct net *net, __be32 laddr,
const struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
- if (l2tp == NULL)
- continue;
-
if ((l2tp->conn_id == tunnel_id) &&
net_eq(sock_net(sk), net) &&
!(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 2f6be6ddc8cb..7165b06d7b25 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -69,9 +69,6 @@ static struct sock *__l2tp_ip6_bind_lookup(const struct net *net,
const struct in6_addr *sk_raddr = &sk->sk_v6_daddr;
const struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk);
- if (l2tp == NULL)
- continue;
-
if ((l2tp->conn_id == tunnel_id) &&
net_eq(sock_net(sk), net) &&
(!sk_laddr || ipv6_addr_any(sk_laddr) || ipv6_addr_equal(sk_laddr, laddr)) &&
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next 4/4] l2tp: rework socket comparison in __l2tp_ip*_bind_lookup()
2017-01-06 19:03 [PATCH net-next 0/4] l2tp: cleanup socket lookup code in l2tp_ip and l2tp_ip6 Guillaume Nault
` (2 preceding siblings ...)
2017-01-06 19:03 ` [PATCH net-next 3/4] l2tp: remove useless NULL check in __l2tp_ip*_bind_lookup() Guillaume Nault
@ 2017-01-06 19:03 ` Guillaume Nault
2017-01-07 3:19 ` [PATCH net-next 0/4] l2tp: cleanup socket lookup code in l2tp_ip and l2tp_ip6 David Miller
4 siblings, 0 replies; 6+ messages in thread
From: Guillaume Nault @ 2017-01-06 19:03 UTC (permalink / raw)
To: netdev; +Cc: James Chapman, Chris Elston
Split conditions, so that each test becomes clearer.
Also, for l2tp_ip, check if "laddr" is 0. This prevents a socket from
binding to the unspecified address when other sockets are already bound
using the same device (if any), connection ID and namespace.
Same thing for l2tp_ip6: add ipv6_addr_any(laddr) and
ipv6_addr_any(raddr) tests to ensure that an IPv6 unspecified address
passed as parameter is properly treated a wildcard.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
---
net/l2tp/l2tp_ip.c | 24 +++++++++++++++++-------
net/l2tp/l2tp_ip6.c | 25 ++++++++++++++++++-------
2 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 499d3cdbfbc8..b07a859f21bd 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -56,13 +56,23 @@ static struct sock *__l2tp_ip_bind_lookup(const struct net *net, __be32 laddr,
const struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
- if ((l2tp->conn_id == tunnel_id) &&
- net_eq(sock_net(sk), net) &&
- !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
- (!inet->inet_daddr || !raddr || inet->inet_daddr == raddr) &&
- (!sk->sk_bound_dev_if || !dif ||
- sk->sk_bound_dev_if == dif))
- goto found;
+ if (!net_eq(sock_net(sk), net))
+ continue;
+
+ if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif)
+ continue;
+
+ if (inet->inet_rcv_saddr && laddr &&
+ inet->inet_rcv_saddr != laddr)
+ continue;
+
+ if (inet->inet_daddr && raddr && inet->inet_daddr != raddr)
+ continue;
+
+ if (l2tp->conn_id != tunnel_id)
+ continue;
+
+ goto found;
}
sk = NULL;
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 7165b06d7b25..4b06eb415f68 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -69,13 +69,24 @@ static struct sock *__l2tp_ip6_bind_lookup(const struct net *net,
const struct in6_addr *sk_raddr = &sk->sk_v6_daddr;
const struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk);
- if ((l2tp->conn_id == tunnel_id) &&
- net_eq(sock_net(sk), net) &&
- (!sk_laddr || ipv6_addr_any(sk_laddr) || ipv6_addr_equal(sk_laddr, laddr)) &&
- (!raddr || ipv6_addr_any(sk_raddr) || ipv6_addr_equal(sk_raddr, raddr)) &&
- (!sk->sk_bound_dev_if || !dif ||
- sk->sk_bound_dev_if == dif))
- goto found;
+ if (!net_eq(sock_net(sk), net))
+ continue;
+
+ if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif)
+ continue;
+
+ if (sk_laddr && !ipv6_addr_any(sk_laddr) &&
+ !ipv6_addr_any(laddr) && !ipv6_addr_equal(sk_laddr, laddr))
+ continue;
+
+ if (!ipv6_addr_any(sk_raddr) && raddr &&
+ !ipv6_addr_any(raddr) && !ipv6_addr_equal(sk_raddr, raddr))
+ continue;
+
+ if (l2tp->conn_id != tunnel_id)
+ continue;
+
+ goto found;
}
sk = NULL;
--
2.11.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH net-next 0/4] l2tp: cleanup socket lookup code in l2tp_ip and l2tp_ip6
2017-01-06 19:03 [PATCH net-next 0/4] l2tp: cleanup socket lookup code in l2tp_ip and l2tp_ip6 Guillaume Nault
` (3 preceding siblings ...)
2017-01-06 19:03 ` [PATCH net-next 4/4] l2tp: rework socket comparison " Guillaume Nault
@ 2017-01-07 3:19 ` David Miller
4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2017-01-07 3:19 UTC (permalink / raw)
To: g.nault; +Cc: netdev, jchapman, celston
From: Guillaume Nault <g.nault@alphalink.fr>
Date: Fri, 6 Jan 2017 20:03:53 +0100
> First three patches remove redundant tests and add missing "const"
> qualifiers.
>
> Fourth patch splits the conditionals found in __l2tp_ip*_bind_lookup(),
> to make these functions easier to review. In the process, I found that
> some corner cases were still not handled properly. So I've added the
> missing tests in this patch too, because they're pretty simple and the
> whole "if" statements are modified anyway.
>
> I expect it to be easier to review this way. If not, I can split up
> patch #4, post the missing tests separately to -net, and later repost
> this series as pure cleanup. Just let me know.
Looks good to me, series applied, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread