zero copy capture
delay copying until necessary
This commit is contained in:
1 parent
276e3b8487
commit
1a41df1edf
2 files changed
+9
-3
No files matched your search
@@ -50,7 +50,7 @@ func newPcapIO(ifName string, promisc bool, snaplen int, bufSz int) (handle *Pca
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pi *PcapIO) ReadPacket() (data []byte, err error) {
|
func (pi *PcapIO) ReadPacket() (data []byte, err error) {
|
||||||
data, _, err = pi.handle.ReadPacketData()
|
data, _, err = pi.handle.ZeroCopyReadPacketData()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,10 +111,16 @@ func (router *Router) handleCapturedPacket(frameData []byte, dec *EthernetDecode
|
|||||||
} else {
|
} else {
|
||||||
router.LogFrame("Forwarding", frameData, &dec.eth)
|
router.LogFrame("Forwarding", frameData, &dec.eth)
|
||||||
}
|
}
|
||||||
|
// at this point we are handing over the frame to forwarders, so
|
||||||
|
// we need to make a copy of it in order to prevent the next
|
||||||
|
// capture from overwriting the data
|
||||||
|
frameLen := len(frameData)
|
||||||
|
frameCopy := make([]byte, frameLen, frameLen)
|
||||||
|
copy(frameCopy, frameData)
|
||||||
if !found || dec.BroadcastFrame() {
|
if !found || dec.BroadcastFrame() {
|
||||||
return checkFrameTooBig(router.Ourself.Broadcast(df, frameData, dec))
|
return checkFrameTooBig(router.Ourself.Broadcast(df, frameCopy, dec))
|
||||||
} else {
|
} else {
|
||||||
return checkFrameTooBig(router.Ourself.Forward(dstPeer, df, frameData, dec))
|
return checkFrameTooBig(router.Ourself.Forward(dstPeer, df, frameCopy, dec))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user