cifs: set the port in sockaddr in a more clearly defined fashion

This patch should replace the patch I sent a couple of weeks ago to
set the port in cifs_convert_address.

Currently we set this in cifs_find_tcp_session, but that's more of a
side effect than anything. Add a new function called cifs_fill_sockaddr.
Have it call cifs_convert_address and then set the port.

This also allows us to skip passing in the port as a separate parm to
cifs_find_tcp_session.

Also, change cifs_convert_address take a struct sockaddr * rather than
void * to make it clearer how this function should be called.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
This commit is contained in:
Jeff Layton 2010-07-06 20:43:01 -04:00 committed by Steve French
parent 488f1d2d6c
commit 50d971602a
4 changed files with 31 additions and 10 deletions

View file

@ -86,7 +86,9 @@ extern unsigned int smbCalcSize(struct smb_hdr *ptr);
extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr); extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
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(char *src, void *dst); extern int cifs_convert_address(struct sockaddr *dst, char *src);
extern int cifs_fill_sockaddr(struct sockaddr *dst, char *src,
unsigned short int port);
extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr); extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr);
extern void header_assemble(struct smb_hdr *, char /* command */ , extern void header_assemble(struct smb_hdr *, char /* command */ ,
const struct cifsTconInfo *, int /* length of const struct cifsTconInfo *, int /* length of

View file

@ -1382,7 +1382,7 @@ cifs_parse_mount_options(char *options, const char *devname,
} }
static struct TCP_Server_Info * static struct TCP_Server_Info *
cifs_find_tcp_session(struct sockaddr_storage *addr, unsigned short int port) cifs_find_tcp_session(struct sockaddr_storage *addr)
{ {
struct list_head *tmp; struct list_head *tmp;
struct TCP_Server_Info *server; struct TCP_Server_Info *server;
@ -1406,7 +1406,6 @@ cifs_find_tcp_session(struct sockaddr_storage *addr, unsigned short int port)
case AF_INET: case AF_INET:
if (addr4->sin_addr.s_addr == if (addr4->sin_addr.s_addr ==
server->addr.sockAddr.sin_addr.s_addr) { server->addr.sockAddr.sin_addr.s_addr) {
addr4->sin_port = htons(port);
/* user overrode default port? */ /* user overrode default port? */
if (addr4->sin_port) { if (addr4->sin_port) {
if (addr4->sin_port != if (addr4->sin_port !=
@ -1422,7 +1421,6 @@ cifs_find_tcp_session(struct sockaddr_storage *addr, unsigned short int port)
&server->addr.sockAddr6.sin6_addr) && &server->addr.sockAddr6.sin6_addr) &&
(addr6->sin6_scope_id == (addr6->sin6_scope_id ==
server->addr.sockAddr6.sin6_scope_id)) { server->addr.sockAddr6.sin6_scope_id)) {
addr6->sin6_port = htons(port);
/* user overrode default port? */ /* user overrode default port? */
if (addr6->sin6_port) { if (addr6->sin6_port) {
if (addr6->sin6_port != if (addr6->sin6_port !=
@ -1482,7 +1480,9 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
cFYI(1, "UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip); cFYI(1, "UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip);
if (volume_info->UNCip && volume_info->UNC) { if (volume_info->UNCip && volume_info->UNC) {
rc = cifs_convert_address(volume_info->UNCip, &addr); rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
volume_info->UNCip,
volume_info->port);
if (!rc) { if (!rc) {
/* we failed translating address */ /* we failed translating address */
rc = -EINVAL; rc = -EINVAL;
@ -1502,7 +1502,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
} }
/* see if we already have a matching tcp_ses */ /* see if we already have a matching tcp_ses */
tcp_ses = cifs_find_tcp_session(&addr, volume_info->port); tcp_ses = cifs_find_tcp_session(&addr);
if (tcp_ses) if (tcp_ses)
return tcp_ses; return tcp_ses;
@ -1546,12 +1546,10 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
cFYI(1, "attempting ipv6 connect"); cFYI(1, "attempting ipv6 connect");
/* BB should we allow ipv6 on port 139? */ /* BB should we allow ipv6 on port 139? */
/* other OS never observed in Wild doing 139 with v6 */ /* other OS never observed in Wild doing 139 with v6 */
sin_server6->sin6_port = htons(volume_info->port);
memcpy(&tcp_ses->addr.sockAddr6, sin_server6, memcpy(&tcp_ses->addr.sockAddr6, sin_server6,
sizeof(struct sockaddr_in6)); sizeof(struct sockaddr_in6));
rc = ipv6_connect(tcp_ses); rc = ipv6_connect(tcp_ses);
} else { } else {
sin_server->sin_port = htons(volume_info->port);
memcpy(&tcp_ses->addr.sockAddr, sin_server, memcpy(&tcp_ses->addr.sockAddr, sin_server,
sizeof(struct sockaddr_in)); sizeof(struct sockaddr_in));
rc = ipv4_connect(tcp_ses); rc = ipv4_connect(tcp_ses);

View file

@ -44,7 +44,7 @@ is_ip(char *name)
{ {
struct sockaddr_storage ss; struct sockaddr_storage ss;
return cifs_convert_address(name, &ss); return cifs_convert_address((struct sockaddr *)&ss, name);
} }
static int static int

View file

@ -164,7 +164,7 @@ cifs_inet_pton(const int address_family, const char *cp, void *dst)
* Returns 0 on failure. * Returns 0 on failure.
*/ */
int int
cifs_convert_address(char *src, void *dst) cifs_convert_address(struct sockaddr *dst, char *src)
{ {
int rc; int rc;
char *pct, *endp; char *pct, *endp;
@ -201,6 +201,27 @@ cifs_convert_address(char *src, void *dst)
return rc; return rc;
} }
int
cifs_fill_sockaddr(struct sockaddr *dst, char *src,
const unsigned short int port)
{
if (!cifs_convert_address(dst, src))
return 0;
switch (dst->sa_family) {
case AF_INET:
((struct sockaddr_in *)dst)->sin_port = htons(port);
break;
case AF_INET6:
((struct sockaddr_in6 *)dst)->sin6_port = htons(port);
break;
default:
return 0;
}
return 1;
}
/***************************************************************************** /*****************************************************************************
convert a NT status code to a dos class/code convert a NT status code to a dos class/code
*****************************************************************************/ *****************************************************************************/