We use stream objects in four different cases: let's track them.
This in particular allows us to make sure the limit on outgoing streams
cannot be exhausted by having incoming streams as this means we can
neatly separate the counters for all four types.
if (s->manager) {
LIST_REMOVE(streams, s->manager->dns_streams, s);
- s->manager->n_dns_streams--;
+ s->manager->n_dns_streams[s->type]--;
}
#if ENABLE_DNS_OVER_TLS
int dns_stream_new(
Manager *m,
DnsStream **ret,
+ DnsStreamType type,
DnsProtocol protocol,
int fd,
const union sockaddr_union *tfo_address) {
assert(m);
assert(ret);
+ assert(type >= 0);
+ assert(type < _DNS_STREAM_TYPE_MAX);
+ assert(protocol >= 0);
+ assert(protocol < _DNS_PROTOCOL_MAX);
assert(fd >= 0);
- if (m->n_dns_streams > DNS_STREAMS_MAX)
+ if (m->n_dns_streams[type] > DNS_STREAMS_MAX)
return -EBUSY;
s = new(DnsStream, 1);
(void) sd_event_source_set_description(s->timeout_event_source, "dns-stream-timeout");
LIST_PREPEND(streams, m->dns_streams, s);
- m->n_dns_streams++;
+ m->n_dns_streams[type]++;
s->manager = m;
s->fd = fd;
typedef struct DnsStream DnsStream;
+typedef enum DnsStreamType {
+ DNS_STREAM_LOOKUP, /* Outgoing connection to a classic DNS server */
+ DNS_STREAM_LLMNR_SEND, /* Outgoing LLMNR TCP lookup */
+ DNS_STREAM_LLMNR_RECV, /* Incoming LLMNR TCP lookup */
+ DNS_STREAM_STUB, /* Incoming DNS stub connection */
+ _DNS_STREAM_TYPE_MAX,
+ _DNS_STREAM_TYPE_INVALID = -1,
+} DnsStreamType;
+
#include "resolved-dns-packet.h"
#include "resolved-dns-transaction.h"
#include "resolved-manager.h"
Manager *manager;
unsigned n_ref;
+ DnsStreamType type;
DnsProtocol protocol;
int fd;
LIST_FIELDS(DnsStream, streams);
};
-int dns_stream_new(Manager *m, DnsStream **s, DnsProtocol protocol, int fd, const union sockaddr_union *tfo_address);
+int dns_stream_new(Manager *m, DnsStream **s, DnsStreamType type, DnsProtocol protocol, int fd, const union sockaddr_union *tfo_address);
#if ENABLE_DNS_OVER_TLS
int dns_stream_connect_tls(DnsStream *s, void *tls_session);
#endif
return -errno;
}
- r = dns_stream_new(m, &stream, DNS_PROTOCOL_DNS, cfd, NULL);
+ r = dns_stream_new(m, &stream, DNS_STREAM_STUB, DNS_PROTOCOL_DNS, cfd, NULL);
if (r < 0) {
safe_close(cfd);
return r;
}
static int dns_transaction_emit_tcp(DnsTransaction *t) {
- _cleanup_close_ int fd = -1;
_cleanup_(dns_stream_unrefp) DnsStream *s = NULL;
+ _cleanup_close_ int fd = -1;
union sockaddr_union sa;
+ DnsStreamType type;
int r;
assert(t);
else
fd = dns_scope_socket_tcp(t->scope, AF_UNSPEC, NULL, t->server, dns_port_for_feature_level(t->current_feature_level), &sa);
+ type = DNS_STREAM_LOOKUP;
break;
case DNS_PROTOCOL_LLMNR:
fd = dns_scope_socket_tcp(t->scope, family, &address, NULL, LLMNR_PORT, &sa);
}
+ type = DNS_STREAM_LLMNR_SEND;
break;
default:
if (fd < 0)
return fd;
- r = dns_stream_new(t->scope->manager, &s, t->scope->protocol, fd, &sa);
+ r = dns_stream_new(t->scope->manager, &s, type, t->scope->protocol, fd, &sa);
if (r < 0)
return r;
return -errno;
}
- r = dns_stream_new(m, &stream, DNS_PROTOCOL_LLMNR, cfd, NULL);
+ r = dns_stream_new(m, &stream, DNS_STREAM_LLMNR_RECV, DNS_PROTOCOL_LLMNR, cfd, NULL);
if (r < 0) {
safe_close(cfd);
return r;
unsigned n_dns_queries;
LIST_HEAD(DnsStream, dns_streams);
- unsigned n_dns_streams;
+ unsigned n_dns_streams[_DNS_STREAM_TYPE_MAX];
/* Unicast dns */
LIST_HEAD(DnsServer, dns_servers);