From 41ba3c0628855cce5ece93cd25649ca5672a821d Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Tue, 7 Nov 2017 18:40:27 +0900 Subject: [PATCH] add new dbus method for preferred Ipv6 address Change-Id: I95b3ee6fa3d6b462b6ca64fcd1ba872d8e9bb356 --- include/neterror.h | 1 + interfaces/netconfig-iface-network-state.xml | 4 + resources/etc/dbus-1/system.d/net-config.conf | 1 + src/neterror.c | 7 ++ src/network-state.c | 84 +++++++++++++++++++ 5 files changed, 97 insertions(+) diff --git a/include/neterror.h b/include/neterror.h index 59f9392..b492797 100755 --- a/include/neterror.h +++ b/include/neterror.h @@ -70,6 +70,7 @@ void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context void netconfig_error_fail_get_sim_auth_delay(GDBusMethodInvocation *context); void netconfig_error_fail_save_congifuration(GDBusMethodInvocation *context); void netconfig_error_fail_ethernet_cable_state(GDBusMethodInvocation *context); +void netconfig_error_fail_preferred_ipv6_address(GDBusMethodInvocation *context); void netconfig_error_dbus_method_return(GDBusMethodInvocation *context, netconfig_error_e error, const gchar *message); void netconfig_error_init(void); diff --git a/interfaces/netconfig-iface-network-state.xml b/interfaces/netconfig-iface-network-state.xml index e0fa110..f0000a3 100755 --- a/interfaces/netconfig-iface-network-state.xml +++ b/interfaces/netconfig-iface-network-state.xml @@ -41,5 +41,9 @@ + + + + diff --git a/resources/etc/dbus-1/system.d/net-config.conf b/resources/etc/dbus-1/system.d/net-config.conf index f4e34c9..10810c4 100755 --- a/resources/etc/dbus-1/system.d/net-config.conf +++ b/resources/etc/dbus-1/system.d/net-config.conf @@ -24,6 +24,7 @@ + diff --git a/src/neterror.c b/src/neterror.c index 24167a0..62998ab 100755 --- a/src/neterror.c +++ b/src/neterror.c @@ -157,6 +157,13 @@ void netconfig_error_fail_ethernet_cable_state(GDBusMethodInvocation *context) NETCONFIG_ERROR_INTERFACE".FailGetEthernetCableState"); } +void netconfig_error_fail_preferred_ipv6_address(GDBusMethodInvocation *context) +{ + g_dbus_method_invocation_return_error(context, netconfig_error_quark(), + NETCONFIG_ERROR_INTERNAL, + NETCONFIG_ERROR_INTERFACE".FailGetPreferredIpv6Address"); +} + #include void netconfig_error_dbus_method_return(GDBusMethodInvocation *context, netconfig_error_e error, const gchar *message) { diff --git a/src/network-state.c b/src/network-state.c index 0fb0280..3e616c4 100755 --- a/src/network-state.c +++ b/src/network-state.c @@ -504,6 +504,72 @@ done: return; } +static char *__netconfig_get_preferred_ipv6_address(char *profile) +{ + GVariant *message = NULL, *variant = NULL, *next = NULL; + GVariantIter *iter = NULL, *sub_iter = NULL, *service = NULL; + gchar *obj_path; + gchar *key = NULL; + gchar *sub_key = NULL; + gchar *preferred_address6 = NULL; + gboolean found_profile = 0; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetServices", NULL); + if (message == NULL) { + ERR("Failed to get service informations"); + goto done; + } + + g_variant_get(message, "(a(oa{sv}))", &service); + if (service == NULL) { + ERR("Failed to get services iter"); + goto done; + } + + while (g_variant_iter_loop(service, "(oa{sv})", &obj_path, &iter)) { + if (g_strcmp0(obj_path, profile) == 0) { + g_free(obj_path); + found_profile = 1; + break; + } + } + + if (iter == NULL || found_profile == 0) { + ERR("Profile %s doesn't exist", profile); + goto done; + } + + while (g_variant_iter_loop(iter, "{sv}", &key, &next)) { + const gchar *value = NULL; + if (g_strcmp0(key, "IPv6") == 0) { + g_variant_get(next, "a{sv}", &sub_iter); + if (sub_iter == NULL) + continue; + while (g_variant_iter_loop(sub_iter, "{sv}", &sub_key, &variant)) { + if (g_strcmp0(sub_key, "Address") == 0) { + value = g_variant_get_string(variant, NULL); + preferred_address6 = g_strdup(value); + } + } + g_variant_iter_free(sub_iter); + } + } + +done: + if (message) + g_variant_unref(message); + + if (iter) + g_variant_iter_free(iter); + + if (service) + g_variant_iter_free(service); + + return preferred_address6; +} + static void __netconfig_adjust_tcp_buffer_size(void) { int fdr = 0, fdw = 0; @@ -1301,7 +1367,23 @@ gboolean handle_get_metered_info(Network *object, DBG("Default metered state [%s]", state ? "TRUE" : "FALSE"); network_complete_get_metered_info(object, context, state); + return TRUE; +} + +gboolean handle_preferred_ipv6_address(Network *object, + GDBusMethodInvocation *context, gchar *profile) +{ + char *address = NULL; + + address = __netconfig_get_preferred_ipv6_address(profile); + if (address == NULL) { + DBG("Failed to get preferred IPv6 address"); + netconfig_error_fail_preferred_ipv6_address(context); + return FALSE; + } + DBG("Successfully get preferred IPv6 address[%s]", address); + network_complete_preferred_ipv6_address(object, context, address); return TRUE; } @@ -1331,6 +1413,8 @@ void state_object_create_and_init(void) G_CALLBACK(handle_check_internet_privilege), NULL); g_signal_connect(netconfigstate, "handle-ethernet-cable-state", G_CALLBACK(handle_ethernet_cable_state), NULL); + g_signal_connect(netconfigstate, "handle-preferred-ipv6-address", + G_CALLBACK(handle_preferred_ipv6_address), NULL); g_signal_connect(netconfigstate, "handle-remove-route", G_CALLBACK(handle_remove_route), NULL); g_signal_connect(netconfigstate, "handle-launch-mdns", -- 2.34.1