Skip to content

Commit 1e68b2b

Browse files
jtlaytonSteve French
authored andcommitted
cifs: add new routine for converting AF_INET and AF_INET6 addrs
...to consolidate some logic used in more than one place. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
1 parent 340481a commit 1e68b2b

4 files changed

Lines changed: 38 additions & 40 deletions

File tree

‎fs/cifs/cifsproto.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extern unsigned int smbCalcSize(struct smb_hdr *ptr);
7474
extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
7575
extern int decode_negTokenInit(unsigned char *security_blob, int length,
7676
enum securityEnum *secType);
77-
extern int cifs_inet_pton(const int, const char *source, void *dst);
77+
extern int cifs_convert_address(char *src, void *dst);
7878
extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr);
7979
extern void header_assemble(struct smb_hdr *, char /* command */ ,
8080
const struct cifsTconInfo *, int /* length of

‎fs/cifs/connect.c‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,28 +1433,15 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
14331433

14341434
memset(&addr, 0, sizeof(struct sockaddr_storage));
14351435

1436-
if (volume_info->UNCip && volume_info->UNC) {
1437-
rc = cifs_inet_pton(AF_INET, volume_info->UNCip,
1438-
&sin_server->sin_addr.s_addr);
1439-
1440-
if (rc <= 0) {
1441-
/* not ipv4 address, try ipv6 */
1442-
rc = cifs_inet_pton(AF_INET6, volume_info->UNCip,
1443-
&sin_server6->sin6_addr.in6_u);
1444-
if (rc > 0)
1445-
addr.ss_family = AF_INET6;
1446-
} else {
1447-
addr.ss_family = AF_INET;
1448-
}
1436+
cFYI(1, ("UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip));
14491437

1450-
if (rc <= 0) {
1438+
if (volume_info->UNCip && volume_info->UNC) {
1439+
rc = cifs_convert_address(volume_info->UNCip, &addr);
1440+
if (!rc) {
14511441
/* we failed translating address */
14521442
rc = -EINVAL;
14531443
goto out_err;
14541444
}
1455-
1456-
cFYI(1, ("UNC: %s ip: %s", volume_info->UNC,
1457-
volume_info->UNCip));
14581445
} else if (volume_info->UNCip) {
14591446
/* BB using ip addr as tcp_ses name to connect to the
14601447
DFS root below */

‎fs/cifs/dns_resolve.c‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,9 @@
3737
static int
3838
is_ip(const char *name)
3939
{
40-
int rc;
41-
struct sockaddr_in sin_server;
42-
struct sockaddr_in6 sin_server6;
43-
44-
rc = cifs_inet_pton(AF_INET, name,
45-
&sin_server.sin_addr.s_addr);
46-
47-
if (rc <= 0) {
48-
/* not ipv4 address, try ipv6 */
49-
rc = cifs_inet_pton(AF_INET6, name,
50-
&sin_server6.sin6_addr.in6_u);
51-
if (rc > 0)
52-
return 1;
53-
} else {
54-
return 1;
55-
}
56-
/* we failed translating address */
57-
return 0;
40+
struct sockaddr_storage ss;
41+
42+
return cifs_convert_address(name, &ss);
5843
}
5944

6045
static int

‎fs/cifs/netmisc.c‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ static const struct smb_to_posix_error mapping_table_ERRHRD[] = {
133133
{0, 0}
134134
};
135135

136-
/* Convert string containing dotted ip address to binary form */
137-
/* returns 0 if invalid address */
138-
139-
int
136+
/*
137+
* Convert a string containing text IPv4 or IPv6 address to binary form.
138+
*
139+
* Returns 0 on failure.
140+
*/
141+
static int
140142
cifs_inet_pton(const int address_family, const char *cp, void *dst)
141143
{
142144
int ret = 0;
@@ -153,6 +155,30 @@ cifs_inet_pton(const int address_family, const char *cp, void *dst)
153155
return ret;
154156
}
155157

158+
/*
159+
* Try to convert a string to an IPv4 address and then attempt to convert
160+
* it to an IPv6 address if that fails. Set the family field if either
161+
* succeeds.
162+
*
163+
* Returns 0 on failure.
164+
*/
165+
int
166+
cifs_convert_address(char *src, void *dst)
167+
{
168+
struct sockaddr_in *s4 = (struct sockaddr_in *) dst;
169+
struct sockaddr_in6 *s6 = (Struct sockaddr_in6 *) dst;
170+
171+
if (cifs_inet_pton(AF_INET, src, &s4->sin_addr.s_addr)) {
172+
s4->sin_family = AF_INET;
173+
return 1;
174+
} else if (cifs_inet_pton(AF_INET6, src, &s6->sin6_addr.s6_addr)) {
175+
s6->sin6_family = AF_INET6;
176+
return 1;
177+
}
178+
179+
return 0;
180+
}
181+
156182
/*****************************************************************************
157183
convert a NT status code to a dos class/code
158184
*****************************************************************************/

0 commit comments

Comments
 (0)