]> git.meshlink.io Git - catta/blobdiff - avahi-core/server.c
core: always normalize configure host/domain name
[catta] / avahi-core / server.c
index 876984c2e1210308365359f81a5255da21d5e528..569b44eb2c8f6abb389eeaa1acfd3071b7117b11 100644 (file)
@@ -49,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);
@@ -657,17 +659,16 @@ 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?)");
             break;
         }
 
-        if (!avahi_key_is_pattern(record->key) && !avahi_record_is_link_local_address(record)) {
+        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);
@@ -678,7 +679,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);
@@ -1241,13 +1242,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);
     }
@@ -1255,7 +1257,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);
 
@@ -1269,10 +1271,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);
@@ -1282,7 +1284,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);
@@ -1584,6 +1586,7 @@ 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;
 
     return c;
 }