1 //-------------------------------------------------------------------------- 2 // Copyright (C) 2019-2021 Cisco and/or its affiliates. All rights reserved. 3 // 4 // This program is free software; you can redistribute it and/or modify it 5 // under the terms of the GNU General Public License Version 2 as published 6 // by the Free Software Foundation. You may not use, modify or distribute 7 // this program under any other version of the GNU General Public License. 8 // 9 // This program is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License along 15 // with this program; if not, write to the Free Software Foundation, Inc., 16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 //-------------------------------------------------------------------------- 18 // http2_hpack_dynamic_table.h author Katura Harvey <katharve@cisco.com> 19 20 #ifndef HTTP2_HPACK_DYNAMIC_TABLE_H 21 #define HTTP2_HPACK_DYNAMIC_TABLE_H 22 23 #include "service_inspectors/http_inspect/http_field.h" 24 #include "main/snort_types.h" 25 26 #include "http2_enum.h" 27 28 #include <vector> 29 30 struct HpackTableEntry; 31 class Http2FlowData; 32 33 class HpackDynamicTable 34 { 35 public: 36 // FIXIT-P This array can be optimized to start smaller and grow on demand HpackDynamicTable()37 HpackDynamicTable() : circular_buf(ARRAY_CAPACITY, nullptr) {} 38 ~HpackDynamicTable(); 39 const HpackTableEntry* get_entry(uint32_t index) const; 40 bool add_entry(const Field& name, const Field& value); 41 void update_size(uint32_t new_size); get_max_size()42 uint32_t get_max_size() { return max_size; } 43 44 private: 45 const static uint32_t RFC_ENTRY_OVERHEAD = 32; 46 47 const static uint32_t DEFAULT_MAX_SIZE = 4096; 48 const static uint32_t ARRAY_CAPACITY = 512; 49 uint32_t max_size = DEFAULT_MAX_SIZE; 50 51 uint32_t start = 0; 52 uint32_t num_entries = 0; 53 uint32_t rfc_table_size = 0; 54 std::vector<HpackTableEntry*> circular_buf; 55 56 void prune_to_size(uint32_t new_max_size); 57 }; 58 #endif 59