ReactOS 0.4.16-dev-297-gc569aee
tcp_helper.h File Reference
#include "../lwip_check.h"
#include "lwip/arch.h"
#include "lwip/tcp.h"
#include "lwip/netif.h"
Include dependency graph for tcp_helper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  test_tcp_counters
 
struct  test_tcp_txcounters
 

Macros

#define TEST_REMOTE_PORT   0x100
 
#define TEST_LOCAL_PORT   0x101
 

Functions

void tcp_remove_all (void)
 
struct pbuftcp_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)
 
struct pbuftcp_create_rx_segment (struct tcp_pcb *pcb, void *data, size_t data_len, u32_t seqno_offset, u32_t ackno_offset, u8_t headerflags)
 
struct pbuftcp_create_rx_segment_wnd (struct tcp_pcb *pcb, void *data, size_t data_len, u32_t seqno_offset, u32_t ackno_offset, u8_t headerflags, u16_t wnd)
 
void tcp_set_state (struct tcp_pcb *pcb, enum tcp_state state, const ip_addr_t *local_ip, const ip_addr_t *remote_ip, u16_t local_port, u16_t remote_port)
 
void test_tcp_counters_err (void *arg, err_t err)
 
err_t test_tcp_counters_recv (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
 
struct tcp_pcb * test_tcp_new_counters_pcb (struct test_tcp_counters *counters)
 
void test_tcp_input (struct pbuf *p, struct netif *inp)
 
void test_tcp_init_netif (struct netif *netif, struct test_tcp_txcounters *txcounters, const ip_addr_t *ip_addr, const ip_addr_t *netmask)
 

Variables

const ip_addr_t test_local_ip
 
const ip_addr_t test_remote_ip
 
const ip_addr_t test_netmask
 

Macro Definition Documentation

◆ TEST_LOCAL_PORT

#define TEST_LOCAL_PORT   0x101

Definition at line 33 of file tcp_helper.h.

◆ TEST_REMOTE_PORT

#define TEST_REMOTE_PORT   0x100

Definition at line 32 of file tcp_helper.h.

Function Documentation

◆ tcp_create_rx_segment()

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 
)

Create a TCP segment usable for passing to tcp_input

  • IP-addresses, ports, seqno and ackno are taken from pcb
  • seqno and ackno can be altered with an offset

Definition at line 130 of file tcp_helper.c.

132{
133 return tcp_create_segment(&pcb->remote_ip, &pcb->local_ip, pcb->remote_port, pcb->local_port,
134 data, data_len, pcb->rcv_nxt + seqno_offset, pcb->lastack + ackno_offset, headerflags);
135}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
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

Referenced by START_TEST(), test_tcp_recv_ooseq_double_FINs(), and test_tcp_tx_full_window_lost().

◆ tcp_create_rx_segment_wnd()

struct pbuf * tcp_create_rx_segment_wnd ( struct tcp_pcb *  pcb,
void data,
size_t  data_len,
u32_t  seqno_offset,
u32_t  ackno_offset,
u8_t  headerflags,
u16_t  wnd 
)

Create a TCP segment usable for passing to tcp_input

  • IP-addresses, ports, seqno and ackno are taken from pcb
  • seqno and ackno can be altered with an offset
  • TCP window can be adjusted

Definition at line 142 of file tcp_helper.c.

144{
145 return tcp_create_segment_wnd(&pcb->remote_ip, &pcb->local_ip, pcb->remote_port, pcb->local_port,
146 data, data_len, pcb->rcv_nxt + seqno_offset, pcb->lastack + ackno_offset, headerflags, wnd);
147}
static struct pbuf * tcp_create_segment_wnd(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, u16_t wnd)
Definition: tcp_helper.c:52

Referenced by START_TEST(), test_tcp_tx_full_window_lost(), and test_tcp_zwp_timeout_impl().

◆ tcp_create_segment()

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 
)

Create a TCP segment usable for passing to tcp_input

Definition at line 117 of file tcp_helper.c.

120{
121 return tcp_create_segment_wnd(src_ip, dst_ip, src_port, dst_port, data,
122 data_len, seqno, ackno, headerflags, TCP_WND);
123}
#define TCP_WND
Definition: lwipopts.h:48

Referenced by START_TEST(), and tcp_create_rx_segment().

◆ tcp_remove_all()

void tcp_remove_all ( void  )

Remove all pcbs on listen-, active- and time-wait-list (bound- isn't exported).

Definition at line 38 of file tcp_helper.c.

39{
40 tcp_remove(tcp_listen_pcbs.pcbs);
41 tcp_remove(tcp_bound_pcbs);
42 tcp_remove(tcp_active_pcbs);
43 tcp_remove(tcp_tw_pcbs);
44 fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
45 fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB_LISTEN) == 0);
46 fail_unless(MEMP_STATS_GET(used, MEMP_TCP_SEG) == 0);
47 fail_unless(MEMP_STATS_GET(used, MEMP_PBUF_POOL) == 0);
48}
static int used
Definition: adh-main.c:39
#define MEMP_STATS_GET(x, i)
Definition: stats.h:409
static void tcp_remove(struct tcp_pcb *pcb_list)
Definition: tcp_helper.c:20

Referenced by tcp_oos_setup(), tcp_oos_teardown(), tcp_setup(), tcp_state_setup(), tcp_state_teardown(), and tcp_teardown().

◆ tcp_set_state()

void tcp_set_state ( struct tcp_pcb *  pcb,
enum tcp_state  state,
const ip_addr_t local_ip,
const ip_addr_t remote_ip,
u16_t  local_port,
u16_t  remote_port 
)

Safely bring a tcp_pcb into the requested state

Definition at line 151 of file tcp_helper.c.

153{
154 u32_t iss;
155
156 /* @todo: are these all states? */
157 /* @todo: remove from previous list */
158 pcb->state = state;
159
160 iss = tcp_next_iss(pcb);
161 pcb->snd_wl2 = iss;
162 pcb->snd_nxt = iss;
163 pcb->lastack = iss;
164 pcb->snd_lbb = iss;
165
166 if (state == ESTABLISHED) {
167 TCP_REG(&tcp_active_pcbs, pcb);
168 ip_addr_copy(pcb->local_ip, *local_ip);
169 pcb->local_port = local_port;
170 ip_addr_copy(pcb->remote_ip, *remote_ip);
171 pcb->remote_port = remote_port;
172 } else if(state == LISTEN) {
173 TCP_REG(&tcp_listen_pcbs.pcbs, pcb);
174 ip_addr_copy(pcb->local_ip, *local_ip);
175 pcb->local_port = local_port;
176 } else if(state == TIME_WAIT) {
177 TCP_REG(&tcp_tw_pcbs, pcb);
178 ip_addr_copy(pcb->local_ip, *local_ip);
179 pcb->local_port = local_port;
180 ip_addr_copy(pcb->remote_ip, *remote_ip);
181 pcb->remote_port = remote_port;
182 } else {
183 fail();
184 }
185}
static int state
Definition: maze.c:121
uint32_t u32_t
Definition: arch.h:129
#define ip_addr_copy(dest, src)
Definition: ip_addr.h:360

◆ test_tcp_counters_err()

void test_tcp_counters_err ( void arg,
err_t  err 
)

Definition at line 188 of file tcp_helper.c.

189{
191 EXPECT_RET(arg != NULL);
192 counters->err_calls++;
193 counters->last_err = err;
194}
#define NULL
Definition: types.h:112
GLint GLint GLsizei GLuint * counters
Definition: glext.h:11114
#define EXPECT_RET(x)
Definition: lwip_check.h:12
#define err(...)

Referenced by test_tcp_new_counters_pcb().

◆ test_tcp_counters_recv()

err_t test_tcp_counters_recv ( void arg,
struct tcp_pcb *  pcb,
struct pbuf p,
err_t  err 
)

Definition at line 218 of file tcp_helper.c.

219{
222 EXPECT_RETX(pcb != NULL, ERR_OK);
224
225 if (p != NULL) {
226 if (counters->close_calls == 0) {
227 counters->recv_calls++;
229 counters->recved_bytes += p->tot_len;
230 } else {
231 counters->recv_calls_after_close++;
232 counters->recved_bytes_after_close += p->tot_len;
233 }
234 pbuf_free(p);
235 } else {
236 counters->close_calls++;
237 }
238 EXPECT(counters->recv_calls_after_close == 0 && counters->recved_bytes_after_close == 0);
239 return ERR_OK;
240}
GLfloat GLfloat p
Definition: glext.h:8902
@ ERR_OK
Definition: err.h:55
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
#define EXPECT_RETX(x, y)
Definition: lwip_check.h:13
#define EXPECT(x)
Definition: lwip_check.h:11
static void test_tcp_counters_check_rxdata(struct test_tcp_counters *counters, struct pbuf *p)
Definition: tcp_helper.c:197

Referenced by test_tcp_new_counters_pcb().

◆ test_tcp_init_netif()

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 at line 305 of file tcp_helper.c.

307{
308 struct netif *n;
309 memset(netif, 0, sizeof(struct netif));
310 if (txcounters != NULL) {
311 memset(txcounters, 0, sizeof(struct test_tcp_txcounters));
312 netif->state = txcounters;
313 }
316 ip_addr_copy_from_ip4(netif->netmask, *ip_2_ip4(netmask));
317 ip_addr_copy_from_ip4(netif->ip_addr, *ip_2_ip4(ip_addr));
318 for (n = netif_list; n != NULL; n = n->next) {
319 if (n == netif) {
320 return;
321 }
322 }
323 netif->next = NULL;
325}
GLdouble n
Definition: glext.h:7729
#define NETIF_FLAG_LINK_UP
Definition: netif.h:93
#define NETIF_FLAG_UP
Definition: netif.h:84
struct netif * netif_list
Definition: netif.c:113
#define memset(x, y, z)
Definition: compat.h:39
struct define * next
Definition: compiler.c:65
Definition: netif.h:269
u8_t flags
Definition: netif.h:354
void * state
Definition: netif.h:332
struct netif * next
Definition: netif.h:272
static err_t test_tcp_netif_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr)
Definition: tcp_helper.c:280

Referenced by START_TEST(), tcp_state_setup(), test_tcp_recv_ooseq_double_FINs(), test_tcp_rto_timeout_impl(), test_tcp_rto_timeout_syn_sent_impl(), test_tcp_tx_full_window_lost(), and test_tcp_zwp_timeout_impl().

◆ test_tcp_input()

void test_tcp_input ( struct pbuf p,
struct netif inp 
)

Calls tcp_input() after adjusting current_iphdr_dest

Definition at line 259 of file tcp_helper.c.

260{
261 struct ip_hdr *iphdr = (struct ip_hdr*)p->payload;
262 /* these lines are a hack, don't use them as an example :-) */
263 ip_addr_copy_from_ip4(*ip_current_dest_addr(), iphdr->dest);
264 ip_addr_copy_from_ip4(*ip_current_src_addr(), iphdr->src);
265 ip_current_netif() = inp;
266 ip_data.current_ip4_header = iphdr;
267 ip_data.current_input_netif = inp;
268
269 /* since adding IPv6, p->payload must point to tcp header, not ip header */
270 pbuf_header(p, -(s16_t)sizeof(struct ip_hdr));
271
272 tcp_input(p, inp);
273
277 ip_data.current_ip4_header = NULL;
278}
#define ip_current_src_addr()
Definition: ip.h:223
#define ip_current_dest_addr()
Definition: ip.h:225
#define ip_current_netif()
Definition: ip.h:146
struct ip_globals ip_data
int16_t s16_t
Definition: arch.h:128
#define ip_addr_set_zero(ipaddr)
Definition: ip_addr.h:365
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:649
Definition: ip4.h:73

Referenced by START_TEST(), test_rst_generation_with_incoming_packet(), test_tcp_recv_ooseq_double_FINs(), test_tcp_tx_full_window_lost(), and test_tcp_zwp_timeout_impl().

◆ test_tcp_new_counters_pcb()

struct tcp_pcb * test_tcp_new_counters_pcb ( struct test_tcp_counters counters)

Allocate a pcb and set up the test_tcp_counters_* callbacks

Definition at line 244 of file tcp_helper.c.

245{
246 struct tcp_pcb* pcb = tcp_new();
247 if (pcb != NULL) {
248 /* set up args and callbacks */
249 tcp_arg(pcb, counters);
251 tcp_err(pcb, test_tcp_counters_err);
252 pcb->snd_wnd = TCP_WND;
253 pcb->snd_wnd_max = TCP_WND;
254 }
255 return pcb;
256}
STREAM tcp_recv(STREAM s, uint32 length)
Definition: tcp.c:344
void test_tcp_counters_err(void *arg, err_t err)
Definition: tcp_helper.c:188
err_t test_tcp_counters_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
Definition: tcp_helper.c:218

Referenced by create_listening_pcb(), START_TEST(), test_tcp_recv_ooseq_double_FINs(), test_tcp_rto_timeout_impl(), test_tcp_rto_timeout_syn_sent_impl(), test_tcp_tx_full_window_lost(), and test_tcp_zwp_timeout_impl().

Variable Documentation

◆ test_local_ip

◆ test_netmask

const ip_addr_t test_netmask
extern

Definition at line 16 of file tcp_helper.c.

◆ test_remote_ip