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 - ilm->entries;
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 - ilm->entries;
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->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
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",
596 .runs_before = ORDER_CONSTRAINTS{"ip6-lookup", 0},
597 .feature_index = &ila_main.ila_sir2ila_feature_index,
601 ila_add_del_entry (ila_add_del_entry_args_t * args)
603 ila_main_t *ilm = &ila_main;
604 ip6_main_t *im6 = &ip6_main;
605 BVT (clib_bihash_kv) kv, value;
608 if (args->type == ILA_TYPE_IID || args->type == ILA_TYPE_LUID)
610 if ((args->sir_address.as_u8[8] >> 5) != args->type)
612 clib_warning ("Incorrect SIR address (ILA type mismatch %d %d)",
613 args->sir_address.as_u8[8] >> 1, args->type);
616 if (args->sir_address.as_u8[8] & 0x10)
618 clib_warning ("Checksum bit should not be set in SIR address");
622 else if (args->type == ILA_TYPE_VNIDM)
624 if (args->sir_address.as_u8[0] != 0xff ||
625 (args->sir_address.as_u8[1] & 0xf0) != 0xf0)
627 clib_warning ("SIR multicast address must start with fff");
630 if (args->sir_address.as_u16[1] || args->sir_address.as_u16[2] ||
631 args->sir_address.as_u16[3] || args->sir_address.as_u16[4] ||
632 args->sir_address.as_u16[5] || (args->sir_address.as_u8[12] & 0xf0))
634 clib_warning ("SIR multicast address must start with fff");
642 pool_get (ilm->entries, e);
643 e->type = args->type;
644 e->sir_address = args->sir_address;
645 e->ila_adj_index = args->local_adj_index;
646 e->csum_mode = args->csum_mode;
649 //Construct ILA address
653 e->ila_address = e->sir_address;
656 e->ila_address.as_u64[0] = args->locator;
657 e->ila_address.as_u64[1] = args->sir_address.as_u64[1];
660 e->ila_address.as_u64[0] = args->locator;
661 e->ila_address.as_u8[8] = (ILA_TYPE_VNID6 << 1);
662 e->ila_address.as_u32[2] |= args->vnid;
663 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
666 e->ila_address.as_u64[0] = args->locator;
667 e->ila_address.as_u8[8] = (ILA_TYPE_VNIDM << 1);
668 e->ila_address.as_u32[2] |= args->vnid;
669 e->ila_address.as_u32[3] = args->sir_address.as_u32[3];
670 e->ila_address.as_u8[12] |= args->sir_address.as_u8[2] << 4;
673 clib_warning ("ILA type '%U' is not supported", format_ila_type,
678 //Modify ILA checksum if necessary
679 if (e->csum_mode == ILA_CSUM_MODE_NEUTRAL_MAP)
681 ip_csum_t csum = e->ila_address.as_u16[7];
683 for (i = 0; i < 4; i++)
685 csum = ip_csum_sub_even (csum, e->sir_address.as_u32[i]);
686 csum = ip_csum_add_even (csum, e->ila_address.as_u32[i]);
688 csum = ip_csum_add_even (csum, clib_host_to_net_u16 (0x1000));
689 e->ila_address.as_u16[7] = ip_csum_fold (csum);
690 e->ila_address.as_u8[8] |= 0x10;
693 //Create entry with the sir address
694 kv.key[0] = e->sir_address.as_u64[0];
695 kv.key[1] = e->sir_address.as_u64[1];
697 kv.value = e - ilm->entries;
698 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
701 if (e->ila_adj_index != ~0)
703 //This is a local entry - let's create a local adjacency
705 ip6_add_del_route_args_t route_args;
709 memset (&adj, 0, sizeof (adj));
710 adj.explicit_fib_index = ~0;
711 adj.lookup_next_index = ilm->ip6_lookup_next_index;
712 ad = (ila_adj_data_t *) & adj.opaque;
713 ad->entry_index = e - ilm->entries;
716 memset (&route_args, 0, sizeof (route_args));
717 route_args.table_index_or_table_id = 0;
718 route_args.flags = IP6_ROUTE_FLAG_ADD;
719 route_args.dst_address = e->ila_address;
720 route_args.dst_address_length = 128;
721 route_args.adj_index = ~0;
722 route_args.add_adj = &adj;
723 route_args.n_add_adj = 1;
725 ip6_add_del_route (im6, &route_args);
731 kv.key[0] = args->sir_address.as_u64[0];
732 kv.key[1] = args->sir_address.as_u64[1];
735 if ((BV (clib_bihash_search) (&ilm->id_to_entry_table, &kv, &value) <
741 e = &ilm->entries[value.value];
743 if (e->ila_adj_index != ~0)
745 //Delete that route - Associated adjacency will be deleted too
746 ip6_add_del_route_args_t route_args;
747 memset (&route_args, 0, sizeof (route_args));
748 route_args.table_index_or_table_id = 0;
749 route_args.flags = IP6_ROUTE_FLAG_DEL;
750 route_args.dst_address = e->ila_address;
751 route_args.dst_address_length = 128;
752 route_args.adj_index = ~0;
753 route_args.add_adj = NULL;
754 route_args.n_add_adj = 0;
756 ip6_add_del_route (im6, &route_args);
759 BV (clib_bihash_add_del) (&ilm->id_to_entry_table, &kv,
761 pool_put (ilm->entries, e);
767 ila_interface (u32 sw_if_index, u8 disable)
769 vlib_main_t *vm = vlib_get_main ();
770 ila_main_t *ilm = &ila_main;
771 ip6_main_t *im = &ip6_main;
772 ip_lookup_main_t *lm = &im->lookup_main;
773 ip_config_main_t *cm = &lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
774 vnet_config_main_t *vcm = &cm->config_main;
775 u32 ci, feature_index;
777 vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
778 ci = cm->config_index_by_sw_if_index[sw_if_index];
779 feature_index = ilm->ila_sir2ila_feature_index;
781 ci = ((disable) ? vnet_config_del_feature : vnet_config_add_feature)
782 (vm, vcm, ci, feature_index,
784 /* # bytes of config data */ 0);
786 cm->config_index_by_sw_if_index[sw_if_index] = ci;
791 vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
794 clib_error_t *error = 0;
799 u8 *ila_format_adjacency(u8 * s, va_list * va)
801 ila_main_t *ilm = &ila_main;
802 __attribute((unused)) ip_lookup_main_t *lm = va_arg (*va, ip_lookup_main_t *);
803 ip_adjacency_t *adj = va_arg (*va, ip_adjacency_t *);
804 ila_adj_data_t * ad = (ila_adj_data_t *) & adj->opaque;
805 ila_entry_t *ie = pool_elt_at_index (ilm->entries, ad->entry_index);
806 return format(s, "idx:%d sir:%U", ad->entry_index, format_ip6_address, &ie->sir_address);
810 ila_init (vlib_main_t * vm)
812 ila_main_t *ilm = &ila_main;
815 ASSERT (sizeof (ila_adj_data_t) < IP_ADJACENCY_OPAQUE_SZ);
817 ilm->lookup_table_nbuckets = ILA_TABLE_DEFAULT_HASH_NUM_BUCKETS;
818 ilm->lookup_table_nbuckets = 1 << max_log2 (ilm->lookup_table_nbuckets);
819 ilm->lookup_table_size = ILA_TABLE_DEFAULT_HASH_MEMORY_SIZE;
821 BV (clib_bihash_init) (&ilm->id_to_entry_table,
822 "ila id to entry index table",
823 ilm->lookup_table_nbuckets, ilm->lookup_table_size);
828 VNET_IP6_REGISTER_ADJACENCY(ila2sir) = {
829 .node_name = "ila-to-sir",
830 .fn = ila_format_adjacency,
831 .next_index = &ila_main.ip6_lookup_next_index
834 VLIB_INIT_FUNCTION (ila_init);
836 static clib_error_t *
837 ila_entry_command_fn (vlib_main_t * vm,
838 unformat_input_t * input, vlib_cli_command_t * cmd)
840 unformat_input_t _line_input, *line_input = &_line_input;
841 ila_add_del_entry_args_t args = { 0 };
842 ip6_address_t next_hop;
844 ip6_main_t *im6 = &ip6_main;
847 args.type = ILA_TYPE_IID;
848 args.csum_mode = ILA_CSUM_MODE_NO_ACTION;
849 args.local_adj_index = ~0;
850 args.dir = ILA_DIR_BIDIR;
852 if (!unformat_user (input, unformat_line_input, line_input))
855 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
857 if (unformat (line_input, "type %U", unformat_ila_type, &args.type))
861 (line_input, "sir-address %U", unformat_ip6_address,
866 (line_input, "locator %U", unformat_half_ip6_address,
869 else if (unformat (line_input, "adj-index %u", &args.local_adj_index))
873 (line_input, "csum-mode %U", unformat_ila_csum_mode,
876 else if (unformat (line_input, "vnid %x", &args.vnid))
880 (line_input, "next-hop %U", unformat_ip6_address, &next_hop))
883 (line_input, "direction %U", unformat_ila_direction, &args.dir))
885 else if (unformat (line_input, "del"))
888 return clib_error_return (0, "parse error: '%U'",
889 format_unformat_error, line_input);
892 unformat_free (line_input);
896 if (args.local_adj_index != ~0)
897 return clib_error_return (0,
898 "Specified both next hop and adjacency index");
900 u32 ai = ip6_get_route (im6, 0, 0, &next_hop, 128);
902 return clib_error_return (0, "No route to next-hop %U",
903 format_ip6_address, &next_hop);
905 ip_lookup_main_t *lm6 = &ip6_main.lookup_main;
906 ip_adjacency_t *adj6 = ip_get_adjacency (lm6, ai);
907 if (adj6->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
909 return clib_error_return (0,
910 "Next-Hop route has to be a rewrite route");
912 args.local_adj_index = ai;
915 if ((ret = ila_add_del_entry (&args)))
916 return clib_error_return (0, "ila_add_del_entry returned error %d", ret);
921 VLIB_CLI_COMMAND (ila_entry_command, static) =
924 .short_help = "ila entry [type <type>] [sir-address <address>] [locator <locator>] [vnid <hex-vnid>]"
925 " [adj-index <adj-index>] [next-hop <next-hop>] [direction (bidir|sir2ila|ila2sir)]"
926 " [csum-mode (no-action|neutral-map|transport-adjust)] [del]",
927 .function = ila_entry_command_fn,
930 static clib_error_t *
931 ila_interface_command_fn (vlib_main_t * vm,
932 unformat_input_t * input, vlib_cli_command_t * cmd)
934 vnet_main_t *vnm = vnet_get_main ();
935 u32 sw_if_index = ~0;
938 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
940 return clib_error_return (0, "Invalid interface name");
943 if (unformat (input, "disable"))
949 if ((ret = ila_interface (sw_if_index, disable)))
950 return clib_error_return (0, "ila_interface returned error %d", ret);
955 VLIB_CLI_COMMAND (ila_interface_command, static) =
957 .path = "ila interface",
958 .short_help = "ila interface <interface-name> [disable]",
959 .function = ila_interface_command_fn,
962 static clib_error_t *
963 ila_show_entries_command_fn (vlib_main_t * vm,
964 unformat_input_t * input,
965 vlib_cli_command_t * cmd)
967 vnet_main_t *vnm = vnet_get_main ();
968 ila_main_t *ilm = &ila_main;
971 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, NULL);
972 pool_foreach (e, ilm->entries,
974 vlib_cli_output (vm, " %U\n", format_ila_entry, vnm, e);
980 VLIB_CLI_COMMAND (ila_show_entries_command, static) =
982 .path = "show ila entries",
983 .short_help = "show ila entries",
984 .function = ila_show_entries_command_fn,