00001 //--------------------------------------------------------------------------
00002 // Copyright (C) 2015-2017 Cisco and/or its affiliates. All rights reserved.
00003 //
00004 // This program is free software; you can redistribute it and/or modify it
00005 // under the terms of the GNU General Public License Version 2 as published
00006 // by the Free Software Foundation. You may not use, modify or distribute
00007 // this program under any other version of the GNU General Public License.
00008 //
00009 // This program is distributed in the hope that it will be useful, but
00010 // WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program; if not, write to the Free Software Foundation, Inc.,
00016 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017 //--------------------------------------------------------------------------
00018
00019 // tcp_state_syn_sent.cc author davis mcpherson <davmcphe@cisco.com>
00020 // Created on: Aug 5, 2015
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include "config.h"
00024 #endif
00025
00026 #include "tcp_state_syn_sent.h"
00027
00028 #include "tcp_session.h"
00029
00030 using namespace std;
00031
00032 TcpStateSynSent::TcpStateSynSent(TcpStateMachine& tsm) :
00033 TcpStateHandler(TcpStreamTracker::TCP_SYN_SENT, tsm)
00034 {
00035 }
00036
00037
00038 bool TcpStateSynSent::syn_sent(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00039 {
00040 trk.session->check_for_repeated_syn(tsd);
00041
00042 return default_state_action(tsd, trk);
00043 }
00044
00045 bool TcpStateSynSent::syn_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00046 {
00047 trk.finish_client_init(tsd);
00048 if ( tsd.get_seg_len() )
00049 trk.session->handle_data_on_syn(tsd);
00050 trk.set_tcp_state(TcpStreamTracker::TCP_SYN_RECV);
00051
00052 return default_state_action(tsd, trk);
00053 }
00054
00055 bool TcpStateSynSent::syn_ack_sent(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00056 {
00057 return default_state_action(tsd, trk);
00058 }
00059
00060 bool TcpStateSynSent::syn_ack_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00061 {
00062 if ( trk.update_on_3whs_ack(tsd) )
00063 {
00064 trk.session->update_timestamp_tracking(tsd);
00065 if ( tsd.get_seg_len() )
00066 trk.session->handle_data_on_syn(tsd);
00067 }
00068 else
00069 trk.session->set_pkt_action_flag(ACTION_BAD_PKT);
00070
00071 return default_state_action(tsd, trk);
00072 }
00073
00074 bool TcpStateSynSent::ack_sent(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00075 {
00076 Flow* flow = tsd.get_flow();
00077
00078 // FIXIT-H verify ack being sent is valid...
00079 trk.update_tracker_ack_sent(tsd);
00080 flow->set_session_flags(SSNFLAG_ESTABLISHED);
00081 flow->session_state |= ( STREAM_STATE_ACK | STREAM_STATE_ESTABLISHED );
00082 trk.session->update_timestamp_tracking(tsd);
00083 trk.session->update_perf_base_state(TcpStreamTracker::TCP_ESTABLISHED);
00084 trk.set_tcp_state(TcpStreamTracker::TCP_ESTABLISHED);
00085 trk.r_nxt_ack = tsd.get_seg_ack();
00086
00087 return default_state_action(tsd, trk);
00088 }
00089
00090 bool TcpStateSynSent::ack_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00091 {
00092 if ( tsd.get_seg_len() > 0 )
00093 trk.session->handle_data_segment(tsd);
00094
00095 return default_state_action(tsd, trk);
00096 }
00097
00098 bool TcpStateSynSent::data_seg_sent(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00099 {
00100 Flow* flow = tsd.get_flow();
00101
00102 // FIXIT-H verify ack being sent is valid...
00103 trk.update_tracker_ack_sent(tsd);
00104 flow->set_session_flags(SSNFLAG_ESTABLISHED);
00105 flow->session_state |= ( STREAM_STATE_ACK | STREAM_STATE_ESTABLISHED );
00106 trk.session->update_timestamp_tracking(tsd);
00107 trk.session->update_perf_base_state(TcpStreamTracker::TCP_ESTABLISHED);
00108 trk.set_tcp_state(TcpStreamTracker::TCP_ESTABLISHED);
00109
00110 return default_state_action(tsd, trk);
00111 }
00112
00113 bool TcpStateSynSent::data_seg_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00114 {
00115 trk.session->handle_data_segment(tsd);
00116
00117 return default_state_action(tsd, trk);
00118 }
00119
00120 bool TcpStateSynSent::fin_sent(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00121 {
00122 return default_state_action(tsd, trk);
00123 }
00124
00125 bool TcpStateSynSent::fin_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00126 {
00127 if ( tsd.get_seg_len() > 0 )
00128 trk.session->handle_data_segment(tsd);
00129
00130 return default_state_action(tsd, trk);
00131 }
00132
00133 bool TcpStateSynSent::rst_sent(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00134 {
00135 return default_state_action(tsd, trk);
00136 }
00137
00138 bool TcpStateSynSent::rst_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk)
00139 {
00140 if ( trk.update_on_rst_recv(tsd) )
00141 {
00142 trk.session->update_session_on_rst(tsd, false);
00143 trk.set_tcp_state(TcpStreamTracker::TCP_CLOSED);
00144 trk.session->update_perf_base_state(TcpStreamTracker::TCP_CLOSED);
00145 trk.session->set_pkt_action_flag(ACTION_RST);
00146 tsd.get_pkt()->flow->session_state |= STREAM_STATE_CLOSED;
00147 }
00148 else
00149 {
00150 trk.session->tel.set_tcp_event(EVENT_BAD_RST);
00151 }
00152
00153 // FIXIT-L might be good to create alert specific to RST with data
00154 if ( tsd.get_seg_len() > 0 )
00155 trk.session->tel.set_tcp_event(EVENT_DATA_AFTER_RST_RCVD);
00156
00157 return default_state_action(tsd, trk);
00158 }
00159
END OF CODE