Blob Blame History Raw
From 85b13870020facf5f4441df51df64ee647c6abd9 Mon Sep 17 00:00:00 2001
Message-Id: <85b13870020facf5f4441df51df64ee647c6abd9.1588608928.git.lorenzo.bianconi@redhat.com>
In-Reply-To: <0b9d16670d5561d8300d2448cbd4686a3acdc57e.1588608928.git.lorenzo.bianconi@redhat.com>
References: <0b9d16670d5561d8300d2448cbd4686a3acdc57e.1588608928.git.lorenzo.bianconi@redhat.com>
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Date: Wed, 29 Apr 2020 18:05:30 +0200
Subject: [PATCH 2/3] controller: Add garbage collector for ipv6_prefixd.

Introduce a garbage collector for stale entries in ipv6_prefixd that are
no longer managed by the controller (e.g. if the processing has been
disabled setting ipv6_prefix_delegation to false on all logical router
ports).

Tested-by: Jianlin Shi <jishi@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
---
 controller/pinctrl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/controller/pinctrl.c b/controller/pinctrl.c
index 3230bb386..f0d63b9a6 100644
--- a/controller/pinctrl.c
+++ b/controller/pinctrl.c
@@ -578,6 +578,7 @@ enum {
 
 struct ipv6_prefixd_state {
     long long int next_announce;
+    long long int last_used;
     struct in6_addr ipv6_addr;
     struct eth_addr ea;
     struct eth_addr cmac;
@@ -1128,11 +1129,13 @@ fill_ipv6_prefix_state(struct ovsdb_idl_txn *ovnsb_idl_txn,
             sbrec_port_binding_set_options(pb, &options);
             smap_destroy(&options);
         }
+        pfd->last_used = time_msec();
     }
 
     return changed;
 }
 
+#define IPV6_PREFIXD_STALE_TIMEOUT  180000LL
 static void
 prepare_ipv6_prefixd(struct ovsdb_idl_txn *ovnsb_idl_txn,
                      struct ovsdb_idl_index *sbrec_port_binding_by_name,
@@ -1210,6 +1213,15 @@ prepare_ipv6_prefixd(struct ovsdb_idl_txn *ovnsb_idl_txn,
         }
     }
 
+    struct shash_node *iter, *next;
+    SHASH_FOR_EACH_SAFE (iter, next, &ipv6_prefixd) {
+        struct ipv6_prefixd_state *pfd = iter->data;
+        if (pfd->last_used + IPV6_PREFIXD_STALE_TIMEOUT < time_msec()) {
+            free(pfd);
+            shash_delete(&ipv6_prefixd, iter);
+        }
+    }
+
     if (changed) {
         notify_pinctrl_handler();
     }
-- 
2.26.2