1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate * 26*7c478bd9Sstevel@tonic-gate * clnt.h - Client side remote procedure call interface. 27*7c478bd9Sstevel@tonic-gate * Stripped down sockets based client for boot. 28*7c478bd9Sstevel@tonic-gate */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #ifndef _RPC_CLNT_H 31*7c478bd9Sstevel@tonic-gate #define _RPC_CLNT_H 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 36*7c478bd9Sstevel@tonic-gate #include <rpc/clnt_stat.h> 37*7c478bd9Sstevel@tonic-gate #include <rpc/auth.h> 38*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 41*7c478bd9Sstevel@tonic-gate extern "C" { 42*7c478bd9Sstevel@tonic-gate #endif 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate /* 45*7c478bd9Sstevel@tonic-gate * Error info. 46*7c478bd9Sstevel@tonic-gate */ 47*7c478bd9Sstevel@tonic-gate struct rpc_err { 48*7c478bd9Sstevel@tonic-gate enum clnt_stat re_status; 49*7c478bd9Sstevel@tonic-gate union { 50*7c478bd9Sstevel@tonic-gate int RE_errno; /* realated system error */ 51*7c478bd9Sstevel@tonic-gate enum auth_stat RE_why; /* why the auth error occurred */ 52*7c478bd9Sstevel@tonic-gate } ru; 53*7c478bd9Sstevel@tonic-gate #define re_errno ru.RE_errno 54*7c478bd9Sstevel@tonic-gate #define re_why ru.RE_why 55*7c478bd9Sstevel@tonic-gate }; 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * Client rpc handle. 60*7c478bd9Sstevel@tonic-gate * Created by individual implementations, see e.g. rpc_udp.c. 61*7c478bd9Sstevel@tonic-gate * Client is responsible for initializing auth, see e.g. auth_none.c. 62*7c478bd9Sstevel@tonic-gate */ 63*7c478bd9Sstevel@tonic-gate typedef struct __client { 64*7c478bd9Sstevel@tonic-gate AUTH *cl_auth; /* authenticator */ 65*7c478bd9Sstevel@tonic-gate struct clnt_ops { 66*7c478bd9Sstevel@tonic-gate /* call remote procedure */ 67*7c478bd9Sstevel@tonic-gate enum clnt_stat (*cl_call)(struct __client *, rpcproc_t, 68*7c478bd9Sstevel@tonic-gate xdrproc_t, caddr_t, xdrproc_t, 69*7c478bd9Sstevel@tonic-gate caddr_t, struct timeval); 70*7c478bd9Sstevel@tonic-gate /* abort a call */ 71*7c478bd9Sstevel@tonic-gate void (*cl_abort)(/* various */); 72*7c478bd9Sstevel@tonic-gate /* get specific error code */ 73*7c478bd9Sstevel@tonic-gate void (*cl_geterr)(struct __client *, 74*7c478bd9Sstevel@tonic-gate struct rpc_err *); 75*7c478bd9Sstevel@tonic-gate /* frees results */ 76*7c478bd9Sstevel@tonic-gate bool_t (*cl_freeres)(struct __client *, xdrproc_t, 77*7c478bd9Sstevel@tonic-gate caddr_t); 78*7c478bd9Sstevel@tonic-gate /* destroy this structure */ 79*7c478bd9Sstevel@tonic-gate void (*cl_destroy)(struct __client *); 80*7c478bd9Sstevel@tonic-gate /* the ioctl() of rpc */ 81*7c478bd9Sstevel@tonic-gate bool_t (*cl_control)(struct __client *, int, char *); 82*7c478bd9Sstevel@tonic-gate } *cl_ops; 83*7c478bd9Sstevel@tonic-gate caddr_t cl_private; /* private stuff */ 84*7c478bd9Sstevel@tonic-gate } CLIENT; 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* 88*7c478bd9Sstevel@tonic-gate * client side rpc interface ops 89*7c478bd9Sstevel@tonic-gate * 90*7c478bd9Sstevel@tonic-gate * Parameter types are: 91*7c478bd9Sstevel@tonic-gate * 92*7c478bd9Sstevel@tonic-gate */ 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* 95*7c478bd9Sstevel@tonic-gate * enum clnt_stat 96*7c478bd9Sstevel@tonic-gate * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) 97*7c478bd9Sstevel@tonic-gate * CLIENT *rh; 98*7c478bd9Sstevel@tonic-gate * ulong_t proc; 99*7c478bd9Sstevel@tonic-gate * xdrproc_t xargs; 100*7c478bd9Sstevel@tonic-gate * caddr_t argsp; 101*7c478bd9Sstevel@tonic-gate * xdrproc_t xres; 102*7c478bd9Sstevel@tonic-gate * caddr_t resp; 103*7c478bd9Sstevel@tonic-gate * struct timeval timeout; 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ 106*7c478bd9Sstevel@tonic-gate ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs)) 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /* 109*7c478bd9Sstevel@tonic-gate * void 110*7c478bd9Sstevel@tonic-gate * CLNT_ABORT(rh); 111*7c478bd9Sstevel@tonic-gate * CLIENT *rh; 112*7c478bd9Sstevel@tonic-gate */ 113*7c478bd9Sstevel@tonic-gate #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate /* 116*7c478bd9Sstevel@tonic-gate * struct rpc_err 117*7c478bd9Sstevel@tonic-gate * CLNT_GETERR(rh); 118*7c478bd9Sstevel@tonic-gate * CLIENT *rh; 119*7c478bd9Sstevel@tonic-gate */ 120*7c478bd9Sstevel@tonic-gate #define CLNT_GETERR(rh, errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate /* 123*7c478bd9Sstevel@tonic-gate * bool_t 124*7c478bd9Sstevel@tonic-gate * CLNT_FREERES(rh, xres, resp); 125*7c478bd9Sstevel@tonic-gate * CLIENT *rh; 126*7c478bd9Sstevel@tonic-gate * xdrproc_t xres; 127*7c478bd9Sstevel@tonic-gate * caddr_t resp; 128*7c478bd9Sstevel@tonic-gate */ 129*7c478bd9Sstevel@tonic-gate #define CLNT_FREERES(rh, xres, resp) ((*(rh)->cl_ops->cl_freeres)\ 130*7c478bd9Sstevel@tonic-gate (rh, xres, resp)) 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate /* 133*7c478bd9Sstevel@tonic-gate * bool_t 134*7c478bd9Sstevel@tonic-gate * CLNT_CONTROL(cl, request, info) 135*7c478bd9Sstevel@tonic-gate * CLIENT *cl; 136*7c478bd9Sstevel@tonic-gate * uint_t request; 137*7c478bd9Sstevel@tonic-gate * char *info; 138*7c478bd9Sstevel@tonic-gate */ 139*7c478bd9Sstevel@tonic-gate #define CLNT_CONTROL(cl, rq, in) ((*(cl)->cl_ops->cl_control)(cl, rq, in)) 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate /* 142*7c478bd9Sstevel@tonic-gate * control operations that apply to both udp and tcp transports 143*7c478bd9Sstevel@tonic-gate */ 144*7c478bd9Sstevel@tonic-gate #define CLSET_TIMEOUT 1 /* set timeout (timeval) */ 145*7c478bd9Sstevel@tonic-gate #define CLGET_TIMEOUT 2 /* get timeout (timeval) */ 146*7c478bd9Sstevel@tonic-gate #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ 147*7c478bd9Sstevel@tonic-gate #define CLGET_FD 6 /* get connections file descriptor */ 148*7c478bd9Sstevel@tonic-gate #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */ 149*7c478bd9Sstevel@tonic-gate #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */ 150*7c478bd9Sstevel@tonic-gate /* 151*7c478bd9Sstevel@tonic-gate * udp only control operations 152*7c478bd9Sstevel@tonic-gate */ 153*7c478bd9Sstevel@tonic-gate #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ 154*7c478bd9Sstevel@tonic-gate #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate /* 157*7c478bd9Sstevel@tonic-gate * void 158*7c478bd9Sstevel@tonic-gate * CLNT_DESTROY(rh); 159*7c478bd9Sstevel@tonic-gate * CLIENT *rh; 160*7c478bd9Sstevel@tonic-gate */ 161*7c478bd9Sstevel@tonic-gate #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate /* 164*7c478bd9Sstevel@tonic-gate * By convention, procedure 0 takes null arguments and returns them 165*7c478bd9Sstevel@tonic-gate */ 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate #define NULLPROC ((ulong_t)0) 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate /* 170*7c478bd9Sstevel@tonic-gate * Below are the client handle creation routines for the various 171*7c478bd9Sstevel@tonic-gate * implementations of client side rpc. They can return NULL if a 172*7c478bd9Sstevel@tonic-gate * creation failure occurs. 173*7c478bd9Sstevel@tonic-gate */ 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate /* 176*7c478bd9Sstevel@tonic-gate * UDP based rpc. 177*7c478bd9Sstevel@tonic-gate * CLIENT * 178*7c478bd9Sstevel@tonic-gate * clntbudp_create(raddr, program, version, wait, sockp) 179*7c478bd9Sstevel@tonic-gate * struct sockaddr_in *raddr; 180*7c478bd9Sstevel@tonic-gate * ulong_t program; 181*7c478bd9Sstevel@tonic-gate * ulong_t version; 182*7c478bd9Sstevel@tonic-gate * struct timeval wait; 183*7c478bd9Sstevel@tonic-gate * int *sockp; 184*7c478bd9Sstevel@tonic-gate * 185*7c478bd9Sstevel@tonic-gate * Same as above, but you specify max packet sizes. 186*7c478bd9Sstevel@tonic-gate * CLIENT * 187*7c478bd9Sstevel@tonic-gate * clntbudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) 188*7c478bd9Sstevel@tonic-gate * struct sockaddr_in *raddr; 189*7c478bd9Sstevel@tonic-gate * ulong_t program; 190*7c478bd9Sstevel@tonic-gate * ulong_t version; 191*7c478bd9Sstevel@tonic-gate * struct timeval wait; 192*7c478bd9Sstevel@tonic-gate * int *sockp; 193*7c478bd9Sstevel@tonic-gate * uint_t sendsz; 194*7c478bd9Sstevel@tonic-gate * uint_t recvsz; 195*7c478bd9Sstevel@tonic-gate */ 196*7c478bd9Sstevel@tonic-gate extern CLIENT *clntbudp_create(struct sockaddr_in *raddr, rpcprog_t program, 197*7c478bd9Sstevel@tonic-gate rpcvers_t version, struct timeval wait, 198*7c478bd9Sstevel@tonic-gate int *sockp); 199*7c478bd9Sstevel@tonic-gate extern CLIENT *clntbudp_bufcreate(struct sockaddr_in *raddr, rpcprog_t program, 200*7c478bd9Sstevel@tonic-gate rpcvers_t version, struct timeval wait, 201*7c478bd9Sstevel@tonic-gate int *sockp, uint_t sendsz, uint_t recvsz); 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate /* 204*7c478bd9Sstevel@tonic-gate * TCP based rpc. 205*7c478bd9Sstevel@tonic-gate * CLIENT * 206*7c478bd9Sstevel@tonic-gate * clntbtcp_create(raddr, program, version, wait, sockp, sendsz, recvsz) 207*7c478bd9Sstevel@tonic-gate * struct sockaddr_in *raddr; 208*7c478bd9Sstevel@tonic-gate * ulong_t program; 209*7c478bd9Sstevel@tonic-gate * ulong_t version; 210*7c478bd9Sstevel@tonic-gate * struct timeval wait; 211*7c478bd9Sstevel@tonic-gate * int *sockp; 212*7c478bd9Sstevel@tonic-gate * uint_t sendsz; 213*7c478bd9Sstevel@tonic-gate * uint_t recvsz; 214*7c478bd9Sstevel@tonic-gate * 215*7c478bd9Sstevel@tonic-gate */ 216*7c478bd9Sstevel@tonic-gate extern CLIENT *clntbtcp_create(struct sockaddr_in *raddr, rpcprog_t program, 217*7c478bd9Sstevel@tonic-gate rpcvers_t version, struct timeval wait, 218*7c478bd9Sstevel@tonic-gate int *sockp, uint_t sendsz, uint_t recvsz); 219*7c478bd9Sstevel@tonic-gate /* 220*7c478bd9Sstevel@tonic-gate * If a creation fails, the following allows the user to figure out why. 221*7c478bd9Sstevel@tonic-gate */ 222*7c478bd9Sstevel@tonic-gate struct rpc_createerr { 223*7c478bd9Sstevel@tonic-gate enum clnt_stat cf_stat; 224*7c478bd9Sstevel@tonic-gate struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ 225*7c478bd9Sstevel@tonic-gate }; 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate extern struct rpc_createerr rpc_createerr; 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */ 230*7c478bd9Sstevel@tonic-gate #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ 231*7c478bd9Sstevel@tonic-gate #define TCPMSGSIZE (32 * 1024) /* reasonably sized RPC/TCP msg */ 232*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 233*7c478bd9Sstevel@tonic-gate } 234*7c478bd9Sstevel@tonic-gate #endif 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate #endif /* !_RPC_CLNT_H */ 237