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