Skip to content

Commit

Permalink
add tunnel logging
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Mar 21, 2022
1 parent f2b9db6 commit 143a999
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tunnel/handler/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,21 @@ func isPrivateIP(host string) bool {
addr = addrs[0]
}

logger.Info("Parsing address ", addr)
logger.Infof("Checking host %v address %v", host, addr)
ip := net.ParseIP(addr)

if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
logger.Infof("Blocked ip local host %v address %v", host, addr)
return true
}

for _, block := range privateIPs {
if block.Contains(ip) {
logger.Infof("Blocked ip cidr host %v address %v", host, addr)
return true
}
}

logger.Info("No match for address ", addr)
logger.Infof("No match for ip host %v address %v", host, addr)
return false
}
2 changes: 2 additions & 0 deletions tunnel/handler/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ func (e *Tunnel) Send(ctx context.Context, req *pb.SendRequest, rsp *pb.SendResp

// check if its a private ip
if isPrivateIP(uri.Host) {
logger.Infof("Blocked private host %v", uri.Host)
return errors.BadRequest("tunnel.send", "cannot send to private ip")
}

// check if its in the block list
if e.Blocklist[strings.ToLower(uri.Host)] {
logger.Infof("Blocked host %v in blocklist", uri.Host)
return errors.Forbidden("tunnel.send", "request not allowed")
}

Expand Down

0 comments on commit 143a999

Please sign in to comment.