Skip to content

Commit 210e7b4

Browse files
lxingregkh
authored andcommitted
udp: call udp_encap_enable for v6 sockets when enabling encap
commit a4a600d upstream. When enabling encap for a ipv6 socket without udp_encap_needed_key increased, UDP GRO won't work for v4 mapped v6 address packets as sk will be NULL in udp4_gro_receive(). This patch is to enable it by increasing udp_encap_needed_key for v6 sockets in udp_tunnel_encap_enable(), and correspondingly decrease udp_encap_needed_key in udpv6_destroy_sock(). v1->v2: - add udp_encap_disable() and export it. v2->v3: - add the change for rxrpc and bareudp into one patch, as Alex suggested. v3->v4: - move rxrpc part to another patch. Acked-by: Willem de Bruijn <[email protected]> Signed-off-by: Xin Long <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Tested-by: Antonio Quartulli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e1a5849 commit 210e7b4

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

drivers/net/bareudp.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,6 @@ static int bareudp_socket_create(struct bareudp_dev *bareudp, __be16 port)
246246
tunnel_cfg.encap_destroy = NULL;
247247
setup_udp_tunnel_sock(bareudp->net, sock, &tunnel_cfg);
248248

249-
/* As the setup_udp_tunnel_sock does not call udp_encap_enable if the
250-
* socket type is v6 an explicit call to udp_encap_enable is needed.
251-
*/
252-
if (sock->sk->sk_family == AF_INET6)
253-
udp_encap_enable();
254-
255249
rcu_assign_pointer(bareudp->sock, sock);
256250
return 0;
257251
}

include/net/udp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ void udp_init(void);
467467

468468
DECLARE_STATIC_KEY_FALSE(udp_encap_needed_key);
469469
void udp_encap_enable(void);
470+
void udp_encap_disable(void);
470471
#if IS_ENABLED(CONFIG_IPV6)
471472
DECLARE_STATIC_KEY_FALSE(udpv6_encap_needed_key);
472473
void udpv6_encap_enable(void);

include/net/udp_tunnel.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ static inline void udp_tunnel_encap_enable(struct socket *sock)
177177
#if IS_ENABLED(CONFIG_IPV6)
178178
if (sock->sk->sk_family == PF_INET6)
179179
ipv6_stub->udpv6_encap_enable();
180-
else
181180
#endif
182-
udp_encap_enable();
181+
udp_encap_enable();
183182
}
184183

185184
#define UDP_TUNNEL_NIC_MAX_TABLES 4

net/ipv4/udp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,12 @@ void udp_encap_enable(void)
598598
}
599599
EXPORT_SYMBOL(udp_encap_enable);
600600

601+
void udp_encap_disable(void)
602+
{
603+
static_branch_dec(&udp_encap_needed_key);
604+
}
605+
EXPORT_SYMBOL(udp_encap_disable);
606+
601607
/* Handler for tunnels with arbitrary destination ports: no socket lookup, go
602608
* through error handlers in encapsulations looking for a match.
603609
*/

net/ipv6/udp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,8 +1610,10 @@ void udpv6_destroy_sock(struct sock *sk)
16101610
if (encap_destroy)
16111611
encap_destroy(sk);
16121612
}
1613-
if (up->encap_enabled)
1613+
if (up->encap_enabled) {
16141614
static_branch_dec(&udpv6_encap_needed_key);
1615+
udp_encap_disable();
1616+
}
16151617
}
16161618

16171619
inet6_destroy_sock(sk);

0 commit comments

Comments
 (0)