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 \ 115 return (
seq_geq (end_seq, tc->rcv_las)
116 &&
seq_leq (seq, tc->rcv_nxt + tc->rcv_wnd));
130 u8 opt_len, opts_len, kind;
135 data = (
const u8 *) (th + 1);
138 to->
flags &= (TCP_OPTS_FLAG_SACK_PERMITTED | TCP_OPTS_FLAG_WSCALE);
140 for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
160 if (opt_len < 2 || opt_len > opts_len)
170 to->
flags |= TCP_OPTS_FLAG_MSS;
171 to->
mss = clib_net_to_host_u16 (*(
u16 *) (data + 2));
177 to->
flags |= TCP_OPTS_FLAG_WSCALE;
190 to->
flags |= TCP_OPTS_FLAG_TSTAMP;
191 to->
tsval = clib_net_to_host_u32 (*(
u32 *) (data + 2));
192 to->
tsecr = clib_net_to_host_u32 (*(
u32 *) (data + 6));
197 to->
flags |= TCP_OPTS_FLAG_SACK_PERMITTED;
201 if ((to->
flags & TCP_OPTS_FLAG_SACK_PERMITTED) == 0 ||
tcp_syn (th))
208 to->
flags |= TCP_OPTS_FLAG_SACK;
213 b.start = clib_net_to_host_u32 (*(
u32 *) (data + 2 + 8 * j));
214 b.end = clib_net_to_host_u32 (*(
u32 *) (data + 6 + 8 * j));
256 &&
seq_leq (tc->rcv_las, seq_end))
259 tc->tsval_recent = tc->rcv_opts.tsval;
305 tc0->tsval_recent = 0;
306 clib_warning (
"paws failed - really old segment. REALLY?");
327 if (tc0->rcv_wnd == 0
328 && tc0->rcv_nxt ==
vnet_buffer (b0)->tcp.seq_number)
358 if (tc0->state == TCP_STATE_SYN_RCVD)
402 err = mrtt - tc->srtt;
406 tc->srtt =
clib_max ((
int) tc->srtt + (err >> 3), 1);
407 diff = (
clib_abs (err) - (int) tc->rttvar) >> 2;
408 tc->rttvar =
clib_max ((
int) tc->rttvar + diff, 1);
414 tc->rttvar = mrtt >> 1;
446 if (tc->rtt_ts &&
seq_geq (ack, tc->rtt_seq))
485 tc->bytes_acked + tc->sack_sb.snd_una_adv);
504 return ((
vnet_buffer (b)->tcp.ack_number == prev_snd_una)
505 &&
seq_gt (tc->snd_una_max, tc->snd_una)
507 && (prev_snd_wnd == tc->snd_wnd));
515 u32 prev_snd_wnd,
u32 prev_snd_una,
u8 * is_dack)
519 *is_dack = tc->sack_sb.last_sacked_bytes
533 next->prev = hole->prev;
537 sb->tail = hole->prev;
543 prev->next = hole->next;
547 sb->head = hole->next;
555 memset (hole, 0xfe,
sizeof (*hole));
568 memset (hole, 0,
sizeof (*hole));
577 hole->prev = prev_index;
578 hole->next = prev->next;
581 next->prev = hole_index;
583 sb->tail = hole_index;
585 prev->next = hole_index;
589 sb->head = hole_index;
601 u32 bytes = 0, blks = 0;
604 sb->sacked_bytes = 0;
609 if (
seq_gt (sb->high_sacked, hole->end))
611 bytes = sb->high_sacked - hole->end;
619 bytes += hole->start - prev->end;
631 bytes += prev->start - hole->end;
633 sb->sacked_bytes = bytes;
645 u8 * can_rescue,
u8 * snd_limited)
650 while (hole &&
seq_leq (hole->end, sb->high_rxt) && hole->is_lost)
661 if (hole->is_lost &&
seq_lt (hole->start, sb->high_sacked))
668 if (!have_sent_1_smss)
674 else if (
seq_lt (hole->start, sb->high_sacked))
690 if (hole &&
seq_lt (sb->high_rxt, hole->start))
691 sb->high_rxt = hole->start;
703 seq =
seq_gt (seq, hole->start) ? seq : hole->start;
704 sb->cur_rxt_hole = sb->head;
720 return (!hole ||
seq_geq (hole->start, tc->snd_una));
729 u32 blk_index = 0, old_sacked_bytes, hole_index;
732 sb->last_sacked_bytes = 0;
734 old_sacked_bytes = sb->sacked_bytes;
735 sb->last_bytes_delivered = 0;
742 blk = tc->rcv_opts.sacks;
743 while (blk <
vec_end (tc->rcv_opts.sacks))
745 if (
seq_lt (blk->start, blk->end)
746 &&
seq_gt (blk->start, tc->snd_una)
747 &&
seq_gt (blk->start, ack) &&
seq_leq (blk->end, tc->snd_una_max))
752 vec_del1 (tc->rcv_opts.sacks, blk - tc->rcv_opts.sacks);
756 if (
seq_gt (ack, tc->snd_una))
758 tmp.start = tc->snd_una;
763 if (
vec_len (tc->rcv_opts.sacks) == 0)
769 for (i = 0; i <
vec_len (tc->rcv_opts.sacks); i++)
770 for (j = i + 1; j <
vec_len (tc->rcv_opts.sacks); j++)
771 if (
seq_lt (tc->rcv_opts.sacks[j].start, tc->rcv_opts.sacks[i].start))
773 tmp = tc->rcv_opts.sacks[
i];
774 tc->rcv_opts.sacks[
i] = tc->rcv_opts.sacks[j];
775 tc->rcv_opts.sacks[j] = tmp;
782 tc->snd_una, tc->snd_una_max);
784 tmp = tc->rcv_opts.sacks[
vec_len (tc->rcv_opts.sacks) - 1];
785 sb->high_sacked = tmp.end;
791 tmp = tc->rcv_opts.sacks[
vec_len (tc->rcv_opts.sacks) - 1];
793 if (
seq_gt (tc->snd_una_max, last_hole->end))
795 if (
seq_geq (last_hole->start, sb->high_sacked))
797 last_hole->end = tc->snd_una_max;
800 else if (
seq_lt (sb->high_sacked, tc->snd_una_max))
808 if (
seq_gt (tmp.end, sb->high_sacked))
809 sb->high_sacked = tmp.end;
814 while (hole && blk_index < vec_len (tc->rcv_opts.sacks))
816 blk = &tc->rcv_opts.sacks[blk_index];
817 if (
seq_leq (blk->start, hole->start))
820 if (
seq_geq (blk->end, hole->end))
829 if (
seq_lt (ack, next_hole->start))
830 sb->snd_una_adv = next_hole->start - ack;
831 sb->last_bytes_delivered +=
832 next_hole->start - hole->end;
837 sb->snd_una_adv = sb->high_sacked - ack;
838 sb->last_bytes_delivered += sb->high_sacked - hole->end;
848 if (
seq_gt (blk->end, hole->start))
850 hole->start = blk->end;
858 if (
seq_lt (blk->end, hole->end))
866 hole->end = blk->start;
870 else if (
seq_lt (blk->start, hole->end))
872 hole->end = blk->start;
879 sb->last_sacked_bytes = sb->sacked_bytes
880 - (old_sacked_bytes - sb->last_bytes_delivered);
881 ASSERT (sb->last_sacked_bytes <= sb->sacked_bytes);
882 ASSERT (sb->sacked_bytes == 0
883 || sb->sacked_bytes < tc->snd_una_max -
seq_max (tc->snd_una, ack));
884 ASSERT (sb->last_sacked_bytes + sb->lost_bytes <= tc->snd_una_max
887 || sb->holes[sb->head].start == ack + sb->snd_una_adv);
901 if (
seq_lt (tc->snd_wl1, seq)
902 || (tc->snd_wl1 == seq &&
seq_leq (tc->snd_wl2, ack)))
904 tc->snd_wnd = snd_wnd;
909 if (tc->snd_wnd < tc->snd_mss)
932 tc->snd_congestion = tc->snd_una_max;
933 tc->cc_algo->congestion (tc);
944 tc->snd_nxt = tc->snd_una_max;
952 tc->cc_algo->recovered (tc);
953 tc->snd_rxt_bytes = 0;
955 tc->snd_nxt = tc->snd_una_max;
964 tc->cwnd = tc->prev_cwnd;
965 tc->ssthresh = tc->prev_ssthresh;
966 tc->snd_nxt = tc->snd_una_max;
970 ASSERT (tc->rto_boff == 0);
999 ASSERT (tc->rto_boff == 0);
1011 tc->cc_algo->rcv_ack (tc);
1012 tc->tsecr_last_ack = tc->rcv_opts.tsecr;
1015 tc->rcv_dupacks = 0;
1022 (
seq_leq (tc->snd_congestion, tc->snd_una - tc->bytes_acked)
1023 &&
seq_gt (tc->snd_congestion, tc->snd_una)))
1024 tc->snd_congestion = tc->snd_una - 1;
1054 ASSERT (tc->snd_una != tc->snd_una_max
1055 || tc->sack_sb.last_sacked_bytes);
1071 tc->rcv_dupacks = 0;
1072 goto partial_ack_test;
1085 if (
seq_leq (tc->snd_una, tc->snd_congestion)
1086 && ((!(tc->cwnd > tc->snd_mss
1087 && tc->bytes_acked <= 4 * tc->snd_mss))
1088 || (tc->rcv_opts.tsecr != tc->tsecr_last_ack)))
1090 tc->rcv_dupacks = 0;
1103 tc->cwnd = tc->ssthresh + tc->rcv_dupacks * tc->snd_mss;
1104 ASSERT (tc->cwnd >= tc->snd_mss);
1110 tc->snd_una + tc->snd_mss);
1120 else if (!tc->bytes_acked
1132 if (!tc->bytes_acked)
1142 if (
seq_geq (tc->snd_una, tc->snd_congestion))
1147 tc->tsecr_last_ack = tc->rcv_opts.tsecr;
1151 tc->snd_nxt = tc->snd_una_max;
1154 tc->cc_algo->rcv_ack (tc);
1155 tc->tsecr_last_ack = tc->rcv_opts.tsecr;
1166 tc->rcv_dupacks = 0;
1175 ASSERT (tc->bytes_acked + tc->sack_sb.snd_una_adv
1176 >= tc->sack_sb.last_bytes_delivered
1177 || (tc->flags & TCP_CONN_FINSNT));
1179 if (
seq_lt (tc->snd_una, tc->sack_sb.high_rxt))
1183 rxt_delivered = tc->bytes_acked + tc->sack_sb.snd_una_adv
1184 - tc->sack_sb.last_bytes_delivered;
1185 ASSERT (tc->snd_rxt_bytes >= rxt_delivered);
1186 tc->snd_rxt_bytes -= rxt_delivered;
1192 tc->snd_rxt_bytes = 0;
1207 tc->cc_algo->init (tc);
1217 u32 prev_snd_wnd, prev_snd_una;
1232 *error = TCP_ERROR_ACK_INVALID;
1242 *error = TCP_ERROR_ACK_FUTURE;
1248 *error = TCP_ERROR_ACK_OLD;
1267 prev_snd_wnd = tc->snd_wnd;
1268 prev_snd_una = tc->snd_una;
1271 clib_net_to_host_u16 (th->window) << tc->snd_wscale);
1272 tc->bytes_acked =
vnet_buffer (b)->tcp.ack_number - tc->snd_una;
1273 tc->snd_una =
vnet_buffer (b)->tcp.ack_number + tc->sack_sb.snd_una_adv;
1276 if (tc->bytes_acked)
1290 *error = TCP_ERROR_ACK_DUP;
1307 for (i = 1; i <
vec_len (sacks); i++)
1309 if (sacks[i - 1].end == sacks[i].start)
1334 if (
seq_lt (tc->rcv_nxt, start))
1337 block->start = start;
1342 for (i = 0; i <
vec_len (tc->snd_sacks); i++)
1345 if (
seq_leq (tc->snd_sacks[i].start, tc->rcv_nxt))
1349 if (block && (
seq_geq (tc->snd_sacks[i].end, new_list[0].start)
1350 &&
seq_leq (tc->snd_sacks[i].start, new_list[0].end)))
1352 if (
seq_lt (tc->snd_sacks[i].start, new_list[0].start))
1353 new_list[0].start = tc->snd_sacks[i].start;
1354 if (
seq_lt (new_list[0].end, tc->snd_sacks[i].end))
1355 new_list[0].end = tc->snd_sacks[i].end;
1362 vec_add1 (new_list, tc->snd_sacks[i]);
1374 tc->snd_sacks = new_list;
1385 int written, error = TCP_ERROR_ENQUEUED;
1392 return TCP_ERROR_PURE_ACK;
1398 TCP_EVT_DBG (TCP_EVT_INPUT, tc, 0, data_len, written);
1403 tc->rcv_nxt += written;
1406 else if (written > data_len)
1408 tc->rcv_nxt += written;
1411 tc->flags |= TCP_CONN_SNDACK;
1413 else if (written > 0)
1416 tc->rcv_nxt += written;
1420 tc->flags |= TCP_CONN_SNDACK;
1422 error = TCP_ERROR_PARTIALLY_ENQUEUED;
1426 tc->flags |= TCP_CONN_SNDACK;
1427 return TCP_ERROR_FIFO_FULL;
1453 return TCP_ERROR_PURE_ACK;
1466 return TCP_ERROR_FIFO_FULL;
1469 TCP_EVT_DBG (TCP_EVT_INPUT, tc, 1, data_len, data_len);
1477 s0 =
session_get (tc->c_s_index, tc->c_thread_index);
1485 start = tc->rcv_nxt +
offset;
1492 return TCP_ERROR_ENQUEUED;
1505 || (tc->flags & TCP_CONN_SENT_RCV_WND0) != 0
1507 || (tc->flags & TCP_CONN_SNDACK) != 0
1531 n_bytes_to_drop -= discard;
1533 while (n_bytes_to_drop);
1534 if (n_bytes_to_drop > first)
1547 u32 error = 0, n_bytes_to_drop, n_data_bytes;
1560 error = TCP_ERROR_SEGMENT_OLD;
1573 n_bytes_to_drop = tc->rcv_nxt -
vnet_buffer (b)->tcp.seq_number;
1574 n_data_bytes -= n_bytes_to_drop;
1638 s =
format (s,
"%U\n%U%U",
1653 s =
format (s,
"%d -> %d (%U)",
1654 clib_net_to_host_u16 (t->
tcp_header.src_port),
1678 u8 is_ip4,
u8 evt,
u8 val)
1693 u32 n_left_from, next_index, *from, *to_next;
1703 while (n_left_from > 0)
1708 while (n_left_from > 0 && n_left_to_next > 0)
1721 n_left_to_next -= 1;
1729 error0 = TCP_ERROR_INVALID_CONNECTION;
1747 error0 = TCP_ERROR_SEGMENT_INVALID;
1774 tc0->state = TCP_STATE_CLOSE_WAIT;
1790 n_left_to_next, bi0, next0);
1800 TCP_ERROR_EVENT_FIFO_FULL, errors);
1824 .name =
"tcp4-established",
1826 .vector_size =
sizeof (
u32),
1832 #define _(s,n) [TCP_ESTABLISHED_NEXT_##s] = n, 1846 .name =
"tcp6-established",
1848 .vector_size =
sizeof (
u32),
1854 #define _(s,n) [TCP_ESTABLISHED_NEXT_##s] = n, 1878 if (tc->c_lcl_port == 0 && tc->state == TCP_STATE_LISTEN)
1881 u8 is_valid = (tc->c_lcl_port == hdr->dst_port
1882 && (tc->state == TCP_STATE_LISTEN
1883 || tc->c_rmt_port == hdr->src_port));
1889 tc->c_proto, tc->c_is_ip4);
1893 if (tmp->lcl_port == hdr->dst_port
1894 && tmp->rmt_port == hdr->src_port)
1896 TCP_DBG (
"half-open is valid!");
1925 thread_index, &is_filtered);
1940 thread_index, &is_filtered);
1952 u32 n_left_from, next_index, *from, *to_next;
1960 while (n_left_from > 0)
1966 while (n_left_from > 0 && n_left_to_next > 0)
1968 u32 bi0, ack0, seq0;
1981 n_left_to_next -= 1;
1986 tcp.connection_index);
1989 error0 = TCP_ERROR_INVALID_CONNECTION;
1999 my_thread_index, is_ip4));
2010 || tcp0->src_port != tc0->c_rmt_port))
2035 if (
seq_leq (ack0, tc0->iss) ||
seq_gt (ack0, tc0->snd_nxt))
2044 if (
seq_gt (tc0->snd_una, ack0))
2088 pool_get (tm->connections[my_thread_index], new_tc0);
2090 new_tc0->c_c_index = new_tc0 - tm->connections[my_thread_index];
2091 new_tc0->c_thread_index = my_thread_index;
2093 new_tc0->irs = seq0;
2095 new_tc0->timers[TCP_TIMER_RETRANSMIT_SYN] =
2101 tc0->flags |= TCP_CONN_HALF_OPEN_DONE;
2105 new_tc0->tsval_recent = new_tc0->rcv_opts.tsval;
2110 new_tc0->snd_wscale = new_tc0->rcv_opts.wscale;
2113 new_tc0->snd_wnd = clib_net_to_host_u16 (tcp0->window);
2114 new_tc0->snd_wl1 = seq0;
2115 new_tc0->snd_wl2 = ack0;
2125 new_tc0->snd_una = ack0;
2126 new_tc0->state = TCP_STATE_ESTABLISHED;
2129 new_tc0->rcv_las = new_tc0->rcv_nxt;
2142 new_tc0->flags |= TCP_CONN_SNDACK;
2151 new_tc0->state = TCP_STATE_SYN_RCVD;
2175 if (error0 == TCP_ERROR_PURE_ACK)
2176 error0 = TCP_ERROR_SYN_ACKS_RCVD;
2197 n_left_to_next, bi0, next0);
2207 TCP_ERROR_EVENT_FIFO_FULL, errors);
2229 .name =
"tcp4-syn-sent",
2231 .vector_size =
sizeof (
u32),
2237 #define _(s,n) [TCP_SYN_SENT_NEXT_##s] = n, 2251 .name =
"tcp6-syn-sent",
2253 .vector_size =
sizeof (
u32),
2259 #define _(s,n) [TCP_SYN_SENT_NEXT_##s] = n, 2281 u32 n_left_from, next_index, *from, *to_next;
2289 while (n_left_from > 0)
2295 while (n_left_from > 0 && n_left_to_next > 0)
2309 n_left_to_next -= 1;
2316 error0 = TCP_ERROR_INVALID_CONNECTION;
2333 if (tmp->state != tc0->state)
2346 case TCP_STATE_CLOSED:
2359 error0 = TCP_ERROR_SEGMENT_INVALID;
2366 case TCP_STATE_SYN_RCVD:
2375 TCP_DBG (
"connection not accepted");
2384 tc0->state = TCP_STATE_ESTABLISHED;
2388 tc0->snd_wnd = clib_net_to_host_u16 (tcp0->window)
2389 << tc0->rcv_opts.wscale;
2399 case TCP_STATE_ESTABLISHED:
2406 case TCP_STATE_FIN_WAIT_1:
2414 if (tc0->flags & TCP_CONN_FINPNDG)
2421 else if (tc0->snd_una == tc0->snd_una_max)
2423 tc0->state = TCP_STATE_FIN_WAIT_2;
2433 case TCP_STATE_FIN_WAIT_2:
2440 case TCP_STATE_CLOSE_WAIT:
2445 case TCP_STATE_CLOSING:
2452 tc0->state = TCP_STATE_TIME_WAIT;
2458 case TCP_STATE_LAST_ACK:
2465 error0 = TCP_ERROR_ACK_INVALID;
2471 if (is_fin0 && tc0->snd_una != tc0->snd_una_max)
2477 tc0->state = TCP_STATE_CLOSED;
2490 case TCP_STATE_TIME_WAIT:
2514 case TCP_STATE_ESTABLISHED:
2515 case TCP_STATE_FIN_WAIT_1:
2516 case TCP_STATE_FIN_WAIT_2:
2522 case TCP_STATE_CLOSE_WAIT:
2523 case TCP_STATE_CLOSING:
2524 case TCP_STATE_LAST_ACK:
2525 case TCP_STATE_TIME_WAIT:
2537 case TCP_STATE_ESTABLISHED:
2538 case TCP_STATE_SYN_RCVD:
2545 tc0->state = TCP_STATE_CLOSE_WAIT;
2548 case TCP_STATE_CLOSE_WAIT:
2549 case TCP_STATE_CLOSING:
2550 case TCP_STATE_LAST_ACK:
2553 case TCP_STATE_FIN_WAIT_1:
2554 tc0->state = TCP_STATE_CLOSING;
2561 case TCP_STATE_FIN_WAIT_2:
2563 tc0->state = TCP_STATE_TIME_WAIT;
2570 case TCP_STATE_TIME_WAIT:
2590 n_left_to_next, bi0, next0);
2600 TCP_ERROR_EVENT_FIFO_FULL, errors);
2623 .name =
"tcp4-rcv-process",
2625 .vector_size =
sizeof (
u32),
2631 #define _(s,n) [TCP_RCV_PROCESS_NEXT_##s] = n, 2645 .name =
"tcp6-rcv-process",
2647 .vector_size =
sizeof (
u32),
2653 #define _(s,n) [TCP_RCV_PROCESS_NEXT_##s] = n, 2673 u32 n_left_from, next_index, *from, *to_next;
2681 while (n_left_from > 0)
2687 while (n_left_from > 0 && n_left_to_next > 0)
2704 n_left_to_next -= 1;
2741 error0 = TCP_ERROR_CREATE_EXISTS;
2747 child0->c_lcl_port = th0->dst_port;
2748 child0->c_rmt_port = th0->src_port;
2749 child0->c_is_ip4 = is_ip4;
2750 child0->state = TCP_STATE_SYN_RCVD;
2772 child0->rcv_nxt =
vnet_buffer (b0)->tcp.seq_number + 1;
2773 child0->rcv_las = child0->rcv_nxt;
2779 child0->tsval_recent = child0->rcv_opts.tsval;
2784 child0->snd_wscale = child0->rcv_opts.wscale;
2786 child0->snd_wnd = clib_net_to_host_u16 (th0->window)
2787 << child0->snd_wscale;
2788 child0->snd_wl1 =
vnet_buffer (b0)->tcp.seq_number;
2789 child0->snd_wl2 =
vnet_buffer (b0)->tcp.ack_number;
2799 error0 = TCP_ERROR_CREATE_SESSION_FAIL;
2820 n_left_to_next, bi0, next0);
2846 .name =
"tcp4-listen",
2848 .vector_size =
sizeof (
u32),
2854 #define _(s,n) [TCP_LISTEN_NEXT_##s] = n, 2868 .name =
"tcp6-listen",
2870 .vector_size =
sizeof (
u32),
2876 #define _(s,n) [TCP_LISTEN_NEXT_##s] = n, 2889 typedef enum _tcp_input_next
2901 #define foreach_tcp4_input_next \ 2902 _ (DROP, "ip4-drop") \ 2903 _ (LISTEN, "tcp4-listen") \ 2904 _ (RCV_PROCESS, "tcp4-rcv-process") \ 2905 _ (SYN_SENT, "tcp4-syn-sent") \ 2906 _ (ESTABLISHED, "tcp4-established") \ 2907 _ (RESET, "tcp4-reset") \ 2908 _ (PUNT, "ip4-punt") 2910 #define foreach_tcp6_input_next \ 2911 _ (DROP, "ip6-drop") \ 2912 _ (LISTEN, "tcp6-listen") \ 2913 _ (RCV_PROCESS, "tcp6-rcv-process") \ 2914 _ (SYN_SENT, "tcp6-syn-sent") \ 2915 _ (ESTABLISHED, "tcp6-established") \ 2916 _ (RESET, "tcp6-reset") \ 2917 _ (PUNT, "ip6-punt") 2919 #define filter_flags (TCP_FLAG_SYN|TCP_FLAG_ACK|TCP_FLAG_RST|TCP_FLAG_FIN) 2925 u32 n_left_from, next_index, *from, *to_next;
2934 while (n_left_from > 0)
2940 while (n_left_from > 0 && n_left_to_next > 0)
2942 int n_advance_bytes0, n_data_bytes0;
2943 u32 bi0, fib_index0;
2951 u8 flags0, is_filtered = 0;
2958 n_left_to_next -= 1;
2972 n_data_bytes0 = clib_net_to_host_u16 (ip40->
length)
2990 n_advance_bytes0 +=
sizeof (ip60[0]);
3004 error0 = TCP_ERROR_LENGTH;
3018 vnet_buffer (b0)->tcp.connection_index = tc0->c_c_index;
3020 clib_net_to_host_u32 (tcp0->seq_number);
3022 clib_net_to_host_u32 (tcp0->ack_number);
3024 vnet_buffer (b0)->tcp.data_offset = n_advance_bytes0;
3028 next0 = tm->dispatch_table[tc0->state][flags0].next;
3029 error0 = tm->dispatch_table[tc0->state][flags0].error;
3038 if (error0 == TCP_ERROR_DISPATCH)
3049 error0 = TCP_ERROR_FILTERED;
3051 else if ((is_ip4 && tm->punt_unknown4) ||
3052 (!is_ip4 && tm->punt_unknown6))
3055 error0 = TCP_ERROR_PUNT;
3061 error0 = TCP_ERROR_NO_LISTENER;
3076 n_left_to_next, bi0, next0);
3103 .name =
"tcp4-input",
3105 .vector_size =
sizeof (
u32),
3111 #define _(s,n) [TCP_INPUT_NEXT_##s] = n, 3126 .name =
"tcp6-input",
3128 .vector_size =
sizeof (
u32),
3134 #define _(s,n) [TCP_INPUT_NEXT_##s] = n, 3149 for (i = 0; i <
ARRAY_LEN (tm->dispatch_table); i++)
3150 for (j = 0; j <
ARRAY_LEN (tm->dispatch_table[i]); j++)
3153 tm->dispatch_table[
i][j].error = TCP_ERROR_DISPATCH;
3156 #define _(t,f,n,e) \ 3158 tm->dispatch_table[TCP_STATE_##t][f].next = (n); \ 3159 tm->dispatch_table[TCP_STATE_##t][f].error = (e); \ 3219 TCP_ERROR_CONNECTION_CLOSED);
#define tcp_in_cong_recovery(tc)
sll srl srl sll sra u16x4 i
#define tcp_fastrecovery_1_smss_off(tc)
#define tcp_in_recovery(tc)
#define TCP_OPTION_LEN_SACK_PERMITTED
#define seq_leq(_s1, _s2)
void tcp_make_fin(tcp_connection_t *tc, vlib_buffer_t *b)
Convert buffer to FIN-ACK.
struct _sack_block sack_block_t
#define timestamp_leq(_t1, _t2)
struct _transport_connection transport_connection_t
#define TCP_TIMEWAIT_TIME
#define tcp_opts_tstamp(_to)
void tcp_fast_retransmit(tcp_connection_t *tc)
Do fast retransmit.
tcp_connection_t * tcp_connection_new(u8 thread_index)
static int ip4_header_bytes(ip4_header_t *i)
struct _sack_scoreboard sack_scoreboard_t
static tcp_connection_t * tcp_half_open_connection_get(u32 conn_index)
struct _tcp_main tcp_main_t
void tcp_connection_timers_reset(tcp_connection_t *tc)
Stop all connection timers.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define tcp_recovery_off(tc)
struct _vlib_node_registration vlib_node_registration_t
static sack_scoreboard_hole_t * scoreboard_prev_hole(sack_scoreboard_t *sb, sack_scoreboard_hole_t *hole)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
struct _tcp_connection tcp_connection_t
#define tcp_opts_sack(_to)
void tcp_fast_retransmit_sack(tcp_connection_t *tc)
Do fast retransmit with SACKs.
tcp_connection_t tcp_connection
static tcp_connection_t * tcp_get_connection_from_transport(transport_connection_t *tconn)
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)
void tcp_send_reset_w_pkt(tcp_connection_t *tc, vlib_buffer_t *pkt, u8 is_ip4)
Send reset without reusing existing buffer.
vlib_error_t * errors
Vector of errors for this node.
format_function_t format_tcp_flags
#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
static u32 tcp_available_snd_space(const tcp_connection_t *tc)
Estimate of how many bytes we can still push into the network.
int tcp_half_open_connection_cleanup(tcp_connection_t *tc)
Try to cleanup half-open connection.
struct _sack_scoreboard_hole sack_scoreboard_hole_t
u8 wscale
Window scale advertised.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define tcp_fastrecovery_on(tc)
void tcp_flush_frame_to_output(vlib_main_t *vm, u8 thread_index, u8 is_ip4)
Flush tx frame populated by retransmits and timer pops.
#define VLIB_BUFFER_NEXT_PRESENT
static u32 scoreboard_hole_index(sack_scoreboard_t *sb, sack_scoreboard_hole_t *hole)
void tcp_init_snd_vars(tcp_connection_t *tc)
Initialize connection send variables.
#define VLIB_INIT_FUNCTION(x)
#define TCP_CLOSEWAIT_TIME
void stream_session_accept_notify(transport_connection_t *tc)
#define TCP_OPTION_LEN_SACK_BLOCK
static tcp_header_t * tcp_buffer_hdr(vlib_buffer_t *b)
enum _tcp_state tcp_state_t
#define TCP_ALWAYS_ACK
On/off delayed acks.
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.
static tcp_cc_algorithm_t * tcp_cc_algo_get(tcp_cc_algorithm_type_e type)
static u32 scoreboard_hole_bytes(sack_scoreboard_hole_t *hole)
struct _stream_session_t stream_session_t
#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)
u32 stream_session_dequeue_drop(transport_connection_t *tc, u32 max_bytes)
#define TCP_INVALID_SACK_HOLE_INDEX
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 current_length
Nbytes between current data and the end of this buffer.
#define tcp_in_fastrecovery(tc)
void tcp_retransmit_first_unacked(tcp_connection_t *tc)
Retransmit first unacked segment.
static sack_scoreboard_hole_t * scoreboard_next_hole(sack_scoreboard_t *sb, sack_scoreboard_hole_t *hole)
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.
#define pool_put(P, E)
Free an object E in pool P.
#define TCP_TIMER_HANDLE_INVALID
void tcp_fast_retransmit_no_sack(tcp_connection_t *tc)
Fast retransmit without SACK info.
#define vec_del1(v, i)
Delete the element at index I.
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
static sack_scoreboard_hole_t * scoreboard_last_hole(sack_scoreboard_t *sb)
int stream_session_accept(transport_connection_t *tc, u32 listener_index, u8 notify)
Accept a stream session.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
#define TCP_OPTION_LEN_TIMESTAMP
static ooo_segment_t * svm_fifo_newest_ooo_segment(svm_fifo_t *f)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
static stream_session_t * session_get(u32 si, u32 thread_index)
#define TCP_DBG(_fmt, _args...)
#define TCP_MAX_WND_SCALE
static void tcp_timer_reset(tcp_connection_t *tc, u8 timer_id)
static sack_scoreboard_hole_t * scoreboard_first_hole(sack_scoreboard_t *sb)
u32 stream_session_tx_fifo_max_dequeue(transport_connection_t *tc)
#define vec_free(V)
Free vector's memory (no header).
#define TCP_DUPACK_THRESHOLD
format_function_t format_tcp_state
#define clib_warning(format, args...)
#define VLIB_BUFFER_IS_TRACED
#define clib_memcpy(a, b, c)
void tcp_make_synack(tcp_connection_t *ts, vlib_buffer_t *b)
Convert buffer to SYN-ACK.
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
u16 mss
Option flags, see above.
static void * ip6_next_header(ip6_header_t *i)
void tcp_make_ack(tcp_connection_t *ts, vlib_buffer_t *b)
Convert buffer to ACK.
void stream_session_disconnect_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
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 *is_filtered)
Lookup connection with ip4 and transport layer information.
static void tcp_timer_update(tcp_connection_t *tc, u8 timer_id, u32 interval)
#define TCP_PAWS_IDLE
24 days
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
#define seq_geq(_s1, _s2)
u32 next_buffer
Next buffer for this linked-list of buffers.
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
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 *is_filtered)
Lookup connection with ip6 and transport layer information.
static vlib_main_t * vlib_get_main(void)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
#define tcp_opts_wscale(_to)
static sack_scoreboard_hole_t * scoreboard_get_hole(sack_scoreboard_t *sb, u32 index)
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)
static u32 tcp_set_time_now(u32 thread_index)
static u8 tcp_is_lost_fin(tcp_connection_t *tc)
static void tcp_retransmit_timer_update(tcp_connection_t *tc)
#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.
#define TCP_OPTION_LEN_MSS
clib_error_t * tcp_init(vlib_main_t *vm)
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)
int session_manager_flush_enqueue_events(u8 transport_proto, u32 thread_index)
Flushes queue of sessions that are to be notified of new data enqueued events.
static tcp_connection_t * tcp_connection_get(u32 conn_index, u32 thread_index)
#define VLIB_REGISTER_NODE(x,...)
static int tcp_header_bytes(tcp_header_t *t)
int session_stream_connect_notify(transport_connection_t *tc, u8 is_fail)
void tcp_connection_cleanup(tcp_connection_t *tc)
Cleans up connection state.
#define tcp_opts_sack_permitted(_to)
#define TCP_SYN_RCVD_TIME
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
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)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
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)