Skip to content

Commit

Permalink
fix handler
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Mar 20, 2022
1 parent 6bde22d commit 8019835
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tunnel/handler/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,24 @@ func init() {
}
}

func isPrivateIP(addr string) bool {
func isPrivateIP(host string) bool {
var addr string

// split on host port
h, _, err := net.SplitHostPort(host)
if err == nil {
host = h
}

// resolve the host
addrs, err := net.LookupHost(host)
if err != nil {
addr = host
} else {
addr = addrs[0]
}

logger.Info("Parsing address ", addr)
ip := net.ParseIP(addr)

if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
Expand All @@ -43,5 +60,6 @@ func isPrivateIP(addr string) bool {
}
}

logger.Info("No match for address ", addr)
return false
}

0 comments on commit 8019835

Please sign in to comment.