Commit | Line | Data |
---|---|---|
a0ae2562 | 1 | // SPDX-License-Identifier: GPL-2.0 |
9fb9cbb1 YK |
2 | #include <linux/types.h> |
3 | #include <linux/netfilter.h> | |
5a0e3ad6 | 4 | #include <linux/slab.h> |
9fb9cbb1 YK |
5 | #include <linux/module.h> |
6 | #include <linux/skbuff.h> | |
7 | #include <linux/proc_fs.h> | |
8 | #include <linux/seq_file.h> | |
9 | #include <linux/percpu.h> | |
10 | #include <linux/netdevice.h> | |
1ae4de0c | 11 | #include <linux/security.h> |
457c4cbc | 12 | #include <net/net_namespace.h> |
9fb9cbb1 YK |
13 | #ifdef CONFIG_SYSCTL |
14 | #include <linux/sysctl.h> | |
15 | #endif | |
16 | ||
9fb9cbb1 | 17 | #include <net/netfilter/nf_conntrack.h> |
f6180121 | 18 | #include <net/netfilter/nf_conntrack_core.h> |
605dcad6 | 19 | #include <net/netfilter/nf_conntrack_l4proto.h> |
77ab9cff | 20 | #include <net/netfilter/nf_conntrack_expect.h> |
9fb9cbb1 | 21 | #include <net/netfilter/nf_conntrack_helper.h> |
58401572 | 22 | #include <net/netfilter/nf_conntrack_acct.h> |
5d0aa2cc | 23 | #include <net/netfilter/nf_conntrack_zones.h> |
a992ca2a | 24 | #include <net/netfilter/nf_conntrack_timestamp.h> |
0e60ebe0 | 25 | #include <linux/rculist_nulls.h> |
9fb9cbb1 | 26 | |
ba3fbe66 PNA |
27 | static bool enable_hooks __read_mostly; |
28 | MODULE_PARM_DESC(enable_hooks, "Always enable conntrack hooks"); | |
29 | module_param(enable_hooks, bool, 0000); | |
30 | ||
a0ae2562 | 31 | unsigned int nf_conntrack_net_id __read_mostly; |
9fb9cbb1 | 32 | |
54b07dca | 33 | #ifdef CONFIG_NF_CONNTRACK_PROCFS |
824f1fbe | 34 | void |
9fb9cbb1 | 35 | print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple, |
32948588 | 36 | const struct nf_conntrack_l4proto *l4proto) |
9fb9cbb1 | 37 | { |
f957be9d | 38 | switch (tuple->src.l3num) { |
91950833 FW |
39 | case NFPROTO_IPV4: |
40 | seq_printf(s, "src=%pI4 dst=%pI4 ", | |
41 | &tuple->src.u3.ip, &tuple->dst.u3.ip); | |
42 | break; | |
43 | case NFPROTO_IPV6: | |
44 | seq_printf(s, "src=%pI6 dst=%pI6 ", | |
45 | tuple->src.u3.ip6, tuple->dst.u3.ip6); | |
46 | break; | |
47 | default: | |
48 | break; | |
49 | } | |
50 | ||
51 | switch (l4proto->l4proto) { | |
52 | case IPPROTO_ICMP: | |
53 | seq_printf(s, "type=%u code=%u id=%u ", | |
54 | tuple->dst.u.icmp.type, | |
55 | tuple->dst.u.icmp.code, | |
56 | ntohs(tuple->src.u.icmp.id)); | |
57 | break; | |
58 | case IPPROTO_TCP: | |
59 | seq_printf(s, "sport=%hu dport=%hu ", | |
60 | ntohs(tuple->src.u.tcp.port), | |
61 | ntohs(tuple->dst.u.tcp.port)); | |
62 | break; | |
954d8297 | 63 | case IPPROTO_UDPLITE: |
91950833 FW |
64 | case IPPROTO_UDP: |
65 | seq_printf(s, "sport=%hu dport=%hu ", | |
66 | ntohs(tuple->src.u.udp.port), | |
67 | ntohs(tuple->dst.u.udp.port)); | |
68 | ||
69 | break; | |
70 | case IPPROTO_DCCP: | |
71 | seq_printf(s, "sport=%hu dport=%hu ", | |
72 | ntohs(tuple->src.u.dccp.port), | |
73 | ntohs(tuple->dst.u.dccp.port)); | |
74 | break; | |
75 | case IPPROTO_SCTP: | |
76 | seq_printf(s, "sport=%hu dport=%hu ", | |
77 | ntohs(tuple->src.u.sctp.port), | |
78 | ntohs(tuple->dst.u.sctp.port)); | |
79 | break; | |
80 | case IPPROTO_ICMPV6: | |
81 | seq_printf(s, "type=%u code=%u id=%u ", | |
82 | tuple->dst.u.icmp.type, | |
83 | tuple->dst.u.icmp.code, | |
84 | ntohs(tuple->src.u.icmp.id)); | |
85 | break; | |
86 | case IPPROTO_GRE: | |
87 | seq_printf(s, "srckey=0x%x dstkey=0x%x ", | |
88 | ntohs(tuple->src.u.gre.key), | |
89 | ntohs(tuple->dst.u.gre.key)); | |
90 | break; | |
91 | default: | |
92 | break; | |
93 | } | |
9fb9cbb1 | 94 | } |
e4bd8bce | 95 | EXPORT_SYMBOL_GPL(print_tuple); |
9fb9cbb1 | 96 | |
9fb9cbb1 | 97 | struct ct_iter_state { |
b2ce2c74 | 98 | struct seq_net_private p; |
64b87639 LZ |
99 | struct hlist_nulls_head *hash; |
100 | unsigned int htable_size; | |
9fb9cbb1 | 101 | unsigned int bucket; |
a992ca2a | 102 | u_int64_t time_now; |
9fb9cbb1 YK |
103 | }; |
104 | ||
ea781f19 | 105 | static struct hlist_nulls_node *ct_get_first(struct seq_file *seq) |
9fb9cbb1 YK |
106 | { |
107 | struct ct_iter_state *st = seq->private; | |
ea781f19 | 108 | struct hlist_nulls_node *n; |
9fb9cbb1 YK |
109 | |
110 | for (st->bucket = 0; | |
64b87639 | 111 | st->bucket < st->htable_size; |
9fb9cbb1 | 112 | st->bucket++) { |
64b87639 LZ |
113 | n = rcu_dereference( |
114 | hlist_nulls_first_rcu(&st->hash[st->bucket])); | |
ea781f19 | 115 | if (!is_a_nulls(n)) |
76507f69 | 116 | return n; |
9fb9cbb1 YK |
117 | } |
118 | return NULL; | |
119 | } | |
120 | ||
ea781f19 ED |
121 | static struct hlist_nulls_node *ct_get_next(struct seq_file *seq, |
122 | struct hlist_nulls_node *head) | |
9fb9cbb1 YK |
123 | { |
124 | struct ct_iter_state *st = seq->private; | |
125 | ||
0e60ebe0 | 126 | head = rcu_dereference(hlist_nulls_next_rcu(head)); |
ea781f19 ED |
127 | while (is_a_nulls(head)) { |
128 | if (likely(get_nulls_value(head) == st->bucket)) { | |
64b87639 | 129 | if (++st->bucket >= st->htable_size) |
ea781f19 ED |
130 | return NULL; |
131 | } | |
0e60ebe0 | 132 | head = rcu_dereference( |
64b87639 | 133 | hlist_nulls_first_rcu(&st->hash[st->bucket])); |
9fb9cbb1 YK |
134 | } |
135 | return head; | |
136 | } | |
137 | ||
ea781f19 | 138 | static struct hlist_nulls_node *ct_get_idx(struct seq_file *seq, loff_t pos) |
9fb9cbb1 | 139 | { |
ea781f19 | 140 | struct hlist_nulls_node *head = ct_get_first(seq); |
9fb9cbb1 YK |
141 | |
142 | if (head) | |
143 | while (pos && (head = ct_get_next(seq, head))) | |
144 | pos--; | |
145 | return pos ? NULL : head; | |
146 | } | |
147 | ||
148 | static void *ct_seq_start(struct seq_file *seq, loff_t *pos) | |
76507f69 | 149 | __acquires(RCU) |
9fb9cbb1 | 150 | { |
a992ca2a PNA |
151 | struct ct_iter_state *st = seq->private; |
152 | ||
d2de875c | 153 | st->time_now = ktime_get_real_ns(); |
76507f69 | 154 | rcu_read_lock(); |
64b87639 LZ |
155 | |
156 | nf_conntrack_get_ht(&st->hash, &st->htable_size); | |
9fb9cbb1 YK |
157 | return ct_get_idx(seq, *pos); |
158 | } | |
159 | ||
160 | static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos) | |
161 | { | |
162 | (*pos)++; | |
163 | return ct_get_next(s, v); | |
164 | } | |
165 | ||
166 | static void ct_seq_stop(struct seq_file *s, void *v) | |
76507f69 | 167 | __releases(RCU) |
9fb9cbb1 | 168 | { |
76507f69 | 169 | rcu_read_unlock(); |
9fb9cbb1 YK |
170 | } |
171 | ||
1ae4de0c | 172 | #ifdef CONFIG_NF_CONNTRACK_SECMARK |
e71456ae | 173 | static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) |
1ae4de0c EP |
174 | { |
175 | int ret; | |
176 | u32 len; | |
177 | char *secctx; | |
178 | ||
179 | ret = security_secid_to_secctx(ct->secmark, &secctx, &len); | |
180 | if (ret) | |
e71456ae | 181 | return; |
1ae4de0c | 182 | |
e71456ae | 183 | seq_printf(s, "secctx=%s ", secctx); |
1ae4de0c EP |
184 | |
185 | security_release_secctx(secctx, len); | |
1ae4de0c EP |
186 | } |
187 | #else | |
e71456ae | 188 | static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) |
1ae4de0c | 189 | { |
1ae4de0c EP |
190 | } |
191 | #endif | |
192 | ||
308ac914 | 193 | #ifdef CONFIG_NF_CONNTRACK_ZONES |
deedb590 DB |
194 | static void ct_show_zone(struct seq_file *s, const struct nf_conn *ct, |
195 | int dir) | |
308ac914 | 196 | { |
deedb590 DB |
197 | const struct nf_conntrack_zone *zone = nf_ct_zone(ct); |
198 | ||
199 | if (zone->dir != dir) | |
200 | return; | |
201 | switch (zone->dir) { | |
202 | case NF_CT_DEFAULT_ZONE_DIR: | |
203 | seq_printf(s, "zone=%u ", zone->id); | |
204 | break; | |
205 | case NF_CT_ZONE_DIR_ORIG: | |
206 | seq_printf(s, "zone-orig=%u ", zone->id); | |
207 | break; | |
208 | case NF_CT_ZONE_DIR_REPL: | |
209 | seq_printf(s, "zone-reply=%u ", zone->id); | |
210 | break; | |
211 | default: | |
212 | break; | |
213 | } | |
308ac914 DB |
214 | } |
215 | #else | |
deedb590 DB |
216 | static inline void ct_show_zone(struct seq_file *s, const struct nf_conn *ct, |
217 | int dir) | |
308ac914 DB |
218 | { |
219 | } | |
220 | #endif | |
221 | ||
a992ca2a | 222 | #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP |
e71456ae | 223 | static void ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct) |
a992ca2a | 224 | { |
f5c88f56 | 225 | struct ct_iter_state *st = s->private; |
a992ca2a | 226 | struct nf_conn_tstamp *tstamp; |
f5c88f56 | 227 | s64 delta_time; |
a992ca2a PNA |
228 | |
229 | tstamp = nf_conn_tstamp_find(ct); | |
230 | if (tstamp) { | |
f5c88f56 PM |
231 | delta_time = st->time_now - tstamp->start; |
232 | if (delta_time > 0) | |
233 | delta_time = div_s64(delta_time, NSEC_PER_SEC); | |
234 | else | |
235 | delta_time = 0; | |
236 | ||
e71456ae SRRH |
237 | seq_printf(s, "delta-time=%llu ", |
238 | (unsigned long long)delta_time); | |
a992ca2a | 239 | } |
e71456ae | 240 | return; |
a992ca2a PNA |
241 | } |
242 | #else | |
e71456ae | 243 | static inline void |
a992ca2a PNA |
244 | ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct) |
245 | { | |
a992ca2a PNA |
246 | } |
247 | #endif | |
248 | ||
a3134d53 FW |
249 | static const char* l3proto_name(u16 proto) |
250 | { | |
251 | switch (proto) { | |
252 | case AF_INET: return "ipv4"; | |
253 | case AF_INET6: return "ipv6"; | |
254 | } | |
255 | ||
256 | return "unknown"; | |
257 | } | |
258 | ||
09ec82f5 FW |
259 | static const char* l4proto_name(u16 proto) |
260 | { | |
261 | switch (proto) { | |
262 | case IPPROTO_ICMP: return "icmp"; | |
263 | case IPPROTO_TCP: return "tcp"; | |
264 | case IPPROTO_UDP: return "udp"; | |
265 | case IPPROTO_DCCP: return "dccp"; | |
266 | case IPPROTO_GRE: return "gre"; | |
267 | case IPPROTO_SCTP: return "sctp"; | |
268 | case IPPROTO_UDPLITE: return "udplite"; | |
fbea3180 | 269 | case IPPROTO_ICMPV6: return "icmpv6"; |
09ec82f5 FW |
270 | } |
271 | ||
272 | return "unknown"; | |
273 | } | |
274 | ||
4b216e21 FW |
275 | static unsigned int |
276 | seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir) | |
277 | { | |
278 | struct nf_conn_acct *acct; | |
279 | struct nf_conn_counter *counter; | |
280 | ||
281 | acct = nf_conn_acct_find(ct); | |
282 | if (!acct) | |
283 | return 0; | |
284 | ||
285 | counter = acct->counter; | |
286 | seq_printf(s, "packets=%llu bytes=%llu ", | |
287 | (unsigned long long)atomic64_read(&counter[dir].packets), | |
288 | (unsigned long long)atomic64_read(&counter[dir].bytes)); | |
289 | ||
290 | return 0; | |
291 | } | |
292 | ||
9fb9cbb1 YK |
293 | /* return 0 on success, 1 in case of error */ |
294 | static int ct_seq_show(struct seq_file *s, void *v) | |
295 | { | |
ea781f19 ED |
296 | struct nf_conntrack_tuple_hash *hash = v; |
297 | struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash); | |
32948588 | 298 | const struct nf_conntrack_l4proto *l4proto; |
e77e6ff5 | 299 | struct net *net = seq_file_net(s); |
ea781f19 | 300 | int ret = 0; |
9fb9cbb1 | 301 | |
44d6e2f2 | 302 | WARN_ON(!ct); |
ea781f19 ED |
303 | if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use))) |
304 | return 0; | |
9fb9cbb1 | 305 | |
58e207e4 FW |
306 | if (nf_ct_should_gc(ct)) { |
307 | nf_ct_kill(ct); | |
308 | goto release; | |
309 | } | |
310 | ||
9fb9cbb1 YK |
311 | /* we only want to print DIR_ORIGINAL */ |
312 | if (NF_CT_DIRECTION(hash)) | |
ea781f19 | 313 | goto release; |
9fb9cbb1 | 314 | |
e77e6ff5 LZ |
315 | if (!net_eq(nf_ct_net(ct), net)) |
316 | goto release; | |
317 | ||
4a60dc74 | 318 | l4proto = nf_ct_l4proto_find(nf_ct_protonum(ct)); |
9fb9cbb1 | 319 | |
ea781f19 | 320 | ret = -ENOSPC; |
90964016 | 321 | seq_printf(s, "%-8s %u %-8s %u ", |
f957be9d | 322 | l3proto_name(nf_ct_l3num(ct)), nf_ct_l3num(ct), |
90964016 PNA |
323 | l4proto_name(l4proto->l4proto), nf_ct_protonum(ct)); |
324 | ||
325 | if (!test_bit(IPS_OFFLOAD_BIT, &ct->status)) | |
326 | seq_printf(s, "%ld ", nf_ct_expires(ct) / HZ); | |
9fb9cbb1 | 327 | |
37246a58 SRRH |
328 | if (l4proto->print_conntrack) |
329 | l4proto->print_conntrack(s, ct); | |
9fb9cbb1 | 330 | |
824f1fbe | 331 | print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, |
f957be9d | 332 | l4proto); |
9fb9cbb1 | 333 | |
deedb590 DB |
334 | ct_show_zone(s, ct, NF_CT_ZONE_DIR_ORIG); |
335 | ||
e71456ae SRRH |
336 | if (seq_has_overflowed(s)) |
337 | goto release; | |
338 | ||
58401572 | 339 | if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL)) |
ea781f19 | 340 | goto release; |
9fb9cbb1 | 341 | |
c88130bc | 342 | if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) |
cdec2685 | 343 | seq_puts(s, "[UNREPLIED] "); |
9fb9cbb1 | 344 | |
f957be9d | 345 | print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, l4proto); |
9fb9cbb1 | 346 | |
deedb590 DB |
347 | ct_show_zone(s, ct, NF_CT_ZONE_DIR_REPL); |
348 | ||
58401572 | 349 | if (seq_print_acct(s, ct, IP_CT_DIR_REPLY)) |
ea781f19 | 350 | goto release; |
9fb9cbb1 | 351 | |
74f99482 BW |
352 | if (test_bit(IPS_HW_OFFLOAD_BIT, &ct->status)) |
353 | seq_puts(s, "[HW_OFFLOAD] "); | |
354 | else if (test_bit(IPS_OFFLOAD_BIT, &ct->status)) | |
90964016 PNA |
355 | seq_puts(s, "[OFFLOAD] "); |
356 | else if (test_bit(IPS_ASSURED_BIT, &ct->status)) | |
cdec2685 | 357 | seq_puts(s, "[ASSURED] "); |
9fb9cbb1 | 358 | |
e71456ae | 359 | if (seq_has_overflowed(s)) |
ea781f19 | 360 | goto release; |
e71456ae SRRH |
361 | |
362 | #if defined(CONFIG_NF_CONNTRACK_MARK) | |
363 | seq_printf(s, "mark=%u ", ct->mark); | |
9fb9cbb1 YK |
364 | #endif |
365 | ||
e71456ae | 366 | ct_show_secctx(s, ct); |
deedb590 | 367 | ct_show_zone(s, ct, NF_CT_DEFAULT_ZONE_DIR); |
e71456ae SRRH |
368 | ct_show_delta_time(s, ct); |
369 | ||
370 | seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)); | |
a992ca2a | 371 | |
e71456ae | 372 | if (seq_has_overflowed(s)) |
ea781f19 | 373 | goto release; |
a5d29264 | 374 | |
ea781f19 ED |
375 | ret = 0; |
376 | release: | |
377 | nf_ct_put(ct); | |
d88d7de0 | 378 | return ret; |
9fb9cbb1 YK |
379 | } |
380 | ||
56b3d975 | 381 | static const struct seq_operations ct_seq_ops = { |
9fb9cbb1 YK |
382 | .start = ct_seq_start, |
383 | .next = ct_seq_next, | |
384 | .stop = ct_seq_stop, | |
385 | .show = ct_seq_show | |
386 | }; | |
387 | ||
9fb9cbb1 YK |
388 | static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos) |
389 | { | |
8e9df801 | 390 | struct net *net = seq_file_net(seq); |
9fb9cbb1 YK |
391 | int cpu; |
392 | ||
393 | if (*pos == 0) | |
394 | return SEQ_START_TOKEN; | |
395 | ||
0f23174a | 396 | for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) { |
9fb9cbb1 YK |
397 | if (!cpu_possible(cpu)) |
398 | continue; | |
399 | *pos = cpu + 1; | |
8e9df801 | 400 | return per_cpu_ptr(net->ct.stat, cpu); |
9fb9cbb1 YK |
401 | } |
402 | ||
403 | return NULL; | |
404 | } | |
405 | ||
406 | static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
407 | { | |
8e9df801 | 408 | struct net *net = seq_file_net(seq); |
9fb9cbb1 YK |
409 | int cpu; |
410 | ||
0f23174a | 411 | for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) { |
9fb9cbb1 YK |
412 | if (!cpu_possible(cpu)) |
413 | continue; | |
414 | *pos = cpu + 1; | |
8e9df801 | 415 | return per_cpu_ptr(net->ct.stat, cpu); |
9fb9cbb1 | 416 | } |
dc15af8e | 417 | (*pos)++; |
9fb9cbb1 YK |
418 | return NULL; |
419 | } | |
420 | ||
421 | static void ct_cpu_seq_stop(struct seq_file *seq, void *v) | |
422 | { | |
423 | } | |
424 | ||
425 | static int ct_cpu_seq_show(struct seq_file *seq, void *v) | |
426 | { | |
8e9df801 | 427 | struct net *net = seq_file_net(seq); |
32948588 | 428 | const struct ip_conntrack_stat *st = v; |
c53bd0e9 | 429 | unsigned int nr_conntracks; |
9fb9cbb1 YK |
430 | |
431 | if (v == SEQ_START_TOKEN) { | |
1702ad79 | 432 | seq_puts(seq, "entries clashres found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error expect_new expect_create expect_delete search_restart\n"); |
9fb9cbb1 YK |
433 | return 0; |
434 | } | |
435 | ||
c53bd0e9 FW |
436 | nr_conntracks = nf_conntrack_count(net); |
437 | ||
9fb9cbb1 | 438 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x " |
af740b2c | 439 | "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n", |
9fb9cbb1 | 440 | nr_conntracks, |
1702ad79 | 441 | st->clash_resolve, |
9fb9cbb1 | 442 | st->found, |
8e8118f8 | 443 | 0, |
9fb9cbb1 | 444 | st->invalid, |
4afc41df | 445 | 0, |
8e8118f8 FW |
446 | 0, |
447 | 0, | |
9fb9cbb1 YK |
448 | st->insert, |
449 | st->insert_failed, | |
450 | st->drop, | |
451 | st->early_drop, | |
452 | st->error, | |
453 | ||
454 | st->expect_new, | |
455 | st->expect_create, | |
af740b2c JDB |
456 | st->expect_delete, |
457 | st->search_restart | |
9fb9cbb1 YK |
458 | ); |
459 | return 0; | |
460 | } | |
461 | ||
56b3d975 | 462 | static const struct seq_operations ct_cpu_seq_ops = { |
9fb9cbb1 YK |
463 | .start = ct_cpu_seq_start, |
464 | .next = ct_cpu_seq_next, | |
465 | .stop = ct_cpu_seq_stop, | |
466 | .show = ct_cpu_seq_show, | |
467 | }; | |
468 | ||
b2ce2c74 | 469 | static int nf_conntrack_standalone_init_proc(struct net *net) |
b916f7d4 AD |
470 | { |
471 | struct proc_dir_entry *pde; | |
f13f2aee PW |
472 | kuid_t root_uid; |
473 | kgid_t root_gid; | |
b916f7d4 | 474 | |
c3506372 CH |
475 | pde = proc_create_net("nf_conntrack", 0440, net->proc_net, &ct_seq_ops, |
476 | sizeof(struct ct_iter_state)); | |
b916f7d4 AD |
477 | if (!pde) |
478 | goto out_nf_conntrack; | |
52c0e111 | 479 | |
f13f2aee PW |
480 | root_uid = make_kuid(net->user_ns, 0); |
481 | root_gid = make_kgid(net->user_ns, 0); | |
482 | if (uid_valid(root_uid) && gid_valid(root_gid)) | |
483 | proc_set_user(pde, root_uid, root_gid); | |
484 | ||
c3506372 CH |
485 | pde = proc_create_net("nf_conntrack", 0444, net->proc_net_stat, |
486 | &ct_cpu_seq_ops, sizeof(struct seq_net_private)); | |
b916f7d4 AD |
487 | if (!pde) |
488 | goto out_stat_nf_conntrack; | |
b916f7d4 AD |
489 | return 0; |
490 | ||
491 | out_stat_nf_conntrack: | |
ece31ffd | 492 | remove_proc_entry("nf_conntrack", net->proc_net); |
b916f7d4 AD |
493 | out_nf_conntrack: |
494 | return -ENOMEM; | |
495 | } | |
496 | ||
b2ce2c74 | 497 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
b916f7d4 | 498 | { |
b2ce2c74 | 499 | remove_proc_entry("nf_conntrack", net->proc_net_stat); |
ece31ffd | 500 | remove_proc_entry("nf_conntrack", net->proc_net); |
b916f7d4 AD |
501 | } |
502 | #else | |
b2ce2c74 | 503 | static int nf_conntrack_standalone_init_proc(struct net *net) |
b916f7d4 AD |
504 | { |
505 | return 0; | |
506 | } | |
507 | ||
b2ce2c74 | 508 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
b916f7d4 AD |
509 | { |
510 | } | |
54b07dca | 511 | #endif /* CONFIG_NF_CONNTRACK_PROCFS */ |
9fb9cbb1 | 512 | |
c53bd0e9 FW |
513 | u32 nf_conntrack_count(const struct net *net) |
514 | { | |
515 | const struct nf_conntrack_net *cnet; | |
516 | ||
517 | cnet = net_generic(net, nf_conntrack_net_id); | |
518 | ||
519 | return atomic_read(&cnet->count); | |
520 | } | |
521 | EXPORT_SYMBOL_GPL(nf_conntrack_count); | |
522 | ||
9fb9cbb1 YK |
523 | /* Sysctl support */ |
524 | ||
525 | #ifdef CONFIG_SYSCTL | |
3183ab89 FW |
526 | /* size the user *wants to set */ |
527 | static unsigned int nf_conntrack_htable_size_user __read_mostly; | |
528 | ||
529 | static int | |
530 | nf_conntrack_hash_sysctl(struct ctl_table *table, int write, | |
32927393 | 531 | void *buffer, size_t *lenp, loff_t *ppos) |
3183ab89 FW |
532 | { |
533 | int ret; | |
534 | ||
f6351c3f JDB |
535 | /* module_param hashsize could have changed value */ |
536 | nf_conntrack_htable_size_user = nf_conntrack_htable_size; | |
537 | ||
3183ab89 FW |
538 | ret = proc_dointvec(table, write, buffer, lenp, ppos); |
539 | if (ret < 0 || !write) | |
540 | return ret; | |
541 | ||
542 | /* update ret, we might not be able to satisfy request */ | |
543 | ret = nf_conntrack_hash_resize(nf_conntrack_htable_size_user); | |
544 | ||
545 | /* update it to the actual value used by conntrack */ | |
546 | nf_conntrack_htable_size_user = nf_conntrack_htable_size; | |
547 | return ret; | |
548 | } | |
9fb9cbb1 | 549 | |
9714be7d | 550 | static struct ctl_table_header *nf_ct_netfilter_header; |
9fb9cbb1 | 551 | |
4a65798a FW |
552 | enum nf_ct_sysctl_index { |
553 | NF_SYSCTL_CT_MAX, | |
554 | NF_SYSCTL_CT_COUNT, | |
555 | NF_SYSCTL_CT_BUCKETS, | |
556 | NF_SYSCTL_CT_CHECKSUM, | |
557 | NF_SYSCTL_CT_LOG_INVALID, | |
558 | NF_SYSCTL_CT_EXPECT_MAX, | |
d912dec1 FW |
559 | NF_SYSCTL_CT_ACCT, |
560 | NF_SYSCTL_CT_HELPER, | |
cb2833ed FW |
561 | #ifdef CONFIG_NF_CONNTRACK_EVENTS |
562 | NF_SYSCTL_CT_EVENTS, | |
563 | #endif | |
564 | #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP | |
565 | NF_SYSCTL_CT_TIMESTAMP, | |
566 | #endif | |
b884fa46 FW |
567 | NF_SYSCTL_CT_PROTO_TIMEOUT_GENERIC, |
568 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_SYN_SENT, | |
569 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_SYN_RECV, | |
570 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_ESTABLISHED, | |
571 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_FIN_WAIT, | |
572 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_CLOSE_WAIT, | |
573 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_LAST_ACK, | |
574 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_TIME_WAIT, | |
575 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_CLOSE, | |
576 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_RETRANS, | |
577 | NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_UNACK, | |
578 | NF_SYSCTL_CT_PROTO_TCP_LOOSE, | |
579 | NF_SYSCTL_CT_PROTO_TCP_LIBERAL, | |
580 | NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS, | |
581 | NF_SYSCTL_CT_PROTO_TIMEOUT_UDP, | |
582 | NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_STREAM, | |
583 | NF_SYSCTL_CT_PROTO_TIMEOUT_ICMP, | |
584 | NF_SYSCTL_CT_PROTO_TIMEOUT_ICMPV6, | |
585 | #ifdef CONFIG_NF_CT_PROTO_SCTP | |
586 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_CLOSED, | |
587 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_COOKIE_WAIT, | |
588 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_COOKIE_ECHOED, | |
589 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_ESTABLISHED, | |
590 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_SHUTDOWN_SENT, | |
591 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_SHUTDOWN_RECD, | |
592 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_SHUTDOWN_ACK_SENT, | |
593 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_HEARTBEAT_SENT, | |
594 | NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_HEARTBEAT_ACKED, | |
595 | #endif | |
596 | #ifdef CONFIG_NF_CT_PROTO_DCCP | |
597 | NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_REQUEST, | |
598 | NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_RESPOND, | |
599 | NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_PARTOPEN, | |
600 | NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_OPEN, | |
601 | NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_CLOSEREQ, | |
602 | NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_CLOSING, | |
603 | NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_TIMEWAIT, | |
604 | NF_SYSCTL_CT_PROTO_DCCP_LOOSE, | |
605 | #endif | |
606 | #ifdef CONFIG_NF_CT_PROTO_GRE | |
607 | NF_SYSCTL_CT_PROTO_TIMEOUT_GRE, | |
608 | NF_SYSCTL_CT_PROTO_TIMEOUT_GRE_STREAM, | |
609 | #endif | |
610 | ||
611 | __NF_SYSCTL_CT_LAST_SYSCTL, | |
4a65798a FW |
612 | }; |
613 | ||
b884fa46 FW |
614 | #define NF_SYSCTL_CT_LAST_SYSCTL (__NF_SYSCTL_CT_LAST_SYSCTL + 1) |
615 | ||
fe2c6338 | 616 | static struct ctl_table nf_ct_sysctl_table[] = { |
4a65798a | 617 | [NF_SYSCTL_CT_MAX] = { |
9fb9cbb1 YK |
618 | .procname = "nf_conntrack_max", |
619 | .data = &nf_conntrack_max, | |
620 | .maxlen = sizeof(int), | |
621 | .mode = 0644, | |
6d9f239a | 622 | .proc_handler = proc_dointvec, |
9fb9cbb1 | 623 | }, |
4a65798a | 624 | [NF_SYSCTL_CT_COUNT] = { |
9fb9cbb1 | 625 | .procname = "nf_conntrack_count", |
9fb9cbb1 YK |
626 | .maxlen = sizeof(int), |
627 | .mode = 0444, | |
6d9f239a | 628 | .proc_handler = proc_dointvec, |
9fb9cbb1 | 629 | }, |
4a65798a | 630 | [NF_SYSCTL_CT_BUCKETS] = { |
9fb9cbb1 | 631 | .procname = "nf_conntrack_buckets", |
3183ab89 | 632 | .data = &nf_conntrack_htable_size_user, |
9fb9cbb1 | 633 | .maxlen = sizeof(unsigned int), |
3183ab89 FW |
634 | .mode = 0644, |
635 | .proc_handler = nf_conntrack_hash_sysctl, | |
9fb9cbb1 | 636 | }, |
4a65798a | 637 | [NF_SYSCTL_CT_CHECKSUM] = { |
39a27a35 | 638 | .procname = "nf_conntrack_checksum", |
c04d0552 | 639 | .data = &init_net.ct.sysctl_checksum, |
9b1a4d0f | 640 | .maxlen = sizeof(u8), |
39a27a35 | 641 | .mode = 0644, |
9b1a4d0f | 642 | .proc_handler = proc_dou8vec_minmax, |
e84fb4b3 MC |
643 | .extra1 = SYSCTL_ZERO, |
644 | .extra2 = SYSCTL_ONE, | |
39a27a35 | 645 | }, |
4a65798a | 646 | [NF_SYSCTL_CT_LOG_INVALID] = { |
9fb9cbb1 | 647 | .procname = "nf_conntrack_log_invalid", |
c2a2c7e0 | 648 | .data = &init_net.ct.sysctl_log_invalid, |
9b1a4d0f | 649 | .maxlen = sizeof(u8), |
9fb9cbb1 | 650 | .mode = 0644, |
9b1a4d0f | 651 | .proc_handler = proc_dou8vec_minmax, |
9fb9cbb1 | 652 | }, |
4a65798a | 653 | [NF_SYSCTL_CT_EXPECT_MAX] = { |
f264a7df PM |
654 | .procname = "nf_conntrack_expect_max", |
655 | .data = &nf_ct_expect_max, | |
656 | .maxlen = sizeof(int), | |
657 | .mode = 0644, | |
6d9f239a | 658 | .proc_handler = proc_dointvec, |
f264a7df | 659 | }, |
d912dec1 FW |
660 | [NF_SYSCTL_CT_ACCT] = { |
661 | .procname = "nf_conntrack_acct", | |
662 | .data = &init_net.ct.sysctl_acct, | |
9b1a4d0f | 663 | .maxlen = sizeof(u8), |
d912dec1 | 664 | .mode = 0644, |
9b1a4d0f | 665 | .proc_handler = proc_dou8vec_minmax, |
e84fb4b3 MC |
666 | .extra1 = SYSCTL_ZERO, |
667 | .extra2 = SYSCTL_ONE, | |
d912dec1 FW |
668 | }, |
669 | [NF_SYSCTL_CT_HELPER] = { | |
670 | .procname = "nf_conntrack_helper", | |
67f28216 | 671 | .maxlen = sizeof(u8), |
d912dec1 | 672 | .mode = 0644, |
67f28216 | 673 | .proc_handler = proc_dou8vec_minmax, |
e84fb4b3 MC |
674 | .extra1 = SYSCTL_ZERO, |
675 | .extra2 = SYSCTL_ONE, | |
d912dec1 | 676 | }, |
cb2833ed FW |
677 | #ifdef CONFIG_NF_CONNTRACK_EVENTS |
678 | [NF_SYSCTL_CT_EVENTS] = { | |
679 | .procname = "nf_conntrack_events", | |
680 | .data = &init_net.ct.sysctl_events, | |
9b1a4d0f | 681 | .maxlen = sizeof(u8), |
cb2833ed | 682 | .mode = 0644, |
9b1a4d0f | 683 | .proc_handler = proc_dou8vec_minmax, |
e84fb4b3 MC |
684 | .extra1 = SYSCTL_ZERO, |
685 | .extra2 = SYSCTL_ONE, | |
cb2833ed FW |
686 | }, |
687 | #endif | |
688 | #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP | |
689 | [NF_SYSCTL_CT_TIMESTAMP] = { | |
690 | .procname = "nf_conntrack_timestamp", | |
691 | .data = &init_net.ct.sysctl_tstamp, | |
9b1a4d0f | 692 | .maxlen = sizeof(u8), |
cb2833ed | 693 | .mode = 0644, |
9b1a4d0f | 694 | .proc_handler = proc_dou8vec_minmax, |
e84fb4b3 MC |
695 | .extra1 = SYSCTL_ZERO, |
696 | .extra2 = SYSCTL_ONE, | |
cb2833ed FW |
697 | }, |
698 | #endif | |
b884fa46 FW |
699 | [NF_SYSCTL_CT_PROTO_TIMEOUT_GENERIC] = { |
700 | .procname = "nf_conntrack_generic_timeout", | |
701 | .maxlen = sizeof(unsigned int), | |
702 | .mode = 0644, | |
703 | .proc_handler = proc_dointvec_jiffies, | |
704 | }, | |
705 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_SYN_SENT] = { | |
706 | .procname = "nf_conntrack_tcp_timeout_syn_sent", | |
707 | .maxlen = sizeof(unsigned int), | |
708 | .mode = 0644, | |
709 | .proc_handler = proc_dointvec_jiffies, | |
710 | }, | |
711 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_SYN_RECV] = { | |
712 | .procname = "nf_conntrack_tcp_timeout_syn_recv", | |
713 | .maxlen = sizeof(unsigned int), | |
714 | .mode = 0644, | |
715 | .proc_handler = proc_dointvec_jiffies, | |
716 | }, | |
717 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_ESTABLISHED] = { | |
718 | .procname = "nf_conntrack_tcp_timeout_established", | |
719 | .maxlen = sizeof(unsigned int), | |
720 | .mode = 0644, | |
721 | .proc_handler = proc_dointvec_jiffies, | |
722 | }, | |
723 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_FIN_WAIT] = { | |
724 | .procname = "nf_conntrack_tcp_timeout_fin_wait", | |
725 | .maxlen = sizeof(unsigned int), | |
726 | .mode = 0644, | |
727 | .proc_handler = proc_dointvec_jiffies, | |
728 | }, | |
729 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_CLOSE_WAIT] = { | |
730 | .procname = "nf_conntrack_tcp_timeout_close_wait", | |
731 | .maxlen = sizeof(unsigned int), | |
732 | .mode = 0644, | |
733 | .proc_handler = proc_dointvec_jiffies, | |
734 | }, | |
735 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_LAST_ACK] = { | |
736 | .procname = "nf_conntrack_tcp_timeout_last_ack", | |
737 | .maxlen = sizeof(unsigned int), | |
738 | .mode = 0644, | |
739 | .proc_handler = proc_dointvec_jiffies, | |
740 | }, | |
741 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_TIME_WAIT] = { | |
742 | .procname = "nf_conntrack_tcp_timeout_time_wait", | |
743 | .maxlen = sizeof(unsigned int), | |
744 | .mode = 0644, | |
745 | .proc_handler = proc_dointvec_jiffies, | |
746 | }, | |
747 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_CLOSE] = { | |
748 | .procname = "nf_conntrack_tcp_timeout_close", | |
749 | .maxlen = sizeof(unsigned int), | |
750 | .mode = 0644, | |
751 | .proc_handler = proc_dointvec_jiffies, | |
752 | }, | |
753 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_RETRANS] = { | |
754 | .procname = "nf_conntrack_tcp_timeout_max_retrans", | |
755 | .maxlen = sizeof(unsigned int), | |
756 | .mode = 0644, | |
757 | .proc_handler = proc_dointvec_jiffies, | |
758 | }, | |
759 | [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_UNACK] = { | |
760 | .procname = "nf_conntrack_tcp_timeout_unacknowledged", | |
761 | .maxlen = sizeof(unsigned int), | |
762 | .mode = 0644, | |
763 | .proc_handler = proc_dointvec_jiffies, | |
764 | }, | |
765 | [NF_SYSCTL_CT_PROTO_TCP_LOOSE] = { | |
766 | .procname = "nf_conntrack_tcp_loose", | |
9b1a4d0f | 767 | .maxlen = sizeof(u8), |
b884fa46 | 768 | .mode = 0644, |
9b1a4d0f | 769 | .proc_handler = proc_dou8vec_minmax, |
e84fb4b3 MC |
770 | .extra1 = SYSCTL_ZERO, |
771 | .extra2 = SYSCTL_ONE, | |
b884fa46 FW |
772 | }, |
773 | [NF_SYSCTL_CT_PROTO_TCP_LIBERAL] = { | |
774 | .procname = "nf_conntrack_tcp_be_liberal", | |
9b1a4d0f | 775 | .maxlen = sizeof(u8), |
b884fa46 | 776 | .mode = 0644, |
9b1a4d0f | 777 | .proc_handler = proc_dou8vec_minmax, |
e84fb4b3 MC |
778 | .extra1 = SYSCTL_ZERO, |
779 | .extra2 = SYSCTL_ONE, | |
b884fa46 FW |
780 | }, |
781 | [NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS] = { | |
782 | .procname = "nf_conntrack_tcp_max_retrans", | |
9b1a4d0f | 783 | .maxlen = sizeof(u8), |
b884fa46 | 784 | .mode = 0644, |
9b1a4d0f | 785 | .proc_handler = proc_dou8vec_minmax, |
b884fa46 FW |
786 | }, |
787 | [NF_SYSCTL_CT_PROTO_TIMEOUT_UDP] = { | |
788 | .procname = "nf_conntrack_udp_timeout", | |
789 | .maxlen = sizeof(unsigned int), | |
790 | .mode = 0644, | |
791 | .proc_handler = proc_dointvec_jiffies, | |
792 | }, | |
793 | [NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_STREAM] = { | |
794 | .procname = "nf_conntrack_udp_timeout_stream", | |
795 | .maxlen = sizeof(unsigned int), | |
796 | .mode = 0644, | |
797 | .proc_handler = proc_dointvec_jiffies, | |
798 | }, | |
799 | [NF_SYSCTL_CT_PROTO_TIMEOUT_ICMP] = { | |
800 | .procname = "nf_conntrack_icmp_timeout", | |
801 | .maxlen = sizeof(unsigned int), | |
802 | .mode = 0644, | |
803 | .proc_handler = proc_dointvec_jiffies, | |
804 | }, | |
805 | [NF_SYSCTL_CT_PROTO_TIMEOUT_ICMPV6] = { | |
806 | .procname = "nf_conntrack_icmpv6_timeout", | |
807 | .maxlen = sizeof(unsigned int), | |
808 | .mode = 0644, | |
809 | .proc_handler = proc_dointvec_jiffies, | |
810 | }, | |
811 | #ifdef CONFIG_NF_CT_PROTO_SCTP | |
812 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_CLOSED] = { | |
813 | .procname = "nf_conntrack_sctp_timeout_closed", | |
814 | .maxlen = sizeof(unsigned int), | |
815 | .mode = 0644, | |
816 | .proc_handler = proc_dointvec_jiffies, | |
817 | }, | |
818 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_COOKIE_WAIT] = { | |
819 | .procname = "nf_conntrack_sctp_timeout_cookie_wait", | |
820 | .maxlen = sizeof(unsigned int), | |
821 | .mode = 0644, | |
822 | .proc_handler = proc_dointvec_jiffies, | |
823 | }, | |
824 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_COOKIE_ECHOED] = { | |
825 | .procname = "nf_conntrack_sctp_timeout_cookie_echoed", | |
826 | .maxlen = sizeof(unsigned int), | |
827 | .mode = 0644, | |
828 | .proc_handler = proc_dointvec_jiffies, | |
829 | }, | |
830 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_ESTABLISHED] = { | |
831 | .procname = "nf_conntrack_sctp_timeout_established", | |
832 | .maxlen = sizeof(unsigned int), | |
833 | .mode = 0644, | |
834 | .proc_handler = proc_dointvec_jiffies, | |
835 | }, | |
836 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_SHUTDOWN_SENT] = { | |
837 | .procname = "nf_conntrack_sctp_timeout_shutdown_sent", | |
838 | .maxlen = sizeof(unsigned int), | |
839 | .mode = 0644, | |
840 | .proc_handler = proc_dointvec_jiffies, | |
841 | }, | |
842 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_SHUTDOWN_RECD] = { | |
843 | .procname = "nf_conntrack_sctp_timeout_shutdown_recd", | |
844 | .maxlen = sizeof(unsigned int), | |
845 | .mode = 0644, | |
846 | .proc_handler = proc_dointvec_jiffies, | |
847 | }, | |
848 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_SHUTDOWN_ACK_SENT] = { | |
849 | .procname = "nf_conntrack_sctp_timeout_shutdown_ack_sent", | |
850 | .maxlen = sizeof(unsigned int), | |
851 | .mode = 0644, | |
852 | .proc_handler = proc_dointvec_jiffies, | |
853 | }, | |
854 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_HEARTBEAT_SENT] = { | |
855 | .procname = "nf_conntrack_sctp_timeout_heartbeat_sent", | |
856 | .maxlen = sizeof(unsigned int), | |
857 | .mode = 0644, | |
858 | .proc_handler = proc_dointvec_jiffies, | |
859 | }, | |
860 | [NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_HEARTBEAT_ACKED] = { | |
861 | .procname = "nf_conntrack_sctp_timeout_heartbeat_acked", | |
862 | .maxlen = sizeof(unsigned int), | |
863 | .mode = 0644, | |
864 | .proc_handler = proc_dointvec_jiffies, | |
865 | }, | |
866 | #endif | |
867 | #ifdef CONFIG_NF_CT_PROTO_DCCP | |
868 | [NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_REQUEST] = { | |
869 | .procname = "nf_conntrack_dccp_timeout_request", | |
870 | .maxlen = sizeof(unsigned int), | |
871 | .mode = 0644, | |
872 | .proc_handler = proc_dointvec_jiffies, | |
873 | }, | |
874 | [NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_RESPOND] = { | |
875 | .procname = "nf_conntrack_dccp_timeout_respond", | |
876 | .maxlen = sizeof(unsigned int), | |
877 | .mode = 0644, | |
878 | .proc_handler = proc_dointvec_jiffies, | |
879 | }, | |
880 | [NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_PARTOPEN] = { | |
881 | .procname = "nf_conntrack_dccp_timeout_partopen", | |
882 | .maxlen = sizeof(unsigned int), | |
883 | .mode = 0644, | |
884 | .proc_handler = proc_dointvec_jiffies, | |
885 | }, | |
886 | [NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_OPEN] = { | |
887 | .procname = "nf_conntrack_dccp_timeout_open", | |
888 | .maxlen = sizeof(unsigned int), | |
889 | .mode = 0644, | |
890 | .proc_handler = proc_dointvec_jiffies, | |
891 | }, | |
892 | [NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_CLOSEREQ] = { | |
893 | .procname = "nf_conntrack_dccp_timeout_closereq", | |
894 | .maxlen = sizeof(unsigned int), | |
895 | .mode = 0644, | |
896 | .proc_handler = proc_dointvec_jiffies, | |
897 | }, | |
898 | [NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_CLOSING] = { | |
899 | .procname = "nf_conntrack_dccp_timeout_closing", | |
900 | .maxlen = sizeof(unsigned int), | |
901 | .mode = 0644, | |
902 | .proc_handler = proc_dointvec_jiffies, | |
903 | }, | |
904 | [NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_TIMEWAIT] = { | |
905 | .procname = "nf_conntrack_dccp_timeout_timewait", | |
906 | .maxlen = sizeof(unsigned int), | |
907 | .mode = 0644, | |
908 | .proc_handler = proc_dointvec_jiffies, | |
909 | }, | |
910 | [NF_SYSCTL_CT_PROTO_DCCP_LOOSE] = { | |
911 | .procname = "nf_conntrack_dccp_loose", | |
9b1a4d0f | 912 | .maxlen = sizeof(u8), |
b884fa46 | 913 | .mode = 0644, |
9b1a4d0f | 914 | .proc_handler = proc_dou8vec_minmax, |
e84fb4b3 MC |
915 | .extra1 = SYSCTL_ZERO, |
916 | .extra2 = SYSCTL_ONE, | |
b884fa46 FW |
917 | }, |
918 | #endif | |
919 | #ifdef CONFIG_NF_CT_PROTO_GRE | |
920 | [NF_SYSCTL_CT_PROTO_TIMEOUT_GRE] = { | |
921 | .procname = "nf_conntrack_gre_timeout", | |
922 | .maxlen = sizeof(unsigned int), | |
923 | .mode = 0644, | |
924 | .proc_handler = proc_dointvec_jiffies, | |
925 | }, | |
926 | [NF_SYSCTL_CT_PROTO_TIMEOUT_GRE_STREAM] = { | |
927 | .procname = "nf_conntrack_gre_timeout_stream", | |
928 | .maxlen = sizeof(unsigned int), | |
929 | .mode = 0644, | |
930 | .proc_handler = proc_dointvec_jiffies, | |
931 | }, | |
932 | #endif | |
933 | {} | |
9fb9cbb1 YK |
934 | }; |
935 | ||
fe2c6338 | 936 | static struct ctl_table nf_ct_netfilter_table[] = { |
9fb9cbb1 | 937 | { |
9fb9cbb1 YK |
938 | .procname = "nf_conntrack_max", |
939 | .data = &nf_conntrack_max, | |
940 | .maxlen = sizeof(int), | |
941 | .mode = 0644, | |
6d9f239a | 942 | .proc_handler = proc_dointvec, |
9fb9cbb1 | 943 | }, |
f8572d8f | 944 | { } |
9fb9cbb1 YK |
945 | }; |
946 | ||
b884fa46 FW |
947 | static void nf_conntrack_standalone_init_tcp_sysctl(struct net *net, |
948 | struct ctl_table *table) | |
949 | { | |
950 | struct nf_tcp_net *tn = nf_tcp_pernet(net); | |
951 | ||
952 | #define XASSIGN(XNAME, tn) \ | |
953 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_ ## XNAME].data = \ | |
954 | &(tn)->timeouts[TCP_CONNTRACK_ ## XNAME] | |
955 | ||
956 | XASSIGN(SYN_SENT, tn); | |
957 | XASSIGN(SYN_RECV, tn); | |
958 | XASSIGN(ESTABLISHED, tn); | |
959 | XASSIGN(FIN_WAIT, tn); | |
960 | XASSIGN(CLOSE_WAIT, tn); | |
961 | XASSIGN(LAST_ACK, tn); | |
962 | XASSIGN(TIME_WAIT, tn); | |
963 | XASSIGN(CLOSE, tn); | |
964 | XASSIGN(RETRANS, tn); | |
965 | XASSIGN(UNACK, tn); | |
966 | #undef XASSIGN | |
967 | #define XASSIGN(XNAME, rval) \ | |
968 | table[NF_SYSCTL_CT_PROTO_TCP_ ## XNAME].data = (rval) | |
969 | ||
970 | XASSIGN(LOOSE, &tn->tcp_loose); | |
971 | XASSIGN(LIBERAL, &tn->tcp_be_liberal); | |
972 | XASSIGN(MAX_RETRANS, &tn->tcp_max_retrans); | |
973 | #undef XASSIGN | |
974 | } | |
975 | ||
976 | static void nf_conntrack_standalone_init_sctp_sysctl(struct net *net, | |
977 | struct ctl_table *table) | |
978 | { | |
979 | #ifdef CONFIG_NF_CT_PROTO_SCTP | |
980 | struct nf_sctp_net *sn = nf_sctp_pernet(net); | |
981 | ||
982 | #define XASSIGN(XNAME, sn) \ | |
983 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_SCTP_ ## XNAME].data = \ | |
984 | &(sn)->timeouts[SCTP_CONNTRACK_ ## XNAME] | |
985 | ||
986 | XASSIGN(CLOSED, sn); | |
987 | XASSIGN(COOKIE_WAIT, sn); | |
988 | XASSIGN(COOKIE_ECHOED, sn); | |
989 | XASSIGN(ESTABLISHED, sn); | |
990 | XASSIGN(SHUTDOWN_SENT, sn); | |
991 | XASSIGN(SHUTDOWN_RECD, sn); | |
992 | XASSIGN(SHUTDOWN_ACK_SENT, sn); | |
993 | XASSIGN(HEARTBEAT_SENT, sn); | |
994 | XASSIGN(HEARTBEAT_ACKED, sn); | |
995 | #undef XASSIGN | |
996 | #endif | |
997 | } | |
998 | ||
999 | static void nf_conntrack_standalone_init_dccp_sysctl(struct net *net, | |
1000 | struct ctl_table *table) | |
1001 | { | |
1002 | #ifdef CONFIG_NF_CT_PROTO_DCCP | |
1003 | struct nf_dccp_net *dn = nf_dccp_pernet(net); | |
1004 | ||
1005 | #define XASSIGN(XNAME, dn) \ | |
1006 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_DCCP_ ## XNAME].data = \ | |
1007 | &(dn)->dccp_timeout[CT_DCCP_ ## XNAME] | |
1008 | ||
1009 | XASSIGN(REQUEST, dn); | |
1010 | XASSIGN(RESPOND, dn); | |
1011 | XASSIGN(PARTOPEN, dn); | |
1012 | XASSIGN(OPEN, dn); | |
1013 | XASSIGN(CLOSEREQ, dn); | |
1014 | XASSIGN(CLOSING, dn); | |
1015 | XASSIGN(TIMEWAIT, dn); | |
1016 | #undef XASSIGN | |
1017 | ||
1018 | table[NF_SYSCTL_CT_PROTO_DCCP_LOOSE].data = &dn->dccp_loose; | |
1019 | #endif | |
1020 | } | |
1021 | ||
1022 | static void nf_conntrack_standalone_init_gre_sysctl(struct net *net, | |
1023 | struct ctl_table *table) | |
1024 | { | |
1025 | #ifdef CONFIG_NF_CT_PROTO_GRE | |
1026 | struct nf_gre_net *gn = nf_gre_pernet(net); | |
1027 | ||
1028 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_GRE].data = &gn->timeouts[GRE_CT_UNREPLIED]; | |
1029 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_GRE_STREAM].data = &gn->timeouts[GRE_CT_REPLIED]; | |
1030 | #endif | |
1031 | } | |
1032 | ||
80250707 | 1033 | static int nf_conntrack_standalone_init_sysctl(struct net *net) |
b916f7d4 | 1034 | { |
7b597470 | 1035 | struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id); |
b884fa46 | 1036 | struct nf_udp_net *un = nf_udp_pernet(net); |
80250707 AD |
1037 | struct ctl_table *table; |
1038 | ||
b884fa46 FW |
1039 | BUILD_BUG_ON(ARRAY_SIZE(nf_ct_sysctl_table) != NF_SYSCTL_CT_LAST_SYSCTL); |
1040 | ||
80250707 AD |
1041 | table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table), |
1042 | GFP_KERNEL); | |
1043 | if (!table) | |
b884fa46 | 1044 | return -ENOMEM; |
80250707 | 1045 | |
c53bd0e9 | 1046 | table[NF_SYSCTL_CT_COUNT].data = &cnet->count; |
4a65798a FW |
1047 | table[NF_SYSCTL_CT_CHECKSUM].data = &net->ct.sysctl_checksum; |
1048 | table[NF_SYSCTL_CT_LOG_INVALID].data = &net->ct.sysctl_log_invalid; | |
478553fd | 1049 | table[NF_SYSCTL_CT_ACCT].data = &net->ct.sysctl_acct; |
67f28216 | 1050 | table[NF_SYSCTL_CT_HELPER].data = &cnet->sysctl_auto_assign_helper; |
cb2833ed FW |
1051 | #ifdef CONFIG_NF_CONNTRACK_EVENTS |
1052 | table[NF_SYSCTL_CT_EVENTS].data = &net->ct.sysctl_events; | |
478553fd FW |
1053 | #endif |
1054 | #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP | |
1055 | table[NF_SYSCTL_CT_TIMESTAMP].data = &net->ct.sysctl_tstamp; | |
cb2833ed | 1056 | #endif |
b884fa46 FW |
1057 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_GENERIC].data = &nf_generic_pernet(net)->timeout; |
1058 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_ICMP].data = &nf_icmp_pernet(net)->timeout; | |
1059 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_ICMPV6].data = &nf_icmpv6_pernet(net)->timeout; | |
1060 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_UDP].data = &un->timeouts[UDP_CT_UNREPLIED]; | |
1061 | table[NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_STREAM].data = &un->timeouts[UDP_CT_REPLIED]; | |
1062 | ||
1063 | nf_conntrack_standalone_init_tcp_sysctl(net, table); | |
1064 | nf_conntrack_standalone_init_sctp_sysctl(net, table); | |
1065 | nf_conntrack_standalone_init_dccp_sysctl(net, table); | |
1066 | nf_conntrack_standalone_init_gre_sysctl(net, table); | |
80250707 | 1067 | |
2671fa4d JR |
1068 | /* Don't allow non-init_net ns to alter global sysctls */ |
1069 | if (!net_eq(&init_net, net)) { | |
d0febd81 FW |
1070 | table[NF_SYSCTL_CT_MAX].mode = 0444; |
1071 | table[NF_SYSCTL_CT_EXPECT_MAX].mode = 0444; | |
d0febd81 FW |
1072 | table[NF_SYSCTL_CT_BUCKETS].mode = 0444; |
1073 | } | |
3183ab89 | 1074 | |
7b597470 FW |
1075 | cnet->sysctl_header = register_net_sysctl(net, "net/netfilter", table); |
1076 | if (!cnet->sysctl_header) | |
9714be7d KPO |
1077 | goto out_unregister_netfilter; |
1078 | ||
b916f7d4 AD |
1079 | return 0; |
1080 | ||
9714be7d | 1081 | out_unregister_netfilter: |
80250707 | 1082 | kfree(table); |
9714be7d | 1083 | return -ENOMEM; |
b916f7d4 AD |
1084 | } |
1085 | ||
80250707 | 1086 | static void nf_conntrack_standalone_fini_sysctl(struct net *net) |
b916f7d4 | 1087 | { |
7b597470 | 1088 | struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id); |
80250707 AD |
1089 | struct ctl_table *table; |
1090 | ||
7b597470 FW |
1091 | table = cnet->sysctl_header->ctl_table_arg; |
1092 | unregister_net_sysctl_table(cnet->sysctl_header); | |
80250707 | 1093 | kfree(table); |
b916f7d4 AD |
1094 | } |
1095 | #else | |
80250707 | 1096 | static int nf_conntrack_standalone_init_sysctl(struct net *net) |
b916f7d4 AD |
1097 | { |
1098 | return 0; | |
1099 | } | |
1100 | ||
80250707 | 1101 | static void nf_conntrack_standalone_fini_sysctl(struct net *net) |
b916f7d4 AD |
1102 | { |
1103 | } | |
9fb9cbb1 YK |
1104 | #endif /* CONFIG_SYSCTL */ |
1105 | ||
ba3fbe66 PNA |
1106 | static void nf_conntrack_fini_net(struct net *net) |
1107 | { | |
1108 | if (enable_hooks) | |
1109 | nf_ct_netns_put(net, NFPROTO_INET); | |
1110 | ||
1111 | nf_conntrack_standalone_fini_proc(net); | |
1112 | nf_conntrack_standalone_fini_sysctl(net); | |
1113 | } | |
1114 | ||
f94161c1 | 1115 | static int nf_conntrack_pernet_init(struct net *net) |
dfdb8d79 | 1116 | { |
b2ce2c74 AD |
1117 | int ret; |
1118 | ||
b884fa46 FW |
1119 | net->ct.sysctl_checksum = 1; |
1120 | ||
1121 | ret = nf_conntrack_standalone_init_sysctl(net); | |
b2ce2c74 | 1122 | if (ret < 0) |
b884fa46 | 1123 | return ret; |
f94161c1 | 1124 | |
b2ce2c74 AD |
1125 | ret = nf_conntrack_standalone_init_proc(net); |
1126 | if (ret < 0) | |
1127 | goto out_proc; | |
f94161c1 | 1128 | |
b884fa46 | 1129 | ret = nf_conntrack_init_net(net); |
80250707 | 1130 | if (ret < 0) |
b884fa46 | 1131 | goto out_init_net; |
f94161c1 | 1132 | |
ba3fbe66 PNA |
1133 | if (enable_hooks) { |
1134 | ret = nf_ct_netns_get(net, NFPROTO_INET); | |
1135 | if (ret < 0) | |
1136 | goto out_hooks; | |
1137 | } | |
1138 | ||
b2ce2c74 AD |
1139 | return 0; |
1140 | ||
ba3fbe66 | 1141 | out_hooks: |
ac088a88 | 1142 | nf_conntrack_cleanup_net(net); |
b884fa46 | 1143 | out_init_net: |
80250707 | 1144 | nf_conntrack_standalone_fini_proc(net); |
b2ce2c74 | 1145 | out_proc: |
ac088a88 | 1146 | nf_conntrack_standalone_fini_sysctl(net); |
b2ce2c74 | 1147 | return ret; |
dfdb8d79 AD |
1148 | } |
1149 | ||
dece40e8 | 1150 | static void nf_conntrack_pernet_exit(struct list_head *net_exit_list) |
dfdb8d79 | 1151 | { |
dece40e8 VD |
1152 | struct net *net; |
1153 | ||
ba3fbe66 PNA |
1154 | list_for_each_entry(net, net_exit_list, exit_list) |
1155 | nf_conntrack_fini_net(net); | |
1156 | ||
dece40e8 | 1157 | nf_conntrack_cleanup_net_list(net_exit_list); |
dfdb8d79 AD |
1158 | } |
1159 | ||
1160 | static struct pernet_operations nf_conntrack_net_ops = { | |
dece40e8 VD |
1161 | .init = nf_conntrack_pernet_init, |
1162 | .exit_batch = nf_conntrack_pernet_exit, | |
a0ae2562 FW |
1163 | .id = &nf_conntrack_net_id, |
1164 | .size = sizeof(struct nf_conntrack_net), | |
dfdb8d79 AD |
1165 | }; |
1166 | ||
65b4b4e8 | 1167 | static int __init nf_conntrack_standalone_init(void) |
9fb9cbb1 | 1168 | { |
f94161c1 G |
1169 | int ret = nf_conntrack_init_start(); |
1170 | if (ret < 0) | |
1171 | goto out_start; | |
1172 | ||
a9e419dc FW |
1173 | BUILD_BUG_ON(NFCT_INFOMASK <= IP_CT_NUMBER); |
1174 | ||
5f9f946b | 1175 | #ifdef CONFIG_SYSCTL |
f94161c1 G |
1176 | nf_ct_netfilter_header = |
1177 | register_net_sysctl(&init_net, "net", nf_ct_netfilter_table); | |
5f9f946b PNA |
1178 | if (!nf_ct_netfilter_header) { |
1179 | pr_err("nf_conntrack: can't register to sysctl.\n"); | |
5389090b | 1180 | ret = -ENOMEM; |
f94161c1 | 1181 | goto out_sysctl; |
5f9f946b | 1182 | } |
3183ab89 FW |
1183 | |
1184 | nf_conntrack_htable_size_user = nf_conntrack_htable_size; | |
5f9f946b | 1185 | #endif |
f94161c1 G |
1186 | |
1187 | ret = register_pernet_subsys(&nf_conntrack_net_ops); | |
1188 | if (ret < 0) | |
1189 | goto out_pernet; | |
1190 | ||
1191 | nf_conntrack_init_end(); | |
1192 | return 0; | |
1193 | ||
1194 | out_pernet: | |
5f9f946b | 1195 | #ifdef CONFIG_SYSCTL |
f94161c1 G |
1196 | unregister_net_sysctl_table(nf_ct_netfilter_header); |
1197 | out_sysctl: | |
5f9f946b | 1198 | #endif |
f94161c1 G |
1199 | nf_conntrack_cleanup_end(); |
1200 | out_start: | |
1201 | return ret; | |
9fb9cbb1 YK |
1202 | } |
1203 | ||
65b4b4e8 | 1204 | static void __exit nf_conntrack_standalone_fini(void) |
9fb9cbb1 | 1205 | { |
f94161c1 | 1206 | nf_conntrack_cleanup_start(); |
dfdb8d79 | 1207 | unregister_pernet_subsys(&nf_conntrack_net_ops); |
5f9f946b | 1208 | #ifdef CONFIG_SYSCTL |
f94161c1 | 1209 | unregister_net_sysctl_table(nf_ct_netfilter_header); |
5f9f946b | 1210 | #endif |
1e47ee83 | 1211 | nf_conntrack_cleanup_end(); |
9fb9cbb1 YK |
1212 | } |
1213 | ||
65b4b4e8 AM |
1214 | module_init(nf_conntrack_standalone_init); |
1215 | module_exit(nf_conntrack_standalone_fini); |