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>
40 #include <netinet/in.h>
42 #include <rpc/pmap_prot.h>
43 #include <rpc/pmap_clnt.h>
48 #include "nfs_mount.h"
49 #include "mount_constants.h"
54 * Earlier versions of glibc's /usr/include/netdb.h exclude these
55 * definitions because it was thought they were not part of a stable
56 * POSIX standard. However, they are defined by RFC 2553 and 3493
57 * and in POSIX 1003.1-2001, so these definitions were added in later
58 * versions of netdb.h.
61 #define AI_V4MAPPED 0x0008 /* IPv4-mapped addresses are acceptable. */
62 #endif /* AI_V4MAPPED */
64 #define AI_ALL 0x0010 /* Return both IPv4 and IPv6 addresses. */
67 #define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose \
68 returned address type. */
69 #endif /* AI_ADDRCONFIG */
71 #define PMAP_TIMEOUT (10)
72 #define CONNECT_TIMEOUT (20)
73 #define MOUNT_TIMEOUT (30)
75 #if SIZEOF_SOCKLEN_T - 0 == 0
76 #define socklen_t unsigned int
79 extern int nfs_mount_data_version;
80 extern char *progname;
83 static const char *nfs_ns_pgmtbl[] = {
88 static const unsigned long nfs_to_mnt[] = {
95 static const unsigned long mnt_to_nfs[] = {
103 * Map an NFS version into the corresponding Mountd version
105 unsigned long nfsvers_to_mnt(const unsigned long vers)
108 return nfs_to_mnt[vers];
113 * Map a Mountd version into the corresponding NFS version
115 static unsigned long mntvers_to_nfs(const unsigned long vers)
118 return mnt_to_nfs[vers];
122 static const unsigned int probe_udp_only[] = {
127 static const unsigned int probe_udp_first[] = {
133 static const unsigned int probe_tcp_first[] = {
139 static const unsigned long probe_nfs2_only[] = {
144 static const unsigned long probe_nfs3_first[] = {
150 static const unsigned long probe_mnt1_first[] = {
156 static const unsigned long probe_mnt3_first[] = {
164 * nfs_name_to_address - resolve hostname to an IPv4 or IPv6 socket address
165 * @hostname: pointer to C string containing DNS hostname to resolve
166 * @sap: pointer to buffer to fill with socket address
167 * @len: IN: size of buffer to fill; OUT: size of socket address
169 * Returns 1 and places a socket address at @sap if successful;
172 int nfs_name_to_address(const char *hostname,
173 const sa_family_t af_hint,
174 struct sockaddr *sap, socklen_t *salen)
176 struct addrinfo *gai_results;
177 struct addrinfo gai_hint = {
178 .ai_family = af_hint,
179 .ai_flags = AI_ADDRCONFIG,
181 socklen_t len = *salen;
184 if (af_hint == AF_INET6)
185 gai_hint.ai_flags |= AI_V4MAPPED|AI_ALL;
189 error = getaddrinfo(hostname, NULL, &gai_hint, &gai_results);
191 nfs_error(_("%s: DNS resolution failed for %s: %s"),
192 progname, hostname, (error == EAI_SYSTEM ?
193 strerror(errno) : gai_strerror(error)));
197 switch (gai_results->ai_addr->sa_family) {
200 if (len >= gai_results->ai_addrlen) {
201 *salen = gai_results->ai_addrlen;
202 memcpy(sap, gai_results->ai_addr, *salen);
207 /* things are really broken if we get here, so warn */
208 nfs_error(_("%s: unrecognized DNS resolution results for %s"),
213 freeaddrinfo(gai_results);
218 * nfs_gethostbyname - resolve a hostname to an IPv4 address
219 * @hostname: pointer to a C string containing a DNS hostname
220 * @saddr: returns an IPv4 address
222 * Returns 1 if successful, otherwise zero.
224 int nfs_gethostbyname(const char *hostname, struct sockaddr_in *sin)
226 socklen_t len = sizeof(*sin);
228 return nfs_name_to_address(hostname, AF_INET,
229 (struct sockaddr *)sin, &len);
233 * nfs_string_to_sockaddr - convert string address to sockaddr
234 * @address: pointer to presentation format address to convert
235 * @addrlen: length of presentation address
236 * @sap: pointer to socket address buffer to fill in
237 * @salen: IN: length of address buffer
238 * OUT: length of converted socket address
240 * Convert a presentation format address string to a socket address.
241 * Similar to nfs_name_to_address(), but the DNS query is squelched,
242 * and won't make any noise if the getaddrinfo() call fails.
244 * Returns 1 and fills in @sap and @salen if successful; otherwise zero.
246 * See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
247 * on presenting IPv6 addresses as text strings.
249 int nfs_string_to_sockaddr(const char *address, const size_t addrlen,
250 struct sockaddr *sap, socklen_t *salen)
252 struct addrinfo *gai_results;
253 struct addrinfo gai_hint = {
254 .ai_flags = AI_NUMERICHOST,
256 socklen_t len = *salen;
261 if (getaddrinfo(address, NULL, &gai_hint, &gai_results) == 0) {
262 switch (gai_results->ai_addr->sa_family) {
265 if (len >= gai_results->ai_addrlen) {
266 *salen = gai_results->ai_addrlen;
267 memcpy(sap, gai_results->ai_addr, *salen);
272 freeaddrinfo(gai_results);
279 * nfs_present_sockaddr - convert sockaddr to string
280 * @sap: pointer to socket address to convert
281 * @salen: length of socket address
282 * @buf: pointer to buffer to fill in
283 * @buflen: length of buffer
285 * Convert the passed-in sockaddr-style address to presentation format.
286 * The presentation format address is placed in @buf and is
289 * Returns 1 if successful; otherwise zero.
291 * See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
292 * on presenting IPv6 addresses as text strings.
294 int nfs_present_sockaddr(const struct sockaddr *sap, const socklen_t salen,
295 char *buf, const size_t buflen)
297 #ifdef HAVE_GETNAMEINFO
300 result = getnameinfo(sap, salen, buf, buflen,
301 NULL, 0, NI_NUMERICHOST);
305 nfs_error(_("%s: invalid server address: %s"), progname,
306 gai_strerror(result));
308 #else /* HAVE_GETNAMEINFO */
311 if (sap->sa_family == AF_INET) {
312 addr = inet_ntoa(((struct sockaddr_in *)sap)->sin_addr);
313 if (addr && strlen(addr) < buflen) {
319 nfs_error(_("%s: invalid server address"), progname);
321 #endif /* HAVE_GETNAMEINFO */
325 * Attempt to connect a socket, but time out after "timeout" seconds.
327 * On error return, caller closes the socket.
329 static int connect_to(int fd, struct sockaddr *addr,
330 socklen_t addrlen, int timeout)
334 struct timeval tv = {
338 saved = fcntl(fd, F_GETFL, 0);
339 fcntl(fd, F_SETFL, saved | O_NONBLOCK);
341 ret = connect(fd, addr, addrlen);
342 if (ret < 0 && errno != EINPROGRESS)
350 ret = select(fd + 1, &rset, &wset, NULL, &tv);
355 if (FD_ISSET(fd, &rset) || FD_ISSET(fd, &wset)) {
357 socklen_t len = sizeof(error);
358 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
368 fcntl(fd, F_SETFL, saved);
373 * Create a socket that is locally bound to a reserved or non-reserved port.
375 * The caller should check rpc_createerr to determine the cause of any error.
377 static int get_socket(struct sockaddr_in *saddr, unsigned int p_prot,
378 unsigned int timeout, int resvp, int conn)
381 struct sockaddr_in laddr;
382 socklen_t namelen = sizeof(laddr);
384 type = (p_prot == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM);
385 if ((so = socket (AF_INET, type, p_prot)) < 0)
388 laddr.sin_family = AF_INET;
390 laddr.sin_addr.s_addr = htonl(INADDR_ANY);
392 if (bindresvport(so, &laddr) < 0)
393 goto err_bindresvport;
395 cc = bind(so, (struct sockaddr *)&laddr, namelen);
399 if (type == SOCK_STREAM || (conn && type == SOCK_DGRAM)) {
400 cc = connect_to(so, (struct sockaddr *)saddr, namelen,
408 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
409 rpc_createerr.cf_error.re_errno = errno;
411 nfs_error(_("%s: Unable to create %s socket: errno %d (%s)\n"),
412 progname, p_prot == IPPROTO_UDP ? _("UDP") : _("TCP"),
413 errno, strerror(errno));
418 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
419 rpc_createerr.cf_error.re_errno = errno;
421 nfs_error(_("%s: Unable to bindresvport %s socket: errno %d"
423 progname, p_prot == IPPROTO_UDP ? _("UDP") : _("TCP"),
424 errno, strerror(errno));
430 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
431 rpc_createerr.cf_error.re_errno = errno;
433 nfs_error(_("%s: Unable to bind to %s socket: errno %d (%s)\n"),
434 progname, p_prot == IPPROTO_UDP ? _("UDP") : _("TCP"),
435 errno, strerror(errno));
441 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
442 rpc_createerr.cf_error.re_errno = errno;
444 nfs_error(_("%s: Unable to connect to %s:%d, errno %d (%s)\n"),
445 progname, inet_ntoa(saddr->sin_addr),
446 ntohs(saddr->sin_port), errno, strerror(errno));
452 static void nfs_pp_debug(const struct sockaddr *sap, const socklen_t salen,
453 const rpcprog_t program, const rpcvers_t version,
454 const unsigned short protocol,
455 const unsigned short port)
457 char buf[NI_MAXHOST];
462 if (nfs_present_sockaddr(sap, salen, buf, sizeof(buf)) == 0) {
464 strcat(buf, "unknown host");
467 fprintf(stderr, _("%s: trying %s prog %ld vers %ld prot %s port %d\n"),
468 progname, buf, program, version,
469 (protocol == IPPROTO_UDP ? _("UDP") : _("TCP")),
474 * Use the portmapper to discover whether or not the service we want is
475 * available. The lists 'versions' and 'protos' define ordered sequences
476 * of service versions and udp/tcp protocols to probe for.
478 static int probe_port(clnt_addr_t *server, const unsigned long *versions,
479 const unsigned int *protos)
481 const struct sockaddr *saddr = (struct sockaddr *)&server->saddr;
482 const socklen_t salen = sizeof(server->saddr);
483 struct pmap *pmap = &server->pmap;
484 const unsigned long prog = pmap->pm_prog, *p_vers;
485 const unsigned int prot = (u_int)pmap->pm_prot, *p_prot;
486 const u_short port = (u_short) pmap->pm_port;
487 unsigned long vers = pmap->pm_vers;
488 unsigned short p_port;
490 p_prot = prot ? &prot : protos;
491 p_vers = vers ? &vers : versions;
492 rpc_createerr.cf_stat = 0;
494 p_port = nfs_getport(saddr, salen, prog, *p_vers, *p_prot);
496 if (!port || port == p_port) {
497 server->saddr.sin_port = htons(p_port);
498 nfs_pp_debug(saddr, salen, prog, *p_vers,
500 if (nfs_rpc_ping(saddr, salen, prog,
501 *p_vers, *p_prot, NULL))
505 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
506 rpc_createerr.cf_stat != RPC_TIMEDOUT &&
507 rpc_createerr.cf_stat != RPC_CANTRECV &&
508 rpc_createerr.cf_stat != RPC_PROGVERSMISMATCH)
516 if (rpc_createerr.cf_stat == RPC_TIMEDOUT ||
517 rpc_createerr.cf_stat == RPC_CANTRECV)
520 if (vers || !*++p_vers)
529 pmap->pm_vers = *p_vers;
531 pmap->pm_prot = *p_prot;
533 pmap->pm_port = p_port;
534 rpc_createerr.cf_stat = 0;
538 static int probe_nfsport(clnt_addr_t *nfs_server)
540 struct pmap *pmap = &nfs_server->pmap;
542 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
545 if (nfs_mount_data_version >= 4)
546 return probe_port(nfs_server, probe_nfs3_first, probe_tcp_first);
548 return probe_port(nfs_server, probe_nfs2_only, probe_udp_only);
551 static int probe_mntport(clnt_addr_t *mnt_server)
553 struct pmap *pmap = &mnt_server->pmap;
555 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
558 if (nfs_mount_data_version >= 4)
559 return probe_port(mnt_server, probe_mnt3_first, probe_udp_first);
561 return probe_port(mnt_server, probe_mnt1_first, probe_udp_only);
565 * probe_bothports - discover the RPC endpoints of mountd and NFS server
566 * @mnt_server: pointer to address and pmap argument for mountd results
567 * @nfs_server: pointer to address and pmap argument for NFS server
569 * Returns 1 if successful, otherwise zero if some error occurred.
570 * Note that the arguments are both input and output arguments.
572 * A side effect of calling this function is that rpccreateerr is set.
574 int probe_bothports(clnt_addr_t *mnt_server, clnt_addr_t *nfs_server)
576 struct pmap *nfs_pmap = &nfs_server->pmap;
577 struct pmap *mnt_pmap = &mnt_server->pmap;
578 struct pmap save_nfs, save_mnt;
580 const unsigned long *probe_vers;
582 if (mnt_pmap->pm_vers && !nfs_pmap->pm_vers)
583 nfs_pmap->pm_vers = mntvers_to_nfs(mnt_pmap->pm_vers);
584 else if (nfs_pmap->pm_vers && !mnt_pmap->pm_vers)
585 mnt_pmap->pm_vers = nfsvers_to_mnt(nfs_pmap->pm_vers);
586 if (nfs_pmap->pm_vers)
589 memcpy(&save_nfs, nfs_pmap, sizeof(save_nfs));
590 memcpy(&save_mnt, mnt_pmap, sizeof(save_mnt));
591 probe_vers = (nfs_mount_data_version >= 4) ?
592 probe_mnt3_first : probe_mnt1_first;
594 for (; *probe_vers; probe_vers++) {
595 nfs_pmap->pm_vers = mntvers_to_nfs(*probe_vers);
596 if ((res = probe_nfsport(nfs_server) != 0)) {
597 mnt_pmap->pm_vers = *probe_vers;
598 if ((res = probe_mntport(mnt_server)) != 0)
600 memcpy(mnt_pmap, &save_mnt, sizeof(*mnt_pmap));
602 switch (rpc_createerr.cf_stat) {
603 case RPC_PROGVERSMISMATCH:
604 case RPC_PROGNOTREGISTERED:
609 memcpy(nfs_pmap, &save_nfs, sizeof(*nfs_pmap));
616 if (!probe_nfsport(nfs_server))
618 return probe_mntport(mnt_server);
621 static int nfs_probe_statd(void)
623 struct sockaddr_in addr = {
624 .sin_family = AF_INET,
625 .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
627 rpcprog_t program = nfs_getrpcbyname(NSMPROG, nfs_ns_pgmtbl);
629 return nfs_getport_ping((struct sockaddr *)&addr, sizeof(addr),
630 program, (rpcvers_t)1, IPPROTO_UDP);
634 * start_statd - attempt to start rpc.statd
636 * Returns 1 if statd is running; otherwise zero.
638 int start_statd(void)
644 if (nfs_probe_statd())
648 if (stat(START_STATD, &stb) == 0) {
649 if (S_ISREG(stb.st_mode) && (stb.st_mode & S_IXUSR)) {
653 execl(START_STATD, START_STATD, NULL);
656 nfs_error(_("fork failed: %s"),
659 default: /* parent */
660 waitpid(pid, NULL,0);
663 if (nfs_probe_statd())
673 * nfs_call_umount - ask the server to remove a share from it's rmtab
674 * @mnt_server: address of RPC MNT program server
675 * @argp: directory path of share to "unmount"
677 * Returns one if the unmount call succeeded; zero if the unmount
678 * failed for any reason.
680 * Note that a side effect of calling this function is that rpccreateerr
683 int nfs_call_umount(clnt_addr_t *mnt_server, dirpath *argp)
686 enum clnt_stat res = 0;
689 if (!probe_mntport(mnt_server))
691 clnt = mnt_openclnt(mnt_server, &msock);
694 res = clnt_call(clnt, MOUNTPROC_UMNT,
695 (xdrproc_t)xdr_dirpath, (caddr_t)argp,
696 (xdrproc_t)xdr_void, NULL,
698 mnt_closeclnt(clnt, msock);
700 if (res == RPC_SUCCESS)
706 * mnt_openclnt - get a handle for a remote mountd service
707 * @mnt_server: address and pmap arguments of mountd service
708 * @msock: returns a file descriptor of the underlying transport socket
710 * Returns an active handle for the remote's mountd service
712 CLIENT *mnt_openclnt(clnt_addr_t *mnt_server, int *msock)
714 struct sockaddr_in *mnt_saddr = &mnt_server->saddr;
715 struct pmap *mnt_pmap = &mnt_server->pmap;
718 mnt_saddr->sin_port = htons((u_short)mnt_pmap->pm_port);
719 *msock = get_socket(mnt_saddr, mnt_pmap->pm_prot, MOUNT_TIMEOUT,
721 if (*msock == RPC_ANYSOCK) {
722 if (rpc_createerr.cf_error.re_errno == EADDRINUSE)
724 * Probably in-use by a TIME_WAIT connection,
725 * It is worth waiting a while and trying again.
727 rpc_createerr.cf_stat = RPC_TIMEDOUT;
731 switch (mnt_pmap->pm_prot) {
733 clnt = clntudp_bufcreate(mnt_saddr,
734 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
735 RETRY_TIMEOUT, msock,
736 MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
739 clnt = clnttcp_create(mnt_saddr,
740 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
742 MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
746 /* try to mount hostname:dirname */
747 clnt->cl_auth = authunix_create_default();
754 * mnt_closeclnt - terminate a handle for a remote mountd service
755 * @clnt: pointer to an active handle for a remote mountd service
756 * @msock: file descriptor of the underlying transport socket
759 void mnt_closeclnt(CLIENT *clnt, int msock)
761 auth_destroy(clnt->cl_auth);
767 * clnt_ping - send an RPC ping to the remote RPC service endpoint
768 * @saddr: server's address
769 * @prog: target RPC program number
770 * @vers: target RPC version number
771 * @prot: target RPC protocol
772 * @caddr: filled in with our network address
774 * Sigh... GETPORT queries don't actually check the version number.
775 * In order to make sure that the server actually supports the service
776 * we're requesting, we open an RPC client, and fire off a NULL
779 * caddr is the network address that the server will use to call us back.
780 * On multi-homed clients, this address depends on which NIC we use to
781 * route requests to the server.
783 * Returns one if successful, otherwise zero.
785 int clnt_ping(struct sockaddr_in *saddr, const unsigned long prog,
786 const unsigned long vers, const unsigned int prot,
787 struct sockaddr_in *caddr)
791 static char clnt_res;
792 struct sockaddr dissolve;
794 rpc_createerr.cf_stat = stat = 0;
795 sock = get_socket(saddr, prot, CONNECT_TIMEOUT, FALSE, TRUE);
796 if (sock == RPC_ANYSOCK) {
797 if (rpc_createerr.cf_error.re_errno == ETIMEDOUT) {
799 * TCP timeout. Bubble up the error to see
800 * how it should be handled.
802 rpc_createerr.cf_stat = RPC_TIMEDOUT;
808 /* Get the address of our end of this connection */
809 socklen_t len = sizeof(*caddr);
810 if (getsockname(sock, caddr, &len) != 0)
811 caddr->sin_family = 0;
816 /* The socket is connected (so we could getsockname successfully),
817 * but some servers on multi-homed hosts reply from
818 * the wrong address, so if we stay connected, we lose the reply.
820 dissolve.sa_family = AF_UNSPEC;
821 connect(sock, &dissolve, sizeof(dissolve));
823 clnt = clntudp_bufcreate(saddr, prog, vers,
824 RETRY_TIMEOUT, &sock,
825 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
828 clnt = clnttcp_create(saddr, prog, vers, &sock,
829 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
836 memset(&clnt_res, 0, sizeof(clnt_res));
837 stat = clnt_call(clnt, NULLPROC,
838 (xdrproc_t)xdr_void, (caddr_t)NULL,
839 (xdrproc_t)xdr_void, (caddr_t)&clnt_res,
842 clnt_geterr(clnt, &rpc_createerr.cf_error);
843 rpc_createerr.cf_stat = stat;
848 if (stat == RPC_SUCCESS)
855 * Try a getsockname() on a connected datagram socket.
857 * Returns 1 and fills in @buf if successful; otherwise, zero.
859 * A connected datagram socket prevents leaving a socket in TIME_WAIT.
860 * This conserves the ephemeral port number space, helping reduce failed
861 * socket binds during mount storms.
863 static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
864 struct sockaddr *buf, socklen_t *buflen)
866 struct sockaddr_in sin = {
867 .sin_family = AF_INET,
868 .sin_addr.s_addr = htonl(INADDR_ANY),
870 struct sockaddr_in6 sin6 = {
871 .sin6_family = AF_INET6,
872 .sin6_addr = IN6ADDR_ANY_INIT,
876 sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP);
880 switch (sap->sa_family) {
882 if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
888 if (bind(sock, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
894 errno = EAFNOSUPPORT;
898 if (connect(sock, sap, salen) < 0) {
903 return !getsockname(sock, buf, buflen);
907 * Try to generate an address that prevents the server from calling us.
909 * Returns 1 and fills in @buf if successful; otherwise, zero.
911 static int nfs_ca_gai(const struct sockaddr *sap, const socklen_t salen,
912 struct sockaddr *buf, socklen_t *buflen)
914 struct addrinfo *gai_results;
915 struct addrinfo gai_hint = {
916 .ai_family = sap->sa_family,
917 .ai_flags = AI_PASSIVE, /* ANYADDR */
920 if (getaddrinfo(NULL, "", &gai_hint, &gai_results))
923 *buflen = gai_results->ai_addrlen;
924 memcpy(buf, gai_results->ai_addr, *buflen);
926 freeaddrinfo(gai_results);
932 * nfs_callback_address - acquire our local network address
933 * @sap: pointer to address of remote
934 * @sap_len: length of address
935 * @buf: pointer to buffer to be filled in with local network address
936 * @buflen: IN: length of buffer to fill in; OUT: length of filled-in address
938 * Discover a network address that an NFSv4 server can use to call us back.
939 * On multi-homed clients, this address depends on which NIC we use to
940 * route requests to the server.
942 * Returns 1 and fills in @buf if an unambiguous local address is
943 * available; returns 1 and fills in an appropriate ANYADDR address
944 * if a local address isn't available; otherwise, returns zero.
946 int nfs_callback_address(const struct sockaddr *sap, const socklen_t salen,
947 struct sockaddr *buf, socklen_t *buflen)
949 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf;
951 if (nfs_ca_sockname(sap, salen, buf, buflen) == 0)
952 if (nfs_ca_gai(sap, salen, buf, buflen) == 0)
956 * The server can't use an interface ID that was generated
957 * here on the client, so always clear sin6_scope_id.
959 if (sin6->sin6_family == AF_INET6)
960 sin6->sin6_scope_id = 0;
967 nfs_error(_("%s: failed to construct callback address"));