FD.io VPP  v17.07-30-g839fa73
Vector Packet Processing
tcp.c File Reference
+ Include dependency graph for tcp.c:

Go to the source code of this file.

Data Structures

struct  ip4_tcp_hdr
 
struct  ip6_tcp_hdr
 

Macros

#define PORT_MASK   ((1 << 16)- 1)
 

Typedefs

typedef struct ip4_tcp_hdr ip4_tcp_hdr_t
 
typedef struct ip6_tcp_hdr ip6_tcp_hdr_t
 

Functions

static u32 tcp_connection_bind (u32 session_index, ip46_address_t *ip, u16 port_host_byte_order, u8 is_ip4)
 
u32 tcp_session_bind_ip4 (u32 session_index, ip46_address_t *ip, u16 port_host_byte_order)
 
u32 tcp_session_bind_ip6 (u32 session_index, ip46_address_t *ip, u16 port_host_byte_order)
 
static void tcp_connection_unbind (u32 listener_index)
 
u32 tcp_session_unbind (u32 listener_index)
 
transport_connection_ttcp_session_get_listener (u32 listener_index)
 
void tcp_connection_cleanup (tcp_connection_t *tc)
 Cleans up connection state. More...
 
void tcp_connection_del (tcp_connection_t *tc)
 Connection removal. More...
 
void tcp_connection_reset (tcp_connection_t *tc)
 Notify session that connection has been reset. More...
 
void tcp_connection_close (tcp_connection_t *tc)
 Begin connection closing procedure. More...
 
void tcp_session_close (u32 conn_index, u32 thread_index)
 
void tcp_session_cleanup (u32 conn_index, u32 thread_index)
 
void * ip_interface_get_first_ip (u32 sw_if_index, u8 is_ip4)
 
u16 tcp_allocate_local_port (tcp_main_t *tm, ip46_address_t *ip)
 Allocate local port and add if successful add entry to local endpoint table to mark the pair as used. More...
 
void tcp_connection_timers_init (tcp_connection_t *tc)
 Initialize all connection timers as invalid. More...
 
void tcp_connection_timers_reset (tcp_connection_t *tc)
 Stop all connection timers. More...
 
static void tcp_connection_select_lb_bucket (tcp_connection_t *tc, const dpo_id_t *dpo, dpo_id_t *result)
 
fib_node_index_t tcp_lookup_rmt_in_fib (tcp_connection_t *tc)
 
static int tcp_connection_stack_on_fib_entry (tcp_connection_t *tc)
 
static void tcp_connection_fib_attach (tcp_connection_t *tc)
 Stack tcp connection on peer's fib entry. More...
 
void tcp_connection_init_vars (tcp_connection_t *tc)
 Initialize tcp connection variables. More...
 
int tcp_connection_open (ip46_address_t *rmt_addr, u16 rmt_port, u8 is_ip4)
 
int tcp_session_open_ip4 (ip46_address_t *addr, u16 port)
 
int tcp_session_open_ip6 (ip46_address_t *addr, u16 port)
 
u8format_tcp_state (u8 *s, va_list *args)
 
u8format_tcp_timers (u8 *s, va_list *args)
 
u8format_tcp_congestion_status (u8 *s, va_list *args)
 
u8format_tcp_vars (u8 *s, va_list *args)
 
u8format_tcp_connection_id (u8 *s, va_list *args)
 
u8format_tcp_connection (u8 *s, va_list *args)
 
u8format_tcp_session (u8 *s, va_list *args)
 
u8format_tcp_listener_session (u8 *s, va_list *args)
 
u8format_tcp_half_open_session (u8 *s, va_list *args)
 
u8format_tcp_sacks (u8 *s, va_list *args)
 
u8format_tcp_sack_hole (u8 *s, va_list *args)
 
u8format_tcp_scoreboard (u8 *s, va_list *args)
 
transport_connection_ttcp_session_get_transport (u32 conn_index, u32 thread_index)
 
transport_connection_ttcp_half_open_session_get_transport (u32 conn_index)
 
u16 tcp_session_send_mss (transport_connection_t *trans_conn)
 Compute maximum segment size for session layer. More...
 
static u32 tcp_round_snd_space (tcp_connection_t *tc, u32 snd_space)
 
u32 tcp_snd_space (tcp_connection_t *tc)
 Compute tx window session is allowed to fill. More...
 
u32 tcp_session_send_space (transport_connection_t *trans_conn)
 
i32 tcp_rcv_wnd_available (tcp_connection_t *tc)
 
u32 tcp_session_tx_fifo_offset (transport_connection_t *trans_conn)
 
void tcp_timer_keep_handler (u32 conn_index)
 
void tcp_timer_establish_handler (u32 conn_index)
 
void tcp_timer_waitclose_handler (u32 conn_index)
 
static void tcp_expired_timers_dispatch (u32 *expired_timers)
 
void tcp_initialize_timer_wheels (tcp_main_t *tm)
 
clib_error_ttcp_main_enable (vlib_main_t *vm)
 
clib_error_tvnet_tcp_enable_disable (vlib_main_t *vm, u8 is_en)
 
clib_error_ttcp_init (vlib_main_t *vm)
 

Variables

tcp_main_t tcp_main
 
const char * tcp_dbg_evt_str []
 
const char * tcp_fsm_states []
 
const char * tcp_conn_timers []
 
static const transport_proto_vft_t tcp4_proto
 
static const transport_proto_vft_t tcp6_proto
 
static timer_expiration_handlertimer_expiration_handlers [TCP_N_TIMERS]
 

Macro Definition Documentation

#define PORT_MASK   ((1 << 16)- 1)

Definition at line 265 of file tcp.c.

Typedef Documentation

typedef struct ip4_tcp_hdr ip4_tcp_hdr_t
typedef struct ip6_tcp_hdr ip6_tcp_hdr_t

Function Documentation

u8* format_tcp_congestion_status ( u8 s,
va_list *  args 
)

Definition at line 601 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_tcp_connection ( u8 s,
va_list *  args 
)

Definition at line 669 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_tcp_connection_id ( u8 s,
va_list *  args 
)

Definition at line 645 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_tcp_half_open_session ( u8 s,
va_list *  args 
)

Definition at line 709 of file tcp.c.

+ Here is the call graph for this function:

u8* format_tcp_listener_session ( u8 s,
va_list *  args 
)

Definition at line 701 of file tcp.c.

+ Here is the call graph for this function:

u8* format_tcp_sack_hole ( u8 s,
va_list *  args 
)

Definition at line 731 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_tcp_sacks ( u8 s,
va_list *  args 
)

Definition at line 717 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_tcp_scoreboard ( u8 s,
va_list *  args 
)

Definition at line 739 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_tcp_session ( u8 s,
va_list *  args 
)

Definition at line 685 of file tcp.c.

+ Here is the call graph for this function:

u8* format_tcp_state ( u8 s,
va_list *  args 
)

Definition at line 558 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_tcp_timers ( u8 s,
va_list *  args 
)

Definition at line 576 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_tcp_vars ( u8 s,
va_list *  args 
)

Definition at line 614 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* ip_interface_get_first_ip ( u32  sw_if_index,
u8  is_ip4 
)

Definition at line 237 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u16 tcp_allocate_local_port ( tcp_main_t tm,
ip46_address_t *  ip 
)

Allocate local port and add if successful add entry to local endpoint table to mark the pair as used.

Definition at line 271 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static u32 tcp_connection_bind ( u32  session_index,
ip46_address_t *  ip,
u16  port_host_byte_order,
u8  is_ip4 
)
static

Definition at line 25 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tcp_connection_cleanup ( tcp_connection_t tc)

Cleans up connection state.

No notifications.

Definition at line 104 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tcp_connection_close ( tcp_connection_t tc)

Begin connection closing procedure.

If at the end the connection is not in CLOSED state, it is not removed. Instead, we rely on on TCP to advance through state machine to either 1) LAST_ACK (passive close) whereby when the last ACK is received tcp_connection_del is called. This notifies session of the delete and calls cleanup. 2) TIME_WAIT (active close) whereby after 2MSL the 2MSL timer triggers and cleanup is called.

N.B. Half-close connections are not supported

Definition at line 194 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tcp_connection_del ( tcp_connection_t tc)

Connection removal.

This should be called only once connection enters CLOSED state. Note that it notifies the session of the removal event, so if the goal is to just remove the connection, call tcp_connection_cleanup instead.

Definition at line 140 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void tcp_connection_fib_attach ( tcp_connection_t tc)
static

Stack tcp connection on peer's fib entry.

This ultimately populates the dpo the connection will use to send packets.

Definition at line 430 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tcp_connection_init_vars ( tcp_connection_t tc)

Initialize tcp connection variables.

Should be called after having received a msg from the peer, i.e., a SYN or a SYNACK, such that connection options have already been exchanged.

Definition at line 444 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int tcp_connection_open ( ip46_address_t *  rmt_addr,
u16  rmt_port,
u8  is_ip4 
)

Definition at line 454 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tcp_connection_reset ( tcp_connection_t tc)

Notify session that connection has been reset.

Switch state to closed and wait for session to call cleanup.

Definition at line 152 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void tcp_connection_select_lb_bucket ( tcp_connection_t tc,
const dpo_id_t dpo,
dpo_id_t result 
)
static

Definition at line 359 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int tcp_connection_stack_on_fib_entry ( tcp_connection_t tc)
static

Definition at line 407 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tcp_connection_timers_init ( tcp_connection_t tc)

Initialize all connection timers as invalid.

Definition at line 320 of file tcp.c.

+ Here is the caller graph for this function:

void tcp_connection_timers_reset ( tcp_connection_t tc)

Stop all connection timers.

Definition at line 337 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void tcp_connection_unbind ( u32  listener_index)
static

Definition at line 74 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void tcp_expired_timers_dispatch ( u32 expired_timers)
static

Definition at line 1004 of file tcp.c.

+ Here is the caller graph for this function:

transport_connection_t* tcp_half_open_session_get_transport ( u32  conn_index)

Definition at line 770 of file tcp.c.

+ Here is the call graph for this function:

clib_error_t* tcp_init ( vlib_main_t vm)

Definition at line 1115 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tcp_initialize_timer_wheels ( tcp_main_t tm)

Definition at line 1023 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

fib_node_index_t tcp_lookup_rmt_in_fib ( tcp_connection_t tc)

Definition at line 396 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

clib_error_t* tcp_main_enable ( vlib_main_t vm)

Definition at line 1037 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

i32 tcp_rcv_wnd_available ( tcp_connection_t tc)

Definition at line 876 of file tcp.c.

+ Here is the caller graph for this function:

static u32 tcp_round_snd_space ( tcp_connection_t tc,
u32  snd_space 
)
inlinestatic

Definition at line 797 of file tcp.c.

+ Here is the caller graph for this function:

u32 tcp_session_bind_ip4 ( u32  session_index,
ip46_address_t *  ip,
u16  port_host_byte_order 
)

Definition at line 60 of file tcp.c.

+ Here is the call graph for this function:

u32 tcp_session_bind_ip6 ( u32  session_index,
ip46_address_t *  ip,
u16  port_host_byte_order 
)

Definition at line 67 of file tcp.c.

+ Here is the call graph for this function:

void tcp_session_cleanup ( u32  conn_index,
u32  thread_index 
)

Definition at line 226 of file tcp.c.

+ Here is the call graph for this function:

void tcp_session_close ( u32  conn_index,
u32  thread_index 
)

Definition at line 218 of file tcp.c.

+ Here is the call graph for this function:

transport_connection_t* tcp_session_get_listener ( u32  listener_index)

Definition at line 90 of file tcp.c.

+ Here is the call graph for this function:

transport_connection_t* tcp_session_get_transport ( u32  conn_index,
u32  thread_index 
)

Definition at line 763 of file tcp.c.

+ Here is the call graph for this function:

int tcp_session_open_ip4 ( ip46_address_t *  addr,
u16  port 
)

Definition at line 534 of file tcp.c.

+ Here is the call graph for this function:

int tcp_session_open_ip6 ( ip46_address_t *  addr,
u16  port 
)

Definition at line 540 of file tcp.c.

+ Here is the call graph for this function:

u16 tcp_session_send_mss ( transport_connection_t trans_conn)

Compute maximum segment size for session layer.

Since the result needs to be the actual data length, it first computes the tcp options to be used in the next burst and subtracts their length from the connection's snd_mss.

Definition at line 784 of file tcp.c.

+ Here is the call graph for this function:

u32 tcp_session_send_space ( transport_connection_t trans_conn)

Definition at line 869 of file tcp.c.

+ Here is the call graph for this function:

u32 tcp_session_tx_fifo_offset ( transport_connection_t trans_conn)

Definition at line 882 of file tcp.c.

u32 tcp_session_unbind ( u32  listener_index)

Definition at line 83 of file tcp.c.

+ Here is the call graph for this function:

u32 tcp_snd_space ( tcp_connection_t tc)

Compute tx window session is allowed to fill.

Takes into account available send space, snd_mss and the congestion state of the connection. If possible, the value returned is a multiple of snd_mss.

Parameters
tctcp connection
Returns
number of bytes session is allowed to write

Definition at line 823 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tcp_timer_establish_handler ( u32  conn_index)

Definition at line 943 of file tcp.c.

+ Here is the call graph for this function:

void tcp_timer_keep_handler ( u32  conn_index)

Definition at line 931 of file tcp.c.

+ Here is the call graph for this function:

void tcp_timer_waitclose_handler ( u32  conn_index)

Definition at line 960 of file tcp.c.

+ Here is the call graph for this function:

clib_error_t* vnet_tcp_enable_disable ( vlib_main_t vm,
u8  is_en 
)

Definition at line 1097 of file tcp.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const transport_proto_vft_t tcp4_proto
static
Initial value:
= {
.unbind = tcp_session_unbind,
.push_header = tcp_push_header,
.get_connection = tcp_session_get_transport,
.get_listener = tcp_session_get_listener,
.cleanup = tcp_session_cleanup,
.send_mss = tcp_session_send_mss,
.send_space = tcp_session_send_space,
.tx_fifo_offset = tcp_session_tx_fifo_offset,
.format_connection = format_tcp_session,
.format_listener = format_tcp_listener_session,
.format_half_open = format_tcp_half_open_session,
}
u32 tcp_session_unbind(u32 listener_index)
Definition: tcp.c:83
transport_connection_t * tcp_half_open_session_get_transport(u32 conn_index)
Definition: tcp.c:770
u32 tcp_session_tx_fifo_offset(transport_connection_t *trans_conn)
Definition: tcp.c:882
u32 tcp_session_bind_ip4(u32 session_index, ip46_address_t *ip, u16 port_host_byte_order)
Definition: tcp.c:60
transport_connection_t * tcp_session_get_listener(u32 listener_index)
Definition: tcp.c:90
void tcp_session_cleanup(u32 conn_index, u32 thread_index)
Definition: tcp.c:226
u32 tcp_push_header(transport_connection_t *tconn, vlib_buffer_t *b)
Definition: tcp_output.c:1637
void tcp_session_close(u32 conn_index, u32 thread_index)
Definition: tcp.c:218
u8 * format_tcp_half_open_session(u8 *s, va_list *args)
Definition: tcp.c:709
u8 * format_tcp_session(u8 *s, va_list *args)
Definition: tcp.c:685
u16 tcp_session_send_mss(transport_connection_t *trans_conn)
Compute maximum segment size for session layer.
Definition: tcp.c:784
int tcp_session_open_ip4(ip46_address_t *addr, u16 port)
Definition: tcp.c:534
u32 tcp_session_send_space(transport_connection_t *trans_conn)
Definition: tcp.c:869
transport_connection_t * tcp_session_get_transport(u32 conn_index, u32 thread_index)
Definition: tcp.c:763
u8 * format_tcp_listener_session(u8 *s, va_list *args)
Definition: tcp.c:701

Definition at line 893 of file tcp.c.

const transport_proto_vft_t tcp6_proto
static
Initial value:
= {
.unbind = tcp_session_unbind,
.push_header = tcp_push_header,
.get_connection = tcp_session_get_transport,
.get_listener = tcp_session_get_listener,
.cleanup = tcp_session_cleanup,
.send_mss = tcp_session_send_mss,
.send_space = tcp_session_send_space,
.tx_fifo_offset = tcp_session_tx_fifo_offset,
.format_connection = format_tcp_session,
.format_listener = format_tcp_listener_session,
.format_half_open = format_tcp_half_open_session,
}
u32 tcp_session_unbind(u32 listener_index)
Definition: tcp.c:83
transport_connection_t * tcp_half_open_session_get_transport(u32 conn_index)
Definition: tcp.c:770
u32 tcp_session_tx_fifo_offset(transport_connection_t *trans_conn)
Definition: tcp.c:882
transport_connection_t * tcp_session_get_listener(u32 listener_index)
Definition: tcp.c:90
void tcp_session_cleanup(u32 conn_index, u32 thread_index)
Definition: tcp.c:226
u32 tcp_push_header(transport_connection_t *tconn, vlib_buffer_t *b)
Definition: tcp_output.c:1637
void tcp_session_close(u32 conn_index, u32 thread_index)
Definition: tcp.c:218
u8 * format_tcp_half_open_session(u8 *s, va_list *args)
Definition: tcp.c:709
u8 * format_tcp_session(u8 *s, va_list *args)
Definition: tcp.c:685
int tcp_session_open_ip6(ip46_address_t *addr, u16 port)
Definition: tcp.c:540
u16 tcp_session_send_mss(transport_connection_t *trans_conn)
Compute maximum segment size for session layer.
Definition: tcp.c:784
u32 tcp_session_send_space(transport_connection_t *trans_conn)
Definition: tcp.c:869
u32 tcp_session_bind_ip6(u32 session_index, ip46_address_t *ip, u16 port_host_byte_order)
Definition: tcp.c:67
transport_connection_t * tcp_session_get_transport(u32 conn_index, u32 thread_index)
Definition: tcp.c:763
u8 * format_tcp_listener_session(u8 *s, va_list *args)
Definition: tcp.c:701

Definition at line 911 of file tcp.c.

const char* tcp_conn_timers[]
Initial value:
= {
#define _(sym, str)
}
#define foreach_tcp_timer
TCP timers.
Definition: tcp.h:67

Definition at line 569 of file tcp.c.

const char* tcp_dbg_evt_str[]
Initial value:
= {
#define _(sym, str)
}

Definition at line 545 of file tcp.c.

const char* tcp_fsm_states[]
Initial value:
= {
#define _(sym, str)
}
#define foreach_tcp_fsm_state
TCP FSM state definitions as per RFC793.
Definition: tcp.h:41

Definition at line 551 of file tcp.c.

tcp_main_t tcp_main

Definition at line 22 of file tcp.c.

timer_expiration_handler* timer_expiration_handlers[TCP_N_TIMERS]
static
Initial value:
=
{
}
void tcp_timer_keep_handler(u32 conn_index)
Definition: tcp.c:931
timer_expiration_handler tcp_timer_retransmit_handler
void tcp_timer_establish_handler(u32 conn_index)
Definition: tcp.c:943
timer_expiration_handler tcp_timer_retransmit_syn_handler
timer_expiration_handler tcp_timer_persist_handler
void tcp_timer_waitclose_handler(u32 conn_index)
Definition: tcp.c:960
timer_expiration_handler tcp_timer_delack_handler

Definition at line 991 of file tcp.c.