Skip to content

Commit

Permalink
Merge pull request #5 from fzu-huang/dev/support-spec-src-ip
Browse files Browse the repository at this point in the history
support DAD arping
  • Loading branch information
fzu-huang authored Oct 25, 2024
2 parents 26f76a0 + f3142e7 commit 19185d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arp_datagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (datagram arpDatagram) IsResponseOf(request arpDatagram) bool {
bytes.Equal(request.tpa, datagram.spa)
}

func (datagram arpDatagram) IsDuplicateRequestOf(request arpDatagram) bool {
return datagram.oper == requestOper && bytes.Equal(request.spa, datagram.tpa) &&
bytes.Equal(request.tpa, datagram.tpa)
}

func parseArpDatagram(buffer []byte) arpDatagram {
var datagram arpDatagram

Expand Down
11 changes: 11 additions & 0 deletions arping.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ func PingOverIface(dstIP, srcIP net.IP, iface net.Interface) (net.HardwareAddr,
return
}

if srcIP.Equal(net.IPv4zero) || srcIP.Equal(net.IPv6zero) {
// if arping with src IP as IPv4zero, we expect no response but request from dst IP
if response.IsDuplicateRequestOf(request) {
duration := receiveTime.Sub(sendTime)
verboseLog.Printf("process received arp: srcIP: '%s', srcMac: '%s'\n",
response.SenderIP(), response.SenderMac())
pingResultChan <- PingResult{response.SenderMac(), duration, err}
return
}
}

if response.IsResponseOf(request) {
duration := receiveTime.Sub(sendTime)
verboseLog.Printf("process received arp: srcIP: '%s', srcMac: '%s'\n",
Expand Down

0 comments on commit 19185d7

Please sign in to comment.