Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1 | /* (C) 1999-2001 Paul `Rusty' Russell |
| 2 | * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> |
Patrick McHardy | f229f6c | 2013-04-06 15:24:29 +0200 | [diff] [blame] | 3 | * (C) 2006-2012 Patrick McHardy <kaber@trash.net> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/types.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 11 | #include <linux/timer.h> |
| 12 | #include <linux/module.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [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> |
Martin Josefsson | f618012 | 2006-11-29 02:35:01 +0100 | [diff] [blame] | 19 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 20 | #include <linux/netfilter.h> |
| 21 | #include <linux/netfilter_ipv4.h> |
| 22 | #include <linux/netfilter_ipv6.h> |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 23 | #include <net/netfilter/nf_conntrack_l4proto.h> |
Martin Josefsson | f618012 | 2006-11-29 02:35:01 +0100 | [diff] [blame] | 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> |
Christoph Paasch | 9d2493f | 2009-03-16 15:15:35 +0100 | [diff] [blame] | 26 | #include <net/netfilter/ipv4/nf_conntrack_ipv4.h> |
| 27 | #include <net/netfilter/ipv6/nf_conntrack_ipv6.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 28 | |
Pablo Neira Ayuso | 5a41db9 | 2012-02-28 02:23:28 +0100 | [diff] [blame] | 29 | static unsigned int udp_timeouts[UDP_CT_MAX] = { |
| 30 | [UDP_CT_UNREPLIED] = 30*HZ, |
| 31 | [UDP_CT_REPLIED] = 180*HZ, |
| 32 | }; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 33 | |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 34 | static inline struct nf_udp_net *udp_pernet(struct net *net) |
| 35 | { |
| 36 | return &net->ct.nf_ct_proto.udp; |
| 37 | } |
| 38 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 39 | static bool udp_pkt_to_tuple(const struct sk_buff *skb, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 40 | unsigned int dataoff, |
Eric W. Biederman | a31f1ad | 2015-09-18 14:33:04 -0500 | [diff] [blame] | 41 | struct net *net, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 42 | struct nf_conntrack_tuple *tuple) |
| 43 | { |
Jan Engelhardt | da3f13c | 2008-01-31 04:52:29 -0800 | [diff] [blame] | 44 | const struct udphdr *hp; |
| 45 | struct udphdr _hdr; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 46 | |
Gao Feng | e5e693a | 2016-07-23 19:21:47 +0800 | [diff] [blame] | 47 | /* Actually only need first 4 bytes to get ports. */ |
| 48 | hp = skb_header_pointer(skb, dataoff, 4, &_hdr); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 49 | if (hp == NULL) |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 50 | return false; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 51 | |
| 52 | tuple->src.u.udp.port = hp->source; |
| 53 | tuple->dst.u.udp.port = hp->dest; |
| 54 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 55 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 58 | static bool udp_invert_tuple(struct nf_conntrack_tuple *tuple, |
| 59 | const struct nf_conntrack_tuple *orig) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 60 | { |
| 61 | tuple->src.u.udp.port = orig->dst.u.udp.port; |
| 62 | tuple->dst.u.udp.port = orig->src.u.udp.port; |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 63 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* Print out the per-protocol part of the tuple. */ |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 67 | static void udp_print_tuple(struct seq_file *s, |
| 68 | const struct nf_conntrack_tuple *tuple) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 69 | { |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 70 | seq_printf(s, "sport=%hu dport=%hu ", |
| 71 | ntohs(tuple->src.u.udp.port), |
| 72 | ntohs(tuple->dst.u.udp.port)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 75 | static unsigned int *udp_get_timeouts(struct net *net) |
| 76 | { |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 77 | return udp_pernet(net)->timeouts; |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 80 | /* Returns verdict for packet, and may modify conntracktype */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 81 | static int udp_packet(struct nf_conn *ct, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 82 | const struct sk_buff *skb, |
| 83 | unsigned int dataoff, |
| 84 | enum ip_conntrack_info ctinfo, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 85 | u_int8_t pf, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 86 | unsigned int hooknum, |
| 87 | unsigned int *timeouts) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 88 | { |
| 89 | /* If we've seen traffic both ways, this is some kind of UDP |
| 90 | stream. Extend timeout. */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 91 | if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) { |
Pablo Neira Ayuso | 5a41db9 | 2012-02-28 02:23:28 +0100 | [diff] [blame] | 92 | nf_ct_refresh_acct(ct, ctinfo, skb, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 93 | timeouts[UDP_CT_REPLIED]); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 94 | /* Also, more likely to be important, and not a probe */ |
Patrick McHardy | c88130b | 2008-01-31 04:42:11 -0800 | [diff] [blame] | 95 | if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status)) |
Patrick McHardy | 858b3133 | 2010-02-03 13:48:53 +0100 | [diff] [blame] | 96 | nf_conntrack_event_cache(IPCT_ASSURED, ct); |
Pablo Neira Ayuso | 5a41db9 | 2012-02-28 02:23:28 +0100 | [diff] [blame] | 97 | } else { |
| 98 | nf_ct_refresh_acct(ct, ctinfo, skb, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 99 | timeouts[UDP_CT_UNREPLIED]); |
Pablo Neira Ayuso | 5a41db9 | 2012-02-28 02:23:28 +0100 | [diff] [blame] | 100 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 101 | return NF_ACCEPT; |
| 102 | } |
| 103 | |
| 104 | /* Called when a new connection for this protocol found. */ |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 105 | static bool udp_new(struct nf_conn *ct, const struct sk_buff *skb, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 106 | unsigned int dataoff, unsigned int *timeouts) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 107 | { |
Jan Engelhardt | 09f263c | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 108 | return true; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Patrick McHardy | 8fea97e | 2010-02-15 17:45:08 +0100 | [diff] [blame] | 111 | static int udp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb, |
| 112 | unsigned int dataoff, enum ip_conntrack_info *ctinfo, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 113 | u_int8_t pf, |
Patrick McHardy | 96f6bf8 | 2006-04-06 14:19:24 -0700 | [diff] [blame] | 114 | unsigned int hooknum) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 115 | { |
| 116 | unsigned int udplen = skb->len - dataoff; |
Jan Engelhardt | da3f13c | 2008-01-31 04:52:29 -0800 | [diff] [blame] | 117 | const struct udphdr *hdr; |
| 118 | struct udphdr _hdr; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 119 | |
| 120 | /* Header is too small? */ |
| 121 | hdr = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr); |
| 122 | if (hdr == NULL) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 123 | if (LOG_INVALID(net, IPPROTO_UDP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 124 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 125 | "nf_ct_udp: short packet "); |
| 126 | return -NF_ACCEPT; |
| 127 | } |
| 128 | |
| 129 | /* Truncated/malformed packets */ |
| 130 | if (ntohs(hdr->len) > udplen || ntohs(hdr->len) < sizeof(*hdr)) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 131 | if (LOG_INVALID(net, IPPROTO_UDP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 132 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 133 | "nf_ct_udp: truncated/malformed packet "); |
| 134 | return -NF_ACCEPT; |
| 135 | } |
| 136 | |
| 137 | /* Packet with no checksum */ |
| 138 | if (!hdr->check) |
| 139 | return NF_ACCEPT; |
| 140 | |
| 141 | /* Checksum invalid? Ignore. |
| 142 | * We skip checking packets on the outgoing path |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 143 | * because the checksum is assumed to be correct. |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 144 | * FIXME: Source route IP option packets --RR */ |
Alexey Dobriyan | c04d055 | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 145 | if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING && |
Patrick McHardy | 96f6bf8 | 2006-04-06 14:19:24 -0700 | [diff] [blame] | 146 | nf_checksum(skb, hooknum, dataoff, IPPROTO_UDP, pf)) { |
Alexey Dobriyan | c2a2c7e | 2008-10-08 11:35:08 +0200 | [diff] [blame] | 147 | if (LOG_INVALID(net, IPPROTO_UDP)) |
Gao feng | 30e0c6a | 2013-03-24 23:50:40 +0000 | [diff] [blame] | 148 | nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 149 | "nf_ct_udp: bad UDP checksum "); |
| 150 | return -NF_ACCEPT; |
| 151 | } |
| 152 | |
| 153 | return NF_ACCEPT; |
| 154 | } |
| 155 | |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 156 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 157 | |
| 158 | #include <linux/netfilter/nfnetlink.h> |
| 159 | #include <linux/netfilter/nfnetlink_cttimeout.h> |
| 160 | |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 161 | static int udp_timeout_nlattr_to_obj(struct nlattr *tb[], |
| 162 | struct net *net, void *data) |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 163 | { |
| 164 | unsigned int *timeouts = data; |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 165 | struct nf_udp_net *un = udp_pernet(net); |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 166 | |
| 167 | /* set default timeouts for UDP. */ |
Gao feng | 8264deb | 2012-05-28 21:04:23 +0000 | [diff] [blame] | 168 | timeouts[UDP_CT_UNREPLIED] = un->timeouts[UDP_CT_UNREPLIED]; |
| 169 | timeouts[UDP_CT_REPLIED] = un->timeouts[UDP_CT_REPLIED]; |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 170 | |
| 171 | if (tb[CTA_TIMEOUT_UDP_UNREPLIED]) { |
| 172 | timeouts[UDP_CT_UNREPLIED] = |
| 173 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDP_UNREPLIED])) * HZ; |
| 174 | } |
| 175 | if (tb[CTA_TIMEOUT_UDP_REPLIED]) { |
| 176 | timeouts[UDP_CT_REPLIED] = |
| 177 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDP_REPLIED])) * HZ; |
| 178 | } |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | static int |
| 183 | udp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) |
| 184 | { |
| 185 | const unsigned int *timeouts = data; |
| 186 | |
David S. Miller | 3c60a17 | 2012-04-01 18:48:06 -0400 | [diff] [blame] | 187 | if (nla_put_be32(skb, CTA_TIMEOUT_UDP_UNREPLIED, |
| 188 | htonl(timeouts[UDP_CT_UNREPLIED] / HZ)) || |
| 189 | nla_put_be32(skb, CTA_TIMEOUT_UDP_REPLIED, |
| 190 | htonl(timeouts[UDP_CT_REPLIED] / HZ))) |
| 191 | goto nla_put_failure; |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 192 | return 0; |
| 193 | |
| 194 | nla_put_failure: |
| 195 | return -ENOSPC; |
| 196 | } |
| 197 | |
| 198 | static const struct nla_policy |
| 199 | udp_timeout_nla_policy[CTA_TIMEOUT_UDP_MAX+1] = { |
| 200 | [CTA_TIMEOUT_UDP_UNREPLIED] = { .type = NLA_U32 }, |
| 201 | [CTA_TIMEOUT_UDP_REPLIED] = { .type = NLA_U32 }, |
| 202 | }; |
| 203 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
| 204 | |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 205 | #ifdef CONFIG_SYSCTL |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 206 | static struct ctl_table udp_sysctl_table[] = { |
| 207 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 208 | .procname = "nf_conntrack_udp_timeout", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 209 | .maxlen = sizeof(unsigned int), |
| 210 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 211 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 212 | }, |
| 213 | { |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 214 | .procname = "nf_conntrack_udp_timeout_stream", |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 215 | .maxlen = sizeof(unsigned int), |
| 216 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 217 | .proc_handler = proc_dointvec_jiffies, |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 218 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 219 | { } |
Patrick McHardy | 933a41e | 2006-11-29 02:35:18 +0100 | [diff] [blame] | 220 | }; |
| 221 | #endif /* CONFIG_SYSCTL */ |
| 222 | |
Gao feng | dee7364 | 2012-06-21 04:36:44 +0000 | [diff] [blame] | 223 | static int udp_kmemdup_sysctl_table(struct nf_proto_net *pn, |
| 224 | struct nf_udp_net *un) |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 225 | { |
| 226 | #ifdef CONFIG_SYSCTL |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 227 | if (pn->ctl_table) |
| 228 | return 0; |
| 229 | pn->ctl_table = kmemdup(udp_sysctl_table, |
| 230 | sizeof(udp_sysctl_table), |
| 231 | GFP_KERNEL); |
| 232 | if (!pn->ctl_table) |
| 233 | return -ENOMEM; |
| 234 | pn->ctl_table[0].data = &un->timeouts[UDP_CT_UNREPLIED]; |
| 235 | pn->ctl_table[1].data = &un->timeouts[UDP_CT_REPLIED]; |
| 236 | #endif |
| 237 | return 0; |
| 238 | } |
| 239 | |
Gao feng | dee7364 | 2012-06-21 04:36:44 +0000 | [diff] [blame] | 240 | static int udp_init_net(struct net *net, u_int16_t proto) |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 241 | { |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 242 | struct nf_udp_net *un = udp_pernet(net); |
Gao feng | dee7364 | 2012-06-21 04:36:44 +0000 | [diff] [blame] | 243 | struct nf_proto_net *pn = &un->pn; |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 244 | |
Gao feng | dee7364 | 2012-06-21 04:36:44 +0000 | [diff] [blame] | 245 | if (!pn->users) { |
| 246 | int i; |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 247 | |
Gao feng | dee7364 | 2012-06-21 04:36:44 +0000 | [diff] [blame] | 248 | for (i = 0; i < UDP_CT_MAX; i++) |
| 249 | un->timeouts[i] = udp_timeouts[i]; |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 250 | } |
Gao feng | dee7364 | 2012-06-21 04:36:44 +0000 | [diff] [blame] | 251 | |
Pablo Neira Ayuso | adf0516 | 2016-08-12 13:47:06 +0200 | [diff] [blame^] | 252 | return udp_kmemdup_sysctl_table(pn, un); |
Gao feng | 0ce490a | 2012-05-28 21:04:13 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Pablo Neira Ayuso | 0891147 | 2012-06-29 05:23:24 +0000 | [diff] [blame] | 255 | static struct nf_proto_net *udp_get_net_proto(struct net *net) |
| 256 | { |
| 257 | return &net->ct.nf_ct_proto.udp.pn; |
| 258 | } |
| 259 | |
Patrick McHardy | 61075af | 2007-07-14 20:48:19 -0700 | [diff] [blame] | 260 | struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 261 | { |
| 262 | .l3proto = PF_INET, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 263 | .l4proto = IPPROTO_UDP, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 264 | .name = "udp", |
Pablo Neira Ayuso | 71d8c47 | 2016-05-01 00:28:40 +0200 | [diff] [blame] | 265 | .allow_clash = true, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 266 | .pkt_to_tuple = udp_pkt_to_tuple, |
| 267 | .invert_tuple = udp_invert_tuple, |
| 268 | .print_tuple = udp_print_tuple, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 269 | .packet = udp_packet, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 270 | .get_timeouts = udp_get_timeouts, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 271 | .new = udp_new, |
Patrick McHardy | 96f6bf8 | 2006-04-06 14:19:24 -0700 | [diff] [blame] | 272 | .error = udp_error, |
Igor Maravić | c0cd115 | 2011-12-12 02:58:24 +0000 | [diff] [blame] | 273 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 274 | .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, |
| 275 | .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 276 | .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 277 | .nla_policy = nf_ct_port_nla_policy, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 278 | #endif |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 279 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 280 | .ctnl_timeout = { |
| 281 | .nlattr_to_obj = udp_timeout_nlattr_to_obj, |
| 282 | .obj_to_nlattr = udp_timeout_obj_to_nlattr, |
| 283 | .nlattr_max = CTA_TIMEOUT_UDP_MAX, |
| 284 | .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX, |
| 285 | .nla_policy = udp_timeout_nla_policy, |
| 286 | }, |
| 287 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
Gao feng | dee7364 | 2012-06-21 04:36:44 +0000 | [diff] [blame] | 288 | .init_net = udp_init_net, |
Pablo Neira Ayuso | 0891147 | 2012-06-29 05:23:24 +0000 | [diff] [blame] | 289 | .get_net_proto = udp_get_net_proto, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 290 | }; |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 291 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp4); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 292 | |
Patrick McHardy | 61075af | 2007-07-14 20:48:19 -0700 | [diff] [blame] | 293 | struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 __read_mostly = |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 294 | { |
| 295 | .l3proto = PF_INET6, |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 296 | .l4proto = IPPROTO_UDP, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 297 | .name = "udp", |
Pablo Neira Ayuso | 71d8c47 | 2016-05-01 00:28:40 +0200 | [diff] [blame] | 298 | .allow_clash = true, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 299 | .pkt_to_tuple = udp_pkt_to_tuple, |
| 300 | .invert_tuple = udp_invert_tuple, |
| 301 | .print_tuple = udp_print_tuple, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 302 | .packet = udp_packet, |
Pablo Neira Ayuso | 2c8503f | 2012-02-28 18:23:31 +0100 | [diff] [blame] | 303 | .get_timeouts = udp_get_timeouts, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 304 | .new = udp_new, |
Patrick McHardy | 96f6bf8 | 2006-04-06 14:19:24 -0700 | [diff] [blame] | 305 | .error = udp_error, |
Igor Maravić | c0cd115 | 2011-12-12 02:58:24 +0000 | [diff] [blame] | 306 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 307 | .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr, |
| 308 | .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, |
Holger Eitzenberger | a400c30 | 2009-03-25 21:53:39 +0100 | [diff] [blame] | 309 | .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, |
Patrick McHardy | f73e924 | 2007-09-28 14:39:55 -0700 | [diff] [blame] | 310 | .nla_policy = nf_ct_port_nla_policy, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 311 | #endif |
Pablo Neira Ayuso | 5097846 | 2012-02-28 19:13:48 +0100 | [diff] [blame] | 312 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
| 313 | .ctnl_timeout = { |
| 314 | .nlattr_to_obj = udp_timeout_nlattr_to_obj, |
| 315 | .obj_to_nlattr = udp_timeout_obj_to_nlattr, |
| 316 | .nlattr_max = CTA_TIMEOUT_UDP_MAX, |
| 317 | .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX, |
| 318 | .nla_policy = udp_timeout_nla_policy, |
| 319 | }, |
| 320 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
Gao feng | dee7364 | 2012-06-21 04:36:44 +0000 | [diff] [blame] | 321 | .init_net = udp_init_net, |
Pablo Neira Ayuso | 0891147 | 2012-06-29 05:23:24 +0000 | [diff] [blame] | 322 | .get_net_proto = udp_get_net_proto, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 323 | }; |
Patrick McHardy | 13b1833 | 2006-12-02 22:11:25 -0800 | [diff] [blame] | 324 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp6); |