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> |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 28 | #include <net/netfilter/nf_conntrack_acct.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 29 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 30 | MODULE_LICENSE("GPL"); |
| 31 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 32 | #ifdef CONFIG_PROC_FS |
Martin Josefsson | 77ab9cf | 2006-11-29 02:34:58 +0100 | [diff] [blame] | 33 | int |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 34 | print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple, |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 35 | const struct nf_conntrack_l3proto *l3proto, |
| 36 | const struct nf_conntrack_l4proto *l4proto) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 37 | { |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 38 | return l3proto->print_tuple(s, tuple) || l4proto->print_tuple(s, tuple); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 39 | } |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 40 | EXPORT_SYMBOL_GPL(print_tuple); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 41 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 42 | struct ct_iter_state { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 43 | struct seq_net_private p; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 44 | unsigned int bucket; |
| 45 | }; |
| 46 | |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 47 | static struct hlist_node *ct_get_first(struct seq_file *seq) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 48 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 49 | struct net *net = seq_file_net(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 50 | struct ct_iter_state *st = seq->private; |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 51 | struct hlist_node *n; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 52 | |
| 53 | for (st->bucket = 0; |
| 54 | st->bucket < nf_conntrack_htable_size; |
| 55 | st->bucket++) { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 56 | n = rcu_dereference(net->ct.hash[st->bucket].first); |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 57 | if (n) |
| 58 | return n; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 59 | } |
| 60 | return NULL; |
| 61 | } |
| 62 | |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 63 | static struct hlist_node *ct_get_next(struct seq_file *seq, |
| 64 | struct hlist_node *head) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 65 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 66 | struct net *net = seq_file_net(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 67 | struct ct_iter_state *st = seq->private; |
| 68 | |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 69 | head = rcu_dereference(head->next); |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 70 | while (head == NULL) { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 71 | if (++st->bucket >= nf_conntrack_htable_size) |
| 72 | return NULL; |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 73 | head = rcu_dereference(net->ct.hash[st->bucket].first); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 74 | } |
| 75 | return head; |
| 76 | } |
| 77 | |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 78 | 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] | 79 | { |
Patrick McHardy | f205c5e | 2007-07-07 22:28:14 -0700 | [diff] [blame] | 80 | struct hlist_node *head = ct_get_first(seq); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 81 | |
| 82 | if (head) |
| 83 | while (pos && (head = ct_get_next(seq, head))) |
| 84 | pos--; |
| 85 | return pos ? NULL : head; |
| 86 | } |
| 87 | |
| 88 | static void *ct_seq_start(struct seq_file *seq, loff_t *pos) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 89 | __acquires(RCU) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 90 | { |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 91 | rcu_read_lock(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 92 | return ct_get_idx(seq, *pos); |
| 93 | } |
| 94 | |
| 95 | static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos) |
| 96 | { |
| 97 | (*pos)++; |
| 98 | return ct_get_next(s, v); |
| 99 | } |
| 100 | |
| 101 | static void ct_seq_stop(struct seq_file *s, void *v) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 102 | __releases(RCU) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 103 | { |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 104 | rcu_read_unlock(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* return 0 on success, 1 in case of error */ |
| 108 | static int ct_seq_show(struct seq_file *s, void *v) |
| 109 | { |
| 110 | const struct nf_conntrack_tuple_hash *hash = v; |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 111 | const struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 112 | const struct nf_conntrack_l3proto *l3proto; |
| 113 | const struct nf_conntrack_l4proto *l4proto; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 114 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 115 | NF_CT_ASSERT(ct); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 116 | |
| 117 | /* we only want to print DIR_ORIGINAL */ |
| 118 | if (NF_CT_DIRECTION(hash)) |
| 119 | return 0; |
| 120 | |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 121 | l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 122 | NF_CT_ASSERT(l3proto); |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 123 | 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] | 124 | NF_CT_ASSERT(l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 125 | |
| 126 | if (seq_printf(s, "%-8s %u %-8s %u %ld ", |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 127 | l3proto->name, nf_ct_l3num(ct), |
| 128 | l4proto->name, nf_ct_protonum(ct), |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 129 | timer_pending(&ct->timeout) |
| 130 | ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 131 | return -ENOSPC; |
| 132 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 133 | if (l4proto->print_conntrack && l4proto->print_conntrack(s, ct)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 134 | return -ENOSPC; |
| 135 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 136 | if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 137 | l3proto, l4proto)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 138 | return -ENOSPC; |
| 139 | |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 140 | if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 141 | return -ENOSPC; |
| 142 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 143 | if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 144 | if (seq_printf(s, "[UNREPLIED] ")) |
| 145 | return -ENOSPC; |
| 146 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 147 | if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 148 | l3proto, l4proto)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 149 | return -ENOSPC; |
| 150 | |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 151 | if (seq_print_acct(s, ct, IP_CT_DIR_REPLY)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 152 | return -ENOSPC; |
| 153 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 154 | if (test_bit(IPS_ASSURED_BIT, &ct->status)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 155 | if (seq_printf(s, "[ASSURED] ")) |
| 156 | return -ENOSPC; |
| 157 | |
| 158 | #if defined(CONFIG_NF_CONNTRACK_MARK) |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 159 | if (seq_printf(s, "mark=%u ", ct->mark)) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 160 | return -ENOSPC; |
| 161 | #endif |
| 162 | |
James Morris | 7c9728c | 2006-06-09 00:31:46 -0700 | [diff] [blame] | 163 | #ifdef CONFIG_NF_CONNTRACK_SECMARK |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 164 | if (seq_printf(s, "secmark=%u ", ct->secmark)) |
James Morris | 7c9728c | 2006-06-09 00:31:46 -0700 | [diff] [blame] | 165 | return -ENOSPC; |
| 166 | #endif |
| 167 | |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 168 | 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] | 169 | return -ENOSPC; |
YOSHIFUJI Hideaki | a5d2926 | 2007-07-19 10:44:21 +0900 | [diff] [blame] | 170 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 174 | static const struct seq_operations ct_seq_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 175 | .start = ct_seq_start, |
| 176 | .next = ct_seq_next, |
| 177 | .stop = ct_seq_stop, |
| 178 | .show = ct_seq_show |
| 179 | }; |
| 180 | |
| 181 | static int ct_open(struct inode *inode, struct file *file) |
| 182 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 183 | return seq_open_net(inode, file, &ct_seq_ops, |
Pavel Emelyanov | e2da591 | 2007-10-10 02:29:58 -0700 | [diff] [blame] | 184 | sizeof(struct ct_iter_state)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 187 | static const struct file_operations ct_file_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 188 | .owner = THIS_MODULE, |
| 189 | .open = ct_open, |
| 190 | .read = seq_read, |
| 191 | .llseek = seq_lseek, |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 192 | .release = seq_release_net, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 193 | }; |
| 194 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 195 | static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos) |
| 196 | { |
| 197 | int cpu; |
| 198 | |
| 199 | if (*pos == 0) |
| 200 | return SEQ_START_TOKEN; |
| 201 | |
| 202 | for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) { |
| 203 | if (!cpu_possible(cpu)) |
| 204 | continue; |
| 205 | *pos = cpu + 1; |
| 206 | return &per_cpu(nf_conntrack_stat, cpu); |
| 207 | } |
| 208 | |
| 209 | return NULL; |
| 210 | } |
| 211 | |
| 212 | static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 213 | { |
| 214 | int cpu; |
| 215 | |
| 216 | for (cpu = *pos; cpu < NR_CPUS; ++cpu) { |
| 217 | if (!cpu_possible(cpu)) |
| 218 | continue; |
| 219 | *pos = cpu + 1; |
| 220 | return &per_cpu(nf_conntrack_stat, cpu); |
| 221 | } |
| 222 | |
| 223 | return NULL; |
| 224 | } |
| 225 | |
| 226 | static void ct_cpu_seq_stop(struct seq_file *seq, void *v) |
| 227 | { |
| 228 | } |
| 229 | |
| 230 | static int ct_cpu_seq_show(struct seq_file *seq, void *v) |
| 231 | { |
Alexey Dobriyan | 49ac871 | 2008-10-08 11:35:03 +0200 | [diff] [blame] | 232 | unsigned int nr_conntracks = atomic_read(&init_net.ct.count); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 233 | const struct ip_conntrack_stat *st = v; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 234 | |
| 235 | if (v == SEQ_START_TOKEN) { |
| 236 | 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"); |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x " |
| 241 | "%08x %08x %08x %08x %08x %08x %08x %08x \n", |
| 242 | nr_conntracks, |
| 243 | st->searched, |
| 244 | st->found, |
| 245 | st->new, |
| 246 | st->invalid, |
| 247 | st->ignore, |
| 248 | st->delete, |
| 249 | st->delete_list, |
| 250 | st->insert, |
| 251 | st->insert_failed, |
| 252 | st->drop, |
| 253 | st->early_drop, |
| 254 | st->error, |
| 255 | |
| 256 | st->expect_new, |
| 257 | st->expect_create, |
| 258 | st->expect_delete |
| 259 | ); |
| 260 | return 0; |
| 261 | } |
| 262 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 263 | static const struct seq_operations ct_cpu_seq_ops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 264 | .start = ct_cpu_seq_start, |
| 265 | .next = ct_cpu_seq_next, |
| 266 | .stop = ct_cpu_seq_stop, |
| 267 | .show = ct_cpu_seq_show, |
| 268 | }; |
| 269 | |
| 270 | static int ct_cpu_seq_open(struct inode *inode, struct file *file) |
| 271 | { |
| 272 | return seq_open(file, &ct_cpu_seq_ops); |
| 273 | } |
| 274 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 275 | static const struct file_operations ct_cpu_seq_fops = { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 276 | .owner = THIS_MODULE, |
| 277 | .open = ct_cpu_seq_open, |
| 278 | .read = seq_read, |
| 279 | .llseek = seq_lseek, |
Pavel Emelyanov | 665bba1 | 2008-02-29 11:39:17 -0800 | [diff] [blame] | 280 | .release = seq_release, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 281 | }; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 282 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 283 | static int nf_conntrack_standalone_init_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 284 | { |
| 285 | struct proc_dir_entry *pde; |
| 286 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 287 | pde = proc_net_fops_create(net, "nf_conntrack", 0440, &ct_file_ops); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 288 | if (!pde) |
| 289 | goto out_nf_conntrack; |
Denis V. Lunev | 52c0e11 | 2008-05-02 04:10:57 -0700 | [diff] [blame] | 290 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 291 | pde = proc_create("nf_conntrack", S_IRUGO, net->proc_net_stat, |
Denis V. Lunev | 52c0e11 | 2008-05-02 04:10:57 -0700 | [diff] [blame] | 292 | &ct_cpu_seq_fops); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 293 | if (!pde) |
| 294 | goto out_stat_nf_conntrack; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 295 | return 0; |
| 296 | |
| 297 | out_stat_nf_conntrack: |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 298 | proc_net_remove(net, "nf_conntrack"); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 299 | out_nf_conntrack: |
| 300 | return -ENOMEM; |
| 301 | } |
| 302 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 303 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 304 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 305 | remove_proc_entry("nf_conntrack", net->proc_net_stat); |
| 306 | proc_net_remove(net, "nf_conntrack"); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 307 | } |
| 308 | #else |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 309 | static int nf_conntrack_standalone_init_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 310 | { |
| 311 | return 0; |
| 312 | } |
| 313 | |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 314 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 315 | { |
| 316 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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; |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 330 | static struct ctl_table_header *nf_ct_netfilter_header; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 331 | |
| 332 | static ctl_table nf_ct_sysctl_table[] = { |
| 333 | { |
| 334 | .ctl_name = NET_NF_CONNTRACK_MAX, |
| 335 | .procname = "nf_conntrack_max", |
| 336 | .data = &nf_conntrack_max, |
| 337 | .maxlen = sizeof(int), |
| 338 | .mode = 0644, |
| 339 | .proc_handler = &proc_dointvec, |
| 340 | }, |
| 341 | { |
| 342 | .ctl_name = NET_NF_CONNTRACK_COUNT, |
| 343 | .procname = "nf_conntrack_count", |
Alexey Dobriyan | 49ac871 | 2008-10-08 11:35:03 +0200 | [diff] [blame] | 344 | .data = &init_net.ct.count, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 345 | .maxlen = sizeof(int), |
| 346 | .mode = 0444, |
| 347 | .proc_handler = &proc_dointvec, |
| 348 | }, |
| 349 | { |
| 350 | .ctl_name = NET_NF_CONNTRACK_BUCKETS, |
| 351 | .procname = "nf_conntrack_buckets", |
| 352 | .data = &nf_conntrack_htable_size, |
| 353 | .maxlen = sizeof(unsigned int), |
| 354 | .mode = 0444, |
| 355 | .proc_handler = &proc_dointvec, |
| 356 | }, |
| 357 | { |
Patrick McHardy | 39a27a3 | 2006-05-29 18:23:54 -0700 | [diff] [blame] | 358 | .ctl_name = NET_NF_CONNTRACK_CHECKSUM, |
| 359 | .procname = "nf_conntrack_checksum", |
| 360 | .data = &nf_conntrack_checksum, |
| 361 | .maxlen = sizeof(unsigned int), |
| 362 | .mode = 0644, |
| 363 | .proc_handler = &proc_dointvec, |
| 364 | }, |
| 365 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 366 | .ctl_name = NET_NF_CONNTRACK_LOG_INVALID, |
| 367 | .procname = "nf_conntrack_log_invalid", |
| 368 | .data = &nf_ct_log_invalid, |
| 369 | .maxlen = sizeof(unsigned int), |
| 370 | .mode = 0644, |
| 371 | .proc_handler = &proc_dointvec_minmax, |
| 372 | .strategy = &sysctl_intvec, |
| 373 | .extra1 = &log_invalid_proto_min, |
| 374 | .extra2 = &log_invalid_proto_max, |
| 375 | }, |
Patrick McHardy | f264a7d | 2007-07-07 22:36:24 -0700 | [diff] [blame] | 376 | { |
| 377 | .ctl_name = CTL_UNNUMBERED, |
| 378 | .procname = "nf_conntrack_expect_max", |
| 379 | .data = &nf_ct_expect_max, |
| 380 | .maxlen = sizeof(int), |
| 381 | .mode = 0644, |
| 382 | .proc_handler = &proc_dointvec, |
| 383 | }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 384 | { .ctl_name = 0 } |
| 385 | }; |
| 386 | |
| 387 | #define NET_NF_CONNTRACK_MAX 2089 |
| 388 | |
| 389 | static ctl_table nf_ct_netfilter_table[] = { |
| 390 | { |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 391 | .ctl_name = NET_NF_CONNTRACK_MAX, |
| 392 | .procname = "nf_conntrack_max", |
| 393 | .data = &nf_conntrack_max, |
| 394 | .maxlen = sizeof(int), |
| 395 | .mode = 0644, |
| 396 | .proc_handler = &proc_dointvec, |
| 397 | }, |
| 398 | { .ctl_name = 0 } |
| 399 | }; |
| 400 | |
Patrick McHardy | 9e23249 | 2008-01-31 04:54:45 -0800 | [diff] [blame] | 401 | static struct ctl_path nf_ct_path[] = { |
Pavel Emelyanov | 3d7cc2b | 2008-01-09 00:33:11 -0800 | [diff] [blame] | 402 | { .procname = "net", .ctl_name = CTL_NET, }, |
| 403 | { } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 404 | }; |
Pavel Emelyanov | 3d7cc2b | 2008-01-09 00:33:11 -0800 | [diff] [blame] | 405 | |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 406 | EXPORT_SYMBOL_GPL(nf_ct_log_invalid); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 407 | |
| 408 | static int nf_conntrack_standalone_init_sysctl(void) |
| 409 | { |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 410 | nf_ct_netfilter_header = |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 411 | register_sysctl_paths(nf_ct_path, nf_ct_netfilter_table); |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 412 | if (!nf_ct_netfilter_header) |
| 413 | goto out; |
| 414 | |
| 415 | nf_ct_sysctl_header = |
| 416 | register_sysctl_paths(nf_net_netfilter_sysctl_path, |
| 417 | nf_ct_sysctl_table); |
| 418 | if (!nf_ct_sysctl_header) |
| 419 | goto out_unregister_netfilter; |
| 420 | |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 421 | return 0; |
| 422 | |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 423 | out_unregister_netfilter: |
| 424 | unregister_sysctl_table(nf_ct_netfilter_header); |
| 425 | out: |
| 426 | printk("nf_conntrack: can't register to sysctl.\n"); |
| 427 | return -ENOMEM; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void nf_conntrack_standalone_fini_sysctl(void) |
| 431 | { |
Krzysztof Piotr Oledzki | 9714be7 | 2008-08-06 02:35:44 -0700 | [diff] [blame] | 432 | unregister_sysctl_table(nf_ct_netfilter_header); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 433 | unregister_sysctl_table(nf_ct_sysctl_header); |
| 434 | } |
| 435 | #else |
| 436 | static int nf_conntrack_standalone_init_sysctl(void) |
| 437 | { |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static void nf_conntrack_standalone_fini_sysctl(void) |
| 442 | { |
| 443 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 444 | #endif /* CONFIG_SYSCTL */ |
| 445 | |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 446 | static int nf_conntrack_net_init(struct net *net) |
| 447 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 448 | int ret; |
| 449 | |
| 450 | ret = nf_conntrack_init(net); |
| 451 | if (ret < 0) |
| 452 | goto out_init; |
| 453 | ret = nf_conntrack_standalone_init_proc(net); |
| 454 | if (ret < 0) |
| 455 | goto out_proc; |
| 456 | return 0; |
| 457 | |
| 458 | out_proc: |
| 459 | nf_conntrack_cleanup(net); |
| 460 | out_init: |
| 461 | return ret; |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | static void nf_conntrack_net_exit(struct net *net) |
| 465 | { |
Alexey Dobriyan | b2ce2c7 | 2008-10-08 11:35:05 +0200 | [diff] [blame^] | 466 | nf_conntrack_standalone_fini_proc(net); |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 467 | nf_conntrack_cleanup(net); |
| 468 | } |
| 469 | |
| 470 | static struct pernet_operations nf_conntrack_net_ops = { |
| 471 | .init = nf_conntrack_net_init, |
| 472 | .exit = nf_conntrack_net_exit, |
| 473 | }; |
| 474 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 475 | static int __init nf_conntrack_standalone_init(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 476 | { |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 477 | int ret; |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 478 | |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 479 | ret = register_pernet_subsys(&nf_conntrack_net_ops); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 480 | if (ret < 0) |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 481 | goto out; |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 482 | ret = nf_conntrack_standalone_init_sysctl(); |
| 483 | if (ret < 0) |
| 484 | goto out_sysctl; |
| 485 | return 0; |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 486 | |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 487 | out_sysctl: |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 488 | unregister_pernet_subsys(&nf_conntrack_net_ops); |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 489 | out: |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 490 | return ret; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 493 | static void __exit nf_conntrack_standalone_fini(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 494 | { |
Alexey Dobriyan | b916f7d | 2008-03-20 15:15:43 +0100 | [diff] [blame] | 495 | nf_conntrack_standalone_fini_sysctl(); |
Alexey Dobriyan | dfdb8d7 | 2008-10-08 11:35:02 +0200 | [diff] [blame] | 496 | unregister_pernet_subsys(&nf_conntrack_net_ops); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 499 | module_init(nf_conntrack_standalone_init); |
| 500 | module_exit(nf_conntrack_standalone_fini); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 501 | |
| 502 | /* Some modules need us, but don't depend directly on any symbol. |
| 503 | They should call this. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 504 | void need_conntrack(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 505 | { |
| 506 | } |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 507 | EXPORT_SYMBOL_GPL(need_conntrack); |