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; |
Liping Zhang | e77e6ff | 2016-08-15 21:50:35 +0800 | [diff] [blame] | 208 | struct net *net = seq_file_net(s); |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 209 | int ret = 0; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 210 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 211 | NF_CT_ASSERT(ct); |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 212 | if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use))) |
| 213 | return 0; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 214 | |
Florian Westphal | 58e207e | 2016-09-22 23:49:17 +0200 | [diff] [blame] | 215 | if (nf_ct_should_gc(ct)) { |
| 216 | nf_ct_kill(ct); |
| 217 | goto release; |
| 218 | } |
| 219 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 220 | /* we only want to print DIR_ORIGINAL */ |
| 221 | if (NF_CT_DIRECTION(hash)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 222 | goto release; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 223 | |
Liping Zhang | e77e6ff | 2016-08-15 21:50:35 +0800 | [diff] [blame] | 224 | if (!net_eq(nf_ct_net(ct), net)) |
| 225 | goto release; |
| 226 | |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 227 | l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 228 | NF_CT_ASSERT(l3proto); |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 229 | 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] | 230 | NF_CT_ASSERT(l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 231 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 232 | ret = -ENOSPC; |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 233 | seq_printf(s, "%-8s %u %-8s %u %ld ", |
| 234 | l3proto->name, nf_ct_l3num(ct), |
| 235 | l4proto->name, nf_ct_protonum(ct), |
Florian Westphal | d0b35b9 | 2016-08-03 02:45:07 +0200 | [diff] [blame] | 236 | nf_ct_expires(ct) / HZ); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 237 | |
Steven Rostedt (Red Hat) | 37246a5 | 2014-10-27 16:02:47 -0400 | [diff] [blame] | 238 | if (l4proto->print_conntrack) |
| 239 | l4proto->print_conntrack(s, ct); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 240 | |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 241 | print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, |
| 242 | l3proto, l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 243 | |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 244 | ct_show_zone(s, ct, NF_CT_ZONE_DIR_ORIG); |
| 245 | |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 246 | if (seq_has_overflowed(s)) |
| 247 | goto release; |
| 248 | |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 249 | if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 250 | goto release; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 251 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 252 | if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 253 | seq_printf(s, "[UNREPLIED] "); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 254 | |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 255 | print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, |
| 256 | l3proto, l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 257 | |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 258 | ct_show_zone(s, ct, NF_CT_ZONE_DIR_REPL); |
| 259 | |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 260 | if (seq_print_acct(s, ct, IP_CT_DIR_REPLY)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 261 | goto release; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 262 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 263 | if (test_bit(IPS_ASSURED_BIT, &ct->status)) |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 264 | seq_printf(s, "[ASSURED] "); |
| 265 | |
| 266 | if (seq_has_overflowed(s)) |
| 267 | goto release; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 268 | |
| 269 | #if defined(CONFIG_NF_CONNTRACK_MARK) |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 270 | seq_printf(s, "mark=%u ", ct->mark); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 271 | #endif |
| 272 | |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 273 | ct_show_secctx(s, ct); |
Daniel Borkmann | deedb59 | 2015-08-14 16:03:39 +0200 | [diff] [blame] | 274 | ct_show_zone(s, ct, NF_CT_DEFAULT_ZONE_DIR); |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 275 | ct_show_delta_time(s, ct); |
Pablo Neira Ayuso | a992ca2 | 2011-01-19 16:00:07 +0100 | [diff] [blame] | 276 | |
Steven Rostedt (Red Hat) | e71456a | 2014-10-27 17:43:45 -0400 | [diff] [blame] | 277 | seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)); |
| 278 | |
| 279 | if (seq_has_overflowed(s)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 280 | goto release; |
YOSHIFUJI Hideaki | a5d2926 | 2007-07-19 10:44:21 +0900 | [diff] [blame] | 281 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 282 | ret = 0; |
| 283 | release: |
| 284 | nf_ct_put(ct); |
David S. Miller | d88d7de | 2011-04-17 17:03:33 -0700 | [diff] [blame] | 285 | return ret; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 288 | static const struct seq_operations ct_seq_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 289 | .start = ct_seq_start, |
| 290 | .next = ct_seq_next, |
| 291 | .stop = ct_seq_stop, |
| 292 | .show = ct_seq_show |
| 293 | }; |
| 294 | |
| 295 | static int ct_open(struct inode *inode, struct file *file) |
| 296 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 297 | return seq_open_net(inode, file, &ct_seq_ops, |
Pavel Emelyanov | e2da591 | 2007-10-10 02:29:58 -0700 | [diff] [blame] | 298 | sizeof(struct ct_iter_state)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 301 | static const struct file_operations ct_file_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 302 | .owner = THIS_MODULE, |
| 303 | .open = ct_open, |
| 304 | .read = seq_read, |
| 305 | .llseek = seq_lseek, |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 306 | .release = seq_release_net, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 307 | }; |
| 308 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 309 | static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos) |
| 310 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 311 | struct net *net = seq_file_net(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 312 | int cpu; |
| 313 | |
| 314 | if (*pos == 0) |
| 315 | return SEQ_START_TOKEN; |
| 316 | |
Rusty Russell | 0f23174a | 2008-12-29 12:23:42 +0000 | [diff] [blame] | 317 | for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 318 | if (!cpu_possible(cpu)) |
| 319 | continue; |
| 320 | *pos = cpu + 1; |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 321 | return per_cpu_ptr(net->ct.stat, cpu); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | return NULL; |
| 325 | } |
| 326 | |
| 327 | static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 328 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 329 | struct net *net = seq_file_net(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 330 | int cpu; |
| 331 | |
Rusty Russell | 0f23174a | 2008-12-29 12:23:42 +0000 | [diff] [blame] | 332 | for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 333 | if (!cpu_possible(cpu)) |
| 334 | continue; |
| 335 | *pos = cpu + 1; |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 336 | return per_cpu_ptr(net->ct.stat, cpu); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | return NULL; |
| 340 | } |
| 341 | |
| 342 | static void ct_cpu_seq_stop(struct seq_file *seq, void *v) |
| 343 | { |
| 344 | } |
| 345 | |
| 346 | static int ct_cpu_seq_show(struct seq_file *seq, void *v) |
| 347 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 348 | struct net *net = seq_file_net(seq); |
| 349 | unsigned int nr_conntracks = atomic_read(&net->ct.count); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 350 | const struct ip_conntrack_stat *st = v; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 351 | |
| 352 | if (v == SEQ_START_TOKEN) { |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 353 | 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] | 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x " |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 358 | "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n", |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 359 | nr_conntracks, |
Florian Westphal | 8e8118f | 2016-09-11 22:55:53 +0200 | [diff] [blame] | 360 | 0, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 361 | st->found, |
Florian Westphal | 8e8118f | 2016-09-11 22:55:53 +0200 | [diff] [blame] | 362 | 0, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 363 | st->invalid, |
| 364 | st->ignore, |
Florian Westphal | 8e8118f | 2016-09-11 22:55:53 +0200 | [diff] [blame] | 365 | 0, |
| 366 | 0, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 367 | st->insert, |
| 368 | st->insert_failed, |
| 369 | st->drop, |
| 370 | st->early_drop, |
| 371 | st->error, |
| 372 | |
| 373 | st->expect_new, |
| 374 | st->expect_create, |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 375 | st->expect_delete, |
| 376 | st->search_restart |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 377 | ); |
| 378 | return 0; |
| 379 | } |
| 380 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 381 | static const struct seq_operations ct_cpu_seq_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 382 | .start = ct_cpu_seq_start, |
| 383 | .next = ct_cpu_seq_next, |
| 384 | .stop = ct_cpu_seq_stop, |
| 385 | .show = ct_cpu_seq_show, |
| 386 | }; |
| 387 | |
| 388 | static int ct_cpu_seq_open(struct inode *inode, struct file *file) |
| 389 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 390 | return seq_open_net(inode, file, &ct_cpu_seq_ops, |
| 391 | sizeof(struct seq_net_private)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 394 | static const struct file_operations ct_cpu_seq_fops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 395 | .owner = THIS_MODULE, |
| 396 | .open = ct_cpu_seq_open, |
| 397 | .read = seq_read, |
| 398 | .llseek = seq_lseek, |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 399 | .release = seq_release_net, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 400 | }; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 401 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 402 | static int nf_conntrack_standalone_init_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 403 | { |
| 404 | struct proc_dir_entry *pde; |
Philip Whineray | f13f2ae | 2015-11-22 11:35:07 +0000 | [diff] [blame] | 405 | kuid_t root_uid; |
| 406 | kgid_t root_gid; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 407 | |
Gao feng | d4beaa6 | 2013-02-18 01:34:54 +0000 | [diff] [blame] | 408 | pde = proc_create("nf_conntrack", 0440, net->proc_net, &ct_file_ops); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 409 | if (!pde) |
| 410 | goto out_nf_conntrack; |
Denis V. Lunev | 52c0e11 | 2008-05-02 04:10:57 -0700 | [diff] [blame] | 411 | |
Philip Whineray | f13f2ae | 2015-11-22 11:35:07 +0000 | [diff] [blame] | 412 | root_uid = make_kuid(net->user_ns, 0); |
| 413 | root_gid = make_kgid(net->user_ns, 0); |
| 414 | if (uid_valid(root_uid) && gid_valid(root_gid)) |
| 415 | proc_set_user(pde, root_uid, root_gid); |
| 416 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 417 | pde = proc_create("nf_conntrack", S_IRUGO, net->proc_net_stat, |
Denis V. Lunev | 52c0e11 | 2008-05-02 04:10:57 -0700 | [diff] [blame] | 418 | &ct_cpu_seq_fops); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 419 | if (!pde) |
| 420 | goto out_stat_nf_conntrack; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 421 | return 0; |
| 422 | |
| 423 | out_stat_nf_conntrack: |
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 | out_nf_conntrack: |
| 426 | return -ENOMEM; |
| 427 | } |
| 428 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 429 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 430 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 431 | remove_proc_entry("nf_conntrack", net->proc_net_stat); |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 432 | remove_proc_entry("nf_conntrack", net->proc_net); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 433 | } |
| 434 | #else |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 435 | static int nf_conntrack_standalone_init_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 436 | { |
| 437 | return 0; |
| 438 | } |
| 439 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 440 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 441 | { |
| 442 | } |
Jan Engelhardt | 54b07dc | 2011-04-21 09:32:45 +0200 | [diff] [blame] | 443 | #endif /* CONFIG_NF_CONNTRACK_PROCFS */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 444 | |
| 445 | /* Sysctl support */ |
| 446 | |
| 447 | #ifdef CONFIG_SYSCTL |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 448 | /* Log invalid packets of a given protocol */ |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 449 | static int log_invalid_proto_min __read_mostly; |
| 450 | static int log_invalid_proto_max __read_mostly = 255; |
| 451 | |
| 452 | /* size the user *wants to set */ |
| 453 | static unsigned int nf_conntrack_htable_size_user __read_mostly; |
| 454 | |
| 455 | static int |
| 456 | nf_conntrack_hash_sysctl(struct ctl_table *table, int write, |
| 457 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 458 | { |
| 459 | int ret; |
| 460 | |
| 461 | ret = proc_dointvec(table, write, buffer, lenp, ppos); |
| 462 | if (ret < 0 || !write) |
| 463 | return ret; |
| 464 | |
| 465 | /* update ret, we might not be able to satisfy request */ |
| 466 | ret = nf_conntrack_hash_resize(nf_conntrack_htable_size_user); |
| 467 | |
| 468 | /* update it to the actual value used by conntrack */ |
| 469 | nf_conntrack_htable_size_user = nf_conntrack_htable_size; |
| 470 | return ret; |
| 471 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 472 | |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 473 | static struct ctl_table_header *nf_ct_netfilter_header; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 474 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 475 | static struct ctl_table nf_ct_sysctl_table[] = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 476 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 477 | .procname = "nf_conntrack_max", |
| 478 | .data = &nf_conntrack_max, |
| 479 | .maxlen = sizeof(int), |
| 480 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 481 | .proc_handler = proc_dointvec, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 482 | }, |
| 483 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 484 | .procname = "nf_conntrack_count", |
Alexey Dobriyan | 49ac871 | 2008-10-08 11:35:03 +0200 | [diff] [blame] | 485 | .data = &init_net.ct.count, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 486 | .maxlen = sizeof(int), |
| 487 | .mode = 0444, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 488 | .proc_handler = proc_dointvec, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 489 | }, |
| 490 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 491 | .procname = "nf_conntrack_buckets", |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 492 | .data = &nf_conntrack_htable_size_user, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 493 | .maxlen = sizeof(unsigned int), |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 494 | .mode = 0644, |
| 495 | .proc_handler = nf_conntrack_hash_sysctl, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 496 | }, |
| 497 | { |
Patrick McHardy | 39a27a3 | 2006-05-29 18:23:54 -0700 | [diff] [blame] | 498 | .procname = "nf_conntrack_checksum", |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 499 | .data = &init_net.ct.sysctl_checksum, |
Patrick McHardy | 39a27a3 | 2006-05-29 18:23:54 -0700 | [diff] [blame] | 500 | .maxlen = sizeof(unsigned int), |
| 501 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 502 | .proc_handler = proc_dointvec, |
Patrick McHardy | 39a27a3 | 2006-05-29 18:23:54 -0700 | [diff] [blame] | 503 | }, |
| 504 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 505 | .procname = "nf_conntrack_log_invalid", |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 506 | .data = &init_net.ct.sysctl_log_invalid, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 507 | .maxlen = sizeof(unsigned int), |
| 508 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 509 | .proc_handler = proc_dointvec_minmax, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 510 | .extra1 = &log_invalid_proto_min, |
| 511 | .extra2 = &log_invalid_proto_max, |
| 512 | }, |
Patrick McHardy | f264a7d | 2007-07-07 22:36:24 -0700 | [diff] [blame] | 513 | { |
Patrick McHardy | f264a7d | 2007-07-07 22:36:24 -0700 | [diff] [blame] | 514 | .procname = "nf_conntrack_expect_max", |
| 515 | .data = &nf_ct_expect_max, |
| 516 | .maxlen = sizeof(int), |
| 517 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 518 | .proc_handler = proc_dointvec, |
Patrick McHardy | f264a7d | 2007-07-07 22:36:24 -0700 | [diff] [blame] | 519 | }, |
Mohammed Javid | 53d20ee | 2016-02-10 17:29:57 +0530 | [diff] [blame] | 520 | { |
| 521 | .procname = "nf_conntrack_pkt_threshold", |
| 522 | .data = &nf_conntrack_pkt_threshold, |
| 523 | .maxlen = sizeof(int), |
| 524 | .mode = 0644, |
| 525 | .proc_handler = proc_dointvec, |
| 526 | }, |
| 527 | |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 528 | { } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 529 | }; |
| 530 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 531 | static struct ctl_table nf_ct_netfilter_table[] = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 532 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 533 | .procname = "nf_conntrack_max", |
| 534 | .data = &nf_conntrack_max, |
| 535 | .maxlen = sizeof(int), |
| 536 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 537 | .proc_handler = proc_dointvec, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 538 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 539 | { } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 540 | }; |
| 541 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 542 | static int nf_conntrack_standalone_init_sysctl(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 543 | { |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 544 | struct ctl_table *table; |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 545 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 546 | table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table), |
| 547 | GFP_KERNEL); |
| 548 | if (!table) |
| 549 | goto out_kmemdup; |
| 550 | |
| 551 | table[1].data = &net->ct.count; |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 552 | table[3].data = &net->ct.sysctl_checksum; |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 553 | table[4].data = &net->ct.sysctl_log_invalid; |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 554 | |
Eric W. Biederman | 464dc80 | 2012-11-16 03:02:59 +0000 | [diff] [blame] | 555 | /* Don't export sysctls to unprivileged users */ |
| 556 | if (net->user_ns != &init_user_ns) |
| 557 | table[0].procname = NULL; |
| 558 | |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 559 | if (!net_eq(&init_net, net)) |
| 560 | table[2].mode = 0444; |
| 561 | |
Eric W. Biederman | ec8f23c | 2012-04-19 13:44:49 +0000 | [diff] [blame] | 562 | net->ct.sysctl_header = register_net_sysctl(net, "net/netfilter", table); |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 563 | if (!net->ct.sysctl_header) |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 564 | goto out_unregister_netfilter; |
| 565 | |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 566 | return 0; |
| 567 | |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 568 | out_unregister_netfilter: |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 569 | kfree(table); |
| 570 | out_kmemdup: |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 571 | return -ENOMEM; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 572 | } |
| 573 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 574 | static void nf_conntrack_standalone_fini_sysctl(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 575 | { |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 576 | struct ctl_table *table; |
| 577 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 578 | table = net->ct.sysctl_header->ctl_table_arg; |
| 579 | unregister_net_sysctl_table(net->ct.sysctl_header); |
| 580 | kfree(table); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 581 | } |
| 582 | #else |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 583 | static int nf_conntrack_standalone_init_sysctl(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 584 | { |
| 585 | return 0; |
| 586 | } |
| 587 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 588 | static void nf_conntrack_standalone_fini_sysctl(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 589 | { |
| 590 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 591 | #endif /* CONFIG_SYSCTL */ |
| 592 | |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 593 | static int nf_conntrack_pernet_init(struct net *net) |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 594 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 595 | int ret; |
| 596 | |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 597 | ret = nf_conntrack_init_net(net); |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 598 | if (ret < 0) |
| 599 | goto out_init; |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 600 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 601 | ret = nf_conntrack_standalone_init_proc(net); |
| 602 | if (ret < 0) |
| 603 | goto out_proc; |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 604 | |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 605 | net->ct.sysctl_checksum = 1; |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 606 | net->ct.sysctl_log_invalid = 0; |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 607 | ret = nf_conntrack_standalone_init_sysctl(net); |
| 608 | if (ret < 0) |
| 609 | goto out_sysctl; |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 610 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 611 | return 0; |
| 612 | |
Alexey Dobriyan | 8025070 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 613 | out_sysctl: |
| 614 | nf_conntrack_standalone_fini_proc(net); |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 615 | out_proc: |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 616 | nf_conntrack_cleanup_net(net); |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 617 | out_init: |
| 618 | return ret; |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 619 | } |
| 620 | |
Vladimir Davydov | dece40e | 2013-03-13 23:40:14 +0000 | [diff] [blame] | 621 | static void nf_conntrack_pernet_exit(struct list_head *net_exit_list) |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 622 | { |
Vladimir Davydov | dece40e | 2013-03-13 23:40:14 +0000 | [diff] [blame] | 623 | struct net *net; |
| 624 | |
| 625 | list_for_each_entry(net, net_exit_list, exit_list) { |
| 626 | nf_conntrack_standalone_fini_sysctl(net); |
| 627 | nf_conntrack_standalone_fini_proc(net); |
| 628 | } |
| 629 | nf_conntrack_cleanup_net_list(net_exit_list); |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | static struct pernet_operations nf_conntrack_net_ops = { |
Vladimir Davydov | dece40e | 2013-03-13 23:40:14 +0000 | [diff] [blame] | 633 | .init = nf_conntrack_pernet_init, |
| 634 | .exit_batch = nf_conntrack_pernet_exit, |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 635 | }; |
| 636 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 637 | static int __init nf_conntrack_standalone_init(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 638 | { |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 639 | int ret = nf_conntrack_init_start(); |
| 640 | if (ret < 0) |
| 641 | goto out_start; |
| 642 | |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 643 | #ifdef CONFIG_SYSCTL |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 644 | nf_ct_netfilter_header = |
| 645 | register_net_sysctl(&init_net, "net", nf_ct_netfilter_table); |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 646 | if (!nf_ct_netfilter_header) { |
| 647 | pr_err("nf_conntrack: can't register to sysctl.\n"); |
Wei Yongjun | 5389090 | 2013-03-27 03:57:10 +0000 | [diff] [blame] | 648 | ret = -ENOMEM; |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 649 | goto out_sysctl; |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 650 | } |
Florian Westphal | 3183ab8 | 2016-06-22 13:26:10 +0200 | [diff] [blame] | 651 | |
| 652 | nf_conntrack_htable_size_user = nf_conntrack_htable_size; |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 653 | #endif |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 654 | |
| 655 | ret = register_pernet_subsys(&nf_conntrack_net_ops); |
| 656 | if (ret < 0) |
| 657 | goto out_pernet; |
| 658 | |
| 659 | nf_conntrack_init_end(); |
| 660 | return 0; |
| 661 | |
| 662 | out_pernet: |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 663 | #ifdef CONFIG_SYSCTL |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 664 | unregister_net_sysctl_table(nf_ct_netfilter_header); |
| 665 | out_sysctl: |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 666 | #endif |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 667 | nf_conntrack_cleanup_end(); |
| 668 | out_start: |
| 669 | return ret; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 672 | static void __exit nf_conntrack_standalone_fini(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 673 | { |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 674 | nf_conntrack_cleanup_start(); |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 675 | unregister_pernet_subsys(&nf_conntrack_net_ops); |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 676 | #ifdef CONFIG_SYSCTL |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 677 | unregister_net_sysctl_table(nf_ct_netfilter_header); |
Pablo Neira Ayuso | 5f9f946 | 2013-01-23 15:12:25 +0100 | [diff] [blame] | 678 | #endif |
Pablo Neira Ayuso | 1e47ee8 | 2013-01-10 16:12:01 +0100 | [diff] [blame] | 679 | nf_conntrack_cleanup_end(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 680 | } |
| 681 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 682 | module_init(nf_conntrack_standalone_init); |
| 683 | module_exit(nf_conntrack_standalone_fini); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 684 | |
| 685 | /* Some modules need us, but don't depend directly on any symbol. |
| 686 | They should call this. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 687 | void need_conntrack(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 688 | { |
| 689 | } |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 690 | EXPORT_SYMBOL_GPL(need_conntrack); |