|
|
|
/* Copyright (C) 2007-2010 Open Information Security Foundation
|
|
|
|
*
|
|
|
|
* You can copy, redistribute or modify this Program under the terms of
|
|
|
|
* the GNU General Public License version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* version 2 along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
|
|
|
* \author Victor Julien <victor@inliniac.net>
|
|
|
|
*
|
|
|
|
* Decode the raw packet
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "suricata-common.h"
|
|
|
|
#include "suricata.h"
|
|
|
|
#include "decode.h"
|
|
|
|
#include "util-debug.h"
|
|
|
|
#include "util-mem.h"
|
|
|
|
#include "app-layer-detect-proto.h"
|
Add per packet profiling.
Per packet profiling uses tick based accounting. It has 2 outputs, a summary
and a csv file that contains per packet stats.
Stats per packet include:
1) total ticks spent
2) ticks spent per individual thread module
3) "threading overhead" which is simply calculated by subtracting (2) of (1).
A number of changes were made to integrate the new code in a clean way:
a number of generic enums are now placed in tm-threads-common.h so we can
include them from any part of the engine.
Code depends on --enable-profiling just like the rule profiling code.
New yaml parameters:
profiling:
# packet profiling
packets:
# Profiling can be disabled here, but it will still have a
# performance impact if compiled in.
enabled: yes
filename: packet_stats.log
append: yes
# per packet csv output
csv:
# Output can be disabled here, but it will still have a
# performance impact if compiled in.
enabled: no
filename: packet_stats.csv
Example output of summary stats:
IP ver Proto cnt min max avg
------ ----- ------ ------ ---------- -------
IPv4 6 19436 11448 5404365 32993
IPv4 256 4 11511 49968 30575
Per Thread module stats:
Thread Module IP ver Proto cnt min max avg
------------------------ ------ ----- ------ ------ ---------- -------
TMM_DECODEPCAPFILE IPv4 6 19434 1242 47889 1770
TMM_DETECT IPv4 6 19436 1107 137241 1504
TMM_ALERTFASTLOG IPv4 6 19436 90 1323 155
TMM_ALERTUNIFIED2ALERT IPv4 6 19436 108 1359 138
TMM_ALERTDEBUGLOG IPv4 6 19436 90 1134 154
TMM_LOGHTTPLOG IPv4 6 19436 414 5392089 7944
TMM_STREAMTCP IPv4 6 19434 828 1299159 19438
The proto 256 is a counter for handling of pseudo/tunnel packets.
Example output of csv:
pcap_cnt,ipver,ipproto,total,TMM_DECODENFQ,TMM_VERDICTNFQ,TMM_RECEIVENFQ,TMM_RECEIVEPCAP,TMM_RECEIVEPCAPFILE,TMM_DECODEPCAP,TMM_DECODEPCAPFILE,TMM_RECEIVEPFRING,TMM_DECODEPFRING,TMM_DETECT,TMM_ALERTFASTLOG,TMM_ALERTFASTLOG4,TMM_ALERTFASTLOG6,TMM_ALERTUNIFIEDLOG,TMM_ALERTUNIFIEDALERT,TMM_ALERTUNIFIED2ALERT,TMM_ALERTPRELUDE,TMM_ALERTDEBUGLOG,TMM_ALERTSYSLOG,TMM_LOGDROPLOG,TMM_ALERTSYSLOG4,TMM_ALERTSYSLOG6,TMM_RESPONDREJECT,TMM_LOGHTTPLOG,TMM_LOGHTTPLOG4,TMM_LOGHTTPLOG6,TMM_PCAPLOG,TMM_STREAMTCP,TMM_DECODEIPFW,TMM_VERDICTIPFW,TMM_RECEIVEIPFW,TMM_RECEIVEERFFILE,TMM_DECODEERFFILE,TMM_RECEIVEERFDAG,TMM_DECODEERFDAG,threading
1,4,6,172008,0,0,0,0,0,0,47889,0,0,48582,1323,0,0,0,0,1359,0,1134,0,0,0,0,0,8028,0,0,0,49356,0,0,0,0,0,0,0,14337
First line of the file contains labels.
2 example gnuplot scripts added to plot the data.
14 years ago
|
|
|
#include "tm-threads.h"
|
|
|
|
#include "util-error.h"
|
|
|
|
#include "util-print.h"
|
|
|
|
#include "tmqh-packetpool.h"
|
Add per packet profiling.
Per packet profiling uses tick based accounting. It has 2 outputs, a summary
and a csv file that contains per packet stats.
Stats per packet include:
1) total ticks spent
2) ticks spent per individual thread module
3) "threading overhead" which is simply calculated by subtracting (2) of (1).
A number of changes were made to integrate the new code in a clean way:
a number of generic enums are now placed in tm-threads-common.h so we can
include them from any part of the engine.
Code depends on --enable-profiling just like the rule profiling code.
New yaml parameters:
profiling:
# packet profiling
packets:
# Profiling can be disabled here, but it will still have a
# performance impact if compiled in.
enabled: yes
filename: packet_stats.log
append: yes
# per packet csv output
csv:
# Output can be disabled here, but it will still have a
# performance impact if compiled in.
enabled: no
filename: packet_stats.csv
Example output of summary stats:
IP ver Proto cnt min max avg
------ ----- ------ ------ ---------- -------
IPv4 6 19436 11448 5404365 32993
IPv4 256 4 11511 49968 30575
Per Thread module stats:
Thread Module IP ver Proto cnt min max avg
------------------------ ------ ----- ------ ------ ---------- -------
TMM_DECODEPCAPFILE IPv4 6 19434 1242 47889 1770
TMM_DETECT IPv4 6 19436 1107 137241 1504
TMM_ALERTFASTLOG IPv4 6 19436 90 1323 155
TMM_ALERTUNIFIED2ALERT IPv4 6 19436 108 1359 138
TMM_ALERTDEBUGLOG IPv4 6 19436 90 1134 154
TMM_LOGHTTPLOG IPv4 6 19436 414 5392089 7944
TMM_STREAMTCP IPv4 6 19434 828 1299159 19438
The proto 256 is a counter for handling of pseudo/tunnel packets.
Example output of csv:
pcap_cnt,ipver,ipproto,total,TMM_DECODENFQ,TMM_VERDICTNFQ,TMM_RECEIVENFQ,TMM_RECEIVEPCAP,TMM_RECEIVEPCAPFILE,TMM_DECODEPCAP,TMM_DECODEPCAPFILE,TMM_RECEIVEPFRING,TMM_DECODEPFRING,TMM_DETECT,TMM_ALERTFASTLOG,TMM_ALERTFASTLOG4,TMM_ALERTFASTLOG6,TMM_ALERTUNIFIEDLOG,TMM_ALERTUNIFIEDALERT,TMM_ALERTUNIFIED2ALERT,TMM_ALERTPRELUDE,TMM_ALERTDEBUGLOG,TMM_ALERTSYSLOG,TMM_LOGDROPLOG,TMM_ALERTSYSLOG4,TMM_ALERTSYSLOG6,TMM_RESPONDREJECT,TMM_LOGHTTPLOG,TMM_LOGHTTPLOG4,TMM_LOGHTTPLOG6,TMM_PCAPLOG,TMM_STREAMTCP,TMM_DECODEIPFW,TMM_VERDICTIPFW,TMM_RECEIVEIPFW,TMM_RECEIVEERFFILE,TMM_DECODEERFFILE,TMM_RECEIVEERFDAG,TMM_DECODEERFDAG,threading
1,4,6,172008,0,0,0,0,0,0,47889,0,0,48582,1323,0,0,0,0,1359,0,1134,0,0,0,0,0,8028,0,0,0,49356,0,0,0,0,0,0,0,14337
First line of the file contains labels.
2 example gnuplot scripts added to plot the data.
14 years ago
|
|
|
#include "util-profiling.h"
|
|
|
|
|
|
|
|
void DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
|
|
|
|
uint8_t *pkt, uint16_t len, PacketQueue *pq, uint8_t proto)
|
|
|
|
{
|
|
|
|
switch (proto) {
|
|
|
|
case PPP_OVER_GRE:
|
|
|
|
return DecodePPP(tv, dtv, p, pkt, len, pq);
|
|
|
|
case IPPROTO_IP:
|
|
|
|
return DecodeIPV4(tv, dtv, p, pkt, len, pq);
|
|
|
|
case IPPROTO_IPV6:
|
|
|
|
return DecodeIPV6(tv, dtv, p, pkt, len, pq);
|
|
|
|
case VLAN_OVER_GRE:
|
|
|
|
return DecodeVLAN(tv, dtv, p, pkt, len, pq);
|
|
|
|
default:
|
|
|
|
SCLogInfo("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.", proto);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get a packet. We try to get a packet from the packetpool first, but
|
|
|
|
* if that is empty we alloc a packet that is free'd again after
|
|
|
|
* processing.
|
|
|
|
*
|
|
|
|
* \retval p packet, NULL on error
|
|
|
|
*/
|
|
|
|
Packet *PacketGetFromQueueOrAlloc(void) {
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
|
|
|
/* try the pool first */
|
|
|
|
if (PacketPoolSize() > 0) {
|
|
|
|
p = PacketPoolGetPacket();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p == NULL) {
|
|
|
|
/* non fatal, we're just not processing a packet then */
|
|
|
|
p = SCMalloc(SIZE_OF_PACKET);
|
|
|
|
if (p == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PACKET_INITIALIZE(p);
|
|
|
|
p->flags |= PKT_ALLOC;
|
|
|
|
|
|
|
|
SCLogDebug("allocated a new packet...");
|
|
|
|
}
|
|
|
|
|
Add per packet profiling.
Per packet profiling uses tick based accounting. It has 2 outputs, a summary
and a csv file that contains per packet stats.
Stats per packet include:
1) total ticks spent
2) ticks spent per individual thread module
3) "threading overhead" which is simply calculated by subtracting (2) of (1).
A number of changes were made to integrate the new code in a clean way:
a number of generic enums are now placed in tm-threads-common.h so we can
include them from any part of the engine.
Code depends on --enable-profiling just like the rule profiling code.
New yaml parameters:
profiling:
# packet profiling
packets:
# Profiling can be disabled here, but it will still have a
# performance impact if compiled in.
enabled: yes
filename: packet_stats.log
append: yes
# per packet csv output
csv:
# Output can be disabled here, but it will still have a
# performance impact if compiled in.
enabled: no
filename: packet_stats.csv
Example output of summary stats:
IP ver Proto cnt min max avg
------ ----- ------ ------ ---------- -------
IPv4 6 19436 11448 5404365 32993
IPv4 256 4 11511 49968 30575
Per Thread module stats:
Thread Module IP ver Proto cnt min max avg
------------------------ ------ ----- ------ ------ ---------- -------
TMM_DECODEPCAPFILE IPv4 6 19434 1242 47889 1770
TMM_DETECT IPv4 6 19436 1107 137241 1504
TMM_ALERTFASTLOG IPv4 6 19436 90 1323 155
TMM_ALERTUNIFIED2ALERT IPv4 6 19436 108 1359 138
TMM_ALERTDEBUGLOG IPv4 6 19436 90 1134 154
TMM_LOGHTTPLOG IPv4 6 19436 414 5392089 7944
TMM_STREAMTCP IPv4 6 19434 828 1299159 19438
The proto 256 is a counter for handling of pseudo/tunnel packets.
Example output of csv:
pcap_cnt,ipver,ipproto,total,TMM_DECODENFQ,TMM_VERDICTNFQ,TMM_RECEIVENFQ,TMM_RECEIVEPCAP,TMM_RECEIVEPCAPFILE,TMM_DECODEPCAP,TMM_DECODEPCAPFILE,TMM_RECEIVEPFRING,TMM_DECODEPFRING,TMM_DETECT,TMM_ALERTFASTLOG,TMM_ALERTFASTLOG4,TMM_ALERTFASTLOG6,TMM_ALERTUNIFIEDLOG,TMM_ALERTUNIFIEDALERT,TMM_ALERTUNIFIED2ALERT,TMM_ALERTPRELUDE,TMM_ALERTDEBUGLOG,TMM_ALERTSYSLOG,TMM_LOGDROPLOG,TMM_ALERTSYSLOG4,TMM_ALERTSYSLOG6,TMM_RESPONDREJECT,TMM_LOGHTTPLOG,TMM_LOGHTTPLOG4,TMM_LOGHTTPLOG6,TMM_PCAPLOG,TMM_STREAMTCP,TMM_DECODEIPFW,TMM_VERDICTIPFW,TMM_RECEIVEIPFW,TMM_RECEIVEERFFILE,TMM_DECODEERFFILE,TMM_RECEIVEERFDAG,TMM_DECODEERFDAG,threading
1,4,6,172008,0,0,0,0,0,0,47889,0,0,48582,1323,0,0,0,0,1359,0,1134,0,0,0,0,0,8028,0,0,0,49356,0,0,0,0,0,0,0,14337
First line of the file contains labels.
2 example gnuplot scripts added to plot the data.
14 years ago
|
|
|
PACKET_PROFILING_START(p);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get a malloced packet.
|
|
|
|
*
|
|
|
|
* \retval p packet, NULL on error
|
|
|
|
*/
|
|
|
|
Packet *PacketGetFromAlloc(void)
|
|
|
|
{
|
|
|
|
Packet *p = SCMalloc(SIZE_OF_PACKET);
|
|
|
|
if (p == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PACKET_INITIALIZE(p);
|
|
|
|
p->flags |= PKT_ALLOC;
|
|
|
|
|
|
|
|
SCLogDebug("allocated a new packet only using alloc...");
|
|
|
|
|
|
|
|
PACKET_PROFILING_START(p);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Setup a pseudo packet (tunnel or reassembled frags)
|
|
|
|
*
|
|
|
|
* \param parent parent packet for this pseudo pkt
|
|
|
|
* \param pkt raw packet data
|
|
|
|
* \param len packet data length
|
|
|
|
* \param proto protocol of the tunneled packet
|
|
|
|
*
|
|
|
|
* \retval p the pseudo packet or NULL if out of memory
|
|
|
|
*/
|
|
|
|
Packet *PacketPseudoPktSetup(Packet *parent, uint8_t *pkt, uint16_t len, uint8_t proto)
|
|
|
|
{
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
/* get us a packet */
|
|
|
|
Packet *p = PacketGetFromQueueOrAlloc();
|
|
|
|
if (p == NULL) {
|
|
|
|
SCReturnPtr(NULL, "Packet");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the root ptr to the lowest layer */
|
|
|
|
if (parent->root != NULL)
|
|
|
|
p->root = parent->root;
|
|
|
|
else
|
|
|
|
p->root = parent;
|
|
|
|
|
|
|
|
/* copy packet and set lenght, proto */
|
|
|
|
PacketCopyData(p, pkt, len);
|
|
|
|
p->recursion_level = parent->recursion_level + 1;
|
|
|
|
p->ts.tv_sec = parent->ts.tv_sec;
|
|
|
|
p->ts.tv_usec = parent->ts.tv_usec;
|
|
|
|
|
|
|
|
/* set tunnel flags */
|
|
|
|
|
|
|
|
/* tell new packet it's part of a tunnel */
|
|
|
|
SET_TUNNEL_PKT(p);
|
|
|
|
/* tell parent packet it's part of a tunnel */
|
|
|
|
SET_TUNNEL_PKT(parent);
|
|
|
|
|
|
|
|
/* increment tunnel packet refcnt in the root packet */
|
|
|
|
TUNNEL_INCR_PKT_TPR(p);
|
|
|
|
|
|
|
|
/* disable payload (not packet) inspection on the parent, as the payload
|
|
|
|
* is the packet we will now run through the system separately. We do
|
|
|
|
* check it against the ip/port/other header checks though */
|
|
|
|
DecodeSetNoPayloadInspectionFlag(parent);
|
|
|
|
SCReturnPtr(p, "Packet");
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
|
|
|
|
{
|
|
|
|
/* register counters */
|
|
|
|
dtv->counter_pkts = SCPerfTVRegisterCounter("decoder.pkts", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
#if 0
|
|
|
|
dtv->counter_pkts_per_sec = SCPerfTVRegisterIntervalCounter("decoder.pkts_per_sec",
|
|
|
|
tv, SC_PERF_TYPE_DOUBLE,
|
|
|
|
"NULL", "1s");
|
|
|
|
#endif
|
|
|
|
dtv->counter_bytes = SCPerfTVRegisterCounter("decoder.bytes", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
#if 0
|
|
|
|
dtv->counter_bytes_per_sec = SCPerfTVRegisterIntervalCounter("decoder.bytes_per_sec",
|
|
|
|
tv, SC_PERF_TYPE_DOUBLE,
|
|
|
|
"NULL", "1s");
|
|
|
|
dtv->counter_mbit_per_sec = SCPerfTVRegisterIntervalCounter("decoder.mbit_per_sec",
|
|
|
|
tv, SC_PERF_TYPE_DOUBLE,
|
|
|
|
"NULL", "1s");
|
|
|
|
#endif
|
|
|
|
dtv->counter_ipv4 = SCPerfTVRegisterCounter("decoder.ipv4", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_ipv6 = SCPerfTVRegisterCounter("decoder.ipv6", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_eth = SCPerfTVRegisterCounter("decoder.ethernet", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_raw = SCPerfTVRegisterCounter("decoder.raw", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_sll = SCPerfTVRegisterCounter("decoder.sll", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_tcp = SCPerfTVRegisterCounter("decoder.tcp", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_udp = SCPerfTVRegisterCounter("decoder.udp", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_sctp = SCPerfTVRegisterCounter("decoder.sctp", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_icmpv4 = SCPerfTVRegisterCounter("decoder.icmpv4", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_icmpv6 = SCPerfTVRegisterCounter("decoder.icmpv6", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_ppp = SCPerfTVRegisterCounter("decoder.ppp", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_pppoe = SCPerfTVRegisterCounter("decoder.pppoe", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_gre = SCPerfTVRegisterCounter("decoder.gre", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_vlan = SCPerfTVRegisterCounter("decoder.vlan", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_avg_pkt_size = SCPerfTVRegisterAvgCounter("decoder.avg_pkt_size", tv,
|
|
|
|
SC_PERF_TYPE_DOUBLE, "NULL");
|
|
|
|
dtv->counter_max_pkt_size = SCPerfTVRegisterMaxCounter("decoder.max_pkt_size", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
|
|
|
|
dtv->counter_defrag_ipv4_fragments =
|
|
|
|
SCPerfTVRegisterCounter("defrag.ipv4.fragments", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_defrag_ipv4_reassembled =
|
|
|
|
SCPerfTVRegisterCounter("defrag.ipv4.reassembled", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_defrag_ipv4_timeouts =
|
|
|
|
SCPerfTVRegisterCounter("defrag.ipv4.timeouts", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_defrag_ipv6_fragments =
|
|
|
|
SCPerfTVRegisterCounter("defrag.ipv6.fragments", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_defrag_ipv6_reassembled =
|
|
|
|
SCPerfTVRegisterCounter("defrag.ipv6.reassembled", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
dtv->counter_defrag_ipv6_timeouts =
|
|
|
|
SCPerfTVRegisterCounter("defrag.ipv6.timeouts", tv,
|
|
|
|
SC_PERF_TYPE_UINT64, "NULL");
|
|
|
|
|
|
|
|
tv->sc_perf_pca = SCPerfGetAllCountersArray(&tv->sc_perf_pctx);
|
|
|
|
SCPerfAddToClubbedTMTable(tv->name, &tv->sc_perf_pctx);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Debug print function for printing addresses
|
|
|
|
*
|
|
|
|
* \param Address object
|
|
|
|
*
|
|
|
|
* \todo IPv6
|
|
|
|
*/
|
|
|
|
void AddressDebugPrint(Address *a) {
|
|
|
|
if (a == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (a->family) {
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
char s[16];
|
|
|
|
PrintInet(AF_INET, (const void *)&a->addr_data32[0], s, sizeof(s));
|
|
|
|
SCLogDebug("%s", s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Alloc and setup DecodeThreadVars */
|
|
|
|
DecodeThreadVars *DecodeThreadVarsAlloc() {
|
|
|
|
|
|
|
|
DecodeThreadVars *dtv = NULL;
|
|
|
|
|
|
|
|
if ( (dtv = SCMalloc(sizeof(DecodeThreadVars))) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(dtv, 0, sizeof(DecodeThreadVars));
|
|
|
|
|
|
|
|
/* initialize UDP app layer code */
|
|
|
|
AlpProtoFinalize2Thread(&dtv->udp_dp_ctx);
|
|
|
|
|
|
|
|
return dtv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Copy data to Packet payload at given offset
|
|
|
|
*
|
|
|
|
* \param Pointer to the Packet to modify
|
|
|
|
* \param Offset of the copy relatively to payload of Packet
|
|
|
|
* \param Pointer to the data to copy
|
|
|
|
* \param Length of the data to copy
|
|
|
|
*/
|
|
|
|
inline int PacketCopyDataOffset(Packet *p, int offset, uint8_t *data, int datalen)
|
|
|
|
{
|
|
|
|
if (offset + datalen > MAX_PAYLOAD_SIZE) {
|
|
|
|
/* too big */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! p->ext_pkt) {
|
|
|
|
if (offset + datalen <= default_packet_size) {
|
|
|
|
memcpy(p->pkt + offset, data, datalen);
|
|
|
|
} else {
|
|
|
|
/* here we need a dynamic allocation. This case should rarely
|
|
|
|
* occur as there is a high probability the first frag has
|
|
|
|
* reveal the packet size*/
|
|
|
|
p->ext_pkt = SCMalloc(MAX_PAYLOAD_SIZE);
|
|
|
|
if (p->ext_pkt == NULL) {
|
|
|
|
SET_PKT_LEN(p, 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* copy initial data */
|
|
|
|
memcpy(p->ext_pkt, GET_PKT_DIRECT_DATA(p), GET_PKT_DIRECT_MAX_SIZE(p));
|
|
|
|
/* copy data as asked */
|
|
|
|
memcpy(p->ext_pkt + offset, data, datalen);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memcpy(p->ext_pkt + offset, data, datalen);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Copy data to Packet payload and set packet length
|
|
|
|
*
|
|
|
|
* \param Pointer to the Packet to modify
|
|
|
|
* \param Pointer to the data to copy
|
|
|
|
* \param Length of the data to copy
|
|
|
|
*/
|
|
|
|
inline int PacketCopyData(Packet *p, uint8_t *pktdata, int pktlen)
|
|
|
|
{
|
|
|
|
SET_PKT_LEN(p, (size_t)pktlen);
|
|
|
|
return PacketCopyDataOffset(p, 0, pktdata, pktlen);
|
|
|
|
}
|