Skip to content

Commit a85406a

Browse files
dcarattiummakynes
authored andcommitted
netfilter: conntrack: built-in support for SCTP
CONFIG_NF_CT_PROTO_SCTP is no more a tristate. When set to y, connection tracking support for SCTP protocol is built-in into nf_conntrack.ko. footprint test: $ ls -l net/netfilter/nf_conntrack{_proto_sctp,}.ko \ net/ipv4/netfilter/nf_conntrack_ipv4.ko \ net/ipv6/netfilter/nf_conntrack_ipv6.ko (builtin)|| sctp | ipv4 | ipv6 | nf_conntrack ---------++--------+--------+--------+-------------- none || 498243 | 828755 | 828676 | 6141434 SCTP || - | 829254 | 829175 | 6547872 Signed-off-by: Davide Caratti <dcaratti@redhat.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent c51d390 commit a85406a

8 files changed

Lines changed: 38 additions & 72 deletions

File tree

‎include/net/netfilter/ipv4/nf_conntrack_ipv4.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ extern struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp;
1818
#ifdef CONFIG_NF_CT_PROTO_DCCP
1919
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4;
2020
#endif
21+
#ifdef CONFIG_NF_CT_PROTO_SCTP
22+
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4;
23+
#endif
2124

2225
int nf_conntrack_ipv4_compat_init(void);
2326
void nf_conntrack_ipv4_compat_fini(void);

‎include/net/netfilter/ipv6/nf_conntrack_ipv6.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ extern struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6;
99
#ifdef CONFIG_NF_CT_PROTO_DCCP
1010
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6;
1111
#endif
12+
#ifdef CONFIG_NF_CT_PROTO_SCTP
13+
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6;
14+
#endif
1215

1316
#include <linux/sysctl.h>
1417
extern struct ctl_table nf_ct_ipv6_sysctl_table[];

‎include/net/netns/conntrack.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#ifdef CONFIG_NF_CT_PROTO_DCCP
1010
#include <linux/netfilter/nf_conntrack_dccp.h>
1111
#endif
12+
#ifdef CONFIG_NF_CT_PROTO_SCTP
13+
#include <linux/netfilter/nf_conntrack_sctp.h>
14+
#endif
1215
#include <linux/seqlock.h>
1316

1417
struct ctl_table_header;
@@ -59,6 +62,13 @@ struct nf_dccp_net {
5962
};
6063
#endif
6164

65+
#ifdef CONFIG_NF_CT_PROTO_SCTP
66+
struct nf_sctp_net {
67+
struct nf_proto_net pn;
68+
unsigned int timeouts[SCTP_CONNTRACK_MAX];
69+
};
70+
#endif
71+
6272
struct nf_ip_net {
6373
struct nf_generic_net generic;
6474
struct nf_tcp_net tcp;
@@ -68,6 +78,9 @@ struct nf_ip_net {
6878
#ifdef CONFIG_NF_CT_PROTO_DCCP
6979
struct nf_dccp_net dccp;
7080
#endif
81+
#ifdef CONFIG_NF_CT_PROTO_SCTP
82+
struct nf_sctp_net sctp;
83+
#endif
7184
};
7285

7386
struct ct_pcpu {

‎net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ static struct nf_conntrack_l4proto *builtin_l4proto4[] = {
343343
#ifdef CONFIG_NF_CT_PROTO_DCCP
344344
&nf_conntrack_l4proto_dccp4,
345345
#endif
346+
#ifdef CONFIG_NF_CT_PROTO_SCTP
347+
&nf_conntrack_l4proto_sctp4,
348+
#endif
346349
};
347350

348351
static int ipv4_net_init(struct net *net)

‎net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ static struct nf_conntrack_l4proto *builtin_l4proto6[] = {
343343
#ifdef CONFIG_NF_CT_PROTO_DCCP
344344
&nf_conntrack_l4proto_dccp6,
345345
#endif
346+
#ifdef CONFIG_NF_CT_PROTO_SCTP
347+
&nf_conntrack_l4proto_sctp6,
348+
#endif
346349
};
347350

348351
static int ipv6_net_init(struct net *net)

‎net/netfilter/Kconfig‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,14 @@ config NF_CT_PROTO_GRE
159159
tristate
160160

161161
config NF_CT_PROTO_SCTP
162-
tristate 'SCTP protocol connection tracking support'
162+
bool 'SCTP protocol connection tracking support'
163163
depends on NETFILTER_ADVANCED
164-
default IP_SCTP
164+
default y
165165
help
166166
With this option enabled, the layer 3 independent connection
167167
tracking code will be able to do state tracking on SCTP connections.
168168

169-
If you want to compile it as a module, say M here and read
170-
<file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
169+
If unsure, say Y.
171170

172171
config NF_CT_PROTO_UDPLITE
173172
tristate 'UDP-Lite protocol connection tracking support'

‎net/netfilter/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ nf_conntrack-$(CONFIG_NF_CONNTRACK_TIMESTAMP) += nf_conntrack_timestamp.o
66
nf_conntrack-$(CONFIG_NF_CONNTRACK_EVENTS) += nf_conntrack_ecache.o
77
nf_conntrack-$(CONFIG_NF_CONNTRACK_LABELS) += nf_conntrack_labels.o
88
nf_conntrack-$(CONFIG_NF_CT_PROTO_DCCP) += nf_conntrack_proto_dccp.o
9+
nf_conntrack-$(CONFIG_NF_CT_PROTO_SCTP) += nf_conntrack_proto_sctp.o
910

1011
obj-$(CONFIG_NETFILTER) = netfilter.o
1112

@@ -18,7 +19,6 @@ obj-$(CONFIG_NETFILTER_NETLINK_LOG) += nfnetlink_log.o
1819
obj-$(CONFIG_NF_CONNTRACK) += nf_conntrack.o
1920

2021
obj-$(CONFIG_NF_CT_PROTO_GRE) += nf_conntrack_proto_gre.o
21-
obj-$(CONFIG_NF_CT_PROTO_SCTP) += nf_conntrack_proto_sctp.o
2222
obj-$(CONFIG_NF_CT_PROTO_UDPLITE) += nf_conntrack_proto_udplite.o
2323

2424
# netlink interface for nf_conntrack

‎net/netfilter/nf_conntrack_proto_sctp.c‎

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <linux/types.h>
1616
#include <linux/timer.h>
1717
#include <linux/netfilter.h>
18-
#include <linux/module.h>
1918
#include <linux/in.h>
2019
#include <linux/ip.h>
2120
#include <linux/sctp.h>
@@ -144,15 +143,9 @@ static const u8 sctp_conntracks[2][11][SCTP_CONNTRACK_MAX] = {
144143
}
145144
};
146145

147-
static unsigned int sctp_net_id __read_mostly;
148-
struct sctp_net {
149-
struct nf_proto_net pn;
150-
unsigned int timeouts[SCTP_CONNTRACK_MAX];
151-
};
152-
153-
static inline struct sctp_net *sctp_pernet(struct net *net)
146+
static inline struct nf_sctp_net *sctp_pernet(struct net *net)
154147
{
155-
return net_generic(net, sctp_net_id);
148+
return &net->ct.nf_ct_proto.sctp;
156149
}
157150

158151
static bool sctp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
@@ -600,7 +593,7 @@ static int sctp_timeout_nlattr_to_obj(struct nlattr *tb[],
600593
struct net *net, void *data)
601594
{
602595
unsigned int *timeouts = data;
603-
struct sctp_net *sn = sctp_pernet(net);
596+
struct nf_sctp_net *sn = sctp_pernet(net);
604597
int i;
605598

606599
/* set default SCTP timeouts. */
@@ -708,7 +701,7 @@ static struct ctl_table sctp_sysctl_table[] = {
708701
#endif
709702

710703
static int sctp_kmemdup_sysctl_table(struct nf_proto_net *pn,
711-
struct sctp_net *sn)
704+
struct nf_sctp_net *sn)
712705
{
713706
#ifdef CONFIG_SYSCTL
714707
if (pn->ctl_table)
@@ -735,7 +728,7 @@ static int sctp_kmemdup_sysctl_table(struct nf_proto_net *pn,
735728

736729
static int sctp_init_net(struct net *net, u_int16_t proto)
737730
{
738-
struct sctp_net *sn = sctp_pernet(net);
731+
struct nf_sctp_net *sn = sctp_pernet(net);
739732
struct nf_proto_net *pn = &sn->pn;
740733

741734
if (!pn->users) {
@@ -748,7 +741,7 @@ static int sctp_init_net(struct net *net, u_int16_t proto)
748741
return sctp_kmemdup_sysctl_table(pn, sn);
749742
}
750743

751-
static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = {
744+
struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = {
752745
.l3proto = PF_INET,
753746
.l4proto = IPPROTO_SCTP,
754747
.name = "sctp",
@@ -778,11 +771,11 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = {
778771
.nla_policy = sctp_timeout_nla_policy,
779772
},
780773
#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
781-
.net_id = &sctp_net_id,
782774
.init_net = sctp_init_net,
783775
};
776+
EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_sctp4);
784777

785-
static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = {
778+
struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = {
786779
.l3proto = PF_INET6,
787780
.l4proto = IPPROTO_SCTP,
788781
.name = "sctp",
@@ -812,57 +805,6 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = {
812805
},
813806
#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
814807
#endif
815-
.net_id = &sctp_net_id,
816808
.init_net = sctp_init_net,
817809
};
818-
819-
static struct nf_conntrack_l4proto *sctp_proto[] = {
820-
&nf_conntrack_l4proto_sctp4,
821-
&nf_conntrack_l4proto_sctp6,
822-
};
823-
824-
static int sctp_net_init(struct net *net)
825-
{
826-
return nf_ct_l4proto_pernet_register(net, sctp_proto,
827-
ARRAY_SIZE(sctp_proto));
828-
}
829-
830-
static void sctp_net_exit(struct net *net)
831-
{
832-
nf_ct_l4proto_pernet_unregister(net, sctp_proto,
833-
ARRAY_SIZE(sctp_proto));
834-
}
835-
836-
static struct pernet_operations sctp_net_ops = {
837-
.init = sctp_net_init,
838-
.exit = sctp_net_exit,
839-
.id = &sctp_net_id,
840-
.size = sizeof(struct sctp_net),
841-
};
842-
843-
static int __init nf_conntrack_proto_sctp_init(void)
844-
{
845-
int ret;
846-
847-
ret = register_pernet_subsys(&sctp_net_ops);
848-
if (ret < 0)
849-
return ret;
850-
ret = nf_ct_l4proto_register(sctp_proto, ARRAY_SIZE(sctp_proto));
851-
if (ret < 0)
852-
unregister_pernet_subsys(&sctp_net_ops);
853-
return ret;
854-
}
855-
856-
static void __exit nf_conntrack_proto_sctp_fini(void)
857-
{
858-
nf_ct_l4proto_unregister(sctp_proto, ARRAY_SIZE(sctp_proto));
859-
unregister_pernet_subsys(&sctp_net_ops);
860-
}
861-
862-
module_init(nf_conntrack_proto_sctp_init);
863-
module_exit(nf_conntrack_proto_sctp_fini);
864-
865-
MODULE_LICENSE("GPL");
866-
MODULE_AUTHOR("Kiran Kumar Immidi");
867-
MODULE_DESCRIPTION("Netfilter connection tracking protocol helper for SCTP");
868-
MODULE_ALIAS("ip_conntrack_proto_sctp");
810+
EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_sctp6);

0 commit comments

Comments
 (0)