[ovs-dev] [PATCH 3/4] datapath: Refactor ovs_dp_process_packet()
Andy Zhou
azhou at nicira.com
Fri Aug 15 10:12:12 UTC 2014
Split ovs_dp_packet_flow_lookup() into its own API. In preparation for
the next patch.
Signed-off-by: Andy Zhou <azhou at nicira.com>
---
datapath/datapath.c | 27 ++++++++++++++++++++-------
datapath/datapath.h | 1 +
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/datapath/datapath.c b/datapath/datapath.c
index aa13817..bcfdd62 100644
--- a/datapath/datapath.c
+++ b/datapath/datapath.c
@@ -252,23 +252,23 @@ void ovs_dp_detach_port(struct vport *p)
}
/* Must be called with rcu_read_lock. */
-void ovs_dp_process_packet(struct sk_buff *skb)
+bool ovs_dp_packet_flow_lookup(struct datapath *dp, struct sk_buff *skb)
{
- const struct vport *p = OVS_CB(skb)->input_vport;
struct sw_flow_key *pkt_key = OVS_CB(skb)->pkt_key;
- struct datapath *dp = p->dp;
struct sw_flow *flow;
struct dp_stats_percpu *stats;
u64 *stats_counter;
u32 n_mask_hit;
+ bool found;
stats = this_cpu_ptr(dp->stats_percpu);
/* Look up flow. */
- flow = ovs_flow_tbl_lookup_stats(&dp->table, pkt_key, skb_get_hash(skb),
- &n_mask_hit);
+ flow = ovs_flow_tbl_lookup_stats(&dp->table, pkt_key,
+ skb_get_hash(skb), &n_mask_hit);
if (unlikely(!flow)) {
struct dp_upcall_info upcall;
+ const struct vport *p = OVS_CB(skb)->input_vport;
upcall.cmd = OVS_PACKET_CMD_MISS;
upcall.userdata = NULL;
@@ -276,13 +276,14 @@ void ovs_dp_process_packet(struct sk_buff *skb)
ovs_dp_upcall(dp, skb, &upcall);
consume_skb(skb);
stats_counter = &stats->n_missed;
+ found = false;
goto out;
}
OVS_CB(skb)->flow = flow;
+ found = true;
- ovs_flow_stats_update(OVS_CB(skb)->flow, pkt_key->tp.flags, skb);
- ovs_execute_actions(dp, skb);
+ ovs_flow_stats_update(flow, pkt_key->tp.flags, skb);
stats_counter = &stats->n_hit;
out:
@@ -291,6 +292,18 @@ out:
(*stats_counter)++;
stats->n_mask_hit += n_mask_hit;
u64_stats_update_end(&stats->sync);
+
+ return found;
+}
+
+/* Must be called with rcu_read_lock. */
+void ovs_dp_process_packet(struct sk_buff *skb)
+{
+ const struct vport *p = OVS_CB(skb)->input_vport;
+ struct datapath *dp = p->dp;
+
+ if (ovs_dp_packet_flow_lookup(dp, skb))
+ ovs_execute_actions(dp, skb);
}
int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
diff --git a/datapath/datapath.h b/datapath/datapath.h
index 73f4e14..38cdc23 100644
--- a/datapath/datapath.h
+++ b/datapath/datapath.h
@@ -190,6 +190,7 @@ extern struct genl_family dp_vport_genl_family;
extern struct genl_multicast_group ovs_dp_vport_multicast_group;
void ovs_dp_process_packet(struct sk_buff *c);
+bool ovs_dp_packet_flow_lookup(struct datapath *dp, struct sk_buff *c);
void ovs_dp_detach_port(struct vport *);
int ovs_dp_upcall(struct datapath *, struct sk_buff *,
const struct dp_upcall_info *);
--
1.9.1
More information about the dev
mailing list