xref: /titanic_41/usr/src/uts/common/inet/ip/rts.c (revision be4c8f742bc67a43d01e3ea82a814b7d6503dbfd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
588cda078Skcpoon  * Common Development and Distribution License (the "License").
688cda078Skcpoon  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*be4c8f74SErik Nordmark  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/stream.h>
287c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
297c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
307c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
317c478bd9Sstevel@tonic-gate #include <sys/strlog.h>
327c478bd9Sstevel@tonic-gate #define	_SUN_TPI_VERSION 2
337c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
347c478bd9Sstevel@tonic-gate #include <sys/timod.h>
357c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
367c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
377c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
387c478bd9Sstevel@tonic-gate #include <sys/proc.h>
397c478bd9Sstevel@tonic-gate #include <sys/suntpi.h>
407c478bd9Sstevel@tonic-gate #include <sys/policy.h>
41f4b3ec61Sdh155122 #include <sys/zone.h>
420f1702c5SYu Xiangning #include <sys/disp.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #include <sys/socket.h>
450f1702c5SYu Xiangning #include <sys/socketvar.h>
467c478bd9Sstevel@tonic-gate #include <netinet/in.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include <inet/common.h>
497c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
507c478bd9Sstevel@tonic-gate #include <inet/ip.h>
51fc80c0dfSnordmark #include <inet/ipclassifier.h>
520f1702c5SYu Xiangning #include <inet/proto_set.h>
537c478bd9Sstevel@tonic-gate #include <inet/nd.h>
547c478bd9Sstevel@tonic-gate #include <inet/optcom.h>
557c478bd9Sstevel@tonic-gate #include <netinet/ip_mroute.h>
567c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
577c478bd9Sstevel@tonic-gate #include <net/route.h>
587c478bd9Sstevel@tonic-gate 
59fc80c0dfSnordmark #include <inet/rts_impl.h>
60fc80c0dfSnordmark #include <inet/ip_rts.h>
61fc80c0dfSnordmark 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * This is a transport provider for routing sockets.  Downstream messages are
647c478bd9Sstevel@tonic-gate  * wrapped with a IP_IOCTL header, and ip_wput_ioctl calls the appropriate entry
657c478bd9Sstevel@tonic-gate  * in the ip_ioctl_ftbl callout table to pass the routing socket data into IP.
667c478bd9Sstevel@tonic-gate  * Upstream messages are generated for listeners of the routing socket as well
677c478bd9Sstevel@tonic-gate  * as the message sender (unless they have turned off their end using
687c478bd9Sstevel@tonic-gate  * SO_USELOOPBACK or shutdown(3n)).  Upstream messages may also be generated
697c478bd9Sstevel@tonic-gate  * asynchronously when:
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  *	Interfaces are brought up or down.
727c478bd9Sstevel@tonic-gate  *	Addresses are assigned to interfaces.
7327c48ed9Snordmark  *	ICMP redirects are processed and a IRE_HOST/RTF_DYNAMIC is installed.
747c478bd9Sstevel@tonic-gate  *	No route is found while sending a packet.
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  * Since all we do is reformat the messages between routing socket and
777c478bd9Sstevel@tonic-gate  * ioctl forms, no synchronization is necessary in this module; all
787c478bd9Sstevel@tonic-gate  * the dirty work is done down in ip.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /* Default structure copied into T_INFO_ACK messages */
827c478bd9Sstevel@tonic-gate static struct T_info_ack rts_g_t_info_ack = {
837c478bd9Sstevel@tonic-gate 	T_INFO_ACK,
847c478bd9Sstevel@tonic-gate 	T_INFINITE,	/* TSDU_size. Maximum size messages. */
857c478bd9Sstevel@tonic-gate 	T_INVALID,	/* ETSDU_size. No expedited data. */
867c478bd9Sstevel@tonic-gate 	T_INVALID,	/* CDATA_size. No connect data. */
877c478bd9Sstevel@tonic-gate 	T_INVALID,	/* DDATA_size. No disconnect data. */
887c478bd9Sstevel@tonic-gate 	0,		/* ADDR_size. */
897c478bd9Sstevel@tonic-gate 	0,		/* OPT_size - not initialized here */
907c478bd9Sstevel@tonic-gate 	64 * 1024,	/* TIDU_size. rts allows maximum size messages. */
917c478bd9Sstevel@tonic-gate 	T_COTS,		/* SERV_type. rts supports connection oriented. */
927c478bd9Sstevel@tonic-gate 	TS_UNBND,	/* CURRENT_state. This is set from rts_state. */
937c478bd9Sstevel@tonic-gate 	(XPG4_1)	/* PROVIDER_flag */
947c478bd9Sstevel@tonic-gate };
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Table of ND variables supported by rts. These are loaded into rts_g_nd
987c478bd9Sstevel@tonic-gate  * in rts_open.
997c478bd9Sstevel@tonic-gate  * All of these are alterable, within the min/max values given, at run time.
1007c478bd9Sstevel@tonic-gate  */
101f4b3ec61Sdh155122 static rtsparam_t	lcl_param_arr[] = {
1027c478bd9Sstevel@tonic-gate 	/* min		max		value		name */
1037c478bd9Sstevel@tonic-gate 	{ 4096,		65536,		8192,		"rts_xmit_hiwat"},
1047c478bd9Sstevel@tonic-gate 	{ 0,		65536,		1024,		"rts_xmit_lowat"},
1057c478bd9Sstevel@tonic-gate 	{ 4096,		65536,		8192,		"rts_recv_hiwat"},
1067c478bd9Sstevel@tonic-gate 	{ 65536,	1024*1024*1024, 256*1024,	"rts_max_buf"},
1077c478bd9Sstevel@tonic-gate };
108f4b3ec61Sdh155122 #define	rtss_xmit_hiwat		rtss_params[0].rts_param_value
109f4b3ec61Sdh155122 #define	rtss_xmit_lowat		rtss_params[1].rts_param_value
110f4b3ec61Sdh155122 #define	rtss_recv_hiwat		rtss_params[2].rts_param_value
111f4b3ec61Sdh155122 #define	rtss_max_buf		rtss_params[3].rts_param_value
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate static void 	rts_err_ack(queue_t *q, mblk_t *mp, t_scalar_t t_error,
1147c478bd9Sstevel@tonic-gate     int sys_error);
115bd670b35SErik Nordmark static void	rts_input(void *, mblk_t *, void *, ip_recv_attr_t *);
116bd670b35SErik Nordmark static void	rts_icmp_input(void *, mblk_t *, void *, ip_recv_attr_t *);
117de8c4a14SErik Nordmark static mblk_t	*rts_ioctl_alloc(mblk_t *data);
1187c478bd9Sstevel@tonic-gate static int	rts_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr);
119f4b3ec61Sdh155122 static boolean_t rts_param_register(IDP *ndp, rtsparam_t *rtspa, int cnt);
1207c478bd9Sstevel@tonic-gate static int	rts_param_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp,
1217c478bd9Sstevel@tonic-gate     cred_t *cr);
122fc80c0dfSnordmark static void	rts_rsrv(queue_t *q);
123f4b3ec61Sdh155122 static void	*rts_stack_init(netstackid_t stackid, netstack_t *ns);
124f4b3ec61Sdh155122 static void	rts_stack_fini(netstackid_t stackid, void *arg);
1257c478bd9Sstevel@tonic-gate static void	rts_wput(queue_t *q, mblk_t *mp);
1267c478bd9Sstevel@tonic-gate static void	rts_wput_iocdata(queue_t *q, mblk_t *mp);
1277c478bd9Sstevel@tonic-gate static void 	rts_wput_other(queue_t *q, mblk_t *mp);
1287c478bd9Sstevel@tonic-gate static int	rts_wrw(queue_t *q, struiod_t *dp);
1297c478bd9Sstevel@tonic-gate 
1300f1702c5SYu Xiangning static int	rts_stream_open(queue_t *q, dev_t *devp, int flag, int sflag,
1310f1702c5SYu Xiangning 		    cred_t *credp);
1320f1702c5SYu Xiangning static conn_t	*rts_open(int flag, cred_t *credp);
1330f1702c5SYu Xiangning 
1340f1702c5SYu Xiangning static int	rts_stream_close(queue_t *q);
1350f1702c5SYu Xiangning static int	rts_close(sock_lower_handle_t proto_handle, int flags,
1360f1702c5SYu Xiangning 		    cred_t *cr);
1370f1702c5SYu Xiangning 
138fc80c0dfSnordmark static struct module_info rts_mod_info = {
1397c478bd9Sstevel@tonic-gate 	129, "rts", 1, INFPSZ, 512, 128
1407c478bd9Sstevel@tonic-gate };
1417c478bd9Sstevel@tonic-gate 
142fc80c0dfSnordmark static struct qinit rtsrinit = {
1430f1702c5SYu Xiangning 	NULL, (pfi_t)rts_rsrv, rts_stream_open, rts_stream_close, NULL,
1440f1702c5SYu Xiangning 	&rts_mod_info
1457c478bd9Sstevel@tonic-gate };
1467c478bd9Sstevel@tonic-gate 
147fc80c0dfSnordmark static struct qinit rtswinit = {
148fc80c0dfSnordmark 	(pfi_t)rts_wput, NULL, NULL, NULL, NULL, &rts_mod_info,
1497c478bd9Sstevel@tonic-gate 	NULL, (pfi_t)rts_wrw, NULL, STRUIOT_STANDARD
1507c478bd9Sstevel@tonic-gate };
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate struct streamtab rtsinfo = {
153fc80c0dfSnordmark 	&rtsrinit, &rtswinit
1547c478bd9Sstevel@tonic-gate };
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * This routine allocates the necessary
1587c478bd9Sstevel@tonic-gate  * message blocks for IOCTL wrapping the
1597c478bd9Sstevel@tonic-gate  * user data.
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate static mblk_t *
rts_ioctl_alloc(mblk_t * data)162de8c4a14SErik Nordmark rts_ioctl_alloc(mblk_t *data)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate 	mblk_t	*mp = NULL;
1657c478bd9Sstevel@tonic-gate 	mblk_t	*mp1 = NULL;
1667c478bd9Sstevel@tonic-gate 	ipllc_t	*ipllc;
1677c478bd9Sstevel@tonic-gate 	struct iocblk	*ioc;
1687c478bd9Sstevel@tonic-gate 
169de8c4a14SErik Nordmark 	mp = allocb_tmpl(sizeof (ipllc_t), data);
1707c478bd9Sstevel@tonic-gate 	if (mp == NULL)
1717c478bd9Sstevel@tonic-gate 		return (NULL);
172de8c4a14SErik Nordmark 	mp1 = allocb_tmpl(sizeof (struct iocblk), data);
1737c478bd9Sstevel@tonic-gate 	if (mp1 == NULL) {
1747c478bd9Sstevel@tonic-gate 		freeb(mp);
1757c478bd9Sstevel@tonic-gate 		return (NULL);
1767c478bd9Sstevel@tonic-gate 	}
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	ipllc = (ipllc_t *)mp->b_rptr;
1797c478bd9Sstevel@tonic-gate 	ipllc->ipllc_cmd = IP_IOC_RTS_REQUEST;
1807c478bd9Sstevel@tonic-gate 	ipllc->ipllc_name_offset = 0;
1817c478bd9Sstevel@tonic-gate 	ipllc->ipllc_name_length = 0;
1827c478bd9Sstevel@tonic-gate 	mp->b_wptr += sizeof (ipllc_t);
1837c478bd9Sstevel@tonic-gate 	mp->b_cont = data;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	ioc = (struct iocblk *)mp1->b_rptr;
1867c478bd9Sstevel@tonic-gate 	ioc->ioc_cmd = IP_IOCTL;
1877c478bd9Sstevel@tonic-gate 	ioc->ioc_error = 0;
1887c478bd9Sstevel@tonic-gate 	ioc->ioc_cr = NULL;
1897c478bd9Sstevel@tonic-gate 	ioc->ioc_count = msgdsize(mp);
1907c478bd9Sstevel@tonic-gate 	mp1->b_wptr += sizeof (struct iocblk);
1917c478bd9Sstevel@tonic-gate 	mp1->b_datap->db_type = M_IOCTL;
1927c478bd9Sstevel@tonic-gate 	mp1->b_cont = mp;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	return (mp1);
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * This routine closes rts stream, by disabling
1997c478bd9Sstevel@tonic-gate  * put/srv routines and freeing the this module
2007c478bd9Sstevel@tonic-gate  * internal datastructure.
2017c478bd9Sstevel@tonic-gate  */
2027c478bd9Sstevel@tonic-gate static int
rts_common_close(queue_t * q,conn_t * connp)2030f1702c5SYu Xiangning rts_common_close(queue_t *q, conn_t *connp)
2047c478bd9Sstevel@tonic-gate {
205fc80c0dfSnordmark 
206fc80c0dfSnordmark 	ASSERT(connp != NULL && IPCL_IS_RTS(connp));
207fc80c0dfSnordmark 
208fc80c0dfSnordmark 	ip_rts_unregister(connp);
209fc80c0dfSnordmark 
210fc80c0dfSnordmark 	ip_quiesce_conn(connp);
211f4b3ec61Sdh155122 
2120f1702c5SYu Xiangning 	if (!IPCL_IS_NONSTR(connp)) {
2137c478bd9Sstevel@tonic-gate 		qprocsoff(q);
214bd670b35SErik Nordmark 	}
2157c478bd9Sstevel@tonic-gate 
216fc80c0dfSnordmark 	/*
217fc80c0dfSnordmark 	 * Now we are truly single threaded on this stream, and can
218bd670b35SErik Nordmark 	 * delete the things hanging off the connp, and finally the connp.
219fc80c0dfSnordmark 	 * We removed this connp from the fanout list, it cannot be
220fc80c0dfSnordmark 	 * accessed thru the fanouts, and we already waited for the
221fc80c0dfSnordmark 	 * conn_ref to drop to 0. We are already in close, so
222fc80c0dfSnordmark 	 * there cannot be any other thread from the top. qprocsoff
223fc80c0dfSnordmark 	 * has completed, and service has completed or won't run in
224fc80c0dfSnordmark 	 * future.
225fc80c0dfSnordmark 	 */
226bd670b35SErik Nordmark 	ASSERT(connp->conn_ref == 1);
227bd670b35SErik Nordmark 
228bd670b35SErik Nordmark 	if (!IPCL_IS_NONSTR(connp)) {
2290f1702c5SYu Xiangning 		inet_minor_free(connp->conn_minor_arena, connp->conn_dev);
2300f1702c5SYu Xiangning 	} else {
231bfcb55b8SRao Shoaib 		ip_free_helper_stream(connp);
2320f1702c5SYu Xiangning 	}
233fc80c0dfSnordmark 
234fc80c0dfSnordmark 	connp->conn_ref--;
235fc80c0dfSnordmark 	ipcl_conn_destroy(connp);
2360f1702c5SYu Xiangning 	return (0);
2370f1702c5SYu Xiangning }
2380f1702c5SYu Xiangning 
2390f1702c5SYu Xiangning static int
rts_stream_close(queue_t * q)2400f1702c5SYu Xiangning rts_stream_close(queue_t *q)
2410f1702c5SYu Xiangning {
2420f1702c5SYu Xiangning 	conn_t  *connp = Q_TO_CONN(q);
2430f1702c5SYu Xiangning 
2440f1702c5SYu Xiangning 	(void) rts_common_close(q, connp);
245fc80c0dfSnordmark 	q->q_ptr = WR(q)->q_ptr = NULL;
2467c478bd9Sstevel@tonic-gate 	return (0);
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate  * This is the open routine for routing socket. It allocates
251fc80c0dfSnordmark  * rts_t structure for the stream and tells IP that it is a routing socket.
2527c478bd9Sstevel@tonic-gate  */
2537c478bd9Sstevel@tonic-gate /* ARGSUSED */
2547c478bd9Sstevel@tonic-gate static int
rts_stream_open(queue_t * q,dev_t * devp,int flag,int sflag,cred_t * credp)2550f1702c5SYu Xiangning rts_stream_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp)
2567c478bd9Sstevel@tonic-gate {
257fc80c0dfSnordmark 	conn_t *connp;
258fc80c0dfSnordmark 	dev_t	conn_dev;
2590f1702c5SYu Xiangning 	rts_t   *rts;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	/* If the stream is already open, return immediately. */
2627c478bd9Sstevel@tonic-gate 	if (q->q_ptr != NULL)
2637c478bd9Sstevel@tonic-gate 		return (0);
2647c478bd9Sstevel@tonic-gate 
265fc80c0dfSnordmark 	if (sflag == MODOPEN)
2667c478bd9Sstevel@tonic-gate 		return (EINVAL);
2677c478bd9Sstevel@tonic-gate 
2680f1702c5SYu Xiangning 	/*
2690f1702c5SYu Xiangning 	 * Since RTS is not used so heavily, allocating from the small
2700f1702c5SYu Xiangning 	 * arena should be sufficient.
2710f1702c5SYu Xiangning 	 */
2720f1702c5SYu Xiangning 	if ((conn_dev = inet_minor_alloc(ip_minor_arena_sa)) == 0) {
2730f1702c5SYu Xiangning 		return (EBUSY);
2740f1702c5SYu Xiangning 	}
2750f1702c5SYu Xiangning 
2760f1702c5SYu Xiangning 	connp = rts_open(flag, credp);
2770f1702c5SYu Xiangning 	ASSERT(connp != NULL);
2780f1702c5SYu Xiangning 
2790f1702c5SYu Xiangning 	*devp = makedevice(getemajor(*devp), (minor_t)conn_dev);
2800f1702c5SYu Xiangning 
2810f1702c5SYu Xiangning 	rts = connp->conn_rts;
2820f1702c5SYu Xiangning 	rw_enter(&rts->rts_rwlock, RW_WRITER);
2830f1702c5SYu Xiangning 	connp->conn_dev = conn_dev;
2840f1702c5SYu Xiangning 	connp->conn_minor_arena = ip_minor_arena_sa;
2850f1702c5SYu Xiangning 
2860f1702c5SYu Xiangning 	q->q_ptr = connp;
2870f1702c5SYu Xiangning 	WR(q)->q_ptr = connp;
2880f1702c5SYu Xiangning 	connp->conn_rq = q;
2890f1702c5SYu Xiangning 	connp->conn_wq = WR(q);
2900f1702c5SYu Xiangning 
291bd670b35SErik Nordmark 	WR(q)->q_hiwat = connp->conn_sndbuf;
292bd670b35SErik Nordmark 	WR(q)->q_lowat = connp->conn_sndlowat;
2930f1702c5SYu Xiangning 
2940f1702c5SYu Xiangning 	mutex_enter(&connp->conn_lock);
2950f1702c5SYu Xiangning 	connp->conn_state_flags &= ~CONN_INCIPIENT;
2960f1702c5SYu Xiangning 	mutex_exit(&connp->conn_lock);
297bd670b35SErik Nordmark 	rw_exit(&rts->rts_rwlock);
298bd670b35SErik Nordmark 
299bd670b35SErik Nordmark 	/* Indicate to IP that this is a routing socket client */
300bd670b35SErik Nordmark 	ip_rts_register(connp);
3010f1702c5SYu Xiangning 
3020f1702c5SYu Xiangning 	qprocson(q);
3030f1702c5SYu Xiangning 
3040f1702c5SYu Xiangning 	return (0);
3050f1702c5SYu Xiangning }
3060f1702c5SYu Xiangning 
3070f1702c5SYu Xiangning /* ARGSUSED */
3080f1702c5SYu Xiangning static conn_t *
rts_open(int flag,cred_t * credp)3090f1702c5SYu Xiangning rts_open(int flag, cred_t *credp)
3100f1702c5SYu Xiangning {
3110f1702c5SYu Xiangning 	netstack_t *ns;
3120f1702c5SYu Xiangning 	rts_stack_t *rtss;
3130f1702c5SYu Xiangning 	rts_t	*rts;
3140f1702c5SYu Xiangning 	conn_t	*connp;
3150f1702c5SYu Xiangning 	zoneid_t zoneid;
3160f1702c5SYu Xiangning 
317f4b3ec61Sdh155122 	ns = netstack_find_by_cred(credp);
318f4b3ec61Sdh155122 	ASSERT(ns != NULL);
319f4b3ec61Sdh155122 	rtss = ns->netstack_rts;
320f4b3ec61Sdh155122 	ASSERT(rtss != NULL);
321f4b3ec61Sdh155122 
322fc80c0dfSnordmark 	/*
323fc80c0dfSnordmark 	 * For exclusive stacks we set the zoneid to zero
324fc80c0dfSnordmark 	 * to make RTS operate as if in the global zone.
325fc80c0dfSnordmark 	 */
326fc80c0dfSnordmark 	if (ns->netstack_stackid != GLOBAL_NETSTACKID)
327fc80c0dfSnordmark 		zoneid = GLOBAL_ZONEID;
328fc80c0dfSnordmark 	else
329fc80c0dfSnordmark 		zoneid = crgetzoneid(credp);
330fc80c0dfSnordmark 
331fc80c0dfSnordmark 	connp = ipcl_conn_create(IPCL_RTSCONN, KM_SLEEP, ns);
332fc80c0dfSnordmark 	rts = connp->conn_rts;
333fc80c0dfSnordmark 
334fc80c0dfSnordmark 	/*
335fc80c0dfSnordmark 	 * ipcl_conn_create did a netstack_hold. Undo the hold that was
336fc80c0dfSnordmark 	 * done by netstack_find_by_cred()
337fc80c0dfSnordmark 	 */
338fc80c0dfSnordmark 	netstack_rele(ns);
339fc80c0dfSnordmark 
340fc80c0dfSnordmark 	rw_enter(&rts->rts_rwlock, RW_WRITER);
341fc80c0dfSnordmark 	ASSERT(connp->conn_rts == rts);
342fc80c0dfSnordmark 	ASSERT(rts->rts_connp == connp);
343fc80c0dfSnordmark 
344bd670b35SErik Nordmark 	connp->conn_ixa->ixa_flags |= IXAF_MULTICAST_LOOP | IXAF_SET_ULP_CKSUM;
345bd670b35SErik Nordmark 	/* conn_allzones can not be set this early, hence no IPCL_ZONEID */
346bd670b35SErik Nordmark 	connp->conn_ixa->ixa_zoneid = zoneid;
347fc80c0dfSnordmark 	connp->conn_zoneid = zoneid;
3480f1702c5SYu Xiangning 	connp->conn_flow_cntrld = B_FALSE;
349fc80c0dfSnordmark 
350f4b3ec61Sdh155122 	rts->rts_rtss = rtss;
351bd670b35SErik Nordmark 
352bd670b35SErik Nordmark 	connp->conn_rcvbuf = rtss->rtss_recv_hiwat;
353bd670b35SErik Nordmark 	connp->conn_sndbuf = rtss->rtss_xmit_hiwat;
354bd670b35SErik Nordmark 	connp->conn_sndlowat = rtss->rtss_xmit_lowat;
355bd670b35SErik Nordmark 	connp->conn_rcvlowat = rts_mod_info.mi_lowat;
356bd670b35SErik Nordmark 
357bd670b35SErik Nordmark 	connp->conn_family = PF_ROUTE;
358bd670b35SErik Nordmark 	connp->conn_so_type = SOCK_RAW;
359bd670b35SErik Nordmark 	/* SO_PROTOTYPE is always sent down by sockfs setting conn_proto */
360fc80c0dfSnordmark 
361fc80c0dfSnordmark 	connp->conn_recv = rts_input;
362bd670b35SErik Nordmark 	connp->conn_recvicmp = rts_icmp_input;
363bd670b35SErik Nordmark 
364fc80c0dfSnordmark 	crhold(credp);
365fc80c0dfSnordmark 	connp->conn_cred = credp;
366bd670b35SErik Nordmark 	connp->conn_cpid = curproc->p_pid;
367bd670b35SErik Nordmark 	/* Cache things in ixa without an extra refhold */
368*be4c8f74SErik Nordmark 	ASSERT(!(connp->conn_ixa->ixa_free_flags & IXA_FREE_CRED));
369bd670b35SErik Nordmark 	connp->conn_ixa->ixa_cred = connp->conn_cred;
370bd670b35SErik Nordmark 	connp->conn_ixa->ixa_cpid = connp->conn_cpid;
371bd670b35SErik Nordmark 	if (is_system_labeled())
372bd670b35SErik Nordmark 		connp->conn_ixa->ixa_tsl = crgetlabel(connp->conn_cred);
373fc80c0dfSnordmark 
3740f1702c5SYu Xiangning 	/*
3750f1702c5SYu Xiangning 	 * rts sockets start out as bound and connected
3760f1702c5SYu Xiangning 	 * For streams based sockets, socket state is set to
3770f1702c5SYu Xiangning 	 * SS_ISBOUND | SS_ISCONNECTED in so_strinit.
3780f1702c5SYu Xiangning 	 */
3790f1702c5SYu Xiangning 	rts->rts_state = TS_DATA_XFER;
380fc80c0dfSnordmark 	rw_exit(&rts->rts_rwlock);
381fc80c0dfSnordmark 
3820f1702c5SYu Xiangning 	return (connp);
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate /*
3867c478bd9Sstevel@tonic-gate  * This routine creates a T_ERROR_ACK message and passes it upstream.
3877c478bd9Sstevel@tonic-gate  */
3887c478bd9Sstevel@tonic-gate static void
rts_err_ack(queue_t * q,mblk_t * mp,t_scalar_t t_error,int sys_error)3897c478bd9Sstevel@tonic-gate rts_err_ack(queue_t *q, mblk_t *mp, t_scalar_t t_error, int sys_error)
3907c478bd9Sstevel@tonic-gate {
3917c478bd9Sstevel@tonic-gate 	if ((mp = mi_tpi_err_ack_alloc(mp, t_error, sys_error)) != NULL)
3927c478bd9Sstevel@tonic-gate 		qreply(q, mp);
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate /*
3967c478bd9Sstevel@tonic-gate  * This routine creates a T_OK_ACK message and passes it upstream.
3977c478bd9Sstevel@tonic-gate  */
3987c478bd9Sstevel@tonic-gate static void
rts_ok_ack(queue_t * q,mblk_t * mp)3997c478bd9Sstevel@tonic-gate rts_ok_ack(queue_t *q, mblk_t *mp)
4007c478bd9Sstevel@tonic-gate {
4017c478bd9Sstevel@tonic-gate 	if ((mp = mi_tpi_ok_ack_alloc(mp)) != NULL)
4027c478bd9Sstevel@tonic-gate 		qreply(q, mp);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate /*
4067c478bd9Sstevel@tonic-gate  * This routine is called by rts_wput to handle T_UNBIND_REQ messages.
4077c478bd9Sstevel@tonic-gate  */
4087c478bd9Sstevel@tonic-gate static void
rts_tpi_unbind(queue_t * q,mblk_t * mp)4090f1702c5SYu Xiangning rts_tpi_unbind(queue_t *q, mblk_t *mp)
4107c478bd9Sstevel@tonic-gate {
411fc80c0dfSnordmark 	conn_t	*connp = Q_TO_CONN(q);
412fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	/* If a bind has not been done, we can't unbind. */
4157c478bd9Sstevel@tonic-gate 	if (rts->rts_state != TS_IDLE) {
4167c478bd9Sstevel@tonic-gate 		rts_err_ack(q, mp, TOUTSTATE, 0);
4177c478bd9Sstevel@tonic-gate 		return;
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 	rts->rts_state = TS_UNBND;
4207c478bd9Sstevel@tonic-gate 	rts_ok_ack(q, mp);
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate /*
4247c478bd9Sstevel@tonic-gate  * This routine is called to handle each
4257c478bd9Sstevel@tonic-gate  * O_T_BIND_REQ/T_BIND_REQ message passed to
4267c478bd9Sstevel@tonic-gate  * rts_wput. Note: This routine works with both
4277c478bd9Sstevel@tonic-gate  * O_T_BIND_REQ and T_BIND_REQ semantics.
4287c478bd9Sstevel@tonic-gate  */
4297c478bd9Sstevel@tonic-gate static void
rts_tpi_bind(queue_t * q,mblk_t * mp)4300f1702c5SYu Xiangning rts_tpi_bind(queue_t *q, mblk_t *mp)
4317c478bd9Sstevel@tonic-gate {
432fc80c0dfSnordmark 	conn_t	*connp = Q_TO_CONN(q);
433fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
4347c478bd9Sstevel@tonic-gate 	struct T_bind_req *tbr;
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate 	if ((mp->b_wptr - mp->b_rptr) < sizeof (*tbr)) {
4377c478bd9Sstevel@tonic-gate 		(void) mi_strlog(q, 1, SL_ERROR|SL_TRACE,
4380f1702c5SYu Xiangning 		    "rts_tpi_bind: bad data, %d", rts->rts_state);
4397c478bd9Sstevel@tonic-gate 		rts_err_ack(q, mp, TBADADDR, 0);
4407c478bd9Sstevel@tonic-gate 		return;
4417c478bd9Sstevel@tonic-gate 	}
4427c478bd9Sstevel@tonic-gate 	if (rts->rts_state != TS_UNBND) {
4437c478bd9Sstevel@tonic-gate 		(void) mi_strlog(q, 1, SL_ERROR|SL_TRACE,
4440f1702c5SYu Xiangning 		    "rts_tpi_bind: bad state, %d", rts->rts_state);
4457c478bd9Sstevel@tonic-gate 		rts_err_ack(q, mp, TOUTSTATE, 0);
4467c478bd9Sstevel@tonic-gate 		return;
4477c478bd9Sstevel@tonic-gate 	}
4487c478bd9Sstevel@tonic-gate 	tbr = (struct T_bind_req *)mp->b_rptr;
4497c478bd9Sstevel@tonic-gate 	if (tbr->ADDR_length != 0) {
4507c478bd9Sstevel@tonic-gate 		(void) mi_strlog(q, 1, SL_ERROR|SL_TRACE,
4510f1702c5SYu Xiangning 		    "rts_tpi_bind: bad ADDR_length %d", tbr->ADDR_length);
4527c478bd9Sstevel@tonic-gate 		rts_err_ack(q, mp, TBADADDR, 0);
4537c478bd9Sstevel@tonic-gate 		return;
4547c478bd9Sstevel@tonic-gate 	}
4557c478bd9Sstevel@tonic-gate 	/* Generic request */
4567c478bd9Sstevel@tonic-gate 	tbr->ADDR_offset = (t_scalar_t)sizeof (struct T_bind_req);
4577c478bd9Sstevel@tonic-gate 	tbr->ADDR_length = 0;
4587c478bd9Sstevel@tonic-gate 	tbr->PRIM_type = T_BIND_ACK;
459bd670b35SErik Nordmark 	mp->b_datap->db_type = M_PCPROTO;
4607c478bd9Sstevel@tonic-gate 	rts->rts_state = TS_IDLE;
4617c478bd9Sstevel@tonic-gate 	qreply(q, mp);
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate static void
rts_copy_info(struct T_info_ack * tap,rts_t * rts)4657c478bd9Sstevel@tonic-gate rts_copy_info(struct T_info_ack *tap, rts_t *rts)
4667c478bd9Sstevel@tonic-gate {
4677c478bd9Sstevel@tonic-gate 	*tap = rts_g_t_info_ack;
4687c478bd9Sstevel@tonic-gate 	tap->CURRENT_state = rts->rts_state;
4697c478bd9Sstevel@tonic-gate 	tap->OPT_size = rts_max_optsize;
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate /*
4737c478bd9Sstevel@tonic-gate  * This routine responds to T_CAPABILITY_REQ messages.  It is called by
4747c478bd9Sstevel@tonic-gate  * rts_wput.  Much of the T_CAPABILITY_ACK information is copied from
4757c478bd9Sstevel@tonic-gate  * rts_g_t_info_ack.  The current state of the stream is copied from
4767c478bd9Sstevel@tonic-gate  * rts_state.
4777c478bd9Sstevel@tonic-gate  */
4787c478bd9Sstevel@tonic-gate static void
rts_capability_req(queue_t * q,mblk_t * mp)4797c478bd9Sstevel@tonic-gate rts_capability_req(queue_t *q, mblk_t *mp)
4807c478bd9Sstevel@tonic-gate {
481fc80c0dfSnordmark 	conn_t	*connp = Q_TO_CONN(q);
482fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
4837c478bd9Sstevel@tonic-gate 	t_uscalar_t		cap_bits1;
4847c478bd9Sstevel@tonic-gate 	struct T_capability_ack	*tcap;
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate 	cap_bits1 = ((struct T_capability_req *)mp->b_rptr)->CAP_bits1;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	mp = tpi_ack_alloc(mp, sizeof (struct T_capability_ack),
4897c478bd9Sstevel@tonic-gate 	    mp->b_datap->db_type, T_CAPABILITY_ACK);
4907c478bd9Sstevel@tonic-gate 	if (mp == NULL)
4917c478bd9Sstevel@tonic-gate 		return;
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	tcap = (struct T_capability_ack *)mp->b_rptr;
4947c478bd9Sstevel@tonic-gate 	tcap->CAP_bits1 = 0;
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	if (cap_bits1 & TC1_INFO) {
4977c478bd9Sstevel@tonic-gate 		rts_copy_info(&tcap->INFO_ack, rts);
4987c478bd9Sstevel@tonic-gate 		tcap->CAP_bits1 |= TC1_INFO;
4997c478bd9Sstevel@tonic-gate 	}
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	qreply(q, mp);
5027c478bd9Sstevel@tonic-gate }
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate /*
5057c478bd9Sstevel@tonic-gate  * This routine responds to T_INFO_REQ messages.  It is called by rts_wput.
5067c478bd9Sstevel@tonic-gate  * Most of the T_INFO_ACK information is copied from rts_g_t_info_ack.
5077c478bd9Sstevel@tonic-gate  * The current state of the stream is copied from rts_state.
5087c478bd9Sstevel@tonic-gate  */
5097c478bd9Sstevel@tonic-gate static void
rts_info_req(queue_t * q,mblk_t * mp)5107c478bd9Sstevel@tonic-gate rts_info_req(queue_t *q, mblk_t *mp)
5117c478bd9Sstevel@tonic-gate {
512fc80c0dfSnordmark 	conn_t	*connp = Q_TO_CONN(q);
513fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	mp = tpi_ack_alloc(mp, sizeof (rts_g_t_info_ack), M_PCPROTO,
5167c478bd9Sstevel@tonic-gate 	    T_INFO_ACK);
5177c478bd9Sstevel@tonic-gate 	if (mp == NULL)
5187c478bd9Sstevel@tonic-gate 		return;
5197c478bd9Sstevel@tonic-gate 	rts_copy_info((struct T_info_ack *)mp->b_rptr, rts);
5207c478bd9Sstevel@tonic-gate 	qreply(q, mp);
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate /*
5247c478bd9Sstevel@tonic-gate  * This routine gets default values of certain options whose default
5257c478bd9Sstevel@tonic-gate  * values are maintained by protcol specific code
5267c478bd9Sstevel@tonic-gate  */
5277c478bd9Sstevel@tonic-gate /* ARGSUSED */
5287c478bd9Sstevel@tonic-gate int
rts_opt_default(queue_t * q,t_scalar_t level,t_scalar_t name,uchar_t * ptr)5297c478bd9Sstevel@tonic-gate rts_opt_default(queue_t *q, t_scalar_t level, t_scalar_t name, uchar_t *ptr)
5307c478bd9Sstevel@tonic-gate {
5317c478bd9Sstevel@tonic-gate 	/* no default value processed by protocol specific code currently */
5327c478bd9Sstevel@tonic-gate 	return (-1);
5337c478bd9Sstevel@tonic-gate }
5347c478bd9Sstevel@tonic-gate 
5350f1702c5SYu Xiangning 
5360f1702c5SYu Xiangning static int
rts_opt_get(conn_t * connp,int level,int name,uchar_t * ptr)5370f1702c5SYu Xiangning rts_opt_get(conn_t *connp, int level, int name, uchar_t *ptr)
5387c478bd9Sstevel@tonic-gate {
539fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
540bd670b35SErik Nordmark 	conn_opt_arg_t	coas;
541bd670b35SErik Nordmark 	int retval;
5420f1702c5SYu Xiangning 
5430f1702c5SYu Xiangning 	ASSERT(RW_READ_HELD(&rts->rts_rwlock));
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	switch (level) {
546bd670b35SErik Nordmark 	/* do this in conn_opt_get? */
547e11c3f44Smeem 	case SOL_ROUTE:
548e11c3f44Smeem 		switch (name) {
549e11c3f44Smeem 		case RT_AWARE:
550e11c3f44Smeem 			mutex_enter(&connp->conn_lock);
551bd670b35SErik Nordmark 			*(int *)ptr = connp->conn_rtaware;
552e11c3f44Smeem 			mutex_exit(&connp->conn_lock);
553bd670b35SErik Nordmark 			return (0);
554e11c3f44Smeem 		}
555e11c3f44Smeem 		break;
5567c478bd9Sstevel@tonic-gate 	}
557bd670b35SErik Nordmark 	coas.coa_connp = connp;
558bd670b35SErik Nordmark 	coas.coa_ixa = connp->conn_ixa;
559bd670b35SErik Nordmark 	coas.coa_ipp = &connp->conn_xmit_ipp;
560bd670b35SErik Nordmark 	mutex_enter(&connp->conn_lock);
561bd670b35SErik Nordmark 	retval = conn_opt_get(&coas, level, name, ptr);
562bd670b35SErik Nordmark 	mutex_exit(&connp->conn_lock);
563bd670b35SErik Nordmark 	return (retval);
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /* ARGSUSED */
5670f1702c5SYu Xiangning static int
rts_do_opt_set(conn_t * connp,int level,int name,uint_t inlen,uchar_t * invalp,uint_t * outlenp,uchar_t * outvalp,cred_t * cr,void * thisdg_attrs,boolean_t checkonly)5680f1702c5SYu Xiangning rts_do_opt_set(conn_t *connp, int level, int name, uint_t inlen,
5690f1702c5SYu Xiangning     uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp, cred_t *cr,
5700f1702c5SYu Xiangning     void *thisdg_attrs, boolean_t checkonly)
5717c478bd9Sstevel@tonic-gate {
5727c478bd9Sstevel@tonic-gate 	int	*i1 = (int *)invalp;
573fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
574f4b3ec61Sdh155122 	rts_stack_t	*rtss = rts->rts_rtss;
575bd670b35SErik Nordmark 	int		error;
576bd670b35SErik Nordmark 	conn_opt_arg_t	coas;
577bd670b35SErik Nordmark 
578bd670b35SErik Nordmark 	coas.coa_connp = connp;
579bd670b35SErik Nordmark 	coas.coa_ixa = connp->conn_ixa;
580bd670b35SErik Nordmark 	coas.coa_ipp = &connp->conn_xmit_ipp;
5817c478bd9Sstevel@tonic-gate 
5820f1702c5SYu Xiangning 	ASSERT(RW_WRITE_HELD(&rts->rts_rwlock));
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	/*
5857c478bd9Sstevel@tonic-gate 	 * For rts, we should have no ancillary data sent down
5867c478bd9Sstevel@tonic-gate 	 * (rts_wput doesn't handle options).
5877c478bd9Sstevel@tonic-gate 	 */
5887c478bd9Sstevel@tonic-gate 	ASSERT(thisdg_attrs == NULL);
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 	/*
5917c478bd9Sstevel@tonic-gate 	 * For fixed length options, no sanity check
5927c478bd9Sstevel@tonic-gate 	 * of passed in length is done. It is assumed *_optcom_req()
5937c478bd9Sstevel@tonic-gate 	 * routines do the right thing.
5947c478bd9Sstevel@tonic-gate 	 */
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	switch (level) {
5977c478bd9Sstevel@tonic-gate 	case SOL_SOCKET:
5987c478bd9Sstevel@tonic-gate 		switch (name) {
5997c478bd9Sstevel@tonic-gate 		case SO_PROTOTYPE:
6007c478bd9Sstevel@tonic-gate 			/*
6017c478bd9Sstevel@tonic-gate 			 * Routing socket applications that call socket() with
6027c478bd9Sstevel@tonic-gate 			 * a third argument can filter which messages will be
6037c478bd9Sstevel@tonic-gate 			 * sent upstream thanks to sockfs.  so_socket() sends
6047c478bd9Sstevel@tonic-gate 			 * down the SO_PROTOTYPE and rts_queue_input()
6057c478bd9Sstevel@tonic-gate 			 * implements the filtering.
6067c478bd9Sstevel@tonic-gate 			 */
607bd670b35SErik Nordmark 			if (*i1 != AF_INET && *i1 != AF_INET6) {
608bd670b35SErik Nordmark 				*outlenp = 0;
6097c478bd9Sstevel@tonic-gate 				return (EPROTONOSUPPORT);
610beb2c8edSRao Shoaib 			}
611bd670b35SErik Nordmark 			if (!checkonly)
612bd670b35SErik Nordmark 				connp->conn_proto = *i1;
613bd670b35SErik Nordmark 			*outlenp = inlen;
614bd670b35SErik Nordmark 			return (0);
615bd670b35SErik Nordmark 
6167c478bd9Sstevel@tonic-gate 		/*
6177c478bd9Sstevel@tonic-gate 		 * The following two items can be manipulated,
6187c478bd9Sstevel@tonic-gate 		 * but changing them should do nothing.
6197c478bd9Sstevel@tonic-gate 		 */
6207c478bd9Sstevel@tonic-gate 		case SO_SNDBUF:
621f4b3ec61Sdh155122 			if (*i1 > rtss->rtss_max_buf) {
6227c478bd9Sstevel@tonic-gate 				*outlenp = 0;
6237c478bd9Sstevel@tonic-gate 				return (ENOBUFS);
6247c478bd9Sstevel@tonic-gate 			}
6257c478bd9Sstevel@tonic-gate 			break;	/* goto sizeof (int) option return */
6267c478bd9Sstevel@tonic-gate 		case SO_RCVBUF:
627f4b3ec61Sdh155122 			if (*i1 > rtss->rtss_max_buf) {
6287c478bd9Sstevel@tonic-gate 				*outlenp = 0;
6297c478bd9Sstevel@tonic-gate 				return (ENOBUFS);
6307c478bd9Sstevel@tonic-gate 			}
6317c478bd9Sstevel@tonic-gate 			break;	/* goto sizeof (int) option return */
6327c478bd9Sstevel@tonic-gate 		}
6337c478bd9Sstevel@tonic-gate 		break;
634e11c3f44Smeem 	case SOL_ROUTE:
635e11c3f44Smeem 		switch (name) {
636e11c3f44Smeem 		case RT_AWARE:
637e11c3f44Smeem 			if (!checkonly) {
638e11c3f44Smeem 				mutex_enter(&connp->conn_lock);
639e11c3f44Smeem 				connp->conn_rtaware = *i1;
640e11c3f44Smeem 				mutex_exit(&connp->conn_lock);
641e11c3f44Smeem 			}
642bd670b35SErik Nordmark 			*outlenp = inlen;
643bd670b35SErik Nordmark 			return (0);
644e11c3f44Smeem 		}
645e11c3f44Smeem 		break;
646bd670b35SErik Nordmark 	}
647bd670b35SErik Nordmark 	/* Serialized setsockopt since we are D_MTQPAIR */
648bd670b35SErik Nordmark 	error = conn_opt_set(&coas, level, name, inlen, invalp,
649bd670b35SErik Nordmark 	    checkonly, cr);
650bd670b35SErik Nordmark 	if (error != 0) {
6517c478bd9Sstevel@tonic-gate 		*outlenp = 0;
652bd670b35SErik Nordmark 		return (error);
6537c478bd9Sstevel@tonic-gate 	}
6547c478bd9Sstevel@tonic-gate 	/*
6557c478bd9Sstevel@tonic-gate 	 * Common case of return from an option that is sizeof (int)
6567c478bd9Sstevel@tonic-gate 	 */
6570f1702c5SYu Xiangning 	if (invalp != outvalp) {
6580f1702c5SYu Xiangning 		/* don't trust bcopy for identical src/dst */
6590f1702c5SYu Xiangning 		(void) bcopy(invalp, outvalp, inlen);
6600f1702c5SYu Xiangning 	}
6617c478bd9Sstevel@tonic-gate 	*outlenp = (t_uscalar_t)sizeof (int);
6627c478bd9Sstevel@tonic-gate 	return (0);
6637c478bd9Sstevel@tonic-gate }
6647c478bd9Sstevel@tonic-gate 
6650f1702c5SYu Xiangning static int
rts_opt_set(conn_t * connp,uint_t optset_context,int level,int name,uint_t inlen,uchar_t * invalp,uint_t * outlenp,uchar_t * outvalp,void * thisdg_attrs,cred_t * cr)6660f1702c5SYu Xiangning rts_opt_set(conn_t *connp, uint_t optset_context, int level, int name,
6670f1702c5SYu Xiangning     uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp,
6680f1702c5SYu Xiangning     void *thisdg_attrs, cred_t *cr)
6690f1702c5SYu Xiangning {
6700f1702c5SYu Xiangning 	boolean_t 	checkonly = B_FALSE;
6710f1702c5SYu Xiangning 
6720f1702c5SYu Xiangning 	if (optset_context) {
6730f1702c5SYu Xiangning 		switch (optset_context) {
6740f1702c5SYu Xiangning 		case SETFN_OPTCOM_CHECKONLY:
6750f1702c5SYu Xiangning 			checkonly = B_TRUE;
6760f1702c5SYu Xiangning 			/*
6770f1702c5SYu Xiangning 			 * Note: Implies T_CHECK semantics for T_OPTCOM_REQ
6780f1702c5SYu Xiangning 			 * inlen != 0 implies value supplied and
6790f1702c5SYu Xiangning 			 * 	we have to "pretend" to set it.
6800f1702c5SYu Xiangning 			 * inlen == 0 implies that there is no value part
6810f1702c5SYu Xiangning 			 * 	in T_CHECK request and just validation
6820f1702c5SYu Xiangning 			 * done elsewhere should be enough, we just return here.
6830f1702c5SYu Xiangning 			 */
6840f1702c5SYu Xiangning 			if (inlen == 0) {
6850f1702c5SYu Xiangning 				*outlenp = 0;
6860f1702c5SYu Xiangning 				return (0);
6870f1702c5SYu Xiangning 			}
6880f1702c5SYu Xiangning 			break;
6890f1702c5SYu Xiangning 		case SETFN_OPTCOM_NEGOTIATE:
6900f1702c5SYu Xiangning 			checkonly = B_FALSE;
6910f1702c5SYu Xiangning 			break;
6920f1702c5SYu Xiangning 		case SETFN_UD_NEGOTIATE:
6930f1702c5SYu Xiangning 		case SETFN_CONN_NEGOTIATE:
6940f1702c5SYu Xiangning 			checkonly = B_FALSE;
6950f1702c5SYu Xiangning 			/*
6960f1702c5SYu Xiangning 			 * Negotiating local and "association-related" options
6970f1702c5SYu Xiangning 			 * through T_UNITDATA_REQ or T_CONN_{REQ,CON}
6980f1702c5SYu Xiangning 			 * Not allowed in this module.
6990f1702c5SYu Xiangning 			 */
7000f1702c5SYu Xiangning 			return (EINVAL);
7010f1702c5SYu Xiangning 		default:
7020f1702c5SYu Xiangning 			/*
7030f1702c5SYu Xiangning 			 * We should never get here
7040f1702c5SYu Xiangning 			 */
7050f1702c5SYu Xiangning 			*outlenp = 0;
7060f1702c5SYu Xiangning 			return (EINVAL);
7070f1702c5SYu Xiangning 		}
7080f1702c5SYu Xiangning 
7090f1702c5SYu Xiangning 		ASSERT((optset_context != SETFN_OPTCOM_CHECKONLY) ||
7100f1702c5SYu Xiangning 		    (optset_context == SETFN_OPTCOM_CHECKONLY && inlen != 0));
7110f1702c5SYu Xiangning 
7120f1702c5SYu Xiangning 	}
7130f1702c5SYu Xiangning 	return (rts_do_opt_set(connp, level, name, inlen, invalp, outlenp,
7140f1702c5SYu Xiangning 	    outvalp, cr, thisdg_attrs, checkonly));
7150f1702c5SYu Xiangning 
7160f1702c5SYu Xiangning }
7170f1702c5SYu Xiangning 
7180f1702c5SYu Xiangning /*
7190f1702c5SYu Xiangning  * This routine retrieves the current status of socket options.
7200f1702c5SYu Xiangning  * It returns the size of the option retrieved.
7210f1702c5SYu Xiangning  */
7220f1702c5SYu Xiangning int
rts_tpi_opt_get(queue_t * q,t_scalar_t level,t_scalar_t name,uchar_t * ptr)7230f1702c5SYu Xiangning rts_tpi_opt_get(queue_t *q, t_scalar_t level, t_scalar_t name, uchar_t *ptr)
7240f1702c5SYu Xiangning {
7250f1702c5SYu Xiangning 	rts_t	*rts;
7260f1702c5SYu Xiangning 	int	err;
7270f1702c5SYu Xiangning 
7280f1702c5SYu Xiangning 	rts = Q_TO_RTS(q);
7290f1702c5SYu Xiangning 	rw_enter(&rts->rts_rwlock, RW_READER);
7300f1702c5SYu Xiangning 	err = rts_opt_get(Q_TO_CONN(q), level, name, ptr);
7310f1702c5SYu Xiangning 	rw_exit(&rts->rts_rwlock);
7320f1702c5SYu Xiangning 	return (err);
7330f1702c5SYu Xiangning }
7340f1702c5SYu Xiangning 
7350f1702c5SYu Xiangning /*
7360f1702c5SYu Xiangning  * This routine sets socket options.
7370f1702c5SYu Xiangning  */
7380f1702c5SYu Xiangning /*ARGSUSED*/
7390f1702c5SYu Xiangning int
rts_tpi_opt_set(queue_t * q,uint_t optset_context,int level,int name,uint_t inlen,uchar_t * invalp,uint_t * outlenp,uchar_t * outvalp,void * thisdg_attrs,cred_t * cr)7400f1702c5SYu Xiangning rts_tpi_opt_set(queue_t *q, uint_t optset_context, int level,
7410f1702c5SYu Xiangning     int name, uint_t inlen, uchar_t *invalp, uint_t *outlenp,
742bd670b35SErik Nordmark     uchar_t *outvalp, void *thisdg_attrs, cred_t *cr)
7430f1702c5SYu Xiangning {
7440f1702c5SYu Xiangning 	conn_t	*connp = Q_TO_CONN(q);
7450f1702c5SYu Xiangning 	int	error;
7460f1702c5SYu Xiangning 	rts_t	*rts = connp->conn_rts;
7470f1702c5SYu Xiangning 
7480f1702c5SYu Xiangning 
7490f1702c5SYu Xiangning 	rw_enter(&rts->rts_rwlock, RW_WRITER);
7500f1702c5SYu Xiangning 	error = rts_opt_set(connp, optset_context, level, name, inlen, invalp,
7510f1702c5SYu Xiangning 	    outlenp, outvalp, thisdg_attrs, cr);
7520f1702c5SYu Xiangning 	rw_exit(&rts->rts_rwlock);
7530f1702c5SYu Xiangning 	return (error);
7540f1702c5SYu Xiangning }
7550f1702c5SYu Xiangning 
7567c478bd9Sstevel@tonic-gate /*
7577c478bd9Sstevel@tonic-gate  * This routine retrieves the value of an ND variable in a rtsparam_t
7587c478bd9Sstevel@tonic-gate  * structure. It is called through nd_getset when a user reads the
7597c478bd9Sstevel@tonic-gate  * variable.
7607c478bd9Sstevel@tonic-gate  */
7617c478bd9Sstevel@tonic-gate /* ARGSUSED */
7627c478bd9Sstevel@tonic-gate static int
rts_param_get(queue_t * q,mblk_t * mp,caddr_t cp,cred_t * cr)7637c478bd9Sstevel@tonic-gate rts_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
7647c478bd9Sstevel@tonic-gate {
7657c478bd9Sstevel@tonic-gate 	rtsparam_t	*rtspa = (rtsparam_t *)cp;
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "%u", rtspa->rts_param_value);
7687c478bd9Sstevel@tonic-gate 	return (0);
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate /*
7727c478bd9Sstevel@tonic-gate  * Walk through the param array specified registering each element with the
7737c478bd9Sstevel@tonic-gate  * named dispatch (ND) handler.
7747c478bd9Sstevel@tonic-gate  */
7757c478bd9Sstevel@tonic-gate static boolean_t
rts_param_register(IDP * ndp,rtsparam_t * rtspa,int cnt)776f4b3ec61Sdh155122 rts_param_register(IDP *ndp, rtsparam_t *rtspa, int cnt)
7777c478bd9Sstevel@tonic-gate {
7787c478bd9Sstevel@tonic-gate 	for (; cnt-- > 0; rtspa++) {
7797c478bd9Sstevel@tonic-gate 		if (rtspa->rts_param_name != NULL && rtspa->rts_param_name[0]) {
780f4b3ec61Sdh155122 			if (!nd_load(ndp, rtspa->rts_param_name,
7817c478bd9Sstevel@tonic-gate 			    rts_param_get, rts_param_set, (caddr_t)rtspa)) {
782f4b3ec61Sdh155122 				nd_free(ndp);
7837c478bd9Sstevel@tonic-gate 				return (B_FALSE);
7847c478bd9Sstevel@tonic-gate 			}
7857c478bd9Sstevel@tonic-gate 		}
7867c478bd9Sstevel@tonic-gate 	}
7877c478bd9Sstevel@tonic-gate 	return (B_TRUE);
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate /* This routine sets an ND variable in a rtsparam_t structure. */
7917c478bd9Sstevel@tonic-gate /* ARGSUSED */
7927c478bd9Sstevel@tonic-gate static int
rts_param_set(queue_t * q,mblk_t * mp,char * value,caddr_t cp,cred_t * cr)7937c478bd9Sstevel@tonic-gate rts_param_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp, cred_t *cr)
7947c478bd9Sstevel@tonic-gate {
7957c478bd9Sstevel@tonic-gate 	ulong_t	new_value;
7967c478bd9Sstevel@tonic-gate 	rtsparam_t	*rtspa = (rtsparam_t *)cp;
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 	/*
7997c478bd9Sstevel@tonic-gate 	 * Fail the request if the new value does not lie within the
8007c478bd9Sstevel@tonic-gate 	 * required bounds.
8017c478bd9Sstevel@tonic-gate 	 */
8027c478bd9Sstevel@tonic-gate 	if (ddi_strtoul(value, NULL, 10, &new_value) != 0 ||
8037c478bd9Sstevel@tonic-gate 	    new_value < rtspa->rts_param_min ||
8047c478bd9Sstevel@tonic-gate 	    new_value > rtspa->rts_param_max) {
8057c478bd9Sstevel@tonic-gate 		return (EINVAL);
8067c478bd9Sstevel@tonic-gate 	}
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 	/* Set the new value */
8097c478bd9Sstevel@tonic-gate 	rtspa->rts_param_value = new_value;
8107c478bd9Sstevel@tonic-gate 	return (0);
8117c478bd9Sstevel@tonic-gate }
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate /*
814fc80c0dfSnordmark  * Empty rsrv routine which is used by rts_input to cause a wakeup
815fc80c0dfSnordmark  * of a thread in qwait.
816fc80c0dfSnordmark  */
817fc80c0dfSnordmark /*ARGSUSED*/
818fc80c0dfSnordmark static void
rts_rsrv(queue_t * q)819fc80c0dfSnordmark rts_rsrv(queue_t *q)
820fc80c0dfSnordmark {
821fc80c0dfSnordmark }
822fc80c0dfSnordmark 
823fc80c0dfSnordmark /*
8247c478bd9Sstevel@tonic-gate  * This routine handles synchronous messages passed downstream. It either
8257c478bd9Sstevel@tonic-gate  * consumes the message or passes it downstream; it never queues a
8267c478bd9Sstevel@tonic-gate  * a message. The data messages that go down are wrapped in an IOCTL
8277c478bd9Sstevel@tonic-gate  * message.
8287c478bd9Sstevel@tonic-gate  *
8297c478bd9Sstevel@tonic-gate  * Since it is synchronous, it waits for the M_IOCACK/M_IOCNAK so that
8307c478bd9Sstevel@tonic-gate  * it can return an immediate error (such as ENETUNREACH when adding a route).
8317c478bd9Sstevel@tonic-gate  * It uses the RTS_WRW_PENDING to ensure that each rts instance has only
8327c478bd9Sstevel@tonic-gate  * one M_IOCTL outstanding at any given time.
8337c478bd9Sstevel@tonic-gate  */
8347c478bd9Sstevel@tonic-gate static int
rts_wrw(queue_t * q,struiod_t * dp)8357c478bd9Sstevel@tonic-gate rts_wrw(queue_t *q, struiod_t *dp)
8367c478bd9Sstevel@tonic-gate {
8377c478bd9Sstevel@tonic-gate 	mblk_t	*mp = dp->d_mp;
8387c478bd9Sstevel@tonic-gate 	mblk_t	*mp1;
8397c478bd9Sstevel@tonic-gate 	int	error;
8407c478bd9Sstevel@tonic-gate 	rt_msghdr_t	*rtm;
841fc80c0dfSnordmark 	conn_t	*connp = Q_TO_CONN(q);
842fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 	while (rts->rts_flag & RTS_WRW_PENDING) {
8457c478bd9Sstevel@tonic-gate 		if (qwait_rw(q)) {
8467c478bd9Sstevel@tonic-gate 			rts->rts_error = EINTR;
8477c478bd9Sstevel@tonic-gate 			goto err_ret;
8487c478bd9Sstevel@tonic-gate 		}
8497c478bd9Sstevel@tonic-gate 	}
8507c478bd9Sstevel@tonic-gate 	rts->rts_flag |= RTS_WRW_PENDING;
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 	if (isuioq(q) && (error = struioget(q, mp, dp, 0))) {
8537c478bd9Sstevel@tonic-gate 		/*
8547c478bd9Sstevel@tonic-gate 		 * Uio error of some sort, so just return the error.
8557c478bd9Sstevel@tonic-gate 		 */
8567c478bd9Sstevel@tonic-gate 		rts->rts_error = error;
8577c478bd9Sstevel@tonic-gate 		goto err_ret;
8587c478bd9Sstevel@tonic-gate 	}
8597c478bd9Sstevel@tonic-gate 	/*
8607c478bd9Sstevel@tonic-gate 	 * Pass the mblk (chain) onto wput().
8617c478bd9Sstevel@tonic-gate 	 */
8627c478bd9Sstevel@tonic-gate 	dp->d_mp = 0;
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
8657c478bd9Sstevel@tonic-gate 	case M_PROTO:
8667c478bd9Sstevel@tonic-gate 	case M_PCPROTO:
8677c478bd9Sstevel@tonic-gate 		/* Expedite other than T_DATA_REQ to below the switch */
8687c478bd9Sstevel@tonic-gate 		if (((mp->b_wptr - mp->b_rptr) !=
8697c478bd9Sstevel@tonic-gate 		    sizeof (struct T_data_req)) ||
8707c478bd9Sstevel@tonic-gate 		    (((union T_primitives *)mp->b_rptr)->type != T_DATA_REQ))
8717c478bd9Sstevel@tonic-gate 			break;
8727c478bd9Sstevel@tonic-gate 		if ((mp1 = mp->b_cont) == NULL) {
8737c478bd9Sstevel@tonic-gate 			rts->rts_error = EINVAL;
874a45f3f93Smeem 			freemsg(mp);
8757c478bd9Sstevel@tonic-gate 			goto err_ret;
8767c478bd9Sstevel@tonic-gate 		}
8777c478bd9Sstevel@tonic-gate 		freeb(mp);
8787c478bd9Sstevel@tonic-gate 		mp = mp1;
8797c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
8807c478bd9Sstevel@tonic-gate 	case M_DATA:
8817c478bd9Sstevel@tonic-gate 		/*
8827c478bd9Sstevel@tonic-gate 		 * The semantics of the routing socket is such that the rtm_pid
8837c478bd9Sstevel@tonic-gate 		 * field is automatically filled in during requests with the
8847c478bd9Sstevel@tonic-gate 		 * current process' pid.  We do this here (where we still have
8857c478bd9Sstevel@tonic-gate 		 * user context) after checking we have at least a message the
8867c478bd9Sstevel@tonic-gate 		 * size of a routing message header.
8877c478bd9Sstevel@tonic-gate 		 */
8887c478bd9Sstevel@tonic-gate 		if ((mp->b_wptr - mp->b_rptr) < sizeof (rt_msghdr_t)) {
8897c478bd9Sstevel@tonic-gate 			if (!pullupmsg(mp, sizeof (rt_msghdr_t))) {
8907c478bd9Sstevel@tonic-gate 				rts->rts_error = EINVAL;
891a45f3f93Smeem 				freemsg(mp);
8927c478bd9Sstevel@tonic-gate 				goto err_ret;
8937c478bd9Sstevel@tonic-gate 			}
8947c478bd9Sstevel@tonic-gate 		}
8957c478bd9Sstevel@tonic-gate 		rtm = (rt_msghdr_t *)mp->b_rptr;
8967c478bd9Sstevel@tonic-gate 		rtm->rtm_pid = curproc->p_pid;
8977c478bd9Sstevel@tonic-gate 		break;
8987c478bd9Sstevel@tonic-gate 	default:
8997c478bd9Sstevel@tonic-gate 		break;
9007c478bd9Sstevel@tonic-gate 	}
9017c478bd9Sstevel@tonic-gate 	rts->rts_flag |= RTS_WPUT_PENDING;
9027c478bd9Sstevel@tonic-gate 	rts_wput(q, mp);
9037c478bd9Sstevel@tonic-gate 	while (rts->rts_flag & RTS_WPUT_PENDING)
9047c478bd9Sstevel@tonic-gate 		if (qwait_rw(q)) {
9057c478bd9Sstevel@tonic-gate 			/* RTS_WPUT_PENDING will be cleared below */
9067c478bd9Sstevel@tonic-gate 			rts->rts_error = EINTR;
9077c478bd9Sstevel@tonic-gate 			break;
9087c478bd9Sstevel@tonic-gate 		}
9097c478bd9Sstevel@tonic-gate err_ret:
9107c478bd9Sstevel@tonic-gate 	rts->rts_flag &= ~(RTS_WPUT_PENDING | RTS_WRW_PENDING);
9117c478bd9Sstevel@tonic-gate 	return (rts->rts_error);
9127c478bd9Sstevel@tonic-gate }
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate /*
9157c478bd9Sstevel@tonic-gate  * This routine handles all messages passed downstream. It either
9167c478bd9Sstevel@tonic-gate  * consumes the message or passes it downstream; it never queues a
9177c478bd9Sstevel@tonic-gate  * a message. The data messages that go down are wrapped in an IOCTL
9187c478bd9Sstevel@tonic-gate  * message.
9197c478bd9Sstevel@tonic-gate  */
9207c478bd9Sstevel@tonic-gate static void
rts_wput(queue_t * q,mblk_t * mp)9217c478bd9Sstevel@tonic-gate rts_wput(queue_t *q, mblk_t *mp)
9227c478bd9Sstevel@tonic-gate {
9237c478bd9Sstevel@tonic-gate 	uchar_t	*rptr = mp->b_rptr;
9247c478bd9Sstevel@tonic-gate 	mblk_t	*mp1;
925fc80c0dfSnordmark 	conn_t	*connp = Q_TO_CONN(q);
926fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
9297c478bd9Sstevel@tonic-gate 	case M_DATA:
9307c478bd9Sstevel@tonic-gate 		break;
9317c478bd9Sstevel@tonic-gate 	case M_PROTO:
9327c478bd9Sstevel@tonic-gate 	case M_PCPROTO:
9337c478bd9Sstevel@tonic-gate 		if ((mp->b_wptr - rptr) == sizeof (struct T_data_req)) {
9347c478bd9Sstevel@tonic-gate 			/* Expedite valid T_DATA_REQ to below the switch */
9357c478bd9Sstevel@tonic-gate 			if (((union T_primitives *)rptr)->type == T_DATA_REQ) {
9367c478bd9Sstevel@tonic-gate 				mp1 = mp->b_cont;
9377c478bd9Sstevel@tonic-gate 				freeb(mp);
9387c478bd9Sstevel@tonic-gate 				if (mp1 == NULL)
9397c478bd9Sstevel@tonic-gate 					return;
9407c478bd9Sstevel@tonic-gate 				mp = mp1;
9417c478bd9Sstevel@tonic-gate 				break;
9427c478bd9Sstevel@tonic-gate 			}
9437c478bd9Sstevel@tonic-gate 		}
9447c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
9457c478bd9Sstevel@tonic-gate 	default:
9467c478bd9Sstevel@tonic-gate 		rts_wput_other(q, mp);
9477c478bd9Sstevel@tonic-gate 		return;
9487c478bd9Sstevel@tonic-gate 	}
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate 
951de8c4a14SErik Nordmark 	ASSERT(msg_getcred(mp, NULL) != NULL);
952de8c4a14SErik Nordmark 
953de8c4a14SErik Nordmark 	mp1 = rts_ioctl_alloc(mp);
9547c478bd9Sstevel@tonic-gate 	if (mp1 == NULL) {
9557c478bd9Sstevel@tonic-gate 		ASSERT(rts != NULL);
9567c478bd9Sstevel@tonic-gate 		freemsg(mp);
9577c478bd9Sstevel@tonic-gate 		if (rts->rts_flag & RTS_WPUT_PENDING) {
9587c478bd9Sstevel@tonic-gate 			rts->rts_error = ENOMEM;
9597c478bd9Sstevel@tonic-gate 			rts->rts_flag &= ~RTS_WPUT_PENDING;
9607c478bd9Sstevel@tonic-gate 		}
9617c478bd9Sstevel@tonic-gate 		return;
9627c478bd9Sstevel@tonic-gate 	}
963bd670b35SErik Nordmark 	ip_wput_nondata(q, mp1);
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate /*
9687c478bd9Sstevel@tonic-gate  * Handles all the control message, if it
9697c478bd9Sstevel@tonic-gate  * can not understand it, it will
9707c478bd9Sstevel@tonic-gate  * pass down stream.
9717c478bd9Sstevel@tonic-gate  */
9727c478bd9Sstevel@tonic-gate static void
rts_wput_other(queue_t * q,mblk_t * mp)9737c478bd9Sstevel@tonic-gate rts_wput_other(queue_t *q, mblk_t *mp)
9747c478bd9Sstevel@tonic-gate {
975fc80c0dfSnordmark 	conn_t	*connp = Q_TO_CONN(q);
976fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
9777c478bd9Sstevel@tonic-gate 	uchar_t	*rptr = mp->b_rptr;
9787c478bd9Sstevel@tonic-gate 	struct iocblk	*iocp;
9797c478bd9Sstevel@tonic-gate 	cred_t	*cr;
980f4b3ec61Sdh155122 	rts_stack_t	*rtss;
9817c478bd9Sstevel@tonic-gate 
982f4b3ec61Sdh155122 	rtss = rts->rts_rtss;
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
9857c478bd9Sstevel@tonic-gate 	case M_PROTO:
9867c478bd9Sstevel@tonic-gate 	case M_PCPROTO:
9877c478bd9Sstevel@tonic-gate 		if ((mp->b_wptr - rptr) < sizeof (t_scalar_t)) {
9887c478bd9Sstevel@tonic-gate 			/*
9897c478bd9Sstevel@tonic-gate 			 * If the message does not contain a PRIM_type,
9907c478bd9Sstevel@tonic-gate 			 * throw it away.
9917c478bd9Sstevel@tonic-gate 			 */
9927c478bd9Sstevel@tonic-gate 			freemsg(mp);
9937c478bd9Sstevel@tonic-gate 			return;
9947c478bd9Sstevel@tonic-gate 		}
9957c478bd9Sstevel@tonic-gate 		switch (((union T_primitives *)rptr)->type) {
9967c478bd9Sstevel@tonic-gate 		case T_BIND_REQ:
9977c478bd9Sstevel@tonic-gate 		case O_T_BIND_REQ:
9980f1702c5SYu Xiangning 			rts_tpi_bind(q, mp);
9997c478bd9Sstevel@tonic-gate 			return;
10007c478bd9Sstevel@tonic-gate 		case T_UNBIND_REQ:
10010f1702c5SYu Xiangning 			rts_tpi_unbind(q, mp);
10027c478bd9Sstevel@tonic-gate 			return;
10037c478bd9Sstevel@tonic-gate 		case T_CAPABILITY_REQ:
10047c478bd9Sstevel@tonic-gate 			rts_capability_req(q, mp);
10057c478bd9Sstevel@tonic-gate 			return;
10067c478bd9Sstevel@tonic-gate 		case T_INFO_REQ:
10077c478bd9Sstevel@tonic-gate 			rts_info_req(q, mp);
10087c478bd9Sstevel@tonic-gate 			return;
10097c478bd9Sstevel@tonic-gate 		case T_SVR4_OPTMGMT_REQ:
10107c478bd9Sstevel@tonic-gate 		case T_OPTMGMT_REQ:
1011de8c4a14SErik Nordmark 			/*
1012de8c4a14SErik Nordmark 			 * All Solaris components should pass a db_credp
1013de8c4a14SErik Nordmark 			 * for this TPI message, hence we ASSERT.
1014de8c4a14SErik Nordmark 			 * But in case there is some other M_PROTO that looks
1015de8c4a14SErik Nordmark 			 * like a TPI message sent by some other kernel
1016de8c4a14SErik Nordmark 			 * component, we check and return an error.
1017de8c4a14SErik Nordmark 			 */
1018de8c4a14SErik Nordmark 			cr = msg_getcred(mp, NULL);
1019de8c4a14SErik Nordmark 			ASSERT(cr != NULL);
1020de8c4a14SErik Nordmark 			if (cr == NULL) {
1021de8c4a14SErik Nordmark 				rts_err_ack(q, mp, TSYSERR, EINVAL);
1022de8c4a14SErik Nordmark 				return;
1023de8c4a14SErik Nordmark 			}
1024de8c4a14SErik Nordmark 			if (((union T_primitives *)rptr)->type ==
1025de8c4a14SErik Nordmark 			    T_SVR4_OPTMGMT_REQ) {
1026bd670b35SErik Nordmark 				svr4_optcom_req(q, mp, cr, &rts_opt_obj);
1027de8c4a14SErik Nordmark 			} else {
1028bd670b35SErik Nordmark 				tpi_optcom_req(q, mp, cr, &rts_opt_obj);
1029de8c4a14SErik Nordmark 			}
10307c478bd9Sstevel@tonic-gate 			return;
10317c478bd9Sstevel@tonic-gate 		case O_T_CONN_RES:
10327c478bd9Sstevel@tonic-gate 		case T_CONN_RES:
10337c478bd9Sstevel@tonic-gate 		case T_DISCON_REQ:
10347c478bd9Sstevel@tonic-gate 			/* Not supported by rts. */
10357c478bd9Sstevel@tonic-gate 			rts_err_ack(q, mp, TNOTSUPPORT, 0);
10367c478bd9Sstevel@tonic-gate 			return;
10377c478bd9Sstevel@tonic-gate 		case T_DATA_REQ:
10387c478bd9Sstevel@tonic-gate 		case T_EXDATA_REQ:
10397c478bd9Sstevel@tonic-gate 		case T_ORDREL_REQ:
10407c478bd9Sstevel@tonic-gate 			/* Illegal for rts. */
10417c478bd9Sstevel@tonic-gate 			freemsg(mp);
10427c478bd9Sstevel@tonic-gate 			(void) putnextctl1(RD(q), M_ERROR, EPROTO);
10437c478bd9Sstevel@tonic-gate 			return;
10440f1702c5SYu Xiangning 
10457c478bd9Sstevel@tonic-gate 		default:
10467c478bd9Sstevel@tonic-gate 			break;
10477c478bd9Sstevel@tonic-gate 		}
10487c478bd9Sstevel@tonic-gate 		break;
10497c478bd9Sstevel@tonic-gate 	case M_IOCTL:
10507c478bd9Sstevel@tonic-gate 		iocp = (struct iocblk *)mp->b_rptr;
10517c478bd9Sstevel@tonic-gate 		switch (iocp->ioc_cmd) {
10527c478bd9Sstevel@tonic-gate 		case ND_SET:
10537c478bd9Sstevel@tonic-gate 		case ND_GET:
1054f4b3ec61Sdh155122 			if (nd_getset(q, rtss->rtss_g_nd, mp)) {
10557c478bd9Sstevel@tonic-gate 				qreply(q, mp);
10567c478bd9Sstevel@tonic-gate 				return;
10577c478bd9Sstevel@tonic-gate 			}
10587c478bd9Sstevel@tonic-gate 			break;
10597c478bd9Sstevel@tonic-gate 		case TI_GETPEERNAME:
10607c478bd9Sstevel@tonic-gate 			mi_copyin(q, mp, NULL,
10617c478bd9Sstevel@tonic-gate 			    SIZEOF_STRUCT(strbuf, iocp->ioc_flag));
10627c478bd9Sstevel@tonic-gate 			return;
10637c478bd9Sstevel@tonic-gate 		default:
10647c478bd9Sstevel@tonic-gate 			break;
10657c478bd9Sstevel@tonic-gate 		}
10667c478bd9Sstevel@tonic-gate 	case M_IOCDATA:
10677c478bd9Sstevel@tonic-gate 		rts_wput_iocdata(q, mp);
10687c478bd9Sstevel@tonic-gate 		return;
10697c478bd9Sstevel@tonic-gate 	default:
10707c478bd9Sstevel@tonic-gate 		break;
10717c478bd9Sstevel@tonic-gate 	}
1072bd670b35SErik Nordmark 	ip_wput_nondata(q, mp);
10737c478bd9Sstevel@tonic-gate }
10747c478bd9Sstevel@tonic-gate 
10757c478bd9Sstevel@tonic-gate /*
10767c478bd9Sstevel@tonic-gate  * Called by rts_wput_other to handle all M_IOCDATA messages.
10777c478bd9Sstevel@tonic-gate  */
10787c478bd9Sstevel@tonic-gate static void
rts_wput_iocdata(queue_t * q,mblk_t * mp)10797c478bd9Sstevel@tonic-gate rts_wput_iocdata(queue_t *q, mblk_t *mp)
10807c478bd9Sstevel@tonic-gate {
10817c478bd9Sstevel@tonic-gate 	struct sockaddr	*rtsaddr;
10827c478bd9Sstevel@tonic-gate 	mblk_t	*mp1;
10837c478bd9Sstevel@tonic-gate 	STRUCT_HANDLE(strbuf, sb);
10847c478bd9Sstevel@tonic-gate 	struct iocblk	*iocp	= (struct iocblk *)mp->b_rptr;
10857c478bd9Sstevel@tonic-gate 
10867c478bd9Sstevel@tonic-gate 	/* Make sure it is one of ours. */
10877c478bd9Sstevel@tonic-gate 	switch (iocp->ioc_cmd) {
10887c478bd9Sstevel@tonic-gate 	case TI_GETPEERNAME:
10897c478bd9Sstevel@tonic-gate 		break;
10907c478bd9Sstevel@tonic-gate 	default:
1091bd670b35SErik Nordmark 		ip_wput_nondata(q, mp);
10927c478bd9Sstevel@tonic-gate 		return;
10937c478bd9Sstevel@tonic-gate 	}
10947c478bd9Sstevel@tonic-gate 	switch (mi_copy_state(q, mp, &mp1)) {
10957c478bd9Sstevel@tonic-gate 	case -1:
10967c478bd9Sstevel@tonic-gate 		return;
10977c478bd9Sstevel@tonic-gate 	case MI_COPY_CASE(MI_COPY_IN, 1):
10987c478bd9Sstevel@tonic-gate 		break;
10997c478bd9Sstevel@tonic-gate 	case MI_COPY_CASE(MI_COPY_OUT, 1):
11007c478bd9Sstevel@tonic-gate 		/* Copy out the strbuf. */
11017c478bd9Sstevel@tonic-gate 		mi_copyout(q, mp);
11027c478bd9Sstevel@tonic-gate 		return;
11037c478bd9Sstevel@tonic-gate 	case MI_COPY_CASE(MI_COPY_OUT, 2):
11047c478bd9Sstevel@tonic-gate 		/* All done. */
11057c478bd9Sstevel@tonic-gate 		mi_copy_done(q, mp, 0);
11067c478bd9Sstevel@tonic-gate 		return;
11077c478bd9Sstevel@tonic-gate 	default:
11087c478bd9Sstevel@tonic-gate 		mi_copy_done(q, mp, EPROTO);
11097c478bd9Sstevel@tonic-gate 		return;
11107c478bd9Sstevel@tonic-gate 	}
11117c478bd9Sstevel@tonic-gate 	STRUCT_SET_HANDLE(sb, iocp->ioc_flag, (void *)mp1->b_rptr);
11127c478bd9Sstevel@tonic-gate 	if (STRUCT_FGET(sb, maxlen) < (int)sizeof (sin_t)) {
11137c478bd9Sstevel@tonic-gate 		mi_copy_done(q, mp, EINVAL);
11147c478bd9Sstevel@tonic-gate 		return;
11157c478bd9Sstevel@tonic-gate 	}
11167c478bd9Sstevel@tonic-gate 	switch (iocp->ioc_cmd) {
11177c478bd9Sstevel@tonic-gate 	case TI_GETPEERNAME:
11187c478bd9Sstevel@tonic-gate 		break;
11197c478bd9Sstevel@tonic-gate 	default:
11207c478bd9Sstevel@tonic-gate 		mi_copy_done(q, mp, EPROTO);
11217c478bd9Sstevel@tonic-gate 		return;
11227c478bd9Sstevel@tonic-gate 	}
11237c478bd9Sstevel@tonic-gate 	mp1 = mi_copyout_alloc(q, mp, STRUCT_FGETP(sb, buf), sizeof (sin_t),
11247c478bd9Sstevel@tonic-gate 	    B_TRUE);
11257c478bd9Sstevel@tonic-gate 	if (mp1 == NULL)
11267c478bd9Sstevel@tonic-gate 		return;
11277c478bd9Sstevel@tonic-gate 	STRUCT_FSET(sb, len, (int)sizeof (sin_t));
11287c478bd9Sstevel@tonic-gate 	rtsaddr = (struct sockaddr *)mp1->b_rptr;
11297c478bd9Sstevel@tonic-gate 	mp1->b_wptr = (uchar_t *)&rtsaddr[1];
11307c478bd9Sstevel@tonic-gate 	bzero(rtsaddr, sizeof (struct sockaddr));
11317c478bd9Sstevel@tonic-gate 	rtsaddr->sa_family = AF_ROUTE;
11327c478bd9Sstevel@tonic-gate 	/* Copy out the address */
11337c478bd9Sstevel@tonic-gate 	mi_copyout(q, mp);
11347c478bd9Sstevel@tonic-gate }
11357c478bd9Sstevel@tonic-gate 
1136bd670b35SErik Nordmark /*
1137bd670b35SErik Nordmark  * IP passes up a NULL ira.
1138bd670b35SErik Nordmark  */
1139fc80c0dfSnordmark /*ARGSUSED2*/
11407c478bd9Sstevel@tonic-gate static void
rts_input(void * arg1,mblk_t * mp,void * arg2,ip_recv_attr_t * ira)1141bd670b35SErik Nordmark rts_input(void *arg1, mblk_t *mp, void *arg2, ip_recv_attr_t *ira)
11427c478bd9Sstevel@tonic-gate {
1143fc80c0dfSnordmark 	conn_t *connp = (conn_t *)arg1;
1144fc80c0dfSnordmark 	rts_t	*rts = connp->conn_rts;
11457c478bd9Sstevel@tonic-gate 	struct iocblk	*iocp;
11467c478bd9Sstevel@tonic-gate 	mblk_t *mp1;
11477c478bd9Sstevel@tonic-gate 	struct T_data_ind *tdi;
11480f1702c5SYu Xiangning 	int	error;
11497c478bd9Sstevel@tonic-gate 
11507c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
11517c478bd9Sstevel@tonic-gate 	case M_IOCACK:
11527c478bd9Sstevel@tonic-gate 	case M_IOCNAK:
11537c478bd9Sstevel@tonic-gate 		iocp = (struct iocblk *)mp->b_rptr;
1154bd670b35SErik Nordmark 		ASSERT(!IPCL_IS_NONSTR(connp));
1155fc80c0dfSnordmark 		if (rts->rts_flag & (RTS_WPUT_PENDING)) {
11567c478bd9Sstevel@tonic-gate 			rts->rts_flag &= ~RTS_WPUT_PENDING;
11577c478bd9Sstevel@tonic-gate 			rts->rts_error = iocp->ioc_error;
1158fc80c0dfSnordmark 			/*
1159fc80c0dfSnordmark 			 * Tell rts_wvw/qwait that we are done.
1160fc80c0dfSnordmark 			 * Note: there is no qwait_wakeup() we can use.
1161fc80c0dfSnordmark 			 */
1162fc80c0dfSnordmark 			qenable(connp->conn_rq);
11637c478bd9Sstevel@tonic-gate 			freemsg(mp);
11647c478bd9Sstevel@tonic-gate 			return;
11657c478bd9Sstevel@tonic-gate 		}
11667c478bd9Sstevel@tonic-gate 		break;
11677c478bd9Sstevel@tonic-gate 	case M_DATA:
11687c478bd9Sstevel@tonic-gate 		/*
11697c478bd9Sstevel@tonic-gate 		 * Prepend T_DATA_IND to prevent the stream head from
11707c478bd9Sstevel@tonic-gate 		 * consolidating multiple messages together.
11717c478bd9Sstevel@tonic-gate 		 * If the allocation fails just send up the M_DATA.
11727c478bd9Sstevel@tonic-gate 		 */
11737c478bd9Sstevel@tonic-gate 		mp1 = allocb(sizeof (*tdi), BPRI_MED);
11747c478bd9Sstevel@tonic-gate 		if (mp1 != NULL) {
11757c478bd9Sstevel@tonic-gate 			mp1->b_cont = mp;
11767c478bd9Sstevel@tonic-gate 			mp = mp1;
11777c478bd9Sstevel@tonic-gate 
11787c478bd9Sstevel@tonic-gate 			mp->b_datap->db_type = M_PROTO;
11797c478bd9Sstevel@tonic-gate 			mp->b_wptr += sizeof (*tdi);
11807c478bd9Sstevel@tonic-gate 			tdi = (struct T_data_ind *)mp->b_rptr;
11817c478bd9Sstevel@tonic-gate 			tdi->PRIM_type = T_DATA_IND;
11827c478bd9Sstevel@tonic-gate 			tdi->MORE_flag = 0;
11837c478bd9Sstevel@tonic-gate 		}
11847c478bd9Sstevel@tonic-gate 		break;
11857c478bd9Sstevel@tonic-gate 	default:
11867c478bd9Sstevel@tonic-gate 		break;
11877c478bd9Sstevel@tonic-gate 	}
11880f1702c5SYu Xiangning 
11890f1702c5SYu Xiangning 	if (IPCL_IS_NONSTR(connp)) {
11900f1702c5SYu Xiangning 		if ((*connp->conn_upcalls->su_recv)
11910f1702c5SYu Xiangning 		    (connp->conn_upper_handle, mp, msgdsize(mp), 0,
11920f1702c5SYu Xiangning 		    &error, NULL) < 0) {
11930f1702c5SYu Xiangning 			ASSERT(error == ENOSPC);
11940f1702c5SYu Xiangning 			/*
11950f1702c5SYu Xiangning 			 * Let's confirm hoding the lock that
11960f1702c5SYu Xiangning 			 * we are out of recv space.
11970f1702c5SYu Xiangning 			 */
11980f1702c5SYu Xiangning 			mutex_enter(&rts->rts_recv_mutex);
11990f1702c5SYu Xiangning 			if ((*connp->conn_upcalls->su_recv)
12000f1702c5SYu Xiangning 			    (connp->conn_upper_handle, NULL, 0, 0,
12010f1702c5SYu Xiangning 			    &error, NULL) < 0) {
12020f1702c5SYu Xiangning 				ASSERT(error == ENOSPC);
12030f1702c5SYu Xiangning 				connp->conn_flow_cntrld = B_TRUE;
12040f1702c5SYu Xiangning 			}
12050f1702c5SYu Xiangning 			mutex_exit(&rts->rts_recv_mutex);
12060f1702c5SYu Xiangning 		}
12070f1702c5SYu Xiangning 	} else {
1208fc80c0dfSnordmark 		putnext(connp->conn_rq, mp);
12097c478bd9Sstevel@tonic-gate 	}
12100f1702c5SYu Xiangning }
12117c478bd9Sstevel@tonic-gate 
1212bd670b35SErik Nordmark /*ARGSUSED*/
1213bd670b35SErik Nordmark static void
rts_icmp_input(void * arg1,mblk_t * mp,void * arg2,ip_recv_attr_t * ira)1214bd670b35SErik Nordmark rts_icmp_input(void *arg1, mblk_t *mp, void *arg2, ip_recv_attr_t *ira)
1215bd670b35SErik Nordmark {
1216bd670b35SErik Nordmark 	freemsg(mp);
1217bd670b35SErik Nordmark }
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate void
rts_ddi_g_init(void)12200f1702c5SYu Xiangning rts_ddi_g_init(void)
12217c478bd9Sstevel@tonic-gate {
12227c478bd9Sstevel@tonic-gate 	rts_max_optsize = optcom_max_optsize(rts_opt_obj.odb_opt_des_arr,
12237c478bd9Sstevel@tonic-gate 	    rts_opt_obj.odb_opt_arr_cnt);
1224f4b3ec61Sdh155122 
1225f4b3ec61Sdh155122 	/*
1226f4b3ec61Sdh155122 	 * We want to be informed each time a stack is created or
1227f4b3ec61Sdh155122 	 * destroyed in the kernel, so we can maintain the
1228f4b3ec61Sdh155122 	 * set of rts_stack_t's.
1229f4b3ec61Sdh155122 	 */
1230f4b3ec61Sdh155122 	netstack_register(NS_RTS, rts_stack_init, NULL, rts_stack_fini);
1231f4b3ec61Sdh155122 }
1232f4b3ec61Sdh155122 
1233f4b3ec61Sdh155122 void
rts_ddi_g_destroy(void)12340f1702c5SYu Xiangning rts_ddi_g_destroy(void)
1235f4b3ec61Sdh155122 {
1236f4b3ec61Sdh155122 	netstack_unregister(NS_RTS);
1237f4b3ec61Sdh155122 }
1238f4b3ec61Sdh155122 
12390f1702c5SYu Xiangning #define	INET_NAME	"ip"
12400f1702c5SYu Xiangning 
1241f4b3ec61Sdh155122 /*
1242f4b3ec61Sdh155122  * Initialize the RTS stack instance.
1243f4b3ec61Sdh155122  */
1244f4b3ec61Sdh155122 /* ARGSUSED */
1245f4b3ec61Sdh155122 static void *
rts_stack_init(netstackid_t stackid,netstack_t * ns)1246f4b3ec61Sdh155122 rts_stack_init(netstackid_t stackid, netstack_t *ns)
1247f4b3ec61Sdh155122 {
1248f4b3ec61Sdh155122 	rts_stack_t	*rtss;
1249f4b3ec61Sdh155122 	rtsparam_t	*pa;
12500f1702c5SYu Xiangning 	int		error = 0;
12510f1702c5SYu Xiangning 	major_t		major;
1252f4b3ec61Sdh155122 
1253f4b3ec61Sdh155122 	rtss = (rts_stack_t *)kmem_zalloc(sizeof (*rtss), KM_SLEEP);
1254f4b3ec61Sdh155122 	rtss->rtss_netstack = ns;
1255f4b3ec61Sdh155122 
1256f4b3ec61Sdh155122 	pa = (rtsparam_t *)kmem_alloc(sizeof (lcl_param_arr), KM_SLEEP);
1257f4b3ec61Sdh155122 	rtss->rtss_params = pa;
1258f4b3ec61Sdh155122 	bcopy(lcl_param_arr, rtss->rtss_params, sizeof (lcl_param_arr));
1259f4b3ec61Sdh155122 
1260f4b3ec61Sdh155122 	(void) rts_param_register(&rtss->rtss_g_nd,
1261f4b3ec61Sdh155122 	    rtss->rtss_params, A_CNT(lcl_param_arr));
12620f1702c5SYu Xiangning 
12630f1702c5SYu Xiangning 	major = mod_name_to_major(INET_NAME);
12640f1702c5SYu Xiangning 	error = ldi_ident_from_major(major, &rtss->rtss_ldi_ident);
12650f1702c5SYu Xiangning 	ASSERT(error == 0);
1266f4b3ec61Sdh155122 	return (rtss);
1267f4b3ec61Sdh155122 }
1268f4b3ec61Sdh155122 
1269f4b3ec61Sdh155122 /*
1270f4b3ec61Sdh155122  * Free the RTS stack instance.
1271f4b3ec61Sdh155122  */
1272f4b3ec61Sdh155122 /* ARGSUSED */
1273f4b3ec61Sdh155122 static void
rts_stack_fini(netstackid_t stackid,void * arg)1274f4b3ec61Sdh155122 rts_stack_fini(netstackid_t stackid, void *arg)
1275f4b3ec61Sdh155122 {
1276f4b3ec61Sdh155122 	rts_stack_t *rtss = (rts_stack_t *)arg;
1277f4b3ec61Sdh155122 
1278fc80c0dfSnordmark 	nd_free(&rtss->rtss_g_nd);
1279f4b3ec61Sdh155122 	kmem_free(rtss->rtss_params, sizeof (lcl_param_arr));
1280f4b3ec61Sdh155122 	rtss->rtss_params = NULL;
12810f1702c5SYu Xiangning 	ldi_ident_release(rtss->rtss_ldi_ident);
1282f4b3ec61Sdh155122 	kmem_free(rtss, sizeof (*rtss));
12837c478bd9Sstevel@tonic-gate }
12840f1702c5SYu Xiangning 
12850f1702c5SYu Xiangning /* ARGSUSED */
12860f1702c5SYu Xiangning int
rts_accept(sock_lower_handle_t lproto_handle,sock_lower_handle_t eproto_handle,sock_upper_handle_t sock_handle,cred_t * cr)12870f1702c5SYu Xiangning rts_accept(sock_lower_handle_t lproto_handle,
12880f1702c5SYu Xiangning     sock_lower_handle_t eproto_handle, sock_upper_handle_t sock_handle,
12890f1702c5SYu Xiangning     cred_t *cr)
12900f1702c5SYu Xiangning {
12910f1702c5SYu Xiangning 	return (EINVAL);
12920f1702c5SYu Xiangning }
12930f1702c5SYu Xiangning 
12940f1702c5SYu Xiangning /* ARGSUSED */
12950f1702c5SYu Xiangning static int
rts_bind(sock_lower_handle_t proto_handle,struct sockaddr * sa,socklen_t len,cred_t * cr)12960f1702c5SYu Xiangning rts_bind(sock_lower_handle_t proto_handle, struct sockaddr *sa,
12970f1702c5SYu Xiangning     socklen_t len, cred_t *cr)
12980f1702c5SYu Xiangning {
12990f1702c5SYu Xiangning 	/*
13000f1702c5SYu Xiangning 	 * rebind not allowed
13010f1702c5SYu Xiangning 	 */
13020f1702c5SYu Xiangning 	return (EINVAL);
13030f1702c5SYu Xiangning }
13040f1702c5SYu Xiangning 
13050f1702c5SYu Xiangning /* ARGSUSED */
13060f1702c5SYu Xiangning int
rts_listen(sock_lower_handle_t proto_handle,int backlog,cred_t * cr)13070f1702c5SYu Xiangning rts_listen(sock_lower_handle_t proto_handle, int backlog, cred_t *cr)
13080f1702c5SYu Xiangning {
13090f1702c5SYu Xiangning 	return (EINVAL);
13100f1702c5SYu Xiangning }
13110f1702c5SYu Xiangning 
13120f1702c5SYu Xiangning /* ARGSUSED */
13130f1702c5SYu Xiangning int
rts_connect(sock_lower_handle_t proto_handle,const struct sockaddr * sa,socklen_t len,sock_connid_t * id,cred_t * cr)13140f1702c5SYu Xiangning rts_connect(sock_lower_handle_t proto_handle, const struct sockaddr *sa,
13150f1702c5SYu Xiangning     socklen_t len, sock_connid_t *id, cred_t *cr)
13160f1702c5SYu Xiangning {
13170f1702c5SYu Xiangning 	/*
13180f1702c5SYu Xiangning 	 * rts sockets start out as bound and connected
13190f1702c5SYu Xiangning 	 */
13200f1702c5SYu Xiangning 	*id = 0;
13210f1702c5SYu Xiangning 	return (EISCONN);
13220f1702c5SYu Xiangning }
13230f1702c5SYu Xiangning 
13240f1702c5SYu Xiangning /* ARGSUSED */
13250f1702c5SYu Xiangning int
rts_getpeername(sock_lower_handle_t proto_handle,struct sockaddr * addr,socklen_t * addrlen,cred_t * cr)13260f1702c5SYu Xiangning rts_getpeername(sock_lower_handle_t proto_handle, struct sockaddr *addr,
13270f1702c5SYu Xiangning     socklen_t *addrlen, cred_t *cr)
13280f1702c5SYu Xiangning {
13290f1702c5SYu Xiangning 	bzero(addr, sizeof (struct sockaddr));
13300f1702c5SYu Xiangning 	addr->sa_family = AF_ROUTE;
13310f1702c5SYu Xiangning 	*addrlen = sizeof (struct sockaddr);
13320f1702c5SYu Xiangning 
13330f1702c5SYu Xiangning 	return (0);
13340f1702c5SYu Xiangning }
13350f1702c5SYu Xiangning 
13360f1702c5SYu Xiangning /* ARGSUSED */
13370f1702c5SYu Xiangning int
rts_getsockname(sock_lower_handle_t proto_handle,struct sockaddr * addr,socklen_t * addrlen,cred_t * cr)13380f1702c5SYu Xiangning rts_getsockname(sock_lower_handle_t proto_handle, struct sockaddr *addr,
13390f1702c5SYu Xiangning     socklen_t *addrlen, cred_t *cr)
13400f1702c5SYu Xiangning {
1341bd670b35SErik Nordmark 	bzero(addr, sizeof (struct sockaddr));
1342bd670b35SErik Nordmark 	addr->sa_family = AF_ROUTE;
1343bd670b35SErik Nordmark 	*addrlen = sizeof (struct sockaddr);
1344bd670b35SErik Nordmark 
1345bd670b35SErik Nordmark 	return (0);
13460f1702c5SYu Xiangning }
13470f1702c5SYu Xiangning 
13480f1702c5SYu Xiangning static int
rts_getsockopt(sock_lower_handle_t proto_handle,int level,int option_name,void * optvalp,socklen_t * optlen,cred_t * cr)13490f1702c5SYu Xiangning rts_getsockopt(sock_lower_handle_t proto_handle, int level, int option_name,
13500f1702c5SYu Xiangning     void *optvalp, socklen_t *optlen, cred_t *cr)
13510f1702c5SYu Xiangning {
13520f1702c5SYu Xiangning 	conn_t  	*connp = (conn_t *)proto_handle;
13530f1702c5SYu Xiangning 	rts_t		*rts = connp->conn_rts;
13540f1702c5SYu Xiangning 	int		error;
13550f1702c5SYu Xiangning 	t_uscalar_t	max_optbuf_len;
13560f1702c5SYu Xiangning 	void		*optvalp_buf;
13570f1702c5SYu Xiangning 	int		len;
13580f1702c5SYu Xiangning 
13590f1702c5SYu Xiangning 	error = proto_opt_check(level, option_name, *optlen, &max_optbuf_len,
13600f1702c5SYu Xiangning 	    rts_opt_obj.odb_opt_des_arr,
13610f1702c5SYu Xiangning 	    rts_opt_obj.odb_opt_arr_cnt,
13620f1702c5SYu Xiangning 	    B_FALSE, B_TRUE, cr);
13630f1702c5SYu Xiangning 	if (error != 0) {
13640f1702c5SYu Xiangning 		if (error < 0)
13650f1702c5SYu Xiangning 			error = proto_tlitosyserr(-error);
13660f1702c5SYu Xiangning 		return (error);
13670f1702c5SYu Xiangning 	}
13680f1702c5SYu Xiangning 
13690f1702c5SYu Xiangning 	optvalp_buf = kmem_alloc(max_optbuf_len, KM_SLEEP);
13700f1702c5SYu Xiangning 	rw_enter(&rts->rts_rwlock, RW_READER);
13710f1702c5SYu Xiangning 	len = rts_opt_get(connp, level, option_name, optvalp_buf);
13720f1702c5SYu Xiangning 	rw_exit(&rts->rts_rwlock);
1373bd670b35SErik Nordmark 	if (len == -1) {
1374bd670b35SErik Nordmark 		kmem_free(optvalp_buf, max_optbuf_len);
1375bd670b35SErik Nordmark 		return (EINVAL);
1376bd670b35SErik Nordmark 	}
13770f1702c5SYu Xiangning 
13780f1702c5SYu Xiangning 	/*
13790f1702c5SYu Xiangning 	 * update optlen and copy option value
13800f1702c5SYu Xiangning 	 */
13810f1702c5SYu Xiangning 	t_uscalar_t size = MIN(len, *optlen);
1382bd670b35SErik Nordmark 
13830f1702c5SYu Xiangning 	bcopy(optvalp_buf, optvalp, size);
13840f1702c5SYu Xiangning 	bcopy(&size, optlen, sizeof (size));
13850f1702c5SYu Xiangning 	kmem_free(optvalp_buf, max_optbuf_len);
1386bd670b35SErik Nordmark 	return (0);
13870f1702c5SYu Xiangning }
13880f1702c5SYu Xiangning 
13890f1702c5SYu Xiangning static int
rts_setsockopt(sock_lower_handle_t proto_handle,int level,int option_name,const void * optvalp,socklen_t optlen,cred_t * cr)13900f1702c5SYu Xiangning rts_setsockopt(sock_lower_handle_t proto_handle, int level, int option_name,
13910f1702c5SYu Xiangning     const void *optvalp, socklen_t optlen, cred_t *cr)
13920f1702c5SYu Xiangning {
13930f1702c5SYu Xiangning 	conn_t	*connp = (conn_t *)proto_handle;
13940f1702c5SYu Xiangning 	rts_t	*rts = connp->conn_rts;
13950f1702c5SYu Xiangning 	int	error;
13960f1702c5SYu Xiangning 
13970f1702c5SYu Xiangning 	error = proto_opt_check(level, option_name, optlen, NULL,
13980f1702c5SYu Xiangning 	    rts_opt_obj.odb_opt_des_arr,
13990f1702c5SYu Xiangning 	    rts_opt_obj.odb_opt_arr_cnt,
14000f1702c5SYu Xiangning 	    B_TRUE, B_FALSE, cr);
14010f1702c5SYu Xiangning 
14020f1702c5SYu Xiangning 	if (error != 0) {
14030f1702c5SYu Xiangning 		if (error < 0)
14040f1702c5SYu Xiangning 			error = proto_tlitosyserr(-error);
14050f1702c5SYu Xiangning 		return (error);
14060f1702c5SYu Xiangning 	}
14070f1702c5SYu Xiangning 
14080f1702c5SYu Xiangning 	rw_enter(&rts->rts_rwlock, RW_WRITER);
14090f1702c5SYu Xiangning 	error = rts_opt_set(connp, SETFN_OPTCOM_NEGOTIATE, level, option_name,
14100f1702c5SYu Xiangning 	    optlen, (uchar_t *)optvalp, (uint_t *)&optlen, (uchar_t *)optvalp,
14110f1702c5SYu Xiangning 	    NULL, cr);
14120f1702c5SYu Xiangning 	rw_exit(&rts->rts_rwlock);
14130f1702c5SYu Xiangning 
14140f1702c5SYu Xiangning 	ASSERT(error >= 0);
14150f1702c5SYu Xiangning 
14160f1702c5SYu Xiangning 	return (error);
14170f1702c5SYu Xiangning }
14180f1702c5SYu Xiangning 
14190f1702c5SYu Xiangning /* ARGSUSED */
14200f1702c5SYu Xiangning static int
rts_send(sock_lower_handle_t proto_handle,mblk_t * mp,struct nmsghdr * msg,cred_t * cr)14210f1702c5SYu Xiangning rts_send(sock_lower_handle_t proto_handle, mblk_t *mp,
14220f1702c5SYu Xiangning     struct nmsghdr *msg, cred_t *cr)
14230f1702c5SYu Xiangning {
14240f1702c5SYu Xiangning 	conn_t  *connp = (conn_t *)proto_handle;
14250f1702c5SYu Xiangning 	rt_msghdr_t	*rtm;
14260f1702c5SYu Xiangning 	int error;
14270f1702c5SYu Xiangning 
14280f1702c5SYu Xiangning 	ASSERT(DB_TYPE(mp) == M_DATA);
14290f1702c5SYu Xiangning 	/*
14300f1702c5SYu Xiangning 	 * The semantics of the routing socket is such that the rtm_pid
14310f1702c5SYu Xiangning 	 * field is automatically filled in during requests with the
14320f1702c5SYu Xiangning 	 * current process' pid.  We do this here (where we still have
14330f1702c5SYu Xiangning 	 * user context) after checking we have at least a message the
14340f1702c5SYu Xiangning 	 * size of a routing message header.
14350f1702c5SYu Xiangning 	 */
14360f1702c5SYu Xiangning 	if ((mp->b_wptr - mp->b_rptr) < sizeof (rt_msghdr_t)) {
14370f1702c5SYu Xiangning 		if (!pullupmsg(mp, sizeof (rt_msghdr_t))) {
14380f1702c5SYu Xiangning 			freemsg(mp);
1439bd670b35SErik Nordmark 			return (EINVAL);
14400f1702c5SYu Xiangning 		}
14410f1702c5SYu Xiangning 	}
14420f1702c5SYu Xiangning 	rtm = (rt_msghdr_t *)mp->b_rptr;
14430f1702c5SYu Xiangning 	rtm->rtm_pid = curproc->p_pid;
14440f1702c5SYu Xiangning 
14450f1702c5SYu Xiangning 	/*
1446bd670b35SErik Nordmark 	 * We are not constrained by the ioctl interface and
1447bd670b35SErik Nordmark 	 * ip_rts_request_common processing requests synchronously hence
1448bd670b35SErik Nordmark 	 * we can send them down concurrently.
14490f1702c5SYu Xiangning 	 */
1450bd670b35SErik Nordmark 	error = ip_rts_request_common(mp, connp, cr);
14510f1702c5SYu Xiangning 	return (error);
14520f1702c5SYu Xiangning }
14530f1702c5SYu Xiangning 
14540f1702c5SYu Xiangning /* ARGSUSED */
14550f1702c5SYu Xiangning sock_lower_handle_t
rts_create(int family,int type,int proto,sock_downcalls_t ** sock_downcalls,uint_t * smodep,int * errorp,int flags,cred_t * credp)14560f1702c5SYu Xiangning rts_create(int family, int type, int proto, sock_downcalls_t **sock_downcalls,
14570f1702c5SYu Xiangning     uint_t *smodep, int *errorp, int flags, cred_t *credp)
14580f1702c5SYu Xiangning {
14590f1702c5SYu Xiangning 	conn_t	*connp;
14600f1702c5SYu Xiangning 
14610f1702c5SYu Xiangning 	if (family != AF_ROUTE || type != SOCK_RAW ||
14620f1702c5SYu Xiangning 	    (proto != 0 && proto != AF_INET && proto != AF_INET6)) {
14630f1702c5SYu Xiangning 		*errorp = EPROTONOSUPPORT;
14640f1702c5SYu Xiangning 		return (NULL);
14650f1702c5SYu Xiangning 	}
14660f1702c5SYu Xiangning 
14670f1702c5SYu Xiangning 	connp = rts_open(flags, credp);
14680f1702c5SYu Xiangning 	ASSERT(connp != NULL);
14690f1702c5SYu Xiangning 	connp->conn_flags |= IPCL_NONSTR;
14700f1702c5SYu Xiangning 
1471bd670b35SErik Nordmark 	connp->conn_proto = proto;
14720f1702c5SYu Xiangning 
14730f1702c5SYu Xiangning 	mutex_enter(&connp->conn_lock);
14740f1702c5SYu Xiangning 	connp->conn_state_flags &= ~CONN_INCIPIENT;
14750f1702c5SYu Xiangning 	mutex_exit(&connp->conn_lock);
14760f1702c5SYu Xiangning 
14770f1702c5SYu Xiangning 	*errorp = 0;
14780f1702c5SYu Xiangning 	*smodep = SM_ATOMIC;
14790f1702c5SYu Xiangning 	*sock_downcalls = &sock_rts_downcalls;
14800f1702c5SYu Xiangning 	return ((sock_lower_handle_t)connp);
14810f1702c5SYu Xiangning }
14820f1702c5SYu Xiangning 
14830f1702c5SYu Xiangning /* ARGSUSED */
14840f1702c5SYu Xiangning void
rts_activate(sock_lower_handle_t proto_handle,sock_upper_handle_t sock_handle,sock_upcalls_t * sock_upcalls,int flags,cred_t * cr)14850f1702c5SYu Xiangning rts_activate(sock_lower_handle_t proto_handle, sock_upper_handle_t sock_handle,
14860f1702c5SYu Xiangning     sock_upcalls_t *sock_upcalls, int flags, cred_t *cr)
14870f1702c5SYu Xiangning {
14880f1702c5SYu Xiangning 	conn_t  *connp = (conn_t *)proto_handle;
14890f1702c5SYu Xiangning 	struct sock_proto_props sopp;
14900f1702c5SYu Xiangning 
14910f1702c5SYu Xiangning 	connp->conn_upcalls = sock_upcalls;
14920f1702c5SYu Xiangning 	connp->conn_upper_handle = sock_handle;
14930f1702c5SYu Xiangning 
14940f1702c5SYu Xiangning 	sopp.sopp_flags = SOCKOPT_WROFF | SOCKOPT_RCVHIWAT | SOCKOPT_RCVLOWAT |
14950f1702c5SYu Xiangning 	    SOCKOPT_MAXBLK | SOCKOPT_MAXPSZ | SOCKOPT_MINPSZ;
14960f1702c5SYu Xiangning 	sopp.sopp_wroff = 0;
1497bd670b35SErik Nordmark 	sopp.sopp_rxhiwat = connp->conn_rcvbuf;
1498bd670b35SErik Nordmark 	sopp.sopp_rxlowat = connp->conn_rcvlowat;
14990f1702c5SYu Xiangning 	sopp.sopp_maxblk = INFPSZ;
15000f1702c5SYu Xiangning 	sopp.sopp_maxpsz = rts_mod_info.mi_maxpsz;
15010f1702c5SYu Xiangning 	sopp.sopp_minpsz = (rts_mod_info.mi_minpsz == 1) ? 0 :
15020f1702c5SYu Xiangning 	    rts_mod_info.mi_minpsz;
15030f1702c5SYu Xiangning 
15040f1702c5SYu Xiangning 	(*connp->conn_upcalls->su_set_proto_props)
15050f1702c5SYu Xiangning 	    (connp->conn_upper_handle, &sopp);
15060f1702c5SYu Xiangning 
15070f1702c5SYu Xiangning 	/*
15080f1702c5SYu Xiangning 	 * We treat it as already connected for routing socket.
15090f1702c5SYu Xiangning 	 */
15100f1702c5SYu Xiangning 	(*connp->conn_upcalls->su_connected)
15110f1702c5SYu Xiangning 	    (connp->conn_upper_handle, 0, NULL, -1);
15120f1702c5SYu Xiangning 
1513bd670b35SErik Nordmark 	/* Indicate to IP that this is a routing socket client */
15140f1702c5SYu Xiangning 	ip_rts_register(connp);
15150f1702c5SYu Xiangning }
15160f1702c5SYu Xiangning 
15170f1702c5SYu Xiangning /* ARGSUSED */
15180f1702c5SYu Xiangning int
rts_close(sock_lower_handle_t proto_handle,int flags,cred_t * cr)15190f1702c5SYu Xiangning rts_close(sock_lower_handle_t proto_handle, int flags, cred_t *cr)
15200f1702c5SYu Xiangning {
15210f1702c5SYu Xiangning 	conn_t  *connp = (conn_t *)proto_handle;
15220f1702c5SYu Xiangning 
15230f1702c5SYu Xiangning 	ASSERT(connp != NULL && IPCL_IS_RTS(connp));
15240f1702c5SYu Xiangning 	return (rts_common_close(NULL, connp));
15250f1702c5SYu Xiangning }
15260f1702c5SYu Xiangning 
15270f1702c5SYu Xiangning /* ARGSUSED */
15280f1702c5SYu Xiangning int
rts_shutdown(sock_lower_handle_t proto_handle,int how,cred_t * cr)15290f1702c5SYu Xiangning rts_shutdown(sock_lower_handle_t proto_handle, int how, cred_t *cr)
15300f1702c5SYu Xiangning {
15310f1702c5SYu Xiangning 	conn_t  *connp = (conn_t *)proto_handle;
15320f1702c5SYu Xiangning 
15330f1702c5SYu Xiangning 	/* shut down the send side */
15340f1702c5SYu Xiangning 	if (how != SHUT_RD)
15350f1702c5SYu Xiangning 		(*connp->conn_upcalls->su_opctl)(connp->conn_upper_handle,
15360f1702c5SYu Xiangning 		    SOCK_OPCTL_SHUT_SEND, 0);
15370f1702c5SYu Xiangning 	/* shut down the recv side */
15380f1702c5SYu Xiangning 	if (how != SHUT_WR)
15390f1702c5SYu Xiangning 		(*connp->conn_upcalls->su_opctl)(connp->conn_upper_handle,
15400f1702c5SYu Xiangning 		    SOCK_OPCTL_SHUT_RECV, 0);
15410f1702c5SYu Xiangning 	return (0);
15420f1702c5SYu Xiangning }
15430f1702c5SYu Xiangning 
15440f1702c5SYu Xiangning void
rts_clr_flowctrl(sock_lower_handle_t proto_handle)15450f1702c5SYu Xiangning rts_clr_flowctrl(sock_lower_handle_t proto_handle)
15460f1702c5SYu Xiangning {
15470f1702c5SYu Xiangning 	conn_t  *connp = (conn_t *)proto_handle;
15480f1702c5SYu Xiangning 	rts_t	*rts = connp->conn_rts;
15490f1702c5SYu Xiangning 
15500f1702c5SYu Xiangning 	mutex_enter(&rts->rts_recv_mutex);
15510f1702c5SYu Xiangning 	connp->conn_flow_cntrld = B_FALSE;
15520f1702c5SYu Xiangning 	mutex_exit(&rts->rts_recv_mutex);
15530f1702c5SYu Xiangning }
15540f1702c5SYu Xiangning 
15550f1702c5SYu Xiangning int
rts_ioctl(sock_lower_handle_t proto_handle,int cmd,intptr_t arg,int mode,int32_t * rvalp,cred_t * cr)15560f1702c5SYu Xiangning rts_ioctl(sock_lower_handle_t proto_handle, int cmd, intptr_t arg,
15570f1702c5SYu Xiangning     int mode, int32_t *rvalp, cred_t *cr)
15580f1702c5SYu Xiangning {
15590f1702c5SYu Xiangning 	conn_t		*connp = (conn_t *)proto_handle;
15600f1702c5SYu Xiangning 	int		error;
15610f1702c5SYu Xiangning 
1562bd670b35SErik Nordmark 	/*
1563bd670b35SErik Nordmark 	 * If we don't have a helper stream then create one.
1564bd670b35SErik Nordmark 	 * ip_create_helper_stream takes care of locking the conn_t,
1565bd670b35SErik Nordmark 	 * so this check for NULL is just a performance optimization.
1566bd670b35SErik Nordmark 	 */
1567bd670b35SErik Nordmark 	if (connp->conn_helper_info == NULL) {
1568bd670b35SErik Nordmark 		rts_stack_t *rtss = connp->conn_rts->rts_rtss;
1569bd670b35SErik Nordmark 
1570bd670b35SErik Nordmark 		ASSERT(rtss->rtss_ldi_ident != NULL);
1571bd670b35SErik Nordmark 
1572bd670b35SErik Nordmark 		/*
1573bd670b35SErik Nordmark 		 * Create a helper stream for non-STREAMS socket.
1574bd670b35SErik Nordmark 		 */
1575bd670b35SErik Nordmark 		error = ip_create_helper_stream(connp, rtss->rtss_ldi_ident);
1576bd670b35SErik Nordmark 		if (error != 0) {
1577bd670b35SErik Nordmark 			ip0dbg(("rts_ioctl: create of IP helper stream "
1578bd670b35SErik Nordmark 			    "failed %d\n", error));
1579bd670b35SErik Nordmark 			return (error);
1580bd670b35SErik Nordmark 		}
1581bd670b35SErik Nordmark 	}
1582bd670b35SErik Nordmark 
15830f1702c5SYu Xiangning 	switch (cmd) {
15840f1702c5SYu Xiangning 	case ND_SET:
15850f1702c5SYu Xiangning 	case ND_GET:
15860f1702c5SYu Xiangning 	case TI_GETPEERNAME:
15870f1702c5SYu Xiangning 	case TI_GETMYNAME:
15880f1702c5SYu Xiangning #ifdef DEUG
15890f1702c5SYu Xiangning 		cmn_err(CE_CONT, "rts_ioctl cmd 0x%x on non sreams"
15900f1702c5SYu Xiangning 		    " socket", cmd);
15910f1702c5SYu Xiangning #endif
15920f1702c5SYu Xiangning 		error = EINVAL;
15930f1702c5SYu Xiangning 		break;
15940f1702c5SYu Xiangning 	default:
15950f1702c5SYu Xiangning 		/*
15960f1702c5SYu Xiangning 		 * Pass on to IP using helper stream
15970f1702c5SYu Xiangning 		 */
159819a8a986SRao Shoaib 		error = ldi_ioctl(connp->conn_helper_info->iphs_handle,
15990f1702c5SYu Xiangning 		    cmd, arg, mode, cr, rvalp);
16000f1702c5SYu Xiangning 		break;
16010f1702c5SYu Xiangning 	}
16020f1702c5SYu Xiangning 
16030f1702c5SYu Xiangning 	return (error);
16040f1702c5SYu Xiangning }
16050f1702c5SYu Xiangning 
16060f1702c5SYu Xiangning sock_downcalls_t sock_rts_downcalls = {
16070f1702c5SYu Xiangning 	rts_activate,
16080f1702c5SYu Xiangning 	rts_accept,
16090f1702c5SYu Xiangning 	rts_bind,
16100f1702c5SYu Xiangning 	rts_listen,
16110f1702c5SYu Xiangning 	rts_connect,
16120f1702c5SYu Xiangning 	rts_getpeername,
16130f1702c5SYu Xiangning 	rts_getsockname,
16140f1702c5SYu Xiangning 	rts_getsockopt,
16150f1702c5SYu Xiangning 	rts_setsockopt,
16160f1702c5SYu Xiangning 	rts_send,
16170f1702c5SYu Xiangning 	NULL,
16180f1702c5SYu Xiangning 	NULL,
16190f1702c5SYu Xiangning 	NULL,
16200f1702c5SYu Xiangning 	rts_shutdown,
16210f1702c5SYu Xiangning 	rts_clr_flowctrl,
16220f1702c5SYu Xiangning 	rts_ioctl,
16230f1702c5SYu Xiangning 	rts_close
16240f1702c5SYu Xiangning };
1625