diff --git a/libnetwork/iptables/firewalld.go b/libnetwork/iptables/firewalld.go index ffd1880658..7fca5aec94 100644 --- a/libnetwork/iptables/firewalld.go +++ b/libnetwork/iptables/firewalld.go @@ -12,14 +12,11 @@ import ( dbus "github.com/godbus/dbus/v5" ) -// IPV defines the table string -type IPV string - const ( - // Iptables point ipv4 table - Iptables IPV = "ipv4" - // IP6Tables point to ipv6 table - IP6Tables IPV = "ipv6" + // ipTables point ipv4 table + ipTables = "ipv4" + // ip6Tables point to ipv6 table + ip6Tables = "ipv6" ) const ( @@ -219,7 +216,13 @@ func (fwd *firewalldConnection) isRunning() bool { } // Passthrough method simply passes args through to iptables/ip6tables -func Passthrough(ipv IPV, args ...string) ([]byte, error) { +func Passthrough(ipVersion IPVersion, args ...string) ([]byte, error) { + // select correct IP version for firewalld + ipv := ipTables + if ipVersion == IPv6 { + ipv = ip6Tables + } + var output string log.G(context.TODO()).Debugf("Firewalld passthrough: %s, %s", ipv, args) if err := firewalld.sysObj.Call(dbusInterface+".direct.passthrough", 0, ipv, args).Store(&output); err != nil { diff --git a/libnetwork/iptables/firewalld_test.go b/libnetwork/iptables/firewalld_test.go index 6021afe5b3..bf159333b8 100644 --- a/libnetwork/iptables/firewalld_test.go +++ b/libnetwork/iptables/firewalld_test.go @@ -100,7 +100,7 @@ func TestPassthrough(t *testing.T) { "-j", "ACCEPT", } - _, err := Passthrough(Iptables, append([]string{"-A"}, rule1...)...) + _, err := Passthrough(IPv4, append([]string{"-A"}, rule1...)...) if err != nil { t.Fatal(err) } diff --git a/libnetwork/iptables/iptables.go b/libnetwork/iptables/iptables.go index 7a5cfcf1f1..62d58f28fd 100644 --- a/libnetwork/iptables/iptables.go +++ b/libnetwork/iptables/iptables.go @@ -519,14 +519,8 @@ func filterOutput(start time.Time, output []byte, args ...string) []byte { // Raw calls 'iptables' system command, passing supplied arguments. func (iptable IPTable) Raw(args ...string) ([]byte, error) { if firewalld.isRunning() { - // select correct IP version for firewalld - ipv := Iptables - if iptable.ipVersion == IPv6 { - ipv = IP6Tables - } - startTime := time.Now() - output, err := Passthrough(ipv, args...) + output, err := Passthrough(iptable.ipVersion, args...) if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") { return filterOutput(startTime, output, args...), err }