sockcommon.c revision 7d64f41b87275bdc41b1f4cddb0fe3d951ef64bd
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/sysmacros.h>
#include <sys/socketvar.h>
#include <sys/sodirect.h>
#include <inet/ipclassifier.h>
static struct kmem_cache *sock_sod_cache;
/*
* Common socket access functions.
*
* Instead of accessing the sonode switch directly (i.e., SOP_xxx()),
* the socket_xxx() function should be used.
*/
/*
* Try to create a new sonode of the requested <family, type, protocol>.
*/
/* ARGSUSED */
struct sonode *
{
int saved_error;
/*
* Look for a sockparams entry that match the given criteria.
* solookup() returns with the entry held.
*/
saved_error = *errorp;
/*
* There is no matching sockparams entry. An ephemeral entry is
* created if the caller specifies a device or a socket module.
*/
saved_error = 0;
saved_error = 0;
} else {
}
*errorp = saved_error;
return (NULL);
}
}
} else {
/* Cannot fail, only bumps so_count */
} else {
*errorp = saved_error;
}
}
return (so);
}
struct sonode *
{
struct sockparams *sp;
/*
* This function may be called in interrupt context, and CRED()
* will be NULL. In this case, pass in kcred.
*/
/* Cannot fail, only bumps so_count */
} else {
}
}
return (so);
}
/*
* Bind local endpoint.
*/
int
{
}
/*
* Turn socket into a listen socket.
*/
int
{
if (backlog < 0) {
backlog = 0;
}
/*
* Use the same qlimit as in BSD. BSD checks the qlimit
* before queuing the next connection implying that a
* listen(sock, 0) allows one connection to be queued.
* BSD also uses 1.5 times the requested backlog.
*
* XNS Issue 4 required a strict interpretation of the backlog.
* This has been waived subsequently for Issue 4 and the change
* incorporated in XNS Issue 5. So we aren't required to do
* anything special for XPG apps.
*/
else
}
/*
* Accept incoming connection.
*/
int
{
}
/*
* Active open.
*/
int
{
int error;
/*
* Handle a connect to a name parameter of type AF_UNSPEC like a
* connect to a null address. This is the portable method to
* unconnect a socket.
*/
if ((namelen >= sizeof (sa_family_t)) &&
namelen = 0;
}
/*
* ENETUNREACH be returned but does not require
* EHOSTUNREACH. In order to keep the test suite
* happy we mess with the errno here.
*/
error = ENETUNREACH;
}
return (error);
}
/*
* Get address of remote node.
*/
int
{
}
/*
* Get local address.
*/
int
{
}
/*
* Called from shutdown().
*/
int
{
}
/*
* Get socket options.
*/
/*ARGSUSED*/
int
{
}
/*
* Set socket options
*/
int
{
int val = 1;
/* Caller allocates aligned optval, or passes null */
/* If optval is null optlen is 0, and vice-versa */
}
int
{
int error = 0;
/*
* Do not bypass the cache if we are doing a local (AF_UNIX) write.
*/
else
switch (error) {
default:
break;
case EINTR:
/* EAGAIN is EWOULDBLOCK */
case EWOULDBLOCK:
/* We did a partial send */
error = 0;
break;
case EPIPE:
break;
}
return (error);
}
int
{
int error = 0;
}
return (error);
}
int
{
int error;
/*
* Do not bypass the cache when reading data, as the application
* is likely to access the data shortly.
*/
switch (error) {
case EINTR:
/* EAGAIN is EWOULDBLOCK */
case EWOULDBLOCK:
/* We did a partial read */
error = 0;
break;
default:
break;
}
return (error);
}
int
{
}
int
{
}
int
{
}
int
{
}
void
{
}
/* ARGSUSED */
void
{
}
/*
* TODO Once the common vnode ops is available, then the vnops argument
* should be removed.
*/
/*ARGSUSED*/
int
{
return (-1);
}
so->so_rcv_queued = 0;
so->so_rcv_wanted = 0;
so->so_rcv_timer_tid = 0;
so->so_rcv_thresh = 0;
so->so_acceptq_len = 0;
so->so_backlog = 0;
return (0);
}
/*ARGSUSED*/
void
{
}
void
{
so->so_options = 0;
so->so_rcvtimeo = 0;
so->so_sndtimeo = 0;
so->so_xpg_rcvbuf = 0;
so->so_oobmark = 0;
so->so_copyflag = 0;
so->so_rcv_queued = 0;
}
void
{
if (so->so_rcv_timer_tid) {
so->so_rcv_timer_tid = 0;
}
}
}
}
vn_invalid(vp);
}
}
/*
* This function is called at the beginning of recvmsg().
*
* with state UIOA_ALLOC.
*/
uio_t *
{
return (NULL);
/*
* Big enough I/O for uioa min setup and an sodirect socket
* and sodirect enabled and uioa enabled and I/O will be done
* and not EOF so initialize the sodirect_t uioa_t with "uiop".
*/
/*
* Successful uioainit() so the uio_t part of the
* uioa_t will be used for all uio_t work to follow,
* we return the original "uiop" in "suiop".
*/
/*
* Before returning to the caller the passed in uio_t
* "uiop" will be updated via a call to uioafini()
* below.
*
* Note, the uioa.uioa_state isn't set to UIOA_ENABLED
* here as first we have to uioamove() any currently
* queued M_DATA mblk_t(s) so it will be done later.
*/
}
/*
* In either uioainit() success or not case note the number
* transport (e.g. TCP) strategy.
*/
/*
* No uioa but still using sodirect so note the number of
* transport (e.g. TCP) strategy.
*/
}
return (suiop);
}
/*
* operations, and reset the uioa state to UIOA_ALLOC.
*/
int
{
int error = 0;
return (0);
}
/* Finish any sodirect and uioa processing */
/* Finish any uioa_t processing */
}
}
/* Awoke */
}
/* Last, clear sod_want value */
return (error);
}
/*
* Schedule a uioamove() on a mblk. This is ususally called from
*/
mblk_t *
{
/* Caller must have lock held */
/* Uioa is enabled */
/*
* There isn't enough uio space for the mblk_t chain
* so disable uioa such that this and any additional
* mblk_t data is handled by the socket and schedule
* the socket for wakeup to finish this uioa.
*/
}
return (mp);
}
do {
/* Scheduled, mark dblk_t as such */
} else {
/* Error, turn off async processing */
break;
}
/*
* Not all mblk_t(s) uioamoved (error) or all uio
* space has been consumed so schedule the socket
* for wakeup to finish this uio.
*/
/* Break the mblk chain if neccessary. */
}
}
}
return (mp1);
}
/*
* This function is called on a mblk that thas been successfully uioamoved().
*/
void
{
/*
* A uioa flaged mblk_t chain, already uio processed,
* add it to the sodirect uioa pending free list.
*
* Note, a b_cont chain headed by a DBLK_UIOA enable
* mblk_t must have all mblk_t(s) DBLK_UIOA enabled.
*/
/*
* Add first mblk_t of "bp" chain to current sodirect uioa
* free list tail mblk_t, if any, else empty list so new head.
*/
else
/*
* Walk mblk_t "bp" chain to find tail and adjust rptr of
* each to reflect that uioamove() has consumed all data.
*/
for (;;) {
break;
}
/* New sodirect uioa free list tail */
/* Only dequeue once with data returned per uioa_t */
}
}
}
/*
* When transit from UIOA_INIT state to UIOA_ENABLE state in recvmsg(), call
* this function on a non-STREAMS socket to schedule uioamove() on the data
* that has already queued in this socket.
*/
void
{
int len;
int error;
/*
* Walk first b_cont chain in sod_q
* and schedule any M_DATA mblk_t's for uio asynchronous move.
*/
/* Walk the chain */
do {
break;
/* Not M_DATA, no more uioa */
goto nouioa;
}
/* Have a M_DATA mblk_t with data */
/* Not enough uio sapce, or beyond oobmark */
goto nouioa;
}
if (!error) {
/* Scheduled, mark dblk_t as such */
} else {
/* Break the mblk chain */
goto nouioa;
}
}
/* Save last wbp processed */
/*
* We get here only once to process the sonode dump area
* if so_rcv_q_head is NULL or all the mblks have been
* successfully uioamoved()ed.
*/
/* move to dump area */
goto again;
}
return;
/* No more uioa */
/*
* If we processed 1 or more mblk_t(s) then we need to split the
* current mblk_t chain in 2 so that all the uioamove()ed mblk_t(s)
* are in the current chain and the rest are in the following new
* chain.
*/
/* New end of current chain */
/* Insert new chain wbp after bp */
/*
* No need to grab so_lock, since sod_lockp
* points to so_lock.
*/
if (in_rcv_q)
else
}
}
}
/*
* Initialize sodirect data structures on a socket.
*/
void
{
/*
* Remainder of the sod_uioa members are left uninitialized
* but will be initialized later by uioainit() before uioa
* is enabled.
*/
}
/*
* Init the sodirect kmem cache while sockfs is loading.
*/
void
sod_init()
{
/* Allocate sodirect_t kmem_cache */
}
{
}
}
/* more arrived */
}
#ifdef DEBUG
while (m != NULL) {
" in so_rcv_q_head.\n", (void *)m);
}
m = m->b_next;
}
}
while (m != NULL) {
" in so_rcv_head.\n", (void *)m);
}
m = m->b_next;
}
}
#endif
}