Skip to content

Commit a4a600d

Browse files
lxinkuba-moo
authored andcommitted
udp: call udp_encap_enable for v6 sockets when enabling encap
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]>
1 parent c9dca82 commit a4a600d

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
@@ -240,12 +240,6 @@ static int bareudp_socket_create(struct bareudp_dev *bareudp, __be16 port)
240240
tunnel_cfg.encap_destroy = NULL;
241241
setup_udp_tunnel_sock(bareudp->net, sock, &tunnel_cfg);
242242

243-
/* As the setup_udp_tunnel_sock does not call udp_encap_enable if the
244-
* socket type is v6 an explicit call to udp_encap_enable is needed.
245-
*/
246-
if (sock->sk->sk_family == AF_INET6)
247-
udp_encap_enable();
248-
249243
rcu_assign_pointer(bareudp->sock, sock);
250244
return 0;
251245
}

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
@@ -181,9 +181,8 @@ static inline void udp_tunnel_encap_enable(struct socket *sock)
181181
#if IS_ENABLED(CONFIG_IPV6)
182182
if (sock->sk->sk_family == PF_INET6)
183183
ipv6_stub->udpv6_encap_enable();
184-
else
185184
#endif
186-
udp_encap_enable();
185+
udp_encap_enable();
187186
}
188187

189188
#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
@@ -596,6 +596,12 @@ void udp_encap_enable(void)
596596
}
597597
EXPORT_SYMBOL(udp_encap_enable);
598598

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

net/ipv6/udp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,8 +1608,10 @@ void udpv6_destroy_sock(struct sock *sk)
16081608
if (encap_destroy)
16091609
encap_destroy(sk);
16101610
}
1611-
if (up->encap_enabled)
1611+
if (up->encap_enabled) {
16121612
static_branch_dec(&udpv6_encap_needed_key);
1613+
udp_encap_disable();
1614+
}
16131615
}
16141616

16151617
inet6_destroy_sock(sk);

0 commit comments

Comments
 (0)