diff --git a/src/mod/netutils/ipmatch.go b/src/mod/netutils/ipmatch.go index d969454..b5f6ff4 100644 --- a/src/mod/netutils/ipmatch.go +++ b/src/mod/netutils/ipmatch.go @@ -57,12 +57,7 @@ func GetRequesterIP(r *http.Request) string { //e.g. [15c4:cbb4:cc98:4291:ffc1:3a46:06a1:51a7] requesterRawIp = requesterRawIp[1 : len(requesterRawIp)-1] } - - // Trim away scope ID if present (e.g. %eth0 in IPv6) - if i := strings.Index(requesterRawIp, "%"); i != -1 { - requesterRawIp = requesterRawIp[:i] - } - + return requesterRawIp } @@ -92,6 +87,11 @@ func MatchIpWildcard(ipAddress, wildcard string) bool { // Match ip address with CIDR func MatchIpCIDR(ip string, cidr string) bool { + // Trim away scope ID if present in IP (e.g. fe80::1%eth0) + if i := strings.Index(ip, "%"); i != -1 { + ip = ip[:i] + } + // parse the CIDR string _, cidrnet, err := net.ParseCIDR(cidr) if err != nil {