Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vnet/tcp/tcp.h> |
| 17 | #include <vnet/lisp-cp/packets.h> |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 18 | #include <math.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 19 | |
| 20 | vlib_node_registration_t tcp4_output_node; |
| 21 | vlib_node_registration_t tcp6_output_node; |
| 22 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 23 | typedef enum _tcp_output_next |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 24 | { |
| 25 | TCP_OUTPUT_NEXT_DROP, |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 26 | TCP_OUTPUT_NEXT_IP_LOOKUP, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 27 | TCP_OUTPUT_N_NEXT |
| 28 | } tcp_output_next_t; |
| 29 | |
| 30 | #define foreach_tcp4_output_next \ |
| 31 | _ (DROP, "error-drop") \ |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 32 | _ (IP_LOOKUP, "ip4-lookup") |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 33 | |
| 34 | #define foreach_tcp6_output_next \ |
| 35 | _ (DROP, "error-drop") \ |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 36 | _ (IP_LOOKUP, "ip6-lookup") |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 37 | |
| 38 | static char *tcp_error_strings[] = { |
| 39 | #define tcp_error(n,s) s, |
| 40 | #include <vnet/tcp/tcp_error.def> |
| 41 | #undef tcp_error |
| 42 | }; |
| 43 | |
| 44 | typedef struct |
| 45 | { |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 46 | tcp_header_t tcp_header; |
| 47 | tcp_connection_t tcp_connection; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 48 | } tcp_tx_trace_t; |
| 49 | |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 50 | u16 dummy_mtu = 1460; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 51 | |
| 52 | u8 * |
| 53 | format_tcp_tx_trace (u8 * s, va_list * args) |
| 54 | { |
| 55 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 56 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 57 | tcp_tx_trace_t *t = va_arg (*args, tcp_tx_trace_t *); |
| 58 | uword indent = format_get_indent (s); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 59 | |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 60 | s = format (s, "%U\n%U%U", |
| 61 | format_tcp_header, &t->tcp_header, 128, |
| 62 | format_white_space, indent, |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 63 | format_tcp_connection, &t->tcp_connection, 1); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 64 | |
| 65 | return s; |
| 66 | } |
| 67 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 68 | static u8 |
| 69 | tcp_window_compute_scale (u32 available_space) |
| 70 | { |
| 71 | u8 wnd_scale = 0; |
| 72 | while (wnd_scale < TCP_MAX_WND_SCALE |
| 73 | && (available_space >> wnd_scale) > TCP_WND_MAX) |
| 74 | wnd_scale++; |
| 75 | return wnd_scale; |
| 76 | } |
| 77 | |
| 78 | /** |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 79 | * Update max segment size we're able to process. |
| 80 | * |
| 81 | * The value is constrained by our interface's MTU and IP options. It is |
| 82 | * also what we advertise to our peer. |
| 83 | */ |
| 84 | void |
| 85 | tcp_update_rcv_mss (tcp_connection_t * tc) |
| 86 | { |
| 87 | /* TODO find our iface MTU */ |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 88 | tc->mss = dummy_mtu - sizeof (tcp_header_t); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * TCP's initial window |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 93 | */ |
| 94 | always_inline u32 |
| 95 | tcp_initial_wnd_unscaled (tcp_connection_t * tc) |
| 96 | { |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 97 | /* RFC 6928 recommends the value lower. However at the time our connections |
| 98 | * are initialized, fifos may not be allocated. Therefore, advertise the |
| 99 | * smallest possible unscaled window size and update once fifos are |
| 100 | * assigned to the session. |
| 101 | */ |
| 102 | /* |
| 103 | tcp_update_rcv_mss (tc); |
| 104 | TCP_IW_N_SEGMENTS * tc->mss; |
| 105 | */ |
| 106 | return TCP_MIN_RX_FIFO_SIZE; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /** |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 110 | * Compute initial window and scale factor. As per RFC1323, window field in |
| 111 | * SYN and SYN-ACK segments is never scaled. |
| 112 | */ |
| 113 | u32 |
| 114 | tcp_initial_window_to_advertise (tcp_connection_t * tc) |
| 115 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 116 | u32 max_fifo; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 117 | |
| 118 | /* Initial wnd for SYN. Fifos are not allocated yet. |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 119 | * Use some predefined value. For SYN-ACK we still want the |
| 120 | * scale to be computed in the same way */ |
| 121 | max_fifo = TCP_MAX_RX_FIFO_SIZE; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 122 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 123 | tc->rcv_wscale = tcp_window_compute_scale (max_fifo); |
| 124 | tc->rcv_wnd = tcp_initial_wnd_unscaled (tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 125 | |
| 126 | return clib_min (tc->rcv_wnd, TCP_WND_MAX); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Compute and return window to advertise, scaled as per RFC1323 |
| 131 | */ |
| 132 | u32 |
| 133 | tcp_window_to_advertise (tcp_connection_t * tc, tcp_state_t state) |
| 134 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 135 | if (state < TCP_STATE_ESTABLISHED) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 136 | return tcp_initial_window_to_advertise (tc); |
| 137 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 138 | tcp_update_rcv_wnd (tc); |
| 139 | |
| 140 | if (tc->rcv_wnd == 0) |
| 141 | { |
| 142 | tc->flags |= TCP_CONN_SENT_RCV_WND0; |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | tc->flags &= ~TCP_CONN_SENT_RCV_WND0; |
| 147 | } |
| 148 | |
| 149 | return tc->rcv_wnd >> tc->rcv_wscale; |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | tcp_update_rcv_wnd (tcp_connection_t * tc) |
| 154 | { |
| 155 | i32 observed_wnd; |
| 156 | u32 available_space, max_fifo, wnd; |
| 157 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 158 | /* |
| 159 | * Figure out how much space we have available |
| 160 | */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 161 | available_space = stream_session_max_rx_enqueue (&tc->connection); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 162 | max_fifo = stream_session_rx_fifo_size (&tc->connection); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 163 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 164 | ASSERT (tc->rcv_opts.mss < max_fifo); |
| 165 | if (available_space < tc->rcv_opts.mss && available_space < max_fifo >> 3) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 166 | available_space = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 167 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 168 | /* |
| 169 | * Use the above and what we know about what we've previously advertised |
| 170 | * to compute the new window |
| 171 | */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 172 | observed_wnd = (i32) tc->rcv_wnd - (tc->rcv_nxt - tc->rcv_las); |
| 173 | if (observed_wnd < 0) |
| 174 | observed_wnd = 0; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 175 | |
| 176 | /* Bad. Thou shalt not shrink */ |
| 177 | if (available_space < observed_wnd) |
| 178 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 179 | wnd = observed_wnd; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 180 | TCP_EVT_DBG (TCP_EVT_RCV_WND_SHRUNK, tc, observed_wnd, available_space); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 181 | } |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 182 | else |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 183 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 184 | wnd = available_space; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 187 | /* Make sure we have a multiple of rcv_wscale */ |
| 188 | if (wnd && tc->rcv_wscale) |
| 189 | { |
| 190 | wnd &= ~(1 << tc->rcv_wscale); |
| 191 | if (wnd == 0) |
| 192 | wnd = 1 << tc->rcv_wscale; |
| 193 | } |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 194 | |
| 195 | tc->rcv_wnd = clib_min (wnd, TCP_WND_MAX << tc->rcv_wscale); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Write TCP options to segment. |
| 200 | */ |
| 201 | u32 |
| 202 | tcp_options_write (u8 * data, tcp_options_t * opts) |
| 203 | { |
| 204 | u32 opts_len = 0; |
| 205 | u32 buf, seq_len = 4; |
| 206 | |
| 207 | if (tcp_opts_mss (opts)) |
| 208 | { |
| 209 | *data++ = TCP_OPTION_MSS; |
| 210 | *data++ = TCP_OPTION_LEN_MSS; |
| 211 | buf = clib_host_to_net_u16 (opts->mss); |
| 212 | clib_memcpy (data, &buf, sizeof (opts->mss)); |
| 213 | data += sizeof (opts->mss); |
| 214 | opts_len += TCP_OPTION_LEN_MSS; |
| 215 | } |
| 216 | |
| 217 | if (tcp_opts_wscale (opts)) |
| 218 | { |
| 219 | *data++ = TCP_OPTION_WINDOW_SCALE; |
| 220 | *data++ = TCP_OPTION_LEN_WINDOW_SCALE; |
| 221 | *data++ = opts->wscale; |
| 222 | opts_len += TCP_OPTION_LEN_WINDOW_SCALE; |
| 223 | } |
| 224 | |
| 225 | if (tcp_opts_sack_permitted (opts)) |
| 226 | { |
| 227 | *data++ = TCP_OPTION_SACK_PERMITTED; |
| 228 | *data++ = TCP_OPTION_LEN_SACK_PERMITTED; |
| 229 | opts_len += TCP_OPTION_LEN_SACK_PERMITTED; |
| 230 | } |
| 231 | |
| 232 | if (tcp_opts_tstamp (opts)) |
| 233 | { |
| 234 | *data++ = TCP_OPTION_TIMESTAMP; |
| 235 | *data++ = TCP_OPTION_LEN_TIMESTAMP; |
| 236 | buf = clib_host_to_net_u32 (opts->tsval); |
| 237 | clib_memcpy (data, &buf, sizeof (opts->tsval)); |
| 238 | data += sizeof (opts->tsval); |
| 239 | buf = clib_host_to_net_u32 (opts->tsecr); |
| 240 | clib_memcpy (data, &buf, sizeof (opts->tsecr)); |
| 241 | data += sizeof (opts->tsecr); |
| 242 | opts_len += TCP_OPTION_LEN_TIMESTAMP; |
| 243 | } |
| 244 | |
| 245 | if (tcp_opts_sack (opts)) |
| 246 | { |
| 247 | int i; |
| 248 | u32 n_sack_blocks = clib_min (vec_len (opts->sacks), |
| 249 | TCP_OPTS_MAX_SACK_BLOCKS); |
| 250 | |
| 251 | if (n_sack_blocks != 0) |
| 252 | { |
| 253 | *data++ = TCP_OPTION_SACK_BLOCK; |
| 254 | *data++ = 2 + n_sack_blocks * TCP_OPTION_LEN_SACK_BLOCK; |
| 255 | for (i = 0; i < n_sack_blocks; i++) |
| 256 | { |
| 257 | buf = clib_host_to_net_u32 (opts->sacks[i].start); |
| 258 | clib_memcpy (data, &buf, seq_len); |
| 259 | data += seq_len; |
| 260 | buf = clib_host_to_net_u32 (opts->sacks[i].end); |
| 261 | clib_memcpy (data, &buf, seq_len); |
| 262 | data += seq_len; |
| 263 | } |
| 264 | opts_len += 2 + n_sack_blocks * TCP_OPTION_LEN_SACK_BLOCK; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /* Terminate TCP options */ |
| 269 | if (opts_len % 4) |
| 270 | { |
| 271 | *data++ = TCP_OPTION_EOL; |
| 272 | opts_len += TCP_OPTION_LEN_EOL; |
| 273 | } |
| 274 | |
| 275 | /* Pad with zeroes to a u32 boundary */ |
| 276 | while (opts_len % 4) |
| 277 | { |
| 278 | *data++ = TCP_OPTION_NOOP; |
| 279 | opts_len += TCP_OPTION_LEN_NOOP; |
| 280 | } |
| 281 | return opts_len; |
| 282 | } |
| 283 | |
| 284 | always_inline int |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 285 | tcp_make_syn_options (tcp_options_t * opts, u8 wnd_scale) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 286 | { |
| 287 | u8 len = 0; |
| 288 | |
| 289 | opts->flags |= TCP_OPTS_FLAG_MSS; |
| 290 | opts->mss = dummy_mtu; /*XXX discover that */ |
| 291 | len += TCP_OPTION_LEN_MSS; |
| 292 | |
| 293 | opts->flags |= TCP_OPTS_FLAG_WSCALE; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 294 | opts->wscale = wnd_scale; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 295 | len += TCP_OPTION_LEN_WINDOW_SCALE; |
| 296 | |
| 297 | opts->flags |= TCP_OPTS_FLAG_TSTAMP; |
| 298 | opts->tsval = tcp_time_now (); |
| 299 | opts->tsecr = 0; |
| 300 | len += TCP_OPTION_LEN_TIMESTAMP; |
| 301 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 302 | if (TCP_USE_SACKS) |
| 303 | { |
| 304 | opts->flags |= TCP_OPTS_FLAG_SACK_PERMITTED; |
| 305 | len += TCP_OPTION_LEN_SACK_PERMITTED; |
| 306 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 307 | |
| 308 | /* Align to needed boundary */ |
| 309 | len += (TCP_OPTS_ALIGN - len % TCP_OPTS_ALIGN) % TCP_OPTS_ALIGN; |
| 310 | return len; |
| 311 | } |
| 312 | |
| 313 | always_inline int |
| 314 | tcp_make_synack_options (tcp_connection_t * tc, tcp_options_t * opts) |
| 315 | { |
| 316 | u8 len = 0; |
| 317 | |
| 318 | opts->flags |= TCP_OPTS_FLAG_MSS; |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 319 | opts->mss = tc->mss; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 320 | len += TCP_OPTION_LEN_MSS; |
| 321 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 322 | if (tcp_opts_wscale (&tc->rcv_opts)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 323 | { |
| 324 | opts->flags |= TCP_OPTS_FLAG_WSCALE; |
| 325 | opts->wscale = tc->rcv_wscale; |
| 326 | len += TCP_OPTION_LEN_WINDOW_SCALE; |
| 327 | } |
| 328 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 329 | if (tcp_opts_tstamp (&tc->rcv_opts)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 330 | { |
| 331 | opts->flags |= TCP_OPTS_FLAG_TSTAMP; |
| 332 | opts->tsval = tcp_time_now (); |
| 333 | opts->tsecr = tc->tsval_recent; |
| 334 | len += TCP_OPTION_LEN_TIMESTAMP; |
| 335 | } |
| 336 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 337 | if (tcp_opts_sack_permitted (&tc->rcv_opts)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 338 | { |
| 339 | opts->flags |= TCP_OPTS_FLAG_SACK_PERMITTED; |
| 340 | len += TCP_OPTION_LEN_SACK_PERMITTED; |
| 341 | } |
| 342 | |
| 343 | /* Align to needed boundary */ |
| 344 | len += (TCP_OPTS_ALIGN - len % TCP_OPTS_ALIGN) % TCP_OPTS_ALIGN; |
| 345 | return len; |
| 346 | } |
| 347 | |
| 348 | always_inline int |
| 349 | tcp_make_established_options (tcp_connection_t * tc, tcp_options_t * opts) |
| 350 | { |
| 351 | u8 len = 0; |
| 352 | |
| 353 | opts->flags = 0; |
| 354 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 355 | if (tcp_opts_tstamp (&tc->rcv_opts)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 356 | { |
| 357 | opts->flags |= TCP_OPTS_FLAG_TSTAMP; |
| 358 | opts->tsval = tcp_time_now (); |
| 359 | opts->tsecr = tc->tsval_recent; |
| 360 | len += TCP_OPTION_LEN_TIMESTAMP; |
| 361 | } |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 362 | if (tcp_opts_sack_permitted (&tc->rcv_opts)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 363 | { |
| 364 | if (vec_len (tc->snd_sacks)) |
| 365 | { |
| 366 | opts->flags |= TCP_OPTS_FLAG_SACK; |
| 367 | opts->sacks = tc->snd_sacks; |
Florin Coras | c28764f | 2017-04-26 00:08:42 -0700 | [diff] [blame] | 368 | opts->n_sack_blocks = clib_min (vec_len (tc->snd_sacks), |
| 369 | TCP_OPTS_MAX_SACK_BLOCKS); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 370 | len += 2 + TCP_OPTION_LEN_SACK_BLOCK * opts->n_sack_blocks; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | /* Align to needed boundary */ |
| 375 | len += (TCP_OPTS_ALIGN - len % TCP_OPTS_ALIGN) % TCP_OPTS_ALIGN; |
| 376 | return len; |
| 377 | } |
| 378 | |
| 379 | always_inline int |
| 380 | tcp_make_options (tcp_connection_t * tc, tcp_options_t * opts, |
| 381 | tcp_state_t state) |
| 382 | { |
| 383 | switch (state) |
| 384 | { |
| 385 | case TCP_STATE_ESTABLISHED: |
| 386 | case TCP_STATE_FIN_WAIT_1: |
| 387 | return tcp_make_established_options (tc, opts); |
| 388 | case TCP_STATE_SYN_RCVD: |
| 389 | return tcp_make_synack_options (tc, opts); |
| 390 | case TCP_STATE_SYN_SENT: |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 391 | return tcp_make_syn_options (opts, tc->rcv_wscale); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 392 | default: |
| 393 | clib_warning ("Not handled!"); |
| 394 | return 0; |
| 395 | } |
| 396 | } |
| 397 | |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 398 | /** |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 399 | * Update snd_mss to reflect the effective segment size that we can send |
| 400 | * by taking into account all TCP options, including SACKs |
| 401 | */ |
| 402 | void |
| 403 | tcp_update_snd_mss (tcp_connection_t * tc) |
| 404 | { |
| 405 | /* Compute options to be used for connection. These may be reused when |
| 406 | * sending data or to compute the effective mss (snd_mss) */ |
| 407 | tc->snd_opts_len = |
| 408 | tcp_make_options (tc, &tc->snd_opts, TCP_STATE_ESTABLISHED); |
| 409 | |
| 410 | /* XXX check if MTU has been updated */ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 411 | tc->snd_mss = clib_min (tc->mss, tc->rcv_opts.mss) - tc->snd_opts_len; |
Florin Coras | db84e57 | 2017-05-09 18:54:52 -0700 | [diff] [blame] | 412 | ASSERT (tc->snd_mss > 0); |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void |
| 416 | tcp_init_mss (tcp_connection_t * tc) |
| 417 | { |
Florin Coras | db84e57 | 2017-05-09 18:54:52 -0700 | [diff] [blame] | 418 | u16 default_min_mss = 536; |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 419 | tcp_update_rcv_mss (tc); |
| 420 | |
| 421 | /* TODO cache mss and consider PMTU discovery */ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 422 | tc->snd_mss = clib_min (tc->rcv_opts.mss, tc->mss); |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 423 | |
Florin Coras | db84e57 | 2017-05-09 18:54:52 -0700 | [diff] [blame] | 424 | if (tc->snd_mss < 45) |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 425 | { |
| 426 | clib_warning ("snd mss is 0"); |
Florin Coras | db84e57 | 2017-05-09 18:54:52 -0700 | [diff] [blame] | 427 | /* Assume that at least the min default mss works */ |
| 428 | tc->snd_mss = default_min_mss; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 429 | tc->rcv_opts.mss = default_min_mss; |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /* We should have enough space for 40 bytes of options */ |
| 433 | ASSERT (tc->snd_mss > 45); |
| 434 | |
| 435 | /* If we use timestamp option, account for it */ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 436 | if (tcp_opts_tstamp (&tc->rcv_opts)) |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 437 | tc->snd_mss -= TCP_OPTION_LEN_TIMESTAMP; |
| 438 | } |
| 439 | |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 440 | always_inline int |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 441 | tcp_alloc_tx_buffers (tcp_main_t * tm, u8 thread_index, u32 n_free_buffers) |
| 442 | { |
| 443 | vec_validate (tm->tx_buffers[thread_index], n_free_buffers - 1); |
| 444 | _vec_len (tm->tx_buffers[thread_index]) = |
| 445 | vlib_buffer_alloc_from_free_list (vlib_get_main (), |
| 446 | tm->tx_buffers[thread_index], |
| 447 | n_free_buffers, |
| 448 | VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); |
| 449 | /* buffer shortage, report failure */ |
| 450 | if (vec_len (tm->tx_buffers[thread_index]) == 0) |
| 451 | { |
| 452 | clib_warning ("out of buffers"); |
| 453 | return -1; |
| 454 | } |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | always_inline int |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 459 | tcp_get_free_buffer_index (tcp_main_t * tm, u32 * bidx) |
| 460 | { |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 461 | u32 *my_tx_buffers; |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 462 | u32 thread_index = vlib_get_thread_index (); |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 463 | if (PREDICT_FALSE (vec_len (tm->tx_buffers[thread_index]) == 0)) |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 464 | { |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 465 | if (tcp_alloc_tx_buffers (tm, thread_index, VLIB_FRAME_SIZE)) |
| 466 | return -1; |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 467 | } |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 468 | my_tx_buffers = tm->tx_buffers[thread_index]; |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 469 | *bidx = my_tx_buffers[_vec_len (my_tx_buffers) - 1]; |
| 470 | _vec_len (my_tx_buffers) -= 1; |
| 471 | return 0; |
| 472 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 473 | |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 474 | always_inline void |
| 475 | tcp_return_buffer (tcp_main_t * tm) |
| 476 | { |
| 477 | u32 *my_tx_buffers; |
| 478 | u32 thread_index = vlib_get_thread_index (); |
| 479 | my_tx_buffers = tm->tx_buffers[thread_index]; |
| 480 | _vec_len (my_tx_buffers) += 1; |
| 481 | } |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 482 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 483 | always_inline void |
| 484 | tcp_reuse_buffer (vlib_main_t * vm, vlib_buffer_t * b) |
| 485 | { |
| 486 | vlib_buffer_t *it = b; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 487 | u32 save_free_list = b->flags & VLIB_BUFFER_FREE_LIST_INDEX_MASK; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 488 | do |
| 489 | { |
| 490 | it->current_data = 0; |
| 491 | it->current_length = 0; |
| 492 | it->total_length_not_including_first_buffer = 0; |
| 493 | } |
| 494 | while ((it->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 495 | && (it = vlib_get_buffer (vm, it->next_buffer))); |
| 496 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 497 | if (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 498 | vlib_buffer_free_one (vm, b->next_buffer); |
| 499 | b->flags = save_free_list; |
| 500 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 501 | /* Leave enough space for headers */ |
| 502 | vlib_buffer_make_headroom (b, MAX_HDRS_LEN); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 503 | vnet_buffer (b)->tcp.flags = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Prepare ACK |
| 508 | */ |
| 509 | void |
| 510 | tcp_make_ack_i (tcp_connection_t * tc, vlib_buffer_t * b, tcp_state_t state, |
| 511 | u8 flags) |
| 512 | { |
| 513 | tcp_options_t _snd_opts, *snd_opts = &_snd_opts; |
| 514 | u8 tcp_opts_len, tcp_hdr_opts_len; |
| 515 | tcp_header_t *th; |
| 516 | u16 wnd; |
| 517 | |
| 518 | wnd = tcp_window_to_advertise (tc, state); |
| 519 | |
| 520 | /* Make and write options */ |
| 521 | tcp_opts_len = tcp_make_established_options (tc, snd_opts); |
| 522 | tcp_hdr_opts_len = tcp_opts_len + sizeof (tcp_header_t); |
| 523 | |
| 524 | th = vlib_buffer_push_tcp (b, tc->c_lcl_port, tc->c_rmt_port, tc->snd_nxt, |
| 525 | tc->rcv_nxt, tcp_hdr_opts_len, flags, wnd); |
| 526 | |
| 527 | tcp_options_write ((u8 *) (th + 1), snd_opts); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 528 | vnet_buffer (b)->tcp.connection_index = tc->c_c_index; |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Convert buffer to ACK |
| 533 | */ |
| 534 | void |
| 535 | tcp_make_ack (tcp_connection_t * tc, vlib_buffer_t * b) |
| 536 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 537 | vlib_main_t *vm = vlib_get_main (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 538 | |
| 539 | tcp_reuse_buffer (vm, b); |
| 540 | tcp_make_ack_i (tc, b, TCP_STATE_ESTABLISHED, TCP_FLAG_ACK); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 541 | TCP_EVT_DBG (TCP_EVT_ACK_SENT, tc); |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 542 | vnet_buffer (b)->tcp.flags = TCP_BUF_FLAG_ACK; |
| 543 | tc->rcv_las = tc->rcv_nxt; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Convert buffer to FIN-ACK |
| 548 | */ |
| 549 | void |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 550 | tcp_make_fin (tcp_connection_t * tc, vlib_buffer_t * b) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 551 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 552 | vlib_main_t *vm = vlib_get_main (); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 553 | u8 flags = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 554 | |
| 555 | tcp_reuse_buffer (vm, b); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 556 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 557 | flags = TCP_FLAG_FIN | TCP_FLAG_ACK; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 558 | tcp_make_ack_i (tc, b, TCP_STATE_ESTABLISHED, flags); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 559 | |
| 560 | /* Reset flags, make sure ack is sent */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 561 | vnet_buffer (b)->tcp.flags &= ~TCP_BUF_FLAG_DUPACK; |
| 562 | |
| 563 | tc->snd_nxt += 1; |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * Convert buffer to SYN-ACK |
| 568 | */ |
| 569 | void |
| 570 | tcp_make_synack (tcp_connection_t * tc, vlib_buffer_t * b) |
| 571 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 572 | vlib_main_t *vm = vlib_get_main (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 573 | tcp_options_t _snd_opts, *snd_opts = &_snd_opts; |
| 574 | u8 tcp_opts_len, tcp_hdr_opts_len; |
| 575 | tcp_header_t *th; |
| 576 | u16 initial_wnd; |
| 577 | u32 time_now; |
| 578 | |
| 579 | memset (snd_opts, 0, sizeof (*snd_opts)); |
| 580 | |
| 581 | tcp_reuse_buffer (vm, b); |
| 582 | |
| 583 | /* Set random initial sequence */ |
| 584 | time_now = tcp_time_now (); |
| 585 | |
| 586 | tc->iss = random_u32 (&time_now); |
| 587 | tc->snd_una = tc->iss; |
| 588 | tc->snd_nxt = tc->iss + 1; |
| 589 | tc->snd_una_max = tc->snd_nxt; |
| 590 | |
| 591 | initial_wnd = tcp_initial_window_to_advertise (tc); |
| 592 | |
| 593 | /* Make and write options */ |
| 594 | tcp_opts_len = tcp_make_synack_options (tc, snd_opts); |
| 595 | tcp_hdr_opts_len = tcp_opts_len + sizeof (tcp_header_t); |
| 596 | |
| 597 | th = vlib_buffer_push_tcp (b, tc->c_lcl_port, tc->c_rmt_port, tc->iss, |
| 598 | tc->rcv_nxt, tcp_hdr_opts_len, |
| 599 | TCP_FLAG_SYN | TCP_FLAG_ACK, initial_wnd); |
| 600 | |
| 601 | tcp_options_write ((u8 *) (th + 1), snd_opts); |
| 602 | |
| 603 | vnet_buffer (b)->tcp.connection_index = tc->c_c_index; |
| 604 | vnet_buffer (b)->tcp.flags = TCP_BUF_FLAG_ACK; |
| 605 | |
| 606 | /* Init retransmit timer */ |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 607 | tcp_retransmit_timer_set (tc); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 608 | TCP_EVT_DBG (TCP_EVT_SYNACK_SENT, tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | always_inline void |
| 612 | tcp_enqueue_to_ip_lookup (vlib_main_t * vm, vlib_buffer_t * b, u32 bi, |
| 613 | u8 is_ip4) |
| 614 | { |
| 615 | u32 *to_next, next_index; |
| 616 | vlib_frame_t *f; |
| 617 | |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 618 | b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 619 | b->error = 0; |
| 620 | |
| 621 | /* Default FIB for now */ |
| 622 | vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; |
| 623 | |
| 624 | /* Send to IP lookup */ |
| 625 | next_index = is_ip4 ? ip4_lookup_node.index : ip6_lookup_node.index; |
| 626 | f = vlib_get_frame_to_node (vm, next_index); |
| 627 | |
| 628 | /* Enqueue the packet */ |
| 629 | to_next = vlib_frame_vector_args (f); |
| 630 | to_next[0] = bi; |
| 631 | f->n_vectors = 1; |
| 632 | vlib_put_frame_to_node (vm, next_index, f); |
| 633 | } |
| 634 | |
| 635 | int |
| 636 | tcp_make_reset_in_place (vlib_main_t * vm, vlib_buffer_t * b0, |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 637 | tcp_state_t state, u8 thread_index, u8 is_ip4) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 638 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 639 | ip4_header_t *ih4; |
| 640 | ip6_header_t *ih6; |
| 641 | tcp_header_t *th0; |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 642 | ip4_address_t src_ip40, dst_ip40; |
| 643 | ip6_address_t src_ip60, dst_ip60; |
| 644 | u16 src_port, dst_port; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 645 | u32 tmp; |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 646 | u32 seq, ack; |
| 647 | u8 flags; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 648 | |
| 649 | /* Find IP and TCP headers */ |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 650 | th0 = tcp_buffer_hdr (b0); |
| 651 | |
| 652 | /* Save src and dst ip */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 653 | if (is_ip4) |
| 654 | { |
| 655 | ih4 = vlib_buffer_get_current (b0); |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 656 | ASSERT ((ih4->ip_version_and_header_length & 0xF0) == 0x40); |
| 657 | src_ip40.as_u32 = ih4->src_address.as_u32; |
| 658 | dst_ip40.as_u32 = ih4->dst_address.as_u32; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 659 | } |
| 660 | else |
| 661 | { |
| 662 | ih6 = vlib_buffer_get_current (b0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 663 | ASSERT ((ih6->ip_version_traffic_class_and_flow_label & 0xF0) == 0x60); |
| 664 | clib_memcpy (&src_ip60, &ih6->src_address, sizeof (ip6_address_t)); |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 665 | clib_memcpy (&dst_ip60, &ih6->dst_address, sizeof (ip6_address_t)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 666 | } |
| 667 | |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 668 | src_port = th0->src_port; |
| 669 | dst_port = th0->dst_port; |
| 670 | |
| 671 | /* Try to determine what/why we're actually resetting */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 672 | if (state == TCP_STATE_CLOSED) |
| 673 | { |
| 674 | if (!tcp_syn (th0)) |
| 675 | return -1; |
| 676 | |
| 677 | tmp = clib_net_to_host_u32 (th0->seq_number); |
| 678 | |
| 679 | /* Got a SYN for no listener. */ |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 680 | flags = TCP_FLAG_RST | TCP_FLAG_ACK; |
| 681 | ack = clib_host_to_net_u32 (tmp + 1); |
| 682 | seq = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 683 | } |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 684 | else |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 685 | { |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 686 | flags = TCP_FLAG_RST; |
| 687 | seq = th0->ack_number; |
| 688 | ack = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 689 | } |
| 690 | |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 691 | tcp_reuse_buffer (vm, b0); |
| 692 | th0 = vlib_buffer_push_tcp_net_order (b0, dst_port, src_port, seq, ack, |
| 693 | sizeof (tcp_header_t), flags, 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 694 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 695 | if (is_ip4) |
| 696 | { |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 697 | ih4 = vlib_buffer_push_ip4 (vm, b0, &dst_ip40, &src_ip40, |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame] | 698 | IP_PROTOCOL_TCP, 1); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 699 | th0->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ih4); |
| 700 | } |
| 701 | else |
| 702 | { |
| 703 | int bogus = ~0; |
Florin Coras | dc629cd | 2017-05-09 00:52:37 -0700 | [diff] [blame] | 704 | ih6 = vlib_buffer_push_ip6 (vm, b0, &dst_ip60, &src_ip60, |
| 705 | IP_PROTOCOL_TCP); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 706 | th0->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ih6, &bogus); |
| 707 | ASSERT (!bogus); |
| 708 | } |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | /** |
| 714 | * Send reset without reusing existing buffer |
| 715 | */ |
| 716 | void |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 717 | tcp_send_reset (tcp_connection_t * tc, vlib_buffer_t * pkt, u8 is_ip4) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 718 | { |
| 719 | vlib_buffer_t *b; |
| 720 | u32 bi; |
| 721 | tcp_main_t *tm = vnet_get_tcp_main (); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 722 | vlib_main_t *vm = vlib_get_main (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 723 | u8 tcp_hdr_len, flags = 0; |
| 724 | tcp_header_t *th, *pkt_th; |
| 725 | u32 seq, ack; |
| 726 | ip4_header_t *ih4, *pkt_ih4; |
| 727 | ip6_header_t *ih6, *pkt_ih6; |
| 728 | |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 729 | if (PREDICT_FALSE (tcp_get_free_buffer_index (tm, &bi))) |
| 730 | return; |
| 731 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 732 | b = vlib_get_buffer (vm, bi); |
| 733 | |
| 734 | /* Leave enough space for headers */ |
| 735 | vlib_buffer_make_headroom (b, MAX_HDRS_LEN); |
| 736 | |
| 737 | /* Make and write options */ |
| 738 | tcp_hdr_len = sizeof (tcp_header_t); |
| 739 | |
| 740 | if (is_ip4) |
| 741 | { |
| 742 | pkt_ih4 = vlib_buffer_get_current (pkt); |
| 743 | pkt_th = ip4_next_header (pkt_ih4); |
| 744 | } |
| 745 | else |
| 746 | { |
| 747 | pkt_ih6 = vlib_buffer_get_current (pkt); |
| 748 | pkt_th = ip6_next_header (pkt_ih6); |
| 749 | } |
| 750 | |
| 751 | if (tcp_ack (pkt_th)) |
| 752 | { |
| 753 | flags = TCP_FLAG_RST; |
| 754 | seq = pkt_th->ack_number; |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 755 | ack = (tc && tc->state >= TCP_STATE_SYN_RCVD) ? tc->rcv_nxt : 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 756 | } |
| 757 | else |
| 758 | { |
| 759 | flags = TCP_FLAG_RST | TCP_FLAG_ACK; |
| 760 | seq = 0; |
| 761 | ack = clib_host_to_net_u32 (vnet_buffer (pkt)->tcp.seq_end); |
| 762 | } |
| 763 | |
| 764 | th = vlib_buffer_push_tcp_net_order (b, pkt_th->dst_port, pkt_th->src_port, |
| 765 | seq, ack, tcp_hdr_len, flags, 0); |
| 766 | |
| 767 | /* Swap src and dst ip */ |
| 768 | if (is_ip4) |
| 769 | { |
| 770 | ASSERT ((pkt_ih4->ip_version_and_header_length & 0xF0) == 0x40); |
| 771 | ih4 = vlib_buffer_push_ip4 (vm, b, &pkt_ih4->dst_address, |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame] | 772 | &pkt_ih4->src_address, IP_PROTOCOL_TCP, 1); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 773 | th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ih4); |
| 774 | } |
| 775 | else |
| 776 | { |
| 777 | int bogus = ~0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 778 | ASSERT ((pkt_ih6->ip_version_traffic_class_and_flow_label & 0xF0) == |
| 779 | 0x60); |
root | c9d1c5b | 2017-08-15 12:58:31 -0400 | [diff] [blame] | 780 | ih6 = vlib_buffer_push_ip6 (vm, b, &pkt_ih6->dst_address, |
| 781 | &pkt_ih6->src_address, IP_PROTOCOL_TCP); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 782 | th->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ih6, &bogus); |
| 783 | ASSERT (!bogus); |
| 784 | } |
| 785 | |
| 786 | tcp_enqueue_to_ip_lookup (vm, b, bi, is_ip4); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 787 | TCP_EVT_DBG (TCP_EVT_RST_SENT, tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | void |
| 791 | tcp_push_ip_hdr (tcp_main_t * tm, tcp_connection_t * tc, vlib_buffer_t * b) |
| 792 | { |
| 793 | tcp_header_t *th = vlib_buffer_get_current (b); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 794 | vlib_main_t *vm = vlib_get_main (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 795 | if (tc->c_is_ip4) |
| 796 | { |
| 797 | ip4_header_t *ih; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 798 | ih = vlib_buffer_push_ip4 (vm, b, &tc->c_lcl_ip4, |
Florin Coras | fdbc382 | 2017-07-27 00:34:12 -0700 | [diff] [blame] | 799 | &tc->c_rmt_ip4, IP_PROTOCOL_TCP, 1); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 800 | th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ih); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 801 | } |
| 802 | else |
| 803 | { |
| 804 | ip6_header_t *ih; |
| 805 | int bogus = ~0; |
| 806 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 807 | ih = vlib_buffer_push_ip6 (vm, b, &tc->c_lcl_ip6, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 808 | &tc->c_rmt_ip6, IP_PROTOCOL_TCP); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 809 | th->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ih, &bogus); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 810 | ASSERT (!bogus); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * Send SYN |
| 816 | * |
| 817 | * Builds a SYN packet for a half-open connection and sends it to ipx_lookup. |
| 818 | * The packet is not forwarded through tcpx_output to avoid doing lookups |
| 819 | * in the half_open pool. |
| 820 | */ |
| 821 | void |
| 822 | tcp_send_syn (tcp_connection_t * tc) |
| 823 | { |
| 824 | vlib_buffer_t *b; |
| 825 | u32 bi; |
| 826 | tcp_main_t *tm = vnet_get_tcp_main (); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 827 | vlib_main_t *vm = vlib_get_main (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 828 | u8 tcp_hdr_opts_len, tcp_opts_len; |
| 829 | tcp_header_t *th; |
| 830 | u32 time_now; |
| 831 | u16 initial_wnd; |
| 832 | tcp_options_t snd_opts; |
| 833 | |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 834 | if (PREDICT_FALSE (tcp_get_free_buffer_index (tm, &bi))) |
| 835 | return; |
| 836 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 837 | b = vlib_get_buffer (vm, bi); |
| 838 | |
| 839 | /* Leave enough space for headers */ |
| 840 | vlib_buffer_make_headroom (b, MAX_HDRS_LEN); |
| 841 | |
| 842 | /* Set random initial sequence */ |
| 843 | time_now = tcp_time_now (); |
| 844 | |
| 845 | tc->iss = random_u32 (&time_now); |
| 846 | tc->snd_una = tc->iss; |
| 847 | tc->snd_una_max = tc->snd_nxt = tc->iss + 1; |
| 848 | |
| 849 | initial_wnd = tcp_initial_window_to_advertise (tc); |
| 850 | |
| 851 | /* Make and write options */ |
| 852 | memset (&snd_opts, 0, sizeof (snd_opts)); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 853 | tcp_opts_len = tcp_make_syn_options (&snd_opts, tc->rcv_wscale); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 854 | tcp_hdr_opts_len = tcp_opts_len + sizeof (tcp_header_t); |
| 855 | |
| 856 | th = vlib_buffer_push_tcp (b, tc->c_lcl_port, tc->c_rmt_port, tc->iss, |
| 857 | tc->rcv_nxt, tcp_hdr_opts_len, TCP_FLAG_SYN, |
| 858 | initial_wnd); |
| 859 | |
| 860 | tcp_options_write ((u8 *) (th + 1), &snd_opts); |
| 861 | |
| 862 | /* Measure RTT with this */ |
| 863 | tc->rtt_ts = tcp_time_now (); |
| 864 | tc->rtt_seq = tc->snd_nxt; |
| 865 | |
| 866 | /* Start retransmit trimer */ |
| 867 | tcp_timer_set (tc, TCP_TIMER_RETRANSMIT_SYN, tc->rto * TCP_TO_TIMER_TICK); |
| 868 | tc->rto_boff = 0; |
| 869 | |
| 870 | /* Set the connection establishment timer */ |
| 871 | tcp_timer_set (tc, TCP_TIMER_ESTABLISH, TCP_ESTABLISH_TIME); |
| 872 | |
| 873 | tcp_push_ip_hdr (tm, tc, b); |
| 874 | tcp_enqueue_to_ip_lookup (vm, b, bi, tc->c_is_ip4); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 875 | TCP_EVT_DBG (TCP_EVT_SYN_SENT, tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | always_inline void |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 879 | tcp_enqueue_to_output_i (vlib_main_t * vm, vlib_buffer_t * b, u32 bi, |
| 880 | u8 is_ip4, u8 flush) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 881 | { |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 882 | tcp_main_t *tm = vnet_get_tcp_main (); |
| 883 | u32 thread_index = vlib_get_thread_index (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 884 | u32 *to_next, next_index; |
| 885 | vlib_frame_t *f; |
| 886 | |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 887 | b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 888 | b->error = 0; |
| 889 | |
| 890 | /* Decide where to send the packet */ |
| 891 | next_index = is_ip4 ? tcp4_output_node.index : tcp6_output_node.index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 892 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 893 | /* Initialize the trajectory trace, if configured */ |
| 894 | if (VLIB_BUFFER_TRACE_TRAJECTORY > 0) |
| 895 | { |
| 896 | b->pre_data[0] = 1; |
| 897 | b->pre_data[1] = next_index; |
| 898 | } |
| 899 | |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 900 | /* Get frame to v4/6 output node */ |
| 901 | f = tm->tx_frames[!is_ip4][thread_index]; |
| 902 | if (!f) |
| 903 | { |
| 904 | f = vlib_get_frame_to_node (vm, next_index); |
| 905 | ASSERT (f); |
| 906 | tm->tx_frames[!is_ip4][thread_index] = f; |
| 907 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 908 | to_next = vlib_frame_vector_args (f); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 909 | to_next[f->n_vectors] = bi; |
| 910 | f->n_vectors += 1; |
| 911 | if (flush || f->n_vectors == VLIB_FRAME_SIZE) |
| 912 | { |
| 913 | vlib_put_frame_to_node (vm, next_index, f); |
| 914 | tm->tx_frames[!is_ip4][thread_index] = 0; |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | always_inline void |
| 919 | tcp_enqueue_to_output (vlib_main_t * vm, vlib_buffer_t * b, u32 bi, u8 is_ip4) |
| 920 | { |
| 921 | tcp_enqueue_to_output_i (vm, b, bi, is_ip4, 0); |
| 922 | } |
| 923 | |
| 924 | always_inline void |
| 925 | tcp_enqueue_to_output_now (vlib_main_t * vm, vlib_buffer_t * b, u32 bi, |
| 926 | u8 is_ip4) |
| 927 | { |
| 928 | tcp_enqueue_to_output_i (vm, b, bi, is_ip4, 1); |
| 929 | } |
| 930 | |
| 931 | /** |
| 932 | * Flush tx frame populated by retransmits and timer pops |
| 933 | */ |
| 934 | void |
| 935 | tcp_flush_frame_to_output (vlib_main_t * vm, u8 thread_index, u8 is_ip4) |
| 936 | { |
| 937 | if (tcp_main.tx_frames[!is_ip4][thread_index]) |
| 938 | { |
| 939 | u32 next_index; |
| 940 | next_index = is_ip4 ? tcp4_output_node.index : tcp6_output_node.index; |
| 941 | vlib_put_frame_to_node (vm, next_index, |
| 942 | tcp_main.tx_frames[!is_ip4][thread_index]); |
| 943 | tcp_main.tx_frames[!is_ip4][thread_index] = 0; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | /** |
| 948 | * Flush both v4 and v6 tx frames for thread index |
| 949 | */ |
| 950 | void |
| 951 | tcp_flush_frames_to_output (u8 thread_index) |
| 952 | { |
| 953 | vlib_main_t *vm = vlib_get_main (); |
| 954 | tcp_flush_frame_to_output (vm, thread_index, 1); |
| 955 | tcp_flush_frame_to_output (vm, thread_index, 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | /** |
| 959 | * Send FIN |
| 960 | */ |
| 961 | void |
| 962 | tcp_send_fin (tcp_connection_t * tc) |
| 963 | { |
| 964 | vlib_buffer_t *b; |
| 965 | u32 bi; |
| 966 | tcp_main_t *tm = vnet_get_tcp_main (); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 967 | vlib_main_t *vm = vlib_get_main (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 968 | |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 969 | if (PREDICT_FALSE (tcp_get_free_buffer_index (tm, &bi))) |
| 970 | return; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 971 | b = vlib_get_buffer (vm, bi); |
| 972 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 973 | tcp_make_fin (tc, b); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 974 | tcp_enqueue_to_output_now (vm, b, bi, tc->c_is_ip4); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 975 | tc->flags |= TCP_CONN_FINSNT; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 976 | tc->flags &= ~TCP_CONN_FINPNDG; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 977 | tcp_retransmit_timer_force_update (tc); |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 978 | TCP_EVT_DBG (TCP_EVT_FIN_SENT, tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | always_inline u8 |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 982 | tcp_make_state_flags (tcp_connection_t * tc, tcp_state_t next_state) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 983 | { |
| 984 | switch (next_state) |
| 985 | { |
| 986 | case TCP_STATE_ESTABLISHED: |
| 987 | return TCP_FLAG_ACK; |
| 988 | case TCP_STATE_SYN_RCVD: |
| 989 | return TCP_FLAG_SYN | TCP_FLAG_ACK; |
| 990 | case TCP_STATE_SYN_SENT: |
| 991 | return TCP_FLAG_SYN; |
| 992 | case TCP_STATE_LAST_ACK: |
| 993 | case TCP_STATE_FIN_WAIT_1: |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 994 | if (tc->snd_nxt + 1 < tc->snd_una_max) |
| 995 | return TCP_FLAG_ACK; |
| 996 | else |
| 997 | return TCP_FLAG_FIN; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 998 | default: |
| 999 | clib_warning ("Shouldn't be here!"); |
| 1000 | } |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | /** |
| 1005 | * Push TCP header and update connection variables |
| 1006 | */ |
| 1007 | static void |
| 1008 | tcp_push_hdr_i (tcp_connection_t * tc, vlib_buffer_t * b, |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1009 | tcp_state_t next_state, u8 compute_opts) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1010 | { |
| 1011 | u32 advertise_wnd, data_len; |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1012 | u8 tcp_hdr_opts_len, opts_write_len, flags; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1013 | tcp_header_t *th; |
| 1014 | |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 1015 | data_len = b->current_length + b->total_length_not_including_first_buffer; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1016 | vnet_buffer (b)->tcp.flags = 0; |
| 1017 | |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1018 | if (compute_opts) |
| 1019 | tc->snd_opts_len = tcp_make_options (tc, &tc->snd_opts, tc->state); |
| 1020 | |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1021 | tcp_hdr_opts_len = tc->snd_opts_len + sizeof (tcp_header_t); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1022 | advertise_wnd = tcp_window_to_advertise (tc, next_state); |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1023 | flags = tcp_make_state_flags (tc, next_state); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1024 | |
| 1025 | /* Push header and options */ |
| 1026 | th = vlib_buffer_push_tcp (b, tc->c_lcl_port, tc->c_rmt_port, tc->snd_nxt, |
| 1027 | tc->rcv_nxt, tcp_hdr_opts_len, flags, |
| 1028 | advertise_wnd); |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1029 | opts_write_len = tcp_options_write ((u8 *) (th + 1), &tc->snd_opts); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1030 | |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1031 | ASSERT (opts_write_len == tc->snd_opts_len); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1032 | vnet_buffer (b)->tcp.connection_index = tc->c_c_index; |
| 1033 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1034 | /* |
| 1035 | * Update connection variables |
| 1036 | */ |
| 1037 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1038 | tc->snd_nxt += data_len; |
Florin Coras | c28764f | 2017-04-26 00:08:42 -0700 | [diff] [blame] | 1039 | tc->rcv_las = tc->rcv_nxt; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1040 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1041 | /* TODO this is updated in output as well ... */ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1042 | if (seq_gt (tc->snd_nxt, tc->snd_una_max)) |
Florin Coras | 3af90fc | 2017-05-03 21:09:42 -0700 | [diff] [blame] | 1043 | { |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1044 | tc->snd_una_max = tc->snd_nxt; |
| 1045 | tcp_validate_txf_size (tc, tc->snd_una_max - tc->snd_una); |
Florin Coras | 3af90fc | 2017-05-03 21:09:42 -0700 | [diff] [blame] | 1046 | } |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1047 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1048 | TCP_EVT_DBG (TCP_EVT_PKTIZE, tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1049 | } |
| 1050 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1051 | void |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1052 | tcp_send_ack (tcp_connection_t * tc) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1053 | { |
| 1054 | tcp_main_t *tm = vnet_get_tcp_main (); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1055 | vlib_main_t *vm = vlib_get_main (); |
| 1056 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1057 | vlib_buffer_t *b; |
| 1058 | u32 bi; |
| 1059 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1060 | /* Get buffer */ |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1061 | if (PREDICT_FALSE (tcp_get_free_buffer_index (tm, &bi))) |
| 1062 | return; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1063 | b = vlib_get_buffer (vm, bi); |
| 1064 | |
| 1065 | /* Fill in the ACK */ |
| 1066 | tcp_make_ack (tc, b); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1067 | tcp_enqueue_to_output (vm, b, bi, tc->c_is_ip4); |
| 1068 | } |
| 1069 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1070 | /** |
| 1071 | * Delayed ack timer handler |
| 1072 | * |
| 1073 | * Sends delayed ACK when timer expires |
| 1074 | */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1075 | void |
| 1076 | tcp_timer_delack_handler (u32 index) |
| 1077 | { |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1078 | u32 thread_index = vlib_get_thread_index (); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1079 | tcp_connection_t *tc; |
| 1080 | |
| 1081 | tc = tcp_connection_get (index, thread_index); |
| 1082 | tc->timers[TCP_TIMER_DELACK] = TCP_TIMER_HANDLE_INVALID; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1083 | tcp_send_ack (tc); |
| 1084 | } |
| 1085 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1086 | /** |
| 1087 | * Build a retransmit segment |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1088 | * |
| 1089 | * @return the number of bytes in the segment or 0 if there's nothing to |
| 1090 | * retransmit |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1091 | */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1092 | u32 |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1093 | tcp_prepare_retransmit_segment (tcp_connection_t * tc, u32 offset, |
| 1094 | u32 max_deq_bytes, vlib_buffer_t ** b) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1095 | { |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1096 | tcp_main_t *tm = vnet_get_tcp_main (); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1097 | vlib_main_t *vm = vlib_get_main (); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1098 | int n_bytes = 0; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1099 | u32 start, bi, available_bytes; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1100 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1101 | ASSERT (tc->state >= TCP_STATE_ESTABLISHED); |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1102 | ASSERT (max_deq_bytes != 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1103 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1104 | /* |
| 1105 | * Make sure we can retransmit something |
| 1106 | */ |
| 1107 | max_deq_bytes = clib_min (tc->snd_mss, max_deq_bytes); |
| 1108 | available_bytes = stream_session_tx_fifo_max_dequeue (&tc->connection); |
| 1109 | if (!available_bytes) |
| 1110 | return 0; |
| 1111 | max_deq_bytes = clib_min (available_bytes, max_deq_bytes); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1112 | start = tc->snd_una + offset; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1113 | |
| 1114 | /* Start is beyond snd_congestion */ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1115 | if (seq_geq (start, tc->snd_congestion)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1116 | { |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1117 | goto done; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1118 | } |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1119 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1120 | /* Don't overshoot snd_congestion */ |
| 1121 | if (seq_gt (start + max_deq_bytes, tc->snd_congestion)) |
| 1122 | { |
| 1123 | max_deq_bytes = tc->snd_congestion - start; |
| 1124 | if (max_deq_bytes == 0) |
| 1125 | { |
| 1126 | goto done; |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | /* |
| 1131 | * Prepare options |
| 1132 | */ |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1133 | tc->snd_opts_len = tcp_make_options (tc, &tc->snd_opts, tc->state); |
| 1134 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1135 | /* |
| 1136 | * Allocate and fill in buffer(s) |
| 1137 | */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1138 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1139 | if (PREDICT_FALSE (tcp_get_free_buffer_index (tm, &bi))) |
| 1140 | return 0; |
| 1141 | *b = vlib_get_buffer (vm, bi); |
| 1142 | |
| 1143 | /* Easy case, buffer size greater than mss */ |
| 1144 | if (PREDICT_TRUE (max_deq_bytes <= tm->bytes_per_buffer)) |
| 1145 | { |
| 1146 | n_bytes = stream_session_peek_bytes (&tc->connection, |
| 1147 | vlib_buffer_get_current (*b), |
| 1148 | offset, max_deq_bytes); |
| 1149 | ASSERT (n_bytes == max_deq_bytes); |
| 1150 | b[0]->current_length = n_bytes; |
| 1151 | tcp_push_hdr_i (tc, *b, tc->state, 0); |
| 1152 | } |
| 1153 | /* Split mss into multiple buffers */ |
| 1154 | else |
| 1155 | { |
| 1156 | u32 chain_bi = ~0, n_bufs_per_seg; |
| 1157 | u32 thread_index = vlib_get_thread_index (); |
| 1158 | u16 n_peeked, len_to_deq, available_bufs; |
| 1159 | vlib_buffer_t *chain_b, *prev_b; |
| 1160 | u8 *data0; |
| 1161 | int i; |
| 1162 | |
| 1163 | n_bufs_per_seg = ceil ((double) max_deq_bytes / tm->bytes_per_buffer); |
| 1164 | ASSERT (available_bytes >= max_deq_bytes); |
| 1165 | |
| 1166 | /* Make sure we have enough buffers */ |
| 1167 | available_bufs = vec_len (tm->tx_buffers[thread_index]); |
| 1168 | if (n_bufs_per_seg > available_bufs) |
| 1169 | { |
| 1170 | if (tcp_alloc_tx_buffers (tm, thread_index, |
| 1171 | VLIB_FRAME_SIZE - available_bufs)) |
| 1172 | { |
| 1173 | tcp_return_buffer (tm); |
| 1174 | return 0; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | n_bytes = stream_session_peek_bytes (&tc->connection, |
| 1179 | vlib_buffer_get_current (*b), |
| 1180 | offset, tm->bytes_per_buffer); |
| 1181 | b[0]->current_length = n_bytes; |
| 1182 | b[0]->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID; |
| 1183 | b[0]->total_length_not_including_first_buffer = 0; |
| 1184 | |
| 1185 | tcp_push_hdr_i (tc, *b, tc->state, 0); |
| 1186 | max_deq_bytes -= n_bytes; |
| 1187 | |
| 1188 | chain_b = *b; |
| 1189 | for (i = 1; i < n_bufs_per_seg; i++) |
| 1190 | { |
| 1191 | prev_b = chain_b; |
| 1192 | len_to_deq = clib_min (max_deq_bytes, tm->bytes_per_buffer); |
| 1193 | tcp_get_free_buffer_index (tm, &chain_bi); |
| 1194 | ASSERT (chain_bi != (u32) ~ 0); |
| 1195 | chain_b = vlib_get_buffer (vm, chain_bi); |
| 1196 | chain_b->current_data = 0; |
| 1197 | data0 = vlib_buffer_get_current (chain_b); |
| 1198 | n_peeked = stream_session_peek_bytes (&tc->connection, data0, |
| 1199 | n_bytes, len_to_deq); |
| 1200 | n_bytes += n_peeked; |
| 1201 | ASSERT (n_peeked == len_to_deq); |
| 1202 | chain_b->current_length = n_peeked; |
| 1203 | b[0]->total_length_not_including_first_buffer += |
| 1204 | chain_b->current_length; |
| 1205 | |
| 1206 | /* update previous buffer */ |
| 1207 | prev_b->next_buffer = chain_bi; |
| 1208 | prev_b->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 1209 | |
| 1210 | /* update current buffer */ |
| 1211 | chain_b->next_buffer = 0; |
| 1212 | |
| 1213 | max_deq_bytes -= n_peeked; |
| 1214 | } |
| 1215 | } |
| 1216 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1217 | ASSERT (n_bytes > 0); |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 1218 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1219 | if (tcp_in_fastrecovery (tc)) |
| 1220 | tc->snd_rxt_bytes += n_bytes; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1221 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1222 | done: |
| 1223 | TCP_EVT_DBG (TCP_EVT_CC_RTX, tc, offset, n_bytes); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1224 | return n_bytes; |
| 1225 | } |
| 1226 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1227 | /** |
| 1228 | * Reset congestion control, switch cwnd to loss window and try again. |
| 1229 | */ |
| 1230 | static void |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1231 | tcp_rtx_timeout_cc (tcp_connection_t * tc) |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1232 | { |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1233 | tc->prev_ssthresh = tc->ssthresh; |
| 1234 | tc->prev_cwnd = tc->cwnd; |
| 1235 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1236 | /* Cleanly recover cc (also clears up fast retransmit) */ |
| 1237 | if (tcp_in_fastrecovery (tc)) |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1238 | tcp_cc_fastrecovery_exit (tc); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1239 | |
| 1240 | /* Start again from the beginning */ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1241 | tc->ssthresh = clib_max (tcp_flight_size (tc) / 2, 2 * tc->snd_mss); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1242 | tc->cwnd = tcp_loss_wnd (tc); |
| 1243 | tc->snd_congestion = tc->snd_una_max; |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 1244 | |
Florin Coras | 3af90fc | 2017-05-03 21:09:42 -0700 | [diff] [blame] | 1245 | tcp_recovery_on (tc); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1248 | static void |
| 1249 | tcp_timer_retransmit_handler_i (u32 index, u8 is_syn) |
| 1250 | { |
| 1251 | tcp_main_t *tm = vnet_get_tcp_main (); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1252 | vlib_main_t *vm = vlib_get_main (); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1253 | u32 thread_index = vlib_get_thread_index (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1254 | tcp_connection_t *tc; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1255 | vlib_buffer_t *b = 0; |
Florin Coras | 3af90fc | 2017-05-03 21:09:42 -0700 | [diff] [blame] | 1256 | u32 bi, n_bytes; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1257 | |
| 1258 | if (is_syn) |
| 1259 | { |
| 1260 | tc = tcp_half_open_connection_get (index); |
Florin Coras | 6881062 | 2017-07-24 17:40:28 -0700 | [diff] [blame] | 1261 | tc->timers[TCP_TIMER_RETRANSMIT_SYN] = TCP_TIMER_HANDLE_INVALID; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1262 | } |
| 1263 | else |
| 1264 | { |
| 1265 | tc = tcp_connection_get (index, thread_index); |
Florin Coras | 6881062 | 2017-07-24 17:40:28 -0700 | [diff] [blame] | 1266 | tc->timers[TCP_TIMER_RETRANSMIT] = TCP_TIMER_HANDLE_INVALID; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1267 | } |
| 1268 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1269 | if (!tcp_in_recovery (tc) && tc->rto_boff > 0 |
| 1270 | && tc->state >= TCP_STATE_ESTABLISHED) |
| 1271 | { |
| 1272 | tc->rto_boff = 0; |
| 1273 | tcp_update_rto (tc); |
| 1274 | } |
| 1275 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1276 | /* Increment RTO backoff (also equal to number of retries) */ |
| 1277 | tc->rto_boff += 1; |
| 1278 | |
| 1279 | /* Go back to first un-acked byte */ |
| 1280 | tc->snd_nxt = tc->snd_una; |
| 1281 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1282 | if (tc->state >= TCP_STATE_ESTABLISHED) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1283 | { |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1284 | /* Lost FIN, retransmit and return */ |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1285 | if (tcp_is_lost_fin (tc)) |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1286 | { |
| 1287 | tcp_send_fin (tc); |
| 1288 | return; |
| 1289 | } |
| 1290 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1291 | /* First retransmit timeout */ |
| 1292 | if (tc->rto_boff == 1) |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1293 | tcp_rtx_timeout_cc (tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1294 | |
| 1295 | /* Exponential backoff */ |
| 1296 | tc->rto = clib_min (tc->rto << 1, TCP_RTO_MAX); |
| 1297 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1298 | TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 1); |
| 1299 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1300 | /* Send one segment */ |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1301 | n_bytes = tcp_prepare_retransmit_segment (tc, 0, tc->snd_mss, &b); |
| 1302 | ASSERT (n_bytes); |
| 1303 | bi = vlib_get_buffer_index (vm, b); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1304 | /* TODO be less aggressive about this */ |
Florin Coras | 3af90fc | 2017-05-03 21:09:42 -0700 | [diff] [blame] | 1305 | scoreboard_clear (&tc->sack_sb); |
| 1306 | |
| 1307 | if (n_bytes == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1308 | { |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 1309 | clib_warning ("could not retransmit anything"); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1310 | clib_warning ("%U", format_tcp_connection, tc, 2); |
| 1311 | |
Florin Coras | bb292f4 | 2017-05-19 09:49:19 -0700 | [diff] [blame] | 1312 | /* Try again eventually */ |
| 1313 | tcp_retransmit_timer_set (tc); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1314 | ASSERT (0 || (tc->rto_boff > 1 |
| 1315 | && tc->snd_una == tc->snd_congestion)); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1316 | return; |
| 1317 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1318 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1319 | /* For first retransmit, record timestamp (Eifel detection RFC3522) */ |
| 1320 | if (tc->rto_boff == 1) |
| 1321 | tc->snd_rxt_ts = tcp_time_now (); |
| 1322 | } |
| 1323 | /* Retransmit for SYN/SYNACK */ |
| 1324 | else if (tc->state == TCP_STATE_SYN_RCVD || tc->state == TCP_STATE_SYN_SENT) |
| 1325 | { |
Florin Coras | 6881062 | 2017-07-24 17:40:28 -0700 | [diff] [blame] | 1326 | /* Half-open connection actually moved to established but we were |
| 1327 | * waiting for syn retransmit to pop to call cleanup from the right |
| 1328 | * thread. */ |
| 1329 | if (tc->flags & TCP_CONN_HALF_OPEN_DONE) |
| 1330 | { |
| 1331 | ASSERT (tc->state == TCP_STATE_SYN_SENT); |
| 1332 | if (tcp_half_open_connection_cleanup (tc)) |
| 1333 | { |
| 1334 | clib_warning ("could not remove half-open connection"); |
| 1335 | ASSERT (0); |
| 1336 | } |
| 1337 | return; |
| 1338 | } |
| 1339 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1340 | /* Try without increasing RTO a number of times. If this fails, |
| 1341 | * start growing RTO exponentially */ |
| 1342 | if (tc->rto_boff > TCP_RTO_SYN_RETRIES) |
| 1343 | tc->rto = clib_min (tc->rto << 1, TCP_RTO_MAX); |
| 1344 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1345 | if (PREDICT_FALSE (tcp_get_free_buffer_index (tm, &bi))) |
| 1346 | return; |
| 1347 | b = vlib_get_buffer (vm, bi); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1348 | vlib_buffer_make_headroom (b, MAX_HDRS_LEN); |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1349 | tcp_push_hdr_i (tc, b, tc->state, 1); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1350 | |
| 1351 | /* Account for the SYN */ |
| 1352 | tc->snd_nxt += 1; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 1353 | tc->rtt_ts = 0; |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1354 | TCP_EVT_DBG (TCP_EVT_SYN_RXT, tc, |
| 1355 | (tc->state == TCP_STATE_SYN_SENT ? 0 : 1)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1356 | } |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1357 | else |
| 1358 | { |
| 1359 | ASSERT (tc->state == TCP_STATE_CLOSED); |
| 1360 | clib_warning ("connection closed ..."); |
| 1361 | return; |
| 1362 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1363 | |
| 1364 | if (!is_syn) |
| 1365 | { |
| 1366 | tcp_enqueue_to_output (vm, b, bi, tc->c_is_ip4); |
| 1367 | |
| 1368 | /* Re-enable retransmit timer */ |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 1369 | tcp_retransmit_timer_set (tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1370 | } |
| 1371 | else |
| 1372 | { |
| 1373 | ASSERT (tc->state == TCP_STATE_SYN_SENT); |
| 1374 | |
| 1375 | /* This goes straight to ipx_lookup */ |
| 1376 | tcp_push_ip_hdr (tm, tc, b); |
| 1377 | tcp_enqueue_to_ip_lookup (vm, b, bi, tc->c_is_ip4); |
| 1378 | |
| 1379 | /* Re-enable retransmit timer */ |
| 1380 | tcp_timer_set (tc, TCP_TIMER_RETRANSMIT_SYN, |
| 1381 | tc->rto * TCP_TO_TIMER_TICK); |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | void |
| 1386 | tcp_timer_retransmit_handler (u32 index) |
| 1387 | { |
| 1388 | tcp_timer_retransmit_handler_i (index, 0); |
| 1389 | } |
| 1390 | |
| 1391 | void |
| 1392 | tcp_timer_retransmit_syn_handler (u32 index) |
| 1393 | { |
| 1394 | tcp_timer_retransmit_handler_i (index, 1); |
| 1395 | } |
| 1396 | |
| 1397 | /** |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1398 | * Got 0 snd_wnd from peer, try to do something about it. |
| 1399 | * |
| 1400 | */ |
| 1401 | void |
| 1402 | tcp_timer_persist_handler (u32 index) |
| 1403 | { |
| 1404 | tcp_main_t *tm = vnet_get_tcp_main (); |
| 1405 | vlib_main_t *vm = vlib_get_main (); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1406 | u32 thread_index = vlib_get_thread_index (); |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1407 | tcp_connection_t *tc; |
| 1408 | vlib_buffer_t *b; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1409 | u32 bi, old_snd_nxt, snd_bytes = 0, available_bytes = 0; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1410 | int n_bytes = 0; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1411 | |
Florin Coras | db84e57 | 2017-05-09 18:54:52 -0700 | [diff] [blame] | 1412 | tc = tcp_connection_get_if_valid (index, thread_index); |
| 1413 | |
| 1414 | if (!tc) |
| 1415 | return; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1416 | |
| 1417 | /* Make sure timer handle is set to invalid */ |
| 1418 | tc->timers[TCP_TIMER_PERSIST] = TCP_TIMER_HANDLE_INVALID; |
| 1419 | |
| 1420 | /* Problem already solved or worse */ |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1421 | available_bytes = stream_session_tx_fifo_max_dequeue (&tc->connection); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 1422 | if (tc->state == TCP_STATE_CLOSED || tc->state > TCP_STATE_ESTABLISHED |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1423 | || tc->snd_wnd > tc->snd_mss || tcp_in_recovery (tc) |
| 1424 | || !available_bytes) |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1425 | return; |
| 1426 | |
| 1427 | /* Increment RTO backoff */ |
| 1428 | tc->rto_boff += 1; |
| 1429 | tc->rto = clib_min (tc->rto << 1, TCP_RTO_MAX); |
| 1430 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1431 | /* |
| 1432 | * Try to force the first unsent segment (or buffer) |
| 1433 | */ |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1434 | if (PREDICT_FALSE (tcp_get_free_buffer_index (tm, &bi))) |
| 1435 | return; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1436 | b = vlib_get_buffer (vm, bi); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1437 | |
| 1438 | tcp_validate_txf_size (tc, tc->snd_una_max - tc->snd_una); |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1439 | tc->snd_opts_len = tcp_make_options (tc, &tc->snd_opts, tc->state); |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1440 | snd_bytes = clib_min (tc->snd_mss, tm->bytes_per_buffer); |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1441 | n_bytes = stream_session_peek_bytes (&tc->connection, |
| 1442 | vlib_buffer_get_current (b), |
| 1443 | tc->snd_una_max - tc->snd_una, |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1444 | snd_bytes); |
| 1445 | ASSERT (n_bytes != 0); |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1446 | b->current_length = n_bytes; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1447 | ASSERT (tc->snd_nxt == tc->snd_una_max || tc->rto_boff > 1 |
| 1448 | || tcp_timer_is_active (tc, TCP_TIMER_RETRANSMIT)); |
| 1449 | |
| 1450 | /* Allow updating of snd_una_max but don't update snd_nxt */ |
| 1451 | old_snd_nxt = tc->snd_nxt; |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1452 | tcp_push_hdr_i (tc, b, tc->state, 0); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1453 | tc->snd_nxt = old_snd_nxt; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 1454 | tcp_enqueue_to_output (vm, b, bi, tc->c_is_ip4); |
| 1455 | |
| 1456 | /* Re-enable persist timer */ |
| 1457 | tcp_persist_timer_set (tc); |
| 1458 | } |
| 1459 | |
| 1460 | /** |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1461 | * Retransmit first unacked segment |
| 1462 | */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1463 | void |
| 1464 | tcp_retransmit_first_unacked (tcp_connection_t * tc) |
| 1465 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1466 | vlib_main_t *vm = vlib_get_main (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1467 | vlib_buffer_t *b; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1468 | u32 bi, old_snd_nxt, n_bytes; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1469 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1470 | old_snd_nxt = tc->snd_nxt; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1471 | tc->snd_nxt = tc->snd_una; |
| 1472 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1473 | TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 2); |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1474 | n_bytes = tcp_prepare_retransmit_segment (tc, 0, tc->snd_mss, &b); |
| 1475 | if (!n_bytes) |
| 1476 | return; |
| 1477 | bi = vlib_get_buffer_index (vm, b); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1478 | tcp_enqueue_to_output (vm, b, bi, tc->c_is_ip4); |
Florin Coras | 5921f98 | 2017-04-03 18:00:00 -0700 | [diff] [blame] | 1479 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1480 | tc->snd_nxt = old_snd_nxt; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /** |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1484 | * Do fast retransmit with SACKs |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1485 | */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1486 | void |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1487 | tcp_fast_retransmit_sack (tcp_connection_t * tc) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1488 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1489 | vlib_main_t *vm = vlib_get_main (); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1490 | u32 n_written = 0, offset = 0, max_bytes; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1491 | vlib_buffer_t *b = 0; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1492 | sack_scoreboard_hole_t *hole; |
| 1493 | sack_scoreboard_t *sb; |
| 1494 | u32 bi, old_snd_nxt; |
| 1495 | int snd_space; |
| 1496 | u8 snd_limited = 0, can_rescue = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1497 | |
| 1498 | ASSERT (tcp_in_fastrecovery (tc)); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1499 | TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1500 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1501 | old_snd_nxt = tc->snd_nxt; |
| 1502 | sb = &tc->sack_sb; |
| 1503 | snd_space = tcp_available_snd_space (tc); |
| 1504 | |
| 1505 | hole = scoreboard_get_hole (sb, sb->cur_rxt_hole); |
| 1506 | while (hole && snd_space > 0) |
| 1507 | { |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1508 | hole = scoreboard_next_rxt_hole (sb, hole, |
| 1509 | tcp_fastrecovery_sent_1_smss (tc), |
| 1510 | &can_rescue, &snd_limited); |
| 1511 | if (!hole) |
| 1512 | { |
| 1513 | if (!can_rescue || !(seq_lt (sb->rescue_rxt, tc->snd_una) |
| 1514 | || seq_gt (sb->rescue_rxt, |
| 1515 | tc->snd_congestion))) |
| 1516 | break; |
| 1517 | |
| 1518 | /* If rescue rxt undefined or less than snd_una then one segment of |
| 1519 | * up to SMSS octets that MUST include the highest outstanding |
| 1520 | * unSACKed sequence number SHOULD be returned, and RescueRxt set to |
| 1521 | * RecoveryPoint. HighRxt MUST NOT be updated. |
| 1522 | */ |
| 1523 | max_bytes = clib_min (tc->snd_mss, snd_space); |
| 1524 | offset = tc->snd_congestion - tc->snd_una - max_bytes; |
| 1525 | sb->rescue_rxt = tc->snd_congestion; |
| 1526 | tc->snd_nxt = tc->snd_una + offset; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1527 | n_written = tcp_prepare_retransmit_segment (tc, offset, max_bytes, |
| 1528 | &b); |
| 1529 | ASSERT (n_written); |
| 1530 | bi = vlib_get_buffer_index (vm, b); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1531 | tcp_enqueue_to_output (vm, b, bi, tc->c_is_ip4); |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | max_bytes = snd_limited ? tc->snd_mss : hole->end - sb->high_rxt; |
| 1536 | offset = sb->high_rxt - tc->snd_una; |
| 1537 | tc->snd_nxt = tc->snd_una + offset; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1538 | n_written = tcp_prepare_retransmit_segment (tc, offset, max_bytes, &b); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1539 | |
| 1540 | /* Nothing left to retransmit */ |
| 1541 | if (n_written == 0) |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1542 | break; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1543 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1544 | bi = vlib_get_buffer_index (vm, b); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1545 | sb->high_rxt += n_written; |
| 1546 | tcp_enqueue_to_output (vm, b, bi, tc->c_is_ip4); |
| 1547 | snd_space -= n_written; |
| 1548 | } |
| 1549 | |
| 1550 | /* If window allows, send 1 SMSS of new data */ |
| 1551 | tc->snd_nxt = old_snd_nxt; |
| 1552 | } |
| 1553 | |
| 1554 | /** |
| 1555 | * Fast retransmit without SACK info |
| 1556 | */ |
| 1557 | void |
| 1558 | tcp_fast_retransmit_no_sack (tcp_connection_t * tc) |
| 1559 | { |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1560 | vlib_main_t *vm = vlib_get_main (); |
| 1561 | u32 n_written = 0, offset = 0, bi, old_snd_nxt; |
| 1562 | int snd_space; |
| 1563 | vlib_buffer_t *b; |
| 1564 | |
| 1565 | ASSERT (tcp_in_fastrecovery (tc)); |
| 1566 | TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 0); |
| 1567 | |
| 1568 | /* Start resending from first un-acked segment */ |
| 1569 | old_snd_nxt = tc->snd_nxt; |
| 1570 | tc->snd_nxt = tc->snd_una; |
| 1571 | snd_space = tcp_available_snd_space (tc); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1572 | |
| 1573 | while (snd_space > 0) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1574 | { |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1575 | offset += n_written; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1576 | n_written = tcp_prepare_retransmit_segment (tc, offset, snd_space, &b); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1577 | |
| 1578 | /* Nothing left to retransmit */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1579 | if (n_written == 0) |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1580 | break; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1581 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 1582 | bi = vlib_get_buffer_index (vm, b); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1583 | tcp_enqueue_to_output (vm, b, bi, tc->c_is_ip4); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1584 | snd_space -= n_written; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1585 | } |
| 1586 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1587 | /* Restore snd_nxt. If window allows, send 1 SMSS of new data */ |
| 1588 | tc->snd_nxt = old_snd_nxt; |
| 1589 | } |
| 1590 | |
| 1591 | /** |
| 1592 | * Do fast retransmit |
| 1593 | */ |
| 1594 | void |
| 1595 | tcp_fast_retransmit (tcp_connection_t * tc) |
| 1596 | { |
| 1597 | if (tcp_opts_sack_permitted (&tc->rcv_opts) |
| 1598 | && scoreboard_first_hole (&tc->sack_sb)) |
| 1599 | tcp_fast_retransmit_sack (tc); |
| 1600 | else |
| 1601 | tcp_fast_retransmit_no_sack (tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | always_inline u32 |
| 1605 | tcp_session_has_ooo_data (tcp_connection_t * tc) |
| 1606 | { |
| 1607 | stream_session_t *s = |
| 1608 | stream_session_get (tc->c_s_index, tc->c_thread_index); |
| 1609 | return svm_fifo_has_ooo_data (s->server_rx_fifo); |
| 1610 | } |
| 1611 | |
| 1612 | always_inline uword |
| 1613 | tcp46_output_inline (vlib_main_t * vm, |
| 1614 | vlib_node_runtime_t * node, |
| 1615 | vlib_frame_t * from_frame, int is_ip4) |
| 1616 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1617 | u32 n_left_from, next_index, *from, *to_next; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1618 | u32 my_thread_index = vm->thread_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1619 | |
| 1620 | from = vlib_frame_vector_args (from_frame); |
| 1621 | n_left_from = from_frame->n_vectors; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1622 | next_index = node->cached_next_index; |
Florin Coras | 82d3ec8 | 2017-08-14 08:10:42 -0700 | [diff] [blame] | 1623 | tcp_set_time_now (my_thread_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1624 | |
| 1625 | while (n_left_from > 0) |
| 1626 | { |
| 1627 | u32 n_left_to_next; |
| 1628 | |
| 1629 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 1630 | |
| 1631 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1632 | { |
| 1633 | u32 bi0; |
| 1634 | vlib_buffer_t *b0; |
| 1635 | tcp_connection_t *tc0; |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 1636 | tcp_tx_trace_t *t0; |
| 1637 | tcp_header_t *th0 = 0; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 1638 | u32 error0 = TCP_ERROR_PKTS_SENT, next0 = TCP_OUTPUT_NEXT_IP_LOOKUP; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1639 | |
| 1640 | bi0 = from[0]; |
| 1641 | to_next[0] = bi0; |
| 1642 | from += 1; |
| 1643 | to_next += 1; |
| 1644 | n_left_from -= 1; |
| 1645 | n_left_to_next -= 1; |
| 1646 | |
| 1647 | b0 = vlib_get_buffer (vm, bi0); |
| 1648 | tc0 = tcp_connection_get (vnet_buffer (b0)->tcp.connection_index, |
| 1649 | my_thread_index); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 1650 | if (PREDICT_FALSE (tc0 == 0 || tc0->state == TCP_STATE_CLOSED)) |
| 1651 | { |
| 1652 | error0 = TCP_ERROR_INVALID_CONNECTION; |
| 1653 | next0 = TCP_OUTPUT_NEXT_DROP; |
| 1654 | goto done; |
| 1655 | } |
| 1656 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1657 | th0 = vlib_buffer_get_current (b0); |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1658 | TCP_EVT_DBG (TCP_EVT_OUTPUT, tc0, th0->flags, b0->current_length); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1659 | |
| 1660 | if (is_ip4) |
| 1661 | { |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1662 | vlib_buffer_push_ip4 (vm, b0, &tc0->c_lcl_ip4, &tc0->c_rmt_ip4, |
| 1663 | IP_PROTOCOL_TCP, 1); |
| 1664 | b0->flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 1665 | vnet_buffer (b0)->l4_hdr_offset = (u8 *) th0 - b0->data; |
| 1666 | th0->checksum = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1667 | } |
| 1668 | else |
| 1669 | { |
| 1670 | ip6_header_t *ih0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1671 | ih0 = vlib_buffer_push_ip6 (vm, b0, &tc0->c_lcl_ip6, |
| 1672 | &tc0->c_rmt_ip6, IP_PROTOCOL_TCP); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1673 | b0->flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 1674 | vnet_buffer (b0)->l3_hdr_offset = (u8 *) ih0 - b0->data; |
| 1675 | vnet_buffer (b0)->l4_hdr_offset = (u8 *) th0 - b0->data; |
| 1676 | th0->checksum = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | /* Filter out DUPACKs if there are no OOO segments left */ |
| 1680 | if (PREDICT_FALSE |
| 1681 | (vnet_buffer (b0)->tcp.flags & TCP_BUF_FLAG_DUPACK)) |
| 1682 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1683 | if (!tcp_session_has_ooo_data (tc0)) |
| 1684 | { |
| 1685 | error0 = TCP_ERROR_FILTERED_DUPACKS; |
| 1686 | next0 = TCP_OUTPUT_NEXT_DROP; |
| 1687 | goto done; |
| 1688 | } |
| 1689 | } |
| 1690 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1691 | /* Stop DELACK timer and fix flags */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1692 | tc0->flags &= ~(TCP_CONN_SNDACK); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 1693 | tcp_timer_reset (tc0, TCP_TIMER_DELACK); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1694 | |
| 1695 | /* If not retransmitting |
Florin Coras | 3af90fc | 2017-05-03 21:09:42 -0700 | [diff] [blame] | 1696 | * 1) update snd_una_max (SYN, SYNACK, FIN) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1697 | * 2) If we're not tracking an ACK, start tracking */ |
| 1698 | if (seq_lt (tc0->snd_una_max, tc0->snd_nxt)) |
| 1699 | { |
| 1700 | tc0->snd_una_max = tc0->snd_nxt; |
| 1701 | if (tc0->rtt_ts == 0) |
| 1702 | { |
| 1703 | tc0->rtt_ts = tcp_time_now (); |
| 1704 | tc0->rtt_seq = tc0->snd_nxt; |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | /* Set the retransmit timer if not set already and not |
| 1709 | * doing a pure ACK */ |
| 1710 | if (!tcp_timer_is_active (tc0, TCP_TIMER_RETRANSMIT) |
| 1711 | && tc0->snd_nxt != tc0->snd_una) |
| 1712 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 1713 | tcp_retransmit_timer_set (tc0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1714 | tc0->rto_boff = 0; |
| 1715 | } |
| 1716 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 1717 | #if 0 |
Florin Coras | f6359c8 | 2017-06-19 12:26:09 -0400 | [diff] [blame] | 1718 | /* Make sure we haven't lost route to our peer */ |
| 1719 | if (PREDICT_FALSE (tc0->last_fib_check |
| 1720 | < tc0->snd_opts.tsval + TCP_FIB_RECHECK_PERIOD)) |
| 1721 | { |
| 1722 | if (PREDICT_TRUE |
| 1723 | (tc0->c_rmt_fei == tcp_lookup_rmt_in_fib (tc0))) |
| 1724 | { |
| 1725 | tc0->last_fib_check = tc0->snd_opts.tsval; |
| 1726 | } |
| 1727 | else |
| 1728 | { |
| 1729 | clib_warning ("lost connection to peer"); |
| 1730 | tcp_connection_reset (tc0); |
| 1731 | goto done; |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | /* Use pre-computed dpo to set next node */ |
| 1736 | next0 = tc0->c_rmt_dpo.dpoi_next_node; |
| 1737 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = tc0->c_rmt_dpo.dpoi_index; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 1738 | #endif |
| 1739 | |
| 1740 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0; |
| 1741 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1742 | |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1743 | b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1744 | done: |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1745 | b0->error = node->errors[error0]; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1746 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1747 | { |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 1748 | t0 = vlib_add_trace (vm, node, b0, sizeof (*t0)); |
| 1749 | if (th0) |
| 1750 | { |
| 1751 | clib_memcpy (&t0->tcp_header, th0, sizeof (t0->tcp_header)); |
| 1752 | } |
| 1753 | else |
| 1754 | { |
| 1755 | memset (&t0->tcp_header, 0, sizeof (t0->tcp_header)); |
| 1756 | } |
| 1757 | clib_memcpy (&t0->tcp_connection, tc0, |
| 1758 | sizeof (t0->tcp_connection)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 1762 | n_left_to_next, bi0, next0); |
| 1763 | } |
| 1764 | |
| 1765 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1766 | } |
| 1767 | |
| 1768 | return from_frame->n_vectors; |
| 1769 | } |
| 1770 | |
| 1771 | static uword |
| 1772 | tcp4_output (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1773 | vlib_frame_t * from_frame) |
| 1774 | { |
| 1775 | return tcp46_output_inline (vm, node, from_frame, 1 /* is_ip4 */ ); |
| 1776 | } |
| 1777 | |
| 1778 | static uword |
| 1779 | tcp6_output (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1780 | vlib_frame_t * from_frame) |
| 1781 | { |
| 1782 | return tcp46_output_inline (vm, node, from_frame, 0 /* is_ip4 */ ); |
| 1783 | } |
| 1784 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1785 | /* *INDENT-OFF* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1786 | VLIB_REGISTER_NODE (tcp4_output_node) = |
| 1787 | { |
| 1788 | .function = tcp4_output,.name = "tcp4-output", |
| 1789 | /* Takes a vector of packets. */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1790 | .vector_size = sizeof (u32), |
| 1791 | .n_errors = TCP_N_ERROR, |
| 1792 | .error_strings = tcp_error_strings, |
| 1793 | .n_next_nodes = TCP_OUTPUT_N_NEXT, |
| 1794 | .next_nodes = { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1795 | #define _(s,n) [TCP_OUTPUT_NEXT_##s] = n, |
| 1796 | foreach_tcp4_output_next |
| 1797 | #undef _ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1798 | }, |
| 1799 | .format_buffer = format_tcp_header, |
| 1800 | .format_trace = format_tcp_tx_trace, |
| 1801 | }; |
| 1802 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1803 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1804 | VLIB_NODE_FUNCTION_MULTIARCH (tcp4_output_node, tcp4_output); |
| 1805 | |
| 1806 | /* *INDENT-OFF* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1807 | VLIB_REGISTER_NODE (tcp6_output_node) = |
| 1808 | { |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1809 | .function = tcp6_output, |
| 1810 | .name = "tcp6-output", |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1811 | /* Takes a vector of packets. */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1812 | .vector_size = sizeof (u32), |
| 1813 | .n_errors = TCP_N_ERROR, |
| 1814 | .error_strings = tcp_error_strings, |
| 1815 | .n_next_nodes = TCP_OUTPUT_N_NEXT, |
| 1816 | .next_nodes = { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1817 | #define _(s,n) [TCP_OUTPUT_NEXT_##s] = n, |
| 1818 | foreach_tcp6_output_next |
| 1819 | #undef _ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1820 | }, |
| 1821 | .format_buffer = format_tcp_header, |
| 1822 | .format_trace = format_tcp_tx_trace, |
| 1823 | }; |
| 1824 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1825 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1826 | VLIB_NODE_FUNCTION_MULTIARCH (tcp6_output_node, tcp6_output); |
| 1827 | |
| 1828 | u32 |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1829 | tcp_push_header (transport_connection_t * tconn, vlib_buffer_t * b) |
| 1830 | { |
| 1831 | tcp_connection_t *tc; |
| 1832 | |
| 1833 | tc = (tcp_connection_t *) tconn; |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 1834 | tcp_push_hdr_i (tc, b, TCP_STATE_ESTABLISHED, 0); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1835 | |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 1836 | if (tc->rtt_ts == 0 && !tcp_in_cong_recovery (tc)) |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 1837 | { |
| 1838 | tc->rtt_ts = tcp_time_now (); |
| 1839 | tc->rtt_seq = tc->snd_nxt; |
| 1840 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1841 | return 0; |
| 1842 | } |
| 1843 | |
| 1844 | typedef enum _tcp_reset_next |
| 1845 | { |
| 1846 | TCP_RESET_NEXT_DROP, |
| 1847 | TCP_RESET_NEXT_IP_LOOKUP, |
| 1848 | TCP_RESET_N_NEXT |
| 1849 | } tcp_reset_next_t; |
| 1850 | |
| 1851 | #define foreach_tcp4_reset_next \ |
| 1852 | _(DROP, "error-drop") \ |
| 1853 | _(IP_LOOKUP, "ip4-lookup") |
| 1854 | |
| 1855 | #define foreach_tcp6_reset_next \ |
| 1856 | _(DROP, "error-drop") \ |
| 1857 | _(IP_LOOKUP, "ip6-lookup") |
| 1858 | |
| 1859 | static uword |
| 1860 | tcp46_send_reset_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1861 | vlib_frame_t * from_frame, u8 is_ip4) |
| 1862 | { |
| 1863 | u32 n_left_from, next_index, *from, *to_next; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1864 | u32 my_thread_index = vm->thread_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1865 | |
| 1866 | from = vlib_frame_vector_args (from_frame); |
| 1867 | n_left_from = from_frame->n_vectors; |
| 1868 | |
| 1869 | next_index = node->cached_next_index; |
| 1870 | |
| 1871 | while (n_left_from > 0) |
| 1872 | { |
| 1873 | u32 n_left_to_next; |
| 1874 | |
| 1875 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 1876 | |
| 1877 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1878 | { |
| 1879 | u32 bi0; |
| 1880 | vlib_buffer_t *b0; |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 1881 | tcp_tx_trace_t *t0; |
| 1882 | tcp_header_t *th0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1883 | u32 error0 = TCP_ERROR_RST_SENT, next0 = TCP_RESET_NEXT_IP_LOOKUP; |
| 1884 | |
| 1885 | bi0 = from[0]; |
| 1886 | to_next[0] = bi0; |
| 1887 | from += 1; |
| 1888 | to_next += 1; |
| 1889 | n_left_from -= 1; |
| 1890 | n_left_to_next -= 1; |
| 1891 | |
| 1892 | b0 = vlib_get_buffer (vm, bi0); |
| 1893 | |
| 1894 | if (tcp_make_reset_in_place (vm, b0, vnet_buffer (b0)->tcp.flags, |
| 1895 | my_thread_index, is_ip4)) |
| 1896 | { |
| 1897 | error0 = TCP_ERROR_LOOKUP_DROPS; |
| 1898 | next0 = TCP_RESET_NEXT_DROP; |
| 1899 | goto done; |
| 1900 | } |
| 1901 | |
| 1902 | /* Prepare to send to IP lookup */ |
| 1903 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = 0; |
| 1904 | next0 = TCP_RESET_NEXT_IP_LOOKUP; |
| 1905 | |
| 1906 | done: |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1907 | b0->error = node->errors[error0]; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1908 | b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1909 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1910 | { |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 1911 | th0 = vlib_buffer_get_current (b0); |
| 1912 | if (is_ip4) |
| 1913 | th0 = ip4_next_header ((ip4_header_t *) th0); |
| 1914 | else |
| 1915 | th0 = ip6_next_header ((ip6_header_t *) th0); |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 1916 | t0 = vlib_add_trace (vm, node, b0, sizeof (*t0)); |
| 1917 | clib_memcpy (&t0->tcp_header, th0, sizeof (t0->tcp_header)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 1921 | n_left_to_next, bi0, next0); |
| 1922 | } |
| 1923 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1924 | } |
| 1925 | return from_frame->n_vectors; |
| 1926 | } |
| 1927 | |
| 1928 | static uword |
| 1929 | tcp4_send_reset (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1930 | vlib_frame_t * from_frame) |
| 1931 | { |
| 1932 | return tcp46_send_reset_inline (vm, node, from_frame, 1); |
| 1933 | } |
| 1934 | |
| 1935 | static uword |
| 1936 | tcp6_send_reset (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1937 | vlib_frame_t * from_frame) |
| 1938 | { |
| 1939 | return tcp46_send_reset_inline (vm, node, from_frame, 0); |
| 1940 | } |
| 1941 | |
| 1942 | /* *INDENT-OFF* */ |
| 1943 | VLIB_REGISTER_NODE (tcp4_reset_node) = { |
| 1944 | .function = tcp4_send_reset, |
| 1945 | .name = "tcp4-reset", |
| 1946 | .vector_size = sizeof (u32), |
| 1947 | .n_errors = TCP_N_ERROR, |
| 1948 | .error_strings = tcp_error_strings, |
| 1949 | .n_next_nodes = TCP_RESET_N_NEXT, |
| 1950 | .next_nodes = { |
| 1951 | #define _(s,n) [TCP_RESET_NEXT_##s] = n, |
| 1952 | foreach_tcp4_reset_next |
| 1953 | #undef _ |
| 1954 | }, |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 1955 | .format_trace = format_tcp_tx_trace, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1956 | }; |
| 1957 | /* *INDENT-ON* */ |
| 1958 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1959 | VLIB_NODE_FUNCTION_MULTIARCH (tcp4_reset_node, tcp4_send_reset); |
| 1960 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1961 | /* *INDENT-OFF* */ |
| 1962 | VLIB_REGISTER_NODE (tcp6_reset_node) = { |
| 1963 | .function = tcp6_send_reset, |
| 1964 | .name = "tcp6-reset", |
| 1965 | .vector_size = sizeof (u32), |
| 1966 | .n_errors = TCP_N_ERROR, |
| 1967 | .error_strings = tcp_error_strings, |
| 1968 | .n_next_nodes = TCP_RESET_N_NEXT, |
| 1969 | .next_nodes = { |
| 1970 | #define _(s,n) [TCP_RESET_NEXT_##s] = n, |
| 1971 | foreach_tcp6_reset_next |
| 1972 | #undef _ |
| 1973 | }, |
Clement Durand | 6cf260c | 2017-04-13 13:27:04 +0200 | [diff] [blame] | 1974 | .format_trace = format_tcp_tx_trace, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1975 | }; |
| 1976 | /* *INDENT-ON* */ |
| 1977 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1978 | VLIB_NODE_FUNCTION_MULTIARCH (tcp6_reset_node, tcp6_send_reset); |
| 1979 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1980 | /* |
| 1981 | * fd.io coding-style-patch-verification: ON |
| 1982 | * |
| 1983 | * Local Variables: |
| 1984 | * eval: (c-set-style "gnu") |
| 1985 | * End: |
| 1986 | */ |