From d857c8aabf5195a35b9fd740fcc66ae23f222451 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Tue, 18 Jun 2013 19:36:44 -0700 Subject: [PATCH] ofproto-dpif-ipfix: Reference count 'struct dpif_ipfix'. Signed-off-by: Ethan Jackson Acked-by: Ben Pfaff --- 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 083fe15aa..ef0e980d1 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 26b02f1d1..c050dba08 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 afda80d45..b3b38ae0c 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1644,7 +1644,7 @@ set_ipfix( n_flow_exporters_options); } else { if (di) { - dpif_ipfix_destroy(di); + dpif_ipfix_unref(di); ofproto->ipfix = NULL; } } -- 2.43.0