ReactOS 0.4.16-dev-257-g6aa11ac
test_tcp_state.c File Reference
#include "test_tcp_state.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/stats.h"
#include "tcp_helper.h"
#include "lwip/inet_chksum.h"
Include dependency graph for test_tcp_state.c:

Go to the source code of this file.

Macros

#define SEQNO1   (0xFFFFFF00 - TCP_MSS)
 
#define ISS   6510
 

Functions

static void test_tcp_tmr (void)
 
static u8_t get_tcp_flags_from_packet (struct pbuf *p, u16_t tcp_hdr_offset)
 
static struct tcp_pcb_listen * create_listening_pcb (u16_t local_port, struct test_tcp_counters *counters)
 
static void tcp_state_setup (void)
 
static void tcp_state_teardown (void)
 
static void test_rst_generation_with_incoming_packet (struct pbuf *p, struct netif *netif, struct test_tcp_txcounters *tx_counters)
 
 START_TEST (test_tcp_new_max_num)
 
END_TEST START_TEST (test_tcp_new_max_num_remove_TIME_WAIT)
 
END_TEST START_TEST (test_tcp_connect_active_open)
 
END_TEST START_TEST (test_tcp_active_close)
 
END_TEST START_TEST (test_tcp_imultaneous_close)
 
END_TEST START_TEST (test_tcp_gen_rst_in_CLOSED)
 
END_TEST START_TEST (test_tcp_gen_rst_in_LISTEN)
 
END_TEST START_TEST (test_tcp_gen_rst_in_TIME_WAIT)
 
END_TEST START_TEST (test_tcp_process_rst_seqno)
 
END_TEST START_TEST (test_tcp_gen_rst_in_SYN_SENT_ackseq)
 
END_TEST START_TEST (test_tcp_gen_rst_in_SYN_SENT_non_syn_ack)
 
END_TEST START_TEST (test_tcp_gen_rst_in_SYN_RCVD)
 
END_TEST START_TEST (test_tcp_receive_rst_SYN_RCVD_to_LISTEN)
 
END_TEST Suite * tcp_state_suite (void)
 

Variables

static struct netif test_netif = {0}
 
static struct test_tcp_txcounters test_txcounters = {0}
 
static u8_t test_tcp_timer
 
static struct netifold_netif_list
 
static struct netifold_netif_default
 

Macro Definition Documentation

◆ ISS

#define ISS   6510

Definition at line 20 of file test_tcp_state.c.

◆ SEQNO1

#define SEQNO1   (0xFFFFFF00 - TCP_MSS)

Definition at line 19 of file test_tcp_state.c.

Function Documentation

◆ create_listening_pcb()

static struct tcp_pcb_listen * create_listening_pcb ( u16_t  local_port,
struct test_tcp_counters counters 
)
static

Definition at line 48 of file test_tcp_state.c.

49{
50 struct tcp_pcb *pcb;
51 struct tcp_pcb_listen *lpcb=NULL;
52 err_t err;
53 u16_t port = local_port?local_port:1234;
54
55 if (counters) {
57 } else {
58 pcb = tcp_new();
59 }
60 EXPECT(pcb != NULL);
61
62 if (pcb) {
63 err = tcp_bind(pcb, &test_netif.ip_addr, port);
64 EXPECT(err == ERR_OK);
65 lpcb = (struct tcp_pcb_listen *)tcp_listen(pcb);
66 }
67
68 return lpcb;
69}
#define NULL
Definition: types.h:112
USHORT port
Definition: uri.c:228
GLint GLint GLsizei GLuint * counters
Definition: glext.h:11114
uint16_t u16_t
Definition: arch.h:127
s8_t err_t
Definition: err.h:96
@ ERR_OK
Definition: err.h:55
#define EXPECT(x)
Definition: lwip_check.h:11
#define err(...)
struct tcp_pcb * test_tcp_new_counters_pcb(struct test_tcp_counters *counters)
Definition: tcp_helper.c:244
static struct netif test_netif

Referenced by START_TEST().

◆ get_tcp_flags_from_packet()

static u8_t get_tcp_flags_from_packet ( struct pbuf p,
u16_t  tcp_hdr_offset 
)
static

Definition at line 35 of file test_tcp_state.c.

36{
37 struct tcp_hdr tcphdr;
38 u16_t ret;
39 EXPECT_RETX(p != NULL, 0);
40 EXPECT_RETX(p->len >= tcp_hdr_offset + sizeof(struct tcp_hdr), 0);
41 ret = pbuf_copy_partial(p, &tcphdr, sizeof(struct tcp_hdr), tcp_hdr_offset);
42 EXPECT(ret == sizeof(struct tcp_hdr));
43 return TCPH_FLAGS(&tcphdr);
44}
GLfloat GLfloat p
Definition: glext.h:8902
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1058
#define TCPH_FLAGS(phdr)
Definition: tcp.h:87
#define EXPECT_RETX(x, y)
Definition: lwip_check.h:13
Definition: tcp.h:56
Definition: tcpdef.h:22
int ret

Referenced by START_TEST(), and test_rst_generation_with_incoming_packet().

◆ START_TEST() [1/13]

END_TEST START_TEST ( test_tcp_active_close  )

Definition at line 253 of file test_tcp_state.c.

254{
255 struct tcp_pcb *pcb, *pcbl;
257 struct pbuf *p;
258 err_t err;
259 u32_t i;
260 LWIP_UNUSED_ARG(_i);
261
262 /* create TCP in LISTEN state */
263 memset(&counters, 0, sizeof(counters));
265 EXPECT_RET(pcb != NULL);
266 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
267 err = tcp_bind(pcb, &test_netif.ip_addr, 1234);
269 pcbl = tcp_listen(pcb);
270 EXPECT_RET(pcbl != NULL);
271 EXPECT_RET(pcbl->state == LISTEN);
272 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
273 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) == 1);
274
276 err = tcp_close(pcbl);
278 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
279 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) == 0);
280 EXPECT(test_txcounters.num_tx_calls == 0);
281
282 /* close TCP in SYN_SENT state */
283 memset(&counters, 0, sizeof(counters));
285 EXPECT_RET(pcb != NULL);
286 err = tcp_connect(pcb, &test_netif.gw, 1234, NULL);
288 EXPECT_RET(pcb->state == SYN_SENT);
289 EXPECT(test_txcounters.num_tx_calls == 1);
290 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
291
293 err = tcp_close(pcb);
295 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
296 EXPECT(test_txcounters.num_tx_calls == 0);
297
298 /* close TCP in ESTABLISHED state */
299 memset(&counters, 0, sizeof(counters));
301 EXPECT_RET(pcb != NULL);
303 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
304
306 err = tcp_close(pcb);
308 EXPECT_RET(pcb->state == FIN_WAIT_1);
309 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
310 /* test_tcp_tmr(); */
311 EXPECT(test_txcounters.num_tx_calls == 1);
312 /* create a segment ACK and pass it to tcp_input */
313 p = tcp_create_rx_segment(pcb, NULL, 0, 0, 1, TCP_ACK);
314 EXPECT_RET(p != NULL);
316 EXPECT_RET(pcb->state == FIN_WAIT_2);
317 /* create a segment FIN and pass it to tcp_input */
318 p = tcp_create_rx_segment(pcb, NULL, 0, 0, 0, TCP_FIN);
319 EXPECT_RET(p != NULL);
321 EXPECT_RET(pcb->state == TIME_WAIT);
322 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
323 for (i = 0; i < 2 * TCP_MSL / TCP_TMR_INTERVAL + 1; i++) {
324 test_tcp_tmr();
325 }
326 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
327}
static int used
Definition: adh-main.c:39
RD_BOOL tcp_connect(char *server)
Definition: tcp.c:717
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t u32_t
Definition: arch.h:129
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
#define TCP_ACK
Definition: tcp.h:76
#define TCP_FIN
Definition: tcp.h:72
#define EXPECT_RET(x)
Definition: lwip_check.h:12
#define memset(x, y, z)
Definition: compat.h:39
#define MEMP_STATS_GET(x, i)
Definition: stats.h:409
Definition: pbuf.h:186
void test_tcp_input(struct pbuf *p, struct netif *inp)
Definition: tcp_helper.c:259
struct pbuf * tcp_create_rx_segment(struct tcp_pcb *pcb, void *data, size_t data_len, u32_t seqno_offset, u32_t ackno_offset, u8_t headerflags)
Definition: tcp_helper.c:130
const ip_addr_t test_local_ip
Definition: tcp_helper.c:14
const ip_addr_t test_remote_ip
Definition: tcp_helper.c:15
#define TEST_REMOTE_PORT
Definition: tcp_helper.h:32
#define TEST_LOCAL_PORT
Definition: tcp_helper.h:33
void tcp_close(struct sock *sk, long timeout)
static __inline void tcp_set_state(struct sock *sk, int state)
Definition: tcpcore.h:3256
static void test_tcp_tmr(void)
static struct test_tcp_txcounters test_txcounters

◆ START_TEST() [2/13]

END_TEST START_TEST ( test_tcp_connect_active_open  )

Definition at line 203 of file test_tcp_state.c.

204{
206 struct tcp_pcb *pcb;
207 struct pbuf *p;
208 err_t err;
209 u16_t test_port = 1234;
210 u32_t seqno = 0;
211 LWIP_UNUSED_ARG(_i);
212
213 /* create and initialize the pcb */
214 tcp_ticks = SEQNO1 - ISS;
216 EXPECT_RET(pcb != NULL);
217
218 /* Get seqno from SYN packet */
219 test_txcounters.copy_tx_packets = 1;
221 test_txcounters.copy_tx_packets = 0;
222 EXPECT(err == ERR_OK);
223 EXPECT(pcb->state == SYN_SENT);
224 EXPECT(test_txcounters.num_tx_calls == 1);
225 EXPECT_RET(test_txcounters.tx_packets != NULL);
226 if (test_txcounters.tx_packets != NULL) {
227 struct tcp_hdr tcphdr;
228 u16_t ret;
229 ret = pbuf_copy_partial(test_txcounters.tx_packets, &tcphdr, 20, 20);
230 EXPECT(ret == 20);
232 pbuf_free(test_txcounters.tx_packets);
233 test_txcounters.tx_packets = NULL;
234 seqno = lwip_htonl(tcphdr.seqno);
235 EXPECT(seqno == pcb->lastack);
236 }
237
238 /* check correct syn packet */
239 p = tcp_create_segment(&pcb->remote_ip, &pcb->local_ip, test_port,
240 pcb->local_port, NULL, 0, 12345, seqno + 1, TCP_SYN|TCP_ACK);
241 EXPECT_RET(p != NULL);
243 EXPECT_RET(pcb->state == ESTABLISHED);
244 EXPECT_RET(test_txcounters.num_tx_calls == 2);
245
246 /* make sure the pcb is freed */
247 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
248 tcp_abort(pcb);
249 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
250}
#define lwip_htonl(x)
Definition: def.h:88
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
#define TCP_SYN
Definition: tcp.h:73
static void test_port(IHTMLLocation *loc, const struct location_test *test)
Definition: htmllocation.c:199
struct pbuf * tcp_create_segment(ip_addr_t *src_ip, ip_addr_t *dst_ip, u16_t src_port, u16_t dst_port, void *data, size_t data_len, u32_t seqno, u32_t ackno, u8_t headerflags)
Definition: tcp_helper.c:117
#define SEQNO1
#define ISS

◆ START_TEST() [3/13]

END_TEST START_TEST ( test_tcp_gen_rst_in_CLOSED  )

Definition at line 375 of file test_tcp_state.c.

376{
377 struct pbuf *p;
378 ip_addr_t src_addr = test_remote_ip;
379 ip_addr_t dst_addr = test_local_ip;
380 LWIP_UNUSED_ARG(_i);
381
382 /* Do not create any pcb */
383
384 /* create a segment */
385 p = tcp_create_segment(&src_addr, &dst_addr, TEST_REMOTE_PORT,
386 TEST_LOCAL_PORT, NULL, 0, 12345, 54321, TCP_ACK);
387 EXPECT(p != NULL);
389 EXPECT(test_txcounters.num_tx_calls == 1);
390
391}
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
static void test_rst_generation_with_incoming_packet(struct pbuf *p, struct netif *netif, struct test_tcp_txcounters *tx_counters)

◆ START_TEST() [4/13]

END_TEST START_TEST ( test_tcp_gen_rst_in_LISTEN  )

Definition at line 395 of file test_tcp_state.c.

396{
397 struct tcp_pcb_listen *lpcb;
398 struct pbuf *p;
399 ip_addr_t src_addr = test_remote_ip;
400 LWIP_UNUSED_ARG(_i);
401
402 /* create a pcb in LISTEN state */
404 EXPECT_RET(lpcb != NULL);
405
406 /* create a segment */
407 p = tcp_create_segment(&src_addr,&lpcb->local_ip, TEST_REMOTE_PORT,
408 lpcb->local_port, NULL, 0, 12345, 54321, TCP_ACK);
409 EXPECT(p != NULL);
411 EXPECT(test_txcounters.num_tx_calls == 1);
412
413 /* the PCB still in LISTEN state */
414 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) == 1);
415 if (MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) != 0) {
416 /* can not use tcp_abort() */
417 tcp_close((struct tcp_pcb *)lpcb);
418 }
419
420}
static struct tcp_pcb_listen * create_listening_pcb(u16_t local_port, struct test_tcp_counters *counters)

◆ START_TEST() [5/13]

END_TEST START_TEST ( test_tcp_gen_rst_in_SYN_RCVD  )

Definition at line 559 of file test_tcp_state.c.

560{
561 struct tcp_pcb_listen *lpcb;
562 struct pbuf *p;
563 u32_t ack_seqno = 0;
564 ip_addr_t src_addr = test_remote_ip;
565 LWIP_UNUSED_ARG(_i);
566
567 /* create and initialize a pcb in listen state */
569 EXPECT_RET(lpcb != NULL);
570
571 /* LISTEN -> SYN_RCVD */
572 p = tcp_create_segment(&src_addr, &lpcb->local_ip, TEST_REMOTE_PORT,
573 lpcb->local_port, NULL, 0, 1000, 54321, TCP_SYN);
574 EXPECT(p != NULL);
575 memset(&test_txcounters, 0, sizeof(struct test_tcp_txcounters));
577 EXPECT(test_txcounters.num_tx_calls == 1);
578 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
579 if (MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1) {
580 ack_seqno = tcp_active_pcbs[0].lastack;
581 }
582
583 /* create a ACK segment with incorrect seqno */
584 p = tcp_create_segment(&src_addr, &lpcb->local_ip, TEST_REMOTE_PORT,
585 lpcb->local_port, NULL, 0, 1001, ack_seqno+1111, TCP_ACK);
586 EXPECT(p != NULL);
588 EXPECT(test_txcounters.num_tx_calls == 1);
589
590 /* the active pcb still exists */
591 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
592 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) == 1);
593 if (MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) != 0) {
594 /* can not use tcp_abort() */
595 tcp_close((struct tcp_pcb *)lpcb);
596 }
597}

◆ START_TEST() [6/13]

END_TEST START_TEST ( test_tcp_gen_rst_in_SYN_SENT_ackseq  )

Definition at line 505 of file test_tcp_state.c.

506{
507 struct tcp_pcb *pcb;
508 struct pbuf *p;
509 u16_t test_port = 1234;
510 err_t err;
511 LWIP_UNUSED_ARG(_i);
512
513 /* create and initialize a pcb in listen state */
514 pcb = tcp_new();
515 EXPECT_RET(pcb != NULL);
518
519 /* create a SYN+ACK segment with incorrect seqno */
520 p = tcp_create_segment(&pcb->remote_ip, &pcb->local_ip, pcb->remote_port,
521 pcb->local_port, NULL, 0, 12345, pcb->lastack-10, TCP_SYN|TCP_ACK);
522 EXPECT(p != NULL);
524
525 /* LWIP: send RST then re-send SYN immediately */
526 EXPECT(test_txcounters.num_tx_calls == 2);
527
528}

◆ START_TEST() [7/13]

END_TEST START_TEST ( test_tcp_gen_rst_in_SYN_SENT_non_syn_ack  )

Definition at line 532 of file test_tcp_state.c.

533{
534 struct tcp_pcb *pcb;
535 struct pbuf *p;
536 u16_t test_port = 1234;
537 err_t err;
538 LWIP_UNUSED_ARG(_i);
539
540 /* create and initialize a pcb in listen state */
541 pcb = tcp_new();
542 EXPECT_RET(pcb != NULL);
545
546 /* create a SYN+ACK segment with incorrect seqno */
547 p = tcp_create_segment(&pcb->remote_ip, &pcb->local_ip, pcb->remote_port,
548 pcb->local_port, NULL, 0, 12345, pcb->lastack, TCP_ACK);
549 EXPECT(p != NULL);
551
552 /* LWIP: send RST then re-send SYN immediately */
553 EXPECT(test_txcounters.num_tx_calls == 2);
554
555}

◆ START_TEST() [8/13]

END_TEST START_TEST ( test_tcp_gen_rst_in_TIME_WAIT  )

Definition at line 425 of file test_tcp_state.c.

426{
427 struct tcp_pcb *pcb;
428 struct pbuf *p;
429 LWIP_UNUSED_ARG(_i);
430
431 /* create a pcb in LISTEN state */
432 pcb = tcp_new();
433 EXPECT_RET(pcb != NULL);
435
436 /* create a segment */
437 p = tcp_create_rx_segment(pcb, NULL, 0, 0, 0, TCP_SYN);
438 EXPECT(p != NULL);
440 EXPECT(test_txcounters.num_tx_calls == 1);
441
442 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
443 EXPECT(pcb->state == TIME_WAIT);
444}

◆ START_TEST() [9/13]

END_TEST START_TEST ( test_tcp_imultaneous_close  )

Definition at line 330 of file test_tcp_state.c.

331{
333 struct tcp_pcb* pcb;
334 struct pbuf* p;
335 char data = 0x0f;
336 err_t err;
337 u32_t i;
338 LWIP_UNUSED_ARG(_i);
339
340 /* initialize counter struct */
341 memset(&counters, 0, sizeof(counters));
342 counters.expected_data_len = 1;
343 counters.expected_data = &data;
344
345 /* create and initialize the pcb */
347 EXPECT_RET(pcb != NULL);
349 err = tcp_close(pcb);
351 EXPECT_RET(pcb->state == FIN_WAIT_1);
352 /* create a FIN segment */
353 p = tcp_create_rx_segment(pcb, &data, 0, 0, 0, TCP_FIN);
354 EXPECT(p != NULL);
355 if (p != NULL) {
357 }
358 EXPECT_RET(pcb->state == CLOSING);
359 /* create an ACK segment */
360 p = tcp_create_rx_segment(pcb, &data, 0, 0, 1, TCP_ACK);
361 EXPECT(p != NULL);
362 if (p != NULL) {
364 }
365 EXPECT_RET(pcb->state == TIME_WAIT);
366 for (i = 0; i < 2 * TCP_MSL / TCP_TMR_INTERVAL + 1; i++) {
367 test_tcp_tmr();
368 }
369 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
370}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

◆ START_TEST() [10/13]

START_TEST ( test_tcp_new_max_num  )

Definition at line 135 of file test_tcp_state.c.

136{
137 struct tcp_pcb* pcb[MEMP_NUM_TCP_PCB + 1];
138 int i;
139 LWIP_UNUSED_ARG(_i);
140
141 fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
142
143 for(i = 0;i < MEMP_NUM_TCP_PCB; i++) {
144 pcb[i] = tcp_new();
145 fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB) == (i + 1));
146 }
147 fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB) == MEMP_NUM_TCP_PCB);
148 /* Trying to remove the oldest pcb in TIME_WAIT,LAST_ACK,CLOSING state when pcb full */
149 pcb[MEMP_NUM_TCP_PCB] = tcp_new();
150 fail_unless(pcb[MEMP_NUM_TCP_PCB] == NULL);
152 pcb[MEMP_NUM_TCP_PCB] = tcp_new();
153 fail_unless(pcb[MEMP_NUM_TCP_PCB] != NULL);
154 fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB) == MEMP_NUM_TCP_PCB);
155
156 for (i = 1; i <= MEMP_NUM_TCP_PCB; i++)
157 {
158 tcp_abort(pcb[i]);
159 }
160 fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
161}
#define MEMP_NUM_TCP_PCB
Definition: opt.h:429

◆ START_TEST() [11/13]

END_TEST START_TEST ( test_tcp_new_max_num_remove_TIME_WAIT  )

Definition at line 166 of file test_tcp_state.c.

167{
168 struct tcp_pcb* pcb;
169 struct tcp_pcb* pcb_list[MEMP_NUM_TCP_PCB + 1];
170 int i;
171 LWIP_UNUSED_ARG(_i);
172
173 /* create a pcb in TIME_WAIT state */
174 pcb = tcp_new();
175 EXPECT_RET(pcb != NULL);
177 EXPECT_RET(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
178 EXPECT_RET(pcb->state == TIME_WAIT);
179
180 /* Create max number pcbs */
181 for(i = 0;i < MEMP_NUM_TCP_PCB-1; i++) {
182 pcb_list[i] = tcp_new();
183 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == (i + 2));
184 }
185 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == MEMP_NUM_TCP_PCB);
186
187 /* Create one more pcb, and expect that the pcb in the TIME_WAIT state is deleted */
188 pcb_list[MEMP_NUM_TCP_PCB-1] = tcp_new();
189 EXPECT_RET(pcb_list[MEMP_NUM_TCP_PCB-1] != NULL);
191
192 for (i = 0; i <= MEMP_NUM_TCP_PCB-1; i++)
193 {
194 tcp_abort(pcb_list[i]);
195 }
196 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
197
198}

◆ START_TEST() [12/13]

END_TEST START_TEST ( test_tcp_process_rst_seqno  )

Definition at line 448 of file test_tcp_state.c.

449{
451 struct tcp_pcb *pcb;
452 struct pbuf *p;
453 err_t err;
454 LWIP_UNUSED_ARG(_i);
455
456 /* create and initialize a pcb in SYN_SENT state */
457 memset(&counters, 0, sizeof(counters));
459 EXPECT_RET(pcb != NULL);
462
463 /* a RST segment with incorrect seqno will not be accepted */
464 p = tcp_create_segment(&pcb->remote_ip, &pcb->local_ip, TEST_REMOTE_PORT,
465 pcb->local_port, NULL, 0, 12345, pcb->snd_nxt-10, TCP_RST);
466 EXPECT(p != NULL);
468 EXPECT(counters.err_calls == 0);
469
470 /* a RST segment with correct seqno will be accepted */
471 p = tcp_create_segment(&pcb->remote_ip, &pcb->local_ip, TEST_REMOTE_PORT,
472 pcb->local_port, NULL, 0, 12345, pcb->snd_nxt, TCP_RST);
473 EXPECT(p != NULL);
475 EXPECT(counters.err_calls == 1);
476 counters.err_calls = 0;
477 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
478
479 /* create another pcb in ESTABLISHED state */
480 memset(&counters, 0, sizeof(counters));
482 EXPECT_RET(pcb != NULL);
484
485 /* a RST segment with incorrect seqno will not be accepted */
486 p = tcp_create_segment(&pcb->remote_ip, &pcb->local_ip, pcb->remote_port,
487 pcb->local_port, NULL, 0, pcb->rcv_nxt-10, 54321, TCP_RST);
488 EXPECT(p != NULL);
490 EXPECT(counters.err_calls == 0);
491
492 /* a RST segment with correct seqno will be accepted */
493 p = tcp_create_segment(&pcb->remote_ip, &pcb->local_ip, TEST_REMOTE_PORT,
494 pcb->local_port, NULL, 0, pcb->rcv_nxt, 54321, TCP_RST);
495 EXPECT(p != NULL);
497 EXPECT(counters.err_calls == 1);
498 counters.err_calls = 0;
499 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
500
501}
#define TCP_RST
Definition: tcp.h:74

◆ START_TEST() [13/13]

END_TEST START_TEST ( test_tcp_receive_rst_SYN_RCVD_to_LISTEN  )

Definition at line 601 of file test_tcp_state.c.

602{
603 struct tcp_pcb_listen *lpcb;
604 struct pbuf *p;
605 u16_t tcp_flags;
606 ip_addr_t src_addr = test_remote_ip;
607 LWIP_UNUSED_ARG(_i);
608
609 /* create and initialize a pcb in listen state */
611 EXPECT_RET(lpcb != NULL);
612
613 /* create a SYN segment */
614 p = tcp_create_segment(&src_addr, &lpcb->local_ip, TEST_REMOTE_PORT,
615 lpcb->local_port, NULL, 0, 1000, 54321, TCP_SYN);
616 EXPECT(p != NULL);
617 /* pass the segment to tcp_input */
618 memset(&test_txcounters, 0, sizeof(struct test_tcp_txcounters));
619 test_txcounters.copy_tx_packets = 1;
621 test_txcounters.copy_tx_packets = 0;
622 /* check if packets are as expected */
623 EXPECT(test_txcounters.num_tx_calls == 1);
624 tcp_flags = get_tcp_flags_from_packet(test_txcounters.tx_packets, 20);
625 pbuf_free(test_txcounters.tx_packets);
626 test_txcounters.tx_packets = NULL;
627 EXPECT((tcp_flags & TCP_SYN) && (tcp_flags & TCP_ACK));
628 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
629
630 /* create a RST segment */
631 p = tcp_create_segment(&src_addr, &lpcb->local_ip, TEST_REMOTE_PORT,
632 lpcb->local_port, NULL, 0, 1001, 54321, TCP_RST);
633 EXPECT(p != NULL);
635 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
636 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) == 1);
637
638 if (MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) != 0) {
639 /* can not use tcp_abort() */
640 tcp_close((struct tcp_pcb *)lpcb);
641 }
642}
static u8_t get_tcp_flags_from_packet(struct pbuf *p, u16_t tcp_hdr_offset)

◆ tcp_state_setup()

static void tcp_state_setup ( void  )
static

Definition at line 76 of file test_tcp_state.c.

77{
78 struct tcp_pcb dummy_pcb; /* we need this for tcp_next_iss() only */
79
80 /* reset iss to default (6510) */
81 tcp_ticks = 0;
82 tcp_ticks = 0 - (tcp_next_iss(&dummy_pcb) - 6510);
83 tcp_next_iss(&dummy_pcb);
84 tcp_ticks = 0;
85
87
94 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
95}
#define SKIP_POOL(x)
Definition: lwip_check.h:48
void lwip_check_ensure_no_alloc(unsigned int skip)
struct netif * netif_list
Definition: netif.c:113
struct netif * netif_default
Definition: netif.c:115
void test_tcp_init_netif(struct netif *netif, struct test_tcp_txcounters *txcounters, const ip_addr_t *ip_addr, const ip_addr_t *netmask)
Definition: tcp_helper.c:305
void tcp_remove_all(void)
Definition: tcp_helper.c:38
static ip4_addr_t test_netmask
Definition: test_etharp.c:18
static struct netif * old_netif_list
static struct netif * old_netif_default
static u8_t test_tcp_timer

Referenced by tcp_state_suite().

◆ tcp_state_suite()

END_TEST Suite * tcp_state_suite ( void  )

Create the suite including all tests for this module

Definition at line 647 of file test_tcp_state.c.

648{
649 testfunc tests[] = {
650 TESTFUNC(test_tcp_new_max_num),
651 TESTFUNC(test_tcp_new_max_num_remove_TIME_WAIT),
652 TESTFUNC(test_tcp_connect_active_open),
653 TESTFUNC(test_tcp_active_close),
654 TESTFUNC(test_tcp_imultaneous_close),
655 TESTFUNC(test_tcp_gen_rst_in_CLOSED),
656 TESTFUNC(test_tcp_gen_rst_in_LISTEN),
657 TESTFUNC(test_tcp_gen_rst_in_TIME_WAIT),
658 TESTFUNC(test_tcp_process_rst_seqno),
659 TESTFUNC(test_tcp_gen_rst_in_SYN_SENT_ackseq),
660 TESTFUNC(test_tcp_gen_rst_in_SYN_SENT_non_syn_ack),
661 TESTFUNC(test_tcp_gen_rst_in_SYN_RCVD),
662 TESTFUNC(test_tcp_receive_rst_SYN_RCVD_to_LISTEN),
663 };
664 return create_suite("TCP_STATE", tests, sizeof(tests) / sizeof(testfunc), tcp_state_setup, tcp_state_teardown);
665}
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define TESTFUNC(x)
Definition: lwip_check.h:22
static struct test_info tests[]
static void tcp_state_teardown(void)
static void tcp_state_setup(void)

Referenced by main().

◆ tcp_state_teardown()

static void tcp_state_teardown ( void  )
static

Definition at line 98 of file test_tcp_state.c.

99{
103 /* restore netif_list for next tests (e.g. loopif) */
106 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
107}

Referenced by tcp_state_suite().

◆ test_rst_generation_with_incoming_packet()

static void test_rst_generation_with_incoming_packet ( struct pbuf p,
struct netif netif,
struct test_tcp_txcounters tx_counters 
)
static

Definition at line 112 of file test_tcp_state.c.

114{
115 u16_t tcp_flags;
116 EXPECT_RET(p != NULL);
117 memset(tx_counters, 0, sizeof(struct test_tcp_txcounters));
118 /* pass the segment to tcp_input */
119 tx_counters->copy_tx_packets = 1;
121 tx_counters->copy_tx_packets = 0;
122 /* check if packets are as expected */
123 EXPECT(tx_counters->tx_packets != NULL);
124 if (tx_counters->tx_packets) {
125 tcp_flags = get_tcp_flags_from_packet(tx_counters->tx_packets, 20);
126 EXPECT(tcp_flags & TCP_RST);
127 pbuf_free(tx_counters->tx_packets);
128 tx_counters->tx_packets = NULL;
129 }
130}
Definition: netif.h:269
struct pbuf * tx_packets
Definition: tcp_helper.h:26

Referenced by START_TEST().

◆ test_tcp_tmr()

static void test_tcp_tmr ( void  )
static

Definition at line 25 of file test_tcp_state.c.

26{
27 tcp_fasttmr();
28 if (++test_tcp_timer & 1) {
29 tcp_slowtmr();
30 }
31}

Referenced by START_TEST().

Variable Documentation

◆ old_netif_default

struct netif* old_netif_default
static

Definition at line 73 of file test_tcp_state.c.

Referenced by tcp_state_setup(), and tcp_state_teardown().

◆ old_netif_list

struct netif* old_netif_list
static

Definition at line 72 of file test_tcp_state.c.

Referenced by tcp_state_setup(), and tcp_state_teardown().

◆ test_netif

struct netif test_netif = {0}
static

Definition at line 16 of file test_tcp_state.c.

Referenced by create_listening_pcb(), START_TEST(), and tcp_state_setup().

◆ test_tcp_timer

u8_t test_tcp_timer
static

Definition at line 21 of file test_tcp_state.c.

Referenced by tcp_state_setup(), and test_tcp_tmr().

◆ test_txcounters

struct test_tcp_txcounters test_txcounters = {0}
static

Definition at line 17 of file test_tcp_state.c.

Referenced by START_TEST(), and tcp_state_setup().