diff --git a/cache.c b/cache.c index 06c4eb6..c9527e2 100644 --- a/cache.c +++ b/cache.c @@ -128,7 +128,14 @@ cache_gc_timer(struct uloop_timeout *timeout) continue; } r->refresh += 50; - dns_send_question(r->iface, (struct sockaddr *)&r->from, r->record, r->type, 0); + /* + * Preserve refresh routing: multicast interfaces send a QU query + * to the mDNS group, while unicast interfaces query the cached peer. + */ + dns_send_question(r->iface, + interface_multicast(r->iface) ? NULL : + (struct sockaddr *)&r->from, + r->record, r->type, 0); } avl_for_each_element_safe(&services, s, avl, t) { diff --git a/dns.c b/dns.c index 6e7ec15..5159302 100644 --- a/dns.c +++ b/dns.c @@ -589,11 +589,8 @@ parse_question(struct interface *iface, struct sockaddr *from, char *name, struc char *host, *host6; /* TODO: Multicast if more than one quarter of TTL has passed */ - if (is_unicast) { + if (is_unicast) to = from; - if (interface_multicast(iface)) - iface = interface_get(iface->name, iface->type | SOCKTYPE_BIT_UNICAST); - } DBG(1, "Q -> %s %s\n", dns_type_string(q->type), name); diff --git a/interface.c b/interface.c index 340878e..0017084 100644 --- a/interface.c +++ b/interface.c @@ -78,10 +78,8 @@ interface_send_packet4(struct interface *iface, struct sockaddr_in *to, struct i pkti->ipi_ifindex = iface->ifindex; fd = ufd[iface->type].fd; - if (interface_multicast(iface)) { + if (interface_multicast(iface) && !to) { a.sin_addr.s_addr = inet_addr(MCAST_ADDR); - if (to) - fprintf(stderr, "Ignoring IPv4 address for multicast interface\n"); } else { a.sin_addr.s_addr = to->sin_addr.s_addr; a.sin_port = to->sin_port; @@ -121,10 +119,8 @@ interface_send_packet6(struct interface *iface, struct sockaddr_in6 *to, struct pkti->ipi6_ifindex = iface->ifindex; fd = ufd[iface->type].fd; - if (interface_multicast(iface)) { + if (interface_multicast(iface) && !to) { inet_pton(AF_INET6, MCAST_ADDR6, &a.sin6_addr); - if (to) - fprintf(stderr, "Ignoring IPv6 address for multicast interface\n"); } else { a.sin6_addr = to->sin6_addr; } @@ -518,8 +514,8 @@ static int interface_init_socket(enum umdns_socket_type type, bool *mcast) local.sin_port = htons(MCAST_PORT); break; case SOCK_MC_IPV6: - setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)); - setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)); + setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ittl, sizeof(ittl)); + setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ittl, sizeof(ittl)); setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)); setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &no, sizeof(no)); local6.sin6_port = htons(MCAST_PORT);