From: Ben Pfaff Date: Mon, 29 Dec 2008 23:55:54 +0000 (-0800) Subject: New function mac_learning_flush(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0a5d9303627cf28299eed40d9ff1f4d5308d526;p=openvswitch New function mac_learning_flush(). --- diff --git a/lib/mac-learning.c b/lib/mac-learning.c index 49dfbefa..61c6fccb 100644 --- a/lib/mac-learning.c +++ b/lib/mac-learning.c @@ -122,6 +122,31 @@ search_bucket(struct list *bucket, const uint8_t mac[ETH_ADDR_LEN], 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) @@ -241,20 +266,27 @@ mac_learning_lookup_tag(const struct mac_learning *ml, } } +/* 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); } } diff --git a/lib/mac-learning.h b/lib/mac-learning.h index 37ebf0bc..8e3db910 100644 --- a/lib/mac-learning.h +++ b/lib/mac-learning.h @@ -47,6 +47,7 @@ uint16_t mac_learning_lookup(const struct mac_learning *, 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 *);