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>
22 static ila_main_t ila_main;
24 #define ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
25 #define ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE (32<<20)
27 #define foreach_ila_error \
28 _(NONE, "valid ILA packets")
31 #define _(sym,str) ILA_ERROR_##sym,
37 static char *ila_error_strings[] = {
38 #define _(sym,string) string,
44 ILA_ILA2SIR_NEXT_DROP,
50 ip6_address_t initial_dst;
52 } ila_ila2sir_trace_t;
54 static ila_entry_t ila_sir2ila_default_entry = {
55 .csum_mode = ILA_CSUM_MODE_NO_ACTION,
57 .dir = ILA_DIR_ILA2SIR, //Will pass the packet with no
61 * @brief Dynamically registered DPO Type for ILA
63 static dpo_type_t ila_dpo_type;
66 * @brief Dynamically registered FIB node type for ILA
68 static fib_node_type_t ila_fib_node_type;
71 format_half_ip6_address (u8 * s, va_list * va)
73 u64 v = clib_net_to_host_u64 (va_arg (*va, u64));
75 return format (s, "%04x:%04x:%04x:%04x",
76 v >> 48, (v >> 32) & 0xffff, (v >> 16) & 0xffff, v & 0xffff);
81 format_ila_direction (u8 * s, va_list * args)
83 ila_direction_t t = va_arg (*args, ila_direction_t);
85 if (t == ILA_DIR_##i) \
89 return format (s, "invalid_ila_direction");
93 format_csum_mode (u8 * s, va_list * va)
95 ila_csum_mode_t csum_mode = va_arg (*va, ila_csum_mode_t);
101 case ILA_CSUM_MODE_##i: \
104 ila_csum_foreach_type
107 txt = "invalid_ila_csum_mode";
110 return format (s, txt);
114 format_ila_type (u8 * s, va_list * args)
116 ila_type_t t = va_arg (*args, ila_type_t);
118 if (t == ILA_TYPE_##i) \
119 return format(s, st);
122 return format (s, "invalid_ila_type");
126 format_ila_entry (u8 * s, va_list * va)
128 vnet_main_t *vnm = va_arg (*va, vnet_main_t *);
129 ila_entry_t *e = va_arg (*va, ila_entry_t *);
133 return format (s, "%-15s%=40s%=40s%+16s%+18s%+11s", "Type", "SIR Address",
134 "ILA Address", "Checksum Mode", "Direction", "Next DPO");
138 if (ip6_address_is_zero(&e->next_hop))
140 return format (s, "%-15U%=40U%=40U%18U%11U%s",
141 format_ila_type, e->type,
142 format_ip6_address, &e->sir_address,
143 format_ip6_address, &e->ila_address,
144 format_csum_mode, e->csum_mode,
145 format_ila_direction, e->dir,
150 return format (s, "%-15U%=40U%=40U%18U%11U%U",
151 format_ila_type, e->type,
152 format_ip6_address, &e->sir_address,
153 format_ip6_address, &e->ila_address,
154 format_csum_mode, e->csum_mode,
155 format_ila_direction, e->dir,
156 format_dpo_id, &e->ila_dpo, 0);
164 format_ila_ila2sir_trace (u8 * s, va_list * args)
166 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
167 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
168 ila_ila2sir_trace_t *t = va_arg (*args, ila_ila2sir_trace_t *);
170 "ILA -> SIR adj index: %d entry index: %d initial_dst: %U",
171 t->adj_index, t->ila_index, format_ip6_address,
176 unformat_ila_direction (unformat_input_t * input, va_list * args)
178 ila_direction_t *result = va_arg (*args, ila_direction_t *);
180 if (unformat(input, s)) \
182 *result = ILA_DIR_##i; \
186 ila_foreach_direction
192 unformat_ila_type (unformat_input_t * input, va_list * args)
194 ila_type_t *result = va_arg (*args, ila_type_t *);
196 if (unformat(input, s)) \
198 *result = ILA_TYPE_##i; \
208 unformat_ila_csum_mode (unformat_input_t * input, va_list * args)
210 ila_csum_mode_t *result = va_arg (*args, ila_csum_mode_t *);
211 if (unformat (input, "none") || unformat (input, "no-action"))
213 *result = ILA_CSUM_MODE_NO_ACTION;
216 if (unformat (input, "neutral-map"))
218 *result = ILA_CSUM_MODE_NEUTRAL_MAP;
221 if (unformat (input, "adjust-transport"))
223 *result = ILA_CSUM_MODE_ADJUST_TRANSPORT;
230 unformat_half_ip6_address (unformat_input_t * input, va_list * args)
232 u64 *result = va_arg (*args, u64 *);
235 if (!unformat (input, "%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3]))
238 if (a[0] > 0xFFFF || a[1] > 0xFFFF || a[2] > 0xFFFF || a[3] > 0xFFFF)
241 *result = clib_host_to_net_u64 ((((u64) a[0]) << 48) |
242 (((u64) a[1]) << 32) |
243 (((u64) a[2]) << 16) | (((u64) a[3])));
248 static vlib_node_registration_t ila_ila2sir_node;
251 ila_ila2sir (vlib_main_t * vm,
252 vlib_node_runtime_t * node, vlib_frame_t * frame)
254 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
255 ila_main_t *ilm = &ila_main;
257 from = vlib_frame_vector_args (frame);
258 n_left_from = frame->n_vectors;
259 next_index = node->cached_next_index;
261 while (n_left_from > 0)
263 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
265 while (n_left_from >= 4 && n_left_to_next >= 2)
268 vlib_buffer_t *p0, *p1;
269 ila_entry_t *ie0, *ie1;
270 ip6_header_t *ip60, *ip61;
271 ip6_address_t *sir_address0, *sir_address1;
274 vlib_buffer_t *p2, *p3;
276 p2 = vlib_get_buffer (vm, from[2]);
277 p3 = vlib_get_buffer (vm, from[3]);
279 vlib_prefetch_buffer_header (p2, LOAD);
280 vlib_prefetch_buffer_header (p3, LOAD);
281 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
282 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
285 pi0 = to_next[0] = from[0];
286 pi1 = to_next[1] = from[1];
292 p0 = vlib_get_buffer (vm, pi0);
293 p1 = vlib_get_buffer (vm, pi1);
294 ip60 = vlib_buffer_get_current (p0);
295 ip61 = vlib_buffer_get_current (p1);
296 sir_address0 = &ip60->dst_address;
297 sir_address1 = &ip61->dst_address;
298 ie0 = pool_elt_at_index (ilm->entries,
299 vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
300 ie1 = pool_elt_at_index (ilm->entries,
301 vnet_buffer (p1)->ip.adj_index[VLIB_TX]);
303 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
305 ila_ila2sir_trace_t *tr =
306 vlib_add_trace (vm, node, p0, sizeof (*tr));
307 tr->ila_index = ie0 - ilm->entries;
308 tr->initial_dst = ip60->dst_address;
309 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
312 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
314 ila_ila2sir_trace_t *tr =
315 vlib_add_trace (vm, node, p1, sizeof (*tr));
316 tr->ila_index = ie1 - ilm->entries;
317 tr->initial_dst = ip61->dst_address;
318 tr->adj_index = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
321 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
322 sir_address1 = (ie1->dir != ILA_DIR_SIR2ILA) ? &ie1->sir_address : sir_address1;
323 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
324 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
325 ip61->dst_address.as_u64[0] = sir_address1->as_u64[0];
326 ip61->dst_address.as_u64[1] = sir_address1->as_u64[1];
328 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_dpo.dpoi_index;
329 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = ie1->ila_dpo.dpoi_index;
331 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
332 n_left_to_next, pi0, pi1,
333 ie0->ila_dpo.dpoi_next_node,
334 ie1->ila_dpo.dpoi_next_node);
338 while (n_left_from > 0 && n_left_to_next > 0)
344 ip6_address_t *sir_address0;
346 pi0 = to_next[0] = from[0];
352 p0 = vlib_get_buffer (vm, pi0);
353 ip60 = vlib_buffer_get_current (p0);
354 sir_address0 = &ip60->dst_address;
355 ie0 = pool_elt_at_index (ilm->entries,
356 vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
358 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
360 ila_ila2sir_trace_t *tr =
361 vlib_add_trace (vm, node, p0, sizeof (*tr));
362 tr->ila_index = ie0 ? (ie0 - ilm->entries) : ~0;
363 tr->initial_dst = ip60->dst_address;
364 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
367 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
368 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
369 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
370 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_dpo.dpoi_index;
372 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
374 ie0->ila_dpo.dpoi_next_node);
376 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
379 return frame->n_vectors;
383 VLIB_REGISTER_NODE (ila_ila2sir_node, static) =
385 .function = ila_ila2sir,
386 .name = "ila-to-sir",
387 .vector_size = sizeof (u32),
388 .format_trace = format_ila_ila2sir_trace,
389 .n_errors = ILA_N_ERROR,
390 .error_strings = ila_error_strings,
391 .n_next_nodes = ILA_ILA2SIR_N_NEXT,
394 [ILA_ILA2SIR_NEXT_DROP] = "error-drop"
401 ILA_SIR2ILA_NEXT_DROP,
403 } ila_sir2ila_next_t;
408 ip6_address_t initial_dst;
409 } ila_sir2ila_trace_t;
412 format_ila_sir2ila_trace (u8 * s, va_list * args)
414 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
415 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
416 ila_sir2ila_trace_t *t = va_arg (*args, ila_sir2ila_trace_t *);
418 return format (s, "SIR -> ILA entry index: %d initial_dst: %U",
419 t->ila_index, format_ip6_address, &t->initial_dst);
422 static vlib_node_registration_t ila_sir2ila_node;
425 ila_sir2ila (vlib_main_t * vm,
426 vlib_node_runtime_t * node, vlib_frame_t * frame)
428 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
429 ila_main_t *ilm = &ila_main;
431 from = vlib_frame_vector_args (frame);
432 n_left_from = frame->n_vectors;
433 next_index = node->cached_next_index;
435 while (n_left_from > 0)
437 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
439 while (n_left_from >= 4 && n_left_to_next >= 2)
442 vlib_buffer_t *p0, *p1;
443 ip6_header_t *ip60, *ip61;
444 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
445 u32 next1 = ILA_SIR2ILA_NEXT_DROP;
446 BVT (clib_bihash_kv) kv0, value0;
447 BVT (clib_bihash_kv) kv1, value1;
448 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
449 ila_entry_t *ie1 = &ila_sir2ila_default_entry;
450 ip6_address_t *ila_address0, *ila_address1;
453 vlib_buffer_t *p2, *p3;
455 p2 = vlib_get_buffer (vm, from[2]);
456 p3 = vlib_get_buffer (vm, from[3]);
458 vlib_prefetch_buffer_header (p2, LOAD);
459 vlib_prefetch_buffer_header (p3, LOAD);
460 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
461 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
464 pi0 = to_next[0] = from[0];
465 pi1 = to_next[1] = from[1];
471 p0 = vlib_get_buffer (vm, pi0);
472 p1 = vlib_get_buffer (vm, pi1);
473 ip60 = vlib_buffer_get_current (p0);
474 ip61 = vlib_buffer_get_current (p1);
475 ila_address0 = &ip60->dst_address;
476 ila_address1 = &ip61->dst_address;
477 kv0.key[0] = ip60->dst_address.as_u64[0];
478 kv0.key[1] = ip60->dst_address.as_u64[1];
480 kv1.key[0] = ip61->dst_address.as_u64[0];
481 kv1.key[1] = ip61->dst_address.as_u64[1];
484 if (PREDICT_TRUE((BV (clib_bihash_search)
485 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
486 ie0 = &ilm->entries[value0.value];
487 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
490 if ((BV (clib_bihash_search)
491 (&ilm->id_to_entry_table, &kv1, &value1)) == 0) {
492 ie1 = &ilm->entries[value1.value];
493 ila_address1 = (ie1->dir != ILA_DIR_ILA2SIR) ? &ie1->ila_address : ila_address1;
496 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
498 ila_sir2ila_trace_t *tr =
499 vlib_add_trace (vm, node, p0, sizeof (*tr));
501 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
502 tr->initial_dst = ip60->dst_address;
505 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
507 ila_sir2ila_trace_t *tr =
508 vlib_add_trace (vm, node, p1, sizeof (*tr));
510 (ie1 != &ila_sir2ila_default_entry) ? (ie1 - ilm->entries) : ~0;
511 tr->initial_dst = ip61->dst_address;
514 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
515 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
516 ip61->dst_address.as_u64[0] = ila_address1->as_u64[0];
517 ip61->dst_address.as_u64[1] = ila_address1->as_u64[1];
519 vnet_feature_next (vnet_buffer (p0)->sw_if_index[VLIB_RX], &next0, p0);
520 vnet_feature_next (vnet_buffer (p1)->sw_if_index[VLIB_RX], &next1, p1);
522 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
523 n_left_to_next, pi0, pi1, next0,
528 while (n_left_from > 0 && n_left_to_next > 0)
533 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
534 BVT (clib_bihash_kv) kv0, value0;
535 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
536 ip6_address_t *ila_address0;
538 pi0 = to_next[0] = from[0];
544 p0 = vlib_get_buffer (vm, pi0);
545 ip60 = vlib_buffer_get_current (p0);
546 ila_address0 = &ip60->dst_address;
548 kv0.key[0] = ip60->dst_address.as_u64[0];
549 kv0.key[1] = ip60->dst_address.as_u64[1];
552 if (PREDICT_TRUE((BV (clib_bihash_search)
553 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
554 ie0 = &ilm->entries[value0.value];
555 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
558 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
560 ila_sir2ila_trace_t *tr =
561 vlib_add_trace (vm, node, p0, sizeof (*tr));
563 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
564 tr->initial_dst = ip60->dst_address;
567 //This operation should do everything for any type (except vnid4 obviously)
568 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
569 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
571 vnet_feature_next (vnet_buffer (p0)->sw_if_index[VLIB_RX], &next0, p0);
573 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
574 n_left_to_next, pi0, next0);
576 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
579 return frame->n_vectors;
583 VLIB_REGISTER_NODE (ila_sir2ila_node, static) =
585 .function = ila_sir2ila,.name = "sir-to-ila",
586 .vector_size = sizeof (u32),
587 .format_trace = format_ila_sir2ila_trace,
588 .n_errors = ILA_N_ERROR,
589 .error_strings = ila_error_strings,
590 .n_next_nodes = ILA_SIR2ILA_N_NEXT,
593 [ILA_SIR2ILA_NEXT_DROP] = "error-drop"
599 VNET_FEATURE_INIT (ila_sir2ila, static) =
601 .arc_name = "ip6-unicast",
602 .node_name = "sir-to-ila",
603 .runs_before = VNET_FEATURES ("ip6-lookup"),
608 ila_entry_stack (ila_entry_t *ie)
611 * restack on the next-hop's FIB entry
613 dpo_stack(ila_dpo_type,
616 fib_entry_contribute_ip_forwarding(
617 ie->next_hop_fib_entry_index));
621 ila_add_del_entry (ila_add_del_entry_args_t * args)
623 ila_main_t *ilm = &ila_main;
624 BVT (clib_bihash_kv) kv, value;
627 if (args->type == ILA_TYPE_IID || args->type == ILA_TYPE_LUID)
629 if ((args->sir_address.as_u8[8] >> 5) != args->type)
631 clib_warning ("Incorrect SIR address (ILA type mismatch %d %d)",
632 args->sir_address.as_u8[8] >> 1, args->type);
635 if (args->sir_address.as_u8[8] & 0x10)
637 clib_warning ("Checksum bit should not be set in SIR address");
641 else if (args->type == ILA_TYPE_VNIDM)
643 if (args->sir_address.as_u8[0] != 0xff ||
644 (args->sir_address.as_u8[1] & 0xf0) != 0xf0)
646 clib_warning ("SIR multicast address must start with fff");
649 if (args->sir_address.as_u16[1] || args->sir_address.as_u16[2] ||
650 args->sir_address.as_u16[3] || args->sir_address.as_u16[4] ||
651 args->sir_address.as_u16[5] || (args->sir_address.as_u8[12] & 0xf0))
653 clib_warning ("SIR multicast address must start with fff");
661 pool_get (ilm->entries, e);
662 e->type = args->type;
663 e->sir_address = args->sir_address;
664 e->next_hop = args->next_hop_address;
665 e->csum_mode = args->csum_mode;
668 //Construct ILA address
672 e->ila_address = e->sir_address;
675 e->ila_address.as_u64[0] = args->locator;
676 e->ila_address.as_u64[1] = args->sir_address.as_u64[1];
679 e->ila_address.as_u64[0] = args->locator;
680 e->ila_address.as_u8[8] = (ILA_TYPE_VNID6 << 1);
681 e->ila_address.as_u32[2] |= args->vnid;
682 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
685 e->ila_address.as_u64[0] = args->locator;
686 e->ila_address.as_u8[8] = (ILA_TYPE_VNIDM << 1);
687 e->ila_address.as_u32[2] |= args->vnid;
688 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
689 e->ila_address.as_u8[12] |= args->sir_address.as_u8[2] << 4;
692 clib_warning ("ILA type '%U' is not supported", format_ila_type,
697 //Modify ILA checksum if necessary
698 if (e->csum_mode == ILA_CSUM_MODE_NEUTRAL_MAP)
700 ip_csum_t csum = e->ila_address.as_u16[7];
702 for (i = 0; i < 4; i++)
704 csum = ip_csum_sub_even (csum, e->sir_address.as_u32[i]);
705 csum = ip_csum_add_even (csum, e->ila_address.as_u32[i]);
707 csum = ip_csum_add_even (csum, clib_host_to_net_u16 (0x1000));
708 e->ila_address.as_u16[7] = ip_csum_fold (csum);
709 e->ila_address.as_u8[8] |= 0x10;
712 //Create entry with the sir address
713 kv.key[0] = e->sir_address.as_u64[0];
714 kv.key[1] = e->sir_address.as_u64[1];
716 kv.value = e - ilm->entries;
717 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
720 if (!ip6_address_is_zero(&e->next_hop))
723 * become a child of the FIB netry for the next-hop
724 * so we are informed when its forwarding changes
726 fib_prefix_t next_hop = {
731 .fp_proto = FIB_PROTOCOL_IP6,
734 e->next_hop_fib_entry_index =
735 fib_table_entry_special_add(0,
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 (vlib_main_t * vm, vnet_plugin_handoff_t * h,
828 clib_error_t *error = 0;
833 u8 *format_ila_dpo (u8 * s, va_list * va)
835 index_t index = va_arg (*va, index_t);
836 CLIB_UNUSED(u32 indent) = va_arg (*va, u32);
837 ila_main_t *ilm = &ila_main;
838 ila_entry_t *ie = pool_elt_at_index (ilm->entries, index);
839 return format(s, "ILA: idx:%d sir:%U",
841 format_ip6_address, &ie->sir_address);
845 * @brief no-op lock function.
846 * The lifetime of the ILA entry is managed by the control plane
849 ila_dpo_lock (dpo_id_t *dpo)
854 * @brief no-op unlock function.
855 * The lifetime of the ILA entry is managed by the control plane
858 ila_dpo_unlock (dpo_id_t *dpo)
862 const static dpo_vft_t ila_vft = {
863 .dv_lock = ila_dpo_lock,
864 .dv_unlock = ila_dpo_unlock,
865 .dv_format = format_ila_dpo,
867 const static char* const ila_ip6_nodes[] =
872 const static char* const * const ila_nodes[DPO_PROTO_NUM] =
874 [DPO_PROTO_IP6] = ila_ip6_nodes,
878 ila_fib_node_get_node (fib_node_index_t index)
880 ila_main_t *ilm = &ila_main;
881 ila_entry_t *ie = pool_elt_at_index (ilm->entries, index);
883 return (&ie->ila_fib_node);
887 * @brief no-op unlock function.
888 * The lifetime of the ILA entry is managed by the control plane
891 ila_fib_node_last_lock_gone (fib_node_t *node)
896 ila_entry_from_fib_node (fib_node_t *node)
898 return ((ila_entry_t*)(((char*)node) -
899 STRUCT_OFFSET_OF(ila_entry_t, ila_fib_node)));
904 * Callback function invoked when the forwarding changes for the ILA next-hop
906 static fib_node_back_walk_rc_t
907 ila_fib_node_back_walk_notify (fib_node_t *node,
908 fib_node_back_walk_ctx_t *ctx)
910 ila_entry_stack(ila_entry_from_fib_node(node));
912 return (FIB_NODE_BACK_WALK_CONTINUE);
916 * ILA's FIB graph node virtual function table
918 static const fib_node_vft_t ila_fib_node_vft = {
919 .fnv_get = ila_fib_node_get_node,
920 .fnv_last_lock = ila_fib_node_last_lock_gone,
921 .fnv_back_walk = ila_fib_node_back_walk_notify,
925 ila_init (vlib_main_t * vm)
927 ila_main_t *ilm = &ila_main;
930 ilm->lookup_table_nbuckets = ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS;
931 ilm->lookup_table_nbuckets = 1 << max_log2 (ilm->lookup_table_nbuckets);
932 ilm->lookup_table_size = ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE;
934 BV (clib_bihash_init) (&ilm->id_to_entry_table,
935 "ila id to entry index table",
936 ilm->lookup_table_nbuckets, ilm->lookup_table_size);
938 ila_dpo_type = dpo_register_new_type(&ila_vft, ila_nodes);
939 ila_fib_node_type = fib_node_register_new_type(&ila_fib_node_vft);
944 VLIB_INIT_FUNCTION (ila_init);
946 static clib_error_t *
947 ila_entry_command_fn (vlib_main_t * vm,
948 unformat_input_t * input, vlib_cli_command_t * cmd)
950 unformat_input_t _line_input, *line_input = &_line_input;
951 ila_add_del_entry_args_t args = { 0 };
955 args.type = ILA_TYPE_IID;
956 args.csum_mode = ILA_CSUM_MODE_NO_ACTION;
957 args.local_adj_index = ~0;
958 args.dir = ILA_DIR_BIDIR;
960 if (!unformat_user (input, unformat_line_input, line_input))
963 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
965 if (unformat (line_input, "type %U", unformat_ila_type, &args.type))
968 (line_input, "sir-address %U", unformat_ip6_address,
972 (line_input, "locator %U", unformat_half_ip6_address,
976 (line_input, "csum-mode %U", unformat_ila_csum_mode,
979 else if (unformat (line_input, "vnid %x", &args.vnid))
982 (line_input, "next-hop %U", unformat_ip6_address,
983 &args.next_hop_address))
986 (line_input, "direction %U", unformat_ila_direction, &args.dir))
988 else if (unformat (line_input, "del"))
991 return clib_error_return (0, "parse error: '%U'",
992 format_unformat_error, line_input);
995 unformat_free (line_input);
998 return clib_error_return (0, "Specified a next hop");
1000 if ((ret = ila_add_del_entry (&args)))
1001 return clib_error_return (0, "ila_add_del_entry returned error %d", ret);
1006 VLIB_CLI_COMMAND (ila_entry_command, static) =
1008 .path = "ila entry",
1009 .short_help = "ila entry [type <type>] [sir-address <address>] [locator <locator>] [vnid <hex-vnid>]"
1010 " [adj-index <adj-index>] [next-hop <next-hop>] [direction (bidir|sir2ila|ila2sir)]"
1011 " [csum-mode (no-action|neutral-map|transport-adjust)] [del]",
1012 .function = ila_entry_command_fn,
1015 static clib_error_t *
1016 ila_interface_command_fn (vlib_main_t * vm,
1017 unformat_input_t * input, vlib_cli_command_t * cmd)
1019 vnet_main_t *vnm = vnet_get_main ();
1020 u32 sw_if_index = ~0;
1023 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1025 return clib_error_return (0, "Invalid interface name");
1028 if (unformat (input, "disable"))
1034 if ((ret = ila_interface (sw_if_index, disable)))
1035 return clib_error_return (0, "ila_interface returned error %d", ret);
1040 VLIB_CLI_COMMAND (ila_interface_command, static) =
1042 .path = "ila interface",
1043 .short_help = "ila interface <interface-name> [disable]",
1044 .function = ila_interface_command_fn,
1047 static clib_error_t *
1048 ila_show_entries_command_fn (vlib_main_t * vm,
1049 unformat_input_t * input,
1050 vlib_cli_command_t * cmd)
1052 vnet_main_t *vnm = vnet_get_main ();
1053 ila_main_t *ilm = &ila_main;
1056 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, NULL);
1057 pool_foreach (e, ilm->entries,
1059 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, e);
1065 VLIB_CLI_COMMAND (ila_show_entries_command, static) =
1067 .path = "show ila entries",
1068 .short_help = "show ila entries",
1069 .function = ila_show_entries_command_fn,