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");
77 __connman_nat_disable("bridge");
80 static void test_nat_basic1(void)
82 struct connman_service *service;
85 service = g_try_new0(struct connman_service, 1);
88 nat_notifier->default_changed(service);
90 err = __connman_nat_enable("bridge", "192.168.2.1", 24);
93 /* test that table is not empty */
94 err = __connman_iptables_command("-t nat -C POSTROUTING "
95 "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
98 __connman_nat_disable("bridge");
100 /* test that table is empty again */
101 err = __connman_iptables_command("-t nat -C POSTROUTING "
102 "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
106 int main(int argc, char *argv[])
110 g_test_init(&argc, &argv, NULL);
112 __connman_log_init(argv[0], "*", FALSE);
113 __connman_iptables_init();
114 __connman_nat_init();
116 g_test_add_func("/basic0", test_nat_basic0);
117 g_test_add_func("/basic1", test_nat_basic1);
121 __connman_nat_cleanup();
122 __connman_iptables_cleanup();
123 __connman_log_cleanup();