L2-fib-dump: send 1 or 0 rather than flag value
[vpp.git] / src / vnet / l2 / l2_api.c
index be3b75e..3a37938 100644 (file)
@@ -63,6 +63,7 @@ _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge)       \
 _(L2_PATCH_ADD_DEL, l2_patch_add_del)                          \
 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter)             \
 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del)                         \
+_(BD_IP_MAC_DUMP, bd_ip_mac_dump)                              \
 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del)                 \
 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump)                       \
 _(BRIDGE_FLAGS, bridge_flags)                                   \
@@ -141,9 +142,9 @@ send_l2fib_table_entry (vpe_api_main_t * am,
 
   clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
   mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
-  mp->static_mac = l2fe_res->fields.static_mac;
-  mp->filter_mac = l2fe_res->fields.filter;
-  mp->bvi_mac = l2fe_res->fields.bvi;
+  mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
+  mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
+  mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
   mp->context = context;
 
   vl_api_send_msg (reg, (u8 *) mp);
@@ -214,6 +215,7 @@ vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
        l2fib_add_filter_entry (mac, bd_index);
       else
        {
+         l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE;
          u32 sw_if_index = ntohl (mp->sw_if_index);
          VALIDATE_SW_IF_INDEX (mp);
          if (vec_len (l2im->configs) <= sw_if_index)
@@ -231,10 +233,11 @@ vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
                  goto bad_sw_if_index;
                }
            }
-         u8 static_mac = mp->static_mac ? 1 : 0;
-         u8 bvi_mac = mp->bvi_mac ? 1 : 0;
-         l2fib_add_fwd_entry (mac, bd_index, sw_if_index, static_mac,
-                              bvi_mac);
+         if (mp->static_mac)
+           flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
+         if (mp->bvi_mac)
+           flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
+         l2fib_add_entry (mac, bd_index, sw_if_index, flags);
        }
     }
   else
@@ -701,6 +704,86 @@ static void
   REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
 }
 
+static void
+send_bd_ip_mac_entry (vpe_api_main_t * am,
+                     vl_api_registration_t * reg,
+                     u32 bd_id, u8 is_ipv6,
+                     u8 * ip_address, u8 * mac_address, u32 context)
+{
+  vl_api_bd_ip_mac_details_t *mp;
+
+  mp = vl_msg_api_alloc (sizeof (*mp));
+  memset (mp, 0, sizeof (*mp));
+  mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
+
+  mp->bd_id = ntohl (bd_id);
+
+  clib_memcpy (mp->mac_address, mac_address, 6);
+  mp->is_ipv6 = is_ipv6;
+  clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
+  mp->context = context;
+
+  vl_api_send_msg (reg, (u8 *) mp);
+}
+
+static void
+vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
+{
+  vpe_api_main_t *am = &vpe_api_main;
+  bd_main_t *bdm = &bd_main;
+  l2_bridge_domain_t *bd_config;
+  u32 bd_id = ntohl (mp->bd_id);
+  u32 bd_index, start, end;
+  vl_api_registration_t *reg;
+  uword *p;
+
+  reg = vl_api_client_index_to_registration (mp->client_index);
+  if (!reg)
+    return;
+
+  /* see bd_id: ~0 means "any" */
+  if (bd_id == ~0)
+    {
+      start = 1;
+      end = vec_len (l2input_main.bd_configs);
+    }
+  else
+    {
+      p = hash_get (bdm->bd_index_by_bd_id, bd_id);
+      if (p == 0)
+       return;
+
+      bd_index = p[0];
+      vec_validate (l2input_main.bd_configs, bd_index);
+      start = bd_index;
+      end = start + 1;
+    }
+
+  for (bd_index = start; bd_index < end; bd_index++)
+    {
+      bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
+      if (bd_is_valid (bd_config))
+       {
+         ip4_address_t ip4_addr;
+         ip6_address_t *ip6_addr;
+         u64 mac_addr;
+         bd_id = bd_config->bd_id;
+
+         /* *INDENT-OFF* */
+         hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4,
+         ({
+            send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context);
+         }));
+
+         hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
+         ({
+            send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context);
+         }));
+         /* *INDENT-ON* */
+       }
+    }
+}
+
 static void
 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
 {