From d307cfad052d8ecbd69332dc9ea8229f2794435c Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 27 Jul 2018 12:24:20 +0200 Subject: [PATCH] packet: add 'swap' function to reverse direction --- src/decode.c | 22 ++++++++++++++++++++++ src/decode.h | 1 + src/stream-tcp.h | 19 +------------------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/decode.c b/src/decode.c index dfcd8dacf9..b19365d054 100644 --- a/src/decode.c +++ b/src/decode.c @@ -414,6 +414,28 @@ void PacketBypassCallback(Packet *p) } } +/** \brief switch direction of a packet */ +void PacketSwap(Packet *p) +{ + if (PKT_IS_TOSERVER(p)) { + p->flowflags &= ~FLOW_PKT_TOSERVER; + p->flowflags |= FLOW_PKT_TOCLIENT; + + if (p->flowflags & FLOW_PKT_TOSERVER_FIRST) { + p->flowflags &= ~FLOW_PKT_TOSERVER_FIRST; + p->flowflags |= FLOW_PKT_TOCLIENT_FIRST; + } + } else { + p->flowflags &= ~FLOW_PKT_TOCLIENT; + p->flowflags |= FLOW_PKT_TOSERVER; + + if (p->flowflags & FLOW_PKT_TOCLIENT_FIRST) { + p->flowflags &= ~FLOW_PKT_TOCLIENT_FIRST; + p->flowflags |= FLOW_PKT_TOSERVER_FIRST; + } + } +} + /* counter name store */ static HashTable *g_counter_table = NULL; static SCMutex g_counter_table_mutex = SCMUTEX_INITIALIZER; diff --git a/src/decode.h b/src/decode.h index bbad1bb4b8..ba07c771cc 100644 --- a/src/decode.h +++ b/src/decode.h @@ -917,6 +917,7 @@ int PacketSetData(Packet *p, uint8_t *pktdata, uint32_t pktlen); int PacketCopyDataOffset(Packet *p, uint32_t offset, uint8_t *data, uint32_t datalen); const char *PktSrcToString(enum PktSrcEnum pkt_src); void PacketBypassCallback(Packet *p); +void PacketSwap(Packet *p); DecodeThreadVars *DecodeThreadVarsAlloc(ThreadVars *); void DecodeThreadVarsFree(ThreadVars *, DecodeThreadVars *); diff --git a/src/stream-tcp.h b/src/stream-tcp.h index bf383ff0f2..7ad867bdce 100644 --- a/src/stream-tcp.h +++ b/src/stream-tcp.h @@ -176,24 +176,7 @@ static inline int StreamTcpCheckFlowDrops(Packet *p) static inline void StreamTcpPacketSwitchDir(TcpSession *ssn, Packet *p) { SCLogDebug("ssn %p: switching pkt direction", ssn); - - if (PKT_IS_TOSERVER(p)) { - p->flowflags &= ~FLOW_PKT_TOSERVER; - p->flowflags |= FLOW_PKT_TOCLIENT; - - if (p->flowflags & FLOW_PKT_TOSERVER_FIRST) { - p->flowflags &= ~FLOW_PKT_TOSERVER_FIRST; - p->flowflags |= FLOW_PKT_TOCLIENT_FIRST; - } - } else { - p->flowflags &= ~FLOW_PKT_TOCLIENT; - p->flowflags |= FLOW_PKT_TOSERVER; - - if (p->flowflags & FLOW_PKT_TOCLIENT_FIRST) { - p->flowflags &= ~FLOW_PKT_TOCLIENT_FIRST; - p->flowflags |= FLOW_PKT_TOSERVER_FIRST; - } - } + PacketSwap(p); } enum { -- 2.47.3