Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 SUSE LLC. |
| 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 | #include <vnet/sctp/sctp.h> |
| 16 | #include <vnet/sctp/sctp_debug.h> |
| 17 | |
| 18 | sctp_main_t sctp_main; |
| 19 | |
| 20 | static u32 |
| 21 | sctp_connection_bind (u32 session_index, transport_endpoint_t * tep) |
| 22 | { |
| 23 | sctp_main_t *tm = &sctp_main; |
| 24 | sctp_connection_t *listener; |
| 25 | void *iface_ip; |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 26 | u32 mtu = 1460; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 27 | |
| 28 | pool_get (tm->listener_pool, listener); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 29 | clib_memset (listener, 0, sizeof (*listener)); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 30 | |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 31 | listener->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx = |
| 32 | SCTP_PRIMARY_PATH_IDX; |
| 33 | listener->sub_conn[SCTP_PRIMARY_PATH_IDX].c_c_index = |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 34 | listener - tm->listener_pool; |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 35 | listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.lcl_port = tep->port; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 36 | |
| 37 | /* If we are provided a sw_if_index, bind using one of its IPs */ |
| 38 | if (ip_is_zero (&tep->ip, 1) && tep->sw_if_index != ENDPOINT_INVALID_INDEX) |
| 39 | { |
| 40 | if ((iface_ip = ip_interface_get_first_ip (tep->sw_if_index, |
| 41 | tep->is_ip4))) |
| 42 | ip_set (&tep->ip, iface_ip, tep->is_ip4); |
| 43 | } |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 44 | ip_copy (&listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.lcl_ip, |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 45 | &tep->ip, tep->is_ip4); |
| 46 | |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 47 | if (tep->sw_if_index != ENDPOINT_INVALID_INDEX) |
| 48 | mtu = tep->is_ip4 ? vnet_sw_interface_get_mtu (vnet_get_main (), |
| 49 | tep->sw_if_index, |
| 50 | VNET_MTU_IP4) : |
| 51 | vnet_sw_interface_get_mtu (vnet_get_main (), tep->sw_if_index, |
| 52 | VNET_MTU_IP6); |
| 53 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 54 | listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU = mtu; |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 55 | listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.is_ip4 = tep->is_ip4; |
| 56 | listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto = |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 57 | TRANSPORT_PROTO_SCTP; |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 58 | listener->sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index = session_index; |
| 59 | listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index = |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 60 | tep->fib_index; |
| 61 | listener->state = SCTP_STATE_CLOSED; |
| 62 | |
| 63 | sctp_connection_timers_init (listener); |
| 64 | |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 65 | return listener->sub_conn[SCTP_PRIMARY_PATH_IDX].c_c_index; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | u32 |
| 69 | sctp_session_bind (u32 session_index, transport_endpoint_t * tep) |
| 70 | { |
| 71 | return sctp_connection_bind (session_index, tep); |
| 72 | } |
| 73 | |
| 74 | static void |
| 75 | sctp_connection_unbind (u32 listener_index) |
| 76 | { |
| 77 | sctp_main_t *tm = vnet_get_sctp_main (); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 78 | sctp_connection_t *sctp_conn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 79 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 80 | sctp_conn = pool_elt_at_index (tm->listener_pool, listener_index); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 81 | |
| 82 | /* Poison the entry */ |
| 83 | if (CLIB_DEBUG > 0) |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 84 | clib_memset (sctp_conn, 0xFA, sizeof (*sctp_conn)); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 85 | |
| 86 | pool_put_index (tm->listener_pool, listener_index); |
| 87 | } |
| 88 | |
| 89 | u32 |
| 90 | sctp_session_unbind (u32 listener_index) |
| 91 | { |
| 92 | sctp_connection_unbind (listener_index); |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | sctp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add) |
| 98 | { |
| 99 | sctp_main_t *tm = &sctp_main; |
| 100 | if (is_ip4) |
| 101 | tm->punt_unknown4 = is_add; |
| 102 | else |
| 103 | tm->punt_unknown6 = is_add; |
| 104 | } |
| 105 | |
| 106 | static int |
| 107 | sctp_alloc_custom_local_endpoint (sctp_main_t * tm, ip46_address_t * lcl_addr, |
| 108 | u16 * lcl_port, u8 is_ip4) |
| 109 | { |
| 110 | int index, port; |
| 111 | if (is_ip4) |
| 112 | { |
| 113 | index = tm->last_v4_address_rotor++; |
| 114 | if (tm->last_v4_address_rotor >= vec_len (tm->ip4_src_addresses)) |
| 115 | tm->last_v4_address_rotor = 0; |
| 116 | lcl_addr->ip4.as_u32 = tm->ip4_src_addresses[index].as_u32; |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | index = tm->last_v6_address_rotor++; |
| 121 | if (tm->last_v6_address_rotor >= vec_len (tm->ip6_src_addresses)) |
| 122 | tm->last_v6_address_rotor = 0; |
| 123 | clib_memcpy (&lcl_addr->ip6, &tm->ip6_src_addresses[index], |
| 124 | sizeof (ip6_address_t)); |
| 125 | } |
| 126 | port = transport_alloc_local_port (TRANSPORT_PROTO_SCTP, lcl_addr); |
| 127 | if (port < 1) |
| 128 | { |
| 129 | clib_warning ("Failed to allocate src port"); |
| 130 | return -1; |
| 131 | } |
| 132 | *lcl_port = port; |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Initialize all connection timers as invalid |
| 138 | */ |
| 139 | void |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 140 | sctp_connection_timers_init (sctp_connection_t * sctp_conn) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 141 | { |
| 142 | int i, j; |
| 143 | |
| 144 | /* Set all to invalid */ |
| 145 | for (i = 0; i < MAX_SCTP_CONNECTIONS; i++) |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 146 | { |
| 147 | sctp_conn->sub_conn[i].RTO = SCTP_RTO_INIT; |
Marco Varlese | 21c8baf | 2018-02-02 17:17:51 +0100 | [diff] [blame] | 148 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 149 | for (j = 0; j < SCTP_N_TIMERS; j++) |
| 150 | { |
| 151 | sctp_conn->sub_conn[i].timers[j] = SCTP_TIMER_HANDLE_INVALID; |
| 152 | } |
| 153 | } |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Stop all connection timers |
| 158 | */ |
| 159 | void |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 160 | sctp_connection_timers_reset (sctp_connection_t * sctp_conn) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 161 | { |
| 162 | int i, j; |
| 163 | for (i = 0; i < MAX_SCTP_CONNECTIONS; i++) |
| 164 | { |
| 165 | for (j = 0; j < SCTP_N_TIMERS; j++) |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 166 | sctp_timer_reset (sctp_conn, i, j); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | const char *sctp_fsm_states[] = { |
| 171 | #define _(sym, str) str, |
| 172 | foreach_sctp_fsm_state |
| 173 | #undef _ |
| 174 | }; |
| 175 | |
| 176 | u8 * |
| 177 | format_sctp_state (u8 * s, va_list * args) |
| 178 | { |
| 179 | u32 state = va_arg (*args, u32); |
| 180 | |
| 181 | if (state < SCTP_N_STATES) |
| 182 | s = format (s, "%s", sctp_fsm_states[state]); |
| 183 | else |
| 184 | s = format (s, "UNKNOWN (%d (0x%x))", state, state); |
| 185 | return s; |
| 186 | } |
| 187 | |
| 188 | u8 * |
| 189 | format_sctp_connection_id (u8 * s, va_list * args) |
| 190 | { |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 191 | sctp_connection_t *sctp_conn = va_arg (*args, sctp_connection_t *); |
| 192 | if (!sctp_conn) |
| 193 | return s; |
| 194 | |
| 195 | u8 i; |
| 196 | for (i = 0; i < MAX_SCTP_CONNECTIONS; i++) |
| 197 | { |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 198 | if (i > 0 && sctp_conn->sub_conn[i].state == SCTP_SUBCONN_STATE_DOWN) |
| 199 | continue; |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 200 | if (sctp_conn->sub_conn[i].connection.is_ip4) |
| 201 | { |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 202 | s = format (s, "[#%d][%s] %U:%d->%U:%d", |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 203 | sctp_conn->sub_conn[i].connection.thread_index, |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 204 | "S", |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 205 | format_ip4_address, |
| 206 | &sctp_conn->sub_conn[i].connection.lcl_ip.ip4, |
| 207 | clib_net_to_host_u16 (sctp_conn->sub_conn[i]. |
| 208 | connection.lcl_port), |
| 209 | format_ip4_address, |
| 210 | &sctp_conn->sub_conn[i].connection.rmt_ip.ip4, |
| 211 | clib_net_to_host_u16 (sctp_conn->sub_conn[i]. |
| 212 | connection.rmt_port)); |
| 213 | } |
| 214 | else |
| 215 | { |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 216 | s = format (s, "[#%d][%s] %U:%d->%U:%d", |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 217 | sctp_conn->sub_conn[i].connection.thread_index, |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 218 | "S", |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 219 | format_ip6_address, |
| 220 | &sctp_conn->sub_conn[i].connection.lcl_ip.ip6, |
| 221 | clib_net_to_host_u16 (sctp_conn->sub_conn[i]. |
| 222 | connection.lcl_port), |
| 223 | format_ip6_address, |
| 224 | &sctp_conn->sub_conn[i].connection.rmt_ip.ip6, |
| 225 | clib_net_to_host_u16 (sctp_conn->sub_conn[i]. |
| 226 | connection.rmt_port)); |
| 227 | } |
| 228 | } |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 229 | return s; |
| 230 | } |
| 231 | |
| 232 | u8 * |
| 233 | format_sctp_connection (u8 * s, va_list * args) |
| 234 | { |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 235 | sctp_connection_t *sctp_conn = va_arg (*args, sctp_connection_t *); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 236 | u32 verbose = va_arg (*args, u32); |
| 237 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 238 | if (!sctp_conn) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 239 | return s; |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 240 | s = format (s, "%-50U", format_sctp_connection_id, sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 241 | if (verbose) |
| 242 | { |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 243 | s = format (s, "%-15U", format_sctp_state, sctp_conn->state); |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 244 | if (verbose > 1) |
| 245 | s = format (s, "\n"); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | return s; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Initialize connection send variables. |
| 253 | */ |
| 254 | void |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 255 | sctp_init_snd_vars (sctp_connection_t * sctp_conn) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 256 | { |
| 257 | u32 time_now; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 258 | /* |
| 259 | * We use the time to randomize iss and for setting up the initial |
| 260 | * timestamp. Make sure it's updated otherwise syn and ack in the |
| 261 | * handshake may make it look as if time has flown in the opposite |
| 262 | * direction for us. |
| 263 | */ |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 264 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 265 | sctp_set_time_now (vlib_get_thread_index ()); |
| 266 | time_now = sctp_time_now (); |
| 267 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 268 | sctp_conn->local_initial_tsn = random_u32 (&time_now); |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 269 | sctp_conn->last_unacked_tsn = sctp_conn->local_initial_tsn; |
| 270 | sctp_conn->next_tsn = sctp_conn->local_initial_tsn + 1; |
| 271 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 272 | sctp_conn->remote_initial_tsn = 0x0; |
| 273 | sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | always_inline sctp_connection_t * |
| 277 | sctp_sub_connection_add (u8 thread_index) |
| 278 | { |
| 279 | sctp_main_t *tm = vnet_get_sctp_main (); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 280 | sctp_connection_t *sctp_conn = tm->connections[thread_index]; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 281 | |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 282 | u8 subconn_idx = sctp_next_avail_subconn (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 283 | |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 284 | ASSERT (subconn_idx < MAX_SCTP_CONNECTIONS); |
| 285 | |
| 286 | sctp_conn->sub_conn[subconn_idx].connection.c_index = |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 287 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index; |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 288 | sctp_conn->sub_conn[subconn_idx].connection.thread_index = thread_index; |
| 289 | sctp_conn->sub_conn[subconn_idx].subconn_idx = subconn_idx; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 290 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 291 | return sctp_conn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 292 | } |
| 293 | |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 294 | u8 |
| 295 | sctp_sub_connection_add_ip4 (vlib_main_t * vm, |
| 296 | ip4_address_t * lcl_addr, |
| 297 | ip4_address_t * rmt_addr) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 298 | { |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 299 | sctp_connection_t *sctp_conn = sctp_sub_connection_add (vm->thread_index); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 300 | |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 301 | u8 subconn_idx = sctp_next_avail_subconn (sctp_conn); |
| 302 | |
| 303 | if (subconn_idx == MAX_SCTP_CONNECTIONS) |
| 304 | return SCTP_ERROR_MAX_CONNECTIONS; |
| 305 | |
| 306 | clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.lcl_ip, |
| 307 | &lcl_addr, sizeof (lcl_addr)); |
| 308 | |
| 309 | clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.rmt_ip, |
| 310 | &rmt_addr, sizeof (rmt_addr)); |
Marco Varlese | eacf3cf | 2018-02-26 14:52:25 +0100 | [diff] [blame] | 311 | |
| 312 | sctp_conn->forming_association_changed = 1; |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 313 | |
| 314 | return SCTP_ERROR_NONE; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 317 | u8 |
Marco Varlese | 465c087 | 2018-03-01 14:01:46 +0100 | [diff] [blame] | 318 | sctp_sub_connection_del_ip4 (ip4_address_t * lcl_addr, |
| 319 | ip4_address_t * rmt_addr) |
| 320 | { |
| 321 | sctp_main_t *sctp_main = vnet_get_sctp_main (); |
| 322 | |
| 323 | u32 thread_idx = vlib_get_thread_index (); |
| 324 | u8 i; |
| 325 | |
| 326 | ASSERT (thread_idx == 0); |
| 327 | |
| 328 | for (i = 0; i < MAX_SCTP_CONNECTIONS; i++) |
| 329 | { |
| 330 | sctp_connection_t *sctp_conn = sctp_main->connections[thread_idx]; |
| 331 | sctp_sub_connection_t *sub_conn = |
| 332 | &sctp_main->connections[thread_idx]->sub_conn[i]; |
| 333 | ip46_address_t *lcl_ip = |
| 334 | &sctp_main->connections[thread_idx]->sub_conn[i].connection.lcl_ip; |
| 335 | ip46_address_t *rmt_ip = |
| 336 | &sctp_main->connections[thread_idx]->sub_conn[i].connection.rmt_ip; |
| 337 | |
| 338 | if (!sub_conn->connection.is_ip4) |
| 339 | continue; |
| 340 | if (lcl_ip->ip4.as_u32 == lcl_addr->as_u32 && |
| 341 | rmt_ip->ip4.as_u32 == rmt_addr->as_u32) |
| 342 | { |
| 343 | sub_conn->state = SCTP_SUBCONN_STATE_DOWN; |
| 344 | sctp_conn->forming_association_changed = 1; |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | return SCTP_ERROR_NONE; |
| 349 | } |
| 350 | |
| 351 | u8 |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 352 | sctp_sub_connection_add_ip6 (vlib_main_t * vm, |
| 353 | ip6_address_t * lcl_addr, |
| 354 | ip6_address_t * rmt_addr) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 355 | { |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 356 | sctp_connection_t *sctp_conn = sctp_sub_connection_add (vm->thread_index); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 357 | |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 358 | u8 subconn_idx = sctp_next_avail_subconn (sctp_conn); |
| 359 | |
| 360 | if (subconn_idx == MAX_SCTP_CONNECTIONS) |
| 361 | return SCTP_ERROR_MAX_CONNECTIONS; |
| 362 | |
| 363 | clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.lcl_ip, |
| 364 | &lcl_addr, sizeof (lcl_addr)); |
| 365 | |
| 366 | clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.rmt_ip, |
| 367 | &rmt_addr, sizeof (rmt_addr)); |
Marco Varlese | eacf3cf | 2018-02-26 14:52:25 +0100 | [diff] [blame] | 368 | |
| 369 | sctp_conn->forming_association_changed = 1; |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 370 | |
| 371 | return SCTP_ERROR_NONE; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Marco Varlese | 465c087 | 2018-03-01 14:01:46 +0100 | [diff] [blame] | 374 | u8 |
| 375 | sctp_sub_connection_del_ip6 (ip6_address_t * lcl_addr, |
| 376 | ip6_address_t * rmt_addr) |
| 377 | { |
| 378 | sctp_main_t *sctp_main = vnet_get_sctp_main (); |
| 379 | |
| 380 | u32 thread_idx = vlib_get_thread_index (); |
| 381 | u8 i; |
| 382 | |
| 383 | ASSERT (thread_idx == 0); |
| 384 | |
| 385 | for (i = 0; i < MAX_SCTP_CONNECTIONS; i++) |
| 386 | { |
| 387 | sctp_connection_t *sctp_conn = sctp_main->connections[thread_idx]; |
| 388 | sctp_sub_connection_t *sub_conn = |
| 389 | &sctp_main->connections[thread_idx]->sub_conn[i]; |
| 390 | ip46_address_t *lcl_ip = |
| 391 | &sctp_main->connections[thread_idx]->sub_conn[i].connection.lcl_ip; |
| 392 | ip46_address_t *rmt_ip = |
| 393 | &sctp_main->connections[thread_idx]->sub_conn[i].connection.rmt_ip; |
| 394 | |
| 395 | if (!sub_conn->connection.is_ip4) |
| 396 | continue; |
| 397 | if ((lcl_ip->ip6.as_u64[0] == lcl_addr->as_u64[0] |
| 398 | && lcl_ip->ip6.as_u64[1] == lcl_addr->as_u64[1]) |
| 399 | && (rmt_ip->ip6.as_u64[0] == rmt_addr->as_u64[0] |
| 400 | && rmt_ip->ip6.as_u64[1] == rmt_addr->as_u64[1])) |
| 401 | { |
| 402 | sub_conn->state = SCTP_SUBCONN_STATE_DOWN; |
| 403 | sctp_conn->forming_association_changed = 1; |
| 404 | break; |
| 405 | } |
| 406 | } |
| 407 | return SCTP_ERROR_NONE; |
| 408 | } |
| 409 | |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 410 | u8 |
| 411 | sctp_configure (sctp_user_configuration_t config) |
| 412 | { |
| 413 | sctp_main_t *sctp_main = vnet_get_sctp_main (); |
| 414 | |
| 415 | u32 thread_idx = vlib_get_thread_index (); |
| 416 | |
| 417 | sctp_main->connections[thread_idx]->conn_config.never_delay_sack = |
| 418 | config.never_delay_sack; |
| 419 | sctp_main->connections[thread_idx]->conn_config.never_bundle = |
| 420 | config.never_bundle; |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 425 | sctp_connection_t * |
| 426 | sctp_connection_new (u8 thread_index) |
| 427 | { |
Marco Varlese | 15cc6a8 | 2018-02-21 12:39:52 +0100 | [diff] [blame] | 428 | sctp_main_t *sctp_main = vnet_get_sctp_main (); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 429 | sctp_connection_t *sctp_conn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 430 | |
Marco Varlese | 15cc6a8 | 2018-02-21 12:39:52 +0100 | [diff] [blame] | 431 | pool_get (sctp_main->connections[thread_index], sctp_conn); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 432 | clib_memset (sctp_conn, 0, sizeof (*sctp_conn)); |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 433 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx = |
| 434 | SCTP_PRIMARY_PATH_IDX; |
| 435 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_c_index = |
Marco Varlese | 15cc6a8 | 2018-02-21 12:39:52 +0100 | [diff] [blame] | 436 | sctp_conn - sctp_main->connections[thread_index]; |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 437 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_thread_index = thread_index; |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 438 | sctp_conn->local_tag = 0; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 439 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 440 | return sctp_conn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | sctp_connection_t * |
| 444 | sctp_half_open_connection_new (u8 thread_index) |
| 445 | { |
| 446 | sctp_main_t *tm = vnet_get_sctp_main (); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 447 | sctp_connection_t *sctp_conn = 0; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 448 | ASSERT (vlib_get_thread_index () == 0); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 449 | pool_get (tm->half_open_connections, sctp_conn); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 450 | clib_memset (sctp_conn, 0, sizeof (*sctp_conn)); |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 451 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_c_index = |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 452 | sctp_conn - tm->half_open_connections; |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 453 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx = |
| 454 | SCTP_PRIMARY_PATH_IDX; |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 455 | return sctp_conn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static inline int |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 459 | sctp_connection_open (transport_endpoint_cfg_t * rmt) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 460 | { |
| 461 | sctp_main_t *tm = vnet_get_sctp_main (); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 462 | sctp_connection_t *sctp_conn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 463 | ip46_address_t lcl_addr; |
| 464 | u16 lcl_port; |
| 465 | uword thread_id; |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 466 | u32 mtu = 1460; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 467 | int rv; |
| 468 | |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 469 | u8 idx = SCTP_PRIMARY_PATH_IDX; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 470 | |
| 471 | /* |
| 472 | * Allocate local endpoint |
| 473 | */ |
| 474 | if ((rmt->is_ip4 && vec_len (tm->ip4_src_addresses)) |
| 475 | || (!rmt->is_ip4 && vec_len (tm->ip6_src_addresses))) |
| 476 | rv = sctp_alloc_custom_local_endpoint (tm, &lcl_addr, &lcl_port, |
| 477 | rmt->is_ip4); |
| 478 | else |
| 479 | rv = transport_alloc_local_endpoint (TRANSPORT_PROTO_SCTP, |
| 480 | rmt, &lcl_addr, &lcl_port); |
| 481 | |
| 482 | if (rv) |
| 483 | return -1; |
| 484 | |
| 485 | /* |
| 486 | * Create connection and send INIT CHUNK |
| 487 | */ |
| 488 | thread_id = vlib_get_thread_index (); |
| 489 | ASSERT (thread_id == 0); |
| 490 | |
| 491 | clib_spinlock_lock_if_init (&tm->half_open_lock); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 492 | sctp_conn = sctp_half_open_connection_new (thread_id); |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 493 | if (rmt->peer.sw_if_index != ENDPOINT_INVALID_INDEX) |
| 494 | mtu = rmt->is_ip4 ? vnet_sw_interface_get_mtu (vnet_get_main (), |
| 495 | rmt->peer.sw_if_index, |
| 496 | VNET_MTU_IP4) : |
| 497 | vnet_sw_interface_get_mtu (vnet_get_main (), rmt->peer.sw_if_index, |
| 498 | VNET_MTU_IP6); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 499 | sctp_conn->sub_conn[idx].PMTU = mtu; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 500 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 501 | transport_connection_t *trans_conn = &sctp_conn->sub_conn[idx].connection; |
| 502 | ip_copy (&trans_conn->rmt_ip, &rmt->ip, rmt->is_ip4); |
| 503 | ip_copy (&trans_conn->lcl_ip, &lcl_addr, rmt->is_ip4); |
Marco Varlese | 04e5d64 | 2018-02-23 17:43:06 +0100 | [diff] [blame] | 504 | sctp_conn->sub_conn[idx].subconn_idx = idx; |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 505 | trans_conn->rmt_port = rmt->port; |
| 506 | trans_conn->lcl_port = clib_host_to_net_u16 (lcl_port); |
| 507 | trans_conn->is_ip4 = rmt->is_ip4; |
| 508 | trans_conn->proto = TRANSPORT_PROTO_SCTP; |
| 509 | trans_conn->fib_index = rmt->fib_index; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 510 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 511 | sctp_connection_timers_init (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 512 | /* The other connection vars will be initialized after INIT_ACK chunk received */ |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 513 | sctp_init_snd_vars (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 514 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 515 | sctp_send_init (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 516 | |
| 517 | clib_spinlock_unlock_if_init (&tm->half_open_lock); |
| 518 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 519 | return sctp_conn->sub_conn[idx].connection.c_index; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | /** |
| 523 | * Cleans up connection state. |
| 524 | * |
| 525 | * No notifications. |
| 526 | */ |
| 527 | void |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 528 | sctp_connection_cleanup (sctp_connection_t * sctp_conn) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 529 | { |
| 530 | sctp_main_t *tm = &sctp_main; |
| 531 | u8 i; |
| 532 | |
| 533 | /* Cleanup local endpoint if this was an active connect */ |
| 534 | for (i = 0; i < MAX_SCTP_CONNECTIONS; i++) |
| 535 | transport_endpoint_cleanup (TRANSPORT_PROTO_SCTP, |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 536 | &sctp_conn->sub_conn[i].connection.lcl_ip, |
| 537 | sctp_conn->sub_conn[i].connection.lcl_port); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 538 | |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 539 | int thread_index = |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 540 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.thread_index; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 541 | |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 542 | /* Make sure all timers are cleared */ |
| 543 | sctp_connection_timers_reset (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 544 | |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 545 | /* Poison the entry */ |
| 546 | if (CLIB_DEBUG > 0) |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 547 | clib_memset (sctp_conn, 0xFA, sizeof (*sctp_conn)); |
Marco Varlese | 200fa32 | 2018-02-26 16:33:54 +0100 | [diff] [blame] | 548 | pool_put (tm->connections[thread_index], sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | int |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 552 | sctp_session_open (transport_endpoint_cfg_t * tep) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 553 | { |
| 554 | return sctp_connection_open (tep); |
| 555 | } |
| 556 | |
| 557 | u16 |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 558 | sctp_check_outstanding_data_chunks (sctp_connection_t * sctp_conn) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 559 | { |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 560 | u8 i; |
| 561 | for (i = 0; i < MAX_SCTP_CONNECTIONS; i++) |
| 562 | { |
| 563 | if (sctp_conn->sub_conn[i].state == SCTP_SUBCONN_STATE_DOWN) |
| 564 | continue; |
| 565 | |
| 566 | if (sctp_conn->sub_conn[i].is_retransmitting == 1 || |
| 567 | sctp_conn->sub_conn[i].enqueue_state != SCTP_ERROR_ENQUEUED) |
| 568 | { |
| 569 | SCTP_DBG_OUTPUT |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 570 | ("Connection %u has still DATA to be enqueued inboud / outboud", |
| 571 | sctp_conn->sub_conn[i].connection.c_index); |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 572 | return 1; |
| 573 | } |
| 574 | |
| 575 | } |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 576 | return 0; /* Indicates no more data to be read/sent */ |
| 577 | } |
| 578 | |
| 579 | void |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 580 | sctp_connection_close (sctp_connection_t * sctp_conn) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 581 | { |
| 582 | SCTP_DBG ("Closing connection %u...", |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 583 | sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 584 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 585 | sctp_conn->state = SCTP_STATE_SHUTDOWN_PENDING; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 586 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 587 | sctp_send_shutdown (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | void |
| 591 | sctp_session_close (u32 conn_index, u32 thread_index) |
| 592 | { |
| 593 | ASSERT (thread_index == 0); |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 594 | |
Marco Varlese | 15cc6a8 | 2018-02-21 12:39:52 +0100 | [diff] [blame] | 595 | sctp_connection_t *sctp_conn = |
| 596 | sctp_connection_get (conn_index, thread_index); |
Marco Varlese | a38783e | 2018-02-13 12:38:52 +0100 | [diff] [blame] | 597 | if (sctp_conn != NULL) |
| 598 | sctp_connection_close (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | void |
| 602 | sctp_session_cleanup (u32 conn_index, u32 thread_index) |
| 603 | { |
Marco Varlese | 15cc6a8 | 2018-02-21 12:39:52 +0100 | [diff] [blame] | 604 | sctp_connection_t *sctp_conn = |
| 605 | sctp_connection_get (conn_index, thread_index); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 606 | |
Marco Varlese | a38783e | 2018-02-13 12:38:52 +0100 | [diff] [blame] | 607 | if (sctp_conn != NULL) |
| 608 | { |
| 609 | sctp_connection_timers_reset (sctp_conn); |
| 610 | /* Wait for the session tx events to clear */ |
| 611 | sctp_conn->state = SCTP_STATE_CLOSED; |
| 612 | } |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /** |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 616 | * Compute maximum segment size for session layer. |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 617 | */ |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 618 | u16 |
| 619 | sctp_session_send_mss (transport_connection_t * trans_conn) |
| 620 | { |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 621 | sctp_connection_t *sctp_conn = |
| 622 | sctp_get_connection_from_transport (trans_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 623 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 624 | if (sctp_conn == NULL) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 625 | { |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 626 | SCTP_DBG ("sctp_conn == NULL"); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 627 | return 0; |
| 628 | } |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 629 | |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 630 | update_cwnd (sctp_conn); |
| 631 | update_smallest_pmtu_idx (sctp_conn); |
| 632 | |
Marco Varlese | 6e4d4a3 | 2018-03-12 12:36:59 +0100 | [diff] [blame] | 633 | u8 idx = sctp_data_subconn_select (sctp_conn); |
Marco Varlese | 6e4d4a3 | 2018-03-12 12:36:59 +0100 | [diff] [blame] | 634 | return sctp_conn->sub_conn[idx].cwnd; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | u16 |
| 638 | sctp_snd_space (sctp_connection_t * sctp_conn) |
| 639 | { |
Marco Varlese | 6e4d4a3 | 2018-03-12 12:36:59 +0100 | [diff] [blame] | 640 | /* RFC 4096 Section 6.1; point (A) */ |
| 641 | if (sctp_conn->peer_rwnd == 0) |
| 642 | return 0; |
| 643 | |
| 644 | u8 idx = sctp_data_subconn_select (sctp_conn); |
Marco Varlese | 3e9b465 | 2018-03-13 15:44:56 +0100 | [diff] [blame] | 645 | |
| 646 | u32 available_wnd = |
| 647 | clib_min (sctp_conn->peer_rwnd, sctp_conn->sub_conn[idx].cwnd); |
| 648 | int flight_size = (int) (sctp_conn->next_tsn - sctp_conn->last_unacked_tsn); |
| 649 | |
| 650 | if (available_wnd <= flight_size) |
| 651 | return 0; |
| 652 | |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 653 | /* Finally, let's subtract the DATA chunk headers overhead */ |
Marco Varlese | 3e9b465 | 2018-03-13 15:44:56 +0100 | [diff] [blame] | 654 | return available_wnd - |
| 655 | flight_size - |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 656 | sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_full_hdr_t); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 657 | } |
| 658 | |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 659 | /** |
| 660 | * Compute TX window session is allowed to fill. |
| 661 | */ |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 662 | u32 |
| 663 | sctp_session_send_space (transport_connection_t * trans_conn) |
| 664 | { |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 665 | sctp_connection_t *sctp_conn = |
| 666 | sctp_get_connection_from_transport (trans_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 667 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 668 | return sctp_snd_space (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | transport_connection_t * |
| 672 | sctp_session_get_transport (u32 conn_index, u32 thread_index) |
| 673 | { |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 674 | sctp_connection_t *sctp_conn = |
| 675 | sctp_connection_get (conn_index, thread_index); |
Marco Varlese | 2802bd7 | 2018-02-15 13:45:39 +0100 | [diff] [blame] | 676 | |
| 677 | if (PREDICT_TRUE (sctp_conn != NULL)) |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 678 | return &sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection; |
Marco Varlese | 2802bd7 | 2018-02-15 13:45:39 +0100 | [diff] [blame] | 679 | |
| 680 | return NULL; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | transport_connection_t * |
| 684 | sctp_session_get_listener (u32 listener_index) |
| 685 | { |
| 686 | sctp_main_t *tm = vnet_get_sctp_main (); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 687 | sctp_connection_t *sctp_conn; |
| 688 | sctp_conn = pool_elt_at_index (tm->listener_pool, listener_index); |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 689 | return &sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | u8 * |
| 693 | format_sctp_session (u8 * s, va_list * args) |
| 694 | { |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 695 | u32 tci = va_arg (*args, u32); |
| 696 | u32 thread_index = va_arg (*args, u32); |
| 697 | u32 verbose = va_arg (*args, u32); |
| 698 | sctp_connection_t *tc; |
| 699 | |
| 700 | tc = sctp_connection_get (tci, thread_index); |
| 701 | if (tc) |
| 702 | s = format (s, "%U", format_sctp_connection, tc, verbose); |
| 703 | else |
| 704 | s = format (s, "empty\n"); |
| 705 | return s; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | u8 * |
| 709 | format_sctp_listener_session (u8 * s, va_list * args) |
| 710 | { |
Marco Varlese | f3ab489 | 2018-02-19 15:23:13 +0100 | [diff] [blame] | 711 | u32 tci = va_arg (*args, u32); |
| 712 | sctp_connection_t *tc = sctp_listener_get (tci); |
| 713 | return format (s, "%U", format_sctp_connection_id, tc); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | void |
Marco Varlese | f47276f | 2018-02-06 09:01:39 +0100 | [diff] [blame] | 717 | sctp_expired_timers_cb (u32 conn_index, u32 timer_id) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 718 | { |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 719 | sctp_connection_t *sctp_conn; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 720 | |
Marco Varlese | 9382673 | 2018-09-27 16:43:57 +0200 | [diff] [blame] | 721 | SCTP_DBG ("%s expired", sctp_timer_to_string (timer_id)); |
| 722 | |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 723 | sctp_conn = sctp_connection_get (conn_index, vlib_get_thread_index ()); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 724 | /* note: the connection may have already disappeared */ |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 725 | if (PREDICT_FALSE (sctp_conn == 0)) |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 726 | return; |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 727 | |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 728 | if (sctp_conn->sub_conn[conn_index].unacknowledged_hb > |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 729 | SCTP_PATH_MAX_RETRANS) |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 730 | { |
| 731 | // The remote-peer is considered to be unreachable hence shutting down |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 732 | u8 i, total_subs_down = 1; |
| 733 | for (i = 0; i < MAX_SCTP_CONNECTIONS; i++) |
| 734 | { |
| 735 | if (sctp_conn->sub_conn[i].state == SCTP_SUBCONN_STATE_DOWN) |
| 736 | continue; |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 737 | |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 738 | u32 now = sctp_time_now (); |
| 739 | if (now > (sctp_conn->sub_conn[i].last_seen + SCTP_HB_INTERVAL)) |
| 740 | { |
| 741 | total_subs_down += 1; |
| 742 | sctp_conn->sub_conn[i].state = SCTP_SUBCONN_STATE_DOWN; |
| 743 | } |
| 744 | } |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 745 | |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 746 | if (total_subs_down == MAX_SCTP_CONNECTIONS) |
| 747 | { |
| 748 | /* Start cleanup. App wasn't notified yet so use delete notify as |
| 749 | * opposed to delete to cleanup session layer state. */ |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 750 | session_transport_delete_notify (&sctp_conn->sub_conn |
| 751 | [SCTP_PRIMARY_PATH_IDX].connection); |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 752 | |
Marco Varlese | 54432f8 | 2018-02-15 17:01:56 +0100 | [diff] [blame] | 753 | sctp_connection_timers_reset (sctp_conn); |
| 754 | |
| 755 | sctp_connection_cleanup (sctp_conn); |
| 756 | } |
Marco Varlese | 9e09ff3 | 2018-03-05 12:31:45 +0100 | [diff] [blame] | 757 | return; |
| 758 | } |
| 759 | |
| 760 | switch (timer_id) |
| 761 | { |
| 762 | case SCTP_TIMER_T1_INIT: |
| 763 | sctp_send_init (sctp_conn); |
| 764 | break; |
| 765 | case SCTP_TIMER_T1_COOKIE: |
| 766 | sctp_send_cookie_echo (sctp_conn); |
| 767 | break; |
| 768 | case SCTP_TIMER_T2_SHUTDOWN: |
| 769 | sctp_send_shutdown (sctp_conn); |
| 770 | break; |
| 771 | case SCTP_TIMER_T3_RXTX: |
| 772 | sctp_timer_reset (sctp_conn, conn_index, timer_id); |
Marco Varlese | 3e9b465 | 2018-03-13 15:44:56 +0100 | [diff] [blame] | 773 | sctp_conn->flags |= SCTP_CONN_RECOVERY; |
Marco Varlese | 9e09ff3 | 2018-03-05 12:31:45 +0100 | [diff] [blame] | 774 | sctp_data_retransmit (sctp_conn); |
| 775 | break; |
| 776 | case SCTP_TIMER_T4_HEARTBEAT: |
| 777 | sctp_timer_reset (sctp_conn, conn_index, timer_id); |
| 778 | goto heartbeat; |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 779 | } |
| 780 | return; |
| 781 | |
| 782 | heartbeat: |
| 783 | sctp_send_heartbeat (sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 784 | } |
| 785 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 786 | static void |
| 787 | sctp_expired_timers_dispatch (u32 * expired_timers) |
| 788 | { |
| 789 | int i; |
| 790 | u32 connection_index, timer_id; |
| 791 | |
| 792 | for (i = 0; i < vec_len (expired_timers); i++) |
| 793 | { |
| 794 | /* Get session index and timer id */ |
| 795 | connection_index = expired_timers[i] & 0x0FFFFFFF; |
| 796 | timer_id = expired_timers[i] >> 28; |
| 797 | |
Marco Varlese | f47276f | 2018-02-06 09:01:39 +0100 | [diff] [blame] | 798 | SCTP_DBG ("Expired timer ID: %u", timer_id); |
| 799 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 800 | /* Handle expiration */ |
Marco Varlese | df5a99c | 2018-02-06 13:48:30 +0100 | [diff] [blame] | 801 | sctp_expired_timers_cb (connection_index, timer_id); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
| 805 | void |
| 806 | sctp_initialize_timer_wheels (sctp_main_t * tm) |
| 807 | { |
| 808 | tw_timer_wheel_16t_2w_512sl_t *tw; |
| 809 | /* *INDENT-OFF* */ |
| 810 | foreach_vlib_main (({ |
| 811 | tw = &tm->timer_wheels[ii]; |
| 812 | tw_timer_wheel_init_16t_2w_512sl (tw, sctp_expired_timers_dispatch, |
| 813 | 100e-3 /* timer period 100ms */ , ~0); |
| 814 | tw->last_run_time = vlib_time_now (this_vlib_main); |
| 815 | })); |
| 816 | /* *INDENT-ON* */ |
| 817 | } |
| 818 | |
| 819 | clib_error_t * |
| 820 | sctp_main_enable (vlib_main_t * vm) |
| 821 | { |
| 822 | sctp_main_t *tm = vnet_get_sctp_main (); |
| 823 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
| 824 | clib_error_t *error = 0; |
| 825 | u32 num_threads; |
| 826 | int thread; |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 827 | sctp_connection_t *sctp_conn __attribute__ ((unused)); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 828 | u32 preallocated_connections_per_thread; |
| 829 | |
| 830 | if ((error = vlib_call_init_function (vm, ip_main_init))) |
| 831 | return error; |
| 832 | if ((error = vlib_call_init_function (vm, ip4_lookup_init))) |
| 833 | return error; |
| 834 | if ((error = vlib_call_init_function (vm, ip6_lookup_init))) |
| 835 | return error; |
| 836 | |
| 837 | /* |
| 838 | * Registrations |
| 839 | */ |
| 840 | |
| 841 | ip4_register_protocol (IP_PROTOCOL_SCTP, sctp4_input_node.index); |
| 842 | ip6_register_protocol (IP_PROTOCOL_SCTP, sctp6_input_node.index); |
| 843 | |
| 844 | /* |
| 845 | * Initialize data structures |
| 846 | */ |
| 847 | |
| 848 | num_threads = 1 /* main thread */ + vtm->n_threads; |
| 849 | vec_validate (tm->connections, num_threads - 1); |
| 850 | |
| 851 | /* |
| 852 | * Preallocate connections. Assume that thread 0 won't |
| 853 | * use preallocated threads when running multi-core |
| 854 | */ |
| 855 | if (num_threads == 1) |
| 856 | { |
| 857 | thread = 0; |
| 858 | preallocated_connections_per_thread = tm->preallocated_connections; |
| 859 | } |
| 860 | else |
| 861 | { |
| 862 | thread = 1; |
| 863 | preallocated_connections_per_thread = |
| 864 | tm->preallocated_connections / (num_threads - 1); |
| 865 | } |
| 866 | for (; thread < num_threads; thread++) |
| 867 | { |
| 868 | if (preallocated_connections_per_thread) |
| 869 | pool_init_fixed (tm->connections[thread], |
| 870 | preallocated_connections_per_thread); |
| 871 | } |
| 872 | |
| 873 | /* Initialize per worker thread tx buffers (used for control messages) */ |
| 874 | vec_validate (tm->tx_buffers, num_threads - 1); |
| 875 | |
| 876 | /* Initialize timer wheels */ |
| 877 | vec_validate (tm->timer_wheels, num_threads - 1); |
| 878 | sctp_initialize_timer_wheels (tm); |
| 879 | |
| 880 | /* Initialize clocks per tick for SCTP timestamp. Used to compute |
| 881 | * monotonically increasing timestamps. */ |
| 882 | tm->tstamp_ticks_per_clock = vm->clib_time.seconds_per_clock |
| 883 | / SCTP_TSTAMP_RESOLUTION; |
| 884 | |
| 885 | if (num_threads > 1) |
| 886 | { |
Marco Varlese | f47276f | 2018-02-06 09:01:39 +0100 | [diff] [blame] | 887 | clib_spinlock_init (&tm->half_open_lock); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | vec_validate (tm->tx_frames[0], num_threads - 1); |
| 891 | vec_validate (tm->tx_frames[1], num_threads - 1); |
| 892 | vec_validate (tm->ip_lookup_tx_frames[0], num_threads - 1); |
| 893 | vec_validate (tm->ip_lookup_tx_frames[1], num_threads - 1); |
| 894 | |
Damjan Marion | 671e60e | 2018-12-30 18:09:59 +0100 | [diff] [blame] | 895 | tm->bytes_per_buffer = VLIB_BUFFER_DATA_SIZE; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 896 | |
| 897 | vec_validate (tm->time_now, num_threads - 1); |
| 898 | return error; |
| 899 | } |
| 900 | |
| 901 | clib_error_t * |
| 902 | sctp_enable_disable (vlib_main_t * vm, u8 is_en) |
| 903 | { |
| 904 | if (is_en) |
| 905 | { |
| 906 | if (sctp_main.is_enabled) |
| 907 | return 0; |
| 908 | |
| 909 | return sctp_main_enable (vm); |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | sctp_main.is_enabled = 0; |
| 914 | } |
| 915 | |
| 916 | return 0; |
| 917 | } |
| 918 | |
| 919 | transport_connection_t * |
| 920 | sctp_half_open_session_get_transport (u32 conn_index) |
| 921 | { |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 922 | sctp_connection_t *sctp_conn = sctp_half_open_connection_get (conn_index); |
Marco Varlese | c7fe4f3 | 2018-03-05 15:12:29 +0100 | [diff] [blame] | 923 | return &sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection; |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | u8 * |
| 927 | format_sctp_half_open (u8 * s, va_list * args) |
| 928 | { |
| 929 | u32 tci = va_arg (*args, u32); |
Marco Varlese | 8ad6a2d | 2018-01-26 16:50:01 +0100 | [diff] [blame] | 930 | sctp_connection_t *sctp_conn = sctp_half_open_connection_get (tci); |
| 931 | return format (s, "%U", format_sctp_connection_id, sctp_conn); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 932 | } |
| 933 | |
Marco Varlese | 21c8baf | 2018-02-02 17:17:51 +0100 | [diff] [blame] | 934 | void |
| 935 | sctp_update_time (f64 now, u8 thread_index) |
| 936 | { |
| 937 | sctp_set_time_now (thread_index); |
| 938 | tw_timer_expire_timers_16t_2w_512sl (&sctp_main.timer_wheels[thread_index], |
| 939 | now); |
| 940 | sctp_flush_frames_to_output (thread_index); |
| 941 | } |
| 942 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 943 | /* *INDENT OFF* */ |
| 944 | const static transport_proto_vft_t sctp_proto = { |
| 945 | .enable = sctp_enable_disable, |
| 946 | .bind = sctp_session_bind, |
| 947 | .unbind = sctp_session_unbind, |
| 948 | .open = sctp_session_open, |
| 949 | .close = sctp_session_close, |
| 950 | .cleanup = sctp_session_cleanup, |
| 951 | .push_header = sctp_push_header, |
| 952 | .send_mss = sctp_session_send_mss, |
| 953 | .send_space = sctp_session_send_space, |
Marco Varlese | 21c8baf | 2018-02-02 17:17:51 +0100 | [diff] [blame] | 954 | .update_time = sctp_update_time, |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 955 | .get_connection = sctp_session_get_transport, |
| 956 | .get_listener = sctp_session_get_listener, |
| 957 | .get_half_open = sctp_half_open_session_get_transport, |
| 958 | .format_connection = format_sctp_session, |
| 959 | .format_listener = format_sctp_listener_session, |
| 960 | .format_half_open = format_sctp_half_open, |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 961 | .tx_type = TRANSPORT_TX_DEQUEUE, |
| 962 | .service_type = TRANSPORT_SERVICE_VC, |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 963 | }; |
| 964 | |
| 965 | /* *INDENT ON* */ |
| 966 | |
| 967 | clib_error_t * |
| 968 | sctp_init (vlib_main_t * vm) |
| 969 | { |
| 970 | sctp_main_t *tm = vnet_get_sctp_main (); |
| 971 | ip_main_t *im = &ip_main; |
| 972 | ip_protocol_info_t *pi; |
| 973 | /* Session layer, and by implication SCTP, are disabled by default */ |
| 974 | tm->is_enabled = 0; |
| 975 | |
| 976 | /* Register with IP for header parsing */ |
| 977 | pi = ip_get_protocol_info (im, IP_PROTOCOL_SCTP); |
| 978 | if (pi == 0) |
| 979 | return clib_error_return (0, "SCTP protocol info AWOL"); |
| 980 | pi->format_header = format_sctp_header; |
| 981 | pi->unformat_pg_edit = unformat_pg_sctp_header; |
| 982 | |
| 983 | /* Register as transport with session layer */ |
| 984 | transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto, |
| 985 | FIB_PROTOCOL_IP4, sctp4_output_node.index); |
| 986 | transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto, |
| 987 | FIB_PROTOCOL_IP6, sctp6_output_node.index); |
| 988 | |
Marco Varlese | 3c6a976 | 2018-03-01 11:19:59 +0100 | [diff] [blame] | 989 | sctp_api_reference (); |
| 990 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 991 | return 0; |
| 992 | } |
| 993 | |
| 994 | VLIB_INIT_FUNCTION (sctp_init); |
| 995 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 996 | static clib_error_t * |
| 997 | show_sctp_punt_fn (vlib_main_t * vm, unformat_input_t * input, |
| 998 | vlib_cli_command_t * cmd_arg) |
| 999 | { |
| 1000 | sctp_main_t *tm = &sctp_main; |
| 1001 | if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 1002 | return clib_error_return (0, "unknown input `%U'", format_unformat_error, |
| 1003 | input); |
| 1004 | vlib_cli_output (vm, "IPv4 UDP punt: %s", |
| 1005 | tm->punt_unknown4 ? "enabled" : "disabled"); |
| 1006 | vlib_cli_output (vm, "IPv6 UDP punt: %s", |
| 1007 | tm->punt_unknown6 ? "enabled" : "disabled"); |
| 1008 | return 0; |
| 1009 | } |
| 1010 | /* *INDENT-OFF* */ |
| 1011 | VLIB_CLI_COMMAND (show_tcp_punt_command, static) = |
| 1012 | { |
| 1013 | .path = "show sctp punt", |
| 1014 | .short_help = "show sctp punt", |
| 1015 | .function = show_sctp_punt_fn, |
| 1016 | }; |
| 1017 | /* *INDENT-ON* */ |
| 1018 | |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 1019 | /* |
| 1020 | * fd.io coding-style-patch-verification: ON |
| 1021 | * |
| 1022 | * Local Variables: |
| 1023 | * eval: (c-set-style "gnu") |
| 1024 | * End: |
| 1025 | */ |