Skip to content

Commit ceafb40

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents b3d037e + 2af29e9 commit ceafb40

File tree

6 files changed

+14
-181
lines changed

6 files changed

+14
-181
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ aclocal.m4
33
autom4te.cache/
44
configure
55
/BUILD/
6+
/nbproject/private/

config/general.m4

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ AC_DEFUN([CHECK_SSL],
161161
[ AC_ARG_WITH(openssl,
162162
[ --with-openssl=PATH to openssl source directory],
163163
[openssl_path=$withval],
164-
[openssl_path="/usr/local /usr/local/ssl /usr/ssl /usr/pkg /usr / /sw/lib"]
164+
[openssl_path="/usr/local /usr/local/ssl /usr/lib/x86_64-linux-gnu /usr/ssl /usr/pkg /usr / /sw/lib"]
165165
)
166166
AC_PATH_PROG([OPENSSL],[openssl])
167167
AC_MSG_CHECKING([for openssl includes])
@@ -196,7 +196,7 @@ AC_DEFUN([CHECK_SSL],
196196
197197
AC_MSG_CHECKING([for openssl libraries])
198198
found_ssl_lib="no";
199-
for libsubdir in lib lib64 lib32 lib/hpux32; do
199+
for libsubdir in lib lib64 lib/x86_64-linux-gnu i386-linux-gnu lib32 lib/hpux32; do
200200
for dir in $openssl_path ; do
201201
if test -f "$dir/$libsubdir/libssl.so" -o -f "$dir/$libsubdir/libssl.dylib" -o -f "$dir/$libsubdir/libssl.a"; then
202202
found_ssl_lib="yes";

configure.ac

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ SFAC_AUTOMAKE_VERSION([1.6])
88
AC_CONFIG_SRCDIR([src/Core.cpp])
99
AM_CONFIG_HEADER([src/config.h])
1010
AC_PROG_LIBTOOL
11+
AC_CHECK_LIB(boost_thread, main, [BOOST_LIBS="-lboost_date_time -lboost_filesystem -lboost_system -lboost_thread -lboost_program_options -lboost_iostreams -lboost_random -lboost_regex"],
12+
[AC_CHECK_LIB(boost_thread-mt, main,
13+
[BOOST_LIBS="-lboost_date_time-mt -lboost_filesystem-mt -lboost_system-mt -lboost_thread-mt -lboost_program_options-mt -lboost_iostreams-mt -lboost_random-mt -lboost_regex-mt"],
14+
[AC_MSG_ERROR("no boost thread found")])])
15+
AC_SUBST(BOOST_LIBS)
1116
AC_LTDL_SHLIBEXT
1217
AC_PATH_PROG([BASH], [bash])
1318
AC_PROG_CXX

include/OSS/Net/Firewall.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ class Firewall : boost::noncopyable
4444
typedef boost::function<void(const std::string&)> TableLoopHandler;
4545
static Firewall& instance();
4646

47-
bool dnetAddRule(const FirewallRule& rule);
48-
/// Adds a new firewall rule
49-
50-
bool dnetDeleteRule(const FirewallRule&);
51-
/// Delete the rule by valaue.
52-
53-
void dnetTableLoop(TableLoopHandler& handler);
54-
/// Loop through all rules. String representation of the rule is
5547
/// pushed the the handle callback.
5648

5749
bool iptAddRule(const FirewallRule& rule);
@@ -65,9 +57,8 @@ class Firewall : boost::noncopyable
6557

6658
private:
6759
friend Firewall& instance();
68-
Firewall(bool useLibDnet = false);
60+
Firewall();
6961
~Firewall();
70-
bool _useLibDnet;
7162
};
7263

7364

src/Makefile.am

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ liboss_core_la_LDFLAGS = \
1818
-version-info ${version_Current}:${version_Revision}:${version_Age}
1919

2020
dep_libs = \
21-
-lboost_date_time-mt \
22-
-lboost_filesystem-mt \
23-
-lboost_system-mt \
24-
-lboost_thread-mt \
25-
-lboost_regex-mt \
26-
-lboost_program_options-mt \
27-
-lboost_iostreams-mt \
28-
-lboost_random-mt \
21+
@BOOST_LIBS@ \
2922
-lPocoFoundation \
3023
-lPocoUtil \
3124
-lPocoNet \

src/net/Firewall.cpp

+4-161
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919

20-
#include <dnet.h>
2120
#include <sstream>
2221
#include "OSS/Net/Firewall.h"
2322
#include "OSS/Logger.h"
@@ -29,89 +28,6 @@ extern "C" { size_t strlcpy(char *dst, const char *src, size_t siz); };
2928
namespace OSS {
3029
namespace Net {
3130

32-
//
33-
// DNET specific functions
34-
//
35-
fw_t* _pInstance = 0;
36-
37-
static bool rule_to_fwrule(const FirewallRule& rule, fw_rule* fr)
38-
{
39-
fr->fw_proto = rule.getProtocol();
40-
fr->fw_op = rule.getOperation();
41-
fr->fw_dir = rule.getDirection();
42-
43-
if (!rule.getDevice().empty())
44-
strlcpy(fr->fw_device, rule.getDevice().c_str(), sizeof(fr->fw_device));
45-
46-
if (!rule.getSourceAddress().empty())
47-
{
48-
if (addr_pton(rule.getSourceAddress().c_str(), &fr->fw_dst) < 0)
49-
return false;
50-
}
51-
52-
if (!rule.getDestinationAddress().empty())
53-
{
54-
if (addr_pton(rule.getDestinationAddress().c_str(), &fr->fw_dst) < 0)
55-
return false;
56-
}
57-
58-
if (rule.getSourcePort() != 0)
59-
{
60-
fr->fw_sport[0] = rule.getSourcePort();
61-
if (rule.getSourceEndPort() != 0)
62-
fr->fw_sport[1] = rule.getSourceEndPort();
63-
else
64-
fr->fw_sport[1] = rule.getSourcePort();
65-
}
66-
else if (fr->fw_proto == IP_PROTO_TCP || fr->fw_proto == IP_PROTO_UDP)
67-
{
68-
fr->fw_sport[0] = 0;
69-
fr->fw_sport[1] = TCP_PORT_MAX;
70-
}
71-
72-
if (rule.getDestinationPort() != 0)
73-
{
74-
fr->fw_dport[0] = rule.getDestinationPort();
75-
if (rule.getDestinationEndPort() != 0)
76-
fr->fw_dport[1] = rule.getDestinationEndPort();
77-
else
78-
fr->fw_dport[1] = rule.getDestinationPort();
79-
}
80-
else if (fr->fw_proto == IP_PROTO_TCP || fr->fw_proto == IP_PROTO_UDP)
81-
{
82-
fr->fw_dport[0] = 0;
83-
fr->fw_dport[1] = TCP_PORT_MAX;
84-
}
85-
86-
return true;
87-
}
88-
89-
static int internal_table_loop(const struct fw_rule *fr, void *arg)
90-
{
91-
Firewall::TableLoopHandler* pHandler = reinterpret_cast<Firewall::TableLoopHandler*>(arg);
92-
93-
FirewallRule rule(
94-
fr->fw_device ? fr->fw_device : "",
95-
fr->fw_src.addr_type ? addr_ntoa(&fr->fw_src) : "",
96-
fr->fw_sport[0],
97-
fr->fw_sport[1],
98-
fr->fw_src.addr_type ? addr_ntoa(&fr->fw_dst) : "",
99-
fr->fw_dport[0],
100-
fr->fw_dport[1],
101-
fr->fw_proto,
102-
fr->fw_dir,
103-
fr->fw_op
104-
);
105-
106-
(*pHandler)(rule.str());
107-
return 0;
108-
}
109-
110-
//
111-
// EOF Dnet functions
112-
//
113-
114-
11531
//
11632
// Start of IPTables functions
11733
//
@@ -218,55 +134,20 @@ static std::string iptables_get_rules(FirewallRule::Direction direction)
218134

219135
Firewall& Firewall::instance()
220136
{
221-
static Firewall fw(false /* o not use libdnet */);
137+
static Firewall fw;
222138
return fw;
223139
}
224140

225-
Firewall::Firewall(bool useLibDnet) :
226-
_useLibDnet(useLibDnet)
141+
Firewall::Firewall()
227142
{
228-
if (_useLibDnet)
229-
{
230-
_pInstance = fw_open();
231-
}
232143
}
233144

234145
Firewall::~Firewall()
235146
{
236-
if (_useLibDnet)
237-
{
238-
if (_pInstance)
239-
fw_close(_pInstance);
240-
}
241147
}
242148

243149

244-
bool Firewall::dnetAddRule(const FirewallRule& rule)
245-
{
246-
if (_useLibDnet)
247-
{
248-
if (!_pInstance)
249-
{
250-
OSS_LOG_ERROR("Dnet Firewall hook is not open.");
251-
return false;
252-
}
253-
254-
fw_rule fr;
255-
if (!rule_to_fwrule(rule, &fr))
256-
{
257-
OSS_LOG_ERROR("Dnet Firewall hook is not open.");
258-
return false;
259-
}
260-
int ret = fw_add(_pInstance, &fr);
261-
if (ret < 0)
262-
{
263-
OSS_LOG_ERROR("Firewall: Error adding rule (ret=" << ret << ")");
264-
return false;
265-
}
266-
return true;
267-
}
268-
return false;
269-
}
150+
270151

271152
bool Firewall::iptAddRule(const FirewallRule& rule)
272153
{
@@ -276,49 +157,11 @@ bool Firewall::iptAddRule(const FirewallRule& rule)
276157

277158
bool Firewall::iptDeleteRule(FirewallRule::Direction direction, std::size_t index)
278159
{
279-
if (!_useLibDnet)
280-
{
281-
OSS_EXEC(iptables_delete(direction, index));
282-
return true;
283-
}
284-
return false;
285-
}
286-
287-
bool Firewall::dnetDeleteRule(const FirewallRule& rule)
288-
{
289-
if (_useLibDnet)
290-
{
291-
if (!_pInstance)
292-
{
293-
OSS_LOG_ERROR("Dnet Firewall hook is not open.");
294-
return false;
295-
}
296-
297-
fw_rule fr;
298-
rule_to_fwrule(rule, &fr);
299-
int ret = fw_delete(_pInstance, &fr);
300-
if (ret < 0)
301-
{
302-
OSS_LOG_ERROR("Firewall: Error deleting rule (ret=" << ret << ")");
303-
return false;
304-
}
305-
}
160+
OSS_EXEC(iptables_delete(direction, index));
306161
return true;
307162
}
308163

309164

310-
void Firewall::dnetTableLoop(TableLoopHandler& handler)
311-
{
312-
if (_useLibDnet)
313-
{
314-
if (!_pInstance)
315-
{
316-
OSS_LOG_ERROR("Dnet Firewall hook is not open.");
317-
return;
318-
}
319-
fw_loop(_pInstance, internal_table_loop, (void*)&handler);
320-
}
321-
}
322165

323166
void Firewall::iptGetRules(FirewallRule::Direction direction, std::vector<std::string>& rules)
324167
{

0 commit comments

Comments
 (0)