Skip to content

Commit

Permalink
CIFS: Simplify ipv*_connect functions into one (try #4)
Browse files Browse the repository at this point in the history
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: Pavel Shilovsky <[email protected]>
Reviewed-and-Tested-by: Jeff Layton <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
piastry authored and Steve French committed Jan 6, 2011
1 parent df8fbc2 commit a9f1b85
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 247 deletions.
16 changes: 9 additions & 7 deletions fs/cifs/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t maxbuf)
{
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;
uint16_t key_len = sizeof(struct cifs_server_key);

Expand All @@ -76,16 +78,16 @@ static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
*/
switch (sa->sa_family) {
case AF_INET:
key->family = server->addr.sockAddr.sin_family;
key->port = server->addr.sockAddr.sin_port;
key->addr[0].ipv4_addr = server->addr.sockAddr.sin_addr;
key->family = sa->sa_family;
key->port = addr->sin_port;
key->addr[0].ipv4_addr = addr->sin_addr;
key_len += sizeof(key->addr[0].ipv4_addr);
break;

case AF_INET6:
key->family = server->addr.sockAddr6.sin6_family;
key->port = server->addr.sockAddr6.sin6_port;
key->addr[0].ipv6_addr = server->addr.sockAddr6.sin6_addr;
key->family = sa->sa_family;
key->port = addr6->sin6_port;
key->addr[0].ipv6_addr = addr6->sin6_addr;
key_len += sizeof(key->addr[0].ipv6_addr);
break;

Expand Down
10 changes: 6 additions & 4 deletions fs/cifs/cifs_spnego.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ struct key *
cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
{
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;
size_t desc_len;
struct key *spnego_key;
Expand Down Expand Up @@ -127,10 +129,10 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
dp = description + strlen(description);

/* add the server address */
if (server->addr.sockAddr.sin_family == AF_INET)
sprintf(dp, "ip4=%pI4", &server->addr.sockAddr.sin_addr);
else if (server->addr.sockAddr.sin_family == AF_INET6)
sprintf(dp, "ip6=%pI6", &server->addr.sockAddr6.sin6_addr);
if (server->dstaddr.ss_family == AF_INET)
sprintf(dp, "ip4=%pI4", &sa->sin_addr);
else if (server->dstaddr.ss_family == AF_INET6)
sprintf(dp, "ip6=%pI6", &sa6->sin6_addr);
else
goto out;

Expand Down
15 changes: 8 additions & 7 deletions fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,19 @@ cifs_evict_inode(struct inode *inode)
static void
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=");

switch (server->addr.sockAddr.sin_family) {
switch (server->dstaddr.ss_family) {
case AF_INET:
seq_printf(s, "%pI4", &server->addr.sockAddr.sin_addr.s_addr);
seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
break;
case AF_INET6:
seq_printf(s, "%pI6",
&server->addr.sockAddr6.sin6_addr.s6_addr);
if (server->addr.sockAddr6.sin6_scope_id)
seq_printf(s, "%%%u",
server->addr.sockAddr6.sin6_scope_id);
seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
if (sa6->sin6_scope_id)
seq_printf(s, "%%%u", sa6->sin6_scope_id);
break;
default:
seq_printf(s, "(unknown)");
Expand Down
5 changes: 1 addition & 4 deletions fs/cifs/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ struct TCP_Server_Info {
char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
char *hostname; /* hostname portion of UNC string */
struct socket *ssocket;
union {
struct sockaddr_in sockAddr;
struct sockaddr_in6 sockAddr6;
} addr;
struct sockaddr_storage dstaddr;
struct sockaddr_storage srcaddr; /* locally bind to this IP */
wait_queue_head_t response_q;
wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
Expand Down
Loading

0 comments on commit a9f1b85

Please sign in to comment.