+static void *rtnl_nd_opt_rdnss(struct nd_opt_hdr *opt, guint32 *lifetime,
+ int *nr_servers)
+{
+ guint32 *optint = (void *)opt;
+
+ if (opt->nd_opt_len < 3)
+ return NULL;
+
+ if (*lifetime > ntohl(optint[1]))
+ *lifetime = ntohl(optint[1]);
+
+ /* nd_opt_len is in units of 8 bytes. The header is 1 unit (8 bytes)
+ and each address is another 2 units (16 bytes).
+ So the number of addresses (given rounding) is nd_opt_len/2 */
+ *nr_servers = opt->nd_opt_len / 2;
+
+ /* And they start 8 bytes into the packet, or two guint32s in. */
+ return optint + 2;
+}
+
+static const char **rtnl_nd_opt_dnssl(struct nd_opt_hdr *opt, guint32 *lifetime)
+{
+ const char **domains = NULL;
+ guint32 *optint = (void *)opt;
+ unsigned char *optc = (void *)&optint[2];
+ int data_len = (opt->nd_opt_len * 8) - 8;
+ int nr_domains = 0;
+ int i, tmp;
+
+ if (*lifetime > ntohl(optint[1]))
+ *lifetime = ntohl(optint[1]);
+
+ /* Turn it into normal strings by converting the length bytes into '.',
+ and count how many search domains there are while we're at it. */
+ i = 0;
+ while (i < data_len) {
+ if (optc[i] > 0x3f) {
+ DBG("DNSSL contains compressed elements in violation of RFC6106");
+ return NULL;
+ }
+
+ if (optc[i] == 0) {
+ nr_domains++;
+ i++;
+ /* Check for double zero */
+ if (i < data_len && optc[i] == 0)
+ break;
+ continue;
+ }
+
+ tmp = i;
+ i += optc[i] + 1;
+
+ if (i >= data_len) {
+ DBG("DNSSL data overflows option length");
+ return NULL;
+ }
+
+ optc[tmp] = '.';
+ }
+
+ domains = g_try_new0(const char *, nr_domains + 1);
+ if (!domains)
+ return NULL;
+
+ /* Now point to the normal strings, missing out the leading '.' that
+ each of them will have now. */
+ for (i = 0; i < nr_domains; i++) {
+ domains[i] = (char *)optc + 1;
+ optc += strlen((char *)optc) + 1;
+ }
+
+ return domains;
+}
+
+static void rtnl_newnduseropt(struct nlmsghdr *hdr)
+{
+ struct nduseroptmsg *msg = (struct nduseroptmsg *) NLMSG_DATA(hdr);
+ struct nd_opt_hdr *opt;
+ guint32 lifetime = -1;
+ const char **domains = NULL;
+ struct in6_addr *servers = NULL;
+ int i, nr_servers = 0;
+ int msglen = msg->nduseropt_opts_len;
+ int index;
+
+ DBG("family %d index %d len %d type %d code %d",
+ msg->nduseropt_family, msg->nduseropt_ifindex,
+ msg->nduseropt_opts_len, msg->nduseropt_icmp_type,
+ msg->nduseropt_icmp_code);
+
+ if (msg->nduseropt_family != AF_INET6 ||
+ msg->nduseropt_icmp_type != ND_ROUTER_ADVERT ||
+ msg->nduseropt_icmp_code != 0)
+ return;
+
+ index = msg->nduseropt_ifindex;
+ if (index < 0)
+ return;
+
+#if defined TIZEN_EXT
+ struct connman_service *service;
+ enum connman_service_state state;
+ enum connman_dnsconfig_method ipv6_dns_method;
+
+ service = __connman_service_lookup_from_index(index);
+ if (!service) {
+ DBG("Invalid service");
+ return;
+ }
+
+ DBG("service: %p index: %d\n", service, index);
+
+ if (connman_setting_get_bool("SingleConnectedTechnology") == TRUE) {
+ state = __connman_service_ipconfig_get_state(service, CONNMAN_IPCONFIG_TYPE_IPV6);
+ if (state != CONNMAN_SERVICE_STATE_ASSOCIATION &&
+ state != CONNMAN_SERVICE_STATE_CONFIGURATION &&
+ state != CONNMAN_SERVICE_STATE_READY &&
+ state != CONNMAN_SERVICE_STATE_ONLINE) {
+ DBG("Service state[%d] is not connecting/connected", state);
+ return;
+ }
+ }
+
+ ipv6_dns_method = connman_service_get_ipv6_dns_method(service);
+ if (ipv6_dns_method != CONNMAN_DNSCONFIG_METHOD_DHCP) {
+ DBG("IPv6 DNS method is not Auto ignore RA!!! [DNS method: %d]", ipv6_dns_method);
+ return;
+ }
+#endif
+
+ for (opt = (void *)&msg[1];
+ msglen > 0;
+ msglen -= opt->nd_opt_len * 8,
+ opt = ((void *)opt) + opt->nd_opt_len*8) {
+
+ DBG("remaining %d nd opt type %d len %d\n",
+ msglen, opt->nd_opt_type, opt->nd_opt_len);
+
+ if (opt->nd_opt_type == 25) { /* ND_OPT_RDNSS */
+ char buf[40];
+#if defined TIZEN_EXT
+ struct connman_service *service;
+
+ service = __connman_service_lookup_from_index(index);
+ DBG("service: %p\n",service);
+#endif
+ servers = rtnl_nd_opt_rdnss(opt, &lifetime,
+ &nr_servers);
+ for (i = 0; i < nr_servers; i++) {
+ if (!inet_ntop(AF_INET6, servers + i, buf,
+ sizeof(buf)))
+ continue;
+
+#if defined TIZEN_EXT
+ __connman_service_nameserver_remove(service,
+ buf, false,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
+ __connman_service_nameserver_append(service,
+ buf, false,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
+#endif
+ connman_resolver_append_lifetime(index,
+ NULL, buf, lifetime);
+ }
+
+ } else if (opt->nd_opt_type == 31) { /* ND_OPT_DNSSL */
+ g_free(domains);
+
+ domains = rtnl_nd_opt_dnssl(opt, &lifetime);
+ for (i = 0; domains && domains[i]; i++)
+ connman_resolver_append_lifetime(index,
+ domains[i], NULL, lifetime);
+ }
+ }
+
+ g_free(domains);
+}
+