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.
16 #include <vlibmemory/api.h>
17 #include <vnet/lisp-cp/control.h>
18 #include <vnet/lisp-cp/packets.h>
19 #include <vnet/lisp-cp/lisp_msg_serdes.h>
20 #include <vnet/lisp-gpe/lisp_gpe.h>
21 #include <vnet/fib/fib_entry.h>
22 #include <vnet/fib/fib_table.h>
33 vnet_lisp_get_map_request_mode (void)
35 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
36 return lcm->map_request_mode;
40 queue_map_request (gid_address_t * seid, gid_address_t * deid,
41 u8 smr_invoked, u8 is_resend);
43 ip_interface_address_t *
44 ip_interface_get_first_interface_address (ip_lookup_main_t * lm,
45 u32 sw_if_index, u8 loop)
47 vnet_main_t *vnm = vnet_get_main ();
48 vnet_sw_interface_t *swif = vnet_get_sw_interface (vnm, sw_if_index);
49 if (loop && swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
50 sw_if_index = swif->unnumbered_sw_if_index;
52 (vec_len ((lm)->if_address_pool_index_by_sw_if_index) > (sw_if_index)) ?
53 vec_elt ((lm)->if_address_pool_index_by_sw_if_index, (sw_if_index)) :
55 return pool_elt_at_index ((lm)->if_address_pool, ia);
59 ip_interface_get_first_address (ip_lookup_main_t * lm, u32 sw_if_index,
62 ip_interface_address_t *ia;
64 ia = ip_interface_get_first_interface_address (lm, sw_if_index, 1);
67 return ip_interface_address_get_address (lm, ia);
71 ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index,
72 u8 version, ip_address_t * result)
77 lm = (version == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
78 addr = ip_interface_get_first_address (lm, sw_if_index, version);
82 ip_address_set (result, addr, version);
87 * convert from a LISP address to a FIB prefix
90 ip_address_to_fib_prefix (const ip_address_t * addr, fib_prefix_t * prefix)
92 if (addr->version == IP4)
95 prefix->fp_proto = FIB_PROTOCOL_IP4;
96 memset (&prefix->fp_addr.pad, 0, sizeof (prefix->fp_addr.pad));
97 memcpy (&prefix->fp_addr.ip4, &addr->ip, sizeof (prefix->fp_addr.ip4));
101 prefix->fp_len = 128;
102 prefix->fp_proto = FIB_PROTOCOL_IP6;
103 memcpy (&prefix->fp_addr.ip6, &addr->ip, sizeof (prefix->fp_addr.ip6));
108 * convert from a LISP to a FIB prefix
111 ip_prefix_to_fib_prefix (const ip_prefix_t * ip_prefix,
112 fib_prefix_t * fib_prefix)
114 ip_address_to_fib_prefix (&ip_prefix->addr, fib_prefix);
115 fib_prefix->fp_len = ip_prefix->len;
119 * Find the sw_if_index of the interface that would be used to egress towards
123 ip_fib_get_egress_iface_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst)
125 fib_node_index_t fei;
128 ip_address_to_fib_prefix (dst, &prefix);
130 fei = fib_table_lookup (0, &prefix);
132 return (fib_entry_get_resolving_interface (fei));
136 * Find first IP of the interface that would be used to egress towards dst.
137 * Returns 1 if the address is found 0 otherwise.
140 ip_fib_get_first_egress_ip_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst,
141 ip_address_t * result)
144 ip_lookup_main_t *lm;
148 ASSERT (result != 0);
150 ipver = ip_addr_version (dst);
152 lm = (ipver == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
153 si = ip_fib_get_egress_iface_for_dst (lcm, dst);
158 /* find the first ip address */
159 addr = ip_interface_get_first_address (lm, si, ipver);
163 ip_address_set (result, addr, ipver);
168 dp_add_del_iface (lisp_cp_main_t * lcm, u32 vni, u8 is_l2, u8 is_add)
170 uword *dp_table, *intf;
171 vnet_lisp_gpe_add_del_iface_args_t _ai, *ai = &_ai;
175 dp_table = hash_get (lcm->table_id_by_vni, vni);
179 clib_warning ("vni %d not associated to a vrf!", vni);
180 return VNET_API_ERROR_INVALID_VALUE;
185 dp_table = hash_get (lcm->bd_id_by_vni, vni);
188 clib_warning ("vni %d not associated to a bridge domain!", vni);
189 return VNET_API_ERROR_INVALID_VALUE;
193 intf = hash_get (is_l2 ? lcm->l2_dp_intf_by_vni : lcm->dp_intf_by_vni, vni);
195 /* enable/disable data-plane interface */
198 /* create interface */
204 ai->dp_table = dp_table[0];
206 vnet_lisp_gpe_add_del_iface (ai, 0);
208 /* keep track of vnis for which interfaces have been created */
209 hash_set (lcm->dp_intf_by_vni, vni, 1);
216 clib_warning ("interface for vni %d doesn't exist!", vni);
217 return VNET_API_ERROR_INVALID_VALUE;
222 ai->dp_table = dp_table[0];
223 vnet_lisp_gpe_add_del_iface (ai, 0);
224 hash_unset (lcm->dp_intf_by_vni, vni);
231 dp_del_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
233 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
236 memset (a, 0, sizeof (*a));
238 feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index);
242 fe = pool_elt_at_index (lcm->fwd_entry_pool, feip[0]);
244 /* delete dp fwd entry */
247 a->locator_pairs = fe->locator_pairs;
248 a->vni = gid_address_vni (&fe->reid);
249 gid_address_copy (&a->rmt_eid, &fe->reid);
251 vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
253 /* delete entry in fwd table */
254 hash_unset (lcm->fwd_entry_by_mapping_index, dst_map_index);
255 vec_free (fe->locator_pairs);
256 pool_put (lcm->fwd_entry_pool, fe);
260 * Finds first remote locator with best (lowest) priority that has a local
261 * peer locator with an underlying route to it.
265 get_locator_pairs (lisp_cp_main_t * lcm, mapping_t * lcl_map,
266 mapping_t * rmt_map, locator_pair_t ** locator_pairs)
268 u32 i, limitp = 0, li, found = 0, esi;
269 locator_set_t *rmt_ls, *lcl_ls;
270 ip_address_t _lcl_addr, *lcl_addr = &_lcl_addr;
271 locator_t *lp, *rmt = 0;
276 pool_elt_at_index (lcm->locator_set_pool, rmt_map->locator_set_index);
278 pool_elt_at_index (lcm->locator_set_pool, lcl_map->locator_set_index);
280 if (!rmt_ls || vec_len (rmt_ls->locator_indices) == 0)
287 /* find unvisited remote locator with best priority */
288 for (i = 0; i < vec_len (rmt_ls->locator_indices); i++)
290 if (0 != hash_get (checked, i))
293 li = vec_elt (rmt_ls->locator_indices, i);
294 lp = pool_elt_at_index (lcm->locator_pool, li);
296 /* we don't support non-IP locators for now */
297 if (gid_address_type (&lp->address) != GID_ADDR_IP_PREFIX)
300 if ((found && lp->priority == limitp)
301 || (!found && lp->priority >= limitp))
305 /* don't search for locators with lower priority and don't
306 * check this locator again*/
307 limitp = lp->priority;
308 hash_set (checked, i, 1);
312 /* check if a local locator with a route to remote locator exists */
315 /* find egress sw_if_index for rmt locator */
317 ip_fib_get_egress_iface_for_dst (lcm,
318 &gid_address_ip (&rmt->address));
319 if ((u32) ~ 0 == esi)
322 for (i = 0; i < vec_len (lcl_ls->locator_indices); i++)
324 li = vec_elt (lcl_ls->locator_indices, i);
325 locator_t *sl = pool_elt_at_index (lcm->locator_pool, li);
327 /* found local locator with the needed sw_if_index */
328 if (sl->sw_if_index == esi)
330 /* and it has an address */
331 if (0 == ip_interface_get_first_ip_address (lcm,
333 gid_address_ip_version
338 memset (&pair, 0, sizeof (pair));
339 ip_address_copy (&pair.rmt_loc,
340 &gid_address_ip (&rmt->address));
341 ip_address_copy (&pair.lcl_loc, lcl_addr);
342 pair.weight = rmt->weight;
343 vec_add1 (locator_pairs[0], pair);
357 gid_address_sd_to_flat (gid_address_t * dst, gid_address_t * src,
360 ASSERT (GID_ADDR_SRC_DST == gid_address_type (src));
364 switch (fid_addr_type (fid))
366 case FID_ADDR_IP_PREF:
367 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
368 gid_address_ippref (dst) = fid_addr_ippref (fid);
371 gid_address_type (dst) = GID_ADDR_MAC;
372 mac_copy (gid_address_mac (dst), fid_addr_mac (fid));
375 clib_warning ("Unsupported fid type %d!", fid_addr_type (fid));
381 dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
383 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
384 mapping_t *src_map, *dst_map;
386 uword *feip = 0, *dpid;
390 memset (a, 0, sizeof (*a));
392 /* remove entry if it already exists */
393 feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index);
395 dp_del_fwd_entry (lcm, src_map_index, dst_map_index);
397 src_map = pool_elt_at_index (lcm->mapping_pool, src_map_index);
398 dst_map = pool_elt_at_index (lcm->mapping_pool, dst_map_index);
400 /* insert data plane forwarding entry */
403 if (GID_ADDR_SRC_DST == gid_address_type (&dst_map->eid))
405 gid_address_sd_to_flat (&a->rmt_eid, &dst_map->eid,
406 &gid_address_sd_dst (&dst_map->eid));
407 gid_address_sd_to_flat (&a->lcl_eid, &dst_map->eid,
408 &gid_address_sd_src (&dst_map->eid));
411 gid_address_copy (&a->rmt_eid, &dst_map->eid);
413 a->vni = gid_address_vni (&a->rmt_eid);
415 /* get vrf or bd_index associated to vni */
416 type = gid_address_type (&a->rmt_eid);
417 if (GID_ADDR_IP_PREFIX == type)
419 dpid = hash_get (lcm->table_id_by_vni, a->vni);
422 clib_warning ("vni %d not associated to a vrf!", a->vni);
425 a->table_id = dpid[0];
427 else if (GID_ADDR_MAC == type)
429 dpid = hash_get (lcm->bd_id_by_vni, a->vni);
432 clib_warning ("vni %d not associated to a bridge domain !", a->vni);
438 /* find best locator pair that 1) verifies LISP policy 2) are connected */
439 if (0 == get_locator_pairs (lcm, src_map, dst_map, &a->locator_pairs))
443 a->action = dst_map->action;
447 u8 ipver = ip_prefix_version (&gid_address_ippref (&a->rmt_eid));
448 a->decap_next_index = (ipver == IP4) ?
449 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
451 vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
453 /* add tunnel to fwd entry table XXX check return value from DP insertion */
454 pool_get (lcm->fwd_entry_pool, fe);
455 fe->locator_pairs = a->locator_pairs;
456 gid_address_copy (&fe->reid, &a->rmt_eid);
457 hash_set (lcm->fwd_entry_by_mapping_index, dst_map_index,
458 fe - lcm->fwd_entry_pool);
462 * Add/remove mapping to/from map-cache. Overwriting not allowed.
465 vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a,
466 u32 * map_index_result)
468 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
469 u32 mi, *map_indexp, map_index, i;
470 mapping_t *m, *old_map;
473 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->eid);
474 old_map = mi != ~0 ? pool_elt_at_index (lcm->mapping_pool, mi) : 0;
477 /* TODO check if overwriting and take appropriate actions */
478 if (mi != GID_LOOKUP_MISS && !gid_address_cmp (&old_map->eid, &a->eid))
480 clib_warning ("eid %U found in the eid-table", format_gid_address,
482 return VNET_API_ERROR_VALUE_EXIST;
485 pool_get (lcm->mapping_pool, m);
486 gid_address_copy (&m->eid, &a->eid);
487 m->locator_set_index = a->locator_set_index;
489 m->action = a->action;
491 m->is_static = a->is_static;
493 map_index = m - lcm->mapping_pool;
494 gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, map_index,
497 if (pool_is_free_index (lcm->locator_set_pool, a->locator_set_index))
499 clib_warning ("Locator set with index %d doesn't exist",
500 a->locator_set_index);
501 return VNET_API_ERROR_INVALID_VALUE;
504 /* add eid to list of eids supported by locator-set */
505 vec_validate (lcm->locator_set_to_eids, a->locator_set_index);
506 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids,
507 a->locator_set_index);
508 vec_add1 (eid_indexes[0], map_index);
513 vec_add1 (lcm->local_mappings_indexes, map_index);
515 map_index_result[0] = map_index;
519 if (mi == GID_LOOKUP_MISS)
521 clib_warning ("eid %U not found in the eid-table",
522 format_gid_address, &a->eid);
523 return VNET_API_ERROR_INVALID_VALUE;
526 /* clear locator-set to eids binding */
527 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids,
528 a->locator_set_index);
529 for (i = 0; i < vec_len (eid_indexes[0]); i++)
531 map_indexp = vec_elt_at_index (eid_indexes[0], i);
532 if (map_indexp[0] == mi)
535 vec_del1 (eid_indexes[0], i);
537 /* remove local mark if needed */
538 m = pool_elt_at_index (lcm->mapping_pool, mi);
542 for (k = 0; k < vec_len (lcm->local_mappings_indexes); k++)
544 lm_indexp = vec_elt_at_index (lcm->local_mappings_indexes, k);
545 if (lm_indexp[0] == mi)
548 vec_del1 (lcm->local_mappings_indexes, k);
551 /* remove mapping from dictionary */
552 gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, 0, 0);
553 gid_address_free (&m->eid);
554 pool_put_index (lcm->mapping_pool, mi);
561 * Add/update/delete mapping to/in/from map-cache.
564 vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a,
565 u32 * map_index_result)
571 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
573 if (vnet_lisp_enable_disable_status () == 0)
575 clib_warning ("LISP is disabled!");
576 return VNET_API_ERROR_LISP_DISABLED;
579 vni = gid_address_vni (&a->eid);
580 type = gid_address_type (&a->eid);
581 if (GID_ADDR_IP_PREFIX == type)
582 dp_table = hash_get (lcm->table_id_by_vni, vni);
583 else if (GID_ADDR_MAC == type)
584 dp_table = hash_get (lcm->bd_id_by_vni, vni);
588 clib_warning ("vni %d not associated to a %s!", vni,
589 GID_ADDR_IP_PREFIX == type ? "vrf" : "bd");
590 return VNET_API_ERROR_INVALID_VALUE;
593 /* store/remove mapping from map-cache */
594 return vnet_lisp_map_cache_add_del (a, map_index_result);
597 static clib_error_t *
598 lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
599 vlib_cli_command_t * cmd)
601 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
602 unformat_input_t _line_input, *line_input = &_line_input;
605 gid_address_t *eids = 0;
606 clib_error_t *error = 0;
607 u8 *locator_set_name = 0;
608 u32 locator_set_index = 0, map_index = 0;
610 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
614 memset (&eid, 0, sizeof (eid));
615 memset (a, 0, sizeof (*a));
617 /* Get a line of input. */
618 if (!unformat_user (input, unformat_line_input, line_input))
621 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
623 if (unformat (line_input, "add"))
625 else if (unformat (line_input, "del"))
627 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
629 else if (unformat (line_input, "vni %d", &vni))
630 gid_address_vni (&eid) = vni;
631 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
633 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
636 error = clib_error_return (0, "locator-set %s doesn't exist",
640 locator_set_index = p[0];
644 error = unformat_parse_error (line_input);
648 /* XXX treat batch configuration */
650 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
653 clib_error_return (0, "src/dst is not supported for local EIDs!");
657 gid_address_copy (&a->eid, &eid);
659 a->locator_set_index = locator_set_index;
662 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
665 error = clib_error_return (0, "failed to %s local mapping!",
666 is_add ? "add" : "delete");
670 if (locator_set_name)
671 vec_free (locator_set_name);
672 gid_address_free (&a->eid);
677 VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = {
678 .path = "lisp eid-table",
679 .short_help = "lisp eid-table add/del [vni <vni>] eid <eid> "
680 "locator-set <locator-set>",
681 .function = lisp_add_del_local_eid_command_fn,
686 vnet_lisp_eid_table_map (u32 vni, u32 dp_id, u8 is_l2, u8 is_add)
688 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
689 uword *dp_idp, *vnip, **dp_table_by_vni, **vni_by_dp_table;
691 if (vnet_lisp_enable_disable_status () == 0)
693 clib_warning ("LISP is disabled!");
697 dp_table_by_vni = is_l2 ? &lcm->bd_id_by_vni : &lcm->table_id_by_vni;
698 vni_by_dp_table = is_l2 ? &lcm->vni_by_bd_id : &lcm->vni_by_table_id;
700 if (!is_l2 && (vni == 0 || dp_id == 0))
702 clib_warning ("can't add/del default vni-vrf mapping!");
706 dp_idp = hash_get (dp_table_by_vni[0], vni);
707 vnip = hash_get (vni_by_dp_table[0], dp_id);
713 clib_warning ("vni %d or vrf %d already used in vrf/vni "
714 "mapping!", vni, dp_id);
717 hash_set (dp_table_by_vni[0], vni, dp_id);
718 hash_set (vni_by_dp_table[0], dp_id, vni);
720 /* create dp iface */
721 dp_add_del_iface (lcm, vni, is_l2, 1);
725 if (!dp_idp || !vnip)
727 clib_warning ("vni %d or vrf %d not used in any vrf/vni! "
728 "mapping!", vni, dp_id);
731 hash_unset (dp_table_by_vni[0], vni);
732 hash_unset (vni_by_dp_table[0], dp_id);
734 /* remove dp iface */
735 dp_add_del_iface (lcm, vni, is_l2, 0);
741 static clib_error_t *
742 lisp_eid_table_map_command_fn (vlib_main_t * vm,
743 unformat_input_t * input,
744 vlib_cli_command_t * cmd)
746 u8 is_add = 1, is_l2 = 0;
747 u32 vni = 0, dp_id = 0;
748 unformat_input_t _line_input, *line_input = &_line_input;
750 /* Get a line of input. */
751 if (!unformat_user (input, unformat_line_input, line_input))
754 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
756 if (unformat (line_input, "del"))
758 else if (unformat (line_input, "vni %d", &vni))
760 else if (unformat (line_input, "vrf %d", &dp_id))
762 else if (unformat (line_input, "bd %d", &dp_id))
766 return unformat_parse_error (line_input);
769 vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
774 VLIB_CLI_COMMAND (lisp_eid_table_map_command) = {
775 .path = "lisp eid-table map",
776 .short_help = "lisp eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
777 .function = lisp_eid_table_map_command_fn,
781 /* return 0 if the two locator sets are identical 1 otherwise */
783 compare_locators (lisp_cp_main_t * lcm, u32 * old_ls_indexes,
784 locator_t * new_locators)
787 locator_t *old_loc, *new_loc;
789 if (vec_len (old_ls_indexes) != vec_len (new_locators))
792 for (i = 0; i < vec_len (new_locators); i++)
794 old_li = vec_elt (old_ls_indexes, i);
795 old_loc = pool_elt_at_index (lcm->locator_pool, old_li);
797 new_loc = vec_elt_at_index (new_locators, i);
799 if (locator_cmp (old_loc, new_loc))
806 * Adds/removes/updates mapping. Does not program forwarding.
808 * @param eid end-host identifier
809 * @param rlocs vector of remote locators
810 * @param action action for negative map-reply
811 * @param is_add add mapping if non-zero, delete otherwise
812 * @param res_map_index the map-index that was created/updated/removed. It is
813 * set to ~0 if no action is taken.
814 * @param is_static used for distinguishing between statically learned
815 remote mappings and mappings obtained from MR
816 * @return return code
819 vnet_lisp_add_del_mapping (gid_address_t * eid, locator_t * rlocs, u8 action,
820 u8 authoritative, u32 ttl, u8 is_add, u8 is_static,
823 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
824 vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args;
825 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
826 u32 mi, ls_index = 0, dst_map_index;
829 if (vnet_lisp_enable_disable_status () == 0)
831 clib_warning ("LISP is disabled!");
832 return VNET_API_ERROR_LISP_DISABLED;
836 res_map_index[0] = ~0;
838 memset (m_args, 0, sizeof (m_args[0]));
839 memset (ls_args, 0, sizeof (ls_args[0]));
841 ls_args->locators = rlocs;
843 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
844 old_map = ((u32) ~ 0 != mi) ? pool_elt_at_index (lcm->mapping_pool, mi) : 0;
848 /* overwrite: if mapping already exists, decide if locators should be
849 * updated and be done */
850 if (old_map && gid_address_cmp (&old_map->eid, eid) == 0)
852 if (!is_static && (old_map->is_static || old_map->local))
854 /* do not overwrite local or static remote mappings */
855 clib_warning ("mapping %U rejected due to collision with local "
856 "or static remote mapping!", format_gid_address,
861 locator_set_t *old_ls;
863 /* update mapping attributes */
864 old_map->action = action;
865 old_map->authoritative = authoritative;
868 old_ls = pool_elt_at_index (lcm->locator_set_pool,
869 old_map->locator_set_index);
870 if (compare_locators (lcm, old_ls->locator_indices,
873 /* set locator-set index to overwrite */
875 ls_args->index = old_map->locator_set_index;
876 vnet_lisp_add_del_locator_set (ls_args, 0);
878 res_map_index[0] = mi;
887 vnet_lisp_add_del_locator_set (ls_args, &ls_index);
890 gid_address_copy (&m_args->eid, eid);
892 m_args->action = action;
893 m_args->locator_set_index = ls_index;
894 m_args->is_static = is_static;
895 vnet_lisp_map_cache_add_del (m_args, &dst_map_index);
898 res_map_index[0] = dst_map_index;
903 if (old_map == 0 || gid_address_cmp (&old_map->eid, eid) != 0)
905 clib_warning ("cannot delete mapping for eid %U",
906 format_gid_address, eid);
911 gid_address_copy (&m_args->eid, eid);
912 m_args->locator_set_index = old_map->locator_set_index;
914 /* delete mapping associated from map-cache */
915 vnet_lisp_map_cache_add_del (m_args, 0);
918 ls_args->index = old_map->locator_set_index;
919 /* delete locator set */
920 vnet_lisp_add_del_locator_set (ls_args, 0);
922 /* return old mapping index */
924 res_map_index[0] = mi;
932 vnet_lisp_clear_all_remote_adjacencies (void)
935 u32 mi, *map_indices = 0, *map_indexp;
936 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
937 vnet_lisp_add_del_mapping_args_t _dm_args, *dm_args = &_dm_args;
938 vnet_lisp_add_del_locator_set_args_t _ls, *ls = &_ls;
941 pool_foreach_index (mi, lcm->mapping_pool,
943 vec_add1 (map_indices, mi);
947 vec_foreach (map_indexp, map_indices)
949 mapping_t *map = pool_elt_at_index (lcm->mapping_pool, map_indexp[0]);
952 dp_del_fwd_entry (lcm, 0, map_indexp[0]);
955 gid_address_copy (&dm_args->eid, &map->eid);
956 dm_args->locator_set_index = map->locator_set_index;
958 /* delete mapping associated to fwd entry */
959 vnet_lisp_map_cache_add_del (dm_args, 0);
963 ls->index = map->locator_set_index;
964 /* delete locator set */
965 rv = vnet_lisp_add_del_locator_set (ls, 0);
973 vec_free (map_indices);
978 * Adds adjacency or removes forwarding entry associated to remote mapping.
979 * Note that adjacencies are not stored, they only result in forwarding entries
983 lisp_add_del_adjacency (lisp_cp_main_t * lcm, gid_address_t * local_eid,
984 gid_address_t * remote_eid, u8 is_add)
986 u32 local_mi, remote_mi = ~0;
988 if (vnet_lisp_enable_disable_status () == 0)
990 clib_warning ("LISP is disabled!");
991 return VNET_API_ERROR_LISP_DISABLED;
994 remote_mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, remote_eid);
995 if (GID_LOOKUP_MISS == remote_mi)
997 clib_warning ("Remote eid %U not found. Cannot add adjacency!",
998 format_gid_address, remote_eid);
1005 /* TODO 1) check if src/dst 2) once we have src/dst working, use it in
1008 /* check if source eid has an associated mapping. If pitr mode is on,
1009 * just use the pitr's mapping */
1010 local_mi = lcm->lisp_pitr ? lcm->pitr_map_index :
1011 gid_dictionary_lookup (&lcm->mapping_index_by_gid, local_eid);
1014 if (GID_LOOKUP_MISS == local_mi)
1016 clib_warning ("Local eid %U not found. Cannot add adjacency!",
1017 format_gid_address, local_eid);
1022 /* update forwarding */
1023 dp_add_fwd_entry (lcm, local_mi, remote_mi);
1026 dp_del_fwd_entry (lcm, 0, remote_mi);
1032 vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a)
1034 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1035 return lisp_add_del_adjacency (lcm, &a->leid, &a->reid, a->is_add);
1039 * Handler for add/del remote mapping CLI.
1041 * @param vm vlib context
1042 * @param input input from user
1044 * @return pointer to clib error structure
1046 static clib_error_t *
1047 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
1048 unformat_input_t * input,
1049 vlib_cli_command_t * cmd)
1051 clib_error_t *error = 0;
1052 unformat_input_t _line_input, *line_input = &_line_input;
1053 u8 is_add = 1, del_all = 0;
1054 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
1057 u32 vni, action = ~0, p, w;
1060 /* Get a line of input. */
1061 if (!unformat_user (input, unformat_line_input, line_input))
1064 memset (&eid, 0, sizeof (eid));
1065 memset (&rloc, 0, sizeof (rloc));
1067 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1069 if (unformat (line_input, "del-all"))
1071 else if (unformat (line_input, "del"))
1073 else if (unformat (line_input, "add"))
1075 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
1077 else if (unformat (line_input, "vni %u", &vni))
1079 gid_address_vni (&eid) = vni;
1081 else if (unformat (line_input, "p %d w %d", &p, &w))
1086 ("No RLOC configured for setting priority/weight!");
1089 curr_rloc->priority = p;
1090 curr_rloc->weight = w;
1092 else if (unformat (line_input, "rloc %U", unformat_ip_address,
1093 &gid_address_ip (&rloc.address)))
1095 /* since rloc is stored in ip prefix we need to set prefix length */
1096 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
1098 u8 version = gid_address_ip_version (&rloc.address);
1099 ip_prefix_len (pref) = ip_address_max_len (version);
1101 vec_add1 (rlocs, rloc);
1102 curr_rloc = &rlocs[vec_len (rlocs) - 1];
1104 else if (unformat (line_input, "action %U",
1105 unformat_negative_mapping_action, &action))
1109 clib_warning ("parse error");
1116 clib_warning ("missing eid!");
1122 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
1124 clib_warning ("no action set for negative map-reply!");
1130 vnet_lisp_clear_all_remote_adjacencies ();
1134 /* TODO build src/dst with seid */
1136 /* if it's a delete, clean forwarding */
1139 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1140 rv = lisp_add_del_adjacency (lcm, 0, &eid, /* is_add */ 0);
1147 /* add as static remote mapping, i.e., not authoritative and infinite
1149 rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add,
1150 1 /* is_static */ , 0);
1153 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
1157 unformat_free (line_input);
1161 VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) =
1163 .path = "lisp remote-mapping",.short_help =
1164 "lisp remote-mapping add|del [del-all] vni <vni> "
1165 "eid <est-eid> [action <no-action|natively-forward|"
1166 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
1167 "[rloc <dst-locator> ... ]",.function =
1168 lisp_add_del_remote_mapping_command_fn,};
1171 * Handler for add/del adjacency CLI.
1173 static clib_error_t *
1174 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
1175 vlib_cli_command_t * cmd)
1177 clib_error_t *error = 0;
1178 unformat_input_t _line_input, *line_input = &_line_input;
1179 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
1181 ip_prefix_t *reid_ippref, *leid_ippref;
1182 gid_address_t leid, reid;
1183 u8 *dmac = gid_address_mac (&reid);
1184 u8 *smac = gid_address_mac (&leid);
1185 u8 reid_set = 0, leid_set = 0;
1189 /* Get a line of input. */
1190 if (!unformat_user (input, unformat_line_input, line_input))
1193 memset (&reid, 0, sizeof (reid));
1194 memset (&leid, 0, sizeof (leid));
1196 leid_ippref = &gid_address_ippref (&leid);
1197 reid_ippref = &gid_address_ippref (&reid);
1199 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1201 if (unformat (line_input, "del"))
1203 else if (unformat (line_input, "add"))
1205 else if (unformat (line_input, "reid %U",
1206 unformat_ip_prefix, reid_ippref))
1208 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
1211 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
1213 gid_address_type (&reid) = GID_ADDR_MAC;
1216 else if (unformat (line_input, "vni %u", &vni))
1218 gid_address_vni (&leid) = vni;
1219 gid_address_vni (&reid) = vni;
1221 else if (unformat (line_input, "leid %U",
1222 unformat_ip_prefix, leid_ippref))
1224 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
1227 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
1229 gid_address_type (&leid) = GID_ADDR_MAC;
1234 clib_warning ("parse error");
1239 if (!reid_set || !leid_set)
1241 clib_warning ("missing remote or local eid!");
1245 if ((gid_address_type (&leid) != gid_address_type (&reid))
1246 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
1247 && ip_prefix_version (reid_ippref)
1248 != ip_prefix_version (leid_ippref)))
1250 clib_warning ("remote and local EIDs are of different types!");
1254 memset (a, 0, sizeof (a[0]));
1255 gid_address_copy (&a->leid, &leid);
1256 gid_address_copy (&a->reid, &reid);
1259 rv = vnet_lisp_add_del_adjacency (a);
1262 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
1265 unformat_free (line_input);
1270 VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = {
1271 .path = "lisp adjacency",
1272 .short_help = "lisp adjacency add|del vni <vni> reid <remote-eid> "
1274 .function = lisp_add_del_adjacency_command_fn,
1279 vnet_lisp_set_map_request_mode (u8 mode)
1281 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1283 if (vnet_lisp_enable_disable_status () == 0)
1285 clib_warning ("LISP is disabled!");
1286 return VNET_API_ERROR_LISP_DISABLED;
1289 if (mode >= _MR_MODE_MAX)
1291 clib_warning ("Invalid LISP map request mode %d!", mode);
1292 return VNET_API_ERROR_INVALID_ARGUMENT;
1295 lcm->map_request_mode = mode;
1299 static clib_error_t *
1300 lisp_map_request_mode_command_fn (vlib_main_t * vm,
1301 unformat_input_t * input,
1302 vlib_cli_command_t * cmd)
1304 unformat_input_t _i, *i = &_i;
1305 map_request_mode_t mr_mode = _MR_MODE_MAX;
1307 /* Get a line of input. */
1308 if (!unformat_user (input, unformat_line_input, i))
1311 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1313 if (unformat (i, "dst-only"))
1314 mr_mode = MR_MODE_DST_ONLY;
1315 else if (unformat (i, "src-dst"))
1316 mr_mode = MR_MODE_SRC_DST;
1319 clib_warning ("parse error '%U'", format_unformat_error, i);
1324 if (_MR_MODE_MAX == mr_mode)
1326 clib_warning ("No LISP map request mode entered!");
1330 vnet_lisp_set_map_request_mode (mr_mode);
1336 VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
1337 .path = "lisp map-request mode",
1338 .short_help = "lisp map-request mode dst-only|src-dst",
1339 .function = lisp_map_request_mode_command_fn,
1344 format_lisp_map_request_mode (u8 * s, va_list * args)
1346 u32 mode = va_arg (*args, u32);
1351 return format (0, "dst-only");
1353 return format (0, "src-dst");
1358 static clib_error_t *
1359 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
1360 unformat_input_t * input,
1361 vlib_cli_command_t * cmd)
1363 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
1364 vnet_lisp_get_map_request_mode ());
1369 VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
1370 .path = "show lisp map-request mode",
1371 .short_help = "show lisp map-request mode",
1372 .function = lisp_show_map_request_mode_command_fn,
1376 static clib_error_t *
1377 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
1378 unformat_input_t * input,
1379 vlib_cli_command_t * cmd)
1382 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1384 vec_foreach (mr, lcm->map_resolvers)
1386 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
1392 VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
1393 .path = "show lisp map-resolvers",
1394 .short_help = "show lisp map-resolvers",
1395 .function = lisp_show_map_resolvers_command_fn,
1400 vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add)
1402 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1403 u32 locator_set_index = ~0;
1407 if (vnet_lisp_enable_disable_status () == 0)
1409 clib_warning ("LISP is disabled!");
1410 return VNET_API_ERROR_LISP_DISABLED;
1413 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
1416 clib_warning ("locator-set %v doesn't exist", locator_set_name);
1419 locator_set_index = p[0];
1423 pool_get (lcm->mapping_pool, m);
1424 m->locator_set_index = locator_set_index;
1426 lcm->pitr_map_index = m - lcm->mapping_pool;
1428 /* enable pitr mode */
1433 /* remove pitr mapping */
1434 pool_put_index (lcm->mapping_pool, lcm->pitr_map_index);
1436 /* disable pitr mode */
1442 static clib_error_t *
1443 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
1444 unformat_input_t * input,
1445 vlib_cli_command_t * cmd)
1447 u8 locator_name_set = 0;
1448 u8 *locator_set_name = 0;
1450 unformat_input_t _line_input, *line_input = &_line_input;
1451 clib_error_t *error = 0;
1454 /* Get a line of input. */
1455 if (!unformat_user (input, unformat_line_input, line_input))
1458 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1460 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
1461 locator_name_set = 1;
1462 else if (unformat (line_input, "disable"))
1465 return clib_error_return (0, "parse error");
1468 if (!locator_name_set)
1470 clib_warning ("No locator set specified!");
1473 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
1476 error = clib_error_return (0, "failed to %s pitr!",
1477 is_add ? "add" : "delete");
1481 if (locator_set_name)
1482 vec_free (locator_set_name);
1487 VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
1488 .path = "lisp pitr",
1489 .short_help = "lisp pitr [disable] ls <locator-set-name>",
1490 .function = lisp_pitr_set_locator_set_command_fn,
1494 static clib_error_t *
1495 lisp_show_pitr_command_fn (vlib_main_t * vm,
1496 unformat_input_t * input, vlib_cli_command_t * cmd)
1498 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1503 vlib_cli_output (vm, "%=20s%=16s",
1504 "pitr", lcm->lisp_pitr ? "locator-set" : "");
1506 if (!lcm->lisp_pitr)
1508 vlib_cli_output (vm, "%=20s", "disable");
1512 if (~0 == lcm->pitr_map_index)
1514 tmp_str = format (0, "N/A");
1518 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1519 if (~0 != m->locator_set_index)
1522 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1523 tmp_str = format (0, "%s", ls->name);
1527 tmp_str = format (0, "N/A");
1530 vec_add1 (tmp_str, 0);
1532 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1540 VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
1541 .path = "show lisp pitr",
1542 .short_help = "Show pitr",
1543 .function = lisp_show_pitr_command_fn,
1548 format_eid_entry (u8 * s, va_list * args)
1550 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
1551 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
1552 mapping_t *mapit = va_arg (*args, mapping_t *);
1553 locator_set_t *ls = va_arg (*args, locator_set_t *);
1554 gid_address_t *gid = &mapit->eid;
1555 u32 ttl = mapit->ttl;
1556 u8 aut = mapit->authoritative;
1561 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
1562 : format (0, "remote");
1564 if (vec_len (ls->locator_indices) == 0)
1566 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
1571 vec_foreach (loc_index, ls->locator_indices)
1573 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
1575 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
1578 loc = format (0, "%U", format_ip_address,
1579 &gid_address_ip (&l->address));
1583 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
1584 gid, type, loc, ttl, aut);
1588 s = format (s, "%55s%v\n", "", loc);
1594 static clib_error_t *
1595 lisp_show_eid_table_command_fn (vlib_main_t * vm,
1596 unformat_input_t * input,
1597 vlib_cli_command_t * cmd)
1599 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1601 unformat_input_t _line_input, *line_input = &_line_input;
1607 memset (&eid, 0, sizeof (eid));
1609 /* Get a line of input. */
1610 if (!unformat_user (input, unformat_line_input, line_input))
1613 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1615 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
1617 else if (unformat (line_input, "local"))
1619 else if (unformat (line_input, "remote"))
1622 return clib_error_return (0, "parse error: '%U'",
1623 format_unformat_error, line_input);
1626 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
1627 "EID", "type", "locators", "ttl", "autoritative");
1632 pool_foreach (mapit, lcm->mapping_pool,
1634 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
1635 mapit->locator_set_index);
1636 if (filter && !((1 == filter && ls->local) ||
1637 (2 == filter && !ls->local)))
1641 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
1648 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
1649 if ((u32) ~ 0 == mi)
1652 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
1653 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
1654 mapit->locator_set_index);
1656 if (filter && !((1 == filter && ls->local) ||
1657 (2 == filter && !ls->local)))
1662 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
1670 VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = {
1671 .path = "show lisp eid-table",
1672 .short_help = "Shows EID table",
1673 .function = lisp_show_eid_table_command_fn,
1677 /* cleans locator to locator-set data and removes locators not part of
1678 * any locator-set */
1680 clean_locator_to_locator_set (lisp_cp_main_t * lcm, u32 lsi)
1682 u32 i, j, *loc_indexp, *ls_indexp, **ls_indexes, *to_be_deleted = 0;
1683 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, lsi);
1684 for (i = 0; i < vec_len (ls->locator_indices); i++)
1686 loc_indexp = vec_elt_at_index (ls->locator_indices, i);
1687 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets,
1689 for (j = 0; j < vec_len (ls_indexes[0]); j++)
1691 ls_indexp = vec_elt_at_index (ls_indexes[0], j);
1692 if (ls_indexp[0] == lsi)
1696 /* delete index for removed locator-set */
1697 vec_del1 (ls_indexes[0], j);
1699 /* delete locator if it's part of no locator-set */
1700 if (vec_len (ls_indexes[0]) == 0)
1702 pool_put_index (lcm->locator_pool, loc_indexp[0]);
1703 vec_add1 (to_be_deleted, i);
1709 for (i = 0; i < vec_len (to_be_deleted); i++)
1711 loc_indexp = vec_elt_at_index (to_be_deleted, i);
1712 vec_del1 (ls->locator_indices, loc_indexp[0]);
1714 vec_free (to_be_deleted);
1718 static inline uword *
1719 get_locator_set_index (vnet_lisp_add_del_locator_set_args_t * a, uword * p)
1721 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1726 /* find locator-set */
1729 p = hash_get_mem (lcm->locator_set_index_by_name, a->name);
1740 is_locator_in_locator_set (lisp_cp_main_t * lcm, locator_set_t * ls,
1746 ASSERT (ls != NULL);
1747 ASSERT (loc != NULL);
1749 vec_foreach (locit, ls->locator_indices)
1751 itloc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1752 if ((ls->local && itloc->sw_if_index == loc->sw_if_index) ||
1753 (!ls->local && !gid_address_cmp (&itloc->address, &loc->address)))
1755 clib_warning ("Duplicate locator");
1756 return VNET_API_ERROR_VALUE_EXIST;
1764 remove_locator_from_locator_set (locator_set_t * ls, u32 * locit,
1765 u32 ls_index, u32 loc_id)
1767 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1768 u32 **ls_indexes = NULL;
1770 ASSERT (ls != NULL);
1771 ASSERT (locit != NULL);
1773 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, locit[0]);
1774 pool_put_index (lcm->locator_pool, locit[0]);
1775 vec_del1 (ls->locator_indices, loc_id);
1776 vec_del1 (ls_indexes[0], ls_index);
1780 vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a,
1781 locator_set_t * ls, u32 * ls_result)
1783 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1784 locator_t *loc = NULL, *itloc = NULL;
1785 uword _p = (u32) ~ 0, *p = &_p;
1786 u32 loc_index = ~0, ls_index = ~0, *locit = NULL, **ls_indexes = NULL;
1792 if (vnet_lisp_enable_disable_status () == 0)
1794 clib_warning ("LISP is disabled!");
1795 return VNET_API_ERROR_LISP_DISABLED;
1798 p = get_locator_set_index (a, p);
1801 clib_warning ("locator-set %v doesn't exist", a->name);
1802 return VNET_API_ERROR_INVALID_ARGUMENT;
1807 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1810 clib_warning ("locator-set %d to be overwritten doesn't exist!",
1812 return VNET_API_ERROR_INVALID_ARGUMENT;
1819 ls_result[0] = p[0];
1821 /* allocate locators */
1822 vec_foreach (itloc, a->locators)
1824 ret = is_locator_in_locator_set (lcm, ls, itloc);
1830 pool_get (lcm->locator_pool, loc);
1832 loc_index = loc - lcm->locator_pool;
1834 vec_add1 (ls->locator_indices, loc_index);
1836 vec_validate (lcm->locator_to_locator_sets, loc_index);
1837 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets,
1839 vec_add1 (ls_indexes[0], p[0]);
1846 itloc = a->locators;
1848 vec_foreach (locit, ls->locator_indices)
1850 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1852 if (loc->local && loc->sw_if_index == itloc->sw_if_index)
1854 remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
1856 if (0 == loc->local &&
1857 !gid_address_cmp (&loc->address, &itloc->address))
1859 remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
1870 vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a,
1873 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1875 uword _p = (u32) ~ 0, *p = &_p;
1880 if (vnet_lisp_enable_disable_status () == 0)
1882 clib_warning ("LISP is disabled!");
1883 return VNET_API_ERROR_LISP_DISABLED;
1888 p = get_locator_set_index (a, p);
1891 if (p && p[0] != (u32) ~ 0)
1893 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1896 clib_warning ("locator-set %d to be overwritten doesn't exist!",
1901 /* clean locator to locator-set vectors and remove locators if
1902 * they're not part of another locator-set */
1903 clean_locator_to_locator_set (lcm, p[0]);
1905 /* remove locator indices from locator set */
1906 vec_free (ls->locator_indices);
1911 ls_result[0] = p[0];
1913 /* new locator-set */
1916 pool_get (lcm->locator_set_pool, ls);
1917 memset (ls, 0, sizeof (*ls));
1918 ls_index = ls - lcm->locator_set_pool;
1922 ls->name = vec_dup (a->name);
1924 if (!lcm->locator_set_index_by_name)
1925 lcm->locator_set_index_by_name = hash_create_vec (
1933 hash_set_mem (lcm->locator_set_index_by_name, ls->name,
1936 /* mark as local locator-set */
1937 vec_add1 (lcm->local_locator_set_indexes, ls_index);
1939 ls->local = a->local;
1941 ls_result[0] = ls_index;
1944 ret = vnet_lisp_add_del_locator (a, ls, NULL);
1952 p = get_locator_set_index (a, p);
1955 clib_warning ("locator-set %v doesn't exists", a->name);
1959 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1962 clib_warning ("locator-set with index %d doesn't exists", p[0]);
1966 if (lcm->mreq_itr_rlocs == p[0])
1968 clib_warning ("Can't delete the locator-set used to constrain "
1969 "the itr-rlocs in map-requests!");
1973 if (vec_len (lcm->locator_set_to_eids) != 0)
1975 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, p[0]);
1976 if (vec_len (eid_indexes[0]) != 0)
1979 ("Can't delete a locator that supports a mapping!");
1984 /* clean locator to locator-sets data */
1985 clean_locator_to_locator_set (lcm, p[0]);
1991 vec_foreach_index (it, lcm->local_locator_set_indexes)
1993 lsi = vec_elt (lcm->local_locator_set_indexes, it);
1996 vec_del1 (lcm->local_locator_set_indexes, it);
2000 hash_unset_mem (lcm->locator_set_index_by_name, ls->name);
2002 vec_free (ls->name);
2003 vec_free (ls->locator_indices);
2004 pool_put (lcm->locator_set_pool, ls);
2010 vnet_lisp_enable_disable (u8 is_enable)
2013 clib_error_t *error = 0;
2014 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2015 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
2017 a->is_en = is_enable;
2018 error = vnet_lisp_gpe_enable_disable (a);
2021 return clib_error_return (0, "failed to %s data-plane!",
2022 a->is_en ? "enable" : "disable");
2027 /* enable all l2 and l3 ifaces */
2030 hash_foreach(vni, dp_table, lcm->table_id_by_vni, ({
2031 dp_add_del_iface(lcm, vni, 0, 1);
2033 hash_foreach(vni, dp_table, lcm->bd_id_by_vni, ({
2034 dp_add_del_iface(lcm, vni, /* is_l2 */ 1, 1);
2040 /* clear interface table */
2041 hash_free (lcm->dp_intf_by_vni);
2042 hash_free (lcm->fwd_entry_by_mapping_index);
2043 pool_free (lcm->fwd_entry_pool);
2046 /* update global flag */
2047 lcm->is_enabled = is_enable;
2052 static clib_error_t *
2053 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
2054 vlib_cli_command_t * cmd)
2056 unformat_input_t _line_input, *line_input = &_line_input;
2060 /* Get a line of input. */
2061 if (!unformat_user (input, unformat_line_input, line_input))
2064 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2066 if (unformat (line_input, "enable"))
2071 else if (unformat (line_input, "disable"))
2075 return clib_error_return (0, "parse error: '%U'",
2076 format_unformat_error, line_input);
2081 return clib_error_return (0, "state not set");
2083 return vnet_lisp_enable_disable (is_enabled);
2087 VLIB_CLI_COMMAND (lisp_cp_enable_disable_command) = {
2089 .short_help = "lisp [enable|disable]",
2090 .function = lisp_enable_disable_command_fn,
2095 vnet_lisp_enable_disable_status (void)
2097 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2098 return lcm->is_enabled;
2102 format_lisp_status (u8 * s, va_list * args)
2104 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2105 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
2108 static clib_error_t *
2109 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
2110 vlib_cli_command_t * cmd)
2113 msg = format (msg, "feature: %U\ngpe: %U\n",
2114 format_lisp_status, format_vnet_lisp_gpe_status);
2115 vlib_cli_output (vm, "%v", msg);
2121 VLIB_CLI_COMMAND (lisp_show_status_command) = {
2122 .path = "show lisp status",
2123 .short_help = "show lisp status",
2124 .function = lisp_show_status_command_fn,
2128 static clib_error_t *
2129 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
2130 unformat_input_t * input,
2131 vlib_cli_command_t * cmd)
2134 unformat_input_t _line_input, *line_input = &_line_input;
2135 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2136 uword *vni_table = 0;
2139 /* Get a line of input. */
2140 if (!unformat_user (input, unformat_line_input, line_input))
2143 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2145 if (unformat (line_input, "l2"))
2147 vni_table = lcm->bd_id_by_vni;
2150 else if (unformat (line_input, "l3"))
2152 vni_table = lcm->table_id_by_vni;
2156 return clib_error_return (0, "parse error: '%U'",
2157 format_unformat_error, line_input);
2162 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
2166 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
2169 hash_foreach_pair (p, vni_table,
2171 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
2179 VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
2180 .path = "show lisp eid-table map",
2181 .short_help = "show lisp eid-table l2|l3",
2182 .function = lisp_show_eid_table_map_command_fn,
2186 static clib_error_t *
2187 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
2188 unformat_input_t * input,
2189 vlib_cli_command_t * cmd)
2191 lisp_gpe_main_t *lgm = &lisp_gpe_main;
2192 vnet_main_t *vnm = lgm->vnet_main;
2193 unformat_input_t _line_input, *line_input = &_line_input;
2195 clib_error_t *error = 0;
2196 u8 *locator_set_name = 0;
2197 locator_t locator, *locators = 0;
2198 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
2202 memset (&locator, 0, sizeof (locator));
2203 memset (a, 0, sizeof (a[0]));
2205 /* Get a line of input. */
2206 if (!unformat_user (input, unformat_line_input, line_input))
2209 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2211 if (unformat (line_input, "add %_%v%_", &locator_set_name))
2213 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
2215 else if (unformat (line_input, "iface %U p %d w %d",
2216 unformat_vnet_sw_interface, vnm,
2217 &locator.sw_if_index, &locator.priority,
2221 vec_add1 (locators, locator);
2225 error = unformat_parse_error (line_input);
2230 a->name = locator_set_name;
2231 a->locators = locators;
2235 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
2238 error = clib_error_return (0, "failed to %s locator-set!",
2239 is_add ? "add" : "delete");
2243 vec_free (locators);
2244 if (locator_set_name)
2245 vec_free (locator_set_name);
2250 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
2251 .path = "lisp locator-set",
2252 .short_help = "lisp locator-set add/del <name> [iface <iface-name> "
2253 "p <priority> w <weight>]",
2254 .function = lisp_add_del_locator_set_command_fn,
2258 static clib_error_t *
2259 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
2260 unformat_input_t * input,
2261 vlib_cli_command_t * cmd)
2263 lisp_gpe_main_t *lgm = &lisp_gpe_main;
2264 vnet_main_t *vnm = lgm->vnet_main;
2265 unformat_input_t _line_input, *line_input = &_line_input;
2267 clib_error_t *error = 0;
2268 u8 *locator_set_name = 0;
2269 u8 locator_set_name_set = 0;
2270 locator_t locator, *locators = 0;
2271 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
2274 memset (&locator, 0, sizeof (locator));
2275 memset (a, 0, sizeof (a[0]));
2277 /* Get a line of input. */
2278 if (!unformat_user (input, unformat_line_input, line_input))
2281 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2283 if (unformat (line_input, "add"))
2285 else if (unformat (line_input, "del"))
2287 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
2288 locator_set_name_set = 1;
2289 else if (unformat (line_input, "iface %U p %d w %d",
2290 unformat_vnet_sw_interface, vnm,
2291 &locator.sw_if_index, &locator.priority,
2295 vec_add1 (locators, locator);
2299 error = unformat_parse_error (line_input);
2304 if (!locator_set_name_set)
2306 error = clib_error_return (0, "locator_set name not set!");
2310 a->name = locator_set_name;
2311 a->locators = locators;
2315 vnet_lisp_add_del_locator (a, 0, &ls_index);
2318 vec_free (locators);
2319 vec_free (locator_set_name);
2324 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = {
2325 .path = "lisp locator",
2326 .short_help = "lisp locator add/del locator-set <name> iface <iface-name> "
2327 "p <priority> w <weight>",
2328 .function = lisp_add_del_locator_in_set_command_fn,
2332 static clib_error_t *
2333 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
2334 unformat_input_t * input,
2335 vlib_cli_command_t * cmd)
2337 locator_set_t *lsit;
2340 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2342 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
2343 "Priority", "Weight");
2346 pool_foreach (lsit, lcm->locator_set_pool,
2352 msg = format (msg, "%v", lsit->name);
2356 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
2358 vec_foreach (locit, lsit->locator_indices)
2362 msg = format (msg, "%16s", " ");
2364 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
2366 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
2369 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
2370 &gid_address_ip(&loc->address), loc->priority,
2374 vlib_cli_output (vm, "%v", msg);
2382 VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
2383 .path = "show lisp locator-set",
2384 .short_help = "Shows locator-sets",
2385 .function = lisp_cp_show_locator_sets_command_fn,
2389 static map_resolver_t *
2390 get_map_resolver (ip_address_t * a)
2392 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2395 vec_foreach (mr, lcm->map_resolvers)
2397 if (!ip_address_cmp (&mr->address, a))
2406 vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a)
2408 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2410 map_resolver_t _mr, *mr = &_mr;
2412 if (vnet_lisp_enable_disable_status () == 0)
2414 clib_warning ("LISP is disabled!");
2415 return VNET_API_ERROR_LISP_DISABLED;
2421 if (get_map_resolver (&a->address))
2423 clib_warning ("map-resolver %U already exists!", format_ip_address,
2428 memset (mr, 0, sizeof (*mr));
2429 ip_address_copy (&mr->address, &a->address);
2430 vec_add1 (lcm->map_resolvers, *mr);
2432 if (vec_len (lcm->map_resolvers) == 1)
2433 lcm->do_map_resolver_election = 1;
2437 for (i = 0; i < vec_len (lcm->map_resolvers); i++)
2439 mr = vec_elt_at_index (lcm->map_resolvers, i);
2440 if (!ip_address_cmp (&mr->address, &a->address))
2442 if (!ip_address_cmp (&mr->address, &lcm->active_map_resolver))
2443 lcm->do_map_resolver_election = 1;
2445 vec_del1 (lcm->map_resolvers, i);
2453 static clib_error_t *
2454 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
2455 unformat_input_t * input,
2456 vlib_cli_command_t * cmd)
2458 unformat_input_t _line_input, *line_input = &_line_input;
2459 u8 is_add = 1, addr_set = 0;
2460 ip_address_t ip_addr;
2461 clib_error_t *error = 0;
2463 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
2465 /* Get a line of input. */
2466 if (!unformat_user (input, unformat_line_input, line_input))
2469 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2471 if (unformat (line_input, "add"))
2473 else if (unformat (line_input, "del"))
2475 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
2479 error = unformat_parse_error (line_input);
2486 error = clib_error_return (0, "Map-resolver address must be set!");
2491 a->address = ip_addr;
2492 rv = vnet_lisp_add_del_map_resolver (a);
2495 error = clib_error_return (0, "failed to %s map-resolver!",
2496 is_add ? "add" : "delete");
2504 VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
2505 .path = "lisp map-resolver",
2506 .short_help = "lisp map-resolver add/del <ip_address>",
2507 .function = lisp_add_del_map_resolver_command_fn,
2512 vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a)
2514 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2517 if (vnet_lisp_enable_disable_status () == 0)
2519 clib_warning ("LISP is disabled!");
2520 return VNET_API_ERROR_LISP_DISABLED;
2525 p = hash_get_mem (lcm->locator_set_index_by_name, a->locator_set_name);
2528 clib_warning ("locator-set %v doesn't exist", a->locator_set_name);
2529 return VNET_API_ERROR_INVALID_ARGUMENT;
2532 lcm->mreq_itr_rlocs = p[0];
2536 lcm->mreq_itr_rlocs = ~0;
2542 static clib_error_t *
2543 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
2544 unformat_input_t * input,
2545 vlib_cli_command_t * cmd)
2547 unformat_input_t _line_input, *line_input = &_line_input;
2549 u8 *locator_set_name = 0;
2550 clib_error_t *error = 0;
2552 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
2554 /* Get a line of input. */
2555 if (!unformat_user (input, unformat_line_input, line_input))
2558 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2560 if (unformat (line_input, "del"))
2562 else if (unformat (line_input, "add %s", &locator_set_name))
2566 error = unformat_parse_error (line_input);
2572 a->locator_set_name = locator_set_name;
2573 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
2576 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
2577 is_add ? "add" : "delete");
2580 vec_free (locator_set_name);
2588 VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = {
2589 .path = "lisp map-request itr-rlocs",
2590 .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>",
2591 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
2595 static clib_error_t *
2596 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
2597 unformat_input_t * input,
2598 vlib_cli_command_t * cmd)
2600 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2601 locator_set_t *loc_set;
2603 vlib_cli_output (vm, "%=20s", "itr-rlocs");
2605 if (~0 == lcm->mreq_itr_rlocs)
2610 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
2612 vlib_cli_output (vm, "%=20s", loc_set->name);
2618 VLIB_CLI_COMMAND (lisp_show_map_request_command) = {
2619 .path = "show lisp map-request itr-rlocs",
2620 .short_help = "Shows map-request itr-rlocs",
2621 .function = lisp_show_mreq_itr_rlocs_command_fn,
2625 /* Statistics (not really errors) */
2626 #define foreach_lisp_cp_lookup_error \
2628 _(MAP_REQUESTS_SENT, "map-request sent")
2630 static char *lisp_cp_lookup_error_strings[] = {
2631 #define _(sym,string) string,
2632 foreach_lisp_cp_lookup_error
2638 #define _(sym,str) LISP_CP_LOOKUP_ERROR_##sym,
2639 foreach_lisp_cp_lookup_error
2641 LISP_CP_LOOKUP_N_ERROR,
2642 } lisp_cp_lookup_error_t;
2646 LISP_CP_LOOKUP_NEXT_DROP,
2647 LISP_CP_LOOKUP_NEXT_IP4_LOOKUP,
2648 LISP_CP_LOOKUP_NEXT_IP6_LOOKUP,
2649 LISP_CP_LOOKUP_N_NEXT,
2650 } lisp_cp_lookup_next_t;
2654 gid_address_t dst_eid;
2655 ip_address_t map_resolver_ip;
2656 } lisp_cp_lookup_trace_t;
2659 format_lisp_cp_lookup_trace (u8 * s, va_list * args)
2661 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2662 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
2663 lisp_cp_lookup_trace_t *t = va_arg (*args, lisp_cp_lookup_trace_t *);
2665 s = format (s, "LISP-CP-LOOKUP: map-resolver: %U destination eid %U",
2666 format_ip_address, &t->map_resolver_ip, format_gid_address,
2672 get_mr_and_local_iface_ip (lisp_cp_main_t * lcm, ip_address_t * mr_ip,
2673 ip_address_t * sloc)
2675 map_resolver_t *mrit;
2678 if (vec_len (lcm->map_resolvers) == 0)
2680 clib_warning ("No map-resolver configured");
2684 /* find the first mr ip we have a route to and the ip of the
2685 * iface that has a route to it */
2686 vec_foreach (mrit, lcm->map_resolvers)
2689 if (0 != ip_fib_get_first_egress_ip_for_dst (lcm, a, sloc))
2691 ip_address_copy (mr_ip, a);
2693 /* also update globals */
2698 clib_warning ("Can't find map-resolver and local interface ip!");
2702 static gid_address_t *
2703 build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set)
2709 ip_interface_address_t *ia = 0;
2710 gid_address_t gid_data, *gid = &gid_data;
2711 gid_address_t *rlocs = 0;
2712 ip_prefix_t *ippref = &gid_address_ippref (gid);
2713 ip_address_t *rloc = &ip_prefix_addr (ippref);
2715 memset (gid, 0, sizeof (gid[0]));
2716 gid_address_type (gid) = GID_ADDR_IP_PREFIX;
2717 for (i = 0; i < vec_len (loc_set->locator_indices); i++)
2719 loc_indexp = vec_elt_at_index (loc_set->locator_indices, i);
2720 loc = pool_elt_at_index (lcm->locator_pool, loc_indexp[0]);
2722 /* Add ipv4 locators first TODO sort them */
2725 foreach_ip_interface_address (&lcm->im4->lookup_main, ia,
2726 loc->sw_if_index, 1 /* unnumbered */,
2728 addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia);
2729 ip_address_set (rloc, addr, IP4);
2730 ip_prefix_len (ippref) = 32;
2731 ip_prefix_normalize (ippref);
2732 vec_add1 (rlocs, gid[0]);
2735 /* Add ipv6 locators */
2736 foreach_ip_interface_address (&lcm->im6->lookup_main, ia,
2737 loc->sw_if_index, 1 /* unnumbered */,
2739 addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia);
2740 ip_address_set (rloc, addr, IP6);
2741 ip_prefix_len (ippref) = 128;
2742 ip_prefix_normalize (ippref);
2743 vec_add1 (rlocs, gid[0]);
2751 static vlib_buffer_t *
2752 build_encapsulated_map_request (lisp_cp_main_t * lcm,
2753 gid_address_t * seid, gid_address_t * deid,
2754 locator_set_t * loc_set, ip_address_t * mr_ip,
2755 ip_address_t * sloc, u8 is_smr_invoked,
2756 u64 * nonce_res, u32 * bi_res)
2760 gid_address_t *rlocs = 0;
2761 vlib_main_t *vm = lcm->vlib_main;
2763 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
2765 clib_warning ("Can't allocate buffer for Map-Request!");
2769 b = vlib_get_buffer (vm, bi);
2771 /* leave some space for the encap headers */
2772 vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN);
2775 rlocs = build_itr_rloc_list (lcm, loc_set);
2777 if (MR_MODE_SRC_DST == lcm->map_request_mode)
2780 memset (&sd, 0, sizeof (sd));
2781 build_src_dst (&sd, seid, deid);
2782 lisp_msg_put_mreq (lcm, b, seid, &sd, rlocs, is_smr_invoked, nonce_res);
2787 lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, is_smr_invoked,
2791 /* push ecm: udp-ip-lisp */
2792 lisp_msg_push_ecm (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, seid, deid);
2794 /* push outer ip header */
2795 pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc,
2805 reset_pending_mr_counters (pending_map_request_t * r)
2807 r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME;
2812 elect_map_resolver (lisp_cp_main_t * lcm)
2816 vec_foreach (mr, lcm->map_resolvers)
2820 ip_address_copy (&lcm->active_map_resolver, &mr->address);
2821 lcm->do_map_resolver_election = 0;
2828 #define send_encapsulated_map_request(lcm, seid, deid, smr) \
2829 _send_encapsulated_map_request(lcm, seid, deid, smr, 0)
2831 #define resend_encapsulated_map_request(lcm, seid, deid, smr) \
2832 _send_encapsulated_map_request(lcm, seid, deid, smr, 1)
2835 _send_encapsulated_map_request (lisp_cp_main_t * lcm,
2836 gid_address_t * seid, gid_address_t * deid,
2837 u8 is_smr_invoked, u8 is_resend)
2840 u32 next_index, bi = 0, *to_next, map_index;
2844 locator_set_t *loc_set;
2846 pending_map_request_t *pmr, *duplicate_pmr = 0;
2850 ASSERT (*lcm->pending_map_request_lock);
2852 /* if there is already a pending request remember it */
2855 pool_foreach(pmr, lcm->pending_map_requests_pool,
2857 if (!gid_address_cmp (&pmr->src, seid)
2858 && !gid_address_cmp (&pmr->dst, deid))
2860 duplicate_pmr = pmr;
2866 if (!is_resend && duplicate_pmr)
2868 /* don't send the request if there is a pending map request already */
2872 /* get locator-set for seid */
2873 if (!lcm->lisp_pitr)
2875 map_index = gid_dictionary_lookup (&lcm->mapping_index_by_gid, seid);
2876 if (map_index == ~0)
2878 clib_warning ("No local mapping found in eid-table for %U!",
2879 format_gid_address, seid);
2883 map = pool_elt_at_index (lcm->mapping_pool, map_index);
2888 ("Mapping found for src eid %U is not marked as local!",
2889 format_gid_address, seid);
2892 ls_index = map->locator_set_index;
2896 map_index = lcm->pitr_map_index;
2897 map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
2898 ls_index = map->locator_set_index;
2901 /* overwrite locator set if map-request itr-rlocs configured */
2902 if (~0 != lcm->mreq_itr_rlocs)
2904 ls_index = lcm->mreq_itr_rlocs;
2907 loc_set = pool_elt_at_index (lcm->locator_set_pool, ls_index);
2909 while (lcm->do_map_resolver_election
2910 | (0 == ip_fib_get_first_egress_ip_for_dst (lcm,
2911 &lcm->active_map_resolver,
2914 if (0 == elect_map_resolver (lcm))
2915 /* all Mrs are down */
2918 duplicate_pmr->to_be_removed = 1;
2920 /* restart MR checking by marking all of them up */
2921 vec_foreach (mr, lcm->map_resolvers) mr->is_down = 0;
2927 /* build the encapsulated map request */
2928 b = build_encapsulated_map_request (lcm, seid, deid, loc_set,
2929 &lcm->active_map_resolver,
2930 &sloc, is_smr_invoked, &nonce, &bi);
2935 /* set fib index to default and lookup node */
2936 vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
2937 next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ?
2938 ip4_lookup_node.index : ip6_lookup_node.index;
2940 f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
2942 /* Enqueue the packet */
2943 to_next = vlib_frame_vector_args (f);
2946 vlib_put_frame_to_node (lcm->vlib_main, next_index, f);
2949 /* if there is a pending request already update it */
2951 if (clib_fifo_elts (duplicate_pmr->nonces) >= PENDING_MREQ_QUEUE_LEN)
2953 /* remove the oldest nonce */
2954 u64 CLIB_UNUSED (tmp), *nonce_del;
2955 nonce_del = clib_fifo_head (duplicate_pmr->nonces);
2956 hash_unset (lcm->pending_map_requests_by_nonce, nonce_del[0]);
2957 clib_fifo_sub1 (duplicate_pmr->nonces, tmp);
2960 clib_fifo_add1 (duplicate_pmr->nonces, nonce);
2961 hash_set (lcm->pending_map_requests_by_nonce, nonce,
2962 duplicate_pmr - lcm->pending_map_requests_pool);
2966 /* add map-request to pending requests table */
2967 pool_get (lcm->pending_map_requests_pool, pmr);
2968 memset (pmr, 0, sizeof (*pmr));
2969 gid_address_copy (&pmr->src, seid);
2970 gid_address_copy (&pmr->dst, deid);
2971 clib_fifo_add1 (pmr->nonces, nonce);
2972 pmr->is_smr_invoked = is_smr_invoked;
2973 reset_pending_mr_counters (pmr);
2974 hash_set (lcm->pending_map_requests_by_nonce, nonce,
2975 pmr - lcm->pending_map_requests_pool);
2982 get_src_and_dst_ip (void *hdr, ip_address_t * src, ip_address_t * dst)
2984 ip4_header_t *ip4 = hdr;
2987 if ((ip4->ip_version_and_header_length & 0xF0) == 0x40)
2989 ip_address_set (src, &ip4->src_address, IP4);
2990 ip_address_set (dst, &ip4->dst_address, IP4);
2995 ip_address_set (src, &ip6->src_address, IP6);
2996 ip_address_set (dst, &ip6->dst_address, IP6);
3001 lisp_get_vni_from_buffer_ip (lisp_cp_main_t * lcm, vlib_buffer_t * b,
3005 u32 vni = ~0, table_id = ~0;
3007 table_id = fib_table_get_table_id_for_sw_if_index ((version ==
3008 IP4 ? FIB_PROTOCOL_IP4 :
3014 vnip = hash_get (lcm->vni_by_table_id, table_id);
3018 clib_warning ("vrf %d is not mapped to any vni!", table_id);
3024 lisp_get_vni_from_buffer_eth (lisp_cp_main_t * lcm, vlib_buffer_t * b)
3030 l2input_main_t *l2im = &l2input_main;
3031 l2_input_config_t *config;
3032 l2_bridge_domain_t *bd_config;
3034 sw_if_index0 = vnet_buffer (b)->sw_if_index[VLIB_RX];
3035 config = vec_elt_at_index (l2im->configs, sw_if_index0);
3036 bd_config = vec_elt_at_index (l2im->bd_configs, config->bd_index);
3038 vnip = hash_get (lcm->vni_by_bd_id, bd_config->bd_id);
3042 clib_warning ("bridge domain %d is not mapped to any vni!",
3049 get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b,
3050 gid_address_t * src, gid_address_t * dst)
3055 memset (src, 0, sizeof (*src));
3056 memset (dst, 0, sizeof (*dst));
3057 type = vnet_buffer (b)->lisp.overlay_afi;
3059 if (LISP_AFI_IP == type || LISP_AFI_IP6 == type)
3062 u8 version, preflen;
3064 gid_address_type (src) = GID_ADDR_IP_PREFIX;
3065 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3067 ip = vlib_buffer_get_current (b);
3068 get_src_and_dst_ip (ip, &gid_address_ip (src), &gid_address_ip (dst));
3070 version = gid_address_ip_version (src);
3071 preflen = ip_address_max_len (version);
3072 gid_address_ippref_len (src) = preflen;
3073 gid_address_ippref_len (dst) = preflen;
3075 vni = lisp_get_vni_from_buffer_ip (lcm, b, version);
3076 gid_address_vni (dst) = vni;
3077 gid_address_vni (src) = vni;
3079 else if (LISP_AFI_MAC == type)
3081 ethernet_header_t *eh;
3083 eh = vlib_buffer_get_current (b);
3085 gid_address_type (src) = GID_ADDR_MAC;
3086 gid_address_type (dst) = GID_ADDR_MAC;
3087 mac_copy (&gid_address_mac (src), eh->src_address);
3088 mac_copy (&gid_address_mac (dst), eh->dst_address);
3091 vni = lisp_get_vni_from_buffer_eth (lcm, b);
3093 gid_address_vni (dst) = vni;
3094 gid_address_vni (src) = vni;
3099 lisp_cp_lookup_inline (vlib_main_t * vm,
3100 vlib_node_runtime_t * node,
3101 vlib_frame_t * from_frame, int overlay)
3103 u32 *from, *to_next_drop, di, si;
3104 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3105 u32 pkts_mapped = 0;
3106 uword n_left_from, n_left_to_next_drop;
3108 from = vlib_frame_vector_args (from_frame);
3109 n_left_from = from_frame->n_vectors;
3111 while (n_left_from > 0)
3113 vlib_get_next_frame (vm, node, LISP_CP_LOOKUP_NEXT_DROP,
3114 to_next_drop, n_left_to_next_drop);
3116 while (n_left_from > 0 && n_left_to_next_drop > 0)
3120 gid_address_t src, dst;
3125 to_next_drop[0] = pi0;
3127 n_left_to_next_drop -= 1;
3129 b0 = vlib_get_buffer (vm, pi0);
3130 b0->error = node->errors[LISP_CP_LOOKUP_ERROR_DROP];
3131 vnet_buffer (b0)->lisp.overlay_afi = overlay;
3133 /* src/dst eid pair */
3134 get_src_and_dst_eids_from_buffer (lcm, b0, &src, &dst);
3136 /* if we have remote mapping for destination already in map-chache
3137 add forwarding tunnel directly. If not send a map-request */
3138 di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst,
3142 mapping_t *m = vec_elt_at_index (lcm->mapping_pool, di);
3143 /* send a map-request also in case of negative mapping entry
3144 with corresponding action */
3145 if (m->action == LISP_SEND_MAP_REQUEST)
3147 /* send map-request */
3148 queue_map_request (&src, &dst, 0 /* smr_invoked */ ,
3149 0 /* is_resend */ );
3154 si = gid_dictionary_lookup (&lcm->mapping_index_by_gid,
3158 dp_add_fwd_entry (lcm, si, di);
3164 /* send map-request */
3165 queue_map_request (&src, &dst, 0 /* smr_invoked */ ,
3166 0 /* is_resend */ );
3170 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
3172 lisp_cp_lookup_trace_t *tr = vlib_add_trace (vm, node, b0,
3175 memset (tr, 0, sizeof (*tr));
3176 gid_address_copy (&tr->dst_eid, &dst);
3177 ip_address_copy (&tr->map_resolver_ip,
3178 &lcm->active_map_resolver);
3180 gid_address_free (&dst);
3181 gid_address_free (&src);
3184 vlib_put_next_frame (vm, node, LISP_CP_LOOKUP_NEXT_DROP,
3185 n_left_to_next_drop);
3187 vlib_node_increment_counter (vm, node->node_index,
3188 LISP_CP_LOOKUP_ERROR_MAP_REQUESTS_SENT,
3190 return from_frame->n_vectors;
3194 lisp_cp_lookup_ip4 (vlib_main_t * vm,
3195 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3197 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP));
3201 lisp_cp_lookup_ip6 (vlib_main_t * vm,
3202 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3204 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP6));
3208 VLIB_REGISTER_NODE (lisp_cp_lookup_ip4_node) = {
3209 .function = lisp_cp_lookup_ip4,
3210 .name = "lisp-cp-lookup-ip4",
3211 .vector_size = sizeof (u32),
3212 .format_trace = format_lisp_cp_lookup_trace,
3213 .type = VLIB_NODE_TYPE_INTERNAL,
3215 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3216 .error_strings = lisp_cp_lookup_error_strings,
3218 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3221 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3222 [LISP_CP_LOOKUP_NEXT_IP4_LOOKUP] = "ip4-lookup",
3223 [LISP_CP_LOOKUP_NEXT_IP6_LOOKUP] = "ip6-lookup",
3229 VLIB_REGISTER_NODE (lisp_cp_lookup_ip6_node) = {
3230 .function = lisp_cp_lookup_ip6,
3231 .name = "lisp-cp-lookup-ip6",
3232 .vector_size = sizeof (u32),
3233 .format_trace = format_lisp_cp_lookup_trace,
3234 .type = VLIB_NODE_TYPE_INTERNAL,
3236 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3237 .error_strings = lisp_cp_lookup_error_strings,
3239 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3242 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3243 [LISP_CP_LOOKUP_NEXT_IP4_LOOKUP] = "ip4-lookup",
3244 [LISP_CP_LOOKUP_NEXT_IP6_LOOKUP] = "ip6-lookup",
3249 /* lisp_cp_input statistics */
3250 #define foreach_lisp_cp_input_error \
3252 _(MAP_REPLIES_RECEIVED, "map-replies received")
3254 static char *lisp_cp_input_error_strings[] = {
3255 #define _(sym,string) string,
3256 foreach_lisp_cp_input_error
3262 #define _(sym,str) LISP_CP_INPUT_ERROR_##sym,
3263 foreach_lisp_cp_input_error
3265 LISP_CP_INPUT_N_ERROR,
3266 } lisp_cp_input_error_t;
3270 LISP_CP_INPUT_NEXT_DROP,
3271 LISP_CP_INPUT_N_NEXT,
3272 } lisp_cp_input_next_t;
3276 gid_address_t dst_eid;
3277 ip4_address_t map_resolver_ip;
3278 } lisp_cp_input_trace_t;
3281 format_lisp_cp_input_trace (u8 * s, va_list * args)
3283 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
3284 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
3285 CLIB_UNUSED (lisp_cp_input_trace_t * t) =
3286 va_arg (*args, lisp_cp_input_trace_t *);
3288 s = format (s, "LISP-CP-INPUT: TODO");
3293 process_map_reply (void *arg)
3295 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3296 vlib_buffer_t *b = arg;
3297 u32 len = 0, i, ttl, dst_map_index = 0;
3299 pending_map_request_t *pmr;
3301 map_reply_hdr_t *mrep_hdr;
3305 u8 authoritative, action;
3306 locator_t *locators = 0, *loc;
3308 mrep_hdr = vlib_buffer_get_current (b);
3310 lisp_pending_map_request_lock (lcm);
3312 /* Check pending requests table and nonce */
3313 nonce = MREP_NONCE (mrep_hdr);
3314 pmr_index = hash_get (lcm->pending_map_requests_by_nonce, nonce);
3317 clib_warning ("No pending map-request entry with nonce %lu!", nonce);
3320 pmr = pool_elt_at_index (lcm->pending_map_requests_pool, pmr_index[0]);
3322 vlib_buffer_pull (b, sizeof (*mrep_hdr));
3324 for (i = 0; i < MREP_REC_COUNT (mrep_hdr); i++)
3326 h = vlib_buffer_get_current (b);
3327 ttl = clib_net_to_host_u32 (MAP_REC_TTL (h));
3328 action = MAP_REC_ACTION (h);
3329 authoritative = MAP_REC_AUTH (h);
3331 len = lisp_msg_parse_mapping_record (b, &deid, &locators, &probed);
3334 clib_warning ("Failed to parse mapping record!");
3335 vec_foreach (loc, locators)
3339 vec_free (locators);
3343 /* insert/update mappings cache */
3344 vnet_lisp_add_del_mapping (&deid, locators, action, authoritative, ttl,
3345 1, 0 /* is_static */ , &dst_map_index);
3347 /* try to program forwarding only if mapping saved or updated */
3348 if ((u32) ~ 0 != dst_map_index)
3349 lisp_add_del_adjacency (lcm, &pmr->src, &deid, 1);
3351 vec_free (locators);
3354 /* remove pending map request entry */
3357 clib_fifo_foreach (noncep, pmr->nonces, ({
3358 hash_unset(lcm->pending_map_requests_by_nonce, noncep[0]);
3362 clib_fifo_free (pmr->nonces);
3363 pool_put (lcm->pending_map_requests_pool, pmr);
3366 lisp_pending_map_request_unlock (lcm);
3371 process_map_request (vlib_main_t * vm, lisp_cp_main_t * lcm,
3374 map_request_hdr_t *mreq_hdr;
3375 gid_address_t src, dst;
3378 gid_address_t *itr_rlocs = 0, *rloc;
3380 mreq_hdr = vlib_buffer_get_current (b);
3381 vlib_buffer_pull (b, sizeof (*mreq_hdr));
3383 // nonce = MREQ_NONCE(mreq_hdr);
3385 if (!MREQ_SMR (mreq_hdr))
3387 clib_warning ("Only SMR Map-Requests supported for now!");
3392 len = lisp_msg_parse_addr (b, &src);
3396 /* for now we don't do anything with the itr's rlocs */
3398 lisp_msg_parse_itr_rlocs (b, &itr_rlocs,
3399 MREQ_ITR_RLOC_COUNT (mreq_hdr) + 1);
3403 /* TODO: RLOCs are currently unused, so free them for now */
3404 vec_foreach (rloc, itr_rlocs)
3406 gid_address_free (rloc);
3409 /* parse eid records and send SMR-invoked map-requests */
3410 for (i = 0; i < MREQ_REC_COUNT (mreq_hdr); i++)
3412 memset (&dst, 0, sizeof (dst));
3413 len = lisp_msg_parse_eid_rec (b, &dst);
3416 clib_warning ("Can't parse map-request EID-record");
3419 /* send SMR-invoked map-requests */
3420 queue_map_request (&dst, &src, 1 /* invoked */ , 0 /* resend */ );
3425 queue_map_reply (vlib_buffer_t * b)
3427 vlib_buffer_t *a = clib_mem_alloc (sizeof (a[0]) + b->current_length);
3429 clib_memcpy (a->data, b->data + b->current_data, b->current_length);
3430 a->current_length = b->current_length;
3431 a->current_data = 0;
3433 vl_api_rpc_call_main_thread (process_map_reply, (u8 *) a, sizeof (a[0])
3434 + a->current_length);
3439 lisp_cp_input (vlib_main_t * vm, vlib_node_runtime_t * node,
3440 vlib_frame_t * from_frame)
3442 u32 n_left_from, *from, *to_next_drop;
3443 lisp_msg_type_e type;
3444 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3446 from = vlib_frame_vector_args (from_frame);
3447 n_left_from = from_frame->n_vectors;
3450 while (n_left_from > 0)
3452 u32 n_left_to_next_drop;
3454 vlib_get_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP,
3455 to_next_drop, n_left_to_next_drop);
3456 while (n_left_from > 0 && n_left_to_next_drop > 0)
3464 to_next_drop[0] = bi0;
3466 n_left_to_next_drop -= 1;
3468 b0 = vlib_get_buffer (vm, bi0);
3470 type = lisp_msg_type (vlib_buffer_get_current (b0));
3473 case LISP_MAP_REPLY:
3474 queue_map_reply (b0);
3476 case LISP_MAP_REQUEST:
3477 process_map_request (vm, lcm, b0);
3480 clib_warning ("Unsupported LISP message type %d", type);
3484 b0->error = node->errors[LISP_CP_INPUT_ERROR_DROP];
3486 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
3492 vlib_put_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP,
3493 n_left_to_next_drop);
3495 return from_frame->n_vectors;
3499 VLIB_REGISTER_NODE (lisp_cp_input_node) = {
3500 .function = lisp_cp_input,
3501 .name = "lisp-cp-input",
3502 .vector_size = sizeof (u32),
3503 .format_trace = format_lisp_cp_input_trace,
3504 .type = VLIB_NODE_TYPE_INTERNAL,
3506 .n_errors = LISP_CP_INPUT_N_ERROR,
3507 .error_strings = lisp_cp_input_error_strings,
3509 .n_next_nodes = LISP_CP_INPUT_N_NEXT,
3512 [LISP_CP_INPUT_NEXT_DROP] = "error-drop",
3518 lisp_cp_init (vlib_main_t * vm)
3520 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3521 clib_error_t *error = 0;
3523 if ((error = vlib_call_init_function (vm, lisp_gpe_init)))
3526 lcm->im4 = &ip4_main;
3527 lcm->im6 = &ip6_main;
3528 lcm->vlib_main = vm;
3529 lcm->vnet_main = vnet_get_main ();
3530 lcm->mreq_itr_rlocs = ~0;
3532 memset (&lcm->active_map_resolver, 0, sizeof (lcm->active_map_resolver));
3534 lcm->pending_map_request_lock =
3535 clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);
3537 lcm->pending_map_request_lock[0] = 0;
3538 gid_dictionary_init (&lcm->mapping_index_by_gid);
3539 lcm->do_map_resolver_election = 1;
3540 lcm->map_request_mode = MR_MODE_DST_ONLY;
3542 /* default vrf mapped to vni 0 */
3543 hash_set (lcm->table_id_by_vni, 0, 0);
3544 hash_set (lcm->vni_by_table_id, 0, 0);
3546 udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp,
3547 lisp_cp_input_node.index, 1 /* is_ip4 */ );
3548 udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp6,
3549 lisp_cp_input_node.index, 0 /* is_ip4 */ );
3555 send_map_request_thread_fn (void *arg)
3557 map_request_args_t *a = arg;
3558 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3560 lisp_pending_map_request_lock (lcm);
3563 resend_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked);
3565 send_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked);
3567 lisp_pending_map_request_unlock (lcm);
3573 queue_map_request (gid_address_t * seid, gid_address_t * deid,
3574 u8 smr_invoked, u8 is_resend)
3576 map_request_args_t a;
3578 a.is_resend = is_resend;
3579 gid_address_copy (&a.seid, seid);
3580 gid_address_copy (&a.deid, deid);
3581 a.smr_invoked = smr_invoked;
3583 vl_api_rpc_call_main_thread (send_map_request_thread_fn,
3584 (u8 *) & a, sizeof (a));
3589 * Take an action with a pending map request depending on expiration time
3590 * and re-try counters.
3593 update_pending_request (pending_map_request_t * r, f64 dt)
3595 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3598 if (r->time_to_expire - dt < 0)
3599 /* it's time to decide what to do with this pending request */
3601 if (r->retries_num >= NUMBER_OF_RETRIES)
3602 /* too many retries -> assume current map resolver is not available */
3604 mr = get_map_resolver (&lcm->active_map_resolver);
3607 clib_warning ("Map resolver %U not found - probably deleted "
3608 "by the user recently.", format_ip_address,
3609 &lcm->active_map_resolver);
3613 clib_warning ("map resolver %U is unreachable, ignoring",
3614 format_ip_address, &lcm->active_map_resolver);
3616 /* mark current map resolver unavailable so it won't be
3617 * selected next time */
3619 mr->last_update = vlib_time_now (lcm->vlib_main);
3622 reset_pending_mr_counters (r);
3623 elect_map_resolver (lcm);
3625 /* try to find a next eligible map resolver and re-send */
3626 queue_map_request (&r->src, &r->dst, r->is_smr_invoked,
3632 queue_map_request (&r->src, &r->dst, r->is_smr_invoked,
3635 r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME;
3639 r->time_to_expire -= dt;
3643 remove_dead_pending_map_requests (lisp_cp_main_t * lcm)
3646 pending_map_request_t *pmr;
3647 u32 *to_be_removed = 0, *pmr_index;
3649 ASSERT (*lcm->pending_map_request_lock);
3652 pool_foreach (pmr, lcm->pending_map_requests_pool,
3654 if (pmr->to_be_removed)
3656 clib_fifo_foreach (nonce, pmr->nonces, ({
3657 hash_unset (lcm->pending_map_requests_by_nonce, nonce[0]);
3660 vec_add1 (to_be_removed, pmr - lcm->pending_map_requests_pool);
3665 vec_foreach (pmr_index, to_be_removed)
3666 pool_put_index (lcm->pending_map_requests_by_nonce, pmr_index[0]);
3668 vec_free (to_be_removed);
3672 send_map_resolver_service (vlib_main_t * vm,
3673 vlib_node_runtime_t * rt, vlib_frame_t * f)
3676 pending_map_request_t *pmr;
3677 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3681 vlib_process_wait_for_event_or_clock (vm, period);
3683 /* currently no signals are expected - just wait for clock */
3684 (void) vlib_process_get_events (vm, 0);
3686 lisp_pending_map_request_lock (lcm);
3689 pool_foreach (pmr, lcm->pending_map_requests_pool,
3691 if (!pmr->to_be_removed)
3692 update_pending_request (pmr, period);
3696 remove_dead_pending_map_requests (lcm);
3698 lisp_pending_map_request_unlock (lcm);
3706 VLIB_REGISTER_NODE (lisp_retry_service_node,static) = {
3707 .function = send_map_resolver_service,
3708 .type = VLIB_NODE_TYPE_PROCESS,
3709 .name = "lisp-retry-service",
3710 .process_log2_n_stack_bytes = 16,
3714 VLIB_INIT_FUNCTION (lisp_cp_init);
3717 * fd.io coding-style-patch-verification: ON
3720 * eval: (c-set-style "gnu")