Skip to contentSkip to conversation

fix - src: add support for IPv6 NAT

PATCH Applied Ken-ichirou MATSUZAWA 2 participants 10 messages Feb 28, 2017 – Mar 3, 2017 netfilter

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 conntrack: fix missing break

In reply to Ken-ichirou MATSUZAWA

Signed-off-by Ken-ichirou MATSUZAWA <[email protected]>

---
 src/conntrack/objopt.c | 1 +
 1 file changed, 1 insertion(+)
src/conntrack/objopt.c +1 -0
index 119a83a..fb43d6c 100644
@@ -81,6 +81,7 @@ static void setobjopt_undo_dnat(struct nf_conntrack *ct)
 		ct->dnat.max_ip.v4 = ct->dnat.min_ip.v4;
 		ct->repl.src.v4 = ct->head.orig.dst.v4;
 		set_bit(ATTR_DNAT_IPV4, ct->head.set);
+		break;
 	case AF_INET6:
 		memcpy(&ct->dnat.min_ip.v6, &ct->repl.src.v6,
 		       sizeof(struct in6_addr));
Signature · 1 line
2.11.0
#3 lore raw

PATCH 2/2 conntrack: revert getobjopt_is_nat condition

In reply to Ken-ichirou MATSUZAWA
Quoted 1 line

From 9e8aa4ed079b526faf190b69a2c1032f22776602 Mon Sep 17 00:00:00 2001

From: Ken-ichirou MATSUZAWA <[email protected]>
Date: Tue, 28 Feb 2017 11:34:29 +0900
Subject: [PATCH 2/2] conntrack: revert getobjopt_is_nat condition

---
 src/conntrack/objopt.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
src/conntrack/objopt.c +4 -8
index fb43d6c..1581480 100644
@@ -144,10 +144,8 @@ int __setobjopt(struct nf_conntrack *ct, unsigned int option)
 
 static int getobjopt_is_snat(const struct nf_conntrack *ct)
 {
-	if (!(test_bit(ATTR_STATUS, ct->head.set)))
-		return 0;
-
-	if (!(ct->status & IPS_SRC_NAT_DONE))
+	if (test_bit(ATTR_STATUS, ct->head.set) &&
+	    !(ct->status & IPS_SRC_NAT_DONE))
 		return 0;
 
 	switch (ct->head.orig.l3protonum) {
@@ -166,10 +164,8 @@ static int getobjopt_is_snat(const struct nf_conntrack *ct)
 
 static int getobjopt_is_dnat(const struct nf_conntrack *ct)
 {
-	if (!(test_bit(ATTR_STATUS, ct->head.set)))
-		return 0;
-
-	if (!(ct->status & IPS_DST_NAT_DONE))
+	if (test_bit(ATTR_STATUS, ct->head.set) &&
+	    !(ct->status & IPS_DST_NAT_DONE))
 		return 0;
 
 	switch (ct->head.orig.l3protonum) {
Signature · 1 line
2.11.0
#0 lore raw

cover fix - src: add support for IPv6 NAT

Hi,

This patch series fixes commit:

    73ad642ba462d0992e1903012eee4ebfec89ed69
    f5e51ad64d9e5597e8880b652abe261585c2563d

Conditions in getobjopt_is_snat() / getobjopt_is_dnat() has been changed in the commit above and fixed by this, but I do not understand proper way to check a nfct content is correct. Please review it.

Thanks,

#4 lore raw

Re: [PATCH lnfct 2/2] conntrack: revert getobjopt_is_nat condition

In reply to Ken-ichirou MATSUZAWA

Hi Ken-ichirou,

Quoted 15 lines · Ken-ichirou MATSUZAWA

From 9e8aa4ed079b526faf190b69a2c1032f22776602 Mon Sep 17 00:00:00 2001
From: Ken-ichirou MATSUZAWA <[email protected]>
Date: Tue, 28 Feb 2017 11:34:29 +0900
Subject: [PATCH 2/2] conntrack: revert getobjopt_is_nat condition

---
 src/conntrack/objopt.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
src/conntrack/objopt.c +0 -0
index fb43d6c..1581480 100644

src/conntrack/objopt.c int __setobjopt(struct nf_conntrack *ct, unsigned int option) · line 148

Quoted 9 lines
src/conntrack/objopt.c +2 -4
@@ -144,10 +144,8 @@ int __setobjopt(struct nf_conntrack *ct, unsigned int option)
 
 static int getobjopt_is_snat(const struct nf_conntrack *ct)
 {
-	if (!(test_bit(ATTR_STATUS, ct->head.set)))
-		return 0;
-
-	if (!(ct->status & IPS_SRC_NAT_DONE))
+	if (test_bit(ATTR_STATUS, ct->head.set) &&
+	    !(ct->status & IPS_SRC_NAT_DONE))

However, if ATTR_STATUS is not set, we keep checking ahead. What are you trying to fix?

#6 lore raw

Re: [PATCH lnfct 2/2] conntrack: revert getobjopt_is_nat condition

In reply to Ken-ichirou MATSUZAWA
Quoted 28 lines · Ken-ichirou MATSUZAWA

Hi, Pablo

Quoted 6 lines · Pablo Neira Ayuso
Quoted 6 lines
src/conntrack/objopt.c +0 -0
index fb43d6c..1581480 100644
@@ -144,10 +144,8 @@ int __setobjopt(struct nf_conntrack *ct, unsigned int option)
 
Quoted 11 lines

src/conntrack/objopt.c int __setobjopt(struct nf_conntrack *ct, unsigned int option) · line 148

Quoted 8 lines
src/conntrack/objopt.c +2 -4
 static int getobjopt_is_snat(const struct nf_conntrack *ct)
 {
-	if (!(test_bit(ATTR_STATUS, ct->head.set)))
-		return 0;
-
-	if (!(ct->status & IPS_SRC_NAT_DONE))
+	if (test_bit(ATTR_STATUS, ct->head.set) &&
+	    !(ct->status & IPS_SRC_NAT_DONE))

However, if ATTR_STATUS is not set, we keep checking ahead. What are you trying to fix?

It was:

(quoted diff) +0 -4
-       return ((test_bit(ATTR_STATUS, ct->head.set) ?
-               ct->status & IPS_SRC_NAT_DONE : 1) &&
-               ct->repl.dst.v4 !=
-               ct->head.orig.src.v4);
Quoted 3 lines

I thought it keeps checking even ATTR_STATUS is not set. But it's ok not to apply, returning false in case of ATTR_STATUS is not set.

Ah, I see.

static int getobjopt_is_snat(const struct nf_conntrack *ct)

{
        if (!(test_bit(ATTR_STATUS, ct->head.set)))
                return 0;

        if (!(ct->status & IPS_SRC_NAT_DONE))
                return 0;

        switch (ct->head.orig.l3protonum) {
        case AF_INET:
                return ct->repl.dst.v4 != ct->head.orig.src.v4;
        case AF_INET6:
                if (memcmp(&ct->repl.dst.v6, &ct->head.orig.src.v6,
                           sizeof(struct in6_addr)) != 0)
                        return 1;
                else
                        return 0;
        default:
                return 0;
        }
}

So you want to check if the addresses mismatch, so we infer from there if there is NAT or not when status bits are not available.

Are you trying to catch up some case in netlink event specifically?

Thanks for explaining.

#5 lore raw

Re: [PATCH lnfct 2/2] conntrack: revert getobjopt_is_nat condition

In reply to Pablo Neira Ayuso

Hi, Pablo

Quoted 6 lines · Pablo Neira Ayuso
Quoted 6 lines
src/conntrack/objopt.c +0 -0
index fb43d6c..1581480 100644
@@ -144,10 +144,8 @@ int __setobjopt(struct nf_conntrack *ct, unsigned int option)
 
Quoted 11 lines

src/conntrack/objopt.c int __setobjopt(struct nf_conntrack *ct, unsigned int option) · line 148

Quoted 8 lines
src/conntrack/objopt.c +2 -4
 static int getobjopt_is_snat(const struct nf_conntrack *ct)
 {
-	if (!(test_bit(ATTR_STATUS, ct->head.set)))
-		return 0;
-
-	if (!(ct->status & IPS_SRC_NAT_DONE))
+	if (test_bit(ATTR_STATUS, ct->head.set) &&
+	    !(ct->status & IPS_SRC_NAT_DONE))

However, if ATTR_STATUS is not set, we keep checking ahead. What are you trying to fix?

It was:

- return ((test_bit(ATTR_STATUS, ct->head.set) ?

-               ct->status & IPS_SRC_NAT_DONE : 1) &&
-               ct->repl.dst.v4 !=
-               ct->head.orig.src.v4);

I thought it keeps checking even ATTR_STATUS is not set. But it's ok not to apply, returning false in case of ATTR_STATUS is not set.

Thanks,

#7 lore raw

Re: [PATCH lnfct 2/2] conntrack: revert getobjopt_is_nat condition

In reply to Pablo Neira Ayuso

Hi, Pablo

Quoted 4 lines · Pablo Neira Ayuso

So you want to check if the addresses mismatch, so we infer from there if there is NAT or not when status bits are not available.

Are you trying to catch up some case in netlink event specifically?

It's nothing. My skimping test for lnfct binding for another languate which set only ATTR_REPL_IPV4DST then get NFCT_GOPT_IS_NAT was success, but it fails now.

Thanks,

#8 lore raw

Re: [PATCH lnfct 2/2] conntrack: revert getobjopt_is_nat condition

Quoted 11 lines · Ken-ichirou MATSUZAWA

Hi, Pablo

Quoted 4 lines · Pablo Neira Ayuso

So you want to check if the addresses mismatch, so we infer from there if there is NAT or not when status bits are not available.

Are you trying to catch up some case in netlink event specifically?

It's nothing. My skimping test for lnfct binding for another languate which set only ATTR_REPL_IPV4DST then get NFCT_GOPT_IS_NAT was success, but it fails now.

I see, we should restore the original behaviour, I think your patch is correct then.

#9 lore raw

Re: [PATCH lnfct 2/2] conntrack: revert getobjopt_is_nat condition

Quoted 7 lines · Pablo Neira Ayuso
Quoted 6 lines · Ken-ichirou MATSUZAWA

Hi, Pablo

Quoted 3 lines · Pablo Neira Ayuso

So you want to check if the addresses mismatch, so we infer from there if there is NAT or not when status bits are not available.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Are you trying to catch up some case in netlink event specifically?

It's nothing. My skimping test for lnfct binding for another languate which set only ATTR_REPL_IPV4DST then get NFCT_GOPT_IS_NAT was success, but it fails now.

I see, we should restore the original behaviour, I think your patch is correct then.

JFYI: I have applied this patch, thanks for explaining.

BTW, it would be great if you can add some short description to your follow up patch. If English is a concern, don't bother much about it, we're non-native speaker mostly :)

Thanks!