2 * Copyright (c) 2016 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/ip/ip_frag.h>
43 #include <vnet/ip/ip6_neighbor.h>
44 #include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
45 #include <vnet/srp/srp.h> /* for srp_hw_interface_class */
46 #include <vppinfra/cache.h>
47 #include <vnet/fib/fib_urpf_list.h> /* for FIB uRPF check */
48 #include <vnet/fib/ip6_fib.h>
49 #include <vnet/mfib/ip6_mfib.h>
50 #include <vnet/dpo/load_balance_map.h>
51 #include <vnet/dpo/classify_dpo.h>
53 #ifndef CLIB_MARCH_VARIANT
54 #include <vppinfra/bihash_template.c>
56 #include <vnet/ip/ip6_forward.h>
58 /* Flag used by IOAM code. Classifier sets it pop-hop-by-hop checks it */
59 #define OI_DECAP 0x80000000
62 ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index,
63 ip6_main_t * im, u32 fib_index,
64 ip_interface_address_t * a)
66 ip_lookup_main_t *lm = &im->lookup_main;
67 ip6_address_t *address = ip_interface_address_get_address (lm, a);
69 .fp_len = a->address_length,
70 .fp_proto = FIB_PROTOCOL_IP6,
71 .fp_addr.ip6 = *address,
74 if (a->address_length < 128)
76 fib_table_entry_update_one_path (fib_index,
79 (FIB_ENTRY_FLAG_CONNECTED |
80 FIB_ENTRY_FLAG_ATTACHED),
82 /* No next-hop address */
84 /* invalid FIB index */
87 NULL, FIB_ROUTE_PATH_FLAG_NONE);
91 if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
93 u32 classify_table_index =
94 lm->classify_table_index_by_sw_if_index[sw_if_index];
95 if (classify_table_index != (u32) ~ 0)
97 dpo_id_t dpo = DPO_INVALID;
102 classify_dpo_create (DPO_PROTO_IP6, classify_table_index));
104 fib_table_entry_special_dpo_add (fib_index,
107 FIB_ENTRY_FLAG_NONE, &dpo);
112 fib_table_entry_update_one_path (fib_index, &pfx,
113 FIB_SOURCE_INTERFACE,
114 (FIB_ENTRY_FLAG_CONNECTED |
115 FIB_ENTRY_FLAG_LOCAL),
119 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
123 ip6_del_interface_routes (ip6_main_t * im,
125 ip6_address_t * address, u32 address_length)
128 .fp_len = address_length,
129 .fp_proto = FIB_PROTOCOL_IP6,
130 .fp_addr.ip6 = *address,
133 if (pfx.fp_len < 128)
135 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
140 fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
143 #ifndef CLIB_MARCH_VARIANT
145 ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable)
147 ip6_main_t *im = &ip6_main;
149 vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0);
152 * enable/disable only on the 1<->0 transition
156 if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index])
161 /* The ref count is 0 when an address is removed from an interface that has
162 * no address - this is not a ciritical error */
163 if (0 == im->ip_enabled_by_sw_if_index[sw_if_index] ||
164 0 != --im->ip_enabled_by_sw_if_index[sw_if_index])
168 vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
171 vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
172 sw_if_index, !is_enable, 0, 0);
175 /* get first interface address */
177 ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
179 ip_lookup_main_t *lm = &im->lookup_main;
180 ip_interface_address_t *ia = 0;
181 ip6_address_t *result = 0;
184 foreach_ip_interface_address (lm, ia, sw_if_index,
185 1 /* honor unnumbered */,
187 ip6_address_t * a = ip_interface_address_get_address (lm, ia);
196 ip6_add_del_interface_address (vlib_main_t * vm,
198 ip6_address_t * address,
199 u32 address_length, u32 is_del)
201 vnet_main_t *vnm = vnet_get_main ();
202 ip6_main_t *im = &ip6_main;
203 ip_lookup_main_t *lm = &im->lookup_main;
205 u32 if_address_index;
206 ip6_address_fib_t ip6_af, *addr_fib = 0;
207 ip6_address_t ll_addr;
209 /* local0 interface doesn't support IP addressing */
210 if (sw_if_index == 0)
213 clib_error_create ("local0 interface doesn't support IP addressing");
216 if (ip6_address_is_link_local_unicast (address))
218 if (address_length != 128)
220 vnm->api_errno = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
223 ("prefix length of link-local address must be 128");
227 return ip6_neighbor_set_link_local_address (vm, sw_if_index,
232 ll_addr = ip6_neighbor_get_link_local_address (sw_if_index);
233 if (ip6_address_is_equal (&ll_addr, address))
235 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_DELETABLE;
236 return clib_error_create ("address not deletable");
240 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
241 return clib_error_create ("address not found");
246 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
247 vec_validate (im->mfib_index_by_sw_if_index, sw_if_index);
249 ip6_addr_fib_init (&ip6_af, address,
250 vec_elt (im->fib_index_by_sw_if_index, sw_if_index));
251 vec_add1 (addr_fib, ip6_af);
256 /* When adding an address check that it does not conflict
257 with an existing address on any interface in this table. */
258 ip_interface_address_t *ia;
259 vnet_sw_interface_t *sif;
261 pool_foreach(sif, vnm->interface_main.sw_interfaces,
263 if (im->fib_index_by_sw_if_index[sw_if_index] ==
264 im->fib_index_by_sw_if_index[sif->sw_if_index])
266 foreach_ip_interface_address
267 (&im->lookup_main, ia, sif->sw_if_index,
268 0 /* honor unnumbered */ ,
271 ip_interface_address_get_address
272 (&im->lookup_main, ia);
273 if (ip6_destination_matches_route
274 (im, address, x, ia->address_length) ||
275 ip6_destination_matches_route (im,
280 vnm->api_errno = VNET_API_ERROR_DUPLICATE_IF_ADDRESS;
283 ("failed to add %U which conflicts with %U for interface %U",
284 format_ip6_address_and_length, address,
286 format_ip6_address_and_length, x,
288 format_vnet_sw_if_index_name, vnm,
298 uword elts_before = pool_elts (lm->if_address_pool);
300 error = ip_interface_address_add_del
301 (lm, sw_if_index, addr_fib, address_length, is_del, &if_address_index);
305 /* Pool did not grow: add duplicate address. */
306 if (elts_before == pool_elts (lm->if_address_pool))
310 ip6_sw_interface_enable_disable (sw_if_index, !is_del);
313 ip6_del_interface_routes (im, ip6_af.fib_index, address, address_length);
315 ip6_add_interface_routes (vnm, sw_if_index,
316 im, ip6_af.fib_index,
317 pool_elt_at_index (lm->if_address_pool,
321 ip6_add_del_interface_address_callback_t *cb;
322 vec_foreach (cb, im->add_del_interface_address_callbacks)
323 cb->function (im, cb->function_opaque, sw_if_index,
324 address, address_length, if_address_index, is_del);
334 static clib_error_t *
335 ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
337 ip6_main_t *im = &ip6_main;
338 ip_interface_address_t *ia;
340 u32 is_admin_up, fib_index;
342 /* Fill in lookup tables with default table (0). */
343 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
345 vec_validate_init_empty (im->
346 lookup_main.if_address_pool_index_by_sw_if_index,
349 is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
351 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
354 foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
355 0 /* honor unnumbered */,
357 a = ip_interface_address_get_address (&im->lookup_main, ia);
359 ip6_add_interface_routes (vnm, sw_if_index,
363 ip6_del_interface_routes (im, fib_index,
364 a, ia->address_length);
371 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
373 /* Built-in ip6 unicast rx feature path definition */
375 VNET_FEATURE_ARC_INIT (ip6_unicast, static) =
377 .arc_name = "ip6-unicast",
378 .start_nodes = VNET_FEATURES ("ip6-input"),
379 .last_in_arc = "ip6-lookup",
380 .arc_index_ptr = &ip6_main.lookup_main.ucast_feature_arc_index,
383 VNET_FEATURE_INIT (ip6_flow_classify, static) =
385 .arc_name = "ip6-unicast",
386 .node_name = "ip6-flow-classify",
387 .runs_before = VNET_FEATURES ("ip6-inacl"),
390 VNET_FEATURE_INIT (ip6_inacl, static) =
392 .arc_name = "ip6-unicast",
393 .node_name = "ip6-inacl",
394 .runs_before = VNET_FEATURES ("ip6-policer-classify"),
397 VNET_FEATURE_INIT (ip6_policer_classify, static) =
399 .arc_name = "ip6-unicast",
400 .node_name = "ip6-policer-classify",
401 .runs_before = VNET_FEATURES ("ipsec6-input-feature"),
404 VNET_FEATURE_INIT (ip6_ipsec, static) =
406 .arc_name = "ip6-unicast",
407 .node_name = "ipsec6-input-feature",
408 .runs_before = VNET_FEATURES ("l2tp-decap"),
411 VNET_FEATURE_INIT (ip6_l2tp, static) =
413 .arc_name = "ip6-unicast",
414 .node_name = "l2tp-decap",
415 .runs_before = VNET_FEATURES ("vpath-input-ip6"),
418 VNET_FEATURE_INIT (ip6_vpath, static) =
420 .arc_name = "ip6-unicast",
421 .node_name = "vpath-input-ip6",
422 .runs_before = VNET_FEATURES ("ip6-vxlan-bypass"),
425 VNET_FEATURE_INIT (ip6_vxlan_bypass, static) =
427 .arc_name = "ip6-unicast",
428 .node_name = "ip6-vxlan-bypass",
429 .runs_before = VNET_FEATURES ("ip6-lookup"),
432 VNET_FEATURE_INIT (ip6_not_enabled, static) =
434 .arc_name = "ip6-unicast",
435 .node_name = "ip6-not-enabled",
436 .runs_before = VNET_FEATURES ("ip6-lookup"),
439 VNET_FEATURE_INIT (ip6_lookup, static) =
441 .arc_name = "ip6-unicast",
442 .node_name = "ip6-lookup",
443 .runs_before = 0, /*last feature*/
446 /* Built-in ip6 multicast rx feature path definition (none now) */
447 VNET_FEATURE_ARC_INIT (ip6_multicast, static) =
449 .arc_name = "ip6-multicast",
450 .start_nodes = VNET_FEATURES ("ip6-input"),
451 .last_in_arc = "ip6-mfib-forward-lookup",
452 .arc_index_ptr = &ip6_main.lookup_main.mcast_feature_arc_index,
455 VNET_FEATURE_INIT (ip6_vpath_mc, static) = {
456 .arc_name = "ip6-multicast",
457 .node_name = "vpath-input-ip6",
458 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
461 VNET_FEATURE_INIT (ip6_not_enabled_mc, static) = {
462 .arc_name = "ip6-multicast",
463 .node_name = "ip6-not-enabled",
464 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
467 VNET_FEATURE_INIT (ip6_mc_lookup, static) = {
468 .arc_name = "ip6-multicast",
469 .node_name = "ip6-mfib-forward-lookup",
470 .runs_before = 0, /* last feature */
473 /* Built-in ip4 tx feature path definition */
474 VNET_FEATURE_ARC_INIT (ip6_output, static) =
476 .arc_name = "ip6-output",
477 .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain", "ip6-dvr-dpo"),
478 .last_in_arc = "interface-output",
479 .arc_index_ptr = &ip6_main.lookup_main.output_feature_arc_index,
482 VNET_FEATURE_INIT (ip6_outacl, static) = {
483 .arc_name = "ip6-output",
484 .node_name = "ip6-outacl",
485 .runs_before = VNET_FEATURES ("ipsec6-output-feature"),
488 VNET_FEATURE_INIT (ip6_ipsec_output, static) = {
489 .arc_name = "ip6-output",
490 .node_name = "ipsec6-output-feature",
491 .runs_before = VNET_FEATURES ("interface-output"),
494 VNET_FEATURE_INIT (ip6_interface_output, static) = {
495 .arc_name = "ip6-output",
496 .node_name = "interface-output",
497 .runs_before = 0, /* not before any other features */
501 static clib_error_t *
502 ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
504 ip6_main_t *im = &ip6_main;
506 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
507 vec_validate (im->mfib_index_by_sw_if_index, sw_if_index);
511 /* Ensure that IPv6 is disabled */
512 ip6_main_t *im6 = &ip6_main;
513 ip_lookup_main_t *lm6 = &im6->lookup_main;
514 ip_interface_address_t *ia = 0;
515 ip6_address_t *address;
516 vlib_main_t *vm = vlib_get_main ();
518 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, 0 /* is_add */ );
519 vnet_sw_interface_update_unnumbered (sw_if_index, ~0, 0);
521 foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
523 address = ip_interface_address_get_address (lm6, ia);
524 ip6_add_del_interface_address(vm, sw_if_index, address, ia->address_length, 1);
527 ip6_mfib_interface_enable_disable (sw_if_index, 0);
530 vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
533 vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
534 sw_if_index, is_add, 0, 0);
536 return /* no error */ 0;
539 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del);
541 VLIB_NODE_FN (ip6_lookup_node) (vlib_main_t * vm,
542 vlib_node_runtime_t * node,
543 vlib_frame_t * frame)
545 return ip6_lookup_inline (vm, node, frame);
548 static u8 *format_ip6_lookup_trace (u8 * s, va_list * args);
551 VLIB_REGISTER_NODE (ip6_lookup_node) =
553 .name = "ip6-lookup",
554 .vector_size = sizeof (u32),
555 .format_trace = format_ip6_lookup_trace,
556 .n_next_nodes = IP6_LOOKUP_N_NEXT,
557 .next_nodes = IP6_LOOKUP_NEXT_NODES,
561 VLIB_NODE_FN (ip6_load_balance_node) (vlib_main_t * vm,
562 vlib_node_runtime_t * node,
563 vlib_frame_t * frame)
565 vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters;
566 u32 n_left_from, n_left_to_next, *from, *to_next;
567 ip_lookup_next_t next;
568 u32 thread_index = vm->thread_index;
569 ip6_main_t *im = &ip6_main;
571 from = vlib_frame_vector_args (frame);
572 n_left_from = frame->n_vectors;
573 next = node->cached_next_index;
575 while (n_left_from > 0)
577 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
580 while (n_left_from >= 4 && n_left_to_next >= 2)
582 ip_lookup_next_t next0, next1;
583 const load_balance_t *lb0, *lb1;
584 vlib_buffer_t *p0, *p1;
585 u32 pi0, lbi0, hc0, pi1, lbi1, hc1;
586 const ip6_header_t *ip0, *ip1;
587 const dpo_id_t *dpo0, *dpo1;
589 /* Prefetch next iteration. */
591 vlib_buffer_t *p2, *p3;
593 p2 = vlib_get_buffer (vm, from[2]);
594 p3 = vlib_get_buffer (vm, from[3]);
596 vlib_prefetch_buffer_header (p2, STORE);
597 vlib_prefetch_buffer_header (p3, STORE);
599 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
600 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
603 pi0 = to_next[0] = from[0];
604 pi1 = to_next[1] = from[1];
611 p0 = vlib_get_buffer (vm, pi0);
612 p1 = vlib_get_buffer (vm, pi1);
614 ip0 = vlib_buffer_get_current (p0);
615 ip1 = vlib_buffer_get_current (p1);
616 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
617 lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
619 lb0 = load_balance_get (lbi0);
620 lb1 = load_balance_get (lbi1);
623 * this node is for via FIBs we can re-use the hash value from the
624 * to node if present.
625 * We don't want to use the same hash value at each level in the recursion
626 * graph as that would lead to polarisation
630 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
632 if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
634 hc0 = vnet_buffer (p0)->ip.flow_hash =
635 vnet_buffer (p0)->ip.flow_hash >> 1;
639 hc0 = vnet_buffer (p0)->ip.flow_hash =
640 ip6_compute_flow_hash (ip0, lb0->lb_hash_config);
643 load_balance_get_fwd_bucket (lb0,
645 lb0->lb_n_buckets_minus_1));
649 dpo0 = load_balance_get_bucket_i (lb0, 0);
651 if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
653 if (PREDICT_TRUE (vnet_buffer (p1)->ip.flow_hash))
655 hc1 = vnet_buffer (p1)->ip.flow_hash =
656 vnet_buffer (p1)->ip.flow_hash >> 1;
660 hc1 = vnet_buffer (p1)->ip.flow_hash =
661 ip6_compute_flow_hash (ip1, lb1->lb_hash_config);
664 load_balance_get_fwd_bucket (lb1,
666 lb1->lb_n_buckets_minus_1));
670 dpo1 = load_balance_get_bucket_i (lb1, 0);
673 next0 = dpo0->dpoi_next_node;
674 next1 = dpo1->dpoi_next_node;
676 /* Only process the HBH Option Header if explicitly configured to do so */
678 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
680 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
681 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
683 /* Only process the HBH Option Header if explicitly configured to do so */
685 (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
687 next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ?
688 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1;
691 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
692 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
694 vlib_increment_combined_counter
695 (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
696 vlib_increment_combined_counter
697 (cm, thread_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
699 vlib_validate_buffer_enqueue_x2 (vm, node, next,
700 to_next, n_left_to_next,
701 pi0, pi1, next0, next1);
704 while (n_left_from > 0 && n_left_to_next > 0)
706 ip_lookup_next_t next0;
707 const load_balance_t *lb0;
710 const ip6_header_t *ip0;
711 const dpo_id_t *dpo0;
720 p0 = vlib_get_buffer (vm, pi0);
722 ip0 = vlib_buffer_get_current (p0);
723 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
725 lb0 = load_balance_get (lbi0);
728 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
730 if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash))
732 hc0 = vnet_buffer (p0)->ip.flow_hash =
733 vnet_buffer (p0)->ip.flow_hash >> 1;
737 hc0 = vnet_buffer (p0)->ip.flow_hash =
738 ip6_compute_flow_hash (ip0, lb0->lb_hash_config);
741 load_balance_get_fwd_bucket (lb0,
743 lb0->lb_n_buckets_minus_1));
747 dpo0 = load_balance_get_bucket_i (lb0, 0);
750 next0 = dpo0->dpoi_next_node;
751 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
753 /* Only process the HBH Option Header if explicitly configured to do so */
755 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
757 next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ?
758 (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0;
761 vlib_increment_combined_counter
762 (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
764 vlib_validate_buffer_enqueue_x1 (vm, node, next,
765 to_next, n_left_to_next,
769 vlib_put_next_frame (vm, node, next, n_left_to_next);
772 if (node->flags & VLIB_NODE_FLAG_TRACE)
773 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
775 return frame->n_vectors;
779 VLIB_REGISTER_NODE (ip6_load_balance_node) =
781 .name = "ip6-load-balance",
782 .vector_size = sizeof (u32),
783 .sibling_of = "ip6-lookup",
784 .format_trace = format_ip6_lookup_trace,
790 /* Adjacency taken. */
795 /* Packet data, possibly *after* rewrite. */
796 u8 packet_data[128 - 1 * sizeof (u32)];
798 ip6_forward_next_trace_t;
800 #ifndef CLIB_MARCH_VARIANT
802 format_ip6_forward_next_trace (u8 * s, va_list * args)
804 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
805 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
806 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
807 u32 indent = format_get_indent (s);
809 s = format (s, "%U%U",
810 format_white_space, indent,
811 format_ip6_header, t->packet_data, sizeof (t->packet_data));
817 format_ip6_lookup_trace (u8 * s, va_list * args)
819 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
820 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
821 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
822 u32 indent = format_get_indent (s);
824 s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
825 t->fib_index, t->adj_index, t->flow_hash);
826 s = format (s, "\n%U%U",
827 format_white_space, indent,
828 format_ip6_header, t->packet_data, sizeof (t->packet_data));
834 format_ip6_rewrite_trace (u8 * s, va_list * args)
836 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
837 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
838 ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *);
839 u32 indent = format_get_indent (s);
841 s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
842 t->fib_index, t->adj_index, format_ip_adjacency,
843 t->adj_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash);
844 s = format (s, "\n%U%U",
845 format_white_space, indent,
846 format_ip_adjacency_packet_data,
847 t->adj_index, t->packet_data, sizeof (t->packet_data));
851 /* Common trace function for all ip6-forward next nodes. */
852 #ifndef CLIB_MARCH_VARIANT
854 ip6_forward_next_trace (vlib_main_t * vm,
855 vlib_node_runtime_t * node,
856 vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index)
859 ip6_main_t *im = &ip6_main;
861 n_left = frame->n_vectors;
862 from = vlib_frame_vector_args (frame);
867 vlib_buffer_t *b0, *b1;
868 ip6_forward_next_trace_t *t0, *t1;
870 /* Prefetch next iteration. */
871 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
872 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
877 b0 = vlib_get_buffer (vm, bi0);
878 b1 = vlib_get_buffer (vm, bi1);
880 if (b0->flags & VLIB_BUFFER_IS_TRACED)
882 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
883 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
884 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
886 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
887 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
888 vec_elt (im->fib_index_by_sw_if_index,
889 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
891 clib_memcpy_fast (t0->packet_data,
892 vlib_buffer_get_current (b0),
893 sizeof (t0->packet_data));
895 if (b1->flags & VLIB_BUFFER_IS_TRACED)
897 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
898 t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
899 t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
901 (vnet_buffer (b1)->sw_if_index[VLIB_TX] !=
902 (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] :
903 vec_elt (im->fib_index_by_sw_if_index,
904 vnet_buffer (b1)->sw_if_index[VLIB_RX]);
906 clib_memcpy_fast (t1->packet_data,
907 vlib_buffer_get_current (b1),
908 sizeof (t1->packet_data));
918 ip6_forward_next_trace_t *t0;
922 b0 = vlib_get_buffer (vm, bi0);
924 if (b0->flags & VLIB_BUFFER_IS_TRACED)
926 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
927 t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
928 t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
930 (vnet_buffer (b0)->sw_if_index[VLIB_TX] !=
931 (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] :
932 vec_elt (im->fib_index_by_sw_if_index,
933 vnet_buffer (b0)->sw_if_index[VLIB_RX]);
935 clib_memcpy_fast (t0->packet_data,
936 vlib_buffer_get_current (b0),
937 sizeof (t0->packet_data));
944 /* Compute TCP/UDP/ICMP6 checksum in software. */
946 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
947 ip6_header_t * ip0, int *bogus_lengthp)
950 u16 sum16, payload_length_host_byte_order;
951 u32 i, n_this_buffer, n_bytes_left;
952 u32 headers_size = sizeof (ip0[0]);
953 void *data_this_buffer;
955 ASSERT (bogus_lengthp);
958 /* Initialize checksum with ip header. */
959 sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol);
960 payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
961 data_this_buffer = (void *) (ip0 + 1);
963 for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
965 sum0 = ip_csum_with_carry (sum0,
966 clib_mem_unaligned (&ip0->
967 src_address.as_uword[i],
970 ip_csum_with_carry (sum0,
971 clib_mem_unaligned (&ip0->dst_address.as_uword[i],
975 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets)
976 * or UDP-Ping packets */
977 if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
980 ip6_hop_by_hop_ext_t *ext_hdr =
981 (ip6_hop_by_hop_ext_t *) data_this_buffer;
983 /* validate really icmp6 next */
984 ASSERT ((ext_hdr->next_hdr == IP_PROTOCOL_ICMP6)
985 || (ext_hdr->next_hdr == IP_PROTOCOL_UDP));
987 skip_bytes = 8 * (1 + ext_hdr->n_data_u64s);
988 data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes);
990 payload_length_host_byte_order -= skip_bytes;
991 headers_size += skip_bytes;
994 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
995 if (p0 && n_this_buffer + headers_size > p0->current_length)
998 headers_size ? p0->current_length - headers_size : 0;
1001 sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
1002 n_bytes_left -= n_this_buffer;
1003 if (n_bytes_left == 0)
1006 if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
1011 p0 = vlib_get_buffer (vm, p0->next_buffer);
1012 data_this_buffer = vlib_buffer_get_current (p0);
1013 n_this_buffer = p0->current_length;
1016 sum16 = ~ip_csum_fold (sum0);
1022 ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0)
1024 ip6_header_t *ip0 = vlib_buffer_get_current (p0);
1029 /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
1030 ASSERT (ip0->protocol == IP_PROTOCOL_TCP
1031 || ip0->protocol == IP_PROTOCOL_ICMP6
1032 || ip0->protocol == IP_PROTOCOL_UDP
1033 || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
1035 udp0 = (void *) (ip0 + 1);
1036 if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0)
1038 p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED
1039 | VNET_BUFFER_F_L4_CHECKSUM_CORRECT);
1043 sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length);
1045 p0->flags |= (VNET_BUFFER_F_L4_CHECKSUM_COMPUTED
1046 | ((sum16 == 0) << VNET_BUFFER_F_LOG2_L4_CHECKSUM_CORRECT));
1053 * @brief returns number of links on which src is reachable.
1056 ip6_urpf_loose_check (ip6_main_t * im, vlib_buffer_t * b, ip6_header_t * i)
1058 const load_balance_t *lb0;
1062 fib_index = vec_elt (im->fib_index_by_sw_if_index,
1063 vnet_buffer (b)->sw_if_index[VLIB_RX]);
1065 (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
1066 fib_index : vnet_buffer (b)->sw_if_index[VLIB_TX];
1068 lbi = ip6_fib_table_fwding_lookup (im, fib_index, &i->src_address);
1069 lb0 = load_balance_get (lbi);
1071 return (fib_urpf_check_size (lb0->lb_urpf));
1075 ip6_next_proto_is_tcp_udp (vlib_buffer_t * p0, ip6_header_t * ip0,
1079 proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_UDP, udp_offset0);
1080 if (proto0 != IP_PROTOCOL_UDP)
1082 proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_TCP, udp_offset0);
1083 proto0 = (proto0 == IP_PROTOCOL_TCP) ? proto0 : 0;
1089 VNET_FEATURE_ARC_INIT (ip6_local) =
1091 .arc_name = "ip6-local",
1092 .start_nodes = VNET_FEATURES ("ip6-local"),
1097 ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1098 vlib_frame_t * frame, int head_of_feature_arc)
1100 ip6_main_t *im = &ip6_main;
1101 ip_lookup_main_t *lm = &im->lookup_main;
1102 u32 *from, n_left_from;
1103 vlib_node_runtime_t *error_node =
1104 vlib_node_get_runtime (vm, ip6_input_node.index);
1105 u8 arc_index = vnet_feat_arc_ip6_local.feature_arc_index;
1106 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1107 u16 nexts[VLIB_FRAME_SIZE], *next;
1109 from = vlib_frame_vector_args (frame);
1110 n_left_from = frame->n_vectors;
1112 if (node->flags & VLIB_NODE_FLAG_TRACE)
1113 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1115 vlib_get_buffers (vm, from, bufs, n_left_from);
1120 #define xN for (int n=0; n<N; n++)
1122 while (n_left_from > N)
1124 /* Prefetch next iteration. */
1125 if (n_left_from >= 3 * N)
1127 xN vlib_prefetch_buffer_header (b[2 * N + n], STORE);
1128 xN vlib_prefetch_buffer_data (b[1 * N + n], LOAD);
1132 xN error[n] = IP6_ERROR_UNKNOWN_PROTOCOL;
1134 ip6_header_t *ip[N];
1135 xN ip[n] = vlib_buffer_get_current (b[n]);
1137 if (head_of_feature_arc)
1139 xN vnet_buffer (b[n])->l3_hdr_offset = b[n]->current_data;
1142 xN type[n] = lm->builtin_protocol_by_ip_protocol[ip[n]->protocol];
1145 xN flags[n] = b[n]->flags;
1147 u32 good_l4_csum[N];
1148 xN good_l4_csum[n] =
1149 flags[n] & (VNET_BUFFER_F_L4_CHECKSUM_CORRECT |
1150 VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
1151 VNET_BUFFER_F_OFFLOAD_UDP_CKSUM);
1156 ip6_next_proto_is_tcp_udp (b[n], ip[n], &udp_offset[n]);
1157 i16 len_diff[N] = { 0 };
1158 xN if (PREDICT_TRUE (is_tcp_udp[n]))
1161 (udp_header_t *) ((u8 *) ip[n] + udp_offset[n]);
1162 good_l4_csum[n] |= type[n] == IP_BUILTIN_PROTOCOL_UDP
1163 && udp->checksum == 0;
1164 /* optimistically verify UDP length. */
1165 u16 ip_len, udp_len;
1166 ip_len = clib_net_to_host_u16 (ip[n]->payload_length);
1167 udp_len = clib_net_to_host_u16 (udp->length);
1168 len_diff[n] = ip_len - udp_len;
1171 xN good_l4_csum[n] |= type[n] == IP_BUILTIN_PROTOCOL_UNKNOWN;
1173 type[n] == IP_BUILTIN_PROTOCOL_UDP ? len_diff[n] : 0;
1176 xN need_csum[n] = type[n] != IP_BUILTIN_PROTOCOL_UNKNOWN
1178 && !(flags[n] & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED);
1179 xN if (PREDICT_FALSE (need_csum[n]))
1181 flags[n] = ip6_tcp_udp_icmp_validate_checksum (vm, b[n]);
1182 good_l4_csum[n] = flags[n] & VNET_BUFFER_F_L4_CHECKSUM_CORRECT;
1185 xN error[n] = IP6_ERROR_UNKNOWN_PROTOCOL;
1186 xN error[n] = len_diff[n] < 0 ? IP6_ERROR_UDP_LENGTH : error[n];
1188 STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1189 IP6_ERROR_UDP_CHECKSUM,
1190 "Wrong IP6 errors constants");
1191 STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1192 IP6_ERROR_ICMP_CHECKSUM,
1193 "Wrong IP6 errors constants");
1196 !good_l4_csum[n] ? IP6_ERROR_UDP_CHECKSUM + type[n] : error[n];
1198 /* Drop packets from unroutable hosts. */
1199 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
1201 xN unroutable[n] = error[n] == IP6_ERROR_UNKNOWN_PROTOCOL
1202 && type[n] != IP_BUILTIN_PROTOCOL_ICMP
1203 && !ip6_address_is_link_local_unicast (&ip[n]->src_address);
1204 xN if (PREDICT_FALSE (unroutable[n]))
1207 !ip6_urpf_loose_check (im, b[n],
1208 ip[n]) ? IP6_ERROR_SRC_LOOKUP_MISS
1212 xN vnet_buffer (b[n])->ip.fib_index =
1213 vnet_buffer (b[n])->sw_if_index[VLIB_TX] != ~0 ?
1214 vnet_buffer (b[n])->sw_if_index[VLIB_TX] :
1215 vnet_buffer (b[n])->ip.fib_index;
1216 } /* head_of_feature_arc */
1218 xN next[n] = lm->local_next_by_ip_protocol[ip[n]->protocol];
1220 error[n] != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next[n];
1222 xN b[n]->error = error_node->errors[n];
1224 if (head_of_feature_arc)
1227 xN ip6_unknown[n] = error[n] == (u8) IP6_ERROR_UNKNOWN_PROTOCOL;
1228 xN if (PREDICT_TRUE (ip6_unknown[n]))
1230 u32 next32 = next[n];
1231 vnet_feature_arc_start (arc_index,
1232 vnet_buffer (b[n])->sw_if_index
1233 [VLIB_RX], &next32, b[n]);
1248 error = IP6_ERROR_UNKNOWN_PROTOCOL;
1251 ip = vlib_buffer_get_current (b[0]);
1253 if (head_of_feature_arc)
1255 vnet_buffer (b[0])->l3_hdr_offset = b[0]->current_data;
1256 u8 type = lm->builtin_protocol_by_ip_protocol[ip->protocol];
1258 u32 flags = b[0]->flags;
1260 flags & (VNET_BUFFER_F_L4_CHECKSUM_CORRECT |
1261 VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
1262 VNET_BUFFER_F_OFFLOAD_UDP_CKSUM);
1266 u8 is_tcp_udp = ip6_next_proto_is_tcp_udp (b[0], ip, &udp_offset);
1267 if (PREDICT_TRUE (is_tcp_udp))
1269 udp_header_t *udp = (udp_header_t *) ((u8 *) ip + udp_offset);
1270 /* Don't verify UDP checksum for packets with explicit zero checksum. */
1271 good_l4_csum |= type == IP_BUILTIN_PROTOCOL_UDP
1272 && udp->checksum == 0;
1273 /* optimistically verify UDP length. */
1274 u16 ip_len, udp_len;
1275 ip_len = clib_net_to_host_u16 (ip->payload_length);
1276 udp_len = clib_net_to_host_u16 (udp->length);
1277 len_diff = ip_len - udp_len;
1280 good_l4_csum |= type == IP_BUILTIN_PROTOCOL_UNKNOWN;
1281 len_diff = type == IP_BUILTIN_PROTOCOL_UDP ? len_diff : 0;
1283 u8 need_csum = type != IP_BUILTIN_PROTOCOL_UNKNOWN && !good_l4_csum
1284 && !(flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED);
1285 if (PREDICT_FALSE (need_csum))
1287 flags = ip6_tcp_udp_icmp_validate_checksum (vm, b[0]);
1288 good_l4_csum = flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT;
1291 error = IP6_ERROR_UNKNOWN_PROTOCOL;
1292 error = len_diff < 0 ? IP6_ERROR_UDP_LENGTH : error;
1294 STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP ==
1295 IP6_ERROR_UDP_CHECKSUM,
1296 "Wrong IP6 errors constants");
1297 STATIC_ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP ==
1298 IP6_ERROR_ICMP_CHECKSUM,
1299 "Wrong IP6 errors constants");
1301 error = !good_l4_csum ? IP6_ERROR_UDP_CHECKSUM + type : error;
1303 /* Drop packets from unroutable hosts. */
1304 /* If this is a neighbor solicitation (ICMP), skip source RPF check */
1305 u8 unroutable = error == IP6_ERROR_UNKNOWN_PROTOCOL
1306 && type != IP_BUILTIN_PROTOCOL_ICMP
1307 && !ip6_address_is_link_local_unicast (&ip->src_address);
1308 if (PREDICT_FALSE (unroutable))
1311 !ip6_urpf_loose_check (im, b[0],
1312 ip) ? IP6_ERROR_SRC_LOOKUP_MISS :
1316 vnet_buffer (b[0])->ip.fib_index =
1317 vnet_buffer (b[0])->sw_if_index[VLIB_TX] != ~0 ?
1318 vnet_buffer (b[0])->sw_if_index[VLIB_TX] :
1319 vnet_buffer (b[0])->ip.fib_index;
1320 } /* head_of_feature_arc */
1322 next[0] = lm->local_next_by_ip_protocol[ip->protocol];
1324 error != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next[0];
1326 b[0]->error = error_node->errors[0];
1328 if (head_of_feature_arc)
1330 if (PREDICT_TRUE (error == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
1332 u32 next32 = next[0];
1333 vnet_feature_arc_start (arc_index,
1334 vnet_buffer (b[0])->sw_if_index
1335 [VLIB_RX], &next32, b[0]);
1346 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
1347 return frame->n_vectors;
1350 VLIB_NODE_FN (ip6_local_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
1351 vlib_frame_t * frame)
1353 return ip6_local_inline (vm, node, frame, 1 /* head of feature arc */ );
1357 VLIB_REGISTER_NODE (ip6_local_node) =
1359 .name = "ip6-local",
1360 .vector_size = sizeof (u32),
1361 .format_trace = format_ip6_forward_next_trace,
1362 .n_next_nodes = IP_LOCAL_N_NEXT,
1365 [IP_LOCAL_NEXT_DROP] = "ip6-drop",
1366 [IP_LOCAL_NEXT_PUNT] = "ip6-punt",
1367 [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
1368 [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
1369 [IP_LOCAL_NEXT_REASSEMBLY] = "ip6-reassembly",
1374 VLIB_NODE_FN (ip6_local_end_of_arc_node) (vlib_main_t * vm,
1375 vlib_node_runtime_t * node,
1376 vlib_frame_t * frame)
1378 return ip6_local_inline (vm, node, frame, 0 /* head of feature arc */ );
1382 VLIB_REGISTER_NODE (ip6_local_end_of_arc_node) = {
1383 .name = "ip6-local-end-of-arc",
1384 .vector_size = sizeof (u32),
1386 .format_trace = format_ip6_forward_next_trace,
1387 .sibling_of = "ip6-local",
1390 VNET_FEATURE_INIT (ip6_local_end_of_arc, static) = {
1391 .arc_name = "ip6-local",
1392 .node_name = "ip6-local-end-of-arc",
1393 .runs_before = 0, /* not before any other features */
1397 #ifdef CLIB_MARCH_VARIANT
1398 extern vlib_node_registration_t ip6_local_node;
1403 ip6_register_protocol (u32 protocol, u32 node_index)
1405 vlib_main_t *vm = vlib_get_main ();
1406 ip6_main_t *im = &ip6_main;
1407 ip_lookup_main_t *lm = &im->lookup_main;
1409 ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
1410 lm->local_next_by_ip_protocol[protocol] =
1411 vlib_node_add_next (vm, ip6_local_node.index, node_index);
1415 ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index,
1418 vnet_main_t *vnm = vnet_get_main ();
1419 ip6_main_t *im = &ip6_main;
1420 icmp6_neighbor_solicitation_header_t *h;
1422 ip_interface_address_t *ia;
1423 ip_adjacency_t *adj;
1424 vnet_hw_interface_t *hi;
1425 vnet_sw_interface_t *si;
1431 si = vnet_get_sw_interface (vnm, sw_if_index);
1433 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
1435 return clib_error_return (0, "%U: interface %U down",
1436 format_ip6_address, dst,
1437 format_vnet_sw_if_index_name, vnm,
1442 ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia);
1445 vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE;
1446 return clib_error_return
1447 (0, "no matching interface address for destination %U (interface %U)",
1448 format_ip6_address, dst,
1449 format_vnet_sw_if_index_name, vnm, sw_if_index);
1453 vlib_packet_template_get_packet (vm,
1454 &im->discover_neighbor_packet_template,
1457 return clib_error_return (0, "ICMP6 NS packet allocation failed");
1459 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
1461 /* Destination address is a solicited node multicast address. We need to fill in
1462 the low 24 bits with low 24 bits of target's address. */
1463 h->ip.dst_address.as_u8[13] = dst->as_u8[13];
1464 h->ip.dst_address.as_u8[14] = dst->as_u8[14];
1465 h->ip.dst_address.as_u8[15] = dst->as_u8[15];
1467 h->ip.src_address = src[0];
1468 h->neighbor.target_address = dst[0];
1470 if (PREDICT_FALSE (!hi->hw_address))
1472 return clib_error_return (0, "%U: interface %U do not support ip probe",
1473 format_ip6_address, dst,
1474 format_vnet_sw_if_index_name, vnm,
1478 clib_memcpy_fast (h->link_layer_option.ethernet_address, hi->hw_address,
1479 vec_len (hi->hw_address));
1481 h->neighbor.icmp.checksum =
1482 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
1483 ASSERT (bogus_length == 0);
1485 b = vlib_get_buffer (vm, bi);
1486 vnet_buffer (b)->sw_if_index[VLIB_RX] =
1487 vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
1489 /* Add encapsulation string for software interface (e.g. ethernet header). */
1490 ip46_address_t nh = {
1494 ai = adj_nbr_add_or_lock (FIB_PROTOCOL_IP6,
1495 VNET_LINK_IP6, &nh, sw_if_index);
1498 /* Peer has been previously resolved, retrieve glean adj instead */
1499 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE && refresh == 0)
1502 ai = adj_glean_add_or_lock (FIB_PROTOCOL_IP6,
1503 VNET_LINK_IP6, sw_if_index, &nh);
1507 vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
1508 vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
1511 vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
1512 u32 *to_next = vlib_frame_vector_args (f);
1515 vlib_put_frame_to_node (vm, hi->output_node_index, f);
1519 return /* no error */ 0;
1525 IP6_REWRITE_NEXT_DROP,
1526 IP6_REWRITE_NEXT_ICMP_ERROR,
1527 IP6_REWRITE_NEXT_FRAGMENT,
1528 IP6_REWRITE_N_NEXT /* Last */
1529 } ip6_rewrite_next_t;
1532 * This bits of an IPv6 address to mask to construct a multicast
1535 #define IP6_MCAST_ADDR_MASK 0xffffffff
1538 ip6_mtu_check (vlib_buffer_t * b, u16 packet_bytes,
1539 u16 adj_packet_bytes, bool is_locally_generated,
1540 u32 * next, u32 * error)
1542 if (adj_packet_bytes >= 1280 && packet_bytes > adj_packet_bytes)
1544 if (is_locally_generated)
1546 /* IP fragmentation */
1547 ip_frag_set_vnet_buffer (b, adj_packet_bytes,
1548 IP6_FRAG_NEXT_IP6_REWRITE, 0);
1549 *next = IP6_REWRITE_NEXT_FRAGMENT;
1550 *error = IP6_ERROR_MTU_EXCEEDED;
1554 *error = IP6_ERROR_MTU_EXCEEDED;
1555 icmp6_error_set_vnet_buffer (b, ICMP6_packet_too_big, 0,
1557 *next = IP6_REWRITE_NEXT_ICMP_ERROR;
1563 ip6_rewrite_inline (vlib_main_t * vm,
1564 vlib_node_runtime_t * node,
1565 vlib_frame_t * frame,
1566 int do_counters, int is_midchain, int is_mcast)
1568 ip_lookup_main_t *lm = &ip6_main.lookup_main;
1569 u32 *from = vlib_frame_vector_args (frame);
1570 u32 n_left_from, n_left_to_next, *to_next, next_index;
1571 vlib_node_runtime_t *error_node =
1572 vlib_node_get_runtime (vm, ip6_input_node.index);
1574 n_left_from = frame->n_vectors;
1575 next_index = node->cached_next_index;
1576 u32 thread_index = vm->thread_index;
1578 while (n_left_from > 0)
1580 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1582 while (n_left_from >= 4 && n_left_to_next >= 2)
1584 ip_adjacency_t *adj0, *adj1;
1585 vlib_buffer_t *p0, *p1;
1586 ip6_header_t *ip0, *ip1;
1587 u32 pi0, rw_len0, next0, error0, adj_index0;
1588 u32 pi1, rw_len1, next1, error1, adj_index1;
1589 u32 tx_sw_if_index0, tx_sw_if_index1;
1590 bool is_locally_originated0, is_locally_originated1;
1592 /* Prefetch next iteration. */
1594 vlib_buffer_t *p2, *p3;
1596 p2 = vlib_get_buffer (vm, from[2]);
1597 p3 = vlib_get_buffer (vm, from[3]);
1599 vlib_prefetch_buffer_header (p2, LOAD);
1600 vlib_prefetch_buffer_header (p3, LOAD);
1602 CLIB_PREFETCH (p2->pre_data, 32, STORE);
1603 CLIB_PREFETCH (p3->pre_data, 32, STORE);
1605 CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
1606 CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
1609 pi0 = to_next[0] = from[0];
1610 pi1 = to_next[1] = from[1];
1615 n_left_to_next -= 2;
1617 p0 = vlib_get_buffer (vm, pi0);
1618 p1 = vlib_get_buffer (vm, pi1);
1620 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1621 adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
1623 ip0 = vlib_buffer_get_current (p0);
1624 ip1 = vlib_buffer_get_current (p1);
1626 error0 = error1 = IP6_ERROR_NONE;
1627 next0 = next1 = IP6_REWRITE_NEXT_DROP;
1629 is_locally_originated0 =
1630 p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
1631 if (PREDICT_TRUE (!is_locally_originated0))
1633 i32 hop_limit0 = ip0->hop_limit;
1635 /* Input node should have reject packets with hop limit 0. */
1636 ASSERT (ip0->hop_limit > 0);
1640 ip0->hop_limit = hop_limit0;
1643 * If the hop count drops below 1 when forwarding, generate
1646 if (PREDICT_FALSE (hop_limit0 <= 0))
1648 error0 = IP6_ERROR_TIME_EXPIRED;
1649 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
1650 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1651 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
1652 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1658 p0->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
1660 is_locally_originated1 =
1661 p1->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
1662 if (PREDICT_TRUE (!is_locally_originated1))
1664 i32 hop_limit1 = ip1->hop_limit;
1666 /* Input node should have reject packets with hop limit 0. */
1667 ASSERT (ip1->hop_limit > 0);
1671 ip1->hop_limit = hop_limit1;
1674 * If the hop count drops below 1 when forwarding, generate
1677 if (PREDICT_FALSE (hop_limit1 <= 0))
1679 error1 = IP6_ERROR_TIME_EXPIRED;
1680 next1 = IP6_REWRITE_NEXT_ICMP_ERROR;
1681 vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1682 icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded,
1683 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1689 p1->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
1691 adj0 = adj_get (adj_index0);
1692 adj1 = adj_get (adj_index1);
1694 rw_len0 = adj0[0].rewrite_header.data_bytes;
1695 rw_len1 = adj1[0].rewrite_header.data_bytes;
1696 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
1697 vnet_buffer (p1)->ip.save_rewrite_length = rw_len1;
1701 vlib_increment_combined_counter
1702 (&adjacency_counters,
1703 thread_index, adj_index0, 1,
1704 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
1705 vlib_increment_combined_counter
1706 (&adjacency_counters,
1707 thread_index, adj_index1, 1,
1708 vlib_buffer_length_in_chain (vm, p1) + rw_len1);
1711 /* Check MTU of outgoing interface. */
1712 ip6_mtu_check (p0, clib_net_to_host_u16 (ip0->payload_length) +
1713 sizeof (ip6_header_t),
1714 adj0[0].rewrite_header.max_l3_packet_bytes,
1715 is_locally_originated0, &next0, &error0);
1716 ip6_mtu_check (p1, clib_net_to_host_u16 (ip1->payload_length) +
1717 sizeof (ip6_header_t),
1718 adj1[0].rewrite_header.max_l3_packet_bytes,
1719 is_locally_originated1, &next1, &error1);
1721 /* Don't adjust the buffer for hop count issue; icmp-error node
1722 * wants to see the IP headerr */
1723 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
1725 p0->current_data -= rw_len0;
1726 p0->current_length += rw_len0;
1728 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
1729 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
1730 next0 = adj0[0].rewrite_header.next_index;
1733 (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
1734 vnet_feature_arc_start (lm->output_feature_arc_index,
1735 tx_sw_if_index0, &next0, p0);
1737 if (PREDICT_TRUE (error1 == IP6_ERROR_NONE))
1739 p1->current_data -= rw_len1;
1740 p1->current_length += rw_len1;
1742 tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index;
1743 vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1;
1744 next1 = adj1[0].rewrite_header.next_index;
1747 (adj1[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
1748 vnet_feature_arc_start (lm->output_feature_arc_index,
1749 tx_sw_if_index1, &next1, p1);
1752 /* Guess we are only writing on simple Ethernet header. */
1753 vnet_rewrite_two_headers (adj0[0], adj1[0],
1754 ip0, ip1, sizeof (ethernet_header_t));
1758 adj0->sub_type.midchain.fixup_func
1759 (vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
1760 adj1->sub_type.midchain.fixup_func
1761 (vm, adj1, p1, adj1->sub_type.midchain.fixup_data);
1766 * copy bytes from the IP address into the MAC rewrite
1768 vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK,
1770 rewrite_header.dst_mcast_offset,
1771 &ip0->dst_address.as_u32[3],
1773 vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK,
1775 rewrite_header.dst_mcast_offset,
1776 &ip1->dst_address.as_u32[3],
1780 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1781 to_next, n_left_to_next,
1782 pi0, pi1, next0, next1);
1785 while (n_left_from > 0 && n_left_to_next > 0)
1787 ip_adjacency_t *adj0;
1791 u32 adj_index0, next0, error0;
1792 u32 tx_sw_if_index0;
1793 bool is_locally_originated0;
1795 pi0 = to_next[0] = from[0];
1797 p0 = vlib_get_buffer (vm, pi0);
1799 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1801 adj0 = adj_get (adj_index0);
1803 ip0 = vlib_buffer_get_current (p0);
1805 error0 = IP6_ERROR_NONE;
1806 next0 = IP6_REWRITE_NEXT_DROP;
1808 /* Check hop limit */
1809 is_locally_originated0 =
1810 p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED;
1811 if (PREDICT_TRUE (!is_locally_originated0))
1813 i32 hop_limit0 = ip0->hop_limit;
1815 ASSERT (ip0->hop_limit > 0);
1819 ip0->hop_limit = hop_limit0;
1821 if (PREDICT_FALSE (hop_limit0 <= 0))
1824 * If the hop count drops below 1 when forwarding, generate
1827 error0 = IP6_ERROR_TIME_EXPIRED;
1828 next0 = IP6_REWRITE_NEXT_ICMP_ERROR;
1829 vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1830 icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded,
1831 ICMP6_time_exceeded_ttl_exceeded_in_transit,
1837 p0->flags &= ~VNET_BUFFER_F_LOCALLY_ORIGINATED;
1840 /* Guess we are only writing on simple Ethernet header. */
1841 vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
1843 /* Update packet buffer attributes/set output interface. */
1844 rw_len0 = adj0[0].rewrite_header.data_bytes;
1845 vnet_buffer (p0)->ip.save_rewrite_length = rw_len0;
1849 vlib_increment_combined_counter
1850 (&adjacency_counters,
1851 thread_index, adj_index0, 1,
1852 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
1855 /* Check MTU of outgoing interface. */
1856 ip6_mtu_check (p0, clib_net_to_host_u16 (ip0->payload_length) +
1857 sizeof (ip6_header_t),
1858 adj0[0].rewrite_header.max_l3_packet_bytes,
1859 is_locally_originated0, &next0, &error0);
1861 /* Don't adjust the buffer for hop count issue; icmp-error node
1862 * wants to see the IP header */
1863 if (PREDICT_TRUE (error0 == IP6_ERROR_NONE))
1865 p0->current_data -= rw_len0;
1866 p0->current_length += rw_len0;
1868 tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index;
1870 vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0;
1871 next0 = adj0[0].rewrite_header.next_index;
1874 (adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
1875 vnet_feature_arc_start (lm->output_feature_arc_index,
1876 tx_sw_if_index0, &next0, p0);
1881 adj0->sub_type.midchain.fixup_func
1882 (vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
1886 vnet_ip_mcast_fixup_header (IP6_MCAST_ADDR_MASK,
1888 rewrite_header.dst_mcast_offset,
1889 &ip0->dst_address.as_u32[3],
1893 p0->error = error_node->errors[error0];
1898 n_left_to_next -= 1;
1900 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1901 to_next, n_left_to_next,
1905 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1908 /* Need to do trace after rewrites to pick up new packet data. */
1909 if (node->flags & VLIB_NODE_FLAG_TRACE)
1910 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1912 return frame->n_vectors;
1915 VLIB_NODE_FN (ip6_rewrite_node) (vlib_main_t * vm,
1916 vlib_node_runtime_t * node,
1917 vlib_frame_t * frame)
1919 if (adj_are_counters_enabled ())
1920 return ip6_rewrite_inline (vm, node, frame, 1, 0, 0);
1922 return ip6_rewrite_inline (vm, node, frame, 0, 0, 0);
1925 VLIB_NODE_FN (ip6_rewrite_bcast_node) (vlib_main_t * vm,
1926 vlib_node_runtime_t * node,
1927 vlib_frame_t * frame)
1929 if (adj_are_counters_enabled ())
1930 return ip6_rewrite_inline (vm, node, frame, 1, 0, 0);
1932 return ip6_rewrite_inline (vm, node, frame, 0, 0, 0);
1935 VLIB_NODE_FN (ip6_rewrite_mcast_node) (vlib_main_t * vm,
1936 vlib_node_runtime_t * node,
1937 vlib_frame_t * frame)
1939 if (adj_are_counters_enabled ())
1940 return ip6_rewrite_inline (vm, node, frame, 1, 0, 1);
1942 return ip6_rewrite_inline (vm, node, frame, 0, 0, 1);
1945 VLIB_NODE_FN (ip6_midchain_node) (vlib_main_t * vm,
1946 vlib_node_runtime_t * node,
1947 vlib_frame_t * frame)
1949 if (adj_are_counters_enabled ())
1950 return ip6_rewrite_inline (vm, node, frame, 1, 1, 0);
1952 return ip6_rewrite_inline (vm, node, frame, 0, 1, 0);
1955 VLIB_NODE_FN (ip6_mcast_midchain_node) (vlib_main_t * vm,
1956 vlib_node_runtime_t * node,
1957 vlib_frame_t * frame)
1959 if (adj_are_counters_enabled ())
1960 return ip6_rewrite_inline (vm, node, frame, 1, 1, 1);
1962 return ip6_rewrite_inline (vm, node, frame, 0, 1, 1);
1966 VLIB_REGISTER_NODE (ip6_midchain_node) =
1968 .name = "ip6-midchain",
1969 .vector_size = sizeof (u32),
1970 .format_trace = format_ip6_forward_next_trace,
1971 .sibling_of = "ip6-rewrite",
1974 VLIB_REGISTER_NODE (ip6_rewrite_node) =
1976 .name = "ip6-rewrite",
1977 .vector_size = sizeof (u32),
1978 .format_trace = format_ip6_rewrite_trace,
1979 .n_next_nodes = IP6_REWRITE_N_NEXT,
1982 [IP6_REWRITE_NEXT_DROP] = "ip6-drop",
1983 [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error",
1984 [IP6_REWRITE_NEXT_FRAGMENT] = "ip6-frag",
1988 VLIB_REGISTER_NODE (ip6_rewrite_bcast_node) = {
1989 .name = "ip6-rewrite-bcast",
1990 .vector_size = sizeof (u32),
1992 .format_trace = format_ip6_rewrite_trace,
1993 .sibling_of = "ip6-rewrite",
1996 VLIB_REGISTER_NODE (ip6_rewrite_mcast_node) =
1998 .name = "ip6-rewrite-mcast",
1999 .vector_size = sizeof (u32),
2000 .format_trace = format_ip6_rewrite_trace,
2001 .sibling_of = "ip6-rewrite",
2005 VLIB_REGISTER_NODE (ip6_mcast_midchain_node) =
2007 .name = "ip6-mcast-midchain",
2008 .vector_size = sizeof (u32),
2009 .format_trace = format_ip6_rewrite_trace,
2010 .sibling_of = "ip6-rewrite",
2016 * Hop-by-Hop handling
2018 #ifndef CLIB_MARCH_VARIANT
2019 ip6_hop_by_hop_main_t ip6_hop_by_hop_main;
2020 #endif /* CLIB_MARCH_VARIANT */
2022 #define foreach_ip6_hop_by_hop_error \
2023 _(PROCESSED, "pkts with ip6 hop-by-hop options") \
2024 _(FORMAT, "incorrectly formatted hop-by-hop options") \
2025 _(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options")
2030 #define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym,
2031 foreach_ip6_hop_by_hop_error
2033 IP6_HOP_BY_HOP_N_ERROR,
2034 } ip6_hop_by_hop_error_t;
2038 * Primary h-b-h handler trace support
2039 * We work pretty hard on the problem for obvious reasons
2045 u8 option_data[256];
2046 } ip6_hop_by_hop_trace_t;
2048 extern vlib_node_registration_t ip6_hop_by_hop_node;
2050 static char *ip6_hop_by_hop_error_strings[] = {
2051 #define _(sym,string) string,
2052 foreach_ip6_hop_by_hop_error
2056 #ifndef CLIB_MARCH_VARIANT
2058 format_ip6_hop_by_hop_ext_hdr (u8 * s, va_list * args)
2060 ip6_hop_by_hop_header_t *hbh0 = va_arg (*args, ip6_hop_by_hop_header_t *);
2061 int total_len = va_arg (*args, int);
2062 ip6_hop_by_hop_option_t *opt0, *limit0;
2063 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2066 s = format (s, "IP6_HOP_BY_HOP: next protocol %d len %d total %d",
2067 hbh0->protocol, (hbh0->length + 1) << 3, total_len);
2069 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2070 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + total_len);
2072 while (opt0 < limit0)
2077 case 0: /* Pad, just stop */
2078 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0 + 1);
2082 if (hm->trace[type0])
2084 s = (*hm->trace[type0]) (s, opt0);
2089 format (s, "\n unrecognized option %d length %d", type0,
2093 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2094 sizeof (ip6_hop_by_hop_option_t));
2103 format_ip6_hop_by_hop_trace (u8 * s, va_list * args)
2105 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2106 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
2107 ip6_hop_by_hop_trace_t *t = va_arg (*args, ip6_hop_by_hop_trace_t *);
2108 ip6_hop_by_hop_header_t *hbh0;
2109 ip6_hop_by_hop_option_t *opt0, *limit0;
2110 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2114 hbh0 = (ip6_hop_by_hop_header_t *) t->option_data;
2116 s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d",
2117 t->next_index, (hbh0->length + 1) << 3, t->trace_len);
2119 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2120 limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0) + t->trace_len;
2122 while (opt0 < limit0)
2127 case 0: /* Pad, just stop */
2128 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
2132 if (hm->trace[type0])
2134 s = (*hm->trace[type0]) (s, opt0);
2139 format (s, "\n unrecognized option %d length %d", type0,
2143 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2144 sizeof (ip6_hop_by_hop_option_t));
2152 ip6_scan_hbh_options (vlib_buffer_t * b0,
2154 ip6_hop_by_hop_header_t * hbh0,
2155 ip6_hop_by_hop_option_t * opt0,
2156 ip6_hop_by_hop_option_t * limit0, u32 * next0)
2158 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2162 while (opt0 < limit0)
2168 opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
2173 if (hm->options[type0])
2175 if ((*hm->options[type0]) (b0, ip0, opt0) < 0)
2177 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2183 /* Unrecognized mandatory option, check the two high order bits */
2184 switch (opt0->type & HBH_OPTION_TYPE_HIGH_ORDER_BITS)
2186 case HBH_OPTION_TYPE_SKIP_UNKNOWN:
2188 case HBH_OPTION_TYPE_DISCARD_UNKNOWN:
2189 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2190 *next0 = IP_LOOKUP_NEXT_DROP;
2192 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP:
2193 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2194 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
2195 icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem,
2196 ICMP6_parameter_problem_unrecognized_option,
2197 (u8 *) opt0 - (u8 *) ip0);
2199 case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST:
2200 error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION;
2201 if (!ip6_address_is_multicast (&ip0->dst_address))
2203 *next0 = IP_LOOKUP_NEXT_ICMP_ERROR;
2204 icmp6_error_set_vnet_buffer (b0,
2205 ICMP6_parameter_problem,
2206 ICMP6_parameter_problem_unrecognized_option,
2207 (u8 *) opt0 - (u8 *) ip0);
2211 *next0 = IP_LOOKUP_NEXT_DROP;
2219 (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
2220 sizeof (ip6_hop_by_hop_option_t));
2226 * Process the Hop-by-Hop Options header
2228 VLIB_NODE_FN (ip6_hop_by_hop_node) (vlib_main_t * vm,
2229 vlib_node_runtime_t * node,
2230 vlib_frame_t * frame)
2232 vlib_node_runtime_t *error_node =
2233 vlib_node_get_runtime (vm, ip6_hop_by_hop_node.index);
2234 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2235 u32 n_left_from, *from, *to_next;
2236 ip_lookup_next_t next_index;
2238 from = vlib_frame_vector_args (frame);
2239 n_left_from = frame->n_vectors;
2240 next_index = node->cached_next_index;
2242 while (n_left_from > 0)
2246 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2248 while (n_left_from >= 4 && n_left_to_next >= 2)
2251 vlib_buffer_t *b0, *b1;
2253 ip6_header_t *ip0, *ip1;
2254 ip6_hop_by_hop_header_t *hbh0, *hbh1;
2255 ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1;
2256 u8 error0 = 0, error1 = 0;
2258 /* Prefetch next iteration. */
2260 vlib_buffer_t *p2, *p3;
2262 p2 = vlib_get_buffer (vm, from[2]);
2263 p3 = vlib_get_buffer (vm, from[3]);
2265 vlib_prefetch_buffer_header (p2, LOAD);
2266 vlib_prefetch_buffer_header (p3, LOAD);
2268 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
2269 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
2272 /* Speculatively enqueue b0, b1 to the current next frame */
2273 to_next[0] = bi0 = from[0];
2274 to_next[1] = bi1 = from[1];
2278 n_left_to_next -= 2;
2280 b0 = vlib_get_buffer (vm, bi0);
2281 b1 = vlib_get_buffer (vm, bi1);
2283 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2284 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
2285 ip_adjacency_t *adj0 = adj_get (adj_index0);
2286 u32 adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
2287 ip_adjacency_t *adj1 = adj_get (adj_index1);
2289 /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */
2290 next0 = adj0->lookup_next_index;
2291 next1 = adj1->lookup_next_index;
2293 ip0 = vlib_buffer_get_current (b0);
2294 ip1 = vlib_buffer_get_current (b1);
2295 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2296 hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
2297 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2298 opt1 = (ip6_hop_by_hop_option_t *) (hbh1 + 1);
2300 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2301 ((hbh0->length + 1) << 3));
2303 (ip6_hop_by_hop_option_t *) ((u8 *) hbh1 +
2304 ((hbh1->length + 1) << 3));
2307 * Basic validity checks
2309 if ((hbh0->length + 1) << 3 >
2310 clib_net_to_host_u16 (ip0->payload_length))
2312 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2313 next0 = IP_LOOKUP_NEXT_DROP;
2316 /* Scan the set of h-b-h options, process ones that we understand */
2317 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2319 if ((hbh1->length + 1) << 3 >
2320 clib_net_to_host_u16 (ip1->payload_length))
2322 error1 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2323 next1 = IP_LOOKUP_NEXT_DROP;
2326 /* Scan the set of h-b-h options, process ones that we understand */
2327 error1 = ip6_scan_hbh_options (b1, ip1, hbh1, opt1, limit1, &next1);
2330 /* Has the classifier flagged this buffer for special treatment? */
2333 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2334 next0 = hm->next_override;
2336 /* Has the classifier flagged this buffer for special treatment? */
2339 && (vnet_buffer (b1)->l2_classify.opaque_index & OI_DECAP)))
2340 next1 = hm->next_override;
2342 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
2344 if (b0->flags & VLIB_BUFFER_IS_TRACED)
2346 ip6_hop_by_hop_trace_t *t =
2347 vlib_add_trace (vm, node, b0, sizeof (*t));
2348 u32 trace_len = (hbh0->length + 1) << 3;
2349 t->next_index = next0;
2350 /* Capture the h-b-h option verbatim */
2353 ARRAY_LEN (t->option_data) ? trace_len :
2354 ARRAY_LEN (t->option_data);
2355 t->trace_len = trace_len;
2356 clib_memcpy_fast (t->option_data, hbh0, trace_len);
2358 if (b1->flags & VLIB_BUFFER_IS_TRACED)
2360 ip6_hop_by_hop_trace_t *t =
2361 vlib_add_trace (vm, node, b1, sizeof (*t));
2362 u32 trace_len = (hbh1->length + 1) << 3;
2363 t->next_index = next1;
2364 /* Capture the h-b-h option verbatim */
2367 ARRAY_LEN (t->option_data) ? trace_len :
2368 ARRAY_LEN (t->option_data);
2369 t->trace_len = trace_len;
2370 clib_memcpy_fast (t->option_data, hbh1, trace_len);
2375 b0->error = error_node->errors[error0];
2376 b1->error = error_node->errors[error1];
2378 /* verify speculative enqueue, maybe switch current next frame */
2379 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
2380 n_left_to_next, bi0, bi1, next0,
2384 while (n_left_from > 0 && n_left_to_next > 0)
2390 ip6_hop_by_hop_header_t *hbh0;
2391 ip6_hop_by_hop_option_t *opt0, *limit0;
2394 /* Speculatively enqueue b0 to the current next frame */
2400 n_left_to_next -= 1;
2402 b0 = vlib_get_buffer (vm, bi0);
2404 * Default use the next_index from the adjacency.
2405 * A HBH option rarely redirects to a different node
2407 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
2408 ip_adjacency_t *adj0 = adj_get (adj_index0);
2409 next0 = adj0->lookup_next_index;
2411 ip0 = vlib_buffer_get_current (b0);
2412 hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
2413 opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
2415 (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 +
2416 ((hbh0->length + 1) << 3));
2419 * Basic validity checks
2421 if ((hbh0->length + 1) << 3 >
2422 clib_net_to_host_u16 (ip0->payload_length))
2424 error0 = IP6_HOP_BY_HOP_ERROR_FORMAT;
2425 next0 = IP_LOOKUP_NEXT_DROP;
2429 /* Scan the set of h-b-h options, process ones that we understand */
2430 error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0);
2433 /* Has the classifier flagged this buffer for special treatment? */
2436 && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP)))
2437 next0 = hm->next_override;
2439 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
2441 ip6_hop_by_hop_trace_t *t =
2442 vlib_add_trace (vm, node, b0, sizeof (*t));
2443 u32 trace_len = (hbh0->length + 1) << 3;
2444 t->next_index = next0;
2445 /* Capture the h-b-h option verbatim */
2448 ARRAY_LEN (t->option_data) ? trace_len :
2449 ARRAY_LEN (t->option_data);
2450 t->trace_len = trace_len;
2451 clib_memcpy_fast (t->option_data, hbh0, trace_len);
2454 b0->error = error_node->errors[error0];
2456 /* verify speculative enqueue, maybe switch current next frame */
2457 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
2458 n_left_to_next, bi0, next0);
2460 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2462 return frame->n_vectors;
2466 VLIB_REGISTER_NODE (ip6_hop_by_hop_node) =
2468 .name = "ip6-hop-by-hop",
2469 .sibling_of = "ip6-lookup",
2470 .vector_size = sizeof (u32),
2471 .format_trace = format_ip6_hop_by_hop_trace,
2472 .type = VLIB_NODE_TYPE_INTERNAL,
2473 .n_errors = ARRAY_LEN (ip6_hop_by_hop_error_strings),
2474 .error_strings = ip6_hop_by_hop_error_strings,
2479 static clib_error_t *
2480 ip6_hop_by_hop_init (vlib_main_t * vm)
2482 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2483 clib_memset (hm->options, 0, sizeof (hm->options));
2484 clib_memset (hm->trace, 0, sizeof (hm->trace));
2485 hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
2489 VLIB_INIT_FUNCTION (ip6_hop_by_hop_init);
2491 #ifndef CLIB_MARCH_VARIANT
2493 ip6_hbh_set_next_override (uword next)
2495 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2497 hm->next_override = next;
2501 ip6_hbh_register_option (u8 option,
2502 int options (vlib_buffer_t * b, ip6_header_t * ip,
2503 ip6_hop_by_hop_option_t * opt),
2504 u8 * trace (u8 * s, ip6_hop_by_hop_option_t * opt))
2506 ip6_main_t *im = &ip6_main;
2507 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2509 ASSERT ((u32) option < ARRAY_LEN (hm->options));
2511 /* Already registered */
2512 if (hm->options[option])
2515 hm->options[option] = options;
2516 hm->trace[option] = trace;
2518 /* Set global variable */
2519 im->hbh_enabled = 1;
2525 ip6_hbh_unregister_option (u8 option)
2527 ip6_main_t *im = &ip6_main;
2528 ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main;
2530 ASSERT ((u32) option < ARRAY_LEN (hm->options));
2532 /* Not registered */
2533 if (!hm->options[option])
2536 hm->options[option] = NULL;
2537 hm->trace[option] = NULL;
2539 /* Disable global knob if this was the last option configured */
2542 for (i = 0; i < 256; i++)
2544 if (hm->options[option])
2551 im->hbh_enabled = 0;
2556 /* Global IP6 main. */
2557 ip6_main_t ip6_main;
2560 static clib_error_t *
2561 ip6_lookup_init (vlib_main_t * vm)
2563 ip6_main_t *im = &ip6_main;
2564 clib_error_t *error;
2567 if ((error = vlib_call_init_function (vm, vnet_feature_init)))
2570 for (i = 0; i < ARRAY_LEN (im->fib_masks); i++)
2577 for (j = 0; j < i0; j++)
2578 im->fib_masks[i].as_u32[j] = ~0;
2581 im->fib_masks[i].as_u32[i0] =
2582 clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
2585 ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1);
2587 if (im->lookup_table_nbuckets == 0)
2588 im->lookup_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS;
2590 im->lookup_table_nbuckets = 1 << max_log2 (im->lookup_table_nbuckets);
2592 if (im->lookup_table_size == 0)
2593 im->lookup_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE;
2595 clib_bihash_init_24_8 (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash),
2596 "ip6 FIB fwding table",
2597 im->lookup_table_nbuckets, im->lookup_table_size);
2598 clib_bihash_init_24_8 (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
2599 "ip6 FIB non-fwding table",
2600 im->lookup_table_nbuckets, im->lookup_table_size);
2601 clib_bihash_init_40_8 (&im->ip6_mtable.ip6_mhash,
2603 im->lookup_table_nbuckets, im->lookup_table_size);
2605 /* Create FIB with index 0 and table id of 0. */
2606 fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0,
2607 FIB_SOURCE_DEFAULT_ROUTE);
2608 mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0,
2609 MFIB_SOURCE_DEFAULT_ROUTE);
2613 pn = pg_get_node (ip6_lookup_node.index);
2614 pn->unformat_edit = unformat_pg_ip6_header;
2617 /* Unless explicitly configured, don't process HBH options */
2618 im->hbh_enabled = 0;
2621 icmp6_neighbor_solicitation_header_t p;
2623 clib_memset (&p, 0, sizeof (p));
2625 p.ip.ip_version_traffic_class_and_flow_label =
2626 clib_host_to_net_u32 (0x6 << 28);
2627 p.ip.payload_length =
2628 clib_host_to_net_u16 (sizeof (p) -
2630 (icmp6_neighbor_solicitation_header_t, neighbor));
2631 p.ip.protocol = IP_PROTOCOL_ICMP6;
2632 p.ip.hop_limit = 255;
2633 ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0);
2635 p.neighbor.icmp.type = ICMP6_neighbor_solicitation;
2637 p.link_layer_option.header.type =
2638 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
2639 p.link_layer_option.header.n_data_u64s =
2640 sizeof (p.link_layer_option) / sizeof (u64);
2642 vlib_packet_template_init (vm,
2643 &im->discover_neighbor_packet_template,
2645 /* alloc chunk size */ 8,
2646 "ip6 neighbor discovery");
2652 VLIB_INIT_FUNCTION (ip6_lookup_init);
2654 static clib_error_t *
2655 test_ip6_link_command_fn (vlib_main_t * vm,
2656 unformat_input_t * input, vlib_cli_command_t * cmd)
2659 ip6_address_t _a, *a = &_a;
2661 if (unformat (input, "%U", unformat_ethernet_address, mac))
2663 ip6_link_local_address_from_ethernet_mac_address (a, mac);
2664 vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a);
2665 ip6_ethernet_mac_address_from_link_local_address (mac, a);
2666 vlib_cli_output (vm, "Original MAC address: %U",
2667 format_ethernet_address, mac);
2674 * This command converts the given MAC Address into an IPv6 link-local
2678 * Example of how to create an IPv6 link-local address:
2679 * @cliexstart{test ip6 link 16:d9:e0:91:79:86}
2680 * Link local address: fe80::14d9:e0ff:fe91:7986
2681 * Original MAC address: 16:d9:e0:91:79:86
2685 VLIB_CLI_COMMAND (test_link_command, static) =
2687 .path = "test ip6 link",
2688 .function = test_ip6_link_command_fn,
2689 .short_help = "test ip6 link <mac-address>",
2693 #ifndef CLIB_MARCH_VARIANT
2695 vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
2699 fib_index = fib_table_find (FIB_PROTOCOL_IP6, table_id);
2701 if (~0 == fib_index)
2702 return VNET_API_ERROR_NO_SUCH_FIB;
2704 fib_table_set_flow_hash_config (fib_index, FIB_PROTOCOL_IP6,
2711 static clib_error_t *
2712 set_ip6_flow_hash_command_fn (vlib_main_t * vm,
2713 unformat_input_t * input,
2714 vlib_cli_command_t * cmd)
2718 u32 flow_hash_config = 0;
2721 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2723 if (unformat (input, "table %d", &table_id))
2726 else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
2727 foreach_flow_hash_bit
2734 return clib_error_return (0, "unknown input `%U'",
2735 format_unformat_error, input);
2737 rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
2744 return clib_error_return (0, "no such FIB table %d", table_id);
2747 clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config);
2755 * Configure the set of IPv6 fields used by the flow hash.
2759 * Example of how to set the flow hash on a given table:
2760 * @cliexcmd{set ip6 flow-hash table 8 dst sport dport proto}
2762 * Example of display the configured flow hash:
2763 * @cliexstart{show ip6 fib}
2764 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
2767 * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]]
2768 * [0] [@0]: dpo-drop ip6
2771 * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]]
2772 * [0] [@2]: dpo-receive
2775 * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]]
2776 * [0] [@2]: dpo-receive
2779 * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]]
2780 * [0] [@2]: dpo-receive
2783 * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]]
2784 * [0] [@2]: dpo-receive
2785 * ff02::1:ff00:0/104
2787 * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]]
2788 * [0] [@2]: dpo-receive
2789 * ipv6-VRF:8, fib_index 1, flow hash: dst sport dport proto
2792 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
2793 * [0] [@0]: dpo-drop ip6
2796 * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]]
2797 * [0] [@4]: ipv6-glean: af_packet0
2800 * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]]
2801 * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0
2804 * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]]
2805 * [0] [@2]: dpo-receive
2806 * fe80::fe:3eff:fe3e:9222/128
2808 * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]]
2809 * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0
2812 * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]]
2813 * [0] [@2]: dpo-receive
2816 * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]]
2817 * [0] [@2]: dpo-receive
2820 * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]]
2821 * [0] [@2]: dpo-receive
2822 * ff02::1:ff00:0/104
2824 * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]]
2825 * [0] [@2]: dpo-receive
2830 VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) =
2832 .path = "set ip6 flow-hash",
2834 "set ip6 flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]",
2835 .function = set_ip6_flow_hash_command_fn,
2839 static clib_error_t *
2840 show_ip6_local_command_fn (vlib_main_t * vm,
2841 unformat_input_t * input, vlib_cli_command_t * cmd)
2843 ip6_main_t *im = &ip6_main;
2844 ip_lookup_main_t *lm = &im->lookup_main;
2847 vlib_cli_output (vm, "Protocols handled by ip6_local");
2848 for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++)
2850 if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
2853 u32 node_index = vlib_get_node (vm,
2854 ip6_local_node.index)->
2855 next_nodes[lm->local_next_by_ip_protocol[i]];
2856 vlib_cli_output (vm, "%d: %U", i, format_vlib_node_name, vm,
2866 * Display the set of protocols handled by the local IPv6 stack.
2869 * Example of how to display local protocol table:
2870 * @cliexstart{show ip6 local}
2871 * Protocols handled by ip6_local
2879 VLIB_CLI_COMMAND (show_ip6_local, static) =
2881 .path = "show ip6 local",
2882 .function = show_ip6_local_command_fn,
2883 .short_help = "show ip6 local",
2887 #ifndef CLIB_MARCH_VARIANT
2889 vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index,
2892 vnet_main_t *vnm = vnet_get_main ();
2893 vnet_interface_main_t *im = &vnm->interface_main;
2894 ip6_main_t *ipm = &ip6_main;
2895 ip_lookup_main_t *lm = &ipm->lookup_main;
2896 vnet_classify_main_t *cm = &vnet_classify_main;
2897 ip6_address_t *if_addr;
2899 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2900 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
2902 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
2903 return VNET_API_ERROR_NO_SUCH_ENTRY;
2905 vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index);
2906 lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index;
2908 if_addr = ip6_interface_first_address (ipm, sw_if_index);
2910 if (NULL != if_addr)
2912 fib_prefix_t pfx = {
2914 .fp_proto = FIB_PROTOCOL_IP6,
2915 .fp_addr.ip6 = *if_addr,
2919 fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
2923 if (table_index != (u32) ~ 0)
2925 dpo_id_t dpo = DPO_INVALID;
2930 classify_dpo_create (DPO_PROTO_IP6, table_index));
2932 fib_table_entry_special_dpo_add (fib_index,
2934 FIB_SOURCE_CLASSIFY,
2935 FIB_ENTRY_FLAG_NONE, &dpo);
2940 fib_table_entry_special_remove (fib_index,
2941 &pfx, FIB_SOURCE_CLASSIFY);
2949 static clib_error_t *
2950 set_ip6_classify_command_fn (vlib_main_t * vm,
2951 unformat_input_t * input,
2952 vlib_cli_command_t * cmd)
2954 u32 table_index = ~0;
2955 int table_index_set = 0;
2956 u32 sw_if_index = ~0;
2959 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2961 if (unformat (input, "table-index %d", &table_index))
2962 table_index_set = 1;
2963 else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
2964 vnet_get_main (), &sw_if_index))
2970 if (table_index_set == 0)
2971 return clib_error_return (0, "classify table-index must be specified");
2973 if (sw_if_index == ~0)
2974 return clib_error_return (0, "interface / subif must be specified");
2976 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
2983 case VNET_API_ERROR_NO_MATCHING_INTERFACE:
2984 return clib_error_return (0, "No such interface");
2986 case VNET_API_ERROR_NO_SUCH_ENTRY:
2987 return clib_error_return (0, "No such classifier table");
2993 * Assign a classification table to an interface. The classification
2994 * table is created using the '<em>classify table</em>' and '<em>classify session</em>'
2995 * commands. Once the table is create, use this command to filter packets
2999 * Example of how to assign a classification table to an interface:
3000 * @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1}
3003 VLIB_CLI_COMMAND (set_ip6_classify_command, static) =
3005 .path = "set ip6 classify",
3007 "set ip6 classify intfc <interface> table-index <classify-idx>",
3008 .function = set_ip6_classify_command_fn,
3012 static clib_error_t *
3013 ip6_config (vlib_main_t * vm, unformat_input_t * input)
3015 ip6_main_t *im = &ip6_main;
3020 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3022 if (unformat (input, "hash-buckets %d", &tmp))
3024 else if (unformat (input, "heap-size %U",
3025 unformat_memory_size, &heapsize))
3028 return clib_error_return (0, "unknown input '%U'",
3029 format_unformat_error, input);
3032 im->lookup_table_nbuckets = nbuckets;
3033 im->lookup_table_size = heapsize;
3038 VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6");
3041 * fd.io coding-style-patch-verification: ON
3044 * eval: (c-set-style "gnu")