xref: /titanic_50/usr/src/uts/common/io/ksocket/ksocket_impl.h (revision 0f1702c5201310f0529cd5abb77652e5e9b241b6)
1*0f1702c5SYu Xiangning /*
2*0f1702c5SYu Xiangning  * CDDL HEADER START
3*0f1702c5SYu Xiangning  *
4*0f1702c5SYu Xiangning  * The contents of this file are subject to the terms of the
5*0f1702c5SYu Xiangning  * Common Development and Distribution License (the "License").
6*0f1702c5SYu Xiangning  * You may not use this file except in compliance with the License.
7*0f1702c5SYu Xiangning  *
8*0f1702c5SYu Xiangning  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*0f1702c5SYu Xiangning  * or http://www.opensolaris.org/os/licensing.
10*0f1702c5SYu Xiangning  * See the License for the specific language governing permissions
11*0f1702c5SYu Xiangning  * and limitations under the License.
12*0f1702c5SYu Xiangning  *
13*0f1702c5SYu Xiangning  * When distributing Covered Code, include this CDDL HEADER in each
14*0f1702c5SYu Xiangning  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*0f1702c5SYu Xiangning  * If applicable, add the following below this CDDL HEADER, with the
16*0f1702c5SYu Xiangning  * fields enclosed by brackets "[]" replaced with your own identifying
17*0f1702c5SYu Xiangning  * information: Portions Copyright [yyyy] [name of copyright owner]
18*0f1702c5SYu Xiangning  *
19*0f1702c5SYu Xiangning  * CDDL HEADER END
20*0f1702c5SYu Xiangning  */
21*0f1702c5SYu Xiangning 
22*0f1702c5SYu Xiangning /*
23*0f1702c5SYu Xiangning  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*0f1702c5SYu Xiangning  * Use is subject to license terms.
25*0f1702c5SYu Xiangning  */
26*0f1702c5SYu Xiangning 
27*0f1702c5SYu Xiangning #ifndef	_INET_KSOCKET_KSOCKET_IMPL_H
28*0f1702c5SYu Xiangning #define	_INET_KSOCKET_KSOCKET_IMPL_H
29*0f1702c5SYu Xiangning 
30*0f1702c5SYu Xiangning #define	KSTOSO(ks)	((struct sonode *)(ks))
31*0f1702c5SYu Xiangning #define	SOTOKS(so)	((ksocket_t)(uintptr_t)(so))
32*0f1702c5SYu Xiangning 
33*0f1702c5SYu Xiangning #define	IS_KERNEL_SOCKET(so)	((so)->so_mode & SM_KERNEL)
34*0f1702c5SYu Xiangning 
35*0f1702c5SYu Xiangning #define	KSOCKET_MOD_VERSION	"kernel socket module"
36*0f1702c5SYu Xiangning 
37*0f1702c5SYu Xiangning #define	__KSOCKET_EV_connected		KSOCKET_EV_CONNECTED
38*0f1702c5SYu Xiangning #define	__KSOCKET_EV_connectfailed	KSOCKET_EV_CONNECTFAILED
39*0f1702c5SYu Xiangning #define	__KSOCKET_EV_disconnected	KSOCKET_EV_DISCONNECTED
40*0f1702c5SYu Xiangning #define	__KSOCKET_EV_oobdata		KSOCKET_EV_OOBDATA
41*0f1702c5SYu Xiangning #define	__KSOCKET_EV_newdata		KSOCKET_EV_NEWDATA
42*0f1702c5SYu Xiangning #define	__KSOCKET_EV_newconn		KSOCKET_EV_NEWCONN
43*0f1702c5SYu Xiangning #define	__KSOCKET_EV_cansend		KSOCKET_EV_CANSEND
44*0f1702c5SYu Xiangning #define	__KSOCKET_EV_cantsendmore	KSOCKET_EV_CANTSENDMORE
45*0f1702c5SYu Xiangning #define	__KSOCKET_EV_cantrecvmore	KSOCKET_EV_CANTRECVMORE
46*0f1702c5SYu Xiangning #define	__KSOCKET_EV_error		KSOCKET_EV_ERROR
47*0f1702c5SYu Xiangning 
48*0f1702c5SYu Xiangning #define	KSOCKET_CALLBACK(so, cbfn, arg) 				\
49*0f1702c5SYu Xiangning 	if ((so)->so_ksock_callbacks.ksock_cb_##cbfn != NULL) {		\
50*0f1702c5SYu Xiangning 		(*(so)->so_ksock_callbacks.ksock_cb_##cbfn)(SOTOKS(so),	\
51*0f1702c5SYu Xiangning 		    __KSOCKET_EV_##cbfn, (so)->so_ksock_cb_arg, (arg));	\
52*0f1702c5SYu Xiangning 	}
53*0f1702c5SYu Xiangning 
54*0f1702c5SYu Xiangning #define	KSOCKET_FMODE(so)	FREAD|FWRITE|	\
55*0f1702c5SYu Xiangning 	((KSTOSO(so)->so_state & (SS_NDELAY|SS_NONBLOCK)) ? FNDELAY : 0)
56*0f1702c5SYu Xiangning 
57*0f1702c5SYu Xiangning #define	KSOCKET_VALID(ks)	\
58*0f1702c5SYu Xiangning 	((ks) != NULL && (KSTOSO(ks))->so_mode & SM_KERNEL &&		\
59*0f1702c5SYu Xiangning 	    !((KSTOSO(ks))->so_state & SS_CLOSING))
60*0f1702c5SYu Xiangning 
61*0f1702c5SYu Xiangning #define	SETCALLBACK(so, cb, cbfn, cbflg)			\
62*0f1702c5SYu Xiangning 	if ((cb)->ksock_cb_flags & (cbflg)) {			\
63*0f1702c5SYu Xiangning 		(so)->so_ksock_callbacks.ksock_cb_##cbfn	\
64*0f1702c5SYu Xiangning 		    = (cb)->ksock_cb_##cbfn;			\
65*0f1702c5SYu Xiangning 		if ((cb)->ksock_cb_##cbfn == NULL)		\
66*0f1702c5SYu Xiangning 			(so)->so_ksock_callbacks.ksock_cb_flags \
67*0f1702c5SYu Xiangning 			    &= ~(cbflg);			\
68*0f1702c5SYu Xiangning 		else						\
69*0f1702c5SYu Xiangning 			(so)->so_ksock_callbacks.ksock_cb_flags \
70*0f1702c5SYu Xiangning 			    |= (cbflg);				\
71*0f1702c5SYu Xiangning 	}
72*0f1702c5SYu Xiangning 
73*0f1702c5SYu Xiangning 
74*0f1702c5SYu Xiangning #endif /* _INET_KSOCKET_KSOCKET_IMPL_H */
75