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_reassemblers.cc author davis mcpherson <davmcphe@@cisco.com>
00020 // Created on: Oct 9, 2015
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include "config.h"
00024 #endif
00025
00026 #include "tcp_reassemblers.h"
00027
00028 class TcpReassemblerFirst : public TcpReassembler
00029 {
00030 public:
00031 TcpReassemblerFirst(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00032 TcpReassembler(session, tracker, StreamPolicy::OS_FIRST, server)
00033 { }
00034
00035 private:
00036 int insert_left_overlap() override
00037 {
00038 return left_overlap_keep_first( );
00039 }
00040
00041 void insert_right_overlap() override
00042 {
00043 right_overlap_truncate_new( );
00044 }
00045
00046 int insert_full_overlap() override
00047 {
00048 return full_right_overlap_os5( );
00049 }
00050 };
00051
00052 class TcpReassemblerLast : public TcpReassembler
00053 {
00054 public:
00055 TcpReassemblerLast(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00056 TcpReassembler(session, tracker, StreamPolicy::OS_LAST, server)
00057 { }
00058
00059 private:
00060 int insert_left_overlap() override
00061 {
00062 return left_overlap_keep_last( );
00063 }
00064
00065 void insert_right_overlap() override
00066 {
00067 right_overlap_truncate_existing( );
00068 }
00069
00070 int insert_full_overlap() override
00071 {
00072 return full_right_overlap_os4( );
00073 }
00074 };
00075
00076 class TcpReassemblerLinux : public TcpReassembler
00077 {
00078 public:
00079 TcpReassemblerLinux(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00080 TcpReassembler(session, tracker, StreamPolicy::OS_LINUX, server)
00081 { }
00082
00083 private:
00084 int insert_left_overlap() override
00085 {
00086 return left_overlap_keep_first( );
00087 }
00088
00089 void insert_right_overlap() override
00090 {
00091 right_overlap_truncate_existing( );
00092 }
00093
00094 int insert_full_overlap() override
00095 {
00096 return full_right_overlap_os2( );
00097 }
00098 };
00099
00100 class TcpReassemblerOldLinux : public TcpReassembler
00101 {
00102 public:
00103 TcpReassemblerOldLinux(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00104 TcpReassembler(session, tracker, StreamPolicy::OS_OLD_LINUX, server)
00105 { }
00106
00107 private:
00108 int insert_left_overlap() override
00109 {
00110 return left_overlap_keep_first( );
00111 }
00112
00113 void insert_right_overlap() override
00114 {
00115 right_overlap_truncate_existing( );
00116 }
00117
00118 int insert_full_overlap() override
00119 {
00120 return full_right_overlap_os4( );
00121 }
00122 };
00123
00124 class TcpReassemblerBSD : public TcpReassembler
00125 {
00126 public:
00127 TcpReassemblerBSD(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00128 TcpReassembler(session, tracker, StreamPolicy::OS_BSD, server)
00129 { }
00130
00131 private:
00132 int insert_left_overlap() override
00133 {
00134 return left_overlap_keep_first( );
00135 }
00136
00137 void insert_right_overlap() override
00138 {
00139 right_overlap_truncate_existing( );
00140 }
00141
00142 int insert_full_overlap() override
00143 {
00144 return full_right_overlap_os1( );
00145 }
00146 };
00147
00148 class TcpReassemblerMacOS : public TcpReassembler
00149 {
00150 public:
00151 TcpReassemblerMacOS(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00152 TcpReassembler(session, tracker, StreamPolicy::OS_MACOS, server)
00153 { }
00154
00155 private:
00156 int insert_left_overlap() override
00157 {
00158 return left_overlap_keep_first( );
00159 }
00160
00161 void insert_right_overlap() override
00162 {
00163 right_overlap_truncate_existing( );
00164 }
00165
00166 int insert_full_overlap() override
00167 {
00168 return full_right_overlap_os1( );
00169 }
00170 };
00171
00172 class TcpReassemblerSolaris : public TcpReassembler
00173 {
00174 public:
00175 TcpReassemblerSolaris(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00176 TcpReassembler(session, tracker, StreamPolicy::OS_SOLARIS, server)
00177 { }
00178
00179 private:
00180 int insert_left_overlap() override
00181 {
00182 return left_overlap_trim_first( );
00183 }
00184
00185 void insert_right_overlap() override
00186 {
00187 right_overlap_truncate_new( );
00188 }
00189
00190 int insert_full_overlap() override
00191 {
00192 return full_right_overlap_os3( );
00193 }
00194 };
00195
00196 class TcpReassemblerIrix : public TcpReassembler
00197 {
00198 public:
00199 TcpReassemblerIrix(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00200 TcpReassembler(session, tracker, StreamPolicy::OS_IRIX, server)
00201 { }
00202
00203 private:
00204 int insert_left_overlap() override
00205 {
00206 return left_overlap_keep_first( );
00207 }
00208
00209 void insert_right_overlap() override
00210 {
00211 right_overlap_truncate_existing( );
00212 }
00213
00214 int insert_full_overlap() override
00215 {
00216 return full_right_overlap_os2( );
00217 }
00218 };
00219
00220 class TcpReassemblerHpux11 : public TcpReassembler
00221 {
00222 public:
00223 TcpReassemblerHpux11(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00224 TcpReassembler(session, tracker, StreamPolicy::OS_HPUX11, server)
00225 { }
00226
00227 private:
00228 int insert_left_overlap() override
00229 {
00230 return left_overlap_trim_first( );
00231 }
00232
00233 void insert_right_overlap() override
00234 {
00235 right_overlap_truncate_new( );
00236 }
00237
00238 int insert_full_overlap() override
00239 {
00240 return full_right_overlap_os3( );
00241 }
00242 };
00243
00244 class TcpReassemblerHpux10 : public TcpReassembler
00245 {
00246 public:
00247 TcpReassemblerHpux10(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00248 TcpReassembler(session, tracker, StreamPolicy::OS_HPUX10, server)
00249 { }
00250
00251 private:
00252 int insert_left_overlap() override
00253 {
00254 return left_overlap_keep_first( );
00255 }
00256
00257 void insert_right_overlap() override
00258 {
00259 right_overlap_truncate_existing( );
00260 }
00261
00262 int insert_full_overlap() override
00263 {
00264 return full_right_overlap_os2( );
00265 }
00266 };
00267
00268 class TcpReassemblerWindows : public TcpReassembler
00269 {
00270 public:
00271 TcpReassemblerWindows(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00272 TcpReassembler(session, tracker, StreamPolicy::OS_WINDOWS, server)
00273 { }
00274
00275 private:
00276 int insert_left_overlap() override
00277 {
00278 return left_overlap_keep_first( );
00279 }
00280
00281 void insert_right_overlap() override
00282 {
00283 right_overlap_truncate_existing( );
00284 }
00285
00286 int insert_full_overlap() override
00287 {
00288 return full_right_overlap_os1( );
00289 }
00290 };
00291
00292 class TcpReassemblerWindows2K3 : public TcpReassembler
00293 {
00294 public:
00295 TcpReassemblerWindows2K3(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00296 TcpReassembler(session, tracker, StreamPolicy::OS_WINDOWS2K3, server)
00297 { }
00298
00299 private:
00300 int insert_left_overlap() override
00301 {
00302 return left_overlap_keep_first( );
00303 }
00304
00305 void insert_right_overlap() override
00306 {
00307 right_overlap_truncate_existing( );
00308 }
00309
00310 int insert_full_overlap() override
00311 {
00312 return full_right_overlap_os1( );
00313 }
00314 };
00315
00316 class TcpReassemblerVista : public TcpReassembler
00317 {
00318 public:
00319 TcpReassemblerVista(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00320 TcpReassembler(session, tracker, StreamPolicy::OS_VISTA, server)
00321 { }
00322
00323 private:
00324 int insert_left_overlap() override
00325 {
00326 return left_overlap_keep_first( );
00327 }
00328
00329 void insert_right_overlap() override
00330 {
00331 right_overlap_truncate_new( );
00332 }
00333
00334 int insert_full_overlap() override
00335 {
00336 return full_right_overlap_os5 ( );
00337 }
00338 };
00339
00340 class TcpReassemblerProxy : public TcpReassemblerFirst
00341 {
00342 public:
00343 TcpReassemblerProxy(TcpSession* session, TcpStreamTracker* tracker, bool server) :
00344 TcpReassemblerFirst(session, tracker, server)
00345 {
00346 tcp_ips_data = NORM_MODE_TEST;
00347 }
00348
00349 private:
00350 int insert_left_overlap() override
00351 {
00352 return left_overlap_keep_first( );
00353 }
00354
00355 void insert_right_overlap() override
00356 {
00357 right_overlap_truncate_new( );
00358 }
00359
00360 int insert_full_overlap() override
00361 {
00362 return full_right_overlap_os5( );
00363 }
00364 };
00365
00366 TcpReassembler* TcpReassemblerFactory::create(TcpSession* session, TcpStreamTracker* tracker,
00367 StreamPolicy os_policy, bool server)
00368 {
00369 NormMode tcp_ips_data = Normalize_GetMode(NORM_TCP_IPS);
00370
00371 if (tcp_ips_data == NORM_MODE_ON)
00372 return new TcpReassemblerFirst(session, tracker, server);
00373 else
00374 {
00375 switch (os_policy)
00376 {
00377 case StreamPolicy::OS_FIRST:
00378 return new TcpReassemblerFirst(session, tracker, server);
00379
00380 case StreamPolicy::OS_LAST:
00381 return new TcpReassemblerLast(session, tracker, server);
00382
00383 case StreamPolicy::OS_LINUX:
00384 return new TcpReassemblerLinux(session, tracker, server);
00385
00386 case StreamPolicy::OS_OLD_LINUX:
00387 return new TcpReassemblerOldLinux(session, tracker, server);
00388
00389 case StreamPolicy::OS_BSD:
00390 return new TcpReassemblerBSD(session, tracker, server);
00391
00392 case StreamPolicy::OS_MACOS:
00393 return new TcpReassemblerMacOS(session, tracker, server);
00394
00395 case StreamPolicy::OS_SOLARIS:
00396 return new TcpReassemblerSolaris(session, tracker, server);
00397
00398 case StreamPolicy::OS_IRIX:
00399 return new TcpReassemblerIrix(session, tracker, server);
00400
00401 case StreamPolicy::OS_HPUX11:
00402 return new TcpReassemblerHpux11(session, tracker, server);
00403
00404 case StreamPolicy::OS_HPUX10:
00405 return new TcpReassemblerHpux10(session, tracker, server);
00406
00407 case StreamPolicy::OS_WINDOWS:
00408 return new TcpReassemblerWindows(session, tracker, server);
00409
00410 case StreamPolicy::OS_WINDOWS2K3:
00411 return new TcpReassemblerWindows2K3(session, tracker, server);
00412
00413 case StreamPolicy::OS_VISTA:
00414 return new TcpReassemblerVista(session, tracker, server);
00415
00416 case StreamPolicy::OS_PROXY:
00417 return new TcpReassemblerProxy(session, tracker, server);
00418
00419 default:
00420 return new TcpReassemblerBSD(session, tracker, server);
00421 }
00422 }
00423 }
00424
END OF CODE