[ovs-dev,v2,07/11] ct-dpif: Helper functions for conntrack zone limit

Message ID 1533170156-769-8-git-send-email-yihung.wei@gmail.com
State Changes Requested
Headers show
Series
  • conntrack zone limitation
Related show

Commit Message

Yi-Hung Wei Aug. 2, 2018, 12:35 a.m.
This patch implments some helper function for conntrack zone limit.
It will be useful for the following patches.

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
---
 lib/ct-dpif.c | 32 ++++++++++++++++++++++++++++++++
 lib/ct-dpif.h |  4 ++++
 2 files changed, 36 insertions(+)

Patch

diff --git a/lib/ct-dpif.c b/lib/ct-dpif.c
index d1e8a6b8b4a9..a772799fe347 100644
--- a/lib/ct-dpif.c
+++ b/lib/ct-dpif.c
@@ -597,3 +597,35 @@  error:
     free(copy);
     return false;
 }
+
+void
+ct_dpif_push_zone_limit(struct ovs_list *zone_limits, uint16_t zone,
+                        uint32_t limit, uint32_t count)
+{
+    struct ct_dpif_zone_limit *zone_limit = xmalloc(sizeof *zone_limit);
+    zone_limit->zone = zone;
+    zone_limit->limit = limit;
+    zone_limit->count = count;
+    ovs_list_push_back(zone_limits, &zone_limit->node);
+}
+
+/* The caller takes ownership of 'struct ct_dpif_zone_limit *', and is
+ * responsible to free that struct. */
+struct ct_dpif_zone_limit *
+ct_dpif_pop_zone_limit(struct ovs_list *zone_limits)
+{
+    struct ct_dpif_zone_limit *zone_limit;
+    LIST_FOR_EACH_POP (zone_limit, node, zone_limits) {
+        return zone_limit;
+    }
+    OVS_NOT_REACHED();
+}
+
+void
+ct_dpif_free_zone_limits(struct ovs_list *zone_limits)
+{
+    while (!ovs_list_is_empty(zone_limits)) {
+        struct ct_dpif_zone_limit *p = ct_dpif_pop_zone_limit(zone_limits);
+        free(p);
+    }
+}
diff --git a/lib/ct-dpif.h b/lib/ct-dpif.h
index 4e83bc555e03..c80e18b72b56 100644
--- a/lib/ct-dpif.h
+++ b/lib/ct-dpif.h
@@ -219,5 +219,9 @@  void ct_dpif_format_tuple(struct ds *, const struct ct_dpif_tuple *);
 uint8_t ct_dpif_coalesce_tcp_state(uint8_t state);
 void ct_dpif_format_tcp_stat(struct ds *, int, int);
 bool ct_dpif_parse_tuple(struct ct_dpif_tuple *, const char *s, struct ds *);
+void ct_dpif_push_zone_limit(struct ovs_list *, uint16_t zone, uint32_t limit,
+                             uint32_t count);
+struct ct_dpif_zone_limit * ct_dpif_pop_zone_limit(struct ovs_list *);
+void ct_dpif_free_zone_limits(struct ovs_list *);
 
 #endif /* CT_DPIF_H */