#include <errno.h>
#include <stdio.h>
#include <assert.h>
+#include <stdlib.h>
#include <avahi-common/domain.h>
#include <avahi-common/timeval.h>
#include <avahi-common/malloc.h>
+#include <avahi-common/error.h>
#include "server.h"
#include "iface.h"
avahi_free(e);
}
-static void free_group(AvahiServer *s, AvahiEntryGroup *g) {
+static void free_group(AvahiServer *s, AvahiSEntryGroup *g) {
assert(s);
assert(g);
if (g->register_time_event)
avahi_time_event_free(g->register_time_event);
- AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, s->groups, g);
+ AVAHI_LLIST_REMOVE(AvahiSEntryGroup, groups, s->groups, g);
avahi_free(g);
}
assert(s);
if (s->need_group_cleanup) {
- AvahiEntryGroup *g, *next;
+ AvahiSEntryGroup *g, *next;
for (g = s->groups; g; g = next) {
next = g->groups_next;
e->group->n_probing = 0;
- avahi_entry_group_change_state(e->group, AVAHI_ENTRY_GROUP_COLLISION);
+ avahi_s_entry_group_change_state(e->group, AVAHI_ENTRY_GROUP_COLLISION);
} else {
avahi_goodbye_entry(s, e, 0);
e->dead = 1;
}
}
-
if (!ours) {
if (won)
for (e = avahi_hashmap_lookup(s->entries_by_key, record->key); e; e = n) {
n = e->by_key_next;
- if (e->dead || (!(e->flags & AVAHI_ENTRY_UNIQUE) && !unique))
+ if (e->dead)
+ continue;
+
+ /* Check if the incoming is a goodbye record */
+ if (avahi_record_is_goodbye(record)) {
+
+ if (avahi_record_equal_no_ttl(e->record, record)) {
+ char *t;
+
+ /* Refresh */
+ t = avahi_record_to_string(record);
+ avahi_log_debug("Recieved goodbye record for one of our records [%s]. Refreshing.", t);
+ avahi_server_prepare_matching_responses(s, i, e->record->key, 0);
+
+ valid = 0;
+ avahi_free(t);
+ break;
+ }
+
+ /* If the goodybe packet doesn't match one of our own RRs, we simply ignore it. */
+ continue;
+ }
+
+ if (!(e->flags & AVAHI_ENTRY_UNIQUE) && !unique)
continue;
/* Either our entry or the other is intended to be unique, so let's check */
avahi_interface_post_probe(j, r, 1);
}
-static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, uint16_t port, int legacy_unicast) {
+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;
goto fail;
}
- if (!legacy_unicast)
+ if (!legacy_unicast && !from_local_iface)
reflect_query(s, i, key);
if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 &&
avahi_key_unref(key);
}
- /* Known Answer Suppression */
- for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT); n > 0; n --) {
- AvahiRecord *record;
- int unique = 0;
-
- if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
- avahi_log_warn("Packet too short (2)");
- goto fail;
- }
+ if (!legacy_unicast) {
- if (handle_conflict(s, i, record, unique, a)) {
- avahi_response_scheduler_suppress(i->response_scheduler, record, a);
- avahi_record_list_drop(s->record_list, record);
+ /* Known Answer Suppression */
+ for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT); n > 0; n --) {
+ AvahiRecord *record;
+ int unique = 0;
+
+ if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
+ avahi_log_warn("Packet too short (2)");
+ goto fail;
+ }
+
+ if (handle_conflict(s, i, record, unique, a)) {
+ avahi_response_scheduler_suppress(i->response_scheduler, record, a);
+ avahi_record_list_drop(s->record_list, record);
+ }
+
+ avahi_record_unref(record);
}
- avahi_record_unref(record);
- }
-
- /* Probe record */
- for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT); n > 0; n --) {
- AvahiRecord *record;
- int unique = 0;
-
- if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
- avahi_log_warn("Packet too short (3)");
- goto fail;
- }
-
- if (!avahi_key_is_pattern(record->key)) {
- reflect_probe(s, i, record);
- incoming_probe(s, record, i);
+ /* Probe record */
+ for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT); n > 0; n --) {
+ AvahiRecord *record;
+ int unique = 0;
+
+ if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
+ avahi_log_warn("Packet too short (3)");
+ goto fail;
+ }
+
+ if (!avahi_key_is_pattern(record->key)) {
+ if (!from_local_iface)
+ reflect_probe(s, i, record);
+ incoming_probe(s, record, i);
+ }
+
+ avahi_record_unref(record);
}
-
- avahi_record_unref(record);
}
if (!avahi_record_list_is_empty(s->record_list))
avahi_record_list_flush(s->record_list);
}
-static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a) {
+static void handle_response_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, int from_local_iface) {
unsigned n;
assert(s);
/* avahi_free(txt); */
if (handle_conflict(s, i, record, cache_flush, a)) {
- reflect_response(s, i, record, cache_flush);
+ if (!from_local_iface)
+ reflect_response(s, i, record, cache_flush);
avahi_cache_update(i->cache, record, cache_flush, a);
avahi_response_scheduler_incoming(i->response_scheduler, record, cache_flush);
}
if (!(slot = avahi_new(AvahiLegacyUnicastReflectSlot, 1)))
return NULL; /* OOM */
- slot = s->legacy_unicast_reflect_slots[idx];
+ s->legacy_unicast_reflect_slots[idx] = slot;
slot->id = s->legacy_unicast_reflect_id++;
slot->server = s;
+
return slot;
}
assert(i);
assert(a);
assert(port > 0);
- assert(i->protocol == a->family);
+ assert(i->protocol == a->proto);
if (!s->config.enable_reflector)
return;
AvahiAddress b;
assert(a);
- avahi_address_parse(a->family == AVAHI_PROTO_INET ? AVAHI_IPV4_MCAST_GROUP : AVAHI_IPV6_MCAST_GROUP, a->family, &b);
+ avahi_address_parse(a->proto == AVAHI_PROTO_INET ? AVAHI_IPV4_MCAST_GROUP : AVAHI_IPV6_MCAST_GROUP, a->proto, &b);
return avahi_address_cmp(a, &b) == 0;
}
+static int originates_from_local_iface(AvahiServer *s, AvahiIfIndex iface, const AvahiAddress *a, uint16_t port) {
+ assert(s);
+ assert(iface != AVAHI_IF_UNSPEC);
+ assert(a);
+
+ /* If it isn't the MDNS port it can't be generated by us */
+ if (port != AVAHI_MDNS_PORT)
+ return 0;
+
+ return avahi_interface_has_address(s->monitor, iface, a);
+}
+
static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const struct sockaddr *sa, AvahiAddress *dest, AvahiIfIndex iface, int ttl) {
AvahiInterface *i;
AvahiAddress a;
uint16_t port;
+ int from_local_iface = 0;
assert(s);
assert(p);
assert(dest);
assert(iface > 0);
- if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family)) ||
+ if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, avahi_af_to_proto(sa->sa_family))) ||
!avahi_interface_relevant(i)) {
avahi_log_warn("Recieved packet from invalid interface.");
return;
/* This originates from our local reflector, so let's ignore it */
return;
+ /* We don't want to reflect local traffic, so we check if this packet is generated locally. */
+ if (s->config.enable_reflector)
+ from_local_iface = originates_from_local_iface(s, iface, &a, port);
+
if (avahi_dns_packet_is_valid(p) < 0) {
avahi_log_warn("Recieved invalid packet.");
return;
if (legacy_unicast)
reflect_legacy_unicast_query_packet(s, p, i, &a, port);
- handle_query_packet(s, p, i, &a, port, legacy_unicast);
+ handle_query_packet(s, p, i, &a, port, legacy_unicast, from_local_iface);
/* avahi_log_debug("Handled query"); */
} else {
return;
}
- handle_response_packet(s, p, i, &a);
+ handle_response_packet(s, p, i, &a, from_local_iface);
/* avahi_log_debug("Handled response"); */
}
}
assert(sa);
assert(iface > 0);
- if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family)) ||
+ if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, avahi_af_to_proto(sa->sa_family))) ||
!avahi_interface_relevant(i)) {
avahi_log_warn("Recieved packet from invalid interface.");
return;
return;
}
- if (!(j = avahi_interface_monitor_get_interface(s->monitor, slot->interface, slot->address.family)) ||
+ if (!(j = avahi_interface_monitor_get_interface(s->monitor, slot->interface, slot->address.proto)) ||
!avahi_interface_relevant(j))
return;
if (events & AVAHI_WATCH_IN) {
if (fd == s->fd_ipv4) {
- dest.family = AVAHI_PROTO_INET;
+ dest.proto = AVAHI_PROTO_INET;
if ((p = avahi_recv_dns_packet_ipv4(s->fd_ipv4, &sa, &dest.data.ipv4, &iface, &ttl))) {
dispatch_packet(s, p, (struct sockaddr*) &sa, &dest, iface, ttl);
avahi_dns_packet_free(p);
}
} else if (fd == s->fd_ipv6) {
- dest.family = AVAHI_PROTO_INET6;
+ dest.proto = AVAHI_PROTO_INET6;
if ((p = avahi_recv_dns_packet_ipv6(s->fd_ipv6, &sa6, &dest.data.ipv6, &iface, &ttl))) {
dispatch_packet(s, p, (struct sockaddr*) &sa6, &dest, iface, ttl);
avahi_dns_packet_free(p);
}
} else if (fd == s->fd_legacy_unicast_ipv4) {
- dest.family = AVAHI_PROTO_INET;
+ dest.proto = AVAHI_PROTO_INET;
if ((p = avahi_recv_dns_packet_ipv4(s->fd_legacy_unicast_ipv4, &sa, &dest.data.ipv4, &iface, &ttl))) {
dispatch_legacy_unicast_packet(s, p, (struct sockaddr*) &sa, iface, ttl);
avahi_dns_packet_free(p);
}
} else if (fd == s->fd_legacy_unicast_ipv6) {
- dest.family = AVAHI_PROTO_INET6;
+ dest.proto = AVAHI_PROTO_INET6;
if ((p = avahi_recv_dns_packet_ipv6(s->fd_legacy_unicast_ipv6, &sa6, &dest.data.ipv6, &iface, &ttl))) {
dispatch_legacy_unicast_packet(s, p, (struct sockaddr*) &sa6, iface, ttl);
assert(s);
if (s->hinfo_entry_group)
- avahi_entry_group_reset(s->hinfo_entry_group);
+ avahi_s_entry_group_reset(s->hinfo_entry_group);
if (s->browse_domain_entry_group)
- avahi_entry_group_reset(s->browse_domain_entry_group);
+ avahi_s_entry_group_reset(s->browse_domain_entry_group);
avahi_update_host_rrs(s->monitor, 1);
s->n_host_rr_pending = 0;
s->n_host_rr_pending ++;
}
-void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
+void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
assert(s);
assert(g);
return;
if (s->hinfo_entry_group)
- assert(avahi_entry_group_is_empty(s->hinfo_entry_group));
+ assert(avahi_s_entry_group_is_empty(s->hinfo_entry_group));
else
- s->hinfo_entry_group = avahi_entry_group_new(s, avahi_host_rr_entry_group_callback, NULL);
+ s->hinfo_entry_group = avahi_s_entry_group_new(s, avahi_host_rr_entry_group_callback, NULL);
if (!s->hinfo_entry_group) {
avahi_log_warn("Failed to create HINFO entry group: %s", avahi_strerror(s->error));
avahi_record_unref(r);
}
- if (avahi_entry_group_commit(s->hinfo_entry_group) < 0)
+ if (avahi_s_entry_group_commit(s->hinfo_entry_group) < 0)
avahi_log_warn("Failed to commit HINFO entry group: %s", avahi_strerror(s->error));
}
return;
if (s->browse_domain_entry_group)
- assert(avahi_entry_group_is_empty(s->browse_domain_entry_group));
+ assert(avahi_s_entry_group_is_empty(s->browse_domain_entry_group));
else
- s->browse_domain_entry_group = avahi_entry_group_new(s, NULL, NULL);
+ s->browse_domain_entry_group = avahi_s_entry_group_new(s, NULL, NULL);
if (!s->browse_domain_entry_group) {
avahi_log_warn("Failed to create browse domain entry group: %s", avahi_strerror(s->error));
return;
}
- if (avahi_entry_group_commit(s->browse_domain_entry_group) < 0)
+ if (avahi_s_entry_group_commit(s->browse_domain_entry_group) < 0)
avahi_log_warn("Failed to commit browse domain entry group: %s", avahi_strerror(s->error));
}
assert(s);
server_set_state(s, AVAHI_SERVER_REGISTERING);
+ s->n_host_rr_pending ++; /** Make sure that the state isn't changed tp AVAHI_SERVER_RUNNING too early */
+
register_hinfo(s);
register_browse_domain(s);
avahi_update_host_rrs(s->monitor, 0);
+ s->n_host_rr_pending --;
+
if (s->n_host_rr_pending == 0)
server_set_state(s, AVAHI_SERVER_RUNNING);
}
return 0;
}
-AvahiServer *avahi_server_new(AvahiPoll *poll_api, const AvahiServerConfig *sc, AvahiServerCallback callback, void* userdata, int *error) {
+AvahiServer *avahi_server_new(const AvahiPoll *poll_api, const AvahiServerConfig *sc, AvahiServerCallback callback, void* userdata, int *error) {
AvahiServer *s;
int e;
AVAHI_LLIST_HEAD_INIT(AvahiGroup, s->groups);
s->record_browser_hashmap = avahi_hashmap_new((AvahiHashFunc) avahi_key_hash, (AvahiEqualFunc) avahi_key_equal, NULL, NULL);
- AVAHI_LLIST_HEAD_INIT(AvahiRecordBrowser, s->record_browsers);
- AVAHI_LLIST_HEAD_INIT(AvahiHostNameResolver, s->host_name_resolvers);
- AVAHI_LLIST_HEAD_INIT(AvahiAddressResolver, s->address_resolvers);
- AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, s->domain_browsers);
- AVAHI_LLIST_HEAD_INIT(AvahiServiceTypeBrowser, s->service_type_browsers);
- AVAHI_LLIST_HEAD_INIT(AvahiServiceBrowser, s->service_browsers);
- AVAHI_LLIST_HEAD_INIT(AvahiServiceResolver, s->service_resolvers);
- AVAHI_LLIST_HEAD_INIT(AvahiDNSServerBrowser, s->dns_server_browsers);
+ AVAHI_LLIST_HEAD_INIT(AvahiSRecordBrowser, s->record_browsers);
+ AVAHI_LLIST_HEAD_INIT(AvahiSHostNameResolver, s->host_name_resolvers);
+ AVAHI_LLIST_HEAD_INIT(AvahiSAddressResolver, s->address_resolvers);
+ AVAHI_LLIST_HEAD_INIT(AvahiSDomainBrowser, s->domain_browsers);
+ AVAHI_LLIST_HEAD_INIT(AvahiSServiceTypeBrowser, s->service_type_browsers);
+ AVAHI_LLIST_HEAD_INIT(AvahiSServiceBrowser, s->service_browsers);
+ AVAHI_LLIST_HEAD_INIT(AvahiSServiceResolver, s->service_resolvers);
+ AVAHI_LLIST_HEAD_INIT(AvahiSDNSServerBrowser, s->dns_server_browsers);
s->legacy_unicast_reflect_slots = NULL;
s->legacy_unicast_reflect_id = 0;
+
+ do {
+ s->local_service_cookie = (uint32_t) rand() * (uint32_t) rand();
+ } while (s->local_service_cookie == AVAHI_SERVICE_COOKIE_INVALID);
/* Get host name */
s->host_name = s->config.host_name ? avahi_normalize_name(s->config.host_name) : avahi_get_host_name();
free_slots(s);
while (s->dns_server_browsers)
- avahi_dns_server_browser_free(s->dns_server_browsers);
+ avahi_s_dns_server_browser_free(s->dns_server_browsers);
while (s->host_name_resolvers)
- avahi_host_name_resolver_free(s->host_name_resolvers);
+ avahi_s_host_name_resolver_free(s->host_name_resolvers);
while (s->address_resolvers)
- avahi_address_resolver_free(s->address_resolvers);
+ avahi_s_address_resolver_free(s->address_resolvers);
while (s->domain_browsers)
- avahi_domain_browser_free(s->domain_browsers);
+ avahi_s_domain_browser_free(s->domain_browsers);
while (s->service_type_browsers)
- avahi_service_type_browser_free(s->service_type_browsers);
+ avahi_s_service_type_browser_free(s->service_type_browsers);
while (s->service_browsers)
- avahi_service_browser_free(s->service_browsers);
+ avahi_s_service_browser_free(s->service_browsers);
while (s->service_resolvers)
- avahi_service_resolver_free(s->service_resolvers);
+ avahi_s_service_resolver_free(s->service_resolvers);
while (s->record_browsers)
- avahi_record_browser_destroy(s->record_browsers);
+ avahi_s_record_browser_destroy(s->record_browsers);
avahi_hashmap_free(s->record_browser_hashmap);
avahi_hashmap_free(s->entries_by_key);
if ((flags & AVAHI_ENTRY_ALLOWMUTIPLE) && (e->flags & AVAHI_ENTRY_ALLOWMUTIPLE) )
continue;
- if (interface <= 0 ||
- e->interface <= 0 ||
- e->interface == interface ||
- protocol == AVAHI_PROTO_UNSPEC ||
- e->protocol == AVAHI_PROTO_UNSPEC ||
- e->protocol == protocol)
+ if ((interface <= 0 ||
+ e->interface <= 0 ||
+ e->interface == interface) &&
+ (protocol == AVAHI_PROTO_UNSPEC ||
+ e->protocol == AVAHI_PROTO_UNSPEC ||
+ e->protocol == protocol))
return -1;
-
}
return 0;
int avahi_server_add(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiEntryFlags flags,
return 0;
}
-const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state) {
+const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiSEntryGroup *g, void **state) {
AvahiEntry **e = (AvahiEntry**) state;
assert(s);
assert(e);
int avahi_server_add_ptr(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiEntryFlags flags,
int avahi_server_add_address(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiEntryFlags flags,
goto fail;
}
- if (a->family == AVAHI_PROTO_INET) {
+ if (a->proto == AVAHI_PROTO_INET) {
char *reverse;
AvahiRecord *r;
char *reverse;
AvahiRecord *r;
- assert(a->family == AVAHI_PROTO_INET6);
+ assert(a->proto == AVAHI_PROTO_INET6);
if (!(r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA, AVAHI_DEFAULT_TTL_HOST_NAME))) {
ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
static int server_add_txt_strlst_nocopy(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiEntryFlags flags,
int avahi_server_add_txt_strlst(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiEntryFlags flags,
int avahi_server_add_txt_va(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiEntryFlags flags,
int avahi_server_add_txt(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiEntryFlags flags,
*(d++) = 0;
}
+static AvahiStringList *add_magic_cookie(
+ AvahiServer *s,
+ AvahiStringList *strlst) {
+
+ assert(s);
+
+ if (!s->config.add_service_cookie)
+ return strlst;
+
+ if (avahi_string_list_find(strlst, AVAHI_SERVICE_COOKIE))
+ /* This string list already contains a magic cookie */
+ return strlst;
+
+ return avahi_string_list_add_printf(strlst, AVAHI_SERVICE_COOKIE"=%u", s->local_service_cookie);
+}
+
static int server_add_service_strlst_nocopy(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *name,
if (host && !avahi_is_valid_domain_name(host))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME);
- if (port == 0)
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT);
-
escape_service_name(ename, sizeof(ename), name);
if (!domain)
if (ret < 0)
goto fail;
+ strlst = add_magic_cookie(s, strlst);
+
ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
strlst = NULL;
int avahi_server_add_service_strlst(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *name,
int avahi_server_add_service_va(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *name,
int avahi_server_add_service(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *name,
int avahi_server_add_dns_server_address(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *domain,
assert(s);
assert(address);
assert(type == AVAHI_DNS_SERVER_UPDATE || type == AVAHI_DNS_SERVER_RESOLVE);
- assert(address->family == AVAHI_PROTO_INET || address->family == AVAHI_PROTO_INET6);
-
- if (domain && !avahi_is_valid_domain_name(domain))
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
+ assert(address->proto == AVAHI_PROTO_INET || address->proto == AVAHI_PROTO_INET6);
if (port == 0)
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT);
- if (address->family == AVAHI_PROTO_INET) {
+ if (domain && !avahi_is_valid_domain_name(domain))
+ return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
+
+ if (address->proto == AVAHI_PROTO_INET) {
hexstring(n+3, sizeof(n)-3, &address->data, 4);
r = avahi_record_new_full(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A, AVAHI_DEFAULT_TTL_HOST_NAME);
r->data.a.address = address->data.ipv4;
int avahi_server_add_dns_server_name(
AvahiServer *s,
- AvahiEntryGroup *g,
+ AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *domain,
avahi_interface_monitor_walk(s->monitor, interface, protocol, post_query_callback, key);
}
-void avahi_entry_group_change_state(AvahiEntryGroup *g, AvahiEntryGroupState state) {
+void avahi_s_entry_group_change_state(AvahiSEntryGroup *g, AvahiEntryGroupState state) {
assert(g);
if (g->state == state)
g->callback(g->server, g, state, g->userdata);
}
-AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, void* userdata) {
- AvahiEntryGroup *g;
+AvahiSEntryGroup *avahi_s_entry_group_new(AvahiServer *s, AvahiSEntryGroupCallback callback, void* userdata) {
+ AvahiSEntryGroup *g;
assert(s);
- if (!(g = avahi_new(AvahiEntryGroup, 1))) {
+ if (!(g = avahi_new(AvahiSEntryGroup, 1))) {
avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
return NULL;
}
g->register_time.tv_usec = 0;
AVAHI_LLIST_HEAD_INIT(AvahiEntry, g->entries);
- AVAHI_LLIST_PREPEND(AvahiEntryGroup, groups, s->groups, g);
+ AVAHI_LLIST_PREPEND(AvahiSEntryGroup, groups, s->groups, g);
return g;
}
-void avahi_entry_group_free(AvahiEntryGroup *g) {
+void avahi_s_entry_group_free(AvahiSEntryGroup *g) {
AvahiEntry *e;
assert(g);
g->server->need_entry_cleanup = 1;
}
-static void entry_group_commit_real(AvahiEntryGroup *g) {
+static void entry_group_commit_real(AvahiSEntryGroup *g) {
assert(g);
gettimeofday(&g->register_time, NULL);
- avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
+ avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
if (!g->dead) {
avahi_announce_group(g->server, g);
- avahi_entry_group_check_probed(g, 0);
+ avahi_s_entry_group_check_probed(g, 0);
}
}
static void entry_group_register_time_event_callback(AvahiTimeEvent *e, void* userdata) {
- AvahiEntryGroup *g = userdata;
+ AvahiSEntryGroup *g = userdata;
assert(g);
/* avahi_log_debug("Holdoff passed, waking up and going on."); */
entry_group_commit_real(g);
}
-int avahi_entry_group_commit(AvahiEntryGroup *g) {
+int avahi_s_entry_group_commit(AvahiSEntryGroup *g) {
struct timeval now;
assert(g);
assert(!g->register_time_event);
g->register_time_event = avahi_time_event_new(g->server->time_event_queue, &g->register_time, entry_group_register_time_event_callback, g);
- avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
+ avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
}
return AVAHI_OK;
}
-void avahi_entry_group_reset(AvahiEntryGroup *g) {
+void avahi_s_entry_group_reset(AvahiSEntryGroup *g) {
AvahiEntry *e;
assert(g);
g->server->need_entry_cleanup = 1;
g->n_probing = 0;
- avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_UNCOMMITED);
+ avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_UNCOMMITED);
}
int avahi_entry_is_commited(AvahiEntry *e) {
e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED;
}
-AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g) {
+AvahiEntryGroupState avahi_s_entry_group_get_state(AvahiSEntryGroup *g) {
assert(g);
assert(!g->dead);
return g->state;
}
-void avahi_entry_group_set_data(AvahiEntryGroup *g, void* userdata) {
+void avahi_s_entry_group_set_data(AvahiSEntryGroup *g, void* userdata) {
assert(g);
g->userdata = userdata;
}
-void* avahi_entry_group_get_data(AvahiEntryGroup *g) {
+void* avahi_s_entry_group_get_data(AvahiSEntryGroup *g) {
assert(g);
return g->userdata;
}
-int avahi_entry_group_is_empty(AvahiEntryGroup *g) {
+int avahi_s_entry_group_is_empty(AvahiSEntryGroup *g) {
AvahiEntry *e;
assert(g);
c->use_iff_running = 0;
c->enable_reflector = 0;
c->reflect_ipv = 0;
+ c->add_service_cookie = 1;
return c;
}
return s->error = error;
}
+uint32_t avahi_server_get_local_service_cookie(AvahiServer *s) {
+ assert(s);
+
+ return s->local_service_cookie;
+}
+
+int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char*domain) {
+ AvahiKey *key = NULL;
+ char *d, *t;
+ char ename[64], n[256];
+ int ret;
+ AvahiEntry *e;
+
+ assert(s);
+ assert(name);
+ assert(type);
+ assert(domain);
+
+ if (!avahi_is_valid_service_name(name))
+ return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_NAME);
+
+ if (!avahi_is_valid_service_type(type))
+ return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_TYPE);
+
+ if (domain && !avahi_is_valid_domain_name(domain))
+ return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
+
+ escape_service_name(ename, sizeof(ename), name);
+
+ if (!(d = avahi_normalize_name(domain)) ||
+ !(t = avahi_normalize_name(type))) {
+ ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+ snprintf(n, sizeof(n), "%s.%s.%s", ename, t, d);
+
+ if (!(key = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV))) {
+ ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ ret = 0;
+
+ for (e = avahi_hashmap_lookup(s->entries_by_key, key); e; e = e->by_key_next) {
+
+ if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
+ (e->protocol == protocol || e->protocol == AVAHI_PROTO_UNSPEC || protocol == AVAHI_PROTO_UNSPEC)) {
+ ret = 1;
+ break;
+ }
+ }
+
+ avahi_key_unref(key);
+
+ avahi_free(d);
+ avahi_free(t);
+
+ return ret;
+
+fail:
+ if (d)
+ avahi_free(d);
+
+ if (t)
+ avahi_free(t);
+
+ if (key)
+ avahi_key_unref(key);
+
+ return ret;
+}