Skip to content

Commit

Permalink
stream/midstream: add counter for exception policy
Browse files Browse the repository at this point in the history
  • Loading branch information
jufajardini committed Mar 30, 2023
1 parent 714c1f2 commit ebba762
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions etc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5174,6 +5174,9 @@
"midstream_pickups": {
"type": "integer"
},
"midstream_exception_policy": {
"type": "integer"
},
"no_flow": {
"type": "integer"
},
Expand Down
5 changes: 5 additions & 0 deletions src/stream-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ static int StreamTcpPacketStateNone(
} else if (p->tcph->th_flags & TH_FIN) {
/* Drop reason will only be used if midstream policy is set to fail closed */
ExceptionPolicyApply(p, stream_config.midstream_policy, PKT_DROP_REASON_STREAM_MIDSTREAM);
StatsIncr(tv, stt->counter_tcp_midstream_exc_policy);

if (!stream_config.midstream || p->payload_len == 0) {
StreamTcpSetEvent(p, STREAM_FIN_BUT_NO_SESSION);
Expand Down Expand Up @@ -1060,6 +1061,7 @@ static int StreamTcpPacketStateNone(
} else if ((p->tcph->th_flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK)) {
/* Drop reason will only be used if midstream policy is set to fail closed */
ExceptionPolicyApply(p, stream_config.midstream_policy, PKT_DROP_REASON_STREAM_MIDSTREAM);
StatsIncr(tv, stt->counter_tcp_midstream_exc_policy);

if (!stream_config.midstream && !stream_config.async_oneside) {
SCLogDebug("Midstream not enabled, so won't pick up a session");
Expand Down Expand Up @@ -1233,6 +1235,7 @@ static int StreamTcpPacketStateNone(
} else if (p->tcph->th_flags & TH_ACK) {
/* Drop reason will only be used if midstream policy is set to fail closed */
ExceptionPolicyApply(p, stream_config.midstream_policy, PKT_DROP_REASON_STREAM_MIDSTREAM);
StatsIncr(tv, stt->counter_tcp_midstream_exc_policy);

if (!stream_config.midstream) {
SCLogDebug("Midstream not enabled, so won't pick up a session");
Expand Down Expand Up @@ -5782,6 +5785,8 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
stt->counter_tcp_synack = StatsRegisterCounter("tcp.synack", tv);
stt->counter_tcp_rst = StatsRegisterCounter("tcp.rst", tv);
stt->counter_tcp_midstream_pickups = StatsRegisterCounter("tcp.midstream_pickups", tv);
stt->counter_tcp_midstream_exc_policy =
StatsRegisterCounter("tcp.midstream_exception_policy", tv);
stt->counter_tcp_wrong_thread = StatsRegisterCounter("tcp.pkt_on_wrong_thread", tv);
stt->counter_tcp_ack_unseen_data = StatsRegisterCounter("tcp.ack_unseen_data", tv);

Expand Down
1 change: 1 addition & 0 deletions src/stream-tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ typedef struct StreamTcpThread_ {
uint16_t counter_tcp_rst;
/** midstream pickups */
uint16_t counter_tcp_midstream_pickups;
uint16_t counter_tcp_midstream_exc_policy;
/** wrong thread */
uint16_t counter_tcp_wrong_thread;
/** ack for unseen data */
Expand Down

0 comments on commit ebba762

Please sign in to comment.