static void add_host_child_to_holder (GHolder * h) { GMetrics *nmetrics; GSubList *sub_list = new_gsublist (); char *host = h->items[h->idx].metrics->data; char *hostname = NULL; int n = h->sub_items_size; /* add child nodes */ set_host_sub_list (h, sub_list); pthread_mutex_lock (&gdns_thread.mutex); hostname = get_hostname (host); pthread_mutex_unlock (&gdns_thread.mutex); /* hostname */ if (!hostname) { dns_resolver (host); } else if (hostname) { set_host_child_metrics (hostname, MTRC_ID_HOSTNAME, &nmetrics); add_sub_item_back (sub_list, h->module, nmetrics); h->items[h->idx].sub_list = sub_list; h->sub_items_size++; free (hostname); } /* did not add any items */ if (n == h->sub_items_size) free (sub_list); }
/* add a host item to holder */ static void add_host_node (GHolder * h, int hits, char *data, unsigned long long bw, unsigned long long usecs) { GSubList *sub_list = new_gsublist (); char *ip = xstrdup (data); gpointer value_ptr; gboolean found; #ifdef HAVE_LIBGEOIP const char *addr = data; const char *location = NULL; #endif h->items[h->idx].bw += bw; h->items[h->idx].hits += hits; h->items[h->idx].data = xstrdup (data); if (conf.serve_usecs) h->items[h->idx].usecs = usecs; h->items[h->idx].sub_list = sub_list; #ifdef HAVE_LIBGEOIP location = get_geoip_data (addr); add_sub_item_back (sub_list, h->module, location, hits, bw); h->items[h->idx].sub_list = sub_list; h->sub_items_size++; #endif pthread_mutex_lock (&gdns_thread.mutex); found = g_hash_table_lookup_extended (ht_hostnames, ip, NULL, &value_ptr); pthread_mutex_unlock (&gdns_thread.mutex); if (!found) { dns_resolver (ip); } else if (value_ptr) { add_sub_item_back (sub_list, h->module, (char *) value_ptr, hits, bw); h->items[h->idx].sub_list = sub_list; h->sub_items_size++; } free (ip); h->idx++; }
int dns_query_a_or_aaaa(key_serial_t key, const char *hostname, char *options) { unsigned mask; int ret; debug("Get A/AAAA RR for hostname:'%s', options:'%s'", hostname, options); if (!options[0]) { /* legacy mode */ mask = INET_IP4_ONLY | ONE_ADDR_ONLY; } else { char *key, *val; mask = INET_ALL | ONE_ADDR_ONLY; do { key = options; options = strchr(options, ' '); if (!options) options = key + strlen(key); else *options++ = '\0'; if (!*key) continue; if (strchr(key, ',')) error("Option name '%s' contains a comma", key); val = strchr(key, '='); if (val) *val++ = '\0'; debug("Opt %s", key); if (strcmp(key, "ipv4") == 0) { mask &= ~INET_ALL; mask |= INET_IP4_ONLY; } else if (strcmp(key, "ipv6") == 0) { mask &= ~INET_ALL; mask |= INET_IP6_ONLY; } else if (strcmp(key, "list") == 0) { mask &= ~ONE_ADDR_ONLY; mask |= LIST_MULTIPLE_ADDRS; } } while (*options); } /* Turn the hostname into IP addresses */ ret = dns_resolver(hostname, mask); if (ret) nsError(NO_DATA, hostname); /* handle a lack of results */ if (payload_index == 0) nsError(NO_DATA, hostname); /* must include a NUL char at the end of the payload */ payload[payload_index].iov_base = ""; payload[payload_index++].iov_len = 1; dump_payload(); /* load the key with data key */ if (!debug_mode) { ret = keyctl_instantiate_iov(key, payload, payload_index, 0); if (ret == -1) error("%s: keyctl_instantiate: %m", __func__); } exit(0); }
static void afsdb_hosts_to_addrs(char *vllist[], int *vlsnum, ns_msg handle, ns_sect section, unsigned mask, unsigned long *_ttl) { int rrnum; ns_rr rr; int subtype, i, ret; unsigned int ttl = UINT_MAX, rr_ttl; debug("AFSDB RR count is %d", ns_msg_count(handle, section)); /* Look at all the resource records in this section. */ for (rrnum = 0; rrnum < ns_msg_count(handle, section); rrnum++) { /* Expand the resource record number rrnum into rr. */ if (ns_parserr(&handle, section, rrnum, &rr)) { _error("ns_parserr failed : %m"); continue; } /* We're only interested in AFSDB records */ if (ns_rr_type(rr) == ns_t_afsdb) { vllist[*vlsnum] = malloc(MAXDNAME); if (!vllist[*vlsnum]) error("Out of memory"); subtype = ns_get16(ns_rr_rdata(rr)); /* Expand the name server's domain name */ if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle), ns_rr_rdata(rr) + 2, vllist[*vlsnum], MAXDNAME) < 0) error("ns_name_uncompress failed"); rr_ttl = ns_rr_ttl(rr); if (ttl > rr_ttl) ttl = rr_ttl; /* Check the domain name we've just unpacked and add it to * the list of VL servers if it is not a duplicate. * If it is a duplicate, just ignore it. */ for (i = 0; i < *vlsnum; i++) if (strcasecmp(vllist[i], vllist[*vlsnum]) == 0) goto next_one; /* Turn the hostname into IP addresses */ ret = dns_resolver(vllist[*vlsnum], mask); if (ret) { debug("AFSDB RR can't resolve." "subtype:%d, server name:%s, netmask:%u", subtype, vllist[*vlsnum], mask); goto next_one; } info("AFSDB RR subtype:%d, server name:%s, ip:%*.*s, ttl:%u", subtype, vllist[*vlsnum], (int)payload[payload_index - 1].iov_len, (int)payload[payload_index - 1].iov_len, (char *)payload[payload_index - 1].iov_base, ttl); /* prepare for the next record */ *vlsnum += 1; continue; next_one: free(vllist[*vlsnum]); } } *_ttl = ttl; info("ttl: %u", ttl); }