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)
65 static void test_nat_basic0(void)
69 err = __connman_nat_enable("bridge", "192.168.2.1", 24);
72 /* test that table is empty */
73 err = __connman_iptables_command("-t nat -C POSTROUTING "
74 "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
76 err = __connman_iptables_commit("nat");
80 __connman_nat_disable("bridge");
83 static void test_nat_basic1(void)
85 struct connman_service *service;
88 service = g_try_new0(struct connman_service, 1);
91 nat_notifier->default_changed(service);
93 err = __connman_nat_enable("bridge", "192.168.2.1", 24);
96 /* test that table is not empty */
97 err = __connman_iptables_command("-t nat -C POSTROUTING "
98 "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
100 err = __connman_iptables_commit("nat");
103 __connman_nat_disable("bridge");
105 /* test that table is empty again */
106 err = __connman_iptables_command("-t nat -C POSTROUTING "
107 "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
109 err = __connman_iptables_commit("nat");
113 int main(int argc, char *argv[])
117 g_test_init(&argc, &argv, NULL);
119 __connman_log_init(argv[0], "*", FALSE);
120 __connman_iptables_init();
121 __connman_nat_init();
123 g_test_add_func("/basic0", test_nat_basic0);
124 g_test_add_func("/basic1", test_nat_basic1);
128 __connman_nat_cleanup();
129 __connman_iptables_cleanup();
130 __connman_log_cleanup();