/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 2009, Sun Microsystems, Inc.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8* - Redistributions of source code must retain the above copyright notice,9* this list of conditions and the following disclaimer.10* - Redistributions in binary form must reproduce the above copyright notice,11* this list of conditions and the following disclaimer in the documentation12* and/or other materials provided with the distribution.13* - Neither the name of Sun Microsystems, Inc. nor the names of its14* contributors may be used to endorse or promote products derived15* from this software without specific prior written permission.16*17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"18* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE21* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS24* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN25* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)26* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGE.28*/2930#ifndef _RPC_KRPC_H_31#define _RPC_KRPC_H_3233#ifdef _KERNEL34/*35* Definitions now shared between client and server RPC for backchannels.36*/37#define MCALL_MSG_SIZE 243839void clnt_bck_svccall(void *, struct mbuf *, uint32_t);40enum clnt_stat clnt_bck_call(CLIENT *, struct rpc_callextra *, rpcproc_t,41struct mbuf *, struct mbuf **, struct timeval, SVCXPRT *);42struct mbuf *_rpc_copym_into_ext_pgs(struct mbuf *, int);4344/*45* A pending RPC request which awaits a reply. Requests which have46* received their reply will have cr_xid set to zero and cr_mrep to47* the mbuf chain of the reply.48*/49struct ct_request {50TAILQ_ENTRY(ct_request) cr_link;51struct mbuf *cr_mrep; /* reply received by upcall */52#ifdef VIMAGE53struct vnet *cr_vnet;54#endif55uint32_t cr_xid; /* XID of request */56int cr_error; /* any error from upcall */57char cr_verf[MAX_AUTH_BYTES]; /* reply verf */58};5960TAILQ_HEAD(ct_request_list, ct_request);6162struct rc_data {63struct mtx rc_lock;64struct sockaddr_storage rc_addr; /* server address */65struct netconfig* rc_nconf; /* network type */66rpcprog_t rc_prog; /* program number */67rpcvers_t rc_vers; /* version number */68size_t rc_sendsz;69size_t rc_recvsz;70struct timeval rc_timeout;71struct timeval rc_retry;72int rc_retries;73int rc_privport;74char *rc_waitchan;75int rc_intr;76int rc_connecting;77int rc_closed;78struct ucred *rc_ucred;79CLIENT* rc_client; /* underlying RPC client */80struct rpc_err rc_err;81void *rc_backchannel;82bool rc_tls; /* Enable TLS on connection */83char *rc_tlscertname;84void (*rc_reconcall)(CLIENT *, void *,85struct ucred *); /* reconection upcall */86void *rc_reconarg; /* upcall arg */87};8889/* Bits for ct_rcvstate. */90#define RPCRCVSTATE_NORMAL 0x01 /* Normal reception. */91#define RPCRCVSTATE_NONAPPDATA 0x02 /* Reception of a non-application record. */92#define RPCRCVSTATE_TLSHANDSHAKE 0x04 /* Reception blocked for TLS handshake. */93#define RPCRCVSTATE_UPCALLNEEDED 0x08 /* Upcall to rpctlscd needed. */94#define RPCRCVSTATE_UPCALLINPROG 0x10 /* Upcall to rpctlscd in progress. */95#define RPCRCVSTATE_SOUPCALLNEEDED 0x20 /* Socket upcall needed. */96#define RPCRCVSTATE_UPCALLTHREAD 0x40 /* Upcall kthread running. */9798struct ct_data {99struct mtx ct_lock;100int ct_threads; /* number of threads in clnt_vc_call */101bool_t ct_closing; /* TRUE if we are closing */102bool_t ct_closed; /* TRUE if we are closed */103struct socket *ct_socket; /* connection socket */104bool_t ct_closeit; /* close it on destroy */105struct timeval ct_wait; /* wait interval in milliseconds */106struct sockaddr_storage ct_addr; /* remote addr */107struct rpc_err ct_error;108uint32_t ct_xid;109char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */110size_t ct_mpos; /* pos after marshal */111const char *ct_waitchan;112int ct_waitflag;113struct mbuf *ct_record; /* current reply record */114size_t ct_record_resid; /* how much left of reply to read */115bool_t ct_record_eor; /* true if reading last fragment */116struct ct_request_list ct_pending;117int ct_upcallrefs; /* Ref cnt of upcalls in prog. */118SVCXPRT *ct_backchannelxprt; /* xprt for backchannel */119enum tlsstate {120RPCTLS_NONE = 0,121RPCTLS_INHANDSHAKE, /* fd given to the daemon, daemon is working */122RPCTLS_COMPLETE, /* daemon reported success rpctlscd_connect() */123} ct_tlsstate;124uint32_t ct_rcvstate; /* Handle receiving for TLS upcalls */125struct mbuf *ct_raw; /* Raw mbufs recv'd */126};127128struct cf_conn { /* kept in xprt->xp_p1 for actual connection */129enum xprt_stat strm_stat;130struct mbuf *mpending; /* unparsed data read from the socket */131struct mbuf *mreq; /* current record being built from mpending */132uint32_t resid; /* number of bytes needed for fragment */133bool_t eor; /* reading last fragment of current record */134};135136void rpcnl_init(void);137138#endif /* _KERNEL */139140#endif /* _RPC_KRPC_H_ */141142143