return NULL;
}
+/* If the LRU list is not empty, stores the least-recently-used entry in '*e'
+ * and returns true. Otherwise, if the LRU list is empty, stores NULL in '*e'
+ * and return false. */
+static bool
+get_lru(struct mac_learning *ml, struct mac_entry **e)
+{
+ if (!list_is_empty(&ml->lrus)) {
+ *e = mac_entry_from_lru_node(ml->lrus.next);
+ return true;
+ } else {
+ *e = NULL;
+ return false;
+ }
+}
+
+/* Removes 'e' from the 'ml' hash table. 'e' must not already be on the free
+ * list. */
+static void
+free_mac_entry(struct mac_learning *ml, struct mac_entry *e)
+{
+ list_remove(&e->hash_node);
+ list_remove(&e->lru_node);
+ list_push_front(&ml->free, &e->lru_node);
+}
+
/* Creates and returns a new MAC learning table. */
struct mac_learning *
mac_learning_create(void)
}
}
+/* Expires all the mac-learning entries in 'ml'. The tags in 'ml' are
+ * discarded, so the client is responsible for revalidating any flows that
+ * depend on 'ml', if necessary. */
+void
+mac_learning_flush(struct mac_learning *ml)
+{
+ struct mac_entry *e;
+ while (get_lru(ml, &e)){
+ free_mac_entry(ml, e);
+ }
+}
+
void
mac_learning_run(struct mac_learning *ml, struct tag_set *set)
{
- while (!list_is_empty(&ml->lrus)) {
- struct mac_entry *e = mac_entry_from_lru_node(ml->lrus.next);
- if (time_now() < e->expires) {
- break;
- }
+ struct mac_entry *e;
+ while (get_lru(ml, &e) && time_now() >= e->expires) {
if (set) {
tag_set_add(set, e->tag);
}
- list_remove(&e->hash_node);
- list_remove(&e->lru_node);
- list_push_front(&ml->free, &e->lru_node);
+ free_mac_entry(ml, e);
}
}
uint16_t mac_learning_lookup_tag(const struct mac_learning *,
const uint8_t dst[ETH_ADDR_LEN],
uint16_t vlan, tag_type *tag);
+void mac_learning_flush(struct mac_learning *);
void mac_learning_run(struct mac_learning *, struct tag_set *);
void mac_learning_wait(struct mac_learning *);