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> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 7 | */ |
| 8 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 9 | #include <linux/types.h> |
| 10 | #include <linux/netfilter.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/skbuff.h> |
| 13 | #include <linux/proc_fs.h> |
| 14 | #include <linux/seq_file.h> |
| 15 | #include <linux/percpu.h> |
| 16 | #include <linux/netdevice.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 17 | #include <net/net_namespace.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 18 | #ifdef CONFIG_SYSCTL |
| 19 | #include <linux/sysctl.h> |
| 20 | #endif |
| 21 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 22 | #include <net/netfilter/nf_conntrack.h> |
Martin Josefsson | f618012 | 2006-11-29 02:35:01 +0100 | [diff] [blame] | 23 | #include <net/netfilter/nf_conntrack_core.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 24 | #include <net/netfilter/nf_conntrack_l3proto.h> |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 25 | #include <net/netfilter/nf_conntrack_l4proto.h> |
Martin Josefsson | 77ab9cf | 2006-11-29 02:34:58 +0100 | [diff] [blame] | 26 | #include <net/netfilter/nf_conntrack_expect.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 27 | #include <net/netfilter/nf_conntrack_helper.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 28 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 29 | MODULE_LICENSE("GPL"); |
| 30 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 31 | #ifdef CONFIG_PROC_FS |
Martin Josefsson | 77ab9cf | 2006-11-29 02:34:58 +0100 | [diff] [blame] | 32 | int |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 33 | print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple, |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame^] | 34 | const struct nf_conntrack_l3proto *l3proto, |
| 35 | const struct nf_conntrack_l4proto *l4proto) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 36 | { |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 37 | return l3proto->print_tuple(s, tuple) || l4proto->print_tuple(s, tuple); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 38 | } |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 39 | EXPORT_SYMBOL_GPL(print_tuple); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 40 | |
| 41 | #ifdef CONFIG_NF_CT_ACCT |
| 42 | static unsigned int |
| 43 | seq_print_counters(struct seq_file *s, |
| 44 | const struct ip_conntrack_counter *counter) |
| 45 | { |
| 46 | return seq_printf(s, "packets=%llu bytes=%llu ", |
| 47 | (unsigned long long)counter->packets, |
| 48 | (unsigned long long)counter->bytes); |
| 49 | } |
| 50 | #else |
| 51 | #define seq_print_counters(x, y) 0 |
| 52 | #endif |
| 53 | |
| 54 | struct ct_iter_state { |
| 55 | unsigned int bucket; |
| 56 | }; |
| 57 | |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 58 | static struct hlist_node *ct_get_first(struct seq_file *seq) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 59 | { |
| 60 | struct ct_iter_state *st = seq->private; |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 61 | struct hlist_node *n; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 62 | |
| 63 | for (st->bucket = 0; |
| 64 | st->bucket < nf_conntrack_htable_size; |
| 65 | st->bucket++) { |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 66 | n = rcu_dereference(nf_conntrack_hash[st->bucket].first); |
| 67 | if (n) |
| 68 | return n; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 69 | } |
| 70 | return NULL; |
| 71 | } |
| 72 | |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 73 | static struct hlist_node *ct_get_next(struct seq_file *seq, |
| 74 | struct hlist_node *head) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 75 | { |
| 76 | struct ct_iter_state *st = seq->private; |
| 77 | |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 78 | head = rcu_dereference(head->next); |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 79 | while (head == NULL) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 80 | if (++st->bucket >= nf_conntrack_htable_size) |
| 81 | return NULL; |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 82 | head = rcu_dereference(nf_conntrack_hash[st->bucket].first); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 83 | } |
| 84 | return head; |
| 85 | } |
| 86 | |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 87 | static struct hlist_node *ct_get_idx(struct seq_file *seq, loff_t pos) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 88 | { |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 89 | struct hlist_node *head = ct_get_first(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 90 | |
| 91 | if (head) |
| 92 | while (pos && (head = ct_get_next(seq, head))) |
| 93 | pos--; |
| 94 | return pos ? NULL : head; |
| 95 | } |
| 96 | |
| 97 | static void *ct_seq_start(struct seq_file *seq, loff_t *pos) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 98 | __acquires(RCU) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 99 | { |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 100 | rcu_read_lock(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 101 | return ct_get_idx(seq, *pos); |
| 102 | } |
| 103 | |
| 104 | static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos) |
| 105 | { |
| 106 | (*pos)++; |
| 107 | return ct_get_next(s, v); |
| 108 | } |
| 109 | |
| 110 | static void ct_seq_stop(struct seq_file *s, void *v) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 111 | __releases(RCU) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 112 | { |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 113 | rcu_read_unlock(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* return 0 on success, 1 in case of error */ |
| 117 | static int ct_seq_show(struct seq_file *s, void *v) |
| 118 | { |
| 119 | const struct nf_conntrack_tuple_hash *hash = v; |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 120 | const struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame^] | 121 | const struct nf_conntrack_l3proto *l3proto; |
| 122 | const struct nf_conntrack_l4proto *l4proto; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 123 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 124 | NF_CT_ASSERT(ct); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 125 | |
| 126 | /* we only want to print DIR_ORIGINAL */ |
| 127 | if (NF_CT_DIRECTION(hash)) |
| 128 | return 0; |
| 129 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 130 | l3proto = __nf_ct_l3proto_find(ct->tuplehash[IP_CT_DIR_ORIGINAL] |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 131 | .tuple.src.l3num); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 132 | |
| 133 | NF_CT_ASSERT(l3proto); |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 134 | l4proto = __nf_ct_l4proto_find(ct->tuplehash[IP_CT_DIR_ORIGINAL] |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 135 | .tuple.src.l3num, |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 136 | ct->tuplehash[IP_CT_DIR_ORIGINAL] |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 137 | .tuple.dst.protonum); |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 138 | NF_CT_ASSERT(l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 139 | |
| 140 | if (seq_printf(s, "%-8s %u %-8s %u %ld ", |
| 141 | l3proto->name, |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 142 | ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 143 | l4proto->name, |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 144 | ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum, |
| 145 | timer_pending(&ct->timeout) |
| 146 | ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 147 | return -ENOSPC; |
| 148 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 149 | if (l4proto->print_conntrack && l4proto->print_conntrack(s, ct)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 150 | return -ENOSPC; |
| 151 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 152 | if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 153 | l3proto, l4proto)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 154 | return -ENOSPC; |
| 155 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 156 | if (seq_print_counters(s, &ct->counters[IP_CT_DIR_ORIGINAL])) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 157 | return -ENOSPC; |
| 158 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 159 | if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 160 | if (seq_printf(s, "[UNREPLIED] ")) |
| 161 | return -ENOSPC; |
| 162 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 163 | if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 164 | l3proto, l4proto)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 165 | return -ENOSPC; |
| 166 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 167 | if (seq_print_counters(s, &ct->counters[IP_CT_DIR_REPLY])) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 168 | return -ENOSPC; |
| 169 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 170 | if (test_bit(IPS_ASSURED_BIT, &ct->status)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 171 | if (seq_printf(s, "[ASSURED] ")) |
| 172 | return -ENOSPC; |
| 173 | |
| 174 | #if defined(CONFIG_NF_CONNTRACK_MARK) |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 175 | if (seq_printf(s, "mark=%u ", ct->mark)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 176 | return -ENOSPC; |
| 177 | #endif |
| 178 | |
James Morris | 7c9728c | 2006-06-09 00:31:46 -0700 | [diff] [blame] | 179 | #ifdef CONFIG_NF_CONNTRACK_SECMARK |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 180 | if (seq_printf(s, "secmark=%u ", ct->secmark)) |
James Morris | 7c9728c | 2006-06-09 00:31:46 -0700 | [diff] [blame] | 181 | return -ENOSPC; |
| 182 | #endif |
| 183 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 184 | if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use))) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 185 | return -ENOSPC; |
YOSHIFUJI Hideaki | a5d2926 | 2007-07-19 10:44:21 +0900 | [diff] [blame] | 186 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 190 | static const struct seq_operations ct_seq_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 191 | .start = ct_seq_start, |
| 192 | .next = ct_seq_next, |
| 193 | .stop = ct_seq_stop, |
| 194 | .show = ct_seq_show |
| 195 | }; |
| 196 | |
| 197 | static int ct_open(struct inode *inode, struct file *file) |
| 198 | { |
Pavel Emelyanov | e2da591 | 2007-10-10 02:29:58 -0700 | [diff] [blame] | 199 | return seq_open_private(file, &ct_seq_ops, |
| 200 | sizeof(struct ct_iter_state)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 203 | static const struct file_operations ct_file_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 204 | .owner = THIS_MODULE, |
| 205 | .open = ct_open, |
| 206 | .read = seq_read, |
| 207 | .llseek = seq_lseek, |
| 208 | .release = seq_release_private, |
| 209 | }; |
| 210 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 211 | static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos) |
| 212 | { |
| 213 | int cpu; |
| 214 | |
| 215 | if (*pos == 0) |
| 216 | return SEQ_START_TOKEN; |
| 217 | |
| 218 | for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) { |
| 219 | if (!cpu_possible(cpu)) |
| 220 | continue; |
| 221 | *pos = cpu + 1; |
| 222 | return &per_cpu(nf_conntrack_stat, cpu); |
| 223 | } |
| 224 | |
| 225 | return NULL; |
| 226 | } |
| 227 | |
| 228 | static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 229 | { |
| 230 | int cpu; |
| 231 | |
| 232 | for (cpu = *pos; cpu < NR_CPUS; ++cpu) { |
| 233 | if (!cpu_possible(cpu)) |
| 234 | continue; |
| 235 | *pos = cpu + 1; |
| 236 | return &per_cpu(nf_conntrack_stat, cpu); |
| 237 | } |
| 238 | |
| 239 | return NULL; |
| 240 | } |
| 241 | |
| 242 | static void ct_cpu_seq_stop(struct seq_file *seq, void *v) |
| 243 | { |
| 244 | } |
| 245 | |
| 246 | static int ct_cpu_seq_show(struct seq_file *seq, void *v) |
| 247 | { |
| 248 | unsigned int nr_conntracks = atomic_read(&nf_conntrack_count); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame^] | 249 | const struct ip_conntrack_stat *st = v; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 250 | |
| 251 | if (v == SEQ_START_TOKEN) { |
| 252 | 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\n"); |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x " |
| 257 | "%08x %08x %08x %08x %08x %08x %08x %08x \n", |
| 258 | nr_conntracks, |
| 259 | st->searched, |
| 260 | st->found, |
| 261 | st->new, |
| 262 | st->invalid, |
| 263 | st->ignore, |
| 264 | st->delete, |
| 265 | st->delete_list, |
| 266 | st->insert, |
| 267 | st->insert_failed, |
| 268 | st->drop, |
| 269 | st->early_drop, |
| 270 | st->error, |
| 271 | |
| 272 | st->expect_new, |
| 273 | st->expect_create, |
| 274 | st->expect_delete |
| 275 | ); |
| 276 | return 0; |
| 277 | } |
| 278 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 279 | static const struct seq_operations ct_cpu_seq_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 280 | .start = ct_cpu_seq_start, |
| 281 | .next = ct_cpu_seq_next, |
| 282 | .stop = ct_cpu_seq_stop, |
| 283 | .show = ct_cpu_seq_show, |
| 284 | }; |
| 285 | |
| 286 | static int ct_cpu_seq_open(struct inode *inode, struct file *file) |
| 287 | { |
| 288 | return seq_open(file, &ct_cpu_seq_ops); |
| 289 | } |
| 290 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 291 | static const struct file_operations ct_cpu_seq_fops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 292 | .owner = THIS_MODULE, |
| 293 | .open = ct_cpu_seq_open, |
| 294 | .read = seq_read, |
| 295 | .llseek = seq_lseek, |
| 296 | .release = seq_release_private, |
| 297 | }; |
| 298 | #endif /* CONFIG_PROC_FS */ |
| 299 | |
| 300 | /* Sysctl support */ |
| 301 | |
Brian Haley | 94aec08 | 2006-09-18 00:05:22 -0700 | [diff] [blame] | 302 | int nf_conntrack_checksum __read_mostly = 1; |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 303 | EXPORT_SYMBOL_GPL(nf_conntrack_checksum); |
Adrian Bunk | 72b5582 | 2006-07-24 22:53:12 -0700 | [diff] [blame] | 304 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 305 | #ifdef CONFIG_SYSCTL |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 306 | /* Log invalid packets of a given protocol */ |
| 307 | static int log_invalid_proto_min = 0; |
| 308 | static int log_invalid_proto_max = 255; |
| 309 | |
| 310 | static struct ctl_table_header *nf_ct_sysctl_header; |
| 311 | |
| 312 | static ctl_table nf_ct_sysctl_table[] = { |
| 313 | { |
| 314 | .ctl_name = NET_NF_CONNTRACK_MAX, |
| 315 | .procname = "nf_conntrack_max", |
| 316 | .data = &nf_conntrack_max, |
| 317 | .maxlen = sizeof(int), |
| 318 | .mode = 0644, |
| 319 | .proc_handler = &proc_dointvec, |
| 320 | }, |
| 321 | { |
| 322 | .ctl_name = NET_NF_CONNTRACK_COUNT, |
| 323 | .procname = "nf_conntrack_count", |
| 324 | .data = &nf_conntrack_count, |
| 325 | .maxlen = sizeof(int), |
| 326 | .mode = 0444, |
| 327 | .proc_handler = &proc_dointvec, |
| 328 | }, |
| 329 | { |
| 330 | .ctl_name = NET_NF_CONNTRACK_BUCKETS, |
| 331 | .procname = "nf_conntrack_buckets", |
| 332 | .data = &nf_conntrack_htable_size, |
| 333 | .maxlen = sizeof(unsigned int), |
| 334 | .mode = 0444, |
| 335 | .proc_handler = &proc_dointvec, |
| 336 | }, |
| 337 | { |
Patrick McHardy | 39a27a3 | 2006-05-29 18:23:54 -0700 | [diff] [blame] | 338 | .ctl_name = NET_NF_CONNTRACK_CHECKSUM, |
| 339 | .procname = "nf_conntrack_checksum", |
| 340 | .data = &nf_conntrack_checksum, |
| 341 | .maxlen = sizeof(unsigned int), |
| 342 | .mode = 0644, |
| 343 | .proc_handler = &proc_dointvec, |
| 344 | }, |
| 345 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 346 | .ctl_name = NET_NF_CONNTRACK_LOG_INVALID, |
| 347 | .procname = "nf_conntrack_log_invalid", |
| 348 | .data = &nf_ct_log_invalid, |
| 349 | .maxlen = sizeof(unsigned int), |
| 350 | .mode = 0644, |
| 351 | .proc_handler = &proc_dointvec_minmax, |
| 352 | .strategy = &sysctl_intvec, |
| 353 | .extra1 = &log_invalid_proto_min, |
| 354 | .extra2 = &log_invalid_proto_max, |
| 355 | }, |
Patrick McHardy | f264a7d | 2007-07-07 22:36:24 -0700 | [diff] [blame] | 356 | { |
| 357 | .ctl_name = CTL_UNNUMBERED, |
| 358 | .procname = "nf_conntrack_expect_max", |
| 359 | .data = &nf_ct_expect_max, |
| 360 | .maxlen = sizeof(int), |
| 361 | .mode = 0644, |
| 362 | .proc_handler = &proc_dointvec, |
| 363 | }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 364 | { .ctl_name = 0 } |
| 365 | }; |
| 366 | |
| 367 | #define NET_NF_CONNTRACK_MAX 2089 |
| 368 | |
| 369 | static ctl_table nf_ct_netfilter_table[] = { |
| 370 | { |
| 371 | .ctl_name = NET_NETFILTER, |
| 372 | .procname = "netfilter", |
| 373 | .mode = 0555, |
| 374 | .child = nf_ct_sysctl_table, |
| 375 | }, |
| 376 | { |
| 377 | .ctl_name = NET_NF_CONNTRACK_MAX, |
| 378 | .procname = "nf_conntrack_max", |
| 379 | .data = &nf_conntrack_max, |
| 380 | .maxlen = sizeof(int), |
| 381 | .mode = 0644, |
| 382 | .proc_handler = &proc_dointvec, |
| 383 | }, |
| 384 | { .ctl_name = 0 } |
| 385 | }; |
| 386 | |
Pavel Emelyanov | 3d7cc2b | 2008-01-09 00:33:11 -0800 | [diff] [blame] | 387 | struct ctl_path nf_ct_path[] = { |
| 388 | { .procname = "net", .ctl_name = CTL_NET, }, |
| 389 | { } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 390 | }; |
Pavel Emelyanov | 3d7cc2b | 2008-01-09 00:33:11 -0800 | [diff] [blame] | 391 | |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 392 | EXPORT_SYMBOL_GPL(nf_ct_log_invalid); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 393 | #endif /* CONFIG_SYSCTL */ |
| 394 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 395 | static int __init nf_conntrack_standalone_init(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 396 | { |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 397 | #ifdef CONFIG_PROC_FS |
Patrick McHardy | e9c1b08 | 2007-07-07 22:32:53 -0700 | [diff] [blame] | 398 | struct proc_dir_entry *proc, *proc_stat; |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 399 | #endif |
| 400 | int ret = 0; |
| 401 | |
| 402 | ret = nf_conntrack_init(); |
| 403 | if (ret < 0) |
| 404 | return ret; |
| 405 | |
| 406 | #ifdef CONFIG_PROC_FS |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 407 | proc = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 408 | if (!proc) goto cleanup_init; |
| 409 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 410 | proc_stat = create_proc_entry("nf_conntrack", S_IRUGO, init_net.proc_net_stat); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 411 | if (!proc_stat) |
Patrick McHardy | e9c1b08 | 2007-07-07 22:32:53 -0700 | [diff] [blame] | 412 | goto cleanup_proc; |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 413 | |
| 414 | proc_stat->proc_fops = &ct_cpu_seq_fops; |
| 415 | proc_stat->owner = THIS_MODULE; |
| 416 | #endif |
| 417 | #ifdef CONFIG_SYSCTL |
Pavel Emelyanov | 3d7cc2b | 2008-01-09 00:33:11 -0800 | [diff] [blame] | 418 | nf_ct_sysctl_header = register_sysctl_paths(nf_ct_path, |
| 419 | nf_ct_netfilter_table); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 420 | if (nf_ct_sysctl_header == NULL) { |
| 421 | printk("nf_conntrack: can't register to sysctl.\n"); |
| 422 | ret = -ENOMEM; |
| 423 | goto cleanup_proc_stat; |
| 424 | } |
| 425 | #endif |
| 426 | return ret; |
| 427 | |
| 428 | #ifdef CONFIG_SYSCTL |
| 429 | cleanup_proc_stat: |
| 430 | #endif |
| 431 | #ifdef CONFIG_PROC_FS |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 432 | remove_proc_entry("nf_conntrack", init_net. proc_net_stat); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 433 | cleanup_proc: |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 434 | proc_net_remove(&init_net, "nf_conntrack"); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 435 | cleanup_init: |
| 436 | #endif /* CNFIG_PROC_FS */ |
| 437 | nf_conntrack_cleanup(); |
| 438 | return ret; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 441 | static void __exit nf_conntrack_standalone_fini(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 442 | { |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 443 | #ifdef CONFIG_SYSCTL |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 444 | unregister_sysctl_table(nf_ct_sysctl_header); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 445 | #endif |
| 446 | #ifdef CONFIG_PROC_FS |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 447 | remove_proc_entry("nf_conntrack", init_net.proc_net_stat); |
| 448 | proc_net_remove(&init_net, "nf_conntrack"); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 449 | #endif /* CNFIG_PROC_FS */ |
| 450 | nf_conntrack_cleanup(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 453 | module_init(nf_conntrack_standalone_init); |
| 454 | module_exit(nf_conntrack_standalone_fini); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 455 | |
| 456 | /* Some modules need us, but don't depend directly on any symbol. |
| 457 | They should call this. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 458 | void need_conntrack(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 459 | { |
| 460 | } |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 461 | EXPORT_SYMBOL_GPL(need_conntrack); |