tcp reuse: unify autofp and single/workers check

pull/1342/head
Victor Julien 11 years ago
parent 29f70bad34
commit 11e3f25de3

@ -390,7 +390,7 @@ static inline int FlowCompareICMPv4(Flow *f, const Packet *p)
return 0; return 0;
} }
int TcpSessionPacketSsnReuse(const Packet *p, void *tcp_ssn); int TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, void *tcp_ssn);
static inline int FlowCompare(Flow *f, const Packet *p) static inline int FlowCompare(Flow *f, const Packet *p)
{ {
@ -405,20 +405,13 @@ static inline int FlowCompare(Flow *f, const Packet *p)
if (f->flags & FLOW_TCP_REUSED) if (f->flags & FLOW_TCP_REUSED)
return 0; return 0;
/* lets see if we need to consider the existing session for /* lets see if we need to consider the existing session reuse */
* reuse: only considering SYN packets. */ if (unlikely(TcpSessionPacketSsnReuse(p, f, f->protoctx) == 1)) {
int syn = (p->tcph && ((p->tcph->th_flags & TH_SYN) == TH_SYN)); /* okay, we need to setup a new flow for this packet.
int has_protoctx = ((f->protoctx != NULL)); * Flag the flow that it's been replaced by a new one */
f->flags |= FLOW_TCP_REUSED;
/* syn on existing state, need to see if we need to 'reuse' */ SCLogDebug("flow obsolete: TCP reuse will use a new flow");
if (unlikely(syn && has_protoctx && FlowGetPacketDirection(f,p) == TOSERVER)) { return 0;
if (unlikely(TcpSessionPacketSsnReuse(p, f->protoctx) == 1)) {
/* okay, we need to setup a new flow for this packet.
* Flag the flow that it's been replaced by a new one */
f->flags |= FLOW_TCP_REUSED;
SCLogDebug("flow obsolete: TCP reuse will use a new flow");
return 0;
}
} }
return 1; return 1;
} else { } else {

@ -178,7 +178,7 @@ void FlowSetIPOnlyFlagNoLock(Flow *f, char direction)
* \retval 0 to_server * \retval 0 to_server
* \retval 1 to_client * \retval 1 to_client
*/ */
int FlowGetPacketDirection(Flow *f, const Packet *p) int FlowGetPacketDirection(const Flow *f, const Packet *p)
{ {
if (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP || p->proto == IPPROTO_SCTP) { if (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP || p->proto == IPPROTO_SCTP) {
if (!(CMP_PORT(p->sp,p->dp))) { if (!(CMP_PORT(p->sp,p->dp))) {

@ -444,7 +444,7 @@ static inline void FlowLockSetNoPayloadInspectionFlag(Flow *);
static inline void FlowSetNoPayloadInspectionFlag(Flow *); static inline void FlowSetNoPayloadInspectionFlag(Flow *);
static inline void FlowSetSessionNoApplayerInspectionFlag(Flow *); static inline void FlowSetSessionNoApplayerInspectionFlag(Flow *);
int FlowGetPacketDirection(Flow *, const Packet *); int FlowGetPacketDirection(const Flow *, const Packet *);
void FlowCleanupAppLayer(Flow *); void FlowCleanupAppLayer(Flow *);

@ -4386,18 +4386,6 @@ static int StreamTcpPacketIsBadWindowUpdate(TcpSession *ssn, Packet *p)
return 0; return 0;
} }
int TcpSessionPacketSsnReuse(const Packet *p, void *tcp_ssn)
{
TcpSession *ssn = tcp_ssn;
if (ssn->state == TCP_CLOSED) {
if(!(SEQ_EQ(ssn->client.isn, TCP_GET_SEQ(p))))
{
return 1;
}
}
return 0;
}
/* flow is and stays locked */ /* flow is and stays locked */
int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt, int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
PacketQueue *pq) PacketQueue *pq)
@ -4706,9 +4694,9 @@ static int TcpSessionPacketIsStreamStarter(const Packet *p)
/** \internal /** \internal
* \brief Check if Flow and TCP SSN allow this flow/tuple to be reused * \brief Check if Flow and TCP SSN allow this flow/tuple to be reused
* \retval bool true yes reuse, false no keep tracking old ssn */ * \retval bool true yes reuse, false no keep tracking old ssn */
int TcpSessionReuseDoneEnough(Packet *p, const TcpSession *ssn) int TcpSessionReuseDoneEnough(const Packet *p, const Flow *f, const TcpSession *ssn)
{ {
if (FlowGetPacketDirection(p->flow, p) == TOSERVER) { if (FlowGetPacketDirection(f, p) == TOSERVER) {
if (ssn == NULL) { if (ssn == NULL) {
SCLogDebug("steam starter packet %"PRIu64", ssn %p null. No reuse.", p->pcap_cnt, ssn); SCLogDebug("steam starter packet %"PRIu64", ssn %p null. No reuse.", p->pcap_cnt, ssn);
return 0; return 0;
@ -4749,11 +4737,22 @@ int TcpSessionReuseDoneEnough(Packet *p, const TcpSession *ssn)
} }
} }
SCLogDebug("default: how did we get here?"); SCLogDebug("default: how did we get here?");
return 0; return 0;
} }
int TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, const void *tcp_ssn)
{
if (p->proto == IPPROTO_TCP && p->tcph != NULL) {
if (TcpSessionPacketIsStreamStarter(p) == 1) {
if (TcpSessionReuseDoneEnough(p, f, tcp_ssn) == 1) {
return 1;
}
}
}
return 0;
}
/** \brief Handle TCP reuse of tuple /** \brief Handle TCP reuse of tuple
* *
* Logic: * Logic:
@ -4779,7 +4778,7 @@ static void TcpSessionReuseHandle(Packet *p) {
int reuse = 0; int reuse = 0;
FLOWLOCK_RDLOCK(p->flow); FLOWLOCK_RDLOCK(p->flow);
reuse = TcpSessionReuseDoneEnough(p, p->flow->protoctx); reuse = TcpSessionReuseDoneEnough(p, p->flow, p->flow->protoctx);
if (!reuse) { if (!reuse) {
SCLogDebug("steam starter packet %"PRIu64", but state not " SCLogDebug("steam starter packet %"PRIu64", but state not "
"ready to be reused", p->pcap_cnt); "ready to be reused", p->pcap_cnt);

Loading…
Cancel
Save