xref: /linux/samples/bpf/cookie_uid_helper_example.c (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
151570a5aSChenbo Feng /* This test is a demo of using get_socket_uid and get_socket_cookie
251570a5aSChenbo Feng  * helper function to do per socket based network traffic monitoring.
351570a5aSChenbo Feng  * It requires iptables version higher then 1.6.1. to load pinned eBPF
451570a5aSChenbo Feng  * program into the xt_bpf match.
551570a5aSChenbo Feng  *
651570a5aSChenbo Feng  * TEST:
700f660eaSChenbo Feng  * ./run_cookie_uid_helper_example.sh -option
800f660eaSChenbo Feng  * option:
900f660eaSChenbo Feng  *	-t: do traffic monitoring test, the program will continuously
1000f660eaSChenbo Feng  * print out network traffic happens after program started A sample
1100f660eaSChenbo Feng  * output is shown below:
1251570a5aSChenbo Feng  *
1351570a5aSChenbo Feng  * cookie: 877, uid: 0x3e8, Pakcet Count: 20, Bytes Count: 11058
1451570a5aSChenbo Feng  * cookie: 132, uid: 0x0, Pakcet Count: 2, Bytes Count: 286
1551570a5aSChenbo Feng  * cookie: 812, uid: 0x3e8, Pakcet Count: 3, Bytes Count: 1726
1651570a5aSChenbo Feng  * cookie: 802, uid: 0x3e8, Pakcet Count: 2, Bytes Count: 104
1751570a5aSChenbo Feng  * cookie: 877, uid: 0x3e8, Pakcet Count: 20, Bytes Count: 11058
1851570a5aSChenbo Feng  * cookie: 831, uid: 0x3e8, Pakcet Count: 2, Bytes Count: 104
1951570a5aSChenbo Feng  * cookie: 0, uid: 0x0, Pakcet Count: 6, Bytes Count: 712
2051570a5aSChenbo Feng  * cookie: 880, uid: 0xfffe, Pakcet Count: 1, Bytes Count: 70
2151570a5aSChenbo Feng  *
2200f660eaSChenbo Feng  *	-s: do getsockopt SO_COOKIE test, the program will set up a pair of
2300f660eaSChenbo Feng  * UDP sockets and send packets between them. And read out the traffic data
2400f660eaSChenbo Feng  * directly from the ebpf map based on the socket cookie.
2500f660eaSChenbo Feng  *
2651570a5aSChenbo Feng  * Clean up: if using shell script, the script file will delete the iptables
2751570a5aSChenbo Feng  * rule and unmount the bpf program when exit. Else the iptables rule need
2851570a5aSChenbo Feng  * to be deleted by hand, see run_cookie_uid_helper_example.sh for detail.
2951570a5aSChenbo Feng  */
3051570a5aSChenbo Feng 
3151570a5aSChenbo Feng #define _GNU_SOURCE
3251570a5aSChenbo Feng 
3351570a5aSChenbo Feng #define offsetof(type, member)	__builtin_offsetof(type, member)
3451570a5aSChenbo Feng #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
3551570a5aSChenbo Feng 
3651570a5aSChenbo Feng #include <arpa/inet.h>
3751570a5aSChenbo Feng #include <errno.h>
3851570a5aSChenbo Feng #include <error.h>
3951570a5aSChenbo Feng #include <limits.h>
4051570a5aSChenbo Feng #include <linux/bpf.h>
4151570a5aSChenbo Feng #include <linux/if_ether.h>
4200f660eaSChenbo Feng #include <net/if.h>
4300f660eaSChenbo Feng #include <signal.h>
4451570a5aSChenbo Feng #include <stdbool.h>
4551570a5aSChenbo Feng #include <stdint.h>
4651570a5aSChenbo Feng #include <stdio.h>
4751570a5aSChenbo Feng #include <stdlib.h>
4851570a5aSChenbo Feng #include <string.h>
4951570a5aSChenbo Feng #include <sys/socket.h>
5051570a5aSChenbo Feng #include <sys/stat.h>
5151570a5aSChenbo Feng #include <sys/types.h>
5251570a5aSChenbo Feng #include <unistd.h>
5351570a5aSChenbo Feng #include <bpf/bpf.h>
548d930450SJakub Kicinski #include "bpf_insn.h"
5551570a5aSChenbo Feng 
5600f660eaSChenbo Feng #define PORT 8888
5700f660eaSChenbo Feng 
5851570a5aSChenbo Feng struct stats {
5951570a5aSChenbo Feng 	uint32_t uid;
6051570a5aSChenbo Feng 	uint64_t packets;
6151570a5aSChenbo Feng 	uint64_t bytes;
6251570a5aSChenbo Feng };
6351570a5aSChenbo Feng 
6451570a5aSChenbo Feng static int map_fd, prog_fd;
6551570a5aSChenbo Feng 
6600f660eaSChenbo Feng static bool test_finish;
6700f660eaSChenbo Feng 
maps_create(void)6851570a5aSChenbo Feng static void maps_create(void)
6951570a5aSChenbo Feng {
70*c58f9815SAndrii Nakryiko 	map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(uint32_t),
71*c58f9815SAndrii Nakryiko 				sizeof(struct stats), 100, NULL);
7251570a5aSChenbo Feng 	if (map_fd < 0)
7351570a5aSChenbo Feng 		error(1, errno, "map create failed!\n");
7451570a5aSChenbo Feng }
7551570a5aSChenbo Feng 
prog_load(void)7651570a5aSChenbo Feng static void prog_load(void)
7751570a5aSChenbo Feng {
7851570a5aSChenbo Feng 	static char log_buf[1 << 16];
7951570a5aSChenbo Feng 
8051570a5aSChenbo Feng 	struct bpf_insn prog[] = {
8151570a5aSChenbo Feng 		/*
8251570a5aSChenbo Feng 		 * Save sk_buff for future usage. value stored in R6 to R10 will
8351570a5aSChenbo Feng 		 * not be reset after a bpf helper function call.
8451570a5aSChenbo Feng 		 */
8551570a5aSChenbo Feng 		BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
8651570a5aSChenbo Feng 		/*
8751570a5aSChenbo Feng 		 * pc1: BPF_FUNC_get_socket_cookie takes one parameter,
8851570a5aSChenbo Feng 		 * R1: sk_buff
8951570a5aSChenbo Feng 		 */
9051570a5aSChenbo Feng 		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
9151570a5aSChenbo Feng 				BPF_FUNC_get_socket_cookie),
9251570a5aSChenbo Feng 		/* pc2-4: save &socketCookie to r7 for future usage*/
9351570a5aSChenbo Feng 		BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
9451570a5aSChenbo Feng 		BPF_MOV64_REG(BPF_REG_7, BPF_REG_10),
9551570a5aSChenbo Feng 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, -8),
9651570a5aSChenbo Feng 		/*
9751570a5aSChenbo Feng 		 * pc5-8: set up the registers for BPF_FUNC_map_lookup_elem,
9851570a5aSChenbo Feng 		 * it takes two parameters (R1: map_fd,  R2: &socket_cookie)
9951570a5aSChenbo Feng 		 */
10051570a5aSChenbo Feng 		BPF_LD_MAP_FD(BPF_REG_1, map_fd),
10151570a5aSChenbo Feng 		BPF_MOV64_REG(BPF_REG_2, BPF_REG_7),
10251570a5aSChenbo Feng 		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
10351570a5aSChenbo Feng 				BPF_FUNC_map_lookup_elem),
10451570a5aSChenbo Feng 		/*
10551570a5aSChenbo Feng 		 * pc9. if r0 != 0x0, go to pc+14, since we have the cookie
10651570a5aSChenbo Feng 		 * stored already
10751570a5aSChenbo Feng 		 * Otherwise do pc10-22 to setup a new data entry.
10851570a5aSChenbo Feng 		 */
10951570a5aSChenbo Feng 		BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 14),
11051570a5aSChenbo Feng 		BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
11151570a5aSChenbo Feng 		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
11251570a5aSChenbo Feng 				BPF_FUNC_get_socket_uid),
11351570a5aSChenbo Feng 		/*
11451570a5aSChenbo Feng 		 * Place a struct stats in the R10 stack and sequentially
11551570a5aSChenbo Feng 		 * place the member value into the memory. Packets value
11651570a5aSChenbo Feng 		 * is set by directly place a IMM value 1 into the stack.
11751570a5aSChenbo Feng 		 */
11851570a5aSChenbo Feng 		BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0,
119eb6211d3SDaniel Borkmann 			    -32 + (__s16)offsetof(struct stats, uid)),
12051570a5aSChenbo Feng 		BPF_ST_MEM(BPF_DW, BPF_REG_10,
121eb6211d3SDaniel Borkmann 			   -32 + (__s16)offsetof(struct stats, packets), 1),
12251570a5aSChenbo Feng 		/*
12351570a5aSChenbo Feng 		 * __sk_buff is a special struct used for eBPF program to
12451570a5aSChenbo Feng 		 * directly access some sk_buff field.
12551570a5aSChenbo Feng 		 */
12651570a5aSChenbo Feng 		BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_6,
12751570a5aSChenbo Feng 				offsetof(struct __sk_buff, len)),
12851570a5aSChenbo Feng 		BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_1,
129eb6211d3SDaniel Borkmann 			    -32 + (__s16)offsetof(struct stats, bytes)),
13051570a5aSChenbo Feng 		/*
13151570a5aSChenbo Feng 		 * add new map entry using BPF_FUNC_map_update_elem, it takes
13251570a5aSChenbo Feng 		 * 4 parameters (R1: map_fd, R2: &socket_cookie, R3: &stats,
13351570a5aSChenbo Feng 		 * R4: flags)
13451570a5aSChenbo Feng 		 */
13551570a5aSChenbo Feng 		BPF_LD_MAP_FD(BPF_REG_1, map_fd),
13651570a5aSChenbo Feng 		BPF_MOV64_REG(BPF_REG_2, BPF_REG_7),
13751570a5aSChenbo Feng 		BPF_MOV64_REG(BPF_REG_3, BPF_REG_10),
13851570a5aSChenbo Feng 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, -32),
13951570a5aSChenbo Feng 		BPF_MOV64_IMM(BPF_REG_4, 0),
14051570a5aSChenbo Feng 		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
14151570a5aSChenbo Feng 				BPF_FUNC_map_update_elem),
14251570a5aSChenbo Feng 		BPF_JMP_IMM(BPF_JA, 0, 0, 5),
14351570a5aSChenbo Feng 		/*
14451570a5aSChenbo Feng 		 * pc24-30 update the packet info to a exist data entry, it can
14551570a5aSChenbo Feng 		 * be done by directly write to pointers instead of using
14651570a5aSChenbo Feng 		 * BPF_FUNC_map_update_elem helper function
14751570a5aSChenbo Feng 		 */
14851570a5aSChenbo Feng 		BPF_MOV64_REG(BPF_REG_9, BPF_REG_0),
14951570a5aSChenbo Feng 		BPF_MOV64_IMM(BPF_REG_1, 1),
15091c960b0SBrendan Jackman 		BPF_ATOMIC_OP(BPF_DW, BPF_ADD, BPF_REG_9, BPF_REG_1,
15151570a5aSChenbo Feng 			      offsetof(struct stats, packets)),
15251570a5aSChenbo Feng 		BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_6,
15351570a5aSChenbo Feng 				offsetof(struct __sk_buff, len)),
15491c960b0SBrendan Jackman 		BPF_ATOMIC_OP(BPF_DW, BPF_ADD, BPF_REG_9, BPF_REG_1,
15551570a5aSChenbo Feng 			      offsetof(struct stats, bytes)),
15651570a5aSChenbo Feng 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_6,
15751570a5aSChenbo Feng 				offsetof(struct __sk_buff, len)),
15851570a5aSChenbo Feng 		BPF_EXIT_INSN(),
15951570a5aSChenbo Feng 	};
160*c58f9815SAndrii Nakryiko 	LIBBPF_OPTS(bpf_prog_load_opts, opts,
161*c58f9815SAndrii Nakryiko 		.log_buf = log_buf,
162*c58f9815SAndrii Nakryiko 		.log_size = sizeof(log_buf),
163*c58f9815SAndrii Nakryiko 	);
164*c58f9815SAndrii Nakryiko 
165*c58f9815SAndrii Nakryiko 	prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL",
166*c58f9815SAndrii Nakryiko 				prog, ARRAY_SIZE(prog), &opts);
16751570a5aSChenbo Feng 	if (prog_fd < 0)
16851570a5aSChenbo Feng 		error(1, errno, "failed to load prog\n%s\n", log_buf);
16951570a5aSChenbo Feng }
17051570a5aSChenbo Feng 
prog_attach_iptables(char * file)17151570a5aSChenbo Feng static void prog_attach_iptables(char *file)
17251570a5aSChenbo Feng {
17351570a5aSChenbo Feng 	int ret;
17450b796e6SKumar Kartikeya Dwivedi 	char rules[256];
17551570a5aSChenbo Feng 
17651570a5aSChenbo Feng 	if (bpf_obj_pin(prog_fd, file))
17751570a5aSChenbo Feng 		error(1, errno, "bpf_obj_pin");
17851570a5aSChenbo Feng 	if (strlen(file) > 50) {
17951570a5aSChenbo Feng 		printf("file path too long: %s\n", file);
18051570a5aSChenbo Feng 		exit(1);
18151570a5aSChenbo Feng 	}
18250b796e6SKumar Kartikeya Dwivedi 	ret = snprintf(rules, sizeof(rules),
18350b796e6SKumar Kartikeya Dwivedi 		       "iptables -A OUTPUT -m bpf --object-pinned %s -j ACCEPT",
18451570a5aSChenbo Feng 		       file);
18550b796e6SKumar Kartikeya Dwivedi 	if (ret < 0 || ret >= sizeof(rules)) {
18650b796e6SKumar Kartikeya Dwivedi 		printf("error constructing iptables command\n");
18750b796e6SKumar Kartikeya Dwivedi 		exit(1);
18850b796e6SKumar Kartikeya Dwivedi 	}
18951570a5aSChenbo Feng 	ret = system(rules);
19051570a5aSChenbo Feng 	if (ret < 0) {
19151570a5aSChenbo Feng 		printf("iptables rule update failed: %d/n", WEXITSTATUS(ret));
19251570a5aSChenbo Feng 		exit(1);
19351570a5aSChenbo Feng 	}
19451570a5aSChenbo Feng }
19551570a5aSChenbo Feng 
print_table(void)19651570a5aSChenbo Feng static void print_table(void)
19751570a5aSChenbo Feng {
19851570a5aSChenbo Feng 	struct stats curEntry;
19951570a5aSChenbo Feng 	uint32_t curN = UINT32_MAX;
20000f660eaSChenbo Feng 	uint32_t nextN;
20100f660eaSChenbo Feng 	int res;
20251570a5aSChenbo Feng 
20351570a5aSChenbo Feng 	while (bpf_map_get_next_key(map_fd, &curN, &nextN) > -1) {
20451570a5aSChenbo Feng 		curN = nextN;
20551570a5aSChenbo Feng 		res = bpf_map_lookup_elem(map_fd, &curN, &curEntry);
20651570a5aSChenbo Feng 		if (res < 0) {
20751570a5aSChenbo Feng 			error(1, errno, "fail to get entry value of Key: %u\n",
20851570a5aSChenbo Feng 				curN);
20951570a5aSChenbo Feng 		} else {
21051570a5aSChenbo Feng 			printf("cookie: %u, uid: 0x%x, Packet Count: %lu,"
21151570a5aSChenbo Feng 				" Bytes Count: %lu\n", curN, curEntry.uid,
21251570a5aSChenbo Feng 				curEntry.packets, curEntry.bytes);
21351570a5aSChenbo Feng 		}
21451570a5aSChenbo Feng 	}
21551570a5aSChenbo Feng }
21651570a5aSChenbo Feng 
udp_client(void)21700f660eaSChenbo Feng static void udp_client(void)
21851570a5aSChenbo Feng {
21900f660eaSChenbo Feng 	struct sockaddr_in si_other = {0};
22000f660eaSChenbo Feng 	struct sockaddr_in si_me = {0};
22100f660eaSChenbo Feng 	struct stats dataEntry;
22200f660eaSChenbo Feng 	int s_rcv, s_send, i, recv_len;
22300f660eaSChenbo Feng 	char message = 'a';
22400f660eaSChenbo Feng 	char buf;
22500f660eaSChenbo Feng 	uint64_t cookie;
22600f660eaSChenbo Feng 	int res;
22700f660eaSChenbo Feng 	socklen_t cookie_len = sizeof(cookie);
22800f660eaSChenbo Feng 	socklen_t slen = sizeof(si_other);
22900f660eaSChenbo Feng 
23000f660eaSChenbo Feng 	s_rcv = socket(PF_INET, SOCK_DGRAM, 0);
23100f660eaSChenbo Feng 	if (s_rcv < 0)
23200f660eaSChenbo Feng 		error(1, errno, "rcv socket creat failed!\n");
23300f660eaSChenbo Feng 	si_other.sin_family = AF_INET;
23400f660eaSChenbo Feng 	si_other.sin_port = htons(PORT);
23500f660eaSChenbo Feng 	if (inet_aton("127.0.0.1", &si_other.sin_addr) == 0)
23600f660eaSChenbo Feng 		error(1, errno, "inet_aton\n");
23700f660eaSChenbo Feng 	if (bind(s_rcv, (struct sockaddr *)&si_other, sizeof(si_other)) == -1)
23800f660eaSChenbo Feng 		error(1, errno, "bind\n");
23900f660eaSChenbo Feng 	s_send = socket(PF_INET, SOCK_DGRAM, 0);
24000f660eaSChenbo Feng 	if (s_send < 0)
24100f660eaSChenbo Feng 		error(1, errno, "send socket creat failed!\n");
24200f660eaSChenbo Feng 	res = getsockopt(s_send, SOL_SOCKET, SO_COOKIE, &cookie, &cookie_len);
24300f660eaSChenbo Feng 	if (res < 0)
24400f660eaSChenbo Feng 		printf("get cookie failed: %s\n", strerror(errno));
24500f660eaSChenbo Feng 	res = bpf_map_lookup_elem(map_fd, &cookie, &dataEntry);
24600f660eaSChenbo Feng 	if (res != -1)
24700f660eaSChenbo Feng 		error(1, errno, "socket stat found while flow not active\n");
24800f660eaSChenbo Feng 	for (i = 0; i < 10; i++) {
24900f660eaSChenbo Feng 		res = sendto(s_send, &message, sizeof(message), 0,
25000f660eaSChenbo Feng 			     (struct sockaddr *)&si_other, slen);
25100f660eaSChenbo Feng 		if (res == -1)
25200f660eaSChenbo Feng 			error(1, errno, "send\n");
25300f660eaSChenbo Feng 		if (res != sizeof(message))
25400f660eaSChenbo Feng 			error(1, 0, "%uB != %luB\n", res, sizeof(message));
25500f660eaSChenbo Feng 		recv_len = recvfrom(s_rcv, &buf, sizeof(buf), 0,
25600f660eaSChenbo Feng 			     (struct sockaddr *)&si_me, &slen);
25700f660eaSChenbo Feng 		if (recv_len < 0)
25820cfb7a0SColin Ian King 			error(1, errno, "receive\n");
25900f660eaSChenbo Feng 		res = memcmp(&(si_other.sin_addr), &(si_me.sin_addr),
26000f660eaSChenbo Feng 			   sizeof(si_me.sin_addr));
26100f660eaSChenbo Feng 		if (res != 0)
26200f660eaSChenbo Feng 			error(1, EFAULT, "sender addr error: %d\n", res);
26300f660eaSChenbo Feng 		printf("Message received: %c\n", buf);
26400f660eaSChenbo Feng 		res = bpf_map_lookup_elem(map_fd, &cookie, &dataEntry);
26500f660eaSChenbo Feng 		if (res < 0)
26600f660eaSChenbo Feng 			error(1, errno, "lookup sk stat failed, cookie: %lu\n",
26700f660eaSChenbo Feng 			      cookie);
26800f660eaSChenbo Feng 		printf("cookie: %lu, uid: 0x%x, Packet Count: %lu,"
26900f660eaSChenbo Feng 			" Bytes Count: %lu\n\n", cookie, dataEntry.uid,
27000f660eaSChenbo Feng 			dataEntry.packets, dataEntry.bytes);
27100f660eaSChenbo Feng 	}
27200f660eaSChenbo Feng 	close(s_send);
27300f660eaSChenbo Feng 	close(s_rcv);
27400f660eaSChenbo Feng }
27500f660eaSChenbo Feng 
usage(void)27600f660eaSChenbo Feng static int usage(void)
27700f660eaSChenbo Feng {
27800f660eaSChenbo Feng 	printf("Usage: ./run_cookie_uid_helper_example.sh"
27900f660eaSChenbo Feng 		" bpfObjName -option\n"
28000f660eaSChenbo Feng 		"	-t	traffic monitor test\n"
28100f660eaSChenbo Feng 		"	-s	getsockopt cookie test\n");
28251570a5aSChenbo Feng 	return 1;
28351570a5aSChenbo Feng }
28451570a5aSChenbo Feng 
finish(int ret)2854784726fSAlexander Alemayhu static void finish(int ret)
28600f660eaSChenbo Feng {
28700f660eaSChenbo Feng 	test_finish = true;
28800f660eaSChenbo Feng }
28900f660eaSChenbo Feng 
main(int argc,char * argv[])29000f660eaSChenbo Feng int main(int argc, char *argv[])
29100f660eaSChenbo Feng {
29200f660eaSChenbo Feng 	int opt;
29300f660eaSChenbo Feng 	bool cfg_test_traffic = false;
29400f660eaSChenbo Feng 	bool cfg_test_cookie = false;
29500f660eaSChenbo Feng 
29600f660eaSChenbo Feng 	if (argc != 3)
29700f660eaSChenbo Feng 		return usage();
29800f660eaSChenbo Feng 	while ((opt = getopt(argc, argv, "ts")) != -1) {
29900f660eaSChenbo Feng 		switch (opt) {
30000f660eaSChenbo Feng 		case 't':
30100f660eaSChenbo Feng 			cfg_test_traffic = true;
30200f660eaSChenbo Feng 			break;
30300f660eaSChenbo Feng 		case 's':
30400f660eaSChenbo Feng 			cfg_test_cookie = true;
30500f660eaSChenbo Feng 			break;
30600f660eaSChenbo Feng 
30700f660eaSChenbo Feng 		default:
30800f660eaSChenbo Feng 			printf("unknown option %c\n", opt);
30900f660eaSChenbo Feng 			usage();
31000f660eaSChenbo Feng 			return -1;
31100f660eaSChenbo Feng 		}
31200f660eaSChenbo Feng 	}
31351570a5aSChenbo Feng 	maps_create();
31451570a5aSChenbo Feng 	prog_load();
31500f660eaSChenbo Feng 	prog_attach_iptables(argv[2]);
31600f660eaSChenbo Feng 	if (cfg_test_traffic) {
31700f660eaSChenbo Feng 		if (signal(SIGINT, finish) == SIG_ERR)
318ad990dbeSAndy Gospodarek 			error(1, errno, "register SIGINT handler failed");
319ad990dbeSAndy Gospodarek 		if (signal(SIGTERM, finish) == SIG_ERR)
320ad990dbeSAndy Gospodarek 			error(1, errno, "register SIGTERM handler failed");
32100f660eaSChenbo Feng 		while (!test_finish) {
32251570a5aSChenbo Feng 			print_table();
32351570a5aSChenbo Feng 			printf("\n");
32451570a5aSChenbo Feng 			sleep(1);
3251132b998SYang Li 		}
32600f660eaSChenbo Feng 	} else if (cfg_test_cookie) {
32700f660eaSChenbo Feng 		udp_client();
32800f660eaSChenbo Feng 	}
32900f660eaSChenbo Feng 	close(prog_fd);
33000f660eaSChenbo Feng 	close(map_fd);
33151570a5aSChenbo Feng 	return 0;
33251570a5aSChenbo Feng }
333