suricata
packet.c File Reference
#include "packet.h"
#include "pkt-var.h"
#include "flow.h"
#include "host.h"
#include "util-profiling.h"
#include "util-validate.h"
#include "action-globals.h"
#include "app-layer-events.h"
Include dependency graph for packet.c:

Go to the source code of this file.

Macros

#define CLEAR_ADDR(a)
 
#define PACKET_RESET_ACTION(p)   (p)->action = 0
 
#define RESET_PKT_LEN(p)   ((p)->pktlen = 0)
 

Functions

void PacketDrop (Packet *p, const uint8_t action, enum PacketDropReason r)
 issue drop action More...
 
bool PacketCheckAction (const Packet *p, const uint8_t a)
 
void PacketInit (Packet *p)
 Initialize a packet structure for use. More...
 
void PacketReleaseRefs (Packet *p)
 
void PacketReinit (Packet *p)
 Recycle a packet structure for reuse. More...
 
void PacketRecycle (Packet *p)
 
void PacketDestructor (Packet *p)
 Cleanup a packet so that we can free it. No memset needed.. More...
 
void SCPacketSetReleasePacket (Packet *p, void(*ReleasePacket)(Packet *p))
 Set a packet release function. More...
 
void SCPacketSetLiveDevice (Packet *p, LiveDevice *device)
 Set a packets live device. More...
 
void SCPacketSetDatalink (Packet *p, int datalink)
 Set a packets data link type. More...
 
void SCPacketSetTime (Packet *p, SCTime_t ts)
 Set the timestamp for a packet. More...
 
void SCPacketSetSource (Packet *p, enum PktSrcEnum source)
 Set packet source. More...
 

Macro Definition Documentation

◆ CLEAR_ADDR

#define CLEAR_ADDR (   a)
Value:
do { \
(a)->family = 0; \
(a)->addr_data32[0] = 0; \
(a)->addr_data32[1] = 0; \
(a)->addr_data32[2] = 0; \
(a)->addr_data32[3] = 0; \
} while (0)

◆ PACKET_RESET_ACTION

#define PACKET_RESET_ACTION (   p)    (p)->action = 0

◆ RESET_PKT_LEN

#define RESET_PKT_LEN (   p)    ((p)->pktlen = 0)

Function Documentation

◆ PacketCheckAction()

bool PacketCheckAction ( const Packet p,
const uint8_t  a 
)

Definition at line 49 of file packet.c.

References Packet_::action, likely, and Packet_::root.

Referenced by AlertJsonHeader(), CaptureStatsUpdate(), EveAddVerdict(), RejectSendIPv4ICMP(), RejectSendIPv4TCP(), RejectSendIPv6ICMP(), and RejectSendIPv6TCP().

Here is the caller graph for this function:

◆ PacketDestructor()

void PacketDestructor ( Packet p)

Cleanup a packet so that we can free it. No memset needed..

Definition at line 154 of file packet.c.

References PacketAlerts_::alerts, Packet_::alerts, Packet_::app_layer_events, AppLayerDecoderEventsFreeEvents(), PACKET_FREE_EXTDATA, PACKET_PROFILING_RESET, PacketAlertFree(), PacketReleaseRefs(), Packet_::persistent, Packet_::pktvar, PktVarFree(), SCSpinDestroy, and Packet_::tunnel_lock.

Referenced by PacketFree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PacketDrop()

void PacketDrop ( Packet p,
const uint8_t  action,
enum PacketDropReason  r 
)

issue drop action

Set drop (+reject) flags in both current and root packet.

Parameters
actionaction bit flags. Must be limited to ACTION_DROP_REJECT|ACTION_ALERT

Definition at line 33 of file packet.c.

References Packet_::action, ACTION_ALERT, ACTION_DROP_REJECT, DEBUG_VALIDATE_BUG_ON, Packet_::drop_reason, PKT_DROP_REASON_INNER_PACKET, PKT_DROP_REASON_NOT_SET, and Packet_::root.

◆ PacketInit()

void PacketInit ( Packet p)

Initialize a packet structure for use.

Definition at line 63 of file packet.c.

References PacketAlerts_::alerts, Packet_::alerts, Packet_::livedev, PacketAlertCreate(), Packet_::persistent, SCSpinInit, and Packet_::tunnel_lock.

Referenced by PacketGetFromAlloc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PacketRecycle()

void PacketRecycle ( Packet p)

Definition at line 145 of file packet.c.

References PacketReinit(), and PacketReleaseRefs().

Here is the call graph for this function:

◆ PacketReinit()

◆ PacketReleaseRefs()

void PacketReleaseRefs ( Packet p)

Definition at line 70 of file packet.c.

Referenced by PacketDestructor(), and PacketRecycle().

Here is the caller graph for this function:

◆ SCPacketSetDatalink()

void SCPacketSetDatalink ( Packet p,
int  datalink 
)
inline

Set a packets data link type.

Definition at line 177 of file packet.c.

References Packet_::datalink.

◆ SCPacketSetLiveDevice()

void SCPacketSetLiveDevice ( Packet p,
LiveDevice device 
)
inline

Set a packets live device.

Definition at line 172 of file packet.c.

References Packet_::livedev.

◆ SCPacketSetReleasePacket()

void SCPacketSetReleasePacket ( Packet p,
void(*)(Packet *p)  ReleasePacket 
)
inline

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.

Definition at line 167 of file packet.c.

◆ SCPacketSetSource()

void SCPacketSetSource ( Packet p,
enum PktSrcEnum  source 
)
inline

Set packet source.

Definition at line 187 of file packet.c.

References Packet_::pkt_src.

◆ SCPacketSetTime()

void SCPacketSetTime ( Packet p,
SCTime_t  ts 
)
inline

Set the timestamp for a packet.

Parameters
tsA timestamp in SCTime_t format. See SCTIME_FROM_TIMEVAL for conversion from struct timeval.

Definition at line 182 of file packet.c.

References ts, and Packet_::ts.

addr_data32
#define addr_data32
Definition: decode.h:122