Skip to content

Commit 2ff3e4e

Browse files
author
Pravin B Shelar
committed
openvswitch: Remove pkt_key from OVS_CB
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>
1 parent c1f570a commit 2ff3e4e

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

‎net/openvswitch/actions.c‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "vport.h"
3939

4040
static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
41+
struct sw_flow_key *key,
4142
const struct nlattr *attr, int len);
4243

4344
static int make_writable(struct sk_buff *skb, int write_len)
@@ -410,16 +411,14 @@ static int do_output(struct datapath *dp, struct sk_buff *skb, int out_port)
410411
}
411412

412413
static int output_userspace(struct datapath *dp, struct sk_buff *skb,
413-
const struct nlattr *attr)
414+
struct sw_flow_key *key, const struct nlattr *attr)
414415
{
415416
struct dp_upcall_info upcall;
416417
const struct nlattr *a;
417418
int rem;
418419

419-
BUG_ON(!OVS_CB(skb)->pkt_key);
420-
421420
upcall.cmd = OVS_PACKET_CMD_ACTION;
422-
upcall.key = OVS_CB(skb)->pkt_key;
421+
upcall.key = key;
423422
upcall.userdata = NULL;
424423
upcall.portid = 0;
425424

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

447446
static int sample(struct datapath *dp, struct sk_buff *skb,
448-
const struct nlattr *attr)
447+
struct sw_flow_key *key, const struct nlattr *attr)
449448
{
450449
const struct nlattr *acts_list = NULL;
451450
const struct nlattr *a;
@@ -493,7 +492,7 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
493492
* return the error code and let the caller (also
494493
* do_execute_actions()) free skb on error.
495494
*/
496-
return do_execute_actions(dp, sample_skb, a, rem);
495+
return do_execute_actions(dp, sample_skb, key, a, rem);
497496
}
498497

499498
static int execute_set_action(struct sk_buff *skb,
@@ -544,6 +543,7 @@ static int execute_set_action(struct sk_buff *skb,
544543

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

571571
case OVS_ACTION_ATTR_USERSPACE:
572-
output_userspace(dp, skb, a);
572+
output_userspace(dp, skb, key, a);
573573
break;
574574

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

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

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

615616
OVS_CB(skb)->tun_key = NULL;
616-
return do_execute_actions(dp, skb, acts->actions, acts->actions_len);
617+
return do_execute_actions(dp, skb, key,
618+
acts->actions, acts->actions_len);
617619
}

‎net/openvswitch/datapath.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,9 @@ void ovs_dp_process_received_packet(struct vport *p, struct sk_buff *skb)
275275
}
276276

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

280279
ovs_flow_stats_update(OVS_CB(skb)->flow, key.tp.flags, skb);
281-
ovs_execute_actions(dp, skb);
280+
ovs_execute_actions(dp, skb, &key);
282281
stats_counter = &stats->n_hit;
283282

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

570569
OVS_CB(packet)->flow = flow;
571-
OVS_CB(packet)->pkt_key = &flow->key;
572570
packet->priority = flow->key.phy.priority;
573571
packet->mark = flow->key.phy.skb_mark;
574572

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

581579
local_bh_disable();
582-
err = ovs_execute_actions(dp, packet);
580+
err = ovs_execute_actions(dp, packet, &flow->key);
583581
local_bh_enable();
584582
rcu_read_unlock();
585583

‎net/openvswitch/datapath.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,11 @@ struct datapath {
9595
/**
9696
* struct ovs_skb_cb - OVS data in skb CB
9797
* @flow: The flow associated with this packet. May be %NULL if no flow.
98-
* @pkt_key: The flow information extracted from the packet. Must be nonnull.
9998
* @tun_key: Key for the tunnel that encapsulated this packet. NULL if the
10099
* packet is not being tunneled.
101100
*/
102101
struct ovs_skb_cb {
103102
struct sw_flow *flow;
104-
struct sw_flow_key *pkt_key;
105103
struct ovs_key_ipv4_tunnel *tun_key;
106104
};
107105
#define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
@@ -191,7 +189,8 @@ int ovs_dp_upcall(struct datapath *, struct sk_buff *,
191189
struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq,
192190
u8 cmd);
193191

194-
int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb);
192+
int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
193+
struct sw_flow_key *);
195194
void ovs_dp_notify_wq(struct work_struct *work);
196195

197196
#define OVS_NLERR(fmt, ...) \

0 commit comments

Comments
 (0)