2 * network.c -- Provide common network functions for NFS mount/umount
4 * Copyright (C) 2007 Oracle. All rights reserved.
5 * Copyright (C) 2007 Chuck Lever <chuck.lever@oracle.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 021110-1307, USA.
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
41 #include <rpc/pmap_prot.h>
42 #include <rpc/pmap_clnt.h>
47 #include "nfs_mount.h"
48 #include "mount_constants.h"
51 #define PMAP_TIMEOUT (10)
52 #define CONNECT_TIMEOUT (20)
53 #define MOUNT_TIMEOUT (30)
55 #if SIZEOF_SOCKLEN_T - 0 == 0
56 #define socklen_t unsigned int
59 extern int nfs_mount_data_version;
60 extern char *progname;
63 static const unsigned long nfs_to_mnt[] = {
70 static const unsigned long mnt_to_nfs[] = {
78 * Map an NFS version into the corresponding Mountd version
80 unsigned long nfsvers_to_mnt(const unsigned long vers)
83 return nfs_to_mnt[vers];
88 * Map a Mountd version into the corresponding NFS version
90 static unsigned long mntvers_to_nfs(const unsigned long vers)
93 return mnt_to_nfs[vers];
97 static const unsigned int probe_udp_only[] = {
102 static const unsigned int probe_udp_first[] = {
108 static const unsigned int probe_tcp_first[] = {
114 static const unsigned long probe_nfs2_only[] = {
119 static const unsigned long probe_nfs3_first[] = {
125 static const unsigned long probe_mnt1_first[] = {
131 static const unsigned long probe_mnt3_first[] = {
139 * nfs_name_to_address - resolve hostname to an IPv4 or IPv6 socket address
140 * @hostname: pointer to C string containing DNS hostname to resolve
141 * @sap: pointer to buffer to fill with socket address
142 * @len: IN: size of buffer to fill; OUT: size of socket address
144 * Returns 1 and places a socket address at @sap if successful;
147 int nfs_name_to_address(const char *hostname,
148 const sa_family_t af_hint,
149 struct sockaddr *sap, socklen_t *salen)
151 struct addrinfo *gai_results;
152 struct addrinfo gai_hint = {
153 .ai_family = af_hint,
154 .ai_flags = AI_ADDRCONFIG,
156 socklen_t len = *salen;
159 if (af_hint == AF_INET6)
160 gai_hint.ai_flags |= AI_V4MAPPED|AI_ALL;
164 error = getaddrinfo(hostname, NULL, &gai_hint, &gai_results);
166 nfs_error(_("%s: DNS resolution failed for %s: %s"),
167 progname, hostname, (error == EAI_SYSTEM ?
168 strerror(errno) : gai_strerror(error)));
172 switch (gai_results->ai_addr->sa_family) {
175 if (len >= gai_results->ai_addrlen) {
176 *salen = gai_results->ai_addrlen;
177 memcpy(sap, gai_results->ai_addr, *salen);
182 /* things are really broken if we get here, so warn */
183 nfs_error(_("%s: unrecognized DNS resolution results for %s"),
188 freeaddrinfo(gai_results);
193 * nfs_gethostbyname - resolve a hostname to an IPv4 address
194 * @hostname: pointer to a C string containing a DNS hostname
195 * @saddr: returns an IPv4 address
197 * Returns 1 if successful, otherwise zero.
199 int nfs_gethostbyname(const char *hostname, struct sockaddr_in *sin)
201 socklen_t len = sizeof(*sin);
203 return nfs_name_to_address(hostname, AF_INET,
204 (struct sockaddr *)sin, &len);
208 * nfs_string_to_sockaddr - convert string address to sockaddr
209 * @address: pointer to presentation format address to convert
210 * @addrlen: length of presentation address
211 * @sap: pointer to socket address buffer to fill in
212 * @salen: IN: length of address buffer
213 * OUT: length of converted socket address
215 * Convert a presentation format address string to a socket address.
216 * Similar to nfs_name_to_address(), but the DNS query is squelched,
217 * and won't make any noise if the getaddrinfo() call fails.
219 * Returns 1 and fills in @sap and @salen if successful; otherwise zero.
221 * See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
222 * on presenting IPv6 addresses as text strings.
224 int nfs_string_to_sockaddr(const char *address, const size_t addrlen,
225 struct sockaddr *sap, socklen_t *salen)
227 struct addrinfo *gai_results;
228 struct addrinfo gai_hint = {
229 .ai_flags = AI_NUMERICHOST,
231 socklen_t len = *salen;
236 if (getaddrinfo(address, NULL, &gai_hint, &gai_results) == 0) {
237 switch (gai_results->ai_addr->sa_family) {
240 if (len >= gai_results->ai_addrlen) {
241 *salen = gai_results->ai_addrlen;
242 memcpy(sap, gai_results->ai_addr, *salen);
247 freeaddrinfo(gai_results);
254 * nfs_present_sockaddr - convert sockaddr to string
255 * @sap: pointer to socket address to convert
256 * @salen: length of socket address
257 * @buf: pointer to buffer to fill in
258 * @buflen: length of buffer
260 * Convert the passed-in sockaddr-style address to presentation format.
261 * The presentation format address is placed in @buf and is
264 * Returns 1 if successful; otherwise zero.
266 * See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
267 * on presenting IPv6 addresses as text strings.
269 int nfs_present_sockaddr(const struct sockaddr *sap, const socklen_t salen,
270 char *buf, const size_t buflen)
272 #ifdef HAVE_GETNAMEINFO
275 result = getnameinfo(sap, salen, buf, buflen,
276 NULL, 0, NI_NUMERICHOST);
280 nfs_error(_("%s: invalid server address: %s"), progname,
281 gai_strerror(result));
283 #else /* HAVE_GETNAMEINFO */
286 if (sap->sa_family == AF_INET) {
287 addr = inet_ntoa(((struct sockaddr_in *)sap)->sin_addr);
288 if (addr && strlen(addr) < buflen) {
294 nfs_error(_("%s: invalid server address"), progname);
296 #endif /* HAVE_GETNAMEINFO */
300 * Attempt to connect a socket, but time out after "timeout" seconds.
302 * On error return, caller closes the socket.
304 static int connect_to(int fd, struct sockaddr *addr,
305 socklen_t addrlen, int timeout)
309 struct timeval tv = {
313 saved = fcntl(fd, F_GETFL, 0);
314 fcntl(fd, F_SETFL, saved | O_NONBLOCK);
316 ret = connect(fd, addr, addrlen);
317 if (ret < 0 && errno != EINPROGRESS)
325 ret = select(fd + 1, &rset, &wset, NULL, &tv);
330 if (FD_ISSET(fd, &rset) || FD_ISSET(fd, &wset)) {
332 socklen_t len = sizeof(error);
333 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
343 fcntl(fd, F_SETFL, saved);
348 * Create a socket that is locally bound to a reserved or non-reserved port.
350 * The caller should check rpc_createerr to determine the cause of any error.
352 static int get_socket(struct sockaddr_in *saddr, unsigned int p_prot,
353 unsigned int timeout, int resvp, int conn)
356 struct sockaddr_in laddr;
357 socklen_t namelen = sizeof(laddr);
359 type = (p_prot == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM);
360 if ((so = socket (AF_INET, type, p_prot)) < 0)
363 laddr.sin_family = AF_INET;
365 laddr.sin_addr.s_addr = htonl(INADDR_ANY);
367 if (bindresvport(so, &laddr) < 0)
368 goto err_bindresvport;
370 cc = bind(so, (struct sockaddr *)&laddr, namelen);
374 if (type == SOCK_STREAM || (conn && type == SOCK_DGRAM)) {
375 cc = connect_to(so, (struct sockaddr *)saddr, namelen,
383 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
384 rpc_createerr.cf_error.re_errno = errno;
386 nfs_error(_("%s: Unable to create %s socket: errno %d (%s)\n"),
387 progname, p_prot == IPPROTO_UDP ? _("UDP") : _("TCP"),
388 errno, strerror(errno));
393 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
394 rpc_createerr.cf_error.re_errno = errno;
396 nfs_error(_("%s: Unable to bindresvport %s socket: errno %d"
398 progname, p_prot == IPPROTO_UDP ? _("UDP") : _("TCP"),
399 errno, strerror(errno));
405 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
406 rpc_createerr.cf_error.re_errno = errno;
408 nfs_error(_("%s: Unable to bind to %s socket: errno %d (%s)\n"),
409 progname, p_prot == IPPROTO_UDP ? _("UDP") : _("TCP"),
410 errno, strerror(errno));
416 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
417 rpc_createerr.cf_error.re_errno = errno;
419 nfs_error(_("%s: Unable to connect to %s:%d, errno %d (%s)\n"),
420 progname, inet_ntoa(saddr->sin_addr),
421 ntohs(saddr->sin_port), errno, strerror(errno));
428 * getport() is very similar to pmap_getport() with the exception that
429 * this version tries to use an ephemeral port, since reserved ports are
430 * not needed for GETPORT queries. This conserves the very limited
431 * reserved port space, which helps reduce failed socket binds
432 * during mount storms.
434 * A side effect of calling this function is that rpccreateerr is set.
436 static unsigned short getport(struct sockaddr_in *saddr,
437 unsigned long program,
438 unsigned long version,
441 struct sockaddr_in bind_saddr;
442 unsigned short port = 0;
448 bind_saddr.sin_port = htons(PMAPPORT);
450 socket = get_socket(&bind_saddr, proto, PMAP_TIMEOUT, FALSE, FALSE);
451 if (socket == RPC_ANYSOCK) {
452 if (proto == IPPROTO_TCP &&
453 rpc_createerr.cf_error.re_errno == ETIMEDOUT)
454 rpc_createerr.cf_stat = RPC_TIMEDOUT;
460 clnt = clntudp_bufcreate(&bind_saddr,
462 RETRY_TIMEOUT, &socket,
467 clnt = clnttcp_create(&bind_saddr,
470 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
474 struct pmap parms = {
480 stat = clnt_call(clnt, PMAPPROC_GETPORT,
481 (xdrproc_t)xdr_pmap, (caddr_t)&parms,
482 (xdrproc_t)xdr_u_short, (caddr_t)&port,
485 clnt_geterr(clnt, &rpc_createerr.cf_error);
486 rpc_createerr.cf_stat = stat;
489 if (stat != RPC_SUCCESS)
492 rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
500 * Use the portmapper to discover whether or not the service we want is
501 * available. The lists 'versions' and 'protos' define ordered sequences
502 * of service versions and udp/tcp protocols to probe for.
504 static int probe_port(clnt_addr_t *server, const unsigned long *versions,
505 const unsigned int *protos)
507 struct sockaddr_in *saddr = &server->saddr;
508 struct pmap *pmap = &server->pmap;
509 const unsigned long prog = pmap->pm_prog, *p_vers;
510 const unsigned int prot = (u_int)pmap->pm_prot, *p_prot;
511 const u_short port = (u_short) pmap->pm_port;
512 unsigned long vers = pmap->pm_vers;
513 unsigned short p_port;
515 p_prot = prot ? &prot : protos;
516 p_vers = vers ? &vers : versions;
517 rpc_createerr.cf_stat = 0;
519 p_port = getport(saddr, prog, *p_vers, *p_prot);
521 if (!port || port == p_port) {
522 saddr->sin_port = htons(p_port);
524 printf(_("%s: trying %s prog %ld vers "
525 "%ld prot %s port %d\n"),
527 inet_ntoa(saddr->sin_addr),
529 *p_prot == IPPROTO_UDP ?
533 if (clnt_ping(saddr, prog, *p_vers, *p_prot, NULL))
535 if (rpc_createerr.cf_stat == RPC_TIMEDOUT)
539 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
540 rpc_createerr.cf_stat != RPC_PROGVERSMISMATCH)
548 if (vers || !*++p_vers)
557 pmap->pm_vers = *p_vers;
559 pmap->pm_prot = *p_prot;
561 pmap->pm_port = p_port;
562 rpc_createerr.cf_stat = 0;
566 static int probe_nfsport(clnt_addr_t *nfs_server)
568 struct pmap *pmap = &nfs_server->pmap;
570 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
573 if (nfs_mount_data_version >= 4)
574 return probe_port(nfs_server, probe_nfs3_first, probe_tcp_first);
576 return probe_port(nfs_server, probe_nfs2_only, probe_udp_only);
579 static int probe_mntport(clnt_addr_t *mnt_server)
581 struct pmap *pmap = &mnt_server->pmap;
583 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
586 if (nfs_mount_data_version >= 4)
587 return probe_port(mnt_server, probe_mnt3_first, probe_udp_first);
589 return probe_port(mnt_server, probe_mnt1_first, probe_udp_only);
593 * probe_bothports - discover the RPC endpoints of mountd and NFS server
594 * @mnt_server: pointer to address and pmap argument for mountd results
595 * @nfs_server: pointer to address and pmap argument for NFS server
597 * Returns 1 if successful, otherwise zero if some error occurred.
598 * Note that the arguments are both input and output arguments.
600 * A side effect of calling this function is that rpccreateerr is set.
602 int probe_bothports(clnt_addr_t *mnt_server, clnt_addr_t *nfs_server)
604 struct pmap *nfs_pmap = &nfs_server->pmap;
605 struct pmap *mnt_pmap = &mnt_server->pmap;
606 struct pmap save_nfs, save_mnt;
608 const unsigned long *probe_vers;
610 if (mnt_pmap->pm_vers && !nfs_pmap->pm_vers)
611 nfs_pmap->pm_vers = mntvers_to_nfs(mnt_pmap->pm_vers);
612 else if (nfs_pmap->pm_vers && !mnt_pmap->pm_vers)
613 mnt_pmap->pm_vers = nfsvers_to_mnt(nfs_pmap->pm_vers);
614 if (nfs_pmap->pm_vers)
617 memcpy(&save_nfs, nfs_pmap, sizeof(save_nfs));
618 memcpy(&save_mnt, mnt_pmap, sizeof(save_mnt));
619 probe_vers = (nfs_mount_data_version >= 4) ?
620 probe_mnt3_first : probe_mnt1_first;
622 for (; *probe_vers; probe_vers++) {
623 nfs_pmap->pm_vers = mntvers_to_nfs(*probe_vers);
624 if ((res = probe_nfsport(nfs_server) != 0)) {
625 mnt_pmap->pm_vers = *probe_vers;
626 if ((res = probe_mntport(mnt_server)) != 0)
628 memcpy(mnt_pmap, &save_mnt, sizeof(*mnt_pmap));
630 switch (rpc_createerr.cf_stat) {
631 case RPC_PROGVERSMISMATCH:
632 case RPC_PROGNOTREGISTERED:
637 memcpy(nfs_pmap, &save_nfs, sizeof(*nfs_pmap));
644 if (!probe_nfsport(nfs_server))
646 return probe_mntport(mnt_server);
649 static int probe_statd(void)
651 struct sockaddr_in addr;
654 memset(&addr, 0, sizeof(addr));
655 addr.sin_family = AF_INET;
656 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
657 port = getport(&addr, 100024, 1, IPPROTO_UDP);
661 addr.sin_port = htons(port);
663 if (clnt_ping(&addr, 100024, 1, IPPROTO_UDP, NULL) <= 0)
670 * start_statd - attempt to start rpc.statd
672 * Returns 1 if statd is running; otherwise zero.
674 int start_statd(void)
684 if (stat(START_STATD, &stb) == 0) {
685 if (S_ISREG(stb.st_mode) && (stb.st_mode & S_IXUSR)) {
697 * nfs_call_umount - ask the server to remove a share from it's rmtab
698 * @mnt_server: address of RPC MNT program server
699 * @argp: directory path of share to "unmount"
701 * Returns one if the unmount call succeeded; zero if the unmount
702 * failed for any reason.
704 * Note that a side effect of calling this function is that rpccreateerr
707 int nfs_call_umount(clnt_addr_t *mnt_server, dirpath *argp)
710 enum clnt_stat res = 0;
713 if (!probe_mntport(mnt_server))
715 clnt = mnt_openclnt(mnt_server, &msock);
718 res = clnt_call(clnt, MOUNTPROC_UMNT,
719 (xdrproc_t)xdr_dirpath, (caddr_t)argp,
720 (xdrproc_t)xdr_void, NULL,
722 mnt_closeclnt(clnt, msock);
724 if (res == RPC_SUCCESS)
730 * mnt_openclnt - get a handle for a remote mountd service
731 * @mnt_server: address and pmap arguments of mountd service
732 * @msock: returns a file descriptor of the underlying transport socket
734 * Returns an active handle for the remote's mountd service
736 CLIENT *mnt_openclnt(clnt_addr_t *mnt_server, int *msock)
738 struct sockaddr_in *mnt_saddr = &mnt_server->saddr;
739 struct pmap *mnt_pmap = &mnt_server->pmap;
742 mnt_saddr->sin_port = htons((u_short)mnt_pmap->pm_port);
743 *msock = get_socket(mnt_saddr, mnt_pmap->pm_prot, MOUNT_TIMEOUT,
745 if (*msock == RPC_ANYSOCK) {
746 if (rpc_createerr.cf_error.re_errno == EADDRINUSE)
748 * Probably in-use by a TIME_WAIT connection,
749 * It is worth waiting a while and trying again.
751 rpc_createerr.cf_stat = RPC_TIMEDOUT;
755 switch (mnt_pmap->pm_prot) {
757 clnt = clntudp_bufcreate(mnt_saddr,
758 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
759 RETRY_TIMEOUT, msock,
760 MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
763 clnt = clnttcp_create(mnt_saddr,
764 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
766 MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
770 /* try to mount hostname:dirname */
771 clnt->cl_auth = authunix_create_default();
778 * mnt_closeclnt - terminate a handle for a remote mountd service
779 * @clnt: pointer to an active handle for a remote mountd service
780 * @msock: file descriptor of the underlying transport socket
783 void mnt_closeclnt(CLIENT *clnt, int msock)
785 auth_destroy(clnt->cl_auth);
791 * clnt_ping - send an RPC ping to the remote RPC service endpoint
792 * @saddr: server's address
793 * @prog: target RPC program number
794 * @vers: target RPC version number
795 * @prot: target RPC protocol
796 * @caddr: filled in with our network address
798 * Sigh... getport() doesn't actually check the version number.
799 * In order to make sure that the server actually supports the service
800 * we're requesting, we open and RPC client, and fire off a NULL
803 * caddr is the network address that the server will use to call us back.
804 * On multi-homed clients, this address depends on which NIC we use to
805 * route requests to the server.
807 * Returns one if successful, otherwise zero.
809 int clnt_ping(struct sockaddr_in *saddr, const unsigned long prog,
810 const unsigned long vers, const unsigned int prot,
811 struct sockaddr_in *caddr)
815 static char clnt_res;
816 struct sockaddr dissolve;
818 rpc_createerr.cf_stat = stat = 0;
819 sock = get_socket(saddr, prot, CONNECT_TIMEOUT, FALSE, TRUE);
820 if (sock == RPC_ANYSOCK) {
821 if (rpc_createerr.cf_error.re_errno == ETIMEDOUT) {
823 * TCP timeout. Bubble up the error to see
824 * how it should be handled.
826 rpc_createerr.cf_stat = RPC_TIMEDOUT;
832 /* Get the address of our end of this connection */
833 socklen_t len = sizeof(*caddr);
834 if (getsockname(sock, caddr, &len) != 0)
835 caddr->sin_family = 0;
840 /* The socket is connected (so we could getsockname successfully),
841 * but some servers on multi-homed hosts reply from
842 * the wrong address, so if we stay connected, we lose the reply.
844 dissolve.sa_family = AF_UNSPEC;
845 connect(sock, &dissolve, sizeof(dissolve));
847 clnt = clntudp_bufcreate(saddr, prog, vers,
848 RETRY_TIMEOUT, &sock,
849 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
852 clnt = clnttcp_create(saddr, prog, vers, &sock,
853 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
860 memset(&clnt_res, 0, sizeof(clnt_res));
861 stat = clnt_call(clnt, NULLPROC,
862 (xdrproc_t)xdr_void, (caddr_t)NULL,
863 (xdrproc_t)xdr_void, (caddr_t)&clnt_res,
866 clnt_geterr(clnt, &rpc_createerr.cf_error);
867 rpc_createerr.cf_stat = stat;
872 if (stat == RPC_SUCCESS)
879 * Try a getsockname() on a connected datagram socket.
881 * Returns 1 and fills in @buf if successful; otherwise, zero.
883 * A connected datagram socket prevents leaving a socket in TIME_WAIT.
884 * This conserves the ephemeral port number space, helping reduce failed
885 * socket binds during mount storms.
887 static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
888 struct sockaddr *buf, socklen_t *buflen)
890 struct sockaddr_in sin = {
891 .sin_family = AF_INET,
892 .sin_addr.s_addr = htonl(INADDR_ANY),
894 struct sockaddr_in6 sin6 = {
895 .sin6_family = AF_INET6,
896 .sin6_addr = IN6ADDR_ANY_INIT,
900 sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP);
904 switch (sap->sa_family) {
906 if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
912 if (bind(sock, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
918 errno = EAFNOSUPPORT;
922 if (connect(sock, sap, salen) < 0) {
927 return !getsockname(sock, buf, buflen);
931 * Try to generate an address that prevents the server from calling us.
933 * Returns 1 and fills in @buf if successful; otherwise, zero.
935 static int nfs_ca_gai(const struct sockaddr *sap, const socklen_t salen,
936 struct sockaddr *buf, socklen_t *buflen)
938 struct addrinfo *gai_results;
939 struct addrinfo gai_hint = {
940 .ai_family = sap->sa_family,
941 .ai_flags = AI_PASSIVE, /* ANYADDR */
944 if (getaddrinfo(NULL, "", &gai_hint, &gai_results))
947 *buflen = gai_results->ai_addrlen;
948 memcpy(buf, gai_results->ai_addr, *buflen);
950 freeaddrinfo(gai_results);
956 * nfs_callback_address - acquire our local network address
957 * @sap: pointer to address of remote
958 * @sap_len: length of address
959 * @buf: pointer to buffer to be filled in with local network address
960 * @buflen: IN: length of buffer to fill in; OUT: length of filled-in address
962 * Discover a network address that an NFSv4 server can use to call us back.
963 * On multi-homed clients, this address depends on which NIC we use to
964 * route requests to the server.
966 * Returns 1 and fills in @buf if an unambiguous local address is
967 * available; returns 1 and fills in an appropriate ANYADDR address
968 * if a local address isn't available; otherwise, returns zero.
970 int nfs_callback_address(const struct sockaddr *sap, const socklen_t salen,
971 struct sockaddr *buf, socklen_t *buflen)
973 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf;
975 if (nfs_ca_sockname(sap, salen, buf, buflen) == 0)
976 if (nfs_ca_gai(sap, salen, buf, buflen) == 0)
980 * The server can't use an interface ID that was generated
981 * here on the client, so always clear sin6_scope_id.
983 if (sin6->sin6_family == AF_INET6)
984 sin6->sin6_scope_id = 0;
991 nfs_error(_("%s: failed to construct callback address"));