nis_cast.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* nis_cast: multicast to a specific group of hosts.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <errno.h>
#include <sys/resource.h>
#include <rpc/clnt_soc.h>
#include <netconfig.h>
#include <netdir.h>
#include <locale.h>
#include "nis_clnt.h"
#include "nis_local.h"
/*
* This is an arbitrary number. It limits the number of servers
* that we can send a request to. This should be adequate though,
* because we only need to get a response from one of these servers.
*/
#define MAXBCAST 1024
static void set_addresses(nis_bound_directory *, char *);
extern int __nis_debuglevel;
/* A list of connectionless transports */
struct transp {
int tr_fd;
char *tr_device;
char *tr_protofmly;
char *uaddr;
};
struct server_addr {
};
static void free_transports(struct transp *);
static void free_server_addrs(struct server_addr *, int);
/*
* __nis_cast_proc(): this provides a pseudo multicast feature where the list of
* the servers is in the directory object. Very similar to rpc_broadcast().
*/
enum clnt_stat
int base,
int nbep,
void *in, /* input argument */
void *out, /* output argument */
int *fastest, /* return endpoint that responded first */
int mytimeout) /* timeout (sec). Can be 0 for messaging */
{
int flag;
int i;
int fd;
int pingable = 0;
struct server_addr *saddrs = 0;
struct r_rpcb_rmtcallargs rarg6;
struct r_rpcb_rmtcallres rres6;
int fdlistno = 0; /* number of entries in pfd */
int pollretval;
int fds_found;
/* large enough for an IPv6 uaddr */
goto done_broad;
}
if (saddrs == 0) {
stat = RPC_CANTSEND;
goto done_broad;
}
continue;
if (nc == 0 ||
continue;
break; /* no more slots available */
pingable++;
stat = RPC_CANTSEND;
goto done_broad;
}
else
prev_trans = trans;
stat = RPC_CANTSEND;
goto done_broad;
}
stat = RPC_CANTSEND;
goto done_broad;
}
goto done_broad;
}
if (taddr) {
addr_cnt++;
}
}
/*
* If we didn't find any addresss to send to, then
* syslog an error message.
*/
if (addr_cnt == 0) {
/* only syslog if we actually had some addresses to ping */
if (pingable)
stat = RPC_CANTSEND;
goto done_broad;
}
/* serialize the RPC header */
/*
* For NC_INET, we must use a portmap version (2) so that we can
* speak to 4.X machines and 5.X machines with a single ping packet.
*/
goto done_broad;
}
goto done_broad;
}
/*
* Basic loop: send packet to all hosts and wait for response(s).
* The response timeout grows larger per iteration.
* A unique xid is assigned to each address in order to
* correctly match the replies. We allow a timeout of 0 as well to
* support one-way messages.
*/
struct rpc_msg *m;
if (timeout < 0)
sent = 0;
for (i = 0; i < nbep; i++) {
/*
* We randomly choose to go either forward or
* backward through the array so we get better
* behavior on "clumps" of addresses.
*/
if (start & 0x1)
else
/*
* We only have 8 bits for the endpoint number
* in the xid, so we have to stop before 256.
*/
continue;
/*
* Put endpoint number in xid.
* xid is the first thing in
* preserialized buffer
*/
} else {
}
sent++;
}
if (sent == 0) { /* no packets sent ? */
stat = RPC_CANTSEND;
goto done_broad;
}
if (mytimeout == 0)
/* this could be set for message passing mode */
stat = RPC_SUCCESS;
else
stat = RPC_TIMEDOUT;
goto done_broad;
}
/*
* Have sent all the packets. Now collect the responses...
*/
rcvd = 0;
case 0: /* timed out */
if (rcvd == 0) {
stat = RPC_TIMEDOUT;
continue;
} else
goto done_broad;
case -1: /* some kind of error */
goto recv_again;
if (rcvd == 0)
stat = RPC_CANTRECV;
goto done_broad;
} /* end of poll results switch */
/*
* Find the trans that corresponds to the first fd
* which poll managed to read on. We take advantage of
* the fact that the list of trans and the array pfd
* contain the same fd's in the same order.
*/
continue; /* nothing on this fd */
/*
* Something bad has happened to this
* descriptor. We can cause poll() to
* ignore it simply by using a negative
* fd. We do that rather than
* compacting the pfd[] array and trans
* list.
*/
fds_found++;
continue;
} else
break;
}
goto recv_again;
goto try_again;
/*
* Ignore any T_UDERR look errors. We should
* never see any ICMP port unreachables when
* broadcasting but it has been observed with
* broken IP implementations.
*/
goto recv_again;
stat = RPC_CANTRECV;
continue;
}
goto recv_again;
"nis_cast: t_rcvudata: %s: buffer overflow",
goto recv_again;
}
/*
* see if reply transaction id matches sent id.
* If so, decode the results.
* Note: received addr is ignored, it could be different
* from the send addr if the host has more than one addr.
*/
if (xdr_replymsg(xdrs, m)) {
rcvd++;
if (fastest) {
done = 1;
}
stat = RPC_SUCCESS;
}
/* otherwise, we just ignore the errors ... */
}
(void) xdr_replymsg(xdrs, m);
if (done)
goto done_broad;
else
goto recv_again;
}
if (!rcvd)
stat = RPC_TIMEDOUT;
return (stat);
}
static void
{
if (t->tr_taddr)
if (t->tr_fd >= 0)
free(t);
}
}
static void
{
int i;
if (saddrs == 0)
return;
for (i = 0; i < n; i++) {
}
}
static
struct netbuf *
{
"translate_addr: uaddr2taddr: %s (%d).",
return (0);
}
return (taddr);
}
int
{
int answer = 0;
answer = 1;
}
return (answer);
}
static
enum clnt_stat
{
int count;
if (st == RPC_SUCCESS)
return (st);
}
/*
* The MIN_ACTIVE define sets the minimum number of endpoints we
* want to have avaialable. It is set to twice the number of
* servers because each server has a tcp endpoint and udp endpoint.
* This is really just a heuristic right now, because we don't
* even check that we have separate servers rather than different
* interfaces on a multi-homed server.
*/
{
int i;
int base;
int scan;
int nbep;
int active_count = 0;
int new_active;
int min_active;
int fastest;
if (quick)
min_active = 1;
else
new_active = 0;
new_active++;
scan++;
}
/* see if we have enough active servers before pinging */
break;
if (st == RPC_SUCCESS) {
break;
}
active_count++;
/* see if we have enough active servers now */
if (active_count >= min_active)
break;
}
return (err);
}
/*
* Call the portmapper for each bound endpoint and get the
* server's transport address.
*/
static
void
{
int i;
char *u;
continue;
if (u)
else
}
}
}