--- /dev/null	2012-07-09 14:38:12.000000000 +0000
+++ new/usr/src/uts/common/inet/dccp/dccp_features.c	2012-07-09 14:38:12.701618385 +0000
@@ -0,0 +1,289 @@
+/*
+ * 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.
+ */
+
+#include <sys/types.h> 
+#include <sys/stream.h> 
+#include <sys/debug.h> 
+#include <sys/cmn_err.h>
+
+#include "dccp_impl.h"
+#include "dccp_stack.h"
+
+/*
+ * This file contains functions to parse and process DCCP options
+ * and features.
+ */
+
+static void	dccp_parse_feature(dccp_t *, uint8_t, uint8_t, uchar_t *,
+		    boolean_t);
+
+/*
+ * Feature handling.
+ */
+static void
+dccp_parse_feature(dccp_t *dccp, uint8_t option, uint8_t length, uchar_t *up,
+    boolean_t mandatory)
+{
+	dccp_feature_t	*feature;
+	uint8_t		feature_type;
+	uint8_t		feature_length = length - 1;
+
+	cmn_err(CE_NOTE, "dccp_features.c: dccp_parse_feature");
+
+	feature_type = *up;
+
+	switch (feature_type) {
+	case DCCP_FEATURE_CCID:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_CCID");
+		break;
+	case DCCP_FEATURE_ALLOW_SHORT_SEQNOS:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_ALLOW_SHORT_SEQNOS");
+		break;
+	case DCCP_FEATURE_SEQUENCE_WINDOW:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_SEQUENCE_WINDOW");
+		break;
+	case DCCP_FEATURE_ECN_INCAPABLE:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_ECN_INCAPABLE");
+		break;
+	case DCCP_FEATURE_ACK_RATIO:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_ACK_RATIO");
+		break;
+	case DCCP_FEATURE_SEND_ACK_VECTOR:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_SEND_ACK_VECTOR");
+		break;
+	case DCCP_FEATURE_SEND_NDP_COUNT:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_SEND_NDP_COUNT");
+		break;
+	case DCCP_FEATURE_MIN_CHECKSUM_COVERAGE:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_MIN_CHECKSUM_COVERAGE");
+		break;
+	case DCCP_FEATURE_CHECK_DATA_CHECKSUM:
+		cmn_err(CE_NOTE, "DCCP_FEATURE_CHECK_DATA_CHECKSUM");
+		break;
+
+	default:
+		cmn_err(CE_NOTE, "ERROR DEFAULT");
+		break;
+	}
+
+	feature = (dccp_feature_t *)kmem_alloc(sizeof (dccp_feature_t),
+	    KM_SLEEP);
+	if (feature == NULL) {
+		return;
+	}
+
+	feature->df_option = option;
+	feature->df_type = feature_type;
+	feature->df_mandatory = mandatory;
+
+	list_insert_tail(&dccp->dccp_features, feature);
+}
+
+/*
+ * Parse the options in a DCCP header.
+ */
+void
+dccp_parse_options(dccp_t *dccp, dccpha_t *dccpha)
+{
+	uchar_t		*end;
+	uchar_t		*up;
+	uint8_t		dccp_type;
+	uint8_t		option_type;
+	uint8_t		option_length;
+	int		len;
+	int		i;
+	uchar_t		*value;
+	boolean_t	mandatory = B_FALSE;
+
+	cmn_err(CE_NOTE, "dccp_features.c: dccp_parse_options");
+
+	dccp_type = dccpha->dha_type;
+
+	up = (uchar_t *)dccpha;
+	end = up + DCCP_HDR_LENGTH(dccpha);
+	up += 20;
+
+	if (dccp_type != DCCP_PKT_REQUEST) {
+		cmn_err(CE_NOTE, "not request pkt");
+		return;
+	}
+
+	while (up != end) {
+		option_length = 0;
+		option_type = *up++;
+
+		if (option_type > 31) {
+			option_length = *up++;
+			option_length -= 2;
+			value = up;
+
+			up += option_length;
+		}
+
+		switch (option_type) {
+		case DCCP_OPTION_PADDING:
+			cmn_err(CE_NOTE, "PADDING");
+			break;
+		case DCCP_OPTION_MANDATORY:
+			cmn_err(CE_NOTE, "MANDATORY");
+			mandatory = B_TRUE;
+			break;
+		case DCCP_OPTION_SLOW_RECEIVER:
+			cmn_err(CE_NOTE, "SLOW RECEIVER");
+			break;
+		case DCCP_OPTION_CHANGE_L:
+		case DCCP_OPTION_CONFIRM_L:
+		case DCCP_OPTION_CHANGE_R:
+		case DCCP_OPTION_CONFIRM_R:
+			dccp_parse_feature(dccp, option_type, option_length,
+			    value, mandatory);
+			break;
+		case DCCP_OPTION_INIT_COOKIE:
+			cmn_err(CE_NOTE, "INIT COOKIE");
+			break;
+		case DCCP_OPTION_NDP_COUNT:
+			cmn_err(CE_NOTE, "NDP COUNT");
+			break;
+		case DCCP_OPTION_ACK_VECTOR_1:
+			cmn_err(CE_NOTE, "ACK VECTOR 1");
+			break;
+		case DCCP_OPTION_ACK_VECTOR_2:
+			cmn_err(CE_NOTE, "ACK VECTOR 2");
+			break;
+		case DCCP_OPTION_DATA_DROPPED:
+			cmn_err(CE_NOTE, "DATA DROPPED");
+			break;
+		case DCCP_OPTION_TIMESTAMP:
+			cmn_err(CE_NOTE, "TIMESTAMP");
+			if (option_length == 4) {
+				cmn_err(CE_NOTE, "timestamp length == 4");
+			} else {
+				cmn_err(CE_NOTE, "timestamp length != 4");
+			}
+			break;
+		case DCCP_OPTION_TIMESTAMP_ECHO:
+			cmn_err(CE_NOTE, "TIMESTAMP ECHO");
+			break;
+		case DCCP_OPTION_ELAPSED_TIME:
+			cmn_err(CE_NOTE, "ELAPSES TIME");
+			break;
+		case DCCP_OPTION_DATA_CHECKSUM:
+			cmn_err(CE_NOTE, "DATA CHECKSUM");
+			break;
+
+		default:
+			cmn_err(CE_NOTE, "DEFAULT");
+			break;
+		}
+
+		if (option_type != DCCP_OPTION_MANDATORY) {
+			mandatory = B_FALSE;
+		}
+	}
+}
+
+void
+dccp_process_options(dccp_t *dccp, dccpha_t *dccpha)
+{
+	cmn_err(CE_NOTE, "dccp_features.c: dccp_process_features");
+
+	dccp_parse_options(dccp, dccpha);
+}
+
+int
+dccp_generate_options(dccp_t *dccp, void **opt, size_t *opt_len)
+{
+	dccp_feature_t	*feature = NULL;
+	uint8_t		buf[1024];	/* XXX */
+	uint8_t		option_type;
+	uint_t		len = 0;
+	uint_t		total_len;
+	void		*options;
+	int		rest;
+
+	cmn_err(CE_NOTE, "dccp_features.c: dccp_generate_options");
+
+	for (feature = list_head(&dccp->dccp_features); feature;
+	    feature = list_next(&dccp->dccp_features, feature)) {
+		if (feature->df_option == DCCP_OPTION_CHANGE_L) {
+			option_type = DCCP_OPTION_CONFIRM_R;
+		} else {
+			option_type = DCCP_OPTION_CONFIRM_L;
+		}
+/*
+		if (feature->df_mandatory == B_TRUE) {
+			buf[len] = DCCP_OPTION_MANDATORY;
+			len++;
+		}
+*/
+		if (feature->df_type == DCCP_FEATURE_CCID) {
+			cmn_err(CE_NOTE, "FOUND DCCP_FEATURE_CCID");
+
+			buf[len] = option_type;
+			len++;
+			buf[len] = 4;
+			len++;
+			buf[len] = DCCP_FEATURE_CCID;
+			len++;
+			buf[len] = 2;
+			len++;
+		}
+
+		if (feature->df_type == DCCP_FEATURE_ALLOW_SHORT_SEQNOS) {
+			buf[len] = option_type;
+			len++;
+			buf[len] = 4;
+			len++;
+			buf[len] = feature->df_type;
+			len++;
+			buf[len] = 0;
+			len++;
+		}
+
+		if (feature->df_type == DCCP_FEATURE_ECN_INCAPABLE) {
+			buf[len] = option_type;
+			len++;
+			buf[len] = 4;
+			len++;
+			buf[len] = feature->df_type;
+			len++;
+			buf[len] = 1;
+			len++;
+		}
+	}
+
+	total_len = ((len + (4 - 1)) / 4) * 4;
+	options = kmem_zalloc(total_len, KM_SLEEP);
+	if (options == NULL) {
+		cmn_err(CE_NOTE, "kmem_zalloc failed");
+		return (ENOMEM);
+	}
+	memcpy(options, buf, len);
+
+	*opt = options;
+	*opt_len = len;
+
+	return (0);
+}
+
+void
+dccp_features_init(void)
+{
+}
+
+void
+dccp_features_destroy(void)
+{
+}
