From nobody Wed Nov 27 22:35:38 2024 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 676C01D415D; Mon, 7 Oct 2024 12:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728304918; cv=none; b=EK97b/i3LXZaf2M+MA7sbyPGs/SY2nKxytb9v90C1nOCNFtM3FlkjaZGlwwBX/ZcR3eP7uU9Ll6mNct03UGKHdChYkO5/7IRvM5/v087MvsHBJiDkSqBfv+71T9j0lO+WwMRet4ktT+1FoiPHbuyW2N7EII/eK4yEvr0qrHWW8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728304918; c=relaxed/simple; bh=aBlOcBGpY6fSZAZ+sX+T0PzvypJLxIF4FfnR85bUerg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jrNDMi0aQrioNMSduDyST/Yqndm+12dcOxYq9ISWCMtjfQAIZBYq9NPM2pUdFhRhCSwwc3OUvEnPVHcI7PMU1kcxG8xofXXOa+zDpR8cmXPQ0Gfd356mYgpMbdfUTo6EBJZo8EpbxqTwdFdkxcUabyL43E0YUBhWyBk/fUEagvk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XMf0c4p5mz6K8kG; Mon, 7 Oct 2024 20:41:36 +0800 (CST) Received: from frapeml500005.china.huawei.com (unknown [7.182.85.13]) by mail.maildlp.com (Postfix) with ESMTPS id B7D39140581; Mon, 7 Oct 2024 20:41:48 +0800 (CST) Received: from china (10.200.201.82) by frapeml500005.china.huawei.com (7.182.85.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 7 Oct 2024 14:41:44 +0200 From: Gur Stavi To: Gur Stavi CC: , , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH net-next v01 1/4] af_packet: allow fanout_add when socket is not RUNNING Date: Mon, 7 Oct 2024 15:40:24 +0300 Message-ID: <52a2ac061498e96e69a71e49ecb961b6a17dfff7.1728303615.git.gur.stavi@huawei.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To frapeml500005.china.huawei.com (7.182.85.13) Content-Type: text/plain; charset="utf-8" PACKET socket can retain its fanout membership through link down and up and (obviously) leave a fanout while it is not RUNNING (link down). However, socket was forbidden from joining a fanout while it was not RUNNING. This patch allows PACKET socket to join fanout while not RUNNING. Signed-off-by: Gur Stavi --- net/packet/af_packet.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index a705ec214254..c28eee7f6ce0 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1846,21 +1846,21 @@ static int fanout_add(struct sock *sk, struct fanou= t_args *args) err =3D -EINVAL; =20 spin_lock(&po->bind_lock); - if (packet_sock_flag(po, PACKET_SOCK_RUNNING) && - match->type =3D=3D type && + if (match->type =3D=3D type && match->prot_hook.type =3D=3D po->prot_hook.type && match->prot_hook.dev =3D=3D po->prot_hook.dev) { err =3D -ENOSPC; if (refcount_read(&match->sk_ref) < match->max_num_members) { - __dev_remove_pack(&po->prot_hook); - /* Paired with packet_setsockopt(PACKET_FANOUT_DATA) */ WRITE_ONCE(po->fanout, match); =20 po->rollover =3D rollover; rollover =3D NULL; refcount_set(&match->sk_ref, refcount_read(&match->sk_ref) + 1); - __fanout_link(sk, po); + if (packet_sock_flag(po, PACKET_SOCK_RUNNING)) { + __dev_remove_pack(&po->prot_hook); + __fanout_link(sk, po); + } err =3D 0; } } --=20 2.45.2 From nobody Wed Nov 27 22:35:38 2024 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 618EC1D4142; Mon, 7 Oct 2024 12:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728304917; cv=none; b=L717ehAFg9gwxd9Ou0Vw1RaXUvDIRUOQKRu0GxqRECIIfVOXuuekDcZdggOR9U7gUCj1lBVIN4cW2onsRIGokBncUg+zaxE3lSsa3kRogVtYxpSNXB0dVRxgjhDe186PhteLSc5FehsjL9VrICmZWHpXonQ0AZio3Wmqt48GH9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728304917; c=relaxed/simple; bh=ZGw/ydXe3lqLhHPyW6x479+JVflWiIK6QLHwbbeX1Bk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VwU/myu8haQ9qrg3NCOiSmDQM2mBhNfw8PpS8dSgVuP+MsbLXO3zhUhHrglLV8OSMEvJOWuHkfjCyZCD+lQna+SnWoziFi2J/w0s3NtVXRbwAEckXtEacCyHUC5doorb7BdYIadAnEheC/+sXI4loAQ/FWqgr1K6g2UtJtowPOI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XMdzZ0zbMz6G9gq; Mon, 7 Oct 2024 20:40:42 +0800 (CST) Received: from frapeml500005.china.huawei.com (unknown [7.182.85.13]) by mail.maildlp.com (Postfix) with ESMTPS id 647F114011A; Mon, 7 Oct 2024 20:41:53 +0800 (CST) Received: from china (10.200.201.82) by frapeml500005.china.huawei.com (7.182.85.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 7 Oct 2024 14:41:49 +0200 From: Gur Stavi To: Gur Stavi CC: , , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH net-next v01 2/4] selftests: net/psock_fanout: add loopback up/down toggle facility Date: Mon, 7 Oct 2024 15:40:25 +0300 Message-ID: <31c93d3d050cadf75aaa833aca4b6614666ba8de.1728303615.git.gur.stavi@huawei.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To frapeml500005.china.huawei.com (7.182.85.13) Content-Type: text/plain; charset="utf-8" Prepare to test setsockopt with PACKET_FANOUT on a link that is down. Signed-off-by: Gur Stavi --- tools/testing/selftests/net/psock_fanout.c | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/testing/selftests/net/psock_fanout.c b/tools/testing/sel= ftests/net/psock_fanout.c index 4f31e92ebd96..a8b22494a635 100644 --- a/tools/testing/selftests/net/psock_fanout.c +++ b/tools/testing/selftests/net/psock_fanout.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,43 @@ #define RING_NUM_FRAMES 20 =20 static uint32_t cfg_max_num_members; +static int lo_up_down_toggled; + +static void loopback_up_down_toggle(void) +{ + struct ifreq ifreq =3D {}; + int fd, err; + + fd =3D socket(AF_PACKET, SOCK_RAW, 0); + if (fd =3D=3D -1) + return; + strcpy(ifreq.ifr_name, "lo"); + err =3D ioctl(fd, SIOCGIFFLAGS, &ifreq); + if (err) { + perror("SIOCGIFFLAGS"); + exit(1); + } + ifreq.ifr_flags ^=3D IFF_UP; + err =3D ioctl(fd, SIOCSIFFLAGS, &ifreq); + if (err) { + perror("SIOCSIFFLAGS"); + exit(1); + } + lo_up_down_toggled ^=3D 1; + close(fd); +} + +static void loopback_up_down_restore(void) +{ + if (lo_up_down_toggled) + loopback_up_down_toggle(); +} + +static int cleanup_and_exit(int status) +{ + loopback_up_down_restore(); + exit(status); +} =20 /* Open a socket in a given fanout mode. * @return -1 if mode is bad, a valid socket otherwise */ --=20 2.45.2 From nobody Wed Nov 27 22:35:38 2024 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FE341D415D; Mon, 7 Oct 2024 12:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728304922; cv=none; b=j3FCeIbV3ZgBLbu5HjnqtY+C0NzKRYL7fCM0YUu/6vFBGTZuP3Zlx2Ups5DFrvChnmack4YZytkf+lQ+19YwEQw1zpAjtGAkbjhb+x9Qnl8/tktZq5hcEIgxash7WNpgR9t2Dyhz3kVRkNPrzoUQeMWoTm0oDQrq9FcNzg80EoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728304922; c=relaxed/simple; bh=cZhV2qPiFjDdEQqGl5oq97yO4OM1xzFW6BUmRKYsNDE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aHdccNcXf3x8JZVbOALThvNPa5G/Q4eOynnSask29i5scx8mK7Dvt72ZUqx806YCr9wahFMZ8c4JJ/Pa+jetCYMpH740Jb0CzwBMssAmYk9TJGsFEjdDEsdQXJVQAiiI78/SdZhaLuzukwYDM25dNuHGlPIOXCqtTgcQiH801ng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XMdw56TrTz6LCxH; Mon, 7 Oct 2024 20:37:41 +0800 (CST) Received: from frapeml500005.china.huawei.com (unknown [7.182.85.13]) by mail.maildlp.com (Postfix) with ESMTPS id 40DAA140680; Mon, 7 Oct 2024 20:41:58 +0800 (CST) Received: from china (10.200.201.82) by frapeml500005.china.huawei.com (7.182.85.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 7 Oct 2024 14:41:53 +0200 From: Gur Stavi To: Gur Stavi CC: , , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH net-next v01 3/4] selftests: net/psock_fanout: restore loopback up/down state on exit Date: Mon, 7 Oct 2024 15:40:26 +0300 Message-ID: <7b2cb791fb402b88e22013ae012363d596befb50.1728303615.git.gur.stavi@huawei.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To frapeml500005.china.huawei.com (7.182.85.13) Content-Type: text/plain; charset="utf-8" Minimize the risk that psock_fanout leaves loopback device in a different state than the start state. Restore loopback up/down state when test reaches end of main. For abort on errors, globally replace all 'exit' with 'cleanup_and_exit' that restores loopback up/down state. Signed-off-by: Gur Stavi --- tools/testing/selftests/net/psock_fanout.c | 73 +++++++++++----------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/tools/testing/selftests/net/psock_fanout.c b/tools/testing/sel= ftests/net/psock_fanout.c index a8b22494a635..64edcd661d43 100644 --- a/tools/testing/selftests/net/psock_fanout.c +++ b/tools/testing/selftests/net/psock_fanout.c @@ -108,7 +108,7 @@ static int sock_fanout_open(uint16_t typeflags, uint16_= t group_id) fd =3D socket(PF_PACKET, SOCK_RAW, 0); if (fd < 0) { perror("socket packet"); - exit(1); + cleanup_and_exit(1); } =20 pair_udp_setfilter(fd); @@ -118,11 +118,11 @@ static int sock_fanout_open(uint16_t typeflags, uint1= 6_t group_id) addr.sll_ifindex =3D if_nametoindex("lo"); if (addr.sll_ifindex =3D=3D 0) { perror("if_nametoindex"); - exit(1); + cleanup_and_exit(1); } if (bind(fd, (void *) &addr, sizeof(addr))) { perror("bind packet"); - exit(1); + cleanup_and_exit(1); } =20 if (cfg_max_num_members) { @@ -139,7 +139,7 @@ static int sock_fanout_open(uint16_t typeflags, uint16_= t group_id) if (err) { if (close(fd)) { perror("close packet"); - exit(1); + cleanup_and_exit(1); } return -1; } @@ -161,7 +161,7 @@ static void sock_fanout_set_cbpf(int fd) if (setsockopt(fd, SOL_PACKET, PACKET_FANOUT_DATA, &bpf_prog, sizeof(bpf_prog))) { perror("fanout data cbpf"); - exit(1); + cleanup_and_exit(1); } } =20 @@ -173,7 +173,7 @@ static void sock_fanout_getopts(int fd, uint16_t *typef= lags, uint16_t *group_id) if (getsockopt(fd, SOL_PACKET, PACKET_FANOUT, &sockopt, &sockopt_len)) { perror("failed to getsockopt"); - exit(1); + cleanup_and_exit(1); } *typeflags =3D sockopt >> 16; *group_id =3D sockopt & 0xfffff; @@ -211,17 +211,17 @@ static void sock_fanout_set_ebpf(int fd) if (pfd < 0) { perror("bpf"); fprintf(stderr, "bpf verifier:\n%s\n", log_buf); - exit(1); + cleanup_and_exit(1); } =20 if (setsockopt(fd, SOL_PACKET, PACKET_FANOUT_DATA, &pfd, sizeof(pfd))) { perror("fanout data ebpf"); - exit(1); + cleanup_and_exit(1); } =20 if (close(pfd)) { perror("close ebpf"); - exit(1); + cleanup_and_exit(1); } } =20 @@ -239,19 +239,19 @@ static char *sock_fanout_open_ring(int fd) if (setsockopt(fd, SOL_PACKET, PACKET_VERSION, (void *) &val, sizeof(val))) { perror("packetsock ring setsockopt version"); - exit(1); + cleanup_and_exit(1); } if (setsockopt(fd, SOL_PACKET, PACKET_RX_RING, (void *) &req, sizeof(req))) { perror("packetsock ring setsockopt"); - exit(1); + cleanup_and_exit(1); } =20 ring =3D mmap(0, req.tp_block_size * req.tp_block_nr, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (ring =3D=3D MAP_FAILED) { perror("packetsock ring mmap"); - exit(1); + cleanup_and_exit(1); } =20 return ring; @@ -297,7 +297,7 @@ static void test_control_single(void) if (sock_fanout_open(PACKET_FANOUT_ROLLOVER | PACKET_FANOUT_FLAG_ROLLOVER, 0) !=3D -1) { fprintf(stderr, "ERROR: opened socket with dual rollover\n"); - exit(1); + cleanup_and_exit(1); } } =20 @@ -311,30 +311,30 @@ static void test_control_group(void) fds[0] =3D sock_fanout_open(PACKET_FANOUT_HASH, 0); if (fds[0] =3D=3D -1) { fprintf(stderr, "ERROR: failed to open HASH socket\n"); - exit(1); + cleanup_and_exit(1); } if (sock_fanout_open(PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG, 0) !=3D -1) { fprintf(stderr, "ERROR: joined group with wrong flag defrag\n"); - exit(1); + cleanup_and_exit(1); } if (sock_fanout_open(PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_ROLLOVER, 0) !=3D -1) { fprintf(stderr, "ERROR: joined group with wrong flag ro\n"); - exit(1); + cleanup_and_exit(1); } if (sock_fanout_open(PACKET_FANOUT_CPU, 0) !=3D -1) { fprintf(stderr, "ERROR: joined group with wrong mode\n"); - exit(1); + cleanup_and_exit(1); } fds[1] =3D sock_fanout_open(PACKET_FANOUT_HASH, 0); if (fds[1] =3D=3D -1) { fprintf(stderr, "ERROR: failed to join group\n"); - exit(1); + cleanup_and_exit(1); } if (close(fds[1]) || close(fds[0])) { fprintf(stderr, "ERROR: closing sockets\n"); - exit(1); + cleanup_and_exit(1); } } =20 @@ -349,21 +349,21 @@ static void test_control_group_max_num_members(void) cfg_max_num_members =3D (1 << 16) + 1; if (sock_fanout_open(PACKET_FANOUT_HASH, 0) !=3D -1) { fprintf(stderr, "ERROR: max_num_members > PACKET_FANOUT_MAX\n"); - exit(1); + cleanup_and_exit(1); } =20 cfg_max_num_members =3D 256; fds[0] =3D sock_fanout_open(PACKET_FANOUT_HASH, 0); if (fds[0] =3D=3D -1) { fprintf(stderr, "ERROR: failed open\n"); - exit(1); + cleanup_and_exit(1); } =20 /* expected failure on joining group with different max_num_members */ cfg_max_num_members =3D 257; if (sock_fanout_open(PACKET_FANOUT_HASH, 0) !=3D -1) { fprintf(stderr, "ERROR: set different max_num_members\n"); - exit(1); + cleanup_and_exit(1); } =20 /* success on joining group with same max_num_members */ @@ -371,7 +371,7 @@ static void test_control_group_max_num_members(void) fds[1] =3D sock_fanout_open(PACKET_FANOUT_HASH, 0); if (fds[1] =3D=3D -1) { fprintf(stderr, "ERROR: failed to join group\n"); - exit(1); + cleanup_and_exit(1); } =20 /* success on joining group with max_num_members unspecified */ @@ -379,12 +379,12 @@ static void test_control_group_max_num_members(void) fds[2] =3D sock_fanout_open(PACKET_FANOUT_HASH, 0); if (fds[2] =3D=3D -1) { fprintf(stderr, "ERROR: failed to join group\n"); - exit(1); + cleanup_and_exit(1); } =20 if (close(fds[2]) || close(fds[1]) || close(fds[0])) { fprintf(stderr, "ERROR: closing sockets\n"); - exit(1); + cleanup_and_exit(1); } } =20 @@ -400,25 +400,25 @@ static void test_unique_fanout_group_ids(void) PACKET_FANOUT_FLAG_UNIQUEID, 0); if (fds[0] =3D=3D -1) { fprintf(stderr, "ERROR: failed to create a unique id group.\n"); - exit(1); + cleanup_and_exit(1); } =20 sock_fanout_getopts(fds[0], &typeflags, &first_group_id); if (typeflags !=3D PACKET_FANOUT_HASH) { fprintf(stderr, "ERROR: unexpected typeflags %x\n", typeflags); - exit(1); + cleanup_and_exit(1); } =20 if (sock_fanout_open(PACKET_FANOUT_CPU, first_group_id) !=3D -1) { fprintf(stderr, "ERROR: joined group with wrong type.\n"); - exit(1); + cleanup_and_exit(1); } =20 fds[1] =3D sock_fanout_open(PACKET_FANOUT_HASH, first_group_id); if (fds[1] =3D=3D -1) { fprintf(stderr, "ERROR: failed to join previously created group.\n"); - exit(1); + cleanup_and_exit(1); } =20 fds[2] =3D sock_fanout_open(PACKET_FANOUT_HASH | @@ -426,7 +426,7 @@ static void test_unique_fanout_group_ids(void) if (fds[2] =3D=3D -1) { fprintf(stderr, "ERROR: failed to create a second unique id group.\n"); - exit(1); + cleanup_and_exit(1); } =20 sock_fanout_getopts(fds[2], &typeflags, &second_group_id); @@ -434,12 +434,12 @@ static void test_unique_fanout_group_ids(void) second_group_id) !=3D -1) { fprintf(stderr, "ERROR: specified a group id when requesting unique id\n"); - exit(1); + cleanup_and_exit(1); } =20 if (close(fds[0]) || close(fds[1]) || close(fds[2])) { fprintf(stderr, "ERROR: closing sockets\n"); - exit(1); + cleanup_and_exit(1); } } =20 @@ -459,7 +459,7 @@ static int test_datapath(uint16_t typeflags, int port_o= ff, fds[1] =3D sock_fanout_open(typeflags, 0); if (fds[0] =3D=3D -1 || fds[1] =3D=3D -1) { fprintf(stderr, "ERROR: failed open\n"); - exit(1); + cleanup_and_exit(1); } if (type =3D=3D PACKET_FANOUT_CBPF) sock_fanout_set_cbpf(fds[0]); @@ -485,13 +485,13 @@ static int test_datapath(uint16_t typeflags, int port= _off, if (munmap(rings[1], RING_NUM_FRAMES * getpagesize()) || munmap(rings[0], RING_NUM_FRAMES * getpagesize())) { fprintf(stderr, "close rings\n"); - exit(1); + cleanup_and_exit(1); } if (close(fds_udp[1][1]) || close(fds_udp[1][0]) || close(fds_udp[0][1]) || close(fds_udp[0][0]) || close(fds[1]) || close(fds[0])) { fprintf(stderr, "close datapath\n"); - exit(1); + cleanup_and_exit(1); } =20 return ret; @@ -506,7 +506,7 @@ static int set_cpuaffinity(int cpuid) if (sched_setaffinity(0, sizeof(mask), &mask)) { if (errno !=3D EINVAL) { fprintf(stderr, "setaffinity %d\n", cpuid); - exit(1); + cleanup_and_exit(1); } return 1; } @@ -569,6 +569,7 @@ int main(int argc, char **argv) ret |=3D test_datapath(PACKET_FANOUT_FLAG_UNIQUEID, port_off, expect_uniqueid[0], expect_uniqueid[1]); =20 + loopback_up_down_restore(); if (ret) return 1; =20 --=20 2.45.2 From nobody Wed Nov 27 22:35:38 2024 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BDB71D415D; Mon, 7 Oct 2024 12:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728304927; cv=none; b=RtKWL3mbfZougyLPulFQuUxtlnGfQHZVamMC4Kb9EP0oVLl9nx+kJsRz8t2jIo1lHxHAhnATO0gw6mN4fRgDgU/umDEqvgWcCF9Ab9RTzw6m6w7NjvMsMdGd9T7OK//iYpsh6ykUINW4vM4TAHudRdfI78kokp4XTmAucTlEdhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728304927; c=relaxed/simple; bh=0ecxNdjjMUusXLGDujDykGlXNP8253S2c5pvZV3R9yc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TXdeylMJahFFFgYvZAz+4sHVevFs4fgtJ7pBMPXisrGDKbCTYUDQqXGMuSFUtvOHIM6MoygJrjhRCnH2TZ73k33HdCNvPFGpoDRUrHDZygrgwuLLSJ1g62eqYQDEfGlEbQUa+CX4ZuJnqy6BbwRd8uhNGd+FkQbYYKmoJ21aP8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XMdwB3yvRz6LCv0; Mon, 7 Oct 2024 20:37:46 +0800 (CST) Received: from frapeml500005.china.huawei.com (unknown [7.182.85.13]) by mail.maildlp.com (Postfix) with ESMTPS id DC187140B55; Mon, 7 Oct 2024 20:42:02 +0800 (CST) Received: from china (10.200.201.82) by frapeml500005.china.huawei.com (7.182.85.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 7 Oct 2024 14:41:58 +0200 From: Gur Stavi To: Gur Stavi CC: , , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH net-next v01 4/4] selftests: net/psock_fanout: socket joins fanout when link is down Date: Mon, 7 Oct 2024 15:40:27 +0300 Message-ID: <8965036dce0ad6c52acfdf93637fb9f5c10aff76.1728303615.git.gur.stavi@huawei.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To frapeml500005.china.huawei.com (7.182.85.13) Content-Type: text/plain; charset="utf-8" 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 --- tools/testing/selftests/net/psock_fanout.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/psock_fanout.c b/tools/testing/sel= ftests/net/psock_fanout.c index 64edcd661d43..49023d9b85b4 100644 --- a/tools/testing/selftests/net/psock_fanout.c +++ b/tools/testing/selftests/net/psock_fanout.c @@ -302,17 +302,22 @@ static void test_control_single(void) } =20 /* Test illegal group with different modes or flags */ -static void test_control_group(void) +static void test_control_group(int toggle) { int fds[2]; =20 - fprintf(stderr, "test: control multiple sockets\n"); + if (toggle) + fprintf(stderr, "test: control multiple sockets with link down toggle\n"= ); + else + fprintf(stderr, "test: control multiple sockets\n"); =20 fds[0] =3D sock_fanout_open(PACKET_FANOUT_HASH, 0); if (fds[0] =3D=3D -1) { fprintf(stderr, "ERROR: failed to open HASH socket\n"); cleanup_and_exit(1); } + if (toggle) + loopback_up_down_toggle(); if (sock_fanout_open(PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG, 0) !=3D -1) { fprintf(stderr, "ERROR: joined group with wrong flag defrag\n"); @@ -332,6 +337,7 @@ static void test_control_group(void) fprintf(stderr, "ERROR: failed to join group\n"); cleanup_and_exit(1); } + loopback_up_down_restore(); if (close(fds[1]) || close(fds[0])) { fprintf(stderr, "ERROR: closing sockets\n"); cleanup_and_exit(1); @@ -527,7 +533,8 @@ int main(int argc, char **argv) int port_off =3D 2, tries =3D 20, ret; =20 test_control_single(); - test_control_group(); + test_control_group(0); + test_control_group(1); test_control_group_max_num_members(); test_unique_fanout_group_ids(); =20 --=20 2.45.2