2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <glib-object.h>
21 #include "stc_ipt_test.h"
22 #include "stc_ipt_gdbus.h"
23 #include "stc_ipt_sys.h"
24 #include "stc_ipt_menu.h"
26 static char g_chain_name[MENU_DATA_SIZE] = "STC_CHAIN";
28 static int __stc_ipt_add_chain(void)
30 GVariant *message = NULL;
31 GVariant *params = NULL;
32 int err = STC_ERROR_NONE;
35 params = g_variant_new("(s)", g_chain_name);
37 message = stc_ipt_dbus_invoke_method(
39 STC_IPT_DBUS_CHAIN_PATH,
40 STC_IPT_DBUS_CHAIN_INTERFACE,
41 STC_IPT_DBUS_METHOD_IPT_ADD_CHAIN,
45 if (message == NULL) {
46 msg(LOG_RED "Failed to invoke dbus method" LOG_END);
50 g_variant_get(message, "(i)", &result);
51 msg(LOG_GREEN "Successfully add chain [%d]" LOG_END, result);
52 g_variant_unref(message);
54 stc_ipt_exe_cmd(CHECK_IPTABLES);
59 static int __stc_ip6t_add_chain(void)
61 GVariant *message = NULL;
62 GVariant *params = NULL;
63 int err = STC_ERROR_NONE;
66 params = g_variant_new("(s)", g_chain_name);
68 message = stc_ipt_dbus_invoke_method(
70 STC_IPT_DBUS_CHAIN_PATH,
71 STC_IPT_DBUS_CHAIN_INTERFACE,
72 STC_IPT_DBUS_METHOD_IP6T_ADD_CHAIN,
76 if (message == NULL) {
77 msg(LOG_RED "Failed to invoke dbus method" LOG_END);
81 g_variant_get(message, "(i)", &result);
82 msg(LOG_GREEN "Successfully add 6 chain [%d]" LOG_END, result);
83 g_variant_unref(message);
85 stc_ipt_exe_cmd(CHECK_IP6TABLES);
90 static int __stc_ipt_remove_chain(void)
92 GVariant *message = NULL;
93 GVariant *params = NULL;
94 int err = STC_ERROR_NONE;
97 params = g_variant_new("(s)", g_chain_name);
99 message = stc_ipt_dbus_invoke_method(
100 STC_IPT_DBUS_SERVICE,
101 STC_IPT_DBUS_CHAIN_PATH,
102 STC_IPT_DBUS_CHAIN_INTERFACE,
103 STC_IPT_DBUS_METHOD_IPT_REMOVE_CHAIN,
107 if (message == NULL) {
108 msg(LOG_RED "Failed to invoke dbus method" LOG_END);
112 stc_ipt_exe_cmd(CHECK_IPTABLES);
114 g_variant_get(message, "(i)", &result);
115 msg(LOG_GREEN "Successfully remove chain [%d]" LOG_END, result);
116 g_variant_unref(message);
121 static int __stc_ip6t_remove_chain(void)
123 GVariant *message = NULL;
124 GVariant *params = NULL;
125 int err = STC_ERROR_NONE;
128 params = g_variant_new("(s)", g_chain_name);
130 message = stc_ipt_dbus_invoke_method(
131 STC_IPT_DBUS_SERVICE,
132 STC_IPT_DBUS_CHAIN_PATH,
133 STC_IPT_DBUS_CHAIN_INTERFACE,
134 STC_IPT_DBUS_METHOD_IP6T_REMOVE_CHAIN,
138 if (message == NULL) {
139 msg(LOG_RED "Failed to invoke dbus method" LOG_END);
143 stc_ipt_exe_cmd(CHECK_IP6TABLES);
145 g_variant_get(message, "(i)", &result);
146 msg(LOG_GREEN "Successfully remove 6 chain [%d]" LOG_END, result);
147 g_variant_unref(message);
152 static int test_stc_ipt_add_chain(MManager *mm, struct menu_data *menu)
154 int err = STC_ERROR_NONE;
156 err = __stc_ipt_add_chain();
157 if (err != STC_ERROR_NONE)
158 msg(LOG_RED "Failed to add chain" LOG_END);
160 err = __stc_ip6t_add_chain();
161 if (err != STC_ERROR_NONE)
162 msg(LOG_RED "Failed to add 6 chain" LOG_END);
167 static int test_stc_ipt_remove_chain(MManager *mm, struct menu_data *menu)
169 int err = STC_ERROR_NONE;
171 err = __stc_ipt_remove_chain();
172 if (err != STC_ERROR_NONE)
173 msg(LOG_RED "Failed to remove chain" LOG_END);
175 err = __stc_ip6t_remove_chain();
176 if (err != STC_ERROR_NONE)
177 msg(LOG_RED "Failed to remove 6 chain" LOG_END);
182 struct menu_data menu_chain[] = {
183 { "1", LOG_LIGHTMAGENTA "[Set]" LOG_END " Chain Name", NULL, NULL, g_chain_name},
184 { "a", LOG_LIGHTBLUE "[Add]" LOG_END " Chain", NULL, test_stc_ipt_add_chain, NULL},
185 { "r", LOG_LIGHTMAGENTA "[Remove]" LOG_END " Chain", NULL, test_stc_ipt_remove_chain, NULL},