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 (c) 2012, OmniTI Computer Consulting, Inc. All rights reserved. 23 */ 24 25 #include <sys/kmem.h> 26 #include <sys/systm.h> 27 #include <sys/stropts.h> 28 #include <sys/strsun.h> 29 #include <sys/socketvar.h> 30 #include <sys/sockfilter.h> 31 #include <sys/note.h> 32 #include <sys/taskq.h> 33 34 static struct modlmisc dataf_modlmisc = { 35 &mod_miscops, 36 "Kernel data-ready socket filter" 37 }; 38 39 static struct modlinkage dataf_modlinkage = { 40 MODREV_1, 41 &dataf_modlmisc, 42 NULL 43 }; 44 45 #define DATAFILT_MODULE "datafilt" 46 47 /* ARGSUSED */ 48 sof_rval_t 49 dataf_attach_passive_cb(sof_handle_t handle, sof_handle_t ph, 50 void *parg, struct sockaddr *laddr, socklen_t laddrlen, 51 struct sockaddr *faddr, socklen_t faddrlen, void **cookiep) 52 { 53 return (SOF_RVAL_DEFER); 54 } 55 56 void 57 dataf_detach_cb(sof_handle_t handle, void *cookie, cred_t *cr) 58 { 59 _NOTE(ARGUNUSED(handle, cookie, cr)); 60 } 61 62 /* 63 * Called for each incoming segment. 64 */ 65 mblk_t * 66 dataf_data_in_cb(sof_handle_t handle, void *cookie, mblk_t *mp, int flags, 67 size_t *lenp) 68 { 69 _NOTE(ARGUNUSED(cookie, flags, lenp)); 70 71 if (mp != NULL && MBLKL(mp) > 0) 72 sof_newconn_ready(handle); 73 74 return (mp); 75 } 76 77 sof_ops_t dataf_ops = { 78 .sofop_attach_passive = dataf_attach_passive_cb, 79 .sofop_detach = dataf_detach_cb, 80 .sofop_data_in = dataf_data_in_cb 81 }; 82 83 int 84 _init(void) 85 { 86 int error; 87 88 if ((error = sof_register(SOF_VERSION, DATAFILT_MODULE, &dataf_ops, 0)) 89 != 0) 90 return (error); 91 if ((error = mod_install(&dataf_modlinkage)) != 0) 92 (void) sof_unregister(DATAFILT_MODULE); 93 94 return (error); 95 } 96 97 int 98 _fini(void) 99 { 100 int error; 101 102 if ((error = sof_unregister(DATAFILT_MODULE)) != 0) 103 return (error); 104 105 return (mod_remove(&dataf_modlinkage)); 106 } 107 108 int 109 _info(struct modinfo *modinfop) 110 { 111 return (mod_info(&dataf_modlinkage, modinfop)); 112 }