57 if (host_tag_id.
id == -1) {
58 FatalError(
"Can't initiate host storage for tag");
61 if (flow_tag_id.
id == -1) {
62 FatalError(
"Can't initiate flow storage for tag");
118 uint16_t tag_cnt = 0;
127 for (; iter != NULL; iter = iter->
next) {
150 if (new_tde != NULL) {
157 SCLogDebug(
"Max tags for sessions reached (%"PRIu16
")", tag_cnt);
197 if (new_tde != NULL) {
209 for (iter =
tag; iter != NULL; iter = iter->
next) {
230 if (new_tde != NULL) {
237 SCLogDebug(
"Max tags for sessions reached (%"PRIu16
")", ntags);
245 static void TagHandlePacketFlow(
Flow *f,
Packet *p)
253 uint8_t flag_added = 0;
255 while (iter != NULL) {
277 SCLogDebug(
"flow tag expired: packets %u > %u",
295 }
else if (flag_added == 0) {
322 }
else if (flag_added == 0) {
333 SCLogDebug(
"flow tag expired: %u - %u = %u > %u",
352 }
else if (flag_added == 0) {
368 static void TagHandlePacketHost(
Host *host,
Packet *p)
373 uint8_t flag_added = 0;
377 while (iter != NULL) {
415 }
else if (flag_added == 0) {
441 }
else if (flag_added == 0) {
452 SCLogDebug(
"host tag expired: %u - %u = %u > %u",
471 }
else if (flag_added == 0) {
522 if (current_tags == 0)
526 if (p->
flow != NULL) {
527 TagHandlePacketFlow(p->
flow, p);
530 Host *
src = GetLockedSrcHost(p);
533 TagHandlePacketHost(
src, p);
538 Host *
dst = GetLockedDstHost(p);
541 TagHandlePacketHost(
dst, p);
570 while (tmp != NULL) {
607 static int DetectTagTestPacket01 (
void)
609 uint8_t *buf = (uint8_t *)
"Hi all!";
610 uint8_t *buf2 = (uint8_t *)
"lalala!";
611 uint16_t buf_len = strlen((
char *)buf);
612 uint16_t buf_len2 = strlen((
char *)buf2);
616 "192.168.1.5",
"192.168.1.1",
619 "192.168.1.5",
"192.168.1.1",
622 "192.168.1.5",
"192.168.1.9",
625 "192.168.1.5",
"192.168.1.9",
628 "192.168.1.1",
"192.168.1.9",
631 "192.168.1.1",
"192.168.1.11",
634 "192.168.1.5",
"192.168.1.11",
638 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing tag 1\"; content:\"Hi all\"; tag:host,3,packets,src; sid:1;)";
639 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"Hi all\"; tag:host,4,packets,dst; sid:2;)";
640 sigs[2]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:3;)";
641 sigs[3]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:4;)";
642 sigs[4]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:5;)";
645 uint32_t sid[5] = {1,2,3,4,5};
647 int32_t results[7][5] = {
697 static int DetectTagTestPacket02 (
void)
699 uint8_t *buf = (uint8_t *)
"Hi all!";
700 uint8_t *buf2 = (uint8_t *)
"lalala!";
701 uint16_t buf_len = strlen((
char *)buf);
702 uint16_t buf_len2 = strlen((
char *)buf2);
708 memset(&th_v, 0,
sizeof(th_v));
721 "192.168.1.5",
"192.168.1.1",
724 "192.168.1.5",
"192.168.1.1",
727 "192.168.1.5",
"192.168.1.9",
730 "192.168.1.5",
"192.168.1.9",
733 "192.168.1.1",
"192.168.1.9",
736 "192.168.1.1",
"192.168.1.11",
739 "192.168.1.5",
"192.168.1.11",
743 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing tag 1\"; content:\"Hi all\"; tag:host,3,seconds,src; sid:1;)";
744 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"Hi all\"; tag:host,8,seconds,dst; sid:2;)";
745 sigs[2]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:3;)";
746 sigs[3]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:4;)";
747 sigs[4]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:5;)";
750 uint32_t sid[5] = {1,2,3,4,5};
757 int32_t results[7][5] = {
772 for (; i < num_packets; i++) {
782 bool expect = (i == 1 || i == 4);
799 static int DetectTagTestPacket03 (
void)
801 uint8_t *buf = (uint8_t *)
"Hi all!";
802 uint8_t *buf2 = (uint8_t *)
"lalala!";
803 uint16_t buf_len = strlen((
char *)buf);
804 uint16_t buf_len2 = strlen((
char *)buf2);
810 memset(&th_v, 0,
sizeof(th_v));
824 "192.168.1.5",
"192.168.1.1",
827 "192.168.1.5",
"192.168.1.1",
830 "192.168.1.5",
"192.168.1.9",
833 "192.168.1.5",
"192.168.1.9",
836 "192.168.1.1",
"192.168.1.9",
839 "192.168.1.1",
"192.168.1.11",
842 "192.168.1.5",
"192.168.1.11",
846 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing tag 1\"; content:\"Hi all\"; tag:host, 150, bytes, src; sid:1;)";
847 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"Hi all\"; tag:host, 150, bytes, dst; sid:2;)";
848 sigs[2]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:3;)";
849 sigs[3]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:4;)";
850 sigs[4]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:5;)";
853 uint32_t sid[5] = {1,2,3,4,5};
858 int32_t results[7][5] = {
873 for (; i < num_packets; i++) {
881 bool expect = (i == 1 || i == 2 || i == 4);
898 static int DetectTagTestPacket04 (
void)
900 uint8_t *buf = (uint8_t *)
"Hi all!";
901 uint8_t *buf2 = (uint8_t *)
"lalala!";
902 uint16_t buf_len = strlen((
char *)buf);
903 uint16_t buf_len2 = strlen((
char *)buf2);
908 memset(&f, 0,
sizeof(f));
909 memset(&ssn, 0,
sizeof(ssn));
922 FAIL_IF(inet_pton(AF_INET,
"192.168.1.5", f->
src.addr_data32) != 1);
923 FAIL_IF(inet_pton(AF_INET,
"192.168.1.1", f->
dst.addr_data32) != 1);
929 memset(&th_v, 0,
sizeof(th_v));
937 "192.168.1.5",
"192.168.1.1",
940 "192.168.1.5",
"192.168.1.1",
943 "192.168.1.5",
"192.168.1.1",
946 "192.168.1.5",
"192.168.1.1",
949 "192.168.1.1",
"192.168.1.5",
952 "192.168.1.1",
"192.168.1.5",
955 "192.168.1.5",
"192.168.1.1",
959 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing tag 1\"; content:\"Hi all\"; tag:session,4,packets; sid:1;)";
960 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"blahblah\"; sid:2;)";
961 sigs[2]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:3;)";
962 sigs[3]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:4;)";
963 sigs[4]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:5;)";
966 uint32_t sid[5] = {1,2,3,4,5};
971 int32_t results[7][5] = {
986 for (; i < num_packets; i++) {
995 bool expect = (i == 1 || i == 2 || i == 3);
1019 static int DetectTagTestPacket05 (
void)
1021 uint8_t *buf = (uint8_t *)
"Hi all!";
1022 uint8_t *buf2 = (uint8_t *)
"lalala!";
1023 uint16_t buf_len = strlen((
char *)buf);
1024 uint16_t buf_len2 = strlen((
char *)buf2);
1029 memset(&f, 0,
sizeof(f));
1030 memset(&ssn, 0,
sizeof(ssn));
1043 FAIL_IF(inet_pton(AF_INET,
"192.168.1.5", f->
src.addr_data32) != 1);
1044 FAIL_IF(inet_pton(AF_INET,
"192.168.1.1", f->
dst.addr_data32) != 1);
1050 memset(&th_v, 0,
sizeof(th_v));
1058 "192.168.1.5",
"192.168.1.1",
1061 "192.168.1.5",
"192.168.1.1",
1064 "192.168.1.5",
"192.168.1.1",
1067 "192.168.1.5",
"192.168.1.1",
1070 "192.168.1.1",
"192.168.1.5",
1073 "192.168.1.1",
"192.168.1.5",
1076 "192.168.1.5",
"192.168.1.1",
1079 const char *sigs[5];
1080 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing tag 1\"; content:\"Hi all\"; tag:session,8,seconds; sid:1;)";
1081 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"blahblah\"; sid:2;)";
1082 sigs[2]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:3;)";
1083 sigs[3]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:4;)";
1084 sigs[4]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:5;)";
1087 uint32_t sid[5] = {1,2,3,4,5};
1092 int32_t results[7][5] = {
1102 int num_packets = 7;
1107 for (; i < num_packets; i++) {
1121 bool expect = (i == 1 || i == 2 || i == 3 || i == 4);
1145 static int DetectTagTestPacket06 (
void)
1147 uint8_t *buf = (uint8_t *)
"Hi all!";
1148 uint8_t *buf2 = (uint8_t *)
"lalala!";
1149 uint16_t buf_len = strlen((
char *)buf);
1150 uint16_t buf_len2 = strlen((
char *)buf2);
1155 memset(&f, 0,
sizeof(f));
1156 memset(&ssn, 0,
sizeof(ssn));
1169 FAIL_IF(inet_pton(AF_INET,
"192.168.1.5", f->
src.addr_data32) != 1);
1170 FAIL_IF(inet_pton(AF_INET,
"192.168.1.1", f->
dst.addr_data32) != 1);
1176 memset(&th_v, 0,
sizeof(th_v));
1184 "192.168.1.5",
"192.168.1.1",
1187 "192.168.1.5",
"192.168.1.1",
1190 "192.168.1.5",
"192.168.1.1",
1193 "192.168.1.5",
"192.168.1.1",
1196 "192.168.1.1",
"192.168.1.5",
1199 "192.168.1.1",
"192.168.1.5",
1202 "192.168.1.5",
"192.168.1.1",
1205 const char *sigs[5];
1206 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing tag 1\"; content:\"Hi all\"; tag:session,150,bytes; sid:1;)";
1207 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"blahblah\"; sid:2;)";
1208 sigs[2]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:3;)";
1209 sigs[3]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:4;)";
1210 sigs[4]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:5;)";
1213 uint32_t sid[5] = {1,2,3,4,5};
1218 int32_t results[7][5] = {
1228 int num_packets = 7;
1233 for (; i < num_packets; i++) {
1243 bool expect = (i == 1 || i == 2);
1267 static int DetectTagTestPacket07 (
void)
1269 uint8_t *buf = (uint8_t *)
"Hi all!";
1270 uint8_t *buf2 = (uint8_t *)
"lalala!";
1271 uint16_t buf_len = strlen((
char *)buf);
1272 uint16_t buf_len2 = strlen((
char *)buf2);
1277 memset(&f, 0,
sizeof(f));
1278 memset(&ssn, 0,
sizeof(ssn));
1291 FAIL_IF(inet_pton(AF_INET,
"192.168.1.5", f->
src.addr_data32) != 1);
1292 FAIL_IF(inet_pton(AF_INET,
"192.168.1.1", f->
dst.addr_data32) != 1);
1298 memset(&th_v, 0,
sizeof(th_v));
1306 "192.168.1.5",
"192.168.1.1",
1309 "192.168.1.5",
"192.168.1.1",
1312 "192.168.1.5",
"192.168.1.1",
1315 "192.168.1.5",
"192.168.1.1",
1318 "192.168.1.1",
"192.168.1.5",
1321 "192.168.1.1",
"192.168.1.5",
1324 "192.168.1.5",
"192.168.1.1",
1327 const char *sigs[5];
1328 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing tag 1\"; content:\"Hi all\"; tag:session,150,bytes; sid:1;)";
1329 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"blahblah\"; sid:2;)";
1330 sigs[2]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:3;)";
1331 sigs[3]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:4;)";
1332 sigs[4]=
"alert tcp any any -> any any (msg:\"Testing tag 2\"; content:\"no match\"; sid:5;)";
1335 uint32_t sid[5] = {1,2,3,4,5};
1339 int32_t results[7][5] = {
1349 int num_packets = 7;
1354 for (; i < num_packets; i++) {
1364 bool expect = (i == 1 || i == 2 || i == 3 || i == 4 || i == 5);