diff mbox

[ovs-dev,3/5] flow: New function ct_state_from_string().

Message ID 20170418194743.27431-4-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff April 18, 2017, 7:47 p.m. UTC
This will have its first user in an upcoming commit.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 lib/flow.c | 15 ++++++++++++++-
 lib/flow.h |  4 +++-
 2 files changed, 17 insertions(+), 2 deletions(-)

Comments

Miguel Angel Ajo April 20, 2017, 9:19 a.m. UTC | #1
Acked-By: Miguel Angel Ajo <majopela@redhat.com>

On Tue, Apr 18, 2017 at 9:47 PM, Ben Pfaff <blp@ovn.org> wrote:

> This will have its first user in an upcoming commit.
>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> ---
>  lib/flow.c | 15 ++++++++++++++-
>  lib/flow.h |  4 +++-
>  2 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/lib/flow.c b/lib/flow.c
> index 5f9c3d0e3a88..7552cd72a173 100644
> --- a/lib/flow.c
> +++ b/lib/flow.c
> @@ -1000,7 +1000,8 @@ flow_get_metadata(const struct flow *flow, struct
> match *flow_metadata)
>      }
>  }
>
> -const char *ct_state_to_string(uint32_t state)
> +const char *
> +ct_state_to_string(uint32_t state)
>  {
>      switch (state) {
>  #define CS_STATE(ENUM, INDEX, NAME) case CS_##ENUM: return NAME;
> @@ -1011,6 +1012,18 @@ const char *ct_state_to_string(uint32_t state)
>      }
>  }
>
> +uint32_t
> +ct_state_from_string(const char *s)
> +{
> +#define CS_STATE(ENUM, INDEX, NAME) \
> +    if (!strcmp(s, NAME)) {         \
> +        return CS_##ENUM;           \
> +    }
> +    CS_STATES
> +#undef CS_STATE
> +    return 0;
> +}
> +
>  char *
>  flow_to_string(const struct flow *flow)
>  {
> diff --git a/lib/flow.h b/lib/flow.h
> index 86b52584b1de..9d4ae49ccfbd 100644
> --- a/lib/flow.h
> +++ b/lib/flow.h
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016
> Nicira, Inc.
> + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
> 2017 Nicira, Inc.
>   *
>   * Licensed under the Apache License, Version 2.0 (the "License");
>   * you may not use this file except in compliance with the License.
> @@ -73,6 +73,8 @@ void flow_unwildcard_tp_ports(const struct flow *,
> struct flow_wildcards *);
>  void flow_get_metadata(const struct flow *, struct match *flow_metadata);
>
>  const char *ct_state_to_string(uint32_t state);
> +uint32_t ct_state_from_string(const char *);
> +
>  char *flow_to_string(const struct flow *);
>  void format_flags(struct ds *ds, const char *(*bit_to_string)(uint32_t),
>                    uint32_t flags, char del);
> --
> 2.10.2
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
diff mbox

Patch

diff --git a/lib/flow.c b/lib/flow.c
index 5f9c3d0e3a88..7552cd72a173 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -1000,7 +1000,8 @@  flow_get_metadata(const struct flow *flow, struct match *flow_metadata)
     }
 }
 
-const char *ct_state_to_string(uint32_t state)
+const char *
+ct_state_to_string(uint32_t state)
 {
     switch (state) {
 #define CS_STATE(ENUM, INDEX, NAME) case CS_##ENUM: return NAME;
@@ -1011,6 +1012,18 @@  const char *ct_state_to_string(uint32_t state)
     }
 }
 
+uint32_t
+ct_state_from_string(const char *s)
+{
+#define CS_STATE(ENUM, INDEX, NAME) \
+    if (!strcmp(s, NAME)) {         \
+        return CS_##ENUM;           \
+    }
+    CS_STATES
+#undef CS_STATE
+    return 0;
+}
+
 char *
 flow_to_string(const struct flow *flow)
 {
diff --git a/lib/flow.h b/lib/flow.h
index 86b52584b1de..9d4ae49ccfbd 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -1,5 +1,5 @@ 
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -73,6 +73,8 @@  void flow_unwildcard_tp_ports(const struct flow *, struct flow_wildcards *);
 void flow_get_metadata(const struct flow *, struct match *flow_metadata);
 
 const char *ct_state_to_string(uint32_t state);
+uint32_t ct_state_from_string(const char *);
+
 char *flow_to_string(const struct flow *);
 void format_flags(struct ds *ds, const char *(*bit_to_string)(uint32_t),
                   uint32_t flags, char del);