• Kui-Feng Lee's avatar
    selftests/bpf: Add traffic monitor functions. · f52403b6
    Kui-Feng Lee authored
    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.)
    
        lo      In  IPv4 127.0.0.1:40265 > 127.0.0.1:55907: TCP, length 68, SYN
        lo      In  IPv4 127.0.0.1:55907 > 127.0.0.1:40265: TCP, length 60, SYN, ACK
        lo      In  IPv4 127.0.0.1:40265 > 127.0.0.1:55907: TCP, length 60, ACK
        lo      In  IPv4 127.0.0.1:55907 > 127.0.0.1:40265: TCP, length 52, ACK
        lo      In  IPv4 127.0.0.1:40265 > 127.0.0.1:55907: TCP, length 52, FIN, ACK
        lo      In  IPv4 127.0.0.1:55907 > 127.0.0.1:40265: TCP, length 52, RST, ACK
        Packet file: packets-2173-86-select_reuseport:sockhash_IPv4_TCP_LOOPBACK_test_detach_bpf-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 libpcap is available. (Could be found by pkg-config)
    Acked-by: default avatarStanislav Fomichev <sdf@fomichev.me>
    Signed-off-by: default avatarKui-Feng Lee <thinker.li@gmail.com>
    Link: https://lore.kernel.org/r/20240815053254.470944-2-thinker.li@gmail.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
    f52403b6
Makefile 31.9 KB