Skip to content

Commit 614adf3

Browse files
ThinkerYzu1Kernel Patches Daemon
authored andcommitted
selftests/bpf: Add traffic monitor functions.
Add functions that capture packets and print log in the background. They are supposed to be used for debugging flaky network test cases. A monitored test case should call traffic_monitor_start() to start a thread to capture packets in the background for a given namespace and call traffic_monitor_stop() to stop capturing. (Or, option '-m' implemented by the later patches.) IPv4 TCP packet: 127.0.0.1:48165 -> 127.0.0.1:36707, len 68, ifindex 1, SYN IPv4 TCP packet: 127.0.0.1:36707 -> 127.0.0.1:48165, len 60, ifindex 1, SYN, ACK IPv4 TCP packet: 127.0.0.1:48165 -> 127.0.0.1:36707, len 60, ifindex 1, ACK IPv4 TCP packet: 127.0.0.1:36707 -> 127.0.0.1:48165, len 52, ifindex 1, ACK IPv4 TCP packet: 127.0.0.1:48165 -> 127.0.0.1:36707, len 52, ifindex 1, FIN, ACK IPv4 TCP packet: 127.0.0.1:36707 -> 127.0.0.1:48165, len 52, ifindex 1, RST, ACK Packet file: packets-2172-86-select_reuseport:sockhash-test.log #280/87 select_reuseport/sockhash IPv4/TCP LOOPBACK test_detach_bpf:OK The above is the output of an example. It shows the packets of a connection and the name of the file that contains captured packets in the directory /tmp/tmon_pcap. The file can be loaded by tcpdump or wireshark. This feature only works if TRAFFIC_MONITOR variable has been passed to build BPF selftests. For example, make TRAFFIC_MONITOR=1 -C tools/testing/selftests/bpf This command will build BPF selftests with this feature enabled. Signed-off-by: Kui-Feng Lee <[email protected]>
1 parent 7259784 commit 614adf3

File tree

3 files changed

+453
-0
lines changed

3 files changed

+453
-0
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ CFLAGS += -g $(OPT_FLAGS) -rdynamic \
4141
LDFLAGS += $(SAN_LDFLAGS)
4242
LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread
4343

44+
ifneq ($(TRAFFIC_MONITOR),)
45+
LDLIBS += -lpcap
46+
CFLAGS += -DTRAFFIC_MONITOR=1
47+
endif
48+
4449
# The following tests perform type punning and they may break strict
4550
# aliasing rules, which are exploited by both GCC and clang by default
4651
# while optimizing. This can lead to broken programs.

0 commit comments

Comments
 (0)