blob: 31adc90ecab901ab44b32c3f70468fdcca90bb40 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
AkshayaNadahallied4a2fd2016-08-09 13:38:04 +05302 * Copyright (c) 2016 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 * 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 Troan313f7e22018-04-10 16:02:51 +020042#include <vnet/ip/ip_frag.h>
Neale Rannscbe25aa2019-09-30 10:53:31 +000043#include <vnet/ip/ip6_link.h>
Dave Barachd7cb1b52016-12-09 09:52:16 -050044#include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
Ed Warnickecb9cada2015-12-08 15:45:58 -070045#include <vnet/srp/srp.h> /* for srp_hw_interface_class */
46#include <vppinfra/cache.h>
AkshayaNadahalli0f438df2017-02-10 10:54:16 +053047#include <vnet/fib/fib_urpf_list.h> /* for FIB uRPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +010048#include <vnet/fib/ip6_fib.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000049#include <vnet/mfib/ip6_mfib.h>
Neale Rannsf12a83f2017-04-18 09:09:40 -070050#include <vnet/dpo/load_balance_map.h>
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +020051#include <vnet/dpo/receive_dpo.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010052#include <vnet/dpo/classify_dpo.h>
Neale Rannsba4a5bf2020-01-09 06:43:14 +000053#include <vnet/classify/vnet_classify.h>
Maxime Peim0e3fcc02024-04-04 11:09:26 +020054#include <vnet/adj/adj_dp.h>
Neale Ranns68d48d92021-06-03 14:59:47 +000055#include <vnet/pg/pg.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070056
Damjan Marion38173502019-02-13 19:30:09 +010057#ifndef CLIB_MARCH_VARIANT
Ed Warnickecb9cada2015-12-08 15:45:58 -070058#include <vppinfra/bihash_template.c>
Damjan Marion38173502019-02-13 19:30:09 +010059#endif
Vijayabhaskar Katamreddyacbde662018-01-23 13:39:40 -080060#include <vnet/ip/ip6_forward.h>
Neale Ranns25edf142019-03-22 08:12:48 +000061#include <vnet/interface_output.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070062
AkshayaNadahallifdd81af2016-12-01 16:33:51 +053063/* Flag used by IOAM code. Classifier sets it pop-hop-by-hop checks it */
64#define OI_DECAP 0x80000000
65
Ed Warnickecb9cada2015-12-08 15:45:58 -070066static void
Matthew Smith6c92f5b2019-08-07 11:46:30 -050067ip6_add_interface_prefix_routes (ip6_main_t * im,
68 u32 sw_if_index,
69 u32 fib_index,
70 ip6_address_t * address, u32 address_length)
71{
72 ip_lookup_main_t *lm = &im->lookup_main;
73 ip_interface_prefix_t *if_prefix;
74
75 ip_interface_prefix_key_t key = {
76 .prefix = {
Neale Ranns1ff3c152019-10-07 22:40:54 -070077 .fp_len = address_length,
78 .fp_proto = FIB_PROTOCOL_IP6,
79 .fp_addr.ip6 = {
80 .as_u64 = {
81 address->as_u64[0] & im->fib_masks[address_length].as_u64[0],
82 address->as_u64[1] & im->fib_masks[address_length].as_u64[1],
83 },
84 },
85 },
Matthew Smith6c92f5b2019-08-07 11:46:30 -050086 .sw_if_index = sw_if_index,
87 };
88
89 /* If prefix already set on interface, just increment ref count & return */
90 if_prefix = ip_get_interface_prefix (lm, &key);
91 if (if_prefix)
92 {
93 if_prefix->ref_count += 1;
94 return;
95 }
96
97 /* New prefix - allocate a pool entry, initialize it, add to the hash */
98 pool_get (lm->if_prefix_pool, if_prefix);
99 if_prefix->ref_count = 1;
100 clib_memcpy (&if_prefix->key, &key, sizeof (key));
101 mhash_set (&lm->prefix_to_if_prefix_index, &key,
102 if_prefix - lm->if_prefix_pool, 0 /* old value */ );
103
104 /* length < 128 - add glean */
105 if (address_length < 128)
106 {
107 /* set the glean route for the prefix */
108 fib_table_entry_update_one_path (fib_index, &key.prefix,
109 FIB_SOURCE_INTERFACE,
110 (FIB_ENTRY_FLAG_CONNECTED |
111 FIB_ENTRY_FLAG_ATTACHED),
112 DPO_PROTO_IP6,
113 /* No next-hop address */
114 NULL, sw_if_index,
115 /* invalid FIB index */
116 ~0, 1,
117 /* no out-label stack */
118 NULL, FIB_ROUTE_PATH_FLAG_NONE);
119 }
120}
121
122static void
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index,
124 ip6_main_t * im, u32 fib_index,
125 ip_interface_address_t * a)
126{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500127 ip_lookup_main_t *lm = &im->lookup_main;
128 ip6_address_t *address = ip_interface_address_get_address (lm, a);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100129 fib_prefix_t pfx = {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500130 .fp_len = a->address_length,
131 .fp_proto = FIB_PROTOCOL_IP6,
132 .fp_addr.ip6 = *address,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100133 };
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500135 /* set special routes for the prefix if needed */
136 ip6_add_interface_prefix_routes (im, sw_if_index, fib_index,
137 address, a->address_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100139 pfx.fp_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140 if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500141 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100142 u32 classify_table_index =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500143 lm->classify_table_index_by_sw_if_index[sw_if_index];
144 if (classify_table_index != (u32) ~ 0)
145 {
146 dpo_id_t dpo = DPO_INVALID;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100147
Dave Barachd7cb1b52016-12-09 09:52:16 -0500148 dpo_set (&dpo,
149 DPO_CLASSIFY,
150 DPO_PROTO_IP6,
151 classify_dpo_create (DPO_PROTO_IP6, classify_table_index));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100152
Dave Barachd7cb1b52016-12-09 09:52:16 -0500153 fib_table_entry_special_dpo_add (fib_index,
154 &pfx,
155 FIB_SOURCE_CLASSIFY,
156 FIB_ENTRY_FLAG_NONE, &dpo);
157 dpo_reset (&dpo);
158 }
159 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100160
Neale Rannsf12a83f2017-04-18 09:09:40 -0700161 fib_table_entry_update_one_path (fib_index, &pfx,
162 FIB_SOURCE_INTERFACE,
163 (FIB_ENTRY_FLAG_CONNECTED |
164 FIB_ENTRY_FLAG_LOCAL),
Neale Rannsda78f952017-05-24 09:15:43 -0700165 DPO_PROTO_IP6,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700166 &pfx.fp_addr,
167 sw_if_index, ~0,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500168 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700169}
170
171static void
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500172ip6_del_interface_prefix_routes (ip6_main_t * im,
173 u32 sw_if_index,
174 u32 fib_index,
175 ip6_address_t * address, u32 address_length)
176{
177 ip_lookup_main_t *lm = &im->lookup_main;
178 ip_interface_prefix_t *if_prefix;
179
180 ip_interface_prefix_key_t key = {
181 .prefix = {
Neale Ranns1ff3c152019-10-07 22:40:54 -0700182 .fp_len = address_length,
183 .fp_proto = FIB_PROTOCOL_IP6,
184 .fp_addr.ip6 = {
185 .as_u64 = {
186 address->as_u64[0] & im->fib_masks[address_length].as_u64[0],
187 address->as_u64[1] & im->fib_masks[address_length].as_u64[1],
188 },
189 },
190 },
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500191 .sw_if_index = sw_if_index,
192 };
193
194 if_prefix = ip_get_interface_prefix (lm, &key);
195 if (!if_prefix)
196 {
197 clib_warning ("Prefix not found while deleting %U",
Vladislav Grishenko2921e022022-05-16 01:58:53 +0500198 format_ip6_address_and_length, address, address_length);
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500199 return;
200 }
201
202 /* If not deleting last intf addr in prefix, decrement ref count & return */
203 if_prefix->ref_count -= 1;
204 if (if_prefix->ref_count > 0)
205 return;
206
Neale Ranns1ff3c152019-10-07 22:40:54 -0700207 /* length <= 128, delete glean route */
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500208 if (address_length <= 128)
209 {
210 /* remove glean route for prefix */
211 fib_table_entry_delete (fib_index, &key.prefix, FIB_SOURCE_INTERFACE);
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500212 }
213
214 mhash_unset (&lm->prefix_to_if_prefix_index, &key, 0 /* old_value */ );
215 pool_put (lm->if_prefix_pool, if_prefix);
216}
217
218static void
219ip6_del_interface_routes (u32 sw_if_index, ip6_main_t * im,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100220 u32 fib_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500221 ip6_address_t * address, u32 address_length)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700222{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500223 fib_prefix_t pfx = {
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500224 .fp_len = 128,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500225 .fp_proto = FIB_PROTOCOL_IP6,
226 .fp_addr.ip6 = *address,
227 };
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500229 /* delete special routes for the prefix if needed */
230 ip6_del_interface_prefix_routes (im, sw_if_index, fib_index,
231 address, address_length);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100232
Dave Barachd7cb1b52016-12-09 09:52:16 -0500233 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700234}
235
Damjan Marion38173502019-02-13 19:30:09 +0100236#ifndef CLIB_MARCH_VARIANT
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100237void
Dave Barachd7cb1b52016-12-09 09:52:16 -0500238ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100239{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500240 ip6_main_t *im = &ip6_main;
John Lo4a302ee2020-05-12 22:34:39 -0400241 vnet_main_t *vnm = vnet_get_main ();
242 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700243
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100244 vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700245
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100246 /*
247 * enable/disable only on the 1<->0 transition
248 */
249 if (is_enable)
250 {
251 if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index])
Dave Barachd7cb1b52016-12-09 09:52:16 -0500252 return;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100253 }
254 else
255 {
Neale Ranns75152282017-01-09 01:00:45 -0800256 /* The ref count is 0 when an address is removed from an interface that has
257 * no address - this is not a ciritical error */
258 if (0 == im->ip_enabled_by_sw_if_index[sw_if_index] ||
259 0 != --im->ip_enabled_by_sw_if_index[sw_if_index])
Dave Barachd7cb1b52016-12-09 09:52:16 -0500260 return;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100261 }
262
Neale Ranns8269d3d2018-01-30 09:02:20 -0800263 vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
Neale Ranns630198f2017-05-22 09:20:20 -0400264 !is_enable, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100265
Neale Ranns8269d3d2018-01-30 09:02:20 -0800266 vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
267 sw_if_index, !is_enable, 0, 0);
John Lo4a302ee2020-05-12 22:34:39 -0400268
269 if (is_enable)
270 hi->l3_if_count++;
271 else if (hi->l3_if_count)
272 hi->l3_if_count--;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100273}
274
Neale Rannsdf089a82016-10-02 16:39:06 +0100275/* get first interface address */
276ip6_address_t *
Neale Ranns6cfc39c2017-02-14 01:44:25 -0800277ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
Neale Rannsdf089a82016-10-02 16:39:06 +0100278{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500279 ip_lookup_main_t *lm = &im->lookup_main;
280 ip_interface_address_t *ia = 0;
281 ip6_address_t *result = 0;
Neale Rannsdf089a82016-10-02 16:39:06 +0100282
283 foreach_ip_interface_address (lm, ia, sw_if_index,
284 1 /* honor unnumbered */,
285 ({
286 ip6_address_t * a = ip_interface_address_get_address (lm, ia);
287 result = a;
288 break;
289 }));
Neale Rannsdf089a82016-10-02 16:39:06 +0100290 return result;
291}
292
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100293clib_error_t *
294ip6_add_del_interface_address (vlib_main_t * vm,
295 u32 sw_if_index,
296 ip6_address_t * address,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500297 u32 address_length, u32 is_del)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700298{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500299 vnet_main_t *vnm = vnet_get_main ();
300 ip6_main_t *im = &ip6_main;
301 ip_lookup_main_t *lm = &im->lookup_main;
Neale Ranns59f71132020-04-08 12:19:38 +0000302 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700303 u32 if_address_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500304 ip6_address_fib_t ip6_af, *addr_fib = 0;
Neale Rannscbe25aa2019-09-30 10:53:31 +0000305 const ip6_address_t *ll_addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700306
Pim van Pelt76b19ce2021-08-10 23:44:44 +0200307 error = vnet_sw_interface_supports_addressing (vnm, sw_if_index);
308 if (error)
Matthew Smith1b6c7932021-09-24 15:27:36 -0500309 {
310 vnm->api_errno = VNET_API_ERROR_UNSUPPORTED;
311 return error;
312 }
Pavel Kotucek57808982017-08-02 08:20:19 +0200313
Juraj Sloboda5bb1eca2018-10-22 09:57:13 +0200314 if (ip6_address_is_link_local_unicast (address))
315 {
316 if (address_length != 128)
317 {
318 vnm->api_errno = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
319 return
320 clib_error_create
321 ("prefix length of link-local address must be 128");
322 }
323 if (!is_del)
324 {
Neale Rannscbe25aa2019-09-30 10:53:31 +0000325 int rv;
326
Neale Rannsec40a7d2020-04-23 07:36:12 +0000327 rv = ip6_link_set_local_address (sw_if_index, address);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000328
329 if (rv)
330 {
331 vnm->api_errno = rv;
332 return clib_error_create ("address not assignable");
333 }
Juraj Sloboda5bb1eca2018-10-22 09:57:13 +0200334 }
335 else
336 {
Neale Rannscbe25aa2019-09-30 10:53:31 +0000337 ll_addr = ip6_get_link_local_address (sw_if_index);
338 if (ip6_address_is_equal (ll_addr, address))
Juraj Sloboda5bb1eca2018-10-22 09:57:13 +0200339 {
340 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_DELETABLE;
341 return clib_error_create ("address not deletable");
342 }
343 else
344 {
345 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
346 return clib_error_create ("address not found");
347 }
348 }
Neale Rannsec40a7d2020-04-23 07:36:12 +0000349
350 return (NULL);
Juraj Sloboda5bb1eca2018-10-22 09:57:13 +0200351 }
352
Ed Warnickecb9cada2015-12-08 15:45:58 -0700353 ip6_addr_fib_init (&ip6_af, address,
354 vec_elt (im->fib_index_by_sw_if_index, sw_if_index));
355 vec_add1 (addr_fib, ip6_af);
356
Neale Ranns744902e2017-08-14 10:35:44 -0700357 if (!is_del)
358 {
359 /* When adding an address check that it does not conflict
360 with an existing address on any interface in this table. */
361 ip_interface_address_t *ia;
362 vnet_sw_interface_t *sif;
363
Damjan Marionb2c31b62020-12-13 21:47:40 +0100364 pool_foreach (sif, vnm->interface_main.sw_interfaces)
365 {
Neale Ranns744902e2017-08-14 10:35:44 -0700366 if (im->fib_index_by_sw_if_index[sw_if_index] ==
367 im->fib_index_by_sw_if_index[sif->sw_if_index])
368 {
369 foreach_ip_interface_address
370 (&im->lookup_main, ia, sif->sw_if_index,
371 0 /* honor unnumbered */ ,
372 ({
373 ip6_address_t * x =
374 ip_interface_address_get_address
375 (&im->lookup_main, ia);
Neale Ranns59f71132020-04-08 12:19:38 +0000376
Neale Ranns744902e2017-08-14 10:35:44 -0700377 if (ip6_destination_matches_route
378 (im, address, x, ia->address_length) ||
379 ip6_destination_matches_route (im,
380 x,
381 address,
382 address_length))
383 {
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500384 /* an intf may have >1 addr from the same prefix */
385 if ((sw_if_index == sif->sw_if_index) &&
386 (ia->address_length == address_length) &&
387 !ip6_address_is_equal (x, address))
388 continue;
389
Neale Ranns59f71132020-04-08 12:19:38 +0000390 if (ia->flags & IP_INTERFACE_ADDRESS_FLAG_STALE)
391 /* if the address we're comparing against is stale
392 * then the CP has not added this one back yet, maybe
393 * it never will, so we have to assume it won't and
394 * ignore it. if it does add it back, then it will fail
395 * because this one is now present */
396 continue;
397
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500398 /* error if the length or intf was different */
Neale Ranns744902e2017-08-14 10:35:44 -0700399 vnm->api_errno = VNET_API_ERROR_DUPLICATE_IF_ADDRESS;
Neale Ranns59f71132020-04-08 12:19:38 +0000400 error = clib_error_create
Neale Ranns744902e2017-08-14 10:35:44 -0700401 ("failed to add %U which conflicts with %U for interface %U",
402 format_ip6_address_and_length, address,
403 address_length,
404 format_ip6_address_and_length, x,
405 ia->address_length,
406 format_vnet_sw_if_index_name, vnm,
407 sif->sw_if_index);
Neale Ranns59f71132020-04-08 12:19:38 +0000408 goto done;
Neale Ranns744902e2017-08-14 10:35:44 -0700409 }
410 }));
411 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100412 }
Neale Ranns744902e2017-08-14 10:35:44 -0700413 }
Neale Ranns744902e2017-08-14 10:35:44 -0700414
Neale Ranns59f71132020-04-08 12:19:38 +0000415 if_address_index = ip_interface_address_find (lm, addr_fib, address_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700416
Neale Ranns59f71132020-04-08 12:19:38 +0000417 if (is_del)
418 {
419 if (~0 == if_address_index)
420 {
421 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
422 error = clib_error_create ("%U not found for interface %U",
423 lm->format_address_and_length,
424 addr_fib, address_length,
425 format_vnet_sw_if_index_name, vnm,
426 sw_if_index);
427 goto done;
428 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700429
yedgdbd366b2020-05-14 10:51:53 +0800430 error = ip_interface_address_del (lm, vnm, if_address_index, addr_fib,
431 address_length, sw_if_index);
432 if (error)
433 goto done;
Neale Ranns59f71132020-04-08 12:19:38 +0000434 }
435 else
436 {
437 if (~0 != if_address_index)
438 {
439 ip_interface_address_t *ia;
440
441 ia = pool_elt_at_index (lm->if_address_pool, if_address_index);
442
443 if (ia->flags & IP_INTERFACE_ADDRESS_FLAG_STALE)
444 {
445 if (ia->sw_if_index == sw_if_index)
446 {
447 /* re-adding an address during the replace action.
448 * consdier this the update. clear the flag and
449 * we're done */
450 ia->flags &= ~IP_INTERFACE_ADDRESS_FLAG_STALE;
451 goto done;
452 }
453 else
454 {
455 /* The prefix is moving from one interface to another.
456 * delete the stale and add the new */
457 ip6_add_del_interface_address (vm,
458 ia->sw_if_index,
459 address, address_length, 1);
460 ia = NULL;
461 error = ip_interface_address_add (lm, sw_if_index,
462 addr_fib, address_length,
463 &if_address_index);
464 }
465 }
466 else
467 {
468 vnm->api_errno = VNET_API_ERROR_DUPLICATE_IF_ADDRESS;
469 error = clib_error_create
470 ("Prefix %U already found on interface %U",
471 lm->format_address_and_length, addr_fib, address_length,
472 format_vnet_sw_if_index_name, vnm, ia->sw_if_index);
473 }
474 }
475 else
476 error = ip_interface_address_add (lm, sw_if_index,
477 addr_fib, address_length,
478 &if_address_index);
479 }
480
481 if (error)
482 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700483
Dave Barachd7cb1b52016-12-09 09:52:16 -0500484 ip6_sw_interface_enable_disable (sw_if_index, !is_del);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000485 if (!is_del)
Neale Rannsec40a7d2020-04-23 07:36:12 +0000486 ip6_link_enable (sw_if_index, NULL);
Neale Ranns177bbdc2016-11-15 09:46:51 +0000487
Neale Ranns1ff3c152019-10-07 22:40:54 -0700488 /* intf addr routes are added/deleted on admin up/down */
489 if (vnet_sw_interface_is_admin_up (vnm, sw_if_index))
490 {
491 if (is_del)
492 ip6_del_interface_routes (sw_if_index,
493 im, ip6_af.fib_index, address,
494 address_length);
495 else
496 ip6_add_interface_routes (vnm, sw_if_index,
497 im, ip6_af.fib_index,
498 pool_elt_at_index (lm->if_address_pool,
499 if_address_index));
500 }
Neale Ranns59f71132020-04-08 12:19:38 +0000501
502 ip6_add_del_interface_address_callback_t *cb;
503 vec_foreach (cb, im->add_del_interface_address_callbacks)
504 cb->function (im, cb->function_opaque, sw_if_index,
505 address, address_length, if_address_index, is_del);
506
Neale Rannscbe25aa2019-09-30 10:53:31 +0000507 if (is_del)
508 ip6_link_disable (sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700509
Dave Barachd7cb1b52016-12-09 09:52:16 -0500510done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700511 vec_free (addr_fib);
512 return error;
513}
514
Damjan Marion38173502019-02-13 19:30:09 +0100515#endif
516
517static clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500518ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700519{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500520 ip6_main_t *im = &ip6_main;
521 ip_interface_address_t *ia;
522 ip6_address_t *a;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700523 u32 is_admin_up, fib_index;
524
Dave Barachd7cb1b52016-12-09 09:52:16 -0500525 vec_validate_init_empty (im->
526 lookup_main.if_address_pool_index_by_sw_if_index,
527 sw_if_index, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700528
529 is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
530
531 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
532
Dave Barach75fc8542016-10-11 16:16:02 -0400533 foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534 0 /* honor unnumbered */,
535 ({
536 a = ip_interface_address_get_address (&im->lookup_main, ia);
537 if (is_admin_up)
538 ip6_add_interface_routes (vnm, sw_if_index,
539 im, fib_index,
540 ia);
541 else
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500542 ip6_del_interface_routes (sw_if_index, im, fib_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700543 a, ia->address_length);
544 }));
545
546 return 0;
547}
548
549VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
550
Dave Barachd6534602016-06-14 18:38:02 -0400551/* Built-in ip6 unicast rx feature path definition */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100552VNET_FEATURE_ARC_INIT (ip6_unicast, static) =
553{
554 .arc_name = "ip6-unicast",
555 .start_nodes = VNET_FEATURES ("ip6-input"),
Dave Baracha25def72018-11-26 11:04:45 -0500556 .last_in_arc = "ip6-lookup",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100557 .arc_index_ptr = &ip6_main.lookup_main.ucast_feature_arc_index,
558};
559
Dave Barachd7cb1b52016-12-09 09:52:16 -0500560VNET_FEATURE_INIT (ip6_flow_classify, static) =
561{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100562 .arc_name = "ip6-unicast",
Juraj Sloboda506b2452016-08-07 23:45:24 -0700563 .node_name = "ip6-flow-classify",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100564 .runs_before = VNET_FEATURES ("ip6-inacl"),
Juraj Sloboda506b2452016-08-07 23:45:24 -0700565};
566
Dave Barachd7cb1b52016-12-09 09:52:16 -0500567VNET_FEATURE_INIT (ip6_inacl, static) =
568{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100569 .arc_name = "ip6-unicast",
Dave Barach75fc8542016-10-11 16:16:02 -0400570 .node_name = "ip6-inacl",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100571 .runs_before = VNET_FEATURES ("ip6-policer-classify"),
Dave Barachd6534602016-06-14 18:38:02 -0400572};
573
Dave Barachd7cb1b52016-12-09 09:52:16 -0500574VNET_FEATURE_INIT (ip6_policer_classify, static) =
575{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100576 .arc_name = "ip6-unicast",
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700577 .node_name = "ip6-policer-classify",
Pierre Pfister057b3562018-12-10 17:01:01 +0100578 .runs_before = VNET_FEATURES ("ipsec6-input-feature"),
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700579};
580
Dave Barachd7cb1b52016-12-09 09:52:16 -0500581VNET_FEATURE_INIT (ip6_ipsec, static) =
582{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100583 .arc_name = "ip6-unicast",
Pierre Pfister057b3562018-12-10 17:01:01 +0100584 .node_name = "ipsec6-input-feature",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100585 .runs_before = VNET_FEATURES ("l2tp-decap"),
Dave Barachd6534602016-06-14 18:38:02 -0400586};
587
Dave Barachd7cb1b52016-12-09 09:52:16 -0500588VNET_FEATURE_INIT (ip6_l2tp, static) =
589{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100590 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400591 .node_name = "l2tp-decap",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100592 .runs_before = VNET_FEATURES ("vpath-input-ip6"),
Dave Barachd6534602016-06-14 18:38:02 -0400593};
594
Dave Barachd7cb1b52016-12-09 09:52:16 -0500595VNET_FEATURE_INIT (ip6_vpath, static) =
596{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100597 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400598 .node_name = "vpath-input-ip6",
John Lo2b81eb82017-01-30 13:12:10 -0500599 .runs_before = VNET_FEATURES ("ip6-vxlan-bypass"),
600};
601
602VNET_FEATURE_INIT (ip6_vxlan_bypass, static) =
603{
604 .arc_name = "ip6-unicast",
605 .node_name = "ip6-vxlan-bypass",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100606 .runs_before = VNET_FEATURES ("ip6-lookup"),
Dave Barachd6534602016-06-14 18:38:02 -0400607};
608
Neale Ranns8269d3d2018-01-30 09:02:20 -0800609VNET_FEATURE_INIT (ip6_not_enabled, static) =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500610{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100611 .arc_name = "ip6-unicast",
Neale Ranns8269d3d2018-01-30 09:02:20 -0800612 .node_name = "ip6-not-enabled",
Neale Ranns630198f2017-05-22 09:20:20 -0400613 .runs_before = VNET_FEATURES ("ip6-lookup"),
614};
615
616VNET_FEATURE_INIT (ip6_lookup, static) =
617{
618 .arc_name = "ip6-unicast",
619 .node_name = "ip6-lookup",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100620 .runs_before = 0, /*last feature*/
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100621};
622
Dave Barachd6534602016-06-14 18:38:02 -0400623/* Built-in ip6 multicast rx feature path definition (none now) */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100624VNET_FEATURE_ARC_INIT (ip6_multicast, static) =
625{
626 .arc_name = "ip6-multicast",
627 .start_nodes = VNET_FEATURES ("ip6-input"),
Dave Baracha25def72018-11-26 11:04:45 -0500628 .last_in_arc = "ip6-mfib-forward-lookup",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100629 .arc_index_ptr = &ip6_main.lookup_main.mcast_feature_arc_index,
630};
631
632VNET_FEATURE_INIT (ip6_vpath_mc, static) = {
633 .arc_name = "ip6-multicast",
Dave Barachd6534602016-06-14 18:38:02 -0400634 .node_name = "vpath-input-ip6",
Neale Ranns32e1c012016-11-22 17:07:28 +0000635 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
Dave Barachd6534602016-06-14 18:38:02 -0400636};
637
Neale Ranns8269d3d2018-01-30 09:02:20 -0800638VNET_FEATURE_INIT (ip6_not_enabled_mc, static) = {
Damjan Marion8b3191e2016-11-09 19:54:20 +0100639 .arc_name = "ip6-multicast",
Neale Ranns8269d3d2018-01-30 09:02:20 -0800640 .node_name = "ip6-not-enabled",
Neale Ranns630198f2017-05-22 09:20:20 -0400641 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
642};
643
644VNET_FEATURE_INIT (ip6_mc_lookup, static) = {
645 .arc_name = "ip6-multicast",
646 .node_name = "ip6-mfib-forward-lookup",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100647 .runs_before = 0, /* last feature */
Neale Ranns5e575b12016-10-03 09:40:25 +0100648};
Dave Barach5331c722016-08-17 11:54:30 -0400649
650/* Built-in ip4 tx feature path definition */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100651VNET_FEATURE_ARC_INIT (ip6_output, static) =
652{
653 .arc_name = "ip6-output",
Neale Rannsf068c3e2018-01-03 04:18:48 -0800654 .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain", "ip6-dvr-dpo"),
Dave Baracha25def72018-11-26 11:04:45 -0500655 .last_in_arc = "interface-output",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100656 .arc_index_ptr = &ip6_main.lookup_main.output_feature_arc_index,
Dave Barach5331c722016-08-17 11:54:30 -0400657};
658
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100659VNET_FEATURE_INIT (ip6_outacl, static) = {
660 .arc_name = "ip6-output",
661 .node_name = "ip6-outacl",
Pierre Pfister057b3562018-12-10 17:01:01 +0100662 .runs_before = VNET_FEATURES ("ipsec6-output-feature"),
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100663};
664
Matus Fabian08a6f012016-11-15 06:08:51 -0800665VNET_FEATURE_INIT (ip6_ipsec_output, static) = {
666 .arc_name = "ip6-output",
Pierre Pfister057b3562018-12-10 17:01:01 +0100667 .node_name = "ipsec6-output-feature",
Matus Fabian08a6f012016-11-15 06:08:51 -0800668 .runs_before = VNET_FEATURES ("interface-output"),
669};
670
Damjan Marion8b3191e2016-11-09 19:54:20 +0100671VNET_FEATURE_INIT (ip6_interface_output, static) = {
672 .arc_name = "ip6-output",
673 .node_name = "interface-output",
674 .runs_before = 0, /* not before any other features */
675};
Dave Barachd6534602016-06-14 18:38:02 -0400676
Damjan Marion38173502019-02-13 19:30:09 +0100677static clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500678ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700679{
Florin Corasb5c13fd2017-05-10 12:32:53 -0700680 ip6_main_t *im = &ip6_main;
681
Nathan Skrzypczak7854b462021-08-16 16:13:40 +0200682 vec_validate_init_empty (im->fib_index_by_sw_if_index, sw_if_index, ~0);
683 vec_validate_init_empty (im->mfib_index_by_sw_if_index, sw_if_index, ~0);
Florin Corasb5c13fd2017-05-10 12:32:53 -0700684
Nathan Skrzypczak7854b462021-08-16 16:13:40 +0200685 if (is_add)
686 {
687 /* Fill in lookup tables with default table (0). */
688 im->fib_index_by_sw_if_index[sw_if_index] = 0;
689 im->mfib_index_by_sw_if_index[sw_if_index] = 0;
690 }
691 else
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +0200692 {
693 /* Ensure that IPv6 is disabled */
694 ip6_main_t *im6 = &ip6_main;
695 ip_lookup_main_t *lm6 = &im6->lookup_main;
696 ip_interface_address_t *ia = 0;
697 ip6_address_t *address;
698 vlib_main_t *vm = vlib_get_main ();
699
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700700 vnet_sw_interface_update_unnumbered (sw_if_index, ~0, 0);
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700701 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +0200702 ({
703 address = ip_interface_address_get_address (lm6, ia);
704 ip6_add_del_interface_address(vm, sw_if_index, address, ia->address_length, 1);
705 }));
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +0200706 ip6_mfib_interface_enable_disable (sw_if_index, 0);
Nathan Skrzypczaka424dd12021-08-20 15:53:43 +0200707
708 if (0 != im6->fib_index_by_sw_if_index[sw_if_index])
709 fib_table_bind (FIB_PROTOCOL_IP6, sw_if_index, 0);
710 if (0 != im6->mfib_index_by_sw_if_index[sw_if_index])
711 mfib_table_bind (FIB_PROTOCOL_IP6, sw_if_index, 0);
712
713 /* Erase the lookup tables just in case */
714 im6->fib_index_by_sw_if_index[sw_if_index] = ~0;
715 im6->mfib_index_by_sw_if_index[sw_if_index] = ~0;
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +0200716 }
717
Neale Ranns8269d3d2018-01-30 09:02:20 -0800718 vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
Damjan Marion8b3191e2016-11-09 19:54:20 +0100719 is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700720
Neale Ranns8269d3d2018-01-30 09:02:20 -0800721 vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
722 sw_if_index, is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700723
Ed Warnickecb9cada2015-12-08 15:45:58 -0700724 return /* no error */ 0;
725}
726
727VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del);
728
Damjan Marion38173502019-02-13 19:30:09 +0100729VLIB_NODE_FN (ip6_lookup_node) (vlib_main_t * vm,
730 vlib_node_runtime_t * node,
731 vlib_frame_t * frame)
Damjan Marionaca64c92016-04-13 09:48:56 +0200732{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100733 return ip6_lookup_inline (vm, node, frame);
Damjan Marionaca64c92016-04-13 09:48:56 +0200734}
735
Dave Barachd7cb1b52016-12-09 09:52:16 -0500736static u8 *format_ip6_lookup_trace (u8 * s, va_list * args);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100737
Dave Barachd7cb1b52016-12-09 09:52:16 -0500738VLIB_REGISTER_NODE (ip6_lookup_node) =
739{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700740 .name = "ip6-lookup",
741 .vector_size = sizeof (u32),
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100742 .format_trace = format_ip6_lookup_trace,
Ole Troanf0f85222016-06-14 21:12:32 +0200743 .n_next_nodes = IP6_LOOKUP_N_NEXT,
Damjan Marionb2707892016-04-13 11:21:07 +0200744 .next_nodes = IP6_LOOKUP_NEXT_NODES,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700745};
746
Damjan Marion38173502019-02-13 19:30:09 +0100747VLIB_NODE_FN (ip6_load_balance_node) (vlib_main_t * vm,
748 vlib_node_runtime_t * node,
749 vlib_frame_t * frame)
Damjan Marionaca64c92016-04-13 09:48:56 +0200750{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500751 vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters;
Neale Ranns3ce72b22019-05-27 08:21:32 -0400752 u32 n_left, *from;
Damjan Marion067cd622018-07-11 12:47:43 +0200753 u32 thread_index = vm->thread_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500754 ip6_main_t *im = &ip6_main;
Neale Ranns3ce72b22019-05-27 08:21:32 -0400755 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
756 u16 nexts[VLIB_FRAME_SIZE], *next;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100757
758 from = vlib_frame_vector_args (frame);
Neale Ranns3ce72b22019-05-27 08:21:32 -0400759 n_left = frame->n_vectors;
760 next = nexts;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100761
Neale Ranns3ce72b22019-05-27 08:21:32 -0400762 vlib_get_buffers (vm, from, bufs, n_left);
763
764 while (n_left >= 4)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100765 {
Neale Ranns3ce72b22019-05-27 08:21:32 -0400766 const load_balance_t *lb0, *lb1;
767 const ip6_header_t *ip0, *ip1;
768 u32 lbi0, hc0, lbi1, hc1;
769 const dpo_id_t *dpo0, *dpo1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100770
Neale Ranns3ce72b22019-05-27 08:21:32 -0400771 /* Prefetch next iteration. */
772 {
773 vlib_prefetch_buffer_header (b[2], STORE);
774 vlib_prefetch_buffer_header (b[3], STORE);
Dave Barach75fc8542016-10-11 16:16:02 -0400775
Neale Ranns3ce72b22019-05-27 08:21:32 -0400776 CLIB_PREFETCH (b[2]->data, sizeof (ip0[0]), STORE);
777 CLIB_PREFETCH (b[3]->data, sizeof (ip0[0]), STORE);
778 }
779
780 ip0 = vlib_buffer_get_current (b[0]);
781 ip1 = vlib_buffer_get_current (b[1]);
782 lbi0 = vnet_buffer (b[0])->ip.adj_index[VLIB_TX];
783 lbi1 = vnet_buffer (b[1])->ip.adj_index[VLIB_TX];
784
785 lb0 = load_balance_get (lbi0);
786 lb1 = load_balance_get (lbi1);
787
788 /*
789 * this node is for via FIBs we can re-use the hash value from the
790 * to node if present.
791 * We don't want to use the same hash value at each level in the recursion
792 * graph as that would lead to polarisation
793 */
794 hc0 = hc1 = 0;
795
796 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500797 {
Neale Ranns3ce72b22019-05-27 08:21:32 -0400798 if (PREDICT_TRUE (vnet_buffer (b[0])->ip.flow_hash))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500799 {
Neale Ranns3ce72b22019-05-27 08:21:32 -0400800 hc0 = vnet_buffer (b[0])->ip.flow_hash =
801 vnet_buffer (b[0])->ip.flow_hash >> 1;
Neale Rannsf12a83f2017-04-18 09:09:40 -0700802 }
803 else
804 {
Neale Ranns3ce72b22019-05-27 08:21:32 -0400805 hc0 = vnet_buffer (b[0])->ip.flow_hash =
806 ip6_compute_flow_hash (ip0, lb0->lb_hash_config);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500807 }
Neale Ranns3ce72b22019-05-27 08:21:32 -0400808 dpo0 = load_balance_get_fwd_bucket
809 (lb0, (hc0 & (lb0->lb_n_buckets_minus_1)));
810 }
811 else
812 {
813 dpo0 = load_balance_get_bucket_i (lb0, 0);
814 }
815 if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
816 {
817 if (PREDICT_TRUE (vnet_buffer (b[1])->ip.flow_hash))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500818 {
Neale Ranns3ce72b22019-05-27 08:21:32 -0400819 hc1 = vnet_buffer (b[1])->ip.flow_hash =
820 vnet_buffer (b[1])->ip.flow_hash >> 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500821 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700822 else
823 {
Neale Ranns3ce72b22019-05-27 08:21:32 -0400824 hc1 = vnet_buffer (b[1])->ip.flow_hash =
825 ip6_compute_flow_hash (ip1, lb1->lb_hash_config);
Neale Rannsf12a83f2017-04-18 09:09:40 -0700826 }
Neale Ranns3ce72b22019-05-27 08:21:32 -0400827 dpo1 = load_balance_get_fwd_bucket
828 (lb1, (hc1 & (lb1->lb_n_buckets_minus_1)));
829 }
830 else
831 {
832 dpo1 = load_balance_get_bucket_i (lb1, 0);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500833 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000834
Neale Ranns3ce72b22019-05-27 08:21:32 -0400835 next[0] = dpo0->dpoi_next_node;
836 next[1] = dpo1->dpoi_next_node;
837
838 /* Only process the HBH Option Header if explicitly configured to do so */
839 if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500840 {
Neale Ranns3ce72b22019-05-27 08:21:32 -0400841 next[0] = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
842 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next[0];
843 }
844 /* Only process the HBH Option Header if explicitly configured to do so */
845 if (PREDICT_FALSE (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
846 {
847 next[1] = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
848 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next[1];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500849 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100850
Neale Ranns3ce72b22019-05-27 08:21:32 -0400851 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
852 vnet_buffer (b[1])->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
853
854 vlib_increment_combined_counter
855 (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, b[0]));
856 vlib_increment_combined_counter
857 (cm, thread_index, lbi1, 1, vlib_buffer_length_in_chain (vm, b[1]));
858
859 b += 2;
860 next += 2;
861 n_left -= 2;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100862 }
863
Neale Ranns3ce72b22019-05-27 08:21:32 -0400864 while (n_left > 0)
865 {
866 const load_balance_t *lb0;
867 const ip6_header_t *ip0;
868 const dpo_id_t *dpo0;
869 u32 lbi0, hc0;
870
871 ip0 = vlib_buffer_get_current (b[0]);
872 lbi0 = vnet_buffer (b[0])->ip.adj_index[VLIB_TX];
873
874 lb0 = load_balance_get (lbi0);
875
876 hc0 = 0;
877 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
878 {
879 if (PREDICT_TRUE (vnet_buffer (b[0])->ip.flow_hash))
880 {
881 hc0 = vnet_buffer (b[0])->ip.flow_hash =
882 vnet_buffer (b[0])->ip.flow_hash >> 1;
883 }
884 else
885 {
886 hc0 = vnet_buffer (b[0])->ip.flow_hash =
887 ip6_compute_flow_hash (ip0, lb0->lb_hash_config);
888 }
889 dpo0 = load_balance_get_fwd_bucket
890 (lb0, (hc0 & (lb0->lb_n_buckets_minus_1)));
891 }
892 else
893 {
894 dpo0 = load_balance_get_bucket_i (lb0, 0);
895 }
896
897 next[0] = dpo0->dpoi_next_node;
898 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
899
900 /* Only process the HBH Option Header if explicitly configured to do so */
901 if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
902 {
903 next[0] = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
904 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next[0];
905 }
906
907 vlib_increment_combined_counter
908 (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, b[0]));
909
910 b += 1;
911 next += 1;
912 n_left -= 1;
913 }
914
915 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
916
Neale Rannsa71844f2018-11-08 07:31:36 -0800917 if (node->flags & VLIB_NODE_FLAG_TRACE)
918 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
919
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100920 return frame->n_vectors;
Damjan Marionaca64c92016-04-13 09:48:56 +0200921}
922
Dave Barachd7cb1b52016-12-09 09:52:16 -0500923VLIB_REGISTER_NODE (ip6_load_balance_node) =
924{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100925 .name = "ip6-load-balance",
Damjan Marionaca64c92016-04-13 09:48:56 +0200926 .vector_size = sizeof (u32),
Ole Troanf0f85222016-06-14 21:12:32 +0200927 .sibling_of = "ip6-lookup",
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100928 .format_trace = format_ip6_lookup_trace,
Damjan Marionaca64c92016-04-13 09:48:56 +0200929};
930
Dave Barachd7cb1b52016-12-09 09:52:16 -0500931typedef struct
932{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700933 /* Adjacency taken. */
934 u32 adj_index;
935 u32 flow_hash;
John Lo2d343742016-01-19 17:27:17 -0500936 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700937
938 /* Packet data, possibly *after* rewrite. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500939 u8 packet_data[128 - 1 * sizeof (u32)];
940}
941ip6_forward_next_trace_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700942
Damjan Marion38173502019-02-13 19:30:09 +0100943#ifndef CLIB_MARCH_VARIANT
John Lo2b81eb82017-01-30 13:12:10 -0500944u8 *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500945format_ip6_forward_next_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700946{
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100947 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
948 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500949 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200950 u32 indent = format_get_indent (s);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100951
Vladislav Grishenko302db472024-01-24 16:17:23 +0500952 s = format (s, "%Ufib:%d adj:%d flow:0x%08x", format_white_space, indent,
Neale Rannsdc617b82020-08-20 08:22:56 +0000953 t->fib_index, t->adj_index, t->flow_hash);
954 s = format (s, "\n%U%U",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500955 format_white_space, indent,
956 format_ip6_header, t->packet_data, sizeof (t->packet_data));
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100957 return s;
958}
Damjan Marion38173502019-02-13 19:30:09 +0100959#endif
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100960
Dave Barachd7cb1b52016-12-09 09:52:16 -0500961static u8 *
962format_ip6_lookup_trace (u8 * s, va_list * args)
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100963{
964 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
965 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500966 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200967 u32 indent = format_get_indent (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968
John Loac8146c2016-09-27 17:44:02 -0400969 s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500970 t->fib_index, t->adj_index, t->flow_hash);
971 s = format (s, "\n%U%U",
972 format_white_space, indent,
973 format_ip6_header, t->packet_data, sizeof (t->packet_data));
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100974 return s;
975}
Pierre Pfister0febaf12016-06-08 12:23:21 +0100976
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977
Dave Barachd7cb1b52016-12-09 09:52:16 -0500978static u8 *
979format_ip6_rewrite_trace (u8 * s, va_list * args)
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100980{
981 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
982 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500983 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200984 u32 indent = format_get_indent (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700985
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100986 s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500987 t->fib_index, t->adj_index, format_ip_adjacency,
988 t->adj_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100989 s = format (s, "\n%U%U",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500990 format_white_space, indent,
991 format_ip_adjacency_packet_data,
Neale Ranns0b6a8572019-10-30 17:34:14 +0000992 t->packet_data, sizeof (t->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700993 return s;
994}
995
996/* Common trace function for all ip6-forward next nodes. */
Damjan Marion38173502019-02-13 19:30:09 +0100997#ifndef CLIB_MARCH_VARIANT
Ed Warnickecb9cada2015-12-08 15:45:58 -0700998void
999ip6_forward_next_trace (vlib_main_t * vm,
1000 vlib_node_runtime_t * node,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001001 vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001002{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001003 u32 *from, n_left;
1004 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001005
1006 n_left = frame->n_vectors;
1007 from = vlib_frame_vector_args (frame);
Pierre Pfister0febaf12016-06-08 12:23:21 +01001008
Ed Warnickecb9cada2015-12-08 15:45:58 -07001009 while (n_left >= 4)
1010 {
1011 u32 bi0, bi1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001012 vlib_buffer_t *b0, *b1;
1013 ip6_forward_next_trace_t *t0, *t1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001014
1015 /* Prefetch next iteration. */
1016 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
1017 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
1018
1019 bi0 = from[0];
1020 bi1 = from[1];
1021
1022 b0 = vlib_get_buffer (vm, bi0);
1023 b1 = vlib_get_buffer (vm, bi1);
1024
1025 if (b0->flags & VLIB_BUFFER_IS_TRACED)
1026 {
1027 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1028 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001029 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
1030 t0->fib_index =
1031 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
1032 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
1033 vec_elt (im->fib_index_by_sw_if_index,
1034 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +01001035
Dave Barach178cf492018-11-13 16:34:13 -05001036 clib_memcpy_fast (t0->packet_data,
1037 vlib_buffer_get_current (b0),
1038 sizeof (t0->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001039 }
1040 if (b1->flags & VLIB_BUFFER_IS_TRACED)
1041 {
1042 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
1043 t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001044 t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
1045 t1->fib_index =
1046 (vnet_buffer (b1)->sw_if_index[VLIB_TX] !=
1047 (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] :
1048 vec_elt (im->fib_index_by_sw_if_index,
1049 vnet_buffer (b1)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +01001050
Dave Barach178cf492018-11-13 16:34:13 -05001051 clib_memcpy_fast (t1->packet_data,
1052 vlib_buffer_get_current (b1),
1053 sizeof (t1->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001054 }
1055 from += 2;
1056 n_left -= 2;
1057 }
1058
1059 while (n_left >= 1)
1060 {
1061 u32 bi0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001062 vlib_buffer_t *b0;
1063 ip6_forward_next_trace_t *t0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001064
1065 bi0 = from[0];
1066
1067 b0 = vlib_get_buffer (vm, bi0);
1068
1069 if (b0->flags & VLIB_BUFFER_IS_TRACED)
1070 {
1071 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1072 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001073 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
1074 t0->fib_index =
1075 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
1076 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
1077 vec_elt (im->fib_index_by_sw_if_index,
1078 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +01001079
Dave Barach178cf492018-11-13 16:34:13 -05001080 clib_memcpy_fast (t0->packet_data,
1081 vlib_buffer_get_current (b0),
1082 sizeof (t0->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001083 }
1084 from += 1;
1085 n_left -= 1;
1086 }
1087}
1088
Ed Warnickecb9cada2015-12-08 15:45:58 -07001089/* Compute TCP/UDP/ICMP6 checksum in software. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001090u16
1091ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
1092 ip6_header_t * ip0, int *bogus_lengthp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001093{
Matthew Smith97677a22020-02-05 11:46:40 -06001094 ip_csum_t sum0 = 0;
1095 u16 payload_length, payload_length_host_byte_order;
Srikanth A02833ff2019-10-02 17:48:58 -07001096 u32 i;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001097 u32 headers_size = sizeof (ip0[0]);
Dave Barachc4abafd2019-09-04 12:09:32 -04001098 u8 *data_this_buffer;
Matthew Smith97677a22020-02-05 11:46:40 -06001099 u8 next_hdr = ip0->protocol;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001100
Dave Barachd7cb1b52016-12-09 09:52:16 -05001101 ASSERT (bogus_lengthp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001102 *bogus_lengthp = 0;
1103
Ed Warnickecb9cada2015-12-08 15:45:58 -07001104 payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
Dave Barachc4abafd2019-09-04 12:09:32 -04001105 data_this_buffer = (u8 *) (ip0 + 1);
Matthew Smith97677a22020-02-05 11:46:40 -06001106 payload_length = ip0->payload_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001107
AkshayaNadahalli1b563522017-01-23 22:05:35 +05301108 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets)
1109 * or UDP-Ping packets */
Matthew Smith97677a22020-02-05 11:46:40 -06001110 if (PREDICT_FALSE (next_hdr == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001111 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001112 u32 skip_bytes;
1113 ip6_hop_by_hop_ext_t *ext_hdr =
1114 (ip6_hop_by_hop_ext_t *) data_this_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001115
1116 /* validate really icmp6 next */
AkshayaNadahalli1b563522017-01-23 22:05:35 +05301117 ASSERT ((ext_hdr->next_hdr == IP_PROTOCOL_ICMP6)
1118 || (ext_hdr->next_hdr == IP_PROTOCOL_UDP));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001119
Dave Barachd7cb1b52016-12-09 09:52:16 -05001120 skip_bytes = 8 * (1 + ext_hdr->n_data_u64s);
1121 data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes);
Dave Barach75fc8542016-10-11 16:16:02 -04001122
Dave Barachd7cb1b52016-12-09 09:52:16 -05001123 payload_length_host_byte_order -= skip_bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001124 headers_size += skip_bytes;
Matthew Smith97677a22020-02-05 11:46:40 -06001125
1126 /* pseudo-header adjustments:
1127 * exclude ext header bytes from payload length
1128 * use payload IP proto rather than ext header IP proto
1129 */
1130 payload_length = clib_host_to_net_u16 (payload_length_host_byte_order);
1131 next_hdr = ext_hdr->next_hdr;
1132 }
1133
1134 /* Initialize checksum with ip pseudo-header. */
1135 sum0 = payload_length + clib_host_to_net_u16 (next_hdr);
1136
1137 for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
1138 {
1139 sum0 = ip_csum_with_carry
1140 (sum0, clib_mem_unaligned (&ip0->src_address.as_uword[i], uword));
1141 sum0 = ip_csum_with_carry
1142 (sum0, clib_mem_unaligned (&ip0->dst_address.as_uword[i], uword));
Dave Barachd7cb1b52016-12-09 09:52:16 -05001143 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001144
John Lo3bc6bc22019-08-03 14:36:39 -04001145 if (p0)
Srikanth A02833ff2019-10-02 17:48:58 -07001146 return ip_calculate_l4_checksum (vm, p0, sum0,
1147 payload_length_host_byte_order,
1148 (u8 *) ip0, headers_size, NULL);
1149 else
1150 return ip_calculate_l4_checksum (vm, 0, sum0,
1151 payload_length_host_byte_order, NULL, 0,
1152 data_this_buffer);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001153}
1154
Dave Barachd7cb1b52016-12-09 09:52:16 -05001155u32
1156ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001157{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001158 ip6_header_t *ip0 = vlib_buffer_get_current (p0);
1159 udp_header_t *udp0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001160 u16 sum16;
1161 int bogus_length;
1162
1163 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
1164 ASSERT (ip0->protocol == IP_PROTOCOL_TCP
1165 || ip0->protocol == IP_PROTOCOL_ICMP6
1166 || ip0->protocol == IP_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001167 || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001168
1169 udp0 = (void *) (ip0 + 1);
1170 if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0)
1171 {
Damjan Marion213b5aa2017-07-13 21:19:27 +02001172 p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED
1173 | VNET_BUFFER_F_L4_CHECKSUM_CORRECT);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001174 return p0->flags;
1175 }
1176
1177 sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length);
1178
Damjan Marion213b5aa2017-07-13 21:19:27 +02001179 p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED
1180 | ((sum16 == 0) << VNET_BUFFER_F_LOG2_L4_CHECKSUM_CORRECT));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001181
1182 return p0->flags;
1183}
Damjan Marion38173502019-02-13 19:30:09 +01001184#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -07001185
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301186/**
1187 * @brief returns number of links on which src is reachable.
1188 */
1189always_inline int
1190ip6_urpf_loose_check (ip6_main_t * im, vlib_buffer_t * b, ip6_header_t * i)
1191{
1192 const load_balance_t *lb0;
1193 index_t lbi;
Florin Corasf3a3bad2018-03-28 02:18:29 -07001194 u32 fib_index;
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301195
Florin Corasf3a3bad2018-03-28 02:18:29 -07001196 fib_index = vec_elt (im->fib_index_by_sw_if_index,
1197 vnet_buffer (b)->sw_if_index[VLIB_RX]);
1198 fib_index =
1199 (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
1200 fib_index : vnet_buffer (b)->sw_if_index[VLIB_TX];
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301201
Simon Zhange7eba482019-08-25 15:30:45 +08001202 lbi = ip6_fib_table_fwding_lookup (fib_index, &i->src_address);
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301203 lb0 = load_balance_get (lbi);
1204
1205 return (fib_urpf_check_size (lb0->lb_urpf));
1206}
1207
rootc9d1c5b2017-08-15 12:58:31 -04001208always_inline u8
1209ip6_next_proto_is_tcp_udp (vlib_buffer_t * p0, ip6_header_t * ip0,
1210 u32 * udp_offset0)
1211{
Ole Troan03092c12021-11-23 15:55:39 +01001212 int nh = ip6_locate_header (p0, ip0, -1, udp_offset0);
1213 if (nh > 0)
1214 if (nh == IP_PROTOCOL_UDP || nh == IP_PROTOCOL_TCP)
1215 return nh;
1216 return 0;
rootc9d1c5b2017-08-15 12:58:31 -04001217}
1218
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001219VNET_FEATURE_ARC_INIT (ip6_local) = {
1220 .arc_name = "ip6-local",
1221 .start_nodes = VNET_FEATURES ("ip6-local", "ip6-receive"),
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001222};
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001223
johny17478e42019-10-11 18:28:51 +02001224static_always_inline u8
1225ip6_tcp_udp_icmp_bad_length (vlib_main_t * vm, vlib_buffer_t * p0)
1226{
1227
1228 u16 payload_length_host_byte_order;
1229 u32 n_this_buffer, n_bytes_left;
1230 ip6_header_t *ip0 = vlib_buffer_get_current (p0);
1231 u32 headers_size = sizeof (ip0[0]);
1232 u8 *data_this_buffer;
1233
1234
1235 data_this_buffer = (u8 *) (ip0 + 1);
1236
1237 ip6_hop_by_hop_ext_t *ext_hdr = (ip6_hop_by_hop_ext_t *) data_this_buffer;
1238
1239 /* validate really icmp6 next */
1240
1241 if (!(ext_hdr->next_hdr == IP_PROTOCOL_ICMP6)
1242 || (ext_hdr->next_hdr == IP_PROTOCOL_UDP))
1243 return 0;
1244
1245
1246 payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
1247 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
1248
johnya633a432019-12-06 13:58:35 +01001249
1250 u32 n_ip_bytes_this_buffer =
1251 p0->current_length - (((u8 *) ip0 - p0->data) - p0->current_data);
1252 if (n_this_buffer + headers_size > n_ip_bytes_this_buffer)
johny17478e42019-10-11 18:28:51 +02001253 {
johnya633a432019-12-06 13:58:35 +01001254 n_this_buffer = p0->current_length > headers_size ?
1255 n_ip_bytes_this_buffer - headers_size : 0;
johny17478e42019-10-11 18:28:51 +02001256 }
1257
1258 n_bytes_left -= n_this_buffer;
Klement Sekeracf1e8c12022-01-28 13:16:46 +00001259 n_bytes_left -= vlib_buffer_length_in_chain (vm, p0) - p0->current_length;
johny17478e42019-10-11 18:28:51 +02001260
1261 if (n_bytes_left == 0)
1262 return 0;
1263 else
1264 return 1;
1265}
1266
Benoît Ganne26a10192019-02-14 15:32:45 +01001267always_inline uword
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001268ip6_local_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
1269 vlib_frame_t *frame, int head_of_feature_arc,
1270 int is_receive_dpo)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001271{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001272 ip6_main_t *im = &ip6_main;
1273 ip_lookup_main_t *lm = &im->lookup_main;
Benoît Ganne26a10192019-02-14 15:32:45 +01001274 u32 *from, n_left_from;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001275 vlib_node_runtime_t *error_node =
1276 vlib_node_get_runtime (vm, ip6_input_node.index);
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001277 u8 arc_index = vnet_feat_arc_ip6_local.feature_arc_index;
Benoît Ganne26a10192019-02-14 15:32:45 +01001278 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1279 u16 nexts[VLIB_FRAME_SIZE], *next;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001280
1281 from = vlib_frame_vector_args (frame);
1282 n_left_from = frame->n_vectors;
Dave Barach75fc8542016-10-11 16:16:02 -04001283
Ed Warnickecb9cada2015-12-08 15:45:58 -07001284 if (node->flags & VLIB_NODE_FLAG_TRACE)
1285 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1286
Benoît Ganne26a10192019-02-14 15:32:45 +01001287 vlib_get_buffers (vm, from, bufs, n_left_from);
1288 b = bufs;
1289 next = nexts;
1290
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001291 while (n_left_from > 2)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001292 {
Benoît Ganne26a10192019-02-14 15:32:45 +01001293 /* Prefetch next iteration. */
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001294 if (n_left_from >= 6)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001295 {
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001296 vlib_prefetch_buffer_header (b[4], STORE);
1297 vlib_prefetch_buffer_header (b[5], STORE);
1298 vlib_prefetch_buffer_data (b[2], LOAD);
1299 vlib_prefetch_buffer_data (b[3], LOAD);
Benoît Ganne26a10192019-02-14 15:32:45 +01001300 }
Dave Barach75fc8542016-10-11 16:16:02 -04001301
Neale Rannse22a7042022-08-09 03:03:29 +00001302 vl_counter_ip6_enum_t error[2];
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001303 error[0] = IP6_ERROR_UNKNOWN_PROTOCOL;
1304 error[1] = IP6_ERROR_UNKNOWN_PROTOCOL;
Dave Barach75fc8542016-10-11 16:16:02 -04001305
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001306 ip6_header_t *ip[2];
1307 ip[0] = vlib_buffer_get_current (b[0]);
1308 ip[1] = vlib_buffer_get_current (b[1]);
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001309
Benoît Ganne26a10192019-02-14 15:32:45 +01001310 if (head_of_feature_arc)
1311 {
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001312 vnet_buffer (b[0])->l3_hdr_offset = b[0]->current_data;
1313 vnet_buffer (b[1])->l3_hdr_offset = b[1]->current_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001314
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001315 u8 type[2];
1316 type[0] = lm->builtin_protocol_by_ip_protocol[ip[0]->protocol];
1317 type[1] = lm->builtin_protocol_by_ip_protocol[ip[1]->protocol];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001318
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001319 u32 flags[2];
1320 flags[0] = b[0]->flags;
1321 flags[1] = b[1]->flags;
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001322
Mohsin Kazmi36f7a6a2021-05-05 14:26:38 +02001323 vnet_buffer_oflags_t oflags[2];
Mohsin Kazmia7e830e2021-04-23 15:16:50 +02001324 oflags[0] = vnet_buffer (b[0])->oflags;
1325 oflags[1] = vnet_buffer (b[1])->oflags;
Mohsin Kazmi68095382021-02-10 11:26:24 +01001326
1327 u32 l4_offload[2];
1328 l4_offload[0] = (flags[0] & VNET_BUFFER_F_OFFLOAD) &&
1329 (oflags[0] & (VNET_BUFFER_OFFLOAD_F_TCP_CKSUM |
1330 VNET_BUFFER_OFFLOAD_F_UDP_CKSUM));
1331 l4_offload[1] = (flags[1] & VNET_BUFFER_F_OFFLOAD) &&
1332 (oflags[1] & (VNET_BUFFER_OFFLOAD_F_TCP_CKSUM |
1333 VNET_BUFFER_OFFLOAD_F_UDP_CKSUM));
1334
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001335 u32 good_l4_csum[2];
1336 good_l4_csum[0] =
Mohsin Kazmi68095382021-02-10 11:26:24 +01001337 (flags[0] & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) | l4_offload[0];
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001338 good_l4_csum[1] =
Mohsin Kazmi68095382021-02-10 11:26:24 +01001339 (flags[1] & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) | l4_offload[1];
Filip Tehlarb601f222017-01-02 10:22:56 +01001340
Damjan Marion34e823f2019-02-19 08:55:18 +01001341 u32 udp_offset[2] = { };
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001342 u8 is_tcp_udp[2];
1343 is_tcp_udp[0] =
1344 ip6_next_proto_is_tcp_udp (b[0], ip[0], &udp_offset[0]);
1345 is_tcp_udp[1] =
1346 ip6_next_proto_is_tcp_udp (b[1], ip[1], &udp_offset[1]);
1347 i16 len_diff[2] = { 0 };
1348 if (PREDICT_TRUE (is_tcp_udp[0]))
Shwethab78292e2016-09-13 11:51:00 +01001349 {
Benoît Ganne26a10192019-02-14 15:32:45 +01001350 udp_header_t *udp =
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001351 (udp_header_t *) ((u8 *) ip[0] + udp_offset[0]);
1352 good_l4_csum[0] |= type[0] == IP_BUILTIN_PROTOCOL_UDP
Benoît Ganne26a10192019-02-14 15:32:45 +01001353 && udp->checksum == 0;
1354 /* optimistically verify UDP length. */
1355 u16 ip_len, udp_len;
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001356 ip_len = clib_net_to_host_u16 (ip[0]->payload_length);
Benoît Ganne26a10192019-02-14 15:32:45 +01001357 udp_len = clib_net_to_host_u16 (udp->length);
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001358 len_diff[0] = ip_len - udp_len;
Shwethab78292e2016-09-13 11:51:00 +01001359 }
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001360 if (PREDICT_TRUE (is_tcp_udp[1]))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001361 {
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001362 udp_header_t *udp =
1363 (udp_header_t *) ((u8 *) ip[1] + udp_offset[1]);
1364 good_l4_csum[1] |= type[1] == IP_BUILTIN_PROTOCOL_UDP
1365 && udp->checksum == 0;
1366 /* optimistically verify UDP length. */
1367 u16 ip_len, udp_len;
1368 ip_len = clib_net_to_host_u16 (ip[1]->payload_length);
1369 udp_len = clib_net_to_host_u16 (udp->length);
1370 len_diff[1] = ip_len - udp_len;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001371 }
1372
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001373 good_l4_csum[0] |= type[0] == IP_BUILTIN_PROTOCOL_UNKNOWN;
1374 good_l4_csum[1] |= type[1] == IP_BUILTIN_PROTOCOL_UNKNOWN;
1375
1376 len_diff[0] = type[0] == IP_BUILTIN_PROTOCOL_UDP ? len_diff[0] : 0;
1377 len_diff[1] = type[1] == IP_BUILTIN_PROTOCOL_UDP ? len_diff[1] : 0;
1378
1379 u8 need_csum[2];
1380 need_csum[0] = type[0] != IP_BUILTIN_PROTOCOL_UNKNOWN
1381 && !good_l4_csum[0]
1382 && !(flags[0] & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED);
1383 need_csum[1] = type[1] != IP_BUILTIN_PROTOCOL_UNKNOWN
1384 && !good_l4_csum[1]
1385 && !(flags[1] & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED);
1386 if (PREDICT_FALSE (need_csum[0]))
1387 {
1388 flags[0] = ip6_tcp_udp_icmp_validate_checksum (vm, b[0]);
1389 good_l4_csum[0] = flags[0] & VNET_BUFFER_F_L4_CHECKSUM_CORRECT;
johny17478e42019-10-11 18:28:51 +02001390 error[0] = IP6_ERROR_UNKNOWN_PROTOCOL;
1391 }
1392 else
1393 {
1394 if (ip6_tcp_udp_icmp_bad_length (vm, b[0]))
1395 error[0] = IP6_ERROR_BAD_LENGTH;
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001396 }
1397 if (PREDICT_FALSE (need_csum[1]))
1398 {
1399 flags[1] = ip6_tcp_udp_icmp_validate_checksum (vm, b[1]);
1400 good_l4_csum[1] = flags[1] & VNET_BUFFER_F_L4_CHECKSUM_CORRECT;
johny17478e42019-10-11 18:28:51 +02001401 error[1] = IP6_ERROR_UNKNOWN_PROTOCOL;
1402 }
1403 else
1404 {
1405 if (ip6_tcp_udp_icmp_bad_length (vm, b[1]))
1406 error[1] = IP6_ERROR_BAD_LENGTH;
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001407 }
1408
johny17478e42019-10-11 18:28:51 +02001409
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001410 error[0] = len_diff[0] < 0 ? IP6_ERROR_UDP_LENGTH : error[0];
johny17478e42019-10-11 18:28:51 +02001411
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001412 error[1] = len_diff[1] < 0 ? IP6_ERROR_UDP_LENGTH : error[1];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001413
Benoît Ganne26a10192019-02-14 15:32:45 +01001414 STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1415 IP6_ERROR_UDP_CHECKSUM,
1416 "Wrong IP6 errors constants");
1417 STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1418 IP6_ERROR_ICMP_CHECKSUM,
1419 "Wrong IP6 errors constants");
1420
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001421 error[0] =
1422 !good_l4_csum[0] ? IP6_ERROR_UDP_CHECKSUM + type[0] : error[0];
1423 error[1] =
1424 !good_l4_csum[1] ? IP6_ERROR_UDP_CHECKSUM + type[1] : error[1];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001425
1426 /* Drop packets from unroutable hosts. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001427 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001428 u8 unroutable[2];
1429 unroutable[0] = error[0] == IP6_ERROR_UNKNOWN_PROTOCOL
1430 && type[0] != IP_BUILTIN_PROTOCOL_ICMP
1431 && !ip6_address_is_link_local_unicast (&ip[0]->src_address);
1432 unroutable[1] = error[1] == IP6_ERROR_UNKNOWN_PROTOCOL
1433 && type[1] != IP_BUILTIN_PROTOCOL_ICMP
1434 && !ip6_address_is_link_local_unicast (&ip[1]->src_address);
1435 if (PREDICT_FALSE (unroutable[0]))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001436 {
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001437 error[0] =
1438 !ip6_urpf_loose_check (im, b[0],
1439 ip[0]) ? IP6_ERROR_SRC_LOOKUP_MISS
1440 : error[0];
1441 }
1442 if (PREDICT_FALSE (unroutable[1]))
1443 {
1444 error[1] =
1445 !ip6_urpf_loose_check (im, b[1],
1446 ip[1]) ? IP6_ERROR_SRC_LOOKUP_MISS
1447 : error[1];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001448 }
1449
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001450 vnet_buffer (b[0])->ip.fib_index =
1451 vnet_buffer (b[0])->sw_if_index[VLIB_TX] != ~0 ?
1452 vnet_buffer (b[0])->sw_if_index[VLIB_TX] :
1453 vnet_buffer (b[0])->ip.fib_index;
1454 vnet_buffer (b[1])->ip.fib_index =
1455 vnet_buffer (b[1])->sw_if_index[VLIB_TX] != ~0 ?
1456 vnet_buffer (b[1])->sw_if_index[VLIB_TX] :
1457 vnet_buffer (b[1])->ip.fib_index;
Alexander Chernavin65e770d2022-04-11 13:02:11 +00001458
1459 vnet_buffer (b[0])->ip.rx_sw_if_index =
1460 vnet_buffer (b[0])->sw_if_index[VLIB_RX];
1461 vnet_buffer (b[1])->ip.rx_sw_if_index =
1462 vnet_buffer (b[1])->sw_if_index[VLIB_RX];
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001463 if (is_receive_dpo)
1464 {
1465 const receive_dpo_t *rd0, *rd1;
1466 rd0 =
1467 receive_dpo_get (vnet_buffer (b[0])->ip.adj_index[VLIB_TX]);
1468 rd1 =
1469 receive_dpo_get (vnet_buffer (b[1])->ip.adj_index[VLIB_TX]);
Alexander Chernavin65e770d2022-04-11 13:02:11 +00001470 if (rd0->rd_sw_if_index != ~0)
1471 vnet_buffer (b[0])->ip.rx_sw_if_index = rd0->rd_sw_if_index;
1472 if (rd1->rd_sw_if_index != ~0)
1473 vnet_buffer (b[1])->ip.rx_sw_if_index = rd1->rd_sw_if_index;
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001474 }
Benoît Ganne26a10192019-02-14 15:32:45 +01001475 } /* head_of_feature_arc */
Florin Corascea194d2017-10-02 00:18:51 -07001476
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001477 next[0] = lm->local_next_by_ip_protocol[ip[0]->protocol];
1478 next[0] =
1479 error[0] != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next[0];
1480 next[1] = lm->local_next_by_ip_protocol[ip[1]->protocol];
1481 next[1] =
1482 error[1] != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next[1];
Florin Corascea194d2017-10-02 00:18:51 -07001483
Benoît Gannec15539a2021-01-19 16:40:07 +01001484 b[0]->error = error_node->errors[error[0]];
1485 b[1]->error = error_node->errors[error[1]];
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001486
Benoît Ganne26a10192019-02-14 15:32:45 +01001487 if (head_of_feature_arc)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001488 {
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001489 u8 ip6_unknown[2];
1490 ip6_unknown[0] = error[0] == (u8) IP6_ERROR_UNKNOWN_PROTOCOL;
1491 ip6_unknown[1] = error[1] == (u8) IP6_ERROR_UNKNOWN_PROTOCOL;
1492 if (PREDICT_TRUE (ip6_unknown[0]))
Shwethab78292e2016-09-13 11:51:00 +01001493 {
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001494 u32 next32 = next[0];
Benoît Ganne26a10192019-02-14 15:32:45 +01001495 vnet_feature_arc_start (arc_index,
Florin Corasf8408802021-11-09 18:29:03 -08001496 vnet_buffer (b[0])->ip.rx_sw_if_index,
1497 &next32, b[0]);
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001498 next[0] = next32;
1499 }
1500 if (PREDICT_TRUE (ip6_unknown[1]))
1501 {
1502 u32 next32 = next[1];
1503 vnet_feature_arc_start (arc_index,
Florin Corasf8408802021-11-09 18:29:03 -08001504 vnet_buffer (b[1])->ip.rx_sw_if_index,
1505 &next32, b[1]);
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001506 next[1] = next32;
Shwethab78292e2016-09-13 11:51:00 +01001507 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001508 }
Dave Barach75fc8542016-10-11 16:16:02 -04001509
Benoît Ganne26a10192019-02-14 15:32:45 +01001510 /* next */
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001511 b += 2;
1512 next += 2;
1513 n_left_from -= 2;
Benoît Ganne26a10192019-02-14 15:32:45 +01001514 }
Benoît Ganne7dcb80a2019-02-14 15:32:45 +01001515
Benoît Ganne26a10192019-02-14 15:32:45 +01001516 while (n_left_from)
1517 {
1518 u8 error;
1519 error = IP6_ERROR_UNKNOWN_PROTOCOL;
1520
1521 ip6_header_t *ip;
1522 ip = vlib_buffer_get_current (b[0]);
1523
1524 if (head_of_feature_arc)
1525 {
1526 vnet_buffer (b[0])->l3_hdr_offset = b[0]->current_data;
1527 u8 type = lm->builtin_protocol_by_ip_protocol[ip->protocol];
1528
1529 u32 flags = b[0]->flags;
Benoît Ganne26a10192019-02-14 15:32:45 +01001530
Mohsin Kazmi36f7a6a2021-05-05 14:26:38 +02001531 vnet_buffer_oflags_t oflags = vnet_buffer (b[0])->oflags;
Mohsin Kazmi68095382021-02-10 11:26:24 +01001532
1533 u32 l4_offload = (flags & VNET_BUFFER_F_OFFLOAD) &&
1534 (oflags & (VNET_BUFFER_OFFLOAD_F_TCP_CKSUM |
1535 VNET_BUFFER_OFFLOAD_F_UDP_CKSUM));
1536
1537 u32 good_l4_csum =
1538 (flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) | l4_offload;
Benoît Ganne26a10192019-02-14 15:32:45 +01001539 u32 udp_offset;
1540 i16 len_diff = 0;
1541 u8 is_tcp_udp = ip6_next_proto_is_tcp_udp (b[0], ip, &udp_offset);
1542 if (PREDICT_TRUE (is_tcp_udp))
1543 {
1544 udp_header_t *udp = (udp_header_t *) ((u8 *) ip + udp_offset);
1545 /* Don't verify UDP checksum for packets with explicit zero checksum. */
1546 good_l4_csum |= type == IP_BUILTIN_PROTOCOL_UDP
1547 && udp->checksum == 0;
1548 /* optimistically verify UDP length. */
1549 u16 ip_len, udp_len;
1550 ip_len = clib_net_to_host_u16 (ip->payload_length);
1551 udp_len = clib_net_to_host_u16 (udp->length);
1552 len_diff = ip_len - udp_len;
1553 }
1554
1555 good_l4_csum |= type == IP_BUILTIN_PROTOCOL_UNKNOWN;
1556 len_diff = type == IP_BUILTIN_PROTOCOL_UDP ? len_diff : 0;
1557
Mohsin Kazmi68095382021-02-10 11:26:24 +01001558 u8 need_csum = type != IP_BUILTIN_PROTOCOL_UNKNOWN &&
1559 !good_l4_csum &&
1560 !(flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED);
Benoît Ganne26a10192019-02-14 15:32:45 +01001561 if (PREDICT_FALSE (need_csum))
1562 {
1563 flags = ip6_tcp_udp_icmp_validate_checksum (vm, b[0]);
1564 good_l4_csum = flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT;
johny17478e42019-10-11 18:28:51 +02001565 error = IP6_ERROR_UNKNOWN_PROTOCOL;
1566 }
1567 else
1568 {
1569 if (ip6_tcp_udp_icmp_bad_length (vm, b[0]))
1570 error = IP6_ERROR_BAD_LENGTH;
Benoît Ganne26a10192019-02-14 15:32:45 +01001571 }
1572
johny17478e42019-10-11 18:28:51 +02001573
1574
Benoît Ganne26a10192019-02-14 15:32:45 +01001575 error = len_diff < 0 ? IP6_ERROR_UDP_LENGTH : error;
Benoît Ganne26a10192019-02-14 15:32:45 +01001576 STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1577 IP6_ERROR_UDP_CHECKSUM,
1578 "Wrong IP6 errors constants");
1579 STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1580 IP6_ERROR_ICMP_CHECKSUM,
1581 "Wrong IP6 errors constants");
1582
1583 error = !good_l4_csum ? IP6_ERROR_UDP_CHECKSUM + type : error;
1584
1585 /* Drop packets from unroutable hosts. */
1586 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
1587 u8 unroutable = error == IP6_ERROR_UNKNOWN_PROTOCOL
1588 && type != IP_BUILTIN_PROTOCOL_ICMP
1589 && !ip6_address_is_link_local_unicast (&ip->src_address);
1590 if (PREDICT_FALSE (unroutable))
1591 {
1592 error =
1593 !ip6_urpf_loose_check (im, b[0],
1594 ip) ? IP6_ERROR_SRC_LOOKUP_MISS :
1595 error;
1596 }
1597
1598 vnet_buffer (b[0])->ip.fib_index =
1599 vnet_buffer (b[0])->sw_if_index[VLIB_TX] != ~0 ?
1600 vnet_buffer (b[0])->sw_if_index[VLIB_TX] :
1601 vnet_buffer (b[0])->ip.fib_index;
Alexander Chernavin65e770d2022-04-11 13:02:11 +00001602
1603 vnet_buffer (b[0])->ip.rx_sw_if_index =
1604 vnet_buffer (b[0])->sw_if_index[VLIB_RX];
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001605 if (is_receive_dpo)
1606 {
1607 receive_dpo_t *rd;
1608 rd = receive_dpo_get (vnet_buffer (b[0])->ip.adj_index[VLIB_TX]);
Alexander Chernavin65e770d2022-04-11 13:02:11 +00001609 if (rd->rd_sw_if_index != ~0)
1610 vnet_buffer (b[0])->ip.rx_sw_if_index = rd->rd_sw_if_index;
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001611 }
Benoît Ganne26a10192019-02-14 15:32:45 +01001612 } /* head_of_feature_arc */
1613
1614 next[0] = lm->local_next_by_ip_protocol[ip->protocol];
1615 next[0] =
1616 error != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next[0];
1617
Benoît Gannec15539a2021-01-19 16:40:07 +01001618 b[0]->error = error_node->errors[error];
Benoît Ganne26a10192019-02-14 15:32:45 +01001619
1620 if (head_of_feature_arc)
1621 {
1622 if (PREDICT_TRUE (error == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
1623 {
1624 u32 next32 = next[0];
1625 vnet_feature_arc_start (arc_index,
Florin Corasf8408802021-11-09 18:29:03 -08001626 vnet_buffer (b[0])->ip.rx_sw_if_index,
1627 &next32, b[0]);
Benoît Ganne26a10192019-02-14 15:32:45 +01001628 next[0] = next32;
1629 }
1630 }
1631
1632 /* next */
1633 b += 1;
1634 next += 1;
1635 n_left_from -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001636 }
1637
Benoît Ganne26a10192019-02-14 15:32:45 +01001638 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001639 return frame->n_vectors;
1640}
1641
Damjan Marion38173502019-02-13 19:30:09 +01001642VLIB_NODE_FN (ip6_local_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
1643 vlib_frame_t * frame)
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001644{
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001645 return ip6_local_inline (vm, node, frame, 1 /* head of feature arc */,
1646 0 /* ip6_local_inline */);
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001647}
1648
Damjan Marion38173502019-02-13 19:30:09 +01001649VLIB_REGISTER_NODE (ip6_local_node) =
Dave Barachd7cb1b52016-12-09 09:52:16 -05001650{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001651 .name = "ip6-local",
1652 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -07001653 .format_trace = format_ip6_forward_next_trace,
Neale Rannse22a7042022-08-09 03:03:29 +00001654 .n_errors = IP6_N_ERROR,
1655 .error_counters = ip6_error_counters,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001656 .n_next_nodes = IP_LOCAL_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001657 .next_nodes =
1658 {
Neale Rannsd91c1db2017-07-31 02:30:50 -07001659 [IP_LOCAL_NEXT_DROP] = "ip6-drop",
1660 [IP_LOCAL_NEXT_PUNT] = "ip6-punt",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001661 [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
1662 [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
Klement Sekera01c1fa42021-12-14 18:25:11 +00001663 [IP_LOCAL_NEXT_REASSEMBLY] = "ip6-local-full-reassembly",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001664 },
1665};
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001666
1667VLIB_NODE_FN (ip6_receive_local_node)
1668(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
1669{
1670 return ip6_local_inline (vm, node, frame, 1 /* head of feature arc */,
1671 1 /* is_receive_dpo */);
1672}
1673
1674VLIB_REGISTER_NODE (ip6_receive_local_node) = {
1675 .name = "ip6-receive",
1676 .vector_size = sizeof (u32),
1677 .format_trace = format_ip6_forward_next_trace,
1678 .sibling_of = "ip6-local"
1679};
Ed Warnickecb9cada2015-12-08 15:45:58 -07001680
Damjan Marion38173502019-02-13 19:30:09 +01001681VLIB_NODE_FN (ip6_local_end_of_arc_node) (vlib_main_t * vm,
1682 vlib_node_runtime_t * node,
1683 vlib_frame_t * frame)
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001684{
Nathan Skrzypczakbfa86082021-09-09 18:31:36 +02001685 return ip6_local_inline (vm, node, frame, 0 /* head of feature arc */,
1686 0 /* ip6_local_inline */);
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001687}
1688
Damjan Marion38173502019-02-13 19:30:09 +01001689VLIB_REGISTER_NODE (ip6_local_end_of_arc_node) = {
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001690 .name = "ip6-local-end-of-arc",
1691 .vector_size = sizeof (u32),
1692
1693 .format_trace = format_ip6_forward_next_trace,
1694 .sibling_of = "ip6-local",
1695};
1696
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001697VNET_FEATURE_INIT (ip6_local_end_of_arc, static) = {
1698 .arc_name = "ip6-local",
1699 .node_name = "ip6-local-end-of-arc",
1700 .runs_before = 0, /* not before any other features */
1701};
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001702
Damjan Marion38173502019-02-13 19:30:09 +01001703#ifdef CLIB_MARCH_VARIANT
1704extern vlib_node_registration_t ip6_local_node;
Damjan Marion38173502019-02-13 19:30:09 +01001705#else
Dave Barachd7cb1b52016-12-09 09:52:16 -05001706void
1707ip6_register_protocol (u32 protocol, u32 node_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001708{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001709 vlib_main_t *vm = vlib_get_main ();
1710 ip6_main_t *im = &ip6_main;
1711 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001712
1713 ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
Dave Barachd7cb1b52016-12-09 09:52:16 -05001714 lm->local_next_by_ip_protocol[protocol] =
1715 vlib_node_add_next (vm, ip6_local_node.index, node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001716}
1717
Neale Rannsb538dd82019-05-21 06:54:54 -07001718void
1719ip6_unregister_protocol (u32 protocol)
1720{
1721 ip6_main_t *im = &ip6_main;
1722 ip_lookup_main_t *lm = &im->lookup_main;
1723
1724 ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
1725 lm->local_next_by_ip_protocol[protocol] = IP_LOCAL_NEXT_PUNT;
1726}
Damjan Marion38173502019-02-13 19:30:09 +01001727#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -07001728
Dave Barachd7cb1b52016-12-09 09:52:16 -05001729typedef enum
1730{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001731 IP6_REWRITE_NEXT_DROP,
Chris Luke816f3e12016-06-14 16:24:47 -04001732 IP6_REWRITE_NEXT_ICMP_ERROR,
Ole Troan313f7e22018-04-10 16:02:51 +02001733 IP6_REWRITE_NEXT_FRAGMENT,
1734 IP6_REWRITE_N_NEXT /* Last */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001735} ip6_rewrite_next_t;
1736
Neale Ranns889fe942017-06-01 05:43:19 -04001737/**
1738 * This bits of an IPv6 address to mask to construct a multicast
1739 * MAC address
1740 */
1741#define IP6_MCAST_ADDR_MASK 0xffffffff
1742
Ole Troanda6e11b2018-05-23 11:21:42 +02001743always_inline void
1744ip6_mtu_check (vlib_buffer_t * b, u16 packet_bytes,
Ole Troan313f7e22018-04-10 16:02:51 +02001745 u16 adj_packet_bytes, bool is_locally_generated,
Ole Troaneb284a12019-10-09 13:33:19 +02001746 u32 * next, u8 is_midchain, u32 * error)
Ole Troanda6e11b2018-05-23 11:21:42 +02001747{
1748 if (adj_packet_bytes >= 1280 && packet_bytes > adj_packet_bytes)
1749 {
Ole Troan313f7e22018-04-10 16:02:51 +02001750 if (is_locally_generated)
1751 {
1752 /* IP fragmentation */
Ole Troan282093f2018-09-19 12:38:51 +02001753 ip_frag_set_vnet_buffer (b, adj_packet_bytes,
Ole Troaneb284a12019-10-09 13:33:19 +02001754 (is_midchain ?
1755 IP_FRAG_NEXT_IP_REWRITE_MIDCHAIN :
1756 IP_FRAG_NEXT_IP_REWRITE), 0);
Ole Troan313f7e22018-04-10 16:02:51 +02001757 *next = IP6_REWRITE_NEXT_FRAGMENT;
Ole Troan282093f2018-09-19 12:38:51 +02001758 *error = IP6_ERROR_MTU_EXCEEDED;
Ole Troan313f7e22018-04-10 16:02:51 +02001759 }
1760 else
1761 {
1762 *error = IP6_ERROR_MTU_EXCEEDED;
1763 icmp6_error_set_vnet_buffer (b, ICMP6_packet_too_big, 0,
1764 adj_packet_bytes);
1765 *next = IP6_REWRITE_NEXT_ICMP_ERROR;
1766 }
Ole Troanda6e11b2018-05-23 11:21:42 +02001767 }
1768}
1769
Ed Warnickecb9cada2015-12-08 15:45:58 -07001770always_inline uword
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02001771ip6_rewrite_inline_with_gso (vlib_main_t * vm,
1772 vlib_node_runtime_t * node,
1773 vlib_frame_t * frame,
Mohsin Kazmi3f5594d2019-12-03 18:56:26 +01001774 int do_counters, int is_midchain, int is_mcast)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001775{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001776 ip_lookup_main_t *lm = &ip6_main.lookup_main;
1777 u32 *from = vlib_frame_vector_args (frame);
1778 u32 n_left_from, n_left_to_next, *to_next, next_index;
1779 vlib_node_runtime_t *error_node =
1780 vlib_node_get_runtime (vm, ip6_input_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001781
1782 n_left_from = frame->n_vectors;
1783 next_index = node->cached_next_index;
Damjan Marion067cd622018-07-11 12:47:43 +02001784 u32 thread_index = vm->thread_index;
Dave Barach75fc8542016-10-11 16:16:02 -04001785
Ed Warnickecb9cada2015-12-08 15:45:58 -07001786 while (n_left_from > 0)
1787 {
1788 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1789
1790 while (n_left_from >= 4 && n_left_to_next >= 2)
1791 {
Neale Ranns960eeea2019-12-02 23:28:50 +00001792 const ip_adjacency_t *adj0, *adj1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001793 vlib_buffer_t *p0, *p1;
1794 ip6_header_t *ip0, *ip1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001795 u32 pi0, rw_len0, next0, error0, adj_index0;
1796 u32 pi1, rw_len1, next1, error1, adj_index1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001797 u32 tx_sw_if_index0, tx_sw_if_index1;
Ole Troan313f7e22018-04-10 16:02:51 +02001798 bool is_locally_originated0, is_locally_originated1;
Dave Barach75fc8542016-10-11 16:16:02 -04001799
Ed Warnickecb9cada2015-12-08 15:45:58 -07001800 /* Prefetch next iteration. */
1801 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001802 vlib_buffer_t *p2, *p3;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001803
1804 p2 = vlib_get_buffer (vm, from[2]);
1805 p3 = vlib_get_buffer (vm, from[3]);
1806
1807 vlib_prefetch_buffer_header (p2, LOAD);
1808 vlib_prefetch_buffer_header (p3, LOAD);
1809
Damjan Marionaf7fb042021-07-15 11:54:41 +02001810 clib_prefetch_store (p2->pre_data);
1811 clib_prefetch_store (p3->pre_data);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001812
1813 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
1814 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
1815 }
1816
1817 pi0 = to_next[0] = from[0];
1818 pi1 = to_next[1] = from[1];
1819
1820 from += 2;
1821 n_left_from -= 2;
1822 to_next += 2;
1823 n_left_to_next -= 2;
Dave Barach75fc8542016-10-11 16:16:02 -04001824
Ed Warnickecb9cada2015-12-08 15:45:58 -07001825 p0 = vlib_get_buffer (vm, pi0);
1826 p1 = vlib_get_buffer (vm, pi1);
1827
Neale Rannsf06aea52016-11-29 06:51:37 -08001828 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1829 adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001830
Ed Warnickecb9cada2015-12-08 15:45:58 -07001831 ip0 = vlib_buffer_get_current (p0);
1832 ip1 = vlib_buffer_get_current (p1);
1833
1834 error0 = error1 = IP6_ERROR_NONE;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001835 next0 = next1 = IP6_REWRITE_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001836
Ole Troan313f7e22018-04-10 16:02:51 +02001837 is_locally_originated0 =
1838 p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
1839 if (PREDICT_TRUE (!is_locally_originated0))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001840 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001841 i32 hop_limit0 = ip0->hop_limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001842
1843 /* Input node should have reject packets with hop limit 0. */
1844 ASSERT (ip0->hop_limit > 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001845
1846 hop_limit0 -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001847
1848 ip0->hop_limit = hop_limit0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001849
Dave Barachd7cb1b52016-12-09 09:52:16 -05001850 /*
1851 * If the hop count drops below 1 when forwarding, generate
1852 * an ICMP response.
1853 */
1854 if (PREDICT_FALSE (hop_limit0 <= 0))
1855 {
1856 error0 = IP6_ERROR_TIME_EXPIRED;
1857 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
1858 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1859 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
1860 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1861 0);
1862 }
Neale Rannsf06aea52016-11-29 06:51:37 -08001863 }
Neale Ranns88cecfa2020-04-08 08:28:06 -04001864
Ole Troan313f7e22018-04-10 16:02:51 +02001865 is_locally_originated1 =
1866 p1->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
1867 if (PREDICT_TRUE (!is_locally_originated1))
Dave Barachd7cb1b52016-12-09 09:52:16 -05001868 {
Neale Rannsf06aea52016-11-29 06:51:37 -08001869 i32 hop_limit1 = ip1->hop_limit;
1870
1871 /* Input node should have reject packets with hop limit 0. */
1872 ASSERT (ip1->hop_limit > 0);
1873
1874 hop_limit1 -= 1;
1875
1876 ip1->hop_limit = hop_limit1;
1877
Dave Barachd7cb1b52016-12-09 09:52:16 -05001878 /*
1879 * If the hop count drops below 1 when forwarding, generate
1880 * an ICMP response.
1881 */
1882 if (PREDICT_FALSE (hop_limit1 <= 0))
1883 {
1884 error1 = IP6_ERROR_TIME_EXPIRED;
1885 next1 = IP6_REWRITE_NEXT_ICMP_ERROR;
1886 vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1887 icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded,
1888 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1889 0);
1890 }
1891 }
Neale Ranns88cecfa2020-04-08 08:28:06 -04001892
Neale Ranns107e7d42017-04-11 09:55:19 -07001893 adj0 = adj_get (adj_index0);
1894 adj1 = adj_get (adj_index1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001895
Ed Warnickecb9cada2015-12-08 15:45:58 -07001896 rw_len0 = adj0[0].rewrite_header.data_bytes;
1897 rw_len1 = adj1[0].rewrite_header.data_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001898 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
1899 vnet_buffer (p1)->ip.save_rewrite_length = rw_len1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001900
Ed Warnickecb9cada2015-12-08 15:45:58 -07001901 /* Check MTU of outgoing interface. */
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02001902 u16 ip0_len =
1903 clib_net_to_host_u16 (ip0->payload_length) +
1904 sizeof (ip6_header_t);
1905 u16 ip1_len =
1906 clib_net_to_host_u16 (ip1->payload_length) +
1907 sizeof (ip6_header_t);
Mohsin Kazmi3f5594d2019-12-03 18:56:26 +01001908 if (p0->flags & VNET_BUFFER_F_GSO)
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02001909 ip0_len = gso_mtu_sz (p0);
Mohsin Kazmi3f5594d2019-12-03 18:56:26 +01001910 if (p1->flags & VNET_BUFFER_F_GSO)
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02001911 ip1_len = gso_mtu_sz (p1);
1912
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02001913 ip6_mtu_check (p0, ip0_len,
Ole Troanda6e11b2018-05-23 11:21:42 +02001914 adj0[0].rewrite_header.max_l3_packet_bytes,
Ole Troaneb284a12019-10-09 13:33:19 +02001915 is_locally_originated0, &next0, is_midchain,
1916 &error0);
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02001917 ip6_mtu_check (p1, ip1_len,
Ole Troanda6e11b2018-05-23 11:21:42 +02001918 adj1[0].rewrite_header.max_l3_packet_bytes,
Ole Troaneb284a12019-10-09 13:33:19 +02001919 is_locally_originated1, &next1, is_midchain,
1920 &error1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001921 /* Don't adjust the buffer for hop count issue; icmp-error node
Jim Thompsonf324dec2019-04-08 03:22:21 -05001922 * wants to see the IP header */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001923 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
1924 {
Maxime Peim0e3fcc02024-04-04 11:09:26 +02001925 vlib_buffer_advance (p0, -(word) rw_len0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001926 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
1927 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
1928 next0 = adj0[0].rewrite_header.next_index;
Neale Rannsb069a692017-03-15 12:34:25 -04001929 if (PREDICT_FALSE
1930 (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
Maxime Peim0e3fcc02024-04-04 11:09:26 +02001931 vnet_feature_arc_start_w_cfg_index (
1932 lm->output_feature_arc_index, tx_sw_if_index0, &next0, p0,
1933 adj0->ia_cfg_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001934 }
Kingwel Xiecb36a1d2019-03-20 03:45:47 -04001935 else
1936 {
1937 p0->error = error_node->errors[error0];
1938 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001939 if (PREDICT_TRUE (error1 == IP6_ERROR_NONE))
1940 {
Maxime Peim0e3fcc02024-04-04 11:09:26 +02001941 vlib_buffer_advance (p1, -(word) rw_len1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001942 tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
1943 vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1;
1944 next1 = adj1[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04001945
Neale Rannsb069a692017-03-15 12:34:25 -04001946 if (PREDICT_FALSE
1947 (adj1[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
Maxime Peim0e3fcc02024-04-04 11:09:26 +02001948 vnet_feature_arc_start_w_cfg_index (
1949 lm->output_feature_arc_index, tx_sw_if_index1, &next1, p1,
1950 adj1->ia_cfg_index);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001951 }
Kingwel Xiecb36a1d2019-03-20 03:45:47 -04001952 else
1953 {
1954 p1->error = error_node->errors[error1];
1955 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001956
Neale Ranns25edf142019-03-22 08:12:48 +00001957 if (is_midchain)
Maxime Peim0e3fcc02024-04-04 11:09:26 +02001958 /* Guess we are only writing on ipv6 header. */
1959 vnet_rewrite_two_headers (adj0[0], adj1[0], ip0, ip1,
1960 sizeof (ip6_header_t));
Neale Ranns4ec36c52020-03-31 09:21:29 -04001961 else
1962 /* Guess we are only writing on simple Ethernet header. */
1963 vnet_rewrite_two_headers (adj0[0], adj1[0],
1964 ip0, ip1, sizeof (ethernet_header_t));
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001965
Maxime Peim0e3fcc02024-04-04 11:09:26 +02001966 if (do_counters)
1967 {
1968 if (error0 == IP6_ERROR_NONE)
1969 vlib_increment_combined_counter (
1970 &adjacency_counters, thread_index, adj_index0, 1,
1971 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
1972 if (error1 == IP6_ERROR_NONE)
1973 vlib_increment_combined_counter (
1974 &adjacency_counters, thread_index, adj_index1, 1,
1975 vlib_buffer_length_in_chain (vm, p1) + rw_len1);
1976 }
1977
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001978 if (is_midchain)
1979 {
Maxime Peim0e3fcc02024-04-04 11:09:26 +02001980 if (error0 == IP6_ERROR_NONE)
1981 adj_midchain_fixup (vm, adj0, p0, VNET_LINK_IP6);
1982 if (error1 == IP6_ERROR_NONE)
1983 adj_midchain_fixup (vm, adj1, p1, VNET_LINK_IP6);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001984 }
1985 if (is_mcast)
1986 {
1987 /*
1988 * copy bytes from the IP address into the MAC rewrite
1989 */
Maxime Peim0e3fcc02024-04-04 11:09:26 +02001990 if (error0 == IP6_ERROR_NONE)
1991 vnet_ip_mcast_fixup_header (
1992 IP6_MCAST_ADDR_MASK, adj0->rewrite_header.dst_mcast_offset,
1993 &ip0->dst_address.as_u32[3], (u8 *) ip0);
1994 if (error1 == IP6_ERROR_NONE)
1995 vnet_ip_mcast_fixup_header (
1996 IP6_MCAST_ADDR_MASK, adj1->rewrite_header.dst_mcast_offset,
1997 &ip1->dst_address.as_u32[3], (u8 *) ip1);
Neale Ranns32e1c012016-11-22 17:07:28 +00001998 }
Neale Ranns5e575b12016-10-03 09:40:25 +01001999
Ed Warnickecb9cada2015-12-08 15:45:58 -07002000 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
2001 to_next, n_left_to_next,
2002 pi0, pi1, next0, next1);
2003 }
2004
2005 while (n_left_from > 0 && n_left_to_next > 0)
2006 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002007 ip_adjacency_t *adj0;
2008 vlib_buffer_t *p0;
2009 ip6_header_t *ip0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002010 u32 pi0, rw_len0;
2011 u32 adj_index0, next0, error0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002012 u32 tx_sw_if_index0;
Ole Troan313f7e22018-04-10 16:02:51 +02002013 bool is_locally_originated0;
Dave Barach75fc8542016-10-11 16:16:02 -04002014
Ed Warnickecb9cada2015-12-08 15:45:58 -07002015 pi0 = to_next[0] = from[0];
2016
2017 p0 = vlib_get_buffer (vm, pi0);
2018
Neale Rannsf06aea52016-11-29 06:51:37 -08002019 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07002020
Neale Ranns107e7d42017-04-11 09:55:19 -07002021 adj0 = adj_get (adj_index0);
Dave Barach75fc8542016-10-11 16:16:02 -04002022
Ed Warnickecb9cada2015-12-08 15:45:58 -07002023 ip0 = vlib_buffer_get_current (p0);
2024
2025 error0 = IP6_ERROR_NONE;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002026 next0 = IP6_REWRITE_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002027
2028 /* Check hop limit */
Ole Troan313f7e22018-04-10 16:02:51 +02002029 is_locally_originated0 =
2030 p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
2031 if (PREDICT_TRUE (!is_locally_originated0))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002032 {
2033 i32 hop_limit0 = ip0->hop_limit;
2034
2035 ASSERT (ip0->hop_limit > 0);
2036
2037 hop_limit0 -= 1;
2038
2039 ip0->hop_limit = hop_limit0;
2040
Dave Barachd7cb1b52016-12-09 09:52:16 -05002041 if (PREDICT_FALSE (hop_limit0 <= 0))
2042 {
2043 /*
2044 * If the hop count drops below 1 when forwarding, generate
2045 * an ICMP response.
2046 */
2047 error0 = IP6_ERROR_TIME_EXPIRED;
2048 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
2049 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
2050 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
2051 ICMP6_time_exceeded_ttl_exceeded_in_transit,
2052 0);
2053 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002054 }
2055
Ed Warnickecb9cada2015-12-08 15:45:58 -07002056 /* Update packet buffer attributes/set output interface. */
2057 rw_len0 = adj0[0].rewrite_header.data_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002058 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002059
Ed Warnickecb9cada2015-12-08 15:45:58 -07002060 /* Check MTU of outgoing interface. */
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02002061 u16 ip0_len =
2062 clib_net_to_host_u16 (ip0->payload_length) +
2063 sizeof (ip6_header_t);
Mohsin Kazmi3f5594d2019-12-03 18:56:26 +01002064 if (p0->flags & VNET_BUFFER_F_GSO)
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02002065 ip0_len = gso_mtu_sz (p0);
2066
2067 ip6_mtu_check (p0, ip0_len,
Ole Troanda6e11b2018-05-23 11:21:42 +02002068 adj0[0].rewrite_header.max_l3_packet_bytes,
Ole Troaneb284a12019-10-09 13:33:19 +02002069 is_locally_originated0, &next0, is_midchain,
2070 &error0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002071 /* Don't adjust the buffer for hop count issue; icmp-error node
Ole Troanda6e11b2018-05-23 11:21:42 +02002072 * wants to see the IP header */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002073 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
2074 {
Maxime Peim0e3fcc02024-04-04 11:09:26 +02002075 vlib_buffer_advance (p0, -(word) rw_len0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002076 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
Dave Barach5331c722016-08-17 11:54:30 -04002077
Dave Barachd7cb1b52016-12-09 09:52:16 -05002078 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
2079 next0 = adj0[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04002080
Neale Rannsb069a692017-03-15 12:34:25 -04002081 if (PREDICT_FALSE
2082 (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
Maxime Peim0e3fcc02024-04-04 11:09:26 +02002083 vnet_feature_arc_start_w_cfg_index (
2084 lm->output_feature_arc_index, tx_sw_if_index0, &next0, p0,
2085 adj0->ia_cfg_index);
2086
2087 if (is_midchain)
2088 /* Guess we are only writing on ip6 header. */
2089 vnet_rewrite_one_header (adj0[0], ip0, sizeof (ip6_header_t));
2090 else
2091 /* Guess we are only writing on simple Ethernet header. */
2092 vnet_rewrite_one_header (adj0[0], ip0,
2093 sizeof (ethernet_header_t));
2094
2095 if (do_counters)
2096 {
2097 vlib_increment_combined_counter (
2098 &adjacency_counters, thread_index, adj_index0, 1,
2099 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
2100 }
2101
2102 if (is_midchain && adj0->sub_type.midchain.fixup_func)
2103 adj_midchain_fixup (vm, adj0, p0, VNET_LINK_IP6);
2104 if (is_mcast)
2105 vnet_ip_mcast_fixup_header (
2106 IP6_MCAST_ADDR_MASK, adj0->rewrite_header.dst_mcast_offset,
2107 &ip0->dst_address.as_u32[3], (u8 *) ip0);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02002108 }
Kingwel Xiecb36a1d2019-03-20 03:45:47 -04002109 else
2110 {
2111 p0->error = error_node->errors[error0];
2112 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002113
Ed Warnickecb9cada2015-12-08 15:45:58 -07002114 from += 1;
2115 n_left_from -= 1;
2116 to_next += 1;
2117 n_left_to_next -= 1;
Dave Barach75fc8542016-10-11 16:16:02 -04002118
Ed Warnickecb9cada2015-12-08 15:45:58 -07002119 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
2120 to_next, n_left_to_next,
2121 pi0, next0);
2122 }
2123
2124 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2125 }
2126
2127 /* Need to do trace after rewrites to pick up new packet data. */
2128 if (node->flags & VLIB_NODE_FLAG_TRACE)
Neale Rannsf06aea52016-11-29 06:51:37 -08002129 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002130
2131 return frame->n_vectors;
2132}
2133
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02002134always_inline uword
2135ip6_rewrite_inline (vlib_main_t * vm,
2136 vlib_node_runtime_t * node,
2137 vlib_frame_t * frame,
2138 int do_counters, int is_midchain, int is_mcast)
2139{
Mohsin Kazmi3f5594d2019-12-03 18:56:26 +01002140 return ip6_rewrite_inline_with_gso (vm, node, frame, do_counters,
2141 is_midchain, is_mcast);
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +02002142}
2143
Damjan Marion38173502019-02-13 19:30:09 +01002144VLIB_NODE_FN (ip6_rewrite_node) (vlib_main_t * vm,
2145 vlib_node_runtime_t * node,
2146 vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002147{
Neale Ranns9c6a6132017-02-21 05:33:14 -08002148 if (adj_are_counters_enabled ())
2149 return ip6_rewrite_inline (vm, node, frame, 1, 0, 0);
2150 else
2151 return ip6_rewrite_inline (vm, node, frame, 0, 0, 0);
Neale Ranns32e1c012016-11-22 17:07:28 +00002152}
2153
Damjan Marion38173502019-02-13 19:30:09 +01002154VLIB_NODE_FN (ip6_rewrite_bcast_node) (vlib_main_t * vm,
2155 vlib_node_runtime_t * node,
2156 vlib_frame_t * frame)
Neale Ranns1855b8e2018-07-11 10:31:26 -07002157{
2158 if (adj_are_counters_enabled ())
2159 return ip6_rewrite_inline (vm, node, frame, 1, 0, 0);
2160 else
2161 return ip6_rewrite_inline (vm, node, frame, 0, 0, 0);
2162}
2163
Damjan Marion38173502019-02-13 19:30:09 +01002164VLIB_NODE_FN (ip6_rewrite_mcast_node) (vlib_main_t * vm,
2165 vlib_node_runtime_t * node,
2166 vlib_frame_t * frame)
Neale Ranns32e1c012016-11-22 17:07:28 +00002167{
Neale Ranns9c6a6132017-02-21 05:33:14 -08002168 if (adj_are_counters_enabled ())
2169 return ip6_rewrite_inline (vm, node, frame, 1, 0, 1);
2170 else
2171 return ip6_rewrite_inline (vm, node, frame, 0, 0, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002172}
2173
Damjan Marion38173502019-02-13 19:30:09 +01002174VLIB_NODE_FN (ip6_midchain_node) (vlib_main_t * vm,
2175 vlib_node_runtime_t * node,
2176 vlib_frame_t * frame)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002177{
Neale Ranns9c6a6132017-02-21 05:33:14 -08002178 if (adj_are_counters_enabled ())
2179 return ip6_rewrite_inline (vm, node, frame, 1, 1, 0);
2180 else
2181 return ip6_rewrite_inline (vm, node, frame, 0, 1, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002182}
2183
Damjan Marion38173502019-02-13 19:30:09 +01002184VLIB_NODE_FN (ip6_mcast_midchain_node) (vlib_main_t * vm,
2185 vlib_node_runtime_t * node,
2186 vlib_frame_t * frame)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002187{
2188 if (adj_are_counters_enabled ())
2189 return ip6_rewrite_inline (vm, node, frame, 1, 1, 1);
2190 else
Neale Ranns9f171f52017-04-11 08:56:53 -07002191 return ip6_rewrite_inline (vm, node, frame, 0, 1, 1);
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002192}
2193
Neale Rannse22a7042022-08-09 03:03:29 +00002194VLIB_REGISTER_NODE (ip6_midchain_node) = {
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002195 .name = "ip6-midchain",
2196 .vector_size = sizeof (u32),
Maxime Peimd5fa6cc2024-05-24 17:01:36 +02002197 .format_trace = format_ip6_rewrite_trace,
Neale Ranns5e575b12016-10-03 09:40:25 +01002198 .sibling_of = "ip6-rewrite",
Neale Rannse22a7042022-08-09 03:03:29 +00002199};
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002200
Dave Barachd7cb1b52016-12-09 09:52:16 -05002201VLIB_REGISTER_NODE (ip6_rewrite_node) =
2202{
Ed Warnickecb9cada2015-12-08 15:45:58 -07002203 .name = "ip6-rewrite",
2204 .vector_size = sizeof (u32),
Pierre Pfistera38c3df2016-06-13 10:28:09 +01002205 .format_trace = format_ip6_rewrite_trace,
Ole Troan313f7e22018-04-10 16:02:51 +02002206 .n_next_nodes = IP6_REWRITE_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002207 .next_nodes =
2208 {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08002209 [IP6_REWRITE_NEXT_DROP] = "ip6-drop",
Chris Luke816f3e12016-06-14 16:24:47 -04002210 [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error",
Ole Troan313f7e22018-04-10 16:02:51 +02002211 [IP6_REWRITE_NEXT_FRAGMENT] = "ip6-frag",
Ed Warnickecb9cada2015-12-08 15:45:58 -07002212 },
2213};
2214
Neale Ranns1855b8e2018-07-11 10:31:26 -07002215VLIB_REGISTER_NODE (ip6_rewrite_bcast_node) = {
Neale Ranns1855b8e2018-07-11 10:31:26 -07002216 .name = "ip6-rewrite-bcast",
2217 .vector_size = sizeof (u32),
2218
2219 .format_trace = format_ip6_rewrite_trace,
2220 .sibling_of = "ip6-rewrite",
2221};
Neale Ranns1855b8e2018-07-11 10:31:26 -07002222
Neale Ranns32e1c012016-11-22 17:07:28 +00002223VLIB_REGISTER_NODE (ip6_rewrite_mcast_node) =
2224{
Neale Ranns32e1c012016-11-22 17:07:28 +00002225 .name = "ip6-rewrite-mcast",
2226 .vector_size = sizeof (u32),
2227 .format_trace = format_ip6_rewrite_trace,
2228 .sibling_of = "ip6-rewrite",
2229};
Neale Ranns32e1c012016-11-22 17:07:28 +00002230
Neale Ranns32e1c012016-11-22 17:07:28 +00002231
Damjan Marion38173502019-02-13 19:30:09 +01002232VLIB_REGISTER_NODE (ip6_mcast_midchain_node) =
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002233{
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002234 .name = "ip6-mcast-midchain",
2235 .vector_size = sizeof (u32),
2236 .format_trace = format_ip6_rewrite_trace,
2237 .sibling_of = "ip6-rewrite",
2238};
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002239
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002240
Ole Troan944f5482016-05-24 11:56:58 +02002241/*
2242 * Hop-by-Hop handling
2243 */
Benoît Ganne47727c02019-02-12 13:35:08 +01002244#ifndef CLIB_MARCH_VARIANT
Ole Troan944f5482016-05-24 11:56:58 +02002245ip6_hop_by_hop_main_t ip6_hop_by_hop_main;
Benoît Ganne47727c02019-02-12 13:35:08 +01002246#endif /* CLIB_MARCH_VARIANT */
Ole Troan944f5482016-05-24 11:56:58 +02002247
2248#define foreach_ip6_hop_by_hop_error \
2249_(PROCESSED, "pkts with ip6 hop-by-hop options") \
2250_(FORMAT, "incorrectly formatted hop-by-hop options") \
2251_(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options")
2252
Dave Barachd7cb1b52016-12-09 09:52:16 -05002253typedef enum
2254{
Ole Troan944f5482016-05-24 11:56:58 +02002255#define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym,
2256 foreach_ip6_hop_by_hop_error
2257#undef _
Neale Ranns32e1c012016-11-22 17:07:28 +00002258 IP6_HOP_BY_HOP_N_ERROR,
Ole Troan944f5482016-05-24 11:56:58 +02002259} ip6_hop_by_hop_error_t;
2260
2261/*
2262 * Primary h-b-h handler trace support
2263 * We work pretty hard on the problem for obvious reasons
2264 */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002265typedef struct
2266{
Ole Troan944f5482016-05-24 11:56:58 +02002267 u32 next_index;
2268 u32 trace_len;
2269 u8 option_data[256];
2270} ip6_hop_by_hop_trace_t;
2271
Benoît Ganne47727c02019-02-12 13:35:08 +01002272extern vlib_node_registration_t ip6_hop_by_hop_node;
Ole Troan944f5482016-05-24 11:56:58 +02002273
Dave Barachd7cb1b52016-12-09 09:52:16 -05002274static char *ip6_hop_by_hop_error_strings[] = {
Ole Troan944f5482016-05-24 11:56:58 +02002275#define _(sym,string) string,
2276 foreach_ip6_hop_by_hop_error
2277#undef _
2278};
2279
Damjan Marion38173502019-02-13 19:30:09 +01002280#ifndef CLIB_MARCH_VARIANT
Shwetha Bhandari78372a92017-01-18 12:43:54 +05302281u8 *
2282format_ip6_hop_by_hop_ext_hdr (u8 * s, va_list * args)
2283{
2284 ip6_hop_by_hop_header_t *hbh0 = va_arg (*args, ip6_hop_by_hop_header_t *);
2285 int total_len = va_arg (*args, int);
2286 ip6_hop_by_hop_option_t *opt0, *limit0;
2287 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2288 u8 type0;
Shwetha Bhandari78372a92017-01-18 12:43:54 +05302289 s = format (s, "IP6_HOP_BY_HOP: next protocol %d len %d total %d",
2290 hbh0->protocol, (hbh0->length + 1) << 3, total_len);
2291
2292 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2293 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + total_len);
2294
2295 while (opt0 < limit0)
2296 {
2297 type0 = opt0->type;
2298 switch (type0)
2299 {
2300 case 0: /* Pad, just stop */
2301 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0 + 1);
2302 break;
2303
2304 default:
2305 if (hm->trace[type0])
2306 {
2307 s = (*hm->trace[type0]) (s, opt0);
2308 }
2309 else
2310 {
Mohsin Kazmi68095382021-02-10 11:26:24 +01002311 s = format (s, "\n unrecognized option %d length %d", type0,
2312 opt0->length);
Shwetha Bhandari78372a92017-01-18 12:43:54 +05302313 }
2314 opt0 =
2315 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2316 sizeof (ip6_hop_by_hop_option_t));
2317 break;
2318 }
2319 }
2320 return s;
2321}
Damjan Marion38173502019-02-13 19:30:09 +01002322#endif
Shwetha Bhandari78372a92017-01-18 12:43:54 +05302323
Ole Troan944f5482016-05-24 11:56:58 +02002324static u8 *
2325format_ip6_hop_by_hop_trace (u8 * s, va_list * args)
2326{
2327 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2328 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002329 ip6_hop_by_hop_trace_t *t = va_arg (*args, ip6_hop_by_hop_trace_t *);
Ole Troan944f5482016-05-24 11:56:58 +02002330 ip6_hop_by_hop_header_t *hbh0;
2331 ip6_hop_by_hop_option_t *opt0, *limit0;
2332 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2333
2334 u8 type0;
2335
Dave Barachd7cb1b52016-12-09 09:52:16 -05002336 hbh0 = (ip6_hop_by_hop_header_t *) t->option_data;
Ole Troan944f5482016-05-24 11:56:58 +02002337
2338 s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002339 t->next_index, (hbh0->length + 1) << 3, t->trace_len);
Ole Troan944f5482016-05-24 11:56:58 +02002340
Dave Barachd7cb1b52016-12-09 09:52:16 -05002341 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2342 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0) + t->trace_len;
Ole Troan944f5482016-05-24 11:56:58 +02002343
Dave Barachd7cb1b52016-12-09 09:52:16 -05002344 while (opt0 < limit0)
2345 {
2346 type0 = opt0->type;
2347 switch (type0)
2348 {
2349 case 0: /* Pad, just stop */
2350 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
2351 break;
Ole Troan944f5482016-05-24 11:56:58 +02002352
Dave Barachd7cb1b52016-12-09 09:52:16 -05002353 default:
2354 if (hm->trace[type0])
2355 {
2356 s = (*hm->trace[type0]) (s, opt0);
2357 }
2358 else
2359 {
Mohsin Kazmi68095382021-02-10 11:26:24 +01002360 s = format (s, "\n unrecognized option %d length %d", type0,
2361 opt0->length);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002362 }
2363 opt0 =
2364 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2365 sizeof (ip6_hop_by_hop_option_t));
2366 break;
2367 }
Ole Troan944f5482016-05-24 11:56:58 +02002368 }
Ole Troan944f5482016-05-24 11:56:58 +02002369 return s;
2370}
2371
Dave Barachd7cb1b52016-12-09 09:52:16 -05002372always_inline u8
2373ip6_scan_hbh_options (vlib_buffer_t * b0,
2374 ip6_header_t * ip0,
2375 ip6_hop_by_hop_header_t * hbh0,
2376 ip6_hop_by_hop_option_t * opt0,
2377 ip6_hop_by_hop_option_t * limit0, u32 * next0)
Shwethaa91cbe62016-08-08 15:51:04 +01002378{
2379 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2380 u8 type0;
2381 u8 error0 = 0;
2382
2383 while (opt0 < limit0)
2384 {
2385 type0 = opt0->type;
2386 switch (type0)
2387 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002388 case 0: /* Pad1 */
2389 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
Shwethaa91cbe62016-08-08 15:51:04 +01002390 continue;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002391 case 1: /* PadN */
Shwethaa91cbe62016-08-08 15:51:04 +01002392 break;
2393 default:
2394 if (hm->options[type0])
2395 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002396 if ((*hm->options[type0]) (b0, ip0, opt0) < 0)
2397 {
Shwethaa91cbe62016-08-08 15:51:04 +01002398 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002399 return (error0);
2400 }
Shwethaa91cbe62016-08-08 15:51:04 +01002401 }
2402 else
2403 {
2404 /* Unrecognized mandatory option, check the two high order bits */
2405 switch (opt0->type & HBH_OPTION_TYPE_HIGH_ORDER_BITS)
2406 {
2407 case HBH_OPTION_TYPE_SKIP_UNKNOWN:
2408 break;
2409 case HBH_OPTION_TYPE_DISCARD_UNKNOWN:
2410 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2411 *next0 = IP_LOOKUP_NEXT_DROP;
2412 break;
2413 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP:
2414 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2415 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002416 icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem,
2417 ICMP6_parameter_problem_unrecognized_option,
2418 (u8 *) opt0 - (u8 *) ip0);
Shwethaa91cbe62016-08-08 15:51:04 +01002419 break;
2420 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST:
2421 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002422 if (!ip6_address_is_multicast (&ip0->dst_address))
Shwethaa91cbe62016-08-08 15:51:04 +01002423 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002424 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
2425 icmp6_error_set_vnet_buffer (b0,
2426 ICMP6_parameter_problem,
2427 ICMP6_parameter_problem_unrecognized_option,
2428 (u8 *) opt0 - (u8 *) ip0);
Shwethaa91cbe62016-08-08 15:51:04 +01002429 }
2430 else
2431 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002432 *next0 = IP_LOOKUP_NEXT_DROP;
Shwethaa91cbe62016-08-08 15:51:04 +01002433 }
2434 break;
2435 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002436 return (error0);
Shwethaa91cbe62016-08-08 15:51:04 +01002437 }
2438 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002439 opt0 =
2440 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2441 sizeof (ip6_hop_by_hop_option_t));
Shwethaa91cbe62016-08-08 15:51:04 +01002442 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002443 return (error0);
Shwethaa91cbe62016-08-08 15:51:04 +01002444}
2445
Ole Troan944f5482016-05-24 11:56:58 +02002446/*
2447 * Process the Hop-by-Hop Options header
2448 */
Damjan Marion38173502019-02-13 19:30:09 +01002449VLIB_NODE_FN (ip6_hop_by_hop_node) (vlib_main_t * vm,
2450 vlib_node_runtime_t * node,
2451 vlib_frame_t * frame)
Ole Troan944f5482016-05-24 11:56:58 +02002452{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002453 vlib_node_runtime_t *error_node =
2454 vlib_node_get_runtime (vm, ip6_hop_by_hop_node.index);
Ole Troan944f5482016-05-24 11:56:58 +02002455 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2456 u32 n_left_from, *from, *to_next;
2457 ip_lookup_next_t next_index;
Ole Troan944f5482016-05-24 11:56:58 +02002458
2459 from = vlib_frame_vector_args (frame);
2460 n_left_from = frame->n_vectors;
2461 next_index = node->cached_next_index;
2462
Dave Barachd7cb1b52016-12-09 09:52:16 -05002463 while (n_left_from > 0)
2464 {
2465 u32 n_left_to_next;
Ole Troan944f5482016-05-24 11:56:58 +02002466
Dave Barachd7cb1b52016-12-09 09:52:16 -05002467 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ole Troan944f5482016-05-24 11:56:58 +02002468
Dave Barachd7cb1b52016-12-09 09:52:16 -05002469 while (n_left_from >= 4 && n_left_to_next >= 2)
Shwethaa91cbe62016-08-08 15:51:04 +01002470 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002471 u32 bi0, bi1;
2472 vlib_buffer_t *b0, *b1;
2473 u32 next0, next1;
2474 ip6_header_t *ip0, *ip1;
2475 ip6_hop_by_hop_header_t *hbh0, *hbh1;
2476 ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1;
2477 u8 error0 = 0, error1 = 0;
2478
2479 /* Prefetch next iteration. */
2480 {
2481 vlib_buffer_t *p2, *p3;
2482
2483 p2 = vlib_get_buffer (vm, from[2]);
2484 p3 = vlib_get_buffer (vm, from[3]);
2485
2486 vlib_prefetch_buffer_header (p2, LOAD);
2487 vlib_prefetch_buffer_header (p3, LOAD);
2488
2489 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
2490 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
Shwethaa91cbe62016-08-08 15:51:04 +01002491 }
2492
Dave Barachd7cb1b52016-12-09 09:52:16 -05002493 /* Speculatively enqueue b0, b1 to the current next frame */
2494 to_next[0] = bi0 = from[0];
2495 to_next[1] = bi1 = from[1];
2496 from += 2;
2497 to_next += 2;
2498 n_left_from -= 2;
2499 n_left_to_next -= 2;
2500
2501 b0 = vlib_get_buffer (vm, bi0);
2502 b1 = vlib_get_buffer (vm, bi1);
2503
2504 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2505 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002506 ip_adjacency_t *adj0 = adj_get (adj_index0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002507 u32 adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002508 ip_adjacency_t *adj1 = adj_get (adj_index1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002509
2510 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2511 next0 = adj0->lookup_next_index;
2512 next1 = adj1->lookup_next_index;
2513
2514 ip0 = vlib_buffer_get_current (b0);
2515 ip1 = vlib_buffer_get_current (b1);
2516 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2517 hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
2518 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2519 opt1 = (ip6_hop_by_hop_option_t *) (hbh1 + 1);
2520 limit0 =
2521 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2522 ((hbh0->length + 1) << 3));
2523 limit1 =
2524 (ip6_hop_by_hop_option_t *) ((u8 *) hbh1 +
2525 ((hbh1->length + 1) << 3));
2526
2527 /*
2528 * Basic validity checks
2529 */
2530 if ((hbh0->length + 1) << 3 >
2531 clib_net_to_host_u16 (ip0->payload_length))
2532 {
2533 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2534 next0 = IP_LOOKUP_NEXT_DROP;
2535 goto outdual;
2536 }
2537 /* Scan the set of h-b-h options, process ones that we understand */
2538 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2539
2540 if ((hbh1->length + 1) << 3 >
2541 clib_net_to_host_u16 (ip1->payload_length))
2542 {
2543 error1 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2544 next1 = IP_LOOKUP_NEXT_DROP;
2545 goto outdual;
2546 }
2547 /* Scan the set of h-b-h options, process ones that we understand */
2548 error1 = ip6_scan_hbh_options (b1, ip1, hbh1, opt1, limit1, &next1);
2549
2550 outdual:
2551 /* Has the classifier flagged this buffer for special treatment? */
2552 if (PREDICT_FALSE
2553 ((error0 == 0)
2554 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2555 next0 = hm->next_override;
2556
2557 /* Has the classifier flagged this buffer for special treatment? */
2558 if (PREDICT_FALSE
2559 ((error1 == 0)
2560 && (vnet_buffer (b1)->l2_classify.opaque_index & OI_DECAP)))
2561 next1 = hm->next_override;
2562
2563 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
2564 {
2565 if (b0->flags & VLIB_BUFFER_IS_TRACED)
2566 {
2567 ip6_hop_by_hop_trace_t *t =
2568 vlib_add_trace (vm, node, b0, sizeof (*t));
2569 u32 trace_len = (hbh0->length + 1) << 3;
2570 t->next_index = next0;
2571 /* Capture the h-b-h option verbatim */
2572 trace_len =
2573 trace_len <
2574 ARRAY_LEN (t->option_data) ? trace_len :
2575 ARRAY_LEN (t->option_data);
2576 t->trace_len = trace_len;
Dave Barach178cf492018-11-13 16:34:13 -05002577 clib_memcpy_fast (t->option_data, hbh0, trace_len);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002578 }
2579 if (b1->flags & VLIB_BUFFER_IS_TRACED)
2580 {
2581 ip6_hop_by_hop_trace_t *t =
2582 vlib_add_trace (vm, node, b1, sizeof (*t));
2583 u32 trace_len = (hbh1->length + 1) << 3;
2584 t->next_index = next1;
2585 /* Capture the h-b-h option verbatim */
2586 trace_len =
2587 trace_len <
2588 ARRAY_LEN (t->option_data) ? trace_len :
2589 ARRAY_LEN (t->option_data);
2590 t->trace_len = trace_len;
Dave Barach178cf492018-11-13 16:34:13 -05002591 clib_memcpy_fast (t->option_data, hbh1, trace_len);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002592 }
2593
2594 }
2595
2596 b0->error = error_node->errors[error0];
2597 b1->error = error_node->errors[error1];
2598
2599 /* verify speculative enqueue, maybe switch current next frame */
2600 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
2601 n_left_to_next, bi0, bi1, next0,
2602 next1);
Shwethaa91cbe62016-08-08 15:51:04 +01002603 }
2604
Dave Barachd7cb1b52016-12-09 09:52:16 -05002605 while (n_left_from > 0 && n_left_to_next > 0)
2606 {
2607 u32 bi0;
2608 vlib_buffer_t *b0;
2609 u32 next0;
2610 ip6_header_t *ip0;
2611 ip6_hop_by_hop_header_t *hbh0;
2612 ip6_hop_by_hop_option_t *opt0, *limit0;
2613 u8 error0 = 0;
Shwethaa91cbe62016-08-08 15:51:04 +01002614
Dave Barachd7cb1b52016-12-09 09:52:16 -05002615 /* Speculatively enqueue b0 to the current next frame */
2616 bi0 = from[0];
2617 to_next[0] = bi0;
2618 from += 1;
2619 to_next += 1;
2620 n_left_from -= 1;
2621 n_left_to_next -= 1;
2622
2623 b0 = vlib_get_buffer (vm, bi0);
2624 /*
2625 * Default use the next_index from the adjacency.
2626 * A HBH option rarely redirects to a different node
2627 */
2628 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002629 ip_adjacency_t *adj0 = adj_get (adj_index0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002630 next0 = adj0->lookup_next_index;
2631
2632 ip0 = vlib_buffer_get_current (b0);
2633 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2634 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2635 limit0 =
2636 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2637 ((hbh0->length + 1) << 3));
2638
2639 /*
2640 * Basic validity checks
2641 */
2642 if ((hbh0->length + 1) << 3 >
2643 clib_net_to_host_u16 (ip0->payload_length))
2644 {
2645 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2646 next0 = IP_LOOKUP_NEXT_DROP;
2647 goto out0;
2648 }
2649
2650 /* Scan the set of h-b-h options, process ones that we understand */
2651 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2652
2653 out0:
2654 /* Has the classifier flagged this buffer for special treatment? */
2655 if (PREDICT_FALSE
2656 ((error0 == 0)
2657 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2658 next0 = hm->next_override;
2659
2660 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2661 {
2662 ip6_hop_by_hop_trace_t *t =
2663 vlib_add_trace (vm, node, b0, sizeof (*t));
2664 u32 trace_len = (hbh0->length + 1) << 3;
2665 t->next_index = next0;
2666 /* Capture the h-b-h option verbatim */
2667 trace_len =
2668 trace_len <
2669 ARRAY_LEN (t->option_data) ? trace_len :
2670 ARRAY_LEN (t->option_data);
2671 t->trace_len = trace_len;
Dave Barach178cf492018-11-13 16:34:13 -05002672 clib_memcpy_fast (t->option_data, hbh0, trace_len);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002673 }
2674
2675 b0->error = error_node->errors[error0];
2676
2677 /* verify speculative enqueue, maybe switch current next frame */
2678 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2679 n_left_to_next, bi0, next0);
2680 }
2681 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
Shwethaa91cbe62016-08-08 15:51:04 +01002682 }
Ole Troan944f5482016-05-24 11:56:58 +02002683 return frame->n_vectors;
2684}
2685
Dave Barachd7cb1b52016-12-09 09:52:16 -05002686VLIB_REGISTER_NODE (ip6_hop_by_hop_node) =
2687{
Ole Troan944f5482016-05-24 11:56:58 +02002688 .name = "ip6-hop-by-hop",
Ole Troan964f93e2016-06-10 13:22:36 +02002689 .sibling_of = "ip6-lookup",
Ole Troan944f5482016-05-24 11:56:58 +02002690 .vector_size = sizeof (u32),
2691 .format_trace = format_ip6_hop_by_hop_trace,
2692 .type = VLIB_NODE_TYPE_INTERNAL,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002693 .n_errors = ARRAY_LEN (ip6_hop_by_hop_error_strings),
Ole Troan944f5482016-05-24 11:56:58 +02002694 .error_strings = ip6_hop_by_hop_error_strings,
Ole Troan964f93e2016-06-10 13:22:36 +02002695 .n_next_nodes = 0,
Ole Troan944f5482016-05-24 11:56:58 +02002696};
2697
Ole Troan944f5482016-05-24 11:56:58 +02002698static clib_error_t *
2699ip6_hop_by_hop_init (vlib_main_t * vm)
2700{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002701 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Dave Barachb7b92992018-10-17 10:38:51 -04002702 clib_memset (hm->options, 0, sizeof (hm->options));
2703 clib_memset (hm->trace, 0, sizeof (hm->trace));
Shwethaa91cbe62016-08-08 15:51:04 +01002704 hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
Ole Troan944f5482016-05-24 11:56:58 +02002705 return (0);
2706}
2707
2708VLIB_INIT_FUNCTION (ip6_hop_by_hop_init);
2709
Damjan Marion38173502019-02-13 19:30:09 +01002710#ifndef CLIB_MARCH_VARIANT
Dave Barachd7cb1b52016-12-09 09:52:16 -05002711void
2712ip6_hbh_set_next_override (uword next)
Shwethaa91cbe62016-08-08 15:51:04 +01002713{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002714 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Shwethaa91cbe62016-08-08 15:51:04 +01002715
2716 hm->next_override = next;
2717}
2718
Ole Troan944f5482016-05-24 11:56:58 +02002719int
2720ip6_hbh_register_option (u8 option,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002721 int options (vlib_buffer_t * b, ip6_header_t * ip,
2722 ip6_hop_by_hop_option_t * opt),
2723 u8 * trace (u8 * s, ip6_hop_by_hop_option_t * opt))
Ole Troan944f5482016-05-24 11:56:58 +02002724{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002725 ip6_main_t *im = &ip6_main;
2726 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Ole Troan944f5482016-05-24 11:56:58 +02002727
Neale Ranns756cd942018-04-06 09:18:11 -07002728 ASSERT ((u32) option < ARRAY_LEN (hm->options));
Ole Troan944f5482016-05-24 11:56:58 +02002729
2730 /* Already registered */
2731 if (hm->options[option])
2732 return (-1);
2733
2734 hm->options[option] = options;
2735 hm->trace[option] = trace;
2736
2737 /* Set global variable */
2738 im->hbh_enabled = 1;
2739
2740 return (0);
2741}
2742
2743int
2744ip6_hbh_unregister_option (u8 option)
2745{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002746 ip6_main_t *im = &ip6_main;
2747 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Ole Troan944f5482016-05-24 11:56:58 +02002748
Neale Ranns756cd942018-04-06 09:18:11 -07002749 ASSERT ((u32) option < ARRAY_LEN (hm->options));
Ole Troan944f5482016-05-24 11:56:58 +02002750
2751 /* Not registered */
2752 if (!hm->options[option])
2753 return (-1);
2754
2755 hm->options[option] = NULL;
2756 hm->trace[option] = NULL;
2757
2758 /* Disable global knob if this was the last option configured */
2759 int i;
2760 bool found = false;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002761 for (i = 0; i < 256; i++)
2762 {
2763 if (hm->options[option])
2764 {
2765 found = true;
2766 break;
2767 }
Ole Troan944f5482016-05-24 11:56:58 +02002768 }
Ole Troan944f5482016-05-24 11:56:58 +02002769 if (!found)
2770 im->hbh_enabled = 0;
2771
2772 return (0);
2773}
2774
Ed Warnickecb9cada2015-12-08 15:45:58 -07002775/* Global IP6 main. */
2776ip6_main_t ip6_main;
Damjan Marion38173502019-02-13 19:30:09 +01002777#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -07002778
2779static clib_error_t *
2780ip6_lookup_init (vlib_main_t * vm)
2781{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002782 ip6_main_t *im = &ip6_main;
2783 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002784 uword i;
2785
Damjan Marion8b3191e2016-11-09 19:54:20 +01002786 if ((error = vlib_call_init_function (vm, vnet_feature_init)))
2787 return error;
2788
Ed Warnickecb9cada2015-12-08 15:45:58 -07002789 for (i = 0; i < ARRAY_LEN (im->fib_masks); i++)
2790 {
2791 u32 j, i0, i1;
2792
2793 i0 = i / 32;
2794 i1 = i % 32;
2795
2796 for (j = 0; j < i0; j++)
2797 im->fib_masks[i].as_u32[j] = ~0;
2798
2799 if (i1)
Dave Barachd7cb1b52016-12-09 09:52:16 -05002800 im->fib_masks[i].as_u32[i0] =
2801 clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002802 }
2803
2804 ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1);
2805
Ed Warnickecb9cada2015-12-08 15:45:58 -07002806 /* Create FIB with index 0 and table id of 0. */
Neale Ranns15002542017-09-10 04:39:11 -07002807 fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0,
2808 FIB_SOURCE_DEFAULT_ROUTE);
2809 mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0,
2810 MFIB_SOURCE_DEFAULT_ROUTE);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002811
2812 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002813 pg_node_t *pn;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002814 pn = pg_get_node (ip6_lookup_node.index);
2815 pn->unformat_edit = unformat_pg_ip6_header;
2816 }
2817
Ole Troan944f5482016-05-24 11:56:58 +02002818 /* Unless explicitly configured, don't process HBH options */
2819 im->hbh_enabled = 0;
2820
Dave Barach203c6322016-06-26 10:29:03 -04002821 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002822}
2823
2824VLIB_INIT_FUNCTION (ip6_lookup_init);
2825
Ed Warnickecb9cada2015-12-08 15:45:58 -07002826static clib_error_t *
2827set_ip6_flow_hash_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002828 unformat_input_t * input,
2829 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002830{
2831 int matched = 0;
2832 u32 table_id = 0;
2833 u32 flow_hash_config = 0;
2834 int rv;
2835
Dave Barachd7cb1b52016-12-09 09:52:16 -05002836 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2837 {
2838 if (unformat (input, "table %d", &table_id))
2839 matched = 1;
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00002840#define _(a, b, v) \
2841 else if (unformat (input, #a)) \
2842 { \
2843 flow_hash_config |= v; \
2844 matched = 1; \
2845 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002846 foreach_flow_hash_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07002847#undef _
Dave Barachd7cb1b52016-12-09 09:52:16 -05002848 else
2849 break;
2850 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002851
2852 if (matched == 0)
2853 return clib_error_return (0, "unknown input `%U'",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002854 format_unformat_error, input);
Dave Barach75fc8542016-10-11 16:16:02 -04002855
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00002856 rv = ip_flow_hash_set (AF_IP6, table_id, flow_hash_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002857 switch (rv)
2858 {
Neale Ranns227038a2017-04-21 01:07:59 -07002859 case 0:
Ed Warnickecb9cada2015-12-08 15:45:58 -07002860 break;
2861
2862 case -1:
2863 return clib_error_return (0, "no such FIB table %d", table_id);
Dave Barach75fc8542016-10-11 16:16:02 -04002864
Ed Warnickecb9cada2015-12-08 15:45:58 -07002865 default:
2866 clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config);
2867 break;
2868 }
Dave Barach75fc8542016-10-11 16:16:02 -04002869
Ed Warnickecb9cada2015-12-08 15:45:58 -07002870 return 0;
2871}
2872
Billy McFall0683c9c2016-10-13 08:27:31 -04002873/*?
2874 * Configure the set of IPv6 fields used by the flow hash.
2875 *
2876 * @cliexpar
2877 * @parblock
2878 * Example of how to set the flow hash on a given table:
Billy McFallebb9a6a2016-10-17 11:35:32 -04002879 * @cliexcmd{set ip6 flow-hash table 8 dst sport dport proto}
2880 *
Billy McFall0683c9c2016-10-13 08:27:31 -04002881 * Example of display the configured flow hash:
2882 * @cliexstart{show ip6 fib}
Billy McFallebb9a6a2016-10-17 11:35:32 -04002883 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
2884 * @::/0
2885 * unicast-ip6-chain
2886 * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]]
2887 * [0] [@0]: dpo-drop ip6
2888 * fe80::/10
2889 * unicast-ip6-chain
2890 * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]]
2891 * [0] [@2]: dpo-receive
2892 * ff02::1/128
2893 * unicast-ip6-chain
2894 * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]]
2895 * [0] [@2]: dpo-receive
2896 * ff02::2/128
2897 * unicast-ip6-chain
2898 * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]]
2899 * [0] [@2]: dpo-receive
2900 * ff02::16/128
2901 * unicast-ip6-chain
2902 * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]]
2903 * [0] [@2]: dpo-receive
2904 * ff02::1:ff00:0/104
2905 * unicast-ip6-chain
2906 * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]]
2907 * [0] [@2]: dpo-receive
2908 * ipv6-VRF:8, fib_index 1, flow hash: dst sport dport proto
2909 * @::/0
2910 * unicast-ip6-chain
2911 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
2912 * [0] [@0]: dpo-drop ip6
2913 * @::a:1:1:0:4/126
2914 * unicast-ip6-chain
2915 * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]]
2916 * [0] [@4]: ipv6-glean: af_packet0
2917 * @::a:1:1:0:7/128
2918 * unicast-ip6-chain
2919 * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]]
2920 * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0
2921 * fe80::/10
2922 * unicast-ip6-chain
2923 * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]]
2924 * [0] [@2]: dpo-receive
2925 * fe80::fe:3eff:fe3e:9222/128
2926 * unicast-ip6-chain
2927 * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]]
2928 * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0
2929 * ff02::1/128
2930 * unicast-ip6-chain
2931 * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]]
2932 * [0] [@2]: dpo-receive
2933 * ff02::2/128
2934 * unicast-ip6-chain
2935 * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]]
2936 * [0] [@2]: dpo-receive
2937 * ff02::16/128
2938 * unicast-ip6-chain
2939 * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]]
2940 * [0] [@2]: dpo-receive
2941 * ff02::1:ff00:0/104
2942 * unicast-ip6-chain
2943 * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]]
2944 * [0] [@2]: dpo-receive
Billy McFall0683c9c2016-10-13 08:27:31 -04002945 * @cliexend
2946 * @endparblock
2947?*/
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00002948VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) = {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002949 .path = "set ip6 flow-hash",
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00002950 .short_help = "set ip6 flow-hash table <table-id> [src] [dst] [sport] "
2951 "[dport] [proto] [reverse] [flowlabel]",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002952 .function = set_ip6_flow_hash_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07002953};
2954
2955static clib_error_t *
2956show_ip6_local_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002957 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002958{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002959 ip6_main_t *im = &ip6_main;
2960 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002961 int i;
Dave Barach75fc8542016-10-11 16:16:02 -04002962
Ed Warnickecb9cada2015-12-08 15:45:58 -07002963 vlib_cli_output (vm, "Protocols handled by ip6_local");
Dave Barachd7cb1b52016-12-09 09:52:16 -05002964 for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002965 {
2966 if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
Pierre Pfister1bfd3722017-09-18 11:40:32 +02002967 {
2968
2969 u32 node_index = vlib_get_node (vm,
2970 ip6_local_node.index)->
2971 next_nodes[lm->local_next_by_ip_protocol[i]];
2972 vlib_cli_output (vm, "%d: %U", i, format_vlib_node_name, vm,
2973 node_index);
2974 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002975 }
2976 return 0;
2977}
2978
2979
2980
Billy McFall0683c9c2016-10-13 08:27:31 -04002981/*?
2982 * Display the set of protocols handled by the local IPv6 stack.
2983 *
2984 * @cliexpar
2985 * Example of how to display local protocol table:
2986 * @cliexstart{show ip6 local}
2987 * Protocols handled by ip6_local
2988 * 17
2989 * 43
2990 * 58
2991 * 115
2992 * @cliexend
2993?*/
Dave Barachd7cb1b52016-12-09 09:52:16 -05002994VLIB_CLI_COMMAND (show_ip6_local, static) =
2995{
Ed Warnickecb9cada2015-12-08 15:45:58 -07002996 .path = "show ip6 local",
2997 .function = show_ip6_local_command_fn,
Billy McFall0683c9c2016-10-13 08:27:31 -04002998 .short_help = "show ip6 local",
Ed Warnickecb9cada2015-12-08 15:45:58 -07002999};
3000
Damjan Marion38173502019-02-13 19:30:09 +01003001#ifndef CLIB_MARCH_VARIANT
Dave Barachd7cb1b52016-12-09 09:52:16 -05003002int
Mohsin Kazmi68095382021-02-10 11:26:24 +01003003vnet_set_ip6_classify_intfc (vlib_main_t *vm, u32 sw_if_index, u32 table_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003004{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003005 vnet_main_t *vnm = vnet_get_main ();
3006 vnet_interface_main_t *im = &vnm->interface_main;
3007 ip6_main_t *ipm = &ip6_main;
3008 ip_lookup_main_t *lm = &ipm->lookup_main;
3009 vnet_classify_main_t *cm = &vnet_classify_main;
Neale Rannsdf089a82016-10-02 16:39:06 +01003010 ip6_address_t *if_addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003011
3012 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
3013 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
3014
3015 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
3016 return VNET_API_ERROR_NO_SUCH_ENTRY;
3017
3018 vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003019 lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003020
Neale Ranns6cfc39c2017-02-14 01:44:25 -08003021 if_addr = ip6_interface_first_address (ipm, sw_if_index);
Neale Rannsdf089a82016-10-02 16:39:06 +01003022
3023 if (NULL != if_addr)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003024 {
Neale Rannsdf089a82016-10-02 16:39:06 +01003025 fib_prefix_t pfx = {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003026 .fp_len = 128,
3027 .fp_proto = FIB_PROTOCOL_IP6,
3028 .fp_addr.ip6 = *if_addr,
Neale Rannsdf089a82016-10-02 16:39:06 +01003029 };
3030 u32 fib_index;
3031
Dave Barachd7cb1b52016-12-09 09:52:16 -05003032 fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
3033 sw_if_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003034 if (table_index != (u32) ~ 0)
3035 {
3036 dpo_id_t dpo = DPO_INVALID;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003037 dpo_set (&dpo,
3038 DPO_CLASSIFY,
3039 DPO_PROTO_IP6,
3040 classify_dpo_create (DPO_PROTO_IP6, table_index));
Dave Barachd7cb1b52016-12-09 09:52:16 -05003041 fib_table_entry_special_dpo_add (fib_index,
3042 &pfx,
3043 FIB_SOURCE_CLASSIFY,
3044 FIB_ENTRY_FLAG_NONE, &dpo);
3045 dpo_reset (&dpo);
3046 }
Neale Rannsdf089a82016-10-02 16:39:06 +01003047 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05003048 {
3049 fib_table_entry_special_remove (fib_index,
3050 &pfx, FIB_SOURCE_CLASSIFY);
3051 }
3052 }
Neale Rannsdf089a82016-10-02 16:39:06 +01003053
Ed Warnickecb9cada2015-12-08 15:45:58 -07003054 return 0;
3055}
Damjan Marion38173502019-02-13 19:30:09 +01003056#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -07003057
3058static clib_error_t *
3059set_ip6_classify_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003060 unformat_input_t * input,
3061 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003062{
3063 u32 table_index = ~0;
3064 int table_index_set = 0;
3065 u32 sw_if_index = ~0;
3066 int rv;
Dave Barach75fc8542016-10-11 16:16:02 -04003067
Dave Barachd7cb1b52016-12-09 09:52:16 -05003068 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3069 {
3070 if (unformat (input, "table-index %d", &table_index))
3071 table_index_set = 1;
3072 else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
3073 vnet_get_main (), &sw_if_index))
3074 ;
3075 else
3076 break;
3077 }
Dave Barach75fc8542016-10-11 16:16:02 -04003078
Ed Warnickecb9cada2015-12-08 15:45:58 -07003079 if (table_index_set == 0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003080 return clib_error_return (0, "classify table-index must be specified");
Dave Barach75fc8542016-10-11 16:16:02 -04003081
Ed Warnickecb9cada2015-12-08 15:45:58 -07003082 if (sw_if_index == ~0)
3083 return clib_error_return (0, "interface / subif must be specified");
3084
3085 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3086
3087 switch (rv)
3088 {
3089 case 0:
3090 break;
3091
3092 case VNET_API_ERROR_NO_MATCHING_INTERFACE:
3093 return clib_error_return (0, "No such interface");
3094
3095 case VNET_API_ERROR_NO_SUCH_ENTRY:
3096 return clib_error_return (0, "No such classifier table");
3097 }
3098 return 0;
3099}
3100
Billy McFall0683c9c2016-10-13 08:27:31 -04003101/*?
3102 * Assign a classification table to an interface. The classification
3103 * table is created using the '<em>classify table</em>' and '<em>classify session</em>'
3104 * commands. Once the table is create, use this command to filter packets
3105 * on an interface.
3106 *
3107 * @cliexpar
3108 * Example of how to assign a classification table to an interface:
3109 * @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1}
3110?*/
Dave Barachd7cb1b52016-12-09 09:52:16 -05003111VLIB_CLI_COMMAND (set_ip6_classify_command, static) =
3112{
3113 .path = "set ip6 classify",
3114 .short_help =
3115 "set ip6 classify intfc <interface> table-index <classify-idx>",
3116 .function = set_ip6_classify_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003117};
3118
Dave Barachd7cb1b52016-12-09 09:52:16 -05003119/*
3120 * fd.io coding-style-patch-verification: ON
3121 *
3122 * Local Variables:
3123 * eval: (c-set-style "gnu")
3124 * End:
3125 */