Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1 | /* (C) 1999-2001 Paul `Rusty' Russell |
| 2 | * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> |
Patrick McHardy | f229f6c | 2013-04-06 15:24:29 +0200 | [diff] [blame] | 3 | * (C) 2005-2012 Patrick McHardy <kaber@trash.net> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 8 | */ |
| 9 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 10 | #include <linux/types.h> |
| 11 | #include <linux/netfilter.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/skbuff.h> |
| 15 | #include <linux/proc_fs.h> |
| 16 | #include <linux/seq_file.h> |
| 17 | #include <linux/percpu.h> |
| 18 | #include <linux/netdevice.h> |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 19 | #include <linux/security.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 20 | #include <net/net_namespace.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 21 | #ifdef CONFIG_SYSCTL |
| 22 | #include <linux/sysctl.h> |
| 23 | #endif |
| 24 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 25 | #include <net/netfilter/nf_conntrack.h> |
Martin Josefsson | f618012 | 2006-11-29 02:35:01 +0100 | [diff] [blame] | 26 | #include <net/netfilter/nf_conntrack_core.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 27 | #include <net/netfilter/nf_conntrack_l3proto.h> |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 28 | #include <net/netfilter/nf_conntrack_l4proto.h> |
Martin Josefsson | 77ab9cf | 2006-11-29 02:34:58 +0100 | [diff] [blame] | 29 | #include <net/netfilter/nf_conntrack_expect.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 30 | #include <net/netfilter/nf_conntrack_helper.h> |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 31 | #include <net/netfilter/nf_conntrack_acct.h> |
Patrick McHardy | 5d0aa2c | 2010-02-15 18:13:33 +0100 | [diff] [blame] | 32 | #include <net/netfilter/nf_conntrack_zones.h> |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 33 | #include <net/netfilter/nf_conntrack_timestamp.h> |
Eric Dumazet | 0e60ebe | 2010-11-15 18:17:21 +0100 | [diff] [blame] | 34 | #include <linux/rculist_nulls.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 35 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 36 | MODULE_LICENSE("GPL"); |
| 37 | |
Jan Engelhardt | 54b07dc | 2011-04-21 09:32:45 +0200 | [diff] [blame] | 38 | #ifdef CONFIG_NF_CONNTRACK_PROCFS |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 39 | void |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 40 | print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple, |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 41 | const struct nf_conntrack_l3proto *l3proto, |
| 42 | const struct nf_conntrack_l4proto *l4proto) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 43 | { |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 44 | l3proto->print_tuple(s, tuple); |
| 45 | l4proto->print_tuple(s, tuple); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 46 | } |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 47 | EXPORT_SYMBOL_GPL(print_tuple); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 48 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 49 | struct ct_iter_state { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 50 | struct seq_net_private p; |
Liping Zhang | 64b8763 | 2016-07-03 13:18:43 +0800 | [diff] [blame^] | 51 | struct hlist_nulls_head *hash; |
| 52 | unsigned int htable_size; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 53 | unsigned int bucket; |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 54 | u_int64_t time_now; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 55 | }; |
| 56 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 57 | static struct hlist_nulls_node *ct_get_first(struct seq_file *seq) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 58 | { |
| 59 | struct ct_iter_state *st = seq->private; |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 60 | struct hlist_nulls_node *n; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 61 | |
| 62 | for (st->bucket = 0; |
Liping Zhang | 64b8763 | 2016-07-03 13:18:43 +0800 | [diff] [blame^] | 63 | st->bucket < st->htable_size; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 64 | st->bucket++) { |
Liping Zhang | 64b8763 | 2016-07-03 13:18:43 +0800 | [diff] [blame^] | 65 | n = rcu_dereference( |
| 66 | hlist_nulls_first_rcu(&st->hash[st->bucket])); |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 67 | if (!is_a_nulls(n)) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 68 | return n; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 69 | } |
| 70 | return NULL; |
| 71 | } |
| 72 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 73 | static struct hlist_nulls_node *ct_get_next(struct seq_file *seq, |
| 74 | struct hlist_nulls_node *head) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 75 | { |
| 76 | struct ct_iter_state *st = seq->private; |
| 77 | |
Eric Dumazet | 0e60ebe | 2010-11-15 18:17:21 +0100 | [diff] [blame] | 78 | head = rcu_dereference(hlist_nulls_next_rcu(head)); |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 79 | while (is_a_nulls(head)) { |
| 80 | if (likely(get_nulls_value(head) == st->bucket)) { |
Liping Zhang | 64b8763 | 2016-07-03 13:18:43 +0800 | [diff] [blame^] | 81 | if (++st->bucket >= st->htable_size) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 82 | return NULL; |
| 83 | } |
Eric Dumazet | 0e60ebe | 2010-11-15 18:17:21 +0100 | [diff] [blame] | 84 | head = rcu_dereference( |
Liping Zhang | 64b8763 | 2016-07-03 13:18:43 +0800 | [diff] [blame^] | 85 | hlist_nulls_first_rcu(&st->hash[st->bucket])); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 86 | } |
| 87 | return head; |
| 88 | } |
| 89 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 90 | static struct hlist_nulls_node *ct_get_idx(struct seq_file *seq, loff_t pos) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 91 | { |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 92 | struct hlist_nulls_node *head = ct_get_first(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 93 | |
| 94 | if (head) |
| 95 | while (pos && (head = ct_get_next(seq, head))) |
| 96 | pos--; |
| 97 | return pos ? NULL : head; |
| 98 | } |
| 99 | |
| 100 | static void *ct_seq_start(struct seq_file *seq, loff_t *pos) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 101 | __acquires(RCU) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 102 | { |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 103 | struct ct_iter_state *st = seq->private; |
| 104 | |
Eric Dumazet | d2de875 | 2014-08-22 18:32:09 -0700 | [diff] [blame] | 105 | st->time_now = ktime_get_real_ns(); |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 106 | rcu_read_lock(); |
Liping Zhang | 64b8763 | 2016-07-03 13:18:43 +0800 | [diff] [blame^] | 107 | |
| 108 | nf_conntrack_get_ht(&st->hash, &st->htable_size); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 109 | return ct_get_idx(seq, *pos); |
| 110 | } |
| 111 | |
| 112 | static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos) |
| 113 | { |
| 114 | (*pos)++; |
| 115 | return ct_get_next(s, v); |
| 116 | } |
| 117 | |
| 118 | static void ct_seq_stop(struct seq_file *s, void *v) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 119 | __releases(RCU) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 120 | { |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 121 | rcu_read_unlock(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 124 | #ifdef CONFIG_NF_CONNTRACK_SECMARK |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 125 | static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 126 | { |
| 127 | int ret; |
| 128 | u32 len; |
| 129 | char *secctx; |
| 130 | |
| 131 | ret = security_secid_to_secctx(ct->secmark, &secctx, &len); |
| 132 | if (ret) |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 133 | return; |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 134 | |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 135 | seq_printf(s, "secctx=%s ", secctx); |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 136 | |
| 137 | security_release_secctx(secctx, len); |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 138 | } |
| 139 | #else |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 140 | static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 141 | { |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 142 | } |
| 143 | #endif |
| 144 | |
Daniel Borkmann | 308ac91 | 2015-08-08 21:40:01 +0200 | [diff] [blame] | 145 | #ifdef CONFIG_NF_CONNTRACK_ZONES |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 146 | static void ct_show_zone(struct seq_file *s, const struct nf_conn *ct, |
| 147 | int dir) |
Daniel Borkmann | 308ac91 | 2015-08-08 21:40:01 +0200 | [diff] [blame] | 148 | { |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 149 | const struct nf_conntrack_zone *zone = nf_ct_zone(ct); |
| 150 | |
| 151 | if (zone->dir != dir) |
| 152 | return; |
| 153 | switch (zone->dir) { |
| 154 | case NF_CT_DEFAULT_ZONE_DIR: |
| 155 | seq_printf(s, "zone=%u ", zone->id); |
| 156 | break; |
| 157 | case NF_CT_ZONE_DIR_ORIG: |
| 158 | seq_printf(s, "zone-orig=%u ", zone->id); |
| 159 | break; |
| 160 | case NF_CT_ZONE_DIR_REPL: |
| 161 | seq_printf(s, "zone-reply=%u ", zone->id); |
| 162 | break; |
| 163 | default: |
| 164 | break; |
| 165 | } |
Daniel Borkmann | 308ac91 | 2015-08-08 21:40:01 +0200 | [diff] [blame] | 166 | } |
| 167 | #else |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 168 | static inline void ct_show_zone(struct seq_file *s, const struct nf_conn *ct, |
| 169 | int dir) |
Daniel Borkmann | 308ac91 | 2015-08-08 21:40:01 +0200 | [diff] [blame] | 170 | { |
| 171 | } |
| 172 | #endif |
| 173 | |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 174 | #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 175 | static void ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct) |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 176 | { |
| 177 | struct ct_iter_state *st = s->private; |
Patrick McHardy | f5c88f5 | 2011-01-19 19:10:49 +0100 | [diff] [blame] | 178 | struct nf_conn_tstamp *tstamp; |
| 179 | s64 delta_time; |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 180 | |
Patrick McHardy | f5c88f5 | 2011-01-19 19:10:49 +0100 | [diff] [blame] | 181 | tstamp = nf_conn_tstamp_find(ct); |
| 182 | if (tstamp) { |
| 183 | delta_time = st->time_now - tstamp->start; |
| 184 | if (delta_time > 0) |
| 185 | delta_time = div_s64(delta_time, NSEC_PER_SEC); |
| 186 | else |
| 187 | delta_time = 0; |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 188 | |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 189 | seq_printf(s, "delta-time=%llu ", |
| 190 | (unsigned long long)delta_time); |
Patrick McHardy | f5c88f5 | 2011-01-19 19:10:49 +0100 | [diff] [blame] | 191 | } |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 192 | return; |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 193 | } |
| 194 | #else |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 195 | static inline void |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 196 | ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct) |
| 197 | { |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 198 | } |
| 199 | #endif |
| 200 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 201 | /* return 0 on success, 1 in case of error */ |
| 202 | static int ct_seq_show(struct seq_file *s, void *v) |
| 203 | { |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 204 | struct nf_conntrack_tuple_hash *hash = v; |
| 205 | struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 206 | const struct nf_conntrack_l3proto *l3proto; |
| 207 | const struct nf_conntrack_l4proto *l4proto; |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 208 | int ret = 0; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 209 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 210 | NF_CT_ASSERT(ct); |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 211 | if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use))) |
| 212 | return 0; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 213 | |
| 214 | /* we only want to print DIR_ORIGINAL */ |
| 215 | if (NF_CT_DIRECTION(hash)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 216 | goto release; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 217 | |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 218 | l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 219 | NF_CT_ASSERT(l3proto); |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 220 | l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct)); |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 221 | NF_CT_ASSERT(l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 222 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 223 | ret = -ENOSPC; |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 224 | seq_printf(s, "%-8s %u %-8s %u %ld ", |
| 225 | l3proto->name, nf_ct_l3num(ct), |
| 226 | l4proto->name, nf_ct_protonum(ct), |
| 227 | timer_pending(&ct->timeout) |
| 228 | ? (long)(ct->timeout.expires - jiffies)/HZ : 0); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 229 | |
Steven Rostedt (Red Hat) | 37246a5 | 2014-10-27 16:02:47 -0400 | [diff] [blame] | 230 | if (l4proto->print_conntrack) |
| 231 | l4proto->print_conntrack(s, ct); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 232 | |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 233 | print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, |
| 234 | l3proto, l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 235 | |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 236 | ct_show_zone(s, ct, NF_CT_ZONE_DIR_ORIG); |
| 237 | |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 238 | if (seq_has_overflowed(s)) |
| 239 | goto release; |
| 240 | |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 241 | if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 242 | goto release; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 243 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 244 | if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 245 | seq_printf(s, "[UNREPLIED] "); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 246 | |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 247 | print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, |
| 248 | l3proto, l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 249 | |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 250 | ct_show_zone(s, ct, NF_CT_ZONE_DIR_REPL); |
| 251 | |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 252 | if (seq_print_acct(s, ct, IP_CT_DIR_REPLY)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 253 | goto release; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 254 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 255 | if (test_bit(IPS_ASSURED_BIT, &ct->status)) |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 256 | seq_printf(s, "[ASSURED] "); |
| 257 | |
| 258 | if (seq_has_overflowed(s)) |
| 259 | goto release; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 260 | |
| 261 | #if defined(CONFIG_NF_CONNTRACK_MARK) |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 262 | seq_printf(s, "mark=%u ", ct->mark); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 263 | #endif |
| 264 | |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 265 | ct_show_secctx(s, ct); |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 266 | ct_show_zone(s, ct, NF_CT_DEFAULT_ZONE_DIR); |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 267 | ct_show_delta_time(s, ct); |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 268 | |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 269 | seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)); |
| 270 | |
| 271 | if (seq_has_overflowed(s)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 272 | goto release; |
YOSHIFUJI Hideaki | a5d2926 | 2007-07-19 10:44:21 +0900 | [diff] [blame] | 273 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 274 | ret = 0; |
| 275 | release: |
| 276 | nf_ct_put(ct); |
David S. Miller | d88d7de | 2011-04-17 17:03:33 -0700 | [diff] [blame] | 277 | return ret; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 280 | static const struct seq_operations ct_seq_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 281 | .start = ct_seq_start, |
| 282 | .next = ct_seq_next, |
| 283 | .stop = ct_seq_stop, |
| 284 | .show = ct_seq_show |
| 285 | }; |
| 286 | |
| 287 | static int ct_open(struct inode *inode, struct file *file) |
| 288 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 289 | return seq_open_net(inode, file, &ct_seq_ops, |
Pavel Emelyanov | e2da591 | 2007-10-10 02:29:58 -0700 | [diff] [blame] | 290 | sizeof(struct ct_iter_state)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 293 | static const struct file_operations ct_file_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 294 | .owner = THIS_MODULE, |
| 295 | .open = ct_open, |
| 296 | .read = seq_read, |
| 297 | .llseek = seq_lseek, |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 298 | .release = seq_release_net, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 299 | }; |
| 300 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 301 | static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos) |
| 302 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 303 | struct net *net = seq_file_net(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 304 | int cpu; |
| 305 | |
| 306 | if (*pos == 0) |
| 307 | return SEQ_START_TOKEN; |
| 308 | |
Rusty Russell | 0f23174a | 2008-12-29 12:23:42 +0000 | [diff] [blame] | 309 | for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 310 | if (!cpu_possible(cpu)) |
| 311 | continue; |
| 312 | *pos = cpu + 1; |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 313 | return per_cpu_ptr(net->ct.stat, cpu); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | return NULL; |
| 317 | } |
| 318 | |
| 319 | static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 320 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 321 | struct net *net = seq_file_net(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 322 | int cpu; |
| 323 | |
Rusty Russell | 0f23174a | 2008-12-29 12:23:42 +0000 | [diff] [blame] | 324 | for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 325 | if (!cpu_possible(cpu)) |
| 326 | continue; |
| 327 | *pos = cpu + 1; |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 328 | return per_cpu_ptr(net->ct.stat, cpu); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | return NULL; |
| 332 | } |
| 333 | |
| 334 | static void ct_cpu_seq_stop(struct seq_file *seq, void *v) |
| 335 | { |
| 336 | } |
| 337 | |
| 338 | static int ct_cpu_seq_show(struct seq_file *seq, void *v) |
| 339 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 340 | struct net *net = seq_file_net(seq); |
| 341 | unsigned int nr_conntracks = atomic_read(&net->ct.count); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 342 | const struct ip_conntrack_stat *st = v; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 343 | |
| 344 | if (v == SEQ_START_TOKEN) { |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 345 | seq_printf(seq, "entries searched found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error expect_new expect_create expect_delete search_restart\n"); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x " |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 350 | "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n", |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 351 | nr_conntracks, |
| 352 | st->searched, |
| 353 | st->found, |
| 354 | st->new, |
| 355 | st->invalid, |
| 356 | st->ignore, |
| 357 | st->delete, |
| 358 | st->delete_list, |
| 359 | st->insert, |
| 360 | st->insert_failed, |
| 361 | st->drop, |
| 362 | st->early_drop, |
| 363 | st->error, |
| 364 | |
| 365 | st->expect_new, |
| 366 | st->expect_create, |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 367 | st->expect_delete, |
| 368 | st->search_restart |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 369 | ); |
| 370 | return 0; |
| 371 | } |
| 372 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 373 | static const struct seq_operations ct_cpu_seq_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 374 | .start = ct_cpu_seq_start, |
| 375 | .next = ct_cpu_seq_next, |
| 376 | .stop = ct_cpu_seq_stop, |
| 377 | .show = ct_cpu_seq_show, |
| 378 | }; |
| 379 | |
| 380 | static int ct_cpu_seq_open(struct inode *inode, struct file *file) |
| 381 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 382 | return seq_open_net(inode, file, &ct_cpu_seq_ops, |
| 383 | sizeof(struct seq_net_private)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 386 | static const struct file_operations ct_cpu_seq_fops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 387 | .owner = THIS_MODULE, |
| 388 | .open = ct_cpu_seq_open, |
| 389 | .read = seq_read, |
| 390 | .llseek = seq_lseek, |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 391 | .release = seq_release_net, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 392 | }; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 393 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 394 | static int nf_conntrack_standalone_init_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 395 | { |
| 396 | struct proc_dir_entry *pde; |
Philip Whineray | f13f2ae | 2015-11-22 11:35:07 +0000 | [diff] [blame] | 397 | kuid_t root_uid; |
| 398 | kgid_t root_gid; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 399 | |
Gao feng | d4beaa6 | 2013-02-18 01:34:54 +0000 | [diff] [blame] | 400 | pde = proc_create("nf_conntrack", 0440, net->proc_net, &ct_file_ops); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 401 | if (!pde) |
| 402 | goto out_nf_conntrack; |
Denis V. Lunev | 52c0e11 | 2008-05-02 04:10:57 -0700 | [diff] [blame] | 403 | |
Philip Whineray | f13f2ae | 2015-11-22 11:35:07 +0000 | [diff] [blame] | 404 | root_uid = make_kuid(net->user_ns, 0); |
| 405 | root_gid = make_kgid(net->user_ns, 0); |
| 406 | if (uid_valid(root_uid) && gid_valid(root_gid)) |
| 407 | proc_set_user(pde, root_uid, root_gid); |
| 408 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 409 | pde = proc_create("nf_conntrack", S_IRUGO, net->proc_net_stat, |
Denis V. Lunev | 52c0e11 | 2008-05-02 04:10:57 -0700 | [diff] [blame] | 410 | &ct_cpu_seq_fops); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 411 | if (!pde) |
| 412 | goto out_stat_nf_conntrack; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 413 | return 0; |
| 414 | |
| 415 | out_stat_nf_conntrack: |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 416 | remove_proc_entry("nf_conntrack", net->proc_net); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 417 | out_nf_conntrack: |
| 418 | return -ENOMEM; |
| 419 | } |
| 420 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 421 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 422 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 423 | remove_proc_entry("nf_conntrack", net->proc_net_stat); |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 424 | remove_proc_entry("nf_conntrack", net->proc_net); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 425 | } |
| 426 | #else |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 427 | static int nf_conntrack_standalone_init_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 428 | { |
| 429 | return 0; |
| 430 | } |
| 431 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 432 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 433 | { |
| 434 | } |
Jan Engelhardt | 54b07dc | 2011-04-21 09:32:45 +0200 | [diff] [blame] | 435 | #endif /* CONFIG_NF_CONNTRACK_PROCFS */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 436 | |
| 437 | /* Sysctl support */ |
| 438 | |
| 439 | #ifdef CONFIG_SYSCTL |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 440 | /* Log invalid packets of a given protocol */ |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 441 | static int log_invalid_proto_min __read_mostly; |
| 442 | static int log_invalid_proto_max __read_mostly = 255; |
| 443 | |
| 444 | /* size the user *wants to set */ |
| 445 | static unsigned int nf_conntrack_htable_size_user __read_mostly; |
| 446 | |
| 447 | static int |
| 448 | nf_conntrack_hash_sysctl(struct ctl_table *table, int write, |
| 449 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 450 | { |
| 451 | int ret; |
| 452 | |
| 453 | ret = proc_dointvec(table, write, buffer, lenp, ppos); |
| 454 | if (ret < 0 || !write) |
| 455 | return ret; |
| 456 | |
| 457 | /* update ret, we might not be able to satisfy request */ |
| 458 | ret = nf_conntrack_hash_resize(nf_conntrack_htable_size_user); |
| 459 | |
| 460 | /* update it to the actual value used by conntrack */ |
| 461 | nf_conntrack_htable_size_user = nf_conntrack_htable_size; |
| 462 | return ret; |
| 463 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 464 | |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 465 | static struct ctl_table_header *nf_ct_netfilter_header; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 466 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 467 | static struct ctl_table nf_ct_sysctl_table[] = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 468 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 469 | .procname = "nf_conntrack_max", |
| 470 | .data = &nf_conntrack_max, |
| 471 | .maxlen = sizeof(int), |
| 472 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 473 | .proc_handler = proc_dointvec, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 474 | }, |
| 475 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 476 | .procname = "nf_conntrack_count", |
Alexey Dobriyan | 49ac871 | 2008-10-08 11:35:03 +0200 | [diff] [blame] | 477 | .data = &init_net.ct.count, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 478 | .maxlen = sizeof(int), |
| 479 | .mode = 0444, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 480 | .proc_handler = proc_dointvec, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 481 | }, |
| 482 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 483 | .procname = "nf_conntrack_buckets", |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 484 | .data = &nf_conntrack_htable_size_user, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 485 | .maxlen = sizeof(unsigned int), |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 486 | .mode = 0644, |
| 487 | .proc_handler = nf_conntrack_hash_sysctl, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 488 | }, |
| 489 | { |
Patrick McHardy | 39a27a3 | 2006-05-29 18:23:54 -0700 | [diff] [blame] | 490 | .procname = "nf_conntrack_checksum", |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 491 | .data = &init_net.ct.sysctl_checksum, |
Patrick McHardy | 39a27a3 | 2006-05-29 18:23:54 -0700 | [diff] [blame] | 492 | .maxlen = sizeof(unsigned int), |
| 493 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 494 | .proc_handler = proc_dointvec, |
Patrick McHardy | 39a27a3 | 2006-05-29 18:23:54 -0700 | [diff] [blame] | 495 | }, |
| 496 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 497 | .procname = "nf_conntrack_log_invalid", |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 498 | .data = &init_net.ct.sysctl_log_invalid, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 499 | .maxlen = sizeof(unsigned int), |
| 500 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 501 | .proc_handler = proc_dointvec_minmax, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 502 | .extra1 = &log_invalid_proto_min, |
| 503 | .extra2 = &log_invalid_proto_max, |
| 504 | }, |
Patrick McHardy | f264a7d | 2007-07-07 22:36:24 -0700 | [diff] [blame] | 505 | { |
Patrick McHardy | f264a7d | 2007-07-07 22:36:24 -0700 | [diff] [blame] | 506 | .procname = "nf_conntrack_expect_max", |
| 507 | .data = &nf_ct_expect_max, |
| 508 | .maxlen = sizeof(int), |
| 509 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 510 | .proc_handler = proc_dointvec, |
Patrick McHardy | f264a7d | 2007-07-07 22:36:24 -0700 | [diff] [blame] | 511 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 512 | { } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 513 | }; |
| 514 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 515 | static struct ctl_table nf_ct_netfilter_table[] = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 516 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 517 | .procname = "nf_conntrack_max", |
| 518 | .data = &nf_conntrack_max, |
| 519 | .maxlen = sizeof(int), |
| 520 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 521 | .proc_handler = proc_dointvec, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 522 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 523 | { } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 524 | }; |
| 525 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 526 | static int nf_conntrack_standalone_init_sysctl(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 527 | { |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 528 | struct ctl_table *table; |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 529 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 530 | table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table), |
| 531 | GFP_KERNEL); |
| 532 | if (!table) |
| 533 | goto out_kmemdup; |
| 534 | |
| 535 | table[1].data = &net->ct.count; |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 536 | table[3].data = &net->ct.sysctl_checksum; |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 537 | table[4].data = &net->ct.sysctl_log_invalid; |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 538 | |
Eric W. Biederman | 464dc80 | 2012-11-16 03:02:59 +0000 | [diff] [blame] | 539 | /* Don't export sysctls to unprivileged users */ |
| 540 | if (net->user_ns != &init_user_ns) |
| 541 | table[0].procname = NULL; |
| 542 | |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 543 | if (!net_eq(&init_net, net)) |
| 544 | table[2].mode = 0444; |
| 545 | |
Eric W. Biederman | ec8f23c | 2012-04-19 13:44:49 +0000 | [diff] [blame] | 546 | net->ct.sysctl_header = register_net_sysctl(net, "net/netfilter", table); |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 547 | if (!net->ct.sysctl_header) |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 548 | goto out_unregister_netfilter; |
| 549 | |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 550 | return 0; |
| 551 | |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 552 | out_unregister_netfilter: |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 553 | kfree(table); |
| 554 | out_kmemdup: |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 555 | return -ENOMEM; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 556 | } |
| 557 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 558 | static void nf_conntrack_standalone_fini_sysctl(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 559 | { |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 560 | struct ctl_table *table; |
| 561 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 562 | table = net->ct.sysctl_header->ctl_table_arg; |
| 563 | unregister_net_sysctl_table(net->ct.sysctl_header); |
| 564 | kfree(table); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 565 | } |
| 566 | #else |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 567 | static int nf_conntrack_standalone_init_sysctl(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 568 | { |
| 569 | return 0; |
| 570 | } |
| 571 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 572 | static void nf_conntrack_standalone_fini_sysctl(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 573 | { |
| 574 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 575 | #endif /* CONFIG_SYSCTL */ |
| 576 | |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 577 | static int nf_conntrack_pernet_init(struct net *net) |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 578 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 579 | int ret; |
| 580 | |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 581 | ret = nf_conntrack_init_net(net); |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 582 | if (ret < 0) |
| 583 | goto out_init; |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 584 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 585 | ret = nf_conntrack_standalone_init_proc(net); |
| 586 | if (ret < 0) |
| 587 | goto out_proc; |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 588 | |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 589 | net->ct.sysctl_checksum = 1; |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 590 | net->ct.sysctl_log_invalid = 0; |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 591 | ret = nf_conntrack_standalone_init_sysctl(net); |
| 592 | if (ret < 0) |
| 593 | goto out_sysctl; |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 594 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 595 | return 0; |
| 596 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 597 | out_sysctl: |
| 598 | nf_conntrack_standalone_fini_proc(net); |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 599 | out_proc: |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 600 | nf_conntrack_cleanup_net(net); |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 601 | out_init: |
| 602 | return ret; |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 603 | } |
| 604 | |
Vladimir Davydov | dece40e | 2013-03-13 23:40:14 +0000 | [diff] [blame] | 605 | static void nf_conntrack_pernet_exit(struct list_head *net_exit_list) |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 606 | { |
Vladimir Davydov | dece40e | 2013-03-13 23:40:14 +0000 | [diff] [blame] | 607 | struct net *net; |
| 608 | |
| 609 | list_for_each_entry(net, net_exit_list, exit_list) { |
| 610 | nf_conntrack_standalone_fini_sysctl(net); |
| 611 | nf_conntrack_standalone_fini_proc(net); |
| 612 | } |
| 613 | nf_conntrack_cleanup_net_list(net_exit_list); |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static struct pernet_operations nf_conntrack_net_ops = { |
Vladimir Davydov | dece40e | 2013-03-13 23:40:14 +0000 | [diff] [blame] | 617 | .init = nf_conntrack_pernet_init, |
| 618 | .exit_batch = nf_conntrack_pernet_exit, |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 619 | }; |
| 620 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 621 | static int __init nf_conntrack_standalone_init(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 622 | { |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 623 | int ret = nf_conntrack_init_start(); |
| 624 | if (ret < 0) |
| 625 | goto out_start; |
| 626 | |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 627 | #ifdef CONFIG_SYSCTL |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 628 | nf_ct_netfilter_header = |
| 629 | register_net_sysctl(&init_net, "net", nf_ct_netfilter_table); |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 630 | if (!nf_ct_netfilter_header) { |
| 631 | pr_err("nf_conntrack: can't register to sysctl.\n"); |
Wei Yongjun | 5389090 | 2013-03-27 03:57:10 +0000 | [diff] [blame] | 632 | ret = -ENOMEM; |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 633 | goto out_sysctl; |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 634 | } |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 635 | |
| 636 | nf_conntrack_htable_size_user = nf_conntrack_htable_size; |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 637 | #endif |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 638 | |
| 639 | ret = register_pernet_subsys(&nf_conntrack_net_ops); |
| 640 | if (ret < 0) |
| 641 | goto out_pernet; |
| 642 | |
| 643 | nf_conntrack_init_end(); |
| 644 | return 0; |
| 645 | |
| 646 | out_pernet: |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 647 | #ifdef CONFIG_SYSCTL |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 648 | unregister_net_sysctl_table(nf_ct_netfilter_header); |
| 649 | out_sysctl: |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 650 | #endif |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 651 | nf_conntrack_cleanup_end(); |
| 652 | out_start: |
| 653 | return ret; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 656 | static void __exit nf_conntrack_standalone_fini(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 657 | { |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 658 | nf_conntrack_cleanup_start(); |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 659 | unregister_pernet_subsys(&nf_conntrack_net_ops); |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 660 | #ifdef CONFIG_SYSCTL |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 661 | unregister_net_sysctl_table(nf_ct_netfilter_header); |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 662 | #endif |
Pablo Neira Ayuso | 1e47ee8 | 2013-01-10 16:12:01 +0100 | [diff] [blame] | 663 | nf_conntrack_cleanup_end(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 664 | } |
| 665 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 666 | module_init(nf_conntrack_standalone_init); |
| 667 | module_exit(nf_conntrack_standalone_fini); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 668 | |
| 669 | /* Some modules need us, but don't depend directly on any symbol. |
| 670 | They should call this. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 671 | void need_conntrack(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 672 | { |
| 673 | } |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 674 | EXPORT_SYMBOL_GPL(need_conntrack); |