"Fossies" - the Fresh Open Source Software Archive

Member "snort-2.9.17/src/file-process/file_segment_process.h" (16 Oct 2020, 3544 Bytes) of package /linux/misc/snort-2.9.17.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "file_segment_process.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.9.16.1_vs_2.9.17.

    1 /****************************************************************************
    2  * Copyright (C) 2014-2020 Cisco and/or its affiliates. All rights reserved.
    3  * Copyright (C) 2008-2013 Sourcefire, Inc.
    4  *
    5  * This program is free software; you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License Version 2 as
    7  * published by the Free Software Foundation.  You may not use, modify or
    8  * distribute this program under any other version of the GNU General
    9  * Public License.
   10  *
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, write to the Free Software
   18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   19  *
   20  ****************************************************************************
   21  *
   22  ****************************************************************************/
   23 /*
   24  * File data reassemble and processing
   25  * Author(s):  Hui Cao <huica@cisco.com>
   26  *
   27  */
   28 
   29 #ifndef _FILE_PROCESS_H_
   30 #define _FILE_PROCESS_H_
   31 
   32 #include <sys/types.h>
   33 #include "sf_types.h"
   34 #include "sfxhash.h"
   35 #include "file_lib.h"
   36 #include "decode.h"
   37 #include "ipv6_port.h"
   38 #include "util.h"
   39 
   40 typedef struct _FileCache
   41 {
   42     SFXHASH *hashTable;
   43     uint32_t max_files;
   44     uint32_t cleanup_files;
   45     FileCacheStatus status;
   46     uint64_t file_segment_memcap;
   47 } FileCache;
   48 
   49 typedef struct _FileSegment
   50 {
   51     /*Use single list for simplicity*/
   52     struct _FileSegment *next;
   53 
   54     uint32_t   offset;
   55     uint32_t   size;   /* actual data size*/
   56     uint32_t   segment_size; /* memory allocated, including headers */
   57     uint8_t    data[1];  /* variable length */
   58 
   59 } FileSegment;
   60 
   61 typedef struct _FileKey
   62 {
   63     struct in6_addr sip;
   64     struct in6_addr dip;
   65     uint64_t file_id;
   66 } FileKey;
   67 
   68 typedef struct _FileEntry
   69 {
   70     FileContext *context;
   71     uint8_t *file_name;
   72     uint64_t offset;
   73     FileSegment *segments;
   74     uint64_t file_size;
   75     FileCache *file_cache;
   76     uint32_t file_name_size;
   77     bool file_resume_check;
   78 } FileEntry;
   79 
   80 /* Create file cache to store file segments and track file
   81  * memcap: total memory available for file cache, including file contexts
   82  * cleanup_files: maximal number of files pruned when memcap reached
   83  */
   84 FileCache *file_cache_create(uint64_t memcap, uint32_t cleanup_files);
   85 
   86 /* Free file cache */
   87 void file_cache_free(FileCache *fileCache);
   88 
   89 /* Get the status of file cache*/
   90 FileCacheStatus *file_cache_status(FileCache *fileCache);
   91 
   92 bool file_cache_shrink_to_memcap(FileCache *fileCache, uint8_t *pWork);
   93 void file_cache_set_memcap(FileCache *fileCache, uint64_t memcap);
   94 
   95 /* Add/update a file entry in the file cache*/
   96 void *file_cache_update_entry (FileCache *fileCache, void* p, uint64_t file_id,
   97         uint8_t *file_name, uint32_t file_name_size, uint64_t file_size, bool reset, 
   98         bool no_update_size);
   99 
  100 /* Process file segments with offset specified. If file segment is out of order,
  101  * it will be put into the file seglist. Otherwise, it will be processed.
  102  *
  103  * Return:
  104  *    1: continue processing/log/block this file
  105  *    0: ignore this file
  106  */
  107 int file_segment_process( FileCache *fileCache, void* p, uint64_t file_id,
  108         uint64_t file_size, const uint8_t* file_data, int data_size, uint64_t offset,
  109         bool upload);
  110 
  111 #endif  /* _FILE_PROCESS_H_ */
  112