From aad2dbb93dbf8b57bfe0d9728aae2ec0652a159d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 16 Jul 2023 13:39:12 +0200 Subject: [PATCH] libnetwork/iptables: GetIptable: validate provided IPversion For backward-compatibility, continue to accept empty strings as default (IPv4). Signed-off-by: Sebastiaan van Stijn --- libnetwork/iptables/iptables.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libnetwork/iptables/iptables.go b/libnetwork/iptables/iptables.go index d6add67b53..e68f866983 100644 --- a/libnetwork/iptables/iptables.go +++ b/libnetwork/iptables/iptables.go @@ -144,8 +144,18 @@ func initCheck() error { 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 { + 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} }