blob: 6f77c6dd69d5c9bf1aca0c63bcf579f94d6bcc56 [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>
Dave Barachd7cb1b52016-12-09 09:52:16 -050042#include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
Ed Warnickecb9cada2015-12-08 15:45:58 -070043#include <vnet/srp/srp.h> /* for srp_hw_interface_class */
44#include <vppinfra/cache.h>
AkshayaNadahalli0f438df2017-02-10 10:54:16 +053045#include <vnet/fib/fib_urpf_list.h> /* for FIB uRPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +010046#include <vnet/fib/ip6_fib.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000047#include <vnet/mfib/ip6_mfib.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010048#include <vnet/dpo/load_balance.h>
49#include <vnet/dpo/classify_dpo.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070050
51#include <vppinfra/bihash_template.c>
52
AkshayaNadahallifdd81af2016-12-01 16:33:51 +053053/* Flag used by IOAM code. Classifier sets it pop-hop-by-hop checks it */
54#define OI_DECAP 0x80000000
55
Billy McFall0683c9c2016-10-13 08:27:31 -040056/**
57 * @file
58 * @brief IPv6 Forwarding.
59 *
60 * This file contains the source code for IPv6 forwarding.
61 */
62
Pierre Pfister0febaf12016-06-08 12:23:21 +010063void
64ip6_forward_next_trace (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -050065 vlib_node_runtime_t * node,
66 vlib_frame_t * frame,
67 vlib_rx_or_tx_t which_adj_index);
Pierre Pfister0febaf12016-06-08 12:23:21 +010068
Damjan Marionaca64c92016-04-13 09:48:56 +020069always_inline uword
70ip6_lookup_inline (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -050071 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -070072{
Dave Barachd7cb1b52016-12-09 09:52:16 -050073 ip6_main_t *im = &ip6_main;
74 vlib_combined_counter_main_t *cm = &load_balance_main.lbm_to_counters;
75 u32 n_left_from, n_left_to_next, *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -070076 ip_lookup_next_t next;
Dave Barachd7cb1b52016-12-09 09:52:16 -050077 u32 cpu_index = os_get_cpu_number ();
Ed Warnickecb9cada2015-12-08 15:45:58 -070078
79 from = vlib_frame_vector_args (frame);
80 n_left_from = frame->n_vectors;
81 next = node->cached_next_index;
82
83 while (n_left_from > 0)
84 {
Dave Barachd7cb1b52016-12-09 09:52:16 -050085 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -070086
87 while (n_left_from >= 4 && n_left_to_next >= 2)
88 {
Dave Barachd7cb1b52016-12-09 09:52:16 -050089 vlib_buffer_t *p0, *p1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010090 u32 pi0, pi1, lbi0, lbi1, wrong_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -070091 ip_lookup_next_t next0, next1;
Dave Barachd7cb1b52016-12-09 09:52:16 -050092 ip6_header_t *ip0, *ip1;
93 ip6_address_t *dst_addr0, *dst_addr1;
94 u32 fib_index0, fib_index1;
95 u32 flow_hash_config0, flow_hash_config1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010096 const dpo_id_t *dpo0, *dpo1;
97 const load_balance_t *lb0, *lb1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070098
99 /* Prefetch next iteration. */
100 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500101 vlib_buffer_t *p2, *p3;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102
103 p2 = vlib_get_buffer (vm, from[2]);
104 p3 = vlib_get_buffer (vm, from[3]);
105
106 vlib_prefetch_buffer_header (p2, LOAD);
107 vlib_prefetch_buffer_header (p3, LOAD);
108 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), LOAD);
109 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), LOAD);
110 }
111
112 pi0 = to_next[0] = from[0];
113 pi1 = to_next[1] = from[1];
114
115 p0 = vlib_get_buffer (vm, pi0);
116 p1 = vlib_get_buffer (vm, pi1);
117
118 ip0 = vlib_buffer_get_current (p0);
119 ip1 = vlib_buffer_get_current (p1);
120
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100121 dst_addr0 = &ip0->dst_address;
122 dst_addr1 = &ip1->dst_address;
Damjan Marionaca64c92016-04-13 09:48:56 +0200123
Dave Barachd7cb1b52016-12-09 09:52:16 -0500124 fib_index0 =
125 vec_elt (im->fib_index_by_sw_if_index,
126 vnet_buffer (p0)->sw_if_index[VLIB_RX]);
127 fib_index1 =
128 vec_elt (im->fib_index_by_sw_if_index,
129 vnet_buffer (p1)->sw_if_index[VLIB_RX]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130
Dave Barachd7cb1b52016-12-09 09:52:16 -0500131 fib_index0 = (vnet_buffer (p0)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
132 fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX];
133 fib_index1 = (vnet_buffer (p1)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
134 fib_index1 : vnet_buffer (p1)->sw_if_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100136 lbi0 = ip6_fib_table_fwding_lookup (im, fib_index0, dst_addr0);
137 lbi1 = ip6_fib_table_fwding_lookup (im, fib_index1, dst_addr1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100139 lb0 = load_balance_get (lbi0);
140 lb1 = load_balance_get (lbi1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141
Dave Barachd7cb1b52016-12-09 09:52:16 -0500142 vnet_buffer (p0)->ip.flow_hash = vnet_buffer (p1)->ip.flow_hash = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700143
Dave Barachd7cb1b52016-12-09 09:52:16 -0500144 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
145 {
146 flow_hash_config0 = lb0->lb_hash_config;
147 vnet_buffer (p0)->ip.flow_hash =
148 ip6_compute_flow_hash (ip0, flow_hash_config0);
149 }
150 if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
151 {
152 flow_hash_config1 = lb1->lb_hash_config;
153 vnet_buffer (p1)->ip.flow_hash =
154 ip6_compute_flow_hash (ip1, flow_hash_config1);
155 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100157 ASSERT (lb0->lb_n_buckets > 0);
158 ASSERT (lb1->lb_n_buckets > 0);
159 ASSERT (is_pow2 (lb0->lb_n_buckets));
160 ASSERT (is_pow2 (lb1->lb_n_buckets));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500161 dpo0 = load_balance_get_bucket_i (lb0,
162 (vnet_buffer (p0)->ip.flow_hash &
163 lb0->lb_n_buckets_minus_1));
164 dpo1 = load_balance_get_bucket_i (lb1,
165 (vnet_buffer (p1)->ip.flow_hash &
166 lb1->lb_n_buckets_minus_1));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100168 next0 = dpo0->dpoi_next_node;
169 next1 = dpo1->dpoi_next_node;
170
171 /* Only process the HBH Option Header if explicitly configured to do so */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500172 if (PREDICT_FALSE
173 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Shwetha57fc8542016-09-27 08:04:05 +0100174 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500175 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
Shwetha57fc8542016-09-27 08:04:05 +0100176 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
177 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500178 if (PREDICT_FALSE
179 (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Shwetha57fc8542016-09-27 08:04:05 +0100180 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500181 next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
Shwetha57fc8542016-09-27 08:04:05 +0100182 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1;
183 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100184 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
185 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186
Dave Barach75fc8542016-10-11 16:16:02 -0400187 vlib_increment_combined_counter
Dave Barachd7cb1b52016-12-09 09:52:16 -0500188 (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
Dave Barach75fc8542016-10-11 16:16:02 -0400189 vlib_increment_combined_counter
Dave Barachd7cb1b52016-12-09 09:52:16 -0500190 (cm, cpu_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191
192 from += 2;
193 to_next += 2;
194 n_left_to_next -= 2;
195 n_left_from -= 2;
196
Dave Barachd7cb1b52016-12-09 09:52:16 -0500197 wrong_next = (next0 != next) + 2 * (next1 != next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700198 if (PREDICT_FALSE (wrong_next != 0))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500199 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200 switch (wrong_next)
201 {
202 case 1:
203 /* A B A */
204 to_next[-2] = pi1;
205 to_next -= 1;
206 n_left_to_next += 1;
207 vlib_set_next_frame_buffer (vm, node, next0, pi0);
208 break;
209
210 case 2:
211 /* A A B */
212 to_next -= 1;
213 n_left_to_next += 1;
214 vlib_set_next_frame_buffer (vm, node, next1, pi1);
215 break;
216
217 case 3:
218 /* A B C */
219 to_next -= 2;
220 n_left_to_next += 2;
221 vlib_set_next_frame_buffer (vm, node, next0, pi0);
222 vlib_set_next_frame_buffer (vm, node, next1, pi1);
223 if (next0 == next1)
224 {
225 /* A B B */
226 vlib_put_next_frame (vm, node, next, n_left_to_next);
227 next = next1;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500228 vlib_get_next_frame (vm, node, next, to_next,
229 n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700230 }
231 }
232 }
233 }
Dave Barach75fc8542016-10-11 16:16:02 -0400234
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235 while (n_left_from > 0 && n_left_to_next > 0)
236 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500237 vlib_buffer_t *p0;
238 ip6_header_t *ip0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100239 u32 pi0, lbi0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240 ip_lookup_next_t next0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500241 load_balance_t *lb0;
242 ip6_address_t *dst_addr0;
243 u32 fib_index0, flow_hash_config0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100244 const dpo_id_t *dpo0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700245
246 pi0 = from[0];
247 to_next[0] = pi0;
248
249 p0 = vlib_get_buffer (vm, pi0);
250
251 ip0 = vlib_buffer_get_current (p0);
252
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100253 dst_addr0 = &ip0->dst_address;
Damjan Marionaca64c92016-04-13 09:48:56 +0200254
Dave Barachd7cb1b52016-12-09 09:52:16 -0500255 fib_index0 =
256 vec_elt (im->fib_index_by_sw_if_index,
257 vnet_buffer (p0)->sw_if_index[VLIB_RX]);
258 fib_index0 =
259 (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
260 (u32) ~ 0) ? fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700261
Dave Barachd7cb1b52016-12-09 09:52:16 -0500262 flow_hash_config0 = ip6_fib_get (fib_index0)->flow_hash_config;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700263
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100264 lbi0 = ip6_fib_table_fwding_lookup (im, fib_index0, dst_addr0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100266 lb0 = load_balance_get (lbi0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700267
Dave Barachd7cb1b52016-12-09 09:52:16 -0500268 vnet_buffer (p0)->ip.flow_hash = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269
Dave Barachd7cb1b52016-12-09 09:52:16 -0500270 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
271 {
272 flow_hash_config0 = lb0->lb_hash_config;
273 vnet_buffer (p0)->ip.flow_hash =
274 ip6_compute_flow_hash (ip0, flow_hash_config0);
275 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700276
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100277 ASSERT (lb0->lb_n_buckets > 0);
278 ASSERT (is_pow2 (lb0->lb_n_buckets));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500279 dpo0 = load_balance_get_bucket_i (lb0,
280 (vnet_buffer (p0)->ip.flow_hash &
281 lb0->lb_n_buckets_minus_1));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100282 next0 = dpo0->dpoi_next_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700283
Shwetha57fc8542016-09-27 08:04:05 +0100284 /* Only process the HBH Option Header if explicitly configured to do so */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500285 if (PREDICT_FALSE
286 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Shwetha57fc8542016-09-27 08:04:05 +0100287 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500288 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
Shwetha57fc8542016-09-27 08:04:05 +0100289 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
290 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100291 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292
Dave Barach75fc8542016-10-11 16:16:02 -0400293 vlib_increment_combined_counter
Dave Barachd7cb1b52016-12-09 09:52:16 -0500294 (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700295
296 from += 1;
297 to_next += 1;
298 n_left_to_next -= 1;
299 n_left_from -= 1;
300
301 if (PREDICT_FALSE (next0 != next))
302 {
303 n_left_to_next += 1;
304 vlib_put_next_frame (vm, node, next, n_left_to_next);
305 next = next0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500306 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700307 to_next[0] = pi0;
308 to_next += 1;
309 n_left_to_next -= 1;
310 }
311 }
312
313 vlib_put_next_frame (vm, node, next, n_left_to_next);
314 }
315
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100316 if (node->flags & VLIB_NODE_FLAG_TRACE)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500317 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100318
Ed Warnickecb9cada2015-12-08 15:45:58 -0700319 return frame->n_vectors;
320}
321
Ed Warnickecb9cada2015-12-08 15:45:58 -0700322static void
323ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index,
324 ip6_main_t * im, u32 fib_index,
325 ip_interface_address_t * a)
326{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500327 ip_lookup_main_t *lm = &im->lookup_main;
328 ip6_address_t *address = ip_interface_address_get_address (lm, a);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100329 fib_prefix_t pfx = {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500330 .fp_len = a->address_length,
331 .fp_proto = FIB_PROTOCOL_IP6,
332 .fp_addr.ip6 = *address,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100333 };
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334
335 a->neighbor_probe_adj_index = ~0;
336 if (a->address_length < 128)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500337 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100338 fib_node_index_t fei;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339
Dave Barachd7cb1b52016-12-09 09:52:16 -0500340 fei = fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_ATTACHED), FIB_PROTOCOL_IP6, NULL, /* No next-hop address */
341 sw_if_index, ~0, // invalid FIB index
342 1, NULL, // no label stack
343 FIB_ROUTE_PATH_FLAG_NONE);
344 a->neighbor_probe_adj_index = fib_entry_get_adj (fei);
345 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700346
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100347 pfx.fp_len = 128;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700348 if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500349 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100350 u32 classify_table_index =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500351 lm->classify_table_index_by_sw_if_index[sw_if_index];
352 if (classify_table_index != (u32) ~ 0)
353 {
354 dpo_id_t dpo = DPO_INVALID;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100355
Dave Barachd7cb1b52016-12-09 09:52:16 -0500356 dpo_set (&dpo,
357 DPO_CLASSIFY,
358 DPO_PROTO_IP6,
359 classify_dpo_create (DPO_PROTO_IP6, classify_table_index));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100360
Dave Barachd7cb1b52016-12-09 09:52:16 -0500361 fib_table_entry_special_dpo_add (fib_index,
362 &pfx,
363 FIB_SOURCE_CLASSIFY,
364 FIB_ENTRY_FLAG_NONE, &dpo);
365 dpo_reset (&dpo);
366 }
367 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100368
Dave Barachd7cb1b52016-12-09 09:52:16 -0500369 fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL), FIB_PROTOCOL_IP6, &pfx.fp_addr, sw_if_index, ~0, // invalid FIB index
370 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700371}
372
373static void
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100374ip6_del_interface_routes (ip6_main_t * im,
375 u32 fib_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500376 ip6_address_t * address, u32 address_length)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700377{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500378 fib_prefix_t pfx = {
379 .fp_len = address_length,
380 .fp_proto = FIB_PROTOCOL_IP6,
381 .fp_addr.ip6 = *address,
382 };
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383
Dave Barachd7cb1b52016-12-09 09:52:16 -0500384 if (pfx.fp_len < 128)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700385 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500386 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100387
Ed Warnickecb9cada2015-12-08 15:45:58 -0700388 }
389
Dave Barachd7cb1b52016-12-09 09:52:16 -0500390 pfx.fp_len = 128;
391 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700392}
393
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100394void
Dave Barachd7cb1b52016-12-09 09:52:16 -0500395ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100396{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500397 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700398
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100399 vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700400
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100401 /*
402 * enable/disable only on the 1<->0 transition
403 */
404 if (is_enable)
405 {
406 if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index])
Dave Barachd7cb1b52016-12-09 09:52:16 -0500407 return;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100408 }
409 else
410 {
Neale Ranns75152282017-01-09 01:00:45 -0800411 /* The ref count is 0 when an address is removed from an interface that has
412 * no address - this is not a ciritical error */
413 if (0 == im->ip_enabled_by_sw_if_index[sw_if_index] ||
414 0 != --im->ip_enabled_by_sw_if_index[sw_if_index])
Dave Barachd7cb1b52016-12-09 09:52:16 -0500415 return;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100416 }
417
Damjan Marion8b3191e2016-11-09 19:54:20 +0100418 vnet_feature_enable_disable ("ip6-unicast", "ip6-lookup", sw_if_index,
419 is_enable, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100420
Neale Ranns32e1c012016-11-22 17:07:28 +0000421 vnet_feature_enable_disable ("ip6-multicast", "ip6-mfib-forward-lookup",
422 sw_if_index, is_enable, 0, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100423
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100424}
425
Neale Rannsdf089a82016-10-02 16:39:06 +0100426/* get first interface address */
427ip6_address_t *
Neale Ranns6cfc39c2017-02-14 01:44:25 -0800428ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
Neale Rannsdf089a82016-10-02 16:39:06 +0100429{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500430 ip_lookup_main_t *lm = &im->lookup_main;
431 ip_interface_address_t *ia = 0;
432 ip6_address_t *result = 0;
Neale Rannsdf089a82016-10-02 16:39:06 +0100433
Dave Barachd7cb1b52016-12-09 09:52:16 -0500434 /* *INDENT-OFF* */
Neale Rannsdf089a82016-10-02 16:39:06 +0100435 foreach_ip_interface_address (lm, ia, sw_if_index,
436 1 /* honor unnumbered */,
437 ({
438 ip6_address_t * a = ip_interface_address_get_address (lm, ia);
439 result = a;
440 break;
441 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500442 /* *INDENT-ON* */
Neale Rannsdf089a82016-10-02 16:39:06 +0100443 return result;
444}
445
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100446clib_error_t *
447ip6_add_del_interface_address (vlib_main_t * vm,
448 u32 sw_if_index,
449 ip6_address_t * address,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500450 u32 address_length, u32 is_del)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700451{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500452 vnet_main_t *vnm = vnet_get_main ();
453 ip6_main_t *im = &ip6_main;
454 ip_lookup_main_t *lm = &im->lookup_main;
455 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700456 u32 if_address_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500457 ip6_address_fib_t ip6_af, *addr_fib = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700458
459 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000460 vec_validate (im->mfib_index_by_sw_if_index, sw_if_index);
461
Ed Warnickecb9cada2015-12-08 15:45:58 -0700462 ip6_addr_fib_init (&ip6_af, address,
463 vec_elt (im->fib_index_by_sw_if_index, sw_if_index));
464 vec_add1 (addr_fib, ip6_af);
465
466 {
467 uword elts_before = pool_elts (lm->if_address_pool);
468
469 error = ip_interface_address_add_del
Dave Barachd7cb1b52016-12-09 09:52:16 -0500470 (lm, sw_if_index, addr_fib, address_length, is_del, &if_address_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700471 if (error)
472 goto done;
473
474 /* Pool did not grow: add duplicate address. */
475 if (elts_before == pool_elts (lm->if_address_pool))
476 goto done;
477 }
478
Dave Barachd7cb1b52016-12-09 09:52:16 -0500479 ip6_sw_interface_enable_disable (sw_if_index, !is_del);
Neale Ranns177bbdc2016-11-15 09:46:51 +0000480
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100481 if (is_del)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500482 ip6_del_interface_routes (im, ip6_af.fib_index, address, address_length);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100483 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500484 ip6_add_interface_routes (vnm, sw_if_index,
485 im, ip6_af.fib_index,
486 pool_elt_at_index (lm->if_address_pool,
487 if_address_index));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700488
489 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500490 ip6_add_del_interface_address_callback_t *cb;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700491 vec_foreach (cb, im->add_del_interface_address_callbacks)
492 cb->function (im, cb->function_opaque, sw_if_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500493 address, address_length, if_address_index, is_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700494 }
495
Dave Barachd7cb1b52016-12-09 09:52:16 -0500496done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700497 vec_free (addr_fib);
498 return error;
499}
500
501clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500502ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700503{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500504 ip6_main_t *im = &ip6_main;
505 ip_interface_address_t *ia;
506 ip6_address_t *a;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700507 u32 is_admin_up, fib_index;
508
509 /* Fill in lookup tables with default table (0). */
510 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
511
Dave Barachd7cb1b52016-12-09 09:52:16 -0500512 vec_validate_init_empty (im->
513 lookup_main.if_address_pool_index_by_sw_if_index,
514 sw_if_index, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700515
516 is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
517
518 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
519
Dave Barachd7cb1b52016-12-09 09:52:16 -0500520 /* *INDENT-OFF* */
Dave Barach75fc8542016-10-11 16:16:02 -0400521 foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700522 0 /* honor unnumbered */,
523 ({
524 a = ip_interface_address_get_address (&im->lookup_main, ia);
525 if (is_admin_up)
526 ip6_add_interface_routes (vnm, sw_if_index,
527 im, fib_index,
528 ia);
529 else
530 ip6_del_interface_routes (im, fib_index,
531 a, ia->address_length);
532 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500533 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534
535 return 0;
536}
537
538VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
539
Dave Barachd6534602016-06-14 18:38:02 -0400540/* Built-in ip6 unicast rx feature path definition */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500541/* *INDENT-OFF* */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100542VNET_FEATURE_ARC_INIT (ip6_unicast, static) =
543{
544 .arc_name = "ip6-unicast",
545 .start_nodes = VNET_FEATURES ("ip6-input"),
546 .arc_index_ptr = &ip6_main.lookup_main.ucast_feature_arc_index,
547};
548
Dave Barachd7cb1b52016-12-09 09:52:16 -0500549VNET_FEATURE_INIT (ip6_flow_classify, static) =
550{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100551 .arc_name = "ip6-unicast",
Juraj Sloboda506b2452016-08-07 23:45:24 -0700552 .node_name = "ip6-flow-classify",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100553 .runs_before = VNET_FEATURES ("ip6-inacl"),
Juraj Sloboda506b2452016-08-07 23:45:24 -0700554};
555
Dave Barachd7cb1b52016-12-09 09:52:16 -0500556VNET_FEATURE_INIT (ip6_inacl, static) =
557{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100558 .arc_name = "ip6-unicast",
Dave Barach75fc8542016-10-11 16:16:02 -0400559 .node_name = "ip6-inacl",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100560 .runs_before = VNET_FEATURES ("ip6-policer-classify"),
Dave Barachd6534602016-06-14 18:38:02 -0400561};
562
Dave Barachd7cb1b52016-12-09 09:52:16 -0500563VNET_FEATURE_INIT (ip6_policer_classify, static) =
564{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100565 .arc_name = "ip6-unicast",
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700566 .node_name = "ip6-policer-classify",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100567 .runs_before = VNET_FEATURES ("ipsec-input-ip6"),
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700568};
569
Dave Barachd7cb1b52016-12-09 09:52:16 -0500570VNET_FEATURE_INIT (ip6_ipsec, static) =
571{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100572 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400573 .node_name = "ipsec-input-ip6",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100574 .runs_before = VNET_FEATURES ("l2tp-decap"),
Dave Barachd6534602016-06-14 18:38:02 -0400575};
576
Dave Barachd7cb1b52016-12-09 09:52:16 -0500577VNET_FEATURE_INIT (ip6_l2tp, static) =
578{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100579 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400580 .node_name = "l2tp-decap",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100581 .runs_before = VNET_FEATURES ("vpath-input-ip6"),
Dave Barachd6534602016-06-14 18:38:02 -0400582};
583
Dave Barachd7cb1b52016-12-09 09:52:16 -0500584VNET_FEATURE_INIT (ip6_vpath, static) =
585{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100586 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400587 .node_name = "vpath-input-ip6",
John Lo2b81eb82017-01-30 13:12:10 -0500588 .runs_before = VNET_FEATURES ("ip6-vxlan-bypass"),
589};
590
591VNET_FEATURE_INIT (ip6_vxlan_bypass, static) =
592{
593 .arc_name = "ip6-unicast",
594 .node_name = "ip6-vxlan-bypass",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100595 .runs_before = VNET_FEATURES ("ip6-lookup"),
Dave Barachd6534602016-06-14 18:38:02 -0400596};
597
Dave Barachd7cb1b52016-12-09 09:52:16 -0500598VNET_FEATURE_INIT (ip6_lookup, static) =
599{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100600 .arc_name = "ip6-unicast",
Dave Barachd6534602016-06-14 18:38:02 -0400601 .node_name = "ip6-lookup",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100602 .runs_before = VNET_FEATURES ("ip6-drop"),
Dave Barachd6534602016-06-14 18:38:02 -0400603};
604
Dave Barachd7cb1b52016-12-09 09:52:16 -0500605VNET_FEATURE_INIT (ip6_drop, static) =
606{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100607 .arc_name = "ip6-unicast",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100608 .node_name = "ip6-drop",
609 .runs_before = 0, /*last feature*/
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100610};
611
Dave Barachd6534602016-06-14 18:38:02 -0400612/* Built-in ip6 multicast rx feature path definition (none now) */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100613VNET_FEATURE_ARC_INIT (ip6_multicast, static) =
614{
615 .arc_name = "ip6-multicast",
616 .start_nodes = VNET_FEATURES ("ip6-input"),
617 .arc_index_ptr = &ip6_main.lookup_main.mcast_feature_arc_index,
618};
619
620VNET_FEATURE_INIT (ip6_vpath_mc, static) = {
621 .arc_name = "ip6-multicast",
Dave Barachd6534602016-06-14 18:38:02 -0400622 .node_name = "vpath-input-ip6",
Neale Ranns32e1c012016-11-22 17:07:28 +0000623 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
Dave Barachd6534602016-06-14 18:38:02 -0400624};
625
Damjan Marion8b3191e2016-11-09 19:54:20 +0100626VNET_FEATURE_INIT (ip6_mc_lookup, static) = {
627 .arc_name = "ip6-multicast",
Neale Ranns32e1c012016-11-22 17:07:28 +0000628 .node_name = "ip6-mfib-forward-lookup",
Damjan Marion8b3191e2016-11-09 19:54:20 +0100629 .runs_before = VNET_FEATURES ("ip6-drop"),
Dave Barachd6534602016-06-14 18:38:02 -0400630};
631
Damjan Marion8b3191e2016-11-09 19:54:20 +0100632VNET_FEATURE_INIT (ip6_drop_mc, static) = {
633 .arc_name = "ip6-multicast",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100634 .node_name = "ip6-drop",
635 .runs_before = 0, /* last feature */
Neale Ranns5e575b12016-10-03 09:40:25 +0100636};
Dave Barach5331c722016-08-17 11:54:30 -0400637
638/* Built-in ip4 tx feature path definition */
Damjan Marion8b3191e2016-11-09 19:54:20 +0100639VNET_FEATURE_ARC_INIT (ip6_output, static) =
640{
641 .arc_name = "ip6-output",
642 .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain"),
643 .arc_index_ptr = &ip6_main.lookup_main.output_feature_arc_index,
Dave Barach5331c722016-08-17 11:54:30 -0400644};
645
Matus Fabian08a6f012016-11-15 06:08:51 -0800646VNET_FEATURE_INIT (ip6_ipsec_output, static) = {
647 .arc_name = "ip6-output",
648 .node_name = "ipsec-output-ip6",
649 .runs_before = VNET_FEATURES ("interface-output"),
650};
651
Damjan Marion8b3191e2016-11-09 19:54:20 +0100652VNET_FEATURE_INIT (ip6_interface_output, static) = {
653 .arc_name = "ip6-output",
654 .node_name = "interface-output",
655 .runs_before = 0, /* not before any other features */
656};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500657/* *INDENT-ON* */
Dave Barachd6534602016-06-14 18:38:02 -0400658
Ed Warnickecb9cada2015-12-08 15:45:58 -0700659clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500660ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700661{
Damjan Marion8b3191e2016-11-09 19:54:20 +0100662 vnet_feature_enable_disable ("ip6-unicast", "ip6-drop", sw_if_index,
663 is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700664
Damjan Marion8b3191e2016-11-09 19:54:20 +0100665 vnet_feature_enable_disable ("ip6-multicast", "ip6-drop", sw_if_index,
666 is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700667
Damjan Marion8b3191e2016-11-09 19:54:20 +0100668 vnet_feature_enable_disable ("ip6-output", "interface-output", sw_if_index,
669 is_add, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700670
Ed Warnickecb9cada2015-12-08 15:45:58 -0700671 return /* no error */ 0;
672}
673
674VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del);
675
Damjan Marionaca64c92016-04-13 09:48:56 +0200676static uword
677ip6_lookup (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500678 vlib_node_runtime_t * node, vlib_frame_t * frame)
Damjan Marionaca64c92016-04-13 09:48:56 +0200679{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100680 return ip6_lookup_inline (vm, node, frame);
Damjan Marionaca64c92016-04-13 09:48:56 +0200681}
682
Dave Barachd7cb1b52016-12-09 09:52:16 -0500683static u8 *format_ip6_lookup_trace (u8 * s, va_list * args);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100684
Dave Barachd7cb1b52016-12-09 09:52:16 -0500685/* *INDENT-OFF* */
686VLIB_REGISTER_NODE (ip6_lookup_node) =
687{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700688 .function = ip6_lookup,
689 .name = "ip6-lookup",
690 .vector_size = sizeof (u32),
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100691 .format_trace = format_ip6_lookup_trace,
Ole Troanf0f85222016-06-14 21:12:32 +0200692 .n_next_nodes = IP6_LOOKUP_N_NEXT,
Damjan Marionb2707892016-04-13 11:21:07 +0200693 .next_nodes = IP6_LOOKUP_NEXT_NODES,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700694};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500695/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696
Dave Barachd7cb1b52016-12-09 09:52:16 -0500697VLIB_NODE_FUNCTION_MULTIARCH (ip6_lookup_node, ip6_lookup);
Damjan Marion1c80e832016-05-11 23:07:18 +0200698
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100699always_inline uword
700ip6_load_balance (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500701 vlib_node_runtime_t * node, vlib_frame_t * frame)
Damjan Marionaca64c92016-04-13 09:48:56 +0200702{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500703 vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters;
704 u32 n_left_from, n_left_to_next, *from, *to_next;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100705 ip_lookup_next_t next;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500706 u32 cpu_index = os_get_cpu_number ();
707 ip6_main_t *im = &ip6_main;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100708
709 from = vlib_frame_vector_args (frame);
710 n_left_from = frame->n_vectors;
711 next = node->cached_next_index;
712
713 if (node->flags & VLIB_NODE_FLAG_TRACE)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500714 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100715
716 while (n_left_from > 0)
717 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500718 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100719
Dave Barach75fc8542016-10-11 16:16:02 -0400720
Neale Ranns2be95c12016-11-19 13:50:04 +0000721 while (n_left_from >= 4 && n_left_to_next >= 2)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500722 {
723 ip_lookup_next_t next0, next1;
724 const load_balance_t *lb0, *lb1;
725 vlib_buffer_t *p0, *p1;
726 u32 pi0, lbi0, hc0, pi1, lbi1, hc1;
727 const ip6_header_t *ip0, *ip1;
728 const dpo_id_t *dpo0, *dpo1;
Neale Ranns2be95c12016-11-19 13:50:04 +0000729
Dave Barachd7cb1b52016-12-09 09:52:16 -0500730 /* Prefetch next iteration. */
731 {
732 vlib_buffer_t *p2, *p3;
Neale Ranns2be95c12016-11-19 13:50:04 +0000733
Dave Barachd7cb1b52016-12-09 09:52:16 -0500734 p2 = vlib_get_buffer (vm, from[2]);
735 p3 = vlib_get_buffer (vm, from[3]);
Neale Ranns2be95c12016-11-19 13:50:04 +0000736
Dave Barachd7cb1b52016-12-09 09:52:16 -0500737 vlib_prefetch_buffer_header (p2, STORE);
738 vlib_prefetch_buffer_header (p3, STORE);
Neale Ranns2be95c12016-11-19 13:50:04 +0000739
Dave Barachd7cb1b52016-12-09 09:52:16 -0500740 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
741 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
742 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000743
Dave Barachd7cb1b52016-12-09 09:52:16 -0500744 pi0 = to_next[0] = from[0];
745 pi1 = to_next[1] = from[1];
Neale Ranns2be95c12016-11-19 13:50:04 +0000746
Dave Barachd7cb1b52016-12-09 09:52:16 -0500747 from += 2;
748 n_left_from -= 2;
749 to_next += 2;
750 n_left_to_next -= 2;
Neale Ranns2be95c12016-11-19 13:50:04 +0000751
Dave Barachd7cb1b52016-12-09 09:52:16 -0500752 p0 = vlib_get_buffer (vm, pi0);
753 p1 = vlib_get_buffer (vm, pi1);
Neale Ranns2be95c12016-11-19 13:50:04 +0000754
Dave Barachd7cb1b52016-12-09 09:52:16 -0500755 ip0 = vlib_buffer_get_current (p0);
756 ip1 = vlib_buffer_get_current (p1);
757 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
758 lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
Neale Ranns2be95c12016-11-19 13:50:04 +0000759
Dave Barachd7cb1b52016-12-09 09:52:16 -0500760 lb0 = load_balance_get (lbi0);
761 lb1 = load_balance_get (lbi1);
Neale Ranns2be95c12016-11-19 13:50:04 +0000762
Dave Barachd7cb1b52016-12-09 09:52:16 -0500763 /*
764 * this node is for via FIBs we can re-use the hash value from the
765 * to node if present.
766 * We don't want to use the same hash value at each level in the recursion
767 * graph as that would lead to polarisation
768 */
769 hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
770 hc1 = vnet_buffer (p1)->ip.flow_hash = 0;
Neale Ranns2be95c12016-11-19 13:50:04 +0000771
Dave Barachd7cb1b52016-12-09 09:52:16 -0500772 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
773 {
774 if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
775 {
776 hc0 = vnet_buffer (p0)->ip.flow_hash =
777 vnet_buffer (p0)->ip.flow_hash >> 1;
778 }
779 else
780 {
781 hc0 = vnet_buffer (p0)->ip.flow_hash =
782 ip6_compute_flow_hash (ip0, hc0);
783 }
784 }
785 if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
786 {
787 if (PREDICT_TRUE (vnet_buffer (p1)->ip.flow_hash))
788 {
789 hc1 = vnet_buffer (p1)->ip.flow_hash =
790 vnet_buffer (p1)->ip.flow_hash >> 1;
791 }
792 else
793 {
794 hc1 = vnet_buffer (p1)->ip.flow_hash =
795 ip6_compute_flow_hash (ip1, hc1);
796 }
797 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000798
Dave Barachd7cb1b52016-12-09 09:52:16 -0500799 dpo0 =
800 load_balance_get_bucket_i (lb0,
801 hc0 & (lb0->lb_n_buckets_minus_1));
802 dpo1 =
803 load_balance_get_bucket_i (lb1,
804 hc1 & (lb1->lb_n_buckets_minus_1));
Neale Ranns2be95c12016-11-19 13:50:04 +0000805
Dave Barachd7cb1b52016-12-09 09:52:16 -0500806 next0 = dpo0->dpoi_next_node;
807 next1 = dpo1->dpoi_next_node;
Neale Ranns2be95c12016-11-19 13:50:04 +0000808
Dave Barachd7cb1b52016-12-09 09:52:16 -0500809 /* Only process the HBH Option Header if explicitly configured to do so */
810 if (PREDICT_FALSE
811 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
812 {
813 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
814 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
815 }
816 /* Only process the HBH Option Header if explicitly configured to do so */
817 if (PREDICT_FALSE
818 (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
819 {
820 next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
821 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1;
822 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000823
Dave Barachd7cb1b52016-12-09 09:52:16 -0500824 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
825 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
Neale Ranns2be95c12016-11-19 13:50:04 +0000826
Dave Barachd7cb1b52016-12-09 09:52:16 -0500827 vlib_increment_combined_counter
828 (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
829 vlib_increment_combined_counter
830 (cm, cpu_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
Neale Ranns2be95c12016-11-19 13:50:04 +0000831
Dave Barachd7cb1b52016-12-09 09:52:16 -0500832 vlib_validate_buffer_enqueue_x2 (vm, node, next,
833 to_next, n_left_to_next,
834 pi0, pi1, next0, next1);
835 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000836
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100837 while (n_left_from > 0 && n_left_to_next > 0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500838 {
839 ip_lookup_next_t next0;
840 const load_balance_t *lb0;
841 vlib_buffer_t *p0;
842 u32 pi0, lbi0, hc0;
843 const ip6_header_t *ip0;
844 const dpo_id_t *dpo0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100845
Dave Barachd7cb1b52016-12-09 09:52:16 -0500846 pi0 = from[0];
847 to_next[0] = pi0;
848 from += 1;
849 to_next += 1;
850 n_left_to_next -= 1;
851 n_left_from -= 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100852
Dave Barachd7cb1b52016-12-09 09:52:16 -0500853 p0 = vlib_get_buffer (vm, pi0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100854
Dave Barachd7cb1b52016-12-09 09:52:16 -0500855 ip0 = vlib_buffer_get_current (p0);
856 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100857
Dave Barachd7cb1b52016-12-09 09:52:16 -0500858 lb0 = load_balance_get (lbi0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100859
Dave Barachd7cb1b52016-12-09 09:52:16 -0500860 hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
861 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
862 {
863 if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
864 {
865 hc0 = vnet_buffer (p0)->ip.flow_hash =
866 vnet_buffer (p0)->ip.flow_hash >> 1;
867 }
868 else
869 {
870 hc0 = vnet_buffer (p0)->ip.flow_hash =
871 ip6_compute_flow_hash (ip0, hc0);
872 }
873 }
874 dpo0 =
875 load_balance_get_bucket_i (lb0,
876 hc0 & (lb0->lb_n_buckets_minus_1));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100877
Dave Barachd7cb1b52016-12-09 09:52:16 -0500878 next0 = dpo0->dpoi_next_node;
879 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
Neale Ranns2be95c12016-11-19 13:50:04 +0000880
Dave Barachd7cb1b52016-12-09 09:52:16 -0500881 /* Only process the HBH Option Header if explicitly configured to do so */
882 if (PREDICT_FALSE
883 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
884 {
885 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
886 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
887 }
Neale Ranns2be95c12016-11-19 13:50:04 +0000888
Dave Barachd7cb1b52016-12-09 09:52:16 -0500889 vlib_increment_combined_counter
890 (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100891
Dave Barachd7cb1b52016-12-09 09:52:16 -0500892 vlib_validate_buffer_enqueue_x1 (vm, node, next,
893 to_next, n_left_to_next,
894 pi0, next0);
895 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100896
897 vlib_put_next_frame (vm, node, next, n_left_to_next);
898 }
899
900 return frame->n_vectors;
Damjan Marionaca64c92016-04-13 09:48:56 +0200901}
902
Dave Barachd7cb1b52016-12-09 09:52:16 -0500903/* *INDENT-OFF* */
904VLIB_REGISTER_NODE (ip6_load_balance_node) =
905{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100906 .function = ip6_load_balance,
907 .name = "ip6-load-balance",
Damjan Marionaca64c92016-04-13 09:48:56 +0200908 .vector_size = sizeof (u32),
Ole Troanf0f85222016-06-14 21:12:32 +0200909 .sibling_of = "ip6-lookup",
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100910 .format_trace = format_ip6_lookup_trace,
Damjan Marionaca64c92016-04-13 09:48:56 +0200911};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500912/* *INDENT-ON* */
Damjan Marionaca64c92016-04-13 09:48:56 +0200913
Dave Barachd7cb1b52016-12-09 09:52:16 -0500914VLIB_NODE_FUNCTION_MULTIARCH (ip6_load_balance_node, ip6_load_balance);
Damjan Marion1c80e832016-05-11 23:07:18 +0200915
Dave Barachd7cb1b52016-12-09 09:52:16 -0500916typedef struct
917{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700918 /* Adjacency taken. */
919 u32 adj_index;
920 u32 flow_hash;
John Lo2d343742016-01-19 17:27:17 -0500921 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700922
923 /* Packet data, possibly *after* rewrite. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500924 u8 packet_data[128 - 1 * sizeof (u32)];
925}
926ip6_forward_next_trace_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700927
John Lo2b81eb82017-01-30 13:12:10 -0500928u8 *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500929format_ip6_forward_next_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700930{
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100931 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
932 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500933 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100934 uword indent = format_get_indent (s);
935
Dave Barachd7cb1b52016-12-09 09:52:16 -0500936 s = format (s, "%U%U",
937 format_white_space, indent,
938 format_ip6_header, t->packet_data, sizeof (t->packet_data));
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100939 return s;
940}
941
Dave Barachd7cb1b52016-12-09 09:52:16 -0500942static u8 *
943format_ip6_lookup_trace (u8 * s, va_list * args)
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100944{
945 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
946 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500947 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700948 uword indent = format_get_indent (s);
949
John Loac8146c2016-09-27 17:44:02 -0400950 s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500951 t->fib_index, t->adj_index, t->flow_hash);
952 s = format (s, "\n%U%U",
953 format_white_space, indent,
954 format_ip6_header, t->packet_data, sizeof (t->packet_data));
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100955 return s;
956}
Pierre Pfister0febaf12016-06-08 12:23:21 +0100957
Ed Warnickecb9cada2015-12-08 15:45:58 -0700958
Dave Barachd7cb1b52016-12-09 09:52:16 -0500959static u8 *
960format_ip6_rewrite_trace (u8 * s, va_list * args)
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100961{
962 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
963 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500964 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
965 vnet_main_t *vnm = vnet_get_main ();
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100966 uword indent = format_get_indent (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700967
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100968 s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500969 t->fib_index, t->adj_index, format_ip_adjacency,
970 t->adj_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash);
Pierre Pfistera38c3df2016-06-13 10:28:09 +0100971 s = format (s, "\n%U%U",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500972 format_white_space, indent,
973 format_ip_adjacency_packet_data,
974 vnm, t->adj_index, t->packet_data, sizeof (t->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700975 return s;
976}
977
978/* Common trace function for all ip6-forward next nodes. */
979void
980ip6_forward_next_trace (vlib_main_t * vm,
981 vlib_node_runtime_t * node,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500982 vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700983{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500984 u32 *from, n_left;
985 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700986
987 n_left = frame->n_vectors;
988 from = vlib_frame_vector_args (frame);
Pierre Pfister0febaf12016-06-08 12:23:21 +0100989
Ed Warnickecb9cada2015-12-08 15:45:58 -0700990 while (n_left >= 4)
991 {
992 u32 bi0, bi1;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500993 vlib_buffer_t *b0, *b1;
994 ip6_forward_next_trace_t *t0, *t1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700995
996 /* Prefetch next iteration. */
997 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
998 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
999
1000 bi0 = from[0];
1001 bi1 = from[1];
1002
1003 b0 = vlib_get_buffer (vm, bi0);
1004 b1 = vlib_get_buffer (vm, bi1);
1005
1006 if (b0->flags & VLIB_BUFFER_IS_TRACED)
1007 {
1008 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1009 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001010 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
1011 t0->fib_index =
1012 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
1013 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
1014 vec_elt (im->fib_index_by_sw_if_index,
1015 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +01001016
Damjan Marionf1213b82016-03-13 02:22:06 +01001017 clib_memcpy (t0->packet_data,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001018 vlib_buffer_get_current (b0),
1019 sizeof (t0->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001020 }
1021 if (b1->flags & VLIB_BUFFER_IS_TRACED)
1022 {
1023 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
1024 t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001025 t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
1026 t1->fib_index =
1027 (vnet_buffer (b1)->sw_if_index[VLIB_TX] !=
1028 (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] :
1029 vec_elt (im->fib_index_by_sw_if_index,
1030 vnet_buffer (b1)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +01001031
Damjan Marionf1213b82016-03-13 02:22:06 +01001032 clib_memcpy (t1->packet_data,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001033 vlib_buffer_get_current (b1),
1034 sizeof (t1->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001035 }
1036 from += 2;
1037 n_left -= 2;
1038 }
1039
1040 while (n_left >= 1)
1041 {
1042 u32 bi0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001043 vlib_buffer_t *b0;
1044 ip6_forward_next_trace_t *t0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001045
1046 bi0 = from[0];
1047
1048 b0 = vlib_get_buffer (vm, bi0);
1049
1050 if (b0->flags & VLIB_BUFFER_IS_TRACED)
1051 {
1052 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1053 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001054 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
1055 t0->fib_index =
1056 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
1057 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
1058 vec_elt (im->fib_index_by_sw_if_index,
1059 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Pierre Pfister0febaf12016-06-08 12:23:21 +01001060
Damjan Marionf1213b82016-03-13 02:22:06 +01001061 clib_memcpy (t0->packet_data,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001062 vlib_buffer_get_current (b0),
1063 sizeof (t0->packet_data));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001064 }
1065 from += 1;
1066 n_left -= 1;
1067 }
1068}
1069
1070static uword
1071ip6_drop_or_punt (vlib_main_t * vm,
1072 vlib_node_runtime_t * node,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001073 vlib_frame_t * frame, ip6_error_t error_code)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001074{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001075 u32 *buffers = vlib_frame_vector_args (frame);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001076 uword n_packets = frame->n_vectors;
1077
Dave Barachd7cb1b52016-12-09 09:52:16 -05001078 vlib_error_drop_buffers (vm, node, buffers,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001079 /* stride */ 1,
1080 n_packets,
1081 /* next */ 0,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001082 ip6_input_node.index, error_code);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001083
1084 if (node->flags & VLIB_NODE_FLAG_TRACE)
1085 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1086
1087 return n_packets;
1088}
1089
1090static uword
Dave Barachd7cb1b52016-12-09 09:52:16 -05001091ip6_drop (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1092{
1093 return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_DROP);
1094}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001095
1096static uword
Dave Barachd7cb1b52016-12-09 09:52:16 -05001097ip6_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1098{
1099 return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_PUNT);
1100}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001101
Dave Barachd7cb1b52016-12-09 09:52:16 -05001102/* *INDENT-OFF* */
1103VLIB_REGISTER_NODE (ip6_drop_node, static) =
1104{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001105 .function = ip6_drop,
1106 .name = "ip6-drop",
1107 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -07001108 .format_trace = format_ip6_forward_next_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001109 .n_next_nodes = 1,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001110 .next_nodes =
1111 {
1112 [0] = "error-drop",},
Ed Warnickecb9cada2015-12-08 15:45:58 -07001113};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001114/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001115
Dave Barachd7cb1b52016-12-09 09:52:16 -05001116VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop);
Damjan Marion1c80e832016-05-11 23:07:18 +02001117
Dave Barachd7cb1b52016-12-09 09:52:16 -05001118/* *INDENT-OFF* */
1119VLIB_REGISTER_NODE (ip6_punt_node, static) =
1120{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001121 .function = ip6_punt,
1122 .name = "ip6-punt",
1123 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -07001124 .format_trace = format_ip6_forward_next_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001125 .n_next_nodes = 1,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001126 .next_nodes =
1127 {
1128 [0] = "error-punt",},
Ed Warnickecb9cada2015-12-08 15:45:58 -07001129};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001130/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001131
Dave Barachd7cb1b52016-12-09 09:52:16 -05001132VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt);
Damjan Marion1c80e832016-05-11 23:07:18 +02001133
Ed Warnickecb9cada2015-12-08 15:45:58 -07001134/* Compute TCP/UDP/ICMP6 checksum in software. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001135u16
1136ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
1137 ip6_header_t * ip0, int *bogus_lengthp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001138{
1139 ip_csum_t sum0;
1140 u16 sum16, payload_length_host_byte_order;
1141 u32 i, n_this_buffer, n_bytes_left;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001142 u32 headers_size = sizeof (ip0[0]);
1143 void *data_this_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001144
Dave Barachd7cb1b52016-12-09 09:52:16 -05001145 ASSERT (bogus_lengthp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001146 *bogus_lengthp = 0;
1147
1148 /* Initialize checksum with ip header. */
1149 sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol);
1150 payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
1151 data_this_buffer = (void *) (ip0 + 1);
Dave Barach75fc8542016-10-11 16:16:02 -04001152
Ed Warnickecb9cada2015-12-08 15:45:58 -07001153 for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
1154 {
1155 sum0 = ip_csum_with_carry (sum0,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001156 clib_mem_unaligned (&ip0->
1157 src_address.as_uword[i],
1158 uword));
1159 sum0 =
1160 ip_csum_with_carry (sum0,
1161 clib_mem_unaligned (&ip0->dst_address.as_uword[i],
1162 uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001163 }
1164
1165 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001166 if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001167 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001168 u32 skip_bytes;
1169 ip6_hop_by_hop_ext_t *ext_hdr =
1170 (ip6_hop_by_hop_ext_t *) data_this_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001171
1172 /* validate really icmp6 next */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001173 ASSERT (ext_hdr->next_hdr == IP_PROTOCOL_ICMP6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001174
Dave Barachd7cb1b52016-12-09 09:52:16 -05001175 skip_bytes = 8 * (1 + ext_hdr->n_data_u64s);
1176 data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes);
Dave Barach75fc8542016-10-11 16:16:02 -04001177
Dave Barachd7cb1b52016-12-09 09:52:16 -05001178 payload_length_host_byte_order -= skip_bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001179 headers_size += skip_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001180 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001181
1182 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001183 if (p0 && n_this_buffer + headers_size > p0->current_length)
1184 n_this_buffer =
1185 p0->current_length >
1186 headers_size ? p0->current_length - headers_size : 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001187 while (1)
1188 {
1189 sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
1190 n_bytes_left -= n_this_buffer;
1191 if (n_bytes_left == 0)
1192 break;
1193
1194 if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
Dave Barachd7cb1b52016-12-09 09:52:16 -05001195 {
1196 *bogus_lengthp = 1;
1197 return 0xfefe;
1198 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001199 p0 = vlib_get_buffer (vm, p0->next_buffer);
1200 data_this_buffer = vlib_buffer_get_current (p0);
1201 n_this_buffer = p0->current_length;
1202 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001203
Dave Barachd7cb1b52016-12-09 09:52:16 -05001204 sum16 = ~ip_csum_fold (sum0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001205
1206 return sum16;
1207}
1208
Dave Barachd7cb1b52016-12-09 09:52:16 -05001209u32
1210ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001211{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001212 ip6_header_t *ip0 = vlib_buffer_get_current (p0);
1213 udp_header_t *udp0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001214 u16 sum16;
1215 int bogus_length;
1216
1217 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
1218 ASSERT (ip0->protocol == IP_PROTOCOL_TCP
1219 || ip0->protocol == IP_PROTOCOL_ICMP6
1220 || ip0->protocol == IP_PROTOCOL_UDP
Dave Barachd7cb1b52016-12-09 09:52:16 -05001221 || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001222
1223 udp0 = (void *) (ip0 + 1);
1224 if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0)
1225 {
1226 p0->flags |= (IP_BUFFER_L4_CHECKSUM_COMPUTED
1227 | IP_BUFFER_L4_CHECKSUM_CORRECT);
1228 return p0->flags;
1229 }
1230
1231 sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length);
1232
1233 p0->flags |= (IP_BUFFER_L4_CHECKSUM_COMPUTED
1234 | ((sum16 == 0) << LOG2_IP_BUFFER_L4_CHECKSUM_CORRECT));
1235
1236 return p0->flags;
1237}
1238
Shwethab78292e2016-09-13 11:51:00 +01001239/* ip6_locate_header
1240 *
1241 * This function is to search for the header specified by the find_hdr number.
1242 * 1. If the find_hdr < 0 then it finds and returns the protocol number and
1243 * offset stored in *offset of the transport or ESP header in the chain if
1244 * found.
1245 * 2. If a header with find_hdr > 0 protocol number is found then the
1246 * offset is stored in *offset and protocol number of the header is
1247 * returned.
1248 * 3. If find_hdr header is not found or packet is malformed or
1249 * it is a non-first fragment -1 is returned.
1250 */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001251always_inline int
1252ip6_locate_header (vlib_buffer_t * p0,
1253 ip6_header_t * ip0, int find_hdr, u32 * offset)
Shwethab78292e2016-09-13 11:51:00 +01001254{
1255 u8 next_proto = ip0->protocol;
1256 u8 *next_header;
1257 u8 done = 0;
1258 u32 cur_offset;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001259 u8 *temp_nxthdr = 0;
Shwethab78292e2016-09-13 11:51:00 +01001260 u32 exthdr_len = 0;
1261
Dave Barachd7cb1b52016-12-09 09:52:16 -05001262 next_header = ip6_next_header (ip0);
1263 cur_offset = sizeof (ip6_header_t);
1264 while (1)
Shwethab78292e2016-09-13 11:51:00 +01001265 {
1266 done = (next_proto == find_hdr);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001267 if (PREDICT_FALSE
1268 (next_header >=
1269 (u8 *) vlib_buffer_get_current (p0) + p0->current_length))
Shwethab78292e2016-09-13 11:51:00 +01001270 {
1271 //A malicious packet could set an extension header with a too big size
Dave Barachd7cb1b52016-12-09 09:52:16 -05001272 return (-1);
Shwethab78292e2016-09-13 11:51:00 +01001273 }
1274 if (done)
1275 break;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001276 if ((!ip6_ext_hdr (next_proto)) || next_proto == IP_PROTOCOL_IP6_NONXT)
Shwethab78292e2016-09-13 11:51:00 +01001277 {
1278 if (find_hdr < 0)
1279 break;
1280 return -1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001281 }
Shwethab78292e2016-09-13 11:51:00 +01001282 if (next_proto == IP_PROTOCOL_IPV6_FRAGMENTATION)
1283 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001284 ip6_frag_hdr_t *frag_hdr = (ip6_frag_hdr_t *) next_header;
1285 u16 frag_off = ip6_frag_hdr_offset (frag_hdr);
1286 /* Non first fragment return -1 */
Shwethab78292e2016-09-13 11:51:00 +01001287 if (frag_off)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001288 return (-1);
1289 exthdr_len = sizeof (ip6_frag_hdr_t);
1290 temp_nxthdr = next_header + exthdr_len;
Shwethab78292e2016-09-13 11:51:00 +01001291 }
1292 else if (next_proto == IP_PROTOCOL_IPSEC_AH)
1293 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001294 exthdr_len =
1295 ip6_ext_authhdr_len (((ip6_ext_header_t *) next_header));
Shwethab78292e2016-09-13 11:51:00 +01001296 temp_nxthdr = next_header + exthdr_len;
1297 }
1298 else
1299 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001300 exthdr_len =
1301 ip6_ext_header_len (((ip6_ext_header_t *) next_header));
Shwethab78292e2016-09-13 11:51:00 +01001302 temp_nxthdr = next_header + exthdr_len;
1303 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001304 next_proto = ((ip6_ext_header_t *) next_header)->next_hdr;
1305 next_header = temp_nxthdr;
1306 cur_offset += exthdr_len;
Shwethab78292e2016-09-13 11:51:00 +01001307 }
1308
1309 *offset = cur_offset;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001310 return (next_proto);
Shwethab78292e2016-09-13 11:51:00 +01001311}
1312
AkshayaNadahalli0f438df2017-02-10 10:54:16 +05301313/**
1314 * @brief returns number of links on which src is reachable.
1315 */
1316always_inline int
1317ip6_urpf_loose_check (ip6_main_t * im, vlib_buffer_t * b, ip6_header_t * i)
1318{
1319 const load_balance_t *lb0;
1320 index_t lbi;
1321
1322 lbi = ip6_fib_table_fwding_lookup_with_if_index (im,
1323 vnet_buffer
1324 (b)->sw_if_index[VLIB_RX],
1325 &i->src_address);
1326
1327 lb0 = load_balance_get (lbi);
1328
1329 return (fib_urpf_check_size (lb0->lb_urpf));
1330}
1331
Ed Warnickecb9cada2015-12-08 15:45:58 -07001332static uword
Dave Barachd7cb1b52016-12-09 09:52:16 -05001333ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001334{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001335 ip6_main_t *im = &ip6_main;
1336 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001337 ip_local_next_t next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001338 u32 *from, *to_next, n_left_from, n_left_to_next;
1339 vlib_node_runtime_t *error_node =
1340 vlib_node_get_runtime (vm, ip6_input_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001341
1342 from = vlib_frame_vector_args (frame);
1343 n_left_from = frame->n_vectors;
1344 next_index = node->cached_next_index;
Dave Barach75fc8542016-10-11 16:16:02 -04001345
Ed Warnickecb9cada2015-12-08 15:45:58 -07001346 if (node->flags & VLIB_NODE_FLAG_TRACE)
1347 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1348
1349 while (n_left_from > 0)
1350 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001351 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001352
1353 while (n_left_from >= 4 && n_left_to_next >= 2)
1354 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001355 vlib_buffer_t *p0, *p1;
1356 ip6_header_t *ip0, *ip1;
1357 udp_header_t *udp0, *udp1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001358 u32 pi0, ip_len0, udp_len0, flags0, next0;
1359 u32 pi1, ip_len1, udp_len1, flags1, next1;
1360 i32 len_diff0, len_diff1;
1361 u8 error0, type0, good_l4_checksum0;
1362 u8 error1, type1, good_l4_checksum1;
Shwethab78292e2016-09-13 11:51:00 +01001363 u32 udp_offset0, udp_offset1;
Dave Barach75fc8542016-10-11 16:16:02 -04001364
Ed Warnickecb9cada2015-12-08 15:45:58 -07001365 pi0 = to_next[0] = from[0];
1366 pi1 = to_next[1] = from[1];
1367 from += 2;
1368 n_left_from -= 2;
1369 to_next += 2;
1370 n_left_to_next -= 2;
Dave Barach75fc8542016-10-11 16:16:02 -04001371
Ed Warnickecb9cada2015-12-08 15:45:58 -07001372 p0 = vlib_get_buffer (vm, pi0);
1373 p1 = vlib_get_buffer (vm, pi1);
1374
1375 ip0 = vlib_buffer_get_current (p0);
1376 ip1 = vlib_buffer_get_current (p1);
1377
Filip Tehlarb601f222017-01-02 10:22:56 +01001378 vnet_buffer (p0)->ip.start_of_ip_header = p0->current_data;
1379 vnet_buffer (p1)->ip.start_of_ip_header = p1->current_data;
1380
Ed Warnickecb9cada2015-12-08 15:45:58 -07001381 type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
1382 type1 = lm->builtin_protocol_by_ip_protocol[ip1->protocol];
1383
1384 next0 = lm->local_next_by_ip_protocol[ip0->protocol];
1385 next1 = lm->local_next_by_ip_protocol[ip1->protocol];
1386
1387 flags0 = p0->flags;
1388 flags1 = p1->flags;
1389
1390 good_l4_checksum0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1391 good_l4_checksum1 = (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
Shwethab78292e2016-09-13 11:51:00 +01001392 len_diff0 = 0;
1393 len_diff1 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001394
Shwethab78292e2016-09-13 11:51:00 +01001395 /* Skip HBH local processing */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001396 if (PREDICT_FALSE
1397 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Shwethab78292e2016-09-13 11:51:00 +01001398 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001399 ip6_hop_by_hop_ext_t *ext_hdr =
1400 (ip6_hop_by_hop_ext_t *) ip6_next_header (ip0);
Shwethab78292e2016-09-13 11:51:00 +01001401 next0 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr];
1402 type0 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr];
1403 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001404 if (PREDICT_FALSE
1405 (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Shwethab78292e2016-09-13 11:51:00 +01001406 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001407 ip6_hop_by_hop_ext_t *ext_hdr =
1408 (ip6_hop_by_hop_ext_t *) ip6_next_header (ip1);
Shwethab78292e2016-09-13 11:51:00 +01001409 next1 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr];
1410 type1 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr];
1411 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001412 if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p0, ip0,
1413 IP_PROTOCOL_UDP,
1414 &udp_offset0)))
Shwethab78292e2016-09-13 11:51:00 +01001415 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001416 udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0);
Shwethab78292e2016-09-13 11:51:00 +01001417 /* Don't verify UDP checksum for packets with explicit zero checksum. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001418 good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP
1419 && udp0->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001420 /* Verify UDP length. */
1421 ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1422 udp_len0 = clib_net_to_host_u16 (udp0->length);
1423 len_diff0 = ip_len0 - udp_len0;
1424 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001425 if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p1, ip1,
1426 IP_PROTOCOL_UDP,
1427 &udp_offset1)))
Shwethab78292e2016-09-13 11:51:00 +01001428 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001429 udp1 = (udp_header_t *) ((u8 *) ip1 + udp_offset1);
Shwethab78292e2016-09-13 11:51:00 +01001430 /* Don't verify UDP checksum for packets with explicit zero checksum. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001431 good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UDP
1432 && udp1->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001433 /* Verify UDP length. */
1434 ip_len1 = clib_net_to_host_u16 (ip1->payload_length);
1435 udp_len1 = clib_net_to_host_u16 (udp1->length);
1436 len_diff1 = ip_len1 - udp_len1;
1437 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001438
1439 good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1440 good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1441
Ed Warnickecb9cada2015-12-08 15:45:58 -07001442 len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1443 len_diff1 = type1 == IP_BUILTIN_PROTOCOL_UDP ? len_diff1 : 0;
1444
1445 if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
Dave Barachd7cb1b52016-12-09 09:52:16 -05001446 && !good_l4_checksum0
1447 && !(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001448 {
1449 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
1450 good_l4_checksum0 =
1451 (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1452 }
1453 if (PREDICT_FALSE (type1 != IP_BUILTIN_PROTOCOL_UNKNOWN
Dave Barachd7cb1b52016-12-09 09:52:16 -05001454 && !good_l4_checksum1
1455 && !(flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001456 {
1457 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, p1);
1458 good_l4_checksum1 =
1459 (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1460 }
1461
1462 error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL;
1463
1464 error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1465 error1 = len_diff1 < 0 ? IP6_ERROR_UDP_LENGTH : error1;
1466
Dave Barachd7cb1b52016-12-09 09:52:16 -05001467 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1468 IP6_ERROR_UDP_CHECKSUM);
1469 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1470 IP6_ERROR_ICMP_CHECKSUM);
1471 error0 =
1472 (!good_l4_checksum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0);
1473 error1 =
1474 (!good_l4_checksum1 ? IP6_ERROR_UDP_CHECKSUM + type1 : error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001475
1476 /* Drop packets from unroutable hosts. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001477 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001478 if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1479 type0 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001480 !ip6_address_is_link_local_unicast (&ip0->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001481 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301482 error0 = (!ip6_urpf_loose_check (im, p0, ip0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001483 ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001484 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001485 if (error1 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1486 type1 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001487 !ip6_address_is_link_local_unicast (&ip1->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001488 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301489 error1 = (!ip6_urpf_loose_check (im, p1, ip1)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001490 ? IP6_ERROR_SRC_LOOKUP_MISS : error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001491 }
1492
Dave Barachd7cb1b52016-12-09 09:52:16 -05001493 next0 =
1494 error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
1495 next1 =
1496 error1 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001497
1498 p0->error = error_node->errors[error0];
1499 p1->error = error_node->errors[error1];
1500
1501 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1502 to_next, n_left_to_next,
1503 pi0, pi1, next0, next1);
1504 }
1505
1506 while (n_left_from > 0 && n_left_to_next > 0)
1507 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001508 vlib_buffer_t *p0;
1509 ip6_header_t *ip0;
1510 udp_header_t *udp0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001511 u32 pi0, ip_len0, udp_len0, flags0, next0;
1512 i32 len_diff0;
1513 u8 error0, type0, good_l4_checksum0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001514 u32 udp_offset0;
Dave Barach75fc8542016-10-11 16:16:02 -04001515
Ed Warnickecb9cada2015-12-08 15:45:58 -07001516 pi0 = to_next[0] = from[0];
1517 from += 1;
1518 n_left_from -= 1;
1519 to_next += 1;
1520 n_left_to_next -= 1;
Dave Barach75fc8542016-10-11 16:16:02 -04001521
Ed Warnickecb9cada2015-12-08 15:45:58 -07001522 p0 = vlib_get_buffer (vm, pi0);
1523
1524 ip0 = vlib_buffer_get_current (p0);
1525
Filip Tehlarb601f222017-01-02 10:22:56 +01001526 vnet_buffer (p0)->ip.start_of_ip_header = p0->current_data;
1527
Ed Warnickecb9cada2015-12-08 15:45:58 -07001528 type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
1529 next0 = lm->local_next_by_ip_protocol[ip0->protocol];
1530
1531 flags0 = p0->flags;
1532
1533 good_l4_checksum0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
Shwethab78292e2016-09-13 11:51:00 +01001534 len_diff0 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001535
Shwethab78292e2016-09-13 11:51:00 +01001536 /* Skip HBH local processing */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001537 if (PREDICT_FALSE
1538 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
Shwethab78292e2016-09-13 11:51:00 +01001539 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001540 ip6_hop_by_hop_ext_t *ext_hdr =
1541 (ip6_hop_by_hop_ext_t *) ip6_next_header (ip0);
Shwethab78292e2016-09-13 11:51:00 +01001542 next0 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr];
1543 type0 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr];
1544 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001545 if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p0, ip0,
1546 IP_PROTOCOL_UDP,
1547 &udp_offset0)))
Shwethab78292e2016-09-13 11:51:00 +01001548 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001549 udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0);
Shwethab78292e2016-09-13 11:51:00 +01001550 /* Don't verify UDP checksum for packets with explicit zero checksum. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001551 good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP
1552 && udp0->checksum == 0;
Shwethab78292e2016-09-13 11:51:00 +01001553 /* Verify UDP length. */
1554 ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1555 udp_len0 = clib_net_to_host_u16 (udp0->length);
1556 len_diff0 = ip_len0 - udp_len0;
1557 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001558
1559 good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001560 len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1561
1562 if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
Dave Barachd7cb1b52016-12-09 09:52:16 -05001563 && !good_l4_checksum0
1564 && !(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001565 {
1566 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
1567 good_l4_checksum0 =
1568 (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1569 }
1570
1571 error0 = IP6_ERROR_UNKNOWN_PROTOCOL;
1572
1573 error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1574
Dave Barachd7cb1b52016-12-09 09:52:16 -05001575 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1576 IP6_ERROR_UDP_CHECKSUM);
1577 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1578 IP6_ERROR_ICMP_CHECKSUM);
1579 error0 =
1580 (!good_l4_checksum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001581
Dave Barachd7cb1b52016-12-09 09:52:16 -05001582 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001583 if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1584 type0 != IP_BUILTIN_PROTOCOL_ICMP &&
Dave Barachd7cb1b52016-12-09 09:52:16 -05001585 !ip6_address_is_link_local_unicast (&ip0->src_address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001586 {
AkshayaNadahalli8ea6d712017-02-07 23:59:54 +05301587 error0 = (!ip6_urpf_loose_check (im, p0, ip0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001588 ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001589 }
1590
Dave Barachd7cb1b52016-12-09 09:52:16 -05001591 next0 =
1592 error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001593
1594 p0->error = error_node->errors[error0];
1595
1596 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1597 to_next, n_left_to_next,
1598 pi0, next0);
1599 }
Dave Barach75fc8542016-10-11 16:16:02 -04001600
Ed Warnickecb9cada2015-12-08 15:45:58 -07001601 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1602 }
1603
1604 return frame->n_vectors;
1605}
1606
Dave Barachd7cb1b52016-12-09 09:52:16 -05001607/* *INDENT-OFF* */
1608VLIB_REGISTER_NODE (ip6_local_node, static) =
1609{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001610 .function = ip6_local,
1611 .name = "ip6-local",
1612 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -07001613 .format_trace = format_ip6_forward_next_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001614 .n_next_nodes = IP_LOCAL_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001615 .next_nodes =
1616 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07001617 [IP_LOCAL_NEXT_DROP] = "error-drop",
1618 [IP_LOCAL_NEXT_PUNT] = "error-punt",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001619 [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
1620 [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
1621 },
1622};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001623/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001624
Dave Barachd7cb1b52016-12-09 09:52:16 -05001625VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_node, ip6_local);
Damjan Marion1c80e832016-05-11 23:07:18 +02001626
Dave Barachd7cb1b52016-12-09 09:52:16 -05001627void
1628ip6_register_protocol (u32 protocol, u32 node_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001629{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001630 vlib_main_t *vm = vlib_get_main ();
1631 ip6_main_t *im = &ip6_main;
1632 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001633
1634 ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
Dave Barachd7cb1b52016-12-09 09:52:16 -05001635 lm->local_next_by_ip_protocol[protocol] =
1636 vlib_node_add_next (vm, ip6_local_node.index, node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001637}
1638
Dave Barachd7cb1b52016-12-09 09:52:16 -05001639typedef enum
1640{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001641 IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
John Lod1f5d042016-04-12 18:20:39 -04001642 IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001643 IP6_DISCOVER_NEIGHBOR_N_NEXT,
1644} ip6_discover_neighbor_next_t;
1645
Dave Barachd7cb1b52016-12-09 09:52:16 -05001646typedef enum
1647{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001648 IP6_DISCOVER_NEIGHBOR_ERROR_DROP,
1649 IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT,
Pierre Pfisterd076f192016-06-22 12:58:30 +01001650 IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001651} ip6_discover_neighbor_error_t;
1652
1653static uword
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001654ip6_discover_neighbor_inline (vlib_main_t * vm,
1655 vlib_node_runtime_t * node,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001656 vlib_frame_t * frame, int is_glean)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001657{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001658 vnet_main_t *vnm = vnet_get_main ();
1659 ip6_main_t *im = &ip6_main;
1660 ip_lookup_main_t *lm = &im->lookup_main;
1661 u32 *from, *to_next_drop;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001662 uword n_left_from, n_left_to_next_drop;
1663 static f64 time_last_seed_change = -1e100;
1664 static u32 hash_seeds[3];
Dave Barach75fc8542016-10-11 16:16:02 -04001665 static uword hash_bitmap[256 / BITS (uword)];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001666 f64 time_now;
1667 int bogus_length;
1668
1669 if (node->flags & VLIB_NODE_FLAG_TRACE)
1670 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1671
1672 time_now = vlib_time_now (vm);
1673 if (time_now - time_last_seed_change > 1e-3)
1674 {
1675 uword i;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001676 u32 *r = clib_random_buffer_get_data (&vm->random_buffer,
1677 sizeof (hash_seeds));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001678 for (i = 0; i < ARRAY_LEN (hash_seeds); i++)
1679 hash_seeds[i] = r[i];
1680
1681 /* Mark all hash keys as been not-seen before. */
1682 for (i = 0; i < ARRAY_LEN (hash_bitmap); i++)
1683 hash_bitmap[i] = 0;
1684
1685 time_last_seed_change = time_now;
1686 }
1687
1688 from = vlib_frame_vector_args (frame);
1689 n_left_from = frame->n_vectors;
1690
1691 while (n_left_from > 0)
1692 {
1693 vlib_get_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
1694 to_next_drop, n_left_to_next_drop);
1695
1696 while (n_left_from > 0 && n_left_to_next_drop > 0)
1697 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001698 vlib_buffer_t *p0;
1699 ip6_header_t *ip0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001700 u32 pi0, adj_index0, a0, b0, c0, m0, sw_if_index0, drop0;
1701 uword bm0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001702 ip_adjacency_t *adj0;
1703 vnet_hw_interface_t *hw_if0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001704 u32 next0;
1705
1706 pi0 = from[0];
1707
1708 p0 = vlib_get_buffer (vm, pi0);
1709
1710 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1711
1712 ip0 = vlib_buffer_get_current (p0);
1713
1714 adj0 = ip_get_adjacency (lm, adj_index0);
1715
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001716 if (!is_glean)
1717 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001718 ip0->dst_address.as_u64[0] =
1719 adj0->sub_type.nbr.next_hop.ip6.as_u64[0];
1720 ip0->dst_address.as_u64[1] =
1721 adj0->sub_type.nbr.next_hop.ip6.as_u64[1];
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001722 }
Pierre Pfister1dabaaf2016-04-25 14:15:15 +01001723
Ed Warnickecb9cada2015-12-08 15:45:58 -07001724 a0 = hash_seeds[0];
1725 b0 = hash_seeds[1];
1726 c0 = hash_seeds[2];
1727
1728 sw_if_index0 = adj0->rewrite_header.sw_if_index;
1729 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
1730
1731 a0 ^= sw_if_index0;
1732 b0 ^= ip0->dst_address.as_u32[0];
1733 c0 ^= ip0->dst_address.as_u32[1];
1734
1735 hash_v3_mix32 (a0, b0, c0);
1736
1737 b0 ^= ip0->dst_address.as_u32[2];
1738 c0 ^= ip0->dst_address.as_u32[3];
1739
1740 hash_v3_finalize32 (a0, b0, c0);
1741
1742 c0 &= BITS (hash_bitmap) - 1;
1743 c0 = c0 / BITS (uword);
1744 m0 = (uword) 1 << (c0 % BITS (uword));
1745
1746 bm0 = hash_bitmap[c0];
1747 drop0 = (bm0 & m0) != 0;
1748
1749 /* Mark it as seen. */
1750 hash_bitmap[c0] = bm0 | m0;
1751
1752 from += 1;
1753 n_left_from -= 1;
1754 to_next_drop[0] = pi0;
1755 to_next_drop += 1;
1756 n_left_to_next_drop -= 1;
1757
Dave Barachd7cb1b52016-12-09 09:52:16 -05001758 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001759
Dave Barachd7cb1b52016-12-09 09:52:16 -05001760 /* If the interface is link-down, drop the pkt */
1761 if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
1762 drop0 = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001763
Dave Barach75fc8542016-10-11 16:16:02 -04001764 p0->error =
Dave Barachd7cb1b52016-12-09 09:52:16 -05001765 node->errors[drop0 ? IP6_DISCOVER_NEIGHBOR_ERROR_DROP
1766 : IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001767 if (drop0)
1768 continue;
1769
Neale Rannsb80c5362016-10-08 13:03:40 +01001770 /*
1771 * the adj has been updated to a rewrite but the node the DPO that got
1772 * us here hasn't - yet. no big deal. we'll drop while we wait.
1773 */
1774 if (IP_LOOKUP_NEXT_REWRITE == adj0->lookup_next_index)
1775 continue;
1776
Ed Warnickecb9cada2015-12-08 15:45:58 -07001777 {
1778 u32 bi0 = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001779 icmp6_neighbor_solicitation_header_t *h0;
1780 vlib_buffer_t *b0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001781
Dave Barach75fc8542016-10-11 16:16:02 -04001782 h0 = vlib_packet_template_get_packet
Dave Barachd7cb1b52016-12-09 09:52:16 -05001783 (vm, &im->discover_neighbor_packet_template, &bi0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001784
Dave Barach75fc8542016-10-11 16:16:02 -04001785 /*
Dave Barachd7cb1b52016-12-09 09:52:16 -05001786 * Build ethernet header.
1787 * Choose source address based on destination lookup
1788 * adjacency.
1789 */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001790 if (ip6_src_address_for_packet (lm,
1791 sw_if_index0,
1792 &h0->ip.src_address))
1793 {
1794 /* There is no address on the interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001795 p0->error =
1796 node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS];
1797 vlib_buffer_free (vm, &bi0, 1);
Pierre Pfisterd076f192016-06-22 12:58:30 +01001798 continue;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001799 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001800
Dave Barach75fc8542016-10-11 16:16:02 -04001801 /*
Dave Barachd7cb1b52016-12-09 09:52:16 -05001802 * Destination address is a solicited node multicast address.
1803 * We need to fill in
1804 * the low 24 bits with low 24 bits of target's address.
1805 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001806 h0->ip.dst_address.as_u8[13] = ip0->dst_address.as_u8[13];
1807 h0->ip.dst_address.as_u8[14] = ip0->dst_address.as_u8[14];
1808 h0->ip.dst_address.as_u8[15] = ip0->dst_address.as_u8[15];
1809
1810 h0->neighbor.target_address = ip0->dst_address;
1811
Dave Barach75fc8542016-10-11 16:16:02 -04001812 clib_memcpy (h0->link_layer_option.ethernet_address,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001813 hw_if0->hw_address, vec_len (hw_if0->hw_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001814
Dave Barachd7cb1b52016-12-09 09:52:16 -05001815 /* $$$$ appears we need this; why is the checksum non-zero? */
1816 h0->neighbor.icmp.checksum = 0;
Dave Barach75fc8542016-10-11 16:16:02 -04001817 h0->neighbor.icmp.checksum =
Dave Barachd7cb1b52016-12-09 09:52:16 -05001818 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip,
1819 &bogus_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001820
Dave Barachd7cb1b52016-12-09 09:52:16 -05001821 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001822
1823 vlib_buffer_copy_trace_flag (vm, p0, bi0);
1824 b0 = vlib_get_buffer (vm, bi0);
Dave Barach75fc8542016-10-11 16:16:02 -04001825 vnet_buffer (b0)->sw_if_index[VLIB_TX]
Dave Barachd7cb1b52016-12-09 09:52:16 -05001826 = vnet_buffer (p0)->sw_if_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001827
1828 /* Add rewrite/encap string. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001829 vnet_rewrite_one_header (adj0[0], h0, sizeof (ethernet_header_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001830 vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
1831
John Lod1f5d042016-04-12 18:20:39 -04001832 next0 = IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001833
1834 vlib_set_next_frame_buffer (vm, node, next0, bi0);
1835 }
1836 }
1837
Dave Barach75fc8542016-10-11 16:16:02 -04001838 vlib_put_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001839 n_left_to_next_drop);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001840 }
1841
1842 return frame->n_vectors;
1843}
1844
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001845static uword
1846ip6_discover_neighbor (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001847 vlib_node_runtime_t * node, vlib_frame_t * frame)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001848{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001849 return (ip6_discover_neighbor_inline (vm, node, frame, 0));
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001850}
1851
1852static uword
Dave Barachd7cb1b52016-12-09 09:52:16 -05001853ip6_glean (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001854{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001855 return (ip6_discover_neighbor_inline (vm, node, frame, 1));
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001856}
1857
Dave Barachd7cb1b52016-12-09 09:52:16 -05001858static char *ip6_discover_neighbor_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -07001859 [IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops",
Dave Barachd7cb1b52016-12-09 09:52:16 -05001860 [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT] = "neighbor solicitations sent",
Pierre Pfisterd076f192016-06-22 12:58:30 +01001861 [IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS]
1862 = "no source address for ND solicitation",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001863};
1864
Dave Barachd7cb1b52016-12-09 09:52:16 -05001865/* *INDENT-OFF* */
1866VLIB_REGISTER_NODE (ip6_discover_neighbor_node) =
1867{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001868 .function = ip6_discover_neighbor,
1869 .name = "ip6-discover-neighbor",
1870 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -07001871 .format_trace = format_ip6_forward_next_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001872 .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
1873 .error_strings = ip6_discover_neighbor_error_strings,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001874 .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001875 .next_nodes =
1876 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07001877 [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
John Lod1f5d042016-04-12 18:20:39 -04001878 [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001879 },
1880};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001881/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001882
Dave Barachd7cb1b52016-12-09 09:52:16 -05001883/* *INDENT-OFF* */
1884VLIB_REGISTER_NODE (ip6_glean_node) =
1885{
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001886 .function = ip6_glean,
1887 .name = "ip6-glean",
1888 .vector_size = sizeof (u32),
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001889 .format_trace = format_ip6_forward_next_trace,
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001890 .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
1891 .error_strings = ip6_discover_neighbor_error_strings,
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001892 .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001893 .next_nodes =
1894 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001895 [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
1896 [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
1897 },
1898};
Dave Barachd7cb1b52016-12-09 09:52:16 -05001899/* *INDENT-ON* */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001900
Ed Warnickecb9cada2015-12-08 15:45:58 -07001901clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001902ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
1903{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001904 vnet_main_t *vnm = vnet_get_main ();
1905 ip6_main_t *im = &ip6_main;
1906 icmp6_neighbor_solicitation_header_t *h;
1907 ip6_address_t *src;
1908 ip_interface_address_t *ia;
1909 ip_adjacency_t *adj;
1910 vnet_hw_interface_t *hi;
1911 vnet_sw_interface_t *si;
1912 vlib_buffer_t *b;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001913 u32 bi = 0;
1914 int bogus_length;
1915
1916 si = vnet_get_sw_interface (vnm, sw_if_index);
1917
1918 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
1919 {
1920 return clib_error_return (0, "%U: interface %U down",
Dave Barachd7cb1b52016-12-09 09:52:16 -05001921 format_ip6_address, dst,
1922 format_vnet_sw_if_index_name, vnm,
1923 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001924 }
1925
Dave Barachd7cb1b52016-12-09 09:52:16 -05001926 src =
1927 ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia);
1928 if (!src)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001929 {
1930 vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE;
Dave Barach75fc8542016-10-11 16:16:02 -04001931 return clib_error_return
Dave Barachd7cb1b52016-12-09 09:52:16 -05001932 (0, "no matching interface address for destination %U (interface %U)",
1933 format_ip6_address, dst,
1934 format_vnet_sw_if_index_name, vnm, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001935 }
1936
Dave Barachd7cb1b52016-12-09 09:52:16 -05001937 h =
1938 vlib_packet_template_get_packet (vm,
1939 &im->discover_neighbor_packet_template,
1940 &bi);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001941
1942 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
1943
1944 /* Destination address is a solicited node multicast address. We need to fill in
1945 the low 24 bits with low 24 bits of target's address. */
1946 h->ip.dst_address.as_u8[13] = dst->as_u8[13];
1947 h->ip.dst_address.as_u8[14] = dst->as_u8[14];
1948 h->ip.dst_address.as_u8[15] = dst->as_u8[15];
1949
1950 h->ip.src_address = src[0];
1951 h->neighbor.target_address = dst[0];
1952
Dave Barachd7cb1b52016-12-09 09:52:16 -05001953 clib_memcpy (h->link_layer_option.ethernet_address, hi->hw_address,
1954 vec_len (hi->hw_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001955
Dave Barach75fc8542016-10-11 16:16:02 -04001956 h->neighbor.icmp.checksum =
Ed Warnickecb9cada2015-12-08 15:45:58 -07001957 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001958 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001959
1960 b = vlib_get_buffer (vm, bi);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001961 vnet_buffer (b)->sw_if_index[VLIB_RX] =
1962 vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001963
1964 /* Add encapsulation string for software interface (e.g. ethernet header). */
1965 adj = ip_get_adjacency (&im->lookup_main, ia->neighbor_probe_adj_index);
1966 vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
1967 vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
1968
1969 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001970 vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
1971 u32 *to_next = vlib_frame_vector_args (f);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001972 to_next[0] = bi;
1973 f->n_vectors = 1;
1974 vlib_put_frame_to_node (vm, hi->output_node_index, f);
1975 }
1976
1977 return /* no error */ 0;
1978}
1979
Dave Barachd7cb1b52016-12-09 09:52:16 -05001980typedef enum
1981{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001982 IP6_REWRITE_NEXT_DROP,
Chris Luke816f3e12016-06-14 16:24:47 -04001983 IP6_REWRITE_NEXT_ICMP_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001984} ip6_rewrite_next_t;
1985
1986always_inline uword
1987ip6_rewrite_inline (vlib_main_t * vm,
1988 vlib_node_runtime_t * node,
Neale Ranns32e1c012016-11-22 17:07:28 +00001989 vlib_frame_t * frame, int is_midchain, int is_mcast)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001990{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001991 ip_lookup_main_t *lm = &ip6_main.lookup_main;
1992 u32 *from = vlib_frame_vector_args (frame);
1993 u32 n_left_from, n_left_to_next, *to_next, next_index;
1994 vlib_node_runtime_t *error_node =
1995 vlib_node_get_runtime (vm, ip6_input_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001996
1997 n_left_from = frame->n_vectors;
1998 next_index = node->cached_next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001999 u32 cpu_index = os_get_cpu_number ();
Dave Barach75fc8542016-10-11 16:16:02 -04002000
Ed Warnickecb9cada2015-12-08 15:45:58 -07002001 while (n_left_from > 0)
2002 {
2003 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2004
2005 while (n_left_from >= 4 && n_left_to_next >= 2)
2006 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002007 ip_adjacency_t *adj0, *adj1;
2008 vlib_buffer_t *p0, *p1;
2009 ip6_header_t *ip0, *ip1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002010 u32 pi0, rw_len0, next0, error0, adj_index0;
2011 u32 pi1, rw_len1, next1, error1, adj_index1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002012 u32 tx_sw_if_index0, tx_sw_if_index1;
Dave Barach75fc8542016-10-11 16:16:02 -04002013
Ed Warnickecb9cada2015-12-08 15:45:58 -07002014 /* Prefetch next iteration. */
2015 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002016 vlib_buffer_t *p2, *p3;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002017
2018 p2 = vlib_get_buffer (vm, from[2]);
2019 p3 = vlib_get_buffer (vm, from[3]);
2020
2021 vlib_prefetch_buffer_header (p2, LOAD);
2022 vlib_prefetch_buffer_header (p3, LOAD);
2023
2024 CLIB_PREFETCH (p2->pre_data, 32, STORE);
2025 CLIB_PREFETCH (p3->pre_data, 32, STORE);
2026
2027 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
2028 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
2029 }
2030
2031 pi0 = to_next[0] = from[0];
2032 pi1 = to_next[1] = from[1];
2033
2034 from += 2;
2035 n_left_from -= 2;
2036 to_next += 2;
2037 n_left_to_next -= 2;
Dave Barach75fc8542016-10-11 16:16:02 -04002038
Ed Warnickecb9cada2015-12-08 15:45:58 -07002039 p0 = vlib_get_buffer (vm, pi0);
2040 p1 = vlib_get_buffer (vm, pi1);
2041
Neale Rannsf06aea52016-11-29 06:51:37 -08002042 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
2043 adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07002044
Dave Barachd7cb1b52016-12-09 09:52:16 -05002045 /* We should never rewrite a pkt using the MISS adjacency */
2046 ASSERT (adj_index0 && adj_index1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002047
2048 ip0 = vlib_buffer_get_current (p0);
2049 ip1 = vlib_buffer_get_current (p1);
2050
2051 error0 = error1 = IP6_ERROR_NONE;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002052 next0 = next1 = IP6_REWRITE_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002053
Dave Barachd7cb1b52016-12-09 09:52:16 -05002054 if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002055 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002056 i32 hop_limit0 = ip0->hop_limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002057
2058 /* Input node should have reject packets with hop limit 0. */
2059 ASSERT (ip0->hop_limit > 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002060
2061 hop_limit0 -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002062
2063 ip0->hop_limit = hop_limit0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002064
Dave Barachd7cb1b52016-12-09 09:52:16 -05002065 /*
2066 * If the hop count drops below 1 when forwarding, generate
2067 * an ICMP response.
2068 */
2069 if (PREDICT_FALSE (hop_limit0 <= 0))
2070 {
2071 error0 = IP6_ERROR_TIME_EXPIRED;
2072 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
2073 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
2074 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
2075 ICMP6_time_exceeded_ttl_exceeded_in_transit,
2076 0);
2077 }
Neale Rannsf06aea52016-11-29 06:51:37 -08002078 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002079 else
2080 {
2081 p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
2082 }
2083 if (PREDICT_TRUE (!(p1->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
2084 {
Neale Rannsf06aea52016-11-29 06:51:37 -08002085 i32 hop_limit1 = ip1->hop_limit;
2086
2087 /* Input node should have reject packets with hop limit 0. */
2088 ASSERT (ip1->hop_limit > 0);
2089
2090 hop_limit1 -= 1;
2091
2092 ip1->hop_limit = hop_limit1;
2093
Dave Barachd7cb1b52016-12-09 09:52:16 -05002094 /*
2095 * If the hop count drops below 1 when forwarding, generate
2096 * an ICMP response.
2097 */
2098 if (PREDICT_FALSE (hop_limit1 <= 0))
2099 {
2100 error1 = IP6_ERROR_TIME_EXPIRED;
2101 next1 = IP6_REWRITE_NEXT_ICMP_ERROR;
2102 vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
2103 icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded,
2104 ICMP6_time_exceeded_ttl_exceeded_in_transit,
2105 0);
2106 }
2107 }
2108 else
2109 {
2110 p1->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
2111 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002112 adj0 = ip_get_adjacency (lm, adj_index0);
2113 adj1 = ip_get_adjacency (lm, adj_index1);
2114
Ed Warnickecb9cada2015-12-08 15:45:58 -07002115 rw_len0 = adj0[0].rewrite_header.data_bytes;
2116 rw_len1 = adj1[0].rewrite_header.data_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002117 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
2118 vnet_buffer (p1)->ip.save_rewrite_length = rw_len1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002119
Neale Ranns044183f2017-01-24 01:34:25 -08002120 vlib_increment_combined_counter
2121 (&adjacency_counters,
2122 cpu_index,
2123 adj_index0, 1, vlib_buffer_length_in_chain (vm, p0) + rw_len0);
2124 vlib_increment_combined_counter
2125 (&adjacency_counters,
2126 cpu_index, adj_index1,
2127 1, vlib_buffer_length_in_chain (vm, p1) + rw_len1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002128
2129 /* Check MTU of outgoing interface. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002130 error0 =
2131 (vlib_buffer_length_in_chain (vm, p0) >
2132 adj0[0].
2133 rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
2134 error0);
2135 error1 =
2136 (vlib_buffer_length_in_chain (vm, p1) >
2137 adj1[0].
2138 rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
2139 error1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002140
Dave Barachd7cb1b52016-12-09 09:52:16 -05002141 /* Don't adjust the buffer for hop count issue; icmp-error node
2142 * wants to see the IP headerr */
2143 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
2144 {
2145 p0->current_data -= rw_len0;
2146 p0->current_length += rw_len0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002147
Dave Barachd7cb1b52016-12-09 09:52:16 -05002148 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
2149 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
2150 next0 = adj0[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04002151
Dave Barachd7cb1b52016-12-09 09:52:16 -05002152 vnet_feature_arc_start (lm->output_feature_arc_index,
2153 tx_sw_if_index0, &next0, p0);
2154 }
2155 if (PREDICT_TRUE (error1 == IP6_ERROR_NONE))
2156 {
2157 p1->current_data -= rw_len1;
2158 p1->current_length += rw_len1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002159
Dave Barachd7cb1b52016-12-09 09:52:16 -05002160 tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
2161 vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1;
2162 next1 = adj1[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04002163
Dave Barachd7cb1b52016-12-09 09:52:16 -05002164 vnet_feature_arc_start (lm->output_feature_arc_index,
2165 tx_sw_if_index1, &next1, p1);
2166 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002167
2168 /* Guess we are only writing on simple Ethernet header. */
2169 vnet_rewrite_two_headers (adj0[0], adj1[0],
Dave Barachd7cb1b52016-12-09 09:52:16 -05002170 ip0, ip1, sizeof (ethernet_header_t));
Dave Barach75fc8542016-10-11 16:16:02 -04002171
Neale Ranns5e575b12016-10-03 09:40:25 +01002172 if (is_midchain)
Dave Barachd7cb1b52016-12-09 09:52:16 -05002173 {
2174 adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
2175 adj1->sub_type.midchain.fixup_func (vm, adj1, p1);
2176 }
Neale Ranns32e1c012016-11-22 17:07:28 +00002177 if (is_mcast)
2178 {
2179 /*
2180 * copy bytes from the IP address into the MAC rewrite
2181 */
2182 vnet_fixup_one_header (adj0[0], &ip0->dst_address, ip0, 0);
2183 vnet_fixup_one_header (adj1[0], &ip1->dst_address, ip1, 0);
2184 }
Neale Ranns5e575b12016-10-03 09:40:25 +01002185
Ed Warnickecb9cada2015-12-08 15:45:58 -07002186 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
2187 to_next, n_left_to_next,
2188 pi0, pi1, next0, next1);
2189 }
2190
2191 while (n_left_from > 0 && n_left_to_next > 0)
2192 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002193 ip_adjacency_t *adj0;
2194 vlib_buffer_t *p0;
2195 ip6_header_t *ip0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002196 u32 pi0, rw_len0;
2197 u32 adj_index0, next0, error0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002198 u32 tx_sw_if_index0;
Dave Barach75fc8542016-10-11 16:16:02 -04002199
Ed Warnickecb9cada2015-12-08 15:45:58 -07002200 pi0 = to_next[0] = from[0];
2201
2202 p0 = vlib_get_buffer (vm, pi0);
2203
Neale Rannsf06aea52016-11-29 06:51:37 -08002204 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -07002205
Dave Barachd7cb1b52016-12-09 09:52:16 -05002206 /* We should never rewrite a pkt using the MISS adjacency */
2207 ASSERT (adj_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002208
2209 adj0 = ip_get_adjacency (lm, adj_index0);
Dave Barach75fc8542016-10-11 16:16:02 -04002210
Ed Warnickecb9cada2015-12-08 15:45:58 -07002211 ip0 = vlib_buffer_get_current (p0);
2212
2213 error0 = IP6_ERROR_NONE;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002214 next0 = IP6_REWRITE_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002215
2216 /* Check hop limit */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002217 if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002218 {
2219 i32 hop_limit0 = ip0->hop_limit;
2220
2221 ASSERT (ip0->hop_limit > 0);
2222
2223 hop_limit0 -= 1;
2224
2225 ip0->hop_limit = hop_limit0;
2226
Dave Barachd7cb1b52016-12-09 09:52:16 -05002227 if (PREDICT_FALSE (hop_limit0 <= 0))
2228 {
2229 /*
2230 * If the hop count drops below 1 when forwarding, generate
2231 * an ICMP response.
2232 */
2233 error0 = IP6_ERROR_TIME_EXPIRED;
2234 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
2235 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
2236 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
2237 ICMP6_time_exceeded_ttl_exceeded_in_transit,
2238 0);
2239 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002240 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002241 else
2242 {
2243 p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED;
2244 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002245
Ed Warnickecb9cada2015-12-08 15:45:58 -07002246 /* Guess we are only writing on simple Ethernet header. */
2247 vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
Dave Barach75fc8542016-10-11 16:16:02 -04002248
Ed Warnickecb9cada2015-12-08 15:45:58 -07002249 /* Update packet buffer attributes/set output interface. */
2250 rw_len0 = adj0[0].rewrite_header.data_bytes;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002251 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002252
Neale Ranns044183f2017-01-24 01:34:25 -08002253 vlib_increment_combined_counter
2254 (&adjacency_counters,
2255 cpu_index,
2256 adj_index0, 1, vlib_buffer_length_in_chain (vm, p0) + rw_len0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002257
2258 /* Check MTU of outgoing interface. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002259 error0 =
2260 (vlib_buffer_length_in_chain (vm, p0) >
2261 adj0[0].
2262 rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED :
2263 error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002264
Dave Barachd7cb1b52016-12-09 09:52:16 -05002265 /* Don't adjust the buffer for hop count issue; icmp-error node
2266 * wants to see the IP headerr */
2267 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
2268 {
Chris Luke816f3e12016-06-14 16:24:47 -04002269 p0->current_data -= rw_len0;
2270 p0->current_length += rw_len0;
2271
Dave Barachd7cb1b52016-12-09 09:52:16 -05002272 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
Dave Barach5331c722016-08-17 11:54:30 -04002273
Dave Barachd7cb1b52016-12-09 09:52:16 -05002274 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
2275 next0 = adj0[0].rewrite_header.next_index;
Dave Barach5331c722016-08-17 11:54:30 -04002276
Dave Barachd7cb1b52016-12-09 09:52:16 -05002277 vnet_feature_arc_start (lm->output_feature_arc_index,
2278 tx_sw_if_index0, &next0, p0);
2279 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002280
Neale Ranns5e575b12016-10-03 09:40:25 +01002281 if (is_midchain)
Dave Barachd7cb1b52016-12-09 09:52:16 -05002282 {
2283 adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
2284 }
Neale Ranns32e1c012016-11-22 17:07:28 +00002285 if (is_mcast)
2286 {
2287 vnet_fixup_one_header (adj0[0], &ip0->dst_address, ip0, 0);
2288 }
Neale Ranns5e575b12016-10-03 09:40:25 +01002289
Ed Warnickecb9cada2015-12-08 15:45:58 -07002290 p0->error = error_node->errors[error0];
2291
2292 from += 1;
2293 n_left_from -= 1;
2294 to_next += 1;
2295 n_left_to_next -= 1;
Dave Barach75fc8542016-10-11 16:16:02 -04002296
Ed Warnickecb9cada2015-12-08 15:45:58 -07002297 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
2298 to_next, n_left_to_next,
2299 pi0, next0);
2300 }
2301
2302 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2303 }
2304
2305 /* Need to do trace after rewrites to pick up new packet data. */
2306 if (node->flags & VLIB_NODE_FLAG_TRACE)
Neale Rannsf06aea52016-11-29 06:51:37 -08002307 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002308
2309 return frame->n_vectors;
2310}
2311
2312static uword
Neale Rannsf06aea52016-11-29 06:51:37 -08002313ip6_rewrite (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002314 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002315{
Neale Ranns32e1c012016-11-22 17:07:28 +00002316 return ip6_rewrite_inline (vm, node, frame, 0, 0);
2317}
2318
2319static uword
2320ip6_rewrite_mcast (vlib_main_t * vm,
2321 vlib_node_runtime_t * node, vlib_frame_t * frame)
2322{
2323 return ip6_rewrite_inline (vm, node, frame, 0, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002324}
2325
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002326static uword
2327ip6_midchain (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002328 vlib_node_runtime_t * node, vlib_frame_t * frame)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002329{
Neale Ranns32e1c012016-11-22 17:07:28 +00002330 return ip6_rewrite_inline (vm, node, frame, 1, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002331}
2332
Dave Barachd7cb1b52016-12-09 09:52:16 -05002333/* *INDENT-OFF* */
2334VLIB_REGISTER_NODE (ip6_midchain_node) =
2335{
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002336 .function = ip6_midchain,
2337 .name = "ip6-midchain",
2338 .vector_size = sizeof (u32),
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002339 .format_trace = format_ip6_forward_next_trace,
Neale Ranns5e575b12016-10-03 09:40:25 +01002340 .sibling_of = "ip6-rewrite",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002341 };
2342/* *INDENT-ON* */
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002343
Dave Barachd7cb1b52016-12-09 09:52:16 -05002344VLIB_NODE_FUNCTION_MULTIARCH (ip6_midchain_node, ip6_midchain);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002345
Dave Barachd7cb1b52016-12-09 09:52:16 -05002346/* *INDENT-OFF* */
2347VLIB_REGISTER_NODE (ip6_rewrite_node) =
2348{
Neale Rannsf06aea52016-11-29 06:51:37 -08002349 .function = ip6_rewrite,
Ed Warnickecb9cada2015-12-08 15:45:58 -07002350 .name = "ip6-rewrite",
2351 .vector_size = sizeof (u32),
Pierre Pfistera38c3df2016-06-13 10:28:09 +01002352 .format_trace = format_ip6_rewrite_trace,
Chris Luke816f3e12016-06-14 16:24:47 -04002353 .n_next_nodes = 2,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002354 .next_nodes =
2355 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07002356 [IP6_REWRITE_NEXT_DROP] = "error-drop",
Chris Luke816f3e12016-06-14 16:24:47 -04002357 [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error",
Ed Warnickecb9cada2015-12-08 15:45:58 -07002358 },
2359};
Dave Barachd7cb1b52016-12-09 09:52:16 -05002360/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002361
Neale Rannsf06aea52016-11-29 06:51:37 -08002362VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_node, ip6_rewrite);
Damjan Marion1c80e832016-05-11 23:07:18 +02002363
Neale Ranns32e1c012016-11-22 17:07:28 +00002364/* *INDENT-OFF* */
2365VLIB_REGISTER_NODE (ip6_rewrite_mcast_node) =
2366{
2367 .function = ip6_rewrite_mcast,
2368 .name = "ip6-rewrite-mcast",
2369 .vector_size = sizeof (u32),
2370 .format_trace = format_ip6_rewrite_trace,
2371 .sibling_of = "ip6-rewrite",
2372};
2373/* *INDENT-ON* */
2374
2375VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_mcast_node, ip6_rewrite_mcast);
2376
Ole Troan944f5482016-05-24 11:56:58 +02002377/*
2378 * Hop-by-Hop handling
2379 */
Ole Troan944f5482016-05-24 11:56:58 +02002380ip6_hop_by_hop_main_t ip6_hop_by_hop_main;
2381
2382#define foreach_ip6_hop_by_hop_error \
2383_(PROCESSED, "pkts with ip6 hop-by-hop options") \
2384_(FORMAT, "incorrectly formatted hop-by-hop options") \
2385_(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options")
2386
Neale Ranns32e1c012016-11-22 17:07:28 +00002387/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002388typedef enum
2389{
Ole Troan944f5482016-05-24 11:56:58 +02002390#define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym,
2391 foreach_ip6_hop_by_hop_error
2392#undef _
Neale Ranns32e1c012016-11-22 17:07:28 +00002393 IP6_HOP_BY_HOP_N_ERROR,
Ole Troan944f5482016-05-24 11:56:58 +02002394} ip6_hop_by_hop_error_t;
Neale Ranns32e1c012016-11-22 17:07:28 +00002395/* *INDENT-ON* */
Ole Troan944f5482016-05-24 11:56:58 +02002396
2397/*
2398 * Primary h-b-h handler trace support
2399 * We work pretty hard on the problem for obvious reasons
2400 */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002401typedef struct
2402{
Ole Troan944f5482016-05-24 11:56:58 +02002403 u32 next_index;
2404 u32 trace_len;
2405 u8 option_data[256];
2406} ip6_hop_by_hop_trace_t;
2407
2408vlib_node_registration_t ip6_hop_by_hop_node;
2409
Dave Barachd7cb1b52016-12-09 09:52:16 -05002410static char *ip6_hop_by_hop_error_strings[] = {
Ole Troan944f5482016-05-24 11:56:58 +02002411#define _(sym,string) string,
2412 foreach_ip6_hop_by_hop_error
2413#undef _
2414};
2415
2416static u8 *
2417format_ip6_hop_by_hop_trace (u8 * s, va_list * args)
2418{
2419 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2420 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002421 ip6_hop_by_hop_trace_t *t = va_arg (*args, ip6_hop_by_hop_trace_t *);
Ole Troan944f5482016-05-24 11:56:58 +02002422 ip6_hop_by_hop_header_t *hbh0;
2423 ip6_hop_by_hop_option_t *opt0, *limit0;
2424 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2425
2426 u8 type0;
2427
Dave Barachd7cb1b52016-12-09 09:52:16 -05002428 hbh0 = (ip6_hop_by_hop_header_t *) t->option_data;
Ole Troan944f5482016-05-24 11:56:58 +02002429
2430 s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d",
Dave Barachd7cb1b52016-12-09 09:52:16 -05002431 t->next_index, (hbh0->length + 1) << 3, t->trace_len);
Ole Troan944f5482016-05-24 11:56:58 +02002432
Dave Barachd7cb1b52016-12-09 09:52:16 -05002433 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2434 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0) + t->trace_len;
Ole Troan944f5482016-05-24 11:56:58 +02002435
Dave Barachd7cb1b52016-12-09 09:52:16 -05002436 while (opt0 < limit0)
2437 {
2438 type0 = opt0->type;
2439 switch (type0)
2440 {
2441 case 0: /* Pad, just stop */
2442 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
2443 break;
Ole Troan944f5482016-05-24 11:56:58 +02002444
Dave Barachd7cb1b52016-12-09 09:52:16 -05002445 default:
2446 if (hm->trace[type0])
2447 {
2448 s = (*hm->trace[type0]) (s, opt0);
2449 }
2450 else
2451 {
2452 s =
2453 format (s, "\n unrecognized option %d length %d", type0,
2454 opt0->length);
2455 }
2456 opt0 =
2457 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2458 sizeof (ip6_hop_by_hop_option_t));
2459 break;
2460 }
Ole Troan944f5482016-05-24 11:56:58 +02002461 }
Ole Troan944f5482016-05-24 11:56:58 +02002462 return s;
2463}
2464
Dave Barachd7cb1b52016-12-09 09:52:16 -05002465always_inline u8
2466ip6_scan_hbh_options (vlib_buffer_t * b0,
2467 ip6_header_t * ip0,
2468 ip6_hop_by_hop_header_t * hbh0,
2469 ip6_hop_by_hop_option_t * opt0,
2470 ip6_hop_by_hop_option_t * limit0, u32 * next0)
Shwethaa91cbe62016-08-08 15:51:04 +01002471{
2472 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2473 u8 type0;
2474 u8 error0 = 0;
2475
2476 while (opt0 < limit0)
2477 {
2478 type0 = opt0->type;
2479 switch (type0)
2480 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002481 case 0: /* Pad1 */
2482 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
Shwethaa91cbe62016-08-08 15:51:04 +01002483 continue;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002484 case 1: /* PadN */
Shwethaa91cbe62016-08-08 15:51:04 +01002485 break;
2486 default:
2487 if (hm->options[type0])
2488 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002489 if ((*hm->options[type0]) (b0, ip0, opt0) < 0)
2490 {
Shwethaa91cbe62016-08-08 15:51:04 +01002491 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002492 return (error0);
2493 }
Shwethaa91cbe62016-08-08 15:51:04 +01002494 }
2495 else
2496 {
2497 /* Unrecognized mandatory option, check the two high order bits */
2498 switch (opt0->type & HBH_OPTION_TYPE_HIGH_ORDER_BITS)
2499 {
2500 case HBH_OPTION_TYPE_SKIP_UNKNOWN:
2501 break;
2502 case HBH_OPTION_TYPE_DISCARD_UNKNOWN:
2503 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2504 *next0 = IP_LOOKUP_NEXT_DROP;
2505 break;
2506 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP:
2507 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2508 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002509 icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem,
2510 ICMP6_parameter_problem_unrecognized_option,
2511 (u8 *) opt0 - (u8 *) ip0);
Shwethaa91cbe62016-08-08 15:51:04 +01002512 break;
2513 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST:
2514 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002515 if (!ip6_address_is_multicast (&ip0->dst_address))
Shwethaa91cbe62016-08-08 15:51:04 +01002516 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002517 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
2518 icmp6_error_set_vnet_buffer (b0,
2519 ICMP6_parameter_problem,
2520 ICMP6_parameter_problem_unrecognized_option,
2521 (u8 *) opt0 - (u8 *) ip0);
Shwethaa91cbe62016-08-08 15:51:04 +01002522 }
2523 else
2524 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002525 *next0 = IP_LOOKUP_NEXT_DROP;
Shwethaa91cbe62016-08-08 15:51:04 +01002526 }
2527 break;
2528 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002529 return (error0);
Shwethaa91cbe62016-08-08 15:51:04 +01002530 }
2531 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002532 opt0 =
2533 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2534 sizeof (ip6_hop_by_hop_option_t));
Shwethaa91cbe62016-08-08 15:51:04 +01002535 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002536 return (error0);
Shwethaa91cbe62016-08-08 15:51:04 +01002537}
2538
Ole Troan944f5482016-05-24 11:56:58 +02002539/*
2540 * Process the Hop-by-Hop Options header
2541 */
2542static uword
2543ip6_hop_by_hop (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002544 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ole Troan944f5482016-05-24 11:56:58 +02002545{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002546 vlib_node_runtime_t *error_node =
2547 vlib_node_get_runtime (vm, ip6_hop_by_hop_node.index);
Ole Troan944f5482016-05-24 11:56:58 +02002548 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2549 u32 n_left_from, *from, *to_next;
2550 ip_lookup_next_t next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002551 ip6_main_t *im = &ip6_main;
Ole Troan944f5482016-05-24 11:56:58 +02002552 ip_lookup_main_t *lm = &im->lookup_main;
2553
2554 from = vlib_frame_vector_args (frame);
2555 n_left_from = frame->n_vectors;
2556 next_index = node->cached_next_index;
2557
Dave Barachd7cb1b52016-12-09 09:52:16 -05002558 while (n_left_from > 0)
2559 {
2560 u32 n_left_to_next;
Ole Troan944f5482016-05-24 11:56:58 +02002561
Dave Barachd7cb1b52016-12-09 09:52:16 -05002562 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ole Troan944f5482016-05-24 11:56:58 +02002563
Dave Barachd7cb1b52016-12-09 09:52:16 -05002564 while (n_left_from >= 4 && n_left_to_next >= 2)
Shwethaa91cbe62016-08-08 15:51:04 +01002565 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002566 u32 bi0, bi1;
2567 vlib_buffer_t *b0, *b1;
2568 u32 next0, next1;
2569 ip6_header_t *ip0, *ip1;
2570 ip6_hop_by_hop_header_t *hbh0, *hbh1;
2571 ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1;
2572 u8 error0 = 0, error1 = 0;
2573
2574 /* Prefetch next iteration. */
2575 {
2576 vlib_buffer_t *p2, *p3;
2577
2578 p2 = vlib_get_buffer (vm, from[2]);
2579 p3 = vlib_get_buffer (vm, from[3]);
2580
2581 vlib_prefetch_buffer_header (p2, LOAD);
2582 vlib_prefetch_buffer_header (p3, LOAD);
2583
2584 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
2585 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
Shwethaa91cbe62016-08-08 15:51:04 +01002586 }
2587
Dave Barachd7cb1b52016-12-09 09:52:16 -05002588 /* Speculatively enqueue b0, b1 to the current next frame */
2589 to_next[0] = bi0 = from[0];
2590 to_next[1] = bi1 = from[1];
2591 from += 2;
2592 to_next += 2;
2593 n_left_from -= 2;
2594 n_left_to_next -= 2;
2595
2596 b0 = vlib_get_buffer (vm, bi0);
2597 b1 = vlib_get_buffer (vm, bi1);
2598
2599 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2600 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
2601 ip_adjacency_t *adj0 = ip_get_adjacency (lm, adj_index0);
2602 u32 adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
2603 ip_adjacency_t *adj1 = ip_get_adjacency (lm, adj_index1);
2604
2605 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2606 next0 = adj0->lookup_next_index;
2607 next1 = adj1->lookup_next_index;
2608
2609 ip0 = vlib_buffer_get_current (b0);
2610 ip1 = vlib_buffer_get_current (b1);
2611 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2612 hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
2613 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2614 opt1 = (ip6_hop_by_hop_option_t *) (hbh1 + 1);
2615 limit0 =
2616 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2617 ((hbh0->length + 1) << 3));
2618 limit1 =
2619 (ip6_hop_by_hop_option_t *) ((u8 *) hbh1 +
2620 ((hbh1->length + 1) << 3));
2621
2622 /*
2623 * Basic validity checks
2624 */
2625 if ((hbh0->length + 1) << 3 >
2626 clib_net_to_host_u16 (ip0->payload_length))
2627 {
2628 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2629 next0 = IP_LOOKUP_NEXT_DROP;
2630 goto outdual;
2631 }
2632 /* Scan the set of h-b-h options, process ones that we understand */
2633 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2634
2635 if ((hbh1->length + 1) << 3 >
2636 clib_net_to_host_u16 (ip1->payload_length))
2637 {
2638 error1 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2639 next1 = IP_LOOKUP_NEXT_DROP;
2640 goto outdual;
2641 }
2642 /* Scan the set of h-b-h options, process ones that we understand */
2643 error1 = ip6_scan_hbh_options (b1, ip1, hbh1, opt1, limit1, &next1);
2644
2645 outdual:
2646 /* Has the classifier flagged this buffer for special treatment? */
2647 if (PREDICT_FALSE
2648 ((error0 == 0)
2649 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2650 next0 = hm->next_override;
2651
2652 /* Has the classifier flagged this buffer for special treatment? */
2653 if (PREDICT_FALSE
2654 ((error1 == 0)
2655 && (vnet_buffer (b1)->l2_classify.opaque_index & OI_DECAP)))
2656 next1 = hm->next_override;
2657
2658 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
2659 {
2660 if (b0->flags & VLIB_BUFFER_IS_TRACED)
2661 {
2662 ip6_hop_by_hop_trace_t *t =
2663 vlib_add_trace (vm, node, b0, sizeof (*t));
2664 u32 trace_len = (hbh0->length + 1) << 3;
2665 t->next_index = next0;
2666 /* Capture the h-b-h option verbatim */
2667 trace_len =
2668 trace_len <
2669 ARRAY_LEN (t->option_data) ? trace_len :
2670 ARRAY_LEN (t->option_data);
2671 t->trace_len = trace_len;
2672 clib_memcpy (t->option_data, hbh0, trace_len);
2673 }
2674 if (b1->flags & VLIB_BUFFER_IS_TRACED)
2675 {
2676 ip6_hop_by_hop_trace_t *t =
2677 vlib_add_trace (vm, node, b1, sizeof (*t));
2678 u32 trace_len = (hbh1->length + 1) << 3;
2679 t->next_index = next1;
2680 /* Capture the h-b-h option verbatim */
2681 trace_len =
2682 trace_len <
2683 ARRAY_LEN (t->option_data) ? trace_len :
2684 ARRAY_LEN (t->option_data);
2685 t->trace_len = trace_len;
2686 clib_memcpy (t->option_data, hbh1, trace_len);
2687 }
2688
2689 }
2690
2691 b0->error = error_node->errors[error0];
2692 b1->error = error_node->errors[error1];
2693
2694 /* verify speculative enqueue, maybe switch current next frame */
2695 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
2696 n_left_to_next, bi0, bi1, next0,
2697 next1);
Shwethaa91cbe62016-08-08 15:51:04 +01002698 }
2699
Dave Barachd7cb1b52016-12-09 09:52:16 -05002700 while (n_left_from > 0 && n_left_to_next > 0)
2701 {
2702 u32 bi0;
2703 vlib_buffer_t *b0;
2704 u32 next0;
2705 ip6_header_t *ip0;
2706 ip6_hop_by_hop_header_t *hbh0;
2707 ip6_hop_by_hop_option_t *opt0, *limit0;
2708 u8 error0 = 0;
Shwethaa91cbe62016-08-08 15:51:04 +01002709
Dave Barachd7cb1b52016-12-09 09:52:16 -05002710 /* Speculatively enqueue b0 to the current next frame */
2711 bi0 = from[0];
2712 to_next[0] = bi0;
2713 from += 1;
2714 to_next += 1;
2715 n_left_from -= 1;
2716 n_left_to_next -= 1;
2717
2718 b0 = vlib_get_buffer (vm, bi0);
2719 /*
2720 * Default use the next_index from the adjacency.
2721 * A HBH option rarely redirects to a different node
2722 */
2723 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
2724 ip_adjacency_t *adj0 = ip_get_adjacency (lm, adj_index0);
2725 next0 = adj0->lookup_next_index;
2726
2727 ip0 = vlib_buffer_get_current (b0);
2728 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2729 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2730 limit0 =
2731 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2732 ((hbh0->length + 1) << 3));
2733
2734 /*
2735 * Basic validity checks
2736 */
2737 if ((hbh0->length + 1) << 3 >
2738 clib_net_to_host_u16 (ip0->payload_length))
2739 {
2740 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2741 next0 = IP_LOOKUP_NEXT_DROP;
2742 goto out0;
2743 }
2744
2745 /* Scan the set of h-b-h options, process ones that we understand */
2746 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2747
2748 out0:
2749 /* Has the classifier flagged this buffer for special treatment? */
2750 if (PREDICT_FALSE
2751 ((error0 == 0)
2752 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2753 next0 = hm->next_override;
2754
2755 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2756 {
2757 ip6_hop_by_hop_trace_t *t =
2758 vlib_add_trace (vm, node, b0, sizeof (*t));
2759 u32 trace_len = (hbh0->length + 1) << 3;
2760 t->next_index = next0;
2761 /* Capture the h-b-h option verbatim */
2762 trace_len =
2763 trace_len <
2764 ARRAY_LEN (t->option_data) ? trace_len :
2765 ARRAY_LEN (t->option_data);
2766 t->trace_len = trace_len;
2767 clib_memcpy (t->option_data, hbh0, trace_len);
2768 }
2769
2770 b0->error = error_node->errors[error0];
2771
2772 /* verify speculative enqueue, maybe switch current next frame */
2773 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2774 n_left_to_next, bi0, next0);
2775 }
2776 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
Shwethaa91cbe62016-08-08 15:51:04 +01002777 }
Ole Troan944f5482016-05-24 11:56:58 +02002778 return frame->n_vectors;
2779}
2780
Dave Barachd7cb1b52016-12-09 09:52:16 -05002781/* *INDENT-OFF* */
2782VLIB_REGISTER_NODE (ip6_hop_by_hop_node) =
2783{
Ole Troan944f5482016-05-24 11:56:58 +02002784 .function = ip6_hop_by_hop,
2785 .name = "ip6-hop-by-hop",
Ole Troan964f93e2016-06-10 13:22:36 +02002786 .sibling_of = "ip6-lookup",
Ole Troan944f5482016-05-24 11:56:58 +02002787 .vector_size = sizeof (u32),
2788 .format_trace = format_ip6_hop_by_hop_trace,
2789 .type = VLIB_NODE_TYPE_INTERNAL,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002790 .n_errors = ARRAY_LEN (ip6_hop_by_hop_error_strings),
Ole Troan944f5482016-05-24 11:56:58 +02002791 .error_strings = ip6_hop_by_hop_error_strings,
Ole Troan964f93e2016-06-10 13:22:36 +02002792 .n_next_nodes = 0,
Ole Troan944f5482016-05-24 11:56:58 +02002793};
Dave Barachd7cb1b52016-12-09 09:52:16 -05002794/* *INDENT-ON* */
Ole Troan944f5482016-05-24 11:56:58 +02002795
Dave Barach5331c722016-08-17 11:54:30 -04002796VLIB_NODE_FUNCTION_MULTIARCH (ip6_hop_by_hop_node, ip6_hop_by_hop);
Ole Troan944f5482016-05-24 11:56:58 +02002797
2798static clib_error_t *
2799ip6_hop_by_hop_init (vlib_main_t * vm)
2800{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002801 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2802 memset (hm->options, 0, sizeof (hm->options));
2803 memset (hm->trace, 0, sizeof (hm->trace));
Shwethaa91cbe62016-08-08 15:51:04 +01002804 hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
Ole Troan944f5482016-05-24 11:56:58 +02002805 return (0);
2806}
2807
2808VLIB_INIT_FUNCTION (ip6_hop_by_hop_init);
2809
Dave Barachd7cb1b52016-12-09 09:52:16 -05002810void
2811ip6_hbh_set_next_override (uword next)
Shwethaa91cbe62016-08-08 15:51:04 +01002812{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002813 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Shwethaa91cbe62016-08-08 15:51:04 +01002814
2815 hm->next_override = next;
2816}
2817
Ole Troan944f5482016-05-24 11:56:58 +02002818int
2819ip6_hbh_register_option (u8 option,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002820 int options (vlib_buffer_t * b, ip6_header_t * ip,
2821 ip6_hop_by_hop_option_t * opt),
2822 u8 * trace (u8 * s, ip6_hop_by_hop_option_t * opt))
Ole Troan944f5482016-05-24 11:56:58 +02002823{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002824 ip6_main_t *im = &ip6_main;
2825 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Ole Troan944f5482016-05-24 11:56:58 +02002826
2827 ASSERT (option < ARRAY_LEN (hm->options));
2828
2829 /* Already registered */
2830 if (hm->options[option])
2831 return (-1);
2832
2833 hm->options[option] = options;
2834 hm->trace[option] = trace;
2835
2836 /* Set global variable */
2837 im->hbh_enabled = 1;
2838
2839 return (0);
2840}
2841
2842int
2843ip6_hbh_unregister_option (u8 option)
2844{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002845 ip6_main_t *im = &ip6_main;
2846 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
Ole Troan944f5482016-05-24 11:56:58 +02002847
2848 ASSERT (option < ARRAY_LEN (hm->options));
2849
2850 /* Not registered */
2851 if (!hm->options[option])
2852 return (-1);
2853
2854 hm->options[option] = NULL;
2855 hm->trace[option] = NULL;
2856
2857 /* Disable global knob if this was the last option configured */
2858 int i;
2859 bool found = false;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002860 for (i = 0; i < 256; i++)
2861 {
2862 if (hm->options[option])
2863 {
2864 found = true;
2865 break;
2866 }
Ole Troan944f5482016-05-24 11:56:58 +02002867 }
Ole Troan944f5482016-05-24 11:56:58 +02002868 if (!found)
2869 im->hbh_enabled = 0;
2870
2871 return (0);
2872}
2873
Ed Warnickecb9cada2015-12-08 15:45:58 -07002874/* Global IP6 main. */
2875ip6_main_t ip6_main;
2876
2877static clib_error_t *
2878ip6_lookup_init (vlib_main_t * vm)
2879{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002880 ip6_main_t *im = &ip6_main;
2881 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002882 uword i;
2883
Damjan Marion8b3191e2016-11-09 19:54:20 +01002884 if ((error = vlib_call_init_function (vm, vnet_feature_init)))
2885 return error;
2886
Ed Warnickecb9cada2015-12-08 15:45:58 -07002887 for (i = 0; i < ARRAY_LEN (im->fib_masks); i++)
2888 {
2889 u32 j, i0, i1;
2890
2891 i0 = i / 32;
2892 i1 = i % 32;
2893
2894 for (j = 0; j < i0; j++)
2895 im->fib_masks[i].as_u32[j] = ~0;
2896
2897 if (i1)
Dave Barachd7cb1b52016-12-09 09:52:16 -05002898 im->fib_masks[i].as_u32[i0] =
2899 clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002900 }
2901
2902 ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1);
2903
2904 if (im->lookup_table_nbuckets == 0)
2905 im->lookup_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS;
2906
Dave Barachd7cb1b52016-12-09 09:52:16 -05002907 im->lookup_table_nbuckets = 1 << max_log2 (im->lookup_table_nbuckets);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002908
2909 if (im->lookup_table_size == 0)
2910 im->lookup_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE;
Dave Barach75fc8542016-10-11 16:16:02 -04002911
Dave Barachd7cb1b52016-12-09 09:52:16 -05002912 BV (clib_bihash_init) (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash),
2913 "ip6 FIB fwding table",
2914 im->lookup_table_nbuckets, im->lookup_table_size);
2915 BV (clib_bihash_init) (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
2916 "ip6 FIB non-fwding table",
2917 im->lookup_table_nbuckets, im->lookup_table_size);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002918
Ed Warnickecb9cada2015-12-08 15:45:58 -07002919 /* Create FIB with index 0 and table id of 0. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002920 fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0);
Neale Ranns32e1c012016-11-22 17:07:28 +00002921 mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002922
2923 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002924 pg_node_t *pn;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002925 pn = pg_get_node (ip6_lookup_node.index);
2926 pn->unformat_edit = unformat_pg_ip6_header;
2927 }
2928
Ole Troan944f5482016-05-24 11:56:58 +02002929 /* Unless explicitly configured, don't process HBH options */
2930 im->hbh_enabled = 0;
2931
Ed Warnickecb9cada2015-12-08 15:45:58 -07002932 {
2933 icmp6_neighbor_solicitation_header_t p;
2934
2935 memset (&p, 0, sizeof (p));
2936
Dave Barachd7cb1b52016-12-09 09:52:16 -05002937 p.ip.ip_version_traffic_class_and_flow_label =
2938 clib_host_to_net_u32 (0x6 << 28);
2939 p.ip.payload_length =
2940 clib_host_to_net_u16 (sizeof (p) -
2941 STRUCT_OFFSET_OF
2942 (icmp6_neighbor_solicitation_header_t, neighbor));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002943 p.ip.protocol = IP_PROTOCOL_ICMP6;
2944 p.ip.hop_limit = 255;
2945 ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0);
2946
2947 p.neighbor.icmp.type = ICMP6_neighbor_solicitation;
2948
Dave Barachd7cb1b52016-12-09 09:52:16 -05002949 p.link_layer_option.header.type =
2950 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
2951 p.link_layer_option.header.n_data_u64s =
2952 sizeof (p.link_layer_option) / sizeof (u64);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002953
2954 vlib_packet_template_init (vm,
2955 &im->discover_neighbor_packet_template,
2956 &p, sizeof (p),
2957 /* alloc chunk size */ 8,
2958 "ip6 neighbor discovery");
2959 }
2960
Dave Barach203c6322016-06-26 10:29:03 -04002961 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002962}
2963
2964VLIB_INIT_FUNCTION (ip6_lookup_init);
2965
2966static clib_error_t *
2967add_del_ip6_interface_table (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002968 unformat_input_t * input,
2969 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002970{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002971 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns4008ac92017-02-13 23:20:04 -08002972 ip_interface_address_t *ia;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002973 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002974 u32 sw_if_index, table_id;
2975
2976 sw_if_index = ~0;
2977
Dave Barachd7cb1b52016-12-09 09:52:16 -05002978 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002979 {
2980 error = clib_error_return (0, "unknown interface `%U'",
2981 format_unformat_error, input);
2982 goto done;
2983 }
2984
2985 if (unformat (input, "%d", &table_id))
2986 ;
2987 else
2988 {
2989 error = clib_error_return (0, "expected table id `%U'",
2990 format_unformat_error, input);
2991 goto done;
2992 }
2993
Neale Ranns4008ac92017-02-13 23:20:04 -08002994 /*
2995 * If the interface already has in IP address, then a change int
2996 * VRF is not allowed. The IP address applied must first be removed.
2997 * We do not do that automatically here, since VPP has no knowledge
2998 * of whether thoses subnets are valid in the destination VRF.
2999 */
3000 /* *INDENT-OFF* */
3001 foreach_ip_interface_address (&ip6_main.lookup_main,
3002 ia, sw_if_index,
3003 1 /* honor unnumbered */,
3004 ({
3005 ip4_address_t * a;
3006
3007 a = ip_interface_address_get_address (&ip6_main.lookup_main, ia);
3008 error = clib_error_return (0, "interface %U has address %U",
3009 format_vnet_sw_if_index_name, vnm,
3010 sw_if_index,
3011 format_ip6_address, a);
3012 goto done;
3013 }));
3014 /* *INDENT-ON* */
3015
Ed Warnickecb9cada2015-12-08 15:45:58 -07003016 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003017 u32 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
3018 table_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003019
Neale Ranns0bfe5d82016-08-25 15:29:12 +01003020 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
3021 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
Neale Ranns32e1c012016-11-22 17:07:28 +00003022
3023 fib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
3024 table_id);
3025
3026 vec_validate (ip6_main.mfib_index_by_sw_if_index, sw_if_index);
3027 ip6_main.mfib_index_by_sw_if_index[sw_if_index] = fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003028 }
3029
Neale Ranns0bfe5d82016-08-25 15:29:12 +01003030
Dave Barachd7cb1b52016-12-09 09:52:16 -05003031done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07003032 return error;
3033}
3034
Billy McFall0683c9c2016-10-13 08:27:31 -04003035/*?
3036 * Place the indicated interface into the supplied IPv6 FIB table (also known
3037 * as a VRF). If the FIB table does not exist, this command creates it. To
3038 * display the current IPv6 FIB table, use the command '<em>show ip6 fib</em>'.
3039 * FIB table will only be displayed if a route has been added to the table, or
3040 * an IP Address is assigned to an interface in the table (which adds a route
3041 * automatically).
3042 *
Neale Ranns4008ac92017-02-13 23:20:04 -08003043 * @note IP addresses added after setting the interface IP table are added to
3044 * the indicated FIB table. If an IP address is added prior to changing the
3045 * table then this is an error. The control plane must remove these addresses
3046 * first and then change the table. VPP will not automatically move the
3047 * addresses from the old to the new table as it does not know the validity
3048 * of such a change.
Billy McFall0683c9c2016-10-13 08:27:31 -04003049 *
3050 * @cliexpar
3051 * Example of how to add an interface to an IPv6 FIB table (where 2 is the table-id):
3052 * @cliexcmd{set interface ip6 table GigabitEthernet2/0/0 2}
3053 ?*/
3054/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003055VLIB_CLI_COMMAND (set_interface_ip6_table_command, static) =
3056{
Ed Warnickecb9cada2015-12-08 15:45:58 -07003057 .path = "set interface ip6 table",
3058 .function = add_del_ip6_interface_table,
Billy McFall0683c9c2016-10-13 08:27:31 -04003059 .short_help = "set interface ip6 table <interface> <table-id>"
Ed Warnickecb9cada2015-12-08 15:45:58 -07003060};
Billy McFall0683c9c2016-10-13 08:27:31 -04003061/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003062
Dave Barach75fc8542016-10-11 16:16:02 -04003063void
Dave Barachd7cb1b52016-12-09 09:52:16 -05003064ip6_link_local_address_from_ethernet_mac_address (ip6_address_t * ip,
3065 u8 * mac)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003066{
3067 ip->as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
3068 /* Invert the "u" bit */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003069 ip->as_u8[8] = mac[0] ^ (1 << 1);
3070 ip->as_u8[9] = mac[1];
3071 ip->as_u8[10] = mac[2];
3072 ip->as_u8[11] = 0xFF;
3073 ip->as_u8[12] = 0xFE;
3074 ip->as_u8[13] = mac[3];
3075 ip->as_u8[14] = mac[4];
3076 ip->as_u8[15] = mac[5];
Ed Warnickecb9cada2015-12-08 15:45:58 -07003077}
3078
Dave Barach75fc8542016-10-11 16:16:02 -04003079void
Dave Barachd7cb1b52016-12-09 09:52:16 -05003080ip6_ethernet_mac_address_from_link_local_address (u8 * mac,
3081 ip6_address_t * ip)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003082{
3083 /* Invert the previously inverted "u" bit */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003084 mac[0] = ip->as_u8[8] ^ (1 << 1);
3085 mac[1] = ip->as_u8[9];
3086 mac[2] = ip->as_u8[10];
3087 mac[3] = ip->as_u8[13];
3088 mac[4] = ip->as_u8[14];
3089 mac[5] = ip->as_u8[15];
Ed Warnickecb9cada2015-12-08 15:45:58 -07003090}
3091
Dave Barach75fc8542016-10-11 16:16:02 -04003092static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07003093test_ip6_link_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003094 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003095{
3096 u8 mac[6];
3097 ip6_address_t _a, *a = &_a;
3098
3099 if (unformat (input, "%U", unformat_ethernet_address, mac))
3100 {
3101 ip6_link_local_address_from_ethernet_mac_address (a, mac);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003102 vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003103 ip6_ethernet_mac_address_from_link_local_address (mac, a);
3104 vlib_cli_output (vm, "Original MAC address: %U",
Dave Barachd7cb1b52016-12-09 09:52:16 -05003105 format_ethernet_address, mac);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003106 }
Dave Barach75fc8542016-10-11 16:16:02 -04003107
Ed Warnickecb9cada2015-12-08 15:45:58 -07003108 return 0;
3109}
3110
Billy McFall0683c9c2016-10-13 08:27:31 -04003111/*?
3112 * This command converts the given MAC Address into an IPv6 link-local
3113 * address.
3114 *
3115 * @cliexpar
3116 * Example of how to create an IPv6 link-local address:
3117 * @cliexstart{test ip6 link 16:d9:e0:91:79:86}
3118 * Link local address: fe80::14d9:e0ff:fe91:7986
3119 * Original MAC address: 16:d9:e0:91:79:86
3120 * @cliexend
3121?*/
3122/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003123VLIB_CLI_COMMAND (test_link_command, static) =
3124{
Ed Warnickecb9cada2015-12-08 15:45:58 -07003125 .path = "test ip6 link",
Dave Barach75fc8542016-10-11 16:16:02 -04003126 .function = test_ip6_link_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003127 .short_help = "test ip6 link <mac-address>",
3128};
Billy McFall0683c9c2016-10-13 08:27:31 -04003129/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003130
Dave Barachd7cb1b52016-12-09 09:52:16 -05003131int
3132vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003133{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003134 ip6_main_t *im6 = &ip6_main;
3135 ip6_fib_t *fib;
3136 uword *p = hash_get (im6->fib_index_by_table_id, table_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003137
3138 if (p == 0)
3139 return -1;
3140
Neale Ranns0bfe5d82016-08-25 15:29:12 +01003141 fib = ip6_fib_get (p[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003142
3143 fib->flow_hash_config = flow_hash_config;
3144 return 1;
3145}
3146
3147static clib_error_t *
3148set_ip6_flow_hash_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003149 unformat_input_t * input,
3150 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003151{
3152 int matched = 0;
3153 u32 table_id = 0;
3154 u32 flow_hash_config = 0;
3155 int rv;
3156
Dave Barachd7cb1b52016-12-09 09:52:16 -05003157 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3158 {
3159 if (unformat (input, "table %d", &table_id))
3160 matched = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003161#define _(a,v) \
3162 else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
Dave Barachd7cb1b52016-12-09 09:52:16 -05003163 foreach_flow_hash_bit
Ed Warnickecb9cada2015-12-08 15:45:58 -07003164#undef _
Dave Barachd7cb1b52016-12-09 09:52:16 -05003165 else
3166 break;
3167 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003168
3169 if (matched == 0)
3170 return clib_error_return (0, "unknown input `%U'",
Dave Barachd7cb1b52016-12-09 09:52:16 -05003171 format_unformat_error, input);
Dave Barach75fc8542016-10-11 16:16:02 -04003172
Ed Warnickecb9cada2015-12-08 15:45:58 -07003173 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
3174 switch (rv)
3175 {
3176 case 1:
3177 break;
3178
3179 case -1:
3180 return clib_error_return (0, "no such FIB table %d", table_id);
Dave Barach75fc8542016-10-11 16:16:02 -04003181
Ed Warnickecb9cada2015-12-08 15:45:58 -07003182 default:
3183 clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config);
3184 break;
3185 }
Dave Barach75fc8542016-10-11 16:16:02 -04003186
Ed Warnickecb9cada2015-12-08 15:45:58 -07003187 return 0;
3188}
3189
Billy McFall0683c9c2016-10-13 08:27:31 -04003190/*?
3191 * Configure the set of IPv6 fields used by the flow hash.
3192 *
3193 * @cliexpar
3194 * @parblock
3195 * Example of how to set the flow hash on a given table:
Billy McFallebb9a6a2016-10-17 11:35:32 -04003196 * @cliexcmd{set ip6 flow-hash table 8 dst sport dport proto}
3197 *
Billy McFall0683c9c2016-10-13 08:27:31 -04003198 * Example of display the configured flow hash:
3199 * @cliexstart{show ip6 fib}
Billy McFallebb9a6a2016-10-17 11:35:32 -04003200 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
3201 * @::/0
3202 * unicast-ip6-chain
3203 * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]]
3204 * [0] [@0]: dpo-drop ip6
3205 * fe80::/10
3206 * unicast-ip6-chain
3207 * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]]
3208 * [0] [@2]: dpo-receive
3209 * ff02::1/128
3210 * unicast-ip6-chain
3211 * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]]
3212 * [0] [@2]: dpo-receive
3213 * ff02::2/128
3214 * unicast-ip6-chain
3215 * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]]
3216 * [0] [@2]: dpo-receive
3217 * ff02::16/128
3218 * unicast-ip6-chain
3219 * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]]
3220 * [0] [@2]: dpo-receive
3221 * ff02::1:ff00:0/104
3222 * unicast-ip6-chain
3223 * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]]
3224 * [0] [@2]: dpo-receive
3225 * ipv6-VRF:8, fib_index 1, flow hash: dst sport dport proto
3226 * @::/0
3227 * unicast-ip6-chain
3228 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
3229 * [0] [@0]: dpo-drop ip6
3230 * @::a:1:1:0:4/126
3231 * unicast-ip6-chain
3232 * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]]
3233 * [0] [@4]: ipv6-glean: af_packet0
3234 * @::a:1:1:0:7/128
3235 * unicast-ip6-chain
3236 * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]]
3237 * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0
3238 * fe80::/10
3239 * unicast-ip6-chain
3240 * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]]
3241 * [0] [@2]: dpo-receive
3242 * fe80::fe:3eff:fe3e:9222/128
3243 * unicast-ip6-chain
3244 * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]]
3245 * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0
3246 * ff02::1/128
3247 * unicast-ip6-chain
3248 * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]]
3249 * [0] [@2]: dpo-receive
3250 * ff02::2/128
3251 * unicast-ip6-chain
3252 * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]]
3253 * [0] [@2]: dpo-receive
3254 * ff02::16/128
3255 * unicast-ip6-chain
3256 * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]]
3257 * [0] [@2]: dpo-receive
3258 * ff02::1:ff00:0/104
3259 * unicast-ip6-chain
3260 * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]]
3261 * [0] [@2]: dpo-receive
Billy McFall0683c9c2016-10-13 08:27:31 -04003262 * @cliexend
3263 * @endparblock
3264?*/
3265/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003266VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) =
3267{
3268 .path = "set ip6 flow-hash",
3269 .short_help =
3270 "set ip6 flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]",
3271 .function = set_ip6_flow_hash_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003272};
Billy McFall0683c9c2016-10-13 08:27:31 -04003273/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003274
3275static clib_error_t *
3276show_ip6_local_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003277 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003278{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003279 ip6_main_t *im = &ip6_main;
3280 ip_lookup_main_t *lm = &im->lookup_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003281 int i;
Dave Barach75fc8542016-10-11 16:16:02 -04003282
Ed Warnickecb9cada2015-12-08 15:45:58 -07003283 vlib_cli_output (vm, "Protocols handled by ip6_local");
Dave Barachd7cb1b52016-12-09 09:52:16 -05003284 for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003285 {
3286 if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003287 vlib_cli_output (vm, "%d", i);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003288 }
3289 return 0;
3290}
3291
3292
3293
Billy McFall0683c9c2016-10-13 08:27:31 -04003294/*?
3295 * Display the set of protocols handled by the local IPv6 stack.
3296 *
3297 * @cliexpar
3298 * Example of how to display local protocol table:
3299 * @cliexstart{show ip6 local}
3300 * Protocols handled by ip6_local
3301 * 17
3302 * 43
3303 * 58
3304 * 115
3305 * @cliexend
3306?*/
3307/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003308VLIB_CLI_COMMAND (show_ip6_local, static) =
3309{
Ed Warnickecb9cada2015-12-08 15:45:58 -07003310 .path = "show ip6 local",
3311 .function = show_ip6_local_command_fn,
Billy McFall0683c9c2016-10-13 08:27:31 -04003312 .short_help = "show ip6 local",
Ed Warnickecb9cada2015-12-08 15:45:58 -07003313};
Billy McFall0683c9c2016-10-13 08:27:31 -04003314/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003315
Dave Barachd7cb1b52016-12-09 09:52:16 -05003316int
3317vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
3318 u32 table_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003319{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003320 vnet_main_t *vnm = vnet_get_main ();
3321 vnet_interface_main_t *im = &vnm->interface_main;
3322 ip6_main_t *ipm = &ip6_main;
3323 ip_lookup_main_t *lm = &ipm->lookup_main;
3324 vnet_classify_main_t *cm = &vnet_classify_main;
Neale Rannsdf089a82016-10-02 16:39:06 +01003325 ip6_address_t *if_addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003326
3327 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
3328 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
3329
3330 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
3331 return VNET_API_ERROR_NO_SUCH_ENTRY;
3332
3333 vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003334 lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003335
Neale Ranns6cfc39c2017-02-14 01:44:25 -08003336 if_addr = ip6_interface_first_address (ipm, sw_if_index);
Neale Rannsdf089a82016-10-02 16:39:06 +01003337
3338 if (NULL != if_addr)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003339 {
Neale Rannsdf089a82016-10-02 16:39:06 +01003340 fib_prefix_t pfx = {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003341 .fp_len = 128,
3342 .fp_proto = FIB_PROTOCOL_IP6,
3343 .fp_addr.ip6 = *if_addr,
Neale Rannsdf089a82016-10-02 16:39:06 +01003344 };
3345 u32 fib_index;
3346
Dave Barachd7cb1b52016-12-09 09:52:16 -05003347 fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
3348 sw_if_index);
Neale Rannsdf089a82016-10-02 16:39:06 +01003349
3350
Dave Barachd7cb1b52016-12-09 09:52:16 -05003351 if (table_index != (u32) ~ 0)
3352 {
3353 dpo_id_t dpo = DPO_INVALID;
Neale Rannsdf089a82016-10-02 16:39:06 +01003354
Dave Barachd7cb1b52016-12-09 09:52:16 -05003355 dpo_set (&dpo,
3356 DPO_CLASSIFY,
3357 DPO_PROTO_IP6,
3358 classify_dpo_create (DPO_PROTO_IP6, table_index));
Neale Rannsdf089a82016-10-02 16:39:06 +01003359
Dave Barachd7cb1b52016-12-09 09:52:16 -05003360 fib_table_entry_special_dpo_add (fib_index,
3361 &pfx,
3362 FIB_SOURCE_CLASSIFY,
3363 FIB_ENTRY_FLAG_NONE, &dpo);
3364 dpo_reset (&dpo);
3365 }
Neale Rannsdf089a82016-10-02 16:39:06 +01003366 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05003367 {
3368 fib_table_entry_special_remove (fib_index,
3369 &pfx, FIB_SOURCE_CLASSIFY);
3370 }
3371 }
Neale Rannsdf089a82016-10-02 16:39:06 +01003372
Ed Warnickecb9cada2015-12-08 15:45:58 -07003373 return 0;
3374}
3375
3376static clib_error_t *
3377set_ip6_classify_command_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003378 unformat_input_t * input,
3379 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003380{
3381 u32 table_index = ~0;
3382 int table_index_set = 0;
3383 u32 sw_if_index = ~0;
3384 int rv;
Dave Barach75fc8542016-10-11 16:16:02 -04003385
Dave Barachd7cb1b52016-12-09 09:52:16 -05003386 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3387 {
3388 if (unformat (input, "table-index %d", &table_index))
3389 table_index_set = 1;
3390 else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
3391 vnet_get_main (), &sw_if_index))
3392 ;
3393 else
3394 break;
3395 }
Dave Barach75fc8542016-10-11 16:16:02 -04003396
Ed Warnickecb9cada2015-12-08 15:45:58 -07003397 if (table_index_set == 0)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003398 return clib_error_return (0, "classify table-index must be specified");
Dave Barach75fc8542016-10-11 16:16:02 -04003399
Ed Warnickecb9cada2015-12-08 15:45:58 -07003400 if (sw_if_index == ~0)
3401 return clib_error_return (0, "interface / subif must be specified");
3402
3403 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3404
3405 switch (rv)
3406 {
3407 case 0:
3408 break;
3409
3410 case VNET_API_ERROR_NO_MATCHING_INTERFACE:
3411 return clib_error_return (0, "No such interface");
3412
3413 case VNET_API_ERROR_NO_SUCH_ENTRY:
3414 return clib_error_return (0, "No such classifier table");
3415 }
3416 return 0;
3417}
3418
Billy McFall0683c9c2016-10-13 08:27:31 -04003419/*?
3420 * Assign a classification table to an interface. The classification
3421 * table is created using the '<em>classify table</em>' and '<em>classify session</em>'
3422 * commands. Once the table is create, use this command to filter packets
3423 * on an interface.
3424 *
3425 * @cliexpar
3426 * Example of how to assign a classification table to an interface:
3427 * @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1}
3428?*/
3429/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003430VLIB_CLI_COMMAND (set_ip6_classify_command, static) =
3431{
3432 .path = "set ip6 classify",
3433 .short_help =
3434 "set ip6 classify intfc <interface> table-index <classify-idx>",
3435 .function = set_ip6_classify_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003436};
Billy McFall0683c9c2016-10-13 08:27:31 -04003437/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003438
3439static clib_error_t *
3440ip6_config (vlib_main_t * vm, unformat_input_t * input)
3441{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003442 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003443 uword heapsize = 0;
3444 u32 tmp;
3445 u32 nbuckets = 0;
3446
Dave Barachd7cb1b52016-12-09 09:52:16 -05003447 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3448 {
3449 if (unformat (input, "hash-buckets %d", &tmp))
3450 nbuckets = tmp;
3451 else if (unformat (input, "heap-size %dm", &tmp))
3452 heapsize = ((u64) tmp) << 20;
3453 else if (unformat (input, "heap-size %dM", &tmp))
3454 heapsize = ((u64) tmp) << 20;
3455 else if (unformat (input, "heap-size %dg", &tmp))
3456 heapsize = ((u64) tmp) << 30;
3457 else if (unformat (input, "heap-size %dG", &tmp))
3458 heapsize = ((u64) tmp) << 30;
3459 else
3460 return clib_error_return (0, "unknown input '%U'",
3461 format_unformat_error, input);
3462 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003463
3464 im->lookup_table_nbuckets = nbuckets;
3465 im->lookup_table_size = heapsize;
3466
3467 return 0;
3468}
3469
3470VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6");
Dave Barachd7cb1b52016-12-09 09:52:16 -05003471
3472/*
3473 * fd.io coding-style-patch-verification: ON
3474 *
3475 * Local Variables:
3476 * eval: (c-set-style "gnu")
3477 * End:
3478 */