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>
19 static ila_main_t ila_main;
21 #define ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
22 #define ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE (32<<20)
24 #define foreach_ila_error \
25 _(NONE, "valid ILA packets")
28 #define _(sym,str) ILA_ERROR_##sym,
34 static char *ila_error_strings[] = {
35 #define _(sym,string) string,
41 ILA_ILA2SIR_NEXT_IP6_REWRITE,
42 ILA_ILA2SIR_NEXT_DROP,
48 ip6_address_t initial_dst;
50 } ila_ila2sir_trace_t;
52 static ila_entry_t ila_sir2ila_default_entry = {
53 .csum_mode = ILA_CSUM_MODE_NO_ACTION,
55 .dir = ILA_DIR_ILA2SIR, //Will pass the packet with no
59 format_half_ip6_address (u8 * s, va_list * va)
61 u64 v = clib_net_to_host_u64 (va_arg (*va, u64));
63 return format (s, "%04x:%04x:%04x:%04x",
64 v >> 48, (v >> 32) & 0xffff, (v >> 16) & 0xffff, v & 0xffff);
69 format_ila_direction (u8 * s, va_list * args)
71 ila_direction_t t = va_arg (*args, ila_direction_t);
73 if (t == ILA_DIR_##i) \
77 return format (s, "invalid_ila_direction");
81 format_csum_mode (u8 * s, va_list * va)
83 ila_csum_mode_t csum_mode = va_arg (*va, ila_csum_mode_t);
89 case ILA_CSUM_MODE_##i: \
95 txt = "invalid_ila_csum_mode";
98 return format (s, txt);
102 format_ila_type (u8 * s, va_list * args)
104 ila_type_t t = va_arg (*args, ila_type_t);
106 if (t == ILA_TYPE_##i) \
107 return format(s, st);
110 return format (s, "invalid_ila_type");
114 format_ila_entry (u8 * s, va_list * va)
116 vnet_main_t *vnm = va_arg (*va, vnet_main_t *);
117 ila_entry_t *e = va_arg (*va, ila_entry_t *);
121 return format (s, "%-15s%=40s%=40s%+16s%+18s%+11s", "Type", "SIR Address",
122 "ILA Address", "Adjacency Index", "Checksum Mode", "Direction");
127 if (e->ila_adj_index == ~0)
129 return format (s, "%-15U%=40U%=40U%16s%18U%11U",
130 format_ila_type, e->type,
131 format_ip6_address, &e->sir_address,
132 format_ip6_address, &e->ila_address,
133 "n/a", format_csum_mode, e->csum_mode,
134 format_ila_direction, e->dir);
138 return format (s, "%-15U%=40U%=40U%16d%18U%11U",
139 format_ila_type, e->type,
140 format_ip6_address, &e->sir_address,
141 format_ip6_address, &e->ila_address,
142 e->ila_adj_index, format_csum_mode, e->csum_mode,
143 format_ila_direction, e->dir);
151 format_ila_ila2sir_trace (u8 * s, va_list * args)
153 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
154 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
155 ila_ila2sir_trace_t *t = va_arg (*args, ila_ila2sir_trace_t *);
157 "ILA -> SIR adj index: %d entry index: %d initial_dst: %U",
158 t->adj_index, t->ila_index, format_ip6_address,
163 unformat_ila_direction (unformat_input_t * input, va_list * args)
165 ila_direction_t *result = va_arg (*args, ila_direction_t *);
167 if (unformat(input, s)) \
169 *result = ILA_DIR_##i; \
173 ila_foreach_direction
179 unformat_ila_type (unformat_input_t * input, va_list * args)
181 ila_type_t *result = va_arg (*args, ila_type_t *);
183 if (unformat(input, s)) \
185 *result = ILA_TYPE_##i; \
195 unformat_ila_csum_mode (unformat_input_t * input, va_list * args)
197 ila_csum_mode_t *result = va_arg (*args, ila_csum_mode_t *);
198 if (unformat (input, "none") || unformat (input, "no-action"))
200 *result = ILA_CSUM_MODE_NO_ACTION;
203 if (unformat (input, "neutral-map"))
205 *result = ILA_CSUM_MODE_NEUTRAL_MAP;
208 if (unformat (input, "adjust-transport"))
210 *result = ILA_CSUM_MODE_ADJUST_TRANSPORT;
217 unformat_half_ip6_address (unformat_input_t * input, va_list * args)
219 u64 *result = va_arg (*args, u64 *);
222 if (!unformat (input, "%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3]))
225 if (a[0] > 0xFFFF || a[1] > 0xFFFF || a[2] > 0xFFFF || a[3] > 0xFFFF)
228 *result = clib_host_to_net_u64 ((((u64) a[0]) << 48) |
229 (((u64) a[1]) << 32) |
230 (((u64) a[2]) << 16) | (((u64) a[3])));
235 static vlib_node_registration_t ila_ila2sir_node;
238 ila_ila2sir (vlib_main_t * vm,
239 vlib_node_runtime_t * node, vlib_frame_t * frame)
241 ip6_main_t *im = &ip6_main;
242 ip_lookup_main_t *lm = &im->lookup_main;
243 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
244 ila_main_t *ilm = &ila_main;
246 from = vlib_frame_vector_args (frame);
247 n_left_from = frame->n_vectors;
248 next_index = node->cached_next_index;
250 while (n_left_from > 0)
252 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
254 while (n_left_from >= 4 && n_left_to_next >= 2)
257 vlib_buffer_t *p0, *p1;
258 ip_adjacency_t *adj0, *adj1;
259 ila_entry_t *ie0, *ie1;
260 ip6_header_t *ip60, *ip61;
261 ila_adj_data_t *ad0, *ad1;
262 ip6_address_t *sir_address0, *sir_address1;
265 vlib_buffer_t *p2, *p3;
267 p2 = vlib_get_buffer (vm, from[2]);
268 p3 = vlib_get_buffer (vm, from[3]);
270 vlib_prefetch_buffer_header (p2, LOAD);
271 vlib_prefetch_buffer_header (p3, LOAD);
272 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
273 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
276 pi0 = to_next[0] = from[0];
277 pi1 = to_next[1] = from[1];
283 p0 = vlib_get_buffer (vm, pi0);
284 p1 = vlib_get_buffer (vm, pi1);
285 ip60 = vlib_buffer_get_current (p0);
286 ip61 = vlib_buffer_get_current (p1);
287 sir_address0 = &ip60->dst_address;
288 sir_address1 = &ip61->dst_address;
290 ip_get_adjacency (lm, vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
292 ip_get_adjacency (lm, vnet_buffer (p1)->ip.adj_index[VLIB_TX]);
293 ad0 = (ila_adj_data_t *) & adj0->opaque;
294 ad1 = (ila_adj_data_t *) & adj1->opaque;
295 ie0 = pool_elt_at_index (ilm->entries, ad0->entry_index);
296 ie1 = pool_elt_at_index (ilm->entries, ad1->entry_index);
298 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
300 ila_ila2sir_trace_t *tr =
301 vlib_add_trace (vm, node, p0, sizeof (*tr));
302 tr->ila_index = ie0 ? (ie0 - ilm->entries) : ~0;
303 tr->initial_dst = ip60->dst_address;
304 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
307 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
309 ila_ila2sir_trace_t *tr =
310 vlib_add_trace (vm, node, p1, sizeof (*tr));
311 tr->ila_index = ie1 ? (ie1 - ilm->entries) : ~0;
312 tr->initial_dst = ip61->dst_address;
313 tr->adj_index = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
316 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
317 sir_address1 = (ie1->dir != ILA_DIR_SIR2ILA) ? &ie1->sir_address : sir_address1;
318 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
319 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
320 ip61->dst_address.as_u64[0] = sir_address1->as_u64[0];
321 ip61->dst_address.as_u64[1] = sir_address1->as_u64[1];
323 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_adj_index;
324 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = ie1->ila_adj_index;
326 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
327 n_left_to_next, pi0, pi1,
328 ILA_ILA2SIR_NEXT_IP6_REWRITE,
329 ILA_ILA2SIR_NEXT_IP6_REWRITE);
333 while (n_left_from > 0 && n_left_to_next > 0)
337 ip_adjacency_t *adj0;
341 ip6_address_t *sir_address0;
343 pi0 = to_next[0] = from[0];
349 p0 = vlib_get_buffer (vm, pi0);
350 ip60 = vlib_buffer_get_current (p0);
351 sir_address0 = &ip60->dst_address;
353 ip_get_adjacency (lm, vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
354 ad0 = (ila_adj_data_t *) & adj0->opaque;
355 ie0 = pool_elt_at_index (ilm->entries, ad0->entry_index);
357 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
359 ila_ila2sir_trace_t *tr =
360 vlib_add_trace (vm, node, p0, sizeof (*tr));
361 tr->ila_index = ie0 ? (ie0 - ilm->entries) : ~0;
362 tr->initial_dst = ip60->dst_address;
363 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
366 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
367 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
368 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
369 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_adj_index;
371 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
373 ILA_ILA2SIR_NEXT_IP6_REWRITE);
375 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
378 return frame->n_vectors;
381 VLIB_REGISTER_NODE (ila_ila2sir_node, static) =
383 .function = ila_ila2sir,.name = "ila-to-sir",.vector_size =
384 sizeof (u32),.format_trace = format_ila_ila2sir_trace,.n_errors =
385 ILA_N_ERROR,.error_strings = ila_error_strings,.n_next_nodes =
386 ILA_ILA2SIR_N_NEXT,.next_nodes =
388 [ILA_ILA2SIR_NEXT_IP6_REWRITE] = "ip6-rewrite",
389 [ILA_ILA2SIR_NEXT_DROP] = "error-drop"}
394 ILA_SIR2ILA_NEXT_DROP,
396 } ila_sir2ila_next_t;
401 ip6_address_t initial_dst;
402 } ila_sir2ila_trace_t;
405 format_ila_sir2ila_trace (u8 * s, va_list * args)
407 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
408 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
409 ila_sir2ila_trace_t *t = va_arg (*args, ila_sir2ila_trace_t *);
411 return format (s, "SIR -> ILA entry index: %d initial_dst: %U",
412 t->ila_index, format_ip6_address, &t->initial_dst);
415 static vlib_node_registration_t ila_sir2ila_node;
418 ila_sir2ila (vlib_main_t * vm,
419 vlib_node_runtime_t * node, vlib_frame_t * frame)
421 ip6_main_t *im = &ip6_main;
422 ip_lookup_main_t *lm = &im->lookup_main;
423 ip_config_main_t *cm = &lm->rx_config_mains[VNET_UNICAST];
424 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
425 ila_main_t *ilm = &ila_main;
427 from = vlib_frame_vector_args (frame);
428 n_left_from = frame->n_vectors;
429 next_index = node->cached_next_index;
431 while (n_left_from > 0)
433 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
435 while (n_left_from >= 4 && n_left_to_next >= 2)
438 vlib_buffer_t *p0, *p1;
439 ip6_header_t *ip60, *ip61;
440 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
441 u32 next1 = ILA_SIR2ILA_NEXT_DROP;
442 BVT (clib_bihash_kv) kv0, value0;
443 BVT (clib_bihash_kv) kv1, value1;
444 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
445 ila_entry_t *ie1 = &ila_sir2ila_default_entry;
446 ip6_address_t *ila_address0, *ila_address1;
449 vlib_buffer_t *p2, *p3;
451 p2 = vlib_get_buffer (vm, from[2]);
452 p3 = vlib_get_buffer (vm, from[3]);
454 vlib_prefetch_buffer_header (p2, LOAD);
455 vlib_prefetch_buffer_header (p3, LOAD);
456 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
457 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
460 pi0 = to_next[0] = from[0];
461 pi1 = to_next[1] = from[1];
467 p0 = vlib_get_buffer (vm, pi0);
468 p1 = vlib_get_buffer (vm, pi1);
469 ip60 = vlib_buffer_get_current (p0);
470 ip61 = vlib_buffer_get_current (p1);
471 ila_address0 = &ip60->dst_address;
472 ila_address1 = &ip61->dst_address;
473 kv0.key[0] = ip60->dst_address.as_u64[0];
474 kv0.key[1] = ip60->dst_address.as_u64[1];
476 kv1.key[0] = ip61->dst_address.as_u64[0];
477 kv1.key[1] = ip61->dst_address.as_u64[1];
480 if (PREDICT_TRUE((BV (clib_bihash_search)
481 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
482 ie0 = &ilm->entries[value0.value];
483 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
486 if ((BV (clib_bihash_search)
487 (&ilm->id_to_entry_table, &kv1, &value1)) == 0) {
488 ie1 = &ilm->entries[value1.value];
489 ila_address1 = (ie1->dir != ILA_DIR_ILA2SIR) ? &ie1->ila_address : ila_address1;
492 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
494 ila_sir2ila_trace_t *tr =
495 vlib_add_trace (vm, node, p0, sizeof (*tr));
497 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
498 tr->initial_dst = ip60->dst_address;
501 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
503 ila_sir2ila_trace_t *tr =
504 vlib_add_trace (vm, node, p1, sizeof (*tr));
506 (ie1 != &ila_sir2ila_default_entry) ? (ie1 - ilm->entries) : ~0;
507 tr->initial_dst = ip61->dst_address;
510 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
511 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
512 ip61->dst_address.as_u64[0] = ila_address1->as_u64[0];
513 ip61->dst_address.as_u64[1] = ila_address1->as_u64[1];
515 vnet_get_config_data (&cm->config_main,
516 &p0->current_config_index, &next0, 0);
518 vnet_get_config_data (&cm->config_main,
519 &p1->current_config_index, &next1, 0);
521 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
522 n_left_to_next, pi0, pi1, next0,
527 while (n_left_from > 0 && n_left_to_next > 0)
532 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
533 BVT (clib_bihash_kv) kv0, value0;
534 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
535 ip6_address_t *ila_address0;
537 pi0 = to_next[0] = from[0];
543 p0 = vlib_get_buffer (vm, pi0);
544 ip60 = vlib_buffer_get_current (p0);
545 ila_address0 = &ip60->dst_address;
547 kv0.key[0] = ip60->dst_address.as_u64[0];
548 kv0.key[1] = ip60->dst_address.as_u64[1];
551 if (PREDICT_TRUE((BV (clib_bihash_search)
552 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
553 ie0 = &ilm->entries[value0.value];
554 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
557 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
559 ila_sir2ila_trace_t *tr =
560 vlib_add_trace (vm, node, p0, sizeof (*tr));
562 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
563 tr->initial_dst = ip60->dst_address;
566 //This operation should do everything for any type (except vnid4 obviously)
567 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
568 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
570 vnet_get_config_data (&cm->config_main,
571 &p0->current_config_index, &next0, 0);
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;
582 VLIB_REGISTER_NODE (ila_sir2ila_node, static) =
584 .function = ila_sir2ila,.name = "sir-to-ila",.vector_size =
585 sizeof (u32),.format_trace = format_ila_sir2ila_trace,.n_errors =
586 ILA_N_ERROR,.error_strings = ila_error_strings,.n_next_nodes =
587 ILA_SIR2ILA_N_NEXT,.next_nodes =
589 [ILA_SIR2ILA_NEXT_DROP] = "error-drop"}
592 VNET_IP6_UNICAST_FEATURE_INIT (ila_sir2ila, static) =
594 .node_name = "sir-to-ila",.runs_before =
596 "ip6-lookup", 0},.feature_index = &ila_main.ila_sir2ila_feature_index,};
599 ila_add_del_entry (ila_add_del_entry_args_t * args)
601 ila_main_t *ilm = &ila_main;
602 ip6_main_t *im6 = &ip6_main;
603 BVT (clib_bihash_kv) kv, value;
606 if (args->type == ILA_TYPE_IID || args->type == ILA_TYPE_LUID)
608 if ((args->sir_address.as_u8[8] >> 5) != args->type)
610 clib_warning ("Incorrect SIR address (ILA type mismatch %d %d)",
611 args->sir_address.as_u8[8] >> 1, args->type);
614 if (args->sir_address.as_u8[8] & 0x10)
616 clib_warning ("Checksum bit should not be set in SIR address");
620 else if (args->type == ILA_TYPE_VNIDM)
622 if (args->sir_address.as_u8[0] != 0xff ||
623 (args->sir_address.as_u8[1] & 0xf0) != 0xf0)
625 clib_warning ("SIR multicast address must start with fff");
628 if (args->sir_address.as_u16[1] || args->sir_address.as_u16[2] ||
629 args->sir_address.as_u16[3] || args->sir_address.as_u16[4] ||
630 args->sir_address.as_u16[5] || (args->sir_address.as_u8[12] & 0xf0))
632 clib_warning ("SIR multicast address must start with fff");
640 pool_get (ilm->entries, e);
641 e->type = args->type;
642 e->sir_address = args->sir_address;
643 e->ila_adj_index = args->local_adj_index;
644 e->csum_mode = args->csum_mode;
647 //Construct ILA address
651 e->ila_address = e->sir_address;
654 e->ila_address.as_u64[0] = args->locator;
655 e->ila_address.as_u64[1] = args->sir_address.as_u64[1];
658 e->ila_address.as_u64[0] = args->locator;
659 e->ila_address.as_u8[8] = (ILA_TYPE_VNID6 << 1);
660 e->ila_address.as_u32[2] |= args->vnid;
661 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
664 e->ila_address.as_u64[0] = args->locator;
665 e->ila_address.as_u8[8] = (ILA_TYPE_VNIDM << 1);
666 e->ila_address.as_u32[2] |= args->vnid;
667 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
668 e->ila_address.as_u8[12] |= args->sir_address.as_u8[2] << 4;
671 clib_warning ("ILA type '%U' is not supported", format_ila_type,
676 //Modify ILA checksum if necessary
677 if (e->csum_mode == ILA_CSUM_MODE_NEUTRAL_MAP)
679 ip_csum_t csum = e->ila_address.as_u16[7];
681 for (i = 0; i < 4; i++)
683 csum = ip_csum_sub_even (csum, e->sir_address.as_u32[i]);
684 csum = ip_csum_add_even (csum, e->ila_address.as_u32[i]);
686 csum = ip_csum_add_even (csum, clib_host_to_net_u16 (0x1000));
687 e->ila_address.as_u16[7] = ip_csum_fold (csum);
688 e->ila_address.as_u8[8] |= 0x10;
691 //Create entry with the sir address
692 kv.key[0] = e->sir_address.as_u64[0];
693 kv.key[1] = e->sir_address.as_u64[1];
695 kv.value = e - ilm->entries;
696 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
699 if (e->ila_adj_index != ~0)
701 //This is a local entry - let's create a local adjacency
703 ip6_add_del_route_args_t route_args;
707 memset (&adj, 0, sizeof (adj));
708 adj.explicit_fib_index = ~0;
709 adj.lookup_next_index = ilm->ip6_lookup_next_index;
710 ad = (ila_adj_data_t *) & adj.opaque;
711 ad->entry_index = e - ilm->entries;
714 memset (&route_args, 0, sizeof (route_args));
715 route_args.table_index_or_table_id = 0;
716 route_args.flags = IP6_ROUTE_FLAG_ADD;
717 route_args.dst_address = e->ila_address;
718 route_args.dst_address_length = 128;
719 route_args.adj_index = ~0;
720 route_args.add_adj = &adj;
721 route_args.n_add_adj = 1;
723 ip6_add_del_route (im6, &route_args);
729 kv.key[0] = args->sir_address.as_u64[0];
730 kv.key[1] = args->sir_address.as_u64[1];
733 if ((BV (clib_bihash_search) (&ilm->id_to_entry_table, &kv, &value) <
739 e = &ilm->entries[value.value];
741 if (e->ila_adj_index != ~0)
743 //Delete that route - Associated adjacency will be deleted too
744 ip6_add_del_route_args_t route_args;
745 memset (&route_args, 0, sizeof (route_args));
746 route_args.table_index_or_table_id = 0;
747 route_args.flags = IP6_ROUTE_FLAG_DEL;
748 route_args.dst_address = e->ila_address;
749 route_args.dst_address_length = 128;
750 route_args.adj_index = ~0;
751 route_args.add_adj = NULL;
752 route_args.n_add_adj = 0;
754 ip6_add_del_route (im6, &route_args);
757 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
759 pool_put (ilm->entries, e);
765 ila_interface (u32 sw_if_index, u8 disable)
767 vlib_main_t *vm = vlib_get_main ();
768 ila_main_t *ilm = &ila_main;
769 ip6_main_t *im = &ip6_main;
770 ip_lookup_main_t *lm = &im->lookup_main;
771 ip_config_main_t *cm = &lm->rx_config_mains[VNET_UNICAST];
772 vnet_config_main_t *vcm = &cm->config_main;
773 u32 ci, feature_index;
775 vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
776 ci = cm->config_index_by_sw_if_index[sw_if_index];
777 feature_index = ilm->ila_sir2ila_feature_index;
779 ci = ((disable) ? vnet_config_del_feature : vnet_config_add_feature)
780 (vm, vcm, ci, feature_index,
782 /* # bytes of config data */ 0);
784 cm->config_index_by_sw_if_index[sw_if_index] = ci;
789 vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
792 clib_error_t *error = 0;
798 ila_init (vlib_main_t * vm)
800 ila_main_t *ilm = &ila_main;
803 ASSERT (sizeof (ila_adj_data_t) < IP_ADJACENCY_OPAQUE_SZ);
805 ilm->lookup_table_nbuckets = ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS;
806 ilm->lookup_table_nbuckets = 1 << max_log2 (ilm->lookup_table_nbuckets);
807 ilm->lookup_table_size = ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE;
809 BV (clib_bihash_init) (&ilm->id_to_entry_table,
810 "ila id to entry index table",
811 ilm->lookup_table_nbuckets, ilm->lookup_table_size);
813 vlib_node_t *ip6_lookup_node =
814 vlib_get_node_by_name (vm, (u8 *) "ip6-lookup");
816 ilm->ip6_lookup_next_index =
817 vlib_node_add_next (vm, ip6_lookup_node->index, ila_ila2sir_node.index);
821 VLIB_INIT_FUNCTION (ila_init);
823 static clib_error_t *
824 ila_entry_command_fn (vlib_main_t * vm,
825 unformat_input_t * input, vlib_cli_command_t * cmd)
827 unformat_input_t _line_input, *line_input = &_line_input;
828 ila_add_del_entry_args_t args = { 0 };
829 ip6_address_t next_hop;
831 ip6_main_t *im6 = &ip6_main;
834 args.type = ILA_TYPE_IID;
835 args.csum_mode = ILA_CSUM_MODE_NO_ACTION;
836 args.local_adj_index = ~0;
837 args.dir = ILA_DIR_BIDIR;
839 if (!unformat_user (input, unformat_line_input, line_input))
842 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
844 if (unformat (line_input, "type %U", unformat_ila_type, &args.type))
848 (line_input, "sir-address %U", unformat_ip6_address,
853 (line_input, "locator %U", unformat_half_ip6_address,
856 else if (unformat (line_input, "adj-index %u", &args.local_adj_index))
860 (line_input, "csum-mode %U", unformat_ila_csum_mode,
863 else if (unformat (line_input, "vnid %x", &args.vnid))
867 (line_input, "next-hop %U", unformat_ip6_address, &next_hop))
870 (line_input, "direction %U", unformat_ila_direction, &args.dir))
872 else if (unformat (line_input, "del"))
875 return clib_error_return (0, "parse error: '%U'",
876 format_unformat_error, line_input);
879 unformat_free (line_input);
883 if (args.local_adj_index != ~0)
884 return clib_error_return (0,
885 "Specified both next hop and adjacency index");
887 u32 ai = ip6_get_route (im6, 0, 0, &next_hop, 128);
889 return clib_error_return (0, "No route to next-hop %U",
890 format_ip6_address, &next_hop);
892 ip_lookup_main_t *lm6 = &ip6_main.lookup_main;
893 ip_adjacency_t *adj6 = ip_get_adjacency (lm6, ai);
894 if (adj6->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
896 return clib_error_return (0,
897 "Next-Hop route has to be a rewrite route");
899 args.local_adj_index = ai;
902 if ((ret = ila_add_del_entry (&args)))
903 return clib_error_return (0, "ila_add_del_entry returned error %d", ret);
908 VLIB_CLI_COMMAND (ila_entry_command, static) =
911 .short_help = "ila entry [type <type>] [sir-address <address>] [locator <locator>] [vnid <hex-vnid>]"
912 " [adj-index <adj-index>] [next-hop <next-hop>] [direction (bidir|sir2ila|ila2sir)]"
913 " [csum-mode (no-action|neutral-map|transport-adjust)] [del]",
914 .function = ila_entry_command_fn,
917 static clib_error_t *
918 ila_interface_command_fn (vlib_main_t * vm,
919 unformat_input_t * input, vlib_cli_command_t * cmd)
921 vnet_main_t *vnm = vnet_get_main ();
922 u32 sw_if_index = ~0;
925 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
927 return clib_error_return (0, "Invalid interface name");
930 if (unformat (input, "disable"))
936 if ((ret = ila_interface (sw_if_index, disable)))
937 return clib_error_return (0, "ila_interface returned error %d", ret);
942 VLIB_CLI_COMMAND (ila_interface_command, static) =
944 .path = "ila interface",
945 .short_help = "ila interface <interface-name> [disable]",
946 .function = ila_interface_command_fn,
949 static clib_error_t *
950 ila_show_entries_command_fn (vlib_main_t * vm,
951 unformat_input_t * input,
952 vlib_cli_command_t * cmd)
954 vnet_main_t *vnm = vnet_get_main ();
955 ila_main_t *ilm = &ila_main;
958 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, NULL);
959 pool_foreach (e, ilm->entries,
961 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, e);
967 VLIB_CLI_COMMAND (ila_show_entries_command, static) =
969 .path = "show ila entries",
970 .short_help = "show ila entries",
971 .function = ila_show_entries_command_fn,