mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-05-31 04:37:20 +02:00
Move Scope ID handling into CIDR check
This commit is contained in:
parent
e961e52dea
commit
23eeeee701
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user