Skip to content

Commit b98b330

Browse files
Florian Westphalkuba-moo
authored andcommitted
net: dccp: use net_generic storage
DCCP is virtually never used, so no need to use space in struct net for it. Put the pernet ipv4/v6 socket in the dccp ipv4/ipv6 modules instead. Signed-off-by: Florian Westphal <fw@strlen.de> Link: https://lore.kernel.org/r/20210408174502.1625-1-fw@strlen.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 4438669 commit b98b330

File tree

4 files changed

+40
-24
lines changed

4 files changed

+40
-24
lines changed

include/net/net_namespace.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <net/netns/nexthop.h>
2323
#include <net/netns/ieee802154_6lowpan.h>
2424
#include <net/netns/sctp.h>
25-
#include <net/netns/dccp.h>
2625
#include <net/netns/netfilter.h>
2726
#include <net/netns/x_tables.h>
2827
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
@@ -130,9 +129,6 @@ struct net {
130129
#if defined(CONFIG_IP_SCTP) || defined(CONFIG_IP_SCTP_MODULE)
131130
struct netns_sctp sctp;
132131
#endif
133-
#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
134-
struct netns_dccp dccp;
135-
#endif
136132
#ifdef CONFIG_NETFILTER
137133
struct netns_nf nf;
138134
struct netns_xt xt;

include/net/netns/dccp.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

net/dccp/ipv4.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@
2323
#include <net/tcp_states.h>
2424
#include <net/xfrm.h>
2525
#include <net/secure_seq.h>
26+
#include <net/netns/generic.h>
2627

2728
#include "ackvec.h"
2829
#include "ccid.h"
2930
#include "dccp.h"
3031
#include "feat.h"
3132

33+
struct dccp_v4_pernet {
34+
struct sock *v4_ctl_sk;
35+
};
36+
37+
static unsigned int dccp_v4_pernet_id __read_mostly;
38+
3239
/*
33-
* The per-net dccp.v4_ctl_sk socket is used for responding to
40+
* The per-net v4_ctl_sk socket is used for responding to
3441
* the Out-of-the-blue (OOTB) packets. A control sock will be created
3542
* for this socket at the initialization time.
3643
*/
@@ -513,7 +520,8 @@ static void dccp_v4_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb)
513520
struct sk_buff *skb;
514521
struct dst_entry *dst;
515522
struct net *net = dev_net(skb_dst(rxskb)->dev);
516-
struct sock *ctl_sk = net->dccp.v4_ctl_sk;
523+
struct dccp_v4_pernet *pn;
524+
struct sock *ctl_sk;
517525

518526
/* Never send a reset in response to a reset. */
519527
if (dccp_hdr(rxskb)->dccph_type == DCCP_PKT_RESET)
@@ -522,6 +530,8 @@ static void dccp_v4_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb)
522530
if (skb_rtable(rxskb)->rt_type != RTN_LOCAL)
523531
return;
524532

533+
pn = net_generic(net, dccp_v4_pernet_id);
534+
ctl_sk = pn->v4_ctl_sk;
525535
dst = dccp_v4_route_skb(net, ctl_sk, rxskb);
526536
if (dst == NULL)
527537
return;
@@ -1005,16 +1015,20 @@ static struct inet_protosw dccp_v4_protosw = {
10051015

10061016
static int __net_init dccp_v4_init_net(struct net *net)
10071017
{
1018+
struct dccp_v4_pernet *pn = net_generic(net, dccp_v4_pernet_id);
1019+
10081020
if (dccp_hashinfo.bhash == NULL)
10091021
return -ESOCKTNOSUPPORT;
10101022

1011-
return inet_ctl_sock_create(&net->dccp.v4_ctl_sk, PF_INET,
1023+
return inet_ctl_sock_create(&pn->v4_ctl_sk, PF_INET,
10121024
SOCK_DCCP, IPPROTO_DCCP, net);
10131025
}
10141026

10151027
static void __net_exit dccp_v4_exit_net(struct net *net)
10161028
{
1017-
inet_ctl_sock_destroy(net->dccp.v4_ctl_sk);
1029+
struct dccp_v4_pernet *pn = net_generic(net, dccp_v4_pernet_id);
1030+
1031+
inet_ctl_sock_destroy(pn->v4_ctl_sk);
10181032
}
10191033

10201034
static void __net_exit dccp_v4_exit_batch(struct list_head *net_exit_list)
@@ -1026,6 +1040,8 @@ static struct pernet_operations dccp_v4_ops = {
10261040
.init = dccp_v4_init_net,
10271041
.exit = dccp_v4_exit_net,
10281042
.exit_batch = dccp_v4_exit_batch,
1043+
.id = &dccp_v4_pernet_id,
1044+
.size = sizeof(struct dccp_v4_pernet),
10291045
};
10301046

10311047
static int __init dccp_v4_init(void)

net/dccp/ipv6.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@
2727
#include <net/ip6_checksum.h>
2828
#include <net/xfrm.h>
2929
#include <net/secure_seq.h>
30+
#include <net/netns/generic.h>
3031
#include <net/sock.h>
3132

3233
#include "dccp.h"
3334
#include "ipv6.h"
3435
#include "feat.h"
3536

36-
/* The per-net dccp.v6_ctl_sk is used for sending RSTs and ACKs */
37+
struct dccp_v6_pernet {
38+
struct sock *v6_ctl_sk;
39+
};
40+
41+
static unsigned int dccp_v6_pernet_id __read_mostly;
42+
43+
/* The per-net v6_ctl_sk is used for sending RSTs and ACKs */
3744

3845
static const struct inet_connection_sock_af_ops dccp_ipv6_mapped;
3946
static const struct inet_connection_sock_af_ops dccp_ipv6_af_ops;
@@ -254,7 +261,8 @@ static void dccp_v6_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb)
254261
struct sk_buff *skb;
255262
struct flowi6 fl6;
256263
struct net *net = dev_net(skb_dst(rxskb)->dev);
257-
struct sock *ctl_sk = net->dccp.v6_ctl_sk;
264+
struct dccp_v6_pernet *pn;
265+
struct sock *ctl_sk;
258266
struct dst_entry *dst;
259267

260268
if (dccp_hdr(rxskb)->dccph_type == DCCP_PKT_RESET)
@@ -263,6 +271,8 @@ static void dccp_v6_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb)
263271
if (!ipv6_unicast_destination(rxskb))
264272
return;
265273

274+
pn = net_generic(net, dccp_v6_pernet_id);
275+
ctl_sk = pn->v6_ctl_sk;
266276
skb = dccp_ctl_make_reset(ctl_sk, rxskb);
267277
if (skb == NULL)
268278
return;
@@ -1089,16 +1099,20 @@ static struct inet_protosw dccp_v6_protosw = {
10891099

10901100
static int __net_init dccp_v6_init_net(struct net *net)
10911101
{
1102+
struct dccp_v6_pernet *pn = net_generic(net, dccp_v6_pernet_id);
1103+
10921104
if (dccp_hashinfo.bhash == NULL)
10931105
return -ESOCKTNOSUPPORT;
10941106

1095-
return inet_ctl_sock_create(&net->dccp.v6_ctl_sk, PF_INET6,
1107+
return inet_ctl_sock_create(&pn->v6_ctl_sk, PF_INET6,
10961108
SOCK_DCCP, IPPROTO_DCCP, net);
10971109
}
10981110

10991111
static void __net_exit dccp_v6_exit_net(struct net *net)
11001112
{
1101-
inet_ctl_sock_destroy(net->dccp.v6_ctl_sk);
1113+
struct dccp_v6_pernet *pn = net_generic(net, dccp_v6_pernet_id);
1114+
1115+
inet_ctl_sock_destroy(pn->v6_ctl_sk);
11021116
}
11031117

11041118
static void __net_exit dccp_v6_exit_batch(struct list_head *net_exit_list)
@@ -1110,6 +1124,8 @@ static struct pernet_operations dccp_v6_ops = {
11101124
.init = dccp_v6_init_net,
11111125
.exit = dccp_v6_exit_net,
11121126
.exit_batch = dccp_v6_exit_batch,
1127+
.id = &dccp_v6_pernet_id,
1128+
.size = sizeof(struct dccp_v6_pernet),
11131129
};
11141130

11151131
static int __init dccp_v6_init(void)

0 commit comments

Comments
 (0)