nlm: Fix error messages for failed remote rpcbind contact

In case of a remote rpcbind connection timeout,
the NFS kernel lock manager emits an error message
along the lines of:

    NLM: failed to contact remote rpcbind, stat = 5, port = 28416

In the Bugzilla PR, Garrett Wollman identified the following problems
with that error message:

- The error is in decimal, which can only be deciphered by reading the
  source code.
- The port number is byte-swapped.
- The error message does not identify the client the NLM is trying to
  communicate with.

Fix the shortcomings of the current error message by:

- Printing out the port number correctly.
- Mentioning the remote client.

The low-level decimal error remains an outstanding issue though.
It seems like the error strings describing the error codes live outside
of the kernel code currently.

PR:		244698
Reported by:	wollman
Approved by:	allanjude
Sponsored by:	National Bureau of Economic Research
Sponsored by:	Klara, Inc.
Co-authored-by:	Mateusz Piotrowski <0mp@FreeBSD.org>
This commit is contained in:
Tom Jones 2023-09-25 20:33:45 +02:00 committed by Mateusz Piotrowski
parent 6e5b1ff71e
commit 14105aae55

View file

@ -343,6 +343,12 @@ nlm_get_rpc(struct sockaddr *sa, rpcprog_t prog, rpcvers_t vers)
bool_t tryagain = FALSE;
struct portmap mapping;
u_short port = 0;
struct sockaddr_in *sin4;
char namebuf[INET_ADDRSTRLEN];
#ifdef INET6
struct sockaddr_in6 *sin6;
char namebuf6[INET6_ADDRSTRLEN];
#endif
/*
* First we need to contact the remote RPCBIND service to find
@ -489,8 +495,26 @@ nlm_get_rpc(struct sockaddr *sa, rpcprog_t prog, rpcvers_t vers)
}
/* Otherwise, bad news. */
NLM_ERR("NLM: failed to contact remote rpcbind, "
"stat = %d, port = %d\n", (int) stat, port);
switch (ss.ss_family) {
case AF_INET:
sin4 = (struct sockaddr_in *)&ss;
inet_ntop(ss.ss_family, &sin4->sin_addr,
namebuf, sizeof namebuf);
NLM_ERR("NLM: failed to contact remote rpcbind, "
"stat = %d, host = %s, port = %d\n",
(int) stat, namebuf, htons(port));
break;
#ifdef INET6
case AF_INET6:
sin6 = (struct sockaddr_in6 *)&ss;
inet_ntop(ss.ss_family, &sin6->sin6_addr,
namebuf6, sizeof namebuf6);
NLM_ERR("NLM: failed to contact remote rpcbind, "
"stat = %d, host = %s, port = %d\n",
(int) stat, namebuf6, htons(port));
break;
#endif
}
CLNT_DESTROY(rpcb);
return (NULL);
}