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.
17 #include <vnet/plugin/plugin.h>
18 #include <vnet/ip/lookup.h>
19 #include <vnet/dpo/dpo.h>
20 #include <vnet/fib/fib_table.h>
21 #include <vpp/app/version.h>
23 static ila_main_t ila_main;
25 #define ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
26 #define ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE (32<<20)
28 #define foreach_ila_error \
29 _(NONE, "valid ILA packets")
32 #define _(sym,str) ILA_ERROR_##sym,
38 static char *ila_error_strings[] = {
39 #define _(sym,string) string,
45 ILA_ILA2SIR_NEXT_DROP,
51 ip6_address_t initial_dst;
53 } ila_ila2sir_trace_t;
55 static ila_entry_t ila_sir2ila_default_entry = {
56 .csum_mode = ILA_CSUM_MODE_NO_ACTION,
58 .dir = ILA_DIR_ILA2SIR, //Will pass the packet with no
62 * @brief Dynamically registered DPO Type for ILA
64 static dpo_type_t ila_dpo_type;
67 * @brief Dynamically registered FIB node type for ILA
69 static fib_node_type_t ila_fib_node_type;
72 format_half_ip6_address (u8 * s, va_list * va)
74 u64 v = clib_net_to_host_u64 (va_arg (*va, u64));
76 return format (s, "%04x:%04x:%04x:%04x",
77 v >> 48, (v >> 32) & 0xffff, (v >> 16) & 0xffff, v & 0xffff);
82 format_ila_direction (u8 * s, va_list * args)
84 ila_direction_t t = va_arg (*args, ila_direction_t);
86 if (t == ILA_DIR_##i) \
90 return format (s, "invalid_ila_direction");
94 format_csum_mode (u8 * s, va_list * va)
96 ila_csum_mode_t csum_mode = va_arg (*va, ila_csum_mode_t);
102 case ILA_CSUM_MODE_##i: \
105 ila_csum_foreach_type
108 txt = "invalid_ila_csum_mode";
111 return format (s, txt);
115 format_ila_type (u8 * s, va_list * args)
117 ila_type_t t = va_arg (*args, ila_type_t);
119 if (t == ILA_TYPE_##i) \
120 return format(s, st);
123 return format (s, "invalid_ila_type");
127 format_ila_entry (u8 * s, va_list * va)
129 vnet_main_t *vnm = va_arg (*va, vnet_main_t *);
130 ila_entry_t *e = va_arg (*va, ila_entry_t *);
134 return format (s, "%-15s%=40s%=40s%+16s%+18s%+11s", "Type", "SIR Address",
135 "ILA Address", "Checksum Mode", "Direction", "Next DPO");
139 if (ip6_address_is_zero(&e->next_hop))
141 return format (s, "%-15U%=40U%=40U%18U%11U%s",
142 format_ila_type, e->type,
143 format_ip6_address, &e->sir_address,
144 format_ip6_address, &e->ila_address,
145 format_csum_mode, e->csum_mode,
146 format_ila_direction, e->dir,
151 return format (s, "%-15U%=40U%=40U%18U%11U%U",
152 format_ila_type, e->type,
153 format_ip6_address, &e->sir_address,
154 format_ip6_address, &e->ila_address,
155 format_csum_mode, e->csum_mode,
156 format_ila_direction, e->dir,
157 format_dpo_id, &e->ila_dpo, 0);
165 format_ila_ila2sir_trace (u8 * s, va_list * args)
167 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
168 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
169 ila_ila2sir_trace_t *t = va_arg (*args, ila_ila2sir_trace_t *);
171 "ILA -> SIR adj index: %d entry index: %d initial_dst: %U",
172 t->adj_index, t->ila_index, format_ip6_address,
177 unformat_ila_direction (unformat_input_t * input, va_list * args)
179 ila_direction_t *result = va_arg (*args, ila_direction_t *);
181 if (unformat(input, s)) \
183 *result = ILA_DIR_##i; \
187 ila_foreach_direction
193 unformat_ila_type (unformat_input_t * input, va_list * args)
195 ila_type_t *result = va_arg (*args, ila_type_t *);
197 if (unformat(input, s)) \
199 *result = ILA_TYPE_##i; \
209 unformat_ila_csum_mode (unformat_input_t * input, va_list * args)
211 ila_csum_mode_t *result = va_arg (*args, ila_csum_mode_t *);
212 if (unformat (input, "none") || unformat (input, "no-action"))
214 *result = ILA_CSUM_MODE_NO_ACTION;
217 if (unformat (input, "neutral-map"))
219 *result = ILA_CSUM_MODE_NEUTRAL_MAP;
222 if (unformat (input, "adjust-transport"))
224 *result = ILA_CSUM_MODE_ADJUST_TRANSPORT;
231 unformat_half_ip6_address (unformat_input_t * input, va_list * args)
233 u64 *result = va_arg (*args, u64 *);
236 if (!unformat (input, "%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3]))
239 if (a[0] > 0xFFFF || a[1] > 0xFFFF || a[2] > 0xFFFF || a[3] > 0xFFFF)
242 *result = clib_host_to_net_u64 ((((u64) a[0]) << 48) |
243 (((u64) a[1]) << 32) |
244 (((u64) a[2]) << 16) | (((u64) a[3])));
249 static vlib_node_registration_t ila_ila2sir_node;
252 ila_ila2sir (vlib_main_t * vm,
253 vlib_node_runtime_t * node, vlib_frame_t * frame)
255 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
256 ila_main_t *ilm = &ila_main;
258 from = vlib_frame_vector_args (frame);
259 n_left_from = frame->n_vectors;
260 next_index = node->cached_next_index;
262 while (n_left_from > 0)
264 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
266 while (n_left_from >= 4 && n_left_to_next >= 2)
269 vlib_buffer_t *p0, *p1;
270 ila_entry_t *ie0, *ie1;
271 ip6_header_t *ip60, *ip61;
272 ip6_address_t *sir_address0, *sir_address1;
275 vlib_buffer_t *p2, *p3;
277 p2 = vlib_get_buffer (vm, from[2]);
278 p3 = vlib_get_buffer (vm, from[3]);
280 vlib_prefetch_buffer_header (p2, LOAD);
281 vlib_prefetch_buffer_header (p3, LOAD);
282 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
283 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
286 pi0 = to_next[0] = from[0];
287 pi1 = to_next[1] = from[1];
293 p0 = vlib_get_buffer (vm, pi0);
294 p1 = vlib_get_buffer (vm, pi1);
295 ip60 = vlib_buffer_get_current (p0);
296 ip61 = vlib_buffer_get_current (p1);
297 sir_address0 = &ip60->dst_address;
298 sir_address1 = &ip61->dst_address;
299 ie0 = pool_elt_at_index (ilm->entries,
300 vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
301 ie1 = pool_elt_at_index (ilm->entries,
302 vnet_buffer (p1)->ip.adj_index[VLIB_TX]);
304 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
306 ila_ila2sir_trace_t *tr =
307 vlib_add_trace (vm, node, p0, sizeof (*tr));
308 tr->ila_index = ie0 - ilm->entries;
309 tr->initial_dst = ip60->dst_address;
310 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
313 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
315 ila_ila2sir_trace_t *tr =
316 vlib_add_trace (vm, node, p1, sizeof (*tr));
317 tr->ila_index = ie1 - ilm->entries;
318 tr->initial_dst = ip61->dst_address;
319 tr->adj_index = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
322 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
323 sir_address1 = (ie1->dir != ILA_DIR_SIR2ILA) ? &ie1->sir_address : sir_address1;
324 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
325 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
326 ip61->dst_address.as_u64[0] = sir_address1->as_u64[0];
327 ip61->dst_address.as_u64[1] = sir_address1->as_u64[1];
329 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_dpo.dpoi_index;
330 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = ie1->ila_dpo.dpoi_index;
332 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
333 n_left_to_next, pi0, pi1,
334 ie0->ila_dpo.dpoi_next_node,
335 ie1->ila_dpo.dpoi_next_node);
339 while (n_left_from > 0 && n_left_to_next > 0)
345 ip6_address_t *sir_address0;
347 pi0 = to_next[0] = from[0];
353 p0 = vlib_get_buffer (vm, pi0);
354 ip60 = vlib_buffer_get_current (p0);
355 sir_address0 = &ip60->dst_address;
356 ie0 = pool_elt_at_index (ilm->entries,
357 vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
359 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
361 ila_ila2sir_trace_t *tr =
362 vlib_add_trace (vm, node, p0, sizeof (*tr));
363 tr->ila_index = ie0 ? (ie0 - ilm->entries) : ~0;
364 tr->initial_dst = ip60->dst_address;
365 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
368 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
369 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
370 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
371 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_dpo.dpoi_index;
373 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
375 ie0->ila_dpo.dpoi_next_node);
377 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
380 return frame->n_vectors;
384 VLIB_REGISTER_NODE (ila_ila2sir_node, static) =
386 .function = ila_ila2sir,
387 .name = "ila-to-sir",
388 .vector_size = sizeof (u32),
389 .format_trace = format_ila_ila2sir_trace,
390 .n_errors = ILA_N_ERROR,
391 .error_strings = ila_error_strings,
392 .n_next_nodes = ILA_ILA2SIR_N_NEXT,
395 [ILA_ILA2SIR_NEXT_DROP] = "error-drop"
402 ILA_SIR2ILA_NEXT_DROP,
404 } ila_sir2ila_next_t;
409 ip6_address_t initial_dst;
410 } ila_sir2ila_trace_t;
413 format_ila_sir2ila_trace (u8 * s, va_list * args)
415 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
416 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
417 ila_sir2ila_trace_t *t = va_arg (*args, ila_sir2ila_trace_t *);
419 return format (s, "SIR -> ILA entry index: %d initial_dst: %U",
420 t->ila_index, format_ip6_address, &t->initial_dst);
423 static vlib_node_registration_t ila_sir2ila_node;
426 ila_sir2ila (vlib_main_t * vm,
427 vlib_node_runtime_t * node, vlib_frame_t * frame)
429 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
430 ila_main_t *ilm = &ila_main;
432 from = vlib_frame_vector_args (frame);
433 n_left_from = frame->n_vectors;
434 next_index = node->cached_next_index;
436 while (n_left_from > 0)
438 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
440 while (n_left_from >= 4 && n_left_to_next >= 2)
443 vlib_buffer_t *p0, *p1;
444 ip6_header_t *ip60, *ip61;
445 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
446 u32 next1 = ILA_SIR2ILA_NEXT_DROP;
447 BVT (clib_bihash_kv) kv0, value0;
448 BVT (clib_bihash_kv) kv1, value1;
449 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
450 ila_entry_t *ie1 = &ila_sir2ila_default_entry;
451 ip6_address_t *ila_address0, *ila_address1;
454 vlib_buffer_t *p2, *p3;
456 p2 = vlib_get_buffer (vm, from[2]);
457 p3 = vlib_get_buffer (vm, from[3]);
459 vlib_prefetch_buffer_header (p2, LOAD);
460 vlib_prefetch_buffer_header (p3, LOAD);
461 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
462 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
465 pi0 = to_next[0] = from[0];
466 pi1 = to_next[1] = from[1];
472 p0 = vlib_get_buffer (vm, pi0);
473 p1 = vlib_get_buffer (vm, pi1);
474 ip60 = vlib_buffer_get_current (p0);
475 ip61 = vlib_buffer_get_current (p1);
476 ila_address0 = &ip60->dst_address;
477 ila_address1 = &ip61->dst_address;
478 kv0.key[0] = ip60->dst_address.as_u64[0];
479 kv0.key[1] = ip60->dst_address.as_u64[1];
481 kv1.key[0] = ip61->dst_address.as_u64[0];
482 kv1.key[1] = ip61->dst_address.as_u64[1];
485 if (PREDICT_TRUE((BV (clib_bihash_search)
486 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
487 ie0 = &ilm->entries[value0.value];
488 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
491 if ((BV (clib_bihash_search)
492 (&ilm->id_to_entry_table, &kv1, &value1)) == 0) {
493 ie1 = &ilm->entries[value1.value];
494 ila_address1 = (ie1->dir != ILA_DIR_ILA2SIR) ? &ie1->ila_address : ila_address1;
497 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
499 ila_sir2ila_trace_t *tr =
500 vlib_add_trace (vm, node, p0, sizeof (*tr));
502 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
503 tr->initial_dst = ip60->dst_address;
506 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
508 ila_sir2ila_trace_t *tr =
509 vlib_add_trace (vm, node, p1, sizeof (*tr));
511 (ie1 != &ila_sir2ila_default_entry) ? (ie1 - ilm->entries) : ~0;
512 tr->initial_dst = ip61->dst_address;
515 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
516 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
517 ip61->dst_address.as_u64[0] = ila_address1->as_u64[0];
518 ip61->dst_address.as_u64[1] = ila_address1->as_u64[1];
520 vnet_feature_next (vnet_buffer (p0)->sw_if_index[VLIB_RX], &next0, p0);
521 vnet_feature_next (vnet_buffer (p1)->sw_if_index[VLIB_RX], &next1, p1);
523 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
524 n_left_to_next, pi0, pi1, next0,
529 while (n_left_from > 0 && n_left_to_next > 0)
534 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
535 BVT (clib_bihash_kv) kv0, value0;
536 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
537 ip6_address_t *ila_address0;
539 pi0 = to_next[0] = from[0];
545 p0 = vlib_get_buffer (vm, pi0);
546 ip60 = vlib_buffer_get_current (p0);
547 ila_address0 = &ip60->dst_address;
549 kv0.key[0] = ip60->dst_address.as_u64[0];
550 kv0.key[1] = ip60->dst_address.as_u64[1];
553 if (PREDICT_TRUE((BV (clib_bihash_search)
554 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
555 ie0 = &ilm->entries[value0.value];
556 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
559 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
561 ila_sir2ila_trace_t *tr =
562 vlib_add_trace (vm, node, p0, sizeof (*tr));
564 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
565 tr->initial_dst = ip60->dst_address;
568 //This operation should do everything for any type (except vnid4 obviously)
569 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
570 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
572 vnet_feature_next (vnet_buffer (p0)->sw_if_index[VLIB_RX], &next0, p0);
574 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
575 n_left_to_next, pi0, next0);
577 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
580 return frame->n_vectors;
584 VLIB_REGISTER_NODE (ila_sir2ila_node, static) =
586 .function = ila_sir2ila,.name = "sir-to-ila",
587 .vector_size = sizeof (u32),
588 .format_trace = format_ila_sir2ila_trace,
589 .n_errors = ILA_N_ERROR,
590 .error_strings = ila_error_strings,
591 .n_next_nodes = ILA_SIR2ILA_N_NEXT,
594 [ILA_SIR2ILA_NEXT_DROP] = "error-drop"
600 VNET_FEATURE_INIT (ila_sir2ila, static) =
602 .arc_name = "ip6-unicast",
603 .node_name = "sir-to-ila",
604 .runs_before = VNET_FEATURES ("ip6-lookup"),
609 ila_entry_stack (ila_entry_t *ie)
612 * restack on the next-hop's FIB entry
614 dpo_stack(ila_dpo_type,
617 fib_entry_contribute_ip_forwarding(
618 ie->next_hop_fib_entry_index));
622 ila_add_del_entry (ila_add_del_entry_args_t * args)
624 ila_main_t *ilm = &ila_main;
625 BVT (clib_bihash_kv) kv, value;
628 if (args->type == ILA_TYPE_IID || args->type == ILA_TYPE_LUID)
630 if ((args->sir_address.as_u8[8] >> 5) != args->type)
632 clib_warning ("Incorrect SIR address (ILA type mismatch %d %d)",
633 args->sir_address.as_u8[8] >> 1, args->type);
636 if (args->sir_address.as_u8[8] & 0x10)
638 clib_warning ("Checksum bit should not be set in SIR address");
642 else if (args->type == ILA_TYPE_VNIDM)
644 if (args->sir_address.as_u8[0] != 0xff ||
645 (args->sir_address.as_u8[1] & 0xf0) != 0xf0)
647 clib_warning ("SIR multicast address must start with fff");
650 if (args->sir_address.as_u16[1] || args->sir_address.as_u16[2] ||
651 args->sir_address.as_u16[3] || args->sir_address.as_u16[4] ||
652 args->sir_address.as_u16[5] || (args->sir_address.as_u8[12] & 0xf0))
654 clib_warning ("SIR multicast address must start with fff");
662 pool_get (ilm->entries, e);
663 e->type = args->type;
664 e->sir_address = args->sir_address;
665 e->next_hop = args->next_hop_address;
666 e->csum_mode = args->csum_mode;
669 //Construct ILA address
673 e->ila_address = e->sir_address;
676 e->ila_address.as_u64[0] = args->locator;
677 e->ila_address.as_u64[1] = args->sir_address.as_u64[1];
680 e->ila_address.as_u64[0] = args->locator;
681 e->ila_address.as_u8[8] = (ILA_TYPE_VNID6 << 1);
682 e->ila_address.as_u32[2] |= args->vnid;
683 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
686 e->ila_address.as_u64[0] = args->locator;
687 e->ila_address.as_u8[8] = (ILA_TYPE_VNIDM << 1);
688 e->ila_address.as_u32[2] |= args->vnid;
689 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
690 e->ila_address.as_u8[12] |= args->sir_address.as_u8[2] << 4;
693 clib_warning ("ILA type '%U' is not supported", format_ila_type,
698 //Modify ILA checksum if necessary
699 if (e->csum_mode == ILA_CSUM_MODE_NEUTRAL_MAP)
701 ip_csum_t csum = e->ila_address.as_u16[7];
703 for (i = 0; i < 4; i++)
705 csum = ip_csum_sub_even (csum, e->sir_address.as_u32[i]);
706 csum = ip_csum_add_even (csum, e->ila_address.as_u32[i]);
708 csum = ip_csum_add_even (csum, clib_host_to_net_u16 (0x1000));
709 e->ila_address.as_u16[7] = ip_csum_fold (csum);
710 e->ila_address.as_u8[8] |= 0x10;
713 //Create entry with the sir address
714 kv.key[0] = e->sir_address.as_u64[0];
715 kv.key[1] = e->sir_address.as_u64[1];
717 kv.value = e - ilm->entries;
718 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
721 if (!ip6_address_is_zero(&e->next_hop))
724 * become a child of the FIB netry for the next-hop
725 * so we are informed when its forwarding changes
727 fib_prefix_t next_hop = {
732 .fp_proto = FIB_PROTOCOL_IP6,
735 e->next_hop_fib_entry_index =
736 fib_table_entry_special_add(0,
739 FIB_ENTRY_FLAG_NONE);
740 e->next_hop_child_index =
741 fib_entry_child_add(e->next_hop_fib_entry_index,
746 * Create a route that results in the ILA entry
748 dpo_id_t dpo = DPO_INVALID;
751 .ip6 = e->ila_address,
754 .fp_proto = FIB_PROTOCOL_IP6,
757 dpo_set(&dpo, ila_dpo_type, DPO_PROTO_IP6, e - ilm->entries);
759 fib_table_entry_special_dpo_add(0,
761 FIB_SOURCE_PLUGIN_HI,
762 FIB_ENTRY_FLAG_EXCLUSIVE,
767 * finally stack the ILA entry so it will forward to the next-hop
775 kv.key[0] = args->sir_address.as_u64[0];
776 kv.key[1] = args->sir_address.as_u64[1];
779 if ((BV (clib_bihash_search) (&ilm->id_to_entry_table, &kv, &value) <
785 e = &ilm->entries[value.value];
787 if (!ip6_address_is_zero(&e->next_hop))
791 .ip6 = e->ila_address,
794 .fp_proto = FIB_PROTOCOL_IP6,
797 fib_table_entry_special_remove(0, &pfx, FIB_SOURCE_PLUGIN_HI);
799 * remove this ILA entry as child of the FIB netry for the next-hop
801 fib_entry_child_remove(e->next_hop_fib_entry_index,
802 e->next_hop_child_index);
803 fib_table_entry_delete_index(e->next_hop_fib_entry_index,
805 e->next_hop_fib_entry_index = FIB_NODE_INDEX_INVALID;
807 dpo_reset (&e->ila_dpo);
809 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
811 pool_put (ilm->entries, e);
817 ila_interface (u32 sw_if_index, u8 disable)
819 vnet_feature_enable_disable ("ip4-unicast", "sir-to-ila", sw_if_index,
825 VLIB_PLUGIN_REGISTER () = {
826 .version = VPP_BUILD_VER,
827 .description = "Identifier-locator addressing for IPv6",
831 u8 *format_ila_dpo (u8 * s, va_list * va)
833 index_t index = va_arg (*va, index_t);
834 CLIB_UNUSED(u32 indent) = va_arg (*va, u32);
835 ila_main_t *ilm = &ila_main;
836 ila_entry_t *ie = pool_elt_at_index (ilm->entries, index);
837 return format(s, "ILA: idx:%d sir:%U",
839 format_ip6_address, &ie->sir_address);
843 * @brief no-op lock function.
844 * The lifetime of the ILA entry is managed by the control plane
847 ila_dpo_lock (dpo_id_t *dpo)
852 * @brief no-op unlock function.
853 * The lifetime of the ILA entry is managed by the control plane
856 ila_dpo_unlock (dpo_id_t *dpo)
860 const static dpo_vft_t ila_vft = {
861 .dv_lock = ila_dpo_lock,
862 .dv_unlock = ila_dpo_unlock,
863 .dv_format = format_ila_dpo,
865 const static char* const ila_ip6_nodes[] =
870 const static char* const * const ila_nodes[DPO_PROTO_NUM] =
872 [DPO_PROTO_IP6] = ila_ip6_nodes,
876 ila_fib_node_get_node (fib_node_index_t index)
878 ila_main_t *ilm = &ila_main;
879 ila_entry_t *ie = pool_elt_at_index (ilm->entries, index);
881 return (&ie->ila_fib_node);
885 * @brief no-op unlock function.
886 * The lifetime of the ILA entry is managed by the control plane
889 ila_fib_node_last_lock_gone (fib_node_t *node)
894 ila_entry_from_fib_node (fib_node_t *node)
896 return ((ila_entry_t*)(((char*)node) -
897 STRUCT_OFFSET_OF(ila_entry_t, ila_fib_node)));
902 * Callback function invoked when the forwarding changes for the ILA next-hop
904 static fib_node_back_walk_rc_t
905 ila_fib_node_back_walk_notify (fib_node_t *node,
906 fib_node_back_walk_ctx_t *ctx)
908 ila_entry_stack(ila_entry_from_fib_node(node));
910 return (FIB_NODE_BACK_WALK_CONTINUE);
914 * ILA's FIB graph node virtual function table
916 static const fib_node_vft_t ila_fib_node_vft = {
917 .fnv_get = ila_fib_node_get_node,
918 .fnv_last_lock = ila_fib_node_last_lock_gone,
919 .fnv_back_walk = ila_fib_node_back_walk_notify,
923 ila_init (vlib_main_t * vm)
925 ila_main_t *ilm = &ila_main;
928 ilm->lookup_table_nbuckets = ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS;
929 ilm->lookup_table_nbuckets = 1 << max_log2 (ilm->lookup_table_nbuckets);
930 ilm->lookup_table_size = ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE;
932 BV (clib_bihash_init) (&ilm->id_to_entry_table,
933 "ila id to entry index table",
934 ilm->lookup_table_nbuckets, ilm->lookup_table_size);
936 ila_dpo_type = dpo_register_new_type(&ila_vft, ila_nodes);
937 ila_fib_node_type = fib_node_register_new_type(&ila_fib_node_vft);
942 VLIB_INIT_FUNCTION (ila_init);
944 static clib_error_t *
945 ila_entry_command_fn (vlib_main_t * vm,
946 unformat_input_t * input, vlib_cli_command_t * cmd)
948 unformat_input_t _line_input, *line_input = &_line_input;
949 ila_add_del_entry_args_t args = { 0 };
952 clib_error_t *error = 0;
954 args.type = ILA_TYPE_IID;
955 args.csum_mode = ILA_CSUM_MODE_NO_ACTION;
956 args.local_adj_index = ~0;
957 args.dir = ILA_DIR_BIDIR;
959 if (!unformat_user (input, unformat_line_input, line_input))
962 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
964 if (unformat (line_input, "type %U", unformat_ila_type, &args.type))
967 (line_input, "sir-address %U", unformat_ip6_address,
971 (line_input, "locator %U", unformat_half_ip6_address,
975 (line_input, "csum-mode %U", unformat_ila_csum_mode,
978 else if (unformat (line_input, "vnid %x", &args.vnid))
981 (line_input, "next-hop %U", unformat_ip6_address,
982 &args.next_hop_address))
985 (line_input, "direction %U", unformat_ila_direction, &args.dir))
987 else if (unformat (line_input, "del"))
991 error = clib_error_return (0, "parse error: '%U'",
992 format_unformat_error, line_input);
999 error = clib_error_return (0, "Specified a next hop");
1003 if ((ret = ila_add_del_entry (&args)))
1005 error = clib_error_return (0, "ila_add_del_entry returned error %d", ret);
1010 unformat_free (line_input);
1015 VLIB_CLI_COMMAND (ila_entry_command, static) =
1017 .path = "ila entry",
1018 .short_help = "ila entry [type <type>] [sir-address <address>] [locator <locator>] [vnid <hex-vnid>]"
1019 " [adj-index <adj-index>] [next-hop <next-hop>] [direction (bidir|sir2ila|ila2sir)]"
1020 " [csum-mode (no-action|neutral-map|transport-adjust)] [del]",
1021 .function = ila_entry_command_fn,
1024 static clib_error_t *
1025 ila_interface_command_fn (vlib_main_t * vm,
1026 unformat_input_t * input, vlib_cli_command_t * cmd)
1028 vnet_main_t *vnm = vnet_get_main ();
1029 u32 sw_if_index = ~0;
1032 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1034 return clib_error_return (0, "Invalid interface name");
1037 if (unformat (input, "disable"))
1043 if ((ret = ila_interface (sw_if_index, disable)))
1044 return clib_error_return (0, "ila_interface returned error %d", ret);
1049 VLIB_CLI_COMMAND (ila_interface_command, static) =
1051 .path = "ila interface",
1052 .short_help = "ila interface <interface-name> [disable]",
1053 .function = ila_interface_command_fn,
1056 static clib_error_t *
1057 ila_show_entries_command_fn (vlib_main_t * vm,
1058 unformat_input_t * input,
1059 vlib_cli_command_t * cmd)
1061 vnet_main_t *vnm = vnet_get_main ();
1062 ila_main_t *ilm = &ila_main;
1065 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, NULL);
1066 pool_foreach (e, ilm->entries,
1068 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, e);
1074 VLIB_CLI_COMMAND (ila_show_entries_command, static) =
1076 .path = "show ila entries",
1077 .short_help = "show ila entries",
1078 .function = ila_show_entries_command_fn,