diff --git a/avahi-common/simple-watch.c b/avahi-common/simple-watch.c index 8df18dd..08d8090 100644 --- a/avahi-common/simple-watch.c +++ b/avahi-common/simple-watch.c @@ -21,7 +21,7 @@ #include #endif -#include +#include #include #include #include diff --git a/avahi-common/simple-watch.h b/avahi-common/simple-watch.h index 72c1905..db87122 100644 --- a/avahi-common/simple-watch.h +++ b/avahi-common/simple-watch.h @@ -22,7 +22,7 @@ /** \file simple-watch.h Simple poll() based main loop implementation */ -#include +#include #include #include diff --git a/avahi-common/thread-watch.c b/avahi-common/thread-watch.c index c0cadeb..ecb202b 100644 --- a/avahi-common/thread-watch.c +++ b/avahi-common/thread-watch.c @@ -21,7 +21,7 @@ #include #endif -#include +#include #include #include #include diff --git a/avahi-common/thread-watch.h b/avahi-common/thread-watch.h index dec0cf3..1b44ccb 100644 --- a/avahi-common/thread-watch.h +++ b/avahi-common/thread-watch.h @@ -22,7 +22,7 @@ /** \file thread-watch.h Threaded poll() based main loop implementation */ -#include +#include #include #include diff --git a/avahi-common/watch.h b/avahi-common/watch.h index 86e63d3..eea12ec 100644 --- a/avahi-common/watch.h +++ b/avahi-common/watch.h @@ -22,7 +22,7 @@ /** \file watch.h Simplistic main loop abstraction */ -#include +#include #include #include diff --git a/avahi-core/core.h b/avahi-core/core.h index f50c612..3fba55e 100644 --- a/avahi-core/core.h +++ b/avahi-core/core.h @@ -65,7 +65,7 @@ typedef struct AvahiServerConfig { int disable_publishing; /**< Disable publishing of any record */ int allow_point_to_point; /**< Enable publishing on POINTOPOINT interfaces */ int publish_a_on_ipv6; /**< Publish an IPv4 A RR on IPv6 sockets */ - int publish_aaaa_on_ipv4; /**< Publish an IPv4 A RR on IPv6 sockets */ + int publish_aaaa_on_ipv4; /**< Publish an IPv6 AAAA RR on IPv4 sockets */ unsigned n_cache_entries_max; /**< Maximum number of cache entries per interface */ AvahiUsec ratelimit_interval; /**< If non-zero, rate-limiting interval parameter. */ unsigned ratelimit_burst; /**< If ratelimit_interval is non-zero, rate-limiting burst parameter. */ diff --git a/avahi-core/dns.c b/avahi-core/dns.c index 2fcd91f..7c38f42 100644 --- a/avahi-core/dns.c +++ b/avahi-core/dns.c @@ -55,6 +55,7 @@ AvahiDnsPacket* avahi_dns_packet_new(unsigned mtu) { p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE; p->max_size = max_size; + p->res_size = 0; p->name_table = NULL; p->data = NULL; @@ -833,6 +834,25 @@ size_t avahi_dns_packet_space(AvahiDnsPacket *p) { return p->max_size - p->size; } +size_t avahi_dns_packet_reserve_size(AvahiDnsPacket *p, size_t res_size) { + assert(p); + + assert(p->size + p->res_size <= p->max_size); + + if ((p->size + p->res_size + res_size) <= p->max_size) + p->res_size += res_size; + + return p->res_size; +} + +size_t avahi_dns_packet_reserved_space(AvahiDnsPacket *p) { + assert(p); + + assert(p->size + p->res_size <= p->max_size); + + return p->max_size - p->size - p->res_size; +} + int avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size) { int ret; AvahiDnsPacket p; diff --git a/avahi-core/dns.h b/avahi-core/dns.h index 52e8d88..13b1ac2 100644 --- a/avahi-core/dns.h +++ b/avahi-core/dns.h @@ -30,7 +30,7 @@ #define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX) typedef struct AvahiDnsPacket { - size_t size, rindex, max_size; + size_t size, rindex, max_size, res_size; AvahiHashmap *name_table; /* for name compression */ uint8_t *data; } AvahiDnsPacket; @@ -78,6 +78,8 @@ int avahi_dns_packet_skip(AvahiDnsPacket *p, size_t length); int avahi_dns_packet_is_empty(AvahiDnsPacket *p); size_t avahi_dns_packet_space(AvahiDnsPacket *p); +size_t avahi_dns_packet_reserve_size(AvahiDnsPacket *p, size_t res_size); +size_t avahi_dns_packet_reserved_space(AvahiDnsPacket *p); #define AVAHI_DNS_FIELD_ID 0 #define AVAHI_DNS_FIELD_FLAGS 1 diff --git a/avahi-core/iface-linux.c b/avahi-core/iface-linux.c index da497bc..c6c5f77 100644 --- a/avahi-core/iface-linux.c +++ b/avahi-core/iface-linux.c @@ -204,7 +204,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat switch(a->rta_type) { - case IFA_ADDRESS: + case IFA_LOCAL: if ((rlocal.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || (rlocal.proto == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4)) @@ -215,7 +215,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat break; - case IFA_LOCAL: + case IFA_ADDRESS: /* Fill in local address data. Usually this is * preferable over IFA_ADDRESS if both are set, diff --git a/avahi-core/probe-sched.c b/avahi-core/probe-sched.c index 1e63411..2e22338 100644 --- a/avahi-core/probe-sched.c +++ b/avahi-core/probe-sched.c @@ -179,7 +179,7 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava avahi_record_get_estimate_size(pj->record); /* Too large */ - if (size > avahi_dns_packet_space(p)) + if (size > avahi_dns_packet_reserved_space(p)) return 0; /* Create the probe query */ @@ -189,6 +189,9 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava b = !!avahi_dns_packet_append_key(p, k, 0); assert(b); + /* reserve size for record data */ + avahi_dns_packet_reserve_size(p, avahi_record_get_estimate_size(pj->record)); + /* Mark this job for addition to the packet */ pj->chosen = 1; @@ -202,9 +205,12 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava continue; /* This job wouldn't fit in */ - if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_space(p)) + if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_reserved_space(p)) break; + /* reserve size for record data */ + avahi_dns_packet_reserve_size(p, avahi_record_get_estimate_size(pj->record)); + /* Mark this job for addition to the packet */ pj->chosen = 1; } diff --git a/avahi-core/server.c b/avahi-core/server.c index 69a1d02..a2cb19a 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -587,7 +587,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(__FILE__": Packet too short or invalid while reading question key. (Maybe a UTF-8 problem?)"); + avahi_log_debug(__FILE__": Packet too short or invalid while reading question key. (Maybe a UTF-8 problem?)"); goto fail; } @@ -615,7 +615,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(__FILE__": Packet too short or invalid while reading known answer record. (Maybe a UTF-8 problem?)"); + avahi_log_debug(__FILE__": Packet too short or invalid while reading known answer record. (Maybe a UTF-8 problem?)"); goto fail; } @@ -632,7 +632,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(__FILE__": Packet too short or invalid while reading probe record. (Maybe a UTF-8 problem?)"); + avahi_log_debug(__FILE__": Packet too short or invalid while reading probe record. (Maybe a UTF-8 problem?)"); goto fail; } @@ -669,7 +669,7 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter int cache_flush = 0; if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) { - avahi_log_warn(__FILE__": Packet too short or invalid while reading response record. (Maybe a UTF-8 problem?)"); + avahi_log_debug(__FILE__": Packet too short or invalid while reading response record. (Maybe a UTF-8 problem?)"); break; } @@ -901,13 +901,13 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, src_address->proto)) || !i->announcing) { - avahi_log_warn("Received packet from invalid interface."); + avahi_log_debug("Received packet from invalid interface."); return; } if (port <= 0) { /* This fixes RHBZ #475394 */ - avahi_log_warn("Received packet from invalid source port %u.", (unsigned) port); + avahi_log_debug("Received packet from invalid source port %u.", (unsigned) port); return; } @@ -924,7 +924,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("Received invalid packet."); + avahi_log_debug("Received invalid packet."); return; } @@ -940,7 +940,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres if ((avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) != 0 || avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0)) { - avahi_log_warn("Invalid legacy unicast query packet."); + avahi_log_debug("Invalid legacy unicast query packet."); return; } @@ -956,19 +956,19 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres char t[AVAHI_ADDRESS_STR_MAX]; if (port != AVAHI_MDNS_PORT) { - avahi_log_warn("Received response from host %s with invalid source port %u on interface '%s.%i'", avahi_address_snprint(t, sizeof(t), src_address), port, i->hardware->name, i->protocol); + avahi_log_debug("Received response from host %s with invalid source port %u on interface '%s.%i'", avahi_address_snprint(t, sizeof(t), src_address), port, i->hardware->name, i->protocol); return; } if (ttl != 255 && s->config.check_response_ttl) { - avahi_log_warn("Received response from host %s with invalid TTL %u on interface '%s.%i'.", avahi_address_snprint(t, sizeof(t), src_address), ttl, i->hardware->name, i->protocol); + avahi_log_debug("Received response from host %s with invalid TTL %u on interface '%s.%i'.", avahi_address_snprint(t, sizeof(t), src_address), ttl, i->hardware->name, i->protocol); return; } if (!is_mdns_mcast_address(dst_address) && !avahi_interface_address_on_link(i, src_address)) { - avahi_log_warn("Received non-local response from host %s on interface '%s.%i'.", avahi_address_snprint(t, sizeof(t), src_address), i->hardware->name, i->protocol); + avahi_log_debug("Received non-local response from host %s on interface '%s.%i'.", avahi_address_snprint(t, sizeof(t), src_address), i->hardware->name, i->protocol); return; } @@ -976,7 +976,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 || avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0) { - avahi_log_warn("Invalid response packet from host %s.", avahi_address_snprint(t, sizeof(t), src_address)); + avahi_log_debug("Invalid response packet from host %s.", avahi_address_snprint(t, sizeof(t), src_address)); return; } @@ -992,12 +992,12 @@ 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("Received invalid packet."); + avahi_log_debug("Received invalid packet."); return; } if (!(slot = find_slot(s, avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ID)))) { - avahi_log_warn("Received legacy unicast response with unknown id"); + avahi_log_debug("Received legacy unicast response with unknown id"); return; } @@ -1794,7 +1794,7 @@ int avahi_server_set_browse_domains(AvahiServer *s, AvahiStringList *domains) { assert(s); - for (l = s->config.browse_domains; l; l = l->next) + for (l = 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); diff --git a/avahi-core/socket.c b/avahi-core/socket.c index 17ab6e5..5a00300 100644 --- a/avahi-core/socket.c +++ b/avahi-core/socket.c @@ -177,7 +177,8 @@ static int reuseaddr(int fd) { yes = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) < 0) { avahi_log_warn("SO_REUSEPORT failed: %s", strerror(errno)); - return -1; + if (errno != ENOPROTOOPT) + return -1; } #endif