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