Commit a9f1b85e authored by Pavel Shilovsky's avatar Pavel Shilovsky Committed by Steve French

CIFS: Simplify ipv*_connect functions into one (try #4)

Make connect logic more ip-protocol independent and move RFC1001 stuff into
a separate function. Also replace union addr in TCP_Server_Info structure
with sockaddr_storage.
Signed-off-by: default avatarPavel Shilovsky <piastryyy@gmail.com>
Reviewed-and-Tested-by: default avatarJeff Layton <jlayton@samba.org>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent df8fbc24
...@@ -64,7 +64,9 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data, ...@@ -64,7 +64,9 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t maxbuf) void *buffer, uint16_t maxbuf)
{ {
const struct TCP_Server_Info *server = cookie_netfs_data; const struct TCP_Server_Info *server = cookie_netfs_data;
const struct sockaddr *sa = (struct sockaddr *) &server->addr.sockAddr; const struct sockaddr *sa = (struct sockaddr *) &server->dstaddr;
const struct sockaddr_in *addr = (struct sockaddr_in *) sa;
const struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) sa;
struct cifs_server_key *key = buffer; struct cifs_server_key *key = buffer;
uint16_t key_len = sizeof(struct cifs_server_key); uint16_t key_len = sizeof(struct cifs_server_key);
...@@ -76,16 +78,16 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data, ...@@ -76,16 +78,16 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
*/ */
switch (sa->sa_family) { switch (sa->sa_family) {
case AF_INET: case AF_INET:
key->family = server->addr.sockAddr.sin_family; key->family = sa->sa_family;
key->port = server->addr.sockAddr.sin_port; key->port = addr->sin_port;
key->addr[0].ipv4_addr = server->addr.sockAddr.sin_addr; key->addr[0].ipv4_addr = addr->sin_addr;
key_len += sizeof(key->addr[0].ipv4_addr); key_len += sizeof(key->addr[0].ipv4_addr);
break; break;
case AF_INET6: case AF_INET6:
key->family = server->addr.sockAddr6.sin6_family; key->family = sa->sa_family;
key->port = server->addr.sockAddr6.sin6_port; key->port = addr6->sin6_port;
key->addr[0].ipv6_addr = server->addr.sockAddr6.sin6_addr; key->addr[0].ipv6_addr = addr6->sin6_addr;
key_len += sizeof(key->addr[0].ipv6_addr); key_len += sizeof(key->addr[0].ipv6_addr);
break; break;
......
...@@ -98,6 +98,8 @@ struct key * ...@@ -98,6 +98,8 @@ struct key *
cifs_get_spnego_key(struct cifsSesInfo *sesInfo) cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
{ {
struct TCP_Server_Info *server = sesInfo->server; struct TCP_Server_Info *server = sesInfo->server;
struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
char *description, *dp; char *description, *dp;
size_t desc_len; size_t desc_len;
struct key *spnego_key; struct key *spnego_key;
...@@ -127,10 +129,10 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo) ...@@ -127,10 +129,10 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
dp = description + strlen(description); dp = description + strlen(description);
/* add the server address */ /* add the server address */
if (server->addr.sockAddr.sin_family == AF_INET) if (server->dstaddr.ss_family == AF_INET)
sprintf(dp, "ip4=%pI4", &server->addr.sockAddr.sin_addr); sprintf(dp, "ip4=%pI4", &sa->sin_addr);
else if (server->addr.sockAddr.sin_family == AF_INET6) else if (server->dstaddr.ss_family == AF_INET6)
sprintf(dp, "ip6=%pI6", &server->addr.sockAddr6.sin6_addr); sprintf(dp, "ip6=%pI6", &sa6->sin6_addr);
else else
goto out; goto out;
......
...@@ -351,18 +351,19 @@ cifs_evict_inode(struct inode *inode) ...@@ -351,18 +351,19 @@ cifs_evict_inode(struct inode *inode)
static void static void
cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server) cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
{ {
struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
seq_printf(s, ",addr="); seq_printf(s, ",addr=");
switch (server->addr.sockAddr.sin_family) { switch (server->dstaddr.ss_family) {
case AF_INET: case AF_INET:
seq_printf(s, "%pI4", &server->addr.sockAddr.sin_addr.s_addr); seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
break; break;
case AF_INET6: case AF_INET6:
seq_printf(s, "%pI6", seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
&server->addr.sockAddr6.sin6_addr.s6_addr); if (sa6->sin6_scope_id)
if (server->addr.sockAddr6.sin6_scope_id) seq_printf(s, "%%%u", sa6->sin6_scope_id);
seq_printf(s, "%%%u",
server->addr.sockAddr6.sin6_scope_id);
break; break;
default: default:
seq_printf(s, "(unknown)"); seq_printf(s, "(unknown)");
......
...@@ -163,10 +163,7 @@ struct TCP_Server_Info { ...@@ -163,10 +163,7 @@ struct TCP_Server_Info {
char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
char *hostname; /* hostname portion of UNC string */ char *hostname; /* hostname portion of UNC string */
struct socket *ssocket; struct socket *ssocket;
union { struct sockaddr_storage dstaddr;
struct sockaddr_in sockAddr;
struct sockaddr_in6 sockAddr6;
} addr;
struct sockaddr_storage srcaddr; /* locally bind to this IP */ struct sockaddr_storage srcaddr; /* locally bind to this IP */
wait_queue_head_t response_q; wait_queue_head_t response_q;
wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/ wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
......
This diff is collapsed.
...@@ -119,7 +119,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) ...@@ -119,7 +119,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
if (ssocket == NULL) if (ssocket == NULL)
return -ENOTSOCK; /* BB eventually add reconnect code here */ return -ENOTSOCK; /* BB eventually add reconnect code here */
smb_msg.msg_name = (struct sockaddr *) &server->addr.sockAddr; smb_msg.msg_name = (struct sockaddr *) &server->dstaddr;
smb_msg.msg_namelen = sizeof(struct sockaddr); smb_msg.msg_namelen = sizeof(struct sockaddr);
smb_msg.msg_control = NULL; smb_msg.msg_control = NULL;
smb_msg.msg_controllen = 0; smb_msg.msg_controllen = 0;
......
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