133181bb8SStanislav Fomichev /* SPDX-License-Identifier: GPL-2.0 */ 233181bb8SStanislav Fomichev #ifndef __NETWORK_HELPERS_H 333181bb8SStanislav Fomichev #define __NETWORK_HELPERS_H 433181bb8SStanislav Fomichev #include <sys/socket.h> 533181bb8SStanislav Fomichev #include <sys/types.h> 6488a23b8SStanislav Fomichev #include <linux/types.h> 7488a23b8SStanislav Fomichev typedef __u16 __sum16; 8488a23b8SStanislav Fomichev #include <linux/if_ether.h> 9488a23b8SStanislav Fomichev #include <linux/if_packet.h> 10488a23b8SStanislav Fomichev #include <linux/ip.h> 11488a23b8SStanislav Fomichev #include <linux/ipv6.h> 12488a23b8SStanislav Fomichev #include <netinet/tcp.h> 13488a23b8SStanislav Fomichev #include <bpf/bpf_endian.h> 14488a23b8SStanislav Fomichev 15488a23b8SStanislav Fomichev #define MAGIC_VAL 0x1234 16488a23b8SStanislav Fomichev #define NUM_ITER 100000 17488a23b8SStanislav Fomichev #define VIP_NUM 5 18488a23b8SStanislav Fomichev #define MAGIC_BYTES 123 19488a23b8SStanislav Fomichev 203d778983SMartin KaFai Lau struct network_helper_opts { 213d778983SMartin KaFai Lau const char *cc; 223d778983SMartin KaFai Lau int timeout_ms; 2343d2b88cSDaniel Borkmann bool must_fail; 243d778983SMartin KaFai Lau }; 253d778983SMartin KaFai Lau 26488a23b8SStanislav Fomichev /* ipv4 test vector */ 27488a23b8SStanislav Fomichev struct ipv4_packet { 28488a23b8SStanislav Fomichev struct ethhdr eth; 29488a23b8SStanislav Fomichev struct iphdr iph; 30488a23b8SStanislav Fomichev struct tcphdr tcp; 31488a23b8SStanislav Fomichev } __packed; 32488a23b8SStanislav Fomichev extern struct ipv4_packet pkt_v4; 33488a23b8SStanislav Fomichev 34488a23b8SStanislav Fomichev /* ipv6 test vector */ 35488a23b8SStanislav Fomichev struct ipv6_packet { 36488a23b8SStanislav Fomichev struct ethhdr eth; 37488a23b8SStanislav Fomichev struct ipv6hdr iph; 38488a23b8SStanislav Fomichev struct tcphdr tcp; 39488a23b8SStanislav Fomichev } __packed; 40488a23b8SStanislav Fomichev extern struct ipv6_packet pkt_v6; 4133181bb8SStanislav Fomichev 42096eccdeSJussi Maki int settimeo(int fd, int timeout_ms); 4399126abeSMartin KaFai Lau int start_server(int family, int type, const char *addr, __u16 port, 4499126abeSMartin KaFai Lau int timeout_ms); 45eed92afdSMartin KaFai Lau int *start_reuseport_server(int family, int type, const char *addr_str, 46eed92afdSMartin KaFai Lau __u16 port, int timeout_ms, 47eed92afdSMartin KaFai Lau unsigned int nr_listens); 48eed92afdSMartin KaFai Lau void free_fds(int *fds, unsigned int nr_close_fds); 4999126abeSMartin KaFai Lau int connect_to_fd(int server_fd, int timeout_ms); 503d778983SMartin KaFai Lau int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); 5199126abeSMartin KaFai Lau int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); 528085e1dcSMartin KaFai Lau int fastopen_connect(int server_fd, const char *data, unsigned int data_len, 538085e1dcSMartin KaFai Lau int timeout_ms); 540ab5539fSJakub Sitnicki int make_sockaddr(int family, const char *addr_str, __u16 port, 550ab5539fSJakub Sitnicki struct sockaddr_storage *addr, socklen_t *len); 56372642eaSStanislav Fomichev char *ping_command(int family); 5733181bb8SStanislav Fomichev 58*a3033884SToke Høiland-Jørgensen struct nstoken; 59*a3033884SToke Høiland-Jørgensen /** 60*a3033884SToke Høiland-Jørgensen * open_netns() - Switch to specified network namespace by name. 61*a3033884SToke Høiland-Jørgensen * 62*a3033884SToke Høiland-Jørgensen * Returns token with which to restore the original namespace 63*a3033884SToke Høiland-Jørgensen * using close_netns(). 64*a3033884SToke Høiland-Jørgensen */ 65*a3033884SToke Høiland-Jørgensen struct nstoken *open_netns(const char *name); 66*a3033884SToke Høiland-Jørgensen void close_netns(struct nstoken *token); 6733181bb8SStanislav Fomichev #endif 68