Add common definitions for Windows builds.
[cascardo/ovs.git] / ofproto / netflow.c
index c91ecf0..f79ad6a 100644 (file)
@@ -79,6 +79,7 @@ struct netflow_flow {
 };
 
 static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
+static atomic_uint netflow_count = ATOMIC_VAR_INIT(0);
 
 static struct netflow_flow *netflow_flow_lookup(const struct netflow *,
                                                 const struct flow *)
@@ -97,8 +98,7 @@ netflow_mask_wc(struct flow *flow, struct flow_wildcards *wc)
     memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
     memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
     memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
-    memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
-    memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
+    flow_unwildcard_tp_ports(flow, wc);
     wc->masks.nw_tos |= IP_DSCP_MASK;
 }
 
@@ -396,6 +396,8 @@ struct netflow *
 netflow_create(void)
 {
     struct netflow *nf = xzalloc(sizeof *nf);
+    int junk;
+
     nf->engine_type = 0;
     nf->engine_id = 0;
     nf->boot_time = time_msec();
@@ -405,6 +407,7 @@ netflow_create(void)
     hmap_init(&nf->flows);
     atomic_init(&nf->ref_cnt, 1);
     ofpbuf_init(&nf->packet, 1500);
+    atomic_add(&netflow_count, 1, &junk);
     return nf;
 }
 
@@ -432,11 +435,22 @@ netflow_unref(struct netflow *nf)
     atomic_sub(&nf->ref_cnt, 1, &orig);
     ovs_assert(orig > 0);
     if (orig == 1) {
-        ofpbuf_uninit(&nf->packet);
+        atomic_sub(&netflow_count, 1, &orig);
         collectors_destroy(nf->collectors);
+        ofpbuf_uninit(&nf->packet);
         free(nf);
     }
 }
+
+/* Returns true if there exist any netflow objects, false otherwise. */
+bool
+netflow_exists(void)
+{
+    int n;
+
+    atomic_read(&netflow_count, &n);
+    return n > 0;
+}
 \f
 /* Helpers. */