netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / lib / dp-packet.c
index 88b5708..db3c857 100644 (file)
 static void
 dp_packet_init__(struct dp_packet *b, size_t allocated, enum dp_packet_source source)
 {
-    b->allocated = allocated;
+    dp_packet_set_allocated(b, allocated);
     b->source = source;
-    b->frame = NULL;
-    b->l2_pad_size = 0;
-    b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX;
-    b->md = PKT_METADATA_INITIALIZER(0);
-    list_poison(&b->list_node);
+    dp_packet_reset_offsets(b);
+    pkt_metadata_init(&b->md, 0);
 }
 
 static void
@@ -165,12 +162,6 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom)
     new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
                                                  dp_packet_size(buffer),
                                                  headroom);
-    if (buffer->frame) {
-        uintptr_t data_delta
-            = (char *)dp_packet_data(new_buffer) - (char *)dp_packet_data(buffer);
-
-        new_buffer->frame = (char *) buffer->frame + data_delta;
-    }
     new_buffer->l2_pad_size = buffer->l2_pad_size;
     new_buffer->l2_5_ofs = buffer->l2_5_ofs;
     new_buffer->l3_ofs = buffer->l3_ofs;
@@ -251,16 +242,11 @@ dp_packet_resize__(struct dp_packet *b, size_t new_headroom, size_t new_tailroom
         OVS_NOT_REACHED();
     }
 
-    b->allocated = new_allocated;
+    dp_packet_set_allocated(b, new_allocated);
     dp_packet_set_base(b, new_base);
 
     new_data = (char *) new_base + new_headroom;
     if (dp_packet_data(b) != new_data) {
-        if (b->frame) {
-            uintptr_t data_delta = (char *) new_data - (char *) dp_packet_data(b);
-
-            b->frame = (char *) b->frame + data_delta;
-        }
         dp_packet_set_data(b, new_data);
     }
 }
@@ -445,34 +431,6 @@ dp_packet_steal_data(struct dp_packet *b)
     return p;
 }
 
-/* Returns a string that describes some of 'b''s metadata plus a hex dump of up
- * to 'maxbytes' from the start of the buffer. */
-char *
-dp_packet_to_string(const struct dp_packet *b, size_t maxbytes)
-{
-    struct ds s;
-
-    ds_init(&s);
-    ds_put_format(&s, "size=%"PRIu32", allocated=%"PRIu32", head=%"PRIuSIZE", tail=%"PRIuSIZE"\n",
-                  dp_packet_size(b), b->allocated,
-                  dp_packet_headroom(b), dp_packet_tailroom(b));
-    ds_put_hex_dump(&s, dp_packet_data(b), MIN(dp_packet_size(b), maxbytes), 0, false);
-    return ds_cstr(&s);
-}
-
-/* Removes each of the "struct dp_packet"s on 'list' from the list and frees
- * them.  */
-void
-dp_packet_list_delete(struct ovs_list *list)
-{
-    struct dp_packet *b, *next;
-
-    LIST_FOR_EACH_SAFE (b, next, list_node, list) {
-        list_remove(&b->list_node);
-        dp_packet_delete(b);
-    }
-}
-
 static inline void
 dp_packet_adjust_layer_offset(uint16_t *offset, int increment)
 {
@@ -493,12 +451,11 @@ dp_packet_resize_l2_5(struct dp_packet *b, int increment)
         dp_packet_pull(b, -increment);
     }
 
-    b->frame = dp_packet_data(b);
     /* Adjust layer offsets after l2_5. */
     dp_packet_adjust_layer_offset(&b->l3_ofs, increment);
     dp_packet_adjust_layer_offset(&b->l4_ofs, increment);
 
-    return b->frame;
+    return dp_packet_data(b);
 }
 
 /* Adjust the size of the l2 portion of the dp_packet, updating the l2
@@ -509,5 +466,5 @@ dp_packet_resize_l2(struct dp_packet *b, int increment)
 {
     dp_packet_resize_l2_5(b, increment);
     dp_packet_adjust_layer_offset(&b->l2_5_ofs, increment);
-    return b->frame;
+    return dp_packet_data(b);
 }