From 18d7b32946d09826ac393d68958a64dc08a5efe5 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Fri, 16 May 2008 16:39:23 -0400 Subject: [PATCH] Localize sequence packet checking in SocketZero class Put sequence packet check directly in the SocketZero::RawReceive() function, which now localizes all sequence packet handling and checking, as well as avoids packet order problems when multiple sockets are in use, such as with pppob... FIXME - this localized sequence checking may make all the calls to CheckSequence() obsolete, which should probably be cleaned up someday, if so. --- ChangeLog | 9 +++++++++ src/socket.cc | 48 +++++++++++++++++++++++++++++++++++------------- src/socket.h | 3 +++ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a9dacef..95dc09ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ Release: version 0.13 - 2008/05/?? ------------------------------------------------------------------------------ +2008/05/16 + - put sequence packet check directly in the SocketZero::RawReceive() + function, which now localizes all sequence packet + handling and checking, as well as avoids packet + order problems when multiple sockets are in use, + such as with pppob... + FIXME - this localized sequence checking may make all + the calls to CheckSequence() obsolete which + should probably be cleaned up someday, if so. 2008/05/15 - mention CVS and git on main documentation "how to" list - moved PPP filter logic into its own class diff --git a/src/socket.cc b/src/socket.cc index c68f81ae..3b020eca 100644 --- a/src/socket.cc +++ b/src/socket.cc @@ -158,11 +158,6 @@ unsigned int SocketZero::MakeNextFragment(const Data &whole, Data &fragment, uns // void SocketZero::CheckSequence(uint16_t socket, const Data &seq) { -// if( m_socket == 0 ) { -// // don't do any sequence checking on socket 0 -// return; -// } - MAKE_PACKET(spack, seq); if( (unsigned int) seq.GetSize() < SB_SEQUENCE_PACKET_SIZE ) { eout("Short sequence packet:\n" << seq); @@ -329,15 +324,42 @@ void SocketZero::RawSend(Data &send, int timeout) void SocketZero::RawReceive(Data &receive, int timeout) { - if( m_queue ) { - if( !m_queue->DefaultRead(receive, timeout) ) - throw Timeout("SocketZero::RawReceive: queue DefaultRead returned false (likely a timeout)"); - } - else { - m_dev->BulkRead(m_readEp, receive, timeout); + do { + if( m_queue ) { + if( !m_queue->DefaultRead(receive, timeout) ) + throw Timeout("SocketZero::RawReceive: queue DefaultRead returned false (likely a timeout)"); + } + else { + m_dev->BulkRead(m_readEp, receive, timeout); + } + ddout("SocketZero::RawReceive: Endpoint " << m_readEp + << "\nReceived:\n" << receive); + } while( SequencePacket(receive) ); +} + +// +// SequencePacket +// +/// Returns true if this is a sequence packet that should be ignored. +/// This function is used in SocketZero::RawReceive() in order +/// to determine whether to keep reading or not. By default, +/// this function checks whether the packet is a sequence packet +/// or not, and returns true if so. Also, if it is a sequence +/// packet, it checks the validity of the sequence number. +/// +/// If sequence packets become important in the future, this +/// function could be changed to call a user-defined callback, +/// in order to handle these things out of band. +/// +bool SocketZero::SequencePacket(const Data &data) +{ + if( data.GetSize() >= MIN_PACKET_SIZE ) { + if( IS_COMMAND(data, SB_COMMAND_SEQUENCE_HANDSHAKE) ) { + CheckSequence(0, data); + return true; + } } - ddout("SocketZero::RawReceive: Endpoint " << m_readEp - << "\nReceived:\n" << receive); + return false; // not a sequence packet } void SocketZero::Send(Data &send, int timeout) diff --git a/src/socket.h b/src/socket.h index 3d72b701..0f2fc648 100644 --- a/src/socket.h +++ b/src/socket.h @@ -71,6 +71,9 @@ private: void RawSend(Data &send, int timeout = -1); void RawReceive(Data &receive, int timeout = -1); +protected: + bool SequencePacket(const Data &data); + public: explicit SocketZero(SocketRoutingQueue &queue, int writeEndpoint, uint8_t zeroSocketSequenceStart = 0); -- 2.11.4.GIT