From patchwork Mon Feb 27 19:51:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 62126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2618111wrd; Mon, 27 Feb 2023 12:04:10 -0800 (PST) X-Google-Smtp-Source: AK7set8JFjuv80w7KXR5CD0cnm5Z3nGfITWFrOf8IE4ilZKfbGIyklLHxUf4bLkG1Pjc7X285H42 X-Received: by 2002:a17:906:374d:b0:878:7189:a457 with SMTP id e13-20020a170906374d00b008787189a457mr37477574ejc.51.1677528250489; Mon, 27 Feb 2023 12:04:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677528250; cv=none; d=google.com; s=arc-20160816; b=1HVdNB8u+3F9sXIwJWETIXf2JUMiiJP8kEOCLzkvXXYi1lcDUtig8Wps1uSiEhJnkN xpYoqhu2dHMtZjuyNQ71bK+zi8y9GtQWvs/vkDwDmj8O7I/HTqoji53tgKPX/xKFGblz aelT/SrTzHSdtl4LRsY4EJmcvIi/BSgFE/2FP1MZSu7blOw3uC6VCYQoWxaM/E9o3SM5 clxje7JJrcj800clHLQA+uto3Ee0or7GGlZer4gJQIX/qB63jCmOQ1LU0OyWIZKE6gtb yiL7phfEcbpXQbTBnTMRU6NRSEYom83y6qhA+CrnBoFHU+uxjlSB90A0veWdip5+wg0+ 9+QQ== 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=pJ73DrAYXIIgt6NXNbsY1qViBhntRO01+UwF0Z/mWJw=; b=hWVCz/YhIAXFjQWHxsL+EFt/r//dt4gW288tbYE8KHN4R9/wU8A6OLXqadHBPB20f2 RPruVjfXP5HHJL9gWmMavYQFVzxohdQjv8zZtUpGCt3Nt5G8Yi2UwD9usNg+mUozl/y4 sFsgg9mm4w+6mcP065mvyQJsuWUyjypVq/TYgocI8HRO/fyJqUqS6HFpDxw6sw3CPigJ 9ygAKS02pHtkTl06up3KERvesp3ogj1+uL309k+2WCTGIwoAqghB9R+1o1AEYcHDRVhj efHhGBjaX2X0L5n7CHLcho2WVr4luykwUBJh25nXPiW+DiPvZw4eMrjisdmaFrZj/ND7 5bjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=MDIPO55u; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=kz+0nHbG; 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 lf15-20020a170906ae4f00b008dfcc758e97si1043356ejb.570.2023.02.27.12.03.27; Mon, 27 Feb 2023 12:04:10 -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=fm3 header.b=MDIPO55u; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=kz+0nHbG; 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 S230395AbjB0Tx0 (ORCPT + 99 others); Mon, 27 Feb 2023 14:53:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbjB0TxK (ORCPT ); Mon, 27 Feb 2023 14:53:10 -0500 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E3B298E2; Mon, 27 Feb 2023 11:52:46 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 4F9D23200955; Mon, 27 Feb 2023 14:52:22 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 27 Feb 2023 14:52:23 -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=fm3; t=1677527541; x=1677613941; bh=pJ 73DrAYXIIgt6NXNbsY1qViBhntRO01+UwF0Z/mWJw=; b=MDIPO55uf1Rb/b4t3e jiFTioMtMkDuBgR4BulVyFNVLTKTzPBqjzkyOB42QBpmAb0736fxW8suE7MzxVQE m166WOWMxdx2ye6ajv33y5v6YOtJUKl4FjT6CDzdYpaxd87+4HZZXY3sgJfNgzKr My7z5vPM1cBZI0GM8V7gQ4RE1K0rzgmBY0arz7EVXp5CetjY1VczIrQIt1tKFWzO Y9T5ElwC4Z9hC4l5T7GMyDlcW6t2JAEncSBIQCMIW390p8BStzUS0kBzryd3dDvZ SAcY/wVzNhEG18P2mfERIn+8ZMuCHhll4PROWinAi0egMClEBSkHM4uqT8FL19eH Mxog== 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=fm1; t=1677527541; x=1677613941; bh=pJ73DrAYXIIgt 6NXNbsY1qViBhntRO01+UwF0Z/mWJw=; b=kz+0nHbGjE2FFDAJ001z+0EeK/zzD DwucsUCmtlowxtidYhNqKQfYSSyBzDvZcDmav5+abm4zUGke1tewTtUoLs7IwGNW PO7DFlNKI2I3DODBUIjW9FRPdwmSkI1WtUGGRD73xUkjrA1n5Aw9KaEhC5WrUTZ+ aAXR2GA6T4qPzWcxdaZjV53lJKBuKJlEtVWlXlSDM4EogrTbk3Nn1f5/QMP4CQEY JcU+DFWKhCAjfQDGLrhcpEhKNuudtSWxvuvkH2e4SD1cVM/KpEvipIWZzq0Pqi/S cM0CnNZjqdnqMsJoHhRAI8tY2PD+Y7zOtJRmHVTQm8SKgQgVanD+dQgog== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudeltddguddviecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephf fvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcu oegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpefgfefggeejhfduie ekvdeuteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 Feb 2023 14:52:20 -0500 (EST) From: Daniel Xu To: andrii@kernel.org, daniel@iogearbox.net, shuah@kernel.org, ast@kernel.org Cc: mykolal@fb.com, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 7/8] bpf: selftests: Support custom type and proto for client sockets Date: Mon, 27 Feb 2023 12:51:09 -0700 Message-Id: <4c74acce194c9896da3c84cbaf6191f3c706845c.1677526810.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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?1759015862789856160?= X-GMAIL-MSGID: =?utf-8?q?1759015862789856160?= 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 */