diff mbox series

[ovs-dev,ovn,1/2] controller: add garbage collector for ipv6_prefixd

Message ID c9d8006c9470c8f81d2665970ec9f97f75e6d33e.1588176268.git.lorenzo.bianconi@redhat.com
State Accepted
Headers show
Series IPv6 PD: stop processing if necessary | expand

Commit Message

Lorenzo Bianconi April 29, 2020, 4:05 p.m. UTC
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>
---
 controller/pinctrl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

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();
     }