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) {
+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;
goto fail;
}
- if (!legacy_unicast)
+ if (!legacy_unicast && !from_local_iface)
reflect_query(s, i, key);
if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 &&
avahi_key_unref(key);
}
- /* Known Answer Suppression */
- for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT); n > 0; n --) {
- AvahiRecord *record;
- int unique = 0;
+ if (!legacy_unicast) {
- 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);
+ /* 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);
}
- 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)) {
- reflect_probe(s, i, record);
- incoming_probe(s, record, i);
+ /* 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);
+ }
+
+ avahi_record_unref(record);
}
-
- avahi_record_unref(record);
}
if (!avahi_record_list_is_empty(s->record_list))
avahi_record_list_flush(s->record_list);
}
-static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a) {
+static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, int from_local_iface) {
unsigned n;
assert(s);
/* avahi_free(txt); */
if (handle_conflict(s, i, record, cache_flush, a)) {
- reflect_response(s, i, record, cache_flush);
+ if (!from_local_iface)
+ reflect_response(s, i, record, cache_flush);
avahi_cache_update(i->cache, record, cache_flush, a);
avahi_response_scheduler_incoming(i->response_scheduler, record, cache_flush);
}
return avahi_address_cmp(a, &b) == 0;
}
+static int originates_from_local_iface(AvahiServer *s, AvahiIfIndex iface, const AvahiAddress *a, uint16_t port) {
+ assert(s);
+ assert(iface != AVAHI_IF_UNSPEC);
+ assert(a);
+
+ /* If it isn't the MDNS port it can't be generated by us */
+ if (port != AVAHI_MDNS_PORT)
+ return 0;
+
+ return avahi_interface_has_address(s->monitor, iface, a);
+}
+
static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sockaddr *sa, AvahiAddress *dest, AvahiIfIndex iface, int ttl) {
AvahiInterface *i;
AvahiAddress a;
uint16_t port;
+ int from_local_iface = 0;
assert(s);
assert(p);
/* This originates from our local reflector, so let's ignore it */
return;
+ /* We don't want to reflect local traffic, so we check if this packet is generated locally. */
+ if (s->config.enable_reflector)
+ from_local_iface = originates_from_local_iface(s, iface, &a, port);
+
if (avahi_dns_packet_is_valid(p) < 0) {
avahi_log_warn("Recieved invalid packet.");
return;
if (legacy_unicast)
reflect_legacy_unicast_query_packet(s, p, i, &a, port);
- handle_query_packet(s, p, i, &a, port, legacy_unicast);
+ handle_query_packet(s, p, i, &a, port, legacy_unicast, from_local_iface);
/* avahi_log_debug("Handled query"); */
} else {
return;
}
- handle_response_packet(s, p, i, &a);
+ handle_response_packet(s, p, i, &a, from_local_iface);
/* avahi_log_debug("Handled response"); */
}
}