return NULL;
}
-DnsServer *dns_scope_get_server(DnsScope *s) {
+DnsServer *dns_scope_get_dns_server(DnsScope *s) {
assert(s);
if (s->protocol != DNS_PROTOCOL_DNS)
if (DNS_PACKET_QDCOUNT(p) > 1)
return -ENOTSUP;
- srv = dns_scope_get_server(s);
+ srv = dns_scope_get_dns_server(s);
if (!srv)
return -ESRCH;
if (family == AF_UNSPEC) {
DnsServer *srv;
- srv = dns_scope_get_server(s);
+ srv = dns_scope_get_dns_server(s);
if (!srv)
return -ESRCH;
if (fd < 0)
return fd;
+ /* Always first try to drop membership before we add
+ * one. This is necessary on some devices, such as
+ * veth. */
+ if (b)
+ setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreqn, sizeof(mreqn));
+
if (setsockopt(fd, IPPROTO_IP, b ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP, &mreqn, sizeof(mreqn)) < 0)
return -errno;
if (fd < 0)
return fd;
+ if (b)
+ setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
+
if (setsockopt(fd, IPPROTO_IPV6, b ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
return -errno;
} else
assert(s);
- if (q->n_keys <= 0 && answer->n_rrs <= 0 && soa->n_rrs <= 0)
+ if ((!q || q->n_keys <= 0)
+ && (!answer || answer->n_rrs <= 0)
+ && (!soa || soa->n_rrs <= 0))
return -EINVAL;
r = dns_packet_new(&p, s->protocol, 0);
}
}
-DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsQuestion *question) {
+DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsQuestion *question, bool cache_ok) {
DnsTransaction *t;
assert(scope);
/* Try to find an ongoing transaction that is a equal or a
* superset of the specified question */
- LIST_FOREACH(transactions_by_scope, t, scope->transactions)
+ LIST_FOREACH(transactions_by_scope, t, scope->transactions) {
+
+ /* Refuse reusing transactions that completed based on
+ * cached data instead of a real packet, if that's
+ * requested. */
+ if (!cache_ok &&
+ IN_SET(t->state, DNS_TRANSACTION_SUCCESS, DNS_TRANSACTION_FAILURE) &&
+ !t->received)
+ continue;
+
if (dns_question_is_superset(t->question, question) > 0)
return t;
+ }
return NULL;
}