]> git.meshlink.io Git - catta/blobdiff - avahi-core/server.c
minor NEWS updat
[catta] / avahi-core / server.c
index a3fac4bea0b8465297463da83de2908c15e6c09a..66cc70592699286d40120494f45b44263729989e 100644 (file)
@@ -35,6 +35,7 @@
 #include <avahi-common/domain.h>
 #include <avahi-common/timeval.h>
 #include <avahi-common/malloc.h>
+#include <avahi-common/error.h>
 
 #include "server.h"
 #include "iface.h"
@@ -74,7 +75,7 @@ static void free_entry(AvahiServer*s, AvahiEntry *e) {
     avahi_free(e);
 }
 
-static void free_group(AvahiServer *s, AvahiEntryGroup *g) {
+static void free_group(AvahiServer *s, AvahiSEntryGroup *g) {
     assert(s);
     assert(g);
 
@@ -84,7 +85,7 @@ static void free_group(AvahiServer *s, AvahiEntryGroup *g) {
     if (g->register_time_event)
         avahi_time_event_free(g->register_time_event);
     
-    AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, s->groups, g);
+    AVAHI_LLIST_REMOVE(AvahiSEntryGroup, groups, s->groups, g);
     avahi_free(g);
 }
 
@@ -92,7 +93,7 @@ static void cleanup_dead(AvahiServer *s) {
     assert(s);
 
     if (s->need_group_cleanup) {
-        AvahiEntryGroup *g, *next;
+        AvahiSEntryGroup *g, *next;
         
         for (g = s->groups; g; g = next) {
             next = g->groups_next;
@@ -212,7 +213,7 @@ static void withdraw_entry(AvahiServer *s, AvahiEntry *e) {
 
         e->group->n_probing = 0;
 
-        avahi_entry_group_change_state(e->group, AVAHI_ENTRY_GROUP_COLLISION);
+        avahi_s_entry_group_change_state(e->group, AVAHI_ENTRY_GROUP_COLLISION);
     } else {
         avahi_goodbye_entry(s, e, 0);
         e->dead = 1;
@@ -266,7 +267,6 @@ static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface *
         }
     }
 
-
     if (!ours) {
 
         if (won)
@@ -295,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 */
@@ -564,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;
     
@@ -589,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 &&
@@ -602,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 (!(record = avahi_dns_packet_consume_record(p, &unique))) {
-            avahi_log_warn("Packet too short (2)");
-            goto fail;
-        }
+    if (!legacy_unicast) {
 
-        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))
@@ -647,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);
@@ -674,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);
             }
@@ -712,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;
 }
 
@@ -876,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);
@@ -906,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;
@@ -934,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 {
@@ -961,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"); */
     }
 }
@@ -1081,10 +1127,10 @@ static void withdraw_host_rrs(AvahiServer *s) {
     assert(s);
 
     if (s->hinfo_entry_group)
-        avahi_entry_group_reset(s->hinfo_entry_group);
+        avahi_s_entry_group_reset(s->hinfo_entry_group);
 
     if (s->browse_domain_entry_group)
-        avahi_entry_group_reset(s->browse_domain_entry_group);
+        avahi_s_entry_group_reset(s->browse_domain_entry_group);
 
     avahi_update_host_rrs(s->monitor, 1);
     s->n_host_rr_pending = 0;
@@ -1105,7 +1151,7 @@ void avahi_server_increase_host_rr_pending(AvahiServer *s) {
     s->n_host_rr_pending ++;
 }
 
-void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
+void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
     assert(s);
     assert(g);
 
@@ -1133,9 +1179,9 @@ static void register_hinfo(AvahiServer *s) {
         return;
 
     if (s->hinfo_entry_group)
-        assert(avahi_entry_group_is_empty(s->hinfo_entry_group));
+        assert(avahi_s_entry_group_is_empty(s->hinfo_entry_group));
     else
-        s->hinfo_entry_group = avahi_entry_group_new(s, avahi_host_rr_entry_group_callback, NULL);
+        s->hinfo_entry_group = avahi_s_entry_group_new(s, avahi_host_rr_entry_group_callback, NULL);
 
     if (!s->hinfo_entry_group) {
         avahi_log_warn("Failed to create HINFO entry group: %s", avahi_strerror(s->error));
@@ -1156,7 +1202,7 @@ static void register_hinfo(AvahiServer *s) {
         avahi_record_unref(r);
     }
 
-    if (avahi_entry_group_commit(s->hinfo_entry_group) < 0)
+    if (avahi_s_entry_group_commit(s->hinfo_entry_group) < 0)
         avahi_log_warn("Failed to commit HINFO entry group: %s", avahi_strerror(s->error));
 
 }
@@ -1180,9 +1226,9 @@ static void register_browse_domain(AvahiServer *s) {
         return;
 
     if (s->browse_domain_entry_group)
-        assert(avahi_entry_group_is_empty(s->browse_domain_entry_group));
+        assert(avahi_s_entry_group_is_empty(s->browse_domain_entry_group));
     else
-        s->browse_domain_entry_group = avahi_entry_group_new(s, NULL, NULL);
+        s->browse_domain_entry_group = avahi_s_entry_group_new(s, NULL, NULL);
 
     if (!s->browse_domain_entry_group) {
         avahi_log_warn("Failed to create browse domain entry group: %s", avahi_strerror(s->error));
@@ -1194,7 +1240,7 @@ static void register_browse_domain(AvahiServer *s) {
         return;
     }
 
-    if (avahi_entry_group_commit(s->browse_domain_entry_group) < 0)
+    if (avahi_s_entry_group_commit(s->browse_domain_entry_group) < 0)
         avahi_log_warn("Failed to commit browse domain entry group: %s", avahi_strerror(s->error));
 }
 
@@ -1202,10 +1248,14 @@ static void register_stuff(AvahiServer *s) {
     assert(s);
 
     server_set_state(s, AVAHI_SERVER_REGISTERING);
+    s->n_host_rr_pending ++;  /** Make sure that the state isn't changed tp AVAHI_SERVER_RUNNING too early */
+
     register_hinfo(s);
     register_browse_domain(s);
     avahi_update_host_rrs(s->monitor, 0);
 
+    s->n_host_rr_pending --;
+    
     if (s->n_host_rr_pending == 0)
         server_set_state(s, AVAHI_SERVER_RUNNING);
 }
@@ -1301,7 +1351,7 @@ static int setup_sockets(AvahiServer *s) {
     return 0;
 }
 
-AvahiServer *avahi_server_new(AvahiPoll *poll_api, const AvahiServerConfig *sc, AvahiServerCallback callback, void* userdata, int *error) {
+AvahiServer *avahi_server_new(const AvahiPoll *poll_api, const AvahiServerConfig *sc, AvahiServerCallback callback, void* userdata, int *error) {
     AvahiServer *s;
     int e;
     
@@ -1350,14 +1400,14 @@ AvahiServer *avahi_server_new(AvahiPoll *poll_api, const AvahiServerConfig *sc,
     AVAHI_LLIST_HEAD_INIT(AvahiGroup, s->groups);
 
     s->record_browser_hashmap = avahi_hashmap_new((AvahiHashFunc) avahi_key_hash, (AvahiEqualFunc) avahi_key_equal, NULL, NULL);
-    AVAHI_LLIST_HEAD_INIT(AvahiRecordBrowser, s->record_browsers);
-    AVAHI_LLIST_HEAD_INIT(AvahiHostNameResolver, s->host_name_resolvers);
-    AVAHI_LLIST_HEAD_INIT(AvahiAddressResolver, s->address_resolvers);
-    AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, s->domain_browsers);
-    AVAHI_LLIST_HEAD_INIT(AvahiServiceTypeBrowser, s->service_type_browsers);
-    AVAHI_LLIST_HEAD_INIT(AvahiServiceBrowser, s->service_browsers);
-    AVAHI_LLIST_HEAD_INIT(AvahiServiceResolver, s->service_resolvers);
-    AVAHI_LLIST_HEAD_INIT(AvahiDNSServerBrowser, s->dns_server_browsers);
+    AVAHI_LLIST_HEAD_INIT(AvahiSRecordBrowser, s->record_browsers);
+    AVAHI_LLIST_HEAD_INIT(AvahiSHostNameResolver, s->host_name_resolvers);
+    AVAHI_LLIST_HEAD_INIT(AvahiSAddressResolver, s->address_resolvers);
+    AVAHI_LLIST_HEAD_INIT(AvahiSDomainBrowser, s->domain_browsers);
+    AVAHI_LLIST_HEAD_INIT(AvahiSServiceTypeBrowser, s->service_type_browsers);
+    AVAHI_LLIST_HEAD_INIT(AvahiSServiceBrowser, s->service_browsers);
+    AVAHI_LLIST_HEAD_INIT(AvahiSServiceResolver, s->service_resolvers);
+    AVAHI_LLIST_HEAD_INIT(AvahiSDNSServerBrowser, s->dns_server_browsers);
 
     s->legacy_unicast_reflect_slots = NULL;
     s->legacy_unicast_reflect_id = 0;
@@ -1401,21 +1451,21 @@ void avahi_server_free(AvahiServer* s) {
     free_slots(s);
 
     while (s->dns_server_browsers)
-        avahi_dns_server_browser_free(s->dns_server_browsers);
+        avahi_s_dns_server_browser_free(s->dns_server_browsers);
     while (s->host_name_resolvers)
-        avahi_host_name_resolver_free(s->host_name_resolvers);
+        avahi_s_host_name_resolver_free(s->host_name_resolvers);
     while (s->address_resolvers)
-        avahi_address_resolver_free(s->address_resolvers);
+        avahi_s_address_resolver_free(s->address_resolvers);
     while (s->domain_browsers)
-        avahi_domain_browser_free(s->domain_browsers);
+        avahi_s_domain_browser_free(s->domain_browsers);
     while (s->service_type_browsers)
-        avahi_service_type_browser_free(s->service_type_browsers);
+        avahi_s_service_type_browser_free(s->service_type_browsers);
     while (s->service_browsers)
-        avahi_service_browser_free(s->service_browsers);
+        avahi_s_service_browser_free(s->service_browsers);
     while (s->service_resolvers)
-        avahi_service_resolver_free(s->service_resolvers);
+        avahi_s_service_resolver_free(s->service_resolvers);
     while (s->record_browsers)
-        avahi_record_browser_destroy(s->record_browsers);
+        avahi_s_record_browser_destroy(s->record_browsers);
     
     avahi_hashmap_free(s->record_browser_hashmap);
     avahi_hashmap_free(s->entries_by_key);
@@ -1467,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;
@@ -1483,7 +1532,7 @@ static int check_record_conflict(AvahiServer *s, AvahiIfIndex interface, AvahiPr
 
 int avahi_server_add(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiEntryFlags flags,
@@ -1535,7 +1584,7 @@ int avahi_server_add(
     return 0;
 }
 
-const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state) {
+const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiSEntryGroup *g, void **state) {
     AvahiEntry **e = (AvahiEntry**) state;
     assert(s);
     assert(e);
@@ -1582,7 +1631,7 @@ int avahi_server_dump(AvahiServer *s, AvahiDumpCallback callback, void* userdata
 
 int avahi_server_add_ptr(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiEntryFlags flags,
@@ -1607,7 +1656,7 @@ int avahi_server_add_ptr(
 
 int avahi_server_add_address(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiEntryFlags flags,
@@ -1703,7 +1752,7 @@ fail:
 
 static int server_add_txt_strlst_nocopy(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiEntryFlags flags,
@@ -1728,7 +1777,7 @@ static int server_add_txt_strlst_nocopy(
 
 int avahi_server_add_txt_strlst(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiEntryFlags flags,
@@ -1743,7 +1792,7 @@ int avahi_server_add_txt_strlst(
 
 int avahi_server_add_txt_va(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiEntryFlags flags,
@@ -1758,7 +1807,7 @@ int avahi_server_add_txt_va(
 
 int avahi_server_add_txt(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiEntryFlags flags,
@@ -1802,7 +1851,7 @@ static void escape_service_name(char *d, size_t size, const char *s) {
 
 static int server_add_service_strlst_nocopy(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     const char *name,
@@ -1833,9 +1882,6 @@ static int server_add_service_strlst_nocopy(
     if (host && !avahi_is_valid_domain_name(host))
         return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME);
 
-    if (port == 0)
-        return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT);
-    
     escape_service_name(ename, sizeof(ename), name);
 
     if (!domain)
@@ -1895,7 +1941,7 @@ fail:
 
 int avahi_server_add_service_strlst(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     const char *name,
@@ -1914,7 +1960,7 @@ int avahi_server_add_service_strlst(
 
 int avahi_server_add_service_va(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     const char *name,
@@ -1933,7 +1979,7 @@ int avahi_server_add_service_va(
 
 int avahi_server_add_service(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     const char *name,
@@ -1980,7 +2026,7 @@ static void hexstring(char *s, size_t sl, const void *p, size_t pl) {
 
 int avahi_server_add_dns_server_address(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     const char *domain,
@@ -1997,12 +2043,12 @@ int avahi_server_add_dns_server_address(
     assert(type == AVAHI_DNS_SERVER_UPDATE || type == AVAHI_DNS_SERVER_RESOLVE);
     assert(address->family == AVAHI_PROTO_INET || address->family == AVAHI_PROTO_INET6);
 
-    if (domain && !avahi_is_valid_domain_name(domain))
-        return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
-
     if (port == 0)
         return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT);
     
+    if (domain && !avahi_is_valid_domain_name(domain))
+        return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
+
     if (address->family == AVAHI_PROTO_INET) {
         hexstring(n+3, sizeof(n)-3, &address->data, 4);
         r = avahi_record_new_full(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A, AVAHI_DEFAULT_TTL_HOST_NAME);
@@ -2027,7 +2073,7 @@ int avahi_server_add_dns_server_address(
 
 int avahi_server_add_dns_server_name(
     AvahiServer *s,
-    AvahiEntryGroup *g,
+    AvahiSEntryGroup *g,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     const char *domain,
@@ -2098,7 +2144,7 @@ void avahi_server_post_query(AvahiServer *s, AvahiIfIndex interface, AvahiProtoc
     avahi_interface_monitor_walk(s->monitor, interface, protocol, post_query_callback, key);
 }
 
-void avahi_entry_group_change_state(AvahiEntryGroup *g, AvahiEntryGroupState state) {
+void avahi_s_entry_group_change_state(AvahiSEntryGroup *g, AvahiEntryGroupState state) {
     assert(g);
 
     if (g->state == state)
@@ -2112,12 +2158,12 @@ void avahi_entry_group_change_state(AvahiEntryGroup *g, AvahiEntryGroupState sta
         g->callback(g->server, g, state, g->userdata);
 }
 
-AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, void* userdata) {
-    AvahiEntryGroup *g;
+AvahiSEntryGroup *avahi_s_entry_group_new(AvahiServer *s, AvahiSEntryGroupCallback callback, void* userdata) {
+    AvahiSEntryGroup *g;
     
     assert(s);
 
-    if (!(g = avahi_new(AvahiEntryGroup, 1))) {
+    if (!(g = avahi_new(AvahiSEntryGroup, 1))) {
         avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
         return NULL;
     }
@@ -2134,11 +2180,11 @@ AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback c
     g->register_time.tv_usec = 0;
     AVAHI_LLIST_HEAD_INIT(AvahiEntry, g->entries);
 
-    AVAHI_LLIST_PREPEND(AvahiEntryGroup, groups, s->groups, g);
+    AVAHI_LLIST_PREPEND(AvahiSEntryGroup, groups, s->groups, g);
     return g;
 }
 
-void avahi_entry_group_free(AvahiEntryGroup *g) {
+void avahi_s_entry_group_free(AvahiSEntryGroup *g) {
     AvahiEntry *e;
     
     assert(g);
@@ -2162,21 +2208,21 @@ void avahi_entry_group_free(AvahiEntryGroup *g) {
     g->server->need_entry_cleanup = 1;
 }
 
-static void entry_group_commit_real(AvahiEntryGroup *g) {
+static void entry_group_commit_real(AvahiSEntryGroup *g) {
     assert(g);
 
     gettimeofday(&g->register_time, NULL);
 
-    avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
+    avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
 
     if (!g->dead) {
         avahi_announce_group(g->server, g);
-        avahi_entry_group_check_probed(g, 0);
+        avahi_s_entry_group_check_probed(g, 0);
     }
 }
 
 static void entry_group_register_time_event_callback(AvahiTimeEvent *e, void* userdata) {
-    AvahiEntryGroup *g = userdata;
+    AvahiSEntryGroup *g = userdata;
     assert(g);
 
 /*     avahi_log_debug("Holdoff passed, waking up and going on."); */
@@ -2188,7 +2234,7 @@ static void entry_group_register_time_event_callback(AvahiTimeEvent *e, void* us
     entry_group_commit_real(g);
 }
 
-int avahi_entry_group_commit(AvahiEntryGroup *g) {
+int avahi_s_entry_group_commit(AvahiSEntryGroup *g) {
     struct timeval now;
     
     assert(g);
@@ -2218,13 +2264,13 @@ int avahi_entry_group_commit(AvahiEntryGroup *g) {
         assert(!g->register_time_event);
         g->register_time_event = avahi_time_event_new(g->server->time_event_queue, &g->register_time, entry_group_register_time_event_callback, g);
         
-        avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
+        avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
     }
 
     return AVAHI_OK;
 }
 
-void avahi_entry_group_reset(AvahiEntryGroup *g) {
+void avahi_s_entry_group_reset(AvahiSEntryGroup *g) {
     AvahiEntry *e;
     assert(g);
     
@@ -2248,7 +2294,7 @@ void avahi_entry_group_reset(AvahiEntryGroup *g) {
     g->server->need_entry_cleanup = 1;
     g->n_probing = 0;
 
-    avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_UNCOMMITED);
+    avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_UNCOMMITED);
 }
 
 int avahi_entry_is_commited(AvahiEntry *e) {
@@ -2260,26 +2306,26 @@ int avahi_entry_is_commited(AvahiEntry *e) {
         e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED;
 }
 
-AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g) {
+AvahiEntryGroupState avahi_s_entry_group_get_state(AvahiSEntryGroup *g) {
     assert(g);
     assert(!g->dead);
 
     return g->state;
 }
 
-void avahi_entry_group_set_data(AvahiEntryGroup *g, void* userdata) {
+void avahi_s_entry_group_set_data(AvahiSEntryGroup *g, void* userdata) {
     assert(g);
 
     g->userdata = userdata;
 }
 
-void* avahi_entry_group_get_data(AvahiEntryGroup *g) {
+void* avahi_s_entry_group_get_data(AvahiSEntryGroup *g) {
     assert(g);
 
     return g->userdata;
 }
 
-int avahi_entry_group_is_empty(AvahiEntryGroup *g) {
+int avahi_s_entry_group_is_empty(AvahiSEntryGroup *g) {
     AvahiEntry *e;
     assert(g);