From: Shyam Prasad N <nspmangalore@gmail.com>
To: linux-cifs@vger.kernel.org, smfrench@gmail.com, pc@cjr.nz,
bharathsm.hsk@gmail.com, tom@talpey.com
Cc: Shyam Prasad N <sprasad@microsoft.com>,
kernel test robot <lkp@intel.com>,
Dan Carpenter <error27@gmail.com>
Subject: [PATCH 6/6] cifs: fix sockaddr comparison in iface_cmp
Date: Fri, 9 Jun 2023 17:46:59 +0000 [thread overview]
Message-ID: <20230609174659.60327-6-sprasad@microsoft.com> (raw)
In-Reply-To: <20230609174659.60327-1-sprasad@microsoft.com>
iface_cmp used to simply do a memcmp of the two
provided struct sockaddrs. The comparison needs to do more
based on the address family. Similar logic was already
present in cifs_match_ipaddr. Doing something similar now.
Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
---
fs/smb/client/cifsglob.h | 37 -----------------------------
fs/smb/client/cifsproto.h | 1 +
fs/smb/client/connect.c | 50 +++++++++++++++++++++++++++++++++++++++
fs/smb/client/smb2ops.c | 37 +++++++++++++++++++++++++++++
4 files changed, 88 insertions(+), 37 deletions(-)
diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index 0d84bb1a8cd9..b212a4e16b39 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -970,43 +970,6 @@ release_iface(struct kref *ref)
kfree(iface);
}
-/*
- * compare two interfaces a and b
- * return 0 if everything matches.
- * return 1 if a has higher link speed, or rdma capable, or rss capable
- * return -1 otherwise.
- */
-static inline int
-iface_cmp(struct cifs_server_iface *a, struct cifs_server_iface *b)
-{
- int cmp_ret = 0;
-
- WARN_ON(!a || !b);
- if (a->speed == b->speed) {
- if (a->rdma_capable == b->rdma_capable) {
- if (a->rss_capable == b->rss_capable) {
- cmp_ret = memcmp(&a->sockaddr, &b->sockaddr,
- sizeof(a->sockaddr));
- if (!cmp_ret)
- return 0;
- else if (cmp_ret > 0)
- return 1;
- else
- return -1;
- } else if (a->rss_capable > b->rss_capable)
- return 1;
- else
- return -1;
- } else if (a->rdma_capable > b->rdma_capable)
- return 1;
- else
- return -1;
- } else if (a->speed > b->speed)
- return 1;
- else
- return -1;
-}
-
struct cifs_chan {
unsigned int in_reconnect : 1; /* if session setup in progress for this channel */
struct TCP_Server_Info *server;
diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h
index c1c704990b98..d127aded2f28 100644
--- a/fs/smb/client/cifsproto.h
+++ b/fs/smb/client/cifsproto.h
@@ -87,6 +87,7 @@ extern int cifs_handle_standard(struct TCP_Server_Info *server,
struct mid_q_entry *mid);
extern int smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx);
extern int smb3_parse_opt(const char *options, const char *key, char **val);
+extern int cifs_ipaddr_cmp(struct sockaddr *srcaddr, struct sockaddr *rhs);
extern bool cifs_match_ipaddr(struct sockaddr *srcaddr, struct sockaddr *rhs);
extern int cifs_discard_remaining_data(struct TCP_Server_Info *server);
extern int cifs_call_async(struct TCP_Server_Info *server,
diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index 1250d156619b..9d16626e7a66 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -1288,6 +1288,56 @@ cifs_demultiplex_thread(void *p)
module_put_and_kthread_exit(0);
}
+int
+cifs_ipaddr_cmp(struct sockaddr *srcaddr, struct sockaddr *rhs)
+{
+ struct sockaddr_in *saddr4 = (struct sockaddr_in *)srcaddr;
+ struct sockaddr_in *vaddr4 = (struct sockaddr_in *)rhs;
+ struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)srcaddr;
+ struct sockaddr_in6 *vaddr6 = (struct sockaddr_in6 *)rhs;
+
+ switch (srcaddr->sa_family) {
+ case AF_UNSPEC:
+ switch (rhs->sa_family) {
+ case AF_UNSPEC:
+ return 0;
+ case AF_INET:
+ case AF_INET6:
+ return 1;
+ default:
+ return -1;
+ }
+ case AF_INET: {
+ switch (rhs->sa_family) {
+ case AF_UNSPEC:
+ return -1;
+ case AF_INET:
+ return memcmp(saddr4, vaddr4,
+ sizeof(struct sockaddr_in));
+ case AF_INET6:
+ return 1;
+ default:
+ return -1;
+ }
+ }
+ case AF_INET6: {
+ switch (rhs->sa_family) {
+ case AF_UNSPEC:
+ case AF_INET:
+ return -1;
+ case AF_INET6:
+ return memcmp(saddr6,
+ vaddr6,
+ sizeof(struct sockaddr_in6));
+ default:
+ return -1;
+ }
+ }
+ default:
+ return -1; /* don't expect to be here */
+ }
+}
+
/*
* Returns true if srcaddr isn't specified and rhs isn't specified, or
* if srcaddr is specified and matches the IP address of the rhs argument
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 18faf267c54d..046341115add 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -513,6 +513,43 @@ smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
return rsize;
}
+/*
+ * compare two interfaces a and b
+ * return 0 if everything matches.
+ * return 1 if a is rdma capable, or rss capable, or has higher link speed
+ * return -1 otherwise.
+ */
+static int
+iface_cmp(struct cifs_server_iface *a, struct cifs_server_iface *b)
+{
+ int cmp_ret = 0;
+
+ WARN_ON(!a || !b);
+ if (a->rdma_capable == b->rdma_capable) {
+ if (a->rss_capable == b->rss_capable) {
+ if (a->speed == b->speed) {
+ cmp_ret = cifs_ipaddr_cmp((struct sockaddr *) &a->sockaddr,
+ (struct sockaddr *) &b->sockaddr);
+ if (!cmp_ret)
+ return 0;
+ else if (cmp_ret > 0)
+ return 1;
+ else
+ return -1;
+ } else if (a->speed > b->speed)
+ return 1;
+ else
+ return -1;
+ } else if (a->rss_capable > b->rss_capable)
+ return 1;
+ else
+ return -1;
+ } else if (a->rdma_capable > b->rdma_capable)
+ return 1;
+ else
+ return -1;
+}
+
static int
parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
size_t buf_len, struct cifs_ses *ses, bool in_mount)
--
2.34.1
next prev parent reply other threads:[~2023-06-09 17:48 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-09 17:46 [PATCH 1/6] cifs: fix status checks in cifs_tree_connect Shyam Prasad N
2023-06-09 17:46 ` [PATCH 2/6] cifs: print all credit counters in DebugData Shyam Prasad N
2023-06-10 19:48 ` Steve French
2023-06-09 17:46 ` [PATCH 3/6] cifs: add a warning when the in-flight count goes negative Shyam Prasad N
2023-06-10 19:49 ` Steve French
2023-06-11 8:01 ` Shyam Prasad N
2023-06-23 16:22 ` Tom Talpey
2023-06-26 6:33 ` Shyam Prasad N
2023-06-27 19:40 ` Tom Talpey
2023-06-09 17:46 ` [PATCH 4/6] cifs: display the endpoint IP details in DebugData Shyam Prasad N
2023-06-09 18:02 ` Enzo Matsumiya
2023-06-11 8:02 ` Shyam Prasad N
2023-06-12 7:59 ` Shyam Prasad N
2023-06-12 7:59 ` Shyam Prasad N
2023-06-12 14:03 ` Enzo Matsumiya
2023-06-12 13:52 ` Enzo Matsumiya
2023-06-12 15:25 ` Paulo Alcantara
2023-06-12 15:29 ` Enzo Matsumiya
2023-06-23 4:21 ` Shyam Prasad N
2023-06-23 15:51 ` Steve French
2023-06-23 15:54 ` Tom Talpey
2023-06-27 12:17 ` Shyam Prasad N
2023-06-28 10:20 ` Shyam Prasad N
2023-06-28 13:39 ` Tom Talpey
2023-06-28 16:24 ` Steve French
2023-06-28 16:51 ` Steve French
2023-06-28 17:07 ` Steve French
2023-06-28 17:11 ` Steve French
2023-06-29 15:35 ` Shyam Prasad N
2023-06-09 17:46 ` [PATCH 5/6] cifs: fix max_credits implementation Shyam Prasad N
2023-06-23 16:00 ` Tom Talpey
2023-06-26 5:40 ` Shyam Prasad N
2023-06-09 17:46 ` Shyam Prasad N [this message]
2023-06-23 16:09 ` [PATCH 6/6] cifs: fix sockaddr comparison in iface_cmp Tom Talpey
2023-06-26 11:12 ` Dan Carpenter
2023-06-27 19:37 ` Tom Talpey
2023-06-10 19:45 ` [PATCH 1/6] cifs: fix status checks in cifs_tree_connect Steve French
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=20230609174659.60327-6-sprasad@microsoft.com \
--to=nspmangalore@gmail.com \
--cc=bharathsm.hsk@gmail.com \
--cc=error27@gmail.com \
--cc=linux-cifs@vger.kernel.org \
--cc=lkp@intel.com \
--cc=pc@cjr.nz \
--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