Commit e66097ab authored by Alex Wang's avatar Alex Wang Committed by Kamal Mostafa

openvswitch: Use exact lookup for flow_get and flow_del.

commit 4a46b24e upstream.

BugLink: http://bugs.launchpad.net/bugs/1408972

Due to the race condition in userspace, there is chance that two
overlapping megaflows could be installed in datapath.  And this
causes userspace unable to delete the less inclusive megaflow flow
even after it timeout, since the flow_del logic will stop at the
first match of masked flow.

This commit fixes the bug by making the kernel flow_del and flow_get
logic check all masks in that case.

Introduced by 03f0d916 (openvswitch: Mega flow implementation).
Signed-off-by: default avatarAlex Wang <alexw@nicira.com>
Acked-by: default avatarAndy Zhou <azhou@nicira.com>
Signed-off-by: default avatarPravin B Shelar <pshelar@nicira.com>
(backported from commit 4a46b24e)
Signed-off-by: default avatarJoseph Salisbury <joseph.salisbury@canonical.com>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent 72944b29
...@@ -852,10 +852,12 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) ...@@ -852,10 +852,12 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
goto err_unlock_ovs; goto err_unlock_ovs;
/* The unmasked key has to be the same for flow updates. */ /* The unmasked key has to be the same for flow updates. */
error = -EINVAL;
if (!ovs_flow_cmp_unmasked_key(flow, &match)) { if (!ovs_flow_cmp_unmasked_key(flow, &match)) {
OVS_NLERR("Flow modification message rejected, unmasked key does not match.\n"); flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
goto err_unlock_ovs; if (!flow) {
error = -ENOENT;
goto err_unlock_ovs;
}
} }
/* Update actions. */ /* Update actions. */
...@@ -873,6 +875,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info) ...@@ -873,6 +875,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
spin_unlock_bh(&flow->lock); spin_unlock_bh(&flow->lock);
} }
} }
ovs_unlock(); ovs_unlock();
if (!IS_ERR(reply)) if (!IS_ERR(reply))
...@@ -920,8 +923,8 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info) ...@@ -920,8 +923,8 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info)
goto unlock; goto unlock;
} }
flow = __ovs_flow_tbl_lookup(&dp->table, &key); flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
if (!flow || !ovs_flow_cmp_unmasked_key(flow, &match)) { if (!flow) {
err = -ENOENT; err = -ENOENT;
goto unlock; goto unlock;
} }
...@@ -968,8 +971,8 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info) ...@@ -968,8 +971,8 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
if (err) if (err)
goto unlock; goto unlock;
flow = __ovs_flow_tbl_lookup(&dp->table, &key); flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
if (!flow || !ovs_flow_cmp_unmasked_key(flow, &match)) { if (unlikely(!flow)) {
err = -ENOENT; err = -ENOENT;
goto unlock; goto unlock;
} }
......
...@@ -447,6 +447,22 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl, ...@@ -447,6 +447,22 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl,
return NULL; return NULL;
} }
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
struct sw_flow_match *match)
{
struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
struct sw_flow_mask *mask;
struct sw_flow *flow;
/* Always called under ovs-mutex. */
list_for_each_entry(mask, &tbl->mask_list, list) {
flow = masked_flow_lookup(ti, match->key, mask);
if (flow && ovs_flow_cmp_unmasked_key(flow, match)) /* Found */
return flow;
}
return NULL;
}
int ovs_flow_tbl_num_masks(const struct flow_table *table) int ovs_flow_tbl_num_masks(const struct flow_table *table)
{ {
struct sw_flow_mask *mask; struct sw_flow_mask *mask;
......
...@@ -72,7 +72,8 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table, ...@@ -72,7 +72,8 @@ struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *, struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
const struct sw_flow_key *, const struct sw_flow_key *,
u32 *n_mask_hit); u32 *n_mask_hit);
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
struct sw_flow_match *match);
bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow, bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
struct sw_flow_match *match); struct sw_flow_match *match);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment