aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph/messenger.c
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2010-07-08 13:47:16 -0400
committerSage Weil <sage@newdream.net>2010-07-08 19:49:53 -0400
commitd06dbaf6c2c7187938f3f6745d9e4938a2d0ec47 (patch)
tree472cfd72bcc15d7a7323a58a8698bab6ec7f33f1 /fs/ceph/messenger.c
parentb0bbb0be8f7fbf6d366b359e034c78a96c4e274d (diff)
ceph: fix printing of ipv6 addrs
The buffer was too small. Make it bigger, use snprintf(), put brackets around the ipv6 address to avoid mixing it up with the :port, and use the ever-so-handy %pI[46] formats. Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/messenger.c')
-rw-r--r--fs/ceph/messenger.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/fs/ceph/messenger.c b/fs/ceph/messenger.c
index 9692d08e2f88..e8c5a2d0e88f 100644
--- a/fs/ceph/messenger.c
+++ b/fs/ceph/messenger.c
@@ -43,7 +43,8 @@ static void ceph_fault(struct ceph_connection *con);
43 * nicely render a sockaddr as a string. 43 * nicely render a sockaddr as a string.
44 */ 44 */
45#define MAX_ADDR_STR 20 45#define MAX_ADDR_STR 20
46static char addr_str[MAX_ADDR_STR][40]; 46#define MAX_ADDR_STR_LEN 60
47static char addr_str[MAX_ADDR_STR][MAX_ADDR_STR_LEN];
47static DEFINE_SPINLOCK(addr_str_lock); 48static DEFINE_SPINLOCK(addr_str_lock);
48static int last_addr_str; 49static int last_addr_str;
49 50
@@ -52,7 +53,6 @@ const char *pr_addr(const struct sockaddr_storage *ss)
52 int i; 53 int i;
53 char *s; 54 char *s;
54 struct sockaddr_in *in4 = (void *)ss; 55 struct sockaddr_in *in4 = (void *)ss;
55 unsigned char *quad = (void *)&in4->sin_addr.s_addr;
56 struct sockaddr_in6 *in6 = (void *)ss; 56 struct sockaddr_in6 *in6 = (void *)ss;
57 57
58 spin_lock(&addr_str_lock); 58 spin_lock(&addr_str_lock);
@@ -64,25 +64,13 @@ const char *pr_addr(const struct sockaddr_storage *ss)
64 64
65 switch (ss->ss_family) { 65 switch (ss->ss_family) {
66 case AF_INET: 66 case AF_INET:
67 sprintf(s, "%u.%u.%u.%u:%u", 67 snprintf(s, MAX_ADDR_STR_LEN, "%pI4:%u", &in4->sin_addr,
68 (unsigned int)quad[0], 68 (unsigned int)ntohs(in4->sin_port));
69 (unsigned int)quad[1],
70 (unsigned int)quad[2],
71 (unsigned int)quad[3],
72 (unsigned int)ntohs(in4->sin_port));
73 break; 69 break;
74 70
75 case AF_INET6: 71 case AF_INET6:
76 sprintf(s, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%u", 72 snprintf(s, MAX_ADDR_STR_LEN, "[%pI6c]:%u", &in6->sin6_addr,
77 in6->sin6_addr.s6_addr16[0], 73 (unsigned int)ntohs(in6->sin6_port));
78 in6->sin6_addr.s6_addr16[1],
79 in6->sin6_addr.s6_addr16[2],
80 in6->sin6_addr.s6_addr16[3],
81 in6->sin6_addr.s6_addr16[4],
82 in6->sin6_addr.s6_addr16[5],
83 in6->sin6_addr.s6_addr16[6],
84 in6->sin6_addr.s6_addr16[7],
85 (unsigned int)ntohs(in6->sin6_port));
86 break; 74 break;
87 75
88 default: 76 default: