56 static int DecodeSCTPChunks(
Packet *
p,
const uint8_t *pkt, uint16_t
len)
58 const SCTPHdr *sctph = PacketGetSCTP(
p);
61 uint16_t chunk_cnt = 0;
62 uint8_t tracked_chunk_cnt = 0;
63 bool has_init =
false;
64 bool has_init_ack =
false;
65 bool has_data =
false;
66 bool has_abort =
false;
67 uint8_t data_chunk_cnt = 0;
79 memcpy(&chunk, pkt +
offset,
sizeof(chunk));
80 const uint16_t chunk_len =
SCNtohs(chunk.length);
104 switch (chunk.type) {
139 uint32_t padded_len = (chunk_len + 3) & ~3U;
149 if ((has_init || has_init_ack) && chunk_cnt > 1) {
174 const SCTPHdr *sctph = PacketSetSCTP(
p, pkt);
242 static int SCTPDecodeValidInitTest01(
void)
248 uint8_t raw_sctp[] = {
249 0x04, 0xd2, 0x00, 0x50,
250 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00,
252 0x01, 0x00, 0x00, 0x14,
253 0x00, 0x00, 0x00, 0x01,
254 0x00, 0x01, 0x00, 0x00,
255 0x00, 0x01, 0x00, 0x01,
256 0x00, 0x00, 0x00, 0x01,
290 static int SCTPDecodePktTooSmallTest02(
void)
292 uint8_t raw_sctp[] = { 0x04, 0xd2, 0x00, 0x50, 0x00, 0x00 };
313 static int SCTPDecodeChunkTooSmallTest03(
void)
316 uint8_t raw_sctp[] = {
317 0x04, 0xd2, 0x00, 0x50,
318 0x00, 0x00, 0x00, 0x01,
319 0x00, 0x00, 0x00, 0x00,
343 static int SCTPDecodeChunkLenInvalidTest04(
void)
346 uint8_t raw_sctp[] = {
347 0x04, 0xd2, 0x00, 0x50,
348 0x00, 0x00, 0x00, 0x01,
349 0x00, 0x00, 0x00, 0x00,
350 0x00, 0x00, 0x00, 0x02,
373 static int SCTPDecodeInitNonZeroVtagTest05(
void)
376 uint8_t raw_sctp[] = {
377 0x04, 0xd2, 0x00, 0x50,
378 0x00, 0x00, 0x00, 0x42,
379 0x00, 0x00, 0x00, 0x00,
380 0x01, 0x00, 0x00, 0x14,
381 0x00, 0x00, 0x00, 0x01,
382 0x00, 0x01, 0x00, 0x00,
383 0x00, 0x01, 0x00, 0x01,
384 0x00, 0x00, 0x00, 0x01,
407 static int SCTPDecodeMultiChunkTest06(
void)
410 uint8_t raw_sctp[] = {
411 0x04, 0xd2, 0x00, 0x50,
412 0x00, 0x00, 0x00, 0x01,
413 0x00, 0x00, 0x00, 0x00,
415 0x00, 0x03, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00,
416 0x00, 0x01, 0x00, 0x00,
417 0x00, 0x00, 0x00, 0x00,
418 0x41, 0x42, 0x43, 0x44,
420 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01,
421 0x00, 0x01, 0x00, 0x00,
422 0x00, 0x00, 0x00, 0x00,
450 static int SCTPDecodeInitNotAloneTest07(
void)
453 uint8_t raw_sctp[] = {
454 0x04, 0xd2, 0x00, 0x50,
455 0x00, 0x00, 0x00, 0x00,
456 0x00, 0x00, 0x00, 0x00,
458 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
459 0x00, 0x01, 0x00, 0x00,
460 0x00, 0x01, 0x00, 0x01,
461 0x00, 0x00, 0x00, 0x01,
463 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
464 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
488 static int SCTPDecodeDataPayloadTest08(
void)
491 uint8_t raw_sctp[] = {
492 0x04, 0xd2, 0x00, 0x50,
493 0x00, 0x00, 0x00, 0x01,
494 0x00, 0x00, 0x00, 0x00,
496 0x00, 0x03, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
497 0x00, 0x01, 0x00, 0x00,
498 0x00, 0x00, 0x00, 0x00,
499 0x41, 0x42, 0x43, 0x44,
524 static int SCTPDecodeNoDataPayloadTest09(
void)
527 uint8_t raw_sctp[] = {
528 0x04, 0xd2, 0x00, 0x50,
529 0x00, 0x00, 0x00, 0x00,
530 0x00, 0x00, 0x00, 0x00,
531 0x01, 0x00, 0x00, 0x14,
532 0x00, 0x00, 0x00, 0x01,
533 0x00, 0x01, 0x00, 0x00,
534 0x00, 0x01, 0x00, 0x01,
535 0x00, 0x00, 0x00, 0x01,
559 static int SCTPDecodeDataOffsetTest10(
void)
562 uint8_t raw_sctp[] = {
563 0x04, 0xd2, 0x00, 0x50,
564 0x00, 0x00, 0x00, 0x01,
565 0x00, 0x00, 0x00, 0x00,
567 0x00, 0x03, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
568 0x00, 0x01, 0x00, 0x00,
569 0x00, 0x00, 0x00, 0x00,
570 0x41, 0x42, 0x43, 0x44,
597 static int SCTPDecodeMultiDataTest11(
void)
600 uint8_t raw_sctp[] = {
601 0x04, 0xd2, 0x00, 0x50,
602 0x00, 0x00, 0x00, 0x01,
603 0x00, 0x00, 0x00, 0x00,
605 0x00, 0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
606 0x00, 0x01, 0x00, 0x00,
607 0x00, 0x00, 0x00, 0x00,
608 0x41, 0x42, 0x43, 0x44,
610 0x00, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0x02,
611 0x00, 0x01, 0x00, 0x01,
612 0x00, 0x00, 0x00, 0x00,
613 0x45, 0x46, 0x47, 0x48,
647 static int SCTPDecodeSmallDataChunkTest12(
void)
650 uint8_t raw_sctp[] = {
651 0x04, 0xd2, 0x00, 0x50,
652 0x00, 0x00, 0x00, 0x01,
653 0x00, 0x00, 0x00, 0x00,
655 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
685 UtRegisterTest(
"SCTPDecodeValidInitTest01", SCTPDecodeValidInitTest01);
686 UtRegisterTest(
"SCTPDecodePktTooSmallTest02", SCTPDecodePktTooSmallTest02);
687 UtRegisterTest(
"SCTPDecodeChunkTooSmallTest03", SCTPDecodeChunkTooSmallTest03);
688 UtRegisterTest(
"SCTPDecodeChunkLenInvalidTest04", SCTPDecodeChunkLenInvalidTest04);
689 UtRegisterTest(
"SCTPDecodeInitNonZeroVtagTest05", SCTPDecodeInitNonZeroVtagTest05);
690 UtRegisterTest(
"SCTPDecodeMultiChunkTest06", SCTPDecodeMultiChunkTest06);
691 UtRegisterTest(
"SCTPDecodeInitNotAloneTest07", SCTPDecodeInitNotAloneTest07);
692 UtRegisterTest(
"SCTPDecodeDataPayloadTest08", SCTPDecodeDataPayloadTest08);
693 UtRegisterTest(
"SCTPDecodeNoDataPayloadTest09", SCTPDecodeNoDataPayloadTest09);
694 UtRegisterTest(
"SCTPDecodeDataOffsetTest10", SCTPDecodeDataOffsetTest10);
695 UtRegisterTest(
"SCTPDecodeMultiDataTest11", SCTPDecodeMultiDataTest11);
696 UtRegisterTest(
"SCTPDecodeSmallDataChunkTest12", SCTPDecodeSmallDataChunkTest12);