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:
parent
47063ca3ae
commit
aad2dbb93d
1 changed files with 11 additions and 1 deletions
|
@ -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}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue