49 static int IPV4OptValidateGeneric(
Packet *p,
const IPV4Opt *o)
116 if (
unlikely((ptr < 4) || (ptr % 4) || (ptr > o->
len + 1))) {
131 static int IPV4OptValidateTimestamp(
Packet *p,
const IPV4Opt *o)
155 flag = *(o->
data + 1) & 0x0f;
158 rec_size = ((flag == 1) || (flag == 3)) ? 8 : 4;
164 if (
unlikely(((ptr - 5) % rec_size) || (ptr > o->
len + 1))) {
306 for (i = 0; i <
len; i++) {
326 SCLogDebug(
"IPV4OPT %" PRIu8
" len 1 @ %d/%d",
327 *pkt, (
len - plen), (
len - 1));
331 SCLogDebug(
"IPV4OPT %" PRIu8
" len 1 @ %d/%d",
332 *pkt, (
len - plen), (
len - 1));
353 IPV4Opt opt = {*pkt, *(pkt+1), plen > 2 ? (pkt + 2) : NULL };
371 }
else if (IPV4OptValidateTimestamp(p, &opt) == 0) {
380 }
else if (IPV4OptValidateRoute(p, &opt) == 0) {
389 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
398 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
407 }
else if (IPV4OptValidateRoute(p, &opt) == 0) {
416 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
425 }
else if (IPV4OptValidateCIPSO(p, &opt) == 0) {
434 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
443 }
else if (IPV4OptValidateRoute(p, &opt) == 0) {
452 }
else if (IPV4OptValidateGeneric(p, &opt) == 0) {
458 SCLogDebug(
"IPV4OPT <unknown> (%" PRIu8
") len %" PRIu8,
473 static int DecodeIPV4Packet(
Packet *p,
const uint8_t *pkt, uint16_t
len)
509 if (ip_opt_len > 0) {
511 memset(&opts, 0x00,
sizeof(opts));
512 if (DecodeIPV4Options(p, pkt +
IPV4_HEADER_LEN, ip_opt_len, &opts) < 0) {
521 const uint8_t *pkt, uint16_t
len)
527 if (!PacketIncreaseCheckLayers(p)) {
531 if (
unlikely(DecodeIPV4Packet (p, pkt,
len) < 0)) {
556 SCLogDebug(
"IPV4 %s->%s PROTO: %" PRIu32
" OFFSET: %" PRIu32
" RF: %" PRIu32
" DF: %" PRIu32
" MF: %" PRIu32
" ID: %" PRIu32
"", s,d,
622 static int DecodeIPV4OptionsNONETest01(
void)
624 uint8_t raw_opts[] = { };
629 memset(&opts, 0x00,
sizeof(opts));
630 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
638 static int DecodeIPV4OptionsEOLTest01(
void)
640 uint8_t raw_opts[] = {
646 memset(&opts, 0x00,
sizeof(opts));
647 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
654 static int DecodeIPV4OptionsNOPTest01(
void)
656 uint8_t raw_opts[] = {
662 memset(&opts, 0x00,
sizeof(opts));
663 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
670 static int DecodeIPV4OptionsRRTest01(
void)
672 uint8_t raw_opts[] = {
673 IPV4_OPT_RR, 0x27, 0x08, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
674 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
675 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
676 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
677 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
683 memset(&opts, 0x00,
sizeof(opts));
684 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
692 static int DecodeIPV4OptionsRRTest02(
void)
694 uint8_t raw_opts[] = {
695 IPV4_OPT_RR, 0xff, 0x08, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
696 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
697 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
698 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
699 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
705 memset(&opts, 0x00,
sizeof(opts));
706 FAIL_IF(DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts) != -1);
714 static int DecodeIPV4OptionsRRTest03(
void)
716 uint8_t raw_opts[] = {
717 IPV4_OPT_RR, 0x27, 0xff, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
718 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
719 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
720 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
721 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
727 memset(&opts, 0x00,
sizeof(opts));
728 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
736 static int DecodeIPV4OptionsRRTest04(
void)
738 uint8_t raw_opts[] = {
739 IPV4_OPT_RR, 0x27, 0x05, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
740 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
741 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
742 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
743 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
749 memset(&opts, 0x00,
sizeof(opts));
750 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
758 static int DecodeIPV4OptionsQSTest01(
void)
760 uint8_t raw_opts[] = {
761 IPV4_OPT_QS, 0x08, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
767 memset(&opts, 0x00,
sizeof(opts));
768 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
776 static int DecodeIPV4OptionsQSTest02(
void)
778 uint8_t raw_opts[] = {
779 IPV4_OPT_QS, 0x07, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
785 memset(&opts, 0x00,
sizeof(opts));
786 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
794 static int DecodeIPV4OptionsTSTest01(
void)
796 uint8_t raw_opts[] = {
797 IPV4_OPT_TS, 0x24, 0x0d, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
798 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
799 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
800 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
801 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
807 memset(&opts, 0x00,
sizeof(opts));
808 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
816 static int DecodeIPV4OptionsTSTest02(
void)
818 uint8_t raw_opts[] = {
819 IPV4_OPT_TS, 0x24, 0x04, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
820 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
821 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
822 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
823 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
829 memset(&opts, 0x00,
sizeof(opts));
830 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
838 static int DecodeIPV4OptionsTSTest03(
void)
840 uint8_t raw_opts[] = {
841 IPV4_OPT_TS, 0x24, 0xff, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
842 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
843 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
844 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
845 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
851 memset(&opts, 0x00,
sizeof(opts));
852 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
860 static int DecodeIPV4OptionsTSTest04(
void)
862 uint8_t raw_opts[] = {
863 IPV4_OPT_TS, 0x24, 0x0a, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
864 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
865 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
866 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
867 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
873 memset(&opts, 0x00,
sizeof(opts));
874 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
882 static int DecodeIPV4OptionsSECTest01(
void)
884 uint8_t raw_opts[] = {
886 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
892 memset(&opts, 0x00,
sizeof(opts));
893 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
901 static int DecodeIPV4OptionsSECTest02(
void)
903 uint8_t raw_opts[] = {
IPV4_OPT_SEC, 0x02, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
904 0x00, 0x00, 0x00, 0x00, 0x00 };
909 memset(&opts, 0x00,
sizeof(opts));
910 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
918 static int DecodeIPV4OptionsESECTest01(
void)
920 uint8_t raw_opts[] = {
IPV4_OPT_ESEC, 0x0b, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
921 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 DecodeIPV4OptionsESECTest02(
void)
937 uint8_t raw_opts[] = {
IPV4_OPT_ESEC, 0x02, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
938 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
943 memset(&opts, 0x00,
sizeof(opts));
944 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
952 static int DecodeIPV4OptionsLSRRTest01(
void)
954 uint8_t raw_opts[] = {
956 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
957 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
958 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
959 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
965 memset(&opts, 0x00,
sizeof(opts));
966 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
974 static int DecodeIPV4OptionsLSRRTest02(
void)
976 uint8_t raw_opts[] = {
978 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
979 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
980 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
981 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
987 memset(&opts, 0x00,
sizeof(opts));
988 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
996 static int DecodeIPV4OptionsLSRRTest03(
void)
998 uint8_t raw_opts[] = {
1000 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1001 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1002 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1003 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1009 memset(&opts, 0x00,
sizeof(opts));
1010 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1018 static int DecodeIPV4OptionsLSRRTest04(
void)
1020 uint8_t raw_opts[] = {
1022 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1023 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1024 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1025 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1031 memset(&opts, 0x00,
sizeof(opts));
1032 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1040 static int DecodeIPV4OptionsCIPSOTest01(
void)
1042 uint8_t raw_opts[] = {
1044 0x00, 0x03, 0x00, 0xef, 0x00, 0xef, 0x00, 0x06,
1045 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00
1051 memset(&opts, 0x00,
sizeof(opts));
1052 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1060 static int DecodeIPV4OptionsSIDTest01(
void)
1062 uint8_t raw_opts[] = {
1069 memset(&opts, 0x00,
sizeof(opts));
1070 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1078 static int DecodeIPV4OptionsSIDTest02(
void)
1080 uint8_t raw_opts[] = {
1087 memset(&opts, 0x00,
sizeof(opts));
1088 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1096 static int DecodeIPV4OptionsSSRRTest01(
void)
1098 uint8_t raw_opts[] = {
1100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1103 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1109 memset(&opts, 0x00,
sizeof(opts));
1110 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1118 static int DecodeIPV4OptionsSSRRTest02(
void)
1120 uint8_t raw_opts[] = {
1122 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1131 memset(&opts, 0x00,
sizeof(opts));
1132 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1140 static int DecodeIPV4OptionsSSRRTest03(
void)
1142 uint8_t raw_opts[] = {
1144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1146 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1153 memset(&opts, 0x00,
sizeof(opts));
1154 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1162 static int DecodeIPV4OptionsSSRRTest04(
void)
1164 uint8_t raw_opts[] = {
1166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1168 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1175 memset(&opts, 0x00,
sizeof(opts));
1176 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1184 static int DecodeIPV4OptionsRTRALTTest01(
void)
1186 uint8_t raw_opts[] = {
1193 memset(&opts, 0x00,
sizeof(opts));
1194 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1202 static int DecodeIPV4OptionsRTRALTTest02(
void)
1204 uint8_t raw_opts[] = {
1211 memset(&opts, 0x00,
sizeof(opts));
1212 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1219 static int IPV4CalculateValidChecksumtest01(
void)
1223 uint8_t raw_ipv4[] = {
1224 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1225 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1226 0xc0, 0xa8, 0x01, 0x03};
1228 csum = *( ((uint16_t *)raw_ipv4) + 5);
1230 FAIL_IF(IPV4Checksum((uint16_t *)raw_ipv4,
sizeof(raw_ipv4), csum) != 0);
1234 static int IPV4CalculateInvalidChecksumtest02(
void)
1238 uint8_t raw_ipv4[] = {
1239 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1240 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1241 0xc0, 0xa8, 0x01, 0x07};
1243 csum = *( ((uint16_t *)raw_ipv4) + 5);
1245 FAIL_IF(IPV4Checksum((uint16_t *)raw_ipv4,
sizeof(raw_ipv4), csum) == 0);
1252 static int DecodeIPV4DefragTest01(
void)
1255 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1256 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1257 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1258 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1259 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1263 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1264 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1265 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x01, 0x40, 0x06,
1266 0x9a, 0xc7, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1267 0xe1, 0x0c, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1271 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1272 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1273 0x00, 0x18, 0xe9, 0xef, 0x00, 0x02, 0x40, 0x06,
1274 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1275 0xe1, 0x0c, 0xb1, 0xa3, 0x00, 0x00
1277 uint8_t tunnel_pkt[] = {
1278 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1279 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1280 0x00, 0x28, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1281 0xba, 0xbc, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1282 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1283 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1284 0x80, 0x00, 0xb1, 0xa3, 0x00, 0x00
1303 if (p->
tcph != NULL) {
1304 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1313 if (p->
tcph != NULL) {
1314 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1323 if (p->
tcph != NULL) {
1324 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1330 printf(
"Failed to get defragged pseudo packet\n");
1335 printf(
"defragged pseudo packet's and parent packet's recursion "
1336 "level don't match\n %d != %d",
1341 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1342 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1348 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1349 "don't match\n %u != %"PRIuMAX,
1354 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1374 static int DecodeIPV4DefragTest02(
void)
1377 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1378 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1379 0x00, 0x24, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1380 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1383 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1384 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1388 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1389 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1390 0x00, 0x2c, 0xe9, 0xef, 0x20, 0x02, 0x40, 0x06,
1391 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1394 0xb1, 0xa3, 0x00, 0x10, 0x5b, 0xa3, 0x81, 0x5e,
1395 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1396 0xb1, 0xa3, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04
1399 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1400 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1401 0x00, 0x16, 0xe9, 0xef, 0x00, 0x05, 0x40, 0x06,
1402 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1408 uint8_t tunnel_pkt[] = {
1409 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1410 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1411 0x00, 0x3e, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1412 0xba, 0xae, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1414 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3, 0x81, 0x5e,
1415 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1416 0xb1, 0xa3, 0x00, 0x10, 0x5b, 0xa3, 0x81, 0x5e,
1417 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1418 0xb1, 0xa3, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04,
1438 if (p->
tcph != NULL) {
1439 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1447 if (p->
tcph != NULL) {
1448 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1457 if (p->
tcph != NULL) {
1458 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1463 printf(
"Failed to get defragged pseudo packet\n");
1467 printf(
"defragged pseudo packet's and parent packet's recursion "
1468 "level don't match %d != %d: ",
1472 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1473 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1478 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1479 "don't match %u != %"PRIuMAX
": ",
1484 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1503 static int DecodeIPV4DefragTest03(
void)
1506 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1507 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1508 0x00, 0x28, 0xe9, 0xee, 0x00, 0x00, 0x40, 0x06,
1509 0xba, 0xbd, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1510 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1511 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
1512 0x80, 0x00, 0x0c, 0xee, 0x00, 0x00
1515 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1516 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1517 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1518 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1519 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1523 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1524 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1525 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x01, 0x40, 0x06,
1526 0x9a, 0xc7, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1527 0xe1, 0x0c, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1531 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1532 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1533 0x00, 0x18, 0xe9, 0xef, 0x00, 0x02, 0x40, 0x06,
1534 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1535 0xe1, 0x0c, 0xb1, 0xa3, 0x00, 0x00
1537 uint8_t tunnel_pkt[] = {
1538 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1539 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1540 0x00, 0x28, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1541 0xba, 0xbc, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1542 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1543 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1544 0x80, 0x00, 0xb1, 0xa3, 0x00, 0x00
1563 if (p->
tcph == NULL) {
1564 printf(
"tcp header shouldn't be NULL, but it is\n");
1569 printf(
"packet flow shouldn't be NULL\n");
1578 if (p->
tcph != NULL) {
1579 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1588 if (p->
tcph != NULL) {
1589 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1598 if (p->
tcph != NULL) {
1599 printf(
"tcp header should be NULL for ip fragment, but it isn't\n");
1606 printf(
"Failed to get defragged pseudo packet\n");
1619 printf(
"defragged pseudo packet's and parent packet's recursion "
1620 "level don't match\n %d != %d",
1625 if (tp->
ip4h == NULL || tp->
tcph == NULL) {
1626 printf(
"pseudo packet's ip header and tcp header shouldn't be NULL, "
1632 printf(
"defragged pseudo packet's and parent packet's pkt lens "
1633 "don't match\n %u != %"PRIuMAX,
1639 if (memcmp(
GET_PKT_DATA(tp), tunnel_pkt,
sizeof(tunnel_pkt)) != 0) {
1657 static int DecodeEthernetTestIPv4Opt(
void)
1659 uint8_t raw_eth[] = {
1660 0xae, 0x71, 0x00, 0x00, 0x00, 0x4b, 0x06, 0x90, 0x61, 0x02, 0x00, 0xcd, 0x88, 0x64, 0x11, 0x00,
1661 0x15, 0x00, 0x80, 0x64, 0x00, 0x21, 0x4c, 0x00, 0x00, 0x30, 0x42, 0xd6, 0xff, 0xff, 0xbd, 0x2f,
1662 0x02, 0x02, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
1663 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
1664 0x01, 0x44, 0x05, 0x22, 0x02, 0x01
1689 UtRegisterTest(
"DecodeIPV4OptionsNONETest01", DecodeIPV4OptionsNONETest01);
1690 UtRegisterTest(
"DecodeIPV4OptionsEOLTest01", DecodeIPV4OptionsEOLTest01);
1691 UtRegisterTest(
"DecodeIPV4OptionsNOPTest01", DecodeIPV4OptionsNOPTest01);
1692 UtRegisterTest(
"DecodeIPV4OptionsRRTest01", DecodeIPV4OptionsRRTest01);
1693 UtRegisterTest(
"DecodeIPV4OptionsRRTest02", DecodeIPV4OptionsRRTest02);
1694 UtRegisterTest(
"DecodeIPV4OptionsRRTest03", DecodeIPV4OptionsRRTest03);
1695 UtRegisterTest(
"DecodeIPV4OptionsRRTest04", DecodeIPV4OptionsRRTest04);
1696 UtRegisterTest(
"DecodeIPV4OptionsQSTest01", DecodeIPV4OptionsQSTest01);
1697 UtRegisterTest(
"DecodeIPV4OptionsQSTest02", DecodeIPV4OptionsQSTest02);
1698 UtRegisterTest(
"DecodeIPV4OptionsTSTest01", DecodeIPV4OptionsTSTest01);
1699 UtRegisterTest(
"DecodeIPV4OptionsTSTest02", DecodeIPV4OptionsTSTest02);
1700 UtRegisterTest(
"DecodeIPV4OptionsTSTest03", DecodeIPV4OptionsTSTest03);
1701 UtRegisterTest(
"DecodeIPV4OptionsTSTest04", DecodeIPV4OptionsTSTest04);
1702 UtRegisterTest(
"DecodeIPV4OptionsSECTest01", DecodeIPV4OptionsSECTest01);
1703 UtRegisterTest(
"DecodeIPV4OptionsSECTest02", DecodeIPV4OptionsSECTest02);
1704 UtRegisterTest(
"DecodeIPV4OptionsESECTest01", DecodeIPV4OptionsESECTest01);
1705 UtRegisterTest(
"DecodeIPV4OptionsESECTest02", DecodeIPV4OptionsESECTest02);
1706 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest01", DecodeIPV4OptionsLSRRTest01);
1707 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest02", DecodeIPV4OptionsLSRRTest02);
1708 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest03", DecodeIPV4OptionsLSRRTest03);
1709 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest04", DecodeIPV4OptionsLSRRTest04);
1711 DecodeIPV4OptionsCIPSOTest01);
1712 UtRegisterTest(
"DecodeIPV4OptionsSIDTest01", DecodeIPV4OptionsSIDTest01);
1713 UtRegisterTest(
"DecodeIPV4OptionsSIDTest02", DecodeIPV4OptionsSIDTest02);
1714 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest01", DecodeIPV4OptionsSSRRTest01);
1715 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest02", DecodeIPV4OptionsSSRRTest02);
1716 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest03", DecodeIPV4OptionsSSRRTest03);
1717 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest04", DecodeIPV4OptionsSSRRTest04);
1719 DecodeIPV4OptionsRTRALTTest01);
1721 DecodeIPV4OptionsRTRALTTest02);
1723 IPV4CalculateValidChecksumtest01);
1725 IPV4CalculateInvalidChecksumtest02);
1726 UtRegisterTest(
"DecodeIPV4DefragTest01", DecodeIPV4DefragTest01);
1727 UtRegisterTest(
"DecodeIPV4DefragTest02", DecodeIPV4DefragTest02);
1728 UtRegisterTest(
"DecodeIPV4DefragTest03", DecodeIPV4DefragTest03);
1729 UtRegisterTest(
"DecodeEthernetTestIPv4Opt", DecodeEthernetTestIPv4Opt);