From patchwork Wed Oct 16 11:48:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 13838242 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D1A7206059 for ; Wed, 16 Oct 2024 11:48:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079302; cv=none; b=Er29FIdSaTT3mrgavILnpdQGs3kJCcuAElbjAz2FT+n4CDXvp4N6ITzpD4HoXNjiiWhO/NRgfwZqdbtsN0T6xboX/YNamb6xtyGrLndEqDr+OpAem38p6jPpj8P8k2Bhu2R+NRXRYN/ywcUBKYWpjS3OS2+07kLDbL7p7IAbsrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079302; c=relaxed/simple; bh=qbvn7cMfkO2c4uTl7WuppgSTQF4OowjoHeHTqoTItGA=; h=Message-ID:Date:MIME-Version:To:From:Subject:Cc:Content-Type; b=NF3LW3iItVlVlwbULfIOC2gthe0PARbN+p0Ama+MGPbnqLS1UjQz7GQw7YRjH5eNwzWJeAYrZlU0l2s3w4fz5zWUG2ZtyDfLgbjW/K6vmK2ZxNXMD3HSgYg7jajKuMY9zVqxR/BFhiy+F2zLKnB9JApJ3A/tf66h6OKWyCKcu8U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lIzDdrDd; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lIzDdrDd" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4311d972e3eso40458705e9.3 for ; Wed, 16 Oct 2024 04:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729079299; x=1729684099; darn=vger.kernel.org; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=uSNgr1NTdLrTqc2CXS2Ctb0rZHZP76JOVZbaS2bCQSQ=; b=lIzDdrDd5Ue4W6WdyU8p+DfpcZtcdvJLmG6RfxCqrjiS11XsMW/wiwrm8Abz6E8k8S rj5Sr+HnpOuHVmNe5L9xcSMtLips6f96Evz/8bWLLWTLc4WLtKDUyKBfctKJgQ67zGCL SC4HZM6l/8jn3EwX3XGFQ3H8oWAFqwtGE0iEqoSANe/hM3vdkkVfdkptncUZCA0nPz2j YVpjbp3J4Smq+smFxAkxYbBeNeKVWBtL43ZphHgaQratXeGSE7L3hypT6rcbhM5x/sEh /W1Dw8+g9BUxsv3k6KdcEuko+uPEkFuIONyD2mLQVKaZk9NmbIkbsVVT+k5dKpZc+LN8 YDqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729079299; x=1729684099; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=uSNgr1NTdLrTqc2CXS2Ctb0rZHZP76JOVZbaS2bCQSQ=; b=qAE37cZrx4cLwnpPq3mYBJEOjGl874BVac3RjWTFRM2URR4n3vlGhA/BHaC7GneSVP eiDZ0FRhvqogIxbGPanSwrA8SSiECmJT9xnpCz9jGjhEdsu6hn7OOfIKGGKp7BJ8XAE8 DmKVi8VZ50RDPYQo+q+BqyF+K/CHBKeoMDzIsmWfsJoVjWWpZq3GuaoByUqlDw7PNHWT 7Esg+eHvHPQ4Q+0IzjBiVaOOltyCnkcUfctqTGgCbOlES3UtwF7ibUJ0DndD9SXDDYNF HR2frD6SxI2YJ9TgVXKlSAk/UGYKI+KcszCmSNxMKinF+NSY97p6xhwsUbAlnxX9tVWD psDg== X-Forwarded-Encrypted: i=1; AJvYcCX/Y378aSQHb5Ij9K5Dj5VSRHnNG8UKV4DprXAMx6qREdtDu7RjL+fJ72Xfl+hi0mjKlnAzdBT9KhI=@vger.kernel.org X-Gm-Message-State: AOJu0YyXYTBsYD8Sdhu6tBmOU8iM800FwBI7NKGaPJ+TevoRWh671mj9 CwEzPvhIHBdaqOwwd+QVpSa4dIg5U1uGUxh+XczZf9HVuF4B6qsY X-Google-Smtp-Source: AGHT+IH0Ufz61rrGsLzM2DBMnTNPuqutjmEPLL4DJoExm6xXpRlKzUNk39EePHSw2ktrkqKuAjbDYQ== X-Received: by 2002:a05:600c:190f:b0:430:53f8:38bc with SMTP id 5b1f17b1804b1-431255dcb76mr115860775e9.12.1729079298559; Wed, 16 Oct 2024 04:48:18 -0700 (PDT) Received: from [0.0.0.0] ([95.179.233.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d7fc445fesm4109430f8f.113.2024.10.16.04.48.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Oct 2024 04:48:18 -0700 (PDT) Message-ID: Date: Wed, 16 Oct 2024 19:48:14 +0800 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: Trond Myklebust , Chuck Lever From: Kinglong Mee Subject: [RFC PATCH 1/5] SUNRPC: reserve space before encode gid Cc: kinglongmee@gmail.com, Linux NFS Mailing List Reserve space must be done before gid encoding. Signed-off-by: Kinglong Mee --- net/sunrpc/auth_unix.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c index 1e091d3fa607..9ef3025682bf 100644 --- a/net/sunrpc/auth_unix.c +++ b/net/sunrpc/auth_unix.c @@ -113,7 +113,7 @@ unx_marshal(struct rpc_task *task, struct xdr_stream *xdr) struct rpc_clnt *clnt = task->tk_client; struct rpc_cred *cred = task->tk_rqstp->rq_cred; __be32 *p, *cred_len, *gidarr_len; - int i; + int i, ngroups; struct group_info *gi = cred->cr_cred->group_info; struct user_namespace *userns = clnt->cl_cred ? clnt->cl_cred->user_ns : &init_user_ns; @@ -136,14 +136,17 @@ unx_marshal(struct rpc_task *task, struct xdr_stream *xdr) *p++ = cpu_to_be32(from_kgid_munged(userns, cred->cr_cred->fsgid)); gidarr_len = p++; - if (gi) - for (i = 0; i < UNX_NGROUPS && i < gi->ngroups; i++) + if (gi && gi->ngroups) { + ngroups = min(UNX_NGROUPS, gi->ngroups); + p = xdr_reserve_space(xdr, ngroups * sizeof(*p)); + if (!p) + goto marshal_failed; + for (i = 0; i < ngroups; i++) *p++ = cpu_to_be32(from_kgid_munged(userns, gi->gid[i])); + } + *gidarr_len = cpu_to_be32(p - gidarr_len - 1); *cred_len = cpu_to_be32((p - cred_len - 1) << 2); - p = xdr_reserve_space(xdr, (p - gidarr_len - 1) << 2); - if (!p) - goto marshal_failed; /* Verifier */ From patchwork Wed Oct 16 11:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 13838243 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B661206059 for ; Wed, 16 Oct 2024 11:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079304; cv=none; b=d8xeAK+Zip8APg2S0Znw8jld2MIF418sdgt2kSEswEQxHWqLGJLbIw4H14vwbnfa/1JmWD5TQQOOaOlWJuU048307Xx3ZBI6qlmh3p0bhPRe1d1xrn8GDgmnMgv4B38IzQss1KmCTcMR6on+r7WYyiB0Hw8+ozOE335QUjpmsa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079304; c=relaxed/simple; bh=eu+25H83fZ3AZJj3Xmuho4Y+d5B4KXdwCNRVXTJBPis=; h=Message-ID:Date:MIME-Version:To:From:Subject:Cc:Content-Type; b=eBYNiKBhEs56VWesIPuoUicpjqk7DSMAiFrpM924dsBbk+4XmloLtvSr/37d7iv/NV7cTTQj9ov6hVVMqGFlGMDOLfhCbXLQATaaIIV6v1J+jregd0dJwswDom9NDRgMUJx0pbn6bfQjfWUwtV5mJZkX0R6EsV2DBzQSpcrh5Qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PftNsVRR; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PftNsVRR" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-37d4ba20075so4288779f8f.0 for ; Wed, 16 Oct 2024 04:48:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729079301; x=1729684101; darn=vger.kernel.org; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=PktEzubkoqqhwuLMCzcaMlIAVvRQ8abKGOIdjgaahjk=; b=PftNsVRRnlkjQ9RHxzj0nar3+LkNc5JJqRz5PTM5iEncpqRjX8e+m1XZKb1kLImYfg AYbBgXJV0napDqZm1YrhHlRpS5W6bpre18SHPdDnRoVG20X6gLP8p/zLlu/ch1tDB1JL fUt9JjYl4768JDFKCdr+3QuVPICveNDYiwbxSRzLyOwBtis2sXL7J2JzCaTTAKMFR3P9 p9AcivlozcenwRmFvussd9LfgPCgeGdg3uls75SPOab678c8n9lRAn5LoMaZcrUy5oqP BsxrsN2Mo7yRienZLI9f3PDu/g3sAHf/jcAEoPMwTmlSmfwDvgZfSR/eS9Pnij51dlei 67MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729079301; x=1729684101; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=PktEzubkoqqhwuLMCzcaMlIAVvRQ8abKGOIdjgaahjk=; b=KPNYG0zPjtpEQDATfdjUcIsZdPhccGXMZ32wIGXFuxb8m1UE31O7fldXi6Mv27L5ci 6XoUhfD9NVXSlXndvUcL0rnTxVmid5NFjiriyJI4e4Si/LFyc0xjlXrYIDJGkwUWjKrR Mdd0d8WbDRL/232P8K5kRL1yS6YjKzhGP1RnWfbNNc+aquzIytjoTRJp9mzW3KiOru6o ShvHzxjRipjZdOmFS9gN9XvLHL+8EVtG/Zz9ht9YNjImMCBKVx98P0xHiN1F0YNcAify F/iqAd8w/LzlVW9VI0ueCidBCUBIV3AHPBZ+uBJF94fymRTU3scVQxPced8pY5VKci0/ xDnQ== X-Forwarded-Encrypted: i=1; AJvYcCXT8PuC/1pqDWltV6gGX6L/nuTlvgUsc9/oRqEeHFecDOTzBRWfrN3ZGUSnrLOK1kZqX9fhsfG2tlo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0dIvTeNxgokdl6mF6tN+CMsRTmQA5C/czji2RkgMaDGmf1Vn9 /p9ZEdiKC4iwQUlP4bncu8E2Ftud8RcJEHvm51KET8/GD+y8GBih X-Google-Smtp-Source: AGHT+IFa4sWXzR7P1MLTlsGnZu3PwAlq0AGf2LnzEx4wXorNLbOPQWrYsHY//h53XEZY0FONcX/KFA== X-Received: by 2002:adf:ea8d:0:b0:37c:d1b6:a261 with SMTP id ffacd0b85a97d-37d55300b05mr12584883f8f.59.1729079301154; Wed, 16 Oct 2024 04:48:21 -0700 (PDT) Received: from [0.0.0.0] ([95.179.233.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d7fc445fesm4109430f8f.113.2024.10.16.04.48.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Oct 2024 04:48:20 -0700 (PDT) Message-ID: <30e0a095-4684-4271-8748-82d1ecd1facf@gmail.com> Date: Wed, 16 Oct 2024 19:48:17 +0800 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: Trond Myklebust , Chuck Lever From: Kinglong Mee Subject: [RFC PATCH 2/5] SUNRPC: move macro for resvport to address header Cc: kinglongmee@gmail.com, Linux NFS Mailing List Signed-off-by: Kinglong Mee --- include/linux/sunrpc/addr.h | 5 +++++ include/linux/sunrpc/xprtsock.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h index 07d454873b6d..f662798c5d83 100644 --- a/include/linux/sunrpc/addr.h +++ b/include/linux/sunrpc/addr.h @@ -13,6 +13,11 @@ #include #include +#define RPC_MIN_RESVPORT (1U) +#define RPC_MAX_RESVPORT (65535U) +#define RPC_DEF_MIN_RESVPORT (665U) +#define RPC_DEF_MAX_RESVPORT (1023U) + size_t rpc_ntop(const struct sockaddr *, char *, const size_t); size_t rpc_pton(struct net *, const char *, const size_t, struct sockaddr *, const size_t); diff --git a/include/linux/sunrpc/xprtsock.h b/include/linux/sunrpc/xprtsock.h index 700a1e6c047c..b627065db7ab 100644 --- a/include/linux/sunrpc/xprtsock.h +++ b/include/linux/sunrpc/xprtsock.h @@ -11,11 +11,6 @@ int init_socket_xprt(void); void cleanup_socket_xprt(void); -#define RPC_MIN_RESVPORT (1U) -#define RPC_MAX_RESVPORT (65535U) -#define RPC_DEF_MIN_RESVPORT (665U) -#define RPC_DEF_MAX_RESVPORT (1023U) - struct sock_xprt { struct rpc_xprt xprt; From patchwork Wed Oct 16 11:48:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 13838244 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EA6A2076DA for ; Wed, 16 Oct 2024 11:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079308; cv=none; b=SYiFx5HTP9vDQy3m/POaytkVZqNZvIonUkX+Q0+i+QzZFC0NExz7LHlNorw82zITf8W8Gqsxrk0AwA3e9Z/sIL6M93ml21DoZp8FUNsgFjxrSCBDtewx93DTW3E9YL/99qtT65/pr6tPnKLKVIvX9P1A+igrf2XqFtYTdbFIZJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079308; c=relaxed/simple; bh=VVTu70tv98puH0c6noYlH+9HzYoP6WKevvtBuIwanU4=; h=Message-ID:Date:MIME-Version:To:From:Subject:Cc:Content-Type; b=LiqMswC4I7R56AF2XDIEWqWwqmOSQucs97UP36KvOpr9/Bv6EnCklcRt9CKPJWWZBxuLIWvvnHr6gYpuHvMVYIHvj9X/IZ3tNhLH2Nb48+x1lyUI/+SIYxLDFtFwoOKYI3LB2Ydhs4SNUfH15Pkkc2bSsnlW+Sd2VCBjVtZ/jo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GObkdPB0; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GObkdPB0" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-37d4a5ecc44so4601220f8f.2 for ; Wed, 16 Oct 2024 04:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729079305; x=1729684105; darn=vger.kernel.org; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=jpwmcC4XdvJxSE1ZsmpIDb2iUQKkONcv1m5Cn51GsXk=; b=GObkdPB0utsM0IdY3KdO/S0ZzqnT+3Ao+IFFhEo6Fbs/7i0hpYcytdCyfOYlRwFhhN +OHWshzhTPlEBaXtZg2Ivo/+a7MuFma7KWejUl43yFP8cjm6xvIblMO/rcm1ZUBkMQ6r pxTnP3uDvmxJ5b/dRmGZSyuaDIM0pKt+1+ePSD9287kfwxHX1ZVArToyT4DCTKtIxtSc 98CDhlfOsTtrKsqlZCdM5L8xLfwqISNKUj3o7MilF5gjJYr36oKewULI4SAPmiphgmtf A9dj2fe09zBvLA3efosU82BjKDpj5kuI6aHVimxhYGB4fGtVk5vZHINQUnuzXFQjaATD of/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729079305; x=1729684105; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=jpwmcC4XdvJxSE1ZsmpIDb2iUQKkONcv1m5Cn51GsXk=; b=S8yCP3EIpei15D5/1vmZp2iOaGpKYmTT1V8KD3XqNfnCsxS410T7h4pMcM47TbE5LZ nLpgJvfmBjrGVudgsiW6KVjhg86wkbmugaoVEoBdRfGv5h2iQV319J+uLytpYvNjlRjb EvB+PTQ9vFndc8kPchrI2Gk9cm4vFZYo+z+BnLQXLsynYgq+fuoB+qPx520CFPkFDMIN hsa49rlB4Ts4I0kCtwmlMgbw8x08TjRIuNbpf3euqfveuAwThTIeJLbflv7Qz7u4WlT2 RYgy7S+tdcw+k67Fu9GmlpDeE3HbFW+ybDKO6rtzbvmQ58e9uUQDv07NBHauwMUgH6+X Hpng== X-Forwarded-Encrypted: i=1; AJvYcCWR0P5RbrgZNnF0WUbFcEaAcO4ep+80NB13QJSswnap6tyYIxLRsWhyLLCbTSOAEh27LIiFsZfA6yc=@vger.kernel.org X-Gm-Message-State: AOJu0YwE9YCCKCjHDslFnB0KFa0Ap2GlKQ9dKH9xHpDEhHNOXpqoWTjY SVcpRZFVy9zAJmwIpbz0K49ql0zep56aGK6FncySgIVytdfpC3fg X-Google-Smtp-Source: AGHT+IG3mpkkFzwTf3IH5MKBzQRzp/zSOc071va3iNsSH4Qzd7MMx/QrEV63RcxWQBFjFqIzAaBNfg== X-Received: by 2002:a5d:63c6:0:b0:37d:45c3:3459 with SMTP id ffacd0b85a97d-37d86bd5846mr2498671f8f.21.1729079304629; Wed, 16 Oct 2024 04:48:24 -0700 (PDT) Received: from [0.0.0.0] ([95.179.233.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d7fc445fesm4109430f8f.113.2024.10.16.04.48.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Oct 2024 04:48:24 -0700 (PDT) Message-ID: Date: Wed, 16 Oct 2024 19:48:22 +0800 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: Trond Myklebust , Chuck Lever From: Kinglong Mee Subject: [RFC PATCH 3/5] SUNRPC: move helper xs_init_anyaddr to rpc_init_anyaddr Cc: kinglongmee@gmail.com, Linux NFS Mailing List Signed-off-by: Kinglong Mee --- include/linux/sunrpc/addr.h | 26 ++++++++++++++++++++++++++ net/sunrpc/xprtsock.c | 29 +---------------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h index f662798c5d83..134450a9fd38 100644 --- a/include/linux/sunrpc/addr.h +++ b/include/linux/sunrpc/addr.h @@ -186,4 +186,30 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa) return ((struct sockaddr_in6 *) sa)->sin6_scope_id; } +static inline int rpc_init_anyaddr(const int family, struct sockaddr *sap) +{ + static const struct sockaddr_in sin = { + .sin_family = AF_INET, + .sin_addr.s_addr = htonl(INADDR_ANY), + }; + static const struct sockaddr_in6 sin6 = { + .sin6_family = AF_INET6, + .sin6_addr = IN6ADDR_ANY_INIT, + }; + + switch (family) { + case AF_LOCAL: + break; + case AF_INET: + memcpy(sap, &sin, sizeof(sin)); + break; + case AF_INET6: + memcpy(sap, &sin6, sizeof(sin6)); + break; + default: + return -EAFNOSUPPORT; + } + return 0; +} + #endif /* _LINUX_SUNRPC_ADDR_H */ diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 0e1691316f42..c4c002fd7333 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -3125,33 +3125,6 @@ static const struct rpc_xprt_ops bc_tcp_ops = { .inject_disconnect = xs_inject_disconnect, }; -static int xs_init_anyaddr(const int family, struct sockaddr *sap) -{ - static const struct sockaddr_in sin = { - .sin_family = AF_INET, - .sin_addr.s_addr = htonl(INADDR_ANY), - }; - static const struct sockaddr_in6 sin6 = { - .sin6_family = AF_INET6, - .sin6_addr = IN6ADDR_ANY_INIT, - }; - - switch (family) { - case AF_LOCAL: - break; - case AF_INET: - memcpy(sap, &sin, sizeof(sin)); - break; - case AF_INET6: - memcpy(sap, &sin6, sizeof(sin6)); - break; - default: - dprintk("RPC: %s: Bad address family\n", __func__); - return -EAFNOSUPPORT; - } - return 0; -} - static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args, unsigned int slot_table_size, unsigned int max_slot_table_size) @@ -3180,7 +3153,7 @@ static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args, memcpy(&new->srcaddr, args->srcaddr, args->addrlen); else { int err; - err = xs_init_anyaddr(args->dstaddr->sa_family, + err = rpc_init_anyaddr(args->dstaddr->sa_family, (struct sockaddr *)&new->srcaddr); if (err != 0) { xprt_free(xprt); From patchwork Wed Oct 16 11:48:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 13838245 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 933E5206059 for ; Wed, 16 Oct 2024 11:48:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079311; cv=none; b=t+r5jIiplPWWY2BEbBceP3PF09/vVsX6Hmq6t989OUa7jXOrYZhG3eOuVV6kw9a2fOlgyvAxxlzMv7J6JhCRqAJCYbPauQBJ1n4Q3fvE81pgI+KOT3ydvfSiThAw88T3VF6c309l3H8UtWPfzpbvoV18U27lxNTOqO5TcSxm08s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079311; c=relaxed/simple; bh=llJ5hAdvdW+foy2VEbHuBB4lSkcaBNNtpJkRTUbUDn0=; h=Message-ID:Date:MIME-Version:To:From:Subject:Cc:Content-Type; b=LMRNVviQzwg4Uh2+F4bTVl7NSpl7yuTqIutbBDjW2TPow6eO7hnVQgFeD/EV0enJFYh34SdBxwULw3cKgab0beQ4QfsRRaPEX4oDE+ZDx0+j5zJwCa+YGb72lnax0/ErNUw5sBdT6hLtkQU5f6NZ+vCmBMxO7XPAx2S4eq8P3q8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H42hVFR4; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H42hVFR4" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-43111cff9d3so49231685e9.1 for ; Wed, 16 Oct 2024 04:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729079308; x=1729684108; darn=vger.kernel.org; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=j29kn8NSBAGoTSCtLUrhbz75yhIUIt6KQzMWUePNXkg=; b=H42hVFR41Oc6Lm0Rtc1lyI3ha0yPrCO5EXBql7QMdDHTOBZy7HwAzUJ0v+w5qSnXYw aTlRpKqk933wD8lrS3LI2MYPLvROQnHPQiHRjcUVOyXhv1fLhSW0ONvJ09GiGjz4Oc1Z MmoKa1OqrRFJ/eLJ3Zakmbi+uZlbp+ofsw/1z8KvXpJd7hvJaAqVClxlWsbhD9Zqi5+K V9d2ucBdEyXIkb967WjD++lxKXUOL0xOuIZiEbBgWKySjpGst7Khqn0hlEi+Jpp4ryAT 0JUOwPLD1G2lulnZuKHkREmShzDYuvGU5KjsW9m4guzXp7xfcG5B/kqM5NTK6b786+wa g1cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729079308; x=1729684108; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=j29kn8NSBAGoTSCtLUrhbz75yhIUIt6KQzMWUePNXkg=; b=ED7zRBP8Rn3LWu2elGO3n1iBE4xM7QKoZQihMvOZGbSoGFG37cx9JGXuWyebpWDk63 2JD4rIJSTzbCdatO6l5SvO+lSPp/46dl3EYQ3CIh1qgqOH+EqccjU/teyJbLY86QkdHw BkAHPFEO4uJiK5O+heiH8WxmGMseFwLzNwCgymG+eomGgZiqNNQC7PLRDalWFs/DHg7m CDUz+/pesJr4HTdnZm/kbrB6EerMnS89SBP3E2zVlOzTacXEM34VixgljryH8FF13/+o p298wmVI68/9+x/75uXrmuCJGxmC+orOQHKmsDJ8m5S8hy/CMqL7S0f2vK24o/gFieML dAFA== X-Forwarded-Encrypted: i=1; AJvYcCVKcIvrk9co66iCDvD6F9fenRLXcTMzcwjKIlkfhV5RnbRrMJQRnBpGmHwfSrbAi6dMx2AqhnWZ2eU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw568YXr8J+i9mLDNYHVB3x4GY4afLYmH6HDX8r3ttrznXgoh27 9UG1mckpbMMGIeF8F10ArEDJWPBWPug86uZEJ0Qw5rMH+mWp0MGI X-Google-Smtp-Source: AGHT+IFTdwjoUp+2xTVTXbX+CEILP1+rgFPT0DaIPiM87hS/MMBvNc7Tx1GU6vKbjmWH3qOZ7XePvA== X-Received: by 2002:a05:600c:1d94:b0:42f:4f6:f8f3 with SMTP id 5b1f17b1804b1-4314a284aacmr32817345e9.7.1729079307494; Wed, 16 Oct 2024 04:48:27 -0700 (PDT) Received: from [0.0.0.0] ([95.179.233.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d7fc445fesm4109430f8f.113.2024.10.16.04.48.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Oct 2024 04:48:27 -0700 (PDT) Message-ID: <1a765211-2d1e-48ef-a5ca-a6b39b833d5a@gmail.com> Date: Wed, 16 Oct 2024 19:48:25 +0800 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: Trond Myklebust , Chuck Lever From: Kinglong Mee Subject: [RFC PATCH 4/5] SUNRPC: support resvport and reuseport for rpcrdma Cc: kinglongmee@gmail.com, Linux NFS Mailing List NFSd's DRC key contains peer port, but rpcrdma does't support port resue now. This patch supports resvport and resueport as tcp/udp for rpcrdma. Signed-off-by: Kinglong Mee --- net/sunrpc/xprtrdma/transport.c | 36 ++++++++++++ net/sunrpc/xprtrdma/verbs.c | 100 ++++++++++++++++++++++++++++++++ net/sunrpc/xprtrdma/xprt_rdma.h | 5 ++ 3 files changed, 141 insertions(+) diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index 9a8ce5df83ca..fee3b562932b 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c @@ -70,6 +70,10 @@ unsigned int xprt_rdma_max_inline_write = RPCRDMA_DEF_INLINE; unsigned int xprt_rdma_memreg_strategy = RPCRDMA_FRWR; int xprt_rdma_pad_optimize; static struct xprt_class xprt_rdma; +static unsigned int xprt_rdma_min_resvport_limit = RPC_MIN_RESVPORT; +static unsigned int xprt_rdma_max_resvport_limit = RPC_MAX_RESVPORT; +unsigned int xprt_rdma_min_resvport = RPC_DEF_MIN_RESVPORT; +unsigned int xprt_rdma_max_resvport = RPC_DEF_MAX_RESVPORT; #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) @@ -137,6 +141,24 @@ static struct ctl_table xr_tunables_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "rdma_min_resvport", + .data = &xprt_rdma_min_resvport, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &xprt_rdma_min_resvport_limit, + .extra2 = &xprt_rdma_max_resvport_limit + }, + { + .procname = "rdma_max_resvport", + .data = &xprt_rdma_max_resvport, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &xprt_rdma_min_resvport_limit, + .extra2 = &xprt_rdma_max_resvport_limit + }, }; #endif @@ -346,6 +368,20 @@ xprt_setup_rdma(struct xprt_create *args) xprt_rdma_format_addresses(xprt, sap); new_xprt = rpcx_to_rdmax(xprt); + + if (args->srcaddr) + memcpy(&new_xprt->rx_srcaddr, args->srcaddr, args->addrlen); + else { + rc = rpc_init_anyaddr(args->dstaddr->sa_family, + (struct sockaddr *)&new_xprt->rx_srcaddr); + if (rc != 0) { + xprt_rdma_free_addresses(xprt); + xprt_free(xprt); + module_put(THIS_MODULE); + return ERR_PTR(rc); + } + } + rc = rpcrdma_buffer_create(new_xprt); if (rc) { xprt_rdma_free_addresses(xprt); diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 63262ef0c2e3..0ce5123d799b 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -285,6 +285,98 @@ static void rpcrdma_ep_removal_done(struct rpcrdma_notification *rn) xprt_force_disconnect(ep->re_xprt); } +static int rpcrdma_get_random_port(void) +{ + unsigned short min = xprt_rdma_min_resvport, max = xprt_rdma_max_resvport; + unsigned short range; + unsigned short rand; + + if (max < min) + return -EADDRINUSE; + range = max - min + 1; + rand = get_random_u32_below(range); + return rand + min; +} + +static void rpcrdma_set_srcport(struct rpcrdma_xprt *r_xprt, struct rdma_cm_id *id) +{ + struct sockaddr *sap = (struct sockaddr *)&id->route.addr.src_addr; + + if (r_xprt->rx_srcport == 0 && r_xprt->rx_xprt.reuseport) { + switch (sap->sa_family) { + case AF_INET6: + r_xprt->rx_srcport = ntohs(((struct sockaddr_in6 *)sap)->sin6_port); + break; + case AF_INET: + r_xprt->rx_srcport = ntohs(((struct sockaddr_in *)sap)->sin_port); + break; + } + } +} + +static int rpcrdma_get_srcport(struct rpcrdma_xprt *r_xprt) +{ + int port = r_xprt->rx_srcport; + + if (port == 0 && r_xprt->rx_xprt.resvport) + port = rpcrdma_get_random_port(); + return port; +} + +static unsigned short rpcrdma_next_srcport(struct rpcrdma_xprt *r_xprt, unsigned short port) +{ + if (r_xprt->rx_srcport != 0) + r_xprt->rx_srcport = 0; + if (!r_xprt->rx_xprt.resvport) + return 0; + if (port <= xprt_rdma_min_resvport || port > xprt_rdma_max_resvport) + return xprt_rdma_max_resvport; + return --port; +} + +static int rpcrdma_bind(struct rpcrdma_xprt *r_xprt, struct rdma_cm_id *id) +{ + struct sockaddr_storage myaddr; + int err, nloop = 0; + int port = rpcrdma_get_srcport(r_xprt); + unsigned short last; + + /* + * If we are asking for any ephemeral port (i.e. port == 0 && + * r_xprt->rx_xprt.resvport == 0), don't bind. Let the local + * port selection happen implicitly when the socket is used + * (for example at connect time). + * + * This ensures that we can continue to establish TCP + * connections even when all local ephemeral ports are already + * a part of some TCP connection. This makes no difference + * for UDP sockets, but also doesn't harm them. + * + * If we're asking for any reserved port (i.e. port == 0 && + * r_xprt->rx_xprt.resvport == 1) rpcrdma_get_srcport above will + * ensure that port is non-zero and we will bind as needed. + */ + if (port <= 0) + return port; + + memcpy(&myaddr, &r_xprt->rx_srcaddr, r_xprt->rx_xprt.addrlen); + do { + rpc_set_port((struct sockaddr *)&myaddr, port); + err = rdma_bind_addr(id, (struct sockaddr *)&myaddr); + if (err == 0) { + if (r_xprt->rx_xprt.reuseport) + r_xprt->rx_srcport = port; + break; + } + last = port; + port = rpcrdma_next_srcport(r_xprt, port); + if (port > last) + nloop++; + } while (err == -EADDRINUSE && nloop != 2); + + return err; +} + static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt, struct rpcrdma_ep *ep) { @@ -300,6 +392,12 @@ static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt, if (IS_ERR(id)) return id; + rc = rpcrdma_bind(r_xprt, id); + if (rc) { + rc = -ENOTCONN; + goto out; + } + ep->re_async_rc = -ETIMEDOUT; rc = rdma_resolve_addr(id, NULL, (struct sockaddr *)&xprt->addr, RDMA_RESOLVE_TIMEOUT); @@ -328,6 +426,8 @@ static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt, if (rc) goto out; + rpcrdma_set_srcport(r_xprt, id); + return id; out: diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h index 8147d2b41494..9c7bcb541267 100644 --- a/net/sunrpc/xprtrdma/xprt_rdma.h +++ b/net/sunrpc/xprtrdma/xprt_rdma.h @@ -433,6 +433,9 @@ struct rpcrdma_xprt { struct delayed_work rx_connect_worker; struct rpc_timeout rx_timeout; struct rpcrdma_stats rx_stats; + + struct sockaddr_storage rx_srcaddr; + unsigned short rx_srcport; }; #define rpcx_to_rdmax(x) container_of(x, struct rpcrdma_xprt, rx_xprt) @@ -581,6 +584,8 @@ static inline void rpcrdma_set_xdrlen(struct xdr_buf *xdr, size_t len) */ extern unsigned int xprt_rdma_max_inline_read; extern unsigned int xprt_rdma_max_inline_write; +extern unsigned int xprt_rdma_min_resvport; +extern unsigned int xprt_rdma_max_resvport; void xprt_rdma_format_addresses(struct rpc_xprt *xprt, struct sockaddr *sap); void xprt_rdma_free_addresses(struct rpc_xprt *xprt); void xprt_rdma_close(struct rpc_xprt *xprt); From patchwork Wed Oct 16 11:48:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 13838246 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11E23204F9E for ; Wed, 16 Oct 2024 11:48:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079315; cv=none; b=ZC35jJ6L/001UomBvMzqNdF517b31j22ZPg48xjG08zuGZDn16QZZuVlM5XhYK2w7bfuc92TeigUCPVPCIo3bTO6vjYk5TTWbENhn+EN4JU/JSDqqEOqHOPJd08Rcl8RPez7ypBgeQFD4WPAV5tuLHE/NBOHWqZB84QgaDDJPiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079315; c=relaxed/simple; bh=lvpVYFs34PepvjpPlaJ5vM18KiAWkvPGmG7W8BaYVqI=; h=Message-ID:Date:MIME-Version:To:From:Subject:Cc:Content-Type; b=To8Zm5ZUv9eAOJgATPtStGrewR6OqIKWUfTexa/D2Gp2iCPxb77plV8yUD28s6mCWoP2pb5UPn8oOLCw7X42N0RL3eV5jgajclKeSOH5A+szuoc17bGGNejAMVfRgjifSdr5wM809qXYZ8UyhqVCsjfdrdymR6WSmFzu2IdB0GY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VFJMihhl; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VFJMihhl" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-37d4fd00574so568726f8f.0 for ; Wed, 16 Oct 2024 04:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729079312; x=1729684112; darn=vger.kernel.org; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=2Y6BqjGpxglIg0aVJLSHzaLYU+Tno0Kqngva9AKJI4k=; b=VFJMihhlrSjgoiiD/fBp3hDhLeO/EJD22IHS6Ys85yCH7/cJNpk19kyWs9yBzgqp9K tb4/wWvQmp7uTrmNxP2liX07EDtM9Kz8HXuJ8gsy6Mj5/MrOd67BJxia7IcJUehH4kgV ALA0uCk+sHJQqk6sFIpjkdsbc0GkuLYmBi0HYl8rEmTlK71gm//8GCPokJdPzjz4CD5f yEoTzfyWDojVSLQC7V13TMW/CQONaJFgP1cvvgxPhkKgVIMHOOXTdJJ0zfGef1s6uFf0 xaAcp1V3MDfTceMXA0+zVFEzkO8fSIDkDSWjxC4XptCM0pMJLVsSM1fxuOfwjqboGfl4 nbbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729079312; x=1729684112; h=content-transfer-encoding:cc:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=2Y6BqjGpxglIg0aVJLSHzaLYU+Tno0Kqngva9AKJI4k=; b=kHqdOhGcJFzEZOlZeJRq6QROp0GNUDXdgNs8FoSeHVlM7mHGst/y4cFUygcJJP7r0u mzDN8v+sySQwvR1SAvxRr8hHKWA7rWV0rfT9jS8lD09kRs8oHqX5QFzlPrLuhxzt9rzH 7p4Sv3i1nxLWLLYrQDzySaiRg/aVFpbmF3rDbUBdre7r/Zcm7BZSiML5++wp3MzrKVsF kvXKrgbY8doPoYSazXEcA5vAhAd/VJpSTG73EJIpPt3M4If8nmdnSo4+BDHiXI4aVdC4 ncEByUK+Xm3YZG2UhiM+nVFIQ4yWIVIRpzvumWPWQTvjj6o8dvK5fQMUO69MudEyLkKd lb0Q== X-Forwarded-Encrypted: i=1; AJvYcCWPI1LGxTNQeThYSzEU+Da+xssg84gXWUajWUevDdLjqwCsA2vyUh+3UiXDlVnG8ILs9BaVgwfwng0=@vger.kernel.org X-Gm-Message-State: AOJu0YxjQEkuNiTbI4KkmjsUECEBRCKsSC+P33Lyy8u0gdMTZbI98VtY 50dHqSUtuCNIL7UOc6hvf9P88JPlXRU+nwp9SPSv3buLEZ4l7m0hgsblNQ== X-Google-Smtp-Source: AGHT+IEjj/RBpz7lsVZPxhUp0WJIZvAw877/n52/xi0IVYfvYevKkZpQ7WRhu664t/rQQax0co9H+w== X-Received: by 2002:a5d:5350:0:b0:37d:2e74:2eea with SMTP id ffacd0b85a97d-37d5519cbd3mr13713854f8f.5.1729079312305; Wed, 16 Oct 2024 04:48:32 -0700 (PDT) Received: from [0.0.0.0] ([95.179.233.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d7fc445fesm4109430f8f.113.2024.10.16.04.48.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Oct 2024 04:48:31 -0700 (PDT) Message-ID: Date: Wed, 16 Oct 2024 19:48:30 +0800 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: Trond Myklebust , Chuck Lever From: Kinglong Mee Subject: [RFC PATCH 5/5] SUNRPC: support get_srcaddr and get_srcport for rpcrdma Cc: kinglongmee@gmail.com, Linux NFS Mailing List Signed-off-by: Kinglong Mee --- net/sunrpc/xprtrdma/transport.c | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index fee3b562932b..e2860632102a 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c @@ -442,6 +442,55 @@ xprt_rdma_set_port(struct rpc_xprt *xprt, u16 port) xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL); } +/** + * xprt_rdma_get_srcaddr - get the rdma local address, without port + * @xprt: controlling RPC transport + * @buf: address buffer + * @buflen: the buffer length + */ +static int +xprt_rdma_get_srcaddr(struct rpc_xprt *xprt, char *buf, size_t buflen) +{ + struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt); + struct rpcrdma_ep *ep = r_xprt->rx_ep; + struct sockaddr *sap; + int ret = -1; + + if (ep && ep->re_id && (ep->re_connect_status == 1)) { + sap = (struct sockaddr *)&ep->re_id->route.addr.src_addr; + ret = snprintf(buf, buflen, "%pISc", sap); + } + + return ret; +} + +/** + * xprt_rdma_get_srcaddr - get the rdma local address, without port + * @xprt: controlling RPC transport + */ +static unsigned short +xprt_rdma_get_srcport(struct rpc_xprt *xprt) +{ + struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt); + struct rpcrdma_ep *ep = r_xprt->rx_ep; + struct sockaddr *sap; + unsigned short ret = 0; + + if (ep && ep->re_id && (ep->re_connect_status == 1)) { + sap = (struct sockaddr *)&ep->re_id->route.addr.src_addr; + switch (sap->sa_family) { + case AF_INET6: + ret = ntohs(((struct sockaddr_in6 *)sap)->sin6_port); + break; + case AF_INET: + ret = ntohs(((struct sockaddr_in *)sap)->sin_port); + break; + } + } + + return ret; +} + /** * xprt_rdma_timer - invoked when an RPC times out * @xprt: controlling RPC transport @@ -768,6 +817,8 @@ static const struct rpc_xprt_ops xprt_rdma_procs = { .rpcbind = rpcb_getport_async, /* sunrpc/rpcb_clnt.c */ .set_port = xprt_rdma_set_port, .connect = xprt_rdma_connect, + .get_srcaddr = xprt_rdma_get_srcaddr, + .get_srcport = xprt_rdma_get_srcport, .buf_alloc = xprt_rdma_allocate, .buf_free = xprt_rdma_free, .send_request = xprt_rdma_send_request,