From 31a2685f8d726429f6682d4719051e4290120927 Mon Sep 17 00:00:00 2001
From: hoelscher <jens.hoelscher@fh-muenster.de>
Date: Wed, 30 Sep 2015 14:20:22 +0200
Subject: [PATCH] Add for set/getsockopt for sctp_paddrparams with spp_address
 as ellipsis with primary peeraddress

---
 gtests/net/packetdrill/run_system_call.c      | 23 +++++++++++++++----
 .../bsd/sctp/sctp_get_socket_options.pkt      |  4 +++-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c
index 60e149a9..dae5651e 100644
--- a/gtests/net/packetdrill/run_system_call.c
+++ b/gtests/net/packetdrill/run_system_call.c
@@ -1621,13 +1621,19 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall,
 		struct sctp_paddrparams_expr *expr_params = val_expression->value.sctp_paddrparams;
 		struct sctp_paddrparams *live_params = malloc(sizeof(struct sctp_paddrparams));
 		live_optlen = sizeof(struct sctp_paddrparams);
-		if (expr_params->spp_address->type != EXPR_ELLIPSIS) {
-			if (expr_params->spp_address->type == EXPR_SOCKET_ADDRESS_IPV4) {
-				memcpy(&live_params->spp_address, expr_params->spp_address->value.socket_address_ipv4, sizeof(struct sockaddr_in));
-			} else {
-				memcpy(&live_params->spp_address, expr_params->spp_address->value.socket_address_ipv6, sizeof(struct sockaddr_in6));
+		if (expr_params->spp_address->type == EXPR_ELLIPSIS) {
+			socklen_t len_addr = sizeof(live_params->spp_address);
+			if (getpeername(live_fd, (struct sockaddr*) &live_params->spp_address, &len_addr)) {
+				asprintf(error, "Bad setsockopt, bad get primary peer address");
+				free(live_params);
+				return STATUS_ERR;
 			}
+		} else if (expr_params->spp_address->type == EXPR_SOCKET_ADDRESS_IPV4) {
+			memcpy(&live_params->spp_address, expr_params->spp_address->value.socket_address_ipv4, sizeof(struct sockaddr_in));
+		} else if (expr_params->spp_address->type == EXPR_SOCKET_ADDRESS_IPV6) {
+			memcpy(&live_params->spp_address, expr_params->spp_address->value.socket_address_ipv6, sizeof(struct sockaddr_in6));
 		} else {
+			asprintf(error, "Bad setsockopt, bad get input for spp_address");
 			free(live_params);
 			return STATUS_ERR;
 		}
@@ -2031,6 +2037,13 @@ static int syscall_setsockopt(struct state *state, struct syscall_spec *syscall,
 			memcpy(&params->spp_address, expr_params->spp_address->value.socket_address_ipv4, sizeof(struct sockaddr_in));
 		} else if (expr_params->spp_address->type == EXPR_SOCKET_ADDRESS_IPV6) {
 			memcpy(&params->spp_address, expr_params->spp_address->value.socket_address_ipv6, sizeof(struct sockaddr_in6));
+		} else if (expr_params->spp_address->type == EXPR_ELLIPSIS) {
+			socklen_t len_addr = sizeof(params->spp_address);
+			if (getpeername(live_fd, (struct sockaddr*) &params->spp_address, &len_addr)) {
+				asprintf(error, "Bad setsockopt, bad get primary peer address");
+				free(params);
+				return STATUS_ERR;
+			}
 		} else {
 			asprintf(error, "Bad setsockopt, bad input for spp_address for socketoption SCTP_PADDRPARAMS");
 			free(params);
diff --git a/gtests/net/packetdrill/tests/bsd/sctp/sctp_get_socket_options.pkt b/gtests/net/packetdrill/tests/bsd/sctp/sctp_get_socket_options.pkt
index e165429e..173449ba 100644
--- a/gtests/net/packetdrill/tests/bsd/sctp/sctp_get_socket_options.pkt
+++ b/gtests/net/packetdrill/tests/bsd/sctp/sctp_get_socket_options.pkt
@@ -11,7 +11,7 @@
 //+0.0 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
 
 
-+0 getsockopt(3, IPPROTO_SCTP, SCTP_STATUS, {sstat_state=SCTP_ESTABLISHED, sstat_rwnd=1500, 
++0 getsockopt(3, IPPROTO_SCTP, SCTP_STATUS, {sstat_state=..., sstat_rwnd=1500, 
 sstat_unackdata=0, sstat_penddata=0, sstat_instrms=1, sstat_outstrms=1, sstat_fragmentation_point=1452, sstat_primary=...}, [176])= 0
 
 +0 getsockopt(3, IPPROTO_SCTP, SCTP_STATUS, {sstat_state=..., sstat_rwnd=1500, sstat_unackdata=0, 
@@ -55,6 +55,8 @@ spp_hbinterval=60000, spp_pathmtu=..., spp_pathmaxrxt=5}, [152]) = 0
 +0 getsockopt(3, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, {spp_address={sa_family=AF_INET, sin_port=htons(8080), sin_addr=inet_addr("192.0.2.1")},
 spp_hbinterval=60000, spp_pathmtu=1468, spp_pathmaxrxt=...}, [152]) = 0
 
++0 getsockopt(3, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, {spp_address=..., spp_hbinterval=60000, spp_pathmtu=1468, spp_pathmaxrxt=...}, [152]) = 0
+
 +0 setsockopt(3, SOL_SOCKET, SO_LINGER, {onoff=1, linger=30}, 8) = 0
 +0 getsockopt(3, SOL_SOCKET, SO_LINGER, {onoff=128, linger=30}, [8]) = 0
 +0 getsockopt(3, SOL_SOCKET, SO_LINGER, {onoff=128, linger=...}, [8]) = 0
-- 
GitLab