From patchwork Wed Dec 14 23:25:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 33408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp24831wrn; Wed, 14 Dec 2022 15:31:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf6XB+qD8aVpktwIhDYoXgHKXyQsVvev6gMUxMmDWG9g+X7L6ZSNkfpRVitTdxtA8/q33Nkn X-Received: by 2002:a17:906:4b18:b0:7c0:dac1:ebcf with SMTP id y24-20020a1709064b1800b007c0dac1ebcfmr22282215eju.58.1671060661094; Wed, 14 Dec 2022 15:31:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671060661; cv=none; d=google.com; s=arc-20160816; b=oMHWsRXaKBnur1IBbqSJaNwxQBj0adz6CKOuWDgBxDuKbjJB8PzT72lNlNlkq16vDN f0rtBDNZus5dqgWBYsntJfmc4eUK9DmwYlPMX1CsDjxm2XzMYRDcsoE6qg8qhkBut5/+ lvZWRlkCyt1bic3CvD5UGYzg87Oq9d8DIru7a9MkC8qaCL1SXfcJG6PQa8K58h7iTkGk 1GI4+HDTLqL+jxDtldUIVHUgSRFPnHRjgQNCjQ56l0HqnpbIGX+xNEGcueHjqumfgQ9V puHc+YeeLB+suxTV2BQrDN2+JZPCW1lHBuAJCoCb/UJOFZnFeWF5DGh9cknMIAD80cm5 3dYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=BDuLvltuZiCfQIpl/cg6UT6rVLB+E4UVzC26FRWH+yc=; b=lIIEFiXxMSnkG36CiZdA+cLEqZURx5hvpbmqQQvHIuAcvqRgvIPA673X2rmvqB2alt 2AhbRA5GHMTt6l0BbbDYZwZrbBtjAbYwtCzPkWEsBD9kJEbezXpeizwePTkoVrMNn18E 8/7UEBcJqz4JUnU/dluD/BohzY90z2scQLuGlAx8pqifJsjkglIfoWZjGZgayOVn2q0a DakYldVq/aRu1aqHGT7potsmeY04FEXg7pt9ITx2DHy9lD5+FBpaoZF/vTemgF+2nzmC l/K2GTC81UBgoXhYDtcWlG7KeNnd8QVhFPc6VZO1oxmF8hg0zDb7Gosr7k8092Lj7835 8xIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm1 header.b=v0duqfni; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=cC7kZ9LH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb40-20020a1709077ea800b00781e6ba94ffsi12874766ejc.126.2022.12.14.15.30.15; Wed, 14 Dec 2022 15:31:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm1 header.b=v0duqfni; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=cC7kZ9LH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229798AbiLNX2n (ORCPT + 99 others); Wed, 14 Dec 2022 18:28:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbiLNX2H (ORCPT ); Wed, 14 Dec 2022 18:28:07 -0500 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7453D4A07E; Wed, 14 Dec 2022 15:26:21 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id C0C2932008FD; Wed, 14 Dec 2022 18:26:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 14 Dec 2022 18:26:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1671060379; x=1671146779; bh=BD uLvltuZiCfQIpl/cg6UT6rVLB+E4UVzC26FRWH+yc=; b=v0duqfnizi6TXQq0pv tV0Mtr9tJguGjJjr9lhJDVIsWIjj0l2hEI6imQgrX/wGZDbyGsgRV3LXJqvJ71YG hhNzVPpyVwB3yDcqBWvMPRdfo5EMF/GrGer7yXJGjPaJkOUSlzlCpqRKWbWpKQmJ pOiNkef22a5HuMT072LceBUyShZqIrg4m/yCID8tojqGYpEIqWOKLOkN7QNhqrbQ 8KD8vuqOoBup/9lPXEnj5c/8DsFCf6rkUe3u10a6Xpryg5jMlvEr+7cpF/btxyBb rG+jDWXq87fCgSUCG9afQvVT4KJs8yIBcoQ9pcnLM+S5laneM8MKP1MgwPCg2qbd 8kOg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671060379; x=1671146779; bh=BDuLvltuZiCfQ Ipl/cg6UT6rVLB+E4UVzC26FRWH+yc=; b=cC7kZ9LHhbZsYpHUpfWe/Q7WhbFu3 p/metdPtPy7+iJt71YvXtkl1JIpJLqjBpAseCDlEUUh5dR4KhWcQU9B43rzxFM9h uizLbcpKEh56jf1OBg3ZfQEauFf9YN28c9C89eJux+App++SWYqCh9RM0+OIXXrB 2jjDGGWg2+MBeh8wWo2W4eumqEybjVyC2AC7+szWmIf+N5tsx/XNixMHx1pxhU+k KSVAvIVj9yWdG8ApUE7V9NZcZo7m+ezcdp5qrkc1z2W0KNbH8EgKwZ0F9BaPjKP0 P7mvs+EJegrBg+xADPEi4bw7sF6b60ZDG70ot5rsZjCx/iVBvyKD10kJQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeggddtjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepffgrnhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqeenuc ggtffrrghtthgvrhhnpefgfefggeejhfduieekvdeuteffleeifeeuvdfhheejleejjeek gfffgefhtddtteenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfh hrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 14 Dec 2022 18:26:17 -0500 (EST) From: Daniel Xu To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: ppenkov@aviatrix.com, dbird@aviatrix.com, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 5/6] bpf: selftests: Support custom type and proto for client sockets Date: Wed, 14 Dec 2022 16:25:32 -0700 Message-Id: <892b579588b4985fdae013fc752fa1b2c2315e34.1671049840.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_PDS_OTHER_BAD_TLD autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752234103635256545?= X-GMAIL-MSGID: =?utf-8?q?1752234103635256545?= Extend connect_to_fd_opts() to take optional type and protocol parameters for the client socket. These parameters are useful when opening a raw socket to send IP fragments. Signed-off-by: Daniel Xu --- tools/testing/selftests/bpf/network_helpers.c | 21 +++++++++++++------ tools/testing/selftests/bpf/network_helpers.h | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 24f5efebc7dd..4f9ba90b1b7e 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -270,14 +270,23 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) opts = &default_opts; optlen = sizeof(type); - if (getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &type, &optlen)) { - log_err("getsockopt(SOL_TYPE)"); - return -1; + + if (opts->type) { + type = opts->type; + } else { + if (getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &type, &optlen)) { + log_err("getsockopt(SOL_TYPE)"); + return -1; + } } - if (getsockopt(server_fd, SOL_SOCKET, SO_PROTOCOL, &protocol, &optlen)) { - log_err("getsockopt(SOL_PROTOCOL)"); - return -1; + if (opts->proto) { + protocol = opts->proto; + } else { + if (getsockopt(server_fd, SOL_SOCKET, SO_PROTOCOL, &protocol, &optlen)) { + log_err("getsockopt(SOL_PROTOCOL)"); + return -1; + } } addrlen = sizeof(addr); diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 8be04cd76d8b..7119804ea79b 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -22,6 +22,8 @@ struct network_helper_opts { int timeout_ms; bool must_fail; bool noconnect; + int type; + int proto; }; /* ipv4 test vector */