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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Functions related to TPI.
24 */
25
26 #include <sys/types.h>
27 #include <sys/stream.h>
28 #include <sys/strsun.h>
29 #include <sys/strsubr.h>
30 #include <sys/stropts.h>
31 #include <sys/strlog.h>
32 #define _SUN_TPI_VERSION 2
33 #include <sys/tihdr.h>
34 #include <sys/suntpi.h>
35 #include <sys/xti_inet.h>
36 #include <sys/squeue_impl.h>
37 #include <sys/squeue.h>
38 #include <sys/tsol/tnet.h>
39
40 #include <inet/common.h>
41 #include <inet/ip.h>
42
43 #include <sys/cmn_err.h>
44
45 #include "dccp_impl.h"
46
47 /*
48 * Helper function to generate TPI errors acks.
49 */
50 void
51 dccp_err_ack(dccp_t *dccp, mblk_t *mp, int t_error, int sys_error)
52 {
53 if ((mp = mi_tpi_err_ack_alloc(mp, t_error, sys_error)) != NULL) {
54 putnext(dccp->dccp_connp->conn_rq, mp);
55 }
56 }
57
58 void
59 dccp_tpi_connect(dccp_t *dccp, mblk_t *mp)
60 {
61 struct T_conn_req *tcr;
62 conn_t *connp = dccp->dccp_connp;
63 sin_t *sin;
64 sin6_t *sin6;
65 cred_t *cr;
66 pid_t cpid;
67 int error;
68
69 cmn_err(CE_NOTE, "dccp_tpi.c: dccp_tpi_connect");
70
71 cr = msg_getcred(mp, &cpid);
72 ASSERT(cr != NULL);
73 if (cr == NULL) {
74 dccp_err_ack(dccp, mp, TSYSERR, EINVAL);
75 return;
76 }
77
78 tcr = (struct T_conn_req *)mp->b_rptr;
79
80 ASSERT((uintptr_t)(mp->b_wptr - mp->b_rptr) <= (uintptr_t)INT_MAX);
81 if ((mp->b_wptr - mp->b_rptr) < sizeof (*tcr)) {
82 dccp_err_ack(dccp, mp, TPROTO, 0);
83 return;
84 }
85
86 }
87
88 int
89 dccp_tpi_close(queue_t *q, int flags)
90 {
91 return (0);
92 }
93
94 /*
95 * Options related functions.
96 */
97 int
98 dccp_tpi_opt_get(queue_t *q, int level, int name, uchar_t *ptr)
99 {
100 return (tcp_opt_get(Q_TO_CONN(q), level, name, ptr));
101 }
102
103 /* ARGSUSED */
104 int
105 dccp_tpi_opt_set(queue_t *q, uint_t optset_context, int level, int name,
106 uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp,
107 void *thisdg_attrs, cred_t *cr)
108 {
109 conn_t *connp = Q_TO_CONN(q);
110
111 return (tcp_opt_set(connp, optset_context, level, name, inlen, invalp,
112 outlenp, outvalp, thisdg_attrs, cr));
113 }