func ValidateCIDRs(ss []string) error {

	cidrmap := make(map[string]*cidr)
	// instantiate NewPCTrieRanger
	ranger := cidranger.NewPCTrieRanger()

	for _, s := range ss {
		cidr, err := parseCIDR(s)
		if err != nil {
			return err
		}
		if _, ok := cidrmap[cidr.ipNet.String()]; !ok {
			cidrmap[cidr.ipNet.String()] = cidr
		} else {
			return fmt.Errorf("CIDR subnet parsed from %s is duplicated", cidr.str)
		}
		if err := ranger.Insert(newCustomRangerEntry(cidr)); err != nil {
			return fmt.Errorf("Error adding CIDR %s", cidr.str)
		}
	}

	// Parse and validate all not CIDRs are included in regular CIDRs
	for _, c := range cidrmap {

		if c.op == opExclude {

			entries, err := ranger.ContainingNetworks(c.ipNet.IP)
			if err != nil {
				return fmt.Errorf("Cannot find the CIDR: %s", err)
			}

			mask := c.ipNet.Mask
			present := checkExcPfxContainedInc(entries, mask, c.ipNet)

			// if the excluded CIDR is not contained in the included CIDR then return error
			if !present {
				return fmt.Errorf("%s is not contained in any CIDR", c.str)
			}
		}
	}

	return nil
}
// ValidateCIDRs validates that the list of string provided as a set is a valid CIDR set
ValidateCIDRs validates that the list of string provided as a set is a valid CIDR set
// ValidateCIDRs validates that the list of string provided as a set is a valid CIDR set
func ValidateCIDRs(ss []string) error {
	cidrmap := make(map[string]*cidr)
	ranger := cidranger.NewPCTrieRanger()
	for _, s := range ss {
		cidr, err := parseCIDR(s)
		if err != nil {
			return err
		}
		if _, ok := cidrmap[cidr.ipNet.String()]; !ok {
			cidrmap[cidr.ipNet.String()] = cidr
		} else {
			return fmt.Errorf("CIDR subnet parsed from %s is duplicated", cidr.str)
		}
		if err := ranger.Insert(newCustomRangerEntry(cidr)); err != nil {
			return fmt.Errorf("Error adding CIDR %s", cidr.str)
		}
	}
	for _, c := range cidrmap {
		if c.op == opExclude {
			entries, err := ranger.ContainingNetworks(c.ipNet.IP)
			if err != nil {
				return fmt.Errorf("Cannot find the CIDR: %s", err)
			}
			mask := c.ipNet.Mask
			present := checkExcPfxContainedInc(entries, mask, c.ipNet)
			if !present {
				return fmt.Errorf("%s is not contained in any CIDR", c.str)
			}
		}
	}
	return nil
}
func ValidateCIDRs ( ss [ ] string ) error { cidrmap := make ( map [ string ] * cidr ) ranger := cidranger . NewPCTrieRanger ( ) for _ , s := range ss { cidr , err := parseCIDR ( s ) if err != nil { return err } if _ , ok := cidrmap [ cidr . ipNet . String ( ) ] ; ! ok { cidrmap [ cidr . ipNet . String ( ) ] = cidr } else { return fmt . Errorf ( " " , cidr . str ) } if err := ranger . Insert ( newCustomRangerEntry ( cidr ) ) ; err != nil { return fmt . Errorf ( " " , cidr . str ) } } for _ , c := range cidrmap { if c . op == opExclude { entries , err := ranger . ContainingNetworks ( c . ipNet . IP ) if err != nil { return fmt . Errorf ( " " , err ) } mask := c . ipNet . Mask present := checkExcPfxContainedInc ( entries , mask , c . ipNet ) if ! present { return fmt . Errorf ( " " , c . str ) } } } return nil }
ValidateCIDRs validates that the list of string provided as a set is a valid CIDR set
ValidateCIDRs validates that the list of string provided as a set is a valid CIDR set
// instantiate NewPCTrieRanger // Parse and validate all not CIDRs are included in regular CIDRs // if the excluded CIDR is not contained in the included CIDR then return error