Added CAPI to add/remove route table 88/124488/1 accepted/tizen/unified/20170419.165216 submit/tizen/20170419.041337
authortaesub kim <taesub.kim@samsung.com>
Tue, 11 Apr 2017 10:49:32 +0000 (19:49 +0900)
committertaesub kim <taesub.kim@samsung.com>
Tue, 11 Apr 2017 10:49:37 +0000 (19:49 +0900)
Change-Id: Ie1236e2fe666b8b684b0c8fb24171deb4e56a8b5
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
NOTICE [changed mode: 0644->0755]
include/common/network-cm-intf.h
src/network-cm-intf.c

diff --git a/NOTICE b/NOTICE
old mode 100644 (file)
new mode 100755 (executable)
index 23ad969..d3b7219 100755 (executable)
@@ -1136,6 +1136,28 @@ int net_remove_route(const char *ip_addr, const char *interface, int address_fam
 /**
  * \brief      This API is only for Connection CAPI. Don't use this.
  *
+ * \param[in]  ip_addr     ip address to route.
+ * \param[in]  interface   interface name.
+ * \param[in]  address_family address family of ip address.
+ * \param[in]  gateway     The gateway address.
+ *
+ ******************************************************************************************/
+int net_add_route_entry(const char *ip_addr, const char *interface, int address_family, const char *gateway);
+
+/**
+ * \brief      This API is only for Connection CAPI. Don't use this.
+ *
+ * \param[in]  ip_addr     ip address to route.
+ * \param[in]  interface   interface name.
+ * \param[in]  address_family address family of ip address.
+ * \param[in]  gateway     The gateway address.
+ *
+ ******************************************************************************************/
+int net_remove_route_entry(const char *ip_addr, const char *interface, int address_family, const char *gateway);
+
+/**
+ * \brief      This API is only for Connection CAPI. Don't use this.
+ *
  * \param[in]  ip_addr     ipv6 address to route.
  * \param[in]  interface   interface name.
  * \param[in]  address_family address family of ip address.
index 5e88a7a..74c5570 100755 (executable)
@@ -154,6 +154,100 @@ done:
        return Error;
 }
 
+static int __net_add_route_entry(const char *ip_addr, const char *interface, int address_family, const char *gateway)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+       char dest_ip[INET6_ADDRSTRLEN] = { '\0' };
+       char netmask[INET_ADDRSTRLEN] = { '\0' };
+       char if_name[40] = { '\0' };
+       GVariant *params = NULL;
+
+       g_snprintf(dest_ip, INET6_ADDRSTRLEN, "%s", ip_addr);
+       g_snprintf(if_name, strlen(interface) + 1, "%s", interface);
+
+       if (address_family == AF_INET) {
+               g_snprintf(netmask, INET_ADDRSTRLEN, "255.255.255.255");
+               params = g_variant_new("(ssssi)", dest_ip, netmask, if_name, gateway, address_family);
+       } else {
+               params = g_variant_new("(ssssi)", dest_ip, netmask, if_name, gateway, address_family);
+       }
+
+       message = _net_invoke_dbus_method(NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
+                       NETCONFIG_NETWORK_INTERFACE, "AddRoute", params, &Error);
+
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to add route\n");
+               goto done;
+       }
+
+       /** Check Reply */
+       gboolean add_result = FALSE;
+
+       g_variant_get(message, "(b)", &add_result);
+       NETWORK_LOG(NETWORK_HIGH, "Add route, result : %d\n", add_result);
+
+       if (add_result)
+               Error = NET_ERR_NONE;
+       else
+               Error = NET_ERR_UNKNOWN;
+
+       g_variant_unref(message);
+
+done:
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+static int __net_remove_route_entry(const char *ip_addr, const char *interface, int address_family, const char *gateway)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+       char dest_ip[INET6_ADDRSTRLEN] = { '\0' };
+       char netmask[INET_ADDRSTRLEN] = { '\0' };
+       char if_name[40] = { '\0' };
+       GVariant *params = NULL;
+
+       g_snprintf(dest_ip, INET6_ADDRSTRLEN, "%s", ip_addr);
+       g_snprintf(if_name, strlen(interface) + 1, "%s", interface);
+
+       if (address_family == AF_INET) {
+               g_snprintf(netmask, INET_ADDRSTRLEN, "255.255.255.255");
+               params = g_variant_new("(ssssi)", dest_ip, netmask, if_name, gateway, address_family);
+       } else {
+               params = g_variant_new("(ssssi)", dest_ip, netmask, if_name, gateway, address_family);
+       }
+
+       message = _net_invoke_dbus_method(NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
+                       NETCONFIG_NETWORK_INTERFACE, "RemoveRoute", params, &Error);
+
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to remove route\n");
+               goto done;
+       }
+
+       /** Check Reply */
+       gboolean remove_result = FALSE;
+
+       g_variant_get(message, "(b)", &remove_result);
+       NETWORK_LOG(NETWORK_HIGH, "Remove route, result : %d\n", remove_result);
+
+       if (remove_result)
+               Error = NET_ERR_NONE;
+       else
+               Error = NET_ERR_UNKNOWN;
+
+       g_variant_unref(message);
+
+done:
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 static int __net_add_route_ipv6(const char *ip_addr, const char *interface, int address_family, const char *gateway)
 {
        __NETWORK_FUNC_ENTER__;
@@ -1016,6 +1110,50 @@ EXPORT_API int net_remove_route(const char *ip_addr, const char *interface, int
        return Error;
 }
 
+EXPORT_API int net_add_route_entry(const char *ip_addr, const char *interface, int address_family, const char *gateway)
+{
+       net_err_t Error = NET_ERR_NONE;
+
+       if (ip_addr == NULL || strlen(ip_addr) < 7 || interface == NULL || gateway == NULL || strlen(interface) == 0) {
+               NETWORK_LOG(NETWORK_ERROR, "Invalid parameter");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
+       Error = __net_add_route_entry(ip_addr, interface, address_family, gateway);
+       if (Error != NET_ERR_NONE) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to add route. Error [%s]",
+                               _net_print_error(Error));
+
+               return Error;
+       }
+
+       return Error;
+}
+
+EXPORT_API int net_remove_route_entry(const char *ip_addr, const char *interface, int address_family, const char *gateway)
+{
+       net_err_t Error = NET_ERR_NONE;
+
+       if (ip_addr == NULL || strlen(ip_addr) < 7 || interface == NULL || gateway == NULL || strlen(interface) == 0) {
+               NETWORK_LOG(NETWORK_ERROR, "Invalid parameter\n");
+
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
+       Error = __net_remove_route_entry(ip_addr, interface, address_family, gateway);
+       if (Error != NET_ERR_NONE) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to remove route. Error [%s]\n",
+                               _net_print_error(Error));
+
+               return Error;
+       }
+
+       return Error;
+}
+
+
 EXPORT_API int net_add_route_ipv6(const char *ip_addr, const char *interface, int address_family, const char *gateway)
 {
        net_err_t Error = NET_ERR_NONE;