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