@@ -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;
@@ -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;
@@ -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;
@@ -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;
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(-)