summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorEd Schouten <ed@il.fontys.nl>2004-10-19 18:40:45 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-10-19 18:40:45 -0700
commitfc29938dabf736b88f7f2ae3e18efbb01b1fbcb8 (patch)
treef434f27e58f59d5f3c05bf02a86519525faf6f1b /fs
parent47387472176f51d2f84548a353204029daf6cf91 (diff)
[PATCH] lockd: remove hardcoded maximum NLM cookie length
At the moment, the NLM cookie length is fixed to 8 bytes, while 1024 is the theoretical maximum. FreeBSD uses 16 bytes, Mac OS X uses 20 bytes. Therefore we need to make the length dynamic (which I set to 32 bytes). This patch is based on an old patch for Linux 2.4.23-pre9, which I changed to patch properly (also added some stylish NIPQUAD fixes). From: Neil Brown <neilb@cse.unsw.edu.au> Further lockd tidyups. - NIPQUAD everywhere that is appropriate - use XDR_QUADLEN in more places as appropriate - discard QUADLEN which is a lockd-specific version of XDR_QUADLEN Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/lockd/host.c6
-rw-r--r--fs/lockd/mon.c4
-rw-r--r--fs/lockd/svc4proc.c8
-rw-r--r--fs/lockd/svclock.c16
-rw-r--r--fs/lockd/svcproc.c8
-rw-r--r--fs/lockd/xdr.c49
-rw-r--r--fs/lockd/xdr4.c10
7 files changed, 62 insertions, 39 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index fc4f414a8c5f..54f25ae2ad64 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -104,11 +104,7 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
memset(host, 0, sizeof(*host));
addr = sin->sin_addr.s_addr;
- sprintf(host->h_name, "%d.%d.%d.%d",
- (unsigned char) (ntohl(addr) >> 24),
- (unsigned char) (ntohl(addr) >> 16),
- (unsigned char) (ntohl(addr) >> 8),
- (unsigned char) (ntohl(addr) >> 0));
+ sprintf(host->h_name, "%u.%u.%u.%u", NIPQUAD(addr));
host->h_addr = *sin;
host->h_addr.sin_port = 0; /* ouch! */
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
index de204b36bc34..a9f08284cf2d 100644
--- a/fs/lockd/mon.c
+++ b/fs/lockd/mon.c
@@ -140,7 +140,6 @@ static u32 *
xdr_encode_common(struct rpc_rqst *rqstp, u32 *p, struct nsm_args *argp)
{
char buffer[20];
- u32 addr = ntohl(argp->addr);
/*
* Use the dotted-quad IP address of the remote host as
@@ -148,8 +147,7 @@ xdr_encode_common(struct rpc_rqst *rqstp, u32 *p, struct nsm_args *argp)
* hostname first for whatever remote hostname it receives,
* so this works alright.
*/
- sprintf(buffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
- (addr>>8) & 0xff, (addr) & 0xff);
+ sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(argp->addr));
if (!(p = xdr_encode_string(p, buffer))
|| !(p = xdr_encode_string(p, system_utsname.nodename)))
return ERR_PTR(-EIO);
diff --git a/fs/lockd/svc4proc.c b/fs/lockd/svc4proc.c
index 3afa2659b21d..489670e21769 100644
--- a/fs/lockd/svc4proc.c
+++ b/fs/lockd/svc4proc.c
@@ -546,10 +546,10 @@ struct nlm_void { int dummy; };
.pc_ressize = sizeof(struct nlm_##rest), \
.pc_xdrressize = respsize, \
}
-#define Ck (1+8) /* cookie */
-#define No (1+1024/4) /* netobj */
-#define St 1 /* status */
-#define Rg 4 /* range (offset + length) */
+#define Ck (1+XDR_QUADLEN(NLM_MAXCOOKIELEN)) /* cookie */
+#define No (1+1024/4) /* netobj */
+#define St 1 /* status */
+#define Rg 4 /* range (offset + length) */
struct svc_procedure nlmsvc_procedures4[] = {
PROC(null, void, void, void, void, 1),
PROC(test, testargs, testres, args, res, Ck+St+2+No+Rg),
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 80e7cc4d44a2..de3f50afa424 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -112,11 +112,11 @@ nlmsvc_lookup_block(struct nlm_file *file, struct nlm_lock *lock, int remove)
(long long)lock->fl.fl_end, lock->fl.fl_type);
for (head = &nlm_blocked; (block = *head) != 0; head = &block->b_next) {
fl = &block->b_call.a_args.lock.fl;
- dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%x\n",
+ dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
block->b_file, fl->fl_pid,
(long long)fl->fl_start,
(long long)fl->fl_end, fl->fl_type,
- *(unsigned int*)(block->b_call.a_args.cookie.data));
+ nlmdbg_cookie2a(&block->b_call.a_args.cookie));
if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) {
if (remove) {
*head = block->b_next;
@@ -584,13 +584,13 @@ nlmsvc_grant_callback(struct rpc_task *task)
struct sockaddr_in *peer_addr = RPC_PEERADDR(task->tk_client);
dprintk("lockd: GRANT_MSG RPC callback\n");
- dprintk("callback: looking for cookie %x, host (%08x)\n",
- *(unsigned int *)(call->a_args.cookie.data),
- ntohl(peer_addr->sin_addr.s_addr));
+ dprintk("callback: looking for cookie %s, host (%u.%u.%u.%u)\n",
+ nlmdbg_cookie2a(&call->a_args.cookie),
+ NIPQUAD(peer_addr->sin_addr.s_addr));
if (!(block = nlmsvc_find_block(&call->a_args.cookie, peer_addr))) {
- dprintk("lockd: no block for cookie %x, host (%08x)\n",
- *(u32 *)(call->a_args.cookie.data),
- ntohl(peer_addr->sin_addr.s_addr));
+ dprintk("lockd: no block for cookie %s, host (%u.%u.%u.%u)\n",
+ nlmdbg_cookie2a(&call->a_args.cookie),
+ NIPQUAD(peer_addr->sin_addr.s_addr));
return;
}
diff --git a/fs/lockd/svcproc.c b/fs/lockd/svcproc.c
index 3eca6cfdbdd6..757e344cf200 100644
--- a/fs/lockd/svcproc.c
+++ b/fs/lockd/svcproc.c
@@ -571,10 +571,10 @@ struct nlm_void { int dummy; };
.pc_xdrressize = respsize, \
}
-#define Ck (1+8) /* cookie */
-#define St 1 /* status */
-#define No (1+1024/4) /* Net Obj */
-#define Rg 2 /* range - offset + size */
+#define Ck (1+XDR_QUADLEN(NLM_MAXCOOKIELEN)) /* cookie */
+#define St 1 /* status */
+#define No (1+1024/4) /* Net Obj */
+#define Rg 2 /* range - offset + size */
struct svc_procedure nlmsvc_procedures[] = {
PROC(null, void, void, void, void, 1),
diff --git a/fs/lockd/xdr.c b/fs/lockd/xdr.c
index a76c496a5f0d..f01e9c0d2677 100644
--- a/fs/lockd/xdr.c
+++ b/fs/lockd/xdr.c
@@ -55,16 +55,16 @@ static inline u32 *nlm_decode_cookie(u32 *p, struct nlm_cookie *c)
c->len=4;
memset(c->data, 0, 4); /* hockeypux brain damage */
}
- else if(len<=8)
+ else if(len<=NLM_MAXCOOKIELEN)
{
c->len=len;
memcpy(c->data, p, len);
- p+=(len+3)>>2;
+ p+=XDR_QUADLEN(len);
}
else
{
printk(KERN_NOTICE
- "lockd: bad cookie size %d (only cookies under 8 bytes are supported.)\n", len);
+ "lockd: bad cookie size %d (only cookies under %d bytes are supported.)\n", len, NLM_MAXCOOKIELEN);
return NULL;
}
return p;
@@ -75,7 +75,7 @@ nlm_encode_cookie(u32 *p, struct nlm_cookie *c)
{
*p++ = htonl(c->len);
memcpy(p, c->data, c->len);
- p+=(c->len+3)>>2;
+ p+=XDR_QUADLEN(c->len);
return p;
}
@@ -86,7 +86,7 @@ nlm_decode_fh(u32 *p, struct nfs_fh *f)
if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
printk(KERN_NOTICE
- "lockd: bad fhandle size %x (should be %d)\n",
+ "lockd: bad fhandle size %d (should be %d)\n",
len, NFS2_FHSIZE);
return NULL;
}
@@ -512,11 +512,11 @@ nlmclt_decode_res(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
* Buffer requirements for NLM
*/
#define NLM_void_sz 0
-#define NLM_cookie_sz 3 /* 1 len , 2 data */
-#define NLM_caller_sz 1+QUADLEN(sizeof(system_utsname.nodename))
-#define NLM_netobj_sz 1+QUADLEN(XDR_MAX_NETOBJ)
-/* #define NLM_owner_sz 1+QUADLEN(NLM_MAXOWNER) */
-#define NLM_fhandle_sz 1+QUADLEN(NFS2_FHSIZE)
+#define NLM_cookie_sz 1+XDR_QUADLEN(NLM_MAXCOOKIELEN)
+#define NLM_caller_sz 1+XDR_QUADLEN(sizeof(system_utsname.nodename))
+#define NLM_netobj_sz 1+XDR_QUADLEN(XDR_MAX_NETOBJ)
+/* #define NLM_owner_sz 1+XDR_QUADLEN(NLM_MAXOWNER) */
+#define NLM_fhandle_sz 1+XDR_QUADLEN(NFS2_FHSIZE)
#define NLM_lock_sz 3+NLM_caller_sz+NLM_netobj_sz+NLM_fhandle_sz
#define NLM_holder_sz 4+NLM_netobj_sz
@@ -604,3 +604,32 @@ struct rpc_program nlm_program = {
.stats = &nlm_stats,
};
+#ifdef RPC_DEBUG
+const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
+{
+ /*
+ * We can get away with a static buffer because we're only
+ * called with BKL held.
+ */
+ static char buf[2*NLM_MAXCOOKIELEN+1];
+ int i;
+ int len = sizeof(buf);
+ char *p = buf;
+
+ len--; /* allow for trailing \0 */
+ if (len < 3)
+ return "???";
+ for (i = 0 ; i < cookie->len ; i++) {
+ if (len < 2) {
+ strcpy(p-3, "...");
+ break;
+ }
+ sprintf(p, "%02x", cookie->data[i]);
+ p += 2;
+ len -= 2;
+ }
+ *p = '\0';
+
+ return buf;
+}
+#endif
diff --git a/fs/lockd/xdr4.c b/fs/lockd/xdr4.c
index 10562d31f073..ae4d6b426c62 100644
--- a/fs/lockd/xdr4.c
+++ b/fs/lockd/xdr4.c
@@ -56,16 +56,16 @@ nlm4_decode_cookie(u32 *p, struct nlm_cookie *c)
c->len=4;
memset(c->data, 0, 4); /* hockeypux brain damage */
}
- else if(len<=8)
+ else if(len<=NLM_MAXCOOKIELEN)
{
c->len=len;
memcpy(c->data, p, len);
- p+=(len+3)>>2;
+ p+=XDR_QUADLEN(len);
}
else
{
printk(KERN_NOTICE
- "lockd: bad cookie size %d (only cookies under 8 bytes are supported.)\n", len);
+ "lockd: bad cookie size %d (only cookies under %d bytes are supported.)\n", len, NLM_MAXCOOKIELEN);
return NULL;
}
return p;
@@ -76,7 +76,7 @@ nlm4_encode_cookie(u32 *p, struct nlm_cookie *c)
{
*p++ = htonl(c->len);
memcpy(p, c->data, c->len);
- p+=(c->len+3)>>2;
+ p+=XDR_QUADLEN(c->len);
return p;
}
@@ -515,7 +515,7 @@ nlm4clt_decode_res(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
* Buffer requirements for NLM
*/
#define NLM4_void_sz 0
-#define NLM4_cookie_sz 3 /* 1 len , 2 data */
+#define NLM4_cookie_sz 1+XDR_QUADLEN(NLM_MAXCOOKIELEN)
#define NLM4_caller_sz 1+XDR_QUADLEN(NLM_MAXSTRLEN)
#define NLM4_netobj_sz 1+XDR_QUADLEN(XDR_MAX_NETOBJ)
/* #define NLM4_owner_sz 1+XDR_QUADLEN(NLM4_MAXOWNER) */