Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

spp_stream4.c File Reference

#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <rpc/types.h>
#include "bounds.h"
#include "decode.h"
#include "event.h"
#include "debug.h"
#include "util.h"
#include "plugbase.h"
#include "parser.h"
#include "mstring.h"
#include "checksum.h"
#include "log.h"
#include "generators.h"
#include "detect.h"
#include "perf.h"
#include "timersub.h"
#include "ubi_SplayTree.h"
#include "snort.h"
#include "stream.h"
#include "spp_stream4.h"
#include "snort_packet_header.h"
#include "event_queue.h"
#include "inline.h"
#include "sfghash.h"
#include "snort_stream4_session.h"

Go to the source code of this file.

Defines

#define INLINE   inline
#define CLOSED   0
#define LISTEN   1
#define SYN_RCVD   2
#define SYN_SENT   3
#define ESTABLISHED   4
#define CLOSE_WAIT   5
#define LAST_ACK   6
#define FIN_WAIT_1   7
#define CLOSING   8
#define FIN_WAIT_2   9
#define TIME_WAIT   10
#define NMAP_FINGERPRINT_2S   30
#define NMAP_FINGERPRINT_NULL   31
#define NMAP_FINGERPRINT_UPSF   32
#define NMAP_FINGERPRINT_ZERO_ACK   33
#define ACTION_NOTHING   0x00000000
#define ACTION_FLUSH_SERVER_STREAM   0x00000001
#define ACTION_FLUSH_CLIENT_STREAM   0x00000002
#define ACTION_DROP_SESSION   0x00000004
#define ACTION_ACK_SERVER_DATA   0x00000008
#define ACTION_ACK_CLIENT_DATA   0x00000010
#define ACTION_DATA_ON_SYN   0x00000020
#define ACTION_SET_SERVER_ISN   0x00000040
#define ACTION_COMPLETE_TWH   0x00000080
#define ACTION_ALERT_NMAP_FINGERPRINT   0x00000100
#define ACTION_INC_PORT   0x00000200
#define FROM_SERVER   0
#define FROM_CLIENT   1
#define PRUNE_QUANTA   30
#define STREAM4_MEMORY_CAP   8388608
#define STREAM4_MAX_SESSIONS   8192
#define STREAM4_CLEANUP   5
#define STREAM4_CACHE_PERCENT   0.1
#define STREAM4_TTL_LIMIT   5
#define DEFAULT_STREAM_TRACKERS   256000
#define STATS_HUMAN_READABLE   1
#define STATS_MACHINE_READABLE   2
#define STATS_BINARY   3
#define STATS_MAGIC   0xDEAD029A
#define REVERSE   0
#define NO_REVERSE   1
#define METHOD_FAVOR_NEW   0x01
#define METHOD_FAVOR_OLD   0x02
#define UNESTABLISHED_MAX_PCOUNT   300
#define MAX_STREAM_SIZE   (IP_MAXPACKET - IP_HEADER_LEN - TCP_HEADER_LEN - ETHERNET_HEADER_LEN)
#define SEQ_LT(a, b)   ((int)((a) - (b)) < 0)
#define SEQ_LEQ(a, b)   ((int)((a) - (b)) <= 0)
#define SEQ_GT(a, b)   ((int)((a) - (b)) > 0)
#define SEQ_GEQ(a, b)   ((int)((a) - (b)) >= 0)
#define SEQ_EQ(a, b)   ((int)((a) - (b)) == 0)
#define NO_CHK_SEQ   0
#define CHK_SEQ   1
#define S4I
#define SPARC_TWIDDLE   0
#define SELF_PRES_THRESHOLD   50
#define SELF_PRES_PERIOD   90
#define SUSPEND_THRESHOLD   200
#define SUSPEND_PERIOD   30
#define OPS_NORMAL   0
#define OPS_SELF_PRESERVATION   1
#define OPS_SUSPEND   2
#define MAXSIZE_IP   65535
#define MAX_TRACKER_AMOUNT   (MAX_STREAM_SIZE + 4000)
#define FCOUNT   64
#define STREAM4_FLUSH_BASE   512
#define STREAM4_FLUSH_RANGE   1213
#define FLUSH_BEHAVIOR_RANDOM   -1
#define FLUSH_BEHAVIOR_DEFAULT   0
#define FLUSH_BEHAVIOR_LARGE   1

Typedefs

typedef _OverlapData OverlapData
typedef _BuildData BuildData
typedef _BinStats BinStats
typedef _StatsLog StatsLog
typedef _StatsLogHeader StatsLogHeader
typedef _S4Emergency S4Emergency
typedef _StreamKey STREAM_KEY
typedef SessionSessionPtr

Functions

void * SafeAlloc (unsigned long, int, Session *)
void ParseStream4Args (char *)
void Stream4InitReassembler (u_char *)
void ReassembleStream4 (Packet *, void *)
SessionCreateNewSession (Packet *, u_int32_t, u_int32_t)
void DropSession (Session *)
void DeleteSession (Session *, u_int32_t)
void DeleteSpd (ubi_trRootPtr)
int GetDirection (Session *, Packet *)
void Stream4ShutdownFunction (int, void *)
void Stream4CleanExitFunction (int, void *)
void Stream4RestartFunction (int, void *)
void PrintSessionCache ()
int CheckRst (Session *, int, u_int32_t, Packet *)
int PruneSessionCache (u_int32_t, int, Session *)
void StoreStreamPkt (Session *, Packet *, u_int32_t)
void FlushStream (Stream *, Packet *, int)
void InitStream4Pkt ()
int BuildPacket (Stream *, u_int32_t, Packet *, int)
int CheckPorts (u_int16_t, u_int16_t)
void PortscanWatch (Session *, u_int32_t)
void PortscanDeclare (Packet *)
void AddNewTarget (ubi_trRootPtr, u_int32_t, u_int16_t, u_int8_t)
void AddNewPort (ubi_trRootPtr, u_int16_t, u_int8_t)
int LogStream (Stream *)
void WriteSsnStats (BinStats *)
void OpenStatsFile ()
static int RetransTooFast (struct timeval *old, struct timeval *new)
void Stream4Init (u_char *)
void PreprocFunction (Packet *)
void PreprocRestartFunction (int)
void PreprocCleanExitFunction (int)
static INLINE int isBetween (u_int32_t low, u_int32_t high, u_int32_t cur)
static INLINE int NotForStream4 (Packet *p)
static INLINE int SetFinSent (Packet *p, Session *ssn, int direction)
static INLINE int WithinSessionLimits (Packet *p, Stream *stream)
static INLINE void StreamSegmentSub (Stream *stream, u_int16_t sub)
static INLINE void StreamSegmentAdd (Stream *stream, u_int16_t add)
int UpdateState (Session *, Packet *, u_int32_t)
int UpdateState2 (Session *, Packet *, u_int32_t)
int UpdateStateAsync (Session *, Packet *, u_int32_t)
static void TcpAction (Session *ssn, Packet *p, int action, int direction, u_int32_t pkt_seq, u_int32_t pkt_ack)
static void TcpActionAsync (Session *ssn, Packet *p, int action, int direction, u_int32_t pkt_seq, u_int32_t pkt_ack)
int LoadStateTable (const u_int32_t thetime, const char *path)
static int DataCompareFunc (ubi_trItemPtr ItemPtr, ubi_trNodePtr NodePtr)
static int OverlapCompareFunc (ubi_trItemPtr ItemPtr, void *data)
static void KillSpd (ubi_trNodePtr NodePtr)
static void TraverseFunc (ubi_trNodePtr NodePtr, void *build_data)
void SegmentCleanTraverse (Stream *s)
void DirectLogTcpdump (struct pcap_pkthdr *, u_int8_t *)
static void LogTraverse (ubi_trNodePtr NodePtr, void *foo)
void SetupStream4 ()
void DisplayStream4Config (void)
static INLINE void PruneCheck (Packet *p)
void INLINE QueueState (u_int8_t transition, Stream *sptr, u_int8_t expected_flags, u_int32_t seq_num, u_int8_t chk_seq)
int INLINE EvalStateQueue (Stream *sptr, u_int8_t flags, u_int32_t ack)
void FlushDeletedStream (Session *ssn, Stream *s)
static u_int32_t GetTcpTimestamp (Packet *p, u_int32_t *ts)
int AlertFlushStream (Packet *p)
static void InitFakePkt (Packet *p)
static char parse_one_v1 (u_int32_t thetime, Packet *fakep, struct parse_v1_file *parse)

Variables

char * file_name
int * file_line
int opdsize
static u_int32_t old_flush_points [FCOUNT]
static u_int32_t new_flush_points [FCOUNT]
StatsLogstats_log
u_int32_t safe_alloc_faults
Packetstream_pkt
int do_detect
FILE * session_log
Stream4Data s4data
u_int32_t stream4_memory_usage
u_int32_t ps_memory_usage
S4Emergency s4_emergency
u_int32_t flush_points [FCOUNT]


Define Documentation

#define ACTION_ACK_CLIENT_DATA   0x00000010
 

Definition at line 159 of file spp_stream4.c.

Referenced by TcpAction(), TcpActionAsync(), and UpdateState2().

#define ACTION_ACK_SERVER_DATA   0x00000008
 

Definition at line 158 of file spp_stream4.c.

Referenced by TcpAction(), TcpActionAsync(), and UpdateState2().

#define ACTION_ALERT_NMAP_FINGERPRINT   0x00000100
 

Definition at line 163 of file spp_stream4.c.

Referenced by TcpAction(), and TcpActionAsync().

#define ACTION_COMPLETE_TWH   0x00000080
 

Definition at line 162 of file spp_stream4.c.

Referenced by TcpAction(), TcpActionAsync(), UpdateState2(), and UpdateStateAsync().

#define ACTION_DATA_ON_SYN   0x00000020
 

Definition at line 160 of file spp_stream4.c.

Referenced by TcpAction(), TcpActionAsync(), and UpdateState2().

#define ACTION_DROP_SESSION   0x00000004
 

Definition at line 157 of file spp_stream4.c.

Referenced by TcpAction(), TcpActionAsync(), UpdateState2(), and UpdateStateAsync().

#define ACTION_FLUSH_CLIENT_STREAM   0x00000002
 

Definition at line 156 of file spp_stream4.c.

Referenced by ReassembleStream4(), TcpAction(), TcpActionAsync(), UpdateState2(), and UpdateStateAsync().

#define ACTION_FLUSH_SERVER_STREAM   0x00000001
 

Definition at line 155 of file spp_stream4.c.

Referenced by ReassembleStream4(), TcpAction(), TcpActionAsync(), UpdateState2(), and UpdateStateAsync().

#define ACTION_INC_PORT   0x00000200
 

Definition at line 164 of file spp_stream4.c.

Referenced by TcpAction(), and TcpActionAsync().

#define ACTION_NOTHING   0x00000000
 

Definition at line 154 of file spp_stream4.c.

Referenced by TcpAction(), TcpActionAsync(), and UpdateStateAsync().

#define ACTION_SET_SERVER_ISN   0x00000040
 

Definition at line 161 of file spp_stream4.c.

Referenced by TcpAction(), TcpActionAsync(), and UpdateState2().

#define CHK_SEQ   1
 

Definition at line 203 of file spp_stream4.c.

Referenced by UpdateState2().

#define CLOSE_WAIT   5
 

Definition at line 141 of file spp_stream4.c.

Referenced by UpdateState2().

#define CLOSED   0
 

Definition at line 136 of file spp_stream4.c.

Referenced by UpdateState2(), and UpdateStateAsync().

#define CLOSING   8
 

Definition at line 144 of file spp_stream4.c.

#define DEFAULT_STREAM_TRACKERS   256000
 

Definition at line 175 of file spp_stream4.c.

#define ESTABLISHED   4
 

Definition at line 140 of file spp_stream4.c.

Referenced by CreateNewSession(), parse_one_v1(), ReassembleStream4(), StoreStreamPkt(), UpdateState2(), and UpdateStateAsync().

#define FCOUNT   64
 

Definition at line 241 of file spp_stream4.c.

Referenced by CreateNewSession(), parse_one_v1(), and Stream4InitReassembler().

#define FIN_WAIT_1   7
 

Definition at line 143 of file spp_stream4.c.

Referenced by UpdateState2().

#define FIN_WAIT_2   9
 

Definition at line 145 of file spp_stream4.c.

Referenced by UpdateState2().

#define FLUSH_BEHAVIOR_DEFAULT   0
 

Definition at line 246 of file spp_stream4.c.

Referenced by ParseStream4Args(), and Stream4InitReassembler().

#define FLUSH_BEHAVIOR_LARGE   1
 

Definition at line 247 of file spp_stream4.c.

Referenced by Stream4InitReassembler().

#define FLUSH_BEHAVIOR_RANDOM   -1
 

Definition at line 245 of file spp_stream4.c.

Referenced by Stream4InitReassembler().

#define FROM_CLIENT   1
 

Definition at line 167 of file spp_stream4.c.

Referenced by GetDirection(), StoreStreamPkt(), TcpAction(), TcpActionAsync(), UpdateState2(), and UpdateStateAsync().

#define FROM_SERVER   0
 

Definition at line 166 of file spp_stream4.c.

Referenced by AlertFlushStream(), CheckRst(), GetDirection(), ReassembleStream4(), SetFinSent(), TcpAction(), TcpActionAsync(), UpdateState2(), and UpdateStateAsync().

#define INLINE   inline
 

Definition at line 82 of file spp_stream4.c.

#define LAST_ACK   6
 

Definition at line 142 of file spp_stream4.c.

Referenced by UpdateState2().

#define LISTEN   1
 

Definition at line 137 of file spp_stream4.c.

Referenced by CreateNewSession(), and UpdateState2().

#define MAX_STREAM_SIZE   (IP_MAXPACKET - IP_HEADER_LEN - TCP_HEADER_LEN - ETHERNET_HEADER_LEN)
 

Definition at line 193 of file spp_stream4.c.

Referenced by BuildPacket(), FlushStream(), ReassembleStream4(), TcpAction(), TraverseFunc(), and WithinSessionLimits().

#define MAX_TRACKER_AMOUNT   (MAX_STREAM_SIZE + 4000)
 

Definition at line 236 of file spp_stream4.c.

#define MAXSIZE_IP   65535
 

Definition at line 235 of file spp_stream4.c.

#define METHOD_FAVOR_NEW   0x01
 

Definition at line 186 of file spp_stream4.c.

Referenced by StoreStreamPkt(), and Stream4InitReassembler().

#define METHOD_FAVOR_OLD   0x02
 

Definition at line 187 of file spp_stream4.c.

Referenced by BuildPacket(), LogStream(), and Stream4InitReassembler().

#define NMAP_FINGERPRINT_2S   30
 

Definition at line 149 of file spp_stream4.c.

Referenced by CreateNewSession().

#define NMAP_FINGERPRINT_NULL   31
 

Definition at line 150 of file spp_stream4.c.

#define NMAP_FINGERPRINT_UPSF   32
 

Definition at line 151 of file spp_stream4.c.

#define NMAP_FINGERPRINT_ZERO_ACK   33
 

Definition at line 152 of file spp_stream4.c.

#define NO_CHK_SEQ   0
 

Definition at line 202 of file spp_stream4.c.

Referenced by UpdateState2().

#define NO_REVERSE   1
 

Definition at line 184 of file spp_stream4.c.

Referenced by AlertFlushStream(), FlushDeletedStream(), ReassembleStream4(), TcpAction(), and TcpActionAsync().

#define OPS_NORMAL   0
 

Definition at line 231 of file spp_stream4.c.

#define OPS_SELF_PRESERVATION   1
 

Definition at line 232 of file spp_stream4.c.

#define OPS_SUSPEND   2
 

Definition at line 233 of file spp_stream4.c.

#define PRUNE_QUANTA   30
 

Definition at line 169 of file spp_stream4.c.

Referenced by ParseStream4Args().

#define REVERSE   0
 

Definition at line 183 of file spp_stream4.c.

Referenced by BuildPacket(), TcpAction(), and TcpActionAsync().

#define S4I
 

Definition at line 205 of file spp_stream4.c.

#define SELF_PRES_PERIOD   90
 

Definition at line 226 of file spp_stream4.c.

#define SELF_PRES_THRESHOLD   50
 

Definition at line 225 of file spp_stream4.c.

#define SEQ_EQ a,
 )     ((int)((a) - (b)) == 0)
 

Definition at line 200 of file spp_stream4.c.

Referenced by CheckRst(), and TraverseFunc().

#define SEQ_GEQ a,
 )     ((int)((a) - (b)) >= 0)
 

Definition at line 199 of file spp_stream4.c.

Referenced by EvalStateQueue(), SegmentCleanTraverse(), and TraverseFunc().

#define SEQ_GT a,
 )     ((int)((a) - (b)) > 0)
 

Definition at line 198 of file spp_stream4.c.

Referenced by TraverseFunc().

#define SEQ_LEQ a,
 )     ((int)((a) - (b)) <= 0)
 

Definition at line 197 of file spp_stream4.c.

Referenced by TraverseFunc().

#define SEQ_LT a,
 )     ((int)((a) - (b)) < 0)
 

Definition at line 196 of file spp_stream4.c.

Referenced by CheckRst(), TcpAction(), and TraverseFunc().

#define SPARC_TWIDDLE   0
 

Definition at line 221 of file spp_stream4.c.

#define STATS_BINARY   3
 

Definition at line 179 of file spp_stream4.c.

Referenced by DeleteSession(), ParseStream4Args(), Stream4CleanExitFunction(), and Stream4RestartFunction().

#define STATS_HUMAN_READABLE   1
 

Definition at line 177 of file spp_stream4.c.

Referenced by DeleteSession(), and ParseStream4Args().

#define STATS_MACHINE_READABLE   2
 

Definition at line 178 of file spp_stream4.c.

Referenced by DeleteSession(), and ParseStream4Args().

#define STATS_MAGIC   0xDEAD029A
 

Definition at line 181 of file spp_stream4.c.

Referenced by OpenStatsFile().

#define STREAM4_CACHE_PERCENT   0.1
 

Definition at line 173 of file spp_stream4.c.

Referenced by ParseStream4Args().

#define STREAM4_CLEANUP   5
 

Definition at line 172 of file spp_stream4.c.

Referenced by ParseStream4Args().

#define STREAM4_FLUSH_BASE   512
 

Definition at line 242 of file spp_stream4.c.

Referenced by ParseStream4Args().

#define STREAM4_FLUSH_RANGE   1213
 

Definition at line 243 of file spp_stream4.c.

Referenced by ParseStream4Args().

#define STREAM4_MAX_SESSIONS   8192
 

Definition at line 171 of file spp_stream4.c.

Referenced by ParseStream4Args(), and Stream4Init().

#define STREAM4_MEMORY_CAP   8388608
 

Definition at line 170 of file spp_stream4.c.

Referenced by ParseStream4Args(), and Stream4Init().

#define STREAM4_TTL_LIMIT   5
 

Definition at line 174 of file spp_stream4.c.

Referenced by ParseStream4Args().

#define SUSPEND_PERIOD   30
 

Definition at line 229 of file spp_stream4.c.

#define SUSPEND_THRESHOLD   200
 

Definition at line 228 of file spp_stream4.c.

#define SYN_RCVD   2
 

Definition at line 138 of file spp_stream4.c.

Referenced by CreateNewSession(), UpdateState2(), and UpdateStateAsync().

#define SYN_SENT   3
 

Definition at line 139 of file spp_stream4.c.

Referenced by CreateNewSession(), UpdateState2(), and UpdateStateAsync().

#define TIME_WAIT   10
 

Definition at line 146 of file spp_stream4.c.

Referenced by UpdateState2().

#define UNESTABLISHED_MAX_PCOUNT   300
 

Definition at line 190 of file spp_stream4.c.


Typedef Documentation

typedef struct _BinStats BinStats
 

typedef struct _BuildData BuildData
 

typedef struct _OverlapData OverlapData
 

typedef struct _S4Emergency S4Emergency
 

typedef Session* SessionPtr
 

Definition at line 355 of file spp_stream4.c.

typedef struct _StatsLog StatsLog
 

typedef struct _StatsLogHeader StatsLogHeader
 

typedef struct _StreamKey STREAM_KEY
 


Function Documentation

void AddNewPort ubi_trRootPtr  ,
u_int16_t  ,
u_int8_t 
 

void AddNewTarget ubi_trRootPtr  ,
u_int32_t  ,
u_int16_t  ,
u_int8_t 
 

int AlertFlushStream Packet p  ) 
 

Flush the side of the TCP stream that just caused an alert.

This function is exported for the detection engine.

This routine takes a packet, logs out the stream packets ( so that we have original payloads around ), and then updates the stream tracking sequence numbers so that

Parameters:
p Packet to flush the stream reassembler on
Returns:
the number of packets that have been flushed from the stream reassembler

Definition at line 5624 of file spp_stream4.c.

References _Stream::base_seq, _Stream::bytes_tracked, _Session::client, _Stream::data, DEBUG_STREAM, DEBUG_WRAP, DeleteSession(), DeleteSpd(), _Packet::dsize, _Stream4Data::enforce_state, _Stream4Data::flush_on_alert, FlushStream(), FROM_SERVER, GetDirection(), _Stream::last_ack, NO_REVERSE, NotForStream4(), NULL, _Stream::overlap_pkts, _Packet::pkth, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, _Session::server, _Packet::ssnptr, _Packet::tcph, _TCPHdr::th_seq, and pcap_pkthdr::ts.

Referenced by Preprocess().

int BuildPacket Stream s,
u_int32_t  stream_size,
Packet p,
int  direction
 

Build a new stream packet from

Parameters:
s Stream storage variables
stream_size size of the newly assembled stream ( should be less than 2^16 - 41
p packet that caused us to flush
direction which are we flushing
Returns:
0 on success, -1 if we didn't get enough data to create the packet

Definition at line 5819 of file spp_stream4.c.

References _Stream::base_seq, _BuildData::buf, bzero, pcap_pkthdr::caplen, ClearDumpBuf(), _Session::client, _Stream::data, _Packet::data, DEBUG_STREAM, DEBUG_WRAP, _Packet::dp, _Packet::dsize, _Packet::eh, _EtherHdr::ether_dst, _EtherHdr::ether_src, ETHERNET_HEADER_LEN, _Stream4Data::flush_data_diff_size, _IPHdr::ip_dst, IP_HEADER_LEN, _IPHdr::ip_len, _IPHdr::ip_src, _Packet::iph, _Stream::last_ack, pcap_pkthdr::len, MAX_STREAM_SIZE, memcpy, METHOD_FAVOR_OLD, NULL, _Packet::packet_flags, pc, PKT_FROM_CLIENT, PKT_FROM_SERVER, PKT_REBUILT_STREAM, PKT_STREAM_EST, _Packet::pkth, _Stream::port, PrintIPPkt(), _Stream4Data::reassy_method, _PacketCount::rebuilt_tcp, REVERSE, _Packet::sp, _Packet::ssnptr, _Stream4Data::stop_seq, _Stream4Data::stop_traverse, _BuildData::stream, _Packet::streamptr, TCP_HEADER_LEN, _Packet::tcp_lastopt_bad, _Packet::tcp_option_count, _Packet::tcph, _TCPHdr::th_ack, _TCPHdr::th_dport, _TCPHdr::th_seq, _TCPHdr::th_sport, _TCPHdr::th_win, _BuildData::total_size, TraverseFunc(), pcap_pkthdr::ts, ubi_trTraverse, ubi_trTraverseReverse, and _Stream4Data::zero_flushed_packets.

Referenced by FlushStream(), and ReassembleStream4().

int CheckPorts u_int16_t  ,
u_int16_t 
 

Definition at line 6060 of file spp_stream4.c.

References _Stream4Data::assemble_ports, _Stream4Data::emergency_ports, OPS_NORMAL, OPS_SELF_PRESERVATION, and _S4Emergency::status.

int CheckRst Session ,
int  ,
u_int32_t  ,
Packet
 

Definition at line 4498 of file spp_stream4.c.

References _Stream::base_seq, _Stream::bytes_sent, _Stream::bytes_tracked, _Session::client, _Stream::data, DEBUG_STREAM, DEBUG_WRAP, _Stream4Data::evasion_alerts, FROM_SERVER, GENERATOR_SPP_STREAM4, _Stream::ip, _Stream::last_ack, _Stream::next_seq, SEQ_EQ, SEQ_LT, _StreamPacketData::seq_num, _Session::server, SnortEventqAdd(), _Stream4Data::stateful_inspection_flag, STREAM4_EVASIVE_RST, STREAM4_EVASIVE_RST_STR, ubi_sptFind(), and _Stream::win_size.

Referenced by UpdateState2().

Session * CreateNewSession Packet ,
u_int32_t  ,
u_int32_t 
 

Definition at line 3937 of file spp_stream4.c.

References _Stream::base_seq, _Session::client, _Stream::data, DataCompareFunc(), DEBUG_STREAM, DEBUG_WRAP, _Packet::dp, ESTABLISHED, FCOUNT, _Session::flush_point, flush_points, GENERATOR_SPP_STREAM4, GetNewSession(), _Stream::ip, _IPHdr::ip_dst, _IPHdr::ip_src, _IPHdr::ip_tos, _Packet::iph, _Stream::isn, _Stream::last_ack, _Session::last_session_time, LISTEN, NMAP_FINGERPRINT_2S, NULL, _Packet::packet_flags, pc, PKT_ECN, _Packet::pkth, _Stream::port, _Stream4Data::ps_alerts, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, RootPtr, SafeAlloc(), _Session::server, _Session::session_flags, SnortEventqAdd(), _Packet::sp, SSNFLAG_ECN_CLIENT_QUERY, SSNFLAG_NMAP, SSNFLAG_SEEN_CLIENT, SSNFLAG_SEEN_SERVER, _Session::start_time, _Stream::state, stream4_memory_usage, STREAM4_STEALTH_ACTIVITY, STREAM4_STEALTH_ACTIVITY_STR, STREAM4_STEALTH_FIN_SCAN, STREAM4_STEALTH_FIN_SCAN_STR, STREAM4_STEALTH_FULL_XMAS, STREAM4_STEALTH_FULL_XMAS_STR, STREAM4_STEALTH_NMAP_XMAS_SCAN, STREAM4_STEALTH_NMAP_XMAS_SCAN_STR, STREAM4_STEALTH_NULL_SCAN, STREAM4_STEALTH_NULL_SCAN_STR, STREAM4_STEALTH_SAPU, STREAM4_STEALTH_SAPU_STR, STREAM4_STEALTH_SYN_FIN_SCAN, STREAM4_STEALTH_SYN_FIN_SCAN_STR, STREAM4_STEALTH_VECNA_SCAN, STREAM4_STEALTH_VECNA_SCAN_STR, SYN_RCVD, SYN_SENT, _PacketCount::tcp_streams, _Packet::tcph, TH_ACK, TH_FIN, _TCPHdr::th_flags, TH_PUSH, TH_RES1, TH_RES2, TH_RST, TH_SYN, TH_URG, _TCPHdr::th_win, pcap_pkthdr::ts, ubi_sptInsert(), ubi_trDUPKEY, ubi_trFALSE, ubi_trInitTree, and _Stream::win_size.

Referenced by ReassembleStream4().

static int DataCompareFunc ubi_trItemPtr  ItemPtr,
ubi_trNodePtr  NodePtr
[static]
 

Definition at line 531 of file spp_stream4.c.

References _StreamPacketData::seq_num.

Referenced by CreateNewSession(), and parse_one_v1().

void DeleteSession Session ,
u_int32_t 
 

void DeleteSpd ubi_trRootPtr   ) 
 

Definition at line 4670 of file spp_stream4.c.

References KillSpd(), and ubi_trKillTree.

Referenced by AlertFlushStream(), DropSession(), and FlushStream().

void DirectLogTcpdump struct pcap_pkthdr ,
u_int8_t
 

void DisplayStream4Config void   ) 
 

Definition at line 1554 of file spp_stream4.c.

References _Stream4Data::asynchronous_link, _Stream4Data::cache_clean_percent, _Stream4Data::cache_clean_sessions, _Stream4Data::enforce_state, _Stream4Data::evasion_alerts, _Stream4Data::log_flushed_streams, LogMessage(), _Stream4Data::max_sessions, _Stream4Data::memcap, _Stream4Data::min_ttl, _Stream4Data::ms_inline_alerts, _Stream4Data::ps_alerts, _Stream4Data::server_inspect_limit, _Stream4Data::sp_period, _Stream4Data::sp_threshold, _Stream4Data::state_alerts, _Stream4Data::state_protection, _Stream4Data::stateful_inspection_flag, _Stream4Data::suspend_period, _Stream4Data::suspend_threshold, _Stream4Data::timeout, _Stream4Data::track_stats_flag, and _Stream4Data::ttl_limit.

Referenced by ParseStream4Args().

void DropSession Session  ) 
 

Definition at line 4627 of file spp_stream4.c.

References _Session::client, _Stream::data, DEBUG_STREAM, DEBUG_WRAP, DeleteSpd(), FlushDeletedStream(), NULL, _Session::preproc_data, _Session::preproc_free, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, _Session::server, stream4_memory_usage, and ubi_trRootPtr.

Referenced by DeleteSession().

int INLINE EvalStateQueue Stream sptr,
u_int8_t  flags,
u_int32_t  ack
 

Evaluate queued state transitions for completion criteria

Parameters:
sptr pointer to the stream to be evaluated
flags flags of the current packet
ack ack number of the current packet
Returns:
1 on successful state transition, 0 on no transition

Definition at line 3465 of file spp_stream4.c.

References DEBUG_STREAM_STATE, DEBUG_WRAP, _Stream::expected_flags, SEQ_GEQ, _Stream::state, _Stream::state_queue, _Stream::stq_chk_seq, and _Stream::trans_seq.

Referenced by UpdateState2().

void FlushDeletedStream Session ssn,
Stream s
 

Definition at line 4601 of file spp_stream4.c.

References _Stream::data, DEBUG_STREAM, DEBUG_WRAP, FlushStream(), NO_REVERSE, _StreamPacketData::pkt, _StreamPacketData::pkth, ubi_btRoot::root, RootPtr, ubi_trCount, and ubi_trLast.

Referenced by DropSession().

void FlushStream Stream ,
Packet ,
int 
 

Definition at line 5482 of file spp_stream4.c.

References _Session::alert_count, _Stream::base_seq, BuildPacket(), _Stream::bytes_tracked, bzero, _Packet::data, _Stream::data, DEBUG_STREAM, DEBUG_WRAP, DeleteSpd(), _Packet::dsize, _SFBASE::iStreamFlushes, _Stream::last_ack, LogStream(), MAX_STREAM_SIZE, _Stream::overlap_pkts, Preprocess(), SegmentCleanTraverse(), _SFPERF::sfBase, sfPerf, _Packet::ssnptr, ubi_trCount, and _Stream4Data::zero_flushed_packets.

Referenced by AlertFlushStream(), FlushDeletedStream(), TcpAction(), and TcpActionAsync().

int GetDirection Session ,
Packet
 

Definition at line 4676 of file spp_stream4.c.

References _Session::client, _Packet::dp, FROM_CLIENT, FROM_SERVER, _Stream::ip, _IPHdr::ip_dst, _IPHdr::ip_src, _Packet::iph, _Stream::port, _Session::server, _Session::session_flags, _Packet::sp, SSNFLAG_ESTABLISHED, _Packet::tcph, _TCPHdr::th_flags, TH_NORESERVED, and TH_SYN.

Referenced by AlertFlushStream(), ReassembleStream4(), StoreStreamPkt(), UpdateState2(), and UpdateStateAsync().

static u_int32_t GetTcpTimestamp Packet p,
u_int32_t ts
[static]
 

Definition at line 4791 of file spp_stream4.c.

References _Options::code, _Options::data, DEBUG_STREAM_STATE, DEBUG_WRAP, EXTRACT_32BITS, _Packet::tcp_option_count, _Packet::tcp_options, and TCPOPT_TIMESTAMP.

Referenced by StoreStreamPkt().

static void InitFakePkt Packet p  )  [static]
 

Definition at line 6879 of file spp_stream4.c.

References _Packet::data, _Packet::eh, _EtherHdr::ether_type, ETHERNET_HEADER_LEN, IP_HEADER_LEN, _IPHdr::ip_len, IP_MAXPACKET, _IPHdr::ip_proto, _IPHdr::ip_tos, _IPHdr::ip_ttl, _Packet::iph, _Packet::pkt, _Packet::pkth, SET_IP_HLEN, SET_IP_VER, SET_TCP_OFFSET, SPARC_TWIDDLE, TCP_HEADER_LEN, _Packet::tcph, TH_ACK, _TCPHdr::th_flags, and TH_PUSH.

Referenced by LoadStateTable().

void InitStream4Pkt  ) 
 

Definition at line 5773 of file spp_stream4.c.

References _Packet::data, _Packet::eh, _EtherHdr::ether_type, ETHERNET_HEADER_LEN, IP_HEADER_LEN, _IPHdr::ip_len, IP_MAXPACKET, _IPHdr::ip_proto, _IPHdr::ip_tos, _IPHdr::ip_ttl, _Packet::iph, _Packet::pkt, _Packet::pkth, SET_IP_HLEN, SET_IP_VER, SET_TCP_OFFSET, SPARC_TWIDDLE, TCP_HEADER_LEN, _Packet::tcph, TH_ACK, _TCPHdr::th_flags, and TH_PUSH.

Referenced by Stream4Init().

static INLINE int isBetween u_int32_t  low,
u_int32_t  high,
u_int32_t  cur
[static]
 

See if a sequence number is in range.

Parameters:
low base sequence number
high acknowledged sequence number
cur sequence number to check
Returns:
1 if we are between these sequence numbers, 0 otherwise

Definition at line 469 of file spp_stream4.c.

References DEBUG_STREAM, and DEBUG_WRAP.

Referenced by TraverseFunc().

static void KillSpd ubi_trNodePtr  NodePtr  )  [static]
 

Definition at line 558 of file spp_stream4.c.

References _StreamPacketData::pkt_size, _StreamPacketData::pktOrig, and stream4_memory_usage.

Referenced by DeleteSpd().

int LoadStateTable const u_int32_t  thetime,
const char *  path
 

Definition at line 7037 of file spp_stream4.c.

References DEBUG_STREAM, DEBUG_WRAP, errno, InitFakePkt(), LogMessage(), memset, NULL, parse_one_v1(), pc, and _PacketCount::tcp_streams.

Referenced by Stream4InitReassembler().

int LogStream Stream s  ) 
 

Log out the Stream if possible

only works with pcap currently

Todo:
make this work with a newer output subsystem
Parameters:
s stream to log the data from
Returns:
number of nodes in the data

Definition at line 5751 of file spp_stream4.c.

References _Stream::data, _progvars::log_bitmap, _Stream4Data::log_flushed_streams, LOG_TCPDUMP, LogTraverse(), METHOD_FAVOR_OLD, pv, _Stream4Data::reassy_method, ubi_trCount, ubi_trTraverse, and ubi_trTraverseReverse.

Referenced by FlushStream().

static void LogTraverse ubi_trNodePtr  NodePtr,
void *  foo
[static]
 

Definition at line 1413 of file spp_stream4.c.

References DirectLogTcpdump(), _StreamPacketData::pkt, and _StreamPacketData::pkth.

Referenced by LogStream().

static INLINE int NotForStream4 Packet p  )  [static]
 

See if we can get ignore this packet

The Emergency Status stuff is taken care of here.

Parameters:
p Packet
Returns:
1 if this packet isn't destined to be processeed, 0 otherwise

Definition at line 2616 of file spp_stream4.c.

References _progvars::assurance_mode, CSE_IP, CSE_TCP, _Packet::csum_flags, DEBUG_STREAM, DEBUG_WRAP, _S4Emergency::end_time, _S4Emergency::new_session_count, NULL, _S4Emergency::old_assurance_mode, _S4Emergency::old_reassemble_client, _S4Emergency::old_reassemble_server, _S4Emergency::old_reassembly_alerts, _S4Emergency::old_stateful_mode, OPS_NORMAL, OPS_SUSPEND, _Packet::packet_flags, PKT_REBUILT_STREAM, PKT_STREAM_UNEST_UNI, _Packet::pkth, PP_STREAM4, _Packet::preprocessors, pv, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, _Stream4Data::reassembly_alerts, _progvars::stateful, _S4Emergency::status, _Packet::tcph, and pcap_pkthdr::ts.

Referenced by AlertFlushStream(), and ReassembleStream4().

void OpenStatsFile  ) 
 

Definition at line 6083 of file spp_stream4.c.

References bzero, errno, FatalError(), _StatsLog::filename, _StatsLog::fp, _progvars::log_dir, _StatsLogHeader::magic, NULL, pv, snprintf, STATS_MAGIC, STD_BUF, _StatsLogHeader::timezone, _StatsLogHeader::version_major, and _StatsLogHeader::version_minor.

Referenced by ParseStream4Args().

static int OverlapCompareFunc ubi_trItemPtr  ItemPtr,
void *  data
[static]
 

Definition at line 545 of file spp_stream4.c.

References _OverlapData::seq_hi, _OverlapData::seq_low, and _StreamPacketData::seq_num.

Referenced by StoreStreamPkt().

static char parse_one_v1 u_int32_t  thetime,
Packet fakep,
struct parse_v1_file parse
[static]
 

Definition at line 6917 of file spp_stream4.c.

References _Stream::base_seq, _Stream::bytes_sent, parse_v1_file::c_base_seq, parse_v1_file::c_bytes_sent, parse_v1_file::c_ip, parse_v1_file::c_isn, parse_v1_file::c_last_ack, parse_v1_file::c_pkts_sent, parse_v1_file::c_port, parse_v1_file::c_win_size, _Session::client, _Stream::data, DataCompareFunc(), DEBUG_STREAM, DEBUG_WRAP, ESTABLISHED, FCOUNT, _Session::flush_point, flush_points, GetNewSession(), _Stream::ip, _IPHdr::ip_dst, _IPHdr::ip_src, _Packet::iph, _Stream::isn, _Stream::last_ack, _Session::last_session_time, parse_v1_file::last_session_time, NULL, _Packet::pkth, _Stream::pkts_sent, _Stream::port, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, parse_v1_file::s_base_seq, parse_v1_file::s_bytes_sent, parse_v1_file::s_ip, parse_v1_file::s_isn, parse_v1_file::s_last_ack, parse_v1_file::s_pkts_sent, parse_v1_file::s_port, parse_v1_file::s_win_size, _Session::server, _Session::session_flags, parse_v1_file::session_flags, SSNFLAG_ESTABLISHED, SSNFLAG_MIDSTREAM, SSNFLAG_SEEN_CLIENT, SSNFLAG_SEEN_SERVER, _Session::start_time, parse_v1_file::start_time, _Stream::state, parse_v1_file::statestr, _Packet::tcph, _TCPHdr::th_dport, _TCPHdr::th_sport, _Stream4Data::timeout, pcap_pkthdr::ts, ubi_trDUPKEY, ubi_trInitTree, and _Stream::win_size.

Referenced by LoadStateTable().

void ParseStream4Args char *   ) 
 

Definition at line 1624 of file spp_stream4.c.

References _Stream4Data::asynchronous_link, _Stream4Data::cache_clean_percent, _Stream4Data::cache_clean_sessions, DEBUG_INIT, DEBUG_WRAP, DisplayStream4Config(), _Stream4Data::enforce_state, ErrorMessage(), _Stream4Data::evasion_alerts, FatalError(), file_line, file_name, _StatsLog::filename, _Stream4Data::flush_base, _Stream4Data::flush_behavior, FLUSH_BEHAVIOR_DEFAULT, _Stream4Data::flush_data_diff_size, _Stream4Data::flush_on_alert, _Stream4Data::flush_range, _Stream4Data::flush_seed, index, _Stream4Data::log_flushed_streams, LogMessage(), _Stream4Data::max_sessions, _Stream4Data::memcap, memset, _Stream4Data::min_ttl, _Stream4Data::ms_inline_alerts, mSplit(), mSplitFree(), NULL, OpenStatsFile(), _Stream4Data::overlap_limit, _Stream4Data::path_mtu, PRUNE_QUANTA, _Stream4Data::ps_alerts, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, SELF_PRES_PERIOD, SELF_PRES_THRESHOLD, _Stream4Data::server_inspect_limit, _Stream4Data::sp_period, _Stream4Data::sp_threshold, _Stream4Data::state_alerts, _Stream4Data::state_protection, _Stream4Data::stateful_inspection_flag, STATS_BINARY, STATS_HUMAN_READABLE, STATS_MACHINE_READABLE, strcasecmp, STREAM4_CACHE_PERCENT, STREAM4_CLEANUP, STREAM4_FLUSH_BASE, STREAM4_FLUSH_RANGE, STREAM4_MAX_SESSIONS, STREAM4_MEMORY_CAP, STREAM4_TTL_LIMIT, strlcpy, strncasecmp, SUSPEND_PERIOD, _Stream4Data::suspend_period, SUSPEND_THRESHOLD, _Stream4Data::suspend_threshold, _Stream4Data::timeout, _Stream4Data::track_stats_flag, _Stream4Data::ttl_limit, and _Stream4Data::zero_flushed_packets.

Referenced by Stream4Init().

void PortscanDeclare Packet  ) 
 

void PortscanWatch Session ,
u_int32_t 
 

void PreprocCleanExitFunction int   ) 
 

Referenced by TemplateInit().

static void PreprocFunction Packet  ) 
 

Definition at line 171 of file spp_template.c.

Referenced by TemplateInit().

void PreprocRestartFunction int   ) 
 

Referenced by TemplateInit().

void PrintSessionCache  ) 
 

Definition at line 496 of file snort_stream4_session.c.

References DEBUG_STREAM, DEBUG_WRAP, RootPtr, sfxhash_count(), stream4_memory_usage, and ubi_trCount.

Referenced by ReassembleStream4().

static INLINE void PruneCheck Packet p  )  [static]
 

Prune The state machine if we need to

Also updates all variables related to pruning that only have to happen at initialization

For want of packet time at plugin initialization. (It only happens once.) It wood be nice to get the first packet and do a little extra before getting into the main snort processing loop. -- cpw

Parameters:
p Packet ptr

Definition at line 2793 of file spp_stream4.c.

References DEBUG_STREAM, DEBUG_WRAP, GetSessionCount(), _SFBASE::iStreamTimeouts, _Stream4Data::last_prune_time, NULL, _Packet::pkth, PruneSessionCache(), safe_alloc_faults, _SFPERF::sfBase, sfPerf, stream4_memory_usage, _Stream4Data::timeout, and pcap_pkthdr::ts.

Referenced by ReassembleStream4().

int PruneSessionCache u_int32_t  ,
int  ,
Session
 

Definition at line 508 of file snort_stream4_session.c.

References _Stream4Data::cache_clean_percent, _Stream4Data::cache_clean_sessions, CleanHashTable(), DEBUG_STREAM, DEBUG_WRAP, DeleteSession(), _Session::last_session_time, _Stream4Data::memcap, NULL, RootPtr, Rotate(), stream4_memory_usage, _Stream4Data::timeout, ubi_btLast(), ubi_btLeafNode(), ubi_btPrev(), and ubi_trCount.

Referenced by PruneCheck(), and SafeAlloc().

void INLINE QueueState u_int8_t  transition,
Stream sptr,
u_int8_t  expected_flags,
u_int32_t  seq_num,
u_int8_t  chk_seq
 

Queues a state transition for UpdateState2

Parameters:
transition the state to transition to
sptr pointer to the stream to queue the transition for
expected_flags flag we need to see to accept the transition
seq_num sequence number of the packet initiating the transition
chk_seq flag to indicate if the seq number actually needs to be checked
Returns:
void function

Definition at line 3442 of file spp_stream4.c.

References DEBUG_STREAM_STATE, DEBUG_WRAP, _Stream::expected_flags, _Stream::state_queue, _Stream::stq_chk_seq, and _Stream::trans_seq.

Referenced by UpdateState2().

void ReassembleStream4 Packet ,
void * 
 

Definition at line 2833 of file spp_stream4.c.

References ACTION_FLUSH_CLIENT_STREAM, ACTION_FLUSH_SERVER_STREAM, AddStreamSession(), _progvars::assurance_mode, ASSURE_ALL, _Stream4Data::asynchronous_link, _Stream::base_seq, BuildPacket(), _Stream::bytes_inspected, _Stream::bytes_sent, _Packet::bytes_to_inspect, _Stream::bytes_tracked, CheckPorts(), _Session::client, CreateNewSession(), CreateTCPFlagString(), _Packet::data, _Stream::data, DEBUG_STREAM, DEBUG_STREAM_STATE, DEBUG_WRAP, DisableDetect(), do_detect, _Packet::dp, _Packet::dsize, DumpStateTable(), _S4Emergency::end_time, _Stream4Data::enforce_state, ESTABLISHED, _Stream4Data::evasion_alerts, FROM_SERVER, GENERATOR_SPP_STREAM4, GetDirection(), GetSession(), InlineDrop(), InlineMode(), _IPHdr::ip_dst, _IPHdr::ip_src, _Packet::iph, _Stream::last_ack, _Session::last_session_time, MAX_STREAM_SIZE, _S4Emergency::new_session_count, NO_REVERSE, NotForStream4(), NULL, _S4Emergency::old_assurance_mode, _S4Emergency::old_reassemble_client, _S4Emergency::old_reassemble_server, _S4Emergency::old_reassembly_alerts, _S4Emergency::old_stateful_mode, opdsize, OPS_NORMAL, OPS_SELF_PRESERVATION, OPS_SUSPEND, _Stream4Data::overlap_limit, _Stream::overlap_pkts, _Packet::packet_flags, pc, PKT_FROM_CLIENT, PKT_FROM_SERVER, PKT_STREAM_EST, PKT_STREAM_UNEST_BI, PKT_STREAM_UNEST_UNI, _Packet::pkth, _Stream::pkts_sent, _Packet::preprocessors, PrintSessionCache(), PruneCheck(), pv, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, _Stream4Data::reassembly_alerts, _Session::server, _Stream4Data::server_inspect_limit, _Session::session_flags, _SFPERF::sfBase, sfPerf, SnortEventqAdd(), _Packet::sp, _Stream4Data::sp_period, _Stream4Data::sp_threshold, SSNFLAG_ESTABLISHED, SSNFLAG_MIDSTREAM, SSNFLAG_SEEN_CLIENT, SSNFLAG_SEEN_SERVER, _Packet::ssnptr, _Stream::state, _Stream4Data::state_protection, _progvars::stateful, _Stream4Data::stateful_inspection_flag, _S4Emergency::status, StoreStreamPkt(), STREAM4_EMERGENCY, STREAM4_EMERGENCY_STR, STREAM4_OVERLAP_LIMIT, STREAM4_OVERLAP_LIMIT_STR, STREAM4_SUSPEND, STREAM4_SUSPEND_STR, _Packet::streamptr, StreamSegmentSub(), _Stream4Data::suspend_period, _Stream4Data::suspend_threshold, _PacketCount::tcp_stream_pkts, TcpAction(), TcpActionAsync(), _Packet::tcph, TH_ACK, _TCPHdr::th_ack, _TCPHdr::th_dport, TH_FIN, _TCPHdr::th_flags, TH_NORESERVED, TH_PUSH, TH_RST, _TCPHdr::th_seq, _TCPHdr::th_sport, TH_SYN, _TCPHdr::th_win, pcap_pkthdr::ts, ubi_trCount, UpdateState2(), UpdateStateAsync(), and _Stream::win_size.

Referenced by Stream4Init().

static int RetransTooFast struct timeval *  old,
struct timeval *  cur
[static]
 

Check to if retransmissions are occuring too quickly

Parameters:
old previous timeval
cur current timeval
Returns:
1 if the Retransmission is too quick, 0 if it's ok

Definition at line 516 of file spp_stream4.c.

References TIMERSUB.

Referenced by StoreStreamPkt().

void * SafeAlloc unsigned  long,
int  ,
Session
 

Definition at line 1422 of file spp_stream4.c.

References FatalError(), _SFBASE::iStreamFaults, _Stream4Data::memcap, NULL, pc, PruneSessionCache(), _SFPERF::sfBase, sfPerf, _PacketCount::str_mem_faults, and stream4_memory_usage.

Referenced by CreateNewSession(), StoreStreamPkt(), and Stream4Init().

void SegmentCleanTraverse Stream s  ) 
 

Definition at line 1368 of file spp_stream4.c.

References _StreamPacketData::chuck, _Stream::data, DEBUG_STREAM, _Stream::last_ack, NULL, _StreamPacketData::payload_size, _StreamPacketData::pkt_size, _StreamPacketData::pktOrig, SEG_FULL, SEQ_GEQ, _StreamPacketData::seq_num, stream4_memory_usage, StreamSegmentSub(), ubi_btFirst(), ubi_btNext(), and ubi_sptRemove().

Referenced by FlushStream().

static INLINE int SetFinSent Packet p,
Session ssn,
int  direction
[static]
 

Set that this side of the session has sent a fin.

This overloads the next_seq variable to also be used to tell how far forward we can acknowledge data.

Parameters:
p packet to grab the session from
s stream to set the next_seq on
Returns:
0 if everything went ok

Definition at line 2584 of file spp_stream4.c.

References _Session::client, DEBUG_STREAM, DEBUG_WRAP, FROM_SERVER, _Stream::next_seq, _Session::server, _Session::session_flags, SSNFLAG_CLIENT_FIN, SSNFLAG_SERVER_FIN, _Packet::tcph, and _TCPHdr::th_seq.

Referenced by UpdateState2().

void SetupStream4  ) 
 

Definition at line 1471 of file spp_stream4.c.

References DEBUG_STREAM, DEBUG_WRAP, RegisterPreprocessor(), Stream4Init(), and Stream4InitReassembler().

Referenced by InitPreprocessors().

void StoreStreamPkt Session ,
Packet ,
u_int32_t 
 

Definition at line 4834 of file spp_stream4.c.

References pcap_pkthdr::caplen, _StreamPacketData::cksum, _Stream::data, _Packet::data, DEBUG_STREAM, DEBUG_WRAP, _Packet::dsize, ESTABLISHED, _Stream4Data::evasion_alerts, FROM_CLIENT, GENERATOR_SPP_STREAM4, GetDirection(), GetTcpTimestamp(), InlineDrop(), _IPHdr::ip_ttl, _Packet::iph, _Stream::last_ack, LogMessage(), memcpy, METHOD_FAVOR_NEW, NULL, _Stream::overlap_pkts, OverlapCompareFunc(), _Packet::packet_flags, _StreamPacketData::payload, _StreamPacketData::payload_size, _Packet::pkt, _StreamPacketData::pkt, _StreamPacketData::pkt_size, PKT_STREAM_INSERT, _StreamPacketData::pkth, _Packet::pkth, _StreamPacketData::pktOrig, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, _Stream4Data::reassy_method, RetransTooFast(), SafeAlloc(), _OverlapData::seq_hi, _OverlapData::seq_low, _StreamPacketData::seq_num, SnortEventqAdd(), SPARC_TWIDDLE, SSNFLAG_ESTABLISHED, _Stream::state, _Stream4Data::state_alerts, STREAM4_EVASIVE_RETRANS, STREAM4_EVASIVE_RETRANS_DATA, STREAM4_EVASIVE_RETRANS_DATA_STR, STREAM4_EVASIVE_RETRANS_DATASPLIT, STREAM4_EVASIVE_RETRANS_DATASPLIT_STR, STREAM4_EVASIVE_RETRANS_STR, STREAM4_FORWARD_OVERLAP, STREAM4_FORWARD_OVERLAP_STR, stream4_memory_usage, STREAM4_TCP_NO_ACK, STREAM4_TCP_NO_ACK_STR, STREAM4_TTL_EVASION, STREAM4_TTL_EVASION_STR, STREAM4_WINDOW_VIOLATION, STREAM4_WINDOW_VIOLATION_STR, STREAM4_ZERO_TIMESTAMP, STREAM4_ZERO_TIMESTAMP_STR, StreamSegmentSub(), _Packet::tcph, TH_ACK, _TCPHdr::th_flags, _TCPHdr::th_sum, TH_SYN, _SnortPktHeader::ts, pcap_pkthdr::ts, _Stream4Data::ttl_limit, ubi_sptFind(), ubi_sptInsert(), ubi_sptRemove(), ubi_trCheck, ubi_trFALSE, _Stream::win_size, and WithinSessionLimits().

Referenced by ReassembleStream4().

void Stream4CleanExitFunction int  ,
void * 
 

Definition at line 4759 of file spp_stream4.c.

References _StatsLog::fp, NULL, session_log, STATS_BINARY, and _Stream4Data::track_stats_flag.

Referenced by Stream4Init().

void Stream4Init u_char *   ) 
 

Definition at line 1492 of file spp_stream4.c.

References AddFuncToCleanExitList(), AddFuncToPreprocList(), AddFuncToRestartList(), AddFuncToShutdownList(), _runtime_config::capabilities, DEBUG_STREAM, DEBUG_WRAP, _S4Emergency::end_time, errno, FatalError(), InitSessionCache(), InitStream4Pkt(), _Stream4Data::last_prune_time, _progvars::log_dir, logfile, _Stream4Data::max_sessions, _Stream4Data::memcap, _S4Emergency::new_session_count, NULL, OPS_NORMAL, ParseStream4Args(), pv, ReassembleStream4(), RootPtr, SafeAlloc(), SELF_PRES_PERIOD, SELF_PRES_THRESHOLD, session_log, snort_runtime, snprintf, _Stream4Data::sp_period, _Stream4Data::sp_threshold, _Stream4Data::state_protection, _progvars::stateful, _Capabilities::stateful_inspection, _S4Emergency::status, STD_BUF, _Stream4Data::stream4_active, STREAM4_MAX_SESSIONS, STREAM4_MEMORY_CAP, Stream4CleanExitFunction(), Stream4RestartFunction(), Stream4ShutdownFunction(), SUSPEND_PERIOD, _Stream4Data::suspend_period, SUSPEND_THRESHOLD, _Stream4Data::suspend_threshold, _Stream4Data::track_stats_flag, and ubi_trInitTree.

Referenced by SetupStream4().

void Stream4InitReassembler u_char *   ) 
 

Definition at line 2060 of file spp_stream4.c.

References _Stream4Data::assemble_ports, DEBUG_STREAM, DEBUG_WRAP, _Stream4Data::emergency_ports, FatalError(), FCOUNT, file_line, file_name, _Stream4Data::flush_base, _Stream4Data::flush_behavior, FLUSH_BEHAVIOR_DEFAULT, FLUSH_BEHAVIOR_LARGE, FLUSH_BEHAVIOR_RANDOM, _Stream4Data::flush_data_diff_size, _Stream4Data::flush_on_alert, flush_points, _Stream4Data::flush_range, _Stream4Data::flush_seed, gettimeofday(), index, LoadStateTable(), LogMessage(), memset, METHOD_FAVOR_NEW, METHOD_FAVOR_OLD, mSplit(), mSplitFree(), new_flush_points, NULL, old_flush_points, _Stream4Data::overlap_limit, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, _Stream4Data::reassembly_alerts, _Stream4Data::reassy_method, sfsnprintfappend(), snprintf, STD_BUF, strcasecmp, _Stream4Data::stream4_active, strncasecmp, and _Stream4Data::zero_flushed_packets.

Referenced by SetupStream4().

void Stream4RestartFunction int  ,
void * 
 

Definition at line 4772 of file spp_stream4.c.

References DumpStateTable(), _StatsLog::fp, NULL, session_log, STATS_BINARY, and _Stream4Data::track_stats_flag.

Referenced by Stream4Init().

void Stream4ShutdownFunction int  ,
void * 
 

Definition at line 4748 of file spp_stream4.c.

References DumpStateTable(), and PurgeSessionCache().

Referenced by Stream4Init().

static INLINE void StreamSegmentAdd Stream stream,
u_int16_t  add
[static]
 

Add to the byte counters for the stream session

Parameters:
stream Stream to adjust the byte counters on
add amount to add to the byte_counters

Definition at line 2716 of file spp_stream4.c.

References _Stream::bytes_sent, _Stream::bytes_tracked, DEBUG_STREAM, DEBUG_WRAP, _Stream::pkts_sent, and stream4_memory_usage.

Referenced by UpdateState2(), and UpdateStateAsync().

static INLINE void StreamSegmentSub Stream stream,
u_int16_t  sub
[static]
 

Subtract from the byte counters for the stream session

Parameters:
stream Stream to adjust the byte counters on
sub amount to subtract from the byte_counters

Definition at line 2688 of file spp_stream4.c.

References _Stream::bytes_tracked, DEBUG_STREAM, and stream4_memory_usage.

Referenced by ReassembleStream4(), SegmentCleanTraverse(), StoreStreamPkt(), and WithinSessionLimits().

static void TcpAction Session ssn,
Packet p,
int  action,
int  direction,
u_int32_t  pkt_seq,
u_int32_t  pkt_ack
[static]
 

Definition at line 6145 of file spp_stream4.c.

References ACTION_ACK_CLIENT_DATA, ACTION_ACK_SERVER_DATA, ACTION_ALERT_NMAP_FINGERPRINT, ACTION_COMPLETE_TWH, ACTION_DATA_ON_SYN, ACTION_DROP_SESSION, ACTION_FLUSH_CLIENT_STREAM, ACTION_FLUSH_SERVER_STREAM, ACTION_INC_PORT, ACTION_NOTHING, ACTION_SET_SERVER_ISN, _Stream::base_seq, _Stream::bytes_tracked, _Session::client, _Stream::data, DEBUG_STREAM, DEBUG_WRAP, DeleteSession(), _Packet::dp, _Stream4Data::evasion_alerts, _Session::flush_point, FlushStream(), FROM_CLIENT, FROM_SERVER, GENERATOR_SPP_STREAM4, _IPHdr::ip_dst, _IPHdr::ip_src, _Packet::iph, _Stream::isn, _Stream::last_ack, MAX_STREAM_SIZE, _Stream::next_seq, NO_REVERSE, NULL, _Packet::packet_flags, PKT_STREAM_EST, PKT_STREAM_TWH, _Packet::pkth, _Stream::port, _Stream4Data::ps_alerts, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, REVERSE, SEQ_LT, _Session::server, _Session::session_flags, SnortEventqAdd(), _Packet::sp, SSNFLAG_CLIENT_FIN, SSNFLAG_ESTABLISHED, SSNFLAG_MIDSTREAM, _Packet::ssnptr, STREAM4_DATA_ON_SYN, STREAM4_DATA_ON_SYN_STR, STREAM4_STEALTH_NMAP_FINGERPRINT, STREAM4_STEALTH_NMAP_FINGERPRINT_STR, _Packet::tcph, _TCPHdr::th_flags, TH_RST, TH_SYN, _TCPHdr::th_win, pcap_pkthdr::ts, ubi_trCount, and _Stream::win_size.

Referenced by ReassembleStream4().

static void TcpActionAsync Session ssn,
Packet p,
int  action,
int  direction,
u_int32_t  pkt_seq,
u_int32_t  pkt_ack
[static]
 

Definition at line 6579 of file spp_stream4.c.

References ACTION_ACK_CLIENT_DATA, ACTION_ACK_SERVER_DATA, ACTION_ALERT_NMAP_FINGERPRINT, ACTION_COMPLETE_TWH, ACTION_DATA_ON_SYN, ACTION_DROP_SESSION, ACTION_FLUSH_CLIENT_STREAM, ACTION_FLUSH_SERVER_STREAM, ACTION_INC_PORT, ACTION_NOTHING, ACTION_SET_SERVER_ISN, _Stream::base_seq, _Session::client, _Stream::data, DEBUG_STREAM, DEBUG_WRAP, DeleteSession(), _Packet::dp, _Stream4Data::evasion_alerts, _Session::flush_point, FlushStream(), FROM_CLIENT, FROM_SERVER, GENERATOR_SPP_STREAM4, _IPHdr::ip_dst, _IPHdr::ip_src, _Packet::iph, _Stream::isn, _Stream::last_ack, _Stream::next_seq, NO_REVERSE, NULL, _Packet::packet_flags, PKT_STREAM_TWH, _Packet::pkth, _Stream::port, _Stream4Data::ps_alerts, _Stream4Data::reassemble_client, _Stream4Data::reassemble_server, REVERSE, _Session::server, _Session::session_flags, SnortEventqAdd(), _Packet::sp, SSNFLAG_CLIENT_FIN, _Packet::ssnptr, STREAM4_DATA_ON_SYN, STREAM4_DATA_ON_SYN_STR, STREAM4_STEALTH_NMAP_FINGERPRINT, STREAM4_STEALTH_NMAP_FINGERPRINT_STR, _Packet::tcph, _TCPHdr::th_flags, TH_RST, TH_SYN, _TCPHdr::th_win, pcap_pkthdr::ts, ubi_trCount, and _Stream::win_size.

Referenced by ReassembleStream4().

static void TraverseFunc ubi_trNodePtr  NodePtr,
void *  build_data
[static]
 

Definition at line 572 of file spp_stream4.c.

References _Stream::base_seq, _BuildData::buf, _StreamPacketData::chuck, _Packet::data, DEBUG_STREAM, DEBUG_WRAP, isBetween(), _Stream::last_ack, MAX_STREAM_SIZE, _Stream::next_seq, _StreamPacketData::payload, _StreamPacketData::payload_size, pc, _PacketCount::rebuilt_segs, SafeMemcpy(), SEG_FULL, SEG_PARTIAL, SEQ_EQ, SEQ_GEQ, SEQ_GT, SEQ_LEQ, SEQ_LT, _StreamPacketData::seq_num, _Stream4Data::stop_seq, _Stream4Data::stop_traverse, _BuildData::stream, and _BuildData::total_size.

Referenced by BuildPacket().

int UpdateState Session ,
Packet ,
u_int32_t 
 

int UpdateState2 Session ,
Packet ,
u_int32_t 
 

Definition at line 3515 of file spp_stream4.c.

References ACTION_ACK_CLIENT_DATA, ACTION_ACK_SERVER_DATA, ACTION_COMPLETE_TWH, ACTION_DATA_ON_SYN, ACTION_DROP_SESSION, ACTION_FLUSH_CLIENT_STREAM, ACTION_FLUSH_SERVER_STREAM, ACTION_SET_SERVER_ISN, CheckRst(), CHK_SEQ, _Session::client, CLOSE_WAIT, CLOSED, DEBUG_STREAM, DEBUG_STREAM_STATE, DEBUG_WRAP, _Packet::dsize, ESTABLISHED, EvalStateQueue(), FIN_WAIT_1, FIN_WAIT_2, FROM_CLIENT, FROM_SERVER, GetDirection(), LAST_ACK, LISTEN, NO_CHK_SEQ, NULL, QueueState(), _Session::server, _Session::session_flags, SetFinSent(), SSNFLAG_ECN_CLIENT_QUERY, SSNFLAG_ECN_SERVER_REPLY, SSNFLAG_SEEN_CLIENT, SSNFLAG_SEEN_SERVER, _Stream::state, StreamSegmentAdd(), SYN_RCVD, SYN_SENT, _Packet::tcph, TH_ACK, _TCPHdr::th_ack, TH_FIN, _TCPHdr::th_flags, TH_RES2, TH_RST, TH_SYN, _TCPHdr::th_win, TIME_WAIT, and _Stream::win_size.

Referenced by ReassembleStream4().

int UpdateStateAsync Session ,
Packet ,
u_int32_t 
 

Definition at line 3804 of file spp_stream4.c.

References ACTION_COMPLETE_TWH, ACTION_DROP_SESSION, ACTION_FLUSH_CLIENT_STREAM, ACTION_FLUSH_SERVER_STREAM, ACTION_NOTHING, _Session::client, CLOSED, DEBUG_STREAM, DEBUG_WRAP, _Packet::dsize, ESTABLISHED, FROM_CLIENT, FROM_SERVER, GetDirection(), _Session::server, _Session::session_flags, SSNFLAG_ESTABLISHED, SSNFLAG_SEEN_CLIENT, SSNFLAG_SEEN_SERVER, _Stream::state, StreamSegmentAdd(), SYN_RCVD, SYN_SENT, _Packet::tcph, TH_ACK, TH_FIN, _TCPHdr::th_flags, TH_NORESERVED, TH_RST, and TH_SYN.

Referenced by ReassembleStream4().

static INLINE int WithinSessionLimits Packet p,
Stream stream
[static]
 

Make sure that we do not log

Parameters:
p Packet to evaluate
stream Stream to compare against
Returns:
1 if we are within established limits, 0 otherwise.

Definition at line 2751 of file spp_stream4.c.

References _Stream::bytes_tracked, _Packet::dsize, MAX_STREAM_SIZE, SSNFLAG_MIDSTREAM, _Packet::ssnptr, and StreamSegmentSub().

Referenced by StoreStreamPkt().

void WriteSsnStats BinStats  ) 
 

Definition at line 6138 of file spp_stream4.c.

References _StatsLog::fp.

Referenced by DeleteSession().


Variable Documentation

int do_detect
 

Definition at line 98 of file detect.c.

Referenced by DisableDetect(), Frag3Defrag(), Preprocess(), ReassembleStream4(), and SnortHttpInspect().

int* file_line
 

Definition at line 88 of file parser.c.

char* file_name
 

external globals from rules.c

Definition at line 87 of file parser.c.

u_int32_t flush_points[FCOUNT]
 

Definition at line 385 of file spp_stream4.c.

Referenced by CreateNewSession(), parse_one_v1(), and Stream4InitReassembler().

u_int32_t new_flush_points[FCOUNT] [static]
 

Initial value:

 { 1280, 2176, 1895, 1303, 2402, 2211, 1340, 1298,
                                              2500, 2320, 1413, 1313, 1444, 1776, 2015, 1305,
                                              2130, 1190, 1377, 1492, 1380, 2100, 1373, 1029,
                                              750, 444, 874, 551, 401, 390, 1801, 1898,
                                              2260, 2601, 642, 485, 619, 929, 794, 340,
                                              445, 1911, 497, 883, 399, 2201, 2431, 2145,
                                              433, 735, 543, 658, 1174, 2042, 1200, 1800,
                                              2015, 1142, 1530, 487, 673, 899, 743, 2101 }

Definition at line 259 of file spp_stream4.c.

Referenced by Stream4InitReassembler().

u_int32_t old_flush_points[FCOUNT] [static]
 

Initial value:

 { 128, 217, 189, 130, 240, 221, 134, 129,
                                               250, 232, 141, 131, 144, 177, 201, 130,
                                               230, 190, 177, 142, 130, 200, 173, 129,
                                               250, 244, 174, 151, 201, 190, 180, 198,
                                               220, 201, 142, 185, 219, 129, 194, 140,
                                               145, 191, 197, 183, 199, 220, 231, 245,
                                               233, 135, 143, 158, 174, 194, 200, 180,
                                               201, 142, 153, 187, 173, 199, 143, 201 }

Definition at line 250 of file spp_stream4.c.

Referenced by Stream4InitReassembler().

int opdsize
 

Definition at line 76 of file inline.h.

Referenced by ReassembleStream4().

u_int32_t ps_memory_usage
 

Definition at line 379 of file spp_stream4.c.

S4Emergency s4_emergency
 

Definition at line 382 of file spp_stream4.c.

Stream4Data s4data
 

Definition at line 377 of file spp_stream4.c.

u_int32_t safe_alloc_faults
 

Definition at line 366 of file spp_stream4.c.

Referenced by PruneCheck().

FILE* session_log
 

Definition at line 376 of file spp_stream4.c.

Referenced by DeleteSession(), Stream4CleanExitFunction(), Stream4Init(), and Stream4RestartFunction().

StatsLog* stats_log
 

Definition at line 357 of file spp_stream4.c.

u_int32_t stream4_memory_usage
 

Definition at line 378 of file spp_stream4.c.

Referenced by CleanHashTable(), CreateNewSession(), DropSession(), KillSpd(), PrintSessionCache(), PruneCheck(), PruneSessionCache(), SafeAlloc(), SegmentCleanTraverse(), StoreStreamPkt(), StreamSegmentAdd(), and StreamSegmentSub().

Packet* stream_pkt
 

Definition at line 369 of file spp_stream4.c.


Generated on Sun May 14 14:51:26 2006 by  doxygen 1.4.2