[ovs-dev] [PATCH 03/12] dpif: Allow execute to modify the packet.

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


This is how the users already use the interface, and this allows
less copying at the userspace datapath.

Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
 lib/dpif-linux.c    |    2 +-
 lib/dpif-netdev.c   |   11 +++--------
 lib/dpif-provider.h |    2 +-
 lib/dpif.c          |    7 +++----
 lib/dpif.h          |    5 ++---
 5 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
index 42958d3..bfea02d 100644
--- a/lib/dpif-linux.c
+++ b/lib/dpif-linux.c
@@ -1086,7 +1086,7 @@ dpif_linux_execute__(int dp_ifindex, const struct dpif_execute *execute)
 }
 
 static int
-dpif_linux_execute(struct dpif *dpif_, const struct dpif_execute *execute)
+dpif_linux_execute(struct dpif *dpif_, struct dpif_execute *execute)
 {
     const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
 
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index c9bcc5e..9e1ade5 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1027,7 +1027,7 @@ dpif_netdev_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *state_)
 }
 
 static int
-dpif_netdev_execute(struct dpif *dpif, const struct dpif_execute *execute)
+dpif_netdev_execute(struct dpif *dpif, struct dpif_execute *execute)
 {
     struct dp_netdev *dp = get_dp_netdev(dpif);
     struct flow md;
@@ -1041,20 +1041,15 @@ dpif_netdev_execute(struct dpif *dpif, const struct dpif_execute *execute)
     /* 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,
+        flow_extract(execute->packet, md.skb_priority, md.pkt_mark, &md.tunnel,
                      &md.in_port, &key);
         ovs_mutex_lock(&dp_netdev_mutex);
-        dp_netdev_execute_actions(dp, &key, copy,
+        dp_netdev_execute_actions(dp, &key, execute->packet,
                                   execute->actions, execute->actions_len);
         ovs_mutex_unlock(&dp_netdev_mutex);
-        ofpbuf_delete(copy);
     }
     return error;
 }
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index 1afac99..c5f8b04 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -316,7 +316,7 @@ struct dpif_class {
      * 'execute->key'.  ('execute->key' is mostly redundant with
      * 'execute->packet', but it contains some metadata that cannot be
      * recovered from 'execute->packet', such as tunnel and in_port.) */
-    int (*execute)(struct dpif *dpif, const struct dpif_execute *execute);
+    int (*execute)(struct dpif *dpif, struct dpif_execute *execute);
 
     /* Executes each of the 'n_ops' operations in 'ops' on 'dpif', in the order
      * in which they are specified, placing each operation's results in the
diff --git a/lib/dpif.c b/lib/dpif.c
index 783a7cb..dd77ebf 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -1116,7 +1116,7 @@ dpif_execute_helper_userspace_cb(void *aux, struct ofpbuf *packet,
  *
  * This helps with actions that a given 'dpif' doesn't implement directly. */
 static int
-dpif_execute_with_help(struct dpif *dpif, const struct dpif_execute *execute)
+dpif_execute_with_help(struct dpif *dpif, struct dpif_execute *execute)
 {
     struct dpif_execute_helper_aux aux;
     enum odp_key_fitness fit;
@@ -1144,7 +1144,7 @@ dpif_execute_with_help(struct dpif *dpif, const struct dpif_execute *execute)
 }
 
 static int
-dpif_execute__(struct dpif *dpif, const struct dpif_execute *execute)
+dpif_execute__(struct dpif *dpif, struct dpif_execute *execute)
 {
     int error;
 
@@ -1182,8 +1182,7 @@ int
 dpif_execute(struct dpif *dpif,
              const struct nlattr *key, size_t key_len,
              const struct nlattr *actions, size_t actions_len,
-             const struct ofpbuf *buf,
-             bool needs_help)
+             struct ofpbuf *buf, bool needs_help)
 {
     struct dpif_execute execute;
 
diff --git a/lib/dpif.h b/lib/dpif.h
index 6db6ad3..3bf3688 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -495,8 +495,7 @@ int dpif_flow_dump_done(struct dpif_flow_dump *);
 int dpif_execute(struct dpif *,
                  const struct nlattr *key, size_t key_len,
                  const struct nlattr *actions, size_t actions_len,
-                 const struct ofpbuf *,
-                 bool needs_help);
+                 struct ofpbuf *, bool needs_help);
 
 /* Operation batching interface.
  *
@@ -539,7 +538,7 @@ struct dpif_execute {
     size_t key_len;                 /* Length of 'key' in bytes. */
     const struct nlattr *actions;   /* Actions to execute on packet. */
     size_t actions_len;             /* Length of 'actions' in bytes. */
-    const struct ofpbuf *packet;    /* Packet to execute. */
+    struct ofpbuf *packet;          /* Packet to execute. */
 
     /* Some dpif providers do not implement every action.  The Linux kernel
      * datapath, in particular, does not implement ARP field modification.
-- 
1.7.10.4




More information about the dev mailing list