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))) {
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)
524 if (!PacketIncreaseCheckLayers(p)) {
528 if (
unlikely(DecodeIPV4Packet (p, pkt,
len) < 0)) {
553 SCLogDebug(
"IPV4 %s->%s PROTO: %" PRIu32
" OFFSET: %" PRIu32
" RF: %" PRIu32
" DF: %" PRIu32
" MF: %" PRIu32
" ID: %" PRIu32
"", s,d,
618 static int DecodeIPV4OptionsNONETest01(
void)
620 uint8_t raw_opts[] = { };
625 memset(&opts, 0x00,
sizeof(opts));
626 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
634 static int DecodeIPV4OptionsEOLTest01(
void)
636 uint8_t raw_opts[] = {
642 memset(&opts, 0x00,
sizeof(opts));
643 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
650 static int DecodeIPV4OptionsNOPTest01(
void)
652 uint8_t raw_opts[] = {
658 memset(&opts, 0x00,
sizeof(opts));
659 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
666 static int DecodeIPV4OptionsRRTest01(
void)
668 uint8_t raw_opts[] = {
669 IPV4_OPT_RR, 0x27, 0x08, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
670 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
671 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
672 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
673 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
679 memset(&opts, 0x00,
sizeof(opts));
680 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
688 static int DecodeIPV4OptionsRRTest02(
void)
690 uint8_t raw_opts[] = {
691 IPV4_OPT_RR, 0xff, 0x08, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
692 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
693 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
694 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
695 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
701 memset(&opts, 0x00,
sizeof(opts));
702 FAIL_IF(DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts) != -1);
710 static int DecodeIPV4OptionsRRTest03(
void)
712 uint8_t raw_opts[] = {
713 IPV4_OPT_RR, 0x27, 0xff, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
714 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
715 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
716 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
717 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
723 memset(&opts, 0x00,
sizeof(opts));
724 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
732 static int DecodeIPV4OptionsRRTest04(
void)
734 uint8_t raw_opts[] = {
735 IPV4_OPT_RR, 0x27, 0x05, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
736 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
737 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
738 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
739 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
745 memset(&opts, 0x00,
sizeof(opts));
746 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
754 static int DecodeIPV4OptionsQSTest01(
void)
756 uint8_t raw_opts[] = {
757 IPV4_OPT_QS, 0x08, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
763 memset(&opts, 0x00,
sizeof(opts));
764 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
772 static int DecodeIPV4OptionsQSTest02(
void)
774 uint8_t raw_opts[] = {
775 IPV4_OPT_QS, 0x07, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
781 memset(&opts, 0x00,
sizeof(opts));
782 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
790 static int DecodeIPV4OptionsTSTest01(
void)
792 uint8_t raw_opts[] = {
793 IPV4_OPT_TS, 0x24, 0x0d, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
794 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
795 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
796 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
797 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
803 memset(&opts, 0x00,
sizeof(opts));
804 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
812 static int DecodeIPV4OptionsTSTest02(
void)
814 uint8_t raw_opts[] = {
815 IPV4_OPT_TS, 0x24, 0x04, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
816 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
817 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
818 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
819 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
825 memset(&opts, 0x00,
sizeof(opts));
826 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
834 static int DecodeIPV4OptionsTSTest03(
void)
836 uint8_t raw_opts[] = {
837 IPV4_OPT_TS, 0x24, 0xff, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
838 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
839 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
840 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
841 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
847 memset(&opts, 0x00,
sizeof(opts));
848 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
856 static int DecodeIPV4OptionsTSTest04(
void)
858 uint8_t raw_opts[] = {
859 IPV4_OPT_TS, 0x24, 0x0a, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
860 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
861 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
862 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
863 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
869 memset(&opts, 0x00,
sizeof(opts));
870 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
878 static int DecodeIPV4OptionsSECTest01(
void)
880 uint8_t raw_opts[] = {
882 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
888 memset(&opts, 0x00,
sizeof(opts));
889 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
897 static int DecodeIPV4OptionsSECTest02(
void)
899 uint8_t raw_opts[] = {
901 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
907 memset(&opts, 0x00,
sizeof(opts));
908 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
916 static int DecodeIPV4OptionsLSRRTest01(
void)
918 uint8_t raw_opts[] = {
920 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
921 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
922 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
923 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
929 memset(&opts, 0x00,
sizeof(opts));
930 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
938 static int DecodeIPV4OptionsLSRRTest02(
void)
940 uint8_t raw_opts[] = {
942 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
943 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
944 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
945 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
951 memset(&opts, 0x00,
sizeof(opts));
952 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
960 static int DecodeIPV4OptionsLSRRTest03(
void)
962 uint8_t raw_opts[] = {
964 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
965 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
966 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
967 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
973 memset(&opts, 0x00,
sizeof(opts));
974 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
982 static int DecodeIPV4OptionsLSRRTest04(
void)
984 uint8_t raw_opts[] = {
986 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
987 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
988 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
989 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
995 memset(&opts, 0x00,
sizeof(opts));
996 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1004 static int DecodeIPV4OptionsCIPSOTest01(
void)
1006 uint8_t raw_opts[] = {
1008 0x00, 0x03, 0x00, 0xef, 0x00, 0xef, 0x00, 0x06,
1009 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00
1015 memset(&opts, 0x00,
sizeof(opts));
1016 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1024 static int DecodeIPV4OptionsSIDTest01(
void)
1026 uint8_t raw_opts[] = {
1033 memset(&opts, 0x00,
sizeof(opts));
1034 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1042 static int DecodeIPV4OptionsSIDTest02(
void)
1044 uint8_t raw_opts[] = {
1051 memset(&opts, 0x00,
sizeof(opts));
1052 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1060 static int DecodeIPV4OptionsSSRRTest01(
void)
1062 uint8_t raw_opts[] = {
1064 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1065 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1066 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1067 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1073 memset(&opts, 0x00,
sizeof(opts));
1074 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1082 static int DecodeIPV4OptionsSSRRTest02(
void)
1084 uint8_t raw_opts[] = {
1086 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1087 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1088 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1089 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1095 memset(&opts, 0x00,
sizeof(opts));
1096 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1104 static int DecodeIPV4OptionsSSRRTest03(
void)
1106 uint8_t raw_opts[] = {
1108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1109 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1117 memset(&opts, 0x00,
sizeof(opts));
1118 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1126 static int DecodeIPV4OptionsSSRRTest04(
void)
1128 uint8_t raw_opts[] = {
1130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1139 memset(&opts, 0x00,
sizeof(opts));
1140 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1148 static int DecodeIPV4OptionsRTRALTTest01(
void)
1150 uint8_t raw_opts[] = {
1157 memset(&opts, 0x00,
sizeof(opts));
1158 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1166 static int DecodeIPV4OptionsRTRALTTest02(
void)
1168 uint8_t raw_opts[] = {
1175 memset(&opts, 0x00,
sizeof(opts));
1176 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1183 static int IPV4CalculateValidChecksumtest01(
void)
1187 uint8_t raw_ipv4[] = {
1188 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1189 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1190 0xc0, 0xa8, 0x01, 0x03};
1192 csum = *( ((uint16_t *)raw_ipv4) + 5);
1194 FAIL_IF(IPV4Checksum((uint16_t *)raw_ipv4,
sizeof(raw_ipv4), csum) != 0);
1198 static int IPV4CalculateInvalidChecksumtest02(
void)
1202 uint8_t raw_ipv4[] = {
1203 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1204 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1205 0xc0, 0xa8, 0x01, 0x07};
1207 csum = *( ((uint16_t *)raw_ipv4) + 5);
1209 FAIL_IF(IPV4Checksum((uint16_t *)raw_ipv4,
sizeof(raw_ipv4), csum) == 0);
1216 static int DecodeIPV4DefragTest01(
void)
1219 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1220 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1221 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1222 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1223 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1227 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1228 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1229 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x01, 0x40, 0x06,
1230 0x9a, 0xc7, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1231 0xe1, 0x0c, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1235 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1236 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1237 0x00, 0x18, 0xe9, 0xef, 0x00, 0x02, 0x40, 0x06,
1238 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1239 0xe1, 0x0c, 0xb1, 0xa3, 0x00, 0x00
1241 uint8_t tunnel_pkt[] = {
1242 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1243 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1244 0x00, 0x28, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1245 0xba, 0xbc, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1246 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1247 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1248 0x80, 0x00, 0xb1, 0xa3, 0x00, 0x00
1267 if (p->
tcph != NULL) {
1268 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1277 if (p->
tcph != NULL) {
1278 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1287 if (p->
tcph != NULL) {
1288 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1294 printf(
"Failed to get defragged pseudo packet\n");
1299 printf(
"defragged pseudo packet's and parent packet's recursion "
1300 "level don't match\n %d != %d",
1305 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1306 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1312 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1313 "don't match\n %u != %"PRIuMAX,
1318 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1338 static int DecodeIPV4DefragTest02(
void)
1341 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1342 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1343 0x00, 0x24, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1344 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1347 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1348 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1352 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1353 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1354 0x00, 0x2c, 0xe9, 0xef, 0x20, 0x02, 0x40, 0x06,
1355 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1358 0xb1, 0xa3, 0x00, 0x10, 0x5b, 0xa3, 0x81, 0x5e,
1359 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1360 0xb1, 0xa3, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04
1363 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1364 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1365 0x00, 0x16, 0xe9, 0xef, 0x00, 0x05, 0x40, 0x06,
1366 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1372 uint8_t tunnel_pkt[] = {
1373 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1374 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1375 0x00, 0x3e, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1376 0xba, 0xae, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1378 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3, 0x81, 0x5e,
1379 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1380 0xb1, 0xa3, 0x00, 0x10, 0x5b, 0xa3, 0x81, 0x5e,
1381 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1382 0xb1, 0xa3, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04,
1402 if (p->
tcph != NULL) {
1403 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1411 if (p->
tcph != NULL) {
1412 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1421 if (p->
tcph != NULL) {
1422 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1427 printf(
"Failed to get defragged pseudo packet\n");
1431 printf(
"defragged pseudo packet's and parent packet's recursion "
1432 "level don't match %d != %d: ",
1436 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1437 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1442 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1443 "don't match %u != %"PRIuMAX
": ",
1448 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1467 static int DecodeIPV4DefragTest03(
void)
1470 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1471 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1472 0x00, 0x28, 0xe9, 0xee, 0x00, 0x00, 0x40, 0x06,
1473 0xba, 0xbd, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1474 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1475 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
1476 0x80, 0x00, 0x0c, 0xee, 0x00, 0x00
1479 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1480 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1481 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1482 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1483 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1487 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1488 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1489 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x01, 0x40, 0x06,
1490 0x9a, 0xc7, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1491 0xe1, 0x0c, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1495 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1496 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1497 0x00, 0x18, 0xe9, 0xef, 0x00, 0x02, 0x40, 0x06,
1498 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1499 0xe1, 0x0c, 0xb1, 0xa3, 0x00, 0x00
1501 uint8_t tunnel_pkt[] = {
1502 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1503 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1504 0x00, 0x28, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1505 0xba, 0xbc, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1506 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1507 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1508 0x80, 0x00, 0xb1, 0xa3, 0x00, 0x00
1527 if (p->
tcph == NULL) {
1528 printf(
"tcp header shouldn't be NULL, but it is\n");
1533 printf(
"packet flow shouldn't be NULL\n");
1542 if (p->
tcph != NULL) {
1543 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1552 if (p->
tcph != NULL) {
1553 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1562 if (p->
tcph != NULL) {
1563 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1570 printf(
"Failed to get defragged pseudo packet\n");
1583 printf(
"defragged pseudo packet's and parent packet's recursion "
1584 "level don't match\n %d != %d",
1589 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1590 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1596 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1597 "don't match\n %u != %"PRIuMAX,
1603 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1621 static int DecodeEthernetTestIPv4Opt(
void)
1623 uint8_t raw_eth[] = {
1624 0xae, 0x71, 0x00, 0x00, 0x00, 0x4b, 0x06, 0x90, 0x61, 0x02, 0x00, 0xcd, 0x88, 0x64, 0x11, 0x00,
1625 0x15, 0x00, 0x80, 0x64, 0x00, 0x21, 0x4c, 0x00, 0x00, 0x30, 0x42, 0xd6, 0xff, 0xff, 0xbd, 0x2f,
1626 0x02, 0x02, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
1627 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
1628 0x01, 0x44, 0x05, 0x22, 0x02, 0x01
1653 UtRegisterTest(
"DecodeIPV4OptionsNONETest01", DecodeIPV4OptionsNONETest01);
1654 UtRegisterTest(
"DecodeIPV4OptionsEOLTest01", DecodeIPV4OptionsEOLTest01);
1655 UtRegisterTest(
"DecodeIPV4OptionsNOPTest01", DecodeIPV4OptionsNOPTest01);
1656 UtRegisterTest(
"DecodeIPV4OptionsRRTest01", DecodeIPV4OptionsRRTest01);
1657 UtRegisterTest(
"DecodeIPV4OptionsRRTest02", DecodeIPV4OptionsRRTest02);
1658 UtRegisterTest(
"DecodeIPV4OptionsRRTest03", DecodeIPV4OptionsRRTest03);
1659 UtRegisterTest(
"DecodeIPV4OptionsRRTest04", DecodeIPV4OptionsRRTest04);
1660 UtRegisterTest(
"DecodeIPV4OptionsQSTest01", DecodeIPV4OptionsQSTest01);
1661 UtRegisterTest(
"DecodeIPV4OptionsQSTest02", DecodeIPV4OptionsQSTest02);
1662 UtRegisterTest(
"DecodeIPV4OptionsTSTest01", DecodeIPV4OptionsTSTest01);
1663 UtRegisterTest(
"DecodeIPV4OptionsTSTest02", DecodeIPV4OptionsTSTest02);
1664 UtRegisterTest(
"DecodeIPV4OptionsTSTest03", DecodeIPV4OptionsTSTest03);
1665 UtRegisterTest(
"DecodeIPV4OptionsTSTest04", DecodeIPV4OptionsTSTest04);
1666 UtRegisterTest(
"DecodeIPV4OptionsSECTest01", DecodeIPV4OptionsSECTest01);
1667 UtRegisterTest(
"DecodeIPV4OptionsSECTest02", DecodeIPV4OptionsSECTest02);
1668 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest01", DecodeIPV4OptionsLSRRTest01);
1669 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest02", DecodeIPV4OptionsLSRRTest02);
1670 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest03", DecodeIPV4OptionsLSRRTest03);
1671 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest04", DecodeIPV4OptionsLSRRTest04);
1673 DecodeIPV4OptionsCIPSOTest01);
1674 UtRegisterTest(
"DecodeIPV4OptionsSIDTest01", DecodeIPV4OptionsSIDTest01);
1675 UtRegisterTest(
"DecodeIPV4OptionsSIDTest02", DecodeIPV4OptionsSIDTest02);
1676 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest01", DecodeIPV4OptionsSSRRTest01);
1677 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest02", DecodeIPV4OptionsSSRRTest02);
1678 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest03", DecodeIPV4OptionsSSRRTest03);
1679 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest04", DecodeIPV4OptionsSSRRTest04);
1681 DecodeIPV4OptionsRTRALTTest01);
1683 DecodeIPV4OptionsRTRALTTest02);
1685 IPV4CalculateValidChecksumtest01);
1687 IPV4CalculateInvalidChecksumtest02);
1688 UtRegisterTest(
"DecodeIPV4DefragTest01", DecodeIPV4DefragTest01);
1689 UtRegisterTest(
"DecodeIPV4DefragTest02", DecodeIPV4DefragTest02);
1690 UtRegisterTest(
"DecodeIPV4DefragTest03", DecodeIPV4DefragTest03);
1691 UtRegisterTest(
"DecodeEthernetTestIPv4Opt", DecodeEthernetTestIPv4Opt);