aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/lockd/host.c21
-rw-r--r--include/linux/lockd/lockd.h10
2 files changed, 24 insertions, 7 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index beb5da810167..012e49aaecd1 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -105,22 +105,31 @@ static void nlm_clear_port(struct sockaddr *sap)
105 } 105 }
106} 106}
107 107
108static void nlm_display_ipv6_address(const struct sockaddr *sap, char *buf,
109 const size_t len)
110{
111 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
112
113 if (ipv6_addr_v4mapped(&sin6->sin6_addr))
114 snprintf(buf, len, "%pI4", &sin6->sin6_addr.s6_addr32[3]);
115 else if (sin6->sin6_scope_id != 0)
116 snprintf(buf, len, "%pI6%%%u", &sin6->sin6_addr,
117 sin6->sin6_scope_id);
118 else
119 snprintf(buf, len, "%pI6", &sin6->sin6_addr);
120}
121
108static void nlm_display_address(const struct sockaddr *sap, 122static void nlm_display_address(const struct sockaddr *sap,
109 char *buf, const size_t len) 123 char *buf, const size_t len)
110{ 124{
111 const struct sockaddr_in *sin = (struct sockaddr_in *)sap; 125 const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
112 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
113 126
114 switch (sap->sa_family) { 127 switch (sap->sa_family) {
115 case AF_INET: 128 case AF_INET:
116 snprintf(buf, len, "%pI4", &sin->sin_addr.s_addr); 129 snprintf(buf, len, "%pI4", &sin->sin_addr.s_addr);
117 break; 130 break;
118 case AF_INET6: 131 case AF_INET6:
119 if (ipv6_addr_v4mapped(&sin6->sin6_addr)) 132 nlm_display_ipv6_address(sap, buf, len);
120 snprintf(buf, len, "%pI4",
121 &sin6->sin6_addr.s6_addr32[3]);
122 else
123 snprintf(buf, len, "%pI6", &sin6->sin6_addr);
124 break; 133 break;
125 default: 134 default:
126 snprintf(buf, len, "unsupported address family"); 135 snprintf(buf, len, "unsupported address family");
diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h
index dae22cb4c38d..80a0a2cff2b8 100644
--- a/include/linux/lockd/lockd.h
+++ b/include/linux/lockd/lockd.h
@@ -68,6 +68,14 @@ struct nlm_host {
68 char *h_addrbuf; /* address eyecatcher */ 68 char *h_addrbuf; /* address eyecatcher */
69}; 69};
70 70
71/*
72 * The largest string sm_addrbuf should hold is a full-size IPv6 address
73 * (no "::" anywhere) with a scope ID. The buffer size is computed to
74 * hold eight groups of colon-separated four-hex-digit numbers, a
75 * percent sign, a scope id (at most 32 bits, in decimal), and NUL.
76 */
77#define NSM_ADDRBUF ((8 * 4 + 7) + (1 + 10) + 1)
78
71struct nsm_handle { 79struct nsm_handle {
72 struct list_head sm_link; 80 struct list_head sm_link;
73 atomic_t sm_count; 81 atomic_t sm_count;
@@ -76,7 +84,7 @@ struct nsm_handle {
76 size_t sm_addrlen; 84 size_t sm_addrlen;
77 unsigned int sm_monitored : 1, 85 unsigned int sm_monitored : 1,
78 sm_sticky : 1; /* don't unmonitor */ 86 sm_sticky : 1; /* don't unmonitor */
79 char sm_addrbuf[48]; /* address eyecatcher */ 87 char sm_addrbuf[NSM_ADDRBUF];
80}; 88};
81 89
82/* 90/*