diff mbox

[ovs-dev,1/2] dp-packet: New function dp_packet_get_send_len().

Message ID 20170802215824.10476-1-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff Aug. 2, 2017, 9:58 p.m. UTC
This function is useful in a few places for representing the packet's
length minus the cutlen.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 lib/dp-packet.h    | 12 ++++++++----
 lib/netdev-bsd.c   |  5 +----
 lib/netdev-dummy.c |  4 +---
 lib/netdev-linux.c |  5 +----
 4 files changed, 11 insertions(+), 15 deletions(-)
diff mbox

Patch

diff --git a/lib/dp-packet.h b/lib/dp-packet.h
index 4c0a30aae13b..9dbb611d95fb 100644
--- a/lib/dp-packet.h
+++ b/lib/dp-packet.h
@@ -533,12 +533,18 @@  dp_packet_set_cutlen(struct dp_packet *b, uint32_t max_len)
 }
 
 static inline uint32_t
-dp_packet_get_cutlen(struct dp_packet *b)
+dp_packet_get_cutlen(const struct dp_packet *b)
 {
     /* Always in valid range if user uses dp_packet_set_cutlen. */
     return b->cutlen;
 }
 
+static inline uint32_t
+dp_packet_get_send_len(const struct dp_packet *b)
+{
+    return dp_packet_size(b) - dp_packet_get_cutlen(b);
+}
+
 static inline void *
 dp_packet_data(const struct dp_packet *b)
 {
@@ -783,9 +789,7 @@  dp_packet_batch_apply_cutlen(struct dp_packet_batch *batch)
         struct dp_packet *packet;
 
         DP_PACKET_BATCH_FOR_EACH (packet, batch) {
-            uint32_t cutlen = dp_packet_get_cutlen(packet);
-
-            dp_packet_set_size(packet, dp_packet_size(packet) - cutlen);
+            dp_packet_set_size(packet, dp_packet_get_send_len(packet));
             dp_packet_reset_cutlen(packet);
         }
         batch->trunc = false;
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 6cc83d347795..8a4cdb3fa34d 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -697,10 +697,7 @@  netdev_bsd_send(struct netdev *netdev_, int qid OVS_UNUSED,
 
     for (i = 0; i < batch->count; i++) {
         const void *data = dp_packet_data(batch->packets[i]);
-        size_t size = dp_packet_size(batch->packets[i]);
-
-        /* Truncate the packet if it is configured. */
-        size -= dp_packet_get_cutlen(batch->packets[i]);
+        size_t size = dp_packet_get_send_len(batch->packets[i]);
 
         while (!error) {
             ssize_t retval;
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index cad781104782..5612500d8902 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -1065,15 +1065,13 @@  netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
     struct dp_packet *packet;
     DP_PACKET_BATCH_FOR_EACH(packet, batch) {
         const void *buffer = dp_packet_data(packet);
-        size_t size = dp_packet_size(packet);
+        size_t size = dp_packet_get_send_len(packet);
 
         if (batch->packets[i]->packet_type != htonl(PT_ETH)) {
             error = EPFNOSUPPORT;
             break;
         }
 
-        size -= dp_packet_get_cutlen(packet);
-
         if (size < ETH_HEADER_LEN) {
             error = EMSGSIZE;
             break;
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index e1d87019f7f2..5b4c643e4eec 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -1231,12 +1231,9 @@  netdev_linux_send(struct netdev *netdev_, int qid OVS_UNUSED,
     /* 'i' is incremented only if there's no error */
     for (int i = 0; i < batch->count; ) {
         const void *data = dp_packet_data(batch->packets[i]);
-        size_t size = dp_packet_size(batch->packets[i]);
+        size_t size = dp_packet_get_send_len(batch->packets[i]);
         ssize_t retval;
 
-        /* Truncate the packet if it is configured. */
-        size -= dp_packet_get_cutlen(batch->packets[i]);
-
         if (!is_tap_netdev(netdev_)) {
             /* Use our AF_PACKET socket to send to this device. */
             struct iovec iov;