--- /dev/null	2012-07-09 14:38:13.000000000 +0000
+++ new/usr/src/uts/common/inet/dccp/dccp_impl.h	2012-07-09 14:38:13.151872024 +0000
@@ -0,0 +1,379 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012 David Hoeppner. All rights reserved.
+ */
+
+#ifndef	_INET_DCCP_IMPL_H
+#define	_INET_DCCP_IMPL_H
+
+#include <sys/int_types.h>
+#include <sys/netstack.h>
+#include <sys/socket.h>
+#include <sys/socket_proto.h>
+
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <netinet/dccp.h>
+
+#include <inet/common.h>
+#include <inet/ip.h>
+#include <inet/ip6.h>
+#include <inet/optcom.h>
+#include <inet/tunables.h>
+
+#include "dccp_stack.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#ifdef	_KERNEL
+
+#define	DCCP_MOD_ID		5999 /* XXX */
+
+extern struct qinit	dccp_sock_winit;
+extern struct qinit	dccp_winit;
+
+extern sock_downcalls_t	sock_dccp_downcalls;
+
+#define	DCCP_XMIT_LOWATER	(4 * 1024)
+#define	DCCP_XMIT_HIWATER	49152
+#define	DCCP_RECV_LOWATER	(2 * 1024)
+#define	DCCP_RECV_HIWATER	128000
+
+#define	TIDUSZ	4096	/* transport interface data unit size */
+
+/*
+ * Bind hash array size and hash function.
+ */
+#define	DCCP_BIND_FANOUT_SIZE		128
+#define	DCCP_BIND_HASH(lport, size)	((ntohs((uint16_t)lport)) & (size - 1))
+
+/*
+ * Was this tcp created via socket() interface?
+ */
+#define	DCCP_IS_SOCKET(dccp)	((dccp)->dccp_issocket)
+
+#define	DCCP_HDR_LENGTH(dccph)		(((dccph_t *)dccph)->dh_offset * 4) /* XXX >> 2 */
+#define	DCCP_MAX_HDR_LENGTH		1020
+#define	DCCP_MIN_HEADER_LENGTH		12
+
+/* Packet types (RFC 4340, Section 5.1.) */
+#define	DCCP_PKT_REQUEST	0
+#define	DCCP_PKT_RESPONSE	1
+#define	DCCP_PKT_DATA		2
+#define	DCCP_PKT_ACK		3
+#define	DCCP_PKT_DATAACK	4
+#define	DCCP_PKT_CLOSEREQ	5
+#define	DCCP_PKT_CLOSE		6
+#define	DCCP_PKT_RESET		7
+#define	DCCP_PKT_SYNC		8
+#define	DCCP_PKT_SYNCACK	9
+
+/*
+ * DCCP options and features.
+ */
+
+/* Options types (RFC 4340, Section 5.8.) */
+#define	DCCP_OPTION_PADDING		0
+#define	DCCP_OPTION_MANDATORY		1
+#define	DCCP_OPTION_SLOW_RECEIVER	2
+#define	DCCP_OPTION_CHANGE_L		32
+#define	DCCP_OPTION_CONFIRM_L		33
+#define	DCCP_OPTION_CHANGE_R		34
+#define	DCCP_OPTION_CONFIRM_R		35
+#define	DCCP_OPTION_INIT_COOKIE		36
+#define	DCCP_OPTION_NDP_COUNT		37
+#define	DCCP_OPTION_ACK_VECTOR_1	38
+#define	DCCP_OPTION_ACK_VECTOR_2	39
+#define	DCCP_OPTION_DATA_DROPPED	40
+#define	DCCP_OPTION_TIMESTAMP		41
+#define	DCCP_OPTION_TIMESTAMP_ECHO	42
+#define	DCCP_OPTION_ELAPSED_TIME	43
+#define DCCP_OPTION_DATA_CHECKSUM	44
+
+/* Feature types (RFC 4340, Section 6.4.) */
+#define	DCCP_FEATURE_CCID			1
+#define	DCCP_FEATURE_ALLOW_SHORT_SEQNOS		2
+#define	DCCP_FEATURE_SEQUENCE_WINDOW		3
+#define	DCCP_FEATURE_ECN_INCAPABLE		4
+#define	DCCP_FEATURE_ACK_RATIO			5
+#define	DCCP_FEATURE_SEND_ACK_VECTOR		6
+#define	DCCP_FEATURE_SEND_NDP_COUNT		7
+#define	DCCP_FEATURE_MIN_CHECKSUM_COVERAGE	8
+#define	DCCP_FEATURE_CHECK_DATA_CHECKSUM	9
+
+/* Feature negotation states (RFC 4340, Section 6.6.2.) */
+#define	DCCP_FEATURE_STATE_CHANGING		0
+#define	DCCP_FEATURE_STATE_UNSTABLE		1
+#define	DCCP_FEATURE_STATE_STABLE		2
+
+typedef struct dccp_feature_s {
+	list_node_t	df_next;
+	uint8_t		df_option;
+	uint8_t		df_type;
+	uint8_t		df_state;
+	uint64_t	df_value;
+	boolean_t	df_mandatory;
+} dccp_feature_t;
+
+/* Options in DCCP header */
+typedef struct dccp_opt_s {
+	int		type;
+	boolean_t	mandatory;
+} dccp_opt_t;
+
+/*
+ * DCCP header structures.
+ */
+
+/* Generic protocol header (RFC 4340, Section 5.1.) */
+typedef struct dccphdr_s {
+	uint8_t		dh_lport[2];
+	uint8_t		dh_fport[2];
+	uint8_t		dh_offset;
+	uint8_t		dh_ccval:4,
+			dh_cscov:4;
+	uint8_t		db_sum[2];
+	uint8_t		dh_reserved:3,
+			dh_type:4,
+			dh_x:1;
+	uint8_t		dh_res_seq;
+	uint8_t		dh_seq[2];
+} dccph_t;
+
+
+/* Generic protocol header aligned (RFC 4340, Section 5.1.) */
+typedef struct dccphdra_s {
+	in_port_t	dha_lport;		/* Source port */
+	in_port_t	dha_fport;		/* Destination port */
+	uint8_t		dha_offset;		/* Data offset */
+	uint8_t		dha_ccval:4,		/* */
+			dha_cscov:4;		/* */
+	uint16_t	dha_sum;		/* Checksum */
+	uint8_t		dha_x:1,		/* Reserved */
+			dha_type:4,		/* Packet type */
+			dha_reserved:3;		/* Header type */
+	uint8_t		dha_res_seq;
+	uint16_t	dha_seq;		/* Partial sequence number */
+} dccpha_t;
+
+typedef struct dccphdra_ext_s {
+	uint32_t	dha_ext_seq;
+} dccpha_ext_t;
+
+/* Acknowledgement number */
+typedef struct dccphdra_ack {
+	uint16_t	dha_ack_reserved;
+	uint16_t	dha_ack_high;
+	uint32_t	dha_ack_low;
+} dccpha_ack_t;
+
+/* Service number */
+typedef	struct dccphdra_srv {
+	uint32_t	dha_srv_code;
+} dccpha_srv_t;
+
+/* Reset data */
+typedef struct dccphdra_reset {
+	uint8_t		dha_reset_code;
+	uint8_t		dha_reset_data[3];
+} dccpha_reset_t;
+
+/* Internal DCCP structure */
+typedef struct dccp_s {
+
+	conn_t		*dccp_connp;		/* Backpointer to conn_t */
+	dccp_stack_t	*dccp_dccps;		/* Backpointer to dccp_stack_t */
+
+	int32_t		dccp_state;
+
+	uint32_t
+		dccp_loopback: 1,	/* Src and dst are the same machine */
+		dccp_localnet: 1,	/* Src and dst are on the same subnet */
+		dccp_active_open: 1,	/* This is a active open */
+		dccp_dummy: 1;
+
+	/* Bind related */
+	struct dccp_s	*dccp_bind_hash;	/* Bind hash chain */
+	struct dccp_s	*dccp_bind_hash_port;	/* Bound to the same port */
+	struct dccp_s	**dccp_ptpbhn;
+
+	struct dccphdra_s *dccp_dccpha;		/* Template header */
+
+	mblk_t		*dccp_xmit_head;
+
+	/*
+	 * Pointers into the header template.
+	 */
+	ipha_t		*dccp_ipha;
+	ip6_t		*dccp_ip6h;
+
+	t_uscalar_t	dccp_acceptor_id;	/* ACCEPTOR_id */
+
+	sock_connid_t	dccp_connid;
+
+	/* Incrementing pending conn req ID */
+	t_scalar_t	dccp_conn_req_seqnum;
+
+	boolean_t	dccp_issocket;		/* This is a socket dccp */
+
+	/* List of features being negotiated */
+	list_t		dccp_features;
+
+	/*
+	 *Sequence numbers (Section 7.1.)
+	 */
+	uint64_t	dccp_iss;	/* Initial sequence number sent */
+	uint64_t	dccp_isr;	/* Initial sequence number received */
+	uint64_t	dccp_gss;	/* Greatest sequence number sent */
+	uint64_t	dccp_gsr;	/* Greatest sequence */
+					/* number received */
+	uint64_t	dccp_gar;	/* Greatest acknowledgement */
+					/* number received */
+} dccp_t;
+
+#define	dccps_smallest_nonpriv_port	dccps_propinfo_tbl[0].prop_cur_uval
+#define	dccps_smallest_anon_port	dccps_propinfo_tbl[1].prop_cur_uval
+#define	dccps_largest_anon_port		dccps_propinfo_tbl[2].prop_cur_uval
+
+#define	dccps_dbg			dccps_propinfo_tbl[4].prop_cur_uval
+#define	dccps_rst_sent_rate_enabled	dccps_propinfo_tbl[5].prop_cur_uval
+#define	dccps_rst_sent_rate		dccps_propinfo_tbl[6].prop_cur_uval
+
+typedef struct dccp_df_s {
+	struct dccp_s	*df_dccp;
+	kmutex_t	df_lock;
+	uchar_t		df_pad[TF_CACHEL_PAD - (sizeof (dccp_t *) +
+			    sizeof (kmutex_t))];
+} dccp_df_t;
+
+extern struct qinit dccp_rinitv4, dccp_rinitv6;
+
+extern optdb_obj_t	dccp_opt_obj;
+extern uint_t		dccp_max_optsize;
+
+extern int		dccp_squeue_flag;
+
+/*
+ * Functions in dccp.c
+ */
+extern int	dccp_build_hdrs(dccp_t *);
+extern conn_t	*dccp_create_common(cred_t *, boolean_t, boolean_t, int *);
+extern void	dccp_close_common(conn_t *, int);
+extern int	dccp_do_bind(conn_t *, struct sockaddr *, socklen_t, cred_t *,
+		    boolean_t);
+extern int	dccp_do_unbind(conn_t *);
+extern int	dccp_do_listen(conn_t *, struct sockaddr *, socklen_t, int,
+		    cred_t *, boolean_t);
+extern int	dccp_do_connect(conn_t *, const struct sockaddr *, socklen_t,
+		    cred_t *, pid_t);
+extern void	dccp_init_values(dccp_t *, dccp_t *);
+extern void	*dccp_get_conn(void *, dccp_stack_t *);
+extern int	dccp_set_destination(dccp_t *dccp);
+
+/*
+ * Functions in dccp_bind.c
+ */
+extern void	dccp_bind_hash_insert(dccp_df_t *, dccp_t *, int);
+extern void	dccp_bind_hash_remove(dccp_t *);
+extern int	dccp_bind_check(conn_t *, struct sockaddr *, socklen_t, cred_t *cr,
+		    boolean_t);
+extern in_port_t dccp_bindi(dccp_t *, in_port_t, const in6_addr_t *, int,
+		    boolean_t, boolean_t, boolean_t);
+extern in_port_t dccp_update_next_port(in_port_t, const dccp_t *, boolean_t);
+
+/*
+ * Functions in dccp_features.c
+ */
+extern void	dccp_process_options(dccp_t *, dccpha_t *);
+extern int	dccp_generate_options(dccp_t *, void **, size_t *);
+
+/*
+ * Functions in dccp_stats.c
+ */
+extern mblk_t	*dccp_snmp_get(queue_t *, mblk_t *, boolean_t);
+extern void	*dccp_kstat_init(netstackid_t);
+extern void	dccp_kstat_fini(netstackid_t, kstat_t *);
+
+/*
+ * Functions in dccp_socket.c
+ */
+extern sock_lower_handle_t	dccp_create(int, int, int, sock_downcalls_t **,
+				    uint_t *, int *, int, cred_t *);
+extern int	dccp_fallback(sock_lower_handle_t, queue_t *, boolean_t,
+		    so_proto_quiesced_cb_t, sock_quiesce_arg_t *);
+
+/*
+ * Functions in dccp_input.c
+ */
+extern void	dccp_icmp_input(void *, mblk_t *, void *, ip_recv_attr_t *);
+extern void	dccp_input_data(void *, mblk_t *, void *, ip_recv_attr_t *);
+extern void	dccp_rsrv(queue_t *);
+extern void	dccp_input_listener_unbound(void *, mblk_t *, void *,
+		    ip_recv_attr_t *);
+extern boolean_t dccp_verifyicmp(conn_t *, void *, icmph_t *, icmp6_t *,
+		    ip_recv_attr_t *);
+
+/*
+ * Functions in dccp_misc.c
+ */
+extern void	dccp_stack_cpu_add(dccp_stack_t *, processorid_t);
+
+/*
+ * Functions in dccp_output.c
+ */
+extern void	dccp_wput(queue_t *, mblk_t *);
+extern void	dccp_wput_sock(queue_t *, mblk_t *);
+extern void	dccp_wput_fallback(queue_t *, mblk_t *);
+extern void	dccp_output_urgent(void *, mblk_t *, void *, ip_recv_attr_t *);
+extern void	dccp_output(void *, mblk_t *, void *, ip_recv_attr_t *);
+extern void	dccp_send_data(dccp_t *, mblk_t *);
+extern void	dccp_xmit_listeners_reset(mblk_t *, ip_recv_attr_t *,
+		    ip_stack_t *, conn_t *);
+extern void	dccp_send_synack(void *, mblk_t *, void *, ip_recv_attr_t *);
+extern mblk_t	*dccp_xmit_mp(dccp_t *, mblk_t *, int32_t, int32_t *,
+		    mblk_t **, uint32_t, boolean_t, uint32_t *, boolean_t);
+/* XXX following functions should be redone */
+extern mblk_t	*dccp_generate_packet(conn_t *, mblk_t *);
+extern mblk_t	*dccp_generate_request(conn_t *);
+
+/*
+ * Functions in dccp_opt_data.c
+ */
+extern int	dccp_opt_get(conn_t *, int, int, uchar_t *);
+extern int	dccp_opt_set(conn_t *, uint_t, int, int, uint_t, uchar_t *,
+		    uint_t *, uchar_t *, void *, cred_t *);
+
+/*
+ * Functions in dccp_tpi.c
+ */
+extern void	dccp_do_capability_ack(dccp_t *, struct T_capability_ack *,
+		    t_uscalar_t);
+extern void	dccp_capability_req(dccp_t *, mblk_t *);
+extern void	dccp_err_ack(dccp_t *, mblk_t *, int, int);
+extern void	dccp_tpi_connect(dccp_t *, mblk_t *);
+extern int	dccp_tpi_close(queue_t *, int);
+extern int	dccp_tpi_close_accept(queue_t *);
+extern int	dccp_tpi_opt_get(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
+extern int	dccp_tpi_opt_set(queue_t *, uint_t, int, int, uint_t, uchar_t *,
+		    uint_t *, uchar_t *, void *, cred_t *);
+extern void	dccp_tpi_accept(queue_t *, mblk_t *);
+
+#endif	/* _KERNEL */
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _INET_DCCP_IMPL_H */
