Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 1 | /* ip_conntrack proc compat - based on ip_conntrack_standalone.c |
| 2 | * |
| 3 | * (C) 1999-2001 Paul `Rusty' Russell |
| 4 | * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org> |
Patrick McHardy | f229f6c | 2013-04-06 15:24:29 +0200 | [diff] [blame] | 5 | * (C) 2006-2010 Patrick McHardy <kaber@trash.net> |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/proc_fs.h> |
| 13 | #include <linux/seq_file.h> |
| 14 | #include <linux/percpu.h> |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 15 | #include <linux/security.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 16 | #include <net/net_namespace.h> |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 17 | |
| 18 | #include <linux/netfilter.h> |
| 19 | #include <net/netfilter/nf_conntrack_core.h> |
| 20 | #include <net/netfilter/nf_conntrack_l3proto.h> |
| 21 | #include <net/netfilter/nf_conntrack_l4proto.h> |
| 22 | #include <net/netfilter/nf_conntrack_expect.h> |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 23 | #include <net/netfilter/nf_conntrack_acct.h> |
Eric Dumazet | eb73316 | 2010-11-15 18:43:59 +0100 | [diff] [blame] | 24 | #include <linux/rculist_nulls.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 25 | #include <linux/export.h> |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 26 | |
| 27 | struct ct_iter_state { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 28 | struct seq_net_private p; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 29 | unsigned int bucket; |
| 30 | }; |
| 31 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 32 | static struct hlist_nulls_node *ct_get_first(struct seq_file *seq) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 33 | { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 34 | struct net *net = seq_file_net(seq); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 35 | struct ct_iter_state *st = seq->private; |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 36 | struct hlist_nulls_node *n; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 37 | |
| 38 | for (st->bucket = 0; |
Patrick McHardy | d696c7b | 2010-02-08 11:18:07 -0800 | [diff] [blame] | 39 | st->bucket < net->ct.htable_size; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 40 | st->bucket++) { |
Eric Dumazet | eb73316 | 2010-11-15 18:43:59 +0100 | [diff] [blame] | 41 | n = rcu_dereference( |
| 42 | hlist_nulls_first_rcu(&net->ct.hash[st->bucket])); |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 43 | if (!is_a_nulls(n)) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 44 | return n; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 45 | } |
| 46 | return NULL; |
| 47 | } |
| 48 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 49 | static struct hlist_nulls_node *ct_get_next(struct seq_file *seq, |
| 50 | struct hlist_nulls_node *head) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 51 | { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 52 | struct net *net = seq_file_net(seq); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 53 | struct ct_iter_state *st = seq->private; |
| 54 | |
Eric Dumazet | eb73316 | 2010-11-15 18:43:59 +0100 | [diff] [blame] | 55 | head = rcu_dereference(hlist_nulls_next_rcu(head)); |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 56 | while (is_a_nulls(head)) { |
| 57 | if (likely(get_nulls_value(head) == st->bucket)) { |
Patrick McHardy | d696c7b | 2010-02-08 11:18:07 -0800 | [diff] [blame] | 58 | if (++st->bucket >= net->ct.htable_size) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 59 | return NULL; |
| 60 | } |
Eric Dumazet | eb73316 | 2010-11-15 18:43:59 +0100 | [diff] [blame] | 61 | head = rcu_dereference( |
| 62 | hlist_nulls_first_rcu(&net->ct.hash[st->bucket])); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 63 | } |
| 64 | return head; |
| 65 | } |
| 66 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 67 | static struct hlist_nulls_node *ct_get_idx(struct seq_file *seq, loff_t pos) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 68 | { |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 69 | struct hlist_nulls_node *head = ct_get_first(seq); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 70 | |
| 71 | if (head) |
| 72 | while (pos && (head = ct_get_next(seq, head))) |
| 73 | pos--; |
| 74 | return pos ? NULL : head; |
| 75 | } |
| 76 | |
| 77 | static void *ct_seq_start(struct seq_file *seq, loff_t *pos) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 78 | __acquires(RCU) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 79 | { |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 80 | rcu_read_lock(); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 81 | return ct_get_idx(seq, *pos); |
| 82 | } |
| 83 | |
| 84 | static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos) |
| 85 | { |
| 86 | (*pos)++; |
| 87 | return ct_get_next(s, v); |
| 88 | } |
| 89 | |
| 90 | static void ct_seq_stop(struct seq_file *s, void *v) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 91 | __releases(RCU) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 92 | { |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 93 | rcu_read_unlock(); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 96 | #ifdef CONFIG_NF_CONNTRACK_SECMARK |
| 97 | static int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) |
| 98 | { |
| 99 | int ret; |
| 100 | u32 len; |
| 101 | char *secctx; |
| 102 | |
| 103 | ret = security_secid_to_secctx(ct->secmark, &secctx, &len); |
| 104 | if (ret) |
Pablo Neira Ayuso | cba85b5 | 2011-01-06 11:25:00 -0800 | [diff] [blame] | 105 | return 0; |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 106 | |
| 107 | ret = seq_printf(s, "secctx=%s ", secctx); |
| 108 | |
| 109 | security_release_secctx(secctx, len); |
| 110 | return ret; |
| 111 | } |
| 112 | #else |
| 113 | static inline int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) |
| 114 | { |
| 115 | return 0; |
| 116 | } |
| 117 | #endif |
| 118 | |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 119 | static int ct_seq_show(struct seq_file *s, void *v) |
| 120 | { |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 121 | struct nf_conntrack_tuple_hash *hash = v; |
| 122 | struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 123 | const struct nf_conntrack_l3proto *l3proto; |
| 124 | const struct nf_conntrack_l4proto *l4proto; |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 125 | int ret = 0; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 126 | |
| 127 | NF_CT_ASSERT(ct); |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 128 | if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use))) |
| 129 | return 0; |
| 130 | |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 131 | |
| 132 | /* we only want to print DIR_ORIGINAL */ |
| 133 | if (NF_CT_DIRECTION(hash)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 134 | goto release; |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 135 | if (nf_ct_l3num(ct) != AF_INET) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 136 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 137 | |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 138 | l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct)); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 139 | NF_CT_ASSERT(l3proto); |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 140 | l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct)); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 141 | NF_CT_ASSERT(l4proto); |
| 142 | |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 143 | ret = -ENOSPC; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 144 | if (seq_printf(s, "%-8s %u %ld ", |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 145 | l4proto->name, nf_ct_protonum(ct), |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 146 | timer_pending(&ct->timeout) |
| 147 | ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 148 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 149 | |
Patrick McHardy | c71e916 | 2008-01-14 23:49:37 -0800 | [diff] [blame] | 150 | if (l4proto->print_conntrack && l4proto->print_conntrack(s, ct)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 151 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 152 | |
| 153 | if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, |
| 154 | l3proto, l4proto)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 155 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 156 | |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 157 | if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 158 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 159 | |
| 160 | if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) |
| 161 | if (seq_printf(s, "[UNREPLIED] ")) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 162 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 163 | |
| 164 | if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, |
| 165 | l3proto, l4proto)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 166 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 167 | |
Krzysztof Piotr Oledzki | 5840157 | 2008-07-21 10:01:34 -0700 | [diff] [blame] | 168 | if (seq_print_acct(s, ct, IP_CT_DIR_REPLY)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 169 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 170 | |
| 171 | if (test_bit(IPS_ASSURED_BIT, &ct->status)) |
| 172 | if (seq_printf(s, "[ASSURED] ")) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 173 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 174 | |
| 175 | #ifdef CONFIG_NF_CONNTRACK_MARK |
| 176 | if (seq_printf(s, "mark=%u ", ct->mark)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 177 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 178 | #endif |
| 179 | |
Eric Paris | 1ae4de0 | 2010-10-13 16:25:00 -0400 | [diff] [blame] | 180 | if (ct_show_secctx(s, ct)) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 181 | goto release; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 182 | |
| 183 | if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use))) |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 184 | goto release; |
| 185 | ret = 0; |
| 186 | release: |
| 187 | nf_ct_put(ct); |
| 188 | return ret; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 191 | static const struct seq_operations ct_seq_ops = { |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 192 | .start = ct_seq_start, |
| 193 | .next = ct_seq_next, |
| 194 | .stop = ct_seq_stop, |
| 195 | .show = ct_seq_show |
| 196 | }; |
| 197 | |
| 198 | static int ct_open(struct inode *inode, struct file *file) |
| 199 | { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 200 | return seq_open_net(inode, file, &ct_seq_ops, |
| 201 | sizeof(struct ct_iter_state)); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 204 | static const struct file_operations ct_file_ops = { |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 205 | .owner = THIS_MODULE, |
| 206 | .open = ct_open, |
| 207 | .read = seq_read, |
| 208 | .llseek = seq_lseek, |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 209 | .release = seq_release_net, |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | /* expects */ |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 213 | struct ct_expect_iter_state { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 214 | struct seq_net_private p; |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 215 | unsigned int bucket; |
| 216 | }; |
| 217 | |
| 218 | static struct hlist_node *ct_expect_get_first(struct seq_file *seq) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 219 | { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 220 | struct net *net = seq_file_net(seq); |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 221 | struct ct_expect_iter_state *st = seq->private; |
Patrick McHardy | 7d0742d | 2008-01-31 04:38:19 -0800 | [diff] [blame] | 222 | struct hlist_node *n; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 223 | |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 224 | for (st->bucket = 0; st->bucket < nf_ct_expect_hsize; st->bucket++) { |
Eric Dumazet | eb73316 | 2010-11-15 18:43:59 +0100 | [diff] [blame] | 225 | n = rcu_dereference( |
| 226 | hlist_first_rcu(&net->ct.expect_hash[st->bucket])); |
Patrick McHardy | 7d0742d | 2008-01-31 04:38:19 -0800 | [diff] [blame] | 227 | if (n) |
| 228 | return n; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 229 | } |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 230 | return NULL; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 231 | } |
| 232 | |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 233 | static struct hlist_node *ct_expect_get_next(struct seq_file *seq, |
| 234 | struct hlist_node *head) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 235 | { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 236 | struct net *net = seq_file_net(seq); |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 237 | struct ct_expect_iter_state *st = seq->private; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 238 | |
Eric Dumazet | eb73316 | 2010-11-15 18:43:59 +0100 | [diff] [blame] | 239 | head = rcu_dereference(hlist_next_rcu(head)); |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 240 | while (head == NULL) { |
| 241 | if (++st->bucket >= nf_ct_expect_hsize) |
| 242 | return NULL; |
Eric Dumazet | eb73316 | 2010-11-15 18:43:59 +0100 | [diff] [blame] | 243 | head = rcu_dereference( |
| 244 | hlist_first_rcu(&net->ct.expect_hash[st->bucket])); |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 245 | } |
| 246 | return head; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 249 | static struct hlist_node *ct_expect_get_idx(struct seq_file *seq, loff_t pos) |
| 250 | { |
| 251 | struct hlist_node *head = ct_expect_get_first(seq); |
| 252 | |
| 253 | if (head) |
| 254 | while (pos && (head = ct_expect_get_next(seq, head))) |
| 255 | pos--; |
| 256 | return pos ? NULL : head; |
| 257 | } |
| 258 | |
| 259 | static void *exp_seq_start(struct seq_file *seq, loff_t *pos) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 260 | __acquires(RCU) |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 261 | { |
Patrick McHardy | 7d0742d | 2008-01-31 04:38:19 -0800 | [diff] [blame] | 262 | rcu_read_lock(); |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 263 | return ct_expect_get_idx(seq, *pos); |
| 264 | } |
| 265 | |
| 266 | static void *exp_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 267 | { |
| 268 | (*pos)++; |
| 269 | return ct_expect_get_next(seq, v); |
| 270 | } |
| 271 | |
| 272 | static void exp_seq_stop(struct seq_file *seq, void *v) |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 273 | __releases(RCU) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 274 | { |
Patrick McHardy | 7d0742d | 2008-01-31 04:38:19 -0800 | [diff] [blame] | 275 | rcu_read_unlock(); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | static int exp_seq_show(struct seq_file *s, void *v) |
| 279 | { |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 280 | struct nf_conntrack_expect *exp; |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 281 | const struct hlist_node *n = v; |
Patrick McHardy | 5d08ad4 | 2007-07-07 22:34:07 -0700 | [diff] [blame] | 282 | |
| 283 | exp = hlist_entry(n, struct nf_conntrack_expect, hnode); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 284 | |
| 285 | if (exp->tuple.src.l3num != AF_INET) |
| 286 | return 0; |
| 287 | |
| 288 | if (exp->timeout.function) |
| 289 | seq_printf(s, "%ld ", timer_pending(&exp->timeout) |
| 290 | ? (long)(exp->timeout.expires - jiffies)/HZ : 0); |
| 291 | else |
| 292 | seq_printf(s, "- "); |
| 293 | |
| 294 | seq_printf(s, "proto=%u ", exp->tuple.dst.protonum); |
| 295 | |
| 296 | print_tuple(s, &exp->tuple, |
| 297 | __nf_ct_l3proto_find(exp->tuple.src.l3num), |
| 298 | __nf_ct_l4proto_find(exp->tuple.src.l3num, |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 299 | exp->tuple.dst.protonum)); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 300 | return seq_putc(s, '\n'); |
| 301 | } |
| 302 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 303 | static const struct seq_operations exp_seq_ops = { |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 304 | .start = exp_seq_start, |
| 305 | .next = exp_seq_next, |
| 306 | .stop = exp_seq_stop, |
| 307 | .show = exp_seq_show |
| 308 | }; |
| 309 | |
| 310 | static int exp_open(struct inode *inode, struct file *file) |
| 311 | { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 312 | return seq_open_net(inode, file, &exp_seq_ops, |
| 313 | sizeof(struct ct_expect_iter_state)); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 314 | } |
| 315 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 316 | static const struct file_operations ip_exp_file_ops = { |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 317 | .owner = THIS_MODULE, |
| 318 | .open = exp_open, |
| 319 | .read = seq_read, |
| 320 | .llseek = seq_lseek, |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 321 | .release = seq_release_net, |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos) |
| 325 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 326 | struct net *net = seq_file_net(seq); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 327 | int cpu; |
| 328 | |
| 329 | if (*pos == 0) |
| 330 | return SEQ_START_TOKEN; |
| 331 | |
Rusty Russell | 0f23174a | 2008-12-29 12:23:42 +0000 | [diff] [blame] | 332 | for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) { |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 333 | if (!cpu_possible(cpu)) |
| 334 | continue; |
| 335 | *pos = cpu+1; |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 336 | return per_cpu_ptr(net->ct.stat, cpu); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | return NULL; |
| 340 | } |
| 341 | |
| 342 | static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 343 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 344 | struct net *net = seq_file_net(seq); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 345 | int cpu; |
| 346 | |
Rusty Russell | 0f23174a | 2008-12-29 12:23:42 +0000 | [diff] [blame] | 347 | for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) { |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 348 | if (!cpu_possible(cpu)) |
| 349 | continue; |
| 350 | *pos = cpu+1; |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 351 | return per_cpu_ptr(net->ct.stat, cpu); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | return NULL; |
| 355 | } |
| 356 | |
| 357 | static void ct_cpu_seq_stop(struct seq_file *seq, void *v) |
| 358 | { |
| 359 | } |
| 360 | |
| 361 | static int ct_cpu_seq_show(struct seq_file *seq, void *v) |
| 362 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 363 | struct net *net = seq_file_net(seq); |
| 364 | unsigned int nr_conntracks = atomic_read(&net->ct.count); |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 365 | const struct ip_conntrack_stat *st = v; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 366 | |
| 367 | if (v == SEQ_START_TOKEN) { |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 368 | seq_printf(seq, "entries searched found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error expect_new expect_create expect_delete search_restart\n"); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x " |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 373 | "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n", |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 374 | nr_conntracks, |
| 375 | st->searched, |
| 376 | st->found, |
| 377 | st->new, |
| 378 | st->invalid, |
| 379 | st->ignore, |
| 380 | st->delete, |
| 381 | st->delete_list, |
| 382 | st->insert, |
| 383 | st->insert_failed, |
| 384 | st->drop, |
| 385 | st->early_drop, |
| 386 | st->error, |
| 387 | |
| 388 | st->expect_new, |
| 389 | st->expect_create, |
Jesper Dangaard Brouer | af740b2 | 2010-04-23 12:34:56 +0200 | [diff] [blame] | 390 | st->expect_delete, |
| 391 | st->search_restart |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 392 | ); |
| 393 | return 0; |
| 394 | } |
| 395 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 396 | static const struct seq_operations ct_cpu_seq_ops = { |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 397 | .start = ct_cpu_seq_start, |
| 398 | .next = ct_cpu_seq_next, |
| 399 | .stop = ct_cpu_seq_stop, |
| 400 | .show = ct_cpu_seq_show, |
| 401 | }; |
| 402 | |
| 403 | static int ct_cpu_seq_open(struct inode *inode, struct file *file) |
| 404 | { |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 405 | return seq_open_net(inode, file, &ct_cpu_seq_ops, |
| 406 | sizeof(struct seq_net_private)); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 409 | static const struct file_operations ct_cpu_seq_fops = { |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 410 | .owner = THIS_MODULE, |
| 411 | .open = ct_cpu_seq_open, |
| 412 | .read = seq_read, |
| 413 | .llseek = seq_lseek, |
Alexey Dobriyan | 8e9df80 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 414 | .release = seq_release_net, |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 415 | }; |
| 416 | |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 417 | static int __net_init ip_conntrack_net_init(struct net *net) |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 418 | { |
| 419 | struct proc_dir_entry *proc, *proc_exp, *proc_stat; |
| 420 | |
Gao feng | d4beaa6 | 2013-02-18 01:34:54 +0000 | [diff] [blame] | 421 | proc = proc_create("ip_conntrack", 0440, net->proc_net, &ct_file_ops); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 422 | if (!proc) |
| 423 | goto err1; |
| 424 | |
Gao feng | d4beaa6 | 2013-02-18 01:34:54 +0000 | [diff] [blame] | 425 | proc_exp = proc_create("ip_conntrack_expect", 0440, net->proc_net, |
| 426 | &ip_exp_file_ops); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 427 | if (!proc_exp) |
| 428 | goto err2; |
| 429 | |
Denis V. Lunev | 8eeee8b | 2008-03-27 16:55:53 -0700 | [diff] [blame] | 430 | proc_stat = proc_create("ip_conntrack", S_IRUGO, |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 431 | net->proc_net_stat, &ct_cpu_seq_fops); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 432 | if (!proc_stat) |
| 433 | goto err3; |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 434 | return 0; |
| 435 | |
| 436 | err3: |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 437 | remove_proc_entry("ip_conntrack_expect", net->proc_net); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 438 | err2: |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 439 | remove_proc_entry("ip_conntrack", net->proc_net); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 440 | err1: |
| 441 | return -ENOMEM; |
| 442 | } |
| 443 | |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 444 | static void __net_exit ip_conntrack_net_exit(struct net *net) |
| 445 | { |
| 446 | remove_proc_entry("ip_conntrack", net->proc_net_stat); |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 447 | remove_proc_entry("ip_conntrack_expect", net->proc_net); |
| 448 | remove_proc_entry("ip_conntrack", net->proc_net); |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static struct pernet_operations ip_conntrack_net_ops = { |
| 452 | .init = ip_conntrack_net_init, |
| 453 | .exit = ip_conntrack_net_exit, |
| 454 | }; |
| 455 | |
| 456 | int __init nf_conntrack_ipv4_compat_init(void) |
| 457 | { |
| 458 | return register_pernet_subsys(&ip_conntrack_net_ops); |
| 459 | } |
| 460 | |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 461 | void __exit nf_conntrack_ipv4_compat_fini(void) |
| 462 | { |
Alexey Dobriyan | 5e6b299 | 2008-10-08 11:35:06 +0200 | [diff] [blame] | 463 | unregister_pernet_subsys(&ip_conntrack_net_ops); |
Patrick McHardy | e4bd8bc | 2006-11-29 02:35:22 +0100 | [diff] [blame] | 464 | } |