[ovs-dev] [PATCH V2] odp-util: Fix a bug in parse_flag().
Alex Wang
alexw at nicira.com
Sat May 2 22:44:34 UTC 2015
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 at nicira.com>
Signed-off-by: Alex Wang <alexw at nicira.com>
---
PATCH->V2:
- Add test in tests/odp.at.
---
lib/odp-util.c | 12 +++++++-----
tests/odp.at | 4 ++++
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/odp-util.c b/lib/odp-util.c
index b82edb7..962b84b 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -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;
diff --git a/tests/odp.at b/tests/odp.at
index c356487..16a58e7 100644
--- a/tests/odp.at
+++ b/tests/odp.at
@@ -120,6 +120,10 @@ skb_mark(0x1234/0xfff0),in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:
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(/
s/$/)/' odp-base.txt
--
1.7.9.5
More information about the dev
mailing list