[ovs-dev] [PATCH 04/11] lib/flow: Split flow_extract().

Jarno Rajahalme jarno.rajahalme at nsn.com
Mon Feb 11 14:46:20 UTC 2013


Split flow_extract() to flow_extract() and flow_extract_l2_onwards().
This allows extracting while keeping existing packet metadata in the flow.

Signed-off-by: Jarno Rajahalme <jarno.rajahalme at nsn.com>
---
 lib/flow.c |   33 +++++++++++++++++++++++++++++----
 lib/flow.h |    1 +
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index 5e7d1d4..525fb71 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -356,10 +356,6 @@ flow_extract(struct ofpbuf *packet, uint32_t skb_priority, uint32_t skb_mark,
              const struct flow_tnl *tnl, uint16_t ofp_in_port,
              struct flow *flow)
 {
-    struct ofpbuf b = *packet;
-    struct eth_header *eth;
-
-    COVERAGE_INC(flow_extract);
 
     memset(flow, 0, sizeof *flow);
 
@@ -371,6 +367,35 @@ flow_extract(struct ofpbuf *packet, uint32_t skb_priority, uint32_t skb_mark,
     flow->skb_priority = skb_priority;
     flow->skb_mark = skb_mark;
 
+    flow_extract_l2_onwards(packet, flow);
+}
+
+/* Initializes l2 and higher 'flow' members from 'packet'
+ *
+ * Initializes 'packet' header pointers as follows:
+ *
+ *    - packet->l2 to the start of the Ethernet header.
+ *
+ *    - packet->l2_5 to the start of the MPLS shim header.
+ *
+ *    - packet->l3 to just past the Ethernet header, or just past the
+ *      vlan_header if one is present, to the first byte of the payload of the
+ *      Ethernet frame.
+ *
+ *    - packet->l4 to just past the IPv4 header, if one is present and has a
+ *      correct length, and otherwise NULL.
+ *
+ *    - packet->l7 to just past the TCP or UDP or ICMP header, if one is
+ *      present and has a correct length, and otherwise NULL.
+ */
+void
+flow_extract_l2_onwards(struct ofpbuf *packet, struct flow *flow)
+{
+    struct ofpbuf b = *packet;
+    struct eth_header *eth;
+
+    COVERAGE_INC(flow_extract);
+
     packet->l2   = b.data;
     packet->l2_5 = NULL;
     packet->l3   = NULL;
diff --git a/lib/flow.h b/lib/flow.h
index e6da480..55940ec 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -126,6 +126,7 @@ struct flow_metadata {
 
 void flow_extract(struct ofpbuf *, uint32_t priority, uint32_t mark,
                   const struct flow_tnl *, uint16_t in_port, struct flow *);
+void flow_extract_l2_onwards(struct ofpbuf *, struct flow *);
 void flow_extract_l3_onwards(struct ofpbuf *, struct flow *,
                              ovs_be16 dl_type);
 
-- 
1.7.10.4




More information about the dev mailing list