X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=server.c;h=04c7d10821bc8a0c4712f68b716715f5eef879cc;hb=cfc653d0fd2f58ef3f4b5ecb285d5beb5bfaacfb;hp=94c7b1d5aa4965ba130fe68cc4b93a33fff8ad23;hpb=8e7f83aa5b6d910e80c56b31f4eb79b02e7ca67b;p=catta diff --git a/server.c b/server.c index 94c7b1d..04c7d10 100644 --- a/server.c +++ b/server.c @@ -22,9 +22,24 @@ static void handle_query_key(flxServer *s, flxKey *k, flxInterface *i, const flx g_message("Handling query: %s", txt = flx_key_to_string(k)); g_free(txt); - for (e = g_hash_table_lookup(s->rrset_by_key, k); e; e = e->by_key_next) - if (flx_interface_match(i, e->interface, e->protocol)) - flx_interface_post_response(i, e->record); + flx_packet_scheduler_incoming_query(i->scheduler, k); + + if (k->type == FLX_DNS_TYPE_ANY) { + + /* Handle ANY query */ + + for (e = s->entries; e; e = e->entry_next) + if (flx_key_pattern_match(k, e->record->key)) + if (flx_interface_match(i, e->interface, e->protocol)) + flx_interface_post_response(i, a, e->record, FALSE); + } else { + + /* Handle all other queries */ + + for (e = g_hash_table_lookup(s->rrset_by_key, k); e; e = e->by_key_next) + if (flx_interface_match(i, e->interface, e->protocol)) + flx_interface_post_response(i, a, e->record, FALSE); + } } static void handle_query(flxServer *s, flxDnsPacket *p, flxInterface *i, const flxAddress *a) { @@ -46,6 +61,20 @@ static void handle_query(flxServer *s, flxDnsPacket *p, flxInterface *i, const f handle_query_key(s, key, i, a); flx_key_unref(key); } + + /* Known Answer Suppresion */ + for (n = flx_dns_packet_get_field(p, DNS_FIELD_ANCOUNT); n > 0; n --) { + flxRecord *record; + gboolean unique = FALSE; + + if (!(record = flx_dns_packet_consume_record(p, &unique))) { + g_warning("Packet too short (2)"); + return; + } + + flx_packet_scheduler_incoming_known_answer(i->scheduler, record, a); + flx_record_unref(record); + } } static void handle_response(flxServer *s, flxDnsPacket *p, flxInterface *i, const flxAddress *a) { @@ -67,14 +96,15 @@ static void handle_response(flxServer *s, flxDnsPacket *p, flxInterface *i, cons return; } - g_message("Handling response: %s", txt = flx_record_to_string(record)); - g_free(txt); - - flx_cache_update(i->cache, record, cache_flush, a); - - if (record->ttl != 0) - flx_packet_scheduler_drop_response(i->scheduler, record); - flx_record_unref(record); + if (record->key->type != FLX_DNS_TYPE_ANY) { + g_message("Handling response: %s", txt = flx_record_to_string(record)); + g_free(txt); + + flx_cache_update(i->cache, record, cache_flush, a); + + flx_packet_scheduler_incoming_response(i->scheduler, record); + flx_record_unref(record); + } } } @@ -347,6 +377,8 @@ void flx_server_add( g_assert(s); g_assert(r); + g_assert(r->key->type != FLX_DNS_TYPE_ANY); + e = g_new(flxServerEntry, 1); e->record = flx_record_ref(r); e->id = id; @@ -548,7 +580,7 @@ static void post_query_callback(flxInterfaceMonitor *m, flxInterface *i, gpointe g_assert(i); g_assert(k); - flx_interface_post_query(i, k); + flx_interface_post_query(i, k, FALSE); } void flx_server_post_query(flxServer *s, gint interface, guchar protocol, flxKey *key) { @@ -565,7 +597,7 @@ static void post_response_callback(flxInterfaceMonitor *m, flxInterface *i, gpoi g_assert(i); g_assert(r); - flx_interface_post_response(i, r); + flx_interface_post_response(i, NULL, r, FALSE); } void flx_server_post_response(flxServer *s, gint interface, guchar protocol, flxRecord *record) {