X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fserver.c;h=ebd0bff575e258d44b459955717599182854c2ad;hb=7686f1b38b13a660ac14b799c62f453fa012b4d7;hp=017605efec2428aed34a2eddfe0fe29030521383;hpb=ee6736004d8662875e1a4a4a4f48faae7ea889b4;p=catta diff --git a/avahi-core/server.c b/avahi-core/server.c index 017605e..ebd0bff 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -228,9 +228,9 @@ static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface * char *t = avahi_record_to_string(record); if (won) - avahi_log_debug("Recieved conflicting probe [%s]. Local host won.", t); + avahi_log_debug("Received conflicting probe [%s]. Local host won.", t); else if (lost) { - avahi_log_debug("Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t); + avahi_log_debug("Received conflicting probe [%s]. Local host lost. Withdrawing.", t); withdraw_rrset(s, record->key); } @@ -262,7 +262,7 @@ static int handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *recor /* Refresh */ t = avahi_record_to_string(record); - avahi_log_debug("Recieved goodbye record for one of our records [%s]. Refreshing.", t); + avahi_log_debug("Received goodbye record for one of our records [%s]. Refreshing.", t); avahi_server_prepare_matching_responses(s, i, e->record->key, 0); valid = 0; @@ -289,7 +289,7 @@ static int handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *recor /* Refresh */ t = avahi_record_to_string(record); - avahi_log_debug("Recieved record with bad TTL [%s]. Refreshing.", t); + avahi_log_debug("Received record with bad TTL [%s]. Refreshing.", t); avahi_server_prepare_matching_responses(s, i, e->record->key, 0); valid = 0; @@ -326,11 +326,11 @@ static int handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *recor t = avahi_record_to_string(record); if (withdraw_immediately) { - avahi_log_debug("Recieved conflicting record [%s] with local record to be. Withdrawing.", t); + avahi_log_debug("Received conflicting record [%s] with local record to be. Withdrawing.", t); withdraw_rrset(s, record->key); } else { assert(conflicting_entry); - avahi_log_debug("Recieved conflicting record [%s]. Resetting our record.", t); + avahi_log_debug("Received conflicting record [%s]. Resetting our record.", t); avahi_entry_return_to_initial_state(s, conflicting_entry, i); /* Local unique records are returned to probing @@ -370,7 +370,7 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP AvahiDnsPacket *reply; AvahiRecord *r; - if (!(reply = avahi_dns_packet_new_reply(p, 512 /* unicast DNS maximum packet size is 512 */ , 1, 1))) + if (!(reply = avahi_dns_packet_new_reply(p, 512 + AVAHI_DNS_PACKET_EXTRA_SIZE /* unicast DNS maximum packet size is 512 */ , 1, 1))) return; /* OOM */ while ((r = avahi_record_list_next(s->record_list, NULL, NULL, NULL))) { @@ -438,7 +438,6 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP * the specific header field, and return to the caller */ avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT); - break; } @@ -449,21 +448,32 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP avahi_dns_packet_free(reply); size = avahi_record_get_estimate_size(r) + AVAHI_DNS_PACKET_HEADER_SIZE; - if (size > AVAHI_DNS_PACKET_SIZE_MAX) - size = AVAHI_DNS_PACKET_SIZE_MAX; - if (!(reply = avahi_dns_packet_new_reply(p, size, 0, 1))) + if (!(reply = avahi_dns_packet_new_reply(p, size + AVAHI_DNS_PACKET_EXTRA_SIZE, 0, 1))) break; /* OOM */ - if (!avahi_dns_packet_append_record(reply, r, flush_cache, 0)) { + if (avahi_dns_packet_append_record(reply, r, flush_cache, 0)) { + + /* Appending this record succeeded, so incremeant + * the specific header field, and return to the caller */ + + avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT); + break; + + } else { + + /* We completely fucked up, there's + * nothing we can do. The RR just doesn't + * fit in. Let's ignore it. */ + char *t; avahi_dns_packet_free(reply); + reply = NULL; t = avahi_record_to_string(r); avahi_log_warn("Record [%s] too large, doesn't fit in any packet!", t); avahi_free(t); break; - } else - avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT); + } } /* Appending the record didn't succeeed, so let's send this packet, and create a new one */ @@ -569,7 +579,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac int unicast_response = 0; if (!(key = avahi_dns_packet_consume_key(p, &unicast_response))) { - avahi_log_warn("Packet too short (1)"); + avahi_log_warn(__FILE__": Packet too short or invalid while reading question key. (Maybe a UTF-8 problem?)"); goto fail; } @@ -596,15 +606,13 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac int unique = 0; if (!(record = avahi_dns_packet_consume_record(p, &unique))) { - avahi_log_warn("Packet too short (2)"); + avahi_log_warn(__FILE__": Packet too short or invalid while reading known answer record. (Maybe a UTF-8 problem?)"); goto fail; } - if (handle_conflict(s, i, record, unique)) { - avahi_response_scheduler_suppress(i->response_scheduler, record, a); - avahi_record_list_drop(s->record_list, record); - avahi_cache_stop_poof(i->cache, record, a); - } + avahi_response_scheduler_suppress(i->response_scheduler, record, a); + avahi_record_list_drop(s->record_list, record); + avahi_cache_stop_poof(i->cache, record, a); avahi_record_unref(record); } @@ -615,7 +623,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac int unique = 0; if (!(record = avahi_dns_packet_consume_record(p, &unique))) { - avahi_log_warn("Packet too short (3)"); + avahi_log_warn(__FILE__": Packet too short or invalid while reading probe record. (Maybe a UTF-8 problem?)"); goto fail; } @@ -653,7 +661,7 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter /* char *txt; */ if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) { - avahi_log_warn("Packet too short (4)"); + avahi_log_warn(__FILE__": Packet too short or invalid while reading response record. (Maybe a UTF-8 problem?)"); break; } @@ -803,7 +811,7 @@ static void reflect_legacy_unicast_query_packet(AvahiServer *s, AvahiDnsPacket * avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ID, slot->id); for (j = s->monitor->interfaces; j; j = j->interface_next) - if (avahi_interface_is_relevant(j) && + if (j->announcing && j != i && (s->config.reflect_ipv || j->protocol == i->protocol)) { @@ -884,8 +892,8 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres assert(src_address->proto == dst_address->proto); if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, src_address->proto)) || - !avahi_interface_is_relevant(i)) { - avahi_log_warn("Recieved packet from invalid interface."); + !i->announcing) { + avahi_log_warn("Received packet from invalid interface."); return; } @@ -902,7 +910,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres from_local_iface = originates_from_local_iface(s, iface, src_address, port); if (avahi_dns_packet_check_valid_multicast(p) < 0) { - avahi_log_warn("Recieved invalid packet."); + avahi_log_warn("Received invalid packet."); return; } @@ -933,12 +941,12 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres } else { if (port != AVAHI_MDNS_PORT) { - avahi_log_warn("Recieved repsonse with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol); + avahi_log_warn("Received response with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol); return; } if (ttl != 255 && s->config.check_response_ttl) { - avahi_log_warn("Recieved response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol); + avahi_log_warn("Received response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol); return; } @@ -967,17 +975,17 @@ static void dispatch_legacy_unicast_packet(AvahiServer *s, AvahiDnsPacket *p) { assert(p); if (avahi_dns_packet_check_valid(p) < 0 || avahi_dns_packet_is_query(p)) { - avahi_log_warn("Recieved invalid packet."); + avahi_log_warn("Received invalid packet."); return; } if (!(slot = find_slot(s, avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ID)))) { - avahi_log_warn("Recieved legacy unicast response with unknown id"); + avahi_log_warn("Received legacy unicast response with unknown id"); return; } if (!(j = avahi_interface_monitor_get_interface(s->monitor, slot->interface, slot->address.proto)) || - !avahi_interface_is_relevant(j)) + !j->announcing) return; /* Patch the original ID into this response */ @@ -1226,17 +1234,27 @@ static void update_fqdn(AvahiServer *s) { } int avahi_server_set_host_name(AvahiServer *s, const char *host_name) { + char *hn = NULL; assert(s); - assert(host_name); + + AVAHI_CHECK_VALIDITY(s, !host_name || avahi_is_valid_host_name(host_name), AVAHI_ERR_INVALID_HOST_NAME); - if (host_name && !avahi_is_valid_host_name(host_name)) - return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME); + if (!host_name) { + hn = avahi_get_host_name_strdup(); + hn[strcspn(hn, ".")] = 0; + host_name = hn; + } + if (avahi_domain_equal(s->host_name, host_name) && s->state != AVAHI_SERVER_COLLISION) { + avahi_free(hn); + return avahi_server_set_errno(s, AVAHI_ERR_NO_CHANGE); + } + withdraw_host_rrs(s); avahi_free(s->host_name); - s->host_name = host_name ? avahi_normalize_name_strdup(host_name) : avahi_get_host_name_strdup(); - s->host_name[strcspn(s->host_name, ".")] = 0; + s->host_name = hn ? hn : avahi_strdup(host_name); + update_fqdn(s); register_stuff(s); @@ -1244,30 +1262,51 @@ int avahi_server_set_host_name(AvahiServer *s, const char *host_name) { } int avahi_server_set_domain_name(AvahiServer *s, const char *domain_name) { + char *dn = NULL; assert(s); - assert(domain_name); - if (domain_name && !avahi_is_valid_domain_name(domain_name)) - return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME); + AVAHI_CHECK_VALIDITY(s, !domain_name || avahi_is_valid_domain_name(domain_name), AVAHI_ERR_INVALID_DOMAIN_NAME); + + if (!domain_name) { + dn = avahi_strdup("local"); + domain_name = dn; + } + + if (avahi_domain_equal(s->domain_name, domain_name)) { + avahi_free(dn); + return avahi_server_set_errno(s, AVAHI_ERR_NO_CHANGE); + } withdraw_host_rrs(s); avahi_free(s->domain_name); - s->domain_name = domain_name ? avahi_normalize_name_strdup(domain_name) : avahi_strdup("local"); + s->domain_name = avahi_normalize_name_strdup(domain_name); update_fqdn(s); register_stuff(s); + + avahi_free(dn); return AVAHI_OK; } static int valid_server_config(const AvahiServerConfig *sc) { + AvahiStringList *l; + + assert(sc); + if (sc->n_wide_area_servers > AVAHI_WIDE_AREA_SERVERS_MAX) + return AVAHI_ERR_INVALID_CONFIG; + if (sc->host_name && !avahi_is_valid_host_name(sc->host_name)) return AVAHI_ERR_INVALID_HOST_NAME; if (sc->domain_name && !avahi_is_valid_domain_name(sc->domain_name)) return AVAHI_ERR_INVALID_DOMAIN_NAME; + for (l = sc->browse_domains; l; l = l->next) + if (!avahi_is_valid_domain_name((char*) l->text)) + return AVAHI_ERR_INVALID_DOMAIN_NAME; + return AVAHI_OK; } @@ -1532,12 +1571,15 @@ AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c) { c->use_iff_running = 0; c->enable_reflector = 0; c->reflect_ipv = 0; - c->add_service_cookie = 1; + c->add_service_cookie = 0; c->enable_wide_area = 0; c->n_wide_area_servers = 0; c->disallow_other_stacks = 0; c->browse_domains = NULL; c->disable_publishing = 0; + c->allow_point_to_point = 0; + c->publish_aaaa_on_ipv4 = 1; + c->publish_a_on_ipv6 = 0; return c; } @@ -1699,3 +1741,25 @@ int avahi_server_set_wide_area_servers(AvahiServer *s, const AvahiAddress *a, un avahi_wide_area_set_servers(s->wide_area_lookup_engine, a, n); return AVAHI_OK; } + +const AvahiServerConfig* avahi_server_get_config(AvahiServer *s) { + assert(s); + + return &s->config; +} + +/** Set the browsing domains */ +int avahi_server_set_browse_domains(AvahiServer *s, AvahiStringList *domains) { + AvahiStringList *l; + + assert(s); + + for (l = s->config.browse_domains; l; l = l->next) + if (!avahi_is_valid_domain_name((char*) l->text)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME); + + avahi_string_list_free(s->config.browse_domains); + s->config.browse_domains = avahi_string_list_copy(domains); + + return AVAHI_OK; +}