xref: /freebsd/sys/rpc/krpc.h (revision a311bd18a6fb57c6d3a19ab5bb53bb6f1c5fd056)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2009, Sun Microsystems, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * - Redistributions of source code must retain the above copyright notice,
10  *   this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  * - Neither the name of Sun Microsystems, Inc. nor the names of its
15  *   contributors may be used to endorse or promote products derived
16  *   from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _RPC_KRPC_H_
32 #define	_RPC_KRPC_H_
33 
34 #ifdef _KERNEL
35 /*
36  * Definitions now shared between client and server RPC for backchannels.
37  */
38 #define MCALL_MSG_SIZE 24
39 
40 void clnt_bck_svccall(void *, struct mbuf *, uint32_t);
41 enum clnt_stat clnt_bck_call(CLIENT *, struct rpc_callextra *, rpcproc_t,
42     struct mbuf *, struct mbuf **, struct timeval, SVCXPRT *);
43 struct mbuf *_rpc_copym_into_ext_pgs(struct mbuf *, int);
44 
45 /* Callback functions for server side RDMA. */
46 typedef int	clnt_bck_rdma_send_ftype(SVCXPRT *xprt, struct mbuf *m);
47 extern clnt_bck_rdma_send_ftype *clnt_bck_rdma_send;
48 
49 /* Functions for client side RDMA. */
50 typedef int	xprt_rdma_check_route_ftype(struct vnet *vnet,
51 		    struct sockaddr *dstaddr, uint32_t cbslots);
52 extern xprt_rdma_check_route_ftype *rdma_check_route;
53 
54 typedef bool_t	clnt_rdma_bcksend_ftype(SVCXPRT *xprt, struct mbuf *m);
55 extern clnt_rdma_bcksend_ftype *clnt_rdma_bcksend_call;
56 
57 typedef CLIENT	*clnt_rdma_create_ftype(struct sockaddr *raddr,
58 		    const rpcprog_t prog, const rpcvers_t vers, int intrflag,
59 		    uint32_t small_reply, uint32_t max_io, uint32_t cblots,
60 		    struct rpc_err *err);
61 extern clnt_rdma_create_ftype *clnt_rdma_create_call;
62 
63 /*
64  * A pending RPC request which awaits a reply. Requests which have
65  * received their reply will have cr_xid set to zero and cr_mrep to
66  * the mbuf chain of the reply.
67  */
68 struct ct_request {
69 	TAILQ_ENTRY(ct_request) cr_link;
70 	struct mbuf		*cr_mrep;	/* reply received by upcall */
71 #ifdef VIMAGE
72 	struct vnet		*cr_vnet;
73 #endif
74 	uint32_t		cr_xid;		/* XID of request */
75 	int			cr_error;	/* any error from upcall */
76 	char			cr_verf[MAX_AUTH_BYTES]; /* reply verf */
77 };
78 
79 TAILQ_HEAD(ct_request_list, ct_request);
80 
81 struct rc_data {
82 	struct mtx		rc_lock;
83 	struct sockaddr_storage	rc_addr; /* server address */
84 	struct netconfig*	rc_nconf; /* network type */
85 	rpcprog_t		rc_prog;  /* program number */
86 	rpcvers_t		rc_vers;  /* version number */
87 	size_t			rc_sendsz;
88 	size_t			rc_recvsz;
89 	struct timeval		rc_timeout;
90 	struct timeval		rc_retry;
91 	int			rc_retries;
92 	int			rc_privport;
93 	char			*rc_waitchan;
94 	int			rc_intr;
95 	int			rc_connecting;
96 	int			rc_closed;
97 	struct ucred		*rc_ucred;
98 	CLIENT*			rc_client; /* underlying RPC client */
99 	struct rpc_err		rc_err;
100 	void			*rc_backchannel;
101 	bool			rc_tls; /* Enable TLS on connection */
102 	char			*rc_tlscertname;
103 	void			(*rc_reconcall)(CLIENT *, void *,
104 				    struct ucred *); /* reconection upcall */
105 	void			*rc_reconarg;	/* upcall arg */
106 	uint32_t		rc_rdmasmall_reply; /* size of small reply */
107 	uint32_t		rc_rdmamax_io;	/* size of largest I/O */
108 	uint32_t		rc_rdma_cbslots; /* Max. # of callbacks */
109 };
110 
111 /* Bits for ct_rcvstate. */
112 #define RPCRCVSTATE_NORMAL		0x01	/* Normal reception. */
113 #define RPCRCVSTATE_NONAPPDATA		0x02	/* Reception of a non-application record. */
114 #define RPCRCVSTATE_TLSHANDSHAKE	0x04	/* Reception blocked for TLS handshake. */
115 #define RPCRCVSTATE_UPCALLNEEDED	0x08	/* Upcall to rpctlscd needed. */
116 #define RPCRCVSTATE_UPCALLINPROG	0x10	/* Upcall to rpctlscd in progress. */
117 #define RPCRCVSTATE_SOUPCALLNEEDED	0x20	/* Socket upcall needed. */
118 #define RPCRCVSTATE_UPCALLTHREAD	0x40	/* Upcall kthread running. */
119 
120 struct ct_data {
121 	struct mtx	ct_lock;
122 	int		ct_threads;	/* number of threads in clnt_vc_call */
123 	bool_t		ct_closing;	/* TRUE if we are closing */
124 	bool_t		ct_closed;	/* TRUE if we are closed */
125 	struct socket	*ct_socket;	/* connection socket */
126 	bool_t		ct_closeit;	/* close it on destroy */
127 	struct timeval	ct_wait;	/* wait interval in milliseconds */
128 	struct sockaddr_storage	ct_addr; /* remote addr */
129 	struct rpc_err	ct_error;
130 	uint32_t	ct_xid;
131 	char		ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
132 	size_t		ct_mpos;	/* pos after marshal */
133 	const char	*ct_waitchan;
134 	int		ct_waitflag;
135 	struct mbuf	*ct_record;	/* current reply record */
136 	size_t		ct_record_resid; /* how much left of reply to read */
137 	bool_t		ct_record_eor;	 /* true if reading last fragment */
138 	struct ct_request_list ct_pending;
139 	int		ct_upcallrefs;	/* Ref cnt of upcalls in prog. */
140 	SVCXPRT		*ct_backchannelxprt; /* xprt for backchannel */
141 	enum tlsstate	{
142 	    RPCTLS_NONE = 0,
143 	    RPCTLS_INHANDSHAKE,	/* fd given to the daemon, daemon is working */
144 	    RPCTLS_COMPLETE,	/* daemon reported success rpctlscd_connect() */
145 	}		ct_tlsstate;
146 	uint32_t 	ct_rcvstate;	/* Handle receiving for TLS upcalls */
147 	struct mbuf	*ct_raw;	/* Raw mbufs recv'd */
148 };
149 
150 struct cf_conn {  /* kept in xprt->xp_p1 for actual connection */
151 	enum xprt_stat strm_stat;
152 	struct mbuf *mpending;	/* unparsed data read from the socket */
153 	struct mbuf *mreq;	/* current record being built from mpending */
154 	uint32_t resid;		/* number of bytes needed for fragment */
155 	bool_t eor;		/* reading last fragment of current record */
156 	bool_t rdma;		/* On an RDMA connection. */
157 };
158 
159 void rpcnl_init(void);
160 
161 /* RDMA procedures. */
162 enum rdma_proc {
163 	RDMA_MSG = 0,
164 	RDMA_NOMSG = 1,
165 	RDMA_MSGP = 2,	/* Not used. */
166 	RDMA_DONE = 3,	/* Not used. */
167 	RDMA_ERROR = 4
168 };
169 
170 enum rdma_errcode {
171 	RDMA_ERR_VERS = 1,
172 	RDMA_ERR_CHUNK = 2
173 };
174 
175 /* Structure use by both client and server RDMA for reductions (RFC8166). */
176 struct rpcrdma_reduce {
177 	struct iovec	*iov;
178 	uint32_t	xid;
179 	uint32_t	off;
180 	uint32_t	len;
181 	uint8_t		into_mem;
182 };
183 
184 #endif	/* _KERNEL */
185 
186 #endif	/* _RPC_KRPC_H_ */
187