validate_actions(const union ofp_action *actions, size_t n_actions,
int max_ports)
{
- const union ofp_action *a;
+ size_t i;
- for (a = actions; a < &actions[n_actions]; ) {
+ for (i = 0; i < n_actions; ) {
+ const union ofp_action *a = &actions[i];
unsigned int len = ntohs(a->header.len);
unsigned int n_slots = len / ACTION_ALIGNMENT;
unsigned int slots_left = &actions[n_actions] - a;
if (error) {
return error;
}
- a += n_slots;
+ i += n_slots;
}
return 0;
}
const union ofp_action *
actions_next(struct actions_iterator *iter)
{
- if (iter->pos < iter->end) {
+ if (iter->pos != iter->end) {
const union ofp_action *a = iter->pos;
unsigned int len = ntohs(a->header.len);
iter->pos += len / ACTION_ALIGNMENT;
} else {
list_init(&rule->list);
}
- rule->n_actions = n_actions;
- rule->actions = xmemdup(actions, n_actions * sizeof *actions);
+ if (n_actions > 0) {
+ rule->n_actions = n_actions;
+ rule->actions = xmemdup(actions, n_actions * sizeof *actions);
+ }
netflow_flow_clear(&rule->nf_flow);
netflow_flow_update_time(ofproto->netflow, &rule->nf_flow, rule->created);
memset(ofs->pad2, 0, sizeof ofs->pad2);
ofs->packet_count = htonll(packet_count);
ofs->byte_count = htonll(byte_count);
- memcpy(ofs->actions, rule->actions, act_len);
+ if (rule->n_actions > 0) {
+ memcpy(ofs->actions, rule->actions, act_len);
+ }
}
static int
ds_put_format(results, "n_packets=%"PRIu64", ", packet_count);
ds_put_format(results, "n_bytes=%"PRIu64", ", byte_count);
ofp_print_match(results, &match, true);
- ofp_print_actions(results, &rule->actions->header, act_len);
+ if (act_len > 0) {
+ ofp_print_actions(results, &rule->actions->header, act_len);
+ }
ds_put_cstr(results, "\n");
}
/* If the actions are the same, do nothing. */
if (n_actions == rule->n_actions
- && !memcmp(ofm->actions, rule->actions, actions_len))
+ && (!n_actions || !memcmp(ofm->actions, rule->actions, actions_len)))
{
return 0;
}
/* Replace actions. */
free(rule->actions);
- rule->actions = xmemdup(ofm->actions, actions_len);
+ rule->actions = n_actions ? xmemdup(ofm->actions, actions_len) : NULL;
rule->n_actions = n_actions;
/* Make sure that the datapath gets updated properly. */