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

ZeroCopy read packet data causes heap allocations in pcapNextPacketEx #1142

Open
baryluk opened this issue Nov 4, 2023 · 0 comments
Open

Comments

@baryluk
Copy link

baryluk commented Nov 4, 2023

gopacket@v1.1.19

go version go1.21.1 linux/amd64

Fedora 39, amd64

ZeroCopy receiving using pcap on Unix causes 1-allocation per receive, which is very unfortunate:

image

There is a mysterious comment in this function suggesting some weirdness with GC:

func (p *Handle) pcapNextPacketEx() NextError {
    // This horrible magic allows us to pass a ptr-to-ptr to pcap_next_ex
    // without causing that ptr-to-ptr to itself be allocated on the heap.
    // Since Handle itself survives through the duration of the pcap_next_ex
    // call, this should be perfectly safe for GC stuff, etc.

    return NextError(C.pcap_next_ex_escaping(p.cptr, C.uintptr_t(uintptr(unsafe.Pointer(&p.pkthdr))), C.uintptr_t(uintptr(unsafe.Pointer(&p.bufptr)))))
}

No idea why this allocates anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant