(ranges []string)
| 282 | } |
| 283 | |
| 284 | func provisionCidrsZonesFromRanges(ranges []string) ([]*netip.Prefix, []string, error) { |
| 285 | cidrs := []*netip.Prefix{} |
| 286 | zones := []string{} |
| 287 | repl := caddy.NewReplacer() |
| 288 | for _, str := range ranges { |
| 289 | str = repl.ReplaceAll(str, "") |
| 290 | // Exclude the zone_id from the IP |
| 291 | if strings.Contains(str, "%") { |
| 292 | split := strings.Split(str, "%") |
| 293 | str = split[0] |
| 294 | // write zone identifiers in m.zones for matching later |
| 295 | zones = append(zones, split[1]) |
| 296 | } else { |
| 297 | zones = append(zones, "") |
| 298 | } |
| 299 | if strings.Contains(str, "/") { |
| 300 | ipNet, err := netip.ParsePrefix(str) |
| 301 | if err != nil { |
| 302 | return nil, nil, fmt.Errorf("parsing CIDR expression '%s': %v", str, err) |
| 303 | } |
| 304 | cidrs = append(cidrs, &ipNet) |
| 305 | } else { |
| 306 | ipAddr, err := netip.ParseAddr(str) |
| 307 | if err != nil { |
| 308 | return nil, nil, fmt.Errorf("invalid IP address: '%s': %v", str, err) |
| 309 | } |
| 310 | ipNew := netip.PrefixFrom(ipAddr, ipAddr.BitLen()) |
| 311 | cidrs = append(cidrs, &ipNew) |
| 312 | } |
| 313 | } |
| 314 | return cidrs, zones, nil |
| 315 | } |
| 316 | |
| 317 | func parseIPZoneFromString(address string) (netip.Addr, string, error) { |
| 318 | ipStr, _, err := net.SplitHostPort(address) |
no test coverage detected