aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/svcsock.c
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2007-02-12 03:53:32 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-12 12:48:35 -0500
commitad06e4bd62351bc569cca0f25d68c58dbd298146 (patch)
tree82024c01e61de32af17d3b67eac0bb93138a2954 /net/sunrpc/svcsock.c
parent1ba951053f07187f6e77be664a4b6f8bf0ba7ae4 (diff)
[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>
Diffstat (limited to 'net/sunrpc/svcsock.c')
-rw-r--r--net/sunrpc/svcsock.c76
1 files changed, 57 insertions, 19 deletions
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index a98be09768a0..08de328ce433 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -41,6 +41,7 @@
41#include <asm/ioctls.h> 41#include <asm/ioctls.h>
42 42
43#include <linux/sunrpc/types.h> 43#include <linux/sunrpc/types.h>
44#include <linux/sunrpc/clnt.h>
44#include <linux/sunrpc/xdr.h> 45#include <linux/sunrpc/xdr.h>
45#include <linux/sunrpc/svcsock.h> 46#include <linux/sunrpc/svcsock.h>
46#include <linux/sunrpc/stats.h> 47#include <linux/sunrpc/stats.h>
@@ -121,6 +122,41 @@ static inline void svc_reclassify_socket(struct socket *sock)
121} 122}
122#endif 123#endif
123 124
125static 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 */
154char *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}
158EXPORT_SYMBOL_GPL(svc_print_addr);
159
124/* 160/*
125 * Queue up an idle server thread. Must have pool->sp_lock held. 161 * Queue up an idle server thread. Must have pool->sp_lock held.
126 * Note: this is really a stack rather than a queue, so that we only 162 * Note: this is really a stack rather than a queue, so that we only
@@ -429,6 +465,7 @@ svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
429 size_t base = xdr->page_base; 465 size_t base = xdr->page_base;
430 unsigned int pglen = xdr->page_len; 466 unsigned int pglen = xdr->page_len;
431 unsigned int flags = MSG_MORE; 467 unsigned int flags = MSG_MORE;
468 char buf[RPC_MAX_ADDRBUFLEN];
432 469
433 slen = xdr->len; 470 slen = xdr->len;
434 471
@@ -491,9 +528,9 @@ svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
491 len += result; 528 len += result;
492 } 529 }
493out: 530out:
494 dprintk("svc: socket %p sendto([%p %Zu... ], %d) = %d (addr %x)\n", 531 dprintk("svc: socket %p sendto([%p %Zu... ], %d) = %d (addr %s)\n",
495 rqstp->rq_sock, xdr->head[0].iov_base, xdr->head[0].iov_len, xdr->len, len, 532 rqstp->rq_sock, xdr->head[0].iov_base, xdr->head[0].iov_len,
496 rqstp->rq_addr.sin_addr.s_addr); 533 xdr->len, len, svc_print_addr(rqstp, buf, sizeof(buf)));
497 534
498 return len; 535 return len;
499} 536}
@@ -878,6 +915,7 @@ svc_tcp_accept(struct svc_sock *svsk)
878 struct socket *newsock; 915 struct socket *newsock;
879 struct svc_sock *newsvsk; 916 struct svc_sock *newsvsk;
880 int err, slen; 917 int err, slen;
918 char buf[RPC_MAX_ADDRBUFLEN];
881 919
882 dprintk("svc: tcp_accept %p sock %p\n", svsk, sock); 920 dprintk("svc: tcp_accept %p sock %p\n", svsk, sock);
883 if (!sock) 921 if (!sock)
@@ -908,18 +946,19 @@ svc_tcp_accept(struct svc_sock *svsk)
908 } 946 }
909 947
910 /* Ideally, we would want to reject connections from unauthorized 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 949 * hosts here, but when we get encryption, the IP of the host won't
912 * tell us anything. For now just warn about unpriv connections. 950 * tell us anything. For now just warn about unpriv connections.
913 */ 951 */
914 if (ntohs(sin.sin_port) >= 1024) { 952 if (ntohs(sin.sin_port) >= 1024) {
915 dprintk(KERN_WARNING 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 serv->sv_name, 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 }
920 959 dprintk("%s: connect from %s\n", serv->sv_name,
921 dprintk("%s: connect from %u.%u.%u.%u:%04x\n", serv->sv_name, 960 __svc_print_addr((struct sockaddr *) &sin, buf,
922 NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port)); 961 sizeof(buf)));
923 962
924 /* make sure that a write doesn't block forever when 963 /* make sure that a write doesn't block forever when
925 * low on memory 964 * low on memory
@@ -955,11 +994,9 @@ svc_tcp_accept(struct svc_sock *svsk)
955 "sockets, consider increasing the " 994 "sockets, consider increasing the "
956 "number of nfsd threads\n", 995 "number of nfsd threads\n",
957 serv->sv_name); 996 serv->sv_name);
958 printk(KERN_NOTICE "%s: last TCP connect from " 997 printk(KERN_NOTICE
959 "%u.%u.%u.%u:%d\n", 998 "%s: last TCP connect from %s\n",
960 serv->sv_name, 999 serv->sv_name, buf);
961 NIPQUAD(sin.sin_addr.s_addr),
962 ntohs(sin.sin_port));
963 } 1000 }
964 /* 1001 /*
965 * Always select the oldest socket. It's not fair, 1002 * Always select the oldest socket. It's not fair,
@@ -1587,11 +1624,12 @@ static int svc_create_socket(struct svc_serv *serv, int protocol,
1587 struct socket *sock; 1624 struct socket *sock;
1588 int error; 1625 int error;
1589 int type; 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", 1629 dprintk("svc: svc_create_socket(%s, %d, %s)\n",
1592 serv->sv_program->pg_name, protocol, 1630 serv->sv_program->pg_name, protocol,
1593 NIPQUAD(sin->sin_addr.s_addr), 1631 __svc_print_addr((struct sockaddr *) sin, buf,
1594 ntohs(sin->sin_port)); 1632 sizeof(buf)));
1595 1633
1596 if (protocol != IPPROTO_UDP && protocol != IPPROTO_TCP) { 1634 if (protocol != IPPROTO_UDP && protocol != IPPROTO_TCP) {
1597 printk(KERN_WARNING "svc: only UDP and TCP " 1635 printk(KERN_WARNING "svc: only UDP and TCP "