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

selftests: net/psock_fanout: socket joins fanout when link is down

Modify test_control_group to have toggle parameter.
When toggle is non-zero, loopback device will be set down for the
initialization of fd[1] which is still expected to successfully join
the fanout.

Signed-off-by: Gur Stavi <gur.stavi@huawei.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/6f4a506ed5f08f8fc00a966dec8febd1030c6e98.1728802323.git.gur.stavi@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Gur Stavi and committed by
Jakub Kicinski
9317e893 2cee3e6e

+39 -3
+39 -3
tools/testing/selftests/net/psock_fanout.c
··· 48 48 #include <string.h> 49 49 #include <sys/mman.h> 50 50 #include <sys/socket.h> 51 + #include <sys/ioctl.h> 51 52 #include <sys/stat.h> 52 53 #include <sys/types.h> 53 54 #include <unistd.h> ··· 59 58 #define RING_NUM_FRAMES 20 60 59 61 60 static uint32_t cfg_max_num_members; 61 + 62 + static void loopback_set_up_down(int state_up) 63 + { 64 + struct ifreq ifreq = {}; 65 + int fd, err; 66 + 67 + fd = socket(AF_PACKET, SOCK_RAW, 0); 68 + if (fd < 0) { 69 + perror("socket loopback"); 70 + exit(1); 71 + } 72 + strcpy(ifreq.ifr_name, "lo"); 73 + err = ioctl(fd, SIOCGIFFLAGS, &ifreq); 74 + if (err) { 75 + perror("SIOCGIFFLAGS"); 76 + exit(1); 77 + } 78 + if (state_up != !!(ifreq.ifr_flags & IFF_UP)) { 79 + ifreq.ifr_flags ^= IFF_UP; 80 + err = ioctl(fd, SIOCSIFFLAGS, &ifreq); 81 + if (err) { 82 + perror("SIOCSIFFLAGS"); 83 + exit(1); 84 + } 85 + } 86 + close(fd); 87 + } 62 88 63 89 /* Open a socket in a given fanout mode. 64 90 * @return -1 if mode is bad, a valid socket otherwise */ ··· 292 264 } 293 265 294 266 /* Test illegal group with different modes or flags */ 295 - static void test_control_group(void) 267 + static void test_control_group(int toggle) 296 268 { 297 269 int fds[2]; 298 270 299 - fprintf(stderr, "test: control multiple sockets\n"); 271 + if (toggle) 272 + fprintf(stderr, "test: control multiple sockets with link down toggle\n"); 273 + else 274 + fprintf(stderr, "test: control multiple sockets\n"); 300 275 301 276 fds[0] = sock_fanout_open(PACKET_FANOUT_HASH, 0); 302 277 if (fds[0] == -1) { 303 278 fprintf(stderr, "ERROR: failed to open HASH socket\n"); 304 279 exit(1); 305 280 } 281 + if (toggle) 282 + loopback_set_up_down(0); 306 283 if (sock_fanout_open(PACKET_FANOUT_HASH | 307 284 PACKET_FANOUT_FLAG_DEFRAG, 0) != -1) { 308 285 fprintf(stderr, "ERROR: joined group with wrong flag defrag\n"); ··· 327 294 fprintf(stderr, "ERROR: failed to join group\n"); 328 295 exit(1); 329 296 } 297 + if (toggle) 298 + loopback_set_up_down(1); 330 299 if (close(fds[1]) || close(fds[0])) { 331 300 fprintf(stderr, "ERROR: closing sockets\n"); 332 301 exit(1); ··· 524 489 int port_off = 2, tries = 20, ret; 525 490 526 491 test_control_single(); 527 - test_control_group(); 492 + test_control_group(0); 493 + test_control_group(1); 528 494 test_control_group_max_num_members(); 529 495 test_unique_fanout_group_ids(); 530 496