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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
40 * Contains the following utility functions:
46 * See individual functions.
49 #include <sys/param.h>
50 #include <sys/types.h>
54 #include <sys/vnode.h>
55 #include <sys/errno.h>
56 #include <sys/stream.h>
57 #include <sys/ioctl.h>
58 #include <sys/stropts.h>
59 #include <sys/strsubr.h>
60 #include <sys/tihdr.h>
61 #include <sys/timod.h>
62 #include <sys/tiuser.h>
63 #include <sys/t_kuser.h>
64 #include <sys/strsun.h>
65 #include <inet/common.h>
67 #include <netinet/ip6.h>
70 extern int getiocseqno(void);
73 tli_send(TIUSER
*tiptr
, mblk_t
*bp
, int fmode
)
78 vp
= tiptr
->fp
->f_vnode
;
81 * Send data honoring flow control and errors
83 error
= kstrputmsg(vp
, bp
, NULL
, 0, 0, MSG_BAND
| MSG_HOLDSIG
, fmode
);
88 tli_recv(TIUSER
*tiptr
, mblk_t
**bp
, int fmode
)
97 vp
= tiptr
->fp
->f_vnode
;
98 if (fmode
& (FNDELAY
|FNONBLOCK
))
106 error
= kstrgetmsg(vp
, bp
, NULL
, &pri
, &pflag
, timout
, &rval
);
114 get_ok_ack(TIUSER
*tiptr
, int type
, int fmode
)
117 union T_primitives
*pptr
;
127 if ((error
= tli_recv(tiptr
, &bp
, fmode
)) != 0)
130 if ((msgsz
= (int)MBLKL(bp
)) < sizeof (int)) {
135 pptr
= (void *)bp
->b_rptr
;
136 switch (pptr
->type
) {
138 if (msgsz
< TOKACKSZ
|| pptr
->ok_ack
.CORRECT_prim
!= type
)
143 if (msgsz
< TERRORACKSZ
) {
148 if (pptr
->error_ack
.TLI_error
== TSYSERR
)
149 error
= pptr
->error_ack
.UNIX_error
;
151 error
= t_tlitosyserr(pptr
->error_ack
.TLI_error
);
163 * Translate a TLI error into a system error as best we can.
165 static const int tli_errs
[] = {
167 EADDRNOTAVAIL
, /* TBADADDR */
168 ENOPROTOOPT
, /* TBADOPT */
171 EADDRNOTAVAIL
, /* TNOADDR */
172 EPROTO
, /* TOUTSTATE */
173 EPROTO
, /* TBADSEQ */
174 0, /* TSYSERR - will never get */
175 EPROTO
, /* TLOOK - should never be sent by transport */
176 EMSGSIZE
, /* TBADDATA */
177 EMSGSIZE
, /* TBUFOVFLW */
179 EWOULDBLOCK
, /* TNODATA */
181 EPROTO
, /* TNOUDERR */
182 EINVAL
, /* TBADFLAG */
184 EOPNOTSUPP
, /* TNOTSUPPORT */
185 EPROTO
, /* TSTATECHNG */
189 t_tlitosyserr(int terr
)
191 if (terr
< 0 || (terr
>= (sizeof (tli_errs
) / sizeof (tli_errs
[0]))))
194 return (tli_errs
[terr
]);
198 * Notify transport that we are having trouble with this connection.
199 * If transport is TCP/IP, IP should delete the IRE and start over.
202 t_kadvise(TIUSER
*tiptr
, uchar_t
*addr
, int addr_len
)
213 mp
= mkiocb(IP_IOCTL
);
217 iocp
= (void *)mp
->b_rptr
;
218 iocp
->ioc_count
= sizeof (ipid_t
) + addr_len
;
220 mp
->b_cont
= allocb(iocp
->ioc_count
, BPRI_HI
);
226 ipid
= (void *)mp
->b_cont
->b_rptr
;
227 mp
->b_cont
->b_wptr
+= iocp
->ioc_count
;
229 bzero(ipid
, sizeof (*ipid
));
230 ipid
->ipid_cmd
= IP_IOC_IRE_DELETE_NO_REPLY
;
231 ipid
->ipid_ire_type
= 0;
232 ipid
->ipid_addr_offset
= sizeof (ipid_t
);
233 ipid
->ipid_addr_length
= addr_len
;
235 bcopy(addr
, &ipid
[1], addr_len
);
237 /* Ignore flow control, signals and errors */
238 (void) kstrputmsg(vp
, mp
, NULL
, 0, 0,
239 MSG_BAND
| MSG_IGNFLOW
| MSG_HOLDSIG
| MSG_IGNERROR
, 0);
246 * Kernel level debugging aid. The global variable "ktlilog" is a bit
247 * mask which allows various types of debugging messages to be printed
250 * ktlilog & 1 will cause actual failures to be printed.
251 * ktlilog & 2 will cause informational messages to be
255 ktli_log(int level
, char *str
, int a1
)