aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/svcauth_unix.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2006-03-27 04:15:02 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-03-27 11:44:42 -0500
commit1a9917c2da5b81fa536e560be0c431435e2c965b (patch)
tree2dbbaeb55277887122409a4c396db2eba750fd59 /net/sunrpc/svcauth_unix.c
parent15a5f6bd23eddd5b3be80366f364be04fb1c1c99 (diff)
[PATCH] knfsd: Convert ip_map cache to use the new lookup routine
Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'net/sunrpc/svcauth_unix.c')
-rw-r--r--net/sunrpc/svcauth_unix.c142
1 files changed, 95 insertions, 47 deletions
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 7ddf068b5b25..7e38621a20b7 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -106,28 +106,38 @@ static inline int hash_ip(unsigned long ip)
106 return (hash ^ (hash>>8)) & 0xff; 106 return (hash ^ (hash>>8)) & 0xff;
107} 107}
108#endif 108#endif
109 109static int ip_map_match(struct cache_head *corig, struct cache_head *cnew)
110static inline int ip_map_hash(struct ip_map *item)
111{
112 return hash_str(item->m_class, IP_HASHBITS) ^
113 hash_ip((unsigned long)item->m_addr.s_addr);
114}
115static inline int ip_map_match(struct ip_map *item, struct ip_map *tmp)
116{ 110{
117 return strcmp(tmp->m_class, item->m_class) == 0 111 struct ip_map *orig = container_of(corig, struct ip_map, h);
118 && tmp->m_addr.s_addr == item->m_addr.s_addr; 112 struct ip_map *new = container_of(cnew, struct ip_map, h);
113 return strcmp(orig->m_class, new->m_class) == 0
114 && orig->m_addr.s_addr == new->m_addr.s_addr;
119} 115}
120static inline void ip_map_init(struct ip_map *new, struct ip_map *item) 116static void ip_map_init(struct cache_head *cnew, struct cache_head *citem)
121{ 117{
118 struct ip_map *new = container_of(cnew, struct ip_map, h);
119 struct ip_map *item = container_of(citem, struct ip_map, h);
120
122 strcpy(new->m_class, item->m_class); 121 strcpy(new->m_class, item->m_class);
123 new->m_addr.s_addr = item->m_addr.s_addr; 122 new->m_addr.s_addr = item->m_addr.s_addr;
124} 123}
125static inline void ip_map_update(struct ip_map *new, struct ip_map *item) 124static void update(struct cache_head *cnew, struct cache_head *citem)
126{ 125{
126 struct ip_map *new = container_of(cnew, struct ip_map, h);
127 struct ip_map *item = container_of(citem, struct ip_map, h);
128
127 kref_get(&item->m_client->h.ref); 129 kref_get(&item->m_client->h.ref);
128 new->m_client = item->m_client; 130 new->m_client = item->m_client;
129 new->m_add_change = item->m_add_change; 131 new->m_add_change = item->m_add_change;
130} 132}
133static struct cache_head *ip_map_alloc(void)
134{
135 struct ip_map *i = kmalloc(sizeof(*i), GFP_KERNEL);
136 if (i)
137 return &i->h;
138 else
139 return NULL;
140}
131 141
132static void ip_map_request(struct cache_detail *cd, 142static void ip_map_request(struct cache_detail *cd,
133 struct cache_head *h, 143 struct cache_head *h,
@@ -148,7 +158,8 @@ static void ip_map_request(struct cache_detail *cd,
148 (*bpp)[-1] = '\n'; 158 (*bpp)[-1] = '\n';
149} 159}
150 160
151static struct ip_map *ip_map_lookup(struct ip_map *, int); 161static struct ip_map *ip_map_lookup(char *class, struct in_addr addr);
162static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry);
152 163
153static int ip_map_parse(struct cache_detail *cd, 164static int ip_map_parse(struct cache_detail *cd,
154 char *mesg, int mlen) 165 char *mesg, int mlen)
@@ -160,7 +171,11 @@ static int ip_map_parse(struct cache_detail *cd,
160 int len; 171 int len;
161 int b1,b2,b3,b4; 172 int b1,b2,b3,b4;
162 char c; 173 char c;
163 struct ip_map ipm, *ipmp; 174 char class[8];
175 struct in_addr addr;
176 int err;
177
178 struct ip_map *ipmp;
164 struct auth_domain *dom; 179 struct auth_domain *dom;
165 time_t expiry; 180 time_t expiry;
166 181
@@ -169,7 +184,7 @@ static int ip_map_parse(struct cache_detail *cd,
169 mesg[mlen-1] = 0; 184 mesg[mlen-1] = 0;
170 185
171 /* class */ 186 /* class */
172 len = qword_get(&mesg, ipm.m_class, sizeof(ipm.m_class)); 187 len = qword_get(&mesg, class, sizeof(class));
173 if (len <= 0) return -EINVAL; 188 if (len <= 0) return -EINVAL;
174 189
175 /* ip address */ 190 /* ip address */
@@ -194,25 +209,22 @@ static int ip_map_parse(struct cache_detail *cd,
194 } else 209 } else
195 dom = NULL; 210 dom = NULL;
196 211
197 ipm.m_addr.s_addr = 212 addr.s_addr =
198 htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4); 213 htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4);
199 ipm.h.flags = 0; 214
200 if (dom) { 215 ipmp = ip_map_lookup(class,addr);
201 ipm.m_client = container_of(dom, struct unix_domain, h); 216 if (ipmp) {
202 ipm.m_add_change = ipm.m_client->addr_changes; 217 err = ip_map_update(ipmp,
218 container_of(dom, struct unix_domain, h),
219 expiry);
203 } else 220 } else
204 set_bit(CACHE_NEGATIVE, &ipm.h.flags); 221 err = -ENOMEM;
205 ipm.h.expiry_time = expiry;
206 222
207 ipmp = ip_map_lookup(&ipm, 1);
208 if (ipmp)
209 ip_map_put(&ipmp->h, &ip_map_cache);
210 if (dom) 223 if (dom)
211 auth_domain_put(dom); 224 auth_domain_put(dom);
212 if (!ipmp) 225
213 return -ENOMEM;
214 cache_flush(); 226 cache_flush();
215 return 0; 227 return err;
216} 228}
217 229
218static int ip_map_show(struct seq_file *m, 230static int ip_map_show(struct seq_file *m,
@@ -256,32 +268,70 @@ struct cache_detail ip_map_cache = {
256 .cache_request = ip_map_request, 268 .cache_request = ip_map_request,
257 .cache_parse = ip_map_parse, 269 .cache_parse = ip_map_parse,
258 .cache_show = ip_map_show, 270 .cache_show = ip_map_show,
271 .match = ip_map_match,
272 .init = ip_map_init,
273 .update = update,
274 .alloc = ip_map_alloc,
259}; 275};
260 276
261static DefineSimpleCacheLookup(ip_map, ip_map) 277static struct ip_map *ip_map_lookup(char *class, struct in_addr addr)
278{
279 struct ip_map ip;
280 struct cache_head *ch;
281
282 strcpy(ip.m_class, class);
283 ip.m_addr = addr;
284 ch = sunrpc_cache_lookup(&ip_map_cache, &ip.h,
285 hash_str(class, IP_HASHBITS) ^
286 hash_ip((unsigned long)addr.s_addr));
287
288 if (ch)
289 return container_of(ch, struct ip_map, h);
290 else
291 return NULL;
292}
262 293
294static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry)
295{
296 struct ip_map ip;
297 struct cache_head *ch;
298
299 ip.m_client = udom;
300 ip.h.flags = 0;
301 if (!udom)
302 set_bit(CACHE_NEGATIVE, &ip.h.flags);
303 else {
304 ip.m_add_change = udom->addr_changes;
305 /* if this is from the legacy set_client system call,
306 * we need m_add_change to be one higher
307 */
308 if (expiry == NEVER)
309 ip.m_add_change++;
310 }
311 ip.h.expiry_time = expiry;
312 ch = sunrpc_cache_update(&ip_map_cache,
313 &ip.h, &ipm->h,
314 hash_str(ipm->m_class, IP_HASHBITS) ^
315 hash_ip((unsigned long)ipm->m_addr.s_addr));
316 if (!ch)
317 return -ENOMEM;
318 ip_map_put(ch, &ip_map_cache);
319 return 0;
320}
263 321
264int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom) 322int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom)
265{ 323{
266 struct unix_domain *udom; 324 struct unix_domain *udom;
267 struct ip_map ip, *ipmp; 325 struct ip_map *ipmp;
268 326
269 if (dom->flavour != &svcauth_unix) 327 if (dom->flavour != &svcauth_unix)
270 return -EINVAL; 328 return -EINVAL;
271 udom = container_of(dom, struct unix_domain, h); 329 udom = container_of(dom, struct unix_domain, h);
272 strcpy(ip.m_class, "nfsd"); 330 ipmp = ip_map_lookup("nfsd", addr);
273 ip.m_addr = addr;
274 ip.m_client = udom;
275 ip.m_add_change = udom->addr_changes+1;
276 ip.h.flags = 0;
277 ip.h.expiry_time = NEVER;
278
279 ipmp = ip_map_lookup(&ip, 1);
280 331
281 if (ipmp) { 332 if (ipmp)
282 ip_map_put(&ipmp->h, &ip_map_cache); 333 return ip_map_update(ipmp, udom, NEVER);
283 return 0; 334 else
284 } else
285 return -ENOMEM; 335 return -ENOMEM;
286} 336}
287 337
@@ -304,7 +354,7 @@ struct auth_domain *auth_unix_lookup(struct in_addr addr)
304 strcpy(key.m_class, "nfsd"); 354 strcpy(key.m_class, "nfsd");
305 key.m_addr = addr; 355 key.m_addr = addr;
306 356
307 ipm = ip_map_lookup(&key, 0); 357 ipm = ip_map_lookup("nfsd", addr);
308 358
309 if (!ipm) 359 if (!ipm)
310 return NULL; 360 return NULL;
@@ -331,16 +381,14 @@ void svcauth_unix_purge(void)
331static int 381static int
332svcauth_unix_set_client(struct svc_rqst *rqstp) 382svcauth_unix_set_client(struct svc_rqst *rqstp)
333{ 383{
334 struct ip_map key, *ipm; 384 struct ip_map *ipm;
335 385
336 rqstp->rq_client = NULL; 386 rqstp->rq_client = NULL;
337 if (rqstp->rq_proc == 0) 387 if (rqstp->rq_proc == 0)
338 return SVC_OK; 388 return SVC_OK;
339 389
340 strcpy(key.m_class, rqstp->rq_server->sv_program->pg_class); 390 ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class,
341 key.m_addr = rqstp->rq_addr.sin_addr; 391 rqstp->rq_addr.sin_addr);
342
343 ipm = ip_map_lookup(&key, 0);
344 392
345 if (ipm == NULL) 393 if (ipm == NULL)
346 return SVC_DENIED; 394 return SVC_DENIED;