diff mbox

[03/21] odp-util: Add tun_key to parse_odp_key_attr()

Message ID 1337850554-10339-4-git-send-email-horms@verge.net.au
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Simon Horman May 24, 2012, 9:08 a.m. UTC
Cc: Kyle Mestery <kmestery@cisco.com>
Signed-off-by: Simon Horman <horms@verge.net.au>

---

v4
Correct parsing of tunnel key in parse_odp_key_attr()
so that it matches the out put of format_odp_key_attr()

TODO: fix test suite

v3
* Initial post
---
 lib/odp-util.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Ben Pfaff May 24, 2012, 4:29 p.m. UTC | #1
On Thu, May 24, 2012 at 06:08:56PM +0900, Simon Horman wrote:
> Cc: Kyle Mestery <kmestery@cisco.com>

But I don't see him CCed?

> +        ovs_be32 ipv4_src;
> +        ovs_be32 ipv4_dst;
> +        unsigned long long tun_flags;
> +        int ipv4_tos;
> +        int ipv4_ttl;
> +        int n = -1;
> +
> +        if (sscanf(s, "ipv4_tunnel(tun_id=%31[x0123456789abcdefABCDEF]"
> +                   ",flags=%llx,src="IP_SCAN_FMT",dst="IP_SCAN_FMT
> +                   ",tos=%i,ttl=%i)%n",
> +                   tun_id_s, &tun_flags,
> +                   IP_SCAN_ARGS(&ipv4_src), IP_SCAN_ARGS(&ipv4_dst),
> +                   &ipv4_tos, &ipv4_ttl, &n) > 0
> +            && n > 0) {

Does this compile?  I don't see a declaration of tun_id_s.

In the ODP printer and parser, we usually require fields that are
hexadecimal to be written with an explicit "0x" on output (using
something like "0x%x" or "%#x" on output), and then use "%i" on input,
so that it is always unambiguous at a glance whether a number is
decimal or hexadecimal.  I'd appreciate it if we could maintain that
here (I didn't look over at the printer code to see if it writes 0x,
but I'd like it to).

Otherwise, this looks good, thank you.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Simon Horman May 25, 2012, 12:01 a.m. UTC | #2
On Thu, May 24, 2012 at 09:29:11AM -0700, Ben Pfaff wrote:
> On Thu, May 24, 2012 at 06:08:56PM +0900, Simon Horman wrote:
> > Cc: Kyle Mestery <kmestery@cisco.com>
> 
> But I don't see him CCed?

Strange. I asked git send-mail to CC him explicitly.

> > +        ovs_be32 ipv4_src;
> > +        ovs_be32 ipv4_dst;
> > +        unsigned long long tun_flags;
> > +        int ipv4_tos;
> > +        int ipv4_ttl;
> > +        int n = -1;
> > +
> > +        if (sscanf(s, "ipv4_tunnel(tun_id=%31[x0123456789abcdefABCDEF]"
> > +                   ",flags=%llx,src="IP_SCAN_FMT",dst="IP_SCAN_FMT
> > +                   ",tos=%i,ttl=%i)%n",
> > +                   tun_id_s, &tun_flags,
> > +                   IP_SCAN_ARGS(&ipv4_src), IP_SCAN_ARGS(&ipv4_dst),
> > +                   &ipv4_tos, &ipv4_ttl, &n) > 0
> > +            && n > 0) {
> 
> Does this compile?  I don't see a declaration of tun_id_s.
> 
> In the ODP printer and parser, we usually require fields that are
> hexadecimal to be written with an explicit "0x" on output (using
> something like "0x%x" or "%#x" on output), and then use "%i" on input,
> so that it is always unambiguous at a glance whether a number is
> decimal or hexadecimal.  I'd appreciate it if we could maintain that
> here (I didn't look over at the printer code to see if it writes 0x,
> but I'd like it to).
> 
> Otherwise, this looks good, thank you.

Sorry, perhaps this is not the latest revision, somehow.
I did have it compiling, and I'll update the patch accordingly.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/odp-util.c b/lib/odp-util.c
index 23d1efe..7cff00c 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -925,6 +925,35 @@  parse_odp_key_attr(const char *s, const struct simap *port_names,
     }
 
     {
+        ovs_be32 ipv4_src;
+        ovs_be32 ipv4_dst;
+        unsigned long long tun_flags;
+        int ipv4_tos;
+        int ipv4_ttl;
+        int n = -1;
+
+        if (sscanf(s, "ipv4_tunnel(tun_id=%31[x0123456789abcdefABCDEF]"
+                   ",flags=%llx,src="IP_SCAN_FMT",dst="IP_SCAN_FMT
+                   ",tos=%i,ttl=%i)%n",
+                   tun_id_s, &tun_flags,
+                   IP_SCAN_ARGS(&ipv4_src), IP_SCAN_ARGS(&ipv4_dst),
+                   &ipv4_tos, &ipv4_ttl, &n) > 0
+            && n > 0) {
+            struct ovs_key_ipv4_tunnel tun_key;
+
+            tun_key.tun_id = htonll(strtoull(tun_id_s, NULL, 0));
+            tun_key.tun_flags = tun_flags;
+            tun_key.ipv4_src = ipv4_src;
+            tun_key.ipv4_dst = ipv4_dst;
+            tun_key.ipv4_tos = ipv4_tos;
+            tun_key.ipv4_ttl = ipv4_ttl;
+            nl_msg_put_unspec(key, OVS_KEY_ATTR_IPV4_TUNNEL,
+                              &tun_key, sizeof tun_key);
+            return n;
+        }
+    }
+
+    {
         unsigned long long int in_port;
         int n = -1;