diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2013-02-12 10:19:36 +0100 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-02-12 12:26:34 +0200 |
commit | e2e73d11d463dd443832f6f96633fb8afddf1bf5 (patch) | |
tree | 2b7631fad95d3be0c4d6e39957721ce99dc790bc /unit | |
parent | 1dcb7cd93631d04efa72afcf9ebf6f9768db59e8 (diff) | |
download | connman-e2e73d11d463dd443832f6f96633fb8afddf1bf5.tar.gz connman-e2e73d11d463dd443832f6f96633fb8afddf1bf5.tar.bz2 connman-e2e73d11d463dd443832f6f96633fb8afddf1bf5.zip |
test-iptables: Add unit test for iptables
Diffstat (limited to 'unit')
-rw-r--r-- | unit/test-iptables.c | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/unit/test-iptables.c b/unit/test-iptables.c new file mode 100644 index 00000000..f11ed551 --- /dev/null +++ b/unit/test-iptables.c @@ -0,0 +1,122 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2013 BWM CarIT GmbH. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib.h> + +#include "../src/connman.h" + +static void test_iptables_basic0(void) +{ + int err; + + err = __connman_iptables_command("-t filter -A INPUT " + "-m mark --mark 1 -j LOG"); + g_assert(err == 0); + + err = __connman_iptables_commit("filter"); + g_assert(err == 0); + + err = __connman_iptables_command("-t filter -D INPUT " + "-m mark --mark 1 -j LOG"); + g_assert(err == 0); + + err = __connman_iptables_commit("filter"); + g_assert(err == 0); +} + +static void test_iptables_basic1(void) +{ + int err; + + /* Test if we can do NAT stuff */ + + err = __connman_iptables_command("-t nat -A POSTROUTING " + "-s 10.10.1.0/24 -o eth0 -j MASQUERADE"); + + err = __connman_iptables_commit("nat"); + g_assert(err == 0); + + err = __connman_iptables_command("-t nat -D POSTROUTING " + "-s 10.10.1.0/24 -o eth0 -j MASQUERADE"); + + err = __connman_iptables_commit("nat"); + g_assert(err == 0); +} + +static void test_iptables_basic2(void) +{ + int err; + + /* Test if the right rule is removed */ + + err = __connman_iptables_command("-t filter -A INPUT " + "-m mark --mark 1 -j LOG"); + g_assert(err == 0); + + err = __connman_iptables_commit("filter"); + g_assert(err == 0); + + err = __connman_iptables_command("-t filter -A INPUT " + "-m mark --mark 2 -j LOG"); + g_assert(err == 0); + + err = __connman_iptables_commit("filter"); + g_assert(err == 0); + + err = __connman_iptables_command("-t filter -D INPUT " + "-m mark --mark 2 -j LOG"); + g_assert(err == 0); + + err = __connman_iptables_commit("filter"); + g_assert(err == 0); + + err = __connman_iptables_command("-t filter -D INPUT " + "-m mark --mark 1 -j LOG"); + g_assert(err == 0); + + err = __connman_iptables_commit("filter"); + g_assert(err == 0); +} + +int main(int argc, char *argv[]) +{ + int err; + + g_test_init(&argc, &argv, NULL); + + __connman_log_init(argv[0], "*", FALSE, FALSE, + "Unit Tests Connection Manager", VERSION); + __connman_iptables_init(); + + g_test_add_func("/iptables/basic0", test_iptables_basic0); + g_test_add_func("/iptables/basic1", test_iptables_basic1); + g_test_add_func("/iptables/basic2", test_iptables_basic2); + + err = g_test_run(); + + __connman_iptables_cleanup(); + + return err; +} |