1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #include <stdio.h> 3 #include <unistd.h> 4 #include <errno.h> 5 #include <string.h> 6 #include <assert.h> 7 #include <stdlib.h> 8 #include <stdarg.h> 9 #include <time.h> 10 #include <signal.h> 11 12 #include <linux/types.h> 13 typedef __u16 __sum16; 14 #include <arpa/inet.h> 15 #include <linux/if_ether.h> 16 #include <linux/if_packet.h> 17 #include <linux/ip.h> 18 #include <linux/ipv6.h> 19 #include <linux/tcp.h> 20 #include <linux/filter.h> 21 #include <linux/perf_event.h> 22 #include <linux/unistd.h> 23 24 #include <sys/ioctl.h> 25 #include <sys/wait.h> 26 #include <sys/types.h> 27 #include <sys/time.h> 28 #include <fcntl.h> 29 #include <pthread.h> 30 #include <linux/bpf.h> 31 #include <linux/err.h> 32 #include <bpf/bpf.h> 33 #include <bpf/libbpf.h> 34 35 #include "test_iptunnel_common.h" 36 #include "bpf_util.h" 37 #include "bpf_endian.h" 38 #include "trace_helpers.h" 39 #include "flow_dissector_load.h" 40 41 extern int error_cnt, pass_cnt; 42 extern bool jit_enabled; 43 44 #define MAGIC_BYTES 123 45 46 /* ipv4 test vector */ 47 struct ipv4_packet { 48 struct ethhdr eth; 49 struct iphdr iph; 50 struct tcphdr tcp; 51 } __packed; 52 extern struct ipv4_packet pkt_v4; 53 54 /* ipv6 test vector */ 55 struct ipv6_packet { 56 struct ethhdr eth; 57 struct ipv6hdr iph; 58 struct tcphdr tcp; 59 } __packed; 60 extern struct ipv6_packet pkt_v6; 61 62 #define _CHECK(condition, tag, duration, format...) ({ \ 63 int __ret = !!(condition); \ 64 if (__ret) { \ 65 error_cnt++; \ 66 printf("%s:FAIL:%s ", __func__, tag); \ 67 printf(format); \ 68 } else { \ 69 pass_cnt++; \ 70 printf("%s:PASS:%s %d nsec\n", __func__, tag, duration);\ 71 } \ 72 __ret; \ 73 }) 74 75 #define CHECK(condition, tag, format...) \ 76 _CHECK(condition, tag, duration, format) 77 #define CHECK_ATTR(condition, tag, format...) \ 78 _CHECK(condition, tag, tattr.duration, format) 79 80 #define MAGIC_VAL 0x1234 81 #define NUM_ITER 100000 82 #define VIP_NUM 5 83 84 static inline __u64 ptr_to_u64(const void *ptr) 85 { 86 return (__u64) (unsigned long) ptr; 87 } 88 89 int bpf_find_map(const char *test, struct bpf_object *obj, const char *name); 90 int compare_map_keys(int map1_fd, int map2_fd); 91 int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len); 92 int extract_build_id(char *build_id, size_t size); 93 void *spin_lock_thread(void *arg); 94