summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Lucangeli Obes <jorgelo@chromium.org>2015-01-29 15:18:46 -0800
committerGilad Arnold <garnold@google.com>2015-08-10 23:11:52 -0700
commit5affd8895f6879153fce488c3f92271349eeadc9 (patch)
tree152243a908d67a18adcb974bcc37a1658132f053
parent0e7a658e0f72b0d2113f5c06136620236dde96f9 (diff)
downloadfirewalld-5affd8895f6879153fce488c3f92271349eeadc9.tar.gz
firewalld: make D-Bus methods simple.
BUG=chromium:435400 TEST=unit tests Change-Id: I4afa4264332ed3ef2eb0e4fafbbb7917e5c995ba Reviewed-on: https://chromium-review.googlesource.com/244492 Commit-Queue: Jorge Lucangeli Obes <jorgelo@chromium.org> Trybot-Ready: Jorge Lucangeli Obes <jorgelo@chromium.org> Tested-by: Jorge Lucangeli Obes <jorgelo@chromium.org> Reviewed-by: Chris Masone <cmasone@chromium.org>
-rw-r--r--dbus_bindings/org.chromium.Firewalld.xml4
-rw-r--r--iptables.cc28
-rw-r--r--iptables.h16
-rw-r--r--iptables_unittest.cc61
4 files changed, 34 insertions, 75 deletions
diff --git a/dbus_bindings/org.chromium.Firewalld.xml b/dbus_bindings/org.chromium.Firewalld.xml
index 61bb122..ef27d77 100644
--- a/dbus_bindings/org.chromium.Firewalld.xml
+++ b/dbus_bindings/org.chromium.Firewalld.xml
@@ -4,18 +4,22 @@
<method name="PunchTcpHole">
<arg type="q" name="port" direction="in" />
<arg type="b" name="success" direction="out" />
+ <annotation name="org.chromium.DBus.Method.Kind" value="simple"/>
</method>
<method name="PunchUdpHole">
<arg type="q" name="port" direction="in" />
<arg type="b" name="success" direction="out" />
+ <annotation name="org.chromium.DBus.Method.Kind" value="simple"/>
</method>
<method name="PlugTcpHole">
<arg type="q" name="port" direction="in" />
<arg type="b" name="success" direction="out" />
+ <annotation name="org.chromium.DBus.Method.Kind" value="simple"/>
</method>
<method name="PlugUdpHole">
<arg type="q" name="port" direction="in" />
<arg type="b" name="success" direction="out" />
+ <annotation name="org.chromium.DBus.Method.Kind" value="simple"/>
</method>
</interface>
</node>
diff --git a/iptables.cc b/iptables.cc
index ca0a8d7..e70f161 100644
--- a/iptables.cc
+++ b/iptables.cc
@@ -26,32 +26,20 @@ IpTables::~IpTables() {
PlugAllHoles();
}
-bool IpTables::PunchTcpHole(chromeos::ErrorPtr* error,
- uint16_t in_port,
- bool* out_success) {
- *out_success = PunchHole(in_port, &tcp_holes_, kProtocolTcp);
- return true;
+bool IpTables::PunchTcpHole(uint16_t in_port) {
+ return PunchHole(in_port, &tcp_holes_, kProtocolTcp);
}
-bool IpTables::PunchUdpHole(chromeos::ErrorPtr* error,
- uint16_t in_port,
- bool* out_success) {
- *out_success = PunchHole(in_port, &udp_holes_, kProtocolUdp);
- return true;
+bool IpTables::PunchUdpHole(uint16_t in_port) {
+ return PunchHole(in_port, &udp_holes_, kProtocolUdp);
}
-bool IpTables::PlugTcpHole(chromeos::ErrorPtr* error,
- uint16_t in_port,
- bool* out_success) {
- *out_success = PlugHole(in_port, &tcp_holes_, kProtocolTcp);
- return true;
+bool IpTables::PlugTcpHole(uint16_t in_port) {
+ return PlugHole(in_port, &tcp_holes_, kProtocolTcp);
}
-bool IpTables::PlugUdpHole(chromeos::ErrorPtr* error,
- uint16_t in_port,
- bool* out_success) {
- *out_success = PlugHole(in_port, &udp_holes_, kProtocolUdp);
- return true;
+bool IpTables::PlugUdpHole(uint16_t in_port) {
+ return PlugHole(in_port, &udp_holes_, kProtocolUdp);
}
bool IpTables::PunchHole(uint16_t port,
diff --git a/iptables.h b/iptables.h
index a0f3f95..2bcf8c8 100644
--- a/iptables.h
+++ b/iptables.h
@@ -25,18 +25,10 @@ class IpTables : public org::chromium::FirewalldInterface {
~IpTables();
// D-Bus methods.
- bool PunchTcpHole(chromeos::ErrorPtr* error,
- uint16_t in_port,
- bool* out_success);
- bool PunchUdpHole(chromeos::ErrorPtr* error,
- uint16_t in_port,
- bool* out_success);
- bool PlugTcpHole(chromeos::ErrorPtr* error,
- uint16_t in_port,
- bool* out_success);
- bool PlugUdpHole(chromeos::ErrorPtr* error,
- uint16_t in_port,
- bool* out_success);
+ bool PunchTcpHole(uint16_t in_port) override;
+ bool PunchUdpHole(uint16_t in_port) override;
+ bool PlugTcpHole(uint16_t in_port) override;
+ bool PlugUdpHole(uint16_t in_port) override;
protected:
// Test-only.
diff --git a/iptables_unittest.cc b/iptables_unittest.cc
index eb470c1..bc86445 100644
--- a/iptables_unittest.cc
+++ b/iptables_unittest.cc
@@ -23,81 +23,56 @@ class IpTablesTest : public testing::Test {
};
TEST_F(IpTablesTest, Port0Fails) {
- bool success = false;
- // Try to punch hole for TCP port 0.
- ASSERT_TRUE(iptables_succeeds.PunchTcpHole(nullptr, 0, &success));
- // Port 0 is not a valid port.
- ASSERT_FALSE(success);
- // Try to punch hole for UDP port 0.
- ASSERT_TRUE(iptables_succeeds.PunchUdpHole(nullptr, 0, &success));
- // Port 0 is not a valid port.
- ASSERT_FALSE(success);
+ // Try to punch hole for TCP port 0, port 0 is not a valid port.
+ ASSERT_FALSE(iptables_succeeds.PunchTcpHole(0));
+ // Try to punch hole for UDP port 0, port 0 is not a valid port.
+ ASSERT_FALSE(iptables_succeeds.PunchUdpHole(0));
}
TEST_F(IpTablesTest, PunchTcpHoleSucceeds) {
- bool success = false;
// Punch hole for TCP port 80, should succeed.
- ASSERT_TRUE(iptables_succeeds.PunchTcpHole(nullptr, 80, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PunchTcpHole(80));
// Punch again, should still succeed.
- ASSERT_TRUE(iptables_succeeds.PunchTcpHole(nullptr, 80, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PunchTcpHole(80));
// Plug the hole, should succeed.
- ASSERT_TRUE(iptables_succeeds.PlugTcpHole(nullptr, 80, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PlugTcpHole(80));
}
TEST_F(IpTablesTest, PlugTcpHoleSucceeds) {
- bool success = false;
// Punch hole for TCP port 80, should succeed.
- ASSERT_TRUE(iptables_succeeds.PunchTcpHole(nullptr, 80, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PunchTcpHole(80));
// Plug the hole, should succeed.
- ASSERT_TRUE(iptables_succeeds.PlugTcpHole(nullptr, 80, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PlugTcpHole(80));
// Plug again, should fail.
- ASSERT_TRUE(iptables_succeeds.PlugTcpHole(nullptr, 80, &success));
- ASSERT_FALSE(success);
+ ASSERT_FALSE(iptables_succeeds.PlugTcpHole(80));
}
TEST_F(IpTablesTest, PunchUdpHoleSucceeds) {
- bool success = false;
// Punch hole for UDP port 53, should succeed.
- ASSERT_TRUE(iptables_succeeds.PunchUdpHole(nullptr, 53, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PunchUdpHole(53));
// Punch again, should still succeed.
- ASSERT_TRUE(iptables_succeeds.PunchUdpHole(nullptr, 53, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PunchUdpHole(53));
// Plug the hole, should succeed.
- ASSERT_TRUE(iptables_succeeds.PlugUdpHole(nullptr, 53, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PlugUdpHole(53));
}
TEST_F(IpTablesTest, PlugUdpHoleSucceeds) {
- bool success = false;
// Punch hole for UDP port 53, should succeed.
- ASSERT_TRUE(iptables_succeeds.PunchUdpHole(nullptr, 53, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PunchUdpHole(53));
// Plug the hole, should succeed.
- ASSERT_TRUE(iptables_succeeds.PlugUdpHole(nullptr, 53, &success));
- ASSERT_TRUE(success);
+ ASSERT_TRUE(iptables_succeeds.PlugUdpHole(53));
// Plug again, should fail.
- ASSERT_TRUE(iptables_succeeds.PlugUdpHole(nullptr, 53, &success));
- ASSERT_FALSE(success);
+ ASSERT_FALSE(iptables_succeeds.PlugUdpHole(53));
}
TEST_F(IpTablesTest, PunchTcpHoleFails) {
- bool success = false;
// Punch hole for TCP port 80, should fail.
- ASSERT_TRUE(iptables_fails.PunchTcpHole(nullptr, 80, &success));
- ASSERT_FALSE(success);
+ ASSERT_FALSE(iptables_fails.PunchTcpHole(80));
}
TEST_F(IpTablesTest, PunchUdpHoleFails) {
- bool success = false;
// Punch hole for UDP port 53, should fail.
- ASSERT_TRUE(iptables_fails.PunchUdpHole(nullptr, 53, &success));
- ASSERT_FALSE(success);
+ ASSERT_FALSE(iptables_fails.PunchUdpHole(53));
}
} // namespace firewalld