Skip to content

Commit

Permalink
fix lock() in IPChange
Browse files Browse the repository at this point in the history
  • Loading branch information
irai committed Aug 4, 2020
1 parent bbb6d38 commit 4832ef2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spoof.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ func (c *Handler) StopIPChange(mac net.HardwareAddr) error {
//
func (c *Handler) IPChanged(mac net.HardwareAddr, clientIP net.IP) {
// Do nothing if we already have this mac and ip
c.RLock()
if client := c.table.findByMAC(mac); client != nil && client.Online && client.IP().Equal(clientIP) {
c.RUnlock()
return
}
c.RUnlock()

if Debug {
log.Printf("ARP new mac=%s - validating", mac)
Expand All @@ -98,20 +101,26 @@ func (c *Handler) IPChanged(mac net.HardwareAddr, clientIP net.IP) {
go func() {
for i := 0; i < 5; i++ {
time.Sleep(time.Second * 1)
c.RLock()
if entry := c.table.findByMAC(mac); entry != nil && entry.findIP(clientIP) != nil {
c.RUnlock()
if Debug {
log.Printf("ARP found mac=%s ips=%s", entry.MAC, entry.IPs())
}
return
}
c.RUnlock()

// Silent request
if err := c.request(c.config.HostMAC, c.config.HostIP, EthernetBroadcast, clientIP); err != nil {
log.Printf("ARP request 2 failed mac=%s ip=%s: %s", mac, clientIP, err)
}
}
log.Printf("ARP could not detect ip=%s mac=%s", clientIP, mac)

c.RLock()
c.table.printTable()
c.RUnlock()
}()
}

Expand Down

0 comments on commit 4832ef2

Please sign in to comment.