1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2017-2018 Covalent IO, Inc. http://covalent.io
5 #include <sys/socket.h>
7 #include <sys/select.h>
8 #include <netinet/in.h>
21 #include <sys/types.h>
22 #include <sys/sendfile.h>
24 #include <linux/netlink.h>
25 #include <linux/socket.h>
26 #include <linux/sock_diag.h>
27 #include <linux/bpf.h>
28 #include <linux/if_link.h>
29 #include <linux/tls.h>
36 #include <bpf/libbpf.h>
39 #include "cgroup_helpers.h"
42 static void running_handler(int a);
51 /* randomly selected ports for testing on lo */
55 #define BPF_SOCKMAP_FILENAME "test_sockmap_kern.bpf.o"
56 #define BPF_SOCKHASH_FILENAME "test_sockhash_kern.bpf.o"
57 #define CG_PATH "/sockmap"
59 #define EDATAINTEGRITY 2001
62 int s1, s2, c1, c2, p1, p2;
67 struct bpf_map *maps[9];
68 struct bpf_program *progs[9];
69 struct bpf_link *links[9];
85 int txmsg_ktls_skb_drop;
86 int txmsg_ktls_skb_redir;
90 int txmsg_omit_skb_parser;
91 int verify_push_start;
96 static const struct option long_options[] = {
97 {"help", no_argument, NULL, 'h' },
98 {"cgroup", required_argument, NULL, 'c' },
99 {"rate", required_argument, NULL, 'r' },
100 {"verbose", optional_argument, NULL, 'v' },
101 {"iov_count", required_argument, NULL, 'i' },
102 {"length", required_argument, NULL, 'l' },
103 {"test", required_argument, NULL, 't' },
104 {"data_test", no_argument, NULL, 'd' },
105 {"txmsg", no_argument, &txmsg_pass, 1 },
106 {"txmsg_redir", no_argument, &txmsg_redir, 1 },
107 {"txmsg_drop", no_argument, &txmsg_drop, 1 },
108 {"txmsg_apply", required_argument, NULL, 'a'},
109 {"txmsg_cork", required_argument, NULL, 'k'},
110 {"txmsg_start", required_argument, NULL, 's'},
111 {"txmsg_end", required_argument, NULL, 'e'},
112 {"txmsg_start_push", required_argument, NULL, 'p'},
113 {"txmsg_end_push", required_argument, NULL, 'q'},
114 {"txmsg_start_pop", required_argument, NULL, 'w'},
115 {"txmsg_pop", required_argument, NULL, 'x'},
116 {"txmsg_ingress", no_argument, &txmsg_ingress, 1 },
117 {"txmsg_redir_skb", no_argument, &txmsg_redir_skb, 1 },
118 {"ktls", no_argument, &ktls, 1 },
119 {"peek", no_argument, &peek_flag, 1 },
120 {"txmsg_omit_skb_parser", no_argument, &txmsg_omit_skb_parser, 1},
121 {"whitelist", required_argument, NULL, 'n' },
122 {"blacklist", required_argument, NULL, 'b' },
141 struct sockmap_options {
147 bool check_recved_len;
160 void (*tester)(int cg_fd, struct sockmap_options *opt);
163 static void test_start(void)
168 static void test_fail(void)
173 static void test_pass(void)
178 static void test_reset(void)
180 txmsg_start = txmsg_end = 0;
181 txmsg_start_pop = txmsg_pop = 0;
182 txmsg_start_push = txmsg_end_push = 0;
183 txmsg_pass = txmsg_drop = txmsg_redir = 0;
184 txmsg_apply = txmsg_cork = 0;
185 txmsg_ingress = txmsg_redir_skb = 0;
186 txmsg_ktls_skb = txmsg_ktls_skb_drop = txmsg_ktls_skb_redir = 0;
187 txmsg_omit_skb_parser = 0;
191 static int test_start_subtest(const struct _test *t, struct sockmap_options *o)
194 env.subtest = t->title;
195 env.prepend = o->prepend;
198 env.fail_last = env.fail_cnt;
203 static void test_end_subtest(void)
205 int error = env.fail_cnt - env.fail_last;
206 int type = strcmp(env.type, BPF_SOCKMAP_FILENAME);
211 fprintf(stdout, "#%2d/%2d %8s:%s:%s:%s\n",
212 env.test_num, env.subtest_num,
213 !type ? "sockmap" : "sockhash",
215 env.subtest, error ? "FAIL" : "OK");
218 static void test_print_results(void)
220 fprintf(stdout, "Pass: %d Fail: %d\n",
221 env.succ_cnt, env.fail_cnt);
224 static void usage(char *argv[])
228 printf(" Usage: %s --cgroup <cgroup_path>\n", argv[0]);
229 printf(" options:\n");
230 for (i = 0; long_options[i].name != 0; i++) {
231 printf(" --%-12s", long_options[i].name);
232 if (long_options[i].flag != NULL)
233 printf(" flag (internal value:%d)\n",
234 *long_options[i].flag);
236 printf(" -%c\n", long_options[i].val);
241 char *sock_to_string(int s)
259 static int sockmap_init_ktls(int verbose, int s)
261 struct tls12_crypto_info_aes_gcm_128 tls_tx = {
263 .version = TLS_1_2_VERSION,
264 .cipher_type = TLS_CIPHER_AES_GCM_128,
267 struct tls12_crypto_info_aes_gcm_128 tls_rx = {
269 .version = TLS_1_2_VERSION,
270 .cipher_type = TLS_CIPHER_AES_GCM_128,
273 int so_buf = 6553500;
276 err = setsockopt(s, 6, TCP_ULP, "tls", sizeof("tls"));
278 fprintf(stderr, "setsockopt: TCP_ULP(%s) failed with error %i\n", sock_to_string(s), err);
281 err = setsockopt(s, SOL_TLS, TLS_TX, (void *)&tls_tx, sizeof(tls_tx));
283 fprintf(stderr, "setsockopt: TLS_TX(%s) failed with error %i\n", sock_to_string(s), err);
286 err = setsockopt(s, SOL_TLS, TLS_RX, (void *)&tls_rx, sizeof(tls_rx));
288 fprintf(stderr, "setsockopt: TLS_RX(%s) failed with error %i\n", sock_to_string(s), err);
291 err = setsockopt(s, SOL_SOCKET, SO_SNDBUF, &so_buf, sizeof(so_buf));
293 fprintf(stderr, "setsockopt: (%s) failed sndbuf with error %i\n", sock_to_string(s), err);
296 err = setsockopt(s, SOL_SOCKET, SO_RCVBUF, &so_buf, sizeof(so_buf));
298 fprintf(stderr, "setsockopt: (%s) failed rcvbuf with error %i\n", sock_to_string(s), err);
303 fprintf(stdout, "socket(%s) kTLS enabled\n", sock_to_string(s));
306 static int sockmap_init_sockets(int verbose)
309 struct sockaddr_in addr;
310 int *fds[4] = {&s1, &s2, &c1, &c2};
312 s1 = s2 = p1 = p2 = c1 = c2 = 0;
315 for (i = 0; i < 4; i++) {
316 *fds[i] = socket(AF_INET, SOCK_STREAM, 0);
318 perror("socket s1 failed()");
324 for (i = 0; i < 2; i++) {
325 err = setsockopt(*fds[i], SOL_SOCKET, SO_REUSEADDR,
326 (char *)&one, sizeof(one));
328 perror("setsockopt failed()");
333 /* Non-blocking sockets */
334 for (i = 0; i < 2; i++) {
335 err = ioctl(*fds[i], FIONBIO, (char *)&one);
337 perror("ioctl s1 failed()");
342 /* Bind server sockets */
343 memset(&addr, 0, sizeof(struct sockaddr_in));
344 addr.sin_family = AF_INET;
345 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
347 addr.sin_port = htons(S1_PORT);
348 err = bind(s1, (struct sockaddr *)&addr, sizeof(addr));
350 perror("bind s1 failed()");
354 addr.sin_port = htons(S2_PORT);
355 err = bind(s2, (struct sockaddr *)&addr, sizeof(addr));
357 perror("bind s2 failed()");
361 /* Listen server sockets */
362 addr.sin_port = htons(S1_PORT);
363 err = listen(s1, 32);
365 perror("listen s1 failed()");
369 addr.sin_port = htons(S2_PORT);
370 err = listen(s2, 32);
372 perror("listen s1 failed()");
376 /* Initiate Connect */
377 addr.sin_port = htons(S1_PORT);
378 err = connect(c1, (struct sockaddr *)&addr, sizeof(addr));
379 if (err < 0 && errno != EINPROGRESS) {
380 perror("connect c1 failed()");
384 addr.sin_port = htons(S2_PORT);
385 err = connect(c2, (struct sockaddr *)&addr, sizeof(addr));
386 if (err < 0 && errno != EINPROGRESS) {
387 perror("connect c2 failed()");
389 } else if (err < 0) {
393 /* Accept Connecrtions */
394 p1 = accept(s1, NULL, NULL);
396 perror("accept s1 failed()");
400 p2 = accept(s2, NULL, NULL);
402 perror("accept s1 failed()");
407 printf("connected sockets: c1 <-> p1, c2 <-> p2\n");
408 printf("cgroups binding: c1(%i) <-> s1(%i) - - - c2(%i) <-> s2(%i)\n",
417 struct timespec start;
421 static int msg_loop_sendpage(int fd, int iov_length, int cnt,
423 struct sockmap_options *opt)
425 bool drop = opt->drop_expected;
432 perror("create file for sendpage");
435 for (i = 0; i < cnt; i++, k = 0) {
436 for (j = 0; j < iov_length; j++, k++)
437 fwrite(&k, sizeof(char), 1, file);
440 fseek(file, 0, SEEK_SET);
444 clock_gettime(CLOCK_MONOTONIC, &s->start);
445 for (i = 0; i < cnt; i++) {
449 sent = sendfile(fd, fp, NULL, iov_length);
451 if (!drop && sent < 0) {
452 perror("sendpage loop error");
455 } else if (drop && sent >= 0) {
456 printf("sendpage loop error expected: %i errno %i\n",
463 s->bytes_sent += sent;
465 clock_gettime(CLOCK_MONOTONIC, &s->end);
470 static void msg_free_iov(struct msghdr *msg)
474 for (i = 0; i < msg->msg_iovlen; i++)
475 free(msg->msg_iov[i].iov_base);
481 static int msg_alloc_iov(struct msghdr *msg,
482 int iov_count, int iov_length,
483 bool data, bool xmit)
489 iov = calloc(iov_count, sizeof(struct iovec));
493 for (i = 0; i < iov_count; i++) {
494 unsigned char *d = calloc(iov_length, sizeof(char));
497 fprintf(stderr, "iov_count %i/%i OOM\n", i, iov_count);
501 iov[i].iov_len = iov_length;
506 for (j = 0; j < iov_length; j++)
512 msg->msg_iovlen = iov_count;
516 for (i--; i >= 0 ; i--)
517 free(msg->msg_iov[i].iov_base);
521 /* In push or pop test, we need to do some calculations for msg_verify_data */
522 static void msg_verify_date_prep(void)
524 int push_range_end = txmsg_start_push + txmsg_end_push - 1;
525 int pop_range_end = txmsg_start_pop + txmsg_pop - 1;
527 if (txmsg_end_push && txmsg_pop &&
528 txmsg_start_push <= pop_range_end && txmsg_start_pop <= push_range_end) {
529 /* The push range and the pop range overlap */
532 verify_push_start = txmsg_start_push;
533 verify_pop_start = txmsg_start_pop;
534 if (txmsg_start_push < txmsg_start_pop)
535 overlap_len = min(push_range_end - txmsg_start_pop + 1, txmsg_pop);
537 overlap_len = min(pop_range_end - txmsg_start_push + 1, txmsg_end_push);
538 verify_push_len = max(txmsg_end_push - overlap_len, 0);
539 verify_pop_len = max(txmsg_pop - overlap_len, 0);
542 verify_push_start = txmsg_start_push;
543 verify_pop_start = txmsg_start_pop;
544 verify_push_len = txmsg_end_push;
545 verify_pop_len = txmsg_pop;
549 static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz,
550 unsigned char *k_p, int *bytes_cnt_p,
551 int *check_cnt_p, int *push_p)
553 int bytes_cnt = *bytes_cnt_p, check_cnt = *check_cnt_p, push = *push_p;
554 unsigned char k = *k_p;
557 for (i = 0, j = 0; i < msg->msg_iovlen && size; i++, j = 0) {
558 unsigned char *d = msg->msg_iov[i].iov_base;
560 /* Special case test for skb ingress + ktls */
561 if (i == 0 && txmsg_ktls_skb) {
562 if (msg->msg_iov[i].iov_len < 4)
563 return -EDATAINTEGRITY;
564 if (memcmp(d, "PASS", 4) != 0) {
566 "detected skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n",
567 i, 0, d[0], d[1], d[2], d[3]);
568 return -EDATAINTEGRITY;
570 j = 4; /* advance index past PASS header */
573 for (; j < msg->msg_iov[i].iov_len && size; j++) {
575 check_cnt == verify_push_start + verify_push_len - push) {
579 if (j + push >= msg->msg_iov[i].iov_len)
580 skipped = msg->msg_iov[i].iov_len - j;
584 check_cnt += skipped;
588 if (verify_pop_len > 0 && check_cnt == verify_pop_start) {
589 bytes_cnt += verify_pop_len;
590 check_cnt += verify_pop_len;
593 if (bytes_cnt == chunk_sz) {
597 push = verify_push_len;
601 check_cnt == verify_push_start + verify_push_len - push)
607 "detected data corruption @iov[%i]:%i %02x != %02x, %02x ?= %02x\n",
608 i, j, d[j], k - 1, d[j+1], k);
609 return -EDATAINTEGRITY;
613 if (bytes_cnt == chunk_sz) {
617 push = verify_push_len;
623 *bytes_cnt_p = bytes_cnt;
624 *check_cnt_p = check_cnt;
629 static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
630 struct msg_stats *s, bool tx,
631 struct sockmap_options *opt)
633 struct msghdr msg = {0}, msg_peek = {0};
634 int err, i, flags = MSG_NOSIGNAL;
635 bool drop = opt->drop_expected;
636 bool data = opt->data_test;
637 int iov_alloc_length = iov_length;
639 if (!tx && opt->check_recved_len)
640 iov_alloc_length *= 2;
642 err = msg_alloc_iov(&msg, iov_count, iov_alloc_length, data, tx);
646 err = msg_alloc_iov(&msg_peek, iov_count, iov_length, data, tx);
652 clock_gettime(CLOCK_MONOTONIC, &s->start);
653 for (i = 0; i < cnt; i++) {
657 sent = sendmsg(fd, &msg, flags);
659 if (!drop && sent < 0) {
660 if (opt->tx_wait_mem && errno == EACCES) {
664 perror("sendmsg loop error");
666 } else if (drop && sent >= 0) {
668 "sendmsg loop error expected: %i errno %i\n",
674 s->bytes_sent += sent;
676 clock_gettime(CLOCK_MONOTONIC, &s->end);
678 float total_bytes, txmsg_pop_total, txmsg_push_total;
679 int slct, recvp = 0, recv, max_fd = fd;
680 int fd_flags = O_NONBLOCK;
681 struct timeval timeout;
689 /* Account for pop bytes noting each iteration of apply will
690 * call msg_pop_data helper so we need to account for this
691 * by calculating the number of apply iterations. Note user
692 * of the tool can create cases where no data is sent by
693 * manipulating pop/push/pull/etc. For example txmsg_apply 1
694 * with txmsg_pop 1 will try to apply 1B at a time but each
695 * iteration will then pop 1B so no data will ever be sent.
696 * This is really only useful for testing edge cases in code
699 total_bytes = (float)iov_length * (float)cnt;
701 total_bytes *= (float)iov_count;
703 txmsg_push_total = txmsg_end_push * (total_bytes / txmsg_apply);
704 txmsg_pop_total = txmsg_pop * (total_bytes / txmsg_apply);
706 txmsg_push_total = txmsg_end_push * cnt;
707 txmsg_pop_total = txmsg_pop * cnt;
709 total_bytes += txmsg_push_total;
710 total_bytes -= txmsg_pop_total;
712 msg_verify_date_prep();
713 push = verify_push_len;
715 err = clock_gettime(CLOCK_MONOTONIC, &s->start);
717 perror("recv start time");
718 while (s->bytes_recvd < total_bytes) {
721 timeout.tv_usec = 300000;
731 slct = select(max_fd + 1, &w, NULL, NULL, &timeout);
734 clock_gettime(CLOCK_MONOTONIC, &s->end);
738 fprintf(stderr, "unexpected timeout: recved %zu/%f pop_total %f\n", s->bytes_recvd, total_bytes, txmsg_pop_total);
740 clock_gettime(CLOCK_MONOTONIC, &s->end);
744 if (opt->tx_wait_mem) {
747 slct = select(max_fd + 1, NULL, NULL, &w, &timeout);
756 recvp = recvmsg(fd, &msg_peek, flags);
758 if (errno != EWOULDBLOCK) {
759 clock_gettime(CLOCK_MONOTONIC, &s->end);
766 recv = recvmsg(fd, &msg, flags);
768 if (errno != EWOULDBLOCK) {
769 clock_gettime(CLOCK_MONOTONIC, &s->end);
770 perror("recv failed()");
776 s->bytes_recvd += recv;
778 if (opt->check_recved_len && s->bytes_recvd > total_bytes) {
780 fprintf(stderr, "recv failed(), bytes_recvd:%zd, total_bytes:%f\n",
781 s->bytes_recvd, total_bytes);
786 int chunk_sz = opt->sendpage ?
788 iov_length * iov_count;
790 errno = msg_verify_data(&msg, recv, chunk_sz, &k, &bytes_cnt,
793 perror("data verify msg failed");
797 errno = msg_verify_data(&msg_peek,
805 perror("data verify msg_peek failed");
811 clock_gettime(CLOCK_MONOTONIC, &s->end);
815 msg_free_iov(&msg_peek);
819 msg_free_iov(&msg_peek);
823 static float giga = 1000000000;
825 static inline float sentBps(struct msg_stats s)
827 return s.bytes_sent / (s.end.tv_sec - s.start.tv_sec);
830 static inline float recvdBps(struct msg_stats s)
832 return s.bytes_recvd / (s.end.tv_sec - s.start.tv_sec);
835 static int sendmsg_test(struct sockmap_options *opt)
837 float sent_Bps = 0, recvd_Bps = 0;
838 int rx_fd, txpid, rxpid, err = 0;
839 struct msg_stats s = {0};
840 int iov_count = opt->iov_count;
841 int iov_buf = opt->iov_length;
842 int rx_status, tx_status;
853 /* Redirecting into non-TLS socket which sends into a TLS
854 * socket is not a valid test. So in this case lets not
855 * enable kTLS but still run the test.
857 if (!txmsg_redir || txmsg_ingress) {
858 err = sockmap_init_ktls(opt->verbose, rx_fd);
862 err = sockmap_init_ktls(opt->verbose, c1);
867 if (opt->tx_wait_mem) {
868 struct timeval timeout;
869 int rxtx_buf_len = 1024;
874 err = setsockopt(c2, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval));
875 err |= setsockopt(c2, SOL_SOCKET, SO_SNDBUFFORCE, &rxtx_buf_len, sizeof(int));
876 err |= setsockopt(p2, SOL_SOCKET, SO_RCVBUFFORCE, &rxtx_buf_len, sizeof(int));
878 perror("setsockopt failed()");
885 if (opt->drop_expected || txmsg_ktls_skb_drop)
888 if (!iov_buf) /* zero bytes sent case */
893 err = msg_loop(rx_fd, iov_count, iov_buf,
894 cnt, &s, false, opt);
895 if (opt->verbose > 1)
897 "msg_loop_rx: iov_count %i iov_buf %i cnt %i err %i\n",
898 iov_count, iov_buf, cnt, err);
899 if (s.end.tv_sec - s.start.tv_sec) {
900 sent_Bps = sentBps(s);
901 recvd_Bps = recvdBps(s);
903 if (opt->verbose > 1)
905 "rx_sendmsg: TX: %zuB %fB/s %fGB/s RX: %zuB %fB/s %fGB/s %s\n",
906 s.bytes_sent, sent_Bps, sent_Bps/giga,
907 s.bytes_recvd, recvd_Bps, recvd_Bps/giga,
908 peek_flag ? "(peek_msg)" : "");
909 if (err && err != -EDATAINTEGRITY && txmsg_cork)
912 } else if (rxpid == -1) {
913 perror("msg_loop_rx");
917 if (opt->tx_wait_mem)
923 err = msg_loop_sendpage(c1, iov_buf, cnt, &s, opt);
925 err = msg_loop(c1, iov_count, iov_buf,
930 "msg_loop_tx: iov_count %i iov_buf %i cnt %i err %i\n",
931 iov_count, iov_buf, cnt, err);
932 if (s.end.tv_sec - s.start.tv_sec) {
933 sent_Bps = sentBps(s);
934 recvd_Bps = recvdBps(s);
936 if (opt->verbose > 1)
938 "tx_sendmsg: TX: %zuB %fB/s %f GB/s RX: %zuB %fB/s %fGB/s\n",
939 s.bytes_sent, sent_Bps, sent_Bps/giga,
940 s.bytes_recvd, recvd_Bps, recvd_Bps/giga);
942 } else if (txpid == -1) {
943 perror("msg_loop_tx");
947 assert(waitpid(rxpid, &rx_status, 0) == rxpid);
948 assert(waitpid(txpid, &tx_status, 0) == txpid);
949 if (WIFEXITED(rx_status)) {
950 err = WEXITSTATUS(rx_status);
952 fprintf(stderr, "rx thread exited with err %d.\n", err);
956 if (WIFEXITED(tx_status)) {
957 err = WEXITSTATUS(tx_status);
959 fprintf(stderr, "tx thread exited with err %d.\n", err);
965 static int forever_ping_pong(int rate, struct sockmap_options *opt)
967 struct timeval timeout;
968 char buf[1024] = {0};
974 /* Ping/Pong data from client to server */
975 sc = send(c1, buf, sizeof(buf), 0);
977 perror("send failed()");
982 int s, rc, i, max_fd = p2;
992 s = select(max_fd + 1, &w, NULL, NULL, &timeout);
997 fprintf(stderr, "unexpected timeout\n");
1001 for (i = 0; i <= max_fd && s > 0; ++i) {
1002 if (!FD_ISSET(i, &w))
1007 rc = recv(i, buf, sizeof(buf), 0);
1009 if (errno != EWOULDBLOCK) {
1010 perror("recv failed()");
1020 sc = send(i, buf, rc, 0);
1022 perror("send failed()");
1049 static int run_options(struct sockmap_options *options, int cg_fd, int test)
1051 int i, key, next_key, err, zero = 0;
1052 struct bpf_program *tx_prog;
1054 /* If base test skip BPF setup */
1055 if (test == BASE || test == BASE_SENDPAGE)
1058 /* Attach programs to sockmap */
1059 if (!txmsg_omit_skb_parser) {
1060 links[0] = bpf_program__attach_sockmap(progs[0], map_fd[0]);
1063 "ERROR: bpf_program__attach_sockmap (sockmap %i->%i): (%s)\n",
1064 bpf_program__fd(progs[0]), map_fd[0], strerror(errno));
1069 links[1] = bpf_program__attach_sockmap(progs[1], map_fd[0]);
1071 fprintf(stderr, "ERROR: bpf_program__attach_sockmap (sockmap): (%s)\n",
1076 /* Attach programs to TLS sockmap */
1077 if (txmsg_ktls_skb) {
1078 if (!txmsg_omit_skb_parser) {
1079 links[2] = bpf_program__attach_sockmap(progs[0], map_fd[8]);
1082 "ERROR: bpf_program__attach_sockmap (TLS sockmap %i->%i): (%s)\n",
1083 bpf_program__fd(progs[0]), map_fd[8], strerror(errno));
1088 links[3] = bpf_program__attach_sockmap(progs[2], map_fd[8]);
1090 fprintf(stderr, "ERROR: bpf_program__attach_sockmap (TLS sockmap): (%s)\n",
1096 /* Attach to cgroups */
1097 err = bpf_prog_attach(bpf_program__fd(progs[3]), cg_fd, BPF_CGROUP_SOCK_OPS, 0);
1099 fprintf(stderr, "ERROR: bpf_prog_attach (groups): %d (%s)\n",
1100 err, strerror(errno));
1105 err = sockmap_init_sockets(options->verbose);
1107 fprintf(stderr, "ERROR: test socket failed: %d\n", err);
1111 /* Attach txmsg program to sockmap */
1114 else if (txmsg_redir)
1116 else if (txmsg_apply)
1118 else if (txmsg_cork)
1120 else if (txmsg_drop)
1128 links[4] = bpf_program__attach_sockmap(tx_prog, map_fd[1]);
1131 "ERROR: bpf_program__attach_sockmap (txmsg): (%s)\n",
1138 err = bpf_map_update_elem(map_fd[1], &i, &c1, BPF_ANY);
1141 "ERROR: bpf_map_update_elem (txmsg): %d (%s\n",
1142 err, strerror(errno));
1151 err = bpf_map_update_elem(map_fd[2], &i, &redir_fd, BPF_ANY);
1154 "ERROR: bpf_map_update_elem (txmsg): %d (%s\n",
1155 err, strerror(errno));
1160 err = bpf_map_update_elem(map_fd[3],
1161 &i, &txmsg_apply, BPF_ANY);
1164 "ERROR: bpf_map_update_elem (apply_bytes): %d (%s\n",
1165 err, strerror(errno));
1171 err = bpf_map_update_elem(map_fd[4],
1172 &i, &txmsg_cork, BPF_ANY);
1175 "ERROR: bpf_map_update_elem (cork_bytes): %d (%s\n",
1176 err, strerror(errno));
1182 err = bpf_map_update_elem(map_fd[5],
1183 &i, &txmsg_start, BPF_ANY);
1186 "ERROR: bpf_map_update_elem (txmsg_start): %d (%s)\n",
1187 err, strerror(errno));
1194 err = bpf_map_update_elem(map_fd[5],
1195 &i, &txmsg_end, BPF_ANY);
1198 "ERROR: bpf_map_update_elem (txmsg_end): %d (%s)\n",
1199 err, strerror(errno));
1204 if (txmsg_start_push) {
1206 err = bpf_map_update_elem(map_fd[5],
1207 &i, &txmsg_start_push, BPF_ANY);
1210 "ERROR: bpf_map_update_elem (txmsg_start_push): %d (%s)\n",
1211 err, strerror(errno));
1216 if (txmsg_end_push) {
1218 err = bpf_map_update_elem(map_fd[5],
1219 &i, &txmsg_end_push, BPF_ANY);
1222 "ERROR: bpf_map_update_elem %i@%i (txmsg_end_push): %d (%s)\n",
1223 txmsg_end_push, i, err, strerror(errno));
1228 if (txmsg_start_pop) {
1230 err = bpf_map_update_elem(map_fd[5],
1231 &i, &txmsg_start_pop, BPF_ANY);
1234 "ERROR: bpf_map_update_elem %i@%i (txmsg_start_pop): %d (%s)\n",
1235 txmsg_start_pop, i, err, strerror(errno));
1240 bpf_map_update_elem(map_fd[5],
1241 &i, &txmsg_start_pop, BPF_ANY);
1246 err = bpf_map_update_elem(map_fd[5],
1247 &i, &txmsg_pop, BPF_ANY);
1250 "ERROR: bpf_map_update_elem %i@%i (txmsg_pop): %d (%s)\n",
1251 txmsg_pop, i, err, strerror(errno));
1256 bpf_map_update_elem(map_fd[5],
1257 &i, &txmsg_pop, BPF_ANY);
1261 if (txmsg_ingress) {
1262 int in = BPF_F_INGRESS;
1265 err = bpf_map_update_elem(map_fd[6], &i, &in, BPF_ANY);
1268 "ERROR: bpf_map_update_elem (txmsg_ingress): %d (%s)\n",
1269 err, strerror(errno));
1272 err = bpf_map_update_elem(map_fd[1], &i, &p1, BPF_ANY);
1275 "ERROR: bpf_map_update_elem (p1 txmsg): %d (%s)\n",
1276 err, strerror(errno));
1278 err = bpf_map_update_elem(map_fd[2], &i, &p1, BPF_ANY);
1281 "ERROR: bpf_map_update_elem (p1 redir): %d (%s)\n",
1282 err, strerror(errno));
1286 err = bpf_map_update_elem(map_fd[2], &i, &p2, BPF_ANY);
1289 "ERROR: bpf_map_update_elem (p2 txmsg): %d (%s)\n",
1290 err, strerror(errno));
1294 if (txmsg_ktls_skb) {
1295 int ingress = BPF_F_INGRESS;
1298 err = bpf_map_update_elem(map_fd[8], &i, &p2, BPF_ANY);
1301 "ERROR: bpf_map_update_elem (c1 sockmap): %d (%s)\n",
1302 err, strerror(errno));
1305 if (txmsg_ktls_skb_redir) {
1307 err = bpf_map_update_elem(map_fd[7],
1308 &i, &ingress, BPF_ANY);
1311 "ERROR: bpf_map_update_elem (txmsg_ingress): %d (%s)\n",
1312 err, strerror(errno));
1316 if (txmsg_ktls_skb_drop) {
1318 err = bpf_map_update_elem(map_fd[7], &i, &i, BPF_ANY);
1322 if (txmsg_redir_skb) {
1323 int skb_fd = (test == SENDMSG || test == SENDPAGE) ?
1325 int ingress = BPF_F_INGRESS;
1328 err = bpf_map_update_elem(map_fd[7],
1329 &i, &ingress, BPF_ANY);
1332 "ERROR: bpf_map_update_elem (txmsg_ingress): %d (%s)\n",
1333 err, strerror(errno));
1337 err = bpf_map_update_elem(map_fd[0], &i, &skb_fd, BPF_ANY);
1340 "ERROR: bpf_map_update_elem (c1 sockmap): %d (%s)\n",
1341 err, strerror(errno));
1346 if (skb_use_parser) {
1348 err = bpf_map_update_elem(map_fd[7], &i, &skb_use_parser, BPF_ANY);
1352 options->drop_expected = true;
1354 if (test == PING_PONG)
1355 err = forever_ping_pong(options->rate, options);
1356 else if (test == SENDMSG) {
1357 options->base = false;
1358 options->sendpage = false;
1359 err = sendmsg_test(options);
1360 } else if (test == SENDPAGE) {
1361 options->base = false;
1362 options->sendpage = true;
1363 err = sendmsg_test(options);
1364 } else if (test == BASE) {
1365 options->base = true;
1366 options->sendpage = false;
1367 err = sendmsg_test(options);
1368 } else if (test == BASE_SENDPAGE) {
1369 options->base = true;
1370 options->sendpage = true;
1371 err = sendmsg_test(options);
1373 fprintf(stderr, "unknown test\n");
1375 /* Detatch and zero all the maps */
1376 bpf_prog_detach2(bpf_program__fd(progs[3]), cg_fd, BPF_CGROUP_SOCK_OPS);
1378 for (i = 0; i < ARRAY_SIZE(links); i++) {
1380 bpf_link__detach(links[i]);
1383 for (i = 0; i < ARRAY_SIZE(map_fd); i++) {
1385 bpf_map_update_elem(map_fd[i], &key, &zero, BPF_ANY);
1386 while (bpf_map_get_next_key(map_fd[i], &key, &next_key) == 0) {
1387 bpf_map_update_elem(map_fd[i], &key, &zero, BPF_ANY);
1401 static char *test_to_str(int test)
1412 static void append_str(char *dst, const char *src, size_t dst_cap)
1414 size_t avail = dst_cap - strlen(dst);
1416 if (avail <= 1) /* just zero byte could be written */
1419 strncat(dst, src, avail - 1); /* strncat() adds + 1 for zero byte */
1422 #define OPTSTRING 60
1423 static void test_options(char *options)
1425 char tstr[OPTSTRING];
1427 memset(options, 0, OPTSTRING);
1430 append_str(options, "pass,", OPTSTRING);
1432 append_str(options, "redir,", OPTSTRING);
1434 append_str(options, "drop,", OPTSTRING);
1436 snprintf(tstr, OPTSTRING, "apply %d,", txmsg_apply);
1437 append_str(options, tstr, OPTSTRING);
1440 snprintf(tstr, OPTSTRING, "cork %d,", txmsg_cork);
1441 append_str(options, tstr, OPTSTRING);
1444 snprintf(tstr, OPTSTRING, "start %d,", txmsg_start);
1445 append_str(options, tstr, OPTSTRING);
1448 snprintf(tstr, OPTSTRING, "end %d,", txmsg_end);
1449 append_str(options, tstr, OPTSTRING);
1451 if (txmsg_start_pop) {
1452 snprintf(tstr, OPTSTRING, "pop (%d,%d),",
1453 txmsg_start_pop, txmsg_start_pop + txmsg_pop);
1454 append_str(options, tstr, OPTSTRING);
1457 append_str(options, "ingress,", OPTSTRING);
1458 if (txmsg_redir_skb)
1459 append_str(options, "redir_skb,", OPTSTRING);
1461 append_str(options, "ktls_skb,", OPTSTRING);
1463 append_str(options, "ktls,", OPTSTRING);
1465 append_str(options, "peek,", OPTSTRING);
1468 static int __test_exec(int cgrp, int test, struct sockmap_options *opt)
1470 char *options = calloc(OPTSTRING, sizeof(char));
1473 if (test == SENDPAGE)
1474 opt->sendpage = true;
1476 opt->sendpage = false;
1479 opt->drop_expected = true;
1481 opt->drop_expected = false;
1483 test_options(options);
1487 " [TEST %i]: (%i, %i, %i, %s, %s): ",
1488 test_cnt, opt->rate, opt->iov_count, opt->iov_length,
1489 test_to_str(test), options);
1492 err = run_options(opt, cgrp, test);
1494 fprintf(stdout, " %s\n", !err ? "PASS" : "FAILED");
1496 !err ? passed++ : failed++;
1501 static void test_exec(int cgrp, struct sockmap_options *opt)
1503 int type = strcmp(opt->map, BPF_SOCKMAP_FILENAME);
1508 err = __test_exec(cgrp, SENDMSG, opt);
1513 err = __test_exec(cgrp, SENDPAGE, opt);
1519 static void test_send_one(struct sockmap_options *opt, int cgrp)
1521 opt->iov_length = 1;
1524 test_exec(cgrp, opt);
1526 opt->iov_length = 1;
1527 opt->iov_count = 1024;
1529 test_exec(cgrp, opt);
1531 opt->iov_length = 1024;
1534 test_exec(cgrp, opt);
1538 static void test_send_many(struct sockmap_options *opt, int cgrp)
1540 opt->iov_length = 3;
1543 test_exec(cgrp, opt);
1547 opt->iov_length = 5;
1548 test_exec(cgrp, opt);
1551 static void test_send_large(struct sockmap_options *opt, int cgrp)
1553 opt->iov_length = 8192;
1554 opt->iov_count = 32;
1556 test_exec(cgrp, opt);
1559 static void test_send(struct sockmap_options *opt, int cgrp)
1561 test_send_one(opt, cgrp);
1562 test_send_many(opt, cgrp);
1563 test_send_large(opt, cgrp);
1567 static void test_txmsg_pass(int cgrp, struct sockmap_options *opt)
1569 /* Test small and large iov_count values with pass/redir/apply/cork */
1571 test_send(opt, cgrp);
1574 static void test_txmsg_redir(int cgrp, struct sockmap_options *opt)
1577 test_send(opt, cgrp);
1580 static void test_txmsg_redir_wait_sndmem(int cgrp, struct sockmap_options *opt)
1582 opt->tx_wait_mem = true;
1584 test_send_large(opt, cgrp);
1588 test_send_large(opt, cgrp);
1589 opt->tx_wait_mem = false;
1592 static void test_txmsg_drop(int cgrp, struct sockmap_options *opt)
1595 test_send(opt, cgrp);
1598 static void test_txmsg_ingress_redir(int cgrp, struct sockmap_options *opt)
1600 txmsg_pass = txmsg_drop = 0;
1601 txmsg_ingress = txmsg_redir = 1;
1602 test_send(opt, cgrp);
1605 static void test_txmsg_skb(int cgrp, struct sockmap_options *opt)
1607 bool data = opt->data_test;
1610 opt->data_test = true;
1613 txmsg_pass = txmsg_drop = 0;
1614 txmsg_ingress = txmsg_redir = 0;
1618 /* Using data verification so ensure iov layout is
1619 * expected from test receiver side. e.g. has enough
1620 * bytes to write test code.
1622 opt->iov_length = 100;
1625 test_exec(cgrp, opt);
1627 txmsg_ktls_skb_drop = 1;
1628 test_exec(cgrp, opt);
1630 txmsg_ktls_skb_drop = 0;
1631 txmsg_ktls_skb_redir = 1;
1632 test_exec(cgrp, opt);
1633 txmsg_ktls_skb_redir = 0;
1635 /* Tests that omit skb_parser */
1636 txmsg_omit_skb_parser = 1;
1639 test_exec(cgrp, opt);
1641 txmsg_ktls_skb_drop = 1;
1642 test_exec(cgrp, opt);
1643 txmsg_ktls_skb_drop = 0;
1645 txmsg_ktls_skb_redir = 1;
1646 test_exec(cgrp, opt);
1649 test_exec(cgrp, opt);
1650 txmsg_omit_skb_parser = 0;
1652 opt->data_test = data;
1656 /* Test cork with hung data. This tests poor usage patterns where
1657 * cork can leave data on the ring if user program is buggy and
1658 * doesn't flush them somehow. They do take some time however
1659 * because they wait for a timeout. Test pass, redir and cork with
1660 * apply logic. Use cork size of 4097 with send_large to avoid
1661 * aligning cork size with send size.
1663 static void test_txmsg_cork_hangs(int cgrp, struct sockmap_options *opt)
1669 test_send_large(opt, cgrp);
1675 test_send_large(opt, cgrp);
1681 test_send_large(opt, cgrp);
1684 static void test_txmsg_pull(int cgrp, struct sockmap_options *opt)
1686 /* Test basic start/end */
1690 test_send(opt, cgrp);
1696 test_send_large(opt, cgrp);
1698 /* Test pull + redirect */
1702 test_send(opt, cgrp);
1704 /* Test pull + cork */
1709 test_send_many(opt, cgrp);
1711 /* Test pull + cork + redirect */
1716 test_send_many(opt, cgrp);
1719 static void test_txmsg_pop(int cgrp, struct sockmap_options *opt)
1721 bool data = opt->data_test;
1723 /* Test basic pop */
1725 txmsg_start_pop = 1;
1727 test_send_many(opt, cgrp);
1729 /* Test pop with >4k */
1731 txmsg_start_pop = 4096;
1733 test_send_large(opt, cgrp);
1735 /* Test pop + redirect */
1737 txmsg_start_pop = 1;
1739 test_send_many(opt, cgrp);
1741 /* TODO: Test for pop + cork should be different,
1742 * - It makes the layout of the received data difficult
1743 * - It makes it hard to calculate the total_bytes in the recvmsg
1744 * Temporarily skip the data integrity test for this case now.
1746 opt->data_test = false;
1747 /* Test pop + cork */
1750 txmsg_start_pop = 1;
1752 test_send_many(opt, cgrp);
1754 /* Test pop + redirect + cork */
1757 txmsg_start_pop = 1;
1759 test_send_many(opt, cgrp);
1760 opt->data_test = data;
1763 static void test_txmsg_push(int cgrp, struct sockmap_options *opt)
1765 bool data = opt->data_test;
1767 /* Test basic push */
1769 txmsg_start_push = 1;
1771 test_send(opt, cgrp);
1773 /* Test push 4kB >4k */
1775 txmsg_start_push = 4096;
1776 txmsg_end_push = 4096;
1777 test_send_large(opt, cgrp);
1779 /* Test push + redirect */
1781 txmsg_start_push = 1;
1783 test_send_many(opt, cgrp);
1785 /* TODO: Test for push + cork should be different,
1786 * - It makes the layout of the received data difficult
1787 * - It makes it hard to calculate the total_bytes in the recvmsg
1788 * Temporarily skip the data integrity test for this case now.
1790 opt->data_test = false;
1791 /* Test push + cork */
1794 txmsg_start_push = 1;
1796 test_send_many(opt, cgrp);
1797 opt->data_test = data;
1800 static void test_txmsg_push_pop(int cgrp, struct sockmap_options *opt)
1802 /* Test push/pop range overlapping */
1804 txmsg_start_push = 1;
1805 txmsg_end_push = 10;
1806 txmsg_start_pop = 5;
1808 test_send_large(opt, cgrp);
1811 txmsg_start_push = 1;
1812 txmsg_end_push = 10;
1813 txmsg_start_pop = 5;
1815 test_send_large(opt, cgrp);
1818 txmsg_start_push = 5;
1820 txmsg_start_pop = 1;
1822 test_send_large(opt, cgrp);
1825 txmsg_start_push = 5;
1826 txmsg_end_push = 16;
1827 txmsg_start_pop = 1;
1829 test_send_large(opt, cgrp);
1831 /* Test push/pop range non-overlapping */
1833 txmsg_start_push = 1;
1834 txmsg_end_push = 10;
1835 txmsg_start_pop = 16;
1837 test_send_large(opt, cgrp);
1840 txmsg_start_push = 16;
1841 txmsg_end_push = 10;
1842 txmsg_start_pop = 5;
1844 test_send_large(opt, cgrp);
1847 static void test_txmsg_apply(int cgrp, struct sockmap_options *opt)
1854 test_send_one(opt, cgrp);
1861 test_send_one(opt, cgrp);
1868 test_send_one(opt, cgrp);
1875 test_send_large(opt, cgrp);
1882 test_send_large(opt, cgrp);
1889 test_send_large(opt, cgrp);
1892 static void test_txmsg_cork(int cgrp, struct sockmap_options *opt)
1898 test_send(opt, cgrp);
1904 test_send(opt, cgrp);
1907 static void test_txmsg_ingress_parser(int cgrp, struct sockmap_options *opt)
1910 skb_use_parser = 512;
1912 skb_use_parser = 570;
1913 opt->iov_length = 256;
1916 test_exec(cgrp, opt);
1919 static void test_txmsg_ingress_parser2(int cgrp, struct sockmap_options *opt)
1923 skb_use_parser = 10;
1924 opt->iov_length = 20;
1927 opt->check_recved_len = true;
1928 test_exec(cgrp, opt);
1929 opt->check_recved_len = false;
1932 char *map_names[] = {
1944 static int populate_progs(char *bpf_file)
1946 struct bpf_program *prog;
1947 struct bpf_object *obj;
1951 obj = bpf_object__open(bpf_file);
1952 err = libbpf_get_error(obj);
1956 libbpf_strerror(err, err_buf, sizeof(err_buf));
1957 printf("Unable to load eBPF objects in file '%s' : %s\n",
1962 i = bpf_object__load(obj);
1964 bpf_object__for_each_program(prog, obj) {
1969 for (i = 0; i < ARRAY_SIZE(map_fd); i++) {
1970 maps[i] = bpf_object__find_map_by_name(obj, map_names[i]);
1971 map_fd[i] = bpf_map__fd(maps[i]);
1972 if (map_fd[i] < 0) {
1973 fprintf(stderr, "load_bpf_file: (%i) %s\n",
1974 map_fd[i], strerror(errno));
1979 for (i = 0; i < ARRAY_SIZE(links); i++)
1985 struct _test test[] = {
1986 {"txmsg test passthrough", test_txmsg_pass},
1987 {"txmsg test redirect", test_txmsg_redir},
1988 {"txmsg test redirect wait send mem", test_txmsg_redir_wait_sndmem},
1989 {"txmsg test drop", test_txmsg_drop},
1990 {"txmsg test ingress redirect", test_txmsg_ingress_redir},
1991 {"txmsg test skb", test_txmsg_skb},
1992 {"txmsg test apply", test_txmsg_apply},
1993 {"txmsg test cork", test_txmsg_cork},
1994 {"txmsg test hanging corks", test_txmsg_cork_hangs},
1995 {"txmsg test push_data", test_txmsg_push},
1996 {"txmsg test pull-data", test_txmsg_pull},
1997 {"txmsg test pop-data", test_txmsg_pop},
1998 {"txmsg test push/pop data", test_txmsg_push_pop},
1999 {"txmsg test ingress parser", test_txmsg_ingress_parser},
2000 {"txmsg test ingress parser2", test_txmsg_ingress_parser2},
2003 static int check_whitelist(struct _test *t, struct sockmap_options *opt)
2007 if (!opt->whitelist)
2009 ptr = strdup(opt->whitelist);
2012 entry = strtok(ptr, ",");
2014 if ((opt->prepend && strstr(opt->prepend, entry) != 0) ||
2015 strstr(opt->map, entry) != 0 ||
2016 strstr(t->title, entry) != 0) {
2020 entry = strtok(NULL, ",");
2026 static int check_blacklist(struct _test *t, struct sockmap_options *opt)
2030 if (!opt->blacklist)
2032 ptr = strdup(opt->blacklist);
2035 entry = strtok(ptr, ",");
2037 if ((opt->prepend && strstr(opt->prepend, entry) != 0) ||
2038 strstr(opt->map, entry) != 0 ||
2039 strstr(t->title, entry) != 0) {
2043 entry = strtok(NULL, ",");
2049 static int __test_selftests(int cg_fd, struct sockmap_options *opt)
2053 err = populate_progs(opt->map);
2055 fprintf(stderr, "ERROR: (%i) load bpf failed\n", err);
2059 /* Tests basic commands and APIs */
2060 for (i = 0; i < ARRAY_SIZE(test); i++) {
2061 struct _test t = test[i];
2063 if (check_whitelist(&t, opt) != 0)
2065 if (check_blacklist(&t, opt) == 0)
2068 test_start_subtest(&t, opt);
2069 t.tester(cg_fd, opt);
2076 static void test_selftests_sockmap(int cg_fd, struct sockmap_options *opt)
2078 opt->map = BPF_SOCKMAP_FILENAME;
2079 __test_selftests(cg_fd, opt);
2082 static void test_selftests_sockhash(int cg_fd, struct sockmap_options *opt)
2084 opt->map = BPF_SOCKHASH_FILENAME;
2085 __test_selftests(cg_fd, opt);
2088 static void test_selftests_ktls(int cg_fd, struct sockmap_options *opt)
2090 opt->map = BPF_SOCKHASH_FILENAME;
2091 opt->prepend = "ktls";
2093 __test_selftests(cg_fd, opt);
2097 static int test_selftest(int cg_fd, struct sockmap_options *opt)
2099 test_selftests_sockmap(cg_fd, opt);
2100 test_selftests_sockhash(cg_fd, opt);
2101 test_selftests_ktls(cg_fd, opt);
2102 test_print_results();
2106 int main(int argc, char **argv)
2108 int iov_count = 1, length = 1024, rate = 1;
2109 struct sockmap_options options = {0};
2110 int opt, longindex, err, cg_fd = 0;
2111 char *bpf_file = BPF_SOCKMAP_FILENAME;
2112 int test = SELFTESTS;
2113 bool cg_created = 0;
2115 while ((opt = getopt_long(argc, argv, ":dhv:c:r:i:l:t:p:q:n:b:",
2116 long_options, &longindex)) != -1) {
2119 txmsg_start = atoi(optarg);
2122 txmsg_end = atoi(optarg);
2125 txmsg_start_push = atoi(optarg);
2128 txmsg_end_push = atoi(optarg);
2131 txmsg_start_pop = atoi(optarg);
2134 txmsg_pop = atoi(optarg);
2137 txmsg_apply = atoi(optarg);
2140 txmsg_cork = atoi(optarg);
2143 cg_fd = open(optarg, O_DIRECTORY, O_RDONLY);
2146 "ERROR: (%i) open cg path failed: %s\n",
2152 rate = atoi(optarg);
2155 options.verbose = 1;
2157 options.verbose = atoi(optarg);
2160 iov_count = atoi(optarg);
2163 length = atoi(optarg);
2166 options.data_test = true;
2169 if (strcmp(optarg, "ping") == 0) {
2171 } else if (strcmp(optarg, "sendmsg") == 0) {
2173 } else if (strcmp(optarg, "base") == 0) {
2175 } else if (strcmp(optarg, "base_sendpage") == 0) {
2176 test = BASE_SENDPAGE;
2177 } else if (strcmp(optarg, "sendpage") == 0) {
2185 options.whitelist = strdup(optarg);
2186 if (!options.whitelist)
2190 options.blacklist = strdup(optarg);
2191 if (!options.blacklist)
2203 cg_fd = cgroup_setup_and_join(CG_PATH);
2209 /* Use libbpf 1.0 API mode */
2210 libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
2212 if (test == SELFTESTS) {
2213 err = test_selftest(cg_fd, &options);
2217 err = populate_progs(bpf_file);
2219 fprintf(stderr, "populate program: (%s) %s\n",
2220 bpf_file, strerror(errno));
2226 signal(SIGINT, running_handler);
2228 options.iov_count = iov_count;
2229 options.iov_length = length;
2230 options.rate = rate;
2232 err = run_options(&options, cg_fd, test);
2234 if (options.whitelist)
2235 free(options.whitelist);
2236 if (options.blacklist)
2237 free(options.blacklist);
2240 cleanup_cgroup_environment();
2244 void running_handler(int a)