cell.c (4e73e0eb633f8a1b5cbf20e7f42c6dbfec1d1ca7) cell.c (07567a5509327bcbf2c867286eb1524447c9b954)
1/* AFS cell and server record management
2 *
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/key.h>
15#include <linux/ctype.h>
1/* AFS cell and server record management
2 *
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/key.h>
15#include <linux/ctype.h>
16#include <linux/dns_resolver.h>
16#include <linux/sched.h>
17#include <keys/rxrpc-type.h>
18#include "internal.h"
19
20DECLARE_RWSEM(afs_proc_cells_sem);
21LIST_HEAD(afs_proc_cells);
22
23static LIST_HEAD(afs_cells);

--- 7 unchanged lines hidden (view full) ---

31 * allocate an anonymous key
32 */
33static struct afs_cell *afs_cell_alloc(const char *name, char *vllist)
34{
35 struct afs_cell *cell;
36 struct key *key;
37 size_t namelen;
38 char keyname[4 + AFS_MAXCELLNAME + 1], *cp, *dp, *next;
17#include <linux/sched.h>
18#include <keys/rxrpc-type.h>
19#include "internal.h"
20
21DECLARE_RWSEM(afs_proc_cells_sem);
22LIST_HEAD(afs_proc_cells);
23
24static LIST_HEAD(afs_cells);

--- 7 unchanged lines hidden (view full) ---

32 * allocate an anonymous key
33 */
34static struct afs_cell *afs_cell_alloc(const char *name, char *vllist)
35{
36 struct afs_cell *cell;
37 struct key *key;
38 size_t namelen;
39 char keyname[4 + AFS_MAXCELLNAME + 1], *cp, *dp, *next;
40 char *dvllist = NULL, *_vllist = NULL;
41 char delimiter = ':';
39 int ret;
40
41 _enter("%s,%s", name, vllist);
42
43 BUG_ON(!name); /* TODO: want to look up "this cell" in the cache */
44
45 namelen = strlen(name);
42 int ret;
43
44 _enter("%s,%s", name, vllist);
45
46 BUG_ON(!name); /* TODO: want to look up "this cell" in the cache */
47
48 namelen = strlen(name);
46 if (namelen > AFS_MAXCELLNAME)
49 if (namelen > AFS_MAXCELLNAME) {
50 _leave(" = -ENAMETOOLONG");
47 return ERR_PTR(-ENAMETOOLONG);
51 return ERR_PTR(-ENAMETOOLONG);
52 }
48
49 /* allocate and initialise a cell record */
50 cell = kzalloc(sizeof(struct afs_cell) + namelen + 1, GFP_KERNEL);
51 if (!cell) {
52 _leave(" = -ENOMEM");
53 return ERR_PTR(-ENOMEM);
54 }
55
56 memcpy(cell->name, name, namelen);
57 cell->name[namelen] = 0;
58
59 atomic_set(&cell->usage, 1);
60 INIT_LIST_HEAD(&cell->link);
61 rwlock_init(&cell->servers_lock);
62 INIT_LIST_HEAD(&cell->servers);
63 init_rwsem(&cell->vl_sem);
64 INIT_LIST_HEAD(&cell->vl_list);
65 spin_lock_init(&cell->vl_lock);
66
53
54 /* allocate and initialise a cell record */
55 cell = kzalloc(sizeof(struct afs_cell) + namelen + 1, GFP_KERNEL);
56 if (!cell) {
57 _leave(" = -ENOMEM");
58 return ERR_PTR(-ENOMEM);
59 }
60
61 memcpy(cell->name, name, namelen);
62 cell->name[namelen] = 0;
63
64 atomic_set(&cell->usage, 1);
65 INIT_LIST_HEAD(&cell->link);
66 rwlock_init(&cell->servers_lock);
67 INIT_LIST_HEAD(&cell->servers);
68 init_rwsem(&cell->vl_sem);
69 INIT_LIST_HEAD(&cell->vl_list);
70 spin_lock_init(&cell->vl_lock);
71
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
67 /* fill in the VL server list from the rest of the string */
68 do {
69 unsigned a, b, c, d;
70
88 /* fill in the VL server list from the rest of the string */
89 do {
90 unsigned a, b, c, d;
91
71 next = strchr(vllist, ':');
92 next = strchr(_vllist, delimiter);
72 if (next)
73 *next++ = 0;
74
93 if (next)
94 *next++ = 0;
95
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)
76 goto bad_address;
77
78 if (a > 255 || b > 255 || c > 255 || d > 255)
79 goto bad_address;
80
81 cell->vl_addrs[cell->vl_naddrs++].s_addr =
82 htonl((a << 24) | (b << 16) | (c << 8) | d);
83
97 goto bad_address;
98
99 if (a > 255 || b > 255 || c > 255 || d > 255)
100 goto bad_address;
101
102 cell->vl_addrs[cell->vl_naddrs++].s_addr =
103 htonl((a << 24) | (b << 16) | (c << 8) | d);
104
84 } while (cell->vl_naddrs < AFS_CELL_MAX_ADDRS && (vllist = next));
105 } while (cell->vl_naddrs < AFS_CELL_MAX_ADDRS && (_vllist = next));
85
86 /* create a key to represent an anonymous user */
87 memcpy(keyname, "afs@", 4);
88 dp = keyname + 4;
89 cp = cell->name;
90 do {
91 *dp++ = toupper(*cp);
92 } while (*cp++);

--- 12 unchanged lines hidden (view full) ---

105 _leave(" = %p", cell);
106 return cell;
107
108bad_address:
109 printk(KERN_ERR "kAFS: bad VL server IP address\n");
110 ret = -EINVAL;
111error:
112 key_put(cell->anonymous_key);
106
107 /* create a key to represent an anonymous user */
108 memcpy(keyname, "afs@", 4);
109 dp = keyname + 4;
110 cp = cell->name;
111 do {
112 *dp++ = toupper(*cp);
113 } while (*cp++);

--- 12 unchanged lines hidden (view full) ---

126 _leave(" = %p", cell);
127 return cell;
128
129bad_address:
130 printk(KERN_ERR "kAFS: bad VL server IP address\n");
131 ret = -EINVAL;
132error:
133 key_put(cell->anonymous_key);
134 kfree(dvllist);
113 kfree(cell);
114 _leave(" = %d", ret);
115 return ERR_PTR(ret);
116}
117
118/*
119 * create a cell record
120 * - "name" is the name of the cell

--- 75 unchanged lines hidden (view full) ---

196 /* module is loaded with no parameters, or built statically.
197 * - in the future we might initialize cell DB here.
198 */
199 _leave(" = 0 [no root]");
200 return 0;
201 }
202
203 cp = strchr(rootcell, ':');
135 kfree(cell);
136 _leave(" = %d", ret);
137 return ERR_PTR(ret);
138}
139
140/*
141 * create a cell record
142 * - "name" is the name of the cell

--- 75 unchanged lines hidden (view full) ---

218 /* module is loaded with no parameters, or built statically.
219 * - in the future we might initialize cell DB here.
220 */
221 _leave(" = 0 [no root]");
222 return 0;
223 }
224
225 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;
209
210 /* allocate a cell record for the root cell */
230
231 /* allocate a cell record for the root cell */
211 *cp++ = 0;
212 new_root = afs_cell_create(rootcell, cp);
213 if (IS_ERR(new_root)) {
214 _leave(" = %ld", PTR_ERR(new_root));
215 return PTR_ERR(new_root);
216 }
217
218 /* install the new cell */
219 write_lock(&afs_cells_lock);

--- 193 unchanged lines hidden ---
232 new_root = afs_cell_create(rootcell, cp);
233 if (IS_ERR(new_root)) {
234 _leave(" = %ld", PTR_ERR(new_root));
235 return PTR_ERR(new_root);
236 }
237
238 /* install the new cell */
239 write_lock(&afs_cells_lock);

--- 193 unchanged lines hidden ---