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>
This commit is contained in:
Sebastiaan van Stijn 2023-07-16 13:39:12 +02:00
parent 47063ca3ae
commit aad2dbb93d
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -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}
}