Update the netdev_class so that struct ofpbuf * is passed to rx_recv()
to provide both the data and size of the data to read a packet into.

This patch should not have any behavioural changes.

This patch is in preparation for the netdev-linux variant of rx_recv()
making use of headroom in the struct ofpbuf * parameter to push a VLAN tag
obtained from auxdata.

Signed-off-by: Simon Horman <ho...@verge.net.au>

---
v2
* First post
---
 lib/netdev-dummy.c    | 6 +++---
 lib/netdev-linux.c    | 7 ++++---
 lib/netdev-provider.h | 2 +-
 lib/netdev.c          | 3 +--
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index fd30454..5b363fa 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -447,7 +447,7 @@ netdev_dummy_rx_dealloc(struct netdev_rx *rx_)
 }
 
 static int
-netdev_dummy_rx_recv(struct netdev_rx *rx_, void *buffer, size_t size)
+netdev_dummy_rx_recv(struct netdev_rx *rx_, struct ofpbuf *buffer)
 {
     struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
     struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
@@ -467,8 +467,8 @@ netdev_dummy_rx_recv(struct netdev_rx *rx_, void *buffer, 
size_t size)
         return -EAGAIN;
     }
 
-    if (packet->size <= size) {
-        memcpy(buffer, packet->data, packet->size);
+    if (packet->size <= ofpbuf_tailroom(buffer)) {
+        memcpy(buffer->data, packet->data, packet->size);
         retval = packet->size;
 
         ovs_mutex_lock(&netdev->mutex);
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 3e0da48..a997a77 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -852,15 +852,16 @@ netdev_linux_rx_dealloc(struct netdev_rx *rx_)
 }
 
 static int
-netdev_linux_rx_recv(struct netdev_rx *rx_, void *data, size_t size)
+netdev_linux_rx_recv(struct netdev_rx *rx_, struct ofpbuf *buffer)
 {
     struct netdev_rx_linux *rx = netdev_rx_linux_cast(rx_);
     ssize_t retval;
+    size_t size = ofpbuf_tailroom(buffer);
 
     do {
         retval = (rx->is_tap
-                  ? read(rx->fd, data, size)
-                  : recv(rx->fd, data, size, MSG_TRUNC));
+                  ? read(rx->fd, buffer->data, size)
+                  : recv(rx->fd, buffer->data, size, MSG_TRUNC));
     } while (retval < 0 && errno == EINTR);
 
     if (retval >= 0) {
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 9ab58fb..db24ac5 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -643,7 +643,7 @@ struct netdev_class {
      * is longer than 'size' bytes.
      *
      * Specify NULL if this */
-    int (*rx_recv)(struct netdev_rx *rx, void *buffer, size_t size);
+    int (*rx_recv)(struct netdev_rx *rx, struct ofpbuf *buffer);
 
     /* Registers with the poll loop to wake up from the next call to
      * poll_block() when a packet is ready to be received with netdev_rx_recv()
diff --git a/lib/netdev.c b/lib/netdev.c
index 9aa6d27..d5b0d78 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -547,8 +547,7 @@ netdev_rx_recv(struct netdev_rx *rx, struct ofpbuf *buffer)
     ovs_assert(buffer->size == 0);
     ovs_assert(ofpbuf_tailroom(buffer) >= ETH_TOTAL_MIN);
 
-    retval = rx->netdev->netdev_class->rx_recv(rx, buffer->data,
-                                               ofpbuf_tailroom(buffer));
+    retval = rx->netdev->netdev_class->rx_recv(rx, buffer);
     if (retval >= 0) {
         COVERAGE_INC(netdev_received);
         buffer->size += retval;
-- 
1.8.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to