blob: 4e1a4a0f35c3e66e89e1d5bba37c3e77a6982786 [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 Persson3e95bd42010-06-17 17:22:09 -070022 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
Andy Fiddaman78a2e112019-08-22 14:59:11 +000023 * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
Yu Xiangning0f1702c2008-12-11 20:04:13 -080024 */
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>
Gordon Ross33697082017-05-08 10:08:35 -040034#include <sys/stream.h>
Andy Fiddaman78a2e112019-08-22 14:59:11 +000035#include <sys/vnode.h>
Yu Xiangning0f1702c2008-12-11 20:04:13 -080036
37/*
38 * Generation count
39 */
40typedef uint64_t sock_connid_t;
41
42#define SOCK_CONNID_INIT(id) { \
43 (id) = 0; \
44}
45#define SOCK_CONNID_BUMP(id) (++(id))
46#define SOCK_CONNID_LT(id1, id2) ((int64_t)((id1)-(id2)) < 0)
47
48/* Socket protocol properties */
49struct sock_proto_props {
50 uint_t sopp_flags; /* options to set */
51 ushort_t sopp_wroff; /* write offset */
52 ssize_t sopp_txhiwat; /* tx hi water mark */
53 ssize_t sopp_txlowat; /* tx lo water mark */
54 ssize_t sopp_rxhiwat; /* recv high water mark */
55 ssize_t sopp_rxlowat; /* recv low water mark */
56 ssize_t sopp_maxblk; /* maximum message block size */
57 ssize_t sopp_maxpsz; /* maximum packet size */
58 ssize_t sopp_minpsz; /* minimum packet size */
59 ushort_t sopp_tail; /* space available at the end */
60 uint_t sopp_zcopyflag; /* zero copy flag */
61 boolean_t sopp_oobinline; /* OOB inline */
62 uint_t sopp_rcvtimer; /* delayed recv notification (time) */
63 uint32_t sopp_rcvthresh; /* delayed recv notification (bytes) */
64 socklen_t sopp_maxaddrlen; /* maximum size of protocol address */
Anders Persson081c0aa2009-07-09 15:48:00 -070065 boolean_t sopp_loopback; /* loopback connection */
Yu Xiangning0f1702c2008-12-11 20:04:13 -080066};
67
68/* flags to determine which socket options are set */
69#define SOCKOPT_WROFF 0x0001 /* set write offset */
70#define SOCKOPT_RCVHIWAT 0x0002 /* set read side high water */
71#define SOCKOPT_RCVLOWAT 0x0004 /* set read side high water */
72#define SOCKOPT_MAXBLK 0x0008 /* set maximum message block size */
73#define SOCKOPT_TAIL 0x0010 /* set the extra allocated space */
74#define SOCKOPT_ZCOPY 0x0020 /* set/unset zero copy for sendfile */
75#define SOCKOPT_MAXPSZ 0x0040 /* set maxpsz for protocols */
76#define SOCKOPT_OOBINLINE 0x0080 /* set oob inline processing */
77#define SOCKOPT_RCVTIMER 0x0100
78#define SOCKOPT_RCVTHRESH 0x0200
79#define SOCKOPT_MAXADDRLEN 0x0400 /* set max address length */
80#define SOCKOPT_MINPSZ 0x0800 /* set minpsz for protocols */
Anders Persson081c0aa2009-07-09 15:48:00 -070081#define SOCKOPT_LOOPBACK 0x1000 /* set loopback */
Yu Xiangning0f1702c2008-12-11 20:04:13 -080082
83#define IS_SO_OOB_INLINE(so) ((so)->so_proto_props.sopp_oobinline)
84
85#ifdef _KERNEL
86
87struct T_capability_ack;
88
89typedef struct sock_upcalls_s sock_upcalls_t;
90typedef struct sock_downcalls_s sock_downcalls_t;
91
92/*
93 * Upcall and downcall handle for sockfs and transport layer.
94 */
95typedef struct __sock_upper_handle *sock_upper_handle_t;
96typedef struct __sock_lower_handle *sock_lower_handle_t;
97
98struct sock_downcalls_s {
99 void (*sd_activate)(sock_lower_handle_t, sock_upper_handle_t,
100 sock_upcalls_t *, int, cred_t *);
101 int (*sd_accept)(sock_lower_handle_t, sock_lower_handle_t,
102 sock_upper_handle_t, cred_t *);
103 int (*sd_bind)(sock_lower_handle_t, struct sockaddr *, socklen_t,
104 cred_t *);
105 int (*sd_listen)(sock_lower_handle_t, int, cred_t *);
106 int (*sd_connect)(sock_lower_handle_t, const struct sockaddr *,
107 socklen_t, sock_connid_t *, cred_t *);
108 int (*sd_getpeername)(sock_lower_handle_t, struct sockaddr *,
109 socklen_t *, cred_t *);
110 int (*sd_getsockname)(sock_lower_handle_t, struct sockaddr *,
111 socklen_t *, cred_t *);
112 int (*sd_getsockopt)(sock_lower_handle_t, int, int, void *,
113 socklen_t *, cred_t *);
114 int (*sd_setsockopt)(sock_lower_handle_t, int, int, const void *,
115 socklen_t, cred_t *);
116 int (*sd_send)(sock_lower_handle_t, mblk_t *, struct nmsghdr *,
117 cred_t *);
118 int (*sd_send_uio)(sock_lower_handle_t, uio_t *, struct nmsghdr *,
119 cred_t *);
120 int (*sd_recv_uio)(sock_lower_handle_t, uio_t *, struct nmsghdr *,
121 cred_t *);
122 short (*sd_poll)(sock_lower_handle_t, short, int, cred_t *);
123 int (*sd_shutdown)(sock_lower_handle_t, int, cred_t *);
124 void (*sd_clr_flowctrl)(sock_lower_handle_t);
125 int (*sd_ioctl)(sock_lower_handle_t, int, intptr_t, int,
126 int32_t *, cred_t *);
127 int (*sd_close)(sock_lower_handle_t, int, cred_t *);
128};
129
130typedef sock_lower_handle_t (*so_proto_create_func_t)(int, int, int,
131 sock_downcalls_t **, uint_t *, int *, int, cred_t *);
132
Anders Persson3e95bd42010-06-17 17:22:09 -0700133typedef struct sock_quiesce_arg {
134 mblk_t *soqa_exdata_mp;
135 mblk_t *soqa_urgmark_mp;
136} sock_quiesce_arg_t;
137typedef mblk_t *(*so_proto_quiesced_cb_t)(sock_upper_handle_t,
138 sock_quiesce_arg_t *, struct T_capability_ack *, struct sockaddr *,
139 socklen_t, struct sockaddr *, socklen_t, short);
Anders Persson41174432009-02-12 17:35:05 -0800140typedef int (*so_proto_fallback_func_t)(sock_lower_handle_t, queue_t *,
Anders Persson3e95bd42010-06-17 17:22:09 -0700141 boolean_t, so_proto_quiesced_cb_t, sock_quiesce_arg_t *);
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800142
143/*
Darren Reed0a0e9772009-09-24 07:28:12 -0700144 * These functions return EOPNOTSUPP and are intended for the sockfs
145 * developer that doesn't wish to supply stubs for every function themselves.
146 */
147extern int sock_accept_notsupp(sock_lower_handle_t, sock_lower_handle_t,
148 sock_upper_handle_t, cred_t *);
149extern int sock_bind_notsupp(sock_lower_handle_t, struct sockaddr *,
150 socklen_t, cred_t *);
151extern int sock_listen_notsupp(sock_lower_handle_t, int, cred_t *);
152extern int sock_connect_notsupp(sock_lower_handle_t,
153 const struct sockaddr *, socklen_t, sock_connid_t *, cred_t *);
154extern int sock_getpeername_notsupp(sock_lower_handle_t, struct sockaddr *,
155 socklen_t *, cred_t *);
156extern int sock_getsockname_notsupp(sock_lower_handle_t, struct sockaddr *,
157 socklen_t *, cred_t *);
158extern int sock_getsockopt_notsupp(sock_lower_handle_t, int, int, void *,
159 socklen_t *, cred_t *);
160extern int sock_setsockopt_notsupp(sock_lower_handle_t, int, int,
161 const void *, socklen_t, cred_t *);
162extern int sock_send_notsupp(sock_lower_handle_t, mblk_t *,
163 struct nmsghdr *, cred_t *);
164extern int sock_send_uio_notsupp(sock_lower_handle_t, uio_t *,
165 struct nmsghdr *, cred_t *);
166extern int sock_recv_uio_notsupp(sock_lower_handle_t, uio_t *,
167 struct nmsghdr *, cred_t *);
168extern short sock_poll_notsupp(sock_lower_handle_t, short, int, cred_t *);
169extern int sock_shutdown_notsupp(sock_lower_handle_t, int, cred_t *);
170extern void sock_clr_flowctrl_notsupp(sock_lower_handle_t);
171extern int sock_ioctl_notsupp(sock_lower_handle_t, int, intptr_t, int,
172 int32_t *, cred_t *);
173extern int sock_close_notsupp(sock_lower_handle_t, int, cred_t *);
174
175/*
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800176 * Upcalls and related information
177 */
178
179/*
180 * su_opctl() actions
181 */
182typedef enum sock_opctl_action {
183 SOCK_OPCTL_ENAB_ACCEPT = 0,
184 SOCK_OPCTL_SHUT_SEND,
185 SOCK_OPCTL_SHUT_RECV
186} sock_opctl_action_t;
187
188struct sock_upcalls_s {
189 sock_upper_handle_t (*su_newconn)(sock_upper_handle_t,
190 sock_lower_handle_t, sock_downcalls_t *, cred_t *, pid_t,
191 sock_upcalls_t **);
192 void (*su_connected)(sock_upper_handle_t, sock_connid_t, cred_t *,
193 pid_t);
194 int (*su_disconnected)(sock_upper_handle_t, sock_connid_t, int);
195 void (*su_opctl)(sock_upper_handle_t, sock_opctl_action_t,
196 uintptr_t);
197 ssize_t (*su_recv)(sock_upper_handle_t, mblk_t *, size_t, int,
198 int *, boolean_t *);
199 void (*su_set_proto_props)(sock_upper_handle_t,
200 struct sock_proto_props *);
201 void (*su_txq_full)(sock_upper_handle_t, boolean_t);
202 void (*su_signal_oob)(sock_upper_handle_t, ssize_t);
203 void (*su_zcopy_notify)(sock_upper_handle_t);
204 void (*su_set_error)(sock_upper_handle_t, int);
Anders Persson3e95bd42010-06-17 17:22:09 -0700205 void (*su_closed)(sock_upper_handle_t);
Andy Fiddaman78a2e112019-08-22 14:59:11 +0000206 vnode_t *(*su_get_vnode)(sock_upper_handle_t);
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800207};
208
209#define SOCK_UC_VERSION sizeof (sock_upcalls_t)
210#define SOCK_DC_VERSION sizeof (sock_downcalls_t)
211
212#define SOCKET_RECVHIWATER (48 * 1024)
213#define SOCKET_RECVLOWATER 1024
214
215#define SOCKET_NO_RCVTIMER 0
216#define SOCKET_TIMER_INTERVAL 50
217
218#endif /* _KERNEL */
219
220#ifdef __cplusplus
221}
222#endif
223
224#endif /* _SYS_SOCKET_PROTO_H_ */