Skip to content

Commit

Permalink
add ipv6 check (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
happytreees committed Sep 27, 2023
1 parent ee60acd commit d767651
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions vultr/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,16 @@ func buildFirewallRules(service *v1.Service) ([]govultr.LBFirewallRule, error) {
}

source := rules[0]
ipType := "v4"
if source != "cloudflare" {
_, _, err := net.ParseCIDR(source)
ip, _, err := net.ParseCIDR(source)
if err != nil {
return nil, fmt.Errorf("loadbalancer fw rules : source %s is invalid", source)
}

if ip.To4() == nil {
ipType = "v6"
}
}

port, err := strconv.Atoi(rules[1])
Expand All @@ -808,7 +813,7 @@ func buildFirewallRules(service *v1.Service) ([]govultr.LBFirewallRule, error) {
}

fwRule.Source = source
fwRule.IPType = "v4"
fwRule.IPType = ipType
fwRule.Port = port
lbFWRules = append(lbFWRules, fwRule)
}
Expand Down

0 comments on commit d767651

Please sign in to comment.