[IPv6] Use DNS address offered from default network 13/183313/1 accepted/tizen/unified/20180705.081242 submit/tizen/20180704.233838
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 19 Jun 2018 05:19:23 +0000 (14:19 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 4 Jul 2018 09:18:35 +0000 (18:18 +0900)
Change-Id: I04b5f93a68f62d5925150c41918536e05a2704bb

include/mobileap_network.h
packaging/mobileap-agent.spec
src/mobileap_network.c
src/mobileap_softap.c

index 4edeadf..79b18fa 100644 (file)
@@ -35,6 +35,7 @@ typedef enum {
 char *_get_ipv6_network_interface(void);
 char *_get_ipv6_network_address(void);
 char *_get_ipv6_network_prefix(void);
+char *_get_ipv6_network_dns_address(void);
 gboolean _get_ipv6_network_state(void);
 int _open_ipv6_network(void);
 void _close_ipv6_network(void);
@@ -53,6 +54,7 @@ gboolean _remove_address(const char *if_name, char *ip);
 
 gboolean _get_network_interface_name(char **if_name);
 gboolean _get_network_gateway_address(mobile_ap_address_type_e address_type, char **ip);
+gboolean _get_network_dns_address(mobile_ap_address_type_e address_type, char **dns);
 gboolean _is_trying_network_operation(void);
 gboolean _set_masquerade(void);
 gboolean _unset_masquerade(void);
index 9331307..f1c666e 100644 (file)
@@ -1,6 +1,6 @@
 Name: mobileap-agent
 Summary: Mobile AP daemon for setting tethering environments
-Version: 1.0.122
+Version: 1.0.123
 Release: 1
 Group: System/Network
 License: Apache-2.0
index da39cf9..72d1fe1 100644 (file)
@@ -56,10 +56,11 @@ typedef struct {
        char *if_name;
        char *global_address;
        char *prefix;
+       char *dns;
        gboolean state;
 } ipv6_network_info_s;
 
-static ipv6_network_info_s ipv6_net_info = {NULL, NULL, NULL, FALSE};
+static ipv6_network_info_s ipv6_net_info = {NULL, NULL, NULL, NULL, FALSE};
 gboolean _set_ipv6_masquerade(void);
 gboolean _unset_ipv6_masquerade(void);
 #endif
@@ -756,6 +757,35 @@ gboolean _get_network_gateway_address(mobile_ap_address_type_e address_type, cha
        return TRUE;
 }
 
+gboolean _get_network_dns_address(mobile_ap_address_type_e address_type, char **dns)
+{
+       if (dns == NULL) {
+               ERR("dns is NULL\n");
+               return FALSE;
+       }
+
+       if (tethered_prof == NULL)
+               return FALSE;
+
+       int ret = 0;
+
+       connection_profile_refresh(tethered_prof);
+
+       ret = connection_profile_get_dns_address(tethered_prof, 1, address_type, dns);
+       if (ret != CONNECTION_ERROR_NONE) {
+               ERR("connection_profile_get_dns_address is failed : 0x%X\n", ret);
+               return FALSE;
+       }
+
+       if (strlen(*dns) == 0) {
+               ERR("dns is zero length\n");
+               free(*dns);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 gboolean _set_masquerade(void)
 {
        char *if_name = NULL;
@@ -1159,6 +1189,7 @@ static int __update_ipv6_network_info(void)
 {
        char *if_name = NULL;
        char *global_address = NULL;
+       char *dns = NULL;
        char prefix[INET6_ADDRSTRLEN] = {0, };
        struct sockaddr_in6 sa;
        int prefix_len = 0, i = 0;
@@ -1202,9 +1233,20 @@ static int __update_ipv6_network_info(void)
                ipv6_net_info.prefix = g_strdup(prefix);
        }
 
-       DBG("Update ipv6 network info([%s][%s][%s][%d])",
+       if (_get_network_dns_address(MOBILE_AP_ADDRESS_TYPE_IPV6, &dns) == FALSE) {
+               ERR("Fail to get dns address!!");
+               g_free(dns);
+               dns = NULL;
+       }
+
+       if (dns)
+               ipv6_net_info.dns = g_strdup(dns);
+       else
+               ipv6_net_info.dns = g_strdup(ipv6_net_info.global_address);
+
+       DBG("Update ipv6 network info([%s][%s][%s][%s][%d])",
                        ipv6_net_info.if_name, ipv6_net_info.global_address,
-                       ipv6_net_info.prefix, ipv6_net_info.state);
+                       ipv6_net_info.prefix, ipv6_net_info.dns, ipv6_net_info.state);
 
        return MOBILE_AP_ERROR_NONE;
 }
@@ -1344,6 +1386,11 @@ char *_get_ipv6_network_prefix(void)
        return ipv6_net_info.prefix;
 }
 
+char *_get_ipv6_network_dns_address(void)
+{
+       return ipv6_net_info.dns;
+}
+
 gboolean _get_ipv6_network_state(void)
 {
        return ipv6_net_info.state;
index 21b10d4..78f65cc 100755 (executable)
@@ -2275,6 +2275,7 @@ int _mh_core_execute_dhcp6_server(void)
        FILE *fp = NULL;
        pid_t pid;
        char *network_addr = NULL;
+       char *dns_addr = NULL;
        char *prefix = NULL;
 
        if (remove(DNSMASQ_LEASES_FILE) < 0)
@@ -2294,6 +2295,13 @@ int _mh_core_execute_dhcp6_server(void)
                        return MOBILE_AP_ERROR_INTERNAL;
                }
 
+               dns_addr = _get_ipv6_network_dns_address();
+               if (dns_addr == NULL) {
+                       ERR("Failed to get DNS address");
+                       fclose(fp);
+                       return MOBILE_AP_ERROR_INTERNAL;
+               }
+
                if (_get_ipv6_network_state()) {
                        prefix = g_strndup(network_addr, 19);
                        snprintf(buf, DNSMASQ_CONF_LEN,
@@ -2302,7 +2310,7 @@ int _mh_core_execute_dhcp6_server(void)
                                        prefix, prefix, prefix, prefix,
                                        prefix, prefix, prefix, prefix,
                                        prefix, prefix, prefix, prefix,
-                                       prefix, prefix, network_addr);
+                                       prefix, prefix, dns_addr);
                } else {
                        prefix = g_strndup(network_addr, 10);
                        snprintf(buf, DNSMASQ_CONF_LEN,