cfm: Migrate cfm/show unixctl command to CFM module.
[openvswitch] / lib / mac-learning.c
index 42864ce0b600919741f8488f9866491b10e6c1fa..f9f4db3d4bfbd2e9a2846c5d5a4861a70ebf6496 100644 (file)
@@ -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);
@@ -133,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'.