xref: /titanic_52/usr/src/uts/common/sys/ksocket.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _SYS_KSOCKET_H_
26 #define	_SYS_KSOCKET_H_
27 
28 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 
32 /* Opaque kernel socket type */
33 typedef struct __ksocket *ksocket_t;
34 struct nmsghdr;
35 
36 /* flag bit for each Callback Event */
37 #define	KSOCKET_CB_CONNECTED		0x00000001
38 #define	KSOCKET_CB_CONNECTFAILED	0x00000002
39 #define	KSOCKET_CB_DISCONNECTED		0x00000004
40 #define	KSOCKET_CB_NEWDATA		0x00000008
41 #define	KSOCKET_CB_NEWCONN		0x00000010
42 #define	KSOCKET_CB_CANSEND		0x00000020
43 #define	KSOCKET_CB_OOBDATA		0x00000040
44 #define	KSOCKET_CB_CANTSENDMORE		0x00000080
45 #define	KSOCKET_CB_CANTRECVMORE		0x00000100
46 #define	KSOCKET_CB_ERROR		0x00000200
47 
48 /*
49  * Kernel Socket Callback Events
50  */
51 typedef enum ksocket_event {
52 	KSOCKET_EV_CONNECTED,
53 	KSOCKET_EV_CONNECTFAILED,
54 	KSOCKET_EV_DISCONNECTED,
55 	KSOCKET_EV_OOBDATA,
56 	KSOCKET_EV_NEWDATA,
57 	KSOCKET_EV_NEWCONN,
58 	KSOCKET_EV_CANSEND,
59 	KSOCKET_EV_CANTSENDMORE,
60 	KSOCKET_EV_CANTRECVMORE,
61 	KSOCKET_EV_ERROR
62 } ksocket_callback_event_t;
63 
64 typedef	void (*ksocket_callback_t)(ksocket_t, ksocket_callback_event_t,
65     void *, uintptr_t);
66 
67 typedef struct ksocket_callbacks {
68 	uint32_t		ksock_cb_flags;
69 	ksocket_callback_t	ksock_cb_connected;
70 	ksocket_callback_t	ksock_cb_connectfailed;
71 	ksocket_callback_t	ksock_cb_disconnected;
72 	ksocket_callback_t	ksock_cb_newdata;
73 	ksocket_callback_t	ksock_cb_newconn;
74 	ksocket_callback_t	ksock_cb_cansend;
75 	ksocket_callback_t	ksock_cb_oobdata;
76 	ksocket_callback_t	ksock_cb_cantsendmore;
77 	ksocket_callback_t	ksock_cb_cantrecvmore;
78 	ksocket_callback_t	ksock_cb_error;
79 } ksocket_callbacks_t;
80 
81 #define	KSOCKET_SLEEP	SOCKET_SLEEP
82 #define	KSOCKET_NOSLEEP	SOCKET_NOSLEEP
83 
84 extern int 	ksocket_socket(ksocket_t *, int, int, int, int, struct cred *);
85 extern int 	ksocket_bind(ksocket_t, struct sockaddr *, socklen_t,
86 		    struct cred *);
87 extern int 	ksocket_listen(ksocket_t, int, struct cred *);
88 extern int 	ksocket_accept(ksocket_t, struct sockaddr *, socklen_t *,
89 		    ksocket_t *, struct cred *);
90 extern int 	ksocket_connect(ksocket_t, struct sockaddr *, socklen_t,
91 		    struct cred *);
92 extern int 	ksocket_send(ksocket_t, void *, size_t, int, size_t *,
93 		    struct cred *);
94 extern int	ksocket_sendto(ksocket_t, void *, size_t, int,
95 		    struct sockaddr *, socklen_t, size_t *, struct cred *);
96 extern int 	ksocket_sendmsg(ksocket_t, struct nmsghdr *, int, size_t *,
97 		    struct cred *);
98 extern int	ksocket_sendmblk(ksocket_t, struct nmsghdr *, int, mblk_t **,
99 		    struct cred *);
100 extern int 	ksocket_recv(ksocket_t, void *, size_t, int, size_t *,
101 		    struct cred *);
102 extern int	ksocket_recvfrom(ksocket_t, void *, size_t, int,
103 		    struct sockaddr *, socklen_t *, size_t *, struct cred *);
104 extern int	ksocket_recvmsg(ksocket_t, struct nmsghdr *, int, size_t *,
105 		    struct cred *);
106 extern int	ksocket_shutdown(ksocket_t, int, struct cred *);
107 extern int 	ksocket_setsockopt(ksocket_t, int, int, const void *, int,
108 		    struct cred *);
109 extern int 	ksocket_getsockopt(ksocket_t, int, int, void *, int *,
110 		    struct cred *);
111 extern int 	ksocket_getpeername(ksocket_t, struct sockaddr *, socklen_t *,
112 		    struct cred *);
113 extern int 	ksocket_getsockname(ksocket_t, struct sockaddr *, socklen_t *,
114 		    struct cred *);
115 extern int	ksocket_ioctl(ksocket_t, int, intptr_t, int *, struct cred *);
116 extern int	ksocket_setcallbacks(ksocket_t, ksocket_callbacks_t *, void *,
117 		    struct cred *);
118 extern int 	ksocket_close(ksocket_t, struct cred *);
119 extern void	ksocket_hold(ksocket_t);
120 extern void	ksocket_rele(ksocket_t);
121 
122 #ifdef	__cplusplus
123 }
124 #endif
125 
126 #endif /* _SYS_KSOCKET_H_ */
127