g_variant_new_uint32(rule->d_ip2.s_addr));
}
+static void __add_rule_reply(
+ GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ GDBusConnection *conn = NULL;
+ GVariant *dbus_data = NULL;
+ GError *dbus_error = NULL;
+ int result = 0;
+ char *nfacct_name = user_data;
+
+ conn = G_DBUS_CONNECTION(source_object);
+ dbus_data = g_dbus_connection_call_finish(conn, res, &dbus_error);
+ if (dbus_error != NULL) {
+ STC_LOGE("Dbus reply error [%s]", dbus_error->message);
+ g_error_free(dbus_error);
+ } else {
+ g_variant_get(dbus_data, "(i)", &result);
+ STC_LOGI("Added rule [%d:%s]", result, nfacct_name);
+ }
+
+ g_free(nfacct_name);
+}
+
+static void __remove_rule_reply(
+ GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ GDBusConnection *conn = NULL;
+ GVariant *dbus_data = NULL;
+ GError *dbus_error = NULL;
+ int result = 0;
+ char *nfacct_name = user_data;
+
+ conn = G_DBUS_CONNECTION(source_object);
+ dbus_data = g_dbus_connection_call_finish(conn, res, &dbus_error);
+ if (dbus_error != NULL) {
+ STC_LOGE("Dbus reply error [%s]", dbus_error->message);
+ g_error_free(dbus_error);
+ } else {
+ g_variant_get(dbus_data, "(i)", &result);
+ STC_LOGI("Removed rule [%d:%s]", result, nfacct_name);
+ }
+
+ g_free(nfacct_name);
+}
+
static int __iptables_rule_add(GDBusConnection *connection,
iptables_rule_s *rule)
{
- int result = 0;
+ int result = STC_ERROR_NONE;
GVariantBuilder *builder = NULL;
GVariant *params = NULL;
- GVariant *message = NULL;
+ char *nfacct_name = NULL;
builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
__add_rule_info_to_builder(builder, rule);
params = g_variant_new("(a{sv})", builder);
g_variant_builder_unref(builder);
- message = stc_manager_gdbus_call_sync(connection,
+ nfacct_name = g_strdup_printf("4:%s", rule->nfacct_name);
+
+ result = stc_manager_gdbus_call_async(connection,
STC_IPTABLES_DBUS_SERVICE,
STC_IPTABLES_DBUS_RULE_PATH,
STC_IPTABLES_DBUS_RULE_INTERFACE,
STC_IPTABLES_DBUS_METHOD_IPT_ADD_RULE,
- params);
+ params,
+ __add_rule_reply,
+ nfacct_name);
- if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
- return STC_ERROR_FAIL; //LCOV_EXCL_LINE
+ if (result != STC_ERROR_NONE) {
+ STC_LOGE("Failed to invoke dbus method async");
+ g_free(nfacct_name);
}
- g_variant_get(message, "(i)", &result);
- if (STC_DEBUG_LOG)
- STC_LOGD("Successfully Add Rule [%d:%s]", result, rule->nfacct_name);
- g_variant_unref(message);
-
- return STC_ERROR_NONE;
+ return result;
}
static int __iptables_rule_remove(GDBusConnection *connection,
iptables_rule_s *rule)
{
- int result = 0;
+ int result = STC_ERROR_NONE;
GVariantBuilder *builder = NULL;
GVariant *params = NULL;
- GVariant *message = NULL;
+ char *nfacct_name = NULL;
builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
__add_rule_info_to_builder(builder, rule);
params = g_variant_new("(a{sv})", builder);
g_variant_builder_unref(builder);
- message = stc_manager_gdbus_call_sync(connection,
+ nfacct_name = g_strdup_printf("4:%s", rule->nfacct_name);
+
+ result = stc_manager_gdbus_call_async(connection,
STC_IPTABLES_DBUS_SERVICE,
STC_IPTABLES_DBUS_RULE_PATH,
STC_IPTABLES_DBUS_RULE_INTERFACE,
STC_IPTABLES_DBUS_METHOD_IPT_REMOVE_RULE,
- params);
+ params,
+ __remove_rule_reply,
+ nfacct_name);
- if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
- return STC_ERROR_FAIL; //LCOV_EXCL_LINE
+ if (result != STC_ERROR_NONE) {
+ STC_LOGE("Failed to invoke dbus method async");
+ g_free(nfacct_name);
}
- g_variant_get(message, "(i)", &result);
- if (STC_DEBUG_LOG)
- STC_LOGD("Successfully Remove Rule [%d:%s]", result, rule->nfacct_name);
- g_variant_unref(message);
-
- return STC_ERROR_NONE;
+ return result;
}
static int __ip6tables_rule_add(GDBusConnection *connection,
iptables_rule_s *rule)
{
- int result = 0;
+ int result = STC_ERROR_NONE;
GVariantBuilder *builder = NULL;
GVariant *params = NULL;
- GVariant *message = NULL;
+ char *nfacct_name = NULL;
builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
__add_rule_info_to_builder(builder, rule);
params = g_variant_new("(a{sv})", builder);
g_variant_builder_unref(builder);
- message = stc_manager_gdbus_call_sync(connection,
+ nfacct_name = g_strdup_printf("6:%s", rule->nfacct_name);
+
+ result = stc_manager_gdbus_call_async(connection,
STC_IPTABLES_DBUS_SERVICE,
STC_IPTABLES_DBUS_RULE_PATH,
STC_IPTABLES_DBUS_RULE_INTERFACE,
STC_IPTABLES_DBUS_METHOD_IP6T_ADD_RULE,
- params);
+ params,
+ __add_rule_reply,
+ nfacct_name);
- if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
- return STC_ERROR_FAIL; //LCOV_EXCL_LINE
+ if (result != STC_ERROR_NONE) {
+ STC_LOGE("Failed to invoke dbus method async");
+ g_free(nfacct_name);
}
- g_variant_get(message, "(i)", &result);
- if (STC_DEBUG_LOG)
- STC_LOGD("Successfully Add 6 Rule [%d:%s]", result, rule->nfacct_name);
- g_variant_unref(message);
-
- return STC_ERROR_NONE;
+ return result;
}
static int __ip6tables_rule_remove(GDBusConnection *connection,
iptables_rule_s *rule)
{
- int result = 0;
+ int result = STC_ERROR_NONE;
GVariantBuilder *builder = NULL;
GVariant *params = NULL;
- GVariant *message = NULL;
+ char *nfacct_name = NULL;
builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
__add_rule_info_to_builder(builder, rule);
params = g_variant_new("(a{sv})", builder);
g_variant_builder_unref(builder);
- message = stc_manager_gdbus_call_sync(connection,
+ nfacct_name = g_strdup_printf("6:%s", rule->nfacct_name);
+
+ result = stc_manager_gdbus_call_async(connection,
STC_IPTABLES_DBUS_SERVICE,
STC_IPTABLES_DBUS_RULE_PATH,
STC_IPTABLES_DBUS_RULE_INTERFACE,
STC_IPTABLES_DBUS_METHOD_IP6T_REMOVE_RULE,
- params);
+ params,
+ __remove_rule_reply,
+ nfacct_name);
- if (message == NULL) {
- STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
- return STC_ERROR_FAIL; //LCOV_EXCL_LINE
+ if (result != STC_ERROR_NONE) {
+ STC_LOGE("Failed to invoke dbus method async");
+ g_free(nfacct_name);
}
- g_variant_get(message, "(i)", &result);
- if (STC_DEBUG_LOG)
- STC_LOGD("Successfully Remove 6 Rule [%d:%s]", result, rule->nfacct_name);
- g_variant_unref(message);
-
- return STC_ERROR_NONE;
+ return result;
}
static int __iptables_add_chain(GDBusConnection *connection,