psock_fanout.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2013 Google Inc.
  4. * Author: Willem de Bruijn (willemb@google.com)
  5. *
  6. * A basic test of packet socket fanout behavior.
  7. *
  8. * Control:
  9. * - create fanout fails as expected with illegal flag combinations
  10. * - join fanout fails as expected with diverging types or flags
  11. *
  12. * Datapath:
  13. * Open a pair of packet sockets and a pair of INET sockets, send a known
  14. * number of packets across the two INET sockets and count the number of
  15. * packets enqueued onto the two packet sockets.
  16. *
  17. * The test currently runs for
  18. * - PACKET_FANOUT_HASH
  19. * - PACKET_FANOUT_HASH with PACKET_FANOUT_FLAG_ROLLOVER
  20. * - PACKET_FANOUT_LB
  21. * - PACKET_FANOUT_CPU
  22. * - PACKET_FANOUT_ROLLOVER
  23. * - PACKET_FANOUT_CBPF
  24. * - PACKET_FANOUT_EBPF
  25. *
  26. * Todo:
  27. * - functionality: PACKET_FANOUT_FLAG_DEFRAG
  28. */
  29. #define _GNU_SOURCE /* for sched_setaffinity */
  30. #include <arpa/inet.h>
  31. #include <errno.h>
  32. #include <fcntl.h>
  33. #include <linux/unistd.h> /* for __NR_bpf */
  34. #include <linux/filter.h>
  35. #include <linux/bpf.h>
  36. #include <linux/if_packet.h>
  37. #include <net/if.h>
  38. #include <net/ethernet.h>
  39. #include <netinet/ip.h>
  40. #include <netinet/udp.h>
  41. #include <poll.h>
  42. #include <sched.h>
  43. #include <stdint.h>
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <sys/mman.h>
  48. #include <sys/socket.h>
  49. #include <sys/ioctl.h>
  50. #include <sys/stat.h>
  51. #include <sys/types.h>
  52. #include <unistd.h>
  53. #include "psock_lib.h"
  54. #include "kselftest.h"
  55. #define RING_NUM_FRAMES 20
  56. static uint32_t cfg_max_num_members;
  57. static void loopback_set_up_down(int state_up)
  58. {
  59. struct ifreq ifreq = {};
  60. int fd, err;
  61. fd = socket(AF_PACKET, SOCK_RAW, 0);
  62. if (fd < 0) {
  63. perror("socket loopback");
  64. exit(1);
  65. }
  66. strcpy(ifreq.ifr_name, "lo");
  67. err = ioctl(fd, SIOCGIFFLAGS, &ifreq);
  68. if (err) {
  69. perror("SIOCGIFFLAGS");
  70. exit(1);
  71. }
  72. if (state_up != !!(ifreq.ifr_flags & IFF_UP)) {
  73. ifreq.ifr_flags ^= IFF_UP;
  74. err = ioctl(fd, SIOCSIFFLAGS, &ifreq);
  75. if (err) {
  76. perror("SIOCSIFFLAGS");
  77. exit(1);
  78. }
  79. }
  80. close(fd);
  81. }
  82. /* Open a socket in a given fanout mode.
  83. * @return -1 if mode is bad, a valid socket otherwise */
  84. static int sock_fanout_open(uint16_t typeflags, uint16_t group_id)
  85. {
  86. struct sockaddr_ll addr = {0};
  87. struct fanout_args args;
  88. int fd, val, err;
  89. fd = socket(PF_PACKET, SOCK_RAW, 0);
  90. if (fd < 0) {
  91. perror("socket packet");
  92. exit(1);
  93. }
  94. pair_udp_setfilter(fd);
  95. addr.sll_family = AF_PACKET;
  96. addr.sll_protocol = htons(ETH_P_IP);
  97. addr.sll_ifindex = if_nametoindex("lo");
  98. if (addr.sll_ifindex == 0) {
  99. perror("if_nametoindex");
  100. exit(1);
  101. }
  102. if (bind(fd, (void *) &addr, sizeof(addr))) {
  103. perror("bind packet");
  104. exit(1);
  105. }
  106. if (cfg_max_num_members) {
  107. args.id = group_id;
  108. args.type_flags = typeflags;
  109. args.max_num_members = cfg_max_num_members;
  110. err = setsockopt(fd, SOL_PACKET, PACKET_FANOUT, &args,
  111. sizeof(args));
  112. } else {
  113. val = (((int) typeflags) << 16) | group_id;
  114. err = setsockopt(fd, SOL_PACKET, PACKET_FANOUT, &val,
  115. sizeof(val));
  116. }
  117. if (err) {
  118. if (close(fd)) {
  119. perror("close packet");
  120. exit(1);
  121. }
  122. return -1;
  123. }
  124. return fd;
  125. }
  126. static void sock_fanout_set_cbpf(int fd)
  127. {
  128. struct sock_filter bpf_filter[] = {
  129. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 80), /* ldb [80] */
  130. BPF_STMT(BPF_RET | BPF_A, 0), /* ret A */
  131. };
  132. struct sock_fprog bpf_prog;
  133. bpf_prog.filter = bpf_filter;
  134. bpf_prog.len = ARRAY_SIZE(bpf_filter);
  135. if (setsockopt(fd, SOL_PACKET, PACKET_FANOUT_DATA, &bpf_prog,
  136. sizeof(bpf_prog))) {
  137. perror("fanout data cbpf");
  138. exit(1);
  139. }
  140. }
  141. static void sock_fanout_getopts(int fd, uint16_t *typeflags, uint16_t *group_id)
  142. {
  143. int sockopt;
  144. socklen_t sockopt_len = sizeof(sockopt);
  145. if (getsockopt(fd, SOL_PACKET, PACKET_FANOUT,
  146. &sockopt, &sockopt_len)) {
  147. perror("failed to getsockopt");
  148. exit(1);
  149. }
  150. *typeflags = sockopt >> 16;
  151. *group_id = sockopt & 0xfffff;
  152. }
  153. static void sock_fanout_set_ebpf(int fd)
  154. {
  155. static char log_buf[65536];
  156. const int len_off = __builtin_offsetof(struct __sk_buff, len);
  157. struct bpf_insn prog[] = {
  158. { BPF_ALU64 | BPF_MOV | BPF_X, 6, 1, 0, 0 },
  159. { BPF_LDX | BPF_W | BPF_MEM, 0, 6, len_off, 0 },
  160. { BPF_JMP | BPF_JGE | BPF_K, 0, 0, 1, DATA_LEN },
  161. { BPF_JMP | BPF_JA | BPF_K, 0, 0, 4, 0 },
  162. { BPF_LD | BPF_B | BPF_ABS, 0, 0, 0, 0x50 },
  163. { BPF_JMP | BPF_JEQ | BPF_K, 0, 0, 2, DATA_CHAR },
  164. { BPF_JMP | BPF_JEQ | BPF_K, 0, 0, 1, DATA_CHAR_1 },
  165. { BPF_ALU | BPF_MOV | BPF_K, 0, 0, 0, 0 },
  166. { BPF_JMP | BPF_EXIT, 0, 0, 0, 0 }
  167. };
  168. union bpf_attr attr;
  169. int pfd;
  170. memset(&attr, 0, sizeof(attr));
  171. attr.prog_type = BPF_PROG_TYPE_SOCKET_FILTER;
  172. attr.insns = (unsigned long) prog;
  173. attr.insn_cnt = ARRAY_SIZE(prog);
  174. attr.license = (unsigned long) "GPL";
  175. attr.log_buf = (unsigned long) log_buf;
  176. attr.log_size = sizeof(log_buf);
  177. attr.log_level = 1;
  178. pfd = syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
  179. if (pfd < 0) {
  180. perror("bpf");
  181. fprintf(stderr, "bpf verifier:\n%s\n", log_buf);
  182. exit(1);
  183. }
  184. if (setsockopt(fd, SOL_PACKET, PACKET_FANOUT_DATA, &pfd, sizeof(pfd))) {
  185. perror("fanout data ebpf");
  186. exit(1);
  187. }
  188. if (close(pfd)) {
  189. perror("close ebpf");
  190. exit(1);
  191. }
  192. }
  193. static char *sock_fanout_open_ring(int fd)
  194. {
  195. struct tpacket_req req = {
  196. .tp_block_size = getpagesize(),
  197. .tp_frame_size = getpagesize(),
  198. .tp_block_nr = RING_NUM_FRAMES,
  199. .tp_frame_nr = RING_NUM_FRAMES,
  200. };
  201. char *ring;
  202. int val = TPACKET_V2;
  203. if (setsockopt(fd, SOL_PACKET, PACKET_VERSION, (void *) &val,
  204. sizeof(val))) {
  205. perror("packetsock ring setsockopt version");
  206. exit(1);
  207. }
  208. if (setsockopt(fd, SOL_PACKET, PACKET_RX_RING, (void *) &req,
  209. sizeof(req))) {
  210. perror("packetsock ring setsockopt");
  211. exit(1);
  212. }
  213. ring = mmap(0, req.tp_block_size * req.tp_block_nr,
  214. PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  215. if (ring == MAP_FAILED) {
  216. perror("packetsock ring mmap");
  217. exit(1);
  218. }
  219. return ring;
  220. }
  221. static int sock_fanout_read_ring(int fd, void *ring)
  222. {
  223. struct tpacket2_hdr *header = ring;
  224. int count = 0;
  225. while (count < RING_NUM_FRAMES && header->tp_status & TP_STATUS_USER) {
  226. count++;
  227. header = ring + (count * getpagesize());
  228. }
  229. return count;
  230. }
  231. static int sock_fanout_read(int fds[], char *rings[], const int expect[])
  232. {
  233. int ret[2];
  234. ret[0] = sock_fanout_read_ring(fds[0], rings[0]);
  235. ret[1] = sock_fanout_read_ring(fds[1], rings[1]);
  236. fprintf(stderr, "info: count=%d,%d, expect=%d,%d\n",
  237. ret[0], ret[1], expect[0], expect[1]);
  238. if ((!(ret[0] == expect[0] && ret[1] == expect[1])) &&
  239. (!(ret[0] == expect[1] && ret[1] == expect[0]))) {
  240. fprintf(stderr, "warning: incorrect queue lengths\n");
  241. return 1;
  242. }
  243. return 0;
  244. }
  245. /* Test that creating/joining a fanout group fails for unbound socket without
  246. * a specified protocol
  247. */
  248. static void test_unbound_fanout(void)
  249. {
  250. int val, fd0, fd1, err;
  251. fprintf(stderr, "test: unbound fanout\n");
  252. fd0 = socket(PF_PACKET, SOCK_RAW, 0);
  253. if (fd0 < 0) {
  254. perror("socket packet");
  255. exit(1);
  256. }
  257. /* Try to create a new fanout group. Should fail. */
  258. val = (PACKET_FANOUT_HASH << 16) | 1;
  259. err = setsockopt(fd0, SOL_PACKET, PACKET_FANOUT, &val, sizeof(val));
  260. if (!err) {
  261. fprintf(stderr, "ERROR: unbound socket fanout create\n");
  262. exit(1);
  263. }
  264. fd1 = sock_fanout_open(PACKET_FANOUT_HASH, 1);
  265. if (fd1 == -1) {
  266. fprintf(stderr, "ERROR: failed to open HASH socket\n");
  267. exit(1);
  268. }
  269. /* Try to join an existing fanout group. Should fail. */
  270. err = setsockopt(fd0, SOL_PACKET, PACKET_FANOUT, &val, sizeof(val));
  271. if (!err) {
  272. fprintf(stderr, "ERROR: unbound socket fanout join\n");
  273. exit(1);
  274. }
  275. close(fd0);
  276. close(fd1);
  277. }
  278. /* Test illegal mode + flag combination */
  279. static void test_control_single(void)
  280. {
  281. fprintf(stderr, "test: control single socket\n");
  282. if (sock_fanout_open(PACKET_FANOUT_ROLLOVER |
  283. PACKET_FANOUT_FLAG_ROLLOVER, 0) != -1) {
  284. fprintf(stderr, "ERROR: opened socket with dual rollover\n");
  285. exit(1);
  286. }
  287. }
  288. /* Test illegal group with different modes or flags */
  289. static void test_control_group(int toggle)
  290. {
  291. int fds[2];
  292. if (toggle)
  293. fprintf(stderr, "test: control multiple sockets with link down toggle\n");
  294. else
  295. fprintf(stderr, "test: control multiple sockets\n");
  296. fds[0] = sock_fanout_open(PACKET_FANOUT_HASH, 0);
  297. if (fds[0] == -1) {
  298. fprintf(stderr, "ERROR: failed to open HASH socket\n");
  299. exit(1);
  300. }
  301. if (toggle)
  302. loopback_set_up_down(0);
  303. if (sock_fanout_open(PACKET_FANOUT_HASH |
  304. PACKET_FANOUT_FLAG_DEFRAG, 0) != -1) {
  305. fprintf(stderr, "ERROR: joined group with wrong flag defrag\n");
  306. exit(1);
  307. }
  308. if (sock_fanout_open(PACKET_FANOUT_HASH |
  309. PACKET_FANOUT_FLAG_ROLLOVER, 0) != -1) {
  310. fprintf(stderr, "ERROR: joined group with wrong flag ro\n");
  311. exit(1);
  312. }
  313. if (sock_fanout_open(PACKET_FANOUT_CPU, 0) != -1) {
  314. fprintf(stderr, "ERROR: joined group with wrong mode\n");
  315. exit(1);
  316. }
  317. fds[1] = sock_fanout_open(PACKET_FANOUT_HASH, 0);
  318. if (fds[1] == -1) {
  319. fprintf(stderr, "ERROR: failed to join group\n");
  320. exit(1);
  321. }
  322. if (toggle)
  323. loopback_set_up_down(1);
  324. if (close(fds[1]) || close(fds[0])) {
  325. fprintf(stderr, "ERROR: closing sockets\n");
  326. exit(1);
  327. }
  328. }
  329. /* Test illegal max_num_members values */
  330. static void test_control_group_max_num_members(void)
  331. {
  332. int fds[3];
  333. fprintf(stderr, "test: control multiple sockets, max_num_members\n");
  334. /* expected failure on greater than PACKET_FANOUT_MAX */
  335. cfg_max_num_members = (1 << 16) + 1;
  336. if (sock_fanout_open(PACKET_FANOUT_HASH, 0) != -1) {
  337. fprintf(stderr, "ERROR: max_num_members > PACKET_FANOUT_MAX\n");
  338. exit(1);
  339. }
  340. cfg_max_num_members = 256;
  341. fds[0] = sock_fanout_open(PACKET_FANOUT_HASH, 0);
  342. if (fds[0] == -1) {
  343. fprintf(stderr, "ERROR: failed open\n");
  344. exit(1);
  345. }
  346. /* expected failure on joining group with different max_num_members */
  347. cfg_max_num_members = 257;
  348. if (sock_fanout_open(PACKET_FANOUT_HASH, 0) != -1) {
  349. fprintf(stderr, "ERROR: set different max_num_members\n");
  350. exit(1);
  351. }
  352. /* success on joining group with same max_num_members */
  353. cfg_max_num_members = 256;
  354. fds[1] = sock_fanout_open(PACKET_FANOUT_HASH, 0);
  355. if (fds[1] == -1) {
  356. fprintf(stderr, "ERROR: failed to join group\n");
  357. exit(1);
  358. }
  359. /* success on joining group with max_num_members unspecified */
  360. cfg_max_num_members = 0;
  361. fds[2] = sock_fanout_open(PACKET_FANOUT_HASH, 0);
  362. if (fds[2] == -1) {
  363. fprintf(stderr, "ERROR: failed to join group\n");
  364. exit(1);
  365. }
  366. if (close(fds[2]) || close(fds[1]) || close(fds[0])) {
  367. fprintf(stderr, "ERROR: closing sockets\n");
  368. exit(1);
  369. }
  370. }
  371. /* Test creating a unique fanout group ids */
  372. static void test_unique_fanout_group_ids(void)
  373. {
  374. int fds[3];
  375. uint16_t typeflags, first_group_id, second_group_id;
  376. fprintf(stderr, "test: unique ids\n");
  377. fds[0] = sock_fanout_open(PACKET_FANOUT_HASH |
  378. PACKET_FANOUT_FLAG_UNIQUEID, 0);
  379. if (fds[0] == -1) {
  380. fprintf(stderr, "ERROR: failed to create a unique id group.\n");
  381. exit(1);
  382. }
  383. sock_fanout_getopts(fds[0], &typeflags, &first_group_id);
  384. if (typeflags != PACKET_FANOUT_HASH) {
  385. fprintf(stderr, "ERROR: unexpected typeflags %x\n", typeflags);
  386. exit(1);
  387. }
  388. if (sock_fanout_open(PACKET_FANOUT_CPU, first_group_id) != -1) {
  389. fprintf(stderr, "ERROR: joined group with wrong type.\n");
  390. exit(1);
  391. }
  392. fds[1] = sock_fanout_open(PACKET_FANOUT_HASH, first_group_id);
  393. if (fds[1] == -1) {
  394. fprintf(stderr,
  395. "ERROR: failed to join previously created group.\n");
  396. exit(1);
  397. }
  398. fds[2] = sock_fanout_open(PACKET_FANOUT_HASH |
  399. PACKET_FANOUT_FLAG_UNIQUEID, 0);
  400. if (fds[2] == -1) {
  401. fprintf(stderr,
  402. "ERROR: failed to create a second unique id group.\n");
  403. exit(1);
  404. }
  405. sock_fanout_getopts(fds[2], &typeflags, &second_group_id);
  406. if (sock_fanout_open(PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_UNIQUEID,
  407. second_group_id) != -1) {
  408. fprintf(stderr,
  409. "ERROR: specified a group id when requesting unique id\n");
  410. exit(1);
  411. }
  412. if (close(fds[0]) || close(fds[1]) || close(fds[2])) {
  413. fprintf(stderr, "ERROR: closing sockets\n");
  414. exit(1);
  415. }
  416. }
  417. static int test_datapath(uint16_t typeflags, int port_off,
  418. const int expect1[], const int expect2[])
  419. {
  420. const int expect0[] = { 0, 0 };
  421. char *rings[2];
  422. uint8_t type = typeflags & 0xFF;
  423. int fds[2], fds_udp[2][2], ret;
  424. fprintf(stderr, "\ntest: datapath 0x%hx ports %hu,%hu\n",
  425. typeflags, (uint16_t)PORT_BASE,
  426. (uint16_t)(PORT_BASE + port_off));
  427. fds[0] = sock_fanout_open(typeflags, 0);
  428. fds[1] = sock_fanout_open(typeflags, 0);
  429. if (fds[0] == -1 || fds[1] == -1) {
  430. fprintf(stderr, "ERROR: failed open\n");
  431. exit(1);
  432. }
  433. if (type == PACKET_FANOUT_CBPF)
  434. sock_fanout_set_cbpf(fds[0]);
  435. else if (type == PACKET_FANOUT_EBPF)
  436. sock_fanout_set_ebpf(fds[0]);
  437. rings[0] = sock_fanout_open_ring(fds[0]);
  438. rings[1] = sock_fanout_open_ring(fds[1]);
  439. pair_udp_open(fds_udp[0], PORT_BASE);
  440. pair_udp_open(fds_udp[1], PORT_BASE + port_off);
  441. sock_fanout_read(fds, rings, expect0);
  442. /* Send data, but not enough to overflow a queue */
  443. pair_udp_send(fds_udp[0], 15);
  444. pair_udp_send_char(fds_udp[1], 5, DATA_CHAR_1);
  445. ret = sock_fanout_read(fds, rings, expect1);
  446. /* Send more data, overflow the queue */
  447. pair_udp_send_char(fds_udp[0], 15, DATA_CHAR_1);
  448. /* TODO: ensure consistent order between expect1 and expect2 */
  449. ret |= sock_fanout_read(fds, rings, expect2);
  450. if (munmap(rings[1], RING_NUM_FRAMES * getpagesize()) ||
  451. munmap(rings[0], RING_NUM_FRAMES * getpagesize())) {
  452. fprintf(stderr, "close rings\n");
  453. exit(1);
  454. }
  455. if (close(fds_udp[1][1]) || close(fds_udp[1][0]) ||
  456. close(fds_udp[0][1]) || close(fds_udp[0][0]) ||
  457. close(fds[1]) || close(fds[0])) {
  458. fprintf(stderr, "close datapath\n");
  459. exit(1);
  460. }
  461. return ret;
  462. }
  463. static int set_cpuaffinity(int cpuid)
  464. {
  465. cpu_set_t mask;
  466. CPU_ZERO(&mask);
  467. CPU_SET(cpuid, &mask);
  468. if (sched_setaffinity(0, sizeof(mask), &mask)) {
  469. if (errno != EINVAL) {
  470. fprintf(stderr, "setaffinity %d\n", cpuid);
  471. exit(1);
  472. }
  473. return 1;
  474. }
  475. return 0;
  476. }
  477. int main(int argc, char **argv)
  478. {
  479. const int expect_hash[2][2] = { { 15, 5 }, { 20, 5 } };
  480. const int expect_hash_rb[2][2] = { { 15, 5 }, { 20, 15 } };
  481. const int expect_lb[2][2] = { { 10, 10 }, { 18, 17 } };
  482. const int expect_rb[2][2] = { { 15, 5 }, { 20, 15 } };
  483. const int expect_cpu0[2][2] = { { 20, 0 }, { 20, 0 } };
  484. const int expect_cpu1[2][2] = { { 0, 20 }, { 0, 20 } };
  485. const int expect_bpf[2][2] = { { 15, 5 }, { 15, 20 } };
  486. const int expect_uniqueid[2][2] = { { 20, 20}, { 20, 20 } };
  487. int port_off = 2, tries = 20, ret;
  488. test_unbound_fanout();
  489. test_control_single();
  490. test_control_group(0);
  491. test_control_group(1);
  492. test_control_group_max_num_members();
  493. test_unique_fanout_group_ids();
  494. /* PACKET_FANOUT_MAX */
  495. cfg_max_num_members = 1 << 16;
  496. /* find a set of ports that do not collide onto the same socket */
  497. ret = test_datapath(PACKET_FANOUT_HASH, port_off,
  498. expect_hash[0], expect_hash[1]);
  499. while (ret) {
  500. fprintf(stderr, "info: trying alternate ports (%d)\n", tries);
  501. ret = test_datapath(PACKET_FANOUT_HASH, ++port_off,
  502. expect_hash[0], expect_hash[1]);
  503. if (!--tries) {
  504. fprintf(stderr, "too many collisions\n");
  505. return 1;
  506. }
  507. }
  508. ret |= test_datapath(PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_ROLLOVER,
  509. port_off, expect_hash_rb[0], expect_hash_rb[1]);
  510. ret |= test_datapath(PACKET_FANOUT_LB,
  511. port_off, expect_lb[0], expect_lb[1]);
  512. ret |= test_datapath(PACKET_FANOUT_ROLLOVER,
  513. port_off, expect_rb[0], expect_rb[1]);
  514. ret |= test_datapath(PACKET_FANOUT_CBPF,
  515. port_off, expect_bpf[0], expect_bpf[1]);
  516. ret |= test_datapath(PACKET_FANOUT_EBPF,
  517. port_off, expect_bpf[0], expect_bpf[1]);
  518. set_cpuaffinity(0);
  519. ret |= test_datapath(PACKET_FANOUT_CPU, port_off,
  520. expect_cpu0[0], expect_cpu0[1]);
  521. if (!set_cpuaffinity(1))
  522. /* TODO: test that choice alternates with previous */
  523. ret |= test_datapath(PACKET_FANOUT_CPU, port_off,
  524. expect_cpu1[0], expect_cpu1[1]);
  525. ret |= test_datapath(PACKET_FANOUT_FLAG_UNIQUEID, port_off,
  526. expect_uniqueid[0], expect_uniqueid[1]);
  527. if (ret)
  528. return 1;
  529. printf("OK. All tests passed\n");
  530. return 0;
  531. }