+static int
+add_l2_arp_bd (BVT (clib_bihash_kv) * kvp, void *arg)
+{
+ u32 **ht = arg;
+ u32 version = (u32) kvp->key[0];
+ if (AF_IP6 == version)
+ return (BIHASH_WALK_CONTINUE);
+
+ u32 bd = (u32) (kvp->key[0] >> 32);
+ hash_set (ht[0], bd, 0);
+ return (BIHASH_WALK_CONTINUE);
+}
+
+u32 *
+vnet_lisp_l2_arp_bds_get (void)
+{
+ lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+ u32 *bds = 0;
+
+ gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid,
+ add_l2_arp_bd, &bds);
+ return bds;
+}
+
+static int
+add_ndp_bd (BVT (clib_bihash_kv) * kvp, void *arg)
+{
+ u32 **ht = arg;
+ u32 version = (u32) kvp->key[0];
+ if (AF_IP4 == version)
+ return (BIHASH_WALK_CONTINUE);
+
+ u32 bd = (u32) (kvp->key[0] >> 32);
+ hash_set (ht[0], bd, 0);
+ return (BIHASH_WALK_CONTINUE);
+}
+
+u32 *
+vnet_lisp_ndp_bds_get (void)
+{
+ lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+ u32 *bds = 0;
+
+ gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid,
+ add_ndp_bd, &bds);
+ return bds;
+}
+
+typedef struct
+{
+ void *vector;
+ u32 bd;
+} lisp_add_l2_arp_ndp_args_t;
+
+static int
+add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
+{
+ lisp_add_l2_arp_ndp_args_t *a = arg;
+ lisp_api_l2_arp_entry_t **vector = a->vector, e;
+
+ u32 version = (u32) kvp->key[0];
+ if (AF_IP6 == version)
+ return (BIHASH_WALK_CONTINUE);
+
+ u32 bd = (u32) (kvp->key[0] >> 32);
+
+ if (bd == a->bd)
+ {
+ mac_copy (e.mac, (void *) &kvp->value);
+ e.ip4 = (u32) kvp->key[1];
+ vec_add1 (vector[0], e);
+ }
+ return (BIHASH_WALK_CONTINUE);
+}
+
+lisp_api_l2_arp_entry_t *
+vnet_lisp_l2_arp_entries_get_by_bd (u32 bd)
+{
+ lisp_api_l2_arp_entry_t *entries = 0;
+ lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+ lisp_add_l2_arp_ndp_args_t a;
+
+ a.vector = &entries;
+ a.bd = bd;
+
+ gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid,
+ add_l2_arp_entry, &a);
+ return entries;
+}
+
+static int
+add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
+{
+ lisp_add_l2_arp_ndp_args_t *a = arg;
+ lisp_api_ndp_entry_t **vector = a->vector, e;
+
+ u32 version = (u32) kvp->key[0];
+ if (AF_IP4 == version)
+ return (BIHASH_WALK_CONTINUE);
+
+ u32 bd = (u32) (kvp->key[0] >> 32);
+
+ if (bd == a->bd)
+ {
+ mac_copy (e.mac, (void *) &kvp->value);
+ clib_memcpy (e.ip6, &kvp->key[1], 16);
+ vec_add1 (vector[0], e);
+ }
+ return (BIHASH_WALK_CONTINUE);
+}
+
+lisp_api_ndp_entry_t *
+vnet_lisp_ndp_entries_get_by_bd (u32 bd)
+{
+ lisp_api_ndp_entry_t *entries = 0;
+ lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+ lisp_add_l2_arp_ndp_args_t a;
+
+ a.vector = &entries;
+ a.bd = bd;
+
+ gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid,
+ add_ndp_entry, &a);
+ return entries;
+}
+
+int
+vnet_lisp_add_del_l2_arp_ndp_entry (gid_address_t * key, u8 * mac, u8 is_add)
+{
+ if (vnet_lisp_enable_disable_status () == 0)
+ {
+ clib_warning ("LISP is disabled!");
+ return VNET_API_ERROR_LISP_DISABLED;
+ }
+
+ lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+ int rc = 0;
+
+ u64 res = gid_dictionary_lookup (&lcm->mapping_index_by_gid, key);
+ if (is_add)
+ {
+ if (res != GID_LOOKUP_MISS_L2)
+ {
+ clib_warning ("Entry %U exists in DB!", format_gid_address, key);
+ return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
+ }
+ u64 val = mac_to_u64 (mac);
+ gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, val,
+ 1 /* is_add */ );
+ }
+ else
+ {
+ if (res == GID_LOOKUP_MISS_L2)
+ {
+ clib_warning ("ONE entry %U not found - cannot delete!",
+ format_gid_address, key);
+ return -1;
+ }
+ gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, 0,
+ 0 /* is_add */ );
+ }
+
+ return rc;
+}
+