blob: 30b717f5545e08a972fbdcc02929bd0bc6e3ceac [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>
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +020042#include <vnet/ip/ip6_neighbor.h>
Dave Barachd7cb1b52016-12-09 09:52:16 -050043#include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
Ed Warnickecb9cada2015-12-08 15:45:58 -070044#include <vnet/srp/srp.h> /* for srp_hw_interface_class */
45#include <vppinfra/cache.h>
AkshayaNadahalli0f438df2017-02-10 10:54:16 +053046#include <vnet/fib/fib_urpf_list.h> /* for FIB uRPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +010047#include <vnet/fib/ip6_fib.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000048#include <vnet/mfib/ip6_mfib.h>
Neale Rannsf12a83f2017-04-18 09:09:40 -070049#include <vnet/dpo/load_balance_map.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010050#include <vnet/dpo/classify_dpo.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
52#include <vppinfra/bihash_template.c>
Vijayabhaskar Katamreddyacbde662018-01-23 13:39:40 -080053#include <vnet/ip/ip6_forward.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070054
AkshayaNadahallifdd81af2016-12-01 16:33:51 +053055/* Flag used by IOAM code. Classifier sets it pop-hop-by-hop checks it */
56#define OI_DECAP 0x80000000
57
Ed Warnickecb9cada2015-12-08 15:45:58 -070058static void
59ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index,
60 ip6_main_t * im, u32 fib_index,
61 ip_interface_address_t * a)
62{
Dave Barachd7cb1b52016-12-09 09:52:16 -050063 ip_lookup_main_t *lm = &im->lookup_main;
64 ip6_address_t *address = ip_interface_address_get_address (lm, a);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010065 fib_prefix_t pfx = {
Dave Barachd7cb1b52016-12-09 09:52:16 -050066 .fp_len = a->address_length,
67 .fp_proto = FIB_PROTOCOL_IP6,
68 .fp_addr.ip6 = *address,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010069 };
Ed Warnickecb9cada2015-12-08 15:45:58 -070070
Ed Warnickecb9cada2015-12-08 15:45:58 -070071 if (a->address_length < 128)
Dave Barachd7cb1b52016-12-09 09:52:16 -050072 {
Neale Ranns7a272742017-05-30 02:08:14 -070073 fib_table_entry_update_one_path (fib_index,
74 &pfx,
75 FIB_SOURCE_INTERFACE,
76 (FIB_ENTRY_FLAG_CONNECTED |
77 FIB_ENTRY_FLAG_ATTACHED),
Neale Rannsda78f952017-05-24 09:15:43 -070078 DPO_PROTO_IP6,
Neale Ranns7a272742017-05-30 02:08:14 -070079 /* No next-hop address */
80 NULL, sw_if_index,
81 /* invalid FIB index */
82 ~0, 1,
83 /* no label stack */
84 NULL, FIB_ROUTE_PATH_FLAG_NONE);
Dave Barachd7cb1b52016-12-09 09:52:16 -050085 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070086
Neale Ranns0bfe5d82016-08-25 15:29:12 +010087 pfx.fp_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -070088 if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
Dave Barachd7cb1b52016-12-09 09:52:16 -050089 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +010090 u32 classify_table_index =
Dave Barachd7cb1b52016-12-09 09:52:16 -050091 lm->classify_table_index_by_sw_if_index[sw_if_index];
92 if (classify_table_index != (u32) ~ 0)
93 {
94 dpo_id_t dpo = DPO_INVALID;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010095
Dave Barachd7cb1b52016-12-09 09:52:16 -050096 dpo_set (&dpo,
97 DPO_CLASSIFY,
98 DPO_PROTO_IP6,
99 classify_dpo_create (DPO_PROTO_IP6, classify_table_index));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100100
Dave Barachd7cb1b52016-12-09 09:52:16 -0500101 fib_table_entry_special_dpo_add (fib_index,
102 &pfx,
103 FIB_SOURCE_CLASSIFY,
104 FIB_ENTRY_FLAG_NONE, &dpo);
105 dpo_reset (&dpo);
106 }
107 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100108
Neale Rannsf12a83f2017-04-18 09:09:40 -0700109 fib_table_entry_update_one_path (fib_index, &pfx,
110 FIB_SOURCE_INTERFACE,
111 (FIB_ENTRY_FLAG_CONNECTED |
112 FIB_ENTRY_FLAG_LOCAL),
Neale Rannsda78f952017-05-24 09:15:43 -0700113 DPO_PROTO_IP6,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700114 &pfx.fp_addr,
115 sw_if_index, ~0,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500116 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117}
118
119static void
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100120ip6_del_interface_routes (ip6_main_t * im,
121 u32 fib_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500122 ip6_address_t * address, u32 address_length)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500124 fib_prefix_t pfx = {
125 .fp_len = address_length,
126 .fp_proto = FIB_PROTOCOL_IP6,
127 .fp_addr.ip6 = *address,
128 };
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129
Dave Barachd7cb1b52016-12-09 09:52:16 -0500130 if (pfx.fp_len < 128)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500132 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100133
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134 }
135
Dave Barachd7cb1b52016-12-09 09:52:16 -0500136 pfx.fp_len = 128;
137 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138}
139
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100140void
Dave Barachd7cb1b52016-12-09 09:52:16 -0500141ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100142{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500143 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100145 vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100147 /*
148 * enable/disable only on the 1<->0 transition
149 */
150 if (is_enable)
151 {
152 if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index])
Dave Barachd7cb1b52016-12-09 09:52:16 -0500153 return;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100154 }
155 else
156 {
Neale Ranns75152282017-01-09 01:00:45 -0800157 /* The ref count is 0 when an address is removed from an interface that has
158 * no address - this is not a ciritical error */
159 if (0 == im->ip_enabled_by_sw_if_index[sw_if_index] ||
160 0 != --im->ip_enabled_by_sw_if_index[sw_if_index])
Dave Barachd7cb1b52016-12-09 09:52:16 -0500161 return;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100162 }
163
Neale Ranns8269d3d2018-01-30 09:02:20 -0800164 vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
Neale Ranns630198f2017-05-22 09:20:20 -0400165 !is_enable, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100166
Neale Ranns8269d3d2018-01-30 09:02:20 -0800167 vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
168 sw_if_index, !is_enable, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100169}
170
Neale Rannsdf089a82016-10-02 16:39:06 +0100171/* get first interface address */
172ip6_address_t *
Neale Ranns6cfc39c2017-02-14 01:44:25 -0800173ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
Neale Rannsdf089a82016-10-02 16:39:06 +0100174{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500175 ip_lookup_main_t *lm = &im->lookup_main;
176 ip_interface_address_t *ia = 0;
177 ip6_address_t *result = 0;
Neale Rannsdf089a82016-10-02 16:39:06 +0100178
Dave Barachd7cb1b52016-12-09 09:52:16 -0500179 /* *INDENT-OFF* */
Neale Rannsdf089a82016-10-02 16:39:06 +0100180 foreach_ip_interface_address (lm, ia, sw_if_index,
181 1 /* honor unnumbered */,
182 ({
183 ip6_address_t * a = ip_interface_address_get_address (lm, ia);
184 result = a;
185 break;
186 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500187 /* *INDENT-ON* */
Neale Rannsdf089a82016-10-02 16:39:06 +0100188 return result;
189}
190
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100191clib_error_t *
192ip6_add_del_interface_address (vlib_main_t * vm,
193 u32 sw_if_index,
194 ip6_address_t * address,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500195 u32 address_length, u32 is_del)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700196{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500197 vnet_main_t *vnm = vnet_get_main ();
198 ip6_main_t *im = &ip6_main;
199 ip_lookup_main_t *lm = &im->lookup_main;
200 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700201 u32 if_address_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500202 ip6_address_fib_t ip6_af, *addr_fib = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700203
Pavel Kotucek57808982017-08-02 08:20:19 +0200204 /* local0 interface doesn't support IP addressing */
205 if (sw_if_index == 0)
206 {
207 return
208 clib_error_create ("local0 interface doesn't support IP addressing");
209 }
210
Ed Warnickecb9cada2015-12-08 15:45:58 -0700211 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000212 vec_validate (im->mfib_index_by_sw_if_index, sw_if_index);
213
Ed Warnickecb9cada2015-12-08 15:45:58 -0700214 ip6_addr_fib_init (&ip6_af, address,
215 vec_elt (im->fib_index_by_sw_if_index, sw_if_index));
216 vec_add1 (addr_fib, ip6_af);
217
218 {
219 uword elts_before = pool_elts (lm->if_address_pool);
220
221 error = ip_interface_address_add_del
Dave Barachd7cb1b52016-12-09 09:52:16 -0500222 (lm, sw_if_index, addr_fib, address_length, is_del, &if_address_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700223 if (error)
224 goto done;
225
226 /* Pool did not grow: add duplicate address. */
227 if (elts_before == pool_elts (lm->if_address_pool))
228 goto done;
229 }
230
Dave Barachd7cb1b52016-12-09 09:52:16 -0500231 ip6_sw_interface_enable_disable (sw_if_index, !is_del);
Neale Ranns177bbdc2016-11-15 09:46:51 +0000232
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100233 if (is_del)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500234 ip6_del_interface_routes (im, ip6_af.fib_index, address, address_length);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100235 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500236 ip6_add_interface_routes (vnm, sw_if_index,
237 im, ip6_af.fib_index,
238 pool_elt_at_index (lm->if_address_pool,
239 if_address_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240
241 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500242 ip6_add_del_interface_address_callback_t *cb;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700243 vec_foreach (cb, im->add_del_interface_address_callbacks)
244 cb->function (im, cb->function_opaque, sw_if_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500245 address, address_length, if_address_index, is_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700246 }
247
Dave Barachd7cb1b52016-12-09 09:52:16 -0500248done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249 vec_free (addr_fib);
250 return error;
251}
252
253clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500254ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500256 ip6_main_t *im = &ip6_main;
257 ip_interface_address_t *ia;
258 ip6_address_t *a;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259 u32 is_admin_up, fib_index;
260
261 /* Fill in lookup tables with default table (0). */
262 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
263
Dave Barachd7cb1b52016-12-09 09:52:16 -0500264 vec_validate_init_empty (im->
265 lookup_main.if_address_pool_index_by_sw_if_index,
266 sw_if_index, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700267
268 is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
269
270 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
271
Dave Barachd7cb1b52016-12-09 09:52:16 -0500272 /* *INDENT-OFF* */
Dave Barach75fc8542016-10-11 16:16:02 -0400273 foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700274 0 /* honor unnumbered */,
275 ({
276 a = ip_interface_address_get_address (&im->lookup_main, ia);
277 if (is_admin_up)
278 ip6_add_interface_routes (vnm, sw_if_index,
279 im, fib_index,
280 ia);
281 else
282 ip6_del_interface_routes (im, fib_index,
283 a, ia->address_length);
284 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500285 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286
287 return 0;
288}
289
290VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
291
Dave Barachd6534602016-06-14 18:38:02 -0400292/* Built-in ip6 unicast rx feature path definition */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500293/* *INDENT-OFF* */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100294VNET_FEATURE_ARC_INIT (ip6_unicast, static) =
295{
296 .arc_name = "ip6-unicast",
297 .start_nodes = VNET_FEATURES ("ip6-input"),
298 .arc_index_ptr = &ip6_main.lookup_main.ucast_feature_arc_index,
299};
300
Dave Barachd7cb1b52016-12-09 09:52:16 -0500301VNET_FEATURE_INIT (ip6_flow_classify, static) =
302{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100303 .arc_name = "ip6-unicast",
Juraj Sloboda506b2452016-08-07 23:45:24 -0700304 .node_name = "ip6-flow-classify",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100305 .runs_before = VNET_FEATURES ("ip6-inacl"),
Juraj Sloboda506b2452016-08-07 23:45:24 -0700306};
307
Dave Barachd7cb1b52016-12-09 09:52:16 -0500308VNET_FEATURE_INIT (ip6_inacl, static) =
309{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100310 .arc_name = "ip6-unicast",
Dave Barach75fc8542016-10-11 16:16:02 -0400311 .node_name = "ip6-inacl",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100312 .runs_before = VNET_FEATURES ("ip6-policer-classify"),
Dave Barachd6534602016-06-14 18:38:02 -0400313};
314
Dave Barachd7cb1b52016-12-09 09:52:16 -0500315VNET_FEATURE_INIT (ip6_policer_classify, static) =
316{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100317 .arc_name = "ip6-unicast",
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700318 .node_name = "ip6-policer-classify",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100319 .runs_before = VNET_FEATURES ("ipsec-input-ip6"),
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700320};
321
Dave Barachd7cb1b52016-12-09 09:52:16 -0500322VNET_FEATURE_INIT (ip6_ipsec, static) =
323{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100324 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400325 .node_name = "ipsec-input-ip6",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100326 .runs_before = VNET_FEATURES ("l2tp-decap"),
Dave Barachd6534602016-06-14 18:38:02 -0400327};
328
Dave Barachd7cb1b52016-12-09 09:52:16 -0500329VNET_FEATURE_INIT (ip6_l2tp, static) =
330{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100331 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400332 .node_name = "l2tp-decap",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100333 .runs_before = VNET_FEATURES ("vpath-input-ip6"),
Dave Barachd6534602016-06-14 18:38:02 -0400334};
335
Dave Barachd7cb1b52016-12-09 09:52:16 -0500336VNET_FEATURE_INIT (ip6_vpath, static) =
337{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100338 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400339 .node_name = "vpath-input-ip6",
John Lo2b81eb82017-01-30 13:12:10 -0500340 .runs_before = VNET_FEATURES ("ip6-vxlan-bypass"),
341};
342
343VNET_FEATURE_INIT (ip6_vxlan_bypass, static) =
344{
345 .arc_name = "ip6-unicast",
346 .node_name = "ip6-vxlan-bypass",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100347 .runs_before = VNET_FEATURES ("ip6-lookup"),
Dave Barachd6534602016-06-14 18:38:02 -0400348};
349
Neale Ranns8269d3d2018-01-30 09:02:20 -0800350VNET_FEATURE_INIT (ip6_not_enabled, static) =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500351{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100352 .arc_name = "ip6-unicast",
Neale Ranns8269d3d2018-01-30 09:02:20 -0800353 .node_name = "ip6-not-enabled",
Neale Ranns630198f2017-05-22 09:20:20 -0400354 .runs_before = VNET_FEATURES ("ip6-lookup"),
355};
356
357VNET_FEATURE_INIT (ip6_lookup, static) =
358{
359 .arc_name = "ip6-unicast",
360 .node_name = "ip6-lookup",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100361 .runs_before = 0, /*last feature*/
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100362};
363
Dave Barachd6534602016-06-14 18:38:02 -0400364/* Built-in ip6 multicast rx feature path definition (none now) */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100365VNET_FEATURE_ARC_INIT (ip6_multicast, static) =
366{
367 .arc_name = "ip6-multicast",
368 .start_nodes = VNET_FEATURES ("ip6-input"),
369 .arc_index_ptr = &ip6_main.lookup_main.mcast_feature_arc_index,
370};
371
372VNET_FEATURE_INIT (ip6_vpath_mc, static) = {
373 .arc_name = "ip6-multicast",
Dave Barachd6534602016-06-14 18:38:02 -0400374 .node_name = "vpath-input-ip6",
Neale Ranns32e1c012016-11-22 17:07:28 +0000375 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
Dave Barachd6534602016-06-14 18:38:02 -0400376};
377
Neale Ranns8269d3d2018-01-30 09:02:20 -0800378VNET_FEATURE_INIT (ip6_not_enabled_mc, static) = {
Damjan Marion8b3191e2016-11-09 19:54:20 +0100379 .arc_name = "ip6-multicast",
Neale Ranns8269d3d2018-01-30 09:02:20 -0800380 .node_name = "ip6-not-enabled",
Neale Ranns630198f2017-05-22 09:20:20 -0400381 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
382};
383
384VNET_FEATURE_INIT (ip6_mc_lookup, static) = {
385 .arc_name = "ip6-multicast",
386 .node_name = "ip6-mfib-forward-lookup",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100387 .runs_before = 0, /* last feature */
Neale Ranns5e575b12016-10-03 09:40:25 +0100388};
Dave Barach5331c722016-08-17 11:54:30 -0400389
390/* Built-in ip4 tx feature path definition */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100391VNET_FEATURE_ARC_INIT (ip6_output, static) =
392{
393 .arc_name = "ip6-output",
Neale Rannsf068c3e2018-01-03 04:18:48 -0800394 .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain", "ip6-dvr-dpo"),
Damjan Marion8b3191e2016-11-09 19:54:20 +0100395 .arc_index_ptr = &ip6_main.lookup_main.output_feature_arc_index,
Dave Barach5331c722016-08-17 11:54:30 -0400396};
397
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100398VNET_FEATURE_INIT (ip6_outacl, static) = {
399 .arc_name = "ip6-output",
400 .node_name = "ip6-outacl",
401 .runs_before = VNET_FEATURES ("ipsec-output-ip6"),
402};
403
Matus Fabian08a6f012016-11-15 06:08:51 -0800404VNET_FEATURE_INIT (ip6_ipsec_output, static) = {
405 .arc_name = "ip6-output",
406 .node_name = "ipsec-output-ip6",
407 .runs_before = VNET_FEATURES ("interface-output"),
408};
409
Damjan Marion8b3191e2016-11-09 19:54:20 +0100410VNET_FEATURE_INIT (ip6_interface_output, static) = {
411 .arc_name = "ip6-output",
412 .node_name = "interface-output",
413 .runs_before = 0, /* not before any other features */
414};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500415/* *INDENT-ON* */
Dave Barachd6534602016-06-14 18:38:02 -0400416
Ed Warnickecb9cada2015-12-08 15:45:58 -0700417clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500418ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419{
Florin Corasb5c13fd2017-05-10 12:32:53 -0700420 ip6_main_t *im = &ip6_main;
421
422 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
423 vec_validate (im->mfib_index_by_sw_if_index, sw_if_index);
424
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +0200425 if (!is_add)
426 {
427 /* Ensure that IPv6 is disabled */
428 ip6_main_t *im6 = &ip6_main;
429 ip_lookup_main_t *lm6 = &im6->lookup_main;
430 ip_interface_address_t *ia = 0;
431 ip6_address_t *address;
432 vlib_main_t *vm = vlib_get_main ();
433
434 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, 0 /* is_add */ );
435 /* *INDENT-OFF* */
436 foreach_ip_interface_address (lm6, ia, sw_if_index, 1 /* honor unnumbered */,
437 ({
438 address = ip_interface_address_get_address (lm6, ia);
439 ip6_add_del_interface_address(vm, sw_if_index, address, ia->address_length, 1);
440 }));
441 /* *INDENT-ON* */
442 ip6_mfib_interface_enable_disable (sw_if_index, 0);
443 }
444
Neale Ranns8269d3d2018-01-30 09:02:20 -0800445 vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
Damjan Marion8b3191e2016-11-09 19:54:20 +0100446 is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700447
Neale Ranns8269d3d2018-01-30 09:02:20 -0800448 vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
449 sw_if_index, is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700450
Ed Warnickecb9cada2015-12-08 15:45:58 -0700451 return /* no error */ 0;
452}
453
454VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del);
455
Damjan Marionaca64c92016-04-13 09:48:56 +0200456static uword
457ip6_lookup (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500458 vlib_node_runtime_t * node, vlib_frame_t * frame)
Damjan Marionaca64c92016-04-13 09:48:56 +0200459{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100460 return ip6_lookup_inline (vm, node, frame);
Damjan Marionaca64c92016-04-13 09:48:56 +0200461}
462
Dave Barachd7cb1b52016-12-09 09:52:16 -0500463static u8 *format_ip6_lookup_trace (u8 * s, va_list * args);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100464
Dave Barachd7cb1b52016-12-09 09:52:16 -0500465/* *INDENT-OFF* */
466VLIB_REGISTER_NODE (ip6_lookup_node) =
467{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700468 .function = ip6_lookup,
469 .name = "ip6-lookup",
470 .vector_size = sizeof (u32),
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100471 .format_trace = format_ip6_lookup_trace,
Ole Troanf0f85222016-06-14 21:12:32 +0200472 .n_next_nodes = IP6_LOOKUP_N_NEXT,
Damjan Marionb2707892016-04-13 11:21:07 +0200473 .next_nodes = IP6_LOOKUP_NEXT_NODES,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700474};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500475/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700476
Dave Barachd7cb1b52016-12-09 09:52:16 -0500477VLIB_NODE_FUNCTION_MULTIARCH (ip6_lookup_node, ip6_lookup);
Damjan Marion1c80e832016-05-11 23:07:18 +0200478
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100479always_inline uword
480ip6_load_balance (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500481 vlib_node_runtime_t * node, vlib_frame_t * frame)
Damjan Marionaca64c92016-04-13 09:48:56 +0200482{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500483 vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters;
484 u32 n_left_from, n_left_to_next, *from, *to_next;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100485 ip_lookup_next_t next;
Damjan Marion586afd72017-04-05 19:18:20 +0200486 u32 thread_index = vlib_get_thread_index ();
Dave Barachd7cb1b52016-12-09 09:52:16 -0500487 ip6_main_t *im = &ip6_main;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100488
489 from = vlib_frame_vector_args (frame);
490 n_left_from = frame->n_vectors;
491 next = node->cached_next_index;
492
493 if (node->flags & VLIB_NODE_FLAG_TRACE)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500494 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100495
496 while (n_left_from > 0)
497 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500498 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100499
Dave Barach75fc8542016-10-11 16:16:02 -0400500
Neale Ranns2be95c12016-11-19 13:50:04 +0000501 while (n_left_from >= 4 && n_left_to_next >= 2)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500502 {
503 ip_lookup_next_t next0, next1;
504 const load_balance_t *lb0, *lb1;
505 vlib_buffer_t *p0, *p1;
506 u32 pi0, lbi0, hc0, pi1, lbi1, hc1;
507 const ip6_header_t *ip0, *ip1;
508 const dpo_id_t *dpo0, *dpo1;
Neale Ranns2be95c12016-11-19 13:50:04 +0000509
Dave Barachd7cb1b52016-12-09 09:52:16 -0500510 /* Prefetch next iteration. */
511 {
512 vlib_buffer_t *p2, *p3;
Neale Ranns2be95c12016-11-19 13:50:04 +0000513
Dave Barachd7cb1b52016-12-09 09:52:16 -0500514 p2 = vlib_get_buffer (vm, from[2]);
515 p3 = vlib_get_buffer (vm, from[3]);
Neale Ranns2be95c12016-11-19 13:50:04 +0000516
Dave Barachd7cb1b52016-12-09 09:52:16 -0500517 vlib_prefetch_buffer_header (p2, STORE);
518 vlib_prefetch_buffer_header (p3, STORE);
Neale Ranns2be95c12016-11-19 13:50:04 +0000519
Dave Barachd7cb1b52016-12-09 09:52:16 -0500520 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
521 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
522 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000523
Dave Barachd7cb1b52016-12-09 09:52:16 -0500524 pi0 = to_next[0] = from[0];
525 pi1 = to_next[1] = from[1];
Neale Ranns2be95c12016-11-19 13:50:04 +0000526
Dave Barachd7cb1b52016-12-09 09:52:16 -0500527 from += 2;
528 n_left_from -= 2;
529 to_next += 2;
530 n_left_to_next -= 2;
Neale Ranns2be95c12016-11-19 13:50:04 +0000531
Dave Barachd7cb1b52016-12-09 09:52:16 -0500532 p0 = vlib_get_buffer (vm, pi0);
533 p1 = vlib_get_buffer (vm, pi1);
Neale Ranns2be95c12016-11-19 13:50:04 +0000534
Dave Barachd7cb1b52016-12-09 09:52:16 -0500535 ip0 = vlib_buffer_get_current (p0);
536 ip1 = vlib_buffer_get_current (p1);
537 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
538 lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
Neale Ranns2be95c12016-11-19 13:50:04 +0000539
Dave Barachd7cb1b52016-12-09 09:52:16 -0500540 lb0 = load_balance_get (lbi0);
541 lb1 = load_balance_get (lbi1);
Neale Ranns2be95c12016-11-19 13:50:04 +0000542
Dave Barachd7cb1b52016-12-09 09:52:16 -0500543 /*
544 * this node is for via FIBs we can re-use the hash value from the
545 * to node if present.
546 * We don't want to use the same hash value at each level in the recursion
547 * graph as that would lead to polarisation
548 */
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000549 hc0 = hc1 = 0;
Neale Ranns2be95c12016-11-19 13:50:04 +0000550
Dave Barachd7cb1b52016-12-09 09:52:16 -0500551 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
552 {
553 if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
554 {
555 hc0 = vnet_buffer (p0)->ip.flow_hash =
556 vnet_buffer (p0)->ip.flow_hash >> 1;
557 }
558 else
559 {
560 hc0 = vnet_buffer (p0)->ip.flow_hash =
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000561 ip6_compute_flow_hash (ip0, lb0->lb_hash_config);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500562 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700563 dpo0 =
564 load_balance_get_fwd_bucket (lb0,
565 (hc0 &
566 lb0->lb_n_buckets_minus_1));
567 }
568 else
569 {
570 dpo0 = load_balance_get_bucket_i (lb0, 0);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500571 }
572 if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
573 {
574 if (PREDICT_TRUE (vnet_buffer (p1)->ip.flow_hash))
575 {
576 hc1 = vnet_buffer (p1)->ip.flow_hash =
577 vnet_buffer (p1)->ip.flow_hash >> 1;
578 }
579 else
580 {
581 hc1 = vnet_buffer (p1)->ip.flow_hash =
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000582 ip6_compute_flow_hash (ip1, lb1->lb_hash_config);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500583 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700584 dpo1 =
585 load_balance_get_fwd_bucket (lb1,
586 (hc1 &
587 lb1->lb_n_buckets_minus_1));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500588 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700589 else
590 {
591 dpo1 = load_balance_get_bucket_i (lb1, 0);
592 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000593
Dave Barachd7cb1b52016-12-09 09:52:16 -0500594 next0 = dpo0->dpoi_next_node;
595 next1 = dpo1->dpoi_next_node;
Neale Ranns2be95c12016-11-19 13:50:04 +0000596
Dave Barachd7cb1b52016-12-09 09:52:16 -0500597 /* Only process the HBH Option Header if explicitly configured to do so */
598 if (PREDICT_FALSE
599 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
600 {
601 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
602 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
603 }
604 /* Only process the HBH Option Header if explicitly configured to do so */
605 if (PREDICT_FALSE
606 (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
607 {
608 next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
609 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1;
610 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000611
Dave Barachd7cb1b52016-12-09 09:52:16 -0500612 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
613 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
Neale Ranns2be95c12016-11-19 13:50:04 +0000614
Dave Barachd7cb1b52016-12-09 09:52:16 -0500615 vlib_increment_combined_counter
Damjan Marion586afd72017-04-05 19:18:20 +0200616 (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500617 vlib_increment_combined_counter
Damjan Marion586afd72017-04-05 19:18:20 +0200618 (cm, thread_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
Neale Ranns2be95c12016-11-19 13:50:04 +0000619
Dave Barachd7cb1b52016-12-09 09:52:16 -0500620 vlib_validate_buffer_enqueue_x2 (vm, node, next,
621 to_next, n_left_to_next,
622 pi0, pi1, next0, next1);
623 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000624
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100625 while (n_left_from > 0 && n_left_to_next > 0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500626 {
627 ip_lookup_next_t next0;
628 const load_balance_t *lb0;
629 vlib_buffer_t *p0;
630 u32 pi0, lbi0, hc0;
631 const ip6_header_t *ip0;
632 const dpo_id_t *dpo0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100633
Dave Barachd7cb1b52016-12-09 09:52:16 -0500634 pi0 = from[0];
635 to_next[0] = pi0;
636 from += 1;
637 to_next += 1;
638 n_left_to_next -= 1;
639 n_left_from -= 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100640
Dave Barachd7cb1b52016-12-09 09:52:16 -0500641 p0 = vlib_get_buffer (vm, pi0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100642
Dave Barachd7cb1b52016-12-09 09:52:16 -0500643 ip0 = vlib_buffer_get_current (p0);
644 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100645
Dave Barachd7cb1b52016-12-09 09:52:16 -0500646 lb0 = load_balance_get (lbi0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100647
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000648 hc0 = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500649 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
650 {
651 if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
652 {
653 hc0 = vnet_buffer (p0)->ip.flow_hash =
654 vnet_buffer (p0)->ip.flow_hash >> 1;
655 }
656 else
657 {
658 hc0 = vnet_buffer (p0)->ip.flow_hash =
AkshayaNadahalli153b8712017-03-06 18:22:29 +0000659 ip6_compute_flow_hash (ip0, lb0->lb_hash_config);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500660 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700661 dpo0 =
662 load_balance_get_fwd_bucket (lb0,
663 (hc0 &
664 lb0->lb_n_buckets_minus_1));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500665 }
Neale Rannsf12a83f2017-04-18 09:09:40 -0700666 else
667 {
668 dpo0 = load_balance_get_bucket_i (lb0, 0);
669 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100670
Dave Barachd7cb1b52016-12-09 09:52:16 -0500671 next0 = dpo0->dpoi_next_node;
672 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
Neale Ranns2be95c12016-11-19 13:50:04 +0000673
Dave Barachd7cb1b52016-12-09 09:52:16 -0500674 /* Only process the HBH Option Header if explicitly configured to do so */
675 if (PREDICT_FALSE
676 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
677 {
678 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
679 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
680 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000681
Dave Barachd7cb1b52016-12-09 09:52:16 -0500682 vlib_increment_combined_counter
Damjan Marion586afd72017-04-05 19:18:20 +0200683 (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100684
Dave Barachd7cb1b52016-12-09 09:52:16 -0500685 vlib_validate_buffer_enqueue_x1 (vm, node, next,
686 to_next, n_left_to_next,
687 pi0, next0);
688 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100689
690 vlib_put_next_frame (vm, node, next, n_left_to_next);
691 }
692
693 return frame->n_vectors;
Damjan Marionaca64c92016-04-13 09:48:56 +0200694}
695
Dave Barachd7cb1b52016-12-09 09:52:16 -0500696/* *INDENT-OFF* */
697VLIB_REGISTER_NODE (ip6_load_balance_node) =
698{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100699 .function = ip6_load_balance,
700 .name = "ip6-load-balance",
Damjan Marionaca64c92016-04-13 09:48:56 +0200701 .vector_size = sizeof (u32),
Ole Troanf0f85222016-06-14 21:12:32 +0200702 .sibling_of = "ip6-lookup",
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100703 .format_trace = format_ip6_lookup_trace,
Damjan Marionaca64c92016-04-13 09:48:56 +0200704};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500705/* *INDENT-ON* */
Damjan Marionaca64c92016-04-13 09:48:56 +0200706
Dave Barachd7cb1b52016-12-09 09:52:16 -0500707VLIB_NODE_FUNCTION_MULTIARCH (ip6_load_balance_node, ip6_load_balance);
Damjan Marion1c80e832016-05-11 23:07:18 +0200708
Dave Barachd7cb1b52016-12-09 09:52:16 -0500709typedef struct
710{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700711 /* Adjacency taken. */
712 u32 adj_index;
713 u32 flow_hash;
John Lo2d343742016-01-19 17:27:17 -0500714 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700715
716 /* Packet data, possibly *after* rewrite. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500717 u8 packet_data[128 - 1 * sizeof (u32)];
718}
719ip6_forward_next_trace_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700720
John Lo2b81eb82017-01-30 13:12:10 -0500721u8 *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500722format_ip6_forward_next_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700723{
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100724 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
725 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500726 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200727 u32 indent = format_get_indent (s);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100728
Dave Barachd7cb1b52016-12-09 09:52:16 -0500729 s = format (s, "%U%U",
730 format_white_space, indent,
731 format_ip6_header, t->packet_data, sizeof (t->packet_data));
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100732 return s;
733}
734
Dave Barachd7cb1b52016-12-09 09:52:16 -0500735static u8 *
736format_ip6_lookup_trace (u8 * s, va_list * args)
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100737{
738 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
739 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500740 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200741 u32 indent = format_get_indent (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700742
John Loac8146c2016-09-27 17:44:02 -0400743 s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500744 t->fib_index, t->adj_index, t->flow_hash);
745 s = format (s, "\n%U%U",
746 format_white_space, indent,
747 format_ip6_header, t->packet_data, sizeof (t->packet_data));
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100748 return s;
749}
Pierre Pfister0febaf12016-06-08 12:23:21 +0100750
Ed Warnickecb9cada2015-12-08 15:45:58 -0700751
Dave Barachd7cb1b52016-12-09 09:52:16 -0500752static u8 *
753format_ip6_rewrite_trace (u8 * s, va_list * args)
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100754{
755 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
756 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500757 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200758 u32 indent = format_get_indent (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700759
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100760 s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500761 t->fib_index, t->adj_index, format_ip_adjacency,
762 t->adj_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100763 s = format (s, "\n%U%U",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500764 format_white_space, indent,
765 format_ip_adjacency_packet_data,
Neale Rannsb069a692017-03-15 12:34:25 -0400766 t->adj_index, t->packet_data, sizeof (t->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700767 return s;
768}
769
770/* Common trace function for all ip6-forward next nodes. */
771void
772ip6_forward_next_trace (vlib_main_t * vm,
773 vlib_node_runtime_t * node,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500774 vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700775{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500776 u32 *from, n_left;
777 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700778
779 n_left = frame->n_vectors;
780 from = vlib_frame_vector_args (frame);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100781
Ed Warnickecb9cada2015-12-08 15:45:58 -0700782 while (n_left >= 4)
783 {
784 u32 bi0, bi1;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500785 vlib_buffer_t *b0, *b1;
786 ip6_forward_next_trace_t *t0, *t1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700787
788 /* Prefetch next iteration. */
789 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
790 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
791
792 bi0 = from[0];
793 bi1 = from[1];
794
795 b0 = vlib_get_buffer (vm, bi0);
796 b1 = vlib_get_buffer (vm, bi1);
797
798 if (b0->flags & VLIB_BUFFER_IS_TRACED)
799 {
800 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
801 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500802 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
803 t0->fib_index =
804 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
805 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
806 vec_elt (im->fib_index_by_sw_if_index,
807 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100808
Damjan Marionf1213b82016-03-13 02:22:06 +0100809 clib_memcpy (t0->packet_data,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500810 vlib_buffer_get_current (b0),
811 sizeof (t0->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700812 }
813 if (b1->flags & VLIB_BUFFER_IS_TRACED)
814 {
815 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
816 t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500817 t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
818 t1->fib_index =
819 (vnet_buffer (b1)->sw_if_index[VLIB_TX] !=
820 (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] :
821 vec_elt (im->fib_index_by_sw_if_index,
822 vnet_buffer (b1)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100823
Damjan Marionf1213b82016-03-13 02:22:06 +0100824 clib_memcpy (t1->packet_data,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500825 vlib_buffer_get_current (b1),
826 sizeof (t1->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700827 }
828 from += 2;
829 n_left -= 2;
830 }
831
832 while (n_left >= 1)
833 {
834 u32 bi0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500835 vlib_buffer_t *b0;
836 ip6_forward_next_trace_t *t0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700837
838 bi0 = from[0];
839
840 b0 = vlib_get_buffer (vm, bi0);
841
842 if (b0->flags & VLIB_BUFFER_IS_TRACED)
843 {
844 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
845 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500846 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
847 t0->fib_index =
848 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
849 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
850 vec_elt (im->fib_index_by_sw_if_index,
851 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100852
Damjan Marionf1213b82016-03-13 02:22:06 +0100853 clib_memcpy (t0->packet_data,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500854 vlib_buffer_get_current (b0),
855 sizeof (t0->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700856 }
857 from += 1;
858 n_left -= 1;
859 }
860}
861
Ed Warnickecb9cada2015-12-08 15:45:58 -0700862/* Compute TCP/UDP/ICMP6 checksum in software. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500863u16
864ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
865 ip6_header_t * ip0, int *bogus_lengthp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700866{
867 ip_csum_t sum0;
868 u16 sum16, payload_length_host_byte_order;
869 u32 i, n_this_buffer, n_bytes_left;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500870 u32 headers_size = sizeof (ip0[0]);
871 void *data_this_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700872
Dave Barachd7cb1b52016-12-09 09:52:16 -0500873 ASSERT (bogus_lengthp);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700874 *bogus_lengthp = 0;
875
876 /* Initialize checksum with ip header. */
877 sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol);
878 payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
879 data_this_buffer = (void *) (ip0 + 1);
Dave Barach75fc8542016-10-11 16:16:02 -0400880
Ed Warnickecb9cada2015-12-08 15:45:58 -0700881 for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
882 {
883 sum0 = ip_csum_with_carry (sum0,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500884 clib_mem_unaligned (&ip0->
885 src_address.as_uword[i],
886 uword));
887 sum0 =
888 ip_csum_with_carry (sum0,
889 clib_mem_unaligned (&ip0->dst_address.as_uword[i],
890 uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700891 }
892
AkshayaNadahalli1b563522017-01-23 22:05:35 +0530893 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets)
894 * or UDP-Ping packets */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500895 if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700896 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500897 u32 skip_bytes;
898 ip6_hop_by_hop_ext_t *ext_hdr =
899 (ip6_hop_by_hop_ext_t *) data_this_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700900
901 /* validate really icmp6 next */
AkshayaNadahalli1b563522017-01-23 22:05:35 +0530902 ASSERT ((ext_hdr->next_hdr == IP_PROTOCOL_ICMP6)
903 || (ext_hdr->next_hdr == IP_PROTOCOL_UDP));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700904
Dave Barachd7cb1b52016-12-09 09:52:16 -0500905 skip_bytes = 8 * (1 + ext_hdr->n_data_u64s);
906 data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes);
Dave Barach75fc8542016-10-11 16:16:02 -0400907
Dave Barachd7cb1b52016-12-09 09:52:16 -0500908 payload_length_host_byte_order -= skip_bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700909 headers_size += skip_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500910 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700911
912 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500913 if (p0 && n_this_buffer + headers_size > p0->current_length)
914 n_this_buffer =
915 p0->current_length >
916 headers_size ? p0->current_length - headers_size : 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700917 while (1)
918 {
919 sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
920 n_bytes_left -= n_this_buffer;
921 if (n_bytes_left == 0)
922 break;
923
924 if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500925 {
926 *bogus_lengthp = 1;
927 return 0xfefe;
928 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700929 p0 = vlib_get_buffer (vm, p0->next_buffer);
930 data_this_buffer = vlib_buffer_get_current (p0);
931 n_this_buffer = p0->current_length;
932 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700933
Dave Barachd7cb1b52016-12-09 09:52:16 -0500934 sum16 = ~ip_csum_fold (sum0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700935
936 return sum16;
937}
938
Dave Barachd7cb1b52016-12-09 09:52:16 -0500939u32
940ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700941{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500942 ip6_header_t *ip0 = vlib_buffer_get_current (p0);
943 udp_header_t *udp0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700944 u16 sum16;
945 int bogus_length;
946
947 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
948 ASSERT (ip0->protocol == IP_PROTOCOL_TCP
949 || ip0->protocol == IP_PROTOCOL_ICMP6
950 || ip0->protocol == IP_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -0500951 || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700952
953 udp0 = (void *) (ip0 + 1);
954 if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0)
955 {
Damjan Marion213b5aa2017-07-13 21:19:27 +0200956 p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED
957 | VNET_BUFFER_F_L4_CHECKSUM_CORRECT);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700958 return p0->flags;
959 }
960
961 sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length);
962
Damjan Marion213b5aa2017-07-13 21:19:27 +0200963 p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED
964 | ((sum16 == 0) << VNET_BUFFER_F_LOG2_L4_CHECKSUM_CORRECT));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700965
966 return p0->flags;
967}
968
AkshayaNadahalli0f438df2017-02-10 10:54:16 +0530969/**
970 * @brief returns number of links on which src is reachable.
971 */
972always_inline int
973ip6_urpf_loose_check (ip6_main_t * im, vlib_buffer_t * b, ip6_header_t * i)
974{
975 const load_balance_t *lb0;
976 index_t lbi;
977
978 lbi = ip6_fib_table_fwding_lookup_with_if_index (im,
979 vnet_buffer
980 (b)->sw_if_index[VLIB_RX],
981 &i->src_address);
982
983 lb0 = load_balance_get (lbi);
984
985 return (fib_urpf_check_size (lb0->lb_urpf));
986}
987
rootc9d1c5b2017-08-15 12:58:31 -0400988always_inline u8
989ip6_next_proto_is_tcp_udp (vlib_buffer_t * p0, ip6_header_t * ip0,
990 u32 * udp_offset0)
991{
992 u32 proto0;
993 proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_UDP, udp_offset0);
994 if (proto0 != IP_PROTOCOL_UDP)
995 {
996 proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_TCP, udp_offset0);
997 proto0 = (proto0 == IP_PROTOCOL_TCP) ? proto0 : 0;
998 }
999 return proto0;
1000}
1001
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001002/* *INDENT-OFF* */
1003VNET_FEATURE_ARC_INIT (ip6_local) =
1004{
1005 .arc_name = "ip6-local",
1006 .start_nodes = VNET_FEATURES ("ip6-local"),
1007};
1008/* *INDENT-ON* */
1009
Ed Warnickecb9cada2015-12-08 15:45:58 -07001010static uword
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001011ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1012 vlib_frame_t * frame, int head_of_feature_arc)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001013{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001014 ip6_main_t *im = &ip6_main;
1015 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001016 ip_local_next_t next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001017 u32 *from, *to_next, n_left_from, n_left_to_next;
1018 vlib_node_runtime_t *error_node =
1019 vlib_node_get_runtime (vm, ip6_input_node.index);
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001020 u8 arc_index = vnet_feat_arc_ip6_local.feature_arc_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001021
1022 from = vlib_frame_vector_args (frame);
1023 n_left_from = frame->n_vectors;
1024 next_index = node->cached_next_index;
Dave Barach75fc8542016-10-11 16:16:02 -04001025
Ed Warnickecb9cada2015-12-08 15:45:58 -07001026 if (node->flags & VLIB_NODE_FLAG_TRACE)
1027 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1028
1029 while (n_left_from > 0)
1030 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001031 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001032
1033 while (n_left_from >= 4 && n_left_to_next >= 2)
1034 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001035 vlib_buffer_t *p0, *p1;
1036 ip6_header_t *ip0, *ip1;
1037 udp_header_t *udp0, *udp1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001038 u32 pi0, ip_len0, udp_len0, flags0, next0;
1039 u32 pi1, ip_len1, udp_len1, flags1, next1;
1040 i32 len_diff0, len_diff1;
rootc9d1c5b2017-08-15 12:58:31 -04001041 u8 error0, type0, good_l4_csum0, is_tcp_udp0;
1042 u8 error1, type1, good_l4_csum1, is_tcp_udp1;
Shwethab78292e2016-09-13 11:51:00 +01001043 u32 udp_offset0, udp_offset1;
Dave Barach75fc8542016-10-11 16:16:02 -04001044
Ed Warnickecb9cada2015-12-08 15:45:58 -07001045 pi0 = to_next[0] = from[0];
1046 pi1 = to_next[1] = from[1];
1047 from += 2;
1048 n_left_from -= 2;
1049 to_next += 2;
1050 n_left_to_next -= 2;
Dave Barach75fc8542016-10-11 16:16:02 -04001051
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001052 error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL;
1053
Ed Warnickecb9cada2015-12-08 15:45:58 -07001054 p0 = vlib_get_buffer (vm, pi0);
1055 p1 = vlib_get_buffer (vm, pi1);
1056
1057 ip0 = vlib_buffer_get_current (p0);
1058 ip1 = vlib_buffer_get_current (p1);
1059
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001060 if (head_of_feature_arc == 0)
1061 goto skip_checks;
1062
Damjan Marion072401e2017-07-13 18:53:27 +02001063 vnet_buffer (p0)->l3_hdr_offset = p0->current_data;
1064 vnet_buffer (p1)->l3_hdr_offset = p1->current_data;
Filip Tehlarb601f222017-01-02 10:22:56 +01001065
Ed Warnickecb9cada2015-12-08 15:45:58 -07001066 type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
1067 type1 = lm->builtin_protocol_by_ip_protocol[ip1->protocol];
1068
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069 flags0 = p0->flags;
1070 flags1 = p1->flags;
1071
rootc9d1c5b2017-08-15 12:58:31 -04001072 is_tcp_udp0 = ip6_next_proto_is_tcp_udp (p0, ip0, &udp_offset0);
1073 is_tcp_udp1 = ip6_next_proto_is_tcp_udp (p1, ip1, &udp_offset1);
1074
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001075 good_l4_csum0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
Jakub Grajciar2eeeb4b2017-11-07 14:39:10 +01001076 || (flags0 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
1077 || flags0 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001078 != 0;
1079 good_l4_csum1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
Jakub Grajciar2eeeb4b2017-11-07 14:39:10 +01001080 || (flags1 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
1081 || flags1 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001082 != 0;
Shwethab78292e2016-09-13 11:51:00 +01001083 len_diff0 = 0;
1084 len_diff1 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001085
rootc9d1c5b2017-08-15 12:58:31 -04001086 if (PREDICT_TRUE (is_tcp_udp0))
Shwethab78292e2016-09-13 11:51:00 +01001087 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001088 udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0);
Shwethab78292e2016-09-13 11:51:00 +01001089 /* Don't verify UDP checksum for packets with explicit zero checksum. */
rootc9d1c5b2017-08-15 12:58:31 -04001090 good_l4_csum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001091 && udp0->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001092 /* Verify UDP length. */
rootc9d1c5b2017-08-15 12:58:31 -04001093 if (is_tcp_udp0 == IP_PROTOCOL_UDP)
1094 {
1095 ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1096 udp_len0 = clib_net_to_host_u16 (udp0->length);
1097 len_diff0 = ip_len0 - udp_len0;
1098 }
Shwethab78292e2016-09-13 11:51:00 +01001099 }
rootc9d1c5b2017-08-15 12:58:31 -04001100 if (PREDICT_TRUE (is_tcp_udp1))
Shwethab78292e2016-09-13 11:51:00 +01001101 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001102 udp1 = (udp_header_t *) ((u8 *) ip1 + udp_offset1);
Shwethab78292e2016-09-13 11:51:00 +01001103 /* Don't verify UDP checksum for packets with explicit zero checksum. */
rootc9d1c5b2017-08-15 12:58:31 -04001104 good_l4_csum1 |= type1 == IP_BUILTIN_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001105 && udp1->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001106 /* Verify UDP length. */
rootc9d1c5b2017-08-15 12:58:31 -04001107 if (is_tcp_udp1 == IP_PROTOCOL_UDP)
1108 {
1109 ip_len1 = clib_net_to_host_u16 (ip1->payload_length);
1110 udp_len1 = clib_net_to_host_u16 (udp1->length);
1111 len_diff1 = ip_len1 - udp_len1;
1112 }
Shwethab78292e2016-09-13 11:51:00 +01001113 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001114
rootc9d1c5b2017-08-15 12:58:31 -04001115 good_l4_csum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1116 good_l4_csum1 |= type1 == IP_BUILTIN_PROTOCOL_UNKNOWN;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117
Ed Warnickecb9cada2015-12-08 15:45:58 -07001118 len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1119 len_diff1 = type1 == IP_BUILTIN_PROTOCOL_UDP ? len_diff1 : 0;
1120
1121 if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
rootc9d1c5b2017-08-15 12:58:31 -04001122 && !good_l4_csum0
Damjan Marion213b5aa2017-07-13 21:19:27 +02001123 && !(flags0 &
1124 VNET_BUFFER_F_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001125 {
1126 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
rootc9d1c5b2017-08-15 12:58:31 -04001127 good_l4_csum0 =
Damjan Marion213b5aa2017-07-13 21:19:27 +02001128 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001129 }
1130 if (PREDICT_FALSE (type1 != IP_BUILTIN_PROTOCOL_UNKNOWN
rootc9d1c5b2017-08-15 12:58:31 -04001131 && !good_l4_csum1
Damjan Marion213b5aa2017-07-13 21:19:27 +02001132 && !(flags1 &
1133 VNET_BUFFER_F_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001134 {
1135 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, p1);
rootc9d1c5b2017-08-15 12:58:31 -04001136 good_l4_csum1 =
Damjan Marion213b5aa2017-07-13 21:19:27 +02001137 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001138 }
1139
1140 error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001141 error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1142 error1 = len_diff1 < 0 ? IP6_ERROR_UDP_LENGTH : error1;
1143
Dave Barachd7cb1b52016-12-09 09:52:16 -05001144 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1145 IP6_ERROR_UDP_CHECKSUM);
1146 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1147 IP6_ERROR_ICMP_CHECKSUM);
rootc9d1c5b2017-08-15 12:58:31 -04001148 error0 = (!good_l4_csum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0);
1149 error1 = (!good_l4_csum1 ? IP6_ERROR_UDP_CHECKSUM + type1 : error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001150
1151 /* Drop packets from unroutable hosts. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001152 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001153 if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1154 type0 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001155 !ip6_address_is_link_local_unicast (&ip0->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001156 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301157 error0 = (!ip6_urpf_loose_check (im, p0, ip0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001158 ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001159 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001160 if (error1 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1161 type1 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001162 !ip6_address_is_link_local_unicast (&ip1->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001163 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301164 error1 = (!ip6_urpf_loose_check (im, p1, ip1)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001165 ? IP6_ERROR_SRC_LOOKUP_MISS : error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001166 }
1167
Florin Corascea194d2017-10-02 00:18:51 -07001168 /* TODO maybe move to lookup? */
1169 vnet_buffer (p0)->ip.fib_index =
1170 vec_elt (im->fib_index_by_sw_if_index,
1171 vnet_buffer (p0)->sw_if_index[VLIB_RX]);
1172 vnet_buffer (p0)->ip.fib_index =
1173 (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
1174 (u32) ~ 0) ? vnet_buffer (p0)->ip.
1175 fib_index : vnet_buffer (p0)->sw_if_index[VLIB_TX];
1176
1177 vnet_buffer (p1)->ip.fib_index =
1178 vec_elt (im->fib_index_by_sw_if_index,
1179 vnet_buffer (p1)->sw_if_index[VLIB_RX]);
1180 vnet_buffer (p1)->ip.fib_index =
1181 (vnet_buffer (p1)->sw_if_index[VLIB_TX] ==
1182 (u32) ~ 0) ? vnet_buffer (p1)->ip.
1183 fib_index : vnet_buffer (p1)->sw_if_index[VLIB_TX];
1184
1185
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001186 skip_checks:
1187
1188 next0 = lm->local_next_by_ip_protocol[ip0->protocol];
1189 next1 = lm->local_next_by_ip_protocol[ip1->protocol];
1190
Dave Barachd7cb1b52016-12-09 09:52:16 -05001191 next0 =
1192 error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
1193 next1 =
1194 error1 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001195
1196 p0->error = error_node->errors[error0];
1197 p1->error = error_node->errors[error1];
1198
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001199 if (head_of_feature_arc)
1200 {
1201 if (PREDICT_TRUE (error0 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
1202 vnet_feature_arc_start (arc_index,
1203 vnet_buffer (p0)->sw_if_index
1204 [VLIB_RX], &next0, p0);
1205 if (PREDICT_TRUE (error1 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
1206 vnet_feature_arc_start (arc_index,
1207 vnet_buffer (p1)->sw_if_index
1208 [VLIB_RX], &next1, p1);
1209 }
1210
Ed Warnickecb9cada2015-12-08 15:45:58 -07001211 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1212 to_next, n_left_to_next,
1213 pi0, pi1, next0, next1);
1214 }
1215
1216 while (n_left_from > 0 && n_left_to_next > 0)
1217 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001218 vlib_buffer_t *p0;
1219 ip6_header_t *ip0;
1220 udp_header_t *udp0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001221 u32 pi0, ip_len0, udp_len0, flags0, next0;
1222 i32 len_diff0;
rootc9d1c5b2017-08-15 12:58:31 -04001223 u8 error0, type0, good_l4_csum0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001224 u32 udp_offset0;
rootc9d1c5b2017-08-15 12:58:31 -04001225 u8 is_tcp_udp0;
Dave Barach75fc8542016-10-11 16:16:02 -04001226
Ed Warnickecb9cada2015-12-08 15:45:58 -07001227 pi0 = to_next[0] = from[0];
1228 from += 1;
1229 n_left_from -= 1;
1230 to_next += 1;
1231 n_left_to_next -= 1;
Dave Barach75fc8542016-10-11 16:16:02 -04001232
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001233 error0 = IP6_ERROR_UNKNOWN_PROTOCOL;
1234
Ed Warnickecb9cada2015-12-08 15:45:58 -07001235 p0 = vlib_get_buffer (vm, pi0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001236 ip0 = vlib_buffer_get_current (p0);
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001237
1238 if (head_of_feature_arc == 0)
1239 goto skip_check;
1240
Damjan Marion072401e2017-07-13 18:53:27 +02001241 vnet_buffer (p0)->l3_hdr_offset = p0->current_data;
Filip Tehlarb601f222017-01-02 10:22:56 +01001242
Ed Warnickecb9cada2015-12-08 15:45:58 -07001243 type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001244 flags0 = p0->flags;
rootc9d1c5b2017-08-15 12:58:31 -04001245 is_tcp_udp0 = ip6_next_proto_is_tcp_udp (p0, ip0, &udp_offset0);
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001246 good_l4_csum0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
Jakub Grajciar2eeeb4b2017-11-07 14:39:10 +01001247 || (flags0 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
1248 || flags0 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
Jakub Grajciar96be8e82017-10-30 14:56:17 +01001249 != 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001250
Shwethab78292e2016-09-13 11:51:00 +01001251 len_diff0 = 0;
rootc9d1c5b2017-08-15 12:58:31 -04001252 if (PREDICT_TRUE (is_tcp_udp0))
Shwethab78292e2016-09-13 11:51:00 +01001253 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001254 udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0);
rootc9d1c5b2017-08-15 12:58:31 -04001255 /* Don't verify UDP checksum for packets with explicit zero
1256 * checksum. */
1257 good_l4_csum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001258 && udp0->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001259 /* Verify UDP length. */
rootc9d1c5b2017-08-15 12:58:31 -04001260 if (is_tcp_udp0 == IP_PROTOCOL_UDP)
1261 {
1262 ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1263 udp_len0 = clib_net_to_host_u16 (udp0->length);
1264 len_diff0 = ip_len0 - udp_len0;
1265 }
Shwethab78292e2016-09-13 11:51:00 +01001266 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001267
rootc9d1c5b2017-08-15 12:58:31 -04001268 good_l4_csum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001269 len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1270
1271 if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
rootc9d1c5b2017-08-15 12:58:31 -04001272 && !good_l4_csum0
Damjan Marion213b5aa2017-07-13 21:19:27 +02001273 && !(flags0 &
1274 VNET_BUFFER_F_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001275 {
1276 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
rootc9d1c5b2017-08-15 12:58:31 -04001277 good_l4_csum0 =
Damjan Marion213b5aa2017-07-13 21:19:27 +02001278 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001279 }
1280
1281 error0 = IP6_ERROR_UNKNOWN_PROTOCOL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001282 error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1283
Dave Barachd7cb1b52016-12-09 09:52:16 -05001284 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1285 IP6_ERROR_UDP_CHECKSUM);
1286 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1287 IP6_ERROR_ICMP_CHECKSUM);
rootc9d1c5b2017-08-15 12:58:31 -04001288 error0 = (!good_l4_csum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001289
rootc9d1c5b2017-08-15 12:58:31 -04001290 /* If this is a neighbor solicitation (ICMP), skip src RPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001291 if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1292 type0 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001293 !ip6_address_is_link_local_unicast (&ip0->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001294 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301295 error0 = (!ip6_urpf_loose_check (im, p0, ip0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001296 ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001297 }
1298
Florin Corascea194d2017-10-02 00:18:51 -07001299 vnet_buffer (p0)->ip.fib_index =
1300 vec_elt (im->fib_index_by_sw_if_index,
1301 vnet_buffer (p0)->sw_if_index[VLIB_RX]);
1302 vnet_buffer (p0)->ip.fib_index =
1303 (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
1304 (u32) ~ 0) ? vnet_buffer (p0)->ip.
1305 fib_index : vnet_buffer (p0)->sw_if_index[VLIB_TX];
1306
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001307 skip_check:
1308
1309 next0 = lm->local_next_by_ip_protocol[ip0->protocol];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001310 next0 =
1311 error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
Klement Sekera75e7d132017-09-20 08:26:30 +02001312
Ed Warnickecb9cada2015-12-08 15:45:58 -07001313 p0->error = error_node->errors[error0];
1314
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001315 if (head_of_feature_arc)
1316 {
1317 if (PREDICT_TRUE (error0 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
1318 vnet_feature_arc_start (arc_index,
1319 vnet_buffer (p0)->sw_if_index
1320 [VLIB_RX], &next0, p0);
1321 }
1322
Ed Warnickecb9cada2015-12-08 15:45:58 -07001323 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1324 to_next, n_left_to_next,
1325 pi0, next0);
1326 }
Dave Barach75fc8542016-10-11 16:16:02 -04001327
Ed Warnickecb9cada2015-12-08 15:45:58 -07001328 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1329 }
1330
1331 return frame->n_vectors;
1332}
1333
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001334static uword
1335ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1336{
1337 return ip6_local_inline (vm, node, frame, 1 /* head of feature arc */ );
1338}
1339
Dave Barachd7cb1b52016-12-09 09:52:16 -05001340/* *INDENT-OFF* */
1341VLIB_REGISTER_NODE (ip6_local_node, static) =
1342{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001343 .function = ip6_local,
1344 .name = "ip6-local",
1345 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -07001346 .format_trace = format_ip6_forward_next_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001347 .n_next_nodes = IP_LOCAL_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001348 .next_nodes =
1349 {
Neale Rannsd91c1db2017-07-31 02:30:50 -07001350 [IP_LOCAL_NEXT_DROP] = "ip6-drop",
1351 [IP_LOCAL_NEXT_PUNT] = "ip6-punt",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001352 [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
1353 [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
Klement Sekera75e7d132017-09-20 08:26:30 +02001354 [IP_LOCAL_NEXT_REASSEMBLY] = "ip6-reassembly",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001355 },
1356};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001357/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001358
Dave Barachd7cb1b52016-12-09 09:52:16 -05001359VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_node, ip6_local);
Damjan Marion1c80e832016-05-11 23:07:18 +02001360
Pierre Pfister1bfd3722017-09-18 11:40:32 +02001361
1362static uword
1363ip6_local_end_of_arc (vlib_main_t * vm,
1364 vlib_node_runtime_t * node, vlib_frame_t * frame)
1365{
1366 return ip6_local_inline (vm, node, frame, 0 /* head of feature arc */ );
1367}
1368
1369/* *INDENT-OFF* */
1370VLIB_REGISTER_NODE (ip6_local_end_of_arc_node,static) = {
1371 .function = ip6_local_end_of_arc,
1372 .name = "ip6-local-end-of-arc",
1373 .vector_size = sizeof (u32),
1374
1375 .format_trace = format_ip6_forward_next_trace,
1376 .sibling_of = "ip6-local",
1377};
1378
1379VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_end_of_arc_node, ip6_local_end_of_arc)
1380
1381VNET_FEATURE_INIT (ip6_local_end_of_arc, static) = {
1382 .arc_name = "ip6-local",
1383 .node_name = "ip6-local-end-of-arc",
1384 .runs_before = 0, /* not before any other features */
1385};
1386/* *INDENT-ON* */
1387
Dave Barachd7cb1b52016-12-09 09:52:16 -05001388void
1389ip6_register_protocol (u32 protocol, u32 node_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001390{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001391 vlib_main_t *vm = vlib_get_main ();
1392 ip6_main_t *im = &ip6_main;
1393 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001394
1395 ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
Dave Barachd7cb1b52016-12-09 09:52:16 -05001396 lm->local_next_by_ip_protocol[protocol] =
1397 vlib_node_add_next (vm, ip6_local_node.index, node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001398}
1399
Dave Barachd7cb1b52016-12-09 09:52:16 -05001400typedef enum
1401{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001402 IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
John Lod1f5d042016-04-12 18:20:39 -04001403 IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001404 IP6_DISCOVER_NEIGHBOR_N_NEXT,
1405} ip6_discover_neighbor_next_t;
1406
Dave Barachd7cb1b52016-12-09 09:52:16 -05001407typedef enum
1408{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001409 IP6_DISCOVER_NEIGHBOR_ERROR_DROP,
1410 IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT,
Pierre Pfisterd076f192016-06-22 12:58:30 +01001411 IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001412} ip6_discover_neighbor_error_t;
1413
1414static uword
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001415ip6_discover_neighbor_inline (vlib_main_t * vm,
1416 vlib_node_runtime_t * node,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001417 vlib_frame_t * frame, int is_glean)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001418{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001419 vnet_main_t *vnm = vnet_get_main ();
1420 ip6_main_t *im = &ip6_main;
1421 ip_lookup_main_t *lm = &im->lookup_main;
1422 u32 *from, *to_next_drop;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001423 uword n_left_from, n_left_to_next_drop;
1424 static f64 time_last_seed_change = -1e100;
1425 static u32 hash_seeds[3];
Dave Barach75fc8542016-10-11 16:16:02 -04001426 static uword hash_bitmap[256 / BITS (uword)];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001427 f64 time_now;
1428 int bogus_length;
1429
1430 if (node->flags & VLIB_NODE_FLAG_TRACE)
1431 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1432
1433 time_now = vlib_time_now (vm);
1434 if (time_now - time_last_seed_change > 1e-3)
1435 {
1436 uword i;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001437 u32 *r = clib_random_buffer_get_data (&vm->random_buffer,
1438 sizeof (hash_seeds));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001439 for (i = 0; i < ARRAY_LEN (hash_seeds); i++)
1440 hash_seeds[i] = r[i];
1441
1442 /* Mark all hash keys as been not-seen before. */
1443 for (i = 0; i < ARRAY_LEN (hash_bitmap); i++)
1444 hash_bitmap[i] = 0;
1445
1446 time_last_seed_change = time_now;
1447 }
1448
1449 from = vlib_frame_vector_args (frame);
1450 n_left_from = frame->n_vectors;
1451
1452 while (n_left_from > 0)
1453 {
1454 vlib_get_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
1455 to_next_drop, n_left_to_next_drop);
1456
1457 while (n_left_from > 0 && n_left_to_next_drop > 0)
1458 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001459 vlib_buffer_t *p0;
1460 ip6_header_t *ip0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001461 u32 pi0, adj_index0, a0, b0, c0, m0, sw_if_index0, drop0;
1462 uword bm0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001463 ip_adjacency_t *adj0;
1464 vnet_hw_interface_t *hw_if0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001465 u32 next0;
1466
1467 pi0 = from[0];
1468
1469 p0 = vlib_get_buffer (vm, pi0);
1470
1471 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1472
1473 ip0 = vlib_buffer_get_current (p0);
1474
Neale Ranns107e7d42017-04-11 09:55:19 -07001475 adj0 = adj_get (adj_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001476
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001477 if (!is_glean)
1478 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001479 ip0->dst_address.as_u64[0] =
1480 adj0->sub_type.nbr.next_hop.ip6.as_u64[0];
1481 ip0->dst_address.as_u64[1] =
1482 adj0->sub_type.nbr.next_hop.ip6.as_u64[1];
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001483 }
Pierre Pfister1dabaaf2016-04-25 14:15:15 +01001484
Ed Warnickecb9cada2015-12-08 15:45:58 -07001485 a0 = hash_seeds[0];
1486 b0 = hash_seeds[1];
1487 c0 = hash_seeds[2];
1488
1489 sw_if_index0 = adj0->rewrite_header.sw_if_index;
1490 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
1491
1492 a0 ^= sw_if_index0;
1493 b0 ^= ip0->dst_address.as_u32[0];
1494 c0 ^= ip0->dst_address.as_u32[1];
1495
1496 hash_v3_mix32 (a0, b0, c0);
1497
1498 b0 ^= ip0->dst_address.as_u32[2];
1499 c0 ^= ip0->dst_address.as_u32[3];
1500
1501 hash_v3_finalize32 (a0, b0, c0);
1502
1503 c0 &= BITS (hash_bitmap) - 1;
1504 c0 = c0 / BITS (uword);
1505 m0 = (uword) 1 << (c0 % BITS (uword));
1506
1507 bm0 = hash_bitmap[c0];
1508 drop0 = (bm0 & m0) != 0;
1509
1510 /* Mark it as seen. */
1511 hash_bitmap[c0] = bm0 | m0;
1512
1513 from += 1;
1514 n_left_from -= 1;
1515 to_next_drop[0] = pi0;
1516 to_next_drop += 1;
1517 n_left_to_next_drop -= 1;
1518
Dave Barachd7cb1b52016-12-09 09:52:16 -05001519 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001520
Dave Barachd7cb1b52016-12-09 09:52:16 -05001521 /* If the interface is link-down, drop the pkt */
1522 if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
1523 drop0 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001524
Dave Barach75fc8542016-10-11 16:16:02 -04001525 p0->error =
Dave Barachd7cb1b52016-12-09 09:52:16 -05001526 node->errors[drop0 ? IP6_DISCOVER_NEIGHBOR_ERROR_DROP
1527 : IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001528 if (drop0)
1529 continue;
1530
Neale Rannsb80c5362016-10-08 13:03:40 +01001531 /*
1532 * the adj has been updated to a rewrite but the node the DPO that got
1533 * us here hasn't - yet. no big deal. we'll drop while we wait.
1534 */
1535 if (IP_LOOKUP_NEXT_REWRITE == adj0->lookup_next_index)
1536 continue;
1537
Ed Warnickecb9cada2015-12-08 15:45:58 -07001538 {
1539 u32 bi0 = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001540 icmp6_neighbor_solicitation_header_t *h0;
1541 vlib_buffer_t *b0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001542
Dave Barach75fc8542016-10-11 16:16:02 -04001543 h0 = vlib_packet_template_get_packet
Dave Barachd7cb1b52016-12-09 09:52:16 -05001544 (vm, &im->discover_neighbor_packet_template, &bi0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001545
Dave Barach75fc8542016-10-11 16:16:02 -04001546 /*
Dave Barachd7cb1b52016-12-09 09:52:16 -05001547 * Build ethernet header.
1548 * Choose source address based on destination lookup
1549 * adjacency.
1550 */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001551 if (ip6_src_address_for_packet (lm,
1552 sw_if_index0,
1553 &h0->ip.src_address))
1554 {
1555 /* There is no address on the interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001556 p0->error =
1557 node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS];
1558 vlib_buffer_free (vm, &bi0, 1);
Pierre Pfisterd076f192016-06-22 12:58:30 +01001559 continue;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001560 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001561
Dave Barach75fc8542016-10-11 16:16:02 -04001562 /*
Dave Barachd7cb1b52016-12-09 09:52:16 -05001563 * Destination address is a solicited node multicast address.
1564 * We need to fill in
1565 * the low 24 bits with low 24 bits of target's address.
1566 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001567 h0->ip.dst_address.as_u8[13] = ip0->dst_address.as_u8[13];
1568 h0->ip.dst_address.as_u8[14] = ip0->dst_address.as_u8[14];
1569 h0->ip.dst_address.as_u8[15] = ip0->dst_address.as_u8[15];
1570
1571 h0->neighbor.target_address = ip0->dst_address;
1572
Dave Barach75fc8542016-10-11 16:16:02 -04001573 clib_memcpy (h0->link_layer_option.ethernet_address,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001574 hw_if0->hw_address, vec_len (hw_if0->hw_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001575
Dave Barachd7cb1b52016-12-09 09:52:16 -05001576 /* $$$$ appears we need this; why is the checksum non-zero? */
1577 h0->neighbor.icmp.checksum = 0;
Dave Barach75fc8542016-10-11 16:16:02 -04001578 h0->neighbor.icmp.checksum =
Dave Barachd7cb1b52016-12-09 09:52:16 -05001579 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip,
1580 &bogus_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001581
Dave Barachd7cb1b52016-12-09 09:52:16 -05001582 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001583
1584 vlib_buffer_copy_trace_flag (vm, p0, bi0);
1585 b0 = vlib_get_buffer (vm, bi0);
Dave Barach75fc8542016-10-11 16:16:02 -04001586 vnet_buffer (b0)->sw_if_index[VLIB_TX]
Dave Barachd7cb1b52016-12-09 09:52:16 -05001587 = vnet_buffer (p0)->sw_if_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001588
1589 /* Add rewrite/encap string. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001590 vnet_rewrite_one_header (adj0[0], h0, sizeof (ethernet_header_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001591 vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
1592
John Lod1f5d042016-04-12 18:20:39 -04001593 next0 = IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001594
1595 vlib_set_next_frame_buffer (vm, node, next0, bi0);
1596 }
1597 }
1598
Dave Barach75fc8542016-10-11 16:16:02 -04001599 vlib_put_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001600 n_left_to_next_drop);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001601 }
1602
1603 return frame->n_vectors;
1604}
1605
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001606static uword
1607ip6_discover_neighbor (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001608 vlib_node_runtime_t * node, vlib_frame_t * frame)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001609{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001610 return (ip6_discover_neighbor_inline (vm, node, frame, 0));
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001611}
1612
1613static uword
Dave Barachd7cb1b52016-12-09 09:52:16 -05001614ip6_glean (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001615{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001616 return (ip6_discover_neighbor_inline (vm, node, frame, 1));
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001617}
1618
Dave Barachd7cb1b52016-12-09 09:52:16 -05001619static char *ip6_discover_neighbor_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -07001620 [IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops",
Dave Barachd7cb1b52016-12-09 09:52:16 -05001621 [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT] = "neighbor solicitations sent",
Pierre Pfisterd076f192016-06-22 12:58:30 +01001622 [IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS]
1623 = "no source address for ND solicitation",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001624};
1625
Dave Barachd7cb1b52016-12-09 09:52:16 -05001626/* *INDENT-OFF* */
1627VLIB_REGISTER_NODE (ip6_discover_neighbor_node) =
1628{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001629 .function = ip6_discover_neighbor,
1630 .name = "ip6-discover-neighbor",
1631 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -07001632 .format_trace = format_ip6_forward_next_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001633 .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
1634 .error_strings = ip6_discover_neighbor_error_strings,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001635 .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001636 .next_nodes =
1637 {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08001638 [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "ip6-drop",
John Lod1f5d042016-04-12 18:20:39 -04001639 [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001640 },
1641};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001642/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001643
Dave Barachd7cb1b52016-12-09 09:52:16 -05001644/* *INDENT-OFF* */
1645VLIB_REGISTER_NODE (ip6_glean_node) =
1646{
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001647 .function = ip6_glean,
1648 .name = "ip6-glean",
1649 .vector_size = sizeof (u32),
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001650 .format_trace = format_ip6_forward_next_trace,
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001651 .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
1652 .error_strings = ip6_discover_neighbor_error_strings,
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001653 .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001654 .next_nodes =
1655 {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08001656 [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "ip6-drop",
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001657 [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
1658 },
1659};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001660/* *INDENT-ON* */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001661
Ed Warnickecb9cada2015-12-08 15:45:58 -07001662clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001663ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
1664{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001665 vnet_main_t *vnm = vnet_get_main ();
1666 ip6_main_t *im = &ip6_main;
1667 icmp6_neighbor_solicitation_header_t *h;
1668 ip6_address_t *src;
1669 ip_interface_address_t *ia;
1670 ip_adjacency_t *adj;
1671 vnet_hw_interface_t *hi;
1672 vnet_sw_interface_t *si;
1673 vlib_buffer_t *b;
Neale Ranns7a272742017-05-30 02:08:14 -07001674 adj_index_t ai;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001675 u32 bi = 0;
1676 int bogus_length;
1677
1678 si = vnet_get_sw_interface (vnm, sw_if_index);
1679
1680 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
1681 {
1682 return clib_error_return (0, "%U: interface %U down",
Dave Barachd7cb1b52016-12-09 09:52:16 -05001683 format_ip6_address, dst,
1684 format_vnet_sw_if_index_name, vnm,
1685 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001686 }
1687
Dave Barachd7cb1b52016-12-09 09:52:16 -05001688 src =
1689 ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia);
1690 if (!src)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001691 {
1692 vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE;
Dave Barach75fc8542016-10-11 16:16:02 -04001693 return clib_error_return
Dave Barachd7cb1b52016-12-09 09:52:16 -05001694 (0, "no matching interface address for destination %U (interface %U)",
1695 format_ip6_address, dst,
1696 format_vnet_sw_if_index_name, vnm, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001697 }
1698
Dave Barachd7cb1b52016-12-09 09:52:16 -05001699 h =
1700 vlib_packet_template_get_packet (vm,
1701 &im->discover_neighbor_packet_template,
1702 &bi);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001703
1704 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
1705
1706 /* Destination address is a solicited node multicast address. We need to fill in
1707 the low 24 bits with low 24 bits of target's address. */
1708 h->ip.dst_address.as_u8[13] = dst->as_u8[13];
1709 h->ip.dst_address.as_u8[14] = dst->as_u8[14];
1710 h->ip.dst_address.as_u8[15] = dst->as_u8[15];
1711
1712 h->ip.src_address = src[0];
1713 h->neighbor.target_address = dst[0];
1714
Pavel Kotucek57808982017-08-02 08:20:19 +02001715 if (PREDICT_FALSE (!hi->hw_address))
1716 {
1717 return clib_error_return (0, "%U: interface %U do not support ip probe",
1718 format_ip6_address, dst,
1719 format_vnet_sw_if_index_name, vnm,
1720 sw_if_index);
1721 }
1722
Dave Barachd7cb1b52016-12-09 09:52:16 -05001723 clib_memcpy (h->link_layer_option.ethernet_address, hi->hw_address,
1724 vec_len (hi->hw_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001725
Dave Barach75fc8542016-10-11 16:16:02 -04001726 h->neighbor.icmp.checksum =
Ed Warnickecb9cada2015-12-08 15:45:58 -07001727 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001728 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001729
1730 b = vlib_get_buffer (vm, bi);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001731 vnet_buffer (b)->sw_if_index[VLIB_RX] =
1732 vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001733
1734 /* Add encapsulation string for software interface (e.g. ethernet header). */
Neale Ranns7a272742017-05-30 02:08:14 -07001735 ip46_address_t nh = {
1736 .ip6 = *dst,
1737 };
1738
1739 ai = adj_nbr_add_or_lock (FIB_PROTOCOL_IP6,
1740 VNET_LINK_IP6, &nh, sw_if_index);
1741 adj = adj_get (ai);
1742
Dave Barach59b25652017-09-10 15:04:27 -04001743 /* Peer has been previously resolved, retrieve glean adj instead */
1744 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE)
1745 {
1746 adj_unlock (ai);
Ole Troan6ee40512018-02-12 18:14:39 +01001747 ai = adj_glean_add_or_lock (FIB_PROTOCOL_IP6,
1748 VNET_LINK_IP6, sw_if_index, &nh);
Dave Barach59b25652017-09-10 15:04:27 -04001749 adj = adj_get (ai);
1750 }
1751
Ed Warnickecb9cada2015-12-08 15:45:58 -07001752 vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
1753 vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
1754
1755 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001756 vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
1757 u32 *to_next = vlib_frame_vector_args (f);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001758 to_next[0] = bi;
1759 f->n_vectors = 1;
1760 vlib_put_frame_to_node (vm, hi->output_node_index, f);
1761 }
1762
Neale Ranns7a272742017-05-30 02:08:14 -07001763 adj_unlock (ai);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001764 return /* no error */ 0;
1765}
1766
Dave Barachd7cb1b52016-12-09 09:52:16 -05001767typedef enum
1768{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001769 IP6_REWRITE_NEXT_DROP,
Chris Luke816f3e12016-06-14 16:24:47 -04001770 IP6_REWRITE_NEXT_ICMP_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001771} ip6_rewrite_next_t;
1772
1773always_inline uword
1774ip6_rewrite_inline (vlib_main_t * vm,
1775 vlib_node_runtime_t * node,
Neale Ranns9c6a6132017-02-21 05:33:14 -08001776 vlib_frame_t * frame,
1777 int do_counters, int is_midchain, int is_mcast)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001778{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001779 ip_lookup_main_t *lm = &ip6_main.lookup_main;
1780 u32 *from = vlib_frame_vector_args (frame);
1781 u32 n_left_from, n_left_to_next, *to_next, next_index;
1782 vlib_node_runtime_t *error_node =
1783 vlib_node_get_runtime (vm, ip6_input_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001784
1785 n_left_from = frame->n_vectors;
1786 next_index = node->cached_next_index;
Damjan Marion586afd72017-04-05 19:18:20 +02001787 u32 thread_index = vlib_get_thread_index ();
Dave Barach75fc8542016-10-11 16:16:02 -04001788
Ed Warnickecb9cada2015-12-08 15:45:58 -07001789 while (n_left_from > 0)
1790 {
1791 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1792
1793 while (n_left_from >= 4 && n_left_to_next >= 2)
1794 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001795 ip_adjacency_t *adj0, *adj1;
1796 vlib_buffer_t *p0, *p1;
1797 ip6_header_t *ip0, *ip1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001798 u32 pi0, rw_len0, next0, error0, adj_index0;
1799 u32 pi1, rw_len1, next1, error1, adj_index1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001800 u32 tx_sw_if_index0, tx_sw_if_index1;
Dave Barach75fc8542016-10-11 16:16:02 -04001801
Ed Warnickecb9cada2015-12-08 15:45:58 -07001802 /* Prefetch next iteration. */
1803 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001804 vlib_buffer_t *p2, *p3;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001805
1806 p2 = vlib_get_buffer (vm, from[2]);
1807 p3 = vlib_get_buffer (vm, from[3]);
1808
1809 vlib_prefetch_buffer_header (p2, LOAD);
1810 vlib_prefetch_buffer_header (p3, LOAD);
1811
1812 CLIB_PREFETCH (p2->pre_data, 32, STORE);
1813 CLIB_PREFETCH (p3->pre_data, 32, STORE);
1814
1815 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
1816 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
1817 }
1818
1819 pi0 = to_next[0] = from[0];
1820 pi1 = to_next[1] = from[1];
1821
1822 from += 2;
1823 n_left_from -= 2;
1824 to_next += 2;
1825 n_left_to_next -= 2;
Dave Barach75fc8542016-10-11 16:16:02 -04001826
Ed Warnickecb9cada2015-12-08 15:45:58 -07001827 p0 = vlib_get_buffer (vm, pi0);
1828 p1 = vlib_get_buffer (vm, pi1);
1829
Neale Rannsf06aea52016-11-29 06:51:37 -08001830 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1831 adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001832
Ed Warnickecb9cada2015-12-08 15:45:58 -07001833 ip0 = vlib_buffer_get_current (p0);
1834 ip1 = vlib_buffer_get_current (p1);
1835
1836 error0 = error1 = IP6_ERROR_NONE;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001837 next0 = next1 = IP6_REWRITE_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001838
Damjan Marion213b5aa2017-07-13 21:19:27 +02001839 if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001840 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001841 i32 hop_limit0 = ip0->hop_limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001842
1843 /* Input node should have reject packets with hop limit 0. */
1844 ASSERT (ip0->hop_limit > 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001845
1846 hop_limit0 -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001847
1848 ip0->hop_limit = hop_limit0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001849
Dave Barachd7cb1b52016-12-09 09:52:16 -05001850 /*
1851 * If the hop count drops below 1 when forwarding, generate
1852 * an ICMP response.
1853 */
1854 if (PREDICT_FALSE (hop_limit0 <= 0))
1855 {
1856 error0 = IP6_ERROR_TIME_EXPIRED;
1857 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
1858 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1859 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
1860 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1861 0);
1862 }
Neale Rannsf06aea52016-11-29 06:51:37 -08001863 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001864 else
1865 {
Damjan Marion213b5aa2017-07-13 21:19:27 +02001866 p0->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001867 }
Damjan Marion213b5aa2017-07-13 21:19:27 +02001868 if (PREDICT_TRUE (!(p1->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)))
Dave Barachd7cb1b52016-12-09 09:52:16 -05001869 {
Neale Rannsf06aea52016-11-29 06:51:37 -08001870 i32 hop_limit1 = ip1->hop_limit;
1871
1872 /* Input node should have reject packets with hop limit 0. */
1873 ASSERT (ip1->hop_limit > 0);
1874
1875 hop_limit1 -= 1;
1876
1877 ip1->hop_limit = hop_limit1;
1878
Dave Barachd7cb1b52016-12-09 09:52:16 -05001879 /*
1880 * If the hop count drops below 1 when forwarding, generate
1881 * an ICMP response.
1882 */
1883 if (PREDICT_FALSE (hop_limit1 <= 0))
1884 {
1885 error1 = IP6_ERROR_TIME_EXPIRED;
1886 next1 = IP6_REWRITE_NEXT_ICMP_ERROR;
1887 vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1888 icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded,
1889 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1890 0);
1891 }
1892 }
1893 else
1894 {
Damjan Marion213b5aa2017-07-13 21:19:27 +02001895 p1->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001896 }
Neale Ranns107e7d42017-04-11 09:55:19 -07001897 adj0 = adj_get (adj_index0);
1898 adj1 = adj_get (adj_index1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001899
Ed Warnickecb9cada2015-12-08 15:45:58 -07001900 rw_len0 = adj0[0].rewrite_header.data_bytes;
1901 rw_len1 = adj1[0].rewrite_header.data_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001902 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
1903 vnet_buffer (p1)->ip.save_rewrite_length = rw_len1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001904
Neale Ranns9c6a6132017-02-21 05:33:14 -08001905 if (do_counters)
1906 {
1907 vlib_increment_combined_counter
1908 (&adjacency_counters,
Damjan Marion586afd72017-04-05 19:18:20 +02001909 thread_index, adj_index0, 1,
Neale Ranns9c6a6132017-02-21 05:33:14 -08001910 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
1911 vlib_increment_combined_counter
1912 (&adjacency_counters,
Damjan Marion586afd72017-04-05 19:18:20 +02001913 thread_index, adj_index1, 1,
Neale Ranns9c6a6132017-02-21 05:33:14 -08001914 vlib_buffer_length_in_chain (vm, p1) + rw_len1);
1915 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001916
1917 /* Check MTU of outgoing interface. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001918 error0 =
1919 (vlib_buffer_length_in_chain (vm, p0) >
1920 adj0[0].
1921 rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
1922 error0);
1923 error1 =
1924 (vlib_buffer_length_in_chain (vm, p1) >
1925 adj1[0].
1926 rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
1927 error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001928
Dave Barachd7cb1b52016-12-09 09:52:16 -05001929 /* Don't adjust the buffer for hop count issue; icmp-error node
1930 * wants to see the IP headerr */
1931 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
1932 {
1933 p0->current_data -= rw_len0;
1934 p0->current_length += rw_len0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001935
Dave Barachd7cb1b52016-12-09 09:52:16 -05001936 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
1937 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
1938 next0 = adj0[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04001939
Neale Rannsb069a692017-03-15 12:34:25 -04001940 if (PREDICT_FALSE
1941 (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
1942 vnet_feature_arc_start (lm->output_feature_arc_index,
1943 tx_sw_if_index0, &next0, p0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001944 }
1945 if (PREDICT_TRUE (error1 == IP6_ERROR_NONE))
1946 {
1947 p1->current_data -= rw_len1;
1948 p1->current_length += rw_len1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001949
Dave Barachd7cb1b52016-12-09 09:52:16 -05001950 tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
1951 vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1;
1952 next1 = adj1[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04001953
Neale Rannsb069a692017-03-15 12:34:25 -04001954 if (PREDICT_FALSE
1955 (adj1[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
1956 vnet_feature_arc_start (lm->output_feature_arc_index,
1957 tx_sw_if_index1, &next1, p1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001958 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001959
1960 /* Guess we are only writing on simple Ethernet header. */
1961 vnet_rewrite_two_headers (adj0[0], adj1[0],
Dave Barachd7cb1b52016-12-09 09:52:16 -05001962 ip0, ip1, sizeof (ethernet_header_t));
Dave Barach75fc8542016-10-11 16:16:02 -04001963
Neale Ranns5e575b12016-10-03 09:40:25 +01001964 if (is_midchain)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001965 {
Neale Rannsdb14f5a2018-01-29 10:43:33 -08001966 adj0->sub_type.midchain.fixup_func
1967 (vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
1968 adj1->sub_type.midchain.fixup_func
1969 (vm, adj1, p1, adj1->sub_type.midchain.fixup_data);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001970 }
Neale Ranns32e1c012016-11-22 17:07:28 +00001971 if (is_mcast)
1972 {
1973 /*
1974 * copy bytes from the IP address into the MAC rewrite
1975 */
Neale Ranns2e7fbcc2017-03-15 04:22:25 -07001976 vnet_fixup_one_header (adj0[0], &ip0->dst_address, ip0);
1977 vnet_fixup_one_header (adj1[0], &ip1->dst_address, ip1);
Neale Ranns32e1c012016-11-22 17:07:28 +00001978 }
Neale Ranns5e575b12016-10-03 09:40:25 +01001979
Ed Warnickecb9cada2015-12-08 15:45:58 -07001980 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1981 to_next, n_left_to_next,
1982 pi0, pi1, next0, next1);
1983 }
1984
1985 while (n_left_from > 0 && n_left_to_next > 0)
1986 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001987 ip_adjacency_t *adj0;
1988 vlib_buffer_t *p0;
1989 ip6_header_t *ip0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001990 u32 pi0, rw_len0;
1991 u32 adj_index0, next0, error0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001992 u32 tx_sw_if_index0;
Dave Barach75fc8542016-10-11 16:16:02 -04001993
Ed Warnickecb9cada2015-12-08 15:45:58 -07001994 pi0 = to_next[0] = from[0];
1995
1996 p0 = vlib_get_buffer (vm, pi0);
1997
Neale Rannsf06aea52016-11-29 06:51:37 -08001998 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001999
Neale Ranns107e7d42017-04-11 09:55:19 -07002000 adj0 = adj_get (adj_index0);
Dave Barach75fc8542016-10-11 16:16:02 -04002001
Ed Warnickecb9cada2015-12-08 15:45:58 -07002002 ip0 = vlib_buffer_get_current (p0);
2003
2004 error0 = IP6_ERROR_NONE;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002005 next0 = IP6_REWRITE_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002006
2007 /* Check hop limit */
Damjan Marion213b5aa2017-07-13 21:19:27 +02002008 if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002009 {
2010 i32 hop_limit0 = ip0->hop_limit;
2011
2012 ASSERT (ip0->hop_limit > 0);
2013
2014 hop_limit0 -= 1;
2015
2016 ip0->hop_limit = hop_limit0;
2017
Dave Barachd7cb1b52016-12-09 09:52:16 -05002018 if (PREDICT_FALSE (hop_limit0 <= 0))
2019 {
2020 /*
2021 * If the hop count drops below 1 when forwarding, generate
2022 * an ICMP response.
2023 */
2024 error0 = IP6_ERROR_TIME_EXPIRED;
2025 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
2026 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
2027 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
2028 ICMP6_time_exceeded_ttl_exceeded_in_transit,
2029 0);
2030 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002031 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002032 else
2033 {
Damjan Marion213b5aa2017-07-13 21:19:27 +02002034 p0->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002035 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002036
Ed Warnickecb9cada2015-12-08 15:45:58 -07002037 /* Guess we are only writing on simple Ethernet header. */
2038 vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
Dave Barach75fc8542016-10-11 16:16:02 -04002039
Ed Warnickecb9cada2015-12-08 15:45:58 -07002040 /* Update packet buffer attributes/set output interface. */
2041 rw_len0 = adj0[0].rewrite_header.data_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002042 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002043
Neale Ranns9c6a6132017-02-21 05:33:14 -08002044 if (do_counters)
2045 {
2046 vlib_increment_combined_counter
2047 (&adjacency_counters,
Damjan Marion586afd72017-04-05 19:18:20 +02002048 thread_index, adj_index0, 1,
Neale Ranns9c6a6132017-02-21 05:33:14 -08002049 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
2050 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002051
2052 /* Check MTU of outgoing interface. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002053 error0 =
2054 (vlib_buffer_length_in_chain (vm, p0) >
2055 adj0[0].
2056 rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
2057 error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002058
Dave Barachd7cb1b52016-12-09 09:52:16 -05002059 /* Don't adjust the buffer for hop count issue; icmp-error node
2060 * wants to see the IP headerr */
2061 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
2062 {
Chris Luke816f3e12016-06-14 16:24:47 -04002063 p0->current_data -= rw_len0;
2064 p0->current_length += rw_len0;
2065
Dave Barachd7cb1b52016-12-09 09:52:16 -05002066 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
Dave Barach5331c722016-08-17 11:54:30 -04002067
Dave Barachd7cb1b52016-12-09 09:52:16 -05002068 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
2069 next0 = adj0[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04002070
Neale Rannsb069a692017-03-15 12:34:25 -04002071 if (PREDICT_FALSE
2072 (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
2073 vnet_feature_arc_start (lm->output_feature_arc_index,
2074 tx_sw_if_index0, &next0, p0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002075 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002076
Neale Ranns5e575b12016-10-03 09:40:25 +01002077 if (is_midchain)
Dave Barachd7cb1b52016-12-09 09:52:16 -05002078 {
Neale Rannsdb14f5a2018-01-29 10:43:33 -08002079 adj0->sub_type.midchain.fixup_func
2080 (vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002081 }
Neale Ranns32e1c012016-11-22 17:07:28 +00002082 if (is_mcast)
2083 {
Neale Ranns2e7fbcc2017-03-15 04:22:25 -07002084 vnet_fixup_one_header (adj0[0], &ip0->dst_address, ip0);
Neale Ranns32e1c012016-11-22 17:07:28 +00002085 }
Neale Ranns5e575b12016-10-03 09:40:25 +01002086
Ed Warnickecb9cada2015-12-08 15:45:58 -07002087 p0->error = error_node->errors[error0];
2088
2089 from += 1;
2090 n_left_from -= 1;
2091 to_next += 1;
2092 n_left_to_next -= 1;
Dave Barach75fc8542016-10-11 16:16:02 -04002093
Ed Warnickecb9cada2015-12-08 15:45:58 -07002094 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
2095 to_next, n_left_to_next,
2096 pi0, next0);
2097 }
2098
2099 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2100 }
2101
2102 /* Need to do trace after rewrites to pick up new packet data. */
2103 if (node->flags & VLIB_NODE_FLAG_TRACE)
Neale Rannsf06aea52016-11-29 06:51:37 -08002104 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002105
2106 return frame->n_vectors;
2107}
2108
2109static uword
Neale Rannsf06aea52016-11-29 06:51:37 -08002110ip6_rewrite (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002111 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002112{
Neale Ranns9c6a6132017-02-21 05:33:14 -08002113 if (adj_are_counters_enabled ())
2114 return ip6_rewrite_inline (vm, node, frame, 1, 0, 0);
2115 else
2116 return ip6_rewrite_inline (vm, node, frame, 0, 0, 0);
Neale Ranns32e1c012016-11-22 17:07:28 +00002117}
2118
2119static uword
2120ip6_rewrite_mcast (vlib_main_t * vm,
2121 vlib_node_runtime_t * node, vlib_frame_t * frame)
2122{
Neale Ranns9c6a6132017-02-21 05:33:14 -08002123 if (adj_are_counters_enabled ())
2124 return ip6_rewrite_inline (vm, node, frame, 1, 0, 1);
2125 else
2126 return ip6_rewrite_inline (vm, node, frame, 0, 0, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002127}
2128
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002129static uword
2130ip6_midchain (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002131 vlib_node_runtime_t * node, vlib_frame_t * frame)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002132{
Neale Ranns9c6a6132017-02-21 05:33:14 -08002133 if (adj_are_counters_enabled ())
2134 return ip6_rewrite_inline (vm, node, frame, 1, 1, 0);
2135 else
2136 return ip6_rewrite_inline (vm, node, frame, 0, 1, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002137}
2138
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002139static uword
2140ip6_mcast_midchain (vlib_main_t * vm,
2141 vlib_node_runtime_t * node, vlib_frame_t * frame)
2142{
2143 if (adj_are_counters_enabled ())
2144 return ip6_rewrite_inline (vm, node, frame, 1, 1, 1);
2145 else
Neale Ranns9f171f52017-04-11 08:56:53 -07002146 return ip6_rewrite_inline (vm, node, frame, 0, 1, 1);
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002147}
2148
Dave Barachd7cb1b52016-12-09 09:52:16 -05002149/* *INDENT-OFF* */
2150VLIB_REGISTER_NODE (ip6_midchain_node) =
2151{
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002152 .function = ip6_midchain,
2153 .name = "ip6-midchain",
2154 .vector_size = sizeof (u32),
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002155 .format_trace = format_ip6_forward_next_trace,
Neale Ranns5e575b12016-10-03 09:40:25 +01002156 .sibling_of = "ip6-rewrite",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002157 };
2158/* *INDENT-ON* */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002159
Dave Barachd7cb1b52016-12-09 09:52:16 -05002160VLIB_NODE_FUNCTION_MULTIARCH (ip6_midchain_node, ip6_midchain);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002161
Dave Barachd7cb1b52016-12-09 09:52:16 -05002162/* *INDENT-OFF* */
2163VLIB_REGISTER_NODE (ip6_rewrite_node) =
2164{
Neale Rannsf06aea52016-11-29 06:51:37 -08002165 .function = ip6_rewrite,
Ed Warnickecb9cada2015-12-08 15:45:58 -07002166 .name = "ip6-rewrite",
2167 .vector_size = sizeof (u32),
Pierre Pfistera38c3df2016-06-13 10:28:09 +01002168 .format_trace = format_ip6_rewrite_trace,
Chris Luke816f3e12016-06-14 16:24:47 -04002169 .n_next_nodes = 2,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002170 .next_nodes =
2171 {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08002172 [IP6_REWRITE_NEXT_DROP] = "ip6-drop",
Chris Luke816f3e12016-06-14 16:24:47 -04002173 [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error",
Ed Warnickecb9cada2015-12-08 15:45:58 -07002174 },
2175};
Dave Barachd7cb1b52016-12-09 09:52:16 -05002176/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002177
Neale Rannsf06aea52016-11-29 06:51:37 -08002178VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_node, ip6_rewrite);
Damjan Marion1c80e832016-05-11 23:07:18 +02002179
Neale Ranns32e1c012016-11-22 17:07:28 +00002180/* *INDENT-OFF* */
2181VLIB_REGISTER_NODE (ip6_rewrite_mcast_node) =
2182{
2183 .function = ip6_rewrite_mcast,
2184 .name = "ip6-rewrite-mcast",
2185 .vector_size = sizeof (u32),
2186 .format_trace = format_ip6_rewrite_trace,
2187 .sibling_of = "ip6-rewrite",
2188};
2189/* *INDENT-ON* */
2190
2191VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_mcast_node, ip6_rewrite_mcast);
2192
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002193/* *INDENT-OFF* */
2194VLIB_REGISTER_NODE (ip6_mcast_midchain_node, static) =
2195{
2196 .function = ip6_mcast_midchain,
2197 .name = "ip6-mcast-midchain",
2198 .vector_size = sizeof (u32),
2199 .format_trace = format_ip6_rewrite_trace,
2200 .sibling_of = "ip6-rewrite",
2201};
2202/* *INDENT-ON* */
2203
2204VLIB_NODE_FUNCTION_MULTIARCH (ip6_mcast_midchain_node, ip6_mcast_midchain);
2205
Ole Troan944f5482016-05-24 11:56:58 +02002206/*
2207 * Hop-by-Hop handling
2208 */
Ole Troan944f5482016-05-24 11:56:58 +02002209ip6_hop_by_hop_main_t ip6_hop_by_hop_main;
2210
2211#define foreach_ip6_hop_by_hop_error \
2212_(PROCESSED, "pkts with ip6 hop-by-hop options") \
2213_(FORMAT, "incorrectly formatted hop-by-hop options") \
2214_(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options")
2215
Neale Ranns32e1c012016-11-22 17:07:28 +00002216/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002217typedef enum
2218{
Ole Troan944f5482016-05-24 11:56:58 +02002219#define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym,
2220 foreach_ip6_hop_by_hop_error
2221#undef _
Neale Ranns32e1c012016-11-22 17:07:28 +00002222 IP6_HOP_BY_HOP_N_ERROR,
Ole Troan944f5482016-05-24 11:56:58 +02002223} ip6_hop_by_hop_error_t;
Neale Ranns32e1c012016-11-22 17:07:28 +00002224/* *INDENT-ON* */
Ole Troan944f5482016-05-24 11:56:58 +02002225
2226/*
2227 * Primary h-b-h handler trace support
2228 * We work pretty hard on the problem for obvious reasons
2229 */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002230typedef struct
2231{
Ole Troan944f5482016-05-24 11:56:58 +02002232 u32 next_index;
2233 u32 trace_len;
2234 u8 option_data[256];
2235} ip6_hop_by_hop_trace_t;
2236
2237vlib_node_registration_t ip6_hop_by_hop_node;
2238
Dave Barachd7cb1b52016-12-09 09:52:16 -05002239static char *ip6_hop_by_hop_error_strings[] = {
Ole Troan944f5482016-05-24 11:56:58 +02002240#define _(sym,string) string,
2241 foreach_ip6_hop_by_hop_error
2242#undef _
2243};
2244
Shwetha Bhandari78372a92017-01-18 12:43:54 +05302245u8 *
2246format_ip6_hop_by_hop_ext_hdr (u8 * s, va_list * args)
2247{
2248 ip6_hop_by_hop_header_t *hbh0 = va_arg (*args, ip6_hop_by_hop_header_t *);
2249 int total_len = va_arg (*args, int);
2250 ip6_hop_by_hop_option_t *opt0, *limit0;
2251 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2252 u8 type0;
2253
2254 s = format (s, "IP6_HOP_BY_HOP: next protocol %d len %d total %d",
2255 hbh0->protocol, (hbh0->length + 1) << 3, total_len);
2256
2257 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2258 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + total_len);
2259
2260 while (opt0 < limit0)
2261 {
2262 type0 = opt0->type;
2263 switch (type0)
2264 {
2265 case 0: /* Pad, just stop */
2266 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0 + 1);
2267 break;
2268
2269 default:
2270 if (hm->trace[type0])
2271 {
2272 s = (*hm->trace[type0]) (s, opt0);
2273 }
2274 else
2275 {
2276 s =
2277 format (s, "\n unrecognized option %d length %d", type0,
2278 opt0->length);
2279 }
2280 opt0 =
2281 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2282 sizeof (ip6_hop_by_hop_option_t));
2283 break;
2284 }
2285 }
2286 return s;
2287}
2288
Ole Troan944f5482016-05-24 11:56:58 +02002289static u8 *
2290format_ip6_hop_by_hop_trace (u8 * s, va_list * args)
2291{
2292 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2293 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002294 ip6_hop_by_hop_trace_t *t = va_arg (*args, ip6_hop_by_hop_trace_t *);
Ole Troan944f5482016-05-24 11:56:58 +02002295 ip6_hop_by_hop_header_t *hbh0;
2296 ip6_hop_by_hop_option_t *opt0, *limit0;
2297 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2298
2299 u8 type0;
2300
Dave Barachd7cb1b52016-12-09 09:52:16 -05002301 hbh0 = (ip6_hop_by_hop_header_t *) t->option_data;
Ole Troan944f5482016-05-24 11:56:58 +02002302
2303 s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002304 t->next_index, (hbh0->length + 1) << 3, t->trace_len);
Ole Troan944f5482016-05-24 11:56:58 +02002305
Dave Barachd7cb1b52016-12-09 09:52:16 -05002306 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2307 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0) + t->trace_len;
Ole Troan944f5482016-05-24 11:56:58 +02002308
Dave Barachd7cb1b52016-12-09 09:52:16 -05002309 while (opt0 < limit0)
2310 {
2311 type0 = opt0->type;
2312 switch (type0)
2313 {
2314 case 0: /* Pad, just stop */
2315 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
2316 break;
Ole Troan944f5482016-05-24 11:56:58 +02002317
Dave Barachd7cb1b52016-12-09 09:52:16 -05002318 default:
2319 if (hm->trace[type0])
2320 {
2321 s = (*hm->trace[type0]) (s, opt0);
2322 }
2323 else
2324 {
2325 s =
2326 format (s, "\n unrecognized option %d length %d", type0,
2327 opt0->length);
2328 }
2329 opt0 =
2330 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2331 sizeof (ip6_hop_by_hop_option_t));
2332 break;
2333 }
Ole Troan944f5482016-05-24 11:56:58 +02002334 }
Ole Troan944f5482016-05-24 11:56:58 +02002335 return s;
2336}
2337
Dave Barachd7cb1b52016-12-09 09:52:16 -05002338always_inline u8
2339ip6_scan_hbh_options (vlib_buffer_t * b0,
2340 ip6_header_t * ip0,
2341 ip6_hop_by_hop_header_t * hbh0,
2342 ip6_hop_by_hop_option_t * opt0,
2343 ip6_hop_by_hop_option_t * limit0, u32 * next0)
Shwethaa91cbe62016-08-08 15:51:04 +01002344{
2345 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2346 u8 type0;
2347 u8 error0 = 0;
2348
2349 while (opt0 < limit0)
2350 {
2351 type0 = opt0->type;
2352 switch (type0)
2353 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002354 case 0: /* Pad1 */
2355 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
Shwethaa91cbe62016-08-08 15:51:04 +01002356 continue;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002357 case 1: /* PadN */
Shwethaa91cbe62016-08-08 15:51:04 +01002358 break;
2359 default:
2360 if (hm->options[type0])
2361 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002362 if ((*hm->options[type0]) (b0, ip0, opt0) < 0)
2363 {
Shwethaa91cbe62016-08-08 15:51:04 +01002364 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002365 return (error0);
2366 }
Shwethaa91cbe62016-08-08 15:51:04 +01002367 }
2368 else
2369 {
2370 /* Unrecognized mandatory option, check the two high order bits */
2371 switch (opt0->type & HBH_OPTION_TYPE_HIGH_ORDER_BITS)
2372 {
2373 case HBH_OPTION_TYPE_SKIP_UNKNOWN:
2374 break;
2375 case HBH_OPTION_TYPE_DISCARD_UNKNOWN:
2376 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2377 *next0 = IP_LOOKUP_NEXT_DROP;
2378 break;
2379 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP:
2380 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2381 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002382 icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem,
2383 ICMP6_parameter_problem_unrecognized_option,
2384 (u8 *) opt0 - (u8 *) ip0);
Shwethaa91cbe62016-08-08 15:51:04 +01002385 break;
2386 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST:
2387 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002388 if (!ip6_address_is_multicast (&ip0->dst_address))
Shwethaa91cbe62016-08-08 15:51:04 +01002389 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002390 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
2391 icmp6_error_set_vnet_buffer (b0,
2392 ICMP6_parameter_problem,
2393 ICMP6_parameter_problem_unrecognized_option,
2394 (u8 *) opt0 - (u8 *) ip0);
Shwethaa91cbe62016-08-08 15:51:04 +01002395 }
2396 else
2397 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002398 *next0 = IP_LOOKUP_NEXT_DROP;
Shwethaa91cbe62016-08-08 15:51:04 +01002399 }
2400 break;
2401 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002402 return (error0);
Shwethaa91cbe62016-08-08 15:51:04 +01002403 }
2404 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002405 opt0 =
2406 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2407 sizeof (ip6_hop_by_hop_option_t));
Shwethaa91cbe62016-08-08 15:51:04 +01002408 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002409 return (error0);
Shwethaa91cbe62016-08-08 15:51:04 +01002410}
2411
Ole Troan944f5482016-05-24 11:56:58 +02002412/*
2413 * Process the Hop-by-Hop Options header
2414 */
2415static uword
2416ip6_hop_by_hop (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002417 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ole Troan944f5482016-05-24 11:56:58 +02002418{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002419 vlib_node_runtime_t *error_node =
2420 vlib_node_get_runtime (vm, ip6_hop_by_hop_node.index);
Ole Troan944f5482016-05-24 11:56:58 +02002421 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2422 u32 n_left_from, *from, *to_next;
2423 ip_lookup_next_t next_index;
Ole Troan944f5482016-05-24 11:56:58 +02002424
2425 from = vlib_frame_vector_args (frame);
2426 n_left_from = frame->n_vectors;
2427 next_index = node->cached_next_index;
2428
Dave Barachd7cb1b52016-12-09 09:52:16 -05002429 while (n_left_from > 0)
2430 {
2431 u32 n_left_to_next;
Ole Troan944f5482016-05-24 11:56:58 +02002432
Dave Barachd7cb1b52016-12-09 09:52:16 -05002433 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ole Troan944f5482016-05-24 11:56:58 +02002434
Dave Barachd7cb1b52016-12-09 09:52:16 -05002435 while (n_left_from >= 4 && n_left_to_next >= 2)
Shwethaa91cbe62016-08-08 15:51:04 +01002436 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002437 u32 bi0, bi1;
2438 vlib_buffer_t *b0, *b1;
2439 u32 next0, next1;
2440 ip6_header_t *ip0, *ip1;
2441 ip6_hop_by_hop_header_t *hbh0, *hbh1;
2442 ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1;
2443 u8 error0 = 0, error1 = 0;
2444
2445 /* Prefetch next iteration. */
2446 {
2447 vlib_buffer_t *p2, *p3;
2448
2449 p2 = vlib_get_buffer (vm, from[2]);
2450 p3 = vlib_get_buffer (vm, from[3]);
2451
2452 vlib_prefetch_buffer_header (p2, LOAD);
2453 vlib_prefetch_buffer_header (p3, LOAD);
2454
2455 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
2456 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
Shwethaa91cbe62016-08-08 15:51:04 +01002457 }
2458
Dave Barachd7cb1b52016-12-09 09:52:16 -05002459 /* Speculatively enqueue b0, b1 to the current next frame */
2460 to_next[0] = bi0 = from[0];
2461 to_next[1] = bi1 = from[1];
2462 from += 2;
2463 to_next += 2;
2464 n_left_from -= 2;
2465 n_left_to_next -= 2;
2466
2467 b0 = vlib_get_buffer (vm, bi0);
2468 b1 = vlib_get_buffer (vm, bi1);
2469
2470 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2471 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002472 ip_adjacency_t *adj0 = adj_get (adj_index0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002473 u32 adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002474 ip_adjacency_t *adj1 = adj_get (adj_index1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002475
2476 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2477 next0 = adj0->lookup_next_index;
2478 next1 = adj1->lookup_next_index;
2479
2480 ip0 = vlib_buffer_get_current (b0);
2481 ip1 = vlib_buffer_get_current (b1);
2482 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2483 hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
2484 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2485 opt1 = (ip6_hop_by_hop_option_t *) (hbh1 + 1);
2486 limit0 =
2487 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2488 ((hbh0->length + 1) << 3));
2489 limit1 =
2490 (ip6_hop_by_hop_option_t *) ((u8 *) hbh1 +
2491 ((hbh1->length + 1) << 3));
2492
2493 /*
2494 * Basic validity checks
2495 */
2496 if ((hbh0->length + 1) << 3 >
2497 clib_net_to_host_u16 (ip0->payload_length))
2498 {
2499 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2500 next0 = IP_LOOKUP_NEXT_DROP;
2501 goto outdual;
2502 }
2503 /* Scan the set of h-b-h options, process ones that we understand */
2504 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2505
2506 if ((hbh1->length + 1) << 3 >
2507 clib_net_to_host_u16 (ip1->payload_length))
2508 {
2509 error1 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2510 next1 = IP_LOOKUP_NEXT_DROP;
2511 goto outdual;
2512 }
2513 /* Scan the set of h-b-h options, process ones that we understand */
2514 error1 = ip6_scan_hbh_options (b1, ip1, hbh1, opt1, limit1, &next1);
2515
2516 outdual:
2517 /* Has the classifier flagged this buffer for special treatment? */
2518 if (PREDICT_FALSE
2519 ((error0 == 0)
2520 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2521 next0 = hm->next_override;
2522
2523 /* Has the classifier flagged this buffer for special treatment? */
2524 if (PREDICT_FALSE
2525 ((error1 == 0)
2526 && (vnet_buffer (b1)->l2_classify.opaque_index & OI_DECAP)))
2527 next1 = hm->next_override;
2528
2529 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
2530 {
2531 if (b0->flags & VLIB_BUFFER_IS_TRACED)
2532 {
2533 ip6_hop_by_hop_trace_t *t =
2534 vlib_add_trace (vm, node, b0, sizeof (*t));
2535 u32 trace_len = (hbh0->length + 1) << 3;
2536 t->next_index = next0;
2537 /* Capture the h-b-h option verbatim */
2538 trace_len =
2539 trace_len <
2540 ARRAY_LEN (t->option_data) ? trace_len :
2541 ARRAY_LEN (t->option_data);
2542 t->trace_len = trace_len;
2543 clib_memcpy (t->option_data, hbh0, trace_len);
2544 }
2545 if (b1->flags & VLIB_BUFFER_IS_TRACED)
2546 {
2547 ip6_hop_by_hop_trace_t *t =
2548 vlib_add_trace (vm, node, b1, sizeof (*t));
2549 u32 trace_len = (hbh1->length + 1) << 3;
2550 t->next_index = next1;
2551 /* Capture the h-b-h option verbatim */
2552 trace_len =
2553 trace_len <
2554 ARRAY_LEN (t->option_data) ? trace_len :
2555 ARRAY_LEN (t->option_data);
2556 t->trace_len = trace_len;
2557 clib_memcpy (t->option_data, hbh1, trace_len);
2558 }
2559
2560 }
2561
2562 b0->error = error_node->errors[error0];
2563 b1->error = error_node->errors[error1];
2564
2565 /* verify speculative enqueue, maybe switch current next frame */
2566 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
2567 n_left_to_next, bi0, bi1, next0,
2568 next1);
Shwethaa91cbe62016-08-08 15:51:04 +01002569 }
2570
Dave Barachd7cb1b52016-12-09 09:52:16 -05002571 while (n_left_from > 0 && n_left_to_next > 0)
2572 {
2573 u32 bi0;
2574 vlib_buffer_t *b0;
2575 u32 next0;
2576 ip6_header_t *ip0;
2577 ip6_hop_by_hop_header_t *hbh0;
2578 ip6_hop_by_hop_option_t *opt0, *limit0;
2579 u8 error0 = 0;
Shwethaa91cbe62016-08-08 15:51:04 +01002580
Dave Barachd7cb1b52016-12-09 09:52:16 -05002581 /* Speculatively enqueue b0 to the current next frame */
2582 bi0 = from[0];
2583 to_next[0] = bi0;
2584 from += 1;
2585 to_next += 1;
2586 n_left_from -= 1;
2587 n_left_to_next -= 1;
2588
2589 b0 = vlib_get_buffer (vm, bi0);
2590 /*
2591 * Default use the next_index from the adjacency.
2592 * A HBH option rarely redirects to a different node
2593 */
2594 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
Neale Ranns107e7d42017-04-11 09:55:19 -07002595 ip_adjacency_t *adj0 = adj_get (adj_index0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002596 next0 = adj0->lookup_next_index;
2597
2598 ip0 = vlib_buffer_get_current (b0);
2599 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2600 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2601 limit0 =
2602 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2603 ((hbh0->length + 1) << 3));
2604
2605 /*
2606 * Basic validity checks
2607 */
2608 if ((hbh0->length + 1) << 3 >
2609 clib_net_to_host_u16 (ip0->payload_length))
2610 {
2611 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2612 next0 = IP_LOOKUP_NEXT_DROP;
2613 goto out0;
2614 }
2615
2616 /* Scan the set of h-b-h options, process ones that we understand */
2617 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2618
2619 out0:
2620 /* Has the classifier flagged this buffer for special treatment? */
2621 if (PREDICT_FALSE
2622 ((error0 == 0)
2623 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2624 next0 = hm->next_override;
2625
2626 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2627 {
2628 ip6_hop_by_hop_trace_t *t =
2629 vlib_add_trace (vm, node, b0, sizeof (*t));
2630 u32 trace_len = (hbh0->length + 1) << 3;
2631 t->next_index = next0;
2632 /* Capture the h-b-h option verbatim */
2633 trace_len =
2634 trace_len <
2635 ARRAY_LEN (t->option_data) ? trace_len :
2636 ARRAY_LEN (t->option_data);
2637 t->trace_len = trace_len;
2638 clib_memcpy (t->option_data, hbh0, trace_len);
2639 }
2640
2641 b0->error = error_node->errors[error0];
2642
2643 /* verify speculative enqueue, maybe switch current next frame */
2644 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2645 n_left_to_next, bi0, next0);
2646 }
2647 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
Shwethaa91cbe62016-08-08 15:51:04 +01002648 }
Ole Troan944f5482016-05-24 11:56:58 +02002649 return frame->n_vectors;
2650}
2651
Dave Barachd7cb1b52016-12-09 09:52:16 -05002652/* *INDENT-OFF* */
2653VLIB_REGISTER_NODE (ip6_hop_by_hop_node) =
2654{
Ole Troan944f5482016-05-24 11:56:58 +02002655 .function = ip6_hop_by_hop,
2656 .name = "ip6-hop-by-hop",
Ole Troan964f93e2016-06-10 13:22:36 +02002657 .sibling_of = "ip6-lookup",
Ole Troan944f5482016-05-24 11:56:58 +02002658 .vector_size = sizeof (u32),
2659 .format_trace = format_ip6_hop_by_hop_trace,
2660 .type = VLIB_NODE_TYPE_INTERNAL,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002661 .n_errors = ARRAY_LEN (ip6_hop_by_hop_error_strings),
Ole Troan944f5482016-05-24 11:56:58 +02002662 .error_strings = ip6_hop_by_hop_error_strings,
Ole Troan964f93e2016-06-10 13:22:36 +02002663 .n_next_nodes = 0,
Ole Troan944f5482016-05-24 11:56:58 +02002664};
Dave Barachd7cb1b52016-12-09 09:52:16 -05002665/* *INDENT-ON* */
Ole Troan944f5482016-05-24 11:56:58 +02002666
Dave Barach5331c722016-08-17 11:54:30 -04002667VLIB_NODE_FUNCTION_MULTIARCH (ip6_hop_by_hop_node, ip6_hop_by_hop);
Ole Troan944f5482016-05-24 11:56:58 +02002668
2669static clib_error_t *
2670ip6_hop_by_hop_init (vlib_main_t * vm)
2671{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002672 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2673 memset (hm->options, 0, sizeof (hm->options));
2674 memset (hm->trace, 0, sizeof (hm->trace));
Shwethaa91cbe62016-08-08 15:51:04 +01002675 hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
Ole Troan944f5482016-05-24 11:56:58 +02002676 return (0);
2677}
2678
2679VLIB_INIT_FUNCTION (ip6_hop_by_hop_init);
2680
Dave Barachd7cb1b52016-12-09 09:52:16 -05002681void
2682ip6_hbh_set_next_override (uword next)
Shwethaa91cbe62016-08-08 15:51:04 +01002683{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002684 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Shwethaa91cbe62016-08-08 15:51:04 +01002685
2686 hm->next_override = next;
2687}
2688
Ole Troan944f5482016-05-24 11:56:58 +02002689int
2690ip6_hbh_register_option (u8 option,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002691 int options (vlib_buffer_t * b, ip6_header_t * ip,
2692 ip6_hop_by_hop_option_t * opt),
2693 u8 * trace (u8 * s, ip6_hop_by_hop_option_t * opt))
Ole Troan944f5482016-05-24 11:56:58 +02002694{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002695 ip6_main_t *im = &ip6_main;
2696 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Ole Troan944f5482016-05-24 11:56:58 +02002697
2698 ASSERT (option < ARRAY_LEN (hm->options));
2699
2700 /* Already registered */
2701 if (hm->options[option])
2702 return (-1);
2703
2704 hm->options[option] = options;
2705 hm->trace[option] = trace;
2706
2707 /* Set global variable */
2708 im->hbh_enabled = 1;
2709
2710 return (0);
2711}
2712
2713int
2714ip6_hbh_unregister_option (u8 option)
2715{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002716 ip6_main_t *im = &ip6_main;
2717 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Ole Troan944f5482016-05-24 11:56:58 +02002718
2719 ASSERT (option < ARRAY_LEN (hm->options));
2720
2721 /* Not registered */
2722 if (!hm->options[option])
2723 return (-1);
2724
2725 hm->options[option] = NULL;
2726 hm->trace[option] = NULL;
2727
2728 /* Disable global knob if this was the last option configured */
2729 int i;
2730 bool found = false;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002731 for (i = 0; i < 256; i++)
2732 {
2733 if (hm->options[option])
2734 {
2735 found = true;
2736 break;
2737 }
Ole Troan944f5482016-05-24 11:56:58 +02002738 }
Ole Troan944f5482016-05-24 11:56:58 +02002739 if (!found)
2740 im->hbh_enabled = 0;
2741
2742 return (0);
2743}
2744
Ed Warnickecb9cada2015-12-08 15:45:58 -07002745/* Global IP6 main. */
2746ip6_main_t ip6_main;
2747
2748static clib_error_t *
2749ip6_lookup_init (vlib_main_t * vm)
2750{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002751 ip6_main_t *im = &ip6_main;
2752 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002753 uword i;
2754
Damjan Marion8b3191e2016-11-09 19:54:20 +01002755 if ((error = vlib_call_init_function (vm, vnet_feature_init)))
2756 return error;
2757
Ed Warnickecb9cada2015-12-08 15:45:58 -07002758 for (i = 0; i < ARRAY_LEN (im->fib_masks); i++)
2759 {
2760 u32 j, i0, i1;
2761
2762 i0 = i / 32;
2763 i1 = i % 32;
2764
2765 for (j = 0; j < i0; j++)
2766 im->fib_masks[i].as_u32[j] = ~0;
2767
2768 if (i1)
Dave Barachd7cb1b52016-12-09 09:52:16 -05002769 im->fib_masks[i].as_u32[i0] =
2770 clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002771 }
2772
2773 ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1);
2774
2775 if (im->lookup_table_nbuckets == 0)
2776 im->lookup_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS;
2777
Dave Barachd7cb1b52016-12-09 09:52:16 -05002778 im->lookup_table_nbuckets = 1 << max_log2 (im->lookup_table_nbuckets);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002779
2780 if (im->lookup_table_size == 0)
2781 im->lookup_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE;
Dave Barach75fc8542016-10-11 16:16:02 -04002782
Dave Barachd7cb1b52016-12-09 09:52:16 -05002783 BV (clib_bihash_init) (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash),
2784 "ip6 FIB fwding table",
2785 im->lookup_table_nbuckets, im->lookup_table_size);
2786 BV (clib_bihash_init) (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
2787 "ip6 FIB non-fwding table",
2788 im->lookup_table_nbuckets, im->lookup_table_size);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002789
Ed Warnickecb9cada2015-12-08 15:45:58 -07002790 /* Create FIB with index 0 and table id of 0. */
Neale Ranns15002542017-09-10 04:39:11 -07002791 fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0,
2792 FIB_SOURCE_DEFAULT_ROUTE);
2793 mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0,
2794 MFIB_SOURCE_DEFAULT_ROUTE);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002795
2796 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002797 pg_node_t *pn;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002798 pn = pg_get_node (ip6_lookup_node.index);
2799 pn->unformat_edit = unformat_pg_ip6_header;
2800 }
2801
Ole Troan944f5482016-05-24 11:56:58 +02002802 /* Unless explicitly configured, don't process HBH options */
2803 im->hbh_enabled = 0;
2804
Ed Warnickecb9cada2015-12-08 15:45:58 -07002805 {
2806 icmp6_neighbor_solicitation_header_t p;
2807
2808 memset (&p, 0, sizeof (p));
2809
Dave Barachd7cb1b52016-12-09 09:52:16 -05002810 p.ip.ip_version_traffic_class_and_flow_label =
2811 clib_host_to_net_u32 (0x6 << 28);
2812 p.ip.payload_length =
2813 clib_host_to_net_u16 (sizeof (p) -
2814 STRUCT_OFFSET_OF
2815 (icmp6_neighbor_solicitation_header_t, neighbor));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002816 p.ip.protocol = IP_PROTOCOL_ICMP6;
2817 p.ip.hop_limit = 255;
2818 ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0);
2819
2820 p.neighbor.icmp.type = ICMP6_neighbor_solicitation;
2821
Dave Barachd7cb1b52016-12-09 09:52:16 -05002822 p.link_layer_option.header.type =
2823 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
2824 p.link_layer_option.header.n_data_u64s =
2825 sizeof (p.link_layer_option) / sizeof (u64);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002826
2827 vlib_packet_template_init (vm,
2828 &im->discover_neighbor_packet_template,
2829 &p, sizeof (p),
2830 /* alloc chunk size */ 8,
2831 "ip6 neighbor discovery");
2832 }
2833
Dave Barach203c6322016-06-26 10:29:03 -04002834 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002835}
2836
2837VLIB_INIT_FUNCTION (ip6_lookup_init);
2838
Dave Barach75fc8542016-10-11 16:16:02 -04002839void
Dave Barachd7cb1b52016-12-09 09:52:16 -05002840ip6_link_local_address_from_ethernet_mac_address (ip6_address_t * ip,
2841 u8 * mac)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002842{
2843 ip->as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
2844 /* Invert the "u" bit */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002845 ip->as_u8[8] = mac[0] ^ (1 << 1);
2846 ip->as_u8[9] = mac[1];
2847 ip->as_u8[10] = mac[2];
2848 ip->as_u8[11] = 0xFF;
2849 ip->as_u8[12] = 0xFE;
2850 ip->as_u8[13] = mac[3];
2851 ip->as_u8[14] = mac[4];
2852 ip->as_u8[15] = mac[5];
Ed Warnickecb9cada2015-12-08 15:45:58 -07002853}
2854
Dave Barach75fc8542016-10-11 16:16:02 -04002855void
Dave Barachd7cb1b52016-12-09 09:52:16 -05002856ip6_ethernet_mac_address_from_link_local_address (u8 * mac,
2857 ip6_address_t * ip)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002858{
2859 /* Invert the previously inverted "u" bit */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002860 mac[0] = ip->as_u8[8] ^ (1 << 1);
2861 mac[1] = ip->as_u8[9];
2862 mac[2] = ip->as_u8[10];
2863 mac[3] = ip->as_u8[13];
2864 mac[4] = ip->as_u8[14];
2865 mac[5] = ip->as_u8[15];
Ed Warnickecb9cada2015-12-08 15:45:58 -07002866}
2867
Dave Barach75fc8542016-10-11 16:16:02 -04002868static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07002869test_ip6_link_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002870 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002871{
2872 u8 mac[6];
2873 ip6_address_t _a, *a = &_a;
2874
2875 if (unformat (input, "%U", unformat_ethernet_address, mac))
2876 {
2877 ip6_link_local_address_from_ethernet_mac_address (a, mac);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002878 vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002879 ip6_ethernet_mac_address_from_link_local_address (mac, a);
2880 vlib_cli_output (vm, "Original MAC address: %U",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002881 format_ethernet_address, mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002882 }
Dave Barach75fc8542016-10-11 16:16:02 -04002883
Ed Warnickecb9cada2015-12-08 15:45:58 -07002884 return 0;
2885}
2886
Billy McFall0683c9c2016-10-13 08:27:31 -04002887/*?
2888 * This command converts the given MAC Address into an IPv6 link-local
2889 * address.
2890 *
2891 * @cliexpar
2892 * Example of how to create an IPv6 link-local address:
2893 * @cliexstart{test ip6 link 16:d9:e0:91:79:86}
2894 * Link local address: fe80::14d9:e0ff:fe91:7986
2895 * Original MAC address: 16:d9:e0:91:79:86
2896 * @cliexend
2897?*/
2898/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002899VLIB_CLI_COMMAND (test_link_command, static) =
2900{
Ed Warnickecb9cada2015-12-08 15:45:58 -07002901 .path = "test ip6 link",
Dave Barach75fc8542016-10-11 16:16:02 -04002902 .function = test_ip6_link_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07002903 .short_help = "test ip6 link <mac-address>",
2904};
Billy McFall0683c9c2016-10-13 08:27:31 -04002905/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002906
Dave Barachd7cb1b52016-12-09 09:52:16 -05002907int
2908vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002909{
Neale Ranns107e7d42017-04-11 09:55:19 -07002910 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002911
Neale Ranns107e7d42017-04-11 09:55:19 -07002912 fib_index = fib_table_find (FIB_PROTOCOL_IP6, table_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002913
Neale Ranns107e7d42017-04-11 09:55:19 -07002914 if (~0 == fib_index)
2915 return VNET_API_ERROR_NO_SUCH_FIB;
2916
Neale Ranns227038a2017-04-21 01:07:59 -07002917 fib_table_set_flow_hash_config (fib_index, FIB_PROTOCOL_IP6,
2918 flow_hash_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002919
Neale Ranns227038a2017-04-21 01:07:59 -07002920 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002921}
2922
2923static clib_error_t *
2924set_ip6_flow_hash_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002925 unformat_input_t * input,
2926 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002927{
2928 int matched = 0;
2929 u32 table_id = 0;
2930 u32 flow_hash_config = 0;
2931 int rv;
2932
Dave Barachd7cb1b52016-12-09 09:52:16 -05002933 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2934 {
2935 if (unformat (input, "table %d", &table_id))
2936 matched = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002937#define _(a,v) \
2938 else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
Dave Barachd7cb1b52016-12-09 09:52:16 -05002939 foreach_flow_hash_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07002940#undef _
Dave Barachd7cb1b52016-12-09 09:52:16 -05002941 else
2942 break;
2943 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002944
2945 if (matched == 0)
2946 return clib_error_return (0, "unknown input `%U'",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002947 format_unformat_error, input);
Dave Barach75fc8542016-10-11 16:16:02 -04002948
Ed Warnickecb9cada2015-12-08 15:45:58 -07002949 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
2950 switch (rv)
2951 {
Neale Ranns227038a2017-04-21 01:07:59 -07002952 case 0:
Ed Warnickecb9cada2015-12-08 15:45:58 -07002953 break;
2954
2955 case -1:
2956 return clib_error_return (0, "no such FIB table %d", table_id);
Dave Barach75fc8542016-10-11 16:16:02 -04002957
Ed Warnickecb9cada2015-12-08 15:45:58 -07002958 default:
2959 clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config);
2960 break;
2961 }
Dave Barach75fc8542016-10-11 16:16:02 -04002962
Ed Warnickecb9cada2015-12-08 15:45:58 -07002963 return 0;
2964}
2965
Billy McFall0683c9c2016-10-13 08:27:31 -04002966/*?
2967 * Configure the set of IPv6 fields used by the flow hash.
2968 *
2969 * @cliexpar
2970 * @parblock
2971 * Example of how to set the flow hash on a given table:
Billy McFallebb9a6a2016-10-17 11:35:32 -04002972 * @cliexcmd{set ip6 flow-hash table 8 dst sport dport proto}
2973 *
Billy McFall0683c9c2016-10-13 08:27:31 -04002974 * Example of display the configured flow hash:
2975 * @cliexstart{show ip6 fib}
Billy McFallebb9a6a2016-10-17 11:35:32 -04002976 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
2977 * @::/0
2978 * unicast-ip6-chain
2979 * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]]
2980 * [0] [@0]: dpo-drop ip6
2981 * fe80::/10
2982 * unicast-ip6-chain
2983 * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]]
2984 * [0] [@2]: dpo-receive
2985 * ff02::1/128
2986 * unicast-ip6-chain
2987 * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]]
2988 * [0] [@2]: dpo-receive
2989 * ff02::2/128
2990 * unicast-ip6-chain
2991 * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]]
2992 * [0] [@2]: dpo-receive
2993 * ff02::16/128
2994 * unicast-ip6-chain
2995 * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]]
2996 * [0] [@2]: dpo-receive
2997 * ff02::1:ff00:0/104
2998 * unicast-ip6-chain
2999 * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]]
3000 * [0] [@2]: dpo-receive
3001 * ipv6-VRF:8, fib_index 1, flow hash: dst sport dport proto
3002 * @::/0
3003 * unicast-ip6-chain
3004 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
3005 * [0] [@0]: dpo-drop ip6
3006 * @::a:1:1:0:4/126
3007 * unicast-ip6-chain
3008 * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]]
3009 * [0] [@4]: ipv6-glean: af_packet0
3010 * @::a:1:1:0:7/128
3011 * unicast-ip6-chain
3012 * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]]
3013 * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0
3014 * fe80::/10
3015 * unicast-ip6-chain
3016 * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]]
3017 * [0] [@2]: dpo-receive
3018 * fe80::fe:3eff:fe3e:9222/128
3019 * unicast-ip6-chain
3020 * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]]
3021 * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0
3022 * ff02::1/128
3023 * unicast-ip6-chain
3024 * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]]
3025 * [0] [@2]: dpo-receive
3026 * ff02::2/128
3027 * unicast-ip6-chain
3028 * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]]
3029 * [0] [@2]: dpo-receive
3030 * ff02::16/128
3031 * unicast-ip6-chain
3032 * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]]
3033 * [0] [@2]: dpo-receive
3034 * ff02::1:ff00:0/104
3035 * unicast-ip6-chain
3036 * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]]
3037 * [0] [@2]: dpo-receive
Billy McFall0683c9c2016-10-13 08:27:31 -04003038 * @cliexend
3039 * @endparblock
3040?*/
3041/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003042VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) =
3043{
3044 .path = "set ip6 flow-hash",
3045 .short_help =
3046 "set ip6 flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]",
3047 .function = set_ip6_flow_hash_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003048};
Billy McFall0683c9c2016-10-13 08:27:31 -04003049/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003050
3051static clib_error_t *
3052show_ip6_local_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003053 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003054{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003055 ip6_main_t *im = &ip6_main;
3056 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003057 int i;
Dave Barach75fc8542016-10-11 16:16:02 -04003058
Ed Warnickecb9cada2015-12-08 15:45:58 -07003059 vlib_cli_output (vm, "Protocols handled by ip6_local");
Dave Barachd7cb1b52016-12-09 09:52:16 -05003060 for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003061 {
3062 if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
Pierre Pfister1bfd3722017-09-18 11:40:32 +02003063 {
3064
3065 u32 node_index = vlib_get_node (vm,
3066 ip6_local_node.index)->
3067 next_nodes[lm->local_next_by_ip_protocol[i]];
3068 vlib_cli_output (vm, "%d: %U", i, format_vlib_node_name, vm,
3069 node_index);
3070 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003071 }
3072 return 0;
3073}
3074
3075
3076
Billy McFall0683c9c2016-10-13 08:27:31 -04003077/*?
3078 * Display the set of protocols handled by the local IPv6 stack.
3079 *
3080 * @cliexpar
3081 * Example of how to display local protocol table:
3082 * @cliexstart{show ip6 local}
3083 * Protocols handled by ip6_local
3084 * 17
3085 * 43
3086 * 58
3087 * 115
3088 * @cliexend
3089?*/
3090/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003091VLIB_CLI_COMMAND (show_ip6_local, static) =
3092{
Ed Warnickecb9cada2015-12-08 15:45:58 -07003093 .path = "show ip6 local",
3094 .function = show_ip6_local_command_fn,
Billy McFall0683c9c2016-10-13 08:27:31 -04003095 .short_help = "show ip6 local",
Ed Warnickecb9cada2015-12-08 15:45:58 -07003096};
Billy McFall0683c9c2016-10-13 08:27:31 -04003097/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003098
Dave Barachd7cb1b52016-12-09 09:52:16 -05003099int
3100vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
3101 u32 table_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003102{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003103 vnet_main_t *vnm = vnet_get_main ();
3104 vnet_interface_main_t *im = &vnm->interface_main;
3105 ip6_main_t *ipm = &ip6_main;
3106 ip_lookup_main_t *lm = &ipm->lookup_main;
3107 vnet_classify_main_t *cm = &vnet_classify_main;
Neale Rannsdf089a82016-10-02 16:39:06 +01003108 ip6_address_t *if_addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003109
3110 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
3111 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
3112
3113 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
3114 return VNET_API_ERROR_NO_SUCH_ENTRY;
3115
3116 vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003117 lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003118
Neale Ranns6cfc39c2017-02-14 01:44:25 -08003119 if_addr = ip6_interface_first_address (ipm, sw_if_index);
Neale Rannsdf089a82016-10-02 16:39:06 +01003120
3121 if (NULL != if_addr)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003122 {
Neale Rannsdf089a82016-10-02 16:39:06 +01003123 fib_prefix_t pfx = {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003124 .fp_len = 128,
3125 .fp_proto = FIB_PROTOCOL_IP6,
3126 .fp_addr.ip6 = *if_addr,
Neale Rannsdf089a82016-10-02 16:39:06 +01003127 };
3128 u32 fib_index;
3129
Dave Barachd7cb1b52016-12-09 09:52:16 -05003130 fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
3131 sw_if_index);
Neale Rannsdf089a82016-10-02 16:39:06 +01003132
3133
Dave Barachd7cb1b52016-12-09 09:52:16 -05003134 if (table_index != (u32) ~ 0)
3135 {
3136 dpo_id_t dpo = DPO_INVALID;
Neale Rannsdf089a82016-10-02 16:39:06 +01003137
Dave Barachd7cb1b52016-12-09 09:52:16 -05003138 dpo_set (&dpo,
3139 DPO_CLASSIFY,
3140 DPO_PROTO_IP6,
3141 classify_dpo_create (DPO_PROTO_IP6, table_index));
Neale Rannsdf089a82016-10-02 16:39:06 +01003142
Dave Barachd7cb1b52016-12-09 09:52:16 -05003143 fib_table_entry_special_dpo_add (fib_index,
3144 &pfx,
3145 FIB_SOURCE_CLASSIFY,
3146 FIB_ENTRY_FLAG_NONE, &dpo);
3147 dpo_reset (&dpo);
3148 }
Neale Rannsdf089a82016-10-02 16:39:06 +01003149 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05003150 {
3151 fib_table_entry_special_remove (fib_index,
3152 &pfx, FIB_SOURCE_CLASSIFY);
3153 }
3154 }
Neale Rannsdf089a82016-10-02 16:39:06 +01003155
Ed Warnickecb9cada2015-12-08 15:45:58 -07003156 return 0;
3157}
3158
3159static clib_error_t *
3160set_ip6_classify_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003161 unformat_input_t * input,
3162 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003163{
3164 u32 table_index = ~0;
3165 int table_index_set = 0;
3166 u32 sw_if_index = ~0;
3167 int rv;
Dave Barach75fc8542016-10-11 16:16:02 -04003168
Dave Barachd7cb1b52016-12-09 09:52:16 -05003169 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3170 {
3171 if (unformat (input, "table-index %d", &table_index))
3172 table_index_set = 1;
3173 else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
3174 vnet_get_main (), &sw_if_index))
3175 ;
3176 else
3177 break;
3178 }
Dave Barach75fc8542016-10-11 16:16:02 -04003179
Ed Warnickecb9cada2015-12-08 15:45:58 -07003180 if (table_index_set == 0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003181 return clib_error_return (0, "classify table-index must be specified");
Dave Barach75fc8542016-10-11 16:16:02 -04003182
Ed Warnickecb9cada2015-12-08 15:45:58 -07003183 if (sw_if_index == ~0)
3184 return clib_error_return (0, "interface / subif must be specified");
3185
3186 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3187
3188 switch (rv)
3189 {
3190 case 0:
3191 break;
3192
3193 case VNET_API_ERROR_NO_MATCHING_INTERFACE:
3194 return clib_error_return (0, "No such interface");
3195
3196 case VNET_API_ERROR_NO_SUCH_ENTRY:
3197 return clib_error_return (0, "No such classifier table");
3198 }
3199 return 0;
3200}
3201
Billy McFall0683c9c2016-10-13 08:27:31 -04003202/*?
3203 * Assign a classification table to an interface. The classification
3204 * table is created using the '<em>classify table</em>' and '<em>classify session</em>'
3205 * commands. Once the table is create, use this command to filter packets
3206 * on an interface.
3207 *
3208 * @cliexpar
3209 * Example of how to assign a classification table to an interface:
3210 * @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1}
3211?*/
3212/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003213VLIB_CLI_COMMAND (set_ip6_classify_command, static) =
3214{
3215 .path = "set ip6 classify",
3216 .short_help =
3217 "set ip6 classify intfc <interface> table-index <classify-idx>",
3218 .function = set_ip6_classify_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003219};
Billy McFall0683c9c2016-10-13 08:27:31 -04003220/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003221
3222static clib_error_t *
3223ip6_config (vlib_main_t * vm, unformat_input_t * input)
3224{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003225 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003226 uword heapsize = 0;
3227 u32 tmp;
3228 u32 nbuckets = 0;
3229
Dave Barachd7cb1b52016-12-09 09:52:16 -05003230 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3231 {
3232 if (unformat (input, "hash-buckets %d", &tmp))
3233 nbuckets = tmp;
Neale Ranns1ec36522017-11-29 05:20:37 -08003234 else if (unformat (input, "heap-size %U",
3235 unformat_memory_size, &heapsize))
3236 ;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003237 else
3238 return clib_error_return (0, "unknown input '%U'",
3239 format_unformat_error, input);
3240 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003241
3242 im->lookup_table_nbuckets = nbuckets;
3243 im->lookup_table_size = heapsize;
3244
3245 return 0;
3246}
3247
3248VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6");
Dave Barachd7cb1b52016-12-09 09:52:16 -05003249
3250/*
3251 * fd.io coding-style-patch-verification: ON
3252 *
3253 * Local Variables:
3254 * eval: (c-set-style "gnu")
3255 * End:
3256 */