5 * Copyright (C) 2012 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"
34 #define LOG(fmt, arg...) do { \
35 fprintf(stdout, "%s:%s() " fmt "\n", \
36 __FILE__, __func__ , ## arg); \
39 #define LOG(fmt, arg...)
42 struct connman_notifier *nat_notifier;
44 struct connman_service {
48 char *connman_service_get_interface(struct connman_service *service)
53 int connman_notifier_register(struct connman_notifier *notifier)
55 nat_notifier = notifier;
60 void connman_notifier_unregister(struct connman_notifier *notifier)
66 static void test_iptables_basic0(void)
70 err = __connman_iptables_command("-C INPUT -i session-bridge -j ACCEPT");
72 err = __connman_iptables_commit("filter");
75 err = __connman_iptables_command("-I INPUT -i session-bridge -j ACCEPT");
77 err = __connman_iptables_commit("filter");
80 err = __connman_iptables_command("-C INPUT -i session-bridge -j ACCEPT");
82 err = __connman_iptables_commit("filter");
85 err = __connman_iptables_command("-D INPUT -i session-bridge -j ACCEPT");
87 err = __connman_iptables_commit("filter");
90 err = __connman_iptables_command("-C INPUT -i session-bridge -j ACCEPT");
92 err = __connman_iptables_commit("filter");
96 static void test_nat_basic0(void)
100 err = __connman_nat_enable("bridge", "192.168.2.1", 24);
103 /* test that table is empty */
104 err = __connman_iptables_command("-t nat -C POSTROUTING "
105 "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
107 err = __connman_iptables_commit("nat");
111 __connman_nat_disable("bridge");
114 static void test_nat_basic1(void)
116 struct connman_service *service;
119 service = g_try_new0(struct connman_service, 1);
122 nat_notifier->default_changed(service);
124 err = __connman_nat_enable("bridge", "192.168.2.1", 24);
127 /* test that table is not empty */
128 err = __connman_iptables_command("-t nat -C POSTROUTING "
129 "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
131 err = __connman_iptables_commit("nat");
134 __connman_nat_disable("bridge");
136 /* test that table is empty again */
137 err = __connman_iptables_command("-t nat -C POSTROUTING "
138 "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
140 err = __connman_iptables_commit("nat");
144 int main(int argc, char *argv[])
148 g_test_init(&argc, &argv, NULL);
150 __connman_log_init(argv[0], "*", FALSE);
151 __connman_iptables_init();
152 __connman_nat_init();
154 g_test_add_func("/iptables/basic0", test_iptables_basic0);
155 g_test_add_func("/nat/basic0", test_nat_basic0);
156 g_test_add_func("/nat/basic1", test_nat_basic1);
160 __connman_nat_cleanup();
161 __connman_iptables_cleanup();
162 __connman_log_cleanup();