free(this);
}
-METHOD(packet_t, clone_, packet_t*,
- private_packet_t *this)
+/**
+ * Clone the packet with or without data
+ */
+static packet_t *clone_packet(private_packet_t *this, bool skip_data)
{
private_packet_t *other;
{
set_source(other, this->source->clone(this->source));
}
- if (this->data.ptr)
+ other->metadata = metadata_set_clone(this->metadata);
+ set_dscp(other, this->dscp);
+
+ if (!skip_data && this->data.ptr)
{
set_data(other, chunk_clone(this->adjusted_data));
}
- other->metadata = metadata_set_clone(this->metadata);
- set_dscp(other, this->dscp);
return &other->public;
}
+METHOD(packet_t, clone_, packet_t*,
+ private_packet_t *this)
+{
+ return clone_packet(this, FALSE);
+}
+
+/*
+ * Described in header
+ */
+packet_t *packet_clone_no_data(packet_t *packet)
+{
+ return clone_packet((private_packet_t*)packet, TRUE);
+}
+
/**
* Described in header.
*/
* @param src source address (gets owned)
* @param dst destination address (gets owned)
* @param data packet data (gets owned)
- * @return packet_t object
+ * @return packet_t object
*/
packet_t *packet_create_from_data(host_t *src, host_t *dst, chunk_t data);
+/**
+ * Create a clone of the given packet but without data
+ *
+ * @param packet packet to clone
+ * @return cloned packet
+ */
+packet_t *packet_clone_no_data(packet_t *packet);
+
#endif /** PACKET_H_ @}*/