From: Paulo Alcantara <pc@cjr.nz>
To: linux-cifs@vger.kernel.org, piastryyy@gmail.com
Cc: Paulo Alcantara <pc@cjr.nz>
Subject: [PATCH cifs-utils] mount.cifs: handle multiple ip addresses per hostname
Date: Tue, 11 May 2021 13:39:52 -0300 [thread overview]
Message-ID: <20210511163952.11670-1-pc@cjr.nz> (raw)
Support passing multiple 'ip=' options to specify all ip addresses a
server name was resolved to.
Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
---
mount.cifs.c | 44 ++++++++++++++++++++------------------------
mount.cifs.rst | 8 ++++----
2 files changed, 24 insertions(+), 28 deletions(-)
diff --git a/mount.cifs.c b/mount.cifs.c
index 7f898bbd215a..988e56b649a2 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -2036,6 +2036,21 @@ restore_privs:
return rc;
}
+static void set_ip_params(char *options, size_t options_size, char *addrlist)
+{
+ char *s = addrlist + strlen(addrlist), *q = s;
+ char tmp;
+
+ do {
+ for (; s >= addrlist && *s != ','; s--);
+ tmp = *q;
+ *q = '\0';
+ strlcat(options, *options ? ",ip=" : "ip=", options_size);
+ strlcat(options, s + 1, options_size);
+ *q = tmp;
+ } while (q = s--, s >= addrlist);
+}
+
int main(int argc, char **argv)
{
int c;
@@ -2043,7 +2058,6 @@ int main(int argc, char **argv)
char *mountpoint = NULL;
char *options = NULL;
char *orig_dev = NULL;
- char *currentaddress, *nextaddress;
char *value = NULL;
char *ep = NULL;
int rc = 0;
@@ -2201,20 +2215,10 @@ assemble_retry:
goto mount_exit;
}
- currentaddress = parsed_info->addrlist;
- nextaddress = strchr(currentaddress, ',');
- if (nextaddress)
- *nextaddress++ = '\0';
-
mount_retry:
options[0] = '\0';
- if (!currentaddress) {
- fprintf(stderr, "Unable to find suitable address.\n");
- rc = parsed_info->nofail ? 0 : EX_FAIL;
- goto mount_exit;
- }
- strlcpy(options, "ip=", options_size);
- strlcat(options, currentaddress, options_size);
+
+ set_ip_params(options, options_size, parsed_info->addrlist);
strlcat(options, ",unc=\\\\", options_size);
strlcat(options, parsed_info->host, options_size);
@@ -2266,17 +2270,9 @@ mount_retry:
switch (errno) {
case ECONNREFUSED:
case EHOSTUNREACH:
- if (currentaddress) {
- fprintf(stderr, "mount error(%d): could not connect to %s",
- errno, currentaddress);
- }
- currentaddress = nextaddress;
- if (currentaddress) {
- nextaddress = strchr(currentaddress, ',');
- if (nextaddress)
- *nextaddress++ = '\0';
- }
- goto mount_retry;
+ fprintf(stderr, "mount error(%d): could not connect to: %s", errno, parsed_info->addrlist);
+ rc = parsed_info->nofail ? 0 : EX_FAIL;
+ break;
case ENODEV:
fprintf(stderr,
"mount error: %s filesystem not supported by the system\n", cifs_fstype);
diff --git a/mount.cifs.rst b/mount.cifs.rst
index 9d4446f035b6..89fb5c902f79 100644
--- a/mount.cifs.rst
+++ b/mount.cifs.rst
@@ -166,10 +166,10 @@ dir_mode=arg
If the server does not support the CIFS Unix extensions this overrides
the default mode for directories.
-ip=arg|addr=arg
- sets the destination IP address. This option is set automatically if
- the server name portion of the requested UNC name can be resolved so
- rarely needs to be specified by the user.
+ip=arg|addr=arg[,ip=arg2|addr=arg2,...]
+ Sets a maximum number of 16 destination IP addresses. This option is
+ set automatically if the server name portion of the requested UNC
+ name can be resolved so rarely needs to be specified by the user.
domain=arg|dom=arg|workgroup=arg
Sets the domain (workgroup) of the user. If no domains are given,
--
2.31.1
next reply other threads:[~2021-05-11 16:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-11 16:39 Paulo Alcantara [this message]
2021-05-11 17:46 ` [PATCH cifs-utils] mount.cifs: handle multiple ip addresses per hostname Aurélien Aptel
2021-05-11 18:06 ` Steve French
2021-05-11 18:20 ` Paulo Alcantara
2021-07-08 23:00 ` Pavel Shilovsky
2021-07-09 14:50 ` Paulo Alcantara
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=20210511163952.11670-1-pc@cjr.nz \
--to=pc@cjr.nz \
--cc=linux-cifs@vger.kernel.org \
--cc=piastryyy@gmail.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;
as well as URLs for NNTP newsgroup(s).