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