avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
avahi is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
for (e = s->entries; e; e = e->entries_next)
if (!e->dead &&
avahi_entry_is_registered(s, e, i) &&
for (e = s->entries; e; e = e->entries_next)
if (!e->dead &&
avahi_entry_is_registered(s, e, i) &&
callback(s, e->record, e->flags & AVAHI_PUBLISH_UNIQUE, userdata);
callback(s, e->record, e->flags & AVAHI_PUBLISH_UNIQUE, userdata);
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);
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);
for (e = s->entries; e; e = e->entries_next)
if (!e->dead && avahi_key_pattern_match(k, e->record->key) && avahi_entry_is_registered(s, e, i))
avahi_server_prepare_response(s, i, e, unicast_response, 0);
for (e = s->entries; e; e = e->entries_next)
if (!e->dead && avahi_key_pattern_match(k, e->record->key) && avahi_entry_is_registered(s, e, i))
avahi_server_prepare_response(s, i, e, unicast_response, 0);
for (e = avahi_hashmap_lookup(s->entries_by_key, k); e; e = e->by_key_next)
if (!e->dead && avahi_entry_is_registered(s, e, i))
avahi_server_prepare_response(s, i, e, unicast_response, 0);
for (e = avahi_hashmap_lookup(s->entries_by_key, k); e; e = e->by_key_next)
if (!e->dead && avahi_entry_is_registered(s, e, i))
avahi_server_prepare_response(s, i, e, unicast_response, 0);
avahi_server_prepare_matching_responses(s, i, cname_key, unicast_response);
avahi_key_unref(cname_key);
}
avahi_server_prepare_matching_responses(s, i, cname_key, unicast_response);
avahi_key_unref(cname_key);
}
if (!k->dead) {
avahi_goodbye_entry(s, k, 0, 1);
k->dead = 1;
if (!k->dead) {
avahi_goodbye_entry(s, k, 0, 1);
k->dead = 1;
static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface *i) {
AvahiEntry *e, *n;
int ours = 0, won = 0, lost = 0;
static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface *i) {
AvahiEntry *e, *n;
int ours = 0, won = 0, lost = 0;
if (won)
avahi_log_debug("Received conflicting probe [%s]. Local host won.", t);
else if (lost) {
avahi_log_debug("Received conflicting probe [%s]. Local host lost. Withdrawing.", t);
withdraw_rrset(s, record->key);
}
if (won)
avahi_log_debug("Received conflicting probe [%s]. Local host won.", t);
else if (lost) {
avahi_log_debug("Received conflicting probe [%s]. Local host lost. Withdrawing.", t);
withdraw_rrset(s, record->key);
}
static int handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *record, int unique) {
int valid = 1, ours = 0, conflict = 0, withdraw_immediately = 0;
AvahiEntry *e, *n, *conflicting_entry = NULL;
static int handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *record, int unique) {
int valid = 1, ours = 0, conflict = 0, withdraw_immediately = 0;
AvahiEntry *e, *n, *conflicting_entry = NULL;
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);
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);
if (!(e->flags & AVAHI_PUBLISH_UNIQUE) && !unique)
continue;
/* Either our entry or the other is intended to be unique, so let's check */
if (!(e->flags & AVAHI_PUBLISH_UNIQUE) && !unique)
continue;
/* Either our entry or the other is intended to be unique, so let's check */
if (avahi_record_equal_no_ttl(e->record, record)) {
ours = 1; /* We have an identical record, so this is no conflict */
if (avahi_record_equal_no_ttl(e->record, record)) {
ours = 1; /* 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_is_registered(s, e, i)) {
char *t;
/* Refresh */
/* Check wheter there is a TTL conflict */
if (record->ttl <= e->record->ttl/2 &&
avahi_entry_is_registered(s, e, i)) {
char *t;
/* Refresh */
avahi_log_debug("Received record with bad TTL [%s]. Refreshing.", t);
avahi_server_prepare_matching_responses(s, i, e->record->key, 0);
valid = 0;
avahi_log_debug("Received record with bad TTL [%s]. Refreshing.", t);
avahi_server_prepare_matching_responses(s, i, e->record->key, 0);
valid = 0;
if (withdraw_immediately) {
avahi_log_debug("Received conflicting record [%s] with local record to be. Withdrawing.", t);
withdraw_rrset(s, record->key);
if (withdraw_immediately) {
avahi_log_debug("Received conflicting record [%s] with local record to be. Withdrawing.", t);
withdraw_rrset(s, record->key);
avahi_record_list_push(s->record_list, r, flush_cache, *unicast_response, 1);
}
avahi_record_list_push(s->record_list, r, flush_cache, *unicast_response, 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 */
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))) {
append_aux_records_to_list(s, i, r, 0);
while ((r = avahi_record_list_next(s->record_list, NULL, NULL, NULL))) {
append_aux_records_to_list(s, i, r, 0);
if (avahi_dns_packet_append_record(reply, r, 0, 10))
avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
else {
if (avahi_dns_packet_append_record(reply, r, 0, 10))
avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
else {
immediately, because known answer suppression records might be
contained in later packets */
int tc = p && !!(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_TC);
immediately, because known answer suppression records might be
contained in later packets */
int tc = p && !!(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_TC);
while ((r = avahi_record_list_next(s->record_list, &flush_cache, &unicast_response, &auxiliary))) {
int im = immediately;
while ((r = avahi_record_list_next(s->record_list, &flush_cache, &unicast_response, &auxiliary))) {
int im = immediately;
* unique entry AND it is not in reply to a truncated
* packet AND it is not an auxiliary record AND all other
* responses for this record are unique too. */
* unique entry AND it is not in reply to a truncated
* packet AND it is not an auxiliary record AND all other
* responses for this record are unique too. */
* case. Therefore we prepare such a response */
append_aux_records_to_list(s, i, r, unicast_response);
* case. Therefore we prepare such a response */
append_aux_records_to_list(s, i, r, unicast_response);
if (!reply) {
assert(p);
if (!(reply = avahi_dns_packet_new_reply(p, i->hardware->mtu, 0, 0)))
break; /* OOM */
}
if (!reply) {
assert(p);
if (!(reply = avahi_dns_packet_new_reply(p, i->hardware->mtu, 0, 0)))
break; /* OOM */
}
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 */
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 */
/* Appending this record succeeded, so incremeant
* the specific header field, and return to the caller */
/* Appending this record succeeded, so incremeant
* the specific header field, and return to the caller */
/* We completely fucked up, there's
* nothing we can do. The RR just doesn't
* fit in. Let's ignore it. */
/* We completely fucked up, there's
* nothing we can do. The RR just doesn't
* fit in. Let's ignore it. */
avahi_interface_send_packet_unicast(i, reply, a, port);
avahi_dns_packet_free(reply);
}
avahi_interface_send_packet_unicast(i, reply, a, port);
avahi_dns_packet_free(reply);
}
static void reflect_response(AvahiServer *s, AvahiInterface *i, AvahiRecord *r, int flush_cache) {
AvahiInterface *j;
static void reflect_response(AvahiServer *s, AvahiInterface *i, AvahiRecord *r, int flush_cache) {
AvahiInterface *j;
static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, uint16_t port, int legacy_unicast, int from_local_iface) {
size_t n;
int is_probe;
static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, uint16_t port, int legacy_unicast, int from_local_iface) {
size_t n;
int is_probe;
assert(avahi_record_list_is_empty(s->record_list));
is_probe = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) > 0;
assert(avahi_record_list_is_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 --) {
AvahiKey *key;
/* Handle the questions */
for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT); n > 0; n --) {
AvahiKey *key;
/* 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);
/* 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);
}
avahi_server_prepare_matching_responses(s, i, key, unicast_response);
avahi_key_unref(key);
}
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?)");
goto fail;
}
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?)");
goto fail;
}
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);
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?)");
goto fail;
}
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?)");
goto fail;
}
if (!avahi_key_is_pattern(record->key)) {
if (!from_local_iface)
reflect_probe(s, i, record);
incoming_probe(s, record, i);
}
if (!avahi_key_is_pattern(record->key)) {
if (!from_local_iface)
reflect_probe(s, i, record);
incoming_probe(s, record, i);
}
avahi_server_generate_response(s, i, p, a, port, legacy_unicast, is_probe);
return;
avahi_server_generate_response(s, i, p, a, port, legacy_unicast, is_probe);
return;
fail:
avahi_record_list_flush(s->record_list);
}
static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, int from_local_iface) {
unsigned n;
fail:
avahi_record_list_flush(s->record_list);
}
static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, int from_local_iface) {
unsigned n;
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?)");
break;
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?)");
break;
static AvahiLegacyUnicastReflectSlot* allocate_slot(AvahiServer *s) {
unsigned n, idx = (unsigned) -1;
AvahiLegacyUnicastReflectSlot *slot;
static AvahiLegacyUnicastReflectSlot* allocate_slot(AvahiServer *s) {
unsigned n, idx = (unsigned) -1;
AvahiLegacyUnicastReflectSlot *slot;
for (n = 0; n < AVAHI_LEGACY_UNICAST_REFLECT_SLOTS_MAX; n++, s->legacy_unicast_reflect_id++) {
idx = s->legacy_unicast_reflect_id % AVAHI_LEGACY_UNICAST_REFLECT_SLOTS_MAX;
for (n = 0; n < AVAHI_LEGACY_UNICAST_REFLECT_SLOTS_MAX; n++, s->legacy_unicast_reflect_id++) {
idx = s->legacy_unicast_reflect_id % AVAHI_LEGACY_UNICAST_REFLECT_SLOTS_MAX;
idx = id % AVAHI_LEGACY_UNICAST_REFLECT_SLOTS_MAX;
if (!s->legacy_unicast_reflect_slots[idx] || s->legacy_unicast_reflect_slots[idx]->id != id)
idx = id % AVAHI_LEGACY_UNICAST_REFLECT_SLOTS_MAX;
if (!s->legacy_unicast_reflect_slots[idx] || s->legacy_unicast_reflect_slots[idx]->id != id)
/* Patch the packet with our new locally generatet id */
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ID, slot->id);
/* Patch the packet with our new locally generatet id */
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ID, slot->id);
if (address->proto == AVAHI_PROTO_INET && s->fd_legacy_unicast_ipv4 >= 0) {
struct sockaddr_in lsa;
socklen_t l = sizeof(lsa);
if (address->proto == AVAHI_PROTO_INET && s->fd_legacy_unicast_ipv4 >= 0) {
struct sockaddr_in lsa;
socklen_t l = sizeof(lsa);
if (getsockname(s->fd_legacy_unicast_ipv4, (struct sockaddr*) &lsa, &l) != 0)
avahi_log_warn("getsockname(): %s", strerror(errno));
else
if (getsockname(s->fd_legacy_unicast_ipv4, (struct sockaddr*) &lsa, &l) != 0)
avahi_log_warn("getsockname(): %s", strerror(errno));
else
if (getsockname(s->fd_legacy_unicast_ipv6, (struct sockaddr*) &lsa, &l) != 0)
avahi_log_warn("getsockname(): %s", strerror(errno));
else
if (getsockname(s->fd_legacy_unicast_ipv6, (struct sockaddr*) &lsa, &l) != 0)
avahi_log_warn("getsockname(): %s", strerror(errno));
else
static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddress *src_address, uint16_t port, const AvahiAddress *dst_address, AvahiIfIndex iface, int ttl) {
AvahiInterface *i;
int from_local_iface = 0;
static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddress *src_address, uint16_t port, const AvahiAddress *dst_address, AvahiIfIndex iface, int ttl) {
AvahiInterface *i;
int from_local_iface = 0;
if (avahi_address_is_ipv4_in_ipv6(src_address))
/* This is an IPv4 address encapsulated in IPv6, so let's ignore it. */
return;
if (avahi_address_is_ipv4_in_ipv6(src_address))
/* This is an IPv4 address encapsulated in IPv6, so let's ignore it. */
return;
legacy_unicast = 1;
}
if (legacy_unicast)
reflect_legacy_unicast_query_packet(s, p, i, src_address, port);
legacy_unicast = 1;
}
if (legacy_unicast)
reflect_legacy_unicast_query_packet(s, p, i, src_address, port);
handle_query_packet(s, p, i, src_address, port, legacy_unicast, from_local_iface);
handle_query_packet(s, p, i, src_address, port, legacy_unicast, from_local_iface);
- avahi_log_warn("Received response with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol);
+ 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_warn("Received response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol);
+ 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);
return;
}
if (!is_mdns_mcast_address(dst_address) &&
!avahi_interface_address_on_link(i, src_address)) {
return;
}
if (!is_mdns_mcast_address(dst_address) &&
!avahi_interface_address_on_link(i, src_address)) {
- avahi_log_warn("Received non-local response on interface '%s.%i'.", i->hardware->name, i->protocol);
+
+ 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);
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) {
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) {
static void dispatch_legacy_unicast_packet(AvahiServer *s, AvahiDnsPacket *p) {
AvahiInterface *j;
AvahiLegacyUnicastReflectSlot *slot;
static void dispatch_legacy_unicast_packet(AvahiServer *s, AvahiDnsPacket *p) {
AvahiInterface *j;
AvahiLegacyUnicastReflectSlot *slot;
if (fd == s->fd_ipv4) {
dest.proto = src.proto = AVAHI_PROTO_INET;
p = avahi_recv_dns_packet_ipv4(s->fd_ipv4, &src.data.ipv4, &port, &dest.data.ipv4, &iface, &ttl);
if (fd == s->fd_ipv4) {
dest.proto = src.proto = AVAHI_PROTO_INET;
p = avahi_recv_dns_packet_ipv4(s->fd_ipv4, &src.data.ipv4, &port, &dest.data.ipv4, &iface, &ttl);
dest.proto = src.proto = AVAHI_PROTO_INET6;
p = avahi_recv_dns_packet_ipv6(s->fd_ipv6, &src.data.ipv6, &port, &dest.data.ipv6, &iface, &ttl);
}
dest.proto = src.proto = AVAHI_PROTO_INET6;
p = avahi_recv_dns_packet_ipv6(s->fd_ipv6, &src.data.ipv6, &port, &dest.data.ipv6, &iface, &ttl);
}
if (iface != AVAHI_IF_UNSPEC)
dispatch_packet(s, p, &src, port, &dest, iface, ttl);
else
if (iface != AVAHI_IF_UNSPEC)
dispatch_packet(s, p, &src, port, &dest, iface, ttl);
else
if (fd == s->fd_legacy_unicast_ipv4)
p = avahi_recv_dns_packet_ipv4(s->fd_legacy_unicast_ipv4, NULL, NULL, NULL, NULL, NULL);
else {
if (fd == s->fd_legacy_unicast_ipv4)
p = avahi_recv_dns_packet_ipv4(s->fd_legacy_unicast_ipv4, NULL, NULL, NULL, NULL, NULL);
else {
else if (state == AVAHI_ENTRY_GROUP_COLLISION &&
(s->state == AVAHI_SERVER_REGISTERING || s->state == AVAHI_SERVER_RUNNING)) {
withdraw_host_rrs(s);
server_set_state(s, AVAHI_SERVER_COLLISION);
else if (state == AVAHI_ENTRY_GROUP_COLLISION &&
(s->state == AVAHI_SERVER_REGISTERING || s->state == AVAHI_SERVER_RUNNING)) {
withdraw_host_rrs(s);
server_set_state(s, AVAHI_SERVER_COLLISION);
} else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED &&
s->state == AVAHI_SERVER_REGISTERING)
avahi_server_decrease_host_rr_pending(s);
} else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED &&
s->state == AVAHI_SERVER_REGISTERING)
avahi_server_decrease_host_rr_pending(s);
/* Fill in HINFO rr */
if ((r = avahi_record_new_full(s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO, AVAHI_DEFAULT_TTL_HOST_NAME))) {
if (uname(&utsname) < 0)
avahi_log_warn("uname() failed: %s\n", avahi_strerror(errno));
else {
/* Fill in HINFO rr */
if ((r = avahi_record_new_full(s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO, AVAHI_DEFAULT_TTL_HOST_NAME))) {
if (uname(&utsname) < 0)
avahi_log_warn("uname() failed: %s\n", avahi_strerror(errno));
else {
r->data.hinfo.cpu = avahi_strdup(avahi_strup(utsname.machine));
r->data.hinfo.os = avahi_strdup(avahi_strup(utsname.sysname));
r->data.hinfo.cpu = avahi_strdup(avahi_strup(utsname.machine));
r->data.hinfo.os = avahi_strdup(avahi_strup(utsname.sysname));
avahi_log_info("Registering HINFO record with values '%s'/'%s'.", r->data.hinfo.cpu, r->data.hinfo.os);
avahi_log_info("Registering HINFO record with values '%s'/'%s'.", r->data.hinfo.cpu, r->data.hinfo.os);
if (avahi_server_add(s, s->hinfo_entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_UNIQUE, r) < 0) {
avahi_log_warn("Failed to add HINFO RR: %s", avahi_strerror(s->error));
return;
if (avahi_server_add(s, s->hinfo_entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_UNIQUE, r) < 0) {
avahi_log_warn("Failed to add HINFO RR: %s", avahi_strerror(s->error));
return;
/* Add localhost entries */
avahi_address_parse("127.0.0.1", AVAHI_PROTO_INET, &a);
avahi_server_add_address(s, NULL, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_NO_PROBE|AVAHI_PUBLISH_NO_ANNOUNCE, "localhost", &a);
/* Add localhost entries */
avahi_address_parse("127.0.0.1", AVAHI_PROTO_INET, &a);
avahi_server_add_address(s, NULL, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_NO_PROBE|AVAHI_PUBLISH_NO_ANNOUNCE, "localhost", &a);
if (avahi_server_add_ptr(s, s->browse_domain_entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, AVAHI_DEFAULT_TTL, "b._dns-sd._udp.local", s->domain_name) < 0) {
avahi_log_warn("Failed to add browse domain RR: %s", avahi_strerror(s->error));
return;
if (avahi_server_add_ptr(s, s->browse_domain_entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, AVAHI_DEFAULT_TTL, "b._dns-sd._udp.local", s->domain_name) < 0) {
avahi_log_warn("Failed to add browse domain RR: %s", avahi_strerror(s->error));
return;
if (s->n_host_rr_pending == 0)
server_set_state(s, AVAHI_SERVER_RUNNING);
}
static void update_fqdn(AvahiServer *s) {
char *n;
if (s->n_host_rr_pending == 0)
server_set_state(s, AVAHI_SERVER_RUNNING);
}
static void update_fqdn(AvahiServer *s) {
char *n;
AVAHI_CHECK_VALIDITY(s, !host_name || avahi_is_valid_host_name(host_name), AVAHI_ERR_INVALID_HOST_NAME);
if (!host_name) {
AVAHI_CHECK_VALIDITY(s, !host_name || avahi_is_valid_host_name(host_name), AVAHI_ERR_INVALID_HOST_NAME);
if (!host_name) {
if (avahi_domain_equal(s->domain_name, domain_name)) {
avahi_free(dn);
return avahi_server_set_errno(s, AVAHI_ERR_NO_CHANGE);
if (avahi_domain_equal(s->domain_name, domain_name)) {
avahi_free(dn);
return avahi_server_set_errno(s, AVAHI_ERR_NO_CHANGE);
if (sc->domain_name && !avahi_is_valid_domain_name(sc->domain_name))
return AVAHI_ERR_INVALID_DOMAIN_NAME;
if (sc->domain_name && !avahi_is_valid_domain_name(sc->domain_name))
return AVAHI_ERR_INVALID_DOMAIN_NAME;
s->fd_ipv4 = s->config.use_ipv4 ? avahi_open_socket_ipv4(s->config.disallow_other_stacks) : -1;
s->fd_ipv6 = s->config.use_ipv6 ? avahi_open_socket_ipv6(s->config.disallow_other_stacks) : -1;
s->fd_ipv4 = s->config.use_ipv4 ? avahi_open_socket_ipv4(s->config.disallow_other_stacks) : -1;
s->fd_ipv6 = s->config.use_ipv6 ? avahi_open_socket_ipv6(s->config.disallow_other_stacks) : -1;
s->fd_legacy_unicast_ipv4 = s->fd_ipv4 >= 0 && s->config.enable_reflector ? avahi_open_unicast_socket_ipv4() : -1;
s->fd_legacy_unicast_ipv6 = s->fd_ipv6 >= 0 && s->config.enable_reflector ? avahi_open_unicast_socket_ipv6() : -1;
s->fd_legacy_unicast_ipv4 = s->fd_ipv4 >= 0 && s->config.enable_reflector ? avahi_open_unicast_socket_ipv4() : -1;
s->fd_legacy_unicast_ipv6 = s->fd_ipv6 >= 0 && s->config.enable_reflector ? avahi_open_unicast_socket_ipv6() : -1;
if (s->fd_ipv4 >= 0)
s->watch_ipv4 = s->poll_api->watch_new(s->poll_api, s->fd_ipv4, AVAHI_WATCH_IN, mcast_socket_event, s);
if (s->fd_ipv6 >= 0)
s->watch_ipv6 = s->poll_api->watch_new(s->poll_api, s->fd_ipv6, AVAHI_WATCH_IN, mcast_socket_event, s);
if (s->fd_ipv4 >= 0)
s->watch_ipv4 = s->poll_api->watch_new(s->poll_api, s->fd_ipv4, AVAHI_WATCH_IN, mcast_socket_event, s);
if (s->fd_ipv6 >= 0)
s->watch_ipv6 = s->poll_api->watch_new(s->poll_api, s->fd_ipv6, AVAHI_WATCH_IN, mcast_socket_event, s);
if (s->fd_legacy_unicast_ipv4 >= 0)
s->watch_legacy_unicast_ipv4 = s->poll_api->watch_new(s->poll_api, s->fd_legacy_unicast_ipv4, AVAHI_WATCH_IN, legacy_unicast_socket_event, s);
if (s->fd_legacy_unicast_ipv6 >= 0)
s->watch_legacy_unicast_ipv6 = s->poll_api->watch_new(s->poll_api, s->fd_legacy_unicast_ipv6, AVAHI_WATCH_IN, legacy_unicast_socket_event, s);
if (s->fd_legacy_unicast_ipv4 >= 0)
s->watch_legacy_unicast_ipv4 = s->poll_api->watch_new(s->poll_api, s->fd_legacy_unicast_ipv4, AVAHI_WATCH_IN, legacy_unicast_socket_event, s);
if (s->fd_legacy_unicast_ipv6 >= 0)
s->watch_legacy_unicast_ipv6 = s->poll_api->watch_new(s->poll_api, s->fd_legacy_unicast_ipv6, AVAHI_WATCH_IN, legacy_unicast_socket_event, s);
return 0;
}
AvahiServer *avahi_server_new(const AvahiPoll *poll_api, const AvahiServerConfig *sc, AvahiServerCallback callback, void* userdata, int *error) {
AvahiServer *s;
int e;
return 0;
}
AvahiServer *avahi_server_new(const AvahiPoll *poll_api, const AvahiServerConfig *sc, AvahiServerCallback callback, void* userdata, int *error) {
AvahiServer *s;
int e;
if (!(s = avahi_new(AvahiServer, 1))) {
if (error)
*error = AVAHI_ERR_NO_MEMORY;
if (!(s = avahi_new(AvahiServer, 1))) {
if (error)
*error = AVAHI_ERR_NO_MEMORY;
s->n_host_rr_pending = 0;
s->need_entry_cleanup = 0;
s->need_group_cleanup = 0;
s->n_host_rr_pending = 0;
s->need_entry_cleanup = 0;
s->need_group_cleanup = 0;
/* Get host name */
s->host_name = s->config.host_name ? avahi_normalize_name_strdup(s->config.host_name) : avahi_get_host_name_strdup();
s->host_name[strcspn(s->host_name, ".")] = 0;
/* Get host name */
s->host_name = s->config.host_name ? avahi_normalize_name_strdup(s->config.host_name) : avahi_get_host_name_strdup();
s->host_name[strcspn(s->host_name, ".")] = 0;
s->wide_area_lookup_engine = NULL;
s->multicast_lookup_engine = avahi_multicast_lookup_engine_new(s);
s->wide_area_lookup_engine = NULL;
s->multicast_lookup_engine = avahi_multicast_lookup_engine_new(s);
avahi_s_service_resolver_free(s->service_resolvers);
while (s->record_browsers)
avahi_s_record_browser_destroy(s->record_browsers);
avahi_s_service_resolver_free(s->service_resolvers);
while (s->record_browsers)
avahi_s_record_browser_destroy(s->record_browsers);
avahi_multicast_lookup_engine_free(s->multicast_lookup_engine);
avahi_time_event_queue_free(s->time_event_queue);
avahi_multicast_lookup_engine_free(s->multicast_lookup_engine);
avahi_time_event_queue_free(s->time_event_queue);
if (s->watch_legacy_unicast_ipv4)
s->poll_api->watch_free(s->watch_legacy_unicast_ipv4);
if (s->watch_legacy_unicast_ipv6)
s->poll_api->watch_free(s->watch_legacy_unicast_ipv6);
/* Free sockets */
if (s->watch_legacy_unicast_ipv4)
s->poll_api->watch_free(s->watch_legacy_unicast_ipv4);
if (s->watch_legacy_unicast_ipv6)
s->poll_api->watch_free(s->watch_legacy_unicast_ipv6);
/* Free sockets */
if (s->fd_legacy_unicast_ipv4 >= 0)
close(s->fd_legacy_unicast_ipv4);
if (s->fd_legacy_unicast_ipv6 >= 0)
close(s->fd_legacy_unicast_ipv6);
if (s->fd_legacy_unicast_ipv4 >= 0)
close(s->fd_legacy_unicast_ipv4);
if (s->fd_legacy_unicast_ipv6 >= 0)
close(s->fd_legacy_unicast_ipv6);
avahi_free(s->host_name);
avahi_free(s->domain_name);
avahi_free(s->host_name_fqdn);
avahi_free(s->host_name);
avahi_free(s->domain_name);
avahi_free(s->host_name_fqdn);
c->allow_point_to_point = 0;
c->publish_aaaa_on_ipv4 = 1;
c->publish_a_on_ipv6 = 0;
c->allow_point_to_point = 0;
c->publish_aaaa_on_ipv4 = 1;
c->publish_a_on_ipv6 = 0;
avahi_free(c->host_name);
avahi_free(c->domain_name);
avahi_string_list_free(c->browse_domains);
avahi_free(c->host_name);
avahi_free(c->domain_name);
avahi_string_list_free(c->browse_domains);
}
AvahiServerConfig* avahi_server_config_copy(AvahiServerConfig *ret, const AvahiServerConfig *c) {
char *d = NULL, *h = NULL;
}
AvahiServerConfig* avahi_server_config_copy(AvahiServerConfig *ret, const AvahiServerConfig *c) {
char *d = NULL, *h = NULL;
- if (!(l = avahi_string_list_copy(c->browse_domains)) && c->browse_domains) {
+ if (!(browse = avahi_string_list_copy(c->browse_domains)) && c->browse_domains) {
+ avahi_free(h);
+ avahi_free(d);
+ return NULL;
+ }
+
+ if (!(allow = avahi_string_list_copy(c->allow_interfaces)) && c->allow_interfaces) {
+ avahi_string_list_free(browse);
+ avahi_free(h);
+ avahi_free(d);
+ return NULL;
+ }
+
+ if (!(deny = avahi_string_list_copy(c->deny_interfaces)) && c->deny_interfaces) {
+ avahi_string_list_free(allow);
+ avahi_string_list_free(browse);
static AvahiEntry *find_entry(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key) {
AvahiEntry *e;
static AvahiEntry *find_entry(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key) {
AvahiEntry *e;
if ((ret = avahi_service_name_join(n, sizeof(n), name, type, domain) < 0))
return avahi_server_set_errno(s, ret);
if ((ret = avahi_service_name_join(n, sizeof(n), name, type, domain) < 0))
return avahi_server_set_errno(s, ret);
if (!(key = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV)))
return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
if (!(key = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV)))
return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
for (e = avahi_hashmap_lookup(s->entries_by_key, record->key); e; e = e->by_key_next)
if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
for (e = avahi_hashmap_lookup(s->entries_by_key, record->key); e; e = e->by_key_next)
if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
/** Set the browsing domains */
int avahi_server_set_browse_domains(AvahiServer *s, AvahiStringList *domains) {
AvahiStringList *l;
/** 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);
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);
avahi_string_list_free(s->config.browse_domains);
s->config.browse_domains = avahi_string_list_copy(domains);