lldp: set interface MAC address when enabled

Type: improvement
Change-Id: I4f2dc4e4c1c467fb9acd0fed231c56fcd54c8da9
Signed-off-by: Klement Sekera <ksekera@cisco.com>
This commit is contained in:
Klement Sekera
2020-10-02 14:12:37 +00:00
committed by Damjan Marion
parent 1c556d19d0
commit 149fd3fbd0
3 changed files with 28 additions and 10 deletions

View File

@ -24,11 +24,13 @@ typedef enum lldp_cfg_err
lldp_ok, lldp_ok,
lldp_not_supported, lldp_not_supported,
lldp_invalid_arg, lldp_invalid_arg,
lldp_internal_error,
} lldp_cfg_err_t; } lldp_cfg_err_t;
lldp_cfg_err_t lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, 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); u8 **mgmt_ip4, u8 **mgmt_ip6, u8 **mgmt_oid, int enable);
lldp_cfg_err_t lldp_cfg_set (u8 ** host, int hold_time, int tx_interval); lldp_cfg_err_t lldp_cfg_set (u8 ** host, int hold_time, int tx_interval);
extern const u8 lldp_mac_addr[6];
#endif /* __included_lldp_h__ */ #endif /* __included_lldp_h__ */

View File

@ -39,6 +39,8 @@ lldp_cfg_err_to_clib_err (lldp_cfg_err_t e)
return clib_error_return (0, "not supported"); return clib_error_return (0, "not supported");
case lldp_invalid_arg: case lldp_invalid_arg:
return clib_error_return (0, "invalid argument"); return clib_error_return (0, "invalid argument");
case lldp_internal_error:
return clib_error_return (0, "internal error");
} }
return 0; return 0;
} }
@ -99,6 +101,13 @@ lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, u8 ** mgmt_ip4,
*mgmt_oid = NULL; *mgmt_oid = NULL;
} }
if (!vnet_hw_interface_add_del_mac_address (lm->vnet_main, hw_if_index,
lldp_mac_addr,
1 /* is_add */ ))
{
return lldp_internal_error;
}
const vnet_sw_interface_t *sw = const vnet_sw_interface_t *sw =
vnet_get_sw_interface (lm->vnet_main, hi->sw_if_index); vnet_get_sw_interface (lm->vnet_main, hi->sw_if_index);
if (sw->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP)) if (sw->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP))
@ -110,6 +119,12 @@ 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_intf_t *n = lldp_get_intf (lm, hi->sw_if_index);
lldp_delete_intf (lm, n); lldp_delete_intf (lm, n);
if (n)
{
vnet_hw_interface_add_del_mac_address (lm->vnet_main, hw_if_index,
lldp_mac_addr,
0 /* is_add */ );
}
} }
return lldp_ok; return lldp_ok;

View File

@ -263,6 +263,11 @@ lldp_delete_intf (lldp_main_t * lm, lldp_intf_t * n)
} }
} }
/* 01:80:C2:00:00:0E - propagation constrained to a single
* physical link - stopped by all type of bridge */
const u8 lldp_mac_addr[6] = { 0x01, 0x80, 0xC3, 0x00, 0x00, 0x0E };
static clib_error_t * static clib_error_t *
lldp_template_init (vlib_main_t * vm) lldp_template_init (vlib_main_t * vm)
{ {
@ -274,16 +279,12 @@ lldp_template_init (vlib_main_t * vm)
clib_memset (&h, 0, sizeof (h)); clib_memset (&h, 0, sizeof (h));
/* h.dst_address[0] = lldp_mac_addr[0];
* Send to 01:80:C2:00:00:0E - propagation constrained to a single h.dst_address[1] = lldp_mac_addr[1];
* physical link - stopped by all type of bridge h.dst_address[2] = lldp_mac_addr[2];
*/ h.dst_address[3] = lldp_mac_addr[3];
h.dst_address[0] = 0x01; h.dst_address[4] = lldp_mac_addr[4];
h.dst_address[1] = 0x80; h.dst_address[5] = lldp_mac_addr[5];
h.dst_address[2] = 0xC2;
/* h.dst_address[3] = 0x00; (clib_memset) */
/* h.dst_address[4] = 0x00; (clib_memset) */
h.dst_address[5] = 0x0E;
/* leave src address blank (fill in at send time) */ /* leave src address blank (fill in at send time) */