blob: 56e312930b377e8a5be221a97022f30f9d768ff5 [file] [log] [blame]
Yu Xiangning0f1702c2008-12-11 20:04:13 -08001/*
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/*
Anders Persson41174432009-02-12 17:35:05 -080022 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
Yu Xiangning0f1702c2008-12-11 20:04:13 -080023 * Use is subject to license terms.
24 */
25
26#ifndef _SYS_SOCKET_PROTO_H_
27#define _SYS_SOCKET_PROTO_H_
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <sys/socket.h>
34
35/*
36 * Generation count
37 */
38typedef uint64_t sock_connid_t;
39
40#define SOCK_CONNID_INIT(id) { \
41 (id) = 0; \
42}
43#define SOCK_CONNID_BUMP(id) (++(id))
44#define SOCK_CONNID_LT(id1, id2) ((int64_t)((id1)-(id2)) < 0)
45
46/* Socket protocol properties */
47struct sock_proto_props {
48 uint_t sopp_flags; /* options to set */
49 ushort_t sopp_wroff; /* write offset */
50 ssize_t sopp_txhiwat; /* tx hi water mark */
51 ssize_t sopp_txlowat; /* tx lo water mark */
52 ssize_t sopp_rxhiwat; /* recv high water mark */
53 ssize_t sopp_rxlowat; /* recv low water mark */
54 ssize_t sopp_maxblk; /* maximum message block size */
55 ssize_t sopp_maxpsz; /* maximum packet size */
56 ssize_t sopp_minpsz; /* minimum packet size */
57 ushort_t sopp_tail; /* space available at the end */
58 uint_t sopp_zcopyflag; /* zero copy flag */
59 boolean_t sopp_oobinline; /* OOB inline */
60 uint_t sopp_rcvtimer; /* delayed recv notification (time) */
61 uint32_t sopp_rcvthresh; /* delayed recv notification (bytes) */
62 socklen_t sopp_maxaddrlen; /* maximum size of protocol address */
Anders Persson081c0aa2009-07-09 15:48:00 -070063 boolean_t sopp_loopback; /* loopback connection */
Yu Xiangning0f1702c2008-12-11 20:04:13 -080064};
65
66/* flags to determine which socket options are set */
67#define SOCKOPT_WROFF 0x0001 /* set write offset */
68#define SOCKOPT_RCVHIWAT 0x0002 /* set read side high water */
69#define SOCKOPT_RCVLOWAT 0x0004 /* set read side high water */
70#define SOCKOPT_MAXBLK 0x0008 /* set maximum message block size */
71#define SOCKOPT_TAIL 0x0010 /* set the extra allocated space */
72#define SOCKOPT_ZCOPY 0x0020 /* set/unset zero copy for sendfile */
73#define SOCKOPT_MAXPSZ 0x0040 /* set maxpsz for protocols */
74#define SOCKOPT_OOBINLINE 0x0080 /* set oob inline processing */
75#define SOCKOPT_RCVTIMER 0x0100
76#define SOCKOPT_RCVTHRESH 0x0200
77#define SOCKOPT_MAXADDRLEN 0x0400 /* set max address length */
78#define SOCKOPT_MINPSZ 0x0800 /* set minpsz for protocols */
Anders Persson081c0aa2009-07-09 15:48:00 -070079#define SOCKOPT_LOOPBACK 0x1000 /* set loopback */
Yu Xiangning0f1702c2008-12-11 20:04:13 -080080
81#define IS_SO_OOB_INLINE(so) ((so)->so_proto_props.sopp_oobinline)
82
83#ifdef _KERNEL
84
85struct T_capability_ack;
86
87typedef struct sock_upcalls_s sock_upcalls_t;
88typedef struct sock_downcalls_s sock_downcalls_t;
89
90/*
91 * Upcall and downcall handle for sockfs and transport layer.
92 */
93typedef struct __sock_upper_handle *sock_upper_handle_t;
94typedef struct __sock_lower_handle *sock_lower_handle_t;
95
96struct sock_downcalls_s {
97 void (*sd_activate)(sock_lower_handle_t, sock_upper_handle_t,
98 sock_upcalls_t *, int, cred_t *);
99 int (*sd_accept)(sock_lower_handle_t, sock_lower_handle_t,
100 sock_upper_handle_t, cred_t *);
101 int (*sd_bind)(sock_lower_handle_t, struct sockaddr *, socklen_t,
102 cred_t *);
103 int (*sd_listen)(sock_lower_handle_t, int, cred_t *);
104 int (*sd_connect)(sock_lower_handle_t, const struct sockaddr *,
105 socklen_t, sock_connid_t *, cred_t *);
106 int (*sd_getpeername)(sock_lower_handle_t, struct sockaddr *,
107 socklen_t *, cred_t *);
108 int (*sd_getsockname)(sock_lower_handle_t, struct sockaddr *,
109 socklen_t *, cred_t *);
110 int (*sd_getsockopt)(sock_lower_handle_t, int, int, void *,
111 socklen_t *, cred_t *);
112 int (*sd_setsockopt)(sock_lower_handle_t, int, int, const void *,
113 socklen_t, cred_t *);
114 int (*sd_send)(sock_lower_handle_t, mblk_t *, struct nmsghdr *,
115 cred_t *);
116 int (*sd_send_uio)(sock_lower_handle_t, uio_t *, struct nmsghdr *,
117 cred_t *);
118 int (*sd_recv_uio)(sock_lower_handle_t, uio_t *, struct nmsghdr *,
119 cred_t *);
120 short (*sd_poll)(sock_lower_handle_t, short, int, cred_t *);
121 int (*sd_shutdown)(sock_lower_handle_t, int, cred_t *);
122 void (*sd_clr_flowctrl)(sock_lower_handle_t);
123 int (*sd_ioctl)(sock_lower_handle_t, int, intptr_t, int,
124 int32_t *, cred_t *);
125 int (*sd_close)(sock_lower_handle_t, int, cred_t *);
126};
127
128typedef sock_lower_handle_t (*so_proto_create_func_t)(int, int, int,
129 sock_downcalls_t **, uint_t *, int *, int, cred_t *);
130
131typedef void (*so_proto_quiesced_cb_t)(sock_upper_handle_t, queue_t *,
132 struct T_capability_ack *, struct sockaddr *, socklen_t,
133 struct sockaddr *, socklen_t, short);
Anders Persson41174432009-02-12 17:35:05 -0800134typedef int (*so_proto_fallback_func_t)(sock_lower_handle_t, queue_t *,
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800135 boolean_t, so_proto_quiesced_cb_t);
136
137/*
Darren Reed0a0e9772009-09-24 07:28:12 -0700138 * These functions return EOPNOTSUPP and are intended for the sockfs
139 * developer that doesn't wish to supply stubs for every function themselves.
140 */
141extern int sock_accept_notsupp(sock_lower_handle_t, sock_lower_handle_t,
142 sock_upper_handle_t, cred_t *);
143extern int sock_bind_notsupp(sock_lower_handle_t, struct sockaddr *,
144 socklen_t, cred_t *);
145extern int sock_listen_notsupp(sock_lower_handle_t, int, cred_t *);
146extern int sock_connect_notsupp(sock_lower_handle_t,
147 const struct sockaddr *, socklen_t, sock_connid_t *, cred_t *);
148extern int sock_getpeername_notsupp(sock_lower_handle_t, struct sockaddr *,
149 socklen_t *, cred_t *);
150extern int sock_getsockname_notsupp(sock_lower_handle_t, struct sockaddr *,
151 socklen_t *, cred_t *);
152extern int sock_getsockopt_notsupp(sock_lower_handle_t, int, int, void *,
153 socklen_t *, cred_t *);
154extern int sock_setsockopt_notsupp(sock_lower_handle_t, int, int,
155 const void *, socklen_t, cred_t *);
156extern int sock_send_notsupp(sock_lower_handle_t, mblk_t *,
157 struct nmsghdr *, cred_t *);
158extern int sock_send_uio_notsupp(sock_lower_handle_t, uio_t *,
159 struct nmsghdr *, cred_t *);
160extern int sock_recv_uio_notsupp(sock_lower_handle_t, uio_t *,
161 struct nmsghdr *, cred_t *);
162extern short sock_poll_notsupp(sock_lower_handle_t, short, int, cred_t *);
163extern int sock_shutdown_notsupp(sock_lower_handle_t, int, cred_t *);
164extern void sock_clr_flowctrl_notsupp(sock_lower_handle_t);
165extern int sock_ioctl_notsupp(sock_lower_handle_t, int, intptr_t, int,
166 int32_t *, cred_t *);
167extern int sock_close_notsupp(sock_lower_handle_t, int, cred_t *);
168
169/*
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800170 * Upcalls and related information
171 */
172
173/*
174 * su_opctl() actions
175 */
176typedef enum sock_opctl_action {
177 SOCK_OPCTL_ENAB_ACCEPT = 0,
178 SOCK_OPCTL_SHUT_SEND,
179 SOCK_OPCTL_SHUT_RECV
180} sock_opctl_action_t;
181
182struct sock_upcalls_s {
183 sock_upper_handle_t (*su_newconn)(sock_upper_handle_t,
184 sock_lower_handle_t, sock_downcalls_t *, cred_t *, pid_t,
185 sock_upcalls_t **);
186 void (*su_connected)(sock_upper_handle_t, sock_connid_t, cred_t *,
187 pid_t);
188 int (*su_disconnected)(sock_upper_handle_t, sock_connid_t, int);
189 void (*su_opctl)(sock_upper_handle_t, sock_opctl_action_t,
190 uintptr_t);
191 ssize_t (*su_recv)(sock_upper_handle_t, mblk_t *, size_t, int,
192 int *, boolean_t *);
193 void (*su_set_proto_props)(sock_upper_handle_t,
194 struct sock_proto_props *);
195 void (*su_txq_full)(sock_upper_handle_t, boolean_t);
196 void (*su_signal_oob)(sock_upper_handle_t, ssize_t);
197 void (*su_zcopy_notify)(sock_upper_handle_t);
198 void (*su_set_error)(sock_upper_handle_t, int);
199};
200
201#define SOCK_UC_VERSION sizeof (sock_upcalls_t)
202#define SOCK_DC_VERSION sizeof (sock_downcalls_t)
203
204#define SOCKET_RECVHIWATER (48 * 1024)
205#define SOCKET_RECVLOWATER 1024
206
207#define SOCKET_NO_RCVTIMER 0
208#define SOCKET_TIMER_INTERVAL 50
209
210#endif /* _KERNEL */
211
212#ifdef __cplusplus
213}
214#endif
215
216#endif /* _SYS_SOCKET_PROTO_H_ */