Skip to content

Commit 07567a5

Browse files
weylanSteve French
authored andcommitted
DNS: Make AFS go to the DNS for AFSDB records for unknown cells
Add DNS query support for AFS so that it can get the IP addresses of Volume Location servers from the DNS using an AFSDB record. This requires userspace support. /etc/request-key.conf must be configured to invoke a helper for dns_resolver type keys with a subtype of "afsdb:" in the description. Signed-off-by: Wang Lei <wang840925@gmail.com> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
1 parent 1a4240f commit 07567a5

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

‎fs/afs/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ config AFS_FS
22
tristate "Andrew File System support (AFS) (EXPERIMENTAL)"
33
depends on INET && EXPERIMENTAL
44
select AF_RXRPC
5+
select DNS_RESOLVER
56
help
67
If you say Y here, you will get an experimental Andrew File System
78
driver. It currently only supports unsecured read-only AFS access.

‎fs/afs/cell.c‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/slab.h>
1414
#include <linux/key.h>
1515
#include <linux/ctype.h>
16+
#include <linux/dns_resolver.h>
1617
#include <linux/sched.h>
1718
#include <keys/rxrpc-type.h>
1819
#include "internal.h"
@@ -36,15 +37,19 @@ static struct afs_cell *afs_cell_alloc(const char *name, char *vllist)
3637
struct key *key;
3738
size_t namelen;
3839
char keyname[4 + AFS_MAXCELLNAME + 1], *cp, *dp, *next;
40+
char *dvllist = NULL, *_vllist = NULL;
41+
char delimiter = ':';
3942
int ret;
4043

4144
_enter("%s,%s", name, vllist);
4245

4346
BUG_ON(!name); /* TODO: want to look up "this cell" in the cache */
4447

4548
namelen = strlen(name);
46-
if (namelen > AFS_MAXCELLNAME)
49+
if (namelen > AFS_MAXCELLNAME) {
50+
_leave(" = -ENAMETOOLONG");
4751
return ERR_PTR(-ENAMETOOLONG);
52+
}
4853

4954
/* allocate and initialise a cell record */
5055
cell = kzalloc(sizeof(struct afs_cell) + namelen + 1, GFP_KERNEL);
@@ -64,15 +69,31 @@ static struct afs_cell *afs_cell_alloc(const char *name, char *vllist)
6469
INIT_LIST_HEAD(&cell->vl_list);
6570
spin_lock_init(&cell->vl_lock);
6671

72+
/* if the ip address is invalid, try dns query */
73+
if (!vllist || strlen(vllist) < 7) {
74+
ret = dns_query("afsdb", name, namelen, "ipv4", &dvllist, NULL);
75+
if (ret < 0) {
76+
_leave(" = %d", ret);
77+
return ERR_PTR(ret);
78+
}
79+
_vllist = dvllist;
80+
81+
/* change the delimiter for user-space reply */
82+
delimiter = ',';
83+
84+
} else {
85+
_vllist = vllist;
86+
}
87+
6788
/* fill in the VL server list from the rest of the string */
6889
do {
6990
unsigned a, b, c, d;
7091

71-
next = strchr(vllist, ':');
92+
next = strchr(_vllist, delimiter);
7293
if (next)
7394
*next++ = 0;
7495

75-
if (sscanf(vllist, "%u.%u.%u.%u", &a, &b, &c, &d) != 4)
96+
if (sscanf(_vllist, "%u.%u.%u.%u", &a, &b, &c, &d) != 4)
7697
goto bad_address;
7798

7899
if (a > 255 || b > 255 || c > 255 || d > 255)
@@ -81,7 +102,7 @@ static struct afs_cell *afs_cell_alloc(const char *name, char *vllist)
81102
cell->vl_addrs[cell->vl_naddrs++].s_addr =
82103
htonl((a << 24) | (b << 16) | (c << 8) | d);
83104

84-
} while (cell->vl_naddrs < AFS_CELL_MAX_ADDRS && (vllist = next));
105+
} while (cell->vl_naddrs < AFS_CELL_MAX_ADDRS && (_vllist = next));
85106

86107
/* create a key to represent an anonymous user */
87108
memcpy(keyname, "afs@", 4);
@@ -110,6 +131,7 @@ static struct afs_cell *afs_cell_alloc(const char *name, char *vllist)
110131
ret = -EINVAL;
111132
error:
112133
key_put(cell->anonymous_key);
134+
kfree(dvllist);
113135
kfree(cell);
114136
_leave(" = %d", ret);
115137
return ERR_PTR(ret);
@@ -201,14 +223,12 @@ int afs_cell_init(char *rootcell)
201223
}
202224

203225
cp = strchr(rootcell, ':');
204-
if (!cp) {
205-
printk(KERN_ERR "kAFS: no VL server IP addresses specified\n");
206-
_leave(" = -EINVAL");
207-
return -EINVAL;
208-
}
226+
if (!cp)
227+
_debug("kAFS: no VL server IP addresses specified");
228+
else
229+
*cp++ = 0;
209230

210231
/* allocate a cell record for the root cell */
211-
*cp++ = 0;
212232
new_root = afs_cell_create(rootcell, cp);
213233
if (IS_ERR(new_root)) {
214234
_leave(" = %ld", PTR_ERR(new_root));

0 commit comments

Comments
 (0)