Signed-off-by: Ethan Jackson <[email protected]>
---
ofproto/ofproto-dpif-ipfix.c | 22 ++++++++++++++++++++--
ofproto/ofproto-dpif-ipfix.h | 4 +++-
ofproto/ofproto-dpif.c | 2 +-
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c
index 083fe15..ef0e980 100644
--- a/ofproto/ofproto-dpif-ipfix.c
+++ b/ofproto/ofproto-dpif-ipfix.c
@@ -62,6 +62,7 @@ struct dpif_ipfix_flow_exporter_map_node {
struct dpif_ipfix {
struct dpif_ipfix_bridge_exporter bridge_exporter;
struct hmap flow_exporter_map; /* dpif_ipfix_flow_exporter_map_nodes. */
+ int ref_cnt;
};
#define IPFIX_VERSION 0x000a
@@ -464,6 +465,18 @@ dpif_ipfix_create(void)
di = xzalloc(sizeof *di);
dpif_ipfix_exporter_clear(&di->bridge_exporter.exporter);
hmap_init(&di->flow_exporter_map);
+ di->ref_cnt = 1;
+ return di;
+}
+
+struct dpif_ipfix *
+dpif_ipfix_ref(const struct dpif_ipfix *di_)
+{
+ struct dpif_ipfix *di = CONST_CAST(struct dpif_ipfix *, di_);
+ if (di) {
+ ovs_assert(di->ref_cnt > 0);
+ di->ref_cnt++;
+ }
return di;
}
@@ -488,9 +501,14 @@ dpif_ipfix_clear(struct dpif_ipfix *di)
}
void
-dpif_ipfix_destroy(struct dpif_ipfix *di)
+dpif_ipfix_unref(struct dpif_ipfix *di)
{
- if (di) {
+ if (!di) {
+ return;
+ }
+
+ ovs_assert(di->ref_cnt > 0);
+ if (!--di->ref_cnt) {
dpif_ipfix_clear(di);
hmap_destroy(&di->flow_exporter_map);
free(di);
diff --git a/ofproto/ofproto-dpif-ipfix.h b/ofproto/ofproto-dpif-ipfix.h
index 26b02f1..c050dba 100644
--- a/ofproto/ofproto-dpif-ipfix.h
+++ b/ofproto/ofproto-dpif-ipfix.h
@@ -26,8 +26,10 @@ struct ofproto_ipfix_bridge_exporter_options;
struct ofproto_ipfix_flow_exporter_options;
struct dpif_ipfix *dpif_ipfix_create(void);
+struct dpif_ipfix *dpif_ipfix_ref(const struct dpif_ipfix *);
+void dpif_ipfix_unref(struct dpif_ipfix *);
+
uint32_t dpif_ipfix_get_bridge_exporter_probability(const struct dpif_ipfix *);
-void dpif_ipfix_destroy(struct dpif_ipfix *);
void dpif_ipfix_set_options(
struct dpif_ipfix *,
const struct ofproto_ipfix_bridge_exporter_options *,
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 264238c..70f8422 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1639,7 +1639,7 @@ set_ipfix(
n_flow_exporters_options);
} else {
if (di) {
- dpif_ipfix_destroy(di);
+ dpif_ipfix_unref(di);
ofproto->ipfix = NULL;
}
}
--
1.7.9.5
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev