- if (adj_nbr_tables[adj_nh_proto][sw_if_index] ||
- hash_elts(adj_nbr_tables[adj_nh_proto][sw_if_index]))
+ ais = NULL;
+
+ /* elements may be removed from the table during the walk, so
+ * collect the set first then process them */
+ hash_foreach_mem (key, ai, adj_nbr_tables[adj_nh_proto][sw_if_index],
+ ({
+ vec_add1(ais, ai);
+ }));
+
+ vec_foreach(aip, ais)