summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEthan Jackson <ethan@nicira.com>2013-06-18 16:40:19 -0700
committerEthan Jackson <ethan@nicira.com>2013-06-27 18:23:39 -0700
commit92cfab82fc4287aa1859ae38c596bfd03fa45bd1 (patch)
tree8dbb23c1758c60db5be21a0befcc3c021802f74f
parent8e9a73fa94560a175a211264c07c3519615edaf7 (diff)
downloadopenvswitch-92cfab82fc4287aa1859ae38c596bfd03fa45bd1.tar.gz
bfd: Reference count 'struct bfd'.
Signed-off-by: Ethan Jackson <ethan@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
-rw-r--r--lib/bfd.c33
-rw-r--r--lib/bfd.h2
2 files changed, 30 insertions, 5 deletions
diff --git a/lib/bfd.c b/lib/bfd.c
index 22c9caee3..8039c09e6 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -179,6 +179,8 @@ struct bfd {
long long int last_tx; /* Last TX time. */
long long int next_tx; /* Next TX time. */
long long int detect_time; /* RFC 5880 6.8.4 Detection time. */
+
+ int ref_cnt;
};
static bool bfd_in_poll(const struct bfd *);
@@ -248,11 +250,7 @@ bfd_configure(struct bfd *bfd, const char *name,
}
if (!cfg || !smap_get_bool(cfg, "enable", false)) {
- if (bfd) {
- hmap_remove(&all_bfds, &bfd->node);
- free(bfd->name);
- free(bfd);
- }
+ bfd_unref(bfd);
return NULL;
}
@@ -265,6 +263,7 @@ bfd_configure(struct bfd *bfd, const char *name,
bfd->diag = DIAG_NONE;
bfd->min_tx = 1000;
bfd->mult = 3;
+ bfd->ref_cnt = 1;
/* RFC 5881 section 4
* The source port MUST be in the range 49152 through 65535. The same
@@ -309,6 +308,30 @@ bfd_configure(struct bfd *bfd, const char *name,
return bfd;
}
+struct bfd *
+bfd_ref(const struct bfd *bfd_)
+{
+ struct bfd *bfd = CONST_CAST(struct bfd *, bfd_);
+ if (bfd) {
+ ovs_assert(bfd->ref_cnt > 0);
+ bfd->ref_cnt++;
+ }
+ return bfd;
+}
+
+void
+bfd_unref(struct bfd *bfd)
+{
+ if (bfd) {
+ ovs_assert(bfd->ref_cnt > 0);
+ if (!--bfd->ref_cnt) {
+ hmap_remove(&all_bfds, &bfd->node);
+ free(bfd->name);
+ free(bfd);
+ }
+ }
+}
+
void
bfd_wait(const struct bfd *bfd)
{
diff --git a/lib/bfd.h b/lib/bfd.h
index 61f9945f9..ab854d855 100644
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -40,6 +40,8 @@ void bfd_process_packet(struct bfd *, const struct flow *,
struct bfd *bfd_configure(struct bfd *, const char *name,
const struct smap *smap);
+struct bfd *bfd_ref(const struct bfd *);
+void bfd_unref(struct bfd *);
bool bfd_forwarding(const struct bfd *);
void bfd_get_status(const struct bfd *, struct smap *);