/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/socketvar.h>
#include <inet/ipclassifier.h>
#include <inet/proto_set.h>
#include <netinet/ip_mroute.h>
#include <sys/isa_defs.h>
#include <inet/rts_impl.h>
/*
* This is a transport provider for routing sockets. Downstream messages are
* wrapped with a IP_IOCTL header, and ip_wput_ioctl calls the appropriate entry
* in the ip_ioctl_ftbl callout table to pass the routing socket data into IP.
* Upstream messages are generated for listeners of the routing socket as well
* as the message sender (unless they have turned off their end using
* SO_USELOOPBACK or shutdown(3n)). Upstream messages may also be generated
* asynchronously when:
*
* Interfaces are brought up or down.
* Addresses are assigned to interfaces.
* ICMP redirects are processed and a IRE_HOST/RTF_DYNAMIC is installed.
* No route is found while sending a packet.
*
* Since all we do is reformat the messages between routing socket and
* ioctl forms, no synchronization is necessary in this module; all
* the dirty work is done down in ip.
*/
/* Default structure copied into T_INFO_ACK messages */
T_INFINITE, /* TSDU_size. Maximum size messages. */
T_INVALID, /* ETSDU_size. No expedited data. */
T_INVALID, /* CDATA_size. No connect data. */
T_INVALID, /* DDATA_size. No disconnect data. */
0, /* ADDR_size. */
0, /* OPT_size - not initialized here */
64 * 1024, /* TIDU_size. rts allows maximum size messages. */
T_COTS, /* SERV_type. rts supports connection oriented. */
TS_UNBND, /* CURRENT_state. This is set from rts_state. */
(XPG4_1) /* PROVIDER_flag */
};
/*
* Table of ND variables supported by rts. These are loaded into rts_g_nd
* in rts_open.
*/
/* min max value name */
{ 4096, 65536, 8192, "rts_xmit_hiwat"},
{ 0, 65536, 1024, "rts_xmit_lowat"},
{ 4096, 65536, 8192, "rts_recv_hiwat"},
{ 65536, 1024*1024*1024, 256*1024, "rts_max_buf"},
};
int sys_error);
static int rts_stream_close(queue_t *q);
};
};
};
};
/*
* This routine allocates the necessary
* message blocks for IOCTL wrapping the
* user data.
*/
static mblk_t *
{
return (NULL);
return (NULL);
}
ipllc->ipllc_name_offset = 0;
ipllc->ipllc_name_length = 0;
return (mp1);
}
/*
* This routine closes rts stream, by disabling
* internal datastructure.
*/
static int
{
if (!IPCL_IS_NONSTR(connp)) {
qprocsoff(q);
}
/*
* Now we are truly single threaded on this stream, and can
* delete the things hanging off the connp, and finally the connp.
* We removed this connp from the fanout list, it cannot be
* accessed thru the fanouts, and we already waited for the
* conn_ref to drop to 0. We are already in close, so
* there cannot be any other thread from the top. qprocsoff
* has completed, and service has completed or won't run in
* future.
*/
if (!IPCL_IS_NONSTR(connp)) {
} else {
}
return (0);
}
static int
{
(void) rts_common_close(q, connp);
return (0);
}
/*
* This is the open routine for routing socket. It allocates
* rts_t structure for the stream and tells IP that it is a routing socket.
*/
/* ARGSUSED */
static int
{
/* If the stream is already open, return immediately. */
return (0);
return (EINVAL);
/*
* Since RTS is not used so heavily, allocating from the small
* arena should be sufficient.
*/
return (EBUSY);
}
/* Indicate to IP that this is a routing socket client */
qprocson(q);
return (0);
}
/* ARGSUSED */
static conn_t *
{
/*
* For exclusive stacks we set the zoneid to zero
* to make RTS operate as if in the global zone.
*/
else
/*
* ipcl_conn_create did a netstack_hold. Undo the hold that was
* done by netstack_find_by_cred()
*/
/* conn_allzones can not be set this early, hence no IPCL_ZONEID */
/* SO_PROTOTYPE is always sent down by sockfs setting conn_proto */
/* Cache things in ixa without an extra refhold */
if (is_system_labeled())
/*
* rts sockets start out as bound and connected
* For streams based sockets, socket state is set to
* SS_ISBOUND | SS_ISCONNECTED in so_strinit.
*/
return (connp);
}
/*
* This routine creates a T_ERROR_ACK message and passes it upstream.
*/
static void
{
}
/*
* This routine creates a T_OK_ACK message and passes it upstream.
*/
static void
{
}
/*
* This routine is called by rts_wput to handle T_UNBIND_REQ messages.
*/
static void
{
/* If a bind has not been done, we can't unbind. */
return;
}
rts_ok_ack(q, mp);
}
/*
* This routine is called to handle each
* O_T_BIND_REQ/T_BIND_REQ message passed to
* rts_wput. Note: This routine works with both
* O_T_BIND_REQ and T_BIND_REQ semantics.
*/
static void
{
return;
}
return;
}
if (tbr->ADDR_length != 0) {
return;
}
/* Generic request */
tbr->ADDR_length = 0;
}
static void
{
*tap = rts_g_t_info_ack;
}
/*
* This routine responds to T_CAPABILITY_REQ messages. It is called by
* rts_wput. Much of the T_CAPABILITY_ACK information is copied from
* rts_g_t_info_ack. The current state of the stream is copied from
* rts_state.
*/
static void
{
return;
}
}
/*
* This routine responds to T_INFO_REQ messages. It is called by rts_wput.
* Most of the T_INFO_ACK information is copied from rts_g_t_info_ack.
* The current state of the stream is copied from rts_state.
*/
static void
{
return;
}
/*
* This routine gets default values of certain options whose default
* values are maintained by protcol specific code
*/
/* ARGSUSED */
int
{
/* no default value processed by protocol specific code currently */
return (-1);
}
static int
{
int retval;
switch (level) {
/* do this in conn_opt_get? */
case SOL_ROUTE:
switch (name) {
case RT_AWARE:
return (0);
}
break;
}
return (retval);
}
/* ARGSUSED */
static int
{
int error;
/*
* For rts, we should have no ancillary data sent down
* (rts_wput doesn't handle options).
*/
/*
* For fixed length options, no sanity check
* of passed in length is done. It is assumed *_optcom_req()
* routines do the right thing.
*/
switch (level) {
case SOL_SOCKET:
switch (name) {
case SO_PROTOTYPE:
/*
* Routing socket applications that call socket() with
* a third argument can filter which messages will be
* sent upstream thanks to sockfs. so_socket() sends
* down the SO_PROTOTYPE and rts_queue_input()
* implements the filtering.
*/
*outlenp = 0;
return (EPROTONOSUPPORT);
}
if (!checkonly)
return (0);
/*
* The following two items can be manipulated,
* but changing them should do nothing.
*/
case SO_SNDBUF:
*outlenp = 0;
return (ENOBUFS);
}
break; /* goto sizeof (int) option return */
case SO_RCVBUF:
*outlenp = 0;
return (ENOBUFS);
}
break; /* goto sizeof (int) option return */
}
break;
case SOL_ROUTE:
switch (name) {
case RT_AWARE:
if (!checkonly) {
}
return (0);
}
break;
}
/* Serialized setsockopt since we are D_MTQPAIR */
if (error != 0) {
*outlenp = 0;
return (error);
}
/*
* Common case of return from an option that is sizeof (int)
*/
}
*outlenp = (t_uscalar_t)sizeof (int);
return (0);
}
static int
{
if (optset_context) {
switch (optset_context) {
case SETFN_OPTCOM_CHECKONLY:
/*
* Note: Implies T_CHECK semantics for T_OPTCOM_REQ
* inlen != 0 implies value supplied and
* we have to "pretend" to set it.
* inlen == 0 implies that there is no value part
* in T_CHECK request and just validation
* done elsewhere should be enough, we just return here.
*/
if (inlen == 0) {
*outlenp = 0;
return (0);
}
break;
case SETFN_OPTCOM_NEGOTIATE:
break;
case SETFN_UD_NEGOTIATE:
case SETFN_CONN_NEGOTIATE:
/*
* Negotiating local and "association-related" options
* through T_UNITDATA_REQ or T_CONN_{REQ,CON}
* Not allowed in this module.
*/
return (EINVAL);
default:
/*
* We should never get here
*/
*outlenp = 0;
return (EINVAL);
}
}
}
/*
* This routine retrieves the current status of socket options.
* It returns the size of the option retrieved.
*/
int
{
int err;
return (err);
}
/*
* This routine sets socket options.
*/
/*ARGSUSED*/
int
{
int error;
return (error);
}
/*
* This routine retrieves the value of an ND variable in a rtsparam_t
* structure. It is called through nd_getset when a user reads the
* variable.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* Walk through the param array specified registering each element with the
* named dispatch (ND) handler.
*/
static boolean_t
{
return (B_FALSE);
}
}
}
return (B_TRUE);
}
/* This routine sets an ND variable in a rtsparam_t structure. */
/* ARGSUSED */
static int
{
/*
* Fail the request if the new value does not lie within the
* required bounds.
*/
return (EINVAL);
}
/* Set the new value */
return (0);
}
/*
* Empty rsrv routine which is used by rts_input to cause a wakeup
* of a thread in qwait.
*/
/*ARGSUSED*/
static void
{
}
/*
* This routine handles synchronous messages passed downstream. It either
* consumes the message or passes it downstream; it never queues a
* a message. The data messages that go down are wrapped in an IOCTL
* message.
*
* it can return an immediate error (such as ENETUNREACH when adding a route).
* It uses the RTS_WRW_PENDING to ensure that each rts instance has only
* one M_IOCTL outstanding at any given time.
*/
static int
{
int error;
if (qwait_rw(q)) {
goto err_ret;
}
}
/*
* Uio error of some sort, so just return the error.
*/
goto err_ret;
}
/*
* Pass the mblk (chain) onto wput().
*/
case M_PROTO:
case M_PCPROTO:
/* Expedite other than T_DATA_REQ to below the switch */
sizeof (struct T_data_req)) ||
break;
goto err_ret;
}
/* FALLTHRU */
case M_DATA:
/*
* The semantics of the routing socket is such that the rtm_pid
* field is automatically filled in during requests with the
* current process' pid. We do this here (where we still have
* user context) after checking we have at least a message the
* size of a routing message header.
*/
goto err_ret;
}
}
break;
default:
break;
}
if (qwait_rw(q)) {
/* RTS_WPUT_PENDING will be cleared below */
break;
}
}
/*
* This routine handles all messages passed downstream. It either
* consumes the message or passes it downstream; it never queues a
* a message. The data messages that go down are wrapped in an IOCTL
* message.
*/
static void
{
case M_DATA:
break;
case M_PROTO:
case M_PCPROTO:
/* Expedite valid T_DATA_REQ to below the switch */
return;
break;
}
}
/* FALLTHRU */
default:
rts_wput_other(q, mp);
return;
}
}
return;
}
ip_wput_nondata(q, mp1);
}
/*
* Handles all the control message, if it
* can not understand it, it will
* pass down stream.
*/
static void
{
case M_PROTO:
case M_PCPROTO:
/*
* If the message does not contain a PRIM_type,
* throw it away.
*/
return;
}
case T_BIND_REQ:
case O_T_BIND_REQ:
rts_tpi_bind(q, mp);
return;
case T_UNBIND_REQ:
rts_tpi_unbind(q, mp);
return;
case T_CAPABILITY_REQ:
rts_capability_req(q, mp);
return;
case T_INFO_REQ:
rts_info_req(q, mp);
return;
case T_SVR4_OPTMGMT_REQ:
case T_OPTMGMT_REQ:
/*
* All Solaris components should pass a db_credp
* for this TPI message, hence we ASSERT.
* But in case there is some other M_PROTO that looks
* like a TPI message sent by some other kernel
* component, we check and return an error.
*/
return;
}
} else {
}
return;
case O_T_CONN_RES:
case T_CONN_RES:
case T_DISCON_REQ:
/* Not supported by rts. */
return;
case T_DATA_REQ:
case T_EXDATA_REQ:
case T_ORDREL_REQ:
/* Illegal for rts. */
return;
default:
break;
}
break;
case M_IOCTL:
case ND_SET:
case ND_GET:
return;
}
break;
case TI_GETPEERNAME:
return;
default:
break;
}
case M_IOCDATA:
rts_wput_iocdata(q, mp);
return;
default:
break;
}
ip_wput_nondata(q, mp);
}
/*
* Called by rts_wput_other to handle all M_IOCDATA messages.
*/
static void
{
/* Make sure it is one of ours. */
case TI_GETPEERNAME:
break;
default:
ip_wput_nondata(q, mp);
return;
}
case -1:
return;
break;
/* Copy out the strbuf. */
mi_copyout(q, mp);
return;
/* All done. */
mi_copy_done(q, mp, 0);
return;
default:
return;
}
return;
}
case TI_GETPEERNAME:
break;
default:
return;
}
B_TRUE);
return;
/* Copy out the address */
mi_copyout(q, mp);
}
/*
* IP passes up a NULL ira.
*/
/*ARGSUSED2*/
static void
{
int error;
case M_IOCACK:
case M_IOCNAK:
/*
* Note: there is no qwait_wakeup() we can use.
*/
return;
}
break;
case M_DATA:
/*
* Prepend T_DATA_IND to prevent the stream head from
* consolidating multiple messages together.
* If the allocation fails just send up the M_DATA.
*/
}
break;
default:
break;
}
if (IPCL_IS_NONSTR(connp)) {
/*
* Let's confirm hoding the lock that
* we are out of recv space.
*/
}
}
} else {
}
}
/*ARGSUSED*/
static void
{
}
void
rts_ddi_g_init(void)
{
/*
* We want to be informed each time a stack is created or
* destroyed in the kernel, so we can maintain the
* set of rts_stack_t's.
*/
}
void
rts_ddi_g_destroy(void)
{
}
/*
* Initialize the RTS stack instance.
*/
/* ARGSUSED */
static void *
{
int error = 0;
return (rtss);
}
/*
* Free the RTS stack instance.
*/
/* ARGSUSED */
static void
{
}
/* ARGSUSED */
int
{
return (EINVAL);
}
/* ARGSUSED */
static int
{
/*
* rebind not allowed
*/
return (EINVAL);
}
/* ARGSUSED */
int
{
return (EINVAL);
}
/* ARGSUSED */
int
{
/*
* rts sockets start out as bound and connected
*/
*id = 0;
return (EISCONN);
}
/* ARGSUSED */
int
{
return (0);
}
/* ARGSUSED */
int
{
return (0);
}
static int
{
int error;
void *optvalp_buf;
int len;
if (error != 0) {
if (error < 0)
return (error);
}
if (len == -1) {
return (EINVAL);
}
/*
* update optlen and copy option value
*/
return (0);
}
static int
{
int error;
if (error != 0) {
if (error < 0)
return (error);
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
/*
* The semantics of the routing socket is such that the rtm_pid
* field is automatically filled in during requests with the
* current process' pid. We do this here (where we still have
* user context) after checking we have at least a message the
* size of a routing message header.
*/
return (EINVAL);
}
}
/*
* We are not constrained by the ioctl interface and
* ip_rts_request_common processing requests synchronously hence
* we can send them down concurrently.
*/
return (error);
}
/* ARGSUSED */
{
return (NULL);
}
*errorp = 0;
return ((sock_lower_handle_t)connp);
}
/* ARGSUSED */
void
{
sopp.sopp_wroff = 0;
/*
* We treat it as already connected for routing socket.
*/
/* Indicate to IP that this is a routing socket client */
}
/* ARGSUSED */
int
{
}
/* ARGSUSED */
int
{
/* shut down the send side */
SOCK_OPCTL_SHUT_SEND, 0);
/* shut down the recv side */
SOCK_OPCTL_SHUT_RECV, 0);
return (0);
}
void
{
}
int
{
int error;
/*
* If we don't have a helper stream then create one.
* ip_create_helper_stream takes care of locking the conn_t,
* so this check for NULL is just a performance optimization.
*/
/*
* Create a helper stream for non-STREAMS socket.
*/
if (error != 0) {
ip0dbg(("rts_ioctl: create of IP helper stream "
"failed %d\n", error));
return (error);
}
}
switch (cmd) {
case ND_SET:
case ND_GET:
case TI_GETPEERNAME:
case TI_GETMYNAME:
#ifdef DEUG
" socket", cmd);
#endif
break;
default:
/*
* Pass on to IP using helper stream
*/
break;
}
return (error);
}
NULL,
NULL,
NULL,
};