116 if (
unlikely((ptr < 4) || (ptr % 4) || (ptr > o->
len + 1))) {
131static 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,
473static const IPV4Hdr *DecodeIPV4Packet(
Packet *p,
const uint8_t *pkt, uint16_t
len)
486 const IPV4Hdr *ip4h = PacketSetIPV4(p, pkt);
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 const IPV4Hdr *ip4h = DecodeIPV4Packet(p, pkt,
len);
557 SCLogDebug(
"IPV4 %s->%s PROTO: %" PRIu32
" OFFSET: %" PRIu32
" RF: %" PRIu8
" DF: %" PRIu8
558 " MF: %" PRIu8
" ID: %" PRIu32
"",
629static int DecodeIPV4OptionsNONETest01(
void)
631 uint8_t raw_opts[] = { };
636 memset(&opts, 0x00,
sizeof(opts));
637 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
645static int DecodeIPV4OptionsEOLTest01(
void)
647 uint8_t raw_opts[] = {
653 memset(&opts, 0x00,
sizeof(opts));
654 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
661static int DecodeIPV4OptionsNOPTest01(
void)
663 uint8_t raw_opts[] = {
669 memset(&opts, 0x00,
sizeof(opts));
670 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
677static int DecodeIPV4OptionsRRTest01(
void)
679 uint8_t raw_opts[] = {
680 IPV4_OPT_RR, 0x27, 0x08, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
681 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
682 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
683 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
684 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
690 memset(&opts, 0x00,
sizeof(opts));
691 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
699static int DecodeIPV4OptionsRRTest02(
void)
701 uint8_t raw_opts[] = {
702 IPV4_OPT_RR, 0xff, 0x08, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
703 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
704 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
705 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
706 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
712 memset(&opts, 0x00,
sizeof(opts));
713 FAIL_IF(DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts) != -1);
721static int DecodeIPV4OptionsRRTest03(
void)
723 uint8_t raw_opts[] = {
724 IPV4_OPT_RR, 0x27, 0xff, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
725 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
726 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
727 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
728 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
734 memset(&opts, 0x00,
sizeof(opts));
735 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
743static int DecodeIPV4OptionsRRTest04(
void)
745 uint8_t raw_opts[] = {
746 IPV4_OPT_RR, 0x27, 0x05, 0xc0, 0xa8, 0x2a, 0x64, 0x00,
747 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
748 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
749 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
750 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
756 memset(&opts, 0x00,
sizeof(opts));
757 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
765static int DecodeIPV4OptionsQSTest01(
void)
767 uint8_t raw_opts[] = {
768 IPV4_OPT_QS, 0x08, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
774 memset(&opts, 0x00,
sizeof(opts));
775 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
783static int DecodeIPV4OptionsQSTest02(
void)
785 uint8_t raw_opts[] = {
786 IPV4_OPT_QS, 0x07, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
792 memset(&opts, 0x00,
sizeof(opts));
793 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
801static int DecodeIPV4OptionsTSTest01(
void)
803 uint8_t raw_opts[] = {
804 IPV4_OPT_TS, 0x24, 0x0d, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
805 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
806 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
807 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
808 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
814 memset(&opts, 0x00,
sizeof(opts));
815 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
823static int DecodeIPV4OptionsTSTest02(
void)
825 uint8_t raw_opts[] = {
826 IPV4_OPT_TS, 0x24, 0x04, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
827 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
828 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
829 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
830 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
836 memset(&opts, 0x00,
sizeof(opts));
837 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
845static int DecodeIPV4OptionsTSTest03(
void)
847 uint8_t raw_opts[] = {
848 IPV4_OPT_TS, 0x24, 0xff, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
849 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
850 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
851 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
852 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
858 memset(&opts, 0x00,
sizeof(opts));
859 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
867static int DecodeIPV4OptionsTSTest04(
void)
869 uint8_t raw_opts[] = {
870 IPV4_OPT_TS, 0x24, 0x0a, 0x01, 0x0a, 0x0a, 0x0a, 0x69,
871 0x04, 0xce, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
872 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
873 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
874 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
880 memset(&opts, 0x00,
sizeof(opts));
881 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
889static int DecodeIPV4OptionsSECTest01(
void)
891 uint8_t raw_opts[] = {
893 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
899 memset(&opts, 0x00,
sizeof(opts));
900 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
908static int DecodeIPV4OptionsSECTest02(
void)
910 uint8_t raw_opts[] = {
IPV4_OPT_SEC, 0x02, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
911 0x00, 0x00, 0x00, 0x00, 0x00 };
916 memset(&opts, 0x00,
sizeof(opts));
917 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
925static int DecodeIPV4OptionsESECTest01(
void)
927 uint8_t raw_opts[] = {
IPV4_OPT_ESEC, 0x0b, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
928 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
933 memset(&opts, 0x00,
sizeof(opts));
934 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
942static int DecodeIPV4OptionsESECTest02(
void)
944 uint8_t raw_opts[] = {
IPV4_OPT_ESEC, 0x02, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
945 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
950 memset(&opts, 0x00,
sizeof(opts));
951 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
959static int DecodeIPV4OptionsLSRRTest01(
void)
961 uint8_t raw_opts[] = {
963 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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
972 memset(&opts, 0x00,
sizeof(opts));
973 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
981static int DecodeIPV4OptionsLSRRTest02(
void)
983 uint8_t raw_opts[] = {
985 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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
994 memset(&opts, 0x00,
sizeof(opts));
995 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1003static int DecodeIPV4OptionsLSRRTest03(
void)
1005 uint8_t raw_opts[] = {
1007 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1008 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1009 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1010 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1016 memset(&opts, 0x00,
sizeof(opts));
1017 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1025static int DecodeIPV4OptionsLSRRTest04(
void)
1027 uint8_t raw_opts[] = {
1029 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1030 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1031 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1032 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1038 memset(&opts, 0x00,
sizeof(opts));
1039 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1047static int DecodeIPV4OptionsCIPSOTest01(
void)
1049 uint8_t raw_opts[] = {
1051 0x00, 0x03, 0x00, 0xef, 0x00, 0xef, 0x00, 0x06,
1052 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00
1058 memset(&opts, 0x00,
sizeof(opts));
1059 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1067static int DecodeIPV4OptionsSIDTest01(
void)
1069 uint8_t raw_opts[] = {
1076 memset(&opts, 0x00,
sizeof(opts));
1077 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1085static int DecodeIPV4OptionsSIDTest02(
void)
1087 uint8_t raw_opts[] = {
1094 memset(&opts, 0x00,
sizeof(opts));
1095 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1103static int DecodeIPV4OptionsSSRRTest01(
void)
1105 uint8_t raw_opts[] = {
1107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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
1116 memset(&opts, 0x00,
sizeof(opts));
1117 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1125static int DecodeIPV4OptionsSSRRTest02(
void)
1127 uint8_t raw_opts[] = {
1129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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
1138 memset(&opts, 0x00,
sizeof(opts));
1139 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1147static int DecodeIPV4OptionsSSRRTest03(
void)
1149 uint8_t raw_opts[] = {
1151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1160 memset(&opts, 0x00,
sizeof(opts));
1161 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1169static int DecodeIPV4OptionsSSRRTest04(
void)
1171 uint8_t raw_opts[] = {
1173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1182 memset(&opts, 0x00,
sizeof(opts));
1183 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1191static int DecodeIPV4OptionsRTRALTTest01(
void)
1193 uint8_t raw_opts[] = {
1200 memset(&opts, 0x00,
sizeof(opts));
1201 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1209static int DecodeIPV4OptionsRTRALTTest02(
void)
1211 uint8_t raw_opts[] = {
1218 memset(&opts, 0x00,
sizeof(opts));
1219 DecodeIPV4Options(p, raw_opts,
sizeof(raw_opts), &opts);
1226static int IPV4CalculateValidChecksumtest01(
void)
1230 uint8_t raw_ipv4[] = {
1231 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1232 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1233 0xc0, 0xa8, 0x01, 0x03};
1235 csum = *( ((uint16_t *)raw_ipv4) + 5);
1237 FAIL_IF(IPV4Checksum((uint16_t *)raw_ipv4,
sizeof(raw_ipv4), csum) != 0);
1241static int IPV4CalculateInvalidChecksumtest02(
void)
1245 uint8_t raw_ipv4[] = {
1246 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1247 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1248 0xc0, 0xa8, 0x01, 0x07};
1250 csum = *( ((uint16_t *)raw_ipv4) + 5);
1252 FAIL_IF(IPV4Checksum((uint16_t *)raw_ipv4,
sizeof(raw_ipv4), csum) == 0);
1259static int DecodeIPV4DefragTest01(
void)
1262 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1263 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1264 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1265 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1266 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1270 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1271 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1272 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x01, 0x40, 0x06,
1273 0x9a, 0xc7, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1274 0xe1, 0x0c, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1278 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1279 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1280 0x00, 0x18, 0xe9, 0xef, 0x00, 0x02, 0x40, 0x06,
1281 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1282 0xe1, 0x0c, 0xb1, 0xa3, 0x00, 0x00
1284 uint8_t tunnel_pkt[] = {
1285 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1286 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1287 0x00, 0x28, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1288 0xba, 0xbc, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1289 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1290 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1291 0x80, 0x00, 0xb1, 0xa3, 0x00, 0x00
1342static int DecodeIPV4DefragTest02(
void)
1345 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1346 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1347 0x00, 0x24, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1348 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1351 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1352 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1356 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1357 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1358 0x00, 0x2c, 0xe9, 0xef, 0x20, 0x02, 0x40, 0x06,
1359 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1362 0xb1, 0xa3, 0x00, 0x10, 0x5b, 0xa3, 0x81, 0x5e,
1363 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1364 0xb1, 0xa3, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04
1367 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1368 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1369 0x00, 0x16, 0xe9, 0xef, 0x00, 0x05, 0x40, 0x06,
1370 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1376 uint8_t tunnel_pkt[] = {
1377 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1378 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1379 0x00, 0x3e, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1380 0xba, 0xae, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1382 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3, 0x81, 0x5e,
1383 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1384 0xb1, 0xa3, 0x00, 0x10, 0x5b, 0xa3, 0x81, 0x5e,
1385 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10, 0x80, 0x00,
1386 0xb1, 0xa3, 0x00, 0x10, 0x01, 0x02, 0x03, 0x04,
1438static int DecodeIPV4DefragTest03(
void)
1441 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1442 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1443 0x00, 0x28, 0xe9, 0xee, 0x00, 0x00, 0x40, 0x06,
1444 0xba, 0xbd, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1445 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1446 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
1447 0x80, 0x00, 0x0c, 0xee, 0x00, 0x00
1450 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1451 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1452 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x00, 0x40, 0x06,
1453 0x9a, 0xc8, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1454 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1458 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1459 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1460 0x00, 0x1c, 0xe9, 0xef, 0x20, 0x01, 0x40, 0x06,
1461 0x9a, 0xc7, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1462 0xe1, 0x0c, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1466 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1467 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1468 0x00, 0x18, 0xe9, 0xef, 0x00, 0x02, 0x40, 0x06,
1469 0xba, 0xca, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1470 0xe1, 0x0c, 0xb1, 0xa3, 0x00, 0x00
1472 uint8_t tunnel_pkt[] = {
1473 0x00, 0x50, 0x56, 0x00, 0x03, 0x05, 0xde, 0xad,
1474 0x01, 0xa3, 0xa2, 0x2f, 0x08, 0x00, 0x45, 0x00,
1475 0x00, 0x28, 0xe9, 0xef, 0x00, 0x00, 0x40, 0x06,
1476 0xba, 0xbc, 0x0a, 0x00, 0xe1, 0x17, 0x0a, 0x00,
1477 0xe1, 0x0c, 0x6e, 0x12, 0x01, 0xbd, 0x5b, 0xa3,
1478 0x81, 0x5e, 0xac, 0xb0, 0xae, 0x8a, 0x50, 0x10,
1479 0x80, 0x00, 0xb1, 0xa3, 0x00, 0x00
1537static int DecodeEthernetTestIPv4Opt(
void)
1539 uint8_t raw_eth[] = {
1540 0xae, 0x71, 0x00, 0x00, 0x00, 0x4b, 0x06, 0x90, 0x61, 0x02, 0x00, 0xcd, 0x88, 0x64, 0x11, 0x00,
1541 0x15, 0x00, 0x80, 0x64, 0x00, 0x21, 0x4c, 0x00, 0x00, 0x30, 0x42, 0xd6, 0xff, 0xff, 0xbd, 0x2f,
1542 0x02, 0x02, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
1543 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
1544 0x01, 0x44, 0x05, 0x22, 0x02, 0x01
1569 UtRegisterTest(
"DecodeIPV4OptionsNONETest01", DecodeIPV4OptionsNONETest01);
1570 UtRegisterTest(
"DecodeIPV4OptionsEOLTest01", DecodeIPV4OptionsEOLTest01);
1571 UtRegisterTest(
"DecodeIPV4OptionsNOPTest01", DecodeIPV4OptionsNOPTest01);
1572 UtRegisterTest(
"DecodeIPV4OptionsRRTest01", DecodeIPV4OptionsRRTest01);
1573 UtRegisterTest(
"DecodeIPV4OptionsRRTest02", DecodeIPV4OptionsRRTest02);
1574 UtRegisterTest(
"DecodeIPV4OptionsRRTest03", DecodeIPV4OptionsRRTest03);
1575 UtRegisterTest(
"DecodeIPV4OptionsRRTest04", DecodeIPV4OptionsRRTest04);
1576 UtRegisterTest(
"DecodeIPV4OptionsQSTest01", DecodeIPV4OptionsQSTest01);
1577 UtRegisterTest(
"DecodeIPV4OptionsQSTest02", DecodeIPV4OptionsQSTest02);
1578 UtRegisterTest(
"DecodeIPV4OptionsTSTest01", DecodeIPV4OptionsTSTest01);
1579 UtRegisterTest(
"DecodeIPV4OptionsTSTest02", DecodeIPV4OptionsTSTest02);
1580 UtRegisterTest(
"DecodeIPV4OptionsTSTest03", DecodeIPV4OptionsTSTest03);
1581 UtRegisterTest(
"DecodeIPV4OptionsTSTest04", DecodeIPV4OptionsTSTest04);
1582 UtRegisterTest(
"DecodeIPV4OptionsSECTest01", DecodeIPV4OptionsSECTest01);
1583 UtRegisterTest(
"DecodeIPV4OptionsSECTest02", DecodeIPV4OptionsSECTest02);
1584 UtRegisterTest(
"DecodeIPV4OptionsESECTest01", DecodeIPV4OptionsESECTest01);
1585 UtRegisterTest(
"DecodeIPV4OptionsESECTest02", DecodeIPV4OptionsESECTest02);
1586 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest01", DecodeIPV4OptionsLSRRTest01);
1587 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest02", DecodeIPV4OptionsLSRRTest02);
1588 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest03", DecodeIPV4OptionsLSRRTest03);
1589 UtRegisterTest(
"DecodeIPV4OptionsLSRRTest04", DecodeIPV4OptionsLSRRTest04);
1591 DecodeIPV4OptionsCIPSOTest01);
1592 UtRegisterTest(
"DecodeIPV4OptionsSIDTest01", DecodeIPV4OptionsSIDTest01);
1593 UtRegisterTest(
"DecodeIPV4OptionsSIDTest02", DecodeIPV4OptionsSIDTest02);
1594 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest01", DecodeIPV4OptionsSSRRTest01);
1595 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest02", DecodeIPV4OptionsSSRRTest02);
1596 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest03", DecodeIPV4OptionsSSRRTest03);
1597 UtRegisterTest(
"DecodeIPV4OptionsSSRRTest04", DecodeIPV4OptionsSSRRTest04);
1599 DecodeIPV4OptionsRTRALTTest01);
1601 DecodeIPV4OptionsRTRALTTest02);
1603 IPV4CalculateValidChecksumtest01);
1605 IPV4CalculateInvalidChecksumtest02);
1606 UtRegisterTest(
"DecodeIPV4DefragTest01", DecodeIPV4DefragTest01);
1607 UtRegisterTest(
"DecodeIPV4DefragTest02", DecodeIPV4DefragTest02);
1608 UtRegisterTest(
"DecodeIPV4DefragTest03", DecodeIPV4DefragTest03);
1609 UtRegisterTest(
"DecodeEthernetTestIPv4Opt", DecodeEthernetTestIPv4Opt);
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
int DecodeESP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Function to decode IPSEC-ESP packets.
int DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
#define ETHERNET_HEADER_LEN
@ IPV4_IPLEN_SMALLER_THAN_HLEN
int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Function to decode GRE packets.
int DecodeICMPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Main ICMPv4 decoding function.
int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
struct IPV4Options_ IPV4Options
void DecodeIPV4RegisterTests(void)
#define IPV4_OPT_CIPSO_MIN
#define IPV4_OPT_FLAG_LSRR
#define IPV4_GET_RAW_FRAGOFFSET(ip4h)
#define IPV4_GET_RAW_FLAG_DF(ip4h)
#define IPV4_GET_RAW_IPLEN(ip4h)
#define IPV4_OPT_FLAG_SEC
#define IPV4_OPT_FLAG_CIPSO
#define IPV4_GET_RAW_FLAG_RF(ip4h)
#define IPV4_OPT_FLAG_EOL
#define IPV4_OPT_FLAG_ESEC
#define IPV4_OPT_FLAG_SID
#define IPV4_GET_RAW_IPOFFSET(ip4h)
#define IPV4_OPT_RTRALT_LEN
#define IPV4_OPT_FLAG_SSRR
#define IPV4_GET_RAW_HLEN(ip4h)
#define IPV4_GET_RAW_FLAG_MF(ip4h)
#define IPV4_OPT_FLAG_NOP
#define IPV4_GET_RAW_IPID(ip4h)
#define IPV4_OPT_FLAG_RTRALT
#define IPV4_OPT_ROUTE_MIN
#define IPV4_GET_RAW_IPPROTO(ip4h)
int DecodeSCTP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
int DecodeTCP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
int DecodeUDP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
#define GET_IPV4_SRC_ADDR_PTR(p)
#define PKT_SET_SRC(p, src_val)
#define ENGINE_SET_INVALID_EVENT(p, e)
#define SET_IPV4_SRC_ADDR(ip4h, a)
#define IP_GET_RAW_VER(pkt)
#define SET_IPV4_DST_ADDR(ip4h, a)
#define ENGINE_SET_EVENT(p, e)
#define GET_IPV4_DST_ADDR_PTR(p)
Packet * Defrag(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Entry point for IPv4 and IPv6 fragments.
void FlowSetupPacket(Packet *p)
prepare packet for a life with flow Set PKT_WANTS_FLOW flag to indicate workers should do a flow look...
void FlowInitConfig(bool quiet)
initialize the configuration
void FlowShutdown(void)
shutdown the flow engine
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Copy data to Packet payload and set packet length.
Packet * PacketTunnelPktSetup(ThreadVars *tv, DecodeThreadVars *dtv, Packet *parent, const uint8_t *pkt, uint32_t len, enum DecodeTunnelProto proto)
Setup a pseudo packet (tunnel)
void PacketEnqueueNoLock(PacketQueueNoLock *qnl, Packet *p)
Packet * PacketDequeueNoLock(PacketQueueNoLock *qnl)
void PacketRecycle(Packet *p)
Structure to hold thread specific data for all decode modules.
uint16_t counter_ipv4inipv4
uint16_t counter_ipv6inipv4
Per thread variable structure.
PacketQueueNoLock decode_pq
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)