Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Fix warning about false remaining packets in ring buffer when piping mock sources #29

Conversation

fako1024
Copy link
Owner

@fako1024 fako1024 commented May 5, 2023

Closes #28

@fako1024 fako1024 added the bug Something isn't working label May 5, 2023
@fako1024 fako1024 added this to the Initial Release (v1) milestone May 5, 2023
@fako1024 fako1024 requested a review from els0r May 5, 2023 09:15
@fako1024 fako1024 self-assigned this May 5, 2023
@fako1024 fako1024 linked an issue May 5, 2023 that may be closed by this pull request
@@ -99,7 +99,7 @@ func (m *MockSource) PacketAddCallbackFn(fn func(payload []byte, totalLen uint32
// function of an actual ring buffer. Consequently, if the ring buffer is full and elements not
// yet consumed this function may block
func (m *MockSource) AddPacket(pkt capture.Packet) error {
return m.addPacket(pkt.Payload(), pkt.TotalLen(), pkt.Type(), 0)
return m.addPacket(pkt.Payload(), pkt.TotalLen(), pkt.Type(), pkt.IPLayerOffset())
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated, but occurred to me: Now that a capture.Packet provides access to its specific IP layer offset we can properly hand it over (caused an issue when piping from mock to mock with different snaplen).

@@ -235,7 +235,7 @@ func TestPipe(t *testing.T) {

// Setup the original mock source
mockSrc, err := NewMockSource("mock",
CaptureLength(link.CaptureLengthMinimalIPv4Transport),
CaptureLength(link.CaptureLengthMinimalIPv6Transport),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to trigger the IP layer offset issue mentioned in my first comment.

Copy link
Collaborator

@els0r els0r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fako1024 fako1024 merged commit 7c556a5 into main May 7, 2023
@fako1024 fako1024 deleted the 28-mock-piping-may-cause-stray-packets-on-ring-buffer-when-wrapping-around branch May 7, 2023 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mock piping may cause stray packets on ring buffer when wrapping around
2 participants