vrrp: fix vrrp_garp_or_na_send()'s memory leak
[vpp.git] / src / plugins / lldp / lldp_cli.c
index 0d196f4..1ed3efa 100644 (file)
@@ -39,6 +39,8 @@ lldp_cfg_err_to_clib_err (lldp_cfg_err_t e)
       return clib_error_return (0, "not supported");
     case lldp_invalid_arg:
       return clib_error_return (0, "invalid argument");
+    case lldp_internal_error:
+      return clib_error_return (0, "internal error");
     }
   return 0;
 }
@@ -47,6 +49,7 @@ lldp_cfg_err_t
 lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
                   u8 ** mgmt_ip6, u8 ** mgmt_oid, int enable)
 {
+  clib_error_t *error = 0;
   lldp_main_t *lm = &lldp_main;
   vnet_main_t *vnm = lm->vnet_main;
   ethernet_main_t *em = &ethernet_main;
@@ -99,6 +102,22 @@ lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
          *mgmt_oid = NULL;
        }
 
+      /* Add MAC address to an interface's filter */
+      if (hi->caps & VNET_HW_IF_CAP_MAC_FILTER)
+       {
+         error =
+           vnet_hw_interface_add_del_mac_address (lm->vnet_main,
+                                                  hw_if_index,
+                                                  lldp_mac_addr,
+                                                  1 /* is_add */ );
+         if (error)
+           {
+             clib_error_free (error);
+             lldp_delete_intf (lm, n);
+             return lldp_internal_error;
+           }
+       }
+
       const vnet_sw_interface_t *sw =
        vnet_get_sw_interface (lm->vnet_main, hi->sw_if_index);
       if (sw->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP))
@@ -110,6 +129,19 @@ lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
     {
       lldp_intf_t *n = lldp_get_intf (lm, hi->sw_if_index);
       lldp_delete_intf (lm, n);
+      /* Remove MAC address from the interface's filter */
+      if ((n) && (hi->caps & VNET_HW_IF_CAP_MAC_FILTER))
+       {
+         error =
+           vnet_hw_interface_add_del_mac_address (lm->vnet_main,
+                                                  hw_if_index,
+                                                  lldp_mac_addr,
+                                                  0 /* is_add */ );
+         if (error)
+           {
+             clib_error_free (error);
+           }
+       }
     }
 
   return lldp_ok;
@@ -143,13 +175,13 @@ lldp_intf_cmd (vlib_main_t * vm, unformat_input_t * input,
        if (unformat (input, "mgmt-ip4 %U", unformat_ip4_address, &ip4_addr))
        {
          vec_validate (mgmt_ip4, sizeof (ip4_address_t) - 1);
-         clib_memcpy (mgmt_ip4, &ip4_addr, vec_len (mgmt_ip4));
+         clib_memcpy (mgmt_ip4, &ip4_addr, sizeof (ip4_addr));
        }
       else
        if (unformat (input, "mgmt-ip6 %U", unformat_ip6_address, &ip6_addr))
        {
          vec_validate (mgmt_ip6, sizeof (ip6_address_t) - 1);
-         clib_memcpy (mgmt_ip6, &ip6_addr, vec_len (mgmt_ip6));
+         clib_memcpy (mgmt_ip6, &ip6_addr, sizeof (ip6_addr));
        }
       else if (unformat (input, "mgmt-oid %s", &mgmt_oid))
        ;
@@ -266,7 +298,6 @@ out:
   return ret;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND(set_interface_lldp_cmd, static) = {
   .path = "set interface lldp",
   .short_help = "set interface lldp <interface> | sw_if_index <idx>"
@@ -281,7 +312,6 @@ VLIB_CLI_COMMAND(set_lldp_cmd, static) = {
                 "[tx-interval <value>]",
   .function = lldp_cfg_cmd,
 };
-/* *INDENT-ON* */
 
 static const char *
 lldp_chassis_id_subtype_str (lldp_chassis_id_subtype_t t)
@@ -548,9 +578,8 @@ format_lldp_intfs_detail (u8 * s, vlib_main_t * vm, const lldp_main_t * lm)
   s = format (s, "\nLLDP-enabled interface table:\n");
   f64 now = vlib_time_now (vm);
 
-  /* *INDENT-OFF* */
-  pool_foreach(
-      n, lm->intfs, ({
+  pool_foreach (
+      n, lm->intfs)  {
         hw = vnet_get_hw_interface(vnm, n->hw_if_index);
         sw = vnet_get_sw_interface(lm->vnet_main, hw->sw_if_index);
 
@@ -607,8 +636,7 @@ format_lldp_intfs_detail (u8 * s, vlib_main_t * vm, const lldp_main_t * lm)
                        vec_len(n->port_id), 1, format_time_ago, n->last_sent,
                        now, format_time_ago, n->last_heard, now);
           }
-      }));
-  /* *INDENT-ON* */
+      }
   return s;
 }
 
@@ -631,9 +659,8 @@ format_lldp_intfs (u8 * s, va_list * va)
              "Peer chassis ID", "Remote port ID", "Last heard", "Last sent",
              "Status");
 
-  /* *INDENT-OFF* */
-  pool_foreach(
-      n, lm->intfs, ({
+  pool_foreach (
+      n, lm->intfs)  {
         const vnet_hw_interface_t *hw =
             vnet_get_hw_interface(vnm, n->hw_if_index);
         const vnet_sw_interface_t *sw =
@@ -656,8 +683,7 @@ format_lldp_intfs (u8 * s, va_list * va)
                        "", "", format_time_ago, n->last_heard, now,
                        format_time_ago, n->last_sent, now, "inactive");
           }
-      }));
-  /* *INDENT-ON* */
+      }
   return s;
 }
 
@@ -678,13 +704,11 @@ show_lldp (vlib_main_t * vm, unformat_input_t * input,
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND(show_lldp_command, static) = {
   .path = "show lldp",
   .short_help = "show lldp [detail]",
   .function = show_lldp,
 };
-/* *INDENT-ON* */
 
 /*
  * packet trace format function, very similar to