Skip to content

Commit

Permalink
packet: add set functions for some packet fields
Browse files Browse the repository at this point in the history
- SCPacketSetReleasePacket
- SCPacketSetLiveDevice
- SCPacketSetDatalink
- SCPacketSetTime
- SCPacketSetSource

Prevents direct access by library users and provides more ABI
stability.
  • Loading branch information
jasonish committed Oct 9, 2024
1 parent 81289f5 commit e0f9e4e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,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 = source;
}
28 changes: 28 additions & 0 deletions src/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

0 comments on commit e0f9e4e

Please sign in to comment.