]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-stream.h
resolved: set io events after receiving EAGAIN for TLS
[thirdparty/systemd.git] / src / resolve / resolved-dns-stream.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
623a4c97
LP
2#pragma once
3
623a4c97
LP
4#include "socket-util.h"
5
6typedef struct DnsStream DnsStream;
7
ec2c5e43
LP
8#include "resolved-dns-packet.h"
9#include "resolved-dns-transaction.h"
07f264e4 10#include "resolved-manager.h"
56ddbf10 11#if ENABLE_DNS_OVER_TLS
6016fcb0 12#include "resolved-dnstls.h"
5d67a7ae
IT
13#endif
14
6016fcb0
IT
15#define DNS_STREAM_WRITE_TLS_DATA 1
16
b30bf55d
LP
17/* Streams are used by three subsystems:
18 *
19 * 1. The normal transaction logic when doing a DNS or LLMNR lookup via TCP
20 * 2. The LLMNR logic when accepting a TCP-based lookup
21 * 3. The DNS stub logic when accepting a TCP-based lookup
22 */
23
623a4c97
LP
24struct DnsStream {
25 Manager *manager;
b30bf55d 26 int n_ref;
623a4c97
LP
27
28 DnsProtocol protocol;
29
30 int fd;
31 union sockaddr_union peer;
32 socklen_t peer_salen;
33 union sockaddr_union local;
34 socklen_t local_salen;
35 int ifindex;
36 uint32_t ttl;
b914e211 37 bool identified;
623a4c97 38
91ccab1e
IT
39 /* only when using TCP fast open */
40 union sockaddr_union tfo_address;
41 socklen_t tfo_salen;
42
56ddbf10 43#if ENABLE_DNS_OVER_TLS
6016fcb0 44 DnsTlsStreamData dnstls_data;
ba6aaf57 45 int dnstls_events;
5d67a7ae
IT
46#endif
47
623a4c97
LP
48 sd_event_source *io_event_source;
49 sd_event_source *timeout_event_source;
50
51 be16_t write_size, read_size;
52 DnsPacket *write_packet, *read_packet;
53 size_t n_written, n_read;
98767d75 54 OrderedSet *write_queue;
623a4c97 55
5d67a7ae 56 int (*on_connection)(DnsStream *s);
623a4c97
LP
57 int (*on_packet)(DnsStream *s);
58 int (*complete)(DnsStream *s, int error);
59
98767d75
IT
60 LIST_HEAD(DnsTransaction, transactions); /* when used by the transaction logic */
61 DnsServer *server; /* when used by the transaction logic */
b30bf55d 62 DnsQuery *query; /* when used by the DNS stub logic */
623a4c97 63
5d67a7ae
IT
64 /* used when DNS-over-TLS is enabled */
65 bool encrypted:1;
66
623a4c97
LP
67 LIST_FIELDS(DnsStream, streams);
68};
69
91ccab1e 70int dns_stream_new(Manager *m, DnsStream **s, DnsProtocol protocol, int fd, const union sockaddr_union *tfo_address);
56ddbf10 71#if ENABLE_DNS_OVER_TLS
6016fcb0 72int dns_stream_connect_tls(DnsStream *s, void *tls_session);
5d67a7ae 73#endif
b30bf55d
LP
74DnsStream *dns_stream_unref(DnsStream *s);
75DnsStream *dns_stream_ref(DnsStream *s);
623a4c97 76
98767d75
IT
77DEFINE_TRIVIAL_CLEANUP_FUNC(DnsStream*, dns_stream_unref);
78
623a4c97 79int dns_stream_write_packet(DnsStream *s, DnsPacket *p);
6016fcb0 80ssize_t dns_stream_writev(DnsStream *s, const struct iovec *iov, size_t iovcnt, int flags);
b30bf55d
LP
81
82static inline bool DNS_STREAM_QUEUED(DnsStream *s) {
83 assert(s);
84
85 if (s->fd < 0) /* already stopped? */
86 return false;
87
88 return !!s->write_packet;
89}