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

TOMOYO Linux Cross Reference
Linux/net/ipv4/netfilter/nf_nat_proto_icmp.c

Version: ~ [ linux-5.2-rc4 ] ~ [ linux-5.1.9 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.50 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.125 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.181 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.181 ] ~ [ 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.68 ] ~ [ 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-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ 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 /* (C) 1999-2001 Paul `Rusty' Russell
  2  * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
  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 
  9 #include <linux/types.h>
 10 #include <linux/init.h>
 11 #include <linux/export.h>
 12 #include <linux/ip.h>
 13 #include <linux/icmp.h>
 14 
 15 #include <linux/netfilter.h>
 16 #include <net/netfilter/nf_nat.h>
 17 #include <net/netfilter/nf_nat_core.h>
 18 #include <net/netfilter/nf_nat_l4proto.h>
 19 
 20 static bool
 21 icmp_in_range(const struct nf_conntrack_tuple *tuple,
 22               enum nf_nat_manip_type maniptype,
 23               const union nf_conntrack_man_proto *min,
 24               const union nf_conntrack_man_proto *max)
 25 {
 26         return ntohs(tuple->src.u.icmp.id) >= ntohs(min->icmp.id) &&
 27                ntohs(tuple->src.u.icmp.id) <= ntohs(max->icmp.id);
 28 }
 29 
 30 static void
 31 icmp_unique_tuple(const struct nf_nat_l3proto *l3proto,
 32                   struct nf_conntrack_tuple *tuple,
 33                   const struct nf_nat_range *range,
 34                   enum nf_nat_manip_type maniptype,
 35                   const struct nf_conn *ct)
 36 {
 37         static u_int16_t id;
 38         unsigned int range_size;
 39         unsigned int i;
 40 
 41         range_size = ntohs(range->max_proto.icmp.id) -
 42                      ntohs(range->min_proto.icmp.id) + 1;
 43         /* If no range specified... */
 44         if (!(range->flags & NF_NAT_RANGE_PROTO_SPECIFIED))
 45                 range_size = 0xFFFF;
 46 
 47         for (i = 0; ; ++id) {
 48                 tuple->src.u.icmp.id = htons(ntohs(range->min_proto.icmp.id) +
 49                                              (id % range_size));
 50                 if (++i == range_size || !nf_nat_used_tuple(tuple, ct))
 51                         return;
 52         }
 53         return;
 54 }
 55 
 56 static bool
 57 icmp_manip_pkt(struct sk_buff *skb,
 58                const struct nf_nat_l3proto *l3proto,
 59                unsigned int iphdroff, unsigned int hdroff,
 60                const struct nf_conntrack_tuple *tuple,
 61                enum nf_nat_manip_type maniptype)
 62 {
 63         struct icmphdr *hdr;
 64 
 65         if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
 66                 return false;
 67 
 68         hdr = (struct icmphdr *)(skb->data + hdroff);
 69         inet_proto_csum_replace2(&hdr->checksum, skb,
 70                                  hdr->un.echo.id, tuple->src.u.icmp.id, false);
 71         hdr->un.echo.id = tuple->src.u.icmp.id;
 72         return true;
 73 }
 74 
 75 const struct nf_nat_l4proto nf_nat_l4proto_icmp = {
 76         .l4proto                = IPPROTO_ICMP,
 77         .manip_pkt              = icmp_manip_pkt,
 78         .in_range               = icmp_in_range,
 79         .unique_tuple           = icmp_unique_tuple,
 80 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
 81         .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
 82 #endif
 83 };
 84 

~ [ 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