rts.c revision 27c48ed935c6a5f6015c6534b98e3090b1ddfdb6
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define _SUN_TPI_VERSION 2
#include <netinet/ip_mroute.h>
#include <sys/isa_defs.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.
* When TCP requests IP to remove an IRE_CACHE of a troubled destination.
*
* 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.
*/
/*
* RTS stack instances
*/
struct rts_stack {
struct rtsparam_s *rtss_params;
};
typedef struct rts_stack rts_stack_t;
/*
* Object to represent database of options to search passed to
* {sock,tpi}optcom_req() interface routine to take care of option
* management and associated methods.
* XXX. These and other externs should really move to a rts header.
*/
extern optdb_obj_t rts_opt_obj;
extern uint_t rts_max_optsize;
/* Internal routing socket stream control structure, one per open stream */
typedef struct rts_s {
: 0;
} rts_t;
/* Default structure copied into T_INFO_ACK messages */
static struct T_info_ack rts_g_t_info_ack = {
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 */
};
/* Named Dispatch Parameter Management Structure */
typedef struct rtsparam_s {
char *rts_param_name;
} rtsparam_t;
/*
* Table of ND variables supported by rts. These are loaded into rts_g_nd
* in rts_open.
*/
static rtsparam_t lcl_param_arr[] = {
/* 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 struct module_info info = {
};
};
};
};
/*
* 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
{
qprocsoff(q);
return (0);
}
/*
* This is the open routine for routing socket. It allocates
* rts_t structure for the stream and sends an IOCTL to
* the down module to indicate that it is a routing socket
* stream.
*/
/* ARGSUSED */
static int
{
netstack_t *ns;
/* If the stream is already open, return immediately. */
return (0);
/* If this is not a push of rts as a module, fail. */
return (EINVAL);
/*
* The receive hiwat is only looked at on the stream head queue.
* Store in q_hiwat in order to return on SO_RCVBUF getsockopts.
*/
/*
* Store in q_hiwat/q_lowat in order to return on SO_SNDBUF/SO_SNDLOWAT
* getsockopts.
*/
qprocson(q);
/*
* Indicate the down IP module that this is a routing socket
* client by sending an RTS IOCTL without any user data. Although
* this is just a notification message (without any real routing
* request), we pass in any credential for correctness sake.
*/
qprocsoff(q);
return (ENOMEM);
}
if (!qwait_sig(q)) {
(void) rts_close(q);
return (EINTR);
}
}
(void) rts_close(q);
return (ENOTSUP);
}
return (0);
}
/*
* 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.
* After some error checking, the message is passed downstream to ip.
*/
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
{
struct T_bind_req *tbr;
return;
}
return;
}
/*
* Reallocate the message to make sure we have enough room for an
* address and the protocol type.
*/
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
{
struct T_capability_ack *tcap;
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);
}
/*
* This routine retrieves the current status of socket options.
* It returns the size of the option retrieved.
*/
int
{
switch (level) {
case SOL_SOCKET:
switch (name) {
case SO_DEBUG:
break;
case SO_REUSEADDR:
break;
case SO_TYPE:
break;
/*
* The following three items are available here,
* but are only meaningful to IP.
*/
case SO_DONTROUTE:
break;
case SO_USELOOPBACK:
break;
case SO_BROADCAST:
break;
case SO_PROTOTYPE:
break;
/*
* The following two items can be manipulated,
* but changing them should do nothing.
*/
case SO_SNDBUF:
break;
case SO_RCVBUF:
break;
case SO_DOMAIN:
break;
default:
return (-1);
}
break;
default:
return (-1);
}
return ((int)sizeof (int));
}
/*
* This routine sets socket options.
*/
/*ARGSUSED*/
int
{
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);
}
/*
* 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_REUSEADDR:
if (!checkonly)
break; /* goto sizeof (int) option return */
case SO_DEBUG:
if (!checkonly)
break; /* goto sizeof (int) option return */
/*
* The following three items are available here,
* but are only meaningful to IP.
*/
case SO_DONTROUTE:
if (!checkonly)
break; /* goto sizeof (int) option return */
case SO_USELOOPBACK:
if (!checkonly)
break; /* goto sizeof (int) option return */
case SO_BROADCAST:
if (!checkonly)
break; /* goto sizeof (int) option return */
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.
*/
return (EPROTONOSUPPORT);
if (!checkonly)
break; /* goto sizeof (int) option return */
/*
* The following two items can be manipulated,
* but changing them should do nothing.
*/
case SO_SNDBUF:
*outlenp = 0;
return (ENOBUFS);
}
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
case SO_RCVBUF:
*outlenp = 0;
return (ENOBUFS);
}
if (!checkonly) {
}
break; /* goto sizeof (int) option return */
default:
*outlenp = 0;
return (EINVAL);
}
break;
default:
*outlenp = 0;
return (EINVAL);
}
/*
* Common case of return from an option that is sizeof (int)
*/
*outlenp = (t_uscalar_t)sizeof (int);
return (0);
}
/*
* This routine frees the ND table if all streams have been closed.
* It is called by rts_close and rts_open.
*/
static void
{
}
/*
* 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);
}
/*
* 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;
}
}
/*
* 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:
return;
case T_UNBIND_REQ:
rts_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:
return;
case T_OPTMGMT_REQ:
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;
}
}
/*
* 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:
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);
}
static void
{
struct T_data_ind *tdi;
case M_IOCACK:
case M_IOCNAK:
else
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;
}
}
void
rts_ddi_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_destroy(void)
{
}
/*
* Initialize the RTS stack instance.
*/
/* ARGSUSED */
static void *
{
rtsparam_t *pa;
return (rtss);
}
/*
* Free the RTS stack instance.
*/
/* ARGSUSED */
static void
{
}