Print this page
*** NO COMMENTS ***
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/rpc/svc_clts.c
+++ new/usr/src/uts/common/rpc/svc_clts.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 26 /* All Rights Reserved */
27 27
28 28 /*
29 + * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
30 + */
31 +
32 +/*
29 33 * Portions of this source code were derived from Berkeley 4.3 BSD
30 34 * under license from the Regents of the University of California.
31 35 */
32 36
33 37 /*
34 38 * svc_clts.c
35 39 * Server side for RPC in the kernel.
36 40 *
37 41 */
38 42
39 43 #include <sys/param.h>
40 44 #include <sys/types.h>
41 45 #include <sys/sysmacros.h>
42 46 #include <sys/file.h>
43 47 #include <sys/stream.h>
44 48 #include <sys/strsun.h>
45 49 #include <sys/strsubr.h>
46 50 #include <sys/tihdr.h>
47 51 #include <sys/tiuser.h>
48 52 #include <sys/t_kuser.h>
49 53 #include <sys/fcntl.h>
50 54 #include <sys/errno.h>
51 55 #include <sys/kmem.h>
52 56 #include <sys/systm.h>
53 57 #include <sys/cmn_err.h>
54 58 #include <sys/kstat.h>
55 59 #include <sys/vtrace.h>
56 60 #include <sys/debug.h>
57 61
58 62 #include <rpc/types.h>
59 63 #include <rpc/xdr.h>
60 64 #include <rpc/auth.h>
61 65 #include <rpc/clnt.h>
62 66 #include <rpc/rpc_msg.h>
63 67 #include <rpc/svc.h>
64 68 #include <inet/ip.h>
65 69
66 70 /*
67 71 * Routines exported through ops vector.
68 72 */
69 73 static bool_t svc_clts_krecv(SVCXPRT *, mblk_t *, struct rpc_msg *);
70 74 static bool_t svc_clts_ksend(SVCXPRT *, struct rpc_msg *);
71 75 static bool_t svc_clts_kgetargs(SVCXPRT *, xdrproc_t, caddr_t);
72 76 static bool_t svc_clts_kfreeargs(SVCXPRT *, xdrproc_t, caddr_t);
73 77 static void svc_clts_kdestroy(SVCMASTERXPRT *);
74 78 static int svc_clts_kdup(struct svc_req *, caddr_t, int,
75 79 struct dupreq **, bool_t *);
76 80 static void svc_clts_kdupdone(struct dupreq *, caddr_t,
77 81 void (*)(), int, int);
78 82 static int32_t *svc_clts_kgetres(SVCXPRT *, int);
79 83 static void svc_clts_kclone_destroy(SVCXPRT *);
80 84 static void svc_clts_kfreeres(SVCXPRT *);
81 85 static void svc_clts_kstart(SVCMASTERXPRT *);
82 86 static void svc_clts_kclone_xprt(SVCXPRT *, SVCXPRT *);
83 87 static void svc_clts_ktattrs(SVCXPRT *, int, void **);
84 88
85 89 /*
86 90 * Server transport operations vector.
87 91 */
88 92 struct svc_ops svc_clts_op = {
89 93 svc_clts_krecv, /* Get requests */
90 94 svc_clts_kgetargs, /* Deserialize arguments */
91 95 svc_clts_ksend, /* Send reply */
92 96 svc_clts_kfreeargs, /* Free argument data space */
93 97 svc_clts_kdestroy, /* Destroy transport handle */
94 98 svc_clts_kdup, /* Check entry in dup req cache */
95 99 svc_clts_kdupdone, /* Mark entry in dup req cache as done */
96 100 svc_clts_kgetres, /* Get pointer to response buffer */
97 101 svc_clts_kfreeres, /* Destroy pre-serialized response header */
98 102 svc_clts_kclone_destroy, /* Destroy a clone xprt */
99 103 svc_clts_kstart, /* Tell `ready-to-receive' to rpcmod */
100 104 svc_clts_kclone_xprt, /* transport specific clone xprt function */
↓ open down ↓ |
62 lines elided |
↑ open up ↑ |
101 105 svc_clts_ktattrs /* Transport specific attributes. */
102 106 };
103 107
104 108 /*
105 109 * Transport private data.
106 110 * Kept in xprt->xp_p2buf.
107 111 */
108 112 struct udp_data {
109 113 mblk_t *ud_resp; /* buffer for response */
110 114 mblk_t *ud_inmp; /* mblk chain of request */
115 + sin6_t ud_local; /* local address */
111 116 };
112 117
113 118 #define UD_MAXSIZE 8800
114 119 #define UD_INITSIZE 2048
115 120
116 121 /*
117 122 * Connectionless server statistics
118 123 */
119 124 static const struct rpc_clts_server {
120 125 kstat_named_t rscalls;
121 126 kstat_named_t rsbadcalls;
122 127 kstat_named_t rsnullrecv;
123 128 kstat_named_t rsbadlen;
124 129 kstat_named_t rsxdrcall;
125 130 kstat_named_t rsdupchecks;
126 131 kstat_named_t rsdupreqs;
127 132 } clts_rsstat_tmpl = {
128 133 { "calls", KSTAT_DATA_UINT64 },
129 134 { "badcalls", KSTAT_DATA_UINT64 },
130 135 { "nullrecv", KSTAT_DATA_UINT64 },
131 136 { "badlen", KSTAT_DATA_UINT64 },
132 137 { "xdrcall", KSTAT_DATA_UINT64 },
133 138 { "dupchecks", KSTAT_DATA_UINT64 },
134 139 { "dupreqs", KSTAT_DATA_UINT64 }
135 140 };
136 141
137 142 static uint_t clts_rsstat_ndata =
138 143 sizeof (clts_rsstat_tmpl) / sizeof (kstat_named_t);
139 144
140 145 #define CLONE2STATS(clone_xprt) \
141 146 (struct rpc_clts_server *)(clone_xprt)->xp_master->xp_p2
142 147
143 148 #define RSSTAT_INCR(stats, x) \
144 149 atomic_add_64(&(stats)->x.value.ui64, 1)
145 150
146 151 /*
147 152 * Create a transport record.
148 153 * The transport record, output buffer, and private data structure
149 154 * are allocated. The output buffer is serialized into using xdrmem.
150 155 * There is one transport record per user process which implements a
151 156 * set of services.
152 157 */
153 158 /* ARGSUSED */
154 159 int
155 160 svc_clts_kcreate(file_t *fp, uint_t sendsz, struct T_info_ack *tinfo,
156 161 SVCMASTERXPRT **nxprt)
157 162 {
158 163 SVCMASTERXPRT *xprt;
159 164 struct rpcstat *rpcstat;
160 165
161 166 if (nxprt == NULL)
162 167 return (EINVAL);
163 168
164 169 rpcstat = zone_getspecific(rpcstat_zone_key, curproc->p_zone);
165 170 ASSERT(rpcstat != NULL);
166 171
167 172 xprt = kmem_zalloc(sizeof (*xprt), KM_SLEEP);
168 173 xprt->xp_lcladdr.buf = kmem_zalloc(sizeof (sin6_t), KM_SLEEP);
169 174 xprt->xp_p2 = (caddr_t)rpcstat->rpc_clts_server;
170 175 xprt->xp_ops = &svc_clts_op;
171 176 xprt->xp_msg_size = tinfo->TSDU_size;
172 177
173 178 xprt->xp_rtaddr.buf = NULL;
174 179 xprt->xp_rtaddr.maxlen = tinfo->ADDR_size;
175 180 xprt->xp_rtaddr.len = 0;
176 181
177 182 *nxprt = xprt;
178 183
179 184 return (0);
180 185 }
181 186
182 187 /*
183 188 * Destroy a transport record.
184 189 * Frees the space allocated for a transport record.
185 190 */
186 191 static void
187 192 svc_clts_kdestroy(SVCMASTERXPRT *xprt)
188 193 {
189 194 if (xprt->xp_netid)
190 195 kmem_free(xprt->xp_netid, strlen(xprt->xp_netid) + 1);
191 196 if (xprt->xp_addrmask.maxlen)
192 197 kmem_free(xprt->xp_addrmask.buf, xprt->xp_addrmask.maxlen);
193 198
194 199 mutex_destroy(&xprt->xp_req_lock);
195 200 mutex_destroy(&xprt->xp_thread_lock);
196 201
197 202 kmem_free(xprt->xp_lcladdr.buf, sizeof (sin6_t));
198 203 kmem_free(xprt, sizeof (SVCMASTERXPRT));
199 204 }
200 205
201 206 /*
202 207 * Transport-type specific part of svc_xprt_cleanup().
203 208 * Frees the message buffer space allocated for a clone of a transport record
204 209 */
205 210 static void
206 211 svc_clts_kclone_destroy(SVCXPRT *clone_xprt)
207 212 {
208 213 /* LINTED pointer alignment */
209 214 struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
210 215
211 216 if (ud->ud_resp) {
212 217 /*
213 218 * There should not be any left over results buffer.
214 219 */
215 220 ASSERT(ud->ud_resp->b_cont == NULL);
216 221
217 222 /*
218 223 * Free the T_UNITDATA_{REQ/IND} that svc_clts_krecv
219 224 * saved.
220 225 */
221 226 freeb(ud->ud_resp);
222 227 }
223 228 if (ud->ud_inmp)
224 229 freemsg(ud->ud_inmp);
225 230 }
226 231
227 232 /*
228 233 * svc_tli_kcreate() calls this function at the end to tell
229 234 * rpcmod that the transport is ready to receive requests.
230 235 */
231 236 /* ARGSUSED */
232 237 static void
233 238 svc_clts_kstart(SVCMASTERXPRT *xprt)
234 239 {
235 240 }
236 241
237 242 static void
238 243 svc_clts_kclone_xprt(SVCXPRT *src_xprt, SVCXPRT *dst_xprt)
239 244 {
240 245 struct udp_data *ud_src =
241 246 (struct udp_data *)src_xprt->xp_p2buf;
242 247 struct udp_data *ud_dst =
243 248 (struct udp_data *)dst_xprt->xp_p2buf;
244 249
245 250 if (ud_src->ud_resp)
246 251 ud_dst->ud_resp = dupb(ud_src->ud_resp);
247 252
248 253 }
249 254
250 255 static void
251 256 svc_clts_ktattrs(SVCXPRT *clone_xprt, int attrflag, void **tattr)
252 257 {
253 258 *tattr = NULL;
254 259
255 260 switch (attrflag) {
256 261 case SVC_TATTR_ADDRMASK:
257 262 *tattr = (void *)&clone_xprt->xp_master->xp_addrmask;
258 263 }
259 264 }
260 265
261 266 /*
262 267 * Receive rpc requests.
263 268 * Pulls a request in off the socket, checks if the packet is intact,
264 269 * and deserializes the call packet.
265 270 */
266 271 static bool_t
267 272 svc_clts_krecv(SVCXPRT *clone_xprt, mblk_t *mp, struct rpc_msg *msg)
268 273 {
269 274 /* LINTED pointer alignment */
270 275 struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
271 276 XDR *xdrs = &clone_xprt->xp_xdrin;
272 277 struct rpc_clts_server *stats = CLONE2STATS(clone_xprt);
273 278 union T_primitives *pptr;
274 279 int hdrsz;
275 280 cred_t *cr;
276 281
277 282 TRACE_0(TR_FAC_KRPC, TR_SVC_CLTS_KRECV_START,
278 283 "svc_clts_krecv_start:");
279 284
280 285 RSSTAT_INCR(stats, rscalls);
281 286
282 287 /*
283 288 * The incoming request should start with an M_PROTO message.
284 289 */
285 290 if (mp->b_datap->db_type != M_PROTO) {
286 291 goto bad;
287 292 }
288 293
289 294 /*
290 295 * The incoming request should be an T_UNITDTA_IND. There
291 296 * might be other messages coming up the stream, but we can
292 297 * ignore them.
293 298 */
294 299 pptr = (union T_primitives *)mp->b_rptr;
295 300 if (pptr->type != T_UNITDATA_IND) {
296 301 goto bad;
297 302 }
298 303 /*
299 304 * Do some checking to make sure that the header at least looks okay.
300 305 */
301 306 hdrsz = (int)(mp->b_wptr - mp->b_rptr);
302 307 if (hdrsz < TUNITDATAINDSZ ||
303 308 hdrsz < (pptr->unitdata_ind.OPT_offset +
304 309 pptr->unitdata_ind.OPT_length) ||
305 310 hdrsz < (pptr->unitdata_ind.SRC_offset +
306 311 pptr->unitdata_ind.SRC_length)) {
307 312 goto bad;
308 313 }
309 314
310 315 /*
311 316 * Make sure that the transport provided a usable address.
312 317 */
313 318 if (pptr->unitdata_ind.SRC_length <= 0) {
↓ open down ↓ |
193 lines elided |
↑ open up ↑ |
314 319 goto bad;
315 320 }
316 321 /*
317 322 * Point the remote transport address in the service_transport
318 323 * handle at the address in the request.
319 324 */
320 325 clone_xprt->xp_rtaddr.buf = (char *)mp->b_rptr +
321 326 pptr->unitdata_ind.SRC_offset;
322 327 clone_xprt->xp_rtaddr.len = pptr->unitdata_ind.SRC_length;
323 328
329 + clone_xprt->xp_lcladdr.buf = (char *)&ud->ud_local;
330 +
324 331 /*
325 332 * Copy the local transport address in the service_transport
326 333 * handle at the address in the request. We will have only
327 334 * the local IP address in options.
328 335 */
329 336 ((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_family = AF_UNSPEC;
330 337 if (pptr->unitdata_ind.OPT_length && pptr->unitdata_ind.OPT_offset) {
331 338 char *dstopt = (char *)mp->b_rptr +
332 339 pptr->unitdata_ind.OPT_offset;
333 340 struct T_opthdr *toh = (struct T_opthdr *)dstopt;
334 341
335 342 if (toh->level == IPPROTO_IPV6 && toh->status == 0 &&
336 343 toh->name == IPV6_PKTINFO) {
337 344 struct in6_pktinfo *pkti;
338 345
339 346 dstopt += sizeof (struct T_opthdr);
340 347 pkti = (struct in6_pktinfo *)dstopt;
341 348 ((sin6_t *)(clone_xprt->xp_lcladdr.buf))->sin6_addr
342 349 = pkti->ipi6_addr;
343 350 ((sin6_t *)(clone_xprt->xp_lcladdr.buf))->sin6_family
344 351 = AF_INET6;
345 352 } else if (toh->level == IPPROTO_IP && toh->status == 0 &&
346 353 toh->name == IP_RECVDSTADDR) {
347 354 dstopt += sizeof (struct T_opthdr);
348 355 ((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_addr
349 356 = *(struct in_addr *)dstopt;
350 357 ((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_family
351 358 = AF_INET;
352 359 }
353 360 }
354 361
355 362 /*
356 363 * Save the first mblk which contains the T_unidata_ind in
357 364 * ud_resp. It will be used to generate the T_unitdata_req
358 365 * during the reply.
359 366 * We reuse any options in the T_unitdata_ind for the T_unitdata_req
360 367 * since we must pass any SCM_UCRED across in order for TX to
361 368 * work. We also make sure any cred_t is carried across.
362 369 */
363 370 if (ud->ud_resp) {
364 371 if (ud->ud_resp->b_cont != NULL) {
365 372 cmn_err(CE_WARN, "svc_clts_krecv: ud_resp %p, "
366 373 "b_cont %p", (void *)ud->ud_resp,
367 374 (void *)ud->ud_resp->b_cont);
368 375 }
369 376 freeb(ud->ud_resp);
370 377 }
371 378 /* Move any cred_t to the first mblk in the message */
372 379 cr = msg_getcred(mp, NULL);
373 380 if (cr != NULL)
374 381 mblk_setcred(mp, cr, NOPID);
375 382
376 383 ud->ud_resp = mp;
377 384 mp = mp->b_cont;
378 385 ud->ud_resp->b_cont = NULL;
379 386
380 387 xdrmblk_init(xdrs, mp, XDR_DECODE, 0);
381 388
382 389 TRACE_0(TR_FAC_KRPC, TR_XDR_CALLMSG_START,
383 390 "xdr_callmsg_start:");
384 391 if (! xdr_callmsg(xdrs, msg)) {
385 392 TRACE_1(TR_FAC_KRPC, TR_XDR_CALLMSG_END,
386 393 "xdr_callmsg_end:(%S)", "bad");
387 394 RSSTAT_INCR(stats, rsxdrcall);
388 395 goto bad;
389 396 }
390 397 TRACE_1(TR_FAC_KRPC, TR_XDR_CALLMSG_END,
391 398 "xdr_callmsg_end:(%S)", "good");
392 399
393 400 clone_xprt->xp_xid = msg->rm_xid;
394 401 ud->ud_inmp = mp;
395 402
396 403 TRACE_1(TR_FAC_KRPC, TR_SVC_CLTS_KRECV_END,
397 404 "svc_clts_krecv_end:(%S)", "good");
398 405 return (TRUE);
399 406
400 407 bad:
401 408 freemsg(mp);
402 409 if (ud->ud_resp) {
403 410 /*
404 411 * There should not be any left over results buffer.
405 412 */
406 413 ASSERT(ud->ud_resp->b_cont == NULL);
407 414 freeb(ud->ud_resp);
408 415 ud->ud_resp = NULL;
409 416 }
410 417
411 418 RSSTAT_INCR(stats, rsbadcalls);
412 419 TRACE_1(TR_FAC_KRPC, TR_SVC_CLTS_KRECV_END,
413 420 "svc_clts_krecv_end:(%S)", "bad");
414 421 return (FALSE);
415 422 }
416 423
417 424 /*
418 425 * Send rpc reply.
419 426 * Serialize the reply packet into the output buffer then
420 427 * call t_ksndudata to send it.
421 428 */
422 429 static bool_t
423 430 svc_clts_ksend(SVCXPRT *clone_xprt, struct rpc_msg *msg)
424 431 {
425 432 /* LINTED pointer alignment */
426 433 struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
427 434 XDR *xdrs = &clone_xprt->xp_xdrout;
428 435 int stat = FALSE;
429 436 mblk_t *mp;
430 437 int msgsz;
431 438 struct T_unitdata_req *udreq;
432 439 xdrproc_t xdr_results;
433 440 caddr_t xdr_location;
434 441 bool_t has_args;
435 442
436 443 TRACE_0(TR_FAC_KRPC, TR_SVC_CLTS_KSEND_START,
437 444 "svc_clts_ksend_start:");
438 445
439 446 ASSERT(ud->ud_resp != NULL);
440 447
441 448 /*
442 449 * If there is a result procedure specified in the reply message,
443 450 * it will be processed in the xdr_replymsg and SVCAUTH_WRAP.
444 451 * We need to make sure it won't be processed twice, so we null
445 452 * it for xdr_replymsg here.
446 453 */
447 454 has_args = FALSE;
448 455 if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
449 456 msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
450 457 if ((xdr_results = msg->acpted_rply.ar_results.proc) != NULL) {
451 458 has_args = TRUE;
452 459 xdr_location = msg->acpted_rply.ar_results.where;
453 460 msg->acpted_rply.ar_results.proc = xdr_void;
454 461 msg->acpted_rply.ar_results.where = NULL;
455 462 }
456 463 }
457 464
458 465 if (ud->ud_resp->b_cont == NULL) {
459 466 /*
460 467 * Allocate an initial mblk for the response data.
461 468 */
462 469 while ((mp = allocb(UD_INITSIZE, BPRI_LO)) == NULL) {
463 470 if (strwaitbuf(UD_INITSIZE, BPRI_LO)) {
464 471 TRACE_1(TR_FAC_KRPC, TR_SVC_CLTS_KSEND_END,
465 472 "svc_clts_ksend_end:(%S)", "strwaitbuf");
466 473 return (FALSE);
467 474 }
468 475 }
469 476
470 477 /*
471 478 * Initialize the XDR decode stream. Additional mblks
472 479 * will be allocated if necessary. They will be UD_MAXSIZE
473 480 * sized.
474 481 */
475 482 xdrmblk_init(xdrs, mp, XDR_ENCODE, UD_MAXSIZE);
476 483
477 484 /*
478 485 * Leave some space for protocol headers.
479 486 */
480 487 (void) XDR_SETPOS(xdrs, 512);
481 488 mp->b_rptr += 512;
482 489
483 490 msg->rm_xid = clone_xprt->xp_xid;
484 491
485 492 ud->ud_resp->b_cont = mp;
486 493
487 494 TRACE_0(TR_FAC_KRPC, TR_XDR_REPLYMSG_START,
488 495 "xdr_replymsg_start:");
489 496 if (!(xdr_replymsg(xdrs, msg) &&
490 497 (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, xdrs,
491 498 xdr_results, xdr_location)))) {
492 499 TRACE_1(TR_FAC_KRPC, TR_XDR_REPLYMSG_END,
493 500 "xdr_replymsg_end:(%S)", "bad");
494 501 RPCLOG0(1, "xdr_replymsg/SVCAUTH_WRAP failed\n");
495 502 goto out;
496 503 }
497 504 TRACE_1(TR_FAC_KRPC, TR_XDR_REPLYMSG_END,
498 505 "xdr_replymsg_end:(%S)", "good");
499 506
500 507 } else if (!(xdr_replymsg_body(xdrs, msg) &&
501 508 (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, xdrs,
502 509 xdr_results, xdr_location)))) {
503 510 RPCLOG0(1, "xdr_replymsg_body/SVCAUTH_WRAP failed\n");
504 511 goto out;
505 512 }
506 513
507 514 msgsz = (int)xmsgsize(ud->ud_resp->b_cont);
508 515
509 516 if (msgsz <= 0 || (clone_xprt->xp_msg_size != -1 &&
510 517 msgsz > clone_xprt->xp_msg_size)) {
511 518 #ifdef DEBUG
512 519 cmn_err(CE_NOTE,
513 520 "KRPC: server response message of %d bytes; transport limits are [0, %d]",
514 521 msgsz, clone_xprt->xp_msg_size);
515 522 #endif
516 523 goto out;
517 524 }
518 525
519 526 /*
520 527 * Construct the T_unitdata_req. We take advantage of the fact that
521 528 * T_unitdata_ind looks just like T_unitdata_req, except for the
522 529 * primitive type. Reusing it means we preserve the SCM_UCRED, and
523 530 * we must preserve it for TX to work.
524 531 *
525 532 * This has the side effect that we can also pass certain receive-side
526 533 * options like IPV6_PKTINFO back down the send side. This implies
527 534 * that we can not ASSERT on a non-NULL db_credp when we have send-side
528 535 * options in UDP.
529 536 */
530 537 ASSERT(MBLKL(ud->ud_resp) >= TUNITDATAREQSZ);
531 538 udreq = (struct T_unitdata_req *)ud->ud_resp->b_rptr;
532 539 ASSERT(udreq->PRIM_type == T_UNITDATA_IND);
533 540 udreq->PRIM_type = T_UNITDATA_REQ;
534 541
535 542 /*
536 543 * If the local IPv4 transport address is known use it as a source
537 544 * address for the outgoing UDP packet.
538 545 */
539 546 if (((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_family == AF_INET) {
540 547 struct T_opthdr *opthdr;
541 548 in_pktinfo_t *pktinfo;
542 549 size_t size;
543 550
544 551 if (udreq->DEST_length == 0)
545 552 udreq->OPT_offset = _TPI_ALIGN_TOPT(TUNITDATAREQSZ);
546 553 else
547 554 udreq->OPT_offset = _TPI_ALIGN_TOPT(udreq->DEST_offset +
548 555 udreq->DEST_length);
549 556
550 557 udreq->OPT_length = sizeof (struct T_opthdr) +
551 558 sizeof (in_pktinfo_t);
552 559
553 560 size = udreq->OPT_length + udreq->OPT_offset;
554 561
555 562 /* make sure we have enough space for the option data */
556 563 mp = reallocb(ud->ud_resp, size, 1);
557 564 if (mp == NULL)
558 565 goto out;
559 566 ud->ud_resp = mp;
560 567 udreq = (struct T_unitdata_req *)mp->b_rptr;
561 568
562 569 /* set desired option header */
563 570 opthdr = (struct T_opthdr *)(mp->b_rptr + udreq->OPT_offset);
564 571 opthdr->len = udreq->OPT_length;
565 572 opthdr->level = IPPROTO_IP;
566 573 opthdr->name = IP_PKTINFO;
567 574
568 575 /*
569 576 * 1. set source IP of outbound packet
570 577 * 2. value '0' for index means IP layer uses this as source
571 578 * address
572 579 */
573 580 pktinfo = (in_pktinfo_t *)(opthdr + 1);
574 581 (void) memset(pktinfo, 0, sizeof (in_pktinfo_t));
575 582 pktinfo->ipi_spec_dst.s_addr =
576 583 ((sin_t *)(clone_xprt->xp_lcladdr.buf))->sin_addr.s_addr;
577 584 pktinfo->ipi_ifindex = 0;
578 585
579 586 /* adjust the end of active data */
580 587 mp->b_wptr = mp->b_rptr + size;
581 588 }
582 589
583 590 put(clone_xprt->xp_wq, ud->ud_resp);
584 591 stat = TRUE;
585 592 ud->ud_resp = NULL;
586 593
587 594 out:
588 595 if (stat == FALSE) {
589 596 freemsg(ud->ud_resp);
590 597 ud->ud_resp = NULL;
591 598 }
592 599
593 600 /*
594 601 * This is completely disgusting. If public is set it is
595 602 * a pointer to a structure whose first field is the address
596 603 * of the function to free that structure and any related
597 604 * stuff. (see rrokfree in nfs_xdr.c).
598 605 */
599 606 if (xdrs->x_public) {
600 607 /* LINTED pointer alignment */
601 608 (**((int (**)())xdrs->x_public))(xdrs->x_public);
602 609 }
603 610
604 611 TRACE_1(TR_FAC_KRPC, TR_SVC_CLTS_KSEND_END,
605 612 "svc_clts_ksend_end:(%S)", "done");
606 613 return (stat);
607 614 }
608 615
609 616 /*
610 617 * Deserialize arguments.
611 618 */
612 619 static bool_t
613 620 svc_clts_kgetargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args,
614 621 caddr_t args_ptr)
615 622 {
616 623
617 624 /* LINTED pointer alignment */
618 625 return (SVCAUTH_UNWRAP(&clone_xprt->xp_auth, &clone_xprt->xp_xdrin,
619 626 xdr_args, args_ptr));
620 627
621 628 }
622 629
623 630 static bool_t
624 631 svc_clts_kfreeargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args,
625 632 caddr_t args_ptr)
626 633 {
627 634 /* LINTED pointer alignment */
628 635 struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
629 636 XDR *xdrs = &clone_xprt->xp_xdrin;
630 637 bool_t retval;
631 638
632 639 if (args_ptr) {
633 640 xdrs->x_op = XDR_FREE;
634 641 retval = (*xdr_args)(xdrs, args_ptr);
635 642 } else
636 643 retval = TRUE;
637 644
638 645 if (ud->ud_inmp) {
639 646 freemsg(ud->ud_inmp);
640 647 ud->ud_inmp = NULL;
641 648 }
642 649
643 650 return (retval);
644 651 }
645 652
646 653 static int32_t *
647 654 svc_clts_kgetres(SVCXPRT *clone_xprt, int size)
648 655 {
649 656 /* LINTED pointer alignment */
650 657 struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
651 658 XDR *xdrs = &clone_xprt->xp_xdrout;
652 659 mblk_t *mp;
653 660 int32_t *buf;
654 661 struct rpc_msg rply;
655 662
656 663 /*
657 664 * Allocate an initial mblk for the response data.
658 665 */
659 666 while ((mp = allocb(UD_INITSIZE, BPRI_LO)) == NULL) {
660 667 if (strwaitbuf(UD_INITSIZE, BPRI_LO)) {
661 668 return (FALSE);
662 669 }
663 670 }
664 671
665 672 mp->b_cont = NULL;
666 673
667 674 /*
668 675 * Initialize the XDR decode stream. Additional mblks
669 676 * will be allocated if necessary. They will be UD_MAXSIZE
670 677 * sized.
671 678 */
672 679 xdrmblk_init(xdrs, mp, XDR_ENCODE, UD_MAXSIZE);
673 680
674 681 /*
675 682 * Leave some space for protocol headers.
676 683 */
677 684 (void) XDR_SETPOS(xdrs, 512);
678 685 mp->b_rptr += 512;
679 686
680 687 /*
681 688 * Assume a successful RPC since most of them are.
682 689 */
683 690 rply.rm_xid = clone_xprt->xp_xid;
684 691 rply.rm_direction = REPLY;
685 692 rply.rm_reply.rp_stat = MSG_ACCEPTED;
686 693 rply.acpted_rply.ar_verf = clone_xprt->xp_verf;
687 694 rply.acpted_rply.ar_stat = SUCCESS;
688 695
689 696 if (!xdr_replymsg_hdr(xdrs, &rply)) {
690 697 freeb(mp);
691 698 return (NULL);
692 699 }
693 700
694 701 buf = XDR_INLINE(xdrs, size);
695 702
696 703 if (buf == NULL)
697 704 freeb(mp);
698 705 else
699 706 ud->ud_resp->b_cont = mp;
700 707
701 708 return (buf);
702 709 }
703 710
704 711 static void
705 712 svc_clts_kfreeres(SVCXPRT *clone_xprt)
706 713 {
707 714 /* LINTED pointer alignment */
708 715 struct udp_data *ud = (struct udp_data *)clone_xprt->xp_p2buf;
709 716
710 717 if (ud->ud_resp == NULL || ud->ud_resp->b_cont == NULL)
711 718 return;
712 719
713 720 /*
714 721 * SVC_FREERES() is called whenever the server decides not to
715 722 * send normal reply. Thus, we expect only one mblk to be allocated,
716 723 * because we have not attempted any XDR encoding.
717 724 * If we do any XDR encoding and we get an error, then SVC_REPLY()
718 725 * will freemsg(ud->ud_resp);
719 726 */
720 727 ASSERT(ud->ud_resp->b_cont->b_cont == NULL);
721 728 freeb(ud->ud_resp->b_cont);
722 729 ud->ud_resp->b_cont = NULL;
723 730 }
724 731
725 732 /*
726 733 * the dup cacheing routines below provide a cache of non-failure
727 734 * transaction id's. rpc service routines can use this to detect
728 735 * retransmissions and re-send a non-failure response.
729 736 */
730 737
731 738 /*
732 739 * MAXDUPREQS is the number of cached items. It should be adjusted
733 740 * to the service load so that there is likely to be a response entry
734 741 * when the first retransmission comes in.
735 742 */
736 743 #define MAXDUPREQS 1024
737 744
738 745 /*
739 746 * This should be appropriately scaled to MAXDUPREQS.
740 747 */
741 748 #define DRHASHSZ 257
742 749
743 750 #if ((DRHASHSZ & (DRHASHSZ - 1)) == 0)
744 751 #define XIDHASH(xid) ((xid) & (DRHASHSZ - 1))
745 752 #else
746 753 #define XIDHASH(xid) ((xid) % DRHASHSZ)
747 754 #endif
748 755 #define DRHASH(dr) XIDHASH((dr)->dr_xid)
749 756 #define REQTOXID(req) ((req)->rq_xprt->xp_xid)
750 757
751 758 static int ndupreqs = 0;
752 759 int maxdupreqs = MAXDUPREQS;
753 760 static kmutex_t dupreq_lock;
754 761 static struct dupreq *drhashtbl[DRHASHSZ];
755 762 static int drhashstat[DRHASHSZ];
756 763
757 764 static void unhash(struct dupreq *);
758 765
759 766 /*
760 767 * drmru points to the head of a circular linked list in lru order.
761 768 * drmru->dr_next == drlru
762 769 */
763 770 struct dupreq *drmru;
764 771
765 772 /*
766 773 * PSARC 2003/523 Contract Private Interface
767 774 * svc_clts_kdup
768 775 * Changes must be reviewed by Solaris File Sharing
769 776 * Changes must be communicated to contract-2003-523@sun.com
770 777 *
771 778 * svc_clts_kdup searches the request cache and returns 0 if the
772 779 * request is not found in the cache. If it is found, then it
773 780 * returns the state of the request (in progress or done) and
774 781 * the status or attributes that were part of the original reply.
775 782 *
776 783 * If DUP_DONE (there is a duplicate) svc_clts_kdup copies over the
777 784 * value of the response. In that case, also return in *dupcachedp
778 785 * whether the response free routine is cached in the dupreq - in which case
779 786 * the caller should not be freeing it, because it will be done later
780 787 * in the svc_clts_kdup code when the dupreq is reused.
781 788 */
782 789 static int
783 790 svc_clts_kdup(struct svc_req *req, caddr_t res, int size, struct dupreq **drpp,
784 791 bool_t *dupcachedp)
785 792 {
786 793 struct rpc_clts_server *stats = CLONE2STATS(req->rq_xprt);
787 794 struct dupreq *dr;
788 795 uint32_t xid;
789 796 uint32_t drhash;
790 797 int status;
791 798
792 799 xid = REQTOXID(req);
793 800 mutex_enter(&dupreq_lock);
794 801 RSSTAT_INCR(stats, rsdupchecks);
795 802 /*
796 803 * Check to see whether an entry already exists in the cache.
797 804 */
798 805 dr = drhashtbl[XIDHASH(xid)];
799 806 while (dr != NULL) {
800 807 if (dr->dr_xid == xid &&
801 808 dr->dr_proc == req->rq_proc &&
802 809 dr->dr_prog == req->rq_prog &&
803 810 dr->dr_vers == req->rq_vers &&
804 811 dr->dr_addr.len == req->rq_xprt->xp_rtaddr.len &&
805 812 bcmp(dr->dr_addr.buf, req->rq_xprt->xp_rtaddr.buf,
806 813 dr->dr_addr.len) == 0) {
807 814 status = dr->dr_status;
808 815 if (status == DUP_DONE) {
809 816 bcopy(dr->dr_resp.buf, res, size);
810 817 if (dupcachedp != NULL)
811 818 *dupcachedp = (dr->dr_resfree != NULL);
812 819 } else {
813 820 dr->dr_status = DUP_INPROGRESS;
814 821 *drpp = dr;
815 822 }
816 823 RSSTAT_INCR(stats, rsdupreqs);
817 824 mutex_exit(&dupreq_lock);
818 825 return (status);
819 826 }
820 827 dr = dr->dr_chain;
821 828 }
822 829
823 830 /*
824 831 * There wasn't an entry, either allocate a new one or recycle
825 832 * an old one.
826 833 */
827 834 if (ndupreqs < maxdupreqs) {
828 835 dr = kmem_alloc(sizeof (*dr), KM_NOSLEEP);
829 836 if (dr == NULL) {
830 837 mutex_exit(&dupreq_lock);
831 838 return (DUP_ERROR);
832 839 }
833 840 dr->dr_resp.buf = NULL;
834 841 dr->dr_resp.maxlen = 0;
835 842 dr->dr_addr.buf = NULL;
836 843 dr->dr_addr.maxlen = 0;
837 844 if (drmru) {
838 845 dr->dr_next = drmru->dr_next;
839 846 drmru->dr_next = dr;
840 847 } else {
841 848 dr->dr_next = dr;
842 849 }
843 850 ndupreqs++;
844 851 } else {
845 852 dr = drmru->dr_next;
846 853 while (dr->dr_status == DUP_INPROGRESS) {
847 854 dr = dr->dr_next;
848 855 if (dr == drmru->dr_next) {
849 856 cmn_err(CE_WARN, "svc_clts_kdup no slots free");
850 857 mutex_exit(&dupreq_lock);
851 858 return (DUP_ERROR);
852 859 }
853 860 }
854 861 unhash(dr);
855 862 if (dr->dr_resfree) {
856 863 (*dr->dr_resfree)(dr->dr_resp.buf);
857 864 }
858 865 }
859 866 dr->dr_resfree = NULL;
860 867 drmru = dr;
861 868
862 869 dr->dr_xid = REQTOXID(req);
863 870 dr->dr_prog = req->rq_prog;
864 871 dr->dr_vers = req->rq_vers;
865 872 dr->dr_proc = req->rq_proc;
866 873 if (dr->dr_addr.maxlen < req->rq_xprt->xp_rtaddr.len) {
867 874 if (dr->dr_addr.buf != NULL)
868 875 kmem_free(dr->dr_addr.buf, dr->dr_addr.maxlen);
869 876 dr->dr_addr.maxlen = req->rq_xprt->xp_rtaddr.len;
870 877 dr->dr_addr.buf = kmem_alloc(dr->dr_addr.maxlen,
871 878 KM_NOSLEEP);
872 879 if (dr->dr_addr.buf == NULL) {
873 880 dr->dr_addr.maxlen = 0;
874 881 dr->dr_status = DUP_DROP;
875 882 mutex_exit(&dupreq_lock);
876 883 return (DUP_ERROR);
877 884 }
878 885 }
879 886 dr->dr_addr.len = req->rq_xprt->xp_rtaddr.len;
880 887 bcopy(req->rq_xprt->xp_rtaddr.buf, dr->dr_addr.buf, dr->dr_addr.len);
881 888 if (dr->dr_resp.maxlen < size) {
882 889 if (dr->dr_resp.buf != NULL)
883 890 kmem_free(dr->dr_resp.buf, dr->dr_resp.maxlen);
884 891 dr->dr_resp.maxlen = (unsigned int)size;
885 892 dr->dr_resp.buf = kmem_alloc(size, KM_NOSLEEP);
886 893 if (dr->dr_resp.buf == NULL) {
887 894 dr->dr_resp.maxlen = 0;
888 895 dr->dr_status = DUP_DROP;
889 896 mutex_exit(&dupreq_lock);
890 897 return (DUP_ERROR);
891 898 }
892 899 }
893 900 dr->dr_status = DUP_INPROGRESS;
894 901
895 902 drhash = (uint32_t)DRHASH(dr);
896 903 dr->dr_chain = drhashtbl[drhash];
897 904 drhashtbl[drhash] = dr;
898 905 drhashstat[drhash]++;
899 906 mutex_exit(&dupreq_lock);
900 907 *drpp = dr;
901 908 return (DUP_NEW);
902 909 }
903 910
904 911 /*
905 912 * PSARC 2003/523 Contract Private Interface
906 913 * svc_clts_kdupdone
907 914 * Changes must be reviewed by Solaris File Sharing
908 915 * Changes must be communicated to contract-2003-523@sun.com
909 916 *
910 917 * svc_clts_kdupdone marks the request done (DUP_DONE or DUP_DROP)
911 918 * and stores the response.
912 919 */
913 920 static void
914 921 svc_clts_kdupdone(struct dupreq *dr, caddr_t res, void (*dis_resfree)(),
915 922 int size, int status)
916 923 {
917 924
918 925 ASSERT(dr->dr_resfree == NULL);
919 926 if (status == DUP_DONE) {
920 927 bcopy(res, dr->dr_resp.buf, size);
921 928 dr->dr_resfree = dis_resfree;
922 929 }
923 930 dr->dr_status = status;
924 931 }
925 932
926 933 /*
927 934 * This routine expects that the mutex, dupreq_lock, is already held.
928 935 */
929 936 static void
930 937 unhash(struct dupreq *dr)
931 938 {
932 939 struct dupreq *drt;
933 940 struct dupreq *drtprev = NULL;
934 941 uint32_t drhash;
935 942
936 943 ASSERT(MUTEX_HELD(&dupreq_lock));
937 944
938 945 drhash = (uint32_t)DRHASH(dr);
939 946 drt = drhashtbl[drhash];
940 947 while (drt != NULL) {
941 948 if (drt == dr) {
942 949 drhashstat[drhash]--;
943 950 if (drtprev == NULL) {
944 951 drhashtbl[drhash] = drt->dr_chain;
945 952 } else {
946 953 drtprev->dr_chain = drt->dr_chain;
947 954 }
948 955 return;
949 956 }
950 957 drtprev = drt;
951 958 drt = drt->dr_chain;
952 959 }
953 960 }
954 961
955 962 void
956 963 svc_clts_stats_init(zoneid_t zoneid, struct rpc_clts_server **statsp)
957 964 {
958 965 kstat_t *ksp;
959 966 kstat_named_t *knp;
960 967
961 968 knp = rpcstat_zone_init_common(zoneid, "unix", "rpc_clts_server",
962 969 (const kstat_named_t *)&clts_rsstat_tmpl,
963 970 sizeof (clts_rsstat_tmpl));
964 971 /*
965 972 * Backwards compatibility for old kstat clients
966 973 */
967 974 ksp = kstat_create_zone("unix", 0, "rpc_server", "rpc",
968 975 KSTAT_TYPE_NAMED, clts_rsstat_ndata,
969 976 KSTAT_FLAG_VIRTUAL | KSTAT_FLAG_WRITABLE, zoneid);
970 977 if (ksp) {
971 978 ksp->ks_data = knp;
972 979 kstat_install(ksp);
973 980 }
974 981 *statsp = (struct rpc_clts_server *)knp;
975 982 }
976 983
977 984 void
978 985 svc_clts_stats_fini(zoneid_t zoneid, struct rpc_clts_server **statsp)
979 986 {
980 987 rpcstat_zone_fini_common(zoneid, "unix", "rpc_clts_server");
981 988 kstat_delete_byname_zone("unix", 0, "rpc_server", zoneid);
982 989 kmem_free(*statsp, sizeof (clts_rsstat_tmpl));
983 990 }
984 991
985 992 void
986 993 svc_clts_init()
987 994 {
988 995 /*
989 996 * Check to make sure that the clts private data will fit into
990 997 * the stack buffer allocated by svc_run. The compiler should
991 998 * remove this check, but it's a safety net if the udp_data
992 999 * structure ever changes.
993 1000 */
994 1001 /*CONSTANTCONDITION*/
995 1002 ASSERT(sizeof (struct udp_data) <= SVC_P2LEN);
996 1003
997 1004 mutex_init(&dupreq_lock, NULL, MUTEX_DEFAULT, NULL);
998 1005 }
↓ open down ↓ |
665 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX