瀏覽代碼

libnetwork/iptables: Passthrough: re-use IPVersion type

Use the existing IPVersion type to switch between ipv4 and ipv6. The IPV
type was only used for this function, and currently required callers to
map a IPVersion to IPV.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 年之前
父節點
當前提交
55f2e111e9
共有 3 個文件被更改,包括 13 次插入16 次删除
  1. 11 8
      libnetwork/iptables/firewalld.go
  2. 1 1
      libnetwork/iptables/firewalld_test.go
  3. 1 7
      libnetwork/iptables/iptables.go

+ 11 - 8
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 {

+ 1 - 1
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)
 	}

+ 1 - 7
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
 		}