mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
all: generalize vpn client info
VPN clients often have empty MAC address, because they come from virtual network interface. However, there's other setup/devices also create virtual interface, but is not VPN. Changing source of those clients to empty to prevent confustion in clients list command output.
This commit is contained in:
committed by
Cuong Manh Le
parent
8ddbf881b3
commit
6e28517454
@@ -74,7 +74,7 @@ type Table struct {
|
||||
ptr *ptrDiscover
|
||||
mdns *mdns
|
||||
hf *hostsFile
|
||||
vpn *vpn
|
||||
vni *virtualNetworkIface
|
||||
cfg *ctrld.Config
|
||||
quitCh chan struct{}
|
||||
selfIP string
|
||||
@@ -202,8 +202,8 @@ func (t *Table) init() {
|
||||
}
|
||||
// VPN clients.
|
||||
if t.discoverDHCP() || t.discoverARP() {
|
||||
t.vpn = &vpn{}
|
||||
t.hostnameResolvers = append(t.hostnameResolvers, t.vpn)
|
||||
t.vni = &virtualNetworkIface{}
|
||||
t.hostnameResolvers = append(t.hostnameResolvers, t.vni)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ func (t *Table) ListClients() []*Client {
|
||||
_ = r.refresh()
|
||||
}
|
||||
ipMap := make(map[string]*Client)
|
||||
il := []ipLister{t.dhcp, t.arp, t.ptr, t.mdns, t.vpn}
|
||||
il := []ipLister{t.dhcp, t.arp, t.ptr, t.mdns, t.vni}
|
||||
for _, ir := range il {
|
||||
for _, ip := range ir.List() {
|
||||
c, ok := ipMap[ip]
|
||||
@@ -331,11 +331,11 @@ func (t *Table) ListClients() []*Client {
|
||||
|
||||
// StoreVPNClient stores client info for VPN clients.
|
||||
func (t *Table) StoreVPNClient(ci *ctrld.ClientInfo) {
|
||||
if ci == nil || t.vpn == nil {
|
||||
if ci == nil || t.vni == nil {
|
||||
return
|
||||
}
|
||||
t.vpn.mac.Store(ci.IP, ci.Mac)
|
||||
t.vpn.ip2name.Store(ci.IP, ci.Hostname)
|
||||
t.vni.mac.Store(ci.IP, ci.Mac)
|
||||
t.vni.ip2name.Store(ci.IP, ci.Hostname)
|
||||
}
|
||||
|
||||
func (t *Table) discoverDHCP() bool {
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// vpn is the manager for VPN clients info.
|
||||
type vpn struct {
|
||||
// virtualNetworkIface is the manager for clients from virtual network interface.
|
||||
type virtualNetworkIface 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 {
|
||||
func (v *virtualNetworkIface) LookupHostnameByIP(ip string) string {
|
||||
val, ok := v.ip2name.Load(ip)
|
||||
if !ok {
|
||||
return ""
|
||||
@@ -20,17 +20,17 @@ func (v *vpn) LookupHostnameByIP(ip string) string {
|
||||
}
|
||||
|
||||
// LookupHostnameByMac always returns empty string.
|
||||
func (v *vpn) LookupHostnameByMac(mac string) string {
|
||||
func (v *virtualNetworkIface) LookupHostnameByMac(mac string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// String returns the string representation of vpn struct.
|
||||
func (v *vpn) String() string {
|
||||
return "vpn"
|
||||
// String returns the string representation of virtualNetworkIface struct.
|
||||
func (v *virtualNetworkIface) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// List lists all known VPN clients IP.
|
||||
func (v *vpn) List() []string {
|
||||
func (v *virtualNetworkIface) List() []string {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user