54 static int DecodeSCTPChunks(
Packet *
p,
const uint8_t *pkt, uint16_t
len)
56 const SCTPHdr *sctph = PacketGetSCTP(
p);
59 uint16_t chunk_cnt = 0;
60 uint8_t tracked_chunk_cnt = 0;
61 bool has_init =
false;
62 bool has_init_ack =
false;
63 bool has_data =
false;
64 bool has_abort =
false;
65 uint8_t data_chunk_cnt = 0;
77 memcpy(&chunk, pkt +
offset,
sizeof(chunk));
78 const uint16_t chunk_len =
SCNtohs(chunk.length);
102 switch (chunk.type) {
137 uint32_t padded_len = (chunk_len + 3) & ~3U;
147 if ((has_init || has_init_ack) && chunk_cnt > 1) {
172 const SCTPHdr *sctph = PacketSetSCTP(
p, pkt);
240 static int SCTPDecodeValidInitTest01(
void)
246 uint8_t raw_sctp[] = {
247 0x04, 0xd2, 0x00, 0x50,
248 0x00, 0x00, 0x00, 0x00,
249 0x00, 0x00, 0x00, 0x00,
250 0x01, 0x00, 0x00, 0x14,
251 0x00, 0x00, 0x00, 0x01,
252 0x00, 0x01, 0x00, 0x00,
253 0x00, 0x01, 0x00, 0x01,
254 0x00, 0x00, 0x00, 0x01,
288 static int SCTPDecodePktTooSmallTest02(
void)
290 uint8_t raw_sctp[] = { 0x04, 0xd2, 0x00, 0x50, 0x00, 0x00 };
311 static int SCTPDecodeChunkTooSmallTest03(
void)
314 uint8_t raw_sctp[] = {
315 0x04, 0xd2, 0x00, 0x50,
316 0x00, 0x00, 0x00, 0x01,
317 0x00, 0x00, 0x00, 0x00,
341 static int SCTPDecodeChunkLenInvalidTest04(
void)
344 uint8_t raw_sctp[] = {
345 0x04, 0xd2, 0x00, 0x50,
346 0x00, 0x00, 0x00, 0x01,
347 0x00, 0x00, 0x00, 0x00,
348 0x00, 0x00, 0x00, 0x02,
371 static int SCTPDecodeInitNonZeroVtagTest05(
void)
374 uint8_t raw_sctp[] = {
375 0x04, 0xd2, 0x00, 0x50,
376 0x00, 0x00, 0x00, 0x42,
377 0x00, 0x00, 0x00, 0x00,
378 0x01, 0x00, 0x00, 0x14,
379 0x00, 0x00, 0x00, 0x01,
380 0x00, 0x01, 0x00, 0x00,
381 0x00, 0x01, 0x00, 0x01,
382 0x00, 0x00, 0x00, 0x01,
405 static int SCTPDecodeMultiChunkTest06(
void)
408 uint8_t raw_sctp[] = {
409 0x04, 0xd2, 0x00, 0x50,
410 0x00, 0x00, 0x00, 0x01,
411 0x00, 0x00, 0x00, 0x00,
413 0x00, 0x03, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00,
414 0x00, 0x01, 0x00, 0x00,
415 0x00, 0x00, 0x00, 0x00,
416 0x41, 0x42, 0x43, 0x44,
418 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01,
419 0x00, 0x01, 0x00, 0x00,
420 0x00, 0x00, 0x00, 0x00,
448 static int SCTPDecodeInitNotAloneTest07(
void)
451 uint8_t raw_sctp[] = {
452 0x04, 0xd2, 0x00, 0x50,
453 0x00, 0x00, 0x00, 0x00,
454 0x00, 0x00, 0x00, 0x00,
456 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
457 0x00, 0x01, 0x00, 0x00,
458 0x00, 0x01, 0x00, 0x01,
459 0x00, 0x00, 0x00, 0x01,
461 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
462 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
486 static int SCTPDecodeDataPayloadTest08(
void)
489 uint8_t raw_sctp[] = {
490 0x04, 0xd2, 0x00, 0x50,
491 0x00, 0x00, 0x00, 0x01,
492 0x00, 0x00, 0x00, 0x00,
494 0x00, 0x03, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
495 0x00, 0x01, 0x00, 0x00,
496 0x00, 0x00, 0x00, 0x00,
497 0x41, 0x42, 0x43, 0x44,
522 static int SCTPDecodeNoDataPayloadTest09(
void)
525 uint8_t raw_sctp[] = {
526 0x04, 0xd2, 0x00, 0x50,
527 0x00, 0x00, 0x00, 0x00,
528 0x00, 0x00, 0x00, 0x00,
529 0x01, 0x00, 0x00, 0x14,
530 0x00, 0x00, 0x00, 0x01,
531 0x00, 0x01, 0x00, 0x00,
532 0x00, 0x01, 0x00, 0x01,
533 0x00, 0x00, 0x00, 0x01,
557 static int SCTPDecodeDataOffsetTest10(
void)
560 uint8_t raw_sctp[] = {
561 0x04, 0xd2, 0x00, 0x50,
562 0x00, 0x00, 0x00, 0x01,
563 0x00, 0x00, 0x00, 0x00,
565 0x00, 0x03, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
566 0x00, 0x01, 0x00, 0x00,
567 0x00, 0x00, 0x00, 0x00,
568 0x41, 0x42, 0x43, 0x44,
595 static int SCTPDecodeMultiDataTest11(
void)
598 uint8_t raw_sctp[] = {
599 0x04, 0xd2, 0x00, 0x50,
600 0x00, 0x00, 0x00, 0x01,
601 0x00, 0x00, 0x00, 0x00,
603 0x00, 0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
604 0x00, 0x01, 0x00, 0x00,
605 0x00, 0x00, 0x00, 0x00,
606 0x41, 0x42, 0x43, 0x44,
608 0x00, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0x02,
609 0x00, 0x01, 0x00, 0x01,
610 0x00, 0x00, 0x00, 0x00,
611 0x45, 0x46, 0x47, 0x48,
645 static int SCTPDecodeSmallDataChunkTest12(
void)
648 uint8_t raw_sctp[] = {
649 0x04, 0xd2, 0x00, 0x50,
650 0x00, 0x00, 0x00, 0x01,
651 0x00, 0x00, 0x00, 0x00,
653 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
683 UtRegisterTest(
"SCTPDecodeValidInitTest01", SCTPDecodeValidInitTest01);
684 UtRegisterTest(
"SCTPDecodePktTooSmallTest02", SCTPDecodePktTooSmallTest02);
685 UtRegisterTest(
"SCTPDecodeChunkTooSmallTest03", SCTPDecodeChunkTooSmallTest03);
686 UtRegisterTest(
"SCTPDecodeChunkLenInvalidTest04", SCTPDecodeChunkLenInvalidTest04);
687 UtRegisterTest(
"SCTPDecodeInitNonZeroVtagTest05", SCTPDecodeInitNonZeroVtagTest05);
688 UtRegisterTest(
"SCTPDecodeMultiChunkTest06", SCTPDecodeMultiChunkTest06);
689 UtRegisterTest(
"SCTPDecodeInitNotAloneTest07", SCTPDecodeInitNotAloneTest07);
690 UtRegisterTest(
"SCTPDecodeDataPayloadTest08", SCTPDecodeDataPayloadTest08);
691 UtRegisterTest(
"SCTPDecodeNoDataPayloadTest09", SCTPDecodeNoDataPayloadTest09);
692 UtRegisterTest(
"SCTPDecodeDataOffsetTest10", SCTPDecodeDataOffsetTest10);
693 UtRegisterTest(
"SCTPDecodeMultiDataTest11", SCTPDecodeMultiDataTest11);
694 UtRegisterTest(
"SCTPDecodeSmallDataChunkTest12", SCTPDecodeSmallDataChunkTest12);