18 #include "../suricata-common.h"
19 #include "../stream-tcp-private.h"
20 #include "../stream-tcp.h"
21 #include "../stream-tcp-reassemble.h"
22 #include "../stream-tcp-inline.h"
23 #include "../stream-tcp-list.h"
24 #include "../stream-tcp-util.h"
25 #include "../util-streaming-buffer.h"
26 #include "../util-print.h"
27 #include "../util-unittest.h"
29 #define SET_ISN(stream, setseq) \
30 (stream)->isn = (setseq); \
31 (stream)->base_seq = (setseq) + 1
40 static int StreamTcpTest01(
void)
46 memset(&f, 0,
sizeof(
Flow));
55 printf(
"Session can not be allocated: ");
61 printf(
"AppLayer field not set to NULL: ");
64 if (ssn->
state != 0) {
65 printf(
"TCP state field not set to 0: ");
87 static int StreamTcpTest02(
void)
97 memset(&pq, 0,
sizeof(pq));
98 memset(&f, 0,
sizeof(
Flow));
101 memset(&tcph, 0,
sizeof(TCPHdr));
105 tcph.th_win = htons(5480);
114 p->
tcph->th_ack = htonl(1);
120 p->
tcph->th_ack = htonl(1);
121 p->
tcph->th_seq = htonl(1);
127 p->
tcph->th_ack = htonl(1);
128 p->
tcph->th_seq = htonl(2);
141 p->
tcph->th_ack = htonl(1);
142 p->
tcph->th_seq = htonl(6);
172 static int StreamTcpTest03(
void)
181 memset(&pq, 0,
sizeof(pq));
182 memset(&f, 0,
sizeof(
Flow));
185 memset(&tcph, 0,
sizeof(TCPHdr));
191 tcph.th_win = htons(5480);
192 tcph.th_seq = htonl(10);
193 tcph.th_ack = htonl(20);
201 p->
tcph->th_seq = htonl(20);
202 p->
tcph->th_ack = htonl(11);
209 p->
tcph->th_seq = htonl(19);
210 p->
tcph->th_ack = htonl(11);
246 static int StreamTcpTest04(
void)
255 memset(&pq, 0,
sizeof(pq));
256 memset(&f, 0,
sizeof(
Flow));
259 memset(&tcph, 0,
sizeof(TCPHdr));
265 tcph.th_win = htons(5480);
266 tcph.th_seq = htonl(10);
267 tcph.th_ack = htonl(20);
276 p->
tcph->th_seq = htonl(9);
277 p->
tcph->th_ack = htonl(19);
313 static int StreamTcpTest05(
void)
324 memset(&f, 0,
sizeof(
Flow));
327 memset(&tcph, 0,
sizeof(TCPHdr));
333 tcph.th_win = htons(5480);
334 tcph.th_seq = htonl(10);
335 tcph.th_ack = htonl(20);
346 p->
tcph->th_seq = htonl(20);
347 p->
tcph->th_ack = htonl(13);
358 p->
tcph->th_seq = htonl(13);
359 p->
tcph->th_ack = htonl(23);
370 p->
tcph->th_seq = htonl(19);
371 p->
tcph->th_ack = htonl(16);
411 static int StreamTcpTest06(
void)
422 memset(&f, 0,
sizeof(
Flow));
426 memset(&tcph, 0,
sizeof(TCPHdr));
438 printf(
"StreamTcpPacket failed: ");
443 printf(
"we have a ssn while we shouldn't: ");
450 printf(
"StreamTcpPacket failed (2): ");
455 printf(
"we have a ssn while we shouldn't (2): ");
472 static int StreamTcpTest07(
void)
480 uint8_t payload[1] = { 0x42 };
484 memset(&f, 0,
sizeof(
Flow));
487 memset(&tcph, 0,
sizeof(TCPHdr));
495 tcph.th_win = htons(5480);
496 tcph.th_seq = htonl(10);
497 tcph.th_ack = htonl(20);
510 p->
tcph->th_seq = htonl(11);
511 p->
tcph->th_ack = htonl(23);
533 static int StreamTcpTest08(
void)
541 uint8_t payload[1] = { 0x42 };
545 memset(&f, 0,
sizeof(
Flow));
548 memset(&tcph, 0,
sizeof(TCPHdr));
556 tcph.th_win = htons(5480);
557 tcph.th_seq = htonl(10);
558 tcph.th_ack = htonl(20);
571 p->
tcph->th_seq = htonl(11);
572 p->
tcph->th_ack = htonl(20);
595 static int StreamTcpTest09(
void)
603 uint8_t payload[1] = { 0x42 };
607 memset(&f, 0,
sizeof(
Flow));
610 memset(&tcph, 0,
sizeof(TCPHdr));
618 tcph.th_win = htons(5480);
619 tcph.th_seq = htonl(10);
620 tcph.th_ack = htonl(20);
629 p->
tcph->th_seq = htonl(12);
630 p->
tcph->th_ack = htonl(23);
640 p->
tcph->th_seq = htonl(11);
641 p->
tcph->th_ack = htonl(23);
651 FAIL_IF(TCPSEG_RB_NEXT(seg) != NULL);
665 static int StreamTcpTest10(
void)
676 memset(&f, 0,
sizeof(
Flow));
679 memset(&tcph, 0,
sizeof(TCPHdr));
686 tcph.th_win = htons(5480);
687 tcph.th_seq = htonl(10);
694 p->
tcph->th_seq = htonl(11);
695 p->
tcph->th_ack = htonl(11);
701 p->
tcph->th_seq = htonl(11);
702 p->
tcph->th_ack = htonl(11);
712 p->
tcph->th_seq = htonl(6);
713 p->
tcph->th_ack = htonl(11);
743 static int StreamTcpTest11(
void)
754 memset(&f, 0,
sizeof(
Flow));
757 memset(&tcph, 0,
sizeof(TCPHdr));
764 tcph.th_win = htons(5480);
765 tcph.th_seq = htonl(10);
766 tcph.th_ack = htonl(1);
772 p->
tcph->th_seq = htonl(11);
773 p->
tcph->th_ack = htonl(1);
779 p->
tcph->th_seq = htonl(11);
780 p->
tcph->th_ack = htonl(1);
790 p->
tcph->th_seq = htonl(2);
791 p->
tcph->th_ack = htonl(1);
822 static int StreamTcpTest12(
void)
833 memset(&f, 0,
sizeof(
Flow));
836 memset(&tcph, 0,
sizeof(TCPHdr));
842 tcph.th_win = htons(5480);
843 tcph.th_seq = htonl(10);
844 tcph.th_ack = htonl(11);
852 p->
tcph->th_seq = htonl(10);
853 p->
tcph->th_ack = htonl(11);
864 p->
tcph->th_seq = htonl(6);
865 p->
tcph->th_ack = htonl(11);
882 printf(
"failed in setting asynchronous session\n");
887 printf(
"failed in setting state\n");
893 printf(
"failed in seq %" PRIu32
" match\n",
916 static int StreamTcpTest13(
void)
927 memset(&f, 0,
sizeof(
Flow));
930 memset(&tcph, 0,
sizeof(TCPHdr));
936 tcph.th_win = htons(5480);
937 tcph.th_seq = htonl(10);
938 tcph.th_ack = htonl(11);
946 p->
tcph->th_seq = htonl(10);
947 p->
tcph->th_ack = htonl(11);
958 p->
tcph->th_seq = htonl(6);
959 p->
tcph->th_ack = htonl(11);
976 printf(
"failed in setting asynchronous session\n");
981 printf(
"failed in setting state\n");
985 p->
tcph->th_seq = htonl(11);
986 p->
tcph->th_ack = htonl(9);
999 printf(
"failed in seq %" PRIu32
" match\n",
1015 static const char *dummy_conf_string =
"%YAML 1.1\n"
1018 "default-log-dir: /var/log/eidps\n"
1022 " default-log-level: debug\n"
1024 " default-format: \"<%t> - <%l>\"\n"
1026 " default-startup-message: Your IDS has started.\n"
1028 " default-output-filter:\n"
1032 " windows: 192.168.0.1\n"
1034 " linux: 192.168.0.2\n"
1037 static const char *dummy_conf_string1 =
"%YAML 1.1\n"
1040 "default-log-dir: /var/log/eidps\n"
1044 " default-log-level: debug\n"
1046 " default-format: \"<%t> - <%l>\"\n"
1048 " default-startup-message: Your IDS has started.\n"
1050 " default-output-filter:\n"
1054 " windows: 192.168.0.0/24,"
1057 " linux: 192.168.1.0/24,"
1068 static const char *StreamTcpParseOSPolicy(
char *conf_var_name)
1071 char conf_var_type_name[15] =
"host-os-policy";
1072 char *conf_var_full_name = NULL;
1073 const char *conf_var_value = NULL;
1075 if (conf_var_name == NULL)
1079 conf_var_full_name = (
char *)
SCMalloc(strlen(conf_var_type_name) + strlen(conf_var_name) + 2);
1080 if (conf_var_full_name == NULL)
1083 if (snprintf(conf_var_full_name, strlen(conf_var_type_name) + strlen(conf_var_name) + 2,
1084 "%s.%s", conf_var_type_name, conf_var_name) < 0) {
1089 if (
ConfGet(conf_var_full_name, &conf_var_value) != 1) {
1091 conf_var_full_name);
1095 SCLogDebug(
"Value obtained from the yaml conf file, for the var "
1097 conf_var_name, conf_var_value);
1100 if (conf_var_full_name != NULL)
1101 SCFree(conf_var_full_name);
1111 static int StreamTcpTest14(
void)
1120 struct in_addr addr;
1122 char os_policy_name[10] =
"windows";
1123 const char *ip_addr;
1127 memset(&f, 0,
sizeof(
Flow));
1130 memset(&tcph, 0,
sizeof(TCPHdr));
1131 memset(&addr, 0,
sizeof(addr));
1132 memset(&ipv4h, 0,
sizeof(ipv4h));
1145 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
1147 strlcpy(os_policy_name,
"linux\0",
sizeof(os_policy_name));
1148 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
1150 addr.s_addr = inet_addr(
"192.168.0.1");
1151 tcph.th_win = htons(5480);
1152 tcph.th_seq = htonl(10);
1153 tcph.th_ack = htonl(20);
1167 p->
tcph->th_seq = htonl(20);
1168 p->
tcph->th_ack = htonl(13);
1179 p->
tcph->th_seq = htonl(15);
1180 p->
tcph->th_ack = htonl(23);
1191 p->
tcph->th_seq = htonl(14);
1192 p->
tcph->th_ack = htonl(23);
1203 addr.s_addr = inet_addr(
"192.168.0.2");
1204 p->
tcph->th_seq = htonl(25);
1205 p->
tcph->th_ack = htonl(13);
1217 p->
tcph->th_seq = htonl(24);
1218 p->
tcph->th_ack = htonl(13);
1238 printf(
"failed in next_seq match client.next_seq %" PRIu32
""
1239 " server.next_seq %" PRIu32
"\n",
1247 printf(
"failed in setting up OS policy, client.os_policy: %" PRIu8
""
1248 " should be %" PRIu8
" and server.os_policy: %" PRIu8
""
1249 " should be %" PRIu8
"\n",
1273 static int StreamTcp4WHSTest01(
void)
1284 memset(&f, 0,
sizeof(
Flow));
1287 memset(&tcph, 0,
sizeof(TCPHdr));
1293 tcph.th_win = htons(5480);
1294 tcph.th_seq = htonl(10);
1302 p->
tcph->th_seq = htonl(20);
1303 p->
tcph->th_ack = 0;
1311 printf(
"STREAMTCP_FLAG_4WHS flag not set: ");
1315 p->
tcph->th_seq = htonl(10);
1316 p->
tcph->th_ack = htonl(21);
1323 p->
tcph->th_seq = htonl(21);
1324 p->
tcph->th_ack = htonl(10);
1332 printf(
"state is not ESTABLISHED: ");
1353 static int StreamTcp4WHSTest02(
void)
1364 memset(&f, 0,
sizeof(
Flow));
1367 memset(&tcph, 0,
sizeof(TCPHdr));
1373 tcph.th_win = htons(5480);
1374 tcph.th_seq = htonl(10);
1382 p->
tcph->th_seq = htonl(20);
1383 p->
tcph->th_ack = 0;
1391 printf(
"STREAMTCP_FLAG_4WHS flag not set: ");
1395 p->
tcph->th_seq = htonl(30);
1396 p->
tcph->th_ack = htonl(21);
1401 printf(
"SYN/ACK pkt not rejected but it should have: ");
1422 static int StreamTcp4WHSTest03(
void)
1433 memset(&f, 0,
sizeof(
Flow));
1436 memset(&tcph, 0,
sizeof(TCPHdr));
1442 tcph.th_win = htons(5480);
1443 tcph.th_seq = htonl(10);
1451 p->
tcph->th_seq = htonl(20);
1452 p->
tcph->th_ack = 0;
1460 printf(
"STREAMTCP_FLAG_4WHS flag not set: ");
1464 p->
tcph->th_seq = htonl(30);
1465 p->
tcph->th_ack = htonl(11);
1472 p->
tcph->th_seq = htonl(11);
1473 p->
tcph->th_ack = htonl(31);
1481 printf(
"state is not ESTABLISHED: ");
1501 static int StreamTcpTest15(
void)
1510 struct in_addr addr;
1512 char os_policy_name[10] =
"windows";
1513 const char *ip_addr;
1517 memset(&f, 0,
sizeof(
Flow));
1520 memset(&tcph, 0,
sizeof(TCPHdr));
1521 memset(&addr, 0,
sizeof(addr));
1522 memset(&ipv4h, 0,
sizeof(ipv4h));
1535 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
1537 strlcpy(os_policy_name,
"linux\0",
sizeof(os_policy_name));
1538 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
1540 addr.s_addr = inet_addr(
"192.168.0.20");
1541 tcph.th_win = htons(5480);
1542 tcph.th_seq = htonl(10);
1543 tcph.th_ack = htonl(20);
1557 p->
tcph->th_seq = htonl(20);
1558 p->
tcph->th_ack = htonl(13);
1569 p->
tcph->th_seq = htonl(15);
1570 p->
tcph->th_ack = htonl(23);
1581 p->
tcph->th_seq = htonl(14);
1582 p->
tcph->th_ack = htonl(23);
1593 addr.s_addr = inet_addr(
"192.168.1.20");
1594 p->
tcph->th_seq = htonl(25);
1595 p->
tcph->th_ack = htonl(13);
1607 p->
tcph->th_seq = htonl(24);
1608 p->
tcph->th_ack = htonl(13);
1628 printf(
"failed in next_seq match client.next_seq %" PRIu32
""
1629 " server.next_seq %" PRIu32
"\n",
1637 printf(
"failed in setting up OS policy, client.os_policy: %" PRIu8
""
1638 " should be %" PRIu8
" and server.os_policy: %" PRIu8
""
1639 " should be %" PRIu8
"\n",
1663 static int StreamTcpTest16(
void)
1672 struct in_addr addr;
1674 char os_policy_name[10] =
"windows";
1675 const char *ip_addr;
1679 memset(&f, 0,
sizeof(
Flow));
1682 memset(&tcph, 0,
sizeof(TCPHdr));
1683 memset(&addr, 0,
sizeof(addr));
1684 memset(&ipv4h, 0,
sizeof(ipv4h));
1697 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
1699 strlcpy(os_policy_name,
"linux\0",
sizeof(os_policy_name));
1700 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
1702 addr.s_addr = inet_addr(
"192.168.0.1");
1703 tcph.th_win = htons(5480);
1704 tcph.th_seq = htonl(10);
1705 tcph.th_ack = htonl(20);
1719 p->
tcph->th_seq = htonl(20);
1720 p->
tcph->th_ack = htonl(13);
1731 p->
tcph->th_seq = htonl(15);
1732 p->
tcph->th_ack = htonl(23);
1743 p->
tcph->th_seq = htonl(14);
1744 p->
tcph->th_ack = htonl(23);
1755 addr.s_addr = inet_addr(
"192.168.1.1");
1756 p->
tcph->th_seq = htonl(25);
1757 p->
tcph->th_ack = htonl(13);
1769 p->
tcph->th_seq = htonl(24);
1770 p->
tcph->th_ack = htonl(13);
1790 printf(
"failed in next_seq match client.next_seq %" PRIu32
""
1791 " server.next_seq %" PRIu32
"\n",
1799 printf(
"failed in setting up OS policy, client.os_policy: %" PRIu8
""
1800 " should be %" PRIu8
" and server.os_policy: %" PRIu8
""
1801 " should be %" PRIu8
"\n",
1826 static int StreamTcpTest17(
void)
1835 struct in_addr addr;
1837 char os_policy_name[10] =
"windows";
1838 const char *ip_addr;
1842 memset(&f, 0,
sizeof(
Flow));
1845 memset(&tcph, 0,
sizeof(TCPHdr));
1846 memset(&addr, 0,
sizeof(addr));
1847 memset(&ipv4h, 0,
sizeof(ipv4h));
1860 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
1862 strlcpy(os_policy_name,
"linux\0",
sizeof(os_policy_name));
1863 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
1865 addr.s_addr = inet_addr(
"192.168.0.1");
1866 tcph.th_win = htons(5480);
1867 tcph.th_seq = htonl(10);
1868 tcph.th_ack = htonl(20);
1882 p->
tcph->th_seq = htonl(20);
1883 p->
tcph->th_ack = htonl(13);
1894 p->
tcph->th_seq = htonl(15);
1895 p->
tcph->th_ack = htonl(23);
1906 p->
tcph->th_seq = htonl(14);
1907 p->
tcph->th_ack = htonl(23);
1918 addr.s_addr = inet_addr(
"10.1.1.1");
1919 p->
tcph->th_seq = htonl(25);
1920 p->
tcph->th_ack = htonl(13);
1932 p->
tcph->th_seq = htonl(24);
1933 p->
tcph->th_ack = htonl(13);
1953 printf(
"failed in next_seq match client.next_seq %" PRIu32
""
1954 " server.next_seq %" PRIu32
"\n",
1962 printf(
"failed in setting up OS policy, client.os_policy: %" PRIu8
""
1963 " should be %" PRIu8
" and server.os_policy: %" PRIu8
""
1964 " should be %" PRIu8
"\n",
1983 static int StreamTcpTest18(
void)
1986 struct in_addr addr;
1987 char os_policy_name[10] =
"windows";
1988 const char *ip_addr;
1995 memset(&addr, 0,
sizeof(addr));
1996 memset(&stream, 0,
sizeof(stream));
1997 memset(&ipv4h, 0,
sizeof(ipv4h));
2008 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
2013 addr.s_addr = inet_addr(
"192.168.1.1");
2030 static int StreamTcpTest19(
void)
2033 struct in_addr addr;
2034 char os_policy_name[10] =
"windows";
2035 const char *ip_addr;
2042 memset(&addr, 0,
sizeof(addr));
2043 memset(&stream, 0,
sizeof(stream));
2044 memset(&ipv4h, 0,
sizeof(ipv4h));
2055 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
2060 addr.s_addr = inet_addr(
"192.168.0.30");
2065 printf(
"expected os_policy: %" PRIu8
" but received %" PRIu8
": ",
2080 static int StreamTcpTest20(
void)
2083 struct in_addr addr;
2084 char os_policy_name[10] =
"linux";
2085 const char *ip_addr;
2092 memset(&addr, 0,
sizeof(addr));
2093 memset(&stream, 0,
sizeof(stream));
2094 memset(&ipv4h, 0,
sizeof(ipv4h));
2105 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
2110 addr.s_addr = inet_addr(
"192.168.0.1");
2115 printf(
"expected os_policy: %" PRIu8
" but received %" PRIu8
"\n", (uint8_t)
OS_POLICY_LINUX,
2130 static int StreamTcpTest21(
void)
2133 struct in_addr addr;
2134 char os_policy_name[10] =
"linux";
2135 const char *ip_addr;
2142 memset(&addr, 0,
sizeof(addr));
2143 memset(&stream, 0,
sizeof(stream));
2144 memset(&ipv4h, 0,
sizeof(ipv4h));
2155 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
2160 addr.s_addr = inet_addr(
"192.168.1.30");
2165 printf(
"expected os_policy: %" PRIu8
" but received %" PRIu8
"\n", (uint8_t)
OS_POLICY_LINUX,
2180 static int StreamTcpTest22(
void)
2183 struct in_addr addr;
2184 char os_policy_name[10] =
"windows";
2185 const char *ip_addr;
2192 memset(&addr, 0,
sizeof(addr));
2193 memset(&stream, 0,
sizeof(stream));
2194 memset(&ipv4h, 0,
sizeof(ipv4h));
2205 ip_addr = StreamTcpParseOSPolicy(os_policy_name);
2210 addr.s_addr = inet_addr(
"123.231.2.1");
2215 printf(
"expected os_policy: %" PRIu8
" but received %" PRIu8
"\n",
2230 static int StreamTcpTest23(
void)
2236 uint8_t packet[1460] =
"";
2244 memset(&f, 0,
sizeof(
Flow));
2245 memset(&tcph, 0,
sizeof(TCPHdr));
2255 p->
proto = IPPROTO_TCP;
2264 p->
tcph->th_seq = htonl(3184324453UL);
2265 p->
tcph->th_ack = htonl(3373419609UL);
2270 p->
tcph->th_seq = htonl(3184324455UL);
2271 p->
tcph->th_ack = htonl(3373419621UL);
2276 p->
tcph->th_seq = htonl(3184324453UL);
2277 p->
tcph->th_ack = htonl(3373419621UL);
2295 static int StreamTcpTest24(
void)
2303 uint8_t packet[1460] =
"";
2312 memset(&f, 0,
sizeof(
Flow));
2313 memset(&tcph, 0,
sizeof(TCPHdr));
2319 p->
proto = IPPROTO_TCP;
2329 p->
tcph->th_seq = htonl(3184324455UL);
2330 p->
tcph->th_ack = htonl(3373419621UL);
2335 p->
tcph->th_seq = htonl(3184324459UL);
2336 p->
tcph->th_ack = htonl(3373419633UL);
2341 p->
tcph->th_seq = htonl(3184324459UL);
2342 p->
tcph->th_ack = htonl(3373419657UL);
2364 static int StreamTcpTest25(
void)
2377 memset(&f, 0,
sizeof(
Flow));
2380 memset(&tcph, 0,
sizeof(TCPHdr));
2384 tcph.th_win = htons(5480);
2393 p->
tcph->th_ack = htonl(1);
2400 p->
tcph->th_ack = htonl(1);
2401 p->
tcph->th_seq = htonl(1);
2408 p->
tcph->th_ack = htonl(1);
2409 p->
tcph->th_seq = htonl(2);
2424 p->
tcph->th_ack = htonl(1);
2425 p->
tcph->th_seq = htonl(6);
2455 static int StreamTcpTest26(
void)
2468 memset(&f, 0,
sizeof(
Flow));
2471 memset(&tcph, 0,
sizeof(TCPHdr));
2475 tcph.th_win = htons(5480);
2485 p->
tcph->th_ack = htonl(1);
2492 p->
tcph->th_ack = htonl(1);
2493 p->
tcph->th_seq = htonl(1);
2500 p->
tcph->th_ack = htonl(1);
2501 p->
tcph->th_seq = htonl(2);
2516 p->
tcph->th_ack = htonl(1);
2517 p->
tcph->th_seq = htonl(6);
2547 static int StreamTcpTest27(
void)
2560 memset(&f, 0,
sizeof(
Flow));
2563 memset(&tcph, 0,
sizeof(TCPHdr));
2567 tcph.th_win = htons(5480);
2577 p->
tcph->th_ack = htonl(1);
2584 p->
tcph->th_ack = htonl(1);
2585 p->
tcph->th_seq = htonl(1);
2592 p->
tcph->th_ack = htonl(1);
2593 p->
tcph->th_seq = htonl(2);
2608 p->
tcph->th_ack = htonl(1);
2609 p->
tcph->th_seq = htonl(6);
2635 static int StreamTcpTest28(
void)
2666 static int StreamTcpTest29(
void)
2675 struct in_addr addr;
2676 struct in_addr addr1;
2683 memset (&f, 0,
sizeof(
Flow));
2686 memset(&tcph, 0,
sizeof (TCPHdr));
2687 memset (&ipv4h, 0,
sizeof(
IPV4Hdr));
2688 memset (&addr, 0,
sizeof(addr));
2689 memset (&addr1, 0,
sizeof(addr1));
2690 memset (&tcpc, 0,
sizeof(tcpc));
2695 uint8_t packet[1460] =
"";
2706 p.
proto = IPPROTO_TCP;
2717 addr.s_addr = inet_addr(
"10.1.3.53");
2719 addr1.s_addr = inet_addr(
"10.1.3.7");
2728 ssn.
client.ra_base_seq = 10;
2734 ssn.
server.ra_base_seq = 119197101;
2738 p.
tcph->th_seq = htonl(11);
2739 p.
tcph->th_ack = htonl(119197102);
2742 p.
tcph->th_sum = TCPCalculateChecksum((uint16_t *)&(p.
ip4h->
ip_src),
2748 printf(
"failed in segment reassmebling\n");
2755 p.
tcph->th_seq = htonl(119197102);
2756 p.
tcph->th_ack = htonl(15);
2759 p.
tcph->th_sum = TCPCalculateChecksum((uint16_t *)&(p.
ip4h->
ip_src),
2765 printf(
"failed in segment reassmebling\n");
2772 p.
tcph->th_seq = htonl(15);
2773 p.
tcph->th_ack = htonl(119197102);
2776 p.
tcph->th_sum = 12345;
2779 printf(
"failed in segment reassmebling\n");
2785 printf(
"the ssn.state should be TCP_ESTABLISHED(%"PRIu8
"), not %"PRIu8
""
2804 static int StreamTcpTest30(
void)
2813 struct in_addr addr;
2814 struct in_addr addr1;
2821 memset (&f, 0,
sizeof(
Flow));
2824 memset(&tcph, 0,
sizeof (TCPHdr));
2825 memset (&ipv4h, 0,
sizeof(
IPV4Hdr));
2826 memset (&addr, 0,
sizeof(addr));
2827 memset (&addr1, 0,
sizeof(addr1));
2828 memset (&tcpc, 0,
sizeof(tcpc));
2833 uint8_t payload[9] =
"AAAAAAAAA";
2834 uint8_t payload1[9] =
"GET /EVIL";
2835 uint8_t expected_content[9] = { 0x47, 0x45, 0x54, 0x20, 0x2f, 0x45, 0x56,
2847 p.
proto = IPPROTO_TCP;
2857 addr.s_addr = inet_addr(
"10.1.3.53");
2859 addr1.s_addr = inet_addr(
"10.1.3.7");
2868 ssn.
client.ra_base_seq = 10;
2874 ssn.
server.ra_base_seq = 1351079940;
2878 p.
tcph->th_seq = htonl(11);
2879 p.
tcph->th_ack = htonl(1351079940);
2882 p.
tcph->th_sum = 12345;
2885 printf(
"failed in segment reassmebling\n");
2892 p.
tcph->th_seq = htonl(11);
2893 p.
tcph->th_ack = htonl(1351079940);
2897 p.
tcph->th_sum = TCPCalculateChecksum((uint16_t *)&(p.
ip4h->
ip_src),
2903 printf(
"failed in segment reassmebling\n");
2910 p.
tcph->th_seq = htonl(1351079940);
2911 p.
tcph->th_ack = htonl(20);
2914 p.
tcph->th_sum = TCPCalculateChecksum((uint16_t *)&(p.
ip4h->
ip_src),
2920 printf(
"failed in segment reassmebling\n");
2926 printf(
"the contents are not as expected(GET /EVIL), contents are: ");
2945 static int StreamTcpTest31(
void)
2955 struct in_addr addr;
2956 struct in_addr addr1;
2964 memset (&f, 0,
sizeof(
Flow));
2967 memset(&tcph, 0,
sizeof (TCPHdr));
2968 memset (&ipv4h, 0,
sizeof(
IPV4Hdr));
2969 memset (&addr, 0,
sizeof(addr));
2970 memset (&addr1, 0,
sizeof(addr1));
2971 memset (&tcpc, 0,
sizeof(tcpc));
2976 memset(&tcpopt, 0,
sizeof (
TCPOpt));
2987 p.
proto = IPPROTO_TCP;
2996 addr.s_addr = inet_addr(
"10.1.3.53");
2998 addr1.s_addr = inet_addr(
"10.1.3.7");
3007 ssn.
client.ra_base_seq = 10;
3013 ssn.
server.ra_base_seq = 1351079940;
3017 p.
tcph->th_seq = htonl(10);
3021 p.
tcph->th_sum = 12345;
3024 printf(
"failed in segment reassmebling\n");
3031 p.
tcph->th_seq = htonl(10);
3036 p.
tcph->th_sum = TCPCalculateChecksum((uint16_t *)&(p.
ip4h->
ip_src),
3042 printf(
"failed in segment reassmebling\n");
3050 p.
tcph->th_seq = htonl(1351079940);
3051 p.
tcph->th_ack = htonl(11);
3056 p.
tcph->th_sum = TCPCalculateChecksum((uint16_t *)&(p.
ip4h->
ip_src),
3062 printf(
"failed in segment reassmebling\n");
3069 p.
tcph->th_seq = htonl(11);
3070 p.
tcph->th_ack = htonl(1351079941);
3075 p.
tcph->th_sum = TCPCalculateChecksum((uint16_t *)&(p.
ip4h->
ip_src),
3081 printf(
"failed in segment reassmebling\n");
3087 printf(
"the should have been changed to TCP_ESTABLISHED!!\n ");
3103 static int StreamTcpTest32(
void)
3117 memset (&f, 0,
sizeof(
Flow));
3120 memset(&tcph, 0,
sizeof (TCPHdr));
3125 tcph.th_win = htons(5480);
3135 p.
tcph->th_ack = htonl(1);
3140 printf(
"failed in processing packet\n");
3144 p.
tcph->th_ack = htonl(1);
3145 p.
tcph->th_seq = htonl(1);
3150 printf(
"failed in processing packet\n");
3154 p.
tcph->th_ack = htonl(1);
3155 p.
tcph->th_seq = htonl(2);
3164 printf(
"failed in processing packet\n");
3171 printf(
"failed in processing packet\n");
3176 printf(
"the TCP state should be TCP_ESTABLISEHD\n");
3195 static int StreamTcpTest33 (
void)
3207 memset (&f, 0,
sizeof(
Flow));
3210 memset(&tcph, 0,
sizeof (TCPHdr));
3214 tcph.th_win = htons(5480);
3226 p.
tcph->th_ack = htonl(1);
3233 p.
tcph->th_ack = htonl(1);
3234 p.
tcph->th_seq = htonl(1);
3241 p.
tcph->th_ack = htonl(1);
3242 p.
tcph->th_seq = htonl(1);
3250 printf(
"Tcp session should have been closed\n");
3254 p.
tcph->th_seq = htonl(1);
3261 p.
tcph->th_seq = htonl(1);
3262 p.
tcph->th_ack = htonl(2);
3269 p.
tcph->th_ack = htonl(2);
3270 p.
tcph->th_seq = htonl(2);
3278 printf(
"Tcp session should have been ESTABLISHED\n");
3296 static int StreamTcpTest34 (
void)
3308 memset (&f, 0,
sizeof(
Flow));
3311 memset(&tcph, 0,
sizeof (TCPHdr));
3315 tcph.th_win = htons(5480);
3327 p.
tcph->th_ack = htonl(1);
3334 p.
tcph->th_ack = htonl(1);
3335 p.
tcph->th_seq = htonl(1);
3343 printf(
"Tcp session should have been establisehd\n");
3361 static int StreamTcpTest35 (
void)
3373 memset (&f, 0,
sizeof(
Flow));
3376 memset(&tcph, 0,
sizeof (TCPHdr));
3380 tcph.th_win = htons(5480);
3392 p.
tcph->th_ack = htonl(1);
3399 p.
tcph->th_ack = htonl(1);
3400 p.
tcph->th_seq = htonl(1);
3408 printf(
"Tcp session should have been establisehd\n");
3424 static int StreamTcpTest36(
void)
3438 memset (&f, 0,
sizeof(
Flow));
3441 memset(&tcph, 0,
sizeof (TCPHdr));
3446 tcph.th_win = htons(5480);
3454 printf(
"failed in processing packet\n");
3458 p.
tcph->th_ack = htonl(1);
3463 printf(
"failed in processing packet\n");
3467 p.
tcph->th_ack = htonl(1);
3468 p.
tcph->th_seq = htonl(1);
3473 printf(
"failed in processing packet\n");
3478 printf(
"the TCP state should be TCP_ESTABLISEHD\n");
3482 p.
tcph->th_ack = htonl(2);
3483 p.
tcph->th_seq = htonl(1);
3492 printf(
"failed in processing packet\n");
3497 printf(
"the ssn->client.next_seq should be 4, but it is %"PRIu32
"\n",
3516 static int StreamTcpTest37(
void)
3529 memset(&f, 0,
sizeof(
Flow));
3532 memset(&tcph, 0,
sizeof(TCPHdr));
3537 tcph.th_win = htons(5480);
3545 printf(
"failed in processing packet\n");
3549 p->
tcph->th_ack = htonl(1);
3554 printf(
"failed in processing packet\n");
3558 p->
tcph->th_ack = htonl(1);
3559 p->
tcph->th_seq = htonl(1);
3564 printf(
"failed in processing packet\n");
3569 printf(
"the TCP state should be TCP_ESTABLISEHD\n");
3573 p->
tcph->th_ack = htonl(2);
3574 p->
tcph->th_seq = htonl(4);
3579 printf(
"failed in processing packet\n");
3584 printf(
"the TCP state should be TCP_CLOSE_WAIT\n");
3588 p->
tcph->th_ack = htonl(1);
3589 p->
tcph->th_seq = htonl(1);
3598 printf(
"failed in processing packet\n");
3602 p->
tcph->th_ack = htonl(4);
3603 p->
tcph->th_seq = htonl(2);
3609 printf(
"failed in processing packet\n");
3633 static int StreamTcpTest38(
void)
3639 uint8_t payload[128];
3643 memset(&f, 0,
sizeof(
Flow));
3646 memset(&tcph, 0,
sizeof(TCPHdr));
3654 tcph.th_win = htons(5480);
3661 printf(
"failed in processing packet in StreamTcpPacket\n");
3665 p->
tcph->th_ack = htonl(1);
3670 printf(
"failed in processing packet in StreamTcpPacket\n");
3674 p->
tcph->th_ack = htonl(1);
3675 p->
tcph->th_seq = htonl(1);
3680 printf(
"failed in processing packet in StreamTcpPacket\n");
3684 p->
tcph->th_ack = htonl(29847);
3685 p->
tcph->th_seq = htonl(2);
3694 printf(
"failed in processing packet in StreamTcpPacket\n");
3701 printf(
"the server.last_ack should be 1, but it is %" PRIu32
"\n",
3706 p->
tcph->th_ack = htonl(1);
3707 p->
tcph->th_seq = htonl(1);
3716 printf(
"failed in processing packet in StreamTcpPacket\n");
3721 printf(
"the server.next_seq should be 128, but it is %" PRIu32
"\n",
3726 p->
tcph->th_ack = htonl(256);
3727 p->
tcph->th_seq = htonl(5);
3736 printf(
"failed in processing packet in StreamTcpPacket\n");
3743 printf(
"the server.last_ack should be 1, but it is %" PRIu32
"\n",
3748 p->
tcph->th_ack = htonl(128);
3749 p->
tcph->th_seq = htonl(8);
3758 printf(
"failed in processing packet in StreamTcpPacket\n");
3765 printf(
"the server.last_ack should be 256, but it is %" PRIu32
"\n",
3787 static int StreamTcpTest39(
void)
3796 memset(&f, 0,
sizeof(
Flow));
3799 memset(&tcph, 0,
sizeof(TCPHdr));
3807 tcph.th_win = htons(5480);
3816 printf(
"failed in processing packet in StreamTcpPacket\n");
3820 p->
tcph->th_ack = htonl(1);
3825 printf(
"failed in processing packet in StreamTcpPacket\n");
3829 p->
tcph->th_ack = htonl(1);
3830 p->
tcph->th_seq = htonl(1);
3835 printf(
"failed in processing packet in StreamTcpPacket\n");
3839 p->
tcph->th_ack = htonl(1);
3840 p->
tcph->th_seq = htonl(1);
3849 printf(
"failed in processing packet in StreamTcpPacket\n");
3854 printf(
"the server.next_seq should be 4, but it is %" PRIu32
"\n",
3859 p->
tcph->th_ack = htonl(4);
3860 p->
tcph->th_seq = htonl(2);
3869 printf(
"failed in processing packet in StreamTcpPacket\n");
3876 printf(
"the server.last_ack should be 4, but it is %" PRIu32
"\n",
3881 p->
tcph->th_seq = htonl(4);
3882 p->
tcph->th_ack = htonl(5);
3891 printf(
"failed in processing packet in StreamTcpPacket\n");
3898 printf(
"the server.next_seq should be 7, but it is %" PRIu32
"\n",
3914 static int StreamTcpTest42(
void)
3927 memset(&f, 0,
sizeof(
Flow));
3930 memset(&tcph, 0,
sizeof(TCPHdr));
3936 tcph.th_win = htons(5480);
3941 tcph.th_seq = htonl(100);
3948 p->
tcph->th_seq = htonl(500);
3949 p->
tcph->th_ack = htonl(101);
3957 p->
tcph->th_seq = htonl(1000);
3958 p->
tcph->th_ack = htonl(101);
3966 p->
tcph->th_ack = htonl(501);
3967 p->
tcph->th_seq = htonl(101);
3977 printf(
"state not TCP_ESTABLISHED: ");
4001 static int StreamTcpTest43(
void)
4014 memset(&f, 0,
sizeof(
Flow));
4017 memset(&tcph, 0,
sizeof(TCPHdr));
4023 tcph.th_win = htons(5480);
4028 tcph.th_seq = htonl(100);
4035 p->
tcph->th_seq = htonl(500);
4036 p->
tcph->th_ack = htonl(101);
4044 p->
tcph->th_seq = htonl(1000);
4045 p->
tcph->th_ack = htonl(101);
4053 p->
tcph->th_ack = htonl(1001);
4054 p->
tcph->th_seq = htonl(101);
4064 printf(
"state not TCP_ESTABLISHED: ");
4088 static int StreamTcpTest44(
void)
4101 memset(&f, 0,
sizeof(
Flow));
4104 memset(&tcph, 0,
sizeof(TCPHdr));
4110 tcph.th_win = htons(5480);
4115 tcph.th_seq = htonl(100);
4122 p->
tcph->th_seq = htonl(500);
4123 p->
tcph->th_ack = htonl(101);
4131 p->
tcph->th_seq = htonl(1000);
4132 p->
tcph->th_ack = htonl(101);
4140 p->
tcph->th_ack = htonl(3001);
4141 p->
tcph->th_seq = htonl(101);
4171 static int StreamTcpTest45(
void)
4184 memset(&f, 0,
sizeof(
Flow));
4187 memset(&tcph, 0,
sizeof(TCPHdr));
4194 tcph.th_win = htons(5480);
4199 tcph.th_seq = htonl(100);
4206 p->
tcph->th_seq = htonl(500);
4207 p->
tcph->th_ack = htonl(101);
4215 p->
tcph->th_seq = htonl(1000);
4216 p->
tcph->th_ack = htonl(101);
4224 p->
tcph->th_seq = htonl(2000);
4225 p->
tcph->th_ack = htonl(101);
4233 p->
tcph->th_seq = htonl(3000);
4234 p->
tcph->th_ack = htonl(101);
4242 p->
tcph->th_ack = htonl(1001);
4243 p->
tcph->th_seq = htonl(101);
4253 printf(
"state not TCP_ESTABLISHED: ");
4277 UtRegisterTest(
"StreamTcpTest01 -- TCP session allocation", StreamTcpTest01);
4278 UtRegisterTest(
"StreamTcpTest02 -- TCP session deallocation", StreamTcpTest02);
4279 UtRegisterTest(
"StreamTcpTest03 -- SYN missed MidStream session", StreamTcpTest03);
4280 UtRegisterTest(
"StreamTcpTest04 -- SYN/ACK missed MidStream session", StreamTcpTest04);
4281 UtRegisterTest(
"StreamTcpTest05 -- 3WHS missed MidStream session", StreamTcpTest05);
4282 UtRegisterTest(
"StreamTcpTest06 -- FIN, RST message MidStream session", StreamTcpTest06);
4283 UtRegisterTest(
"StreamTcpTest07 -- PAWS invalid timestamp", StreamTcpTest07);
4284 UtRegisterTest(
"StreamTcpTest08 -- PAWS valid timestamp", StreamTcpTest08);
4285 UtRegisterTest(
"StreamTcpTest09 -- No Client Reassembly", StreamTcpTest09);
4286 UtRegisterTest(
"StreamTcpTest10 -- No missed packet Async stream", StreamTcpTest10);
4287 UtRegisterTest(
"StreamTcpTest11 -- SYN missed Async stream", StreamTcpTest11);
4288 UtRegisterTest(
"StreamTcpTest12 -- SYN/ACK missed Async stream", StreamTcpTest12);
4289 UtRegisterTest(
"StreamTcpTest13 -- opposite stream packets for Async "
4295 UtRegisterTest(
"StreamTcpTest14 -- setup OS policy", StreamTcpTest14);
4296 UtRegisterTest(
"StreamTcpTest15 -- setup OS policy", StreamTcpTest15);
4297 UtRegisterTest(
"StreamTcpTest16 -- setup OS policy", StreamTcpTest16);
4298 UtRegisterTest(
"StreamTcpTest17 -- setup OS policy", StreamTcpTest17);
4299 UtRegisterTest(
"StreamTcpTest18 -- setup OS policy", StreamTcpTest18);
4300 UtRegisterTest(
"StreamTcpTest19 -- setup OS policy", StreamTcpTest19);
4301 UtRegisterTest(
"StreamTcpTest20 -- setup OS policy", StreamTcpTest20);
4302 UtRegisterTest(
"StreamTcpTest21 -- setup OS policy", StreamTcpTest21);
4303 UtRegisterTest(
"StreamTcpTest22 -- setup OS policy", StreamTcpTest22);
4304 UtRegisterTest(
"StreamTcpTest23 -- stream memory leaks", StreamTcpTest23);
4305 UtRegisterTest(
"StreamTcpTest24 -- stream memory leaks", StreamTcpTest24);
4306 UtRegisterTest(
"StreamTcpTest25 -- test ecn/cwr sessions", StreamTcpTest25);
4307 UtRegisterTest(
"StreamTcpTest26 -- test ecn/cwr sessions", StreamTcpTest26);
4308 UtRegisterTest(
"StreamTcpTest27 -- test ecn/cwr sessions", StreamTcpTest27);
4309 UtRegisterTest(
"StreamTcpTest28 -- Memcap Test", StreamTcpTest28);
4314 UtRegisterTest(
"StreamTcpTest29 -- Badchecksum Reset Test", StreamTcpTest29, 1);
4315 UtRegisterTest(
"StreamTcpTest30 -- Badchecksum Overlap Test", StreamTcpTest30, 1);
4316 UtRegisterTest(
"StreamTcpTest31 -- MultipleSyns Test", StreamTcpTest31, 1);
4317 UtRegisterTest(
"StreamTcpTest32 -- Bogus CWR Test", StreamTcpTest32, 1);
4318 UtRegisterTest(
"StreamTcpTest33 -- RST-SYN Again Test", StreamTcpTest33, 1);
4319 UtRegisterTest(
"StreamTcpTest34 -- SYN-PUSH Test", StreamTcpTest34, 1);
4320 UtRegisterTest(
"StreamTcpTest35 -- SYN-URG Test", StreamTcpTest35, 1);
4321 UtRegisterTest(
"StreamTcpTest36 -- PUSH-URG Test", StreamTcpTest36, 1);
4323 UtRegisterTest(
"StreamTcpTest37 -- Out of order FIN Test", StreamTcpTest37);
4325 UtRegisterTest(
"StreamTcpTest38 -- validate ACK", StreamTcpTest38);
4326 UtRegisterTest(
"StreamTcpTest39 -- update next_seq", StreamTcpTest39);
4328 UtRegisterTest(
"StreamTcpTest42 -- SYN/ACK queue", StreamTcpTest42);
4329 UtRegisterTest(
"StreamTcpTest43 -- SYN/ACK queue", StreamTcpTest43);
4330 UtRegisterTest(
"StreamTcpTest44 -- SYN/ACK queue", StreamTcpTest44);
4331 UtRegisterTest(
"StreamTcpTest45 -- SYN/ACK queue", StreamTcpTest45);