]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
packet: add set functions for some packet fields
authorJason Ish <jason.ish@oisf.net>
Wed, 9 Oct 2024 18:30:43 +0000 (12:30 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 1 Apr 2025 08:17:05 +0000 (10:17 +0200)
- SCPacketSetReleasePacket
- SCPacketSetLiveDevice
- SCPacketSetDatalink
- SCPacketSetTime
- SCPacketSetSource

Prevents direct access by library users and provides more ABI
stability.

Ticket: #7240

src/packet.c
src/packet.h

index cb6dcf618380f6bdc9ab6f7696f3db7aed7aaba9..22d282f77b2111b22e5c6f6f753fcbe196d79e43 100644 (file)
@@ -161,3 +161,28 @@ void PacketDestructor(Packet *p)
     AppLayerDecoderEventsFreeEvents(&p->app_layer_events);
     PACKET_PROFILING_RESET(p);
 }
+
+inline void SCPacketSetReleasePacket(Packet *p, void (*ReleasePacket)(Packet *p))
+{
+    p->ReleasePacket = ReleasePacket;
+}
+
+inline void SCPacketSetLiveDevice(Packet *p, LiveDevice *device)
+{
+    p->livedev = device;
+}
+
+inline void SCPacketSetDatalink(Packet *p, int datalink)
+{
+    p->datalink = datalink;
+}
+
+inline void SCPacketSetTime(Packet *p, SCTime_t ts)
+{
+    p->ts = ts;
+}
+
+inline void SCPacketSetSource(Packet *p, enum PktSrcEnum source)
+{
+    p->pkt_src = (uint8_t)source;
+}
index 0b03a59631925224560f5a362d77ee8cf0d8468f..633b118d3bf309e26bb414a6c2e358d5cff14f42 100644 (file)
@@ -19,6 +19,7 @@
 #define SURICATA_PACKET_H
 
 #include "decode.h"
+#include "util-device.h"
 
 void PacketDrop(Packet *p, const uint8_t action, enum PacketDropReason r);
 bool PacketCheckAction(const Packet *p, const uint8_t a);
@@ -36,4 +37,31 @@ void PacketReinit(Packet *p);
 void PacketRecycle(Packet *p);
 void PacketDestructor(Packet *p);
 
+/** \brief Set a packet release function.
+ *
+ * Set a custom release function for packet. This is required if extra
+ * non-standard packet was done that needs to be cleaned up when
+ * Suricata is done with a packet.
+ *
+ * Its also where IPS actions may be done.
+ */
+void SCPacketSetReleasePacket(Packet *p, void (*ReleasePacket)(Packet *p));
+
+/** \brief Set a packets live device. */
+void SCPacketSetLiveDevice(Packet *p, LiveDevice *device);
+
+/** \brief Set a packets data link type. */
+void SCPacketSetDatalink(Packet *p, int datalink);
+
+/** \brief Set the timestamp for a packet.
+ *
+ * \param ts A timestamp in SCTime_t format. See SCTIME_FROM_TIMEVAL
+ *     for conversion from struct timeval.
+ */
+void SCPacketSetTime(Packet *p, SCTime_t ts);
+
+/** \brief Set packet source.
+ */
+void SCPacketSetSource(Packet *p, enum PktSrcEnum source);
+
 #endif