1e2adc47dSRick Macklem /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 42e322d37SHiroki Sato * Copyright (c) 2009, Sun Microsystems, Inc. 52e322d37SHiroki Sato * All rights reserved. 6e2adc47dSRick Macklem * 72e322d37SHiroki Sato * Redistribution and use in source and binary forms, with or without 82e322d37SHiroki Sato * modification, are permitted provided that the following conditions are met: 92e322d37SHiroki Sato * - Redistributions of source code must retain the above copyright notice, 102e322d37SHiroki Sato * this list of conditions and the following disclaimer. 112e322d37SHiroki Sato * - Redistributions in binary form must reproduce the above copyright notice, 122e322d37SHiroki Sato * this list of conditions and the following disclaimer in the documentation 132e322d37SHiroki Sato * and/or other materials provided with the distribution. 142e322d37SHiroki Sato * - Neither the name of Sun Microsystems, Inc. nor the names of its 152e322d37SHiroki Sato * contributors may be used to endorse or promote products derived 162e322d37SHiroki Sato * from this software without specific prior written permission. 17e2adc47dSRick Macklem * 182e322d37SHiroki Sato * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 192e322d37SHiroki Sato * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 202e322d37SHiroki Sato * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212e322d37SHiroki Sato * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 222e322d37SHiroki Sato * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 232e322d37SHiroki Sato * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 242e322d37SHiroki Sato * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 252e322d37SHiroki Sato * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 262e322d37SHiroki Sato * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 272e322d37SHiroki Sato * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 282e322d37SHiroki Sato * POSSIBILITY OF SUCH DAMAGE. 29e2adc47dSRick Macklem */ 30e2adc47dSRick Macklem 31e2adc47dSRick Macklem #ifndef _RPC_KRPC_H_ 32e2adc47dSRick Macklem #define _RPC_KRPC_H_ 33e2adc47dSRick Macklem 34e2adc47dSRick Macklem #ifdef _KERNEL 35e2adc47dSRick Macklem /* 36e2adc47dSRick Macklem * Definitions now shared between client and server RPC for backchannels. 37e2adc47dSRick Macklem */ 38e2adc47dSRick Macklem #define MCALL_MSG_SIZE 24 39e2adc47dSRick Macklem 40c59e4cc3SRick Macklem void clnt_bck_svccall(void *, struct mbuf *, uint32_t); 41c59e4cc3SRick Macklem enum clnt_stat clnt_bck_call(CLIENT *, struct rpc_callextra *, rpcproc_t, 42c59e4cc3SRick Macklem struct mbuf *, struct mbuf **, struct timeval, SVCXPRT *); 43ab0c29afSRick Macklem struct mbuf *_rpc_copym_into_ext_pgs(struct mbuf *, int); 44c59e4cc3SRick Macklem 45e2adc47dSRick Macklem /* 46e2adc47dSRick Macklem * A pending RPC request which awaits a reply. Requests which have 47e2adc47dSRick Macklem * received their reply will have cr_xid set to zero and cr_mrep to 48e2adc47dSRick Macklem * the mbuf chain of the reply. 49e2adc47dSRick Macklem */ 50e2adc47dSRick Macklem struct ct_request { 51e2adc47dSRick Macklem TAILQ_ENTRY(ct_request) cr_link; 52e2adc47dSRick Macklem struct mbuf *cr_mrep; /* reply received by upcall */ 53*50c962d7SGleb Smirnoff #ifdef VIMAGE 54*50c962d7SGleb Smirnoff struct vnet *cr_vnet; 55*50c962d7SGleb Smirnoff #endif 56*50c962d7SGleb Smirnoff uint32_t cr_xid; /* XID of request */ 57e2adc47dSRick Macklem int cr_error; /* any error from upcall */ 58e2adc47dSRick Macklem char cr_verf[MAX_AUTH_BYTES]; /* reply verf */ 59e2adc47dSRick Macklem }; 60e2adc47dSRick Macklem 61e2adc47dSRick Macklem TAILQ_HEAD(ct_request_list, ct_request); 62e2adc47dSRick Macklem 63e2adc47dSRick Macklem struct rc_data { 64e2adc47dSRick Macklem struct mtx rc_lock; 65e2adc47dSRick Macklem struct sockaddr_storage rc_addr; /* server address */ 66e2adc47dSRick Macklem struct netconfig* rc_nconf; /* network type */ 67e2adc47dSRick Macklem rpcprog_t rc_prog; /* program number */ 68e2adc47dSRick Macklem rpcvers_t rc_vers; /* version number */ 69e2adc47dSRick Macklem size_t rc_sendsz; 70e2adc47dSRick Macklem size_t rc_recvsz; 71e2adc47dSRick Macklem struct timeval rc_timeout; 72e2adc47dSRick Macklem struct timeval rc_retry; 73e2adc47dSRick Macklem int rc_retries; 74e2adc47dSRick Macklem int rc_privport; 75e2adc47dSRick Macklem char *rc_waitchan; 76e2adc47dSRick Macklem int rc_intr; 77e2adc47dSRick Macklem int rc_connecting; 78e2adc47dSRick Macklem int rc_closed; 79e2adc47dSRick Macklem struct ucred *rc_ucred; 80e2adc47dSRick Macklem CLIENT* rc_client; /* underlying RPC client */ 81e2adc47dSRick Macklem struct rpc_err rc_err; 82e2adc47dSRick Macklem void *rc_backchannel; 83ab0c29afSRick Macklem bool rc_tls; /* Enable TLS on connection */ 84665b1365SRick Macklem char *rc_tlscertname; 857763814fSRick Macklem void (*rc_reconcall)(CLIENT *, void *, 867763814fSRick Macklem struct ucred *); /* reconection upcall */ 877763814fSRick Macklem void *rc_reconarg; /* upcall arg */ 88e2adc47dSRick Macklem }; 89e2adc47dSRick Macklem 90ab0c29afSRick Macklem /* Bits for ct_rcvstate. */ 91ab0c29afSRick Macklem #define RPCRCVSTATE_NORMAL 0x01 /* Normal reception. */ 92ab0c29afSRick Macklem #define RPCRCVSTATE_NONAPPDATA 0x02 /* Reception of a non-application record. */ 93ab0c29afSRick Macklem #define RPCRCVSTATE_TLSHANDSHAKE 0x04 /* Reception blocked for TLS handshake. */ 94ab0c29afSRick Macklem #define RPCRCVSTATE_UPCALLNEEDED 0x08 /* Upcall to rpctlscd needed. */ 95ab0c29afSRick Macklem #define RPCRCVSTATE_UPCALLINPROG 0x10 /* Upcall to rpctlscd in progress. */ 96ab0c29afSRick Macklem #define RPCRCVSTATE_SOUPCALLNEEDED 0x20 /* Socket upcall needed. */ 97ab0c29afSRick Macklem #define RPCRCVSTATE_UPCALLTHREAD 0x40 /* Upcall kthread running. */ 98ab0c29afSRick Macklem 99e2adc47dSRick Macklem struct ct_data { 100e2adc47dSRick Macklem struct mtx ct_lock; 101e2adc47dSRick Macklem int ct_threads; /* number of threads in clnt_vc_call */ 102e2adc47dSRick Macklem bool_t ct_closing; /* TRUE if we are closing */ 103e2adc47dSRick Macklem bool_t ct_closed; /* TRUE if we are closed */ 104e2adc47dSRick Macklem struct socket *ct_socket; /* connection socket */ 105e2adc47dSRick Macklem bool_t ct_closeit; /* close it on destroy */ 106e2adc47dSRick Macklem struct timeval ct_wait; /* wait interval in milliseconds */ 107e2adc47dSRick Macklem struct sockaddr_storage ct_addr; /* remote addr */ 108e2adc47dSRick Macklem struct rpc_err ct_error; 109e2adc47dSRick Macklem uint32_t ct_xid; 110e2adc47dSRick Macklem char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */ 111e2adc47dSRick Macklem size_t ct_mpos; /* pos after marshal */ 112e2adc47dSRick Macklem const char *ct_waitchan; 113e2adc47dSRick Macklem int ct_waitflag; 114e2adc47dSRick Macklem struct mbuf *ct_record; /* current reply record */ 115e2adc47dSRick Macklem size_t ct_record_resid; /* how much left of reply to read */ 116e2adc47dSRick Macklem bool_t ct_record_eor; /* true if reading last fragment */ 117e2adc47dSRick Macklem struct ct_request_list ct_pending; 118e2adc47dSRick Macklem int ct_upcallrefs; /* Ref cnt of upcalls in prog. */ 119e2adc47dSRick Macklem SVCXPRT *ct_backchannelxprt; /* xprt for backchannel */ 12056a96c51SGleb Smirnoff enum tlsstate { 12156a96c51SGleb Smirnoff RPCTLS_NONE = 0, 12256a96c51SGleb Smirnoff RPCTLS_INHANDSHAKE, /* fd given to the daemon, daemon is working */ 12356a96c51SGleb Smirnoff RPCTLS_COMPLETE, /* daemon reported success rpctlscd_connect() */ 12456a96c51SGleb Smirnoff } ct_tlsstate; 125ab0c29afSRick Macklem uint32_t ct_rcvstate; /* Handle receiving for TLS upcalls */ 1264302e8b6SRick Macklem struct mbuf *ct_raw; /* Raw mbufs recv'd */ 127e2adc47dSRick Macklem }; 128e2adc47dSRick Macklem 129e2adc47dSRick Macklem struct cf_conn { /* kept in xprt->xp_p1 for actual connection */ 130e2adc47dSRick Macklem enum xprt_stat strm_stat; 131e2adc47dSRick Macklem struct mbuf *mpending; /* unparsed data read from the socket */ 132e2adc47dSRick Macklem struct mbuf *mreq; /* current record being built from mpending */ 133e2adc47dSRick Macklem uint32_t resid; /* number of bytes needed for fragment */ 134e2adc47dSRick Macklem bool_t eor; /* reading last fragment of current record */ 135e2adc47dSRick Macklem }; 136e2adc47dSRick Macklem 137fa1b9612SGleb Smirnoff void rpcnl_init(void); 138fa1b9612SGleb Smirnoff 139e2adc47dSRick Macklem #endif /* _KERNEL */ 140e2adc47dSRick Macklem 141e2adc47dSRick Macklem #endif /* _RPC_KRPC_H_ */ 142