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 * FIB source for adding entries
74 static fib_source_t ila_fib_src;
77 format_half_ip6_address (u8 * s, va_list * va)
79 u64 v = clib_net_to_host_u64 (va_arg (*va, u64));
81 return format (s, "%04x:%04x:%04x:%04x",
82 v >> 48, (v >> 32) & 0xffff, (v >> 16) & 0xffff, v & 0xffff);
87 format_ila_direction (u8 * s, va_list * args)
89 ila_direction_t t = va_arg (*args, ila_direction_t);
91 if (t == ILA_DIR_##i) \
95 return format (s, "invalid_ila_direction");
99 format_csum_mode (u8 * s, va_list * va)
101 ila_csum_mode_t csum_mode = va_arg (*va, ila_csum_mode_t);
107 case ILA_CSUM_MODE_##i: \
110 ila_csum_foreach_type
113 txt = "invalid_ila_csum_mode";
116 return format (s, txt);
120 format_ila_type (u8 * s, va_list * args)
122 ila_type_t t = va_arg (*args, ila_type_t);
124 if (t == ILA_TYPE_##i) \
125 return format(s, st);
128 return format (s, "invalid_ila_type");
132 format_ila_entry (u8 * s, va_list * va)
134 vnet_main_t *vnm = va_arg (*va, vnet_main_t *);
135 ila_entry_t *e = va_arg (*va, ila_entry_t *);
139 return format (s, "%-15s%=40s%=40s%+16s%+18s%+11s", "Type", "SIR Address",
140 "ILA Address", "Checksum Mode", "Direction", "Next DPO");
144 if (ip6_address_is_zero(&e->next_hop))
146 return format (s, "%-15U%=40U%=40U%18U%11U%s",
147 format_ila_type, e->type,
148 format_ip6_address, &e->sir_address,
149 format_ip6_address, &e->ila_address,
150 format_csum_mode, e->csum_mode,
151 format_ila_direction, e->dir,
156 return format (s, "%-15U%=40U%=40U%18U%11U%U",
157 format_ila_type, e->type,
158 format_ip6_address, &e->sir_address,
159 format_ip6_address, &e->ila_address,
160 format_csum_mode, e->csum_mode,
161 format_ila_direction, e->dir,
162 format_dpo_id, &e->ila_dpo, 0);
170 format_ila_ila2sir_trace (u8 * s, va_list * args)
172 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
173 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
174 ila_ila2sir_trace_t *t = va_arg (*args, ila_ila2sir_trace_t *);
176 "ILA -> SIR adj index: %d entry index: %d initial_dst: %U",
177 t->adj_index, t->ila_index, format_ip6_address,
182 unformat_ila_direction (unformat_input_t * input, va_list * args)
184 ila_direction_t *result = va_arg (*args, ila_direction_t *);
186 if (unformat(input, s)) \
188 *result = ILA_DIR_##i; \
192 ila_foreach_direction
198 unformat_ila_type (unformat_input_t * input, va_list * args)
200 ila_type_t *result = va_arg (*args, ila_type_t *);
202 if (unformat(input, s)) \
204 *result = ILA_TYPE_##i; \
214 unformat_ila_csum_mode (unformat_input_t * input, va_list * args)
216 ila_csum_mode_t *result = va_arg (*args, ila_csum_mode_t *);
217 if (unformat (input, "none") || unformat (input, "no-action"))
219 *result = ILA_CSUM_MODE_NO_ACTION;
222 if (unformat (input, "neutral-map"))
224 *result = ILA_CSUM_MODE_NEUTRAL_MAP;
227 if (unformat (input, "adjust-transport"))
229 *result = ILA_CSUM_MODE_ADJUST_TRANSPORT;
236 unformat_half_ip6_address (unformat_input_t * input, va_list * args)
238 u64 *result = va_arg (*args, u64 *);
241 if (!unformat (input, "%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3]))
244 if (a[0] > 0xFFFF || a[1] > 0xFFFF || a[2] > 0xFFFF || a[3] > 0xFFFF)
247 *result = clib_host_to_net_u64 ((((u64) a[0]) << 48) |
248 (((u64) a[1]) << 32) |
249 (((u64) a[2]) << 16) | (((u64) a[3])));
254 static vlib_node_registration_t ila_ila2sir_node;
257 ila_ila2sir (vlib_main_t * vm,
258 vlib_node_runtime_t * node, vlib_frame_t * frame)
260 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
261 ila_main_t *ilm = &ila_main;
263 from = vlib_frame_vector_args (frame);
264 n_left_from = frame->n_vectors;
265 next_index = node->cached_next_index;
267 while (n_left_from > 0)
269 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
271 while (n_left_from >= 4 && n_left_to_next >= 2)
274 vlib_buffer_t *p0, *p1;
275 ila_entry_t *ie0, *ie1;
276 ip6_header_t *ip60, *ip61;
277 ip6_address_t *sir_address0, *sir_address1;
280 vlib_buffer_t *p2, *p3;
282 p2 = vlib_get_buffer (vm, from[2]);
283 p3 = vlib_get_buffer (vm, from[3]);
285 vlib_prefetch_buffer_header (p2, LOAD);
286 vlib_prefetch_buffer_header (p3, LOAD);
287 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
288 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
291 pi0 = to_next[0] = from[0];
292 pi1 = to_next[1] = from[1];
298 p0 = vlib_get_buffer (vm, pi0);
299 p1 = vlib_get_buffer (vm, pi1);
300 ip60 = vlib_buffer_get_current (p0);
301 ip61 = vlib_buffer_get_current (p1);
302 sir_address0 = &ip60->dst_address;
303 sir_address1 = &ip61->dst_address;
304 ie0 = pool_elt_at_index (ilm->entries,
305 vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
306 ie1 = pool_elt_at_index (ilm->entries,
307 vnet_buffer (p1)->ip.adj_index[VLIB_TX]);
309 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
311 ila_ila2sir_trace_t *tr =
312 vlib_add_trace (vm, node, p0, sizeof (*tr));
313 tr->ila_index = ie0 - ilm->entries;
314 tr->initial_dst = ip60->dst_address;
315 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
318 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
320 ila_ila2sir_trace_t *tr =
321 vlib_add_trace (vm, node, p1, sizeof (*tr));
322 tr->ila_index = ie1 - ilm->entries;
323 tr->initial_dst = ip61->dst_address;
324 tr->adj_index = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
327 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
328 sir_address1 = (ie1->dir != ILA_DIR_SIR2ILA) ? &ie1->sir_address : sir_address1;
329 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
330 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
331 ip61->dst_address.as_u64[0] = sir_address1->as_u64[0];
332 ip61->dst_address.as_u64[1] = sir_address1->as_u64[1];
334 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_dpo.dpoi_index;
335 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = ie1->ila_dpo.dpoi_index;
337 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
338 n_left_to_next, pi0, pi1,
339 ie0->ila_dpo.dpoi_next_node,
340 ie1->ila_dpo.dpoi_next_node);
344 while (n_left_from > 0 && n_left_to_next > 0)
350 ip6_address_t *sir_address0;
352 pi0 = to_next[0] = from[0];
358 p0 = vlib_get_buffer (vm, pi0);
359 ip60 = vlib_buffer_get_current (p0);
360 sir_address0 = &ip60->dst_address;
361 ie0 = pool_elt_at_index (ilm->entries,
362 vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
364 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
366 ila_ila2sir_trace_t *tr =
367 vlib_add_trace (vm, node, p0, sizeof (*tr));
368 tr->ila_index = ie0 ? (ie0 - ilm->entries) : ~0;
369 tr->initial_dst = ip60->dst_address;
370 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
373 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
374 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
375 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
376 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_dpo.dpoi_index;
378 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
380 ie0->ila_dpo.dpoi_next_node);
382 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
385 return frame->n_vectors;
389 VLIB_REGISTER_NODE (ila_ila2sir_node, static) =
391 .function = ila_ila2sir,
392 .name = "ila-to-sir",
393 .vector_size = sizeof (u32),
394 .format_trace = format_ila_ila2sir_trace,
395 .n_errors = ILA_N_ERROR,
396 .error_strings = ila_error_strings,
397 .n_next_nodes = ILA_ILA2SIR_N_NEXT,
400 [ILA_ILA2SIR_NEXT_DROP] = "error-drop"
407 ILA_SIR2ILA_NEXT_DROP,
409 } ila_sir2ila_next_t;
414 ip6_address_t initial_dst;
415 } ila_sir2ila_trace_t;
418 format_ila_sir2ila_trace (u8 * s, va_list * args)
420 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
421 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
422 ila_sir2ila_trace_t *t = va_arg (*args, ila_sir2ila_trace_t *);
424 return format (s, "SIR -> ILA entry index: %d initial_dst: %U",
425 t->ila_index, format_ip6_address, &t->initial_dst);
428 static vlib_node_registration_t ila_sir2ila_node;
431 ila_sir2ila (vlib_main_t * vm,
432 vlib_node_runtime_t * node, vlib_frame_t * frame)
434 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
435 ila_main_t *ilm = &ila_main;
437 from = vlib_frame_vector_args (frame);
438 n_left_from = frame->n_vectors;
439 next_index = node->cached_next_index;
441 while (n_left_from > 0)
443 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
445 while (n_left_from >= 4 && n_left_to_next >= 2)
448 vlib_buffer_t *p0, *p1;
449 ip6_header_t *ip60, *ip61;
450 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
451 u32 next1 = ILA_SIR2ILA_NEXT_DROP;
452 BVT (clib_bihash_kv) kv0, value0;
453 BVT (clib_bihash_kv) kv1, value1;
454 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
455 ila_entry_t *ie1 = &ila_sir2ila_default_entry;
456 ip6_address_t *ila_address0, *ila_address1;
459 vlib_buffer_t *p2, *p3;
461 p2 = vlib_get_buffer (vm, from[2]);
462 p3 = vlib_get_buffer (vm, from[3]);
464 vlib_prefetch_buffer_header (p2, LOAD);
465 vlib_prefetch_buffer_header (p3, LOAD);
466 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
467 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
470 pi0 = to_next[0] = from[0];
471 pi1 = to_next[1] = from[1];
477 p0 = vlib_get_buffer (vm, pi0);
478 p1 = vlib_get_buffer (vm, pi1);
479 ip60 = vlib_buffer_get_current (p0);
480 ip61 = vlib_buffer_get_current (p1);
481 ila_address0 = &ip60->dst_address;
482 ila_address1 = &ip61->dst_address;
483 kv0.key[0] = ip60->dst_address.as_u64[0];
484 kv0.key[1] = ip60->dst_address.as_u64[1];
486 kv1.key[0] = ip61->dst_address.as_u64[0];
487 kv1.key[1] = ip61->dst_address.as_u64[1];
490 if (PREDICT_TRUE((BV (clib_bihash_search)
491 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
492 ie0 = &ilm->entries[value0.value];
493 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
496 if ((BV (clib_bihash_search)
497 (&ilm->id_to_entry_table, &kv1, &value1)) == 0) {
498 ie1 = &ilm->entries[value1.value];
499 ila_address1 = (ie1->dir != ILA_DIR_ILA2SIR) ? &ie1->ila_address : ila_address1;
502 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
504 ila_sir2ila_trace_t *tr =
505 vlib_add_trace (vm, node, p0, sizeof (*tr));
507 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
508 tr->initial_dst = ip60->dst_address;
511 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
513 ila_sir2ila_trace_t *tr =
514 vlib_add_trace (vm, node, p1, sizeof (*tr));
516 (ie1 != &ila_sir2ila_default_entry) ? (ie1 - ilm->entries) : ~0;
517 tr->initial_dst = ip61->dst_address;
520 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
521 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
522 ip61->dst_address.as_u64[0] = ila_address1->as_u64[0];
523 ip61->dst_address.as_u64[1] = ila_address1->as_u64[1];
525 vnet_feature_next (&next0, p0);
526 vnet_feature_next (&next1, p1);
528 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
529 n_left_to_next, pi0, pi1, next0,
534 while (n_left_from > 0 && n_left_to_next > 0)
539 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
540 BVT (clib_bihash_kv) kv0, value0;
541 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
542 ip6_address_t *ila_address0;
544 pi0 = to_next[0] = from[0];
550 p0 = vlib_get_buffer (vm, pi0);
551 ip60 = vlib_buffer_get_current (p0);
552 ila_address0 = &ip60->dst_address;
554 kv0.key[0] = ip60->dst_address.as_u64[0];
555 kv0.key[1] = ip60->dst_address.as_u64[1];
558 if (PREDICT_TRUE((BV (clib_bihash_search)
559 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
560 ie0 = &ilm->entries[value0.value];
561 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
564 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
566 ila_sir2ila_trace_t *tr =
567 vlib_add_trace (vm, node, p0, sizeof (*tr));
569 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
570 tr->initial_dst = ip60->dst_address;
573 //This operation should do everything for any type (except vnid4 obviously)
574 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
575 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
577 vnet_feature_next (&next0, p0);
579 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
580 n_left_to_next, pi0, next0);
582 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
585 return frame->n_vectors;
589 VLIB_REGISTER_NODE (ila_sir2ila_node, static) =
591 .function = ila_sir2ila,.name = "sir-to-ila",
592 .vector_size = sizeof (u32),
593 .format_trace = format_ila_sir2ila_trace,
594 .n_errors = ILA_N_ERROR,
595 .error_strings = ila_error_strings,
596 .n_next_nodes = ILA_SIR2ILA_N_NEXT,
599 [ILA_SIR2ILA_NEXT_DROP] = "error-drop"
605 VNET_FEATURE_INIT (ila_sir2ila, static) =
607 .arc_name = "ip6-unicast",
608 .node_name = "sir-to-ila",
609 .runs_before = VNET_FEATURES ("ip6-lookup"),
614 ila_entry_stack (ila_entry_t *ie)
617 * restack on the next-hop's FIB entry
619 dpo_stack(ila_dpo_type,
622 fib_entry_contribute_ip_forwarding(
623 ie->next_hop_fib_entry_index));
627 ila_add_del_entry (ila_add_del_entry_args_t * args)
629 ila_main_t *ilm = &ila_main;
630 BVT (clib_bihash_kv) kv, value;
633 if (args->type == ILA_TYPE_IID || args->type == ILA_TYPE_LUID)
635 if ((args->sir_address.as_u8[8] >> 5) != args->type)
637 clib_warning ("Incorrect SIR address (ILA type mismatch %d %d)",
638 args->sir_address.as_u8[8] >> 1, args->type);
641 if (args->sir_address.as_u8[8] & 0x10)
643 clib_warning ("Checksum bit should not be set in SIR address");
647 else if (args->type == ILA_TYPE_VNIDM)
649 if (args->sir_address.as_u8[0] != 0xff ||
650 (args->sir_address.as_u8[1] & 0xf0) != 0xf0)
652 clib_warning ("SIR multicast address must start with fff");
655 if (args->sir_address.as_u16[1] || args->sir_address.as_u16[2] ||
656 args->sir_address.as_u16[3] || args->sir_address.as_u16[4] ||
657 args->sir_address.as_u16[5] || (args->sir_address.as_u8[12] & 0xf0))
659 clib_warning ("SIR multicast address must start with fff");
667 pool_get (ilm->entries, e);
668 e->type = args->type;
669 e->sir_address = args->sir_address;
670 e->next_hop = args->next_hop_address;
671 e->csum_mode = args->csum_mode;
674 //Construct ILA address
678 e->ila_address = e->sir_address;
681 e->ila_address.as_u64[0] = args->locator;
682 e->ila_address.as_u64[1] = args->sir_address.as_u64[1];
685 e->ila_address.as_u64[0] = args->locator;
686 e->ila_address.as_u8[8] = (ILA_TYPE_VNID6 << 1);
687 e->ila_address.as_u32[2] |= args->vnid;
688 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
691 e->ila_address.as_u64[0] = args->locator;
692 e->ila_address.as_u8[8] = (ILA_TYPE_VNIDM << 1);
693 e->ila_address.as_u32[2] |= args->vnid;
694 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
695 e->ila_address.as_u8[12] |= args->sir_address.as_u8[2] << 4;
698 clib_warning ("ILA type '%U' is not supported", format_ila_type,
703 //Modify ILA checksum if necessary
704 if (e->csum_mode == ILA_CSUM_MODE_NEUTRAL_MAP)
706 ip_csum_t csum = e->ila_address.as_u16[7];
708 for (i = 0; i < 4; i++)
710 csum = ip_csum_sub_even (csum, e->sir_address.as_u32[i]);
711 csum = ip_csum_add_even (csum, e->ila_address.as_u32[i]);
713 csum = ip_csum_add_even (csum, clib_host_to_net_u16 (0x1000));
714 e->ila_address.as_u16[7] = ip_csum_fold (csum);
715 e->ila_address.as_u8[8] |= 0x10;
718 //Create entry with the sir address
719 kv.key[0] = e->sir_address.as_u64[0];
720 kv.key[1] = e->sir_address.as_u64[1];
722 kv.value = e - ilm->entries;
723 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
726 if (!ip6_address_is_zero(&e->next_hop))
729 * become a child of the FIB netry for the next-hop
730 * so we are informed when its forwarding changes
732 fib_prefix_t next_hop = {
737 .fp_proto = FIB_PROTOCOL_IP6,
740 e->next_hop_fib_entry_index =
741 fib_table_entry_special_add(0,
744 FIB_ENTRY_FLAG_NONE);
745 e->next_hop_child_index =
746 fib_entry_child_add(e->next_hop_fib_entry_index,
751 * Create a route that results in the ILA entry
753 dpo_id_t dpo = DPO_INVALID;
756 .ip6 = e->ila_address,
759 .fp_proto = FIB_PROTOCOL_IP6,
762 dpo_set(&dpo, ila_dpo_type, DPO_PROTO_IP6, e - ilm->entries);
764 fib_table_entry_special_dpo_add(0,
767 FIB_ENTRY_FLAG_EXCLUSIVE,
772 * finally stack the ILA entry so it will forward to the next-hop
780 kv.key[0] = args->sir_address.as_u64[0];
781 kv.key[1] = args->sir_address.as_u64[1];
784 if ((BV (clib_bihash_search) (&ilm->id_to_entry_table, &kv, &value) <
790 e = &ilm->entries[value.value];
792 if (!ip6_address_is_zero(&e->next_hop))
796 .ip6 = e->ila_address,
799 .fp_proto = FIB_PROTOCOL_IP6,
802 fib_table_entry_special_remove(0, &pfx, ila_fib_src);
804 * remove this ILA entry as child of the FIB netry for the next-hop
806 fib_entry_child_remove(e->next_hop_fib_entry_index,
807 e->next_hop_child_index);
808 fib_table_entry_delete_index(e->next_hop_fib_entry_index,
810 e->next_hop_fib_entry_index = FIB_NODE_INDEX_INVALID;
812 dpo_reset (&e->ila_dpo);
814 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
816 pool_put (ilm->entries, e);
822 ila_interface (u32 sw_if_index, u8 disable)
824 vnet_feature_enable_disable ("ip4-unicast", "sir-to-ila", sw_if_index,
830 VLIB_PLUGIN_REGISTER () = {
831 .version = VPP_BUILD_VER,
832 .description = "Identifier Locator Addressing (ILA) for IPv6",
836 u8 *format_ila_dpo (u8 * s, va_list * va)
838 index_t index = va_arg (*va, index_t);
839 CLIB_UNUSED(u32 indent) = va_arg (*va, u32);
840 ila_main_t *ilm = &ila_main;
841 ila_entry_t *ie = pool_elt_at_index (ilm->entries, index);
842 return format(s, "ILA: idx:%d sir:%U",
844 format_ip6_address, &ie->sir_address);
848 * @brief no-op lock function.
849 * The lifetime of the ILA entry is managed by the control plane
852 ila_dpo_lock (dpo_id_t *dpo)
857 * @brief no-op unlock function.
858 * The lifetime of the ILA entry is managed by the control plane
861 ila_dpo_unlock (dpo_id_t *dpo)
865 const static dpo_vft_t ila_vft = {
866 .dv_lock = ila_dpo_lock,
867 .dv_unlock = ila_dpo_unlock,
868 .dv_format = format_ila_dpo,
870 const static char* const ila_ip6_nodes[] =
875 const static char* const * const ila_nodes[DPO_PROTO_NUM] =
877 [DPO_PROTO_IP6] = ila_ip6_nodes,
881 ila_fib_node_get_node (fib_node_index_t index)
883 ila_main_t *ilm = &ila_main;
884 ila_entry_t *ie = pool_elt_at_index (ilm->entries, index);
886 return (&ie->ila_fib_node);
890 * @brief no-op unlock function.
891 * The lifetime of the ILA entry is managed by the control plane
894 ila_fib_node_last_lock_gone (fib_node_t *node)
899 ila_entry_from_fib_node (fib_node_t *node)
901 return ((ila_entry_t*)(((char*)node) -
902 STRUCT_OFFSET_OF(ila_entry_t, ila_fib_node)));
907 * Callback function invoked when the forwarding changes for the ILA next-hop
909 static fib_node_back_walk_rc_t
910 ila_fib_node_back_walk_notify (fib_node_t *node,
911 fib_node_back_walk_ctx_t *ctx)
913 ila_entry_stack(ila_entry_from_fib_node(node));
915 return (FIB_NODE_BACK_WALK_CONTINUE);
919 * ILA's FIB graph node virtual function table
921 static const fib_node_vft_t ila_fib_node_vft = {
922 .fnv_get = ila_fib_node_get_node,
923 .fnv_last_lock = ila_fib_node_last_lock_gone,
924 .fnv_back_walk = ila_fib_node_back_walk_notify,
928 ila_init (vlib_main_t * vm)
930 ila_main_t *ilm = &ila_main;
933 ilm->lookup_table_nbuckets = ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS;
934 ilm->lookup_table_nbuckets = 1 << max_log2 (ilm->lookup_table_nbuckets);
935 ilm->lookup_table_size = ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE;
937 BV (clib_bihash_init) (&ilm->id_to_entry_table,
938 "ila id to entry index table",
939 ilm->lookup_table_nbuckets, ilm->lookup_table_size);
941 ila_dpo_type = dpo_register_new_type(&ila_vft, ila_nodes);
942 ila_fib_node_type = fib_node_register_new_type(&ila_fib_node_vft);
943 ila_fib_src = fib_source_allocate("ila",
944 FIB_SOURCE_PRIORITY_HI,
945 FIB_SOURCE_BH_SIMPLE);
949 VLIB_INIT_FUNCTION (ila_init);
951 static clib_error_t *
952 ila_entry_command_fn (vlib_main_t * vm,
953 unformat_input_t * input, vlib_cli_command_t * cmd)
955 unformat_input_t _line_input, *line_input = &_line_input;
956 ila_add_del_entry_args_t args = { 0 };
959 clib_error_t *error = 0;
961 args.type = ILA_TYPE_IID;
962 args.csum_mode = ILA_CSUM_MODE_NO_ACTION;
963 args.local_adj_index = ~0;
964 args.dir = ILA_DIR_BIDIR;
966 if (!unformat_user (input, unformat_line_input, line_input))
969 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
971 if (unformat (line_input, "type %U", unformat_ila_type, &args.type))
974 (line_input, "sir-address %U", unformat_ip6_address,
978 (line_input, "locator %U", unformat_half_ip6_address,
982 (line_input, "csum-mode %U", unformat_ila_csum_mode,
985 else if (unformat (line_input, "vnid %x", &args.vnid))
988 (line_input, "next-hop %U", unformat_ip6_address,
989 &args.next_hop_address))
992 (line_input, "direction %U", unformat_ila_direction, &args.dir))
994 else if (unformat (line_input, "del"))
998 error = clib_error_return (0, "parse error: '%U'",
999 format_unformat_error, line_input);
1006 error = clib_error_return (0, "Specified a next hop");
1010 if ((ret = ila_add_del_entry (&args)))
1012 error = clib_error_return (0, "ila_add_del_entry returned error %d", ret);
1017 unformat_free (line_input);
1022 VLIB_CLI_COMMAND (ila_entry_command, static) =
1024 .path = "ila entry",
1025 .short_help = "ila entry [type <type>] [sir-address <address>] [locator <locator>] [vnid <hex-vnid>]"
1026 " [adj-index <adj-index>] [next-hop <next-hop>] [direction (bidir|sir2ila|ila2sir)]"
1027 " [csum-mode (no-action|neutral-map|transport-adjust)] [del]",
1028 .function = ila_entry_command_fn,
1031 static clib_error_t *
1032 ila_interface_command_fn (vlib_main_t * vm,
1033 unformat_input_t * input, vlib_cli_command_t * cmd)
1035 vnet_main_t *vnm = vnet_get_main ();
1036 u32 sw_if_index = ~0;
1039 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1041 return clib_error_return (0, "Invalid interface name");
1044 if (unformat (input, "disable"))
1050 if ((ret = ila_interface (sw_if_index, disable)))
1051 return clib_error_return (0, "ila_interface returned error %d", ret);
1056 VLIB_CLI_COMMAND (ila_interface_command, static) =
1058 .path = "ila interface",
1059 .short_help = "ila interface <interface-name> [disable]",
1060 .function = ila_interface_command_fn,
1063 static clib_error_t *
1064 ila_show_entries_command_fn (vlib_main_t * vm,
1065 unformat_input_t * input,
1066 vlib_cli_command_t * cmd)
1068 vnet_main_t *vnm = vnet_get_main ();
1069 ila_main_t *ilm = &ila_main;
1072 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, NULL);
1073 pool_foreach (e, ilm->entries,
1075 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, e);
1081 VLIB_CLI_COMMAND (ila_show_entries_command, static) =
1083 .path = "show ila entries",
1084 .short_help = "show ila entries",
1085 .function = ila_show_entries_command_fn,