Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

lwip_tcp_out.c File Reference

lwip_tcp_out.c File Reference

Transmission Control Protocol, outgoing traffic. More...

Go to the source code of this file.

Functions

static err_t tcp_output_segment (struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif)
 Called by tcp_output() to actually send a TCP segment over IP.
static struct tcp_seg * tcp_create_segment (const struct tcp_pcb *pcb, struct pbuf *p, u8_t hdrflags, u32_t seqno, u8_t optflags)
 Create a TCP segment with prefilled header.
static struct pbuftcp_pbuf_prealloc (pbuf_layer layer, u16_t length, u16_t max_length, u16_t *oversize, const struct tcp_pcb *pcb, u8_t apiflags, u8_t first_seg)
 Allocate a PBUF_RAM pbuf, perhaps with extra space at the end.
static void tcp_seg_add_chksum (u16_t chksum, u16_t len, u16_t *seg_chksum, u8_t *seg_chksum_swapped)
 Add a checksum of newly added data to the segment.
static err_t tcp_write_checks (struct tcp_pcb *pcb, u16_t len)
 Checks if tcp_write is allowed or not (checks state, snd_buf and snd_queuelen).
err_t tcp_write (struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
 Write data for sending (but does not send it immediately).
err_t tcp_split_unsent_seg (struct tcp_pcb *pcb, u16_t split)
 Split segment on the head of the unsent queue.
err_t tcp_send_fin (struct tcp_pcb *pcb)
 Called by tcp_close() to send a segment including FIN flag but not data.
err_t tcp_enqueue_flags (struct tcp_pcb *pcb, u8_t flags)
 Enqueue SYN or FIN for transmission.
static u8_t tcp_get_num_sacks (const struct tcp_pcb *pcb, u8_t optlen)
 Calculates the number of SACK entries that should be generated.
static void tcp_build_sack_option (const struct tcp_pcb *pcb, u32_t *opts, u8_t num_sacks)
 Build a SACK option (12 or more bytes long) at the specified options pointer)
static void tcp_build_wnd_scale_option (u32_t *opts)
 Build a window scale option (3 bytes long) at the specified options pointer)
err_t tcp_output (struct tcp_pcb *pcb)
 Find out what we can send and send it.
static int tcp_output_segment_busy (const struct tcp_seg *seg)
 Check if a segment's pbufs are used by someone else than TCP.
err_t tcp_rexmit_rto_prepare (struct tcp_pcb *pcb)
 Requeue all unacked segments for retransmission.
void tcp_rexmit_rto_commit (struct tcp_pcb *pcb)
 Requeue all unacked segments for retransmission.
void tcp_rexmit_rto (struct tcp_pcb *pcb)
 Requeue all unacked segments for retransmission.
err_t tcp_rexmit (struct tcp_pcb *pcb)
 Requeue the first unacked segment for retransmission.
void tcp_rexmit_fast (struct tcp_pcb *pcb)
 Handle retransmission after three dupacks received.
static struct pbuftcp_output_alloc_header (struct tcp_pcb *pcb, u16_t optlen, u16_t datalen, u32_t seqno_be)
 Allocate a pbuf and create a tcphdr at p->payload, used for output functions other than the default tcp_output -> tcp_output_segment (e.g.
static err_t tcp_output_control_segment (const struct tcp_pcb *pcb, struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dst)
 Output a control segment pbuf to IP.
void tcp_rst (const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno, const ip_addr_t *local_ip, const ip_addr_t *remote_ip, u16_t local_port, u16_t remote_port)
 Send a TCP RESET packet (empty segment with RST flag set) either to abort a connection or to show that there is no matching local connection for a received segment.
err_t tcp_send_empty_ack (struct tcp_pcb *pcb)
 Send an ACK without data.
err_t tcp_keepalive (struct tcp_pcb *pcb)
 Send keepalive packets to keep a connection active although no data is sent over it.
err_t tcp_zero_window_probe (struct tcp_pcb *pcb)
 Send persist timer zero-window probes to keep a connection active when a window update is lost.

Detailed Description

Transmission Control Protocol, outgoing traffic.

The output functions of TCP.

There are two distinct ways for TCP segments to get sent:

  • queued data: these are segments transferring data or segments containing SYN or FIN (which both count as one sequence number). They are created as struct Packet buffers (PBUF) together with a struct tcp_seg and enqueue to the unsent list of the pcb. They are sent by tcp_output:
    • tcp_write : creates data segments
    • tcp_split_unsent_seg : splits a data segment
    • tcp_enqueue_flags : creates SYN-only or FIN-only segments
    • tcp_output / tcp_output_segment : finalize the tcp header (e.g. sequence numbers, options, checksum) and output to IP
    • the various tcp_rexmit functions shuffle around segments between the unsent an unacked lists to retransmit them
    • tcp_create_segment and tcp_pbuf_prealloc allocate pbuf and segment for these functions
  • direct send: these segments don't contain data but control the connection behaviour. They are created as pbuf only and sent directly without enqueueing them:

Definition in file lwip_tcp_out.c.


Function Documentation

static void tcp_build_sack_option ( const struct tcp_pcb pcb,
u32_t *  opts,
u8_t  num_sacks 
) [static]

Build a SACK option (12 or more bytes long) at the specified options pointer)

Parameters:
pcbtcp_pcb
optsoption pointer where to store the SACK option
num_sacksthe number of SACKs to store

Definition at line 1193 of file lwip_tcp_out.c.

static void tcp_build_wnd_scale_option ( u32_t *  opts ) [static]

Build a window scale option (3 bytes long) at the specified options pointer)

Parameters:
optsoption pointer where to store the window scale option

Definition at line 1219 of file lwip_tcp_out.c.

static struct tcp_seg* tcp_create_segment ( const struct tcp_pcb pcb,
struct pbuf p,
u8_t  hdrflags,
u32_t  seqno,
u8_t  optflags 
) [static, read]

Create a TCP segment with prefilled header.

Called by tcp_write, tcp_enqueue_flags and tcp_split_unsent_seg

Parameters:
pcbProtocol control block for the TCP connection.
ppbuf that is used to hold the TCP header.
hdrflagsTCP flags for header.
seqnoTCP sequence number of this packet
optflagsoptions to include in TCP header
Returns:
a new tcp_seg pointing to p, or NULL. The TCP header is filled in except ackno and wnd. p is freed on failure.

Definition at line 158 of file lwip_tcp_out.c.

err_t tcp_enqueue_flags ( struct tcp_pcb pcb,
u8_t  flags 
)

Enqueue SYN or FIN for transmission.

Called by tcp_connect, tcp_listen_input, and tcp_close (via tcp_send_fin)

Parameters:
pcbProtocol control block for the TCP connection.
flagsTCP header flags to set in the outgoing segment.

Definition at line 1032 of file lwip_tcp_out.c.

static u8_t tcp_get_num_sacks ( const struct tcp_pcb pcb,
u8_t  optlen 
) [static]

Calculates the number of SACK entries that should be generated.

It takes into account whether TF_SACK flag is set, the number of SACK entries in tcp_pcb that are valid, as well as the available options size.

Parameters:
pcbtcp_pcb
optlenthe length of other TCP options (in bytes)
Returns:
the number of SACK ranges that can be used

Definition at line 1162 of file lwip_tcp_out.c.

err_t tcp_keepalive ( struct tcp_pcb pcb )

Send keepalive packets to keep a connection active although no data is sent over it.

Called by tcp_slowtmr()

Parameters:
pcbthe tcp_pcb for which to send a keepalive packet

Definition at line 2078 of file lwip_tcp_out.c.

static struct pbuf* tcp_output_alloc_header ( struct tcp_pcb pcb,
u16_t  optlen,
u16_t  datalen,
u32_t  seqno_be 
) [static, read]

Allocate a pbuf and create a tcphdr at p->payload, used for output functions other than the default tcp_output -> tcp_output_segment (e.g.

tcp_send_empty_ack, etc.)

Parameters:
pcbtcp pcb for which to send a packet (used to initialize tcp_hdr)
optlenlength of header-options
datalenlength of tcp data to reserve in pbuf
seqno_beseqno in network byte order (big-endian)
Returns:
pbuf with p->payload being the tcp_hdr

Definition at line 1853 of file lwip_tcp_out.c.

static err_t tcp_output_control_segment ( const struct tcp_pcb pcb,
struct pbuf p,
const ip_addr_t src,
const ip_addr_t dst 
) [static]

Output a control segment pbuf to IP.

Called from tcp_rst, tcp_send_empty_ack, tcp_keepalive and tcp_zero_window_probe, this function combines selecting a netif for transmission, generating the tcp header checksum and calling ip_output_if while handling netif hints and stats.

Definition at line 1921 of file lwip_tcp_out.c.

static err_t tcp_output_segment ( struct tcp_seg *  seg,
struct tcp_pcb pcb,
struct netif netif 
) [static]

Called by tcp_output() to actually send a TCP segment over IP.

Parameters:
segthe tcp_seg to send
pcbthe tcp_pcb for the TCP connection used to send the segment
netifthe netif used to send the segment

Exclude retransmitted segments from this count.

Definition at line 1455 of file lwip_tcp_out.c.

static int tcp_output_segment_busy ( const struct tcp_seg *  seg ) [static]

Check if a segment's pbufs are used by someone else than TCP.

This can happen on retransmission if the pbuf of this segment is still referenced by the netif driver due to deferred transmission. This is the case (only!) if someone down the TX call path called pbuf_ref() on one of the pbufs!

  • seg the tcp segment to check
    Returns:
    1 if ref != 1, 0 if ref == 1

Definition at line 1432 of file lwip_tcp_out.c.

static struct pbuf* tcp_pbuf_prealloc ( pbuf_layer  layer,
u16_t  length,
u16_t  max_length,
u16_t *  oversize,
const struct tcp_pcb pcb,
u8_t  apiflags,
u8_t  first_seg 
) [static, read]

Allocate a PBUF_RAM pbuf, perhaps with extra space at the end.

This function is like pbuf_alloc(layer, length, PBUF_RAM) except there may be extra bytes available at the end.

Called by tcp_write

Parameters:
layerflag to define header size.
lengthsize of the pbuf's payload.
max_lengthmaximum usable size of payload+oversize.
oversizepointer to a u16_t that will receive the number of usable tail bytes.
pcbThe TCP connection that will enqueue the pbuf.
apiflagsAPI flags given to tcp_write.
first_segtrue when this pbuf will be used in the first enqueued segment.

Definition at line 225 of file lwip_tcp_out.c.

err_t tcp_rexmit ( struct tcp_pcb pcb )

Requeue the first unacked segment for retransmission.

Called by tcp_receive() for fast retransmit.

Parameters:
pcbthe tcp_pcb for which to retransmit the first unacked segment

Definition at line 1724 of file lwip_tcp_out.c.

void tcp_rexmit_fast ( struct tcp_pcb pcb )

Handle retransmission after three dupacks received.

Parameters:
pcbthe tcp_pcb for which to retransmit the first unacked segment

Definition at line 1783 of file lwip_tcp_out.c.

void tcp_rexmit_rto ( struct tcp_pcb pcb )

Requeue all unacked segments for retransmission.

Called by tcp_process() only, tcp_slowtmr() needs to do some things between "prepare" and "commit".

Parameters:
pcbthe tcp_pcb for which to re-enqueue all unacked segments

Definition at line 1707 of file lwip_tcp_out.c.

void tcp_rexmit_rto_commit ( struct tcp_pcb pcb )

Requeue all unacked segments for retransmission.

Called by tcp_slowtmr() for slow retransmission.

Parameters:
pcbthe tcp_pcb for which to re-enqueue all unacked segments

Definition at line 1686 of file lwip_tcp_out.c.

err_t tcp_rexmit_rto_prepare ( struct tcp_pcb pcb )

Requeue all unacked segments for retransmission.

Called by tcp_slowtmr() for slow retransmission.

Parameters:
pcbthe tcp_pcb for which to re-enqueue all unacked segments

Definition at line 1631 of file lwip_tcp_out.c.

void tcp_rst ( const struct tcp_pcb pcb,
u32_t  seqno,
u32_t  ackno,
const ip_addr_t local_ip,
const ip_addr_t remote_ip,
u16_t  local_port,
u16_t  remote_port 
)

Send a TCP RESET packet (empty segment with RST flag set) either to abort a connection or to show that there is no matching local connection for a received segment.

Called by tcp_abort() (to abort a local connection), tcp_input() (if no matching local pcb was found), tcp_listen_input() (if incoming segment has ACK flag set) and tcp_process() (received segment in the wrong state)

Since a RST segment is in most cases not sent for an active connection, tcp_rst() has a number of arguments that are taken from a tcp_pcb for most other segment output functions.

Parameters:
pcbTCP pcb (may be NULL if no pcb is available)
seqnothe sequence number to use for the outgoing segment
acknothe acknowledge number to use for the outgoing segment
local_ipthe local IP address to send the segment from
remote_ipthe remote IP address to send the segment to
local_portthe local TCP port to send the segment from
remote_portthe remote TCP port to send the segment to

Definition at line 1980 of file lwip_tcp_out.c.

static void tcp_seg_add_chksum ( u16_t  chksum,
u16_t  len,
u16_t *  seg_chksum,
u8_t *  seg_chksum_swapped 
) [static]

Add a checksum of newly added data to the segment.

Called by tcp_write and tcp_split_unsent_seg.

Definition at line 283 of file lwip_tcp_out.c.

err_t tcp_send_empty_ack ( struct tcp_pcb pcb )

Send an ACK without data.

Parameters:
pcbProtocol control block for the TCP connection to send the ACK

Definition at line 2019 of file lwip_tcp_out.c.

err_t tcp_send_fin ( struct tcp_pcb pcb )

Called by tcp_close() to send a segment including FIN flag but not data.

This FIN may be added to an existing segment or a new, otherwise empty segment is enqueued.

Parameters:
pcbthe tcp_pcb over which to send a segment
Returns:
ERR_OK if sent, another err_t otherwise

Definition at line 1001 of file lwip_tcp_out.c.

err_t tcp_split_unsent_seg ( struct tcp_pcb pcb,
u16_t  split 
)

Split segment on the head of the unsent queue.

If return is not ERR_OK, existing head remains intact

The split is accomplished by creating a new TCP segment and pbuf which holds the remainder payload after the split. The original pbuf is trimmed to new length. This allows splitting of read-only pbufs

Parameters:
pcbthe tcp_pcb for which to split the unsent head
splitthe amount of payload to remain in the head

Definition at line 827 of file lwip_tcp_out.c.

static err_t tcp_write_checks ( struct tcp_pcb pcb,
u16_t  len 
) [static]

Checks if tcp_write is allowed or not (checks state, snd_buf and snd_queuelen).

Parameters:
pcbthe tcp pcb to check for
lenlength of data to send (checked agains snd_buf)
Returns:
ERR_OK if tcp_write is allowed to proceed, another err_t otherwise

Definition at line 305 of file lwip_tcp_out.c.

err_t tcp_zero_window_probe ( struct tcp_pcb pcb )

Send persist timer zero-window probes to keep a connection active when a window update is lost.

Called by tcp_slowtmr()

Parameters:
pcbthe tcp_pcb for which to send a zero-window probe packet

Definition at line 2116 of file lwip_tcp_out.c.