Skip to content

Commit bc99580

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
NLM: Support IPv6 scope IDs in nlm_display_address()
Scope ID support is needed since the kernel's NSM implementation is about to use these displayed addresses as a mon_name in some cases. When nsm_use_hostnames is zero, without scope ID support NSM will fail to handle peers that contact us via a link-local address. Link-local addresses do not work without an interface ID, which is stored in the sockaddr's sin6_scope_id field. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
1 parent 6999fb4 commit bc99580

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎fs/lockd/host.c‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,31 @@ static void nlm_clear_port(struct sockaddr *sap)
105105
}
106106
}
107107

108+
static 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+
108122
static void nlm_display_address(const struct sockaddr *sap,
109123
char *buf, const size_t len)
110124
{
111125
const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
112-
const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
113126

114127
switch (sap->sa_family) {
115128
case AF_INET:
116129
snprintf(buf, len, "%pI4", &sin->sin_addr.s_addr);
117130
break;
118131
case AF_INET6:
119-
if (ipv6_addr_v4mapped(&sin6->sin6_addr))
120-
snprintf(buf, len, "%pI4",
121-
&sin6->sin6_addr.s6_addr32[3]);
122-
else
123-
snprintf(buf, len, "%pI6", &sin6->sin6_addr);
132+
nlm_display_ipv6_address(sap, buf, len);
124133
break;
125134
default:
126135
snprintf(buf, len, "unsupported address family");

‎include/linux/lockd/lockd.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ struct nlm_host {
6868
char *h_addrbuf; /* address eyecatcher */
6969
};
7070

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+
7179
struct nsm_handle {
7280
struct list_head sm_link;
7381
atomic_t sm_count;
@@ -76,7 +84,7 @@ struct nsm_handle {
7684
size_t sm_addrlen;
7785
unsigned int sm_monitored : 1,
7886
sm_sticky : 1; /* don't unmonitor */
79-
char sm_addrbuf[48]; /* address eyecatcher */
87+
char sm_addrbuf[NSM_ADDRBUF];
8088
};
8189

8290
/*

0 commit comments

Comments
 (0)