~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv6/netfilter/nf_nat_proto_icmpv6.c

Version: ~ [ linux-5.10-rc5 ] ~ [ linux-5.9.10 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.79 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.159 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.208 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.245 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.245 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (c) 2011 Patrick Mchardy <kaber@trash.net>
  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  * Based on Rusty Russell's IPv4 ICMP NAT code. Development of IPv6
  9  * NAT funded by Astaro.
 10  */
 11 
 12 #include <linux/types.h>
 13 #include <linux/init.h>
 14 #include <linux/icmpv6.h>
 15 
 16 #include <linux/netfilter.h>
 17 #include <net/netfilter/nf_nat.h>
 18 #include <net/netfilter/nf_nat_core.h>
 19 #include <net/netfilter/nf_nat_l3proto.h>
 20 #include <net/netfilter/nf_nat_l4proto.h>
 21 
 22 static bool
 23 icmpv6_in_range(const struct nf_conntrack_tuple *tuple,
 24                 enum nf_nat_manip_type maniptype,
 25                 const union nf_conntrack_man_proto *min,
 26                 const union nf_conntrack_man_proto *max)
 27 {
 28         return ntohs(tuple->src.u.icmp.id) >= ntohs(min->icmp.id) &&
 29                ntohs(tuple->src.u.icmp.id) <= ntohs(max->icmp.id);
 30 }
 31 
 32 static void
 33 icmpv6_unique_tuple(const struct nf_nat_l3proto *l3proto,
 34                     struct nf_conntrack_tuple *tuple,
 35                     const struct nf_nat_range *range,
 36                     enum nf_nat_manip_type maniptype,
 37                     const struct nf_conn *ct)
 38 {
 39         static u16 id;
 40         unsigned int range_size;
 41         unsigned int i;
 42 
 43         range_size = ntohs(range->max_proto.icmp.id) -
 44                      ntohs(range->min_proto.icmp.id) + 1;
 45 
 46         if (!(range->flags & NF_NAT_RANGE_PROTO_SPECIFIED))
 47                 range_size = 0xffff;
 48 
 49         for (i = 0; ; ++id) {
 50                 tuple->src.u.icmp.id = htons(ntohs(range->min_proto.icmp.id) +
 51                                              (id % range_size));
 52                 if (++i == range_size || !nf_nat_used_tuple(tuple, ct))
 53                         return;
 54         }
 55 }
 56 
 57 static bool
 58 icmpv6_manip_pkt(struct sk_buff *skb,
 59                  const struct nf_nat_l3proto *l3proto,
 60                  unsigned int iphdroff, unsigned int hdroff,
 61                  const struct nf_conntrack_tuple *tuple,
 62                  enum nf_nat_manip_type maniptype)
 63 {
 64         struct icmp6hdr *hdr;
 65 
 66         if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
 67                 return false;
 68 
 69         hdr = (struct icmp6hdr *)(skb->data + hdroff);
 70         l3proto->csum_update(skb, iphdroff, &hdr->icmp6_cksum,
 71                              tuple, maniptype);
 72         if (hdr->icmp6_type == ICMPV6_ECHO_REQUEST ||
 73             hdr->icmp6_type == ICMPV6_ECHO_REPLY) {
 74                 inet_proto_csum_replace2(&hdr->icmp6_cksum, skb,
 75                                          hdr->icmp6_identifier,
 76                                          tuple->src.u.icmp.id, 0);
 77                 hdr->icmp6_identifier = tuple->src.u.icmp.id;
 78         }
 79         return true;
 80 }
 81 
 82 const struct nf_nat_l4proto nf_nat_l4proto_icmpv6 = {
 83         .l4proto                = IPPROTO_ICMPV6,
 84         .manip_pkt              = icmpv6_manip_pkt,
 85         .in_range               = icmpv6_in_range,
 86         .unique_tuple           = icmpv6_unique_tuple,
 87 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
 88         .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
 89 #endif
 90 };
 91 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp