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

supports all ports when target_port is 0 #409

Merged
merged 2 commits into from
Nov 5, 2023
Merged

Conversation

cfc4n
Copy link
Member

@cfc4n cfc4n commented Nov 4, 2023

当使用pcapng模式时,如果--port参数为0,则支持所有端口的网络包捕获。否则则只捕获--port对应的端口数据。默认是443 端口。

--port默认没有捕获所有网络包,是因为有很多场景,主机的网络流量很大,eBPF的map写入太快,用户空间消费过慢,导致丢包的问题。虽然用户空间在创建eBPF map时,已经申请了BufferSizeOfEbpfMap大的内存,但仍然还存在网络包过多导致数据丢失的可能。 而且,在Android上有内存大小限制,BufferSizeOfEbpfMap的值仅为1024


When using pcapng mode, if the --port parameter is set to 0, it supports capturing network packets from all ports. Otherwise, it only captures data from the port corresponding to --port. The default port is 443.

The reason why --port does not capture all network packets by default is that in many scenarios, the host's network traffic is high and eBPF map writes too fast while user space consumption is slow, resulting in packet loss issues. Although user space has already allocated memory of size BufferSizeOfEbpfMap when creating eBPF map, there still exists a problem of data loss due to excessive network packets. Moreover, on Android, there are memory size limitations and the value of BufferSizeOfEbpfMap is only 1024.

	rd, err := perf.NewReader(em, os.Getpagesize()*BufferSizeOfEbpfMap)

Signed-off-by: cfc4n <cfc4n.cs@gmail.com>
Signed-off-by: cfc4n <cfc4n.cs@gmail.com>
@cfc4n cfc4n added the enhancement New feature or request label Nov 4, 2023
@cfc4n cfc4n linked an issue Nov 4, 2023 that may be closed by this pull request
@cfc4n
Copy link
Member Author

cfc4n commented Nov 4, 2023

@Xeonacid Try it.

Copy link

@Xeonacid Xeonacid left a comment

Choose a reason for hiding this comment

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

Thanks! I owe you a beer. :)

@cfc4n cfc4n merged commit 5271944 into master Nov 5, 2023
6 checks passed
@cfc4n cfc4n deleted the network-traffic-all-ports branch November 5, 2023 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capture all network traffic from all ports in pcapng mode
2 participants