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 #ifdef HAVE_RPCSVC_NFS_PROT_H
52 #include <rpcsvc/nfs_prot.h>
54 #include <linux/nfs.h>
55 #define nfsstat nfs_stat
62 #define PMAP_TIMEOUT (10)
63 #define CONNECT_TIMEOUT (20)
64 #define MOUNT_TIMEOUT (30)
66 #if SIZEOF_SOCKLEN_T - 0 == 0
67 #define socklen_t unsigned int
70 extern int nfs_mount_data_version;
71 extern char *progname;
74 static const unsigned long nfs_to_mnt[] = {
81 static const unsigned long mnt_to_nfs[] = {
89 * Map an NFS version into the corresponding Mountd version
91 unsigned long nfsvers_to_mnt(const unsigned long vers)
94 return nfs_to_mnt[vers];
99 * Map a Mountd version into the corresponding NFS version
101 static unsigned long mntvers_to_nfs(const unsigned long vers)
104 return mnt_to_nfs[vers];
108 static const unsigned int probe_udp_only[] = {
113 static const unsigned int probe_udp_first[] = {
119 static const unsigned int probe_tcp_first[] = {
125 static const unsigned long probe_nfs2_only[] = {
130 static const unsigned long probe_nfs3_first[] = {
136 static const unsigned long probe_mnt1_first[] = {
142 static const unsigned long probe_mnt3_first[] = {
150 * nfs_name_to_address - resolve hostname to an IPv4 or IPv6 socket address
151 * @hostname: pointer to C string containing DNS hostname to resolve
152 * @sap: pointer to buffer to fill with socket address
153 * @len: IN: size of buffer to fill; OUT: size of socket address
155 * Returns 1 and places a socket address at @sap if successful;
158 int nfs_name_to_address(const char *hostname,
159 const sa_family_t af_hint,
160 struct sockaddr *sap, socklen_t *salen)
162 struct addrinfo *gai_results;
163 struct addrinfo gai_hint = {
164 .ai_family = af_hint,
165 .ai_flags = AI_ADDRCONFIG,
167 socklen_t len = *salen;
170 if (af_hint == AF_INET6)
171 gai_hint.ai_flags |= AI_V4MAPPED|AI_ALL;
175 error = getaddrinfo(hostname, NULL, &gai_hint, &gai_results);
177 nfs_error(_("%s: DNS resolution failed for %s: %s"),
178 progname, hostname, (error == EAI_SYSTEM ?
179 strerror(errno) : gai_strerror(error)));
183 switch (gai_results->ai_addr->sa_family) {
186 if (len >= gai_results->ai_addrlen) {
187 *salen = gai_results->ai_addrlen;
188 memcpy(sap, gai_results->ai_addr, *salen);
193 /* things are really broken if we get here, so warn */
194 nfs_error(_("%s: unrecognized DNS resolution results for %s"),
199 freeaddrinfo(gai_results);
204 * nfs_gethostbyname - resolve a hostname to an IPv4 address
205 * @hostname: pointer to a C string containing a DNS hostname
206 * @saddr: returns an IPv4 address
208 * Returns 1 if successful, otherwise zero.
210 int nfs_gethostbyname(const char *hostname, struct sockaddr_in *sin)
212 socklen_t len = sizeof(*sin);
214 return nfs_name_to_address(hostname, AF_INET,
215 (struct sockaddr *)sin, &len);
219 * nfs_string_to_sockaddr - convert string address to sockaddr
220 * @address: pointer to presentation format address to convert
221 * @addrlen: length of presentation address
222 * @sap: pointer to socket address buffer to fill in
223 * @salen: IN: length of address buffer
224 * OUT: length of converted socket address
226 * Convert a presentation format address string to a socket address.
227 * Similar to nfs_name_to_address(), but the DNS query is squelched,
228 * and won't make any noise if the getaddrinfo() call fails.
230 * Returns 1 and fills in @sap and @salen if successful; otherwise zero.
232 * See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
233 * on presenting IPv6 addresses as text strings.
235 int nfs_string_to_sockaddr(const char *address, const size_t addrlen,
236 struct sockaddr *sap, socklen_t *salen)
238 struct addrinfo *gai_results;
239 struct addrinfo gai_hint = {
240 .ai_flags = AI_NUMERICHOST,
242 socklen_t len = *salen;
247 if (getaddrinfo(address, NULL, &gai_hint, &gai_results) == 0) {
248 switch (gai_results->ai_addr->sa_family) {
251 if (len >= gai_results->ai_addrlen) {
252 *salen = gai_results->ai_addrlen;
253 memcpy(sap, gai_results->ai_addr, *salen);
258 freeaddrinfo(gai_results);
265 * nfs_present_sockaddr - convert sockaddr to string
266 * @sap: pointer to socket address to convert
267 * @salen: length of socket address
268 * @buf: pointer to buffer to fill in
269 * @buflen: length of buffer
271 * Convert the passed-in sockaddr-style address to presentation format.
272 * The presentation format address is placed in @buf and is
275 * Returns 1 if successful; otherwise zero.
277 * See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
278 * on presenting IPv6 addresses as text strings.
280 int nfs_present_sockaddr(const struct sockaddr *sap, const socklen_t salen,
281 char *buf, const size_t buflen)
283 #ifdef HAVE_GETNAMEINFO
286 result = getnameinfo(sap, salen, buf, buflen,
287 NULL, 0, NI_NUMERICHOST);
291 nfs_error(_("%s: invalid server address: %s"), progname,
292 gai_strerror(result));
294 #else /* HAVE_GETNAMEINFO */
297 if (sap->sa_family == AF_INET) {
298 addr = inet_ntoa(((struct sockaddr_in *)sap)->sin_addr);
299 if (addr && strlen(addr) < buflen) {
305 nfs_error(_("%s: invalid server address"), progname);
307 #endif /* HAVE_GETNAMEINFO */
311 * Attempt to connect a socket, but time out after "timeout" seconds.
313 * On error return, caller closes the socket.
315 static int connect_to(int fd, struct sockaddr *addr,
316 socklen_t addrlen, int timeout)
320 struct timeval tv = {
324 saved = fcntl(fd, F_GETFL, 0);
325 fcntl(fd, F_SETFL, saved | O_NONBLOCK);
327 ret = connect(fd, addr, addrlen);
328 if (ret < 0 && errno != EINPROGRESS)
336 ret = select(fd + 1, &rset, &wset, NULL, &tv);
341 if (FD_ISSET(fd, &rset) || FD_ISSET(fd, &wset)) {
343 socklen_t len = sizeof(error);
344 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
354 fcntl(fd, F_SETFL, saved);
359 * Create a socket that is locally bound to a reserved or non-reserved port.
361 * The caller should check rpc_createerr to determine the cause of any error.
363 static int get_socket(struct sockaddr_in *saddr, unsigned int p_prot,
364 unsigned int timeout, int resvp, int conn)
367 struct sockaddr_in laddr;
368 socklen_t namelen = sizeof(laddr);
370 type = (p_prot == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM);
371 if ((so = socket (AF_INET, type, p_prot)) < 0)
374 laddr.sin_family = AF_INET;
376 laddr.sin_addr.s_addr = htonl(INADDR_ANY);
378 if (bindresvport(so, &laddr) < 0)
379 goto err_bindresvport;
381 cc = bind(so, (struct sockaddr *)&laddr, namelen);
385 if (type == SOCK_STREAM || (conn && type == SOCK_DGRAM)) {
386 cc = connect_to(so, (struct sockaddr *)saddr, namelen,
394 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
395 rpc_createerr.cf_error.re_errno = errno;
397 nfs_error(_("%s: Unable to create %s socket: errno %d (%s)\n"),
398 progname, p_prot == IPPROTO_UDP ? _("UDP") : _("TCP"),
399 errno, strerror(errno));
404 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
405 rpc_createerr.cf_error.re_errno = errno;
407 nfs_error(_("%s: Unable to bindresvport %s socket: errno %d"
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 bind to %s socket: errno %d (%s)\n"),
420 progname, p_prot == IPPROTO_UDP ? _("UDP") : _("TCP"),
421 errno, strerror(errno));
427 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
428 rpc_createerr.cf_error.re_errno = errno;
430 nfs_error(_("%s: Unable to connect to %s:%d, errno %d (%s)\n"),
431 progname, inet_ntoa(saddr->sin_addr),
432 ntohs(saddr->sin_port), errno, strerror(errno));
439 * getport() is very similar to pmap_getport() with the exception that
440 * this version tries to use an ephemeral port, since reserved ports are
441 * not needed for GETPORT queries. This conserves the very limited
442 * reserved port space, which helps reduce failed socket binds
443 * during mount storms.
445 * A side effect of calling this function is that rpccreateerr is set.
447 static unsigned short getport(struct sockaddr_in *saddr,
448 unsigned long program,
449 unsigned long version,
452 struct sockaddr_in bind_saddr;
453 unsigned short port = 0;
459 bind_saddr.sin_port = htons(PMAPPORT);
461 socket = get_socket(&bind_saddr, proto, PMAP_TIMEOUT, FALSE, FALSE);
462 if (socket == RPC_ANYSOCK) {
463 if (proto == IPPROTO_TCP &&
464 rpc_createerr.cf_error.re_errno == ETIMEDOUT)
465 rpc_createerr.cf_stat = RPC_TIMEDOUT;
471 clnt = clntudp_bufcreate(&bind_saddr,
473 RETRY_TIMEOUT, &socket,
478 clnt = clnttcp_create(&bind_saddr,
481 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
485 struct pmap parms = {
491 stat = clnt_call(clnt, PMAPPROC_GETPORT,
492 (xdrproc_t)xdr_pmap, (caddr_t)&parms,
493 (xdrproc_t)xdr_u_short, (caddr_t)&port,
496 clnt_geterr(clnt, &rpc_createerr.cf_error);
497 rpc_createerr.cf_stat = stat;
500 if (stat != RPC_SUCCESS)
503 rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
511 * Use the portmapper to discover whether or not the service we want is
512 * available. The lists 'versions' and 'protos' define ordered sequences
513 * of service versions and udp/tcp protocols to probe for.
515 static int probe_port(clnt_addr_t *server, const unsigned long *versions,
516 const unsigned int *protos)
518 struct sockaddr_in *saddr = &server->saddr;
519 struct pmap *pmap = &server->pmap;
520 const unsigned long prog = pmap->pm_prog, *p_vers;
521 const unsigned int prot = (u_int)pmap->pm_prot, *p_prot;
522 const u_short port = (u_short) pmap->pm_port;
523 unsigned long vers = pmap->pm_vers;
524 unsigned short p_port;
526 p_prot = prot ? &prot : protos;
527 p_vers = vers ? &vers : versions;
528 rpc_createerr.cf_stat = 0;
530 p_port = getport(saddr, prog, *p_vers, *p_prot);
532 if (!port || port == p_port) {
533 saddr->sin_port = htons(p_port);
535 printf(_("%s: trying %s prog %ld vers "
536 "%ld prot %s port %d\n"),
538 inet_ntoa(saddr->sin_addr),
540 *p_prot == IPPROTO_UDP ?
544 if (clnt_ping(saddr, prog, *p_vers, *p_prot, NULL))
546 if (rpc_createerr.cf_stat == RPC_TIMEDOUT)
550 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
551 rpc_createerr.cf_stat != RPC_PROGVERSMISMATCH)
559 if (vers || !*++p_vers)
568 pmap->pm_vers = *p_vers;
570 pmap->pm_prot = *p_prot;
572 pmap->pm_port = p_port;
573 rpc_createerr.cf_stat = 0;
577 static int probe_nfsport(clnt_addr_t *nfs_server)
579 struct pmap *pmap = &nfs_server->pmap;
581 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
584 if (nfs_mount_data_version >= 4)
585 return probe_port(nfs_server, probe_nfs3_first, probe_tcp_first);
587 return probe_port(nfs_server, probe_nfs2_only, probe_udp_only);
590 static int probe_mntport(clnt_addr_t *mnt_server)
592 struct pmap *pmap = &mnt_server->pmap;
594 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
597 if (nfs_mount_data_version >= 4)
598 return probe_port(mnt_server, probe_mnt3_first, probe_udp_first);
600 return probe_port(mnt_server, probe_mnt1_first, probe_udp_only);
604 * probe_bothports - discover the RPC endpoints of mountd and NFS server
605 * @mnt_server: pointer to address and pmap argument for mountd results
606 * @nfs_server: pointer to address and pmap argument for NFS server
608 * Returns 1 if successful, otherwise zero if some error occurred.
609 * Note that the arguments are both input and output arguments.
611 * A side effect of calling this function is that rpccreateerr is set.
613 int probe_bothports(clnt_addr_t *mnt_server, clnt_addr_t *nfs_server)
615 struct pmap *nfs_pmap = &nfs_server->pmap;
616 struct pmap *mnt_pmap = &mnt_server->pmap;
617 struct pmap save_nfs, save_mnt;
619 const unsigned long *probe_vers;
621 if (mnt_pmap->pm_vers && !nfs_pmap->pm_vers)
622 nfs_pmap->pm_vers = mntvers_to_nfs(mnt_pmap->pm_vers);
623 else if (nfs_pmap->pm_vers && !mnt_pmap->pm_vers)
624 mnt_pmap->pm_vers = nfsvers_to_mnt(nfs_pmap->pm_vers);
625 if (nfs_pmap->pm_vers)
628 memcpy(&save_nfs, nfs_pmap, sizeof(save_nfs));
629 memcpy(&save_mnt, mnt_pmap, sizeof(save_mnt));
630 probe_vers = (nfs_mount_data_version >= 4) ?
631 probe_mnt3_first : probe_mnt1_first;
633 for (; *probe_vers; probe_vers++) {
634 nfs_pmap->pm_vers = mntvers_to_nfs(*probe_vers);
635 if ((res = probe_nfsport(nfs_server) != 0)) {
636 mnt_pmap->pm_vers = *probe_vers;
637 if ((res = probe_mntport(mnt_server)) != 0)
639 memcpy(mnt_pmap, &save_mnt, sizeof(*mnt_pmap));
641 switch (rpc_createerr.cf_stat) {
642 case RPC_PROGVERSMISMATCH:
643 case RPC_PROGNOTREGISTERED:
648 memcpy(nfs_pmap, &save_nfs, sizeof(*nfs_pmap));
655 if (!probe_nfsport(nfs_server))
657 return probe_mntport(mnt_server);
660 static int probe_statd(void)
662 struct sockaddr_in addr;
665 memset(&addr, 0, sizeof(addr));
666 addr.sin_family = AF_INET;
667 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
668 port = getport(&addr, 100024, 1, IPPROTO_UDP);
672 addr.sin_port = htons(port);
674 if (clnt_ping(&addr, 100024, 1, IPPROTO_UDP, NULL) <= 0)
681 * start_statd - attempt to start rpc.statd
683 * Returns 1 if statd is running; otherwise zero.
685 int start_statd(void)
695 if (stat(START_STATD, &stb) == 0) {
696 if (S_ISREG(stb.st_mode) && (stb.st_mode & S_IXUSR)) {
708 * nfs_call_umount - ask the server to remove a share from it's rmtab
709 * @mnt_server: address of RPC MNT program server
710 * @argp: directory path of share to "unmount"
712 * Returns one if the unmount call succeeded; zero if the unmount
713 * failed for any reason.
715 * Note that a side effect of calling this function is that rpccreateerr
718 int nfs_call_umount(clnt_addr_t *mnt_server, dirpath *argp)
721 enum clnt_stat res = 0;
724 if (!probe_mntport(mnt_server))
726 clnt = mnt_openclnt(mnt_server, &msock);
729 res = clnt_call(clnt, MOUNTPROC_UMNT,
730 (xdrproc_t)xdr_dirpath, (caddr_t)argp,
731 (xdrproc_t)xdr_void, NULL,
733 mnt_closeclnt(clnt, msock);
735 if (res == RPC_SUCCESS)
741 * mnt_openclnt - get a handle for a remote mountd service
742 * @mnt_server: address and pmap arguments of mountd service
743 * @msock: returns a file descriptor of the underlying transport socket
745 * Returns an active handle for the remote's mountd service
747 CLIENT *mnt_openclnt(clnt_addr_t *mnt_server, int *msock)
749 struct sockaddr_in *mnt_saddr = &mnt_server->saddr;
750 struct pmap *mnt_pmap = &mnt_server->pmap;
753 mnt_saddr->sin_port = htons((u_short)mnt_pmap->pm_port);
754 *msock = get_socket(mnt_saddr, mnt_pmap->pm_prot, MOUNT_TIMEOUT,
756 if (*msock == RPC_ANYSOCK) {
757 if (rpc_createerr.cf_error.re_errno == EADDRINUSE)
759 * Probably in-use by a TIME_WAIT connection,
760 * It is worth waiting a while and trying again.
762 rpc_createerr.cf_stat = RPC_TIMEDOUT;
766 switch (mnt_pmap->pm_prot) {
768 clnt = clntudp_bufcreate(mnt_saddr,
769 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
770 RETRY_TIMEOUT, msock,
771 MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
774 clnt = clnttcp_create(mnt_saddr,
775 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
777 MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
781 /* try to mount hostname:dirname */
782 clnt->cl_auth = authunix_create_default();
789 * mnt_closeclnt - terminate a handle for a remote mountd service
790 * @clnt: pointer to an active handle for a remote mountd service
791 * @msock: file descriptor of the underlying transport socket
794 void mnt_closeclnt(CLIENT *clnt, int msock)
796 auth_destroy(clnt->cl_auth);
802 * clnt_ping - send an RPC ping to the remote RPC service endpoint
803 * @saddr: server's address
804 * @prog: target RPC program number
805 * @vers: target RPC version number
806 * @prot: target RPC protocol
807 * @caddr: filled in with our network address
809 * Sigh... getport() doesn't actually check the version number.
810 * In order to make sure that the server actually supports the service
811 * we're requesting, we open and RPC client, and fire off a NULL
814 * caddr is the network address that the server will use to call us back.
815 * On multi-homed clients, this address depends on which NIC we use to
816 * route requests to the server.
818 * Returns one if successful, otherwise zero.
820 int clnt_ping(struct sockaddr_in *saddr, const unsigned long prog,
821 const unsigned long vers, const unsigned int prot,
822 struct sockaddr_in *caddr)
826 static char clnt_res;
827 struct sockaddr dissolve;
829 rpc_createerr.cf_stat = stat = 0;
830 sock = get_socket(saddr, prot, CONNECT_TIMEOUT, FALSE, TRUE);
831 if (sock == RPC_ANYSOCK) {
832 if (rpc_createerr.cf_error.re_errno == ETIMEDOUT) {
834 * TCP timeout. Bubble up the error to see
835 * how it should be handled.
837 rpc_createerr.cf_stat = RPC_TIMEDOUT;
843 /* Get the address of our end of this connection */
844 socklen_t len = sizeof(*caddr);
845 if (getsockname(sock, caddr, &len) != 0)
846 caddr->sin_family = 0;
851 /* The socket is connected (so we could getsockname successfully),
852 * but some servers on multi-homed hosts reply from
853 * the wrong address, so if we stay connected, we lose the reply.
855 dissolve.sa_family = AF_UNSPEC;
856 connect(sock, &dissolve, sizeof(dissolve));
858 clnt = clntudp_bufcreate(saddr, prog, vers,
859 RETRY_TIMEOUT, &sock,
860 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
863 clnt = clnttcp_create(saddr, prog, vers, &sock,
864 RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
871 memset(&clnt_res, 0, sizeof(clnt_res));
872 stat = clnt_call(clnt, NULLPROC,
873 (xdrproc_t)xdr_void, (caddr_t)NULL,
874 (xdrproc_t)xdr_void, (caddr_t)&clnt_res,
877 clnt_geterr(clnt, &rpc_createerr.cf_error);
878 rpc_createerr.cf_stat = stat;
883 if (stat == RPC_SUCCESS)
890 * Try a getsockname() on a connected datagram socket.
892 * Returns 1 and fills in @buf if successful; otherwise, zero.
894 * A connected datagram socket prevents leaving a socket in TIME_WAIT.
895 * This conserves the ephemeral port number space, helping reduce failed
896 * socket binds during mount storms.
898 static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
899 struct sockaddr *buf, socklen_t *buflen)
901 struct sockaddr_in sin = {
902 .sin_family = AF_INET,
903 .sin_addr.s_addr = htonl(INADDR_ANY),
905 struct sockaddr_in6 sin6 = {
906 .sin6_family = AF_INET6,
907 .sin6_addr = IN6ADDR_ANY_INIT,
911 sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP);
915 switch (sap->sa_family) {
917 if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
923 if (bind(sock, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
929 errno = EAFNOSUPPORT;
933 if (connect(sock, sap, salen) < 0) {
938 return !getsockname(sock, buf, buflen);
942 * Try to generate an address that prevents the server from calling us.
944 * Returns 1 and fills in @buf if successful; otherwise, zero.
946 static int nfs_ca_gai(const struct sockaddr *sap, const socklen_t salen,
947 struct sockaddr *buf, socklen_t *buflen)
949 struct addrinfo *gai_results;
950 struct addrinfo gai_hint = {
951 .ai_family = sap->sa_family,
952 .ai_flags = AI_PASSIVE, /* ANYADDR */
955 if (getaddrinfo(NULL, "", &gai_hint, &gai_results))
958 *buflen = gai_results->ai_addrlen;
959 memcpy(buf, gai_results->ai_addr, *buflen);
961 freeaddrinfo(gai_results);
967 * nfs_callback_address - acquire our local network address
968 * @sap: pointer to address of remote
969 * @sap_len: length of address
970 * @buf: pointer to buffer to be filled in with local network address
971 * @buflen: IN: length of buffer to fill in; OUT: length of filled-in address
973 * Discover a network address that an NFSv4 server can use to call us back.
974 * On multi-homed clients, this address depends on which NIC we use to
975 * route requests to the server.
977 * Returns 1 and fills in @buf if an unambiguous local address is
978 * available; returns 1 and fills in an appropriate ANYADDR address
979 * if a local address isn't available; otherwise, returns zero.
981 int nfs_callback_address(const struct sockaddr *sap, const socklen_t salen,
982 struct sockaddr *buf, socklen_t *buflen)
984 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf;
986 if (nfs_ca_sockname(sap, salen, buf, buflen) == 0)
987 if (nfs_ca_gai(sap, salen, buf, buflen) == 0)
991 * The server can't use an interface ID that was generated
992 * here on the client, so always clear sin6_scope_id.
994 if (sin6->sin6_family == AF_INET6)
995 sin6->sin6_scope_id = 0;
1002 nfs_error(_("%s: failed to construct callback address"));