23 #define tcp_error(n,s) s, 29 #define foreach_tcp_state_next \ 30 _ (DROP4, "ip4-drop") \ 31 _ (DROP6, "ip6-drop") \ 32 _ (TCP4_OUTPUT, "tcp4-output") \ 33 _ (TCP6_OUTPUT, "tcp6-output") 35 typedef enum _tcp_established_next
37 #define _(s,n) TCP_ESTABLISHED_NEXT_##s, 43 typedef enum _tcp_rcv_process_next
45 #define _(s,n) TCP_RCV_PROCESS_NEXT_##s, 51 typedef enum _tcp_syn_sent_next
53 #define _(s,n) TCP_SYN_SENT_NEXT_##s, 59 typedef enum _tcp_listen_next
61 #define _(s,n) TCP_LISTEN_NEXT_##s, 68 typedef enum _tcp_state_next
70 #define _(s,n) TCP_NEXT_##s, 76 #define tcp_next_output(is_ip4) (is_ip4 ? TCP_NEXT_TCP4_OUTPUT \ 77 : TCP_NEXT_TCP6_OUTPUT) 79 #define tcp_next_drop(is_ip4) (is_ip4 ? TCP_NEXT_DROP4 \ 112 return (
seq_geq (end_seq, tc->rcv_las)
113 &&
seq_leq (seq, tc->rcv_nxt + tc->rcv_wnd));
128 u8 opt_len, opts_len, kind;
133 data = (
const u8 *) (th + 1);
136 to->
flags &= (TCP_OPTS_FLAG_SACK_PERMITTED | TCP_OPTS_FLAG_WSCALE
139 for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
159 if (opt_len < 2 || opt_len > opts_len)
171 to->
flags |= TCP_OPTS_FLAG_MSS;
172 to->
mss = clib_net_to_host_u16 (*(
u16 *) (data + 2));
180 to->
flags |= TCP_OPTS_FLAG_WSCALE;
188 to->
flags |= TCP_OPTS_FLAG_TSTAMP;
189 if ((to->
flags & TCP_OPTS_FLAG_TSTAMP)
192 to->
tsval = clib_net_to_host_u32 (*(
u32 *) (data + 2));
193 to->
tsecr = clib_net_to_host_u32 (*(
u32 *) (data + 6));
200 to->
flags |= TCP_OPTS_FLAG_SACK_PERMITTED;
204 if ((to->
flags & TCP_OPTS_FLAG_SACK_PERMITTED) == 0 ||
tcp_syn (th))
211 to->
flags |= TCP_OPTS_FLAG_SACK;
216 b.start = clib_net_to_host_u32 (*(
u32 *) (data + 2 + 8 * j));
217 b.end = clib_net_to_host_u32 (*(
u32 *) (data + 6 + 8 * j));
259 &&
seq_leq (tc->rcv_las, seq_end))
262 tc->tsval_recent = tc->rcv_opts.tsval;
284 *error0 = TCP_ERROR_CONNECTION_CLOSED;
290 *error0 = TCP_ERROR_SEGMENT_INVALID;
296 *error0 = TCP_ERROR_OPTIONS;
302 *error0 = TCP_ERROR_PAWS;
311 tc0->tsval_recent = tc0->rcv_opts.tsval;
332 &&
vnet_buffer (b0)->tcp.seq_number == tc0->rcv_nxt - 1)
335 if (tc0->state == TCP_STATE_SYN_RCVD)
339 *error0 = TCP_ERROR_SYNS_RCVD;
345 *error0 = TCP_ERROR_SYN_ACKS_RCVD;
352 if (tc0->rcv_wnd < tc0->snd_mss
353 && tc0->rcv_nxt ==
vnet_buffer (b0)->tcp.seq_number)
361 tc0->rcv_las - tc0->rcv_wnd)
363 tc0->rcv_nxt + tc0->rcv_wnd))
366 *error0 = TCP_ERROR_RCV_WND;
384 *error0 = TCP_ERROR_RST_RCVD;
393 *error0 = TCP_ERROR_SPURIOUS_SYN;
420 *error = TCP_ERROR_ACK_INVALID;
425 tc->bytes_acked =
vnet_buffer (b)->tcp.ack_number - tc->snd_una;
427 *error = TCP_ERROR_ACK_OK;
447 err = mrtt - tc->srtt;
451 tc->srtt =
clib_max ((
int) tc->srtt + (err >> 3), 1);
452 diff = (
clib_abs (err) - (int) tc->rttvar) >> 2;
453 tc->rttvar =
clib_max ((
int) tc->rttvar + diff, 1);
459 tc->rttvar = mrtt >> 1;
463 #ifndef CLIB_MARCH_VARIANT 497 if (tc->rtt_ts &&
seq_geq (ack, tc->rtt_seq))
500 tc->mrtt_us = tc->mrtt_us + (sample - tc->mrtt_us) * 0.125;
511 mrtt =
clib_max (now - tc->rcv_opts.tsecr, 1);
539 tc->mrtt_us =
clib_max (tc->mrtt_us, 0.0001);
548 if (tc->rto_boff && mrtt > 1 *
THZ)
565 u32 *pending_deq_acked;
573 for (i = 0; i <
vec_len (pending_deq_acked); i++)
576 tc->flags &= ~TCP_CONN_DEQ_PENDING;
588 if (
seq_leq (tc->psh_seq, tc->snd_una))
589 tc->flags &= ~TCP_CONN_PSH_PENDING;
607 if (!(tc->flags & TCP_CONN_DEQ_PENDING))
610 tc->flags |= TCP_CONN_DEQ_PENDING;
612 tc->burst_acked += tc->bytes_acked + tc->sack_sb.snd_una_adv;
622 return ((
vnet_buffer (b)->tcp.ack_number == prev_snd_una)
623 &&
seq_gt (tc->snd_nxt, tc->snd_una)
625 && (prev_snd_wnd == tc->snd_wnd));
633 u32 prev_snd_wnd,
u32 prev_snd_una,
u8 * is_dack)
637 *is_dack = tc->sack_sb.last_sacked_bytes
643 #ifndef CLIB_MARCH_VARIANT 648 return hole - sb->holes;
654 return hole->end - hole->start;
705 next->prev = hole->prev;
709 sb->tail = hole->prev;
715 prev->next = hole->next;
719 sb->head = hole->next;
749 hole->prev = prev_index;
750 hole->next = prev->next;
753 next->prev = hole_index;
755 sb->tail = hole_index;
757 prev->next = hole_index;
761 sb->head = hole_index;
770 #ifndef CLIB_MARCH_VARIANT 775 u32 bytes = 0, blks = 0;
778 sb->sacked_bytes = 0;
783 if (
seq_gt (sb->high_sacked, left->end))
785 bytes = sb->high_sacked - left->end;
789 while ((right = left)
795 bytes += right->start - left->end;
808 bytes += right->start - left->end;
810 while ((right = left));
813 sb->sacked_bytes = bytes;
824 u8 have_unsent,
u8 * can_rescue,
u8 * snd_limited)
829 while (hole &&
seq_leq (hole->end, sb->high_rxt) && hole->is_lost)
840 if (hole->is_lost &&
seq_lt (hole->start, sb->high_sacked))
853 else if (
seq_lt (hole->start, sb->high_sacked))
869 if (hole &&
seq_lt (sb->high_rxt, hole->start))
870 sb->high_rxt = hole->start;
883 snd_una =
seq_gt (snd_una, hole->start) ? snd_una : hole->start;
884 sb->cur_rxt_hole = sb->head;
886 sb->high_rxt = snd_una;
887 sb->rescue_rxt = snd_una - 1;
890 #ifndef CLIB_MARCH_VARIANT 909 sb->sacked_bytes = 0;
910 sb->last_sacked_bytes = 0;
911 sb->last_bytes_delivered = 0;
931 return (!hole || (
seq_geq (hole->start, tc->snd_una)
932 &&
seq_lt (hole->end, tc->snd_nxt)));
935 #ifndef CLIB_MARCH_VARIANT 942 u32 blk_index = 0, old_sacked_bytes, hole_index;
945 sb->last_sacked_bytes = 0;
946 sb->last_bytes_delivered = 0;
953 old_sacked_bytes = sb->sacked_bytes;
956 blk = tc->rcv_opts.sacks;
957 while (blk <
vec_end (tc->rcv_opts.sacks))
959 if (
seq_lt (blk->start, blk->end)
960 &&
seq_gt (blk->start, tc->snd_una)
961 &&
seq_gt (blk->start, ack)
962 &&
seq_lt (blk->start, tc->snd_nxt)
963 &&
seq_leq (blk->end, tc->snd_nxt))
968 vec_del1 (tc->rcv_opts.sacks, blk - tc->rcv_opts.sacks);
972 if (
seq_gt (ack, tc->snd_una))
974 tmp.start = tc->snd_una;
979 if (
vec_len (tc->rcv_opts.sacks) == 0)
985 for (i = 0; i <
vec_len (tc->rcv_opts.sacks); i++)
986 for (j = i + 1; j <
vec_len (tc->rcv_opts.sacks); j++)
987 if (
seq_lt (tc->rcv_opts.sacks[j].start, tc->rcv_opts.sacks[i].start))
989 tmp = tc->rcv_opts.sacks[
i];
990 tc->rcv_opts.sacks[
i] = tc->rcv_opts.sacks[j];
991 tc->rcv_opts.sacks[j] = tmp;
998 tc->snd_una, tc->snd_nxt);
1000 tmp = tc->rcv_opts.sacks[
vec_len (tc->rcv_opts.sacks) - 1];
1001 sb->high_sacked = tmp.end;
1007 tmp = tc->rcv_opts.sacks[
vec_len (tc->rcv_opts.sacks) - 1];
1009 if (
seq_gt (tc->snd_nxt, last_hole->end))
1011 if (
seq_geq (last_hole->start, sb->high_sacked))
1013 last_hole->end = tc->snd_nxt;
1016 else if (
seq_lt (sb->high_sacked, tc->snd_nxt))
1024 if (
seq_gt (tmp.end, sb->high_sacked))
1025 sb->high_sacked = tmp.end;
1030 while (hole && blk_index < vec_len (tc->rcv_opts.sacks))
1032 blk = &tc->rcv_opts.sacks[blk_index];
1033 if (
seq_leq (blk->start, hole->start))
1036 if (
seq_geq (blk->end, hole->end))
1041 if (blk->end == ack)
1045 if (
seq_lt (ack, next_hole->start))
1046 sb->snd_una_adv = next_hole->start - ack;
1047 sb->last_bytes_delivered +=
1048 next_hole->start - hole->end;
1053 sb->snd_una_adv = sb->high_sacked - ack;
1054 sb->last_bytes_delivered += sb->high_sacked - hole->end;
1064 if (
seq_gt (blk->end, hole->start))
1066 hole->start = blk->end;
1074 if (
seq_lt (blk->end, hole->end))
1082 hole->end = blk->start;
1086 else if (
seq_lt (blk->start, hole->end))
1088 hole->end = blk->start;
1097 if (hole->start == ack + sb->snd_una_adv && hole->end == tc->snd_nxt)
1102 sb->last_sacked_bytes = sb->sacked_bytes
1103 - (old_sacked_bytes - sb->last_bytes_delivered);
1106 || sb->sacked_bytes < tc->snd_nxt -
seq_max (tc->snd_una, ack));
1107 ASSERT (sb->last_sacked_bytes + sb->lost_bytes <= tc->snd_nxt
1110 || sb->holes[sb->head].start == ack + sb->snd_una_adv);
1126 if (
seq_lt (tc->snd_wl1, seq)
1127 || (tc->snd_wl1 == seq &&
seq_leq (tc->snd_wl2, ack)))
1129 tc->snd_wnd = snd_wnd;
1153 #ifndef CLIB_MARCH_VARIANT 1164 tc->snd_congestion = tc->snd_nxt;
1165 tc->cwnd_acc_bytes = 0;
1166 tc->snd_rxt_bytes = 0;
1167 tc->prev_ssthresh = tc->ssthresh;
1168 tc->prev_cwnd = tc->cwnd;
1169 tc->cc_algo->congestion (tc);
1185 #ifndef CLIB_MARCH_VARIANT 1189 tc->cc_algo->recovered (tc);
1190 tc->snd_rxt_bytes = 0;
1191 tc->rcv_dupacks = 0;
1192 tc->snd_rxt_bytes = 0;
1205 tc->cwnd = tc->prev_cwnd;
1206 tc->ssthresh = tc->prev_ssthresh;
1207 tc->rcv_dupacks = 0;
1211 tc->snd_nxt =
seq_max (tc->snd_nxt, tc->snd_congestion);
1217 ASSERT (tc->rto_boff == 0);
1234 && tc->cwnd > tc->ssthresh + 3 * tc->snd_mss);
1259 ASSERT (tc->rto_boff == 0);
1274 tc->rcv_dupacks = 0;
1281 (
seq_leq (tc->snd_congestion, tc->snd_una - tc->bytes_acked)
1282 &&
seq_gt (tc->snd_congestion, tc->snd_una)))
1283 tc->snd_congestion = tc->snd_una - 1;
1299 #ifndef CLIB_MARCH_VARIANT 1303 if (!(tc->flags & TCP_CONN_FRXT_PENDING))
1306 tc->flags |= TCP_CONN_FRXT_PENDING;
1313 u32 *ongoing_fast_rxt, burst_bytes, sent_bytes, thread_index;
1314 u32 max_burst_size, burst_size, n_segs = 0, n_segs_now;
1333 max_burst_size =
clib_max (max_burst_size, 1);
1335 for (i = 0; i <
vec_len (ongoing_fast_rxt); i++)
1340 tc->flags &= ~TCP_CONN_FRXT_PENDING;
1350 tc->flags &= ~TCP_CONN_FRXT_PENDING;
1354 burst_size =
clib_min (burst_size, burst_bytes / tc->snd_mss);
1362 sent_bytes =
clib_min (n_segs_now * tc->snd_mss, burst_bytes);
1365 n_segs += n_segs_now;
1367 _vec_len (ongoing_fast_rxt) = 0;
1382 if (tc->bytes_acked)
1394 ASSERT (tc->snd_una != tc->snd_nxt || tc->sack_sb.last_sacked_bytes);
1413 if (is_dack && tc->snd_una == tc->snd_congestion
1416 tc->rcv_dupacks = 0;
1425 tc->cwnd = tc->ssthresh;
1433 tc->cwnd = tc->ssthresh + 3 * tc->snd_mss;
1437 pacer_wnd =
clib_max (0.1 * tc->cwnd, 2 * tc->snd_mss);
1444 else if (!tc->bytes_acked
1466 if (
seq_leq (tc->snd_una, tc->snd_congestion)
1467 && ((!(tc->cwnd > tc->snd_mss
1468 && tc->bytes_acked <= 4 * tc->snd_mss))
1469 || (tc->rcv_opts.tsecr != tc->tsecr_last_ack)))
1471 tc->rcv_dupacks = 0;
1476 if (!tc->bytes_acked)
1490 if (
seq_geq (tc->snd_una, tc->snd_congestion))
1497 tc->tsecr_last_ack = tc->rcv_opts.tsecr;
1515 tc->rcv_dupacks = 0;
1528 ASSERT (tc->bytes_acked + tc->sack_sb.snd_una_adv
1529 >= tc->sack_sb.last_bytes_delivered
1530 || (tc->flags & TCP_CONN_FINSNT));
1534 if (
seq_lt (tc->snd_una, tc->sack_sb.high_rxt))
1536 rxt_delivered = tc->bytes_acked + tc->sack_sb.snd_una_adv
1537 - tc->sack_sb.last_bytes_delivered;
1538 ASSERT (tc->snd_rxt_bytes >= rxt_delivered);
1539 tc->snd_rxt_bytes -= rxt_delivered;
1544 tc->snd_rxt_bytes = 0;
1545 tc->sack_sb.high_rxt = tc->snd_una;
1552 tc->sack_sb.last_bytes_delivered += tc->bytes_acked;
1553 if (tc->snd_rxt_bytes > tc->bytes_acked)
1554 tc->snd_rxt_bytes -= tc->bytes_acked;
1556 tc->snd_rxt_bytes = 0;
1574 u32 prev_snd_wnd, prev_snd_una;
1591 *error = TCP_ERROR_ACK_FUTURE;
1600 *error = TCP_ERROR_ACK_OLD;
1617 prev_snd_wnd = tc->snd_wnd;
1618 prev_snd_una = tc->snd_una;
1621 clib_net_to_host_u16 (th->window) << tc->snd_wscale);
1622 tc->bytes_acked =
vnet_buffer (b)->tcp.ack_number - tc->snd_una;
1623 tc->snd_una =
vnet_buffer (b)->tcp.ack_number + tc->sack_sb.snd_una_adv;
1626 if (tc->bytes_acked)
1643 *error = TCP_ERROR_ACK_OK;
1646 *error = TCP_ERROR_ACK_DUP;
1656 *error = TCP_ERROR_ACK_OK;
1673 u32 thread_index, *pending_disconnects;
1682 for (i = 0; i <
vec_len (pending_disconnects); i++)
1708 *error = TCP_ERROR_FIN_RCVD;
1711 #ifndef CLIB_MARCH_VARIANT 1716 for (i = 1; i <
vec_len (sacks); i++)
1718 if (sacks[i - 1].end == sacks[i].start)
1743 if (
seq_lt (tc->rcv_nxt, start))
1746 block->start = start;
1751 for (i = 0; i <
vec_len (tc->snd_sacks); i++)
1754 if (
seq_leq (tc->snd_sacks[i].start, tc->rcv_nxt))
1758 if (block && (
seq_geq (tc->snd_sacks[i].end, new_list[0].start)
1759 &&
seq_leq (tc->snd_sacks[i].start, new_list[0].end)))
1761 if (
seq_lt (tc->snd_sacks[i].start, new_list[0].start))
1762 new_list[0].start = tc->snd_sacks[i].start;
1763 if (
seq_lt (new_list[0].end, tc->snd_sacks[i].end))
1764 new_list[0].end = tc->snd_sacks[i].end;
1770 vec_add1 (new_list, tc->snd_sacks[i]);
1777 tc->snd_sacks_fl = tc->snd_sacks;
1778 tc->snd_sacks = new_list;
1788 for (
i = 0;
i <
vec_len (tc->snd_sacks);
i++)
1789 bytes += tc->snd_sacks[
i].end - tc->snd_sacks[
i].start;
1799 int written, error = TCP_ERROR_ENQUEUED;
1806 TCP_EVT_DBG (TCP_EVT_INPUT, tc, 0, data_len, written);
1811 tc->rcv_nxt += written;
1814 else if (written > data_len)
1816 tc->rcv_nxt += written;
1817 TCP_EVT_DBG (TCP_EVT_CC_INPUT, tc, data_len, written);
1819 else if (written > 0)
1822 tc->rcv_nxt += written;
1823 error = TCP_ERROR_PARTIALLY_ENQUEUED;
1827 return TCP_ERROR_FIFO_FULL;
1861 return TCP_ERROR_FIFO_FULL;
1864 TCP_EVT_DBG (TCP_EVT_INPUT, tc, 1, data_len, data_len);
1872 s0 =
session_get (tc->c_s_index, tc->c_thread_index);
1880 start = tc->rcv_nxt +
offset;
1888 return TCP_ERROR_ENQUEUED_OOO;
1903 || (tc->flags & TCP_CONN_SNDACK) != 0
1920 if (!(b->
flags & VLIB_BUFFER_NEXT_PRESENT))
1927 n_bytes_to_drop -= discard;
1929 while (n_bytes_to_drop);
1930 if (n_bytes_to_drop > first)
1948 u32 error, n_bytes_to_drop, n_data_bytes;
1966 error = TCP_ERROR_SEGMENT_OLD;
1972 n_bytes_to_drop = tc->rcv_nxt -
vnet_buffer (b)->tcp.seq_number;
1973 n_data_bytes -= n_bytes_to_drop;
1977 error = TCP_ERROR_SEGMENT_OLD;
2022 s =
format (s,
"%U\n%U%U",
2037 s =
format (s,
"%d -> %d (%U)",
2038 clib_net_to_host_u16 (t->
tcp_header.dst_port),
2081 if (b0->
flags & VLIB_BUFFER_IS_TRACED)
2105 #define tcp_maybe_inc_counter(node_id, err, count) \ 2107 if (next0 != tcp_next_drop (is_ip4)) \ 2108 tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index, \ 2109 tcp6_##node_id##_node.index, is_ip4, err, \ 2112 #define tcp_inc_counter(node_id, err, count) \ 2113 tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index, \ 2114 tcp6_##node_id##_node.index, is_ip4, \ 2116 #define tcp_maybe_inc_err_counter(cnts, err) \ 2118 cnts[err] += (next0 != tcp_next_drop (is_ip4)); \ 2120 #define tcp_inc_err_counter(cnts, err, val) \ 2124 #define tcp_store_err_counters(node_id, cnts) \ 2127 for (i = 0; i < TCP_N_ERROR; i++) \ 2129 tcp_inc_counter(node_id, i, cnts[i]); \ 2139 u32 n_left_from, *from, *first_buffer;
2148 while (n_left_from > 0)
2150 u32 bi0, error0 = TCP_ERROR_ACK_OK;
2155 if (n_left_from > 1)
2173 error0 = TCP_ERROR_INVALID_CONNECTION;
2208 err_counters[TCP_ERROR_MSG_QUEUE_FULL] = errors;
2234 .name =
"tcp4-established",
2236 .vector_size =
sizeof (
u32),
2242 #define _(s,n) [TCP_ESTABLISHED_NEXT_##s] = n, 2253 .name =
"tcp6-established",
2255 .vector_size =
sizeof (
u32),
2261 #define _(s,n) [TCP_ESTABLISHED_NEXT_##s] = n, 2280 if (tc->c_lcl_port == 0 && tc->state == TCP_STATE_LISTEN)
2283 u8 is_valid = (tc->c_lcl_port == hdr->dst_port
2284 && (tc->state == TCP_STATE_LISTEN
2285 || tc->c_rmt_port == hdr->src_port));
2291 tc->c_proto, tc->c_is_ip4);
2295 if (tmp->lcl_port == hdr->dst_port
2296 && tmp->rmt_port == hdr->src_port)
2298 TCP_DBG (
"half-open is valid!");
2327 thread_index, &is_filtered);
2342 thread_index, &is_filtered);
2354 u32 n_left_from, *from, *first_buffer, errors = 0;
2361 while (n_left_from > 0)
2363 u32 bi0, ack0, seq0, error0 = TCP_ERROR_NONE;
2378 error0 = TCP_ERROR_INVALID_CONNECTION;
2388 my_thread_index, is_ip4));
2389 error0 = TCP_ERROR_SPURIOUS_SYN_ACK;
2400 || tcp0->src_port != tc0->c_rmt_port))
2402 error0 = TCP_ERROR_INVALID_CONNECTION;
2409 error0 = TCP_ERROR_SEGMENT_INVALID;
2430 if (
seq_leq (ack0, tc0->iss) ||
seq_gt (ack0, tc0->snd_nxt))
2434 error0 = TCP_ERROR_RCV_WND;
2439 if (
seq_gt (tc0->snd_una, ack0))
2441 error0 = TCP_ERROR_ACK_INVALID;
2456 error0 = TCP_ERROR_RST_RCVD;
2471 error0 = TCP_ERROR_SEGMENT_INVALID;
2478 error0 = TCP_ERROR_OPTIONS;
2484 pool_get (tm->connections[my_thread_index], new_tc0);
2486 new_tc0->c_c_index = new_tc0 - tm->connections[my_thread_index];
2487 new_tc0->c_thread_index = my_thread_index;
2489 new_tc0->irs = seq0;
2497 tc0->flags |= TCP_CONN_HALF_OPEN_DONE;
2501 new_tc0->tsval_recent = new_tc0->rcv_opts.tsval;
2506 new_tc0->snd_wscale = new_tc0->rcv_opts.wscale;
2508 new_tc0->rcv_wscale = 0;
2510 new_tc0->snd_wnd = clib_net_to_host_u16 (tcp0->window)
2511 << new_tc0->snd_wscale;
2512 new_tc0->snd_wl1 = seq0;
2513 new_tc0->snd_wl2 = ack0;
2523 new_tc0->snd_una = ack0;
2524 new_tc0->state = TCP_STATE_ESTABLISHED;
2527 new_tc0->rcv_las = new_tc0->rcv_nxt;
2539 new_tc0->tx_fifo_size =
2544 error0 = TCP_ERROR_SYN_ACKS_RCVD;
2549 new_tc0->state = TCP_STATE_SYN_RCVD;
2560 new_tc0->tx_fifo_size =
2562 new_tc0->rtt_ts = 0;
2565 error0 = TCP_ERROR_SYNS_RCVD;
2574 if (error0 == TCP_ERROR_ACK_OK)
2575 error0 = TCP_ERROR_SYN_ACKS_RCVD;
2619 .name =
"tcp4-syn-sent",
2621 .vector_size =
sizeof (
u32),
2627 #define _(s,n) [TCP_SYN_SENT_NEXT_##s] = n, 2638 .name =
"tcp6-syn-sent",
2640 .vector_size =
sizeof (
u32),
2646 #define _(s,n) [TCP_SYN_SENT_NEXT_##s] = n, 2664 u32 n_left_from, *from, max_dequeue;
2669 while (n_left_from > 0)
2671 u32 bi0, error0 = TCP_ERROR_NONE;
2686 error0 = TCP_ERROR_INVALID_CONNECTION;
2698 if (tmp->state != tc0->state)
2700 if (tc0->state != TCP_STATE_CLOSED)
2711 error0 = TCP_ERROR_CONNECTION_CLOSED;
2726 case TCP_STATE_SYN_RCVD:
2729 if (tc0->rcv_nxt !=
vnet_buffer (b0)->tcp.seq_number || is_fin0)
2732 error0 = TCP_ERROR_SEGMENT_INVALID;
2752 tc0->state = TCP_STATE_ESTABLISHED;
2757 tc0->snd_wnd = clib_net_to_host_u16 (tcp0->window)
2758 << tc0->rcv_opts.wscale;
2767 error0 = TCP_ERROR_MSG_QUEUE_FULL;
2771 error0 = TCP_ERROR_ACK_OK;
2773 case TCP_STATE_ESTABLISHED:
2780 case TCP_STATE_FIN_WAIT_1:
2788 if (tc0->flags & TCP_CONN_FINPNDG)
2792 if (max_dequeue <= tc0->burst_acked)
2795 else if ((tc0->flags & TCP_CONN_FINRCVD) && tc0->bytes_acked)
2800 else if (tc0->snd_una == tc0->snd_nxt)
2808 if (tc0->flags & TCP_CONN_FINRCVD)
2821 if (tc0->burst_acked > 1)
2823 tc0->burst_acked - 1);
2824 tc0->burst_acked = 0;
2827 case TCP_STATE_FIN_WAIT_2:
2833 tc0->burst_acked = 0;
2835 case TCP_STATE_CLOSE_WAIT:
2840 if (!(tc0->flags & TCP_CONN_FINPNDG))
2845 if (max_dequeue > tc0->burst_acked)
2853 case TCP_STATE_CLOSING:
2860 if (tc0->snd_una != tc0->snd_nxt)
2869 case TCP_STATE_LAST_ACK:
2878 if (is_fin0 && tc0->snd_una != tc0->snd_nxt)
2895 case TCP_STATE_TIME_WAIT:
2920 case TCP_STATE_ESTABLISHED:
2921 case TCP_STATE_FIN_WAIT_1:
2922 case TCP_STATE_FIN_WAIT_2:
2926 case TCP_STATE_CLOSE_WAIT:
2927 case TCP_STATE_CLOSING:
2928 case TCP_STATE_LAST_ACK:
2929 case TCP_STATE_TIME_WAIT:
2943 case TCP_STATE_ESTABLISHED:
2951 case TCP_STATE_SYN_RCVD:
2961 case TCP_STATE_CLOSE_WAIT:
2962 case TCP_STATE_CLOSING:
2963 case TCP_STATE_LAST_ACK:
2966 case TCP_STATE_FIN_WAIT_1:
2969 if (tc0->flags & TCP_CONN_FINPNDG)
2974 tc0->flags |= TCP_CONN_FINRCVD;
2985 case TCP_STATE_FIN_WAIT_2:
2993 case TCP_STATE_TIME_WAIT:
3000 error0 = TCP_ERROR_FIN_RCVD;
3039 .name =
"tcp4-rcv-process",
3041 .vector_size =
sizeof (
u32),
3047 #define _(s,n) [TCP_RCV_PROCESS_NEXT_##s] = n, 3058 .name =
"tcp6-rcv-process",
3060 .vector_size =
sizeof (
u32),
3066 #define _(s,n) [TCP_RCV_PROCESS_NEXT_##s] = n, 3081 u32 n_left_from, *from, n_syns = 0, *first_buffer;
3087 while (n_left_from > 0)
3097 u32 error0 = TCP_ERROR_NONE;
3139 error0 = TCP_ERROR_CREATE_EXISTS;
3145 child0->c_lcl_port = th0->dst_port;
3146 child0->c_rmt_port = th0->src_port;
3147 child0->c_is_ip4 = is_ip4;
3148 child0->state = TCP_STATE_SYN_RCVD;
3149 child0->c_fib_index = lc0->c_fib_index;
3166 error0 = TCP_ERROR_OPTIONS;
3172 child0->rcv_nxt =
vnet_buffer (b0)->tcp.seq_number + 1;
3173 child0->rcv_las = child0->rcv_nxt;
3180 child0->tsval_recent = child0->rcv_opts.tsval;
3185 child0->snd_wscale = child0->rcv_opts.wscale;
3187 child0->snd_wnd = clib_net_to_host_u16 (th0->window)
3188 << child0->snd_wscale;
3189 child0->snd_wl1 =
vnet_buffer (b0)->tcp.seq_number;
3190 child0->snd_wl2 =
vnet_buffer (b0)->tcp.ack_number;
3199 error0 = TCP_ERROR_CREATE_SESSION_FAIL;
3218 n_syns += (error0 == TCP_ERROR_NONE);
3242 .name =
"tcp4-listen",
3244 .vector_size =
sizeof (
u32),
3250 #define _(s,n) [TCP_LISTEN_NEXT_##s] = n, 3261 .name =
"tcp6-listen",
3263 .vector_size =
sizeof (
u32),
3269 #define _(s,n) [TCP_LISTEN_NEXT_##s] = n, 3277 typedef enum _tcp_input_next
3289 #define foreach_tcp4_input_next \ 3290 _ (DROP, "ip4-drop") \ 3291 _ (LISTEN, "tcp4-listen") \ 3292 _ (RCV_PROCESS, "tcp4-rcv-process") \ 3293 _ (SYN_SENT, "tcp4-syn-sent") \ 3294 _ (ESTABLISHED, "tcp4-established") \ 3295 _ (RESET, "tcp4-reset") \ 3296 _ (PUNT, "ip4-punt") 3298 #define foreach_tcp6_input_next \ 3299 _ (DROP, "ip6-drop") \ 3300 _ (LISTEN, "tcp6-listen") \ 3301 _ (RCV_PROCESS, "tcp6-rcv-process") \ 3302 _ (SYN_SENT, "tcp6-syn-sent") \ 3303 _ (ESTABLISHED, "tcp6-established") \ 3304 _ (RESET, "tcp6-reset") \ 3305 _ (PUNT, "ip6-punt") 3307 #define filter_flags (TCP_FLAG_SYN|TCP_FLAG_ACK|TCP_FLAG_RST|TCP_FLAG_FIN) 3318 for (i = 0; i < n_bufs; i++)
3320 if (bs[i]->
flags & VLIB_BUFFER_IS_TRACED)
3334 if (*error == TCP_ERROR_FILTERED || *error == TCP_ERROR_WRONG_THREAD)
3338 else if ((is_ip4 && tm->punt_unknown4) || (!is_ip4 && tm->punt_unknown6))
3341 *error = TCP_ERROR_PUNT;
3346 *error = TCP_ERROR_NO_LISTENER;
3355 int n_advance_bytes, n_data_bytes;
3366 *error = TCP_ERROR_LENGTH;
3372 n_data_bytes = clib_net_to_host_u16 (ip4->
length) - n_advance_bytes;
3377 *error = TCP_ERROR_LENGTH;
3384 thread_index, &result);
3391 *error = TCP_ERROR_LENGTH;
3399 n_advance_bytes +=
sizeof (ip6[0]);
3403 *error = TCP_ERROR_LENGTH;
3417 thread_index, &result);
3420 vnet_buffer (b)->tcp.seq_number = clib_net_to_host_u32 (tcp->seq_number);
3421 vnet_buffer (b)->tcp.ack_number = clib_net_to_host_u32 (tcp->ack_number);
3422 vnet_buffer (b)->tcp.data_offset = n_advance_bytes;
3428 *error = result ? TCP_ERROR_NONE + result : *error;
3442 *next = tm->dispatch_table[tc->state][
flags].next;
3443 *error = tm->dispatch_table[tc->state][
flags].error;
3452 if (*error == TCP_ERROR_DISPATCH)
3453 clib_warning (
"tcp conn %u disp error state %U flags %U",
3477 while (n_left_from >= 4)
3479 u32 error0 = TCP_ERROR_NO_LISTENER, error1 = TCP_ERROR_NO_LISTENER;
3500 vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index;
3501 vnet_buffer (b[1])->tcp.connection_index = tc1->c_c_index;
3511 vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index;
3520 vnet_buffer (b[1])->tcp.connection_index = tc1->c_c_index;
3531 while (n_left_from > 0)
3534 u32 error0 = TCP_ERROR_NO_LISTENER;
3536 if (n_left_from > 1)
3547 vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index;
3580 .name =
"tcp4-input",
3582 .vector_size =
sizeof (
u32),
3588 #define _(s,n) [TCP_INPUT_NEXT_##s] = n, 3600 .name =
"tcp6-input",
3602 .vector_size =
sizeof (
u32),
3608 #define _(s,n) [TCP_INPUT_NEXT_##s] = n, 3617 #ifndef CLIB_MARCH_VARIANT 3622 for (i = 0; i <
ARRAY_LEN (tm->dispatch_table); i++)
3623 for (j = 0; j <
ARRAY_LEN (tm->dispatch_table[i]); j++)
3626 tm->dispatch_table[
i][j].error = TCP_ERROR_DISPATCH;
3629 #define _(t,f,n,e) \ 3631 tm->dispatch_table[TCP_STATE_##t][f].next = (n); \ 3632 tm->dispatch_table[TCP_STATE_##t][f].error = (e); \ 3641 TCP_ERROR_ACK_INVALID);
3643 TCP_ERROR_SEGMENT_INVALID);
3645 TCP_ERROR_SEGMENT_INVALID);
3647 TCP_ERROR_INVALID_CONNECTION);
3650 TCP_ERROR_SEGMENT_INVALID);
3652 TCP_ERROR_SEGMENT_INVALID);
3656 TCP_ERROR_SEGMENT_INVALID);
3658 TCP_ERROR_SEGMENT_INVALID);
3660 TCP_ERROR_SEGMENT_INVALID);
3838 TCP_ERROR_CONNECTION_CLOSED);
#define tcp_in_cong_recovery(tc)
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 * pending_disconnects
vector of pending disconnect notifications
#define tcp_in_recovery(tc)
static f64 tcp_time_now_us(u32 thread_index)
#define TCP_OPTION_LEN_SACK_PERMITTED
#define seq_leq(_s1, _s2)
struct _sack_block sack_block_t
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
#define timestamp_leq(_t1, _t2)
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.
#define TCP_TIMEWAIT_TIME
#define tcp_opts_tstamp(_to)
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
struct _sack_scoreboard sack_scoreboard_t
static tcp_connection_t * tcp_half_open_connection_get(u32 conn_index)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
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.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define tcp_recovery_off(tc)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define THZ
TCP tick frequency.
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
struct _tcp_connection tcp_connection_t
static session_t * session_get(u32 si, u32 thread_index)
static u32 tcp_available_cc_snd_space(const tcp_connection_t *tc)
Estimate of how many bytes we can still push into the network.
#define tcp_opts_sack(_to)
tcp_connection_t tcp_connection
static tcp_connection_t * tcp_get_connection_from_transport(transport_connection_t *tconn)
#define VLIB_NODE_FN(node)
#define tcp_disconnect_pending_on(tc)
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)
static void tcp_cc_rcv_ack(tcp_connection_t *tc)
format_function_t format_tcp_flags
u32 * ongoing_fast_rxt
vector of connections now doing fast rxt
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
u8 n_sack_blocks
Number of SACKs blocks.
struct _tcp_header tcp_header_t
int tcp_half_open_connection_cleanup(tcp_connection_t *tc)
Try to cleanup half-open connection.
u32 * pending_deq_acked
vector of pending ack dequeues
struct _sack_scoreboard_hole sack_scoreboard_hole_t
u8 wscale
Window scale advertised.
u32 transport_connection_tx_pacer_burst(transport_connection_t *tc, u64 time_now)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define tcp_fastrecovery_on(tc)
void session_transport_closing_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
#define TCP_TICK
TCP tick period (s)
static void tcp_connection_set_state(tcp_connection_t *tc, tcp_state_t state)
void tcp_init_snd_vars(tcp_connection_t *tc)
Initialize connection send variables.
#define VLIB_INIT_FUNCTION(x)
#define TCP_CLOSEWAIT_TIME
#define TCP_OPTION_LEN_SACK_BLOCK
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.
static tcp_header_t * tcp_buffer_hdr(vlib_buffer_t *b)
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
enum _tcp_state tcp_state_t
#define TCP_ALWAYS_ACK
On/off delayed acks.
vhost_vring_state_t state
static u32 ooo_segment_length(svm_fifo_t *f, ooo_segment_t *s)
static void * ip4_next_header(ip4_header_t *i)
static u32 tcp_time_now(void)
sack_block_t * sacks
SACK blocks.
#define vec_end(v)
End (last data address) of vector.
#define vlib_call_init_function(vm, x)
#define TCP_MAX_SACK_BLOCKS
Max number of SACK blocks stored.
#define tcp_validate_txf_size(_tc, _a)
#define TCP_EVT_DBG(_evt, _args...)
#define timestamp_lt(_t1, _t2)
static void tcp_timer_set(tcp_connection_t *tc, u8 timer_id, u32 interval)
#define TCP_OPTION_LEN_WINDOW_SCALE
static void svm_fifo_newest_ooo_segment_reset(svm_fifo_t *f)
static heap_elt_t * first(heap_header_t *h)
vlib_main_t * vm
convenience pointer to this thread's vlib main
#define TCP_INVALID_SACK_HOLE_INDEX
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u32 * postponed_fast_rxt
vector of connections that will do fast rxt
#define tcp_in_fastrecovery(tc)
void tcp_connection_tx_pacer_reset(tcp_connection_t *tc, u32 window, u32 start_bucket)
tcp_connection_t * tcp_connection_alloc(u8 thread_index)
static u32 ooo_segment_offset(svm_fifo_t *f, ooo_segment_t *s)
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 pool_put(P, E)
Free an object E in pool P.
#define TCP_TIMER_HANDLE_INVALID
#define vec_del1(v, i)
Delete the element at index I.
#define TCP_OPTION_LEN_TIMESTAMP
static ooo_segment_t * svm_fifo_newest_ooo_segment(svm_fifo_t *f)
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_MAX_WND_SCALE
static void tcp_timer_reset(tcp_connection_t *tc, u8 timer_id)
void tcp_connection_free(tcp_connection_t *tc)
#define VLIB_REGISTER_NODE(x,...)
#define CLIB_PREFETCH(addr, size, type)
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
void tcp_send_reset(tcp_connection_t *tc)
Build and set reset packet for connection.
#define TCP_DUPACK_THRESHOLD
format_function_t format_tcp_state
void tcp_program_ack(tcp_worker_ctx_t *wrk, tcp_connection_t *tc)
#define clib_warning(format, args...)
struct _transport_connection transport_connection_t
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
int session_stream_accept(transport_connection_t *tc, u32 listener_index, u8 notify)
Accept a stream session.
u16 mss
Option flags, see above.
static void * ip6_next_header(ip6_header_t *i)
static u32 transport_max_tx_dequeue(transport_connection_t *tc)
void tcp_send_synack(tcp_connection_t *tc)
static void tcp_timer_update(tcp_connection_t *tc, u8 timer_id, u32 interval)
#define TCP_PAWS_IDLE
24 days
#define tcp_fastrecovery_first_on(tc)
#define seq_geq(_s1, _s2)
static void transport_add_tx_event(transport_connection_t *tc)
#define vec_append(v1, v2)
Append v2 after v1.
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
static uword ip6_address_is_link_local_unicast(const ip6_address_t *a)
#define tcp_fastrecovery_first_off(tc)
int session_stream_accept_notify(transport_connection_t *tc)
static vlib_main_t * vlib_get_main(void)
static u32 tcp_time_now_w_thread(u32 thread_index)
static clib_error_t * tcp_init(vlib_main_t *vm)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define vec_elt(v, i)
Get vector value at index i.
void transport_connection_tx_pacer_update_bytes(transport_connection_t *tc, u32 bytes)
#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.
void tcp_connection_reset(tcp_connection_t *tc)
Notify session that connection has been reset.
u32 tsval
Timestamp value.
u32 tsecr
Echoed/reflected time stamp.
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 u8 tcp_is_lost_fin(tcp_connection_t *tc)
static tcp_worker_ctx_t * tcp_get_worker(u32 thread_index)
static void tcp_retransmit_timer_update(tcp_connection_t *tc)
VLIB buffer representation.
#define seq_max(_s1, _s2)
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.
int tcp_fast_retransmit(tcp_worker_ctx_t *wrk, tcp_connection_t *tc, u32 burst_size)
Do fast retransmit.
#define TCP_OPTION_LEN_MSS
#define tcp_disconnect_pending(tc)
struct clib_bihash_value offset
template key/value backing page structure
#define tcp_scoreboard_trace_add(_tc, _ack)
u8 * format_tcp_connection(u8 *s, va_list *args)
static tcp_connection_t * tcp_connection_get(u32 conn_index, u32 thread_index)
ip4_main_t ip4_main
Global ip4 main structure.
static int tcp_header_bytes(tcp_header_t *t)
int session_stream_connect_notify(transport_connection_t *tc, u8 is_fail)
#define tcp_disconnect_pending_off(tc)
static u32 vlib_num_workers()
void tcp_connection_cleanup(tcp_connection_t *tc)
Cleans up connection state.
u32 * pending_fast_rxt
vector of connections needing fast rxt
u16 flags
Copy of main node flags.
u32 session_tx_fifo_dequeue_drop(transport_connection_t *tc, u32 max_bytes)
#define tcp_opts_sack_permitted(_to)
static int ip4_header_bytes(const ip4_header_t *i)
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
#define CLIB_CACHE_LINE_BYTES
#define TCP_SYN_RCVD_TIME
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
static void tcp_persist_timer_set(tcp_connection_t *tc)
static tcp_main_t * vnet_get_tcp_main()
#define tcp_fastrecovery_off(tc)
static void tcp_retransmit_timer_reset(tcp_connection_t *tc)
void tcp_program_dupack(tcp_worker_ctx_t *wrk, tcp_connection_t *tc)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u32 tcp_set_time_now(tcp_worker_ctx_t *wrk)
static u32 transport_tx_fifo_size(transport_connection_t *tc)
static u8 tcp_timer_is_active(tcp_connection_t *tc, tcp_timers_e timer)
transport_connection_t * session_lookup_half_open_connection(u64 handle, u8 proto, u8 is_ip4)
static tcp_connection_t * tcp_listener_get(u32 tli)
static void tcp_persist_timer_reset(tcp_connection_t *tc)
static uword pool_elts(void *v)
Number of active elements in a pool.