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 <linux/ethtool.h> 13 #include <linux/sockios.h> 14 #include <netinet/tcp.h> 15 #include <bpf/bpf_endian.h> 16 #include <net/if.h> 17 18 #define MAGIC_VAL 0x1234 19 #define NUM_ITER 100000 20 #define VIP_NUM 5 21 #define MAGIC_BYTES 123 22 23 struct network_helper_opts { 24 const char *cc; 25 int timeout_ms; 26 bool must_fail; 27 bool noconnect; 28 int type; 29 int proto; 30 }; 31 32 /* ipv4 test vector */ 33 struct ipv4_packet { 34 struct ethhdr eth; 35 struct iphdr iph; 36 struct tcphdr tcp; 37 } __packed; 38 extern struct ipv4_packet pkt_v4; 39 40 /* ipv6 test vector */ 41 struct ipv6_packet { 42 struct ethhdr eth; 43 struct ipv6hdr iph; 44 struct tcphdr tcp; 45 } __packed; 46 extern struct ipv6_packet pkt_v6; 47 48 int settimeo(int fd, int timeout_ms); 49 int start_server(int family, int type, const char *addr, __u16 port, 50 int timeout_ms); 51 int start_mptcp_server(int family, const char *addr, __u16 port, 52 int timeout_ms); 53 int *start_reuseport_server(int family, int type, const char *addr_str, 54 __u16 port, int timeout_ms, 55 unsigned int nr_listens); 56 void free_fds(int *fds, unsigned int nr_close_fds); 57 int connect_to_fd(int server_fd, int timeout_ms); 58 int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); 59 int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); 60 int fastopen_connect(int server_fd, const char *data, unsigned int data_len, 61 int timeout_ms); 62 int make_sockaddr(int family, const char *addr_str, __u16 port, 63 struct sockaddr_storage *addr, socklen_t *len); 64 char *ping_command(int family); 65 int get_socket_local_port(int sock_fd); 66 int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param); 67 68 struct nstoken; 69 /** 70 * open_netns() - Switch to specified network namespace by name. 71 * 72 * Returns token with which to restore the original namespace 73 * using close_netns(). 74 */ 75 struct nstoken *open_netns(const char *name); 76 void close_netns(struct nstoken *token); 77 #endif 78