2020-05-08 10:46:08 -07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef __NETWORK_HELPERS_H
|
|
|
|
#define __NETWORK_HELPERS_H
|
2024-10-08 16:50:57 +02:00
|
|
|
#include <arpa/inet.h>
|
2020-05-08 10:46:08 -07:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
2020-05-08 10:46:09 -07:00
|
|
|
#include <linux/types.h>
|
|
|
|
typedef __u16 __sum16;
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/if_packet.h>
|
2025-03-05 21:34:35 +00:00
|
|
|
#include <linux/if_tun.h>
|
2020-05-08 10:46:09 -07:00
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/ipv6.h>
|
2024-04-02 11:45:25 +00:00
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/sockios.h>
|
2024-04-23 18:35:29 +08:00
|
|
|
#include <linux/err.h>
|
2020-05-08 10:46:09 -07:00
|
|
|
#include <netinet/tcp.h>
|
2024-11-20 08:43:22 +01:00
|
|
|
#include <netinet/udp.h>
|
2020-05-08 10:46:09 -07:00
|
|
|
#include <bpf/bpf_endian.h>
|
2024-04-02 11:45:25 +00:00
|
|
|
#include <net/if.h>
|
2025-03-05 10:20:56 -08:00
|
|
|
#include <stdio.h>
|
2020-05-08 10:46:09 -07:00
|
|
|
|
|
|
|
#define MAGIC_VAL 0x1234
|
|
|
|
#define NUM_ITER 100000
|
|
|
|
#define VIP_NUM 5
|
|
|
|
#define MAGIC_BYTES 123
|
|
|
|
|
2021-08-24 10:30:19 -07:00
|
|
|
struct network_helper_opts {
|
|
|
|
int timeout_ms;
|
2023-07-21 14:22:48 -06:00
|
|
|
int proto;
|
2024-07-09 17:16:17 +08:00
|
|
|
/* +ve: Passed to listen() as-is.
|
|
|
|
* 0: Default when the test does not set
|
|
|
|
* a particular value during the struct init.
|
|
|
|
* It is changed to 1 before passing to listen().
|
|
|
|
* Most tests only have one on-going connection.
|
|
|
|
* -ve: It is changed to 0 before passing to listen().
|
|
|
|
* It is useful to force syncookie without
|
|
|
|
* changing the "tcp_syncookies" sysctl from 1 to 2.
|
|
|
|
*/
|
|
|
|
int backlog;
|
2024-05-25 20:08:15 +08:00
|
|
|
int (*post_socket_cb)(int fd, void *opts);
|
2024-05-25 20:08:17 +08:00
|
|
|
void *cb_opts;
|
2021-08-24 10:30:19 -07:00
|
|
|
};
|
|
|
|
|
2020-05-08 10:46:09 -07:00
|
|
|
/* ipv4 test vector */
|
|
|
|
struct ipv4_packet {
|
|
|
|
struct ethhdr eth;
|
|
|
|
struct iphdr iph;
|
|
|
|
struct tcphdr tcp;
|
|
|
|
} __packed;
|
|
|
|
extern struct ipv4_packet pkt_v4;
|
|
|
|
|
|
|
|
/* ipv6 test vector */
|
|
|
|
struct ipv6_packet {
|
|
|
|
struct ethhdr eth;
|
|
|
|
struct ipv6hdr iph;
|
|
|
|
struct tcphdr tcp;
|
|
|
|
} __packed;
|
|
|
|
extern struct ipv6_packet pkt_v6;
|
2020-05-08 10:46:08 -07:00
|
|
|
|
2021-05-05 08:59:25 +00:00
|
|
|
int settimeo(int fd, int timeout_ms);
|
2024-05-25 20:08:16 +08:00
|
|
|
int start_server_str(int family, int type, const char *addr_str, __u16 port,
|
|
|
|
const struct network_helper_opts *opts);
|
2020-07-01 17:48:52 -07:00
|
|
|
int start_server(int family, int type, const char *addr, __u16 port,
|
|
|
|
int timeout_ms);
|
2021-07-01 13:06:25 -07:00
|
|
|
int *start_reuseport_server(int family, int type, const char *addr_str,
|
|
|
|
__u16 port, int timeout_ms,
|
|
|
|
unsigned int nr_listens);
|
2024-04-18 16:09:07 +08:00
|
|
|
int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
|
|
|
|
const struct network_helper_opts *opts);
|
2021-07-01 13:06:25 -07:00
|
|
|
void free_fds(int *fds, unsigned int nr_close_fds);
|
2024-06-21 10:16:00 +08:00
|
|
|
int client_socket(int family, int type,
|
|
|
|
const struct network_helper_opts *opts);
|
2024-04-18 16:09:10 +08:00
|
|
|
int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
|
|
|
|
const struct network_helper_opts *opts);
|
2024-07-18 14:22:31 +08:00
|
|
|
int connect_to_addr_str(int family, int type, const char *addr_str, __u16 port,
|
|
|
|
const struct network_helper_opts *opts);
|
2020-07-01 17:48:52 -07:00
|
|
|
int connect_to_fd(int server_fd, int timeout_ms);
|
2024-07-18 14:22:29 +08:00
|
|
|
int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts);
|
2020-07-01 17:48:52 -07:00
|
|
|
int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms);
|
2020-08-20 12:01:11 -07:00
|
|
|
int fastopen_connect(int server_fd, const char *data, unsigned int data_len,
|
|
|
|
int timeout_ms);
|
selftests/bpf: Tests for BPF_SK_LOOKUP attach point
Add tests to test_progs that exercise:
- attaching/detaching/querying programs to BPF_SK_LOOKUP hook,
- redirecting socket lookup to a socket selected by BPF program,
- failing a socket lookup on BPF program's request,
- error scenarios for selecting a socket from BPF program,
- accessing BPF program context,
- attaching and running multiple BPF programs.
Run log:
bash-5.0# ./test_progs -n 70
#70/1 query lookup prog:OK
#70/2 TCP IPv4 redir port:OK
#70/3 TCP IPv4 redir addr:OK
#70/4 TCP IPv4 redir with reuseport:OK
#70/5 TCP IPv4 redir skip reuseport:OK
#70/6 TCP IPv6 redir port:OK
#70/7 TCP IPv6 redir addr:OK
#70/8 TCP IPv4->IPv6 redir port:OK
#70/9 TCP IPv6 redir with reuseport:OK
#70/10 TCP IPv6 redir skip reuseport:OK
#70/11 UDP IPv4 redir port:OK
#70/12 UDP IPv4 redir addr:OK
#70/13 UDP IPv4 redir with reuseport:OK
#70/14 UDP IPv4 redir skip reuseport:OK
#70/15 UDP IPv6 redir port:OK
#70/16 UDP IPv6 redir addr:OK
#70/17 UDP IPv4->IPv6 redir port:OK
#70/18 UDP IPv6 redir and reuseport:OK
#70/19 UDP IPv6 redir skip reuseport:OK
#70/20 TCP IPv4 drop on lookup:OK
#70/21 TCP IPv6 drop on lookup:OK
#70/22 UDP IPv4 drop on lookup:OK
#70/23 UDP IPv6 drop on lookup:OK
#70/24 TCP IPv4 drop on reuseport:OK
#70/25 TCP IPv6 drop on reuseport:OK
#70/26 UDP IPv4 drop on reuseport:OK
#70/27 TCP IPv6 drop on reuseport:OK
#70/28 sk_assign returns EEXIST:OK
#70/29 sk_assign honors F_REPLACE:OK
#70/30 sk_assign accepts NULL socket:OK
#70/31 access ctx->sk:OK
#70/32 narrow access to ctx v4:OK
#70/33 narrow access to ctx v6:OK
#70/34 sk_assign rejects TCP established:OK
#70/35 sk_assign rejects UDP connected:OK
#70/36 multi prog - pass, pass:OK
#70/37 multi prog - drop, drop:OK
#70/38 multi prog - pass, drop:OK
#70/39 multi prog - drop, pass:OK
#70/40 multi prog - pass, redir:OK
#70/41 multi prog - redir, pass:OK
#70/42 multi prog - drop, redir:OK
#70/43 multi prog - redir, drop:OK
#70/44 multi prog - redir, redir:OK
#70 sk_lookup:OK
Summary: 1/44 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200717103536.397595-16-jakub@cloudflare.com
2020-07-17 12:35:36 +02:00
|
|
|
int make_sockaddr(int family, const char *addr_str, __u16 port,
|
|
|
|
struct sockaddr_storage *addr, socklen_t *len);
|
2021-08-04 13:55:24 -07:00
|
|
|
char *ping_command(int family);
|
2023-05-19 22:51:56 +00:00
|
|
|
int get_socket_local_port(int sock_fd);
|
2024-04-02 11:45:25 +00:00
|
|
|
int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
|
2024-04-02 11:45:26 +00:00
|
|
|
int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
|
2020-05-08 10:46:08 -07:00
|
|
|
|
2025-03-05 21:34:35 +00:00
|
|
|
int open_tuntap(const char *dev_name, bool need_mac);
|
|
|
|
|
2022-03-09 11:53:45 +01:00
|
|
|
struct nstoken;
|
|
|
|
/**
|
|
|
|
* open_netns() - Switch to specified network namespace by name.
|
|
|
|
*
|
|
|
|
* Returns token with which to restore the original namespace
|
|
|
|
* using close_netns().
|
|
|
|
*/
|
|
|
|
struct nstoken *open_netns(const char *name);
|
|
|
|
void close_netns(struct nstoken *token);
|
2024-04-11 13:43:12 +08:00
|
|
|
int send_recv_data(int lfd, int fd, uint32_t total_bytes);
|
2024-08-14 22:32:51 -07:00
|
|
|
int make_netns(const char *name);
|
|
|
|
int remove_netns(const char *name);
|
2023-11-27 11:03:16 -08:00
|
|
|
|
2025-01-31 08:21:40 +01:00
|
|
|
/**
|
|
|
|
* append_tid() - Append thread ID to the given string.
|
|
|
|
*
|
|
|
|
* @str: string to extend
|
|
|
|
* @sz: string's size
|
|
|
|
*
|
|
|
|
* 8 characters are used to append the thread ID (7 digits + '\0')
|
|
|
|
*
|
|
|
|
* Returns -1 on errors, 0 otherwise
|
|
|
|
*/
|
|
|
|
int append_tid(char *str, size_t sz);
|
|
|
|
|
2023-11-27 11:03:16 -08:00
|
|
|
static __u16 csum_fold(__u32 csum)
|
|
|
|
{
|
|
|
|
csum = (csum & 0xffff) + (csum >> 16);
|
|
|
|
csum = (csum & 0xffff) + (csum >> 16);
|
|
|
|
|
|
|
|
return (__u16)~csum;
|
|
|
|
}
|
|
|
|
|
2024-11-20 08:43:19 +01:00
|
|
|
static __wsum csum_partial(const void *buf, int len, __wsum sum)
|
|
|
|
{
|
|
|
|
__u16 *p = (__u16 *)buf;
|
|
|
|
int num_u16 = len >> 1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_u16; i++)
|
|
|
|
sum += p[i];
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline __sum16 build_ip_csum(struct iphdr *iph)
|
|
|
|
{
|
|
|
|
__u32 sum = 0;
|
|
|
|
__u16 *p;
|
|
|
|
|
|
|
|
iph->check = 0;
|
|
|
|
p = (void *)iph;
|
|
|
|
sum = csum_partial(p, iph->ihl << 2, 0);
|
|
|
|
|
|
|
|
return csum_fold(sum);
|
|
|
|
}
|
|
|
|
|
2024-11-20 08:43:20 +01:00
|
|
|
/**
|
|
|
|
* csum_tcpudp_magic - compute IP pseudo-header checksum
|
|
|
|
*
|
|
|
|
* Compute the IPv4 pseudo header checksum. The helper can take a
|
|
|
|
* accumulated sum from the transport layer to accumulate it and directly
|
|
|
|
* return the transport layer
|
|
|
|
*
|
|
|
|
* @saddr: IP source address
|
|
|
|
* @daddr: IP dest address
|
|
|
|
* @len: IP data size
|
|
|
|
* @proto: transport layer protocol
|
|
|
|
* @csum: The accumulated partial sum to add to the computation
|
|
|
|
*
|
|
|
|
* Returns the folded sum
|
|
|
|
*/
|
2023-11-27 11:03:16 -08:00
|
|
|
static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
|
|
|
|
__u32 len, __u8 proto,
|
|
|
|
__wsum csum)
|
|
|
|
{
|
|
|
|
__u64 s = csum;
|
|
|
|
|
|
|
|
s += (__u32)saddr;
|
|
|
|
s += (__u32)daddr;
|
|
|
|
s += htons(proto + len);
|
|
|
|
s = (s & 0xffffffff) + (s >> 32);
|
|
|
|
s = (s & 0xffffffff) + (s >> 32);
|
|
|
|
|
|
|
|
return csum_fold((__u32)s);
|
|
|
|
}
|
|
|
|
|
2024-11-20 08:43:20 +01:00
|
|
|
/**
|
|
|
|
* csum_ipv6_magic - compute IPv6 pseudo-header checksum
|
|
|
|
*
|
|
|
|
* Compute the ipv6 pseudo header checksum. The helper can take a
|
|
|
|
* accumulated sum from the transport layer to accumulate it and directly
|
|
|
|
* return the transport layer
|
|
|
|
*
|
|
|
|
* @saddr: IPv6 source address
|
|
|
|
* @daddr: IPv6 dest address
|
|
|
|
* @len: IPv6 data size
|
|
|
|
* @proto: transport layer protocol
|
|
|
|
* @csum: The accumulated partial sum to add to the computation
|
|
|
|
*
|
|
|
|
* Returns the folded sum
|
|
|
|
*/
|
2023-11-27 11:03:16 -08:00
|
|
|
static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
|
|
|
|
const struct in6_addr *daddr,
|
|
|
|
__u32 len, __u8 proto,
|
|
|
|
__wsum csum)
|
|
|
|
{
|
|
|
|
__u64 s = csum;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
s += (__u32)saddr->s6_addr32[i];
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
s += (__u32)daddr->s6_addr32[i];
|
|
|
|
s += htons(proto + len);
|
|
|
|
s = (s & 0xffffffff) + (s >> 32);
|
|
|
|
s = (s & 0xffffffff) + (s >> 32);
|
|
|
|
|
|
|
|
return csum_fold((__u32)s);
|
|
|
|
}
|
|
|
|
|
2024-11-20 08:43:22 +01:00
|
|
|
/**
|
|
|
|
* build_udp_v4_csum - compute UDP checksum for UDP over IPv4
|
|
|
|
*
|
|
|
|
* Compute the checksum to embed in UDP header, composed of the sum of IP
|
|
|
|
* pseudo-header checksum, UDP header checksum and UDP data checksum
|
|
|
|
* @iph IP header
|
|
|
|
* @udph UDP header, which must be immediately followed by UDP data
|
|
|
|
*
|
|
|
|
* Returns the total checksum
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline __sum16 build_udp_v4_csum(const struct iphdr *iph,
|
|
|
|
const struct udphdr *udph)
|
|
|
|
{
|
|
|
|
unsigned long sum;
|
|
|
|
|
|
|
|
sum = csum_partial(udph, ntohs(udph->len), 0);
|
|
|
|
return csum_tcpudp_magic(iph->saddr, iph->daddr, ntohs(udph->len),
|
|
|
|
IPPROTO_UDP, sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* build_udp_v6_csum - compute UDP checksum for UDP over IPv6
|
|
|
|
*
|
|
|
|
* Compute the checksum to embed in UDP header, composed of the sum of IPv6
|
|
|
|
* pseudo-header checksum, UDP header checksum and UDP data checksum
|
|
|
|
* @ip6h IPv6 header
|
|
|
|
* @udph UDP header, which must be immediately followed by UDP data
|
|
|
|
*
|
|
|
|
* Returns the total checksum
|
|
|
|
*/
|
|
|
|
static inline __sum16 build_udp_v6_csum(const struct ipv6hdr *ip6h,
|
|
|
|
const struct udphdr *udph)
|
|
|
|
{
|
|
|
|
unsigned long sum;
|
|
|
|
|
|
|
|
sum = csum_partial(udph, ntohs(udph->len), 0);
|
|
|
|
return csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, ntohs(udph->len),
|
|
|
|
IPPROTO_UDP, sum);
|
|
|
|
}
|
|
|
|
|
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.)
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: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240815053254.470944-2-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
2024-08-14 22:32:49 -07:00
|
|
|
struct tmonitor_ctx;
|
|
|
|
|
2025-03-05 10:20:56 -08:00
|
|
|
typedef int (*tm_print_fn_t)(const char *format, va_list args);
|
|
|
|
|
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.)
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: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240815053254.470944-2-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
2024-08-14 22:32:49 -07:00
|
|
|
#ifdef TRAFFIC_MONITOR
|
|
|
|
struct tmonitor_ctx *traffic_monitor_start(const char *netns, const char *test_name,
|
|
|
|
const char *subtest_name);
|
|
|
|
void traffic_monitor_stop(struct tmonitor_ctx *ctx);
|
2025-03-05 10:20:56 -08:00
|
|
|
tm_print_fn_t traffic_monitor_set_print(tm_print_fn_t fn);
|
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.)
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: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240815053254.470944-2-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
2024-08-14 22:32:49 -07:00
|
|
|
#else
|
|
|
|
static inline struct tmonitor_ctx *traffic_monitor_start(const char *netns, const char *test_name,
|
|
|
|
const char *subtest_name)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void traffic_monitor_stop(struct tmonitor_ctx *ctx)
|
|
|
|
{
|
|
|
|
}
|
2025-03-05 10:20:56 -08:00
|
|
|
|
|
|
|
static inline tm_print_fn_t traffic_monitor_set_print(tm_print_fn_t fn)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
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.)
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: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240815053254.470944-2-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
2024-08-14 22:32:49 -07:00
|
|
|
#endif
|
|
|
|
|
2020-05-08 10:46:08 -07:00
|
|
|
#endif
|