static struct uloop_timeout cache_gc;
struct avl_tree services;
-AVL_TREE(records, avl_strcmp, true, NULL);
+
+static int avl_strcasecmp(const void *k1, const void *k2, void *ptr)
+{
+ return strcasecmp(k1, k2);
+}
+
+AVL_TREE(records, avl_strcasecmp, true, NULL);
static void
cache_record_free(struct cache_record *r)
int
cache_init(void)
{
- avl_init(&services, avl_strcmp, true, NULL);
+ avl_init(&services, avl_strcasecmp, true, NULL);
cache_gc.cb = cache_gc_timer;
uloop_timeout_set(&cache_gc, 10000);
avl_insert(&services, &s->avl);
if (!hlen)
- dns_send_question(iface, NULL, entry, TYPE_PTR, iface->multicast);
+ dns_send_question(iface, NULL, entry, TYPE_PTR, interface_multicast(iface));
return s;
}
{
struct cache_record *l = avl_find_element(&records, record, l, avl);
- if (!l)
- return NULL;
-
- while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, record)) {
+ while (l && !strcmp(l->record, record)) {
struct cache_record *r = l;
- l = avl_next_element(l, avl);
+ l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, avl) : NULL;
if (r->type != type)
continue;
{
struct cache_record *l = avl_find_element(&records, record, l, avl);
- if (!l)
- return 0;
-
- while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, record)) {
+ while (l && !strcmp(l->record, record)) {
struct cache_record *r = l;
- l = avl_next_element(l, avl);
+ l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, avl) : NULL;
if ((r->type != TYPE_A) && (r->type != TYPE_AAAA))
continue;
return 1;
r->rdlength = dlen;
r->time = now;
r->iface = iface;
- if (iface->v6)
+ if (interface_ipv6(iface))
memcpy(&r->from, from, sizeof(struct sockaddr_in6));
else
memcpy(&r->from, from, sizeof(struct sockaddr_in));
}
void
-cache_dump_records(struct blob_buf *buf, const char *name, int array)
+cache_dump_records(struct blob_buf *buf, const char *name, int array,
+ const char **hostname)
{
struct cache_record *r, *last, *next;
const char *txt;
break;
case TYPE_SRV:
+ if (r->rdata) {
+ blobmsg_add_string(buf, "host", (char *)r->rdata + sizeof(struct dns_srv_data));
+ if (hostname)
+ *hostname = (char *)r->rdata + sizeof(struct dns_srv_data);
+ }
if (r->port)
blobmsg_add_u32(buf, "port", r->port);
break;