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))
537 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
538 rpc_createerr.cf_stat != RPC_TIMEDOUT &&
539 rpc_createerr.cf_stat != RPC_PROGVERSMISMATCH)
547 if (rpc_createerr.cf_stat == RPC_TIMEDOUT)
550 if (vers || !*++p_vers)
559 pmap->pm_vers = *p_vers;
561 pmap->pm_prot = *p_prot;
563 pmap->pm_port = p_port;
564 rpc_createerr.cf_stat = 0;
568 static int probe_nfsport(clnt_addr_t *nfs_server)
570 struct pmap *pmap = &nfs_server->pmap;
572 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
575 if (nfs_mount_data_version >= 4)
576 return probe_port(nfs_server, probe_nfs3_first, probe_tcp_first);
578 return probe_port(nfs_server, probe_nfs2_only, probe_udp_only);
581 static int probe_mntport(clnt_addr_t *mnt_server)
583 struct pmap *pmap = &mnt_server->pmap;
585 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
588 if (nfs_mount_data_version >= 4)
589 return probe_port(mnt_server, probe_mnt3_first, probe_udp_first);
591 return probe_port(mnt_server, probe_mnt1_first, probe_udp_only);
595 * probe_bothports - discover the RPC endpoints of mountd and NFS server
596 * @mnt_server: pointer to address and pmap argument for mountd results
597 * @nfs_server: pointer to address and pmap argument for NFS server
599 * Returns 1 if successful, otherwise zero if some error occurred.
600 * Note that the arguments are both input and output arguments.
602 * A side effect of calling this function is that rpccreateerr is set.
604 int probe_bothports(clnt_addr_t *mnt_server, clnt_addr_t *nfs_server)
606 struct pmap *nfs_pmap = &nfs_server->pmap;
607 struct pmap *mnt_pmap = &mnt_server->pmap;
608 struct pmap save_nfs, save_mnt;
610 const unsigned long *probe_vers;
612 if (mnt_pmap->pm_vers && !nfs_pmap->pm_vers)
613 nfs_pmap->pm_vers = mntvers_to_nfs(mnt_pmap->pm_vers);
614 else if (nfs_pmap->pm_vers && !mnt_pmap->pm_vers)
615 mnt_pmap->pm_vers = nfsvers_to_mnt(nfs_pmap->pm_vers);
616 if (nfs_pmap->pm_vers)
619 memcpy(&save_nfs, nfs_pmap, sizeof(save_nfs));
620 memcpy(&save_mnt, mnt_pmap, sizeof(save_mnt));
621 probe_vers = (nfs_mount_data_version >= 4) ?
622 probe_mnt3_first : probe_mnt1_first;
624 for (; *probe_vers; probe_vers++) {
625 nfs_pmap->pm_vers = mntvers_to_nfs(*probe_vers);
626 if ((res = probe_nfsport(nfs_server) != 0)) {
627 mnt_pmap->pm_vers = *probe_vers;
628 if ((res = probe_mntport(mnt_server)) != 0)
630 memcpy(mnt_pmap, &save_mnt, sizeof(*mnt_pmap));
632 switch (rpc_createerr.cf_stat) {
633 case RPC_PROGVERSMISMATCH:
634 case RPC_PROGNOTREGISTERED:
639 memcpy(nfs_pmap, &save_nfs, sizeof(*nfs_pmap));
646 if (!probe_nfsport(nfs_server))
648 return probe_mntport(mnt_server);
651 static int probe_statd(void)
653 struct sockaddr_in addr;
656 memset(&addr, 0, sizeof(addr));
657 addr.sin_family = AF_INET;
658 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
659 port = getport(&addr, 100024, 1, IPPROTO_UDP);
663 addr.sin_port = htons(port);
665 if (clnt_ping(&addr, 100024, 1, IPPROTO_UDP, NULL) <= 0)
672 * start_statd - attempt to start rpc.statd
674 * Returns 1 if statd is running; otherwise zero.
676 int start_statd(void)
686 if (stat(START_STATD, &stb) == 0) {
687 if (S_ISREG(stb.st_mode) && (stb.st_mode & S_IXUSR)) {
699 * nfs_call_umount - ask the server to remove a share from it's rmtab
700 * @mnt_server: address of RPC MNT program server
701 * @argp: directory path of share to "unmount"
703 * Returns one if the unmount call succeeded; zero if the unmount
704 * failed for any reason.
706 * Note that a side effect of calling this function is that rpccreateerr
709 int nfs_call_umount(clnt_addr_t *mnt_server, dirpath *argp)
712 enum clnt_stat res = 0;
715 if (!probe_mntport(mnt_server))
717 clnt = mnt_openclnt(mnt_server, &msock);
720 res = clnt_call(clnt, MOUNTPROC_UMNT,
721 (xdrproc_t)xdr_dirpath, (caddr_t)argp,
722 (xdrproc_t)xdr_void, NULL,
724 mnt_closeclnt(clnt, msock);
726 if (res == RPC_SUCCESS)
732 * mnt_openclnt - get a handle for a remote mountd service
733 * @mnt_server: address and pmap arguments of mountd service
734 * @msock: returns a file descriptor of the underlying transport socket
736 * Returns an active handle for the remote's mountd service
738 CLIENT *mnt_openclnt(clnt_addr_t *mnt_server, int *msock)
740 struct sockaddr_in *mnt_saddr = &mnt_server->saddr;
741 struct pmap *mnt_pmap = &mnt_server->pmap;
744 mnt_saddr->sin_port = htons((u_short)mnt_pmap->pm_port);
745 *msock = get_socket(mnt_saddr, mnt_pmap->pm_prot, MOUNT_TIMEOUT,
747 if (*msock == RPC_ANYSOCK) {
748 if (rpc_createerr.cf_error.re_errno == EADDRINUSE)
750 * Probably in-use by a TIME_WAIT connection,
751 * It is worth waiting a while and trying again.
753 rpc_createerr.cf_stat = RPC_TIMEDOUT;
757 switch (mnt_pmap->pm_prot) {
759 clnt = clntudp_bufcreate(mnt_saddr,
760 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
761 RETRY_TIMEOUT, msock,
762 MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
765 clnt = clnttcp_create(mnt_saddr,
766 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
768 MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
772 /* try to mount hostname:dirname */
773 clnt->cl_auth = authunix_create_default();
780 * mnt_closeclnt - terminate a handle for a remote mountd service
781 * @clnt: pointer to an active handle for a remote mountd service
782 * @msock: file descriptor of the underlying transport socket
785 void mnt_closeclnt(CLIENT *clnt, int msock)
787 auth_destroy(clnt->cl_auth);
793 * clnt_ping - send an RPC ping to the remote RPC service endpoint
794 * @saddr: server's address
795 * @prog: target RPC program number
796 * @vers: target RPC version number
797 * @prot: target RPC protocol
798 * @caddr: filled in with our network address
800 * Sigh... getport() doesn't actually check the version number.
801 * In order to make sure that the server actually supports the service
802 * we're requesting, we open and RPC client, and fire off a NULL
805 * caddr is the network address that the server will use to call us back.
806 * On multi-homed clients, this address depends on which NIC we use to
807 * route requests to the server.
809 * Returns one if successful, otherwise zero.
811 int clnt_ping(struct sockaddr_in *saddr, const unsigned long prog,
812 const unsigned long vers, const unsigned int prot,
813 struct sockaddr_in *caddr)
817 static char clnt_res;
818 struct sockaddr dissolve;
820 rpc_createerr.cf_stat = stat = 0;
821 sock = get_socket(saddr, prot, CONNECT_TIMEOUT, FALSE, TRUE);
822 if (sock == RPC_ANYSOCK) {
823 if (rpc_createerr.cf_error.re_errno == ETIMEDOUT) {
825 * TCP timeout. Bubble up the error to see
826 * how it should be handled.
828 rpc_createerr.cf_stat = RPC_TIMEDOUT;
834 /* Get the address of our end of this connection */
835 socklen_t len = sizeof(*caddr);
836 if (getsockname(sock, caddr, &len) != 0)
837 caddr->sin_family = 0;
842 /* The socket is connected (so we could getsockname successfully),
843 * but some servers on multi-homed hosts reply from
844 * the wrong address, so if we stay connected, we lose the reply.
846 dissolve.sa_family = AF_UNSPEC;
847 connect(sock, &dissolve, sizeof(dissolve));
849 clnt = clntudp_bufcreate(saddr, prog, vers,
850 RETRY_TIMEOUT, &sock,
851 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
854 clnt = clnttcp_create(saddr, prog, vers, &sock,
855 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
862 memset(&clnt_res, 0, sizeof(clnt_res));
863 stat = clnt_call(clnt, NULLPROC,
864 (xdrproc_t)xdr_void, (caddr_t)NULL,
865 (xdrproc_t)xdr_void, (caddr_t)&clnt_res,
868 clnt_geterr(clnt, &rpc_createerr.cf_error);
869 rpc_createerr.cf_stat = stat;
874 if (stat == RPC_SUCCESS)
881 * Try a getsockname() on a connected datagram socket.
883 * Returns 1 and fills in @buf if successful; otherwise, zero.
885 * A connected datagram socket prevents leaving a socket in TIME_WAIT.
886 * This conserves the ephemeral port number space, helping reduce failed
887 * socket binds during mount storms.
889 static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
890 struct sockaddr *buf, socklen_t *buflen)
892 struct sockaddr_in sin = {
893 .sin_family = AF_INET,
894 .sin_addr.s_addr = htonl(INADDR_ANY),
896 struct sockaddr_in6 sin6 = {
897 .sin6_family = AF_INET6,
898 .sin6_addr = IN6ADDR_ANY_INIT,
902 sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP);
906 switch (sap->sa_family) {
908 if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
914 if (bind(sock, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
920 errno = EAFNOSUPPORT;
924 if (connect(sock, sap, salen) < 0) {
929 return !getsockname(sock, buf, buflen);
933 * Try to generate an address that prevents the server from calling us.
935 * Returns 1 and fills in @buf if successful; otherwise, zero.
937 static int nfs_ca_gai(const struct sockaddr *sap, const socklen_t salen,
938 struct sockaddr *buf, socklen_t *buflen)
940 struct addrinfo *gai_results;
941 struct addrinfo gai_hint = {
942 .ai_family = sap->sa_family,
943 .ai_flags = AI_PASSIVE, /* ANYADDR */
946 if (getaddrinfo(NULL, "", &gai_hint, &gai_results))
949 *buflen = gai_results->ai_addrlen;
950 memcpy(buf, gai_results->ai_addr, *buflen);
952 freeaddrinfo(gai_results);
958 * nfs_callback_address - acquire our local network address
959 * @sap: pointer to address of remote
960 * @sap_len: length of address
961 * @buf: pointer to buffer to be filled in with local network address
962 * @buflen: IN: length of buffer to fill in; OUT: length of filled-in address
964 * Discover a network address that an NFSv4 server can use to call us back.
965 * On multi-homed clients, this address depends on which NIC we use to
966 * route requests to the server.
968 * Returns 1 and fills in @buf if an unambiguous local address is
969 * available; returns 1 and fills in an appropriate ANYADDR address
970 * if a local address isn't available; otherwise, returns zero.
972 int nfs_callback_address(const struct sockaddr *sap, const socklen_t salen,
973 struct sockaddr *buf, socklen_t *buflen)
975 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf;
977 if (nfs_ca_sockname(sap, salen, buf, buflen) == 0)
978 if (nfs_ca_gai(sap, salen, buf, buflen) == 0)
982 * The server can't use an interface ID that was generated
983 * here on the client, so always clear sin6_scope_id.
985 if (sin6->sin6_family == AF_INET6)
986 sin6->sin6_scope_id = 0;
993 nfs_error(_("%s: failed to construct callback address"));