Blame view

net/netfilter/nf_conntrack_proto_icmp.c 10 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-2010 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
13
14
15
16
17
18
19
  #include <linux/timer.h>
  #include <linux/netfilter.h>
  #include <linux/in.h>
  #include <linux/icmp.h>
  #include <linux/seq_file.h>
  #include <net/ip.h>
  #include <net/checksum.h>
  #include <linux/netfilter_ipv4.h>
  #include <net/netfilter/nf_conntrack_tuple.h>
605dcad6c   Martin Josefsson   [NETFILTER]: nf_c...
20
  #include <net/netfilter/nf_conntrack_l4proto.h>
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
21
  #include <net/netfilter/nf_conntrack_core.h>
c779e8496   Florian Westphal   netfilter: conntr...
22
  #include <net/netfilter/nf_conntrack_timeout.h>
5d0aa2ccd   Patrick McHardy   netfilter: nf_con...
23
  #include <net/netfilter/nf_conntrack_zones.h>
f01ffbd6e   Patrick McHardy   [NETFILTER]: nf_l...
24
  #include <net/netfilter/nf_log.h>
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
25

2c9e8637e   Florian Westphal   netfilter: conntr...
26
  static const unsigned int nf_ct_icmp_timeout = 30*HZ;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
27

09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
28
  static bool icmp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
a31f1adc0   Eric W. Biederman   netfilter: nf_con...
29
  			      struct net *net, struct nf_conntrack_tuple *tuple)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
30
  {
7cc3864d3   Jan Engelhardt   [NETFILTER]: nf_{...
31
32
  	const struct icmphdr *hp;
  	struct icmphdr _hdr;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
33
34
35
  
  	hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
  	if (hp == NULL)
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
36
  		return false;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
37
38
39
40
  
  	tuple->dst.u.icmp.type = hp->type;
  	tuple->src.u.icmp.id = hp->un.echo.id;
  	tuple->dst.u.icmp.code = hp->code;
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
41
  	return true;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
42
  }
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
43
44
45
46
47
48
49
50
51
52
53
  /* Add 1; spaces filled with 0. */
  static const u_int8_t invmap[] = {
  	[ICMP_ECHO] = ICMP_ECHOREPLY + 1,
  	[ICMP_ECHOREPLY] = ICMP_ECHO + 1,
  	[ICMP_TIMESTAMP] = ICMP_TIMESTAMPREPLY + 1,
  	[ICMP_TIMESTAMPREPLY] = ICMP_TIMESTAMP + 1,
  	[ICMP_INFO_REQUEST] = ICMP_INFO_REPLY + 1,
  	[ICMP_INFO_REPLY] = ICMP_INFO_REQUEST + 1,
  	[ICMP_ADDRESS] = ICMP_ADDRESSREPLY + 1,
  	[ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1
  };
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
54
55
  static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple,
  			      const struct nf_conntrack_tuple *orig)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
56
  {
3666ed1c4   Joe Perches   netfilter: net/ip...
57
58
  	if (orig->dst.u.icmp.type >= sizeof(invmap) ||
  	    !invmap[orig->dst.u.icmp.type])
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
59
  		return false;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
60
61
62
63
  
  	tuple->src.u.icmp.id = orig->src.u.icmp.id;
  	tuple->dst.u.icmp.type = invmap[orig->dst.u.icmp.type] - 1;
  	tuple->dst.u.icmp.code = orig->dst.u.icmp.code;
09f263cd3   Jan Engelhardt   [NETFILTER]: nf_c...
64
  	return true;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
65
  }
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
66
  /* Returns verdict for packet, or -1 for invalid. */
a47c54048   Florian Westphal   netfilter: conntr...
67
68
69
70
  int nf_conntrack_icmp_packet(struct nf_conn *ct,
  			     struct sk_buff *skb,
  			     enum ip_conntrack_info ctinfo,
  			     const struct nf_hook_state *state)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
71
  {
f87fb666b   Jan Kasprzak   netfilter: nf_ct_...
72
73
74
  	/* Do not immediately delete the connection after the first
  	   successful reply to avoid excessive conntrackd traffic
  	   and also to handle correctly ICMP echo reply duplicates. */
c779e8496   Florian Westphal   netfilter: conntr...
75
  	unsigned int *timeout = nf_ct_timeout_lookup(ct);
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
76
77
78
79
80
81
  	static const u_int8_t valid_new[] = {
  		[ICMP_ECHO] = 1,
  		[ICMP_TIMESTAMP] = 1,
  		[ICMP_INFO_REQUEST] = 1,
  		[ICMP_ADDRESS] = 1
  	};
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
82

dd2934a95   Florian Westphal   netfilter: conntr...
83
84
  	if (state->pf != NFPROTO_IPV4)
  		return -NF_ACCEPT;
3666ed1c4   Joe Perches   netfilter: net/ip...
85
86
  	if (ct->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new) ||
  	    !valid_new[ct->tuplehash[0].tuple.dst.u.icmp.type]) {
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
87
  		/* Can't create a new ICMP `conn' with this. */
0d53778e8   Patrick McHardy   [NETFILTER]: Conv...
88
89
  		pr_debug("icmp: can't create new conn with type %u
  ",
c88130bcd   Patrick McHardy   [NETFILTER]: nf_c...
90
  			 ct->tuplehash[0].tuple.dst.u.icmp.type);
3c9fba656   Jan Engelhardt   [NETFILTER]: nf_c...
91
  		nf_ct_dump_tuple_ip(&ct->tuplehash[0].tuple);
9976fc6e6   Florian Westphal   netfilter: conntr...
92
  		return -NF_ACCEPT;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
93
  	}
9976fc6e6   Florian Westphal   netfilter: conntr...
94
95
  
  	if (!timeout)
a95a7774d   Pablo Neira Ayuso   netfilter: conntr...
96
  		timeout = &nf_icmp_pernet(nf_ct_net(ct))->timeout;
9976fc6e6   Florian Westphal   netfilter: conntr...
97
98
99
  
  	nf_ct_refresh_acct(ct, ctinfo, skb, *timeout);
  	return NF_ACCEPT;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
100
  }
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
101
102
  /* Returns conntrack if it dealt with ICMP, and filled in skb fields */
  static int
93e66024b   Florian Westphal   netfilter: conntr...
103
104
  icmp_error_message(struct nf_conn *tmpl, struct sk_buff *skb,
  		   const struct nf_hook_state *state)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
105
106
  {
  	struct nf_conntrack_tuple innertuple, origtuple;
7cc3864d3   Jan Engelhardt   [NETFILTER]: nf_{...
107
108
  	const struct nf_conntrack_l4proto *innerproto;
  	const struct nf_conntrack_tuple_hash *h;
308ac9143   Daniel Borkmann   netfilter: nf_con...
109
  	const struct nf_conntrack_zone *zone;
11df4b760   Florian Westphal   netfilter: conntr...
110
  	enum ip_conntrack_info ctinfo;
5e8018fc6   Daniel Borkmann   netfilter: nf_con...
111
  	struct nf_conntrack_zone tmp;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
112

44d6e2f27   Varsha Rao   net: Replace NF_C...
113
  	WARN_ON(skb_nfct(skb));
5e8018fc6   Daniel Borkmann   netfilter: nf_con...
114
  	zone = nf_ct_zone_tmpl(tmpl, skb, &tmp);
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
115

e2a3123fb   Yasuyuki Kozakai   [NETFILTER]: nf_c...
116
117
118
119
  	/* Are they talking about one of our connections? */
  	if (!nf_ct_get_tuplepr(skb,
  			       skb_network_offset(skb) + ip_hdrlen(skb)
  						       + sizeof(struct icmphdr),
93e66024b   Florian Westphal   netfilter: conntr...
120
  			       PF_INET, state->net, &origtuple)) {
e2a3123fb   Yasuyuki Kozakai   [NETFILTER]: nf_c...
121
122
  		pr_debug("icmp_error_message: failed to get tuple
  ");
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
123
124
  		return -NF_ACCEPT;
  	}
e2361cb90   Aaron Conole   netfilter: Remove...
125
  	/* rcu_read_lock()ed by nf_hook_thresh */
dd2934a95   Florian Westphal   netfilter: conntr...
126
  	innerproto = __nf_ct_l4proto_find(origtuple.dst.protonum);
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
127

e905a9eda   YOSHIFUJI Hideaki   [NET] IPV4: Fix w...
128
129
  	/* Ordinarily, we'd expect the inverted tupleproto, but it's
  	   been preserved inside the ICMP. */
d1b6fe949   Florian Westphal   netfilter: conntr...
130
  	if (!nf_ct_invert_tuple(&innertuple, &origtuple, innerproto)) {
0d53778e8   Patrick McHardy   [NETFILTER]: Conv...
131
132
  		pr_debug("icmp_error_message: no match
  ");
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
133
134
  		return -NF_ACCEPT;
  	}
11df4b760   Florian Westphal   netfilter: conntr...
135
  	ctinfo = IP_CT_RELATED;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
136

93e66024b   Florian Westphal   netfilter: conntr...
137
  	h = nf_conntrack_find_get(state->net, zone, &innertuple);
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
138
  	if (!h) {
130e7a83d   Yasuyuki Kozakai   [NETFILTER]: nf_c...
139
140
141
  		pr_debug("icmp_error_message: no match
  ");
  		return -NF_ACCEPT;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
142
  	}
130e7a83d   Yasuyuki Kozakai   [NETFILTER]: nf_c...
143
  	if (NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY)
11df4b760   Florian Westphal   netfilter: conntr...
144
  		ctinfo += IP_CT_IS_REPLY;
130e7a83d   Yasuyuki Kozakai   [NETFILTER]: nf_c...
145

e905a9eda   YOSHIFUJI Hideaki   [NET] IPV4: Fix w...
146
  	/* Update skb to refer to this connection */
c74454fad   Florian Westphal   netfilter: add an...
147
  	nf_ct_set(skb, nf_ct_tuplehash_to_ctrack(h), ctinfo);
88ed01d17   Pablo Neira Ayuso   netfilter: nf_con...
148
  	return NF_ACCEPT;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
149
  }
93e66024b   Florian Westphal   netfilter: conntr...
150
151
152
  static void icmp_error_log(const struct sk_buff *skb,
  			   const struct nf_hook_state *state,
  			   const char *msg)
c4f3db159   Florian Westphal   netfilter: conntr...
153
  {
93e66024b   Florian Westphal   netfilter: conntr...
154
155
  	nf_l4proto_log_invalid(skb, state->net, state->pf,
  			       IPPROTO_ICMP, "%s", msg);
c4f3db159   Florian Westphal   netfilter: conntr...
156
  }
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
157
  /* Small and modified version of icmp_rcv */
6fe78fa48   Florian Westphal   netfilter: conntr...
158
159
160
  int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
  			      struct sk_buff *skb, unsigned int dataoff,
  			      const struct nf_hook_state *state)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
161
  {
7cc3864d3   Jan Engelhardt   [NETFILTER]: nf_{...
162
163
  	const struct icmphdr *icmph;
  	struct icmphdr _ih;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
164
165
  
  	/* Not enough header? */
c9bdd4b52   Arnaldo Carvalho de Melo   [IP]: Introduce i...
166
  	icmph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_ih), &_ih);
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
167
  	if (icmph == NULL) {
93e66024b   Florian Westphal   netfilter: conntr...
168
  		icmp_error_log(skb, state, "short packet");
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
169
170
171
172
  		return -NF_ACCEPT;
  	}
  
  	/* See ip_conntrack_proto_tcp.c */
93e66024b   Florian Westphal   netfilter: conntr...
173
174
175
176
  	if (state->net->ct.sysctl_checksum &&
  	    state->hook == NF_INET_PRE_ROUTING &&
  	    nf_ip_checksum(skb, state->hook, dataoff, 0)) {
  		icmp_error_log(skb, state, "bad hw icmp checksum");
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
177
  		return -NF_ACCEPT;
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
178
  	}
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
179
180
181
182
183
184
185
  	/*
  	 *	18 is the highest 'known' ICMP type. Anything else is a mystery
  	 *
  	 *	RFC 1122: 3.2.2  Unknown ICMP messages types MUST be silently
  	 *		  discarded.
  	 */
  	if (icmph->type > NR_ICMP_TYPES) {
93e66024b   Florian Westphal   netfilter: conntr...
186
  		icmp_error_log(skb, state, "invalid icmp type");
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
187
188
189
190
  		return -NF_ACCEPT;
  	}
  
  	/* Need to track icmp error message? */
3666ed1c4   Joe Perches   netfilter: net/ip...
191
192
193
194
195
  	if (icmph->type != ICMP_DEST_UNREACH &&
  	    icmph->type != ICMP_SOURCE_QUENCH &&
  	    icmph->type != ICMP_TIME_EXCEEDED &&
  	    icmph->type != ICMP_PARAMETERPROB &&
  	    icmph->type != ICMP_REDIRECT)
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
196
  		return NF_ACCEPT;
93e66024b   Florian Westphal   netfilter: conntr...
197
  	return icmp_error_message(tmpl, skb, state);
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
198
  }
24de3d377   Duan Jiong   netfilter: use IS...
199
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
200
201
202
  
  #include <linux/netfilter/nfnetlink.h>
  #include <linux/netfilter/nfnetlink_conntrack.h>
fdf708322   Patrick McHardy   [NETFILTER]: nfne...
203
  static int icmp_tuple_to_nlattr(struct sk_buff *skb,
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
204
205
  				const struct nf_conntrack_tuple *t)
  {
d317e4f68   David S. Miller   netfilter: ipv4: ...
206
207
208
209
  	if (nla_put_be16(skb, CTA_PROTO_ICMP_ID, t->src.u.icmp.id) ||
  	    nla_put_u8(skb, CTA_PROTO_ICMP_TYPE, t->dst.u.icmp.type) ||
  	    nla_put_u8(skb, CTA_PROTO_ICMP_CODE, t->dst.u.icmp.code))
  		goto nla_put_failure;
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
210
  	return 0;
df6fb868d   Patrick McHardy   [NETFILTER]: nfne...
211
  nla_put_failure:
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
212
213
  	return -1;
  }
f73e924cd   Patrick McHardy   [NETFILTER]: ctne...
214
215
216
217
  static const struct nla_policy icmp_nla_policy[CTA_PROTO_MAX+1] = {
  	[CTA_PROTO_ICMP_TYPE]	= { .type = NLA_U8 },
  	[CTA_PROTO_ICMP_CODE]	= { .type = NLA_U8 },
  	[CTA_PROTO_ICMP_ID]	= { .type = NLA_U16 },
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
218
  };
fdf708322   Patrick McHardy   [NETFILTER]: nfne...
219
  static int icmp_nlattr_to_tuple(struct nlattr *tb[],
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
220
221
  				struct nf_conntrack_tuple *tuple)
  {
3666ed1c4   Joe Perches   netfilter: net/ip...
222
223
224
  	if (!tb[CTA_PROTO_ICMP_TYPE] ||
  	    !tb[CTA_PROTO_ICMP_CODE] ||
  	    !tb[CTA_PROTO_ICMP_ID])
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
225
  		return -EINVAL;
77236b6e3   Patrick McHardy   [NETFILTER]: ctne...
226
227
228
  	tuple->dst.u.icmp.type = nla_get_u8(tb[CTA_PROTO_ICMP_TYPE]);
  	tuple->dst.u.icmp.code = nla_get_u8(tb[CTA_PROTO_ICMP_CODE]);
  	tuple->src.u.icmp.id = nla_get_be16(tb[CTA_PROTO_ICMP_ID]);
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
229

3666ed1c4   Joe Perches   netfilter: net/ip...
230
231
  	if (tuple->dst.u.icmp.type >= sizeof(invmap) ||
  	    !invmap[tuple->dst.u.icmp.type])
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
232
233
234
235
  		return -EINVAL;
  
  	return 0;
  }
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
236

5caaed151   Florian Westphal   netfilter: conntr...
237
  static unsigned int icmp_nlattr_tuple_size(void)
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
238
  {
5caaed151   Florian Westphal   netfilter: conntr...
239
240
241
242
243
244
  	static unsigned int size __read_mostly;
  
  	if (!size)
  		size = nla_policy_len(icmp_nla_policy, CTA_PROTO_MAX + 1);
  
  	return size;
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
245
  }
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
246
  #endif
a874752a1   Pablo Neira Ayuso   netfilter: conntr...
247
  #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
509784623   Pablo Neira Ayuso   netfilter: add ct...
248
249
250
  
  #include <linux/netfilter/nfnetlink.h>
  #include <linux/netfilter/nfnetlink_cttimeout.h>
8264deb81   Gao feng   netfilter: nf_con...
251
252
  static int icmp_timeout_nlattr_to_obj(struct nlattr *tb[],
  				      struct net *net, void *data)
509784623   Pablo Neira Ayuso   netfilter: add ct...
253
254
  {
  	unsigned int *timeout = data;
a95a7774d   Pablo Neira Ayuso   netfilter: conntr...
255
  	struct nf_icmp_net *in = nf_icmp_pernet(net);
509784623   Pablo Neira Ayuso   netfilter: add ct...
256
257
  
  	if (tb[CTA_TIMEOUT_ICMP_TIMEOUT]) {
c779e8496   Florian Westphal   netfilter: conntr...
258
259
  		if (!timeout)
  			timeout = &in->timeout;
509784623   Pablo Neira Ayuso   netfilter: add ct...
260
261
  		*timeout =
  			ntohl(nla_get_be32(tb[CTA_TIMEOUT_ICMP_TIMEOUT])) * HZ;
c779e8496   Florian Westphal   netfilter: conntr...
262
  	} else if (timeout) {
509784623   Pablo Neira Ayuso   netfilter: add ct...
263
  		/* Set default ICMP timeout. */
8264deb81   Gao feng   netfilter: nf_con...
264
  		*timeout = in->timeout;
509784623   Pablo Neira Ayuso   netfilter: add ct...
265
266
267
268
269
270
271
272
  	}
  	return 0;
  }
  
  static int
  icmp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
  {
  	const unsigned int *timeout = data;
d317e4f68   David S. Miller   netfilter: ipv4: ...
273
274
  	if (nla_put_be32(skb, CTA_TIMEOUT_ICMP_TIMEOUT, htonl(*timeout / HZ)))
  		goto nla_put_failure;
509784623   Pablo Neira Ayuso   netfilter: add ct...
275
276
277
278
279
280
281
282
283
284
  	return 0;
  
  nla_put_failure:
  	return -ENOSPC;
  }
  
  static const struct nla_policy
  icmp_timeout_nla_policy[CTA_TIMEOUT_ICMP_MAX+1] = {
  	[CTA_TIMEOUT_ICMP_TIMEOUT]	= { .type = NLA_U32 },
  };
a874752a1   Pablo Neira Ayuso   netfilter: conntr...
285
  #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
509784623   Pablo Neira Ayuso   netfilter: add ct...
286

933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
287
  #ifdef CONFIG_SYSCTL
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
288
289
  static struct ctl_table icmp_sysctl_table[] = {
  	{
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
290
  		.procname	= "nf_conntrack_icmp_timeout",
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
291
292
  		.maxlen		= sizeof(unsigned int),
  		.mode		= 0644,
6d9f239a1   Alexey Dobriyan   net: '&' redux
293
  		.proc_handler	= proc_dointvec_jiffies,
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
294
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
295
  	{ }
933a41e7e   Patrick McHardy   [NETFILTER]: nf_c...
296
297
  };
  #endif /* CONFIG_SYSCTL */
a9082b45a   Gao feng   netfilter: nf_ct_...
298
299
  static int icmp_kmemdup_sysctl_table(struct nf_proto_net *pn,
  				     struct nf_icmp_net *in)
4b626b9c5   Gao feng   netfilter: nf_ct_...
300
  {
4b626b9c5   Gao feng   netfilter: nf_ct_...
301
302
303
304
305
306
  #ifdef CONFIG_SYSCTL
  	pn->ctl_table = kmemdup(icmp_sysctl_table,
  				sizeof(icmp_sysctl_table),
  				GFP_KERNEL);
  	if (!pn->ctl_table)
  		return -ENOMEM;
a9082b45a   Gao feng   netfilter: nf_ct_...
307

4b626b9c5   Gao feng   netfilter: nf_ct_...
308
  	pn->ctl_table[0].data = &in->timeout;
a9082b45a   Gao feng   netfilter: nf_ct_...
309
310
311
  #endif
  	return 0;
  }
ca2ca6e1c   Florian Westphal   netfilter: conntr...
312
  static int icmp_init_net(struct net *net)
a9082b45a   Gao feng   netfilter: nf_ct_...
313
  {
a95a7774d   Pablo Neira Ayuso   netfilter: conntr...
314
  	struct nf_icmp_net *in = nf_icmp_pernet(net);
a9082b45a   Gao feng   netfilter: nf_ct_...
315
316
317
  	struct nf_proto_net *pn = &in->pn;
  
  	in->timeout = nf_ct_icmp_timeout;
adf051684   Pablo Neira Ayuso   netfilter: remove...
318
  	return icmp_kmemdup_sysctl_table(pn, in);
a9082b45a   Gao feng   netfilter: nf_ct_...
319
  }
08911475d   Pablo Neira Ayuso   netfilter: nf_con...
320
321
322
323
  static struct nf_proto_net *icmp_get_net_proto(struct net *net)
  {
  	return &net->ct.nf_ct_proto.icmp.pn;
  }
9dae47aba   Florian Westphal   netfilter: conntr...
324
  const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp =
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
325
  {
605dcad6c   Martin Josefsson   [NETFILTER]: nf_c...
326
  	.l4proto		= IPPROTO_ICMP,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
327
328
  	.pkt_to_tuple		= icmp_pkt_to_tuple,
  	.invert_tuple		= icmp_invert_tuple,
24de3d377   Duan Jiong   netfilter: use IS...
329
  #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
fdf708322   Patrick McHardy   [NETFILTER]: nfne...
330
  	.tuple_to_nlattr	= icmp_tuple_to_nlattr,
a400c30ed   Holger Eitzenberger   netfilter: nf_con...
331
  	.nlattr_tuple_size	= icmp_nlattr_tuple_size,
fdf708322   Patrick McHardy   [NETFILTER]: nfne...
332
  	.nlattr_to_tuple	= icmp_nlattr_to_tuple,
f73e924cd   Patrick McHardy   [NETFILTER]: ctne...
333
  	.nla_policy		= icmp_nla_policy,
c1d10adb4   Pablo Neira Ayuso   [NETFILTER]: Add ...
334
  #endif
a874752a1   Pablo Neira Ayuso   netfilter: conntr...
335
  #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
509784623   Pablo Neira Ayuso   netfilter: add ct...
336
337
338
339
340
341
342
  	.ctnl_timeout		= {
  		.nlattr_to_obj	= icmp_timeout_nlattr_to_obj,
  		.obj_to_nlattr	= icmp_timeout_obj_to_nlattr,
  		.nlattr_max	= CTA_TIMEOUT_ICMP_MAX,
  		.obj_size	= sizeof(unsigned int),
  		.nla_policy	= icmp_timeout_nla_policy,
  	},
a874752a1   Pablo Neira Ayuso   netfilter: conntr...
343
  #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
4b626b9c5   Gao feng   netfilter: nf_ct_...
344
  	.init_net		= icmp_init_net,
08911475d   Pablo Neira Ayuso   netfilter: nf_con...
345
  	.get_net_proto		= icmp_get_net_proto,
9fb9cbb10   Yasuyuki Kozakai   [NETFILTER]: Add ...
346
  };