Repository navigation
Conversation
NewZeroCopyPacketSource never set zeroCopy, so the PacketsCtx check for NoCopy on a zero copy source never ran. Turning that check on (gopacket#172) made existing callers panic and was reverted. Set zeroCopy, and on the Packets/PacketsCtx path decode with NoCopy cleared for zero copy sources, so each queued packet owns its data and ancillary data instead of aliasing the buffer the source reuses on the next read. NextPacket keeps its zero copy behaviour. Remove the panic. Fixes gopacket#74
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #172, which was reverted in 11ee6a1. This takes the direction from the revert comment: never fail at runtime, and copy on the channel path instead.
Fixes #74
Problem
NewZeroCopyPacketSourcenever setszeroCopy. WithNoCopyset,Packets()/PacketsCtx()queue packets that alias the buffer the source reuses. Once the reader falls behind, those packets show the data (andAncillaryData) of a later read.Change
NewZeroCopyPacketSourcesetszeroCopy.packetsToChanneldecodes withNoCopycleared when the source is zero copy.NewPacketthen copies the data, and the existing ancillary-data copy inNextPacketapplies too. This goes through a smallnextPacket(opts)helper, soNextPacketitself is unchanged.PacketsCtxis removed. ExistingNoCopychannel callers keep working; their packets now own their data. ThePacketsCtxdoc comment says so.NextPacketwithNoCopystill returns packets that use the source buffer directly.Tests
TestZeroCopyPacketSourcePacketsCopiesData: a source that reuses one data buffer and oneAncillaryDataslice queues 5 packets before any are read, then checks each packet's data and ancillary data. On master every packet reads5; with this change they read1..5and none aliases the buffer.TestZeroCopyPacketSourceNextPacketNoCopy:NextPacketwithNoCopystill aliases the source buffer.go test -race .andgo vet .pass, andgofmtis clean.