fix mdns to use A record IPs and create interfaces for IP-only nodes
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
28
mdns.go
28
mdns.go
@@ -84,8 +84,6 @@ func (t *Tendrils) handleMDNSPacket(ifaceName string, srcIP net.IP, data []byte)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tendrils) processMDNSResponse(ifaceName string, srcIP net.IP, msg *dns.Msg) {
|
func (t *Tendrils) processMDNSResponse(ifaceName string, srcIP net.IP, msg *dns.Msg) {
|
||||||
var hostname string
|
|
||||||
|
|
||||||
allRecords := append(msg.Answer, msg.Extra...)
|
allRecords := append(msg.Answer, msg.Extra...)
|
||||||
|
|
||||||
if t.DebugMDNS {
|
if t.DebugMDNS {
|
||||||
@@ -103,10 +101,6 @@ func (t *Tendrils) processMDNSResponse(ifaceName string, srcIP net.IP, msg *dns.
|
|||||||
case *dns.A:
|
case *dns.A:
|
||||||
name := strings.TrimSuffix(r.Hdr.Name, ".")
|
name := strings.TrimSuffix(r.Hdr.Name, ".")
|
||||||
aRecords[name] = r.A
|
aRecords[name] = r.A
|
||||||
localName := strings.TrimSuffix(name, ".local")
|
|
||||||
if localName != "" && r.A.Equal(srcIP) {
|
|
||||||
hostname = localName
|
|
||||||
}
|
|
||||||
case *dns.AAAA:
|
case *dns.AAAA:
|
||||||
continue
|
continue
|
||||||
case *dns.PTR:
|
case *dns.PTR:
|
||||||
@@ -115,23 +109,20 @@ func (t *Tendrils) processMDNSResponse(ifaceName string, srcIP net.IP, msg *dns.
|
|||||||
if name != "" {
|
if name != "" {
|
||||||
danteNames[name] = true
|
danteNames[name] = true
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
name := strings.TrimSuffix(r.Ptr, ".local.")
|
|
||||||
name = strings.TrimSuffix(name, ".")
|
|
||||||
if hostname == "" && name != "" && !strings.HasPrefix(name, "_") {
|
|
||||||
hostname = name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case *dns.SRV:
|
case *dns.SRV:
|
||||||
if isDanteService(r.Hdr.Name) {
|
if isDanteService(r.Hdr.Name) {
|
||||||
name := extractDanteName(r.Hdr.Name)
|
name := extractDanteName(r.Hdr.Name)
|
||||||
target := strings.TrimSuffix(r.Target, ".")
|
target := strings.TrimSuffix(r.Target, ".")
|
||||||
if name != "" && target != "" {
|
if name != "" {
|
||||||
|
danteNames[name] = true
|
||||||
|
if target != "" {
|
||||||
srvTargets[name] = target
|
srvTargets[name] = target
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for name := range danteNames {
|
for name := range danteNames {
|
||||||
var ip net.IP
|
var ip net.IP
|
||||||
@@ -147,11 +138,16 @@ func (t *Tendrils) processMDNSResponse(ifaceName string, srcIP net.IP, msg *dns.
|
|||||||
t.nodes.UpdateDante(name, ip)
|
t.nodes.UpdateDante(name, ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(danteNames) == 0 && hostname != "" {
|
if len(danteNames) == 0 {
|
||||||
|
for aName, ip := range aRecords {
|
||||||
|
hostname := strings.TrimSuffix(aName, ".local")
|
||||||
|
if hostname != "" && hostname != aName {
|
||||||
if t.DebugMDNS {
|
if t.DebugMDNS {
|
||||||
log.Printf("[mdns] %s: %s -> %s", ifaceName, srcIP, hostname)
|
log.Printf("[mdns] %s: %s -> %s", ifaceName, ip, hostname)
|
||||||
|
}
|
||||||
|
t.nodes.Update(nil, nil, []net.IP{ip}, "", hostname, "mdns")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
t.nodes.Update(nil, nil, []net.IP{srcIP}, "", hostname, "mdns")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
nodes.go
8
nodes.go
@@ -283,6 +283,14 @@ func (n *Nodes) Update(target *Node, mac net.HardwareAddr, ips []net.IP, ifaceNa
|
|||||||
ipKey := ip.String()
|
ipKey := ip.String()
|
||||||
if _, exists := n.ipIndex[ipKey]; !exists {
|
if _, exists := n.ipIndex[ipKey]; !exists {
|
||||||
n.ipIndex[ipKey] = targetID
|
n.ipIndex[ipKey] = targetID
|
||||||
|
iface, exists := node.Interfaces[ipKey]
|
||||||
|
if !exists {
|
||||||
|
iface = &Interface{
|
||||||
|
IPs: map[string]net.IP{},
|
||||||
|
}
|
||||||
|
node.Interfaces[ipKey] = iface
|
||||||
|
}
|
||||||
|
iface.IPs[ipKey] = ip
|
||||||
added = append(added, "ip="+ipKey)
|
added = append(added, "ip="+ipKey)
|
||||||
go n.t.requestARP(ip)
|
go n.t.requestARP(ip)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user