X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fserver.c;h=d63f5eca557a13d0c7b85e20f4657fbac856f2c8;hb=f9e13b26d751151c8dab7bbaf1b318554ef40c5b;hp=719f9a91fa1432108338cb6a86a41f8548d63c3f;hpb=41f4062e34d1e13c2d93d971334efbad060b6df0;p=catta diff --git a/avahi-core/server.c b/avahi-core/server.c index 719f9a9..d63f5ec 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -135,7 +135,7 @@ void avahi_server_enumerate_aux_records(AvahiServer *s, AvahiInterface *i, Avahi g_assert(r); g_assert(callback); - if (r->key->class == AVAHI_DNS_CLASS_IN) { + if (r->key->clazz == AVAHI_DNS_CLASS_IN) { if (r->key->type == AVAHI_DNS_TYPE_PTR) { enum_aux_records(s, i, r->data.ptr.name, AVAHI_DNS_TYPE_SRV, callback, userdata); enum_aux_records(s, i, r->data.ptr.name, AVAHI_DNS_TYPE_TXT, callback, userdata); @@ -223,6 +223,10 @@ static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface * g_assert(record); g_assert(i); + t = avahi_record_to_string(record); + +/* avahi_log_debug("incoming_probe()"); */ + for (e = g_hash_table_lookup(s->entries_by_key, record->key); e; e = n) { gint cmp; n = e->by_key_next; @@ -244,16 +248,15 @@ static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface * } } - t = avahi_record_to_string(record); - if (!ours) { if (won) - avahi_log_debug("xxx Recieved conflicting probe [%s]. Local host won.", t); + avahi_log_debug("Recieved conflicting probe [%s]. Local host won.", t); else if (lost) { - avahi_log_debug("yyy Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t); + avahi_log_debug("Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t); withdraw_rrset(s, record->key); - } + }/* else */ +/* avahi_log_debug("Not conflicting probe"); */ } g_free(t); @@ -334,7 +337,7 @@ static gboolean handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord * avahi_log_debug("Recieved conflicting record [%s]. Resetting our record.", t); avahi_entry_return_to_initial_state(s, conflicting_entry, i); - /* Local unique records are returned to probin + /* Local unique records are returned to probing * state. Local shared records are reannounced. */ } @@ -361,7 +364,7 @@ static void append_aux_records_to_list(AvahiServer *s, AvahiInterface *i, AvahiR avahi_server_enumerate_aux_records(s, i, r, append_aux_callback, &unicast_response); } -void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, guint16 port, gboolean legacy_unicast) { +void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, guint16 port, gboolean legacy_unicast, gboolean immediately) { g_assert(s); g_assert(i); @@ -405,7 +408,7 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP while ((r = avahi_record_list_next(s->record_list, &flush_cache, &unicast_response, &auxiliary))) { - if (!avahi_interface_post_response(i, r, flush_cache, a, !tc && flush_cache && !auxiliary) && unicast_response) { + if (!avahi_interface_post_response(i, r, flush_cache, a, immediately || (flush_cache && !tc && !auxiliary)) && unicast_response) { append_aux_records_to_list(s, i, r, unicast_response); @@ -539,6 +542,7 @@ static void reflect_probe(AvahiServer *s, AvahiInterface *i, AvahiRecord *r) { static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, guint16 port, gboolean legacy_unicast) { guint n; + gboolean is_probe; g_assert(s); g_assert(p); @@ -548,6 +552,8 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac /* avahi_log_debug("query"); */ g_assert(avahi_record_list_empty(s->record_list)); + + is_probe = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) > 0; /* Handle the questions */ for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT); n > 0; n --) { @@ -609,7 +615,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac } if (!avahi_record_list_empty(s->record_list)) - avahi_server_generate_response(s, i, p, a, port, legacy_unicast); + avahi_server_generate_response(s, i, p, a, port, legacy_unicast, is_probe); return; @@ -657,7 +663,7 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter records have been scheduling for sending. We need to flush them here. */ if (!avahi_record_list_empty(s->record_list)) - avahi_server_generate_response(s, i, NULL, NULL, 0, FALSE); + avahi_server_generate_response(s, i, NULL, NULL, 0, FALSE, TRUE); } static AvahiLegacyUnicastReflectSlot* allocate_slot(AvahiServer *s) { @@ -1246,7 +1252,7 @@ gint avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name) { withdraw_host_rrs(s); g_free(s->domain_name); - s->domain_name = domain_name ? avahi_normalize_name(domain_name) : g_strdup("local."); + s->domain_name = domain_name ? avahi_normalize_name(domain_name) : g_strdup("local"); update_fqdn(s); delayed_register_stuff(s); @@ -1344,7 +1350,7 @@ AvahiServer *avahi_server_new(GMainContext *c, const AvahiServerConfig *sc, Avah /* Get host name */ s->host_name = s->config.host_name ? avahi_normalize_name(s->config.host_name) : avahi_get_host_name(); s->host_name[strcspn(s->host_name, ".")] = 0; - s->domain_name = s->config.domain_name ? avahi_normalize_name(s->config.domain_name) : g_strdup("local."); + s->domain_name = s->config.domain_name ? avahi_normalize_name(s->config.domain_name) : g_strdup("local"); s->host_name_fqdn = NULL; update_fqdn(s); @@ -1524,25 +1530,29 @@ const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void return avahi_record_ref((*e)->record); } -void avahi_server_dump(AvahiServer *s, FILE *f) { +void avahi_server_dump(AvahiServer *s, AvahiDumpCallback callback, gpointer userdata) { AvahiEntry *e; + g_assert(s); - g_assert(f); + g_assert(callback); - fprintf(f, "\n;;; ZONE DUMP FOLLOWS ;;;\n"); + callback(";;; ZONE DUMP FOLLOWS ;;;", userdata); for (e = s->entries; e; e = e->entries_next) { gchar *t; + gchar ln[256]; if (e->dead) continue; t = avahi_record_to_string(e->record); - fprintf(f, "%s ; iface=%i proto=%i\n", t, e->interface, e->protocol); + snprintf(ln, sizeof(ln), "%s ; iface=%i proto=%i", t, e->interface, e->protocol); g_free(t); + + callback(ln, userdata); } - avahi_dump_caches(s->monitor, f); + avahi_dump_caches(s->monitor, callback, userdata); } gint avahi_server_add_ptr( @@ -1706,14 +1716,15 @@ gint avahi_server_add_service_strlst( AvahiEntryGroup *g, gint interface, guchar protocol, - const gchar *type, const gchar *name, + const gchar *type, const gchar *domain, const gchar *host, guint16 port, AvahiStringList *strlst) { gchar ptr_name[256], svc_name[256], ename[64], enum_ptr[256]; + gchar *t, *d; AvahiRecord *r; gint ret = 0; @@ -1732,9 +1743,12 @@ gint avahi_server_add_service_strlst( if (!host) host = s->host_name_fqdn; - snprintf(ptr_name, sizeof(ptr_name), "%s.%s", type, domain); - snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, type, domain); + d = avahi_normalize_name(domain); + t = avahi_normalize_name(type); + snprintf(ptr_name, sizeof(ptr_name), "%s.%s", t, d); + snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, t, d); + ret = avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, ptr_name, svc_name); r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME); @@ -1747,9 +1761,12 @@ gint avahi_server_add_service_strlst( ret |= avahi_server_add_txt_strlst(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst); - snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", domain); + snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", d); ret |=avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, enum_ptr, ptr_name); + g_free(d); + g_free(t); + return ret; } @@ -1758,8 +1775,8 @@ gint avahi_server_add_service_va( AvahiEntryGroup *g, gint interface, guchar protocol, - const gchar *type, const gchar *name, + const gchar *type, const gchar *domain, const gchar *host, guint16 port, @@ -1769,7 +1786,7 @@ gint avahi_server_add_service_va( g_assert(type); g_assert(name); - return avahi_server_add_service_strlst(s, g, interface, protocol, type, name, domain, host, port, avahi_string_list_new_va(va)); + return avahi_server_add_service_strlst(s, g, interface, protocol, name, type, domain, host, port, avahi_string_list_new_va(va)); } gint avahi_server_add_service( @@ -1777,8 +1794,8 @@ gint avahi_server_add_service( AvahiEntryGroup *g, gint interface, guchar protocol, - const gchar *type, const gchar *name, + const gchar *type, const gchar *domain, const gchar *host, guint16 port, @@ -1792,7 +1809,7 @@ gint avahi_server_add_service( g_assert(name); va_start(va, port); - ret = avahi_server_add_service_va(s, g, interface, protocol, type, name, domain, host, port, va); + ret = avahi_server_add_service_va(s, g, interface, protocol, name, type, domain, host, port, va); va_end(va); return ret; } @@ -1867,7 +1884,7 @@ gint avahi_server_add_dns_server_name( guint16 port /** should be 53 */) { gint ret = -1; - gchar t[256]; + gchar t[256], *d; AvahiRecord *r; g_assert(s); @@ -1880,7 +1897,9 @@ gint avahi_server_add_dns_server_name( } else domain = s->domain_name; - snprintf(t, sizeof(t), "%s.%s", type == AVAHI_DNS_SERVER_RESOLVE ? "_domain._udp" : "_dns-update._udp", domain); + d = avahi_normalize_name(domain); + snprintf(t, sizeof(t), "%s.%s", type == AVAHI_DNS_SERVER_RESOLVE ? "_domain._udp" : "_dns-update._udp", d); + g_free(d); r = avahi_record_new_full(t, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME); r->data.srv.priority = 0; @@ -1893,7 +1912,6 @@ gint avahi_server_add_dns_server_name( return ret; } - static void post_query_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) { AvahiKey *k = userdata;