- /* Bail out if we're not allowed to modify an existing flow. */
- error = -EEXIST;
- if (!(uf->flags & ODPPF_MODIFY))
- goto error;
-
- /* Swap actions. */
- new_acts = get_actions(&uf->flow);
- error = PTR_ERR(new_acts);
- if (IS_ERR(new_acts))
- goto error;
- old_acts = rcu_dereference(flow->sf_acts);
- if (old_acts->actions_len != new_acts->actions_len ||
- memcmp(old_acts->actions, new_acts->actions,
- old_acts->actions_len)) {
- rcu_assign_pointer(flow->sf_acts, new_acts);
- flow_deferred_free_acts(old_acts);
- } else {
- kfree(new_acts);
- }
-
- /* Fetch stats, then clear them if necessary. */
- spin_lock_bh(&flow->lock);
- get_stats(flow, stats);
- if (uf->flags & ODPPF_ZERO_STATS)
- clear_stats(flow);
- spin_unlock_bh(&flow->lock);
- }
-
- return 0;
-
-error_free_flow_acts:
- kfree(flow->sf_acts);
-error_free_flow:
- flow->sf_acts = NULL;
- flow_put(flow);
-error:
- return error;
-}
-
-static int put_flow(struct datapath *dp, struct odp_flow_put __user *ufp)
-{
- struct odp_flow_stats stats;
- struct odp_flow_put uf;
- int error;
-
- if (copy_from_user(&uf, ufp, sizeof(struct odp_flow_put)))
- return -EFAULT;
-
- error = do_put_flow(dp, &uf, &stats);
- if (error)
- return error;
-
- if (copy_to_user(&ufp->flow.stats, &stats,
- sizeof(struct odp_flow_stats)))
- return -EFAULT;
-
- return 0;
-}
-
-static int do_answer_query(struct sw_flow *flow, u32 query_flags,
- struct odp_flow_stats __user *ustats,
- struct nlattr __user *actions,
- u32 __user *actions_lenp)
-{
- struct sw_flow_actions *sf_acts;
- struct odp_flow_stats stats;
- u32 actions_len;
-
- spin_lock_bh(&flow->lock);
- get_stats(flow, &stats);
- if (query_flags & ODPFF_ZERO_TCP_FLAGS)
- flow->tcp_flags = 0;
-
- spin_unlock_bh(&flow->lock);
-
- if (copy_to_user(ustats, &stats, sizeof(struct odp_flow_stats)) ||
- get_user(actions_len, actions_lenp))
- return -EFAULT;
-
- if (!actions_len)
- return 0;
-
- sf_acts = rcu_dereference(flow->sf_acts);
- if (put_user(sf_acts->actions_len, actions_lenp) ||
- (actions && copy_to_user(actions, sf_acts->actions,
- min(sf_acts->actions_len, actions_len))))
- return -EFAULT;