On 07/31, Kui-Feng Lee wrote: > 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 <thinker.li@xxxxxxxxx> > --- > tools/testing/selftests/bpf/Makefile | 5 + > tools/testing/selftests/bpf/test_progs.c | 432 +++++++++++++++++++++++ > tools/testing/selftests/bpf/test_progs.h | 16 + > 3 files changed, 453 insertions(+) > > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile > index 774c6270e377..0a3108311be7 100644 > --- a/tools/testing/selftests/bpf/Makefile > +++ b/tools/testing/selftests/bpf/Makefile > @@ -41,6 +41,11 @@ CFLAGS += -g $(OPT_FLAGS) -rdynamic \ > LDFLAGS += $(SAN_LDFLAGS) > LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread > > +ifneq ($(TRAFFIC_MONITOR),) > +LDLIBS += -lpcap > +CFLAGS += -DTRAFFIC_MONITOR=1 > +endif Optionally: can make this more automagical with the following: LDLIBS += $(shell pkg-config --libs 2>/dev/null) CFLAGS += $(shell pkg-config --cflags 2>/dev/null) CFLAGS += $(shell pkg-config --exists libpcap 2>/dev/null && echo "-DTRAFFIC_MONITOR=1")