Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Add sanity check to detect when receiving own packets
Browse files Browse the repository at this point in the history
  • Loading branch information
brb committed Dec 5, 2016
1 parent e5cf022 commit af962f7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions router/network_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ func (router *NetworkRouter) handleCapturedPacket(key PacketKey) FlowOp {
}

func (router *NetworkRouter) handleForwardedPacket(key ForwardPacketKey) FlowOp {
srcMac := net.HardwareAddr(key.SrcMAC[:])
dstMac := net.HardwareAddr(key.DstMAC[:])

if key.SrcPeer == router.Ourself.Peer {
log.Warn("Received own packet to peer ", key.DstPeer, " from MAC (", srcMac, ") to (", dstMac, ")")
}

if key.DstPeer != router.Ourself.Peer {
// it's not for us, we're just relaying it
router.PacketLogging.LogForwardPacket("Relaying", key)
Expand All @@ -134,9 +141,6 @@ func (router *NetworkRouter) handleForwardedPacket(key ForwardPacketKey) FlowOp
// (because the DstPeer on a forwarded broadcast packet is
// always set to the peer being forwarded to)

srcMac := net.HardwareAddr(key.SrcMAC[:])
dstMac := net.HardwareAddr(key.DstMAC[:])

switch newSrcMac, conflictPeer := router.Macs.AddForced(srcMac, key.SrcPeer); {
case newSrcMac:
log.Print("Discovered remote MAC ", srcMac, " at ", key.SrcPeer)
Expand Down

0 comments on commit af962f7

Please sign in to comment.