From: Samuel Cabrero <scabrero@suse.com>
To: linux-cifs@vger.kernel.org
Cc: smfrench@gmail.com, pc@manguebit.com, ronniesahlberg@gmail.com,
sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com,
henrique.carvalho@suse.com, ematsumiya@suse.de,
Samuel Cabrero <scabrero@suse.com>
Subject: [PATCH 10/18] smb:client: Improve tcon matching logic
Date: Fri, 10 Jul 2026 11:16:29 +0200 [thread overview]
Message-ID: <20260710091637.58873-11-scabrero@suse.com> (raw)
In-Reply-To: <20260710091637.58873-1-scabrero@suse.com>
Split the network name and share name checking into their own functions,
and check if these names match only if its associated flag is enabled.
The registration address is always compared.
Signed-off-by: Samuel Cabrero <scabrero@suse.com>
---
fs/smb/client/cifs_swn.c | 117 ++++++++++++++++++++++++---------------
1 file changed, 72 insertions(+), 45 deletions(-)
diff --git a/fs/smb/client/cifs_swn.c b/fs/smb/client/cifs_swn.c
index 0d7e99203281..5728647a1e5d 100644
--- a/fs/smb/client/cifs_swn.c
+++ b/fs/smb/client/cifs_swn.c
@@ -72,13 +72,67 @@ static int cifs_swn_auth_info_ntlm(struct cifs_tcon *tcon, struct sk_buff *skb)
return 0;
}
+static bool cifs_swn_reg_net_name_matches(const struct cifs_swn_reg *swnreg,
+ const struct cifs_tcon *tcon)
+{
+ const char *unc = tcon->tree_name;
+ const char *host, *delim;
+ size_t host_len;
+
+ /* extract hostname, requires strlen(unc) >= 3 (\\a)*/
+ if (strnlen(unc, 3) < 3)
+ return false;
+
+ /* extract_hostname: skip all leading '\' characters */
+ for (host = unc; *host && *host == '\\'; host++)
+ ;
+
+ if (!*host)
+ return false;
+
+ delim = strchr(host, '\\');
+ if (!delim)
+ return false;
+
+ host_len = delim - host;
+ if (strlen(swnreg->net_name) == host_len &&
+ !strncasecmp(swnreg->net_name, host, host_len)) {
+ return true;
+ }
+ return false;
+}
+
+static bool cifs_swn_reg_share_name_matches(const struct cifs_swn_reg *swnreg,
+ const struct cifs_tcon *tcon)
+{
+ const char *unc = tcon->tree_name;
+ const char *share, *delim;
+ size_t share_len;
+
+ /* extract share name, requires strlen(unc) >= 5 (\\a\b) */
+ if (strnlen(unc, 5) < 5)
+ return false;
+
+ /* extract share name, start at unc + 2, then first '\' onward */
+ share = unc + 2;
+ delim = strchr(share, '\\');
+ if (!delim)
+ return false;
+
+ share = delim + 1;
+ share_len = strlen(share);
+
+ if (strlen(swnreg->share_name) == share_len &&
+ !strncasecmp(swnreg->share_name, share, share_len)) {
+ return true;
+ }
+ return false;
+}
+
static bool cifs_swn_reg_tcon_matches(const struct cifs_swn_reg *swnreg,
const struct cifs_tcon *tcon)
{
- const char *unc = tcon->tree_name;
struct sockaddr_storage *tcon_dstaddr;
- const char *host, *share, *delim;
- size_t host_len, share_len;
if (!tcon->use_witness)
return false;
@@ -88,54 +142,27 @@ static bool cifs_swn_reg_tcon_matches(const struct cifs_swn_reg *swnreg,
else
tcon_dstaddr = &tcon->ses->server->dstaddr;
+ /* Address must always match */
if (!cifs_match_ipaddr((struct sockaddr *)&swnreg->addr,
(struct sockaddr *)tcon_dstaddr))
return false;
- if (swnreg->net_name_notify) {
- /* extract hostname, requires strlen(unc) >= 3 (\\a)*/
- if (strnlen(unc, 3) < 3)
- return false;
-
- /* extract_hostname: skip all leading '\' characters */
- for (host = unc; *host && *host == '\\'; host++)
- ;
-
- if (!*host)
- return false;
-
- delim = strchr(host, '\\');
- if (!delim)
- return false;
-
- host_len = delim - host;
- if (strlen(swnreg->net_name) == host_len &&
- !strncasecmp(swnreg->net_name, host, host_len)) {
- return true;
- }
- }
+ /* The network name notification is always enabled */
+ if (!cifs_swn_reg_net_name_matches(swnreg, tcon))
+ return false;
- if (swnreg->share_name_notify) {
- /* extract share name, requires strlen(unc) >= 5 (\\a\b) */
- if (strnlen(unc, 5) < 5)
- return false;
-
- /* extract share name, start at unc + 2, then first '\' onward */
- share = unc + 2;
- delim = strchr(share, '\\');
- if (!delim)
- return false;
-
- share = delim + 1;
- share_len = strlen(share);
-
- if (strlen(swnreg->share_name) == share_len &&
- !strncasecmp(swnreg->share_name, share, share_len)) {
- return true;
- }
- }
+ /*
+ * Share name notifications is enabled only if asymmetric
+ * capability enabled otherwise ignored
+ */
+ if (swnreg->share_name_notify !=
+ (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC))
+ return false;
+ else if (swnreg->share_name_notify &&
+ !cifs_swn_reg_share_name_matches(swnreg, tcon))
+ return false;
- return false;
+ return true;
}
/*
--
2.54.0
next prev parent reply other threads:[~2026-07-10 9:17 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 9:16 [PATCH 00/18] SWN: Decouple witness registrations and tcons Samuel Cabrero
2026-07-10 9:16 ` [PATCH 01/18] Revert "smb: client: resolve SWN tcon from live registrations" Samuel Cabrero
2026-07-10 9:16 ` [PATCH 02/18] smb:client: Adjust witness notification request Samuel Cabrero
2026-07-10 9:16 ` [PATCH 03/18] smb:client: Rename variable to match the rest of the code Samuel Cabrero
2026-07-10 9:16 ` [PATCH 04/18] smb:client: Split idr remove and release functions Samuel Cabrero
2026-07-10 9:16 ` [PATCH 05/18] smb:client: Add a specific task to refresh witness registrations Samuel Cabrero
2026-07-10 9:16 ` [PATCH 06/18] smb:client: Store the tcon dstaddr in the witness registration Samuel Cabrero
2026-07-10 9:16 ` [PATCH 07/18] smb:client: Fix printf format string Samuel Cabrero
2026-07-10 9:16 ` [PATCH 08/18] smb:client: Save memory allocations Samuel Cabrero
2026-07-10 9:16 ` [PATCH 09/18] smb:client: Use the correct return code Samuel Cabrero
2026-07-10 9:16 ` Samuel Cabrero [this message]
2026-07-10 9:16 ` [PATCH 11/18] smb:client: Pass the tcon to cifs_swn_send_register_message Samuel Cabrero
2026-07-10 9:16 ` [PATCH 12/18] smb:client: Pass the tcon to notification handlers Samuel Cabrero
2026-07-10 9:16 ` [PATCH 13/18] smb:client: Introduce swn_notification struct Samuel Cabrero
2026-07-10 9:16 ` [PATCH 14/18] smb:client: Cache auth info Samuel Cabrero
2026-07-10 9:16 ` [PATCH 15/18] smb:client: Do not store the tcon reference, find a matching one Samuel Cabrero
2026-07-10 9:16 ` [PATCH 16/18] smb:client: Simplify registration creation Samuel Cabrero
2026-07-10 9:16 ` [PATCH 17/18] smb:client: Improve registration network and share names handling Samuel Cabrero
2026-07-10 9:16 ` [PATCH 18/18] smb:client: Avoid witness re-register if the address did not change Samuel Cabrero
2026-07-10 14:16 ` [PATCH 00/18] SWN: Decouple witness registrations and tcons Enzo Matsumiya
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260710091637.58873-11-scabrero@suse.com \
--to=scabrero@suse.com \
--cc=bharathsm@microsoft.com \
--cc=ematsumiya@suse.de \
--cc=henrique.carvalho@suse.com \
--cc=linux-cifs@vger.kernel.org \
--cc=pc@manguebit.com \
--cc=ronniesahlberg@gmail.com \
--cc=smfrench@gmail.com \
--cc=sprasad@microsoft.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox