25 #define tcp_error(n,s) s, 31 #define foreach_tcp_state_next \ 32 _ (DROP4, "ip4-drop") \ 33 _ (DROP6, "ip6-drop") \ 34 _ (TCP4_OUTPUT, "tcp4-output") \ 35 _ (TCP6_OUTPUT, "tcp6-output") 37 typedef enum _tcp_established_next
39 #define _(s,n) TCP_ESTABLISHED_NEXT_##s, 45 typedef enum _tcp_rcv_process_next
47 #define _(s,n) TCP_RCV_PROCESS_NEXT_##s, 53 typedef enum _tcp_syn_sent_next
55 #define _(s,n) TCP_SYN_SENT_NEXT_##s, 61 typedef enum _tcp_listen_next
63 #define _(s,n) TCP_LISTEN_NEXT_##s, 70 typedef enum _tcp_state_next
72 #define _(s,n) TCP_NEXT_##s, 78 #define tcp_next_output(is_ip4) (is_ip4 ? TCP_NEXT_TCP4_OUTPUT \ 79 : TCP_NEXT_TCP6_OUTPUT) 81 #define tcp_next_drop(is_ip4) (is_ip4 ? TCP_NEXT_DROP4 \ 114 return (
seq_geq (end_seq, tc->rcv_las)
115 &&
seq_leq (seq, tc->rcv_nxt + tc->rcv_wnd));
148 &&
seq_leq (tc->rcv_las, seq_end))
151 tc->tsval_recent = tc->rcv_opts.tsval;
159 switch (tc->rst_state)
161 case TCP_STATE_SYN_RCVD:
166 case TCP_STATE_SYN_SENT:
170 case TCP_STATE_ESTABLISHED:
174 case TCP_STATE_CLOSE_WAIT:
175 case TCP_STATE_FIN_WAIT_1:
176 case TCP_STATE_FIN_WAIT_2:
177 case TCP_STATE_CLOSING:
178 case TCP_STATE_LAST_ACK:
181 case TCP_STATE_CLOSED:
182 case TCP_STATE_TIME_WAIT:
185 TCP_DBG (
"reset state: %u", tc->state);
194 tc->rst_state = tc->state;
209 TCP_EVT (TCP_EVT_RST_RCVD, tc);
212 case TCP_STATE_SYN_RCVD:
216 case TCP_STATE_SYN_SENT:
218 tc->rst_state = tc->state;
221 case TCP_STATE_ESTABLISHED:
228 case TCP_STATE_CLOSE_WAIT:
229 case TCP_STATE_FIN_WAIT_1:
230 case TCP_STATE_FIN_WAIT_2:
231 case TCP_STATE_CLOSING:
232 case TCP_STATE_LAST_ACK:
241 case TCP_STATE_CLOSED:
242 case TCP_STATE_TIME_WAIT:
245 TCP_DBG (
"reset state: %u", tc->state);
266 *error0 = TCP_ERROR_CONNECTION_CLOSED;
272 *error0 = TCP_ERROR_SEGMENT_INVALID;
278 *error0 = TCP_ERROR_OPTIONS;
284 *error0 = TCP_ERROR_PAWS;
293 tc0->tsval_recent = tc0->rcv_opts.tsval;
314 &&
vnet_buffer (b0)->tcp.seq_number == tc0->rcv_nxt - 1)
317 if (tc0->state == TCP_STATE_SYN_RCVD)
320 TCP_EVT (TCP_EVT_SYN_RCVD, tc0, 0);
321 *error0 = TCP_ERROR_SYNS_RCVD;
326 TCP_EVT (TCP_EVT_SYNACK_RCVD, tc0);
327 *error0 = TCP_ERROR_SYN_ACKS_RCVD;
334 if (tc0->rcv_wnd < tc0->snd_mss
335 && tc0->rcv_nxt ==
vnet_buffer (b0)->tcp.seq_number)
343 tc0->rcv_las - tc0->rcv_wnd)
345 tc0->rcv_nxt + tc0->rcv_wnd))
348 *error0 = TCP_ERROR_RCV_WND;
352 if ((tc0->flags & TCP_CONN_ZERO_RWND_SENT)
354 tc0->rcv_las + tc0->rcv_opts.mss))
355 *error0 = TCP_ERROR_ZERO_RWND;
376 *error0 = TCP_ERROR_RST_RCVD;
387 *error0 = TCP_ERROR_SPURIOUS_SYN;
413 *error = TCP_ERROR_ACK_INVALID;
418 tc->bytes_acked =
vnet_buffer (b)->tcp.ack_number - tc->snd_una;
420 *error = TCP_ERROR_ACK_OK;
443 err = mrtt - tc->srtt;
444 tc->srtt =
clib_max ((
int) tc->srtt + (err >> 3), 1);
445 diff = (
clib_abs (err) - (int) tc->rttvar) >> 2;
446 tc->rttvar =
clib_max ((
int) tc->rttvar + diff, 1);
452 tc->mrtt_us = tc->mrtt_us + (mrtt - tc->mrtt_us) * 0.125;
482 if (!(tc->cfg_flags & TCP_CFG_F_RATE_SAMPLE)
491 if (tc->rtt_ts &&
seq_geq (ack, tc->rtt_seq))
535 tc->mrtt_us =
clib_max (tc->mrtt_us, 0.0001);
544 if (tc->rto_boff && mrtt > 1 *
THZ)
553 tc->rttvar = mrtt >> 1;
565 u32 *pending_deq_acked;
573 for (i = 0; i <
vec_len (pending_deq_acked); i++)
576 tc->flags &= ~TCP_CONN_DEQ_PENDING;
603 if (!(tc->flags & TCP_CONN_DEQ_PENDING))
606 tc->flags |= TCP_CONN_DEQ_PENDING;
608 tc->burst_acked += tc->bytes_acked;
622 if (
seq_lt (tc->snd_wl1, seq)
623 || (tc->snd_wl1 == seq &&
seq_leq (tc->snd_wl2, ack)))
625 tc->snd_wnd = snd_wnd;
670 tc->snd_congestion = tc->snd_nxt;
671 tc->cwnd_acc_bytes = 0;
672 tc->snd_rxt_bytes = 0;
673 tc->rxt_delivered = 0;
674 tc->prr_delivered = 0;
675 tc->prr_start = tc->snd_una;
676 tc->prev_ssthresh = tc->ssthresh;
677 tc->prev_cwnd = tc->cwnd;
688 tc->fr_occurences += 1;
689 TCP_EVT (TCP_EVT_CC_EVT, tc, 4);
695 tc->cwnd = tc->prev_cwnd;
696 tc->ssthresh = tc->prev_ssthresh;
698 ASSERT (tc->rto_boff == 0);
699 TCP_EVT (TCP_EVT_CC_EVT, tc, 5);
732 if (
seq_leq (tc->snd_una, tc->snd_congestion)
733 && ((!(tc->cwnd > tc->snd_mss
734 && tc->bytes_acked <= 4 * tc->snd_mss))
735 || (tc->rcv_opts.tsecr != tc->tsecr_last_ack)))
741 return tc->sack_sb.lost_bytes || tc->rcv_dupacks >= tc->sack_sb.reorder;
763 if (tc->sack_sb.sacked_bytes)
765 tc->snd_congestion = tc->snd_nxt;
770 tc->rxt_delivered = 0;
771 tc->snd_rxt_bytes = 0;
773 tc->prr_delivered = 0;
775 tc->flags &= ~TCP_CONN_RXT_PENDING;
778 if (hole && hole->start == tc->snd_una && hole->end == tc->snd_nxt)
787 TCP_EVT (TCP_EVT_CC_EVT, tc, 3);
789 ASSERT (tc->rto_boff == 0);
812 (
seq_leq (tc->snd_congestion, tc->snd_una - tc->bytes_acked)
813 &&
seq_gt (tc->snd_congestion, tc->snd_una)))
814 tc->snd_congestion = tc->snd_una - 1;
838 TCP_EVT (TCP_EVT_DUPACK_RCVD, tc, 1);
865 if (!tc->bytes_acked && tc->sack_sb.rxt_sacked)
868 tc->rxt_delivered += tc->sack_sb.rxt_sacked;
869 tc->prr_delivered += tc->bytes_acked + tc->sack_sb.last_sacked_bytes
870 - tc->sack_sb.last_bytes_delivered;
876 tc->rcv_dupacks += 1;
877 TCP_EVT (TCP_EVT_DUPACK_RCVD, tc, 1);
879 tc->rxt_delivered =
clib_min (tc->rxt_delivered + tc->bytes_acked,
882 tc->prr_delivered +=
clib_min (tc->snd_mss,
883 tc->snd_nxt - tc->snd_una);
885 tc->prr_delivered += tc->bytes_acked -
clib_min (tc->bytes_acked,
897 if (
seq_geq (tc->snd_una, tc->snd_congestion))
902 tc->tsecr_last_ack = tc->rcv_opts.tsecr;
917 if (!tc->bytes_acked)
944 if (tc->cfg_flags & TCP_CFG_F_RATE_SAMPLE)
957 return ((
vnet_buffer (b)->tcp.ack_number == prev_snd_una)
958 &&
seq_gt (tc->snd_nxt, tc->snd_una)
960 && (prev_snd_wnd == tc->snd_wnd));
968 u32 prev_snd_wnd,
u32 prev_snd_una,
u8 * is_dack)
972 *is_dack = tc->sack_sb.last_sacked_bytes
985 u32 prev_snd_wnd, prev_snd_una;
1003 tc->errors.above_ack_wnd += 1;
1004 *error = TCP_ERROR_ACK_FUTURE;
1012 tc->errors.below_ack_wnd += 1;
1013 *error = TCP_ERROR_ACK_OLD;
1034 prev_snd_wnd = tc->snd_wnd;
1035 prev_snd_una = tc->snd_una;
1038 clib_net_to_host_u16 (th->window) << tc->snd_wscale);
1039 tc->bytes_acked =
vnet_buffer (b)->tcp.ack_number - tc->snd_una;
1043 if (tc->cfg_flags & TCP_CFG_F_RATE_SAMPLE)
1046 if (tc->bytes_acked + tc->sack_sb.last_sacked_bytes)
1049 if (tc->bytes_acked)
1053 TCP_EVT (TCP_EVT_ACK_RCVD, tc);
1062 tc->dupacks_in += is_dack;
1065 *error = TCP_ERROR_ACK_OK;
1068 *error = TCP_ERROR_ACK_DUP;
1078 *error = TCP_ERROR_ACK_OK;
1095 u32 thread_index, *pending_disconnects, *pending_resets;
1103 for (i = 0; i <
vec_len (pending_disconnects); i++)
1116 for (i = 0; i <
vec_len (pending_resets); i++)
1136 tc->flags |= TCP_CONN_FINRCVD;
1144 TCP_EVT (TCP_EVT_FIN_RCVD, tc);
1145 *error = TCP_ERROR_FIN_RCVD;
1153 int written,
error = TCP_ERROR_ENQUEUED;
1159 tc->bytes_in += written;
1161 TCP_EVT (TCP_EVT_INPUT, tc, 0, data_len, written);
1166 tc->rcv_nxt += written;
1169 else if (written > data_len)
1171 tc->rcv_nxt += written;
1172 TCP_EVT (TCP_EVT_CC_INPUT, tc, data_len, written);
1174 else if (written > 0)
1177 tc->rcv_nxt += written;
1178 error = TCP_ERROR_PARTIALLY_ENQUEUED;
1183 if (tc->rcv_wnd < tc->snd_mss)
1184 return TCP_ERROR_ZERO_RWND;
1186 return TCP_ERROR_FIFO_FULL;
1219 TCP_EVT (TCP_EVT_INPUT, tc, 1, data_len, 0);
1220 return TCP_ERROR_FIFO_FULL;
1223 TCP_EVT (TCP_EVT_INPUT, tc, 1, data_len, data_len);
1232 s0 =
session_get (tc->c_s_index, tc->c_thread_index);
1240 start = tc->rcv_nxt +
offset;
1244 TCP_EVT (TCP_EVT_CC_SACKS, tc);
1248 return TCP_ERROR_ENQUEUED_OOO;
1260 if (!(b->
flags & VLIB_BUFFER_NEXT_PRESENT))
1267 n_bytes_to_drop -= discard;
1269 while (n_bytes_to_drop);
1270 if (n_bytes_to_drop > first)
1288 u32 error, n_bytes_to_drop, n_data_bytes;
1293 tc->data_segs_in += 1;
1311 tc->errors.below_data_wnd++;
1312 error = TCP_ERROR_SEGMENT_OLD;
1318 n_bytes_to_drop = tc->rcv_nxt -
vnet_buffer (b)->tcp.seq_number;
1319 n_data_bytes -= n_bytes_to_drop;
1323 error = TCP_ERROR_SEGMENT_OLD;
1334 tc->rcv_las + tc->rcv_wnd);
1378 s =
format (s,
"%d -> %d (%U)",
1379 clib_net_to_host_u16 (t->
tcp_header.dst_port),
1422 if (b0->
flags & VLIB_BUFFER_IS_TRACED)
1446 #define tcp_maybe_inc_counter(node_id, err, count) \ 1448 if (next0 != tcp_next_drop (is_ip4)) \ 1449 tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index, \ 1450 tcp6_##node_id##_node.index, is_ip4, err, \ 1453 #define tcp_inc_counter(node_id, err, count) \ 1454 tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index, \ 1455 tcp6_##node_id##_node.index, is_ip4, \ 1457 #define tcp_maybe_inc_err_counter(cnts, err) \ 1459 cnts[err] += (next0 != tcp_next_drop (is_ip4)); \ 1461 #define tcp_inc_err_counter(cnts, err, val) \ 1465 #define tcp_store_err_counters(node_id, cnts) \ 1468 for (i = 0; i < TCP_N_ERROR; i++) \ 1470 tcp_inc_counter(node_id, i, cnts[i]); \ 1480 u32 n_left_from, *from, *first_buffer;
1489 while (n_left_from > 0)
1491 u32 bi0, error0 = TCP_ERROR_ACK_OK;
1496 if (n_left_from > 1)
1514 error0 = TCP_ERROR_INVALID_CONNECTION;
1549 err_counters[TCP_ERROR_MSG_QUEUE_FULL] = errors;
1575 .name =
"tcp4-established",
1577 .vector_size =
sizeof (
u32),
1583 #define _(s,n) [TCP_ESTABLISHED_NEXT_##s] = n, 1594 .name =
"tcp6-established",
1596 .vector_size =
sizeof (
u32),
1602 #define _(s,n) [TCP_ESTABLISHED_NEXT_##s] = n, 1622 if (tc->c_lcl_port == 0 && tc->state == TCP_STATE_LISTEN)
1625 u8 is_ip_valid = 0, val_l, val_r;
1627 if (tc->connection.is_ip4)
1632 &tc->connection.lcl_ip.ip4);
1633 val_l = val_l ||
ip_is_zero (&tc->connection.lcl_ip, 1);
1635 &tc->connection.rmt_ip.ip4);
1636 val_r = val_r || tc->state == TCP_STATE_LISTEN;
1637 is_ip_valid = val_l && val_r;
1644 &tc->connection.lcl_ip.ip6);
1645 val_l = val_l ||
ip_is_zero (&tc->connection.lcl_ip, 0);
1647 &tc->connection.rmt_ip.ip6);
1648 val_r = val_r || tc->state == TCP_STATE_LISTEN;
1649 is_ip_valid = val_l && val_r;
1652 u8 is_valid = (tc->c_lcl_port == hdr->dst_port
1653 && (tc->state == TCP_STATE_LISTEN
1654 || tc->c_rmt_port == hdr->src_port) && is_ip_valid);
1660 tc->c_proto, tc->c_is_ip4);
1664 if (tmp->lcl_port == hdr->dst_port
1665 && tmp->rmt_port == hdr->src_port)
1667 TCP_DBG (
"half-open is valid!");
1696 TRANSPORT_PROTO_TCP,
1697 thread_index, &is_filtered);
1711 TRANSPORT_PROTO_TCP,
1712 thread_index, &is_filtered);
1730 tcp->dst_port, TRANSPORT_PROTO_TCP, 1);
1738 tcp->dst_port, TRANSPORT_PROTO_TCP, 1);
1743 (TRANSPORT_PROTO_TCP,
1756 u32 sw_if_idx, lb_idx;
1765 ip6_address_t *
dst_addr = &(tc->c_rmt_ip.ip6);
1780 tc->cfg_flags |= TCP_CFG_F_TSO;
1787 u32 n_left_from, *from, *first_buffer, errors = 0;
1794 while (n_left_from > 0)
1796 u32 bi0, ack0, seq0, error0 = TCP_ERROR_NONE;
1811 error0 = TCP_ERROR_INVALID_CONNECTION;
1821 my_thread_index, is_ip4));
1822 error0 = TCP_ERROR_SPURIOUS_SYN_ACK;
1833 || tcp0->src_port != tc0->c_rmt_port))
1835 error0 = TCP_ERROR_INVALID_CONNECTION;
1842 error0 = TCP_ERROR_SEGMENT_INVALID;
1863 if (
seq_leq (ack0, tc0->iss) ||
seq_gt (ack0, tc0->snd_nxt))
1867 error0 = TCP_ERROR_RCV_WND;
1872 if (
seq_gt (tc0->snd_una, ack0))
1874 error0 = TCP_ERROR_ACK_INVALID;
1889 error0 = TCP_ERROR_RST_RCVD;
1904 error0 = TCP_ERROR_SEGMENT_INVALID;
1911 error0 = TCP_ERROR_OPTIONS;
1919 new_tc0->irs = seq0;
1925 new_tc0->tsval_recent = new_tc0->rcv_opts.tsval;
1930 new_tc0->snd_wscale = new_tc0->rcv_opts.wscale;
1932 new_tc0->rcv_wscale = 0;
1934 new_tc0->snd_wnd = clib_net_to_host_u16 (tcp0->window)
1935 << new_tc0->snd_wscale;
1936 new_tc0->snd_wl1 = seq0;
1937 new_tc0->snd_wl2 = ack0;
1947 new_tc0->snd_una = ack0;
1948 new_tc0->state = TCP_STATE_ESTABLISHED;
1951 new_tc0->rcv_las = new_tc0->rcv_nxt;
1960 error0 = TCP_ERROR_CREATE_SESSION_FAIL;
1965 new_tc0->tx_fifo_size =
1969 TCP_EVT (TCP_EVT_SYNACK_RCVD, new_tc0);
1970 error0 = TCP_ERROR_SYN_ACKS_RCVD;
1975 new_tc0->state = TCP_STATE_SYN_RCVD;
1983 TCP_EVT (TCP_EVT_RST_SENT, tc0);
1984 error0 = TCP_ERROR_CREATE_SESSION_FAIL;
1989 new_tc0->tx_fifo_size =
1991 new_tc0->rtt_ts = 0;
1994 error0 = TCP_ERROR_SYNS_RCVD;
1998 if (!(new_tc0->cfg_flags & TCP_CFG_F_NO_TSO))
2006 if (error0 == TCP_ERROR_ACK_OK)
2007 error0 = TCP_ERROR_SYN_ACKS_RCVD;
2021 tc0->flags |= TCP_CONN_HALF_OPEN_DONE;
2061 .name =
"tcp4-syn-sent",
2063 .vector_size =
sizeof (
u32),
2069 #define _(s,n) [TCP_SYN_SENT_NEXT_##s] = n, 2080 .name =
"tcp6-syn-sent",
2082 .vector_size =
sizeof (
u32),
2088 #define _(s,n) [TCP_SYN_SENT_NEXT_##s] = n, 2106 u32 n_left_from, *from, max_dequeue;
2111 while (n_left_from > 0)
2113 u32 bi0, error0 = TCP_ERROR_NONE;
2128 error0 = TCP_ERROR_INVALID_CONNECTION;
2142 if (tmp->state != tc0->state)
2144 if (tc0->state != TCP_STATE_CLOSED)
2156 error0 = TCP_ERROR_CONNECTION_CLOSED;
2171 case TCP_STATE_SYN_RCVD:
2174 if (tc0->rcv_nxt !=
vnet_buffer (b0)->tcp.seq_number || is_fin0)
2177 error0 = TCP_ERROR_SEGMENT_INVALID;
2190 error0 = TCP_ERROR_SEGMENT_INVALID;
2199 tc0->state = TCP_STATE_ESTABLISHED;
2200 TCP_EVT (TCP_EVT_STATE_CHANGE, tc0);
2202 if (!(tc0->cfg_flags & TCP_CFG_F_NO_TSO))
2207 tc0->snd_wnd = clib_net_to_host_u16 (tcp0->window)
2208 << tc0->rcv_opts.wscale;
2216 error0 = TCP_ERROR_MSG_QUEUE_FULL;
2222 error0 = TCP_ERROR_ACK_OK;
2224 case TCP_STATE_ESTABLISHED:
2231 case TCP_STATE_FIN_WAIT_1:
2239 if (tc0->flags & TCP_CONN_FINPNDG)
2243 if (max_dequeue <= tc0->burst_acked)
2246 else if ((tc0->flags & TCP_CONN_FINRCVD) && tc0->bytes_acked)
2251 else if (tc0->snd_una == tc0->snd_nxt)
2259 if (tc0->flags & TCP_CONN_FINRCVD)
2274 if (tc0->burst_acked > 1)
2276 tc0->burst_acked - 1);
2277 tc0->burst_acked = 0;
2280 case TCP_STATE_FIN_WAIT_2:
2286 tc0->burst_acked = 0;
2288 case TCP_STATE_CLOSE_WAIT:
2293 if (!(tc0->flags & TCP_CONN_FINPNDG))
2298 if (max_dequeue > tc0->burst_acked)
2307 case TCP_STATE_CLOSING:
2314 if (tc0->snd_una != tc0->snd_nxt)
2325 case TCP_STATE_LAST_ACK:
2334 if (is_fin0 && tc0->snd_una != tc0->snd_nxt)
2352 case TCP_STATE_TIME_WAIT:
2378 case TCP_STATE_ESTABLISHED:
2379 case TCP_STATE_FIN_WAIT_1:
2380 case TCP_STATE_FIN_WAIT_2:
2384 if (
vnet_buffer (b0)->tcp.seq_end != tc0->rcv_nxt)
2387 case TCP_STATE_CLOSE_WAIT:
2388 case TCP_STATE_CLOSING:
2389 case TCP_STATE_LAST_ACK:
2390 case TCP_STATE_TIME_WAIT:
2400 TCP_EVT (TCP_EVT_FIN_RCVD, tc0);
2404 case TCP_STATE_ESTABLISHED:
2413 case TCP_STATE_SYN_RCVD:
2424 case TCP_STATE_CLOSE_WAIT:
2425 case TCP_STATE_CLOSING:
2426 case TCP_STATE_LAST_ACK:
2429 case TCP_STATE_FIN_WAIT_1:
2432 if (tc0->flags & TCP_CONN_FINPNDG)
2437 tc0->flags |= TCP_CONN_FINRCVD;
2450 case TCP_STATE_FIN_WAIT_2:
2460 case TCP_STATE_TIME_WAIT:
2468 error0 = TCP_ERROR_FIN_RCVD;
2507 .name =
"tcp4-rcv-process",
2509 .vector_size =
sizeof (
u32),
2515 #define _(s,n) [TCP_RCV_PROCESS_NEXT_##s] = n, 2526 .name =
"tcp6-rcv-process",
2528 .vector_size =
sizeof (
u32),
2534 #define _(s,n) [TCP_RCV_PROCESS_NEXT_##s] = n, 2549 u32 n_left_from, *from, n_syns = 0, *first_buffer;
2555 while (n_left_from > 0)
2573 if (tc->state != TCP_STATE_TIME_WAIT)
2575 error = TCP_ERROR_CREATE_EXISTS;
2584 error = TCP_ERROR_NO_LISTENER;
2594 error = TCP_ERROR_CREATE_EXISTS;
2620 error = TCP_ERROR_OPTIONS;
2627 child->state = TCP_STATE_SYN_RCVD;
2628 child->c_fib_index = lc->c_fib_index;
2629 child->cc_algo = lc->cc_algo;
2638 TCP_EVT (TCP_EVT_SYN_RCVD, child, 1);
2641 lc->c_thread_index, 0 ))
2644 error = TCP_ERROR_CREATE_SESSION_FAIL;
2661 n_syns += (error == TCP_ERROR_NONE);
2685 .name =
"tcp4-listen",
2687 .vector_size =
sizeof (
u32),
2693 #define _(s,n) [TCP_LISTEN_NEXT_##s] = n, 2704 .name =
"tcp6-listen",
2706 .vector_size =
sizeof (
u32),
2712 #define _(s,n) [TCP_LISTEN_NEXT_##s] = n, 2720 typedef enum _tcp_input_next
2732 #define foreach_tcp4_input_next \ 2733 _ (DROP, "ip4-drop") \ 2734 _ (LISTEN, "tcp4-listen") \ 2735 _ (RCV_PROCESS, "tcp4-rcv-process") \ 2736 _ (SYN_SENT, "tcp4-syn-sent") \ 2737 _ (ESTABLISHED, "tcp4-established") \ 2738 _ (RESET, "tcp4-reset") \ 2739 _ (PUNT, "ip4-punt") 2741 #define foreach_tcp6_input_next \ 2742 _ (DROP, "ip6-drop") \ 2743 _ (LISTEN, "tcp6-listen") \ 2744 _ (RCV_PROCESS, "tcp6-rcv-process") \ 2745 _ (SYN_SENT, "tcp6-syn-sent") \ 2746 _ (ESTABLISHED, "tcp6-established") \ 2747 _ (RESET, "tcp6-reset") \ 2748 _ (PUNT, "ip6-punt") 2750 #define filter_flags (TCP_FLAG_SYN|TCP_FLAG_ACK|TCP_FLAG_RST|TCP_FLAG_FIN) 2761 for (i = 0; i < n_bufs; i++)
2763 if (bs[i]->
flags & VLIB_BUFFER_IS_TRACED)
2777 if (*error == TCP_ERROR_FILTERED || *error == TCP_ERROR_WRONG_THREAD)
2781 else if ((is_ip4 && tm->punt_unknown4) || (!is_ip4 && tm->punt_unknown6))
2784 *error = TCP_ERROR_PUNT;
2789 *error = TCP_ERROR_NO_LISTENER;
2804 *next = tm->dispatch_table[tc->state][
flags].next;
2805 error = tm->dispatch_table[tc->state][
flags].error;
2811 if (error == TCP_ERROR_DISPATCH)
2812 clib_warning (
"tcp conn %u disp error state %U flags %U",
2836 while (n_left_from >= 4)
2838 u32 error0 = TCP_ERROR_NO_LISTENER, error1 = TCP_ERROR_NO_LISTENER;
2861 vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index;
2862 vnet_buffer (b[1])->tcp.connection_index = tc1->c_c_index;
2872 vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index;
2884 vnet_buffer (b[1])->tcp.connection_index = tc1->c_c_index;
2898 while (n_left_from > 0)
2901 u32 error0 = TCP_ERROR_NO_LISTENER;
2903 if (n_left_from > 1)
2915 vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index;
2955 .name =
"tcp4-input-nolookup",
2957 .vector_size =
sizeof (
u32),
2963 #define _(s,n) [TCP_INPUT_NEXT_##s] = n, 2975 .name =
"tcp6-input-nolookup",
2977 .vector_size =
sizeof (
u32),
2983 #define _(s,n) [TCP_INPUT_NEXT_##s] = n, 3009 .name =
"tcp4-input",
3011 .vector_size =
sizeof (
u32),
3017 #define _(s,n) [TCP_INPUT_NEXT_##s] = n, 3029 .name =
"tcp6-input",
3031 .vector_size =
sizeof (
u32),
3037 #define _(s,n) [TCP_INPUT_NEXT_##s] = n, 3046 #ifndef CLIB_MARCH_VARIANT 3051 for (i = 0; i <
ARRAY_LEN (tm->dispatch_table); i++)
3052 for (j = 0; j <
ARRAY_LEN (tm->dispatch_table[i]); j++)
3055 tm->dispatch_table[
i][j].error = TCP_ERROR_DISPATCH;
3058 #define _(t,f,n,e) \ 3060 tm->dispatch_table[TCP_STATE_##t][f].next = (n); \ 3061 tm->dispatch_table[TCP_STATE_##t][f].error = (e); \ 3070 TCP_ERROR_ACK_INVALID);
3072 TCP_ERROR_SEGMENT_INVALID);
3074 TCP_ERROR_SEGMENT_INVALID);
3076 TCP_ERROR_INVALID_CONNECTION);
3079 TCP_ERROR_SEGMENT_INVALID);
3081 TCP_ERROR_SEGMENT_INVALID);
3083 TCP_ERROR_SEGMENT_INVALID);
3085 TCP_ERROR_SEGMENT_INVALID);
3087 TCP_ERROR_SEGMENT_INVALID);
3089 TCP_ERROR_SEGMENT_INVALID);
3271 TCP_ERROR_CONNECTION_CLOSED);
3275 TCP_ERROR_CONNECTION_CLOSED);
u16 lb_n_buckets
number of buckets in the load-balance.
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
u32 connection_index
Index of the transport connection associated to the session.
void tcp_program_retransmit(tcp_connection_t *tc)
#define TCP_TIMER_HANDLE_INVALID
u32 * pending_disconnects
vector of pending disconnect notifications
static u32 ip6_fib_table_fwding_lookup(u32 fib_index, const ip6_address_t *dst)
static void tcp_persist_timer_set(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
static u32 tcp_time_now(void)
vl_api_wireguard_peer_flags_t flags
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
static tcp_connection_t * tcp_connection_get(u32 conn_index, u32 thread_index)
transport_connection_t * session_lookup_connection_wt6(u32 fib_index, ip6_address_t *lcl, ip6_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto, u32 thread_index, u8 *result)
Lookup connection with ip6 and transport layer information.
vnet_main_t * vnet_get_main(void)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define THZ
TCP tick frequency.
#define tcp_opts_tstamp(_to)
#define clib_memcpy_fast(a, b, c)
void session_transport_delete_notify(transport_connection_t *tc)
Notification from transport that connection is being deleted.
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
#define tcp_fastrecovery_first_off(tc)
struct _tcp_main tcp_main_t
void tcp_connection_timers_reset(tcp_connection_t *tc)
Stop all connection timers.
u16 current_length
Nbytes between current data and the end of this buffer.
int session_main_flush_enqueue_events(u8 transport_proto, u32 thread_index)
Flushes queue of sessions that are to be notified of new data enqueued events.
struct _tcp_connection tcp_connection_t
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static u32 tcp_set_time_now(tcp_worker_ctx_t *wrk)
void session_transport_reset_notify(transport_connection_t *tc)
Notify application that connection has been reset.
u32 dpo_get_urpf(const dpo_id_t *dpo)
Get a uRPF interface for the DPO.
u32 * pending_resets
vector of pending reset notifications
#define tcp_disconnect_pending_on(tc)
static void tcp_cc_congestion(tcp_connection_t *tc)
static u32 tcp_time_now_w_thread(u32 thread_index)
#define timestamp_lt(_t1, _t2)
static session_t * session_get(u32 si, u32 thread_index)
#define TCP_TICK
TCP tick period (s)
#define tcp_disconnect_pending_off(tc)
tcp_connection_t tcp_connection
#define VLIB_NODE_FN(node)
int session_enqueue_stream_connection(transport_connection_t *tc, vlib_buffer_t *b, u32 offset, u8 queue_event, u8 is_in_order)
u64 session_lookup_half_open_handle(transport_connection_t *tc)
vlib_error_t * errors
Vector of errors for this node.
format_function_t format_tcp_flags
static u8 tcp_is_descheduled(tcp_connection_t *tc)
struct _tcp_header tcp_header_t
int tcp_half_open_connection_cleanup(tcp_connection_t *tc)
Try to cleanup half-open connection.
#define tcp_in_cong_recovery(tc)
u32 * pending_deq_acked
vector of pending ack dequeues
void session_transport_closing_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
#define timestamp_leq(_t1, _t2)
void tcp_init_snd_vars(tcp_connection_t *tc)
Initialize connection send variables.
static void tcp_persist_timer_reset(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
#define VLIB_INIT_FUNCTION(x)
static int tcp_options_parse(tcp_header_t *th, tcp_options_t *to, u8 is_syn)
Parse TCP header options.
void tcp_bt_sample_delivery_rate(tcp_connection_t *tc, tcp_rate_sample_t *rs)
Generate a delivery rate sample from recently acked bytes.
#define seq_leq(_s1, _s2)
transport_connection_t * session_lookup_connection_wt4(u32 fib_index, ip4_address_t *lcl, ip4_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto, u32 thread_index, u8 *result)
Lookup connection with ip4 and transport layer information.
description fragment has unexpected format
vnet_hw_interface_flags_t flags
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
void transport_fifos_init_ooo(transport_connection_t *tc)
#define tcp_fastrecovery_off(tc)
static u32 ooo_segment_length(svm_fifo_t *f, ooo_segment_t *s)
static void * ip4_next_header(ip4_header_t *i)
static sack_scoreboard_hole_t * scoreboard_first_hole(sack_scoreboard_t *sb)
static tcp_header_t * tcp_buffer_hdr(vlib_buffer_t *b)
#define vlib_call_init_function(vm, x)
#define tcp_validate_txf_size(_tc, _a)
#define tcp_fastrecovery_on(tc)
static void tcp_retransmit_timer_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
static void tcp_timer_set(tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id, u32 interval)
static void tcp_cc_recovered(tcp_connection_t *tc)
static void svm_fifo_newest_ooo_segment_reset(svm_fifo_t *f)
static heap_elt_t * first(heap_header_t *h)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void tcp_retransmit_timer_reset(tcp_timer_wheel_t *tw, tcp_connection_t *tc)
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
void tcp_update_sack_list(tcp_connection_t *tc, u32 start, u32 end)
Build SACK list as per RFC2018.
vlib_main_t * vm
convenience pointer to this thread's vlib main
static tcp_connection_t * tcp_half_open_connection_get(u32 conn_index)
void tcp_send_ack(tcp_connection_t *tc)
void tcp_connection_tx_pacer_reset(tcp_connection_t *tc, u32 window, u32 start_bucket)
tcp_connection_t * tcp_connection_alloc_w_base(u8 thread_index, tcp_connection_t *base)
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
format_function_t format_tcp_connection_id
#define TCP_DUPACK_THRESHOLD
tcp_connection_t * tcp_connection_alloc(u8 thread_index)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
void tcp_connection_tx_pacer_update(tcp_connection_t *tc)
#define TCP_PAWS_IDLE
24 days
tcp_timer_wheel_t timer_wheel
worker timer wheel
int ip6_address_compare(ip6_address_t *a1, ip6_address_t *a2)
static u8 tcp_is_lost_fin(tcp_connection_t *tc)
static ooo_segment_t * svm_fifo_newest_ooo_segment(svm_fifo_t *f)
static void tcp_cc_rcv_ack(tcp_connection_t *tc, tcp_rate_sample_t *rs)
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
#define TCP_DBG(_fmt, _args...)
#define tcp_recovery_off(tc)
void tcp_program_cleanup(tcp_worker_ctx_t *wrk, tcp_connection_t *tc)
void tcp_connection_free(tcp_connection_t *tc)
vl_api_mac_address_t dst_addr
#define VLIB_REGISTER_NODE(x,...)
#define CLIB_PREFETCH(addr, size, type)
int ip4_address_compare(ip4_address_t *a1, ip4_address_t *a2)
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
#define tcp_disconnect_pending(tc)
void tcp_program_dupack(tcp_connection_t *tc)
sll srl srl sll sra u16x4 i
void tcp_send_reset(tcp_connection_t *tc)
Build and set reset packet for connection.
format_function_t format_tcp_state
static void tcp_update_rto(tcp_connection_t *tc)
#define clib_warning(format, args...)
#define tcp_in_recovery(tc)
Don't register connection in lookup.
struct _transport_connection transport_connection_t
f64 rtt_time
RTT for sample.
static void tcp_cc_undo_recovery(tcp_connection_t *tc)
static void * ip6_next_header(ip6_header_t *i)
vlib_main_t vlib_node_runtime_t * node
static u32 transport_max_tx_dequeue(transport_connection_t *tc)
void tcp_send_synack(tcp_connection_t *tc)
#define seq_geq(_s1, _s2)
static load_balance_t * load_balance_get(index_t lbi)
static void tcp_cong_recovery_off(tcp_connection_t *tc)
static index_t ip4_fib_forwarding_lookup(u32 fib_index, const ip4_address_t *addr)
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
#define tcp_fastrecovery_first_on(tc)
int session_stream_accept_notify(transport_connection_t *tc)
struct _sack_scoreboard_hole sack_scoreboard_hole_t
static vlib_main_t * vlib_get_main(void)
static clib_error_t * tcp_init(vlib_main_t *vm)
u8 ip_is_zero(ip46_address_t *ip46_address, u8 is_ip4)
u8 tcp_scoreboard_is_sane_post_recovery(tcp_connection_t *tc)
Test that scoreboard is sane after recovery.
#define tcp_opts_wscale(_to)
void tcp_send_reset_w_pkt(tcp_connection_t *tc, vlib_buffer_t *pkt, u32 thread_index, u8 is_ip4)
Send reset without reusing existing buffer.
static void tcp_timer_update(tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id, u32 interval)
void scoreboard_clear(sack_scoreboard_t *sb)
void tcp_send_fin(tcp_connection_t *tc)
Send FIN.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 next_buffer
Next buffer for this linked-list of buffers.
static tcp_connection_t * tcp_listener_get(u32 tli)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
static tcp_worker_ctx_t * tcp_get_worker(u32 thread_index)
void session_transport_closed_notify(transport_connection_t *tc)
Notification from transport that it is closed.
VLIB buffer representation.
int session_stream_connect_notify(transport_connection_t *tc, session_error_t err)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
void tcp_connection_init_vars(tcp_connection_t *tc)
Initialize tcp connection variables.
static void tcp_init_w_buffer(tcp_connection_t *tc, vlib_buffer_t *b, u8 is_ip4)
Initialize connection by gleaning network and rcv params from buffer.
session_t * session_lookup_listener6(u32 fib_index, ip6_address_t *lcl, u16 lcl_port, u8 proto, u8 use_wildcard)
static f64 tcp_time_now_us(u32 thread_index)
void scoreboard_init_rxt(sack_scoreboard_t *sb, u32 snd_una)
static void tcp_connection_set_state(tcp_connection_t *tc, tcp_state_t state)
static u32 ooo_segment_offset_prod(svm_fifo_t *f, ooo_segment_t *s)
struct clib_bihash_value offset
template key/value backing page structure
static u32 vlib_num_workers()
void tcp_connection_cleanup(tcp_connection_t *tc)
Cleans up connection state.
void tcp_connection_del(tcp_connection_t *tc)
Connection removal.
f64 end
end of the time range
void tcp_reschedule(tcp_connection_t *tc)
u16 flags
Copy of main node flags.
u32 session_tx_fifo_dequeue_drop(transport_connection_t *tc, u32 max_bytes)
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static u8 tcp_timer_is_active(tcp_connection_t *tc, tcp_timers_e timer)
void tcp_program_ack(tcp_connection_t *tc)
#define tcp_opts_sack_permitted(_to)
static u32 tcp_tstamp(tcp_connection_t *tc)
Generate timestamp for tcp connection.
static void tcp_cc_rcv_cong_ack(tcp_connection_t *tc, tcp_cc_ack_t ack_type, tcp_rate_sample_t *rs)
int session_stream_accept(transport_connection_t *tc, u32 listener_index, u32 thread_index, u8 notify)
Accept a stream session.
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
#define VLIB_NODE_FLAG_TRACE
tcp_bts_flags_t flags
Rate sample flags from bt sample.
#define CLIB_CACHE_LINE_BYTES
static transport_connection_t * transport_get_listener(transport_proto_t tp, u32 conn_index)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
static tcp_connection_t * tcp_get_connection_from_transport(transport_connection_t *tconn)
static tcp_main_t * vnet_get_tcp_main()
session_t * session_lookup_listener4(u32 fib_index, ip4_address_t *lcl, u16 lcl_port, u8 proto, u8 use_wildcard)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static tcp_connection_t * tcp_input_lookup_buffer(vlib_buffer_t *b, u8 thread_index, u32 *error, u8 is_ip4, u8 is_nolookup)
static u32 transport_tx_fifo_size(transport_connection_t *tc)
transport_connection_t * session_lookup_half_open_connection(u64 handle, u8 proto, u8 is_ip4)
void tcp_rcv_sacks(tcp_connection_t *tc, u32 ack)
#define TCP_EVT(_evt, _args...)