xref: /titanic_44/usr/src/uts/common/sys/sockfilter.h (revision 3e95bd4ab92abca814bd28e854607d1975c7dc88)
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) 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_SYS_SOCKFILTER_H
26 #define	_SYS_SOCKFILTER_H
27 
28 #include <sys/cred.h>
29 #include <sys/errno.h>
30 #include <sys/socket.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Opaque socket filter handle
38  */
39 typedef struct __sof_handle	*sof_handle_t;
40 
41 /*
42  * Return values for callback functions.
43  *
44  * A - Attach (passive/active) only
45  * P - Passive attach only
46  */
47 typedef enum {
48 	SOF_RVAL_DEFER = -3,		/* defer notification (P) */
49 	SOF_RVAL_DETACH = -2,		/* detach filter, continue proc. (A) */
50 	SOF_RVAL_CONTINUE = -1,		/* continue processing */
51 	SOF_RVAL_RETURN = 0,		/* stop proc, does not return error */
52 	SOF_RVAL_EINVAL = EINVAL,	/* stop proc., returns error */
53 	SOF_RVAL_EACCES = EACCES,	/* stop proc., returns error */
54 	SOF_RVAL_ENOMEM = ENOMEM,	/* stop proc., returns error */
55 	SOF_RVAL_ECONNABORTED = ECONNABORTED /* stop proc, returns error */
56 } sof_rval_t;
57 
58 /*
59  * Events generated by the sofop_notify callback.
60  */
61 typedef enum {				/* socket ... */
62 	SOF_EV_CLOSING,			/* ... is closing */
63 	SOF_EV_CONNECTED,		/* ... is connected */
64 	SOF_EV_CONNECTFAILED,		/* ... failed to connect */
65 	SOF_EV_DISCONNECTED,		/* ... was disconnected */
66 	SOF_EV_CANTRECVMORE,		/* ... cannot receive any more data */
67 	SOF_EV_CANTSENDMORE,		/* ... cannot send any more data */
68 	SOF_EV_INJECT_DATA_IN_OK,	/* ... has cleared rcv flow ctrl */
69 	SOF_EV_INJECT_DATA_OUT_OK,	/* ... has cleared snd flow ctrl */
70 } sof_event_t;
71 
72 /* Filter callbacks */
73 typedef sof_rval_t 	(*sof_attach_active_fn_t)(sof_handle_t, int, int, int,
74     cred_t *, void **);
75 typedef sof_rval_t 	(*sof_attach_passive_fn_t)(sof_handle_t, sof_handle_t,
76     void *, struct sockaddr *, socklen_t, struct sockaddr *, socklen_t,
77     void **);
78 typedef void 		(*sof_detach_fn_t)(sof_handle_t, void *, cred_t *);
79 typedef mblk_t 		*(*sof_data_in_fn_t)(sof_handle_t, void *, mblk_t *,
80     int, size_t *);
81 typedef mblk_t		*(*sof_data_in_proc_fn_t)(sof_handle_t, void *,
82     mblk_t *, cred_t *, size_t *);
83 typedef mblk_t		*(*sof_data_out_fn_t)(sof_handle_t, void *, mblk_t *,
84     struct nmsghdr *, cred_t *, sof_rval_t *);
85 typedef sof_rval_t	(*sof_bind_fn_t)(sof_handle_t, void *,
86     struct sockaddr *, socklen_t *, cred_t *);
87 typedef sof_rval_t	(*sof_listen_fn_t)(sof_handle_t, void *, int *,
88     cred_t *);
89 typedef sof_rval_t	(*sof_accept_fn_t)(sof_handle_t, void *, cred_t *);
90 typedef sof_rval_t	(*sof_connect_fn_t)(sof_handle_t, void *,
91     struct sockaddr *, socklen_t *, cred_t *);
92 typedef sof_rval_t	(*sof_shutdown_fn_t)(sof_handle_t, void *, int *,
93     cred_t *);
94 typedef sof_rval_t	(*sof_getsockname_fn_t)(sof_handle_t, void *,
95     struct sockaddr *, socklen_t *, cred_t *);
96 typedef sof_rval_t	(*sof_getpeername_fn_t)(sof_handle_t, void *,
97     struct sockaddr *, socklen_t *, cred_t *);
98 typedef sof_rval_t 		(*sof_setsockopt_fn_t)(sof_handle_t, void *,
99     int, int, void *, socklen_t *, cred_t *);
100 typedef sof_rval_t	(*sof_getsockopt_fn_t)(sof_handle_t, void *,
101     int, int, void *, socklen_t *, cred_t *);
102 typedef sof_rval_t	(*sof_ioctl_fn_t)(sof_handle_t, void *, int, intptr_t,
103     int, int32_t *, cred_t *);
104 typedef void		(*sof_mblk_prop_fn_t)(sof_handle_t, void *, ssize_t *,
105     ushort_t *, ushort_t *);
106 typedef void		(*sof_notify_fn_t)(sof_handle_t, void *, sof_event_t,
107     uintptr_t);
108 
109 typedef struct sof_ops {
110 	sof_attach_active_fn_t	sofop_attach_active;
111 	sof_attach_passive_fn_t	sofop_attach_passive;
112 	sof_detach_fn_t		sofop_detach;
113 	sof_data_in_fn_t	sofop_data_in;
114 	sof_data_in_proc_fn_t	sofop_data_in_proc;
115 	sof_data_out_fn_t	sofop_data_out;
116 	sof_bind_fn_t		sofop_bind;
117 	sof_listen_fn_t		sofop_listen;
118 	sof_connect_fn_t	sofop_connect;
119 	sof_accept_fn_t		sofop_accept;
120 	sof_shutdown_fn_t	sofop_shutdown;
121 	sof_getsockname_fn_t	sofop_getsockname;
122 	sof_getpeername_fn_t	sofop_getpeername;
123 	sof_setsockopt_fn_t	sofop_setsockopt;
124 	sof_getsockopt_fn_t	sofop_getsockopt;
125 	sof_ioctl_fn_t		sofop_ioctl;
126 	sof_mblk_prop_fn_t	sofop_mblk_prop;
127 	sof_notify_fn_t		sofop_notify;
128 } sof_ops_t;
129 
130 #define	SOF_VERSION	1
131 
132 extern int	sof_register(int, const char *, const sof_ops_t *, int);
133 extern int	sof_unregister(const char *);
134 
135 extern void	sof_newconn_ready(sof_handle_t);
136 extern void	sof_bypass(sof_handle_t);
137 extern void	*sof_get_cookie(sof_handle_t);
138 extern void 	*sof_cas_cookie(sof_handle_t, void *, void *);
139 extern int	sof_inject_data_out(sof_handle_t, mblk_t *, struct nmsghdr *,
140     boolean_t *);
141 extern int	sof_inject_data_in(sof_handle_t, mblk_t *, size_t, int,
142     boolean_t *);
143 extern void 	sof_rcv_flowctrl(sof_handle_t, boolean_t);
144 extern void 	sof_snd_flowctrl(sof_handle_t, boolean_t);
145 extern boolean_t sof_newconn_move(sof_handle_t, sof_handle_t);
146 
147 #ifdef	__cplusplus
148 }
149 #endif
150 
151 #endif	/* _SYS_SOCKFILTER_H */
152