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

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

Version: ~ [ linux-6.2-rc3 ] ~ [ linux-6.1.5 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.87 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.162 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.228 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.269 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.302 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* Masquerade.  Simple mapping which alters range to a local IP address
  2    (depending on route). */
  3 
  4 /* (C) 1999-2001 Paul `Rusty' Russell
  5  * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
  6  *
  7  * This program is free software; you can redistribute it and/or modify
  8  * it under the terms of the GNU General Public License version 2 as
  9  * published by the Free Software Foundation.
 10  */
 11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 12 #include <linux/types.h>
 13 #include <linux/inetdevice.h>
 14 #include <linux/ip.h>
 15 #include <linux/timer.h>
 16 #include <linux/module.h>
 17 #include <linux/netfilter.h>
 18 #include <net/protocol.h>
 19 #include <net/ip.h>
 20 #include <net/checksum.h>
 21 #include <net/route.h>
 22 #include <linux/netfilter_ipv4.h>
 23 #include <linux/netfilter/x_tables.h>
 24 #include <net/netfilter/nf_nat.h>
 25 #include <net/netfilter/ipv4/nf_nat_masquerade.h>
 26 
 27 MODULE_LICENSE("GPL");
 28 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
 29 MODULE_DESCRIPTION("Xtables: automatic-address SNAT");
 30 
 31 /* FIXME: Multiple targets. --RR */
 32 static int masquerade_tg_check(const struct xt_tgchk_param *par)
 33 {
 34         const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo;
 35 
 36         if (mr->range[0].flags & NF_NAT_RANGE_MAP_IPS) {
 37                 pr_debug("bad MAP_IPS.\n");
 38                 return -EINVAL;
 39         }
 40         if (mr->rangesize != 1) {
 41                 pr_debug("bad rangesize %u\n", mr->rangesize);
 42                 return -EINVAL;
 43         }
 44         return 0;
 45 }
 46 
 47 static unsigned int
 48 masquerade_tg(struct sk_buff *skb, const struct xt_action_param *par)
 49 {
 50         struct nf_nat_range range;
 51         const struct nf_nat_ipv4_multi_range_compat *mr;
 52 
 53         mr = par->targinfo;
 54         range.flags = mr->range[0].flags;
 55         range.min_proto = mr->range[0].min;
 56         range.max_proto = mr->range[0].max;
 57 
 58         return nf_nat_masquerade_ipv4(skb, par->hooknum, &range, par->out);
 59 }
 60 
 61 static struct xt_target masquerade_tg_reg __read_mostly = {
 62         .name           = "MASQUERADE",
 63         .family         = NFPROTO_IPV4,
 64         .target         = masquerade_tg,
 65         .targetsize     = sizeof(struct nf_nat_ipv4_multi_range_compat),
 66         .table          = "nat",
 67         .hooks          = 1 << NF_INET_POST_ROUTING,
 68         .checkentry     = masquerade_tg_check,
 69         .me             = THIS_MODULE,
 70 };
 71 
 72 static int __init masquerade_tg_init(void)
 73 {
 74         int ret;
 75 
 76         ret = xt_register_target(&masquerade_tg_reg);
 77 
 78         if (ret == 0)
 79                 nf_nat_masquerade_ipv4_register_notifier();
 80 
 81         return ret;
 82 }
 83 
 84 static void __exit masquerade_tg_exit(void)
 85 {
 86         xt_unregister_target(&masquerade_tg_reg);
 87         nf_nat_masquerade_ipv4_unregister_notifier();
 88 }
 89 
 90 module_init(masquerade_tg_init);
 91 module_exit(masquerade_tg_exit);
 92 

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