Commit ad06e4bd62351bc569cca0f25d68c58dbd298146
Committed by
Linus Torvalds
1 parent
1ba951053f
Exists in
master
and in
7 other branches
[PATCH] knfsd: SUNRPC: Add a function to format the address in an svc_rqst for printing
There are loads of places where the RPC server assumes that the rq_addr fields contains an IPv4 address. Top among these are error and debugging messages that display the server's IP address. Let's refactor the address printing into a separate function that's smart enough to figure out the difference between IPv4 and IPv6 addresses. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Cc: Aurelien Charbon <aurelien.charbon@ext.bull.net> Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 8 changed files with 86 additions and 39 deletions Side-by-side Diff
fs/lockd/svc.c
... | ... | @@ -141,6 +141,7 @@ |
141 | 141 | */ |
142 | 142 | while ((nlmsvc_users || !signalled()) && nlmsvc_pid == current->pid) { |
143 | 143 | long timeout = MAX_SCHEDULE_TIMEOUT; |
144 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
144 | 145 | |
145 | 146 | if (signalled()) { |
146 | 147 | flush_signals(current); |
147 | 148 | |
... | ... | @@ -175,11 +176,10 @@ |
175 | 176 | break; |
176 | 177 | } |
177 | 178 | |
178 | - dprintk("lockd: request from %08x\n", | |
179 | - (unsigned)ntohl(rqstp->rq_addr.sin_addr.s_addr)); | |
179 | + dprintk("lockd: request from %s\n", | |
180 | + svc_print_addr(rqstp, buf, sizeof(buf))); | |
180 | 181 | |
181 | 182 | svc_process(rqstp); |
182 | - | |
183 | 183 | } |
184 | 184 | |
185 | 185 | flush_signals(current); |
fs/lockd/svc4proc.c
... | ... | @@ -426,10 +426,9 @@ |
426 | 426 | dprintk("lockd: SM_NOTIFY called\n"); |
427 | 427 | if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK) |
428 | 428 | || ntohs(saddr.sin_port) >= 1024) { |
429 | - printk(KERN_WARNING | |
430 | - "lockd: rejected NSM callback from %08x:%d\n", | |
431 | - ntohl(rqstp->rq_addr.sin_addr.s_addr), | |
432 | - ntohs(rqstp->rq_addr.sin_port)); | |
429 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
430 | + printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", | |
431 | + svc_print_addr(rqstp, buf, sizeof(buf))); | |
433 | 432 | return rpc_system_err; |
434 | 433 | } |
435 | 434 |
fs/lockd/svcproc.c
... | ... | @@ -457,10 +457,9 @@ |
457 | 457 | dprintk("lockd: SM_NOTIFY called\n"); |
458 | 458 | if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK) |
459 | 459 | || ntohs(saddr.sin_port) >= 1024) { |
460 | - printk(KERN_WARNING | |
461 | - "lockd: rejected NSM callback from %08x:%d\n", | |
462 | - ntohl(rqstp->rq_addr.sin_addr.s_addr), | |
463 | - ntohs(rqstp->rq_addr.sin_port)); | |
460 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
461 | + printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", | |
462 | + svc_print_addr(rqstp, buf, sizeof(buf))); | |
464 | 463 | return rpc_system_err; |
465 | 464 | } |
466 | 465 |
fs/nfs/callback.c
... | ... | @@ -71,6 +71,8 @@ |
71 | 71 | complete(&nfs_callback_info.started); |
72 | 72 | |
73 | 73 | for(;;) { |
74 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
75 | + | |
74 | 76 | if (signalled()) { |
75 | 77 | if (nfs_callback_info.users == 0) |
76 | 78 | break; |
... | ... | @@ -88,8 +90,8 @@ |
88 | 90 | __FUNCTION__, -err); |
89 | 91 | break; |
90 | 92 | } |
91 | - dprintk("%s: request from %u.%u.%u.%u\n", __FUNCTION__, | |
92 | - NIPQUAD(rqstp->rq_addr.sin_addr.s_addr)); | |
93 | + dprintk("%s: request from %s\n", __FUNCTION__, | |
94 | + svc_print_addr(rqstp, buf, sizeof(buf))); | |
93 | 95 | svc_process(rqstp); |
94 | 96 | } |
95 | 97 | |
96 | 98 | |
97 | 99 | |
... | ... | @@ -166,13 +168,17 @@ |
166 | 168 | { |
167 | 169 | struct sockaddr_in *addr = &rqstp->rq_addr; |
168 | 170 | struct nfs_client *clp; |
171 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
169 | 172 | |
170 | 173 | /* Don't talk to strangers */ |
171 | 174 | clp = nfs_find_client(addr, 4); |
172 | 175 | if (clp == NULL) |
173 | 176 | return SVC_DROP; |
174 | - dprintk("%s: %u.%u.%u.%u NFSv4 callback!\n", __FUNCTION__, NIPQUAD(addr->sin_addr)); | |
177 | + | |
178 | + dprintk("%s: %s NFSv4 callback!\n", __FUNCTION__, | |
179 | + svc_print_addr(rqstp, buf, sizeof(buf))); | |
175 | 180 | nfs_put_client(clp); |
181 | + | |
176 | 182 | switch (rqstp->rq_authop->flavour) { |
177 | 183 | case RPC_AUTH_NULL: |
178 | 184 | if (rqstp->rq_proc != CB_NULL) |
fs/nfsd/nfsfh.c
... | ... | @@ -20,6 +20,7 @@ |
20 | 20 | #include <linux/mount.h> |
21 | 21 | #include <asm/pgtable.h> |
22 | 22 | |
23 | +#include <linux/sunrpc/clnt.h> | |
23 | 24 | #include <linux/sunrpc/svc.h> |
24 | 25 | #include <linux/nfsd/nfsd.h> |
25 | 26 | |
26 | 27 | |
... | ... | @@ -180,10 +181,10 @@ |
180 | 181 | /* Check if the request originated from a secure port. */ |
181 | 182 | error = nfserr_perm; |
182 | 183 | if (!rqstp->rq_secure && EX_SECURE(exp)) { |
184 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
183 | 185 | printk(KERN_WARNING |
184 | - "nfsd: request from insecure port (%u.%u.%u.%u:%d)!\n", | |
185 | - NIPQUAD(rqstp->rq_addr.sin_addr.s_addr), | |
186 | - ntohs(rqstp->rq_addr.sin_port)); | |
186 | + "nfsd: request from insecure port %s!\n", | |
187 | + svc_print_addr(rqstp, buf, sizeof(buf))); | |
187 | 188 | goto out; |
188 | 189 | } |
189 | 190 |
fs/nfsd/nfsproc.c
... | ... | @@ -19,6 +19,7 @@ |
19 | 19 | #include <linux/unistd.h> |
20 | 20 | #include <linux/slab.h> |
21 | 21 | |
22 | +#include <linux/sunrpc/clnt.h> | |
22 | 23 | #include <linux/sunrpc/svc.h> |
23 | 24 | #include <linux/nfsd/nfsd.h> |
24 | 25 | #include <linux/nfsd/cache.h> |
25 | 26 | |
... | ... | @@ -147,10 +148,10 @@ |
147 | 148 | */ |
148 | 149 | |
149 | 150 | if (NFSSVC_MAXBLKSIZE_V2 < argp->count) { |
151 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
150 | 152 | printk(KERN_NOTICE |
151 | - "oversized read request from %u.%u.%u.%u:%d (%d bytes)\n", | |
152 | - NIPQUAD(rqstp->rq_addr.sin_addr.s_addr), | |
153 | - ntohs(rqstp->rq_addr.sin_port), | |
153 | + "oversized read request from %s (%d bytes)\n", | |
154 | + svc_print_addr(rqstp, buf, sizeof(buf)), | |
154 | 155 | argp->count); |
155 | 156 | argp->count = NFSSVC_MAXBLKSIZE_V2; |
156 | 157 | } |
include/linux/sunrpc/svc.h
... | ... | @@ -368,6 +368,9 @@ |
368 | 368 | void svc_wake_up(struct svc_serv *); |
369 | 369 | void svc_reserve(struct svc_rqst *rqstp, int space); |
370 | 370 | struct svc_pool * svc_pool_for_cpu(struct svc_serv *serv, int cpu); |
371 | +char * svc_print_addr(struct svc_rqst *, char *, size_t); | |
372 | + | |
373 | +#define RPC_MAX_ADDRBUFLEN (63U) | |
371 | 374 | |
372 | 375 | #endif /* SUNRPC_SVC_H */ |
net/sunrpc/svcsock.c
... | ... | @@ -41,6 +41,7 @@ |
41 | 41 | #include <asm/ioctls.h> |
42 | 42 | |
43 | 43 | #include <linux/sunrpc/types.h> |
44 | +#include <linux/sunrpc/clnt.h> | |
44 | 45 | #include <linux/sunrpc/xdr.h> |
45 | 46 | #include <linux/sunrpc/svcsock.h> |
46 | 47 | #include <linux/sunrpc/stats.h> |
... | ... | @@ -121,6 +122,41 @@ |
121 | 122 | } |
122 | 123 | #endif |
123 | 124 | |
125 | +static char *__svc_print_addr(struct sockaddr *addr, char *buf, size_t len) | |
126 | +{ | |
127 | + switch (addr->sa_family) { | |
128 | + case AF_INET: | |
129 | + snprintf(buf, len, "%u.%u.%u.%u, port=%u", | |
130 | + NIPQUAD(((struct sockaddr_in *) addr)->sin_addr), | |
131 | + htons(((struct sockaddr_in *) addr)->sin_port)); | |
132 | + break; | |
133 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | |
134 | + case AF_INET6: | |
135 | + snprintf(buf, len, "%x:%x:%x:%x:%x:%x:%x:%x, port=%u", | |
136 | + NIP6(((struct sockaddr_in6 *) addr)->sin6_addr), | |
137 | + htons(((struct sockaddr_in6 *) addr)->sin6_port)); | |
138 | + break; | |
139 | +#endif | |
140 | + default: | |
141 | + snprintf(buf, len, "unknown address type: %d", addr->sa_family); | |
142 | + break; | |
143 | + } | |
144 | + return buf; | |
145 | +} | |
146 | + | |
147 | +/** | |
148 | + * svc_print_addr - Format rq_addr field for printing | |
149 | + * @rqstp: svc_rqst struct containing address to print | |
150 | + * @buf: target buffer for formatted address | |
151 | + * @len: length of target buffer | |
152 | + * | |
153 | + */ | |
154 | +char *svc_print_addr(struct svc_rqst *rqstp, char *buf, size_t len) | |
155 | +{ | |
156 | + return __svc_print_addr((struct sockaddr *) &rqstp->rq_addr, buf, len); | |
157 | +} | |
158 | +EXPORT_SYMBOL_GPL(svc_print_addr); | |
159 | + | |
124 | 160 | /* |
125 | 161 | * Queue up an idle server thread. Must have pool->sp_lock held. |
126 | 162 | * Note: this is really a stack rather than a queue, so that we only |
... | ... | @@ -429,6 +465,7 @@ |
429 | 465 | size_t base = xdr->page_base; |
430 | 466 | unsigned int pglen = xdr->page_len; |
431 | 467 | unsigned int flags = MSG_MORE; |
468 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
432 | 469 | |
433 | 470 | slen = xdr->len; |
434 | 471 | |
... | ... | @@ -491,9 +528,9 @@ |
491 | 528 | len += result; |
492 | 529 | } |
493 | 530 | out: |
494 | - dprintk("svc: socket %p sendto([%p %Zu... ], %d) = %d (addr %x)\n", | |
495 | - rqstp->rq_sock, xdr->head[0].iov_base, xdr->head[0].iov_len, xdr->len, len, | |
496 | - rqstp->rq_addr.sin_addr.s_addr); | |
531 | + dprintk("svc: socket %p sendto([%p %Zu... ], %d) = %d (addr %s)\n", | |
532 | + rqstp->rq_sock, xdr->head[0].iov_base, xdr->head[0].iov_len, | |
533 | + xdr->len, len, svc_print_addr(rqstp, buf, sizeof(buf))); | |
497 | 534 | |
498 | 535 | return len; |
499 | 536 | } |
... | ... | @@ -878,6 +915,7 @@ |
878 | 915 | struct socket *newsock; |
879 | 916 | struct svc_sock *newsvsk; |
880 | 917 | int err, slen; |
918 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
881 | 919 | |
882 | 920 | dprintk("svc: tcp_accept %p sock %p\n", svsk, sock); |
883 | 921 | if (!sock) |
884 | 922 | |
885 | 923 | |
886 | 924 | |
887 | 925 | |
... | ... | @@ -908,19 +946,20 @@ |
908 | 946 | } |
909 | 947 | |
910 | 948 | /* Ideally, we would want to reject connections from unauthorized |
911 | - * hosts here, but when we get encription, the IP of the host won't | |
912 | - * tell us anything. For now just warn about unpriv connections. | |
949 | + * hosts here, but when we get encryption, the IP of the host won't | |
950 | + * tell us anything. For now just warn about unpriv connections. | |
913 | 951 | */ |
914 | 952 | if (ntohs(sin.sin_port) >= 1024) { |
915 | 953 | dprintk(KERN_WARNING |
916 | - "%s: connect from unprivileged port: %u.%u.%u.%u:%d\n", | |
954 | + "%s: connect from unprivileged port: %s\n", | |
917 | 955 | serv->sv_name, |
918 | - NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port)); | |
956 | + __svc_print_addr((struct sockaddr *) &sin, buf, | |
957 | + sizeof(buf))); | |
919 | 958 | } |
959 | + dprintk("%s: connect from %s\n", serv->sv_name, | |
960 | + __svc_print_addr((struct sockaddr *) &sin, buf, | |
961 | + sizeof(buf))); | |
920 | 962 | |
921 | - dprintk("%s: connect from %u.%u.%u.%u:%04x\n", serv->sv_name, | |
922 | - NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port)); | |
923 | - | |
924 | 963 | /* make sure that a write doesn't block forever when |
925 | 964 | * low on memory |
926 | 965 | */ |
... | ... | @@ -955,11 +994,9 @@ |
955 | 994 | "sockets, consider increasing the " |
956 | 995 | "number of nfsd threads\n", |
957 | 996 | serv->sv_name); |
958 | - printk(KERN_NOTICE "%s: last TCP connect from " | |
959 | - "%u.%u.%u.%u:%d\n", | |
960 | - serv->sv_name, | |
961 | - NIPQUAD(sin.sin_addr.s_addr), | |
962 | - ntohs(sin.sin_port)); | |
997 | + printk(KERN_NOTICE | |
998 | + "%s: last TCP connect from %s\n", | |
999 | + serv->sv_name, buf); | |
963 | 1000 | } |
964 | 1001 | /* |
965 | 1002 | * Always select the oldest socket. It's not fair, |
966 | 1003 | |
... | ... | @@ -1587,11 +1624,12 @@ |
1587 | 1624 | struct socket *sock; |
1588 | 1625 | int error; |
1589 | 1626 | int type; |
1627 | + char buf[RPC_MAX_ADDRBUFLEN]; | |
1590 | 1628 | |
1591 | - dprintk("svc: svc_create_socket(%s, %d, %u.%u.%u.%u:%d)\n", | |
1592 | - serv->sv_program->pg_name, protocol, | |
1593 | - NIPQUAD(sin->sin_addr.s_addr), | |
1594 | - ntohs(sin->sin_port)); | |
1629 | + dprintk("svc: svc_create_socket(%s, %d, %s)\n", | |
1630 | + serv->sv_program->pg_name, protocol, | |
1631 | + __svc_print_addr((struct sockaddr *) sin, buf, | |
1632 | + sizeof(buf))); | |
1595 | 1633 | |
1596 | 1634 | if (protocol != IPPROTO_UDP && protocol != IPPROTO_TCP) { |
1597 | 1635 | printk(KERN_WARNING "svc: only UDP and TCP " |