Skip to contentSkip to conversation

network/iptables: add ipv6 support

PATCH New Alexey Kodanev 2 participants 5 messages Dec 26, 2019 – Jan 9, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 network/iptables: add ipv6 support

New tests: ip6tables, nft6.

---
 runtest/net.ipv6                           |   2 +
 testcases/network/iptables/iptables_lib.sh | 120 +++++++++++----------
 testcases/network/iptables/nft01.sh        |  17 +--
 3 files changed, 77 insertions(+), 62 deletions(-)
runtest/net.ipv6 +2 -0
index a238a087a..e599978c0 100644
@@ -8,3 +8,5 @@ traceroute601 traceroute01.sh -6
 dhcpd6 dhcpd_tests.sh -6
 dnsmasq6 dnsmasq_tests.sh -6
 ipneigh6_ip ipneigh01.sh -6 -c ip
+ip6tables iptables01.sh -6
+nft6 nft01.sh -6
testcases/network/iptables/iptables_lib.sh +64 -56

295 lines not on this page · raw message

testcases/network/iptables/nft01.sh +11 -6
index 6cbd7a3a6..1ae086678 100755
@@ -4,6 +4,7 @@
 
 TST_SETUP="do_setup"
 TST_CLEANUP="do_cleanup"
+TST_NEEDS_DRIVERS="nf_tables"
 use_iptables=0
 cleanup_table=0
 cleanup_chain=0
@@ -12,12 +13,14 @@ cleanup_chain=0
 
 do_setup()
 {
-	if ! nft list table ip filter > /dev/null 2>&1; then
-		ROD nft add table ip filter
+	local ip_table="ip${TST_IPV6}"
+
+	if ! nft list table $ip_table filter > /dev/null 2>&1; then
+		ROD nft add table $ip_table filter
 		cleanup_table=1
 	fi
-	if ! nft list chain ip filter INPUT > /dev/null 2>&1; then
-		ROD nft add chain ip filter INPUT '{ type filter hook input priority 0; }'
+	if ! nft list chain $ip_table filter INPUT > /dev/null 2>&1; then
+		ROD nft add chain $ip_table filter INPUT '{ type filter hook input priority 0; }'
 		cleanup_chain=1
 	fi
 	init
@@ -25,8 +28,10 @@ do_setup()
 
 do_cleanup()
 {
-	[ "$cleanup_chain" = 1 ] && nft delete chain ip filter INPUT >/dev/null 2>&1
-	[ "$cleanup_table" = 1 ] && nft delete table ip filter >/dev/null 2>&1
+	local ip_table="ip${TST_IPV6}"
+
+	[ "$cleanup_chain" = 1 ] && nft delete chain $ip_table filter INPUT >/dev/null 2>&1
+	[ "$cleanup_table" = 1 ] && nft delete table $ip_table filter >/dev/null 2>&1
 	cleanup
 }
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 network/iptables: add ipv6 support

Hi Alexey,

Quoted 1 line

New tests: ip6tables, nft6.

great idea, just there is a regression in nft01.sh, see below.

Quoted 1 line
Quoted 1 line

--- a/testcases/network/iptables/iptables_lib.sh

...

Quoted 11 lines

init()
{

(quoted diff) +9 -0
+	if [ "$use_iptables" = 1 ]; then
+		toolname=ip${TST_IPV6}tables
+		cmds="$toolname"
+		tst_require_drivers ip${TST_IPV6}_tables
+	else
+		toolname=nft
+		cmds="$toolname ip${TST_IPV6}tables-translate"
+	fi
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+	if [ "$TST_IPV6" ];then
+		loc_addr="::1"
+		proto="icmpv6"
+	else
+		loc_addr="127.0.0.1"
+		proto="icmp"
+	fi
+
+	ping_cmd="ping$TST_IPV6"
+	tst_require_cmds $cmds $ping_cmd

change to tst_require_cmds() does not catch missing nft:

nft check broke, original:
nft01 1 TCONF: 'nft' not found

now:
/bin/sh: 1: nft: not found
nft01 1 TBROK: nft add table ip filter failed

one of these fixes it (take whatever you like. Both variants check nft twice, I'd ignore it).

* use TST_NEEDS_CMDS

network/iptables/iptables_lib.sh +1 -1
index ad2a894b6..8d220bc0e 100755
@@ -12,7 +12,7 @@ TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 TST_SETUP="${TST_SETUP:-init}"
 TST_CLEANUP="${TST_CLEANUP:-cleanup}"
-TST_NEEDS_CMDS="grep telnet"
+TST_NEEDS_CMDS="$TST_NEEDS_CMDS grep telnet"
 
 . tst_net.sh
 
network/iptables/nft01.sh +1 -0
index 1ae086678..225f59bc5 100755
@@ -5,6 +5,7 @@
 TST_SETUP="do_setup"
 TST_CLEANUP="do_cleanup"
 TST_NEEDS_DRIVERS="nf_tables"
+TST_NEEDS_CMDS="nft"
 use_iptables=0
 cleanup_table=0
 cleanup_chain=0

* use tst_require_cmds

network/iptables/nft01.sh +1 -0
index 1ae086678..e5799b918 100755
@@ -15,6 +15,7 @@ do_setup()
 {
 	local ip_table="ip${TST_IPV6}"
 
+	tst_require_cmds nft
 	if ! nft list table $ip_table filter > /dev/null 2>&1; then
 		ROD nft add table $ip_table filter
 		cleanup_table=1

Kind regards,
Petr

#2 lore raw

PATCH 1/1 network/iptables: add ipv6 support

Hi Petr,

Quoted 34 lines · Petr Vorel

Hi Alexey,

Quoted 1 line

New tests: ip6tables, nft6.

great idea, just there is a regression in nft01.sh, see below.

Quoted 1 line
Quoted 1 line

--- a/testcases/network/iptables/iptables_lib.sh

...

Quoted 11 lines

init()
{

(quoted diff) +9 -0
+	if [ "$use_iptables" = 1 ]; then
+		toolname=ip${TST_IPV6}tables
+		cmds="$toolname"
+		tst_require_drivers ip${TST_IPV6}_tables
+	else
+		toolname=nft
+		cmds="$toolname ip${TST_IPV6}tables-translate"
+	fi
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+	if [ "$TST_IPV6" ];then
+		loc_addr="::1"
+		proto="icmpv6"
+	else
+		loc_addr="127.0.0.1"
+		proto="icmp"
+	fi
+
+	ping_cmd="ping$TST_IPV6"
+	tst_require_cmds $cmds $ping_cmd

change to tst_require_cmds() does not catch missing nft:

Quoted 6 lines

nft check broke, original:
nft01 1 TCONF: 'nft' not found

now:
/bin/sh: 1: nft: not found
nft01 1 TBROK: nft add table ip filter failed

Good catch, what about starting with init() in do_setup()?

testcases/network/iptables/nft01.sh +1 -1
index 1ae086678..bf2a53c28 100755
@@ -13,6 +13,7 @@ cleanup_chain=0
 
 do_setup()
 {
+       init
        local ip_table="ip${TST_IPV6}"
 
        if ! nft list table $ip_table filter > /dev/null 2>&1; then
@@ -23,7 +24,6 @@ do_setup()
                ROD nft add chain $ip_table filter INPUT '{ type filter hook input priority 0; }'
                cleanup_chain=1
        fi
-       init
 }
 
 
Quoted 49 lines

one of these fixes it (take whatever you like. Both variants check nft twice, I'd ignore it).

* use TST_NEEDS_CMDS

network/iptables/iptables_lib.sh +1 -1
index ad2a894b6..8d220bc0e 100755
@@ -12,7 +12,7 @@ TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 TST_SETUP="${TST_SETUP:-init}"
 TST_CLEANUP="${TST_CLEANUP:-cleanup}"
-TST_NEEDS_CMDS="grep telnet"
+TST_NEEDS_CMDS="$TST_NEEDS_CMDS grep telnet"
 
 . tst_net.sh
 
network/iptables/nft01.sh +1 -0
index 1ae086678..225f59bc5 100755
@@ -5,6 +5,7 @@
 TST_SETUP="do_setup"
 TST_CLEANUP="do_cleanup"
 TST_NEEDS_DRIVERS="nf_tables"
+TST_NEEDS_CMDS="nft"
 use_iptables=0
 cleanup_table=0
 cleanup_chain=0

* use tst_require_cmds

network/iptables/nft01.sh +1 -0
index 1ae086678..e5799b918 100755
@@ -15,6 +15,7 @@ do_setup()
 {
 	local ip_table="ip${TST_IPV6}"
 
+	tst_require_cmds nft
 	if ! nft list table $ip_table filter > /dev/null 2>&1; then
 		ROD nft add table $ip_table filter
 		cleanup_table=1

Kind regards,
Petr

#3 lore raw

PATCH 1/1 network/iptables: add ipv6 support

Hi Alexey,

Quoted 19 lines
Quoted 3 lines

now:
/bin/sh: 1: nft: not found
nft01 1 TBROK: nft add table ip filter failed

Good catch, what about starting with init() in do_setup()?

testcases/network/iptables/nft01.sh +1 -0
index 1ae086678..bf2a53c28 100755
@@ -13,6 +13,7 @@ cleanup_chain=0
 
 do_setup()
 {
+       init
        local ip_table="ip${TST_IPV6}"
 
        if ! nft list table $ip_table filter > /dev/null 2>&1; then

testcases/network/iptables/nft01.sh do_setup() · line 27

Quoted 5 lines
testcases/network/iptables/nft01.sh +0 -1
@@ -23,7 +24,6 @@ do_setup()
                ROD nft add chain $ip_table filter INPUT '{ type filter hook input priority 0; }'
                cleanup_chain=1
        fi
-       init
 }

Great, what a simple fix :).

Kind regards,
Petr

#4 lore raw

PATCH 1/1 network/iptables: add ipv6 support

Quoted 19 lines · Petr Vorel

Hi Alexey,

Quoted 16 lines
Quoted 3 lines

now:
/bin/sh: 1: nft: not found
nft01 1 TBROK: nft add table ip filter failed

Good catch, what about starting with init() in do_setup()?

testcases/network/iptables/nft01.sh +1 -0
index 1ae086678..bf2a53c28 100755
@@ -13,6 +13,7 @@ cleanup_chain=0
 
 do_setup()
 {
+       init
        local ip_table="ip${TST_IPV6}"
Quoted 10 lines

testcases/network/iptables/nft01.sh do_setup() · line 27

Quoted 7 lines
testcases/network/iptables/nft01.sh +0 -1
        if ! nft list table $ip_table filter > /dev/null 2>&1; then
@@ -23,7 +24,6 @@ do_setup()
                ROD nft add chain $ip_table filter INPUT '{ type filter hook input priority 0; }'
                cleanup_chain=1
        fi
-       init
 }

Great, what a simple fix :).

Applied with this change, thanks for your review Petr!