odp-util: Fix a bug in parse_flag().
authorAlex Wang <alexw@nicira.com>
Sat, 2 May 2015 03:54:00 +0000 (20:54 -0700)
committerAlex Wang <alexw@nicira.com>
Sat, 2 May 2015 22:53:59 +0000 (15:53 -0700)
This commit fixes a bug in the parse_flag() function which causes
failure of parsing tunnel flags like:

tunnel(tun_id=0x0,src=1.2.3.4,dst=1.2.3.5,tos=0,ttl=64,flags(-df+csum+key))

Reported-by: Jacob Cherkas <jcherkas@nicira.com>
Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/odp-util.c
tests/odp.at

index b82edb7..962b84b 100644 (file)
@@ -231,21 +231,22 @@ parse_flags(const char *s, const char *(*bit_to_string)(uint32_t),
         uint32_t flags = 0, mask = 0;
 
         /* Parse masked flags. */
-        while (s[n] != ')') {
+        while (s[0] != ')') {
             bool set;
             uint32_t bit;
             int name_len;
 
-            if (s[n] == '+') {
+            if (s[0] == '+') {
                 set = true;
-            } else if (s[n] == '-') {
+            } else if (s[0] == '-') {
                 set = false;
             } else {
                 return -EINVAL;
             }
+            s++;
             n++;
 
-            name_len = strcspn(s + n, "+-)");
+            name_len = strcspn(s, "+-)");
 
             for (bit = 1; bit; bit <<= 1) {
                 const char *fname = bit_to_string(bit);
@@ -259,7 +260,7 @@ parse_flags(const char *s, const char *(*bit_to_string)(uint32_t),
                 if (len != name_len) {
                     continue;
                 }
-                if (!strncmp(s + n, fname, len)) {
+                if (!strncmp(s, fname, len)) {
                     if (mask & bit) {
                         /* bit already set. */
                         return -EINVAL;
@@ -279,6 +280,7 @@ parse_flags(const char *s, const char *(*bit_to_string)(uint32_t),
                 return -EINVAL; /* Unknown flag name */
             }
             s += name_len;
+            n += name_len;
         }
 
         *res_flags = flags;
index c356487..16a58e7 100644 (file)
@@ -119,6 +119,10 @@ skb_mark(0x1234/0xfff0),in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:
  echo '# Valid forms with tunnel header.'
  sed 's/^/tunnel(tun_id=0x7f10354\/0xff,src=10.10.10.10\/255.255.255.0,dst=20.20.20.20\/255.255.255.0,tos=0,ttl=64,tp_src=0,tp_dst=0,gbp_id=0,gbp_flags=0,flags(csum,key)),/' odp-base.txt
 
+ echo
+ echo '# Valid forms with tunnel header (wildcard flag).'
+ sed 's/^/tunnel(tun_id=0x7f10354\/0xff,src=10.10.10.10\/255.255.255.0,dst=20.20.20.20\/255.255.255.0,tos=0,ttl=64,tp_src=0,tp_dst=0,gbp_id=0,gbp_flags=0,flags(-df+csum+key)),/' odp-base.txt
+
  echo
  echo '# Valid forms with VLAN header.'
  sed 's/\(eth([[^)]]*)\),*/\1,eth_type(0x8100),vlan(vid=99,pcp=7),encap(/