[ovs-dev] [PATCH 11/11] dpif-netdev: pass layer pointers and key hash like dpif-linux.

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


Signed-off-by: Jarno Rajahalme <jarno.rajahalme at nsn.com>
---
 lib/dpif-netdev.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index bd3d4d6..4097781 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -886,6 +886,8 @@ dpif_netdev_flow_dump_next(const struct dpif *dpif, void *state_,
         struct ofpbuf buf;
 
         ofpbuf_use_stack(&buf, &state->keybuf, sizeof state->keybuf);
+        /* Put a hash corresponding to the key as the first key atribute */
+        nl_msg_put_u32(&buf, OVS_KEY_ATTR_HASH, node->hash);
         odp_flow_key_from_flow(&buf, &flow->key, flow->key.in_port);
 
         *key = buf.data;
@@ -993,7 +995,9 @@ dpif_netdev_recv(struct dpif *dpif, struct dpif_upcall upcalls[],
         upcalls[n].packet = &bufs[n];
         bufs[n] = u->buf;
         /* Packet starts with an Ethernet frame */
-        upcalls[n].packet->l2 = upcalls[n].packet->data;
+        if (upcalls[n].packet->l2 == NULL) {
+            upcalls[n].packet->l2 = upcalls[n].packet->data;
+        }
     }
     *n_bufs = n;
     return (n > 0) ? 0 : EAGAIN;
@@ -1117,6 +1121,7 @@ dp_netdev_output_userspace(struct dp_netdev *dp, const struct ofpbuf *packet,
     struct dpif_upcall *upcall;
     struct ofpbuf *buf;
     size_t key_len;
+    uintptr_t data_delta;
 
     if (q->head - q->tail >= MAX_QUEUE_LEN) {
         dp->n_lost++;
@@ -1127,12 +1132,36 @@ dp_netdev_output_userspace(struct dp_netdev *dp, const struct ofpbuf *packet,
 
     buf = &u->buf;
     ofpbuf_init(buf, ODPUTIL_FLOW_KEY_BYTES + 2 + packet->size);
+    /* Put a hash corresponding to the key as the first key atribute */
+    nl_msg_put_u32(buf, OVS_KEY_ATTR_HASH, flow_hash(flow, 0));
     odp_flow_key_from_flow(buf, flow, flow->in_port);
     key_len = buf->size;
     ofpbuf_pull(buf, key_len);
     ofpbuf_reserve(buf, 2);
+
+    data_delta = (char *) buf->data - (char *) packet->data;
+
     ofpbuf_put(buf, packet->data, packet->size);
 
+    /* Pass the same layer pointers as dpif-linux does. */
+    if (packet->l2) {
+        buf->l2 = (char *) packet->l2 + data_delta;
+    }
+    if (packet->l2_5) {
+        buf->l2_5 = (char *) packet->l2_5 + data_delta;
+    }
+    if (packet->l3) {
+        buf->l3 = (char *) packet->l3 + data_delta;
+    }
+    if (packet->l4) {
+        buf->l4 = (char *) packet->l4 + data_delta;
+    }
+    /*
+    if (packet->l7) {
+        buf->l7 = (char *) packet->l7 + data_delta;
+    }
+    */
+
     upcall = &u->upcall;
     upcall->type = queue_no;
     upcall->packet = buf;
-- 
1.7.10.4




More information about the dev mailing list