Modified ip type to be properly monitored 72/169672/1
authorhyunuktak <hyunuk.tak@samsung.com>
Thu, 8 Feb 2018 07:29:17 +0000 (16:29 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Thu, 8 Feb 2018 07:29:21 +0000 (16:29 +0900)
Change-Id: Ib08671b5c73a61418c6ad1643799f01efe97916b
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
packaging/stc-manager.spec
src/helper/helper-iptables.c
src/helper/helper-iptables.h
src/helper/helper-nfacct-rule.c
src/helper/helper-nfacct-rule.h

index 40a18d8..98a493a 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.49
+Version:    0.0.50
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
index 06b9378..81cab4a 100755 (executable)
@@ -96,7 +96,7 @@ static int __iptables_rule_add(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully Add Rule [%d]", result);
+       STC_LOGD("Successfully Add Rule [%d:%s]", result, rule->nfacct_name);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -128,7 +128,7 @@ static int __iptables_rule_remove(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully Remove Rule [%d]", result);
+       STC_LOGD("Successfully Remove Rule [%d:%s]", result, rule->nfacct_name);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -160,7 +160,7 @@ static int __ip6tables_rule_add(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully Add 6 Rule [%d]", result);
+       STC_LOGD("Successfully Add 6 Rule [%d:%s]", result, rule->nfacct_name);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -192,7 +192,7 @@ static int __ip6tables_rule_remove(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully Remove 6 Rule [%d]", result);
+       STC_LOGD("Successfully Remove 6 Rule [%d:%s]", result, rule->nfacct_name);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -217,7 +217,7 @@ static int __iptables_add_chain(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully added ipv4 chain [%d]", result);
+       STC_LOGD("Successfully added ipv4 chain [%d:%s]", result, chain);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -242,7 +242,7 @@ static int __ip6tables_add_chain(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully added ipv6 chain [%d]", result);
+       STC_LOGD("Successfully added ipv6 chain [%d:%s]", result, chain);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -267,7 +267,7 @@ static int __iptables_remove_chain(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully removed ipv4 chain [%d]", result);
+       STC_LOGD("Successfully removed ipv4 chain [%d:%s]", result, chain);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -292,7 +292,7 @@ static int __ip6tables_remove_chain(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully removed ipv6 chain [%d]", result);
+       STC_LOGD("Successfully removed ipv6 chain [%d:%s]", result, chain);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -317,7 +317,7 @@ static int __iptables_flush_chain(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully flushed ipv4 chain [%d]", result);
+       STC_LOGD("Successfully flushed ipv4 chain [%d:%s]", result, chain);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -342,7 +342,7 @@ static int __ip6tables_flush_chain(GDBusConnection *connection,
        }
 
        g_variant_get(message, "(i)", &result);
-       STC_LOGD("Successfully flushed ipv6 chain [%d]", result);
+       STC_LOGD("Successfully flushed ipv6 chain [%d:%s]", result, chain);
        g_variant_unref(message);
 
        return STC_ERROR_NONE;
@@ -358,7 +358,7 @@ static int __iptables_add_chain_jump_rule(const char *chain,
        iptables_rule.target = g_strdup(target);
        iptables_rule.chain = g_strdup(chain);
 
-       ret = iptables_add(&iptables_rule);
+       ret = iptables_add(&iptables_rule, IP_TYPE_IPV4_IPV6);
 
        g_free(iptables_rule.target);
        g_free(iptables_rule.chain);
@@ -366,7 +366,7 @@ static int __iptables_add_chain_jump_rule(const char *chain,
        return ret;
 }
 
-stc_error_e iptables_add(iptables_rule_s *rule)
+stc_error_e iptables_add(iptables_rule_s *rule, iptables_ip_type_e iptype)
 {
        stc_error_e ret = STC_ERROR_NONE;
        stc_s *stc = stc_get_manager();
@@ -374,16 +374,22 @@ stc_error_e iptables_add(iptables_rule_s *rule)
        if (!stc || !stc->connection)
                return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
 
-       ret = __iptables_rule_add(stc->connection, rule);
-       if (ret != STC_ERROR_NONE)
-               goto done; //LCOV_EXCL_LINE
+       if (iptype == IP_TYPE_IPV4 ||
+               iptype == IP_TYPE_IPV4_IPV6) {
+               ret = __iptables_rule_add(stc->connection, rule);
+               if (ret != STC_ERROR_NONE)
+                       goto done; //LCOV_EXCL_LINE
+       }
+
+       if (iptype == IP_TYPE_IPV6 ||
+               iptype == IP_TYPE_IPV4_IPV6)
+               ret = __ip6tables_rule_add(stc->connection, rule);
 
-       ret = __ip6tables_rule_add(stc->connection, rule);
 done:
        return ret;
 }
 
-stc_error_e iptables_remove(iptables_rule_s *rule)
+stc_error_e iptables_remove(iptables_rule_s *rule, iptables_ip_type_e iptype)
 {
        stc_error_e ret = STC_ERROR_NONE;
        stc_s *stc = stc_get_manager();
@@ -391,11 +397,17 @@ stc_error_e iptables_remove(iptables_rule_s *rule)
        if (!stc || !stc->connection)
                return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
 
-       ret = __iptables_rule_remove(stc->connection, rule);
-       if (ret != STC_ERROR_NONE)
-               goto done; //LCOV_EXCL_LINE
+       if (iptype == IP_TYPE_IPV4 ||
+               iptype == IP_TYPE_IPV4_IPV6) {
+               ret = __iptables_rule_remove(stc->connection, rule);
+               if (ret != STC_ERROR_NONE)
+                       goto done; //LCOV_EXCL_LINE
+       }
+
+       if (iptype == IP_TYPE_IPV6 ||
+               iptype == IP_TYPE_IPV4_IPV6)
+               ret = __ip6tables_rule_remove(stc->connection, rule);
 
-       ret = __ip6tables_rule_remove(stc->connection, rule);
 done:
        return ret;
 }
index bdfedb1..b73e29f 100755 (executable)
@@ -29,6 +29,14 @@ typedef enum {
        IPTABLES_DIRECTION_OUT
 } iptables_rule_direction_e;
 
+typedef enum {
+       IP_TYPE_UNKNOWN,
+       IP_TYPE_IPV4,
+       IP_TYPE_IPV6,
+       IP_TYPE_IPV4_IPV6,
+       IP_TYPE_LAST_ELEM
+} iptables_ip_type_e;
+
 typedef struct {
        char *chain;
        char *ifname;
@@ -38,8 +46,8 @@ typedef struct {
        uint32_t classid;
 } iptables_rule_s;
 
-stc_error_e iptables_add(iptables_rule_s *rule);
-stc_error_e iptables_remove(iptables_rule_s *rule);
+stc_error_e iptables_add(iptables_rule_s *rule, iptables_ip_type_e iptype);
+stc_error_e iptables_remove(iptables_rule_s *rule, iptables_ip_type_e iptype);
 stc_error_e iptables_flush_chains(void);
 stc_error_e iptables_init(void);
 stc_error_e iptables_deinit(void);
index 8f5dfee..5944967 100755 (executable)
@@ -444,6 +444,7 @@ static char *choose_iftype_name(nfacct_rule_s *rule)
 static stc_error_e exec_iptables_cmd(nfacct_rule_s *rule)
 {
        stc_error_e ret = STC_ERROR_NONE;
+       iptables_ip_type_e iptype;
        iptables_rule_s iptables_rule;
        memset(&iptables_rule, 0, sizeof(iptables_rule_s));
 
@@ -453,13 +454,14 @@ static stc_error_e exec_iptables_cmd(nfacct_rule_s *rule)
        iptables_rule.chain = g_strdup(get_iptables_chain(rule->iotype));
        iptables_rule.classid = rule->classid;
        iptables_rule.direction = (rule->iotype & NFACCT_COUNTER_IN) ? 0 : 1;
+       iptype = (iptables_ip_type_e)rule->iptype;
 
        if (rule->action == NFACCT_ACTION_DELETE) {
                /* delete interface rule */
-               ret = iptables_remove(&iptables_rule);
+               ret = iptables_remove(&iptables_rule, iptype);
        } else {
                /* add interface rule */
-               ret = iptables_add(&iptables_rule);
+               ret = iptables_add(&iptables_rule, iptype);
        }
 
        g_free(iptables_rule.nfacct_name);
index 88b33ad..472cf29 100755 (executable)
@@ -62,6 +62,7 @@ typedef enum {
        NFACCT_TYPE_UNKNOWN,
        NFACCT_TYPE_IPV4,
        NFACCT_TYPE_IPV6,
+       NFACCT_TYPE_IPV4_IPV6,
        NFACCT_TYPE_LAST_ELEM
 } nfacct_rule_iptype;