Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * ip/ip6_forward.c: IP v6 forwarding |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
| 40 | #include <vnet/vnet.h> |
| 41 | #include <vnet/ip/ip.h> |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 42 | #include <vnet/ip/ip_frag.h> |
Pavel Kotucek | 9f5a2b6 | 2017-06-14 13:56:55 +0200 | [diff] [blame] | 43 | #include <vnet/ip/ip6_neighbor.h> |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 44 | #include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | #include <vnet/srp/srp.h> /* for srp_hw_interface_class */ |
| 46 | #include <vppinfra/cache.h> |
AkshayaNadahalli | 0f438df | 2017-02-10 10:54:16 +0530 | [diff] [blame] | 47 | #include <vnet/fib/fib_urpf_list.h> /* for FIB uRPF check */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 48 | #include <vnet/fib/ip6_fib.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 49 | #include <vnet/mfib/ip6_mfib.h> |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 50 | #include <vnet/dpo/load_balance_map.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 51 | #include <vnet/dpo/classify_dpo.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 53 | #ifndef CLIB_MARCH_VARIANT |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | #include <vppinfra/bihash_template.c> |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 55 | #endif |
Vijayabhaskar Katamreddy | acbde66 | 2018-01-23 13:39:40 -0800 | [diff] [blame] | 56 | #include <vnet/ip/ip6_forward.h> |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 57 | #include <vnet/interface_output.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | |
AkshayaNadahalli | fdd81af | 2016-12-01 16:33:51 +0530 | [diff] [blame] | 59 | /* Flag used by IOAM code. Classifier sets it pop-hop-by-hop checks it */ |
| 60 | #define OI_DECAP 0x80000000 |
| 61 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | static void |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame^] | 63 | ip6_add_interface_prefix_routes (ip6_main_t * im, |
| 64 | u32 sw_if_index, |
| 65 | u32 fib_index, |
| 66 | ip6_address_t * address, u32 address_length) |
| 67 | { |
| 68 | ip_lookup_main_t *lm = &im->lookup_main; |
| 69 | ip_interface_prefix_t *if_prefix; |
| 70 | |
| 71 | ip_interface_prefix_key_t key = { |
| 72 | .prefix = { |
| 73 | .fp_len = address_length, |
| 74 | .fp_proto = FIB_PROTOCOL_IP6, |
| 75 | .fp_addr.ip6 = { |
| 76 | .as_u64 = { |
| 77 | address->as_u64[0] & |
| 78 | im->fib_masks[address_length]. |
| 79 | as_u64[0], |
| 80 | address-> |
| 81 | as_u64[1] & |
| 82 | im->fib_masks[address_length]. |
| 83 | as_u64[1], |
| 84 | }, |
| 85 | }, |
| 86 | }, |
| 87 | .sw_if_index = sw_if_index, |
| 88 | }; |
| 89 | |
| 90 | /* If prefix already set on interface, just increment ref count & return */ |
| 91 | if_prefix = ip_get_interface_prefix (lm, &key); |
| 92 | if (if_prefix) |
| 93 | { |
| 94 | if_prefix->ref_count += 1; |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | /* New prefix - allocate a pool entry, initialize it, add to the hash */ |
| 99 | pool_get (lm->if_prefix_pool, if_prefix); |
| 100 | if_prefix->ref_count = 1; |
| 101 | clib_memcpy (&if_prefix->key, &key, sizeof (key)); |
| 102 | mhash_set (&lm->prefix_to_if_prefix_index, &key, |
| 103 | if_prefix - lm->if_prefix_pool, 0 /* old value */ ); |
| 104 | |
| 105 | /* length < 128 - add glean */ |
| 106 | if (address_length < 128) |
| 107 | { |
| 108 | /* set the glean route for the prefix */ |
| 109 | fib_table_entry_update_one_path (fib_index, &key.prefix, |
| 110 | FIB_SOURCE_INTERFACE, |
| 111 | (FIB_ENTRY_FLAG_CONNECTED | |
| 112 | FIB_ENTRY_FLAG_ATTACHED), |
| 113 | DPO_PROTO_IP6, |
| 114 | /* No next-hop address */ |
| 115 | NULL, sw_if_index, |
| 116 | /* invalid FIB index */ |
| 117 | ~0, 1, |
| 118 | /* no out-label stack */ |
| 119 | NULL, FIB_ROUTE_PATH_FLAG_NONE); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | static void |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index, |
| 125 | ip6_main_t * im, u32 fib_index, |
| 126 | ip_interface_address_t * a) |
| 127 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 128 | ip_lookup_main_t *lm = &im->lookup_main; |
| 129 | ip6_address_t *address = ip_interface_address_get_address (lm, a); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 130 | fib_prefix_t pfx = { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 131 | .fp_len = a->address_length, |
| 132 | .fp_proto = FIB_PROTOCOL_IP6, |
| 133 | .fp_addr.ip6 = *address, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 134 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame^] | 136 | /* set special routes for the prefix if needed */ |
| 137 | ip6_add_interface_prefix_routes (im, sw_if_index, fib_index, |
| 138 | address, a->address_length); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 140 | pfx.fp_len = 128; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 141 | if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 142 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 143 | u32 classify_table_index = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 144 | lm->classify_table_index_by_sw_if_index[sw_if_index]; |
| 145 | if (classify_table_index != (u32) ~ 0) |
| 146 | { |
| 147 | dpo_id_t dpo = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 148 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 149 | dpo_set (&dpo, |
| 150 | DPO_CLASSIFY, |
| 151 | DPO_PROTO_IP6, |
| 152 | classify_dpo_create (DPO_PROTO_IP6, classify_table_index)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 153 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 154 | fib_table_entry_special_dpo_add (fib_index, |
| 155 | &pfx, |
| 156 | FIB_SOURCE_CLASSIFY, |
| 157 | FIB_ENTRY_FLAG_NONE, &dpo); |
| 158 | dpo_reset (&dpo); |
| 159 | } |
| 160 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 161 | |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 162 | fib_table_entry_update_one_path (fib_index, &pfx, |
| 163 | FIB_SOURCE_INTERFACE, |
| 164 | (FIB_ENTRY_FLAG_CONNECTED | |
| 165 | FIB_ENTRY_FLAG_LOCAL), |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 166 | DPO_PROTO_IP6, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 167 | &pfx.fp_addr, |
| 168 | sw_if_index, ~0, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 169 | 1, NULL, FIB_ROUTE_PATH_FLAG_NONE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static void |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame^] | 173 | ip6_del_interface_prefix_routes (ip6_main_t * im, |
| 174 | u32 sw_if_index, |
| 175 | u32 fib_index, |
| 176 | ip6_address_t * address, u32 address_length) |
| 177 | { |
| 178 | ip_lookup_main_t *lm = &im->lookup_main; |
| 179 | ip_interface_prefix_t *if_prefix; |
| 180 | |
| 181 | ip_interface_prefix_key_t key = { |
| 182 | .prefix = { |
| 183 | .fp_len = address_length, |
| 184 | .fp_proto = FIB_PROTOCOL_IP6, |
| 185 | .fp_addr.ip6 = { |
| 186 | .as_u64 = { |
| 187 | address->as_u64[0] & |
| 188 | im->fib_masks[address_length]. |
| 189 | as_u64[0], |
| 190 | address-> |
| 191 | as_u64[1] & |
| 192 | im->fib_masks[address_length]. |
| 193 | as_u64[1], |
| 194 | }, |
| 195 | }, |
| 196 | }, |
| 197 | .sw_if_index = sw_if_index, |
| 198 | }; |
| 199 | |
| 200 | if_prefix = ip_get_interface_prefix (lm, &key); |
| 201 | if (!if_prefix) |
| 202 | { |
| 203 | clib_warning ("Prefix not found while deleting %U", |
| 204 | format_ip4_address_and_length, address, address_length); |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | /* If not deleting last intf addr in prefix, decrement ref count & return */ |
| 209 | if_prefix->ref_count -= 1; |
| 210 | if (if_prefix->ref_count > 0) |
| 211 | return; |
| 212 | |
| 213 | /* length <= 30, delete glean route */ |
| 214 | if (address_length <= 128) |
| 215 | { |
| 216 | /* remove glean route for prefix */ |
| 217 | fib_table_entry_delete (fib_index, &key.prefix, FIB_SOURCE_INTERFACE); |
| 218 | |
| 219 | } |
| 220 | |
| 221 | mhash_unset (&lm->prefix_to_if_prefix_index, &key, 0 /* old_value */ ); |
| 222 | pool_put (lm->if_prefix_pool, if_prefix); |
| 223 | } |
| 224 | |
| 225 | static void |
| 226 | ip6_del_interface_routes (u32 sw_if_index, ip6_main_t * im, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 227 | u32 fib_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 228 | ip6_address_t * address, u32 address_length) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 229 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 230 | fib_prefix_t pfx = { |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame^] | 231 | .fp_len = 128, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 232 | .fp_proto = FIB_PROTOCOL_IP6, |
| 233 | .fp_addr.ip6 = *address, |
| 234 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame^] | 236 | /* delete special routes for the prefix if needed */ |
| 237 | ip6_del_interface_prefix_routes (im, sw_if_index, fib_index, |
| 238 | address, address_length); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 239 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 240 | fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 243 | #ifndef CLIB_MARCH_VARIANT |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 244 | void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 245 | ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 246 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 247 | ip6_main_t *im = &ip6_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 248 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 249 | vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 250 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 251 | /* |
| 252 | * enable/disable only on the 1<->0 transition |
| 253 | */ |
| 254 | if (is_enable) |
| 255 | { |
| 256 | if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index]) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 257 | return; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 258 | } |
| 259 | else |
| 260 | { |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 261 | /* The ref count is 0 when an address is removed from an interface that has |
| 262 | * no address - this is not a ciritical error */ |
| 263 | if (0 == im->ip_enabled_by_sw_if_index[sw_if_index] || |
| 264 | 0 != --im->ip_enabled_by_sw_if_index[sw_if_index]) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 265 | return; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 268 | vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index, |
Neale Ranns | 630198f | 2017-05-22 09:20:20 -0400 | [diff] [blame] | 269 | !is_enable, 0, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 270 | |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 271 | vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled", |
| 272 | sw_if_index, !is_enable, 0, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 275 | /* get first interface address */ |
| 276 | ip6_address_t * |
Neale Ranns | 6cfc39c | 2017-02-14 01:44:25 -0800 | [diff] [blame] | 277 | ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index) |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 278 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 279 | ip_lookup_main_t *lm = &im->lookup_main; |
| 280 | ip_interface_address_t *ia = 0; |
| 281 | ip6_address_t *result = 0; |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 282 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 283 | /* *INDENT-OFF* */ |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 284 | foreach_ip_interface_address (lm, ia, sw_if_index, |
| 285 | 1 /* honor unnumbered */, |
| 286 | ({ |
| 287 | ip6_address_t * a = ip_interface_address_get_address (lm, ia); |
| 288 | result = a; |
| 289 | break; |
| 290 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 291 | /* *INDENT-ON* */ |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 292 | return result; |
| 293 | } |
| 294 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 295 | clib_error_t * |
| 296 | ip6_add_del_interface_address (vlib_main_t * vm, |
| 297 | u32 sw_if_index, |
| 298 | ip6_address_t * address, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 299 | u32 address_length, u32 is_del) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 300 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 301 | vnet_main_t *vnm = vnet_get_main (); |
| 302 | ip6_main_t *im = &ip6_main; |
| 303 | ip_lookup_main_t *lm = &im->lookup_main; |
| 304 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | u32 if_address_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 306 | ip6_address_fib_t ip6_af, *addr_fib = 0; |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 307 | ip6_address_t ll_addr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 308 | |
Pavel Kotucek | 5780898 | 2017-08-02 08:20:19 +0200 | [diff] [blame] | 309 | /* local0 interface doesn't support IP addressing */ |
| 310 | if (sw_if_index == 0) |
| 311 | { |
| 312 | return |
| 313 | clib_error_create ("local0 interface doesn't support IP addressing"); |
| 314 | } |
| 315 | |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 316 | if (ip6_address_is_link_local_unicast (address)) |
| 317 | { |
| 318 | if (address_length != 128) |
| 319 | { |
| 320 | vnm->api_errno = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH; |
| 321 | return |
| 322 | clib_error_create |
| 323 | ("prefix length of link-local address must be 128"); |
| 324 | } |
| 325 | if (!is_del) |
| 326 | { |
| 327 | return ip6_neighbor_set_link_local_address (vm, sw_if_index, |
| 328 | address); |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | ll_addr = ip6_neighbor_get_link_local_address (sw_if_index); |
| 333 | if (ip6_address_is_equal (&ll_addr, address)) |
| 334 | { |
| 335 | vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_DELETABLE; |
| 336 | return clib_error_create ("address not deletable"); |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE; |
| 341 | return clib_error_create ("address not found"); |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | vec_validate (im->fib_index_by_sw_if_index, sw_if_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 347 | vec_validate (im->mfib_index_by_sw_if_index, sw_if_index); |
| 348 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | ip6_addr_fib_init (&ip6_af, address, |
| 350 | vec_elt (im->fib_index_by_sw_if_index, sw_if_index)); |
| 351 | vec_add1 (addr_fib, ip6_af); |
| 352 | |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 353 | /* *INDENT-OFF* */ |
| 354 | if (!is_del) |
| 355 | { |
| 356 | /* When adding an address check that it does not conflict |
| 357 | with an existing address on any interface in this table. */ |
| 358 | ip_interface_address_t *ia; |
| 359 | vnet_sw_interface_t *sif; |
| 360 | |
| 361 | pool_foreach(sif, vnm->interface_main.sw_interfaces, |
| 362 | ({ |
| 363 | if (im->fib_index_by_sw_if_index[sw_if_index] == |
| 364 | im->fib_index_by_sw_if_index[sif->sw_if_index]) |
| 365 | { |
| 366 | foreach_ip_interface_address |
| 367 | (&im->lookup_main, ia, sif->sw_if_index, |
| 368 | 0 /* honor unnumbered */ , |
| 369 | ({ |
| 370 | ip6_address_t * x = |
| 371 | ip_interface_address_get_address |
| 372 | (&im->lookup_main, ia); |
| 373 | if (ip6_destination_matches_route |
| 374 | (im, address, x, ia->address_length) || |
| 375 | ip6_destination_matches_route (im, |
| 376 | x, |
| 377 | address, |
| 378 | address_length)) |
| 379 | { |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame^] | 380 | /* an intf may have >1 addr from the same prefix */ |
| 381 | if ((sw_if_index == sif->sw_if_index) && |
| 382 | (ia->address_length == address_length) && |
| 383 | !ip6_address_is_equal (x, address)) |
| 384 | continue; |
| 385 | |
| 386 | /* error if the length or intf was different */ |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 387 | vnm->api_errno = VNET_API_ERROR_DUPLICATE_IF_ADDRESS; |
| 388 | return |
| 389 | clib_error_create |
| 390 | ("failed to add %U which conflicts with %U for interface %U", |
| 391 | format_ip6_address_and_length, address, |
| 392 | address_length, |
| 393 | format_ip6_address_and_length, x, |
| 394 | ia->address_length, |
| 395 | format_vnet_sw_if_index_name, vnm, |
| 396 | sif->sw_if_index); |
| 397 | } |
| 398 | })); |
| 399 | } |
| 400 | })); |
| 401 | } |
| 402 | /* *INDENT-ON* */ |
| 403 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | { |
| 405 | uword elts_before = pool_elts (lm->if_address_pool); |
| 406 | |
| 407 | error = ip_interface_address_add_del |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 408 | (lm, sw_if_index, addr_fib, address_length, is_del, &if_address_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 409 | if (error) |
| 410 | goto done; |
| 411 | |
| 412 | /* Pool did not grow: add duplicate address. */ |
| 413 | if (elts_before == pool_elts (lm->if_address_pool)) |
| 414 | goto done; |
| 415 | } |
| 416 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 417 | ip6_sw_interface_enable_disable (sw_if_index, !is_del); |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 418 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 419 | if (is_del) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame^] | 420 | ip6_del_interface_routes (sw_if_index, |
| 421 | im, ip6_af.fib_index, address, address_length); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 422 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 423 | ip6_add_interface_routes (vnm, sw_if_index, |
| 424 | im, ip6_af.fib_index, |
| 425 | pool_elt_at_index (lm->if_address_pool, |
| 426 | if_address_index)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 427 | |
| 428 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 429 | ip6_add_del_interface_address_callback_t *cb; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 430 | vec_foreach (cb, im->add_del_interface_address_callbacks) |
| 431 | cb->function (im, cb->function_opaque, sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 432 | address, address_length, if_address_index, is_del); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 435 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 436 | vec_free (addr_fib); |
| 437 | return error; |
| 438 | } |
| 439 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 440 | #endif |
| 441 | |
| 442 | static clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 443 | ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 445 | ip6_main_t *im = &ip6_main; |
| 446 | ip_interface_address_t *ia; |
| 447 | ip6_address_t *a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 448 | u32 is_admin_up, fib_index; |
| 449 | |
| 450 | /* Fill in lookup tables with default table (0). */ |
| 451 | vec_validate (im->fib_index_by_sw_if_index, sw_if_index); |
| 452 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 453 | vec_validate_init_empty (im-> |
| 454 | lookup_main.if_address_pool_index_by_sw_if_index, |
| 455 | sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 456 | |
| 457 | is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0; |
| 458 | |
| 459 | fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index); |
| 460 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 461 | /* *INDENT-OFF* */ |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 462 | foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 463 | 0 /* honor unnumbered */, |
| 464 | ({ |
| 465 | a = ip_interface_address_get_address (&im->lookup_main, ia); |
| 466 | if (is_admin_up) |
| 467 | ip6_add_interface_routes (vnm, sw_if_index, |
| 468 | im, fib_index, |
| 469 | ia); |
| 470 | else |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame^] | 471 | ip6_del_interface_routes (sw_if_index, im, fib_index, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | a, ia->address_length); |
| 473 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 474 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down); |
| 480 | |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 481 | /* Built-in ip6 unicast rx feature path definition */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 482 | /* *INDENT-OFF* */ |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 483 | VNET_FEATURE_ARC_INIT (ip6_unicast, static) = |
| 484 | { |
| 485 | .arc_name = "ip6-unicast", |
| 486 | .start_nodes = VNET_FEATURES ("ip6-input"), |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 487 | .last_in_arc = "ip6-lookup", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 488 | .arc_index_ptr = &ip6_main.lookup_main.ucast_feature_arc_index, |
| 489 | }; |
| 490 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 491 | VNET_FEATURE_INIT (ip6_flow_classify, static) = |
| 492 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 493 | .arc_name = "ip6-unicast", |
Juraj Sloboda | 506b245 | 2016-08-07 23:45:24 -0700 | [diff] [blame] | 494 | .node_name = "ip6-flow-classify", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 495 | .runs_before = VNET_FEATURES ("ip6-inacl"), |
Juraj Sloboda | 506b245 | 2016-08-07 23:45:24 -0700 | [diff] [blame] | 496 | }; |
| 497 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 498 | VNET_FEATURE_INIT (ip6_inacl, static) = |
| 499 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 500 | .arc_name = "ip6-unicast", |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 501 | .node_name = "ip6-inacl", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 502 | .runs_before = VNET_FEATURES ("ip6-policer-classify"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 503 | }; |
| 504 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 505 | VNET_FEATURE_INIT (ip6_policer_classify, static) = |
| 506 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 507 | .arc_name = "ip6-unicast", |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 508 | .node_name = "ip6-policer-classify", |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 509 | .runs_before = VNET_FEATURES ("ipsec6-input-feature"), |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 510 | }; |
| 511 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 512 | VNET_FEATURE_INIT (ip6_ipsec, static) = |
| 513 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 514 | .arc_name = "ip6-unicast", |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 515 | .node_name = "ipsec6-input-feature", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 516 | .runs_before = VNET_FEATURES ("l2tp-decap"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 517 | }; |
| 518 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 519 | VNET_FEATURE_INIT (ip6_l2tp, static) = |
| 520 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 521 | .arc_name = "ip6-unicast", |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 522 | .node_name = "l2tp-decap", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 523 | .runs_before = VNET_FEATURES ("vpath-input-ip6"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 524 | }; |
| 525 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 526 | VNET_FEATURE_INIT (ip6_vpath, static) = |
| 527 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 528 | .arc_name = "ip6-unicast", |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 529 | .node_name = "vpath-input-ip6", |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 530 | .runs_before = VNET_FEATURES ("ip6-vxlan-bypass"), |
| 531 | }; |
| 532 | |
| 533 | VNET_FEATURE_INIT (ip6_vxlan_bypass, static) = |
| 534 | { |
| 535 | .arc_name = "ip6-unicast", |
| 536 | .node_name = "ip6-vxlan-bypass", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 537 | .runs_before = VNET_FEATURES ("ip6-lookup"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 538 | }; |
| 539 | |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 540 | VNET_FEATURE_INIT (ip6_not_enabled, static) = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 541 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 542 | .arc_name = "ip6-unicast", |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 543 | .node_name = "ip6-not-enabled", |
Neale Ranns | 630198f | 2017-05-22 09:20:20 -0400 | [diff] [blame] | 544 | .runs_before = VNET_FEATURES ("ip6-lookup"), |
| 545 | }; |
| 546 | |
| 547 | VNET_FEATURE_INIT (ip6_lookup, static) = |
| 548 | { |
| 549 | .arc_name = "ip6-unicast", |
| 550 | .node_name = "ip6-lookup", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 551 | .runs_before = 0, /*last feature*/ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 552 | }; |
| 553 | |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 554 | /* Built-in ip6 multicast rx feature path definition (none now) */ |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 555 | VNET_FEATURE_ARC_INIT (ip6_multicast, static) = |
| 556 | { |
| 557 | .arc_name = "ip6-multicast", |
| 558 | .start_nodes = VNET_FEATURES ("ip6-input"), |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 559 | .last_in_arc = "ip6-mfib-forward-lookup", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 560 | .arc_index_ptr = &ip6_main.lookup_main.mcast_feature_arc_index, |
| 561 | }; |
| 562 | |
| 563 | VNET_FEATURE_INIT (ip6_vpath_mc, static) = { |
| 564 | .arc_name = "ip6-multicast", |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 565 | .node_name = "vpath-input-ip6", |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 566 | .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 567 | }; |
| 568 | |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 569 | VNET_FEATURE_INIT (ip6_not_enabled_mc, static) = { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 570 | .arc_name = "ip6-multicast", |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 571 | .node_name = "ip6-not-enabled", |
Neale Ranns | 630198f | 2017-05-22 09:20:20 -0400 | [diff] [blame] | 572 | .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"), |
| 573 | }; |
| 574 | |
| 575 | VNET_FEATURE_INIT (ip6_mc_lookup, static) = { |
| 576 | .arc_name = "ip6-multicast", |
| 577 | .node_name = "ip6-mfib-forward-lookup", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 578 | .runs_before = 0, /* last feature */ |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 579 | }; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 580 | |
| 581 | /* Built-in ip4 tx feature path definition */ |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 582 | VNET_FEATURE_ARC_INIT (ip6_output, static) = |
| 583 | { |
| 584 | .arc_name = "ip6-output", |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 585 | .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain", "ip6-dvr-dpo"), |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 586 | .last_in_arc = "interface-output", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 587 | .arc_index_ptr = &ip6_main.lookup_main.output_feature_arc_index, |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 588 | }; |
| 589 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 590 | VNET_FEATURE_INIT (ip6_outacl, static) = { |
| 591 | .arc_name = "ip6-output", |
| 592 | .node_name = "ip6-outacl", |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 593 | .runs_before = VNET_FEATURES ("ipsec6-output-feature"), |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 594 | }; |
| 595 | |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 596 | VNET_FEATURE_INIT (ip6_ipsec_output, static) = { |
| 597 | .arc_name = "ip6-output", |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 598 | .node_name = "ipsec6-output-feature", |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 599 | .runs_before = VNET_FEATURES ("interface-output"), |
| 600 | }; |
| 601 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 602 | VNET_FEATURE_INIT (ip6_interface_output, static) = { |
| 603 | .arc_name = "ip6-output", |
| 604 | .node_name = "interface-output", |
| 605 | .runs_before = 0, /* not before any other features */ |
| 606 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 607 | /* *INDENT-ON* */ |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 608 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 609 | static clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 610 | ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 611 | { |
Florin Coras | b5c13fd | 2017-05-10 12:32:53 -0700 | [diff] [blame] | 612 | ip6_main_t *im = &ip6_main; |
| 613 | |
| 614 | vec_validate (im->fib_index_by_sw_if_index, sw_if_index); |
| 615 | vec_validate (im->mfib_index_by_sw_if_index, sw_if_index); |
| 616 | |
Pavel Kotucek | 9f5a2b6 | 2017-06-14 13:56:55 +0200 | [diff] [blame] | 617 | if (!is_add) |
| 618 | { |
| 619 | /* Ensure that IPv6 is disabled */ |
| 620 | ip6_main_t *im6 = &ip6_main; |
| 621 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 622 | ip_interface_address_t *ia = 0; |
| 623 | ip6_address_t *address; |
| 624 | vlib_main_t *vm = vlib_get_main (); |
| 625 | |
| 626 | ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, 0 /* is_add */ ); |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 627 | vnet_sw_interface_update_unnumbered (sw_if_index, ~0, 0); |
Pavel Kotucek | 9f5a2b6 | 2017-06-14 13:56:55 +0200 | [diff] [blame] | 628 | /* *INDENT-OFF* */ |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 629 | foreach_ip_interface_address (lm6, ia, sw_if_index, 0, |
Pavel Kotucek | 9f5a2b6 | 2017-06-14 13:56:55 +0200 | [diff] [blame] | 630 | ({ |
| 631 | address = ip_interface_address_get_address (lm6, ia); |
| 632 | ip6_add_del_interface_address(vm, sw_if_index, address, ia->address_length, 1); |
| 633 | })); |
| 634 | /* *INDENT-ON* */ |
| 635 | ip6_mfib_interface_enable_disable (sw_if_index, 0); |
| 636 | } |
| 637 | |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 638 | vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index, |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 639 | is_add, 0, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 640 | |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 641 | vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled", |
| 642 | sw_if_index, is_add, 0, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 643 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 644 | return /* no error */ 0; |
| 645 | } |
| 646 | |
| 647 | VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del); |
| 648 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 649 | VLIB_NODE_FN (ip6_lookup_node) (vlib_main_t * vm, |
| 650 | vlib_node_runtime_t * node, |
| 651 | vlib_frame_t * frame) |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 652 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 653 | return ip6_lookup_inline (vm, node, frame); |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 654 | } |
| 655 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 656 | static u8 *format_ip6_lookup_trace (u8 * s, va_list * args); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 657 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 658 | /* *INDENT-OFF* */ |
| 659 | VLIB_REGISTER_NODE (ip6_lookup_node) = |
| 660 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 661 | .name = "ip6-lookup", |
| 662 | .vector_size = sizeof (u32), |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 663 | .format_trace = format_ip6_lookup_trace, |
Ole Troan | f0f8522 | 2016-06-14 21:12:32 +0200 | [diff] [blame] | 664 | .n_next_nodes = IP6_LOOKUP_N_NEXT, |
Damjan Marion | b270789 | 2016-04-13 11:21:07 +0200 | [diff] [blame] | 665 | .next_nodes = IP6_LOOKUP_NEXT_NODES, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 666 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 667 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 668 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 669 | VLIB_NODE_FN (ip6_load_balance_node) (vlib_main_t * vm, |
| 670 | vlib_node_runtime_t * node, |
| 671 | vlib_frame_t * frame) |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 672 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 673 | vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters; |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 674 | u32 n_left, *from; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 675 | u32 thread_index = vm->thread_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 676 | ip6_main_t *im = &ip6_main; |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 677 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
| 678 | u16 nexts[VLIB_FRAME_SIZE], *next; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 679 | |
| 680 | from = vlib_frame_vector_args (frame); |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 681 | n_left = frame->n_vectors; |
| 682 | next = nexts; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 683 | |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 684 | vlib_get_buffers (vm, from, bufs, n_left); |
| 685 | |
| 686 | while (n_left >= 4) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 687 | { |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 688 | const load_balance_t *lb0, *lb1; |
| 689 | const ip6_header_t *ip0, *ip1; |
| 690 | u32 lbi0, hc0, lbi1, hc1; |
| 691 | const dpo_id_t *dpo0, *dpo1; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 692 | |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 693 | /* Prefetch next iteration. */ |
| 694 | { |
| 695 | vlib_prefetch_buffer_header (b[2], STORE); |
| 696 | vlib_prefetch_buffer_header (b[3], STORE); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 697 | |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 698 | CLIB_PREFETCH (b[2]->data, sizeof (ip0[0]), STORE); |
| 699 | CLIB_PREFETCH (b[3]->data, sizeof (ip0[0]), STORE); |
| 700 | } |
| 701 | |
| 702 | ip0 = vlib_buffer_get_current (b[0]); |
| 703 | ip1 = vlib_buffer_get_current (b[1]); |
| 704 | lbi0 = vnet_buffer (b[0])->ip.adj_index[VLIB_TX]; |
| 705 | lbi1 = vnet_buffer (b[1])->ip.adj_index[VLIB_TX]; |
| 706 | |
| 707 | lb0 = load_balance_get (lbi0); |
| 708 | lb1 = load_balance_get (lbi1); |
| 709 | |
| 710 | /* |
| 711 | * this node is for via FIBs we can re-use the hash value from the |
| 712 | * to node if present. |
| 713 | * We don't want to use the same hash value at each level in the recursion |
| 714 | * graph as that would lead to polarisation |
| 715 | */ |
| 716 | hc0 = hc1 = 0; |
| 717 | |
| 718 | if (PREDICT_FALSE (lb0->lb_n_buckets > 1)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 719 | { |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 720 | if (PREDICT_TRUE (vnet_buffer (b[0])->ip.flow_hash)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 721 | { |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 722 | hc0 = vnet_buffer (b[0])->ip.flow_hash = |
| 723 | vnet_buffer (b[0])->ip.flow_hash >> 1; |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 724 | } |
| 725 | else |
| 726 | { |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 727 | hc0 = vnet_buffer (b[0])->ip.flow_hash = |
| 728 | ip6_compute_flow_hash (ip0, lb0->lb_hash_config); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 729 | } |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 730 | dpo0 = load_balance_get_fwd_bucket |
| 731 | (lb0, (hc0 & (lb0->lb_n_buckets_minus_1))); |
| 732 | } |
| 733 | else |
| 734 | { |
| 735 | dpo0 = load_balance_get_bucket_i (lb0, 0); |
| 736 | } |
| 737 | if (PREDICT_FALSE (lb1->lb_n_buckets > 1)) |
| 738 | { |
| 739 | if (PREDICT_TRUE (vnet_buffer (b[1])->ip.flow_hash)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 740 | { |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 741 | hc1 = vnet_buffer (b[1])->ip.flow_hash = |
| 742 | vnet_buffer (b[1])->ip.flow_hash >> 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 743 | } |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 744 | else |
| 745 | { |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 746 | hc1 = vnet_buffer (b[1])->ip.flow_hash = |
| 747 | ip6_compute_flow_hash (ip1, lb1->lb_hash_config); |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 748 | } |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 749 | dpo1 = load_balance_get_fwd_bucket |
| 750 | (lb1, (hc1 & (lb1->lb_n_buckets_minus_1))); |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | dpo1 = load_balance_get_bucket_i (lb1, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 755 | } |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 756 | |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 757 | next[0] = dpo0->dpoi_next_node; |
| 758 | next[1] = dpo1->dpoi_next_node; |
| 759 | |
| 760 | /* Only process the HBH Option Header if explicitly configured to do so */ |
| 761 | if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 762 | { |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 763 | next[0] = (dpo_is_adj (dpo0) && im->hbh_enabled) ? |
| 764 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next[0]; |
| 765 | } |
| 766 | /* Only process the HBH Option Header if explicitly configured to do so */ |
| 767 | if (PREDICT_FALSE (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
| 768 | { |
| 769 | next[1] = (dpo_is_adj (dpo1) && im->hbh_enabled) ? |
| 770 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next[1]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 771 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 772 | |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 773 | vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
| 774 | vnet_buffer (b[1])->ip.adj_index[VLIB_TX] = dpo1->dpoi_index; |
| 775 | |
| 776 | vlib_increment_combined_counter |
| 777 | (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, b[0])); |
| 778 | vlib_increment_combined_counter |
| 779 | (cm, thread_index, lbi1, 1, vlib_buffer_length_in_chain (vm, b[1])); |
| 780 | |
| 781 | b += 2; |
| 782 | next += 2; |
| 783 | n_left -= 2; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 784 | } |
| 785 | |
Neale Ranns | 3ce72b2 | 2019-05-27 08:21:32 -0400 | [diff] [blame] | 786 | while (n_left > 0) |
| 787 | { |
| 788 | const load_balance_t *lb0; |
| 789 | const ip6_header_t *ip0; |
| 790 | const dpo_id_t *dpo0; |
| 791 | u32 lbi0, hc0; |
| 792 | |
| 793 | ip0 = vlib_buffer_get_current (b[0]); |
| 794 | lbi0 = vnet_buffer (b[0])->ip.adj_index[VLIB_TX]; |
| 795 | |
| 796 | lb0 = load_balance_get (lbi0); |
| 797 | |
| 798 | hc0 = 0; |
| 799 | if (PREDICT_FALSE (lb0->lb_n_buckets > 1)) |
| 800 | { |
| 801 | if (PREDICT_TRUE (vnet_buffer (b[0])->ip.flow_hash)) |
| 802 | { |
| 803 | hc0 = vnet_buffer (b[0])->ip.flow_hash = |
| 804 | vnet_buffer (b[0])->ip.flow_hash >> 1; |
| 805 | } |
| 806 | else |
| 807 | { |
| 808 | hc0 = vnet_buffer (b[0])->ip.flow_hash = |
| 809 | ip6_compute_flow_hash (ip0, lb0->lb_hash_config); |
| 810 | } |
| 811 | dpo0 = load_balance_get_fwd_bucket |
| 812 | (lb0, (hc0 & (lb0->lb_n_buckets_minus_1))); |
| 813 | } |
| 814 | else |
| 815 | { |
| 816 | dpo0 = load_balance_get_bucket_i (lb0, 0); |
| 817 | } |
| 818 | |
| 819 | next[0] = dpo0->dpoi_next_node; |
| 820 | vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
| 821 | |
| 822 | /* Only process the HBH Option Header if explicitly configured to do so */ |
| 823 | if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
| 824 | { |
| 825 | next[0] = (dpo_is_adj (dpo0) && im->hbh_enabled) ? |
| 826 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next[0]; |
| 827 | } |
| 828 | |
| 829 | vlib_increment_combined_counter |
| 830 | (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, b[0])); |
| 831 | |
| 832 | b += 1; |
| 833 | next += 1; |
| 834 | n_left -= 1; |
| 835 | } |
| 836 | |
| 837 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
| 838 | |
Neale Ranns | a71844f | 2018-11-08 07:31:36 -0800 | [diff] [blame] | 839 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 840 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
| 841 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 842 | return frame->n_vectors; |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 843 | } |
| 844 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 845 | /* *INDENT-OFF* */ |
| 846 | VLIB_REGISTER_NODE (ip6_load_balance_node) = |
| 847 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 848 | .name = "ip6-load-balance", |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 849 | .vector_size = sizeof (u32), |
Ole Troan | f0f8522 | 2016-06-14 21:12:32 +0200 | [diff] [blame] | 850 | .sibling_of = "ip6-lookup", |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 851 | .format_trace = format_ip6_lookup_trace, |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 852 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 853 | /* *INDENT-ON* */ |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 854 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 855 | typedef struct |
| 856 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 857 | /* Adjacency taken. */ |
| 858 | u32 adj_index; |
| 859 | u32 flow_hash; |
John Lo | 2d34374 | 2016-01-19 17:27:17 -0500 | [diff] [blame] | 860 | u32 fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 861 | |
| 862 | /* Packet data, possibly *after* rewrite. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 863 | u8 packet_data[128 - 1 * sizeof (u32)]; |
| 864 | } |
| 865 | ip6_forward_next_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 866 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 867 | #ifndef CLIB_MARCH_VARIANT |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 868 | u8 * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 869 | format_ip6_forward_next_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 870 | { |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 871 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 872 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 873 | ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *); |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 874 | u32 indent = format_get_indent (s); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 875 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 876 | s = format (s, "%U%U", |
| 877 | format_white_space, indent, |
| 878 | format_ip6_header, t->packet_data, sizeof (t->packet_data)); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 879 | return s; |
| 880 | } |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 881 | #endif |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 882 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 883 | static u8 * |
| 884 | format_ip6_lookup_trace (u8 * s, va_list * args) |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 885 | { |
| 886 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 887 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 888 | ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *); |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 889 | u32 indent = format_get_indent (s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 890 | |
John Lo | ac8146c | 2016-09-27 17:44:02 -0400 | [diff] [blame] | 891 | s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 892 | t->fib_index, t->adj_index, t->flow_hash); |
| 893 | s = format (s, "\n%U%U", |
| 894 | format_white_space, indent, |
| 895 | format_ip6_header, t->packet_data, sizeof (t->packet_data)); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 896 | return s; |
| 897 | } |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 898 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 899 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 900 | static u8 * |
| 901 | format_ip6_rewrite_trace (u8 * s, va_list * args) |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 902 | { |
| 903 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 904 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 905 | ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *); |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 906 | u32 indent = format_get_indent (s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 907 | |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 908 | s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 909 | t->fib_index, t->adj_index, format_ip_adjacency, |
| 910 | t->adj_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 911 | s = format (s, "\n%U%U", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 912 | format_white_space, indent, |
| 913 | format_ip_adjacency_packet_data, |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 914 | t->adj_index, t->packet_data, sizeof (t->packet_data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 915 | return s; |
| 916 | } |
| 917 | |
| 918 | /* Common trace function for all ip6-forward next nodes. */ |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 919 | #ifndef CLIB_MARCH_VARIANT |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 920 | void |
| 921 | ip6_forward_next_trace (vlib_main_t * vm, |
| 922 | vlib_node_runtime_t * node, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 923 | vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 924 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 925 | u32 *from, n_left; |
| 926 | ip6_main_t *im = &ip6_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 927 | |
| 928 | n_left = frame->n_vectors; |
| 929 | from = vlib_frame_vector_args (frame); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 930 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 931 | while (n_left >= 4) |
| 932 | { |
| 933 | u32 bi0, bi1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 934 | vlib_buffer_t *b0, *b1; |
| 935 | ip6_forward_next_trace_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 936 | |
| 937 | /* Prefetch next iteration. */ |
| 938 | vlib_prefetch_buffer_with_index (vm, from[2], LOAD); |
| 939 | vlib_prefetch_buffer_with_index (vm, from[3], LOAD); |
| 940 | |
| 941 | bi0 = from[0]; |
| 942 | bi1 = from[1]; |
| 943 | |
| 944 | b0 = vlib_get_buffer (vm, bi0); |
| 945 | b1 = vlib_get_buffer (vm, bi1); |
| 946 | |
| 947 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 948 | { |
| 949 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 950 | t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 951 | t0->flow_hash = vnet_buffer (b0)->ip.flow_hash; |
| 952 | t0->fib_index = |
| 953 | (vnet_buffer (b0)->sw_if_index[VLIB_TX] != |
| 954 | (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] : |
| 955 | vec_elt (im->fib_index_by_sw_if_index, |
| 956 | vnet_buffer (b0)->sw_if_index[VLIB_RX]); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 957 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 958 | clib_memcpy_fast (t0->packet_data, |
| 959 | vlib_buffer_get_current (b0), |
| 960 | sizeof (t0->packet_data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 961 | } |
| 962 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 963 | { |
| 964 | t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); |
| 965 | t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 966 | t1->flow_hash = vnet_buffer (b1)->ip.flow_hash; |
| 967 | t1->fib_index = |
| 968 | (vnet_buffer (b1)->sw_if_index[VLIB_TX] != |
| 969 | (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] : |
| 970 | vec_elt (im->fib_index_by_sw_if_index, |
| 971 | vnet_buffer (b1)->sw_if_index[VLIB_RX]); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 972 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 973 | clib_memcpy_fast (t1->packet_data, |
| 974 | vlib_buffer_get_current (b1), |
| 975 | sizeof (t1->packet_data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 976 | } |
| 977 | from += 2; |
| 978 | n_left -= 2; |
| 979 | } |
| 980 | |
| 981 | while (n_left >= 1) |
| 982 | { |
| 983 | u32 bi0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 984 | vlib_buffer_t *b0; |
| 985 | ip6_forward_next_trace_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 986 | |
| 987 | bi0 = from[0]; |
| 988 | |
| 989 | b0 = vlib_get_buffer (vm, bi0); |
| 990 | |
| 991 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 992 | { |
| 993 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 994 | t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 995 | t0->flow_hash = vnet_buffer (b0)->ip.flow_hash; |
| 996 | t0->fib_index = |
| 997 | (vnet_buffer (b0)->sw_if_index[VLIB_TX] != |
| 998 | (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] : |
| 999 | vec_elt (im->fib_index_by_sw_if_index, |
| 1000 | vnet_buffer (b0)->sw_if_index[VLIB_RX]); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 1001 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1002 | clib_memcpy_fast (t0->packet_data, |
| 1003 | vlib_buffer_get_current (b0), |
| 1004 | sizeof (t0->packet_data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1005 | } |
| 1006 | from += 1; |
| 1007 | n_left -= 1; |
| 1008 | } |
| 1009 | } |
| 1010 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1011 | /* Compute TCP/UDP/ICMP6 checksum in software. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1012 | u16 |
| 1013 | ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, |
| 1014 | ip6_header_t * ip0, int *bogus_lengthp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1015 | { |
| 1016 | ip_csum_t sum0; |
| 1017 | u16 sum16, payload_length_host_byte_order; |
| 1018 | u32 i, n_this_buffer, n_bytes_left; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1019 | u32 headers_size = sizeof (ip0[0]); |
| 1020 | void *data_this_buffer; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1021 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1022 | ASSERT (bogus_lengthp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1023 | *bogus_lengthp = 0; |
| 1024 | |
| 1025 | /* Initialize checksum with ip header. */ |
| 1026 | sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol); |
| 1027 | payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length); |
| 1028 | data_this_buffer = (void *) (ip0 + 1); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1029 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1030 | for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++) |
| 1031 | { |
| 1032 | sum0 = ip_csum_with_carry (sum0, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1033 | clib_mem_unaligned (&ip0-> |
| 1034 | src_address.as_uword[i], |
| 1035 | uword)); |
| 1036 | sum0 = |
| 1037 | ip_csum_with_carry (sum0, |
| 1038 | clib_mem_unaligned (&ip0->dst_address.as_uword[i], |
| 1039 | uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
AkshayaNadahalli | 1b56352 | 2017-01-23 22:05:35 +0530 | [diff] [blame] | 1042 | /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) |
| 1043 | * or UDP-Ping packets */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1044 | if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1045 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1046 | u32 skip_bytes; |
| 1047 | ip6_hop_by_hop_ext_t *ext_hdr = |
| 1048 | (ip6_hop_by_hop_ext_t *) data_this_buffer; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1049 | |
| 1050 | /* validate really icmp6 next */ |
AkshayaNadahalli | 1b56352 | 2017-01-23 22:05:35 +0530 | [diff] [blame] | 1051 | ASSERT ((ext_hdr->next_hdr == IP_PROTOCOL_ICMP6) |
| 1052 | || (ext_hdr->next_hdr == IP_PROTOCOL_UDP)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1053 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1054 | skip_bytes = 8 * (1 + ext_hdr->n_data_u64s); |
| 1055 | data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1056 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1057 | payload_length_host_byte_order -= skip_bytes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1058 | headers_size += skip_bytes; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1059 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1060 | |
| 1061 | n_bytes_left = n_this_buffer = payload_length_host_byte_order; |
John Lo | 3bc6bc2 | 2019-08-03 14:36:39 -0400 | [diff] [blame] | 1062 | |
| 1063 | if (p0) |
| 1064 | { |
| 1065 | u32 n_ip_bytes_this_buffer = |
| 1066 | p0->current_length - (((u8 *) ip0 - p0->data) - p0->current_data); |
| 1067 | if (n_this_buffer + headers_size > n_ip_bytes_this_buffer) |
| 1068 | { |
| 1069 | n_this_buffer = p0->current_length > headers_size ? |
| 1070 | n_ip_bytes_this_buffer - headers_size : 0; |
| 1071 | } |
| 1072 | } |
| 1073 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1074 | while (1) |
| 1075 | { |
| 1076 | sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer); |
| 1077 | n_bytes_left -= n_this_buffer; |
| 1078 | if (n_bytes_left == 0) |
| 1079 | break; |
| 1080 | |
| 1081 | if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1082 | { |
| 1083 | *bogus_lengthp = 1; |
| 1084 | return 0xfefe; |
| 1085 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1086 | p0 = vlib_get_buffer (vm, p0->next_buffer); |
| 1087 | data_this_buffer = vlib_buffer_get_current (p0); |
John Lo | 1cf0007 | 2019-04-09 10:23:56 -0400 | [diff] [blame] | 1088 | n_this_buffer = clib_min (p0->current_length, n_bytes_left); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1089 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1090 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1091 | sum16 = ~ip_csum_fold (sum0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1092 | |
| 1093 | return sum16; |
| 1094 | } |
| 1095 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1096 | u32 |
| 1097 | ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1098 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1099 | ip6_header_t *ip0 = vlib_buffer_get_current (p0); |
| 1100 | udp_header_t *udp0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1101 | u16 sum16; |
| 1102 | int bogus_length; |
| 1103 | |
| 1104 | /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */ |
| 1105 | ASSERT (ip0->protocol == IP_PROTOCOL_TCP |
| 1106 | || ip0->protocol == IP_PROTOCOL_ICMP6 |
| 1107 | || ip0->protocol == IP_PROTOCOL_UDP |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1108 | || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1109 | |
| 1110 | udp0 = (void *) (ip0 + 1); |
| 1111 | if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0) |
| 1112 | { |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1113 | p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED |
| 1114 | | VNET_BUFFER_F_L4_CHECKSUM_CORRECT); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1115 | return p0->flags; |
| 1116 | } |
| 1117 | |
| 1118 | sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length); |
| 1119 | |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1120 | p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED |
| 1121 | | ((sum16 == 0) << VNET_BUFFER_F_LOG2_L4_CHECKSUM_CORRECT)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1122 | |
| 1123 | return p0->flags; |
| 1124 | } |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 1125 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1126 | |
AkshayaNadahalli | 0f438df | 2017-02-10 10:54:16 +0530 | [diff] [blame] | 1127 | /** |
| 1128 | * @brief returns number of links on which src is reachable. |
| 1129 | */ |
| 1130 | always_inline int |
| 1131 | ip6_urpf_loose_check (ip6_main_t * im, vlib_buffer_t * b, ip6_header_t * i) |
| 1132 | { |
| 1133 | const load_balance_t *lb0; |
| 1134 | index_t lbi; |
Florin Coras | f3a3bad | 2018-03-28 02:18:29 -0700 | [diff] [blame] | 1135 | u32 fib_index; |
AkshayaNadahalli | 0f438df | 2017-02-10 10:54:16 +0530 | [diff] [blame] | 1136 | |
Florin Coras | f3a3bad | 2018-03-28 02:18:29 -0700 | [diff] [blame] | 1137 | fib_index = vec_elt (im->fib_index_by_sw_if_index, |
| 1138 | vnet_buffer (b)->sw_if_index[VLIB_RX]); |
| 1139 | fib_index = |
| 1140 | (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ? |
| 1141 | fib_index : vnet_buffer (b)->sw_if_index[VLIB_TX]; |
AkshayaNadahalli | 0f438df | 2017-02-10 10:54:16 +0530 | [diff] [blame] | 1142 | |
Florin Coras | f3a3bad | 2018-03-28 02:18:29 -0700 | [diff] [blame] | 1143 | lbi = ip6_fib_table_fwding_lookup (im, fib_index, &i->src_address); |
AkshayaNadahalli | 0f438df | 2017-02-10 10:54:16 +0530 | [diff] [blame] | 1144 | lb0 = load_balance_get (lbi); |
| 1145 | |
| 1146 | return (fib_urpf_check_size (lb0->lb_urpf)); |
| 1147 | } |
| 1148 | |
root | c9d1c5b | 2017-08-15 12:58:31 -0400 | [diff] [blame] | 1149 | always_inline u8 |
| 1150 | ip6_next_proto_is_tcp_udp (vlib_buffer_t * p0, ip6_header_t * ip0, |
| 1151 | u32 * udp_offset0) |
| 1152 | { |
| 1153 | u32 proto0; |
| 1154 | proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_UDP, udp_offset0); |
| 1155 | if (proto0 != IP_PROTOCOL_UDP) |
| 1156 | { |
| 1157 | proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_TCP, udp_offset0); |
| 1158 | proto0 = (proto0 == IP_PROTOCOL_TCP) ? proto0 : 0; |
| 1159 | } |
| 1160 | return proto0; |
| 1161 | } |
| 1162 | |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1163 | /* *INDENT-OFF* */ |
| 1164 | VNET_FEATURE_ARC_INIT (ip6_local) = |
| 1165 | { |
| 1166 | .arc_name = "ip6-local", |
| 1167 | .start_nodes = VNET_FEATURES ("ip6-local"), |
| 1168 | }; |
| 1169 | /* *INDENT-ON* */ |
| 1170 | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1171 | always_inline uword |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1172 | ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1173 | vlib_frame_t * frame, int head_of_feature_arc) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1174 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1175 | ip6_main_t *im = &ip6_main; |
| 1176 | ip_lookup_main_t *lm = &im->lookup_main; |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1177 | u32 *from, n_left_from; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1178 | vlib_node_runtime_t *error_node = |
| 1179 | vlib_node_get_runtime (vm, ip6_input_node.index); |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1180 | u8 arc_index = vnet_feat_arc_ip6_local.feature_arc_index; |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1181 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 1182 | u16 nexts[VLIB_FRAME_SIZE], *next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1183 | |
| 1184 | from = vlib_frame_vector_args (frame); |
| 1185 | n_left_from = frame->n_vectors; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1186 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1187 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1188 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
| 1189 | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1190 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 1191 | b = bufs; |
| 1192 | next = nexts; |
| 1193 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1194 | while (n_left_from > 2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1195 | { |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1196 | /* Prefetch next iteration. */ |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1197 | if (n_left_from >= 6) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1198 | { |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1199 | vlib_prefetch_buffer_header (b[4], STORE); |
| 1200 | vlib_prefetch_buffer_header (b[5], STORE); |
| 1201 | vlib_prefetch_buffer_data (b[2], LOAD); |
| 1202 | vlib_prefetch_buffer_data (b[3], LOAD); |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1203 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1204 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1205 | u8 error[2]; |
| 1206 | error[0] = IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1207 | error[1] = IP6_ERROR_UNKNOWN_PROTOCOL; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1208 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1209 | ip6_header_t *ip[2]; |
| 1210 | ip[0] = vlib_buffer_get_current (b[0]); |
| 1211 | ip[1] = vlib_buffer_get_current (b[1]); |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1212 | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1213 | if (head_of_feature_arc) |
| 1214 | { |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1215 | vnet_buffer (b[0])->l3_hdr_offset = b[0]->current_data; |
| 1216 | vnet_buffer (b[1])->l3_hdr_offset = b[1]->current_data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1217 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1218 | u8 type[2]; |
| 1219 | type[0] = lm->builtin_protocol_by_ip_protocol[ip[0]->protocol]; |
| 1220 | type[1] = lm->builtin_protocol_by_ip_protocol[ip[1]->protocol]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1221 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1222 | u32 flags[2]; |
| 1223 | flags[0] = b[0]->flags; |
| 1224 | flags[1] = b[1]->flags; |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1225 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1226 | u32 good_l4_csum[2]; |
| 1227 | good_l4_csum[0] = |
| 1228 | flags[0] & (VNET_BUFFER_F_L4_CHECKSUM_CORRECT | |
| 1229 | VNET_BUFFER_F_OFFLOAD_TCP_CKSUM | |
| 1230 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM); |
| 1231 | good_l4_csum[1] = |
| 1232 | flags[1] & (VNET_BUFFER_F_L4_CHECKSUM_CORRECT | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1233 | VNET_BUFFER_F_OFFLOAD_TCP_CKSUM | |
| 1234 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM); |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 1235 | |
Damjan Marion | 34e823f | 2019-02-19 08:55:18 +0100 | [diff] [blame] | 1236 | u32 udp_offset[2] = { }; |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1237 | u8 is_tcp_udp[2]; |
| 1238 | is_tcp_udp[0] = |
| 1239 | ip6_next_proto_is_tcp_udp (b[0], ip[0], &udp_offset[0]); |
| 1240 | is_tcp_udp[1] = |
| 1241 | ip6_next_proto_is_tcp_udp (b[1], ip[1], &udp_offset[1]); |
| 1242 | i16 len_diff[2] = { 0 }; |
| 1243 | if (PREDICT_TRUE (is_tcp_udp[0])) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1244 | { |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1245 | udp_header_t *udp = |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1246 | (udp_header_t *) ((u8 *) ip[0] + udp_offset[0]); |
| 1247 | good_l4_csum[0] |= type[0] == IP_BUILTIN_PROTOCOL_UDP |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1248 | && udp->checksum == 0; |
| 1249 | /* optimistically verify UDP length. */ |
| 1250 | u16 ip_len, udp_len; |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1251 | ip_len = clib_net_to_host_u16 (ip[0]->payload_length); |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1252 | udp_len = clib_net_to_host_u16 (udp->length); |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1253 | len_diff[0] = ip_len - udp_len; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1254 | } |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1255 | if (PREDICT_TRUE (is_tcp_udp[1])) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1256 | { |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1257 | udp_header_t *udp = |
| 1258 | (udp_header_t *) ((u8 *) ip[1] + udp_offset[1]); |
| 1259 | good_l4_csum[1] |= type[1] == IP_BUILTIN_PROTOCOL_UDP |
| 1260 | && udp->checksum == 0; |
| 1261 | /* optimistically verify UDP length. */ |
| 1262 | u16 ip_len, udp_len; |
| 1263 | ip_len = clib_net_to_host_u16 (ip[1]->payload_length); |
| 1264 | udp_len = clib_net_to_host_u16 (udp->length); |
| 1265 | len_diff[1] = ip_len - udp_len; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1268 | good_l4_csum[0] |= type[0] == IP_BUILTIN_PROTOCOL_UNKNOWN; |
| 1269 | good_l4_csum[1] |= type[1] == IP_BUILTIN_PROTOCOL_UNKNOWN; |
| 1270 | |
| 1271 | len_diff[0] = type[0] == IP_BUILTIN_PROTOCOL_UDP ? len_diff[0] : 0; |
| 1272 | len_diff[1] = type[1] == IP_BUILTIN_PROTOCOL_UDP ? len_diff[1] : 0; |
| 1273 | |
| 1274 | u8 need_csum[2]; |
| 1275 | need_csum[0] = type[0] != IP_BUILTIN_PROTOCOL_UNKNOWN |
| 1276 | && !good_l4_csum[0] |
| 1277 | && !(flags[0] & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED); |
| 1278 | need_csum[1] = type[1] != IP_BUILTIN_PROTOCOL_UNKNOWN |
| 1279 | && !good_l4_csum[1] |
| 1280 | && !(flags[1] & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED); |
| 1281 | if (PREDICT_FALSE (need_csum[0])) |
| 1282 | { |
| 1283 | flags[0] = ip6_tcp_udp_icmp_validate_checksum (vm, b[0]); |
| 1284 | good_l4_csum[0] = flags[0] & VNET_BUFFER_F_L4_CHECKSUM_CORRECT; |
| 1285 | } |
| 1286 | if (PREDICT_FALSE (need_csum[1])) |
| 1287 | { |
| 1288 | flags[1] = ip6_tcp_udp_icmp_validate_checksum (vm, b[1]); |
| 1289 | good_l4_csum[1] = flags[1] & VNET_BUFFER_F_L4_CHECKSUM_CORRECT; |
| 1290 | } |
| 1291 | |
| 1292 | error[0] = IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1293 | error[0] = len_diff[0] < 0 ? IP6_ERROR_UDP_LENGTH : error[0]; |
| 1294 | error[1] = IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1295 | error[1] = len_diff[1] < 0 ? IP6_ERROR_UDP_LENGTH : error[1]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1296 | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1297 | STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == |
| 1298 | IP6_ERROR_UDP_CHECKSUM, |
| 1299 | "Wrong IP6 errors constants"); |
| 1300 | STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == |
| 1301 | IP6_ERROR_ICMP_CHECKSUM, |
| 1302 | "Wrong IP6 errors constants"); |
| 1303 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1304 | error[0] = |
| 1305 | !good_l4_csum[0] ? IP6_ERROR_UDP_CHECKSUM + type[0] : error[0]; |
| 1306 | error[1] = |
| 1307 | !good_l4_csum[1] ? IP6_ERROR_UDP_CHECKSUM + type[1] : error[1]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1308 | |
| 1309 | /* Drop packets from unroutable hosts. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1310 | /* If this is a neighbor solicitation (ICMP), skip source RPF check */ |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1311 | u8 unroutable[2]; |
| 1312 | unroutable[0] = error[0] == IP6_ERROR_UNKNOWN_PROTOCOL |
| 1313 | && type[0] != IP_BUILTIN_PROTOCOL_ICMP |
| 1314 | && !ip6_address_is_link_local_unicast (&ip[0]->src_address); |
| 1315 | unroutable[1] = error[1] == IP6_ERROR_UNKNOWN_PROTOCOL |
| 1316 | && type[1] != IP_BUILTIN_PROTOCOL_ICMP |
| 1317 | && !ip6_address_is_link_local_unicast (&ip[1]->src_address); |
| 1318 | if (PREDICT_FALSE (unroutable[0])) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1319 | { |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1320 | error[0] = |
| 1321 | !ip6_urpf_loose_check (im, b[0], |
| 1322 | ip[0]) ? IP6_ERROR_SRC_LOOKUP_MISS |
| 1323 | : error[0]; |
| 1324 | } |
| 1325 | if (PREDICT_FALSE (unroutable[1])) |
| 1326 | { |
| 1327 | error[1] = |
| 1328 | !ip6_urpf_loose_check (im, b[1], |
| 1329 | ip[1]) ? IP6_ERROR_SRC_LOOKUP_MISS |
| 1330 | : error[1]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1333 | vnet_buffer (b[0])->ip.fib_index = |
| 1334 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] != ~0 ? |
| 1335 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] : |
| 1336 | vnet_buffer (b[0])->ip.fib_index; |
| 1337 | vnet_buffer (b[1])->ip.fib_index = |
| 1338 | vnet_buffer (b[1])->sw_if_index[VLIB_TX] != ~0 ? |
| 1339 | vnet_buffer (b[1])->sw_if_index[VLIB_TX] : |
| 1340 | vnet_buffer (b[1])->ip.fib_index; |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1341 | } /* head_of_feature_arc */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1342 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1343 | next[0] = lm->local_next_by_ip_protocol[ip[0]->protocol]; |
| 1344 | next[0] = |
| 1345 | error[0] != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next[0]; |
| 1346 | next[1] = lm->local_next_by_ip_protocol[ip[1]->protocol]; |
| 1347 | next[1] = |
| 1348 | error[1] != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next[1]; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1349 | |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1350 | b[0]->error = error_node->errors[0]; |
| 1351 | b[1]->error = error_node->errors[1]; |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1352 | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1353 | if (head_of_feature_arc) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1354 | { |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1355 | u8 ip6_unknown[2]; |
| 1356 | ip6_unknown[0] = error[0] == (u8) IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1357 | ip6_unknown[1] = error[1] == (u8) IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1358 | if (PREDICT_TRUE (ip6_unknown[0])) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1359 | { |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1360 | u32 next32 = next[0]; |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1361 | vnet_feature_arc_start (arc_index, |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1362 | vnet_buffer (b[0])->sw_if_index |
| 1363 | [VLIB_RX], &next32, b[0]); |
| 1364 | next[0] = next32; |
| 1365 | } |
| 1366 | if (PREDICT_TRUE (ip6_unknown[1])) |
| 1367 | { |
| 1368 | u32 next32 = next[1]; |
| 1369 | vnet_feature_arc_start (arc_index, |
| 1370 | vnet_buffer (b[1])->sw_if_index |
| 1371 | [VLIB_RX], &next32, b[1]); |
| 1372 | next[1] = next32; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1373 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1374 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1375 | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1376 | /* next */ |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1377 | b += 2; |
| 1378 | next += 2; |
| 1379 | n_left_from -= 2; |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1380 | } |
Benoît Ganne | 7dcb80a | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1381 | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1382 | while (n_left_from) |
| 1383 | { |
| 1384 | u8 error; |
| 1385 | error = IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1386 | |
| 1387 | ip6_header_t *ip; |
| 1388 | ip = vlib_buffer_get_current (b[0]); |
| 1389 | |
| 1390 | if (head_of_feature_arc) |
| 1391 | { |
| 1392 | vnet_buffer (b[0])->l3_hdr_offset = b[0]->current_data; |
| 1393 | u8 type = lm->builtin_protocol_by_ip_protocol[ip->protocol]; |
| 1394 | |
| 1395 | u32 flags = b[0]->flags; |
| 1396 | u32 good_l4_csum = |
| 1397 | flags & (VNET_BUFFER_F_L4_CHECKSUM_CORRECT | |
| 1398 | VNET_BUFFER_F_OFFLOAD_TCP_CKSUM | |
| 1399 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM); |
| 1400 | |
| 1401 | u32 udp_offset; |
| 1402 | i16 len_diff = 0; |
| 1403 | u8 is_tcp_udp = ip6_next_proto_is_tcp_udp (b[0], ip, &udp_offset); |
| 1404 | if (PREDICT_TRUE (is_tcp_udp)) |
| 1405 | { |
| 1406 | udp_header_t *udp = (udp_header_t *) ((u8 *) ip + udp_offset); |
| 1407 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 1408 | good_l4_csum |= type == IP_BUILTIN_PROTOCOL_UDP |
| 1409 | && udp->checksum == 0; |
| 1410 | /* optimistically verify UDP length. */ |
| 1411 | u16 ip_len, udp_len; |
| 1412 | ip_len = clib_net_to_host_u16 (ip->payload_length); |
| 1413 | udp_len = clib_net_to_host_u16 (udp->length); |
| 1414 | len_diff = ip_len - udp_len; |
| 1415 | } |
| 1416 | |
| 1417 | good_l4_csum |= type == IP_BUILTIN_PROTOCOL_UNKNOWN; |
| 1418 | len_diff = type == IP_BUILTIN_PROTOCOL_UDP ? len_diff : 0; |
| 1419 | |
| 1420 | u8 need_csum = type != IP_BUILTIN_PROTOCOL_UNKNOWN && !good_l4_csum |
| 1421 | && !(flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED); |
| 1422 | if (PREDICT_FALSE (need_csum)) |
| 1423 | { |
| 1424 | flags = ip6_tcp_udp_icmp_validate_checksum (vm, b[0]); |
| 1425 | good_l4_csum = flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT; |
| 1426 | } |
| 1427 | |
| 1428 | error = IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1429 | error = len_diff < 0 ? IP6_ERROR_UDP_LENGTH : error; |
| 1430 | |
| 1431 | STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == |
| 1432 | IP6_ERROR_UDP_CHECKSUM, |
| 1433 | "Wrong IP6 errors constants"); |
| 1434 | STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == |
| 1435 | IP6_ERROR_ICMP_CHECKSUM, |
| 1436 | "Wrong IP6 errors constants"); |
| 1437 | |
| 1438 | error = !good_l4_csum ? IP6_ERROR_UDP_CHECKSUM + type : error; |
| 1439 | |
| 1440 | /* Drop packets from unroutable hosts. */ |
| 1441 | /* If this is a neighbor solicitation (ICMP), skip source RPF check */ |
| 1442 | u8 unroutable = error == IP6_ERROR_UNKNOWN_PROTOCOL |
| 1443 | && type != IP_BUILTIN_PROTOCOL_ICMP |
| 1444 | && !ip6_address_is_link_local_unicast (&ip->src_address); |
| 1445 | if (PREDICT_FALSE (unroutable)) |
| 1446 | { |
| 1447 | error = |
| 1448 | !ip6_urpf_loose_check (im, b[0], |
| 1449 | ip) ? IP6_ERROR_SRC_LOOKUP_MISS : |
| 1450 | error; |
| 1451 | } |
| 1452 | |
| 1453 | vnet_buffer (b[0])->ip.fib_index = |
| 1454 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] != ~0 ? |
| 1455 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] : |
| 1456 | vnet_buffer (b[0])->ip.fib_index; |
| 1457 | } /* head_of_feature_arc */ |
| 1458 | |
| 1459 | next[0] = lm->local_next_by_ip_protocol[ip->protocol]; |
| 1460 | next[0] = |
| 1461 | error != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next[0]; |
| 1462 | |
| 1463 | b[0]->error = error_node->errors[0]; |
| 1464 | |
| 1465 | if (head_of_feature_arc) |
| 1466 | { |
| 1467 | if (PREDICT_TRUE (error == (u8) IP6_ERROR_UNKNOWN_PROTOCOL)) |
| 1468 | { |
| 1469 | u32 next32 = next[0]; |
| 1470 | vnet_feature_arc_start (arc_index, |
| 1471 | vnet_buffer (b[0])->sw_if_index |
| 1472 | [VLIB_RX], &next32, b[0]); |
| 1473 | next[0] = next32; |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | /* next */ |
| 1478 | b += 1; |
| 1479 | next += 1; |
| 1480 | n_left_from -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
Benoît Ganne | 26a1019 | 2019-02-14 15:32:45 +0100 | [diff] [blame] | 1483 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1484 | return frame->n_vectors; |
| 1485 | } |
| 1486 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 1487 | VLIB_NODE_FN (ip6_local_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1488 | vlib_frame_t * frame) |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1489 | { |
| 1490 | return ip6_local_inline (vm, node, frame, 1 /* head of feature arc */ ); |
| 1491 | } |
| 1492 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1493 | /* *INDENT-OFF* */ |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 1494 | VLIB_REGISTER_NODE (ip6_local_node) = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1495 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1496 | .name = "ip6-local", |
| 1497 | .vector_size = sizeof (u32), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1498 | .format_trace = format_ip6_forward_next_trace, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1499 | .n_next_nodes = IP_LOCAL_N_NEXT, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1500 | .next_nodes = |
| 1501 | { |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1502 | [IP_LOCAL_NEXT_DROP] = "ip6-drop", |
| 1503 | [IP_LOCAL_NEXT_PUNT] = "ip6-punt", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1504 | [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup", |
| 1505 | [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input", |
Juraj Sloboda | 3048b63 | 2018-10-02 11:13:53 +0200 | [diff] [blame] | 1506 | [IP_LOCAL_NEXT_REASSEMBLY] = "ip6-reassembly", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1507 | }, |
| 1508 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1509 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1510 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 1511 | VLIB_NODE_FN (ip6_local_end_of_arc_node) (vlib_main_t * vm, |
| 1512 | vlib_node_runtime_t * node, |
| 1513 | vlib_frame_t * frame) |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1514 | { |
| 1515 | return ip6_local_inline (vm, node, frame, 0 /* head of feature arc */ ); |
| 1516 | } |
| 1517 | |
| 1518 | /* *INDENT-OFF* */ |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 1519 | VLIB_REGISTER_NODE (ip6_local_end_of_arc_node) = { |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1520 | .name = "ip6-local-end-of-arc", |
| 1521 | .vector_size = sizeof (u32), |
| 1522 | |
| 1523 | .format_trace = format_ip6_forward_next_trace, |
| 1524 | .sibling_of = "ip6-local", |
| 1525 | }; |
| 1526 | |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 1527 | VNET_FEATURE_INIT (ip6_local_end_of_arc, static) = { |
| 1528 | .arc_name = "ip6-local", |
| 1529 | .node_name = "ip6-local-end-of-arc", |
| 1530 | .runs_before = 0, /* not before any other features */ |
| 1531 | }; |
| 1532 | /* *INDENT-ON* */ |
| 1533 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 1534 | #ifdef CLIB_MARCH_VARIANT |
| 1535 | extern vlib_node_registration_t ip6_local_node; |
| 1536 | |
| 1537 | #else |
| 1538 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1539 | void |
| 1540 | ip6_register_protocol (u32 protocol, u32 node_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1541 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1542 | vlib_main_t *vm = vlib_get_main (); |
| 1543 | ip6_main_t *im = &ip6_main; |
| 1544 | ip_lookup_main_t *lm = &im->lookup_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1545 | |
| 1546 | ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol)); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1547 | lm->local_next_by_ip_protocol[protocol] = |
| 1548 | vlib_node_add_next (vm, ip6_local_node.index, node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
Neale Ranns | b538dd8 | 2019-05-21 06:54:54 -0700 | [diff] [blame] | 1551 | void |
| 1552 | ip6_unregister_protocol (u32 protocol) |
| 1553 | { |
| 1554 | ip6_main_t *im = &ip6_main; |
| 1555 | ip_lookup_main_t *lm = &im->lookup_main; |
| 1556 | |
| 1557 | ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol)); |
| 1558 | lm->local_next_by_ip_protocol[protocol] = IP_LOCAL_NEXT_PUNT; |
| 1559 | } |
| 1560 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1561 | clib_error_t * |
John Lo | 8637634 | 2018-06-11 20:14:49 -0400 | [diff] [blame] | 1562 | ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index, |
| 1563 | u8 refresh) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1564 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1565 | vnet_main_t *vnm = vnet_get_main (); |
| 1566 | ip6_main_t *im = &ip6_main; |
| 1567 | icmp6_neighbor_solicitation_header_t *h; |
| 1568 | ip6_address_t *src; |
| 1569 | ip_interface_address_t *ia; |
| 1570 | ip_adjacency_t *adj; |
| 1571 | vnet_hw_interface_t *hi; |
| 1572 | vnet_sw_interface_t *si; |
| 1573 | vlib_buffer_t *b; |
Neale Ranns | 7a27274 | 2017-05-30 02:08:14 -0700 | [diff] [blame] | 1574 | adj_index_t ai; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1575 | u32 bi = 0; |
| 1576 | int bogus_length; |
| 1577 | |
| 1578 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1579 | |
| 1580 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)) |
| 1581 | { |
| 1582 | return clib_error_return (0, "%U: interface %U down", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1583 | format_ip6_address, dst, |
| 1584 | format_vnet_sw_if_index_name, vnm, |
| 1585 | sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1588 | src = |
| 1589 | ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia); |
| 1590 | if (!src) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1591 | { |
| 1592 | vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1593 | return clib_error_return |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1594 | (0, "no matching interface address for destination %U (interface %U)", |
| 1595 | format_ip6_address, dst, |
| 1596 | format_vnet_sw_if_index_name, vnm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1599 | h = |
| 1600 | vlib_packet_template_get_packet (vm, |
| 1601 | &im->discover_neighbor_packet_template, |
| 1602 | &bi); |
John Lo | 084606b | 2018-06-19 15:27:48 -0400 | [diff] [blame] | 1603 | if (!h) |
| 1604 | return clib_error_return (0, "ICMP6 NS packet allocation failed"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1605 | |
| 1606 | hi = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 1607 | |
| 1608 | /* Destination address is a solicited node multicast address. We need to fill in |
| 1609 | the low 24 bits with low 24 bits of target's address. */ |
| 1610 | h->ip.dst_address.as_u8[13] = dst->as_u8[13]; |
| 1611 | h->ip.dst_address.as_u8[14] = dst->as_u8[14]; |
| 1612 | h->ip.dst_address.as_u8[15] = dst->as_u8[15]; |
| 1613 | |
| 1614 | h->ip.src_address = src[0]; |
| 1615 | h->neighbor.target_address = dst[0]; |
| 1616 | |
Pavel Kotucek | 5780898 | 2017-08-02 08:20:19 +0200 | [diff] [blame] | 1617 | if (PREDICT_FALSE (!hi->hw_address)) |
| 1618 | { |
| 1619 | return clib_error_return (0, "%U: interface %U do not support ip probe", |
| 1620 | format_ip6_address, dst, |
| 1621 | format_vnet_sw_if_index_name, vnm, |
| 1622 | sw_if_index); |
| 1623 | } |
| 1624 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1625 | clib_memcpy_fast (h->link_layer_option.ethernet_address, hi->hw_address, |
| 1626 | vec_len (hi->hw_address)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1627 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1628 | h->neighbor.icmp.checksum = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1629 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1630 | ASSERT (bogus_length == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1631 | |
| 1632 | b = vlib_get_buffer (vm, bi); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1633 | vnet_buffer (b)->sw_if_index[VLIB_RX] = |
| 1634 | vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1635 | |
| 1636 | /* Add encapsulation string for software interface (e.g. ethernet header). */ |
Neale Ranns | 7a27274 | 2017-05-30 02:08:14 -0700 | [diff] [blame] | 1637 | ip46_address_t nh = { |
| 1638 | .ip6 = *dst, |
| 1639 | }; |
| 1640 | |
| 1641 | ai = adj_nbr_add_or_lock (FIB_PROTOCOL_IP6, |
| 1642 | VNET_LINK_IP6, &nh, sw_if_index); |
| 1643 | adj = adj_get (ai); |
| 1644 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 1645 | /* Peer has been previously resolved, retrieve glean adj instead */ |
John Lo | 8637634 | 2018-06-11 20:14:49 -0400 | [diff] [blame] | 1646 | if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE && refresh == 0) |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 1647 | { |
| 1648 | adj_unlock (ai); |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 1649 | ai = adj_glean_add_or_lock (FIB_PROTOCOL_IP6, |
| 1650 | VNET_LINK_IP6, sw_if_index, &nh); |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 1651 | adj = adj_get (ai); |
| 1652 | } |
| 1653 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1654 | vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t)); |
| 1655 | vlib_buffer_advance (b, -adj->rewrite_header.data_bytes); |
| 1656 | |
| 1657 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1658 | vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index); |
| 1659 | u32 *to_next = vlib_frame_vector_args (f); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1660 | to_next[0] = bi; |
| 1661 | f->n_vectors = 1; |
| 1662 | vlib_put_frame_to_node (vm, hi->output_node_index, f); |
| 1663 | } |
| 1664 | |
Neale Ranns | 7a27274 | 2017-05-30 02:08:14 -0700 | [diff] [blame] | 1665 | adj_unlock (ai); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1666 | return /* no error */ 0; |
| 1667 | } |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 1668 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1669 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1670 | typedef enum |
| 1671 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1672 | IP6_REWRITE_NEXT_DROP, |
Chris Luke | 816f3e1 | 2016-06-14 16:24:47 -0400 | [diff] [blame] | 1673 | IP6_REWRITE_NEXT_ICMP_ERROR, |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1674 | IP6_REWRITE_NEXT_FRAGMENT, |
| 1675 | IP6_REWRITE_N_NEXT /* Last */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1676 | } ip6_rewrite_next_t; |
| 1677 | |
Neale Ranns | 889fe94 | 2017-06-01 05:43:19 -0400 | [diff] [blame] | 1678 | /** |
| 1679 | * This bits of an IPv6 address to mask to construct a multicast |
| 1680 | * MAC address |
| 1681 | */ |
| 1682 | #define IP6_MCAST_ADDR_MASK 0xffffffff |
| 1683 | |
Ole Troan | da6e11b | 2018-05-23 11:21:42 +0200 | [diff] [blame] | 1684 | always_inline void |
| 1685 | ip6_mtu_check (vlib_buffer_t * b, u16 packet_bytes, |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1686 | u16 adj_packet_bytes, bool is_locally_generated, |
| 1687 | u32 * next, u32 * error) |
Ole Troan | da6e11b | 2018-05-23 11:21:42 +0200 | [diff] [blame] | 1688 | { |
| 1689 | if (adj_packet_bytes >= 1280 && packet_bytes > adj_packet_bytes) |
| 1690 | { |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1691 | if (is_locally_generated) |
| 1692 | { |
| 1693 | /* IP fragmentation */ |
Ole Troan | 282093f | 2018-09-19 12:38:51 +0200 | [diff] [blame] | 1694 | ip_frag_set_vnet_buffer (b, adj_packet_bytes, |
Ole Troan | b3655e5 | 2018-08-16 22:08:49 +0200 | [diff] [blame] | 1695 | IP6_FRAG_NEXT_IP6_REWRITE, 0); |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1696 | *next = IP6_REWRITE_NEXT_FRAGMENT; |
Ole Troan | 282093f | 2018-09-19 12:38:51 +0200 | [diff] [blame] | 1697 | *error = IP6_ERROR_MTU_EXCEEDED; |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1698 | } |
| 1699 | else |
| 1700 | { |
| 1701 | *error = IP6_ERROR_MTU_EXCEEDED; |
| 1702 | icmp6_error_set_vnet_buffer (b, ICMP6_packet_too_big, 0, |
| 1703 | adj_packet_bytes); |
| 1704 | *next = IP6_REWRITE_NEXT_ICMP_ERROR; |
| 1705 | } |
Ole Troan | da6e11b | 2018-05-23 11:21:42 +0200 | [diff] [blame] | 1706 | } |
| 1707 | } |
| 1708 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1709 | always_inline uword |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 1710 | ip6_rewrite_inline_with_gso (vlib_main_t * vm, |
| 1711 | vlib_node_runtime_t * node, |
| 1712 | vlib_frame_t * frame, |
| 1713 | int do_counters, int is_midchain, int is_mcast, |
| 1714 | int do_gso) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1715 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1716 | ip_lookup_main_t *lm = &ip6_main.lookup_main; |
| 1717 | u32 *from = vlib_frame_vector_args (frame); |
| 1718 | u32 n_left_from, n_left_to_next, *to_next, next_index; |
| 1719 | vlib_node_runtime_t *error_node = |
| 1720 | vlib_node_get_runtime (vm, ip6_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1721 | |
| 1722 | n_left_from = frame->n_vectors; |
| 1723 | next_index = node->cached_next_index; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 1724 | u32 thread_index = vm->thread_index; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1725 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1726 | while (n_left_from > 0) |
| 1727 | { |
| 1728 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 1729 | |
| 1730 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 1731 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1732 | ip_adjacency_t *adj0, *adj1; |
| 1733 | vlib_buffer_t *p0, *p1; |
| 1734 | ip6_header_t *ip0, *ip1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1735 | u32 pi0, rw_len0, next0, error0, adj_index0; |
| 1736 | u32 pi1, rw_len1, next1, error1, adj_index1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1737 | u32 tx_sw_if_index0, tx_sw_if_index1; |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1738 | bool is_locally_originated0, is_locally_originated1; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1739 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1740 | /* Prefetch next iteration. */ |
| 1741 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1742 | vlib_buffer_t *p2, *p3; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1743 | |
| 1744 | p2 = vlib_get_buffer (vm, from[2]); |
| 1745 | p3 = vlib_get_buffer (vm, from[3]); |
| 1746 | |
| 1747 | vlib_prefetch_buffer_header (p2, LOAD); |
| 1748 | vlib_prefetch_buffer_header (p3, LOAD); |
| 1749 | |
| 1750 | CLIB_PREFETCH (p2->pre_data, 32, STORE); |
| 1751 | CLIB_PREFETCH (p3->pre_data, 32, STORE); |
| 1752 | |
| 1753 | CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE); |
| 1754 | CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE); |
| 1755 | } |
| 1756 | |
| 1757 | pi0 = to_next[0] = from[0]; |
| 1758 | pi1 = to_next[1] = from[1]; |
| 1759 | |
| 1760 | from += 2; |
| 1761 | n_left_from -= 2; |
| 1762 | to_next += 2; |
| 1763 | n_left_to_next -= 2; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1764 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1765 | p0 = vlib_get_buffer (vm, pi0); |
| 1766 | p1 = vlib_get_buffer (vm, pi1); |
| 1767 | |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 1768 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 1769 | adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1770 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1771 | ip0 = vlib_buffer_get_current (p0); |
| 1772 | ip1 = vlib_buffer_get_current (p1); |
| 1773 | |
| 1774 | error0 = error1 = IP6_ERROR_NONE; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1775 | next0 = next1 = IP6_REWRITE_NEXT_DROP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1776 | |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1777 | is_locally_originated0 = |
| 1778 | p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED; |
| 1779 | if (PREDICT_TRUE (!is_locally_originated0)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1780 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1781 | i32 hop_limit0 = ip0->hop_limit; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1782 | |
| 1783 | /* Input node should have reject packets with hop limit 0. */ |
| 1784 | ASSERT (ip0->hop_limit > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1785 | |
| 1786 | hop_limit0 -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1787 | |
| 1788 | ip0->hop_limit = hop_limit0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1789 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1790 | /* |
| 1791 | * If the hop count drops below 1 when forwarding, generate |
| 1792 | * an ICMP response. |
| 1793 | */ |
| 1794 | if (PREDICT_FALSE (hop_limit0 <= 0)) |
| 1795 | { |
| 1796 | error0 = IP6_ERROR_TIME_EXPIRED; |
| 1797 | next0 = IP6_REWRITE_NEXT_ICMP_ERROR; |
| 1798 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0; |
| 1799 | icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded, |
| 1800 | ICMP6_time_exceeded_ttl_exceeded_in_transit, |
| 1801 | 0); |
| 1802 | } |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 1803 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1804 | else |
| 1805 | { |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1806 | p0->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1807 | } |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1808 | is_locally_originated1 = |
| 1809 | p1->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED; |
| 1810 | if (PREDICT_TRUE (!is_locally_originated1)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1811 | { |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 1812 | i32 hop_limit1 = ip1->hop_limit; |
| 1813 | |
| 1814 | /* Input node should have reject packets with hop limit 0. */ |
| 1815 | ASSERT (ip1->hop_limit > 0); |
| 1816 | |
| 1817 | hop_limit1 -= 1; |
| 1818 | |
| 1819 | ip1->hop_limit = hop_limit1; |
| 1820 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1821 | /* |
| 1822 | * If the hop count drops below 1 when forwarding, generate |
| 1823 | * an ICMP response. |
| 1824 | */ |
| 1825 | if (PREDICT_FALSE (hop_limit1 <= 0)) |
| 1826 | { |
| 1827 | error1 = IP6_ERROR_TIME_EXPIRED; |
| 1828 | next1 = IP6_REWRITE_NEXT_ICMP_ERROR; |
| 1829 | vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0; |
| 1830 | icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded, |
| 1831 | ICMP6_time_exceeded_ttl_exceeded_in_transit, |
| 1832 | 0); |
| 1833 | } |
| 1834 | } |
| 1835 | else |
| 1836 | { |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1837 | p1->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1838 | } |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 1839 | adj0 = adj_get (adj_index0); |
| 1840 | adj1 = adj_get (adj_index1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1841 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1842 | rw_len0 = adj0[0].rewrite_header.data_bytes; |
| 1843 | rw_len1 = adj1[0].rewrite_header.data_bytes; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1844 | vnet_buffer (p0)->ip.save_rewrite_length = rw_len0; |
| 1845 | vnet_buffer (p1)->ip.save_rewrite_length = rw_len1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1846 | |
Neale Ranns | 9c6a613 | 2017-02-21 05:33:14 -0800 | [diff] [blame] | 1847 | if (do_counters) |
| 1848 | { |
| 1849 | vlib_increment_combined_counter |
| 1850 | (&adjacency_counters, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1851 | thread_index, adj_index0, 1, |
Neale Ranns | 9c6a613 | 2017-02-21 05:33:14 -0800 | [diff] [blame] | 1852 | vlib_buffer_length_in_chain (vm, p0) + rw_len0); |
| 1853 | vlib_increment_combined_counter |
| 1854 | (&adjacency_counters, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1855 | thread_index, adj_index1, 1, |
Neale Ranns | 9c6a613 | 2017-02-21 05:33:14 -0800 | [diff] [blame] | 1856 | vlib_buffer_length_in_chain (vm, p1) + rw_len1); |
| 1857 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1858 | |
| 1859 | /* Check MTU of outgoing interface. */ |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 1860 | u16 ip0_len = |
| 1861 | clib_net_to_host_u16 (ip0->payload_length) + |
| 1862 | sizeof (ip6_header_t); |
| 1863 | u16 ip1_len = |
| 1864 | clib_net_to_host_u16 (ip1->payload_length) + |
| 1865 | sizeof (ip6_header_t); |
| 1866 | if (do_gso && (p0->flags & VNET_BUFFER_F_GSO)) |
| 1867 | ip0_len = gso_mtu_sz (p0); |
| 1868 | if (do_gso && (p1->flags & VNET_BUFFER_F_GSO)) |
| 1869 | ip1_len = gso_mtu_sz (p1); |
| 1870 | |
| 1871 | |
| 1872 | |
| 1873 | ip6_mtu_check (p0, ip0_len, |
Ole Troan | da6e11b | 2018-05-23 11:21:42 +0200 | [diff] [blame] | 1874 | adj0[0].rewrite_header.max_l3_packet_bytes, |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1875 | is_locally_originated0, &next0, &error0); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 1876 | ip6_mtu_check (p1, ip1_len, |
Ole Troan | da6e11b | 2018-05-23 11:21:42 +0200 | [diff] [blame] | 1877 | adj1[0].rewrite_header.max_l3_packet_bytes, |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1878 | is_locally_originated1, &next1, &error1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1879 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1880 | /* Don't adjust the buffer for hop count issue; icmp-error node |
Jim Thompson | f324dec | 2019-04-08 03:22:21 -0500 | [diff] [blame] | 1881 | * wants to see the IP header */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1882 | if (PREDICT_TRUE (error0 == IP6_ERROR_NONE)) |
| 1883 | { |
| 1884 | p0->current_data -= rw_len0; |
| 1885 | p0->current_length += rw_len0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1886 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1887 | tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index; |
| 1888 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0; |
| 1889 | next0 = adj0[0].rewrite_header.next_index; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 1890 | |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 1891 | if (PREDICT_FALSE |
| 1892 | (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES)) |
| 1893 | vnet_feature_arc_start (lm->output_feature_arc_index, |
| 1894 | tx_sw_if_index0, &next0, p0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1895 | } |
Kingwel Xie | cb36a1d | 2019-03-20 03:45:47 -0400 | [diff] [blame] | 1896 | else |
| 1897 | { |
| 1898 | p0->error = error_node->errors[error0]; |
| 1899 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1900 | if (PREDICT_TRUE (error1 == IP6_ERROR_NONE)) |
| 1901 | { |
| 1902 | p1->current_data -= rw_len1; |
| 1903 | p1->current_length += rw_len1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1904 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1905 | tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index; |
| 1906 | vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1; |
| 1907 | next1 = adj1[0].rewrite_header.next_index; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 1908 | |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 1909 | if (PREDICT_FALSE |
| 1910 | (adj1[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES)) |
| 1911 | vnet_feature_arc_start (lm->output_feature_arc_index, |
| 1912 | tx_sw_if_index1, &next1, p1); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1913 | } |
Kingwel Xie | cb36a1d | 2019-03-20 03:45:47 -0400 | [diff] [blame] | 1914 | else |
| 1915 | { |
| 1916 | p1->error = error_node->errors[error1]; |
| 1917 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1918 | |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1919 | if (is_midchain) |
| 1920 | { |
| 1921 | /* before we paint on the next header, update the L4 |
| 1922 | * checksums if required, since there's no offload on a tunnel */ |
| 1923 | calc_checksums (vm, p0); |
| 1924 | calc_checksums (vm, p1); |
| 1925 | } |
| 1926 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1927 | /* Guess we are only writing on simple Ethernet header. */ |
| 1928 | vnet_rewrite_two_headers (adj0[0], adj1[0], |
| 1929 | ip0, ip1, sizeof (ethernet_header_t)); |
| 1930 | |
| 1931 | if (is_midchain) |
| 1932 | { |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1933 | if (adj0->sub_type.midchain.fixup_func) |
| 1934 | adj0->sub_type.midchain.fixup_func |
| 1935 | (vm, adj0, p0, adj0->sub_type.midchain.fixup_data); |
| 1936 | if (adj1->sub_type.midchain.fixup_func) |
| 1937 | adj1->sub_type.midchain.fixup_func |
| 1938 | (vm, adj1, p1, adj1->sub_type.midchain.fixup_data); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1939 | } |
| 1940 | if (is_mcast) |
| 1941 | { |
| 1942 | /* |
| 1943 | * copy bytes from the IP address into the MAC rewrite |
| 1944 | */ |
Neale Ranns | 889fe94 | 2017-06-01 05:43:19 -0400 | [diff] [blame] | 1945 | vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK, |
| 1946 | adj0-> |
| 1947 | rewrite_header.dst_mcast_offset, |
| 1948 | &ip0->dst_address.as_u32[3], |
| 1949 | (u8 *) ip0); |
| 1950 | vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK, |
| 1951 | adj1-> |
| 1952 | rewrite_header.dst_mcast_offset, |
| 1953 | &ip1->dst_address.as_u32[3], |
| 1954 | (u8 *) ip1); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1955 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 1956 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1957 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 1958 | to_next, n_left_to_next, |
| 1959 | pi0, pi1, next0, next1); |
| 1960 | } |
| 1961 | |
| 1962 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1963 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1964 | ip_adjacency_t *adj0; |
| 1965 | vlib_buffer_t *p0; |
| 1966 | ip6_header_t *ip0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1967 | u32 pi0, rw_len0; |
| 1968 | u32 adj_index0, next0, error0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1969 | u32 tx_sw_if_index0; |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1970 | bool is_locally_originated0; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1971 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1972 | pi0 = to_next[0] = from[0]; |
| 1973 | |
| 1974 | p0 = vlib_get_buffer (vm, pi0); |
| 1975 | |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 1976 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1977 | |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 1978 | adj0 = adj_get (adj_index0); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1979 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1980 | ip0 = vlib_buffer_get_current (p0); |
| 1981 | |
| 1982 | error0 = IP6_ERROR_NONE; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1983 | next0 = IP6_REWRITE_NEXT_DROP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1984 | |
| 1985 | /* Check hop limit */ |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 1986 | is_locally_originated0 = |
| 1987 | p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED; |
| 1988 | if (PREDICT_TRUE (!is_locally_originated0)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1989 | { |
| 1990 | i32 hop_limit0 = ip0->hop_limit; |
| 1991 | |
| 1992 | ASSERT (ip0->hop_limit > 0); |
| 1993 | |
| 1994 | hop_limit0 -= 1; |
| 1995 | |
| 1996 | ip0->hop_limit = hop_limit0; |
| 1997 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1998 | if (PREDICT_FALSE (hop_limit0 <= 0)) |
| 1999 | { |
| 2000 | /* |
| 2001 | * If the hop count drops below 1 when forwarding, generate |
| 2002 | * an ICMP response. |
| 2003 | */ |
| 2004 | error0 = IP6_ERROR_TIME_EXPIRED; |
| 2005 | next0 = IP6_REWRITE_NEXT_ICMP_ERROR; |
| 2006 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0; |
| 2007 | icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded, |
| 2008 | ICMP6_time_exceeded_ttl_exceeded_in_transit, |
| 2009 | 0); |
| 2010 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2011 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2012 | else |
| 2013 | { |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 2014 | p0->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2015 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2016 | |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 2017 | if (is_midchain) |
| 2018 | { |
| 2019 | calc_checksums (vm, p0); |
| 2020 | } |
| 2021 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2022 | /* Guess we are only writing on simple Ethernet header. */ |
| 2023 | vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t)); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2024 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2025 | /* Update packet buffer attributes/set output interface. */ |
| 2026 | rw_len0 = adj0[0].rewrite_header.data_bytes; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2027 | vnet_buffer (p0)->ip.save_rewrite_length = rw_len0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2028 | |
Neale Ranns | 9c6a613 | 2017-02-21 05:33:14 -0800 | [diff] [blame] | 2029 | if (do_counters) |
| 2030 | { |
| 2031 | vlib_increment_combined_counter |
| 2032 | (&adjacency_counters, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 2033 | thread_index, adj_index0, 1, |
Neale Ranns | 9c6a613 | 2017-02-21 05:33:14 -0800 | [diff] [blame] | 2034 | vlib_buffer_length_in_chain (vm, p0) + rw_len0); |
| 2035 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2036 | |
| 2037 | /* Check MTU of outgoing interface. */ |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 2038 | u16 ip0_len = |
| 2039 | clib_net_to_host_u16 (ip0->payload_length) + |
| 2040 | sizeof (ip6_header_t); |
| 2041 | if (do_gso && (p0->flags & VNET_BUFFER_F_GSO)) |
| 2042 | ip0_len = gso_mtu_sz (p0); |
| 2043 | |
| 2044 | ip6_mtu_check (p0, ip0_len, |
Ole Troan | da6e11b | 2018-05-23 11:21:42 +0200 | [diff] [blame] | 2045 | adj0[0].rewrite_header.max_l3_packet_bytes, |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 2046 | is_locally_originated0, &next0, &error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2047 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2048 | /* Don't adjust the buffer for hop count issue; icmp-error node |
Ole Troan | da6e11b | 2018-05-23 11:21:42 +0200 | [diff] [blame] | 2049 | * wants to see the IP header */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2050 | if (PREDICT_TRUE (error0 == IP6_ERROR_NONE)) |
| 2051 | { |
Chris Luke | 816f3e1 | 2016-06-14 16:24:47 -0400 | [diff] [blame] | 2052 | p0->current_data -= rw_len0; |
| 2053 | p0->current_length += rw_len0; |
| 2054 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2055 | tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 2056 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2057 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0; |
| 2058 | next0 = adj0[0].rewrite_header.next_index; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 2059 | |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 2060 | if (PREDICT_FALSE |
| 2061 | (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES)) |
| 2062 | vnet_feature_arc_start (lm->output_feature_arc_index, |
| 2063 | tx_sw_if_index0, &next0, p0); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 2064 | } |
Kingwel Xie | cb36a1d | 2019-03-20 03:45:47 -0400 | [diff] [blame] | 2065 | else |
| 2066 | { |
| 2067 | p0->error = error_node->errors[error0]; |
| 2068 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2069 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 2070 | if (is_midchain) |
| 2071 | { |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 2072 | if (adj0->sub_type.midchain.fixup_func) |
| 2073 | adj0->sub_type.midchain.fixup_func |
| 2074 | (vm, adj0, p0, adj0->sub_type.midchain.fixup_data); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 2075 | } |
| 2076 | if (is_mcast) |
| 2077 | { |
Neale Ranns | 889fe94 | 2017-06-01 05:43:19 -0400 | [diff] [blame] | 2078 | vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK, |
| 2079 | adj0-> |
| 2080 | rewrite_header.dst_mcast_offset, |
| 2081 | &ip0->dst_address.as_u32[3], |
| 2082 | (u8 *) ip0); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2083 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 2084 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2085 | from += 1; |
| 2086 | n_left_from -= 1; |
| 2087 | to_next += 1; |
| 2088 | n_left_to_next -= 1; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2089 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2090 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 2091 | to_next, n_left_to_next, |
| 2092 | pi0, next0); |
| 2093 | } |
| 2094 | |
| 2095 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 2096 | } |
| 2097 | |
| 2098 | /* Need to do trace after rewrites to pick up new packet data. */ |
| 2099 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2100 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2101 | |
| 2102 | return frame->n_vectors; |
| 2103 | } |
| 2104 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 2105 | always_inline uword |
| 2106 | ip6_rewrite_inline (vlib_main_t * vm, |
| 2107 | vlib_node_runtime_t * node, |
| 2108 | vlib_frame_t * frame, |
| 2109 | int do_counters, int is_midchain, int is_mcast) |
| 2110 | { |
| 2111 | vnet_main_t *vnm = vnet_get_main (); |
| 2112 | if (PREDICT_FALSE (vnm->interface_main.gso_interface_count > 0)) |
| 2113 | return ip6_rewrite_inline_with_gso (vm, node, frame, do_counters, |
| 2114 | is_midchain, is_mcast, |
| 2115 | 1 /* do_gso */ ); |
| 2116 | else |
| 2117 | return ip6_rewrite_inline_with_gso (vm, node, frame, do_counters, |
| 2118 | is_midchain, is_mcast, |
| 2119 | 0 /* no do_gso */ ); |
| 2120 | } |
| 2121 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2122 | VLIB_NODE_FN (ip6_rewrite_node) (vlib_main_t * vm, |
| 2123 | vlib_node_runtime_t * node, |
| 2124 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2125 | { |
Neale Ranns | 9c6a613 | 2017-02-21 05:33:14 -0800 | [diff] [blame] | 2126 | if (adj_are_counters_enabled ()) |
| 2127 | return ip6_rewrite_inline (vm, node, frame, 1, 0, 0); |
| 2128 | else |
| 2129 | return ip6_rewrite_inline (vm, node, frame, 0, 0, 0); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2132 | VLIB_NODE_FN (ip6_rewrite_bcast_node) (vlib_main_t * vm, |
| 2133 | vlib_node_runtime_t * node, |
| 2134 | vlib_frame_t * frame) |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2135 | { |
| 2136 | if (adj_are_counters_enabled ()) |
| 2137 | return ip6_rewrite_inline (vm, node, frame, 1, 0, 0); |
| 2138 | else |
| 2139 | return ip6_rewrite_inline (vm, node, frame, 0, 0, 0); |
| 2140 | } |
| 2141 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2142 | VLIB_NODE_FN (ip6_rewrite_mcast_node) (vlib_main_t * vm, |
| 2143 | vlib_node_runtime_t * node, |
| 2144 | vlib_frame_t * frame) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2145 | { |
Neale Ranns | 9c6a613 | 2017-02-21 05:33:14 -0800 | [diff] [blame] | 2146 | if (adj_are_counters_enabled ()) |
| 2147 | return ip6_rewrite_inline (vm, node, frame, 1, 0, 1); |
| 2148 | else |
| 2149 | return ip6_rewrite_inline (vm, node, frame, 0, 0, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2152 | VLIB_NODE_FN (ip6_midchain_node) (vlib_main_t * vm, |
| 2153 | vlib_node_runtime_t * node, |
| 2154 | vlib_frame_t * frame) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2155 | { |
Neale Ranns | 9c6a613 | 2017-02-21 05:33:14 -0800 | [diff] [blame] | 2156 | if (adj_are_counters_enabled ()) |
| 2157 | return ip6_rewrite_inline (vm, node, frame, 1, 1, 0); |
| 2158 | else |
| 2159 | return ip6_rewrite_inline (vm, node, frame, 0, 1, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2162 | VLIB_NODE_FN (ip6_mcast_midchain_node) (vlib_main_t * vm, |
| 2163 | vlib_node_runtime_t * node, |
| 2164 | vlib_frame_t * frame) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2165 | { |
| 2166 | if (adj_are_counters_enabled ()) |
| 2167 | return ip6_rewrite_inline (vm, node, frame, 1, 1, 1); |
| 2168 | else |
Neale Ranns | 9f171f5 | 2017-04-11 08:56:53 -0700 | [diff] [blame] | 2169 | return ip6_rewrite_inline (vm, node, frame, 0, 1, 1); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2170 | } |
| 2171 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2172 | /* *INDENT-OFF* */ |
| 2173 | VLIB_REGISTER_NODE (ip6_midchain_node) = |
| 2174 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2175 | .name = "ip6-midchain", |
| 2176 | .vector_size = sizeof (u32), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2177 | .format_trace = format_ip6_forward_next_trace, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 2178 | .sibling_of = "ip6-rewrite", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2179 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2180 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2181 | VLIB_REGISTER_NODE (ip6_rewrite_node) = |
| 2182 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2183 | .name = "ip6-rewrite", |
| 2184 | .vector_size = sizeof (u32), |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 2185 | .format_trace = format_ip6_rewrite_trace, |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 2186 | .n_next_nodes = IP6_REWRITE_N_NEXT, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2187 | .next_nodes = |
| 2188 | { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 2189 | [IP6_REWRITE_NEXT_DROP] = "ip6-drop", |
Chris Luke | 816f3e1 | 2016-06-14 16:24:47 -0400 | [diff] [blame] | 2190 | [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error", |
Ole Troan | 313f7e2 | 2018-04-10 16:02:51 +0200 | [diff] [blame] | 2191 | [IP6_REWRITE_NEXT_FRAGMENT] = "ip6-frag", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2192 | }, |
| 2193 | }; |
| 2194 | |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2195 | VLIB_REGISTER_NODE (ip6_rewrite_bcast_node) = { |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2196 | .name = "ip6-rewrite-bcast", |
| 2197 | .vector_size = sizeof (u32), |
| 2198 | |
| 2199 | .format_trace = format_ip6_rewrite_trace, |
| 2200 | .sibling_of = "ip6-rewrite", |
| 2201 | }; |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2202 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2203 | VLIB_REGISTER_NODE (ip6_rewrite_mcast_node) = |
| 2204 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2205 | .name = "ip6-rewrite-mcast", |
| 2206 | .vector_size = sizeof (u32), |
| 2207 | .format_trace = format_ip6_rewrite_trace, |
| 2208 | .sibling_of = "ip6-rewrite", |
| 2209 | }; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2210 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2211 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2212 | VLIB_REGISTER_NODE (ip6_mcast_midchain_node) = |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2213 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2214 | .name = "ip6-mcast-midchain", |
| 2215 | .vector_size = sizeof (u32), |
| 2216 | .format_trace = format_ip6_rewrite_trace, |
| 2217 | .sibling_of = "ip6-rewrite", |
| 2218 | }; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2219 | |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 2220 | /* *INDENT-ON* */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2221 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2222 | /* |
| 2223 | * Hop-by-Hop handling |
| 2224 | */ |
Benoît Ganne | 47727c0 | 2019-02-12 13:35:08 +0100 | [diff] [blame] | 2225 | #ifndef CLIB_MARCH_VARIANT |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2226 | ip6_hop_by_hop_main_t ip6_hop_by_hop_main; |
Benoît Ganne | 47727c0 | 2019-02-12 13:35:08 +0100 | [diff] [blame] | 2227 | #endif /* CLIB_MARCH_VARIANT */ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2228 | |
| 2229 | #define foreach_ip6_hop_by_hop_error \ |
| 2230 | _(PROCESSED, "pkts with ip6 hop-by-hop options") \ |
| 2231 | _(FORMAT, "incorrectly formatted hop-by-hop options") \ |
| 2232 | _(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options") |
| 2233 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2234 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2235 | typedef enum |
| 2236 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2237 | #define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym, |
| 2238 | foreach_ip6_hop_by_hop_error |
| 2239 | #undef _ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2240 | IP6_HOP_BY_HOP_N_ERROR, |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2241 | } ip6_hop_by_hop_error_t; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2242 | /* *INDENT-ON* */ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2243 | |
| 2244 | /* |
| 2245 | * Primary h-b-h handler trace support |
| 2246 | * We work pretty hard on the problem for obvious reasons |
| 2247 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2248 | typedef struct |
| 2249 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2250 | u32 next_index; |
| 2251 | u32 trace_len; |
| 2252 | u8 option_data[256]; |
| 2253 | } ip6_hop_by_hop_trace_t; |
| 2254 | |
Benoît Ganne | 47727c0 | 2019-02-12 13:35:08 +0100 | [diff] [blame] | 2255 | extern vlib_node_registration_t ip6_hop_by_hop_node; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2256 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2257 | static char *ip6_hop_by_hop_error_strings[] = { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2258 | #define _(sym,string) string, |
| 2259 | foreach_ip6_hop_by_hop_error |
| 2260 | #undef _ |
| 2261 | }; |
| 2262 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2263 | #ifndef CLIB_MARCH_VARIANT |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 2264 | u8 * |
| 2265 | format_ip6_hop_by_hop_ext_hdr (u8 * s, va_list * args) |
| 2266 | { |
| 2267 | ip6_hop_by_hop_header_t *hbh0 = va_arg (*args, ip6_hop_by_hop_header_t *); |
| 2268 | int total_len = va_arg (*args, int); |
| 2269 | ip6_hop_by_hop_option_t *opt0, *limit0; |
| 2270 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
| 2271 | u8 type0; |
| 2272 | |
| 2273 | s = format (s, "IP6_HOP_BY_HOP: next protocol %d len %d total %d", |
| 2274 | hbh0->protocol, (hbh0->length + 1) << 3, total_len); |
| 2275 | |
| 2276 | opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1); |
| 2277 | limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + total_len); |
| 2278 | |
| 2279 | while (opt0 < limit0) |
| 2280 | { |
| 2281 | type0 = opt0->type; |
| 2282 | switch (type0) |
| 2283 | { |
| 2284 | case 0: /* Pad, just stop */ |
| 2285 | opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0 + 1); |
| 2286 | break; |
| 2287 | |
| 2288 | default: |
| 2289 | if (hm->trace[type0]) |
| 2290 | { |
| 2291 | s = (*hm->trace[type0]) (s, opt0); |
| 2292 | } |
| 2293 | else |
| 2294 | { |
| 2295 | s = |
| 2296 | format (s, "\n unrecognized option %d length %d", type0, |
| 2297 | opt0->length); |
| 2298 | } |
| 2299 | opt0 = |
| 2300 | (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length + |
| 2301 | sizeof (ip6_hop_by_hop_option_t)); |
| 2302 | break; |
| 2303 | } |
| 2304 | } |
| 2305 | return s; |
| 2306 | } |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2307 | #endif |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 2308 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2309 | static u8 * |
| 2310 | format_ip6_hop_by_hop_trace (u8 * s, va_list * args) |
| 2311 | { |
| 2312 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 2313 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2314 | ip6_hop_by_hop_trace_t *t = va_arg (*args, ip6_hop_by_hop_trace_t *); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2315 | ip6_hop_by_hop_header_t *hbh0; |
| 2316 | ip6_hop_by_hop_option_t *opt0, *limit0; |
| 2317 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
| 2318 | |
| 2319 | u8 type0; |
| 2320 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2321 | hbh0 = (ip6_hop_by_hop_header_t *) t->option_data; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2322 | |
| 2323 | s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2324 | t->next_index, (hbh0->length + 1) << 3, t->trace_len); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2325 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2326 | opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1); |
| 2327 | limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0) + t->trace_len; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2328 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2329 | while (opt0 < limit0) |
| 2330 | { |
| 2331 | type0 = opt0->type; |
| 2332 | switch (type0) |
| 2333 | { |
| 2334 | case 0: /* Pad, just stop */ |
| 2335 | opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1; |
| 2336 | break; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2337 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2338 | default: |
| 2339 | if (hm->trace[type0]) |
| 2340 | { |
| 2341 | s = (*hm->trace[type0]) (s, opt0); |
| 2342 | } |
| 2343 | else |
| 2344 | { |
| 2345 | s = |
| 2346 | format (s, "\n unrecognized option %d length %d", type0, |
| 2347 | opt0->length); |
| 2348 | } |
| 2349 | opt0 = |
| 2350 | (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length + |
| 2351 | sizeof (ip6_hop_by_hop_option_t)); |
| 2352 | break; |
| 2353 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2354 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2355 | return s; |
| 2356 | } |
| 2357 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2358 | always_inline u8 |
| 2359 | ip6_scan_hbh_options (vlib_buffer_t * b0, |
| 2360 | ip6_header_t * ip0, |
| 2361 | ip6_hop_by_hop_header_t * hbh0, |
| 2362 | ip6_hop_by_hop_option_t * opt0, |
| 2363 | ip6_hop_by_hop_option_t * limit0, u32 * next0) |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2364 | { |
| 2365 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
| 2366 | u8 type0; |
| 2367 | u8 error0 = 0; |
| 2368 | |
| 2369 | while (opt0 < limit0) |
| 2370 | { |
| 2371 | type0 = opt0->type; |
| 2372 | switch (type0) |
| 2373 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2374 | case 0: /* Pad1 */ |
| 2375 | opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2376 | continue; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2377 | case 1: /* PadN */ |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2378 | break; |
| 2379 | default: |
| 2380 | if (hm->options[type0]) |
| 2381 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2382 | if ((*hm->options[type0]) (b0, ip0, opt0) < 0) |
| 2383 | { |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2384 | error0 = IP6_HOP_BY_HOP_ERROR_FORMAT; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2385 | return (error0); |
| 2386 | } |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2387 | } |
| 2388 | else |
| 2389 | { |
| 2390 | /* Unrecognized mandatory option, check the two high order bits */ |
| 2391 | switch (opt0->type & HBH_OPTION_TYPE_HIGH_ORDER_BITS) |
| 2392 | { |
| 2393 | case HBH_OPTION_TYPE_SKIP_UNKNOWN: |
| 2394 | break; |
| 2395 | case HBH_OPTION_TYPE_DISCARD_UNKNOWN: |
| 2396 | error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION; |
| 2397 | *next0 = IP_LOOKUP_NEXT_DROP; |
| 2398 | break; |
| 2399 | case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP: |
| 2400 | error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION; |
| 2401 | *next0 = IP_LOOKUP_NEXT_ICMP_ERROR; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2402 | icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem, |
| 2403 | ICMP6_parameter_problem_unrecognized_option, |
| 2404 | (u8 *) opt0 - (u8 *) ip0); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2405 | break; |
| 2406 | case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST: |
| 2407 | error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2408 | if (!ip6_address_is_multicast (&ip0->dst_address)) |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2409 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2410 | *next0 = IP_LOOKUP_NEXT_ICMP_ERROR; |
| 2411 | icmp6_error_set_vnet_buffer (b0, |
| 2412 | ICMP6_parameter_problem, |
| 2413 | ICMP6_parameter_problem_unrecognized_option, |
| 2414 | (u8 *) opt0 - (u8 *) ip0); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2415 | } |
| 2416 | else |
| 2417 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2418 | *next0 = IP_LOOKUP_NEXT_DROP; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2419 | } |
| 2420 | break; |
| 2421 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2422 | return (error0); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2423 | } |
| 2424 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2425 | opt0 = |
| 2426 | (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length + |
| 2427 | sizeof (ip6_hop_by_hop_option_t)); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2428 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2429 | return (error0); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2430 | } |
| 2431 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2432 | /* |
| 2433 | * Process the Hop-by-Hop Options header |
| 2434 | */ |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2435 | VLIB_NODE_FN (ip6_hop_by_hop_node) (vlib_main_t * vm, |
| 2436 | vlib_node_runtime_t * node, |
| 2437 | vlib_frame_t * frame) |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2438 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2439 | vlib_node_runtime_t *error_node = |
| 2440 | vlib_node_get_runtime (vm, ip6_hop_by_hop_node.index); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2441 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
| 2442 | u32 n_left_from, *from, *to_next; |
| 2443 | ip_lookup_next_t next_index; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2444 | |
| 2445 | from = vlib_frame_vector_args (frame); |
| 2446 | n_left_from = frame->n_vectors; |
| 2447 | next_index = node->cached_next_index; |
| 2448 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2449 | while (n_left_from > 0) |
| 2450 | { |
| 2451 | u32 n_left_to_next; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2452 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2453 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2454 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2455 | while (n_left_from >= 4 && n_left_to_next >= 2) |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2456 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2457 | u32 bi0, bi1; |
| 2458 | vlib_buffer_t *b0, *b1; |
| 2459 | u32 next0, next1; |
| 2460 | ip6_header_t *ip0, *ip1; |
| 2461 | ip6_hop_by_hop_header_t *hbh0, *hbh1; |
| 2462 | ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1; |
| 2463 | u8 error0 = 0, error1 = 0; |
| 2464 | |
| 2465 | /* Prefetch next iteration. */ |
| 2466 | { |
| 2467 | vlib_buffer_t *p2, *p3; |
| 2468 | |
| 2469 | p2 = vlib_get_buffer (vm, from[2]); |
| 2470 | p3 = vlib_get_buffer (vm, from[3]); |
| 2471 | |
| 2472 | vlib_prefetch_buffer_header (p2, LOAD); |
| 2473 | vlib_prefetch_buffer_header (p3, LOAD); |
| 2474 | |
| 2475 | CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 2476 | CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2477 | } |
| 2478 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2479 | /* Speculatively enqueue b0, b1 to the current next frame */ |
| 2480 | to_next[0] = bi0 = from[0]; |
| 2481 | to_next[1] = bi1 = from[1]; |
| 2482 | from += 2; |
| 2483 | to_next += 2; |
| 2484 | n_left_from -= 2; |
| 2485 | n_left_to_next -= 2; |
| 2486 | |
| 2487 | b0 = vlib_get_buffer (vm, bi0); |
| 2488 | b1 = vlib_get_buffer (vm, bi1); |
| 2489 | |
| 2490 | /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */ |
| 2491 | u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 2492 | ip_adjacency_t *adj0 = adj_get (adj_index0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2493 | u32 adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 2494 | ip_adjacency_t *adj1 = adj_get (adj_index1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2495 | |
| 2496 | /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */ |
| 2497 | next0 = adj0->lookup_next_index; |
| 2498 | next1 = adj1->lookup_next_index; |
| 2499 | |
| 2500 | ip0 = vlib_buffer_get_current (b0); |
| 2501 | ip1 = vlib_buffer_get_current (b1); |
| 2502 | hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1); |
| 2503 | hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1); |
| 2504 | opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1); |
| 2505 | opt1 = (ip6_hop_by_hop_option_t *) (hbh1 + 1); |
| 2506 | limit0 = |
| 2507 | (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + |
| 2508 | ((hbh0->length + 1) << 3)); |
| 2509 | limit1 = |
| 2510 | (ip6_hop_by_hop_option_t *) ((u8 *) hbh1 + |
| 2511 | ((hbh1->length + 1) << 3)); |
| 2512 | |
| 2513 | /* |
| 2514 | * Basic validity checks |
| 2515 | */ |
| 2516 | if ((hbh0->length + 1) << 3 > |
| 2517 | clib_net_to_host_u16 (ip0->payload_length)) |
| 2518 | { |
| 2519 | error0 = IP6_HOP_BY_HOP_ERROR_FORMAT; |
| 2520 | next0 = IP_LOOKUP_NEXT_DROP; |
| 2521 | goto outdual; |
| 2522 | } |
| 2523 | /* Scan the set of h-b-h options, process ones that we understand */ |
| 2524 | error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0); |
| 2525 | |
| 2526 | if ((hbh1->length + 1) << 3 > |
| 2527 | clib_net_to_host_u16 (ip1->payload_length)) |
| 2528 | { |
| 2529 | error1 = IP6_HOP_BY_HOP_ERROR_FORMAT; |
| 2530 | next1 = IP_LOOKUP_NEXT_DROP; |
| 2531 | goto outdual; |
| 2532 | } |
| 2533 | /* Scan the set of h-b-h options, process ones that we understand */ |
| 2534 | error1 = ip6_scan_hbh_options (b1, ip1, hbh1, opt1, limit1, &next1); |
| 2535 | |
| 2536 | outdual: |
| 2537 | /* Has the classifier flagged this buffer for special treatment? */ |
| 2538 | if (PREDICT_FALSE |
| 2539 | ((error0 == 0) |
| 2540 | && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP))) |
| 2541 | next0 = hm->next_override; |
| 2542 | |
| 2543 | /* Has the classifier flagged this buffer for special treatment? */ |
| 2544 | if (PREDICT_FALSE |
| 2545 | ((error1 == 0) |
| 2546 | && (vnet_buffer (b1)->l2_classify.opaque_index & OI_DECAP))) |
| 2547 | next1 = hm->next_override; |
| 2548 | |
| 2549 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) |
| 2550 | { |
| 2551 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 2552 | { |
| 2553 | ip6_hop_by_hop_trace_t *t = |
| 2554 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 2555 | u32 trace_len = (hbh0->length + 1) << 3; |
| 2556 | t->next_index = next0; |
| 2557 | /* Capture the h-b-h option verbatim */ |
| 2558 | trace_len = |
| 2559 | trace_len < |
| 2560 | ARRAY_LEN (t->option_data) ? trace_len : |
| 2561 | ARRAY_LEN (t->option_data); |
| 2562 | t->trace_len = trace_len; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 2563 | clib_memcpy_fast (t->option_data, hbh0, trace_len); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2564 | } |
| 2565 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 2566 | { |
| 2567 | ip6_hop_by_hop_trace_t *t = |
| 2568 | vlib_add_trace (vm, node, b1, sizeof (*t)); |
| 2569 | u32 trace_len = (hbh1->length + 1) << 3; |
| 2570 | t->next_index = next1; |
| 2571 | /* Capture the h-b-h option verbatim */ |
| 2572 | trace_len = |
| 2573 | trace_len < |
| 2574 | ARRAY_LEN (t->option_data) ? trace_len : |
| 2575 | ARRAY_LEN (t->option_data); |
| 2576 | t->trace_len = trace_len; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 2577 | clib_memcpy_fast (t->option_data, hbh1, trace_len); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | } |
| 2581 | |
| 2582 | b0->error = error_node->errors[error0]; |
| 2583 | b1->error = error_node->errors[error1]; |
| 2584 | |
| 2585 | /* verify speculative enqueue, maybe switch current next frame */ |
| 2586 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 2587 | n_left_to_next, bi0, bi1, next0, |
| 2588 | next1); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2589 | } |
| 2590 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2591 | while (n_left_from > 0 && n_left_to_next > 0) |
| 2592 | { |
| 2593 | u32 bi0; |
| 2594 | vlib_buffer_t *b0; |
| 2595 | u32 next0; |
| 2596 | ip6_header_t *ip0; |
| 2597 | ip6_hop_by_hop_header_t *hbh0; |
| 2598 | ip6_hop_by_hop_option_t *opt0, *limit0; |
| 2599 | u8 error0 = 0; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2600 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2601 | /* Speculatively enqueue b0 to the current next frame */ |
| 2602 | bi0 = from[0]; |
| 2603 | to_next[0] = bi0; |
| 2604 | from += 1; |
| 2605 | to_next += 1; |
| 2606 | n_left_from -= 1; |
| 2607 | n_left_to_next -= 1; |
| 2608 | |
| 2609 | b0 = vlib_get_buffer (vm, bi0); |
| 2610 | /* |
| 2611 | * Default use the next_index from the adjacency. |
| 2612 | * A HBH option rarely redirects to a different node |
| 2613 | */ |
| 2614 | u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 2615 | ip_adjacency_t *adj0 = adj_get (adj_index0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2616 | next0 = adj0->lookup_next_index; |
| 2617 | |
| 2618 | ip0 = vlib_buffer_get_current (b0); |
| 2619 | hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1); |
| 2620 | opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1); |
| 2621 | limit0 = |
| 2622 | (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + |
| 2623 | ((hbh0->length + 1) << 3)); |
| 2624 | |
| 2625 | /* |
| 2626 | * Basic validity checks |
| 2627 | */ |
| 2628 | if ((hbh0->length + 1) << 3 > |
| 2629 | clib_net_to_host_u16 (ip0->payload_length)) |
| 2630 | { |
| 2631 | error0 = IP6_HOP_BY_HOP_ERROR_FORMAT; |
| 2632 | next0 = IP_LOOKUP_NEXT_DROP; |
| 2633 | goto out0; |
| 2634 | } |
| 2635 | |
| 2636 | /* Scan the set of h-b-h options, process ones that we understand */ |
| 2637 | error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0); |
| 2638 | |
| 2639 | out0: |
| 2640 | /* Has the classifier flagged this buffer for special treatment? */ |
| 2641 | if (PREDICT_FALSE |
| 2642 | ((error0 == 0) |
| 2643 | && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP))) |
| 2644 | next0 = hm->next_override; |
| 2645 | |
| 2646 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 2647 | { |
| 2648 | ip6_hop_by_hop_trace_t *t = |
| 2649 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 2650 | u32 trace_len = (hbh0->length + 1) << 3; |
| 2651 | t->next_index = next0; |
| 2652 | /* Capture the h-b-h option verbatim */ |
| 2653 | trace_len = |
| 2654 | trace_len < |
| 2655 | ARRAY_LEN (t->option_data) ? trace_len : |
| 2656 | ARRAY_LEN (t->option_data); |
| 2657 | t->trace_len = trace_len; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 2658 | clib_memcpy_fast (t->option_data, hbh0, trace_len); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | b0->error = error_node->errors[error0]; |
| 2662 | |
| 2663 | /* verify speculative enqueue, maybe switch current next frame */ |
| 2664 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 2665 | n_left_to_next, bi0, next0); |
| 2666 | } |
| 2667 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2668 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2669 | return frame->n_vectors; |
| 2670 | } |
| 2671 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2672 | /* *INDENT-OFF* */ |
| 2673 | VLIB_REGISTER_NODE (ip6_hop_by_hop_node) = |
| 2674 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2675 | .name = "ip6-hop-by-hop", |
Ole Troan | 964f93e | 2016-06-10 13:22:36 +0200 | [diff] [blame] | 2676 | .sibling_of = "ip6-lookup", |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2677 | .vector_size = sizeof (u32), |
| 2678 | .format_trace = format_ip6_hop_by_hop_trace, |
| 2679 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2680 | .n_errors = ARRAY_LEN (ip6_hop_by_hop_error_strings), |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2681 | .error_strings = ip6_hop_by_hop_error_strings, |
Ole Troan | 964f93e | 2016-06-10 13:22:36 +0200 | [diff] [blame] | 2682 | .n_next_nodes = 0, |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2683 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2684 | /* *INDENT-ON* */ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2685 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2686 | static clib_error_t * |
| 2687 | ip6_hop_by_hop_init (vlib_main_t * vm) |
| 2688 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2689 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 2690 | clib_memset (hm->options, 0, sizeof (hm->options)); |
| 2691 | clib_memset (hm->trace, 0, sizeof (hm->trace)); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2692 | hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2693 | return (0); |
| 2694 | } |
| 2695 | |
| 2696 | VLIB_INIT_FUNCTION (ip6_hop_by_hop_init); |
| 2697 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2698 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2699 | void |
| 2700 | ip6_hbh_set_next_override (uword next) |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2701 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2702 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2703 | |
| 2704 | hm->next_override = next; |
| 2705 | } |
| 2706 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2707 | int |
| 2708 | ip6_hbh_register_option (u8 option, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2709 | int options (vlib_buffer_t * b, ip6_header_t * ip, |
| 2710 | ip6_hop_by_hop_option_t * opt), |
| 2711 | u8 * trace (u8 * s, ip6_hop_by_hop_option_t * opt)) |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2712 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2713 | ip6_main_t *im = &ip6_main; |
| 2714 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2715 | |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 2716 | ASSERT ((u32) option < ARRAY_LEN (hm->options)); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2717 | |
| 2718 | /* Already registered */ |
| 2719 | if (hm->options[option]) |
| 2720 | return (-1); |
| 2721 | |
| 2722 | hm->options[option] = options; |
| 2723 | hm->trace[option] = trace; |
| 2724 | |
| 2725 | /* Set global variable */ |
| 2726 | im->hbh_enabled = 1; |
| 2727 | |
| 2728 | return (0); |
| 2729 | } |
| 2730 | |
| 2731 | int |
| 2732 | ip6_hbh_unregister_option (u8 option) |
| 2733 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2734 | ip6_main_t *im = &ip6_main; |
| 2735 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2736 | |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 2737 | ASSERT ((u32) option < ARRAY_LEN (hm->options)); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2738 | |
| 2739 | /* Not registered */ |
| 2740 | if (!hm->options[option]) |
| 2741 | return (-1); |
| 2742 | |
| 2743 | hm->options[option] = NULL; |
| 2744 | hm->trace[option] = NULL; |
| 2745 | |
| 2746 | /* Disable global knob if this was the last option configured */ |
| 2747 | int i; |
| 2748 | bool found = false; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2749 | for (i = 0; i < 256; i++) |
| 2750 | { |
| 2751 | if (hm->options[option]) |
| 2752 | { |
| 2753 | found = true; |
| 2754 | break; |
| 2755 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2756 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2757 | if (!found) |
| 2758 | im->hbh_enabled = 0; |
| 2759 | |
| 2760 | return (0); |
| 2761 | } |
| 2762 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2763 | /* Global IP6 main. */ |
| 2764 | ip6_main_t ip6_main; |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2765 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2766 | |
| 2767 | static clib_error_t * |
| 2768 | ip6_lookup_init (vlib_main_t * vm) |
| 2769 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2770 | ip6_main_t *im = &ip6_main; |
| 2771 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2772 | uword i; |
| 2773 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 2774 | if ((error = vlib_call_init_function (vm, vnet_feature_init))) |
| 2775 | return error; |
| 2776 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2777 | for (i = 0; i < ARRAY_LEN (im->fib_masks); i++) |
| 2778 | { |
| 2779 | u32 j, i0, i1; |
| 2780 | |
| 2781 | i0 = i / 32; |
| 2782 | i1 = i % 32; |
| 2783 | |
| 2784 | for (j = 0; j < i0; j++) |
| 2785 | im->fib_masks[i].as_u32[j] = ~0; |
| 2786 | |
| 2787 | if (i1) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2788 | im->fib_masks[i].as_u32[i0] = |
| 2789 | clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1); |
| 2793 | |
| 2794 | if (im->lookup_table_nbuckets == 0) |
| 2795 | im->lookup_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS; |
| 2796 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2797 | im->lookup_table_nbuckets = 1 << max_log2 (im->lookup_table_nbuckets); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2798 | |
| 2799 | if (im->lookup_table_size == 0) |
| 2800 | im->lookup_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2801 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2802 | clib_bihash_init_24_8 (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash), |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2803 | "ip6 FIB fwding table", |
| 2804 | im->lookup_table_nbuckets, im->lookup_table_size); |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2805 | clib_bihash_init_24_8 (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2806 | "ip6 FIB non-fwding table", |
| 2807 | im->lookup_table_nbuckets, im->lookup_table_size); |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2808 | clib_bihash_init_40_8 (&im->ip6_mtable.ip6_mhash, |
| 2809 | "ip6 mFIB table", |
| 2810 | im->lookup_table_nbuckets, im->lookup_table_size); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2811 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2812 | /* Create FIB with index 0 and table id of 0. */ |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 2813 | fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0, |
| 2814 | FIB_SOURCE_DEFAULT_ROUTE); |
| 2815 | mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0, |
| 2816 | MFIB_SOURCE_DEFAULT_ROUTE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2817 | |
| 2818 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2819 | pg_node_t *pn; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2820 | pn = pg_get_node (ip6_lookup_node.index); |
| 2821 | pn->unformat_edit = unformat_pg_ip6_header; |
| 2822 | } |
| 2823 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2824 | /* Unless explicitly configured, don't process HBH options */ |
| 2825 | im->hbh_enabled = 0; |
| 2826 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2827 | { |
| 2828 | icmp6_neighbor_solicitation_header_t p; |
| 2829 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 2830 | clib_memset (&p, 0, sizeof (p)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2831 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2832 | p.ip.ip_version_traffic_class_and_flow_label = |
| 2833 | clib_host_to_net_u32 (0x6 << 28); |
| 2834 | p.ip.payload_length = |
| 2835 | clib_host_to_net_u16 (sizeof (p) - |
| 2836 | STRUCT_OFFSET_OF |
| 2837 | (icmp6_neighbor_solicitation_header_t, neighbor)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2838 | p.ip.protocol = IP_PROTOCOL_ICMP6; |
| 2839 | p.ip.hop_limit = 255; |
| 2840 | ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0); |
| 2841 | |
| 2842 | p.neighbor.icmp.type = ICMP6_neighbor_solicitation; |
| 2843 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2844 | p.link_layer_option.header.type = |
| 2845 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address; |
| 2846 | p.link_layer_option.header.n_data_u64s = |
| 2847 | sizeof (p.link_layer_option) / sizeof (u64); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2848 | |
| 2849 | vlib_packet_template_init (vm, |
| 2850 | &im->discover_neighbor_packet_template, |
| 2851 | &p, sizeof (p), |
| 2852 | /* alloc chunk size */ 8, |
| 2853 | "ip6 neighbor discovery"); |
| 2854 | } |
| 2855 | |
Dave Barach | 203c632 | 2016-06-26 10:29:03 -0400 | [diff] [blame] | 2856 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2857 | } |
| 2858 | |
| 2859 | VLIB_INIT_FUNCTION (ip6_lookup_init); |
| 2860 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2861 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2862 | test_ip6_link_command_fn (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2863 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2864 | { |
| 2865 | u8 mac[6]; |
| 2866 | ip6_address_t _a, *a = &_a; |
| 2867 | |
| 2868 | if (unformat (input, "%U", unformat_ethernet_address, mac)) |
| 2869 | { |
| 2870 | ip6_link_local_address_from_ethernet_mac_address (a, mac); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2871 | vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2872 | ip6_ethernet_mac_address_from_link_local_address (mac, a); |
| 2873 | vlib_cli_output (vm, "Original MAC address: %U", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2874 | format_ethernet_address, mac); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2875 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2876 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2877 | return 0; |
| 2878 | } |
| 2879 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 2880 | /*? |
| 2881 | * This command converts the given MAC Address into an IPv6 link-local |
| 2882 | * address. |
| 2883 | * |
| 2884 | * @cliexpar |
| 2885 | * Example of how to create an IPv6 link-local address: |
| 2886 | * @cliexstart{test ip6 link 16:d9:e0:91:79:86} |
| 2887 | * Link local address: fe80::14d9:e0ff:fe91:7986 |
| 2888 | * Original MAC address: 16:d9:e0:91:79:86 |
| 2889 | * @cliexend |
| 2890 | ?*/ |
| 2891 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2892 | VLIB_CLI_COMMAND (test_link_command, static) = |
| 2893 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2894 | .path = "test ip6 link", |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2895 | .function = test_ip6_link_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2896 | .short_help = "test ip6 link <mac-address>", |
| 2897 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 2898 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2899 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2900 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2901 | int |
| 2902 | vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2903 | { |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 2904 | u32 fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2905 | |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 2906 | fib_index = fib_table_find (FIB_PROTOCOL_IP6, table_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2907 | |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 2908 | if (~0 == fib_index) |
| 2909 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 2910 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2911 | fib_table_set_flow_hash_config (fib_index, FIB_PROTOCOL_IP6, |
| 2912 | flow_hash_config); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2913 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2914 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2915 | } |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 2916 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2917 | |
| 2918 | static clib_error_t * |
| 2919 | set_ip6_flow_hash_command_fn (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2920 | unformat_input_t * input, |
| 2921 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2922 | { |
| 2923 | int matched = 0; |
| 2924 | u32 table_id = 0; |
| 2925 | u32 flow_hash_config = 0; |
| 2926 | int rv; |
| 2927 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2928 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 2929 | { |
| 2930 | if (unformat (input, "table %d", &table_id)) |
| 2931 | matched = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2932 | #define _(a,v) \ |
| 2933 | else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;} |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2934 | foreach_flow_hash_bit |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2935 | #undef _ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2936 | else |
| 2937 | break; |
| 2938 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2939 | |
| 2940 | if (matched == 0) |
| 2941 | return clib_error_return (0, "unknown input `%U'", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2942 | format_unformat_error, input); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2943 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2944 | rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config); |
| 2945 | switch (rv) |
| 2946 | { |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2947 | case 0: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2948 | break; |
| 2949 | |
| 2950 | case -1: |
| 2951 | return clib_error_return (0, "no such FIB table %d", table_id); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2952 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2953 | default: |
| 2954 | clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config); |
| 2955 | break; |
| 2956 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2957 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2958 | return 0; |
| 2959 | } |
| 2960 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 2961 | /*? |
| 2962 | * Configure the set of IPv6 fields used by the flow hash. |
| 2963 | * |
| 2964 | * @cliexpar |
| 2965 | * @parblock |
| 2966 | * Example of how to set the flow hash on a given table: |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 2967 | * @cliexcmd{set ip6 flow-hash table 8 dst sport dport proto} |
| 2968 | * |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 2969 | * Example of display the configured flow hash: |
| 2970 | * @cliexstart{show ip6 fib} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 2971 | * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
| 2972 | * @::/0 |
| 2973 | * unicast-ip6-chain |
| 2974 | * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]] |
| 2975 | * [0] [@0]: dpo-drop ip6 |
| 2976 | * fe80::/10 |
| 2977 | * unicast-ip6-chain |
| 2978 | * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]] |
| 2979 | * [0] [@2]: dpo-receive |
| 2980 | * ff02::1/128 |
| 2981 | * unicast-ip6-chain |
| 2982 | * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]] |
| 2983 | * [0] [@2]: dpo-receive |
| 2984 | * ff02::2/128 |
| 2985 | * unicast-ip6-chain |
| 2986 | * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]] |
| 2987 | * [0] [@2]: dpo-receive |
| 2988 | * ff02::16/128 |
| 2989 | * unicast-ip6-chain |
| 2990 | * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]] |
| 2991 | * [0] [@2]: dpo-receive |
| 2992 | * ff02::1:ff00:0/104 |
| 2993 | * unicast-ip6-chain |
| 2994 | * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]] |
| 2995 | * [0] [@2]: dpo-receive |
| 2996 | * ipv6-VRF:8, fib_index 1, flow hash: dst sport dport proto |
| 2997 | * @::/0 |
| 2998 | * unicast-ip6-chain |
| 2999 | * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]] |
| 3000 | * [0] [@0]: dpo-drop ip6 |
| 3001 | * @::a:1:1:0:4/126 |
| 3002 | * unicast-ip6-chain |
| 3003 | * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]] |
| 3004 | * [0] [@4]: ipv6-glean: af_packet0 |
| 3005 | * @::a:1:1:0:7/128 |
| 3006 | * unicast-ip6-chain |
| 3007 | * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]] |
| 3008 | * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0 |
| 3009 | * fe80::/10 |
| 3010 | * unicast-ip6-chain |
| 3011 | * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]] |
| 3012 | * [0] [@2]: dpo-receive |
| 3013 | * fe80::fe:3eff:fe3e:9222/128 |
| 3014 | * unicast-ip6-chain |
| 3015 | * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]] |
| 3016 | * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0 |
| 3017 | * ff02::1/128 |
| 3018 | * unicast-ip6-chain |
| 3019 | * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]] |
| 3020 | * [0] [@2]: dpo-receive |
| 3021 | * ff02::2/128 |
| 3022 | * unicast-ip6-chain |
| 3023 | * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]] |
| 3024 | * [0] [@2]: dpo-receive |
| 3025 | * ff02::16/128 |
| 3026 | * unicast-ip6-chain |
| 3027 | * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]] |
| 3028 | * [0] [@2]: dpo-receive |
| 3029 | * ff02::1:ff00:0/104 |
| 3030 | * unicast-ip6-chain |
| 3031 | * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]] |
| 3032 | * [0] [@2]: dpo-receive |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3033 | * @cliexend |
| 3034 | * @endparblock |
| 3035 | ?*/ |
| 3036 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3037 | VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) = |
| 3038 | { |
| 3039 | .path = "set ip6 flow-hash", |
| 3040 | .short_help = |
| 3041 | "set ip6 flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]", |
| 3042 | .function = set_ip6_flow_hash_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3043 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3044 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3045 | |
| 3046 | static clib_error_t * |
| 3047 | show_ip6_local_command_fn (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3048 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3049 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3050 | ip6_main_t *im = &ip6_main; |
| 3051 | ip_lookup_main_t *lm = &im->lookup_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3052 | int i; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3053 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3054 | vlib_cli_output (vm, "Protocols handled by ip6_local"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3055 | for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3056 | { |
| 3057 | if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT) |
Pierre Pfister | 1bfd372 | 2017-09-18 11:40:32 +0200 | [diff] [blame] | 3058 | { |
| 3059 | |
| 3060 | u32 node_index = vlib_get_node (vm, |
| 3061 | ip6_local_node.index)-> |
| 3062 | next_nodes[lm->local_next_by_ip_protocol[i]]; |
| 3063 | vlib_cli_output (vm, "%d: %U", i, format_vlib_node_name, vm, |
| 3064 | node_index); |
| 3065 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3066 | } |
| 3067 | return 0; |
| 3068 | } |
| 3069 | |
| 3070 | |
| 3071 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3072 | /*? |
| 3073 | * Display the set of protocols handled by the local IPv6 stack. |
| 3074 | * |
| 3075 | * @cliexpar |
| 3076 | * Example of how to display local protocol table: |
| 3077 | * @cliexstart{show ip6 local} |
| 3078 | * Protocols handled by ip6_local |
| 3079 | * 17 |
| 3080 | * 43 |
| 3081 | * 58 |
| 3082 | * 115 |
| 3083 | * @cliexend |
| 3084 | ?*/ |
| 3085 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3086 | VLIB_CLI_COMMAND (show_ip6_local, static) = |
| 3087 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3088 | .path = "show ip6 local", |
| 3089 | .function = show_ip6_local_command_fn, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3090 | .short_help = "show ip6 local", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3091 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3092 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3093 | |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 3094 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3095 | int |
| 3096 | vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index, |
| 3097 | u32 table_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3098 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3099 | vnet_main_t *vnm = vnet_get_main (); |
| 3100 | vnet_interface_main_t *im = &vnm->interface_main; |
| 3101 | ip6_main_t *ipm = &ip6_main; |
| 3102 | ip_lookup_main_t *lm = &ipm->lookup_main; |
| 3103 | vnet_classify_main_t *cm = &vnet_classify_main; |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3104 | ip6_address_t *if_addr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3105 | |
| 3106 | if (pool_is_free_index (im->sw_interfaces, sw_if_index)) |
| 3107 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 3108 | |
| 3109 | if (table_index != ~0 && pool_is_free_index (cm->tables, table_index)) |
| 3110 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 3111 | |
| 3112 | vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3113 | lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3114 | |
Neale Ranns | 6cfc39c | 2017-02-14 01:44:25 -0800 | [diff] [blame] | 3115 | if_addr = ip6_interface_first_address (ipm, sw_if_index); |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3116 | |
| 3117 | if (NULL != if_addr) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3118 | { |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3119 | fib_prefix_t pfx = { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3120 | .fp_len = 128, |
| 3121 | .fp_proto = FIB_PROTOCOL_IP6, |
| 3122 | .fp_addr.ip6 = *if_addr, |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3123 | }; |
| 3124 | u32 fib_index; |
| 3125 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3126 | fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, |
| 3127 | sw_if_index); |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3128 | |
| 3129 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3130 | if (table_index != (u32) ~ 0) |
| 3131 | { |
| 3132 | dpo_id_t dpo = DPO_INVALID; |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3133 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3134 | dpo_set (&dpo, |
| 3135 | DPO_CLASSIFY, |
| 3136 | DPO_PROTO_IP6, |
| 3137 | classify_dpo_create (DPO_PROTO_IP6, table_index)); |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3138 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3139 | fib_table_entry_special_dpo_add (fib_index, |
| 3140 | &pfx, |
| 3141 | FIB_SOURCE_CLASSIFY, |
| 3142 | FIB_ENTRY_FLAG_NONE, &dpo); |
| 3143 | dpo_reset (&dpo); |
| 3144 | } |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3145 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3146 | { |
| 3147 | fib_table_entry_special_remove (fib_index, |
| 3148 | &pfx, FIB_SOURCE_CLASSIFY); |
| 3149 | } |
| 3150 | } |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3151 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3152 | return 0; |
| 3153 | } |
Damjan Marion | 3817350 | 2019-02-13 19:30:09 +0100 | [diff] [blame] | 3154 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3155 | |
| 3156 | static clib_error_t * |
| 3157 | set_ip6_classify_command_fn (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3158 | unformat_input_t * input, |
| 3159 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3160 | { |
| 3161 | u32 table_index = ~0; |
| 3162 | int table_index_set = 0; |
| 3163 | u32 sw_if_index = ~0; |
| 3164 | int rv; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3165 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3166 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 3167 | { |
| 3168 | if (unformat (input, "table-index %d", &table_index)) |
| 3169 | table_index_set = 1; |
| 3170 | else if (unformat (input, "intfc %U", unformat_vnet_sw_interface, |
| 3171 | vnet_get_main (), &sw_if_index)) |
| 3172 | ; |
| 3173 | else |
| 3174 | break; |
| 3175 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3176 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3177 | if (table_index_set == 0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3178 | return clib_error_return (0, "classify table-index must be specified"); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3179 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3180 | if (sw_if_index == ~0) |
| 3181 | return clib_error_return (0, "interface / subif must be specified"); |
| 3182 | |
| 3183 | rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index); |
| 3184 | |
| 3185 | switch (rv) |
| 3186 | { |
| 3187 | case 0: |
| 3188 | break; |
| 3189 | |
| 3190 | case VNET_API_ERROR_NO_MATCHING_INTERFACE: |
| 3191 | return clib_error_return (0, "No such interface"); |
| 3192 | |
| 3193 | case VNET_API_ERROR_NO_SUCH_ENTRY: |
| 3194 | return clib_error_return (0, "No such classifier table"); |
| 3195 | } |
| 3196 | return 0; |
| 3197 | } |
| 3198 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3199 | /*? |
| 3200 | * Assign a classification table to an interface. The classification |
| 3201 | * table is created using the '<em>classify table</em>' and '<em>classify session</em>' |
| 3202 | * commands. Once the table is create, use this command to filter packets |
| 3203 | * on an interface. |
| 3204 | * |
| 3205 | * @cliexpar |
| 3206 | * Example of how to assign a classification table to an interface: |
| 3207 | * @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1} |
| 3208 | ?*/ |
| 3209 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3210 | VLIB_CLI_COMMAND (set_ip6_classify_command, static) = |
| 3211 | { |
| 3212 | .path = "set ip6 classify", |
| 3213 | .short_help = |
| 3214 | "set ip6 classify intfc <interface> table-index <classify-idx>", |
| 3215 | .function = set_ip6_classify_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3216 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3217 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3218 | |
| 3219 | static clib_error_t * |
| 3220 | ip6_config (vlib_main_t * vm, unformat_input_t * input) |
| 3221 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3222 | ip6_main_t *im = &ip6_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3223 | uword heapsize = 0; |
| 3224 | u32 tmp; |
| 3225 | u32 nbuckets = 0; |
| 3226 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3227 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 3228 | { |
| 3229 | if (unformat (input, "hash-buckets %d", &tmp)) |
| 3230 | nbuckets = tmp; |
Neale Ranns | 1ec3652 | 2017-11-29 05:20:37 -0800 | [diff] [blame] | 3231 | else if (unformat (input, "heap-size %U", |
| 3232 | unformat_memory_size, &heapsize)) |
| 3233 | ; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3234 | else |
| 3235 | return clib_error_return (0, "unknown input '%U'", |
| 3236 | format_unformat_error, input); |
| 3237 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3238 | |
| 3239 | im->lookup_table_nbuckets = nbuckets; |
| 3240 | im->lookup_table_size = heapsize; |
| 3241 | |
| 3242 | return 0; |
| 3243 | } |
| 3244 | |
| 3245 | VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3246 | |
| 3247 | /* |
| 3248 | * fd.io coding-style-patch-verification: ON |
| 3249 | * |
| 3250 | * Local Variables: |
| 3251 | * eval: (c-set-style "gnu") |
| 3252 | * End: |
| 3253 | */ |