1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
3 // Copyright (C) 2005-2013 Sourcefire, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License Version 2 as published
7 // by the Free Software Foundation. You may not use, modify or distribute
8 // this program under any other version of the GNU General Public License.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //--------------------------------------------------------------------------
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "rule_port_tables.h"
25
26 #include "log/messages.h"
27
28 #include "port_object.h"
29 #include "port_table.h"
30
31 using namespace snort;
32
33 #define DEFAULT_LARGE_RULE_GROUP 9
34
PortProto()35 PortProto::PortProto()
36 {
37 src = PortTableNew();
38 dst = PortTableNew();
39
40 any = PortObjectNew();
41 nfp = PortObjectNew();
42
43 // someday these could be read from snort.conf, something like...
44 // 'config portlist: large-rule-count <val>'
45 src->pt_lrc = DEFAULT_LARGE_RULE_GROUP;
46 dst->pt_lrc = DEFAULT_LARGE_RULE_GROUP;
47
48 PortObjectAddPortAny(any);
49 PortObjectAddPortAny(nfp);
50 }
51
~PortProto()52 PortProto::~PortProto()
53 {
54 PortTableFree(src);
55 PortTableFree(dst);
56 PortObjectFree(any);
57 PortObjectFree(nfp);
58 }
59
PortTablesNew()60 RulePortTables* PortTablesNew()
61 {
62 RulePortTables* rpt = new RulePortTables;
63
64 rpt->svc_any = PortObjectNew();
65 PortObjectAddPortAny(rpt->svc_any);
66
67 return rpt;
68 }
69
PortTablesFree(RulePortTables * port_tables)70 void PortTablesFree(RulePortTables* port_tables)
71 {
72 if ( !port_tables )
73 return;
74
75 if (port_tables->svc_any)
76 PortObjectFree(port_tables->svc_any);
77
78 delete port_tables;
79 }
80
81