17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * nfs_cast.c : broadcast to a specific group of NFS servers 247c478bd9Sstevel@tonic-gate * 25*11606941Sjwahlig * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 26*11606941Sjwahlig * Use is subject to license terms. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <stdio.h> 327c478bd9Sstevel@tonic-gate #include <syslog.h> 337c478bd9Sstevel@tonic-gate #include <errno.h> 347c478bd9Sstevel@tonic-gate #include <string.h> 357c478bd9Sstevel@tonic-gate #include <sys/types.h> 367c478bd9Sstevel@tonic-gate #include <sys/time.h> 377c478bd9Sstevel@tonic-gate #include <sys/resource.h> 387c478bd9Sstevel@tonic-gate #include <unistd.h> 397c478bd9Sstevel@tonic-gate #include <stdlib.h> 407c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 417c478bd9Sstevel@tonic-gate #include <rpc/clnt_soc.h> 427c478bd9Sstevel@tonic-gate #include <rpc/nettype.h> 437c478bd9Sstevel@tonic-gate #include <rpc/pmap_prot.h> 447c478bd9Sstevel@tonic-gate #include <netconfig.h> 457c478bd9Sstevel@tonic-gate #include <netdir.h> 467c478bd9Sstevel@tonic-gate #include <nfs/nfs.h> 477c478bd9Sstevel@tonic-gate #define NFSCLIENT 487c478bd9Sstevel@tonic-gate #include <locale.h> 497c478bd9Sstevel@tonic-gate #include "automount.h" 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define PENALTY_WEIGHT 100000 527c478bd9Sstevel@tonic-gate 53*11606941Sjwahlig struct tstamps { 547c478bd9Sstevel@tonic-gate struct tstamps *ts_next; 557c478bd9Sstevel@tonic-gate int ts_penalty; 567c478bd9Sstevel@tonic-gate int ts_inx; 577c478bd9Sstevel@tonic-gate int ts_rcvd; 587c478bd9Sstevel@tonic-gate struct timeval ts_timeval; 597c478bd9Sstevel@tonic-gate }; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* A list of addresses - all belonging to the same transport */ 627c478bd9Sstevel@tonic-gate 63*11606941Sjwahlig struct addrs { 647c478bd9Sstevel@tonic-gate struct addrs *addr_next; 657c478bd9Sstevel@tonic-gate struct mapfs *addr_mfs; 667c478bd9Sstevel@tonic-gate struct nd_addrlist *addr_addrs; 677c478bd9Sstevel@tonic-gate struct tstamps *addr_if_tstamps; 687c478bd9Sstevel@tonic-gate }; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* A list of connectionless transports */ 717c478bd9Sstevel@tonic-gate 72*11606941Sjwahlig struct transp { 737c478bd9Sstevel@tonic-gate struct transp *tr_next; 747c478bd9Sstevel@tonic-gate int tr_fd; 757c478bd9Sstevel@tonic-gate char *tr_device; 767c478bd9Sstevel@tonic-gate struct t_bind *tr_taddr; 777c478bd9Sstevel@tonic-gate struct addrs *tr_addrs; 787c478bd9Sstevel@tonic-gate }; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* A list of map entries and their roundtrip times, for sorting */ 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate struct sm { 837c478bd9Sstevel@tonic-gate struct mapfs *mfs; 847c478bd9Sstevel@tonic-gate struct timeval timeval; 857c478bd9Sstevel@tonic-gate }; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate static void free_transports(struct transp *); 887c478bd9Sstevel@tonic-gate static void calc_resp_time(struct timeval *); 897c478bd9Sstevel@tonic-gate static struct mapfs *sort_responses(struct transp *); 907c478bd9Sstevel@tonic-gate static int host_sm(const void *, const void *b); 917c478bd9Sstevel@tonic-gate static int time_sm(const void *, const void *b); 927c478bd9Sstevel@tonic-gate extern struct mapfs *add_mfs(struct mapfs *, int, struct mapfs **, 937c478bd9Sstevel@tonic-gate struct mapfs **); 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * This routine is designed to be able to "ping" 977c478bd9Sstevel@tonic-gate * a list of hosts and create a list of responding 987c478bd9Sstevel@tonic-gate * hosts sorted by response time. 997c478bd9Sstevel@tonic-gate * This must be done without any prior 1007c478bd9Sstevel@tonic-gate * contact with the host - therefore the "ping" 1017c478bd9Sstevel@tonic-gate * must be to a "well-known" address. The outstanding 1027c478bd9Sstevel@tonic-gate * candidate here is the address of "rpcbind". 1037c478bd9Sstevel@tonic-gate * 1047c478bd9Sstevel@tonic-gate * A response to a ping is no guarantee that the host 1057c478bd9Sstevel@tonic-gate * is running NFS, has a mount daemon, or exports 1067c478bd9Sstevel@tonic-gate * the required filesystem. If the subsequent 1077c478bd9Sstevel@tonic-gate * mount attempt fails then the host will be marked 1087c478bd9Sstevel@tonic-gate * "ignore" and the host list will be re-pinged 1097c478bd9Sstevel@tonic-gate * (sans the bad host). This process continues 1107c478bd9Sstevel@tonic-gate * until a successful mount is achieved or until 1117c478bd9Sstevel@tonic-gate * there are no hosts left to try. 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate enum clnt_stat 1147c478bd9Sstevel@tonic-gate nfs_cast(struct mapfs *mfs_in, struct mapfs **mfs_out, int timeout) 1157c478bd9Sstevel@tonic-gate { 1167c478bd9Sstevel@tonic-gate enum clnt_stat stat; 1177c478bd9Sstevel@tonic-gate AUTH *sys_auth = authsys_create_default(); 1187c478bd9Sstevel@tonic-gate XDR xdr_stream; 1197c478bd9Sstevel@tonic-gate register XDR *xdrs = &xdr_stream; 1207c478bd9Sstevel@tonic-gate int outlen; 1217c478bd9Sstevel@tonic-gate int if_inx; 1227c478bd9Sstevel@tonic-gate int tsec; 1237c478bd9Sstevel@tonic-gate int flag; 1247c478bd9Sstevel@tonic-gate int sent, addr_cnt, rcvd, if_cnt; 1257c478bd9Sstevel@tonic-gate fd_set readfds, mask; 1267c478bd9Sstevel@tonic-gate register ulong_t xid; /* xid - unique per addr */ 1277c478bd9Sstevel@tonic-gate register int i; 1287c478bd9Sstevel@tonic-gate struct rpc_msg msg; 1297c478bd9Sstevel@tonic-gate struct timeval t, rcv_timeout; 1307c478bd9Sstevel@tonic-gate char outbuf[UDPMSGSIZE], inbuf[UDPMSGSIZE]; 1317c478bd9Sstevel@tonic-gate struct t_unitdata t_udata, t_rdata; 1327c478bd9Sstevel@tonic-gate struct nd_hostserv hs; 1337c478bd9Sstevel@tonic-gate struct nd_addrlist *retaddrs; 1347c478bd9Sstevel@tonic-gate struct transp *tr_head; 1357c478bd9Sstevel@tonic-gate struct transp *trans, *prev_trans; 1367c478bd9Sstevel@tonic-gate struct addrs *a, *prev_addr; 1377c478bd9Sstevel@tonic-gate struct tstamps *ts, *prev_ts; 1387c478bd9Sstevel@tonic-gate NCONF_HANDLE *nc = NULL; 1397c478bd9Sstevel@tonic-gate struct netconfig *nconf; 1407c478bd9Sstevel@tonic-gate struct rlimit rl; 1417c478bd9Sstevel@tonic-gate int dtbsize; 1427c478bd9Sstevel@tonic-gate struct mapfs *mfs; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * For each connectionless transport get a list of 1467c478bd9Sstevel@tonic-gate * host addresses. Any single host may have 1477c478bd9Sstevel@tonic-gate * addresses on several transports. 1487c478bd9Sstevel@tonic-gate */ 1497c478bd9Sstevel@tonic-gate addr_cnt = sent = rcvd = 0; 1507c478bd9Sstevel@tonic-gate tr_head = NULL; 1517c478bd9Sstevel@tonic-gate FD_ZERO(&mask); 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* 1547c478bd9Sstevel@tonic-gate * Set the default select size to be the maximum FD_SETSIZE, unless 1557c478bd9Sstevel@tonic-gate * the current rlimit is lower. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate dtbsize = FD_SETSIZE; 1587c478bd9Sstevel@tonic-gate if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { 1597c478bd9Sstevel@tonic-gate if (rl.rlim_cur < FD_SETSIZE) 1607c478bd9Sstevel@tonic-gate dtbsize = rl.rlim_cur; 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate prev_trans = NULL; 1647c478bd9Sstevel@tonic-gate prev_addr = NULL; 1657c478bd9Sstevel@tonic-gate prev_ts = NULL; 1667c478bd9Sstevel@tonic-gate for (mfs = mfs_in; mfs; mfs = mfs->mfs_next) { 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate if (trace > 2) 1697c478bd9Sstevel@tonic-gate trace_prt(1, "nfs_cast: host=%s\n", mfs->mfs_host); 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate nc = setnetconfig(); 1727c478bd9Sstevel@tonic-gate if (nc == NULL) { 1737c478bd9Sstevel@tonic-gate stat = RPC_CANTSEND; 1747c478bd9Sstevel@tonic-gate goto done_broad; 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate while (nconf = getnetconfig(nc)) { 1777c478bd9Sstevel@tonic-gate if (!(nconf->nc_flag & NC_VISIBLE) || 1787c478bd9Sstevel@tonic-gate nconf->nc_semantics != NC_TPI_CLTS || 1797c478bd9Sstevel@tonic-gate (strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0)) 1807c478bd9Sstevel@tonic-gate continue; 1817c478bd9Sstevel@tonic-gate trans = (struct transp *)malloc(sizeof (*trans)); 1827c478bd9Sstevel@tonic-gate if (trans == NULL) { 1837c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "no memory"); 1847c478bd9Sstevel@tonic-gate stat = RPC_CANTSEND; 1857c478bd9Sstevel@tonic-gate goto done_broad; 1867c478bd9Sstevel@tonic-gate } 1877c478bd9Sstevel@tonic-gate (void) memset(trans, 0, sizeof (*trans)); 1887c478bd9Sstevel@tonic-gate if (tr_head == NULL) 1897c478bd9Sstevel@tonic-gate tr_head = trans; 1907c478bd9Sstevel@tonic-gate else 1917c478bd9Sstevel@tonic-gate prev_trans->tr_next = trans; 1927c478bd9Sstevel@tonic-gate prev_trans = trans; 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate trans->tr_fd = t_open(nconf->nc_device, O_RDWR, NULL); 1957c478bd9Sstevel@tonic-gate if (trans->tr_fd < 0) { 1967c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "nfscast: t_open: %s:%m", 1977c478bd9Sstevel@tonic-gate nconf->nc_device); 1987c478bd9Sstevel@tonic-gate stat = RPC_CANTSEND; 1997c478bd9Sstevel@tonic-gate goto done_broad; 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate if (t_bind(trans->tr_fd, (struct t_bind *)NULL, 2027c478bd9Sstevel@tonic-gate (struct t_bind *)NULL) < 0) { 2037c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "nfscast: t_bind: %m"); 2047c478bd9Sstevel@tonic-gate stat = RPC_CANTSEND; 2057c478bd9Sstevel@tonic-gate goto done_broad; 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate trans->tr_taddr = 2087c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */ 2097c478bd9Sstevel@tonic-gate (struct t_bind *)t_alloc(trans->tr_fd, T_BIND, T_ADDR); 2107c478bd9Sstevel@tonic-gate if (trans->tr_taddr == (struct t_bind *)NULL) { 2117c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "nfscast: t_alloc: %m"); 2127c478bd9Sstevel@tonic-gate stat = RPC_SYSTEMERROR; 2137c478bd9Sstevel@tonic-gate goto done_broad; 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate trans->tr_device = nconf->nc_device; 2177c478bd9Sstevel@tonic-gate FD_SET(trans->tr_fd, &mask); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate if_inx = 0; 2207c478bd9Sstevel@tonic-gate hs.h_host = mfs->mfs_host; 2217c478bd9Sstevel@tonic-gate hs.h_serv = "rpcbind"; 2227c478bd9Sstevel@tonic-gate if (netdir_getbyname(nconf, &hs, &retaddrs) == ND_OK) { 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * If mfs->ignore is previously set for 2267c478bd9Sstevel@tonic-gate * this map, clear it. Because a host can 2277c478bd9Sstevel@tonic-gate * have either v6 or v4 address 2287c478bd9Sstevel@tonic-gate */ 2297c478bd9Sstevel@tonic-gate if (mfs->mfs_ignore == 1) 2307c478bd9Sstevel@tonic-gate mfs->mfs_ignore = 0; 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate a = (struct addrs *)malloc(sizeof (*a)); 2337c478bd9Sstevel@tonic-gate if (a == NULL) { 2347c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "no memory"); 2357c478bd9Sstevel@tonic-gate stat = RPC_CANTSEND; 2367c478bd9Sstevel@tonic-gate goto done_broad; 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate (void) memset(a, 0, sizeof (*a)); 2397c478bd9Sstevel@tonic-gate if (trans->tr_addrs == NULL) 2407c478bd9Sstevel@tonic-gate trans->tr_addrs = a; 2417c478bd9Sstevel@tonic-gate else 2427c478bd9Sstevel@tonic-gate prev_addr->addr_next = a; 2437c478bd9Sstevel@tonic-gate prev_addr = a; 2447c478bd9Sstevel@tonic-gate a->addr_if_tstamps = NULL; 2457c478bd9Sstevel@tonic-gate a->addr_mfs = mfs; 2467c478bd9Sstevel@tonic-gate a->addr_addrs = retaddrs; 2477c478bd9Sstevel@tonic-gate if_cnt = retaddrs->n_cnt; 2487c478bd9Sstevel@tonic-gate while (if_cnt--) { 2497c478bd9Sstevel@tonic-gate ts = (struct tstamps *) 2507c478bd9Sstevel@tonic-gate malloc(sizeof (*ts)); 2517c478bd9Sstevel@tonic-gate if (ts == NULL) { 2527c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "no memory"); 2537c478bd9Sstevel@tonic-gate stat = RPC_CANTSEND; 2547c478bd9Sstevel@tonic-gate goto done_broad; 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate (void) memset(ts, 0, sizeof (*ts)); 2577c478bd9Sstevel@tonic-gate ts->ts_penalty = mfs->mfs_penalty; 2587c478bd9Sstevel@tonic-gate if (a->addr_if_tstamps == NULL) 2597c478bd9Sstevel@tonic-gate a->addr_if_tstamps = ts; 2607c478bd9Sstevel@tonic-gate else 2617c478bd9Sstevel@tonic-gate prev_ts->ts_next = ts; 2627c478bd9Sstevel@tonic-gate prev_ts = ts; 2637c478bd9Sstevel@tonic-gate ts->ts_inx = if_inx++; 2647c478bd9Sstevel@tonic-gate addr_cnt++; 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate break; 2677c478bd9Sstevel@tonic-gate } else { 2687c478bd9Sstevel@tonic-gate mfs->mfs_ignore = 1; 2697c478bd9Sstevel@tonic-gate if (verbose) 2707c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 2717c478bd9Sstevel@tonic-gate "%s:%s address not known", 2727c478bd9Sstevel@tonic-gate mfs->mfs_host, 2737c478bd9Sstevel@tonic-gate strcmp(nconf->nc_proto, NC_INET)?"IPv6":"IPv4"); 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate } /* while */ 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate endnetconfig(nc); 2787c478bd9Sstevel@tonic-gate nc = NULL; 2797c478bd9Sstevel@tonic-gate } /* for */ 2807c478bd9Sstevel@tonic-gate if (addr_cnt == 0) { 2817c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "nfscast: couldn't find addresses"); 2827c478bd9Sstevel@tonic-gate stat = RPC_CANTSEND; 2837c478bd9Sstevel@tonic-gate goto done_broad; 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate (void) gettimeofday(&t, (struct timezone *)0); 2877c478bd9Sstevel@tonic-gate xid = (getpid() ^ t.tv_sec ^ t.tv_usec) & ~0xFF; 2887c478bd9Sstevel@tonic-gate t.tv_usec = 0; 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate /* serialize the RPC header */ 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate msg.rm_direction = CALL; 2937c478bd9Sstevel@tonic-gate msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; 2947c478bd9Sstevel@tonic-gate msg.rm_call.cb_prog = RPCBPROG; 2957c478bd9Sstevel@tonic-gate /* 2967c478bd9Sstevel@tonic-gate * we can not use RPCBVERS here since it doesn't exist in 4.X, 2977c478bd9Sstevel@tonic-gate * the fix to bug 1139883 has made the 4.X portmapper silent to 2987c478bd9Sstevel@tonic-gate * version mismatches. This causes the RPC call to the remote 2997c478bd9Sstevel@tonic-gate * portmapper to simply be ignored if it's not Version 2. 3007c478bd9Sstevel@tonic-gate */ 3017c478bd9Sstevel@tonic-gate msg.rm_call.cb_vers = PMAPVERS; 3027c478bd9Sstevel@tonic-gate msg.rm_call.cb_proc = NULLPROC; 3037c478bd9Sstevel@tonic-gate if (sys_auth == (AUTH *)NULL) { 3047c478bd9Sstevel@tonic-gate stat = RPC_SYSTEMERROR; 3057c478bd9Sstevel@tonic-gate goto done_broad; 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate msg.rm_call.cb_cred = sys_auth->ah_cred; 3087c478bd9Sstevel@tonic-gate msg.rm_call.cb_verf = sys_auth->ah_verf; 3097c478bd9Sstevel@tonic-gate xdrmem_create(xdrs, outbuf, sizeof (outbuf), XDR_ENCODE); 3107c478bd9Sstevel@tonic-gate if (! xdr_callmsg(xdrs, &msg)) { 3117c478bd9Sstevel@tonic-gate stat = RPC_CANTENCODEARGS; 3127c478bd9Sstevel@tonic-gate goto done_broad; 3137c478bd9Sstevel@tonic-gate } 3147c478bd9Sstevel@tonic-gate outlen = (int)xdr_getpos(xdrs); 3157c478bd9Sstevel@tonic-gate xdr_destroy(xdrs); 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate t_udata.opt.len = 0; 3187c478bd9Sstevel@tonic-gate t_udata.udata.buf = outbuf; 3197c478bd9Sstevel@tonic-gate t_udata.udata.len = outlen; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate /* 3227c478bd9Sstevel@tonic-gate * Basic loop: send packet to all hosts and wait for response(s). 3237c478bd9Sstevel@tonic-gate * The response timeout grows larger per iteration. 3247c478bd9Sstevel@tonic-gate * A unique xid is assigned to each address in order to 3257c478bd9Sstevel@tonic-gate * correctly match the replies. 3267c478bd9Sstevel@tonic-gate */ 3277c478bd9Sstevel@tonic-gate for (tsec = 4; timeout > 0; tsec *= 2) { 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate timeout -= tsec; 3307c478bd9Sstevel@tonic-gate if (timeout <= 0) 3317c478bd9Sstevel@tonic-gate tsec += timeout; 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate rcv_timeout.tv_sec = tsec; 3347c478bd9Sstevel@tonic-gate rcv_timeout.tv_usec = 0; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate sent = 0; 3377c478bd9Sstevel@tonic-gate for (trans = tr_head; trans; trans = trans->tr_next) { 3387c478bd9Sstevel@tonic-gate for (a = trans->tr_addrs; a; a = a->addr_next) { 3397c478bd9Sstevel@tonic-gate struct netbuf *if_netbuf = 3407c478bd9Sstevel@tonic-gate a->addr_addrs->n_addrs; 3417c478bd9Sstevel@tonic-gate ts = a->addr_if_tstamps; 3427c478bd9Sstevel@tonic-gate if_cnt = a->addr_addrs->n_cnt; 3437c478bd9Sstevel@tonic-gate while (if_cnt--) { 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate /* 3467c478bd9Sstevel@tonic-gate * xid is the first thing in 3477c478bd9Sstevel@tonic-gate * preserialized buffer 3487c478bd9Sstevel@tonic-gate */ 3497c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */ 3507c478bd9Sstevel@tonic-gate *((ulong_t *)outbuf) = 3517c478bd9Sstevel@tonic-gate htonl(xid + ts->ts_inx); 3527c478bd9Sstevel@tonic-gate (void) gettimeofday(&(ts->ts_timeval), 3537c478bd9Sstevel@tonic-gate (struct timezone *)0); 3547c478bd9Sstevel@tonic-gate /* 3557c478bd9Sstevel@tonic-gate * Check if already received 3567c478bd9Sstevel@tonic-gate * from a previous iteration. 3577c478bd9Sstevel@tonic-gate */ 3587c478bd9Sstevel@tonic-gate if (ts->ts_rcvd) { 3597c478bd9Sstevel@tonic-gate sent++; 3607c478bd9Sstevel@tonic-gate ts = ts->ts_next; 3617c478bd9Sstevel@tonic-gate continue; 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate t_udata.addr = *if_netbuf++; 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate if (t_sndudata(trans->tr_fd, 3677c478bd9Sstevel@tonic-gate &t_udata) == 0) { 3687c478bd9Sstevel@tonic-gate sent++; 3697c478bd9Sstevel@tonic-gate } 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate ts = ts->ts_next; 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate } 3757c478bd9Sstevel@tonic-gate if (sent == 0) { /* no packets sent ? */ 3767c478bd9Sstevel@tonic-gate stat = RPC_CANTSEND; 3777c478bd9Sstevel@tonic-gate goto done_broad; 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate /* 3817c478bd9Sstevel@tonic-gate * Have sent all the packets. Now collect the responses... 3827c478bd9Sstevel@tonic-gate */ 3837c478bd9Sstevel@tonic-gate rcvd = 0; 3847c478bd9Sstevel@tonic-gate recv_again: 3857c478bd9Sstevel@tonic-gate msg.acpted_rply.ar_verf = _null_auth; 3867c478bd9Sstevel@tonic-gate msg.acpted_rply.ar_results.proc = xdr_void; 3877c478bd9Sstevel@tonic-gate readfds = mask; 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate switch (select(dtbsize, &readfds, 3907c478bd9Sstevel@tonic-gate (fd_set *)NULL, (fd_set *)NULL, &rcv_timeout)) { 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate case 0: /* Timed out */ 3937c478bd9Sstevel@tonic-gate /* 3947c478bd9Sstevel@tonic-gate * If we got at least one response in the 3957c478bd9Sstevel@tonic-gate * last interval, then don't wait for any 3967c478bd9Sstevel@tonic-gate * more. In theory we should wait for 3977c478bd9Sstevel@tonic-gate * the max weighting (penalty) value so 3987c478bd9Sstevel@tonic-gate * that a very slow server has a chance to 3997c478bd9Sstevel@tonic-gate * respond but this could take a long time 4007c478bd9Sstevel@tonic-gate * if the admin has set a high weighting 4017c478bd9Sstevel@tonic-gate * value. 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate if (rcvd > 0) 4047c478bd9Sstevel@tonic-gate goto done_broad; 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate stat = RPC_TIMEDOUT; 4077c478bd9Sstevel@tonic-gate continue; 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate case -1: /* some kind of error */ 4107c478bd9Sstevel@tonic-gate if (errno == EINTR) 4117c478bd9Sstevel@tonic-gate goto recv_again; 4127c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "nfscast: select: %m"); 4137c478bd9Sstevel@tonic-gate if (rcvd == 0) 4147c478bd9Sstevel@tonic-gate stat = RPC_CANTRECV; 4157c478bd9Sstevel@tonic-gate goto done_broad; 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate } /* end of select results switch */ 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate for (trans = tr_head; trans; trans = trans->tr_next) { 4207c478bd9Sstevel@tonic-gate if (FD_ISSET(trans->tr_fd, &readfds)) 4217c478bd9Sstevel@tonic-gate break; 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate if (trans == NULL) 4247c478bd9Sstevel@tonic-gate goto recv_again; 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate try_again: 4277c478bd9Sstevel@tonic-gate t_rdata.addr = trans->tr_taddr->addr; 4287c478bd9Sstevel@tonic-gate t_rdata.udata.buf = inbuf; 4297c478bd9Sstevel@tonic-gate t_rdata.udata.maxlen = sizeof (inbuf); 4307c478bd9Sstevel@tonic-gate t_rdata.udata.len = 0; 4317c478bd9Sstevel@tonic-gate t_rdata.opt.len = 0; 4327c478bd9Sstevel@tonic-gate if (t_rcvudata(trans->tr_fd, &t_rdata, &flag) < 0) { 4337c478bd9Sstevel@tonic-gate if (errno == EINTR) 4347c478bd9Sstevel@tonic-gate goto try_again; 4357c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "nfscast: t_rcvudata: %s:%m", 4367c478bd9Sstevel@tonic-gate trans->tr_device); 4377c478bd9Sstevel@tonic-gate stat = RPC_CANTRECV; 4387c478bd9Sstevel@tonic-gate continue; 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate if (t_rdata.udata.len < sizeof (ulong_t)) 4417c478bd9Sstevel@tonic-gate goto recv_again; 4427c478bd9Sstevel@tonic-gate if (flag & T_MORE) { 4437c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 4447c478bd9Sstevel@tonic-gate "nfscast: t_rcvudata: %s: buffer overflow", 4457c478bd9Sstevel@tonic-gate trans->tr_device); 4467c478bd9Sstevel@tonic-gate goto recv_again; 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate /* 4507c478bd9Sstevel@tonic-gate * see if reply transaction id matches sent id. 4517c478bd9Sstevel@tonic-gate * If so, decode the results. 4527c478bd9Sstevel@tonic-gate * Note: received addr is ignored, it could be 4537c478bd9Sstevel@tonic-gate * different from the send addr if the host has 4547c478bd9Sstevel@tonic-gate * more than one addr. 4557c478bd9Sstevel@tonic-gate */ 4567c478bd9Sstevel@tonic-gate xdrmem_create(xdrs, inbuf, (uint_t)t_rdata.udata.len, 4577c478bd9Sstevel@tonic-gate XDR_DECODE); 4587c478bd9Sstevel@tonic-gate if (xdr_replymsg(xdrs, &msg)) { 4597c478bd9Sstevel@tonic-gate if (msg.rm_reply.rp_stat == MSG_ACCEPTED && 4607c478bd9Sstevel@tonic-gate (msg.rm_xid & ~0xFF) == xid) { 4617c478bd9Sstevel@tonic-gate struct addrs *curr_addr; 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate i = msg.rm_xid & 0xFF; 4647c478bd9Sstevel@tonic-gate for (curr_addr = trans->tr_addrs; curr_addr; 4657c478bd9Sstevel@tonic-gate curr_addr = curr_addr->addr_next) { 4667c478bd9Sstevel@tonic-gate for (ts = curr_addr->addr_if_tstamps; ts; 4677c478bd9Sstevel@tonic-gate ts = ts->ts_next) 4687c478bd9Sstevel@tonic-gate if (ts->ts_inx == i && !ts->ts_rcvd) { 4697c478bd9Sstevel@tonic-gate ts->ts_rcvd = 1; 4707c478bd9Sstevel@tonic-gate calc_resp_time(&ts->ts_timeval); 4717c478bd9Sstevel@tonic-gate stat = RPC_SUCCESS; 4727c478bd9Sstevel@tonic-gate rcvd++; 4737c478bd9Sstevel@tonic-gate break; 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate } 4767c478bd9Sstevel@tonic-gate } /* otherwise, we just ignore the errors ... */ 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate xdrs->x_op = XDR_FREE; 4797c478bd9Sstevel@tonic-gate msg.acpted_rply.ar_results.proc = xdr_void; 4807c478bd9Sstevel@tonic-gate (void) xdr_replymsg(xdrs, &msg); 4817c478bd9Sstevel@tonic-gate XDR_DESTROY(xdrs); 4827c478bd9Sstevel@tonic-gate if (rcvd == sent) 4837c478bd9Sstevel@tonic-gate goto done_broad; 4847c478bd9Sstevel@tonic-gate else 4857c478bd9Sstevel@tonic-gate goto recv_again; 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate if (!rcvd) 4887c478bd9Sstevel@tonic-gate stat = RPC_TIMEDOUT; 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate done_broad: 4917c478bd9Sstevel@tonic-gate if (rcvd) { 4927c478bd9Sstevel@tonic-gate *mfs_out = sort_responses(tr_head); 4937c478bd9Sstevel@tonic-gate stat = RPC_SUCCESS; 4947c478bd9Sstevel@tonic-gate } 4957c478bd9Sstevel@tonic-gate if (nc) 4967c478bd9Sstevel@tonic-gate endnetconfig(nc); 4977c478bd9Sstevel@tonic-gate free_transports(tr_head); 4987c478bd9Sstevel@tonic-gate AUTH_DESTROY(sys_auth); 4997c478bd9Sstevel@tonic-gate return (stat); 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate /* 5037c478bd9Sstevel@tonic-gate * Go through all the responses and sort fastest to slowest. 5047c478bd9Sstevel@tonic-gate * Note that any penalty is added to the response time - so the 5057c478bd9Sstevel@tonic-gate * fastest response isn't necessarily the one that arrived first. 5067c478bd9Sstevel@tonic-gate */ 5077c478bd9Sstevel@tonic-gate static struct mapfs * 5087c478bd9Sstevel@tonic-gate sort_responses(trans) 5097c478bd9Sstevel@tonic-gate struct transp *trans; 5107c478bd9Sstevel@tonic-gate { 5117c478bd9Sstevel@tonic-gate struct transp *t; 5127c478bd9Sstevel@tonic-gate struct addrs *a; 5137c478bd9Sstevel@tonic-gate struct tstamps *ti; 5147c478bd9Sstevel@tonic-gate int i, size = 0, allocsize = 10; 5157c478bd9Sstevel@tonic-gate struct mapfs *p, *mfs_head = NULL, *mfs_tail = NULL; 5167c478bd9Sstevel@tonic-gate struct sm *buffer; 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate buffer = (struct sm *)malloc(allocsize * sizeof (struct sm)); 5197c478bd9Sstevel@tonic-gate if (!buffer) { 5207c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "sort_responses: malloc error.\n"); 5217c478bd9Sstevel@tonic-gate return (NULL); 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate for (t = trans; t; t = t->tr_next) { 5257c478bd9Sstevel@tonic-gate for (a = t->tr_addrs; a; a = a->addr_next) { 5267c478bd9Sstevel@tonic-gate for (ti = a->addr_if_tstamps; 5277c478bd9Sstevel@tonic-gate ti; ti = ti->ts_next) { 5287c478bd9Sstevel@tonic-gate if (!ti->ts_rcvd) 5297c478bd9Sstevel@tonic-gate continue; 5307c478bd9Sstevel@tonic-gate ti->ts_timeval.tv_usec += 5317c478bd9Sstevel@tonic-gate (ti->ts_penalty * PENALTY_WEIGHT); 5327c478bd9Sstevel@tonic-gate if (ti->ts_timeval.tv_usec >= 1000000) { 5337c478bd9Sstevel@tonic-gate ti->ts_timeval.tv_sec += 5347c478bd9Sstevel@tonic-gate (ti->ts_timeval.tv_usec / 1000000); 5357c478bd9Sstevel@tonic-gate ti->ts_timeval.tv_usec = 5367c478bd9Sstevel@tonic-gate (ti->ts_timeval.tv_usec % 1000000); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate if (size >= allocsize) { 5407c478bd9Sstevel@tonic-gate allocsize += 10; 5417c478bd9Sstevel@tonic-gate buffer = (struct sm *)realloc(buffer, 5427c478bd9Sstevel@tonic-gate allocsize * sizeof (struct sm)); 5437c478bd9Sstevel@tonic-gate if (!buffer) { 5447c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 5457c478bd9Sstevel@tonic-gate "sort_responses: malloc error.\n"); 5467c478bd9Sstevel@tonic-gate return (NULL); 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate buffer[size].timeval = ti->ts_timeval; 5507c478bd9Sstevel@tonic-gate buffer[size].mfs = a->addr_mfs; 5517c478bd9Sstevel@tonic-gate size++; 5527c478bd9Sstevel@tonic-gate } 5537c478bd9Sstevel@tonic-gate } 5547c478bd9Sstevel@tonic-gate } 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate #ifdef DEBUG 5577c478bd9Sstevel@tonic-gate if (trace > 3) { 5587c478bd9Sstevel@tonic-gate trace_prt(1, " sort_responses: before host sort:\n"); 5597c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) 5607c478bd9Sstevel@tonic-gate trace_prt(1, " %s %d.%d\n", buffer[i].mfs->mfs_host, 5617c478bd9Sstevel@tonic-gate buffer[i].timeval.tv_sec, buffer[i].timeval.tv_usec); 5627c478bd9Sstevel@tonic-gate trace_prt(0, "\n"); 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate #endif 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate qsort((void *)buffer, size, sizeof (struct sm), host_sm); 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate /* 5697c478bd9Sstevel@tonic-gate * Cope with multiply listed hosts by choosing first time 5707c478bd9Sstevel@tonic-gate */ 5717c478bd9Sstevel@tonic-gate for (i = 1; i < size; i++) { 5727c478bd9Sstevel@tonic-gate #ifdef DEBUG 5737c478bd9Sstevel@tonic-gate if (trace > 3) { 5747c478bd9Sstevel@tonic-gate trace_prt(1, " sort_responses: comparing %s and %s\n", 5757c478bd9Sstevel@tonic-gate buffer[i-1].mfs->mfs_host, 5767c478bd9Sstevel@tonic-gate buffer[i].mfs->mfs_host); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate #endif 5797c478bd9Sstevel@tonic-gate if (strcmp(buffer[i-1].mfs->mfs_host, 5807c478bd9Sstevel@tonic-gate buffer[i].mfs->mfs_host) == 0) 5817c478bd9Sstevel@tonic-gate memcpy(&buffer[i].timeval, &buffer[i-1].timeval, 5827c478bd9Sstevel@tonic-gate sizeof (struct timeval)); 5837c478bd9Sstevel@tonic-gate } 5847c478bd9Sstevel@tonic-gate if (trace > 3) 5857c478bd9Sstevel@tonic-gate trace_prt(0, "\n"); 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate #ifdef DEBUG 5887c478bd9Sstevel@tonic-gate if (trace > 3) { 5897c478bd9Sstevel@tonic-gate trace_prt(1, " sort_responses: before time sort:\n"); 5907c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) 5917c478bd9Sstevel@tonic-gate trace_prt(1, " %s %d.%d\n", buffer[i].mfs->mfs_host, 5927c478bd9Sstevel@tonic-gate buffer[i].timeval.tv_sec, buffer[i].timeval.tv_usec); 5937c478bd9Sstevel@tonic-gate trace_prt(0, "\n"); 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate #endif 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate qsort((void *)buffer, size, sizeof (struct sm), time_sm); 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate #ifdef DEBUG 6007c478bd9Sstevel@tonic-gate if (trace > 3) { 6017c478bd9Sstevel@tonic-gate trace_prt(1, " sort_responses: after sort:\n"); 6027c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) 6037c478bd9Sstevel@tonic-gate trace_prt(1, " %s %d.%d\n", buffer[i].mfs->mfs_host, 6047c478bd9Sstevel@tonic-gate buffer[i].timeval.tv_sec, buffer[i].timeval.tv_usec); 6057c478bd9Sstevel@tonic-gate trace_prt(0, "\n"); 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate #endif 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) { 6107c478bd9Sstevel@tonic-gate #ifdef DEBUG 6117c478bd9Sstevel@tonic-gate if (trace > 3) { 6127c478bd9Sstevel@tonic-gate trace_prt(1, " sort_responses: adding %s\n", 6137c478bd9Sstevel@tonic-gate buffer[i].mfs->mfs_host); 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate #endif 6167c478bd9Sstevel@tonic-gate p = add_mfs(buffer[i].mfs, 0, &mfs_head, &mfs_tail); 6177c478bd9Sstevel@tonic-gate if (!p) 6187c478bd9Sstevel@tonic-gate return (NULL); 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate free(buffer); 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate return (mfs_head); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate /* 6277c478bd9Sstevel@tonic-gate * Comparison routines called by qsort(3). 6287c478bd9Sstevel@tonic-gate */ 6297c478bd9Sstevel@tonic-gate static int host_sm(const void *a, const void *b) 6307c478bd9Sstevel@tonic-gate { 6317c478bd9Sstevel@tonic-gate return (strcmp(((struct sm *)a)->mfs->mfs_host, 6327c478bd9Sstevel@tonic-gate ((struct sm *)b)->mfs->mfs_host)); 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate static int time_sm(const void *a, const void *b) 6367c478bd9Sstevel@tonic-gate { 6377c478bd9Sstevel@tonic-gate if (timercmp(&(((struct sm *)a)->timeval), 6387c478bd9Sstevel@tonic-gate &(((struct sm *)b)->timeval), < /* cstyle */)) 6397c478bd9Sstevel@tonic-gate return (-1); 6407c478bd9Sstevel@tonic-gate else if (timercmp(&(((struct sm *)a)->timeval), 6417c478bd9Sstevel@tonic-gate &(((struct sm *)b)->timeval), > /* cstyle */)) 6427c478bd9Sstevel@tonic-gate return (1); 6437c478bd9Sstevel@tonic-gate else 6447c478bd9Sstevel@tonic-gate return (0); 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate /* 6487c478bd9Sstevel@tonic-gate * Given send_time which is the time a request 6497c478bd9Sstevel@tonic-gate * was transmitted to a server, subtract it 6507c478bd9Sstevel@tonic-gate * from the time "now" thereby converting it 6517c478bd9Sstevel@tonic-gate * to an elapsed time. 6527c478bd9Sstevel@tonic-gate */ 6537c478bd9Sstevel@tonic-gate static void 6547c478bd9Sstevel@tonic-gate calc_resp_time(send_time) 6557c478bd9Sstevel@tonic-gate struct timeval *send_time; 6567c478bd9Sstevel@tonic-gate { 6577c478bd9Sstevel@tonic-gate struct timeval time_now; 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate (void) gettimeofday(&time_now, (struct timezone *)0); 6607c478bd9Sstevel@tonic-gate if (time_now.tv_usec < send_time->tv_usec) { 6617c478bd9Sstevel@tonic-gate time_now.tv_sec--; 6627c478bd9Sstevel@tonic-gate time_now.tv_usec += 1000000; 6637c478bd9Sstevel@tonic-gate } 6647c478bd9Sstevel@tonic-gate send_time->tv_sec = time_now.tv_sec - send_time->tv_sec; 6657c478bd9Sstevel@tonic-gate send_time->tv_usec = time_now.tv_usec - send_time->tv_usec; 6667c478bd9Sstevel@tonic-gate } 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate static void 6697c478bd9Sstevel@tonic-gate free_transports(trans) 6707c478bd9Sstevel@tonic-gate struct transp *trans; 6717c478bd9Sstevel@tonic-gate { 6727c478bd9Sstevel@tonic-gate struct transp *t, *tmpt = NULL; 6737c478bd9Sstevel@tonic-gate struct addrs *a, *tmpa = NULL; 6747c478bd9Sstevel@tonic-gate struct tstamps *ts, *tmpts = NULL; 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate for (t = trans; t; t = tmpt) { 6777c478bd9Sstevel@tonic-gate if (t->tr_taddr) 6787c478bd9Sstevel@tonic-gate (void) t_free((char *)t->tr_taddr, T_BIND); 6797c478bd9Sstevel@tonic-gate if (t->tr_fd > 0) 6807c478bd9Sstevel@tonic-gate (void) t_close(t->tr_fd); 6817c478bd9Sstevel@tonic-gate for (a = t->tr_addrs; a; a = tmpa) { 6827c478bd9Sstevel@tonic-gate for (ts = a->addr_if_tstamps; ts; ts = tmpts) { 6837c478bd9Sstevel@tonic-gate tmpts = ts->ts_next; 6847c478bd9Sstevel@tonic-gate free(ts); 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate (void) netdir_free((char *)a->addr_addrs, ND_ADDRLIST); 6877c478bd9Sstevel@tonic-gate tmpa = a->addr_next; 6887c478bd9Sstevel@tonic-gate free(a); 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate tmpt = t->tr_next; 6917c478bd9Sstevel@tonic-gate free(t); 6927c478bd9Sstevel@tonic-gate } 6937c478bd9Sstevel@tonic-gate } 694