updates from avahi project

This commit is contained in:
Jonathan Bagg
2018-05-18 13:16:17 -04:00
parent f464b49e44
commit d91e9e5b81
12 changed files with 56 additions and 27 deletions

View File

@ -21,7 +21,7 @@
#include <config.h> #include <config.h>
#endif #endif
#include <sys/poll.h> #include <poll.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>

View File

@ -22,7 +22,7 @@
/** \file simple-watch.h Simple poll() based main loop implementation */ /** \file simple-watch.h Simple poll() based main loop implementation */
#include <sys/poll.h> #include <poll.h>
#include <avahi-common/cdecl.h> #include <avahi-common/cdecl.h>
#include <avahi-common/watch.h> #include <avahi-common/watch.h>

View File

@ -21,7 +21,7 @@
#include <config.h> #include <config.h>
#endif #endif
#include <sys/poll.h> #include <poll.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>

View File

@ -22,7 +22,7 @@
/** \file thread-watch.h Threaded poll() based main loop implementation */ /** \file thread-watch.h Threaded poll() based main loop implementation */
#include <sys/poll.h> #include <poll.h>
#include <avahi-common/cdecl.h> #include <avahi-common/cdecl.h>
#include <avahi-common/watch.h> #include <avahi-common/watch.h>

View File

@ -22,7 +22,7 @@
/** \file watch.h Simplistic main loop abstraction */ /** \file watch.h Simplistic main loop abstraction */
#include <sys/poll.h> #include <poll.h>
#include <sys/time.h> #include <sys/time.h>
#include <avahi-common/cdecl.h> #include <avahi-common/cdecl.h>

View File

@ -65,7 +65,7 @@ typedef struct AvahiServerConfig {
int disable_publishing; /**< Disable publishing of any record */ int disable_publishing; /**< Disable publishing of any record */
int allow_point_to_point; /**< Enable publishing on POINTOPOINT interfaces */ 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_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 */ unsigned n_cache_entries_max; /**< Maximum number of cache entries per interface */
AvahiUsec ratelimit_interval; /**< If non-zero, rate-limiting interval parameter. */ AvahiUsec ratelimit_interval; /**< If non-zero, rate-limiting interval parameter. */
unsigned ratelimit_burst; /**< If ratelimit_interval is non-zero, rate-limiting burst parameter. */ unsigned ratelimit_burst; /**< If ratelimit_interval is non-zero, rate-limiting burst parameter. */

View File

@ -55,6 +55,7 @@ AvahiDnsPacket* avahi_dns_packet_new(unsigned mtu) {
p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE; p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE;
p->max_size = max_size; p->max_size = max_size;
p->res_size = 0;
p->name_table = NULL; p->name_table = NULL;
p->data = NULL; p->data = NULL;
@ -833,6 +834,25 @@ size_t avahi_dns_packet_space(AvahiDnsPacket *p) {
return p->max_size - p->size; 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 avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size) {
int ret; int ret;
AvahiDnsPacket p; AvahiDnsPacket p;

View File

@ -30,7 +30,7 @@
#define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX) #define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX)
typedef struct AvahiDnsPacket { typedef struct AvahiDnsPacket {
size_t size, rindex, max_size; size_t size, rindex, max_size, res_size;
AvahiHashmap *name_table; /* for name compression */ AvahiHashmap *name_table; /* for name compression */
uint8_t *data; uint8_t *data;
} AvahiDnsPacket; } AvahiDnsPacket;
@ -78,6 +78,8 @@ int avahi_dns_packet_skip(AvahiDnsPacket *p, size_t length);
int avahi_dns_packet_is_empty(AvahiDnsPacket *p); int avahi_dns_packet_is_empty(AvahiDnsPacket *p);
size_t avahi_dns_packet_space(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_ID 0
#define AVAHI_DNS_FIELD_FLAGS 1 #define AVAHI_DNS_FIELD_FLAGS 1

View File

@ -204,7 +204,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat
switch(a->rta_type) { switch(a->rta_type) {
case IFA_ADDRESS: case IFA_LOCAL:
if ((rlocal.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || if ((rlocal.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) ||
(rlocal.proto == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4)) (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; break;
case IFA_LOCAL: case IFA_ADDRESS:
/* Fill in local address data. Usually this is /* Fill in local address data. Usually this is
* preferable over IFA_ADDRESS if both are set, * preferable over IFA_ADDRESS if both are set,

View File

@ -179,7 +179,7 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava
avahi_record_get_estimate_size(pj->record); avahi_record_get_estimate_size(pj->record);
/* Too large */ /* Too large */
if (size > avahi_dns_packet_space(p)) if (size > avahi_dns_packet_reserved_space(p))
return 0; return 0;
/* Create the probe query */ /* 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); b = !!avahi_dns_packet_append_key(p, k, 0);
assert(b); 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 */ /* Mark this job for addition to the packet */
pj->chosen = 1; pj->chosen = 1;
@ -202,9 +205,12 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava
continue; continue;
/* This job wouldn't fit in */ /* 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; 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 */ /* Mark this job for addition to the packet */
pj->chosen = 1; pj->chosen = 1;
} }

View File

@ -587,7 +587,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac
int unicast_response = 0; int unicast_response = 0;
if (!(key = avahi_dns_packet_consume_key(p, &unicast_response))) { 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; goto fail;
} }
@ -615,7 +615,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac
int unique = 0; int unique = 0;
if (!(record = avahi_dns_packet_consume_record(p, &unique))) { 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; goto fail;
} }
@ -632,7 +632,7 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac
int unique = 0; int unique = 0;
if (!(record = avahi_dns_packet_consume_record(p, &unique))) { 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; goto fail;
} }
@ -669,7 +669,7 @@ static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInter
int cache_flush = 0; int cache_flush = 0;
if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) { 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; 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)) || if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, src_address->proto)) ||
!i->announcing) { !i->announcing) {
avahi_log_warn("Received packet from invalid interface."); avahi_log_debug("Received packet from invalid interface.");
return; return;
} }
if (port <= 0) { if (port <= 0) {
/* This fixes RHBZ #475394 */ /* 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; 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); from_local_iface = originates_from_local_iface(s, iface, src_address, port);
if (avahi_dns_packet_check_valid_multicast(p) < 0) { if (avahi_dns_packet_check_valid_multicast(p) < 0) {
avahi_log_warn("Received invalid packet."); avahi_log_debug("Received invalid packet.");
return; 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 || if ((avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) != 0 ||
avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 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; return;
} }
@ -956,19 +956,19 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres
char t[AVAHI_ADDRESS_STR_MAX]; char t[AVAHI_ADDRESS_STR_MAX];
if (port != AVAHI_MDNS_PORT) { 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; return;
} }
if (ttl != 255 && s->config.check_response_ttl) { 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; return;
} }
if (!is_mdns_mcast_address(dst_address) && if (!is_mdns_mcast_address(dst_address) &&
!avahi_interface_address_on_link(i, src_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; 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_ANCOUNT) == 0 ||
avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 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; return;
} }
@ -992,12 +992,12 @@ static void dispatch_legacy_unicast_packet(AvahiServer *s, AvahiDnsPacket *p) {
assert(p); assert(p);
if (avahi_dns_packet_check_valid(p) < 0 || avahi_dns_packet_is_query(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; return;
} }
if (!(slot = find_slot(s, avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ID)))) { 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; return;
} }
@ -1794,7 +1794,7 @@ int avahi_server_set_browse_domains(AvahiServer *s, AvahiStringList *domains) {
assert(s); 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)) if (!avahi_is_valid_domain_name((char*) l->text))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME); return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);

View File

@ -177,7 +177,8 @@ static int reuseaddr(int fd) {
yes = 1; yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) < 0) { if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) < 0) {
avahi_log_warn("SO_REUSEPORT failed: %s", strerror(errno)); avahi_log_warn("SO_REUSEPORT failed: %s", strerror(errno));
return -1; if (errno != ENOPROTOOPT)
return -1;
} }
#endif #endif