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:
Cuong Manh Le
2023-10-03 16:51:09 +00:00
committed by Cuong Manh Le
parent 8ddbf881b3
commit 6e28517454
3 changed files with 18 additions and 15 deletions
+7 -7
View File
@@ -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 {