Skip to content

Commit

Permalink
openvswitch: Remove pkt_key from OVS_CB
Browse files Browse the repository at this point in the history
OVS keeps pointer to packet key in skb->cb, but the packet key is
store on stack. This could make code bit tricky. So it is better to
get rid of the pointer.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
  • Loading branch information
Pravin B Shelar committed Sep 16, 2014
1 parent c1f570a commit 2ff3e4e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
22 changes: 12 additions & 10 deletions net/openvswitch/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "vport.h"

static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
struct sw_flow_key *key,
const struct nlattr *attr, int len);

static int make_writable(struct sk_buff *skb, int write_len)
Expand Down Expand Up @@ -410,16 +411,14 @@ static int do_output(struct datapath *dp, struct sk_buff *skb, int out_port)
}

static int output_userspace(struct datapath *dp, struct sk_buff *skb,
const struct nlattr *attr)
struct sw_flow_key *key, const struct nlattr *attr)
{
struct dp_upcall_info upcall;
const struct nlattr *a;
int rem;

BUG_ON(!OVS_CB(skb)->pkt_key);

upcall.cmd = OVS_PACKET_CMD_ACTION;
upcall.key = OVS_CB(skb)->pkt_key;
upcall.key = key;
upcall.userdata = NULL;
upcall.portid = 0;

Expand All @@ -445,7 +444,7 @@ static bool last_action(const struct nlattr *a, int rem)
}

static int sample(struct datapath *dp, struct sk_buff *skb,
const struct nlattr *attr)
struct sw_flow_key *key, const struct nlattr *attr)
{
const struct nlattr *acts_list = NULL;
const struct nlattr *a;
Expand Down Expand Up @@ -493,7 +492,7 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
* return the error code and let the caller (also
* do_execute_actions()) free skb on error.
*/
return do_execute_actions(dp, sample_skb, a, rem);
return do_execute_actions(dp, sample_skb, key, a, rem);
}

static int execute_set_action(struct sk_buff *skb,
Expand Down Expand Up @@ -544,6 +543,7 @@ static int execute_set_action(struct sk_buff *skb,

/* Execute a list of actions against 'skb'. */
static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
struct sw_flow_key *key,
const struct nlattr *attr, int len)
{
/* Every output action needs a separate clone of 'skb', but the common
Expand All @@ -569,7 +569,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
break;

case OVS_ACTION_ATTR_USERSPACE:
output_userspace(dp, skb, a);
output_userspace(dp, skb, key, a);
break;

case OVS_ACTION_ATTR_PUSH_VLAN:
Expand All @@ -587,7 +587,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
break;

case OVS_ACTION_ATTR_SAMPLE:
err = sample(dp, skb, a);
err = sample(dp, skb, key, a);
if (unlikely(err)) /* skb already freed. */
return err;
break;
Expand All @@ -608,10 +608,12 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
}

/* Execute a list of actions against 'skb'. */
int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb)
int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
struct sw_flow_key *key)
{
struct sw_flow_actions *acts = rcu_dereference(OVS_CB(skb)->flow->sf_acts);

OVS_CB(skb)->tun_key = NULL;
return do_execute_actions(dp, skb, acts->actions, acts->actions_len);
return do_execute_actions(dp, skb, key,
acts->actions, acts->actions_len);
}
6 changes: 2 additions & 4 deletions net/openvswitch/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,9 @@ void ovs_dp_process_received_packet(struct vport *p, struct sk_buff *skb)
}

OVS_CB(skb)->flow = flow;
OVS_CB(skb)->pkt_key = &key;

ovs_flow_stats_update(OVS_CB(skb)->flow, key.tp.flags, skb);
ovs_execute_actions(dp, skb);
ovs_execute_actions(dp, skb, &key);
stats_counter = &stats->n_hit;

out:
Expand Down Expand Up @@ -568,7 +567,6 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
goto err_flow_free;

OVS_CB(packet)->flow = flow;
OVS_CB(packet)->pkt_key = &flow->key;
packet->priority = flow->key.phy.priority;
packet->mark = flow->key.phy.skb_mark;

Expand All @@ -579,7 +577,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
goto err_unlock;

local_bh_disable();
err = ovs_execute_actions(dp, packet);
err = ovs_execute_actions(dp, packet, &flow->key);
local_bh_enable();
rcu_read_unlock();

Expand Down
5 changes: 2 additions & 3 deletions net/openvswitch/datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,11 @@ struct datapath {
/**
* struct ovs_skb_cb - OVS data in skb CB
* @flow: The flow associated with this packet. May be %NULL if no flow.
* @pkt_key: The flow information extracted from the packet. Must be nonnull.
* @tun_key: Key for the tunnel that encapsulated this packet. NULL if the
* packet is not being tunneled.
*/
struct ovs_skb_cb {
struct sw_flow *flow;
struct sw_flow_key *pkt_key;
struct ovs_key_ipv4_tunnel *tun_key;
};
#define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
Expand Down Expand Up @@ -191,7 +189,8 @@ int ovs_dp_upcall(struct datapath *, struct sk_buff *,
struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq,
u8 cmd);

int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb);
int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
struct sw_flow_key *);
void ovs_dp_notify_wq(struct work_struct *work);

#define OVS_NLERR(fmt, ...) \
Expand Down

0 comments on commit 2ff3e4e

Please sign in to comment.