xref: /titanic_50/usr/src/uts/common/io/ksocket/ksocket_impl.h (revision e2ca2865a6870e9c6cbef6becbcc68cafde64537)
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  */
26 
27 #ifndef	_INET_KSOCKET_KSOCKET_IMPL_H
28 #define	_INET_KSOCKET_KSOCKET_IMPL_H
29 
30 #define	KSTOSO(ks)	((struct sonode *)(ks))
31 #define	SOTOKS(so)	((ksocket_t)(uintptr_t)(so))
32 
33 #define	IS_KERNEL_SOCKET(so)	((so)->so_mode & SM_KERNEL)
34 
35 #define	KSOCKET_MOD_VERSION	"kernel socket module"
36 
37 #define	__KSOCKET_EV_connected		KSOCKET_EV_CONNECTED
38 #define	__KSOCKET_EV_connectfailed	KSOCKET_EV_CONNECTFAILED
39 #define	__KSOCKET_EV_disconnected	KSOCKET_EV_DISCONNECTED
40 #define	__KSOCKET_EV_oobdata		KSOCKET_EV_OOBDATA
41 #define	__KSOCKET_EV_newdata		KSOCKET_EV_NEWDATA
42 #define	__KSOCKET_EV_newconn		KSOCKET_EV_NEWCONN
43 #define	__KSOCKET_EV_cansend		KSOCKET_EV_CANSEND
44 #define	__KSOCKET_EV_cantsendmore	KSOCKET_EV_CANTSENDMORE
45 #define	__KSOCKET_EV_cantrecvmore	KSOCKET_EV_CANTRECVMORE
46 #define	__KSOCKET_EV_error		KSOCKET_EV_ERROR
47 
48 #define	KSOCKET_CALLBACK(so, cbfn, arg) 				\
49 	if ((so)->so_ksock_callbacks.ksock_cb_##cbfn != NULL) {		\
50 		(*(so)->so_ksock_callbacks.ksock_cb_##cbfn)(SOTOKS(so),	\
51 		    __KSOCKET_EV_##cbfn, (so)->so_ksock_cb_arg, (arg));	\
52 	}
53 
54 #define	KSOCKET_FMODE(so)	FREAD|FWRITE|	\
55 	((KSTOSO(so)->so_state & (SS_NDELAY|SS_NONBLOCK)) ? FNDELAY : 0)
56 
57 #define	KSOCKET_VALID(ks)	\
58 	((ks) != NULL && (KSTOSO(ks))->so_mode & SM_KERNEL &&		\
59 	    !((KSTOSO(ks))->so_state & SS_CLOSING))
60 
61 #define	SETCALLBACK(so, cb, cbfn, cbflg)			\
62 	if ((cb)->ksock_cb_flags & (cbflg)) {			\
63 		(so)->so_ksock_callbacks.ksock_cb_##cbfn	\
64 		    = (cb)->ksock_cb_##cbfn;			\
65 		if ((cb)->ksock_cb_##cbfn == NULL)		\
66 			(so)->so_ksock_callbacks.ksock_cb_flags \
67 			    &= ~(cbflg);			\
68 		else						\
69 			(so)->so_ksock_callbacks.ksock_cb_flags \
70 			    |= (cbflg);				\
71 	}
72 
73 
74 #endif /* _INET_KSOCKET_KSOCKET_IMPL_H */
75