5 * Copyright (C) 2013 BWM CarIT GmbH. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "../src/connman.h"
30 static void test_iptables_basic0(void)
34 err = __connman_iptables_command("-t filter -A INPUT "
35 "-m mark --mark 1 -j LOG");
38 err = __connman_iptables_commit("filter");
41 err = __connman_iptables_command("-t filter -D INPUT "
42 "-m mark --mark 1 -j LOG");
45 err = __connman_iptables_commit("filter");
49 static void test_iptables_basic1(void)
53 /* Test if we can do NAT stuff */
55 err = __connman_iptables_command("-t nat -A POSTROUTING "
56 "-s 10.10.1.0/24 -o eth0 -j MASQUERADE");
58 err = __connman_iptables_commit("nat");
61 err = __connman_iptables_command("-t nat -D POSTROUTING "
62 "-s 10.10.1.0/24 -o eth0 -j MASQUERADE");
64 err = __connman_iptables_commit("nat");
68 static void test_iptables_basic2(void)
72 /* Test if the right rule is removed */
74 err = __connman_iptables_command("-t filter -A INPUT "
75 "-m mark --mark 1 -j LOG");
78 err = __connman_iptables_commit("filter");
81 err = __connman_iptables_command("-t filter -A INPUT "
82 "-m mark --mark 2 -j LOG");
85 err = __connman_iptables_commit("filter");
88 err = __connman_iptables_command("-t filter -D INPUT "
89 "-m mark --mark 2 -j LOG");
92 err = __connman_iptables_commit("filter");
95 err = __connman_iptables_command("-t filter -D INPUT "
96 "-m mark --mark 1 -j LOG");
99 err = __connman_iptables_commit("filter");
103 int main(int argc, char *argv[])
107 g_test_init(&argc, &argv, NULL);
109 __connman_log_init(argv[0], "*", FALSE, FALSE,
110 "Unit Tests Connection Manager", VERSION);
111 __connman_iptables_init();
113 g_test_add_func("/iptables/basic0", test_iptables_basic0);
114 g_test_add_func("/iptables/basic1", test_iptables_basic1);
115 g_test_add_func("/iptables/basic2", test_iptables_basic2);
119 __connman_iptables_cleanup();