Added a new API to commit ip6tables 15/178315/1 accepted/tizen/unified/20180510.134340 submit/tizen/20180510.023945
authorhyunuktak <hyunuk.tak@samsung.com>
Wed, 9 May 2018 08:34:40 +0000 (17:34 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Wed, 9 May 2018 08:34:46 +0000 (17:34 +0900)
Change-Id: Id2ec0e0c4e9b59479a520b194729a5078232100d
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
include/stc_internal.h
packaging/capi-network-stc.spec
src/internal/include/stc-dbus.h
src/stc-manager.c
test/manager.c

index eadc119..31930ce 100755 (executable)
@@ -2698,6 +2698,33 @@ int stc_iptables_commit(stc_h stc, const char *option,
                        int *err_num, char **err_str);
 
 /**
+ * @brief Commits ip6tables 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_ip6tables_commit(stc_h stc, const char *option,
+                       int *err_num, char **err_str);
+
+/**
 * @}
 */
 
index f1056d3..0a7564d 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-network-stc
 Summary:    A Smart Traffic Control (STC) libraries in Native API
-Version:    0.0.28
+Version:    0.0.29
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index b73baf4..582c5d9 100755 (executable)
@@ -74,6 +74,7 @@ extern "C" {
 #define STC_MANAGER_METHOD_RESTRICTION_UNSET            "Unset"
 
 #define STC_MANAGER_METHOD_IPTABLES_COMMIT              "CommitIptables"
+#define STC_MANAGER_METHOD_IP6TABLES_COMMIT             "CommitIp6tables"
 
 #define STC_DEBUG_GDBUS_VARIANT(str, parameters) \
        do { \
index cf09e88..d8ea4fa 100755 (executable)
@@ -103,6 +103,44 @@ stc_error_e _stc_iptables_commit(const char *option,
                return STC_ERROR_OPERATION_FAILED;
 }
 
+stc_error_e _stc_ip6tables_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_IP6TABLES_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 ip6tables 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;
@@ -502,4 +540,31 @@ EXPORT_API int stc_iptables_commit(stc_h stc, const char *option,
 
        return STC_ERROR_NONE;
 }
+
+EXPORT_API int stc_ip6tables_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_ip6tables_commit(option, err_num, err_str);
+       if (ret != STC_ERROR_NONE) {
+               STC_LOGE("Failed to commit ip6tables [%s]",
+                       _stc_convert_error_type_to_string(ret));
+               return ret;
+       }
+
+       return STC_ERROR_NONE;
+}
 //LCOV_EXCL_STOP
index 01ccc00..1ceff3b 100755 (executable)
@@ -65,14 +65,34 @@ static int __test_stc_commit_iptables(MManager *mm, struct menu_data *menu)
        return ret;
 }
 
+static int __test_stc_commit_ip6tables(MManager *mm, struct menu_data *menu)
+{
+       int ret = STC_ERROR_NONE;
+       int err_num = 0;
+       char *err_str = NULL;
+
+       ret = stc_ip6tables_commit(g_stc, g_iptables_option, &err_num, &err_str);
+
+       if (ret == STC_ERROR_NONE)
+               msg(LOG_GREEN "Success to commit ip6tables" LOG_END);
+       else
+               msg("Fail to commit ip6tables " 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},
+       { "2", LOG_LIGHTMAGENTA "[Commit]" LOG_END "iptables", NULL, __test_stc_commit_iptables, NULL},
+       { "3", LOG_LIGHTMAGENTA "[Commit]" LOG_END "ip6tables", NULL, __test_stc_commit_ip6tables, NULL},
        { NULL, NULL, },
 };
 
 struct menu_data menu_iptables[] = {
-       { "1", LOG_LIGHTBLUE "[Commit]" LOG_END " iptables", menu_iptables_commit, NULL, NULL},
+       { "1", LOG_LIGHTBLUE "[Commit]" LOG_END " iptable rule", menu_iptables_commit, NULL, NULL},
        { "2", LOG_LIGHTMAGENTA "[Stop]" LOG_END " manager", NULL, NULL, NULL},
        { NULL, NULL, },
 };