Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: sockmap_listen cleanup: Drop af_inet SOCK_DGRAM redir tests

Remove tests covered by sockmap_redir.

Signed-off-by: Michal Luczaj <mhal@rbox.co>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/r/20250515-selftests-sockmap-redir-v3-8-a1ea723f7e7e@rbox.co

authored by

Michal Luczaj and committed by
Martin KaFai Lau
c04eeeb2 f3de1cf6

-126
-126
tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
··· 1366 1366 } 1367 1367 } 1368 1368 1369 - static void pairs_redir_to_connected(int cli0, int peer0, int cli1, int peer1, 1370 - int sock_mapfd, int nop_mapfd, 1371 - int verd_mapfd, enum redir_mode mode, 1372 - int send_flags) 1373 - { 1374 - const char *log_prefix = redir_mode_str(mode); 1375 - unsigned int pass; 1376 - int err, n; 1377 - u32 key; 1378 - char b; 1379 - 1380 - zero_verdict_count(verd_mapfd); 1381 - 1382 - err = add_to_sockmap(sock_mapfd, peer0, peer1); 1383 - if (err) 1384 - return; 1385 - 1386 - if (nop_mapfd >= 0) { 1387 - err = add_to_sockmap(nop_mapfd, cli0, cli1); 1388 - if (err) 1389 - return; 1390 - } 1391 - 1392 - /* Last byte is OOB data when send_flags has MSG_OOB bit set */ 1393 - n = xsend(cli1, "ab", 2, send_flags); 1394 - if (n >= 0 && n < 2) 1395 - FAIL("%s: incomplete send", log_prefix); 1396 - if (n < 2) 1397 - return; 1398 - 1399 - key = SK_PASS; 1400 - err = xbpf_map_lookup_elem(verd_mapfd, &key, &pass); 1401 - if (err) 1402 - return; 1403 - if (pass != 1) 1404 - FAIL("%s: want pass count 1, have %d", log_prefix, pass); 1405 - 1406 - n = recv_timeout(mode == REDIR_INGRESS ? peer0 : cli0, &b, 1, 0, IO_TIMEOUT_SEC); 1407 - if (n < 0) 1408 - FAIL_ERRNO("%s: recv_timeout", log_prefix); 1409 - if (n == 0) 1410 - FAIL("%s: incomplete recv", log_prefix); 1411 - 1412 - if (send_flags & MSG_OOB) { 1413 - /* Check that we can't read OOB while in sockmap */ 1414 - errno = 0; 1415 - n = recv(peer1, &b, 1, MSG_OOB | MSG_DONTWAIT); 1416 - if (n != -1 || errno != EOPNOTSUPP) 1417 - FAIL("%s: recv(MSG_OOB): expected EOPNOTSUPP: retval=%d errno=%d", 1418 - log_prefix, n, errno); 1419 - 1420 - /* Remove peer1 from sockmap */ 1421 - xbpf_map_delete_elem(sock_mapfd, &(int){ 1 }); 1422 - 1423 - /* Check that OOB was dropped on redirect */ 1424 - errno = 0; 1425 - n = recv(peer1, &b, 1, MSG_OOB | MSG_DONTWAIT); 1426 - if (n != -1 || errno != EINVAL) 1427 - FAIL("%s: recv(MSG_OOB): expected EINVAL: retval=%d errno=%d", 1428 - log_prefix, n, errno); 1429 - } 1430 - } 1431 - 1432 1369 static void test_reuseport(struct test_sockmap_listen *skel, 1433 1370 struct bpf_map *map, int family, int sotype) 1434 1371 { ··· 1406 1469 } 1407 1470 } 1408 1471 1409 - static int inet_socketpair(int family, int type, int *s, int *c) 1410 - { 1411 - return create_pair(family, type | SOCK_NONBLOCK, s, c); 1412 - } 1413 - 1414 - static void udp_redir_to_connected(int family, int sock_mapfd, int verd_mapfd, 1415 - enum redir_mode mode) 1416 - { 1417 - int c0, c1, p0, p1; 1418 - int err; 1419 - 1420 - err = inet_socketpair(family, SOCK_DGRAM, &p0, &c0); 1421 - if (err) 1422 - return; 1423 - err = inet_socketpair(family, SOCK_DGRAM, &p1, &c1); 1424 - if (err) 1425 - goto close_cli0; 1426 - 1427 - pairs_redir_to_connected(c0, p0, c1, p1, sock_mapfd, -1, verd_mapfd, 1428 - mode, NO_FLAGS); 1429 - 1430 - xclose(c1); 1431 - xclose(p1); 1432 - close_cli0: 1433 - xclose(c0); 1434 - xclose(p0); 1435 - } 1436 - 1437 - static void udp_skb_redir_to_connected(struct test_sockmap_listen *skel, 1438 - struct bpf_map *inner_map, int family) 1439 - { 1440 - int verdict = bpf_program__fd(skel->progs.prog_skb_verdict); 1441 - int verdict_map = bpf_map__fd(skel->maps.verdict_map); 1442 - int sock_map = bpf_map__fd(inner_map); 1443 - int err; 1444 - 1445 - err = xbpf_prog_attach(verdict, sock_map, BPF_SK_SKB_VERDICT, 0); 1446 - if (err) 1447 - return; 1448 - 1449 - skel->bss->test_ingress = false; 1450 - udp_redir_to_connected(family, sock_map, verdict_map, REDIR_EGRESS); 1451 - skel->bss->test_ingress = true; 1452 - udp_redir_to_connected(family, sock_map, verdict_map, REDIR_INGRESS); 1453 - 1454 - xbpf_prog_detach2(verdict, sock_map, BPF_SK_SKB_VERDICT); 1455 - } 1456 - 1457 - static void test_udp_redir(struct test_sockmap_listen *skel, struct bpf_map *map, 1458 - int family) 1459 - { 1460 - const char *family_name, *map_name; 1461 - char s[MAX_TEST_NAME]; 1462 - 1463 - family_name = family_str(family); 1464 - map_name = map_type_str(map); 1465 - snprintf(s, sizeof(s), "%s %s %s", map_name, family_name, __func__); 1466 - if (!test__start_subtest(s)) 1467 - return; 1468 - udp_skb_redir_to_connected(skel, map, family); 1469 - } 1470 - 1471 1472 static void run_tests(struct test_sockmap_listen *skel, struct bpf_map *map, 1472 1473 int family) 1473 1474 { ··· 1414 1539 test_redir(skel, map, family, SOCK_STREAM); 1415 1540 test_reuseport(skel, map, family, SOCK_STREAM); 1416 1541 test_reuseport(skel, map, family, SOCK_DGRAM); 1417 - test_udp_redir(skel, map, family); 1418 1542 } 1419 1543 1420 1544 void serial_test_sockmap_listen(void)