[ovs-dev] [PATCH 01/12] dpif_netdev_execute: Extract flow key from the packet.

Jarno Rajahalme jrajahalme at nicira.com
Fri Nov 8 18:54:33 UTC 2013


Extract the flow key from the packet instead of the execute->key.
This reflects how the kernel datapath behaves.

Also use ofpbuf_clone_with_headroom() instead of open coding the same.

Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
 lib/dpif-netdev.c |   27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 1b0039c..94f6dc3 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1030,8 +1030,7 @@ static int
 dpif_netdev_execute(struct dpif *dpif, const struct dpif_execute *execute)
 {
     struct dp_netdev *dp = get_dp_netdev(dpif);
-    struct ofpbuf copy;
-    struct flow key;
+    struct flow md;
     int error;
 
     if (execute->packet->size < ETH_HEADER_LEN ||
@@ -1039,22 +1038,24 @@ dpif_netdev_execute(struct dpif *dpif, const struct dpif_execute *execute)
         return EINVAL;
     }
 
-    /* Make a deep copy of 'packet', because we might modify its data. */
-    ofpbuf_init(&copy, DP_NETDEV_HEADROOM + execute->packet->size);
-    ofpbuf_reserve(&copy, DP_NETDEV_HEADROOM);
-    ofpbuf_put(&copy, execute->packet->data, execute->packet->size);
-
-    flow_extract(&copy, 0, 0, NULL, NULL, &key);
-    error = dpif_netdev_flow_from_nlattrs(execute->key, execute->key_len,
-                                          &key);
+    /* Get packet metadata. */
+    error = dpif_netdev_flow_from_nlattrs(execute->key, execute->key_len, &md);
     if (!error) {
+        struct ofpbuf *copy;
+        struct flow key;
+
+        /* Make a deep copy of 'packet', because we might modify its data. */
+        copy = ofpbuf_clone_with_headroom(execute->packet, DP_NETDEV_HEADROOM);
+
+        /* Extract flow key. */
+        flow_extract(copy, md.skb_priority, md.pkt_mark, &md.tunnel,
+                     &md.in_port, &key);
         ovs_mutex_lock(&dp_netdev_mutex);
-        dp_netdev_execute_actions(dp, &copy, &key,
+        dp_netdev_execute_actions(dp, copy, &key,
                                   execute->actions, execute->actions_len);
         ovs_mutex_unlock(&dp_netdev_mutex);
+        ofpbuf_delete(copy);
     }
-
-    ofpbuf_uninit(&copy);
     return error;
 }
 
-- 
1.7.10.4




More information about the dev mailing list