0001
0002 #ifndef __NETWORK_HELPERS_H
0003 #define __NETWORK_HELPERS_H
0004 #include <sys/socket.h>
0005 #include <sys/types.h>
0006 #include <linux/types.h>
0007 typedef __u16 __sum16;
0008 #include <linux/if_ether.h>
0009 #include <linux/if_packet.h>
0010 #include <linux/ip.h>
0011 #include <linux/ipv6.h>
0012 #include <netinet/tcp.h>
0013 #include <bpf/bpf_endian.h>
0014
0015 #define MAGIC_VAL 0x1234
0016 #define NUM_ITER 100000
0017 #define VIP_NUM 5
0018 #define MAGIC_BYTES 123
0019
0020 struct network_helper_opts {
0021 const char *cc;
0022 int timeout_ms;
0023 bool must_fail;
0024 };
0025
0026
0027 struct ipv4_packet {
0028 struct ethhdr eth;
0029 struct iphdr iph;
0030 struct tcphdr tcp;
0031 } __packed;
0032 extern struct ipv4_packet pkt_v4;
0033
0034
0035 struct ipv6_packet {
0036 struct ethhdr eth;
0037 struct ipv6hdr iph;
0038 struct tcphdr tcp;
0039 } __packed;
0040 extern struct ipv6_packet pkt_v6;
0041
0042 int settimeo(int fd, int timeout_ms);
0043 int start_server(int family, int type, const char *addr, __u16 port,
0044 int timeout_ms);
0045 int start_mptcp_server(int family, const char *addr, __u16 port,
0046 int timeout_ms);
0047 int *start_reuseport_server(int family, int type, const char *addr_str,
0048 __u16 port, int timeout_ms,
0049 unsigned int nr_listens);
0050 void free_fds(int *fds, unsigned int nr_close_fds);
0051 int connect_to_fd(int server_fd, int timeout_ms);
0052 int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts);
0053 int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms);
0054 int fastopen_connect(int server_fd, const char *data, unsigned int data_len,
0055 int timeout_ms);
0056 int make_sockaddr(int family, const char *addr_str, __u16 port,
0057 struct sockaddr_storage *addr, socklen_t *len);
0058 char *ping_command(int family);
0059
0060 struct nstoken;
0061
0062
0063
0064
0065
0066
0067 struct nstoken *open_netns(const char *name);
0068 void close_netns(struct nstoken *token);
0069 #endif