Commit b979aaa1 authored by Jeff Layton's avatar Jeff Layton Committed by Steve French

cifs: get rid of smb_vol->UNCip and smb_vol->port

Passing this around as a string is contorted and painful. Instead, just
convert these to a sockaddr as soon as possible, since that's how we're
going to work with it later anyway.
Signed-off-by: default avatarJeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarSteve French <smfrench@gmail.com>
parent ccb5c001
...@@ -394,7 +394,6 @@ struct smb_vol { ...@@ -394,7 +394,6 @@ struct smb_vol {
char *password; char *password;
char *domainname; char *domainname;
char *UNC; char *UNC;
char *UNCip;
char *iocharset; /* local code page for mapping to and from Unicode */ char *iocharset; /* local code page for mapping to and from Unicode */
char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */ char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */ char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
...@@ -442,11 +441,11 @@ struct smb_vol { ...@@ -442,11 +441,11 @@ struct smb_vol {
unsigned int rsize; unsigned int rsize;
unsigned int wsize; unsigned int wsize;
bool sockopt_tcp_nodelay:1; bool sockopt_tcp_nodelay:1;
unsigned short int port;
unsigned long actimeo; /* attribute cache timeout (jiffies) */ unsigned long actimeo; /* attribute cache timeout (jiffies) */
struct smb_version_operations *ops; struct smb_version_operations *ops;
struct smb_version_values *vals; struct smb_version_values *vals;
char *prepath; char *prepath;
struct sockaddr_storage dstaddr; /* destination address */
struct sockaddr_storage srcaddr; /* allow binding to a local IP */ struct sockaddr_storage srcaddr; /* allow binding to a local IP */
struct nls_table *local_nls; struct nls_table *local_nls;
}; };
......
...@@ -110,9 +110,7 @@ extern unsigned int smbCalcSize(void *buf); ...@@ -110,9 +110,7 @@ extern unsigned int smbCalcSize(void *buf);
extern int decode_negTokenInit(unsigned char *security_blob, int length, extern int decode_negTokenInit(unsigned char *security_blob, int length,
struct TCP_Server_Info *server); struct TCP_Server_Info *server);
extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len); extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
extern int cifs_set_port(struct sockaddr *addr, const unsigned short int port); extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port);
extern int cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
const unsigned short int port);
extern int map_smb_to_linux_error(char *buf, bool logErr); extern int map_smb_to_linux_error(char *buf, bool logErr);
extern void header_assemble(struct smb_hdr *, char /* command */ , extern void header_assemble(struct smb_hdr *, char /* command */ ,
const struct cifs_tcon *, int /* length of const struct cifs_tcon *, int /* length of
......
...@@ -1114,6 +1114,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, ...@@ -1114,6 +1114,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
char *string = NULL; char *string = NULL;
char *tmp_end, *value; char *tmp_end, *value;
char delim; char delim;
bool got_ip = false;
unsigned short port = 0;
struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
separator[0] = ','; separator[0] = ',';
separator[1] = 0; separator[1] = 0;
...@@ -1422,12 +1425,12 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, ...@@ -1422,12 +1425,12 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
vol->dir_mode = option; vol->dir_mode = option;
break; break;
case Opt_port: case Opt_port:
if (get_option_ul(args, &option)) { if (get_option_ul(args, &option) ||
cERROR(1, "%s: Invalid port value", option > USHRT_MAX) {
__func__); cERROR(1, "%s: Invalid port value", __func__);
goto cifs_parse_mount_err; goto cifs_parse_mount_err;
} }
vol->port = option; port = (unsigned short)option;
break; break;
case Opt_rsize: case Opt_rsize:
if (get_option_ul(args, &option)) { if (get_option_ul(args, &option)) {
...@@ -1543,25 +1546,21 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, ...@@ -1543,25 +1546,21 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
vol->password[j] = '\0'; vol->password[j] = '\0';
break; break;
case Opt_blank_ip: case Opt_blank_ip:
vol->UNCip = NULL; /* FIXME: should this be an error instead? */
got_ip = false;
break; break;
case Opt_ip: case Opt_ip:
string = match_strdup(args); string = match_strdup(args);
if (string == NULL) if (string == NULL)
goto out_nomem; goto out_nomem;
if (strnlen(string, INET6_ADDRSTRLEN) > if (!cifs_convert_address(dstaddr, string,
INET6_ADDRSTRLEN) { strlen(string))) {
printk(KERN_WARNING "CIFS: ip address " printk(KERN_ERR "CIFS: bad ip= option (%s).\n",
"too long\n"); string);
goto cifs_parse_mount_err;
}
vol->UNCip = kstrdup(string, GFP_KERNEL);
if (!vol->UNCip) {
printk(KERN_WARNING "CIFS: no memory "
"for UNC IP\n");
goto cifs_parse_mount_err; goto cifs_parse_mount_err;
} }
got_ip = true;
break; break;
case Opt_unc: case Opt_unc:
string = match_strdup(args); string = match_strdup(args);
...@@ -1811,8 +1810,18 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, ...@@ -1811,8 +1810,18 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
goto cifs_parse_mount_err; goto cifs_parse_mount_err;
} }
if (vol->UNCip == NULL) if (!got_ip) {
vol->UNCip = &vol->UNC[2]; /* No ip= option specified? Try to get it from UNC */
if (!cifs_convert_address(dstaddr, &vol->UNC[2],
strlen(&vol->UNC[2]))) {
printk(KERN_ERR "Unable to determine destination "
"address.\n");
goto cifs_parse_mount_err;
}
}
/* set the port that we got earlier */
cifs_set_port(dstaddr, port);
if (uid_specified) if (uid_specified)
vol->override_uid = override_uid; vol->override_uid = override_uid;
...@@ -2062,29 +2071,13 @@ static struct TCP_Server_Info * ...@@ -2062,29 +2071,13 @@ static struct TCP_Server_Info *
cifs_get_tcp_session(struct smb_vol *volume_info) cifs_get_tcp_session(struct smb_vol *volume_info)
{ {
struct TCP_Server_Info *tcp_ses = NULL; struct TCP_Server_Info *tcp_ses = NULL;
struct sockaddr_storage addr; struct sockaddr *dstaddr = (struct sockaddr *)&volume_info->dstaddr;
struct sockaddr_in *sin_server = (struct sockaddr_in *) &addr;
struct sockaddr_in6 *sin_server6 = (struct sockaddr_in6 *) &addr;
int rc; int rc;
memset(&addr, 0, sizeof(struct sockaddr_storage)); cFYI(1, "UNC: %s", volume_info->UNC);
cFYI(1, "UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip);
if (volume_info->UNCip && volume_info->UNC) {
rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
volume_info->UNCip,
strlen(volume_info->UNCip),
volume_info->port);
if (!rc) {
/* we failed translating address */
rc = -EINVAL;
goto out_err;
}
}
/* see if we already have a matching tcp_ses */ /* see if we already have a matching tcp_ses */
tcp_ses = cifs_find_tcp_session((struct sockaddr *)&addr, volume_info); tcp_ses = cifs_find_tcp_session(dstaddr, volume_info);
if (tcp_ses) if (tcp_ses)
return tcp_ses; return tcp_ses;
...@@ -2140,15 +2133,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) ...@@ -2140,15 +2133,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
sizeof(tcp_ses->srcaddr)); sizeof(tcp_ses->srcaddr));
++tcp_ses->srv_count; ++tcp_ses->srv_count;
if (addr.ss_family == AF_INET6) { memcpy(&tcp_ses->dstaddr, dstaddr, sizeof(tcp_ses->dstaddr));
cFYI(1, "attempting ipv6 connect");
/* BB should we allow ipv6 on port 139? */
/* other OS never observed in Wild doing 139 with v6 */
memcpy(&tcp_ses->dstaddr, sin_server6,
sizeof(struct sockaddr_in6));
} else
memcpy(&tcp_ses->dstaddr, sin_server,
sizeof(struct sockaddr_in));
rc = ip_connect(tcp_ses); rc = ip_connect(tcp_ses);
if (rc < 0) { if (rc < 0) {
...@@ -2708,11 +2693,9 @@ cifs_match_super(struct super_block *sb, void *data) ...@@ -2708,11 +2693,9 @@ cifs_match_super(struct super_block *sb, void *data)
struct cifs_ses *ses; struct cifs_ses *ses;
struct cifs_tcon *tcon; struct cifs_tcon *tcon;
struct tcon_link *tlink; struct tcon_link *tlink;
struct sockaddr_storage addr; struct sockaddr *dstaddr;
int rc = 0; int rc = 0;
memset(&addr, 0, sizeof(struct sockaddr_storage));
spin_lock(&cifs_tcp_ses_lock); spin_lock(&cifs_tcp_ses_lock);
cifs_sb = CIFS_SB(sb); cifs_sb = CIFS_SB(sb);
tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb)); tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb));
...@@ -2725,15 +2708,9 @@ cifs_match_super(struct super_block *sb, void *data) ...@@ -2725,15 +2708,9 @@ cifs_match_super(struct super_block *sb, void *data)
tcp_srv = ses->server; tcp_srv = ses->server;
volume_info = mnt_data->vol; volume_info = mnt_data->vol;
dstaddr = (struct sockaddr *)&volume_info->dstaddr;
rc = cifs_fill_sockaddr((struct sockaddr *)&addr, if (!match_server(tcp_srv, dstaddr, volume_info) ||
volume_info->UNCip,
strlen(volume_info->UNCip),
volume_info->port);
if (!rc)
goto out;
if (!match_server(tcp_srv, (struct sockaddr *)&addr, volume_info) ||
!match_session(ses, volume_info) || !match_session(ses, volume_info) ||
!match_tcon(tcon, volume_info->UNC)) { !match_tcon(tcon, volume_info->UNC)) {
rc = 0; rc = 0;
...@@ -3248,8 +3225,6 @@ cleanup_volume_info_contents(struct smb_vol *volume_info) ...@@ -3248,8 +3225,6 @@ cleanup_volume_info_contents(struct smb_vol *volume_info)
{ {
kfree(volume_info->username); kfree(volume_info->username);
kzfree(volume_info->password); kzfree(volume_info->password);
if (volume_info->UNCip != volume_info->UNC + 2)
kfree(volume_info->UNCip);
kfree(volume_info->UNC); kfree(volume_info->UNC);
kfree(volume_info->domainname); kfree(volume_info->domainname);
kfree(volume_info->iocharset); kfree(volume_info->iocharset);
......
...@@ -204,7 +204,7 @@ cifs_convert_address(struct sockaddr *dst, const char *src, int len) ...@@ -204,7 +204,7 @@ cifs_convert_address(struct sockaddr *dst, const char *src, int len)
return rc; return rc;
} }
int void
cifs_set_port(struct sockaddr *addr, const unsigned short int port) cifs_set_port(struct sockaddr *addr, const unsigned short int port)
{ {
switch (addr->sa_family) { switch (addr->sa_family) {
...@@ -214,19 +214,7 @@ cifs_set_port(struct sockaddr *addr, const unsigned short int port) ...@@ -214,19 +214,7 @@ cifs_set_port(struct sockaddr *addr, const unsigned short int port)
case AF_INET6: case AF_INET6:
((struct sockaddr_in6 *)addr)->sin6_port = htons(port); ((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
break; break;
default:
return 0;
} }
return 1;
}
int
cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
const unsigned short int port)
{
if (!cifs_convert_address(dst, src, len))
return 0;
return cifs_set_port(dst, port);
} }
/***************************************************************************** /*****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment