X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fserver.c;h=66cc70592699286d40120494f45b44263729989e;hb=77e36045b7f13654e5dad8b80b3224dd06daede0;hp=6ba8ea0ce7cde7bb1a537a3d411db62526790f1f;hpb=af548e38c2c282132ddac2a75a76218ff3be3175;p=catta diff --git a/avahi-core/server.c b/avahi-core/server.c index 6ba8ea0..66cc705 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -267,7 +267,6 @@ static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface * } } - if (!ours) { if (won) @@ -296,7 +295,30 @@ static int handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *recor for (e = avahi_hashmap_lookup(s->entries_by_key, record->key); e; e = n) { n = e->by_key_next; - if (e->dead || (!(e->flags & AVAHI_ENTRY_UNIQUE) && !unique)) + if (e->dead) + continue; + + /* Check if the incoming is a goodbye record */ + if (avahi_record_is_goodbye(record)) { + + if (avahi_record_equal_no_ttl(e->record, record)) { + char *t; + + /* Refresh */ + t = avahi_record_to_string(record); + avahi_log_debug("Recieved goodbye record for one of our records [%s]. Refreshing.", t); + avahi_server_prepare_matching_responses(s, i, e->record->key, 0); + + valid = 0; + avahi_free(t); + break; + } + + /* If the goodybe packet doesn't match one of our own RRs, we simply ignore it. */ + continue; + } + + if (!(e->flags & AVAHI_ENTRY_UNIQUE) && !unique) continue; /* Either our entry or the other is intended to be unique, so let's check */ @@ -565,7 +587,7 @@ static void reflect_probe(AvahiServer *s, AvahiInterface *i, AvahiRecord *r) { 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; @@ -590,7 +612,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac 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 && @@ -603,40 +625,44 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac 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)) @@ -648,7 +674,7 @@ fail: 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); @@ -675,7 +701,8 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter /* 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); } @@ -713,9 +740,10 @@ static AvahiLegacyUnicastReflectSlot* allocate_slot(AvahiServer *s) { if (!(slot = avahi_new(AvahiLegacyUnicastReflectSlot, 1))) return NULL; /* OOM */ - slot = s->legacy_unicast_reflect_slots[idx]; + s->legacy_unicast_reflect_slots[idx] = slot; slot->id = s->legacy_unicast_reflect_id++; slot->server = s; + return slot; } @@ -877,10 +905,23 @@ static int is_mdns_mcast_address(const AvahiAddress *a) { 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); @@ -907,6 +948,10 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock /* 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; @@ -935,7 +980,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock 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 { @@ -962,7 +1007,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock return; } - handle_response_packet(s, p, i, &a); + handle_response_packet(s, p, i, &a, from_local_iface); /* avahi_log_debug("Handled response"); */ } } @@ -1472,15 +1517,14 @@ static int check_record_conflict(AvahiServer *s, AvahiIfIndex interface, AvahiPr if ((flags & AVAHI_ENTRY_ALLOWMUTIPLE) && (e->flags & AVAHI_ENTRY_ALLOWMUTIPLE) ) continue; - if (interface <= 0 || - e->interface <= 0 || - e->interface == interface || - protocol == AVAHI_PROTO_UNSPEC || - e->protocol == AVAHI_PROTO_UNSPEC || - e->protocol == protocol) + if ((interface <= 0 || + e->interface <= 0 || + e->interface == interface) && + (protocol == AVAHI_PROTO_UNSPEC || + e->protocol == AVAHI_PROTO_UNSPEC || + e->protocol == protocol)) return -1; - } return 0;