1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __NETWORK_HELPERS_H 3 #define __NETWORK_HELPERS_H 4 #include <sys/socket.h> 5 #include <sys/types.h> 6 #include <linux/types.h> 7 typedef __u16 __sum16; 8 #include <linux/if_ether.h> 9 #include <linux/if_packet.h> 10 #include <linux/ip.h> 11 #include <linux/ipv6.h> 12 #include <netinet/tcp.h> 13 #include <bpf/bpf_endian.h> 14 15 #define MAGIC_VAL 0x1234 16 #define NUM_ITER 100000 17 #define VIP_NUM 5 18 #define MAGIC_BYTES 123 19 20 struct network_helper_opts { 21 const char *cc; 22 int timeout_ms; 23 }; 24 25 /* ipv4 test vector */ 26 struct ipv4_packet { 27 struct ethhdr eth; 28 struct iphdr iph; 29 struct tcphdr tcp; 30 } __packed; 31 extern struct ipv4_packet pkt_v4; 32 33 /* ipv6 test vector */ 34 struct ipv6_packet { 35 struct ethhdr eth; 36 struct ipv6hdr iph; 37 struct tcphdr tcp; 38 } __packed; 39 extern struct ipv6_packet pkt_v6; 40 41 int settimeo(int fd, int timeout_ms); 42 int start_server(int family, int type, const char *addr, __u16 port, 43 int timeout_ms); 44 int *start_reuseport_server(int family, int type, const char *addr_str, 45 __u16 port, int timeout_ms, 46 unsigned int nr_listens); 47 void free_fds(int *fds, unsigned int nr_close_fds); 48 int connect_to_fd(int server_fd, int timeout_ms); 49 int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); 50 int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); 51 int fastopen_connect(int server_fd, const char *data, unsigned int data_len, 52 int timeout_ms); 53 int make_sockaddr(int family, const char *addr_str, __u16 port, 54 struct sockaddr_storage *addr, socklen_t *len); 55 char *ping_command(int family); 56 57 #endif 58