+ if (reply) {
+ if (avahi_dns_packet_get_field(reply, AVAHI_DNS_FIELD_ANCOUNT) != 0)
+ avahi_interface_send_packet_unicast(i, reply, a, port);
+ avahi_dns_packet_free(reply);
+ }
+ }
+
+ avahi_record_list_flush(s->record_list);
+}
+
+
+static void reflect_response(AvahiServer *s, AvahiInterface *i, AvahiRecord *r, int flush_cache) {
+ AvahiInterface *j;
+
+ assert(s);
+ assert(i);
+ assert(r);
+
+ if (!s->config.enable_reflector)
+ return;
+
+ for (j = s->monitor->interfaces; j; j = j->interface_next)
+ if (j != i && (s->config.reflect_ipv || j->protocol == i->protocol))
+ avahi_interface_post_response(j, r, flush_cache, NULL, 1);
+}
+
+static void* reflect_cache_walk_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void* userdata) {
+ AvahiServer *s = userdata;
+
+ assert(c);
+ assert(pattern);
+ assert(e);
+ assert(s);
+
+ avahi_record_list_push(s->record_list, e->record, e->cache_flush, 0, 0);
+ return NULL;
+}
+
+static void reflect_query(AvahiServer *s, AvahiInterface *i, AvahiKey *k) {
+ AvahiInterface *j;
+
+ assert(s);
+ assert(i);
+ assert(k);
+
+ if (!s->config.enable_reflector)
+ return;
+
+ for (j = s->monitor->interfaces; j; j = j->interface_next)
+ if (j != i && (s->config.reflect_ipv || j->protocol == i->protocol)) {
+ /* Post the query to other networks */
+ avahi_interface_post_query(j, k, 1);
+
+ /* Reply from caches of other network. This is needed to
+ * "work around" known answer suppression. */
+
+ avahi_cache_walk(j->cache, k, reflect_cache_walk_callback, s);
+ }
+}
+
+static void reflect_probe(AvahiServer *s, AvahiInterface *i, AvahiRecord *r) {
+ AvahiInterface *j;
+
+ assert(s);
+ assert(i);
+ assert(r);
+
+ if (!s->config.enable_reflector)
+ return;
+
+ for (j = s->monitor->interfaces; j; j = j->interface_next)
+ if (j != i && (s->config.reflect_ipv || j->protocol == i->protocol))
+ avahi_interface_post_probe(j, r, 1);
+}
+
+static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, uint16_t port, int legacy_unicast, int from_local_iface) {
+ size_t n;
+ int is_probe;
+
+ assert(s);
+ assert(p);
+ assert(i);
+ assert(a);
+
+/* avahi_log_debug("query"); */
+
+ assert(avahi_record_list_is_empty(s->record_list));
+
+ is_probe = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) > 0;
+
+ /* Handle the questions */
+ for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT); n > 0; n --) {
+ AvahiKey *key;
+ int unicast_response = 0;
+
+ if (!(key = avahi_dns_packet_consume_key(p, &unicast_response))) {
+ avahi_log_warn("Packet too short (1)");
+ goto fail;
+ }
+
+ if (!legacy_unicast && !from_local_iface)
+ reflect_query(s, i, key);
+
+ if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 &&
+ !(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_TC))
+ /* Allow our own queries to be suppressed by incoming
+ * queries only when they do not include known answers */
+ avahi_query_scheduler_incoming(i->query_scheduler, key);
+
+ avahi_server_prepare_matching_responses(s, i, key, unicast_response);
+ avahi_key_unref(key);
+ }
+
+ if (!legacy_unicast) {
+
+ /* Known Answer Suppression */
+ for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT); n > 0; n --) {
+ AvahiRecord *record;
+ int unique = 0;
+
+ if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
+ avahi_log_warn("Packet too short (2)");
+ goto fail;
+ }
+
+ if (handle_conflict(s, i, record, unique, a)) {
+ avahi_response_scheduler_suppress(i->response_scheduler, record, a);
+ avahi_record_list_drop(s->record_list, record);
+ }
+
+ avahi_record_unref(record);
+ }
+
+ /* Probe record */
+ for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT); n > 0; n --) {
+ AvahiRecord *record;
+ int unique = 0;
+
+ if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
+ avahi_log_warn("Packet too short (3)");
+ goto fail;
+ }
+
+ if (!avahi_key_is_pattern(record->key)) {
+ if (!from_local_iface)
+ reflect_probe(s, i, record);
+ incoming_probe(s, record, i);