* [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0
@ 2017-04-17 23:24 Subash Abhinov Kasiviswanathan
2017-04-17 23:51 ` YUAN Linyu
2017-04-18 15:59 ` David Ahern
0 siblings, 2 replies; 5+ messages in thread
From: Subash Abhinov Kasiviswanathan @ 2017-04-17 23:24 UTC (permalink / raw)
To: dsa, davem, netdev, rshearma, eric.dumazet
Cc: Subash Abhinov Kasiviswanathan, Eric Dumazet
David Ahern reported that 5425077d73e0c ("net: ipv6: Add early demux
handler for UDP unicast") breaks udp_l3mdev_accept=0 since early
demux for IPv6 UDP was doing a generic socket lookup which does not
require an exact match. Fix this by making UDPv6 early demux match
connected sockets only.
v1->v2: Take reference to socket after match as suggested by Eric
Fixes: 5425077d73e0c ("net: ipv6: Add early demux handler for UDP unicast")
Reported-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
Cc: Eric Dumazet <edumazet@google.com>
---
net/ipv6/udp.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index b793ed1..5a4504b 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -46,6 +46,7 @@
#include <net/tcp_states.h>
#include <net/ip6_checksum.h>
#include <net/xfrm.h>
+#include <net/inet_hashtables.h>
#include <net/inet6_hashtables.h>
#include <net/busy_poll.h>
#include <net/sock_reuseport.h>
@@ -864,21 +865,25 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
return 0;
}
+
static struct sock *__udp6_lib_demux_lookup(struct net *net,
__be16 loc_port, const struct in6_addr *loc_addr,
__be16 rmt_port, const struct in6_addr *rmt_addr,
int dif)
{
+ unsigned short hnum = ntohs(loc_port);
+ unsigned int hash2 = udp6_portaddr_hash(net, loc_addr, hnum);
+ unsigned int slot2 = hash2 & udp_table.mask;
+ struct udp_hslot *hslot2 = &udp_table.hash2[slot2];
+ const __portpair ports = INET_COMBINED_PORTS(rmt_port, hnum);
struct sock *sk;
- rcu_read_lock();
- sk = __udp6_lib_lookup(net, rmt_addr, rmt_port, loc_addr, loc_port,
- dif, &udp_table, NULL);
- if (sk && !atomic_inc_not_zero(&sk->sk_refcnt))
- sk = NULL;
- rcu_read_unlock();
-
- return sk;
+ udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
+ if (INET6_MATCH(sk, net, rmt_addr, loc_addr, ports, dif))
+ return sk;
+ break;
+ }
+ return NULL;
}
static void udp_v6_early_demux(struct sk_buff *skb)
@@ -903,7 +908,7 @@ static void udp_v6_early_demux(struct sk_buff *skb)
else
return;
- if (!sk)
+ if (!sk || !atomic_inc_not_zero_hint(&sk->sk_refcnt, 2))
return;
skb->sk = sk;
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0
2017-04-17 23:24 [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0 Subash Abhinov Kasiviswanathan
@ 2017-04-17 23:51 ` YUAN Linyu
2017-04-18 1:07 ` Subash Abhinov Kasiviswanathan
2017-04-18 15:59 ` David Ahern
1 sibling, 1 reply; 5+ messages in thread
From: YUAN Linyu @ 2017-04-17 23:51 UTC (permalink / raw)
To: Subash Abhinov Kasiviswanathan, dsa, davem, netdev, rshearma,
eric.dumazet
Cc: Eric Dumazet
> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-owner@vger.kernel.org]
> On Behalf Of Subash Abhinov Kasiviswanathan
> Sent: Tuesday, April 18, 2017 7:25 AM
> To: dsa@cumulusnetworks.com; davem@davemloft.net;
> netdev@vger.kernel.org; rshearma@brocade.com; eric.dumazet@gmail.com
> Cc: Subash Abhinov Kasiviswanathan; Eric Dumazet
> Subject: [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with
> udp_l3mdev_accept=0
>
> - return sk;
> + udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
> + if (INET6_MATCH(sk, net, rmt_addr, loc_addr, ports, dif))
> + return sk;
> + break;
I think break here should remove ?
> + }
> + return NULL;
> }
> --
> 1.9.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0
2017-04-17 23:51 ` YUAN Linyu
@ 2017-04-18 1:07 ` Subash Abhinov Kasiviswanathan
2017-04-18 15:46 ` David Ahern
0 siblings, 1 reply; 5+ messages in thread
From: Subash Abhinov Kasiviswanathan @ 2017-04-18 1:07 UTC (permalink / raw)
To: YUAN Linyu; +Cc: dsa, davem, netdev, rshearma, eric.dumazet, Eric Dumazet
>> + break;
> I think break here should remove ?
Hi Yuan
This is similar to __udp4_lib_demux_lookup where we need to check if the
first
socket is an exact match or break since chains maybe long.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0
2017-04-18 1:07 ` Subash Abhinov Kasiviswanathan
@ 2017-04-18 15:46 ` David Ahern
0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2017-04-18 15:46 UTC (permalink / raw)
To: Subash Abhinov Kasiviswanathan, YUAN Linyu
Cc: davem, netdev, rshearma, eric.dumazet, Eric Dumazet
On 4/17/17 7:07 PM, Subash Abhinov Kasiviswanathan wrote:
>>> + break;
>> I think break here should remove ?
>
> Hi Yuan
>
> This is similar to __udp4_lib_demux_lookup where we need to check if the
> first
> socket is an exact match or break since chains maybe long.
>
I suggest adding the same comment as __udp4_lib_demux_lookup; it does
look odd.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0
2017-04-17 23:24 [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0 Subash Abhinov Kasiviswanathan
2017-04-17 23:51 ` YUAN Linyu
@ 2017-04-18 15:59 ` David Ahern
1 sibling, 0 replies; 5+ messages in thread
From: David Ahern @ 2017-04-18 15:59 UTC (permalink / raw)
To: Subash Abhinov Kasiviswanathan, davem, netdev, rshearma, eric.dumazet
Cc: Eric Dumazet
On 4/17/17 5:24 PM, Subash Abhinov Kasiviswanathan wrote:
> David Ahern reported that 5425077d73e0c ("net: ipv6: Add early demux
> handler for UDP unicast") breaks udp_l3mdev_accept=0 since early
> demux for IPv6 UDP was doing a generic socket lookup which does not
> require an exact match. Fix this by making UDPv6 early demux match
> connected sockets only.
>
> v1->v2: Take reference to socket after match as suggested by Eric
>
> Fixes: 5425077d73e0c ("net: ipv6: Add early demux handler for UDP unicast")
> Reported-by: David Ahern <dsa@cumulusnetworks.com>
> Signed-off-by: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
> Cc: Eric Dumazet <edumazet@google.com>
> ---
> net/ipv6/udp.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
Besides adding the comment before the break, this looks fine to me.
Acked-by: David Ahern <dsa@cumulusnetworks.com>
Tested-by: David Ahern <dsa@cumulusnetworks.com>
If the only change for v3 is the comment before the break, please keep
the above with the new patch.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-04-18 15:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-17 23:24 [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0 Subash Abhinov Kasiviswanathan
2017-04-17 23:51 ` YUAN Linyu
2017-04-18 1:07 ` Subash Abhinov Kasiviswanathan
2017-04-18 15:46 ` David Ahern
2017-04-18 15:59 ` David Ahern
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.