/* if the TCP connection is closed, then close the HTTP connection */
if ((pstate->flags & APP_LAYER_PARSER_EOF) &&
- ! (hstate->flags & HTP_FLAG_STATE_CLOSED) &&
- ! (hstate->flags & HTP_FLAG_STATE_DATA))
- {
- htp_connp_close(hstate->connp, 0);
- hstate->flags |= HTP_FLAG_STATE_CLOSED;
- SCLogDebug("stream eof encountered, closing htp handle");
+ !(hstate->flags & HTP_FLAG_STATE_CLOSED_TS)) {
+ hstate->connp->in_status = STREAM_STATE_CLOSED;
+ // Call the parsers one last time, which will allow them
+ // to process the events that depend on stream closure
+ htp_connp_req_data(hstate->connp, 0, NULL, 0);
+ hstate->flags |= HTP_FLAG_STATE_CLOSED_TS;
+ SCLogDebug("stream eof encountered, closing htp handle for ts");
}
SCLogDebug("hstate->connp %p", hstate->connp);
/* if we the TCP connection is closed, then close the HTTP connection */
if ((pstate->flags & APP_LAYER_PARSER_EOF) &&
- ! (hstate->flags & HTP_FLAG_STATE_CLOSED) &&
- ! (hstate->flags & HTP_FLAG_STATE_DATA))
- {
- htp_connp_close(hstate->connp, 0);
- hstate->flags |= HTP_FLAG_STATE_CLOSED;
+ !(hstate->flags & HTP_FLAG_STATE_CLOSED_TC)) {
+ hstate->connp->out_status = STREAM_STATE_CLOSED;
+ // Call the parsers one last time, which will allow them
+ // to process the events that depend on stream closure
+ htp_connp_res_data(hstate->connp, 0, NULL, 0);
+ hstate->flags |= HTP_FLAG_STATE_CLOSED_TC;
}
SCLogDebug("hstate->connp %p", hstate->connp);
#define HTP_FLAG_STATE_OPEN 0x0001 /**< Flag to indicate that HTTP
connection is open */
-#define HTP_FLAG_STATE_CLOSED 0x0002 /**< Flag to indicate that HTTP
+#define HTP_FLAG_STATE_CLOSED_TS 0x0002 /**< Flag to indicate that HTTP
connection is closed */
-#define HTP_FLAG_STATE_DATA 0x0004 /**< Flag to indicate that HTTP
+#define HTP_FLAG_STATE_CLOSED_TC 0x0004 /**< Flag to indicate that HTTP
+ connection is closed */
+#define HTP_FLAG_STATE_DATA 0x0008 /**< Flag to indicate that HTTP
connection needs more data */
-#define HTP_FLAG_STATE_ERROR 0x0008 /**< Flag to indicate that an error
+#define HTP_FLAG_STATE_ERROR 0x0010 /**< Flag to indicate that an error
has been occured on HTTP
connection */
-#define HTP_FLAG_NEW_BODY_SET 0x0010 /**< Flag to indicate that HTTP
+#define HTP_FLAG_NEW_BODY_SET 0x0020 /**< Flag to indicate that HTTP
has parsed a new body (for
pcre) */
-#define HTP_FLAG_STORE_FILES_TS 0x0020
-#define HTP_FLAG_STORE_FILES_TC 0x0040
-#define HTP_FLAG_STORE_FILES_TX_TS 0x0080
-#define HTP_FLAG_STORE_FILES_TX_TC 0x0100
+#define HTP_FLAG_STORE_FILES_TS 0x0040
+#define HTP_FLAG_STORE_FILES_TC 0x0080
+#define HTP_FLAG_STORE_FILES_TX_TS 0x0100
+#define HTP_FLAG_STORE_FILES_TX_TC 0x0200
/** flag the state that a new file has been set in this tx */
-#define HTP_FLAG_NEW_FILE_TX_TS 0x0200
+#define HTP_FLAG_NEW_FILE_TX_TS 0x0400
/** flag the state that a new file has been set in this tx */
-#define HTP_FLAG_NEW_FILE_TX_TC 0x0400
+#define HTP_FLAG_NEW_FILE_TX_TC 0x0800
enum {
HTP_BODY_NONE = 0, /**< Flag to indicate the current
if (!(ssn->flags & STREAMTCP_FLAG_APPPROTO_DETECTION_COMPLETED)) {\
flag |= STREAM_START; \
} \
- if ((ssn)->state > TCP_ESTABLISHED) { \
+ if (stream->flags & STREAMTCP_STREAM_FLAG_CLOSE_INITIATED) { \
flag |= STREAM_EOF; \
} \
if ((p)->flowflags & FLOW_PKT_TOSERVER) { \
if (!(ssn->flags & STREAMTCP_FLAG_APPPROTO_DETECTION_COMPLETED)) {\
flag |= STREAM_START; \
} \
- if ((ssn)->state > TCP_ESTABLISHED) { \
+ if (stream->flags & STREAMTCP_STREAM_FLAG_CLOSE_INITIATED) { \
flag |= STREAM_EOF; \
} \
if ((p)->flowflags & FLOW_PKT_TOSERVER) { \
SCLogDebug("setting STREAM_START");
smsg->flags = STREAM_START;
}
- if (ssn->state > TCP_ESTABLISHED) {
+ if (stream->flags & STREAMTCP_STREAM_FLAG_CLOSE_INITIATED) {
SCLogDebug("setting STREAM_EOF");
smsg->flags |= STREAM_EOF;
}
/* send EOF to app layer */
STREAM_SET_INLINE_FLAGS(ssn, stream, p, flags);
AppLayerHandleTCPData(&ra_ctx->dp_ctx, p->flow, ssn,
- NULL, 0, flags|STREAM_EOF);
+ NULL, 0, flags);
PACKET_PROFILING_APP_STORE(&ra_ctx->dp_ctx, p);
} else {
/* send EOF to app layer */
STREAM_SET_INLINE_FLAGS(ssn, stream, p, flags);
AppLayerHandleTCPData(&ra_ctx->dp_ctx, p->flow, ssn,
- NULL, 0, flags|STREAM_EOF);
+ NULL, 0, flags);
PACKET_PROFILING_APP_STORE(&ra_ctx->dp_ctx, p);
}
/* send EOF to app layer */
STREAM_SET_FLAGS(ssn, stream, p, flags);
AppLayerHandleTCPData(&ra_ctx->dp_ctx, p->flow, ssn,
- NULL, 0, flags|STREAM_EOF);
+ NULL, 0, flags);
PACKET_PROFILING_APP_STORE(&ra_ctx->dp_ctx, p);
SCReturnInt(0);
SEQ_EQ(TCP_GET_ACK(p), (ssn->client.isn + 1)))
{
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received and state changed to "
"TCP_CLOSED", ssn);
}
} else {
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received and state changed to "
"TCP_CLOSED", ssn);
}
if (reset == TRUE) {
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received and state changed to "
"TCP_CLOSED", ssn);
if(PKT_IS_TOSERVER(p)) {
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received and state changed to "
"TCP_CLOSED", ssn);
* cleanup. */
} else {
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received and state changed to "
"TCP_CLOSED", ssn);
}
StreamTcpPacketSetState(p, ssn, TCP_CLOSE_WAIT);
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: state changed to TCP_CLOSE_WAIT", ssn);
if (SEQ_EQ(TCP_GET_SEQ(p), ssn->client.next_seq))
}
StreamTcpPacketSetState(p, ssn, TCP_FIN_WAIT1);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: state changed to TCP_FIN_WAIT1", ssn);
if (SEQ_EQ(TCP_GET_SEQ(p), ssn->server.next_seq))
}
StreamTcpPacketSetState(p, ssn, TCP_TIME_WAIT);
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: state changed to TCP_TIME_WAIT", ssn);
ssn->server.window = TCP_GET_WINDOW(p) << ssn->server.wscale;
}
StreamTcpPacketSetState(p, ssn, TCP_TIME_WAIT);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: state changed to TCP_TIME_WAIT", ssn);
ssn->client.window = TCP_GET_WINDOW(p) << ssn->client.wscale;
SCPerfCounterIncr(stt->counter_tcp_pseudo, tv->sc_perf_pca);
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received state changed to TCP_CLOSED",
ssn);
SCPerfCounterIncr(stt->counter_tcp_pseudo, tv->sc_perf_pca);
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received state changed to TCP_CLOSED",
ssn);
}
StreamTcpPacketSetState(p, ssn, TCP_TIME_WAIT);
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: state changed to TCP_TIME_WAIT", ssn);
ssn->server.window = TCP_GET_WINDOW(p) << ssn->server.wscale;
}
StreamTcpPacketSetState(p, ssn, TCP_TIME_WAIT);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: state changed to TCP_TIME_WAIT", ssn);
ssn->client.window = TCP_GET_WINDOW(p) << ssn->client.wscale;
SCPerfCounterIncr(stt->counter_tcp_pseudo, tv->sc_perf_pca);
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received state changed to TCP_CLOSED",
ssn);
}
StreamTcpPacketSetState(p, ssn, TCP_LAST_ACK);
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: state changed to TCP_LAST_ACK", ssn);
ssn->server.window = TCP_GET_WINDOW(p) << ssn->server.wscale;
}
StreamTcpPacketSetState(p, ssn, TCP_LAST_ACK);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: state changed to TCP_LAST_ACK", ssn);
ssn->client.window = TCP_GET_WINDOW(p) << ssn->client.wscale;
SCPerfCounterIncr(stt->counter_tcp_pseudo, tv->sc_perf_pca);
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received state changed to TCP_CLOSED",
ssn);
SCPerfCounterIncr(stt->counter_tcp_pseudo, tv->sc_perf_pca);
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received state changed to TCP_CLOSED",
ssn);
SCPerfCounterIncr(stt->counter_tcp_pseudo, tv->sc_perf_pca);
StreamTcpPacketSetState(p, ssn, TCP_CLOSED);
+ ssn->server.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
+ ssn->client.flags |= STREAMTCP_STREAM_FLAG_CLOSE_INITIATED;
SCLogDebug("ssn %p: Reset received state changed to TCP_CLOSED",
ssn);
if (ssn->state >= TCP_ESTABLISHED) {
p->flags |= PKT_STREAM_EST;
}
- if (ssn->state > TCP_ESTABLISHED) {
- p->flags |= PKT_STREAM_EOF;
+
+ if (PKT_IS_TOSERVER(p)) {
+ if (ssn->client.flags & STREAMTCP_STREAM_FLAG_CLOSE_INITIATED)
+ p->flags |= PKT_STREAM_EOF;
+ } else {
+ if (ssn->server.flags & STREAMTCP_STREAM_FLAG_CLOSE_INITIATED)
+ p->flags |= PKT_STREAM_EOF;
}
}