blob: 029206e8dec4958f7651279d81e27833b584cdd0 [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
Gao Fenge5e693a2016-07-23 19:21:47 +080057 /* Actually only need first 4 bytes to get ports. */
58 hp = skb_header_pointer(skb, dataoff, 4, &_hdr);
Patrick McHardy59eecdf2007-07-14 20:48:44 -070059 if (hp == NULL)
Jan Engelhardt09f263c2008-04-14 11:15:53 +020060 return false;
Patrick McHardy59eecdf2007-07-14 20:48:44 -070061
62 tuple->src.u.udp.port = hp->source;
63 tuple->dst.u.udp.port = hp->dest;
Jan Engelhardt09f263c2008-04-14 11:15:53 +020064 return true;
Patrick McHardy59eecdf2007-07-14 20:48:44 -070065}
66
Jan Engelhardt09f263c2008-04-14 11:15:53 +020067static bool udplite_invert_tuple(struct nf_conntrack_tuple *tuple,
68 const struct nf_conntrack_tuple *orig)
Patrick McHardy59eecdf2007-07-14 20:48:44 -070069{
70 tuple->src.u.udp.port = orig->dst.u.udp.port;
71 tuple->dst.u.udp.port = orig->src.u.udp.port;
Jan Engelhardt09f263c2008-04-14 11:15:53 +020072 return true;
Patrick McHardy59eecdf2007-07-14 20:48:44 -070073}
74
75/* Print out the per-protocol part of the tuple. */
Joe Perches824f1fb2014-09-29 16:08:22 -070076static void udplite_print_tuple(struct seq_file *s,
77 const struct nf_conntrack_tuple *tuple)
Patrick McHardy59eecdf2007-07-14 20:48:44 -070078{
Joe Perches824f1fb2014-09-29 16:08:22 -070079 seq_printf(s, "sport=%hu dport=%hu ",
80 ntohs(tuple->src.u.udp.port),
81 ntohs(tuple->dst.u.udp.port));
Patrick McHardy59eecdf2007-07-14 20:48:44 -070082}
83
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010084static unsigned int *udplite_get_timeouts(struct net *net)
85{
Gao fenga8021fe2012-05-28 21:04:19 +000086 return udplite_pernet(net)->timeouts;
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010087}
88
Patrick McHardy59eecdf2007-07-14 20:48:44 -070089/* Returns verdict for packet, and may modify conntracktype */
Patrick McHardyc88130b2008-01-31 04:42:11 -080090static int udplite_packet(struct nf_conn *ct,
Patrick McHardy59eecdf2007-07-14 20:48:44 -070091 const struct sk_buff *skb,
92 unsigned int dataoff,
93 enum ip_conntrack_info ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +020094 u_int8_t pf,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010095 unsigned int hooknum,
96 unsigned int *timeouts)
Patrick McHardy59eecdf2007-07-14 20:48:44 -070097{
98 /* If we've seen traffic both ways, this is some kind of UDP
99 stream. Extend timeout. */
Patrick McHardyc88130b2008-01-31 04:42:11 -0800100 if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
101 nf_ct_refresh_acct(ct, ctinfo, skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100102 timeouts[UDPLITE_CT_REPLIED]);
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700103 /* Also, more likely to be important, and not a probe */
Patrick McHardyc88130b2008-01-31 04:42:11 -0800104 if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status))
Patrick McHardy858b31332010-02-03 13:48:53 +0100105 nf_conntrack_event_cache(IPCT_ASSURED, ct);
Pablo Neira Ayuso5a41db92012-02-28 02:23:28 +0100106 } else {
107 nf_ct_refresh_acct(ct, ctinfo, skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100108 timeouts[UDPLITE_CT_UNREPLIED]);
Pablo Neira Ayuso5a41db92012-02-28 02:23:28 +0100109 }
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700110 return NF_ACCEPT;
111}
112
113/* Called when a new connection for this protocol found. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200114static bool udplite_new(struct nf_conn *ct, const struct sk_buff *skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100115 unsigned int dataoff, unsigned int *timeouts)
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700116{
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200117 return true;
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700118}
119
Patrick McHardy8fea97e2010-02-15 17:45:08 +0100120static int udplite_error(struct net *net, struct nf_conn *tmpl,
Alexey Dobriyan74c51a12008-10-08 11:35:05 +0200121 struct sk_buff *skb,
122 unsigned int dataoff,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700123 enum ip_conntrack_info *ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200124 u_int8_t pf,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700125 unsigned int hooknum)
126{
127 unsigned int udplen = skb->len - dataoff;
Jan Engelhardtda3f13c2008-01-31 04:52:29 -0800128 const struct udphdr *hdr;
129 struct udphdr _hdr;
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700130 unsigned int cscov;
131
132 /* Header is too small? */
133 hdr = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
134 if (hdr == NULL) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200135 if (LOG_INVALID(net, IPPROTO_UDPLITE))
Gao feng30e0c6a2013-03-24 23:50:40 +0000136 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700137 "nf_ct_udplite: short packet ");
138 return -NF_ACCEPT;
139 }
140
141 cscov = ntohs(hdr->len);
142 if (cscov == 0)
143 cscov = udplen;
144 else if (cscov < sizeof(*hdr) || cscov > udplen) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200145 if (LOG_INVALID(net, IPPROTO_UDPLITE))
Gao feng30e0c6a2013-03-24 23:50:40 +0000146 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700147 "nf_ct_udplite: invalid checksum coverage ");
148 return -NF_ACCEPT;
149 }
150
151 /* UDPLITE mandates checksums */
152 if (!hdr->check) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200153 if (LOG_INVALID(net, IPPROTO_UDPLITE))
Gao feng30e0c6a2013-03-24 23:50:40 +0000154 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700155 "nf_ct_udplite: checksum missing ");
156 return -NF_ACCEPT;
157 }
158
159 /* Checksum invalid? Ignore. */
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200160 if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
Patrick McHardyd63a6502008-03-20 15:15:53 +0100161 nf_checksum_partial(skb, hooknum, dataoff, cscov, IPPROTO_UDP,
162 pf)) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200163 if (LOG_INVALID(net, IPPROTO_UDPLITE))
Gao feng30e0c6a2013-03-24 23:50:40 +0000164 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
Patrick McHardyd63a6502008-03-20 15:15:53 +0100165 "nf_ct_udplite: bad UDPLite checksum ");
166 return -NF_ACCEPT;
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700167 }
168
169 return NF_ACCEPT;
170}
171
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100172#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
173
174#include <linux/netfilter/nfnetlink.h>
175#include <linux/netfilter/nfnetlink_cttimeout.h>
176
Gao feng8264deb2012-05-28 21:04:23 +0000177static int udplite_timeout_nlattr_to_obj(struct nlattr *tb[],
178 struct net *net, void *data)
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100179{
180 unsigned int *timeouts = data;
Gao feng8264deb2012-05-28 21:04:23 +0000181 struct udplite_net *un = udplite_pernet(net);
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100182
183 /* set default timeouts for UDPlite. */
Gao feng8264deb2012-05-28 21:04:23 +0000184 timeouts[UDPLITE_CT_UNREPLIED] = un->timeouts[UDPLITE_CT_UNREPLIED];
185 timeouts[UDPLITE_CT_REPLIED] = un->timeouts[UDPLITE_CT_REPLIED];
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100186
187 if (tb[CTA_TIMEOUT_UDPLITE_UNREPLIED]) {
188 timeouts[UDPLITE_CT_UNREPLIED] =
189 ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDPLITE_UNREPLIED])) * HZ;
190 }
191 if (tb[CTA_TIMEOUT_UDPLITE_REPLIED]) {
192 timeouts[UDPLITE_CT_REPLIED] =
193 ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDPLITE_REPLIED])) * HZ;
194 }
195 return 0;
196}
197
198static int
199udplite_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
200{
201 const unsigned int *timeouts = data;
202
David S. Miller3c60a172012-04-01 18:48:06 -0400203 if (nla_put_be32(skb, CTA_TIMEOUT_UDPLITE_UNREPLIED,
204 htonl(timeouts[UDPLITE_CT_UNREPLIED] / HZ)) ||
205 nla_put_be32(skb, CTA_TIMEOUT_UDPLITE_REPLIED,
206 htonl(timeouts[UDPLITE_CT_REPLIED] / HZ)))
207 goto nla_put_failure;
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100208 return 0;
209
210nla_put_failure:
211 return -ENOSPC;
212}
213
214static const struct nla_policy
215udplite_timeout_nla_policy[CTA_TIMEOUT_UDPLITE_MAX+1] = {
216 [CTA_TIMEOUT_UDPLITE_UNREPLIED] = { .type = NLA_U32 },
217 [CTA_TIMEOUT_UDPLITE_REPLIED] = { .type = NLA_U32 },
218};
219#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
220
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700221#ifdef CONFIG_SYSCTL
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700222static struct ctl_table udplite_sysctl_table[] = {
223 {
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700224 .procname = "nf_conntrack_udplite_timeout",
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700225 .maxlen = sizeof(unsigned int),
226 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800227 .proc_handler = proc_dointvec_jiffies,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700228 },
229 {
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700230 .procname = "nf_conntrack_udplite_timeout_stream",
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700231 .maxlen = sizeof(unsigned int),
232 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800233 .proc_handler = proc_dointvec_jiffies,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700234 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800235 { }
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700236};
237#endif /* CONFIG_SYSCTL */
238
Gao feng51b4c822012-06-21 04:36:45 +0000239static int udplite_kmemdup_sysctl_table(struct nf_proto_net *pn,
240 struct udplite_net *un)
241{
242#ifdef CONFIG_SYSCTL
243 if (pn->ctl_table)
244 return 0;
245
246 pn->ctl_table = kmemdup(udplite_sysctl_table,
247 sizeof(udplite_sysctl_table),
248 GFP_KERNEL);
249 if (!pn->ctl_table)
250 return -ENOMEM;
251
252 pn->ctl_table[0].data = &un->timeouts[UDPLITE_CT_UNREPLIED];
253 pn->ctl_table[1].data = &un->timeouts[UDPLITE_CT_REPLIED];
254#endif
255 return 0;
256}
257
Gao fengf1caad22012-06-21 04:36:39 +0000258static int udplite_init_net(struct net *net, u_int16_t proto)
Gao fenga8021fe2012-05-28 21:04:19 +0000259{
Gao fenga8021fe2012-05-28 21:04:19 +0000260 struct udplite_net *un = udplite_pernet(net);
Gao feng51b4c822012-06-21 04:36:45 +0000261 struct nf_proto_net *pn = &un->pn;
262
263 if (!pn->users) {
264 int i;
265
Gao fenga8021fe2012-05-28 21:04:19 +0000266 for (i = 0 ; i < UDPLITE_CT_MAX; i++)
267 un->timeouts[i] = udplite_timeouts[i];
Gao fenga8021fe2012-05-28 21:04:19 +0000268 }
Gao feng51b4c822012-06-21 04:36:45 +0000269
270 return udplite_kmemdup_sysctl_table(pn, un);
Gao fenga8021fe2012-05-28 21:04:19 +0000271}
272
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700273static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly =
274{
275 .l3proto = PF_INET,
276 .l4proto = IPPROTO_UDPLITE,
277 .name = "udplite",
Pablo Neira Ayuso71d8c472016-05-01 00:28:40 +0200278 .allow_clash = true,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700279 .pkt_to_tuple = udplite_pkt_to_tuple,
280 .invert_tuple = udplite_invert_tuple,
281 .print_tuple = udplite_print_tuple,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700282 .packet = udplite_packet,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100283 .get_timeouts = udplite_get_timeouts,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700284 .new = udplite_new,
285 .error = udplite_error,
Igor Maravićc0cd1152011-12-12 02:58:24 +0000286#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
Patrick McHardyfdf70832007-09-28 14:37:41 -0700287 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100288 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
Patrick McHardyfdf70832007-09-28 14:37:41 -0700289 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
Patrick McHardyf73e9242007-09-28 14:39:55 -0700290 .nla_policy = nf_ct_port_nla_policy,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700291#endif
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100292#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
293 .ctnl_timeout = {
294 .nlattr_to_obj = udplite_timeout_nlattr_to_obj,
295 .obj_to_nlattr = udplite_timeout_obj_to_nlattr,
296 .nlattr_max = CTA_TIMEOUT_UDPLITE_MAX,
297 .obj_size = sizeof(unsigned int) *
298 CTA_TIMEOUT_UDPLITE_MAX,
299 .nla_policy = udplite_timeout_nla_policy,
300 },
301#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
Gao fenga8021fe2012-05-28 21:04:19 +0000302 .net_id = &udplite_net_id,
303 .init_net = udplite_init_net,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700304};
305
306static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly =
307{
308 .l3proto = PF_INET6,
309 .l4proto = IPPROTO_UDPLITE,
310 .name = "udplite",
Pablo Neira Ayuso71d8c472016-05-01 00:28:40 +0200311 .allow_clash = true,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700312 .pkt_to_tuple = udplite_pkt_to_tuple,
313 .invert_tuple = udplite_invert_tuple,
314 .print_tuple = udplite_print_tuple,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700315 .packet = udplite_packet,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100316 .get_timeouts = udplite_get_timeouts,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700317 .new = udplite_new,
318 .error = udplite_error,
Igor Maravićc0cd1152011-12-12 02:58:24 +0000319#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
Patrick McHardyfdf70832007-09-28 14:37:41 -0700320 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
Patrick McHardy5ff48292009-04-24 15:37:44 +0200321 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
Patrick McHardyfdf70832007-09-28 14:37:41 -0700322 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
Patrick McHardyf73e9242007-09-28 14:39:55 -0700323 .nla_policy = nf_ct_port_nla_policy,
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700324#endif
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100325#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
326 .ctnl_timeout = {
327 .nlattr_to_obj = udplite_timeout_nlattr_to_obj,
328 .obj_to_nlattr = udplite_timeout_obj_to_nlattr,
329 .nlattr_max = CTA_TIMEOUT_UDPLITE_MAX,
330 .obj_size = sizeof(unsigned int) *
331 CTA_TIMEOUT_UDPLITE_MAX,
332 .nla_policy = udplite_timeout_nla_policy,
333 },
334#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
Gao fenga8021fe2012-05-28 21:04:19 +0000335 .net_id = &udplite_net_id,
336 .init_net = udplite_init_net,
337};
338
339static int udplite_net_init(struct net *net)
340{
341 int ret = 0;
342
Gao fengc296bb42013-01-23 12:51:10 +0100343 ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udplite4);
Gao fenga8021fe2012-05-28 21:04:19 +0000344 if (ret < 0) {
Gao fengc296bb42013-01-23 12:51:10 +0100345 pr_err("nf_conntrack_udplite4: pernet registration failed.\n");
Gao fenga8021fe2012-05-28 21:04:19 +0000346 goto out;
347 }
Gao fengc296bb42013-01-23 12:51:10 +0100348 ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udplite6);
Gao fenga8021fe2012-05-28 21:04:19 +0000349 if (ret < 0) {
Gao fengc296bb42013-01-23 12:51:10 +0100350 pr_err("nf_conntrack_udplite6: pernet registration failed.\n");
Gao fenga8021fe2012-05-28 21:04:19 +0000351 goto cleanup_udplite4;
352 }
353 return 0;
354
355cleanup_udplite4:
Gao fengc296bb42013-01-23 12:51:10 +0100356 nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite4);
Gao fenga8021fe2012-05-28 21:04:19 +0000357out:
358 return ret;
359}
360
361static void udplite_net_exit(struct net *net)
362{
Gao fengc296bb42013-01-23 12:51:10 +0100363 nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite6);
364 nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite4);
Gao fenga8021fe2012-05-28 21:04:19 +0000365}
366
367static struct pernet_operations udplite_net_ops = {
368 .init = udplite_net_init,
369 .exit = udplite_net_exit,
370 .id = &udplite_net_id,
371 .size = sizeof(struct udplite_net),
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700372};
373
374static int __init nf_conntrack_proto_udplite_init(void)
375{
Gao fengc296bb42013-01-23 12:51:10 +0100376 int ret;
377
Gao feng0d98da52013-03-07 17:20:46 +0000378 ret = register_pernet_subsys(&udplite_net_ops);
379 if (ret < 0)
380 goto out_pernet;
381
Gao fengc296bb42013-01-23 12:51:10 +0100382 ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udplite4);
383 if (ret < 0)
384 goto out_udplite4;
385
386 ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udplite6);
387 if (ret < 0)
388 goto out_udplite6;
389
Gao fengc296bb42013-01-23 12:51:10 +0100390 return 0;
Gao fengc296bb42013-01-23 12:51:10 +0100391out_udplite6:
392 nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite4);
393out_udplite4:
Gao feng0d98da52013-03-07 17:20:46 +0000394 unregister_pernet_subsys(&udplite_net_ops);
395out_pernet:
Gao fengc296bb42013-01-23 12:51:10 +0100396 return ret;
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700397}
398
399static void __exit nf_conntrack_proto_udplite_exit(void)
400{
Gao fengc296bb42013-01-23 12:51:10 +0100401 nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite6);
402 nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite4);
Gao fenga8021fe2012-05-28 21:04:19 +0000403 unregister_pernet_subsys(&udplite_net_ops);
Patrick McHardy59eecdf2007-07-14 20:48:44 -0700404}
405
406module_init(nf_conntrack_proto_udplite_init);
407module_exit(nf_conntrack_proto_udplite_exit);
408
409MODULE_LICENSE("GPL");