func (r Route) Validate() error {
	// Make sure the CIDR is actually a CIDR not just an IP or hostname
	destinationIP, _, err := net.ParseCIDR(r.DestinationCIDR)
	if err != nil {
		return errors.Annotate(err, "DestinationCIDR not valid")
	}
	// Make sure the Gateway is just an IP, not a CIDR, etc.
	gatewayIP := net.ParseIP(r.GatewayIP)
	if gatewayIP == nil {
		return errors.Errorf("GatewayIP is not a valid IP address: %q", r.GatewayIP)
	}
	if r.Metric < 0 {
		return errors.Errorf("Metric is negative: %d", r.Metric)
	}
	// Make sure that either both are IPv4 or both are IPv6, not mixed.
	destIP4 := destinationIP.To4()
	gatewayIP4 := gatewayIP.To4()
	if destIP4 != nil {
		if gatewayIP4 == nil {
			return errors.Errorf("DestinationCIDR is IPv4 (%s) but GatewayIP is IPv6 (%s)", r.DestinationCIDR, r.GatewayIP)
		}
	} else {
		if gatewayIP4 != nil {
			return errors.Errorf("DestinationCIDR is IPv6 (%s) but GatewayIP is IPv4 (%s)", r.DestinationCIDR, r.GatewayIP)
		}
	}
	return nil
}
// Validate that this Route is properly formed.
Validate that this Route is properly formed.
// Validate that this Route is properly formed .
func (r Route) Validate() error {
	destinationIP, _, err := net.ParseCIDR(r.DestinationCIDR)
	if err != nil {
		return errors.Annotate(err, "DestinationCIDR not valid")
	}
	gatewayIP := net.ParseIP(r.GatewayIP)
	if gatewayIP == nil {
		return errors.Errorf("GatewayIP is not a valid IP address: %q", r.GatewayIP)
	}
	if r.Metric < 0 {
		return errors.Errorf("Metric is negative: %d", r.Metric)
	}
	destIP4 := destinationIP.To4()
	gatewayIP4 := gatewayIP.To4()
	if destIP4 != nil {
		if gatewayIP4 == nil {
			return errors.Errorf("DestinationCIDR is IPv4 (%s) but GatewayIP is IPv6 (%s)", r.DestinationCIDR, r.GatewayIP)
		}
	} else {
		if gatewayIP4 != nil {
			return errors.Errorf("DestinationCIDR is IPv6 (%s) but GatewayIP is IPv4 (%s)", r.DestinationCIDR, r.GatewayIP)
		}
	}
	return nil
}
func ( r Route ) Validate ( ) error { destinationIP , _ , err := net . ParseCIDR ( r . DestinationCIDR ) if err != nil { return errors . Annotate ( err , " " ) } gatewayIP := net . ParseIP ( r . GatewayIP ) if gatewayIP == nil { return errors . Errorf ( " " , r . GatewayIP ) } if r . Metric < 0 { return errors . Errorf ( " " , r . Metric ) } destIP4 := destinationIP . To4 ( ) gatewayIP4 := gatewayIP . To4 ( ) if destIP4 != nil { if gatewayIP4 == nil { return errors . Errorf ( " " , r . DestinationCIDR , r . GatewayIP ) } } else { if gatewayIP4 != nil { return errors . Errorf ( " " , r . DestinationCIDR , r . GatewayIP ) } } return nil }
Validate that this Route is properly formed.
Validate that this Route is properly formed .
// Make sure the CIDR is actually a CIDR not just an IP or hostname // Make sure the Gateway is just an IP, not a CIDR, etc. // Make sure that either both are IPv4 or both are IPv6, not mixed.