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