From: Jason Ish Date: Wed, 9 Oct 2024 18:30:43 +0000 (-0600) Subject: packet: add set functions for some packet fields X-Git-Tag: suricata-8.0.0-beta1~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8ad7b1d28c052138b3c710caf9fbda96c7ea5bc;p=thirdparty%2Fsuricata.git packet: add set functions for some packet fields - SCPacketSetReleasePacket - SCPacketSetLiveDevice - SCPacketSetDatalink - SCPacketSetTime - SCPacketSetSource Prevents direct access by library users and provides more ABI stability. Ticket: #7240 --- diff --git a/src/packet.c b/src/packet.c index cb6dcf6183..22d282f77b 100644 --- a/src/packet.c +++ b/src/packet.c @@ -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; +} diff --git a/src/packet.h b/src/packet.h index 0b03a59631..633b118d3b 100644 --- a/src/packet.h +++ b/src/packet.h @@ -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