Commit | Line | Data |
---|---|---|
f09943fe PM |
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 | * | |
f229f6ce | 24 | * (C) 2006-2012 Patrick McHardy <kaber@trash.net> |
f09943fe PM |
25 | */ |
26 | ||
27 | #include <linux/module.h> | |
28 | #include <linux/types.h> | |
29 | #include <linux/timer.h> | |
30 | #include <linux/list.h> | |
31 | #include <linux/seq_file.h> | |
32 | #include <linux/in.h> | |
3bb0d1c0 | 33 | #include <linux/netdevice.h> |
f09943fe | 34 | #include <linux/skbuff.h> |
5a0e3ad6 | 35 | #include <linux/slab.h> |
3bb0d1c0 AD |
36 | #include <net/dst.h> |
37 | #include <net/net_namespace.h> | |
38 | #include <net/netns/generic.h> | |
f09943fe PM |
39 | #include <net/netfilter/nf_conntrack_l4proto.h> |
40 | #include <net/netfilter/nf_conntrack_helper.h> | |
41 | #include <net/netfilter/nf_conntrack_core.h> | |
c779e849 | 42 | #include <net/netfilter/nf_conntrack_timeout.h> |
f09943fe PM |
43 | #include <linux/netfilter/nf_conntrack_proto_gre.h> |
44 | #include <linux/netfilter/nf_conntrack_pptp.h> | |
45 | ||
b888341c PNA |
46 | enum grep_conntrack { |
47 | GRE_CT_UNREPLIED, | |
48 | GRE_CT_REPLIED, | |
49 | GRE_CT_MAX | |
50 | }; | |
51 | ||
2c9e8637 | 52 | static const unsigned int gre_timeouts[GRE_CT_MAX] = { |
b888341c PNA |
53 | [GRE_CT_UNREPLIED] = 30*HZ, |
54 | [GRE_CT_REPLIED] = 180*HZ, | |
55 | }; | |
f09943fe | 56 | |
c7d03a00 | 57 | static unsigned int proto_gre_net_id __read_mostly; |
3bb0d1c0 | 58 | struct netns_proto_gre { |
4f71d80f | 59 | struct nf_proto_net nf; |
3bb0d1c0 AD |
60 | rwlock_t keymap_lock; |
61 | struct list_head keymap_list; | |
4f71d80f | 62 | unsigned int gre_timeouts[GRE_CT_MAX]; |
3bb0d1c0 | 63 | }; |
f09943fe | 64 | |
4f71d80f G |
65 | static inline struct netns_proto_gre *gre_pernet(struct net *net) |
66 | { | |
67 | return net_generic(net, proto_gre_net_id); | |
68 | } | |
69 | ||
8142b227 | 70 | static void nf_ct_gre_keymap_flush(struct net *net) |
f09943fe | 71 | { |
4f71d80f | 72 | struct netns_proto_gre *net_gre = gre_pernet(net); |
51807e91 | 73 | struct nf_ct_gre_keymap *km, *tmp; |
f09943fe | 74 | |
3bb0d1c0 AD |
75 | write_lock_bh(&net_gre->keymap_lock); |
76 | list_for_each_entry_safe(km, tmp, &net_gre->keymap_list, list) { | |
51807e91 AD |
77 | list_del(&km->list); |
78 | kfree(km); | |
f09943fe | 79 | } |
3bb0d1c0 | 80 | write_unlock_bh(&net_gre->keymap_lock); |
f09943fe | 81 | } |
f09943fe PM |
82 | |
83 | static inline int gre_key_cmpfn(const struct nf_ct_gre_keymap *km, | |
84 | const struct nf_conntrack_tuple *t) | |
85 | { | |
86 | return km->tuple.src.l3num == t->src.l3num && | |
87 | !memcmp(&km->tuple.src.u3, &t->src.u3, sizeof(t->src.u3)) && | |
88 | !memcmp(&km->tuple.dst.u3, &t->dst.u3, sizeof(t->dst.u3)) && | |
89 | km->tuple.dst.protonum == t->dst.protonum && | |
90 | km->tuple.dst.u.all == t->dst.u.all; | |
91 | } | |
92 | ||
93 | /* look up the source key for a given tuple */ | |
3bb0d1c0 | 94 | static __be16 gre_keymap_lookup(struct net *net, struct nf_conntrack_tuple *t) |
f09943fe | 95 | { |
4f71d80f | 96 | struct netns_proto_gre *net_gre = gre_pernet(net); |
f09943fe PM |
97 | struct nf_ct_gre_keymap *km; |
98 | __be16 key = 0; | |
99 | ||
3bb0d1c0 AD |
100 | read_lock_bh(&net_gre->keymap_lock); |
101 | list_for_each_entry(km, &net_gre->keymap_list, list) { | |
f09943fe PM |
102 | if (gre_key_cmpfn(km, t)) { |
103 | key = km->tuple.src.u.gre.key; | |
104 | break; | |
105 | } | |
106 | } | |
3bb0d1c0 | 107 | read_unlock_bh(&net_gre->keymap_lock); |
f09943fe | 108 | |
0d53778e | 109 | pr_debug("lookup src key 0x%x for ", key); |
3c9fba65 | 110 | nf_ct_dump_tuple(t); |
f09943fe PM |
111 | |
112 | return key; | |
113 | } | |
114 | ||
115 | /* add a single keymap entry, associate with specified master ct */ | |
116 | int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir, | |
117 | struct nf_conntrack_tuple *t) | |
118 | { | |
3bb0d1c0 | 119 | struct net *net = nf_ct_net(ct); |
4f71d80f | 120 | struct netns_proto_gre *net_gre = gre_pernet(net); |
1afc5679 | 121 | struct nf_ct_pptp_master *ct_pptp_info = nfct_help_data(ct); |
f09943fe PM |
122 | struct nf_ct_gre_keymap **kmp, *km; |
123 | ||
1afc5679 | 124 | kmp = &ct_pptp_info->keymap[dir]; |
f09943fe PM |
125 | if (*kmp) { |
126 | /* check whether it's a retransmission */ | |
3bb0d1c0 AD |
127 | read_lock_bh(&net_gre->keymap_lock); |
128 | list_for_each_entry(km, &net_gre->keymap_list, list) { | |
887464a4 | 129 | if (gre_key_cmpfn(km, t) && km == *kmp) { |
3bb0d1c0 | 130 | read_unlock_bh(&net_gre->keymap_lock); |
f09943fe | 131 | return 0; |
887464a4 | 132 | } |
f09943fe | 133 | } |
3bb0d1c0 | 134 | read_unlock_bh(&net_gre->keymap_lock); |
0d53778e PM |
135 | pr_debug("trying to override keymap_%s for ct %p\n", |
136 | dir == IP_CT_DIR_REPLY ? "reply" : "orig", ct); | |
f09943fe PM |
137 | return -EEXIST; |
138 | } | |
139 | ||
140 | km = kmalloc(sizeof(*km), GFP_ATOMIC); | |
141 | if (!km) | |
142 | return -ENOMEM; | |
143 | memcpy(&km->tuple, t, sizeof(*t)); | |
144 | *kmp = km; | |
145 | ||
0d53778e | 146 | pr_debug("adding new entry %p: ", km); |
3c9fba65 | 147 | nf_ct_dump_tuple(&km->tuple); |
f09943fe | 148 | |
3bb0d1c0 AD |
149 | write_lock_bh(&net_gre->keymap_lock); |
150 | list_add_tail(&km->list, &net_gre->keymap_list); | |
151 | write_unlock_bh(&net_gre->keymap_lock); | |
f09943fe PM |
152 | |
153 | return 0; | |
154 | } | |
155 | EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_add); | |
156 | ||
157 | /* destroy the keymap entries associated with specified master ct */ | |
158 | void nf_ct_gre_keymap_destroy(struct nf_conn *ct) | |
159 | { | |
3bb0d1c0 | 160 | struct net *net = nf_ct_net(ct); |
4f71d80f | 161 | struct netns_proto_gre *net_gre = gre_pernet(net); |
1afc5679 | 162 | struct nf_ct_pptp_master *ct_pptp_info = nfct_help_data(ct); |
f09943fe PM |
163 | enum ip_conntrack_dir dir; |
164 | ||
0d53778e | 165 | pr_debug("entering for ct %p\n", ct); |
f09943fe | 166 | |
3bb0d1c0 | 167 | write_lock_bh(&net_gre->keymap_lock); |
f09943fe | 168 | for (dir = IP_CT_DIR_ORIGINAL; dir < IP_CT_DIR_MAX; dir++) { |
1afc5679 | 169 | if (ct_pptp_info->keymap[dir]) { |
0d53778e | 170 | pr_debug("removing %p from list\n", |
1afc5679 PNA |
171 | ct_pptp_info->keymap[dir]); |
172 | list_del(&ct_pptp_info->keymap[dir]->list); | |
173 | kfree(ct_pptp_info->keymap[dir]); | |
174 | ct_pptp_info->keymap[dir] = NULL; | |
f09943fe PM |
175 | } |
176 | } | |
3bb0d1c0 | 177 | write_unlock_bh(&net_gre->keymap_lock); |
f09943fe PM |
178 | } |
179 | EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_destroy); | |
180 | ||
181 | /* PUBLIC CONNTRACK PROTO HELPER FUNCTIONS */ | |
182 | ||
f09943fe | 183 | /* gre hdr info to tuple */ |
09f263cd | 184 | static bool gre_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff, |
a31f1adc | 185 | struct net *net, struct nf_conntrack_tuple *tuple) |
f09943fe | 186 | { |
c579a9e7 GF |
187 | const struct pptp_gre_header *pgrehdr; |
188 | struct pptp_gre_header _pgrehdr; | |
f09943fe | 189 | __be16 srckey; |
c579a9e7 GF |
190 | const struct gre_base_hdr *grehdr; |
191 | struct gre_base_hdr _grehdr; | |
f09943fe PM |
192 | |
193 | /* first only delinearize old RFC1701 GRE header */ | |
194 | grehdr = skb_header_pointer(skb, dataoff, sizeof(_grehdr), &_grehdr); | |
c579a9e7 | 195 | if (!grehdr || (grehdr->flags & GRE_VERSION) != GRE_VERSION_1) { |
f09943fe PM |
196 | /* try to behave like "nf_conntrack_proto_generic" */ |
197 | tuple->src.u.all = 0; | |
198 | tuple->dst.u.all = 0; | |
09f263cd | 199 | return true; |
f09943fe PM |
200 | } |
201 | ||
202 | /* PPTP header is variable length, only need up to the call_id field */ | |
203 | pgrehdr = skb_header_pointer(skb, dataoff, 8, &_pgrehdr); | |
204 | if (!pgrehdr) | |
09f263cd | 205 | return true; |
f09943fe | 206 | |
ecc6569f | 207 | if (grehdr->protocol != GRE_PROTO_PPP) { |
c579a9e7 | 208 | pr_debug("Unsupported GRE proto(0x%x)\n", ntohs(grehdr->protocol)); |
09f263cd | 209 | return false; |
f09943fe PM |
210 | } |
211 | ||
212 | tuple->dst.u.gre.key = pgrehdr->call_id; | |
3bb0d1c0 | 213 | srckey = gre_keymap_lookup(net, tuple); |
f09943fe PM |
214 | tuple->src.u.gre.key = srckey; |
215 | ||
09f263cd | 216 | return true; |
f09943fe PM |
217 | } |
218 | ||
ea48cc83 | 219 | #ifdef CONFIG_NF_CONNTRACK_PROCFS |
f09943fe | 220 | /* print private data for conntrack */ |
37246a58 | 221 | static void gre_print_conntrack(struct seq_file *s, struct nf_conn *ct) |
f09943fe | 222 | { |
37246a58 SRRH |
223 | seq_printf(s, "timeout=%u, stream_timeout=%u ", |
224 | (ct->proto.gre.timeout / HZ), | |
225 | (ct->proto.gre.stream_timeout / HZ)); | |
f09943fe | 226 | } |
ea48cc83 | 227 | #endif |
f09943fe | 228 | |
2c8503f5 PNA |
229 | static unsigned int *gre_get_timeouts(struct net *net) |
230 | { | |
4f71d80f | 231 | return gre_pernet(net)->gre_timeouts; |
2c8503f5 PNA |
232 | } |
233 | ||
f09943fe PM |
234 | /* Returns verdict for packet, and may modify conntrack */ |
235 | static int gre_packet(struct nf_conn *ct, | |
83d213fd | 236 | struct sk_buff *skb, |
f09943fe | 237 | unsigned int dataoff, |
93e66024 FW |
238 | enum ip_conntrack_info ctinfo, |
239 | const struct nf_hook_state *state) | |
f09943fe | 240 | { |
dd2934a9 FW |
241 | if (state->pf != NFPROTO_IPV4) |
242 | return -NF_ACCEPT; | |
243 | ||
9976fc6e FW |
244 | if (!nf_ct_is_confirmed(ct)) { |
245 | unsigned int *timeouts = nf_ct_timeout_lookup(ct); | |
246 | ||
247 | if (!timeouts) | |
248 | timeouts = gre_get_timeouts(nf_ct_net(ct)); | |
249 | ||
250 | /* initialize to sane value. Ideally a conntrack helper | |
251 | * (e.g. in case of pptp) is increasing them */ | |
252 | ct->proto.gre.stream_timeout = timeouts[GRE_CT_REPLIED]; | |
253 | ct->proto.gre.timeout = timeouts[GRE_CT_UNREPLIED]; | |
254 | } | |
255 | ||
f09943fe PM |
256 | /* If we've seen traffic both ways, this is a GRE connection. |
257 | * Extend timeout. */ | |
258 | if (ct->status & IPS_SEEN_REPLY) { | |
259 | nf_ct_refresh_acct(ct, ctinfo, skb, | |
260 | ct->proto.gre.stream_timeout); | |
261 | /* Also, more likely to be important, and not a probe. */ | |
98d9ae84 FW |
262 | if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status)) |
263 | nf_conntrack_event_cache(IPCT_ASSURED, ct); | |
f09943fe PM |
264 | } else |
265 | nf_ct_refresh_acct(ct, ctinfo, skb, | |
266 | ct->proto.gre.timeout); | |
267 | ||
268 | return NF_ACCEPT; | |
269 | } | |
270 | ||
f09943fe PM |
271 | /* Called when a conntrack entry has already been removed from the hashes |
272 | * and is about to be deleted from memory */ | |
273 | static void gre_destroy(struct nf_conn *ct) | |
274 | { | |
275 | struct nf_conn *master = ct->master; | |
0d53778e | 276 | pr_debug(" entering\n"); |
f09943fe PM |
277 | |
278 | if (!master) | |
0d53778e | 279 | pr_debug("no master !?!\n"); |
f09943fe PM |
280 | else |
281 | nf_ct_gre_keymap_destroy(master); | |
282 | } | |
283 | ||
a874752a | 284 | #ifdef CONFIG_NF_CONNTRACK_TIMEOUT |
50978462 PNA |
285 | |
286 | #include <linux/netfilter/nfnetlink.h> | |
287 | #include <linux/netfilter/nfnetlink_cttimeout.h> | |
288 | ||
8264deb8 G |
289 | static int gre_timeout_nlattr_to_obj(struct nlattr *tb[], |
290 | struct net *net, void *data) | |
50978462 PNA |
291 | { |
292 | unsigned int *timeouts = data; | |
8264deb8 | 293 | struct netns_proto_gre *net_gre = gre_pernet(net); |
50978462 | 294 | |
c779e849 FW |
295 | if (!timeouts) |
296 | timeouts = gre_get_timeouts(net); | |
50978462 | 297 | /* set default timeouts for GRE. */ |
8264deb8 G |
298 | timeouts[GRE_CT_UNREPLIED] = net_gre->gre_timeouts[GRE_CT_UNREPLIED]; |
299 | timeouts[GRE_CT_REPLIED] = net_gre->gre_timeouts[GRE_CT_REPLIED]; | |
50978462 PNA |
300 | |
301 | if (tb[CTA_TIMEOUT_GRE_UNREPLIED]) { | |
302 | timeouts[GRE_CT_UNREPLIED] = | |
303 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_GRE_UNREPLIED])) * HZ; | |
304 | } | |
305 | if (tb[CTA_TIMEOUT_GRE_REPLIED]) { | |
306 | timeouts[GRE_CT_REPLIED] = | |
307 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_GRE_REPLIED])) * HZ; | |
308 | } | |
309 | return 0; | |
310 | } | |
311 | ||
312 | static int | |
313 | gre_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) | |
314 | { | |
315 | const unsigned int *timeouts = data; | |
316 | ||
242ddfc0 DM |
317 | if (nla_put_be32(skb, CTA_TIMEOUT_GRE_UNREPLIED, |
318 | htonl(timeouts[GRE_CT_UNREPLIED] / HZ)) || | |
319 | nla_put_be32(skb, CTA_TIMEOUT_GRE_REPLIED, | |
320 | htonl(timeouts[GRE_CT_REPLIED] / HZ))) | |
321 | goto nla_put_failure; | |
50978462 PNA |
322 | return 0; |
323 | ||
324 | nla_put_failure: | |
325 | return -ENOSPC; | |
326 | } | |
327 | ||
328 | static const struct nla_policy | |
329 | gre_timeout_nla_policy[CTA_TIMEOUT_GRE_MAX+1] = { | |
330 | [CTA_TIMEOUT_GRE_UNREPLIED] = { .type = NLA_U32 }, | |
331 | [CTA_TIMEOUT_GRE_REPLIED] = { .type = NLA_U32 }, | |
332 | }; | |
a874752a | 333 | #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ |
50978462 | 334 | |
a0badcc6 YS |
335 | #ifdef CONFIG_SYSCTL |
336 | static struct ctl_table gre_sysctl_table[] = { | |
337 | { | |
338 | .procname = "nf_conntrack_gre_timeout", | |
339 | .maxlen = sizeof(unsigned int), | |
340 | .mode = 0644, | |
341 | .proc_handler = proc_dointvec_jiffies, | |
342 | }, | |
343 | { | |
344 | .procname = "nf_conntrack_gre_timeout_stream", | |
345 | .maxlen = sizeof(unsigned int), | |
346 | .mode = 0644, | |
347 | .proc_handler = proc_dointvec_jiffies, | |
348 | }, | |
349 | {} | |
350 | }; | |
351 | #endif | |
352 | ||
353 | static int gre_kmemdup_sysctl_table(struct net *net, struct nf_proto_net *nf, | |
354 | struct netns_proto_gre *net_gre) | |
355 | { | |
356 | #ifdef CONFIG_SYSCTL | |
357 | int i; | |
358 | ||
359 | if (nf->ctl_table) | |
360 | return 0; | |
361 | ||
362 | nf->ctl_table = kmemdup(gre_sysctl_table, | |
363 | sizeof(gre_sysctl_table), | |
364 | GFP_KERNEL); | |
365 | if (!nf->ctl_table) | |
366 | return -ENOMEM; | |
367 | ||
368 | for (i = 0; i < GRE_CT_MAX; i++) | |
369 | nf->ctl_table[i].data = &net_gre->gre_timeouts[i]; | |
370 | #endif | |
371 | return 0; | |
372 | } | |
373 | ||
ca2ca6e1 | 374 | static int gre_init_net(struct net *net) |
4f71d80f G |
375 | { |
376 | struct netns_proto_gre *net_gre = gre_pernet(net); | |
a0badcc6 | 377 | struct nf_proto_net *nf = &net_gre->nf; |
4f71d80f G |
378 | int i; |
379 | ||
380 | rwlock_init(&net_gre->keymap_lock); | |
381 | INIT_LIST_HEAD(&net_gre->keymap_list); | |
382 | for (i = 0; i < GRE_CT_MAX; i++) | |
383 | net_gre->gre_timeouts[i] = gre_timeouts[i]; | |
384 | ||
a0badcc6 | 385 | return gre_kmemdup_sysctl_table(net, nf, net_gre); |
4f71d80f G |
386 | } |
387 | ||
f09943fe | 388 | /* protocol helper struct */ |
9dae47ab | 389 | static const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 = { |
f09943fe | 390 | .l4proto = IPPROTO_GRE, |
f09943fe | 391 | .pkt_to_tuple = gre_pkt_to_tuple, |
ea48cc83 | 392 | #ifdef CONFIG_NF_CONNTRACK_PROCFS |
f09943fe | 393 | .print_conntrack = gre_print_conntrack, |
ea48cc83 | 394 | #endif |
f09943fe | 395 | .packet = gre_packet, |
f09943fe PM |
396 | .destroy = gre_destroy, |
397 | .me = THIS_MODULE, | |
c0cd1156 | 398 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
fdf70832 | 399 | .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, |
a400c30e | 400 | .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, |
fdf70832 | 401 | .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, |
f73e924c | 402 | .nla_policy = nf_ct_port_nla_policy, |
f09943fe | 403 | #endif |
a874752a | 404 | #ifdef CONFIG_NF_CONNTRACK_TIMEOUT |
50978462 PNA |
405 | .ctnl_timeout = { |
406 | .nlattr_to_obj = gre_timeout_nlattr_to_obj, | |
407 | .obj_to_nlattr = gre_timeout_obj_to_nlattr, | |
408 | .nlattr_max = CTA_TIMEOUT_GRE_MAX, | |
409 | .obj_size = sizeof(unsigned int) * GRE_CT_MAX, | |
410 | .nla_policy = gre_timeout_nla_policy, | |
411 | }, | |
a874752a | 412 | #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ |
4f71d80f G |
413 | .net_id = &proto_gre_net_id, |
414 | .init_net = gre_init_net, | |
f09943fe PM |
415 | }; |
416 | ||
3bb0d1c0 AD |
417 | static int proto_gre_net_init(struct net *net) |
418 | { | |
4f71d80f | 419 | int ret = 0; |
0e54d217 DC |
420 | |
421 | ret = nf_ct_l4proto_pernet_register_one(net, | |
422 | &nf_conntrack_l4proto_gre4); | |
4f71d80f | 423 | if (ret < 0) |
c296bb4d | 424 | pr_err("nf_conntrack_gre4: pernet registration failed.\n"); |
4f71d80f | 425 | return ret; |
3bb0d1c0 AD |
426 | } |
427 | ||
428 | static void proto_gre_net_exit(struct net *net) | |
429 | { | |
0e54d217 | 430 | nf_ct_l4proto_pernet_unregister_one(net, &nf_conntrack_l4proto_gre4); |
3bb0d1c0 | 431 | nf_ct_gre_keymap_flush(net); |
3bb0d1c0 AD |
432 | } |
433 | ||
434 | static struct pernet_operations proto_gre_net_ops = { | |
435 | .init = proto_gre_net_init, | |
436 | .exit = proto_gre_net_exit, | |
e8d02885 EB |
437 | .id = &proto_gre_net_id, |
438 | .size = sizeof(struct netns_proto_gre), | |
3bb0d1c0 AD |
439 | }; |
440 | ||
f09943fe PM |
441 | static int __init nf_ct_proto_gre_init(void) |
442 | { | |
c296bb4d G |
443 | int ret; |
444 | ||
c296bb4d G |
445 | ret = register_pernet_subsys(&proto_gre_net_ops); |
446 | if (ret < 0) | |
447 | goto out_pernet; | |
0e54d217 | 448 | ret = nf_ct_l4proto_register_one(&nf_conntrack_l4proto_gre4); |
0d98da5d G |
449 | if (ret < 0) |
450 | goto out_gre4; | |
451 | ||
c296bb4d | 452 | return 0; |
c296bb4d | 453 | out_gre4: |
0d98da5d G |
454 | unregister_pernet_subsys(&proto_gre_net_ops); |
455 | out_pernet: | |
c296bb4d | 456 | return ret; |
f09943fe PM |
457 | } |
458 | ||
56bc0f96 | 459 | static void __exit nf_ct_proto_gre_fini(void) |
f09943fe | 460 | { |
0e54d217 | 461 | nf_ct_l4proto_unregister_one(&nf_conntrack_l4proto_gre4); |
e8d02885 | 462 | unregister_pernet_subsys(&proto_gre_net_ops); |
f09943fe PM |
463 | } |
464 | ||
465 | module_init(nf_ct_proto_gre_init); | |
466 | module_exit(nf_ct_proto_gre_fini); | |
467 | ||
468 | MODULE_LICENSE("GPL"); |