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

TOMOYO Linux Cross Reference
Linux/net/netfilter/xt_REDIRECT.c

Version: ~ [ linux-6.0-rc1 ] ~ [ linux-5.19.1 ] ~ [ linux-5.18.17 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.60 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.136 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.210 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.255 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.290 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.325 ] ~ [ 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 /*
  2  * (C) 1999-2001 Paul `Rusty' Russell
  3  * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
  4  * Copyright (c) 2011 Patrick McHardy <kaber@trash.net>
  5  *
  6  * This program is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License version 2 as
  8  * published by the Free Software Foundation.
  9  *
 10  * Based on Rusty Russell's IPv4 REDIRECT target. Development of IPv6
 11  * NAT funded by Astaro.
 12  */
 13 
 14 #include <linux/if.h>
 15 #include <linux/inetdevice.h>
 16 #include <linux/ip.h>
 17 #include <linux/kernel.h>
 18 #include <linux/module.h>
 19 #include <linux/netdevice.h>
 20 #include <linux/netfilter.h>
 21 #include <linux/types.h>
 22 #include <linux/netfilter_ipv4.h>
 23 #include <linux/netfilter_ipv6.h>
 24 #include <linux/netfilter/x_tables.h>
 25 #include <net/addrconf.h>
 26 #include <net/checksum.h>
 27 #include <net/protocol.h>
 28 #include <net/netfilter/nf_nat.h>
 29 #include <net/netfilter/nf_nat_redirect.h>
 30 
 31 static unsigned int
 32 redirect_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 33 {
 34         return nf_nat_redirect_ipv6(skb, par->targinfo, xt_hooknum(par));
 35 }
 36 
 37 static int redirect_tg6_checkentry(const struct xt_tgchk_param *par)
 38 {
 39         const struct nf_nat_range *range = par->targinfo;
 40 
 41         if (range->flags & NF_NAT_RANGE_MAP_IPS)
 42                 return -EINVAL;
 43 
 44         return nf_ct_netns_get(par->net, par->family);
 45 }
 46 
 47 static void redirect_tg_destroy(const struct xt_tgdtor_param *par)
 48 {
 49         nf_ct_netns_put(par->net, par->family);
 50 }
 51 
 52 /* FIXME: Take multiple ranges --RR */
 53 static int redirect_tg4_check(const struct xt_tgchk_param *par)
 54 {
 55         const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo;
 56 
 57         if (mr->range[0].flags & NF_NAT_RANGE_MAP_IPS) {
 58                 pr_debug("bad MAP_IPS.\n");
 59                 return -EINVAL;
 60         }
 61         if (mr->rangesize != 1) {
 62                 pr_debug("bad rangesize %u.\n", mr->rangesize);
 63                 return -EINVAL;
 64         }
 65         return nf_ct_netns_get(par->net, par->family);
 66 }
 67 
 68 static unsigned int
 69 redirect_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 70 {
 71         return nf_nat_redirect_ipv4(skb, par->targinfo, xt_hooknum(par));
 72 }
 73 
 74 static struct xt_target redirect_tg_reg[] __read_mostly = {
 75         {
 76                 .name       = "REDIRECT",
 77                 .family     = NFPROTO_IPV6,
 78                 .revision   = 0,
 79                 .table      = "nat",
 80                 .checkentry = redirect_tg6_checkentry,
 81                 .destroy    = redirect_tg_destroy,
 82                 .target     = redirect_tg6,
 83                 .targetsize = sizeof(struct nf_nat_range),
 84                 .hooks      = (1 << NF_INET_PRE_ROUTING) |
 85                               (1 << NF_INET_LOCAL_OUT),
 86                 .me         = THIS_MODULE,
 87         },
 88         {
 89                 .name       = "REDIRECT",
 90                 .family     = NFPROTO_IPV4,
 91                 .revision   = 0,
 92                 .table      = "nat",
 93                 .target     = redirect_tg4,
 94                 .checkentry = redirect_tg4_check,
 95                 .destroy    = redirect_tg_destroy,
 96                 .targetsize = sizeof(struct nf_nat_ipv4_multi_range_compat),
 97                 .hooks      = (1 << NF_INET_PRE_ROUTING) |
 98                               (1 << NF_INET_LOCAL_OUT),
 99                 .me         = THIS_MODULE,
100         },
101 };
102 
103 static int __init redirect_tg_init(void)
104 {
105         return xt_register_targets(redirect_tg_reg,
106                                    ARRAY_SIZE(redirect_tg_reg));
107 }
108 
109 static void __exit redirect_tg_exit(void)
110 {
111         xt_unregister_targets(redirect_tg_reg, ARRAY_SIZE(redirect_tg_reg));
112 }
113 
114 module_init(redirect_tg_init);
115 module_exit(redirect_tg_exit);
116 
117 MODULE_LICENSE("GPL");
118 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
119 MODULE_DESCRIPTION("Xtables: Connection redirection to localhost");
120 MODULE_ALIAS("ip6t_REDIRECT");
121 MODULE_ALIAS("ipt_REDIRECT");
122 

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