Files
ctrld/internal/clientinfo/vpn.go
Cuong Manh Le 0f3e8c7ada all: include client IP if ctrld is dnsmasq upstream
So ctrld can record the raw/original client IP instead of looking up
from MAC to IP, which may not the right choice in some network setup
like using wireguard/vpn on Merlin router.
2023-09-22 18:40:25 +07:00

44 lines
827 B
Go

package clientinfo
import (
"sync"
)
// vpn is the manager for VPN clients info.
type vpn struct {
ip2name sync.Map // ip => name
mac sync.Map // ip => mac
}
// LookupHostnameByIP returns hostname of the given VPN client ip.
func (v *vpn) LookupHostnameByIP(ip string) string {
val, ok := v.ip2name.Load(ip)
if !ok {
return ""
}
return val.(string)
}
// LookupHostnameByMac always returns empty string.
func (v *vpn) LookupHostnameByMac(mac string) string {
return ""
}
// String returns the string representation of vpn struct.
func (v *vpn) String() string {
return "vpn"
}
// List lists all known VPN clients IP.
func (v *vpn) List() []string {
if v == nil {
return nil
}
var ips []string
v.mac.Range(func(key, value any) bool {
ips = append(ips, key.(string))
return true
})
return ips
}