Skip to content

Commit

Permalink
openvswitch: Factor out allocation and verification of actions.
Browse files Browse the repository at this point in the history
As the size of the flow key grows, it can put some pressure on the
stack. This is particularly true in ovs_flow_cmd_set(), which needs several
copies of the key on the stack. One of those uses is logically separate,
so this factors it out to reduce stack pressure and improve readibility.

Signed-off-by: Jesse Gross <jesse@nicira.com>
Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jesse Gross authored and David S. Miller committed Oct 6, 2014
1 parent f0b128c commit 6b205b2
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions net/openvswitch/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,11 +933,34 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
return error;
}

static struct sw_flow_actions *get_flow_actions(const struct nlattr *a,
const struct sw_flow_key *key,
const struct sw_flow_mask *mask)
{
struct sw_flow_actions *acts;
struct sw_flow_key masked_key;
int error;

acts = ovs_nla_alloc_flow_actions(nla_len(a));
if (IS_ERR(acts))
return acts;

ovs_flow_mask_key(&masked_key, key, mask);
error = ovs_nla_copy_actions(a, &masked_key, 0, &acts);
if (error) {
OVS_NLERR("Flow actions may not be safe on all matching packets.\n");
kfree(acts);
return ERR_PTR(error);
}

return acts;
}

static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr **a = info->attrs;
struct ovs_header *ovs_header = info->userhdr;
struct sw_flow_key key, masked_key;
struct sw_flow_key key;
struct sw_flow *flow;
struct sw_flow_mask mask;
struct sk_buff *reply = NULL;
Expand All @@ -959,17 +982,10 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)

/* Validate actions. */
if (a[OVS_FLOW_ATTR_ACTIONS]) {
acts = ovs_nla_alloc_flow_actions(nla_len(a[OVS_FLOW_ATTR_ACTIONS]));
error = PTR_ERR(acts);
if (IS_ERR(acts))
acts = get_flow_actions(a[OVS_FLOW_ATTR_ACTIONS], &key, &mask);
if (IS_ERR(acts)) {
error = PTR_ERR(acts);
goto error;

ovs_flow_mask_key(&masked_key, &key, &mask);
error = ovs_nla_copy_actions(a[OVS_FLOW_ATTR_ACTIONS],
&masked_key, 0, &acts);
if (error) {
OVS_NLERR("Flow actions may not be safe on all matching packets.\n");
goto err_kfree_acts;
}
}

Expand Down

0 comments on commit 6b205b2

Please sign in to comment.