diff --git a/gtests/net/packetdrill/parser.y b/gtests/net/packetdrill/parser.y index 8f76636f3f3e57ff7a9c0e0c04a85b627174a057..525571df46f8890b06be0dfd0396b35ff52ce525 100644 --- a/gtests/net/packetdrill/parser.y +++ b/gtests/net/packetdrill/parser.y @@ -948,7 +948,7 @@ sctp_packet_spec enum direction_t direction = outer->direction; inner = new_sctp_generic_packet(in_config->wire_protocol, direction, $2, - -1, true, $9, &error); + -1, true, $9, &error); if (inner == NULL) { assert(error != NULL); semantic_error(error); @@ -966,7 +966,7 @@ sctp_packet_spec semantic_error("tag value out of range"); } inner = new_sctp_generic_packet(in_config->wire_protocol, direction, $2, - $7, false, $11, &error); + $7, false, $11, &error); if (inner == NULL) { assert(error != NULL); semantic_error(error); @@ -984,7 +984,7 @@ sctp_packet_spec semantic_error("tag value out of range"); } inner = new_sctp_generic_packet(in_config->wire_protocol, direction, $2, - $9, true, $13, &error); + $9, true, $13, &error); if (inner == NULL) { assert(error != NULL); semantic_error(error); diff --git a/gtests/net/packetdrill/run_packet.c b/gtests/net/packetdrill/run_packet.c index 3ecf86533f09f1ea4fe50dfbbd489778ae66cadf..7c97c0922fc175ed484f371ef5c3ba5ddeaf37bc 100644 --- a/gtests/net/packetdrill/run_packet.c +++ b/gtests/net/packetdrill/run_packet.c @@ -222,28 +222,41 @@ static struct socket *handle_listen_for_script_packet( } else { return NULL; } - } - else { + } else { if (packet->flags & FLAGS_SCTP_GENERIC_PACKET) { + struct header sctp_header; + int i; + bool found = false; + + for (i = 0; i < ARRAY_SIZE(packet->headers); ++i) { + if (packet->headers[i].type == HEADER_SCTP) { + sctp_header = packet->headers[i]; + found = true; + break; + } + } + + assert(found != false); + size_t chunk_length = sctp_header.total_bytes - sizeof(struct sctp_common_header); + + if (chunk_length < sizeof(struct sctp_init_chunk)) { + fprintf(stderr, "length of init chunk too short. you must specify the whole init chunk."); + return NULL; + } + u8 *sctp_chunk_start = (u8 *) (packet->sctp + 1); if (sctp_chunk_start[0] == SCTP_INIT_CHUNK_TYPE) { - u8 *initiate_tag_start = (u8 *) (sctp_chunk_start + 4); - u8 *initial_tsn_start = (u8 *) (sctp_chunk_start + 16); - initiate_tag = initiate_tag_start[3] << 24 | initiate_tag_start[2] << 16 | initiate_tag_start[1] << 8 | initiate_tag_start[0]; - initial_tsn = initial_tsn_start[3] << 24 | initial_tsn_start[2] << 16 | initial_tsn_start[1] << 8 | initial_tsn_start[0]; - initiate_tag = ntohl(initiate_tag); - initial_tsn = ntohl(initial_tsn); - } - else { + struct sctp_init_chunk *init = (struct sctp_init_chunk *) sctp_chunk_start; + initiate_tag = ntohl(init->initiate_tag); + initial_tsn = ntohl(init->initial_tsn); + } else { return NULL; } - } - else { + } else { return NULL; } } - } - else { + } else { DEBUGP("packet->sctp == NULL"); } diff --git a/gtests/net/packetdrill/sctp_packet.c b/gtests/net/packetdrill/sctp_packet.c index 8b74339992a06009fcaaf577669c62fa1ca027e9..7c11497e881f6550805cce8eb55deb411d6a0796 100644 --- a/gtests/net/packetdrill/sctp_packet.c +++ b/gtests/net/packetdrill/sctp_packet.c @@ -2688,5 +2688,6 @@ new_sctp_generic_packet(int address_family, packet->chunk_list = NULL; packet->ip_bytes = ip_bytes; + return packet; -} \ No newline at end of file +} diff --git a/gtests/net/packetdrill/tests/bsd/sctp/sctp_generic.pkt b/gtests/net/packetdrill/tests/bsd/sctp/sctp_generic.pkt index d02d0f73041af7ea7c77dc418d03f238509b9bfd..eff794350f28d3071396f8473f62770d4e620990 100644 --- a/gtests/net/packetdrill/tests/bsd/sctp/sctp_generic.pkt +++ b/gtests/net/packetdrill/tests/bsd/sctp/sctp_generic.pkt @@ -6,10 +6,10 @@ // Trigger the active associtation setup +0.1 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress) +0.0 > sctp: INIT[flgs=0, tag=1, a_rwnd=..., os=..., is=..., tsn=0, ...] -//+0.0 < sctp: INIT_ACK[flgs=0, tag=2, a_rwnd=1500, os=1, is=1, tsn=3, STATE_COOKIE[len=4, val=...]] +//+0.0 < sctp(t, tag=1): INIT_ACK[flgs=0, tag=2, a_rwnd=1500, os=1, is=1, tsn=1, STATE_COOKIE[len=4, val=...]] +0.0 < sctp: [0x02, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x05, 0xDC, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x04] -//+0.0 > sctp: COOKIE_ECHO[flgs=0, len=4, val=...] -+0.0 > sctp: [0x0A, 0x00, 0x00, 0x04] ++0.0 > sctp: COOKIE_ECHO[flgs=0, len=4, val=...] +//+0.0 > sctp(tag=3): [0x0A, 0x00, 0x00, 0x04] +0.0 < sctp: COOKIE_ACK[flgs=0] // Check if the setup was sucessful +0.0 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0