diff options
author | John Lo <loj@cisco.com> | 2019-01-07 15:16:33 -0500 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2019-01-07 21:55:28 +0000 |
commit | e26c81fc80d1ce9a8746ebf4009149849b04f60f (patch) | |
tree | 12157a3247ed9169951e1083f8b50e240eec30c7 /src/vnet/l2/l2_bd.c | |
parent | 2500c79423c7d8d35b4e7b8f50060c09f2f857be (diff) |
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 <bd-id> del-all
The API added is bd_ip_mac_flush.
Change-Id: I34ceb87c0f480c7102f6559312c24081ed485af8
Signed-off-by: John Lo <loj@cisco.com>
Diffstat (limited to 'src/vnet/l2/l2_bd.c')
-rw-r--r-- | src/vnet/l2/l2_bd.c | 48 |
1 files changed, 37 insertions, 11 deletions
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; } @@ -806,6 +813,20 @@ bd_add_del_ip_mac (u32 bd_index, } /** + * 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: set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del] @@ -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 <bridge-domain-id> <ip-addr> <mac-addr> [del]", + .short_help = "set bridge-domain arp entry <bridge-domain-id> [<ip-addr> <mac-addr> [del] | del-all]", .function = bd_arp_entry, }; /* *INDENT-ON* */ |