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