diff mbox

[ovs-dev,3/9] ct-dpif: Add ct_dpif_get_info()

Message ID 1503701479-43894-4-git-send-email-yihung.wei@gmail.com
State Deferred
Headers show

Commit Message

Yi-Hung Wei Aug. 25, 2017, 10:51 p.m. UTC
This patch adds ct_dpif_get_info() to dpif_class for querying conntrack
info from datapath. Later patches will use this function to query ct_fields
such as ct_state, ct_mark, and ct_label for ofproto/trace command.
The following commits will provide implementation of ct_dpif_get_info()
on dpif-netlink and dpif-netdev.

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
---
 lib/ct-dpif.c       | 19 +++++++++++++++++++
 lib/ct-dpif.h       |  7 +++++++
 lib/dpif-netdev.c   |  1 +
 lib/dpif-netlink.c  |  1 +
 lib/dpif-provider.h |  8 ++++++++
 5 files changed, 36 insertions(+)

Comments

Gregory Rose Aug. 31, 2017, 10:37 p.m. UTC | #1
On 08/25/2017 03:51 PM, Yi-Hung Wei wrote:
> This patch adds ct_dpif_get_info() to dpif_class for querying conntrack
> info from datapath. Later patches will use this function to query ct_fields
> such as ct_state, ct_mark, and ct_label for ofproto/trace command.
> The following commits will provide implementation of ct_dpif_get_info()
> on dpif-netlink and dpif-netdev.
>
> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
> ---
>   lib/ct-dpif.c       | 19 +++++++++++++++++++
>   lib/ct-dpif.h       |  7 +++++++
>   lib/dpif-netdev.c   |  1 +
>   lib/dpif-netlink.c  |  1 +
>   lib/dpif-provider.h |  8 ++++++++
>   5 files changed, 36 insertions(+)
>
> diff --git a/lib/ct-dpif.c b/lib/ct-dpif.c
> index c79e69e23970..3e6f4cbe9be2 100644
> --- a/lib/ct-dpif.c
> +++ b/lib/ct-dpif.c
> @@ -127,6 +127,25 @@ ct_dpif_flush(struct dpif *dpif, const uint16_t *zone)
>               : EOPNOTSUPP);
>   }
>
> +int
> +ct_dpif_get_info(struct dpif *dpif, struct ct_dpif_tuple *tuple,
> +                 const uint16_t zone, struct ct_dpif_info *info)
> +{
> +    return (dpif->dpif_class->ct_get_info
> +            ? dpif->dpif_class->ct_get_info(dpif, tuple, zone, info)
> +            : EOPNOTSUPP);
> +}
> +
> +void
> +ct_dpif_format_info(const struct ct_dpif_info *info, struct ds *output)
> +{
> +    struct ds s = DS_EMPTY_INITIALIZER;
> +
> +    format_flags(&s, ct_state_to_string, info->ct_state, '|');
> +    ds_put_format(output, "ct_state=%s", ds_cstr(&s));
> +    ds_destroy(&s);
> +}
> +
>   void
>   ct_dpif_entry_uninit(struct ct_dpif_entry *entry)
>   {
> diff --git a/lib/ct-dpif.h b/lib/ct-dpif.h
> index d5f966175bc0..0c82fb022f2b 100644
> --- a/lib/ct-dpif.h
> +++ b/lib/ct-dpif.h
> @@ -172,6 +172,10 @@ struct ct_dpif_entry {
>       uint32_t bkt;       /* CT bucket number. */
>   };
>
> +struct ct_dpif_info {
> +    uint32_t ct_state;
> +};
> +
>   enum {
>       CT_STATS_UDP,
>       CT_STATS_TCP,
> @@ -196,6 +200,9 @@ int ct_dpif_dump_start(struct dpif *, struct ct_dpif_dump_state **,
>   int ct_dpif_dump_next(struct ct_dpif_dump_state *, struct ct_dpif_entry *);
>   int ct_dpif_dump_done(struct ct_dpif_dump_state *);
>   int ct_dpif_flush(struct dpif *, const uint16_t *zone);
> +int ct_dpif_get_info(struct dpif *, struct ct_dpif_tuple *,
> +                     const uint16_t zone, struct ct_dpif_info *);
> +void ct_dpif_format_info(const struct ct_dpif_info *, struct ds *);
>   void ct_dpif_entry_uninit(struct ct_dpif_entry *);
>   void ct_dpif_format_entry(const struct ct_dpif_entry *, struct ds *,
>                             bool verbose, bool print_stats);
> diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
> index e2cd9310d51f..e9586bc46627 100644
> --- a/lib/dpif-netdev.c
> +++ b/lib/dpif-netdev.c
> @@ -5535,6 +5535,7 @@ const struct dpif_class dpif_netdev_class = {
>       dpif_netdev_ct_dump_next,
>       dpif_netdev_ct_dump_done,
>       dpif_netdev_ct_flush,
> +    NULL,                       /* ct_get_info */
>       dpif_netdev_meter_get_features,
>       dpif_netdev_meter_set,
>       dpif_netdev_meter_get,
> diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
> index 29001fbe4a54..122c59614f5a 100644
> --- a/lib/dpif-netlink.c
> +++ b/lib/dpif-netlink.c
> @@ -2986,6 +2986,7 @@ const struct dpif_class dpif_netlink_class = {
>       dpif_netlink_ct_dump_next,
>       dpif_netlink_ct_dump_done,
>       dpif_netlink_ct_flush,
> +    NULL,                       /* ct_get_info */
>       dpif_netlink_meter_get_features,
>       dpif_netlink_meter_set,
>       dpif_netlink_meter_get,
> diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
> index 1d82a0939aa1..829738739c6b 100644
> --- a/lib/dpif-provider.h
> +++ b/lib/dpif-provider.h
> @@ -75,6 +75,8 @@ dpif_flow_dump_thread_init(struct dpif_flow_dump_thread *thread,
>
>   struct ct_dpif_dump_state;
>   struct ct_dpif_entry;
> +struct ct_dpif_tuple;
> +struct ct_dpif_info;
>
>   /* Datapath interface class structure, to be defined by each implementation of
>    * a datapath interface.
> @@ -428,6 +430,12 @@ struct dpif_class {
>        * only deletes connections in '*zone'. */
>       int (*ct_flush)(struct dpif *, const uint16_t *zone);
>
> +    /* Queries 'dpif' for the connection tracking info of a connection
> +     * specified by 'tuple' in 'zone'. On success, returns 0 and sets
> +     * 'info', otherwise returns nonzero value. */
> +    int (*ct_get_info)(struct dpif *, struct ct_dpif_tuple *tuple,
> +                       const uint16_t zone, struct ct_dpif_info *info);
> +
>       /* Meters */
>
>       /* Queries 'dpif' for supported meter features.
>

Seems fine to me.

Reviewed-by: Greg Rose <gvrose8192@gmail.com>
diff mbox

Patch

diff --git a/lib/ct-dpif.c b/lib/ct-dpif.c
index c79e69e23970..3e6f4cbe9be2 100644
--- a/lib/ct-dpif.c
+++ b/lib/ct-dpif.c
@@ -127,6 +127,25 @@  ct_dpif_flush(struct dpif *dpif, const uint16_t *zone)
             : EOPNOTSUPP);
 }
 
+int
+ct_dpif_get_info(struct dpif *dpif, struct ct_dpif_tuple *tuple,
+                 const uint16_t zone, struct ct_dpif_info *info)
+{
+    return (dpif->dpif_class->ct_get_info
+            ? dpif->dpif_class->ct_get_info(dpif, tuple, zone, info)
+            : EOPNOTSUPP);
+}
+
+void
+ct_dpif_format_info(const struct ct_dpif_info *info, struct ds *output)
+{
+    struct ds s = DS_EMPTY_INITIALIZER;
+
+    format_flags(&s, ct_state_to_string, info->ct_state, '|');
+    ds_put_format(output, "ct_state=%s", ds_cstr(&s));
+    ds_destroy(&s);
+}
+
 void
 ct_dpif_entry_uninit(struct ct_dpif_entry *entry)
 {
diff --git a/lib/ct-dpif.h b/lib/ct-dpif.h
index d5f966175bc0..0c82fb022f2b 100644
--- a/lib/ct-dpif.h
+++ b/lib/ct-dpif.h
@@ -172,6 +172,10 @@  struct ct_dpif_entry {
     uint32_t bkt;       /* CT bucket number. */
 };
 
+struct ct_dpif_info {
+    uint32_t ct_state;
+};
+
 enum {
     CT_STATS_UDP,
     CT_STATS_TCP,
@@ -196,6 +200,9 @@  int ct_dpif_dump_start(struct dpif *, struct ct_dpif_dump_state **,
 int ct_dpif_dump_next(struct ct_dpif_dump_state *, struct ct_dpif_entry *);
 int ct_dpif_dump_done(struct ct_dpif_dump_state *);
 int ct_dpif_flush(struct dpif *, const uint16_t *zone);
+int ct_dpif_get_info(struct dpif *, struct ct_dpif_tuple *,
+                     const uint16_t zone, struct ct_dpif_info *);
+void ct_dpif_format_info(const struct ct_dpif_info *, struct ds *);
 void ct_dpif_entry_uninit(struct ct_dpif_entry *);
 void ct_dpif_format_entry(const struct ct_dpif_entry *, struct ds *,
                           bool verbose, bool print_stats);
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index e2cd9310d51f..e9586bc46627 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -5535,6 +5535,7 @@  const struct dpif_class dpif_netdev_class = {
     dpif_netdev_ct_dump_next,
     dpif_netdev_ct_dump_done,
     dpif_netdev_ct_flush,
+    NULL,                       /* ct_get_info */
     dpif_netdev_meter_get_features,
     dpif_netdev_meter_set,
     dpif_netdev_meter_get,
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 29001fbe4a54..122c59614f5a 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -2986,6 +2986,7 @@  const struct dpif_class dpif_netlink_class = {
     dpif_netlink_ct_dump_next,
     dpif_netlink_ct_dump_done,
     dpif_netlink_ct_flush,
+    NULL,                       /* ct_get_info */
     dpif_netlink_meter_get_features,
     dpif_netlink_meter_set,
     dpif_netlink_meter_get,
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index 1d82a0939aa1..829738739c6b 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -75,6 +75,8 @@  dpif_flow_dump_thread_init(struct dpif_flow_dump_thread *thread,
 
 struct ct_dpif_dump_state;
 struct ct_dpif_entry;
+struct ct_dpif_tuple;
+struct ct_dpif_info;
 
 /* Datapath interface class structure, to be defined by each implementation of
  * a datapath interface.
@@ -428,6 +430,12 @@  struct dpif_class {
      * only deletes connections in '*zone'. */
     int (*ct_flush)(struct dpif *, const uint16_t *zone);
 
+    /* Queries 'dpif' for the connection tracking info of a connection
+     * specified by 'tuple' in 'zone'. On success, returns 0 and sets
+     * 'info', otherwise returns nonzero value. */
+    int (*ct_get_info)(struct dpif *, struct ct_dpif_tuple *tuple,
+                       const uint16_t zone, struct ct_dpif_info *info);
+
     /* Meters */
 
     /* Queries 'dpif' for supported meter features.