X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fiface.c;h=f882988cfb55bf79f0074445750a1bf4460fcb29;hb=57a30ff663414e1799a9b991a3e4eac148a8131e;hp=38d9909cb28c6d91a7490676b14712a7e6a2b569;hpb=d11fa869cfa12c1ed84a64e0268282934b68b478;p=catta diff --git a/avahi-core/iface.c b/avahi-core/iface.c index 38d9909..f882988 100644 --- a/avahi-core/iface.c +++ b/avahi-core/iface.c @@ -42,6 +42,8 @@ #include "announce.h" #include "util.h" #include "log.h" +#include "multicast-lookup.h" +#include "querier.h" static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a, int remove_rrs) { assert(m); @@ -180,11 +182,16 @@ static void free_interface(AvahiInterfaceMonitor *m, AvahiInterface *i, int send assert(m); assert(i); + /* Handle goodbyes and remove announcers */ avahi_goodbye_interface(m->server, i, send_goodbye); avahi_response_scheduler_force(i->response_scheduler); - assert(!i->announcements); + /* Remove queriers */ + avahi_querier_free_all(i); + avahi_hashmap_free(i->queriers_by_key); + + /* Remove local RRs */ update_interface_rr(m, i, 1); while (i->addresses) @@ -243,7 +250,7 @@ static int netlink_list_items(AvahiNetlink *nl, uint16_t type, unsigned *ret_seq n = (struct nlmsghdr*) req; n->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)); n->nlmsg_type = type; - n->nlmsg_flags = NLM_F_ROOT/*|NLM_F_MATCH*/|NLM_F_REQUEST; + n->nlmsg_flags = NLM_F_ROOT|NLM_F_REQUEST; n->nlmsg_pid = 0; gen = NLMSG_DATA(n); @@ -271,6 +278,9 @@ static void new_interface(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, AvahiP AVAHI_LLIST_HEAD_INIT(AvahiInterfaceAddress, i->addresses); AVAHI_LLIST_HEAD_INIT(AvahiAnnouncement, i->announcements); + AVAHI_LLIST_HEAD_INIT(AvahiQuerier, i->queriers); + i->queriers_by_key = avahi_hashmap_new((AvahiHashFunc) avahi_key_hash, (AvahiEqualFunc) avahi_key_equal, NULL, NULL); + i->cache = avahi_cache_new(m->server, i); i->response_scheduler = avahi_response_scheduler_new(i); i->query_scheduler = avahi_query_scheduler_new(i); @@ -307,7 +317,7 @@ static void check_interface_relevant(AvahiInterfaceMonitor *m, AvahiInterface *i b = avahi_interface_relevant(i); if (m->list == LIST_DONE && b && !i->announcing) { - avahi_log_info("New relevant interface %s.%i.", i->hardware->name, i->protocol); + avahi_log_info("New relevant interface %s.%s.", i->hardware->name, avahi_proto_to_string(i->protocol)); if (i->protocol == AVAHI_PROTO_INET) avahi_mdns_mcast_join_ipv4(m->server->fd_ipv4, i->hardware->index); @@ -316,9 +326,9 @@ static void check_interface_relevant(AvahiInterfaceMonitor *m, AvahiInterface *i i->announcing = 1; avahi_announce_interface(m->server, i); - avahi_browser_new_interface(m->server, i); + avahi_multicast_lookup_engine_new_interface(m->server->multicast_lookup_engine, i); } else if (!b && i->announcing) { - avahi_log_info("Interface %s.%i no longer relevant.", i->hardware->name, i->protocol); + avahi_log_info("Interface %s.%s no longer relevant.", i->hardware->name, avahi_proto_to_string(i->protocol)); if (i->protocol == AVAHI_PROTO_INET) avahi_mdns_mcast_leave_ipv4(m->server->fd_ipv4, i->hardware->index); @@ -326,6 +336,8 @@ static void check_interface_relevant(AvahiInterfaceMonitor *m, AvahiInterface *i avahi_mdns_mcast_leave_ipv6(m->server->fd_ipv6, i->hardware->index); avahi_goodbye_interface(m->server, i, 0); + avahi_querier_free_all(i); + avahi_response_scheduler_clear(i->response_scheduler); avahi_query_scheduler_clear(i->query_scheduler); avahi_probe_scheduler_clear(i->probe_scheduler); @@ -450,13 +462,13 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat AvahiAddress raddr; int raddr_valid = 0; - if (ifaddrmsg->ifa_family != AVAHI_PROTO_INET && ifaddrmsg->ifa_family != AVAHI_PROTO_INET6) + if (ifaddrmsg->ifa_family != AF_INET && ifaddrmsg->ifa_family != AF_INET6) return; - if (!(i = (AvahiInterface*) avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifaddrmsg->ifa_index, (AvahiProtocol) ifaddrmsg->ifa_family))) + if (!(i = (AvahiInterface*) avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifaddrmsg->ifa_index, avahi_af_to_proto(ifaddrmsg->ifa_family)))) return; - raddr.family = (AvahiProtocol) ifaddrmsg->ifa_family; + raddr.proto = avahi_af_to_proto(ifaddrmsg->ifa_family); l = NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg)); a = IFA_RTA(ifaddrmsg); @@ -465,8 +477,8 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat switch(a->rta_type) { case IFA_ADDRESS: - if ((raddr.family == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || - (raddr.family == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4)) + if ((raddr.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || + (raddr.proto == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4)) return; memcpy(raddr.data.data, RTA_DATA(a), RTA_PAYLOAD(a)); @@ -585,7 +597,6 @@ void avahi_interface_monitor_free(AvahiInterfaceMonitor *m) { free_hw_interface(m, m->hw_interfaces, 1); assert(!m->interfaces); - if (m->netlink) avahi_netlink_free(m->netlink); @@ -602,7 +613,7 @@ AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, AvahiInterface *i; assert(m); - assert(idx > 0); + assert(idx >= 0); assert(protocol != AVAHI_PROTO_UNSPEC); if (!(hw = avahi_interface_monitor_get_hw_interface(m, idx))) @@ -630,7 +641,7 @@ void avahi_interface_send_packet_unicast(AvahiInterface *i, AvahiDnsPacket *p, c if (!avahi_interface_relevant(i)) return; - assert(!a || a->family == i->protocol); + assert(!a || a->proto == i->protocol); /* if (a) */ /* avahi_log_debug("unicast sending on '%s.%i' to %s:%u", i->hardware->name, i->protocol, avahi_address_snprint(t, sizeof(t), a), port); */ @@ -687,7 +698,7 @@ int avahi_dump_caches(AvahiInterfaceMonitor *m, AvahiDumpCallback callback, void for (i = m->interfaces; i; i = i->interface_next) { if (avahi_interface_relevant(i)) { char ln[256]; - snprintf(ln, sizeof(ln), ";;; INTERFACE %s.%i ;;;", i->hardware->name, i->protocol); + snprintf(ln, sizeof(ln), ";;; INTERFACE %s.%s ;;;", i->hardware->name, avahi_proto_to_string(i->protocol)); callback(ln, userdata); if (avahi_cache_dump(i->cache, callback, userdata) < 0) return -1; @@ -757,7 +768,7 @@ int avahi_interface_address_relevant(AvahiInterfaceAddress *a) { int avahi_interface_match(AvahiInterface *i, AvahiIfIndex idx, AvahiProtocol protocol) { assert(i); - if (idx > 0 && idx != i->hardware->index) + if (idx != AVAHI_IF_UNSPEC && idx != i->hardware->index) return 0; if (protocol != AVAHI_PROTO_UNSPEC && protocol != i->protocol) @@ -770,7 +781,7 @@ void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, AvahiIfIndex interfa assert(m); assert(callback); - if (interface > 0) { + if (interface != AVAHI_IF_UNSPEC) { if (protocol != AVAHI_PROTO_UNSPEC) { AvahiInterface *i; @@ -825,12 +836,12 @@ int avahi_interface_address_on_link(AvahiInterface *i, const AvahiAddress *a) { assert(i); assert(a); - if (a->family != i->protocol) + if (a->proto != i->protocol) return 0; for (ia = i->addresses; ia; ia = ia->address_next) { - if (a->family == AVAHI_PROTO_INET) { + if (a->proto == AVAHI_PROTO_INET) { uint32_t m; m = ~(((uint32_t) -1) >> ia->prefix_len); @@ -840,7 +851,7 @@ int avahi_interface_address_on_link(AvahiInterface *i, const AvahiAddress *a) { } else { unsigned j; unsigned char pl; - assert(a->family == AVAHI_PROTO_INET6); + assert(a->proto == AVAHI_PROTO_INET6); pl = ia->prefix_len; @@ -875,7 +886,7 @@ int avahi_interface_has_address(AvahiInterfaceMonitor *m, AvahiIfIndex iface, co assert(iface != AVAHI_IF_UNSPEC); assert(a); - if (!(i = avahi_interface_monitor_get_interface(m, iface, a->family))) + if (!(i = avahi_interface_monitor_get_interface(m, iface, a->proto))) return 0; for (j = i->addresses; j; j = j->address_next)