rpc_generic.c revision e8031f0a8ed0e45c6d8847c5e09424e66fd34a4b
/*
* 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 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"
/*
* Miscl routines for RPC.
*/
#include "mt.h"
#include "rpc_mt.h"
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <sys/resource.h>
#include <netconfig.h>
#include <malloc.h>
#include <syslog.h>
#include <string.h>
#include <sys/systeminfo.h>
#include <netdir.h>
#include <netdb.h>
struct handle {
int nflag; /* Whether NETPATH or NETCONFIG */
int nettype;
};
struct _rpcnettype {
const char *name;
const int type;
} _rpctypelist[] = {
"netpath", _RPC_NETPATH,
"visible", _RPC_VISIBLE,
"circuit_v", _RPC_CIRCUIT_V,
"datagram_v", _RPC_DATAGRAM_V,
"circuit_n", _RPC_CIRCUIT_N,
"datagram_n", _RPC_DATAGRAM_N,
"tcp", _RPC_TCP,
"udp", _RPC_UDP,
"local", _RPC_LOCAL,
"door", _RPC_DOOR,
"door_local", _RPC_DOOR_LOCAL,
"door_netpath", _RPC_DOOR_NETPATH,
0, _RPC_NONE
};
/*
* Cache the result of getrlimit(), so we don't have to do an
* expensive call every time. Since many old programs assume
* it will not return more than 1024 and use svc_fdset, return
* maximum of FD_SETSIZE.
*/
int
__rpc_dtbsize(void)
{
static int tbsize;
if (tbsize)
return (tbsize);
/*
* backward compatibility; too many places
* this function is called assuming it returns
* maximum of 1024.
*/
if (tbsize > FD_SETSIZE)
tbsize = FD_SETSIZE;
return (tbsize);
}
/*
* Something wrong. I'll try to save face by returning a
* pessimistic number.
*/
return (32);
}
/*
* Find the appropriate buffer size
*/
{
return ((uint_t)0);
if (size == 0) {
/*
* bufsize == -1 : No limit on the size
* bufsize == 0 : Concept of tsdu foreign. Choose
* a value.
*/
return ((uint_t)RPC_MAXDATASIZE);
}
}
/* Check whether the value is within the upper max limit */
}
/*
* Find the appropriate address buffer size
*/
{
if (size >= 0)
if (size <= -2)
return ((uint_t)0);
/*
* (size == -1) No limit on the size. we impose a limit here.
*/
return ((uint_t)RPC_MAXADDRSIZE);
}
/*
* If nettype is NULL, it defaults to NETPATH.
*/
static int
getnettype(const char *nettype)
{
int i;
return (_RPC_NETPATH); /* Default */
for (i = 0; _rpctypelist[i].name; i++)
return (_rpctypelist[i].type);
return (_rpctypelist[i].type);
}
/*
* For the given nettype (tcp or udp only), return the first structure found.
* This should be freed by calling freenetconfigent()
*/
struct netconfig *
__rpc_getconfip(char *nettype)
{
char *netid;
static char *netid_tcp_main;
static char *netid_udp_main;
int main_thread;
if ((main_thread = thr_main())) {
} else {
if (tcp_key == 0) {
(void) mutex_lock(&tsd_lock);
if (tcp_key == 0)
(void) mutex_unlock(&tsd_lock);
}
if (udp_key == 0) {
(void) mutex_lock(&tsd_lock);
if (udp_key == 0)
(void) mutex_unlock(&tsd_lock);
}
}
void *confighandle;
if (!(confighandle = setnetconfig()))
return (NULL);
"__rpc_getconfip : "
"strdup failed");
return (NULL);
}
if (main_thread)
else
(void) pthread_setspecific(
(void *)netid_tcp);
} else
"__rpc_getconfip : "
"strdup failed");
return (NULL);
}
if (main_thread)
else
(void) pthread_setspecific(
(void *)netid_udp);
}
}
}
(void) endnetconfig(confighandle);
}
else
return (NULL);
return (NULL);
return (getnetconfigent(netid));
}
/*
* Returns the type of the nettype, which should then be used with
* __rpc_getconf().
*/
void *
__rpc_setconf(char *nettype)
{
return (NULL);
case _RPC_DOOR_NETPATH:
case _RPC_NETPATH:
case _RPC_CIRCUIT_N:
case _RPC_DATAGRAM_N:
return (NULL);
}
break;
case _RPC_VISIBLE:
case _RPC_CIRCUIT_V:
case _RPC_DATAGRAM_V:
case _RPC_TCP:
case _RPC_UDP:
case _RPC_LOCAL:
case _RPC_DOOR_LOCAL:
return (NULL);
}
break;
default:
return (NULL);
}
return (handle);
}
/*
* Returns the next netconfig struct for the given "net" type.
* __rpc_setconf() should have been called previously.
*/
struct netconfig *
__rpc_getconf(void *vhandle)
{
return (NULL);
for (;;) {
else
break;
continue;
case _RPC_VISIBLE:
continue;
/*FALLTHROUGH*/
case _RPC_DOOR_NETPATH:
/*FALLTHROUGH*/
case _RPC_NETPATH: /* Be happy */
break;
case _RPC_CIRCUIT_V:
continue;
/*FALLTHROUGH*/
case _RPC_CIRCUIT_N:
continue;
break;
case _RPC_DATAGRAM_V:
continue;
/*FALLTHROUGH*/
case _RPC_DATAGRAM_N:
continue;
break;
case _RPC_TCP:
continue;
break;
case _RPC_UDP:
continue;
break;
case _RPC_LOCAL:
case _RPC_DOOR_LOCAL:
continue;
continue;
break;
}
break;
}
return (nconf);
}
void
__rpc_endconf(void *vhandle)
{
return;
} else {
}
}
/*
* Used to ping the NULL procedure for clnt handle.
* Returns NULL if fails, else a non-NULL pointer.
*/
void *
{
return (NULL);
return ((void *)clnt);
}
/*
* Given a fd, find the transport device it is using and return the
* netconf entry corresponding to it.
* Note: It assumes servtpe parameter is 0 when uninitialized.
* That is true for xprt->xp_type field.
*/
struct netconfig *
{
void *hndl;
return (NULL);
if (servtype == 0) {
char errorstr[100];
"could not get transport information",
errorstr);
return (NULL);
}
}
hndl = setnetconfig();
return (NULL);
/*
* transport device in use on fd.
* - Match on service type first
* - if that succeeds, match on major numbers (used for new local
* transport code that is self cloning)
* - if that fails, assume transport device uses clone driver
* and try match the fdmajor with minor number of device path
* which will be the major number of transport device since it
* uses the clone driver.
*/
break; /* self cloning driver ? */
break; /* clone driver! */
}
}
}
if (nconf)
(void) endnetconfig(hndl);
return (newnconf);
}
int
{
switch (servtype) {
case T_COTS:
if (nc_semantics == NC_TPI_COTS)
return (TRUE);
break;
case T_COTS_ORD:
if (nc_semantics == NC_TPI_COTS_ORD)
return (TRUE);
break;
case T_CLTS:
if (nc_semantics == NC_TPI_CLTS)
return (TRUE);
break;
default:
/* FALSE! */
break;
}
return (FALSE);
}
/*
*/
extern bool_t __inet_netdir_is_my_host(const char *);
__rpc_is_local_host(const char *host)
{
return (TRUE);
return (FALSE);
return (TRUE);
return (__inet_netdir_is_my_host(host));
}
{
switch (getnettype(nettype)) {
case _RPC_DOOR:
*try_others = FALSE;
return (TRUE);
case _RPC_DOOR_LOCAL:
case _RPC_DOOR_NETPATH:
*try_others = TRUE;
return (TRUE);
default:
*try_others = TRUE;
return (FALSE);
}
}