#include <stdlib.h>
#include <string.h>
#include "ofpbuf.h"
-#include "openflow.h"
+#include "openflow/openflow.h"
#include "packets.h"
#include "timeval.h"
}
/* Returns nonzero if 't' (the table entry's key) and 'd' (the key
- * describing the deletion) match, that is, if their fields are
+ * describing the match) match, that is, if their fields are
* equal modulo wildcards, zero otherwise. If 'strict' is nonzero, the
* wildcards must match in both 't_key' and 'd_key'. Note that the
* table's wildcards are ignored unless 'strict' is set. */
int
-flow_del_matches(const struct sw_flow_key *t, const struct sw_flow_key *d, int strict)
+flow_matches_desc(const struct sw_flow_key *t, const struct sw_flow_key *d,
+ int strict)
{
if (strict && d->wildcards != t->wildcards) {
return 0;
to->pad = 0;
}
-/* Allocates and returns a new flow with 'n_actions' action, using allocation
- * flags 'flags'. Returns the new flow or a null pointer on failure. */
+/* Allocates and returns a new flow with room for 'actions_len' actions.
+ * Returns the new flow or a null pointer on failure. */
struct sw_flow *
-flow_alloc(int n_actions)
+flow_alloc(size_t actions_len)
{
+ struct sw_flow_actions *sfa;
+ size_t size = sizeof *sfa + actions_len;
struct sw_flow *flow = malloc(sizeof *flow);
if (!flow)
return NULL;
- flow->n_actions = n_actions;
- flow->actions = malloc(n_actions * sizeof *flow->actions);
- if (!flow->actions && n_actions > 0) {
+ sfa = malloc(size);
+ if (!sfa) {
free(flow);
return NULL;
}
+ sfa->actions_len = actions_len;
+ flow->sf_acts = sfa;
return flow;
}
if (!flow) {
return;
}
- free(flow->actions);
+ free(flow->sf_acts);
free(flow);
}
+/* Copies 'actions' into a newly allocated structure for use by 'flow'
+ * and frees the structure that defined the previous actions. */
+void flow_replace_acts(struct sw_flow *flow,
+ const struct ofp_action_header *actions, size_t actions_len)
+{
+ struct sw_flow_actions *sfa;
+ int size = sizeof *sfa + actions_len;
+
+ sfa = malloc(size);
+ if (unlikely(!sfa))
+ return;
+
+ sfa->actions_len = actions_len;
+ memcpy(sfa->actions, actions, actions_len);
+
+ free(flow->sf_acts);
+ flow->sf_acts = sfa;
+
+ return;
+}
+
/* Prints a representation of 'key' to the kernel log. */
void
print_flow(const struct sw_flow_key *key)