Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * ip_conntrack_proto_gre.c - Version 3.0 |
| 3 | * |
| 4 | * Connection tracking protocol helper module for GRE. |
| 5 | * |
| 6 | * GRE is a generic encapsulation protocol, which is generally not very |
| 7 | * suited for NAT, as it has no protocol-specific part as port numbers. |
| 8 | * |
| 9 | * It has an optional key field, which may help us distinguishing two |
| 10 | * connections between the same two hosts. |
| 11 | * |
| 12 | * GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784 |
| 13 | * |
| 14 | * PPTP is built on top of a modified version of GRE, and has a mandatory |
| 15 | * field called "CallID", which serves us for the same purpose as the key |
| 16 | * field in plain GRE. |
| 17 | * |
| 18 | * Documentation about PPTP can be found in RFC 2637 |
| 19 | * |
| 20 | * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org> |
| 21 | * |
| 22 | * Development of this code funded by Astaro AG (http://www.astaro.com/) |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/timer.h> |
| 29 | #include <linux/list.h> |
| 30 | #include <linux/seq_file.h> |
| 31 | #include <linux/in.h> |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 32 | #include <linux/netdevice.h> |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 33 | #include <linux/skbuff.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 35 | #include <net/dst.h> |
| 36 | #include <net/net_namespace.h> |
| 37 | #include <net/netns/generic.h> |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 38 | #include <net/netfilter/nf_conntrack_l4proto.h> |
| 39 | #include <net/netfilter/nf_conntrack_helper.h> |
| 40 | #include <net/netfilter/nf_conntrack_core.h> |
| 41 | #include <linux/netfilter/nf_conntrack_proto_gre.h> |
| 42 | #include <linux/netfilter/nf_conntrack_pptp.h> |
| 43 | |
| 44 | #define GRE_TIMEOUT (30 * HZ) |
| 45 | #define GRE_STREAM_TIMEOUT (180 * HZ) |
| 46 | |
Eric Dumazet | f99189b | 2009-11-17 10:42:49 +0000 | [diff] [blame] | 47 | static int proto_gre_net_id __read_mostly; |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 48 | struct netns_proto_gre { |
| 49 | rwlock_t keymap_lock; |
| 50 | struct list_head keymap_list; |
| 51 | }; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 52 | |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 53 | void nf_ct_gre_keymap_flush(struct net *net) |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 54 | { |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 55 | struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id); |
Alexey Dobriyan | 51807e9 | 2008-09-07 18:20:36 -0700 | [diff] [blame] | 56 | struct nf_ct_gre_keymap *km, *tmp; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 57 | |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 58 | write_lock_bh(&net_gre->keymap_lock); |
| 59 | list_for_each_entry_safe(km, tmp, &net_gre->keymap_list, list) { |
Alexey Dobriyan | 51807e9 | 2008-09-07 18:20:36 -0700 | [diff] [blame] | 60 | list_del(&km->list); |
| 61 | kfree(km); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 62 | } |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 63 | write_unlock_bh(&net_gre->keymap_lock); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 64 | } |
| 65 | EXPORT_SYMBOL(nf_ct_gre_keymap_flush); |
| 66 | |
| 67 | static inline int gre_key_cmpfn(const struct nf_ct_gre_keymap *km, |
| 68 | const struct nf_conntrack_tuple *t) |
| 69 | { |
| 70 | return km->tuple.src.l3num == t->src.l3num && |
| 71 | !memcmp(&km->tuple.src.u3, &t->src.u3, sizeof(t->src.u3)) && |
| 72 | !memcmp(&km->tuple.dst.u3, &t->dst.u3, sizeof(t->dst.u3)) && |
| 73 | km->tuple.dst.protonum == t->dst.protonum && |
| 74 | km->tuple.dst.u.all == t->dst.u.all; |
| 75 | } |
| 76 | |
| 77 | /* look up the source key for a given tuple */ |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 78 | static __be16 gre_keymap_lookup(struct net *net, struct nf_conntrack_tuple *t) |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 79 | { |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 80 | struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 81 | struct nf_ct_gre_keymap *km; |
| 82 | __be16 key = 0; |
| 83 | |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 84 | read_lock_bh(&net_gre->keymap_lock); |
| 85 | list_for_each_entry(km, &net_gre->keymap_list, list) { |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 86 | if (gre_key_cmpfn(km, t)) { |
| 87 | key = km->tuple.src.u.gre.key; |
| 88 | break; |
| 89 | } |
| 90 | } |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 91 | read_unlock_bh(&net_gre->keymap_lock); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 92 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 93 | pr_debug("lookup src key 0x%x for ", key); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 94 | nf_ct_dump_tuple(t); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 95 | |
| 96 | return key; |
| 97 | } |
| 98 | |
| 99 | /* add a single keymap entry, associate with specified master ct */ |
| 100 | int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir, |
| 101 | struct nf_conntrack_tuple *t) |
| 102 | { |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 103 | struct net *net = nf_ct_net(ct); |
| 104 | struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 105 | struct nf_conn_help *help = nfct_help(ct); |
| 106 | struct nf_ct_gre_keymap **kmp, *km; |
| 107 | |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 108 | kmp = &help->help.ct_pptp_info.keymap[dir]; |
| 109 | if (*kmp) { |
| 110 | /* check whether it's a retransmission */ |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 111 | read_lock_bh(&net_gre->keymap_lock); |
| 112 | list_for_each_entry(km, &net_gre->keymap_list, list) { |
Alexey Dobriyan | 887464a | 2008-09-07 18:20:08 -0700 | [diff] [blame] | 113 | if (gre_key_cmpfn(km, t) && km == *kmp) { |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 114 | read_unlock_bh(&net_gre->keymap_lock); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 115 | return 0; |
Alexey Dobriyan | 887464a | 2008-09-07 18:20:08 -0700 | [diff] [blame] | 116 | } |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 117 | } |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 118 | read_unlock_bh(&net_gre->keymap_lock); |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 119 | pr_debug("trying to override keymap_%s for ct %p\n", |
| 120 | dir == IP_CT_DIR_REPLY ? "reply" : "orig", ct); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 121 | return -EEXIST; |
| 122 | } |
| 123 | |
| 124 | km = kmalloc(sizeof(*km), GFP_ATOMIC); |
| 125 | if (!km) |
| 126 | return -ENOMEM; |
| 127 | memcpy(&km->tuple, t, sizeof(*t)); |
| 128 | *kmp = km; |
| 129 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 130 | pr_debug("adding new entry %p: ", km); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 131 | nf_ct_dump_tuple(&km->tuple); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 132 | |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 133 | write_lock_bh(&net_gre->keymap_lock); |
| 134 | list_add_tail(&km->list, &net_gre->keymap_list); |
| 135 | write_unlock_bh(&net_gre->keymap_lock); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_add); |
| 140 | |
| 141 | /* destroy the keymap entries associated with specified master ct */ |
| 142 | void nf_ct_gre_keymap_destroy(struct nf_conn *ct) |
| 143 | { |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 144 | struct net *net = nf_ct_net(ct); |
| 145 | struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 146 | struct nf_conn_help *help = nfct_help(ct); |
| 147 | enum ip_conntrack_dir dir; |
| 148 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 149 | pr_debug("entering for ct %p\n", ct); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 150 | |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 151 | write_lock_bh(&net_gre->keymap_lock); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 152 | for (dir = IP_CT_DIR_ORIGINAL; dir < IP_CT_DIR_MAX; dir++) { |
| 153 | if (help->help.ct_pptp_info.keymap[dir]) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 154 | pr_debug("removing %p from list\n", |
| 155 | help->help.ct_pptp_info.keymap[dir]); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 156 | list_del(&help->help.ct_pptp_info.keymap[dir]->list); |
| 157 | kfree(help->help.ct_pptp_info.keymap[dir]); |
| 158 | help->help.ct_pptp_info.keymap[dir] = NULL; |
| 159 | } |
| 160 | } |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 161 | write_unlock_bh(&net_gre->keymap_lock); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 162 | } |
| 163 | EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_destroy); |
| 164 | |
| 165 | /* PUBLIC CONNTRACK PROTO HELPER FUNCTIONS */ |
| 166 | |
| 167 | /* invert gre part of tuple */ |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 168 | static bool gre_invert_tuple(struct nf_conntrack_tuple *tuple, |
| 169 | const struct nf_conntrack_tuple *orig) |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 170 | { |
| 171 | tuple->dst.u.gre.key = orig->src.u.gre.key; |
| 172 | tuple->src.u.gre.key = orig->dst.u.gre.key; |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 173 | return true; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* gre hdr info to tuple */ |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 177 | static bool gre_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff, |
| 178 | struct nf_conntrack_tuple *tuple) |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 179 | { |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 180 | struct net *net = dev_net(skb->dev ? skb->dev : skb_dst(skb)->dev); |
Jan Engelhardt | dc35dc5 | 2008-01-31 04:52:46 -0800 | [diff] [blame] | 181 | const struct gre_hdr_pptp *pgrehdr; |
| 182 | struct gre_hdr_pptp _pgrehdr; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 183 | __be16 srckey; |
Jan Engelhardt | dc35dc5 | 2008-01-31 04:52:46 -0800 | [diff] [blame] | 184 | const struct gre_hdr *grehdr; |
| 185 | struct gre_hdr _grehdr; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 186 | |
| 187 | /* first only delinearize old RFC1701 GRE header */ |
| 188 | grehdr = skb_header_pointer(skb, dataoff, sizeof(_grehdr), &_grehdr); |
| 189 | if (!grehdr || grehdr->version != GRE_VERSION_PPTP) { |
| 190 | /* try to behave like "nf_conntrack_proto_generic" */ |
| 191 | tuple->src.u.all = 0; |
| 192 | tuple->dst.u.all = 0; |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 193 | return true; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* PPTP header is variable length, only need up to the call_id field */ |
| 197 | pgrehdr = skb_header_pointer(skb, dataoff, 8, &_pgrehdr); |
| 198 | if (!pgrehdr) |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 199 | return true; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 200 | |
| 201 | if (ntohs(grehdr->protocol) != GRE_PROTOCOL_PPTP) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 202 | pr_debug("GRE_VERSION_PPTP but unknown proto\n"); |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 203 | return false; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | tuple->dst.u.gre.key = pgrehdr->call_id; |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 207 | srckey = gre_keymap_lookup(net, tuple); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 208 | tuple->src.u.gre.key = srckey; |
| 209 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 210 | return true; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* print gre part of tuple */ |
| 214 | static int gre_print_tuple(struct seq_file *s, |
| 215 | const struct nf_conntrack_tuple *tuple) |
| 216 | { |
| 217 | return seq_printf(s, "srckey=0x%x dstkey=0x%x ", |
| 218 | ntohs(tuple->src.u.gre.key), |
| 219 | ntohs(tuple->dst.u.gre.key)); |
| 220 | } |
| 221 | |
| 222 | /* print private data for conntrack */ |
Patrick McHardy | 440f0d5 | 2009-06-10 14:32:47 +0200 | [diff] [blame] | 223 | static int gre_print_conntrack(struct seq_file *s, struct nf_conn *ct) |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 224 | { |
| 225 | return seq_printf(s, "timeout=%u, stream_timeout=%u ", |
| 226 | (ct->proto.gre.timeout / HZ), |
| 227 | (ct->proto.gre.stream_timeout / HZ)); |
| 228 | } |
| 229 | |
| 230 | /* Returns verdict for packet, and may modify conntrack */ |
| 231 | static int gre_packet(struct nf_conn *ct, |
| 232 | const struct sk_buff *skb, |
| 233 | unsigned int dataoff, |
| 234 | enum ip_conntrack_info ctinfo, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 235 | u_int8_t pf, |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 236 | unsigned int hooknum) |
| 237 | { |
| 238 | /* If we've seen traffic both ways, this is a GRE connection. |
| 239 | * Extend timeout. */ |
| 240 | if (ct->status & IPS_SEEN_REPLY) { |
| 241 | nf_ct_refresh_acct(ct, ctinfo, skb, |
| 242 | ct->proto.gre.stream_timeout); |
| 243 | /* Also, more likely to be important, and not a probe. */ |
| 244 | set_bit(IPS_ASSURED_BIT, &ct->status); |
Patrick McHardy | 858b3133 | 2010-02-03 13:48:53 +0100 | [diff] [blame] | 245 | nf_conntrack_event_cache(IPCT_ASSURED, ct); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 246 | } else |
| 247 | nf_ct_refresh_acct(ct, ctinfo, skb, |
| 248 | ct->proto.gre.timeout); |
| 249 | |
| 250 | return NF_ACCEPT; |
| 251 | } |
| 252 | |
| 253 | /* Called when a new connection for this protocol found. */ |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 254 | static bool gre_new(struct nf_conn *ct, const struct sk_buff *skb, |
| 255 | unsigned int dataoff) |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 256 | { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 257 | pr_debug(": "); |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 258 | nf_ct_dump_tuple(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 259 | |
| 260 | /* initialize to sane value. Ideally a conntrack helper |
| 261 | * (e.g. in case of pptp) is increasing them */ |
| 262 | ct->proto.gre.stream_timeout = GRE_STREAM_TIMEOUT; |
| 263 | ct->proto.gre.timeout = GRE_TIMEOUT; |
| 264 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 265 | return true; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* Called when a conntrack entry has already been removed from the hashes |
| 269 | * and is about to be deleted from memory */ |
| 270 | static void gre_destroy(struct nf_conn *ct) |
| 271 | { |
| 272 | struct nf_conn *master = ct->master; |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 273 | pr_debug(" entering\n"); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 274 | |
| 275 | if (!master) |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 276 | pr_debug("no master !?!\n"); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 277 | else |
| 278 | nf_ct_gre_keymap_destroy(master); |
| 279 | } |
| 280 | |
| 281 | /* protocol helper struct */ |
Patrick McHardy | 61075af | 2007-07-14 20:48:19 -0700 | [diff] [blame] | 282 | static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 __read_mostly = { |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 283 | .l3proto = AF_INET, |
| 284 | .l4proto = IPPROTO_GRE, |
| 285 | .name = "gre", |
| 286 | .pkt_to_tuple = gre_pkt_to_tuple, |
| 287 | .invert_tuple = gre_invert_tuple, |
| 288 | .print_tuple = gre_print_tuple, |
| 289 | .print_conntrack = gre_print_conntrack, |
| 290 | .packet = gre_packet, |
| 291 | .new = gre_new, |
| 292 | .destroy = gre_destroy, |
| 293 | .me = THIS_MODULE, |
Patrick McHardy | e281db5c | 2007-03-04 15:57:25 -0800 | [diff] [blame] | 294 | #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 295 | .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 296 | .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 297 | .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 298 | .nla_policy = nf_ct_port_nla_policy, |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 299 | #endif |
| 300 | }; |
| 301 | |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 302 | static int proto_gre_net_init(struct net *net) |
| 303 | { |
Eric W. Biederman | e8d0288 | 2009-11-29 15:46:08 +0000 | [diff] [blame] | 304 | struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id); |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 305 | |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 306 | rwlock_init(&net_gre->keymap_lock); |
| 307 | INIT_LIST_HEAD(&net_gre->keymap_list); |
| 308 | |
Eric W. Biederman | e8d0288 | 2009-11-29 15:46:08 +0000 | [diff] [blame] | 309 | return 0; |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static void proto_gre_net_exit(struct net *net) |
| 313 | { |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 314 | nf_ct_gre_keymap_flush(net); |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | static struct pernet_operations proto_gre_net_ops = { |
| 318 | .init = proto_gre_net_init, |
| 319 | .exit = proto_gre_net_exit, |
Eric W. Biederman | e8d0288 | 2009-11-29 15:46:08 +0000 | [diff] [blame] | 320 | .id = &proto_gre_net_id, |
| 321 | .size = sizeof(struct netns_proto_gre), |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 322 | }; |
| 323 | |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 324 | static int __init nf_ct_proto_gre_init(void) |
| 325 | { |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 326 | int rv; |
| 327 | |
| 328 | rv = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_gre4); |
| 329 | if (rv < 0) |
| 330 | return rv; |
Eric W. Biederman | e8d0288 | 2009-11-29 15:46:08 +0000 | [diff] [blame] | 331 | rv = register_pernet_subsys(&proto_gre_net_ops); |
Alexey Dobriyan | 3bb0d1c | 2008-10-08 11:35:10 +0200 | [diff] [blame] | 332 | if (rv < 0) |
| 333 | nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4); |
| 334 | return rv; |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Alexey Dobriyan | 56bc0f9 | 2008-11-20 10:01:37 +0100 | [diff] [blame] | 337 | static void __exit nf_ct_proto_gre_fini(void) |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 338 | { |
| 339 | nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4); |
Eric W. Biederman | e8d0288 | 2009-11-29 15:46:08 +0000 | [diff] [blame] | 340 | unregister_pernet_subsys(&proto_gre_net_ops); |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | module_init(nf_ct_proto_gre_init); |
| 344 | module_exit(nf_ct_proto_gre_fini); |
| 345 | |
| 346 | MODULE_LICENSE("GPL"); |