1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-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 // codec_module.cc author Josh Rosenbaum <jrosenba@cisco.com>
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "codecs/codec_module.h"
25 
26 #include "trace/trace.h"
27 
28 using namespace snort;
29 
30 #define codec_module_help \
31     "general decoder rules"
32 
33 #define s_name "decode"
34 
35 THREAD_LOCAL const Trace* decode_trace = nullptr;
36 
37 static const Parameter s_params[] = {{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }};
38 
CodecModule()39 CodecModule::CodecModule() : BaseCodecModule(s_name, codec_module_help, s_params)
40 { }
41 
set_trace(const Trace * trace) const42 void CodecModule::set_trace(const Trace* trace) const
43 { decode_trace = trace; }
44 
get_trace_options() const45 const TraceOption* CodecModule::get_trace_options() const
46 {
47 #ifndef DEBUG_MSGS
48     return nullptr;
49 #else
50     static const TraceOption codec_trace_options(nullptr, 0, nullptr);
51     return &codec_trace_options;
52 #endif
53 }
54 
55 static const RuleMap general_decode_rules[] =
56 {
57     { DECODE_IP_BAD_PROTO, "bad IP protocol" },
58     { DECODE_IP_MULTIPLE_ENCAPSULATION,
59         "two or more IP (v4 and/or v6) encapsulation layers present" },
60     { DECODE_ZERO_LENGTH_FRAG, "fragment with zero length" },
61     { DECODE_BAD_TRAFFIC_LOOPBACK, "loopback IP" },
62     { DECODE_BAD_TRAFFIC_SAME_SRCDST, "same src/dst IP" },
63     { DECODE_IP_UNASSIGNED_PROTO, "unassigned/reserved IP protocol" },
64     { DECODE_TOO_MANY_LAYERS, "too many protocols present" },
65     { DECODE_BAD_ETHER_TYPE, "ether type out of range" },
66     { 0, nullptr },
67 };
68 
get_rules() const69 const RuleMap* CodecModule::get_rules() const
70 { return general_decode_rules; }
71 
72