From 3253eb74dc266daf877decdfeef9d4fe694e16b7 Mon Sep 17 00:00:00 2001
From: hoelscher <jens.hoelscher@fh-muenster.de>
Date: Fri, 27 Nov 2015 17:06:17 +0100
Subject: [PATCH] add support for socketoption sctp_default_send_param

---
 gtests/net/packetdrill/run_system_call.c      | 22 +++++++++++++++++++
 gtests/net/packetdrill/symbols_freebsd.c      |  1 +
 .../getsockopt/sctp_default_send_param.pkt    | 20 +++++++++++++----
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c
index 724ea1a5..cc4e9589 100644
--- a/gtests/net/packetdrill/run_system_call.c
+++ b/gtests/net/packetdrill/run_system_call.c
@@ -3103,6 +3103,12 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall,
 		}
 		break;
 #endif
+#ifdef SCTP_DEFAULT_SEND_PARAM
+	case EXPR_SCTP_SNDRCVINFO:
+		live_optval = malloc(sizeof(struct sctp_sndrcvinfo));
+		live_optlen = sizeof(struct sctp_sndrcvinfo);
+		break;
+#endif
 #ifdef SCTP_EVENTS
 	case EXPR_SCTP_EVENT_SUBSCRIBE:
 		live_optval = malloc(sizeof(struct sctp_event_subscribe));
@@ -3242,6 +3248,11 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall,
 		result = check_sctp_event(val_expression->value.sctp_event, live_optval, error);
 		break;
 #endif
+#ifdef SCTP_DEFAULT_SEND_PARAM
+	case EXPR_SCTP_SNDRCVINFO:
+		result = check_sctp_sndrcvinfo(val_expression->value.sctp_sndrcvinfo, live_optval, error);
+		break;
+#endif
 #ifdef SCTP_EVENTS
 	case EXPR_SCTP_EVENT_SUBSCRIBE:
 		result = check_sctp_event_subscribe(val_expression->value.sctp_event_subscribe, live_optval, error);
@@ -3323,6 +3334,9 @@ static int syscall_setsockopt(struct state *state, struct syscall_spec *syscall,
 #ifdef SCTP_EVENTS
 	struct sctp_event_subscribe event_subscribe;
 #endif
+#ifdef SCTP_DEFAULT_SEND_PARAM
+	struct sctp_sndrcvinfo sndrcvinfo;
+#endif
 #ifdef SCTP_DEFAULT_SNDINFO
 	struct sctp_sndinfo sndinfo;
 #endif
@@ -3574,6 +3588,14 @@ static int syscall_setsockopt(struct state *state, struct syscall_spec *syscall,
 		optval = &event_subscribe;
 		break;
 #endif
+#ifdef SCTP_DEFAULT_SEND_PARAM
+	case EXPR_SCTP_SNDRCVINFO:
+		if (parse_expression_to_sctp_sndrcvinfo(val_expression, &sndrcvinfo, true, error)) {
+			return STATUS_ERR;
+		}
+		optval = &sndrcvinfo;	
+		break;	
+#endif
 #ifdef SCTP_DEFAULT_SNDINFO
 	case EXPR_SCTP_SNDINFO:
 		if (get_u16(val_expression->value.sctp_sndinfo->snd_sid,
diff --git a/gtests/net/packetdrill/symbols_freebsd.c b/gtests/net/packetdrill/symbols_freebsd.c
index 93cbd786..61ab2436 100644
--- a/gtests/net/packetdrill/symbols_freebsd.c
+++ b/gtests/net/packetdrill/symbols_freebsd.c
@@ -88,6 +88,7 @@ struct int_symbol platform_symbols_table[] = {
 	{ SCTP_PRIMARY_ADDR,                "SCTP_PRIMARY_ADDR"               },
 	{ SCTP_ADAPTATION_LAYER,            "SCTP_ADAPTATION_LAYER"           },
 	{ SCTP_DISABLE_FRAGMENTS,           "SCTP_DISABLE_FRAGMENTS"          },
+	{ SCTP_DEFAULT_SEND_PARAM,          "SCTP_DEFAULT_SEND_PARAM"         },
 	{ SCTP_MAXSEG,                      "SCTP_MAXSEG"                     },
 	{ SCTP_AUTH_ACTIVE_KEY,             "SCTP_AUTH_ACTIVE_KEY"            },
 	{ SCTP_DELAYED_SACK,                "SCTP_DELAYED_SACK"               },
diff --git a/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_default_send_param.pkt b/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_default_send_param.pkt
index 34811acd..275882b7 100644
--- a/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_default_send_param.pkt
+++ b/gtests/net/packetdrill/tests/bsd/sctp/api_tests/getsockopt/sctp_default_send_param.pkt
@@ -10,6 +10,16 @@
 
 +0 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
 
++0 getsockopt(3, IPPROTO_SCTP, SCTP_DEFAULT_SEND_PARAM, {sinfo_stream=0,
+							 sinfo_ssn=0,
+							 sinfo_flags=0,
+							 sinfo_ppid=htonl(0),
+							 sinfo_context=0,
+							 sinfo_timetolive=0,
+							 sinfo_tsn=0,
+							 sinfo_cumtsn=0,
+							 sinfo_assoc_id=0}, [128]) = 0
+
 +0 setsockopt(3, IPPROTO_SCTP, SCTP_DEFAULT_SEND_PARAM, {sinfo_stream=0,
 							 sinfo_ssn=1,
 							 sinfo_flags=0,
@@ -18,7 +28,8 @@
 							 sinfo_timetolive=0,
 							 sinfo_tsn=2,
 							 sinfo_cumtsn=1,
-							 sinfo_assoc_id=3}, 30) = 0
+							 sinfo_assoc_id=3}, 128) = 0
+
 +0 getsockopt(3, IPPROTO_SCTP, SCTP_DEFAULT_SEND_PARAM, {sinfo_stream=0,
 							 sinfo_ssn=1,
 							 sinfo_flags=0,
@@ -27,7 +38,7 @@
 							 sinfo_timetolive=0,
 							 sinfo_tsn=2,
 							 sinfo_cumtsn=1,
-							 sinfo_assoc_id=3}, [30]) = 0
+							 sinfo_assoc_id=3}, [128]) = 0
 
 +0 setsockopt(3, IPPROTO_SCTP, SCTP_DEFAULT_SEND_PARAM, {sinfo_stream=0,
 							 sinfo_ssn=1,
@@ -36,7 +47,8 @@
 							 sinfo_context=0,
 							 sinfo_timetolive=0,
 							 sinfo_tsn=2,
-							 sinfo_cumtsn=1}, 30) = 0
+							 sinfo_cumtsn=1}, 128) = 0
+
 +0 getsockopt(3, IPPROTO_SCTP, SCTP_DEFAULT_SEND_PARAM, {sinfo_stream=0,
 							 sinfo_ssn=1,
 							 sinfo_flags=0,
@@ -44,6 +56,6 @@
 							 sinfo_context=0,
 							 sinfo_timetolive=0,
 							 sinfo_tsn=2,
-							 sinfo_cumtsn=1}, [30]) = 0
+							 sinfo_cumtsn=1}, [128]) = 0
 
 +0 close(3) = 0
-- 
GitLab