From e26c81fc80d1ce9a8746ebf4009149849b04f60f Mon Sep 17 00:00:00 2001 From: John Lo Date: Mon, 7 Jan 2019 15:16:33 -0500 Subject: L2 BD API to flush all IP-MAC entries in the specified BD Implement API/CLI to clear IP-MAC tables used for ARP-termination in the specified bridge domain. The CLI to flush MAC IP tables for a BD is: set bridge-domain arp entry del-all The API added is bd_ip_mac_flush. Change-Id: I34ceb87c0f480c7102f6559312c24081ed485af8 Signed-off-by: John Lo --- src/vnet/l2/l2_bd.c | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'src/vnet/l2/l2_bd.c') diff --git a/src/vnet/l2/l2_bd.c b/src/vnet/l2/l2_bd.c index 943385ccb7c..4dd359ed0b7 100644 --- a/src/vnet/l2/l2_bd.c +++ b/src/vnet/l2/l2_bd.c @@ -91,13 +91,27 @@ bd_add_bd_index (bd_main_t * bdm, u32 bd_id) return rv; } +static inline void +bd_free_ip_mac_tables (l2_bridge_domain_t * bd) +{ + u64 mac_addr; + ip6_address_t *ip6_addr_key; + + hash_free (bd->mac_by_ip4); + /* *INDENT-OFF* */ + hash_foreach_mem (ip6_addr_key, mac_addr, bd->mac_by_ip6, + ({ + clib_mem_free (ip6_addr_key); /* free memory used for ip6 addr key */ + })); + /* *INDENT-ON* */ + hash_free (bd->mac_by_ip6); +} + static int bd_delete (bd_main_t * bdm, u32 bd_index) { l2_bridge_domain_t *bd = &l2input_main.bd_configs[bd_index]; u32 bd_id = bd->bd_id; - u64 mac_addr; - ip6_address_t *ip6_addr_key; /* flush non-static MACs in BD and removed bd_id from hash table */ l2fib_flush_bd_mac (vlib_get_main (), bd_index); @@ -115,14 +129,7 @@ bd_delete (bd_main_t * bdm, u32 bd_index) /* free memory used by BD */ vec_free (bd->members); - hash_free (bd->mac_by_ip4); - /* *INDENT-OFF* */ - hash_foreach_mem (ip6_addr_key, mac_addr, bd->mac_by_ip6, - ({ - clib_mem_free (ip6_addr_key); /* free memory used for ip6 addr key */ - })); - /* *INDENT-ON* */ - hash_free (bd->mac_by_ip6); + bd_free_ip_mac_tables (bd); return 0; } @@ -805,6 +812,20 @@ bd_add_del_ip_mac (u32 bd_index, return 0; } +/** + * Flush IP address to MAC address mapping tables in a BD. + */ +void +bd_flush_ip_mac (u32 bd_index) +{ + l2_bridge_domain_t *bd = l2input_bd_config (bd_index); + ASSERT (bd_is_valid (bd)); + bd_free_ip_mac_tables (bd); + bd->mac_by_ip4 = 0; + bd->mac_by_ip6 = + hash_create_mem (0, sizeof (ip6_address_t), sizeof (uword)); +} + /** Set bridge-domain arp entry add/delete. The CLI format is: @@ -849,6 +870,11 @@ bd_arp_entry (vlib_main_t * vm, { type = IP46_TYPE_IP6; } + else if (unformat (input, "del-all")) + { + bd_flush_ip_mac (bd_index); + goto done; + } else { error = clib_error_return (0, "expecting IP address but got `%U'", @@ -893,7 +919,7 @@ done: /* *INDENT-OFF* */ VLIB_CLI_COMMAND (bd_arp_entry_cli, static) = { .path = "set bridge-domain arp entry", - .short_help = "set bridge-domain arp entry [del]", + .short_help = "set bridge-domain arp entry [ [del] | del-all]", .function = bd_arp_entry, }; /* *INDENT-ON* */ -- cgit 1.2.3-korg