netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iptables: allow IPv6 port NAT without address NAT
@ 2013-01-02 15:52 Ulrich Weber
  2013-01-03  0:13 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Weber @ 2013-01-02 15:52 UTC (permalink / raw)
  To: netfilter-devel

correct parsing of IPv6 port NAT without address NAT
and also print brackets for port only IPv6 NAT.

Signed-off-by: Ulrich Weber <ulrich.weber@sophos.com>
---
 extensions/libip6t_DNAT.c | 12 +++++-------
 extensions/libip6t_SNAT.c | 12 +++++-------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/extensions/libip6t_DNAT.c b/extensions/libip6t_DNAT.c
index a5969c3..6f11d52 100644
--- a/extensions/libip6t_DNAT.c
+++ b/extensions/libip6t_DNAT.c
@@ -105,8 +105,8 @@ parse_to(const char *orig_arg, int portok, struct nf_nat_range *range)
 			range->min_proto.tcp.port = htons(port);
 			range->max_proto.tcp.port = htons(maxport);
 		}
-		/* Starts with a colon? No IP info...*/
-		if (colon == arg) {
+		/* Starts with [] colon? No IP info...*/
+		if (colon == arg+2) {
 			free(arg);
 			return;
 		}
@@ -183,18 +183,16 @@ static void DNAT_fcheck(struct xt_fcheck_call *cb)
 
 static void print_range(const struct nf_nat_range *range)
 {
+	if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED)
+		printf("[");
 	if (range->flags & NF_NAT_RANGE_MAP_IPS) {
-		if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED)
-			printf("[");
 		printf("%s", xtables_ip6addr_to_numeric(&range->min_addr.in6));
 		if (memcmp(&range->min_addr, &range->max_addr,
 			   sizeof(range->min_addr)))
 			printf("-%s", xtables_ip6addr_to_numeric(&range->max_addr.in6));
-		if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED)
-			printf("]");
 	}
 	if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
-		printf(":");
+		printf("]:");
 		printf("%hu", ntohs(range->min_proto.tcp.port));
 		if (range->max_proto.tcp.port != range->min_proto.tcp.port)
 			printf("-%hu", ntohs(range->max_proto.tcp.port));
diff --git a/extensions/libip6t_SNAT.c b/extensions/libip6t_SNAT.c
index 307be70..8d2c87e 100644
--- a/extensions/libip6t_SNAT.c
+++ b/extensions/libip6t_SNAT.c
@@ -105,8 +105,8 @@ parse_to(const char *orig_arg, int portok, struct nf_nat_range *range)
 			range->min_proto.tcp.port = htons(port);
 			range->max_proto.tcp.port = htons(maxport);
 		}
-		/* Starts with a colon? No IP info...*/
-		if (colon == arg) {
+		/* Starts with [] colon? No IP info...*/
+		if (colon == arg+2) {
 			free(arg);
 			return;
 		}
@@ -183,18 +183,16 @@ static void SNAT_fcheck(struct xt_fcheck_call *cb)
 
 static void print_range(const struct nf_nat_range *range)
 {
+	if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED)
+		printf("[");
 	if (range->flags & NF_NAT_RANGE_MAP_IPS) {
-		if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED)
-			printf("[");
 		printf("%s", xtables_ip6addr_to_numeric(&range->min_addr.in6));
 		if (memcmp(&range->min_addr, &range->max_addr,
 			   sizeof(range->min_addr)))
 			printf("-%s", xtables_ip6addr_to_numeric(&range->max_addr.in6));
-		if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED)
-			printf("]");
 	}
 	if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
-		printf(":");
+		printf("]:");
 		printf("%hu", ntohs(range->min_proto.tcp.port));
 		if (range->max_proto.tcp.port != range->min_proto.tcp.port)
 			printf("-%hu", ntohs(range->max_proto.tcp.port));
-- 
1.8.0.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iptables: allow IPv6 port NAT without address NAT
  2013-01-02 15:52 [PATCH] iptables: allow IPv6 port NAT without address NAT Ulrich Weber
@ 2013-01-03  0:13 ` Pablo Neira Ayuso
  2013-01-03 10:17   ` Ulrich Weber
  2013-01-03 10:39   ` [PATCH v2] " Ulrich Weber
  0 siblings, 2 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2013-01-03  0:13 UTC (permalink / raw)
  To: Ulrich Weber; +Cc: netfilter-devel

Hi Ulrich,

On Wed, Jan 02, 2013 at 04:52:44PM +0100, Ulrich Weber wrote:
> correct parsing of IPv6 port NAT without address NAT
> and also print brackets for port only IPv6 NAT.

I think we can go further with some extra sanity checkings, something
like:

parse_to(...)
[...]
        start = strchr(arg, '[');
        if (start == NULL)
                xtables_error(PARAMETER_PROBLEM,
                              "IPv6 address has to be enclosed in brackets");

That will help users that expect a similar syntax than IPv4 DNAT.

The current error shows misleading error reporting if brackets are
missing:

# ip6tables -D PREROUTING -p tcp -t nat -j DNAT --to :80-110
ip6tables v1.4.17: Bad IP address ":80"

Would you send me a new version of this patch?

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iptables: allow IPv6 port NAT without address NAT
  2013-01-03  0:13 ` Pablo Neira Ayuso
@ 2013-01-03 10:17   ` Ulrich Weber
  2013-01-03 10:39   ` [PATCH v2] " Ulrich Weber
  1 sibling, 0 replies; 5+ messages in thread
From: Ulrich Weber @ 2013-01-03 10:17 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

Hi Pablo,

On 01/03/13 01:13, Pablo Neira Ayuso wrote:
> Hi Ulrich,
>
> On Wed, Jan 02, 2013 at 04:52:44PM +0100, Ulrich Weber wrote:
>> correct parsing of IPv6 port NAT without address NAT
>> and also print brackets for port only IPv6 NAT.
> I think we can go further with some extra sanity checkings, something
> like:
>
> parse_to(...)
> [...]
>          start = strchr(arg, '[');
>          if (start == NULL)
>                  xtables_error(PARAMETER_PROBLEM,
>                                "IPv6 address has to be enclosed in brackets");

That will force the use of [] and might break existing scripts.
Lets try another way and relax the parsing,
by assuming one colon as port only information.

Will send another patch...

Cheers
Ulrich

-- 
Ulrich Weber | ulrich.weber@sophos.com | Senior Software Engineer
Astaro - a Sophos company | Amalienbadstr 41 | 76227 Karlsruhe | Germany
Phone +49-721-25516-0 | Fax –200 | www.astaro.com

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] iptables: allow IPv6 port NAT without address NAT
  2013-01-03  0:13 ` Pablo Neira Ayuso
  2013-01-03 10:17   ` Ulrich Weber
@ 2013-01-03 10:39   ` Ulrich Weber
  2013-01-04  0:10     ` Pablo Neira Ayuso
  1 sibling, 1 reply; 5+ messages in thread
From: Ulrich Weber @ 2013-01-03 10:39 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

correct parsing of IPv6 port NAT without address NAT,
assume one colon as port information.

Allows:
* address only:
 -j DNAT --to affe::1
 -j DNAT --to [affe::1]

* port only
 -j DNAT --to :80
 -j DNAT --to :80-110
 -j DNAT --to []:80
 -j DNAT --to []:80-110

* address and port
 -j DNAT --to [affe::1]:80
 -j DNAT --to [affe::1]:80-110

Signed-off-by: Ulrich Weber <ulrich.weber@sophos.com>
---
 extensions/libip6t_DNAT.c | 11 ++++++++---
 extensions/libip6t_SNAT.c | 11 ++++++++---
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/extensions/libip6t_DNAT.c b/extensions/libip6t_DNAT.c
index a5969c3..1bba37e 100644
--- a/extensions/libip6t_DNAT.c
+++ b/extensions/libip6t_DNAT.c
@@ -54,8 +54,13 @@ parse_to(const char *orig_arg, int portok, struct nf_nat_range *range)
 		xtables_error(RESOURCE_PROBLEM, "strdup");
 
 	start = strchr(arg, '[');
-	if (start == NULL)
+	if (start == NULL) {
 		start = arg;
+		/* Lets assume one colon is port information. Otherwise its an IPv6 address */
+		colon = strchr(arg, ':');
+		if (colon && strchr(colon+1, ':'))
+			colon = NULL;
+	}
 	else {
 		start++;
 		end = strchr(start, ']');
@@ -105,8 +110,8 @@ parse_to(const char *orig_arg, int portok, struct nf_nat_range *range)
 			range->min_proto.tcp.port = htons(port);
 			range->max_proto.tcp.port = htons(maxport);
 		}
-		/* Starts with a colon? No IP info...*/
-		if (colon == arg) {
+		/* Starts with colon or [] colon? No IP info...*/
+		if (colon == arg || colon == arg+2) {
 			free(arg);
 			return;
 		}
diff --git a/extensions/libip6t_SNAT.c b/extensions/libip6t_SNAT.c
index 307be70..7382ad0 100644
--- a/extensions/libip6t_SNAT.c
+++ b/extensions/libip6t_SNAT.c
@@ -54,8 +54,13 @@ parse_to(const char *orig_arg, int portok, struct nf_nat_range *range)
 		xtables_error(RESOURCE_PROBLEM, "strdup");
 
 	start = strchr(arg, '[');
-	if (start == NULL)
+	if (start == NULL) {
 		start = arg;
+		/* Lets assume one colon is port information. Otherwise its an IPv6 address */
+		colon = strchr(arg, ':');
+		if (colon && strchr(colon+1, ':'))
+			colon = NULL;
+	}
 	else {
 		start++;
 		end = strchr(start, ']');
@@ -105,8 +110,8 @@ parse_to(const char *orig_arg, int portok, struct nf_nat_range *range)
 			range->min_proto.tcp.port = htons(port);
 			range->max_proto.tcp.port = htons(maxport);
 		}
-		/* Starts with a colon? No IP info...*/
-		if (colon == arg) {
+		/* Starts with colon or [] colon? No IP info...*/
+		if (colon == arg || colon == arg+2) {
 			free(arg);
 			return;
 		}
-- 
1.8.0.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] iptables: allow IPv6 port NAT without address NAT
  2013-01-03 10:39   ` [PATCH v2] " Ulrich Weber
@ 2013-01-04  0:10     ` Pablo Neira Ayuso
  0 siblings, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2013-01-04  0:10 UTC (permalink / raw)
  To: Ulrich Weber; +Cc: netfilter-devel

On Thu, Jan 03, 2013 at 11:39:58AM +0100, Ulrich Weber wrote:
> correct parsing of IPv6 port NAT without address NAT,
> assume one colon as port information.
> 
> Allows:
> * address only:
>  -j DNAT --to affe::1
>  -j DNAT --to [affe::1]
> 
> * port only
>  -j DNAT --to :80
>  -j DNAT --to :80-110
>  -j DNAT --to []:80
>  -j DNAT --to []:80-110
> 
> * address and port
>  -j DNAT --to [affe::1]:80
>  -j DNAT --to [affe::1]:80-110

Applied, thanks Ulrich.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-01-04  0:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-02 15:52 [PATCH] iptables: allow IPv6 port NAT without address NAT Ulrich Weber
2013-01-03  0:13 ` Pablo Neira Ayuso
2013-01-03 10:17   ` Ulrich Weber
2013-01-03 10:39   ` [PATCH v2] " Ulrich Weber
2013-01-04  0:10     ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).