Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | * sr_localsid.c: ipv6 segment routing Endpoint behaviors |
| 3 | * |
| 4 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * @file |
| 20 | * @brief Processing of packets with a SRH |
| 21 | * |
| 22 | * CLI to define new Segment Routing End processing functions. |
| 23 | * Graph node to support such functions. |
| 24 | * |
| 25 | * Each function associates an SRv6 segment (IPv6 address) with an specific |
| 26 | * Segment Routing function. |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include <vlib/vlib.h> |
| 31 | #include <vnet/vnet.h> |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 32 | #include <vnet/srv6/sr.h> |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 33 | #include <vnet/ip/ip.h> |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 34 | #include <vnet/srv6/sr_packet.h> |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 35 | #include <vnet/ip/ip6_packet.h> |
| 36 | #include <vnet/fib/ip6_fib.h> |
| 37 | #include <vnet/dpo/dpo.h> |
| 38 | #include <vnet/adj/adj.h> |
| 39 | |
| 40 | #include <vppinfra/error.h> |
| 41 | #include <vppinfra/elog.h> |
| 42 | |
| 43 | /** |
| 44 | * @brief Dynamically added SR localsid DPO type |
| 45 | */ |
| 46 | static dpo_type_t sr_localsid_dpo_type; |
| 47 | static dpo_type_t sr_localsid_d_dpo_type; |
| 48 | |
| 49 | /** |
| 50 | * @brief SR localsid add/del |
| 51 | * |
| 52 | * Function to add or delete SR LocalSIDs. |
| 53 | * |
| 54 | * @param is_del Boolean of whether its a delete instruction |
| 55 | * @param localsid_addr IPv6 address of the localsid |
| 56 | * @param is_decap Boolean of whether decapsulation is allowed in this function |
| 57 | * @param behavior Type of behavior (function) for this localsid |
| 58 | * @param sw_if_index Only for L2/L3 xconnect. OIF. In VRF variant the fib_table. |
| 59 | * @param vlan_index Only for L2 xconnect. Outgoing VLAN tag. |
| 60 | * @param fib_table FIB table in which we should install the localsid entry |
| 61 | * @param nh_addr Next Hop IPv4/IPv6 address. Only for L2/L3 xconnect. |
| 62 | * |
| 63 | * @return 0 on success, error otherwise. |
| 64 | */ |
| 65 | int |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 66 | sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, u16 prefixlen, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 67 | char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, |
| 68 | u32 fib_table, ip46_address_t * nh_addr, void *ls_plugin_mem) |
| 69 | { |
| 70 | ip6_sr_main_t *sm = &sr_main; |
| 71 | uword *p; |
| 72 | int rv; |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 73 | u8 pref_length = 128; |
| 74 | sr_localsid_fn_registration_t *plugin = 0; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 75 | |
| 76 | ip6_sr_localsid_t *ls = 0; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 77 | |
| 78 | dpo_id_t dpo = DPO_INVALID; |
| 79 | |
| 80 | /* Search for the item */ |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 81 | p = mhash_get (&sm->sr_localsids_index_hash, localsid_addr); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 82 | |
| 83 | if (p) |
| 84 | { |
| 85 | if (is_del) |
| 86 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 87 | /* Retrieve localsid */ |
| 88 | ls = pool_elt_at_index (sm->localsids, p[0]); |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 89 | if (ls->behavior >= SR_BEHAVIOR_LAST) |
| 90 | { |
| 91 | plugin = pool_elt_at_index (sm->plugin_functions, |
| 92 | ls->behavior - SR_BEHAVIOR_LAST); |
| 93 | pref_length = plugin->prefix_length; |
| 94 | } |
| 95 | |
| 96 | if (prefixlen != 0) |
| 97 | { |
| 98 | pref_length = prefixlen; |
| 99 | } |
| 100 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 101 | /* Delete FIB entry */ |
| 102 | fib_prefix_t pfx = { |
| 103 | .fp_proto = FIB_PROTOCOL_IP6, |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 104 | .fp_len = pref_length, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 105 | .fp_addr = { |
| 106 | .ip6 = *localsid_addr, |
| 107 | } |
| 108 | }; |
| 109 | |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 110 | fib_table_entry_delete (fib_table_find |
| 111 | (FIB_PROTOCOL_IP6, fib_table), &pfx, |
| 112 | FIB_SOURCE_SR); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 113 | |
| 114 | /* In case it is a Xconnect iface remove the (OIF, NHOP) adj */ |
| 115 | if (ls->behavior == SR_BEHAVIOR_X || ls->behavior == SR_BEHAVIOR_DX6 |
| 116 | || ls->behavior == SR_BEHAVIOR_DX4) |
| 117 | adj_unlock (ls->nh_adj); |
| 118 | |
| 119 | if (ls->behavior >= SR_BEHAVIOR_LAST) |
| 120 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 121 | /* Callback plugin removal function */ |
| 122 | rv = plugin->removal (ls); |
| 123 | } |
| 124 | |
| 125 | /* Delete localsid registry */ |
| 126 | pool_put (sm->localsids, ls); |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 127 | mhash_unset (&sm->sr_localsids_index_hash, localsid_addr, NULL); |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 128 | return 0; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 129 | } |
| 130 | else /* create with function already existing; complain */ |
| 131 | return -1; |
| 132 | } |
| 133 | else |
| 134 | /* delete; localsid does not exist; complain */ |
| 135 | if (is_del) |
| 136 | return -2; |
| 137 | |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 138 | if (behavior >= SR_BEHAVIOR_LAST) |
| 139 | { |
| 140 | sr_localsid_fn_registration_t *plugin = 0; |
| 141 | plugin = |
| 142 | pool_elt_at_index (sm->plugin_functions, behavior - SR_BEHAVIOR_LAST); |
| 143 | pref_length = plugin->prefix_length; |
| 144 | } |
| 145 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 146 | /* Check whether there exists a FIB entry with such address */ |
| 147 | fib_prefix_t pfx = { |
| 148 | .fp_proto = FIB_PROTOCOL_IP6, |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 149 | .fp_len = pref_length, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | pfx.fp_addr.as_u64[0] = localsid_addr->as_u64[0]; |
| 153 | pfx.fp_addr.as_u64[1] = localsid_addr->as_u64[1]; |
| 154 | |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 155 | if (prefixlen != 0) |
| 156 | { |
| 157 | pfx.fp_len = prefixlen; |
| 158 | } |
| 159 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 160 | /* Lookup the FIB index associated to the table id provided */ |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 161 | u32 fib_index = fib_table_find (FIB_PROTOCOL_IP6, fib_table); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 162 | if (fib_index == ~0) |
| 163 | return -3; |
| 164 | |
| 165 | /* Lookup the localsid in such FIB table */ |
| 166 | fib_node_index_t fei = fib_table_lookup_exact_match (fib_index, &pfx); |
| 167 | if (FIB_NODE_INDEX_INVALID != fei) |
| 168 | return -4; //There is an entry for such address (the localsid addr) |
| 169 | |
| 170 | /* Create a new localsid registry */ |
| 171 | pool_get (sm->localsids, ls); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 172 | clib_memset (ls, 0, sizeof (*ls)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 173 | |
| 174 | clib_memcpy (&ls->localsid, localsid_addr, sizeof (ip6_address_t)); |
| 175 | ls->end_psp = end_psp; |
| 176 | ls->behavior = behavior; |
| 177 | ls->nh_adj = (u32) ~ 0; |
| 178 | ls->fib_table = fib_table; |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 179 | ls->localsid_len = pfx.fp_len; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 180 | switch (behavior) |
| 181 | { |
| 182 | case SR_BEHAVIOR_END: |
| 183 | break; |
| 184 | case SR_BEHAVIOR_X: |
| 185 | ls->sw_if_index = sw_if_index; |
| 186 | clib_memcpy (&ls->next_hop.ip6, &nh_addr->ip6, sizeof (ip6_address_t)); |
| 187 | break; |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 188 | case SR_BEHAVIOR_T: |
Neale Ranns | 10e3699 | 2018-02-25 12:39:37 -0800 | [diff] [blame] | 189 | ls->vrf_index = fib_table_find (FIB_PROTOCOL_IP6, sw_if_index); |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 190 | break; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 191 | case SR_BEHAVIOR_DX4: |
| 192 | ls->sw_if_index = sw_if_index; |
| 193 | clib_memcpy (&ls->next_hop.ip4, &nh_addr->ip4, sizeof (ip4_address_t)); |
| 194 | break; |
| 195 | case SR_BEHAVIOR_DX6: |
| 196 | ls->sw_if_index = sw_if_index; |
| 197 | clib_memcpy (&ls->next_hop.ip6, &nh_addr->ip6, sizeof (ip6_address_t)); |
| 198 | break; |
| 199 | case SR_BEHAVIOR_DT6: |
Neale Ranns | 10e3699 | 2018-02-25 12:39:37 -0800 | [diff] [blame] | 200 | ls->vrf_index = fib_table_find (FIB_PROTOCOL_IP6, sw_if_index); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 201 | break; |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 202 | case SR_BEHAVIOR_DT4: |
Neale Ranns | 10e3699 | 2018-02-25 12:39:37 -0800 | [diff] [blame] | 203 | ls->vrf_index = fib_table_find (FIB_PROTOCOL_IP4, sw_if_index); |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 204 | break; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 205 | case SR_BEHAVIOR_DX2: |
| 206 | ls->sw_if_index = sw_if_index; |
| 207 | ls->vlan_index = vlan_index; |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | /* Figure out the adjacency magic for Xconnect variants */ |
| 212 | if (ls->behavior == SR_BEHAVIOR_X || ls->behavior == SR_BEHAVIOR_DX4 |
| 213 | || ls->behavior == SR_BEHAVIOR_DX6) |
| 214 | { |
| 215 | adj_index_t nh_adj_index = ADJ_INDEX_INVALID; |
| 216 | |
| 217 | /* Retrieve the adjacency corresponding to the (OIF, next_hop) */ |
| 218 | if (ls->behavior == SR_BEHAVIOR_DX6 || ls->behavior == SR_BEHAVIOR_X) |
| 219 | nh_adj_index = adj_nbr_add_or_lock (FIB_PROTOCOL_IP6, VNET_LINK_IP6, |
| 220 | nh_addr, sw_if_index); |
| 221 | |
| 222 | else if (ls->behavior == SR_BEHAVIOR_DX4) |
| 223 | nh_adj_index = adj_nbr_add_or_lock (FIB_PROTOCOL_IP4, VNET_LINK_IP4, |
| 224 | nh_addr, sw_if_index); |
| 225 | |
| 226 | /* Check for ADJ creation error. If so panic */ |
| 227 | if (nh_adj_index == ADJ_INDEX_INVALID) |
| 228 | { |
| 229 | pool_put (sm->localsids, ls); |
| 230 | return -5; |
| 231 | } |
| 232 | |
| 233 | ls->nh_adj = nh_adj_index; |
| 234 | } |
| 235 | |
| 236 | /* Set DPO */ |
Ahmed Abdelsalam | 0ae1d80 | 2019-07-25 13:45:55 -0500 | [diff] [blame] | 237 | if (ls->behavior == SR_BEHAVIOR_END || ls->behavior == SR_BEHAVIOR_X |
| 238 | || ls->behavior == SR_BEHAVIOR_T) |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 239 | dpo_set (&dpo, sr_localsid_dpo_type, DPO_PROTO_IP6, ls - sm->localsids); |
| 240 | else if (ls->behavior > SR_BEHAVIOR_D_FIRST |
| 241 | && ls->behavior < SR_BEHAVIOR_LAST) |
| 242 | dpo_set (&dpo, sr_localsid_d_dpo_type, DPO_PROTO_IP6, ls - sm->localsids); |
| 243 | else if (ls->behavior >= SR_BEHAVIOR_LAST) |
| 244 | { |
| 245 | sr_localsid_fn_registration_t *plugin = 0; |
| 246 | plugin = pool_elt_at_index (sm->plugin_functions, |
| 247 | ls->behavior - SR_BEHAVIOR_LAST); |
| 248 | /* Copy the unformat memory result */ |
| 249 | ls->plugin_mem = ls_plugin_mem; |
| 250 | /* Callback plugin creation function */ |
| 251 | rv = plugin->creation (ls); |
| 252 | if (rv) |
| 253 | { |
| 254 | pool_put (sm->localsids, ls); |
| 255 | return -6; |
| 256 | } |
| 257 | dpo_set (&dpo, plugin->dpo, DPO_PROTO_IP6, ls - sm->localsids); |
| 258 | } |
| 259 | |
| 260 | /* Set hash key for searching localsid by address */ |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 261 | mhash_set (&sm->sr_localsids_index_hash, localsid_addr, ls - sm->localsids, |
| 262 | NULL); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 263 | |
| 264 | fib_table_entry_special_dpo_add (fib_index, &pfx, FIB_SOURCE_SR, |
| 265 | FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); |
| 266 | dpo_reset (&dpo); |
| 267 | |
| 268 | /* Set counter to zero */ |
| 269 | vlib_validate_combined_counter (&(sm->sr_ls_valid_counters), |
| 270 | ls - sm->localsids); |
| 271 | vlib_validate_combined_counter (&(sm->sr_ls_invalid_counters), |
| 272 | ls - sm->localsids); |
| 273 | |
| 274 | vlib_zero_combined_counter (&(sm->sr_ls_valid_counters), |
| 275 | ls - sm->localsids); |
| 276 | vlib_zero_combined_counter (&(sm->sr_ls_invalid_counters), |
| 277 | ls - sm->localsids); |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * @brief SR LocalSID CLI function. |
| 284 | * |
| 285 | * @see sr_cli_localsid |
| 286 | */ |
| 287 | static clib_error_t * |
| 288 | sr_cli_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 289 | vlib_cli_command_t * cmd) |
| 290 | { |
| 291 | vnet_main_t *vnm = vnet_get_main (); |
| 292 | ip6_sr_main_t *sm = &sr_main; |
| 293 | u32 sw_if_index = (u32) ~ 0, vlan_index = (u32) ~ 0, fib_index = 0; |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 294 | u16 prefix_len = 0; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 295 | int is_del = 0; |
| 296 | int end_psp = 0; |
| 297 | ip6_address_t resulting_address; |
| 298 | ip46_address_t next_hop; |
| 299 | char address_set = 0; |
| 300 | char behavior = 0; |
| 301 | void *ls_plugin_mem = 0; |
| 302 | |
| 303 | int rv; |
| 304 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 305 | clib_memset (&resulting_address, 0, sizeof (ip6_address_t)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 306 | ip46_address_reset (&next_hop); |
| 307 | |
| 308 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 309 | { |
| 310 | if (unformat (input, "del")) |
| 311 | is_del = 1; |
| 312 | else if (!address_set |
| 313 | && unformat (input, "address %U", unformat_ip6_address, |
| 314 | &resulting_address)) |
| 315 | address_set = 1; |
| 316 | else if (!address_set |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 317 | && unformat (input, "prefix %U/%d", unformat_ip6_address, |
| 318 | &resulting_address, &prefix_len)) |
| 319 | address_set = 1; |
| 320 | else if (!address_set |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 321 | && unformat (input, "addr %U", unformat_ip6_address, |
| 322 | &resulting_address)) |
| 323 | address_set = 1; |
| 324 | else if (unformat (input, "fib-table %u", &fib_index)); |
| 325 | else if (vlan_index == (u32) ~ 0 |
| 326 | && unformat (input, "vlan %u", &vlan_index)); |
| 327 | else if (!behavior && unformat (input, "behavior")) |
| 328 | { |
| 329 | if (unformat (input, "end.x %U %U", |
| 330 | unformat_vnet_sw_interface, vnm, &sw_if_index, |
| 331 | unformat_ip6_address, &next_hop.ip6)) |
| 332 | behavior = SR_BEHAVIOR_X; |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 333 | else if (unformat (input, "end.t %u", &sw_if_index)) |
| 334 | behavior = SR_BEHAVIOR_T; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 335 | else if (unformat (input, "end.dx6 %U %U", |
| 336 | unformat_vnet_sw_interface, vnm, &sw_if_index, |
| 337 | unformat_ip6_address, &next_hop.ip6)) |
| 338 | behavior = SR_BEHAVIOR_DX6; |
| 339 | else if (unformat (input, "end.dx4 %U %U", |
| 340 | unformat_vnet_sw_interface, vnm, &sw_if_index, |
| 341 | unformat_ip4_address, &next_hop.ip4)) |
| 342 | behavior = SR_BEHAVIOR_DX4; |
| 343 | else if (unformat (input, "end.dx2 %U", |
| 344 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 345 | behavior = SR_BEHAVIOR_DX2; |
| 346 | else if (unformat (input, "end.dt6 %u", &sw_if_index)) |
| 347 | behavior = SR_BEHAVIOR_DT6; |
| 348 | else if (unformat (input, "end.dt4 %u", &sw_if_index)) |
| 349 | behavior = SR_BEHAVIOR_DT4; |
| 350 | else |
| 351 | { |
| 352 | /* Loop over all the plugin behavior format functions */ |
| 353 | sr_localsid_fn_registration_t *plugin = 0, **vec_plugins = 0; |
| 354 | sr_localsid_fn_registration_t **plugin_it = 0; |
| 355 | |
| 356 | /* Create a vector out of the plugin pool as recommended */ |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 357 | /* *INDENT-OFF* */ |
| 358 | pool_foreach (plugin, sm->plugin_functions, |
| 359 | { |
| 360 | vec_add1 (vec_plugins, plugin); |
| 361 | }); |
| 362 | /* *INDENT-ON* */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 363 | |
| 364 | vec_foreach (plugin_it, vec_plugins) |
| 365 | { |
| 366 | if (unformat |
| 367 | (input, "%U", (*plugin_it)->ls_unformat, &ls_plugin_mem)) |
| 368 | { |
| 369 | behavior = (*plugin_it)->sr_localsid_function_number; |
| 370 | break; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | if (!behavior) |
| 376 | { |
| 377 | if (unformat (input, "end")) |
| 378 | behavior = SR_BEHAVIOR_END; |
| 379 | else |
| 380 | break; |
| 381 | } |
| 382 | } |
| 383 | else if (!end_psp && unformat (input, "psp")) |
| 384 | end_psp = 1; |
| 385 | else |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | if (!behavior && end_psp) |
| 390 | behavior = SR_BEHAVIOR_END; |
| 391 | |
| 392 | if (!address_set) |
| 393 | return clib_error_return (0, |
| 394 | "Error: SRv6 LocalSID address is mandatory."); |
| 395 | if (!is_del && !behavior) |
| 396 | return clib_error_return (0, |
| 397 | "Error: SRv6 LocalSID behavior is mandatory."); |
| 398 | if (vlan_index != (u32) ~ 0) |
| 399 | return clib_error_return (0, |
| 400 | "Error: SRv6 End.DX2 with rewrite VLAN tag not supported by now."); |
| 401 | if (end_psp && !(behavior == SR_BEHAVIOR_END || behavior == SR_BEHAVIOR_X)) |
| 402 | return clib_error_return (0, |
| 403 | "Error: SRv6 PSP only compatible with End and End.X"); |
| 404 | |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 405 | rv = |
| 406 | sr_cli_localsid (is_del, &resulting_address, prefix_len, end_psp, |
| 407 | behavior, sw_if_index, vlan_index, fib_index, &next_hop, |
| 408 | ls_plugin_mem); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 409 | |
| 410 | switch (rv) |
| 411 | { |
| 412 | case 0: |
| 413 | break; |
| 414 | case 1: |
| 415 | return 0; |
| 416 | case -1: |
| 417 | return clib_error_return (0, |
| 418 | "Identical localsid already exists. Requested localsid not created."); |
| 419 | case -2: |
| 420 | return clib_error_return (0, |
| 421 | "The requested localsid could not be deleted. SR localsid not found"); |
| 422 | case -3: |
| 423 | return clib_error_return (0, "FIB table %u does not exist", fib_index); |
| 424 | case -4: |
| 425 | return clib_error_return (0, "There is already one FIB entry for the" |
| 426 | "requested localsid non segment routing related"); |
| 427 | case -5: |
| 428 | return clib_error_return (0, |
| 429 | "Could not create ARP/ND entry for such next_hop. Internal error."); |
| 430 | case -6: |
| 431 | return clib_error_return (0, |
| 432 | "Error on the plugin based localsid creation."); |
| 433 | default: |
| 434 | return clib_error_return (0, "BUG: sr localsid returns %d", rv); |
| 435 | } |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | /* *INDENT-OFF* */ |
| 440 | VLIB_CLI_COMMAND (sr_localsid_command, static) = { |
| 441 | .path = "sr localsid", |
| 442 | .short_help = "sr localsid (del) address XX:XX::YY:YY" |
| 443 | "(fib-table 8) behavior STRING", |
| 444 | .long_help = |
| 445 | "Create SR LocalSID and binds it to a particular behavior\n" |
| 446 | "Arguments:\n" |
| 447 | "\tlocalSID IPv6_addr(128b) LocalSID IPv6 address\n" |
| 448 | "\t(fib-table X) Optional. VRF where to install SRv6 localsid\n" |
| 449 | "\tbehavior STRING Specifies the behavior\n" |
| 450 | "\n\tBehaviors:\n" |
| 451 | "\tEnd\t-> Endpoint.\n" |
| 452 | "\tEnd.X\t-> Endpoint with decapsulation and Layer-3 cross-connect.\n" |
| 453 | "\t\tParameters: '<iface> <ip6_next_hop>'\n" |
| 454 | "\tEnd.DX2\t-> Endpoint with decapsulation and Layer-2 cross-connect.\n" |
| 455 | "\t\tParameters: '<iface>'\n" |
| 456 | "\tEnd.DX6\t-> Endpoint with decapsulation and IPv6 cross-connect.\n" |
| 457 | "\t\tParameters: '<iface> <ip6_next_hop>'\n" |
| 458 | "\tEnd.DX4\t-> Endpoint with decapsulation and IPv4 cross-connect.\n" |
| 459 | "\t\tParameters: '<iface> <ip4_next_hop>'\n" |
| 460 | "\tEnd.DT6\t-> Endpoint with decapsulation and specific IPv6 table lookup.\n" |
| 461 | "\t\tParameters: '<ip6_fib_table>'\n" |
| 462 | "\tEnd.DT4\t-> Endpoint with decapsulation and specific IPv4 table lookup.\n" |
| 463 | "\t\tParameters: '<ip4_fib_table>'\n", |
| 464 | .function = sr_cli_localsid_command_fn, |
| 465 | }; |
| 466 | /* *INDENT-ON* */ |
| 467 | |
| 468 | /** |
| 469 | * @brief CLI function to 'show' all SR LocalSIDs on console. |
| 470 | */ |
| 471 | static clib_error_t * |
| 472 | show_sr_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 473 | vlib_cli_command_t * cmd) |
| 474 | { |
| 475 | vnet_main_t *vnm = vnet_get_main (); |
| 476 | ip6_sr_main_t *sm = &sr_main; |
| 477 | ip6_sr_localsid_t **localsid_list = 0; |
| 478 | ip6_sr_localsid_t *ls; |
| 479 | int i; |
| 480 | |
| 481 | vlib_cli_output (vm, "SRv6 - My LocalSID Table:"); |
| 482 | vlib_cli_output (vm, "========================="); |
| 483 | /* *INDENT-OFF* */ |
| 484 | pool_foreach (ls, sm->localsids, ({ vec_add1 (localsid_list, ls); })); |
| 485 | /* *INDENT-ON* */ |
| 486 | for (i = 0; i < vec_len (localsid_list); i++) |
| 487 | { |
| 488 | ls = localsid_list[i]; |
| 489 | switch (ls->behavior) |
| 490 | { |
| 491 | case SR_BEHAVIOR_END: |
| 492 | vlib_cli_output (vm, "\tAddress: \t%U\n\tBehavior: \tEnd", |
| 493 | format_ip6_address, &ls->localsid); |
| 494 | break; |
| 495 | case SR_BEHAVIOR_X: |
| 496 | vlib_cli_output (vm, |
| 497 | "\tAddress: \t%U\n\tBehavior: \tX (Endpoint with Layer-3 cross-connect)" |
| 498 | "\n\tIface: \t%U\n\tNext hop: \t%U", |
| 499 | format_ip6_address, &ls->localsid, |
| 500 | format_vnet_sw_if_index_name, vnm, ls->sw_if_index, |
| 501 | format_ip6_address, &ls->next_hop.ip6); |
| 502 | break; |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 503 | case SR_BEHAVIOR_T: |
| 504 | vlib_cli_output (vm, |
| 505 | "\tAddress: \t%U\n\tBehavior: \tT (Endpoint with specific IPv6 table lookup)" |
| 506 | "\n\tTable: \t%u", |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 507 | format_ip6_address, &ls->localsid, ls->vrf_index); |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 508 | break; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 509 | case SR_BEHAVIOR_DX4: |
| 510 | vlib_cli_output (vm, |
| 511 | "\tAddress: \t%U\n\tBehavior: \tDX4 (Endpoint with decapsulation and IPv4 cross-connect)" |
| 512 | "\n\tIface: \t%U\n\tNext hop: \t%U", |
| 513 | format_ip6_address, &ls->localsid, |
| 514 | format_vnet_sw_if_index_name, vnm, ls->sw_if_index, |
| 515 | format_ip4_address, &ls->next_hop.ip4); |
| 516 | break; |
| 517 | case SR_BEHAVIOR_DX6: |
| 518 | vlib_cli_output (vm, |
| 519 | "\tAddress: \t%U\n\tBehavior: \tDX6 (Endpoint with decapsulation and IPv6 cross-connect)" |
| 520 | "\n\tIface: \t%U\n\tNext hop: \t%U", |
| 521 | format_ip6_address, &ls->localsid, |
| 522 | format_vnet_sw_if_index_name, vnm, ls->sw_if_index, |
| 523 | format_ip6_address, &ls->next_hop.ip6); |
| 524 | break; |
| 525 | case SR_BEHAVIOR_DX2: |
| 526 | if (ls->vlan_index == (u32) ~ 0) |
| 527 | vlib_cli_output (vm, |
| 528 | "\tAddress: \t%U\n\tBehavior: \tDX2 (Endpoint with decapulation and Layer-2 cross-connect)" |
| 529 | "\n\tIface: \t%U", format_ip6_address, |
| 530 | &ls->localsid, format_vnet_sw_if_index_name, vnm, |
| 531 | ls->sw_if_index); |
| 532 | else |
| 533 | vlib_cli_output (vm, |
| 534 | "Unsupported yet. (DX2 with egress VLAN rewrite)"); |
| 535 | break; |
| 536 | case SR_BEHAVIOR_DT6: |
| 537 | vlib_cli_output (vm, |
| 538 | "\tAddress: \t%U\n\tBehavior: \tDT6 (Endpoint with decapsulation and specific IPv6 table lookup)" |
| 539 | "\n\tTable: %u", format_ip6_address, &ls->localsid, |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 540 | ls->vrf_index); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 541 | break; |
| 542 | case SR_BEHAVIOR_DT4: |
| 543 | vlib_cli_output (vm, |
| 544 | "\tAddress: \t%U\n\tBehavior: \tDT4 (Endpoint with decapsulation and specific IPv4 table lookup)" |
| 545 | "\n\tTable: \t%u", format_ip6_address, |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 546 | &ls->localsid, ls->vrf_index); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 547 | break; |
| 548 | default: |
| 549 | if (ls->behavior >= SR_BEHAVIOR_LAST) |
| 550 | { |
| 551 | sr_localsid_fn_registration_t *plugin = |
| 552 | pool_elt_at_index (sm->plugin_functions, |
| 553 | ls->behavior - SR_BEHAVIOR_LAST); |
| 554 | |
| 555 | vlib_cli_output (vm, "\tAddress: \t%U\n" |
| 556 | "\tBehavior: \t%s (%s)\n\t%U", |
| 557 | format_ip6_address, &ls->localsid, |
| 558 | plugin->keyword_str, plugin->def_str, |
| 559 | plugin->ls_format, ls->plugin_mem); |
| 560 | } |
| 561 | else |
| 562 | //Should never get here... |
| 563 | vlib_cli_output (vm, "Internal error"); |
| 564 | break; |
| 565 | } |
| 566 | if (ls->end_psp) |
| 567 | vlib_cli_output (vm, "\tPSP: \tTrue\n"); |
| 568 | |
| 569 | /* Print counters */ |
| 570 | vlib_counter_t valid, invalid; |
| 571 | vlib_get_combined_counter (&(sm->sr_ls_valid_counters), i, &valid); |
| 572 | vlib_get_combined_counter (&(sm->sr_ls_invalid_counters), i, &invalid); |
| 573 | vlib_cli_output (vm, "\tGood traffic: \t[%Ld packets : %Ld bytes]\n", |
| 574 | valid.packets, valid.bytes); |
| 575 | vlib_cli_output (vm, "\tBad traffic: \t[%Ld packets : %Ld bytes]\n", |
| 576 | invalid.packets, invalid.bytes); |
| 577 | vlib_cli_output (vm, "--------------------"); |
| 578 | } |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | /* *INDENT-OFF* */ |
| 583 | VLIB_CLI_COMMAND (show_sr_localsid_command, static) = { |
| 584 | .path = "show sr localsids", |
| 585 | .short_help = "show sr localsids", |
| 586 | .function = show_sr_localsid_command_fn, |
| 587 | }; |
| 588 | /* *INDENT-ON* */ |
| 589 | |
| 590 | /** |
| 591 | * @brief Function to 'clear' ALL SR localsid counters |
| 592 | */ |
| 593 | static clib_error_t * |
| 594 | clear_sr_localsid_counters_command_fn (vlib_main_t * vm, |
| 595 | unformat_input_t * input, |
| 596 | vlib_cli_command_t * cmd) |
| 597 | { |
| 598 | ip6_sr_main_t *sm = &sr_main; |
| 599 | |
| 600 | vlib_clear_combined_counters (&(sm->sr_ls_valid_counters)); |
| 601 | vlib_clear_combined_counters (&(sm->sr_ls_invalid_counters)); |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | /* *INDENT-OFF* */ |
| 607 | VLIB_CLI_COMMAND (clear_sr_localsid_counters_command, static) = { |
Francois Clad | 4abc5c3 | 2018-02-01 14:51:33 +0100 | [diff] [blame] | 608 | .path = "clear sr localsid-counters", |
| 609 | .short_help = "clear sr localsid-counters", |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 610 | .function = clear_sr_localsid_counters_command_fn, |
| 611 | }; |
| 612 | /* *INDENT-ON* */ |
| 613 | |
| 614 | /************************ SR LocalSID graphs node ****************************/ |
| 615 | /** |
| 616 | * @brief SR localsid node trace |
| 617 | */ |
| 618 | typedef struct |
| 619 | { |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 620 | ip6_address_t localsid; |
| 621 | u16 behavior; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 622 | u8 sr[256]; |
| 623 | u8 num_segments; |
| 624 | u8 segments_left; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 625 | } sr_localsid_trace_t; |
| 626 | |
| 627 | #define foreach_sr_localsid_error \ |
| 628 | _(NO_INNER_HEADER, "(SR-Error) No inner IP header") \ |
| 629 | _(NO_MORE_SEGMENTS, "(SR-Error) No more segments") \ |
| 630 | _(NO_SRH, "(SR-Error) No SR header") \ |
| 631 | _(NO_PSP, "(SR-Error) PSP Not available (segments left > 0)") \ |
| 632 | _(NOT_LS, "(SR-Error) Decaps not available (segments left > 0)") \ |
| 633 | _(L2, "(SR-Error) SRv6 decapsulated a L2 frame without dest") |
| 634 | |
| 635 | typedef enum |
| 636 | { |
| 637 | #define _(sym,str) SR_LOCALSID_ERROR_##sym, |
| 638 | foreach_sr_localsid_error |
| 639 | #undef _ |
| 640 | SR_LOCALSID_N_ERROR, |
| 641 | } sr_localsid_error_t; |
| 642 | |
| 643 | static char *sr_localsid_error_strings[] = { |
| 644 | #define _(sym,string) string, |
| 645 | foreach_sr_localsid_error |
| 646 | #undef _ |
| 647 | }; |
| 648 | |
| 649 | #define foreach_sr_localsid_next \ |
| 650 | _(ERROR, "error-drop") \ |
| 651 | _(IP6_LOOKUP, "ip6-lookup") \ |
| 652 | _(IP4_LOOKUP, "ip4-lookup") \ |
| 653 | _(IP6_REWRITE, "ip6-rewrite") \ |
| 654 | _(IP4_REWRITE, "ip4-rewrite") \ |
| 655 | _(INTERFACE_OUTPUT, "interface-output") |
| 656 | |
| 657 | typedef enum |
| 658 | { |
| 659 | #define _(s,n) SR_LOCALSID_NEXT_##s, |
| 660 | foreach_sr_localsid_next |
| 661 | #undef _ |
| 662 | SR_LOCALSID_N_NEXT, |
| 663 | } sr_localsid_next_t; |
| 664 | |
| 665 | /** |
| 666 | * @brief SR LocalSID graph node trace function |
| 667 | * |
| 668 | * @see sr_localsid |
| 669 | */ |
| 670 | u8 * |
| 671 | format_sr_localsid_trace (u8 * s, va_list * args) |
| 672 | { |
| 673 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 674 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 675 | sr_localsid_trace_t *t = va_arg (*args, sr_localsid_trace_t *); |
| 676 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 677 | s = |
| 678 | format (s, "SR-LOCALSID:\n\tLocalsid: %U\n", format_ip6_address, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 679 | &t->localsid); |
| 680 | switch (t->behavior) |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 681 | { |
| 682 | case SR_BEHAVIOR_END: |
| 683 | s = format (s, "\tBehavior: End\n"); |
| 684 | break; |
| 685 | case SR_BEHAVIOR_DX6: |
| 686 | s = format (s, "\tBehavior: Decapsulation with IPv6 L3 xconnect\n"); |
| 687 | break; |
| 688 | case SR_BEHAVIOR_DX4: |
| 689 | s = format (s, "\tBehavior: Decapsulation with IPv4 L3 xconnect\n"); |
| 690 | break; |
| 691 | case SR_BEHAVIOR_X: |
| 692 | s = format (s, "\tBehavior: IPv6 L3 xconnect\n"); |
| 693 | break; |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 694 | case SR_BEHAVIOR_T: |
| 695 | s = format (s, "\tBehavior: IPv6 specific table lookup\n"); |
| 696 | break; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 697 | case SR_BEHAVIOR_DT6: |
| 698 | s = format (s, "\tBehavior: Decapsulation with IPv6 Table lookup\n"); |
| 699 | break; |
| 700 | case SR_BEHAVIOR_DT4: |
| 701 | s = format (s, "\tBehavior: Decapsulation with IPv4 Table lookup\n"); |
| 702 | break; |
| 703 | case SR_BEHAVIOR_DX2: |
| 704 | s = format (s, "\tBehavior: Decapsulation with L2 xconnect\n"); |
| 705 | break; |
| 706 | default: |
| 707 | s = format (s, "\tBehavior: defined in plugin\n"); //TODO |
| 708 | break; |
| 709 | } |
| 710 | if (t->num_segments != 0xFF) |
| 711 | { |
| 712 | if (t->num_segments > 0) |
| 713 | { |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 714 | s = format (s, "\tSegments left: %d\n", t->segments_left); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 715 | s = format (s, "\tSID list: [in ietf order]"); |
| 716 | int i = 0; |
| 717 | for (i = 0; i < t->num_segments; i++) |
| 718 | { |
| 719 | s = format (s, "\n\t-> %U", format_ip6_address, |
| 720 | (ip6_address_t *) & t->sr[i * |
| 721 | sizeof (ip6_address_t)]); |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | return s; |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * @brief Function doing End processing. |
| 730 | */ |
| 731 | static_always_inline void |
| 732 | end_srh_processing (vlib_node_runtime_t * node, |
| 733 | vlib_buffer_t * b0, |
| 734 | ip6_header_t * ip0, |
| 735 | ip6_sr_header_t * sr0, |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 736 | ip6_sr_localsid_t * ls0, |
| 737 | u32 * next0, u8 psp, ip6_ext_header_t * prev0) |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 738 | { |
| 739 | ip6_address_t *new_dst0; |
| 740 | |
| 741 | if (PREDICT_TRUE (sr0->type == ROUTING_HEADER_TYPE_SR)) |
| 742 | { |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 743 | if (sr0->segments_left == 1 && psp) |
| 744 | { |
| 745 | u32 new_l0, sr_len; |
| 746 | u64 *copy_dst0, *copy_src0; |
| 747 | u32 copy_len_u64s0 = 0; |
| 748 | |
| 749 | ip0->dst_address.as_u64[0] = sr0->segments->as_u64[0]; |
| 750 | ip0->dst_address.as_u64[1] = sr0->segments->as_u64[1]; |
| 751 | |
| 752 | /* Remove the SRH taking care of the rest of IPv6 ext header */ |
| 753 | if (prev0) |
| 754 | prev0->next_hdr = sr0->protocol; |
| 755 | else |
| 756 | ip0->protocol = sr0->protocol; |
| 757 | |
| 758 | sr_len = ip6_ext_header_len (sr0); |
| 759 | vlib_buffer_advance (b0, sr_len); |
| 760 | new_l0 = clib_net_to_host_u16 (ip0->payload_length) - sr_len; |
| 761 | ip0->payload_length = clib_host_to_net_u16 (new_l0); |
| 762 | copy_src0 = (u64 *) ip0; |
| 763 | copy_dst0 = copy_src0 + (sr0->length + 1); |
| 764 | /* number of 8 octet units to copy |
| 765 | * By default in absence of extension headers it is equal to length of ip6 header |
| 766 | * With extension headers it number of 8 octet units of ext headers preceding |
| 767 | * SR header |
| 768 | */ |
| 769 | copy_len_u64s0 = |
| 770 | (((u8 *) sr0 - (u8 *) ip0) - sizeof (ip6_header_t)) >> 3; |
| 771 | copy_dst0[4 + copy_len_u64s0] = copy_src0[4 + copy_len_u64s0]; |
| 772 | copy_dst0[3 + copy_len_u64s0] = copy_src0[3 + copy_len_u64s0]; |
| 773 | copy_dst0[2 + copy_len_u64s0] = copy_src0[2 + copy_len_u64s0]; |
| 774 | copy_dst0[1 + copy_len_u64s0] = copy_src0[1 + copy_len_u64s0]; |
| 775 | copy_dst0[0 + copy_len_u64s0] = copy_src0[0 + copy_len_u64s0]; |
| 776 | |
| 777 | int i; |
| 778 | for (i = copy_len_u64s0 - 1; i >= 0; i--) |
| 779 | { |
| 780 | copy_dst0[i] = copy_src0[i]; |
| 781 | } |
| 782 | |
| 783 | if (ls0->behavior == SR_BEHAVIOR_X) |
| 784 | { |
| 785 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj; |
| 786 | *next0 = SR_LOCALSID_NEXT_IP6_REWRITE; |
| 787 | } |
| 788 | else if (ls0->behavior == SR_BEHAVIOR_T) |
| 789 | { |
| 790 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->vrf_index; |
| 791 | } |
| 792 | } |
| 793 | else if (PREDICT_TRUE (sr0->segments_left > 0)) |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 794 | { |
| 795 | sr0->segments_left -= 1; |
| 796 | new_dst0 = (ip6_address_t *) (sr0->segments); |
| 797 | new_dst0 += sr0->segments_left; |
| 798 | ip0->dst_address.as_u64[0] = new_dst0->as_u64[0]; |
| 799 | ip0->dst_address.as_u64[1] = new_dst0->as_u64[1]; |
| 800 | |
| 801 | if (ls0->behavior == SR_BEHAVIOR_X) |
| 802 | { |
| 803 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj; |
| 804 | *next0 = SR_LOCALSID_NEXT_IP6_REWRITE; |
| 805 | } |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 806 | else if (ls0->behavior == SR_BEHAVIOR_T) |
| 807 | { |
| 808 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->vrf_index; |
| 809 | } |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 810 | } |
| 811 | else |
| 812 | { |
| 813 | *next0 = SR_LOCALSID_NEXT_ERROR; |
| 814 | b0->error = node->errors[SR_LOCALSID_ERROR_NO_MORE_SEGMENTS]; |
| 815 | } |
| 816 | } |
| 817 | else |
| 818 | { |
| 819 | /* Error. Routing header of type != SR */ |
| 820 | *next0 = SR_LOCALSID_NEXT_ERROR; |
| 821 | b0->error = node->errors[SR_LOCALSID_ERROR_NO_SRH]; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | /* |
| 826 | * @brief Function doing SRH processing for D* variants |
| 827 | */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 828 | static_always_inline void |
| 829 | end_decaps_srh_processing (vlib_node_runtime_t * node, |
| 830 | vlib_buffer_t * b0, |
| 831 | ip6_header_t * ip0, |
| 832 | ip6_sr_header_t * sr0, |
| 833 | ip6_sr_localsid_t * ls0, u32 * next0) |
| 834 | { |
| 835 | /* Compute the size of the IPv6 header with all Ext. headers */ |
| 836 | u8 next_proto; |
| 837 | ip6_ext_header_t *next_ext_header; |
| 838 | u16 total_size = 0; |
| 839 | |
| 840 | next_proto = ip0->protocol; |
| 841 | next_ext_header = (void *) (ip0 + 1); |
| 842 | total_size = sizeof (ip6_header_t); |
| 843 | while (ip6_ext_hdr (next_proto)) |
| 844 | { |
| 845 | total_size += ip6_ext_header_len (next_ext_header); |
| 846 | next_proto = next_ext_header->next_hdr; |
| 847 | next_ext_header = ip6_ext_next_header (next_ext_header); |
| 848 | } |
| 849 | |
| 850 | /* Ensure this is the last segment. Otherwise drop. */ |
| 851 | if (sr0 && sr0->segments_left != 0) |
| 852 | { |
| 853 | *next0 = SR_LOCALSID_NEXT_ERROR; |
| 854 | b0->error = node->errors[SR_LOCALSID_ERROR_NOT_LS]; |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | switch (next_proto) |
| 859 | { |
| 860 | case IP_PROTOCOL_IPV6: |
| 861 | /* Encap-End IPv6. Pop outer IPv6 header. */ |
| 862 | if (ls0->behavior == SR_BEHAVIOR_DX6) |
| 863 | { |
| 864 | vlib_buffer_advance (b0, total_size); |
| 865 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj; |
| 866 | *next0 = SR_LOCALSID_NEXT_IP6_REWRITE; |
| 867 | return; |
| 868 | } |
| 869 | else if (ls0->behavior == SR_BEHAVIOR_DT6) |
| 870 | { |
| 871 | vlib_buffer_advance (b0, total_size); |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 872 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->vrf_index; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 873 | return; |
| 874 | } |
| 875 | break; |
| 876 | case IP_PROTOCOL_IP_IN_IP: |
| 877 | /* Encap-End IPv4. Pop outer IPv6 header */ |
| 878 | if (ls0->behavior == SR_BEHAVIOR_DX4) |
| 879 | { |
| 880 | vlib_buffer_advance (b0, total_size); |
| 881 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj; |
| 882 | *next0 = SR_LOCALSID_NEXT_IP4_REWRITE; |
| 883 | return; |
| 884 | } |
| 885 | else if (ls0->behavior == SR_BEHAVIOR_DT4) |
| 886 | { |
| 887 | vlib_buffer_advance (b0, total_size); |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 888 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->vrf_index; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 889 | *next0 = SR_LOCALSID_NEXT_IP4_LOOKUP; |
| 890 | return; |
| 891 | } |
| 892 | break; |
| 893 | case IP_PROTOCOL_IP6_NONXT: |
| 894 | /* L2 encaps */ |
| 895 | if (ls0->behavior == SR_BEHAVIOR_DX2) |
| 896 | { |
| 897 | vlib_buffer_advance (b0, total_size); |
| 898 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->sw_if_index; |
| 899 | *next0 = SR_LOCALSID_NEXT_INTERFACE_OUTPUT; |
| 900 | return; |
| 901 | } |
| 902 | break; |
| 903 | } |
| 904 | *next0 = SR_LOCALSID_NEXT_ERROR; |
| 905 | b0->error = node->errors[SR_LOCALSID_ERROR_NO_INNER_HEADER]; |
| 906 | return; |
| 907 | } |
| 908 | |
| 909 | /** |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 910 | * @brief SR LocalSID graph node. Supports all default SR Endpoint variants with decaps |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 911 | */ |
| 912 | static uword |
| 913 | sr_localsid_d_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 914 | vlib_frame_t * from_frame) |
| 915 | { |
| 916 | u32 n_left_from, next_index, *from, *to_next; |
| 917 | ip6_sr_main_t *sm = &sr_main; |
| 918 | from = vlib_frame_vector_args (from_frame); |
| 919 | n_left_from = from_frame->n_vectors; |
| 920 | next_index = node->cached_next_index; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 921 | u32 thread_index = vm->thread_index; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 922 | |
| 923 | while (n_left_from > 0) |
| 924 | { |
| 925 | u32 n_left_to_next; |
| 926 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 927 | |
| 928 | /* Quad - Loop */ |
| 929 | while (n_left_from >= 8 && n_left_to_next >= 4) |
| 930 | { |
| 931 | u32 bi0, bi1, bi2, bi3; |
| 932 | vlib_buffer_t *b0, *b1, *b2, *b3; |
| 933 | ip6_header_t *ip0, *ip1, *ip2, *ip3; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 934 | ip6_sr_header_t *sr0, *sr1, *sr2, *sr3; |
| 935 | u32 next0, next1, next2, next3; |
| 936 | next0 = next1 = next2 = next3 = SR_LOCALSID_NEXT_IP6_LOOKUP; |
| 937 | ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3; |
| 938 | |
| 939 | /* Prefetch next iteration. */ |
| 940 | { |
| 941 | vlib_buffer_t *p4, *p5, *p6, *p7; |
| 942 | |
| 943 | p4 = vlib_get_buffer (vm, from[4]); |
| 944 | p5 = vlib_get_buffer (vm, from[5]); |
| 945 | p6 = vlib_get_buffer (vm, from[6]); |
| 946 | p7 = vlib_get_buffer (vm, from[7]); |
| 947 | |
| 948 | /* Prefetch the buffer header and packet for the N+4 loop iteration */ |
| 949 | vlib_prefetch_buffer_header (p4, LOAD); |
| 950 | vlib_prefetch_buffer_header (p5, LOAD); |
| 951 | vlib_prefetch_buffer_header (p6, LOAD); |
| 952 | vlib_prefetch_buffer_header (p7, LOAD); |
| 953 | |
| 954 | CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 955 | CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 956 | CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 957 | CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 958 | } |
| 959 | |
| 960 | to_next[0] = bi0 = from[0]; |
| 961 | to_next[1] = bi1 = from[1]; |
| 962 | to_next[2] = bi2 = from[2]; |
| 963 | to_next[3] = bi3 = from[3]; |
| 964 | from += 4; |
| 965 | to_next += 4; |
| 966 | n_left_from -= 4; |
| 967 | n_left_to_next -= 4; |
| 968 | |
| 969 | b0 = vlib_get_buffer (vm, bi0); |
| 970 | b1 = vlib_get_buffer (vm, bi1); |
| 971 | b2 = vlib_get_buffer (vm, bi2); |
| 972 | b3 = vlib_get_buffer (vm, bi3); |
| 973 | |
| 974 | ls0 = |
| 975 | pool_elt_at_index (sm->localsids, |
| 976 | vnet_buffer (b0)->ip.adj_index[VLIB_TX]); |
| 977 | ls1 = |
| 978 | pool_elt_at_index (sm->localsids, |
Francois Clad | c82b358 | 2018-07-12 09:56:23 +0200 | [diff] [blame] | 979 | vnet_buffer (b1)->ip.adj_index[VLIB_TX]); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 980 | ls2 = |
| 981 | pool_elt_at_index (sm->localsids, |
Francois Clad | c82b358 | 2018-07-12 09:56:23 +0200 | [diff] [blame] | 982 | vnet_buffer (b2)->ip.adj_index[VLIB_TX]); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 983 | ls3 = |
| 984 | pool_elt_at_index (sm->localsids, |
Francois Clad | c82b358 | 2018-07-12 09:56:23 +0200 | [diff] [blame] | 985 | vnet_buffer (b3)->ip.adj_index[VLIB_TX]); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 986 | |
| 987 | ip0 = vlib_buffer_get_current (b0); |
| 988 | ip1 = vlib_buffer_get_current (b1); |
| 989 | ip2 = vlib_buffer_get_current (b2); |
| 990 | ip3 = vlib_buffer_get_current (b3); |
| 991 | |
Klement Sekera | 769145c | 2019-03-06 11:59:57 +0100 | [diff] [blame] | 992 | sr0 = |
| 993 | ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, NULL); |
| 994 | sr1 = |
| 995 | ip6_ext_header_find (vm, b1, ip1, IP_PROTOCOL_IPV6_ROUTE, NULL); |
| 996 | sr2 = |
| 997 | ip6_ext_header_find (vm, b2, ip2, IP_PROTOCOL_IPV6_ROUTE, NULL); |
| 998 | sr3 = |
| 999 | ip6_ext_header_find (vm, b3, ip3, IP_PROTOCOL_IPV6_ROUTE, NULL); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1000 | |
| 1001 | end_decaps_srh_processing (node, b0, ip0, sr0, ls0, &next0); |
| 1002 | end_decaps_srh_processing (node, b1, ip1, sr1, ls1, &next1); |
| 1003 | end_decaps_srh_processing (node, b2, ip2, sr2, ls2, &next2); |
| 1004 | end_decaps_srh_processing (node, b3, ip3, sr3, ls3, &next3); |
| 1005 | |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1006 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1007 | { |
| 1008 | sr_localsid_trace_t *tr = |
| 1009 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 1010 | tr->num_segments = 0; |
| 1011 | clib_memcpy (tr->localsid.as_u8, ls0->localsid.as_u8, |
| 1012 | sizeof (tr->localsid.as_u8)); |
| 1013 | tr->behavior = ls0->behavior; |
| 1014 | if (ip0 == vlib_buffer_get_current (b0)) |
| 1015 | { |
| 1016 | if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1017 | && sr0->type == ROUTING_HEADER_TYPE_SR) |
| 1018 | { |
| 1019 | clib_memcpy (tr->sr, sr0->segments, sr0->length * 8); |
| 1020 | tr->num_segments = |
| 1021 | sr0->length * 8 / sizeof (ip6_address_t); |
| 1022 | tr->segments_left = sr0->segments_left; |
| 1023 | } |
| 1024 | } |
| 1025 | else |
| 1026 | tr->num_segments = 0xFF; |
| 1027 | } |
| 1028 | |
| 1029 | if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 1030 | { |
| 1031 | sr_localsid_trace_t *tr = |
| 1032 | vlib_add_trace (vm, node, b1, sizeof (*tr)); |
| 1033 | tr->num_segments = 0; |
| 1034 | clib_memcpy (tr->localsid.as_u8, ls1->localsid.as_u8, |
| 1035 | sizeof (tr->localsid.as_u8)); |
| 1036 | tr->behavior = ls1->behavior; |
| 1037 | if (ip1 == vlib_buffer_get_current (b1)) |
| 1038 | { |
| 1039 | if (ip1->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1040 | && sr1->type == ROUTING_HEADER_TYPE_SR) |
| 1041 | { |
| 1042 | clib_memcpy (tr->sr, sr1->segments, sr1->length * 8); |
| 1043 | tr->num_segments = |
| 1044 | sr1->length * 8 / sizeof (ip6_address_t); |
| 1045 | tr->segments_left = sr1->segments_left; |
| 1046 | } |
| 1047 | } |
| 1048 | else |
| 1049 | tr->num_segments = 0xFF; |
| 1050 | } |
| 1051 | |
| 1052 | if (PREDICT_FALSE (b2->flags & VLIB_BUFFER_IS_TRACED)) |
| 1053 | { |
| 1054 | sr_localsid_trace_t *tr = |
| 1055 | vlib_add_trace (vm, node, b2, sizeof (*tr)); |
| 1056 | tr->num_segments = 0; |
| 1057 | clib_memcpy (tr->localsid.as_u8, ls2->localsid.as_u8, |
| 1058 | sizeof (tr->localsid.as_u8)); |
| 1059 | tr->behavior = ls2->behavior; |
| 1060 | if (ip2 == vlib_buffer_get_current (b2)) |
| 1061 | { |
| 1062 | if (ip2->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1063 | && sr2->type == ROUTING_HEADER_TYPE_SR) |
| 1064 | { |
| 1065 | clib_memcpy (tr->sr, sr2->segments, sr2->length * 8); |
| 1066 | tr->num_segments = |
| 1067 | sr2->length * 8 / sizeof (ip6_address_t); |
| 1068 | tr->segments_left = sr2->segments_left; |
| 1069 | } |
| 1070 | } |
| 1071 | else |
| 1072 | tr->num_segments = 0xFF; |
| 1073 | } |
| 1074 | |
| 1075 | if (PREDICT_FALSE (b3->flags & VLIB_BUFFER_IS_TRACED)) |
| 1076 | { |
| 1077 | sr_localsid_trace_t *tr = |
| 1078 | vlib_add_trace (vm, node, b3, sizeof (*tr)); |
| 1079 | tr->num_segments = 0; |
| 1080 | clib_memcpy (tr->localsid.as_u8, ls3->localsid.as_u8, |
| 1081 | sizeof (tr->localsid.as_u8)); |
| 1082 | tr->behavior = ls3->behavior; |
| 1083 | if (ip3 == vlib_buffer_get_current (b3)) |
| 1084 | { |
| 1085 | if (ip3->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1086 | && sr3->type == ROUTING_HEADER_TYPE_SR) |
| 1087 | { |
| 1088 | clib_memcpy (tr->sr, sr3->segments, sr3->length * 8); |
| 1089 | tr->num_segments = |
| 1090 | sr3->length * 8 / sizeof (ip6_address_t); |
| 1091 | tr->segments_left = sr3->segments_left; |
| 1092 | } |
| 1093 | } |
| 1094 | else |
| 1095 | tr->num_segments = 0xFF; |
| 1096 | } |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1097 | |
| 1098 | vlib_increment_combined_counter |
| 1099 | (((next0 == |
| 1100 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1101 | &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids, |
| 1102 | 1, vlib_buffer_length_in_chain (vm, b0)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1103 | |
| 1104 | vlib_increment_combined_counter |
| 1105 | (((next1 == |
| 1106 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1107 | &(sm->sr_ls_valid_counters)), thread_index, ls1 - sm->localsids, |
| 1108 | 1, vlib_buffer_length_in_chain (vm, b1)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1109 | |
| 1110 | vlib_increment_combined_counter |
| 1111 | (((next2 == |
| 1112 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1113 | &(sm->sr_ls_valid_counters)), thread_index, ls2 - sm->localsids, |
| 1114 | 1, vlib_buffer_length_in_chain (vm, b2)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1115 | |
| 1116 | vlib_increment_combined_counter |
| 1117 | (((next3 == |
| 1118 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1119 | &(sm->sr_ls_valid_counters)), thread_index, ls3 - sm->localsids, |
| 1120 | 1, vlib_buffer_length_in_chain (vm, b3)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1121 | |
| 1122 | vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next, |
| 1123 | n_left_to_next, bi0, bi1, bi2, bi3, |
| 1124 | next0, next1, next2, next3); |
| 1125 | } |
| 1126 | |
| 1127 | /* Single loop for potentially the last three packets */ |
| 1128 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1129 | { |
| 1130 | u32 bi0; |
| 1131 | vlib_buffer_t *b0; |
| 1132 | ip6_header_t *ip0; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1133 | ip6_sr_header_t *sr0; |
| 1134 | u32 next0 = SR_LOCALSID_NEXT_IP6_LOOKUP; |
| 1135 | ip6_sr_localsid_t *ls0; |
| 1136 | |
| 1137 | bi0 = from[0]; |
| 1138 | to_next[0] = bi0; |
| 1139 | from += 1; |
| 1140 | to_next += 1; |
| 1141 | n_left_from -= 1; |
| 1142 | n_left_to_next -= 1; |
| 1143 | |
| 1144 | b0 = vlib_get_buffer (vm, bi0); |
| 1145 | ip0 = vlib_buffer_get_current (b0); |
| 1146 | |
| 1147 | /* Lookup the SR End behavior based on IP DA (adj) */ |
| 1148 | ls0 = |
| 1149 | pool_elt_at_index (sm->localsids, |
| 1150 | vnet_buffer (b0)->ip.adj_index[VLIB_TX]); |
| 1151 | |
| 1152 | /* Find SRH as well as previous header */ |
Klement Sekera | 769145c | 2019-03-06 11:59:57 +0100 | [diff] [blame] | 1153 | sr0 = |
| 1154 | ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, NULL); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1155 | |
| 1156 | /* SRH processing and End variants */ |
| 1157 | end_decaps_srh_processing (node, b0, ip0, sr0, ls0, &next0); |
| 1158 | |
| 1159 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1160 | { |
| 1161 | sr_localsid_trace_t *tr = |
| 1162 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 1163 | tr->num_segments = 0; |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1164 | clib_memcpy (tr->localsid.as_u8, ls0->localsid.as_u8, |
| 1165 | sizeof (tr->localsid.as_u8)); |
| 1166 | tr->behavior = ls0->behavior; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1167 | if (ip0 == vlib_buffer_get_current (b0)) |
| 1168 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1169 | if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1170 | && sr0->type == ROUTING_HEADER_TYPE_SR) |
| 1171 | { |
| 1172 | clib_memcpy (tr->sr, sr0->segments, sr0->length * 8); |
| 1173 | tr->num_segments = |
| 1174 | sr0->length * 8 / sizeof (ip6_address_t); |
| 1175 | tr->segments_left = sr0->segments_left; |
| 1176 | } |
| 1177 | } |
| 1178 | else |
| 1179 | tr->num_segments = 0xFF; |
| 1180 | } |
| 1181 | |
| 1182 | /* Increase the counters */ |
| 1183 | vlib_increment_combined_counter |
| 1184 | (((next0 == |
| 1185 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1186 | &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids, |
| 1187 | 1, vlib_buffer_length_in_chain (vm, b0)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1188 | |
| 1189 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 1190 | n_left_to_next, bi0, next0); |
| 1191 | } |
| 1192 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1193 | } |
| 1194 | return from_frame->n_vectors; |
| 1195 | } |
| 1196 | |
| 1197 | /* *INDENT-OFF* */ |
| 1198 | VLIB_REGISTER_NODE (sr_localsid_d_node) = { |
| 1199 | .function = sr_localsid_d_fn, |
| 1200 | .name = "sr-localsid-d", |
| 1201 | .vector_size = sizeof (u32), |
| 1202 | .format_trace = format_sr_localsid_trace, |
| 1203 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1204 | .n_errors = SR_LOCALSID_N_ERROR, |
| 1205 | .error_strings = sr_localsid_error_strings, |
| 1206 | .n_next_nodes = SR_LOCALSID_N_NEXT, |
| 1207 | .next_nodes = { |
| 1208 | #define _(s,n) [SR_LOCALSID_NEXT_##s] = n, |
| 1209 | foreach_sr_localsid_next |
| 1210 | #undef _ |
| 1211 | }, |
| 1212 | }; |
| 1213 | /* *INDENT-ON* */ |
| 1214 | |
| 1215 | /** |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1216 | * @brief SR LocalSID graph node. Supports all default SR Endpoint without decaps |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1217 | */ |
| 1218 | static uword |
| 1219 | sr_localsid_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1220 | vlib_frame_t * from_frame) |
| 1221 | { |
| 1222 | u32 n_left_from, next_index, *from, *to_next; |
| 1223 | ip6_sr_main_t *sm = &sr_main; |
| 1224 | from = vlib_frame_vector_args (from_frame); |
| 1225 | n_left_from = from_frame->n_vectors; |
| 1226 | next_index = node->cached_next_index; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 1227 | u32 thread_index = vm->thread_index; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1228 | |
| 1229 | while (n_left_from > 0) |
| 1230 | { |
| 1231 | u32 n_left_to_next; |
| 1232 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 1233 | |
| 1234 | /* Quad - Loop */ |
| 1235 | while (n_left_from >= 8 && n_left_to_next >= 4) |
| 1236 | { |
| 1237 | u32 bi0, bi1, bi2, bi3; |
| 1238 | vlib_buffer_t *b0, *b1, *b2, *b3; |
| 1239 | ip6_header_t *ip0, *ip1, *ip2, *ip3; |
| 1240 | ip6_sr_header_t *sr0, *sr1, *sr2, *sr3; |
| 1241 | ip6_ext_header_t *prev0, *prev1, *prev2, *prev3; |
| 1242 | u32 next0, next1, next2, next3; |
| 1243 | next0 = next1 = next2 = next3 = SR_LOCALSID_NEXT_IP6_LOOKUP; |
| 1244 | ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3; |
| 1245 | |
| 1246 | /* Prefetch next iteration. */ |
| 1247 | { |
| 1248 | vlib_buffer_t *p4, *p5, *p6, *p7; |
| 1249 | |
| 1250 | p4 = vlib_get_buffer (vm, from[4]); |
| 1251 | p5 = vlib_get_buffer (vm, from[5]); |
| 1252 | p6 = vlib_get_buffer (vm, from[6]); |
| 1253 | p7 = vlib_get_buffer (vm, from[7]); |
| 1254 | |
| 1255 | /* Prefetch the buffer header and packet for the N+2 loop iteration */ |
| 1256 | vlib_prefetch_buffer_header (p4, LOAD); |
| 1257 | vlib_prefetch_buffer_header (p5, LOAD); |
| 1258 | vlib_prefetch_buffer_header (p6, LOAD); |
| 1259 | vlib_prefetch_buffer_header (p7, LOAD); |
| 1260 | |
| 1261 | CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 1262 | CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 1263 | CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 1264 | CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 1265 | } |
| 1266 | |
| 1267 | to_next[0] = bi0 = from[0]; |
| 1268 | to_next[1] = bi1 = from[1]; |
| 1269 | to_next[2] = bi2 = from[2]; |
| 1270 | to_next[3] = bi3 = from[3]; |
| 1271 | from += 4; |
| 1272 | to_next += 4; |
| 1273 | n_left_from -= 4; |
| 1274 | n_left_to_next -= 4; |
| 1275 | |
| 1276 | b0 = vlib_get_buffer (vm, bi0); |
| 1277 | b1 = vlib_get_buffer (vm, bi1); |
| 1278 | b2 = vlib_get_buffer (vm, bi2); |
| 1279 | b3 = vlib_get_buffer (vm, bi3); |
| 1280 | |
| 1281 | ip0 = vlib_buffer_get_current (b0); |
| 1282 | ip1 = vlib_buffer_get_current (b1); |
| 1283 | ip2 = vlib_buffer_get_current (b2); |
| 1284 | ip3 = vlib_buffer_get_current (b3); |
| 1285 | |
Klement Sekera | 769145c | 2019-03-06 11:59:57 +0100 | [diff] [blame] | 1286 | sr0 = |
| 1287 | ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, &prev0); |
| 1288 | sr1 = |
| 1289 | ip6_ext_header_find (vm, b1, ip1, IP_PROTOCOL_IPV6_ROUTE, &prev1); |
| 1290 | sr2 = |
| 1291 | ip6_ext_header_find (vm, b2, ip2, IP_PROTOCOL_IPV6_ROUTE, &prev2); |
| 1292 | sr3 = |
| 1293 | ip6_ext_header_find (vm, b3, ip3, IP_PROTOCOL_IPV6_ROUTE, &prev3); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1294 | |
| 1295 | ls0 = |
| 1296 | pool_elt_at_index (sm->localsids, |
| 1297 | vnet_buffer (b0)->ip.adj_index[VLIB_TX]); |
| 1298 | ls1 = |
| 1299 | pool_elt_at_index (sm->localsids, |
Francois Clad | c82b358 | 2018-07-12 09:56:23 +0200 | [diff] [blame] | 1300 | vnet_buffer (b1)->ip.adj_index[VLIB_TX]); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1301 | ls2 = |
| 1302 | pool_elt_at_index (sm->localsids, |
Francois Clad | c82b358 | 2018-07-12 09:56:23 +0200 | [diff] [blame] | 1303 | vnet_buffer (b2)->ip.adj_index[VLIB_TX]); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1304 | ls3 = |
| 1305 | pool_elt_at_index (sm->localsids, |
Francois Clad | c82b358 | 2018-07-12 09:56:23 +0200 | [diff] [blame] | 1306 | vnet_buffer (b3)->ip.adj_index[VLIB_TX]); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1307 | |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 1308 | end_srh_processing (node, b0, ip0, sr0, ls0, &next0, ls0->end_psp, |
| 1309 | prev0); |
| 1310 | end_srh_processing (node, b1, ip1, sr1, ls1, &next1, ls1->end_psp, |
| 1311 | prev1); |
| 1312 | end_srh_processing (node, b2, ip2, sr2, ls2, &next2, ls2->end_psp, |
| 1313 | prev2); |
| 1314 | end_srh_processing (node, b3, ip3, sr3, ls3, &next3, ls3->end_psp, |
| 1315 | prev3); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1316 | |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1317 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1318 | { |
| 1319 | sr_localsid_trace_t *tr = |
| 1320 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 1321 | tr->num_segments = 0; |
| 1322 | clib_memcpy (tr->localsid.as_u8, ls0->localsid.as_u8, |
| 1323 | sizeof (tr->localsid.as_u8)); |
| 1324 | tr->behavior = ls0->behavior; |
| 1325 | if (ip0 == vlib_buffer_get_current (b0)) |
| 1326 | { |
| 1327 | if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1328 | && sr0->type == ROUTING_HEADER_TYPE_SR) |
| 1329 | { |
| 1330 | clib_memcpy (tr->sr, sr0->segments, sr0->length * 8); |
| 1331 | tr->num_segments = |
| 1332 | sr0->length * 8 / sizeof (ip6_address_t); |
| 1333 | tr->segments_left = sr0->segments_left; |
| 1334 | } |
| 1335 | } |
| 1336 | else |
| 1337 | tr->num_segments = 0xFF; |
| 1338 | } |
| 1339 | |
| 1340 | if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 1341 | { |
| 1342 | sr_localsid_trace_t *tr = |
| 1343 | vlib_add_trace (vm, node, b1, sizeof (*tr)); |
| 1344 | tr->num_segments = 0; |
| 1345 | clib_memcpy (tr->localsid.as_u8, ls1->localsid.as_u8, |
| 1346 | sizeof (tr->localsid.as_u8)); |
| 1347 | tr->behavior = ls1->behavior; |
| 1348 | if (ip1 == vlib_buffer_get_current (b1)) |
| 1349 | { |
| 1350 | if (ip1->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1351 | && sr1->type == ROUTING_HEADER_TYPE_SR) |
| 1352 | { |
| 1353 | clib_memcpy (tr->sr, sr1->segments, sr1->length * 8); |
| 1354 | tr->num_segments = |
| 1355 | sr1->length * 8 / sizeof (ip6_address_t); |
| 1356 | tr->segments_left = sr1->segments_left; |
| 1357 | } |
| 1358 | } |
| 1359 | else |
| 1360 | tr->num_segments = 0xFF; |
| 1361 | } |
| 1362 | |
| 1363 | if (PREDICT_FALSE (b2->flags & VLIB_BUFFER_IS_TRACED)) |
| 1364 | { |
| 1365 | sr_localsid_trace_t *tr = |
| 1366 | vlib_add_trace (vm, node, b2, sizeof (*tr)); |
| 1367 | tr->num_segments = 0; |
| 1368 | clib_memcpy (tr->localsid.as_u8, ls2->localsid.as_u8, |
| 1369 | sizeof (tr->localsid.as_u8)); |
| 1370 | tr->behavior = ls2->behavior; |
| 1371 | if (ip2 == vlib_buffer_get_current (b2)) |
| 1372 | { |
| 1373 | if (ip2->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1374 | && sr2->type == ROUTING_HEADER_TYPE_SR) |
| 1375 | { |
| 1376 | clib_memcpy (tr->sr, sr2->segments, sr2->length * 8); |
| 1377 | tr->num_segments = |
| 1378 | sr2->length * 8 / sizeof (ip6_address_t); |
| 1379 | tr->segments_left = sr2->segments_left; |
| 1380 | } |
| 1381 | } |
| 1382 | else |
| 1383 | tr->num_segments = 0xFF; |
| 1384 | } |
| 1385 | |
| 1386 | if (PREDICT_FALSE (b3->flags & VLIB_BUFFER_IS_TRACED)) |
| 1387 | { |
| 1388 | sr_localsid_trace_t *tr = |
| 1389 | vlib_add_trace (vm, node, b3, sizeof (*tr)); |
| 1390 | tr->num_segments = 0; |
| 1391 | clib_memcpy (tr->localsid.as_u8, ls3->localsid.as_u8, |
| 1392 | sizeof (tr->localsid.as_u8)); |
| 1393 | tr->behavior = ls3->behavior; |
| 1394 | if (ip3 == vlib_buffer_get_current (b3)) |
| 1395 | { |
| 1396 | if (ip3->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1397 | && sr3->type == ROUTING_HEADER_TYPE_SR) |
| 1398 | { |
| 1399 | clib_memcpy (tr->sr, sr3->segments, sr3->length * 8); |
| 1400 | tr->num_segments = |
| 1401 | sr3->length * 8 / sizeof (ip6_address_t); |
| 1402 | tr->segments_left = sr3->segments_left; |
| 1403 | } |
| 1404 | } |
| 1405 | else |
| 1406 | tr->num_segments = 0xFF; |
| 1407 | } |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1408 | |
| 1409 | vlib_increment_combined_counter |
| 1410 | (((next0 == |
| 1411 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1412 | &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids, |
| 1413 | 1, vlib_buffer_length_in_chain (vm, b0)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1414 | |
| 1415 | vlib_increment_combined_counter |
| 1416 | (((next1 == |
| 1417 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1418 | &(sm->sr_ls_valid_counters)), thread_index, ls1 - sm->localsids, |
| 1419 | 1, vlib_buffer_length_in_chain (vm, b1)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1420 | |
| 1421 | vlib_increment_combined_counter |
| 1422 | (((next2 == |
| 1423 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1424 | &(sm->sr_ls_valid_counters)), thread_index, ls2 - sm->localsids, |
| 1425 | 1, vlib_buffer_length_in_chain (vm, b2)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1426 | |
| 1427 | vlib_increment_combined_counter |
| 1428 | (((next3 == |
| 1429 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1430 | &(sm->sr_ls_valid_counters)), thread_index, ls3 - sm->localsids, |
| 1431 | 1, vlib_buffer_length_in_chain (vm, b3)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1432 | |
| 1433 | vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next, |
| 1434 | n_left_to_next, bi0, bi1, bi2, bi3, |
| 1435 | next0, next1, next2, next3); |
| 1436 | } |
| 1437 | |
| 1438 | /* Single loop for potentially the last three packets */ |
| 1439 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1440 | { |
| 1441 | u32 bi0; |
| 1442 | vlib_buffer_t *b0; |
| 1443 | ip6_header_t *ip0 = 0; |
| 1444 | ip6_ext_header_t *prev0; |
| 1445 | ip6_sr_header_t *sr0; |
| 1446 | u32 next0 = SR_LOCALSID_NEXT_IP6_LOOKUP; |
| 1447 | ip6_sr_localsid_t *ls0; |
| 1448 | |
| 1449 | bi0 = from[0]; |
| 1450 | to_next[0] = bi0; |
| 1451 | from += 1; |
| 1452 | to_next += 1; |
| 1453 | n_left_from -= 1; |
| 1454 | n_left_to_next -= 1; |
| 1455 | |
| 1456 | b0 = vlib_get_buffer (vm, bi0); |
| 1457 | ip0 = vlib_buffer_get_current (b0); |
Klement Sekera | 769145c | 2019-03-06 11:59:57 +0100 | [diff] [blame] | 1458 | sr0 = |
| 1459 | ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, &prev0); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1460 | |
| 1461 | /* Lookup the SR End behavior based on IP DA (adj) */ |
| 1462 | ls0 = |
| 1463 | pool_elt_at_index (sm->localsids, |
| 1464 | vnet_buffer (b0)->ip.adj_index[VLIB_TX]); |
| 1465 | |
| 1466 | /* SRH processing */ |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 1467 | end_srh_processing (node, b0, ip0, sr0, ls0, &next0, ls0->end_psp, |
| 1468 | prev0); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1469 | |
| 1470 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1471 | { |
| 1472 | sr_localsid_trace_t *tr = |
| 1473 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 1474 | tr->num_segments = 0; |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1475 | clib_memcpy (tr->localsid.as_u8, ls0->localsid.as_u8, |
| 1476 | sizeof (tr->localsid.as_u8)); |
| 1477 | tr->behavior = ls0->behavior; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1478 | if (ip0 == vlib_buffer_get_current (b0)) |
| 1479 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1480 | if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE |
| 1481 | && sr0->type == ROUTING_HEADER_TYPE_SR) |
| 1482 | { |
| 1483 | clib_memcpy (tr->sr, sr0->segments, sr0->length * 8); |
| 1484 | tr->num_segments = |
| 1485 | sr0->length * 8 / sizeof (ip6_address_t); |
| 1486 | tr->segments_left = sr0->segments_left; |
| 1487 | } |
| 1488 | } |
| 1489 | else |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1490 | tr->num_segments = 0xFF; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | vlib_increment_combined_counter |
| 1494 | (((next0 == |
| 1495 | SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) : |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1496 | &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids, |
| 1497 | 1, vlib_buffer_length_in_chain (vm, b0)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1498 | |
| 1499 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 1500 | n_left_to_next, bi0, next0); |
| 1501 | } |
| 1502 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1503 | } |
| 1504 | return from_frame->n_vectors; |
| 1505 | } |
| 1506 | |
| 1507 | /* *INDENT-OFF* */ |
| 1508 | VLIB_REGISTER_NODE (sr_localsid_node) = { |
| 1509 | .function = sr_localsid_fn, |
| 1510 | .name = "sr-localsid", |
| 1511 | .vector_size = sizeof (u32), |
| 1512 | .format_trace = format_sr_localsid_trace, |
| 1513 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1514 | .n_errors = SR_LOCALSID_N_ERROR, |
| 1515 | .error_strings = sr_localsid_error_strings, |
| 1516 | .n_next_nodes = SR_LOCALSID_N_NEXT, |
| 1517 | .next_nodes = { |
| 1518 | #define _(s,n) [SR_LOCALSID_NEXT_##s] = n, |
| 1519 | foreach_sr_localsid_next |
| 1520 | #undef _ |
| 1521 | }, |
| 1522 | }; |
| 1523 | /* *INDENT-ON* */ |
| 1524 | |
| 1525 | static u8 * |
| 1526 | format_sr_dpo (u8 * s, va_list * args) |
| 1527 | { |
| 1528 | index_t index = va_arg (*args, index_t); |
| 1529 | CLIB_UNUSED (u32 indent) = va_arg (*args, u32); |
| 1530 | |
| 1531 | return (format (s, "SR: localsid_index:[%d]", index)); |
| 1532 | } |
| 1533 | |
| 1534 | const static dpo_vft_t sr_loc_vft = { |
| 1535 | .dv_lock = sr_dpo_lock, |
| 1536 | .dv_unlock = sr_dpo_unlock, |
| 1537 | .dv_format = format_sr_dpo, |
| 1538 | }; |
| 1539 | |
| 1540 | const static char *const sr_loc_ip6_nodes[] = { |
| 1541 | "sr-localsid", |
| 1542 | NULL, |
| 1543 | }; |
| 1544 | |
| 1545 | const static char *const *const sr_loc_nodes[DPO_PROTO_NUM] = { |
| 1546 | [DPO_PROTO_IP6] = sr_loc_ip6_nodes, |
| 1547 | }; |
| 1548 | |
| 1549 | const static char *const sr_loc_d_ip6_nodes[] = { |
| 1550 | "sr-localsid-d", |
| 1551 | NULL, |
| 1552 | }; |
| 1553 | |
| 1554 | const static char *const *const sr_loc_d_nodes[DPO_PROTO_NUM] = { |
| 1555 | [DPO_PROTO_IP6] = sr_loc_d_ip6_nodes, |
| 1556 | }; |
| 1557 | |
| 1558 | |
| 1559 | /*************************** SR LocalSID plugins ******************************/ |
| 1560 | /** |
| 1561 | * @brief SR LocalSID plugin registry |
| 1562 | */ |
| 1563 | int |
| 1564 | sr_localsid_register_function (vlib_main_t * vm, u8 * fn_name, |
| 1565 | u8 * keyword_str, u8 * def_str, |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 1566 | u8 * params_str, u8 prefix_length, |
| 1567 | dpo_type_t * dpo, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1568 | format_function_t * ls_format, |
| 1569 | unformat_function_t * ls_unformat, |
| 1570 | sr_plugin_callback_t * creation_fn, |
| 1571 | sr_plugin_callback_t * removal_fn) |
| 1572 | { |
| 1573 | ip6_sr_main_t *sm = &sr_main; |
| 1574 | uword *p; |
| 1575 | |
| 1576 | sr_localsid_fn_registration_t *plugin; |
| 1577 | |
| 1578 | /* Did this function exist? If so update it */ |
| 1579 | p = hash_get_mem (sm->plugin_functions_by_key, fn_name); |
| 1580 | if (p) |
| 1581 | { |
| 1582 | plugin = pool_elt_at_index (sm->plugin_functions, p[0]); |
| 1583 | } |
| 1584 | /* Else create a new one and set hash key */ |
| 1585 | else |
| 1586 | { |
| 1587 | pool_get (sm->plugin_functions, plugin); |
| 1588 | hash_set_mem (sm->plugin_functions_by_key, fn_name, |
| 1589 | plugin - sm->plugin_functions); |
| 1590 | } |
| 1591 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1592 | clib_memset (plugin, 0, sizeof (*plugin)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1593 | |
| 1594 | plugin->sr_localsid_function_number = (plugin - sm->plugin_functions); |
| 1595 | plugin->sr_localsid_function_number += SR_BEHAVIOR_LAST; |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 1596 | plugin->prefix_length = prefix_length; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1597 | plugin->ls_format = ls_format; |
| 1598 | plugin->ls_unformat = ls_unformat; |
| 1599 | plugin->creation = creation_fn; |
| 1600 | plugin->removal = removal_fn; |
| 1601 | clib_memcpy (&plugin->dpo, dpo, sizeof (dpo_type_t)); |
| 1602 | plugin->function_name = format (0, "%s%c", fn_name, 0); |
| 1603 | plugin->keyword_str = format (0, "%s%c", keyword_str, 0); |
| 1604 | plugin->def_str = format (0, "%s%c", def_str, 0); |
| 1605 | plugin->params_str = format (0, "%s%c", params_str, 0); |
| 1606 | |
| 1607 | return plugin->sr_localsid_function_number; |
| 1608 | } |
| 1609 | |
| 1610 | /** |
| 1611 | * @brief CLI function to 'show' all available SR LocalSID behaviors |
| 1612 | */ |
| 1613 | static clib_error_t * |
| 1614 | show_sr_localsid_behaviors_command_fn (vlib_main_t * vm, |
| 1615 | unformat_input_t * input, |
| 1616 | vlib_cli_command_t * cmd) |
| 1617 | { |
| 1618 | ip6_sr_main_t *sm = &sr_main; |
| 1619 | sr_localsid_fn_registration_t *plugin; |
| 1620 | sr_localsid_fn_registration_t **plugins_vec = 0; |
| 1621 | int i; |
| 1622 | |
| 1623 | vlib_cli_output (vm, |
| 1624 | "SR LocalSIDs behaviors:\n-----------------------\n\n"); |
| 1625 | |
| 1626 | /* *INDENT-OFF* */ |
| 1627 | pool_foreach (plugin, sm->plugin_functions, |
| 1628 | ({ vec_add1 (plugins_vec, plugin); })); |
| 1629 | /* *INDENT-ON* */ |
| 1630 | |
| 1631 | /* Print static behaviors */ |
| 1632 | vlib_cli_output (vm, "Default behaviors:\n" |
| 1633 | "\tEnd\t-> Endpoint.\n" |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 1634 | "\tEnd.X\t-> Endpoint with Layer-3 cross-connect.\n" |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1635 | "\t\tParameters: '<iface> <ip6_next_hop>'\n" |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 1636 | "\tEnd.T\t-> Endpoint with specific IPv6 table lookup.\n" |
| 1637 | "\t\tParameters: '<fib_table>'\n" |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1638 | "\tEnd.DX2\t-> Endpoint with decapsulation and Layer-2 cross-connect.\n" |
| 1639 | "\t\tParameters: '<iface>'\n" |
| 1640 | "\tEnd.DX6\t-> Endpoint with decapsulation and IPv6 cross-connect.\n" |
| 1641 | "\t\tParameters: '<iface> <ip6_next_hop>'\n" |
| 1642 | "\tEnd.DX4\t-> Endpoint with decapsulation and IPv4 cross-connect.\n" |
| 1643 | "\t\tParameters: '<iface> <ip4_next_hop>'\n" |
| 1644 | "\tEnd.DT6\t-> Endpoint with decapsulation and specific IPv6 table lookup.\n" |
| 1645 | "\t\tParameters: '<ip6_fib_table>'\n" |
| 1646 | "\tEnd.DT4\t-> Endpoint with decapsulation and specific IPv4 table lookup.\n" |
| 1647 | "\t\tParameters: '<ip4_fib_table>'\n"); |
| 1648 | vlib_cli_output (vm, "Plugin behaviors:\n"); |
| 1649 | for (i = 0; i < vec_len (plugins_vec); i++) |
| 1650 | { |
| 1651 | plugin = plugins_vec[i]; |
| 1652 | vlib_cli_output (vm, "\t%s\t-> %s.\n", plugin->keyword_str, |
| 1653 | plugin->def_str); |
| 1654 | vlib_cli_output (vm, "\t\tParameters: '%s'\n", plugin->params_str); |
| 1655 | } |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | /* *INDENT-OFF* */ |
| 1660 | VLIB_CLI_COMMAND (show_sr_localsid_behaviors_command, static) = { |
| 1661 | .path = "show sr localsids behaviors", |
| 1662 | .short_help = "show sr localsids behaviors", |
| 1663 | .function = show_sr_localsid_behaviors_command_fn, |
| 1664 | }; |
| 1665 | /* *INDENT-ON* */ |
| 1666 | |
| 1667 | /** |
| 1668 | * @brief SR LocalSID initialization |
| 1669 | */ |
| 1670 | clib_error_t * |
| 1671 | sr_localsids_init (vlib_main_t * vm) |
| 1672 | { |
| 1673 | /* Init memory for function keys */ |
| 1674 | ip6_sr_main_t *sm = &sr_main; |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 1675 | mhash_init (&sm->sr_localsids_index_hash, sizeof (uword), |
| 1676 | sizeof (ip6_address_t)); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 1677 | /* Init SR behaviors DPO type */ |
| 1678 | sr_localsid_dpo_type = dpo_register_new_type (&sr_loc_vft, sr_loc_nodes); |
| 1679 | /* Init SR behaviors DPO type */ |
| 1680 | sr_localsid_d_dpo_type = |
| 1681 | dpo_register_new_type (&sr_loc_vft, sr_loc_d_nodes); |
| 1682 | /* Init memory for localsid plugins */ |
| 1683 | sm->plugin_functions_by_key = hash_create_string (0, sizeof (uword)); |
| 1684 | return 0; |
| 1685 | } |
| 1686 | |
| 1687 | VLIB_INIT_FUNCTION (sr_localsids_init); |
| 1688 | /* |
| 1689 | * fd.io coding-style-patch-verification: ON |
| 1690 | * |
| 1691 | * Local Variables: |
| 1692 | * eval: (c-set-style "gnu") |
| 1693 | * End: |
| 1694 | */ |