Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 1 | /* (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 McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 13 | #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 McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame] | 25 | #include <net/netfilter/nf_log.h> |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 26 | |
Pablo Neira Ayuso | 5a41db9 | 2012-02-28 02:23:28 +0100 | [diff] [blame] | 27 | enum udplite_conntrack { |
| 28 | UDPLITE_CT_UNREPLIED, |
| 29 | UDPLITE_CT_REPLIED, |
| 30 | UDPLITE_CT_MAX |
| 31 | }; |
| 32 | |
| 33 | static unsigned int udplite_timeouts[UDPLITE_CT_MAX] = { |
| 34 | [UDPLITE_CT_UNREPLIED] = 30*HZ, |
| 35 | [UDPLITE_CT_REPLIED] = 180*HZ, |
| 36 | }; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 37 | |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 38 | static int udplite_net_id __read_mostly; |
| 39 | struct udplite_net { |
| 40 | struct nf_proto_net pn; |
| 41 | unsigned int timeouts[UDPLITE_CT_MAX]; |
| 42 | }; |
| 43 | |
| 44 | static inline struct udplite_net *udplite_pernet(struct net *net) |
| 45 | { |
| 46 | return net_generic(net, udplite_net_id); |
| 47 | } |
| 48 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 49 | static bool udplite_pkt_to_tuple(const struct sk_buff *skb, |
| 50 | unsigned int dataoff, |
| 51 | struct nf_conntrack_tuple *tuple) |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 52 | { |
Jan Engelhardt | da3f13c | 2008-01-31 04:52:29 -0800 | [diff] [blame] | 53 | const struct udphdr *hp; |
| 54 | struct udphdr _hdr; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 55 | |
| 56 | hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr); |
| 57 | if (hp == NULL) |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 58 | return false; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 59 | |
| 60 | tuple->src.u.udp.port = hp->source; |
| 61 | tuple->dst.u.udp.port = hp->dest; |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 62 | return true; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 65 | static bool udplite_invert_tuple(struct nf_conntrack_tuple *tuple, |
| 66 | const struct nf_conntrack_tuple *orig) |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 67 | { |
| 68 | tuple->src.u.udp.port = orig->dst.u.udp.port; |
| 69 | tuple->dst.u.udp.port = orig->src.u.udp.port; |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 70 | return true; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* Print out the per-protocol part of the tuple. */ |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 74 | static void udplite_print_tuple(struct seq_file *s, |
| 75 | const struct nf_conntrack_tuple *tuple) |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 76 | { |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 77 | seq_printf(s, "sport=%hu dport=%hu ", |
| 78 | ntohs(tuple->src.u.udp.port), |
| 79 | ntohs(tuple->dst.u.udp.port)); |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 82 | static unsigned int *udplite_get_timeouts(struct net *net) |
| 83 | { |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 84 | return udplite_pernet(net)->timeouts; |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 87 | /* Returns verdict for packet, and may modify conntracktype */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 88 | static int udplite_packet(struct nf_conn *ct, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 89 | const struct sk_buff *skb, |
| 90 | unsigned int dataoff, |
| 91 | enum ip_conntrack_info ctinfo, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 92 | u_int8_t pf, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 93 | unsigned int hooknum, |
| 94 | unsigned int *timeouts) |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 95 | { |
| 96 | /* If we've seen traffic both ways, this is some kind of UDP |
| 97 | stream. Extend timeout. */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 98 | if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) { |
| 99 | nf_ct_refresh_acct(ct, ctinfo, skb, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 100 | timeouts[UDPLITE_CT_REPLIED]); |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 101 | /* Also, more likely to be important, and not a probe */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 102 | if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status)) |
Patrick McHardy | 858b3133 | 2010-02-03 13:48:53 +0100 | [diff] [blame] | 103 | nf_conntrack_event_cache(IPCT_ASSURED, ct); |
Pablo Neira Ayuso | 5a41db9 | 2012-02-28 02:23:28 +0100 | [diff] [blame] | 104 | } else { |
| 105 | nf_ct_refresh_acct(ct, ctinfo, skb, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 106 | timeouts[UDPLITE_CT_UNREPLIED]); |
Pablo Neira Ayuso | 5a41db9 | 2012-02-28 02:23:28 +0100 | [diff] [blame] | 107 | } |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 108 | return NF_ACCEPT; |
| 109 | } |
| 110 | |
| 111 | /* Called when a new connection for this protocol found. */ |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 112 | static bool udplite_new(struct nf_conn *ct, const struct sk_buff *skb, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 113 | unsigned int dataoff, unsigned int *timeouts) |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 114 | { |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 115 | return true; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Patrick McHardy | 8fea97e | 2010-02-15 17:45:08 +0100 | [diff] [blame] | 118 | static int udplite_error(struct net *net, struct nf_conn *tmpl, |
Alexey Dobriyan | 74c51a1 | 2008-10-08 11:35:05 +0200 | [diff] [blame] | 119 | struct sk_buff *skb, |
| 120 | unsigned int dataoff, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 121 | enum ip_conntrack_info *ctinfo, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 122 | u_int8_t pf, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 123 | unsigned int hooknum) |
| 124 | { |
| 125 | unsigned int udplen = skb->len - dataoff; |
Jan Engelhardt | da3f13c | 2008-01-31 04:52:29 -0800 | [diff] [blame] | 126 | const struct udphdr *hdr; |
| 127 | struct udphdr _hdr; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 128 | unsigned int cscov; |
| 129 | |
| 130 | /* Header is too small? */ |
| 131 | hdr = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr); |
| 132 | if (hdr == NULL) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 133 | if (LOG_INVALID(net, IPPROTO_UDPLITE)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 134 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 135 | "nf_ct_udplite: short packet "); |
| 136 | return -NF_ACCEPT; |
| 137 | } |
| 138 | |
| 139 | cscov = ntohs(hdr->len); |
| 140 | if (cscov == 0) |
| 141 | cscov = udplen; |
| 142 | else if (cscov < sizeof(*hdr) || cscov > udplen) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 143 | if (LOG_INVALID(net, IPPROTO_UDPLITE)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 144 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 145 | "nf_ct_udplite: invalid checksum coverage "); |
| 146 | return -NF_ACCEPT; |
| 147 | } |
| 148 | |
| 149 | /* UDPLITE mandates checksums */ |
| 150 | if (!hdr->check) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 151 | if (LOG_INVALID(net, IPPROTO_UDPLITE)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 152 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 153 | "nf_ct_udplite: checksum missing "); |
| 154 | return -NF_ACCEPT; |
| 155 | } |
| 156 | |
| 157 | /* Checksum invalid? Ignore. */ |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 158 | if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING && |
Patrick McHardy | d63a650 | 2008-03-20 15:15:53 +0100 | [diff] [blame] | 159 | nf_checksum_partial(skb, hooknum, dataoff, cscov, IPPROTO_UDP, |
| 160 | pf)) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 161 | if (LOG_INVALID(net, IPPROTO_UDPLITE)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 162 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Patrick McHardy | d63a650 | 2008-03-20 15:15:53 +0100 | [diff] [blame] | 163 | "nf_ct_udplite: bad UDPLite checksum "); |
| 164 | return -NF_ACCEPT; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | return NF_ACCEPT; |
| 168 | } |
| 169 | |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 170 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 171 | |
| 172 | #include <linux/netfilter/nfnetlink.h> |
| 173 | #include <linux/netfilter/nfnetlink_cttimeout.h> |
| 174 | |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 175 | static int udplite_timeout_nlattr_to_obj(struct nlattr *tb[], |
| 176 | struct net *net, void *data) |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 177 | { |
| 178 | unsigned int *timeouts = data; |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 179 | struct udplite_net *un = udplite_pernet(net); |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 180 | |
| 181 | /* set default timeouts for UDPlite. */ |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 182 | timeouts[UDPLITE_CT_UNREPLIED] = un->timeouts[UDPLITE_CT_UNREPLIED]; |
| 183 | timeouts[UDPLITE_CT_REPLIED] = un->timeouts[UDPLITE_CT_REPLIED]; |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 184 | |
| 185 | if (tb[CTA_TIMEOUT_UDPLITE_UNREPLIED]) { |
| 186 | timeouts[UDPLITE_CT_UNREPLIED] = |
| 187 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDPLITE_UNREPLIED])) * HZ; |
| 188 | } |
| 189 | if (tb[CTA_TIMEOUT_UDPLITE_REPLIED]) { |
| 190 | timeouts[UDPLITE_CT_REPLIED] = |
| 191 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDPLITE_REPLIED])) * HZ; |
| 192 | } |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static int |
| 197 | udplite_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) |
| 198 | { |
| 199 | const unsigned int *timeouts = data; |
| 200 | |
David S. Miller | 3c60a17 | 2012-04-01 18:48:06 -0400 | [diff] [blame] | 201 | if (nla_put_be32(skb, CTA_TIMEOUT_UDPLITE_UNREPLIED, |
| 202 | htonl(timeouts[UDPLITE_CT_UNREPLIED] / HZ)) || |
| 203 | nla_put_be32(skb, CTA_TIMEOUT_UDPLITE_REPLIED, |
| 204 | htonl(timeouts[UDPLITE_CT_REPLIED] / HZ))) |
| 205 | goto nla_put_failure; |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 206 | return 0; |
| 207 | |
| 208 | nla_put_failure: |
| 209 | return -ENOSPC; |
| 210 | } |
| 211 | |
| 212 | static const struct nla_policy |
| 213 | udplite_timeout_nla_policy[CTA_TIMEOUT_UDPLITE_MAX+1] = { |
| 214 | [CTA_TIMEOUT_UDPLITE_UNREPLIED] = { .type = NLA_U32 }, |
| 215 | [CTA_TIMEOUT_UDPLITE_REPLIED] = { .type = NLA_U32 }, |
| 216 | }; |
| 217 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
| 218 | |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 219 | #ifdef CONFIG_SYSCTL |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 220 | static struct ctl_table udplite_sysctl_table[] = { |
| 221 | { |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 222 | .procname = "nf_conntrack_udplite_timeout", |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 223 | .maxlen = sizeof(unsigned int), |
| 224 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 225 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 226 | }, |
| 227 | { |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 228 | .procname = "nf_conntrack_udplite_timeout_stream", |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 229 | .maxlen = sizeof(unsigned int), |
| 230 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 231 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 232 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 233 | { } |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 234 | }; |
| 235 | #endif /* CONFIG_SYSCTL */ |
| 236 | |
Gao feng | 51b4c82 | 2012-06-21 04:36:45 +0000 | [diff] [blame] | 237 | static int udplite_kmemdup_sysctl_table(struct nf_proto_net *pn, |
| 238 | struct udplite_net *un) |
| 239 | { |
| 240 | #ifdef CONFIG_SYSCTL |
| 241 | if (pn->ctl_table) |
| 242 | return 0; |
| 243 | |
| 244 | pn->ctl_table = kmemdup(udplite_sysctl_table, |
| 245 | sizeof(udplite_sysctl_table), |
| 246 | GFP_KERNEL); |
| 247 | if (!pn->ctl_table) |
| 248 | return -ENOMEM; |
| 249 | |
| 250 | pn->ctl_table[0].data = &un->timeouts[UDPLITE_CT_UNREPLIED]; |
| 251 | pn->ctl_table[1].data = &un->timeouts[UDPLITE_CT_REPLIED]; |
| 252 | #endif |
| 253 | return 0; |
| 254 | } |
| 255 | |
Gao feng | f1caad2 | 2012-06-21 04:36:39 +0000 | [diff] [blame] | 256 | static int udplite_init_net(struct net *net, u_int16_t proto) |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 257 | { |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 258 | struct udplite_net *un = udplite_pernet(net); |
Gao feng | 51b4c82 | 2012-06-21 04:36:45 +0000 | [diff] [blame] | 259 | struct nf_proto_net *pn = &un->pn; |
| 260 | |
| 261 | if (!pn->users) { |
| 262 | int i; |
| 263 | |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 264 | for (i = 0 ; i < UDPLITE_CT_MAX; i++) |
| 265 | un->timeouts[i] = udplite_timeouts[i]; |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 266 | } |
Gao feng | 51b4c82 | 2012-06-21 04:36:45 +0000 | [diff] [blame] | 267 | |
| 268 | return udplite_kmemdup_sysctl_table(pn, un); |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 271 | static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = |
| 272 | { |
| 273 | .l3proto = PF_INET, |
| 274 | .l4proto = IPPROTO_UDPLITE, |
| 275 | .name = "udplite", |
| 276 | .pkt_to_tuple = udplite_pkt_to_tuple, |
| 277 | .invert_tuple = udplite_invert_tuple, |
| 278 | .print_tuple = udplite_print_tuple, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 279 | .packet = udplite_packet, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 280 | .get_timeouts = udplite_get_timeouts, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 281 | .new = udplite_new, |
| 282 | .error = udplite_error, |
Igor Maravić | c0cd115 | 2011-12-12 02:58:24 +0000 | [diff] [blame] | 283 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 284 | .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 285 | .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 286 | .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 287 | .nla_policy = nf_ct_port_nla_policy, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 288 | #endif |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 289 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 290 | .ctnl_timeout = { |
| 291 | .nlattr_to_obj = udplite_timeout_nlattr_to_obj, |
| 292 | .obj_to_nlattr = udplite_timeout_obj_to_nlattr, |
| 293 | .nlattr_max = CTA_TIMEOUT_UDPLITE_MAX, |
| 294 | .obj_size = sizeof(unsigned int) * |
| 295 | CTA_TIMEOUT_UDPLITE_MAX, |
| 296 | .nla_policy = udplite_timeout_nla_policy, |
| 297 | }, |
| 298 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 299 | .net_id = &udplite_net_id, |
| 300 | .init_net = udplite_init_net, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly = |
| 304 | { |
| 305 | .l3proto = PF_INET6, |
| 306 | .l4proto = IPPROTO_UDPLITE, |
| 307 | .name = "udplite", |
| 308 | .pkt_to_tuple = udplite_pkt_to_tuple, |
| 309 | .invert_tuple = udplite_invert_tuple, |
| 310 | .print_tuple = udplite_print_tuple, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 311 | .packet = udplite_packet, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 312 | .get_timeouts = udplite_get_timeouts, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 313 | .new = udplite_new, |
| 314 | .error = udplite_error, |
Igor Maravić | c0cd115 | 2011-12-12 02:58:24 +0000 | [diff] [blame] | 315 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 316 | .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, |
Patrick McHardy | 5ff4829 | 2009-04-24 15:37:44 +0200 | [diff] [blame] | 317 | .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 318 | .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 319 | .nla_policy = nf_ct_port_nla_policy, |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 320 | #endif |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 321 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 322 | .ctnl_timeout = { |
| 323 | .nlattr_to_obj = udplite_timeout_nlattr_to_obj, |
| 324 | .obj_to_nlattr = udplite_timeout_obj_to_nlattr, |
| 325 | .nlattr_max = CTA_TIMEOUT_UDPLITE_MAX, |
| 326 | .obj_size = sizeof(unsigned int) * |
| 327 | CTA_TIMEOUT_UDPLITE_MAX, |
| 328 | .nla_policy = udplite_timeout_nla_policy, |
| 329 | }, |
| 330 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 331 | .net_id = &udplite_net_id, |
| 332 | .init_net = udplite_init_net, |
| 333 | }; |
| 334 | |
| 335 | static int udplite_net_init(struct net *net) |
| 336 | { |
| 337 | int ret = 0; |
| 338 | |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 339 | ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udplite4); |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 340 | if (ret < 0) { |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 341 | pr_err("nf_conntrack_udplite4: pernet registration failed.\n"); |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 342 | goto out; |
| 343 | } |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 344 | ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udplite6); |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 345 | if (ret < 0) { |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 346 | pr_err("nf_conntrack_udplite6: pernet registration failed.\n"); |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 347 | goto cleanup_udplite4; |
| 348 | } |
| 349 | return 0; |
| 350 | |
| 351 | cleanup_udplite4: |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 352 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite4); |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 353 | out: |
| 354 | return ret; |
| 355 | } |
| 356 | |
| 357 | static void udplite_net_exit(struct net *net) |
| 358 | { |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 359 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite6); |
| 360 | nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udplite4); |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static struct pernet_operations udplite_net_ops = { |
| 364 | .init = udplite_net_init, |
| 365 | .exit = udplite_net_exit, |
| 366 | .id = &udplite_net_id, |
| 367 | .size = sizeof(struct udplite_net), |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 368 | }; |
| 369 | |
| 370 | static int __init nf_conntrack_proto_udplite_init(void) |
| 371 | { |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 372 | int ret; |
| 373 | |
Gao feng | 0d98da5 | 2013-03-07 17:20:46 +0000 | [diff] [blame] | 374 | ret = register_pernet_subsys(&udplite_net_ops); |
| 375 | if (ret < 0) |
| 376 | goto out_pernet; |
| 377 | |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 378 | ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udplite4); |
| 379 | if (ret < 0) |
| 380 | goto out_udplite4; |
| 381 | |
| 382 | ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udplite6); |
| 383 | if (ret < 0) |
| 384 | goto out_udplite6; |
| 385 | |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 386 | return 0; |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 387 | out_udplite6: |
| 388 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite4); |
| 389 | out_udplite4: |
Gao feng | 0d98da5 | 2013-03-07 17:20:46 +0000 | [diff] [blame] | 390 | unregister_pernet_subsys(&udplite_net_ops); |
| 391 | out_pernet: |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 392 | return ret; |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static void __exit nf_conntrack_proto_udplite_exit(void) |
| 396 | { |
Gao feng | c296bb4 | 2013-01-23 12:51:10 +0100 | [diff] [blame] | 397 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite6); |
| 398 | nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udplite4); |
Gao feng | a8021fe | 2012-05-28 21:04:19 +0000 | [diff] [blame] | 399 | unregister_pernet_subsys(&udplite_net_ops); |
Patrick McHardy | 59eecdf | 2007-07-14 20:48:44 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | module_init(nf_conntrack_proto_udplite_init); |
| 403 | module_exit(nf_conntrack_proto_udplite_exit); |
| 404 | |
| 405 | MODULE_LICENSE("GPL"); |