Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 4 additions & 8 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down