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