MCPcopy
hub / github.com/moby/moby / validateIpamConfig

Function validateIpamConfig

daemon/network.go:457–493  ·  view source on GitHub ↗
(data []networktypes.IPAMConfig, enableIPv6 bool)

Source from the content-addressed store, hash-verified

455}
456
457func validateIpamConfig(data []networktypes.IPAMConfig, enableIPv6 bool) error {
458 var errs []error
459 for _, cfg := range data {
460 subnetFamily := 4
461 if cfg.Subnet.Addr().Is6() {
462 subnetFamily = 6
463 }
464
465 if !enableIPv6 && subnetFamily == 6 {
466 continue
467 }
468
469 if cfg.Subnet != cfg.Subnet.Masked() {
470 errs = append(errs, fmt.Errorf("invalid subnet %s: it should be %s", cfg.Subnet, cfg.Subnet.Masked()))
471 }
472
473 if ipRangeErrs := validateIPRange(cfg.IPRange, cfg.Subnet, subnetFamily); len(ipRangeErrs) > 0 {
474 errs = append(errs, ipRangeErrs...)
475 }
476
477 if err := validateAddress(cfg.Gateway, cfg.Subnet, subnetFamily); err != nil {
478 errs = append(errs, fmt.Errorf("invalid gateway %s: %w", cfg.Gateway, err))
479 }
480
481 for auxName, aux := range cfg.AuxAddress {
482 if err := validateAddress(aux, cfg.Subnet, subnetFamily); err != nil {
483 errs = append(errs, fmt.Errorf("invalid auxiliary address %s: %w", auxName, err))
484 }
485 }
486 }
487
488 if err := multierror.Join(errs...); err != nil {
489 return fmt.Errorf("invalid network config:\n%w", err)
490 }
491
492 return nil
493}
494
495func validateIPRange(ipRange, subnet netip.Prefix, subnetFamily int) []error {
496 if !ipRange.IsValid() {

Callers 2

TestValidateIPAMFunction · 0.85
createNetworkMethod · 0.85

Calls 6

JoinFunction · 0.92
validateIPRangeFunction · 0.85
validateAddressFunction · 0.85
Is6Method · 0.80
ErrorfMethod · 0.80
AddrMethod · 0.65

Tested by 1

TestValidateIPAMFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…