X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fserver.c;h=a020f6432f0fdfa8b866038588d6d7ca899689a6;hb=219241ab5223b705ade51485ea9227b0a6089c0d;hp=3ccaddc15c9208fec38dd6c7e64ee7ba8b5eac53;hpb=4ff0807c04fcc239de52a793bceb88e7f3408f3f;p=catta diff --git a/avahi-core/server.c b/avahi-core/server.c index 3ccaddc..a020f64 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -35,8 +35,9 @@ #include "iface.h" #include "socket.h" #include "browse.h" +#include "log.h" -#define AVAHI_HOST_RR_HOLDOFF_MSEC 1000 +#define AVAHI_HOST_RR_HOLDOFF_MSEC 2000 static void free_entry(AvahiServer*s, AvahiEntry *e) { AvahiEntry *t; @@ -161,7 +162,7 @@ void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, g_assert(i); g_assert(k); -/* g_message("Posting responses matching [%s]", txt = avahi_key_to_string(k)); */ +/* avahi_log_debug("Posting responses matching [%s]", txt = avahi_key_to_string(k)); */ /* g_free(txt); */ if (avahi_key_is_pattern(k)) { @@ -226,16 +227,21 @@ static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface * gint cmp; n = e->by_key_next; - if (e->dead || !avahi_entry_probing(s, e, i)) + if (e->dead) continue; if ((cmp = avahi_record_lexicographical_compare(e->record, record)) == 0) { ours = TRUE; break; - } else if (cmp > 0) - won = TRUE; - else /* cmp < 0 */ - lost = TRUE; + } else { + + if (avahi_entry_probing(s, e, i)) { + if (cmp > 0) + won = TRUE; + else /* cmp < 0 */ + lost = TRUE; + } + } } t = avahi_record_to_string(record); @@ -243,9 +249,9 @@ static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface * if (!ours) { if (won) - g_message("Recieved conflicting probe [%s]. Local host won.", t); + avahi_log_debug("xxx Recieved conflicting probe [%s]. Local host won.", t); else if (lost) { - g_message("Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t); + avahi_log_debug("yyy Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t); withdraw_rrset(s, record->key); } } @@ -262,7 +268,7 @@ static gboolean handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord * g_assert(record); -/* g_message("CHECKING FOR CONFLICT: [%s]", t); */ +/* avahi_log_debug("CHECKING FOR CONFLICT: [%s]", t); */ for (e = g_hash_table_lookup(s->entries_by_key, record->key); e; e = n) { n = e->by_key_next; @@ -272,36 +278,36 @@ static gboolean handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord * /* Either our entry or the other is intended to be unique, so let's check */ - if (avahi_entry_registered(s, e, i)) { - - if (avahi_record_equal_no_ttl(e->record, record)) { - ours = TRUE; /* We have an identical record, so this is no conflict */ + if (avahi_record_equal_no_ttl(e->record, record)) { + ours = TRUE; /* We have an identical record, so this is no conflict */ + + /* Check wheter there is a TTL conflict */ + if (record->ttl <= e->record->ttl/2 && + avahi_entry_registered(s, e, i)) { + gchar *t; + /* Refresh */ + t = avahi_record_to_string(record); - /* Check wheter there is a TTL conflict */ - if (record->ttl <= e->record->ttl/2) { - gchar *t; - /* Refresh */ - t = avahi_record_to_string(record); - - g_message("Recieved record with bad TTL [%s]. Refreshing.", t); - avahi_server_prepare_matching_responses(s, i, e->record->key, FALSE); - valid = FALSE; - - g_free(t); - } + avahi_log_debug("Recieved record with bad TTL [%s]. Refreshing.", t); + avahi_server_prepare_matching_responses(s, i, e->record->key, FALSE); + valid = FALSE; + + g_free(t); + } + + /* There's no need to check the other entries of this RRset */ + break; + + } else { + + if (avahi_entry_registered(s, e, i)) { - /* There's no need to check the other entries of this RRset */ - break; - } else { /* A conflict => we have to return to probe mode */ conflict = TRUE; conflicting_entry = e; - } - } else if (avahi_entry_probing(s, e, i)) { + } else if (avahi_entry_probing(s, e, i)) { - if (!avahi_record_equal_no_ttl(record, e->record)) { - /* We are currently registering a matching record, but * someone else already claimed it, so let's * withdraw */ @@ -311,7 +317,7 @@ static gboolean handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord * } } -/* g_message("ours=%i conflict=%i", ours, conflict); */ +/* avahi_log_debug("ours=%i conflict=%i", ours, conflict); */ if (!ours && conflict) { gchar *t; @@ -321,11 +327,11 @@ static gboolean handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord * t = avahi_record_to_string(record); if (withdraw_immediately) { - g_message("Recieved conflicting record [%s] with local record to be. Withdrawing.", t); + avahi_log_debug("Recieved conflicting record [%s] with local record to be. Withdrawing.", t); withdraw_rrset(s, record->key); } else { g_assert(conflicting_entry); - g_message("Recieved conflicting record [%s]. Resetting our record.", t); + 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 @@ -375,7 +381,7 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT); else { gchar *t = avahi_record_to_string(r); - g_warning("Record [%s] not fitting in legacy unicast packet, dropping.", t); + avahi_log_warn("Record [%s] not fitting in legacy unicast packet, dropping.", t); g_free(t); } @@ -439,7 +445,7 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP avahi_dns_packet_free(reply); gchar *t = avahi_record_to_string(r); - g_warning("Record [%s] too large, doesn't fit in any packet!", t); + avahi_log_warn("Record [%s] too large, doesn't fit in any packet!", t); g_free(t); break; } else @@ -478,7 +484,7 @@ static void reflect_response(AvahiServer *s, AvahiInterface *i, AvahiRecord *r, return; for (j = s->monitor->interfaces; j; j = j->interface_next) - if (j != i && (s->config.ipv_reflect || j->protocol == i->protocol)) + if (j != i && (s->config.reflect_ipv || j->protocol == i->protocol)) avahi_interface_post_response(j, r, flush_cache, NULL, TRUE); } @@ -505,7 +511,7 @@ static void reflect_query(AvahiServer *s, AvahiInterface *i, AvahiKey *k) { return; for (j = s->monitor->interfaces; j; j = j->interface_next) - if (j != i && (s->config.ipv_reflect || j->protocol == i->protocol)) { + if (j != i && (s->config.reflect_ipv || j->protocol == i->protocol)) { /* Post the query to other networks */ avahi_interface_post_query(j, k, TRUE); @@ -527,7 +533,7 @@ static void reflect_probe(AvahiServer *s, AvahiInterface *i, AvahiRecord *r) { return; for (j = s->monitor->interfaces; j; j = j->interface_next) - if (j != i && (s->config.ipv_reflect || j->protocol == i->protocol)) + if (j != i && (s->config.reflect_ipv || j->protocol == i->protocol)) avahi_interface_post_probe(j, r, TRUE); } @@ -539,7 +545,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac g_assert(i); g_assert(a); -/* g_message("query"); */ +/* avahi_log_debug("query"); */ g_assert(avahi_record_list_empty(s->record_list)); @@ -549,13 +555,19 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac gboolean unicast_response = FALSE; if (!(key = avahi_dns_packet_consume_key(p, &unicast_response))) { - g_warning("Packet too short (1)"); + avahi_log_warn("Packet too short (1)"); goto fail; } if (!legacy_unicast) reflect_query(s, i, key); - avahi_query_scheduler_incoming(i->query_scheduler, key); + + if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 && + !(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_TC)) + /* Allow our own queries to be suppressed by incoming + * queries only when they do not include known answers */ + avahi_query_scheduler_incoming(i->query_scheduler, key); + avahi_server_prepare_matching_responses(s, i, key, unicast_response); avahi_key_unref(key); } @@ -566,7 +578,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac gboolean unique = FALSE; if (!(record = avahi_dns_packet_consume_record(p, &unique))) { - g_warning("Packet too short (2)"); + avahi_log_warn("Packet too short (2)"); goto fail; } @@ -584,7 +596,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac gboolean unique = FALSE; if (!(record = avahi_dns_packet_consume_record(p, &unique))) { - g_warning("Packet too short (3)"); + avahi_log_warn("Packet too short (3)"); goto fail; } @@ -614,7 +626,7 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter g_assert(i); g_assert(a); -/* g_message("response"); */ +/* avahi_log_debug("response"); */ for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) + avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT); n > 0; n--) { @@ -623,13 +635,13 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter /* gchar *txt; */ if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) { - g_warning("Packet too short (4)"); + avahi_log_warn("Packet too short (4)"); break; } if (record->key->type != AVAHI_DNS_TYPE_ANY) { -/* g_message("Handling response: %s", txt = avahi_record_to_string(record)); */ +/* avahi_log_debug("Handling response: %s", txt = avahi_record_to_string(record)); */ /* g_free(txt); */ if (handle_conflict(s, i, record, cache_flush, a)) { @@ -739,7 +751,7 @@ static void reflect_legacy_unicast_query_packet(AvahiServer *s, AvahiDnsPacket * if (!s->config.enable_reflector) return; -/* g_message("legacy unicast reflectr"); */ +/* avahi_log_debug("legacy unicast reflectr"); */ /* Reflecting legacy unicast queries is a little more complicated than reflecting normal queries, since we must route the @@ -751,7 +763,7 @@ static void reflect_legacy_unicast_query_packet(AvahiServer *s, AvahiDnsPacket * if (!(slot = allocate_slot(s))) { /* No slot available, we drop this legacy unicast query */ - g_warning("No slot available for legacy unicast reflection, dropping query packet."); + avahi_log_warn("No slot available for legacy unicast reflection, dropping query packet."); return; } @@ -769,7 +781,7 @@ static void reflect_legacy_unicast_query_packet(AvahiServer *s, AvahiDnsPacket * for (j = s->monitor->interfaces; j; j = j->interface_next) if (avahi_interface_relevant(j) && j != i && - (s->config.ipv_reflect || j->protocol == i->protocol)) { + (s->config.reflect_ipv || j->protocol == i->protocol)) { if (j->protocol == AF_INET && s->fd_legacy_unicast_ipv4 >= 0) { avahi_send_dns_packet_ipv4(s->fd_legacy_unicast_ipv4, j->hardware->index, p, NULL, 0); @@ -799,7 +811,7 @@ static gboolean originates_from_local_legacy_unicast_socket(AvahiServer *s, cons socklen_t l = sizeof(lsa); if (getsockname(s->fd_legacy_unicast_ipv4, &lsa, &l) != 0) - g_warning("getsockname(): %s", strerror(errno)); + avahi_log_warn("getsockname(): %s", strerror(errno)); else return lsa.sin_port == ((struct sockaddr_in*) sa)->sin_port; @@ -810,7 +822,7 @@ static gboolean originates_from_local_legacy_unicast_socket(AvahiServer *s, cons socklen_t l = sizeof(lsa); if (getsockname(s->fd_legacy_unicast_ipv6, &lsa, &l) != 0) - g_warning("getsockname(): %s", strerror(errno)); + avahi_log_warn("getsockname(): %s", strerror(errno)); else return lsa.sin6_port == ((struct sockaddr_in6*) sa)->sin6_port; } @@ -830,11 +842,11 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family)) || !avahi_interface_relevant(i)) { - g_warning("Recieved packet from invalid interface."); + avahi_log_warn("Recieved packet from invalid interface."); return; } -/* g_message("new packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol); */ +/* avahi_log_debug("new packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol); */ port = avahi_port_from_sockaddr(sa); avahi_address_from_sockaddr(sa, &a); @@ -848,7 +860,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock return; if (avahi_dns_packet_check_valid(p) < 0) { - g_warning("Recieved invalid packet."); + avahi_log_warn("Recieved invalid packet."); return; } @@ -856,7 +868,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock gboolean legacy_unicast = FALSE; if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT) != 0) { - g_warning("Invalid query packet."); + avahi_log_warn("Invalid query packet."); return; } @@ -865,7 +877,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock if ((avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) != 0 || avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0)) { - g_warning("Invalid legacy unicast query packet."); + avahi_log_warn("Invalid legacy unicast query packet."); return; } @@ -877,16 +889,16 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock handle_query_packet(s, p, i, &a, port, legacy_unicast); -/* g_message("Handled query"); */ +/* avahi_log_debug("Handled query"); */ } else { if (port != AVAHI_MDNS_PORT) { - g_warning("Recieved repsonse with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol); + avahi_log_warn("Recieved repsonse with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol); return; } if (ttl != 255) { - g_warning("Recieved response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol); + avahi_log_warn("Recieved response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol); if (s->config.check_response_ttl) return; } @@ -894,12 +906,12 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sock if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT) != 0 || avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 || avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0) { - g_warning("Invalid response packet."); + avahi_log_warn("Invalid response packet."); return; } handle_response_packet(s, p, i, &a); -/* g_message("Handled response"); */ +/* avahi_log_debug("Handled response"); */ } } @@ -916,11 +928,11 @@ static void dispatch_legacy_unicast_packet(AvahiServer *s, AvahiDnsPacket *p, co if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family)) || !avahi_interface_relevant(i)) { - g_warning("Recieved packet from invalid interface."); + avahi_log_warn("Recieved packet from invalid interface."); return; } -/* g_message("new legacy unicast packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol); */ +/* avahi_log_debug("new legacy unicast packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol); */ port = avahi_port_from_sockaddr(sa); avahi_address_from_sockaddr(sa, &a); @@ -930,12 +942,12 @@ static void dispatch_legacy_unicast_packet(AvahiServer *s, AvahiDnsPacket *p, co return; if (avahi_dns_packet_check_valid(p) < 0 || avahi_dns_packet_is_query(p)) { - g_warning("Recieved invalid packet."); + avahi_log_warn("Recieved invalid packet."); return; } if (!(slot = find_slot(s, avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ID)))) { - g_warning("Recieved legacy unicast response with unknown id"); + avahi_log_warn("Recieved legacy unicast response with unknown id"); return; } @@ -1099,7 +1111,7 @@ static void register_hinfo(AvahiServer *s) { g_assert(s); - if (!s->config.register_hinfo || s->hinfo_entry_group) + if (!s->config.publish_hinfo || s->hinfo_entry_group) return; s->hinfo_entry_group = avahi_entry_group_new(s, avahi_host_rr_entry_group_callback, NULL); @@ -1130,7 +1142,7 @@ static void register_localhost(AvahiServer *s) { static void register_browse_domain(AvahiServer *s) { g_assert(s); - if (!s->config.announce_domain || s->browse_domain_entry_group) + if (!s->config.publish_domain || s->browse_domain_entry_group) return; s->browse_domain_entry_group = avahi_entry_group_new(s, NULL, NULL); @@ -1187,7 +1199,7 @@ static void delayed_register_stuff(AvahiServer *s) { s->register_time_event = avahi_time_event_queue_add(s->time_event_queue, &tv, register_time_event_callback, s); } -void avahi_server_set_host_name(AvahiServer *s, const gchar *host_name) { +gint avahi_server_set_host_name(AvahiServer *s, const gchar *host_name) { g_assert(s); g_assert(host_name); @@ -1200,9 +1212,10 @@ void avahi_server_set_host_name(AvahiServer *s, const gchar *host_name) { update_fqdn(s); delayed_register_stuff(s); + return 0; } -void avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name) { +gint avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name) { g_assert(s); g_assert(domain_name); @@ -1214,6 +1227,7 @@ void avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name) { update_fqdn(s); delayed_register_stuff(s); + return 0; } @@ -1260,17 +1274,14 @@ AvahiServer *avahi_server_new(GMainContext *c, const AvahiServerConfig *sc, Avah } if (s->fd_ipv4 < 0 && s->config.use_ipv4) - g_message("Failed to create IPv4 socket, proceeding in IPv6 only mode"); + avahi_log_notice("Failed to create IPv4 socket, proceeding in IPv6 only mode"); else if (s->fd_ipv6 < 0 && s->config.use_ipv6) - g_message("Failed to create IPv6 socket, proceeding in IPv4 only mode"); + avahi_log_notice("Failed to create IPv6 socket, proceeding in IPv4 only mode"); s->fd_legacy_unicast_ipv4 = s->fd_ipv4 >= 0 && s->config.enable_reflector ? avahi_open_legacy_unicast_socket_ipv4() : -1; s->fd_legacy_unicast_ipv6 = s->fd_ipv6 >= 0 && s->config.enable_reflector ? avahi_open_legacy_unicast_socket_ipv6() : -1; - - if (c) - g_main_context_ref(s->context = c); - else - s->context = g_main_context_default(); + + g_main_context_ref(s->context = (c ? c : g_main_context_default())); /* Prepare IO source registration */ s->source = g_source_new(&source_funcs, sizeof(GSource) + sizeof(AvahiServer*)); @@ -1391,7 +1402,37 @@ void avahi_server_free(AvahiServer* s) { g_free(s); } -void avahi_server_add( +static gint check_record_conflict(AvahiServer *s, gint interface, guchar protocol, AvahiRecord *r, AvahiEntryFlags flags) { + AvahiEntry *e; + + g_assert(s); + g_assert(r); + + for (e = g_hash_table_lookup(s->entries_by_key, r->key); e; e = e->by_key_next) { + if (e->dead) + continue; + + if (!(flags & AVAHI_ENTRY_UNIQUE) && !(e->flags & AVAHI_ENTRY_UNIQUE)) + continue; + + if ((flags & AVAHI_ENTRY_ALLOWMUTIPLE) && (e->flags & AVAHI_ENTRY_ALLOWMUTIPLE) ) + continue; + + if (interface <= 0 || + e->interface <= 0 || + e->interface == interface || + protocol == AF_UNSPEC || + e->protocol == AF_UNSPEC || + e->protocol == protocol) + + return -1; + + } + + return 0; +} + +gint avahi_server_add( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1405,6 +1446,9 @@ void avahi_server_add( g_assert(r->key->type != AVAHI_DNS_TYPE_ANY); + if (check_record_conflict(s, interface, protocol, r, flags) < 0) + return -1; + e = g_new(AvahiEntry, 1); e->server = s; e->record = avahi_record_ref(r); @@ -1428,7 +1472,10 @@ void avahi_server_add( AVAHI_LLIST_PREPEND(AvahiEntry, by_group, g->entries, e); avahi_announce_entry(s, e); + + return 0; } + const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state) { AvahiEntry **e = (AvahiEntry**) state; g_assert(s); @@ -1467,7 +1514,7 @@ void avahi_server_dump(AvahiServer *s, FILE *f) { avahi_dump_caches(s->monitor, f); } -void avahi_server_add_ptr( +gint avahi_server_add_ptr( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1477,16 +1524,18 @@ void avahi_server_add_ptr( const gchar *dest) { AvahiRecord *r; + gint ret; g_assert(dest); r = avahi_record_new_full(name ? name : s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR); r->data.ptr.name = avahi_normalize_name(dest); - avahi_server_add(s, g, interface, protocol, flags, r); + ret = avahi_server_add(s, g, interface, protocol, flags, r); avahi_record_unref(r); + return ret; } -void avahi_server_add_address( +gint avahi_server_add_address( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1496,6 +1545,7 @@ void avahi_server_add_address( AvahiAddress *a) { gchar *n = NULL; + gint ret = 0; g_assert(s); g_assert(a); @@ -1507,11 +1557,11 @@ void avahi_server_add_address( r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A); r->data.a.address = a->data.ipv4; - avahi_server_add(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, r); + ret = avahi_server_add(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE | AVAHI_ENTRY_ALLOWMUTIPLE, r); avahi_record_unref(r); reverse = avahi_reverse_lookup_name_ipv4(&a->data.ipv4); - avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, reverse, name); + ret |= avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, reverse, name); g_free(reverse); } else { @@ -1520,22 +1570,24 @@ void avahi_server_add_address( r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA); r->data.aaaa.address = a->data.ipv6; - avahi_server_add(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, r); + ret = avahi_server_add(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE | AVAHI_ENTRY_ALLOWMUTIPLE, r); avahi_record_unref(r); reverse = avahi_reverse_lookup_name_ipv6_arpa(&a->data.ipv6); - avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, reverse, name); + ret |= avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, reverse, name); g_free(reverse); reverse = avahi_reverse_lookup_name_ipv6_int(&a->data.ipv6); - avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, reverse, name); + ret |= avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, reverse, name); g_free(reverse); } g_free(n); + + return ret; } -void avahi_server_add_text_strlst( +gint avahi_server_add_text_strlst( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1545,16 +1597,19 @@ void avahi_server_add_text_strlst( AvahiStringList *strlst) { AvahiRecord *r; + gint ret; g_assert(s); r = avahi_record_new_full(name ? name : s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT); r->data.txt.string_list = strlst; - avahi_server_add(s, g, interface, protocol, flags, r); + ret = avahi_server_add(s, g, interface, protocol, flags, r); avahi_record_unref(r); + + return ret; } -void avahi_server_add_text_va( +gint avahi_server_add_text_va( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1565,10 +1620,10 @@ void avahi_server_add_text_va( g_assert(s); - avahi_server_add_text_strlst(s, g, interface, protocol, flags, name, avahi_string_list_new_va(va)); + return avahi_server_add_text_strlst(s, g, interface, protocol, flags, name, avahi_string_list_new_va(va)); } -void avahi_server_add_text( +gint avahi_server_add_text( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1578,12 +1633,15 @@ void avahi_server_add_text( ...) { va_list va; + gint ret; g_assert(s); va_start(va, name); - avahi_server_add_text_va(s, g, interface, protocol, flags, name, va); + ret = avahi_server_add_text_va(s, g, interface, protocol, flags, name, va); va_end(va); + + return ret; } static void escape_service_name(gchar *d, guint size, const gchar *s) { @@ -1608,7 +1666,7 @@ static void escape_service_name(gchar *d, guint size, const gchar *s) { *(d++) = 0; } -void avahi_server_add_service_strlst( +gint avahi_server_add_service_strlst( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1622,6 +1680,7 @@ void avahi_server_add_service_strlst( gchar ptr_name[256], svc_name[256], ename[64], enum_ptr[256]; AvahiRecord *r; + gint ret = 0; g_assert(s); g_assert(type); @@ -1641,23 +1700,25 @@ void avahi_server_add_service_strlst( snprintf(ptr_name, sizeof(ptr_name), "%s.%s", type, domain); snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, type, domain); - avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, ptr_name, svc_name); + ret = avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, ptr_name, svc_name); r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV); r->data.srv.priority = 0; r->data.srv.weight = 0; r->data.srv.port = port; r->data.srv.name = avahi_normalize_name(host); - avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, r); + ret |= avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, r); avahi_record_unref(r); - avahi_server_add_text_strlst(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, svc_name, strlst); + ret |= avahi_server_add_text_strlst(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, svc_name, strlst); snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", domain); - avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, enum_ptr, ptr_name); + ret |=avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, enum_ptr, ptr_name); + + return ret; } -void avahi_server_add_service_va( +gint avahi_server_add_service_va( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1673,10 +1734,10 @@ void avahi_server_add_service_va( g_assert(type); g_assert(name); - 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, type, name, domain, host, port, avahi_string_list_new_va(va)); } -void avahi_server_add_service( +gint avahi_server_add_service( AvahiServer *s, AvahiEntryGroup *g, gint interface, @@ -1689,14 +1750,16 @@ void avahi_server_add_service( ... ){ va_list va; + gint ret; g_assert(s); g_assert(type); g_assert(name); va_start(va, port); - 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, type, name, domain, host, port, va); va_end(va); + return ret; } static void post_query_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) { @@ -1765,16 +1828,18 @@ void avahi_entry_group_free(AvahiEntryGroup *g) { g->server->need_entry_cleanup = TRUE; } -void avahi_entry_group_commit(AvahiEntryGroup *g) { +gint avahi_entry_group_commit(AvahiEntryGroup *g) { g_assert(g); g_assert(!g->dead); if (g->state != AVAHI_ENTRY_GROUP_UNCOMMITED) - return; + return -1; avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING); avahi_announce_group(g->server, g); avahi_entry_group_check_probed(g, FALSE); + + return 0; } gboolean avahi_entry_commited(AvahiEntry *e) { @@ -1845,17 +1910,18 @@ AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c) { g_assert(c); memset(c, 0, sizeof(AvahiServerConfig)); - c->register_hinfo = TRUE; - c->register_addresses = TRUE; c->use_ipv6 = TRUE; c->use_ipv4 = TRUE; c->host_name = NULL; c->domain_name = NULL; c->check_response_ttl = TRUE; - c->announce_domain = TRUE; + c->publish_hinfo = TRUE; + c->publish_addresses = TRUE; + c->publish_workstation = TRUE; + c->publish_domain = TRUE; c->use_iff_running = FALSE; c->enable_reflector = FALSE; - c->ipv_reflect = FALSE; + c->reflect_ipv = FALSE; return c; }