* @}
*/
+/**
+ * @addtogroup CAPI_NETWORK_STC_IPTABLES_MODULE
+ * @{
+ */
+
+/**
+ * @brief Commits iptables rule.
+ * @since_tizen 5.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/firewall.common
+ * @remarks You must release @a err_str using free().
+ *
+ * @param[in] stc The stc handle
+ * @param[in] option The option of iptables rule
+ * @param[out] err_num The error number
+ * @param[out] err_str The error string
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #STC_ERROR_NONE Successful
+ * @retval #STC_ERROR_OPERATION_FAILED General error
+ * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STC_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #STC_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #STC_ERROR_NOT_SUPPORTED Not supported
+ * @retval #STC_ERROR_PERMISSION_DENIED Permission denied
+ *
+ * @see stc_initialize()
+ */
+int stc_iptables_commit(stc_h stc, const char *option,
+ int *err_num, char **err_str);
+
+/**
+* @}
+*/
+
#ifdef __cplusplus
}
#endif
Name: capi-network-stc
Summary: A Smart Traffic Control (STC) libraries in Native API
-Version: 0.0.24
+Version: 0.0.25
Release: 1
Group: Network & Connectivity/API
License: Apache-2.0
*****************************************************************************/
#define STC_DBUS_REPLY_TIMEOUT (120 * 1000)
-#define STC_MANAGER_SERVICE "net.stc"
-#define STC_MANAGER_STATS_INTERFACE STC_MANAGER_SERVICE ".statistics"
-#define STC_MANAGER_RESTRICTION_INTERFACE STC_MANAGER_SERVICE ".restriction"
-
-#define STC_MANAGER_STATS_PATH "/net/stc/statistics"
-#define STC_MANAGER_RESTRICTION_PATH "/net/stc/restriction"
-
-#define STC_MANAGER_METHOD_STATS_INIT "Init"
-#define STC_MANAGER_METHOD_STATS_GET_PER_APP_ID "Get"
-#define STC_MANAGER_METHOD_STATS_GET_ALL "GetAll"
-#define STC_MANAGER_METHOD_STATS_GET_TOTAL "Get"
-#define STC_MANAGER_METHOD_STATS_RESET "Reset"
-
-#define STC_MANAGER_METHOD_RESTRICTION_SET "Set"
-#define STC_MANAGER_METHOD_RESTRICTION_GET_STATUS "GetState"
-#define STC_MANAGER_METHOD_RESTRICTION_GET_PER_APP_ID "Get"
-#define STC_MANAGER_METHOD_RESTRICTION_GET_ALL "GetAll"
-#define STC_MANAGER_METHOD_RESTRICTION_UNSET "Unset"
-#define STC_MANAGER_METHOD_RESTRICTION_EXCLUDE "Exclude"
+#define STC_MANAGER_SERVICE "net.stc"
+#define STC_MANAGER_STATS_INTERFACE STC_MANAGER_SERVICE ".statistics"
+#define STC_MANAGER_RESTRICTION_INTERFACE STC_MANAGER_SERVICE ".restriction"
+#define STC_MANAGER_INTERFACE STC_MANAGER_SERVICE ".manager"
+
+#define STC_MANAGER_STATS_PATH "/net/stc/statistics"
+#define STC_MANAGER_RESTRICTION_PATH "/net/stc/restriction"
+#define STC_MANAGER_PATH "/net/stc/manager"
+
+#define STC_MANAGER_METHOD_STATS_INIT "Init"
+#define STC_MANAGER_METHOD_STATS_GET_PER_APP_ID "Get"
+#define STC_MANAGER_METHOD_STATS_GET_ALL "GetAll"
+#define STC_MANAGER_METHOD_STATS_GET_TOTAL "Get"
+#define STC_MANAGER_METHOD_STATS_RESET "Reset"
+
+#define STC_MANAGER_METHOD_RESTRICTION_SET "Set"
+#define STC_MANAGER_METHOD_RESTRICTION_GET_STATUS "GetState"
+#define STC_MANAGER_METHOD_RESTRICTION_GET_PER_APP_ID "Get"
+#define STC_MANAGER_METHOD_RESTRICTION_GET_ALL "GetAll"
+#define STC_MANAGER_METHOD_RESTRICTION_UNSET "Unset"
+#define STC_MANAGER_METHOD_RESTRICTION_EXCLUDE "Exclude"
+
+#define STC_MANAGER_METHOD_IPTABLES_COMMIT "CommitIptables"
#define STC_DEBUG_GDBUS_VARIANT(str, parameters) \
do { \
*****************************************************************************/
//LCOV_EXCL_START
+stc_error_e _stc_iptables_commit(const char *option,
+ int *err_num, char **err_str)
+{
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+ stc_error_e error = STC_ERROR_NONE;
+ int result = 0;
+ int errnum = 0;
+ char *errstr = NULL;
+
+ params = g_variant_new("(s)", option);
+
+ message = _stc_dbus_invoke_method(
+ STC_MANAGER_SERVICE,
+ STC_MANAGER_PATH,
+ STC_MANAGER_INTERFACE,
+ STC_MANAGER_METHOD_IPTABLES_COMMIT,
+ params,
+ &error);
+
+ STC_RETURN_VAL_IF(message == NULL,
+ error, "Failed to invoke dbus method");
+
+ g_variant_get(message, "(iis)", &result, &errnum, &errstr);
+ STC_LOGI("Commit iptables result [%d:%d:%s]", result, errnum, errstr);
+ g_variant_unref(message);
+
+ if (err_num)
+ *err_num = errnum;
+ if (err_str)
+ *err_str = g_strdup(errstr);
+
+ if (result == STC_ERROR_NONE)
+ return STC_ERROR_NONE;
+ else
+ return STC_ERROR_OPERATION_FAILED;
+}
+
EXPORT_API int stc_reset_stats(stc_h stc, stc_reset_rule_h rule)
{
int ret = STC_ERROR_NONE;
return STC_ERROR_NONE;
}
+
+EXPORT_API int stc_iptables_commit(stc_h stc, const char *option,
+ int *err_num, char **err_str)
+{
+ int ret = STC_ERROR_NONE;
+
+ CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
+
+ if (!(_stc_handle_check_validity(stc))) {
+ STC_LOGE("Invalid parameter");
+ return STC_ERROR_INVALID_PARAMETER;
+ }
+
+ if (option == NULL) {
+ STC_LOGE("Invalid parameter");
+ return STC_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _stc_iptables_commit(option, err_num, err_str);
+ if (ret != STC_ERROR_NONE) {
+ STC_LOGE("Failed to commit iptables [%s]",
+ _stc_convert_error_type_to_string(ret));
+ return ret;
+ }
+
+ return STC_ERROR_NONE;
+}
//LCOV_EXCL_STOP
restriction.c
statistics.c
firewall.c
+ manager.c
stc_menu.c
stc_test.c
)
--- /dev/null
+/*
+ * Smart Traffic Control (STC)
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * This file declares definitions, macros and structures.
+ *
+ * @file manager.c
+ * @author Tak hyunuk (hyunuk.tak@samsung.com)
+ * @version 0.1
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <assert.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <stc.h>
+#include <stc_internal.h>
+
+#include "stc_test.h"
+#include "stc_menu.h"
+
+static char g_iptables_option[MENU_DATA_SIZE] = "";
+
+extern stc_h g_stc;
+
+static int __test_stc_commit_iptables(MManager *mm, struct menu_data *menu)
+{
+ int ret = STC_ERROR_NONE;
+ int err_num = 0;
+ char *err_str = NULL;
+
+ ret = stc_iptables_commit(g_stc, g_iptables_option, &err_num, &err_str);
+
+ if (ret == STC_ERROR_NONE)
+ msg(LOG_GREEN "Success to commit iptables" LOG_END);
+ else
+ msg("Fail to commit iptables " LOG_RED "[%s:%d:%s]" LOG_END,
+ test_stc_convert_error_type_to_string(ret), err_num, err_str);
+
+ FREE(err_str);
+
+ return ret;
+}
+
+static struct menu_data menu_iptables_commit[] = {
+ { "1", "Option", NULL, NULL, g_iptables_option},
+ { "c", LOG_LIGHTMAGENTA "[Commit]" LOG_END, NULL, __test_stc_commit_iptables, NULL},
+ { NULL, NULL, },
+};
+
+struct menu_data menu_iptables[] = {
+ { "1", LOG_LIGHTBLUE "[Commit]" LOG_END " iptables", menu_iptables_commit, NULL, NULL},
+ { "2", LOG_LIGHTMAGENTA "[Stop]" LOG_END " manager", NULL, NULL, NULL},
+ { NULL, NULL, },
+};
--- /dev/null
+/*
+ * Smart Traffic Control (STC)
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * This file declares definitions, macros and structures.
+ *
+ * @file manager.h
+ * @author Tak hyunuk (hyunuk.tak@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef __TEST_STC_MANAGER_H__
+#define __TEST_STC_MANAGER_H__
+
+/*****************************************************************************
+ * Local Functions Definition
+ *****************************************************************************/
+
+#endif /** __TEST_STC_MANAGER_H__ */
#include "statistics.h"
#include "restriction.h"
#include "firewall.h"
+#include "manager.h"
#define STC_APP_ID_LEN 128
#define STC_IFNAME_LEN 16
extern struct menu_data menu_statistics[];
extern struct menu_data menu_restriction[];
extern struct menu_data menu_firewall[];
+extern struct menu_data menu_iptables[];
stc_h g_stc = NULL;
{ "1", LOG_LIGHTBLUE "[Statistics]" LOG_END, menu_statistics, NULL, NULL},
{ "2", LOG_LIGHTMAGENTA "[Restriction]" LOG_END, menu_restriction, NULL, NULL},
{ "3", LOG_LIGHTMAGENTA "[Firewall]" LOG_END, menu_firewall, NULL, NULL},
+ { "4", LOG_LIGHTMAGENTA "[Iptables]" LOG_END, menu_iptables, NULL, NULL},
{ NULL, NULL, },
};