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 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * Copyright 2015, Joyent, Inc. 26 */ 27 28 #ifndef _INET_KSOCKET_KSOCKET_IMPL_H 29 #define _INET_KSOCKET_KSOCKET_IMPL_H 30 31 /* 32 * Note that if this relationship ever changes, the logic in ksocket_krecv_set 33 * must be updated and we must maintain local state about this on whatever the 34 * new ksocket object is. 35 */ 36 #define KSTOSO(ks) ((struct sonode *)(ks)) 37 #define SOTOKS(so) ((ksocket_t)(uintptr_t)(so)) 38 39 #define IS_KERNEL_SOCKET(so) ((so)->so_mode & SM_KERNEL) 40 41 #define KSOCKET_MOD_VERSION "kernel socket module" 42 43 #define __KSOCKET_EV_connected KSOCKET_EV_CONNECTED 44 #define __KSOCKET_EV_connectfailed KSOCKET_EV_CONNECTFAILED 45 #define __KSOCKET_EV_disconnected KSOCKET_EV_DISCONNECTED 46 #define __KSOCKET_EV_oobdata KSOCKET_EV_OOBDATA 47 #define __KSOCKET_EV_newdata KSOCKET_EV_NEWDATA 48 #define __KSOCKET_EV_newconn KSOCKET_EV_NEWCONN 49 #define __KSOCKET_EV_cansend KSOCKET_EV_CANSEND 50 #define __KSOCKET_EV_cantsendmore KSOCKET_EV_CANTSENDMORE 51 #define __KSOCKET_EV_cantrecvmore KSOCKET_EV_CANTRECVMORE 52 #define __KSOCKET_EV_error KSOCKET_EV_ERROR 53 54 #define KSOCKET_CALLBACK(so, cbfn, arg) \ 55 if ((so)->so_ksock_callbacks.ksock_cb_##cbfn != NULL) { \ 56 (*(so)->so_ksock_callbacks.ksock_cb_##cbfn)(SOTOKS(so), \ 57 __KSOCKET_EV_##cbfn, (so)->so_ksock_cb_arg, (arg)); \ 58 } 59 60 #define KSOCKET_FMODE(so) FREAD|FWRITE| \ 61 ((KSTOSO(so)->so_state & (SS_NDELAY|SS_NONBLOCK)) ? FNDELAY : 0) 62 63 #define KSOCKET_VALID(ks) \ 64 ((ks) != NULL && (KSTOSO(ks))->so_mode & SM_KERNEL && \ 65 !((KSTOSO(ks))->so_state & SS_CLOSING)) 66 67 #define SETCALLBACK(so, cb, cbfn, cbflg) \ 68 if ((cb)->ksock_cb_flags & (cbflg)) { \ 69 (so)->so_ksock_callbacks.ksock_cb_##cbfn \ 70 = (cb)->ksock_cb_##cbfn; \ 71 if ((cb)->ksock_cb_##cbfn == NULL) \ 72 (so)->so_ksock_callbacks.ksock_cb_flags \ 73 &= ~(cbflg); \ 74 else \ 75 (so)->so_ksock_callbacks.ksock_cb_flags \ 76 |= (cbflg); \ 77 } 78 79 80 #endif /* _INET_KSOCKET_KSOCKET_IMPL_H */ 81