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>
20 static ila_main_t ila_main;
22 #define ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
23 #define ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE (32<<20)
25 #define foreach_ila_error \
26 _(NONE, "valid ILA packets")
29 #define _(sym,str) ILA_ERROR_##sym,
35 static char *ila_error_strings[] = {
36 #define _(sym,string) string,
42 ILA_ILA2SIR_NEXT_IP6_REWRITE,
43 ILA_ILA2SIR_NEXT_DROP,
49 ip6_address_t initial_dst;
51 } ila_ila2sir_trace_t;
53 static ila_entry_t ila_sir2ila_default_entry = {
54 .csum_mode = ILA_CSUM_MODE_NO_ACTION,
56 .dir = ILA_DIR_ILA2SIR, //Will pass the packet with no
60 format_half_ip6_address (u8 * s, va_list * va)
62 u64 v = clib_net_to_host_u64 (va_arg (*va, u64));
64 return format (s, "%04x:%04x:%04x:%04x",
65 v >> 48, (v >> 32) & 0xffff, (v >> 16) & 0xffff, v & 0xffff);
70 format_ila_direction (u8 * s, va_list * args)
72 ila_direction_t t = va_arg (*args, ila_direction_t);
74 if (t == ILA_DIR_##i) \
78 return format (s, "invalid_ila_direction");
82 format_csum_mode (u8 * s, va_list * va)
84 ila_csum_mode_t csum_mode = va_arg (*va, ila_csum_mode_t);
90 case ILA_CSUM_MODE_##i: \
96 txt = "invalid_ila_csum_mode";
99 return format (s, txt);
103 format_ila_type (u8 * s, va_list * args)
105 ila_type_t t = va_arg (*args, ila_type_t);
107 if (t == ILA_TYPE_##i) \
108 return format(s, st);
111 return format (s, "invalid_ila_type");
115 format_ila_entry (u8 * s, va_list * va)
117 vnet_main_t *vnm = va_arg (*va, vnet_main_t *);
118 ila_entry_t *e = va_arg (*va, ila_entry_t *);
122 return format (s, "%-15s%=40s%=40s%+16s%+18s%+11s", "Type", "SIR Address",
123 "ILA Address", "Adjacency Index", "Checksum Mode", "Direction");
128 if (e->ila_adj_index == ~0)
130 return format (s, "%-15U%=40U%=40U%16s%18U%11U",
131 format_ila_type, e->type,
132 format_ip6_address, &e->sir_address,
133 format_ip6_address, &e->ila_address,
134 "n/a", format_csum_mode, e->csum_mode,
135 format_ila_direction, e->dir);
139 return format (s, "%-15U%=40U%=40U%16d%18U%11U",
140 format_ila_type, e->type,
141 format_ip6_address, &e->sir_address,
142 format_ip6_address, &e->ila_address,
143 e->ila_adj_index, format_csum_mode, e->csum_mode,
144 format_ila_direction, e->dir);
152 format_ila_ila2sir_trace (u8 * s, va_list * args)
154 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
155 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
156 ila_ila2sir_trace_t *t = va_arg (*args, ila_ila2sir_trace_t *);
158 "ILA -> SIR adj index: %d entry index: %d initial_dst: %U",
159 t->adj_index, t->ila_index, format_ip6_address,
164 unformat_ila_direction (unformat_input_t * input, va_list * args)
166 ila_direction_t *result = va_arg (*args, ila_direction_t *);
168 if (unformat(input, s)) \
170 *result = ILA_DIR_##i; \
174 ila_foreach_direction
180 unformat_ila_type (unformat_input_t * input, va_list * args)
182 ila_type_t *result = va_arg (*args, ila_type_t *);
184 if (unformat(input, s)) \
186 *result = ILA_TYPE_##i; \
196 unformat_ila_csum_mode (unformat_input_t * input, va_list * args)
198 ila_csum_mode_t *result = va_arg (*args, ila_csum_mode_t *);
199 if (unformat (input, "none") || unformat (input, "no-action"))
201 *result = ILA_CSUM_MODE_NO_ACTION;
204 if (unformat (input, "neutral-map"))
206 *result = ILA_CSUM_MODE_NEUTRAL_MAP;
209 if (unformat (input, "adjust-transport"))
211 *result = ILA_CSUM_MODE_ADJUST_TRANSPORT;
218 unformat_half_ip6_address (unformat_input_t * input, va_list * args)
220 u64 *result = va_arg (*args, u64 *);
223 if (!unformat (input, "%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3]))
226 if (a[0] > 0xFFFF || a[1] > 0xFFFF || a[2] > 0xFFFF || a[3] > 0xFFFF)
229 *result = clib_host_to_net_u64 ((((u64) a[0]) << 48) |
230 (((u64) a[1]) << 32) |
231 (((u64) a[2]) << 16) | (((u64) a[3])));
236 static vlib_node_registration_t ila_ila2sir_node;
239 ila_ila2sir (vlib_main_t * vm,
240 vlib_node_runtime_t * node, vlib_frame_t * frame)
242 ip6_main_t *im = &ip6_main;
243 ip_lookup_main_t *lm = &im->lookup_main;
244 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
245 ila_main_t *ilm = &ila_main;
247 from = vlib_frame_vector_args (frame);
248 n_left_from = frame->n_vectors;
249 next_index = node->cached_next_index;
251 while (n_left_from > 0)
253 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
255 while (n_left_from >= 4 && n_left_to_next >= 2)
258 vlib_buffer_t *p0, *p1;
259 ip_adjacency_t *adj0, *adj1;
260 ila_entry_t *ie0, *ie1;
261 ip6_header_t *ip60, *ip61;
262 ila_adj_data_t *ad0, *ad1;
263 ip6_address_t *sir_address0, *sir_address1;
266 vlib_buffer_t *p2, *p3;
268 p2 = vlib_get_buffer (vm, from[2]);
269 p3 = vlib_get_buffer (vm, from[3]);
271 vlib_prefetch_buffer_header (p2, LOAD);
272 vlib_prefetch_buffer_header (p3, LOAD);
273 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
274 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
277 pi0 = to_next[0] = from[0];
278 pi1 = to_next[1] = from[1];
284 p0 = vlib_get_buffer (vm, pi0);
285 p1 = vlib_get_buffer (vm, pi1);
286 ip60 = vlib_buffer_get_current (p0);
287 ip61 = vlib_buffer_get_current (p1);
288 sir_address0 = &ip60->dst_address;
289 sir_address1 = &ip61->dst_address;
291 ip_get_adjacency (lm, vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
293 ip_get_adjacency (lm, vnet_buffer (p1)->ip.adj_index[VLIB_TX]);
294 ad0 = (ila_adj_data_t *) & adj0->opaque;
295 ad1 = (ila_adj_data_t *) & adj1->opaque;
296 ie0 = pool_elt_at_index (ilm->entries, ad0->entry_index);
297 ie1 = pool_elt_at_index (ilm->entries, ad1->entry_index);
299 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
301 ila_ila2sir_trace_t *tr =
302 vlib_add_trace (vm, node, p0, sizeof (*tr));
303 tr->ila_index = ie0 ? (ie0 - ilm->entries) : ~0;
304 tr->initial_dst = ip60->dst_address;
305 tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
308 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
310 ila_ila2sir_trace_t *tr =
311 vlib_add_trace (vm, node, p1, sizeof (*tr));
312 tr->ila_index = ie1 ? (ie1 - ilm->entries) : ~0;
313 tr->initial_dst = ip61->dst_address;
314 tr->adj_index = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
317 sir_address0 = (ie0->dir != ILA_DIR_SIR2ILA) ? &ie0->sir_address : sir_address0;
318 sir_address1 = (ie1->dir != ILA_DIR_SIR2ILA) ? &ie1->sir_address : sir_address1;
319 ip60->dst_address.as_u64[0] = sir_address0->as_u64[0];
320 ip60->dst_address.as_u64[1] = sir_address0->as_u64[1];
321 ip61->dst_address.as_u64[0] = sir_address1->as_u64[0];
322 ip61->dst_address.as_u64[1] = sir_address1->as_u64[1];
324 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ie0->ila_adj_index;
325 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = ie1->ila_adj_index;
327 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
328 n_left_to_next, pi0, pi1,
329 ILA_ILA2SIR_NEXT_IP6_REWRITE,
330 ILA_ILA2SIR_NEXT_IP6_REWRITE);
334 while (n_left_from > 0 && n_left_to_next > 0)
338 ip_adjacency_t *adj0;
342 ip6_address_t *sir_address0;
344 pi0 = to_next[0] = from[0];
350 p0 = vlib_get_buffer (vm, pi0);
351 ip60 = vlib_buffer_get_current (p0);
352 sir_address0 = &ip60->dst_address;
354 ip_get_adjacency (lm, vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
355 ad0 = (ila_adj_data_t *) & adj0->opaque;
356 ie0 = pool_elt_at_index (ilm->entries, ad0->entry_index);
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_adj_index;
372 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
374 ILA_ILA2SIR_NEXT_IP6_REWRITE);
376 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
379 return frame->n_vectors;
382 VLIB_REGISTER_NODE (ila_ila2sir_node, static) =
384 .function = ila_ila2sir,.name = "ila-to-sir",.vector_size =
385 sizeof (u32),.format_trace = format_ila_ila2sir_trace,.n_errors =
386 ILA_N_ERROR,.error_strings = ila_error_strings,.n_next_nodes =
387 ILA_ILA2SIR_N_NEXT,.next_nodes =
389 [ILA_ILA2SIR_NEXT_IP6_REWRITE] = "ip6-rewrite",
390 [ILA_ILA2SIR_NEXT_DROP] = "error-drop"}
395 ILA_SIR2ILA_NEXT_DROP,
397 } ila_sir2ila_next_t;
402 ip6_address_t initial_dst;
403 } ila_sir2ila_trace_t;
406 format_ila_sir2ila_trace (u8 * s, va_list * args)
408 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
409 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
410 ila_sir2ila_trace_t *t = va_arg (*args, ila_sir2ila_trace_t *);
412 return format (s, "SIR -> ILA entry index: %d initial_dst: %U",
413 t->ila_index, format_ip6_address, &t->initial_dst);
416 static vlib_node_registration_t ila_sir2ila_node;
419 ila_sir2ila (vlib_main_t * vm,
420 vlib_node_runtime_t * node, vlib_frame_t * frame)
422 ip6_main_t *im = &ip6_main;
423 ip_lookup_main_t *lm = &im->lookup_main;
424 ip_config_main_t *cm = &lm->rx_config_mains[VNET_UNICAST];
425 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
426 ila_main_t *ilm = &ila_main;
428 from = vlib_frame_vector_args (frame);
429 n_left_from = frame->n_vectors;
430 next_index = node->cached_next_index;
432 while (n_left_from > 0)
434 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
436 while (n_left_from >= 4 && n_left_to_next >= 2)
439 vlib_buffer_t *p0, *p1;
440 ip6_header_t *ip60, *ip61;
441 u32 next0 = ILA_SIR2ILA_NEXT_DROP;
442 u32 next1 = ILA_SIR2ILA_NEXT_DROP;
443 BVT (clib_bihash_kv) kv0, value0;
444 BVT (clib_bihash_kv) kv1, value1;
445 ila_entry_t *ie0 = &ila_sir2ila_default_entry;
446 ila_entry_t *ie1 = &ila_sir2ila_default_entry;
447 ip6_address_t *ila_address0, *ila_address1;
450 vlib_buffer_t *p2, *p3;
452 p2 = vlib_get_buffer (vm, from[2]);
453 p3 = vlib_get_buffer (vm, from[3]);
455 vlib_prefetch_buffer_header (p2, LOAD);
456 vlib_prefetch_buffer_header (p3, LOAD);
457 CLIB_PREFETCH (p2->data, sizeof (ip6_header_t), LOAD);
458 CLIB_PREFETCH (p3->data, sizeof (ip6_header_t), LOAD);
461 pi0 = to_next[0] = from[0];
462 pi1 = to_next[1] = from[1];
468 p0 = vlib_get_buffer (vm, pi0);
469 p1 = vlib_get_buffer (vm, pi1);
470 ip60 = vlib_buffer_get_current (p0);
471 ip61 = vlib_buffer_get_current (p1);
472 ila_address0 = &ip60->dst_address;
473 ila_address1 = &ip61->dst_address;
474 kv0.key[0] = ip60->dst_address.as_u64[0];
475 kv0.key[1] = ip60->dst_address.as_u64[1];
477 kv1.key[0] = ip61->dst_address.as_u64[0];
478 kv1.key[1] = ip61->dst_address.as_u64[1];
481 if (PREDICT_TRUE((BV (clib_bihash_search)
482 (&ilm->id_to_entry_table, &kv0, &value0)) == 0)) {
483 ie0 = &ilm->entries[value0.value];
484 ila_address0 = (ie0->dir != ILA_DIR_ILA2SIR) ? &ie0->ila_address : ila_address0;
487 if ((BV (clib_bihash_search)
488 (&ilm->id_to_entry_table, &kv1, &value1)) == 0) {
489 ie1 = &ilm->entries[value1.value];
490 ila_address1 = (ie1->dir != ILA_DIR_ILA2SIR) ? &ie1->ila_address : ila_address1;
493 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
495 ila_sir2ila_trace_t *tr =
496 vlib_add_trace (vm, node, p0, sizeof (*tr));
498 (ie0 != &ila_sir2ila_default_entry) ? (ie0 - ilm->entries) : ~0;
499 tr->initial_dst = ip60->dst_address;
502 if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
504 ila_sir2ila_trace_t *tr =
505 vlib_add_trace (vm, node, p1, sizeof (*tr));
507 (ie1 != &ila_sir2ila_default_entry) ? (ie1 - ilm->entries) : ~0;
508 tr->initial_dst = ip61->dst_address;
511 ip60->dst_address.as_u64[0] = ila_address0->as_u64[0];
512 ip60->dst_address.as_u64[1] = ila_address0->as_u64[1];
513 ip61->dst_address.as_u64[0] = ila_address1->as_u64[0];
514 ip61->dst_address.as_u64[1] = ila_address1->as_u64[1];
516 vnet_get_config_data (&cm->config_main,
517 &p0->current_config_index, &next0, 0);
519 vnet_get_config_data (&cm->config_main,
520 &p1->current_config_index, &next1, 0);
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_get_config_data (&cm->config_main,
572 &p0->current_config_index, &next0, 0);
574 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
575 n_left_to_next, pi0, next0);
577 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
580 return frame->n_vectors;
583 VLIB_REGISTER_NODE (ila_sir2ila_node, static) =
585 .function = ila_sir2ila,.name = "sir-to-ila",.vector_size =
586 sizeof (u32),.format_trace = format_ila_sir2ila_trace,.n_errors =
587 ILA_N_ERROR,.error_strings = ila_error_strings,.n_next_nodes =
588 ILA_SIR2ILA_N_NEXT,.next_nodes =
590 [ILA_SIR2ILA_NEXT_DROP] = "error-drop"}
593 VNET_IP6_UNICAST_FEATURE_INIT (ila_sir2ila, static) =
595 .node_name = "sir-to-ila",.runs_before =
597 "ip6-lookup", 0},.feature_index = &ila_main.ila_sir2ila_feature_index,};
600 ila_add_del_entry (ila_add_del_entry_args_t * args)
602 ila_main_t *ilm = &ila_main;
603 ip6_main_t *im6 = &ip6_main;
604 BVT (clib_bihash_kv) kv, value;
607 if (args->type == ILA_TYPE_IID || args->type == ILA_TYPE_LUID)
609 if ((args->sir_address.as_u8[8] >> 5) != args->type)
611 clib_warning ("Incorrect SIR address (ILA type mismatch %d %d)",
612 args->sir_address.as_u8[8] >> 1, args->type);
615 if (args->sir_address.as_u8[8] & 0x10)
617 clib_warning ("Checksum bit should not be set in SIR address");
621 else if (args->type == ILA_TYPE_VNIDM)
623 if (args->sir_address.as_u8[0] != 0xff ||
624 (args->sir_address.as_u8[1] & 0xf0) != 0xf0)
626 clib_warning ("SIR multicast address must start with fff");
629 if (args->sir_address.as_u16[1] || args->sir_address.as_u16[2] ||
630 args->sir_address.as_u16[3] || args->sir_address.as_u16[4] ||
631 args->sir_address.as_u16[5] || (args->sir_address.as_u8[12] & 0xf0))
633 clib_warning ("SIR multicast address must start with fff");
641 pool_get (ilm->entries, e);
642 e->type = args->type;
643 e->sir_address = args->sir_address;
644 e->ila_adj_index = args->local_adj_index;
645 e->csum_mode = args->csum_mode;
648 //Construct ILA address
652 e->ila_address = e->sir_address;
655 e->ila_address.as_u64[0] = args->locator;
656 e->ila_address.as_u64[1] = args->sir_address.as_u64[1];
659 e->ila_address.as_u64[0] = args->locator;
660 e->ila_address.as_u8[8] = (ILA_TYPE_VNID6 << 1);
661 e->ila_address.as_u32[2] |= args->vnid;
662 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
665 e->ila_address.as_u64[0] = args->locator;
666 e->ila_address.as_u8[8] = (ILA_TYPE_VNIDM << 1);
667 e->ila_address.as_u32[2] |= args->vnid;
668 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
669 e->ila_address.as_u8[12] |= args->sir_address.as_u8[2] << 4;
672 clib_warning ("ILA type '%U' is not supported", format_ila_type,
677 //Modify ILA checksum if necessary
678 if (e->csum_mode == ILA_CSUM_MODE_NEUTRAL_MAP)
680 ip_csum_t csum = e->ila_address.as_u16[7];
682 for (i = 0; i < 4; i++)
684 csum = ip_csum_sub_even (csum, e->sir_address.as_u32[i]);
685 csum = ip_csum_add_even (csum, e->ila_address.as_u32[i]);
687 csum = ip_csum_add_even (csum, clib_host_to_net_u16 (0x1000));
688 e->ila_address.as_u16[7] = ip_csum_fold (csum);
689 e->ila_address.as_u8[8] |= 0x10;
692 //Create entry with the sir address
693 kv.key[0] = e->sir_address.as_u64[0];
694 kv.key[1] = e->sir_address.as_u64[1];
696 kv.value = e - ilm->entries;
697 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
700 if (e->ila_adj_index != ~0)
702 //This is a local entry - let's create a local adjacency
704 ip6_add_del_route_args_t route_args;
708 memset (&adj, 0, sizeof (adj));
709 adj.explicit_fib_index = ~0;
710 adj.lookup_next_index = ilm->ip6_lookup_next_index;
711 ad = (ila_adj_data_t *) & adj.opaque;
712 ad->entry_index = e - ilm->entries;
715 memset (&route_args, 0, sizeof (route_args));
716 route_args.table_index_or_table_id = 0;
717 route_args.flags = IP6_ROUTE_FLAG_ADD;
718 route_args.dst_address = e->ila_address;
719 route_args.dst_address_length = 128;
720 route_args.adj_index = ~0;
721 route_args.add_adj = &adj;
722 route_args.n_add_adj = 1;
724 ip6_add_del_route (im6, &route_args);
730 kv.key[0] = args->sir_address.as_u64[0];
731 kv.key[1] = args->sir_address.as_u64[1];
734 if ((BV (clib_bihash_search) (&ilm->id_to_entry_table, &kv, &value) <
740 e = &ilm->entries[value.value];
742 if (e->ila_adj_index != ~0)
744 //Delete that route - Associated adjacency will be deleted too
745 ip6_add_del_route_args_t route_args;
746 memset (&route_args, 0, sizeof (route_args));
747 route_args.table_index_or_table_id = 0;
748 route_args.flags = IP6_ROUTE_FLAG_DEL;
749 route_args.dst_address = e->ila_address;
750 route_args.dst_address_length = 128;
751 route_args.adj_index = ~0;
752 route_args.add_adj = NULL;
753 route_args.n_add_adj = 0;
755 ip6_add_del_route (im6, &route_args);
758 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
760 pool_put (ilm->entries, e);
766 ila_interface (u32 sw_if_index, u8 disable)
768 vlib_main_t *vm = vlib_get_main ();
769 ila_main_t *ilm = &ila_main;
770 ip6_main_t *im = &ip6_main;
771 ip_lookup_main_t *lm = &im->lookup_main;
772 ip_config_main_t *cm = &lm->rx_config_mains[VNET_UNICAST];
773 vnet_config_main_t *vcm = &cm->config_main;
774 u32 ci, feature_index;
776 vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
777 ci = cm->config_index_by_sw_if_index[sw_if_index];
778 feature_index = ilm->ila_sir2ila_feature_index;
780 ci = ((disable) ? vnet_config_del_feature : vnet_config_add_feature)
781 (vm, vcm, ci, feature_index,
783 /* # bytes of config data */ 0);
785 cm->config_index_by_sw_if_index[sw_if_index] = ci;
790 vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
793 clib_error_t *error = 0;
798 u8 *ila_format_adjacency(u8 * s, va_list * va)
800 ila_main_t *ilm = &ila_main;
801 __attribute((unused)) ip_lookup_main_t *lm = va_arg (*va, ip_lookup_main_t *);
802 ip_adjacency_t *adj = va_arg (*va, ip_adjacency_t *);
803 ila_adj_data_t * ad = (ila_adj_data_t *) & adj->opaque;
804 ila_entry_t *ie = pool_elt_at_index (ilm->entries, ad->entry_index);
805 return format(s, "idx:%d sir:%U", ad->entry_index, format_ip6_address, &ie->sir_address);
809 ila_init (vlib_main_t * vm)
811 ila_main_t *ilm = &ila_main;
814 ASSERT (sizeof (ila_adj_data_t) < IP_ADJACENCY_OPAQUE_SZ);
816 ilm->lookup_table_nbuckets = ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS;
817 ilm->lookup_table_nbuckets = 1 << max_log2 (ilm->lookup_table_nbuckets);
818 ilm->lookup_table_size = ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE;
820 BV (clib_bihash_init) (&ilm->id_to_entry_table,
821 "ila id to entry index table",
822 ilm->lookup_table_nbuckets, ilm->lookup_table_size);
827 VNET_IP6_REGISTER_ADJACENCY(ila2sir) = {
828 .node_name = "ila-to-sir",
829 .fn = ila_format_adjacency,
830 .next_index = &ila_main.ip6_lookup_next_index
833 VLIB_INIT_FUNCTION (ila_init);
835 static clib_error_t *
836 ila_entry_command_fn (vlib_main_t * vm,
837 unformat_input_t * input, vlib_cli_command_t * cmd)
839 unformat_input_t _line_input, *line_input = &_line_input;
840 ila_add_del_entry_args_t args = { 0 };
841 ip6_address_t next_hop;
843 ip6_main_t *im6 = &ip6_main;
846 args.type = ILA_TYPE_IID;
847 args.csum_mode = ILA_CSUM_MODE_NO_ACTION;
848 args.local_adj_index = ~0;
849 args.dir = ILA_DIR_BIDIR;
851 if (!unformat_user (input, unformat_line_input, line_input))
854 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
856 if (unformat (line_input, "type %U", unformat_ila_type, &args.type))
860 (line_input, "sir-address %U", unformat_ip6_address,
865 (line_input, "locator %U", unformat_half_ip6_address,
868 else if (unformat (line_input, "adj-index %u", &args.local_adj_index))
872 (line_input, "csum-mode %U", unformat_ila_csum_mode,
875 else if (unformat (line_input, "vnid %x", &args.vnid))
879 (line_input, "next-hop %U", unformat_ip6_address, &next_hop))
882 (line_input, "direction %U", unformat_ila_direction, &args.dir))
884 else if (unformat (line_input, "del"))
887 return clib_error_return (0, "parse error: '%U'",
888 format_unformat_error, line_input);
891 unformat_free (line_input);
895 if (args.local_adj_index != ~0)
896 return clib_error_return (0,
897 "Specified both next hop and adjacency index");
899 u32 ai = ip6_get_route (im6, 0, 0, &next_hop, 128);
901 return clib_error_return (0, "No route to next-hop %U",
902 format_ip6_address, &next_hop);
904 ip_lookup_main_t *lm6 = &ip6_main.lookup_main;
905 ip_adjacency_t *adj6 = ip_get_adjacency (lm6, ai);
906 if (adj6->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
908 return clib_error_return (0,
909 "Next-Hop route has to be a rewrite route");
911 args.local_adj_index = ai;
914 if ((ret = ila_add_del_entry (&args)))
915 return clib_error_return (0, "ila_add_del_entry returned error %d", ret);
920 VLIB_CLI_COMMAND (ila_entry_command, static) =
923 .short_help = "ila entry [type <type>] [sir-address <address>] [locator <locator>] [vnid <hex-vnid>]"
924 " [adj-index <adj-index>] [next-hop <next-hop>] [direction (bidir|sir2ila|ila2sir)]"
925 " [csum-mode (no-action|neutral-map|transport-adjust)] [del]",
926 .function = ila_entry_command_fn,
929 static clib_error_t *
930 ila_interface_command_fn (vlib_main_t * vm,
931 unformat_input_t * input, vlib_cli_command_t * cmd)
933 vnet_main_t *vnm = vnet_get_main ();
934 u32 sw_if_index = ~0;
937 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
939 return clib_error_return (0, "Invalid interface name");
942 if (unformat (input, "disable"))
948 if ((ret = ila_interface (sw_if_index, disable)))
949 return clib_error_return (0, "ila_interface returned error %d", ret);
954 VLIB_CLI_COMMAND (ila_interface_command, static) =
956 .path = "ila interface",
957 .short_help = "ila interface <interface-name> [disable]",
958 .function = ila_interface_command_fn,
961 static clib_error_t *
962 ila_show_entries_command_fn (vlib_main_t * vm,
963 unformat_input_t * input,
964 vlib_cli_command_t * cmd)
966 vnet_main_t *vnm = vnet_get_main ();
967 ila_main_t *ilm = &ila_main;
970 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, NULL);
971 pool_foreach (e, ilm->entries,
973 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, e);
979 VLIB_CLI_COMMAND (ila_show_entries_command, static) =
981 .path = "show ila entries",
982 .short_help = "show ila entries",
983 .function = ila_show_entries_command_fn,