cfm: Reference count 'struct cfm'.
[sliver-openvswitch.git] / lib / cfm.c
index 67c2002..06415fc 100644 (file)
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -125,6 +125,8 @@ struct cfm {
     int health_interval;      /* Number of fault_intervals since health was
                                  recomputed. */
     long long int last_tx;    /* Last CCM transmission time. */
+
+    int ref_cnt;
 };
 
 /* Remote MPs represent foreign network entities that are configured to have
@@ -318,11 +320,12 @@ cfm_create(const struct netdev *netdev)
     cfm->fault_override = -1;
     cfm->health = -1;
     cfm->last_tx = 0;
+    cfm->ref_cnt = 1;
     return cfm;
 }
 
 void
-cfm_destroy(struct cfm *cfm)
+cfm_unref(struct cfm *cfm)
 {
     struct remote_mp *rmp, *rmp_next;
 
@@ -330,6 +333,11 @@ cfm_destroy(struct cfm *cfm)
         return;
     }
 
+    ovs_assert(cfm->ref_cnt);
+    if (--cfm->ref_cnt) {
+        return;
+    }
+
     HMAP_FOR_EACH_SAFE (rmp, rmp_next, node, &cfm->remote_mps) {
         hmap_remove(&cfm->remote_mps, &rmp->node);
         free(rmp);
@@ -342,6 +350,17 @@ cfm_destroy(struct cfm *cfm)
     free(cfm);
 }
 
+struct cfm *
+cfm_ref(const struct cfm *cfm_)
+{
+    struct cfm *cfm = CONST_CAST(struct cfm *, cfm_);
+    if (cfm) {
+        ovs_assert(cfm->ref_cnt > 0);
+        cfm->ref_cnt++;
+    }
+    return cfm;
+}
+
 /* Should be run periodically to update fault statistics messages. */
 void
 cfm_run(struct cfm *cfm)
@@ -584,7 +603,6 @@ cfm_should_process_flow(const struct cfm *cfm, const struct flow *flow,
                         struct flow_wildcards *wc)
 {
     memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
-    memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
     if (cfm->check_tnl_key) {
         memset(&wc->masks.tunnel.tun_id, 0xff, sizeof wc->masks.tunnel.tun_id);
     }