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