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/lisp-gpe/lisp_gpe_fwd_entry.h>
22 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
23 #include <vnet/fib/fib_entry.h>
24 #include <vnet/fib/fib_table.h>
35 vnet_lisp_get_map_request_mode (void)
37 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
38 return lcm->map_request_mode;
42 queue_map_request (gid_address_t * seid, gid_address_t * deid,
43 u8 smr_invoked, u8 is_resend);
45 ip_interface_address_t *
46 ip_interface_get_first_interface_address (ip_lookup_main_t * lm,
47 u32 sw_if_index, u8 loop)
49 vnet_main_t *vnm = vnet_get_main ();
50 vnet_sw_interface_t *swif = vnet_get_sw_interface (vnm, sw_if_index);
51 if (loop && swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
52 sw_if_index = swif->unnumbered_sw_if_index;
54 (vec_len ((lm)->if_address_pool_index_by_sw_if_index) > (sw_if_index)) ?
55 vec_elt ((lm)->if_address_pool_index_by_sw_if_index, (sw_if_index)) :
57 return pool_elt_at_index ((lm)->if_address_pool, ia);
61 ip_interface_get_first_address (ip_lookup_main_t * lm, u32 sw_if_index,
64 ip_interface_address_t *ia;
66 ia = ip_interface_get_first_interface_address (lm, sw_if_index, 1);
69 return ip_interface_address_get_address (lm, ia);
73 ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index,
74 u8 version, ip_address_t * result)
79 lm = (version == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
80 addr = ip_interface_get_first_address (lm, sw_if_index, version);
84 ip_address_set (result, addr, version);
89 * convert from a LISP address to a FIB prefix
92 ip_address_to_fib_prefix (const ip_address_t * addr, fib_prefix_t * prefix)
94 if (addr->version == IP4)
97 prefix->fp_proto = FIB_PROTOCOL_IP4;
98 memset (&prefix->fp_addr.pad, 0, sizeof (prefix->fp_addr.pad));
99 memcpy (&prefix->fp_addr.ip4, &addr->ip, sizeof (prefix->fp_addr.ip4));
103 prefix->fp_len = 128;
104 prefix->fp_proto = FIB_PROTOCOL_IP6;
105 memcpy (&prefix->fp_addr.ip6, &addr->ip, sizeof (prefix->fp_addr.ip6));
110 * convert from a LISP to a FIB prefix
113 ip_prefix_to_fib_prefix (const ip_prefix_t * ip_prefix,
114 fib_prefix_t * fib_prefix)
116 ip_address_to_fib_prefix (&ip_prefix->addr, fib_prefix);
117 fib_prefix->fp_len = ip_prefix->len;
121 * Find the sw_if_index of the interface that would be used to egress towards
125 ip_fib_get_egress_iface_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst)
127 fib_node_index_t fei;
130 ip_address_to_fib_prefix (dst, &prefix);
132 fei = fib_table_lookup (0, &prefix);
134 return (fib_entry_get_resolving_interface (fei));
138 * Find first IP of the interface that would be used to egress towards dst.
139 * Returns 1 if the address is found 0 otherwise.
142 ip_fib_get_first_egress_ip_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst,
143 ip_address_t * result)
146 ip_lookup_main_t *lm;
150 ASSERT (result != 0);
152 ipver = ip_addr_version (dst);
154 lm = (ipver == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
155 si = ip_fib_get_egress_iface_for_dst (lcm, dst);
160 /* find the first ip address */
161 addr = ip_interface_get_first_address (lm, si, ipver);
165 ip_address_set (result, addr, ipver);
170 dp_add_del_iface (lisp_cp_main_t * lcm, u32 vni, u8 is_l2, u8 is_add)
176 dp_table = hash_get (lcm->table_id_by_vni, vni);
180 clib_warning ("vni %d not associated to a vrf!", vni);
181 return VNET_API_ERROR_INVALID_VALUE;
186 dp_table = hash_get (lcm->bd_id_by_vni, vni);
189 clib_warning ("vni %d not associated to a bridge domain!", vni);
190 return VNET_API_ERROR_INVALID_VALUE;
194 /* enable/disable data-plane interface */
198 lisp_gpe_tenant_l2_iface_add_or_lock (vni, dp_table[0]);
200 lisp_gpe_tenant_l3_iface_add_or_lock (vni, dp_table[0]);
205 lisp_gpe_tenant_l2_iface_unlock (vni);
207 lisp_gpe_tenant_l3_iface_unlock (vni);
214 dp_del_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
216 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
219 memset (a, 0, sizeof (*a));
221 feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index);
225 fe = pool_elt_at_index (lcm->fwd_entry_pool, feip[0]);
227 /* delete dp fwd entry */
230 a->locator_pairs = fe->locator_pairs;
231 a->vni = gid_address_vni (&fe->reid);
232 gid_address_copy (&a->rmt_eid, &fe->reid);
234 vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
236 /* delete entry in fwd table */
237 hash_unset (lcm->fwd_entry_by_mapping_index, dst_map_index);
238 vec_free (fe->locator_pairs);
239 pool_put (lcm->fwd_entry_pool, fe);
243 * Finds first remote locator with best (lowest) priority that has a local
244 * peer locator with an underlying route to it.
248 get_locator_pairs (lisp_cp_main_t * lcm, mapping_t * lcl_map,
249 mapping_t * rmt_map, locator_pair_t ** locator_pairs)
251 u32 i, limitp = 0, li, found = 0, esi;
252 locator_set_t *rmt_ls, *lcl_ls;
253 ip_address_t _lcl_addr, *lcl_addr = &_lcl_addr;
254 locator_t *lp, *rmt = 0;
259 pool_elt_at_index (lcm->locator_set_pool, rmt_map->locator_set_index);
261 pool_elt_at_index (lcm->locator_set_pool, lcl_map->locator_set_index);
263 if (!rmt_ls || vec_len (rmt_ls->locator_indices) == 0)
270 /* find unvisited remote locator with best priority */
271 for (i = 0; i < vec_len (rmt_ls->locator_indices); i++)
273 if (0 != hash_get (checked, i))
276 li = vec_elt (rmt_ls->locator_indices, i);
277 lp = pool_elt_at_index (lcm->locator_pool, li);
279 /* we don't support non-IP locators for now */
280 if (gid_address_type (&lp->address) != GID_ADDR_IP_PREFIX)
283 if ((found && lp->priority == limitp)
284 || (!found && lp->priority >= limitp))
288 /* don't search for locators with lower priority and don't
289 * check this locator again*/
290 limitp = lp->priority;
291 hash_set (checked, i, 1);
295 /* check if a local locator with a route to remote locator exists */
298 /* find egress sw_if_index for rmt locator */
300 ip_fib_get_egress_iface_for_dst (lcm,
301 &gid_address_ip (&rmt->address));
302 if ((u32) ~ 0 == esi)
305 for (i = 0; i < vec_len (lcl_ls->locator_indices); i++)
307 li = vec_elt (lcl_ls->locator_indices, i);
308 locator_t *sl = pool_elt_at_index (lcm->locator_pool, li);
310 /* found local locator with the needed sw_if_index */
311 if (sl->sw_if_index == esi)
313 /* and it has an address */
314 if (0 == ip_interface_get_first_ip_address (lcm,
316 gid_address_ip_version
321 memset (&pair, 0, sizeof (pair));
322 ip_address_copy (&pair.rmt_loc,
323 &gid_address_ip (&rmt->address));
324 ip_address_copy (&pair.lcl_loc, lcl_addr);
325 pair.weight = rmt->weight;
326 vec_add1 (locator_pairs[0], pair);
340 gid_address_sd_to_flat (gid_address_t * dst, gid_address_t * src,
343 ASSERT (GID_ADDR_SRC_DST == gid_address_type (src));
347 switch (fid_addr_type (fid))
349 case FID_ADDR_IP_PREF:
350 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
351 gid_address_ippref (dst) = fid_addr_ippref (fid);
354 gid_address_type (dst) = GID_ADDR_MAC;
355 mac_copy (gid_address_mac (dst), fid_addr_mac (fid));
358 clib_warning ("Unsupported fid type %d!", fid_addr_type (fid));
364 dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
366 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
367 mapping_t *src_map, *dst_map;
369 uword *feip = 0, *dpid;
373 memset (a, 0, sizeof (*a));
375 /* remove entry if it already exists */
376 feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index);
378 dp_del_fwd_entry (lcm, src_map_index, dst_map_index);
381 src_map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
383 src_map = pool_elt_at_index (lcm->mapping_pool, src_map_index);
384 dst_map = pool_elt_at_index (lcm->mapping_pool, dst_map_index);
386 /* insert data plane forwarding entry */
389 if (GID_ADDR_SRC_DST == gid_address_type (&dst_map->eid))
391 gid_address_sd_to_flat (&a->rmt_eid, &dst_map->eid,
392 &gid_address_sd_dst (&dst_map->eid));
393 gid_address_sd_to_flat (&a->lcl_eid, &dst_map->eid,
394 &gid_address_sd_src (&dst_map->eid));
397 gid_address_copy (&a->rmt_eid, &dst_map->eid);
399 a->vni = gid_address_vni (&a->rmt_eid);
401 /* get vrf or bd_index associated to vni */
402 type = gid_address_type (&a->rmt_eid);
403 if (GID_ADDR_IP_PREFIX == type)
405 dpid = hash_get (lcm->table_id_by_vni, a->vni);
408 clib_warning ("vni %d not associated to a vrf!", a->vni);
411 a->table_id = dpid[0];
413 else if (GID_ADDR_MAC == type)
415 dpid = hash_get (lcm->bd_id_by_vni, a->vni);
418 clib_warning ("vni %d not associated to a bridge domain !", a->vni);
424 /* find best locator pair that 1) verifies LISP policy 2) are connected */
425 if (0 == get_locator_pairs (lcm, src_map, dst_map, &a->locator_pairs))
429 a->action = dst_map->action;
433 u8 ipver = ip_prefix_version (&gid_address_ippref (&a->rmt_eid));
434 a->decap_next_index = (ipver == IP4) ?
435 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
437 vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
439 /* add tunnel to fwd entry table XXX check return value from DP insertion */
440 pool_get (lcm->fwd_entry_pool, fe);
441 fe->locator_pairs = a->locator_pairs;
442 gid_address_copy (&fe->reid, &a->rmt_eid);
443 hash_set (lcm->fwd_entry_by_mapping_index, dst_map_index,
444 fe - lcm->fwd_entry_pool);
448 * Add/remove mapping to/from map-cache. Overwriting not allowed.
451 vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a,
452 u32 * map_index_result)
454 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
455 u32 mi, *map_indexp, map_index, i;
456 mapping_t *m, *old_map;
459 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->eid);
460 old_map = mi != ~0 ? pool_elt_at_index (lcm->mapping_pool, mi) : 0;
463 /* TODO check if overwriting and take appropriate actions */
464 if (mi != GID_LOOKUP_MISS && !gid_address_cmp (&old_map->eid, &a->eid))
466 clib_warning ("eid %U found in the eid-table", format_gid_address,
468 return VNET_API_ERROR_VALUE_EXIST;
471 pool_get (lcm->mapping_pool, m);
472 gid_address_copy (&m->eid, &a->eid);
473 m->locator_set_index = a->locator_set_index;
475 m->action = a->action;
477 m->is_static = a->is_static;
479 map_index = m - lcm->mapping_pool;
480 gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, map_index,
483 if (pool_is_free_index (lcm->locator_set_pool, a->locator_set_index))
485 clib_warning ("Locator set with index %d doesn't exist",
486 a->locator_set_index);
487 return VNET_API_ERROR_INVALID_VALUE;
490 /* add eid to list of eids supported by locator-set */
491 vec_validate (lcm->locator_set_to_eids, a->locator_set_index);
492 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids,
493 a->locator_set_index);
494 vec_add1 (eid_indexes[0], map_index);
499 vec_add1 (lcm->local_mappings_indexes, map_index);
501 map_index_result[0] = map_index;
505 if (mi == GID_LOOKUP_MISS)
507 clib_warning ("eid %U not found in the eid-table",
508 format_gid_address, &a->eid);
509 return VNET_API_ERROR_INVALID_VALUE;
512 /* clear locator-set to eids binding */
513 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids,
514 a->locator_set_index);
515 for (i = 0; i < vec_len (eid_indexes[0]); i++)
517 map_indexp = vec_elt_at_index (eid_indexes[0], i);
518 if (map_indexp[0] == mi)
521 vec_del1 (eid_indexes[0], i);
523 /* remove local mark if needed */
524 m = pool_elt_at_index (lcm->mapping_pool, mi);
528 for (k = 0; k < vec_len (lcm->local_mappings_indexes); k++)
530 lm_indexp = vec_elt_at_index (lcm->local_mappings_indexes, k);
531 if (lm_indexp[0] == mi)
534 vec_del1 (lcm->local_mappings_indexes, k);
537 /* remove mapping from dictionary */
538 gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, 0, 0);
539 gid_address_free (&m->eid);
540 pool_put_index (lcm->mapping_pool, mi);
547 * Add/update/delete mapping to/in/from map-cache.
550 vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a,
551 u32 * map_index_result)
557 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
559 if (vnet_lisp_enable_disable_status () == 0)
561 clib_warning ("LISP is disabled!");
562 return VNET_API_ERROR_LISP_DISABLED;
565 vni = gid_address_vni (&a->eid);
566 type = gid_address_type (&a->eid);
567 if (GID_ADDR_IP_PREFIX == type)
568 dp_table = hash_get (lcm->table_id_by_vni, vni);
569 else if (GID_ADDR_MAC == type)
570 dp_table = hash_get (lcm->bd_id_by_vni, vni);
574 clib_warning ("vni %d not associated to a %s!", vni,
575 GID_ADDR_IP_PREFIX == type ? "vrf" : "bd");
576 return VNET_API_ERROR_INVALID_VALUE;
579 /* store/remove mapping from map-cache */
580 return vnet_lisp_map_cache_add_del (a, map_index_result);
583 static clib_error_t *
584 lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
585 vlib_cli_command_t * cmd)
587 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
588 unformat_input_t _line_input, *line_input = &_line_input;
591 gid_address_t *eids = 0;
592 clib_error_t *error = 0;
593 u8 *locator_set_name = 0;
594 u32 locator_set_index = 0, map_index = 0;
596 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
600 memset (&eid, 0, sizeof (eid));
601 memset (a, 0, sizeof (*a));
603 /* Get a line of input. */
604 if (!unformat_user (input, unformat_line_input, line_input))
607 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
609 if (unformat (line_input, "add"))
611 else if (unformat (line_input, "del"))
613 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
615 else if (unformat (line_input, "vni %d", &vni))
616 gid_address_vni (&eid) = vni;
617 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
619 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
622 error = clib_error_return (0, "locator-set %s doesn't exist",
626 locator_set_index = p[0];
630 error = unformat_parse_error (line_input);
634 /* XXX treat batch configuration */
636 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
639 clib_error_return (0, "src/dst is not supported for local EIDs!");
643 gid_address_copy (&a->eid, &eid);
645 a->locator_set_index = locator_set_index;
648 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
651 error = clib_error_return (0, "failed to %s local mapping!",
652 is_add ? "add" : "delete");
656 if (locator_set_name)
657 vec_free (locator_set_name);
658 gid_address_free (&a->eid);
663 VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = {
664 .path = "lisp eid-table",
665 .short_help = "lisp eid-table add/del [vni <vni>] eid <eid> "
666 "locator-set <locator-set>",
667 .function = lisp_add_del_local_eid_command_fn,
672 vnet_lisp_eid_table_map (u32 vni, u32 dp_id, u8 is_l2, u8 is_add)
674 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
675 uword *dp_idp, *vnip, **dp_table_by_vni, **vni_by_dp_table;
677 if (vnet_lisp_enable_disable_status () == 0)
679 clib_warning ("LISP is disabled!");
683 dp_table_by_vni = is_l2 ? &lcm->bd_id_by_vni : &lcm->table_id_by_vni;
684 vni_by_dp_table = is_l2 ? &lcm->vni_by_bd_id : &lcm->vni_by_table_id;
686 if (!is_l2 && (vni == 0 || dp_id == 0))
688 clib_warning ("can't add/del default vni-vrf mapping!");
692 dp_idp = hash_get (dp_table_by_vni[0], vni);
693 vnip = hash_get (vni_by_dp_table[0], dp_id);
699 clib_warning ("vni %d or vrf %d already used in vrf/vni "
700 "mapping!", vni, dp_id);
703 hash_set (dp_table_by_vni[0], vni, dp_id);
704 hash_set (vni_by_dp_table[0], dp_id, vni);
706 /* create dp iface */
707 dp_add_del_iface (lcm, vni, is_l2, 1);
711 if (!dp_idp || !vnip)
713 clib_warning ("vni %d or vrf %d not used in any vrf/vni! "
714 "mapping!", vni, dp_id);
717 hash_unset (dp_table_by_vni[0], vni);
718 hash_unset (vni_by_dp_table[0], dp_id);
720 /* remove dp iface */
721 dp_add_del_iface (lcm, vni, is_l2, 0);
727 static clib_error_t *
728 lisp_eid_table_map_command_fn (vlib_main_t * vm,
729 unformat_input_t * input,
730 vlib_cli_command_t * cmd)
732 u8 is_add = 1, is_l2 = 0;
733 u32 vni = 0, dp_id = 0;
734 unformat_input_t _line_input, *line_input = &_line_input;
736 /* Get a line of input. */
737 if (!unformat_user (input, unformat_line_input, line_input))
740 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
742 if (unformat (line_input, "del"))
744 else if (unformat (line_input, "vni %d", &vni))
746 else if (unformat (line_input, "vrf %d", &dp_id))
748 else if (unformat (line_input, "bd %d", &dp_id))
752 return unformat_parse_error (line_input);
755 vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
760 VLIB_CLI_COMMAND (lisp_eid_table_map_command) = {
761 .path = "lisp eid-table map",
762 .short_help = "lisp eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
763 .function = lisp_eid_table_map_command_fn,
767 /* return 0 if the two locator sets are identical 1 otherwise */
769 compare_locators (lisp_cp_main_t * lcm, u32 * old_ls_indexes,
770 locator_t * new_locators)
773 locator_t *old_loc, *new_loc;
775 if (vec_len (old_ls_indexes) != vec_len (new_locators))
778 for (i = 0; i < vec_len (new_locators); i++)
780 old_li = vec_elt (old_ls_indexes, i);
781 old_loc = pool_elt_at_index (lcm->locator_pool, old_li);
783 new_loc = vec_elt_at_index (new_locators, i);
785 if (locator_cmp (old_loc, new_loc))
792 * Adds/removes/updates mapping. Does not program forwarding.
794 * @param eid end-host identifier
795 * @param rlocs vector of remote locators
796 * @param action action for negative map-reply
797 * @param is_add add mapping if non-zero, delete otherwise
798 * @param res_map_index the map-index that was created/updated/removed. It is
799 * set to ~0 if no action is taken.
800 * @param is_static used for distinguishing between statically learned
801 remote mappings and mappings obtained from MR
802 * @return return code
805 vnet_lisp_add_del_mapping (gid_address_t * eid, locator_t * rlocs, u8 action,
806 u8 authoritative, u32 ttl, u8 is_add, u8 is_static,
809 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
810 vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args;
811 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
812 u32 mi, ls_index = 0, dst_map_index;
815 if (vnet_lisp_enable_disable_status () == 0)
817 clib_warning ("LISP is disabled!");
818 return VNET_API_ERROR_LISP_DISABLED;
822 res_map_index[0] = ~0;
824 memset (m_args, 0, sizeof (m_args[0]));
825 memset (ls_args, 0, sizeof (ls_args[0]));
827 ls_args->locators = rlocs;
829 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
830 old_map = ((u32) ~ 0 != mi) ? pool_elt_at_index (lcm->mapping_pool, mi) : 0;
834 /* overwrite: if mapping already exists, decide if locators should be
835 * updated and be done */
836 if (old_map && gid_address_cmp (&old_map->eid, eid) == 0)
838 if (!is_static && (old_map->is_static || old_map->local))
840 /* do not overwrite local or static remote mappings */
841 clib_warning ("mapping %U rejected due to collision with local "
842 "or static remote mapping!", format_gid_address,
847 locator_set_t *old_ls;
849 /* update mapping attributes */
850 old_map->action = action;
851 old_map->authoritative = authoritative;
854 old_ls = pool_elt_at_index (lcm->locator_set_pool,
855 old_map->locator_set_index);
856 if (compare_locators (lcm, old_ls->locator_indices,
859 /* set locator-set index to overwrite */
861 ls_args->index = old_map->locator_set_index;
862 vnet_lisp_add_del_locator_set (ls_args, 0);
864 res_map_index[0] = mi;
873 vnet_lisp_add_del_locator_set (ls_args, &ls_index);
876 gid_address_copy (&m_args->eid, eid);
878 m_args->action = action;
879 m_args->locator_set_index = ls_index;
880 m_args->is_static = is_static;
881 vnet_lisp_map_cache_add_del (m_args, &dst_map_index);
884 res_map_index[0] = dst_map_index;
889 if (old_map == 0 || gid_address_cmp (&old_map->eid, eid) != 0)
891 clib_warning ("cannot delete mapping for eid %U",
892 format_gid_address, eid);
897 gid_address_copy (&m_args->eid, eid);
898 m_args->locator_set_index = old_map->locator_set_index;
900 /* delete mapping associated from map-cache */
901 vnet_lisp_map_cache_add_del (m_args, 0);
904 ls_args->index = old_map->locator_set_index;
905 /* delete locator set */
906 vnet_lisp_add_del_locator_set (ls_args, 0);
908 /* return old mapping index */
910 res_map_index[0] = mi;
918 vnet_lisp_clear_all_remote_adjacencies (void)
921 u32 mi, *map_indices = 0, *map_indexp;
922 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
923 vnet_lisp_add_del_mapping_args_t _dm_args, *dm_args = &_dm_args;
924 vnet_lisp_add_del_locator_set_args_t _ls, *ls = &_ls;
927 pool_foreach_index (mi, lcm->mapping_pool,
929 vec_add1 (map_indices, mi);
933 vec_foreach (map_indexp, map_indices)
935 mapping_t *map = pool_elt_at_index (lcm->mapping_pool, map_indexp[0]);
938 dp_del_fwd_entry (lcm, 0, map_indexp[0]);
941 gid_address_copy (&dm_args->eid, &map->eid);
942 dm_args->locator_set_index = map->locator_set_index;
944 /* delete mapping associated to fwd entry */
945 vnet_lisp_map_cache_add_del (dm_args, 0);
949 ls->index = map->locator_set_index;
950 /* delete locator set */
951 rv = vnet_lisp_add_del_locator_set (ls, 0);
959 vec_free (map_indices);
964 * Adds adjacency or removes forwarding entry associated to remote mapping.
965 * Note that adjacencies are not stored, they only result in forwarding entries
969 lisp_add_del_adjacency (lisp_cp_main_t * lcm, gid_address_t * local_eid,
970 gid_address_t * remote_eid, u8 is_add)
972 u32 local_mi, remote_mi = ~0;
974 if (vnet_lisp_enable_disable_status () == 0)
976 clib_warning ("LISP is disabled!");
977 return VNET_API_ERROR_LISP_DISABLED;
980 remote_mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, remote_eid);
981 if (GID_LOOKUP_MISS == remote_mi)
983 clib_warning ("Remote eid %U not found. Cannot add adjacency!",
984 format_gid_address, remote_eid);
991 /* TODO 1) check if src/dst 2) once we have src/dst working, use it in
994 /* check if source eid has an associated mapping. If pitr mode is on,
995 * just use the pitr's mapping */
996 local_mi = lcm->lisp_pitr ? lcm->pitr_map_index :
997 gid_dictionary_lookup (&lcm->mapping_index_by_gid, local_eid);
1000 if (GID_LOOKUP_MISS == local_mi)
1002 clib_warning ("Local eid %U not found. Cannot add adjacency!",
1003 format_gid_address, local_eid);
1008 /* update forwarding */
1009 dp_add_fwd_entry (lcm, local_mi, remote_mi);
1012 dp_del_fwd_entry (lcm, 0, remote_mi);
1018 vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a)
1020 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1021 return lisp_add_del_adjacency (lcm, &a->leid, &a->reid, a->is_add);
1025 * Handler for add/del remote mapping CLI.
1027 * @param vm vlib context
1028 * @param input input from user
1030 * @return pointer to clib error structure
1032 static clib_error_t *
1033 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
1034 unformat_input_t * input,
1035 vlib_cli_command_t * cmd)
1037 clib_error_t *error = 0;
1038 unformat_input_t _line_input, *line_input = &_line_input;
1039 u8 is_add = 1, del_all = 0;
1040 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
1043 u32 vni, action = ~0, p, w;
1046 /* Get a line of input. */
1047 if (!unformat_user (input, unformat_line_input, line_input))
1050 memset (&eid, 0, sizeof (eid));
1051 memset (&rloc, 0, sizeof (rloc));
1053 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1055 if (unformat (line_input, "del-all"))
1057 else if (unformat (line_input, "del"))
1059 else if (unformat (line_input, "add"))
1061 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
1063 else if (unformat (line_input, "vni %u", &vni))
1065 gid_address_vni (&eid) = vni;
1067 else if (unformat (line_input, "p %d w %d", &p, &w))
1072 ("No RLOC configured for setting priority/weight!");
1075 curr_rloc->priority = p;
1076 curr_rloc->weight = w;
1078 else if (unformat (line_input, "rloc %U", unformat_ip_address,
1079 &gid_address_ip (&rloc.address)))
1081 /* since rloc is stored in ip prefix we need to set prefix length */
1082 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
1084 u8 version = gid_address_ip_version (&rloc.address);
1085 ip_prefix_len (pref) = ip_address_max_len (version);
1087 vec_add1 (rlocs, rloc);
1088 curr_rloc = &rlocs[vec_len (rlocs) - 1];
1090 else if (unformat (line_input, "action %U",
1091 unformat_negative_mapping_action, &action))
1095 clib_warning ("parse error");
1102 clib_warning ("missing eid!");
1108 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
1110 clib_warning ("no action set for negative map-reply!");
1116 vnet_lisp_clear_all_remote_adjacencies ();
1120 /* TODO build src/dst with seid */
1122 /* if it's a delete, clean forwarding */
1125 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1126 rv = lisp_add_del_adjacency (lcm, 0, &eid, /* is_add */ 0);
1133 /* add as static remote mapping, i.e., not authoritative and infinite
1135 rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add,
1136 1 /* is_static */ , 0);
1139 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
1143 unformat_free (line_input);
1147 VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) =
1149 .path = "lisp remote-mapping",.short_help =
1150 "lisp remote-mapping add|del [del-all] vni <vni> "
1151 "eid <est-eid> [action <no-action|natively-forward|"
1152 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
1153 "[rloc <dst-locator> ... ]",.function =
1154 lisp_add_del_remote_mapping_command_fn,};
1157 * Handler for add/del adjacency CLI.
1159 static clib_error_t *
1160 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
1161 vlib_cli_command_t * cmd)
1163 clib_error_t *error = 0;
1164 unformat_input_t _line_input, *line_input = &_line_input;
1165 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
1167 ip_prefix_t *reid_ippref, *leid_ippref;
1168 gid_address_t leid, reid;
1169 u8 *dmac = gid_address_mac (&reid);
1170 u8 *smac = gid_address_mac (&leid);
1171 u8 reid_set = 0, leid_set = 0;
1175 /* Get a line of input. */
1176 if (!unformat_user (input, unformat_line_input, line_input))
1179 memset (&reid, 0, sizeof (reid));
1180 memset (&leid, 0, sizeof (leid));
1182 leid_ippref = &gid_address_ippref (&leid);
1183 reid_ippref = &gid_address_ippref (&reid);
1185 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1187 if (unformat (line_input, "del"))
1189 else if (unformat (line_input, "add"))
1191 else if (unformat (line_input, "reid %U",
1192 unformat_ip_prefix, reid_ippref))
1194 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
1197 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
1199 gid_address_type (&reid) = GID_ADDR_MAC;
1202 else if (unformat (line_input, "vni %u", &vni))
1204 gid_address_vni (&leid) = vni;
1205 gid_address_vni (&reid) = vni;
1207 else if (unformat (line_input, "leid %U",
1208 unformat_ip_prefix, leid_ippref))
1210 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
1213 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
1215 gid_address_type (&leid) = GID_ADDR_MAC;
1220 clib_warning ("parse error");
1225 if (!reid_set || !leid_set)
1227 clib_warning ("missing remote or local eid!");
1231 if ((gid_address_type (&leid) != gid_address_type (&reid))
1232 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
1233 && ip_prefix_version (reid_ippref)
1234 != ip_prefix_version (leid_ippref)))
1236 clib_warning ("remote and local EIDs are of different types!");
1240 memset (a, 0, sizeof (a[0]));
1241 gid_address_copy (&a->leid, &leid);
1242 gid_address_copy (&a->reid, &reid);
1245 rv = vnet_lisp_add_del_adjacency (a);
1248 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
1251 unformat_free (line_input);
1256 VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = {
1257 .path = "lisp adjacency",
1258 .short_help = "lisp adjacency add|del vni <vni> reid <remote-eid> "
1260 .function = lisp_add_del_adjacency_command_fn,
1265 vnet_lisp_set_map_request_mode (u8 mode)
1267 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1269 if (vnet_lisp_enable_disable_status () == 0)
1271 clib_warning ("LISP is disabled!");
1272 return VNET_API_ERROR_LISP_DISABLED;
1275 if (mode >= _MR_MODE_MAX)
1277 clib_warning ("Invalid LISP map request mode %d!", mode);
1278 return VNET_API_ERROR_INVALID_ARGUMENT;
1281 lcm->map_request_mode = mode;
1285 static clib_error_t *
1286 lisp_map_request_mode_command_fn (vlib_main_t * vm,
1287 unformat_input_t * input,
1288 vlib_cli_command_t * cmd)
1290 unformat_input_t _i, *i = &_i;
1291 map_request_mode_t mr_mode = _MR_MODE_MAX;
1293 /* Get a line of input. */
1294 if (!unformat_user (input, unformat_line_input, i))
1297 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1299 if (unformat (i, "dst-only"))
1300 mr_mode = MR_MODE_DST_ONLY;
1301 else if (unformat (i, "src-dst"))
1302 mr_mode = MR_MODE_SRC_DST;
1305 clib_warning ("parse error '%U'", format_unformat_error, i);
1310 if (_MR_MODE_MAX == mr_mode)
1312 clib_warning ("No LISP map request mode entered!");
1316 vnet_lisp_set_map_request_mode (mr_mode);
1322 VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
1323 .path = "lisp map-request mode",
1324 .short_help = "lisp map-request mode dst-only|src-dst",
1325 .function = lisp_map_request_mode_command_fn,
1330 format_lisp_map_request_mode (u8 * s, va_list * args)
1332 u32 mode = va_arg (*args, u32);
1337 return format (0, "dst-only");
1339 return format (0, "src-dst");
1344 static clib_error_t *
1345 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
1346 unformat_input_t * input,
1347 vlib_cli_command_t * cmd)
1349 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
1350 vnet_lisp_get_map_request_mode ());
1355 VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
1356 .path = "show lisp map-request mode",
1357 .short_help = "show lisp map-request mode",
1358 .function = lisp_show_map_request_mode_command_fn,
1362 static clib_error_t *
1363 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
1364 unformat_input_t * input,
1365 vlib_cli_command_t * cmd)
1368 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1370 vec_foreach (mr, lcm->map_resolvers)
1372 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
1378 VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
1379 .path = "show lisp map-resolvers",
1380 .short_help = "show lisp map-resolvers",
1381 .function = lisp_show_map_resolvers_command_fn,
1386 vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add)
1388 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1389 u32 locator_set_index = ~0;
1393 if (vnet_lisp_enable_disable_status () == 0)
1395 clib_warning ("LISP is disabled!");
1396 return VNET_API_ERROR_LISP_DISABLED;
1399 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
1402 clib_warning ("locator-set %v doesn't exist", locator_set_name);
1405 locator_set_index = p[0];
1409 pool_get (lcm->mapping_pool, m);
1410 m->locator_set_index = locator_set_index;
1412 lcm->pitr_map_index = m - lcm->mapping_pool;
1414 /* enable pitr mode */
1419 /* remove pitr mapping */
1420 pool_put_index (lcm->mapping_pool, lcm->pitr_map_index);
1422 /* disable pitr mode */
1428 static clib_error_t *
1429 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
1430 unformat_input_t * input,
1431 vlib_cli_command_t * cmd)
1433 u8 locator_name_set = 0;
1434 u8 *locator_set_name = 0;
1436 unformat_input_t _line_input, *line_input = &_line_input;
1437 clib_error_t *error = 0;
1440 /* Get a line of input. */
1441 if (!unformat_user (input, unformat_line_input, line_input))
1444 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1446 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
1447 locator_name_set = 1;
1448 else if (unformat (line_input, "disable"))
1451 return clib_error_return (0, "parse error");
1454 if (!locator_name_set)
1456 clib_warning ("No locator set specified!");
1459 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
1462 error = clib_error_return (0, "failed to %s pitr!",
1463 is_add ? "add" : "delete");
1467 if (locator_set_name)
1468 vec_free (locator_set_name);
1473 VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
1474 .path = "lisp pitr",
1475 .short_help = "lisp pitr [disable] ls <locator-set-name>",
1476 .function = lisp_pitr_set_locator_set_command_fn,
1480 static clib_error_t *
1481 lisp_show_pitr_command_fn (vlib_main_t * vm,
1482 unformat_input_t * input, vlib_cli_command_t * cmd)
1484 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1489 vlib_cli_output (vm, "%=20s%=16s",
1490 "pitr", lcm->lisp_pitr ? "locator-set" : "");
1492 if (!lcm->lisp_pitr)
1494 vlib_cli_output (vm, "%=20s", "disable");
1498 if (~0 == lcm->pitr_map_index)
1500 tmp_str = format (0, "N/A");
1504 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1505 if (~0 != m->locator_set_index)
1508 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1509 tmp_str = format (0, "%s", ls->name);
1513 tmp_str = format (0, "N/A");
1516 vec_add1 (tmp_str, 0);
1518 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1526 VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
1527 .path = "show lisp pitr",
1528 .short_help = "Show pitr",
1529 .function = lisp_show_pitr_command_fn,
1534 format_eid_entry (u8 * s, va_list * args)
1536 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
1537 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
1538 mapping_t *mapit = va_arg (*args, mapping_t *);
1539 locator_set_t *ls = va_arg (*args, locator_set_t *);
1540 gid_address_t *gid = &mapit->eid;
1541 u32 ttl = mapit->ttl;
1542 u8 aut = mapit->authoritative;
1547 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
1548 : format (0, "remote");
1550 if (vec_len (ls->locator_indices) == 0)
1552 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
1557 vec_foreach (loc_index, ls->locator_indices)
1559 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
1561 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
1564 loc = format (0, "%U", format_ip_address,
1565 &gid_address_ip (&l->address));
1569 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
1570 gid, type, loc, ttl, aut);
1574 s = format (s, "%55s%v\n", "", loc);
1580 static clib_error_t *
1581 lisp_show_eid_table_command_fn (vlib_main_t * vm,
1582 unformat_input_t * input,
1583 vlib_cli_command_t * cmd)
1585 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1587 unformat_input_t _line_input, *line_input = &_line_input;
1593 memset (&eid, 0, sizeof (eid));
1595 /* Get a line of input. */
1596 if (!unformat_user (input, unformat_line_input, line_input))
1599 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1601 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
1603 else if (unformat (line_input, "local"))
1605 else if (unformat (line_input, "remote"))
1608 return clib_error_return (0, "parse error: '%U'",
1609 format_unformat_error, line_input);
1612 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
1613 "EID", "type", "locators", "ttl", "autoritative");
1618 pool_foreach (mapit, lcm->mapping_pool,
1620 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
1621 mapit->locator_set_index);
1622 if (filter && !((1 == filter && ls->local) ||
1623 (2 == filter && !ls->local)))
1627 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
1634 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
1635 if ((u32) ~ 0 == mi)
1638 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
1639 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
1640 mapit->locator_set_index);
1642 if (filter && !((1 == filter && ls->local) ||
1643 (2 == filter && !ls->local)))
1648 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
1656 VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = {
1657 .path = "show lisp eid-table",
1658 .short_help = "Shows EID table",
1659 .function = lisp_show_eid_table_command_fn,
1663 /* cleans locator to locator-set data and removes locators not part of
1664 * any locator-set */
1666 clean_locator_to_locator_set (lisp_cp_main_t * lcm, u32 lsi)
1668 u32 i, j, *loc_indexp, *ls_indexp, **ls_indexes, *to_be_deleted = 0;
1669 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, lsi);
1670 for (i = 0; i < vec_len (ls->locator_indices); i++)
1672 loc_indexp = vec_elt_at_index (ls->locator_indices, i);
1673 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets,
1675 for (j = 0; j < vec_len (ls_indexes[0]); j++)
1677 ls_indexp = vec_elt_at_index (ls_indexes[0], j);
1678 if (ls_indexp[0] == lsi)
1682 /* delete index for removed locator-set */
1683 vec_del1 (ls_indexes[0], j);
1685 /* delete locator if it's part of no locator-set */
1686 if (vec_len (ls_indexes[0]) == 0)
1688 pool_put_index (lcm->locator_pool, loc_indexp[0]);
1689 vec_add1 (to_be_deleted, i);
1695 for (i = 0; i < vec_len (to_be_deleted); i++)
1697 loc_indexp = vec_elt_at_index (to_be_deleted, i);
1698 vec_del1 (ls->locator_indices, loc_indexp[0]);
1700 vec_free (to_be_deleted);
1704 static inline uword *
1705 get_locator_set_index (vnet_lisp_add_del_locator_set_args_t * a, uword * p)
1707 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1712 /* find locator-set */
1715 p = hash_get_mem (lcm->locator_set_index_by_name, a->name);
1726 is_locator_in_locator_set (lisp_cp_main_t * lcm, locator_set_t * ls,
1732 ASSERT (ls != NULL);
1733 ASSERT (loc != NULL);
1735 vec_foreach (locit, ls->locator_indices)
1737 itloc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1738 if ((ls->local && itloc->sw_if_index == loc->sw_if_index) ||
1739 (!ls->local && !gid_address_cmp (&itloc->address, &loc->address)))
1741 clib_warning ("Duplicate locator");
1742 return VNET_API_ERROR_VALUE_EXIST;
1750 remove_locator_from_locator_set (locator_set_t * ls, u32 * locit,
1751 u32 ls_index, u32 loc_id)
1753 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1754 u32 **ls_indexes = NULL;
1756 ASSERT (ls != NULL);
1757 ASSERT (locit != NULL);
1759 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, locit[0]);
1760 pool_put_index (lcm->locator_pool, locit[0]);
1761 vec_del1 (ls->locator_indices, loc_id);
1762 vec_del1 (ls_indexes[0], ls_index);
1766 vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a,
1767 locator_set_t * ls, u32 * ls_result)
1769 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1770 locator_t *loc = NULL, *itloc = NULL;
1771 uword _p = (u32) ~ 0, *p = &_p;
1772 u32 loc_index = ~0, ls_index = ~0, *locit = NULL, **ls_indexes = NULL;
1778 if (vnet_lisp_enable_disable_status () == 0)
1780 clib_warning ("LISP is disabled!");
1781 return VNET_API_ERROR_LISP_DISABLED;
1784 p = get_locator_set_index (a, p);
1787 clib_warning ("locator-set %v doesn't exist", a->name);
1788 return VNET_API_ERROR_INVALID_ARGUMENT;
1793 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1796 clib_warning ("locator-set %d to be overwritten doesn't exist!",
1798 return VNET_API_ERROR_INVALID_ARGUMENT;
1805 ls_result[0] = p[0];
1807 /* allocate locators */
1808 vec_foreach (itloc, a->locators)
1810 ret = is_locator_in_locator_set (lcm, ls, itloc);
1816 pool_get (lcm->locator_pool, loc);
1818 loc_index = loc - lcm->locator_pool;
1820 vec_add1 (ls->locator_indices, loc_index);
1822 vec_validate (lcm->locator_to_locator_sets, loc_index);
1823 ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets,
1825 vec_add1 (ls_indexes[0], p[0]);
1832 itloc = a->locators;
1834 vec_foreach (locit, ls->locator_indices)
1836 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1838 if (loc->local && loc->sw_if_index == itloc->sw_if_index)
1840 remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
1842 if (0 == loc->local &&
1843 !gid_address_cmp (&loc->address, &itloc->address))
1845 remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
1856 vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a,
1859 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1861 uword _p = (u32) ~ 0, *p = &_p;
1866 if (vnet_lisp_enable_disable_status () == 0)
1868 clib_warning ("LISP is disabled!");
1869 return VNET_API_ERROR_LISP_DISABLED;
1874 p = get_locator_set_index (a, p);
1877 if (p && p[0] != (u32) ~ 0)
1879 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1882 clib_warning ("locator-set %d to be overwritten doesn't exist!",
1887 /* clean locator to locator-set vectors and remove locators if
1888 * they're not part of another locator-set */
1889 clean_locator_to_locator_set (lcm, p[0]);
1891 /* remove locator indices from locator set */
1892 vec_free (ls->locator_indices);
1897 ls_result[0] = p[0];
1899 /* new locator-set */
1902 pool_get (lcm->locator_set_pool, ls);
1903 memset (ls, 0, sizeof (*ls));
1904 ls_index = ls - lcm->locator_set_pool;
1908 ls->name = vec_dup (a->name);
1910 if (!lcm->locator_set_index_by_name)
1911 lcm->locator_set_index_by_name = hash_create_vec (
1919 hash_set_mem (lcm->locator_set_index_by_name, ls->name,
1922 /* mark as local locator-set */
1923 vec_add1 (lcm->local_locator_set_indexes, ls_index);
1925 ls->local = a->local;
1927 ls_result[0] = ls_index;
1930 ret = vnet_lisp_add_del_locator (a, ls, NULL);
1938 p = get_locator_set_index (a, p);
1941 clib_warning ("locator-set %v doesn't exists", a->name);
1945 ls = pool_elt_at_index (lcm->locator_set_pool, p[0]);
1948 clib_warning ("locator-set with index %d doesn't exists", p[0]);
1952 if (lcm->mreq_itr_rlocs == p[0])
1954 clib_warning ("Can't delete the locator-set used to constrain "
1955 "the itr-rlocs in map-requests!");
1959 if (vec_len (lcm->locator_set_to_eids) != 0)
1961 eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, p[0]);
1962 if (vec_len (eid_indexes[0]) != 0)
1965 ("Can't delete a locator that supports a mapping!");
1970 /* clean locator to locator-sets data */
1971 clean_locator_to_locator_set (lcm, p[0]);
1977 vec_foreach_index (it, lcm->local_locator_set_indexes)
1979 lsi = vec_elt (lcm->local_locator_set_indexes, it);
1982 vec_del1 (lcm->local_locator_set_indexes, it);
1986 hash_unset_mem (lcm->locator_set_index_by_name, ls->name);
1988 vec_free (ls->name);
1989 vec_free (ls->locator_indices);
1990 pool_put (lcm->locator_set_pool, ls);
1996 vnet_lisp_enable_disable (u8 is_enable)
1999 clib_error_t *error = 0;
2000 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2001 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
2003 a->is_en = is_enable;
2004 error = vnet_lisp_gpe_enable_disable (a);
2007 return clib_error_return (0, "failed to %s data-plane!",
2008 a->is_en ? "enable" : "disable");
2013 /* enable all l2 and l3 ifaces */
2016 hash_foreach(vni, dp_table, lcm->table_id_by_vni, ({
2017 dp_add_del_iface(lcm, vni, 0, 1);
2019 hash_foreach(vni, dp_table, lcm->bd_id_by_vni, ({
2020 dp_add_del_iface(lcm, vni, /* is_l2 */ 1, 1);
2026 /* clear interface table */
2027 hash_free (lcm->fwd_entry_by_mapping_index);
2028 pool_free (lcm->fwd_entry_pool);
2031 /* update global flag */
2032 lcm->is_enabled = is_enable;
2037 static clib_error_t *
2038 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
2039 vlib_cli_command_t * cmd)
2041 unformat_input_t _line_input, *line_input = &_line_input;
2045 /* Get a line of input. */
2046 if (!unformat_user (input, unformat_line_input, line_input))
2049 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2051 if (unformat (line_input, "enable"))
2056 else if (unformat (line_input, "disable"))
2060 return clib_error_return (0, "parse error: '%U'",
2061 format_unformat_error, line_input);
2066 return clib_error_return (0, "state not set");
2068 return vnet_lisp_enable_disable (is_enabled);
2072 VLIB_CLI_COMMAND (lisp_cp_enable_disable_command) = {
2074 .short_help = "lisp [enable|disable]",
2075 .function = lisp_enable_disable_command_fn,
2080 vnet_lisp_enable_disable_status (void)
2082 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2083 return lcm->is_enabled;
2087 format_lisp_status (u8 * s, va_list * args)
2089 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2090 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
2093 static clib_error_t *
2094 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
2095 vlib_cli_command_t * cmd)
2098 msg = format (msg, "feature: %U\ngpe: %U\n",
2099 format_lisp_status, format_vnet_lisp_gpe_status);
2100 vlib_cli_output (vm, "%v", msg);
2106 VLIB_CLI_COMMAND (lisp_show_status_command) = {
2107 .path = "show lisp status",
2108 .short_help = "show lisp status",
2109 .function = lisp_show_status_command_fn,
2113 static clib_error_t *
2114 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
2115 unformat_input_t * input,
2116 vlib_cli_command_t * cmd)
2119 unformat_input_t _line_input, *line_input = &_line_input;
2120 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2121 uword *vni_table = 0;
2124 /* Get a line of input. */
2125 if (!unformat_user (input, unformat_line_input, line_input))
2128 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2130 if (unformat (line_input, "l2"))
2132 vni_table = lcm->bd_id_by_vni;
2135 else if (unformat (line_input, "l3"))
2137 vni_table = lcm->table_id_by_vni;
2141 return clib_error_return (0, "parse error: '%U'",
2142 format_unformat_error, line_input);
2147 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
2151 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
2154 hash_foreach_pair (p, vni_table,
2156 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
2164 VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
2165 .path = "show lisp eid-table map",
2166 .short_help = "show lisp eid-table l2|l3",
2167 .function = lisp_show_eid_table_map_command_fn,
2171 static clib_error_t *
2172 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
2173 unformat_input_t * input,
2174 vlib_cli_command_t * cmd)
2176 lisp_gpe_main_t *lgm = &lisp_gpe_main;
2177 vnet_main_t *vnm = lgm->vnet_main;
2178 unformat_input_t _line_input, *line_input = &_line_input;
2180 clib_error_t *error = 0;
2181 u8 *locator_set_name = 0;
2182 locator_t locator, *locators = 0;
2183 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
2187 memset (&locator, 0, sizeof (locator));
2188 memset (a, 0, sizeof (a[0]));
2190 /* Get a line of input. */
2191 if (!unformat_user (input, unformat_line_input, line_input))
2194 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2196 if (unformat (line_input, "add %_%v%_", &locator_set_name))
2198 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
2200 else if (unformat (line_input, "iface %U p %d w %d",
2201 unformat_vnet_sw_interface, vnm,
2202 &locator.sw_if_index, &locator.priority,
2206 vec_add1 (locators, locator);
2210 error = unformat_parse_error (line_input);
2215 a->name = locator_set_name;
2216 a->locators = locators;
2220 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
2223 error = clib_error_return (0, "failed to %s locator-set!",
2224 is_add ? "add" : "delete");
2228 vec_free (locators);
2229 if (locator_set_name)
2230 vec_free (locator_set_name);
2235 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
2236 .path = "lisp locator-set",
2237 .short_help = "lisp locator-set add/del <name> [iface <iface-name> "
2238 "p <priority> w <weight>]",
2239 .function = lisp_add_del_locator_set_command_fn,
2243 static clib_error_t *
2244 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
2245 unformat_input_t * input,
2246 vlib_cli_command_t * cmd)
2248 lisp_gpe_main_t *lgm = &lisp_gpe_main;
2249 vnet_main_t *vnm = lgm->vnet_main;
2250 unformat_input_t _line_input, *line_input = &_line_input;
2252 clib_error_t *error = 0;
2253 u8 *locator_set_name = 0;
2254 u8 locator_set_name_set = 0;
2255 locator_t locator, *locators = 0;
2256 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
2259 memset (&locator, 0, sizeof (locator));
2260 memset (a, 0, sizeof (a[0]));
2262 /* Get a line of input. */
2263 if (!unformat_user (input, unformat_line_input, line_input))
2266 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2268 if (unformat (line_input, "add"))
2270 else if (unformat (line_input, "del"))
2272 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
2273 locator_set_name_set = 1;
2274 else if (unformat (line_input, "iface %U p %d w %d",
2275 unformat_vnet_sw_interface, vnm,
2276 &locator.sw_if_index, &locator.priority,
2280 vec_add1 (locators, locator);
2284 error = unformat_parse_error (line_input);
2289 if (!locator_set_name_set)
2291 error = clib_error_return (0, "locator_set name not set!");
2295 a->name = locator_set_name;
2296 a->locators = locators;
2300 vnet_lisp_add_del_locator (a, 0, &ls_index);
2303 vec_free (locators);
2304 vec_free (locator_set_name);
2309 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = {
2310 .path = "lisp locator",
2311 .short_help = "lisp locator add/del locator-set <name> iface <iface-name> "
2312 "p <priority> w <weight>",
2313 .function = lisp_add_del_locator_in_set_command_fn,
2317 static clib_error_t *
2318 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
2319 unformat_input_t * input,
2320 vlib_cli_command_t * cmd)
2322 locator_set_t *lsit;
2325 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2327 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
2328 "Priority", "Weight");
2331 pool_foreach (lsit, lcm->locator_set_pool,
2337 msg = format (msg, "%v", lsit->name);
2341 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
2343 vec_foreach (locit, lsit->locator_indices)
2347 msg = format (msg, "%16s", " ");
2349 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
2351 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
2354 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
2355 &gid_address_ip(&loc->address), loc->priority,
2359 vlib_cli_output (vm, "%v", msg);
2367 VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
2368 .path = "show lisp locator-set",
2369 .short_help = "Shows locator-sets",
2370 .function = lisp_cp_show_locator_sets_command_fn,
2374 static map_resolver_t *
2375 get_map_resolver (ip_address_t * a)
2377 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2380 vec_foreach (mr, lcm->map_resolvers)
2382 if (!ip_address_cmp (&mr->address, a))
2391 vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a)
2393 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2395 map_resolver_t _mr, *mr = &_mr;
2397 if (vnet_lisp_enable_disable_status () == 0)
2399 clib_warning ("LISP is disabled!");
2400 return VNET_API_ERROR_LISP_DISABLED;
2406 if (get_map_resolver (&a->address))
2408 clib_warning ("map-resolver %U already exists!", format_ip_address,
2413 memset (mr, 0, sizeof (*mr));
2414 ip_address_copy (&mr->address, &a->address);
2415 vec_add1 (lcm->map_resolvers, *mr);
2417 if (vec_len (lcm->map_resolvers) == 1)
2418 lcm->do_map_resolver_election = 1;
2422 for (i = 0; i < vec_len (lcm->map_resolvers); i++)
2424 mr = vec_elt_at_index (lcm->map_resolvers, i);
2425 if (!ip_address_cmp (&mr->address, &a->address))
2427 if (!ip_address_cmp (&mr->address, &lcm->active_map_resolver))
2428 lcm->do_map_resolver_election = 1;
2430 vec_del1 (lcm->map_resolvers, i);
2438 static clib_error_t *
2439 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
2440 unformat_input_t * input,
2441 vlib_cli_command_t * cmd)
2443 unformat_input_t _line_input, *line_input = &_line_input;
2444 u8 is_add = 1, addr_set = 0;
2445 ip_address_t ip_addr;
2446 clib_error_t *error = 0;
2448 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
2450 /* Get a line of input. */
2451 if (!unformat_user (input, unformat_line_input, line_input))
2454 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2456 if (unformat (line_input, "add"))
2458 else if (unformat (line_input, "del"))
2460 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
2464 error = unformat_parse_error (line_input);
2471 error = clib_error_return (0, "Map-resolver address must be set!");
2476 a->address = ip_addr;
2477 rv = vnet_lisp_add_del_map_resolver (a);
2480 error = clib_error_return (0, "failed to %s map-resolver!",
2481 is_add ? "add" : "delete");
2489 VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
2490 .path = "lisp map-resolver",
2491 .short_help = "lisp map-resolver add/del <ip_address>",
2492 .function = lisp_add_del_map_resolver_command_fn,
2497 vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a)
2499 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2502 if (vnet_lisp_enable_disable_status () == 0)
2504 clib_warning ("LISP is disabled!");
2505 return VNET_API_ERROR_LISP_DISABLED;
2510 p = hash_get_mem (lcm->locator_set_index_by_name, a->locator_set_name);
2513 clib_warning ("locator-set %v doesn't exist", a->locator_set_name);
2514 return VNET_API_ERROR_INVALID_ARGUMENT;
2517 lcm->mreq_itr_rlocs = p[0];
2521 lcm->mreq_itr_rlocs = ~0;
2527 static clib_error_t *
2528 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
2529 unformat_input_t * input,
2530 vlib_cli_command_t * cmd)
2532 unformat_input_t _line_input, *line_input = &_line_input;
2534 u8 *locator_set_name = 0;
2535 clib_error_t *error = 0;
2537 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
2539 /* Get a line of input. */
2540 if (!unformat_user (input, unformat_line_input, line_input))
2543 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2545 if (unformat (line_input, "del"))
2547 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
2551 error = unformat_parse_error (line_input);
2557 a->locator_set_name = locator_set_name;
2558 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
2561 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
2562 is_add ? "add" : "delete");
2565 vec_free (locator_set_name);
2573 VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = {
2574 .path = "lisp map-request itr-rlocs",
2575 .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>",
2576 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
2580 static clib_error_t *
2581 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
2582 unformat_input_t * input,
2583 vlib_cli_command_t * cmd)
2585 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2586 locator_set_t *loc_set;
2588 vlib_cli_output (vm, "%=20s", "itr-rlocs");
2590 if (~0 == lcm->mreq_itr_rlocs)
2595 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
2597 vlib_cli_output (vm, "%=20s", loc_set->name);
2603 VLIB_CLI_COMMAND (lisp_show_map_request_command) = {
2604 .path = "show lisp map-request itr-rlocs",
2605 .short_help = "Shows map-request itr-rlocs",
2606 .function = lisp_show_mreq_itr_rlocs_command_fn,
2610 /* Statistics (not really errors) */
2611 #define foreach_lisp_cp_lookup_error \
2613 _(MAP_REQUESTS_SENT, "map-request sent")
2615 static char *lisp_cp_lookup_error_strings[] = {
2616 #define _(sym,string) string,
2617 foreach_lisp_cp_lookup_error
2623 #define _(sym,str) LISP_CP_LOOKUP_ERROR_##sym,
2624 foreach_lisp_cp_lookup_error
2626 LISP_CP_LOOKUP_N_ERROR,
2627 } lisp_cp_lookup_error_t;
2631 LISP_CP_LOOKUP_NEXT_DROP,
2632 LISP_CP_LOOKUP_N_NEXT,
2633 } lisp_cp_lookup_next_t;
2637 gid_address_t dst_eid;
2638 ip_address_t map_resolver_ip;
2639 } lisp_cp_lookup_trace_t;
2642 format_lisp_cp_lookup_trace (u8 * s, va_list * args)
2644 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
2645 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
2646 lisp_cp_lookup_trace_t *t = va_arg (*args, lisp_cp_lookup_trace_t *);
2648 s = format (s, "LISP-CP-LOOKUP: map-resolver: %U destination eid %U",
2649 format_ip_address, &t->map_resolver_ip, format_gid_address,
2655 get_mr_and_local_iface_ip (lisp_cp_main_t * lcm, ip_address_t * mr_ip,
2656 ip_address_t * sloc)
2658 map_resolver_t *mrit;
2661 if (vec_len (lcm->map_resolvers) == 0)
2663 clib_warning ("No map-resolver configured");
2667 /* find the first mr ip we have a route to and the ip of the
2668 * iface that has a route to it */
2669 vec_foreach (mrit, lcm->map_resolvers)
2672 if (0 != ip_fib_get_first_egress_ip_for_dst (lcm, a, sloc))
2674 ip_address_copy (mr_ip, a);
2676 /* also update globals */
2681 clib_warning ("Can't find map-resolver and local interface ip!");
2685 static gid_address_t *
2686 build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set)
2692 ip_interface_address_t *ia = 0;
2693 gid_address_t gid_data, *gid = &gid_data;
2694 gid_address_t *rlocs = 0;
2695 ip_prefix_t *ippref = &gid_address_ippref (gid);
2696 ip_address_t *rloc = &ip_prefix_addr (ippref);
2698 memset (gid, 0, sizeof (gid[0]));
2699 gid_address_type (gid) = GID_ADDR_IP_PREFIX;
2700 for (i = 0; i < vec_len (loc_set->locator_indices); i++)
2702 loc_indexp = vec_elt_at_index (loc_set->locator_indices, i);
2703 loc = pool_elt_at_index (lcm->locator_pool, loc_indexp[0]);
2705 /* Add ipv4 locators first TODO sort them */
2708 foreach_ip_interface_address (&lcm->im4->lookup_main, ia,
2709 loc->sw_if_index, 1 /* unnumbered */,
2711 addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia);
2712 ip_address_set (rloc, addr, IP4);
2713 ip_prefix_len (ippref) = 32;
2714 ip_prefix_normalize (ippref);
2715 vec_add1 (rlocs, gid[0]);
2718 /* Add ipv6 locators */
2719 foreach_ip_interface_address (&lcm->im6->lookup_main, ia,
2720 loc->sw_if_index, 1 /* unnumbered */,
2722 addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia);
2723 ip_address_set (rloc, addr, IP6);
2724 ip_prefix_len (ippref) = 128;
2725 ip_prefix_normalize (ippref);
2726 vec_add1 (rlocs, gid[0]);
2734 static vlib_buffer_t *
2735 build_encapsulated_map_request (lisp_cp_main_t * lcm,
2736 gid_address_t * seid, gid_address_t * deid,
2737 locator_set_t * loc_set, ip_address_t * mr_ip,
2738 ip_address_t * sloc, u8 is_smr_invoked,
2739 u64 * nonce_res, u32 * bi_res)
2743 gid_address_t *rlocs = 0;
2744 vlib_main_t *vm = lcm->vlib_main;
2746 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
2748 clib_warning ("Can't allocate buffer for Map-Request!");
2752 b = vlib_get_buffer (vm, bi);
2754 /* leave some space for the encap headers */
2755 vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN);
2758 rlocs = build_itr_rloc_list (lcm, loc_set);
2760 if (MR_MODE_SRC_DST == lcm->map_request_mode)
2763 memset (&sd, 0, sizeof (sd));
2764 build_src_dst (&sd, seid, deid);
2765 lisp_msg_put_mreq (lcm, b, seid, &sd, rlocs, is_smr_invoked, nonce_res);
2770 lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, is_smr_invoked,
2774 /* push ecm: udp-ip-lisp */
2775 lisp_msg_push_ecm (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, seid, deid);
2777 /* push outer ip header */
2778 pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc,
2788 reset_pending_mr_counters (pending_map_request_t * r)
2790 r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME;
2795 elect_map_resolver (lisp_cp_main_t * lcm)
2799 vec_foreach (mr, lcm->map_resolvers)
2803 ip_address_copy (&lcm->active_map_resolver, &mr->address);
2804 lcm->do_map_resolver_election = 0;
2811 #define send_encapsulated_map_request(lcm, seid, deid, smr) \
2812 _send_encapsulated_map_request(lcm, seid, deid, smr, 0)
2814 #define resend_encapsulated_map_request(lcm, seid, deid, smr) \
2815 _send_encapsulated_map_request(lcm, seid, deid, smr, 1)
2818 _send_encapsulated_map_request (lisp_cp_main_t * lcm,
2819 gid_address_t * seid, gid_address_t * deid,
2820 u8 is_smr_invoked, u8 is_resend)
2823 u32 next_index, bi = 0, *to_next, map_index;
2827 locator_set_t *loc_set;
2829 pending_map_request_t *pmr, *duplicate_pmr = 0;
2833 ASSERT (*lcm->pending_map_request_lock);
2835 /* if there is already a pending request remember it */
2838 pool_foreach(pmr, lcm->pending_map_requests_pool,
2840 if (!gid_address_cmp (&pmr->src, seid)
2841 && !gid_address_cmp (&pmr->dst, deid))
2843 duplicate_pmr = pmr;
2849 if (!is_resend && duplicate_pmr)
2851 /* don't send the request if there is a pending map request already */
2855 /* get locator-set for seid */
2856 if (!lcm->lisp_pitr)
2858 map_index = gid_dictionary_lookup (&lcm->mapping_index_by_gid, seid);
2859 if (map_index == ~0)
2861 clib_warning ("No local mapping found in eid-table for %U!",
2862 format_gid_address, seid);
2866 map = pool_elt_at_index (lcm->mapping_pool, map_index);
2871 ("Mapping found for src eid %U is not marked as local!",
2872 format_gid_address, seid);
2875 ls_index = map->locator_set_index;
2879 map_index = lcm->pitr_map_index;
2880 map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
2881 ls_index = map->locator_set_index;
2884 /* overwrite locator set if map-request itr-rlocs configured */
2885 if (~0 != lcm->mreq_itr_rlocs)
2887 ls_index = lcm->mreq_itr_rlocs;
2890 loc_set = pool_elt_at_index (lcm->locator_set_pool, ls_index);
2892 while (lcm->do_map_resolver_election
2893 | (0 == ip_fib_get_first_egress_ip_for_dst (lcm,
2894 &lcm->active_map_resolver,
2897 if (0 == elect_map_resolver (lcm))
2898 /* all Mrs are down */
2901 duplicate_pmr->to_be_removed = 1;
2903 /* restart MR checking by marking all of them up */
2904 vec_foreach (mr, lcm->map_resolvers) mr->is_down = 0;
2910 /* build the encapsulated map request */
2911 b = build_encapsulated_map_request (lcm, seid, deid, loc_set,
2912 &lcm->active_map_resolver,
2913 &sloc, is_smr_invoked, &nonce, &bi);
2918 /* set fib index to default and lookup node */
2919 vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
2920 next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ?
2921 ip4_lookup_node.index : ip6_lookup_node.index;
2923 f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
2925 /* Enqueue the packet */
2926 to_next = vlib_frame_vector_args (f);
2929 vlib_put_frame_to_node (lcm->vlib_main, next_index, f);
2932 /* if there is a pending request already update it */
2934 if (clib_fifo_elts (duplicate_pmr->nonces) >= PENDING_MREQ_QUEUE_LEN)
2936 /* remove the oldest nonce */
2937 u64 CLIB_UNUSED (tmp), *nonce_del;
2938 nonce_del = clib_fifo_head (duplicate_pmr->nonces);
2939 hash_unset (lcm->pending_map_requests_by_nonce, nonce_del[0]);
2940 clib_fifo_sub1 (duplicate_pmr->nonces, tmp);
2943 clib_fifo_add1 (duplicate_pmr->nonces, nonce);
2944 hash_set (lcm->pending_map_requests_by_nonce, nonce,
2945 duplicate_pmr - lcm->pending_map_requests_pool);
2949 /* add map-request to pending requests table */
2950 pool_get (lcm->pending_map_requests_pool, pmr);
2951 memset (pmr, 0, sizeof (*pmr));
2952 gid_address_copy (&pmr->src, seid);
2953 gid_address_copy (&pmr->dst, deid);
2954 clib_fifo_add1 (pmr->nonces, nonce);
2955 pmr->is_smr_invoked = is_smr_invoked;
2956 reset_pending_mr_counters (pmr);
2957 hash_set (lcm->pending_map_requests_by_nonce, nonce,
2958 pmr - lcm->pending_map_requests_pool);
2965 get_src_and_dst_ip (void *hdr, ip_address_t * src, ip_address_t * dst)
2967 ip4_header_t *ip4 = hdr;
2970 if ((ip4->ip_version_and_header_length & 0xF0) == 0x40)
2972 ip_address_set (src, &ip4->src_address, IP4);
2973 ip_address_set (dst, &ip4->dst_address, IP4);
2978 ip_address_set (src, &ip6->src_address, IP6);
2979 ip_address_set (dst, &ip6->dst_address, IP6);
2984 lisp_get_vni_from_buffer_ip (lisp_cp_main_t * lcm, vlib_buffer_t * b,
2988 u32 vni = ~0, table_id = ~0;
2990 table_id = fib_table_get_table_id_for_sw_if_index ((version ==
2991 IP4 ? FIB_PROTOCOL_IP4 :
2997 vnip = hash_get (lcm->vni_by_table_id, table_id);
3001 clib_warning ("vrf %d is not mapped to any vni!", table_id);
3007 lisp_get_vni_from_buffer_eth (lisp_cp_main_t * lcm, vlib_buffer_t * b)
3013 l2input_main_t *l2im = &l2input_main;
3014 l2_input_config_t *config;
3015 l2_bridge_domain_t *bd_config;
3017 sw_if_index0 = vnet_buffer (b)->sw_if_index[VLIB_RX];
3018 config = vec_elt_at_index (l2im->configs, sw_if_index0);
3019 bd_config = vec_elt_at_index (l2im->bd_configs, config->bd_index);
3021 vnip = hash_get (lcm->vni_by_bd_id, bd_config->bd_id);
3025 clib_warning ("bridge domain %d is not mapped to any vni!",
3032 get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b,
3033 gid_address_t * src, gid_address_t * dst)
3038 memset (src, 0, sizeof (*src));
3039 memset (dst, 0, sizeof (*dst));
3040 type = vnet_buffer (b)->lisp.overlay_afi;
3042 if (LISP_AFI_IP == type || LISP_AFI_IP6 == type)
3045 u8 version, preflen;
3047 gid_address_type (src) = GID_ADDR_IP_PREFIX;
3048 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
3050 ip = vlib_buffer_get_current (b);
3051 get_src_and_dst_ip (ip, &gid_address_ip (src), &gid_address_ip (dst));
3053 version = gid_address_ip_version (src);
3054 preflen = ip_address_max_len (version);
3055 gid_address_ippref_len (src) = preflen;
3056 gid_address_ippref_len (dst) = preflen;
3058 vni = lisp_get_vni_from_buffer_ip (lcm, b, version);
3059 gid_address_vni (dst) = vni;
3060 gid_address_vni (src) = vni;
3062 else if (LISP_AFI_MAC == type)
3064 ethernet_header_t *eh;
3066 eh = vlib_buffer_get_current (b);
3068 gid_address_type (src) = GID_ADDR_MAC;
3069 gid_address_type (dst) = GID_ADDR_MAC;
3070 mac_copy (&gid_address_mac (src), eh->src_address);
3071 mac_copy (&gid_address_mac (dst), eh->dst_address);
3074 vni = lisp_get_vni_from_buffer_eth (lcm, b);
3076 gid_address_vni (dst) = vni;
3077 gid_address_vni (src) = vni;
3082 lisp_cp_lookup_inline (vlib_main_t * vm,
3083 vlib_node_runtime_t * node,
3084 vlib_frame_t * from_frame, int overlay)
3086 u32 *from, *to_next_drop, di, si;
3087 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3088 u32 pkts_mapped = 0;
3089 uword n_left_from, n_left_to_next_drop;
3091 from = vlib_frame_vector_args (from_frame);
3092 n_left_from = from_frame->n_vectors;
3094 while (n_left_from > 0)
3096 vlib_get_next_frame (vm, node, LISP_CP_LOOKUP_NEXT_DROP,
3097 to_next_drop, n_left_to_next_drop);
3099 while (n_left_from > 0 && n_left_to_next_drop > 0)
3103 gid_address_t src, dst;
3108 to_next_drop[0] = pi0;
3110 n_left_to_next_drop -= 1;
3112 b0 = vlib_get_buffer (vm, pi0);
3113 b0->error = node->errors[LISP_CP_LOOKUP_ERROR_DROP];
3114 vnet_buffer (b0)->lisp.overlay_afi = overlay;
3116 /* src/dst eid pair */
3117 get_src_and_dst_eids_from_buffer (lcm, b0, &src, &dst);
3119 /* if we have remote mapping for destination already in map-chache
3120 add forwarding tunnel directly. If not send a map-request */
3121 di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst,
3125 mapping_t *m = vec_elt_at_index (lcm->mapping_pool, di);
3126 /* send a map-request also in case of negative mapping entry
3127 with corresponding action */
3128 if (m->action == LISP_SEND_MAP_REQUEST)
3130 /* send map-request */
3131 queue_map_request (&src, &dst, 0 /* smr_invoked */ ,
3132 0 /* is_resend */ );
3137 si = gid_dictionary_lookup (&lcm->mapping_index_by_gid,
3141 dp_add_fwd_entry (lcm, si, di);
3147 /* send map-request */
3148 queue_map_request (&src, &dst, 0 /* smr_invoked */ ,
3149 0 /* is_resend */ );
3153 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
3155 lisp_cp_lookup_trace_t *tr = vlib_add_trace (vm, node, b0,
3158 memset (tr, 0, sizeof (*tr));
3159 gid_address_copy (&tr->dst_eid, &dst);
3160 ip_address_copy (&tr->map_resolver_ip,
3161 &lcm->active_map_resolver);
3163 gid_address_free (&dst);
3164 gid_address_free (&src);
3167 vlib_put_next_frame (vm, node, LISP_CP_LOOKUP_NEXT_DROP,
3168 n_left_to_next_drop);
3170 vlib_node_increment_counter (vm, node->node_index,
3171 LISP_CP_LOOKUP_ERROR_MAP_REQUESTS_SENT,
3173 return from_frame->n_vectors;
3177 lisp_cp_lookup_ip4 (vlib_main_t * vm,
3178 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3180 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP));
3184 lisp_cp_lookup_ip6 (vlib_main_t * vm,
3185 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3187 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP6));
3191 lisp_cp_lookup_l2 (vlib_main_t * vm,
3192 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
3194 return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_MAC));
3198 VLIB_REGISTER_NODE (lisp_cp_lookup_ip4_node) = {
3199 .function = lisp_cp_lookup_ip4,
3200 .name = "lisp-cp-lookup-ip4",
3201 .vector_size = sizeof (u32),
3202 .format_trace = format_lisp_cp_lookup_trace,
3203 .type = VLIB_NODE_TYPE_INTERNAL,
3205 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3206 .error_strings = lisp_cp_lookup_error_strings,
3208 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3211 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3217 VLIB_REGISTER_NODE (lisp_cp_lookup_ip6_node) = {
3218 .function = lisp_cp_lookup_ip6,
3219 .name = "lisp-cp-lookup-ip6",
3220 .vector_size = sizeof (u32),
3221 .format_trace = format_lisp_cp_lookup_trace,
3222 .type = VLIB_NODE_TYPE_INTERNAL,
3224 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3225 .error_strings = lisp_cp_lookup_error_strings,
3227 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3230 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3236 VLIB_REGISTER_NODE (lisp_cp_lookup_l2_node) = {
3237 .function = lisp_cp_lookup_l2,
3238 .name = "lisp-cp-lookup-l2",
3239 .vector_size = sizeof (u32),
3240 .format_trace = format_lisp_cp_lookup_trace,
3241 .type = VLIB_NODE_TYPE_INTERNAL,
3243 .n_errors = LISP_CP_LOOKUP_N_ERROR,
3244 .error_strings = lisp_cp_lookup_error_strings,
3246 .n_next_nodes = LISP_CP_LOOKUP_N_NEXT,
3249 [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop",
3254 /* lisp_cp_input statistics */
3255 #define foreach_lisp_cp_input_error \
3257 _(MAP_REPLIES_RECEIVED, "map-replies received")
3259 static char *lisp_cp_input_error_strings[] = {
3260 #define _(sym,string) string,
3261 foreach_lisp_cp_input_error
3267 #define _(sym,str) LISP_CP_INPUT_ERROR_##sym,
3268 foreach_lisp_cp_input_error
3270 LISP_CP_INPUT_N_ERROR,
3271 } lisp_cp_input_error_t;
3275 LISP_CP_INPUT_NEXT_DROP,
3276 LISP_CP_INPUT_N_NEXT,
3277 } lisp_cp_input_next_t;
3281 gid_address_t dst_eid;
3282 ip4_address_t map_resolver_ip;
3283 } lisp_cp_input_trace_t;
3286 format_lisp_cp_input_trace (u8 * s, va_list * args)
3288 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
3289 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
3290 CLIB_UNUSED (lisp_cp_input_trace_t * t) =
3291 va_arg (*args, lisp_cp_input_trace_t *);
3293 s = format (s, "LISP-CP-INPUT: TODO");
3298 process_map_reply (void *arg)
3300 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3301 vlib_buffer_t *b = arg;
3302 u32 len = 0, i, ttl, dst_map_index = 0;
3304 pending_map_request_t *pmr;
3306 map_reply_hdr_t *mrep_hdr;
3310 u8 authoritative, action;
3311 locator_t *locators = 0, *loc;
3313 mrep_hdr = vlib_buffer_get_current (b);
3315 lisp_pending_map_request_lock (lcm);
3317 /* Check pending requests table and nonce */
3318 nonce = MREP_NONCE (mrep_hdr);
3319 pmr_index = hash_get (lcm->pending_map_requests_by_nonce, nonce);
3322 clib_warning ("No pending map-request entry with nonce %lu!", nonce);
3325 pmr = pool_elt_at_index (lcm->pending_map_requests_pool, pmr_index[0]);
3327 vlib_buffer_pull (b, sizeof (*mrep_hdr));
3329 for (i = 0; i < MREP_REC_COUNT (mrep_hdr); i++)
3331 h = vlib_buffer_get_current (b);
3332 ttl = clib_net_to_host_u32 (MAP_REC_TTL (h));
3333 action = MAP_REC_ACTION (h);
3334 authoritative = MAP_REC_AUTH (h);
3336 len = lisp_msg_parse_mapping_record (b, &deid, &locators, &probed);
3339 clib_warning ("Failed to parse mapping record!");
3340 vec_foreach (loc, locators)
3344 vec_free (locators);
3348 /* insert/update mappings cache */
3349 vnet_lisp_add_del_mapping (&deid, locators, action, authoritative, ttl,
3350 1, 0 /* is_static */ , &dst_map_index);
3352 /* try to program forwarding only if mapping saved or updated */
3353 if ((u32) ~ 0 != dst_map_index)
3354 lisp_add_del_adjacency (lcm, &pmr->src, &deid, 1);
3356 vec_free (locators);
3359 /* remove pending map request entry */
3362 clib_fifo_foreach (noncep, pmr->nonces, ({
3363 hash_unset(lcm->pending_map_requests_by_nonce, noncep[0]);
3367 clib_fifo_free (pmr->nonces);
3368 pool_put (lcm->pending_map_requests_pool, pmr);
3371 lisp_pending_map_request_unlock (lcm);
3376 process_map_request (vlib_main_t * vm, lisp_cp_main_t * lcm,
3379 map_request_hdr_t *mreq_hdr;
3380 gid_address_t src, dst;
3383 gid_address_t *itr_rlocs = 0, *rloc;
3385 mreq_hdr = vlib_buffer_get_current (b);
3386 vlib_buffer_pull (b, sizeof (*mreq_hdr));
3388 // nonce = MREQ_NONCE(mreq_hdr);
3390 if (!MREQ_SMR (mreq_hdr))
3392 clib_warning ("Only SMR Map-Requests supported for now!");
3397 len = lisp_msg_parse_addr (b, &src);
3401 /* for now we don't do anything with the itr's rlocs */
3403 lisp_msg_parse_itr_rlocs (b, &itr_rlocs,
3404 MREQ_ITR_RLOC_COUNT (mreq_hdr) + 1);
3408 /* TODO: RLOCs are currently unused, so free them for now */
3409 vec_foreach (rloc, itr_rlocs)
3411 gid_address_free (rloc);
3414 /* parse eid records and send SMR-invoked map-requests */
3415 for (i = 0; i < MREQ_REC_COUNT (mreq_hdr); i++)
3417 memset (&dst, 0, sizeof (dst));
3418 len = lisp_msg_parse_eid_rec (b, &dst);
3421 clib_warning ("Can't parse map-request EID-record");
3424 /* send SMR-invoked map-requests */
3425 queue_map_request (&dst, &src, 1 /* invoked */ , 0 /* resend */ );
3430 queue_map_reply (vlib_buffer_t * b)
3432 vlib_buffer_t *a = clib_mem_alloc (sizeof (a[0]) + b->current_length);
3434 clib_memcpy (a->data, b->data + b->current_data, b->current_length);
3435 a->current_length = b->current_length;
3436 a->current_data = 0;
3438 vl_api_rpc_call_main_thread (process_map_reply, (u8 *) a, sizeof (a[0])
3439 + a->current_length);
3444 lisp_cp_input (vlib_main_t * vm, vlib_node_runtime_t * node,
3445 vlib_frame_t * from_frame)
3447 u32 n_left_from, *from, *to_next_drop;
3448 lisp_msg_type_e type;
3449 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3451 from = vlib_frame_vector_args (from_frame);
3452 n_left_from = from_frame->n_vectors;
3455 while (n_left_from > 0)
3457 u32 n_left_to_next_drop;
3459 vlib_get_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP,
3460 to_next_drop, n_left_to_next_drop);
3461 while (n_left_from > 0 && n_left_to_next_drop > 0)
3469 to_next_drop[0] = bi0;
3471 n_left_to_next_drop -= 1;
3473 b0 = vlib_get_buffer (vm, bi0);
3475 type = lisp_msg_type (vlib_buffer_get_current (b0));
3478 case LISP_MAP_REPLY:
3479 queue_map_reply (b0);
3481 case LISP_MAP_REQUEST:
3482 process_map_request (vm, lcm, b0);
3485 clib_warning ("Unsupported LISP message type %d", type);
3489 b0->error = node->errors[LISP_CP_INPUT_ERROR_DROP];
3491 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
3497 vlib_put_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP,
3498 n_left_to_next_drop);
3500 return from_frame->n_vectors;
3504 VLIB_REGISTER_NODE (lisp_cp_input_node) = {
3505 .function = lisp_cp_input,
3506 .name = "lisp-cp-input",
3507 .vector_size = sizeof (u32),
3508 .format_trace = format_lisp_cp_input_trace,
3509 .type = VLIB_NODE_TYPE_INTERNAL,
3511 .n_errors = LISP_CP_INPUT_N_ERROR,
3512 .error_strings = lisp_cp_input_error_strings,
3514 .n_next_nodes = LISP_CP_INPUT_N_NEXT,
3517 [LISP_CP_INPUT_NEXT_DROP] = "error-drop",
3523 lisp_cp_init (vlib_main_t * vm)
3525 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3526 clib_error_t *error = 0;
3528 if ((error = vlib_call_init_function (vm, lisp_gpe_init)))
3531 lcm->im4 = &ip4_main;
3532 lcm->im6 = &ip6_main;
3533 lcm->vlib_main = vm;
3534 lcm->vnet_main = vnet_get_main ();
3535 lcm->mreq_itr_rlocs = ~0;
3537 memset (&lcm->active_map_resolver, 0, sizeof (lcm->active_map_resolver));
3539 lcm->pending_map_request_lock =
3540 clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);
3542 lcm->pending_map_request_lock[0] = 0;
3543 gid_dictionary_init (&lcm->mapping_index_by_gid);
3544 lcm->do_map_resolver_election = 1;
3545 lcm->map_request_mode = MR_MODE_DST_ONLY;
3547 /* default vrf mapped to vni 0 */
3548 hash_set (lcm->table_id_by_vni, 0, 0);
3549 hash_set (lcm->vni_by_table_id, 0, 0);
3551 udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp,
3552 lisp_cp_input_node.index, 1 /* is_ip4 */ );
3553 udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp6,
3554 lisp_cp_input_node.index, 0 /* is_ip4 */ );
3560 send_map_request_thread_fn (void *arg)
3562 map_request_args_t *a = arg;
3563 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3566 /* if resending, we already have the lock */
3567 resend_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked);
3570 /* get lock before sending map-request */
3571 lisp_pending_map_request_lock (lcm);
3572 send_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked);
3573 lisp_pending_map_request_unlock (lcm);
3581 queue_map_request (gid_address_t * seid, gid_address_t * deid,
3582 u8 smr_invoked, u8 is_resend)
3584 map_request_args_t a;
3586 a.is_resend = is_resend;
3587 gid_address_copy (&a.seid, seid);
3588 gid_address_copy (&a.deid, deid);
3589 a.smr_invoked = smr_invoked;
3591 vl_api_rpc_call_main_thread (send_map_request_thread_fn,
3592 (u8 *) & a, sizeof (a));
3597 * Take an action with a pending map request depending on expiration time
3598 * and re-try counters.
3601 update_pending_request (pending_map_request_t * r, f64 dt)
3603 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3606 if (r->time_to_expire - dt < 0)
3607 /* it's time to decide what to do with this pending request */
3609 if (r->retries_num >= NUMBER_OF_RETRIES)
3610 /* too many retries -> assume current map resolver is not available */
3612 mr = get_map_resolver (&lcm->active_map_resolver);
3615 clib_warning ("Map resolver %U not found - probably deleted "
3616 "by the user recently.", format_ip_address,
3617 &lcm->active_map_resolver);
3621 clib_warning ("map resolver %U is unreachable, ignoring",
3622 format_ip_address, &lcm->active_map_resolver);
3624 /* mark current map resolver unavailable so it won't be
3625 * selected next time */
3627 mr->last_update = vlib_time_now (lcm->vlib_main);
3630 reset_pending_mr_counters (r);
3631 elect_map_resolver (lcm);
3633 /* try to find a next eligible map resolver and re-send */
3634 queue_map_request (&r->src, &r->dst, r->is_smr_invoked,
3640 queue_map_request (&r->src, &r->dst, r->is_smr_invoked,
3643 r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME;
3647 r->time_to_expire -= dt;
3651 remove_dead_pending_map_requests (lisp_cp_main_t * lcm)
3654 pending_map_request_t *pmr;
3655 u32 *to_be_removed = 0, *pmr_index;
3657 ASSERT (*lcm->pending_map_request_lock);
3660 pool_foreach (pmr, lcm->pending_map_requests_pool,
3662 if (pmr->to_be_removed)
3664 clib_fifo_foreach (nonce, pmr->nonces, ({
3665 hash_unset (lcm->pending_map_requests_by_nonce, nonce[0]);
3668 vec_add1 (to_be_removed, pmr - lcm->pending_map_requests_pool);
3673 vec_foreach (pmr_index, to_be_removed)
3674 pool_put_index (lcm->pending_map_requests_by_nonce, pmr_index[0]);
3676 vec_free (to_be_removed);
3680 send_map_resolver_service (vlib_main_t * vm,
3681 vlib_node_runtime_t * rt, vlib_frame_t * f)
3684 pending_map_request_t *pmr;
3685 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
3689 vlib_process_wait_for_event_or_clock (vm, period);
3691 /* currently no signals are expected - just wait for clock */
3692 (void) vlib_process_get_events (vm, 0);
3694 lisp_pending_map_request_lock (lcm);
3697 pool_foreach (pmr, lcm->pending_map_requests_pool,
3699 if (!pmr->to_be_removed)
3700 update_pending_request (pmr, period);
3704 remove_dead_pending_map_requests (lcm);
3706 lisp_pending_map_request_unlock (lcm);
3714 VLIB_REGISTER_NODE (lisp_retry_service_node,static) = {
3715 .function = send_map_resolver_service,
3716 .type = VLIB_NODE_TYPE_PROCESS,
3717 .name = "lisp-retry-service",
3718 .process_log2_n_stack_bytes = 16,
3722 VLIB_INIT_FUNCTION (lisp_cp_init);
3725 * fd.io coding-style-patch-verification: ON
3728 * eval: (c-set-style "gnu")