_conn_util.c (7c478bd9) | _conn_util.c (61961e0f) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 5 unchanged lines hidden (view full) --- 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 5 unchanged lines hidden (view full) --- 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ |
22 |
|
22/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23/* All Rights Reserved */ 24 | 23/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 24/* All Rights Reserved */ 25 |
25 | |
26/* | 26/* |
27 * Copyright 1993-2003 Sun Microsystems, Inc. All rights reserved. | 27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. |
28 * Use is subject to license terms. 29 */ 30 31#pragma ident "%Z%%M% %I% %E% SMI" 32 33#include "mt.h" 34#include <sys/param.h> 35#include <sys/types.h> | 28 * Use is subject to license terms. 29 */ 30 31#pragma ident "%Z%%M% %I% %E% SMI" 32 33#include "mt.h" 34#include <sys/param.h> 35#include <sys/types.h> |
36#include <rpc/trace.h> | |
37#include <errno.h> 38#include <string.h> 39#include <stdlib.h> 40#include <stropts.h> 41#include <sys/stream.h> 42#define _SUN_TPI_VERSION 2 43#include <sys/tihdr.h> 44#include <sys/timod.h> --- 11 unchanged lines hidden (view full) --- 56 */ 57int 58_t_snd_conn_req( 59 struct _ti_user *tiptr, 60 const struct t_call *call, 61 struct strbuf *ctlbufp) 62{ 63 struct T_conn_req *creq; | 36#include <errno.h> 37#include <string.h> 38#include <stdlib.h> 39#include <stropts.h> 40#include <sys/stream.h> 41#define _SUN_TPI_VERSION 2 42#include <sys/tihdr.h> 43#include <sys/timod.h> --- 11 unchanged lines hidden (view full) --- 55 */ 56int 57_t_snd_conn_req( 58 struct _ti_user *tiptr, 59 const struct t_call *call, 60 struct strbuf *ctlbufp) 61{ 62 struct T_conn_req *creq; |
64 int size, sv_errno; | 63 int size; |
65 int fd; 66 | 64 int fd; 65 |
67 trace2(TR__t_snd_conn_req, 0, fd); | |
68 assert(MUTEX_HELD(&tiptr->ti_lock)); 69 fd = tiptr->ti_fd; 70 71 if (tiptr->ti_servtype == T_CLTS) { 72 t_errno = TNOTSUPPORT; | 66 assert(MUTEX_HELD(&tiptr->ti_lock)); 67 fd = tiptr->ti_fd; 68 69 if (tiptr->ti_servtype == T_CLTS) { 70 t_errno = TNOTSUPPORT; |
73 trace2(TR__t_snd_conn_req, 1, fd); | |
74 return (-1); 75 } 76 | 71 return (-1); 72 } 73 |
77 if (_t_is_event(fd, tiptr) < 0) { 78 sv_errno = errno; 79 trace2(TR__t_snd_conn_req, 1, fd); 80 errno = sv_errno; | 74 if (_t_is_event(fd, tiptr) < 0) |
81 return (-1); | 75 return (-1); |
82 } | |
83 | 76 |
77 /* LINTED pointer cast */ |
|
84 creq = (struct T_conn_req *)ctlbufp->buf; 85 creq->PRIM_type = T_CONN_REQ; 86 creq->DEST_length = call->addr.len; 87 creq->DEST_offset = 0; 88 creq->OPT_length = call->opt.len; 89 creq->OPT_offset = 0; 90 size = (int)sizeof (struct T_conn_req); /* size without any buffers */ 91 92 if (call->addr.len) { 93 if (_t_aligned_copy(ctlbufp, call->addr.len, size, 94 call->addr.buf, &creq->DEST_offset) < 0) { 95 /* 96 * Aligned copy will overflow buffer allocated based 97 * based on transport maximum address size. 98 * return error. 99 */ 100 t_errno = TBADADDR; | 78 creq = (struct T_conn_req *)ctlbufp->buf; 79 creq->PRIM_type = T_CONN_REQ; 80 creq->DEST_length = call->addr.len; 81 creq->DEST_offset = 0; 82 creq->OPT_length = call->opt.len; 83 creq->OPT_offset = 0; 84 size = (int)sizeof (struct T_conn_req); /* size without any buffers */ 85 86 if (call->addr.len) { 87 if (_t_aligned_copy(ctlbufp, call->addr.len, size, 88 call->addr.buf, &creq->DEST_offset) < 0) { 89 /* 90 * Aligned copy will overflow buffer allocated based 91 * based on transport maximum address size. 92 * return error. 93 */ 94 t_errno = TBADADDR; |
101 trace2(TR__t_snd_conn_req, 1, fd); | |
102 return (-1); 103 } 104 size = creq->DEST_offset + creq->DEST_length; 105 } 106 if (call->opt.len) { 107 if (_t_aligned_copy(ctlbufp, call->opt.len, size, 108 call->opt.buf, &creq->OPT_offset) < 0) { 109 /* 110 * Aligned copy will overflow buffer allocated based 111 * on maximum option size in transport. 112 * return error. 113 */ 114 t_errno = TBADOPT; | 95 return (-1); 96 } 97 size = creq->DEST_offset + creq->DEST_length; 98 } 99 if (call->opt.len) { 100 if (_t_aligned_copy(ctlbufp, call->opt.len, size, 101 call->opt.buf, &creq->OPT_offset) < 0) { 102 /* 103 * Aligned copy will overflow buffer allocated based 104 * on maximum option size in transport. 105 * return error. 106 */ 107 t_errno = TBADOPT; |
115 trace2(TR__t_snd_conn_req, 1, fd); | |
116 return (-1); 117 } 118 size = creq->OPT_offset + creq->OPT_length; 119 } 120 if (call->udata.len) { 121 if ((tiptr->ti_cdatasize == T_INVALID /* -2 */) || 122 ((tiptr->ti_cdatasize != T_INFINITE /* -1 */) && 123 (call->udata.len > (uint32_t)tiptr->ti_cdatasize))) { 124 /* 125 * user data not valid with connect or it 126 * exceeds the limits specified by the transport 127 * provider. 128 */ 129 t_errno = TBADDATA; | 108 return (-1); 109 } 110 size = creq->OPT_offset + creq->OPT_length; 111 } 112 if (call->udata.len) { 113 if ((tiptr->ti_cdatasize == T_INVALID /* -2 */) || 114 ((tiptr->ti_cdatasize != T_INFINITE /* -1 */) && 115 (call->udata.len > (uint32_t)tiptr->ti_cdatasize))) { 116 /* 117 * user data not valid with connect or it 118 * exceeds the limits specified by the transport 119 * provider. 120 */ 121 t_errno = TBADDATA; |
130 trace2(TR__t_snd_conn_req, 1, fd); | |
131 return (-1); 132 } 133 } 134 135 ctlbufp->len = size; 136 137 /* 138 * Assumes signals are blocked so putmsg() will not block 139 * indefinitely 140 */ 141 if (putmsg(fd, ctlbufp, 142 (struct strbuf *)(call->udata.len? &call->udata: NULL), 0) < 0) { | 122 return (-1); 123 } 124 } 125 126 ctlbufp->len = size; 127 128 /* 129 * Assumes signals are blocked so putmsg() will not block 130 * indefinitely 131 */ 132 if (putmsg(fd, ctlbufp, 133 (struct strbuf *)(call->udata.len? &call->udata: NULL), 0) < 0) { |
143 sv_errno = errno; | |
144 t_errno = TSYSERR; | 134 t_errno = TSYSERR; |
145 trace2(TR__t_snd_conn_req, 1, fd); 146 errno = sv_errno; | |
147 return (-1); 148 } 149 | 135 return (-1); 136 } 137 |
150 if (_t_is_ok(fd, tiptr, T_CONN_REQ) < 0) { 151 sv_errno = errno; 152 trace2(TR__t_snd_conn_req, 1, fd); 153 errno = sv_errno; | 138 if (_t_is_ok(fd, tiptr, T_CONN_REQ) < 0) |
154 return (-1); | 139 return (-1); |
155 } 156 trace2(TR__t_snd_conn_req, 1, fd); | |
157 return (0); 158} 159 160 161 162/* 163 * Rcv_conn_con - get connection confirmation off 164 * of read queue --- 9 unchanged lines hidden (view full) --- 174{ 175 struct strbuf databuf; 176 union T_primitives *pptr; 177 int retval, fd, sv_errno; 178 int didralloc; 179 180 int flg = 0; 181 | 140 return (0); 141} 142 143 144 145/* 146 * Rcv_conn_con - get connection confirmation off 147 * of read queue --- 9 unchanged lines hidden (view full) --- 157{ 158 struct strbuf databuf; 159 union T_primitives *pptr; 160 int retval, fd, sv_errno; 161 int didralloc; 162 163 int flg = 0; 164 |
182 trace2(TR__t_rcv_conn_con, 0, fd); 183 | |
184 fd = tiptr->ti_fd; 185 186 if (tiptr->ti_servtype == T_CLTS) { 187 t_errno = TNOTSUPPORT; | 165 fd = tiptr->ti_fd; 166 167 if (tiptr->ti_servtype == T_CLTS) { 168 t_errno = TNOTSUPPORT; |
188 trace2(TR__t_rcv_conn_con, 1, fd); | |
189 return (-1); 190 } 191 192 /* 193 * see if there is something in look buffer 194 */ 195 if (tiptr->ti_lookcnt > 0) { 196 t_errno = TLOOK; | 169 return (-1); 170 } 171 172 /* 173 * see if there is something in look buffer 174 */ 175 if (tiptr->ti_lookcnt > 0) { 176 t_errno = TLOOK; |
197 trace2(TR__t_rcv_conn_con, 1, fd); | |
198 return (-1); 199 } 200 201 ctlbufp->len = 0; 202 /* 203 * Acquire databuf for use in sending/receiving data part 204 */ | 177 return (-1); 178 } 179 180 ctlbufp->len = 0; 181 /* 182 * Acquire databuf for use in sending/receiving data part 183 */ |
205 if (_t_acquire_databuf(tiptr, &databuf, &didralloc) < 0) { 206 sv_errno = errno; 207 trace2(TR__t_rcv_conn_con, 1, fd); 208 errno = sv_errno; | 184 if (_t_acquire_databuf(tiptr, &databuf, &didralloc) < 0) |
209 return (-1); | 185 return (-1); |
210 } | |
211 212 /* 213 * This is a call that may block indefinitely so we drop the 214 * lock and allow signals in MT case here and reacquire it. 215 * Error case should roll back state changes done above 216 * (happens to be no state change here) 217 */ 218 sig_mutex_unlock(&tiptr->ti_lock); --- 24 unchanged lines hidden (view full) --- 243 * is cntl part large enough to determine message type? 244 */ 245 if (ctlbufp->len < (int)sizeof (t_scalar_t)) { 246 t_errno = TSYSERR; 247 errno = EPROTO; 248 goto err_out; 249 } 250 | 186 187 /* 188 * This is a call that may block indefinitely so we drop the 189 * lock and allow signals in MT case here and reacquire it. 190 * Error case should roll back state changes done above 191 * (happens to be no state change here) 192 */ 193 sig_mutex_unlock(&tiptr->ti_lock); --- 24 unchanged lines hidden (view full) --- 218 * is cntl part large enough to determine message type? 219 */ 220 if (ctlbufp->len < (int)sizeof (t_scalar_t)) { 221 t_errno = TSYSERR; 222 errno = EPROTO; 223 goto err_out; 224 } 225 |
226 /* LINTED pointer cast */ |
|
251 pptr = (union T_primitives *)ctlbufp->buf; 252 253 switch (pptr->type) { 254 255 case T_CONN_CON: 256 257 if ((ctlbufp->len < (int)sizeof (struct T_conn_con)) || 258 (pptr->conn_con.OPT_length != 0 && --- 46 unchanged lines hidden (view full) --- 305 * is -1 by default 306 */ 307 call->sequence = (int)-1; 308 } 309 if (didralloc) 310 free(databuf.buf); 311 else 312 tiptr->ti_rcvbuf = databuf.buf; | 227 pptr = (union T_primitives *)ctlbufp->buf; 228 229 switch (pptr->type) { 230 231 case T_CONN_CON: 232 233 if ((ctlbufp->len < (int)sizeof (struct T_conn_con)) || 234 (pptr->conn_con.OPT_length != 0 && --- 46 unchanged lines hidden (view full) --- 281 * is -1 by default 282 */ 283 call->sequence = (int)-1; 284 } 285 if (didralloc) 286 free(databuf.buf); 287 else 288 tiptr->ti_rcvbuf = databuf.buf; |
313 trace2(TR__t_rcv_conn_con, 1, fd); | |
314 return (0); 315 316 case T_DISCON_IND: 317 318 /* 319 * if disconnect indication then append it to 320 * the "look bufffer" list. 321 * This may result in MT case for the process --- 10 unchanged lines hidden (view full) --- 332 t_errno = TLOOK; 333 goto err_out; 334 335 default: 336 break; 337 } 338 339 t_errno = TSYSERR; | 289 return (0); 290 291 case T_DISCON_IND: 292 293 /* 294 * if disconnect indication then append it to 295 * the "look bufffer" list. 296 * This may result in MT case for the process --- 10 unchanged lines hidden (view full) --- 307 t_errno = TLOOK; 308 goto err_out; 309 310 default: 311 break; 312 } 313 314 t_errno = TSYSERR; |
340 trace2(TR__t_rcv_conn_con, 1, fd); | |
341 errno = EPROTO; 342err_out: | 315 errno = EPROTO; 316err_out: |
343 sv_errno = errno; | |
344 if (didralloc) 345 free(databuf.buf); 346 else 347 tiptr->ti_rcvbuf = databuf.buf; | 317 if (didralloc) 318 free(databuf.buf); 319 else 320 tiptr->ti_rcvbuf = databuf.buf; |
348 trace2(TR__t_rcv_conn_con, 1, fd); 349 errno = sv_errno; | |
350 return (-1); 351} | 321 return (-1); 322} |