xref: /titanic_51/usr/src/uts/common/fs/sockfs/socktpi.h (revision a51287096c163d49f314be2853367563999e083c)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SOCKFS_SOCKTPI_H
28 #define	_SOCKFS_SOCKTPI_H
29 
30 #include <inet/kssl/ksslapi.h>
31 #include <sys/sodirect.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Internal representation used for addresses.
39  */
40 struct soaddr {
41 	struct sockaddr	*soa_sa;	/* Actual address */
42 	t_uscalar_t	soa_len;	/* Length in bytes for kmem_free */
43 	t_uscalar_t	soa_maxlen;	/* Allocated length */
44 };
45 /* Maximum size address for transports that have ADDR_size == 1 */
46 #define	SOA_DEFSIZE	128
47 
48 struct sonode;
49 
50 /*
51  * TPI Sockets
52  * ======================
53  *
54  * A TPI socket can be created by the TPI socket module, or as a
55  * result of fallback. In either case, the TPI related information is
56  * stored in a sotpi_info_t. Sockets that are TPI based from the
57  * beginning will use a sotpi_sonode_t, but fallback case the
58  * sotpi_info_t will be allocated when needed. However, the so_priv
59  * field in the sonode will always point to the sotpi_info_t, and the
60  * structure should only be accessed via so_priv. Use SOTOTPI().
61  *
62  * A TPI socket always corresponds to a VCHR stream representing the
63  * transport provider (e.g. /dev/tcp). This information is retrieved
64  * from the kernel socket configuration table and accessible via
65  * so_sockparams->sp_sdev_info.  sockfs uses this to perform
66  * VOP_ACCESS checks before allowing an open of the transport
67  * provider.
68  *
69  * AF_UNIX Sockets
70  * -------------------------
71  *
72  * When an AF_UNIX socket is bound to a pathname the sockfs creates a
73  * VSOCK vnode in the underlying file system. However, the vnodeops
74  * etc in this VNODE remain those of the underlying file system.
75  * Sockfs uses the v_stream pointer in the underlying file system
76  * VSOCK node to find the sonode bound to the pathname. The bound
77  * pathname vnode is accessed through sti_ux_vp.
78  *
79  * Out of Band Data Handling
80  * -------------------------
81  *
82  * The counts (sti_oobcnt and sti_oobsigcnt) track the number of
83  * urgent indicates that are (logically) queued on the stream head
84  * read queue. The urgent data is queued on the stream head
85  * as follows.
86  *
87  * In the normal case the SIGURG is not generated until
88  * the T_EXDATA_IND arrives at the stream head. However, transports
89  * that have an early indication that urgent data is pending
90  * (e.g. TCP receiving a "new" urgent pointer value) can send up
91  * an M_PCPROTO/SIGURG message to generate the signal early.
92  *
93  * The mark is indicated by either:
94  *  - a T_EXDATA_IND (with no M_DATA b_cont) with MSGMARK set.
95  *    When this message is consumed by sorecvmsg the socket layer
96  *    sets SS_RCVATMARK until data has been consumed past the mark.
97  *  - a message with MSGMARKNEXT set (indicating that the
98  *    first byte of the next message constitutes the mark). When
99  *    the last byte of the MSGMARKNEXT message is consumed in
100  *    the stream head the stream head sets STRATMARK. This flag
101  *    is cleared when at least one byte is read. (Note that
102  *    the MSGMARKNEXT messages can be of zero length when there
103  *    is no previous data to which the marknext can be attached.)
104  *
105  * While the T_EXDATA_IND method is the common case which is used
106  * with all TPI transports, the MSGMARKNEXT method is needed to
107  * indicate the mark when e.g. the TCP urgent byte has not been
108  * received yet but the TCP urgent pointer has made TCP generate
109  * the M_PCSIG/SIGURG.
110  *
111  * The signal (the M_PCSIG carrying the SIGURG) and the mark
112  * indication can not be delivered as a single message, since
113  * the signal should be delivered as high priority and any mark
114  * indication must flow with the data. This implies that immediately
115  * when the SIGURG has been delivered if the stream head queue is
116  * empty it is impossible to determine if this will be the position
117  * of the mark. This race condition is resolved by using MSGNOTMARKNEXT
118  * messages and the STRNOTATMARK flag in the stream head. The
119  * SIOCATMARK code calls the stream head to wait for either a
120  * non-empty queue or one of the STR*ATMARK flags being set.
121  * This implies that any transport that is sending M_PCSIG(SIGURG)
122  * should send the appropriate MSGNOTMARKNEXT message (which can be
123  * zero length) after sending an M_PCSIG to prevent SIOCATMARK
124  * from sleeping unnecessarily.
125  */
126 
127 #define	SOTPI_INFO_MAGIC	0x12345678
128 
129 /*
130  * Information used by TPI/STREAMS sockets
131  */
132 typedef struct sotpi_info {
133 	/*
134 	 * These fields are initialized once.
135 	 */
136 	uint32_t	sti_magic;	/* always set to SOTPI_INFO_MAGIC */
137 	dev_t		sti_dev;	/* device the sonode represents */
138 
139 	struct sockparams *sti_orig_sp;	/* in case of fallback; the orig sp */
140 
141 	kmutex_t	sti_plumb_lock;	/* serializes plumbs, and the related */
142 					/* so_pushcnt */
143 	short		sti_pushcnt;	/* Number of modules above "sockmod" */
144 
145 	kcondvar_t	sti_ack_cv;	/* wait for TPI acks */
146 
147 	uint8_t
148 		sti_laddr_valid : 1,	/* sti_laddr valid for user */
149 		sti_faddr_valid : 1,	/* sti_faddr valid for user */
150 		sti_faddr_noxlate : 1,	/* No xlation of faddr for AF_UNIX */
151 
152 		sti_direct : 1,		/* transport is directly below */
153 
154 		sti_pad_to_bit7 : 4;
155 
156 	mblk_t	*sti_ack_mp;		/* TPI ack received from below */
157 	mblk_t	*sti_unbind_mp;		/* Preallocated T_UNBIND_REQ message */
158 
159 	time_t  sti_atime;		/* time of last access */
160 	time_t  sti_mtime;		/* time of last modification */
161 	time_t  sti_ctime;		/* time of last attributes change */
162 
163 	ushort_t sti_delayed_error;	/* From T_uderror_ind */
164 	mblk_t	*sti_eaddr_mp;		/* for so_delayed_error */
165 					/* put here for delayed processing  */
166 
167 	mblk_t	*sti_conn_ind_head;	/* b_next list of T_CONN_IND */
168 	mblk_t	*sti_conn_ind_tail;
169 
170 	uint_t	sti_oobsigcnt;		/* Number of SIGURG generated */
171 	uint_t	sti_oobcnt;		/* Number of T_EXDATA_IND queued */
172 
173 	/* From T_info_ack */
174 	t_uscalar_t	sti_tsdu_size;
175 	t_uscalar_t	sti_etsdu_size;
176 	t_scalar_t	sti_addr_size;
177 	t_uscalar_t	sti_opt_size;
178 	t_uscalar_t	sti_tidu_size;
179 	t_scalar_t	sti_serv_type;
180 
181 	/* From T_capability_ack */
182 	t_uscalar_t	sti_acceptor_id;
183 
184 	/* Internal provider information */
185 	struct tpi_provinfo	*sti_provinfo;
186 
187 	/*
188 	 * The local and remote addresses have multiple purposes
189 	 * but one of the key reasons for their existence and careful
190 	 * tracking in sockfs is to support getsockname and getpeername
191 	 * when the transport does not handle the TI_GET*NAME ioctls
192 	 * and caching when it does (signalled by valid bits in so_state).
193 	 * When all transports support the new TPI (with T_ADDR_REQ)
194 	 * we can revisit this code.
195 	 *
196 	 * The other usage of sti_faddr is to keep the "connected to"
197 	 * address for datagram sockets.
198 	 *
199 	 * Finally, for AF_UNIX both local and remote addresses are used
200 	 * to record the sockaddr_un since we use a separate namespace
201 	 * in the loopback transport.
202 	 */
203 	struct soaddr sti_laddr;	/* Local address */
204 	struct soaddr sti_faddr;	/* Peer address */
205 #define	sti_laddr_sa		sti_laddr.soa_sa
206 #define	sti_faddr_sa		sti_faddr.soa_sa
207 #define	sti_laddr_len		sti_laddr.soa_len
208 #define	sti_faddr_len		sti_faddr.soa_len
209 #define	sti_laddr_maxlen	sti_laddr.soa_maxlen
210 #define	sti_faddr_maxlen	sti_faddr.soa_maxlen
211 
212 	/*
213 	 * For AF_UNIX sockets:
214 	 *
215 	 * sti_ux_laddr/faddr records the internal addresses used with the
216 	 * transport. sti_ux_vp and v_stream->sd_vnode form the
217 	 * cross-linkage between the underlying fs vnode corresponding
218 	 * to the bound sockaddr_un and the socket node.
219 	 */
220 	struct so_ux_addr sti_ux_laddr; /* laddr bound with the transport */
221 	struct so_ux_addr sti_ux_faddr; /* temporary peer address */
222 	struct vnode	*sti_ux_bound_vp; /* bound AF_UNIX file system vnode */
223 	struct sonode	*sti_next_so; 	/* next sonode on socklist	*/
224 	struct sonode	*sti_prev_so;	/* previous sonode on socklist	*/
225 	mblk_t	*sti_discon_ind_mp;	/* T_DISCON_IND received from below */
226 
227 	/*
228 	 * For NL7C sockets:
229 	 *
230 	 * sti_nl7c_flags	the NL7C state of URL processing.
231 	 *
232 	 * sti_nl7c_rcv_mp	mblk_t chain of already received data to be
233 	 *			passed up to the app after NL7C gives up on
234 	 *			a socket.
235 	 *
236 	 * sti_nl7c_rcv_rval	returned rval for last mblk_t from above.
237 	 *
238 	 * sti_nl7c_uri		the URI currently being processed.
239 	 *
240 	 * sti_nl7c_rtime	URI request gethrestime_sec().
241 	 *
242 	 * sti_nl7c_addr	pointer returned by nl7c_addr_lookup().
243 	 */
244 	uint64_t	sti_nl7c_flags;
245 	mblk_t		*sti_nl7c_rcv_mp;
246 	int64_t		sti_nl7c_rcv_rval;
247 	void		*sti_nl7c_uri;
248 	time_t		sti_nl7c_rtime;
249 	void		*sti_nl7c_addr;
250 
251 	/* For sockets acting as an in-kernel SSL proxy */
252 	kssl_endpt_type_t	sti_kssl_type;	/* is proxy/is proxied/none */
253 	kssl_ent_t		sti_kssl_ent;	/* SSL config entry */
254 	kssl_ctx_t		sti_kssl_ctx;	/* SSL session context */
255 } sotpi_info_t;
256 
257 struct T_capability_ack;
258 
259 extern sonodeops_t sotpi_sonodeops;
260 
261 extern int	socktpi_init(void);
262 extern queue_t	*sotpi_convert_sonode(struct sonode *, struct sockparams *,
263 		    boolean_t *, struct cred *);
264 extern void	sotpi_update_state(struct sonode *, struct T_capability_ack *,
265 		    struct sockaddr *, socklen_t, struct sockaddr *, socklen_t,
266 		    short);
267 
268 extern sotpi_info_t 	*sotpi_sototpi(struct sonode *);
269 #ifdef DEBUG
270 #define	SOTOTPI(so)	(sotpi_sototpi(so))
271 #else
272 #define	SOTOTPI(so)	((sotpi_info_t *)(so)->so_priv)
273 #endif
274 
275 /* for consumers outside sockfs */
276 #define	_SOTOTPI(so)	((sotpi_info_t *)(so)->so_priv)
277 
278 #ifdef	__cplusplus
279 }
280 #endif
281 
282 #endif /* _SOCKFS_SOCKTPI_H */
283