#include <errno.h>
#include <stdio.h>
#include <assert.h>
+#include <stdlib.h>
#include <avahi-common/domain.h>
#include <avahi-common/timeval.h>
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 */
s->legacy_unicast_reflect_slots = NULL;
s->legacy_unicast_reflect_id = 0;
+
+ do {
+ s->local_service_cookie = (uint32_t) rand() * (uint32_t) rand();
+ } while (s->local_service_cookie == AVAHI_SERVICE_COOKIE_INVALID);
/* Get host name */
s->host_name = s->config.host_name ? avahi_normalize_name(s->config.host_name) : avahi_get_host_name();
*(d++) = 0;
}
+static AvahiStringList *add_magic_cookie(
+ AvahiServer *s,
+ AvahiStringList *strlst) {
+
+ assert(s);
+
+ if (!s->config.add_service_cookie)
+ return strlst;
+
+ if (avahi_string_list_find(strlst, AVAHI_SERVICE_COOKIE))
+ /* This string list already contains a magic cookie */
+ return strlst;
+
+ return avahi_string_list_add_printf(strlst, AVAHI_SERVICE_COOKIE"=%u", s->local_service_cookie);
+}
+
static int server_add_service_strlst_nocopy(
AvahiServer *s,
AvahiSEntryGroup *g,
if (ret < 0)
goto fail;
+ strlst = add_magic_cookie(s, strlst);
+
ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
strlst = NULL;
c->use_iff_running = 0;
c->enable_reflector = 0;
c->reflect_ipv = 0;
+ c->add_service_cookie = 1;
return c;
}
return s->error = error;
}
+uint32_t avahi_server_get_local_service_cookie(AvahiServer *s) {
+ assert(s);
+
+ return s->local_service_cookie;
+}