blob: f5a61bc3ec2b3b5bfd9ce75c3646a37598b9b71f [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/*
2 * Copyright (C)2003,2004 USAGI/WIDE Project
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * Author:
9 * Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080010 */
11
12#include <linux/types.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080013#include <linux/timer.h>
14#include <linux/module.h>
15#include <linux/netfilter.h>
16#include <linux/in6.h>
17#include <linux/icmpv6.h>
18#include <linux/ipv6.h>
19#include <net/ipv6.h>
20#include <net/ip6_checksum.h>
21#include <linux/seq_file.h>
22#include <linux/netfilter_ipv6.h>
23#include <net/netfilter/nf_conntrack_tuple.h>
Martin Josefsson605dcad2006-11-29 02:35:06 +010024#include <net/netfilter/nf_conntrack_l4proto.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080025#include <net/netfilter/nf_conntrack_core.h>
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010026#include <net/netfilter/nf_conntrack_zones.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080027#include <net/netfilter/ipv6/nf_conntrack_icmpv6.h>
Patrick McHardyf01ffbd2007-12-17 22:38:49 -080028#include <net/netfilter/nf_log.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080029
Patrick McHardy71320af2009-01-12 00:06:07 +000030static unsigned int nf_ct_icmpv6_timeout __read_mostly = 30*HZ;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080031
Gao feng7080ba02012-05-28 21:04:15 +000032static inline struct nf_icmp_net *icmpv6_pernet(struct net *net)
33{
34 return &net->ct.nf_ct_proto.icmpv6;
35}
36
Jan Engelhardt09f263c2008-04-14 11:15:53 +020037static bool icmpv6_pkt_to_tuple(const struct sk_buff *skb,
38 unsigned int dataoff,
Eric W. Biedermana31f1ad2015-09-18 14:33:04 -050039 struct net *net,
Jan Engelhardt09f263c2008-04-14 11:15:53 +020040 struct nf_conntrack_tuple *tuple)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080041{
Jan Engelhardt7cc38642008-01-31 04:53:05 -080042 const struct icmp6hdr *hp;
43 struct icmp6hdr _hdr;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080044
45 hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
46 if (hp == NULL)
Jan Engelhardt09f263c2008-04-14 11:15:53 +020047 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080048 tuple->dst.u.icmp.type = hp->icmp6_type;
49 tuple->src.u.icmp.id = hp->icmp6_identifier;
50 tuple->dst.u.icmp.code = hp->icmp6_code;
51
Jan Engelhardt09f263c2008-04-14 11:15:53 +020052 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080053}
54
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080055/* Add 1; spaces filled with 0. */
Jan Engelhardt7cc38642008-01-31 04:53:05 -080056static const u_int8_t invmap[] = {
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080057 [ICMPV6_ECHO_REQUEST - 128] = ICMPV6_ECHO_REPLY + 1,
58 [ICMPV6_ECHO_REPLY - 128] = ICMPV6_ECHO_REQUEST + 1,
Eric Leblonda51f42f2009-02-09 14:33:03 -080059 [ICMPV6_NI_QUERY - 128] = ICMPV6_NI_REPLY + 1,
Ian Morrisf9527ea2015-10-11 17:32:17 +010060 [ICMPV6_NI_REPLY - 128] = ICMPV6_NI_QUERY + 1
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080061};
62
Eric Leblond3f900712009-02-09 14:33:20 -080063static const u_int8_t noct_valid_new[] = {
64 [ICMPV6_MGM_QUERY - 130] = 1,
Ian Morrisf9527ea2015-10-11 17:32:17 +010065 [ICMPV6_MGM_REPORT - 130] = 1,
Eric Leblond3f900712009-02-09 14:33:20 -080066 [ICMPV6_MGM_REDUCTION - 130] = 1,
67 [NDISC_ROUTER_SOLICITATION - 130] = 1,
68 [NDISC_ROUTER_ADVERTISEMENT - 130] = 1,
69 [NDISC_NEIGHBOUR_SOLICITATION - 130] = 1,
70 [NDISC_NEIGHBOUR_ADVERTISEMENT - 130] = 1,
71 [ICMPV6_MLD2_REPORT - 130] = 1
72};
73
Jan Engelhardt09f263c2008-04-14 11:15:53 +020074static bool icmpv6_invert_tuple(struct nf_conntrack_tuple *tuple,
75 const struct nf_conntrack_tuple *orig)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080076{
Yasuyuki Kozakaif16c9102005-12-05 13:32:50 -080077 int type = orig->dst.u.icmp.type - 128;
78 if (type < 0 || type >= sizeof(invmap) || !invmap[type])
Jan Engelhardt09f263c2008-04-14 11:15:53 +020079 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080080
81 tuple->src.u.icmp.id = orig->src.u.icmp.id;
82 tuple->dst.u.icmp.type = invmap[type] - 1;
83 tuple->dst.u.icmp.code = orig->dst.u.icmp.code;
Jan Engelhardt09f263c2008-04-14 11:15:53 +020084 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080085}
86
87/* Print out the per-protocol part of the tuple. */
Joe Perches824f1fb2014-09-29 16:08:22 -070088static void icmpv6_print_tuple(struct seq_file *s,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080089 const struct nf_conntrack_tuple *tuple)
90{
Joe Perches824f1fb2014-09-29 16:08:22 -070091 seq_printf(s, "type=%u code=%u id=%u ",
92 tuple->dst.u.icmp.type,
93 tuple->dst.u.icmp.code,
94 ntohs(tuple->src.u.icmp.id));
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080095}
96
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010097static unsigned int *icmpv6_get_timeouts(struct net *net)
98{
Gao feng7080ba02012-05-28 21:04:15 +000099 return &icmpv6_pernet(net)->timeout;
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100100}
101
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800102/* Returns verdict for packet, or -1 for invalid. */
103static int icmpv6_packet(struct nf_conn *ct,
104 const struct sk_buff *skb,
105 unsigned int dataoff,
106 enum ip_conntrack_info ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200107 u_int8_t pf,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100108 unsigned int hooknum,
109 unsigned int *timeout)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800110{
Jan Kasprzakf87fb662009-06-08 15:53:43 +0200111 /* Do not immediately delete the connection after the first
112 successful reply to avoid excessive conntrackd traffic
113 and also to handle correctly ICMP echo reply duplicates. */
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100114 nf_ct_refresh_acct(ct, ctinfo, skb, *timeout);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800115
116 return NF_ACCEPT;
117}
118
119/* Called when a new connection for this protocol found. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200120static bool icmpv6_new(struct nf_conn *ct, const struct sk_buff *skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100121 unsigned int dataoff, unsigned int *timeouts)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800122{
Jan Engelhardt7cc38642008-01-31 04:53:05 -0800123 static const u_int8_t valid_new[] = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800124 [ICMPV6_ECHO_REQUEST - 128] = 1,
125 [ICMPV6_NI_QUERY - 128] = 1
126 };
Patrick McHardyc88130b2008-01-31 04:42:11 -0800127 int type = ct->tuplehash[0].tuple.dst.u.icmp.type - 128;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800128
Yasuyuki Kozakaif16c9102005-12-05 13:32:50 -0800129 if (type < 0 || type >= sizeof(valid_new) || !valid_new[type]) {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800130 /* Can't create a new ICMPv6 `conn' with this. */
Patrick McHardy0d537782007-07-07 22:39:38 -0700131 pr_debug("icmpv6: can't create new conn with type %u\n",
132 type + 128);
Jan Engelhardt3c9fba62008-04-14 11:15:54 +0200133 nf_ct_dump_tuple_ipv6(&ct->tuplehash[0].tuple);
Eric Leblond55df4ac2009-02-18 16:30:56 +0100134 if (LOG_INVALID(nf_ct_net(ct), IPPROTO_ICMPV6))
Gao feng30e0c6a2013-03-24 23:50:40 +0000135 nf_log_packet(nf_ct_net(ct), PF_INET6, 0, skb, NULL,
136 NULL, NULL,
Eric Leblond55df4ac2009-02-18 16:30:56 +0100137 "nf_ct_icmpv6: invalid new with type %d ",
138 type + 128);
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200139 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800140 }
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200141 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800142}
143
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800144static int
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +0100145icmpv6_error_message(struct net *net, struct nf_conn *tmpl,
Alexey Dobriyan74c51a12008-10-08 11:35:05 +0200146 struct sk_buff *skb,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800147 unsigned int icmp6off,
148 enum ip_conntrack_info *ctinfo,
149 unsigned int hooknum)
150{
151 struct nf_conntrack_tuple intuple, origtuple;
Jan Engelhardt7cc38642008-01-31 04:53:05 -0800152 const struct nf_conntrack_tuple_hash *h;
153 const struct nf_conntrack_l4proto *inproto;
Daniel Borkmann5e8018f2015-08-14 16:03:40 +0200154 struct nf_conntrack_zone tmp;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800155
156 NF_CT_ASSERT(skb->nfct == NULL);
157
Yasuyuki Kozakaie2a31232007-07-14 20:45:14 -0700158 /* Are they talking about one of our connections? */
159 if (!nf_ct_get_tuplepr(skb,
160 skb_network_offset(skb)
161 + sizeof(struct ipv6hdr)
162 + sizeof(struct icmp6hdr),
Eric W. Biedermana31f1ad2015-09-18 14:33:04 -0500163 PF_INET6, net, &origtuple)) {
Yasuyuki Kozakaie2a31232007-07-14 20:45:14 -0700164 pr_debug("icmpv6_error: Can't get tuple\n");
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800165 return -NF_ACCEPT;
166 }
167
Aaron Conolee2361cb2016-09-21 11:35:04 -0400168 /* rcu_read_lock()ed by nf_hook_thresh */
Yasuyuki Kozakaie2a31232007-07-14 20:45:14 -0700169 inproto = __nf_ct_l4proto_find(PF_INET6, origtuple.dst.protonum);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800170
171 /* Ordinarily, we'd expect the inverted tupleproto, but it's
172 been preserved inside the ICMP. */
173 if (!nf_ct_invert_tuple(&intuple, &origtuple,
174 &nf_conntrack_l3proto_ipv6, inproto)) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700175 pr_debug("icmpv6_error: Can't invert tuple\n");
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800176 return -NF_ACCEPT;
177 }
178
179 *ctinfo = IP_CT_RELATED;
180
Daniel Borkmann5e8018f2015-08-14 16:03:40 +0200181 h = nf_conntrack_find_get(net, nf_ct_zone_tmpl(tmpl, skb, &tmp),
182 &intuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800183 if (!h) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700184 pr_debug("icmpv6_error: no match\n");
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800185 return -NF_ACCEPT;
186 } else {
187 if (NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY)
188 *ctinfo += IP_CT_IS_REPLY;
189 }
190
191 /* Update skb to refer to this connection */
192 skb->nfct = &nf_ct_tuplehash_to_ctrack(h)->ct_general;
193 skb->nfctinfo = *ctinfo;
Pablo Neira Ayuso88ed01d2011-06-02 15:08:45 +0200194 return NF_ACCEPT;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800195}
196
197static int
Patrick McHardy8fea97e2010-02-15 17:45:08 +0100198icmpv6_error(struct net *net, struct nf_conn *tmpl,
199 struct sk_buff *skb, unsigned int dataoff,
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200200 enum ip_conntrack_info *ctinfo, u_int8_t pf, unsigned int hooknum)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800201{
Jan Engelhardt7cc38642008-01-31 04:53:05 -0800202 const struct icmp6hdr *icmp6h;
203 struct icmp6hdr _ih;
Eric Leblond3f900712009-02-09 14:33:20 -0800204 int type;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800205
206 icmp6h = skb_header_pointer(skb, dataoff, sizeof(_ih), &_ih);
207 if (icmp6h == NULL) {
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200208 if (LOG_INVALID(net, IPPROTO_ICMPV6))
Gao feng30e0c6a2013-03-24 23:50:40 +0000209 nf_log_packet(net, PF_INET6, 0, skb, NULL, NULL, NULL,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800210 "nf_ct_icmpv6: short packet ");
211 return -NF_ACCEPT;
212 }
213
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200214 if (net->ct.sysctl_checksum && hooknum == NF_INET_PRE_ROUTING &&
Patrick McHardy96f6bf82006-04-06 14:19:24 -0700215 nf_ip6_checksum(skb, hooknum, dataoff, IPPROTO_ICMPV6)) {
Eric Leblond4aa3b2e2009-02-18 15:28:46 +0100216 if (LOG_INVALID(net, IPPROTO_ICMPV6))
Gao feng30e0c6a2013-03-24 23:50:40 +0000217 nf_log_packet(net, PF_INET6, 0, skb, NULL, NULL, NULL,
Eric Leblond4aa3b2e2009-02-18 15:28:46 +0100218 "nf_ct_icmpv6: ICMPv6 checksum failed ");
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800219 return -NF_ACCEPT;
220 }
221
Eric Leblond3f900712009-02-09 14:33:20 -0800222 type = icmp6h->icmp6_type - 130;
223 if (type >= 0 && type < sizeof(noct_valid_new) &&
224 noct_valid_new[type]) {
Eric Dumazet5bfddbd2010-06-08 16:09:52 +0200225 skb->nfct = &nf_ct_untracked_get()->ct_general;
Eric Leblond3f900712009-02-09 14:33:20 -0800226 skb->nfctinfo = IP_CT_NEW;
227 nf_conntrack_get(skb->nfct);
228 return NF_ACCEPT;
229 }
230
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800231 /* is not error message ? */
232 if (icmp6h->icmp6_type >= 128)
233 return NF_ACCEPT;
234
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +0100235 return icmpv6_error_message(net, tmpl, skb, dataoff, ctinfo, hooknum);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800236}
237
Amerigo Wang07a93622012-10-29 16:23:10 +0000238#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800239
240#include <linux/netfilter/nfnetlink.h>
241#include <linux/netfilter/nfnetlink_conntrack.h>
Patrick McHardyfdf70832007-09-28 14:37:41 -0700242static int icmpv6_tuple_to_nlattr(struct sk_buff *skb,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800243 const struct nf_conntrack_tuple *t)
244{
David S. Millere549a6b2012-04-01 20:28:52 -0400245 if (nla_put_be16(skb, CTA_PROTO_ICMPV6_ID, t->src.u.icmp.id) ||
246 nla_put_u8(skb, CTA_PROTO_ICMPV6_TYPE, t->dst.u.icmp.type) ||
247 nla_put_u8(skb, CTA_PROTO_ICMPV6_CODE, t->dst.u.icmp.code))
248 goto nla_put_failure;
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800249 return 0;
250
Patrick McHardydf6fb862007-09-28 14:37:03 -0700251nla_put_failure:
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800252 return -1;
253}
254
Patrick McHardyf73e9242007-09-28 14:39:55 -0700255static const struct nla_policy icmpv6_nla_policy[CTA_PROTO_MAX+1] = {
256 [CTA_PROTO_ICMPV6_TYPE] = { .type = NLA_U8 },
257 [CTA_PROTO_ICMPV6_CODE] = { .type = NLA_U8 },
258 [CTA_PROTO_ICMPV6_ID] = { .type = NLA_U16 },
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800259};
260
Patrick McHardyfdf70832007-09-28 14:37:41 -0700261static int icmpv6_nlattr_to_tuple(struct nlattr *tb[],
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800262 struct nf_conntrack_tuple *tuple)
263{
Joe Perches3666ed12009-11-23 23:17:06 +0100264 if (!tb[CTA_PROTO_ICMPV6_TYPE] ||
265 !tb[CTA_PROTO_ICMPV6_CODE] ||
266 !tb[CTA_PROTO_ICMPV6_ID])
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800267 return -EINVAL;
268
Patrick McHardy77236b62007-12-17 22:29:45 -0800269 tuple->dst.u.icmp.type = nla_get_u8(tb[CTA_PROTO_ICMPV6_TYPE]);
270 tuple->dst.u.icmp.code = nla_get_u8(tb[CTA_PROTO_ICMPV6_CODE]);
271 tuple->src.u.icmp.id = nla_get_be16(tb[CTA_PROTO_ICMPV6_ID]);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800272
Joe Perches3666ed12009-11-23 23:17:06 +0100273 if (tuple->dst.u.icmp.type < 128 ||
274 tuple->dst.u.icmp.type - 128 >= sizeof(invmap) ||
275 !invmap[tuple->dst.u.icmp.type - 128])
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800276 return -EINVAL;
277
278 return 0;
279}
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100280
281static int icmpv6_nlattr_tuple_size(void)
282{
283 return nla_policy_len(icmpv6_nla_policy, CTA_PROTO_MAX + 1);
284}
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800285#endif
286
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100287#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
288
289#include <linux/netfilter/nfnetlink.h>
290#include <linux/netfilter/nfnetlink_cttimeout.h>
291
Gao feng8264deb2012-05-28 21:04:23 +0000292static int icmpv6_timeout_nlattr_to_obj(struct nlattr *tb[],
293 struct net *net, void *data)
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100294{
295 unsigned int *timeout = data;
Gao feng8264deb2012-05-28 21:04:23 +0000296 struct nf_icmp_net *in = icmpv6_pernet(net);
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100297
298 if (tb[CTA_TIMEOUT_ICMPV6_TIMEOUT]) {
299 *timeout =
300 ntohl(nla_get_be32(tb[CTA_TIMEOUT_ICMPV6_TIMEOUT])) * HZ;
301 } else {
302 /* Set default ICMPv6 timeout. */
Gao feng8264deb2012-05-28 21:04:23 +0000303 *timeout = in->timeout;
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100304 }
305 return 0;
306}
307
308static int
309icmpv6_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
310{
311 const unsigned int *timeout = data;
312
David S. Millere549a6b2012-04-01 20:28:52 -0400313 if (nla_put_be32(skb, CTA_TIMEOUT_ICMPV6_TIMEOUT, htonl(*timeout / HZ)))
314 goto nla_put_failure;
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100315 return 0;
316
317nla_put_failure:
318 return -ENOSPC;
319}
320
321static const struct nla_policy
322icmpv6_timeout_nla_policy[CTA_TIMEOUT_ICMPV6_MAX+1] = {
323 [CTA_TIMEOUT_ICMPV6_TIMEOUT] = { .type = NLA_U32 },
324};
325#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
326
Patrick McHardy933a41e2006-11-29 02:35:18 +0100327#ifdef CONFIG_SYSCTL
Patrick McHardy933a41e2006-11-29 02:35:18 +0100328static struct ctl_table icmpv6_sysctl_table[] = {
329 {
Patrick McHardy933a41e2006-11-29 02:35:18 +0100330 .procname = "nf_conntrack_icmpv6_timeout",
Patrick McHardy933a41e2006-11-29 02:35:18 +0100331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800333 .proc_handler = proc_dointvec_jiffies,
Patrick McHardy933a41e2006-11-29 02:35:18 +0100334 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800335 { }
Patrick McHardy933a41e2006-11-29 02:35:18 +0100336};
337#endif /* CONFIG_SYSCTL */
338
Gao feng8fc02782012-06-21 04:36:50 +0000339static int icmpv6_kmemdup_sysctl_table(struct nf_proto_net *pn,
340 struct nf_icmp_net *in)
Gao feng7080ba02012-05-28 21:04:15 +0000341{
Gao feng7080ba02012-05-28 21:04:15 +0000342#ifdef CONFIG_SYSCTL
343 pn->ctl_table = kmemdup(icmpv6_sysctl_table,
344 sizeof(icmpv6_sysctl_table),
345 GFP_KERNEL);
346 if (!pn->ctl_table)
347 return -ENOMEM;
Gao feng8fc02782012-06-21 04:36:50 +0000348
Gao feng7080ba02012-05-28 21:04:15 +0000349 pn->ctl_table[0].data = &in->timeout;
350#endif
351 return 0;
352}
353
Gao feng8fc02782012-06-21 04:36:50 +0000354static int icmpv6_init_net(struct net *net, u_int16_t proto)
355{
356 struct nf_icmp_net *in = icmpv6_pernet(net);
357 struct nf_proto_net *pn = &in->pn;
358
359 in->timeout = nf_ct_icmpv6_timeout;
360
361 return icmpv6_kmemdup_sysctl_table(pn, in);
362}
363
Pablo Neira Ayuso08911472012-06-29 05:23:24 +0000364static struct nf_proto_net *icmpv6_get_net_proto(struct net *net)
365{
366 return &net->ct.nf_ct_proto.icmpv6.pn;
367}
368
Patrick McHardy61075af2007-07-14 20:48:19 -0700369struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 __read_mostly =
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800370{
371 .l3proto = PF_INET6,
Martin Josefsson605dcad2006-11-29 02:35:06 +0100372 .l4proto = IPPROTO_ICMPV6,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800373 .name = "icmpv6",
374 .pkt_to_tuple = icmpv6_pkt_to_tuple,
375 .invert_tuple = icmpv6_invert_tuple,
376 .print_tuple = icmpv6_print_tuple,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800377 .packet = icmpv6_packet,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100378 .get_timeouts = icmpv6_get_timeouts,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800379 .new = icmpv6_new,
380 .error = icmpv6_error,
Amerigo Wang07a93622012-10-29 16:23:10 +0000381#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
Patrick McHardyfdf70832007-09-28 14:37:41 -0700382 .tuple_to_nlattr = icmpv6_tuple_to_nlattr,
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100383 .nlattr_tuple_size = icmpv6_nlattr_tuple_size,
Patrick McHardyfdf70832007-09-28 14:37:41 -0700384 .nlattr_to_tuple = icmpv6_nlattr_to_tuple,
Patrick McHardyf73e9242007-09-28 14:39:55 -0700385 .nla_policy = icmpv6_nla_policy,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800386#endif
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100387#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
388 .ctnl_timeout = {
389 .nlattr_to_obj = icmpv6_timeout_nlattr_to_obj,
390 .obj_to_nlattr = icmpv6_timeout_obj_to_nlattr,
391 .nlattr_max = CTA_TIMEOUT_ICMP_MAX,
392 .obj_size = sizeof(unsigned int),
393 .nla_policy = icmpv6_timeout_nla_policy,
394 },
395#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
Gao feng7080ba02012-05-28 21:04:15 +0000396 .init_net = icmpv6_init_net,
Pablo Neira Ayuso08911472012-06-29 05:23:24 +0000397 .get_net_proto = icmpv6_get_net_proto,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800398};