lwIP
2.1.0
Lightweight IP stack
|
#include "lwip/opt.h"
#include "lwip/tcp.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/ip.h"
#include "lwip/icmp.h"
#include "lwip/err.h"
#include "lwip/ip6.h"
#include "lwip/ip6_addr.h"
#include "lwip/prot/tcp.h"
Macros | |
#define | tcp_do_output_nagle(tpcb) |
#define | TF_RESET (u8_t)0x08U /* Connection was reset. */ |
#define | TCP_OVERSIZE_DBGCHECK 0 |
#define | TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) |
#define | TCP_BUILD_MSS_OPTION(mss) lwip_htonl(0x02040000 | ((mss) & 0xFFFF)) |
Functions | |
void | tcp_init (void) |
void | tcp_tmr (void) |
void | tcp_slowtmr (void) |
void | tcp_fasttmr (void) |
void | tcp_txnow (void) |
void | tcp_input (struct pbuf *p, struct netif *inp) |
struct tcp_pcb * | tcp_alloc (u8_t prio) |
void | tcp_free (struct tcp_pcb *pcb) |
void | tcp_abandon (struct tcp_pcb *pcb, int reset) |
err_t | tcp_send_empty_ack (struct tcp_pcb *pcb) |
err_t | tcp_rexmit (struct tcp_pcb *pcb) |
err_t | tcp_rexmit_rto_prepare (struct tcp_pcb *pcb) |
void | tcp_rexmit_rto_commit (struct tcp_pcb *pcb) |
void | tcp_rexmit_rto (struct tcp_pcb *pcb) |
void | tcp_rexmit_fast (struct tcp_pcb *pcb) |
u32_t | tcp_update_rcv_ann_wnd (struct tcp_pcb *pcb) |
err_t | tcp_process_refused_data (struct tcp_pcb *pcb) |
void | tcp_pcb_purge (struct tcp_pcb *pcb) |
void | tcp_pcb_remove (struct tcp_pcb **pcblist, struct tcp_pcb *pcb) |
void | tcp_segs_free (struct tcp_seg *seg) |
void | tcp_seg_free (struct tcp_seg *seg) |
struct tcp_seg * | tcp_seg_copy (struct tcp_seg *seg) |
err_t | tcp_send_fin (struct tcp_pcb *pcb) |
err_t | tcp_enqueue_flags (struct tcp_pcb *pcb, u8_t flags) |
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) |
u32_t | tcp_next_iss (struct tcp_pcb *pcb) |
err_t | tcp_keepalive (struct tcp_pcb *pcb) |
err_t | tcp_split_unsent_seg (struct tcp_pcb *pcb, u16_t split) |
err_t | tcp_zero_window_probe (struct tcp_pcb *pcb) |
u16_t | tcp_eff_send_mss_netif (u16_t sendmss, struct netif *outif, const ip_addr_t *dest) |
err_t | tcp_recv_null (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) |
void | tcp_timer_needed (void) |
void | tcp_netif_ip_addr_changed (const ip_addr_t *old_addr, const ip_addr_t *new_addr) |
err_t | tcp_ext_arg_invoke_callbacks_passive_open (struct tcp_pcb_listen *lpcb, struct tcp_pcb *cpcb) |
Variables | |
struct tcp_pcb * | tcp_bound_pcbs |
union tcp_listen_pcbs_t | tcp_listen_pcbs |
struct tcp_pcb * | tcp_active_pcbs |
struct tcp_pcb * | tcp_tw_pcbs |
struct tcp_pcb **const | tcp_pcb_lists [4] |
TCP internal implementations (do not use in application code)
#define TCP_BUILD_MSS_OPTION | ( | mss | ) | lwip_htonl(0x02040000 | ((mss) & 0xFFFF)) |
This returns a TCP header option for MSS in an u32_t
#define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) |
Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled
#define tcp_do_output_nagle | ( | tpcb | ) |
This is the Nagle algorithm: try to combine user data to send as few TCP segments as possible. Only send if
#define TCP_OVERSIZE_DBGCHECK 0 |
Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled
#define TF_RESET (u8_t)0x08U /* Connection was reset. */ |
Flags used on input processing, not on pcb->flags
void tcp_abandon | ( | struct tcp_pcb * | pcb, |
int | reset | ||
) |
Abandons a connection and optionally sends a RST to the remote host. Deletes the local protocol control block. This is done when a connection is killed because of shortage of memory.
pcb | the tcp_pcb to abort |
reset | boolean to indicate whether a reset should be sent |
struct tcp_pcb* tcp_alloc | ( | u8_t | prio | ) |
Calculates the effective send mss that can be used for a specific IP address by calculating the minimum of TCP_MSS and the mtu (if set) of the target netif (if not NULL).
Enqueue SYN or FIN for transmission.
Called by tcp_connect, tcp_listen_input, and tcp_close (via tcp_send_fin)
pcb | Protocol control block for the TCP connection. |
flags | TCP header flags to set in the outgoing segment. |
err_t tcp_ext_arg_invoke_callbacks_passive_open | ( | struct tcp_pcb_listen * | lpcb, |
struct tcp_pcb * | cpcb | ||
) |
This function calls the "passive_open" callback for all ext_args if a connection is in the process of being accepted. This is called just after the SYN is received and before a SYN/ACK is sent, to allow to modify the very first segment sent even on passive open. Naturally, the "accepted" callback of the pcb has not been called yet!
void tcp_fasttmr | ( | void | ) |
Is called every TCP_FAST_INTERVAL (250 ms) and process data previously "refused" by upper layer (application) and sends delayed ACKs or pending FINs.
Automatically called from tcp_tmr().
void tcp_free | ( | struct tcp_pcb * | pcb | ) |
Free a tcp pcb
void tcp_init | ( | void | ) |
Initialize this module.
The initial input processing of TCP. It verifies the TCP header, demultiplexes the segment between the PCBs and passes it on to tcp_process(), which implements the TCP finite state machine. This function is called by the IP layer (in ip_input()).
p | received TCP segment to process (p->payload pointing to the TCP header) |
inp | network interface on which this segment was received |
Send keepalive packets to keep a connection active although no data is sent over it.
Called by tcp_slowtmr()
pcb | the tcp_pcb for which to send a keepalive packet |
This function is called from netif.c when address is changed or netif is removed
old_addr | IP address of the netif before change |
new_addr | IP address of the netif after change or NULL if netif has been removed |
u32_t tcp_next_iss | ( | struct tcp_pcb * | pcb | ) |
Calculates a new initial sequence number for new connections.
void tcp_pcb_purge | ( | struct tcp_pcb * | pcb | ) |
Purges a TCP PCB. Removes any buffered data and frees the buffer memory (pcb->ooseq, pcb->unsent and pcb->unacked are freed).
pcb | tcp_pcb to purge. The pcb itself is not deallocated! |
Purges the PCB and removes it from a PCB list. Any delayed ACKs are sent first.
pcblist | PCB list to purge. |
pcb | tcp_pcb to purge. The pcb itself is NOT deallocated! |
Default receive callback that is called if the user didn't register a recv callback for the pcb.
Requeue the first unacked segment for retransmission
Called by tcp_receive() for fast retransmit.
pcb | the tcp_pcb for which to retransmit the first unacked segment |
void tcp_rexmit_fast | ( | struct tcp_pcb * | pcb | ) |
Handle retransmission after three dupacks received
pcb | the tcp_pcb for which to retransmit the first unacked segment |
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".
pcb | the tcp_pcb for which to re-enqueue all unacked segments |
void tcp_rexmit_rto_commit | ( | struct tcp_pcb * | pcb | ) |
Requeue all unacked segments for retransmission
Called by tcp_slowtmr() for slow retransmission.
pcb | the tcp_pcb for which to re-enqueue all unacked segments |
Requeue all unacked segments for retransmission
Called by tcp_slowtmr() for slow retransmission.
pcb | the tcp_pcb for which to re-enqueue all unacked segments |
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.
pcb | TCP pcb (may be NULL if no pcb is available) |
seqno | the sequence number to use for the outgoing segment |
ackno | the acknowledge number to use for the outgoing segment |
local_ip | the local IP address to send the segment from |
remote_ip | the remote IP address to send the segment to |
local_port | the local TCP port to send the segment from |
remote_port | the remote TCP port to send the segment to |
struct tcp_seg* tcp_seg_copy | ( | struct tcp_seg * | seg | ) |
Returns a copy of the given TCP segment. The pbuf and data are not copied, only the pointers
seg | the old tcp_seg |
void tcp_seg_free | ( | struct tcp_seg * | seg | ) |
Frees a TCP segment (tcp_seg structure).
seg | single tcp_seg to free |
void tcp_segs_free | ( | struct tcp_seg * | seg | ) |
Deallocates a list of TCP segments (tcp_seg structures).
seg | tcp_seg list of TCP segments to free |
Send an ACK without data.
pcb | Protocol control block for the TCP connection to send the ACK |
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.
pcb | the tcp_pcb over which to send a segment |
void tcp_slowtmr | ( | void | ) |
Called every 500 ms and implements the retransmission timer and the timer that removes PCBs that have been in TIME-WAIT for enough time. It also increments various timers such as the inactivity timer in each PCB.
Automatically called from tcp_tmr().
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
pcb | the tcp_pcb for which to split the unsent head |
split | the amount of payload to remain in the head |
void tcp_timer_needed | ( | void | ) |
External function (implemented in timers.c), called when TCP detects that a timer is needed (i.e. active- or time-wait-pcb found).
Called from TCP_REG when registering a new PCB: the reason is to have the TCP timer only running when there are active (or time-wait) PCBs.
void tcp_tmr | ( | void | ) |
Called periodically to dispatch TCP timers.
void tcp_txnow | ( | void | ) |
Call tcp_output for all active pcbs that have TF_NAGLEMEMERR set
u32_t tcp_update_rcv_ann_wnd | ( | struct tcp_pcb * | pcb | ) |
Update the state that tracks the available window space to advertise.
Returns how much extra window would be advertised if we sent an update now.
Send persist timer zero-window probes to keep a connection active when a window update is lost.
Called by tcp_slowtmr()
pcb | the tcp_pcb for which to send a zero-window probe packet |
struct tcp_pcb* tcp_active_pcbs |
List of all TCP PCBs that are in a state in which they accept or send data.
struct tcp_pcb* tcp_bound_pcbs |
List of all TCP PCBs bound but not yet (connected || listening)
union tcp_listen_pcbs_t tcp_listen_pcbs |
List of all TCP PCBs in LISTEN state
struct tcp_pcb** const tcp_pcb_lists[4] |
An array with all (non-temporary) PCB lists, mainly used for smaller code size
struct tcp_pcb* tcp_tw_pcbs |
List of all TCP PCBs in TIME-WAIT state