2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * ip/ip6_forward.c: IP v6 forwarding
18 * Copyright (c) 2008 Eliot Dresselhaus
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:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
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.
40 #include <vnet/vnet.h>
41 #include <vnet/ip/ip.h>
42 #include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
43 #include <vnet/srp/srp.h> /* for srp_hw_interface_class */
44 #include <vppinfra/cache.h>
45 #include <vnet/fib/fib_table.h>
46 #include <vnet/fib/ip6_fib.h>
47 #include <vnet/dpo/load_balance.h>
48 #include <vnet/dpo/classify_dpo.h>
50 #include <vppinfra/bihash_template.c>
53 ip6_forward_next_trace (vlib_main_t * vm,
54 vlib_node_runtime_t * node,
56 vlib_rx_or_tx_t which_adj_index);
59 ip6_lookup_inline (vlib_main_t * vm,
60 vlib_node_runtime_t * node,
63 ip6_main_t * im = &ip6_main;
64 vlib_combined_counter_main_t * cm = &load_balance_main.lbm_to_counters;
65 u32 n_left_from, n_left_to_next, * from, * to_next;
66 ip_lookup_next_t next;
67 u32 cpu_index = os_get_cpu_number();
69 from = vlib_frame_vector_args (frame);
70 n_left_from = frame->n_vectors;
71 next = node->cached_next_index;
73 while (n_left_from > 0)
75 vlib_get_next_frame (vm, node, next,
76 to_next, n_left_to_next);
78 while (n_left_from >= 4 && n_left_to_next >= 2)
80 vlib_buffer_t * p0, * p1;
81 u32 pi0, pi1, lbi0, lbi1, wrong_next;
82 ip_lookup_next_t next0, next1;
83 ip6_header_t * ip0, * ip1;
84 ip6_address_t * dst_addr0, * dst_addr1;
85 u32 fib_index0, fib_index1;
86 u32 flow_hash_config0, flow_hash_config1;
87 const dpo_id_t *dpo0, *dpo1;
88 const load_balance_t *lb0, *lb1;
90 /* Prefetch next iteration. */
92 vlib_buffer_t * p2, * p3;
94 p2 = vlib_get_buffer (vm, from[2]);
95 p3 = vlib_get_buffer (vm, from[3]);
97 vlib_prefetch_buffer_header (p2, LOAD);
98 vlib_prefetch_buffer_header (p3, LOAD);
99 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), LOAD);
100 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), LOAD);
103 pi0 = to_next[0] = from[0];
104 pi1 = to_next[1] = from[1];
106 p0 = vlib_get_buffer (vm, pi0);
107 p1 = vlib_get_buffer (vm, pi1);
109 ip0 = vlib_buffer_get_current (p0);
110 ip1 = vlib_buffer_get_current (p1);
112 dst_addr0 = &ip0->dst_address;
113 dst_addr1 = &ip1->dst_address;
115 fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
116 fib_index1 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p1)->sw_if_index[VLIB_RX]);
118 fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
119 fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
120 fib_index1 = (vnet_buffer(p1)->sw_if_index[VLIB_TX] == (u32)~0) ?
121 fib_index1 : vnet_buffer(p1)->sw_if_index[VLIB_TX];
123 lbi0 = ip6_fib_table_fwding_lookup (im, fib_index0, dst_addr0);
124 lbi1 = ip6_fib_table_fwding_lookup (im, fib_index1, dst_addr1);
126 lb0 = load_balance_get (lbi0);
127 lb1 = load_balance_get (lbi1);
129 vnet_buffer (p0)->ip.flow_hash =
130 vnet_buffer(p1)->ip.flow_hash = 0;
132 if (PREDICT_FALSE(lb0->lb_n_buckets > 1))
134 flow_hash_config0 = lb0->lb_hash_config;
135 vnet_buffer (p0)->ip.flow_hash =
136 ip6_compute_flow_hash (ip0, flow_hash_config0);
138 if (PREDICT_FALSE(lb1->lb_n_buckets > 1))
140 flow_hash_config1 = lb1->lb_hash_config;
141 vnet_buffer (p1)->ip.flow_hash =
142 ip6_compute_flow_hash (ip1, flow_hash_config1);
145 ASSERT (lb0->lb_n_buckets > 0);
146 ASSERT (lb1->lb_n_buckets > 0);
147 ASSERT (is_pow2 (lb0->lb_n_buckets));
148 ASSERT (is_pow2 (lb1->lb_n_buckets));
149 dpo0 = load_balance_get_bucket_i(lb0,
150 (vnet_buffer (p0)->ip.flow_hash &
151 lb0->lb_n_buckets_minus_1));
152 dpo1 = load_balance_get_bucket_i(lb1,
153 (vnet_buffer (p1)->ip.flow_hash &
154 lb1->lb_n_buckets_minus_1));
156 next0 = dpo0->dpoi_next_node;
157 next1 = dpo1->dpoi_next_node;
159 /* Only process the HBH Option Header if explicitly configured to do so */
160 next0 = ((ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) &&
162 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP :
164 next1 = ((ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) &&
166 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP :
169 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
170 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
172 vlib_increment_combined_counter
173 (cm, cpu_index, lbi0, 1,
174 vlib_buffer_length_in_chain (vm, p0));
175 vlib_increment_combined_counter
176 (cm, cpu_index, lbi1, 1,
177 vlib_buffer_length_in_chain (vm, p1));
184 wrong_next = (next0 != next) + 2*(next1 != next);
185 if (PREDICT_FALSE (wrong_next != 0))
194 vlib_set_next_frame_buffer (vm, node, next0, pi0);
201 vlib_set_next_frame_buffer (vm, node, next1, pi1);
208 vlib_set_next_frame_buffer (vm, node, next0, pi0);
209 vlib_set_next_frame_buffer (vm, node, next1, pi1);
213 vlib_put_next_frame (vm, node, next, n_left_to_next);
215 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
221 while (n_left_from > 0 && n_left_to_next > 0)
226 ip_lookup_next_t next0;
227 load_balance_t * lb0;
228 ip6_address_t * dst_addr0;
229 u32 fib_index0, flow_hash_config0;
230 const dpo_id_t *dpo0;
235 p0 = vlib_get_buffer (vm, pi0);
237 ip0 = vlib_buffer_get_current (p0);
239 dst_addr0 = &ip0->dst_address;
241 fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
242 fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
243 fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
246 ip6_fib_get (fib_index0)->flow_hash_config;
248 lbi0 = ip6_fib_table_fwding_lookup (im, fib_index0, dst_addr0);
250 lb0 = load_balance_get (lbi0);
252 vnet_buffer (p0)->ip.flow_hash = 0;
254 if (PREDICT_FALSE(lb0->lb_n_buckets > 1))
256 flow_hash_config0 = lb0->lb_hash_config;
257 vnet_buffer (p0)->ip.flow_hash =
258 ip6_compute_flow_hash (ip0, flow_hash_config0);
261 ASSERT (lb0->lb_n_buckets > 0);
262 ASSERT (is_pow2 (lb0->lb_n_buckets));
263 dpo0 = load_balance_get_bucket_i(lb0,
264 (vnet_buffer (p0)->ip.flow_hash &
265 lb0->lb_n_buckets_minus_1));
266 next0 = dpo0->dpoi_next_node;
267 /* Only process the HBH Option Header if explicitly configured to do so */
268 next0 = ((ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) &&
270 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP :
273 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
275 vlib_increment_combined_counter
276 (cm, cpu_index, lbi0, 1,
277 vlib_buffer_length_in_chain (vm, p0));
284 if (PREDICT_FALSE (next0 != next))
287 vlib_put_next_frame (vm, node, next, n_left_to_next);
289 vlib_get_next_frame (vm, node, next,
290 to_next, n_left_to_next);
297 vlib_put_next_frame (vm, node, next, n_left_to_next);
300 if (node->flags & VLIB_NODE_FLAG_TRACE)
301 ip6_forward_next_trace(vm, node, frame, VLIB_TX);
303 return frame->n_vectors;
307 ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index,
308 ip6_main_t * im, u32 fib_index,
309 ip_interface_address_t * a)
311 ip_lookup_main_t * lm = &im->lookup_main;
312 ip6_address_t * address = ip_interface_address_get_address (lm, a);
314 .fp_len = a->address_length,
315 .fp_proto = FIB_PROTOCOL_IP6,
316 .fp_addr.ip6 = *address,
319 a->neighbor_probe_adj_index = ~0;
320 if (a->address_length < 128)
322 fib_node_index_t fei;
324 fei = fib_table_entry_update_one_path(fib_index,
326 FIB_SOURCE_INTERFACE,
327 (FIB_ENTRY_FLAG_CONNECTED |
328 FIB_ENTRY_FLAG_ATTACHED),
330 NULL, /* No next-hop address */
332 ~0, // invalid FIB index
335 FIB_ROUTE_PATH_FLAG_NONE);
336 a->neighbor_probe_adj_index = fib_entry_get_adj(fei);
340 if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
342 u32 classify_table_index =
343 lm->classify_table_index_by_sw_if_index [sw_if_index];
344 if (classify_table_index != (u32) ~0)
346 dpo_id_t dpo = DPO_NULL;
351 classify_dpo_create(FIB_PROTOCOL_IP6,
352 classify_table_index));
354 fib_table_entry_special_dpo_add(fib_index,
363 fib_table_entry_update_one_path(fib_index,
365 FIB_SOURCE_INTERFACE,
366 (FIB_ENTRY_FLAG_CONNECTED |
367 FIB_ENTRY_FLAG_LOCAL),
371 ~0, // invalid FIB index
374 FIB_ROUTE_PATH_FLAG_NONE);
378 ip6_del_interface_routes (ip6_main_t * im,
380 ip6_address_t * address,
384 .fp_len = address_length,
385 .fp_proto = FIB_PROTOCOL_IP6,
386 .fp_addr.ip6 = *address,
389 if (pfx.fp_len < 128)
391 fib_table_entry_delete(fib_index,
393 FIB_SOURCE_INTERFACE);
398 fib_table_entry_delete(fib_index,
400 FIB_SOURCE_INTERFACE);
404 ip6_sw_interface_enable_disable (u32 sw_if_index,
407 vlib_main_t * vm = vlib_get_main();
408 ip6_main_t * im = &ip6_main;
409 ip_lookup_main_t * lm = &im->lookup_main;
411 u32 lookup_feature_index;
413 vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0);
416 * enable/disable only on the 1<->0 transition
420 if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index])
425 ASSERT(im->ip_enabled_by_sw_if_index[sw_if_index] > 0);
426 if (0 != --im->ip_enabled_by_sw_if_index[sw_if_index])
430 for (cast = 0; cast <= VNET_IP_RX_MULTICAST_FEAT; cast++)
432 ip_config_main_t * cm = &lm->feature_config_mains[cast];
433 vnet_config_main_t * vcm = &cm->config_main;
435 vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
436 ci = cm->config_index_by_sw_if_index[sw_if_index];
438 if (cast == VNET_IP_RX_UNICAST_FEAT)
439 lookup_feature_index = im->ip6_unicast_rx_feature_lookup;
441 lookup_feature_index = im->ip6_multicast_rx_feature_lookup;
444 ci = vnet_config_add_feature (vm, vcm,
446 lookup_feature_index,
448 /* # bytes of config data */ 0);
450 ci = vnet_config_del_feature (vm, vcm,
452 lookup_feature_index,
454 /* # bytes of config data */ 0);
456 cm->config_index_by_sw_if_index[sw_if_index] = ci;
461 ip6_add_del_interface_address (vlib_main_t * vm,
463 ip6_address_t * address,
467 vnet_main_t * vnm = vnet_get_main();
468 ip6_main_t * im = &ip6_main;
469 ip_lookup_main_t * lm = &im->lookup_main;
470 clib_error_t * error;
471 u32 if_address_index;
472 ip6_address_fib_t ip6_af, * addr_fib = 0;
474 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
475 ip6_addr_fib_init (&ip6_af, address,
476 vec_elt (im->fib_index_by_sw_if_index, sw_if_index));
477 vec_add1 (addr_fib, ip6_af);
480 uword elts_before = pool_elts (lm->if_address_pool);
482 error = ip_interface_address_add_del
492 /* Pool did not grow: add duplicate address. */
493 if (elts_before == pool_elts (lm->if_address_pool))
498 ip6_del_interface_routes (im, ip6_af.fib_index, address,
501 ip6_add_interface_routes (vnm, sw_if_index,
502 im, ip6_af.fib_index,
503 pool_elt_at_index (lm->if_address_pool, if_address_index));
506 ip6_add_del_interface_address_callback_t * cb;
507 vec_foreach (cb, im->add_del_interface_address_callbacks)
508 cb->function (im, cb->function_opaque, sw_if_index,
509 address, address_length,
520 ip6_sw_interface_admin_up_down (vnet_main_t * vnm,
524 ip6_main_t * im = &ip6_main;
525 ip_interface_address_t * ia;
527 u32 is_admin_up, fib_index;
529 /* Fill in lookup tables with default table (0). */
530 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
532 vec_validate_init_empty (im->lookup_main.if_address_pool_index_by_sw_if_index, sw_if_index, ~0);
534 is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
536 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
538 foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
539 0 /* honor unnumbered */,
541 a = ip_interface_address_get_address (&im->lookup_main, ia);
543 ip6_add_interface_routes (vnm, sw_if_index,
547 ip6_del_interface_routes (im, fib_index,
548 a, ia->address_length);
554 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
556 /* Built-in ip6 unicast rx feature path definition */
557 VNET_IP6_UNICAST_FEATURE_INIT (ip6_inacl, static) = {
558 .node_name = "ip6-inacl",
559 .runs_before = ORDER_CONSTRAINTS {"ip6-policer-classify", 0},
560 .feature_index = &ip6_main.ip6_unicast_rx_feature_check_access,
563 VNET_IP6_UNICAST_FEATURE_INIT (ip6_policer_classify, static) = {
564 .node_name = "ip6-policer-classify",
565 .runs_before = ORDER_CONSTRAINTS {"ipsec-input-ip6", 0},
566 .feature_index = &ip6_main.ip6_unicast_rx_feature_policer_classify,
569 VNET_IP6_UNICAST_FEATURE_INIT (ip6_ipsec, static) = {
570 .node_name = "ipsec-input-ip6",
571 .runs_before = ORDER_CONSTRAINTS {"l2tp-decap", 0},
572 .feature_index = &ip6_main.ip6_unicast_rx_feature_ipsec,
575 VNET_IP6_UNICAST_FEATURE_INIT (ip6_l2tp, static) = {
576 .node_name = "l2tp-decap",
577 .runs_before = ORDER_CONSTRAINTS {"vpath-input-ip6", 0},
578 .feature_index = &ip6_main.ip6_unicast_rx_feature_l2tp_decap,
581 VNET_IP6_UNICAST_FEATURE_INIT (ip6_vpath, static) = {
582 .node_name = "vpath-input-ip6",
583 .runs_before = ORDER_CONSTRAINTS {"ip6-lookup", 0},
584 .feature_index = &ip6_main.ip6_unicast_rx_feature_vpath,
587 VNET_IP6_UNICAST_FEATURE_INIT (ip6_lookup, static) = {
588 .node_name = "ip6-lookup",
589 .runs_before = ORDER_CONSTRAINTS {"ip6-drop", 0},
590 .feature_index = &ip6_main.ip6_unicast_rx_feature_lookup,
593 VNET_IP6_UNICAST_FEATURE_INIT (ip6_drop, static) = {
594 .node_name = "ip6-drop",
595 .runs_before = 0, /*last feature*/
596 .feature_index = &ip6_main.ip6_unicast_rx_feature_drop,
599 /* Built-in ip6 multicast rx feature path definition (none now) */
600 VNET_IP6_MULTICAST_FEATURE_INIT (ip6_vpath_mc, static) = {
601 .node_name = "vpath-input-ip6",
602 .runs_before = ORDER_CONSTRAINTS {"ip6-lookup", 0},
603 .feature_index = &ip6_main.ip6_multicast_rx_feature_vpath,
606 VNET_IP6_MULTICAST_FEATURE_INIT (ip6_lookup, static) = {
607 .node_name = "ip6-lookup",
608 .runs_before = ORDER_CONSTRAINTS {"ip6-drop", 0},
609 .feature_index = &ip6_main.ip6_multicast_rx_feature_lookup,
612 VNET_IP6_MULTICAST_FEATURE_INIT (ip6_drop_mc, static) = {
613 .node_name = "ip6-drop",
614 .runs_before = 0, /* last feature */
615 .feature_index = &ip6_main.ip6_multicast_rx_feature_drop,
618 static char * rx_feature_start_nodes[] =
621 static char * tx_feature_start_nodes[] =
624 /* Built-in ip4 tx feature path definition */
625 VNET_IP6_TX_FEATURE_INIT (interface_output, static) = {
626 .node_name = "interface-output",
627 .runs_before = 0, /* not before any other features */
628 .feature_index = &ip6_main.ip6_tx_feature_interface_output,
631 static clib_error_t *
632 ip6_feature_init (vlib_main_t * vm, ip6_main_t * im)
634 ip_lookup_main_t * lm = &im->lookup_main;
635 clib_error_t * error;
637 ip_config_main_t * cm;
638 vnet_config_main_t * vcm;
639 char **feature_start_nodes;
640 int feature_start_len;
642 for (cast = 0; cast < VNET_N_IP_FEAT; cast++)
644 cm = &lm->feature_config_mains[cast];
645 vcm = &cm->config_main;
647 if (cast < VNET_IP_TX_FEAT)
649 feature_start_nodes = rx_feature_start_nodes;
650 feature_start_len = ARRAY_LEN(rx_feature_start_nodes);
654 feature_start_nodes = tx_feature_start_nodes;
655 feature_start_len = ARRAY_LEN(tx_feature_start_nodes);
658 if ((error = ip_feature_init_cast (vm, cm, vcm,
662 VNET_L3_PACKET_TYPE_IP6)))
669 ip6_sw_interface_add_del (vnet_main_t * vnm,
673 vlib_main_t * vm = vnm->vlib_main;
674 ip6_main_t * im = &ip6_main;
675 ip_lookup_main_t * lm = &im->lookup_main;
679 for (cast = 0; cast < VNET_N_IP_FEAT; cast++)
681 ip_config_main_t * cm = &lm->feature_config_mains[cast];
682 vnet_config_main_t * vcm = &cm->config_main;
684 vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
685 ci = cm->config_index_by_sw_if_index[sw_if_index];
687 if (cast == VNET_IP_RX_UNICAST_FEAT)
688 feature_index = im->ip6_unicast_rx_feature_drop;
689 else if (cast == VNET_IP_RX_MULTICAST_FEAT)
690 feature_index = im->ip6_multicast_rx_feature_drop;
692 feature_index = im->ip6_tx_feature_interface_output;
695 ci = vnet_config_add_feature (vm, vcm,
699 /* # bytes of config data */ 0);
702 ci = vnet_config_del_feature (vm, vcm, ci,
705 /* # bytes of config data */ 0);
706 if (vec_len(im->ip_enabled_by_sw_if_index) > sw_if_index)
707 im->ip_enabled_by_sw_if_index[sw_if_index] = 0;
709 cm->config_index_by_sw_if_index[sw_if_index] = ci;
711 * note: do not update the tx feature count here.
714 return /* no error */ 0;
717 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del);
720 ip6_lookup (vlib_main_t * vm,
721 vlib_node_runtime_t * node,
722 vlib_frame_t * frame)
724 return ip6_lookup_inline (vm, node, frame);
727 static u8 * format_ip6_lookup_trace (u8 * s, va_list * args);
729 VLIB_REGISTER_NODE (ip6_lookup_node) = {
730 .function = ip6_lookup,
731 .name = "ip6-lookup",
732 .vector_size = sizeof (u32),
734 .format_trace = format_ip6_lookup_trace,
736 .n_next_nodes = IP6_LOOKUP_N_NEXT,
737 .next_nodes = IP6_LOOKUP_NEXT_NODES,
740 VLIB_NODE_FUNCTION_MULTIARCH (ip6_lookup_node, ip6_lookup)
743 ip6_load_balance (vlib_main_t * vm,
744 vlib_node_runtime_t * node,
745 vlib_frame_t * frame)
747 vlib_combined_counter_main_t * cm = &load_balance_main.lbm_via_counters;
748 u32 n_left_from, n_left_to_next, * from, * to_next;
749 ip_lookup_next_t next;
750 u32 cpu_index = os_get_cpu_number();
752 from = vlib_frame_vector_args (frame);
753 n_left_from = frame->n_vectors;
754 next = node->cached_next_index;
756 if (node->flags & VLIB_NODE_FLAG_TRACE)
757 ip6_forward_next_trace(vm, node, frame, VLIB_TX);
759 while (n_left_from > 0)
761 vlib_get_next_frame (vm, node, next,
762 to_next, n_left_to_next);
765 while (n_left_from > 0 && n_left_to_next > 0)
767 ip_lookup_next_t next0;
768 const load_balance_t *lb0;
771 const ip6_header_t *ip0;
772 const dpo_id_t *dpo0;
777 p0 = vlib_get_buffer (vm, pi0);
779 ip0 = vlib_buffer_get_current (p0);
780 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
782 lb0 = load_balance_get(lbi0);
783 hc0 = lb0->lb_hash_config;
784 vnet_buffer(p0)->ip.flow_hash = ip6_compute_flow_hash(ip0, hc0);
786 dpo0 = load_balance_get_bucket_i(lb0,
787 vnet_buffer(p0)->ip.flow_hash &
788 (lb0->lb_n_buckets - 1));
790 next0 = dpo0->dpoi_next_node;
791 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
793 vlib_increment_combined_counter
794 (cm, cpu_index, lbi0, 1,
795 vlib_buffer_length_in_chain (vm, p0));
802 if (PREDICT_FALSE (next0 != next))
805 vlib_put_next_frame (vm, node, next, n_left_to_next);
807 vlib_get_next_frame (vm, node, next,
808 to_next, n_left_to_next);
815 vlib_put_next_frame (vm, node, next, n_left_to_next);
818 return frame->n_vectors;
821 VLIB_REGISTER_NODE (ip6_load_balance_node) = {
822 .function = ip6_load_balance,
823 .name = "ip6-load-balance",
824 .vector_size = sizeof (u32),
825 .sibling_of = "ip6-lookup",
826 .format_trace = format_ip6_lookup_trace,
830 VLIB_NODE_FUNCTION_MULTIARCH (ip6_load_balance_node, ip6_load_balance)
833 /* Adjacency taken. */
838 /* Packet data, possibly *after* rewrite. */
839 u8 packet_data[128 - 1*sizeof(u32)];
840 } ip6_forward_next_trace_t;
842 static u8 * format_ip6_forward_next_trace (u8 * s, va_list * args)
844 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
845 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
846 ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
847 uword indent = format_get_indent (s);
849 s = format(s, "%U%U",
850 format_white_space, indent,
851 format_ip6_header, t->packet_data, sizeof (t->packet_data));
855 static u8 * format_ip6_lookup_trace (u8 * s, va_list * args)
857 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
858 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
859 ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
860 uword indent = format_get_indent (s);
862 s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
863 t->fib_index, t->adj_index, t->flow_hash);
864 s = format(s, "\n%U%U",
865 format_white_space, indent,
866 format_ip6_header, t->packet_data, sizeof (t->packet_data));
871 static u8 * format_ip6_rewrite_trace (u8 * s, va_list * args)
873 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
874 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
875 ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
876 vnet_main_t * vnm = vnet_get_main();
877 uword indent = format_get_indent (s);
879 s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
880 t->fib_index, t->adj_index, format_ip_adjacency,
881 vnm, t->adj_index, FORMAT_IP_ADJACENCY_NONE,
883 s = format (s, "\n%U%U",
884 format_white_space, indent,
885 format_ip_adjacency_packet_data,
887 t->packet_data, sizeof (t->packet_data));
891 /* Common trace function for all ip6-forward next nodes. */
893 ip6_forward_next_trace (vlib_main_t * vm,
894 vlib_node_runtime_t * node,
895 vlib_frame_t * frame,
896 vlib_rx_or_tx_t which_adj_index)
899 ip6_main_t * im = &ip6_main;
901 n_left = frame->n_vectors;
902 from = vlib_frame_vector_args (frame);
907 vlib_buffer_t * b0, * b1;
908 ip6_forward_next_trace_t * t0, * t1;
910 /* Prefetch next iteration. */
911 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
912 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
917 b0 = vlib_get_buffer (vm, bi0);
918 b1 = vlib_get_buffer (vm, bi1);
920 if (b0->flags & VLIB_BUFFER_IS_TRACED)
922 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
923 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
924 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
925 t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
926 vnet_buffer(b0)->sw_if_index[VLIB_TX] :
927 vec_elt (im->fib_index_by_sw_if_index,
928 vnet_buffer(b0)->sw_if_index[VLIB_RX]);
930 clib_memcpy (t0->packet_data,
931 vlib_buffer_get_current (b0),
932 sizeof (t0->packet_data));
934 if (b1->flags & VLIB_BUFFER_IS_TRACED)
936 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
937 t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
938 t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
939 t1->fib_index = (vnet_buffer(b1)->sw_if_index[VLIB_TX] != (u32)~0) ?
940 vnet_buffer(b1)->sw_if_index[VLIB_TX] :
941 vec_elt (im->fib_index_by_sw_if_index,
942 vnet_buffer(b1)->sw_if_index[VLIB_RX]);
944 clib_memcpy (t1->packet_data,
945 vlib_buffer_get_current (b1),
946 sizeof (t1->packet_data));
956 ip6_forward_next_trace_t * t0;
960 b0 = vlib_get_buffer (vm, bi0);
962 if (b0->flags & VLIB_BUFFER_IS_TRACED)
964 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
965 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
966 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
967 t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
968 vnet_buffer(b0)->sw_if_index[VLIB_TX] :
969 vec_elt (im->fib_index_by_sw_if_index,
970 vnet_buffer(b0)->sw_if_index[VLIB_RX]);
972 clib_memcpy (t0->packet_data,
973 vlib_buffer_get_current (b0),
974 sizeof (t0->packet_data));
982 ip6_drop_or_punt (vlib_main_t * vm,
983 vlib_node_runtime_t * node,
984 vlib_frame_t * frame,
985 ip6_error_t error_code)
987 u32 * buffers = vlib_frame_vector_args (frame);
988 uword n_packets = frame->n_vectors;
990 vlib_error_drop_buffers (vm, node,
995 ip6_input_node.index,
998 if (node->flags & VLIB_NODE_FLAG_TRACE)
999 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1005 ip6_drop (vlib_main_t * vm,
1006 vlib_node_runtime_t * node,
1007 vlib_frame_t * frame)
1008 { return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_DROP); }
1011 ip6_punt (vlib_main_t * vm,
1012 vlib_node_runtime_t * node,
1013 vlib_frame_t * frame)
1014 { return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_PUNT); }
1016 VLIB_REGISTER_NODE (ip6_drop_node,static) = {
1017 .function = ip6_drop,
1019 .vector_size = sizeof (u32),
1021 .format_trace = format_ip6_forward_next_trace,
1029 VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop)
1031 VLIB_REGISTER_NODE (ip6_punt_node,static) = {
1032 .function = ip6_punt,
1034 .vector_size = sizeof (u32),
1036 .format_trace = format_ip6_forward_next_trace,
1044 VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt)
1046 VLIB_REGISTER_NODE (ip6_multicast_node,static) = {
1047 .function = ip6_drop,
1048 .name = "ip6-multicast",
1049 .vector_size = sizeof (u32),
1051 .format_trace = format_ip6_forward_next_trace,
1059 /* Compute TCP/UDP/ICMP6 checksum in software. */
1060 u16 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, ip6_header_t * ip0, int *bogus_lengthp)
1063 u16 sum16, payload_length_host_byte_order;
1064 u32 i, n_this_buffer, n_bytes_left;
1065 u32 headers_size = sizeof(ip0[0]);
1066 void * data_this_buffer;
1068 ASSERT(bogus_lengthp);
1071 /* Initialize checksum with ip header. */
1072 sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol);
1073 payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
1074 data_this_buffer = (void *) (ip0 + 1);
1076 for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
1078 sum0 = ip_csum_with_carry (sum0,
1079 clib_mem_unaligned (&ip0->src_address.as_uword[i], uword));
1080 sum0 = ip_csum_with_carry (sum0,
1081 clib_mem_unaligned (&ip0->dst_address.as_uword[i], uword));
1084 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
1085 if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
1088 ip6_hop_by_hop_ext_t *ext_hdr = (ip6_hop_by_hop_ext_t *)data_this_buffer;
1090 /* validate really icmp6 next */
1091 ASSERT(ext_hdr->next_hdr == IP_PROTOCOL_ICMP6);
1093 skip_bytes = 8* (1 + ext_hdr->n_data_u64s);
1094 data_this_buffer = (void *)((u8 *)data_this_buffer + skip_bytes);
1096 payload_length_host_byte_order -= skip_bytes;
1097 headers_size += skip_bytes;
1100 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
1102 if (p0 && n_this_buffer + headers_size > p0->current_length)
1104 struct rte_mbuf *mb = rte_mbuf_from_vlib_buffer(p0);
1105 u8 nb_segs = mb->nb_segs;
1107 n_this_buffer = (p0->current_length > headers_size ?
1108 p0->current_length - headers_size : 0);
1109 while (n_bytes_left)
1111 sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
1112 n_bytes_left -= n_this_buffer;
1116 if ((nb_segs == 0) || (mb == 0))
1119 data_this_buffer = rte_ctrlmbuf_data(mb);
1120 n_this_buffer = mb->data_len;
1122 if (n_bytes_left || nb_segs)
1128 else sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
1130 if (p0 && n_this_buffer + headers_size > p0->current_length)
1131 n_this_buffer = p0->current_length > headers_size ? p0->current_length - headers_size : 0;
1134 sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
1135 n_bytes_left -= n_this_buffer;
1136 if (n_bytes_left == 0)
1139 if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
1144 p0 = vlib_get_buffer (vm, p0->next_buffer);
1145 data_this_buffer = vlib_buffer_get_current (p0);
1146 n_this_buffer = p0->current_length;
1150 sum16 = ~ ip_csum_fold (sum0);
1155 u32 ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
1157 ip6_header_t * ip0 = vlib_buffer_get_current (p0);
1158 udp_header_t * udp0;
1162 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
1163 ASSERT (ip0->protocol == IP_PROTOCOL_TCP
1164 || ip0->protocol == IP_PROTOCOL_ICMP6
1165 || ip0->protocol == IP_PROTOCOL_UDP
1166 || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
1168 udp0 = (void *) (ip0 + 1);
1169 if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0)
1171 p0->flags |= (IP_BUFFER_L4_CHECKSUM_COMPUTED
1172 | IP_BUFFER_L4_CHECKSUM_CORRECT);
1176 sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length);
1178 p0->flags |= (IP_BUFFER_L4_CHECKSUM_COMPUTED
1179 | ((sum16 == 0) << LOG2_IP_BUFFER_L4_CHECKSUM_CORRECT));
1185 ip6_local (vlib_main_t * vm,
1186 vlib_node_runtime_t * node,
1187 vlib_frame_t * frame)
1189 ip6_main_t * im = &ip6_main;
1190 ip_lookup_main_t * lm = &im->lookup_main;
1191 ip_local_next_t next_index;
1192 u32 * from, * to_next, n_left_from, n_left_to_next;
1193 vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_input_node.index);
1195 from = vlib_frame_vector_args (frame);
1196 n_left_from = frame->n_vectors;
1197 next_index = node->cached_next_index;
1199 if (node->flags & VLIB_NODE_FLAG_TRACE)
1200 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1202 while (n_left_from > 0)
1204 vlib_get_next_frame (vm, node, next_index,
1205 to_next, n_left_to_next);
1207 while (n_left_from >= 4 && n_left_to_next >= 2)
1209 vlib_buffer_t * p0, * p1;
1210 ip6_header_t * ip0, * ip1;
1211 udp_header_t * udp0, * udp1;
1212 u32 pi0, ip_len0, udp_len0, flags0, next0;
1213 u32 pi1, ip_len1, udp_len1, flags1, next1;
1214 i32 len_diff0, len_diff1;
1215 u8 error0, type0, good_l4_checksum0;
1216 u8 error1, type1, good_l4_checksum1;
1218 pi0 = to_next[0] = from[0];
1219 pi1 = to_next[1] = from[1];
1223 n_left_to_next -= 2;
1225 p0 = vlib_get_buffer (vm, pi0);
1226 p1 = vlib_get_buffer (vm, pi1);
1228 ip0 = vlib_buffer_get_current (p0);
1229 ip1 = vlib_buffer_get_current (p1);
1231 type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
1232 type1 = lm->builtin_protocol_by_ip_protocol[ip1->protocol];
1234 next0 = lm->local_next_by_ip_protocol[ip0->protocol];
1235 next1 = lm->local_next_by_ip_protocol[ip1->protocol];
1240 good_l4_checksum0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1241 good_l4_checksum1 = (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1243 udp0 = ip6_next_header (ip0);
1244 udp1 = ip6_next_header (ip1);
1246 /* Don't verify UDP checksum for packets with explicit zero checksum. */
1247 good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP && udp0->checksum == 0;
1248 good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UDP && udp1->checksum == 0;
1250 good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1251 good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1253 /* Verify UDP length. */
1254 ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1255 ip_len1 = clib_net_to_host_u16 (ip1->payload_length);
1256 udp_len0 = clib_net_to_host_u16 (udp0->length);
1257 udp_len1 = clib_net_to_host_u16 (udp1->length);
1259 len_diff0 = ip_len0 - udp_len0;
1260 len_diff1 = ip_len1 - udp_len1;
1262 len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1263 len_diff1 = type1 == IP_BUILTIN_PROTOCOL_UDP ? len_diff1 : 0;
1265 if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
1266 && ! good_l4_checksum0
1267 && ! (flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
1269 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
1271 (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1273 if (PREDICT_FALSE (type1 != IP_BUILTIN_PROTOCOL_UNKNOWN
1274 && ! good_l4_checksum1
1275 && ! (flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
1277 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, p1);
1279 (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1282 error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL;
1284 error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1285 error1 = len_diff1 < 0 ? IP6_ERROR_UDP_LENGTH : error1;
1287 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == IP6_ERROR_UDP_CHECKSUM);
1288 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == IP6_ERROR_ICMP_CHECKSUM);
1289 error0 = (! good_l4_checksum0
1290 ? IP6_ERROR_UDP_CHECKSUM + type0
1292 error1 = (! good_l4_checksum1
1293 ? IP6_ERROR_UDP_CHECKSUM + type1
1296 /* Drop packets from unroutable hosts. */
1297 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
1298 if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1299 type0 != IP_BUILTIN_PROTOCOL_ICMP &&
1300 !ip6_address_is_link_local_unicast(&ip0->src_address))
1302 u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
1303 error0 = (ADJ_INDEX_INVALID == src_adj_index0
1304 ? IP6_ERROR_SRC_LOOKUP_MISS
1307 if (error1 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1308 type1 != IP_BUILTIN_PROTOCOL_ICMP &&
1309 !ip6_address_is_link_local_unicast(&ip1->src_address))
1311 u32 src_adj_index1 = ip6_src_lookup_for_packet (im, p1, ip1);
1312 error1 = (ADJ_INDEX_INVALID == src_adj_index1
1313 ? IP6_ERROR_SRC_LOOKUP_MISS
1317 next0 = error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
1318 next1 = error1 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
1320 p0->error = error_node->errors[error0];
1321 p1->error = error_node->errors[error1];
1323 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1324 to_next, n_left_to_next,
1325 pi0, pi1, next0, next1);
1328 while (n_left_from > 0 && n_left_to_next > 0)
1332 udp_header_t * udp0;
1333 u32 pi0, ip_len0, udp_len0, flags0, next0;
1335 u8 error0, type0, good_l4_checksum0;
1337 pi0 = to_next[0] = from[0];
1341 n_left_to_next -= 1;
1343 p0 = vlib_get_buffer (vm, pi0);
1345 ip0 = vlib_buffer_get_current (p0);
1347 type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
1348 next0 = lm->local_next_by_ip_protocol[ip0->protocol];
1352 good_l4_checksum0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1354 udp0 = ip6_next_header (ip0);
1356 /* Don't verify UDP checksum for packets with explicit zero checksum. */
1357 good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP && udp0->checksum == 0;
1359 good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1361 /* Verify UDP length. */
1362 ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1363 udp_len0 = clib_net_to_host_u16 (udp0->length);
1365 len_diff0 = ip_len0 - udp_len0;
1367 len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1369 if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN
1370 && ! good_l4_checksum0
1371 && ! (flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
1373 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
1375 (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1378 error0 = IP6_ERROR_UNKNOWN_PROTOCOL;
1380 error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1382 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == IP6_ERROR_UDP_CHECKSUM);
1383 ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == IP6_ERROR_ICMP_CHECKSUM);
1384 error0 = (! good_l4_checksum0
1385 ? IP6_ERROR_UDP_CHECKSUM + type0
1388 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
1389 if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL &&
1390 type0 != IP_BUILTIN_PROTOCOL_ICMP &&
1391 !ip6_address_is_link_local_unicast(&ip0->src_address))
1393 u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
1394 error0 = (ADJ_INDEX_INVALID == src_adj_index0
1395 ? IP6_ERROR_SRC_LOOKUP_MISS
1399 next0 = error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
1401 p0->error = error_node->errors[error0];
1403 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1404 to_next, n_left_to_next,
1408 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1411 return frame->n_vectors;
1414 VLIB_REGISTER_NODE (ip6_local_node,static) = {
1415 .function = ip6_local,
1416 .name = "ip6-local",
1417 .vector_size = sizeof (u32),
1419 .format_trace = format_ip6_forward_next_trace,
1421 .n_next_nodes = IP_LOCAL_N_NEXT,
1423 [IP_LOCAL_NEXT_DROP] = "error-drop",
1424 [IP_LOCAL_NEXT_PUNT] = "error-punt",
1425 [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
1426 [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
1430 VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_node, ip6_local)
1432 void ip6_register_protocol (u32 protocol, u32 node_index)
1434 vlib_main_t * vm = vlib_get_main();
1435 ip6_main_t * im = &ip6_main;
1436 ip_lookup_main_t * lm = &im->lookup_main;
1438 ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
1439 lm->local_next_by_ip_protocol[protocol] = vlib_node_add_next (vm, ip6_local_node.index, node_index);
1443 IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
1444 IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX,
1445 IP6_DISCOVER_NEIGHBOR_N_NEXT,
1446 } ip6_discover_neighbor_next_t;
1449 IP6_DISCOVER_NEIGHBOR_ERROR_DROP,
1450 IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT,
1451 IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS,
1452 } ip6_discover_neighbor_error_t;
1455 ip6_discover_neighbor_inline (vlib_main_t * vm,
1456 vlib_node_runtime_t * node,
1457 vlib_frame_t * frame,
1460 vnet_main_t * vnm = vnet_get_main();
1461 ip6_main_t * im = &ip6_main;
1462 ip_lookup_main_t * lm = &im->lookup_main;
1463 u32 * from, * to_next_drop;
1464 uword n_left_from, n_left_to_next_drop;
1465 static f64 time_last_seed_change = -1e100;
1466 static u32 hash_seeds[3];
1467 static uword hash_bitmap[256 / BITS (uword)];
1471 if (node->flags & VLIB_NODE_FLAG_TRACE)
1472 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1474 time_now = vlib_time_now (vm);
1475 if (time_now - time_last_seed_change > 1e-3)
1478 u32 * r = clib_random_buffer_get_data (&vm->random_buffer,
1479 sizeof (hash_seeds));
1480 for (i = 0; i < ARRAY_LEN (hash_seeds); i++)
1481 hash_seeds[i] = r[i];
1483 /* Mark all hash keys as been not-seen before. */
1484 for (i = 0; i < ARRAY_LEN (hash_bitmap); i++)
1487 time_last_seed_change = time_now;
1490 from = vlib_frame_vector_args (frame);
1491 n_left_from = frame->n_vectors;
1493 while (n_left_from > 0)
1495 vlib_get_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
1496 to_next_drop, n_left_to_next_drop);
1498 while (n_left_from > 0 && n_left_to_next_drop > 0)
1502 u32 pi0, adj_index0, a0, b0, c0, m0, sw_if_index0, drop0;
1504 ip_adjacency_t * adj0;
1505 vnet_hw_interface_t * hw_if0;
1510 p0 = vlib_get_buffer (vm, pi0);
1512 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1514 ip0 = vlib_buffer_get_current (p0);
1516 adj0 = ip_get_adjacency (lm, adj_index0);
1520 ip0->dst_address.as_u64[0] = adj0->sub_type.nbr.next_hop.ip6.as_u64[0];
1521 ip0->dst_address.as_u64[1] = adj0->sub_type.nbr.next_hop.ip6.as_u64[1];
1528 sw_if_index0 = adj0->rewrite_header.sw_if_index;
1529 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
1532 b0 ^= ip0->dst_address.as_u32[0];
1533 c0 ^= ip0->dst_address.as_u32[1];
1535 hash_v3_mix32 (a0, b0, c0);
1537 b0 ^= ip0->dst_address.as_u32[2];
1538 c0 ^= ip0->dst_address.as_u32[3];
1540 hash_v3_finalize32 (a0, b0, c0);
1542 c0 &= BITS (hash_bitmap) - 1;
1543 c0 = c0 / BITS (uword);
1544 m0 = (uword) 1 << (c0 % BITS (uword));
1546 bm0 = hash_bitmap[c0];
1547 drop0 = (bm0 & m0) != 0;
1549 /* Mark it as seen. */
1550 hash_bitmap[c0] = bm0 | m0;
1554 to_next_drop[0] = pi0;
1556 n_left_to_next_drop -= 1;
1558 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
1560 /* If the interface is link-down, drop the pkt */
1561 if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
1565 node->errors[drop0 ? IP6_DISCOVER_NEIGHBOR_ERROR_DROP
1566 : IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT];
1572 icmp6_neighbor_solicitation_header_t * h0;
1575 h0 = vlib_packet_template_get_packet
1576 (vm, &im->discover_neighbor_packet_template, &bi0);
1579 * Build ethernet header.
1580 * Choose source address based on destination lookup
1583 if (ip6_src_address_for_packet (lm,
1585 &h0->ip.src_address))
1587 /* There is no address on the interface */
1588 p0->error = node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS];
1589 vlib_buffer_free(vm, &bi0, 1);
1594 * Destination address is a solicited node multicast address.
1595 * We need to fill in
1596 * the low 24 bits with low 24 bits of target's address.
1598 h0->ip.dst_address.as_u8[13] = ip0->dst_address.as_u8[13];
1599 h0->ip.dst_address.as_u8[14] = ip0->dst_address.as_u8[14];
1600 h0->ip.dst_address.as_u8[15] = ip0->dst_address.as_u8[15];
1602 h0->neighbor.target_address = ip0->dst_address;
1604 clib_memcpy (h0->link_layer_option.ethernet_address,
1605 hw_if0->hw_address, vec_len (hw_if0->hw_address));
1607 /* $$$$ appears we need this; why is the checksum non-zero? */
1608 h0->neighbor.icmp.checksum = 0;
1609 h0->neighbor.icmp.checksum =
1610 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip,
1613 ASSERT (bogus_length == 0);
1615 vlib_buffer_copy_trace_flag (vm, p0, bi0);
1616 b0 = vlib_get_buffer (vm, bi0);
1617 vnet_buffer (b0)->sw_if_index[VLIB_TX]
1618 = vnet_buffer (p0)->sw_if_index[VLIB_TX];
1620 /* Add rewrite/encap string. */
1621 vnet_rewrite_one_header (adj0[0], h0,
1622 sizeof (ethernet_header_t));
1623 vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
1625 next0 = IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX;
1627 vlib_set_next_frame_buffer (vm, node, next0, bi0);
1631 vlib_put_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
1632 n_left_to_next_drop);
1635 return frame->n_vectors;
1639 ip6_discover_neighbor (vlib_main_t * vm,
1640 vlib_node_runtime_t * node,
1641 vlib_frame_t * frame)
1643 return (ip6_discover_neighbor_inline(vm, node, frame, 0));
1647 ip6_glean (vlib_main_t * vm,
1648 vlib_node_runtime_t * node,
1649 vlib_frame_t * frame)
1651 return (ip6_discover_neighbor_inline(vm, node, frame, 1));
1654 static char * ip6_discover_neighbor_error_strings[] = {
1655 [IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops",
1656 [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT]
1657 = "neighbor solicitations sent",
1658 [IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS]
1659 = "no source address for ND solicitation",
1662 VLIB_REGISTER_NODE (ip6_discover_neighbor_node) = {
1663 .function = ip6_discover_neighbor,
1664 .name = "ip6-discover-neighbor",
1665 .vector_size = sizeof (u32),
1667 .format_trace = format_ip6_forward_next_trace,
1669 .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
1670 .error_strings = ip6_discover_neighbor_error_strings,
1672 .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
1674 [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
1675 [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
1679 VLIB_REGISTER_NODE (ip6_glean_node) = {
1680 .function = ip6_glean,
1681 .name = "ip6-glean",
1682 .vector_size = sizeof (u32),
1684 .format_trace = format_ip6_forward_next_trace,
1686 .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
1687 .error_strings = ip6_discover_neighbor_error_strings,
1689 .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
1691 [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
1692 [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
1697 ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
1699 vnet_main_t * vnm = vnet_get_main();
1700 ip6_main_t * im = &ip6_main;
1701 icmp6_neighbor_solicitation_header_t * h;
1702 ip6_address_t * src;
1703 ip_interface_address_t * ia;
1704 ip_adjacency_t * adj;
1705 vnet_hw_interface_t * hi;
1706 vnet_sw_interface_t * si;
1711 si = vnet_get_sw_interface (vnm, sw_if_index);
1713 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
1715 return clib_error_return (0, "%U: interface %U down",
1716 format_ip6_address, dst,
1717 format_vnet_sw_if_index_name, vnm,
1721 src = ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia);
1724 vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE;
1725 return clib_error_return
1726 (0, "no matching interface address for destination %U (interface %U)",
1727 format_ip6_address, dst,
1728 format_vnet_sw_if_index_name, vnm, sw_if_index);
1731 h = vlib_packet_template_get_packet (vm, &im->discover_neighbor_packet_template, &bi);
1733 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
1735 /* Destination address is a solicited node multicast address. We need to fill in
1736 the low 24 bits with low 24 bits of target's address. */
1737 h->ip.dst_address.as_u8[13] = dst->as_u8[13];
1738 h->ip.dst_address.as_u8[14] = dst->as_u8[14];
1739 h->ip.dst_address.as_u8[15] = dst->as_u8[15];
1741 h->ip.src_address = src[0];
1742 h->neighbor.target_address = dst[0];
1744 clib_memcpy (h->link_layer_option.ethernet_address, hi->hw_address, vec_len (hi->hw_address));
1746 h->neighbor.icmp.checksum =
1747 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
1748 ASSERT(bogus_length == 0);
1750 b = vlib_get_buffer (vm, bi);
1751 vnet_buffer (b)->sw_if_index[VLIB_RX] = vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
1753 /* Add encapsulation string for software interface (e.g. ethernet header). */
1754 adj = ip_get_adjacency (&im->lookup_main, ia->neighbor_probe_adj_index);
1755 vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
1756 vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
1759 vlib_frame_t * f = vlib_get_frame_to_node (vm, hi->output_node_index);
1760 u32 * to_next = vlib_frame_vector_args (f);
1763 vlib_put_frame_to_node (vm, hi->output_node_index, f);
1766 return /* no error */ 0;
1770 IP6_REWRITE_NEXT_DROP,
1771 IP6_REWRITE_NEXT_ICMP_ERROR,
1772 } ip6_rewrite_next_t;
1775 ip6_rewrite_inline (vlib_main_t * vm,
1776 vlib_node_runtime_t * node,
1777 vlib_frame_t * frame,
1778 int rewrite_for_locally_received_packets)
1780 ip_lookup_main_t * lm = &ip6_main.lookup_main;
1781 u32 * from = vlib_frame_vector_args (frame);
1782 u32 n_left_from, n_left_to_next, * to_next, next_index;
1783 vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_input_node.index);
1784 vlib_rx_or_tx_t adj_rx_tx = rewrite_for_locally_received_packets ? VLIB_RX : VLIB_TX;
1785 ip_config_main_t * cm = &lm->feature_config_mains[VNET_IP_TX_FEAT];
1787 n_left_from = frame->n_vectors;
1788 next_index = node->cached_next_index;
1789 u32 cpu_index = os_get_cpu_number();
1791 while (n_left_from > 0)
1793 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1795 while (n_left_from >= 4 && n_left_to_next >= 2)
1797 ip_adjacency_t * adj0, * adj1;
1798 vlib_buffer_t * p0, * p1;
1799 ip6_header_t * ip0, * ip1;
1800 u32 pi0, rw_len0, next0, error0, adj_index0;
1801 u32 pi1, rw_len1, next1, error1, adj_index1;
1802 u32 tx_sw_if_index0, tx_sw_if_index1;
1804 /* Prefetch next iteration. */
1806 vlib_buffer_t * p2, * p3;
1808 p2 = vlib_get_buffer (vm, from[2]);
1809 p3 = vlib_get_buffer (vm, from[3]);
1811 vlib_prefetch_buffer_header (p2, LOAD);
1812 vlib_prefetch_buffer_header (p3, LOAD);
1814 CLIB_PREFETCH (p2->pre_data, 32, STORE);
1815 CLIB_PREFETCH (p3->pre_data, 32, STORE);
1817 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
1818 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
1821 pi0 = to_next[0] = from[0];
1822 pi1 = to_next[1] = from[1];
1827 n_left_to_next -= 2;
1829 p0 = vlib_get_buffer (vm, pi0);
1830 p1 = vlib_get_buffer (vm, pi1);
1832 adj_index0 = vnet_buffer (p0)->ip.adj_index[adj_rx_tx];
1833 adj_index1 = vnet_buffer (p1)->ip.adj_index[adj_rx_tx];
1835 /* We should never rewrite a pkt using the MISS adjacency */
1836 ASSERT(adj_index0 && adj_index1);
1838 ip0 = vlib_buffer_get_current (p0);
1839 ip1 = vlib_buffer_get_current (p1);
1841 error0 = error1 = IP6_ERROR_NONE;
1842 next0 = next1 = IP6_REWRITE_NEXT_DROP;
1844 if (! rewrite_for_locally_received_packets)
1846 i32 hop_limit0 = ip0->hop_limit, hop_limit1 = ip1->hop_limit;
1848 /* Input node should have reject packets with hop limit 0. */
1849 ASSERT (ip0->hop_limit > 0);
1850 ASSERT (ip1->hop_limit > 0);
1855 ip0->hop_limit = hop_limit0;
1856 ip1->hop_limit = hop_limit1;
1859 * If the hop count drops below 1 when forwarding, generate
1862 if (PREDICT_FALSE(hop_limit0 <= 0))
1864 error0 = IP6_ERROR_TIME_EXPIRED;
1865 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
1866 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32)~0;
1867 icmp6_error_set_vnet_buffer(p0, ICMP6_time_exceeded,
1868 ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
1870 if (PREDICT_FALSE(hop_limit1 <= 0))
1872 error1 = IP6_ERROR_TIME_EXPIRED;
1873 next1 = IP6_REWRITE_NEXT_ICMP_ERROR;
1874 vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32)~0;
1875 icmp6_error_set_vnet_buffer(p1, ICMP6_time_exceeded,
1876 ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
1880 adj0 = ip_get_adjacency (lm, adj_index0);
1881 adj1 = ip_get_adjacency (lm, adj_index1);
1883 rw_len0 = adj0[0].rewrite_header.data_bytes;
1884 rw_len1 = adj1[0].rewrite_header.data_bytes;
1885 vnet_buffer(p0)->ip.save_rewrite_length = rw_len0;
1886 vnet_buffer(p1)->ip.save_rewrite_length = rw_len1;
1888 vlib_increment_combined_counter (&adjacency_counters,
1891 /* packet increment */ 0,
1892 /* byte increment */ rw_len0);
1893 vlib_increment_combined_counter (&adjacency_counters,
1896 /* packet increment */ 0,
1897 /* byte increment */ rw_len1);
1899 /* Check MTU of outgoing interface. */
1900 error0 = (vlib_buffer_length_in_chain (vm, p0) > adj0[0].rewrite_header.max_l3_packet_bytes
1901 ? IP6_ERROR_MTU_EXCEEDED
1903 error1 = (vlib_buffer_length_in_chain (vm, p1) > adj1[0].rewrite_header.max_l3_packet_bytes
1904 ? IP6_ERROR_MTU_EXCEEDED
1907 /* Don't adjust the buffer for hop count issue; icmp-error node
1908 * wants to see the IP headerr */
1909 if (PREDICT_TRUE(error0 == IP6_ERROR_NONE))
1911 p0->current_data -= rw_len0;
1912 p0->current_length += rw_len0;
1914 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
1915 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
1917 next0 = adj0[0].rewrite_header.next_index;
1920 (clib_bitmap_get (lm->tx_sw_if_has_ip_output_features,
1923 p0->current_config_index =
1924 vec_elt (cm->config_index_by_sw_if_index,
1926 vnet_get_config_data (&cm->config_main,
1927 &p0->current_config_index,
1929 /* # bytes of config data */ 0);
1932 if (PREDICT_TRUE(error1 == IP6_ERROR_NONE))
1934 p1->current_data -= rw_len1;
1935 p1->current_length += rw_len1;
1937 tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
1938 vnet_buffer (p1)->sw_if_index[VLIB_TX] =
1940 next1 = adj1[0].rewrite_header.next_index;
1943 (clib_bitmap_get (lm->tx_sw_if_has_ip_output_features,
1946 p1->current_config_index =
1947 vec_elt (cm->config_index_by_sw_if_index,
1949 vnet_get_config_data (&cm->config_main,
1950 &p1->current_config_index,
1952 /* # bytes of config data */ 0);
1956 /* Guess we are only writing on simple Ethernet header. */
1957 vnet_rewrite_two_headers (adj0[0], adj1[0],
1959 sizeof (ethernet_header_t));
1961 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1962 to_next, n_left_to_next,
1963 pi0, pi1, next0, next1);
1966 while (n_left_from > 0 && n_left_to_next > 0)
1968 ip_adjacency_t * adj0;
1972 u32 adj_index0, next0, error0;
1973 u32 tx_sw_if_index0;
1975 pi0 = to_next[0] = from[0];
1977 p0 = vlib_get_buffer (vm, pi0);
1979 adj_index0 = vnet_buffer (p0)->ip.adj_index[adj_rx_tx];
1981 /* We should never rewrite a pkt using the MISS adjacency */
1984 adj0 = ip_get_adjacency (lm, adj_index0);
1986 ip0 = vlib_buffer_get_current (p0);
1988 error0 = IP6_ERROR_NONE;
1989 next0 = IP6_REWRITE_NEXT_DROP;
1991 /* Check hop limit */
1992 if (! rewrite_for_locally_received_packets)
1994 i32 hop_limit0 = ip0->hop_limit;
1996 ASSERT (ip0->hop_limit > 0);
2000 ip0->hop_limit = hop_limit0;
2002 if (PREDICT_FALSE(hop_limit0 <= 0))
2005 * If the hop count drops below 1 when forwarding, generate
2008 error0 = IP6_ERROR_TIME_EXPIRED;
2009 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
2010 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32)~0;
2011 icmp6_error_set_vnet_buffer(p0, ICMP6_time_exceeded,
2012 ICMP6_time_exceeded_ttl_exceeded_in_transit, 0);
2016 /* Guess we are only writing on simple Ethernet header. */
2017 vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
2019 /* Update packet buffer attributes/set output interface. */
2020 rw_len0 = adj0[0].rewrite_header.data_bytes;
2021 vnet_buffer(p0)->ip.save_rewrite_length = rw_len0;
2023 vlib_increment_combined_counter (&adjacency_counters,
2026 /* packet increment */ 0,
2027 /* byte increment */ rw_len0);
2029 /* Check MTU of outgoing interface. */
2030 error0 = (vlib_buffer_length_in_chain (vm, p0) > adj0[0].rewrite_header.max_l3_packet_bytes
2031 ? IP6_ERROR_MTU_EXCEEDED
2034 /* Don't adjust the buffer for hop count issue; icmp-error node
2035 * wants to see the IP headerr */
2036 if (PREDICT_TRUE(error0 == IP6_ERROR_NONE))
2038 p0->current_data -= rw_len0;
2039 p0->current_length += rw_len0;
2041 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
2043 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
2044 next0 = adj0[0].rewrite_header.next_index;
2047 (clib_bitmap_get (lm->tx_sw_if_has_ip_output_features,
2050 p0->current_config_index =
2051 vec_elt (cm->config_index_by_sw_if_index,
2053 vnet_get_config_data (&cm->config_main,
2054 &p0->current_config_index,
2056 /* # bytes of config data */ 0);
2060 p0->error = error_node->errors[error0];
2065 n_left_to_next -= 1;
2067 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
2068 to_next, n_left_to_next,
2072 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2075 /* Need to do trace after rewrites to pick up new packet data. */
2076 if (node->flags & VLIB_NODE_FLAG_TRACE)
2077 ip6_forward_next_trace (vm, node, frame, adj_rx_tx);
2079 return frame->n_vectors;
2083 ip6_rewrite_transit (vlib_main_t * vm,
2084 vlib_node_runtime_t * node,
2085 vlib_frame_t * frame)
2087 return ip6_rewrite_inline (vm, node, frame,
2088 /* rewrite_for_locally_received_packets */ 0);
2092 ip6_rewrite_local (vlib_main_t * vm,
2093 vlib_node_runtime_t * node,
2094 vlib_frame_t * frame)
2096 return ip6_rewrite_inline (vm, node, frame,
2097 /* rewrite_for_locally_received_packets */ 1);
2101 ip6_midchain (vlib_main_t * vm,
2102 vlib_node_runtime_t * node,
2103 vlib_frame_t * frame)
2105 return ip6_rewrite_inline (vm, node, frame,
2106 /* rewrite_for_locally_received_packets */ 0);
2109 VLIB_REGISTER_NODE (ip6_midchain_node) = {
2110 .function = ip6_midchain,
2111 .name = "ip6-midchain",
2112 .vector_size = sizeof (u32),
2114 .format_trace = format_ip6_forward_next_trace,
2117 [IP6_REWRITE_NEXT_DROP] = "error-drop",
2121 VLIB_NODE_FUNCTION_MULTIARCH (ip6_midchain_node, ip6_midchain)
2123 VLIB_REGISTER_NODE (ip6_rewrite_node) = {
2124 .function = ip6_rewrite_transit,
2125 .name = "ip6-rewrite",
2126 .vector_size = sizeof (u32),
2128 .format_trace = format_ip6_rewrite_trace,
2132 [IP6_REWRITE_NEXT_DROP] = "error-drop",
2133 [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error",
2137 VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_node, ip6_rewrite_transit);
2139 VLIB_REGISTER_NODE (ip6_rewrite_local_node) = {
2140 .function = ip6_rewrite_local,
2141 .name = "ip6-rewrite-local",
2142 .vector_size = sizeof (u32),
2144 .sibling_of = "ip6-rewrite",
2146 .format_trace = format_ip6_rewrite_trace,
2151 VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_local_node, ip6_rewrite_local);
2154 * Hop-by-Hop handling
2157 ip6_hop_by_hop_main_t ip6_hop_by_hop_main;
2159 #define foreach_ip6_hop_by_hop_error \
2160 _(PROCESSED, "pkts with ip6 hop-by-hop options") \
2161 _(FORMAT, "incorrectly formatted hop-by-hop options") \
2162 _(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options")
2165 #define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym,
2166 foreach_ip6_hop_by_hop_error
2168 IP6_HOP_BY_HOP_N_ERROR,
2169 } ip6_hop_by_hop_error_t;
2172 * Primary h-b-h handler trace support
2173 * We work pretty hard on the problem for obvious reasons
2178 u8 option_data[256];
2179 } ip6_hop_by_hop_trace_t;
2181 vlib_node_registration_t ip6_hop_by_hop_node;
2183 static char * ip6_hop_by_hop_error_strings[] = {
2184 #define _(sym,string) string,
2185 foreach_ip6_hop_by_hop_error
2190 format_ip6_hop_by_hop_trace (u8 * s, va_list * args)
2192 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2193 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
2194 ip6_hop_by_hop_trace_t * t = va_arg (*args, ip6_hop_by_hop_trace_t *);
2195 ip6_hop_by_hop_header_t *hbh0;
2196 ip6_hop_by_hop_option_t *opt0, *limit0;
2197 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2201 hbh0 = (ip6_hop_by_hop_header_t *)t->option_data;
2203 s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d",
2204 t->next_index, (hbh0->length+1)<<3, t->trace_len);
2206 opt0 = (ip6_hop_by_hop_option_t *) (hbh0+1);
2207 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *)hbh0) + t->trace_len;
2209 while (opt0 < limit0) {
2212 case 0: /* Pad, just stop */
2213 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *)opt0) + 1;
2217 if (hm->trace[type0]) {
2218 s = (*hm->trace[type0])(s, opt0);
2220 s = format (s, "\n unrecognized option %d length %d", type0, opt0->length);
2222 opt0 = (ip6_hop_by_hop_option_t *) (((u8 *)opt0) + opt0->length + sizeof (ip6_hop_by_hop_option_t));
2229 always_inline u8 ip6_scan_hbh_options (
2232 ip6_hop_by_hop_header_t *hbh0,
2233 ip6_hop_by_hop_option_t *opt0,
2234 ip6_hop_by_hop_option_t *limit0,
2237 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2241 while (opt0 < limit0)
2247 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *)opt0) + 1;
2252 if (hm->options[type0])
2254 if ((*hm->options[type0])(b0, ip0, opt0) < 0)
2256 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2262 /* Unrecognized mandatory option, check the two high order bits */
2263 switch (opt0->type & HBH_OPTION_TYPE_HIGH_ORDER_BITS)
2265 case HBH_OPTION_TYPE_SKIP_UNKNOWN:
2267 case HBH_OPTION_TYPE_DISCARD_UNKNOWN:
2268 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2269 *next0 = IP_LOOKUP_NEXT_DROP;
2271 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP:
2272 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2273 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
2274 icmp6_error_set_vnet_buffer(b0, ICMP6_parameter_problem,
2275 ICMP6_parameter_problem_unrecognized_option, (u8 *)opt0 - (u8 *)ip0);
2277 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST:
2278 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2279 if (!ip6_address_is_multicast(&ip0->dst_address))
2281 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
2282 icmp6_error_set_vnet_buffer(b0, ICMP6_parameter_problem,
2283 ICMP6_parameter_problem_unrecognized_option, (u8 *)opt0 - (u8 *)ip0);
2287 *next0 = IP_LOOKUP_NEXT_DROP;
2294 opt0 = (ip6_hop_by_hop_option_t *) (((u8 *)opt0) + opt0->length + sizeof (ip6_hop_by_hop_option_t));
2300 * Process the Hop-by-Hop Options header
2303 ip6_hop_by_hop (vlib_main_t * vm,
2304 vlib_node_runtime_t * node,
2305 vlib_frame_t * frame)
2307 vlib_node_runtime_t *error_node = vlib_node_get_runtime(vm, ip6_hop_by_hop_node.index);
2308 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2309 u32 n_left_from, *from, *to_next;
2310 ip_lookup_next_t next_index;
2311 ip6_main_t * im = &ip6_main;
2312 ip_lookup_main_t *lm = &im->lookup_main;
2314 from = vlib_frame_vector_args (frame);
2315 n_left_from = frame->n_vectors;
2316 next_index = node->cached_next_index;
2318 while (n_left_from > 0) {
2321 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2323 while (n_left_from >= 4 && n_left_to_next >= 2) {
2325 vlib_buffer_t * b0, *b1;
2327 ip6_header_t * ip0, *ip1;
2328 ip6_hop_by_hop_header_t *hbh0, *hbh1;
2329 ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1;
2330 u8 error0 = 0, error1 = 0;
2332 /* Prefetch next iteration. */
2334 vlib_buffer_t * p2, * p3;
2336 p2 = vlib_get_buffer (vm, from[2]);
2337 p3 = vlib_get_buffer (vm, from[3]);
2339 vlib_prefetch_buffer_header (p2, LOAD);
2340 vlib_prefetch_buffer_header (p3, LOAD);
2342 CLIB_PREFETCH (p2->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
2343 CLIB_PREFETCH (p3->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
2346 /* Speculatively enqueue b0, b1 to the current next frame */
2347 to_next[0] = bi0 = from[0];
2348 to_next[1] = bi1 = from[1];
2352 n_left_to_next -= 2;
2354 b0 = vlib_get_buffer (vm, bi0);
2355 b1 = vlib_get_buffer (vm, bi1);
2356 u32 adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
2357 ip_adjacency_t *adj0 = ip_get_adjacency(lm, adj_index0);
2358 u32 adj_index1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX];
2359 ip_adjacency_t *adj1 = ip_get_adjacency(lm, adj_index1);
2361 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2362 next0 = adj0->lookup_next_index;
2363 next1 = adj1->lookup_next_index;
2365 ip0 = vlib_buffer_get_current (b0);
2366 ip1 = vlib_buffer_get_current (b1);
2367 hbh0 = (ip6_hop_by_hop_header_t *)(ip0+1);
2368 hbh1 = (ip6_hop_by_hop_header_t *)(ip1+1);
2369 opt0 = (ip6_hop_by_hop_option_t *)(hbh0+1);
2370 opt1 = (ip6_hop_by_hop_option_t *)(hbh1+1);
2371 limit0 = (ip6_hop_by_hop_option_t *)((u8 *)hbh0 + ((hbh0->length + 1) << 3));
2372 limit1 = (ip6_hop_by_hop_option_t *)((u8 *)hbh1 + ((hbh1->length + 1) << 3));
2375 * Basic validity checks
2377 if ((hbh0->length + 1) << 3 > clib_net_to_host_u16(ip0->payload_length)) {
2378 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2379 next0 = IP_LOOKUP_NEXT_DROP;
2382 /* Scan the set of h-b-h options, process ones that we understand */
2383 error0 = ip6_scan_hbh_options(b0, ip0, hbh0, opt0, limit0, &next0);
2385 if ((hbh1->length + 1) << 3 > clib_net_to_host_u16(ip1->payload_length)) {
2386 error1 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2387 next1 = IP_LOOKUP_NEXT_DROP;
2390 /* Scan the set of h-b-h options, process ones that we understand */
2391 error1 = ip6_scan_hbh_options(b1,ip1,hbh1,opt1,limit1, &next1);
2394 /* Has the classifier flagged this buffer for special treatment? */
2395 if ((error0 == 0) && (vnet_buffer(b0)->l2_classify.opaque_index == OI_DECAP))
2396 next0 = hm->next_override;
2398 /* Has the classifier flagged this buffer for special treatment? */
2399 if ((error1 == 0) && (vnet_buffer(b1)->l2_classify.opaque_index == OI_DECAP))
2400 next1 = hm->next_override;
2402 if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)))
2404 if (b0->flags & VLIB_BUFFER_IS_TRACED) {
2405 ip6_hop_by_hop_trace_t *t = vlib_add_trace(vm, node, b0, sizeof (*t));
2406 u32 trace_len = (hbh0->length + 1) << 3;
2407 t->next_index = next0;
2408 /* Capture the h-b-h option verbatim */
2409 trace_len = trace_len < ARRAY_LEN(t->option_data) ? trace_len : ARRAY_LEN(t->option_data);
2410 t->trace_len = trace_len;
2411 clib_memcpy(t->option_data, hbh0, trace_len);
2413 if (b1->flags & VLIB_BUFFER_IS_TRACED) {
2414 ip6_hop_by_hop_trace_t *t = vlib_add_trace(vm, node, b1, sizeof (*t));
2415 u32 trace_len = (hbh1->length + 1) << 3;
2416 t->next_index = next1;
2417 /* Capture the h-b-h option verbatim */
2418 trace_len = trace_len < ARRAY_LEN(t->option_data) ? trace_len : ARRAY_LEN(t->option_data);
2419 t->trace_len = trace_len;
2420 clib_memcpy(t->option_data, hbh1, trace_len);
2425 b0->error = error_node->errors[error0];
2426 b1->error = error_node->errors[error1];
2428 /* verify speculative enqueue, maybe switch current next frame */
2429 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, n_left_to_next, bi0,
2433 while (n_left_from > 0 && n_left_to_next > 0) {
2438 ip6_hop_by_hop_header_t *hbh0;
2439 ip6_hop_by_hop_option_t *opt0, *limit0;
2442 /* Speculatively enqueue b0 to the current next frame */
2448 n_left_to_next -= 1;
2450 b0 = vlib_get_buffer (vm, bi0);
2451 u32 adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
2452 ip_adjacency_t *adj0 = ip_get_adjacency(lm, adj_index0);
2453 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2454 next0 = adj0->lookup_next_index;
2456 ip0 = vlib_buffer_get_current (b0);
2457 hbh0 = (ip6_hop_by_hop_header_t *)(ip0+1);
2458 opt0 = (ip6_hop_by_hop_option_t *)(hbh0+1);
2459 limit0 = (ip6_hop_by_hop_option_t *)((u8 *)hbh0 + ((hbh0->length + 1) << 3));
2462 * Basic validity checks
2464 if ((hbh0->length + 1) << 3 > clib_net_to_host_u16(ip0->payload_length)) {
2465 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2466 next0 = IP_LOOKUP_NEXT_DROP;
2470 /* Scan the set of h-b-h options, process ones that we understand */
2471 error0 = ip6_scan_hbh_options(b0, ip0, hbh0, opt0, limit0, &next0);
2474 /* Has the classifier flagged this buffer for special treatment? */
2475 if ((error0 == 0) && (vnet_buffer(b0)->l2_classify.opaque_index == OI_DECAP))
2476 next0 = hm->next_override;
2478 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) {
2479 ip6_hop_by_hop_trace_t *t = vlib_add_trace(vm, node, b0, sizeof (*t));
2480 u32 trace_len = (hbh0->length + 1) << 3;
2481 t->next_index = next0;
2482 /* Capture the h-b-h option verbatim */
2483 trace_len = trace_len < ARRAY_LEN(t->option_data) ? trace_len : ARRAY_LEN(t->option_data);
2484 t->trace_len = trace_len;
2485 clib_memcpy(t->option_data, hbh0, trace_len);
2488 b0->error = error_node->errors[error0];
2490 /* verify speculative enqueue, maybe switch current next frame */
2491 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, bi0, next0);
2493 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2495 return frame->n_vectors;
2498 VLIB_REGISTER_NODE (ip6_hop_by_hop_node) = {
2499 .function = ip6_hop_by_hop,
2500 .name = "ip6-hop-by-hop",
2501 .sibling_of = "ip6-lookup",
2502 .vector_size = sizeof (u32),
2503 .format_trace = format_ip6_hop_by_hop_trace,
2504 .type = VLIB_NODE_TYPE_INTERNAL,
2505 .n_errors = ARRAY_LEN(ip6_hop_by_hop_error_strings),
2506 .error_strings = ip6_hop_by_hop_error_strings,
2510 VLIB_NODE_FUNCTION_MULTIARCH (ip6_hop_by_hop_node, ip6_hop_by_hop);
2512 static clib_error_t *
2513 ip6_hop_by_hop_init (vlib_main_t * vm)
2515 ip6_hop_by_hop_main_t * hm = &ip6_hop_by_hop_main;
2516 memset(hm->options, 0, sizeof(hm->options));
2517 memset(hm->trace, 0, sizeof(hm->trace));
2518 hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
2522 VLIB_INIT_FUNCTION (ip6_hop_by_hop_init);
2524 void ip6_hbh_set_next_override (uword next)
2526 ip6_hop_by_hop_main_t * hm = &ip6_hop_by_hop_main;
2528 hm->next_override = next;
2532 ip6_hbh_register_option (u8 option,
2533 int options(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt),
2534 u8 *trace(u8 *s, ip6_hop_by_hop_option_t *opt))
2536 ip6_main_t * im = &ip6_main;
2537 ip6_hop_by_hop_main_t * hm = &ip6_hop_by_hop_main;
2539 ASSERT (option < ARRAY_LEN (hm->options));
2541 /* Already registered */
2542 if (hm->options[option])
2545 hm->options[option] = options;
2546 hm->trace[option] = trace;
2548 /* Set global variable */
2549 im->hbh_enabled = 1;
2555 ip6_hbh_unregister_option (u8 option)
2557 ip6_main_t * im = &ip6_main;
2558 ip6_hop_by_hop_main_t * hm = &ip6_hop_by_hop_main;
2560 ASSERT (option < ARRAY_LEN (hm->options));
2562 /* Not registered */
2563 if (!hm->options[option])
2566 hm->options[option] = NULL;
2567 hm->trace[option] = NULL;
2569 /* Disable global knob if this was the last option configured */
2572 for (i = 0; i < 256; i++) {
2573 if (hm->options[option]) {
2579 im->hbh_enabled = 0;
2584 /* Global IP6 main. */
2585 ip6_main_t ip6_main;
2587 static clib_error_t *
2588 ip6_lookup_init (vlib_main_t * vm)
2590 ip6_main_t * im = &ip6_main;
2591 clib_error_t * error;
2594 for (i = 0; i < ARRAY_LEN (im->fib_masks); i++)
2601 for (j = 0; j < i0; j++)
2602 im->fib_masks[i].as_u32[j] = ~0;
2605 im->fib_masks[i].as_u32[i0] = clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
2608 ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1);
2610 if (im->lookup_table_nbuckets == 0)
2611 im->lookup_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS;
2613 im->lookup_table_nbuckets = 1<< max_log2 (im->lookup_table_nbuckets);
2615 if (im->lookup_table_size == 0)
2616 im->lookup_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE;
2618 BV(clib_bihash_init) (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash),
2619 "ip6 FIB fwding table",
2620 im->lookup_table_nbuckets,
2621 im->lookup_table_size);
2622 BV(clib_bihash_init) (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
2623 "ip6 FIB non-fwding table",
2624 im->lookup_table_nbuckets,
2625 im->lookup_table_size);
2627 /* Create FIB with index 0 and table id of 0. */
2628 fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP6, 0);
2632 pn = pg_get_node (ip6_lookup_node.index);
2633 pn->unformat_edit = unformat_pg_ip6_header;
2636 /* Unless explicitly configured, don't process HBH options */
2637 im->hbh_enabled = 0;
2640 icmp6_neighbor_solicitation_header_t p;
2642 memset (&p, 0, sizeof (p));
2644 p.ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
2645 p.ip.payload_length = clib_host_to_net_u16 (sizeof (p)
2646 - STRUCT_OFFSET_OF (icmp6_neighbor_solicitation_header_t, neighbor));
2647 p.ip.protocol = IP_PROTOCOL_ICMP6;
2648 p.ip.hop_limit = 255;
2649 ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0);
2651 p.neighbor.icmp.type = ICMP6_neighbor_solicitation;
2653 p.link_layer_option.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
2654 p.link_layer_option.header.n_data_u64s = sizeof (p.link_layer_option) / sizeof (u64);
2656 vlib_packet_template_init (vm,
2657 &im->discover_neighbor_packet_template,
2659 /* alloc chunk size */ 8,
2660 "ip6 neighbor discovery");
2663 error = ip6_feature_init (vm, im);
2668 VLIB_INIT_FUNCTION (ip6_lookup_init);
2670 static clib_error_t *
2671 add_del_ip6_interface_table (vlib_main_t * vm,
2672 unformat_input_t * input,
2673 vlib_cli_command_t * cmd)
2675 vnet_main_t * vnm = vnet_get_main();
2676 clib_error_t * error = 0;
2677 u32 sw_if_index, table_id;
2681 if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
2683 error = clib_error_return (0, "unknown interface `%U'",
2684 format_unformat_error, input);
2688 if (unformat (input, "%d", &table_id))
2692 error = clib_error_return (0, "expected table id `%U'",
2693 format_unformat_error, input);
2698 u32 fib_index = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP6,
2701 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
2702 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
2710 VLIB_CLI_COMMAND (set_interface_ip6_table_command, static) = {
2711 .path = "set interface ip6 table",
2712 .function = add_del_ip6_interface_table,
2713 .short_help = "set interface ip6 table <intfc> <table-id>"
2717 ip6_link_local_address_from_ethernet_mac_address (ip6_address_t *ip,
2720 ip->as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
2721 /* Invert the "u" bit */
2722 ip->as_u8 [8] = mac[0] ^ (1<<1);
2723 ip->as_u8 [9] = mac[1];
2724 ip->as_u8 [10] = mac[2];
2725 ip->as_u8 [11] = 0xFF;
2726 ip->as_u8 [12] = 0xFE;
2727 ip->as_u8 [13] = mac[3];
2728 ip->as_u8 [14] = mac[4];
2729 ip->as_u8 [15] = mac[5];
2733 ip6_ethernet_mac_address_from_link_local_address (u8 *mac,
2736 /* Invert the previously inverted "u" bit */
2737 mac[0] = ip->as_u8 [8] ^ (1<<1);
2738 mac[1] = ip->as_u8 [9];
2739 mac[2] = ip->as_u8 [10];
2740 mac[3] = ip->as_u8 [13];
2741 mac[4] = ip->as_u8 [14];
2742 mac[5] = ip->as_u8 [15];
2745 static clib_error_t *
2746 test_ip6_link_command_fn (vlib_main_t * vm,
2747 unformat_input_t * input,
2748 vlib_cli_command_t * cmd)
2751 ip6_address_t _a, *a = &_a;
2753 if (unformat (input, "%U", unformat_ethernet_address, mac))
2755 ip6_link_local_address_from_ethernet_mac_address (a, mac);
2756 vlib_cli_output (vm, "Link local address: %U",
2757 format_ip6_address, a);
2758 ip6_ethernet_mac_address_from_link_local_address (mac, a);
2759 vlib_cli_output (vm, "Original MAC address: %U",
2760 format_ethernet_address, mac);
2766 VLIB_CLI_COMMAND (test_link_command, static) = {
2767 .path = "test ip6 link",
2768 .function = test_ip6_link_command_fn,
2769 .short_help = "test ip6 link <mac-address>",
2772 int vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
2774 ip6_main_t * im6 = &ip6_main;
2776 uword * p = hash_get (im6->fib_index_by_table_id, table_id);
2781 fib = ip6_fib_get (p[0]);
2783 fib->flow_hash_config = flow_hash_config;
2787 static clib_error_t *
2788 set_ip6_flow_hash_command_fn (vlib_main_t * vm,
2789 unformat_input_t * input,
2790 vlib_cli_command_t * cmd)
2794 u32 flow_hash_config = 0;
2797 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
2798 if (unformat (input, "table %d", &table_id))
2801 else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
2802 foreach_flow_hash_bit
2808 return clib_error_return (0, "unknown input `%U'",
2809 format_unformat_error, input);
2811 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
2818 return clib_error_return (0, "no such FIB table %d", table_id);
2821 clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config);
2828 VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) = {
2829 .path = "set ip6 flow-hash",
2831 "set ip table flow-hash table <fib-id> src dst sport dport proto reverse",
2832 .function = set_ip6_flow_hash_command_fn,
2835 static clib_error_t *
2836 show_ip6_local_command_fn (vlib_main_t * vm,
2837 unformat_input_t * input,
2838 vlib_cli_command_t * cmd)
2840 ip6_main_t * im = &ip6_main;
2841 ip_lookup_main_t * lm = &im->lookup_main;
2844 vlib_cli_output (vm, "Protocols handled by ip6_local");
2845 for (i = 0; i < ARRAY_LEN(lm->local_next_by_ip_protocol); i++)
2847 if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
2848 vlib_cli_output (vm, "%d", i);
2855 VLIB_CLI_COMMAND (show_ip6_local, static) = {
2856 .path = "show ip6 local",
2857 .function = show_ip6_local_command_fn,
2858 .short_help = "Show ip6 local protocol table",
2861 int vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
2864 vnet_main_t * vnm = vnet_get_main();
2865 vnet_interface_main_t * im = &vnm->interface_main;
2866 ip6_main_t * ipm = &ip6_main;
2867 ip_lookup_main_t * lm = &ipm->lookup_main;
2868 vnet_classify_main_t * cm = &vnet_classify_main;
2870 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2871 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
2873 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
2874 return VNET_API_ERROR_NO_SUCH_ENTRY;
2876 vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index);
2877 lm->classify_table_index_by_sw_if_index [sw_if_index] = table_index;
2882 static clib_error_t *
2883 set_ip6_classify_command_fn (vlib_main_t * vm,
2884 unformat_input_t * input,
2885 vlib_cli_command_t * cmd)
2887 u32 table_index = ~0;
2888 int table_index_set = 0;
2889 u32 sw_if_index = ~0;
2892 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
2893 if (unformat (input, "table-index %d", &table_index))
2894 table_index_set = 1;
2895 else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
2896 vnet_get_main(), &sw_if_index))
2902 if (table_index_set == 0)
2903 return clib_error_return (0, "classify table-index must be specified");
2905 if (sw_if_index == ~0)
2906 return clib_error_return (0, "interface / subif must be specified");
2908 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
2915 case VNET_API_ERROR_NO_MATCHING_INTERFACE:
2916 return clib_error_return (0, "No such interface");
2918 case VNET_API_ERROR_NO_SUCH_ENTRY:
2919 return clib_error_return (0, "No such classifier table");
2924 VLIB_CLI_COMMAND (set_ip6_classify_command, static) = {
2925 .path = "set ip6 classify",
2927 "set ip6 classify intfc <int> table-index <index>",
2928 .function = set_ip6_classify_command_fn,
2931 static clib_error_t *
2932 ip6_config (vlib_main_t * vm, unformat_input_t * input)
2934 ip6_main_t * im = &ip6_main;
2939 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
2940 if (unformat (input, "hash-buckets %d", &tmp))
2942 else if (unformat (input, "heap-size %dm", &tmp))
2943 heapsize = ((u64)tmp) << 20;
2944 else if (unformat (input, "heap-size %dM", &tmp))
2945 heapsize = ((u64)tmp) << 20;
2946 else if (unformat (input, "heap-size %dg", &tmp))
2947 heapsize = ((u64)tmp) << 30;
2948 else if (unformat (input, "heap-size %dG", &tmp))
2949 heapsize = ((u64)tmp) << 30;
2951 return clib_error_return (0, "unknown input '%U'",
2952 format_unformat_error, input);
2955 im->lookup_table_nbuckets = nbuckets;
2956 im->lookup_table_size = heapsize;
2961 VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6");
2966 static clib_error_t *
2967 set_interface_ip6_output_feature_command_fn (vlib_main_t * vm,
2968 unformat_input_t * input,
2969 vlib_cli_command_t * cmd)
2971 vnet_main_t * vnm = vnet_get_main();
2972 u32 sw_if_index = ~0;
2974 ip6_main_t * im = &ip6_main;
2975 ip_lookup_main_t * lm = &im->lookup_main;
2977 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2979 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
2981 else if (unformat (input, "del"))
2987 if (sw_if_index == ~0)
2988 return clib_error_return (0, "unknown interface `%U'",
2989 format_unformat_error, input);
2991 lm->tx_sw_if_has_ip_output_features =
2992 clib_bitmap_set (lm->tx_sw_if_has_ip_output_features, sw_if_index, is_add);
2997 VLIB_CLI_COMMAND (set_interface_ip6_output_feature, static) = {
2998 .path = "set interface ip6 output feature",
2999 .function = set_interface_ip6_output_feature_command_fn,
3000 .short_help = "set interface output feature <intfc>",
3002 #endif /* TEST_CODE */