blob: 4bf6b4e4b7763197c5698db8993e5362c5ef0911 [file] [log] [blame]
Patrick McHardyf09943f2006-12-02 22:09:41 -08001/*
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 Dobriyan3bb0d1c2008-10-08 11:35:10 +020032#include <linux/netdevice.h>
Patrick McHardyf09943f2006-12-02 22:09:41 -080033#include <linux/skbuff.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020035#include <net/dst.h>
36#include <net/net_namespace.h>
37#include <net/netns/generic.h>
Patrick McHardyf09943f2006-12-02 22:09:41 -080038#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
Pablo Neira Ayusob8883412012-02-28 18:56:39 +010044enum grep_conntrack {
45 GRE_CT_UNREPLIED,
46 GRE_CT_REPLIED,
47 GRE_CT_MAX
48};
49
50static unsigned int gre_timeouts[GRE_CT_MAX] = {
51 [GRE_CT_UNREPLIED] = 30*HZ,
52 [GRE_CT_REPLIED] = 180*HZ,
53};
Patrick McHardyf09943f2006-12-02 22:09:41 -080054
Eric Dumazetf99189b2009-11-17 10:42:49 +000055static int proto_gre_net_id __read_mostly;
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020056struct netns_proto_gre {
57 rwlock_t keymap_lock;
58 struct list_head keymap_list;
59};
Patrick McHardyf09943f2006-12-02 22:09:41 -080060
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020061void nf_ct_gre_keymap_flush(struct net *net)
Patrick McHardyf09943f2006-12-02 22:09:41 -080062{
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020063 struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id);
Alexey Dobriyan51807e92008-09-07 18:20:36 -070064 struct nf_ct_gre_keymap *km, *tmp;
Patrick McHardyf09943f2006-12-02 22:09:41 -080065
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020066 write_lock_bh(&net_gre->keymap_lock);
67 list_for_each_entry_safe(km, tmp, &net_gre->keymap_list, list) {
Alexey Dobriyan51807e92008-09-07 18:20:36 -070068 list_del(&km->list);
69 kfree(km);
Patrick McHardyf09943f2006-12-02 22:09:41 -080070 }
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020071 write_unlock_bh(&net_gre->keymap_lock);
Patrick McHardyf09943f2006-12-02 22:09:41 -080072}
73EXPORT_SYMBOL(nf_ct_gre_keymap_flush);
74
75static inline int gre_key_cmpfn(const struct nf_ct_gre_keymap *km,
76 const struct nf_conntrack_tuple *t)
77{
78 return km->tuple.src.l3num == t->src.l3num &&
79 !memcmp(&km->tuple.src.u3, &t->src.u3, sizeof(t->src.u3)) &&
80 !memcmp(&km->tuple.dst.u3, &t->dst.u3, sizeof(t->dst.u3)) &&
81 km->tuple.dst.protonum == t->dst.protonum &&
82 km->tuple.dst.u.all == t->dst.u.all;
83}
84
85/* look up the source key for a given tuple */
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020086static __be16 gre_keymap_lookup(struct net *net, struct nf_conntrack_tuple *t)
Patrick McHardyf09943f2006-12-02 22:09:41 -080087{
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020088 struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id);
Patrick McHardyf09943f2006-12-02 22:09:41 -080089 struct nf_ct_gre_keymap *km;
90 __be16 key = 0;
91
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020092 read_lock_bh(&net_gre->keymap_lock);
93 list_for_each_entry(km, &net_gre->keymap_list, list) {
Patrick McHardyf09943f2006-12-02 22:09:41 -080094 if (gre_key_cmpfn(km, t)) {
95 key = km->tuple.src.u.gre.key;
96 break;
97 }
98 }
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +020099 read_unlock_bh(&net_gre->keymap_lock);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800100
Patrick McHardy0d537782007-07-07 22:39:38 -0700101 pr_debug("lookup src key 0x%x for ", key);
Jan Engelhardt3c9fba62008-04-14 11:15:54 +0200102 nf_ct_dump_tuple(t);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800103
104 return key;
105}
106
107/* add a single keymap entry, associate with specified master ct */
108int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir,
109 struct nf_conntrack_tuple *t)
110{
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200111 struct net *net = nf_ct_net(ct);
112 struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800113 struct nf_conn_help *help = nfct_help(ct);
114 struct nf_ct_gre_keymap **kmp, *km;
115
Patrick McHardyf09943f2006-12-02 22:09:41 -0800116 kmp = &help->help.ct_pptp_info.keymap[dir];
117 if (*kmp) {
118 /* check whether it's a retransmission */
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200119 read_lock_bh(&net_gre->keymap_lock);
120 list_for_each_entry(km, &net_gre->keymap_list, list) {
Alexey Dobriyan887464a2008-09-07 18:20:08 -0700121 if (gre_key_cmpfn(km, t) && km == *kmp) {
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200122 read_unlock_bh(&net_gre->keymap_lock);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800123 return 0;
Alexey Dobriyan887464a2008-09-07 18:20:08 -0700124 }
Patrick McHardyf09943f2006-12-02 22:09:41 -0800125 }
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200126 read_unlock_bh(&net_gre->keymap_lock);
Patrick McHardy0d537782007-07-07 22:39:38 -0700127 pr_debug("trying to override keymap_%s for ct %p\n",
128 dir == IP_CT_DIR_REPLY ? "reply" : "orig", ct);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800129 return -EEXIST;
130 }
131
132 km = kmalloc(sizeof(*km), GFP_ATOMIC);
133 if (!km)
134 return -ENOMEM;
135 memcpy(&km->tuple, t, sizeof(*t));
136 *kmp = km;
137
Patrick McHardy0d537782007-07-07 22:39:38 -0700138 pr_debug("adding new entry %p: ", km);
Jan Engelhardt3c9fba62008-04-14 11:15:54 +0200139 nf_ct_dump_tuple(&km->tuple);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800140
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200141 write_lock_bh(&net_gre->keymap_lock);
142 list_add_tail(&km->list, &net_gre->keymap_list);
143 write_unlock_bh(&net_gre->keymap_lock);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800144
145 return 0;
146}
147EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_add);
148
149/* destroy the keymap entries associated with specified master ct */
150void nf_ct_gre_keymap_destroy(struct nf_conn *ct)
151{
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200152 struct net *net = nf_ct_net(ct);
153 struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800154 struct nf_conn_help *help = nfct_help(ct);
155 enum ip_conntrack_dir dir;
156
Patrick McHardy0d537782007-07-07 22:39:38 -0700157 pr_debug("entering for ct %p\n", ct);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800158
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200159 write_lock_bh(&net_gre->keymap_lock);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800160 for (dir = IP_CT_DIR_ORIGINAL; dir < IP_CT_DIR_MAX; dir++) {
161 if (help->help.ct_pptp_info.keymap[dir]) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700162 pr_debug("removing %p from list\n",
163 help->help.ct_pptp_info.keymap[dir]);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800164 list_del(&help->help.ct_pptp_info.keymap[dir]->list);
165 kfree(help->help.ct_pptp_info.keymap[dir]);
166 help->help.ct_pptp_info.keymap[dir] = NULL;
167 }
168 }
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200169 write_unlock_bh(&net_gre->keymap_lock);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800170}
171EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_destroy);
172
173/* PUBLIC CONNTRACK PROTO HELPER FUNCTIONS */
174
175/* invert gre part of tuple */
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200176static bool gre_invert_tuple(struct nf_conntrack_tuple *tuple,
177 const struct nf_conntrack_tuple *orig)
Patrick McHardyf09943f2006-12-02 22:09:41 -0800178{
179 tuple->dst.u.gre.key = orig->src.u.gre.key;
180 tuple->src.u.gre.key = orig->dst.u.gre.key;
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200181 return true;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800182}
183
184/* gre hdr info to tuple */
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200185static bool gre_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
186 struct nf_conntrack_tuple *tuple)
Patrick McHardyf09943f2006-12-02 22:09:41 -0800187{
Eric Dumazetadf30902009-06-02 05:19:30 +0000188 struct net *net = dev_net(skb->dev ? skb->dev : skb_dst(skb)->dev);
Jan Engelhardtdc35dc52008-01-31 04:52:46 -0800189 const struct gre_hdr_pptp *pgrehdr;
190 struct gre_hdr_pptp _pgrehdr;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800191 __be16 srckey;
Jan Engelhardtdc35dc52008-01-31 04:52:46 -0800192 const struct gre_hdr *grehdr;
193 struct gre_hdr _grehdr;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800194
195 /* first only delinearize old RFC1701 GRE header */
196 grehdr = skb_header_pointer(skb, dataoff, sizeof(_grehdr), &_grehdr);
197 if (!grehdr || grehdr->version != GRE_VERSION_PPTP) {
198 /* try to behave like "nf_conntrack_proto_generic" */
199 tuple->src.u.all = 0;
200 tuple->dst.u.all = 0;
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200201 return true;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800202 }
203
204 /* PPTP header is variable length, only need up to the call_id field */
205 pgrehdr = skb_header_pointer(skb, dataoff, 8, &_pgrehdr);
206 if (!pgrehdr)
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200207 return true;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800208
209 if (ntohs(grehdr->protocol) != GRE_PROTOCOL_PPTP) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700210 pr_debug("GRE_VERSION_PPTP but unknown proto\n");
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200211 return false;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800212 }
213
214 tuple->dst.u.gre.key = pgrehdr->call_id;
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200215 srckey = gre_keymap_lookup(net, tuple);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800216 tuple->src.u.gre.key = srckey;
217
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200218 return true;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800219}
220
221/* print gre part of tuple */
222static int gre_print_tuple(struct seq_file *s,
223 const struct nf_conntrack_tuple *tuple)
224{
225 return seq_printf(s, "srckey=0x%x dstkey=0x%x ",
226 ntohs(tuple->src.u.gre.key),
227 ntohs(tuple->dst.u.gre.key));
228}
229
230/* print private data for conntrack */
Patrick McHardy440f0d52009-06-10 14:32:47 +0200231static int gre_print_conntrack(struct seq_file *s, struct nf_conn *ct)
Patrick McHardyf09943f2006-12-02 22:09:41 -0800232{
233 return seq_printf(s, "timeout=%u, stream_timeout=%u ",
234 (ct->proto.gre.timeout / HZ),
235 (ct->proto.gre.stream_timeout / HZ));
236}
237
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100238static unsigned int *gre_get_timeouts(struct net *net)
239{
240 return gre_timeouts;
241}
242
Patrick McHardyf09943f2006-12-02 22:09:41 -0800243/* Returns verdict for packet, and may modify conntrack */
244static int gre_packet(struct nf_conn *ct,
245 const struct sk_buff *skb,
246 unsigned int dataoff,
247 enum ip_conntrack_info ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200248 u_int8_t pf,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100249 unsigned int hooknum,
250 unsigned int *timeouts)
Patrick McHardyf09943f2006-12-02 22:09:41 -0800251{
252 /* If we've seen traffic both ways, this is a GRE connection.
253 * Extend timeout. */
254 if (ct->status & IPS_SEEN_REPLY) {
255 nf_ct_refresh_acct(ct, ctinfo, skb,
256 ct->proto.gre.stream_timeout);
257 /* Also, more likely to be important, and not a probe. */
Florian Westphal98d9ae82011-09-30 16:38:29 +0200258 if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status))
259 nf_conntrack_event_cache(IPCT_ASSURED, ct);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800260 } else
261 nf_ct_refresh_acct(ct, ctinfo, skb,
262 ct->proto.gre.timeout);
263
264 return NF_ACCEPT;
265}
266
267/* Called when a new connection for this protocol found. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200268static bool gre_new(struct nf_conn *ct, const struct sk_buff *skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100269 unsigned int dataoff, unsigned int *timeouts)
Patrick McHardyf09943f2006-12-02 22:09:41 -0800270{
Patrick McHardy0d537782007-07-07 22:39:38 -0700271 pr_debug(": ");
Jan Engelhardt3c9fba62008-04-14 11:15:54 +0200272 nf_ct_dump_tuple(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800273
274 /* initialize to sane value. Ideally a conntrack helper
275 * (e.g. in case of pptp) is increasing them */
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100276 ct->proto.gre.stream_timeout = timeouts[GRE_CT_REPLIED];
277 ct->proto.gre.timeout = timeouts[GRE_CT_UNREPLIED];
Patrick McHardyf09943f2006-12-02 22:09:41 -0800278
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200279 return true;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800280}
281
282/* Called when a conntrack entry has already been removed from the hashes
283 * and is about to be deleted from memory */
284static void gre_destroy(struct nf_conn *ct)
285{
286 struct nf_conn *master = ct->master;
Patrick McHardy0d537782007-07-07 22:39:38 -0700287 pr_debug(" entering\n");
Patrick McHardyf09943f2006-12-02 22:09:41 -0800288
289 if (!master)
Patrick McHardy0d537782007-07-07 22:39:38 -0700290 pr_debug("no master !?!\n");
Patrick McHardyf09943f2006-12-02 22:09:41 -0800291 else
292 nf_ct_gre_keymap_destroy(master);
293}
294
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100295#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
296
297#include <linux/netfilter/nfnetlink.h>
298#include <linux/netfilter/nfnetlink_cttimeout.h>
299
300static int gre_timeout_nlattr_to_obj(struct nlattr *tb[], void *data)
301{
302 unsigned int *timeouts = data;
303
304 /* set default timeouts for GRE. */
305 timeouts[GRE_CT_UNREPLIED] = gre_timeouts[GRE_CT_UNREPLIED];
306 timeouts[GRE_CT_REPLIED] = gre_timeouts[GRE_CT_REPLIED];
307
308 if (tb[CTA_TIMEOUT_GRE_UNREPLIED]) {
309 timeouts[GRE_CT_UNREPLIED] =
310 ntohl(nla_get_be32(tb[CTA_TIMEOUT_GRE_UNREPLIED])) * HZ;
311 }
312 if (tb[CTA_TIMEOUT_GRE_REPLIED]) {
313 timeouts[GRE_CT_REPLIED] =
314 ntohl(nla_get_be32(tb[CTA_TIMEOUT_GRE_REPLIED])) * HZ;
315 }
316 return 0;
317}
318
319static int
320gre_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
321{
322 const unsigned int *timeouts = data;
323
David S. Miller242ddfc2012-04-01 18:52:03 -0400324 if (nla_put_be32(skb, CTA_TIMEOUT_GRE_UNREPLIED,
325 htonl(timeouts[GRE_CT_UNREPLIED] / HZ)) ||
326 nla_put_be32(skb, CTA_TIMEOUT_GRE_REPLIED,
327 htonl(timeouts[GRE_CT_REPLIED] / HZ)))
328 goto nla_put_failure;
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100329 return 0;
330
331nla_put_failure:
332 return -ENOSPC;
333}
334
335static const struct nla_policy
336gre_timeout_nla_policy[CTA_TIMEOUT_GRE_MAX+1] = {
337 [CTA_TIMEOUT_GRE_UNREPLIED] = { .type = NLA_U32 },
338 [CTA_TIMEOUT_GRE_REPLIED] = { .type = NLA_U32 },
339};
340#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
341
Patrick McHardyf09943f2006-12-02 22:09:41 -0800342/* protocol helper struct */
Patrick McHardy61075af2007-07-14 20:48:19 -0700343static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 __read_mostly = {
Patrick McHardyf09943f2006-12-02 22:09:41 -0800344 .l3proto = AF_INET,
345 .l4proto = IPPROTO_GRE,
346 .name = "gre",
347 .pkt_to_tuple = gre_pkt_to_tuple,
348 .invert_tuple = gre_invert_tuple,
349 .print_tuple = gre_print_tuple,
350 .print_conntrack = gre_print_conntrack,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100351 .get_timeouts = gre_get_timeouts,
Patrick McHardyf09943f2006-12-02 22:09:41 -0800352 .packet = gre_packet,
353 .new = gre_new,
354 .destroy = gre_destroy,
355 .me = THIS_MODULE,
Igor Maravićc0cd1152011-12-12 02:58:24 +0000356#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
Patrick McHardyfdf70832007-09-28 14:37:41 -0700357 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100358 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
Patrick McHardyfdf70832007-09-28 14:37:41 -0700359 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
Patrick McHardyf73e9242007-09-28 14:39:55 -0700360 .nla_policy = nf_ct_port_nla_policy,
Patrick McHardyf09943f2006-12-02 22:09:41 -0800361#endif
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100362#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
363 .ctnl_timeout = {
364 .nlattr_to_obj = gre_timeout_nlattr_to_obj,
365 .obj_to_nlattr = gre_timeout_obj_to_nlattr,
366 .nlattr_max = CTA_TIMEOUT_GRE_MAX,
367 .obj_size = sizeof(unsigned int) * GRE_CT_MAX,
368 .nla_policy = gre_timeout_nla_policy,
369 },
370#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
Patrick McHardyf09943f2006-12-02 22:09:41 -0800371};
372
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200373static int proto_gre_net_init(struct net *net)
374{
Eric W. Biedermane8d02882009-11-29 15:46:08 +0000375 struct netns_proto_gre *net_gre = net_generic(net, proto_gre_net_id);
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200376
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200377 rwlock_init(&net_gre->keymap_lock);
378 INIT_LIST_HEAD(&net_gre->keymap_list);
379
Eric W. Biedermane8d02882009-11-29 15:46:08 +0000380 return 0;
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200381}
382
383static void proto_gre_net_exit(struct net *net)
384{
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200385 nf_ct_gre_keymap_flush(net);
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200386}
387
388static struct pernet_operations proto_gre_net_ops = {
389 .init = proto_gre_net_init,
390 .exit = proto_gre_net_exit,
Eric W. Biedermane8d02882009-11-29 15:46:08 +0000391 .id = &proto_gre_net_id,
392 .size = sizeof(struct netns_proto_gre),
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200393};
394
Patrick McHardyf09943f2006-12-02 22:09:41 -0800395static int __init nf_ct_proto_gre_init(void)
396{
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200397 int rv;
398
399 rv = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_gre4);
400 if (rv < 0)
401 return rv;
Eric W. Biedermane8d02882009-11-29 15:46:08 +0000402 rv = register_pernet_subsys(&proto_gre_net_ops);
Alexey Dobriyan3bb0d1c2008-10-08 11:35:10 +0200403 if (rv < 0)
404 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4);
405 return rv;
Patrick McHardyf09943f2006-12-02 22:09:41 -0800406}
407
Alexey Dobriyan56bc0f92008-11-20 10:01:37 +0100408static void __exit nf_ct_proto_gre_fini(void)
Patrick McHardyf09943f2006-12-02 22:09:41 -0800409{
410 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_gre4);
Eric W. Biedermane8d02882009-11-29 15:46:08 +0000411 unregister_pernet_subsys(&proto_gre_net_ops);
Patrick McHardyf09943f2006-12-02 22:09:41 -0800412}
413
414module_init(nf_ct_proto_gre_init);
415module_exit(nf_ct_proto_gre_fini);
416
417MODULE_LICENSE("GPL");