]> git.meshlink.io Git - catta/blobdiff - avahi-core/server.c
forgot to pull the publish_no_reverse change to the example.
[catta] / avahi-core / server.c
index bb625a577ca123e4fb90a771400425d9e0065785..b348269d59dd15544eace1b9c399f86b8fe67e9c 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of avahi.
 
@@ -51,6 +49,8 @@
 #include "domain-util.h"
 #include "rr-util.h"
 
+#define AVAHI_DEFAULT_CACHE_ENTRIES_MAX 4096
+
 static void enum_aux_records(AvahiServer *s, AvahiInterface *i, const char *name, uint16_t type, void (*callback)(AvahiServer *s, AvahiRecord *r, int flush_cache, void* userdata), void* userdata) {
     assert(s);
     assert(i);
@@ -513,12 +513,20 @@ static void reflect_response(AvahiServer *s, AvahiInterface *i, AvahiRecord *r,
 
 static void* reflect_cache_walk_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void* userdata) {
     AvahiServer *s = userdata;
+    AvahiRecord* r;
 
     assert(c);
     assert(pattern);
     assert(e);
     assert(s);
 
+    /* Don't reflect cache entry with ipv6 link-local addresses. */
+    r = e->record;
+    if ((r->key->type == AVAHI_DNS_TYPE_AAAA) &&
+            (r->data.aaaa.address.address[0] == 0xFE) &&
+            (r->data.aaaa.address.address[1] == 0x80))
+      return NULL;
+
     avahi_record_list_push(s->record_list, e->record, e->cache_flush, 0, 0);
     return NULL;
 }
@@ -659,7 +667,6 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter
              avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT); n > 0; n--) {
         AvahiRecord *record;
         int cache_flush = 0;
-/*         char *txt; */
 
         if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) {
             avahi_log_warn(__FILE__": Packet too short or invalid while reading response record. (Maybe a UTF-8 problem?)");
@@ -669,7 +676,7 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter
         if (!avahi_key_is_pattern(record->key)) {
 
             if (handle_conflict(s, i, record, cache_flush)) {
-                if (!from_local_iface)
+                if (!from_local_iface && !avahi_record_is_link_local_address(record))
                     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);
@@ -680,7 +687,7 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter
     }
 
     /* If the incoming response contained a conflicting record, some
-       records have been scheduling for sending. We need to flush them
+       records have been scheduled for sending. We need to flush them
        here. */
     if (!avahi_record_list_is_empty(s->record_list))
         avahi_server_generate_response(s, i, NULL, NULL, 0, 0, 1);
@@ -924,10 +931,9 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres
     if (avahi_dns_packet_is_query(p)) {
         int legacy_unicast = 0;
 
-        if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT) != 0) {
-            avahi_log_warn("Invalid query packet.");
-            return;
-        }
+        /* For queries EDNS0 might allow ARCOUNT != 0. We ignore the
+         * AR section completely here, so far. Until the day we add
+         * EDNS0 support. */
 
         if (port != AVAHI_MDNS_PORT) {
             /* Legacy Unicast */
@@ -1009,13 +1015,6 @@ static void dispatch_legacy_unicast_packet(AvahiServer *s, AvahiDnsPacket *p) {
     avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ID, slot->id);
 }
 
-static void cleanup_dead(AvahiServer *s) {
-    assert(s);
-
-    avahi_cleanup_dead_entries(s);
-    avahi_browser_cleanup(s);
-}
-
 static void mcast_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events, void *userdata) {
     AvahiServer *s = userdata;
     AvahiAddress dest, src;
@@ -1044,11 +1043,11 @@ static void mcast_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events, vo
         if (iface != AVAHI_IF_UNSPEC)
             dispatch_packet(s, p, &src, port, &dest, iface, ttl);
         else
-            avahi_log_error("Incoming packet recieved on address that isn't local.");
+            avahi_log_error("Incoming packet received on address that isn't local.");
 
         avahi_dns_packet_free(p);
 
-        cleanup_dead(s);
+        avahi_cleanup_dead_entries(s);
     }
 }
 
@@ -1071,7 +1070,7 @@ static void legacy_unicast_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent e
         dispatch_legacy_unicast_packet(s, p);
         avahi_dns_packet_free(p);
 
-        cleanup_dead(s);
+        avahi_cleanup_dead_entries(s);
     }
 }
 
@@ -1224,6 +1223,7 @@ static void register_stuff(AvahiServer *s) {
     register_browse_domain(s);
     avahi_interface_monitor_update_rrs(s->monitor, 0);
 
+    assert(s->n_host_rr_pending > 0);
     s->n_host_rr_pending --;
 
     if (s->n_host_rr_pending == 0)
@@ -1250,13 +1250,14 @@ int avahi_server_set_host_name(AvahiServer *s, const char *host_name) {
 
     AVAHI_CHECK_VALIDITY(s, !host_name || avahi_is_valid_host_name(host_name), AVAHI_ERR_INVALID_HOST_NAME);
 
-    if (!host_name) {
+    if (!host_name)
         hn = avahi_get_host_name_strdup();
-        hn[strcspn(hn, ".")] = 0;
-        host_name = hn;
-    }
+    else
+        hn = avahi_normalize_name_strdup(host_name);
 
-    if (avahi_domain_equal(s->host_name, host_name) && s->state != AVAHI_SERVER_COLLISION) {
+    hn[strcspn(hn, ".")] = 0;
+
+    if (avahi_domain_equal(s->host_name, hn) && s->state != AVAHI_SERVER_COLLISION) {
         avahi_free(hn);
         return avahi_server_set_errno(s, AVAHI_ERR_NO_CHANGE);
     }
@@ -1264,7 +1265,7 @@ int avahi_server_set_host_name(AvahiServer *s, const char *host_name) {
     withdraw_host_rrs(s);
 
     avahi_free(s->host_name);
-    s->host_name = hn ? hn : avahi_strdup(host_name);
+    s->host_name = hn;
 
     update_fqdn(s);
 
@@ -1278,10 +1279,10 @@ int avahi_server_set_domain_name(AvahiServer *s, const char *domain_name) {
 
     AVAHI_CHECK_VALIDITY(s, !domain_name || avahi_is_valid_domain_name(domain_name), AVAHI_ERR_INVALID_DOMAIN_NAME);
 
-    if (!domain_name) {
+    if (!domain_name)
         dn = avahi_strdup("local");
-        domain_name = dn;
-    }
+    else
+        dn = avahi_normalize_name_strdup(domain_name);
 
     if (avahi_domain_equal(s->domain_name, domain_name)) {
         avahi_free(dn);
@@ -1291,7 +1292,7 @@ int avahi_server_set_domain_name(AvahiServer *s, const char *domain_name) {
     withdraw_host_rrs(s);
 
     avahi_free(s->domain_name);
-    s->domain_name = avahi_normalize_name_strdup(domain_name);
+    s->domain_name = dn;
     update_fqdn(s);
 
     register_stuff(s);
@@ -1394,6 +1395,7 @@ AvahiServer *avahi_server_new(const AvahiPoll *poll_api, const AvahiServerConfig
     s->need_entry_cleanup = 0;
     s->need_group_cleanup = 0;
     s->need_browser_cleanup = 0;
+    s->cleanup_time_event = NULL;
     s->hinfo_entry_group = NULL;
     s->browse_domain_entry_group = NULL;
     s->error = AVAHI_OK;
@@ -1493,6 +1495,9 @@ void avahi_server_free(AvahiServer* s) {
         avahi_wide_area_engine_free(s->wide_area_lookup_engine);
     avahi_multicast_lookup_engine_free(s->multicast_lookup_engine);
 
+    if (s->cleanup_time_event)
+        avahi_time_event_free(s->cleanup_time_event);
+
     avahi_time_event_queue_free(s->time_event_queue);
 
     /* Free watches */
@@ -1577,9 +1582,10 @@ AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c) {
     c->host_name = NULL;
     c->domain_name = NULL;
     c->check_response_ttl = 0;
-    c->publish_hinfo = 1;
+    c->publish_hinfo = 0;
     c->publish_addresses = 1;
-    c->publish_workstation = 1;
+    c->publish_no_reverse = 0;
+    c->publish_workstation = 0;
     c->publish_domain = 1;
     c->use_iff_running = 0;
     c->enable_reflector = 0;
@@ -1593,6 +1599,9 @@ AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c) {
     c->allow_point_to_point = 0;
     c->publish_aaaa_on_ipv4 = 1;
     c->publish_a_on_ipv6 = 0;
+    c->n_cache_entries_max = AVAHI_DEFAULT_CACHE_ENTRIES_MAX;
+    c->ratelimit_interval = 0;
+    c->ratelimit_burst = 0;
 
     return c;
 }