You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/09/07 15:48:09 UTC

[GitHub] DylanVolz commented on a change in pull request #2792: validate that a servers ip6address field is an IPv6 address or CIDR

DylanVolz commented on a change in pull request #2792: validate that a servers ip6address field is an IPv6 address or CIDR
URL: https://github.com/apache/trafficcontrol/pull/2792#discussion_r216004455
 
 

 ##########
 File path: lib/go-tc/tovalidate/rules.go
 ##########
 @@ -129,3 +130,33 @@ func IsValidPortNumber(value interface{}) error {
 	}
 	return errors.New("must be a valid port number")
 }
+
+func IsValidIPv6CIDROrAddress(value interface{}) error {
+	switch v := value.(type) {
+	case *string:
+		if v == nil {
+			return nil
+		}
+		ip, _, err := net.ParseCIDR(*v)
+		if err == nil {
+			if ip.To4() == nil {
+				return nil
+			} else {
+				return fmt.Errorf("got IPv4 CIDR, IPv6 expected")
+			}
+		} else {
+			ip := net.ParseIP(*v)
+			if ip != nil {
 
 Review comment:
   Yeah, we can because we don't care about the difference between an un-parseable string and an IPv4 address.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services