blob: 9d692f5adb941b311ac0ab5eba76d9ec8f126e70 [file] [log] [blame]
Patrick McHardy59eecdf2007-07-14 20:48:44 -07001/* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
3 * (C) 2007 Patrick McHardy <kaber@trash.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/types.h>
11#include <linux/timer.h>
12#include <linux/module.h>
Patrick McHardy59eecdf2007-07-14 20:48:44 -070013#include <linux/udp.h>
14#include <linux/seq_file.h>
15#include <linux/skbuff.h>
16#include <linux/ipv6.h>
17#include <net/ip6_checksum.h>
18#include <net/checksum.h>
19
20#include <linux/netfilter.h>
21#include <linux/netfilter_ipv4.h>
22#include <linux/netfilter_ipv6.h>
23#include <net/netfilter/nf_conntrack_l4proto.h>
24#include <net/netfilter/nf_conntrack_ecache.h>
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080025#include <net/netfilter/nf_log.h>
Patrick McHardy59eecdf2007-07-14 20:48:44 -070026
Pablo Neira Ayuso5a41db92012-02-28 02:23:28 +010027enum udplite_conntrack {
28 UDPLITE_CT_UNREPLIED,
29 UDPLITE_CT_REPLIED,
30 UDPLITE_CT_MAX
31};
32
33static unsigned int udplite_timeouts[UDPLITE_CT_MAX] = {
34 [UDPLITE_CT_UNREPLIED] = 30*HZ,
35 [UDPLITE_CT_REPLIED] = 180*HZ,
36};
Patrick McHardy59eecdf2007-07-14 20:48:44 -070037
Gao fenga8021fe2012-05-28 21:04:19 +000038static int udplite_net_id __read_mostly;
39struct udplite_net {
40 struct nf_proto_net pn;
41 unsigned int timeouts[UDPLITE_CT_MAX];
42};
43
44static inline struct udplite_net *udplite_pernet(struct net *net)
45{
46 return net_generic(net, udplite_net_id);
47}
48
Jan Engelhardt09f263c2008-04-14 11:15:53 +020049static bool udplite_pkt_to_tuple(const struct sk_buff *skb,
50 unsigned int dataoff,
Eric W. Biedermana31f1ad2015-09-18 14:33:04 -050051 struct net *net,
Jan Engelhardt09f263c2008-04-14 11:15:53 +020052 struct nf_conntrack_tuple *tuple)
Patrick McHardy59eecdf2007-07-14 20:48:44 -070053{
Jan Engelhardtda3f13c2008-01-31 04:52:29 -080054 const struct udphdr *hp;
55 struct udphdr _hdr;
Patrick McHardy59eecdf2007-07-14 20:48:44 -070056
57 hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
58 if (hp == NULL)
Jan Engelhardt09f263c2008-04-14 11:15:53 +020059 return false;
Patrick McHardy59eecdf2007-07-14 20:48:44 -070060
61 tuple->src.u.udp.port = hp->source;
62 tuple->dst.u.udp.port = hp->dest;
Jan Engelhardt09f263c2008-04-14 11:15:53 +020063 return true;
Patrick McHardy59eecdf2007-07-14 20:48:44 -070064}
65
Jan Engelhardt09f263c2008-04-14 11:15:53 +020066static bool udplite_invert_tuple(struct nf_conntrack_tuple *tuple,
67 const struct nf_conntrack_tuple *orig)
Patrick McHardy59eecdf2007-07-14 20:48:44 -070068{
69 tuple->src.u.udp.port = orig->dst.u.udp.port;
70 tuple->dst.u.udp.port = orig->src.u.udp.port;
Jan Engelhardt09f263c2008-04-14 11:15:53 +020071 return true;
Patrick McHardy59eecdf2007-07-14 20:48:44 -070072}
73
74/* Print out the per-protocol part of the tuple. */
Joe Perches824f1fb2014-09-29 16:08:22 -070075static void udplite_print_tuple(struct seq_file *s,
76 const struct nf_conntrack_tuple *tuple)
Patrick McHardy59eecdf2007-07-14 20:48:44 -070077{
Joe Perches824f1fb2014-09-29 16:08:22 -070078 seq_printf(s, "sport=%hu dport=%hu ",
79 ntohs(tuple->src.u.udp.port),
80 ntohs(tuple->dst.u.udp.port));
Patrick McHardy59eecdf2007-07-14 20:48:44 -070081}
82
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010083static unsigned int *udplite_get_timeouts(struct net *net)
84{
Gao fenga8021fe2012-05-28 21:04:19 +000085 return udplite_pernet(net)->timeouts;
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010086}
87
Patrick McHardy59eecdf2007-07-14 20:48:44 -070088/* Returns verdict for packet, and may modify conntracktype */
Patrick McHardyc88130b2008-01-31 04:42:11 -080089static int udplite_packet(struct nf_conn *ct,
Patrick McHardy59eecdf2007-07-14 20:48:44 -070090 const struct sk_buff *skb,
91 unsigned int dataoff,
92 enum ip_conntrack_info ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +020093 u_int8_t pf,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010094 unsigned int hooknum,
95 unsigned int *timeouts)
Patrick McHardy59eecdf2007-07-14 20:48:44 -070096{
97 /* If we've seen traffic both ways, this is some kind of UDP
98 stream. Extend timeout. */
Patrick McHardyc88130b2008-01-31 04:42:11 -080099 if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
100 nf_ct_refresh_acct(ct, ctinfo, skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100101 timeouts[UDPLITE_CT_REPLIED]);
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700102 /* Also, more likely to be important, and not a probe */
Patrick McHardyc88130b2008-01-31 04:42:11 -0800103 if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status))
Patrick McHardy858b31332010-02-03 13:48:53 +0100104 nf_conntrack_event_cache(IPCT_ASSURED, ct);
Pablo Neira Ayuso5a41db92012-02-28 02:23:28 +0100105 } else {
106 nf_ct_refresh_acct(ct, ctinfo, skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100107 timeouts[UDPLITE_CT_UNREPLIED]);
Pablo Neira Ayuso5a41db92012-02-28 02:23:28 +0100108 }
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700109 return NF_ACCEPT;
110}
111
112/* Called when a new connection for this protocol found. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200113static bool udplite_new(struct nf_conn *ct, const struct sk_buff *skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100114 unsigned int dataoff, unsigned int *timeouts)
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700115{
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200116 return true;
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700117}
118
Patrick McHardy8fea97e2010-02-15 17:45:08 +0100119static int udplite_error(struct net *net, struct nf_conn *tmpl,
Alexey Dobriyan74c51a12008-10-08 11:35:05 +0200120 struct sk_buff *skb,
121 unsigned int dataoff,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700122 enum ip_conntrack_info *ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200123 u_int8_t pf,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700124 unsigned int hooknum)
125{
126 unsigned int udplen = skb->len - dataoff;
Jan Engelhardtda3f13c2008-01-31 04:52:29 -0800127 const struct udphdr *hdr;
128 struct udphdr _hdr;
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700129 unsigned int cscov;
130
131 /* Header is too small? */
132 hdr = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
133 if (hdr == NULL) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200134 if (LOG_INVALID(net, IPPROTO_UDPLITE))
Gao feng30e0c6a2013-03-24 23:50:40 +0000135 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700136 "nf_ct_udplite: short packet ");
137 return -NF_ACCEPT;
138 }
139
140 cscov = ntohs(hdr->len);
141 if (cscov == 0)
142 cscov = udplen;
143 else if (cscov < sizeof(*hdr) || cscov > udplen) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200144 if (LOG_INVALID(net, IPPROTO_UDPLITE))
Gao feng30e0c6a2013-03-24 23:50:40 +0000145 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700146 "nf_ct_udplite: invalid checksum coverage ");
147 return -NF_ACCEPT;
148 }
149
150 /* UDPLITE mandates checksums */
151 if (!hdr->check) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200152 if (LOG_INVALID(net, IPPROTO_UDPLITE))
Gao feng30e0c6a2013-03-24 23:50:40 +0000153 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700154 "nf_ct_udplite: checksum missing ");
155 return -NF_ACCEPT;
156 }
157
158 /* Checksum invalid? Ignore. */
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200159 if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
Patrick McHardyd63a6502008-03-20 15:15:53 +0100160 nf_checksum_partial(skb, hooknum, dataoff, cscov, IPPROTO_UDP,
161 pf)) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200162 if (LOG_INVALID(net, IPPROTO_UDPLITE))
Gao feng30e0c6a2013-03-24 23:50:40 +0000163 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
Patrick McHardyd63a6502008-03-20 15:15:53 +0100164 "nf_ct_udplite: bad UDPLite checksum ");
165 return -NF_ACCEPT;
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700166 }
167
168 return NF_ACCEPT;
169}
170
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100171#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
172
173#include <linux/netfilter/nfnetlink.h>
174#include <linux/netfilter/nfnetlink_cttimeout.h>
175
Gao feng8264deb2012-05-28 21:04:23 +0000176static int udplite_timeout_nlattr_to_obj(struct nlattr *tb[],
177 struct net *net, void *data)
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100178{
179 unsigned int *timeouts = data;
Gao feng8264deb2012-05-28 21:04:23 +0000180 struct udplite_net *un = udplite_pernet(net);
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100181
182 /* set default timeouts for UDPlite. */
Gao feng8264deb2012-05-28 21:04:23 +0000183 timeouts[UDPLITE_CT_UNREPLIED] = un->timeouts[UDPLITE_CT_UNREPLIED];
184 timeouts[UDPLITE_CT_REPLIED] = un->timeouts[UDPLITE_CT_REPLIED];
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100185
186 if (tb[CTA_TIMEOUT_UDPLITE_UNREPLIED]) {
187 timeouts[UDPLITE_CT_UNREPLIED] =
188 ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDPLITE_UNREPLIED])) * HZ;
189 }
190 if (tb[CTA_TIMEOUT_UDPLITE_REPLIED]) {
191 timeouts[UDPLITE_CT_REPLIED] =
192 ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDPLITE_REPLIED])) * HZ;
193 }
194 return 0;
195}
196
197static int
198udplite_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
199{
200 const unsigned int *timeouts = data;
201
David S. Miller3c60a172012-04-01 18:48:06 -0400202 if (nla_put_be32(skb, CTA_TIMEOUT_UDPLITE_UNREPLIED,
203 htonl(timeouts[UDPLITE_CT_UNREPLIED] / HZ)) ||
204 nla_put_be32(skb, CTA_TIMEOUT_UDPLITE_REPLIED,
205 htonl(timeouts[UDPLITE_CT_REPLIED] / HZ)))
206 goto nla_put_failure;
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100207 return 0;
208
209nla_put_failure:
210 return -ENOSPC;
211}
212
213static const struct nla_policy
214udplite_timeout_nla_policy[CTA_TIMEOUT_UDPLITE_MAX+1] = {
215 [CTA_TIMEOUT_UDPLITE_UNREPLIED] = { .type = NLA_U32 },
216 [CTA_TIMEOUT_UDPLITE_REPLIED] = { .type = NLA_U32 },
217};
218#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
219
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700220#ifdef CONFIG_SYSCTL
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700221static struct ctl_table udplite_sysctl_table[] = {
222 {
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700223 .procname = "nf_conntrack_udplite_timeout",
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700224 .maxlen = sizeof(unsigned int),
225 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800226 .proc_handler = proc_dointvec_jiffies,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700227 },
228 {
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700229 .procname = "nf_conntrack_udplite_timeout_stream",
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700230 .maxlen = sizeof(unsigned int),
231 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800232 .proc_handler = proc_dointvec_jiffies,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700233 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800234 { }
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700235};
236#endif /* CONFIG_SYSCTL */
237
Gao feng51b4c822012-06-21 04:36:45 +0000238static int udplite_kmemdup_sysctl_table(struct nf_proto_net *pn,
239 struct udplite_net *un)
240{
241#ifdef CONFIG_SYSCTL
242 if (pn->ctl_table)
243 return 0;
244
245 pn->ctl_table = kmemdup(udplite_sysctl_table,
246 sizeof(udplite_sysctl_table),
247 GFP_KERNEL);
248 if (!pn->ctl_table)
249 return -ENOMEM;
250
251 pn->ctl_table[0].data = &un->timeouts[UDPLITE_CT_UNREPLIED];
252 pn->ctl_table[1].data = &un->timeouts[UDPLITE_CT_REPLIED];
253#endif
254 return 0;
255}
256
Gao fengf1caad22012-06-21 04:36:39 +0000257static int udplite_init_net(struct net *net, u_int16_t proto)
Gao fenga8021fe2012-05-28 21:04:19 +0000258{
Gao fenga8021fe2012-05-28 21:04:19 +0000259 struct udplite_net *un = udplite_pernet(net);
Gao feng51b4c822012-06-21 04:36:45 +0000260 struct nf_proto_net *pn = &un->pn;
261
262 if (!pn->users) {
263 int i;
264
Gao fenga8021fe2012-05-28 21:04:19 +0000265 for (i = 0 ; i < UDPLITE_CT_MAX; i++)
266 un->timeouts[i] = udplite_timeouts[i];
Gao fenga8021fe2012-05-28 21:04:19 +0000267 }
Gao feng51b4c822012-06-21 04:36:45 +0000268
269 return udplite_kmemdup_sysctl_table(pn, un);
Gao fenga8021fe2012-05-28 21:04:19 +0000270}
271
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700272static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly =
273{
274 .l3proto = PF_INET,
275 .l4proto = IPPROTO_UDPLITE,
276 .name = "udplite",
Pablo Neira Ayuso71d8c472016-05-01 00:28:40 +0200277 .allow_clash = true,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700278 .pkt_to_tuple = udplite_pkt_to_tuple,
279 .invert_tuple = udplite_invert_tuple,
280 .print_tuple = udplite_print_tuple,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700281 .packet = udplite_packet,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100282 .get_timeouts = udplite_get_timeouts,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700283 .new = udplite_new,
284 .error = udplite_error,
Igor Maravićc0cd1152011-12-12 02:58:24 +0000285#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
Patrick McHardyfdf70832007-09-28 14:37:41 -0700286 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100287 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
Patrick McHardyfdf70832007-09-28 14:37:41 -0700288 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
Patrick McHardyf73e9242007-09-28 14:39:55 -0700289 .nla_policy = nf_ct_port_nla_policy,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700290#endif
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100291#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
292 .ctnl_timeout = {
293 .nlattr_to_obj = udplite_timeout_nlattr_to_obj,
294 .obj_to_nlattr = udplite_timeout_obj_to_nlattr,
295 .nlattr_max = CTA_TIMEOUT_UDPLITE_MAX,
296 .obj_size = sizeof(unsigned int) *
297 CTA_TIMEOUT_UDPLITE_MAX,
298 .nla_policy = udplite_timeout_nla_policy,
299 },
300#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
Gao fenga8021fe2012-05-28 21:04:19 +0000301 .net_id = &udplite_net_id,
302 .init_net = udplite_init_net,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700303};
304
305static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly =
306{
307 .l3proto = PF_INET6,
308 .l4proto = IPPROTO_UDPLITE,
309 .name = "udplite",
Pablo Neira Ayuso71d8c472016-05-01 00:28:40 +0200310 .allow_clash = true,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700311 .pkt_to_tuple = udplite_pkt_to_tuple,
312 .invert_tuple = udplite_invert_tuple,
313 .print_tuple = udplite_print_tuple,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700314 .packet = udplite_packet,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100315 .get_timeouts = udplite_get_timeouts,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700316 .new = udplite_new,
317 .error = udplite_error,
Igor Maravićc0cd1152011-12-12 02:58:24 +0000318#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
Patrick McHardyfdf70832007-09-28 14:37:41 -0700319 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
Patrick McHardy5ff48292009-04-24 15:37:44 +0200320 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
Patrick McHardyfdf70832007-09-28 14:37:41 -0700321 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
Patrick McHardyf73e9242007-09-28 14:39:55 -0700322 .nla_policy = nf_ct_port_nla_policy,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700323#endif
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100324#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
325 .ctnl_timeout = {
326 .nlattr_to_obj = udplite_timeout_nlattr_to_obj,
327 .obj_to_nlattr = udplite_timeout_obj_to_nlattr,
328 .nlattr_max = CTA_TIMEOUT_UDPLITE_MAX,
329 .obj_size = sizeof(unsigned int) *
330 CTA_TIMEOUT_UDPLITE_MAX,
331 .nla_policy = udplite_timeout_nla_policy,
332 },
333#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
Gao fenga8021fe2012-05-28 21:04:19 +0000334 .net_id = &udplite_net_id,
335 .init_net = udplite_init_net,
336};
337
338static int udplite_net_init(struct net *net)
339{
340 int ret = 0;
341
Gao fengc296bb42013-01-23 12:51:10 +0100342 ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udplite4);
Gao fenga8021fe2012-05-28 21:04:19 +0000343 if (ret < 0) {
Gao fengc296bb42013-01-23 12:51:10 +0100344 pr_err("nf_conntrack_udplite4: pernet registration failed.\n");
Gao fenga8021fe2012-05-28 21:04:19 +0000345 goto out;
346 }
Gao fengc296bb42013-01-23 12:51:10 +0100347 ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udplite6);
Gao fenga8021fe2012-05-28 21:04:19 +0000348 if (ret < 0) {
Gao fengc296bb42013-01-23 12:51:10 +0100349 pr_err("nf_conntrack_udplite6: pernet registration failed.\n");
Gao fenga8021fe2012-05-28 21:04:19 +0000350 goto cleanup_udplite4;
351 }
352 return 0;
353
354cleanup_udplite4:
Gao fengc296bb42013-01-23 12:51:10 +0100355 nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite4);
Gao fenga8021fe2012-05-28 21:04:19 +0000356out:
357 return ret;
358}
359
360static void udplite_net_exit(struct net *net)
361{
Gao fengc296bb42013-01-23 12:51:10 +0100362 nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite6);
363 nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite4);
Gao fenga8021fe2012-05-28 21:04:19 +0000364}
365
366static struct pernet_operations udplite_net_ops = {
367 .init = udplite_net_init,
368 .exit = udplite_net_exit,
369 .id = &udplite_net_id,
370 .size = sizeof(struct udplite_net),
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700371};
372
373static int __init nf_conntrack_proto_udplite_init(void)
374{
Gao fengc296bb42013-01-23 12:51:10 +0100375 int ret;
376
Gao feng0d98da52013-03-07 17:20:46 +0000377 ret = register_pernet_subsys(&udplite_net_ops);
378 if (ret < 0)
379 goto out_pernet;
380
Gao fengc296bb42013-01-23 12:51:10 +0100381 ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udplite4);
382 if (ret < 0)
383 goto out_udplite4;
384
385 ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udplite6);
386 if (ret < 0)
387 goto out_udplite6;
388
Gao fengc296bb42013-01-23 12:51:10 +0100389 return 0;
Gao fengc296bb42013-01-23 12:51:10 +0100390out_udplite6:
391 nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite4);
392out_udplite4:
Gao feng0d98da52013-03-07 17:20:46 +0000393 unregister_pernet_subsys(&udplite_net_ops);
394out_pernet:
Gao fengc296bb42013-01-23 12:51:10 +0100395 return ret;
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700396}
397
398static void __exit nf_conntrack_proto_udplite_exit(void)
399{
Gao fengc296bb42013-01-23 12:51:10 +0100400 nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite6);
401 nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite4);
Gao fenga8021fe2012-05-28 21:04:19 +0000402 unregister_pernet_subsys(&udplite_net_ops);
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700403}
404
405module_init(nf_conntrack_proto_udplite_init);
406module_exit(nf_conntrack_proto_udplite_exit);
407
408MODULE_LICENSE("GPL");