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