diff options
author | Arturo Borrero <arturo.borrero.glez@gmail.com> | 2014-10-17 06:39:09 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-10-27 17:49:39 -0400 |
commit | e9105f1bead4ec3f64904564c7c6268185d6b363 (patch) | |
tree | c2b91e5f3183503759fd8759cdeb9bf3ccf45af2 /net/ipv6 | |
parent | 9de920eddb74bf67f1d6af603acc5ed05dcd35e9 (diff) |
netfilter: nf_tables: add new expression nft_redir
This new expression provides NAT in the redirect flavour, which is to
redirect packets to local machine.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/netfilter/Kconfig | 9 | ||||
-rw-r--r-- | net/ipv6/netfilter/Makefile | 1 | ||||
-rw-r--r-- | net/ipv6/netfilter/nft_redir_ipv6.c | 77 |
3 files changed, 87 insertions, 0 deletions
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig index 462eebbf4377..0dbe5c7953e5 100644 --- a/net/ipv6/netfilter/Kconfig +++ b/net/ipv6/netfilter/Kconfig | |||
@@ -97,6 +97,15 @@ config NFT_MASQ_IPV6 | |||
97 | This is the expression that provides IPv4 masquerading support for | 97 | This is the expression that provides IPv4 masquerading support for |
98 | nf_tables. | 98 | nf_tables. |
99 | 99 | ||
100 | config NFT_REDIR_IPV6 | ||
101 | tristate "IPv6 redirect support for nf_tables" | ||
102 | depends on NF_TABLES_IPV6 | ||
103 | depends on NFT_REDIR | ||
104 | select NF_NAT_REDIRECT_IPV6 | ||
105 | help | ||
106 | This is the expression that provides IPv4 redirect support for | ||
107 | nf_tables. | ||
108 | |||
100 | endif # NF_NAT_IPV6 | 109 | endif # NF_NAT_IPV6 |
101 | 110 | ||
102 | config IP6_NF_IPTABLES | 111 | config IP6_NF_IPTABLES |
diff --git a/net/ipv6/netfilter/Makefile b/net/ipv6/netfilter/Makefile index 6c2baab10f21..d2ac9f5f212c 100644 --- a/net/ipv6/netfilter/Makefile +++ b/net/ipv6/netfilter/Makefile | |||
@@ -37,6 +37,7 @@ obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o | |||
37 | obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o | 37 | obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o |
38 | obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o | 38 | obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o |
39 | obj-$(CONFIG_NFT_MASQ_IPV6) += nft_masq_ipv6.o | 39 | obj-$(CONFIG_NFT_MASQ_IPV6) += nft_masq_ipv6.o |
40 | obj-$(CONFIG_NFT_REDIR_IPV6) += nft_redir_ipv6.o | ||
40 | 41 | ||
41 | # matches | 42 | # matches |
42 | obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o | 43 | obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o |
diff --git a/net/ipv6/netfilter/nft_redir_ipv6.c b/net/ipv6/netfilter/nft_redir_ipv6.c new file mode 100644 index 000000000000..83420eeaad1c --- /dev/null +++ b/net/ipv6/netfilter/nft_redir_ipv6.c | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2014 Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> | ||
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/kernel.h> | ||
10 | #include <linux/init.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/netlink.h> | ||
13 | #include <linux/netfilter.h> | ||
14 | #include <linux/netfilter/nf_tables.h> | ||
15 | #include <net/netfilter/nf_tables.h> | ||
16 | #include <net/netfilter/nf_nat.h> | ||
17 | #include <net/netfilter/nft_redir.h> | ||
18 | #include <net/netfilter/ipv6/nf_nat_redirect.h> | ||
19 | |||
20 | static void nft_redir_ipv6_eval(const struct nft_expr *expr, | ||
21 | struct nft_data data[NFT_REG_MAX + 1], | ||
22 | const struct nft_pktinfo *pkt) | ||
23 | { | ||
24 | struct nft_redir *priv = nft_expr_priv(expr); | ||
25 | struct nf_nat_range range; | ||
26 | unsigned int verdict; | ||
27 | |||
28 | memset(&range, 0, sizeof(range)); | ||
29 | if (priv->sreg_proto_min) { | ||
30 | range.min_proto.all = (__force __be16) | ||
31 | data[priv->sreg_proto_min].data[0]; | ||
32 | range.max_proto.all = (__force __be16) | ||
33 | data[priv->sreg_proto_max].data[0]; | ||
34 | range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED; | ||
35 | } | ||
36 | |||
37 | range.flags |= priv->flags; | ||
38 | |||
39 | verdict = nf_nat_redirect_ipv6(pkt->skb, &range, pkt->ops->hooknum); | ||
40 | data[NFT_REG_VERDICT].verdict = verdict; | ||
41 | } | ||
42 | |||
43 | static struct nft_expr_type nft_redir_ipv6_type; | ||
44 | static const struct nft_expr_ops nft_redir_ipv6_ops = { | ||
45 | .type = &nft_redir_ipv6_type, | ||
46 | .size = NFT_EXPR_SIZE(sizeof(struct nft_redir)), | ||
47 | .eval = nft_redir_ipv6_eval, | ||
48 | .init = nft_redir_init, | ||
49 | .dump = nft_redir_dump, | ||
50 | .validate = nft_redir_validate, | ||
51 | }; | ||
52 | |||
53 | static struct nft_expr_type nft_redir_ipv6_type __read_mostly = { | ||
54 | .family = NFPROTO_IPV6, | ||
55 | .name = "redir", | ||
56 | .ops = &nft_redir_ipv6_ops, | ||
57 | .policy = nft_redir_policy, | ||
58 | .maxattr = NFTA_REDIR_MAX, | ||
59 | .owner = THIS_MODULE, | ||
60 | }; | ||
61 | |||
62 | static int __init nft_redir_ipv6_module_init(void) | ||
63 | { | ||
64 | return nft_register_expr(&nft_redir_ipv6_type); | ||
65 | } | ||
66 | |||
67 | static void __exit nft_redir_ipv6_module_exit(void) | ||
68 | { | ||
69 | nft_unregister_expr(&nft_redir_ipv6_type); | ||
70 | } | ||
71 | |||
72 | module_init(nft_redir_ipv6_module_init); | ||
73 | module_exit(nft_redir_ipv6_module_exit); | ||
74 | |||
75 | MODULE_LICENSE("GPL"); | ||
76 | MODULE_AUTHOR("Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>"); | ||
77 | MODULE_ALIAS_NFT_AF_EXPR(AF_INET6, "redir"); | ||