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 ip6_main_t *im = &ip6_main;
429 ip_lookup_main_t *lm = &im->lookup_main;
430 ip_config_main_t *cm = &lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
431 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
432 ila_main_t *ilm = &ila_main;
434 from = vlib_frame_vector_args (frame);
435 n_left_from = frame->n_vectors;
436 next_index = node->cached_next_index;
438 while (n_left_from > 0)
440 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
442 while (n_left_from >= 4 && n_left_to_next >= 2)
445 vlib_buffer_t *p0, *p1;
446 ip6_header_t *ip60, *ip61;
447 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
448 u32 next1 = ILA_SIR2ILA_NEXT_DROP;
449 BVT (clib_bihash_kv) kv0, value0;
450 BVT (clib_bihash_kv) kv1, value1;
451 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
452 ila_entry_t *ie1 = &ila_sir2ila_default_entry;
453 ip6_address_t *ila_address0, *ila_address1;
456 vlib_buffer_t *p2, *p3;
458 p2 = vlib_get_buffer (vm, from[2]);
459 p3 = vlib_get_buffer (vm, from[3]);
461 vlib_prefetch_buffer_header (p2, LOAD);
462 vlib_prefetch_buffer_header (p3, LOAD);
463 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
464 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
467 pi0 = to_next[0] = from[0];
468 pi1 = to_next[1] = from[1];
474 p0 = vlib_get_buffer (vm, pi0);
475 p1 = vlib_get_buffer (vm, pi1);
476 ip60 = vlib_buffer_get_current (p0);
477 ip61 = vlib_buffer_get_current (p1);
478 ila_address0 = &ip60->dst_address;
479 ila_address1 = &ip61->dst_address;
480 kv0.key[0] = ip60->dst_address.as_u64[0];
481 kv0.key[1] = ip60->dst_address.as_u64[1];
483 kv1.key[0] = ip61->dst_address.as_u64[0];
484 kv1.key[1] = ip61->dst_address.as_u64[1];
487 if (PREDICT_TRUE((BV (clib_bihash_search)
488 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
489 ie0 = &ilm->entries[value0.value];
490 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
493 if ((BV (clib_bihash_search)
494 (&ilm->id_to_entry_table, &kv1, &value1)) == 0) {
495 ie1 = &ilm->entries[value1.value];
496 ila_address1 = (ie1->dir != ILA_DIR_ILA2SIR) ? &ie1->ila_address : ila_address1;
499 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
501 ila_sir2ila_trace_t *tr =
502 vlib_add_trace (vm, node, p0, sizeof (*tr));
504 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
505 tr->initial_dst = ip60->dst_address;
508 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
510 ila_sir2ila_trace_t *tr =
511 vlib_add_trace (vm, node, p1, sizeof (*tr));
513 (ie1 != &ila_sir2ila_default_entry) ? (ie1 - ilm->entries) : ~0;
514 tr->initial_dst = ip61->dst_address;
517 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
518 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
519 ip61->dst_address.as_u64[0] = ila_address1->as_u64[0];
520 ip61->dst_address.as_u64[1] = ila_address1->as_u64[1];
522 vnet_get_config_data (&cm->config_main,
523 &p0->current_config_index, &next0, 0);
525 vnet_get_config_data (&cm->config_main,
526 &p1->current_config_index, &next1, 0);
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_get_config_data (&cm->config_main,
578 &p0->current_config_index, &next0, 0);
580 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
581 n_left_to_next, pi0, next0);
583 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
586 return frame->n_vectors;
590 VLIB_REGISTER_NODE (ila_sir2ila_node, static) =
592 .function = ila_sir2ila,.name = "sir-to-ila",
593 .vector_size = sizeof (u32),
594 .format_trace = format_ila_sir2ila_trace,
595 .n_errors = ILA_N_ERROR,
596 .error_strings = ila_error_strings,
597 .n_next_nodes = ILA_SIR2ILA_N_NEXT,
600 [ILA_SIR2ILA_NEXT_DROP] = "error-drop"
606 VNET_IP6_UNICAST_FEATURE_INIT (ila_sir2ila, static) =
608 .node_name = "sir-to-ila",
609 .runs_before = ORDER_CONSTRAINTS{"ip6-lookup", 0},
610 .feature_index = &ila_main.ila_sir2ila_feature_index,
615 ila_entry_stack (ila_entry_t *ie)
618 * restack on the next-hop's FIB entry
620 dpo_stack(ila_dpo_type,
623 fib_entry_contribute_ip_forwarding(
624 ie->next_hop_fib_entry_index));
628 ila_add_del_entry (ila_add_del_entry_args_t * args)
630 ila_main_t *ilm = &ila_main;
631 BVT (clib_bihash_kv) kv, value;
634 if (args->type == ILA_TYPE_IID || args->type == ILA_TYPE_LUID)
636 if ((args->sir_address.as_u8[8] >> 5) != args->type)
638 clib_warning ("Incorrect SIR address (ILA type mismatch %d %d)",
639 args->sir_address.as_u8[8] >> 1, args->type);
642 if (args->sir_address.as_u8[8] & 0x10)
644 clib_warning ("Checksum bit should not be set in SIR address");
648 else if (args->type == ILA_TYPE_VNIDM)
650 if (args->sir_address.as_u8[0] != 0xff ||
651 (args->sir_address.as_u8[1] & 0xf0) != 0xf0)
653 clib_warning ("SIR multicast address must start with fff");
656 if (args->sir_address.as_u16[1] || args->sir_address.as_u16[2] ||
657 args->sir_address.as_u16[3] || args->sir_address.as_u16[4] ||
658 args->sir_address.as_u16[5] || (args->sir_address.as_u8[12] & 0xf0))
660 clib_warning ("SIR multicast address must start with fff");
668 pool_get (ilm->entries, e);
669 e->type = args->type;
670 e->sir_address = args->sir_address;
671 e->next_hop = args->next_hop_address;
672 e->csum_mode = args->csum_mode;
675 //Construct ILA address
679 e->ila_address = e->sir_address;
682 e->ila_address.as_u64[0] = args->locator;
683 e->ila_address.as_u64[1] = args->sir_address.as_u64[1];
686 e->ila_address.as_u64[0] = args->locator;
687 e->ila_address.as_u8[8] = (ILA_TYPE_VNID6 << 1);
688 e->ila_address.as_u32[2] |= args->vnid;
689 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
692 e->ila_address.as_u64[0] = args->locator;
693 e->ila_address.as_u8[8] = (ILA_TYPE_VNIDM << 1);
694 e->ila_address.as_u32[2] |= args->vnid;
695 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
696 e->ila_address.as_u8[12] |= args->sir_address.as_u8[2] << 4;
699 clib_warning ("ILA type '%U' is not supported", format_ila_type,
704 //Modify ILA checksum if necessary
705 if (e->csum_mode == ILA_CSUM_MODE_NEUTRAL_MAP)
707 ip_csum_t csum = e->ila_address.as_u16[7];
709 for (i = 0; i < 4; i++)
711 csum = ip_csum_sub_even (csum, e->sir_address.as_u32[i]);
712 csum = ip_csum_add_even (csum, e->ila_address.as_u32[i]);
714 csum = ip_csum_add_even (csum, clib_host_to_net_u16 (0x1000));
715 e->ila_address.as_u16[7] = ip_csum_fold (csum);
716 e->ila_address.as_u8[8] |= 0x10;
719 //Create entry with the sir address
720 kv.key[0] = e->sir_address.as_u64[0];
721 kv.key[1] = e->sir_address.as_u64[1];
723 kv.value = e - ilm->entries;
724 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
727 if (!ip6_address_is_zero(&e->next_hop))
730 * become a child of the FIB netry for the next-hop
731 * so we are informed when its forwarding changes
733 fib_prefix_t next_hop = {
738 .fp_proto = FIB_PROTOCOL_IP6,
741 e->next_hop_fib_entry_index =
742 fib_table_entry_special_add(0,
747 e->next_hop_child_index =
748 fib_entry_child_add(e->next_hop_fib_entry_index,
753 * Create a route that results in the ILA entry
755 dpo_id_t dpo = DPO_NULL;
758 .ip6 = e->ila_address,
761 .fp_proto = FIB_PROTOCOL_IP6,
764 dpo_set(&dpo, ila_dpo_type, DPO_PROTO_IP6, e - ilm->entries);
766 fib_table_entry_special_dpo_add(0,
768 FIB_SOURCE_PLUGIN_HI,
769 FIB_ENTRY_FLAG_EXCLUSIVE,
774 * finally stack the ILA entry so it will forward to the next-hop
782 kv.key[0] = args->sir_address.as_u64[0];
783 kv.key[1] = args->sir_address.as_u64[1];
786 if ((BV (clib_bihash_search) (&ilm->id_to_entry_table, &kv, &value) <
792 e = &ilm->entries[value.value];
794 if (!ip6_address_is_zero(&e->next_hop))
798 .ip6 = e->ila_address,
801 .fp_proto = FIB_PROTOCOL_IP6,
804 fib_table_entry_special_remove(0, &pfx, FIB_SOURCE_PLUGIN_HI);
806 * remove this ILA entry as child of the FIB netry for the next-hop
808 fib_entry_child_remove(e->next_hop_fib_entry_index,
809 e->next_hop_child_index);
810 fib_table_entry_delete_index(e->next_hop_fib_entry_index,
812 e->next_hop_fib_entry_index = FIB_NODE_INDEX_INVALID;
814 dpo_reset (&e->ila_dpo);
816 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
818 pool_put (ilm->entries, e);
824 ila_interface (u32 sw_if_index, u8 disable)
826 vlib_main_t *vm = vlib_get_main ();
827 ila_main_t *ilm = &ila_main;
828 ip6_main_t *im = &ip6_main;
829 ip_lookup_main_t *lm = &im->lookup_main;
830 ip_config_main_t *cm = &lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
831 vnet_config_main_t *vcm = &cm->config_main;
832 u32 ci, feature_index;
834 vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
835 ci = cm->config_index_by_sw_if_index[sw_if_index];
836 feature_index = ilm->ila_sir2ila_feature_index;
838 ci = ((disable) ? vnet_config_del_feature : vnet_config_add_feature)
839 (vm, vcm, ci, feature_index,
841 /* # bytes of config data */ 0);
843 cm->config_index_by_sw_if_index[sw_if_index] = ci;
848 vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
851 clib_error_t *error = 0;
856 u8 *format_ila_dpo (u8 * s, va_list * va)
858 index_t index = va_arg (*va, index_t);
859 CLIB_UNUSED(u32 indent) = va_arg (*va, u32);
860 ila_main_t *ilm = &ila_main;
861 ila_entry_t *ie = pool_elt_at_index (ilm->entries, index);
862 return format(s, "ILA: idx:%d sir:%U",
864 format_ip6_address, &ie->sir_address);
868 * @brief no-op lock function.
869 * The lifetime of the ILA entry is managed by the control plane
872 ila_dpo_lock (dpo_id_t *dpo)
877 * @brief no-op unlock function.
878 * The lifetime of the ILA entry is managed by the control plane
881 ila_dpo_unlock (dpo_id_t *dpo)
885 const static dpo_vft_t ila_vft = {
886 .dv_lock = ila_dpo_lock,
887 .dv_unlock = ila_dpo_unlock,
888 .dv_format = format_ila_dpo,
890 const static char* const ila_ip6_nodes[] =
895 const static char* const * const ila_nodes[DPO_PROTO_NUM] =
897 [DPO_PROTO_IP6] = ila_ip6_nodes,
901 ila_fib_node_get_node (fib_node_index_t index)
903 ila_main_t *ilm = &ila_main;
904 ila_entry_t *ie = pool_elt_at_index (ilm->entries, index);
906 return (&ie->ila_fib_node);
910 * @brief no-op unlock function.
911 * The lifetime of the ILA entry is managed by the control plane
914 ila_fib_node_last_lock_gone (fib_node_t *node)
919 ila_entry_from_fib_node (fib_node_t *node)
921 return ((ila_entry_t*)(((char*)node) -
922 STRUCT_OFFSET_OF(ila_entry_t, ila_fib_node)));
927 * Callback function invoked when the forwarding changes for the ILA next-hop
929 static fib_node_back_walk_rc_t
930 ila_fib_node_back_walk_notify (fib_node_t *node,
931 fib_node_back_walk_ctx_t *ctx)
933 ila_entry_stack(ila_entry_from_fib_node(node));
935 return (FIB_NODE_BACK_WALK_CONTINUE);
939 * ILA's FIB graph node virtual function table
941 static const fib_node_vft_t ila_fib_node_vft = {
942 .fnv_get = ila_fib_node_get_node,
943 .fnv_last_lock = ila_fib_node_last_lock_gone,
944 .fnv_back_walk = ila_fib_node_back_walk_notify,
948 ila_init (vlib_main_t * vm)
950 ila_main_t *ilm = &ila_main;
953 ilm->lookup_table_nbuckets = ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS;
954 ilm->lookup_table_nbuckets = 1 << max_log2 (ilm->lookup_table_nbuckets);
955 ilm->lookup_table_size = ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE;
957 BV (clib_bihash_init) (&ilm->id_to_entry_table,
958 "ila id to entry index table",
959 ilm->lookup_table_nbuckets, ilm->lookup_table_size);
961 ila_dpo_type = dpo_register_new_type(&ila_vft, ila_nodes);
962 ila_fib_node_type = fib_node_register_new_type(&ila_fib_node_vft);
967 VLIB_INIT_FUNCTION (ila_init);
969 static clib_error_t *
970 ila_entry_command_fn (vlib_main_t * vm,
971 unformat_input_t * input, vlib_cli_command_t * cmd)
973 unformat_input_t _line_input, *line_input = &_line_input;
974 ila_add_del_entry_args_t args = { 0 };
978 args.type = ILA_TYPE_IID;
979 args.csum_mode = ILA_CSUM_MODE_NO_ACTION;
980 args.local_adj_index = ~0;
981 args.dir = ILA_DIR_BIDIR;
983 if (!unformat_user (input, unformat_line_input, line_input))
986 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
988 if (unformat (line_input, "type %U", unformat_ila_type, &args.type))
991 (line_input, "sir-address %U", unformat_ip6_address,
995 (line_input, "locator %U", unformat_half_ip6_address,
999 (line_input, "csum-mode %U", unformat_ila_csum_mode,
1002 else if (unformat (line_input, "vnid %x", &args.vnid))
1005 (line_input, "next-hop %U", unformat_ip6_address,
1006 &args.next_hop_address))
1009 (line_input, "direction %U", unformat_ila_direction, &args.dir))
1011 else if (unformat (line_input, "del"))
1014 return clib_error_return (0, "parse error: '%U'",
1015 format_unformat_error, line_input);
1018 unformat_free (line_input);
1021 return clib_error_return (0, "Specified a next hop");
1023 if ((ret = ila_add_del_entry (&args)))
1024 return clib_error_return (0, "ila_add_del_entry returned error %d", ret);
1029 VLIB_CLI_COMMAND (ila_entry_command, static) =
1031 .path = "ila entry",
1032 .short_help = "ila entry [type <type>] [sir-address <address>] [locator <locator>] [vnid <hex-vnid>]"
1033 " [adj-index <adj-index>] [next-hop <next-hop>] [direction (bidir|sir2ila|ila2sir)]"
1034 " [csum-mode (no-action|neutral-map|transport-adjust)] [del]",
1035 .function = ila_entry_command_fn,
1038 static clib_error_t *
1039 ila_interface_command_fn (vlib_main_t * vm,
1040 unformat_input_t * input, vlib_cli_command_t * cmd)
1042 vnet_main_t *vnm = vnet_get_main ();
1043 u32 sw_if_index = ~0;
1046 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1048 return clib_error_return (0, "Invalid interface name");
1051 if (unformat (input, "disable"))
1057 if ((ret = ila_interface (sw_if_index, disable)))
1058 return clib_error_return (0, "ila_interface returned error %d", ret);
1063 VLIB_CLI_COMMAND (ila_interface_command, static) =
1065 .path = "ila interface",
1066 .short_help = "ila interface <interface-name> [disable]",
1067 .function = ila_interface_command_fn,
1070 static clib_error_t *
1071 ila_show_entries_command_fn (vlib_main_t * vm,
1072 unformat_input_t * input,
1073 vlib_cli_command_t * cmd)
1075 vnet_main_t *vnm = vnet_get_main ();
1076 ila_main_t *ilm = &ila_main;
1079 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, NULL);
1080 pool_foreach (e, ilm->entries,
1082 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, e);
1088 VLIB_CLI_COMMAND (ila_show_entries_command, static) =
1090 .path = "show ila entries",
1091 .short_help = "show ila entries",
1092 .function = ila_show_entries_command_fn,