Skip to content

Commit 400328c

Browse files
Lukas Sismisvictorjulien
authored andcommitted
pcap-file: prep codebase for pcap_cnt move refactor
For an easier review process, this is a two-step change process, in which pcap_cnt is first accessed by functions-to-be, implemented as simple macros. In the follow-up commit, the actual refactor is implemented with the new function. The old macros are deleted. Ticket: 7835
1 parent f33f6e7 commit 400328c

42 files changed

Lines changed: 266 additions & 214 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

plugins/ndpi/ndpi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,18 @@ static int DetectnDPIProtocolPacketMatch(
191191
/*
192192
if (s->type == SIG_TYPE_PDONLY &&
193193
(p->flags & (PKT_PROTO_DETECT_TS_DONE | PKT_PROTO_DETECT_TC_DONE)) == 0) {
194-
SCLogDebug("packet %"PRIu64": flags not set", p->pcap_cnt);
194+
SCLogDebug("packet %"PRIu64": flags not set", PcapPacketCntGet(p));
195195
SCReturnInt(0);
196196
}
197197
*/
198198

199199
if (!flowctx->detection_completed) {
200-
SCLogDebug("packet %" PRIu64 ": ndpi protocol not yet detected", p->pcap_cnt);
200+
SCLogDebug("packet %" PRIu64 ": ndpi protocol not yet detected", PcapPacketCntGet(p));
201201
SCReturnInt(0);
202202
}
203203

204204
if (f == NULL) {
205-
SCLogDebug("packet %" PRIu64 ": no flow", p->pcap_cnt);
205+
SCLogDebug("packet %" PRIu64 ": no flow", PcapPacketCntGet(p));
206206
SCReturnInt(0);
207207
}
208208

@@ -318,12 +318,12 @@ static int DetectnDPIRiskPacketMatch(
318318
SCEnter();
319319

320320
if (!flowctx->detection_completed) {
321-
SCLogDebug("packet %" PRIu64 ": ndpi risks not yet detected", p->pcap_cnt);
321+
SCLogDebug("packet %" PRIu64 ": ndpi risks not yet detected", PcapPacketCntGet(p));
322322
SCReturnInt(0);
323323
}
324324

325325
if (f == NULL) {
326-
SCLogDebug("packet %" PRIu64 ": no flow", p->pcap_cnt);
326+
SCLogDebug("packet %" PRIu64 ": no flow", PcapPacketCntGet(p));
327327
SCReturnInt(0);
328328
}
329329

src/alert-debuglog.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ static TmEcode AlertDebugLogger(ThreadVars *tv, const Packet *p, void *thread_da
167167

168168
MemBufferWriteString(aft->buffer, "+================\n"
169169
"TIME: %s\n", timebuf);
170-
if (p->pcap_cnt > 0) {
171-
MemBufferWriteString(aft->buffer, "PCAP PKT NUM: %"PRIu64"\n", p->pcap_cnt);
170+
uint64_t pcap_cnt = PcapPacketCntGet(p);
171+
if (pcap_cnt > 0) {
172+
MemBufferWriteString(aft->buffer, "PCAP PKT NUM: %" PRIu64 "\n", pcap_cnt);
172173
}
173174
pkt_src_str = PktSrcToString(p->pkt_src);
174175
MemBufferWriteString(aft->buffer, "PKT SRC: %s\n", pkt_src_str);
@@ -327,9 +328,9 @@ static TmEcode AlertDebugLogDecoderEvent(ThreadVars *tv, const Packet *p, void *
327328
MemBufferWriteString(aft->buffer,
328329
"+================\n"
329330
"TIME: %s\n", timebuf);
330-
if (p->pcap_cnt > 0) {
331-
MemBufferWriteString(aft->buffer,
332-
"PCAP PKT NUM: %"PRIu64"\n", p->pcap_cnt);
331+
uint64_t pcap_cnt = PcapPacketCntGet(p);
332+
if (pcap_cnt > 0) {
333+
MemBufferWriteString(aft->buffer, "PCAP PKT NUM: %" PRIu64 "\n", pcap_cnt);
333334
}
334335
pkt_src_str = PktSrcToString(p->pkt_src);
335336
MemBufferWriteString(aft->buffer, "PKT SRC: %s\n", pkt_src_str);

src/alert-fastlog.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p)
179179
pa->s->id, pa->s->rev, pa->s->msg, pa->s->class_msg, pa->s->prio);
180180
PrintBufferRawLineHex(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
181181
GET_PKT_DATA(p), GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
182-
if (p->pcap_cnt != 0) {
183-
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
184-
"] [pcap file packet: %"PRIu64"]\n", p->pcap_cnt);
182+
uint64_t pcap_cnt = PcapPacketCntGet(p);
183+
if (pcap_cnt != 0) {
184+
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
185+
"] [pcap file packet: %" PRIu64 "]\n", pcap_cnt);
185186
} else {
186187
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE, "]\n");
187188
}

src/alert-syslog.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,10 @@ static TmEcode AlertSyslogDecoderEvent(ThreadVars *tv, const Packet *p, void *da
343343
PrintRawLineHexBuf(temp_buf_pkt, sizeof(temp_buf_pkt), GET_PKT_DATA(p), GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
344344
strlcat(alert, temp_buf_pkt, sizeof(alert));
345345

346-
if (p->pcap_cnt != 0) {
347-
snprintf(temp_buf_tail, sizeof(temp_buf_tail), "] [pcap file packet: %"PRIu64"]",
348-
p->pcap_cnt);
346+
uint64_t pcap_cnt = PcapPacketCntGet(p);
347+
if (pcap_cnt != 0) {
348+
snprintf(temp_buf_tail, sizeof(temp_buf_tail), "] [pcap file packet: %" PRIu64 "]",
349+
pcap_cnt);
349350
} else {
350351
temp_buf_tail[0] = ']';
351352
temp_buf_tail[1] = '\0';

src/app-layer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,9 @@ static int TCPProtoDetect(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
657657
AppLayerIncFlowCounter(tv, f);
658658

659659
*alproto = *alproto_otherdir;
660-
SCLogDebug("packet %"PRIu64": pd done(us %u them %u), parser called (r==%d), APPLAYER_DETECT_PROTOCOL_ONLY_ONE_DIRECTION set",
661-
p->pcap_cnt, *alproto, *alproto_otherdir, r);
660+
SCLogDebug("packet %" PRIu64 ": pd done(us %u them %u), parser called (r==%d), "
661+
"APPLAYER_DETECT_PROTOCOL_ONLY_ONE_DIRECTION set",
662+
PcapPacketCntGet(p), *alproto, *alproto_otherdir, r);
662663
if (r < 0) {
663664
goto parser_error;
664665
}

src/decode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,4 +1522,12 @@ static inline bool DecodeNetworkLayer(ThreadVars *tv, DecodeThreadVars *dtv,
15221522
return true;
15231523
}
15241524

1525+
// temporary macro to get pcap packet count to reduce the number of changes
1526+
// in the follow-up commit
1527+
#define PcapPacketCntGet(p) (p)->pcap_cnt
1528+
#define PcapPacketCntSet(p, cnt) \
1529+
do { \
1530+
(p)->pcap_cnt = (cnt); \
1531+
} while (0)
1532+
15251533
#endif /* SURICATA_DECODE_H */

src/defrag-hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ static void DefragExceptionPolicyStatsIncr(
469469
static DefragTracker *DefragTrackerGetNew(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
470470
{
471471
#ifdef DEBUG
472-
if (g_eps_defrag_memcap != UINT64_MAX && g_eps_defrag_memcap == p->pcap_cnt) {
473-
SCLogNotice("simulating memcap hit for packet %" PRIu64, p->pcap_cnt);
472+
if (g_eps_defrag_memcap != UINT64_MAX && g_eps_defrag_memcap == PcapPacketCntGet(p)) {
473+
SCLogNotice("simulating memcap hit for packet %" PRIu64, PcapPacketCntGet(p));
474474
ExceptionPolicyApply(p, defrag_config.memcap_policy, PKT_DROP_REASON_DEFRAG_MEMCAP);
475475
DefragExceptionPolicyStatsIncr(tv, dtv, defrag_config.memcap_policy);
476476
return NULL;

src/defrag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ DefragInsertFrag(ThreadVars *tv, DecodeThreadVars *dtv, DefragTracker *tracker,
584584
uint8_t ip6_nh_set_value = 0;
585585

586586
#ifdef DEBUG
587-
uint64_t pcap_cnt = p->pcap_cnt;
587+
uint64_t pcap_cnt = PcapPacketCntGet(p);
588588
#endif
589589

590590
if (tracker->af == AF_INET) {

src/detect-app-layer-protocol.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ static int DetectAppLayerProtocolPacketMatch(
6565
/* if the sig is PD-only we only match when PD packet flags are set */
6666
if (s->type == SIG_TYPE_PDONLY &&
6767
(p->flags & (PKT_PROTO_DETECT_TS_DONE | PKT_PROTO_DETECT_TC_DONE)) == 0) {
68-
SCLogDebug("packet %"PRIu64": flags not set", p->pcap_cnt);
68+
SCLogDebug("packet %" PRIu64 ": flags not set", PcapPacketCntGet(p));
6969
SCReturnInt(0);
7070
}
7171

7272
const Flow *f = p->flow;
7373
if (f == NULL) {
74-
SCLogDebug("packet %"PRIu64": no flow", p->pcap_cnt);
74+
SCLogDebug("packet %" PRIu64 ": no flow", PcapPacketCntGet(p));
7575
SCReturnInt(0);
7676
}
7777

@@ -289,17 +289,17 @@ PrefilterPacketAppProtoMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const vo
289289
const PrefilterPacketHeaderCtx *ctx = pectx;
290290

291291
if (!PrefilterPacketHeaderExtraMatch(ctx, p)) {
292-
SCLogDebug("packet %"PRIu64": extra match failed", p->pcap_cnt);
292+
SCLogDebug("packet %" PRIu64 ": extra match failed", PcapPacketCntGet(p));
293293
SCReturn;
294294
}
295295

296296
if (p->flow == NULL) {
297-
SCLogDebug("packet %"PRIu64": no flow, no alproto", p->pcap_cnt);
297+
SCLogDebug("packet %" PRIu64 ": no flow, no alproto", PcapPacketCntGet(p));
298298
SCReturn;
299299
}
300300

301301
if ((p->flags & (PKT_PROTO_DETECT_TS_DONE|PKT_PROTO_DETECT_TC_DONE)) == 0) {
302-
SCLogDebug("packet %"PRIu64": flags not set", p->pcap_cnt);
302+
SCLogDebug("packet %" PRIu64 ": flags not set", PcapPacketCntGet(p));
303303
SCReturn;
304304
}
305305

src/detect-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static int ConfigApply(DetectEngineThreadCtx *det_ctx,
187187
}
188188

189189
if (this_packet) {
190-
SCLogDebug("packet logic here: %" PRIu64, p->pcap_cnt);
190+
SCLogDebug("packet logic here: %" PRIu64, PcapPacketCntGet(p));
191191
ConfigApplyPacket(p, config);
192192
} else if (this_tx) {
193193
SCLogDebug("tx logic here: tx_id %"PRIu64, det_ctx->tx_id);

0 commit comments

Comments
 (0)