From patchwork Thu Jul 6 23:25:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 116882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2896630vqx; Thu, 6 Jul 2023 16:28:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlG46pUb/+Qf6UvmgMPMVpae0uR/fmuYcNC6zbdy3LiwnPgZHAfZqQlTPL/C2qE+t/5hTgxL X-Received: by 2002:a05:6a21:328a:b0:12c:efd8:de4c with SMTP id yt10-20020a056a21328a00b0012cefd8de4cmr3090657pzb.18.1688686098893; Thu, 06 Jul 2023 16:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688686098; cv=none; d=google.com; s=arc-20160816; b=Ux04nnTJ1Te09odyV+K414ELpu/kPHNU1t9X6rRoVHNTeukzfOYC8x6N6zfb4ZQyvf jr17ZEdzv/C3TazGsm2WQ/fwWPxYqKy/56zA3VqdHFTsKCVPbPSsn3kcK2VBEVN2O9F8 bVJWzu7FZmDJYNsRaNfFw3mZsEeoLD7iZ/PZu64P88XBVHGXUpxEUfCoQ9NnhzCoMBRs OLzb57XA+WqYJPSUok95nAo4uIiG6d8SLdqL9gv5kdEY6DTdCNO/Zz/A8DQmPuf6QDCk 7wGoXjMtGlErCS9oN6OY5MvbWdWcgGpT/zL++usKUffpi60yazgSqkPKJFPyecVroO8S iCjg== 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=mh2KjQBz6mCJdLiOPKegvHoIrW81ZhsG8oihhV3ETuM=; b=fFSR+ehKvYOn7GKuQB09sBxOXRC7US4FkXqcBBvkU8Q/8Wp1htOw2715blArLiiDpF Q4ug871v9UqKFtG6C+0pSU+JG/bpe1op7H595aRIQOVSmvzC9RfvD40HjcJFG6Pzuj1u 9gGqnxHxyLbeeOj2dYrf5GialDreclzfY5y3vjbf2+Ir3bSuI7KPfvAHJVUhU9hxYGQi 1mSoYmdU2X0jim2vAWtQkZ2x9kGAPWCO+VluAHtry7lKDvv5M4NUYszbt0cll7PjAmFI FUwDMX2bqaUCFLXC0ZQvPDnvMXiESvxOaViYMaKu9TSECnDSPTBqP/PkUWtkHjqXkfiN li9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm1 header.b=qDE8nerL; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Ox7aiC6M; 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 x18-20020a170902ec9200b001b8c6662081si1969732plg.375.2023.07.06.16.28.04; Thu, 06 Jul 2023 16:28:18 -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=qDE8nerL; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Ox7aiC6M; 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 S231912AbjGFX0h (ORCPT + 99 others); Thu, 6 Jul 2023 19:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbjGFX00 (ORCPT ); Thu, 6 Jul 2023 19:26:26 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A4BC1BC9; Thu, 6 Jul 2023 16:26:25 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 043725C00C1; Thu, 6 Jul 2023 19:26:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 06 Jul 2023 19:26:25 -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=1688685985; x= 1688772385; bh=jCzr01pZ2u8uI49LnXSVMw7KSVSfUH7qENNmnpv8K+w=; b=q DE8nerLk1zdCRgbLbcNyLzu/2fSH9WE1z0b0GxZ8SHIjiixreXCpkwPakHgKFlCF 0E6t+Js8uIkuFnolE2Pji7yr4hedGHf6vjMDTZzrtAJgyiLCpTGEdP5a4GVz77He qsjrtPu3Z6JbkBx2FZzl6xny2TPfxfmzKs+GkUQjTquvCqecSPKr0pbmpONPoTQS frbqeZ58i1XmA72AdnfK1xQb+iUBPMSWgsGTqxeoim102ujAbcCO7Kk4c+WMAbT3 7VGcHgSOI+45OcW765VqwHpOCXWEBUgO0sy4GwiT9bwvMRA+BGJE2tzudAqMwQup e6VMRyyEEwtiYB/uy05Jw== 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=1688685985; x= 1688772385; bh=jCzr01pZ2u8uI49LnXSVMw7KSVSfUH7qENNmnpv8K+w=; b=O x7aiC6MDx0+rDHB+9xIAgqkTslsqDkbevuH2G8qZFU0RIwzPztjFJtMwIHxl0RcN iO1QB00iWG/CJkYxCm4IXn4rnENa+mwsY7wEXabcob5EH5Oib/x+UJv442vIv4PJ WKmgQ5162tcmT6D7fdiYXwiXkqYKu5pzQ+nnMh/dCMIQUCOVTwaT8h3qmCfhTEhJ jU+ePAtMAPaI21a41WEXOO/oTCZUx8R6kVQgK8Auphui8KxzI0yLTSHN/zxoCM+N v5S4WdacrWKpDw1P50lL2/HavxiL7cD6wXGYmSsEsAa5c/B3poSRxm33HKrsZCRM g4+j0ZWlEFHhP20XaT3sA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrvddtgddvudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcuoegu gihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpefgfefggeejhfduieekvd euteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 Jul 2023 19:26:23 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, shuah@kernel.org, daniel@iogearbox.net, 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 v2 5/6] bpf: selftests: Support custom type and proto for client sockets Date: Thu, 6 Jul 2023 17:25:52 -0600 Message-ID: <7729886a0e1ae0e07850840a7cd54530b26318d8.1688685338.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,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770715714461743177?= X-GMAIL-MSGID: =?utf-8?q?1770715714461743177?= 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 */