usr/src/uts/common/fs/sockfs/sockssl.c
changeset 898 64b2a371a6bd
child 5850 0ec7030e8335
equal deleted inserted replaced
897:8bc35ca89c2f 898:64b2a371a6bd
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License, Version 1.0 only
       
     6  * (the "License").  You may not use this file except in compliance
       
     7  * with the License.
       
     8  *
       
     9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10  * or http://www.opensolaris.org/os/licensing.
       
    11  * See the License for the specific language governing permissions
       
    12  * and limitations under the License.
       
    13  *
       
    14  * When distributing Covered Code, include this CDDL HEADER in each
       
    15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16  * If applicable, add the following below this CDDL HEADER, with the
       
    17  * fields enclosed by brackets "[]" replaced with your own identifying
       
    18  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    19  *
       
    20  * CDDL HEADER END
       
    21  */
       
    22 /*
       
    23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
       
    24  * Use is subject to license terms.
       
    25  */
       
    26 
       
    27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
       
    28 
       
    29 #include <sys/types.h>
       
    30 #include <sys/param.h>
       
    31 #include <sys/systm.h>
       
    32 #include <sys/kmem.h>
       
    33 #include <sys/sysmacros.h>
       
    34 #include <sys/vnode.h>
       
    35 #include <sys/debug.h>
       
    36 #include <sys/errno.h>
       
    37 #include <sys/stream.h>
       
    38 #include <sys/strsubr.h>
       
    39 #include <sys/vtrace.h>
       
    40 #include <sys/strsun.h>
       
    41 #include <sys/cmn_err.h>
       
    42 
       
    43 #include <sys/socket.h>
       
    44 #include <sys/sockio.h>
       
    45 #include <sys/socketvar.h>
       
    46 
       
    47 #include <inet/kssl/ksslapi.h>
       
    48 
       
    49 
       
    50 /*
       
    51  * This routine is registered with the stream head to be called by kstrgetmsg()
       
    52  * with every packet received on the read queue, and before copying its
       
    53  * content to user buffers. kstrgetmsg() calls only once with the same
       
    54  * message.
       
    55  * If the message is successfully procssed, then it is returned.
       
    56  * A failed message will be freed.
       
    57  */
       
    58 /* ARGSUSED */
       
    59 mblk_t *
       
    60 strsock_kssl_input(vnode_t *vp, mblk_t *mp,
       
    61 		strwakeup_t *wakeups, strsigset_t *firstmsgsigs,
       
    62 		strsigset_t *allmsgsigs, strpollset_t *pollwakeups)
       
    63 {
       
    64 	struct sonode *so = VTOSO(vp);
       
    65 	kssl_ctx_t kssl_ctx = so->so_kssl_ctx;
       
    66 	kssl_cmd_t kssl_cmd;
       
    67 	mblk_t *out;
       
    68 
       
    69 	dprintso(so, 1, ("strsock_kssl_input(%p, %p)\n", vp, mp));
       
    70 
       
    71 	ASSERT(!(DB_FLAGS(mp) & DBLK_COOKED));
       
    72 
       
    73 	kssl_cmd = kssl_handle_record(kssl_ctx, &mp, &out);
       
    74 
       
    75 	switch (kssl_cmd) {
       
    76 	case KSSL_CMD_NONE:
       
    77 		return (NULL);
       
    78 
       
    79 	case KSSL_CMD_DELIVER_PROXY:
       
    80 		return (mp);
       
    81 
       
    82 	case KSSL_CMD_SEND: {
       
    83 		ASSERT(out != NULL);
       
    84 
       
    85 		putnext(vp->v_stream->sd_wrq, out);
       
    86 	}
       
    87 	/* FALLTHU */
       
    88 	default:
       
    89 		/* transient error. */
       
    90 		return (NULL);
       
    91 	}
       
    92 }
       
    93 
       
    94 /*
       
    95  * This routine is registered with the stream head be called by
       
    96  * kstrmakedata() with every packet sent downstreams.
       
    97  * If the message is successfully procssed, then it is returned.
       
    98  */
       
    99 /* ARGSUSED */
       
   100 mblk_t *
       
   101 strsock_kssl_output(vnode_t *vp, mblk_t *mp,
       
   102 		strwakeup_t *wakeups, strsigset_t *firstmsgsigs,
       
   103 		strsigset_t *allmsgsigs, strpollset_t *pollwakeups)
       
   104 {
       
   105 	struct sonode *so = VTOSO(vp);
       
   106 	kssl_ctx_t kssl_ctx = so->so_kssl_ctx;
       
   107 	mblk_t *recmp;
       
   108 
       
   109 	dprintso(so, 1, ("strsock_kssl_output(%p, %p)\n", vp, mp));
       
   110 
       
   111 	if ((recmp = kssl_build_record(kssl_ctx, mp)) == NULL) {
       
   112 		/* The caller will free the bogus message */
       
   113 		return (NULL);
       
   114 	}
       
   115 	return (recmp);
       
   116 }