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:34:43 UTC

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

dewrich 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_r216000128
 
 

 ##########
 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:
   You can't combine this nested if?

----------------------------------------------------------------
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