/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 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"
/*
* Client interface to broadcast service.
*
* The following is kludged-up support for simple rpc broadcasts.
* Someday a large, complicated system will replace these routines.
*/
#include "mt.h"
#include "rpc_mt.h"
#include <string.h>
#include <strings.h>
#include <netdir.h>
#ifdef PORTMAP
#include <rpc/pmap_prot.h>
#endif
#ifdef RPC_DEBUG
#include <stdio.h>
#endif
#include <errno.h>
#include <syslog.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef NETIDLEN
#endif
/*
* If nettype is NULL, it broadcasts on all the available
* datagram_n transports. May potentially lead to broadacst storms
* and hence should be used with caution, care and courage.
*
* The current parameter xdr packet size is limited by the max tsdu
* size of the transport. If the max tsdu size of any transport is
* smaller than the parameter xdr packet, then broadcast is not
* sent on that transport.
*
* Also, the packet size should be less the packet size of
* the data link layer (for ethernet it is 1400 bytes). There is
* no easy way to find out the max size of the data link layer and
* we are assuming that the args would be smaller than that.
*
* The result size has to be smaller than the transport tsdu size.
*
* If PORTMAP has been defined, we send two packets for UDP, one for
* rpcbind and one for portmap. For those machines which support
* both rpcbind and portmap, it will cause them to reply twice, and
* also here it will get two responses ... inefficient and clumsy.
*/
enum clnt_stat
{
struct timeval t;
int i, j;
void *handle;
/* An array of all the suitable broadcast transports */
struct {
int fdlistno = 0;
int msec;
int pollretval;
int fds_found;
#ifdef PORTMAP
int udpbufsz = 0;
#endif /* PORTMAP */
return (RPC_SYSTEMERROR);
/*
* initialization: create a fd, a broadcast address, and send the
* request on the broadcast transport.
* Listen on all of them and on replies, call the user supplied
* function.
*/
else {
if (len >= sizeof (nettype_array))
return (RPC_UNKNOWNPROTO);
}
nettype = "datagram_n";
return (RPC_UNKNOWNPROTO);
int fd;
continue;
break; /* No more slots available */
stat = RPC_CANTSEND;
continue;
}
stat = RPC_CANTSEND;
continue;
}
/* Do protocol specific negotiating for broadcast */
continue;
}
goto done_broad;
}
goto done_broad;
}
#ifdef PORTMAP
goto done_broad;
}
pmap_flag = 1;
}
#endif
fdlistno++;
}
if (fdlistno == 0) {
if (stat == RPC_SUCCESS)
goto done_broad;
}
if (maxbufsize == 0) {
if (stat == RPC_SUCCESS)
stat = RPC_CANTSEND;
goto done_broad;
}
goto done_broad;
}
/* Serialize all the arguments which have to be sent */
(void) gettimeofday(&t, (struct timezone *)0);
goto done_broad;
}
/* XXX Should have set opt to its legal maxlen. */
#ifdef PORTMAP
/* Prepare the packet for version 2 PORTMAP */
if (pmap_flag) {
goto done_broad;
}
}
#endif /* PORTMAP */
/*
* Basic loop: broadcast the packets to transports which
* support data packets of size such that one can encode
* all the arguments.
* Wait a while for response(s).
* The response timeout grows larger per iteration.
*/
/* Broadcast all the packets now */
for (i = 0; i < fdlistno; i++) {
NC_INET6) == 0) {
/* if it's IPv6 */
/* fill in the multicast address */
/* now send rpcbind message */
&t_udata)) {
"Cannot send broadcast\
packet: %m");
#ifdef RPC_DEBUG
t_error("rpc_broadcast: t_sndudata");
#endif
stat = RPC_CANTSEND;
continue;
}
} else {
stat = RPC_CANTSEND;
continue;
}
continue;
}
#ifdef RPC_DEBUG
#endif
/*
* Only use version 3 if lowvers
* is not set or transport is not UDP.
*/
&t_udata)) {
"Cannot send broadcast\
packet: %m");
#ifdef RPC_DEBUG
t_error("rpc_broadcast: t_sndudata");
#endif
stat = RPC_CANTSEND;
continue;
};
#ifdef RPC_DEBUG
#endif
#ifdef PORTMAP
/*
* Send the version 2 packet also
*/
&t_udata_pmap)) {
"Cannot send broadcast packet: %m");
#ifdef RPC_DEBUG
t_error("rpc_broadcast:\
t_sndudata");
#endif
stat = RPC_CANTSEND;
continue;
}
}
#ifdef RPC_DEBUG
#endif
#endif /* PORTMAP */
}
/* End for sending all packets on this transport */
} /* end non-IPv6 */
} /* End for sending on all transports */
if (eachresult == NULL) {
stat = RPC_SUCCESS;
goto done_broad;
}
/*
* Get all the replies from these broadcast requests
*/
case 0: /* timed out */
stat = RPC_TIMEDOUT;
continue;
case -1: /* some kind of error - we ignore it */
goto recv_again;
} /* end of poll results switch */
for (i = fds_found = 0;
int flag;
continue;
/*
* Something bad has happened to this descri-
* ptor. We can cause poll() to ignore
* it simply by using a negative fd. We do that
* rather than compacting the pfd[] and fdlist[]
* arrays.
*/
fds_found++;
continue;
} else
fds_found++;
#ifdef RPC_DEBUG
#endif
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;
"Cannot receive reply to \
broadcast: %m");
stat = RPC_CANTRECV;
continue;
}
/*
* Not taking care of flag for T_MORE.
* We are assuming that
* such calls should not take more than one
* transport packet.
*/
continue; /* Drop that and go ahead */
continue; /* Drop that and go ahead */
/*
* see if reply transaction id matches sent id.
* If so, decode the results. If return id is xid + 1
* it was a PORTMAP reply
*/
/* LINTED pointer cast */
pmap_reply_flag = 0;
#ifdef PORTMAP
} else if (pmap_flag &&
/* LINTED pointer cast */
/* LINTED pointer cast */
*((uint32_t *)(outbuf_pmap))) {
pmap_reply_flag = 1;
#endif /* PORTMAP */
} else
continue;
#ifdef PORTMAP
if (pmap_flag && pmap_reply_flag) {
/* convert port to taddr */
/* LINTED pointer cast */
((struct sockaddr_in *)
} else /* Convert the uaddr to taddr */
#endif
taddr = uaddr2taddr(
uaddrp);
#ifdef RPC_DEBUG
{
int k;
printf("rmt addr = ");
printf("\n");
}
#endif
if (taddr && !pmap_reply_flag)
netdir_free((char *)taddr,
ND_ADDR);
}
/* otherwise, we just ignore the errors ... */
}
/* else some kind of deserialization problem ... */
if (done) {
stat = RPC_SUCCESS;
goto done_broad;
} else {
goto done_broad;
}
goto recv_again;
}
} /* The recv for loop */
} /* The giant for loop */
if (inbuf)
if (outbuf)
#ifdef PORTMAP
if (outbuf_pmap)
#endif
for (i = 0; i < fdlistno; i++) {
}
(void) __rpc_endconf(handle);
return (stat);
}
enum clnt_stat
{
}