blob: 5a176435510837eabb1ba037ddec57c51d612bf0 [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>
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +020043#include <vnet/ip/ip6_neighbor.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>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010051#include <vnet/dpo/classify_dpo.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070052
53#include <vppinfra/bihash_template.c>
Vijayabhaskar Katamreddyacbde662018-01-23 13:39:40 -080054#include <vnet/ip/ip6_forward.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070055
AkshayaNadahallifdd81af2016-12-01 16:33:51 +053056/* Flag used by IOAM code. Classifier sets it pop-hop-by-hop checks it */
57#define OI_DECAP 0x80000000
58
Ed Warnickecb9cada2015-12-08 15:45:58 -070059static void
60ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index,
61 ip6_main_t * im, u32 fib_index,
62 ip_interface_address_t * a)
63{
Dave Barachd7cb1b52016-12-09 09:52:16 -050064 ip_lookup_main_t *lm = &im->lookup_main;
65 ip6_address_t *address = ip_interface_address_get_address (lm, a);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010066 fib_prefix_t pfx = {
Dave Barachd7cb1b52016-12-09 09:52:16 -050067 .fp_len = a->address_length,
68 .fp_proto = FIB_PROTOCOL_IP6,
69 .fp_addr.ip6 = *address,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010070 };
Ed Warnickecb9cada2015-12-08 15:45:58 -070071
Ed Warnickecb9cada2015-12-08 15:45:58 -070072 if (a->address_length < 128)
Dave Barachd7cb1b52016-12-09 09:52:16 -050073 {
Neale Ranns7a272742017-05-30 02:08:14 -070074 fib_table_entry_update_one_path (fib_index,
75 &pfx,
76 FIB_SOURCE_INTERFACE,
77 (FIB_ENTRY_FLAG_CONNECTED |
78 FIB_ENTRY_FLAG_ATTACHED),
Neale Rannsda78f952017-05-24 09:15:43 -070079 DPO_PROTO_IP6,
Neale Ranns7a272742017-05-30 02:08:14 -070080 /* No next-hop address */
81 NULL, sw_if_index,
82 /* invalid FIB index */
83 ~0, 1,
84 /* no label stack */
85 NULL, FIB_ROUTE_PATH_FLAG_NONE);
Dave Barachd7cb1b52016-12-09 09:52:16 -050086 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070087
Neale Ranns0bfe5d82016-08-25 15:29:12 +010088 pfx.fp_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070089 if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
Dave Barachd7cb1b52016-12-09 09:52:16 -050090 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +010091 u32 classify_table_index =
Dave Barachd7cb1b52016-12-09 09:52:16 -050092 lm->classify_table_index_by_sw_if_index[sw_if_index];
93 if (classify_table_index != (u32) ~ 0)
94 {
95 dpo_id_t dpo = DPO_INVALID;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010096
Dave Barachd7cb1b52016-12-09 09:52:16 -050097 dpo_set (&dpo,
98 DPO_CLASSIFY,
99 DPO_PROTO_IP6,
100 classify_dpo_create (DPO_PROTO_IP6, classify_table_index));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100101
Dave Barachd7cb1b52016-12-09 09:52:16 -0500102 fib_table_entry_special_dpo_add (fib_index,
103 &pfx,
104 FIB_SOURCE_CLASSIFY,
105 FIB_ENTRY_FLAG_NONE, &dpo);
106 dpo_reset (&dpo);
107 }
108 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100109
Neale Rannsf12a83f2017-04-18 09:09:40 -0700110 fib_table_entry_update_one_path (fib_index, &pfx,
111 FIB_SOURCE_INTERFACE,
112 (FIB_ENTRY_FLAG_CONNECTED |
113 FIB_ENTRY_FLAG_LOCAL),
Neale Rannsda78f952017-05-24 09:15:43 -0700114 DPO_PROTO_IP6,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700115 &pfx.fp_addr,
116 sw_if_index, ~0,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500117 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118}
119
120static void
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100121ip6_del_interface_routes (ip6_main_t * im,
122 u32 fib_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500123 ip6_address_t * address, u32 address_length)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500125 fib_prefix_t pfx = {
126 .fp_len = address_length,
127 .fp_proto = FIB_PROTOCOL_IP6,
128 .fp_addr.ip6 = *address,
129 };
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130
Dave Barachd7cb1b52016-12-09 09:52:16 -0500131 if (pfx.fp_len < 128)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500133 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100134
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135 }
136
Dave Barachd7cb1b52016-12-09 09:52:16 -0500137 pfx.fp_len = 128;
138 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139}
140
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100141void
Dave Barachd7cb1b52016-12-09 09:52:16 -0500142ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100143{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500144 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100146 vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100148 /*
149 * enable/disable only on the 1<->0 transition
150 */
151 if (is_enable)
152 {
153 if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index])
Dave Barachd7cb1b52016-12-09 09:52:16 -0500154 return;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100155 }
156 else
157 {
Neale Ranns75152282017-01-09 01:00:45 -0800158 /* The ref count is 0 when an address is removed from an interface that has
159 * no address - this is not a ciritical error */
160 if (0 == im->ip_enabled_by_sw_if_index[sw_if_index] ||
161 0 != --im->ip_enabled_by_sw_if_index[sw_if_index])
Dave Barachd7cb1b52016-12-09 09:52:16 -0500162 return;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100163 }
164
Neale Ranns8269d3d2018-01-30 09:02:20 -0800165 vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
Neale Ranns630198f2017-05-22 09:20:20 -0400166 !is_enable, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100167
Neale Ranns8269d3d2018-01-30 09:02:20 -0800168 vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
169 sw_if_index, !is_enable, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100170}
171
Neale Rannsdf089a82016-10-02 16:39:06 +0100172/* get first interface address */
173ip6_address_t *
Neale Ranns6cfc39c2017-02-14 01:44:25 -0800174ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
Neale Rannsdf089a82016-10-02 16:39:06 +0100175{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500176 ip_lookup_main_t *lm = &im->lookup_main;
177 ip_interface_address_t *ia = 0;
178 ip6_address_t *result = 0;
Neale Rannsdf089a82016-10-02 16:39:06 +0100179
Dave Barachd7cb1b52016-12-09 09:52:16 -0500180 /* *INDENT-OFF* */
Neale Rannsdf089a82016-10-02 16:39:06 +0100181 foreach_ip_interface_address (lm, ia, sw_if_index,
182 1 /* honor unnumbered */,
183 ({
184 ip6_address_t * a = ip_interface_address_get_address (lm, ia);
185 result = a;
186 break;
187 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500188 /* *INDENT-ON* */
Neale Rannsdf089a82016-10-02 16:39:06 +0100189 return result;
190}
191
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100192clib_error_t *
193ip6_add_del_interface_address (vlib_main_t * vm,
194 u32 sw_if_index,
195 ip6_address_t * address,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500196 u32 address_length, u32 is_del)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500198 vnet_main_t *vnm = vnet_get_main ();
199 ip6_main_t *im = &ip6_main;
200 ip_lookup_main_t *lm = &im->lookup_main;
201 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202 u32 if_address_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500203 ip6_address_fib_t ip6_af, *addr_fib = 0;
Juraj Sloboda5bb1eca2018-10-22 09:57:13 +0200204 ip6_address_t ll_addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700205
Pavel Kotucek57808982017-08-02 08:20:19 +0200206 /* local0 interface doesn't support IP addressing */
207 if (sw_if_index == 0)
208 {
209 return
210 clib_error_create ("local0 interface doesn't support IP addressing");
211 }
212
Juraj Sloboda5bb1eca2018-10-22 09:57:13 +0200213 if (ip6_address_is_link_local_unicast (address))
214 {
215 if (address_length != 128)
216 {
217 vnm->api_errno = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
218 return
219 clib_error_create
220 ("prefix length of link-local address must be 128");
221 }
222 if (!is_del)
223 {
224 return ip6_neighbor_set_link_local_address (vm, sw_if_index,
225 address);
226 }
227 else
228 {
229 ll_addr = ip6_neighbor_get_link_local_address (sw_if_index);
230 if (ip6_address_is_equal (&ll_addr, address))
231 {
232 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_DELETABLE;
233 return clib_error_create ("address not deletable");
234 }
235 else
236 {
237 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
238 return clib_error_create ("address not found");
239 }
240 }
241 }
242
Ed Warnickecb9cada2015-12-08 15:45:58 -0700243 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000244 vec_validate (im->mfib_index_by_sw_if_index, sw_if_index);
245
Ed Warnickecb9cada2015-12-08 15:45:58 -0700246 ip6_addr_fib_init (&ip6_af, address,
247 vec_elt (im->fib_index_by_sw_if_index, sw_if_index));
248 vec_add1 (addr_fib, ip6_af);
249
Neale Ranns744902e2017-08-14 10:35:44 -0700250 /* *INDENT-OFF* */
251 if (!is_del)
252 {
253 /* When adding an address check that it does not conflict
254 with an existing address on any interface in this table. */
255 ip_interface_address_t *ia;
256 vnet_sw_interface_t *sif;
257
258 pool_foreach(sif, vnm->interface_main.sw_interfaces,
259 ({
260 if (im->fib_index_by_sw_if_index[sw_if_index] ==
261 im->fib_index_by_sw_if_index[sif->sw_if_index])
262 {
263 foreach_ip_interface_address
264 (&im->lookup_main, ia, sif->sw_if_index,
265 0 /* honor unnumbered */ ,
266 ({
267 ip6_address_t * x =
268 ip_interface_address_get_address
269 (&im->lookup_main, ia);
270 if (ip6_destination_matches_route
271 (im, address, x, ia->address_length) ||
272 ip6_destination_matches_route (im,
273 x,
274 address,
275 address_length))
276 {
277 vnm->api_errno = VNET_API_ERROR_DUPLICATE_IF_ADDRESS;
278 return
279 clib_error_create
280 ("failed to add %U which conflicts with %U for interface %U",
281 format_ip6_address_and_length, address,
282 address_length,
283 format_ip6_address_and_length, x,
284 ia->address_length,
285 format_vnet_sw_if_index_name, vnm,
286 sif->sw_if_index);
287 }
288 }));
289 }
290 }));
291 }
292 /* *INDENT-ON* */
293
Ed Warnickecb9cada2015-12-08 15:45:58 -0700294 {
295 uword elts_before = pool_elts (lm->if_address_pool);
296
297 error = ip_interface_address_add_del
Dave Barachd7cb1b52016-12-09 09:52:16 -0500298 (lm, sw_if_index, addr_fib, address_length, is_del, &if_address_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700299 if (error)
300 goto done;
301
302 /* Pool did not grow: add duplicate address. */
303 if (elts_before == pool_elts (lm->if_address_pool))
304 goto done;
305 }
306
Dave Barachd7cb1b52016-12-09 09:52:16 -0500307 ip6_sw_interface_enable_disable (sw_if_index, !is_del);
Neale Ranns177bbdc2016-11-15 09:46:51 +0000308
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100309 if (is_del)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500310 ip6_del_interface_routes (im, ip6_af.fib_index, address, address_length);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100311 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500312 ip6_add_interface_routes (vnm, sw_if_index,
313 im, ip6_af.fib_index,
314 pool_elt_at_index (lm->if_address_pool,
315 if_address_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700316
317 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500318 ip6_add_del_interface_address_callback_t *cb;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700319 vec_foreach (cb, im->add_del_interface_address_callbacks)
320 cb->function (im, cb->function_opaque, sw_if_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500321 address, address_length, if_address_index, is_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700322 }
323
Dave Barachd7cb1b52016-12-09 09:52:16 -0500324done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700325 vec_free (addr_fib);
326 return error;
327}
328
329clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500330ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500332 ip6_main_t *im = &ip6_main;
333 ip_interface_address_t *ia;
334 ip6_address_t *a;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700335 u32 is_admin_up, fib_index;
336
337 /* Fill in lookup tables with default table (0). */
338 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
339
Dave Barachd7cb1b52016-12-09 09:52:16 -0500340 vec_validate_init_empty (im->
341 lookup_main.if_address_pool_index_by_sw_if_index,
342 sw_if_index, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700343
344 is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
345
346 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
347
Dave Barachd7cb1b52016-12-09 09:52:16 -0500348 /* *INDENT-OFF* */
Dave Barach75fc8542016-10-11 16:16:02 -0400349 foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700350 0 /* honor unnumbered */,
351 ({
352 a = ip_interface_address_get_address (&im->lookup_main, ia);
353 if (is_admin_up)
354 ip6_add_interface_routes (vnm, sw_if_index,
355 im, fib_index,
356 ia);
357 else
358 ip6_del_interface_routes (im, fib_index,
359 a, ia->address_length);
360 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500361 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700362
363 return 0;
364}
365
366VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
367
Dave Barachd6534602016-06-14 18:38:02 -0400368/* Built-in ip6 unicast rx feature path definition */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500369/* *INDENT-OFF* */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100370VNET_FEATURE_ARC_INIT (ip6_unicast, static) =
371{
372 .arc_name = "ip6-unicast",
373 .start_nodes = VNET_FEATURES ("ip6-input"),
374 .arc_index_ptr = &ip6_main.lookup_main.ucast_feature_arc_index,
375};
376
Dave Barachd7cb1b52016-12-09 09:52:16 -0500377VNET_FEATURE_INIT (ip6_flow_classify, static) =
378{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100379 .arc_name = "ip6-unicast",
Juraj Sloboda506b2452016-08-07 23:45:24 -0700380 .node_name = "ip6-flow-classify",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100381 .runs_before = VNET_FEATURES ("ip6-inacl"),
Juraj Sloboda506b2452016-08-07 23:45:24 -0700382};
383
Dave Barachd7cb1b52016-12-09 09:52:16 -0500384VNET_FEATURE_INIT (ip6_inacl, static) =
385{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100386 .arc_name = "ip6-unicast",
Dave Barach75fc8542016-10-11 16:16:02 -0400387 .node_name = "ip6-inacl",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100388 .runs_before = VNET_FEATURES ("ip6-policer-classify"),
Dave Barachd6534602016-06-14 18:38:02 -0400389};
390
Dave Barachd7cb1b52016-12-09 09:52:16 -0500391VNET_FEATURE_INIT (ip6_policer_classify, static) =
392{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100393 .arc_name = "ip6-unicast",
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700394 .node_name = "ip6-policer-classify",
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200395 .runs_before = VNET_FEATURES ("ipsec6-input"),
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700396};
397
Dave Barachd7cb1b52016-12-09 09:52:16 -0500398VNET_FEATURE_INIT (ip6_ipsec, static) =
399{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100400 .arc_name = "ip6-unicast",
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200401 .node_name = "ipsec6-input",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100402 .runs_before = VNET_FEATURES ("l2tp-decap"),
Dave Barachd6534602016-06-14 18:38:02 -0400403};
404
Dave Barachd7cb1b52016-12-09 09:52:16 -0500405VNET_FEATURE_INIT (ip6_l2tp, static) =
406{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100407 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400408 .node_name = "l2tp-decap",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100409 .runs_before = VNET_FEATURES ("vpath-input-ip6"),
Dave Barachd6534602016-06-14 18:38:02 -0400410};
411
Dave Barachd7cb1b52016-12-09 09:52:16 -0500412VNET_FEATURE_INIT (ip6_vpath, static) =
413{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100414 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400415 .node_name = "vpath-input-ip6",
John Lo2b81eb82017-01-30 13:12:10 -0500416 .runs_before = VNET_FEATURES ("ip6-vxlan-bypass"),
417};
418
419VNET_FEATURE_INIT (ip6_vxlan_bypass, static) =
420{
421 .arc_name = "ip6-unicast",
422 .node_name = "ip6-vxlan-bypass",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100423 .runs_before = VNET_FEATURES ("ip6-lookup"),
Dave Barachd6534602016-06-14 18:38:02 -0400424};
425
Neale Ranns8269d3d2018-01-30 09:02:20 -0800426VNET_FEATURE_INIT (ip6_not_enabled, static) =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500427{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100428 .arc_name = "ip6-unicast",
Neale Ranns8269d3d2018-01-30 09:02:20 -0800429 .node_name = "ip6-not-enabled",
Neale Ranns630198f2017-05-22 09:20:20 -0400430 .runs_before = VNET_FEATURES ("ip6-lookup"),
431};
432
433VNET_FEATURE_INIT (ip6_lookup, static) =
434{
435 .arc_name = "ip6-unicast",
436 .node_name = "ip6-lookup",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100437 .runs_before = 0, /*last feature*/
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100438};
439
Dave Barachd6534602016-06-14 18:38:02 -0400440/* Built-in ip6 multicast rx feature path definition (none now) */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100441VNET_FEATURE_ARC_INIT (ip6_multicast, static) =
442{
443 .arc_name = "ip6-multicast",
444 .start_nodes = VNET_FEATURES ("ip6-input"),
445 .arc_index_ptr = &ip6_main.lookup_main.mcast_feature_arc_index,
446};
447
448VNET_FEATURE_INIT (ip6_vpath_mc, static) = {
449 .arc_name = "ip6-multicast",
Dave Barachd6534602016-06-14 18:38:02 -0400450 .node_name = "vpath-input-ip6",
Neale Ranns32e1c012016-11-22 17:07:28 +0000451 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
Dave Barachd6534602016-06-14 18:38:02 -0400452};
453
Neale Ranns8269d3d2018-01-30 09:02:20 -0800454VNET_FEATURE_INIT (ip6_not_enabled_mc, static) = {
Damjan Marion8b3191e2016-11-09 19:54:20 +0100455 .arc_name = "ip6-multicast",
Neale Ranns8269d3d2018-01-30 09:02:20 -0800456 .node_name = "ip6-not-enabled",
Neale Ranns630198f2017-05-22 09:20:20 -0400457 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
458};
459
460VNET_FEATURE_INIT (ip6_mc_lookup, static) = {
461 .arc_name = "ip6-multicast",
462 .node_name = "ip6-mfib-forward-lookup",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100463 .runs_before = 0, /* last feature */
Neale Ranns5e575b12016-10-03 09:40:25 +0100464};
Dave Barach5331c722016-08-17 11:54:30 -0400465
466/* Built-in ip4 tx feature path definition */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100467VNET_FEATURE_ARC_INIT (ip6_output, static) =
468{
469 .arc_name = "ip6-output",
Neale Rannsf068c3e2018-01-03 04:18:48 -0800470 .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain", "ip6-dvr-dpo"),
Damjan Marion8b3191e2016-11-09 19:54:20 +0100471 .arc_index_ptr = &ip6_main.lookup_main.output_feature_arc_index,
Dave Barach5331c722016-08-17 11:54:30 -0400472};
473
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100474VNET_FEATURE_INIT (ip6_outacl, static) = {
475 .arc_name = "ip6-output",
476 .node_name = "ip6-outacl",
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200477 .runs_before = VNET_FEATURES ("ipsec6-output"),
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100478};
479
Matus Fabian08a6f012016-11-15 06:08:51 -0800480VNET_FEATURE_INIT (ip6_ipsec_output, static) = {
481 .arc_name = "ip6-output",
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200482 .node_name = "ipsec6-output",
Matus Fabian08a6f012016-11-15 06:08:51 -0800483 .runs_before = VNET_FEATURES ("interface-output"),
484};
485
Damjan Marion8b3191e2016-11-09 19:54:20 +0100486VNET_FEATURE_INIT (ip6_interface_output, static) = {
487 .arc_name = "ip6-output",
488 .node_name = "interface-output",
489 .runs_before = 0, /* not before any other features */
490};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500491/* *INDENT-ON* */
Dave Barachd6534602016-06-14 18:38:02 -0400492
Ed Warnickecb9cada2015-12-08 15:45:58 -0700493clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500494ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700495{
Florin Corasb5c13fd2017-05-10 12:32:53 -0700496 ip6_main_t *im = &ip6_main;
497
498 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
499 vec_validate (im->mfib_index_by_sw_if_index, sw_if_index);
500
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +0200501 if (!is_add)
502 {
503 /* Ensure that IPv6 is disabled */
504 ip6_main_t *im6 = &ip6_main;
505 ip_lookup_main_t *lm6 = &im6->lookup_main;
506 ip_interface_address_t *ia = 0;
507 ip6_address_t *address;
508 vlib_main_t *vm = vlib_get_main ();
509
510 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, 0 /* is_add */ );
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700511 vnet_sw_interface_update_unnumbered (sw_if_index, ~0, 0);
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +0200512 /* *INDENT-OFF* */
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700513 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +0200514 ({
515 address = ip_interface_address_get_address (lm6, ia);
516 ip6_add_del_interface_address(vm, sw_if_index, address, ia->address_length, 1);
517 }));
518 /* *INDENT-ON* */
519 ip6_mfib_interface_enable_disable (sw_if_index, 0);
520 }
521
Neale Ranns8269d3d2018-01-30 09:02:20 -0800522 vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
Damjan Marion8b3191e2016-11-09 19:54:20 +0100523 is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700524
Neale Ranns8269d3d2018-01-30 09:02:20 -0800525 vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
526 sw_if_index, is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700527
Ed Warnickecb9cada2015-12-08 15:45:58 -0700528 return /* no error */ 0;
529}
530
531VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del);
532
Damjan Marionaca64c92016-04-13 09:48:56 +0200533static uword
534ip6_lookup (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500535 vlib_node_runtime_t * node, vlib_frame_t * frame)
Damjan Marionaca64c92016-04-13 09:48:56 +0200536{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100537 return ip6_lookup_inline (vm, node, frame);
Damjan Marionaca64c92016-04-13 09:48:56 +0200538}
539
Dave Barachd7cb1b52016-12-09 09:52:16 -0500540static u8 *format_ip6_lookup_trace (u8 * s, va_list * args);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100541
Dave Barachd7cb1b52016-12-09 09:52:16 -0500542/* *INDENT-OFF* */
543VLIB_REGISTER_NODE (ip6_lookup_node) =
544{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700545 .function = ip6_lookup,
546 .name = "ip6-lookup",
547 .vector_size = sizeof (u32),
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100548 .format_trace = format_ip6_lookup_trace,
Ole Troanf0f85222016-06-14 21:12:32 +0200549 .n_next_nodes = IP6_LOOKUP_N_NEXT,
Damjan Marionb2707892016-04-13 11:21:07 +0200550 .next_nodes = IP6_LOOKUP_NEXT_NODES,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700551};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500552/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700553
Dave Barachd7cb1b52016-12-09 09:52:16 -0500554VLIB_NODE_FUNCTION_MULTIARCH (ip6_lookup_node, ip6_lookup);
Damjan Marion1c80e832016-05-11 23:07:18 +0200555
Damjan Marion2574d9f2018-06-26 14:45:49 +0200556static uword
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100557ip6_load_balance (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500558 vlib_node_runtime_t * node, vlib_frame_t * frame)
Damjan Marionaca64c92016-04-13 09:48:56 +0200559{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500560 vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters;
561 u32 n_left_from, n_left_to_next, *from, *to_next;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100562 ip_lookup_next_t next;
Damjan Marion067cd622018-07-11 12:47:43 +0200563 u32 thread_index = vm->thread_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500564 ip6_main_t *im = &ip6_main;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100565
566 from = vlib_frame_vector_args (frame);
567 n_left_from = frame->n_vectors;
568 next = node->cached_next_index;
569
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100570 while (n_left_from > 0)
571 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500572 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100573
Dave Barach75fc8542016-10-11 16:16:02 -0400574
Neale Ranns2be95c12016-11-19 13:50:04 +0000575 while (n_left_from >= 4 && n_left_to_next >= 2)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500576 {
577 ip_lookup_next_t next0, next1;
578 const load_balance_t *lb0, *lb1;
579 vlib_buffer_t *p0, *p1;
580 u32 pi0, lbi0, hc0, pi1, lbi1, hc1;
581 const ip6_header_t *ip0, *ip1;
582 const dpo_id_t *dpo0, *dpo1;
Neale Ranns2be95c12016-11-19 13:50:04 +0000583
Dave Barachd7cb1b52016-12-09 09:52:16 -0500584 /* Prefetch next iteration. */
585 {
586 vlib_buffer_t *p2, *p3;
Neale Ranns2be95c12016-11-19 13:50:04 +0000587
Dave Barachd7cb1b52016-12-09 09:52:16 -0500588 p2 = vlib_get_buffer (vm, from[2]);
589 p3 = vlib_get_buffer (vm, from[3]);
Neale Ranns2be95c12016-11-19 13:50:04 +0000590
Dave Barachd7cb1b52016-12-09 09:52:16 -0500591 vlib_prefetch_buffer_header (p2, STORE);
592 vlib_prefetch_buffer_header (p3, STORE);
Neale Ranns2be95c12016-11-19 13:50:04 +0000593
Dave Barachd7cb1b52016-12-09 09:52:16 -0500594 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
595 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
596 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000597
Dave Barachd7cb1b52016-12-09 09:52:16 -0500598 pi0 = to_next[0] = from[0];
599 pi1 = to_next[1] = from[1];
Neale Ranns2be95c12016-11-19 13:50:04 +0000600
Dave Barachd7cb1b52016-12-09 09:52:16 -0500601 from += 2;
602 n_left_from -= 2;
603 to_next += 2;
604 n_left_to_next -= 2;
Neale Ranns2be95c12016-11-19 13:50:04 +0000605
Dave Barachd7cb1b52016-12-09 09:52:16 -0500606 p0 = vlib_get_buffer (vm, pi0);
607 p1 = vlib_get_buffer (vm, pi1);
Neale Ranns2be95c12016-11-19 13:50:04 +0000608
Dave Barachd7cb1b52016-12-09 09:52:16 -0500609 ip0 = vlib_buffer_get_current (p0);
610 ip1 = vlib_buffer_get_current (p1);
611 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
612 lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
Neale Ranns2be95c12016-11-19 13:50:04 +0000613
Dave Barachd7cb1b52016-12-09 09:52:16 -0500614 lb0 = load_balance_get (lbi0);
615 lb1 = load_balance_get (lbi1);
Neale Ranns2be95c12016-11-19 13:50:04 +0000616
Dave Barachd7cb1b52016-12-09 09:52:16 -0500617 /*
618 * this node is for via FIBs we can re-use the hash value from the
619 * to node if present.
620 * We don't want to use the same hash value at each level in the recursion
621 * graph as that would lead to polarisation
622 */
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000623 hc0 = hc1 = 0;
Neale Ranns2be95c12016-11-19 13:50:04 +0000624
Dave Barachd7cb1b52016-12-09 09:52:16 -0500625 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
626 {
627 if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
628 {
629 hc0 = vnet_buffer (p0)->ip.flow_hash =
630 vnet_buffer (p0)->ip.flow_hash >> 1;
631 }
632 else
633 {
634 hc0 = vnet_buffer (p0)->ip.flow_hash =
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000635 ip6_compute_flow_hash (ip0, lb0->lb_hash_config);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500636 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700637 dpo0 =
638 load_balance_get_fwd_bucket (lb0,
639 (hc0 &
640 lb0->lb_n_buckets_minus_1));
641 }
642 else
643 {
644 dpo0 = load_balance_get_bucket_i (lb0, 0);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500645 }
646 if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
647 {
648 if (PREDICT_TRUE (vnet_buffer (p1)->ip.flow_hash))
649 {
650 hc1 = vnet_buffer (p1)->ip.flow_hash =
651 vnet_buffer (p1)->ip.flow_hash >> 1;
652 }
653 else
654 {
655 hc1 = vnet_buffer (p1)->ip.flow_hash =
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000656 ip6_compute_flow_hash (ip1, lb1->lb_hash_config);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500657 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700658 dpo1 =
659 load_balance_get_fwd_bucket (lb1,
660 (hc1 &
661 lb1->lb_n_buckets_minus_1));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500662 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700663 else
664 {
665 dpo1 = load_balance_get_bucket_i (lb1, 0);
666 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000667
Dave Barachd7cb1b52016-12-09 09:52:16 -0500668 next0 = dpo0->dpoi_next_node;
669 next1 = dpo1->dpoi_next_node;
Neale Ranns2be95c12016-11-19 13:50:04 +0000670
Dave Barachd7cb1b52016-12-09 09:52:16 -0500671 /* Only process the HBH Option Header if explicitly configured to do so */
672 if (PREDICT_FALSE
673 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
674 {
675 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
676 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
677 }
678 /* Only process the HBH Option Header if explicitly configured to do so */
679 if (PREDICT_FALSE
680 (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
681 {
682 next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
683 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1;
684 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000685
Dave Barachd7cb1b52016-12-09 09:52:16 -0500686 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
687 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
Neale Ranns2be95c12016-11-19 13:50:04 +0000688
Dave Barachd7cb1b52016-12-09 09:52:16 -0500689 vlib_increment_combined_counter
Damjan Marion586afd72017-04-05 19:18:20 +0200690 (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500691 vlib_increment_combined_counter
Damjan Marion586afd72017-04-05 19:18:20 +0200692 (cm, thread_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
Neale Ranns2be95c12016-11-19 13:50:04 +0000693
Dave Barachd7cb1b52016-12-09 09:52:16 -0500694 vlib_validate_buffer_enqueue_x2 (vm, node, next,
695 to_next, n_left_to_next,
696 pi0, pi1, next0, next1);
697 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000698
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100699 while (n_left_from > 0 && n_left_to_next > 0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500700 {
701 ip_lookup_next_t next0;
702 const load_balance_t *lb0;
703 vlib_buffer_t *p0;
704 u32 pi0, lbi0, hc0;
705 const ip6_header_t *ip0;
706 const dpo_id_t *dpo0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100707
Dave Barachd7cb1b52016-12-09 09:52:16 -0500708 pi0 = from[0];
709 to_next[0] = pi0;
710 from += 1;
711 to_next += 1;
712 n_left_to_next -= 1;
713 n_left_from -= 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100714
Dave Barachd7cb1b52016-12-09 09:52:16 -0500715 p0 = vlib_get_buffer (vm, pi0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100716
Dave Barachd7cb1b52016-12-09 09:52:16 -0500717 ip0 = vlib_buffer_get_current (p0);
718 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100719
Dave Barachd7cb1b52016-12-09 09:52:16 -0500720 lb0 = load_balance_get (lbi0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100721
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000722 hc0 = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500723 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
724 {
725 if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
726 {
727 hc0 = vnet_buffer (p0)->ip.flow_hash =
728 vnet_buffer (p0)->ip.flow_hash >> 1;
729 }
730 else
731 {
732 hc0 = vnet_buffer (p0)->ip.flow_hash =
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000733 ip6_compute_flow_hash (ip0, lb0->lb_hash_config);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500734 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700735 dpo0 =
736 load_balance_get_fwd_bucket (lb0,
737 (hc0 &
738 lb0->lb_n_buckets_minus_1));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500739 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700740 else
741 {
742 dpo0 = load_balance_get_bucket_i (lb0, 0);
743 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100744
Dave Barachd7cb1b52016-12-09 09:52:16 -0500745 next0 = dpo0->dpoi_next_node;
746 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
Neale Ranns2be95c12016-11-19 13:50:04 +0000747
Dave Barachd7cb1b52016-12-09 09:52:16 -0500748 /* Only process the HBH Option Header if explicitly configured to do so */
749 if (PREDICT_FALSE
750 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
751 {
752 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
753 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
754 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000755
Dave Barachd7cb1b52016-12-09 09:52:16 -0500756 vlib_increment_combined_counter
Damjan Marion586afd72017-04-05 19:18:20 +0200757 (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100758
Dave Barachd7cb1b52016-12-09 09:52:16 -0500759 vlib_validate_buffer_enqueue_x1 (vm, node, next,
760 to_next, n_left_to_next,
761 pi0, next0);
762 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100763
764 vlib_put_next_frame (vm, node, next, n_left_to_next);
765 }
766
Neale Rannsa71844f2018-11-08 07:31:36 -0800767 if (node->flags & VLIB_NODE_FLAG_TRACE)
768 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
769
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100770 return frame->n_vectors;
Damjan Marionaca64c92016-04-13 09:48:56 +0200771}
772
Dave Barachd7cb1b52016-12-09 09:52:16 -0500773/* *INDENT-OFF* */
774VLIB_REGISTER_NODE (ip6_load_balance_node) =
775{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100776 .function = ip6_load_balance,
777 .name = "ip6-load-balance",
Damjan Marionaca64c92016-04-13 09:48:56 +0200778 .vector_size = sizeof (u32),
Ole Troanf0f85222016-06-14 21:12:32 +0200779 .sibling_of = "ip6-lookup",
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100780 .format_trace = format_ip6_lookup_trace,
Damjan Marionaca64c92016-04-13 09:48:56 +0200781};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500782/* *INDENT-ON* */
Damjan Marionaca64c92016-04-13 09:48:56 +0200783
Dave Barachd7cb1b52016-12-09 09:52:16 -0500784VLIB_NODE_FUNCTION_MULTIARCH (ip6_load_balance_node, ip6_load_balance);
Damjan Marion1c80e832016-05-11 23:07:18 +0200785
Dave Barachd7cb1b52016-12-09 09:52:16 -0500786typedef struct
787{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700788 /* Adjacency taken. */
789 u32 adj_index;
790 u32 flow_hash;
John Lo2d343742016-01-19 17:27:17 -0500791 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700792
793 /* Packet data, possibly *after* rewrite. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500794 u8 packet_data[128 - 1 * sizeof (u32)];
795}
796ip6_forward_next_trace_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700797
John Lo2b81eb82017-01-30 13:12:10 -0500798u8 *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500799format_ip6_forward_next_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700800{
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100801 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
802 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500803 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200804 u32 indent = format_get_indent (s);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100805
Dave Barachd7cb1b52016-12-09 09:52:16 -0500806 s = format (s, "%U%U",
807 format_white_space, indent,
808 format_ip6_header, t->packet_data, sizeof (t->packet_data));
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100809 return s;
810}
811
Dave Barachd7cb1b52016-12-09 09:52:16 -0500812static u8 *
813format_ip6_lookup_trace (u8 * s, va_list * args)
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100814{
815 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
816 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500817 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200818 u32 indent = format_get_indent (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700819
John Loac8146c2016-09-27 17:44:02 -0400820 s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500821 t->fib_index, t->adj_index, t->flow_hash);
822 s = format (s, "\n%U%U",
823 format_white_space, indent,
824 format_ip6_header, t->packet_data, sizeof (t->packet_data));
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100825 return s;
826}
Pierre Pfister0febaf12016-06-08 12:23:21 +0100827
Ed Warnickecb9cada2015-12-08 15:45:58 -0700828
Dave Barachd7cb1b52016-12-09 09:52:16 -0500829static u8 *
830format_ip6_rewrite_trace (u8 * s, va_list * args)
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100831{
832 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
833 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500834 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200835 u32 indent = format_get_indent (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100837 s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500838 t->fib_index, t->adj_index, format_ip_adjacency,
839 t->adj_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100840 s = format (s, "\n%U%U",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500841 format_white_space, indent,
842 format_ip_adjacency_packet_data,
Neale Rannsb069a692017-03-15 12:34:25 -0400843 t->adj_index, t->packet_data, sizeof (t->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700844 return s;
845}
846
847/* Common trace function for all ip6-forward next nodes. */
848void
849ip6_forward_next_trace (vlib_main_t * vm,
850 vlib_node_runtime_t * node,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500851 vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700852{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500853 u32 *from, n_left;
854 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700855
856 n_left = frame->n_vectors;
857 from = vlib_frame_vector_args (frame);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100858
Ed Warnickecb9cada2015-12-08 15:45:58 -0700859 while (n_left >= 4)
860 {
861 u32 bi0, bi1;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500862 vlib_buffer_t *b0, *b1;
863 ip6_forward_next_trace_t *t0, *t1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700864
865 /* Prefetch next iteration. */
866 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
867 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
868
869 bi0 = from[0];
870 bi1 = from[1];
871
872 b0 = vlib_get_buffer (vm, bi0);
873 b1 = vlib_get_buffer (vm, bi1);
874
875 if (b0->flags & VLIB_BUFFER_IS_TRACED)
876 {
877 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
878 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500879 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
880 t0->fib_index =
881 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
882 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
883 vec_elt (im->fib_index_by_sw_if_index,
884 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100885
Dave Barach178cf492018-11-13 16:34:13 -0500886 clib_memcpy_fast (t0->packet_data,
887 vlib_buffer_get_current (b0),
888 sizeof (t0->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700889 }
890 if (b1->flags & VLIB_BUFFER_IS_TRACED)
891 {
892 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
893 t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500894 t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
895 t1->fib_index =
896 (vnet_buffer (b1)->sw_if_index[VLIB_TX] !=
897 (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] :
898 vec_elt (im->fib_index_by_sw_if_index,
899 vnet_buffer (b1)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100900
Dave Barach178cf492018-11-13 16:34:13 -0500901 clib_memcpy_fast (t1->packet_data,
902 vlib_buffer_get_current (b1),
903 sizeof (t1->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700904 }
905 from += 2;
906 n_left -= 2;
907 }
908
909 while (n_left >= 1)
910 {
911 u32 bi0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500912 vlib_buffer_t *b0;
913 ip6_forward_next_trace_t *t0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700914
915 bi0 = from[0];
916
917 b0 = vlib_get_buffer (vm, bi0);
918
919 if (b0->flags & VLIB_BUFFER_IS_TRACED)
920 {
921 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
922 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500923 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
924 t0->fib_index =
925 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
926 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
927 vec_elt (im->fib_index_by_sw_if_index,
928 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100929
Dave Barach178cf492018-11-13 16:34:13 -0500930 clib_memcpy_fast (t0->packet_data,
931 vlib_buffer_get_current (b0),
932 sizeof (t0->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700933 }
934 from += 1;
935 n_left -= 1;
936 }
937}
938
Ed Warnickecb9cada2015-12-08 15:45:58 -0700939/* Compute TCP/UDP/ICMP6 checksum in software. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500940u16
941ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
942 ip6_header_t * ip0, int *bogus_lengthp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700943{
944 ip_csum_t sum0;
945 u16 sum16, payload_length_host_byte_order;
946 u32 i, n_this_buffer, n_bytes_left;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500947 u32 headers_size = sizeof (ip0[0]);
948 void *data_this_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700949
Dave Barachd7cb1b52016-12-09 09:52:16 -0500950 ASSERT (bogus_lengthp);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700951 *bogus_lengthp = 0;
952
953 /* Initialize checksum with ip header. */
954 sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol);
955 payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
956 data_this_buffer = (void *) (ip0 + 1);
Dave Barach75fc8542016-10-11 16:16:02 -0400957
Ed Warnickecb9cada2015-12-08 15:45:58 -0700958 for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
959 {
960 sum0 = ip_csum_with_carry (sum0,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500961 clib_mem_unaligned (&ip0->
962 src_address.as_uword[i],
963 uword));
964 sum0 =
965 ip_csum_with_carry (sum0,
966 clib_mem_unaligned (&ip0->dst_address.as_uword[i],
967 uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968 }
969
AkshayaNadahalli1b563522017-01-23 22:05:35 +0530970 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets)
971 * or UDP-Ping packets */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500972 if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700973 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500974 u32 skip_bytes;
975 ip6_hop_by_hop_ext_t *ext_hdr =
976 (ip6_hop_by_hop_ext_t *) data_this_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977
978 /* validate really icmp6 next */
AkshayaNadahalli1b563522017-01-23 22:05:35 +0530979 ASSERT ((ext_hdr->next_hdr == IP_PROTOCOL_ICMP6)
980 || (ext_hdr->next_hdr == IP_PROTOCOL_UDP));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700981
Dave Barachd7cb1b52016-12-09 09:52:16 -0500982 skip_bytes = 8 * (1 + ext_hdr->n_data_u64s);
983 data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes);
Dave Barach75fc8542016-10-11 16:16:02 -0400984
Dave Barachd7cb1b52016-12-09 09:52:16 -0500985 payload_length_host_byte_order -= skip_bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700986 headers_size += skip_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500987 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700988
989 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500990 if (p0 && n_this_buffer + headers_size > p0->current_length)
991 n_this_buffer =
992 p0->current_length >
993 headers_size ? p0->current_length - headers_size : 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700994 while (1)
995 {
996 sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
997 n_bytes_left -= n_this_buffer;
998 if (n_bytes_left == 0)
999 break;
1000
1001 if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
Dave Barachd7cb1b52016-12-09 09:52:16 -05001002 {
1003 *bogus_lengthp = 1;
1004 return 0xfefe;
1005 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001006 p0 = vlib_get_buffer (vm, p0->next_buffer);
1007 data_this_buffer = vlib_buffer_get_current (p0);
1008 n_this_buffer = p0->current_length;
1009 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001010
Dave Barachd7cb1b52016-12-09 09:52:16 -05001011 sum16 = ~ip_csum_fold (sum0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001012
1013 return sum16;
1014}
1015
Dave Barachd7cb1b52016-12-09 09:52:16 -05001016u32
1017ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001018{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001019 ip6_header_t *ip0 = vlib_buffer_get_current (p0);
1020 udp_header_t *udp0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001021 u16 sum16;
1022 int bogus_length;
1023
1024 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
1025 ASSERT (ip0->protocol == IP_PROTOCOL_TCP
1026 || ip0->protocol == IP_PROTOCOL_ICMP6
1027 || ip0->protocol == IP_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001028 || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001029
1030 udp0 = (void *) (ip0 + 1);
1031 if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0)
1032 {
Damjan Marion213b5aa2017-07-13 21:19:27 +02001033 p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED
1034 | VNET_BUFFER_F_L4_CHECKSUM_CORRECT);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001035 return p0->flags;
1036 }
1037
1038 sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length);
1039
Damjan Marion213b5aa2017-07-13 21:19:27 +02001040 p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED
1041 | ((sum16 == 0) << VNET_BUFFER_F_LOG2_L4_CHECKSUM_CORRECT));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001042
1043 return p0->flags;
1044}
1045
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301046/**
1047 * @brief returns number of links on which src is reachable.
1048 */
1049always_inline int
1050ip6_urpf_loose_check (ip6_main_t * im, vlib_buffer_t * b, ip6_header_t * i)
1051{
1052 const load_balance_t *lb0;
1053 index_t lbi;
Florin Corasf3a3bad2018-03-28 02:18:29 -07001054 u32 fib_index;
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301055
Florin Corasf3a3bad2018-03-28 02:18:29 -07001056 fib_index = vec_elt (im->fib_index_by_sw_if_index,
1057 vnet_buffer (b)->sw_if_index[VLIB_RX]);
1058 fib_index =
1059 (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
1060 fib_index : vnet_buffer (b)->sw_if_index[VLIB_TX];
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301061
Florin Corasf3a3bad2018-03-28 02:18:29 -07001062 lbi = ip6_fib_table_fwding_lookup (im, fib_index, &i->src_address);
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301063 lb0 = load_balance_get (lbi);
1064
1065 return (fib_urpf_check_size (lb0->lb_urpf));
1066}
1067
rootc9d1c5b2017-08-15 12:58:31 -04001068always_inline u8
1069ip6_next_proto_is_tcp_udp (vlib_buffer_t * p0, ip6_header_t * ip0,
1070 u32 * udp_offset0)
1071{
1072 u32 proto0;
1073 proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_UDP, udp_offset0);
1074 if (proto0 != IP_PROTOCOL_UDP)
1075 {
1076 proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_TCP, udp_offset0);
1077 proto0 = (proto0 == IP_PROTOCOL_TCP) ? proto0 : 0;
1078 }
1079 return proto0;
1080}
1081
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001082/* *INDENT-OFF* */
1083VNET_FEATURE_ARC_INIT (ip6_local) =
1084{
1085 .arc_name = "ip6-local",
1086 .start_nodes = VNET_FEATURES ("ip6-local"),
1087};
1088/* *INDENT-ON* */
1089
Ed Warnickecb9cada2015-12-08 15:45:58 -07001090static uword
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001091ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1092 vlib_frame_t * frame, int head_of_feature_arc)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001093{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001094 ip6_main_t *im = &ip6_main;
1095 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001096 ip_local_next_t next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001097 u32 *from, *to_next, n_left_from, n_left_to_next;
1098 vlib_node_runtime_t *error_node =
1099 vlib_node_get_runtime (vm, ip6_input_node.index);
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001100 u8 arc_index = vnet_feat_arc_ip6_local.feature_arc_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001101
1102 from = vlib_frame_vector_args (frame);
1103 n_left_from = frame->n_vectors;
1104 next_index = node->cached_next_index;
Dave Barach75fc8542016-10-11 16:16:02 -04001105
Ed Warnickecb9cada2015-12-08 15:45:58 -07001106 if (node->flags & VLIB_NODE_FLAG_TRACE)
1107 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1108
1109 while (n_left_from > 0)
1110 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001111 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001112
1113 while (n_left_from >= 4 && n_left_to_next >= 2)
1114 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001115 vlib_buffer_t *p0, *p1;
1116 ip6_header_t *ip0, *ip1;
1117 udp_header_t *udp0, *udp1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001118 u32 pi0, ip_len0, udp_len0, flags0, next0;
1119 u32 pi1, ip_len1, udp_len1, flags1, next1;
1120 i32 len_diff0, len_diff1;
rootc9d1c5b2017-08-15 12:58:31 -04001121 u8 error0, type0, good_l4_csum0, is_tcp_udp0;
1122 u8 error1, type1, good_l4_csum1, is_tcp_udp1;
Shwethab78292e2016-09-13 11:51:00 +01001123 u32 udp_offset0, udp_offset1;
Dave Barach75fc8542016-10-11 16:16:02 -04001124
Ed Warnickecb9cada2015-12-08 15:45:58 -07001125 pi0 = to_next[0] = from[0];
1126 pi1 = to_next[1] = from[1];
1127 from += 2;
1128 n_left_from -= 2;
1129 to_next += 2;
1130 n_left_to_next -= 2;
Dave Barach75fc8542016-10-11 16:16:02 -04001131
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001132 error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL;
1133
Ed Warnickecb9cada2015-12-08 15:45:58 -07001134 p0 = vlib_get_buffer (vm, pi0);
1135 p1 = vlib_get_buffer (vm, pi1);
1136
1137 ip0 = vlib_buffer_get_current (p0);
1138 ip1 = vlib_buffer_get_current (p1);
1139
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001140 if (head_of_feature_arc == 0)
1141 goto skip_checks;
1142
Damjan Marion072401e2017-07-13 18:53:27 +02001143 vnet_buffer (p0)->l3_hdr_offset = p0->current_data;
1144 vnet_buffer (p1)->l3_hdr_offset = p1->current_data;
Filip Tehlarb601f222017-01-02 10:22:56 +01001145
Ed Warnickecb9cada2015-12-08 15:45:58 -07001146 type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
1147 type1 = lm->builtin_protocol_by_ip_protocol[ip1->protocol];
1148
Ed Warnickecb9cada2015-12-08 15:45:58 -07001149 flags0 = p0->flags;
1150 flags1 = p1->flags;
1151
rootc9d1c5b2017-08-15 12:58:31 -04001152 is_tcp_udp0 = ip6_next_proto_is_tcp_udp (p0, ip0, &udp_offset0);
1153 is_tcp_udp1 = ip6_next_proto_is_tcp_udp (p1, ip1, &udp_offset1);
1154
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001155 good_l4_csum0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
Jakub Grajciar2eeeb4b2017-11-07 14:39:10 +01001156 || (flags0 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
1157 || flags0 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001158 != 0;
1159 good_l4_csum1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
Jakub Grajciar2eeeb4b2017-11-07 14:39:10 +01001160 || (flags1 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
1161 || flags1 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001162 != 0;
Shwethab78292e2016-09-13 11:51:00 +01001163 len_diff0 = 0;
1164 len_diff1 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001165
rootc9d1c5b2017-08-15 12:58:31 -04001166 if (PREDICT_TRUE (is_tcp_udp0))
Shwethab78292e2016-09-13 11:51:00 +01001167 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001168 udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0);
Shwethab78292e2016-09-13 11:51:00 +01001169 /* Don't verify UDP checksum for packets with explicit zero checksum. */
rootc9d1c5b2017-08-15 12:58:31 -04001170 good_l4_csum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001171 && udp0->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001172 /* Verify UDP length. */
rootc9d1c5b2017-08-15 12:58:31 -04001173 if (is_tcp_udp0 == IP_PROTOCOL_UDP)
1174 {
1175 ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1176 udp_len0 = clib_net_to_host_u16 (udp0->length);
1177 len_diff0 = ip_len0 - udp_len0;
1178 }
Shwethab78292e2016-09-13 11:51:00 +01001179 }
rootc9d1c5b2017-08-15 12:58:31 -04001180 if (PREDICT_TRUE (is_tcp_udp1))
Shwethab78292e2016-09-13 11:51:00 +01001181 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001182 udp1 = (udp_header_t *) ((u8 *) ip1 + udp_offset1);
Shwethab78292e2016-09-13 11:51:00 +01001183 /* Don't verify UDP checksum for packets with explicit zero checksum. */
rootc9d1c5b2017-08-15 12:58:31 -04001184 good_l4_csum1 |= type1 == IP_BUILTIN_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001185 && udp1->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001186 /* Verify UDP length. */
rootc9d1c5b2017-08-15 12:58:31 -04001187 if (is_tcp_udp1 == IP_PROTOCOL_UDP)
1188 {
1189 ip_len1 = clib_net_to_host_u16 (ip1->payload_length);
1190 udp_len1 = clib_net_to_host_u16 (udp1->length);
1191 len_diff1 = ip_len1 - udp_len1;
1192 }
Shwethab78292e2016-09-13 11:51:00 +01001193 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001194
rootc9d1c5b2017-08-15 12:58:31 -04001195 good_l4_csum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1196 good_l4_csum1 |= type1 == IP_BUILTIN_PROTOCOL_UNKNOWN;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001197
Ed Warnickecb9cada2015-12-08 15:45:58 -07001198 len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1199 len_diff1 = type1 == IP_BUILTIN_PROTOCOL_UDP ? len_diff1 : 0;
1200
1201 if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
rootc9d1c5b2017-08-15 12:58:31 -04001202 && !good_l4_csum0
Damjan Marion213b5aa2017-07-13 21:19:27 +02001203 && !(flags0 &
1204 VNET_BUFFER_F_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001205 {
1206 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
rootc9d1c5b2017-08-15 12:58:31 -04001207 good_l4_csum0 =
Damjan Marion213b5aa2017-07-13 21:19:27 +02001208 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001209 }
1210 if (PREDICT_FALSE (type1 != IP_BUILTIN_PROTOCOL_UNKNOWN
rootc9d1c5b2017-08-15 12:58:31 -04001211 && !good_l4_csum1
Damjan Marion213b5aa2017-07-13 21:19:27 +02001212 && !(flags1 &
1213 VNET_BUFFER_F_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001214 {
1215 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, p1);
rootc9d1c5b2017-08-15 12:58:31 -04001216 good_l4_csum1 =
Damjan Marion213b5aa2017-07-13 21:19:27 +02001217 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001218 }
1219
1220 error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001221 error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1222 error1 = len_diff1 < 0 ? IP6_ERROR_UDP_LENGTH : error1;
1223
Dave Barachd7cb1b52016-12-09 09:52:16 -05001224 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1225 IP6_ERROR_UDP_CHECKSUM);
1226 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1227 IP6_ERROR_ICMP_CHECKSUM);
rootc9d1c5b2017-08-15 12:58:31 -04001228 error0 = (!good_l4_csum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0);
1229 error1 = (!good_l4_csum1 ? IP6_ERROR_UDP_CHECKSUM + type1 : error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001230
1231 /* Drop packets from unroutable hosts. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001232 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001233 if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1234 type0 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001235 !ip6_address_is_link_local_unicast (&ip0->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001236 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301237 error0 = (!ip6_urpf_loose_check (im, p0, ip0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001238 ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001239 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001240 if (error1 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1241 type1 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001242 !ip6_address_is_link_local_unicast (&ip1->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001243 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301244 error1 = (!ip6_urpf_loose_check (im, p1, ip1)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001245 ? IP6_ERROR_SRC_LOOKUP_MISS : error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001246 }
1247
Florin Corascea194d2017-10-02 00:18:51 -07001248 vnet_buffer (p0)->ip.fib_index =
Florin Coras3a0325f2018-06-01 12:22:23 -07001249 vnet_buffer (p0)->sw_if_index[VLIB_TX] != ~0 ?
1250 vnet_buffer (p0)->sw_if_index[VLIB_TX] :
1251 vnet_buffer (p0)->ip.fib_index;
Florin Corascea194d2017-10-02 00:18:51 -07001252
1253 vnet_buffer (p1)->ip.fib_index =
Florin Coras3a0325f2018-06-01 12:22:23 -07001254 vnet_buffer (p1)->sw_if_index[VLIB_TX] != ~0 ?
1255 vnet_buffer (p1)->sw_if_index[VLIB_TX] :
1256 vnet_buffer (p1)->ip.fib_index;
Florin Corascea194d2017-10-02 00:18:51 -07001257
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001258 skip_checks:
1259
1260 next0 = lm->local_next_by_ip_protocol[ip0->protocol];
1261 next1 = lm->local_next_by_ip_protocol[ip1->protocol];
1262
Dave Barachd7cb1b52016-12-09 09:52:16 -05001263 next0 =
1264 error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
1265 next1 =
1266 error1 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001267
1268 p0->error = error_node->errors[error0];
1269 p1->error = error_node->errors[error1];
1270
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001271 if (head_of_feature_arc)
1272 {
1273 if (PREDICT_TRUE (error0 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
1274 vnet_feature_arc_start (arc_index,
1275 vnet_buffer (p0)->sw_if_index
1276 [VLIB_RX], &next0, p0);
1277 if (PREDICT_TRUE (error1 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
1278 vnet_feature_arc_start (arc_index,
1279 vnet_buffer (p1)->sw_if_index
1280 [VLIB_RX], &next1, p1);
1281 }
1282
Ed Warnickecb9cada2015-12-08 15:45:58 -07001283 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1284 to_next, n_left_to_next,
1285 pi0, pi1, next0, next1);
1286 }
1287
1288 while (n_left_from > 0 && n_left_to_next > 0)
1289 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001290 vlib_buffer_t *p0;
1291 ip6_header_t *ip0;
1292 udp_header_t *udp0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001293 u32 pi0, ip_len0, udp_len0, flags0, next0;
1294 i32 len_diff0;
rootc9d1c5b2017-08-15 12:58:31 -04001295 u8 error0, type0, good_l4_csum0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001296 u32 udp_offset0;
rootc9d1c5b2017-08-15 12:58:31 -04001297 u8 is_tcp_udp0;
Dave Barach75fc8542016-10-11 16:16:02 -04001298
Ed Warnickecb9cada2015-12-08 15:45:58 -07001299 pi0 = to_next[0] = from[0];
1300 from += 1;
1301 n_left_from -= 1;
1302 to_next += 1;
1303 n_left_to_next -= 1;
Dave Barach75fc8542016-10-11 16:16:02 -04001304
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001305 error0 = IP6_ERROR_UNKNOWN_PROTOCOL;
1306
Ed Warnickecb9cada2015-12-08 15:45:58 -07001307 p0 = vlib_get_buffer (vm, pi0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001308 ip0 = vlib_buffer_get_current (p0);
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001309
1310 if (head_of_feature_arc == 0)
1311 goto skip_check;
1312
Damjan Marion072401e2017-07-13 18:53:27 +02001313 vnet_buffer (p0)->l3_hdr_offset = p0->current_data;
Filip Tehlarb601f222017-01-02 10:22:56 +01001314
Ed Warnickecb9cada2015-12-08 15:45:58 -07001315 type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001316 flags0 = p0->flags;
rootc9d1c5b2017-08-15 12:58:31 -04001317 is_tcp_udp0 = ip6_next_proto_is_tcp_udp (p0, ip0, &udp_offset0);
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001318 good_l4_csum0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
Jakub Grajciar2eeeb4b2017-11-07 14:39:10 +01001319 || (flags0 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
1320 || flags0 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001321 != 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001322
Shwethab78292e2016-09-13 11:51:00 +01001323 len_diff0 = 0;
rootc9d1c5b2017-08-15 12:58:31 -04001324 if (PREDICT_TRUE (is_tcp_udp0))
Shwethab78292e2016-09-13 11:51:00 +01001325 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001326 udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0);
rootc9d1c5b2017-08-15 12:58:31 -04001327 /* Don't verify UDP checksum for packets with explicit zero
1328 * checksum. */
1329 good_l4_csum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001330 && udp0->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001331 /* Verify UDP length. */
rootc9d1c5b2017-08-15 12:58:31 -04001332 if (is_tcp_udp0 == IP_PROTOCOL_UDP)
1333 {
1334 ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1335 udp_len0 = clib_net_to_host_u16 (udp0->length);
1336 len_diff0 = ip_len0 - udp_len0;
1337 }
Shwethab78292e2016-09-13 11:51:00 +01001338 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001339
rootc9d1c5b2017-08-15 12:58:31 -04001340 good_l4_csum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001341 len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1342
1343 if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
rootc9d1c5b2017-08-15 12:58:31 -04001344 && !good_l4_csum0
Damjan Marion213b5aa2017-07-13 21:19:27 +02001345 && !(flags0 &
1346 VNET_BUFFER_F_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001347 {
1348 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
rootc9d1c5b2017-08-15 12:58:31 -04001349 good_l4_csum0 =
Damjan Marion213b5aa2017-07-13 21:19:27 +02001350 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001351 }
1352
1353 error0 = IP6_ERROR_UNKNOWN_PROTOCOL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001354 error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1355
Dave Barachd7cb1b52016-12-09 09:52:16 -05001356 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1357 IP6_ERROR_UDP_CHECKSUM);
1358 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1359 IP6_ERROR_ICMP_CHECKSUM);
rootc9d1c5b2017-08-15 12:58:31 -04001360 error0 = (!good_l4_csum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001361
rootc9d1c5b2017-08-15 12:58:31 -04001362 /* If this is a neighbor solicitation (ICMP), skip src RPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001363 if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1364 type0 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001365 !ip6_address_is_link_local_unicast (&ip0->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001366 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301367 error0 = (!ip6_urpf_loose_check (im, p0, ip0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001368 ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001369 }
Florin Coras1b255522018-06-01 12:22:23 -07001370
Florin Corascea194d2017-10-02 00:18:51 -07001371 vnet_buffer (p0)->ip.fib_index =
Florin Coras3a0325f2018-06-01 12:22:23 -07001372 vnet_buffer (p0)->sw_if_index[VLIB_TX] != ~0 ?
1373 vnet_buffer (p0)->sw_if_index[VLIB_TX] :
1374 vnet_buffer (p0)->ip.fib_index;
Florin Corascea194d2017-10-02 00:18:51 -07001375
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001376 skip_check:
1377
1378 next0 = lm->local_next_by_ip_protocol[ip0->protocol];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001379 next0 =
1380 error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
Klement Sekera75e7d132017-09-20 08:26:30 +02001381
Ed Warnickecb9cada2015-12-08 15:45:58 -07001382 p0->error = error_node->errors[error0];
1383
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001384 if (head_of_feature_arc)
1385 {
1386 if (PREDICT_TRUE (error0 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
1387 vnet_feature_arc_start (arc_index,
1388 vnet_buffer (p0)->sw_if_index
1389 [VLIB_RX], &next0, p0);
1390 }
1391
Ed Warnickecb9cada2015-12-08 15:45:58 -07001392 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1393 to_next, n_left_to_next,
1394 pi0, next0);
1395 }
Dave Barach75fc8542016-10-11 16:16:02 -04001396
Ed Warnickecb9cada2015-12-08 15:45:58 -07001397 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1398 }
1399
1400 return frame->n_vectors;
1401}
1402
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001403static uword
1404ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1405{
1406 return ip6_local_inline (vm, node, frame, 1 /* head of feature arc */ );
1407}
1408
Dave Barachd7cb1b52016-12-09 09:52:16 -05001409/* *INDENT-OFF* */
1410VLIB_REGISTER_NODE (ip6_local_node, static) =
1411{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001412 .function = ip6_local,
1413 .name = "ip6-local",
1414 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -07001415 .format_trace = format_ip6_forward_next_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001416 .n_next_nodes = IP_LOCAL_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001417 .next_nodes =
1418 {
Neale Rannsd91c1db2017-07-31 02:30:50 -07001419 [IP_LOCAL_NEXT_DROP] = "ip6-drop",
1420 [IP_LOCAL_NEXT_PUNT] = "ip6-punt",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001421 [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
1422 [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
Juraj Sloboda3048b632018-10-02 11:13:53 +02001423 [IP_LOCAL_NEXT_REASSEMBLY] = "ip6-reassembly",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001424 },
1425};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001426/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001427
Dave Barachd7cb1b52016-12-09 09:52:16 -05001428VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_node, ip6_local);
Damjan Marion1c80e832016-05-11 23:07:18 +02001429
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001430
1431static uword
1432ip6_local_end_of_arc (vlib_main_t * vm,
1433 vlib_node_runtime_t * node, vlib_frame_t * frame)
1434{
1435 return ip6_local_inline (vm, node, frame, 0 /* head of feature arc */ );
1436}
1437
1438/* *INDENT-OFF* */
1439VLIB_REGISTER_NODE (ip6_local_end_of_arc_node,static) = {
1440 .function = ip6_local_end_of_arc,
1441 .name = "ip6-local-end-of-arc",
1442 .vector_size = sizeof (u32),
1443
1444 .format_trace = format_ip6_forward_next_trace,
1445 .sibling_of = "ip6-local",
1446};
1447
1448VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_end_of_arc_node, ip6_local_end_of_arc)
1449
1450VNET_FEATURE_INIT (ip6_local_end_of_arc, static) = {
1451 .arc_name = "ip6-local",
1452 .node_name = "ip6-local-end-of-arc",
1453 .runs_before = 0, /* not before any other features */
1454};
1455/* *INDENT-ON* */
1456
Dave Barachd7cb1b52016-12-09 09:52:16 -05001457void
1458ip6_register_protocol (u32 protocol, u32 node_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001459{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001460 vlib_main_t *vm = vlib_get_main ();
1461 ip6_main_t *im = &ip6_main;
1462 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001463
1464 ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
Dave Barachd7cb1b52016-12-09 09:52:16 -05001465 lm->local_next_by_ip_protocol[protocol] =
1466 vlib_node_add_next (vm, ip6_local_node.index, node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001467}
1468
Ed Warnickecb9cada2015-12-08 15:45:58 -07001469clib_error_t *
John Lo86376342018-06-11 20:14:49 -04001470ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index,
1471 u8 refresh)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001472{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001473 vnet_main_t *vnm = vnet_get_main ();
1474 ip6_main_t *im = &ip6_main;
1475 icmp6_neighbor_solicitation_header_t *h;
1476 ip6_address_t *src;
1477 ip_interface_address_t *ia;
1478 ip_adjacency_t *adj;
1479 vnet_hw_interface_t *hi;
1480 vnet_sw_interface_t *si;
1481 vlib_buffer_t *b;
Neale Ranns7a272742017-05-30 02:08:14 -07001482 adj_index_t ai;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001483 u32 bi = 0;
1484 int bogus_length;
1485
1486 si = vnet_get_sw_interface (vnm, sw_if_index);
1487
1488 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
1489 {
1490 return clib_error_return (0, "%U: interface %U down",
Dave Barachd7cb1b52016-12-09 09:52:16 -05001491 format_ip6_address, dst,
1492 format_vnet_sw_if_index_name, vnm,
1493 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001494 }
1495
Dave Barachd7cb1b52016-12-09 09:52:16 -05001496 src =
1497 ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia);
1498 if (!src)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001499 {
1500 vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE;
Dave Barach75fc8542016-10-11 16:16:02 -04001501 return clib_error_return
Dave Barachd7cb1b52016-12-09 09:52:16 -05001502 (0, "no matching interface address for destination %U (interface %U)",
1503 format_ip6_address, dst,
1504 format_vnet_sw_if_index_name, vnm, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001505 }
1506
Dave Barachd7cb1b52016-12-09 09:52:16 -05001507 h =
1508 vlib_packet_template_get_packet (vm,
1509 &im->discover_neighbor_packet_template,
1510 &bi);
John Lo084606b2018-06-19 15:27:48 -04001511 if (!h)
1512 return clib_error_return (0, "ICMP6 NS packet allocation failed");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001513
1514 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
1515
1516 /* Destination address is a solicited node multicast address. We need to fill in
1517 the low 24 bits with low 24 bits of target's address. */
1518 h->ip.dst_address.as_u8[13] = dst->as_u8[13];
1519 h->ip.dst_address.as_u8[14] = dst->as_u8[14];
1520 h->ip.dst_address.as_u8[15] = dst->as_u8[15];
1521
1522 h->ip.src_address = src[0];
1523 h->neighbor.target_address = dst[0];
1524
Pavel Kotucek57808982017-08-02 08:20:19 +02001525 if (PREDICT_FALSE (!hi->hw_address))
1526 {
1527 return clib_error_return (0, "%U: interface %U do not support ip probe",
1528 format_ip6_address, dst,
1529 format_vnet_sw_if_index_name, vnm,
1530 sw_if_index);
1531 }
1532
Dave Barach178cf492018-11-13 16:34:13 -05001533 clib_memcpy_fast (h->link_layer_option.ethernet_address, hi->hw_address,
1534 vec_len (hi->hw_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001535
Dave Barach75fc8542016-10-11 16:16:02 -04001536 h->neighbor.icmp.checksum =
Ed Warnickecb9cada2015-12-08 15:45:58 -07001537 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001538 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001539
1540 b = vlib_get_buffer (vm, bi);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001541 vnet_buffer (b)->sw_if_index[VLIB_RX] =
1542 vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001543
1544 /* Add encapsulation string for software interface (e.g. ethernet header). */
Neale Ranns7a272742017-05-30 02:08:14 -07001545 ip46_address_t nh = {
1546 .ip6 = *dst,
1547 };
1548
1549 ai = adj_nbr_add_or_lock (FIB_PROTOCOL_IP6,
1550 VNET_LINK_IP6, &nh, sw_if_index);
1551 adj = adj_get (ai);
1552
Dave Barach59b25652017-09-10 15:04:27 -04001553 /* Peer has been previously resolved, retrieve glean adj instead */
John Lo86376342018-06-11 20:14:49 -04001554 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE && refresh == 0)
Dave Barach59b25652017-09-10 15:04:27 -04001555 {
1556 adj_unlock (ai);
Ole Troan6ee40512018-02-12 18:14:39 +01001557 ai = adj_glean_add_or_lock (FIB_PROTOCOL_IP6,
1558 VNET_LINK_IP6, sw_if_index, &nh);
Dave Barach59b25652017-09-10 15:04:27 -04001559 adj = adj_get (ai);
1560 }
1561
Ed Warnickecb9cada2015-12-08 15:45:58 -07001562 vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
1563 vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
1564
1565 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001566 vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
1567 u32 *to_next = vlib_frame_vector_args (f);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001568 to_next[0] = bi;
1569 f->n_vectors = 1;
1570 vlib_put_frame_to_node (vm, hi->output_node_index, f);
1571 }
1572
Neale Ranns7a272742017-05-30 02:08:14 -07001573 adj_unlock (ai);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001574 return /* no error */ 0;
1575}
1576
Dave Barachd7cb1b52016-12-09 09:52:16 -05001577typedef enum
1578{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001579 IP6_REWRITE_NEXT_DROP,
Chris Luke816f3e12016-06-14 16:24:47 -04001580 IP6_REWRITE_NEXT_ICMP_ERROR,
Ole Troan313f7e22018-04-10 16:02:51 +02001581 IP6_REWRITE_NEXT_FRAGMENT,
1582 IP6_REWRITE_N_NEXT /* Last */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001583} ip6_rewrite_next_t;
1584
Neale Ranns889fe942017-06-01 05:43:19 -04001585/**
1586 * This bits of an IPv6 address to mask to construct a multicast
1587 * MAC address
1588 */
1589#define IP6_MCAST_ADDR_MASK 0xffffffff
1590
Ole Troanda6e11b2018-05-23 11:21:42 +02001591always_inline void
1592ip6_mtu_check (vlib_buffer_t * b, u16 packet_bytes,
Ole Troan313f7e22018-04-10 16:02:51 +02001593 u16 adj_packet_bytes, bool is_locally_generated,
1594 u32 * next, u32 * error)
Ole Troanda6e11b2018-05-23 11:21:42 +02001595{
1596 if (adj_packet_bytes >= 1280 && packet_bytes > adj_packet_bytes)
1597 {
Ole Troan313f7e22018-04-10 16:02:51 +02001598 if (is_locally_generated)
1599 {
1600 /* IP fragmentation */
Ole Troan282093f2018-09-19 12:38:51 +02001601 ip_frag_set_vnet_buffer (b, adj_packet_bytes,
Ole Troanb3655e52018-08-16 22:08:49 +02001602 IP6_FRAG_NEXT_IP6_REWRITE, 0);
Ole Troan313f7e22018-04-10 16:02:51 +02001603 *next = IP6_REWRITE_NEXT_FRAGMENT;
Ole Troan282093f2018-09-19 12:38:51 +02001604 *error = IP6_ERROR_MTU_EXCEEDED;
Ole Troan313f7e22018-04-10 16:02:51 +02001605 }
1606 else
1607 {
1608 *error = IP6_ERROR_MTU_EXCEEDED;
1609 icmp6_error_set_vnet_buffer (b, ICMP6_packet_too_big, 0,
1610 adj_packet_bytes);
1611 *next = IP6_REWRITE_NEXT_ICMP_ERROR;
1612 }
Ole Troanda6e11b2018-05-23 11:21:42 +02001613 }
1614}
1615
Ed Warnickecb9cada2015-12-08 15:45:58 -07001616always_inline uword
1617ip6_rewrite_inline (vlib_main_t * vm,
1618 vlib_node_runtime_t * node,
Neale Ranns9c6a6132017-02-21 05:33:14 -08001619 vlib_frame_t * frame,
1620 int do_counters, int is_midchain, int is_mcast)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001621{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001622 ip_lookup_main_t *lm = &ip6_main.lookup_main;
1623 u32 *from = vlib_frame_vector_args (frame);
1624 u32 n_left_from, n_left_to_next, *to_next, next_index;
1625 vlib_node_runtime_t *error_node =
1626 vlib_node_get_runtime (vm, ip6_input_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001627
1628 n_left_from = frame->n_vectors;
1629 next_index = node->cached_next_index;
Damjan Marion067cd622018-07-11 12:47:43 +02001630 u32 thread_index = vm->thread_index;
Dave Barach75fc8542016-10-11 16:16:02 -04001631
Ed Warnickecb9cada2015-12-08 15:45:58 -07001632 while (n_left_from > 0)
1633 {
1634 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1635
1636 while (n_left_from >= 4 && n_left_to_next >= 2)
1637 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001638 ip_adjacency_t *adj0, *adj1;
1639 vlib_buffer_t *p0, *p1;
1640 ip6_header_t *ip0, *ip1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001641 u32 pi0, rw_len0, next0, error0, adj_index0;
1642 u32 pi1, rw_len1, next1, error1, adj_index1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001643 u32 tx_sw_if_index0, tx_sw_if_index1;
Ole Troan313f7e22018-04-10 16:02:51 +02001644 bool is_locally_originated0, is_locally_originated1;
Dave Barach75fc8542016-10-11 16:16:02 -04001645
Ed Warnickecb9cada2015-12-08 15:45:58 -07001646 /* Prefetch next iteration. */
1647 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001648 vlib_buffer_t *p2, *p3;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001649
1650 p2 = vlib_get_buffer (vm, from[2]);
1651 p3 = vlib_get_buffer (vm, from[3]);
1652
1653 vlib_prefetch_buffer_header (p2, LOAD);
1654 vlib_prefetch_buffer_header (p3, LOAD);
1655
1656 CLIB_PREFETCH (p2->pre_data, 32, STORE);
1657 CLIB_PREFETCH (p3->pre_data, 32, STORE);
1658
1659 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
1660 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
1661 }
1662
1663 pi0 = to_next[0] = from[0];
1664 pi1 = to_next[1] = from[1];
1665
1666 from += 2;
1667 n_left_from -= 2;
1668 to_next += 2;
1669 n_left_to_next -= 2;
Dave Barach75fc8542016-10-11 16:16:02 -04001670
Ed Warnickecb9cada2015-12-08 15:45:58 -07001671 p0 = vlib_get_buffer (vm, pi0);
1672 p1 = vlib_get_buffer (vm, pi1);
1673
Neale Rannsf06aea52016-11-29 06:51:37 -08001674 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1675 adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001676
Ed Warnickecb9cada2015-12-08 15:45:58 -07001677 ip0 = vlib_buffer_get_current (p0);
1678 ip1 = vlib_buffer_get_current (p1);
1679
1680 error0 = error1 = IP6_ERROR_NONE;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001681 next0 = next1 = IP6_REWRITE_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001682
Ole Troan313f7e22018-04-10 16:02:51 +02001683 is_locally_originated0 =
1684 p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
1685 if (PREDICT_TRUE (!is_locally_originated0))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001686 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001687 i32 hop_limit0 = ip0->hop_limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001688
1689 /* Input node should have reject packets with hop limit 0. */
1690 ASSERT (ip0->hop_limit > 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001691
1692 hop_limit0 -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001693
1694 ip0->hop_limit = hop_limit0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001695
Dave Barachd7cb1b52016-12-09 09:52:16 -05001696 /*
1697 * If the hop count drops below 1 when forwarding, generate
1698 * an ICMP response.
1699 */
1700 if (PREDICT_FALSE (hop_limit0 <= 0))
1701 {
1702 error0 = IP6_ERROR_TIME_EXPIRED;
1703 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
1704 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1705 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
1706 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1707 0);
1708 }
Neale Rannsf06aea52016-11-29 06:51:37 -08001709 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001710 else
1711 {
Damjan Marion213b5aa2017-07-13 21:19:27 +02001712 p0->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001713 }
Ole Troan313f7e22018-04-10 16:02:51 +02001714 is_locally_originated1 =
1715 p1->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
1716 if (PREDICT_TRUE (!is_locally_originated1))
Dave Barachd7cb1b52016-12-09 09:52:16 -05001717 {
Neale Rannsf06aea52016-11-29 06:51:37 -08001718 i32 hop_limit1 = ip1->hop_limit;
1719
1720 /* Input node should have reject packets with hop limit 0. */
1721 ASSERT (ip1->hop_limit > 0);
1722
1723 hop_limit1 -= 1;
1724
1725 ip1->hop_limit = hop_limit1;
1726
Dave Barachd7cb1b52016-12-09 09:52:16 -05001727 /*
1728 * If the hop count drops below 1 when forwarding, generate
1729 * an ICMP response.
1730 */
1731 if (PREDICT_FALSE (hop_limit1 <= 0))
1732 {
1733 error1 = IP6_ERROR_TIME_EXPIRED;
1734 next1 = IP6_REWRITE_NEXT_ICMP_ERROR;
1735 vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1736 icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded,
1737 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1738 0);
1739 }
1740 }
1741 else
1742 {
Damjan Marion213b5aa2017-07-13 21:19:27 +02001743 p1->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001744 }
Neale Ranns107e7d42017-04-11 09:55:19 -07001745 adj0 = adj_get (adj_index0);
1746 adj1 = adj_get (adj_index1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001747
Ed Warnickecb9cada2015-12-08 15:45:58 -07001748 rw_len0 = adj0[0].rewrite_header.data_bytes;
1749 rw_len1 = adj1[0].rewrite_header.data_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001750 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
1751 vnet_buffer (p1)->ip.save_rewrite_length = rw_len1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001752
Neale Ranns9c6a6132017-02-21 05:33:14 -08001753 if (do_counters)
1754 {
1755 vlib_increment_combined_counter
1756 (&adjacency_counters,
Damjan Marion586afd72017-04-05 19:18:20 +02001757 thread_index, adj_index0, 1,
Neale Ranns9c6a6132017-02-21 05:33:14 -08001758 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
1759 vlib_increment_combined_counter
1760 (&adjacency_counters,
Damjan Marion586afd72017-04-05 19:18:20 +02001761 thread_index, adj_index1, 1,
Neale Ranns9c6a6132017-02-21 05:33:14 -08001762 vlib_buffer_length_in_chain (vm, p1) + rw_len1);
1763 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001764
1765 /* Check MTU of outgoing interface. */
Ole Troanda6e11b2018-05-23 11:21:42 +02001766 ip6_mtu_check (p0, clib_net_to_host_u16 (ip0->payload_length) +
1767 sizeof (ip6_header_t),
1768 adj0[0].rewrite_header.max_l3_packet_bytes,
Ole Troan313f7e22018-04-10 16:02:51 +02001769 is_locally_originated0, &next0, &error0);
Ole Troanda6e11b2018-05-23 11:21:42 +02001770 ip6_mtu_check (p1, clib_net_to_host_u16 (ip1->payload_length) +
1771 sizeof (ip6_header_t),
1772 adj1[0].rewrite_header.max_l3_packet_bytes,
Ole Troan313f7e22018-04-10 16:02:51 +02001773 is_locally_originated1, &next1, &error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001774
Dave Barachd7cb1b52016-12-09 09:52:16 -05001775 /* Don't adjust the buffer for hop count issue; icmp-error node
1776 * wants to see the IP headerr */
1777 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
1778 {
1779 p0->current_data -= rw_len0;
1780 p0->current_length += rw_len0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001781
Dave Barachd7cb1b52016-12-09 09:52:16 -05001782 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
1783 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
1784 next0 = adj0[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04001785
Neale Rannsb069a692017-03-15 12:34:25 -04001786 if (PREDICT_FALSE
1787 (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
1788 vnet_feature_arc_start (lm->output_feature_arc_index,
1789 tx_sw_if_index0, &next0, p0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001790 }
1791 if (PREDICT_TRUE (error1 == IP6_ERROR_NONE))
1792 {
1793 p1->current_data -= rw_len1;
1794 p1->current_length += rw_len1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001795
Dave Barachd7cb1b52016-12-09 09:52:16 -05001796 tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
1797 vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1;
1798 next1 = adj1[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04001799
Neale Rannsb069a692017-03-15 12:34:25 -04001800 if (PREDICT_FALSE
1801 (adj1[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
1802 vnet_feature_arc_start (lm->output_feature_arc_index,
1803 tx_sw_if_index1, &next1, p1);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001804 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001805
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001806 /* Guess we are only writing on simple Ethernet header. */
1807 vnet_rewrite_two_headers (adj0[0], adj1[0],
1808 ip0, ip1, sizeof (ethernet_header_t));
1809
1810 if (is_midchain)
1811 {
1812 adj0->sub_type.midchain.fixup_func
1813 (vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
1814 adj1->sub_type.midchain.fixup_func
1815 (vm, adj1, p1, adj1->sub_type.midchain.fixup_data);
1816 }
1817 if (is_mcast)
1818 {
1819 /*
1820 * copy bytes from the IP address into the MAC rewrite
1821 */
Neale Ranns889fe942017-06-01 05:43:19 -04001822 vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK,
1823 adj0->
1824 rewrite_header.dst_mcast_offset,
1825 &ip0->dst_address.as_u32[3],
1826 (u8 *) ip0);
1827 vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK,
1828 adj1->
1829 rewrite_header.dst_mcast_offset,
1830 &ip1->dst_address.as_u32[3],
1831 (u8 *) ip1);
Neale Ranns32e1c012016-11-22 17:07:28 +00001832 }
Neale Ranns5e575b12016-10-03 09:40:25 +01001833
Ed Warnickecb9cada2015-12-08 15:45:58 -07001834 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1835 to_next, n_left_to_next,
1836 pi0, pi1, next0, next1);
1837 }
1838
1839 while (n_left_from > 0 && n_left_to_next > 0)
1840 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001841 ip_adjacency_t *adj0;
1842 vlib_buffer_t *p0;
1843 ip6_header_t *ip0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001844 u32 pi0, rw_len0;
1845 u32 adj_index0, next0, error0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001846 u32 tx_sw_if_index0;
Ole Troan313f7e22018-04-10 16:02:51 +02001847 bool is_locally_originated0;
Dave Barach75fc8542016-10-11 16:16:02 -04001848
Ed Warnickecb9cada2015-12-08 15:45:58 -07001849 pi0 = to_next[0] = from[0];
1850
1851 p0 = vlib_get_buffer (vm, pi0);
1852
Neale Rannsf06aea52016-11-29 06:51:37 -08001853 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001854
Neale Ranns107e7d42017-04-11 09:55:19 -07001855 adj0 = adj_get (adj_index0);
Dave Barach75fc8542016-10-11 16:16:02 -04001856
Ed Warnickecb9cada2015-12-08 15:45:58 -07001857 ip0 = vlib_buffer_get_current (p0);
1858
1859 error0 = IP6_ERROR_NONE;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001860 next0 = IP6_REWRITE_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001861
1862 /* Check hop limit */
Ole Troan313f7e22018-04-10 16:02:51 +02001863 is_locally_originated0 =
1864 p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
1865 if (PREDICT_TRUE (!is_locally_originated0))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001866 {
1867 i32 hop_limit0 = ip0->hop_limit;
1868
1869 ASSERT (ip0->hop_limit > 0);
1870
1871 hop_limit0 -= 1;
1872
1873 ip0->hop_limit = hop_limit0;
1874
Dave Barachd7cb1b52016-12-09 09:52:16 -05001875 if (PREDICT_FALSE (hop_limit0 <= 0))
1876 {
1877 /*
1878 * If the hop count drops below 1 when forwarding, generate
1879 * an ICMP response.
1880 */
1881 error0 = IP6_ERROR_TIME_EXPIRED;
1882 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
1883 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1884 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
1885 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1886 0);
1887 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001888 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001889 else
1890 {
Damjan Marion213b5aa2017-07-13 21:19:27 +02001891 p0->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001892 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001893
Ed Warnickecb9cada2015-12-08 15:45:58 -07001894 /* Guess we are only writing on simple Ethernet header. */
1895 vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
Dave Barach75fc8542016-10-11 16:16:02 -04001896
Ed Warnickecb9cada2015-12-08 15:45:58 -07001897 /* Update packet buffer attributes/set output interface. */
1898 rw_len0 = adj0[0].rewrite_header.data_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001899 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001900
Neale Ranns9c6a6132017-02-21 05:33:14 -08001901 if (do_counters)
1902 {
1903 vlib_increment_combined_counter
1904 (&adjacency_counters,
Damjan Marion586afd72017-04-05 19:18:20 +02001905 thread_index, adj_index0, 1,
Neale Ranns9c6a6132017-02-21 05:33:14 -08001906 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
1907 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001908
1909 /* Check MTU of outgoing interface. */
Ole Troanda6e11b2018-05-23 11:21:42 +02001910 ip6_mtu_check (p0, clib_net_to_host_u16 (ip0->payload_length) +
1911 sizeof (ip6_header_t),
1912 adj0[0].rewrite_header.max_l3_packet_bytes,
Ole Troan313f7e22018-04-10 16:02:51 +02001913 is_locally_originated0, &next0, &error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001914
Dave Barachd7cb1b52016-12-09 09:52:16 -05001915 /* Don't adjust the buffer for hop count issue; icmp-error node
Ole Troanda6e11b2018-05-23 11:21:42 +02001916 * wants to see the IP header */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001917 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
1918 {
Chris Luke816f3e12016-06-14 16:24:47 -04001919 p0->current_data -= rw_len0;
1920 p0->current_length += rw_len0;
1921
Dave Barachd7cb1b52016-12-09 09:52:16 -05001922 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
Dave Barach5331c722016-08-17 11:54:30 -04001923
Dave Barachd7cb1b52016-12-09 09:52:16 -05001924 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
1925 next0 = adj0[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04001926
Neale Rannsb069a692017-03-15 12:34:25 -04001927 if (PREDICT_FALSE
1928 (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
1929 vnet_feature_arc_start (lm->output_feature_arc_index,
1930 tx_sw_if_index0, &next0, p0);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001931 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001932
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001933 if (is_midchain)
1934 {
1935 adj0->sub_type.midchain.fixup_func
1936 (vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
1937 }
1938 if (is_mcast)
1939 {
Neale Ranns889fe942017-06-01 05:43:19 -04001940 vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK,
1941 adj0->
1942 rewrite_header.dst_mcast_offset,
1943 &ip0->dst_address.as_u32[3],
1944 (u8 *) ip0);
Neale Ranns32e1c012016-11-22 17:07:28 +00001945 }
Neale Ranns5e575b12016-10-03 09:40:25 +01001946
Ed Warnickecb9cada2015-12-08 15:45:58 -07001947 p0->error = error_node->errors[error0];
1948
1949 from += 1;
1950 n_left_from -= 1;
1951 to_next += 1;
1952 n_left_to_next -= 1;
Dave Barach75fc8542016-10-11 16:16:02 -04001953
Ed Warnickecb9cada2015-12-08 15:45:58 -07001954 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1955 to_next, n_left_to_next,
1956 pi0, next0);
1957 }
1958
1959 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1960 }
1961
1962 /* Need to do trace after rewrites to pick up new packet data. */
1963 if (node->flags & VLIB_NODE_FLAG_TRACE)
Neale Rannsf06aea52016-11-29 06:51:37 -08001964 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001965
1966 return frame->n_vectors;
1967}
1968
1969static uword
Neale Rannsf06aea52016-11-29 06:51:37 -08001970ip6_rewrite (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001971 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001972{
Neale Ranns9c6a6132017-02-21 05:33:14 -08001973 if (adj_are_counters_enabled ())
1974 return ip6_rewrite_inline (vm, node, frame, 1, 0, 0);
1975 else
1976 return ip6_rewrite_inline (vm, node, frame, 0, 0, 0);
Neale Ranns32e1c012016-11-22 17:07:28 +00001977}
1978
1979static uword
Neale Ranns1855b8e2018-07-11 10:31:26 -07001980ip6_rewrite_bcast (vlib_main_t * vm,
1981 vlib_node_runtime_t * node, vlib_frame_t * frame)
1982{
1983 if (adj_are_counters_enabled ())
1984 return ip6_rewrite_inline (vm, node, frame, 1, 0, 0);
1985 else
1986 return ip6_rewrite_inline (vm, node, frame, 0, 0, 0);
1987}
1988
1989static uword
Neale Ranns32e1c012016-11-22 17:07:28 +00001990ip6_rewrite_mcast (vlib_main_t * vm,
1991 vlib_node_runtime_t * node, vlib_frame_t * frame)
1992{
Neale Ranns9c6a6132017-02-21 05:33:14 -08001993 if (adj_are_counters_enabled ())
1994 return ip6_rewrite_inline (vm, node, frame, 1, 0, 1);
1995 else
1996 return ip6_rewrite_inline (vm, node, frame, 0, 0, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001997}
1998
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001999static uword
2000ip6_midchain (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002001 vlib_node_runtime_t * node, vlib_frame_t * frame)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002002{
Neale Ranns9c6a6132017-02-21 05:33:14 -08002003 if (adj_are_counters_enabled ())
2004 return ip6_rewrite_inline (vm, node, frame, 1, 1, 0);
2005 else
2006 return ip6_rewrite_inline (vm, node, frame, 0, 1, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002007}
2008
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002009static uword
2010ip6_mcast_midchain (vlib_main_t * vm,
2011 vlib_node_runtime_t * node, vlib_frame_t * frame)
2012{
2013 if (adj_are_counters_enabled ())
2014 return ip6_rewrite_inline (vm, node, frame, 1, 1, 1);
2015 else
Neale Ranns9f171f52017-04-11 08:56:53 -07002016 return ip6_rewrite_inline (vm, node, frame, 0, 1, 1);
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002017}
2018
Dave Barachd7cb1b52016-12-09 09:52:16 -05002019/* *INDENT-OFF* */
2020VLIB_REGISTER_NODE (ip6_midchain_node) =
2021{
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002022 .function = ip6_midchain,
2023 .name = "ip6-midchain",
2024 .vector_size = sizeof (u32),
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002025 .format_trace = format_ip6_forward_next_trace,
Neale Ranns5e575b12016-10-03 09:40:25 +01002026 .sibling_of = "ip6-rewrite",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002027 };
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002028
Dave Barachd7cb1b52016-12-09 09:52:16 -05002029VLIB_NODE_FUNCTION_MULTIARCH (ip6_midchain_node, ip6_midchain);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002030
Dave Barachd7cb1b52016-12-09 09:52:16 -05002031VLIB_REGISTER_NODE (ip6_rewrite_node) =
2032{
Neale Rannsf06aea52016-11-29 06:51:37 -08002033 .function = ip6_rewrite,
Ed Warnickecb9cada2015-12-08 15:45:58 -07002034 .name = "ip6-rewrite",
2035 .vector_size = sizeof (u32),
Pierre Pfistera38c3df2016-06-13 10:28:09 +01002036 .format_trace = format_ip6_rewrite_trace,
Ole Troan313f7e22018-04-10 16:02:51 +02002037 .n_next_nodes = IP6_REWRITE_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002038 .next_nodes =
2039 {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08002040 [IP6_REWRITE_NEXT_DROP] = "ip6-drop",
Chris Luke816f3e12016-06-14 16:24:47 -04002041 [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error",
Ole Troan313f7e22018-04-10 16:02:51 +02002042 [IP6_REWRITE_NEXT_FRAGMENT] = "ip6-frag",
Ed Warnickecb9cada2015-12-08 15:45:58 -07002043 },
2044};
2045
Neale Rannsf06aea52016-11-29 06:51:37 -08002046VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_node, ip6_rewrite);
Damjan Marion1c80e832016-05-11 23:07:18 +02002047
Neale Ranns1855b8e2018-07-11 10:31:26 -07002048VLIB_REGISTER_NODE (ip6_rewrite_bcast_node) = {
Matthew Smithe3750672018-07-20 11:52:05 -05002049 .function = ip6_rewrite_bcast,
Neale Ranns1855b8e2018-07-11 10:31:26 -07002050 .name = "ip6-rewrite-bcast",
2051 .vector_size = sizeof (u32),
2052
2053 .format_trace = format_ip6_rewrite_trace,
2054 .sibling_of = "ip6-rewrite",
2055};
2056VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_bcast_node, ip6_rewrite_bcast)
2057
Neale Ranns32e1c012016-11-22 17:07:28 +00002058VLIB_REGISTER_NODE (ip6_rewrite_mcast_node) =
2059{
2060 .function = ip6_rewrite_mcast,
2061 .name = "ip6-rewrite-mcast",
2062 .vector_size = sizeof (u32),
2063 .format_trace = format_ip6_rewrite_trace,
2064 .sibling_of = "ip6-rewrite",
2065};
Neale Ranns32e1c012016-11-22 17:07:28 +00002066
2067VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_mcast_node, ip6_rewrite_mcast);
2068
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002069VLIB_REGISTER_NODE (ip6_mcast_midchain_node, static) =
2070{
2071 .function = ip6_mcast_midchain,
2072 .name = "ip6-mcast-midchain",
2073 .vector_size = sizeof (u32),
2074 .format_trace = format_ip6_rewrite_trace,
2075 .sibling_of = "ip6-rewrite",
2076};
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002077
2078VLIB_NODE_FUNCTION_MULTIARCH (ip6_mcast_midchain_node, ip6_mcast_midchain);
Neale Ranns1855b8e2018-07-11 10:31:26 -07002079/* *INDENT-ON* */
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002080
Ole Troan944f5482016-05-24 11:56:58 +02002081/*
2082 * Hop-by-Hop handling
2083 */
Ole Troan944f5482016-05-24 11:56:58 +02002084ip6_hop_by_hop_main_t ip6_hop_by_hop_main;
2085
2086#define foreach_ip6_hop_by_hop_error \
2087_(PROCESSED, "pkts with ip6 hop-by-hop options") \
2088_(FORMAT, "incorrectly formatted hop-by-hop options") \
2089_(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options")
2090
Neale Ranns32e1c012016-11-22 17:07:28 +00002091/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002092typedef enum
2093{
Ole Troan944f5482016-05-24 11:56:58 +02002094#define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym,
2095 foreach_ip6_hop_by_hop_error
2096#undef _
Neale Ranns32e1c012016-11-22 17:07:28 +00002097 IP6_HOP_BY_HOP_N_ERROR,
Ole Troan944f5482016-05-24 11:56:58 +02002098} ip6_hop_by_hop_error_t;
Neale Ranns32e1c012016-11-22 17:07:28 +00002099/* *INDENT-ON* */
Ole Troan944f5482016-05-24 11:56:58 +02002100
2101/*
2102 * Primary h-b-h handler trace support
2103 * We work pretty hard on the problem for obvious reasons
2104 */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002105typedef struct
2106{
Ole Troan944f5482016-05-24 11:56:58 +02002107 u32 next_index;
2108 u32 trace_len;
2109 u8 option_data[256];
2110} ip6_hop_by_hop_trace_t;
2111
2112vlib_node_registration_t ip6_hop_by_hop_node;
2113
Dave Barachd7cb1b52016-12-09 09:52:16 -05002114static char *ip6_hop_by_hop_error_strings[] = {
Ole Troan944f5482016-05-24 11:56:58 +02002115#define _(sym,string) string,
2116 foreach_ip6_hop_by_hop_error
2117#undef _
2118};
2119
Shwetha Bhandari78372a92017-01-18 12:43:54 +05302120u8 *
2121format_ip6_hop_by_hop_ext_hdr (u8 * s, va_list * args)
2122{
2123 ip6_hop_by_hop_header_t *hbh0 = va_arg (*args, ip6_hop_by_hop_header_t *);
2124 int total_len = va_arg (*args, int);
2125 ip6_hop_by_hop_option_t *opt0, *limit0;
2126 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2127 u8 type0;
2128
2129 s = format (s, "IP6_HOP_BY_HOP: next protocol %d len %d total %d",
2130 hbh0->protocol, (hbh0->length + 1) << 3, total_len);
2131
2132 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2133 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + total_len);
2134
2135 while (opt0 < limit0)
2136 {
2137 type0 = opt0->type;
2138 switch (type0)
2139 {
2140 case 0: /* Pad, just stop */
2141 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0 + 1);
2142 break;
2143
2144 default:
2145 if (hm->trace[type0])
2146 {
2147 s = (*hm->trace[type0]) (s, opt0);
2148 }
2149 else
2150 {
2151 s =
2152 format (s, "\n unrecognized option %d length %d", type0,
2153 opt0->length);
2154 }
2155 opt0 =
2156 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2157 sizeof (ip6_hop_by_hop_option_t));
2158 break;
2159 }
2160 }
2161 return s;
2162}
2163
Ole Troan944f5482016-05-24 11:56:58 +02002164static u8 *
2165format_ip6_hop_by_hop_trace (u8 * s, va_list * args)
2166{
2167 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2168 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002169 ip6_hop_by_hop_trace_t *t = va_arg (*args, ip6_hop_by_hop_trace_t *);
Ole Troan944f5482016-05-24 11:56:58 +02002170 ip6_hop_by_hop_header_t *hbh0;
2171 ip6_hop_by_hop_option_t *opt0, *limit0;
2172 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2173
2174 u8 type0;
2175
Dave Barachd7cb1b52016-12-09 09:52:16 -05002176 hbh0 = (ip6_hop_by_hop_header_t *) t->option_data;
Ole Troan944f5482016-05-24 11:56:58 +02002177
2178 s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002179 t->next_index, (hbh0->length + 1) << 3, t->trace_len);
Ole Troan944f5482016-05-24 11:56:58 +02002180
Dave Barachd7cb1b52016-12-09 09:52:16 -05002181 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2182 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0) + t->trace_len;
Ole Troan944f5482016-05-24 11:56:58 +02002183
Dave Barachd7cb1b52016-12-09 09:52:16 -05002184 while (opt0 < limit0)
2185 {
2186 type0 = opt0->type;
2187 switch (type0)
2188 {
2189 case 0: /* Pad, just stop */
2190 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
2191 break;
Ole Troan944f5482016-05-24 11:56:58 +02002192
Dave Barachd7cb1b52016-12-09 09:52:16 -05002193 default:
2194 if (hm->trace[type0])
2195 {
2196 s = (*hm->trace[type0]) (s, opt0);
2197 }
2198 else
2199 {
2200 s =
2201 format (s, "\n unrecognized option %d length %d", type0,
2202 opt0->length);
2203 }
2204 opt0 =
2205 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2206 sizeof (ip6_hop_by_hop_option_t));
2207 break;
2208 }
Ole Troan944f5482016-05-24 11:56:58 +02002209 }
Ole Troan944f5482016-05-24 11:56:58 +02002210 return s;
2211}
2212
Dave Barachd7cb1b52016-12-09 09:52:16 -05002213always_inline u8
2214ip6_scan_hbh_options (vlib_buffer_t * b0,
2215 ip6_header_t * ip0,
2216 ip6_hop_by_hop_header_t * hbh0,
2217 ip6_hop_by_hop_option_t * opt0,
2218 ip6_hop_by_hop_option_t * limit0, u32 * next0)
Shwethaa91cbe62016-08-08 15:51:04 +01002219{
2220 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2221 u8 type0;
2222 u8 error0 = 0;
2223
2224 while (opt0 < limit0)
2225 {
2226 type0 = opt0->type;
2227 switch (type0)
2228 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002229 case 0: /* Pad1 */
2230 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
Shwethaa91cbe62016-08-08 15:51:04 +01002231 continue;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002232 case 1: /* PadN */
Shwethaa91cbe62016-08-08 15:51:04 +01002233 break;
2234 default:
2235 if (hm->options[type0])
2236 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002237 if ((*hm->options[type0]) (b0, ip0, opt0) < 0)
2238 {
Shwethaa91cbe62016-08-08 15:51:04 +01002239 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002240 return (error0);
2241 }
Shwethaa91cbe62016-08-08 15:51:04 +01002242 }
2243 else
2244 {
2245 /* Unrecognized mandatory option, check the two high order bits */
2246 switch (opt0->type & HBH_OPTION_TYPE_HIGH_ORDER_BITS)
2247 {
2248 case HBH_OPTION_TYPE_SKIP_UNKNOWN:
2249 break;
2250 case HBH_OPTION_TYPE_DISCARD_UNKNOWN:
2251 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2252 *next0 = IP_LOOKUP_NEXT_DROP;
2253 break;
2254 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP:
2255 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2256 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002257 icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem,
2258 ICMP6_parameter_problem_unrecognized_option,
2259 (u8 *) opt0 - (u8 *) ip0);
Shwethaa91cbe62016-08-08 15:51:04 +01002260 break;
2261 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST:
2262 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002263 if (!ip6_address_is_multicast (&ip0->dst_address))
Shwethaa91cbe62016-08-08 15:51:04 +01002264 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002265 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
2266 icmp6_error_set_vnet_buffer (b0,
2267 ICMP6_parameter_problem,
2268 ICMP6_parameter_problem_unrecognized_option,
2269 (u8 *) opt0 - (u8 *) ip0);
Shwethaa91cbe62016-08-08 15:51:04 +01002270 }
2271 else
2272 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002273 *next0 = IP_LOOKUP_NEXT_DROP;
Shwethaa91cbe62016-08-08 15:51:04 +01002274 }
2275 break;
2276 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002277 return (error0);
Shwethaa91cbe62016-08-08 15:51:04 +01002278 }
2279 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002280 opt0 =
2281 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2282 sizeof (ip6_hop_by_hop_option_t));
Shwethaa91cbe62016-08-08 15:51:04 +01002283 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002284 return (error0);
Shwethaa91cbe62016-08-08 15:51:04 +01002285}
2286
Ole Troan944f5482016-05-24 11:56:58 +02002287/*
2288 * Process the Hop-by-Hop Options header
2289 */
2290static uword
2291ip6_hop_by_hop (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002292 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ole Troan944f5482016-05-24 11:56:58 +02002293{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002294 vlib_node_runtime_t *error_node =
2295 vlib_node_get_runtime (vm, ip6_hop_by_hop_node.index);
Ole Troan944f5482016-05-24 11:56:58 +02002296 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2297 u32 n_left_from, *from, *to_next;
2298 ip_lookup_next_t next_index;
Ole Troan944f5482016-05-24 11:56:58 +02002299
2300 from = vlib_frame_vector_args (frame);
2301 n_left_from = frame->n_vectors;
2302 next_index = node->cached_next_index;
2303
Dave Barachd7cb1b52016-12-09 09:52:16 -05002304 while (n_left_from > 0)
2305 {
2306 u32 n_left_to_next;
Ole Troan944f5482016-05-24 11:56:58 +02002307
Dave Barachd7cb1b52016-12-09 09:52:16 -05002308 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ole Troan944f5482016-05-24 11:56:58 +02002309
Dave Barachd7cb1b52016-12-09 09:52:16 -05002310 while (n_left_from >= 4 && n_left_to_next >= 2)
Shwethaa91cbe62016-08-08 15:51:04 +01002311 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002312 u32 bi0, bi1;
2313 vlib_buffer_t *b0, *b1;
2314 u32 next0, next1;
2315 ip6_header_t *ip0, *ip1;
2316 ip6_hop_by_hop_header_t *hbh0, *hbh1;
2317 ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1;
2318 u8 error0 = 0, error1 = 0;
2319
2320 /* Prefetch next iteration. */
2321 {
2322 vlib_buffer_t *p2, *p3;
2323
2324 p2 = vlib_get_buffer (vm, from[2]);
2325 p3 = vlib_get_buffer (vm, from[3]);
2326
2327 vlib_prefetch_buffer_header (p2, LOAD);
2328 vlib_prefetch_buffer_header (p3, LOAD);
2329
2330 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
2331 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
Shwethaa91cbe62016-08-08 15:51:04 +01002332 }
2333
Dave Barachd7cb1b52016-12-09 09:52:16 -05002334 /* Speculatively enqueue b0, b1 to the current next frame */
2335 to_next[0] = bi0 = from[0];
2336 to_next[1] = bi1 = from[1];
2337 from += 2;
2338 to_next += 2;
2339 n_left_from -= 2;
2340 n_left_to_next -= 2;
2341
2342 b0 = vlib_get_buffer (vm, bi0);
2343 b1 = vlib_get_buffer (vm, bi1);
2344
2345 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2346 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002347 ip_adjacency_t *adj0 = adj_get (adj_index0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002348 u32 adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002349 ip_adjacency_t *adj1 = adj_get (adj_index1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002350
2351 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2352 next0 = adj0->lookup_next_index;
2353 next1 = adj1->lookup_next_index;
2354
2355 ip0 = vlib_buffer_get_current (b0);
2356 ip1 = vlib_buffer_get_current (b1);
2357 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2358 hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
2359 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2360 opt1 = (ip6_hop_by_hop_option_t *) (hbh1 + 1);
2361 limit0 =
2362 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2363 ((hbh0->length + 1) << 3));
2364 limit1 =
2365 (ip6_hop_by_hop_option_t *) ((u8 *) hbh1 +
2366 ((hbh1->length + 1) << 3));
2367
2368 /*
2369 * Basic validity checks
2370 */
2371 if ((hbh0->length + 1) << 3 >
2372 clib_net_to_host_u16 (ip0->payload_length))
2373 {
2374 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2375 next0 = IP_LOOKUP_NEXT_DROP;
2376 goto outdual;
2377 }
2378 /* Scan the set of h-b-h options, process ones that we understand */
2379 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2380
2381 if ((hbh1->length + 1) << 3 >
2382 clib_net_to_host_u16 (ip1->payload_length))
2383 {
2384 error1 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2385 next1 = IP_LOOKUP_NEXT_DROP;
2386 goto outdual;
2387 }
2388 /* Scan the set of h-b-h options, process ones that we understand */
2389 error1 = ip6_scan_hbh_options (b1, ip1, hbh1, opt1, limit1, &next1);
2390
2391 outdual:
2392 /* Has the classifier flagged this buffer for special treatment? */
2393 if (PREDICT_FALSE
2394 ((error0 == 0)
2395 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2396 next0 = hm->next_override;
2397
2398 /* Has the classifier flagged this buffer for special treatment? */
2399 if (PREDICT_FALSE
2400 ((error1 == 0)
2401 && (vnet_buffer (b1)->l2_classify.opaque_index & OI_DECAP)))
2402 next1 = hm->next_override;
2403
2404 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
2405 {
2406 if (b0->flags & VLIB_BUFFER_IS_TRACED)
2407 {
2408 ip6_hop_by_hop_trace_t *t =
2409 vlib_add_trace (vm, node, b0, sizeof (*t));
2410 u32 trace_len = (hbh0->length + 1) << 3;
2411 t->next_index = next0;
2412 /* Capture the h-b-h option verbatim */
2413 trace_len =
2414 trace_len <
2415 ARRAY_LEN (t->option_data) ? trace_len :
2416 ARRAY_LEN (t->option_data);
2417 t->trace_len = trace_len;
Dave Barach178cf492018-11-13 16:34:13 -05002418 clib_memcpy_fast (t->option_data, hbh0, trace_len);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002419 }
2420 if (b1->flags & VLIB_BUFFER_IS_TRACED)
2421 {
2422 ip6_hop_by_hop_trace_t *t =
2423 vlib_add_trace (vm, node, b1, sizeof (*t));
2424 u32 trace_len = (hbh1->length + 1) << 3;
2425 t->next_index = next1;
2426 /* Capture the h-b-h option verbatim */
2427 trace_len =
2428 trace_len <
2429 ARRAY_LEN (t->option_data) ? trace_len :
2430 ARRAY_LEN (t->option_data);
2431 t->trace_len = trace_len;
Dave Barach178cf492018-11-13 16:34:13 -05002432 clib_memcpy_fast (t->option_data, hbh1, trace_len);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002433 }
2434
2435 }
2436
2437 b0->error = error_node->errors[error0];
2438 b1->error = error_node->errors[error1];
2439
2440 /* verify speculative enqueue, maybe switch current next frame */
2441 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
2442 n_left_to_next, bi0, bi1, next0,
2443 next1);
Shwethaa91cbe62016-08-08 15:51:04 +01002444 }
2445
Dave Barachd7cb1b52016-12-09 09:52:16 -05002446 while (n_left_from > 0 && n_left_to_next > 0)
2447 {
2448 u32 bi0;
2449 vlib_buffer_t *b0;
2450 u32 next0;
2451 ip6_header_t *ip0;
2452 ip6_hop_by_hop_header_t *hbh0;
2453 ip6_hop_by_hop_option_t *opt0, *limit0;
2454 u8 error0 = 0;
Shwethaa91cbe62016-08-08 15:51:04 +01002455
Dave Barachd7cb1b52016-12-09 09:52:16 -05002456 /* Speculatively enqueue b0 to the current next frame */
2457 bi0 = from[0];
2458 to_next[0] = bi0;
2459 from += 1;
2460 to_next += 1;
2461 n_left_from -= 1;
2462 n_left_to_next -= 1;
2463
2464 b0 = vlib_get_buffer (vm, bi0);
2465 /*
2466 * Default use the next_index from the adjacency.
2467 * A HBH option rarely redirects to a different node
2468 */
2469 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002470 ip_adjacency_t *adj0 = adj_get (adj_index0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002471 next0 = adj0->lookup_next_index;
2472
2473 ip0 = vlib_buffer_get_current (b0);
2474 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2475 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2476 limit0 =
2477 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2478 ((hbh0->length + 1) << 3));
2479
2480 /*
2481 * Basic validity checks
2482 */
2483 if ((hbh0->length + 1) << 3 >
2484 clib_net_to_host_u16 (ip0->payload_length))
2485 {
2486 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2487 next0 = IP_LOOKUP_NEXT_DROP;
2488 goto out0;
2489 }
2490
2491 /* Scan the set of h-b-h options, process ones that we understand */
2492 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2493
2494 out0:
2495 /* Has the classifier flagged this buffer for special treatment? */
2496 if (PREDICT_FALSE
2497 ((error0 == 0)
2498 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2499 next0 = hm->next_override;
2500
2501 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2502 {
2503 ip6_hop_by_hop_trace_t *t =
2504 vlib_add_trace (vm, node, b0, sizeof (*t));
2505 u32 trace_len = (hbh0->length + 1) << 3;
2506 t->next_index = next0;
2507 /* Capture the h-b-h option verbatim */
2508 trace_len =
2509 trace_len <
2510 ARRAY_LEN (t->option_data) ? trace_len :
2511 ARRAY_LEN (t->option_data);
2512 t->trace_len = trace_len;
Dave Barach178cf492018-11-13 16:34:13 -05002513 clib_memcpy_fast (t->option_data, hbh0, trace_len);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002514 }
2515
2516 b0->error = error_node->errors[error0];
2517
2518 /* verify speculative enqueue, maybe switch current next frame */
2519 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2520 n_left_to_next, bi0, next0);
2521 }
2522 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
Shwethaa91cbe62016-08-08 15:51:04 +01002523 }
Ole Troan944f5482016-05-24 11:56:58 +02002524 return frame->n_vectors;
2525}
2526
Dave Barachd7cb1b52016-12-09 09:52:16 -05002527/* *INDENT-OFF* */
2528VLIB_REGISTER_NODE (ip6_hop_by_hop_node) =
2529{
Ole Troan944f5482016-05-24 11:56:58 +02002530 .function = ip6_hop_by_hop,
2531 .name = "ip6-hop-by-hop",
Ole Troan964f93e2016-06-10 13:22:36 +02002532 .sibling_of = "ip6-lookup",
Ole Troan944f5482016-05-24 11:56:58 +02002533 .vector_size = sizeof (u32),
2534 .format_trace = format_ip6_hop_by_hop_trace,
2535 .type = VLIB_NODE_TYPE_INTERNAL,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002536 .n_errors = ARRAY_LEN (ip6_hop_by_hop_error_strings),
Ole Troan944f5482016-05-24 11:56:58 +02002537 .error_strings = ip6_hop_by_hop_error_strings,
Ole Troan964f93e2016-06-10 13:22:36 +02002538 .n_next_nodes = 0,
Ole Troan944f5482016-05-24 11:56:58 +02002539};
Dave Barachd7cb1b52016-12-09 09:52:16 -05002540/* *INDENT-ON* */
Ole Troan944f5482016-05-24 11:56:58 +02002541
Dave Barach5331c722016-08-17 11:54:30 -04002542VLIB_NODE_FUNCTION_MULTIARCH (ip6_hop_by_hop_node, ip6_hop_by_hop);
Ole Troan944f5482016-05-24 11:56:58 +02002543
2544static clib_error_t *
2545ip6_hop_by_hop_init (vlib_main_t * vm)
2546{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002547 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Dave Barachb7b92992018-10-17 10:38:51 -04002548 clib_memset (hm->options, 0, sizeof (hm->options));
2549 clib_memset (hm->trace, 0, sizeof (hm->trace));
Shwethaa91cbe62016-08-08 15:51:04 +01002550 hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
Ole Troan944f5482016-05-24 11:56:58 +02002551 return (0);
2552}
2553
2554VLIB_INIT_FUNCTION (ip6_hop_by_hop_init);
2555
Dave Barachd7cb1b52016-12-09 09:52:16 -05002556void
2557ip6_hbh_set_next_override (uword next)
Shwethaa91cbe62016-08-08 15:51:04 +01002558{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002559 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Shwethaa91cbe62016-08-08 15:51:04 +01002560
2561 hm->next_override = next;
2562}
2563
Ole Troan944f5482016-05-24 11:56:58 +02002564int
2565ip6_hbh_register_option (u8 option,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002566 int options (vlib_buffer_t * b, ip6_header_t * ip,
2567 ip6_hop_by_hop_option_t * opt),
2568 u8 * trace (u8 * s, ip6_hop_by_hop_option_t * opt))
Ole Troan944f5482016-05-24 11:56:58 +02002569{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002570 ip6_main_t *im = &ip6_main;
2571 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Ole Troan944f5482016-05-24 11:56:58 +02002572
Neale Ranns756cd942018-04-06 09:18:11 -07002573 ASSERT ((u32) option < ARRAY_LEN (hm->options));
Ole Troan944f5482016-05-24 11:56:58 +02002574
2575 /* Already registered */
2576 if (hm->options[option])
2577 return (-1);
2578
2579 hm->options[option] = options;
2580 hm->trace[option] = trace;
2581
2582 /* Set global variable */
2583 im->hbh_enabled = 1;
2584
2585 return (0);
2586}
2587
2588int
2589ip6_hbh_unregister_option (u8 option)
2590{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002591 ip6_main_t *im = &ip6_main;
2592 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Ole Troan944f5482016-05-24 11:56:58 +02002593
Neale Ranns756cd942018-04-06 09:18:11 -07002594 ASSERT ((u32) option < ARRAY_LEN (hm->options));
Ole Troan944f5482016-05-24 11:56:58 +02002595
2596 /* Not registered */
2597 if (!hm->options[option])
2598 return (-1);
2599
2600 hm->options[option] = NULL;
2601 hm->trace[option] = NULL;
2602
2603 /* Disable global knob if this was the last option configured */
2604 int i;
2605 bool found = false;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002606 for (i = 0; i < 256; i++)
2607 {
2608 if (hm->options[option])
2609 {
2610 found = true;
2611 break;
2612 }
Ole Troan944f5482016-05-24 11:56:58 +02002613 }
Ole Troan944f5482016-05-24 11:56:58 +02002614 if (!found)
2615 im->hbh_enabled = 0;
2616
2617 return (0);
2618}
2619
Ed Warnickecb9cada2015-12-08 15:45:58 -07002620/* Global IP6 main. */
2621ip6_main_t ip6_main;
2622
2623static clib_error_t *
2624ip6_lookup_init (vlib_main_t * vm)
2625{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002626 ip6_main_t *im = &ip6_main;
2627 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002628 uword i;
2629
Damjan Marion8b3191e2016-11-09 19:54:20 +01002630 if ((error = vlib_call_init_function (vm, vnet_feature_init)))
2631 return error;
2632
Ed Warnickecb9cada2015-12-08 15:45:58 -07002633 for (i = 0; i < ARRAY_LEN (im->fib_masks); i++)
2634 {
2635 u32 j, i0, i1;
2636
2637 i0 = i / 32;
2638 i1 = i % 32;
2639
2640 for (j = 0; j < i0; j++)
2641 im->fib_masks[i].as_u32[j] = ~0;
2642
2643 if (i1)
Dave Barachd7cb1b52016-12-09 09:52:16 -05002644 im->fib_masks[i].as_u32[i0] =
2645 clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002646 }
2647
2648 ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1);
2649
2650 if (im->lookup_table_nbuckets == 0)
2651 im->lookup_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS;
2652
Dave Barachd7cb1b52016-12-09 09:52:16 -05002653 im->lookup_table_nbuckets = 1 << max_log2 (im->lookup_table_nbuckets);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002654
2655 if (im->lookup_table_size == 0)
2656 im->lookup_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE;
Dave Barach75fc8542016-10-11 16:16:02 -04002657
Dave Barachd7cb1b52016-12-09 09:52:16 -05002658 BV (clib_bihash_init) (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash),
2659 "ip6 FIB fwding table",
2660 im->lookup_table_nbuckets, im->lookup_table_size);
2661 BV (clib_bihash_init) (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
2662 "ip6 FIB non-fwding table",
2663 im->lookup_table_nbuckets, im->lookup_table_size);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002664
Ed Warnickecb9cada2015-12-08 15:45:58 -07002665 /* Create FIB with index 0 and table id of 0. */
Neale Ranns15002542017-09-10 04:39:11 -07002666 fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0,
2667 FIB_SOURCE_DEFAULT_ROUTE);
2668 mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0,
2669 MFIB_SOURCE_DEFAULT_ROUTE);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002670
2671 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002672 pg_node_t *pn;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002673 pn = pg_get_node (ip6_lookup_node.index);
2674 pn->unformat_edit = unformat_pg_ip6_header;
2675 }
2676
Ole Troan944f5482016-05-24 11:56:58 +02002677 /* Unless explicitly configured, don't process HBH options */
2678 im->hbh_enabled = 0;
2679
Ed Warnickecb9cada2015-12-08 15:45:58 -07002680 {
2681 icmp6_neighbor_solicitation_header_t p;
2682
Dave Barachb7b92992018-10-17 10:38:51 -04002683 clib_memset (&p, 0, sizeof (p));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002684
Dave Barachd7cb1b52016-12-09 09:52:16 -05002685 p.ip.ip_version_traffic_class_and_flow_label =
2686 clib_host_to_net_u32 (0x6 << 28);
2687 p.ip.payload_length =
2688 clib_host_to_net_u16 (sizeof (p) -
2689 STRUCT_OFFSET_OF
2690 (icmp6_neighbor_solicitation_header_t, neighbor));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002691 p.ip.protocol = IP_PROTOCOL_ICMP6;
2692 p.ip.hop_limit = 255;
2693 ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0);
2694
2695 p.neighbor.icmp.type = ICMP6_neighbor_solicitation;
2696
Dave Barachd7cb1b52016-12-09 09:52:16 -05002697 p.link_layer_option.header.type =
2698 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
2699 p.link_layer_option.header.n_data_u64s =
2700 sizeof (p.link_layer_option) / sizeof (u64);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002701
2702 vlib_packet_template_init (vm,
2703 &im->discover_neighbor_packet_template,
2704 &p, sizeof (p),
2705 /* alloc chunk size */ 8,
2706 "ip6 neighbor discovery");
2707 }
2708
Dave Barach203c6322016-06-26 10:29:03 -04002709 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002710}
2711
2712VLIB_INIT_FUNCTION (ip6_lookup_init);
2713
Dave Barach75fc8542016-10-11 16:16:02 -04002714void
Dave Barachd7cb1b52016-12-09 09:52:16 -05002715ip6_link_local_address_from_ethernet_mac_address (ip6_address_t * ip,
2716 u8 * mac)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002717{
2718 ip->as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
2719 /* Invert the "u" bit */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002720 ip->as_u8[8] = mac[0] ^ (1 << 1);
2721 ip->as_u8[9] = mac[1];
2722 ip->as_u8[10] = mac[2];
2723 ip->as_u8[11] = 0xFF;
2724 ip->as_u8[12] = 0xFE;
2725 ip->as_u8[13] = mac[3];
2726 ip->as_u8[14] = mac[4];
2727 ip->as_u8[15] = mac[5];
Ed Warnickecb9cada2015-12-08 15:45:58 -07002728}
2729
Dave Barach75fc8542016-10-11 16:16:02 -04002730void
Dave Barachd7cb1b52016-12-09 09:52:16 -05002731ip6_ethernet_mac_address_from_link_local_address (u8 * mac,
2732 ip6_address_t * ip)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002733{
2734 /* Invert the previously inverted "u" bit */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002735 mac[0] = ip->as_u8[8] ^ (1 << 1);
2736 mac[1] = ip->as_u8[9];
2737 mac[2] = ip->as_u8[10];
2738 mac[3] = ip->as_u8[13];
2739 mac[4] = ip->as_u8[14];
2740 mac[5] = ip->as_u8[15];
Ed Warnickecb9cada2015-12-08 15:45:58 -07002741}
2742
Dave Barach75fc8542016-10-11 16:16:02 -04002743static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07002744test_ip6_link_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002745 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002746{
2747 u8 mac[6];
2748 ip6_address_t _a, *a = &_a;
2749
2750 if (unformat (input, "%U", unformat_ethernet_address, mac))
2751 {
2752 ip6_link_local_address_from_ethernet_mac_address (a, mac);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002753 vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002754 ip6_ethernet_mac_address_from_link_local_address (mac, a);
2755 vlib_cli_output (vm, "Original MAC address: %U",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002756 format_ethernet_address, mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002757 }
Dave Barach75fc8542016-10-11 16:16:02 -04002758
Ed Warnickecb9cada2015-12-08 15:45:58 -07002759 return 0;
2760}
2761
Billy McFall0683c9c2016-10-13 08:27:31 -04002762/*?
2763 * This command converts the given MAC Address into an IPv6 link-local
2764 * address.
2765 *
2766 * @cliexpar
2767 * Example of how to create an IPv6 link-local address:
2768 * @cliexstart{test ip6 link 16:d9:e0:91:79:86}
2769 * Link local address: fe80::14d9:e0ff:fe91:7986
2770 * Original MAC address: 16:d9:e0:91:79:86
2771 * @cliexend
2772?*/
2773/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002774VLIB_CLI_COMMAND (test_link_command, static) =
2775{
Ed Warnickecb9cada2015-12-08 15:45:58 -07002776 .path = "test ip6 link",
Dave Barach75fc8542016-10-11 16:16:02 -04002777 .function = test_ip6_link_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07002778 .short_help = "test ip6 link <mac-address>",
2779};
Billy McFall0683c9c2016-10-13 08:27:31 -04002780/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002781
Dave Barachd7cb1b52016-12-09 09:52:16 -05002782int
2783vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002784{
Neale Ranns107e7d42017-04-11 09:55:19 -07002785 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002786
Neale Ranns107e7d42017-04-11 09:55:19 -07002787 fib_index = fib_table_find (FIB_PROTOCOL_IP6, table_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002788
Neale Ranns107e7d42017-04-11 09:55:19 -07002789 if (~0 == fib_index)
2790 return VNET_API_ERROR_NO_SUCH_FIB;
2791
Neale Ranns227038a2017-04-21 01:07:59 -07002792 fib_table_set_flow_hash_config (fib_index, FIB_PROTOCOL_IP6,
2793 flow_hash_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002794
Neale Ranns227038a2017-04-21 01:07:59 -07002795 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002796}
2797
2798static clib_error_t *
2799set_ip6_flow_hash_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002800 unformat_input_t * input,
2801 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002802{
2803 int matched = 0;
2804 u32 table_id = 0;
2805 u32 flow_hash_config = 0;
2806 int rv;
2807
Dave Barachd7cb1b52016-12-09 09:52:16 -05002808 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2809 {
2810 if (unformat (input, "table %d", &table_id))
2811 matched = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002812#define _(a,v) \
2813 else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
Dave Barachd7cb1b52016-12-09 09:52:16 -05002814 foreach_flow_hash_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07002815#undef _
Dave Barachd7cb1b52016-12-09 09:52:16 -05002816 else
2817 break;
2818 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002819
2820 if (matched == 0)
2821 return clib_error_return (0, "unknown input `%U'",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002822 format_unformat_error, input);
Dave Barach75fc8542016-10-11 16:16:02 -04002823
Ed Warnickecb9cada2015-12-08 15:45:58 -07002824 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
2825 switch (rv)
2826 {
Neale Ranns227038a2017-04-21 01:07:59 -07002827 case 0:
Ed Warnickecb9cada2015-12-08 15:45:58 -07002828 break;
2829
2830 case -1:
2831 return clib_error_return (0, "no such FIB table %d", table_id);
Dave Barach75fc8542016-10-11 16:16:02 -04002832
Ed Warnickecb9cada2015-12-08 15:45:58 -07002833 default:
2834 clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config);
2835 break;
2836 }
Dave Barach75fc8542016-10-11 16:16:02 -04002837
Ed Warnickecb9cada2015-12-08 15:45:58 -07002838 return 0;
2839}
2840
Billy McFall0683c9c2016-10-13 08:27:31 -04002841/*?
2842 * Configure the set of IPv6 fields used by the flow hash.
2843 *
2844 * @cliexpar
2845 * @parblock
2846 * Example of how to set the flow hash on a given table:
Billy McFallebb9a6a2016-10-17 11:35:32 -04002847 * @cliexcmd{set ip6 flow-hash table 8 dst sport dport proto}
2848 *
Billy McFall0683c9c2016-10-13 08:27:31 -04002849 * Example of display the configured flow hash:
2850 * @cliexstart{show ip6 fib}
Billy McFallebb9a6a2016-10-17 11:35:32 -04002851 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
2852 * @::/0
2853 * unicast-ip6-chain
2854 * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]]
2855 * [0] [@0]: dpo-drop ip6
2856 * fe80::/10
2857 * unicast-ip6-chain
2858 * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]]
2859 * [0] [@2]: dpo-receive
2860 * ff02::1/128
2861 * unicast-ip6-chain
2862 * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]]
2863 * [0] [@2]: dpo-receive
2864 * ff02::2/128
2865 * unicast-ip6-chain
2866 * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]]
2867 * [0] [@2]: dpo-receive
2868 * ff02::16/128
2869 * unicast-ip6-chain
2870 * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]]
2871 * [0] [@2]: dpo-receive
2872 * ff02::1:ff00:0/104
2873 * unicast-ip6-chain
2874 * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]]
2875 * [0] [@2]: dpo-receive
2876 * ipv6-VRF:8, fib_index 1, flow hash: dst sport dport proto
2877 * @::/0
2878 * unicast-ip6-chain
2879 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
2880 * [0] [@0]: dpo-drop ip6
2881 * @::a:1:1:0:4/126
2882 * unicast-ip6-chain
2883 * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]]
2884 * [0] [@4]: ipv6-glean: af_packet0
2885 * @::a:1:1:0:7/128
2886 * unicast-ip6-chain
2887 * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]]
2888 * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0
2889 * fe80::/10
2890 * unicast-ip6-chain
2891 * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]]
2892 * [0] [@2]: dpo-receive
2893 * fe80::fe:3eff:fe3e:9222/128
2894 * unicast-ip6-chain
2895 * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]]
2896 * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0
2897 * ff02::1/128
2898 * unicast-ip6-chain
2899 * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]]
2900 * [0] [@2]: dpo-receive
2901 * ff02::2/128
2902 * unicast-ip6-chain
2903 * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]]
2904 * [0] [@2]: dpo-receive
2905 * ff02::16/128
2906 * unicast-ip6-chain
2907 * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]]
2908 * [0] [@2]: dpo-receive
2909 * ff02::1:ff00:0/104
2910 * unicast-ip6-chain
2911 * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]]
2912 * [0] [@2]: dpo-receive
Billy McFall0683c9c2016-10-13 08:27:31 -04002913 * @cliexend
2914 * @endparblock
2915?*/
2916/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002917VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) =
2918{
2919 .path = "set ip6 flow-hash",
2920 .short_help =
2921 "set ip6 flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]",
2922 .function = set_ip6_flow_hash_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07002923};
Billy McFall0683c9c2016-10-13 08:27:31 -04002924/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002925
2926static clib_error_t *
2927show_ip6_local_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002928 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002929{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002930 ip6_main_t *im = &ip6_main;
2931 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002932 int i;
Dave Barach75fc8542016-10-11 16:16:02 -04002933
Ed Warnickecb9cada2015-12-08 15:45:58 -07002934 vlib_cli_output (vm, "Protocols handled by ip6_local");
Dave Barachd7cb1b52016-12-09 09:52:16 -05002935 for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002936 {
2937 if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
Pierre Pfister1bfd3722017-09-18 11:40:32 +02002938 {
2939
2940 u32 node_index = vlib_get_node (vm,
2941 ip6_local_node.index)->
2942 next_nodes[lm->local_next_by_ip_protocol[i]];
2943 vlib_cli_output (vm, "%d: %U", i, format_vlib_node_name, vm,
2944 node_index);
2945 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002946 }
2947 return 0;
2948}
2949
2950
2951
Billy McFall0683c9c2016-10-13 08:27:31 -04002952/*?
2953 * Display the set of protocols handled by the local IPv6 stack.
2954 *
2955 * @cliexpar
2956 * Example of how to display local protocol table:
2957 * @cliexstart{show ip6 local}
2958 * Protocols handled by ip6_local
2959 * 17
2960 * 43
2961 * 58
2962 * 115
2963 * @cliexend
2964?*/
2965/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002966VLIB_CLI_COMMAND (show_ip6_local, static) =
2967{
Ed Warnickecb9cada2015-12-08 15:45:58 -07002968 .path = "show ip6 local",
2969 .function = show_ip6_local_command_fn,
Billy McFall0683c9c2016-10-13 08:27:31 -04002970 .short_help = "show ip6 local",
Ed Warnickecb9cada2015-12-08 15:45:58 -07002971};
Billy McFall0683c9c2016-10-13 08:27:31 -04002972/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002973
Dave Barachd7cb1b52016-12-09 09:52:16 -05002974int
2975vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
2976 u32 table_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002977{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002978 vnet_main_t *vnm = vnet_get_main ();
2979 vnet_interface_main_t *im = &vnm->interface_main;
2980 ip6_main_t *ipm = &ip6_main;
2981 ip_lookup_main_t *lm = &ipm->lookup_main;
2982 vnet_classify_main_t *cm = &vnet_classify_main;
Neale Rannsdf089a82016-10-02 16:39:06 +01002983 ip6_address_t *if_addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002984
2985 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2986 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
2987
2988 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
2989 return VNET_API_ERROR_NO_SUCH_ENTRY;
2990
2991 vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002992 lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002993
Neale Ranns6cfc39c2017-02-14 01:44:25 -08002994 if_addr = ip6_interface_first_address (ipm, sw_if_index);
Neale Rannsdf089a82016-10-02 16:39:06 +01002995
2996 if (NULL != if_addr)
Dave Barachd7cb1b52016-12-09 09:52:16 -05002997 {
Neale Rannsdf089a82016-10-02 16:39:06 +01002998 fib_prefix_t pfx = {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002999 .fp_len = 128,
3000 .fp_proto = FIB_PROTOCOL_IP6,
3001 .fp_addr.ip6 = *if_addr,
Neale Rannsdf089a82016-10-02 16:39:06 +01003002 };
3003 u32 fib_index;
3004
Dave Barachd7cb1b52016-12-09 09:52:16 -05003005 fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
3006 sw_if_index);
Neale Rannsdf089a82016-10-02 16:39:06 +01003007
3008
Dave Barachd7cb1b52016-12-09 09:52:16 -05003009 if (table_index != (u32) ~ 0)
3010 {
3011 dpo_id_t dpo = DPO_INVALID;
Neale Rannsdf089a82016-10-02 16:39:06 +01003012
Dave Barachd7cb1b52016-12-09 09:52:16 -05003013 dpo_set (&dpo,
3014 DPO_CLASSIFY,
3015 DPO_PROTO_IP6,
3016 classify_dpo_create (DPO_PROTO_IP6, table_index));
Neale Rannsdf089a82016-10-02 16:39:06 +01003017
Dave Barachd7cb1b52016-12-09 09:52:16 -05003018 fib_table_entry_special_dpo_add (fib_index,
3019 &pfx,
3020 FIB_SOURCE_CLASSIFY,
3021 FIB_ENTRY_FLAG_NONE, &dpo);
3022 dpo_reset (&dpo);
3023 }
Neale Rannsdf089a82016-10-02 16:39:06 +01003024 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05003025 {
3026 fib_table_entry_special_remove (fib_index,
3027 &pfx, FIB_SOURCE_CLASSIFY);
3028 }
3029 }
Neale Rannsdf089a82016-10-02 16:39:06 +01003030
Ed Warnickecb9cada2015-12-08 15:45:58 -07003031 return 0;
3032}
3033
3034static clib_error_t *
3035set_ip6_classify_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003036 unformat_input_t * input,
3037 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003038{
3039 u32 table_index = ~0;
3040 int table_index_set = 0;
3041 u32 sw_if_index = ~0;
3042 int rv;
Dave Barach75fc8542016-10-11 16:16:02 -04003043
Dave Barachd7cb1b52016-12-09 09:52:16 -05003044 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3045 {
3046 if (unformat (input, "table-index %d", &table_index))
3047 table_index_set = 1;
3048 else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
3049 vnet_get_main (), &sw_if_index))
3050 ;
3051 else
3052 break;
3053 }
Dave Barach75fc8542016-10-11 16:16:02 -04003054
Ed Warnickecb9cada2015-12-08 15:45:58 -07003055 if (table_index_set == 0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003056 return clib_error_return (0, "classify table-index must be specified");
Dave Barach75fc8542016-10-11 16:16:02 -04003057
Ed Warnickecb9cada2015-12-08 15:45:58 -07003058 if (sw_if_index == ~0)
3059 return clib_error_return (0, "interface / subif must be specified");
3060
3061 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3062
3063 switch (rv)
3064 {
3065 case 0:
3066 break;
3067
3068 case VNET_API_ERROR_NO_MATCHING_INTERFACE:
3069 return clib_error_return (0, "No such interface");
3070
3071 case VNET_API_ERROR_NO_SUCH_ENTRY:
3072 return clib_error_return (0, "No such classifier table");
3073 }
3074 return 0;
3075}
3076
Billy McFall0683c9c2016-10-13 08:27:31 -04003077/*?
3078 * Assign a classification table to an interface. The classification
3079 * table is created using the '<em>classify table</em>' and '<em>classify session</em>'
3080 * commands. Once the table is create, use this command to filter packets
3081 * on an interface.
3082 *
3083 * @cliexpar
3084 * Example of how to assign a classification table to an interface:
3085 * @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1}
3086?*/
3087/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003088VLIB_CLI_COMMAND (set_ip6_classify_command, static) =
3089{
3090 .path = "set ip6 classify",
3091 .short_help =
3092 "set ip6 classify intfc <interface> table-index <classify-idx>",
3093 .function = set_ip6_classify_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003094};
Billy McFall0683c9c2016-10-13 08:27:31 -04003095/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003096
3097static clib_error_t *
3098ip6_config (vlib_main_t * vm, unformat_input_t * input)
3099{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003100 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003101 uword heapsize = 0;
3102 u32 tmp;
3103 u32 nbuckets = 0;
3104
Dave Barachd7cb1b52016-12-09 09:52:16 -05003105 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3106 {
3107 if (unformat (input, "hash-buckets %d", &tmp))
3108 nbuckets = tmp;
Neale Ranns1ec36522017-11-29 05:20:37 -08003109 else if (unformat (input, "heap-size %U",
3110 unformat_memory_size, &heapsize))
3111 ;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003112 else
3113 return clib_error_return (0, "unknown input '%U'",
3114 format_unformat_error, input);
3115 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003116
3117 im->lookup_table_nbuckets = nbuckets;
3118 im->lookup_table_size = heapsize;
3119
3120 return 0;
3121}
3122
3123VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6");
Dave Barachd7cb1b52016-12-09 09:52:16 -05003124
3125/*
3126 * fd.io coding-style-patch-verification: ON
3127 *
3128 * Local Variables:
3129 * eval: (c-set-style "gnu")
3130 * End:
3131 */