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) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2015 Joyent, Inc.
25 */
26
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39 /*
40 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
41 */
42
43 #ifndef _SYS_SOCKETVAR_H
44 #define _SYS_SOCKETVAR_H
86 */
87 struct so_ux_addr {
88 void *soua_vp; /* vnode pointer or assigned by tl */
89 uint_t soua_magic; /* See below */
90 };
91
92 #define SOU_MAGIC_EXPLICIT 0x75787670 /* "uxvp" */
93 #define SOU_MAGIC_IMPLICIT 0x616e6f6e /* "anon" */
94
95 struct sockaddr_ux {
96 sa_family_t sou_family; /* AF_UNIX */
97 struct so_ux_addr sou_addr;
98 };
99
100 #if defined(_KERNEL) || defined(_KMEMUSER)
101
102 #include <sys/socket_proto.h>
103
104 typedef struct sonodeops sonodeops_t;
105 typedef struct sonode sonode_t;
106 typedef boolean_t (*so_krecv_f)(sonode_t *, mblk_t *, size_t, int, void *);
107
108 struct sodirect_s;
109
110 /*
111 * The sonode represents a socket. A sonode never exist in the file system
112 * name space and can not be opened using open() - only the socket, socketpair
113 * and accept calls create sonodes.
114 *
115 * The locking of sockfs uses the so_lock mutex plus the SOLOCKED and
116 * SOREADLOCKED flags in so_flag. The mutex protects all the state in the
117 * sonode. It is expected that the underlying transport protocol serializes
118 * socket operations, so sockfs will not normally not single-thread
119 * operations. However, certain sockets, including TPI based ones, can only
120 * handle one control operation at a time. The SOLOCKED flag is used to
121 * single-thread operations from sockfs users to prevent e.g. multiple bind()
122 * calls to operate on the same sonode concurrently. The SOREADLOCKED flag is
123 * used to ensure that only one thread sleeps in kstrgetmsg for a given
124 * sonode. This is needed to ensure atomic operation for things like
125 * MSG_WAITALL.
126 *
229
230 struct sock_proto_props so_proto_props; /* protocol settings */
231 boolean_t so_flowctrld; /* Flow controlled */
232 uint_t so_copyflag; /* Copy related flag */
233 kcondvar_t so_copy_cv; /* Copy cond variable */
234
235 /* kernel sockets */
236 ksocket_callbacks_t so_ksock_callbacks;
237 void *so_ksock_cb_arg; /* callback argument */
238 kcondvar_t so_closing_cv;
239
240 /* != NULL for sodirect enabled socket */
241 struct sodirect_s *so_direct;
242
243 /* socket filters */
244 uint_t so_filter_active; /* # of active fil */
245 uint_t so_filter_tx; /* pending tx ops */
246 struct sof_instance *so_filter_top; /* top of stack */
247 struct sof_instance *so_filter_bottom; /* bottom of stack */
248 clock_t so_filter_defertime; /* time when deferred */
249
250 /* Kernel direct receive callbacks */
251 so_krecv_f so_krecv_cb; /* recv callback */
252 void *so_krecv_arg; /* recv cb arg */
253 };
254
255 #define SO_HAVE_DATA(so) \
256 /* \
257 * For the (tid == 0) case we must check so_rcv_{q_,}head \
258 * rather than (so_rcv_queued > 0), since the latter does not \
259 * take into account mblks with only control/name information. \
260 */ \
261 ((so)->so_rcv_timer_tid == 0 && ((so)->so_rcv_head != NULL || \
262 (so)->so_rcv_q_head != NULL)) || \
263 ((so)->so_state & SS_CANTRCVMORE)
264
265 /*
266 * Events handled by the protocol (in case sd_poll is set)
267 */
268 #define SO_PROTO_POLLEV (POLLIN|POLLRDNORM|POLLRDBAND)
269
270
271 #endif /* _KERNEL || _KMEMUSER */
272
956 extern int soaccept(struct sonode *, int, struct sonode **);
957 extern int sobind(struct sonode *, struct sockaddr *, socklen_t,
958 int, int);
959 extern int solisten(struct sonode *, int);
960 extern int soconnect(struct sonode *, struct sockaddr *, socklen_t,
961 int, int);
962 extern int sorecvmsg(struct sonode *, struct nmsghdr *, struct uio *);
963 extern int sosendmsg(struct sonode *, struct nmsghdr *, struct uio *);
964 extern int soshutdown(struct sonode *, int);
965 extern int sogetsockopt(struct sonode *, int, int, void *, socklen_t *,
966 int);
967 extern int sosetsockopt(struct sonode *, int, int, const void *,
968 t_uscalar_t);
969
970 extern struct sonode *socreate(struct sockparams *, int, int, int, int,
971 int *);
972
973 extern int so_copyin(const void *, void *, size_t, int);
974 extern int so_copyout(const void *, void *, size_t, int);
975
976 /*
977 * Functions to manipulate the use of direct receive callbacks. This should not
978 * be used outside of sockfs and ksocket. These are generally considered a use
979 * once interface for a socket and will cause all outstanding data on the socket
980 * to be flushed.
981 */
982 extern int so_krecv_set(sonode_t *, so_krecv_f, void *);
983 extern void so_krecv_unblock(sonode_t *);
984
985 #endif
986
987 /*
988 * Internal structure for obtaining sonode information from the socklist.
989 * These types match those corresponding in the sonode structure.
990 * This is not a published interface, and may change at any time.
991 */
992 struct sockinfo {
993 uint_t si_size; /* real length of this struct */
994 short si_family;
995 short si_type;
996 ushort_t si_flag;
997 uint_t si_state;
998 uint_t si_ux_laddr_sou_magic;
999 uint_t si_ux_faddr_sou_magic;
1000 t_scalar_t si_serv_type;
1001 t_uscalar_t si_laddr_soa_len;
1002 t_uscalar_t si_faddr_soa_len;
1003 uint16_t si_laddr_family;
1004 uint16_t si_faddr_family;
|
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) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29 /*
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
32 * All Rights Reserved
33 *
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
36 * contributors.
37 */
38 /*
39 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
40 */
41
42 #ifndef _SYS_SOCKETVAR_H
43 #define _SYS_SOCKETVAR_H
85 */
86 struct so_ux_addr {
87 void *soua_vp; /* vnode pointer or assigned by tl */
88 uint_t soua_magic; /* See below */
89 };
90
91 #define SOU_MAGIC_EXPLICIT 0x75787670 /* "uxvp" */
92 #define SOU_MAGIC_IMPLICIT 0x616e6f6e /* "anon" */
93
94 struct sockaddr_ux {
95 sa_family_t sou_family; /* AF_UNIX */
96 struct so_ux_addr sou_addr;
97 };
98
99 #if defined(_KERNEL) || defined(_KMEMUSER)
100
101 #include <sys/socket_proto.h>
102
103 typedef struct sonodeops sonodeops_t;
104 typedef struct sonode sonode_t;
105
106 struct sodirect_s;
107
108 /*
109 * The sonode represents a socket. A sonode never exist in the file system
110 * name space and can not be opened using open() - only the socket, socketpair
111 * and accept calls create sonodes.
112 *
113 * The locking of sockfs uses the so_lock mutex plus the SOLOCKED and
114 * SOREADLOCKED flags in so_flag. The mutex protects all the state in the
115 * sonode. It is expected that the underlying transport protocol serializes
116 * socket operations, so sockfs will not normally not single-thread
117 * operations. However, certain sockets, including TPI based ones, can only
118 * handle one control operation at a time. The SOLOCKED flag is used to
119 * single-thread operations from sockfs users to prevent e.g. multiple bind()
120 * calls to operate on the same sonode concurrently. The SOREADLOCKED flag is
121 * used to ensure that only one thread sleeps in kstrgetmsg for a given
122 * sonode. This is needed to ensure atomic operation for things like
123 * MSG_WAITALL.
124 *
227
228 struct sock_proto_props so_proto_props; /* protocol settings */
229 boolean_t so_flowctrld; /* Flow controlled */
230 uint_t so_copyflag; /* Copy related flag */
231 kcondvar_t so_copy_cv; /* Copy cond variable */
232
233 /* kernel sockets */
234 ksocket_callbacks_t so_ksock_callbacks;
235 void *so_ksock_cb_arg; /* callback argument */
236 kcondvar_t so_closing_cv;
237
238 /* != NULL for sodirect enabled socket */
239 struct sodirect_s *so_direct;
240
241 /* socket filters */
242 uint_t so_filter_active; /* # of active fil */
243 uint_t so_filter_tx; /* pending tx ops */
244 struct sof_instance *so_filter_top; /* top of stack */
245 struct sof_instance *so_filter_bottom; /* bottom of stack */
246 clock_t so_filter_defertime; /* time when deferred */
247 };
248
249 #define SO_HAVE_DATA(so) \
250 /* \
251 * For the (tid == 0) case we must check so_rcv_{q_,}head \
252 * rather than (so_rcv_queued > 0), since the latter does not \
253 * take into account mblks with only control/name information. \
254 */ \
255 ((so)->so_rcv_timer_tid == 0 && ((so)->so_rcv_head != NULL || \
256 (so)->so_rcv_q_head != NULL)) || \
257 ((so)->so_state & SS_CANTRCVMORE)
258
259 /*
260 * Events handled by the protocol (in case sd_poll is set)
261 */
262 #define SO_PROTO_POLLEV (POLLIN|POLLRDNORM|POLLRDBAND)
263
264
265 #endif /* _KERNEL || _KMEMUSER */
266
950 extern int soaccept(struct sonode *, int, struct sonode **);
951 extern int sobind(struct sonode *, struct sockaddr *, socklen_t,
952 int, int);
953 extern int solisten(struct sonode *, int);
954 extern int soconnect(struct sonode *, struct sockaddr *, socklen_t,
955 int, int);
956 extern int sorecvmsg(struct sonode *, struct nmsghdr *, struct uio *);
957 extern int sosendmsg(struct sonode *, struct nmsghdr *, struct uio *);
958 extern int soshutdown(struct sonode *, int);
959 extern int sogetsockopt(struct sonode *, int, int, void *, socklen_t *,
960 int);
961 extern int sosetsockopt(struct sonode *, int, int, const void *,
962 t_uscalar_t);
963
964 extern struct sonode *socreate(struct sockparams *, int, int, int, int,
965 int *);
966
967 extern int so_copyin(const void *, void *, size_t, int);
968 extern int so_copyout(const void *, void *, size_t, int);
969
970 #endif
971
972 /*
973 * Internal structure for obtaining sonode information from the socklist.
974 * These types match those corresponding in the sonode structure.
975 * This is not a published interface, and may change at any time.
976 */
977 struct sockinfo {
978 uint_t si_size; /* real length of this struct */
979 short si_family;
980 short si_type;
981 ushort_t si_flag;
982 uint_t si_state;
983 uint_t si_ux_laddr_sou_magic;
984 uint_t si_ux_faddr_sou_magic;
985 t_scalar_t si_serv_type;
986 t_uscalar_t si_laddr_soa_len;
987 t_uscalar_t si_faddr_soa_len;
988 uint16_t si_laddr_family;
989 uint16_t si_faddr_family;
|