-
Notifications
You must be signed in to change notification settings - Fork 368
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
Fix PacketCapture pcapng file issue on macOS #6804
base: main
Are you sure you want to change the base?
Conversation
0938e84
to
01870b6
Compare
By default, gopacket will write snap length=0 in the pcapng file header, means unlimited snaplen. tcpdump on osx(libpcap version 1.10.1) cannot recognize this and will report error. This patch will set a default value(524288) for it. Signed-off-by: Hang Yan <[email protected]>
01870b6
to
12e1973
Compare
Signed-off-by: Hang Yan <[email protected]>
e011320
to
32682e8
Compare
// 0 and means unlimited, but tcpdump on Mac OSX will complain: | ||
// 'tcpdump: pcap_loop: invalid packet capture length <len>, bigger than snaplen of 524288' | ||
ngInterface := pcapgo.DefaultNgInterface | ||
ngInterface.SnapLength = 65536 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think the snapshot length could be a parameter to the Capture
interface method, after which snapLength
could be defined as a constant in this file, and we could use the constant here, as well as when invoking Capture
?
defer func() { | ||
defer file.Close() | ||
defer os.Remove(dstFileName) | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the point of having 2 defer statements in a deferred function?
Couldn't the code be like this:
require.NoError(t, data.copyPodFiles(antreaPodName, "antrea-agent", "kube-system", packetFile, os.TempDir()))
defer os.Remove(dstFileName)
file, err := os.Open(dstFileName)
require.NoError(t, err)
defer file.Close()
this would close the file first, then remove it (reversed order of execution for deferred statements)
By default, gopacket will write snap length=0 in the pcapng file header, means unlimited snaplen. tcpdump on osx(libpcap version 1.10.1) cannot recognize this and will report error. This patch will set a default value(524288) for it. This patch also add packets file verification in e2e tests.
origin error message:
pcapng format ref: https://pcapng.com/