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 /* 23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 24 * Copyright 2019 OmniOS Community Edition (OmniOSce) Association. 25 */ 26 27 #ifndef _SOCKCOMMON_H_ 28 #define _SOCKCOMMON_H_ 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #include <sys/filio.h> 35 #include <sys/socket_proto.h> 36 37 struct sonode; 38 39 extern kmem_cache_t *socket_cache; 40 41 /* 42 * Socket access functions 43 * 44 * The following functions should only be used by sockfs, and are common 45 * functions that can be used both by kernel sockets (i.e., no file 46 * descriptors should ever be expected, or created), and to implement 47 * the socket system calls. 48 */ 49 extern struct sonode *socket_create(int, int, int, char *, char *, int, int, 50 struct cred *, int *); 51 extern struct sonode *socket_newconn(struct sonode *, sock_lower_handle_t, 52 sock_downcalls_t *, int, int *); 53 extern int socket_bind(struct sonode *, struct sockaddr *, socklen_t, int, 54 struct cred *); 55 extern int socket_accept(struct sonode *, int, struct cred *, struct sonode **); 56 extern int socket_listen(struct sonode *, int, struct cred *); 57 extern int socket_connect(struct sonode *, struct sockaddr *, 58 socklen_t, int, int, struct cred *); 59 extern int socket_getpeername(struct sonode *, struct sockaddr *, socklen_t *, 60 boolean_t, struct cred *); 61 extern int socket_getsockname(struct sonode *, struct sockaddr *, socklen_t *, 62 struct cred *); 63 extern int socket_shutdown(struct sonode *, int, struct cred *); 64 extern int socket_getsockopt(struct sonode *, int, int, void *, socklen_t *, 65 int, struct cred *); 66 extern int socket_setsockopt(struct sonode *, int, int, const void *, 67 socklen_t, struct cred *); 68 extern int socket_recvmsg(struct sonode *, struct nmsghdr *, struct uio *, 69 struct cred *); 70 extern int socket_sendmsg(struct sonode *, struct nmsghdr *, struct uio *, 71 struct cred *); 72 extern int socket_sendmblk(struct sonode *, struct nmsghdr *, int, 73 struct cred *, mblk_t **); 74 extern int socket_ioctl(struct sonode *, int, intptr_t, int, struct cred *, 75 int32_t *); 76 extern int socket_poll(struct sonode *, short, int, short *, 77 struct pollhead **); 78 extern int socket_close(struct sonode *, int, struct cred *); 79 extern void socket_destroy(struct sonode *); 80 81 /* 82 * Cancel the socket push timer. 83 */ 84 #define SOCKET_TIMER_CANCEL(so) { \ 85 timeout_id_t tid; \ 86 \ 87 ASSERT(MUTEX_HELD(&(so)->so_lock)); \ 88 if ((so)->so_rcv_timer_tid != 0) { \ 89 tid = (so)->so_rcv_timer_tid; \ 90 (so)->so_rcv_timer_tid = 0; \ 91 mutex_exit(&(so)->so_lock); \ 92 \ 93 (void) untimeout(tid); \ 94 \ 95 mutex_enter(&(so)->so_lock); \ 96 } \ 97 } 98 99 #define SOCKET_TIMER_START(so) { \ 100 ASSERT(MUTEX_HELD(&(so)->so_lock)); \ 101 if ((so)->so_rcv_timer_interval != SOCKET_NO_RCVTIMER) { \ 102 (so)->so_rcv_timer_tid = timeout(so_timer_callback, \ 103 (so), MSEC_TO_TICK((so)->so_rcv_timer_interval)); \ 104 } \ 105 } 106 107 /* Common sonode ops not support */ 108 extern int so_listen_notsupp(struct sonode *, int, struct cred *); 109 extern int so_accept_notsupp(struct sonode *, int, struct cred *, 110 struct sonode **); 111 extern int so_getpeername_notsupp(struct sonode *, struct sockaddr *, 112 socklen_t *, boolean_t, struct cred *); 113 extern int so_shutdown_notsupp(struct sonode *, int, struct cred *); 114 extern int so_sendmblk_notsupp(struct sonode *, struct nmsghdr *, 115 int, struct cred *, mblk_t **); 116 117 /* Common sonode ops */ 118 extern int so_init(struct sonode *, struct sonode *, struct cred *, int); 119 extern int so_accept(struct sonode *, int, struct cred *, struct sonode **); 120 extern int so_bind(struct sonode *, struct sockaddr *, socklen_t, int, 121 struct cred *); 122 extern int so_listen(struct sonode *, int, struct cred *); 123 extern int so_connect(struct sonode *, struct sockaddr *, 124 socklen_t, int, int, struct cred *); 125 extern int so_getsockopt(struct sonode *, int, int, void *, 126 socklen_t *, int, struct cred *); 127 extern int so_setsockopt(struct sonode *, int, int, const void *, 128 socklen_t, struct cred *); 129 extern int so_getpeername(struct sonode *, struct sockaddr *, 130 socklen_t *, boolean_t, struct cred *); 131 extern int so_getsockname(struct sonode *, struct sockaddr *, 132 socklen_t *, struct cred *); 133 extern int so_ioctl(struct sonode *, int, intptr_t, int, struct cred *, 134 int32_t *); 135 extern int so_poll(struct sonode *, short, int, short *, 136 struct pollhead **); 137 extern int so_sendmsg(struct sonode *, struct nmsghdr *, struct uio *, 138 struct cred *); 139 extern int so_sendmblk_impl(struct sonode *, struct nmsghdr *, int, 140 struct cred *, mblk_t **, struct sof_instance *, boolean_t); 141 extern int so_sendmblk(struct sonode *, struct nmsghdr *, int, 142 struct cred *, mblk_t **); 143 extern int so_recvmsg(struct sonode *, struct nmsghdr *, struct uio *, 144 struct cred *); 145 extern int so_shutdown(struct sonode *, int, struct cred *); 146 extern int so_close(struct sonode *, int, struct cred *); 147 148 extern int so_tpi_fallback(struct sonode *, struct cred *); 149 150 /* Common upcalls */ 151 extern sock_upper_handle_t so_newconn(sock_upper_handle_t, 152 sock_lower_handle_t, sock_downcalls_t *, struct cred *, pid_t, 153 sock_upcalls_t **); 154 extern void so_set_prop(sock_upper_handle_t, 155 struct sock_proto_props *); 156 extern ssize_t so_queue_msg(sock_upper_handle_t, mblk_t *, size_t, int, 157 int *, boolean_t *); 158 extern ssize_t so_queue_msg_impl(struct sonode *, mblk_t *, size_t, int, 159 int *, boolean_t *, struct sof_instance *); 160 extern void so_signal_oob(sock_upper_handle_t, ssize_t); 161 162 extern void so_connected(sock_upper_handle_t, sock_connid_t, struct cred *, 163 pid_t); 164 extern int so_disconnected(sock_upper_handle_t, sock_connid_t, int); 165 extern void so_txq_full(sock_upper_handle_t, boolean_t); 166 extern void so_opctl(sock_upper_handle_t, sock_opctl_action_t, uintptr_t); 167 extern vnode_t *so_get_vnode(sock_upper_handle_t); 168 169 /* Common misc. functions */ 170 171 /* accept queue */ 172 extern int so_acceptq_enqueue(struct sonode *, struct sonode *); 173 extern int so_acceptq_enqueue_locked(struct sonode *, struct sonode *); 174 extern int so_acceptq_dequeue(struct sonode *, boolean_t, 175 struct sonode **); 176 extern void so_acceptq_flush(struct sonode *, boolean_t); 177 178 /* connect */ 179 extern int so_wait_connected(struct sonode *, boolean_t, sock_connid_t); 180 181 /* send */ 182 extern int so_snd_wait_qnotfull(struct sonode *, boolean_t); 183 extern void so_snd_qfull(struct sonode *so); 184 extern void so_snd_qnotfull(struct sonode *so); 185 186 extern int socket_chgpgrp(struct sonode *, pid_t); 187 extern void socket_sendsig(struct sonode *, int); 188 extern int so_dequeue_msg(struct sonode *, mblk_t **, struct uio *, 189 rval_t *, int); 190 extern void so_enqueue_msg(struct sonode *, mblk_t *, size_t); 191 extern void so_process_new_message(struct sonode *, mblk_t *, mblk_t *); 192 extern boolean_t so_check_flow_control(struct sonode *); 193 194 extern mblk_t *socopyinuio(uio_t *, ssize_t, size_t, ssize_t, size_t, int *); 195 extern mblk_t *socopyoutuio(mblk_t *, struct uio *, ssize_t, int *); 196 197 extern boolean_t somsghasdata(mblk_t *); 198 extern void so_rcv_flush(struct sonode *); 199 extern int sorecvoob(struct sonode *, struct nmsghdr *, struct uio *, 200 int, boolean_t); 201 202 extern void so_timer_callback(void *); 203 204 extern struct sonode *socket_sonode_create(struct sockparams *, int, int, int, 205 int, int, int *, struct cred *); 206 207 extern void socket_sonode_destroy(struct sonode *); 208 extern int socket_init_common(struct sonode *, struct sonode *, int flags, 209 struct cred *); 210 extern int socket_getopt_common(struct sonode *, int, int, void *, socklen_t *, 211 int); 212 extern int socket_ioctl_common(struct sonode *, int, intptr_t, int, 213 struct cred *, int32_t *); 214 extern int socket_strioc_common(struct sonode *, int, intptr_t, int, 215 struct cred *, int32_t *); 216 217 extern int so_zcopy_wait(struct sonode *); 218 extern int so_get_mod_version(struct sockparams *); 219 220 /* Notification functions */ 221 extern void so_notify_connected(struct sonode *); 222 extern void so_notify_disconnecting(struct sonode *); 223 extern void so_notify_disconnected(struct sonode *, boolean_t, int); 224 extern void so_notify_writable(struct sonode *); 225 extern void so_notify_data(struct sonode *, size_t); 226 extern void so_notify_oobsig(struct sonode *); 227 extern void so_notify_oobdata(struct sonode *, boolean_t); 228 extern void so_notify_eof(struct sonode *); 229 extern void so_notify_newconn(struct sonode *); 230 extern void so_notify_shutdown(struct sonode *); 231 extern void so_notify_error(struct sonode *); 232 233 /* Common sonode functions */ 234 extern int sonode_constructor(void *, void *, int); 235 extern void sonode_destructor(void *, void *); 236 extern void sonode_init(struct sonode *, struct sockparams *, 237 int, int, int, sonodeops_t *); 238 extern void sonode_fini(struct sonode *); 239 240 /* 241 * Event flags to socket_sendsig(). 242 */ 243 #define SOCKETSIG_WRITE 0x1 244 #define SOCKETSIG_READ 0x2 245 #define SOCKETSIG_URG 0x4 246 247 extern sonodeops_t so_sonodeops; 248 extern sock_upcalls_t so_upcalls; 249 250 #ifdef __cplusplus 251 } 252 #endif 253 #endif /* _SOCKCOMMON_H_ */ 254