Blame view

net/netfilter/nf_conntrack_proto_udp.c 12 KB
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
1
2
  /* (C) 1999-2001 Paul `Rusty' Russell
   * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
f229f6ce4   Patrick McHardy   netfilter: add my...
3
   * (C) 2006-2012 Patrick McHardy <kaber@trash.net>
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
4
5
6
7
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
8
9
10
   */
  
  #include <linux/types.h>
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
11
12
  #include <linux/timer.h>
  #include <linux/module.h>
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
13
14
15
16
17
18
  #include <linux/udp.h>
  #include <linux/seq_file.h>
  #include <linux/skbuff.h>
  #include <linux/ipv6.h>
  #include <net/ip6_checksum.h>
  #include <net/checksum.h>
f61801218   Martin Josefsson   [NETFILTER]: nf_c...
19

9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
20
21
22
  #include <linux/netfilter.h>
  #include <linux/netfilter_ipv4.h>
  #include <linux/netfilter_ipv6.h>
605dcad6c   Martin Josefsson   [NETFILTER]: nf_c...
23
  #include <net/netfilter/nf_conntrack_l4proto.h>
f61801218   Martin Josefsson   [NETFILTER]: nf_c...
24
  #include <net/netfilter/nf_conntrack_ecache.h>
f01ffbd6e   Patrick McHardy   [NETFILTER]: nf_l...
25
  #include <net/netfilter/nf_log.h>
9d2493f88   Christoph Paasch   netfilter: remove...
26
27
  #include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
  #include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
28

5a41db94c   Pablo Neira Ayuso   netfilter: nf_ct_...
29
30
31
32
  static unsigned int udp_timeouts[UDP_CT_MAX] = {
  	[UDP_CT_UNREPLIED]	= 30*HZ,
  	[UDP_CT_REPLIED]	= 180*HZ,
  };
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
33

0ce490ad4   Gao feng   netfilter: nf_ct_...
34
35
36
37
  static inline struct nf_udp_net *udp_pernet(struct net *net)
  {
  	return &net->ct.nf_ct_proto.udp;
  }
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
38
  static bool udp_pkt_to_tuple(const struct sk_buff *skb,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
39
  			     unsigned int dataoff,
a31f1adc0   Eric W. Biederman   netfilter: nf_con...
40
  			     struct net *net,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
41
42
  			     struct nf_conntrack_tuple *tuple)
  {
da3f13c95   Jan Engelhardt   [NETFILTER]: nf_{...
43
44
  	const struct udphdr *hp;
  	struct udphdr _hdr;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
45

e5e693ab4   Gao Feng   netfilter: conntr...
46
47
  	/* Actually only need first 4 bytes to get ports. */
  	hp = skb_header_pointer(skb, dataoff, 4, &_hdr);
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
48
  	if (hp == NULL)
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
49
  		return false;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
50
51
52
  
  	tuple->src.u.udp.port = hp->source;
  	tuple->dst.u.udp.port = hp->dest;
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
53
  	return true;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
54
  }
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
55
56
  static bool udp_invert_tuple(struct nf_conntrack_tuple *tuple,
  			     const struct nf_conntrack_tuple *orig)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
57
58
59
  {
  	tuple->src.u.udp.port = orig->dst.u.udp.port;
  	tuple->dst.u.udp.port = orig->src.u.udp.port;
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
60
  	return true;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
61
  }
2c8503f55   Pablo Neira Ayuso   netfilter: nf_con...
62
63
  static unsigned int *udp_get_timeouts(struct net *net)
  {
0ce490ad4   Gao feng   netfilter: nf_ct_...
64
  	return udp_pernet(net)->timeouts;
2c8503f55   Pablo Neira Ayuso   netfilter: nf_con...
65
  }
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
66
  /* Returns verdict for packet, and may modify conntracktype */
c88130bcd   Patrick McHardy   [NETFILTER]: nf_c...
67
  static int udp_packet(struct nf_conn *ct,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
68
69
70
  		      const struct sk_buff *skb,
  		      unsigned int dataoff,
  		      enum ip_conntrack_info ctinfo,
76108cea0   Jan Engelhardt   netfilter: Use un...
71
  		      u_int8_t pf,
2c8503f55   Pablo Neira Ayuso   netfilter: nf_con...
72
  		      unsigned int *timeouts)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
73
74
75
  {
  	/* If we've seen traffic both ways, this is some kind of UDP
  	   stream.  Extend timeout. */
c88130bcd   Patrick McHardy   [NETFILTER]: nf_c...
76
  	if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
5a41db94c   Pablo Neira Ayuso   netfilter: nf_ct_...
77
  		nf_ct_refresh_acct(ct, ctinfo, skb,
2c8503f55   Pablo Neira Ayuso   netfilter: nf_con...
78
  				   timeouts[UDP_CT_REPLIED]);
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
79
  		/* Also, more likely to be important, and not a probe */
c88130bcd   Patrick McHardy   [NETFILTER]: nf_c...
80
  		if (!test_and_set_bit(IPS_ASSURED_BIT, &ct->status))
858b31330   Patrick McHardy   netfilter: nf_con...
81
  			nf_conntrack_event_cache(IPCT_ASSURED, ct);
5a41db94c   Pablo Neira Ayuso   netfilter: nf_ct_...
82
83
  	} else {
  		nf_ct_refresh_acct(ct, ctinfo, skb,
2c8503f55   Pablo Neira Ayuso   netfilter: nf_con...
84
  				   timeouts[UDP_CT_UNREPLIED]);
5a41db94c   Pablo Neira Ayuso   netfilter: nf_ct_...
85
  	}
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
86
87
88
89
  	return NF_ACCEPT;
  }
  
  /* Called when a new connection for this protocol found. */
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
90
  static bool udp_new(struct nf_conn *ct, const struct sk_buff *skb,
2c8503f55   Pablo Neira Ayuso   netfilter: nf_con...
91
  		    unsigned int dataoff, unsigned int *timeouts)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
92
  {
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
93
  	return true;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
94
  }
e4781421e   Florian Westphal   netfilter: merge ...
95
96
97
98
  #ifdef CONFIG_NF_CT_PROTO_UDPLITE
  static int udplite_error(struct net *net, struct nf_conn *tmpl,
  			 struct sk_buff *skb,
  			 unsigned int dataoff,
e4781421e   Florian Westphal   netfilter: merge ...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  			 u8 pf, unsigned int hooknum)
  {
  	unsigned int udplen = skb->len - dataoff;
  	const struct udphdr *hdr;
  	struct udphdr _hdr;
  	unsigned int cscov;
  
  	/* Header is too small? */
  	hdr = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
  	if (!hdr) {
  		if (LOG_INVALID(net, IPPROTO_UDPLITE))
  			nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
  				      "nf_ct_udplite: short packet ");
  		return -NF_ACCEPT;
  	}
  
  	cscov = ntohs(hdr->len);
  	if (cscov == 0) {
  		cscov = udplen;
  	} else if (cscov < sizeof(*hdr) || cscov > udplen) {
  		if (LOG_INVALID(net, IPPROTO_UDPLITE))
  			nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
  				      "nf_ct_udplite: invalid checksum coverage ");
  		return -NF_ACCEPT;
  	}
  
  	/* UDPLITE mandates checksums */
  	if (!hdr->check) {
  		if (LOG_INVALID(net, IPPROTO_UDPLITE))
  			nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
  				      "nf_ct_udplite: checksum missing ");
  		return -NF_ACCEPT;
  	}
  
  	/* Checksum invalid? Ignore. */
  	if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
  	    nf_checksum_partial(skb, hooknum, dataoff, cscov, IPPROTO_UDP,
  				pf)) {
  		if (LOG_INVALID(net, IPPROTO_UDPLITE))
  			nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
  				      "nf_ct_udplite: bad UDPLite checksum ");
  		return -NF_ACCEPT;
  	}
  
  	return NF_ACCEPT;
  }
  #endif
8fea97ec1   Patrick McHardy   netfilter: nf_con...
146
  static int udp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
11df4b760   Florian Westphal   netfilter: conntr...
147
  		     unsigned int dataoff,
76108cea0   Jan Engelhardt   netfilter: Use un...
148
  		     u_int8_t pf,
96f6bf82e   Patrick McHardy   [NETFILTER]: Conv...
149
  		     unsigned int hooknum)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
150
151
  {
  	unsigned int udplen = skb->len - dataoff;
da3f13c95   Jan Engelhardt   [NETFILTER]: nf_{...
152
153
  	const struct udphdr *hdr;
  	struct udphdr _hdr;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
154
155
156
157
  
  	/* Header is too small? */
  	hdr = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
  	if (hdr == NULL) {
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
158
  		if (LOG_INVALID(net, IPPROTO_UDP))
30e0c6a6b   Gao feng   netfilter: nf_log...
159
  			nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
160
161
162
163
164
165
  				      "nf_ct_udp: short packet ");
  		return -NF_ACCEPT;
  	}
  
  	/* Truncated/malformed packets */
  	if (ntohs(hdr->len) > udplen || ntohs(hdr->len) < sizeof(*hdr)) {
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
166
  		if (LOG_INVALID(net, IPPROTO_UDP))
30e0c6a6b   Gao feng   netfilter: nf_log...
167
  			nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
168
169
170
171
172
173
174
175
176
177
  				"nf_ct_udp: truncated/malformed packet ");
  		return -NF_ACCEPT;
  	}
  
  	/* Packet with no checksum */
  	if (!hdr->check)
  		return NF_ACCEPT;
  
  	/* Checksum invalid? Ignore.
  	 * We skip checking packets on the outgoing path
84fa7933a   Patrick McHardy   [NET]: Replace CH...
178
  	 * because the checksum is assumed to be correct.
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
179
  	 * FIXME: Source route IP option packets --RR */
c04d05529   Alexey Dobriyan   netfilter: netns ...
180
  	if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
96f6bf82e   Patrick McHardy   [NETFILTER]: Conv...
181
  	    nf_checksum(skb, hooknum, dataoff, IPPROTO_UDP, pf)) {
c2a2c7e0c   Alexey Dobriyan   netfilter: netns ...
182
  		if (LOG_INVALID(net, IPPROTO_UDP))
30e0c6a6b   Gao feng   netfilter: nf_log...
183
  			nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
184
185
186
187
188
189
  				"nf_ct_udp: bad UDP checksum ");
  		return -NF_ACCEPT;
  	}
  
  	return NF_ACCEPT;
  }
509784623   Pablo Neira Ayuso   netfilter: add ct...
190
191
192
193
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
  
  #include <linux/netfilter/nfnetlink.h>
  #include <linux/netfilter/nfnetlink_cttimeout.h>
8264deb81   Gao feng   netfilter: nf_con...
194
195
  static int udp_timeout_nlattr_to_obj(struct nlattr *tb[],
  				     struct net *net, void *data)
509784623   Pablo Neira Ayuso   netfilter: add ct...
196
197
  {
  	unsigned int *timeouts = data;
8264deb81   Gao feng   netfilter: nf_con...
198
  	struct nf_udp_net *un = udp_pernet(net);
509784623   Pablo Neira Ayuso   netfilter: add ct...
199
200
  
  	/* set default timeouts for UDP. */
8264deb81   Gao feng   netfilter: nf_con...
201
202
  	timeouts[UDP_CT_UNREPLIED] = un->timeouts[UDP_CT_UNREPLIED];
  	timeouts[UDP_CT_REPLIED] = un->timeouts[UDP_CT_REPLIED];
509784623   Pablo Neira Ayuso   netfilter: add ct...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  
  	if (tb[CTA_TIMEOUT_UDP_UNREPLIED]) {
  		timeouts[UDP_CT_UNREPLIED] =
  			ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDP_UNREPLIED])) * HZ;
  	}
  	if (tb[CTA_TIMEOUT_UDP_REPLIED]) {
  		timeouts[UDP_CT_REPLIED] =
  			ntohl(nla_get_be32(tb[CTA_TIMEOUT_UDP_REPLIED])) * HZ;
  	}
  	return 0;
  }
  
  static int
  udp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
  {
  	const unsigned int *timeouts = data;
3c60a17b1   David S. Miller   nf_conntrack_prot...
219
220
221
222
223
  	if (nla_put_be32(skb, CTA_TIMEOUT_UDP_UNREPLIED,
  			 htonl(timeouts[UDP_CT_UNREPLIED] / HZ)) ||
  	    nla_put_be32(skb, CTA_TIMEOUT_UDP_REPLIED,
  			 htonl(timeouts[UDP_CT_REPLIED] / HZ)))
  		goto nla_put_failure;
509784623   Pablo Neira Ayuso   netfilter: add ct...
224
225
226
227
228
229
230
231
232
233
234
235
  	return 0;
  
  nla_put_failure:
  	return -ENOSPC;
  }
  
  static const struct nla_policy
  udp_timeout_nla_policy[CTA_TIMEOUT_UDP_MAX+1] = {
         [CTA_TIMEOUT_UDP_UNREPLIED]	= { .type = NLA_U32 },
         [CTA_TIMEOUT_UDP_REPLIED]	= { .type = NLA_U32 },
  };
  #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
236
  #ifdef CONFIG_SYSCTL
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
237
238
  static struct ctl_table udp_sysctl_table[] = {
  	{
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
239
  		.procname	= "nf_conntrack_udp_timeout",
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
240
241
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
6d9f239a1   Alexey Dobriyan   net: '&' redux
242
  		.proc_handler	= proc_dointvec_jiffies,
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
243
244
  	},
  	{
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
245
  		.procname	= "nf_conntrack_udp_timeout_stream",
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
246
247
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
6d9f239a1   Alexey Dobriyan   net: '&' redux
248
  		.proc_handler	= proc_dointvec_jiffies,
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
249
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
250
  	{ }
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
251
252
  };
  #endif /* CONFIG_SYSCTL */
dee7364e0   Gao feng   netfilter: nf_ct_...
253
254
  static int udp_kmemdup_sysctl_table(struct nf_proto_net *pn,
  				    struct nf_udp_net *un)
0ce490ad4   Gao feng   netfilter: nf_ct_...
255
256
  {
  #ifdef CONFIG_SYSCTL
0ce490ad4   Gao feng   netfilter: nf_ct_...
257
258
259
260
261
262
263
264
265
266
267
268
  	if (pn->ctl_table)
  		return 0;
  	pn->ctl_table = kmemdup(udp_sysctl_table,
  				sizeof(udp_sysctl_table),
  				GFP_KERNEL);
  	if (!pn->ctl_table)
  		return -ENOMEM;
  	pn->ctl_table[0].data = &un->timeouts[UDP_CT_UNREPLIED];
  	pn->ctl_table[1].data = &un->timeouts[UDP_CT_REPLIED];
  #endif
  	return 0;
  }
dee7364e0   Gao feng   netfilter: nf_ct_...
269
  static int udp_init_net(struct net *net, u_int16_t proto)
0ce490ad4   Gao feng   netfilter: nf_ct_...
270
  {
0ce490ad4   Gao feng   netfilter: nf_ct_...
271
  	struct nf_udp_net *un = udp_pernet(net);
dee7364e0   Gao feng   netfilter: nf_ct_...
272
  	struct nf_proto_net *pn = &un->pn;
0ce490ad4   Gao feng   netfilter: nf_ct_...
273

dee7364e0   Gao feng   netfilter: nf_ct_...
274
275
  	if (!pn->users) {
  		int i;
0ce490ad4   Gao feng   netfilter: nf_ct_...
276

dee7364e0   Gao feng   netfilter: nf_ct_...
277
278
  		for (i = 0; i < UDP_CT_MAX; i++)
  			un->timeouts[i] = udp_timeouts[i];
0ce490ad4   Gao feng   netfilter: nf_ct_...
279
  	}
0ce490ad4   Gao feng   netfilter: nf_ct_...
280

adf051684   Pablo Neira Ayuso   netfilter: remove...
281
  	return udp_kmemdup_sysctl_table(pn, un);
0ce490ad4   Gao feng   netfilter: nf_ct_...
282
  }
08911475d   Pablo Neira Ayuso   netfilter: nf_con...
283
284
285
286
  static struct nf_proto_net *udp_get_net_proto(struct net *net)
  {
  	return &net->ct.nf_ct_proto.udp.pn;
  }
61075af51   Patrick McHardy   [NETFILTER]: nf_c...
287
  struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly =
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
288
289
  {
  	.l3proto		= PF_INET,
605dcad6c   Martin Josefsson   [NETFILTER]: nf_c...
290
  	.l4proto		= IPPROTO_UDP,
71d8c47fc   Pablo Neira Ayuso   netfilter: conntr...
291
  	.allow_clash		= true,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
292
293
  	.pkt_to_tuple		= udp_pkt_to_tuple,
  	.invert_tuple		= udp_invert_tuple,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
294
  	.packet			= udp_packet,
2c8503f55   Pablo Neira Ayuso   netfilter: nf_con...
295
  	.get_timeouts		= udp_get_timeouts,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
296
  	.new			= udp_new,
96f6bf82e   Patrick McHardy   [NETFILTER]: Conv...
297
  	.error			= udp_error,
c0cd11566   Igor Maravić   net:netfilter: us...
298
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
fdf708322   Patrick McHardy   [NETFILTER]: nfne...
299
300
  	.tuple_to_nlattr	= nf_ct_port_tuple_to_nlattr,
  	.nlattr_to_tuple	= nf_ct_port_nlattr_to_tuple,
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
301
  	.nlattr_tuple_size	= nf_ct_port_nlattr_tuple_size,
f73e924cd   Patrick McHardy   [NETFILTER]: ctne...
302
  	.nla_policy		= nf_ct_port_nla_policy,
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
303
  #endif
509784623   Pablo Neira Ayuso   netfilter: add ct...
304
305
306
307
308
309
310
311
312
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
  	.ctnl_timeout		= {
  		.nlattr_to_obj	= udp_timeout_nlattr_to_obj,
  		.obj_to_nlattr	= udp_timeout_obj_to_nlattr,
  		.nlattr_max	= CTA_TIMEOUT_UDP_MAX,
  		.obj_size	= sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX,
  		.nla_policy	= udp_timeout_nla_policy,
  	},
  #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
dee7364e0   Gao feng   netfilter: nf_ct_...
313
  	.init_net		= udp_init_net,
08911475d   Pablo Neira Ayuso   netfilter: nf_con...
314
  	.get_net_proto		= udp_get_net_proto,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
315
  };
13b183391   Patrick McHardy   [NETFILTER]: nf_c...
316
  EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp4);
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
317

e4781421e   Florian Westphal   netfilter: merge ...
318
319
320
321
322
  #ifdef CONFIG_NF_CT_PROTO_UDPLITE
  struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly =
  {
  	.l3proto		= PF_INET,
  	.l4proto		= IPPROTO_UDPLITE,
e4781421e   Florian Westphal   netfilter: merge ...
323
324
325
  	.allow_clash		= true,
  	.pkt_to_tuple		= udp_pkt_to_tuple,
  	.invert_tuple		= udp_invert_tuple,
e4781421e   Florian Westphal   netfilter: merge ...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
  	.packet			= udp_packet,
  	.get_timeouts		= udp_get_timeouts,
  	.new			= udp_new,
  	.error			= udplite_error,
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
  	.tuple_to_nlattr	= nf_ct_port_tuple_to_nlattr,
  	.nlattr_to_tuple	= nf_ct_port_nlattr_to_tuple,
  	.nlattr_tuple_size	= nf_ct_port_nlattr_tuple_size,
  	.nla_policy		= nf_ct_port_nla_policy,
  #endif
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
  	.ctnl_timeout		= {
  		.nlattr_to_obj	= udp_timeout_nlattr_to_obj,
  		.obj_to_nlattr	= udp_timeout_obj_to_nlattr,
  		.nlattr_max	= CTA_TIMEOUT_UDP_MAX,
  		.obj_size	= sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX,
  		.nla_policy	= udp_timeout_nla_policy,
  	},
  #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
  	.init_net		= udp_init_net,
  	.get_net_proto		= udp_get_net_proto,
  };
  EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udplite4);
  #endif
61075af51   Patrick McHardy   [NETFILTER]: nf_c...
350
  struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 __read_mostly =
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
351
352
  {
  	.l3proto		= PF_INET6,
605dcad6c   Martin Josefsson   [NETFILTER]: nf_c...
353
  	.l4proto		= IPPROTO_UDP,
71d8c47fc   Pablo Neira Ayuso   netfilter: conntr...
354
  	.allow_clash		= true,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
355
356
  	.pkt_to_tuple		= udp_pkt_to_tuple,
  	.invert_tuple		= udp_invert_tuple,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
357
  	.packet			= udp_packet,
2c8503f55   Pablo Neira Ayuso   netfilter: nf_con...
358
  	.get_timeouts		= udp_get_timeouts,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
359
  	.new			= udp_new,
96f6bf82e   Patrick McHardy   [NETFILTER]: Conv...
360
  	.error			= udp_error,
c0cd11566   Igor Maravić   net:netfilter: us...
361
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
fdf708322   Patrick McHardy   [NETFILTER]: nfne...
362
363
  	.tuple_to_nlattr	= nf_ct_port_tuple_to_nlattr,
  	.nlattr_to_tuple	= nf_ct_port_nlattr_to_tuple,
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
364
  	.nlattr_tuple_size	= nf_ct_port_nlattr_tuple_size,
f73e924cd   Patrick McHardy   [NETFILTER]: ctne...
365
  	.nla_policy		= nf_ct_port_nla_policy,
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
366
  #endif
509784623   Pablo Neira Ayuso   netfilter: add ct...
367
368
369
370
371
372
373
374
375
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
  	.ctnl_timeout		= {
  		.nlattr_to_obj	= udp_timeout_nlattr_to_obj,
  		.obj_to_nlattr	= udp_timeout_obj_to_nlattr,
  		.nlattr_max	= CTA_TIMEOUT_UDP_MAX,
  		.obj_size	= sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX,
  		.nla_policy	= udp_timeout_nla_policy,
  	},
  #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
dee7364e0   Gao feng   netfilter: nf_ct_...
376
  	.init_net		= udp_init_net,
08911475d   Pablo Neira Ayuso   netfilter: nf_con...
377
  	.get_net_proto		= udp_get_net_proto,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
378
  };
13b183391   Patrick McHardy   [NETFILTER]: nf_c...
379
  EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp6);
e4781421e   Florian Westphal   netfilter: merge ...
380
381
382
383
384
385
  
  #ifdef CONFIG_NF_CT_PROTO_UDPLITE
  struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly =
  {
  	.l3proto		= PF_INET6,
  	.l4proto		= IPPROTO_UDPLITE,
e4781421e   Florian Westphal   netfilter: merge ...
386
387
388
  	.allow_clash		= true,
  	.pkt_to_tuple		= udp_pkt_to_tuple,
  	.invert_tuple		= udp_invert_tuple,
e4781421e   Florian Westphal   netfilter: merge ...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
  	.packet			= udp_packet,
  	.get_timeouts		= udp_get_timeouts,
  	.new			= udp_new,
  	.error			= udplite_error,
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
  	.tuple_to_nlattr	= nf_ct_port_tuple_to_nlattr,
  	.nlattr_to_tuple	= nf_ct_port_nlattr_to_tuple,
  	.nlattr_tuple_size	= nf_ct_port_nlattr_tuple_size,
  	.nla_policy		= nf_ct_port_nla_policy,
  #endif
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
  	.ctnl_timeout		= {
  		.nlattr_to_obj	= udp_timeout_nlattr_to_obj,
  		.obj_to_nlattr	= udp_timeout_obj_to_nlattr,
  		.nlattr_max	= CTA_TIMEOUT_UDP_MAX,
  		.obj_size	= sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX,
  		.nla_policy	= udp_timeout_nla_policy,
  	},
  #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
  	.init_net		= udp_init_net,
  	.get_net_proto		= udp_get_net_proto,
  };
  EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udplite6);
  #endif