#include "util.h"
#include "iface.h"
#include "socket.h"
-
+#include "subscribe.h"
static void handle_query_key(flxServer *s, flxKey *k, flxInterface *i, const flxAddress *a) {
flxServerEntry *e;
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) {
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) {
return;
}
- 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_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);
+ }
}
}
s->context = g_main_context_default();
s->current_id = 1;
+
+ FLX_LLIST_HEAD_INIT(flxServerEntry, s->entries);
s->rrset_by_id = g_hash_table_new(g_int_hash, g_int_equal);
s->rrset_by_key = g_hash_table_new((GHashFunc) flx_key_hash, (GEqualFunc) flx_key_equal);
- FLX_LLIST_HEAD_INIT(flxServerEntry, s->entries);
+ FLX_LLIST_HEAD_INIT(flxSubscription, s->subscriptions);
+ s->subscription_hashtable = g_hash_table_new((GHashFunc) flx_key_hash, (GEqualFunc) flx_key_equal);
s->monitor = flx_interface_monitor_new(s);
s->time_event_queue = flx_time_event_queue_new(s->context);
flx_interface_monitor_free(s->monitor);
flx_server_remove(s, 0);
+
+ while (s->subscriptions)
+ flx_subscription_free(s->subscriptions);
+ g_hash_table_destroy(s->subscription_hashtable);
g_hash_table_destroy(s->rrset_by_id);
g_hash_table_destroy(s->rrset_by_key);
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;
flx_server_add_full(s, id, interface, protocol, unique, name, FLX_DNS_CLASS_IN, FLX_DNS_TYPE_TXT, buf, l+1, FLX_DEFAULT_TTL);
}
+static void post_query_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) {
+ flxKey *k = userdata;
+
+ g_assert(m);
+ g_assert(i);
+ g_assert(k);
+
+ flx_interface_post_query(i, k, FALSE);
+}
+
void flx_server_post_query(flxServer *s, gint interface, guchar protocol, flxKey *key) {
g_assert(s);
g_assert(key);
-
- if (interface > 0) {
- if (protocol != AF_UNSPEC) {
- flxInterface *i;
-
- if ((i = flx_interface_monitor_get_interface(s->monitor, interface, protocol)))
- flx_interface_post_query(i, key);
- } else {
- flxHwInterface *hw;
- flxInterface *i;
-
- if ((hw = flx_interface_monitor_get_hw_interface(s->monitor, interface)))
- for (i = hw->interfaces; i; i = i->by_hardware_next)
- if (flx_interface_match(i, interface, protocol))
- flx_interface_post_query(i, key);
- }
-
- } else {
- flxInterface *i;
-
- for (i = s->monitor->interfaces; i; i = i->interface_next)
- if (flx_interface_match(i, interface, protocol))
- flx_interface_post_query(i, key);
- }
+
+ flx_interface_monitor_walk(s->monitor, interface, protocol, post_query_callback, key);
+}
+
+static void post_response_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) {
+ flxRecord *r = userdata;
+
+ g_assert(m);
+ g_assert(i);
+ g_assert(r);
+
+ flx_interface_post_response(i, NULL, r, FALSE);
}
void flx_server_post_response(flxServer *s, gint interface, guchar protocol, flxRecord *record) {
g_assert(s);
g_assert(record);
-
- if (interface > 0) {
- if (protocol != AF_UNSPEC) {
- flxInterface *i;
-
- if ((i = flx_interface_monitor_get_interface(s->monitor, interface, protocol)))
- flx_interface_post_response(i, record);
- } else {
- flxHwInterface *hw;
- flxInterface *i;
-
- if ((hw = flx_interface_monitor_get_hw_interface(s->monitor, interface)))
- for (i = hw->interfaces; i; i = i->by_hardware_next)
- if (flx_interface_match(i, interface, protocol))
- flx_interface_post_response(i, record);
- }
-
- } else {
- flxInterface *i;
-
- for (i = s->monitor->interfaces; i; i = i->interface_next)
- if (flx_interface_match(i, interface, protocol))
- flx_interface_post_response(i, record);
- }
+
+ flx_interface_monitor_walk(s->monitor, interface, protocol, post_response_callback, record);
}