]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-stream.h
resolved: longlived TCP connections
[thirdparty/systemd.git] / src / resolve / resolved-dns-stream.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2014 Lennart Poettering
8 ***/
9
10 #include "socket-util.h"
11
12 typedef struct DnsStream DnsStream;
13
14 #include "resolved-dns-packet.h"
15 #include "resolved-dns-transaction.h"
16 #include "resolved-manager.h"
17
18 /* Streams are used by three subsystems:
19 *
20 * 1. The normal transaction logic when doing a DNS or LLMNR lookup via TCP
21 * 2. The LLMNR logic when accepting a TCP-based lookup
22 * 3. The DNS stub logic when accepting a TCP-based lookup
23 */
24
25 struct DnsStream {
26 Manager *manager;
27 int n_ref;
28
29 DnsProtocol protocol;
30
31 int fd;
32 union sockaddr_union peer;
33 socklen_t peer_salen;
34 union sockaddr_union local;
35 socklen_t local_salen;
36 int ifindex;
37 uint32_t ttl;
38 bool identified;
39
40 sd_event_source *io_event_source;
41 sd_event_source *timeout_event_source;
42
43 be16_t write_size, read_size;
44 DnsPacket *write_packet, *read_packet;
45 size_t n_written, n_read;
46 OrderedSet *write_queue;
47
48 int (*on_packet)(DnsStream *s);
49 int (*complete)(DnsStream *s, int error);
50
51 LIST_HEAD(DnsTransaction, transactions); /* when used by the transaction logic */
52 DnsServer *server; /* when used by the transaction logic */
53 DnsQuery *query; /* when used by the DNS stub logic */
54
55 LIST_FIELDS(DnsStream, streams);
56 };
57
58 int dns_stream_new(Manager *m, DnsStream **s, DnsProtocol protocol, int fd);
59 DnsStream *dns_stream_unref(DnsStream *s);
60 DnsStream *dns_stream_ref(DnsStream *s);
61
62 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsStream*, dns_stream_unref);
63
64 int dns_stream_write_packet(DnsStream *s, DnsPacket *p);
65
66 static inline bool DNS_STREAM_QUEUED(DnsStream *s) {
67 assert(s);
68
69 if (s->fd < 0) /* already stopped? */
70 return false;
71
72 return !!s->write_packet;
73 }