X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fmac-learning.c;h=f9f4db3d4bfbd2e9a2846c5d5a4861a70ebf6496;hb=9ac3fce4d5aea7e963439eb97f7c2d157aef4dfc;hp=0bee152386210d6a27ffa29afb7743fbbd9081c5;hpb=db8077c315f12fd523ace965cc22778ed8d5939a;p=openvswitch diff --git a/lib/mac-learning.c b/lib/mac-learning.c index 0bee1523..f9f4db3d 100644 --- a/lib/mac-learning.c +++ b/lib/mac-learning.c @@ -29,6 +29,7 @@ #include "tag.h" #include "timeval.h" #include "util.h" +#include "vlan-bitmap.h" #include "vlog.h" VLOG_DEFINE_THIS_MODULE(mac_learning); @@ -105,16 +106,6 @@ get_lru(struct mac_learning *ml, struct mac_entry **e) } } -/* 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) @@ -143,31 +134,30 @@ mac_learning_destroy(struct mac_learning *ml) { if (ml) { bitmap_free(ml->flood_vlans); + free(ml); } - free(ml); } /* Provides a bitmap of VLANs which have learning disabled, that is, VLANs on - * which all packets are flooded. It takes ownership of the bitmap. Returns - * true if the set has changed from the previous value. */ + * which all packets are flooded. Returns true if the set has changed from the + * previous value. */ bool -mac_learning_set_flood_vlans(struct mac_learning *ml, unsigned long *bitmap) +mac_learning_set_flood_vlans(struct mac_learning *ml, + const unsigned long *bitmap) { - bool ret = (bitmap == NULL - ? ml->flood_vlans != NULL - : (ml->flood_vlans == NULL - || !bitmap_equal(bitmap, ml->flood_vlans, 4096))); - - bitmap_free(ml->flood_vlans); - ml->flood_vlans = bitmap; - - return ret; + if (vlan_bitmap_equal(ml->flood_vlans, bitmap)) { + return false; + } else { + bitmap_free(ml->flood_vlans); + ml->flood_vlans = vlan_bitmap_clone(bitmap); + return true; + } } static bool is_learning_vlan(const struct mac_learning *ml, uint16_t vlan) { - return !(ml->flood_vlans && bitmap_is_set(ml->flood_vlans, vlan)); + return vlan_bitmap_contains(ml->flood_vlans, vlan); } /* Returns true if 'src_mac' may be learned on 'vlan' for 'ml'. @@ -268,6 +258,16 @@ mac_learning_lookup(const struct mac_learning *ml, } } +/* Expires 'e' from the 'ml' hash table. 'e' must not already be on the free + * list. */ +void +mac_learning_expire(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); +} + /* 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. */ @@ -276,7 +276,7 @@ mac_learning_flush(struct mac_learning *ml) { struct mac_entry *e; while (get_lru(ml, &e)){ - free_mac_entry(ml, e); + mac_learning_expire(ml, e); } } @@ -289,7 +289,7 @@ mac_learning_run(struct mac_learning *ml, struct tag_set *set) if (set) { tag_set_add(set, e->tag); } - free_mac_entry(ml, e); + mac_learning_expire(ml, e); } }