]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-stream.h
resolved: make two functions static
[thirdparty/systemd.git] / src / resolve / resolved-dns-stream.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include "socket-util.h"
5
6 typedef struct DnsStream DnsStream;
7
8 typedef enum DnsStreamType {
9 DNS_STREAM_LOOKUP, /* Outgoing connection to a classic DNS server */
10 DNS_STREAM_LLMNR_SEND, /* Outgoing LLMNR TCP lookup */
11 DNS_STREAM_LLMNR_RECV, /* Incoming LLMNR TCP lookup */
12 DNS_STREAM_STUB, /* Incoming DNS stub connection */
13 _DNS_STREAM_TYPE_MAX,
14 _DNS_STREAM_TYPE_INVALID = -1,
15 } DnsStreamType;
16
17 #include "resolved-dns-packet.h"
18 #include "resolved-dns-transaction.h"
19 #include "resolved-dnstls.h"
20 #include "resolved-manager.h"
21
22 #define DNS_STREAM_WRITE_TLS_DATA 1
23
24 /* Streams are used by three subsystems:
25 *
26 * 1. The normal transaction logic when doing a DNS or LLMNR lookup via TCP
27 * 2. The LLMNR logic when accepting a TCP-based lookup
28 * 3. The DNS stub logic when accepting a TCP-based lookup
29 */
30
31 struct DnsStream {
32 Manager *manager;
33 unsigned n_ref;
34
35 DnsStreamType type;
36 DnsProtocol protocol;
37
38 int fd;
39 union sockaddr_union peer;
40 socklen_t peer_salen;
41 union sockaddr_union local;
42 socklen_t local_salen;
43 int ifindex;
44 uint32_t ttl;
45 bool identified;
46
47 /* only when using TCP fast open */
48 union sockaddr_union tfo_address;
49 socklen_t tfo_salen;
50
51 #if ENABLE_DNS_OVER_TLS
52 DnsTlsStreamData dnstls_data;
53 int dnstls_events;
54 #endif
55
56 sd_event_source *io_event_source;
57 sd_event_source *timeout_event_source;
58
59 be16_t write_size, read_size;
60 DnsPacket *write_packet, *read_packet;
61 size_t n_written, n_read;
62 OrderedSet *write_queue;
63
64 int (*on_packet)(DnsStream *s);
65 int (*complete)(DnsStream *s, int error);
66
67 LIST_HEAD(DnsTransaction, transactions); /* when used by the transaction logic */
68 DnsServer *server; /* when used by the transaction logic */
69 Set *queries; /* when used by the DNS stub logic */
70
71 /* used when DNS-over-TLS is enabled */
72 bool encrypted:1;
73
74 LIST_FIELDS(DnsStream, streams);
75 };
76
77 int dns_stream_new(Manager *m, DnsStream **s, DnsStreamType type, DnsProtocol protocol, int fd, const union sockaddr_union *tfo_address);
78 #if ENABLE_DNS_OVER_TLS
79 int dns_stream_connect_tls(DnsStream *s, void *tls_session);
80 #endif
81 DnsStream *dns_stream_unref(DnsStream *s);
82 DnsStream *dns_stream_ref(DnsStream *s);
83
84 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsStream*, dns_stream_unref);
85
86 int dns_stream_write_packet(DnsStream *s, DnsPacket *p);
87 ssize_t dns_stream_writev(DnsStream *s, const struct iovec *iov, size_t iovcnt, int flags);
88
89 static inline bool DNS_STREAM_QUEUED(DnsStream *s) {
90 assert(s);
91
92 if (s->fd < 0) /* already stopped? */
93 return false;
94
95 return !!s->write_packet;
96 }
97
98 DnsPacket *dns_stream_take_read_packet(DnsStream *s);
99
100 void dns_stream_detach(DnsStream *s);