xref: /onnv-gate/usr/src/uts/common/sys/socket_proto.h (revision 8963:f58d8e280203)
18348SEric.Yu@Sun.COM /*
28348SEric.Yu@Sun.COM  * CDDL HEADER START
38348SEric.Yu@Sun.COM  *
48348SEric.Yu@Sun.COM  * The contents of this file are subject to the terms of the
58348SEric.Yu@Sun.COM  * Common Development and Distribution License (the "License").
68348SEric.Yu@Sun.COM  * You may not use this file except in compliance with the License.
78348SEric.Yu@Sun.COM  *
88348SEric.Yu@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98348SEric.Yu@Sun.COM  * or http://www.opensolaris.org/os/licensing.
108348SEric.Yu@Sun.COM  * See the License for the specific language governing permissions
118348SEric.Yu@Sun.COM  * and limitations under the License.
128348SEric.Yu@Sun.COM  *
138348SEric.Yu@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
148348SEric.Yu@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158348SEric.Yu@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
168348SEric.Yu@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
178348SEric.Yu@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
188348SEric.Yu@Sun.COM  *
198348SEric.Yu@Sun.COM  * CDDL HEADER END
208348SEric.Yu@Sun.COM  */
218348SEric.Yu@Sun.COM /*
22*8963SAnders.Persson@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
238348SEric.Yu@Sun.COM  * Use is subject to license terms.
248348SEric.Yu@Sun.COM  */
258348SEric.Yu@Sun.COM 
268348SEric.Yu@Sun.COM #ifndef _SYS_SOCKET_PROTO_H_
278348SEric.Yu@Sun.COM #define	_SYS_SOCKET_PROTO_H_
288348SEric.Yu@Sun.COM 
298348SEric.Yu@Sun.COM #ifdef	__cplusplus
308348SEric.Yu@Sun.COM extern "C" {
318348SEric.Yu@Sun.COM #endif
328348SEric.Yu@Sun.COM 
338348SEric.Yu@Sun.COM #include <sys/socket.h>
348348SEric.Yu@Sun.COM 
358348SEric.Yu@Sun.COM /*
368348SEric.Yu@Sun.COM  * Generation count
378348SEric.Yu@Sun.COM  */
388348SEric.Yu@Sun.COM typedef uint64_t sock_connid_t;
398348SEric.Yu@Sun.COM 
408348SEric.Yu@Sun.COM #define	SOCK_CONNID_INIT(id) {	\
418348SEric.Yu@Sun.COM 	(id) = 0;		\
428348SEric.Yu@Sun.COM }
438348SEric.Yu@Sun.COM #define	SOCK_CONNID_BUMP(id)		(++(id))
448348SEric.Yu@Sun.COM #define	SOCK_CONNID_LT(id1, id2)	((int64_t)((id1)-(id2)) < 0)
458348SEric.Yu@Sun.COM 
468348SEric.Yu@Sun.COM /* Socket protocol properties */
478348SEric.Yu@Sun.COM struct sock_proto_props {
488348SEric.Yu@Sun.COM 	uint_t sopp_flags;		/* options to set */
498348SEric.Yu@Sun.COM 	ushort_t sopp_wroff;		/* write offset */
508348SEric.Yu@Sun.COM 	ssize_t sopp_txhiwat;		/* tx hi water mark */
518348SEric.Yu@Sun.COM 	ssize_t sopp_txlowat;		/* tx lo water mark */
528348SEric.Yu@Sun.COM 	ssize_t	sopp_rxhiwat;		/* recv high water mark */
538348SEric.Yu@Sun.COM 	ssize_t	sopp_rxlowat;		/* recv low water mark */
548348SEric.Yu@Sun.COM 	ssize_t sopp_maxblk;		/* maximum message block size */
558348SEric.Yu@Sun.COM 	ssize_t sopp_maxpsz;		/* maximum packet size */
568348SEric.Yu@Sun.COM 	ssize_t sopp_minpsz;		/* minimum packet size */
578348SEric.Yu@Sun.COM 	ushort_t sopp_tail;		/* space available at the end */
588348SEric.Yu@Sun.COM 	uint_t	sopp_zcopyflag;		/* zero copy flag */
598348SEric.Yu@Sun.COM 	boolean_t sopp_oobinline;	/* OOB inline */
608348SEric.Yu@Sun.COM 	uint_t sopp_rcvtimer;		/* delayed recv notification (time) */
618348SEric.Yu@Sun.COM 	uint32_t sopp_rcvthresh;	/* delayed recv notification (bytes) */
628348SEric.Yu@Sun.COM 	socklen_t sopp_maxaddrlen;	/* maximum size of protocol address */
638348SEric.Yu@Sun.COM };
648348SEric.Yu@Sun.COM 
658348SEric.Yu@Sun.COM /* flags to determine which socket options are set */
668348SEric.Yu@Sun.COM #define	SOCKOPT_WROFF		0x0001	/* set write offset */
678348SEric.Yu@Sun.COM #define	SOCKOPT_RCVHIWAT	0x0002	/* set read side high water */
688348SEric.Yu@Sun.COM #define	SOCKOPT_RCVLOWAT	0x0004	/* set read side high water */
698348SEric.Yu@Sun.COM #define	SOCKOPT_MAXBLK		0x0008	/* set maximum message block size */
708348SEric.Yu@Sun.COM #define	SOCKOPT_TAIL		0x0010	/* set the extra allocated space */
718348SEric.Yu@Sun.COM #define	SOCKOPT_ZCOPY		0x0020	/* set/unset zero copy for sendfile */
728348SEric.Yu@Sun.COM #define	SOCKOPT_MAXPSZ		0x0040	/* set maxpsz for protocols */
738348SEric.Yu@Sun.COM #define	SOCKOPT_OOBINLINE	0x0080	/* set oob inline processing */
748348SEric.Yu@Sun.COM #define	SOCKOPT_RCVTIMER	0x0100
758348SEric.Yu@Sun.COM #define	SOCKOPT_RCVTHRESH	0x0200
768348SEric.Yu@Sun.COM #define	SOCKOPT_MAXADDRLEN	0x0400	/* set max address length */
778348SEric.Yu@Sun.COM #define	SOCKOPT_MINPSZ		0x0800	/* set minpsz for protocols */
788348SEric.Yu@Sun.COM 
798348SEric.Yu@Sun.COM #define	IS_SO_OOB_INLINE(so)	((so)->so_proto_props.sopp_oobinline)
808348SEric.Yu@Sun.COM 
818348SEric.Yu@Sun.COM #ifdef _KERNEL
828348SEric.Yu@Sun.COM 
838348SEric.Yu@Sun.COM struct T_capability_ack;
848348SEric.Yu@Sun.COM 
858348SEric.Yu@Sun.COM typedef struct sock_upcalls_s sock_upcalls_t;
868348SEric.Yu@Sun.COM typedef struct sock_downcalls_s sock_downcalls_t;
878348SEric.Yu@Sun.COM 
888348SEric.Yu@Sun.COM /*
898348SEric.Yu@Sun.COM  * Upcall and downcall handle for sockfs and transport layer.
908348SEric.Yu@Sun.COM  */
918348SEric.Yu@Sun.COM typedef struct __sock_upper_handle *sock_upper_handle_t;
928348SEric.Yu@Sun.COM typedef struct __sock_lower_handle *sock_lower_handle_t;
938348SEric.Yu@Sun.COM 
948348SEric.Yu@Sun.COM struct sock_downcalls_s {
958348SEric.Yu@Sun.COM 	void	(*sd_activate)(sock_lower_handle_t, sock_upper_handle_t,
968348SEric.Yu@Sun.COM 		    sock_upcalls_t *, int, cred_t *);
978348SEric.Yu@Sun.COM 	int	(*sd_accept)(sock_lower_handle_t, sock_lower_handle_t,
988348SEric.Yu@Sun.COM 		    sock_upper_handle_t, cred_t *);
998348SEric.Yu@Sun.COM 	int	(*sd_bind)(sock_lower_handle_t, struct sockaddr *, socklen_t,
1008348SEric.Yu@Sun.COM 		    cred_t *);
1018348SEric.Yu@Sun.COM 	int	(*sd_listen)(sock_lower_handle_t, int, cred_t *);
1028348SEric.Yu@Sun.COM 	int	(*sd_connect)(sock_lower_handle_t, const struct sockaddr *,
1038348SEric.Yu@Sun.COM 		    socklen_t, sock_connid_t *, cred_t *);
1048348SEric.Yu@Sun.COM 	int	(*sd_getpeername)(sock_lower_handle_t, struct sockaddr *,
1058348SEric.Yu@Sun.COM 		    socklen_t *, cred_t *);
1068348SEric.Yu@Sun.COM 	int	(*sd_getsockname)(sock_lower_handle_t, struct sockaddr *,
1078348SEric.Yu@Sun.COM 		    socklen_t *, cred_t *);
1088348SEric.Yu@Sun.COM 	int	(*sd_getsockopt)(sock_lower_handle_t, int, int, void *,
1098348SEric.Yu@Sun.COM 		    socklen_t *, cred_t *);
1108348SEric.Yu@Sun.COM 	int	(*sd_setsockopt)(sock_lower_handle_t, int, int, const void *,
1118348SEric.Yu@Sun.COM 		    socklen_t, cred_t *);
1128348SEric.Yu@Sun.COM 	int	(*sd_send)(sock_lower_handle_t, mblk_t *, struct nmsghdr *,
1138348SEric.Yu@Sun.COM 		    cred_t *);
1148348SEric.Yu@Sun.COM 	int	(*sd_send_uio)(sock_lower_handle_t, uio_t *, struct nmsghdr *,
1158348SEric.Yu@Sun.COM 		    cred_t *);
1168348SEric.Yu@Sun.COM 	int	(*sd_recv_uio)(sock_lower_handle_t, uio_t *, struct nmsghdr *,
1178348SEric.Yu@Sun.COM 		    cred_t *);
1188348SEric.Yu@Sun.COM 	short	(*sd_poll)(sock_lower_handle_t, short, int, cred_t *);
1198348SEric.Yu@Sun.COM 	int	(*sd_shutdown)(sock_lower_handle_t, int, cred_t *);
1208348SEric.Yu@Sun.COM 	void	(*sd_clr_flowctrl)(sock_lower_handle_t);
1218348SEric.Yu@Sun.COM 	int	(*sd_ioctl)(sock_lower_handle_t, int, intptr_t, int,
1228348SEric.Yu@Sun.COM 		    int32_t *, cred_t *);
1238348SEric.Yu@Sun.COM 	int	(*sd_close)(sock_lower_handle_t, int, cred_t *);
1248348SEric.Yu@Sun.COM };
1258348SEric.Yu@Sun.COM 
1268348SEric.Yu@Sun.COM typedef sock_lower_handle_t (*so_proto_create_func_t)(int, int, int,
1278348SEric.Yu@Sun.COM     sock_downcalls_t **, uint_t *, int *, int, cred_t *);
1288348SEric.Yu@Sun.COM 
1298348SEric.Yu@Sun.COM typedef void (*so_proto_quiesced_cb_t)(sock_upper_handle_t, queue_t *,
1308348SEric.Yu@Sun.COM     struct T_capability_ack *, struct sockaddr *, socklen_t,
1318348SEric.Yu@Sun.COM     struct sockaddr *, socklen_t, short);
132*8963SAnders.Persson@Sun.COM typedef int (*so_proto_fallback_func_t)(sock_lower_handle_t, queue_t *,
1338348SEric.Yu@Sun.COM     boolean_t, so_proto_quiesced_cb_t);
1348348SEric.Yu@Sun.COM 
1358348SEric.Yu@Sun.COM /*
1368348SEric.Yu@Sun.COM  * Upcalls and related information
1378348SEric.Yu@Sun.COM  */
1388348SEric.Yu@Sun.COM 
1398348SEric.Yu@Sun.COM /*
1408348SEric.Yu@Sun.COM  * su_opctl() actions
1418348SEric.Yu@Sun.COM  */
1428348SEric.Yu@Sun.COM typedef enum sock_opctl_action {
1438348SEric.Yu@Sun.COM 	SOCK_OPCTL_ENAB_ACCEPT = 0,
1448348SEric.Yu@Sun.COM 	SOCK_OPCTL_SHUT_SEND,
1458348SEric.Yu@Sun.COM 	SOCK_OPCTL_SHUT_RECV
1468348SEric.Yu@Sun.COM } sock_opctl_action_t;
1478348SEric.Yu@Sun.COM 
1488348SEric.Yu@Sun.COM struct sock_upcalls_s {
1498348SEric.Yu@Sun.COM 	sock_upper_handle_t (*su_newconn)(sock_upper_handle_t,
1508348SEric.Yu@Sun.COM 	    sock_lower_handle_t, sock_downcalls_t *, cred_t *, pid_t,
1518348SEric.Yu@Sun.COM 	    sock_upcalls_t **);
1528348SEric.Yu@Sun.COM 	void	(*su_connected)(sock_upper_handle_t, sock_connid_t, cred_t *,
1538348SEric.Yu@Sun.COM 	    pid_t);
1548348SEric.Yu@Sun.COM 	int	(*su_disconnected)(sock_upper_handle_t, sock_connid_t, int);
1558348SEric.Yu@Sun.COM 	void	(*su_opctl)(sock_upper_handle_t, sock_opctl_action_t,
1568348SEric.Yu@Sun.COM 	    uintptr_t);
1578348SEric.Yu@Sun.COM 	ssize_t	(*su_recv)(sock_upper_handle_t, mblk_t *, size_t, int,
1588348SEric.Yu@Sun.COM 		    int *, boolean_t *);
1598348SEric.Yu@Sun.COM 	void	(*su_set_proto_props)(sock_upper_handle_t,
1608348SEric.Yu@Sun.COM 		    struct sock_proto_props *);
1618348SEric.Yu@Sun.COM 	void	(*su_txq_full)(sock_upper_handle_t, boolean_t);
1628348SEric.Yu@Sun.COM 	void	(*su_signal_oob)(sock_upper_handle_t, ssize_t);
1638348SEric.Yu@Sun.COM 	void	(*su_zcopy_notify)(sock_upper_handle_t);
1648348SEric.Yu@Sun.COM 	void	(*su_set_error)(sock_upper_handle_t, int);
1658348SEric.Yu@Sun.COM };
1668348SEric.Yu@Sun.COM 
1678348SEric.Yu@Sun.COM #define	SOCK_UC_VERSION		sizeof (sock_upcalls_t)
1688348SEric.Yu@Sun.COM #define	SOCK_DC_VERSION		sizeof (sock_downcalls_t)
1698348SEric.Yu@Sun.COM 
1708348SEric.Yu@Sun.COM #define	SOCKET_RECVHIWATER	(48 * 1024)
1718348SEric.Yu@Sun.COM #define	SOCKET_RECVLOWATER	1024
1728348SEric.Yu@Sun.COM 
1738348SEric.Yu@Sun.COM #define	SOCKET_NO_RCVTIMER	0
1748348SEric.Yu@Sun.COM #define	SOCKET_TIMER_INTERVAL	50
1758348SEric.Yu@Sun.COM 
1768348SEric.Yu@Sun.COM #endif /* _KERNEL */
1778348SEric.Yu@Sun.COM 
1788348SEric.Yu@Sun.COM #ifdef	__cplusplus
1798348SEric.Yu@Sun.COM }
1808348SEric.Yu@Sun.COM #endif
1818348SEric.Yu@Sun.COM 
1828348SEric.Yu@Sun.COM #endif /* _SYS_SOCKET_PROTO_H_ */
183