Commit 4da2496b authored by Tom Barbette's avatar Tom Barbette

Check ACK comes from the right side

parent 23eea7cd
......@@ -435,7 +435,7 @@ eagain:
manageOptions(packet);
p = packet;
if (isAck(p) && fcb_in->common->state == TCPState::ESTABLISHING) {
if (isAck(p) && fcb_in->common->state < TCPState::OPEN) {
fcb_in->common->lastAckReceived[getFlowDirection()] = getAckNumber(p); //We need to do it now before the GT check for the OPEN state
fcb_in->common->state = TCPState::OPEN;
}
......@@ -464,7 +464,14 @@ eagain:
p->kill();
return NULL;
}
} else if (isAck(p) && fcb_in->common->state == TCPState::ESTABLISHING) {
} else if (isAck(p) && fcb_in->common->state < TCPState::OPEN) {
if (getFlowDirection() == 1 && fcb_in->common->state == TCPState::ESTABLISHING_1
|| getFlowDirection() == 0 && fcb_in->common->state == TCPState::ESTABLISHING_2) {
if (_verbose > 1)
click_chatter("Unexpected packet");
p->kill();
return 0;
}
fcb_in->common->lastAckReceived[getFlowDirection()] = getAckNumber(p); //We need to do it now before the GT check for the OPEN state
fcb_in->common->state = TCPState::OPEN;
}
......@@ -517,8 +524,6 @@ eagain:
fcb_in->common->lock.release();
}
putPacketInList(fcb_in, p);
return 0;
}
......@@ -865,7 +870,7 @@ bool TCPIn::checkConnectionClosed(Packet *packet)
goto do_check;
}
return false;
} else if (state == TCPState::ESTABLISHING) {
} else if (state < TCPState::OPEN) {
if (isRst(packet)) {
goto do_check;
}
......@@ -948,6 +953,7 @@ bool TCPIn::assignTCPCommon(Packet *packet, bool keep_fct)
// The data in the flow will start at current sequence number
uint32_t flowStart = getSequenceNumber(packet);
// Check if we are the side initiating the connection or not
// (if ACK flag, we are not the initiator)
if(((flags & TH_ACK && flags & TH_SYN)) || flags & TH_RST)
......@@ -975,6 +981,8 @@ bool TCPIn::assignTCPCommon(Packet *packet, bool keep_fct)
if (allowResize() || returnElement->allowResize()) {
// Initialize the RBT with the RBTManager
if (_verbose > 1)
click_chatter("Initialize direction %d",getFlowDirection());
fcb_in->common->maintainers[getFlowDirection()].initialize(&(*rbtManager), flowStart);
}
//click_chatter("RE Common is %p",fcb_in->common);
......@@ -982,7 +990,8 @@ bool TCPIn::assignTCPCommon(Packet *packet, bool keep_fct)
else
{
if(!(flags & TH_SYN)) {//First packet, not rst and not syn... Discard
//click_chatter("Not syn !");
if (_verbose > 1)
click_chatter("Not syn !");
return false;
}
......@@ -991,7 +1000,6 @@ bool TCPIn::assignTCPCommon(Packet *packet, bool keep_fct)
tcp_common *allocated = poolFcbTcpCommon.allocate();
// Add an entry if the hashtable
tableFcbTcpCommon.find_insert(flowID, allocated);
// Set the pointer in the structure
......@@ -999,9 +1007,16 @@ bool TCPIn::assignTCPCommon(Packet *packet, bool keep_fct)
fcb_in->common->use_count++;
if (allowResize() || returnElement->allowResize()) {
// Initialize the RBT with the RBTManager
if (_verbose > 1)
click_chatter("Initialize direction %d",getFlowDirection());
fcb_in->common->maintainers[getFlowDirection()].initialize(&(*rbtManager), flowStart);
}
if (getFlowDirection() == 1)
fcb_in->common->state = TCPState::ESTABLISHING_1;
else
fcb_in->common->state = TCPState::ESTABLISHING_2;
// Store in our structure the information needed to free the memory
// of the common structure
//fcb_in->flowID = flowID;
......@@ -1028,7 +1043,7 @@ bool TCPIn::assignTCPCommon(Packet *packet, bool keep_fct)
bool TCPIn::isEstablished()
{
auto fcb_in = fcb_data();
return fcb_in->common && fcb_in->common->state > TCPState::ESTABLISHING;
return fcb_in->common && fcb_in->common->state > TCPState::ESTABLISHING_2;
}
bool TCPIn::isLastUsefulPacket(Packet *packet)
......
......@@ -47,7 +47,7 @@ public:
tcp_common() : lastAckReceived() //This is indeed called as it is not part of the FCBs
{
state = TCPState::ESTABLISHING;
//state = TCPState::ESTABLISHING;
use_count = 0;
}
......
......@@ -87,6 +87,10 @@ void WordMatcher::push_batch(int port, fcb_WordMatcher* WordMatcher, PacketBatch
{
WordMatcher->flowBuffer.enqueueAll(flow);
auto iter = WordMatcher->flowBuffer.contentBegin();
if (!iter.current()) {
goto finished;
}
/**
* This is mostly an example element, so we have two modes :
* - Replacement, done inline using the iterator directly in this element
......@@ -96,7 +100,6 @@ void WordMatcher::push_batch(int port, fcb_WordMatcher* WordMatcher, PacketBatch
{
const char* insult = insults[i].c_str();
if (_mask) { //Masking mode
auto iter = WordMatcher->flowBuffer.contentBegin();
auto end = WordMatcher->flowBuffer.contentEnd();
while (iter != end) {
......@@ -136,8 +139,8 @@ void WordMatcher::push_batch(int port, fcb_WordMatcher* WordMatcher, PacketBatch
int result;
FlowBufferContentIter iter;
do {
//iter = WordMatcher->flowBuffer.search(WordMatcher->flowBuffer.contentBegin(), insult, &result);
iter = WordMatcher->flowBuffer.searchSSE(WordMatcher->flowBuffer.contentBegin(), insult, insults[i].length(), &result);
//iter = WordMatcher->flowBuffer.search(iter, insult, &result);
iter = WordMatcher->flowBuffer.searchSSE(iter, insult, insults[i].length(), &result);
//click_chatter("Found %d at %d,",result,iter.current()?iter.leftInChunk():-1);
if (result == 1) {
if (!_insert) { //If not insert, just remove
......
......@@ -15,7 +15,8 @@ struct TCPState
{
enum Value
{
ESTABLISHING = 0,
ESTABLISHING_1 = 0,
ESTABLISHING_2,
OPEN, // The connection is open and nothing has been made to close it
BEING_CLOSED_GRACEFUL_1, // The connection is being closed gracefully (via first FIN packets)
BEING_CLOSED_GRACEFUL_2, // The connection is being closed gracefully (via second FIN packets, second should free after this)
......
......@@ -180,6 +180,7 @@ FlowBufferContentIter FlowBuffer::searchSSE(FlowBufferContentIter start, const c
const __m256i first = _mm256_set1_epi8(needle[0]);
const __m256i last = _mm256_set1_epi8(needle[pattern_length - 1]);
assert(start.entry);
unsigned char* s = start.get_ptr();
int n = start.leftInChunk();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment