12 #include <linux/types.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>
22 #include <linux/netfilter_ipv6.h>
34 return &net->ct.nf_ct_proto.icmpv6;
37 static bool icmpv6_pkt_to_tuple(
const struct sk_buff *
skb,
44 hp = skb_header_pointer(skb, dataoff,
sizeof(_hdr), &_hdr);
47 tuple->
dst.u.icmp.type = hp->icmp6_type;
48 tuple->
src.u.icmp.id = hp->icmp6_identifier;
49 tuple->
dst.u.icmp.code = hp->icmp6_code;
62 static const u_int8_t noct_valid_new[] = {
76 int type = orig->
dst.u.icmp.type - 128;
80 tuple->
src.u.icmp.id = orig->
src.u.icmp.id;
81 tuple->
dst.u.icmp.type = invmap[
type] - 1;
82 tuple->
dst.u.icmp.code = orig->
dst.u.icmp.code;
87 static int icmpv6_print_tuple(
struct seq_file *
s,
91 tuple->
dst.u.icmp.type,
92 tuple->
dst.u.icmp.code,
96 static unsigned int *icmpv6_get_timeouts(
struct net *
net)
98 return &icmpv6_pernet(net)->timeout;
102 static int icmpv6_packet(
struct nf_conn *
ct,
104 unsigned int dataoff,
108 unsigned int *timeout)
113 nf_ct_refresh_acct(ct, ctinfo, skb, *timeout);
120 unsigned int dataoff,
unsigned int *timeouts)
122 static const u_int8_t valid_new[] = {
126 int type = ct->
tuplehash[0].tuple.dst.u.icmp.type - 128;
130 pr_debug(
"icmpv6: can't create new conn with type %u\n",
132 nf_ct_dump_tuple_ipv6(&ct->
tuplehash[0].tuple);
135 "nf_ct_icmpv6: invalid new with type %d ",
145 unsigned int icmp6off,
158 skb_network_offset(skb)
162 pr_debug(
"icmpv6_error: Can't get tuple\n");
172 &nf_conntrack_l3proto_ipv6, inproto)) {
173 pr_debug(
"icmpv6_error: Can't invert tuple\n");
181 pr_debug(
"icmpv6_error: no match\n");
189 skb->nfct = &nf_ct_tuplehash_to_ctrack(h)->ct_general;
195 icmpv6_error(
struct net *net,
struct nf_conn *tmpl,
196 struct sk_buff *skb,
unsigned int dataoff,
203 icmp6h = skb_header_pointer(skb, dataoff,
sizeof(_ih), &_ih);
204 if (icmp6h ==
NULL) {
207 "nf_ct_icmpv6: short packet ");
215 "nf_ct_icmpv6: ICMPv6 checksum failed ");
220 if (type >= 0 && type <
sizeof(noct_valid_new) &&
221 noct_valid_new[type]) {
222 skb->nfct = &nf_ct_untracked_get()->ct_general;
224 nf_conntrack_get(skb->nfct);
232 return icmpv6_error_message(net, tmpl, skb, dataoff, ctinfo, hooknum);
235 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
237 #include <linux/netfilter/nfnetlink.h>
239 static int icmpv6_tuple_to_nlattr(
struct sk_buff *skb,
245 goto nla_put_failure;
258 static int icmpv6_nlattr_to_tuple(
struct nlattr *
tb[],
268 tuple->
src.u.icmp.id = nla_get_be16(tb[CTA_PROTO_ICMPV6_ID]);
270 if (tuple->
dst.u.icmp.type < 128 ||
271 tuple->
dst.u.icmp.type - 128 >=
sizeof(invmap) ||
272 !invmap[tuple->
dst.u.icmp.type - 128])
278 static int icmpv6_nlattr_tuple_size(
void)
284 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
286 #include <linux/netfilter/nfnetlink.h>
289 static int icmpv6_timeout_nlattr_to_obj(
struct nlattr *tb[],
290 struct net *net,
void *
data)
297 ntohl(nla_get_be32(tb[CTA_TIMEOUT_ICMPV6_TIMEOUT])) *
HZ;
306 icmpv6_timeout_obj_to_nlattr(
struct sk_buff *skb,
const void *data)
308 const unsigned int *timeout =
data;
310 if (nla_put_be32(skb, CTA_TIMEOUT_ICMPV6_TIMEOUT,
htonl(*timeout /
HZ)))
311 goto nla_put_failure;
325 static struct ctl_table icmpv6_sysctl_table[] = {
327 .
procname =
"nf_conntrack_icmpv6_timeout",
328 .maxlen =
sizeof(
unsigned int),
340 pn->ctl_table =
kmemdup(icmpv6_sysctl_table,
341 sizeof(icmpv6_sysctl_table),
346 pn->ctl_table[0].data = &in->
timeout;
356 in->
timeout = nf_ct_icmpv6_timeout;
358 return icmpv6_kmemdup_sysctl_table(pn, in);
361 static struct nf_proto_net *icmpv6_get_net_proto(
struct net *net)
363 return &net->ct.nf_ct_proto.icmpv6.pn;
371 .pkt_to_tuple = icmpv6_pkt_to_tuple,
372 .invert_tuple = icmpv6_invert_tuple,
373 .print_tuple = icmpv6_print_tuple,
374 .packet = icmpv6_packet,
375 .get_timeouts = icmpv6_get_timeouts,
377 .error = icmpv6_error,
378 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
379 .tuple_to_nlattr = icmpv6_tuple_to_nlattr,
380 .nlattr_tuple_size = icmpv6_nlattr_tuple_size,
381 .nlattr_to_tuple = icmpv6_nlattr_to_tuple,
382 .nla_policy = icmpv6_nla_policy,
384 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
386 .nlattr_to_obj = icmpv6_timeout_nlattr_to_obj,
387 .obj_to_nlattr = icmpv6_timeout_obj_to_nlattr,
389 .obj_size =
sizeof(
unsigned int),