test_tcp_oos.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. #include "test_tcp_oos.h"
  2. #include "lwip/priv/tcp_priv.h"
  3. #include "lwip/stats.h"
  4. #include "tcp_helper.h"
  5. #if !LWIP_STATS || !TCP_STATS || !MEMP_STATS
  6. #error "This tests needs TCP- and MEMP-statistics enabled"
  7. #endif
  8. #if !TCP_QUEUE_OOSEQ
  9. #error "This tests needs TCP_QUEUE_OOSEQ enabled"
  10. #endif
  11. /** CHECK_SEGMENTS_ON_OOSEQ:
  12. * 1: check count, seqno and len of segments on pcb->ooseq (strict)
  13. * 0: only check that bytes are received in correct order (less strict) */
  14. #define CHECK_SEGMENTS_ON_OOSEQ 1
  15. #if CHECK_SEGMENTS_ON_OOSEQ
  16. #define EXPECT_OOSEQ(x) EXPECT(x)
  17. #else
  18. #define EXPECT_OOSEQ(x)
  19. #endif
  20. /* helper functions */
  21. /** Get the numbers of segments on the ooseq list */
  22. static int tcp_oos_count(struct tcp_pcb* pcb)
  23. {
  24. int num = 0;
  25. struct tcp_seg* seg = pcb->ooseq;
  26. while(seg != NULL) {
  27. num++;
  28. seg = seg->next;
  29. }
  30. return num;
  31. }
  32. #if TCP_OOSEQ_MAX_PBUFS && (TCP_OOSEQ_MAX_PBUFS < ((TCP_WND / TCP_MSS) + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
  33. /** Get the numbers of pbufs on the ooseq list */
  34. static int tcp_oos_pbuf_count(struct tcp_pcb* pcb)
  35. {
  36. int num = 0;
  37. struct tcp_seg* seg = pcb->ooseq;
  38. while(seg != NULL) {
  39. num += pbuf_clen(seg->p);
  40. seg = seg->next;
  41. }
  42. return num;
  43. }
  44. #endif
  45. /** Get the seqno of a segment (by index) on the ooseq list
  46. *
  47. * @param pcb the pcb to check for ooseq segments
  48. * @param seg_index index of the segment on the ooseq list
  49. * @return seqno of the segment
  50. */
  51. static u32_t
  52. tcp_oos_seg_seqno(struct tcp_pcb* pcb, int seg_index)
  53. {
  54. int num = 0;
  55. struct tcp_seg* seg = pcb->ooseq;
  56. /* then check the actual segment */
  57. while(seg != NULL) {
  58. if(num == seg_index) {
  59. return seg->tcphdr->seqno;
  60. }
  61. num++;
  62. seg = seg->next;
  63. }
  64. fail();
  65. return 0;
  66. }
  67. /** Get the tcplen (datalen + SYN/FIN) of a segment (by index) on the ooseq list
  68. *
  69. * @param pcb the pcb to check for ooseq segments
  70. * @param seg_index index of the segment on the ooseq list
  71. * @return tcplen of the segment
  72. */
  73. static int
  74. tcp_oos_seg_tcplen(struct tcp_pcb* pcb, int seg_index)
  75. {
  76. int num = 0;
  77. struct tcp_seg* seg = pcb->ooseq;
  78. /* then check the actual segment */
  79. while(seg != NULL) {
  80. if(num == seg_index) {
  81. return TCP_TCPLEN(seg);
  82. }
  83. num++;
  84. seg = seg->next;
  85. }
  86. fail();
  87. return -1;
  88. }
  89. /** Get the tcplen (datalen + SYN/FIN) of all segments on the ooseq list
  90. *
  91. * @param pcb the pcb to check for ooseq segments
  92. * @return tcplen of all segment
  93. */
  94. static int
  95. tcp_oos_tcplen(struct tcp_pcb* pcb)
  96. {
  97. int len = 0;
  98. struct tcp_seg* seg = pcb->ooseq;
  99. /* then check the actual segment */
  100. while(seg != NULL) {
  101. len += TCP_TCPLEN(seg);
  102. seg = seg->next;
  103. }
  104. return len;
  105. }
  106. /* Setup/teardown functions */
  107. static struct netif *old_netif_list;
  108. static struct netif *old_netif_default;
  109. static void
  110. tcp_oos_setup(void)
  111. {
  112. old_netif_list = netif_list;
  113. old_netif_default = netif_default;
  114. netif_list = NULL;
  115. netif_default = NULL;
  116. tcp_remove_all();
  117. lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
  118. }
  119. static void
  120. tcp_oos_teardown(void)
  121. {
  122. netif_list = NULL;
  123. netif_default = NULL;
  124. tcp_remove_all();
  125. /* restore netif_list for next tests (e.g. loopif) */
  126. netif_list = old_netif_list;
  127. netif_default = old_netif_default;
  128. lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
  129. }
  130. /* Test functions */
  131. /** create multiple segments and pass them to tcp_input in a wrong
  132. * order to see if ooseq-caching works correctly
  133. * FIN is received in out-of-sequence segments only */
  134. START_TEST(test_tcp_recv_ooseq_FIN_OOSEQ)
  135. {
  136. struct test_tcp_counters counters;
  137. struct tcp_pcb* pcb;
  138. struct pbuf *p_8_9, *p_4_8, *p_4_10, *p_2_14, *p_fin, *pinseq;
  139. char data[] = {
  140. 1, 2, 3, 4,
  141. 5, 6, 7, 8,
  142. 9, 10, 11, 12,
  143. 13, 14, 15, 16};
  144. u16_t data_len;
  145. struct netif netif;
  146. LWIP_UNUSED_ARG(_i);
  147. /* initialize local vars */
  148. test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
  149. data_len = sizeof(data);
  150. /* initialize counter struct */
  151. memset(&counters, 0, sizeof(counters));
  152. counters.expected_data_len = data_len;
  153. counters.expected_data = data;
  154. /* create and initialize the pcb */
  155. pcb = test_tcp_new_counters_pcb(&counters);
  156. EXPECT_RET(pcb != NULL);
  157. tcp_set_state(pcb, ESTABLISHED, &test_local_ip, &test_remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
  158. /* create segments */
  159. /* pinseq is sent as last segment! */
  160. pinseq = tcp_create_rx_segment(pcb, &data[0], 4, 0, 0, TCP_ACK);
  161. /* p1: 8 bytes before FIN */
  162. /* seqno: 8..16 */
  163. p_8_9 = tcp_create_rx_segment(pcb, &data[8], 8, 8, 0, TCP_ACK|TCP_FIN);
  164. /* p2: 4 bytes before p1, including the first 4 bytes of p1 (partly duplicate) */
  165. /* seqno: 4..11 */
  166. p_4_8 = tcp_create_rx_segment(pcb, &data[4], 8, 4, 0, TCP_ACK);
  167. /* p3: same as p2 but 2 bytes longer */
  168. /* seqno: 4..13 */
  169. p_4_10 = tcp_create_rx_segment(pcb, &data[4], 10, 4, 0, TCP_ACK);
  170. /* p4: 14 bytes before FIN, includes data from p1 and p2, plus partly from pinseq */
  171. /* seqno: 2..15 */
  172. p_2_14 = tcp_create_rx_segment(pcb, &data[2], 14, 2, 0, TCP_ACK);
  173. /* FIN, seqno 16 */
  174. p_fin = tcp_create_rx_segment(pcb, NULL, 0,16, 0, TCP_ACK|TCP_FIN);
  175. EXPECT(pinseq != NULL);
  176. EXPECT(p_8_9 != NULL);
  177. EXPECT(p_4_8 != NULL);
  178. EXPECT(p_4_10 != NULL);
  179. EXPECT(p_2_14 != NULL);
  180. EXPECT(p_fin != NULL);
  181. if ((pinseq != NULL) && (p_8_9 != NULL) && (p_4_8 != NULL) && (p_4_10 != NULL) && (p_2_14 != NULL) && (p_fin != NULL)) {
  182. /* pass the segment to tcp_input */
  183. test_tcp_input(p_8_9, &netif);
  184. /* check if counters are as expected */
  185. EXPECT(counters.close_calls == 0);
  186. EXPECT(counters.recv_calls == 0);
  187. EXPECT(counters.recved_bytes == 0);
  188. EXPECT(counters.err_calls == 0);
  189. /* check ooseq queue */
  190. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  191. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 8);
  192. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 9); /* includes FIN */
  193. /* pass the segment to tcp_input */
  194. test_tcp_input(p_4_8, &netif);
  195. /* check if counters are as expected */
  196. EXPECT(counters.close_calls == 0);
  197. EXPECT(counters.recv_calls == 0);
  198. EXPECT(counters.recved_bytes == 0);
  199. EXPECT(counters.err_calls == 0);
  200. /* check ooseq queue */
  201. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  202. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 4);
  203. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 4);
  204. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 8);
  205. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 9); /* includes FIN */
  206. /* pass the segment to tcp_input */
  207. test_tcp_input(p_4_10, &netif);
  208. /* check if counters are as expected */
  209. EXPECT(counters.close_calls == 0);
  210. EXPECT(counters.recv_calls == 0);
  211. EXPECT(counters.recved_bytes == 0);
  212. EXPECT(counters.err_calls == 0);
  213. /* ooseq queue: unchanged */
  214. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  215. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 4);
  216. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 4);
  217. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 8);
  218. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 9); /* includes FIN */
  219. /* pass the segment to tcp_input */
  220. test_tcp_input(p_2_14, &netif);
  221. /* check if counters are as expected */
  222. EXPECT(counters.close_calls == 0);
  223. EXPECT(counters.recv_calls == 0);
  224. EXPECT(counters.recved_bytes == 0);
  225. EXPECT(counters.err_calls == 0);
  226. /* check ooseq queue */
  227. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  228. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 2);
  229. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 15); /* includes FIN */
  230. /* pass the segment to tcp_input */
  231. test_tcp_input(p_fin, &netif);
  232. /* check if counters are as expected */
  233. EXPECT(counters.close_calls == 0);
  234. EXPECT(counters.recv_calls == 0);
  235. EXPECT(counters.recved_bytes == 0);
  236. EXPECT(counters.err_calls == 0);
  237. /* ooseq queue: unchanged */
  238. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  239. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 2);
  240. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 15); /* includes FIN */
  241. /* pass the segment to tcp_input */
  242. test_tcp_input(pinseq, &netif);
  243. /* check if counters are as expected */
  244. EXPECT(counters.close_calls == 1);
  245. EXPECT(counters.recv_calls == 1);
  246. EXPECT(counters.recved_bytes == data_len);
  247. EXPECT(counters.err_calls == 0);
  248. EXPECT(pcb->ooseq == NULL);
  249. }
  250. /* make sure the pcb is freed */
  251. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
  252. tcp_abort(pcb);
  253. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
  254. }
  255. END_TEST
  256. /** create multiple segments and pass them to tcp_input in a wrong
  257. * order to see if ooseq-caching works correctly
  258. * FIN is received IN-SEQUENCE at the end */
  259. START_TEST(test_tcp_recv_ooseq_FIN_INSEQ)
  260. {
  261. struct test_tcp_counters counters;
  262. struct tcp_pcb* pcb;
  263. struct pbuf *p_1_2, *p_4_8, *p_3_11, *p_2_12, *p_15_1, *p_15_1a, *pinseq, *pinseqFIN;
  264. char data[] = {
  265. 1, 2, 3, 4,
  266. 5, 6, 7, 8,
  267. 9, 10, 11, 12,
  268. 13, 14, 15, 16};
  269. u16_t data_len;
  270. struct netif netif;
  271. LWIP_UNUSED_ARG(_i);
  272. /* initialize local vars */
  273. test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
  274. data_len = sizeof(data);
  275. /* initialize counter struct */
  276. memset(&counters, 0, sizeof(counters));
  277. counters.expected_data_len = data_len;
  278. counters.expected_data = data;
  279. /* create and initialize the pcb */
  280. pcb = test_tcp_new_counters_pcb(&counters);
  281. EXPECT_RET(pcb != NULL);
  282. tcp_set_state(pcb, ESTABLISHED, &test_local_ip, &test_remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
  283. /* create segments */
  284. /* p1: 7 bytes - 2 before FIN */
  285. /* seqno: 1..2 */
  286. p_1_2 = tcp_create_rx_segment(pcb, &data[1], 2, 1, 0, TCP_ACK);
  287. /* p2: 4 bytes before p1, including the first 4 bytes of p1 (partly duplicate) */
  288. /* seqno: 4..11 */
  289. p_4_8 = tcp_create_rx_segment(pcb, &data[4], 8, 4, 0, TCP_ACK);
  290. /* p3: same as p2 but 2 bytes longer and one byte more at the front */
  291. /* seqno: 3..13 */
  292. p_3_11 = tcp_create_rx_segment(pcb, &data[3], 11, 3, 0, TCP_ACK);
  293. /* p4: 13 bytes - 2 before FIN - should be ignored as contained in p1 and p3 */
  294. /* seqno: 2..13 */
  295. p_2_12 = tcp_create_rx_segment(pcb, &data[2], 12, 2, 0, TCP_ACK);
  296. /* pinseq is the first segment that is held back to create ooseq! */
  297. /* seqno: 0..3 */
  298. pinseq = tcp_create_rx_segment(pcb, &data[0], 4, 0, 0, TCP_ACK);
  299. /* p5: last byte before FIN */
  300. /* seqno: 15 */
  301. p_15_1 = tcp_create_rx_segment(pcb, &data[15], 1, 15, 0, TCP_ACK);
  302. /* p6: same as p5, should be ignored */
  303. p_15_1a= tcp_create_rx_segment(pcb, &data[15], 1, 15, 0, TCP_ACK);
  304. /* pinseqFIN: last 2 bytes plus FIN */
  305. /* only segment containing seqno 14 and FIN */
  306. pinseqFIN = tcp_create_rx_segment(pcb, &data[14], 2, 14, 0, TCP_ACK|TCP_FIN);
  307. EXPECT(pinseq != NULL);
  308. EXPECT(p_1_2 != NULL);
  309. EXPECT(p_4_8 != NULL);
  310. EXPECT(p_3_11 != NULL);
  311. EXPECT(p_2_12 != NULL);
  312. EXPECT(p_15_1 != NULL);
  313. EXPECT(p_15_1a != NULL);
  314. EXPECT(pinseqFIN != NULL);
  315. if ((pinseq != NULL) && (p_1_2 != NULL) && (p_4_8 != NULL) && (p_3_11 != NULL) && (p_2_12 != NULL)
  316. && (p_15_1 != NULL) && (p_15_1a != NULL) && (pinseqFIN != NULL)) {
  317. /* pass the segment to tcp_input */
  318. test_tcp_input(p_1_2, &netif);
  319. /* check if counters are as expected */
  320. EXPECT(counters.close_calls == 0);
  321. EXPECT(counters.recv_calls == 0);
  322. EXPECT(counters.recved_bytes == 0);
  323. EXPECT(counters.err_calls == 0);
  324. /* check ooseq queue */
  325. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  326. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
  327. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
  328. /* pass the segment to tcp_input */
  329. test_tcp_input(p_4_8, &netif);
  330. /* check if counters are as expected */
  331. EXPECT(counters.close_calls == 0);
  332. EXPECT(counters.recv_calls == 0);
  333. EXPECT(counters.recved_bytes == 0);
  334. EXPECT(counters.err_calls == 0);
  335. /* check ooseq queue */
  336. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  337. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
  338. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
  339. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 4);
  340. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 8);
  341. /* pass the segment to tcp_input */
  342. test_tcp_input(p_3_11, &netif);
  343. /* check if counters are as expected */
  344. EXPECT(counters.close_calls == 0);
  345. EXPECT(counters.recv_calls == 0);
  346. EXPECT(counters.recved_bytes == 0);
  347. EXPECT(counters.err_calls == 0);
  348. /* check ooseq queue */
  349. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  350. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
  351. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
  352. /* p_3_11 has removed p_4_8 from ooseq */
  353. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 3);
  354. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 11);
  355. /* pass the segment to tcp_input */
  356. test_tcp_input(p_2_12, &netif);
  357. /* check if counters are as expected */
  358. EXPECT(counters.close_calls == 0);
  359. EXPECT(counters.recv_calls == 0);
  360. EXPECT(counters.recved_bytes == 0);
  361. EXPECT(counters.err_calls == 0);
  362. /* check ooseq queue */
  363. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  364. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
  365. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
  366. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 2);
  367. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 12);
  368. /* pass the segment to tcp_input */
  369. test_tcp_input(pinseq, &netif);
  370. /* check if counters are as expected */
  371. EXPECT(counters.close_calls == 0);
  372. EXPECT(counters.recv_calls == 1);
  373. EXPECT(counters.recved_bytes == 14);
  374. EXPECT(counters.err_calls == 0);
  375. EXPECT(pcb->ooseq == NULL);
  376. /* pass the segment to tcp_input */
  377. test_tcp_input(p_15_1, &netif);
  378. /* check if counters are as expected */
  379. EXPECT(counters.close_calls == 0);
  380. EXPECT(counters.recv_calls == 1);
  381. EXPECT(counters.recved_bytes == 14);
  382. EXPECT(counters.err_calls == 0);
  383. /* check ooseq queue */
  384. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  385. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 15);
  386. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
  387. /* pass the segment to tcp_input */
  388. test_tcp_input(p_15_1a, &netif);
  389. /* check if counters are as expected */
  390. EXPECT(counters.close_calls == 0);
  391. EXPECT(counters.recv_calls == 1);
  392. EXPECT(counters.recved_bytes == 14);
  393. EXPECT(counters.err_calls == 0);
  394. /* check ooseq queue: unchanged */
  395. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  396. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 15);
  397. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
  398. /* pass the segment to tcp_input */
  399. test_tcp_input(pinseqFIN, &netif);
  400. /* check if counters are as expected */
  401. EXPECT(counters.close_calls == 1);
  402. EXPECT(counters.recv_calls == 2);
  403. EXPECT(counters.recved_bytes == data_len);
  404. EXPECT(counters.err_calls == 0);
  405. EXPECT(pcb->ooseq == NULL);
  406. }
  407. /* make sure the pcb is freed */
  408. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
  409. tcp_abort(pcb);
  410. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
  411. }
  412. END_TEST
  413. static char data_full_wnd[TCP_WND + TCP_MSS];
  414. /** create multiple segments and pass them to tcp_input with the first segment missing
  415. * to simulate overruning the rxwin with ooseq queueing enabled */
  416. START_TEST(test_tcp_recv_ooseq_overrun_rxwin)
  417. {
  418. #if !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS
  419. int i, k;
  420. struct test_tcp_counters counters;
  421. struct tcp_pcb* pcb;
  422. struct pbuf *pinseq, *p_ovr;
  423. struct netif netif;
  424. int datalen = 0;
  425. int datalen2;
  426. for(i = 0; i < (int)sizeof(data_full_wnd); i++) {
  427. data_full_wnd[i] = (char)i;
  428. }
  429. /* initialize local vars */
  430. test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
  431. /* initialize counter struct */
  432. memset(&counters, 0, sizeof(counters));
  433. counters.expected_data_len = TCP_WND;
  434. counters.expected_data = data_full_wnd;
  435. /* create and initialize the pcb */
  436. pcb = test_tcp_new_counters_pcb(&counters);
  437. EXPECT_RET(pcb != NULL);
  438. tcp_set_state(pcb, ESTABLISHED, &test_local_ip, &test_remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
  439. pcb->rcv_nxt = 0x8000;
  440. /* create segments */
  441. /* pinseq is sent as last segment! */
  442. pinseq = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
  443. for(i = TCP_MSS, k = 0; i < TCP_WND; i += TCP_MSS, k++) {
  444. int count, expected_datalen;
  445. struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)],
  446. TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
  447. EXPECT_RET(p != NULL);
  448. /* pass the segment to tcp_input */
  449. test_tcp_input(p, &netif);
  450. /* check if counters are as expected */
  451. EXPECT(counters.close_calls == 0);
  452. EXPECT(counters.recv_calls == 0);
  453. EXPECT(counters.recved_bytes == 0);
  454. EXPECT(counters.err_calls == 0);
  455. /* check ooseq queue */
  456. count = tcp_oos_count(pcb);
  457. EXPECT_OOSEQ(count == k+1);
  458. datalen = tcp_oos_tcplen(pcb);
  459. if (i + TCP_MSS < TCP_WND) {
  460. expected_datalen = (k+1)*TCP_MSS;
  461. } else {
  462. expected_datalen = TCP_WND - TCP_MSS;
  463. }
  464. if (datalen != expected_datalen) {
  465. EXPECT_OOSEQ(datalen == expected_datalen);
  466. }
  467. }
  468. /* pass in one more segment, cleary overrunning the rxwin */
  469. p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)], TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
  470. EXPECT_RET(p_ovr != NULL);
  471. /* pass the segment to tcp_input */
  472. test_tcp_input(p_ovr, &netif);
  473. /* check if counters are as expected */
  474. EXPECT(counters.close_calls == 0);
  475. EXPECT(counters.recv_calls == 0);
  476. EXPECT(counters.recved_bytes == 0);
  477. EXPECT(counters.err_calls == 0);
  478. /* check ooseq queue */
  479. EXPECT_OOSEQ(tcp_oos_count(pcb) == k);
  480. datalen2 = tcp_oos_tcplen(pcb);
  481. EXPECT_OOSEQ(datalen == datalen2);
  482. /* now pass inseq */
  483. test_tcp_input(pinseq, &netif);
  484. EXPECT(pcb->ooseq == NULL);
  485. /* make sure the pcb is freed */
  486. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
  487. tcp_abort(pcb);
  488. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
  489. #endif /* !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS */
  490. LWIP_UNUSED_ARG(_i);
  491. }
  492. END_TEST
  493. /** similar to above test, except seqno starts near the max rxwin */
  494. START_TEST(test_tcp_recv_ooseq_overrun_rxwin_edge)
  495. {
  496. #if !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS
  497. int i, k;
  498. struct test_tcp_counters counters;
  499. struct tcp_pcb* pcb;
  500. struct pbuf *pinseq, *p_ovr;
  501. struct netif netif;
  502. int datalen = 0;
  503. int datalen2;
  504. for(i = 0; i < (int)sizeof(data_full_wnd); i++) {
  505. data_full_wnd[i] = (char)i;
  506. }
  507. /* initialize local vars */
  508. test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
  509. /* initialize counter struct */
  510. memset(&counters, 0, sizeof(counters));
  511. counters.expected_data_len = TCP_WND;
  512. counters.expected_data = data_full_wnd;
  513. /* create and initialize the pcb */
  514. pcb = test_tcp_new_counters_pcb(&counters);
  515. EXPECT_RET(pcb != NULL);
  516. tcp_set_state(pcb, ESTABLISHED, &test_local_ip, &test_remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
  517. pcb->rcv_nxt = 0xffffffff - (TCP_WND / 2);
  518. /* create segments */
  519. /* pinseq is sent as last segment! */
  520. pinseq = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
  521. for(i = TCP_MSS, k = 0; i < TCP_WND; i += TCP_MSS, k++) {
  522. int count, expected_datalen;
  523. struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)],
  524. TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
  525. EXPECT_RET(p != NULL);
  526. /* pass the segment to tcp_input */
  527. test_tcp_input(p, &netif);
  528. /* check if counters are as expected */
  529. EXPECT(counters.close_calls == 0);
  530. EXPECT(counters.recv_calls == 0);
  531. EXPECT(counters.recved_bytes == 0);
  532. EXPECT(counters.err_calls == 0);
  533. /* check ooseq queue */
  534. count = tcp_oos_count(pcb);
  535. EXPECT_OOSEQ(count == k+1);
  536. datalen = tcp_oos_tcplen(pcb);
  537. if (i + TCP_MSS < TCP_WND) {
  538. expected_datalen = (k+1)*TCP_MSS;
  539. } else {
  540. expected_datalen = TCP_WND - TCP_MSS;
  541. }
  542. if (datalen != expected_datalen) {
  543. EXPECT_OOSEQ(datalen == expected_datalen);
  544. }
  545. }
  546. /* pass in one more segment, cleary overrunning the rxwin */
  547. p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)], TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
  548. EXPECT_RET(p_ovr != NULL);
  549. /* pass the segment to tcp_input */
  550. test_tcp_input(p_ovr, &netif);
  551. /* check if counters are as expected */
  552. EXPECT(counters.close_calls == 0);
  553. EXPECT(counters.recv_calls == 0);
  554. EXPECT(counters.recved_bytes == 0);
  555. EXPECT(counters.err_calls == 0);
  556. /* check ooseq queue */
  557. EXPECT_OOSEQ(tcp_oos_count(pcb) == k);
  558. datalen2 = tcp_oos_tcplen(pcb);
  559. EXPECT_OOSEQ(datalen == datalen2);
  560. /* now pass inseq */
  561. test_tcp_input(pinseq, &netif);
  562. EXPECT(pcb->ooseq == NULL);
  563. /* make sure the pcb is freed */
  564. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
  565. tcp_abort(pcb);
  566. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
  567. #endif /* !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS */
  568. LWIP_UNUSED_ARG(_i);
  569. }
  570. END_TEST
  571. START_TEST(test_tcp_recv_ooseq_max_bytes)
  572. {
  573. #if TCP_OOSEQ_MAX_BYTES && (TCP_OOSEQ_MAX_BYTES < (TCP_WND + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
  574. int i, k;
  575. struct test_tcp_counters counters;
  576. struct tcp_pcb* pcb;
  577. struct pbuf *p_ovr;
  578. struct netif netif;
  579. int datalen = 0;
  580. int datalen2;
  581. for(i = 0; i < sizeof(data_full_wnd); i++) {
  582. data_full_wnd[i] = (char)i;
  583. }
  584. /* initialize local vars */
  585. test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
  586. /* initialize counter struct */
  587. memset(&counters, 0, sizeof(counters));
  588. counters.expected_data_len = TCP_WND;
  589. counters.expected_data = data_full_wnd;
  590. /* create and initialize the pcb */
  591. pcb = test_tcp_new_counters_pcb(&counters);
  592. EXPECT_RET(pcb != NULL);
  593. tcp_set_state(pcb, ESTABLISHED, &test_local_ip, &test_remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
  594. pcb->rcv_nxt = 0x8000;
  595. /* don't 'recv' the first segment (1 byte) so that all other segments will be ooseq */
  596. /* create segments and 'recv' them */
  597. for(k = 1, i = 1; k < TCP_OOSEQ_MAX_BYTES; k += TCP_MSS, i++) {
  598. int count;
  599. struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[k],
  600. TCP_MSS, k, 0, TCP_ACK);
  601. EXPECT_RET(p != NULL);
  602. EXPECT_RET(p->next == NULL);
  603. /* pass the segment to tcp_input */
  604. test_tcp_input(p, &netif);
  605. /* check if counters are as expected */
  606. EXPECT(counters.close_calls == 0);
  607. EXPECT(counters.recv_calls == 0);
  608. EXPECT(counters.recved_bytes == 0);
  609. EXPECT(counters.err_calls == 0);
  610. /* check ooseq queue */
  611. count = tcp_oos_pbuf_count(pcb);
  612. EXPECT_OOSEQ(count == i);
  613. datalen = tcp_oos_tcplen(pcb);
  614. EXPECT_OOSEQ(datalen == (i * TCP_MSS));
  615. }
  616. /* pass in one more segment, overrunning the limit */
  617. p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[k+1], 1, k+1, 0, TCP_ACK);
  618. EXPECT_RET(p_ovr != NULL);
  619. /* pass the segment to tcp_input */
  620. test_tcp_input(p_ovr, &netif);
  621. /* check if counters are as expected */
  622. EXPECT(counters.close_calls == 0);
  623. EXPECT(counters.recv_calls == 0);
  624. EXPECT(counters.recved_bytes == 0);
  625. EXPECT(counters.err_calls == 0);
  626. /* check ooseq queue (ensure the new segment was not accepted) */
  627. EXPECT_OOSEQ(tcp_oos_count(pcb) == (i-1));
  628. datalen2 = tcp_oos_tcplen(pcb);
  629. EXPECT_OOSEQ(datalen2 == ((i-1) * TCP_MSS));
  630. /* make sure the pcb is freed */
  631. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
  632. tcp_abort(pcb);
  633. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
  634. #endif /* TCP_OOSEQ_MAX_BYTES && (TCP_OOSEQ_MAX_BYTES < (TCP_WND + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)) */
  635. LWIP_UNUSED_ARG(_i);
  636. }
  637. END_TEST
  638. START_TEST(test_tcp_recv_ooseq_max_pbufs)
  639. {
  640. #if TCP_OOSEQ_MAX_PBUFS && (TCP_OOSEQ_MAX_PBUFS < ((TCP_WND / TCP_MSS) + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
  641. int i;
  642. struct test_tcp_counters counters;
  643. struct tcp_pcb* pcb;
  644. struct pbuf *p_ovr;
  645. struct netif netif;
  646. int datalen = 0;
  647. int datalen2;
  648. for(i = 0; i < sizeof(data_full_wnd); i++) {
  649. data_full_wnd[i] = (char)i;
  650. }
  651. /* initialize local vars */
  652. test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
  653. /* initialize counter struct */
  654. memset(&counters, 0, sizeof(counters));
  655. counters.expected_data_len = TCP_WND;
  656. counters.expected_data = data_full_wnd;
  657. /* create and initialize the pcb */
  658. pcb = test_tcp_new_counters_pcb(&counters);
  659. EXPECT_RET(pcb != NULL);
  660. tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
  661. pcb->rcv_nxt = 0x8000;
  662. /* don't 'recv' the first segment (1 byte) so that all other segments will be ooseq */
  663. /* create segments and 'recv' them */
  664. for(i = 1; i <= TCP_OOSEQ_MAX_PBUFS; i++) {
  665. int count;
  666. struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[i],
  667. 1, i, 0, TCP_ACK);
  668. EXPECT_RET(p != NULL);
  669. EXPECT_RET(p->next == NULL);
  670. /* pass the segment to tcp_input */
  671. test_tcp_input(p, &netif);
  672. /* check if counters are as expected */
  673. EXPECT(counters.close_calls == 0);
  674. EXPECT(counters.recv_calls == 0);
  675. EXPECT(counters.recved_bytes == 0);
  676. EXPECT(counters.err_calls == 0);
  677. /* check ooseq queue */
  678. count = tcp_oos_pbuf_count(pcb);
  679. EXPECT_OOSEQ(count == i);
  680. datalen = tcp_oos_tcplen(pcb);
  681. EXPECT_OOSEQ(datalen == i);
  682. }
  683. /* pass in one more segment, overrunning the limit */
  684. p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[i+1], 1, i+1, 0, TCP_ACK);
  685. EXPECT_RET(p_ovr != NULL);
  686. /* pass the segment to tcp_input */
  687. test_tcp_input(p_ovr, &netif);
  688. /* check if counters are as expected */
  689. EXPECT(counters.close_calls == 0);
  690. EXPECT(counters.recv_calls == 0);
  691. EXPECT(counters.recved_bytes == 0);
  692. EXPECT(counters.err_calls == 0);
  693. /* check ooseq queue (ensure the new segment was not accepted) */
  694. EXPECT_OOSEQ(tcp_oos_count(pcb) == (i-1));
  695. datalen2 = tcp_oos_tcplen(pcb);
  696. EXPECT_OOSEQ(datalen2 == (i-1));
  697. /* make sure the pcb is freed */
  698. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
  699. tcp_abort(pcb);
  700. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
  701. #endif /* TCP_OOSEQ_MAX_PBUFS && (TCP_OOSEQ_MAX_BYTES < (TCP_WND + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)) */
  702. LWIP_UNUSED_ARG(_i);
  703. }
  704. END_TEST
  705. static void
  706. check_rx_counters(struct tcp_pcb *pcb, struct test_tcp_counters *counters, u32_t exp_close_calls, u32_t exp_rx_calls,
  707. u32_t exp_rx_bytes, u32_t exp_err_calls, int exp_oos_count, int exp_oos_len)
  708. {
  709. int oos_len;
  710. EXPECT(counters->close_calls == exp_close_calls);
  711. EXPECT(counters->recv_calls == exp_rx_calls);
  712. EXPECT(counters->recved_bytes == exp_rx_bytes);
  713. EXPECT(counters->err_calls == exp_err_calls);
  714. /* check that pbuf is queued in ooseq */
  715. EXPECT_OOSEQ(tcp_oos_count(pcb) == exp_oos_count);
  716. oos_len = tcp_oos_tcplen(pcb);
  717. EXPECT_OOSEQ(exp_oos_len == oos_len);
  718. }
  719. /* this test uses 4 packets:
  720. * - data (len=TCP_MSS)
  721. * - FIN
  722. * - data after FIN (len=1) (invalid)
  723. * - 2nd FIN (invalid)
  724. *
  725. * the parameter 'delay_packet' is a bitmask that choses which on these packets is ooseq
  726. */
  727. static void test_tcp_recv_ooseq_double_FINs(int delay_packet)
  728. {
  729. int i, k;
  730. struct test_tcp_counters counters;
  731. struct tcp_pcb* pcb;
  732. struct pbuf *p_normal_fin, *p_data_after_fin, *p, *p_2nd_fin_ooseq;
  733. struct netif netif;
  734. u32_t exp_rx_calls = 0, exp_rx_bytes = 0, exp_close_calls = 0, exp_oos_pbufs = 0, exp_oos_tcplen = 0;
  735. int first_dropped = 0xff;
  736. for(i = 0; i < (int)sizeof(data_full_wnd); i++) {
  737. data_full_wnd[i] = (char)i;
  738. }
  739. /* initialize local vars */
  740. test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
  741. /* initialize counter struct */
  742. memset(&counters, 0, sizeof(counters));
  743. counters.expected_data_len = TCP_WND;
  744. counters.expected_data = data_full_wnd;
  745. /* create and initialize the pcb */
  746. pcb = test_tcp_new_counters_pcb(&counters);
  747. EXPECT_RET(pcb != NULL);
  748. tcp_set_state(pcb, ESTABLISHED, &test_local_ip, &test_remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
  749. pcb->rcv_nxt = 0x8000;
  750. /* create segments */
  751. p = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
  752. p_normal_fin = tcp_create_rx_segment(pcb, NULL, 0, TCP_MSS, 0, TCP_ACK|TCP_FIN);
  753. k = 1;
  754. p_data_after_fin = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS+1], k, TCP_MSS+1, 0, TCP_ACK);
  755. p_2nd_fin_ooseq = tcp_create_rx_segment(pcb, NULL, 0, TCP_MSS+1+k, 0, TCP_ACK|TCP_FIN);
  756. if(delay_packet & 1) {
  757. /* drop normal data */
  758. first_dropped = 1;
  759. } else {
  760. /* send normal data */
  761. test_tcp_input(p, &netif);
  762. exp_rx_calls++;
  763. exp_rx_bytes += TCP_MSS;
  764. }
  765. /* check if counters are as expected */
  766. check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
  767. if(delay_packet & 2) {
  768. /* drop FIN */
  769. if(first_dropped > 2) {
  770. first_dropped = 2;
  771. }
  772. } else {
  773. /* send FIN */
  774. test_tcp_input(p_normal_fin, &netif);
  775. if (first_dropped < 2) {
  776. /* already dropped packets, this one is ooseq */
  777. exp_oos_pbufs++;
  778. exp_oos_tcplen++;
  779. } else {
  780. /* inseq */
  781. exp_close_calls++;
  782. }
  783. }
  784. /* check if counters are as expected */
  785. check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
  786. if(delay_packet & 4) {
  787. /* drop data-after-FIN */
  788. if(first_dropped > 3) {
  789. first_dropped = 3;
  790. }
  791. } else {
  792. /* send data-after-FIN */
  793. test_tcp_input(p_data_after_fin, &netif);
  794. if (first_dropped < 3) {
  795. /* already dropped packets, this one is ooseq */
  796. if (delay_packet & 2) {
  797. /* correct FIN was ooseq */
  798. exp_oos_pbufs++;
  799. exp_oos_tcplen += k;
  800. }
  801. } else {
  802. /* inseq: no change */
  803. }
  804. }
  805. /* check if counters are as expected */
  806. check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
  807. if(delay_packet & 8) {
  808. /* drop 2nd-FIN */
  809. if(first_dropped > 4) {
  810. first_dropped = 4;
  811. }
  812. } else {
  813. /* send 2nd-FIN */
  814. test_tcp_input(p_2nd_fin_ooseq, &netif);
  815. if (first_dropped < 3) {
  816. /* already dropped packets, this one is ooseq */
  817. if (delay_packet & 2) {
  818. /* correct FIN was ooseq */
  819. exp_oos_pbufs++;
  820. exp_oos_tcplen++;
  821. }
  822. } else {
  823. /* inseq: no change */
  824. }
  825. }
  826. /* check if counters are as expected */
  827. check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
  828. if(delay_packet & 1) {
  829. /* dropped normal data before */
  830. test_tcp_input(p, &netif);
  831. exp_rx_calls++;
  832. exp_rx_bytes += TCP_MSS;
  833. if((delay_packet & 2) == 0) {
  834. /* normal FIN was NOT delayed */
  835. exp_close_calls++;
  836. exp_oos_pbufs = exp_oos_tcplen = 0;
  837. }
  838. }
  839. /* check if counters are as expected */
  840. check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
  841. if(delay_packet & 2) {
  842. /* dropped normal FIN before */
  843. test_tcp_input(p_normal_fin, &netif);
  844. exp_close_calls++;
  845. exp_oos_pbufs = exp_oos_tcplen = 0;
  846. }
  847. /* check if counters are as expected */
  848. check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
  849. if(delay_packet & 4) {
  850. /* dropped data-after-FIN before */
  851. test_tcp_input(p_data_after_fin, &netif);
  852. }
  853. /* check if counters are as expected */
  854. check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
  855. if(delay_packet & 8) {
  856. /* dropped 2nd-FIN before */
  857. test_tcp_input(p_2nd_fin_ooseq, &netif);
  858. }
  859. /* check if counters are as expected */
  860. check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
  861. /* check that ooseq data has been dumped */
  862. EXPECT(pcb->ooseq == NULL);
  863. /* make sure the pcb is freed */
  864. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
  865. tcp_abort(pcb);
  866. EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
  867. }
  868. /** create multiple segments and pass them to tcp_input with the first segment missing
  869. * to simulate overruning the rxwin with ooseq queueing enabled */
  870. #define FIN_TEST(name, num) \
  871. START_TEST(name) \
  872. { \
  873. LWIP_UNUSED_ARG(_i); \
  874. test_tcp_recv_ooseq_double_FINs(num); \
  875. } \
  876. END_TEST
  877. FIN_TEST(test_tcp_recv_ooseq_double_FIN_0, 0)
  878. FIN_TEST(test_tcp_recv_ooseq_double_FIN_1, 1)
  879. FIN_TEST(test_tcp_recv_ooseq_double_FIN_2, 2)
  880. FIN_TEST(test_tcp_recv_ooseq_double_FIN_3, 3)
  881. FIN_TEST(test_tcp_recv_ooseq_double_FIN_4, 4)
  882. FIN_TEST(test_tcp_recv_ooseq_double_FIN_5, 5)
  883. FIN_TEST(test_tcp_recv_ooseq_double_FIN_6, 6)
  884. FIN_TEST(test_tcp_recv_ooseq_double_FIN_7, 7)
  885. FIN_TEST(test_tcp_recv_ooseq_double_FIN_8, 8)
  886. FIN_TEST(test_tcp_recv_ooseq_double_FIN_9, 9)
  887. FIN_TEST(test_tcp_recv_ooseq_double_FIN_10, 10)
  888. FIN_TEST(test_tcp_recv_ooseq_double_FIN_11, 11)
  889. FIN_TEST(test_tcp_recv_ooseq_double_FIN_12, 12)
  890. FIN_TEST(test_tcp_recv_ooseq_double_FIN_13, 13)
  891. FIN_TEST(test_tcp_recv_ooseq_double_FIN_14, 14)
  892. FIN_TEST(test_tcp_recv_ooseq_double_FIN_15, 15)
  893. /** Create the suite including all tests for this module */
  894. Suite *
  895. tcp_oos_suite(void)
  896. {
  897. testfunc tests[] = {
  898. TESTFUNC(test_tcp_recv_ooseq_FIN_OOSEQ),
  899. TESTFUNC(test_tcp_recv_ooseq_FIN_INSEQ),
  900. TESTFUNC(test_tcp_recv_ooseq_overrun_rxwin),
  901. TESTFUNC(test_tcp_recv_ooseq_overrun_rxwin_edge),
  902. TESTFUNC(test_tcp_recv_ooseq_max_bytes),
  903. TESTFUNC(test_tcp_recv_ooseq_max_pbufs),
  904. TESTFUNC(test_tcp_recv_ooseq_double_FIN_0),
  905. TESTFUNC(test_tcp_recv_ooseq_double_FIN_1),
  906. TESTFUNC(test_tcp_recv_ooseq_double_FIN_2),
  907. TESTFUNC(test_tcp_recv_ooseq_double_FIN_3),
  908. TESTFUNC(test_tcp_recv_ooseq_double_FIN_4),
  909. TESTFUNC(test_tcp_recv_ooseq_double_FIN_5),
  910. TESTFUNC(test_tcp_recv_ooseq_double_FIN_6),
  911. TESTFUNC(test_tcp_recv_ooseq_double_FIN_7),
  912. TESTFUNC(test_tcp_recv_ooseq_double_FIN_8),
  913. TESTFUNC(test_tcp_recv_ooseq_double_FIN_9),
  914. TESTFUNC(test_tcp_recv_ooseq_double_FIN_10),
  915. TESTFUNC(test_tcp_recv_ooseq_double_FIN_11),
  916. TESTFUNC(test_tcp_recv_ooseq_double_FIN_12),
  917. TESTFUNC(test_tcp_recv_ooseq_double_FIN_13),
  918. TESTFUNC(test_tcp_recv_ooseq_double_FIN_14),
  919. TESTFUNC(test_tcp_recv_ooseq_double_FIN_15)
  920. };
  921. return create_suite("TCP_OOS", tests, sizeof(tests)/sizeof(testfunc), tcp_oos_setup, tcp_oos_teardown);
  922. }