Skip to content

Commit

Permalink
ofp-parse: Separate fields properly.
Browse files Browse the repository at this point in the history
Currently, each token in an OpenFlow match field is treated separately -
whether this is a name, a value, or a single identifier. However, this
means that attempting to get a value may result in grabbing the next
token if no value exists. This avoids that problem by breaking the match
string down into its components and then individually separating it into
name/value pairs if appropriate.

Signed-off-by: Jesse Gross <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
jessegross committed Sep 9, 2015
1 parent 9e3ddd4 commit bc78455
Showing 1 changed file with 11 additions and 27 deletions.
38 changes: 11 additions & 27 deletions lib/ofp-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,8 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string,
F_PRIORITY = 1 << 4,
F_FLAGS = 1 << 5,
} fields;
char *save_ptr = NULL;
char *act_str = NULL;
char *name;
char *name, *value;

*usable_protocols = OFPUTIL_P_ANY;

Expand Down Expand Up @@ -339,8 +338,8 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string,
return xstrdup("must specify an action");
}
}
for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {

while (ofputil_parse_key_value(&string, &name, &value)) {
const struct protocol *p;
char *error = NULL;

Expand All @@ -366,25 +365,15 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string,
|| !strcmp(name, "allow_hidden_fields")) {
/* ignore these fields. */
} else if (mf_from_name(name)) {
char *value;

value = strtok_r(NULL, ", \t\r\n", &save_ptr);
if (!value) {
if (!*value) {
/* If there's no value, we're just trying to match on the
* existence of the field, so use a no-op value. */
value = "0/0";
}

error = parse_field(mf_from_name(name), value, &fm->match,
usable_protocols);
if (error) {
return error;
}
} else {
char *value;

value = strtok_r(NULL, ", \t\r\n", &save_ptr);
if (!value) {
if (!*value) {
return xasprintf("field %s missing value", name);
}

Expand Down Expand Up @@ -450,10 +439,10 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string,
} else {
error = xasprintf("unknown keyword %s", name);
}
}

if (error) {
return error;
}
if (error) {
return error;
}
}
/* Check for usable protocol interdependencies between match fields. */
Expand Down Expand Up @@ -776,8 +765,7 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr,
enum ofputil_protocol *usable_protocols)
{
static atomic_count id = ATOMIC_COUNT_INIT(0);
char *save_ptr = NULL;
char *name;
char *name, *value;

fmr->id = atomic_count_inc(&id);

Expand All @@ -787,8 +775,7 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr,
fmr->table_id = 0xff;
match_init_catchall(&fmr->match);

for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {
while (ofputil_parse_key_value(&string, &name, &value)) {
const struct protocol *p;

if (!strcmp(name, "!initial")) {
Expand All @@ -809,10 +796,7 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr,
match_set_nw_proto(&fmr->match, p->nw_proto);
}
} else {
char *value;

value = strtok_r(NULL, ", \t\r\n", &save_ptr);
if (!value) {
if (!*value) {
return xasprintf("%s: field %s missing value", str_, name);
}

Expand Down

0 comments on commit bc78455

Please sign in to comment.