Below methods are added on dbus interface.
i) IptFlushChain
ii) Ip6tFlushChain
Change-Id: I29361263c8d1badb8785524b6b55ba4c5c28f4a7
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
const gchar *chain,
void *user_data);
+gboolean handle_iptables_flush_chain(StcChain *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *chain,
+ void *user_data);
+
/* ip6tables */
gboolean handle_ip6tables_add_rule(StcRule *object,
GDBusMethodInvocation *invocation,
const gchar *chain,
void *user_data);
+gboolean handle_ip6tables_flush_chain(StcChain *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *chain,
+ void *user_data);
+
#endif /* __STC_IPTABLES_UTIL_H__ */
<arg type='s' name='chain' direction='in'/>
<arg type='i' name='error_code' direction='out'/>
</method>
+ <method name='IptFlushChain'>
+ <arg type='s' name='chain' direction='in'/>
+ <arg type='i' name='error_code' direction='out'/>
+ </method>
<method name='Ip6tAddChain'>
<arg type='s' name='chain' direction='in'/>
<arg type='i' name='error_code' direction='out'/>
<arg type='s' name='chain' direction='in'/>
<arg type='i' name='error_code' direction='out'/>
</method>
+ <method name='Ip6tFlushChain'>
+ <arg type='s' name='chain' direction='in'/>
+ <arg type='i' name='error_code' direction='out'/>
+ </method>
</interface>
</node>
Name: stc-iptables
Summary: STC(Smart Traffic Control) iptables
-Version: 0.0.3
+Version: 0.0.4
Release: 0
Group: Network & Connectivity/Other
License: GPL-2.0+
STC_LOGI("Success removing chain");
return STC_ERROR_NONE;
}
+
+int ip6tables_flush_chain(const char *chain)
+{
+ ip6t_handle_t *handle;
+
+ handle = ip6tc_init(IP6TC_TABLE);
+ if (handle == NULL) {
+ STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno));
+ return STC_ERROR_OPERATION_FAILED;
+ }
+
+ if (!ip6tc_is_chain(chain, handle)) {
+ STC_LOGW("chain not present");
+ ip6tc_free(handle);
+ return STC_ERROR_NONE;
+ }
+
+ if(!ip6tc_flush_entries(chain, handle)) {
+ STC_LOGE("Failed to flush chain [%s]", ip6tc_strerror(errno));
+ ip6tc_free(handle);
+ return STC_ERROR_OPERATION_FAILED;
+ }
+
+ if (!ip6tc_commit(handle)) {
+ STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno));
+ ip6tc_free(handle);
+ return STC_ERROR_OPERATION_FAILED;
+ }
+
+ ip6tc_free(handle);
+
+ STC_LOGI("Success removing chain");
+ return STC_ERROR_NONE;
+}
*/
int ip6tables_remove_chain(const char *chain);
+/**
+ * @desc This function flushes all ip6tables rules in chain.
+ * @return 0 on success and negative value if error.
+ */
+int ip6tables_flush_chain(const char *chain);
+
#endif /*__STC_HELPER_IP6TABLES_H__*/
STC_LOGI("Success removing chain");
return STC_ERROR_NONE;
}
+
+int iptables_flush_chain(const char *chain)
+{
+ ipt_handle_t *handle;
+
+ handle = iptc_init(IPTC_TABLE);
+ if (handle == NULL) {
+ STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno));
+ return STC_ERROR_OPERATION_FAILED;
+ }
+
+ if (!iptc_is_chain(chain, handle)) {
+ STC_LOGW("chain not present");
+ iptc_free(handle);
+ return STC_ERROR_NONE;
+ }
+
+ if (!iptc_flush_entries(chain, handle)) {
+ STC_LOGE("Failed to flush chain [%s]", iptc_strerror(errno));
+ iptc_free(handle);
+ return STC_ERROR_OPERATION_FAILED;
+ }
+
+ if (!iptc_commit(handle)) {
+ STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno));
+ iptc_free(handle);
+ return STC_ERROR_OPERATION_FAILED;
+ }
+
+ iptc_free(handle);
+
+ STC_LOGI("Success flushing chain");
+ return STC_ERROR_NONE;
+}
*/
int iptables_remove_chain(const char *chain);
+/**
+ * @desc This function flushes all iptables rules in chain.
+ * @return 0 on success and negative value if error.
+ */
+int iptables_flush_chain(const char *chain);
+
#endif /*__STC_HELPER_IPTABLES_H__*/
G_CALLBACK(handle_iptables_remove_chain),
stc_iptables);
+ g_signal_connect(chain, "handle-ipt-flush-chain",
+ G_CALLBACK(handle_iptables_flush_chain),
+ stc_iptables);
+
g_signal_connect(chain, "handle-ip6t-add-chain",
G_CALLBACK(handle_ip6tables_add_chain),
stc_iptables);
G_CALLBACK(handle_ip6tables_remove_chain),
stc_iptables);
+ g_signal_connect(chain, "handle-ip6t-flush-chain",
+ G_CALLBACK(handle_ip6tables_flush_chain),
+ stc_iptables);
+
g_dbus_object_manager_server_export(stc_iptables->obj_mgr,
G_DBUS_OBJECT_SKELETON(object));
g_object_unref(object);
return TRUE;
}
+gboolean handle_iptables_flush_chain(StcChain *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *chain,
+ void *user_data)
+{
+ __STC_LOG_FUNC_ENTER__;
+ stc_error_e ret = STC_ERROR_NONE;
+ GVariant *return_parameters = NULL;
+
+ ret = iptables_flush_chain(chain);
+ if (ret < STC_ERROR_NONE) {
+ STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+ }
+
+ return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
+
+ STC_DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_IPTABLES_DBUS_REPLY(invocation, return_parameters);
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}
+
gboolean handle_ip6tables_add_rule(StcRule *object,
GDBusMethodInvocation *invocation,
GVariant *rules,
__STC_LOG_FUNC_EXIT__;
return TRUE;
}
+
+gboolean handle_ip6tables_flush_chain(StcChain *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *chain,
+ void *user_data)
+{
+ __STC_LOG_FUNC_ENTER__;
+ stc_error_e ret = STC_ERROR_NONE;
+ GVariant *return_parameters = NULL;
+
+ ret = ip6tables_flush_chain(chain);
+ if (ret < STC_ERROR_NONE) {
+ STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+ }
+
+ return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
+
+ STC_DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_IPTABLES_DBUS_REPLY(invocation, return_parameters);
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}