From patchwork Wed Jul 12 23:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 119439 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1489263vqm; Wed, 12 Jul 2023 16:56:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlE5vFym3LutwWvXwZhYA2KhfRkVJPzloYZaI/uYl7ppLvoq9uPFdfQ6CmJzk0CS/+HHIJQL X-Received: by 2002:aa7:d3ca:0:b0:51d:a012:ec2 with SMTP id o10-20020aa7d3ca000000b0051da0120ec2mr478223edr.3.1689206206881; Wed, 12 Jul 2023 16:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689206206; cv=none; d=google.com; s=arc-20160816; b=dtlXDEBNGq3y/CnXyMgLh6BYZZXL0ZNzjMs+6cGVFvIqqVdOv3S57J3RmUYVlXYbIP dYUo/3tB5pdKjGc9p7zhpsdvqWI7NFlS83gZ9t+/Hf8cBRQnzXlnOyJkNsWvg9bYDK1W 1OpwQRVeDlj0/UxMiK/Wt3/kVifVhCGwqzvE/D6aK2h1vDDyYGthc0GmFPWvLyB9onqb ZYdPTHou9ioRQdMphPFw5eubwLtjcXXjiXzFPwf9k6e2Xeyu8Ak5GlQs/YVOrMVPBk9e R4JGEL3Gr4ldiNyIUXFm6HIJQNg7Xc/Q9uIpjN701PMZuwrMeGPqPGOh637e1w2Q84Zz h9sA== 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=jCzr01pZ2u8uI49LnXSVMw7KSVSfUH7qENNmnpv8K+w=; fh=BaT+O/P/xQ8UA280dO6NBn7Jt/Pk6esaUVk+9EwNMOU=; b=qy437mRogLWzXVdspxcG18ePp3OhBhB0FQXIi5ga344ja5PPmVaTcon8p3C9eI++r2 AjnHXPrBVd1rT9CRBAAOAN877gM2PQJCOu2HyoRjd58HSELFzxiWIIxNqBZfeYUAFYu0 MLqPSe8tc1ZbvXf9raoIX8avdzhNi/XxC8dklM2IC6tji3i4W1yg3fG1UdV7G/rZaEZW SVCnHJHngBPB7R6tdXVkbB7jzaX6iglNahXmTFhBWxNUhDZ7Zr9VD/nDL8QtjhgAkShx QMBIPl0RS7wIic+OAzHAwllw8VNnPfjaV5G60ZviKepcsnif7eUkXraNWj2OkS3FFMvG bHsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm1 header.b=1bPDjgHa; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=nmiiAakA; 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 a20-20020aa7cf14000000b0051fddd077c0si3190085edy.461.2023.07.12.16.56.23; Wed, 12 Jul 2023 16:56:46 -0700 (PDT) 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=1bPDjgHa; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=nmiiAakA; 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 S233283AbjGLXo7 (ORCPT + 99 others); Wed, 12 Jul 2023 19:44:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233265AbjGLXow (ORCPT ); Wed, 12 Jul 2023 19:44:52 -0400 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 653D8211F; Wed, 12 Jul 2023 16:44:44 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 3329B320094D; Wed, 12 Jul 2023 19:44:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 12 Jul 2023 19:44:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type: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=1689205481; x= 1689291881; bh=jCzr01pZ2u8uI49LnXSVMw7KSVSfUH7qENNmnpv8K+w=; b=1 bPDjgHazGZEQ+c+ows2wTY7V33tOSibQdMolPRNEwwHAvcfbYxe+eg/okm8M31/H 8wI8jflCQdMrgnuCimrXzGfwvjIk16oj/cVrpwsjafyN7Nvp+Le1rDpmV6b2TP6M tmHSakCs2R/ibmM9drveZo1B+ppUYQucwPawKgBbgoOHhwAw/KP6NESQFemO8uih f2xdZQ27AK701xr5o4gGmdDUx4qwaKbFJLxJ9ksaeM+Xcrqwx4BNPgEk9xEKgot5 oTZMHPSfgCxZwDmr+7c7Wvy6XVxUkSByN8MsbHFkwxiLdUpTrmZlZPbyc/jlFKMS njIEW/sfQUhME8F3DCbuA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type: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=1689205481; x= 1689291881; bh=jCzr01pZ2u8uI49LnXSVMw7KSVSfUH7qENNmnpv8K+w=; b=n miiAakAvnGENcs76zXufNkCv8xtSSQ92oI2esCbIKZhIQsI9BH9FkdqQ/dn6vbZW yZwsTBUe+jom2wMkNXpqfEd5G8506bPyAnOFLlAurpErsOYFu4O5RRAE9YWDZXQX +trcrZk2f+nmbX1zb5l25GJ04doQ7iQLRiE84WoU/hh+ZJKaRBljAzKy8M2TbIoP OzRiIiWTgJY72Db5v4hGz4Mw1kWwn+bjcbxKPP8vYqySQgufZY0czvrgEED0ozTy VKZRBbYAlL2Ify5qMAbWRfQpHTaeGi6qZ3wqsGt+cyXBR8t2ezxIlsiYzUUIjSvy DYjf5M03kvj/3zywdKoGw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrfeefgddvhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcuoegu gihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpefgfefggeejhfduieekvd euteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Jul 2023 19:44:40 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, daniel@iogearbox.net, ast@kernel.org, shuah@kernel.org, alexei.starovoitov@gmail.com, fw@strlen.de Cc: 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, mykolal@fb.com, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, dsahern@kernel.org Subject: [PATCH bpf-next v4 5/6] bpf: selftests: Support custom type and proto for client sockets Date: Wed, 12 Jul 2023 17:44:00 -0600 Message-ID: <0e39aaed415e84d3a4b096974cd8dac84fbb7b0b.1689203090.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.41.0 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_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1771261087474413135 X-GMAIL-MSGID: 1771261087474413135 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 d5c78c08903b..910d5d0470e6 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 87894dc984dd..5eccc67d1a99 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 */