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