]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/ipv4/netfilter/ipt_MASQUERADE.c
netfilter: x_tables: move hook state into xt_action_param structure
[mirror_ubuntu-artful-kernel.git] / net / ipv4 / netfilter / ipt_MASQUERADE.c
CommitLineData
1da177e4
LT
1/* Masquerade. Simple mapping which alters range to a local IP address
2 (depending on route). */
3
4/* (C) 1999-2001 Paul `Rusty' Russell
5b1158e9 5 * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
1da177e4
LT
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 */
ff67e4e4 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1da177e4 12#include <linux/types.h>
14c85021 13#include <linux/inetdevice.h>
1da177e4
LT
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>
14c85021 21#include <net/route.h>
587aa641 22#include <linux/netfilter_ipv4.h>
6709dbbb 23#include <linux/netfilter/x_tables.h>
c7232c99 24#include <net/netfilter/nf_nat.h>
8dd33cc9 25#include <net/netfilter/ipv4/nf_nat_masquerade.h>
1da177e4
LT
26
27MODULE_LICENSE("GPL");
28MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
2ae15b64 29MODULE_DESCRIPTION("Xtables: automatic-address SNAT");
1da177e4 30
1da177e4 31/* FIXME: Multiple targets. --RR */
135367b8 32static int masquerade_tg_check(const struct xt_tgchk_param *par)
1da177e4 33{
cbc9f2f4 34 const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo;
1da177e4 35
cbc9f2f4 36 if (mr->range[0].flags & NF_NAT_RANGE_MAP_IPS) {
ff67e4e4 37 pr_debug("bad MAP_IPS.\n");
d6b00a53 38 return -EINVAL;
1da177e4
LT
39 }
40 if (mr->rangesize != 1) {
ff67e4e4 41 pr_debug("bad rangesize %u\n", mr->rangesize);
d6b00a53 42 return -EINVAL;
1da177e4 43 }
d6b00a53 44 return 0;
1da177e4
LT
45}
46
47static unsigned int
4b560b44 48masquerade_tg(struct sk_buff *skb, const struct xt_action_param *par)
1da177e4 49{
8dd33cc9 50 struct nf_nat_range range;
cbc9f2f4 51 const struct nf_nat_ipv4_multi_range_compat *mr;
adcb5ad1 52
7eb35586 53 mr = par->targinfo;
8dd33cc9
AB
54 range.flags = mr->range[0].flags;
55 range.min_proto = mr->range[0].min;
56 range.max_proto = mr->range[0].max;
1da177e4 57
613dbd95
PNA
58 return nf_nat_masquerade_ipv4(skb, xt_hooknum(par), &range,
59 xt_out(par));
1da177e4
LT
60}
61
d3c5ee6d 62static struct xt_target masquerade_tg_reg __read_mostly = {
1da177e4 63 .name = "MASQUERADE",
ee999d8b 64 .family = NFPROTO_IPV4,
d3c5ee6d 65 .target = masquerade_tg,
cbc9f2f4 66 .targetsize = sizeof(struct nf_nat_ipv4_multi_range_compat),
1d5cd909 67 .table = "nat",
6e23ae2a 68 .hooks = 1 << NF_INET_POST_ROUTING,
d3c5ee6d 69 .checkentry = masquerade_tg_check,
1da177e4
LT
70 .me = THIS_MODULE,
71};
72
d3c5ee6d 73static int __init masquerade_tg_init(void)
1da177e4
LT
74{
75 int ret;
76
d3c5ee6d 77 ret = xt_register_target(&masquerade_tg_reg);
1da177e4 78
8dd33cc9
AB
79 if (ret == 0)
80 nf_nat_masquerade_ipv4_register_notifier();
1da177e4
LT
81
82 return ret;
83}
84
d3c5ee6d 85static void __exit masquerade_tg_exit(void)
1da177e4 86{
d3c5ee6d 87 xt_unregister_target(&masquerade_tg_reg);
8dd33cc9 88 nf_nat_masquerade_ipv4_unregister_notifier();
1da177e4
LT
89}
90
d3c5ee6d
JE
91module_init(masquerade_tg_init);
92module_exit(masquerade_tg_exit);