57 static int IPV4OptValidateGeneric(
Packet *p,
const IPV4Opt *o)
123 if (
unlikely((ptr < 4) || (ptr % 4) || (ptr > o->
len + 1))) {
138 static int IPV4OptValidateTimestamp(
Packet *p,
const IPV4Opt *o)
162 flag = *(o->
data + 1) & 0x0f;
165 rec_size = ((flag == 1) || (flag == 3)) ? 8 : 4;
171 if (
unlikely(((ptr - 5) % rec_size) || (ptr > o->
len + 1))) {
260 if (
unlikely((ttype != 7) && (*tag != 0))) {
312 for (i = 0; i <
len; i++) {
332 SCLogDebug(
"IPV4OPT %" PRIu8
" len 1 @ %d/%d",
333 *pkt, (
len - plen), (
len - 1));
337 SCLogDebug(
"IPV4OPT %" PRIu8
" len 1 @ %d/%d",
338 *pkt, (
len - plen), (
len - 1));
359 IPV4Opt opt = {*pkt, *(pkt+1), plen > 2 ? (pkt + 2) : NULL };
377 }
else if (IPV4OptValidateTimestamp(p, &opt) == 0) {
386 }
else if (IPV4OptValidateRoute(p, &opt) == 0) {
395 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
404 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
413 }
else if (IPV4OptValidateRoute(p, &opt) == 0) {
422 }
else if (IPV4OptValidateCIPSO(p, &opt) == 0) {
431 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
440 }
else if (IPV4OptValidateRoute(p, &opt) == 0) {
449 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
455 SCLogDebug(
"IPV4OPT <unknown> (%" PRIu8
") len %" PRIu8,
470 static int DecodeIPV4Packet(
Packet *p,
const uint8_t *pkt, uint16_t
len)
506 if (ip_opt_len > 0) {
508 memset(&opts, 0x00,
sizeof(opts));
509 if (DecodeIPV4Options(p, pkt +
IPV4_HEADER_LEN, ip_opt_len, &opts) < 0) {
518 const uint8_t *pkt, uint16_t
len)
525 if (
unlikely(DecodeIPV4Packet (p, pkt,
len) < 0)) {
550 SCLogDebug(
"IPV4 %s->%s PROTO: %" PRIu32
" OFFSET: %" PRIu32
" RF: %" PRIu32
" DF: %" PRIu32
" MF: %" PRIu32
" ID: %" PRIu32
"", s,d,
615 static int DecodeIPV4OptionsNONETest01(
void)
617 uint8_t raw_opts[] = { };
622 memset(&opts, 0x00,
sizeof(opts));
623 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
631 static int DecodeIPV4OptionsEOLTest01(
void)
633 uint8_t raw_opts[] = {
639 memset(&opts, 0x00,
sizeof(opts));
640 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
647 static int DecodeIPV4OptionsNOPTest01(
void)
649 uint8_t raw_opts[] = {
655 memset(&opts, 0x00,
sizeof(opts));
656 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
663 static int DecodeIPV4OptionsRRTest01(
void)
665 uint8_t raw_opts[] = {
666 IPV4_OPT_RR, 0x27, 0x08, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
667 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
668 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
669 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
670 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
676 memset(&opts, 0x00,
sizeof(opts));
677 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
685 static int DecodeIPV4OptionsRRTest02(
void)
687 uint8_t raw_opts[] = {
688 IPV4_OPT_RR, 0xff, 0x08, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
689 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
690 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
691 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
692 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
698 memset(&opts, 0x00,
sizeof(opts));
699 FAIL_IF(DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts) != -1);
707 static int DecodeIPV4OptionsRRTest03(
void)
709 uint8_t raw_opts[] = {
710 IPV4_OPT_RR, 0x27, 0xff, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
711 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
712 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
713 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
714 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
720 memset(&opts, 0x00,
sizeof(opts));
721 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
729 static int DecodeIPV4OptionsRRTest04(
void)
731 uint8_t raw_opts[] = {
732 IPV4_OPT_RR, 0x27, 0x05, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
733 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
734 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
735 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
736 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
742 memset(&opts, 0x00,
sizeof(opts));
743 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
751 static int DecodeIPV4OptionsQSTest01(
void)
753 uint8_t raw_opts[] = {
754 IPV4_OPT_QS, 0x08, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
760 memset(&opts, 0x00,
sizeof(opts));
761 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
769 static int DecodeIPV4OptionsQSTest02(
void)
771 uint8_t raw_opts[] = {
772 IPV4_OPT_QS, 0x07, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
778 memset(&opts, 0x00,
sizeof(opts));
779 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
787 static int DecodeIPV4OptionsTSTest01(
void)
789 uint8_t raw_opts[] = {
790 IPV4_OPT_TS, 0x24, 0x0d, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
791 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
792 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
793 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
794 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
800 memset(&opts, 0x00,
sizeof(opts));
801 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
809 static int DecodeIPV4OptionsTSTest02(
void)
811 uint8_t raw_opts[] = {
812 IPV4_OPT_TS, 0x24, 0x04, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
813 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
814 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
815 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
816 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
822 memset(&opts, 0x00,
sizeof(opts));
823 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
831 static int DecodeIPV4OptionsTSTest03(
void)
833 uint8_t raw_opts[] = {
834 IPV4_OPT_TS, 0x24, 0xff, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
835 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
836 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
837 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
838 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
844 memset(&opts, 0x00,
sizeof(opts));
845 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
853 static int DecodeIPV4OptionsTSTest04(
void)
855 uint8_t raw_opts[] = {
856 IPV4_OPT_TS, 0x24, 0x0a, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
857 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
858 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
859 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
860 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
866 memset(&opts, 0x00,
sizeof(opts));
867 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
875 static int DecodeIPV4OptionsSECTest01(
void)
877 uint8_t raw_opts[] = {
879 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
885 memset(&opts, 0x00,
sizeof(opts));
886 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
894 static int DecodeIPV4OptionsSECTest02(
void)
896 uint8_t raw_opts[] = {
898 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
904 memset(&opts, 0x00,
sizeof(opts));
905 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
913 static int DecodeIPV4OptionsLSRRTest01(
void)
915 uint8_t raw_opts[] = {
917 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
918 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
919 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
920 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
926 memset(&opts, 0x00,
sizeof(opts));
927 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
935 static int DecodeIPV4OptionsLSRRTest02(
void)
937 uint8_t raw_opts[] = {
939 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
940 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
941 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
942 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
948 memset(&opts, 0x00,
sizeof(opts));
949 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
957 static int DecodeIPV4OptionsLSRRTest03(
void)
959 uint8_t raw_opts[] = {
961 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
962 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
963 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
964 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
970 memset(&opts, 0x00,
sizeof(opts));
971 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
979 static int DecodeIPV4OptionsLSRRTest04(
void)
981 uint8_t raw_opts[] = {
983 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
984 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
985 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
986 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
992 memset(&opts, 0x00,
sizeof(opts));
993 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1001 static int DecodeIPV4OptionsCIPSOTest01(
void)
1003 uint8_t raw_opts[] = {
1005 0x00, 0x03, 0x00, 0xef, 0x00, 0xef, 0x00, 0x06,
1006 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00
1012 memset(&opts, 0x00,
sizeof(opts));
1013 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1021 static int DecodeIPV4OptionsSIDTest01(
void)
1023 uint8_t raw_opts[] = {
1030 memset(&opts, 0x00,
sizeof(opts));
1031 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1039 static int DecodeIPV4OptionsSIDTest02(
void)
1041 uint8_t raw_opts[] = {
1048 memset(&opts, 0x00,
sizeof(opts));
1049 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1057 static int DecodeIPV4OptionsSSRRTest01(
void)
1059 uint8_t raw_opts[] = {
1061 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1062 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1063 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1064 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1070 memset(&opts, 0x00,
sizeof(opts));
1071 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1079 static int DecodeIPV4OptionsSSRRTest02(
void)
1081 uint8_t raw_opts[] = {
1083 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1084 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1085 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1086 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1092 memset(&opts, 0x00,
sizeof(opts));
1093 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1101 static int DecodeIPV4OptionsSSRRTest03(
void)
1103 uint8_t raw_opts[] = {
1105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1114 memset(&opts, 0x00,
sizeof(opts));
1115 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1123 static int DecodeIPV4OptionsSSRRTest04(
void)
1125 uint8_t raw_opts[] = {
1127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1136 memset(&opts, 0x00,
sizeof(opts));
1137 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1145 static int DecodeIPV4OptionsRTRALTTest01(
void)
1147 uint8_t raw_opts[] = {
1154 memset(&opts, 0x00,
sizeof(opts));
1155 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1163 static int DecodeIPV4OptionsRTRALTTest02(
void)
1165 uint8_t raw_opts[] = {
1172 memset(&opts, 0x00,
sizeof(opts));
1173 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1180 static int IPV4CalculateValidChecksumtest01(
void)
1184 uint8_t raw_ipv4[] = {
1185 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1186 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1187 0xc0, 0xa8, 0x01, 0x03};
1189 csum = *( ((uint16_t *)raw_ipv4) + 5);
1191 FAIL_IF(IPV4Checksum((uint16_t *)raw_ipv4,
sizeof(raw_ipv4), csum) != 0);
1195 static int IPV4CalculateInvalidChecksumtest02(
void)
1199 uint8_t raw_ipv4[] = {
1200 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1201 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1202 0xc0, 0xa8, 0x01, 0x07};
1204 csum = *( ((uint16_t *)raw_ipv4) + 5);
1206 FAIL_IF(IPV4Checksum((uint16_t *)raw_ipv4,
sizeof(raw_ipv4), csum) == 0);
1213 static int DecodeIPV4DefragTest01(
void)
1216 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1217 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1218 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1219 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1220 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1224 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1225 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1226 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x01, 0x40, 0x06,
1227 0x9a, 0xc7, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1228 0xe1, 0x0c, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1232 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1233 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1234 0x00, 0x18, 0xe9, 0xef, 0x00, 0x02, 0x40, 0x06,
1235 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1236 0xe1, 0x0c, 0xb1, 0xa3, 0x00, 0x00
1238 uint8_t tunnel_pkt[] = {
1239 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1240 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1241 0x00, 0x28, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1242 0xba, 0xbc, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1243 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1244 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1245 0x80, 0x00, 0xb1, 0xa3, 0x00, 0x00
1264 if (p->
tcph != NULL) {
1265 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1274 if (p->
tcph != NULL) {
1275 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1284 if (p->
tcph != NULL) {
1285 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1291 printf(
"Failed to get defragged pseudo packet\n");
1296 printf(
"defragged pseudo packet's and parent packet's recursion "
1297 "level don't match\n %d != %d",
1302 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1303 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1309 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1310 "don't match\n %u != %"PRIuMAX,
1315 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1335 static int DecodeIPV4DefragTest02(
void)
1338 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1339 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1340 0x00, 0x24, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1341 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1344 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1345 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1349 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1350 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1351 0x00, 0x2c, 0xe9, 0xef, 0x20, 0x02, 0x40, 0x06,
1352 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1355 0xb1, 0xa3, 0x00, 0x10, 0x5b, 0xa3, 0x81, 0x5e,
1356 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1357 0xb1, 0xa3, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04
1360 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1361 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1362 0x00, 0x16, 0xe9, 0xef, 0x00, 0x05, 0x40, 0x06,
1363 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1369 uint8_t tunnel_pkt[] = {
1370 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1371 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1372 0x00, 0x3e, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1373 0xba, 0xae, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1375 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3, 0x81, 0x5e,
1376 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1377 0xb1, 0xa3, 0x00, 0x10, 0x5b, 0xa3, 0x81, 0x5e,
1378 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1379 0xb1, 0xa3, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04,
1399 if (p->
tcph != NULL) {
1400 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1408 if (p->
tcph != NULL) {
1409 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1418 if (p->
tcph != NULL) {
1419 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1424 printf(
"Failed to get defragged pseudo packet\n");
1428 printf(
"defragged pseudo packet's and parent packet's recursion "
1429 "level don't match %d != %d: ",
1433 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1434 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1439 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1440 "don't match %u != %"PRIuMAX
": ",
1445 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1464 static int DecodeIPV4DefragTest03(
void)
1467 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1468 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1469 0x00, 0x28, 0xe9, 0xee, 0x00, 0x00, 0x40, 0x06,
1470 0xba, 0xbd, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1471 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1472 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
1473 0x80, 0x00, 0x0c, 0xee, 0x00, 0x00
1476 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1477 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1478 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1479 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1480 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1484 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1485 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1486 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x01, 0x40, 0x06,
1487 0x9a, 0xc7, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1488 0xe1, 0x0c, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1492 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1493 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1494 0x00, 0x18, 0xe9, 0xef, 0x00, 0x02, 0x40, 0x06,
1495 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1496 0xe1, 0x0c, 0xb1, 0xa3, 0x00, 0x00
1498 uint8_t tunnel_pkt[] = {
1499 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1500 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1501 0x00, 0x28, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1502 0xba, 0xbc, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1503 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1504 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1505 0x80, 0x00, 0xb1, 0xa3, 0x00, 0x00
1524 if (p->
tcph == NULL) {
1525 printf(
"tcp header shouldn't be NULL, but it is\n");
1530 printf(
"packet flow shouldn't be NULL\n");
1539 if (p->
tcph != NULL) {
1540 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1549 if (p->
tcph != NULL) {
1550 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1559 if (p->
tcph != NULL) {
1560 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1567 printf(
"Failed to get defragged pseudo packet\n");
1580 printf(
"defragged pseudo packet's and parent packet's recursion "
1581 "level don't match\n %d != %d",
1586 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1587 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1593 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1594 "don't match\n %u != %"PRIuMAX,
1600 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1618 static int DecodeEthernetTestIPv4Opt(
void)
1620 uint8_t raw_eth[] = {
1621 0xae, 0x71, 0x00, 0x00, 0x00, 0x4b, 0x06, 0x90, 0x61, 0x02, 0x00, 0xcd, 0x88, 0x64, 0x11, 0x00,
1622 0x15, 0x00, 0x80, 0x64, 0x00, 0x21, 0x4c, 0x00, 0x00, 0x30, 0x42, 0xd6, 0xff, 0xff, 0xbd, 0x2f,
1623 0x02, 0x02, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
1624 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
1625 0x01, 0x44, 0x05, 0x22, 0x02, 0x01
1651 UtRegisterTest(
"DecodeIPV4OptionsNONETest01", DecodeIPV4OptionsNONETest01);
1652 UtRegisterTest(
"DecodeIPV4OptionsEOLTest01", DecodeIPV4OptionsEOLTest01);
1653 UtRegisterTest(
"DecodeIPV4OptionsNOPTest01", DecodeIPV4OptionsNOPTest01);
1654 UtRegisterTest(
"DecodeIPV4OptionsRRTest01", DecodeIPV4OptionsRRTest01);
1655 UtRegisterTest(
"DecodeIPV4OptionsRRTest02", DecodeIPV4OptionsRRTest02);
1656 UtRegisterTest(
"DecodeIPV4OptionsRRTest03", DecodeIPV4OptionsRRTest03);
1657 UtRegisterTest(
"DecodeIPV4OptionsRRTest04", DecodeIPV4OptionsRRTest04);
1658 UtRegisterTest(
"DecodeIPV4OptionsQSTest01", DecodeIPV4OptionsQSTest01);
1659 UtRegisterTest(
"DecodeIPV4OptionsQSTest02", DecodeIPV4OptionsQSTest02);
1660 UtRegisterTest(
"DecodeIPV4OptionsTSTest01", DecodeIPV4OptionsTSTest01);
1661 UtRegisterTest(
"DecodeIPV4OptionsTSTest02", DecodeIPV4OptionsTSTest02);
1662 UtRegisterTest(
"DecodeIPV4OptionsTSTest03", DecodeIPV4OptionsTSTest03);
1663 UtRegisterTest(
"DecodeIPV4OptionsTSTest04", DecodeIPV4OptionsTSTest04);
1664 UtRegisterTest(
"DecodeIPV4OptionsSECTest01", DecodeIPV4OptionsSECTest01);
1665 UtRegisterTest(
"DecodeIPV4OptionsSECTest02", DecodeIPV4OptionsSECTest02);
1666 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest01", DecodeIPV4OptionsLSRRTest01);
1667 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest02", DecodeIPV4OptionsLSRRTest02);
1668 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest03", DecodeIPV4OptionsLSRRTest03);
1669 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest04", DecodeIPV4OptionsLSRRTest04);
1671 DecodeIPV4OptionsCIPSOTest01);
1672 UtRegisterTest(
"DecodeIPV4OptionsSIDTest01", DecodeIPV4OptionsSIDTest01);
1673 UtRegisterTest(
"DecodeIPV4OptionsSIDTest02", DecodeIPV4OptionsSIDTest02);
1674 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest01", DecodeIPV4OptionsSSRRTest01);
1675 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest02", DecodeIPV4OptionsSSRRTest02);
1676 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest03", DecodeIPV4OptionsSSRRTest03);
1677 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest04", DecodeIPV4OptionsSSRRTest04);
1679 DecodeIPV4OptionsRTRALTTest01);
1681 DecodeIPV4OptionsRTRALTTest02);
1683 IPV4CalculateValidChecksumtest01);
1685 IPV4CalculateInvalidChecksumtest02);
1686 UtRegisterTest(
"DecodeIPV4DefragTest01", DecodeIPV4DefragTest01);
1687 UtRegisterTest(
"DecodeIPV4DefragTest02", DecodeIPV4DefragTest02);
1688 UtRegisterTest(
"DecodeIPV4DefragTest03", DecodeIPV4DefragTest03);
1689 UtRegisterTest(
"DecodeEthernetTestIPv4Opt", DecodeEthernetTestIPv4Opt);