10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51521Syz147064 * Common Development and Distribution License (the "License").
61521Syz147064 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
220Sstevel@tonic-gate /*
23*11861SMarek.Pospisil@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * Transport Interface Library cooperating module - issue 2
320Sstevel@tonic-gate */
330Sstevel@tonic-gate
340Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
350Sstevel@tonic-gate #include <sys/param.h>
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/stream.h>
380Sstevel@tonic-gate #include <sys/stropts.h>
390Sstevel@tonic-gate #include <sys/strsubr.h>
400Sstevel@tonic-gate #define _SUN_TPI_VERSION 2
410Sstevel@tonic-gate #include <sys/tihdr.h>
420Sstevel@tonic-gate #include <sys/timod.h>
430Sstevel@tonic-gate #include <sys/suntpi.h>
440Sstevel@tonic-gate #include <sys/debug.h>
450Sstevel@tonic-gate #include <sys/strlog.h>
460Sstevel@tonic-gate #include <sys/errno.h>
470Sstevel@tonic-gate #include <sys/cred.h>
480Sstevel@tonic-gate #include <sys/cmn_err.h>
490Sstevel@tonic-gate #include <sys/kmem.h>
500Sstevel@tonic-gate #include <sys/sysmacros.h>
510Sstevel@tonic-gate #include <sys/ddi.h>
520Sstevel@tonic-gate #include <sys/sunddi.h>
530Sstevel@tonic-gate #include <sys/strsun.h>
540Sstevel@tonic-gate #include <c2/audit.h>
550Sstevel@tonic-gate
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate * This is the loadable module wrapper.
580Sstevel@tonic-gate */
590Sstevel@tonic-gate #include <sys/conf.h>
600Sstevel@tonic-gate #include <sys/modctl.h>
610Sstevel@tonic-gate
620Sstevel@tonic-gate static struct streamtab timinfo;
630Sstevel@tonic-gate
640Sstevel@tonic-gate static struct fmodsw fsw = {
650Sstevel@tonic-gate "timod",
660Sstevel@tonic-gate &timinfo,
670Sstevel@tonic-gate D_MTQPAIR | D_MP,
680Sstevel@tonic-gate };
690Sstevel@tonic-gate
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate * Module linkage information for the kernel.
720Sstevel@tonic-gate */
730Sstevel@tonic-gate
740Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
750Sstevel@tonic-gate &mod_strmodops, "transport interface str mod", &fsw
760Sstevel@tonic-gate };
770Sstevel@tonic-gate
780Sstevel@tonic-gate static struct modlinkage modlinkage = {
790Sstevel@tonic-gate MODREV_1, &modlstrmod, NULL
800Sstevel@tonic-gate };
810Sstevel@tonic-gate
820Sstevel@tonic-gate static krwlock_t tim_list_rwlock;
830Sstevel@tonic-gate
840Sstevel@tonic-gate /*
850Sstevel@tonic-gate * This module keeps track of capabilities of underlying transport. Information
860Sstevel@tonic-gate * is persistent through module invocations (open/close). Currently it remembers
870Sstevel@tonic-gate * whether underlying transport supports TI_GET{MY,PEER}NAME ioctls and
880Sstevel@tonic-gate * T_CAPABILITY_REQ message. This module either passes ioctl/messages to the
890Sstevel@tonic-gate * transport or emulates it when transport doesn't understand these
900Sstevel@tonic-gate * ioctl/messages.
910Sstevel@tonic-gate *
920Sstevel@tonic-gate * It is assumed that transport supports T_CAPABILITY_REQ when timod receives
930Sstevel@tonic-gate * T_CAPABILITY_ACK from the transport. There is no current standard describing
940Sstevel@tonic-gate * transport behaviour when it receives unknown message type, so following
950Sstevel@tonic-gate * reactions are expected and handled:
960Sstevel@tonic-gate *
970Sstevel@tonic-gate * 1) Transport drops unknown T_CAPABILITY_REQ message type. In this case timod
980Sstevel@tonic-gate * will wait for tcap_wait time and assume that transport doesn't provide
990Sstevel@tonic-gate * this message type. T_CAPABILITY_REQ should never travel over the wire, so
1000Sstevel@tonic-gate * timeout value should only take into consideration internal processing time
1010Sstevel@tonic-gate * for the message. From user standpoint it may mean that an application will
1020Sstevel@tonic-gate * hang for TCAP_WAIT time in the kernel the first time this message is used
1030Sstevel@tonic-gate * with some particular transport (e.g. TCP/IP) during system uptime.
1040Sstevel@tonic-gate *
1050Sstevel@tonic-gate * 2) Transport responds with T_ERROR_ACK specifying T_CAPABILITY_REQ as
1060Sstevel@tonic-gate * original message type. In this case it is assumed that transport doesn't
1070Sstevel@tonic-gate * support it (which may not always be true - some transports return
1080Sstevel@tonic-gate * T_ERROR_ACK in other cases like lack of system memory).
1090Sstevel@tonic-gate *
1100Sstevel@tonic-gate * 3) Transport responds with M_ERROR, effectively shutting down the
1110Sstevel@tonic-gate * stream. Unfortunately there is no standard way to pass the reason of
1120Sstevel@tonic-gate * M_ERROR message back to the caller, so it is assumed that if M_ERROR was
1130Sstevel@tonic-gate * sent in response to T_CAPABILITY_REQ message, transport doesn't support
1140Sstevel@tonic-gate * it.
1150Sstevel@tonic-gate *
1160Sstevel@tonic-gate * It is possible under certain circumstances that timod will incorrectly assume
1170Sstevel@tonic-gate * that underlying transport doesn't provide T_CAPABILITY_REQ message type. In
1180Sstevel@tonic-gate * this "worst-case" scenario timod will emulate its functionality by itself and
1190Sstevel@tonic-gate * will provide only TC1_INFO capability. All other bits in CAP_bits1 field are
1200Sstevel@tonic-gate * cleaned. TC1_INFO is emulated by sending T_INFO_REQ down to transport
1210Sstevel@tonic-gate * provider.
1220Sstevel@tonic-gate */
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate /*
1250Sstevel@tonic-gate * Notes about locking:
1260Sstevel@tonic-gate *
1270Sstevel@tonic-gate * tim_list_rwlock protects the list of tim_tim structures itself. When this
1280Sstevel@tonic-gate * lock is held, the list itself is stable, but the contents of the entries
1290Sstevel@tonic-gate * themselves might not be.
1300Sstevel@tonic-gate *
1310Sstevel@tonic-gate * The rest of the members are generally protected by D_MTQPAIR, which
1320Sstevel@tonic-gate * specifies a default exclusive inner perimeter. If you're looking at
1330Sstevel@tonic-gate * q->q_ptr, then it's stable.
1340Sstevel@tonic-gate *
1350Sstevel@tonic-gate * There's one exception to this rule: tim_peer{maxlen,len,name}. These members
1360Sstevel@tonic-gate * are touched without entering the associated STREAMS perimeter because we
1370Sstevel@tonic-gate * get the pointer via tim_findlink() rather than q_ptr. These are protected
1380Sstevel@tonic-gate * by tim_mutex instead. If you don't hold that lock, don't look at them.
1390Sstevel@tonic-gate *
1400Sstevel@tonic-gate * (It would be possible to separate out the 'set by T_CONN_RES' cases from the
1410Sstevel@tonic-gate * others, but there appears to be no reason to do so.)
1420Sstevel@tonic-gate */
1430Sstevel@tonic-gate struct tim_tim {
1440Sstevel@tonic-gate uint32_t tim_flags;
1450Sstevel@tonic-gate t_uscalar_t tim_backlog;
1460Sstevel@tonic-gate mblk_t *tim_iocsave;
1470Sstevel@tonic-gate t_scalar_t tim_mymaxlen;
1480Sstevel@tonic-gate t_scalar_t tim_mylen;
1490Sstevel@tonic-gate caddr_t tim_myname;
1500Sstevel@tonic-gate t_scalar_t tim_peermaxlen;
1510Sstevel@tonic-gate t_scalar_t tim_peerlen;
1520Sstevel@tonic-gate caddr_t tim_peername;
1530Sstevel@tonic-gate cred_t *tim_peercred;
1540Sstevel@tonic-gate mblk_t *tim_consave;
1550Sstevel@tonic-gate bufcall_id_t tim_wbufcid;
1560Sstevel@tonic-gate bufcall_id_t tim_rbufcid;
1570Sstevel@tonic-gate timeout_id_t tim_wtimoutid;
1580Sstevel@tonic-gate timeout_id_t tim_rtimoutid;
1590Sstevel@tonic-gate /* Protected by the global tim_list_rwlock for all instances */
1600Sstevel@tonic-gate struct tim_tim *tim_next;
1610Sstevel@tonic-gate struct tim_tim **tim_ptpn;
1620Sstevel@tonic-gate t_uscalar_t tim_acceptor;
1630Sstevel@tonic-gate t_scalar_t tim_saved_prim; /* Primitive from message */
1640Sstevel@tonic-gate /* part of ioctl. */
1650Sstevel@tonic-gate timeout_id_t tim_tcap_timoutid; /* For T_CAP_REQ timeout */
1660Sstevel@tonic-gate tpi_provinfo_t *tim_provinfo; /* Transport description */
1670Sstevel@tonic-gate kmutex_t tim_mutex; /* protect tim_peer* */
1680Sstevel@tonic-gate pid_t tim_cpid;
1690Sstevel@tonic-gate };
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate * Local flags used with tim_flags field in instance structure of
1740Sstevel@tonic-gate * type 'struct _ti_user' declared above.
1750Sstevel@tonic-gate * Historical note:
1760Sstevel@tonic-gate * This namespace constants were previously declared in a
1770Sstevel@tonic-gate * a very messed up namespace in timod.h
1780Sstevel@tonic-gate *
1790Sstevel@tonic-gate * There may be 3 states for transport:
1800Sstevel@tonic-gate *
1810Sstevel@tonic-gate * 1) It provides T_CAPABILITY_REQ
1820Sstevel@tonic-gate * 2) It does not provide T_CAPABILITY_REQ
1830Sstevel@tonic-gate * 3) It is not known yet whether transport provides T_CAPABILITY_REQ or not.
1840Sstevel@tonic-gate *
1850Sstevel@tonic-gate * It is assumed that the underlying transport either provides
1860Sstevel@tonic-gate * T_CAPABILITY_REQ or not and this does not changes during the
1870Sstevel@tonic-gate * system lifetime.
1880Sstevel@tonic-gate *
1890Sstevel@tonic-gate */
1900Sstevel@tonic-gate #define PEEK_RDQ_EXPIND 0x0001 /* look for expinds on stream rd queues */
1910Sstevel@tonic-gate #define WAITIOCACK 0x0002 /* waiting for info for ioctl act */
1920Sstevel@tonic-gate #define CLTS 0x0004 /* connectionless transport */
1930Sstevel@tonic-gate #define COTS 0x0008 /* connection-oriented transport */
1940Sstevel@tonic-gate #define CONNWAIT 0x0010 /* waiting for connect confirmation */
1950Sstevel@tonic-gate #define LOCORDREL 0x0020 /* local end has orderly released */
1960Sstevel@tonic-gate #define REMORDREL 0x0040 /* remote end had orderly released */
1970Sstevel@tonic-gate #define NAMEPROC 0x0080 /* processing a NAME ioctl */
1980Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
1990Sstevel@tonic-gate #define DO_MYNAME 0x0100 /* timod handles TI_GETMYNAME */
2000Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
2010Sstevel@tonic-gate #define DO_PEERNAME 0x0200 /* timod handles TI_GETPEERNAME */
2020Sstevel@tonic-gate #define TI_CAP_RECVD 0x0400 /* TI_CAPABILITY received */
2030Sstevel@tonic-gate #define CAP_WANTS_INFO 0x0800 /* TI_CAPABILITY has TC1_INFO set */
2040Sstevel@tonic-gate #define WAIT_IOCINFOACK 0x1000 /* T_INFO_REQ generated from ioctl */
2050Sstevel@tonic-gate #define WAIT_CONNRESACK 0x2000 /* waiting for T_OK_ACK to T_CONN_RES */
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate /* Debugging facilities */
2090Sstevel@tonic-gate /*
2100Sstevel@tonic-gate * Logging needed for debugging timod should only appear in DEBUG kernel.
2110Sstevel@tonic-gate */
2120Sstevel@tonic-gate #ifdef DEBUG
2130Sstevel@tonic-gate #define TILOG(msg, arg) tilog((msg), (arg))
2140Sstevel@tonic-gate #define TILOGP(msg, arg) tilogp((msg), (arg))
2150Sstevel@tonic-gate #else
2160Sstevel@tonic-gate #define TILOG(msg, arg)
2170Sstevel@tonic-gate #define TILOGP(msg, arg)
2180Sstevel@tonic-gate #endif
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate /*
2220Sstevel@tonic-gate * Sleep timeout for T_CAPABILITY_REQ. This message never travels across
2230Sstevel@tonic-gate * network, so timeout value should be enough to cover all internal processing
2240Sstevel@tonic-gate * time.
2250Sstevel@tonic-gate */
2260Sstevel@tonic-gate clock_t tim_tcap_wait = 2;
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate /* Sleep timeout in tim_recover() */
2290Sstevel@tonic-gate #define TIMWAIT (1*hz)
2301261Sgeorges /* Sleep timeout in tim_ioctl_retry() 0.2 seconds */
2311261Sgeorges #define TIMIOCWAIT (200*hz/1000)
2320Sstevel@tonic-gate
2330Sstevel@tonic-gate /*
2340Sstevel@tonic-gate * Return values for ti_doname().
2350Sstevel@tonic-gate */
2360Sstevel@tonic-gate #define DONAME_FAIL 0 /* failing ioctl (done) */
2370Sstevel@tonic-gate #define DONAME_DONE 1 /* done processing */
2380Sstevel@tonic-gate #define DONAME_CONT 2 /* continue proceesing (not done yet) */
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate /*
2410Sstevel@tonic-gate * Function prototypes
2420Sstevel@tonic-gate */
2430Sstevel@tonic-gate static int ti_doname(queue_t *, mblk_t *);
2440Sstevel@tonic-gate static int ti_expind_on_rdqueues(queue_t *);
2450Sstevel@tonic-gate static void tim_ioctl_send_reply(queue_t *, mblk_t *, mblk_t *);
2460Sstevel@tonic-gate static void tim_send_ioc_error_ack(queue_t *, struct tim_tim *, mblk_t *);
2470Sstevel@tonic-gate static void tim_tcap_timer(void *);
2480Sstevel@tonic-gate static void tim_tcap_genreply(queue_t *, struct tim_tim *);
2490Sstevel@tonic-gate static void tim_send_reply(queue_t *, mblk_t *, struct tim_tim *, t_scalar_t);
2500Sstevel@tonic-gate static void tim_answer_ti_sync(queue_t *, mblk_t *, struct tim_tim *,
2510Sstevel@tonic-gate mblk_t *, uint32_t);
2520Sstevel@tonic-gate static void tim_send_ioctl_tpi_msg(queue_t *, mblk_t *, struct tim_tim *,
2530Sstevel@tonic-gate struct iocblk *);
2540Sstevel@tonic-gate static void tim_clear_peer(struct tim_tim *);
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate int
_init(void)2570Sstevel@tonic-gate _init(void)
2580Sstevel@tonic-gate {
2590Sstevel@tonic-gate int error;
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate rw_init(&tim_list_rwlock, NULL, RW_DRIVER, NULL);
2620Sstevel@tonic-gate error = mod_install(&modlinkage);
2630Sstevel@tonic-gate if (error != 0) {
2640Sstevel@tonic-gate rw_destroy(&tim_list_rwlock);
2650Sstevel@tonic-gate return (error);
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate return (0);
2690Sstevel@tonic-gate }
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate int
_fini(void)2720Sstevel@tonic-gate _fini(void)
2730Sstevel@tonic-gate {
2740Sstevel@tonic-gate int error;
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate error = mod_remove(&modlinkage);
2770Sstevel@tonic-gate if (error != 0)
2780Sstevel@tonic-gate return (error);
2790Sstevel@tonic-gate rw_destroy(&tim_list_rwlock);
2800Sstevel@tonic-gate return (0);
2810Sstevel@tonic-gate }
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2840Sstevel@tonic-gate _info(struct modinfo *modinfop)
2850Sstevel@tonic-gate {
2860Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate * Hash list for all instances. Used to find tim_tim structure based on
2920Sstevel@tonic-gate * ACCEPTOR_id in T_CONN_RES. Protected by tim_list_rwlock.
2930Sstevel@tonic-gate */
2940Sstevel@tonic-gate #define TIM_HASH_SIZE 256
2950Sstevel@tonic-gate #ifdef _ILP32
2960Sstevel@tonic-gate #define TIM_HASH(id) (((uintptr_t)(id) >> 8) % TIM_HASH_SIZE)
2970Sstevel@tonic-gate #else
2980Sstevel@tonic-gate #define TIM_HASH(id) ((uintptr_t)(id) % TIM_HASH_SIZE)
2990Sstevel@tonic-gate #endif /* _ILP32 */
3000Sstevel@tonic-gate static struct tim_tim *tim_hash[TIM_HASH_SIZE];
3010Sstevel@tonic-gate int tim_cnt = 0;
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate static void tilog(char *, t_scalar_t);
3040Sstevel@tonic-gate static void tilogp(char *, uintptr_t);
3050Sstevel@tonic-gate static mblk_t *tim_filladdr(queue_t *, mblk_t *, boolean_t);
3060Sstevel@tonic-gate static void tim_addlink(struct tim_tim *);
3070Sstevel@tonic-gate static void tim_dellink(struct tim_tim *);
3080Sstevel@tonic-gate static struct tim_tim *tim_findlink(t_uscalar_t);
3090Sstevel@tonic-gate static void tim_recover(queue_t *, mblk_t *, t_scalar_t);
3101261Sgeorges static void tim_ioctl_retry(queue_t *);
3110Sstevel@tonic-gate
3120Sstevel@tonic-gate int dotilog = 0;
3130Sstevel@tonic-gate
3140Sstevel@tonic-gate #define TIMOD_ID 3
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
3170Sstevel@tonic-gate static int timodopen(queue_t *, dev_t *, int, int, cred_t *);
3180Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
3190Sstevel@tonic-gate static int timodclose(queue_t *, int, cred_t *);
3200Sstevel@tonic-gate static void timodwput(queue_t *, mblk_t *);
3210Sstevel@tonic-gate static void timodrput(queue_t *, mblk_t *);
3220Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
3230Sstevel@tonic-gate static void timodrsrv(queue_t *);
3240Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
3250Sstevel@tonic-gate static void timodwsrv(queue_t *);
3260Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
3270Sstevel@tonic-gate static int timodrproc(queue_t *, mblk_t *);
3280Sstevel@tonic-gate static int timodwproc(queue_t *, mblk_t *);
3290Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate /* stream data structure definitions */
3320Sstevel@tonic-gate
3330Sstevel@tonic-gate static struct module_info timod_info =
3340Sstevel@tonic-gate {TIMOD_ID, "timod", 0, INFPSZ, 512, 128};
3350Sstevel@tonic-gate static struct qinit timodrinit = {
3360Sstevel@tonic-gate (int (*)())timodrput,
3370Sstevel@tonic-gate (int (*)())timodrsrv,
3380Sstevel@tonic-gate timodopen,
3390Sstevel@tonic-gate timodclose,
3400Sstevel@tonic-gate nulldev,
3410Sstevel@tonic-gate &timod_info,
3420Sstevel@tonic-gate NULL
3430Sstevel@tonic-gate };
3440Sstevel@tonic-gate static struct qinit timodwinit = {
3450Sstevel@tonic-gate (int (*)())timodwput,
3460Sstevel@tonic-gate (int (*)())timodwsrv,
3470Sstevel@tonic-gate timodopen,
3480Sstevel@tonic-gate timodclose,
3490Sstevel@tonic-gate nulldev,
3500Sstevel@tonic-gate &timod_info,
3510Sstevel@tonic-gate NULL
3520Sstevel@tonic-gate };
3530Sstevel@tonic-gate static struct streamtab timinfo = { &timodrinit, &timodwinit, NULL, NULL };
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
3560Sstevel@tonic-gate /*
3570Sstevel@tonic-gate * timodopen - open routine gets called when the module gets pushed
3580Sstevel@tonic-gate * onto the stream.
3590Sstevel@tonic-gate */
3600Sstevel@tonic-gate /*ARGSUSED*/
3610Sstevel@tonic-gate static int
timodopen(queue_t * q,dev_t * devp,int flag,int sflag,cred_t * crp)3620Sstevel@tonic-gate timodopen(
3630Sstevel@tonic-gate queue_t *q,
3640Sstevel@tonic-gate dev_t *devp,
3650Sstevel@tonic-gate int flag,
3660Sstevel@tonic-gate int sflag,
3670Sstevel@tonic-gate cred_t *crp)
3680Sstevel@tonic-gate {
3690Sstevel@tonic-gate struct tim_tim *tp;
3700Sstevel@tonic-gate struct stroptions *sop;
3710Sstevel@tonic-gate mblk_t *bp;
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate ASSERT(q != NULL);
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate if (q->q_ptr) {
3760Sstevel@tonic-gate return (0);
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate if ((bp = allocb(sizeof (struct stroptions), BPRI_MED)) == 0)
3800Sstevel@tonic-gate return (ENOMEM);
3810Sstevel@tonic-gate
3820Sstevel@tonic-gate tp = kmem_zalloc(sizeof (struct tim_tim), KM_SLEEP);
3830Sstevel@tonic-gate
3840Sstevel@tonic-gate tp->tim_cpid = -1;
3850Sstevel@tonic-gate tp->tim_saved_prim = -1;
3860Sstevel@tonic-gate
3870Sstevel@tonic-gate mutex_init(&tp->tim_mutex, NULL, MUTEX_DEFAULT, NULL);
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate q->q_ptr = (caddr_t)tp;
3900Sstevel@tonic-gate WR(q)->q_ptr = (caddr_t)tp;
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate tilogp("timodopen: Allocated for tp %lx\n", (uintptr_t)tp);
3930Sstevel@tonic-gate tilogp("timodopen: Allocated for q %lx\n", (uintptr_t)q);
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate /* Must be done before tpi_findprov and _ILP32 q_next walk below */
3960Sstevel@tonic-gate qprocson(q);
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate tp->tim_provinfo = tpi_findprov(q);
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate /*
4010Sstevel@tonic-gate * Defer allocation of the buffers for the local address and
4020Sstevel@tonic-gate * the peer's address until we need them.
4030Sstevel@tonic-gate * Assume that timod has to handle getname until we here
4040Sstevel@tonic-gate * an iocack from the transport provider or we know that
4050Sstevel@tonic-gate * transport provider doesn't understand it.
4060Sstevel@tonic-gate */
4070Sstevel@tonic-gate if (tp->tim_provinfo->tpi_myname != PI_YES) {
4080Sstevel@tonic-gate TILOG("timodopen: setting DO_MYNAME\n", 0);
4090Sstevel@tonic-gate tp->tim_flags |= DO_MYNAME;
4100Sstevel@tonic-gate }
4110Sstevel@tonic-gate
4120Sstevel@tonic-gate if (tp->tim_provinfo->tpi_peername != PI_YES) {
4130Sstevel@tonic-gate TILOG("timodopen: setting DO_PEERNAME\n", 0);
4140Sstevel@tonic-gate tp->tim_flags |= DO_PEERNAME;
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate #ifdef _ILP32
4180Sstevel@tonic-gate {
4190Sstevel@tonic-gate queue_t *driverq;
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate /*
4220Sstevel@tonic-gate * Find my driver's read queue (for T_CONN_RES handling)
4230Sstevel@tonic-gate */
4240Sstevel@tonic-gate driverq = WR(q);
4250Sstevel@tonic-gate while (SAMESTR(driverq))
4260Sstevel@tonic-gate driverq = driverq->q_next;
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate tp->tim_acceptor = (t_uscalar_t)RD(driverq);
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate #else
4310Sstevel@tonic-gate tp->tim_acceptor = (t_uscalar_t)getminor(*devp);
4320Sstevel@tonic-gate #endif /* _ILP32 */
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate /*
4350Sstevel@tonic-gate * Add this one to the list.
4360Sstevel@tonic-gate */
4370Sstevel@tonic-gate tim_addlink(tp);
4380Sstevel@tonic-gate
4390Sstevel@tonic-gate /*
4400Sstevel@tonic-gate * Send M_SETOPTS to stream head to make sure M_PCPROTO messages
4410Sstevel@tonic-gate * are not flushed. This prevents application deadlocks.
4420Sstevel@tonic-gate */
4430Sstevel@tonic-gate bp->b_datap->db_type = M_SETOPTS;
4440Sstevel@tonic-gate bp->b_wptr += sizeof (struct stroptions);
4450Sstevel@tonic-gate sop = (struct stroptions *)bp->b_rptr;
4460Sstevel@tonic-gate sop->so_flags = SO_READOPT;
4470Sstevel@tonic-gate sop->so_readopt = RFLUSHPCPROT;
4480Sstevel@tonic-gate
4490Sstevel@tonic-gate putnext(q, bp);
4500Sstevel@tonic-gate
4510Sstevel@tonic-gate return (0);
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate
4540Sstevel@tonic-gate static void
tim_timer(void * arg)4550Sstevel@tonic-gate tim_timer(void *arg)
4560Sstevel@tonic-gate {
4570Sstevel@tonic-gate queue_t *q = arg;
4580Sstevel@tonic-gate struct tim_tim *tp = (struct tim_tim *)q->q_ptr;
4590Sstevel@tonic-gate
4600Sstevel@tonic-gate ASSERT(tp);
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate if (q->q_flag & QREADR) {
4630Sstevel@tonic-gate ASSERT(tp->tim_rtimoutid);
4640Sstevel@tonic-gate tp->tim_rtimoutid = 0;
4650Sstevel@tonic-gate } else {
4660Sstevel@tonic-gate ASSERT(tp->tim_wtimoutid);
4670Sstevel@tonic-gate tp->tim_wtimoutid = 0;
4680Sstevel@tonic-gate }
4690Sstevel@tonic-gate enableok(q);
4700Sstevel@tonic-gate qenable(q);
4710Sstevel@tonic-gate }
4720Sstevel@tonic-gate
4730Sstevel@tonic-gate static void
tim_buffer(void * arg)4740Sstevel@tonic-gate tim_buffer(void *arg)
4750Sstevel@tonic-gate {
4760Sstevel@tonic-gate queue_t *q = arg;
4770Sstevel@tonic-gate struct tim_tim *tp = (struct tim_tim *)q->q_ptr;
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate ASSERT(tp);
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate if (q->q_flag & QREADR) {
4820Sstevel@tonic-gate ASSERT(tp->tim_rbufcid);
4830Sstevel@tonic-gate tp->tim_rbufcid = 0;
4840Sstevel@tonic-gate } else {
4850Sstevel@tonic-gate ASSERT(tp->tim_wbufcid);
4860Sstevel@tonic-gate tp->tim_wbufcid = 0;
4870Sstevel@tonic-gate }
4880Sstevel@tonic-gate enableok(q);
4890Sstevel@tonic-gate qenable(q);
4900Sstevel@tonic-gate }
4910Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
4920Sstevel@tonic-gate
4930Sstevel@tonic-gate /*
4940Sstevel@tonic-gate * timodclose - This routine gets called when the module gets popped
4950Sstevel@tonic-gate * off of the stream.
4960Sstevel@tonic-gate */
4970Sstevel@tonic-gate /*ARGSUSED*/
4980Sstevel@tonic-gate static int
timodclose(queue_t * q,int flag,cred_t * crp)4990Sstevel@tonic-gate timodclose(
5000Sstevel@tonic-gate queue_t *q,
5010Sstevel@tonic-gate int flag,
5020Sstevel@tonic-gate cred_t *crp)
5030Sstevel@tonic-gate {
5040Sstevel@tonic-gate struct tim_tim *tp;
5050Sstevel@tonic-gate mblk_t *mp;
5060Sstevel@tonic-gate mblk_t *nmp;
5070Sstevel@tonic-gate
5080Sstevel@tonic-gate ASSERT(q != NULL);
5090Sstevel@tonic-gate
5100Sstevel@tonic-gate tp = (struct tim_tim *)q->q_ptr;
5110Sstevel@tonic-gate q->q_ptr = NULL;
5120Sstevel@tonic-gate
5130Sstevel@tonic-gate ASSERT(tp != NULL);
5140Sstevel@tonic-gate
5150Sstevel@tonic-gate tilogp("timodclose: Entered for tp %lx\n", (uintptr_t)tp);
5160Sstevel@tonic-gate tilogp("timodclose: Entered for q %lx\n", (uintptr_t)q);
5170Sstevel@tonic-gate
5180Sstevel@tonic-gate qprocsoff(q);
5190Sstevel@tonic-gate tim_dellink(tp);
5200Sstevel@tonic-gate
5210Sstevel@tonic-gate /*
5220Sstevel@tonic-gate * Cancel any outstanding bufcall
5230Sstevel@tonic-gate * or timeout requests.
5240Sstevel@tonic-gate */
5250Sstevel@tonic-gate if (tp->tim_wbufcid) {
5260Sstevel@tonic-gate qunbufcall(q, tp->tim_wbufcid);
5270Sstevel@tonic-gate tp->tim_wbufcid = 0;
5280Sstevel@tonic-gate }
5290Sstevel@tonic-gate if (tp->tim_rbufcid) {
5300Sstevel@tonic-gate qunbufcall(q, tp->tim_rbufcid);
5310Sstevel@tonic-gate tp->tim_rbufcid = 0;
5320Sstevel@tonic-gate }
5330Sstevel@tonic-gate if (tp->tim_wtimoutid) {
5340Sstevel@tonic-gate (void) quntimeout(q, tp->tim_wtimoutid);
5350Sstevel@tonic-gate tp->tim_wtimoutid = 0;
5360Sstevel@tonic-gate }
5370Sstevel@tonic-gate if (tp->tim_rtimoutid) {
5380Sstevel@tonic-gate (void) quntimeout(q, tp->tim_rtimoutid);
5390Sstevel@tonic-gate tp->tim_rtimoutid = 0;
5400Sstevel@tonic-gate }
5410Sstevel@tonic-gate
5420Sstevel@tonic-gate if (tp->tim_tcap_timoutid != 0) {
5430Sstevel@tonic-gate (void) quntimeout(q, tp->tim_tcap_timoutid);
5440Sstevel@tonic-gate tp->tim_tcap_timoutid = 0;
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate
5470Sstevel@tonic-gate if (tp->tim_iocsave != NULL)
5480Sstevel@tonic-gate freemsg(tp->tim_iocsave);
5490Sstevel@tonic-gate mp = tp->tim_consave;
5500Sstevel@tonic-gate while (mp) {
5510Sstevel@tonic-gate nmp = mp->b_next;
5520Sstevel@tonic-gate mp->b_next = NULL;
5530Sstevel@tonic-gate freemsg(mp);
5540Sstevel@tonic-gate mp = nmp;
5550Sstevel@tonic-gate }
5560Sstevel@tonic-gate ASSERT(tp->tim_mymaxlen >= 0);
5570Sstevel@tonic-gate if (tp->tim_mymaxlen != 0)
5580Sstevel@tonic-gate kmem_free(tp->tim_myname, (size_t)tp->tim_mymaxlen);
5590Sstevel@tonic-gate ASSERT(tp->tim_peermaxlen >= 0);
5600Sstevel@tonic-gate if (tp->tim_peermaxlen != 0)
5610Sstevel@tonic-gate kmem_free(tp->tim_peername, (size_t)tp->tim_peermaxlen);
5620Sstevel@tonic-gate
5630Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = NULL;
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate mutex_destroy(&tp->tim_mutex);
5660Sstevel@tonic-gate
5670Sstevel@tonic-gate if (tp->tim_peercred != NULL)
5680Sstevel@tonic-gate crfree(tp->tim_peercred);
5690Sstevel@tonic-gate
5700Sstevel@tonic-gate kmem_free(tp, sizeof (struct tim_tim));
5710Sstevel@tonic-gate
5720Sstevel@tonic-gate return (0);
5730Sstevel@tonic-gate }
5740Sstevel@tonic-gate
5750Sstevel@tonic-gate /*
5760Sstevel@tonic-gate * timodrput - Module read put procedure. This is called from
5770Sstevel@tonic-gate * the module, driver, or stream head upstream/downstream.
5780Sstevel@tonic-gate * Handles M_FLUSH, M_DATA and some M_PROTO (T_DATA_IND,
5790Sstevel@tonic-gate * and T_UNITDATA_IND) messages. All others are queued to
5800Sstevel@tonic-gate * be handled by the service procedures.
5810Sstevel@tonic-gate */
5820Sstevel@tonic-gate static void
timodrput(queue_t * q,mblk_t * mp)5830Sstevel@tonic-gate timodrput(queue_t *q, mblk_t *mp)
5840Sstevel@tonic-gate {
5850Sstevel@tonic-gate union T_primitives *pptr;
5860Sstevel@tonic-gate
5870Sstevel@tonic-gate /*
5880Sstevel@tonic-gate * During flow control and other instances when messages
5890Sstevel@tonic-gate * are on queue, queue up a non high priority message
5900Sstevel@tonic-gate */
5910Sstevel@tonic-gate if (q->q_first != 0 && mp->b_datap->db_type < QPCTL) {
5920Sstevel@tonic-gate (void) putq(q, mp);
5930Sstevel@tonic-gate return;
5940Sstevel@tonic-gate }
5950Sstevel@tonic-gate
5960Sstevel@tonic-gate /*
5970Sstevel@tonic-gate * Inline processing of data (to avoid additional procedure call).
5980Sstevel@tonic-gate * Rest is handled in timodrproc.
5990Sstevel@tonic-gate */
6000Sstevel@tonic-gate
6010Sstevel@tonic-gate switch (mp->b_datap->db_type) {
6020Sstevel@tonic-gate case M_DATA:
6030Sstevel@tonic-gate if (bcanputnext(q, mp->b_band))
6040Sstevel@tonic-gate putnext(q, mp);
6050Sstevel@tonic-gate else
6060Sstevel@tonic-gate (void) putq(q, mp);
6070Sstevel@tonic-gate break;
6080Sstevel@tonic-gate case M_PROTO:
6090Sstevel@tonic-gate case M_PCPROTO:
6100Sstevel@tonic-gate if (MBLKL(mp) < sizeof (t_scalar_t)) {
6110Sstevel@tonic-gate if (mp->b_datap->db_type == M_PCPROTO ||
6120Sstevel@tonic-gate bcanputnext(q, mp->b_band)) {
6130Sstevel@tonic-gate putnext(q, mp);
6140Sstevel@tonic-gate } else {
6150Sstevel@tonic-gate (void) putq(q, mp);
6160Sstevel@tonic-gate }
6170Sstevel@tonic-gate break;
6180Sstevel@tonic-gate }
6190Sstevel@tonic-gate pptr = (union T_primitives *)mp->b_rptr;
6200Sstevel@tonic-gate switch (pptr->type) {
6210Sstevel@tonic-gate case T_EXDATA_IND:
6220Sstevel@tonic-gate case T_DATA_IND:
6230Sstevel@tonic-gate case T_UNITDATA_IND:
6240Sstevel@tonic-gate if (bcanputnext(q, mp->b_band))
6250Sstevel@tonic-gate putnext(q, mp);
6260Sstevel@tonic-gate else
6270Sstevel@tonic-gate (void) putq(q, mp);
6280Sstevel@tonic-gate break;
6290Sstevel@tonic-gate default:
6300Sstevel@tonic-gate (void) timodrproc(q, mp);
6310Sstevel@tonic-gate break;
6320Sstevel@tonic-gate }
6330Sstevel@tonic-gate break;
6340Sstevel@tonic-gate default:
6350Sstevel@tonic-gate (void) timodrproc(q, mp);
6360Sstevel@tonic-gate break;
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate }
6390Sstevel@tonic-gate
6400Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
6410Sstevel@tonic-gate /*
6420Sstevel@tonic-gate * timodrsrv - Module read queue service procedure. This is called when
6430Sstevel@tonic-gate * messages are placed on an empty queue, when high priority
6440Sstevel@tonic-gate * messages are placed on the queue, and when flow control
6450Sstevel@tonic-gate * restrictions subside. This code used to be included in a
6460Sstevel@tonic-gate * put procedure, but it was moved to a service procedure
6470Sstevel@tonic-gate * because several points were added where memory allocation
6480Sstevel@tonic-gate * could fail, and there is no reasonable recovery mechanism
6490Sstevel@tonic-gate * from the put procedure.
6500Sstevel@tonic-gate */
6510Sstevel@tonic-gate /*ARGSUSED*/
6520Sstevel@tonic-gate static void
timodrsrv(queue_t * q)6530Sstevel@tonic-gate timodrsrv(queue_t *q)
6540Sstevel@tonic-gate {
6550Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
6560Sstevel@tonic-gate mblk_t *mp;
6570Sstevel@tonic-gate struct tim_tim *tp;
6580Sstevel@tonic-gate
6590Sstevel@tonic-gate ASSERT(q != NULL);
6600Sstevel@tonic-gate
6610Sstevel@tonic-gate tp = (struct tim_tim *)q->q_ptr;
6620Sstevel@tonic-gate if (!tp)
6638778SErik.Nordmark@Sun.COM return;
6640Sstevel@tonic-gate
6650Sstevel@tonic-gate while ((mp = getq(q)) != NULL) {
6660Sstevel@tonic-gate if (timodrproc(q, mp)) {
6670Sstevel@tonic-gate /*
6680Sstevel@tonic-gate * timodrproc did a putbq - stop processing
6690Sstevel@tonic-gate * messages.
6700Sstevel@tonic-gate */
6710Sstevel@tonic-gate return;
6720Sstevel@tonic-gate }
6730Sstevel@tonic-gate }
6740Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
6750Sstevel@tonic-gate }
6760Sstevel@tonic-gate
6770Sstevel@tonic-gate /*
6780Sstevel@tonic-gate * Perform common processing when a T_CAPABILITY_ACK or T_INFO_ACK
6790Sstevel@tonic-gate * arrive. Set the queue properties and adjust the tim_flags according
6800Sstevel@tonic-gate * to the service type.
6810Sstevel@tonic-gate */
6820Sstevel@tonic-gate static void
timodprocessinfo(queue_t * q,struct tim_tim * tp,struct T_info_ack * tia)6830Sstevel@tonic-gate timodprocessinfo(queue_t *q, struct tim_tim *tp, struct T_info_ack *tia)
6840Sstevel@tonic-gate {
6850Sstevel@tonic-gate TILOG("timodprocessinfo: strqset(%d)\n", tia->TIDU_size);
6860Sstevel@tonic-gate (void) strqset(q, QMAXPSZ, 0, tia->TIDU_size);
6870Sstevel@tonic-gate (void) strqset(OTHERQ(q), QMAXPSZ, 0, tia->TIDU_size);
6880Sstevel@tonic-gate
6890Sstevel@tonic-gate if ((tia->SERV_type == T_COTS) || (tia->SERV_type == T_COTS_ORD))
6900Sstevel@tonic-gate tp->tim_flags = (tp->tim_flags & ~CLTS) | COTS;
6910Sstevel@tonic-gate else if (tia->SERV_type == T_CLTS)
6920Sstevel@tonic-gate tp->tim_flags = (tp->tim_flags & ~COTS) | CLTS;
6930Sstevel@tonic-gate }
6940Sstevel@tonic-gate
6950Sstevel@tonic-gate static int
timodrproc(queue_t * q,mblk_t * mp)6960Sstevel@tonic-gate timodrproc(queue_t *q, mblk_t *mp)
6970Sstevel@tonic-gate {
698*11861SMarek.Pospisil@Sun.COM uint32_t auditing = AU_AUDITING();
6990Sstevel@tonic-gate union T_primitives *pptr;
7000Sstevel@tonic-gate struct tim_tim *tp;
7010Sstevel@tonic-gate struct iocblk *iocbp;
7020Sstevel@tonic-gate mblk_t *nbp;
7030Sstevel@tonic-gate size_t blen;
7040Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
7050Sstevel@tonic-gate
7060Sstevel@tonic-gate tp = (struct tim_tim *)q->q_ptr;
7070Sstevel@tonic-gate
7080Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
7090Sstevel@tonic-gate switch (mp->b_datap->db_type) {
7100Sstevel@tonic-gate default:
7110Sstevel@tonic-gate putnext(q, mp);
7120Sstevel@tonic-gate break;
7130Sstevel@tonic-gate
7140Sstevel@tonic-gate case M_ERROR:
7150Sstevel@tonic-gate TILOG("timodrproc: Got M_ERROR, flags = %x\n", tp->tim_flags);
7160Sstevel@tonic-gate /*
7170Sstevel@tonic-gate * There is no specified standard response for driver when it
7180Sstevel@tonic-gate * receives unknown message type and M_ERROR is one
7190Sstevel@tonic-gate * possibility. If we send T_CAPABILITY_REQ down and transport
7200Sstevel@tonic-gate * provider responds with M_ERROR we assume that it doesn't
7210Sstevel@tonic-gate * understand this message type. This assumption may be
7220Sstevel@tonic-gate * sometimes incorrect (transport may reply with M_ERROR for
7230Sstevel@tonic-gate * some other reason) but there is no way for us to distinguish
7240Sstevel@tonic-gate * between different cases. In the worst case timod and everyone
7250Sstevel@tonic-gate * else sharing global transport description with it may end up
7260Sstevel@tonic-gate * emulating T_CAPABILITY_REQ.
7270Sstevel@tonic-gate */
7280Sstevel@tonic-gate
7290Sstevel@tonic-gate /*
7300Sstevel@tonic-gate * Check that we are waiting for T_CAPABILITY_ACK and
7310Sstevel@tonic-gate * T_CAPABILITY_REQ is not implemented by transport or emulated
7320Sstevel@tonic-gate * by timod.
7330Sstevel@tonic-gate */
7340Sstevel@tonic-gate if ((tp->tim_provinfo->tpi_capability == PI_DONTKNOW) &&
7350Sstevel@tonic-gate ((tp->tim_flags & TI_CAP_RECVD) != 0)) {
7360Sstevel@tonic-gate /*
7370Sstevel@tonic-gate * Good chances that this transport doesn't provide
7380Sstevel@tonic-gate * T_CAPABILITY_REQ. Mark this information permanently
7390Sstevel@tonic-gate * for the module + transport combination.
7400Sstevel@tonic-gate */
7410Sstevel@tonic-gate PI_PROVLOCK(tp->tim_provinfo);
7420Sstevel@tonic-gate if (tp->tim_provinfo->tpi_capability == PI_DONTKNOW)
7430Sstevel@tonic-gate tp->tim_provinfo->tpi_capability = PI_NO;
7440Sstevel@tonic-gate PI_PROVUNLOCK(tp->tim_provinfo);
7450Sstevel@tonic-gate if (tp->tim_tcap_timoutid != 0) {
7460Sstevel@tonic-gate (void) quntimeout(q, tp->tim_tcap_timoutid);
7470Sstevel@tonic-gate tp->tim_tcap_timoutid = 0;
7480Sstevel@tonic-gate }
7490Sstevel@tonic-gate }
7500Sstevel@tonic-gate putnext(q, mp);
7510Sstevel@tonic-gate break;
7520Sstevel@tonic-gate case M_DATA:
7530Sstevel@tonic-gate if (!bcanputnext(q, mp->b_band)) {
7540Sstevel@tonic-gate (void) putbq(q, mp);
7550Sstevel@tonic-gate return (1);
7560Sstevel@tonic-gate }
7570Sstevel@tonic-gate putnext(q, mp);
7580Sstevel@tonic-gate break;
7590Sstevel@tonic-gate
7600Sstevel@tonic-gate case M_PROTO:
7610Sstevel@tonic-gate case M_PCPROTO:
7620Sstevel@tonic-gate blen = MBLKL(mp);
7630Sstevel@tonic-gate if (blen < sizeof (t_scalar_t)) {
7640Sstevel@tonic-gate /*
7650Sstevel@tonic-gate * Note: it's not actually possible to get
7660Sstevel@tonic-gate * here with db_type M_PCPROTO, because
7670Sstevel@tonic-gate * timodrput has already checked MBLKL, and
7680Sstevel@tonic-gate * thus the assertion below. If the length
7690Sstevel@tonic-gate * was too short, then the message would have
7700Sstevel@tonic-gate * already been putnext'd, and would thus
7710Sstevel@tonic-gate * never appear here. Just the same, the code
7720Sstevel@tonic-gate * below handles the impossible case since
7730Sstevel@tonic-gate * it's easy to do and saves future
7740Sstevel@tonic-gate * maintainers from unfortunate accidents.
7750Sstevel@tonic-gate */
7760Sstevel@tonic-gate ASSERT(mp->b_datap->db_type == M_PROTO);
7770Sstevel@tonic-gate if (mp->b_datap->db_type == M_PROTO &&
7780Sstevel@tonic-gate !bcanputnext(q, mp->b_band)) {
7790Sstevel@tonic-gate (void) putbq(q, mp);
7800Sstevel@tonic-gate return (1);
7810Sstevel@tonic-gate }
7820Sstevel@tonic-gate putnext(q, mp);
7830Sstevel@tonic-gate break;
7840Sstevel@tonic-gate }
7850Sstevel@tonic-gate
7860Sstevel@tonic-gate pptr = (union T_primitives *)mp->b_rptr;
7870Sstevel@tonic-gate switch (pptr->type) {
7880Sstevel@tonic-gate default:
7890Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
7900Sstevel@tonic-gate
791*11861SMarek.Pospisil@Sun.COM if (auditing)
7920Sstevel@tonic-gate audit_sock(T_UNITDATA_IND, q, mp, TIMOD_ID);
7930Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
7940Sstevel@tonic-gate putnext(q, mp);
7950Sstevel@tonic-gate break;
7960Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
7970Sstevel@tonic-gate
7980Sstevel@tonic-gate case T_ERROR_ACK:
7990Sstevel@tonic-gate /* Restore db_type - recover() might have changed it */
8000Sstevel@tonic-gate mp->b_datap->db_type = M_PCPROTO;
8010Sstevel@tonic-gate if (blen < sizeof (struct T_error_ack)) {
8020Sstevel@tonic-gate putnext(q, mp);
8030Sstevel@tonic-gate break;
8040Sstevel@tonic-gate }
8050Sstevel@tonic-gate
8060Sstevel@tonic-gate tilog("timodrproc: Got T_ERROR_ACK, flags = %x\n",
8070Sstevel@tonic-gate tp->tim_flags);
8080Sstevel@tonic-gate
8090Sstevel@tonic-gate if ((tp->tim_flags & WAIT_CONNRESACK) &&
8100Sstevel@tonic-gate tp->tim_saved_prim == pptr->error_ack.ERROR_prim) {
8110Sstevel@tonic-gate tp->tim_flags &=
8120Sstevel@tonic-gate ~(WAIT_CONNRESACK | WAITIOCACK);
8130Sstevel@tonic-gate freemsg(tp->tim_iocsave);
8140Sstevel@tonic-gate tp->tim_iocsave = NULL;
8150Sstevel@tonic-gate tp->tim_saved_prim = -1;
8160Sstevel@tonic-gate putnext(q, mp);
8170Sstevel@tonic-gate } else if (tp->tim_flags & WAITIOCACK) {
8180Sstevel@tonic-gate tim_send_ioc_error_ack(q, tp, mp);
8190Sstevel@tonic-gate } else {
8200Sstevel@tonic-gate putnext(q, mp);
8210Sstevel@tonic-gate }
8220Sstevel@tonic-gate break;
8230Sstevel@tonic-gate
8240Sstevel@tonic-gate case T_OK_ACK:
8250Sstevel@tonic-gate if (blen < sizeof (pptr->ok_ack)) {
8260Sstevel@tonic-gate mp->b_datap->db_type = M_PCPROTO;
8270Sstevel@tonic-gate putnext(q, mp);
8280Sstevel@tonic-gate break;
8290Sstevel@tonic-gate }
8300Sstevel@tonic-gate
8310Sstevel@tonic-gate tilog("timodrproc: Got T_OK_ACK\n", 0);
8320Sstevel@tonic-gate
8330Sstevel@tonic-gate if (pptr->ok_ack.CORRECT_prim == T_UNBIND_REQ)
8340Sstevel@tonic-gate tp->tim_mylen = 0;
8350Sstevel@tonic-gate
8360Sstevel@tonic-gate if ((tp->tim_flags & WAIT_CONNRESACK) &&
8370Sstevel@tonic-gate tp->tim_saved_prim == pptr->ok_ack.CORRECT_prim) {
8380Sstevel@tonic-gate struct T_conn_res *resp;
8390Sstevel@tonic-gate struct T_conn_ind *indp;
8400Sstevel@tonic-gate struct tim_tim *ntp;
8410Sstevel@tonic-gate caddr_t ptr;
8420Sstevel@tonic-gate
8430Sstevel@tonic-gate rw_enter(&tim_list_rwlock, RW_READER);
8440Sstevel@tonic-gate resp = (struct T_conn_res *)
8450Sstevel@tonic-gate tp->tim_iocsave->b_rptr;
8460Sstevel@tonic-gate ntp = tim_findlink(resp->ACCEPTOR_id);
8470Sstevel@tonic-gate if (ntp == NULL)
8480Sstevel@tonic-gate goto cresackout;
8490Sstevel@tonic-gate
8500Sstevel@tonic-gate mutex_enter(&ntp->tim_mutex);
8510Sstevel@tonic-gate if (ntp->tim_peercred != NULL)
8520Sstevel@tonic-gate crfree(ntp->tim_peercred);
8530Sstevel@tonic-gate ntp->tim_peercred =
8548778SErik.Nordmark@Sun.COM msg_getcred(tp->tim_iocsave->b_cont,
8558778SErik.Nordmark@Sun.COM &ntp->tim_cpid);
8560Sstevel@tonic-gate if (ntp->tim_peercred != NULL)
8570Sstevel@tonic-gate crhold(ntp->tim_peercred);
8580Sstevel@tonic-gate
8590Sstevel@tonic-gate if (!(ntp->tim_flags & DO_PEERNAME)) {
8600Sstevel@tonic-gate mutex_exit(&ntp->tim_mutex);
8610Sstevel@tonic-gate goto cresackout;
8620Sstevel@tonic-gate }
8630Sstevel@tonic-gate
8640Sstevel@tonic-gate indp = (struct T_conn_ind *)
8650Sstevel@tonic-gate tp->tim_iocsave->b_cont->b_rptr;
8660Sstevel@tonic-gate /* true as message is put on list */
8670Sstevel@tonic-gate ASSERT(indp->SRC_length >= 0);
8680Sstevel@tonic-gate
8690Sstevel@tonic-gate if (indp->SRC_length > ntp->tim_peermaxlen) {
8700Sstevel@tonic-gate ptr = kmem_alloc(indp->SRC_length,
8710Sstevel@tonic-gate KM_NOSLEEP);
8720Sstevel@tonic-gate if (ptr == NULL) {
8730Sstevel@tonic-gate mutex_exit(&ntp->tim_mutex);
8740Sstevel@tonic-gate rw_exit(&tim_list_rwlock);
8750Sstevel@tonic-gate tilog("timodwproc: kmem_alloc "
8760Sstevel@tonic-gate "failed, attempting "
8770Sstevel@tonic-gate "recovery\n", 0);
8780Sstevel@tonic-gate tim_recover(q, mp,
8790Sstevel@tonic-gate indp->SRC_length);
8800Sstevel@tonic-gate return (1);
8810Sstevel@tonic-gate }
8820Sstevel@tonic-gate if (ntp->tim_peermaxlen > 0)
8830Sstevel@tonic-gate kmem_free(ntp->tim_peername,
8840Sstevel@tonic-gate ntp->tim_peermaxlen);
8850Sstevel@tonic-gate ntp->tim_peername = ptr;
8860Sstevel@tonic-gate ntp->tim_peermaxlen = indp->SRC_length;
8870Sstevel@tonic-gate }
8880Sstevel@tonic-gate ntp->tim_peerlen = indp->SRC_length;
8890Sstevel@tonic-gate ptr = (caddr_t)indp + indp->SRC_offset;
8900Sstevel@tonic-gate bcopy(ptr, ntp->tim_peername, ntp->tim_peerlen);
8910Sstevel@tonic-gate
8920Sstevel@tonic-gate mutex_exit(&ntp->tim_mutex);
8930Sstevel@tonic-gate
8940Sstevel@tonic-gate cresackout:
8950Sstevel@tonic-gate rw_exit(&tim_list_rwlock);
8960Sstevel@tonic-gate tp->tim_flags &=
8970Sstevel@tonic-gate ~(WAIT_CONNRESACK | WAITIOCACK);
8980Sstevel@tonic-gate freemsg(tp->tim_iocsave);
8990Sstevel@tonic-gate tp->tim_iocsave = NULL;
9000Sstevel@tonic-gate tp->tim_saved_prim = -1;
9010Sstevel@tonic-gate }
9020Sstevel@tonic-gate
9030Sstevel@tonic-gate tim_send_reply(q, mp, tp, pptr->ok_ack.CORRECT_prim);
9040Sstevel@tonic-gate break;
9050Sstevel@tonic-gate
9060Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
9070Sstevel@tonic-gate case T_BIND_ACK: {
9080Sstevel@tonic-gate struct T_bind_ack *ackp =
9090Sstevel@tonic-gate (struct T_bind_ack *)mp->b_rptr;
9100Sstevel@tonic-gate
9110Sstevel@tonic-gate /* Restore db_type - recover() might have changed it */
9120Sstevel@tonic-gate mp->b_datap->db_type = M_PCPROTO;
9130Sstevel@tonic-gate if (blen < sizeof (*ackp)) {
9140Sstevel@tonic-gate putnext(q, mp);
9150Sstevel@tonic-gate break;
9160Sstevel@tonic-gate }
9170Sstevel@tonic-gate
9180Sstevel@tonic-gate /* save negotiated backlog */
9190Sstevel@tonic-gate tp->tim_backlog = ackp->CONIND_number;
9200Sstevel@tonic-gate
9210Sstevel@tonic-gate if (((tp->tim_flags & WAITIOCACK) == 0) ||
9220Sstevel@tonic-gate ((tp->tim_saved_prim != O_T_BIND_REQ) &&
9238778SErik.Nordmark@Sun.COM (tp->tim_saved_prim != T_BIND_REQ))) {
9240Sstevel@tonic-gate putnext(q, mp);
9250Sstevel@tonic-gate break;
9260Sstevel@tonic-gate }
9270Sstevel@tonic-gate ASSERT(tp->tim_iocsave != NULL);
9280Sstevel@tonic-gate
9290Sstevel@tonic-gate if (tp->tim_flags & DO_MYNAME) {
9300Sstevel@tonic-gate caddr_t p;
9310Sstevel@tonic-gate
9320Sstevel@tonic-gate if (ackp->ADDR_length < 0 ||
9330Sstevel@tonic-gate mp->b_rptr + ackp->ADDR_offset +
9340Sstevel@tonic-gate ackp->ADDR_length > mp->b_wptr) {
9350Sstevel@tonic-gate putnext(q, mp);
9360Sstevel@tonic-gate break;
9370Sstevel@tonic-gate }
9380Sstevel@tonic-gate if (ackp->ADDR_length > tp->tim_mymaxlen) {
9390Sstevel@tonic-gate p = kmem_alloc(ackp->ADDR_length,
9400Sstevel@tonic-gate KM_NOSLEEP);
9410Sstevel@tonic-gate if (p == NULL) {
9420Sstevel@tonic-gate tilog("timodrproc: kmem_alloc "
9430Sstevel@tonic-gate "failed attempt recovery",
9440Sstevel@tonic-gate 0);
9450Sstevel@tonic-gate
9460Sstevel@tonic-gate tim_recover(q, mp,
9470Sstevel@tonic-gate ackp->ADDR_length);
9480Sstevel@tonic-gate return (1);
9490Sstevel@tonic-gate }
9500Sstevel@tonic-gate ASSERT(tp->tim_mymaxlen >= 0);
9510Sstevel@tonic-gate if (tp->tim_mymaxlen != NULL) {
9520Sstevel@tonic-gate kmem_free(tp->tim_myname,
9530Sstevel@tonic-gate tp->tim_mymaxlen);
9540Sstevel@tonic-gate }
9550Sstevel@tonic-gate tp->tim_myname = p;
9560Sstevel@tonic-gate tp->tim_mymaxlen = ackp->ADDR_length;
9570Sstevel@tonic-gate }
9580Sstevel@tonic-gate tp->tim_mylen = ackp->ADDR_length;
9590Sstevel@tonic-gate bcopy(mp->b_rptr + ackp->ADDR_offset,
9600Sstevel@tonic-gate tp->tim_myname, tp->tim_mylen);
9610Sstevel@tonic-gate }
9620Sstevel@tonic-gate tim_ioctl_send_reply(q, tp->tim_iocsave, mp);
9630Sstevel@tonic-gate tp->tim_iocsave = NULL;
9640Sstevel@tonic-gate tp->tim_saved_prim = -1;
9650Sstevel@tonic-gate tp->tim_flags &= ~(WAITIOCACK | WAIT_IOCINFOACK |
9660Sstevel@tonic-gate TI_CAP_RECVD | CAP_WANTS_INFO);
9670Sstevel@tonic-gate break;
9680Sstevel@tonic-gate }
9690Sstevel@tonic-gate
9700Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
9718778SErik.Nordmark@Sun.COM case T_OPTMGMT_ACK:
9720Sstevel@tonic-gate
973*11861SMarek.Pospisil@Sun.COM tilog("timodrproc: Got T_OPTMGMT_ACK\n", 0);
974*11861SMarek.Pospisil@Sun.COM
975*11861SMarek.Pospisil@Sun.COM /* Restore db_type - recover() might have change it */
976*11861SMarek.Pospisil@Sun.COM mp->b_datap->db_type = M_PCPROTO;
977*11861SMarek.Pospisil@Sun.COM
978*11861SMarek.Pospisil@Sun.COM if (((tp->tim_flags & WAITIOCACK) == 0) ||
979*11861SMarek.Pospisil@Sun.COM ((tp->tim_saved_prim != T_SVR4_OPTMGMT_REQ) &&
980*11861SMarek.Pospisil@Sun.COM (tp->tim_saved_prim != T_OPTMGMT_REQ))) {
981*11861SMarek.Pospisil@Sun.COM putnext(q, mp);
982*11861SMarek.Pospisil@Sun.COM } else {
983*11861SMarek.Pospisil@Sun.COM ASSERT(tp->tim_iocsave != NULL);
984*11861SMarek.Pospisil@Sun.COM tim_ioctl_send_reply(q, tp->tim_iocsave, mp);
985*11861SMarek.Pospisil@Sun.COM tp->tim_iocsave = NULL;
986*11861SMarek.Pospisil@Sun.COM tp->tim_saved_prim = -1;
987*11861SMarek.Pospisil@Sun.COM tp->tim_flags &= ~(WAITIOCACK |
988*11861SMarek.Pospisil@Sun.COM WAIT_IOCINFOACK | TI_CAP_RECVD |
989*11861SMarek.Pospisil@Sun.COM CAP_WANTS_INFO);
990*11861SMarek.Pospisil@Sun.COM }
9910Sstevel@tonic-gate break;
9920Sstevel@tonic-gate
9930Sstevel@tonic-gate case T_INFO_ACK: {
9948778SErik.Nordmark@Sun.COM struct T_info_ack *tia = (struct T_info_ack *)pptr;
9958778SErik.Nordmark@Sun.COM
9968778SErik.Nordmark@Sun.COM /* Restore db_type - recover() might have changed it */
9978778SErik.Nordmark@Sun.COM mp->b_datap->db_type = M_PCPROTO;
9988778SErik.Nordmark@Sun.COM
9998778SErik.Nordmark@Sun.COM if (blen < sizeof (*tia)) {
10000Sstevel@tonic-gate putnext(q, mp);
10010Sstevel@tonic-gate break;
10028778SErik.Nordmark@Sun.COM }
10038778SErik.Nordmark@Sun.COM
10048778SErik.Nordmark@Sun.COM tilog("timodrproc: Got T_INFO_ACK, flags = %x\n",
10058778SErik.Nordmark@Sun.COM tp->tim_flags);
10068778SErik.Nordmark@Sun.COM
10078778SErik.Nordmark@Sun.COM timodprocessinfo(q, tp, tia);
10088778SErik.Nordmark@Sun.COM
10098778SErik.Nordmark@Sun.COM TILOG("timodrproc: flags = %x\n", tp->tim_flags);
10108778SErik.Nordmark@Sun.COM if ((tp->tim_flags & WAITIOCACK) != 0) {
10110Sstevel@tonic-gate size_t expected_ack_size;
10120Sstevel@tonic-gate ssize_t deficit;
10130Sstevel@tonic-gate int ioc_cmd;
10140Sstevel@tonic-gate struct T_capability_ack *tcap;
10150Sstevel@tonic-gate
10160Sstevel@tonic-gate /*
10170Sstevel@tonic-gate * The only case when T_INFO_ACK may be received back
10180Sstevel@tonic-gate * when we are waiting for ioctl to complete is when
10190Sstevel@tonic-gate * this ioctl sent T_INFO_REQ down.
10200Sstevel@tonic-gate */
10210Sstevel@tonic-gate if (!(tp->tim_flags & WAIT_IOCINFOACK)) {
10220Sstevel@tonic-gate putnext(q, mp);
10230Sstevel@tonic-gate break;
10240Sstevel@tonic-gate }
10250Sstevel@tonic-gate ASSERT(tp->tim_iocsave != NULL);
10260Sstevel@tonic-gate
10270Sstevel@tonic-gate iocbp = (struct iocblk *)tp->tim_iocsave->b_rptr;
10280Sstevel@tonic-gate ioc_cmd = iocbp->ioc_cmd;
10290Sstevel@tonic-gate
10300Sstevel@tonic-gate /*
10310Sstevel@tonic-gate * Was it sent from TI_CAPABILITY emulation?
10320Sstevel@tonic-gate */
10330Sstevel@tonic-gate if (ioc_cmd == TI_CAPABILITY) {
10340Sstevel@tonic-gate struct T_info_ack saved_info;
10350Sstevel@tonic-gate
10360Sstevel@tonic-gate /*
10370Sstevel@tonic-gate * Perform sanity checks. The only case when we
10380Sstevel@tonic-gate * send T_INFO_REQ from TI_CAPABILITY is when
10390Sstevel@tonic-gate * timod emulates T_CAPABILITY_REQ and CAP_bits1
10400Sstevel@tonic-gate * has TC1_INFO set.
10410Sstevel@tonic-gate */
10420Sstevel@tonic-gate if ((tp->tim_flags &
10430Sstevel@tonic-gate (TI_CAP_RECVD | CAP_WANTS_INFO)) !=
10440Sstevel@tonic-gate (TI_CAP_RECVD | CAP_WANTS_INFO)) {
10450Sstevel@tonic-gate putnext(q, mp);
10460Sstevel@tonic-gate break;
10470Sstevel@tonic-gate }
10480Sstevel@tonic-gate
10490Sstevel@tonic-gate TILOG("timodrproc: emulating TI_CAPABILITY/"
10500Sstevel@tonic-gate "info\n", 0);
10510Sstevel@tonic-gate
10520Sstevel@tonic-gate /* Save info & reuse mp for T_CAPABILITY_ACK */
10530Sstevel@tonic-gate saved_info = *tia;
10540Sstevel@tonic-gate
10550Sstevel@tonic-gate mp = tpi_ack_alloc(mp,
10560Sstevel@tonic-gate sizeof (struct T_capability_ack),
10570Sstevel@tonic-gate M_PCPROTO, T_CAPABILITY_ACK);
10580Sstevel@tonic-gate
10590Sstevel@tonic-gate if (mp == NULL) {
10600Sstevel@tonic-gate tilog("timodrproc: realloc failed, "
10610Sstevel@tonic-gate "no recovery attempted\n", 0);
10620Sstevel@tonic-gate return (1);
10630Sstevel@tonic-gate }
10640Sstevel@tonic-gate
10650Sstevel@tonic-gate /*
10660Sstevel@tonic-gate * Copy T_INFO information into T_CAPABILITY_ACK
10670Sstevel@tonic-gate */
10680Sstevel@tonic-gate tcap = (struct T_capability_ack *)mp->b_rptr;
10690Sstevel@tonic-gate tcap->CAP_bits1 = TC1_INFO;
10700Sstevel@tonic-gate tcap->INFO_ack = saved_info;
10710Sstevel@tonic-gate tp->tim_flags &= ~(WAITIOCACK |
10720Sstevel@tonic-gate WAIT_IOCINFOACK | TI_CAP_RECVD |
10730Sstevel@tonic-gate CAP_WANTS_INFO);
10740Sstevel@tonic-gate tim_ioctl_send_reply(q, tp->tim_iocsave, mp);
10750Sstevel@tonic-gate tp->tim_iocsave = NULL;
10760Sstevel@tonic-gate tp->tim_saved_prim = -1;
10770Sstevel@tonic-gate break;
10780Sstevel@tonic-gate }
10790Sstevel@tonic-gate
10800Sstevel@tonic-gate /*
10810Sstevel@tonic-gate * The code for TI_SYNC/TI_GETINFO is left here only for
10820Sstevel@tonic-gate * backward compatibility with staticaly linked old
10830Sstevel@tonic-gate * applications. New TLI/XTI code should use
10840Sstevel@tonic-gate * TI_CAPABILITY for getting transport info and should
10850Sstevel@tonic-gate * not use TI_GETINFO/TI_SYNC for this purpose.
10860Sstevel@tonic-gate */
10870Sstevel@tonic-gate
10880Sstevel@tonic-gate /*
10890Sstevel@tonic-gate * make sure the message sent back is the size of
10900Sstevel@tonic-gate * the "expected ack"
10910Sstevel@tonic-gate * For TI_GETINFO, expected ack size is
10920Sstevel@tonic-gate * sizeof (T_info_ack)
10930Sstevel@tonic-gate * For TI_SYNC, expected ack size is
10940Sstevel@tonic-gate * sizeof (struct ti_sync_ack);
10950Sstevel@tonic-gate */
10960Sstevel@tonic-gate if (ioc_cmd != TI_GETINFO && ioc_cmd != TI_SYNC) {
10970Sstevel@tonic-gate putnext(q, mp);
10980Sstevel@tonic-gate break;
10990Sstevel@tonic-gate }
11000Sstevel@tonic-gate
11010Sstevel@tonic-gate expected_ack_size =
11028778SErik.Nordmark@Sun.COM sizeof (struct T_info_ack); /* TI_GETINFO */
11030Sstevel@tonic-gate if (iocbp->ioc_cmd == TI_SYNC) {
11040Sstevel@tonic-gate expected_ack_size = 2 * sizeof (uint32_t) +
11050Sstevel@tonic-gate sizeof (struct ti_sync_ack);
11060Sstevel@tonic-gate }
11070Sstevel@tonic-gate deficit = expected_ack_size - blen;
11080Sstevel@tonic-gate
11090Sstevel@tonic-gate if (deficit != 0) {
11100Sstevel@tonic-gate if (mp->b_datap->db_lim - mp->b_wptr <
11110Sstevel@tonic-gate deficit) {
11128778SErik.Nordmark@Sun.COM mblk_t *tmp = allocb(expected_ack_size,
11138778SErik.Nordmark@Sun.COM BPRI_HI);
1114*11861SMarek.Pospisil@Sun.COM if (tmp == NULL) {
1115*11861SMarek.Pospisil@Sun.COM ASSERT(MBLKSIZE(mp) >=
1116*11861SMarek.Pospisil@Sun.COM sizeof (struct T_error_ack));
1117*11861SMarek.Pospisil@Sun.COM
1118*11861SMarek.Pospisil@Sun.COM tilog("timodrproc: allocb failed no "
1119*11861SMarek.Pospisil@Sun.COM "recovery attempt\n", 0);
1120*11861SMarek.Pospisil@Sun.COM
1121*11861SMarek.Pospisil@Sun.COM mp->b_rptr = mp->b_datap->db_base;
1122*11861SMarek.Pospisil@Sun.COM pptr = (union T_primitives *)
1123*11861SMarek.Pospisil@Sun.COM mp->b_rptr;
1124*11861SMarek.Pospisil@Sun.COM pptr->error_ack.ERROR_prim = T_INFO_REQ;
1125*11861SMarek.Pospisil@Sun.COM pptr->error_ack.TLI_error = TSYSERR;
1126*11861SMarek.Pospisil@Sun.COM pptr->error_ack.UNIX_error = EAGAIN;
1127*11861SMarek.Pospisil@Sun.COM pptr->error_ack.PRIM_type = T_ERROR_ACK;
1128*11861SMarek.Pospisil@Sun.COM mp->b_datap->db_type = M_PCPROTO;
1129*11861SMarek.Pospisil@Sun.COM tim_send_ioc_error_ack(q, tp, mp);
1130*11861SMarek.Pospisil@Sun.COM break;
1131*11861SMarek.Pospisil@Sun.COM } else {
1132*11861SMarek.Pospisil@Sun.COM bcopy(mp->b_rptr, tmp->b_rptr, blen);
1133*11861SMarek.Pospisil@Sun.COM tmp->b_wptr += blen;
1134*11861SMarek.Pospisil@Sun.COM pptr = (union T_primitives *)
1135*11861SMarek.Pospisil@Sun.COM tmp->b_rptr;
1136*11861SMarek.Pospisil@Sun.COM freemsg(mp);
1137*11861SMarek.Pospisil@Sun.COM mp = tmp;
1138*11861SMarek.Pospisil@Sun.COM }
11390Sstevel@tonic-gate }
11400Sstevel@tonic-gate }
11410Sstevel@tonic-gate /*
11420Sstevel@tonic-gate * We now have "mp" which has enough space for an
11430Sstevel@tonic-gate * appropriate ack and contains struct T_info_ack
11440Sstevel@tonic-gate * that the transport provider returned. We now
11450Sstevel@tonic-gate * stuff it with more stuff to fullfill
11460Sstevel@tonic-gate * TI_SYNC ioctl needs, as necessary
11470Sstevel@tonic-gate */
11480Sstevel@tonic-gate if (iocbp->ioc_cmd == TI_SYNC) {
11490Sstevel@tonic-gate /*
11500Sstevel@tonic-gate * Assumes struct T_info_ack is first embedded
11510Sstevel@tonic-gate * type in struct ti_sync_ack so it is
11520Sstevel@tonic-gate * automatically there.
11530Sstevel@tonic-gate */
11540Sstevel@tonic-gate struct ti_sync_ack *tsap =
11550Sstevel@tonic-gate (struct ti_sync_ack *)mp->b_rptr;
11560Sstevel@tonic-gate
11570Sstevel@tonic-gate /*
11580Sstevel@tonic-gate * tsap->tsa_qlen needs to be set only if
11590Sstevel@tonic-gate * TSRF_QLEN_REQ flag is set, but for
11600Sstevel@tonic-gate * compatibility with statically linked
11610Sstevel@tonic-gate * applications it is set here regardless of the
11620Sstevel@tonic-gate * flag since old XTI library expected it to be
11630Sstevel@tonic-gate * set.
11640Sstevel@tonic-gate */
11650Sstevel@tonic-gate tsap->tsa_qlen = tp->tim_backlog;
11660Sstevel@tonic-gate tsap->tsa_flags = 0x0; /* intialize clear */
11670Sstevel@tonic-gate if (tp->tim_flags & PEEK_RDQ_EXPIND) {
11680Sstevel@tonic-gate /*
11690Sstevel@tonic-gate * Request to peek for EXPIND in
11700Sstevel@tonic-gate * rcvbuf.
11710Sstevel@tonic-gate */
11720Sstevel@tonic-gate if (ti_expind_on_rdqueues(q)) {
11730Sstevel@tonic-gate /*
11740Sstevel@tonic-gate * Expedited data is
11750Sstevel@tonic-gate * queued on the stream
11760Sstevel@tonic-gate * read side
11770Sstevel@tonic-gate */
11780Sstevel@tonic-gate tsap->tsa_flags |=
11790Sstevel@tonic-gate TSAF_EXP_QUEUED;
11800Sstevel@tonic-gate }
11810Sstevel@tonic-gate tp->tim_flags &=
11820Sstevel@tonic-gate ~PEEK_RDQ_EXPIND;
11830Sstevel@tonic-gate }
11840Sstevel@tonic-gate mp->b_wptr += 2*sizeof (uint32_t);
11850Sstevel@tonic-gate }
11860Sstevel@tonic-gate tim_ioctl_send_reply(q, tp->tim_iocsave, mp);
11870Sstevel@tonic-gate tp->tim_iocsave = NULL;
11880Sstevel@tonic-gate tp->tim_saved_prim = -1;
11890Sstevel@tonic-gate tp->tim_flags &= ~(WAITIOCACK | WAIT_IOCINFOACK |
11900Sstevel@tonic-gate TI_CAP_RECVD | CAP_WANTS_INFO);
11910Sstevel@tonic-gate break;
11928778SErik.Nordmark@Sun.COM }
11930Sstevel@tonic-gate }
11940Sstevel@tonic-gate
11950Sstevel@tonic-gate putnext(q, mp);
11960Sstevel@tonic-gate break;
11970Sstevel@tonic-gate
11980Sstevel@tonic-gate case T_ADDR_ACK:
11990Sstevel@tonic-gate tilog("timodrproc: Got T_ADDR_ACK\n", 0);
12000Sstevel@tonic-gate tim_send_reply(q, mp, tp, T_ADDR_REQ);
12010Sstevel@tonic-gate break;
12020Sstevel@tonic-gate
12030Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
12040Sstevel@tonic-gate case T_CONN_IND: {
12050Sstevel@tonic-gate struct T_conn_ind *tcip =
12060Sstevel@tonic-gate (struct T_conn_ind *)mp->b_rptr;
12070Sstevel@tonic-gate
12080Sstevel@tonic-gate tilog("timodrproc: Got T_CONN_IND\n", 0);
12090Sstevel@tonic-gate
12100Sstevel@tonic-gate if (blen >= sizeof (*tcip) &&
12110Sstevel@tonic-gate MBLKIN(mp, tcip->SRC_offset, tcip->SRC_length)) {
12120Sstevel@tonic-gate if (((nbp = dupmsg(mp)) != NULL) ||
12130Sstevel@tonic-gate ((nbp = copymsg(mp)) != NULL)) {
12140Sstevel@tonic-gate nbp->b_next = tp->tim_consave;
12150Sstevel@tonic-gate tp->tim_consave = nbp;
12160Sstevel@tonic-gate } else {
12170Sstevel@tonic-gate tim_recover(q, mp,
12180Sstevel@tonic-gate (t_scalar_t)sizeof (mblk_t));
12190Sstevel@tonic-gate return (1);
12200Sstevel@tonic-gate }
12210Sstevel@tonic-gate }
12220Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
1223*11861SMarek.Pospisil@Sun.COM if (auditing)
12240Sstevel@tonic-gate audit_sock(T_CONN_IND, q, mp, TIMOD_ID);
12250Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
12260Sstevel@tonic-gate putnext(q, mp);
12270Sstevel@tonic-gate break;
12280Sstevel@tonic-gate }
12290Sstevel@tonic-gate
12300Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
12310Sstevel@tonic-gate case T_CONN_CON:
12320Sstevel@tonic-gate mutex_enter(&tp->tim_mutex);
12330Sstevel@tonic-gate if (tp->tim_peercred != NULL)
12340Sstevel@tonic-gate crfree(tp->tim_peercred);
12358778SErik.Nordmark@Sun.COM tp->tim_peercred = msg_getcred(mp, &tp->tim_cpid);
12360Sstevel@tonic-gate if (tp->tim_peercred != NULL)
12370Sstevel@tonic-gate crhold(tp->tim_peercred);
12380Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
12390Sstevel@tonic-gate
12400Sstevel@tonic-gate tilog("timodrproc: Got T_CONN_CON\n", 0);
12410Sstevel@tonic-gate
12420Sstevel@tonic-gate tp->tim_flags &= ~CONNWAIT;
12430Sstevel@tonic-gate putnext(q, mp);
12440Sstevel@tonic-gate break;
12450Sstevel@tonic-gate
12460Sstevel@tonic-gate case T_DISCON_IND: {
12470Sstevel@tonic-gate struct T_discon_ind *disp;
12480Sstevel@tonic-gate struct T_conn_ind *conp;
12490Sstevel@tonic-gate mblk_t *pbp = NULL;
12500Sstevel@tonic-gate
12510Sstevel@tonic-gate if (q->q_first != 0)
12520Sstevel@tonic-gate tilog("timodrput: T_DISCON_IND - flow control\n", 0);
12530Sstevel@tonic-gate
12540Sstevel@tonic-gate if (blen < sizeof (*disp)) {
12550Sstevel@tonic-gate putnext(q, mp);
12560Sstevel@tonic-gate break;
12570Sstevel@tonic-gate }
12580Sstevel@tonic-gate
12590Sstevel@tonic-gate disp = (struct T_discon_ind *)mp->b_rptr;
12600Sstevel@tonic-gate
12610Sstevel@tonic-gate tilog("timodrproc: Got T_DISCON_IND Reason: %d\n",
12628778SErik.Nordmark@Sun.COM disp->DISCON_reason);
12630Sstevel@tonic-gate
12640Sstevel@tonic-gate tp->tim_flags &= ~(CONNWAIT|LOCORDREL|REMORDREL);
12650Sstevel@tonic-gate tim_clear_peer(tp);
12660Sstevel@tonic-gate for (nbp = tp->tim_consave; nbp; nbp = nbp->b_next) {
12678778SErik.Nordmark@Sun.COM conp = (struct T_conn_ind *)nbp->b_rptr;
12688778SErik.Nordmark@Sun.COM if (conp->SEQ_number == disp->SEQ_number)
12698778SErik.Nordmark@Sun.COM break;
12708778SErik.Nordmark@Sun.COM pbp = nbp;
12710Sstevel@tonic-gate }
12720Sstevel@tonic-gate if (nbp) {
12738778SErik.Nordmark@Sun.COM if (pbp)
12748778SErik.Nordmark@Sun.COM pbp->b_next = nbp->b_next;
12758778SErik.Nordmark@Sun.COM else
12768778SErik.Nordmark@Sun.COM tp->tim_consave = nbp->b_next;
12778778SErik.Nordmark@Sun.COM nbp->b_next = NULL;
12788778SErik.Nordmark@Sun.COM freemsg(nbp);
12790Sstevel@tonic-gate }
12800Sstevel@tonic-gate putnext(q, mp);
12810Sstevel@tonic-gate break;
12820Sstevel@tonic-gate }
12830Sstevel@tonic-gate
12840Sstevel@tonic-gate case T_ORDREL_IND:
12850Sstevel@tonic-gate
1286*11861SMarek.Pospisil@Sun.COM tilog("timodrproc: Got T_ORDREL_IND\n", 0);
1287*11861SMarek.Pospisil@Sun.COM
1288*11861SMarek.Pospisil@Sun.COM if (tp->tim_flags & LOCORDREL) {
1289*11861SMarek.Pospisil@Sun.COM tp->tim_flags &= ~(LOCORDREL|REMORDREL);
1290*11861SMarek.Pospisil@Sun.COM tim_clear_peer(tp);
1291*11861SMarek.Pospisil@Sun.COM } else {
1292*11861SMarek.Pospisil@Sun.COM tp->tim_flags |= REMORDREL;
1293*11861SMarek.Pospisil@Sun.COM }
1294*11861SMarek.Pospisil@Sun.COM putnext(q, mp);
1295*11861SMarek.Pospisil@Sun.COM break;
12960Sstevel@tonic-gate
12970Sstevel@tonic-gate case T_EXDATA_IND:
12980Sstevel@tonic-gate case T_DATA_IND:
12990Sstevel@tonic-gate case T_UNITDATA_IND:
13000Sstevel@tonic-gate if (pptr->type == T_EXDATA_IND)
13010Sstevel@tonic-gate tilog("timodrproc: Got T_EXDATA_IND\n", 0);
13020Sstevel@tonic-gate
13030Sstevel@tonic-gate if (!bcanputnext(q, mp->b_band)) {
13040Sstevel@tonic-gate (void) putbq(q, mp);
13050Sstevel@tonic-gate return (1);
13060Sstevel@tonic-gate }
13070Sstevel@tonic-gate putnext(q, mp);
13080Sstevel@tonic-gate break;
13090Sstevel@tonic-gate
13100Sstevel@tonic-gate case T_CAPABILITY_ACK: {
13110Sstevel@tonic-gate struct T_capability_ack *tca;
13120Sstevel@tonic-gate
13130Sstevel@tonic-gate if (blen < sizeof (*tca)) {
13140Sstevel@tonic-gate putnext(q, mp);
13150Sstevel@tonic-gate break;
13160Sstevel@tonic-gate }
13170Sstevel@tonic-gate
13180Sstevel@tonic-gate /* This transport supports T_CAPABILITY_REQ */
13190Sstevel@tonic-gate tilog("timodrproc: Got T_CAPABILITY_ACK\n", 0);
13200Sstevel@tonic-gate
13210Sstevel@tonic-gate PI_PROVLOCK(tp->tim_provinfo);
13220Sstevel@tonic-gate if (tp->tim_provinfo->tpi_capability != PI_YES)
13230Sstevel@tonic-gate tp->tim_provinfo->tpi_capability = PI_YES;
13240Sstevel@tonic-gate PI_PROVUNLOCK(tp->tim_provinfo);
13250Sstevel@tonic-gate
13260Sstevel@tonic-gate /* Reset possible pending timeout */
13270Sstevel@tonic-gate if (tp->tim_tcap_timoutid != 0) {
13280Sstevel@tonic-gate (void) quntimeout(q, tp->tim_tcap_timoutid);
13290Sstevel@tonic-gate tp->tim_tcap_timoutid = 0;
13300Sstevel@tonic-gate }
13310Sstevel@tonic-gate
13320Sstevel@tonic-gate tca = (struct T_capability_ack *)mp->b_rptr;
13330Sstevel@tonic-gate
13340Sstevel@tonic-gate if (tca->CAP_bits1 & TC1_INFO)
13350Sstevel@tonic-gate timodprocessinfo(q, tp, &tca->INFO_ack);
13360Sstevel@tonic-gate
13370Sstevel@tonic-gate tim_send_reply(q, mp, tp, T_CAPABILITY_REQ);
13380Sstevel@tonic-gate }
13390Sstevel@tonic-gate break;
13400Sstevel@tonic-gate }
13410Sstevel@tonic-gate break;
13420Sstevel@tonic-gate
13430Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
13440Sstevel@tonic-gate case M_FLUSH:
13450Sstevel@tonic-gate
13460Sstevel@tonic-gate tilog("timodrproc: Got M_FLUSH\n", 0);
13470Sstevel@tonic-gate
13480Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) {
13490Sstevel@tonic-gate if (*mp->b_rptr & FLUSHBAND)
13500Sstevel@tonic-gate flushband(q, *(mp->b_rptr + 1), FLUSHDATA);
13510Sstevel@tonic-gate else
13520Sstevel@tonic-gate flushq(q, FLUSHDATA);
13530Sstevel@tonic-gate }
13540Sstevel@tonic-gate putnext(q, mp);
13550Sstevel@tonic-gate break;
13560Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
13570Sstevel@tonic-gate
13580Sstevel@tonic-gate case M_IOCACK:
13590Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
13600Sstevel@tonic-gate
13610Sstevel@tonic-gate tilog("timodrproc: Got M_IOCACK\n", 0);
13620Sstevel@tonic-gate
13630Sstevel@tonic-gate if (iocbp->ioc_cmd == TI_GETMYNAME) {
13640Sstevel@tonic-gate
13650Sstevel@tonic-gate /*
13660Sstevel@tonic-gate * Transport provider supports this ioctl,
13670Sstevel@tonic-gate * so I don't have to.
13680Sstevel@tonic-gate */
13690Sstevel@tonic-gate if ((tp->tim_flags & DO_MYNAME) != 0) {
13700Sstevel@tonic-gate tp->tim_flags &= ~DO_MYNAME;
13710Sstevel@tonic-gate PI_PROVLOCK(tp->tim_provinfo);
13720Sstevel@tonic-gate tp->tim_provinfo->tpi_myname = PI_YES;
13730Sstevel@tonic-gate PI_PROVUNLOCK(tp->tim_provinfo);
13740Sstevel@tonic-gate }
13750Sstevel@tonic-gate
13760Sstevel@tonic-gate ASSERT(tp->tim_mymaxlen >= 0);
13770Sstevel@tonic-gate if (tp->tim_mymaxlen != 0) {
13780Sstevel@tonic-gate kmem_free(tp->tim_myname, (size_t)tp->tim_mymaxlen);
13790Sstevel@tonic-gate tp->tim_myname = NULL;
13800Sstevel@tonic-gate tp->tim_mymaxlen = 0;
13810Sstevel@tonic-gate }
13820Sstevel@tonic-gate /* tim_iocsave may already be overwritten. */
13830Sstevel@tonic-gate if (tp->tim_saved_prim == -1) {
13840Sstevel@tonic-gate freemsg(tp->tim_iocsave);
13850Sstevel@tonic-gate tp->tim_iocsave = NULL;
13860Sstevel@tonic-gate }
13870Sstevel@tonic-gate } else if (iocbp->ioc_cmd == TI_GETPEERNAME) {
13880Sstevel@tonic-gate boolean_t clearit;
13890Sstevel@tonic-gate
13900Sstevel@tonic-gate /*
13910Sstevel@tonic-gate * Transport provider supports this ioctl,
13920Sstevel@tonic-gate * so I don't have to.
13930Sstevel@tonic-gate */
13940Sstevel@tonic-gate if ((tp->tim_flags & DO_PEERNAME) != 0) {
13950Sstevel@tonic-gate tp->tim_flags &= ~DO_PEERNAME;
13960Sstevel@tonic-gate PI_PROVLOCK(tp->tim_provinfo);
13970Sstevel@tonic-gate tp->tim_provinfo->tpi_peername = PI_YES;
13980Sstevel@tonic-gate PI_PROVUNLOCK(tp->tim_provinfo);
13990Sstevel@tonic-gate }
14000Sstevel@tonic-gate
14010Sstevel@tonic-gate mutex_enter(&tp->tim_mutex);
14020Sstevel@tonic-gate ASSERT(tp->tim_peermaxlen >= 0);
14030Sstevel@tonic-gate clearit = tp->tim_peermaxlen != 0;
14040Sstevel@tonic-gate if (clearit) {
14050Sstevel@tonic-gate kmem_free(tp->tim_peername, tp->tim_peermaxlen);
14060Sstevel@tonic-gate tp->tim_peername = NULL;
14070Sstevel@tonic-gate tp->tim_peermaxlen = 0;
14080Sstevel@tonic-gate tp->tim_peerlen = 0;
14090Sstevel@tonic-gate }
14100Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
14110Sstevel@tonic-gate if (clearit) {
14120Sstevel@tonic-gate mblk_t *bp;
14130Sstevel@tonic-gate
14140Sstevel@tonic-gate bp = tp->tim_consave;
14150Sstevel@tonic-gate while (bp != NULL) {
14160Sstevel@tonic-gate nbp = bp->b_next;
14170Sstevel@tonic-gate bp->b_next = NULL;
14180Sstevel@tonic-gate freemsg(bp);
14190Sstevel@tonic-gate bp = nbp;
14200Sstevel@tonic-gate }
14210Sstevel@tonic-gate tp->tim_consave = NULL;
14220Sstevel@tonic-gate }
14230Sstevel@tonic-gate /* tim_iocsave may already be overwritten. */
14240Sstevel@tonic-gate if (tp->tim_saved_prim == -1) {
14250Sstevel@tonic-gate freemsg(tp->tim_iocsave);
14260Sstevel@tonic-gate tp->tim_iocsave = NULL;
14270Sstevel@tonic-gate }
14280Sstevel@tonic-gate }
14290Sstevel@tonic-gate putnext(q, mp);
14300Sstevel@tonic-gate break;
14310Sstevel@tonic-gate
14320Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
14330Sstevel@tonic-gate case M_IOCNAK:
14340Sstevel@tonic-gate
1435*11861SMarek.Pospisil@Sun.COM tilog("timodrproc: Got M_IOCNAK\n", 0);
1436*11861SMarek.Pospisil@Sun.COM
1437*11861SMarek.Pospisil@Sun.COM iocbp = (struct iocblk *)mp->b_rptr;
1438*11861SMarek.Pospisil@Sun.COM if (((iocbp->ioc_cmd == TI_GETMYNAME) ||
1439*11861SMarek.Pospisil@Sun.COM (iocbp->ioc_cmd == TI_GETPEERNAME)) &&
1440*11861SMarek.Pospisil@Sun.COM ((iocbp->ioc_error == EINVAL) || (iocbp->ioc_error == 0))) {
1441*11861SMarek.Pospisil@Sun.COM PI_PROVLOCK(tp->tim_provinfo);
1442*11861SMarek.Pospisil@Sun.COM if (iocbp->ioc_cmd == TI_GETMYNAME) {
1443*11861SMarek.Pospisil@Sun.COM if (tp->tim_provinfo->tpi_myname == PI_DONTKNOW)
1444*11861SMarek.Pospisil@Sun.COM tp->tim_provinfo->tpi_myname = PI_NO;
1445*11861SMarek.Pospisil@Sun.COM } else if (iocbp->ioc_cmd == TI_GETPEERNAME) {
1446*11861SMarek.Pospisil@Sun.COM if (tp->tim_provinfo->tpi_peername == PI_DONTKNOW)
1447*11861SMarek.Pospisil@Sun.COM tp->tim_provinfo->tpi_peername = PI_NO;
1448*11861SMarek.Pospisil@Sun.COM }
1449*11861SMarek.Pospisil@Sun.COM PI_PROVUNLOCK(tp->tim_provinfo);
1450*11861SMarek.Pospisil@Sun.COM /* tim_iocsave may already be overwritten. */
1451*11861SMarek.Pospisil@Sun.COM if ((tp->tim_iocsave != NULL) &&
1452*11861SMarek.Pospisil@Sun.COM (tp->tim_saved_prim == -1)) {
1453*11861SMarek.Pospisil@Sun.COM freemsg(mp);
1454*11861SMarek.Pospisil@Sun.COM mp = tp->tim_iocsave;
1455*11861SMarek.Pospisil@Sun.COM tp->tim_iocsave = NULL;
1456*11861SMarek.Pospisil@Sun.COM tp->tim_flags |= NAMEPROC;
1457*11861SMarek.Pospisil@Sun.COM if (ti_doname(WR(q), mp) != DONAME_CONT) {
1458*11861SMarek.Pospisil@Sun.COM tp->tim_flags &= ~NAMEPROC;
1459*11861SMarek.Pospisil@Sun.COM }
1460*11861SMarek.Pospisil@Sun.COM break;
1461*11861SMarek.Pospisil@Sun.COM }
1462*11861SMarek.Pospisil@Sun.COM }
1463*11861SMarek.Pospisil@Sun.COM putnext(q, mp);
1464*11861SMarek.Pospisil@Sun.COM break;
14650Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
14660Sstevel@tonic-gate }
14670Sstevel@tonic-gate
14680Sstevel@tonic-gate return (0);
14690Sstevel@tonic-gate }
14700Sstevel@tonic-gate
14710Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
14720Sstevel@tonic-gate /*
14730Sstevel@tonic-gate * timodwput - Module write put procedure. This is called from
14740Sstevel@tonic-gate * the module, driver, or stream head upstream/downstream.
14750Sstevel@tonic-gate * Handles M_FLUSH, M_DATA and some M_PROTO (T_DATA_REQ,
14760Sstevel@tonic-gate * and T_UNITDATA_REQ) messages. All others are queued to
14770Sstevel@tonic-gate * be handled by the service procedures.
14780Sstevel@tonic-gate */
14790Sstevel@tonic-gate
14800Sstevel@tonic-gate static void
timodwput(queue_t * q,mblk_t * mp)14810Sstevel@tonic-gate timodwput(queue_t *q, mblk_t *mp)
14820Sstevel@tonic-gate {
14830Sstevel@tonic-gate union T_primitives *pptr;
14840Sstevel@tonic-gate struct tim_tim *tp;
14850Sstevel@tonic-gate struct iocblk *iocbp;
14860Sstevel@tonic-gate
14870Sstevel@tonic-gate /*
14880Sstevel@tonic-gate * Enqueue normal-priority messages if our queue already
14890Sstevel@tonic-gate * holds some messages for deferred processing but don't
14900Sstevel@tonic-gate * enqueue those M_IOCTLs which will result in an
14910Sstevel@tonic-gate * M_PCPROTO (ie, high priority) message being created.
14920Sstevel@tonic-gate */
14930Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
14940Sstevel@tonic-gate if (q->q_first != 0 && mp->b_datap->db_type < QPCTL) {
14950Sstevel@tonic-gate if (mp->b_datap->db_type == M_IOCTL) {
14960Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
14970Sstevel@tonic-gate switch (iocbp->ioc_cmd) {
14980Sstevel@tonic-gate default:
14990Sstevel@tonic-gate (void) putq(q, mp);
15000Sstevel@tonic-gate return;
15010Sstevel@tonic-gate
15020Sstevel@tonic-gate case TI_GETINFO:
15030Sstevel@tonic-gate case TI_SYNC:
15040Sstevel@tonic-gate case TI_CAPABILITY:
15050Sstevel@tonic-gate break;
15060Sstevel@tonic-gate }
15070Sstevel@tonic-gate } else {
15080Sstevel@tonic-gate (void) putq(q, mp);
15090Sstevel@tonic-gate return;
15100Sstevel@tonic-gate }
15110Sstevel@tonic-gate }
15120Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
15130Sstevel@tonic-gate /*
15140Sstevel@tonic-gate * Inline processing of data (to avoid additional procedure call).
15150Sstevel@tonic-gate * Rest is handled in timodwproc.
15160Sstevel@tonic-gate */
15170Sstevel@tonic-gate
15180Sstevel@tonic-gate switch (mp->b_datap->db_type) {
15190Sstevel@tonic-gate case M_DATA:
15200Sstevel@tonic-gate tp = (struct tim_tim *)q->q_ptr;
15210Sstevel@tonic-gate ASSERT(tp);
15220Sstevel@tonic-gate if (tp->tim_flags & CLTS) {
15230Sstevel@tonic-gate mblk_t *tmp;
15240Sstevel@tonic-gate
15250Sstevel@tonic-gate if ((tmp = tim_filladdr(q, mp, B_FALSE)) == NULL) {
15260Sstevel@tonic-gate (void) putq(q, mp);
15270Sstevel@tonic-gate break;
15280Sstevel@tonic-gate } else {
15290Sstevel@tonic-gate mp = tmp;
15300Sstevel@tonic-gate }
15310Sstevel@tonic-gate }
15320Sstevel@tonic-gate if (bcanputnext(q, mp->b_band))
15330Sstevel@tonic-gate putnext(q, mp);
15340Sstevel@tonic-gate else
15350Sstevel@tonic-gate (void) putq(q, mp);
15360Sstevel@tonic-gate break;
15370Sstevel@tonic-gate case M_PROTO:
15380Sstevel@tonic-gate case M_PCPROTO:
15390Sstevel@tonic-gate pptr = (union T_primitives *)mp->b_rptr;
15400Sstevel@tonic-gate switch (pptr->type) {
15410Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
15420Sstevel@tonic-gate case T_UNITDATA_REQ:
15430Sstevel@tonic-gate tp = (struct tim_tim *)q->q_ptr;
15440Sstevel@tonic-gate ASSERT(tp);
15450Sstevel@tonic-gate if (tp->tim_flags & CLTS) {
15460Sstevel@tonic-gate mblk_t *tmp;
15470Sstevel@tonic-gate
15480Sstevel@tonic-gate tmp = tim_filladdr(q, mp, B_FALSE);
15490Sstevel@tonic-gate if (tmp == NULL) {
15500Sstevel@tonic-gate (void) putq(q, mp);
15510Sstevel@tonic-gate break;
15520Sstevel@tonic-gate } else {
15530Sstevel@tonic-gate mp = tmp;
15540Sstevel@tonic-gate }
15550Sstevel@tonic-gate }
15560Sstevel@tonic-gate if (bcanputnext(q, mp->b_band))
15570Sstevel@tonic-gate putnext(q, mp);
15580Sstevel@tonic-gate else
15590Sstevel@tonic-gate (void) putq(q, mp);
15600Sstevel@tonic-gate break;
15610Sstevel@tonic-gate
15620Sstevel@tonic-gate case T_DATA_REQ:
15630Sstevel@tonic-gate case T_EXDATA_REQ:
15640Sstevel@tonic-gate if (bcanputnext(q, mp->b_band))
15650Sstevel@tonic-gate putnext(q, mp);
15660Sstevel@tonic-gate else
15670Sstevel@tonic-gate (void) putq(q, mp);
15680Sstevel@tonic-gate break;
15690Sstevel@tonic-gate default:
15700Sstevel@tonic-gate (void) timodwproc(q, mp);
15710Sstevel@tonic-gate break;
15720Sstevel@tonic-gate }
15730Sstevel@tonic-gate break;
15740Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
15750Sstevel@tonic-gate default:
15760Sstevel@tonic-gate (void) timodwproc(q, mp);
15770Sstevel@tonic-gate break;
15780Sstevel@tonic-gate }
15790Sstevel@tonic-gate }
15800Sstevel@tonic-gate /*
15810Sstevel@tonic-gate * timodwsrv - Module write queue service procedure.
15820Sstevel@tonic-gate * This is called when messages are placed on an empty queue,
15830Sstevel@tonic-gate * when high priority messages are placed on the queue, and
15840Sstevel@tonic-gate * when flow control restrictions subside. This code used to
15850Sstevel@tonic-gate * be included in a put procedure, but it was moved to a
15860Sstevel@tonic-gate * service procedure because several points were added where
15870Sstevel@tonic-gate * memory allocation could fail, and there is no reasonable
15880Sstevel@tonic-gate * recovery mechanism from the put procedure.
15890Sstevel@tonic-gate */
15900Sstevel@tonic-gate static void
timodwsrv(queue_t * q)15910Sstevel@tonic-gate timodwsrv(queue_t *q)
15920Sstevel@tonic-gate {
15930Sstevel@tonic-gate mblk_t *mp;
15940Sstevel@tonic-gate
15950Sstevel@tonic-gate ASSERT(q != NULL);
15960Sstevel@tonic-gate if (q->q_ptr == NULL)
15978778SErik.Nordmark@Sun.COM return;
15980Sstevel@tonic-gate
15990Sstevel@tonic-gate while ((mp = getq(q)) != NULL) {
16000Sstevel@tonic-gate if (timodwproc(q, mp)) {
16010Sstevel@tonic-gate /*
16020Sstevel@tonic-gate * timodwproc did a putbq - stop processing
16030Sstevel@tonic-gate * messages.
16040Sstevel@tonic-gate */
16050Sstevel@tonic-gate return;
16060Sstevel@tonic-gate }
16070Sstevel@tonic-gate }
16080Sstevel@tonic-gate }
16090Sstevel@tonic-gate
16100Sstevel@tonic-gate /*
16110Sstevel@tonic-gate * Common routine to process write side messages
16120Sstevel@tonic-gate */
16130Sstevel@tonic-gate
16140Sstevel@tonic-gate static int
timodwproc(queue_t * q,mblk_t * mp)16150Sstevel@tonic-gate timodwproc(queue_t *q, mblk_t *mp)
16160Sstevel@tonic-gate {
16170Sstevel@tonic-gate union T_primitives *pptr;
16180Sstevel@tonic-gate struct tim_tim *tp;
1619*11861SMarek.Pospisil@Sun.COM uint32_t auditing = AU_AUDITING();
16200Sstevel@tonic-gate mblk_t *tmp;
16210Sstevel@tonic-gate struct iocblk *iocbp;
16220Sstevel@tonic-gate int error;
16230Sstevel@tonic-gate
16240Sstevel@tonic-gate tp = (struct tim_tim *)q->q_ptr;
16250Sstevel@tonic-gate
16260Sstevel@tonic-gate switch (mp->b_datap->db_type) {
16270Sstevel@tonic-gate default:
16280Sstevel@tonic-gate putnext(q, mp);
16290Sstevel@tonic-gate break;
16300Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
16310Sstevel@tonic-gate
16320Sstevel@tonic-gate case M_DATA:
16330Sstevel@tonic-gate if (tp->tim_flags & CLTS) {
16340Sstevel@tonic-gate if ((tmp = tim_filladdr(q, mp, B_TRUE)) == NULL) {
16350Sstevel@tonic-gate return (1);
16360Sstevel@tonic-gate } else {
16370Sstevel@tonic-gate mp = tmp;
16380Sstevel@tonic-gate }
16390Sstevel@tonic-gate }
16400Sstevel@tonic-gate if (!bcanputnext(q, mp->b_band)) {
16410Sstevel@tonic-gate (void) putbq(q, mp);
16420Sstevel@tonic-gate return (1);
16430Sstevel@tonic-gate }
16440Sstevel@tonic-gate putnext(q, mp);
16450Sstevel@tonic-gate break;
16460Sstevel@tonic-gate
16470Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
16480Sstevel@tonic-gate case M_IOCTL:
16490Sstevel@tonic-gate
16500Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
16510Sstevel@tonic-gate TILOG("timodwproc: Got M_IOCTL(%d)\n", iocbp->ioc_cmd);
16520Sstevel@tonic-gate
16530Sstevel@tonic-gate ASSERT(MBLKL(mp) == sizeof (struct iocblk));
16540Sstevel@tonic-gate
16550Sstevel@tonic-gate /*
16560Sstevel@tonic-gate * TPI requires we await response to a previously sent message
16571261Sgeorges * before handling another, put it back on the head of queue.
16581261Sgeorges * Since putbq() may see QWANTR unset when called from the
16591261Sgeorges * service procedure, the queue must be explicitly scheduled
16601261Sgeorges * for service, as no backenable will occur for this case.
16611261Sgeorges * tim_ioctl_retry() sets a timer to handle the qenable.
16620Sstevel@tonic-gate */
16630Sstevel@tonic-gate if (tp->tim_flags & WAITIOCACK) {
16640Sstevel@tonic-gate TILOG("timodwproc: putbq M_IOCTL(%d)\n",
16650Sstevel@tonic-gate iocbp->ioc_cmd);
16660Sstevel@tonic-gate (void) putbq(q, mp);
16671261Sgeorges /* Called from timodwsrv() and messages on queue */
16681261Sgeorges if (!(q->q_flag & QWANTR))
16691261Sgeorges tim_ioctl_retry(q);
16700Sstevel@tonic-gate return (1);
16710Sstevel@tonic-gate }
16720Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
16730Sstevel@tonic-gate
16740Sstevel@tonic-gate switch (iocbp->ioc_cmd) {
16750Sstevel@tonic-gate default:
16760Sstevel@tonic-gate putnext(q, mp);
16770Sstevel@tonic-gate break;
16780Sstevel@tonic-gate
16790Sstevel@tonic-gate case _I_GETPEERCRED:
16800Sstevel@tonic-gate if ((tp->tim_flags & COTS) == 0) {
16810Sstevel@tonic-gate miocnak(q, mp, 0, ENOTSUP);
16820Sstevel@tonic-gate } else {
16830Sstevel@tonic-gate mblk_t *cmp = mp->b_cont;
16840Sstevel@tonic-gate k_peercred_t *kp = NULL;
16850Sstevel@tonic-gate
16860Sstevel@tonic-gate mutex_enter(&tp->tim_mutex);
16870Sstevel@tonic-gate if (cmp != NULL &&
16880Sstevel@tonic-gate iocbp->ioc_flag == IOC_NATIVE &&
16890Sstevel@tonic-gate (tp->tim_flags &
16908778SErik.Nordmark@Sun.COM (CONNWAIT|LOCORDREL|REMORDREL)) == 0 &&
16910Sstevel@tonic-gate tp->tim_peercred != NULL &&
16920Sstevel@tonic-gate DB_TYPE(cmp) == M_DATA &&
16930Sstevel@tonic-gate MBLKL(cmp) == sizeof (k_peercred_t)) {
16940Sstevel@tonic-gate kp = (k_peercred_t *)cmp->b_rptr;
16950Sstevel@tonic-gate crhold(kp->pc_cr = tp->tim_peercred);
16960Sstevel@tonic-gate kp->pc_cpid = tp->tim_cpid;
16970Sstevel@tonic-gate }
16980Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
16990Sstevel@tonic-gate if (kp != NULL)
17000Sstevel@tonic-gate miocack(q, mp, sizeof (*kp), 0);
17010Sstevel@tonic-gate else
17020Sstevel@tonic-gate miocnak(q, mp, 0, ENOTCONN);
17030Sstevel@tonic-gate }
17040Sstevel@tonic-gate break;
17050Sstevel@tonic-gate case TI_BIND:
17060Sstevel@tonic-gate case TI_UNBIND:
17070Sstevel@tonic-gate case TI_OPTMGMT:
17080Sstevel@tonic-gate case TI_GETADDRS:
17090Sstevel@tonic-gate TILOG("timodwproc: TI_{BIND|UNBIND|OPTMGMT|GETADDRS}"
17100Sstevel@tonic-gate "\n", 0);
17110Sstevel@tonic-gate
17120Sstevel@tonic-gate /*
17130Sstevel@tonic-gate * We know that tim_send_ioctl_tpi_msg() is only
17140Sstevel@tonic-gate * going to examine the `type' field, so we only
17150Sstevel@tonic-gate * check that we can access that much data.
17160Sstevel@tonic-gate */
17170Sstevel@tonic-gate error = miocpullup(mp, sizeof (t_scalar_t));
17180Sstevel@tonic-gate if (error != 0) {
17190Sstevel@tonic-gate miocnak(q, mp, 0, error);
17200Sstevel@tonic-gate break;
17210Sstevel@tonic-gate }
17220Sstevel@tonic-gate tim_send_ioctl_tpi_msg(q, mp, tp, iocbp);
17230Sstevel@tonic-gate break;
17240Sstevel@tonic-gate
17250Sstevel@tonic-gate case TI_GETINFO:
17260Sstevel@tonic-gate TILOG("timodwproc: TI_GETINFO\n", 0);
17270Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct T_info_req));
17280Sstevel@tonic-gate if (error != 0) {
17290Sstevel@tonic-gate miocnak(q, mp, 0, error);
17300Sstevel@tonic-gate break;
17310Sstevel@tonic-gate }
17320Sstevel@tonic-gate tp->tim_flags |= WAIT_IOCINFOACK;
17330Sstevel@tonic-gate tim_send_ioctl_tpi_msg(q, mp, tp, iocbp);
17340Sstevel@tonic-gate break;
17350Sstevel@tonic-gate
17360Sstevel@tonic-gate case TI_SYNC: {
17370Sstevel@tonic-gate mblk_t *tsr_mp;
17380Sstevel@tonic-gate struct ti_sync_req *tsr;
17390Sstevel@tonic-gate uint32_t tsr_flags;
17400Sstevel@tonic-gate
17410Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct ti_sync_req));
17420Sstevel@tonic-gate if (error != 0) {
17430Sstevel@tonic-gate miocnak(q, mp, 0, error);
17440Sstevel@tonic-gate break;
17450Sstevel@tonic-gate }
17460Sstevel@tonic-gate
17470Sstevel@tonic-gate tsr_mp = mp->b_cont;
17480Sstevel@tonic-gate tsr = (struct ti_sync_req *)tsr_mp->b_rptr;
17490Sstevel@tonic-gate TILOG("timodwproc: TI_SYNC(%x)\n", tsr->tsr_flags);
17500Sstevel@tonic-gate
17510Sstevel@tonic-gate /*
17520Sstevel@tonic-gate * Save out the value of tsr_flags, in case we
17530Sstevel@tonic-gate * reallocb() tsr_mp (below).
17540Sstevel@tonic-gate */
17550Sstevel@tonic-gate tsr_flags = tsr->tsr_flags;
17560Sstevel@tonic-gate if ((tsr_flags & TSRF_INFO_REQ) == 0) {
17570Sstevel@tonic-gate mblk_t *ack_mp = reallocb(tsr_mp,
17580Sstevel@tonic-gate sizeof (struct ti_sync_ack), 0);
17590Sstevel@tonic-gate
17600Sstevel@tonic-gate /* Can reply immediately. */
17610Sstevel@tonic-gate mp->b_cont = NULL;
17620Sstevel@tonic-gate if (ack_mp == NULL) {
17630Sstevel@tonic-gate tilog("timodwproc: allocb failed no "
17640Sstevel@tonic-gate "recovery attempt\n", 0);
17650Sstevel@tonic-gate freemsg(tsr_mp);
17660Sstevel@tonic-gate miocnak(q, mp, 0, ENOMEM);
17670Sstevel@tonic-gate } else {
17680Sstevel@tonic-gate tim_answer_ti_sync(q, mp, tp,
17690Sstevel@tonic-gate ack_mp, tsr_flags);
17700Sstevel@tonic-gate }
17710Sstevel@tonic-gate break;
17720Sstevel@tonic-gate }
17730Sstevel@tonic-gate
17740Sstevel@tonic-gate /*
17750Sstevel@tonic-gate * This code is retained for compatibility with
17760Sstevel@tonic-gate * old statically linked applications. New code
17770Sstevel@tonic-gate * should use TI_CAPABILITY for all TPI
17780Sstevel@tonic-gate * information and should not use TSRF_INFO_REQ
17790Sstevel@tonic-gate * flag.
17800Sstevel@tonic-gate *
17810Sstevel@tonic-gate * defer processsing necessary to rput procedure
17820Sstevel@tonic-gate * as we need to get information from transport
17830Sstevel@tonic-gate * driver. Set flags that will tell the read
17840Sstevel@tonic-gate * side the work needed on this request.
17850Sstevel@tonic-gate */
17860Sstevel@tonic-gate
17870Sstevel@tonic-gate if (tsr_flags & TSRF_IS_EXP_IN_RCVBUF)
17880Sstevel@tonic-gate tp->tim_flags |= PEEK_RDQ_EXPIND;
17890Sstevel@tonic-gate
17900Sstevel@tonic-gate /*
17910Sstevel@tonic-gate * Convert message to a T_INFO_REQ message; relies
17920Sstevel@tonic-gate * on sizeof (struct ti_sync_req) >= sizeof (struct
17930Sstevel@tonic-gate * T_info_req)).
17940Sstevel@tonic-gate */
17950Sstevel@tonic-gate ASSERT(MBLKL(tsr_mp) >= sizeof (struct T_info_req));
17960Sstevel@tonic-gate
17970Sstevel@tonic-gate ((struct T_info_req *)tsr_mp->b_rptr)->PRIM_type =
17980Sstevel@tonic-gate T_INFO_REQ;
17990Sstevel@tonic-gate tsr_mp->b_wptr = tsr_mp->b_rptr +
18000Sstevel@tonic-gate sizeof (struct T_info_req);
18010Sstevel@tonic-gate tp->tim_flags |= WAIT_IOCINFOACK;
18020Sstevel@tonic-gate tim_send_ioctl_tpi_msg(q, mp, tp, iocbp);
18030Sstevel@tonic-gate }
18040Sstevel@tonic-gate break;
18050Sstevel@tonic-gate
18060Sstevel@tonic-gate case TI_CAPABILITY: {
18070Sstevel@tonic-gate mblk_t *tcsr_mp;
18080Sstevel@tonic-gate struct T_capability_req *tcr;
18090Sstevel@tonic-gate
18100Sstevel@tonic-gate error = miocpullup(mp, sizeof (*tcr));
18110Sstevel@tonic-gate if (error != 0) {
18120Sstevel@tonic-gate miocnak(q, mp, 0, error);
18130Sstevel@tonic-gate break;
18140Sstevel@tonic-gate }
18150Sstevel@tonic-gate
18160Sstevel@tonic-gate tcsr_mp = mp->b_cont;
18170Sstevel@tonic-gate tcr = (struct T_capability_req *)tcsr_mp->b_rptr;
18180Sstevel@tonic-gate TILOG("timodwproc: TI_CAPABILITY(CAP_bits1 = %x)\n",
18190Sstevel@tonic-gate tcr->CAP_bits1);
18200Sstevel@tonic-gate
18210Sstevel@tonic-gate if (tcr->PRIM_type != T_CAPABILITY_REQ) {
18220Sstevel@tonic-gate TILOG("timodwproc: invalid msg type %d\n",
18230Sstevel@tonic-gate tcr->PRIM_type);
18240Sstevel@tonic-gate miocnak(q, mp, 0, EPROTO);
18250Sstevel@tonic-gate break;
18260Sstevel@tonic-gate }
18270Sstevel@tonic-gate
18280Sstevel@tonic-gate switch (tp->tim_provinfo->tpi_capability) {
18290Sstevel@tonic-gate case PI_YES:
18300Sstevel@tonic-gate /* Just send T_CAPABILITY_REQ down */
18310Sstevel@tonic-gate tim_send_ioctl_tpi_msg(q, mp, tp, iocbp);
18320Sstevel@tonic-gate break;
18330Sstevel@tonic-gate
18340Sstevel@tonic-gate case PI_DONTKNOW:
18350Sstevel@tonic-gate /*
18360Sstevel@tonic-gate * It is unknown yet whether transport provides
18370Sstevel@tonic-gate * T_CAPABILITY_REQ or not. Send message down
18380Sstevel@tonic-gate * and wait for reply.
18390Sstevel@tonic-gate */
18400Sstevel@tonic-gate
18410Sstevel@tonic-gate ASSERT(tp->tim_tcap_timoutid == 0);
18420Sstevel@tonic-gate if ((tcr->CAP_bits1 & TC1_INFO) == 0) {
18430Sstevel@tonic-gate tp->tim_flags |= TI_CAP_RECVD;
18440Sstevel@tonic-gate } else {
18450Sstevel@tonic-gate tp->tim_flags |= (TI_CAP_RECVD |
18460Sstevel@tonic-gate CAP_WANTS_INFO);
18470Sstevel@tonic-gate }
18480Sstevel@tonic-gate
18490Sstevel@tonic-gate tp->tim_tcap_timoutid = qtimeout(q,
18500Sstevel@tonic-gate tim_tcap_timer, q, tim_tcap_wait * hz);
18510Sstevel@tonic-gate tim_send_ioctl_tpi_msg(q, mp, tp, iocbp);
18520Sstevel@tonic-gate break;
18530Sstevel@tonic-gate
18540Sstevel@tonic-gate case PI_NO:
18550Sstevel@tonic-gate /*
18560Sstevel@tonic-gate * Transport doesn't support T_CAPABILITY_REQ.
18570Sstevel@tonic-gate * Either reply immediately or send T_INFO_REQ
18580Sstevel@tonic-gate * if needed.
18590Sstevel@tonic-gate */
18600Sstevel@tonic-gate if ((tcr->CAP_bits1 & TC1_INFO) != 0) {
18610Sstevel@tonic-gate tp->tim_flags |= (TI_CAP_RECVD |
18620Sstevel@tonic-gate CAP_WANTS_INFO | WAIT_IOCINFOACK);
18630Sstevel@tonic-gate TILOG("timodwproc: sending down "
18640Sstevel@tonic-gate "T_INFO_REQ, flags = %x\n",
18650Sstevel@tonic-gate tp->tim_flags);
18660Sstevel@tonic-gate
18670Sstevel@tonic-gate /*
18680Sstevel@tonic-gate * Generate T_INFO_REQ message and send
18690Sstevel@tonic-gate * it down
18700Sstevel@tonic-gate */
18710Sstevel@tonic-gate ((struct T_info_req *)tcsr_mp->b_rptr)->
18720Sstevel@tonic-gate PRIM_type = T_INFO_REQ;
18730Sstevel@tonic-gate tcsr_mp->b_wptr = tcsr_mp->b_rptr +
18740Sstevel@tonic-gate sizeof (struct T_info_req);
18750Sstevel@tonic-gate tim_send_ioctl_tpi_msg(q, mp, tp,
18760Sstevel@tonic-gate iocbp);
18770Sstevel@tonic-gate break;
18780Sstevel@tonic-gate }
18790Sstevel@tonic-gate
18800Sstevel@tonic-gate
18810Sstevel@tonic-gate /*
18820Sstevel@tonic-gate * Can reply immediately. Just send back
18830Sstevel@tonic-gate * T_CAPABILITY_ACK with CAP_bits1 set to 0.
18840Sstevel@tonic-gate */
18850Sstevel@tonic-gate mp->b_cont = tcsr_mp = tpi_ack_alloc(mp->b_cont,
18860Sstevel@tonic-gate sizeof (struct T_capability_ack), M_PCPROTO,
18870Sstevel@tonic-gate T_CAPABILITY_ACK);
18880Sstevel@tonic-gate
18890Sstevel@tonic-gate if (tcsr_mp == NULL) {
18900Sstevel@tonic-gate tilog("timodwproc: allocb failed no "
18910Sstevel@tonic-gate "recovery attempt\n", 0);
18920Sstevel@tonic-gate miocnak(q, mp, 0, ENOMEM);
18930Sstevel@tonic-gate break;
18940Sstevel@tonic-gate }
18950Sstevel@tonic-gate
18960Sstevel@tonic-gate tp->tim_flags &= ~(WAITIOCACK | TI_CAP_RECVD |
18970Sstevel@tonic-gate WAIT_IOCINFOACK | CAP_WANTS_INFO);
18980Sstevel@tonic-gate ((struct T_capability_ack *)
18990Sstevel@tonic-gate tcsr_mp->b_rptr)->CAP_bits1 = 0;
19000Sstevel@tonic-gate tim_ioctl_send_reply(q, mp, tcsr_mp);
19010Sstevel@tonic-gate
19020Sstevel@tonic-gate /*
19030Sstevel@tonic-gate * It could happen when timod is awaiting ack
19040Sstevel@tonic-gate * for TI_GETPEERNAME/TI_GETMYNAME.
19050Sstevel@tonic-gate */
19060Sstevel@tonic-gate if (tp->tim_iocsave != NULL) {
19070Sstevel@tonic-gate freemsg(tp->tim_iocsave);
19080Sstevel@tonic-gate tp->tim_iocsave = NULL;
19090Sstevel@tonic-gate tp->tim_saved_prim = -1;
19100Sstevel@tonic-gate }
19110Sstevel@tonic-gate break;
19120Sstevel@tonic-gate
19130Sstevel@tonic-gate default:
19140Sstevel@tonic-gate cmn_err(CE_PANIC,
19150Sstevel@tonic-gate "timodwproc: unknown tpi_capability value "
19160Sstevel@tonic-gate "%d\n", tp->tim_provinfo->tpi_capability);
19170Sstevel@tonic-gate break;
19180Sstevel@tonic-gate }
19190Sstevel@tonic-gate }
19200Sstevel@tonic-gate break;
19210Sstevel@tonic-gate
19220Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
19230Sstevel@tonic-gate case TI_GETMYNAME:
19240Sstevel@tonic-gate
19250Sstevel@tonic-gate tilog("timodwproc: Got TI_GETMYNAME\n", 0);
19260Sstevel@tonic-gate
19270Sstevel@tonic-gate if (tp->tim_provinfo->tpi_myname == PI_YES) {
19280Sstevel@tonic-gate putnext(q, mp);
19290Sstevel@tonic-gate break;
19300Sstevel@tonic-gate }
19310Sstevel@tonic-gate goto getname;
19320Sstevel@tonic-gate
19330Sstevel@tonic-gate case TI_GETPEERNAME:
19340Sstevel@tonic-gate
19350Sstevel@tonic-gate tilog("timodwproc: Got TI_GETPEERNAME\n", 0);
19360Sstevel@tonic-gate
19370Sstevel@tonic-gate if (tp->tim_provinfo->tpi_peername == PI_YES) {
19380Sstevel@tonic-gate putnext(q, mp);
19390Sstevel@tonic-gate break;
19400Sstevel@tonic-gate }
19410Sstevel@tonic-gate getname:
19420Sstevel@tonic-gate if ((tmp = copymsg(mp)) == NULL) {
19430Sstevel@tonic-gate tim_recover(q, mp, msgsize(mp));
19440Sstevel@tonic-gate return (1);
19450Sstevel@tonic-gate }
19460Sstevel@tonic-gate /*
19470Sstevel@tonic-gate * tim_iocsave may be non-NULL when timod is awaiting
19480Sstevel@tonic-gate * ack for another TI_GETPEERNAME/TI_GETMYNAME.
19490Sstevel@tonic-gate */
19500Sstevel@tonic-gate freemsg(tp->tim_iocsave);
19510Sstevel@tonic-gate tp->tim_iocsave = mp;
19520Sstevel@tonic-gate tp->tim_saved_prim = -1;
19530Sstevel@tonic-gate putnext(q, tmp);
19540Sstevel@tonic-gate break;
19550Sstevel@tonic-gate }
19560Sstevel@tonic-gate break;
19570Sstevel@tonic-gate
19580Sstevel@tonic-gate case M_IOCDATA:
19590Sstevel@tonic-gate
19600Sstevel@tonic-gate if (tp->tim_flags & NAMEPROC) {
19610Sstevel@tonic-gate if (ti_doname(q, mp) != DONAME_CONT) {
19620Sstevel@tonic-gate tp->tim_flags &= ~NAMEPROC;
19630Sstevel@tonic-gate }
19640Sstevel@tonic-gate } else
19650Sstevel@tonic-gate putnext(q, mp);
19660Sstevel@tonic-gate break;
19670Sstevel@tonic-gate
19680Sstevel@tonic-gate case M_PROTO:
19690Sstevel@tonic-gate case M_PCPROTO:
19700Sstevel@tonic-gate if (MBLKL(mp) < sizeof (t_scalar_t)) {
19710Sstevel@tonic-gate merror(q, mp, EPROTO);
19720Sstevel@tonic-gate return (1);
19730Sstevel@tonic-gate }
19740Sstevel@tonic-gate
19750Sstevel@tonic-gate pptr = (union T_primitives *)mp->b_rptr;
19760Sstevel@tonic-gate switch (pptr->type) {
19770Sstevel@tonic-gate default:
19780Sstevel@tonic-gate putnext(q, mp);
19790Sstevel@tonic-gate break;
19800Sstevel@tonic-gate
19810Sstevel@tonic-gate case T_EXDATA_REQ:
19820Sstevel@tonic-gate case T_DATA_REQ:
19830Sstevel@tonic-gate if (pptr->type == T_EXDATA_REQ)
19840Sstevel@tonic-gate tilog("timodwproc: Got T_EXDATA_REQ\n", 0);
19850Sstevel@tonic-gate
19860Sstevel@tonic-gate if (!bcanputnext(q, mp->b_band)) {
19870Sstevel@tonic-gate (void) putbq(q, mp);
19880Sstevel@tonic-gate return (1);
19890Sstevel@tonic-gate }
19900Sstevel@tonic-gate putnext(q, mp);
19910Sstevel@tonic-gate break;
19920Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
19930Sstevel@tonic-gate
19940Sstevel@tonic-gate case T_UNITDATA_REQ:
19950Sstevel@tonic-gate if (tp->tim_flags & CLTS) {
19960Sstevel@tonic-gate tmp = tim_filladdr(q, mp, B_TRUE);
19970Sstevel@tonic-gate if (tmp == NULL) {
19980Sstevel@tonic-gate return (1);
19990Sstevel@tonic-gate } else {
20000Sstevel@tonic-gate mp = tmp;
20010Sstevel@tonic-gate }
20020Sstevel@tonic-gate }
2003*11861SMarek.Pospisil@Sun.COM if (auditing)
20040Sstevel@tonic-gate audit_sock(T_UNITDATA_REQ, q, mp, TIMOD_ID);
20050Sstevel@tonic-gate if (!bcanputnext(q, mp->b_band)) {
20060Sstevel@tonic-gate (void) putbq(q, mp);
20070Sstevel@tonic-gate return (1);
20080Sstevel@tonic-gate }
20090Sstevel@tonic-gate putnext(q, mp);
20100Sstevel@tonic-gate break;
20110Sstevel@tonic-gate
20120Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
20130Sstevel@tonic-gate case T_CONN_REQ: {
20140Sstevel@tonic-gate struct T_conn_req *reqp = (struct T_conn_req *)
20150Sstevel@tonic-gate mp->b_rptr;
20160Sstevel@tonic-gate void *p;
20170Sstevel@tonic-gate
20180Sstevel@tonic-gate tilog("timodwproc: Got T_CONN_REQ\n", 0);
20190Sstevel@tonic-gate
20200Sstevel@tonic-gate if (MBLKL(mp) < sizeof (struct T_conn_req)) {
20210Sstevel@tonic-gate merror(q, mp, EPROTO);
20220Sstevel@tonic-gate return (1);
20230Sstevel@tonic-gate }
20240Sstevel@tonic-gate
20250Sstevel@tonic-gate if (tp->tim_flags & DO_PEERNAME) {
20260Sstevel@tonic-gate if (!MBLKIN(mp, reqp->DEST_offset,
20270Sstevel@tonic-gate reqp->DEST_length)) {
20280Sstevel@tonic-gate merror(q, mp, EPROTO);
20290Sstevel@tonic-gate return (1);
20300Sstevel@tonic-gate }
20310Sstevel@tonic-gate ASSERT(reqp->DEST_length >= 0);
20320Sstevel@tonic-gate mutex_enter(&tp->tim_mutex);
20330Sstevel@tonic-gate if (reqp->DEST_length > tp->tim_peermaxlen) {
20340Sstevel@tonic-gate p = kmem_alloc(reqp->DEST_length,
20350Sstevel@tonic-gate KM_NOSLEEP);
20360Sstevel@tonic-gate if (p == NULL) {
20370Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
20380Sstevel@tonic-gate tilog("timodwproc: kmem_alloc "
20390Sstevel@tonic-gate "failed, attempting "
20400Sstevel@tonic-gate "recovery\n", 0);
20410Sstevel@tonic-gate tim_recover(q, mp,
20420Sstevel@tonic-gate reqp->DEST_length);
20430Sstevel@tonic-gate return (1);
20440Sstevel@tonic-gate }
20450Sstevel@tonic-gate if (tp->tim_peermaxlen)
20460Sstevel@tonic-gate kmem_free(tp->tim_peername,
20470Sstevel@tonic-gate tp->tim_peermaxlen);
20480Sstevel@tonic-gate tp->tim_peername = p;
20490Sstevel@tonic-gate tp->tim_peermaxlen = reqp->DEST_length;
20500Sstevel@tonic-gate }
20510Sstevel@tonic-gate tp->tim_peerlen = reqp->DEST_length;
20520Sstevel@tonic-gate p = mp->b_rptr + reqp->DEST_offset;
20530Sstevel@tonic-gate bcopy(p, tp->tim_peername, tp->tim_peerlen);
20540Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
20550Sstevel@tonic-gate }
20560Sstevel@tonic-gate if (tp->tim_flags & COTS)
20570Sstevel@tonic-gate tp->tim_flags |= CONNWAIT;
20580Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
2059*11861SMarek.Pospisil@Sun.COM if (auditing)
20600Sstevel@tonic-gate audit_sock(T_CONN_REQ, q, mp, TIMOD_ID);
20610Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
20620Sstevel@tonic-gate putnext(q, mp);
20630Sstevel@tonic-gate break;
2064*11861SMarek.Pospisil@Sun.COM }
20650Sstevel@tonic-gate
20660Sstevel@tonic-gate case O_T_CONN_RES:
20670Sstevel@tonic-gate case T_CONN_RES: {
20680Sstevel@tonic-gate struct T_conn_res *resp;
20690Sstevel@tonic-gate struct T_conn_ind *indp;
20700Sstevel@tonic-gate mblk_t *pmp = NULL;
20710Sstevel@tonic-gate mblk_t *nbp;
20720Sstevel@tonic-gate
20730Sstevel@tonic-gate if (MBLKL(mp) < sizeof (struct T_conn_res) ||
20740Sstevel@tonic-gate (tp->tim_flags & WAITIOCACK)) {
20750Sstevel@tonic-gate merror(q, mp, EPROTO);
20760Sstevel@tonic-gate return (1);
20770Sstevel@tonic-gate }
20780Sstevel@tonic-gate
20790Sstevel@tonic-gate resp = (struct T_conn_res *)mp->b_rptr;
20800Sstevel@tonic-gate for (tmp = tp->tim_consave; tmp != NULL;
20810Sstevel@tonic-gate tmp = tmp->b_next) {
20820Sstevel@tonic-gate indp = (struct T_conn_ind *)tmp->b_rptr;
20830Sstevel@tonic-gate if (indp->SEQ_number == resp->SEQ_number)
20840Sstevel@tonic-gate break;
20850Sstevel@tonic-gate pmp = tmp;
20860Sstevel@tonic-gate }
20870Sstevel@tonic-gate if (tmp == NULL)
20880Sstevel@tonic-gate goto cresout;
20890Sstevel@tonic-gate
20900Sstevel@tonic-gate if ((nbp = dupb(mp)) == NULL &&
20910Sstevel@tonic-gate (nbp = copyb(mp)) == NULL) {
20920Sstevel@tonic-gate tim_recover(q, mp, msgsize(mp));
20930Sstevel@tonic-gate return (1);
20940Sstevel@tonic-gate }
20950Sstevel@tonic-gate
20960Sstevel@tonic-gate if (pmp != NULL)
20970Sstevel@tonic-gate pmp->b_next = tmp->b_next;
20980Sstevel@tonic-gate else
20990Sstevel@tonic-gate tp->tim_consave = tmp->b_next;
21000Sstevel@tonic-gate tmp->b_next = NULL;
21010Sstevel@tonic-gate
21020Sstevel@tonic-gate /*
21030Sstevel@tonic-gate * Construct a list with:
21040Sstevel@tonic-gate * nbp - copy of user's original request
21050Sstevel@tonic-gate * tmp - the extracted T_conn_ind
21060Sstevel@tonic-gate */
21070Sstevel@tonic-gate nbp->b_cont = tmp;
21080Sstevel@tonic-gate /*
21090Sstevel@tonic-gate * tim_iocsave may be non-NULL when timod is awaiting
21100Sstevel@tonic-gate * ack for TI_GETPEERNAME/TI_GETMYNAME.
21110Sstevel@tonic-gate */
21120Sstevel@tonic-gate freemsg(tp->tim_iocsave);
21130Sstevel@tonic-gate tp->tim_iocsave = nbp;
21140Sstevel@tonic-gate tp->tim_saved_prim = pptr->type;
21150Sstevel@tonic-gate tp->tim_flags |= WAIT_CONNRESACK | WAITIOCACK;
21160Sstevel@tonic-gate
21170Sstevel@tonic-gate cresout:
21180Sstevel@tonic-gate putnext(q, mp);
21190Sstevel@tonic-gate break;
21200Sstevel@tonic-gate }
21210Sstevel@tonic-gate
21220Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
21230Sstevel@tonic-gate case T_DISCON_REQ: {
21240Sstevel@tonic-gate struct T_discon_req *disp;
21250Sstevel@tonic-gate struct T_conn_ind *conp;
21260Sstevel@tonic-gate mblk_t *pmp = NULL;
21270Sstevel@tonic-gate
21280Sstevel@tonic-gate if (MBLKL(mp) < sizeof (struct T_discon_req)) {
21290Sstevel@tonic-gate merror(q, mp, EPROTO);
21300Sstevel@tonic-gate return (1);
21310Sstevel@tonic-gate }
21320Sstevel@tonic-gate
21330Sstevel@tonic-gate disp = (struct T_discon_req *)mp->b_rptr;
21340Sstevel@tonic-gate tp->tim_flags &= ~(CONNWAIT|LOCORDREL|REMORDREL);
21350Sstevel@tonic-gate tim_clear_peer(tp);
21360Sstevel@tonic-gate
21370Sstevel@tonic-gate /*
21380Sstevel@tonic-gate * If we are already connected, there won't
21390Sstevel@tonic-gate * be any messages on tim_consave.
21400Sstevel@tonic-gate */
21410Sstevel@tonic-gate for (tmp = tp->tim_consave; tmp; tmp = tmp->b_next) {
21420Sstevel@tonic-gate conp = (struct T_conn_ind *)tmp->b_rptr;
21430Sstevel@tonic-gate if (conp->SEQ_number == disp->SEQ_number)
21440Sstevel@tonic-gate break;
21450Sstevel@tonic-gate pmp = tmp;
21460Sstevel@tonic-gate }
21470Sstevel@tonic-gate if (tmp) {
21480Sstevel@tonic-gate if (pmp)
21490Sstevel@tonic-gate pmp->b_next = tmp->b_next;
21500Sstevel@tonic-gate else
21510Sstevel@tonic-gate tp->tim_consave = tmp->b_next;
21520Sstevel@tonic-gate tmp->b_next = NULL;
21530Sstevel@tonic-gate freemsg(tmp);
21540Sstevel@tonic-gate }
21550Sstevel@tonic-gate putnext(q, mp);
21560Sstevel@tonic-gate break;
21570Sstevel@tonic-gate }
21580Sstevel@tonic-gate
21590Sstevel@tonic-gate case T_ORDREL_REQ:
21600Sstevel@tonic-gate if (tp->tim_flags & REMORDREL) {
21610Sstevel@tonic-gate tp->tim_flags &= ~(LOCORDREL|REMORDREL);
21620Sstevel@tonic-gate tim_clear_peer(tp);
21630Sstevel@tonic-gate } else {
21640Sstevel@tonic-gate tp->tim_flags |= LOCORDREL;
21650Sstevel@tonic-gate }
21660Sstevel@tonic-gate putnext(q, mp);
21670Sstevel@tonic-gate break;
21680Sstevel@tonic-gate
21690Sstevel@tonic-gate case T_CAPABILITY_REQ:
21700Sstevel@tonic-gate tilog("timodwproc: Got T_CAPABILITY_REQ\n", 0);
21710Sstevel@tonic-gate /*
21720Sstevel@tonic-gate * XXX: We may know at this point whether transport
21730Sstevel@tonic-gate * provides T_CAPABILITY_REQ or not and we may utilise
21740Sstevel@tonic-gate * this knowledge here.
21750Sstevel@tonic-gate */
21760Sstevel@tonic-gate putnext(q, mp);
21770Sstevel@tonic-gate break;
21780Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
21790Sstevel@tonic-gate }
21800Sstevel@tonic-gate break;
21810Sstevel@tonic-gate case M_FLUSH:
21820Sstevel@tonic-gate
21830Sstevel@tonic-gate tilog("timodwproc: Got M_FLUSH\n", 0);
21840Sstevel@tonic-gate
21850Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) {
21860Sstevel@tonic-gate if (*mp->b_rptr & FLUSHBAND)
21870Sstevel@tonic-gate flushband(q, *(mp->b_rptr + 1), FLUSHDATA);
21880Sstevel@tonic-gate else
21890Sstevel@tonic-gate flushq(q, FLUSHDATA);
21900Sstevel@tonic-gate }
21910Sstevel@tonic-gate putnext(q, mp);
21920Sstevel@tonic-gate break;
21930Sstevel@tonic-gate }
21940Sstevel@tonic-gate
21950Sstevel@tonic-gate return (0);
21960Sstevel@tonic-gate }
21970Sstevel@tonic-gate
21980Sstevel@tonic-gate static void
tilog(char * str,t_scalar_t arg)21990Sstevel@tonic-gate tilog(char *str, t_scalar_t arg)
22000Sstevel@tonic-gate {
22010Sstevel@tonic-gate if (dotilog) {
22020Sstevel@tonic-gate if (dotilog & 2)
22030Sstevel@tonic-gate cmn_err(CE_CONT, str, arg);
22040Sstevel@tonic-gate if (dotilog & 4)
22050Sstevel@tonic-gate (void) strlog(TIMOD_ID, -1, 0, SL_TRACE | SL_ERROR,
22060Sstevel@tonic-gate str, arg);
22070Sstevel@tonic-gate else
22080Sstevel@tonic-gate (void) strlog(TIMOD_ID, -1, 0, SL_TRACE, str, arg);
22090Sstevel@tonic-gate }
22100Sstevel@tonic-gate }
22110Sstevel@tonic-gate
22120Sstevel@tonic-gate static void
tilogp(char * str,uintptr_t arg)22130Sstevel@tonic-gate tilogp(char *str, uintptr_t arg)
22140Sstevel@tonic-gate {
22150Sstevel@tonic-gate if (dotilog) {
22160Sstevel@tonic-gate if (dotilog & 2)
22170Sstevel@tonic-gate cmn_err(CE_CONT, str, arg);
22180Sstevel@tonic-gate if (dotilog & 4)
22190Sstevel@tonic-gate (void) strlog(TIMOD_ID, -1, 0, SL_TRACE | SL_ERROR,
22200Sstevel@tonic-gate str, arg);
22210Sstevel@tonic-gate else
22220Sstevel@tonic-gate (void) strlog(TIMOD_ID, -1, 0, SL_TRACE, str, arg);
22230Sstevel@tonic-gate }
22240Sstevel@tonic-gate }
22250Sstevel@tonic-gate
22260Sstevel@tonic-gate
22270Sstevel@tonic-gate /*
22280Sstevel@tonic-gate * Process the TI_GETNAME ioctl. If no name exists, return len = 0
22290Sstevel@tonic-gate * in strbuf structures. The state transitions are determined by what
22300Sstevel@tonic-gate * is hung of cq_private (cp_private) in the copyresp (copyreq) structure.
22310Sstevel@tonic-gate * The high-level steps in the ioctl processing are as follows:
22320Sstevel@tonic-gate *
22330Sstevel@tonic-gate * 1) we recieve an transparent M_IOCTL with the arg in the second message
22340Sstevel@tonic-gate * block of the message.
22350Sstevel@tonic-gate * 2) we send up an M_COPYIN request for the strbuf structure pointed to
22360Sstevel@tonic-gate * by arg. The block containing arg is hung off cq_private.
22370Sstevel@tonic-gate * 3) we receive an M_IOCDATA response with cp->cp_private->b_cont == NULL.
22380Sstevel@tonic-gate * This means that the strbuf structure is found in the message block
22390Sstevel@tonic-gate * mp->b_cont.
22400Sstevel@tonic-gate * 4) we send up an M_COPYOUT request with the strbuf message hung off
22410Sstevel@tonic-gate * cq_private->b_cont. The address we are copying to is strbuf.buf.
22420Sstevel@tonic-gate * we set strbuf.len to 0 to indicate that we should copy the strbuf
22430Sstevel@tonic-gate * structure the next time. The message mp->b_cont contains the
22440Sstevel@tonic-gate * address info.
22450Sstevel@tonic-gate * 5) we receive an M_IOCDATA with cp_private->b_cont != NULL and
22460Sstevel@tonic-gate * strbuf.len == 0. Restore strbuf.len to either tp->tim_mylen or
22470Sstevel@tonic-gate * tp->tim_peerlen.
22480Sstevel@tonic-gate * 6) we send up an M_COPYOUT request with a copy of the strbuf message
22490Sstevel@tonic-gate * hung off mp->b_cont. In the strbuf structure in the message hung
22500Sstevel@tonic-gate * off cq_private->b_cont, we set strbuf.len to 0 and strbuf.maxlen
22510Sstevel@tonic-gate * to 0. This means that the next step is to ACK the ioctl.
22520Sstevel@tonic-gate * 7) we receive an M_IOCDATA message with cp_private->b_cont != NULL and
22530Sstevel@tonic-gate * strbuf.len == 0 and strbuf.maxlen == 0. Free up cp->private and
22540Sstevel@tonic-gate * send an M_IOCACK upstream, and we are done.
22550Sstevel@tonic-gate *
22560Sstevel@tonic-gate */
22570Sstevel@tonic-gate static int
ti_doname(queue_t * q,mblk_t * mp)22580Sstevel@tonic-gate ti_doname(
22590Sstevel@tonic-gate queue_t *q, /* queue message arrived at */
22600Sstevel@tonic-gate mblk_t *mp) /* M_IOCTL or M_IOCDATA message only */
22610Sstevel@tonic-gate {
22620Sstevel@tonic-gate struct iocblk *iocp;
22630Sstevel@tonic-gate struct copyreq *cqp;
22640Sstevel@tonic-gate STRUCT_HANDLE(strbuf, sb);
22650Sstevel@tonic-gate struct copyresp *csp;
22660Sstevel@tonic-gate int ret;
22670Sstevel@tonic-gate mblk_t *bp;
22680Sstevel@tonic-gate struct tim_tim *tp = q->q_ptr;
22690Sstevel@tonic-gate boolean_t getpeer;
22700Sstevel@tonic-gate
22710Sstevel@tonic-gate switch (mp->b_datap->db_type) {
22720Sstevel@tonic-gate case M_IOCTL:
22730Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
22740Sstevel@tonic-gate if ((iocp->ioc_cmd != TI_GETMYNAME) &&
22750Sstevel@tonic-gate (iocp->ioc_cmd != TI_GETPEERNAME)) {
22760Sstevel@tonic-gate tilog("ti_doname: bad M_IOCTL command\n", 0);
22770Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL);
22780Sstevel@tonic-gate ret = DONAME_FAIL;
22790Sstevel@tonic-gate break;
22800Sstevel@tonic-gate }
22810Sstevel@tonic-gate if ((iocp->ioc_count != TRANSPARENT)) {
22820Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL);
22830Sstevel@tonic-gate ret = DONAME_FAIL;
22840Sstevel@tonic-gate break;
22850Sstevel@tonic-gate }
22860Sstevel@tonic-gate
22870Sstevel@tonic-gate cqp = (struct copyreq *)mp->b_rptr;
22880Sstevel@tonic-gate cqp->cq_private = mp->b_cont;
22890Sstevel@tonic-gate cqp->cq_addr = (caddr_t)*(intptr_t *)mp->b_cont->b_rptr;
22900Sstevel@tonic-gate mp->b_cont = NULL;
22910Sstevel@tonic-gate cqp->cq_size = SIZEOF_STRUCT(strbuf, iocp->ioc_flag);
22920Sstevel@tonic-gate cqp->cq_flag = 0;
22930Sstevel@tonic-gate mp->b_datap->db_type = M_COPYIN;
22940Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct copyreq);
22950Sstevel@tonic-gate qreply(q, mp);
22960Sstevel@tonic-gate ret = DONAME_CONT;
22970Sstevel@tonic-gate break;
22980Sstevel@tonic-gate
22990Sstevel@tonic-gate case M_IOCDATA:
23000Sstevel@tonic-gate csp = (struct copyresp *)mp->b_rptr;
23010Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
23020Sstevel@tonic-gate cqp = (struct copyreq *)mp->b_rptr;
23030Sstevel@tonic-gate if ((csp->cp_cmd != TI_GETMYNAME) &&
23040Sstevel@tonic-gate (csp->cp_cmd != TI_GETPEERNAME)) {
23050Sstevel@tonic-gate cmn_err(CE_WARN, "ti_doname: bad M_IOCDATA command\n");
23060Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL);
23070Sstevel@tonic-gate ret = DONAME_FAIL;
23080Sstevel@tonic-gate break;
23090Sstevel@tonic-gate }
23100Sstevel@tonic-gate if (csp->cp_rval) { /* error */
23110Sstevel@tonic-gate freemsg(csp->cp_private);
23120Sstevel@tonic-gate freemsg(mp);
23130Sstevel@tonic-gate ret = DONAME_FAIL;
23140Sstevel@tonic-gate break;
23150Sstevel@tonic-gate }
23160Sstevel@tonic-gate ASSERT(csp->cp_private != NULL);
23170Sstevel@tonic-gate getpeer = csp->cp_cmd == TI_GETPEERNAME;
23180Sstevel@tonic-gate if (getpeer)
23190Sstevel@tonic-gate mutex_enter(&tp->tim_mutex);
23200Sstevel@tonic-gate if (csp->cp_private->b_cont == NULL) { /* got strbuf */
23210Sstevel@tonic-gate ASSERT(mp->b_cont);
23220Sstevel@tonic-gate STRUCT_SET_HANDLE(sb, iocp->ioc_flag,
23230Sstevel@tonic-gate (void *)mp->b_cont->b_rptr);
23240Sstevel@tonic-gate if (getpeer) {
23250Sstevel@tonic-gate if (tp->tim_peerlen == 0) {
23260Sstevel@tonic-gate /* copy just strbuf */
23270Sstevel@tonic-gate STRUCT_FSET(sb, len, 0);
23280Sstevel@tonic-gate } else if (tp->tim_peerlen >
23290Sstevel@tonic-gate STRUCT_FGET(sb, maxlen)) {
23300Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
23310Sstevel@tonic-gate miocnak(q, mp, 0, ENAMETOOLONG);
23320Sstevel@tonic-gate ret = DONAME_FAIL;
23330Sstevel@tonic-gate break;
23340Sstevel@tonic-gate } else {
23350Sstevel@tonic-gate /* copy buffer */
23360Sstevel@tonic-gate STRUCT_FSET(sb, len, tp->tim_peerlen);
23370Sstevel@tonic-gate }
23380Sstevel@tonic-gate } else {
23390Sstevel@tonic-gate if (tp->tim_mylen == 0) {
23400Sstevel@tonic-gate /* copy just strbuf */
23410Sstevel@tonic-gate STRUCT_FSET(sb, len, 0);
23420Sstevel@tonic-gate } else if (tp->tim_mylen >
23430Sstevel@tonic-gate STRUCT_FGET(sb, maxlen)) {
23440Sstevel@tonic-gate freemsg(csp->cp_private);
23450Sstevel@tonic-gate miocnak(q, mp, 0, ENAMETOOLONG);
23460Sstevel@tonic-gate ret = DONAME_FAIL;
23470Sstevel@tonic-gate break;
23480Sstevel@tonic-gate } else {
23490Sstevel@tonic-gate /* copy buffer */
23500Sstevel@tonic-gate STRUCT_FSET(sb, len, tp->tim_mylen);
23510Sstevel@tonic-gate }
23520Sstevel@tonic-gate }
23530Sstevel@tonic-gate csp->cp_private->b_cont = mp->b_cont;
23540Sstevel@tonic-gate mp->b_cont = NULL;
23550Sstevel@tonic-gate }
23560Sstevel@tonic-gate STRUCT_SET_HANDLE(sb, iocp->ioc_flag,
23570Sstevel@tonic-gate (void *)csp->cp_private->b_cont->b_rptr);
23580Sstevel@tonic-gate if (STRUCT_FGET(sb, len) == 0) {
23590Sstevel@tonic-gate /*
23600Sstevel@tonic-gate * restore strbuf.len
23610Sstevel@tonic-gate */
23620Sstevel@tonic-gate if (getpeer)
23630Sstevel@tonic-gate STRUCT_FSET(sb, len, tp->tim_peerlen);
23640Sstevel@tonic-gate else
23650Sstevel@tonic-gate STRUCT_FSET(sb, len, tp->tim_mylen);
23660Sstevel@tonic-gate
23670Sstevel@tonic-gate if (getpeer)
23680Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
23690Sstevel@tonic-gate if (STRUCT_FGET(sb, maxlen) == 0) {
23700Sstevel@tonic-gate
23710Sstevel@tonic-gate /*
23720Sstevel@tonic-gate * ack the ioctl
23730Sstevel@tonic-gate */
23740Sstevel@tonic-gate freemsg(csp->cp_private);
23750Sstevel@tonic-gate tim_ioctl_send_reply(q, mp, NULL);
23760Sstevel@tonic-gate ret = DONAME_DONE;
23770Sstevel@tonic-gate break;
23780Sstevel@tonic-gate }
23790Sstevel@tonic-gate
23800Sstevel@tonic-gate if ((bp = allocb(STRUCT_SIZE(sb), BPRI_MED)) == NULL) {
23810Sstevel@tonic-gate
23820Sstevel@tonic-gate tilog(
23830Sstevel@tonic-gate "ti_doname: allocb failed no recovery attempt\n", 0);
23840Sstevel@tonic-gate
23850Sstevel@tonic-gate freemsg(csp->cp_private);
23860Sstevel@tonic-gate miocnak(q, mp, 0, EAGAIN);
23870Sstevel@tonic-gate ret = DONAME_FAIL;
23880Sstevel@tonic-gate break;
23890Sstevel@tonic-gate }
23900Sstevel@tonic-gate bp->b_wptr += STRUCT_SIZE(sb);
23910Sstevel@tonic-gate bcopy(STRUCT_BUF(sb), bp->b_rptr, STRUCT_SIZE(sb));
23920Sstevel@tonic-gate cqp->cq_addr =
23930Sstevel@tonic-gate (caddr_t)*(intptr_t *)csp->cp_private->b_rptr;
23940Sstevel@tonic-gate cqp->cq_size = STRUCT_SIZE(sb);
23950Sstevel@tonic-gate cqp->cq_flag = 0;
23960Sstevel@tonic-gate mp->b_datap->db_type = M_COPYOUT;
23970Sstevel@tonic-gate mp->b_cont = bp;
23980Sstevel@tonic-gate STRUCT_FSET(sb, len, 0);
23990Sstevel@tonic-gate STRUCT_FSET(sb, maxlen, 0); /* ack next time around */
24000Sstevel@tonic-gate qreply(q, mp);
24010Sstevel@tonic-gate ret = DONAME_CONT;
24020Sstevel@tonic-gate break;
24030Sstevel@tonic-gate }
24040Sstevel@tonic-gate
24050Sstevel@tonic-gate /*
24060Sstevel@tonic-gate * copy the address to the user
24070Sstevel@tonic-gate */
24080Sstevel@tonic-gate if ((bp = allocb((size_t)STRUCT_FGET(sb, len), BPRI_MED))
24090Sstevel@tonic-gate == NULL) {
24100Sstevel@tonic-gate if (getpeer)
24110Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
24120Sstevel@tonic-gate
24130Sstevel@tonic-gate tilog("ti_doname: allocb failed no recovery attempt\n",
24140Sstevel@tonic-gate 0);
24150Sstevel@tonic-gate
24160Sstevel@tonic-gate freemsg(csp->cp_private);
24170Sstevel@tonic-gate miocnak(q, mp, 0, EAGAIN);
24180Sstevel@tonic-gate ret = DONAME_FAIL;
24190Sstevel@tonic-gate break;
24200Sstevel@tonic-gate }
24210Sstevel@tonic-gate bp->b_wptr += STRUCT_FGET(sb, len);
24220Sstevel@tonic-gate if (getpeer) {
24230Sstevel@tonic-gate bcopy(tp->tim_peername, bp->b_rptr,
24240Sstevel@tonic-gate STRUCT_FGET(sb, len));
24250Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
24260Sstevel@tonic-gate } else {
24270Sstevel@tonic-gate bcopy(tp->tim_myname, bp->b_rptr, STRUCT_FGET(sb, len));
24280Sstevel@tonic-gate }
24290Sstevel@tonic-gate cqp->cq_addr = (caddr_t)STRUCT_FGETP(sb, buf);
24300Sstevel@tonic-gate cqp->cq_size = STRUCT_FGET(sb, len);
24310Sstevel@tonic-gate cqp->cq_flag = 0;
24320Sstevel@tonic-gate mp->b_datap->db_type = M_COPYOUT;
24330Sstevel@tonic-gate mp->b_cont = bp;
24340Sstevel@tonic-gate STRUCT_FSET(sb, len, 0); /* copy the strbuf next time around */
24350Sstevel@tonic-gate qreply(q, mp);
24360Sstevel@tonic-gate ret = DONAME_CONT;
24370Sstevel@tonic-gate break;
24380Sstevel@tonic-gate
24390Sstevel@tonic-gate default:
24400Sstevel@tonic-gate tilog("ti_doname: freeing bad message type = %d\n",
24410Sstevel@tonic-gate mp->b_datap->db_type);
24420Sstevel@tonic-gate freemsg(mp);
24430Sstevel@tonic-gate ret = DONAME_FAIL;
24440Sstevel@tonic-gate break;
24450Sstevel@tonic-gate }
24460Sstevel@tonic-gate return (ret);
24470Sstevel@tonic-gate }
24480Sstevel@tonic-gate
24490Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
24500Sstevel@tonic-gate
24510Sstevel@tonic-gate /*
24520Sstevel@tonic-gate * Fill in the address of a connectionless data packet if a connect
24530Sstevel@tonic-gate * had been done on this endpoint.
24540Sstevel@tonic-gate */
24550Sstevel@tonic-gate static mblk_t *
tim_filladdr(queue_t * q,mblk_t * mp,boolean_t dorecover)24560Sstevel@tonic-gate tim_filladdr(queue_t *q, mblk_t *mp, boolean_t dorecover)
24570Sstevel@tonic-gate {
24580Sstevel@tonic-gate mblk_t *bp;
24590Sstevel@tonic-gate struct tim_tim *tp;
24600Sstevel@tonic-gate struct T_unitdata_req *up;
24610Sstevel@tonic-gate struct T_unitdata_req *nup;
24620Sstevel@tonic-gate size_t plen;
24630Sstevel@tonic-gate
24640Sstevel@tonic-gate tp = (struct tim_tim *)q->q_ptr;
24650Sstevel@tonic-gate if (mp->b_datap->db_type == M_DATA) {
24660Sstevel@tonic-gate mutex_enter(&tp->tim_mutex);
24670Sstevel@tonic-gate bp = allocb(sizeof (struct T_unitdata_req) + tp->tim_peerlen,
24680Sstevel@tonic-gate BPRI_MED);
24690Sstevel@tonic-gate if (bp != NULL) {
24700Sstevel@tonic-gate bp->b_datap->db_type = M_PROTO;
24710Sstevel@tonic-gate up = (struct T_unitdata_req *)bp->b_rptr;
24720Sstevel@tonic-gate up->PRIM_type = T_UNITDATA_REQ;
24730Sstevel@tonic-gate up->DEST_length = tp->tim_peerlen;
24740Sstevel@tonic-gate bp->b_wptr += sizeof (struct T_unitdata_req);
24750Sstevel@tonic-gate up->DEST_offset = sizeof (struct T_unitdata_req);
24760Sstevel@tonic-gate up->OPT_length = 0;
24770Sstevel@tonic-gate up->OPT_offset = 0;
24780Sstevel@tonic-gate if (tp->tim_peerlen > 0) {
24790Sstevel@tonic-gate bcopy(tp->tim_peername, bp->b_wptr,
24800Sstevel@tonic-gate tp->tim_peerlen);
24810Sstevel@tonic-gate bp->b_wptr += tp->tim_peerlen;
24820Sstevel@tonic-gate }
24830Sstevel@tonic-gate bp->b_cont = mp;
24840Sstevel@tonic-gate }
24850Sstevel@tonic-gate } else {
24860Sstevel@tonic-gate ASSERT(mp->b_datap->db_type == M_PROTO);
24870Sstevel@tonic-gate up = (struct T_unitdata_req *)mp->b_rptr;
24880Sstevel@tonic-gate ASSERT(up->PRIM_type == T_UNITDATA_REQ);
24890Sstevel@tonic-gate if (up->DEST_length != 0)
24900Sstevel@tonic-gate return (mp);
24910Sstevel@tonic-gate mutex_enter(&tp->tim_mutex);
24920Sstevel@tonic-gate bp = allocb(sizeof (struct T_unitdata_req) + up->OPT_length +
24930Sstevel@tonic-gate tp->tim_peerlen, BPRI_MED);
24940Sstevel@tonic-gate if (bp != NULL) {
24950Sstevel@tonic-gate bp->b_datap->db_type = M_PROTO;
24960Sstevel@tonic-gate nup = (struct T_unitdata_req *)bp->b_rptr;
24970Sstevel@tonic-gate nup->PRIM_type = T_UNITDATA_REQ;
24980Sstevel@tonic-gate nup->DEST_length = plen = tp->tim_peerlen;
24990Sstevel@tonic-gate bp->b_wptr += sizeof (struct T_unitdata_req);
25000Sstevel@tonic-gate nup->DEST_offset = sizeof (struct T_unitdata_req);
25010Sstevel@tonic-gate if (plen > 0) {
25020Sstevel@tonic-gate bcopy(tp->tim_peername, bp->b_wptr, plen);
25030Sstevel@tonic-gate bp->b_wptr += plen;
25040Sstevel@tonic-gate }
25050Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
25060Sstevel@tonic-gate if (up->OPT_length == 0) {
25070Sstevel@tonic-gate nup->OPT_length = 0;
25080Sstevel@tonic-gate nup->OPT_offset = 0;
25090Sstevel@tonic-gate } else {
25100Sstevel@tonic-gate nup->OPT_length = up->OPT_length;
25110Sstevel@tonic-gate nup->OPT_offset =
25120Sstevel@tonic-gate sizeof (struct T_unitdata_req) + plen;
25130Sstevel@tonic-gate bcopy((mp->b_wptr + up->OPT_offset), bp->b_wptr,
25140Sstevel@tonic-gate up->OPT_length);
25150Sstevel@tonic-gate bp->b_wptr += up->OPT_length;
25160Sstevel@tonic-gate }
25170Sstevel@tonic-gate bp->b_cont = mp->b_cont;
25180Sstevel@tonic-gate mp->b_cont = NULL;
25190Sstevel@tonic-gate freeb(mp);
25200Sstevel@tonic-gate return (bp);
25210Sstevel@tonic-gate }
25220Sstevel@tonic-gate }
25230Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tp->tim_mutex));
25240Sstevel@tonic-gate if (bp == NULL && dorecover) {
25250Sstevel@tonic-gate tim_recover(q, mp,
25260Sstevel@tonic-gate sizeof (struct T_unitdata_req) + tp->tim_peerlen);
25270Sstevel@tonic-gate }
25280Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
25290Sstevel@tonic-gate return (bp);
25300Sstevel@tonic-gate }
25310Sstevel@tonic-gate
25320Sstevel@tonic-gate static void
tim_addlink(struct tim_tim * tp)25330Sstevel@tonic-gate tim_addlink(struct tim_tim *tp)
25340Sstevel@tonic-gate {
25350Sstevel@tonic-gate struct tim_tim **tpp;
25360Sstevel@tonic-gate struct tim_tim *next;
25370Sstevel@tonic-gate
25380Sstevel@tonic-gate tpp = &tim_hash[TIM_HASH(tp->tim_acceptor)];
25390Sstevel@tonic-gate rw_enter(&tim_list_rwlock, RW_WRITER);
25400Sstevel@tonic-gate
25410Sstevel@tonic-gate if ((next = *tpp) != NULL)
25420Sstevel@tonic-gate next->tim_ptpn = &tp->tim_next;
25430Sstevel@tonic-gate tp->tim_next = next;
25440Sstevel@tonic-gate tp->tim_ptpn = tpp;
25450Sstevel@tonic-gate *tpp = tp;
25460Sstevel@tonic-gate
25470Sstevel@tonic-gate tim_cnt++;
25480Sstevel@tonic-gate
25490Sstevel@tonic-gate rw_exit(&tim_list_rwlock);
25500Sstevel@tonic-gate }
25510Sstevel@tonic-gate
25520Sstevel@tonic-gate static void
tim_dellink(struct tim_tim * tp)25530Sstevel@tonic-gate tim_dellink(struct tim_tim *tp)
25540Sstevel@tonic-gate {
25550Sstevel@tonic-gate struct tim_tim *next;
25560Sstevel@tonic-gate
25570Sstevel@tonic-gate rw_enter(&tim_list_rwlock, RW_WRITER);
25580Sstevel@tonic-gate
25590Sstevel@tonic-gate if ((next = tp->tim_next) != NULL)
25600Sstevel@tonic-gate next->tim_ptpn = tp->tim_ptpn;
25610Sstevel@tonic-gate *(tp->tim_ptpn) = next;
25620Sstevel@tonic-gate
25630Sstevel@tonic-gate tim_cnt--;
25640Sstevel@tonic-gate
25650Sstevel@tonic-gate rw_exit(&tim_list_rwlock);
25660Sstevel@tonic-gate }
25670Sstevel@tonic-gate
25680Sstevel@tonic-gate static struct tim_tim *
tim_findlink(t_uscalar_t id)25690Sstevel@tonic-gate tim_findlink(t_uscalar_t id)
25700Sstevel@tonic-gate {
25710Sstevel@tonic-gate struct tim_tim *tp;
25720Sstevel@tonic-gate
25730Sstevel@tonic-gate ASSERT(rw_lock_held(&tim_list_rwlock));
25740Sstevel@tonic-gate
25750Sstevel@tonic-gate for (tp = tim_hash[TIM_HASH(id)]; tp != NULL; tp = tp->tim_next) {
25760Sstevel@tonic-gate if (tp->tim_acceptor == id) {
25770Sstevel@tonic-gate break;
25780Sstevel@tonic-gate }
25790Sstevel@tonic-gate }
25800Sstevel@tonic-gate return (tp);
25810Sstevel@tonic-gate }
25820Sstevel@tonic-gate
25830Sstevel@tonic-gate /* ONC_PLUS EXTRACT START */
25840Sstevel@tonic-gate static void
tim_recover(queue_t * q,mblk_t * mp,t_scalar_t size)25850Sstevel@tonic-gate tim_recover(queue_t *q, mblk_t *mp, t_scalar_t size)
25860Sstevel@tonic-gate {
25870Sstevel@tonic-gate struct tim_tim *tp;
25880Sstevel@tonic-gate bufcall_id_t bid;
25890Sstevel@tonic-gate timeout_id_t tid;
25900Sstevel@tonic-gate
25910Sstevel@tonic-gate tp = (struct tim_tim *)q->q_ptr;
25920Sstevel@tonic-gate
25930Sstevel@tonic-gate /*
25940Sstevel@tonic-gate * Avoid re-enabling the queue.
25950Sstevel@tonic-gate */
25960Sstevel@tonic-gate if (mp->b_datap->db_type == M_PCPROTO)
25970Sstevel@tonic-gate mp->b_datap->db_type = M_PROTO;
25980Sstevel@tonic-gate noenable(q);
25990Sstevel@tonic-gate (void) putbq(q, mp);
26000Sstevel@tonic-gate
26010Sstevel@tonic-gate /*
26020Sstevel@tonic-gate * Make sure there is at most one outstanding request per queue.
26030Sstevel@tonic-gate */
26040Sstevel@tonic-gate if (q->q_flag & QREADR) {
26050Sstevel@tonic-gate if (tp->tim_rtimoutid || tp->tim_rbufcid)
26060Sstevel@tonic-gate return;
26070Sstevel@tonic-gate } else {
26080Sstevel@tonic-gate if (tp->tim_wtimoutid || tp->tim_wbufcid)
26090Sstevel@tonic-gate return;
26100Sstevel@tonic-gate }
26110Sstevel@tonic-gate if (!(bid = qbufcall(RD(q), (size_t)size, BPRI_MED, tim_buffer, q))) {
26120Sstevel@tonic-gate tid = qtimeout(RD(q), tim_timer, q, TIMWAIT);
26130Sstevel@tonic-gate if (q->q_flag & QREADR)
26140Sstevel@tonic-gate tp->tim_rtimoutid = tid;
26150Sstevel@tonic-gate else
26160Sstevel@tonic-gate tp->tim_wtimoutid = tid;
26170Sstevel@tonic-gate } else {
26180Sstevel@tonic-gate if (q->q_flag & QREADR)
26190Sstevel@tonic-gate tp->tim_rbufcid = bid;
26200Sstevel@tonic-gate else
26210Sstevel@tonic-gate tp->tim_wbufcid = bid;
26220Sstevel@tonic-gate }
26230Sstevel@tonic-gate }
26240Sstevel@tonic-gate
26250Sstevel@tonic-gate /*
26261261Sgeorges * Timod is waiting on a downstream ioctl reply, come back soon
26271261Sgeorges * to reschedule the write side service routine, which will check
26281261Sgeorges * if the ioctl is done and another can proceed.
26291261Sgeorges */
26301261Sgeorges static void
tim_ioctl_retry(queue_t * q)26311261Sgeorges tim_ioctl_retry(queue_t *q)
26321261Sgeorges {
26331261Sgeorges struct tim_tim *tp;
26341261Sgeorges
26351261Sgeorges tp = (struct tim_tim *)q->q_ptr;
26361261Sgeorges
26371261Sgeorges /*
26381261Sgeorges * Make sure there is at most one outstanding request per wqueue.
26391261Sgeorges */
26401261Sgeorges if (tp->tim_wtimoutid || tp->tim_wbufcid)
26411261Sgeorges return;
26421261Sgeorges
26431261Sgeorges tp->tim_wtimoutid = qtimeout(RD(q), tim_timer, q, TIMIOCWAIT);
26441261Sgeorges }
26451261Sgeorges
26461261Sgeorges /*
26470Sstevel@tonic-gate * Inspect the data on read queues starting from read queues passed as
26480Sstevel@tonic-gate * paramter (timod read queue) and traverse until
26490Sstevel@tonic-gate * q_next is NULL (stream head). Look for a TPI T_EXDATA_IND message
26500Sstevel@tonic-gate * reutrn 1 if found, 0 if not found.
26510Sstevel@tonic-gate */
26520Sstevel@tonic-gate static int
ti_expind_on_rdqueues(queue_t * rq)26530Sstevel@tonic-gate ti_expind_on_rdqueues(queue_t *rq)
26540Sstevel@tonic-gate {
26550Sstevel@tonic-gate mblk_t *bp;
26560Sstevel@tonic-gate queue_t *q;
26570Sstevel@tonic-gate
26580Sstevel@tonic-gate q = rq;
26590Sstevel@tonic-gate /*
26600Sstevel@tonic-gate * We are going to walk q_next, so protect stream from plumbing
26610Sstevel@tonic-gate * changes.
26620Sstevel@tonic-gate */
26630Sstevel@tonic-gate claimstr(q);
26640Sstevel@tonic-gate do {
26650Sstevel@tonic-gate /*
26660Sstevel@tonic-gate * Hold QLOCK while referencing data on queues
26670Sstevel@tonic-gate */
26680Sstevel@tonic-gate mutex_enter(QLOCK(rq));
26690Sstevel@tonic-gate bp = rq->q_first;
26700Sstevel@tonic-gate while (bp != NULL) {
26710Sstevel@tonic-gate /*
26720Sstevel@tonic-gate * Walk the messages on the queue looking
26730Sstevel@tonic-gate * for a possible T_EXDATA_IND
26740Sstevel@tonic-gate */
26750Sstevel@tonic-gate if ((bp->b_datap->db_type == M_PROTO) &&
26760Sstevel@tonic-gate ((bp->b_wptr - bp->b_rptr) >=
26778778SErik.Nordmark@Sun.COM sizeof (struct T_exdata_ind)) &&
26780Sstevel@tonic-gate (((struct T_exdata_ind *)bp->b_rptr)->PRIM_type
26798778SErik.Nordmark@Sun.COM == T_EXDATA_IND)) {
26800Sstevel@tonic-gate /* bp is T_EXDATA_IND */
26810Sstevel@tonic-gate mutex_exit(QLOCK(rq));
26820Sstevel@tonic-gate releasestr(q); /* decrement sd_refcnt */
26830Sstevel@tonic-gate return (1); /* expdata is on a read queue */
26840Sstevel@tonic-gate }
26850Sstevel@tonic-gate bp = bp->b_next; /* next message */
26860Sstevel@tonic-gate }
26870Sstevel@tonic-gate mutex_exit(QLOCK(rq));
26880Sstevel@tonic-gate rq = rq->q_next; /* next upstream queue */
26890Sstevel@tonic-gate } while (rq != NULL);
26900Sstevel@tonic-gate releasestr(q);
26910Sstevel@tonic-gate return (0); /* no expdata on read queues */
26920Sstevel@tonic-gate }
26930Sstevel@tonic-gate
26940Sstevel@tonic-gate /* ONC_PLUS EXTRACT END */
26950Sstevel@tonic-gate static void
tim_tcap_timer(void * q_ptr)26960Sstevel@tonic-gate tim_tcap_timer(void *q_ptr)
26970Sstevel@tonic-gate {
26980Sstevel@tonic-gate queue_t *q = (queue_t *)q_ptr;
26990Sstevel@tonic-gate struct tim_tim *tp = (struct tim_tim *)q->q_ptr;
27000Sstevel@tonic-gate
27010Sstevel@tonic-gate ASSERT(tp != NULL && tp->tim_tcap_timoutid != 0);
27020Sstevel@tonic-gate ASSERT((tp->tim_flags & TI_CAP_RECVD) != 0);
27030Sstevel@tonic-gate
27040Sstevel@tonic-gate tp->tim_tcap_timoutid = 0;
27050Sstevel@tonic-gate TILOG("tim_tcap_timer: fired\n", 0);
27060Sstevel@tonic-gate tim_tcap_genreply(q, tp);
27070Sstevel@tonic-gate }
27080Sstevel@tonic-gate
27090Sstevel@tonic-gate /*
27100Sstevel@tonic-gate * tim_tcap_genreply() is called either from timeout routine or when
27110Sstevel@tonic-gate * T_ERROR_ACK is received. In both cases it means that underlying
27120Sstevel@tonic-gate * transport doesn't provide T_CAPABILITY_REQ.
27130Sstevel@tonic-gate */
27140Sstevel@tonic-gate static void
tim_tcap_genreply(queue_t * q,struct tim_tim * tp)27150Sstevel@tonic-gate tim_tcap_genreply(queue_t *q, struct tim_tim *tp)
27160Sstevel@tonic-gate {
27170Sstevel@tonic-gate mblk_t *mp = tp->tim_iocsave;
27180Sstevel@tonic-gate struct iocblk *iocbp;
27190Sstevel@tonic-gate
27200Sstevel@tonic-gate TILOG("timodrproc: tim_tcap_genreply\n", 0);
27210Sstevel@tonic-gate
27220Sstevel@tonic-gate ASSERT(tp == (struct tim_tim *)q->q_ptr);
27230Sstevel@tonic-gate ASSERT(mp != NULL);
27240Sstevel@tonic-gate
27250Sstevel@tonic-gate iocbp = (struct iocblk *)mp->b_rptr;
27260Sstevel@tonic-gate ASSERT(iocbp != NULL);
27270Sstevel@tonic-gate ASSERT(MBLKL(mp) == sizeof (struct iocblk));
27280Sstevel@tonic-gate ASSERT(iocbp->ioc_cmd == TI_CAPABILITY);
27290Sstevel@tonic-gate ASSERT(mp->b_cont == NULL);
27300Sstevel@tonic-gate
27310Sstevel@tonic-gate /* Save this information permanently in the module */
27320Sstevel@tonic-gate PI_PROVLOCK(tp->tim_provinfo);
27330Sstevel@tonic-gate if (tp->tim_provinfo->tpi_capability == PI_DONTKNOW)
27340Sstevel@tonic-gate tp->tim_provinfo->tpi_capability = PI_NO;
27350Sstevel@tonic-gate PI_PROVUNLOCK(tp->tim_provinfo);
27360Sstevel@tonic-gate
27370Sstevel@tonic-gate if (tp->tim_tcap_timoutid != 0) {
27380Sstevel@tonic-gate (void) quntimeout(q, tp->tim_tcap_timoutid);
27390Sstevel@tonic-gate tp->tim_tcap_timoutid = 0;
27400Sstevel@tonic-gate }
27410Sstevel@tonic-gate
27420Sstevel@tonic-gate if ((tp->tim_flags & CAP_WANTS_INFO) != 0) {
27430Sstevel@tonic-gate /* Send T_INFO_REQ down */
27440Sstevel@tonic-gate mblk_t *tirmp = tpi_ack_alloc(NULL,
27450Sstevel@tonic-gate sizeof (struct T_info_req), M_PCPROTO, T_INFO_REQ);
27460Sstevel@tonic-gate
27470Sstevel@tonic-gate if (tirmp != NULL) {
27480Sstevel@tonic-gate /* Emulate TC1_INFO */
27490Sstevel@tonic-gate TILOG("emulate_tcap_ioc_req: sending T_INFO_REQ\n", 0);
27500Sstevel@tonic-gate tp->tim_flags |= WAIT_IOCINFOACK;
27510Sstevel@tonic-gate putnext(WR(q), tirmp);
27520Sstevel@tonic-gate } else {
27530Sstevel@tonic-gate tilog("emulate_tcap_req: allocb fail, "
27540Sstevel@tonic-gate "no recovery attmpt\n", 0);
27550Sstevel@tonic-gate tp->tim_iocsave = NULL;
27560Sstevel@tonic-gate tp->tim_saved_prim = -1;
27570Sstevel@tonic-gate tp->tim_flags &= ~(TI_CAP_RECVD | WAITIOCACK |
27580Sstevel@tonic-gate CAP_WANTS_INFO | WAIT_IOCINFOACK);
27590Sstevel@tonic-gate miocnak(q, mp, 0, ENOMEM);
27600Sstevel@tonic-gate }
27610Sstevel@tonic-gate } else {
27620Sstevel@tonic-gate /* Reply immediately */
27630Sstevel@tonic-gate mblk_t *ackmp = tpi_ack_alloc(NULL,
27640Sstevel@tonic-gate sizeof (struct T_capability_ack), M_PCPROTO,
27650Sstevel@tonic-gate T_CAPABILITY_ACK);
27660Sstevel@tonic-gate
27670Sstevel@tonic-gate mp->b_cont = ackmp;
27680Sstevel@tonic-gate
27690Sstevel@tonic-gate if (ackmp != NULL) {
27700Sstevel@tonic-gate ((struct T_capability_ack *)
27710Sstevel@tonic-gate ackmp->b_rptr)->CAP_bits1 = 0;
27720Sstevel@tonic-gate tim_ioctl_send_reply(q, mp, ackmp);
27730Sstevel@tonic-gate tp->tim_iocsave = NULL;
27740Sstevel@tonic-gate tp->tim_saved_prim = -1;
27750Sstevel@tonic-gate tp->tim_flags &= ~(WAITIOCACK | WAIT_IOCINFOACK |
27760Sstevel@tonic-gate TI_CAP_RECVD | CAP_WANTS_INFO);
27770Sstevel@tonic-gate } else {
27780Sstevel@tonic-gate tilog("timodwproc:allocb failed no "
27790Sstevel@tonic-gate "recovery attempt\n", 0);
27800Sstevel@tonic-gate tp->tim_iocsave = NULL;
27810Sstevel@tonic-gate tp->tim_saved_prim = -1;
27820Sstevel@tonic-gate tp->tim_flags &= ~(TI_CAP_RECVD | WAITIOCACK |
27830Sstevel@tonic-gate CAP_WANTS_INFO | WAIT_IOCINFOACK);
27840Sstevel@tonic-gate miocnak(q, mp, 0, ENOMEM);
27850Sstevel@tonic-gate }
27860Sstevel@tonic-gate }
27870Sstevel@tonic-gate }
27880Sstevel@tonic-gate
27890Sstevel@tonic-gate
27900Sstevel@tonic-gate static void
tim_ioctl_send_reply(queue_t * q,mblk_t * ioc_mp,mblk_t * mp)27910Sstevel@tonic-gate tim_ioctl_send_reply(queue_t *q, mblk_t *ioc_mp, mblk_t *mp)
27920Sstevel@tonic-gate {
27930Sstevel@tonic-gate struct iocblk *iocbp;
27940Sstevel@tonic-gate
27950Sstevel@tonic-gate ASSERT(q != NULL && ioc_mp != NULL);
27960Sstevel@tonic-gate
27970Sstevel@tonic-gate ioc_mp->b_datap->db_type = M_IOCACK;
27980Sstevel@tonic-gate if (mp != NULL)
27990Sstevel@tonic-gate mp->b_datap->db_type = M_DATA;
28000Sstevel@tonic-gate
28010Sstevel@tonic-gate if (ioc_mp->b_cont != mp) {
28020Sstevel@tonic-gate /* It is safe to call freemsg for NULL pointers */
28030Sstevel@tonic-gate freemsg(ioc_mp->b_cont);
28040Sstevel@tonic-gate ioc_mp->b_cont = mp;
28050Sstevel@tonic-gate }
28060Sstevel@tonic-gate iocbp = (struct iocblk *)ioc_mp->b_rptr;
28070Sstevel@tonic-gate iocbp->ioc_error = 0;
28080Sstevel@tonic-gate iocbp->ioc_rval = 0;
28090Sstevel@tonic-gate /*
28100Sstevel@tonic-gate * All ioctl's may return more data than was specified by
28110Sstevel@tonic-gate * count arg. For TI_CAPABILITY count is treated as maximum data size.
28120Sstevel@tonic-gate */
28130Sstevel@tonic-gate if (mp == NULL)
28140Sstevel@tonic-gate iocbp->ioc_count = 0;
28150Sstevel@tonic-gate else if (iocbp->ioc_cmd != TI_CAPABILITY)
28160Sstevel@tonic-gate iocbp->ioc_count = msgsize(mp);
28170Sstevel@tonic-gate else {
28180Sstevel@tonic-gate iocbp->ioc_count = MIN(MBLKL(mp), iocbp->ioc_count);
28190Sstevel@tonic-gate /* Truncate message if too large */
28200Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + iocbp->ioc_count;
28210Sstevel@tonic-gate }
28220Sstevel@tonic-gate
28230Sstevel@tonic-gate TILOG("iosendreply: ioc_cmd = %d, ", iocbp->ioc_cmd);
28240Sstevel@tonic-gate putnext(RD(q), ioc_mp);
28250Sstevel@tonic-gate }
28260Sstevel@tonic-gate
28270Sstevel@tonic-gate /*
28280Sstevel@tonic-gate * Send M_IOCACK for errors.
28290Sstevel@tonic-gate */
28300Sstevel@tonic-gate static void
tim_send_ioc_error_ack(queue_t * q,struct tim_tim * tp,mblk_t * mp)28310Sstevel@tonic-gate tim_send_ioc_error_ack(queue_t *q, struct tim_tim *tp, mblk_t *mp)
28320Sstevel@tonic-gate {
28330Sstevel@tonic-gate struct T_error_ack *tea = (struct T_error_ack *)mp->b_rptr;
28340Sstevel@tonic-gate t_scalar_t error_prim;
28350Sstevel@tonic-gate
28360Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct T_error_ack);
28370Sstevel@tonic-gate ASSERT(mp->b_wptr <= mp->b_datap->db_lim);
28380Sstevel@tonic-gate error_prim = tea->ERROR_prim;
28390Sstevel@tonic-gate
28400Sstevel@tonic-gate ASSERT(tp->tim_iocsave != NULL);
28410Sstevel@tonic-gate ASSERT(tp->tim_iocsave->b_cont != mp);
28420Sstevel@tonic-gate
28430Sstevel@tonic-gate /* Always send this to the read side of the queue */
28440Sstevel@tonic-gate q = RD(q);
28450Sstevel@tonic-gate
28460Sstevel@tonic-gate TILOG("tim_send_ioc_error_ack: prim = %d\n", tp->tim_saved_prim);
28470Sstevel@tonic-gate
28480Sstevel@tonic-gate if (tp->tim_saved_prim != error_prim) {
28490Sstevel@tonic-gate putnext(q, mp);
28500Sstevel@tonic-gate } else if (error_prim == T_CAPABILITY_REQ) {
28510Sstevel@tonic-gate TILOG("timodrproc: T_ERROR_ACK/T_CAPABILITY_REQ\n", 0);
28520Sstevel@tonic-gate ASSERT(tp->tim_iocsave->b_cont == NULL);
28530Sstevel@tonic-gate
28540Sstevel@tonic-gate tim_tcap_genreply(q, tp);
28550Sstevel@tonic-gate freemsg(mp);
28560Sstevel@tonic-gate } else {
28570Sstevel@tonic-gate struct iocblk *iocbp = (struct iocblk *)tp->tim_iocsave->b_rptr;
28580Sstevel@tonic-gate
28590Sstevel@tonic-gate TILOG("tim_send_ioc_error_ack: T_ERROR_ACK: prim %d\n",
28600Sstevel@tonic-gate error_prim);
28610Sstevel@tonic-gate ASSERT(tp->tim_iocsave->b_cont == NULL);
28620Sstevel@tonic-gate
28630Sstevel@tonic-gate switch (error_prim) {
28640Sstevel@tonic-gate default:
28650Sstevel@tonic-gate TILOG("timodrproc: Unknown T_ERROR_ACK: tlierror %d\n",
28660Sstevel@tonic-gate tea->TLI_error);
28670Sstevel@tonic-gate
28680Sstevel@tonic-gate putnext(q, mp);
28690Sstevel@tonic-gate break;
28700Sstevel@tonic-gate
28710Sstevel@tonic-gate case T_INFO_REQ:
28720Sstevel@tonic-gate case T_SVR4_OPTMGMT_REQ:
28730Sstevel@tonic-gate case T_OPTMGMT_REQ:
28740Sstevel@tonic-gate case O_T_BIND_REQ:
28750Sstevel@tonic-gate case T_BIND_REQ:
28760Sstevel@tonic-gate case T_UNBIND_REQ:
28770Sstevel@tonic-gate case T_ADDR_REQ:
28780Sstevel@tonic-gate case T_CAPABILITY_REQ:
28790Sstevel@tonic-gate
28800Sstevel@tonic-gate TILOG("ioc_err_ack: T_ERROR_ACK: tlierror %x\n",
28810Sstevel@tonic-gate tea->TLI_error);
28820Sstevel@tonic-gate
28830Sstevel@tonic-gate /* get saved ioctl msg and set values */
28840Sstevel@tonic-gate iocbp->ioc_count = 0;
28850Sstevel@tonic-gate iocbp->ioc_error = 0;
28860Sstevel@tonic-gate iocbp->ioc_rval = tea->TLI_error;
28870Sstevel@tonic-gate if (iocbp->ioc_rval == TSYSERR)
28880Sstevel@tonic-gate iocbp->ioc_rval |= tea->UNIX_error << 8;
28890Sstevel@tonic-gate tp->tim_iocsave->b_datap->db_type = M_IOCACK;
28900Sstevel@tonic-gate freemsg(mp);
28910Sstevel@tonic-gate putnext(q, tp->tim_iocsave);
28920Sstevel@tonic-gate tp->tim_iocsave = NULL;
28930Sstevel@tonic-gate tp->tim_saved_prim = -1;
28940Sstevel@tonic-gate tp->tim_flags &= ~(WAITIOCACK | TI_CAP_RECVD |
28950Sstevel@tonic-gate CAP_WANTS_INFO | WAIT_IOCINFOACK);
28960Sstevel@tonic-gate break;
28970Sstevel@tonic-gate }
28980Sstevel@tonic-gate }
28990Sstevel@tonic-gate }
29000Sstevel@tonic-gate
29010Sstevel@tonic-gate /*
29020Sstevel@tonic-gate * Send reply to a usual message or ioctl message upstream.
29030Sstevel@tonic-gate * Should be called from the read side only.
29040Sstevel@tonic-gate */
29050Sstevel@tonic-gate static void
tim_send_reply(queue_t * q,mblk_t * mp,struct tim_tim * tp,t_scalar_t prim)29060Sstevel@tonic-gate tim_send_reply(queue_t *q, mblk_t *mp, struct tim_tim *tp, t_scalar_t prim)
29070Sstevel@tonic-gate {
29080Sstevel@tonic-gate ASSERT(mp != NULL && q != NULL && tp != NULL);
29090Sstevel@tonic-gate ASSERT(q == RD(q));
29100Sstevel@tonic-gate
29110Sstevel@tonic-gate /* Restore db_type - recover() might have changed it */
29120Sstevel@tonic-gate mp->b_datap->db_type = M_PCPROTO;
29130Sstevel@tonic-gate
29140Sstevel@tonic-gate if (((tp->tim_flags & WAITIOCACK) == 0) || (tp->tim_saved_prim != prim))
29150Sstevel@tonic-gate putnext(q, mp);
29160Sstevel@tonic-gate else {
29170Sstevel@tonic-gate ASSERT(tp->tim_iocsave != NULL);
29180Sstevel@tonic-gate tim_ioctl_send_reply(q, tp->tim_iocsave, mp);
29190Sstevel@tonic-gate tp->tim_iocsave = NULL;
29200Sstevel@tonic-gate tp->tim_saved_prim = -1;
29210Sstevel@tonic-gate tp->tim_flags &= ~(WAITIOCACK | WAIT_IOCINFOACK |
29220Sstevel@tonic-gate TI_CAP_RECVD | CAP_WANTS_INFO);
29230Sstevel@tonic-gate }
29240Sstevel@tonic-gate }
29250Sstevel@tonic-gate
29260Sstevel@tonic-gate /*
29270Sstevel@tonic-gate * Reply to TI_SYNC reequest without sending anything downstream.
29280Sstevel@tonic-gate */
29290Sstevel@tonic-gate static void
tim_answer_ti_sync(queue_t * q,mblk_t * mp,struct tim_tim * tp,mblk_t * ackmp,uint32_t tsr_flags)29300Sstevel@tonic-gate tim_answer_ti_sync(queue_t *q, mblk_t *mp, struct tim_tim *tp,
29310Sstevel@tonic-gate mblk_t *ackmp, uint32_t tsr_flags)
29320Sstevel@tonic-gate {
29330Sstevel@tonic-gate struct ti_sync_ack *tsap;
29340Sstevel@tonic-gate
29350Sstevel@tonic-gate ASSERT(q != NULL && q == WR(q) && ackmp != NULL);
29360Sstevel@tonic-gate
29370Sstevel@tonic-gate tsap = (struct ti_sync_ack *)ackmp->b_rptr;
29380Sstevel@tonic-gate bzero(tsap, sizeof (struct ti_sync_ack));
29390Sstevel@tonic-gate ackmp->b_wptr = ackmp->b_rptr + sizeof (struct ti_sync_ack);
29400Sstevel@tonic-gate
29410Sstevel@tonic-gate if (tsr_flags == 0 ||
29420Sstevel@tonic-gate (tsr_flags & ~(TSRF_QLEN_REQ | TSRF_IS_EXP_IN_RCVBUF)) != 0) {
29430Sstevel@tonic-gate /*
29440Sstevel@tonic-gate * unsupported/bad flag setting
29450Sstevel@tonic-gate * or no flag set.
29460Sstevel@tonic-gate */
29470Sstevel@tonic-gate TILOG("timodwproc: unsupported/bad flag setting %x\n",
29480Sstevel@tonic-gate tsr_flags);
29490Sstevel@tonic-gate freemsg(ackmp);
29500Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL);
29510Sstevel@tonic-gate return;
29520Sstevel@tonic-gate }
29530Sstevel@tonic-gate
29540Sstevel@tonic-gate if ((tsr_flags & TSRF_QLEN_REQ) != 0)
29550Sstevel@tonic-gate tsap->tsa_qlen = tp->tim_backlog;
29560Sstevel@tonic-gate
29570Sstevel@tonic-gate if ((tsr_flags & TSRF_IS_EXP_IN_RCVBUF) != 0 &&
29580Sstevel@tonic-gate ti_expind_on_rdqueues(RD(q))) {
29590Sstevel@tonic-gate /*
29600Sstevel@tonic-gate * Expedited data is queued on
29610Sstevel@tonic-gate * the stream read side
29620Sstevel@tonic-gate */
29630Sstevel@tonic-gate tsap->tsa_flags |= TSAF_EXP_QUEUED;
29640Sstevel@tonic-gate }
29650Sstevel@tonic-gate
29660Sstevel@tonic-gate tim_ioctl_send_reply(q, mp, ackmp);
29670Sstevel@tonic-gate tp->tim_iocsave = NULL;
29680Sstevel@tonic-gate tp->tim_saved_prim = -1;
29690Sstevel@tonic-gate tp->tim_flags &= ~(WAITIOCACK | WAIT_IOCINFOACK |
29700Sstevel@tonic-gate TI_CAP_RECVD | CAP_WANTS_INFO);
29710Sstevel@tonic-gate }
29720Sstevel@tonic-gate
29730Sstevel@tonic-gate /*
29740Sstevel@tonic-gate * Send TPI message from IOCTL message, ssave original ioctl header and TPI
29750Sstevel@tonic-gate * message type. Should be called from write side only.
29760Sstevel@tonic-gate */
29770Sstevel@tonic-gate static void
tim_send_ioctl_tpi_msg(queue_t * q,mblk_t * mp,struct tim_tim * tp,struct iocblk * iocb)29780Sstevel@tonic-gate tim_send_ioctl_tpi_msg(queue_t *q, mblk_t *mp, struct tim_tim *tp,
29790Sstevel@tonic-gate struct iocblk *iocb)
29800Sstevel@tonic-gate {
29810Sstevel@tonic-gate mblk_t *tmp;
29820Sstevel@tonic-gate int ioc_cmd = iocb->ioc_cmd;
29830Sstevel@tonic-gate
29840Sstevel@tonic-gate ASSERT(q != NULL && mp != NULL && tp != NULL);
29850Sstevel@tonic-gate ASSERT(q == WR(q));
29860Sstevel@tonic-gate ASSERT(mp->b_cont != NULL);
29870Sstevel@tonic-gate
29880Sstevel@tonic-gate tp->tim_iocsave = mp;
29890Sstevel@tonic-gate tmp = mp->b_cont;
29900Sstevel@tonic-gate
29910Sstevel@tonic-gate mp->b_cont = NULL;
29920Sstevel@tonic-gate tp->tim_flags |= WAITIOCACK;
29930Sstevel@tonic-gate tp->tim_saved_prim = ((union T_primitives *)tmp->b_rptr)->type;
29940Sstevel@tonic-gate
29950Sstevel@tonic-gate /*
29960Sstevel@tonic-gate * For TI_GETINFO, the attached message is a T_INFO_REQ
29970Sstevel@tonic-gate * For TI_SYNC, we generate the T_INFO_REQ message above
29980Sstevel@tonic-gate * For TI_CAPABILITY the attached message is either
29990Sstevel@tonic-gate * T_CAPABILITY_REQ or T_INFO_REQ.
30000Sstevel@tonic-gate * Among TPI request messages possible,
30010Sstevel@tonic-gate * T_INFO_REQ/T_CAPABILITY_ACK messages are a M_PCPROTO, rest
30020Sstevel@tonic-gate * are M_PROTO
30030Sstevel@tonic-gate */
30040Sstevel@tonic-gate if (ioc_cmd == TI_GETINFO || ioc_cmd == TI_SYNC ||
30050Sstevel@tonic-gate ioc_cmd == TI_CAPABILITY) {
30060Sstevel@tonic-gate tmp->b_datap->db_type = M_PCPROTO;
30070Sstevel@tonic-gate } else {
30080Sstevel@tonic-gate tmp->b_datap->db_type = M_PROTO;
30090Sstevel@tonic-gate }
30100Sstevel@tonic-gate
30110Sstevel@tonic-gate /* Verify credentials in STREAM */
30120Sstevel@tonic-gate ASSERT(iocb->ioc_cr == NULL || iocb->ioc_cr == DB_CRED(tmp));
30130Sstevel@tonic-gate
30148778SErik.Nordmark@Sun.COM ASSERT(DB_CRED(tmp) != NULL);
30158778SErik.Nordmark@Sun.COM
30160Sstevel@tonic-gate TILOG("timodwproc: sending down %d\n", tp->tim_saved_prim);
30170Sstevel@tonic-gate putnext(q, tmp);
30180Sstevel@tonic-gate }
30190Sstevel@tonic-gate
30200Sstevel@tonic-gate static void
tim_clear_peer(struct tim_tim * tp)30210Sstevel@tonic-gate tim_clear_peer(struct tim_tim *tp)
30220Sstevel@tonic-gate {
30230Sstevel@tonic-gate mutex_enter(&tp->tim_mutex);
30240Sstevel@tonic-gate if (tp->tim_peercred != NULL) {
30250Sstevel@tonic-gate crfree(tp->tim_peercred);
30260Sstevel@tonic-gate tp->tim_peercred = NULL;
30270Sstevel@tonic-gate }
30280Sstevel@tonic-gate tp->tim_peerlen = 0;
30290Sstevel@tonic-gate mutex_exit(&tp->tim_mutex);
30300Sstevel@tonic-gate }
3031