sockcommon.c revision 0f1702c5201310f0529cd5abb77652e5e9b241b6
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * CDDL HEADER START
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The contents of this file are subject to the terms of the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Common Development and Distribution License (the "License").
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * You may not use this file except in compliance with the License.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * or http://www.opensolaris.org/os/licensing.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * See the License for the specific language governing permissions
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and limitations under the License.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * When distributing Covered Code, include this CDDL HEADER in each
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * If applicable, add the following below this CDDL HEADER, with the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * fields enclosed by brackets "[]" replaced with your own identifying
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * information: Portions Copyright [yyyy] [name of copyright owner]
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * CDDL HEADER END
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Use is subject to license terms.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/types.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/param.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/systm.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/sysmacros.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/debug.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/cmn_err.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/vfs.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/policy.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/modctl.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/sunddi.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/strsun.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/stropts.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/strsubr.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/socket.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/socketvar.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/sodirect.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/uio.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <inet/ipclassifier.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <fs/sockfs/sockcommon.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <fs/sockfs/nl7c.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <inet/ip.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int xnet_skip_checks, xnet_check_print, xnet_truncate_print;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningstatic struct kmem_cache *sock_sod_cache;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Common socket access functions.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Instead of accessing the sonode switch directly (i.e., SOP_xxx()),
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * the socket_xxx() function should be used.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Try to create a new sonode of the requested <family, type, protocol>.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/* ARGSUSED */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningstruct sonode *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_create(int family, int type, int protocol, char *devpath, char *mod,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int flags, int version, struct cred *cr, int *errorp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sonode *so;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sockparams *sp = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Look for a sockparams entry that match the given criteria.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * solookup() returns with the entry held.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *errorp = solookup(family, type, protocol, &sp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (sp == NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int kmflags = (flags == SOCKET_SLEEP) ? KM_SLEEP : KM_NOSLEEP;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * There is no matching sockparams entry. An ephemeral entry is
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * created if the caller specifies a device or a socket module.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (devpath != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sp = sockparams_hold_ephemeral_bydev(family, type,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning protocol, devpath, kmflags, errorp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else if (mod != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sp = sockparams_hold_ephemeral_bymod(family, type,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning protocol, mod, kmflags, errorp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (sp == NULL)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sp->sp_smod_info != NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(flags == SOCKET_SLEEP || flags == SOCKET_NOSLEEP);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so = sp->sp_smod_info->smod_sock_create_func(sp, family, type,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning protocol, version, flags, errorp, cr);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so == NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning SOCKPARAMS_DEC_REF(sp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((*errorp = SOP_INIT(so, NULL, cr, flags)) == 0) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Cannot fail, only bumps so_count */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) VOP_OPEN(&SOTOV(so), FREAD|FWRITE, cr, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socket_destroy(so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningstruct sonode *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_newconn(struct sonode *parent, sock_lower_handle_t lh,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sock_downcalls_t *dc, int flags, int *errorp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sonode *so;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sockparams *sp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *cr;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((cr = CRED()) == NULL)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cr = kcred;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sp = parent->so_sockparams;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sp != NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so = sp->sp_smod_info->smod_sock_create_func(sp, parent->so_family,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning parent->so_type, parent->so_protocol, parent->so_version, flags,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning errorp, cr);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning SOCKPARAMS_INC_REF(sp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_proto_handle = lh;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_downcalls = dc;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This function may be called in interrupt context, and CRED()
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * will be NULL. In this case, pass in kcred.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((*errorp = SOP_INIT(so, parent, cr, flags)) == 0) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Cannot fail, only bumps so_count */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) VOP_OPEN(&SOTOV(so), FREAD|FWRITE, cr, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socket_destroy(so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Bind local endpoint.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_bind(struct sonode *so, struct sockaddr *name, socklen_t namelen,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int flags, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_BIND(so, name, namelen, flags, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Turn socket into a listen socket.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_listen(struct sonode *so, int backlog, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (backlog < 0) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning backlog = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Use the same qlimit as in BSD. BSD checks the qlimit
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * before queuing the next connection implying that a
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * listen(sock, 0) allows one connection to be queued.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * BSD also uses 1.5 times the requested backlog.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * XNS Issue 4 required a strict interpretation of the backlog.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This has been waived subsequently for Issue 4 and the change
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * incorporated in XNS Issue 5. So we aren't required to do
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * anything special for XPG apps.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (backlog >= (INT_MAX - 1) / 3)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning backlog = INT_MAX;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning else
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning backlog = backlog * 3 / 2 + 1;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_LISTEN(so, backlog, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Accept incoming connection.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_accept(struct sonode *lso, int fflag, cred_t *cr, struct sonode **nsop)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_ACCEPT(lso, fflag, cr, nsop));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Active open.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_connect(struct sonode *so, const struct sockaddr *name,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socklen_t namelen, int fflag, int flags, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int error;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Handle a connect to a name parameter of type AF_UNSPEC like a
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * connect to a null address. This is the portable method to
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * unconnect a socket.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((namelen >= sizeof (sa_family_t)) &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (name->sa_family == AF_UNSPEC)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning name = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning namelen = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = SOP_CONNECT(so, name, namelen, fflag, flags, cr);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (error == EHOSTUNREACH && flags & _SOCONNECT_XPG4_2) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * X/Open specification contains a requirement that
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * ENETUNREACH be returned but does not require
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * EHOSTUNREACH. In order to keep the test suite
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * happy we mess with the errno here.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = ENETUNREACH;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (error);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Get address of remote node.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_getpeername(struct sonode *so, struct sockaddr *addr,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socklen_t *addrlen, boolean_t accept, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(*addrlen > 0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_GETPEERNAME(so, addr, addrlen, accept, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Get local address.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_getsockname(struct sonode *so, struct sockaddr *addr,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socklen_t *addrlen, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_GETSOCKNAME(so, addr, addrlen, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Called from shutdown().
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_shutdown(struct sonode *so, int how, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_SHUTDOWN(so, how, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Get socket options.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*ARGSUSED*/
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_getsockopt(struct sonode *so, int level, int option_name,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning void *optval, socklen_t *optlenp, int flags, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_GETSOCKOPT(so, level, option_name, optval,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning optlenp, flags, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Set socket options
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_setsockopt(struct sonode *so, int level, int option_name,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning const void *optval, t_uscalar_t optlen, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Caller allocates aligned optval, or passes null */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(((uintptr_t)optval & (sizeof (t_scalar_t) - 1)) == 0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* If optval is null optlen is 0, and vice-versa */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(optval != NULL || optlen == 0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(optlen != 0 || optval == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* No options should be zero-length */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (optlen == 0)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (EINVAL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_SETSOCKOPT(so, level, option_name, optval, optlen, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_sendmsg(struct sonode *so, struct nmsghdr *msg, struct uio *uiop,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int error = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ssize_t orig_resid = uiop->uio_resid;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Do not bypass the cache if we are doing a local (AF_UNIX) write.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_family == AF_UNIX)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uiop->uio_extflg |= UIO_COPY_CACHED;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning else
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uiop->uio_extflg &= ~UIO_COPY_CACHED;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = SOP_SENDMSG(so, msg, uiop, cr);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning switch (error) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning default:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning break;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning case EINTR:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning case ETIME:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning case EWOULDBLOCK:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* We did a partial send */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (uiop->uio_resid != orig_resid)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning break;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning case EPIPE:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((so->so_mode & SM_KERNEL) == 0)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning tsignal(curthread, SIGPIPE);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning break;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (error);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_sendmblk(struct sonode *so, struct nmsghdr *msg, int fflag,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *cr, mblk_t **mpp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int error = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = SOP_SENDMBLK(so, msg, fflag, cr, mpp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (error == EPIPE) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning tsignal(curthread, SIGPIPE);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (error);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_recvmsg(struct sonode *so, struct nmsghdr *msg, struct uio *uiop,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int error;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ssize_t orig_resid = uiop->uio_resid;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Do not bypass the cache when reading data, as the application
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * is likely to access the data shortly.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uiop->uio_extflg |= UIO_COPY_CACHED;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = SOP_RECVMSG(so, msg, uiop, cr);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning switch (error) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning case EINTR:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning case ETIME:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning case EWOULDBLOCK:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* We did a partial read */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (uiop->uio_resid != orig_resid)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning break;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning default:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning break;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (error);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_ioctl(struct sonode *so, int cmd, intptr_t arg, int mode,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct cred *cr, int32_t *rvalp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_IOCTL(so, cmd, arg, mode, cr, rvalp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_poll(struct sonode *so, short events, int anyyet, short *reventsp,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct pollhead **phpp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_POLL(so, events, anyyet, reventsp, phpp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_close(struct sonode *so, int flag, struct cred *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (VOP_CLOSE(SOTOV(so), flag, 1, 0, cr, NULL));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_close_internal(struct sonode *so, int flag, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_count == 0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_CLOSE(so, flag, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_destroy(struct sonode *so)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vn_invalid(SOTOV(so));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning VN_RELE(SOTOV(so));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/* ARGSUSED */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_destroy_internal(struct sonode *so, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sockparams *sp = so->so_sockparams;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_count == 0 && sp != NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sp->sp_smod_info->smod_sock_destroy_func(so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning SOCKPARAMS_DEC_REF(sp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * TODO Once the common vnode ops is available, then the vnops argument
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * should be removed.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*ARGSUSED*/
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsonode_constructor(void *buf, void *cdrarg, int kmflags)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sonode *so = buf;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct vnode *vp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vp = so->so_vnode = vn_alloc(kmflags);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (vp == NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (-1);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vp->v_data = so;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vn_setops(vp, socket_vnodeops);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_priv = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_oobmsg = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_proto_handle = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_peercred = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_queued = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_q_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_q_last_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_last_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_wanted = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_timer_interval = SOCKET_NO_RCVTIMER;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_timer_tid = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_thresh = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_acceptq_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_acceptq_tail = &so->so_acceptq_head;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_acceptq_next = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_acceptq_len = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_backlog = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_snd_qfull = B_FALSE;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_init(&so->so_lock, NULL, MUTEX_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_init(&so->so_acceptq_lock, NULL, MUTEX_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning rw_init(&so->so_fallback_rwlock, NULL, RW_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_state_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_want_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_acceptq_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_snd_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_rcv_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_copy_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_closing_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*ARGSUSED*/
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsonode_destructor(void *buf, void *cdrarg)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sonode *so = buf;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct vnode *vp = SOTOV(so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_priv == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_peercred == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_oobmsg == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_rcv_q_head == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_acceptq_head == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_acceptq_tail == &so->so_acceptq_head);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_acceptq_next == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(vp->v_data == so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(vn_matchops(vp, socket_vnodeops));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vn_free(vp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_destroy(&so->so_lock);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_destroy(&so->so_acceptq_lock);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning rw_destroy(&so->so_fallback_rwlock);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_destroy(&so->so_state_cv);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_destroy(&so->so_want_cv);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_destroy(&so->so_acceptq_cv);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_destroy(&so->so_snd_cv);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_destroy(&so->so_rcv_cv);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_destroy(&so->so_closing_cv);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsonode_init(struct sonode *so, struct sockparams *sp, int family,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int type, int protocol, sonodeops_t *sops)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vnode_t *vp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vp = SOTOV(so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_flag = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_state = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_mode = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_count = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_family = family;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_type = type;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_protocol = protocol;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning SOCK_CONNID_INIT(so->so_proto_connid);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_options = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_linger.l_onoff = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_linger.l_linger = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_sndbuf = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_error = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcvtimeo = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_sndtimeo = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_oobmsg == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_oobmark = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_pgrp = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_peercred == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_zoneid = getzoneid();
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_sockparams = sp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_ops = sops;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_proto_handle = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_downcalls = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_copyflag = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_acceptq_head == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_acceptq_tail == &so->so_acceptq_head);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_acceptq_next == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vn_reinit(vp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vp->v_vfsp = rootvfs;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vp->v_type = VSOCK;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vp->v_rdev = sockdev;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_queued = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_q_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_q_last_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_last_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_snd_qfull = B_FALSE;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_minpsz = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_wakeup = B_FALSE;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_snd_wakeup = B_FALSE;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_flowctrld = B_FALSE;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_pollev = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&so->so_poll_list, sizeof (so->so_poll_list));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&so->so_proto_props, sizeof (struct sock_proto_props));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&(so->so_ksock_callbacks), sizeof (ksocket_callbacks_t));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_ksock_cb_arg = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_max_addr_len = sizeof (struct sockaddr_storage);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_direct = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vn_exists(vp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsonode_fini(struct sonode *so)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *mp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vnode_t *vp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_count == 0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_rcv_timer_tid) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(MUTEX_NOT_HELD(&so->so_lock));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) untimeout(so->so_rcv_timer_tid);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_timer_tid = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so_acceptq_flush(so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#ifdef DEBUG
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_enter(&so->so_lock);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so_verify_oobstate(so));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_exit(&so->so_lock);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#endif /* DEBUG */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((mp = so->so_oobmsg) != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning freemsg(mp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_oobmsg = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_state &= ~(SS_OOBPEND|SS_HAVEOOBDATA|SS_HADOOBDATA|
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning SS_RCVATMARK);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_poll_list.ph_list != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning pollwakeup(&so->so_poll_list, POLLERR);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning pollhead_clean(&so->so_poll_list);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_direct != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodirect_t *sodp = so->so_direct;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp->sod_uioafh == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_direct = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning kmem_cache_free(sock_sod_cache, sodp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vp = SOTOV(so);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning vn_invalid(vp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_peercred != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning crfree(so->so_peercred);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_peercred = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This function is called at the beginning of recvmsg().
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * If I/OAT is enabled on this sonode, initialize the uioa state machine
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * with state UIOA_ALLOC.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangninguio_t *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_rcv_init(struct sonode *so, int flags, struct uio **uiopp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct uio *suiop;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct uio *uiop;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodirect_t *sodp = so->so_direct;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (sodp == NULL)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning suiop = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uiop = *uiopp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_enter(sodp->sod_lockp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (uiop->uio_resid >= uioasync.mincnt &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp != NULL && (sodp->sod_state & SOD_ENABLED) &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioasync.enabled && !(flags & MSG_PEEK) &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning !(so->so_state & SS_CANTRCVMORE)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Big enough I/O for uioa min setup and an sodirect socket
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and sodirect enabled and uioa enabled and I/O will be done
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and not EOF so initialize the sodirect_t uioa_t with "uiop".
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (!uioainit(uiop, &sodp->sod_uioa)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Successful uioainit() so the uio_t part of the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * uioa_t will be used for all uio_t work to follow,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * we return the original "uiop" in "suiop".
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning suiop = uiop;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *uiopp = (uio_t *)&sodp->sod_uioa;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Before returning to the caller the passed in uio_t
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * "uiop" will be updated via a call to uioafini()
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * below.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Note, the uioa.uioa_state isn't set to UIOA_ENABLED
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * here as first we have to uioamove() any currently
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * queued M_DATA mblk_t(s) so it will be done later.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * In either uioainit() success or not case note the number
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * of uio bytes the caller wants for sod framework and/or
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * transport (e.g. TCP) strategy.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_want = uiop->uio_resid;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else if (sodp != NULL && (sodp->sod_state & SOD_ENABLED)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * No uioa but still using sodirect so note the number of
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * uio bytes the caller wants for sodirect framework and/or
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * transport (e.g. TCP) strategy.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_want = uiop->uio_resid;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_exit(sodp->sod_lockp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (suiop);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This function is called at the end of recvmsg(), it finializes all the I/OAT
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * operations, and reset the uioa state to UIOA_ALLOC.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningint
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_rcv_done(struct sonode *so, struct uio *suiop, struct uio *uiop)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int error = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodirect_t *sodp = so->so_direct;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *mp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (sodp == NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(MUTEX_HELD(sodp->sod_lockp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Finish any sodirect and uioa processing */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (suiop != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Finish any uioa_t processing */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(uiop == (uio_t *)&sodp->sod_uioa);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = uioafini(suiop, (uioa_t *)uiop);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((mp = sodp->sod_uioafh) != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioafh = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioaft = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning freemsg(mp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp->sod_uioafh == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (!(sodp->sod_state & SOD_WAKE_NOT)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Awoke */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_state &= SOD_WAKE_CLR;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_state |= SOD_WAKE_NOT;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Last, clear sod_want value */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_want = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (error);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Schedule a uioamove() on a mblk. This is ususally called from
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * protocols (e.g. TCP) on a I/OAT enabled sonode.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningmblk_t *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_uioa_mblk_init(struct sodirect_s *sodp, mblk_t *mp, size_t msg_size)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioa_t *uioap = &sodp->sod_uioa;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *mp1 = mp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *lmp = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(DB_TYPE(mp) == M_DATA);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(msg_size == msgdsize(mp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Caller must have lock held */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(MUTEX_HELD(sodp->sod_lockp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (uioap->uioa_state & UIOA_ENABLED) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Uioa is enabled */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (msg_size > uioap->uio_resid) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * There isn't enough uio space for the mblk_t chain
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * so disable uioa such that this and any additional
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * mblk_t data is handled by the socket and schedule
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * the socket for wakeup to finish this uioa.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioap->uioa_state &= UIOA_CLR;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioap->uioa_state |= UIOA_FINI;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (sodp->sod_state & SOD_WAKE_NOT) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_state &= SOD_WAKE_CLR;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_state |= SOD_WAKE_NEED;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (mp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning do {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uint32_t len = MBLKL(mp1);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (!uioamove(mp1->b_rptr, len, UIO_READ, uioap)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Scheduled, mark dblk_t as such */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning DB_FLAGS(mp1) |= DBLK_UIOA;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Error, turn off async processing */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioap->uioa_state &= UIOA_CLR;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioap->uioa_state |= UIOA_FINI;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning break;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning lmp = mp1;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } while ((mp1 = mp1->b_cont) != NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (mp1 != NULL || uioap->uio_resid == 0) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Not all mblk_t(s) uioamoved (error) or all uio
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * space has been consumed so schedule the socket
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * for wakeup to finish this uio.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_state &= SOD_WAKE_CLR;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_state |= SOD_WAKE_NEED;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Break the mblk chain if neccessary. */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (mp1 != NULL && lmp != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mp->b_next = mp1;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning lmp->b_cont = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (mp1);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This function is called on a mblk that thas been successfully uioamoved().
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_uioa_mblk_done(sodirect_t *sodp, mblk_t *bp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (bp != NULL && (bp->b_datap->db_flags & DBLK_UIOA)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * A uioa flaged mblk_t chain, already uio processed,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * add it to the sodirect uioa pending free list.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Note, a b_cont chain headed by a DBLK_UIOA enable
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * mblk_t must have all mblk_t(s) DBLK_UIOA enabled.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *bpt = sodp->sod_uioaft;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp != NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Add first mblk_t of "bp" chain to current sodirect uioa
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * free list tail mblk_t, if any, else empty list so new head.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (bpt == NULL)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioafh = bp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning else
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bpt->b_cont = bp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Walk mblk_t "bp" chain to find tail and adjust rptr of
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * each to reflect that uioamove() has consumed all data.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bpt = bp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning for (;;) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(bpt->b_datap->db_flags & DBLK_UIOA);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bpt->b_rptr = bpt->b_wptr;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (bpt->b_cont == NULL)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning break;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bpt = bpt->b_cont;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* New sodirect uioa free list tail */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioaft = bpt;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Only dequeue once with data returned per uioa_t */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (sodp->sod_uioa.uioa_state & UIOA_ENABLED) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioa.uioa_state &= UIOA_CLR;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioa.uioa_state |= UIOA_FINI;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * When transit from UIOA_INIT state to UIOA_ENABLE state in recvmsg(), call
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * this function on a non-STREAMS socket to schedule uioamove() on the data
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * that has already queued in this socket.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_uioa_so_init(struct sonode *so, struct sodirect_s *sodp, struct uio *uiop)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioa_t *uioap = (uioa_t *)uiop;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *lbp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *wbp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *bp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int len;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int error;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning boolean_t in_rcv_q = B_TRUE;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(MUTEX_HELD(sodp->sod_lockp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(&sodp->sod_uioa == uioap);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Walk first b_cont chain in sod_q
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and schedule any M_DATA mblk_t's for uio asynchronous move.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bp = so->so_rcv_q_head;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningagain:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Walk the chain */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning lbp = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning wbp = bp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning do {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (bp == NULL)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning break;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (wbp->b_datap->db_type != M_DATA) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Not M_DATA, no more uioa */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning goto nouioa;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((len = wbp->b_wptr - wbp->b_rptr) > 0) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Have a M_DATA mblk_t with data */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (len > uioap->uio_resid || (so->so_oobmark > 0 &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning len + uioap->uioa_mbytes >= so->so_oobmark)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Not enough uio sapce, or beyond oobmark */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning goto nouioa;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(!(wbp->b_datap->db_flags & DBLK_UIOA));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = uioamove(wbp->b_rptr, len,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning UIO_READ, uioap);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (!error) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Scheduled, mark dblk_t as such */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning wbp->b_datap->db_flags |= DBLK_UIOA;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Break the mblk chain */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning goto nouioa;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Save last wbp processed */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning lbp = wbp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } while ((wbp = wbp->b_cont) != NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (in_rcv_q && (bp == NULL || bp->b_next == NULL)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * We get here only once to process the sonode dump area
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * if so_rcv_q_head is NULL or all the mblks have been
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * successfully uioamoved()ed.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning in_rcv_q = B_FALSE;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* move to dump area */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bp = so->so_rcv_head;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning goto again;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningnouioa:
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* No more uioa */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioap->uioa_state &= UIOA_CLR;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning uioap->uioa_state |= UIOA_FINI;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * If we processed 1 or more mblk_t(s) then we need to split the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * current mblk_t chain in 2 so that all the uioamove()ed mblk_t(s)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * are in the current chain and the rest are in the following new
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * chain.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (lbp != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* New end of current chain */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning lbp->b_cont = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Insert new chain wbp after bp */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((wbp->b_next = bp->b_next) == NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * No need to grab so_lock, since sod_lockp
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * points to so_lock.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (in_rcv_q)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_q_last_head = wbp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning else
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_last_head = wbp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bp->b_next = wbp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bp->b_next->b_prev = bp->b_prev;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bp->b_prev = lbp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Initialize sodirect data structures on a socket.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_sock_init(struct sonode *so, struct stdata *stp, sod_enq_func enq_func,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sod_wakeup_func wake_func, kmutex_t *lockp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodirect_t *sodp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_direct == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_state |= SS_SODIRECT;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp = kmem_cache_alloc(sock_sod_cache, KM_SLEEP);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_state = SOD_ENABLED | SOD_WAKE_NOT;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_want = 0;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_q = (stp != NULL) ? RD(stp->sd_wrq) : NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_enqueue = enq_func;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_wakeup = wake_func;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioafh = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioaft = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_lockp = lockp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Remainder of the sod_uioa members are left uninitialized
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * but will be initialized later by uioainit() before uioa
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * is enabled.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_uioa.uioa_state = UIOA_ALLOC;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_direct = sodp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (stp != NULL)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning stp->sd_sodirect = sodp;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/*
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Init the sodirect kmem cache while sockfs is loading.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningvoid
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_init()
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Allocate sodirect_t kmem_cache */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sock_sod_cache = kmem_cache_create("sock_sod_cache",
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sizeof (sodirect_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningssize_t
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_uioa_mblk(struct sonode *so, mblk_t *mp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodirect_t *sodp = so->so_direct;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp != NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(MUTEX_HELD(sodp->sod_lockp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp->sod_state & SOD_ENABLED);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp->sod_uioa.uioa_state != (UIOA_ALLOC|UIOA_INIT));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp->sod_uioa.uioa_state & (UIOA_ENABLED|UIOA_FINI));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (mp == NULL && so->so_rcv_q_head != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mp = so->so_rcv_q_head;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(mp->b_prev != NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mp->b_prev = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_q_head = mp->b_next;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_rcv_q_head == NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_q_last_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mp->b_next = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sod_uioa_mblk_done(sodp, mp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_rcv_q_head == NULL && so->so_rcv_head != NULL &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning DB_TYPE(so->so_rcv_head) == M_DATA &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (DB_FLAGS(so->so_rcv_head) & DBLK_UIOA)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* more arrived */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_rcv_q_head == NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mp = so->so_rcv_head;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_head = mp->b_next;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_rcv_head == NULL)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_last_head = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mp->b_prev = mp->b_next = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sod_uioa_mblk_done(sodp, mp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#ifdef DEBUG
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_rcv_q_head != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *m = so->so_rcv_q_head;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning while (m != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (DB_FLAGS(m) & DBLK_UIOA) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cmn_err(CE_PANIC, "Unexpected I/OAT mblk %p"
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning " in so_rcv_q_head.\n", (void *)m);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning m = m->b_next;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_rcv_head != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mblk_t *m = so->so_rcv_head;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning while (m != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (DB_FLAGS(m) & DBLK_UIOA) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cmn_err(CE_PANIC, "Unexpected I/OAT mblk %p"
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning " in so_rcv_head.\n", (void *)m);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning m = m->b_next;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning }
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#endif
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (sodp->sod_uioa.uioa_mbytes);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning}