From 2616b2ee679091b1ed91e71eda956491d13097b6 Mon Sep 17 00:00:00 2001 From: hoelscher <jens.hoelscher@fh-muenster.de> Date: Tue, 29 Sep 2015 22:12:58 +0200 Subject: [PATCH] Add support for setsockopt for sctp_peeraddrparams --- gtests/net/packetdrill/run_system_call.c | 40 +++++++++++++++++-- .../bsd/sctp/sctp_get_socket_options.pkt | 9 +++-- .../tests/bsd/sctp/sctp_socket_options.pkt | 4 +- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c index e6a0606d..29373db6 100644 --- a/gtests/net/packetdrill/run_system_call.c +++ b/gtests/net/packetdrill/run_system_call.c @@ -557,7 +557,7 @@ static int end_syscall(struct state *state, struct syscall_spec *syscall, if (mode == CHECK_NON_NEGATIVE) { if (actual < 0) { asprintf(error, - "Expected non-negative result but got %d " + "Expected non-negative result but got %d" "with errno %d (%s)", actual, actual_errno, strerror(actual_errno)); return STATUS_ERR; @@ -1904,7 +1904,7 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall, return STATUS_ERR; } if (live_params->spp_hbinterval != hbinterval) { - asprintf(error, "Bad getsockopt SCTP_PARAMS hbinterval: expected: %u actual: %u ", + asprintf(error, "Bad getsockopt SCTP_PARAMS hbinterval: expected: %u actual: %u", hbinterval, live_params->spp_hbinterval); free(live_optval); return STATUS_ERR; @@ -1916,7 +1916,7 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall, return STATUS_ERR; } if (live_params->spp_pathmaxrxt != pathmaxrxt) { - asprintf(error, "Bad getsockopt SCTP_PARAMS pathmaxrxt: expected: %hu actual: %hu ", + asprintf(error, "Bad getsockopt SCTP_PARAMS pathmaxrxt: expected: %hu actual: %hu", pathmaxrxt, live_params->spp_pathmaxrxt); free(live_optval); return STATUS_ERR; @@ -1928,7 +1928,7 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall, return STATUS_ERR; } if (live_params->spp_pathmtu != pathmtu) { - asprintf(error, "Bad getsockopt SCTP_PARAMS pathmtu: expected: %u actual: %u ", + asprintf(error, "Bad getsockopt SCTP_PARAMS pathmtu: expected: %u actual: %u", pathmtu, live_params->spp_pathmtu); free(live_optval); return STATUS_ERR; @@ -2014,6 +2014,38 @@ static int syscall_setsockopt(struct state *state, struct syscall_spec *syscall, #ifdef SCTP_STATUS } else if (val_expression->type == EXPR_SCTP_STATUS) { optval = &val_expression->value.sctp_status; +#endif +#ifdef SCTP_PEER_ADDR_PARAMS + } else if (val_expression->type == EXPR_SCTP_PEER_ADDR_PARAMS) { + struct sctp_paddrparams_expr *expr_params = val_expression->value.sctp_paddrparams; + struct sctp_paddrparams *params = malloc(sizeof(struct sctp_paddrparams)); + memset(params, 0, sizeof(struct sctp_paddrparams)); + socklen_t live_optlen = sizeof(struct sctp_paddrparams); + if (expr_params->spp_address->type == EXPR_SOCKET_ADDRESS_IPV4) { + memcpy(¶ms->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(¶ms->spp_address, expr_params->spp_address->value.socket_address_ipv6, sizeof(struct sockaddr_in6)); + } else { + asprintf(error, "Bad setsockopt, bad input for spp_address for socketoption SCTP_PADDRPARAMS"); + free(params); + return STATUS_ERR; + } + params->spp_assoc_id = 0; + if (getsockopt(live_fd, level, optname, params, &live_optlen) == -1) { + asprintf(error, "Bad setsockopt, bad get actuall values"); + free(params); + return STATUS_ERR; + } + if (expr_params->spp_hbinterval->type != EXPR_ELLIPSIS) { + params->spp_hbinterval = expr_params->spp_hbinterval->value.num; + } + if (expr_params->spp_pathmaxrxt->type != EXPR_ELLIPSIS) { + params->spp_pathmaxrxt = expr_params->spp_pathmaxrxt->value.num; + } + if (expr_params->spp_pathmtu->type != EXPR_ELLIPSIS) { + params->spp_pathmtu = expr_params->spp_pathmtu->value.num; + } + optval = params; #endif } else { asprintf(error, "unsupported setsockopt value type: %s", 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 1a90543d..2812fe2a 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 @@ -30,14 +30,17 @@ sstat_outstrms=1, sstat_fragmentation_point=..., sstat_primary={ spinfo_state=1, spinfo_cwnd=4464, spinfo_srtt=..., spinfo_rto=1000, spinfo_mtu=1468} }, [176])= 0 ++0 setsockopt(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={sa_family=AF_INET, sin_port=htons(8080), sin_addr=inet_addr("192.0.2.1")}, - spp_hbinterval=30000, spp_pathmtu=1468, spp_pathmaxrxt=5}, [152]) = 0 + spp_hbinterval=60000, spp_pathmtu=1468, 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=..., spp_pathmtu=1468, 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=30000, spp_pathmtu=..., spp_pathmaxrxt=5}, [152]) = 0 + 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=30000, spp_pathmtu=1468, spp_pathmaxrxt=...}, [152]) = 0 + 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 diff --git a/gtests/net/packetdrill/tests/bsd/sctp/sctp_socket_options.pkt b/gtests/net/packetdrill/tests/bsd/sctp/sctp_socket_options.pkt index ea2f192f..5a69cf3c 100644 --- a/gtests/net/packetdrill/tests/bsd/sctp/sctp_socket_options.pkt +++ b/gtests/net/packetdrill/tests/bsd/sctp/sctp_socket_options.pkt @@ -42,5 +42,7 @@ +0 setsockopt(3, IPPROTO_SCTP, SCTP_MAX_BURST, {assoc_value=1}, 9) = 0 +0 setsockopt(3, IPPROTO_SCTP, SCTP_MAX_BURST, {assoc_value=1}, 7) = -1 (Invalid argument) -+0 close(3) = 0 ++0 setsockopt(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=30000, spp_pathmtu=1468, spp_pathmaxrxt=100}, 152) = 0 ++0 close(3) = 0 -- GitLab