Go to the documentation of this file.
98 .valid_settings_ips = {
126 .valid_settings_ips = {
151 if (pa_array == NULL)
154 for (
int i = 0; i <
cnt; i++) {
156 while (current_json) {
160 current_json = next_json;
168 if (pa_array == NULL)
172 while (allocated_json) {
176 allocated_json = next_json;
213 SCLogDebug(
"FIXME: DecodeTunnel: protocol %" PRIu32
" not supported.",
proto);
273 SCLogDebug(
"allocated a new packet only using alloc...");
351 uint32_t newsize =
offset + datalen;
360 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
433 if (parent->
root != NULL) {
435 BUG_ON(!PacketIsTunnelChild(parent));
457 if (parent->
root == NULL) {
460 TUNNEL_INCR_PKT_TPR(
p);
465 DecodeSetNoPayloadInspectionFlag(parent);
494 if (parent->
root != NULL) {
496 BUG_ON(!PacketIsTunnelChild(parent));
504 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
538 TUNNEL_INCR_PKT_TPR(parent);
543 DecodeSetNoPayloadInspectionFlag(parent);
554 #ifdef CAPTURE_OFFLOAD
560 (state == FLOW_STATE_CAPTURE_BYPASSED)) {
618 static HashTable *g_counter_table = NULL;
624 if (g_counter_table) {
626 g_counter_table = NULL;
631 static bool IsDefragMemcapExceptionPolicyStatsValid(
enum ExceptionPolicy policy)
639 static bool IsFlowMemcapExceptionPolicyStatsValid(
enum ExceptionPolicy policy)
701 "decoder.avg_pkt_size",
"decoder.bytes",
"decoder.pkts", &
tv->
stats);
712 IsFlowMemcapExceptionPolicyStatsValid);
760 IsDefragMemcapExceptionPolicyStatsValid);
771 strncmp(
DEvents[i].event_name,
"decoder.", 8) == 0)
774 if (g_counter_table == NULL) {
778 if (g_counter_table == NULL) {
780 "table init failed");
785 const char *dot = strchr(
DEvents[i].event_name,
'.');
787 snprintf(
name,
sizeof(
name),
"%s.%s",
795 "table name init failed");
799 "table name add failed");
835 PrintInet(AF_INET, (
const void *)&a->addr_data32[0], s,
sizeof(s));
853 SCLogError(
"initializing flow log API for thread failed");
896 const char *pkt_src_str = NULL;
899 pkt_src_str =
"wire/pcap";
902 pkt_src_str =
"gre tunnel";
905 pkt_src_str =
"ipv4 tunnel";
908 pkt_src_str =
"ipv6 tunnel";
911 pkt_src_str =
"teredo tunnel";
914 pkt_src_str =
"defrag";
917 pkt_src_str =
"stream (detect/log)";
920 pkt_src_str =
"stream (flow timeout)";
923 pkt_src_str =
"geneve encapsulation";
926 pkt_src_str =
"vxlan encapsulation";
929 pkt_src_str =
"detect reload flush";
932 pkt_src_str =
"capture timeout flush";
935 pkt_src_str =
"shutdown flush";
946 return "decode error";
948 return "defrag error";
950 return "defrag memcap";
952 return "flow memcap";
956 return "exception policy flow drop";
958 return "stream error";
960 return "stream memcap";
962 return "stream midstream";
964 return "stream urgent";
966 return "stream reassembly";
968 return "applayer error";
970 return "applayer memcap";
974 return "threshold detection_filter";
978 return "tunnel packet drop";
980 return "firewall rules";
982 return "firewall default packet policy";
984 return "firewall default app policy";
986 return "firewall pre stream hook";
988 return "firewall pre flow hook";
990 return "firewall flow drop";
1002 return "ips.drop_reason.decode_error";
1004 return "ips.drop_reason.defrag_error";
1006 return "ips.drop_reason.defrag_memcap";
1008 return "ips.drop_reason.flow_memcap";
1010 return "ips.drop_reason.flow_drop";
1012 return "ips.drop_reason.exception_policy_flow_drop";
1014 return "ips.drop_reason.stream_error";
1016 return "ips.drop_reason.stream_memcap";
1018 return "ips.drop_reason.stream_midstream";
1020 return "ips.drop_reason.stream_urgent";
1022 return "ips.drop_reason.stream_reassembly";
1024 return "ips.drop_reason.applayer_error";
1026 return "ips.drop_reason.applayer_memcap";
1028 return "ips.drop_reason.rules";
1030 return "ips.drop_reason.threshold_detection_filter";
1032 return "ips.drop_reason.nfq_error";
1034 return "ips.drop_reason.tunnel_packet_drop";
1036 return "firewall.drop_reason.rules";
1038 return "firewall.drop_reason.pre_stream_hook";
1040 return "firewall.drop_reason.pre_flow_hook";
1042 return "firewall.drop_reason.flow_drop";
1044 return "firewall.drop_reason.default_packet_policy";
1046 return "firewall.drop_reason.default_app_policy";
1068 static bool VerdictByFirewall(
const Packet *
p)
1095 if (VerdictByFirewall(
p)) {
1102 if (VerdictByFirewall(
p)) {
1140 const char *
name = PacketDropReasonToJsonString(i);
1149 const char *
name = PacketDropReasonToJsonString(i);
1165 if (value < 0 || value > UINT8_MAX) {
1178 if (max <= 0 || max > UINT8_MAX) {
1179 SCLogWarning(
"Invalid value for packet-alert-max, default value set instead");
1187 static inline bool PcapPacketCntRunmodeCanAccess(
void)
1195 if (PcapPacketCntRunmodeCanAccess() &&
p != NULL) {
1203 if (PcapPacketCntRunmodeCanAccess() &&
p != NULL) {
bool PacketCheckAction(const Packet *p, const uint8_t a)
enum SCRunModes SCRunMode
@ PKT_DROP_REASON_DEFRAG_MEMCAP
StatsCounterId counter_flow_icmp6
@ PKT_DROP_REASON_DEFRAG_ERROR
@ PKT_DROP_REASON_RULES_THRESHOLD
void StatsCounterMaxUpdateI64(StatsThreadContext *stats, StatsCounterMaxId id, int64_t x)
update the value of the localmax counter
StatsCounterId counter_icmpv4
StatsCounterId counter_defrag_ipv6_fragments
StatsCounterId counter_esp
StatsCounterId counter_ethertype_unknown
TmEcode OutputFlowLogThreadInit(ThreadVars *tv, void **data)
thread init for the flow logger This will run the thread init functions for the individual registered...
int DecodeERSPAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
ERSPAN Type II.
@ PKT_DROP_REASON_FW_FLOW_DROP
StatsCounterId counter_ipv6
StatsCounterId counter_raw
void PacketFreeOrRelease(Packet *p)
Return a packet to where it was allocated.
StatsCounterId counter_vlan_qinqinq
StatsCounterId counter_flow_get_used_eval_busy
int DecodePPP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Copy data to Packet payload and set packet length.
void PacketBypassCallback(Packet *p)
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
@ GENERIC_TOO_MANY_LAYERS
void DecodeERSPANConfig(void)
Functions to decode ERSPAN Type I and II packets.
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
@ PKT_DROP_REASON_STREAM_MEMCAP
int DecodeNSH(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Function to decode NSH packets.
@ PKT_DROP_REASON_FW_RULES
@ PKT_DROP_REASON_FLOW_MEMCAP
void DecodeTeredoConfig(void)
void * SCFlowGetStorageById(const Flow *f, SCFlowStorageId id)
void CaptureStatsSetup(ThreadVars *tv)
const char * PacketDropReasonToString(enum PacketDropReason r)
uint8_t events[PACKET_ENGINE_EVENT_MAX]
#define PKT_STREAM_MODIFIED
StatsCounterId counter_ips_replaced
@ DECODE_TUNNEL_IPV6_TEREDO
uint64_t PcapPacketCntGet(const Packet *p)
StatsCounterId StatsRegisterCounter(const char *name, StatsThreadContext *stats)
Registers a normal, unqualified counter.
StatsCounterId counter_defrag_no_frags
void AddressDebugPrint(Address *a)
Debug print function for printing addresses.
Packet * PacketDefragPktSetup(Packet *parent, const uint8_t *pkt, uint32_t len, uint8_t proto)
Setup a pseudo packet (reassembled frags)
StatsCounterId counter_vxlan
StatsCounterId counter_flow_spare_sync_empty
StatsCounterId counter_nsh
StatsCounterId counter_gre
StatsCounterId counter_flow_get_used_failed
@ PKT_SRC_CAPTURE_TIMEOUT
PacketAlert * PacketAlertCreate(void)
Initialize PacketAlerts with dynamic alerts array size.
struct CaptureStats_ CaptureStats
@ PKT_DROP_REASON_STREAM_REASSEMBLY
void PcapPacketCntSet(Packet *p, uint64_t pcap_cnt)
StatsCounterId counter_bytes
int PacketCopyDataOffset(Packet *p, uint32_t offset, const uint8_t *data, uint32_t datalen)
Copy data to Packet payload at given offset.
StatsCounterId counter_flow_get_used
StatsCounterDeriveId counter_avg_pkt_size
StatsCounterId counter_pppoe
#define FLOW_PKT_TOSERVER
StatsCounterId counter_fw_rejected
StatsCounterId counter_tcp_syn
#define ACTION_REJECT_ANY
ExceptionPolicyStatsSetts flow_memcap_eps_stats
int DecodeARP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
#define SCMUTEX_INITIALIZER
StatsCounterId counter_icmpv6
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
StatsCounterId counter_invalid
void PacketAlertGetMaxConfig(void)
uint8_t decoder_max_layers
bool EngineModeIsFirewall(void)
char StringHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2)
StatsCounterId counter_sctp_init_ack
int(* BypassPacketsFlow)(struct Packet_ *)
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
void DecodeVXLANConfig(void)
StatsCounterId counter_flow_spare_sync
StatsCounterId counter_defrag_ipv4_reassembled
void DecodeUnregisterCounters(void)
StatsCounterId counter_chdlc
StatsCounterId counter_sctp
#define GET_PKT_DIRECT_MAX_SIZE(p)
SCFlowStorageId GetFlowBypassInfoID(void)
StatsCounterAvgId StatsRegisterAvgCounter(const char *name, StatsThreadContext *stats)
Registers a counter, whose value holds the average of all the values assigned to it.
uint32_t StringHashFunc(HashTable *ht, void *data, uint16_t datalen)
PacketEngineEvents events
void PacketAlertFree(PacketAlert *pa_array)
@ DECODE_EVENT_PACKET_MAX
StatsCounterId counter_tcp
void HashTableFree(HashTable *ht)
Free a HashTable and all its contents.
StatsCounterId counter_fw_blocked
@ PKT_DROP_REASON_STREAM_URG
StatsCounterId counter_defrag_tracker_hard_reuse
#define PKT_DEFAULT_MAX_DECODED_LAYERS
const char * stats_decoder_events_prefix
StatsCounterId counter_flow_memcap
StatsCounterId counter_defrag_max_hit
StatsCounterId counter_ips_accepted
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
StatsCounterId counter_flow_elephant
#define SET_PKT_LEN(p, len)
StatsCounterId counter_fw_accepted
#define PKT_DROP_REASON_NON_FW_MAX
@ FLOW_STATE_LOCAL_BYPASSED
struct PacketContextData * json_info
SCRunMode SCRunmodeGet(void)
Get the current run mode.
#define PKT_IS_TOSERVER(p)
StatsCounterId counter_udp
int DecodeERSPANTypeI(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
ERSPAN Type I.
const struct DecodeEvents_ DEvents[]
@ PKT_DROP_REASON_APPLAYER_ERROR
#define SCMutexUnlock(mut)
void PacketSwap(Packet *p)
switch direction of a packet
@ PKT_DROP_REASON_NOT_SET
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
@ PKT_DROP_REASON_FW_FLOW_PRE_HOOK
void PacketDestructor(Packet *p)
Cleanup a packet so that we can free it. No memset needed..
void CaptureStatsUpdate(ThreadVars *tv, const Packet *p)
StatsCounterId counter_vntag
void ExceptionPolicySetStatsCounters(ThreadVars *tv, ExceptionPolicyCounters *counter, ExceptionPolicyStatsSetts *setting, enum ExceptionPolicy conf_policy, const char *default_str, bool(*isExceptionPolicyValid)(enum ExceptionPolicy))
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
Per thread variable structure.
int SCFlowSetStorageById(Flow *f, SCFlowStorageId id, void *ptr)
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
StatsCounterId counter_flow_active
StatsCounterId counter_ipv6inipv4
#define FLOW_PKT_TOCLIENT_FIRST
void StatsCounterIncr(StatsThreadContext *stats, StatsCounterId id)
Increments the local counter.
void PacketFree(Packet *p)
Return a malloced packet.
const char * PktSrcToString(enum PktSrcEnum pkt_src)
bool valid_settings_ids[EXCEPTION_POLICY_MAX]
StatsCounterId counter_tcp_urg
StatsCounterId counter_pkts
StatsCounterId counter_eth
#define SCLogWarning(...)
Macro used to log WARNING messages.
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
void StringHashFreeFunc(void *data)
StatsCounterId counter_sctp_init
StatsCounterAvgId counter_flow_spare_sync_avg
int PacketCallocExtPkt(Packet *p, int datalen)
StatsCounterId counter_flow_icmp4
@ PKT_SRC_STREAM_TCP_DETECTLOG_FLUSH
StatsCounterId counter_ieee8021ah
StatsCounterId counter_defrag_tracker_timeout
StatsCounterId counter_drop_reason[PKT_DROP_REASON_MAX]
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
AppLayerThreadCtx * app_tctx
StatsCounterId counter_ips_blocked
@ PKT_DROP_REASON_STREAM_ERROR
StatsCounterId counter_geneve
#define SCReturnPtr(x, type)
AppLayerThreadCtx * AppLayerGetCtxThread(void)
Creates a new app layer thread context.
StatsCounterId counter_sctp_shutdown
StatsCounterId counter_tcp_rst
#define FLOW_PKT_TOCLIENT
StatsCounterId counter_ipv4inipv6
@ PKT_DROP_REASON_EP_FLOW_DROP
void FlowUpdateState(Flow *f, const enum FlowState s)
StatsCounterMaxId counter_max_mac_addrs_dst
ExceptionPolicyCounters counter_defrag_memcap_eps
StatsCounterMaxId counter_max_mac_addrs_src
uint32_t default_packet_size
uint8_t nb_decoded_layers
void(* ReleasePacket)(struct Packet_ *)
StatsCounterId counter_ipv4_unknown_proto
StatsCounterId counter_sctp_abort
StatsCounterId counter_ipv4inipv4
@ PKT_DROP_REASON_INNER_PACKET
enum ExceptionPolicy FlowGetMemcapExceptionPolicy(void)
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
StatsCounterId counter_sll
StatsCounterId counter_ppp
@ PKT_DROP_REASON_APPLAYER_MEMCAP
void DecodeGlobalConfig(void)
StatsCounterId counter_flow_udp
StatsCounterId counter_igmp
StatsCounterId counter_tcp_synack
@ PKT_DROP_REASON_NFQ_ERROR
StatsCounterId counter_null
void PacketUpdateEngineEventCounters(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
ExceptionPolicyCounters counter_flow_memcap_eps
struct PacketContextData * next
@ PKT_DROP_REASON_FW_STREAM_PRE_HOOK
StatsCounterId counter_vlan_qinq
StatsCounterId counter_teredo
#define PACKET_PROFILING_START(p)
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
ExceptionPolicyStatsSetts defrag_memcap_eps_stats
StatsCounterId counter_ips_rejected
#define SCLogError(...)
Macro used to log ERROR messages.
TmEcode OutputFlowLogThreadDeinit(ThreadVars *tv, void *thread_data)
@ PKT_SRC_DETECT_RELOAD_FLUSH
StatsCounterMaxId counter_max_pkt_size
StatsCounterId counter_flow_spare_sync_incomplete
StatsCounterId counter_sll2
Structure to hold thread specific data for all decode modules.
bool valid_settings_ips[EXCEPTION_POLICY_MAX]
void AppLayerDestroyCtxThread(AppLayerThreadCtx *app_tctx)
Destroys the context created by AppLayerGetCtxThread().
StatsCounterId counter_defrag_ipv4_fragments
StatsCounterId counter_etag
StatsCounterMaxId StatsRegisterMaxCounter(const char *name, StatsThreadContext *stats)
Registers a counter, whose value holds the maximum of all the values assigned to it.
StatsCounterId counter_tcp_active_sessions
void * output_flow_thread_data
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
StatsCounterDeriveId StatsRegisterDeriveDivCounter(const char *name, const char *dname1, const char *dname2, StatsThreadContext *stats)
Registers a counter which tracks the result of the calculating the value of counter dname1 divided by...
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
int PacketSetData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Set data for Packet and set length when zero copy is used.
Packet * PacketPoolGetPacket(void)
Get a new packet from the packet pool.
@ PKT_DROP_REASON_FW_DEFAULT_APP_POLICY
#define GET_PKT_DIRECT_DATA(p)
thread_local CaptureStats t_capture_stats
StatsCounterId counter_defrag_ipv6_reassembled
int EngineModeIsIPS(void)
StatsCounterId counter_mpls
#define ENGINE_SET_INVALID_EVENT(p, e)
void DecodeGeneveConfig(void)
void PacketAlertRecycle(PacketAlert *pa_array, uint16_t cnt)
@ PKT_DROP_REASON_FW_DEFAULT_PACKET_POLICY
uint16_t packet_alert_max
uint16_t vlan_id[VLAN_MAX_LAYERS]
StatsCounterId counter_ipv4
StatsCounterId counter_flow_total
StatsCounterId counter_arp
StatsCounterId counter_vlan
void PacketDefragPktSetupParent(Packet *parent)
inform defrag "parent" that a pseudo packet is now associated to it.
bool PacketInit(Packet *p)
Initialize a packet structure for use.
StatsCounterId counter_defrag_tracker_soft_reuse
Packet * PacketTunnelPktSetup(ThreadVars *tv, DecodeThreadVars *dtv, Packet *parent, const uint8_t *pkt, uint32_t len, enum DecodeTunnelProto proto)
Setup a pseudo packet (tunnel)
StatsCounterId counter_flow_elephant_toclient
StatsCounterId counter_flow_elephant_toserver
bool stats_decoder_events
@ PKT_DROP_REASON_STREAM_MIDSTREAM
int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
StatsCounterId counter_erspan
int DecodeVLAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
void StatsCounterAddI64(StatsThreadContext *stats, StatsCounterId id, int64_t x)
Adds a value of type uint64_t to the local counter.
StatsCounterId counter_ipv6inipv6
#define FLOW_PKT_TOSERVER_FIRST
enum ExceptionPolicy DefragGetMemcapExceptionPolicy(void)
StatsCounterId counter_engine_events[DECODE_EVENT_MAX]
Packet * PacketGetFromQueueOrAlloc(void)
Get a packet. We try to get a packet from the packetpool first, but if that is empty we alloc a packe...
#define DEBUG_VALIDATE_BUG_ON(exp)
int DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
@ PKT_DROP_REASON_FLOW_DROP
void DecodeUpdatePacketCounters(ThreadVars *tv, const DecodeThreadVars *dtv, const Packet *p)
StatsCounterId counter_flow_get_used_eval_reject
StatsCounterId counter_flow_get_used_eval
StatsCounterId counter_flow_tcp_reuse
@ PKT_DROP_REASON_DECODE_ERROR
StatsCounterId counter_flow_tcp
StatsCounterId counter_sctp_data