e5a346cac4f8fd7ae56536f7e3bcdc54734061aa
[openwrt/staging/neocturne.git] /
1 From: Oz Shlomo <ozsh@nvidia.com>
2 Date: Thu, 3 Jun 2021 15:12:33 +0300
3 Subject: [PATCH] netfilter: conntrack: Introduce tcp offload timeout
4 configuration
5
6 TCP connections may be offloaded from nf conntrack to nf flow table.
7 Offloaded connections are aged after 30 seconds of inactivity.
8 Once aged, ownership is returned to conntrack with a hard coded pickup
9 time of 120 seconds, after which the connection may be deleted.
10 eted. The current aging intervals may be too aggressive for some users.
11
12 Provide users with the ability to control the nf flow table offload
13 aging and pickup time intervals via sysctl parameter as a pre-step for
14 configuring the nf flow table GC timeout intervals.
15
16 Signed-off-by: Oz Shlomo <ozsh@nvidia.com>
17 Reviewed-by: Paul Blakey <paulb@nvidia.com>
18 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
19 ---
20
21 --- a/include/net/netns/conntrack.h
22 +++ b/include/net/netns/conntrack.h
23 @@ -27,6 +27,10 @@ struct nf_tcp_net {
24 int tcp_loose;
25 int tcp_be_liberal;
26 int tcp_max_retrans;
27 +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
28 + unsigned int offload_timeout;
29 + unsigned int offload_pickup;
30 +#endif
31 };
32
33 enum udp_conntrack {
34 --- a/net/netfilter/nf_conntrack_proto_tcp.c
35 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
36 @@ -1438,6 +1438,11 @@ void nf_conntrack_tcp_init_net(struct ne
37 tn->tcp_loose = nf_ct_tcp_loose;
38 tn->tcp_be_liberal = nf_ct_tcp_be_liberal;
39 tn->tcp_max_retrans = nf_ct_tcp_max_retrans;
40 +
41 +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
42 + tn->offload_timeout = 30 * HZ;
43 + tn->offload_pickup = 120 * HZ;
44 +#endif
45 }
46
47 const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp =
48 --- a/net/netfilter/nf_conntrack_standalone.c
49 +++ b/net/netfilter/nf_conntrack_standalone.c
50 @@ -567,6 +567,10 @@ enum nf_ct_sysctl_index {
51 NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_CLOSE,
52 NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_RETRANS,
53 NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_UNACK,
54 +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
55 + NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD,
56 + NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD_PICKUP,
57 +#endif
58 NF_SYSCTL_CT_PROTO_TCP_LOOSE,
59 NF_SYSCTL_CT_PROTO_TCP_LIBERAL,
60 NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS,
61 @@ -758,6 +762,20 @@ static struct ctl_table nf_ct_sysctl_tab
62 .mode = 0644,
63 .proc_handler = proc_dointvec_jiffies,
64 },
65 +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
66 + [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD] = {
67 + .procname = "nf_flowtable_tcp_timeout",
68 + .maxlen = sizeof(unsigned int),
69 + .mode = 0644,
70 + .proc_handler = proc_dointvec_jiffies,
71 + },
72 + [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD_PICKUP] = {
73 + .procname = "nf_flowtable_tcp_pickup",
74 + .maxlen = sizeof(unsigned int),
75 + .mode = 0644,
76 + .proc_handler = proc_dointvec_jiffies,
77 + },
78 +#endif
79 [NF_SYSCTL_CT_PROTO_TCP_LOOSE] = {
80 .procname = "nf_conntrack_tcp_loose",
81 .maxlen = sizeof(int),
82 @@ -967,6 +985,12 @@ static void nf_conntrack_standalone_init
83 XASSIGN(LIBERAL, &tn->tcp_be_liberal);
84 XASSIGN(MAX_RETRANS, &tn->tcp_max_retrans);
85 #undef XASSIGN
86 +
87 +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
88 + table[NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD].data = &tn->offload_timeout;
89 + table[NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD_PICKUP].data = &tn->offload_pickup;
90 +#endif
91 +
92 }
93
94 static void nf_conntrack_standalone_init_sctp_sysctl(struct net *net,