Skip to contentSkip to conversation

NAT expression and IPv6 NAT support

PATCH In review Tomasz Bursztyka 2 participants 6 messages Nov 15, 2012 – Nov 16, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover NAT expression and IPv6 NAT support

Hi,

same patches as before with modifications applied according to Pablo's comments. Patch 3 is therefore much simpler.

Tomasz Bursztyka (4):
nf_tables: Change NFTA_NAT_ attributes to better semantic
significance
nf_tables: Split IPv4 NAT into NAT expression and NAT IPv4 chain.
nf_tables: Add support for IPv6 NAT expression
nf_tables: Add support for IPv6 NAT chain

 include/linux/netfilter/nf_tables.h     |   9 +-
 net/ipv4/netfilter/Kconfig              |   1 +
 net/ipv4/netfilter/nft_chain_nat_ipv4.c | 154 +---------------------
 net/ipv6/netfilter/Kconfig              |   5 +
 net/ipv6/netfilter/Makefile             |   2 +
 net/ipv6/netfilter/nft_chain_nat_ipv6.c | 209 ++++++++++++++++++++++++++++++
 net/netfilter/Kconfig                   |   5 +
 net/netfilter/Makefile                  |   1 +
 net/netfilter/nft_nat.c                 | 220 ++++++++++++++++++++++++++++++++
 9 files changed, 449 insertions(+), 157 deletions(-)
 create mode 100644 net/ipv6/netfilter/nft_chain_nat_ipv6.c
 create mode 100644 net/netfilter/nft_nat.c
Signature · 1 line
1.8.0
#1 lore raw

PATCH v2 1/4 nf_tables: Change NFTA_NAT_ attributes to better semantic significance

---
 include/linux/netfilter/nf_tables.h     |  8 +++----
 net/ipv4/netfilter/nft_chain_nat_ipv4.c | 42 ++++++++++++++++++++-------------
 2 files changed, 29 insertions(+), 21 deletions(-)
include/linux/netfilter/nf_tables.h +4 -4
index 1242e62..f42cc9d 100644
@@ -395,10 +395,10 @@ enum nft_nat_types {
 enum nft_nat_attributes {
 	NFTA_NAT_UNSPEC,
 	NFTA_NAT_TYPE,
-	NFTA_NAT_ADDR_MIN,
-	NFTA_NAT_ADDR_MAX,
-	NFTA_NAT_PROTO_MIN,
-	NFTA_NAT_PROTO_MAX,
+	NFTA_NAT_REG_ADDR_MIN,
+	NFTA_NAT_REG_ADDR_MAX,
+	NFTA_NAT_REG_PROTO_MIN,
+	NFTA_NAT_REG_PROTO_MAX,
 	__NFTA_NAT_MAX
 };
 #define NFTA_NAT_MAX		(__NFTA_NAT_MAX - 1)
net/ipv4/netfilter/nft_chain_nat_ipv4.c +25 -17

79 lines not on this page · raw message

Signature · 1 line
1.8.0
#2 lore raw

PATCH v2 2/4 nf_tables: Split IPv4 NAT into NAT expression and IPv4 NAT chain

In reply to Tomasz Bursztyka

This will permit to generalize NAT expression handling for both IPv4 and IPv6.

---
 net/ipv4/netfilter/Kconfig              |   1 +
 net/ipv4/netfilter/nft_chain_nat_ipv4.c | 162 +-------------------------
 net/netfilter/Kconfig                   |   5 +
 net/netfilter/Makefile                  |   1 +
 net/netfilter/nft_nat.c                 | 198 ++++++++++++++++++++++++++++++++
 5 files changed, 206 insertions(+), 161 deletions(-)
 create mode 100644 net/netfilter/nft_nat.c
net/ipv4/netfilter/Kconfig +1 -0
index 1aefe95..e0ebf2f 100644
@@ -63,6 +63,7 @@ config NFT_CHAIN_ROUTE_IPV4
 
 config NFT_CHAIN_NAT_IPV4
 	depends on NF_TABLES_IPV4
+	depends on NFT_NAT
 	tristate "IPv4 nf_tables nat chain support"
 
 config IP_NF_IPTABLES
net/ipv4/netfilter/nft_chain_nat_ipv4.c +1 -161

196 lines not on this page · raw message

net/netfilter/Kconfig +5 -0
index 95d2907..9ba8d0e 100644
@@ -469,6 +469,11 @@ config NFT_LIMIT
        depends on NF_TABLES
        tristate "Netfilter nf_tables limit module"
 
+config NFT_NAT
+       depends on NF_TABLES
+       depends on NF_CONNTRACK
+       tristate "Netfilter nf_tables nat module"
+
 if NETFILTER_XTABLES
 
 comment "Xtables combined modules"
net/netfilter/Makefile +1 -0
index 62d1a0f..1e9b653 100644
@@ -73,6 +73,7 @@ obj-$(CONFIG_NFT_EXTHDR)	+= nft_exthdr.o
 obj-$(CONFIG_NFT_META)		+= nft_meta.o
 obj-$(CONFIG_NFT_CT)		+= nft_ct.o
 obj-$(CONFIG_NFT_LIMIT)		+= nft_limit.o
+obj-$(CONFIG_NFT_NAT)		+= nft_nat.o
 #nf_tables-objs			+= nft_meta_target.o
 obj-$(CONFIG_NFT_RBTREE)	+= nft_rbtree.o
 obj-$(CONFIG_NFT_HASH)		+= nft_hash.o
net/netfilter/nft_nat.c new file +198 -0

198 lines not on this page · raw message

Signature · 1 line
1.8.0
#3 lore raw

PATCH v2 3/4 nf_tables: Add support for IPv6 NAT expression

In reply to Tomasz Bursztyka
---
 include/linux/netfilter/nf_tables.h |  1 +
 net/netfilter/nft_nat.c             | 26 ++++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)
include/linux/netfilter/nf_tables.h +1 -0
index f42cc9d..fed6835 100644
@@ -395,6 +395,7 @@ enum nft_nat_types {
 enum nft_nat_attributes {
 	NFTA_NAT_UNSPEC,
 	NFTA_NAT_TYPE,
+	NFTA_NAT_FAMILY,
 	NFTA_NAT_REG_ADDR_MIN,
 	NFTA_NAT_REG_ADDR_MAX,
 	NFTA_NAT_REG_PROTO_MIN,
net/netfilter/nft_nat.c +24 -2
index ea9854e..b0b87b2 100644
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/skbuff.h>
 #include <linux/ip.h>
+#include <linux/string.h>
 #include <linux/netlink.h>
 #include <linux/netfilter.h>
 #include <linux/netfilter_ipv4.h>
@@ -30,6 +31,7 @@ struct nft_nat {
 	enum nft_registers      sreg_addr_max:8;
 	enum nft_registers      sreg_proto_min:8;
 	enum nft_registers      sreg_proto_max:8;
+	int                     family;
 	enum nf_nat_manip_type  type;
 };
 
@@ -44,8 +46,18 @@ static void nft_nat_eval(const struct nft_expr *expr,
 
 	memset(&range, 0, sizeof(range));
 	if (priv->sreg_addr_min) {
-		range.min_addr.ip = data[priv->sreg_addr_min].data[0];
-		range.max_addr.ip = data[priv->sreg_addr_max].data[0];
+		if (priv->family == AF_INET) {
+			range.min_addr.ip = data[priv->sreg_addr_min].data[0];
+			range.max_addr.ip = data[priv->sreg_addr_max].data[0];
+
+		} else {
+			memcpy(range.min_addr.ip6,
+			       data[priv->sreg_addr_min].data,
+			       sizeof(struct nft_data));
+			memcpy(range.max_addr.ip6,
+			       data[priv->sreg_addr_max].data,
+			       sizeof(struct nft_data));
+		}
 		range.flags |= NF_NAT_RANGE_MAP_IPS;
 	}
 
@@ -61,6 +73,7 @@ static void nft_nat_eval(const struct nft_expr *expr,
 
 static const struct nla_policy nft_nat_policy[NFTA_NAT_MAX + 1] = {
 	[NFTA_NAT_TYPE]		 = { .type = NLA_U32 },
+	[NFTA_NAT_FAMILY]	 = { .type = NLA_U32 },
 	[NFTA_NAT_REG_ADDR_MIN]	 = { .type = NLA_U32 },
 	[NFTA_NAT_REG_ADDR_MAX]	 = { .type = NLA_U32 },
 	[NFTA_NAT_REG_PROTO_MIN] = { .type = NLA_U32 },
@@ -87,6 +100,13 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
 		return -EINVAL;
 	}
 
+	if (tb[NFTA_NAT_FAMILY] == NULL)
+		return -EINVAL;
+
+	priv->family = ntohl(nla_get_be32(tb[NFTA_NAT_FAMILY]));
+	if (priv->family != AF_INET && priv->family != AF_INET6)
+		return -EINVAL;
+
 	if (tb[NFTA_NAT_REG_ADDR_MIN]) {
 		priv->sreg_addr_min = ntohl(nla_get_be32(
 						tb[NFTA_NAT_REG_ADDR_MIN]));
@@ -139,6 +159,8 @@ static int nft_nat_dump(struct sk_buff *skb, const struct nft_expr *expr)
 		break;
 	}
 
+	if (nla_put_be32(skb, NFTA_NAT_FAMILY, htonl(priv->family)))
+		goto nla_put_failure;
 	if (nla_put_be32(skb,
 			 NFTA_NAT_REG_ADDR_MIN, htonl(priv->sreg_addr_min)))
 		goto nla_put_failure;
Signature · 1 line
1.8.0
#4 lore raw

PATCH v2 4/4 nf_tables: Add support for IPv6 NAT chain

In reply to Tomasz Bursztyka
---
 net/ipv6/netfilter/Kconfig              |   5 +
 net/ipv6/netfilter/Makefile             |   2 +
 net/ipv6/netfilter/nft_chain_nat_ipv6.c | 209 ++++++++++++++++++++++++++++++++
 3 files changed, 216 insertions(+)
 create mode 100644 net/ipv6/netfilter/nft_chain_nat_ipv6.c
net/ipv6/netfilter/Kconfig +5 -0
index 20ab251..0be3357 100644
@@ -33,6 +33,11 @@ config NFT_CHAIN_ROUTE_IPV6
 	depends on NF_TABLES_IPV6
 	tristate "IPv6 nf_tables route chain support"
 
+config NFT_CHAIN_NAT_IPV6
+	depends on NF_TABLES_IPV6
+	depends on NFT_NAT
+	tristate "IPv6 nf_tables nat chain support"
+
 config IP6_NF_IPTABLES
 	tristate "IP6 tables support (required for filtering)"
 	depends on INET && IPV6
net/ipv6/netfilter/Makefile +2 -0
index cc19b60..07155bd 100644
@@ -26,6 +26,8 @@ obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
 # nf_tables
 obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o
 obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o
+nft_chain_nat_ipv6-y	:= nf_nat_l3proto_ipv6.o nf_nat_proto_icmpv6.o
+obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o
 
 # matches
 obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nft_chain_nat_ipv6.c new file +209 -0

209 lines not on this page · raw message

Signature · 1 line
1.8.0
#5 lore raw
In reply to Tomasz Bursztyka
Quoted 11 lines · Tomasz Bursztyka

Hi,

same patches as before with modifications applied according to Pablo's comments. Patch 3 is therefore much simpler.

Tomasz Bursztyka (4):
nf_tables: Change NFTA_NAT_ attributes to better semantic
significance
nf_tables: Split IPv4 NAT into NAT expression and NAT IPv4 chain.
nf_tables: Add support for IPv6 NAT expression
nf_tables: Add support for IPv6 NAT chain

All applied, thanks a lot Tomasz