Explorar o código

libnetwork/iptables: GetIptable: validate provided IPversion

For backward-compatibility, continue to accept empty strings
as default (IPv4).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn %!s(int64=2) %!d(string=hai) anos
pai
achega
aad2dbb93d
Modificáronse 1 ficheiros con 11 adicións e 1 borrados
  1. 11 1
      libnetwork/iptables/iptables.go

+ 11 - 1
libnetwork/iptables/iptables.go

@@ -144,8 +144,18 @@ func initCheck() error {
 	return nil
 	return nil
 }
 }
 
 
-// GetIptable returns an instance of IPTable with specified version
+// GetIptable returns an instance of IPTable with specified version ([IPv4]
+// or [IPv6]). It panics if an invalid [IPVersion] is provided.
 func GetIptable(version IPVersion) *IPTable {
 func GetIptable(version IPVersion) *IPTable {
+	switch version {
+	case IPv4, IPv6:
+		// valid version
+	case "":
+		// default is IPv4 for backward-compatibility
+		version = IPv4
+	default:
+		panic("unknown IP version: " + version)
+	}
 	return &IPTable{ipVersion: version}
 	return &IPTable{ipVersion: version}
 }
 }