2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 $Date: 2009/10/12 08:46:05 $
27 #include "rules_finder.h"
31 STG::RULES_FINDER::RULES_FINDER()
33 pthread_mutex_init(&mutex, NULL);
36 STG::RULES_FINDER::~RULES_FINDER()
38 pthread_mutex_destroy(&mutex);
41 void STG::RULES_FINDER::SetRules(const RULES & r)
43 SCOPED_LOCK lock(mutex);
47 int STG::RULES_FINDER::GetDir(const PENDING_PACKET & packet) const
52 STG::RULES::const_iterator ln;
55 SCOPED_LOCK lock(mutex);
59 while (ln != rules.end())
65 switch (packet.direction) {
66 case PENDING_PACKET::INCOMING:
67 portMatch = (packet.sport >= ln->port1) &&
68 (packet.sport <= ln->port2);
70 case PENDING_PACKET::OUTGOING:
71 portMatch = (packet.dport >= ln->port1) &&
72 (packet.dport <= ln->port2);
74 case PENDING_PACKET::LOCAL:
75 portMatch = ((packet.sport >= ln->port1) &&
76 (packet.sport <= ln->port2)) ||
77 ((packet.dport >= ln->port1) &&
78 (packet.dport <= ln->port2));
92 /*portMatch = ((packet.sport >= ln->port1) &&
93 (packet.sport <= ln->port2) &&
94 (packet.direction == PENDING_PACKET::INCOMING)) ||
95 ((packet.dport >= ln->port1) &&
96 (packet.dport <= ln->port2) &&
97 (packet.direction == PENDING_PACKET::OUTGOING));*/
99 if (ln->proto != packet.proto)
101 // Is it a normal protcol number?
108 else if (ln->proto == -2)
111 if (packet.proto != 6 &&
122 switch (packet.direction) {
123 case PENDING_PACKET::INCOMING:
124 // From outer world to us
125 addrMatch = (packet.saddr & ln->mask) == ln->ip;
127 case PENDING_PACKET::OUTGOING:
128 // From us to outer world
129 addrMatch = (packet.daddr & ln->mask) == ln->ip;
131 case PENDING_PACKET::LOCAL:
133 addrMatch = (packet.saddr & ln->mask) == ln->ip ||
134 (packet.daddr & ln->mask) == ln->ip;
137 // From outer world to outer world
146 // At this point ports and protocol are matched
152 } //while (ln != rules.end())