]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-stream.h
resolved: TCP fast open 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 /* only when using TCP fast open */
41 union sockaddr_union tfo_address;
42 socklen_t tfo_salen;
43
44 sd_event_source *io_event_source;
45 sd_event_source *timeout_event_source;
46
47 be16_t write_size, read_size;
48 DnsPacket *write_packet, *read_packet;
49 size_t n_written, n_read;
50 OrderedSet *write_queue;
51
52 int (*on_packet)(DnsStream *s);
53 int (*complete)(DnsStream *s, int error);
54
55 LIST_HEAD(DnsTransaction, transactions); /* when used by the transaction logic */
56 DnsServer *server; /* when used by the transaction logic */
57 DnsQuery *query; /* when used by the DNS stub logic */
58
59 LIST_FIELDS(DnsStream, streams);
60 };
61
62 int dns_stream_new(Manager *m, DnsStream **s, DnsProtocol protocol, int fd, const union sockaddr_union *tfo_address);
63 DnsStream *dns_stream_unref(DnsStream *s);
64 DnsStream *dns_stream_ref(DnsStream *s);
65
66 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsStream*, dns_stream_unref);
67
68 int dns_stream_write_packet(DnsStream *s, DnsPacket *p);
69
70 static inline bool DNS_STREAM_QUEUED(DnsStream *s) {
71 assert(s);
72
73 if (s->fd < 0) /* already stopped? */
74 return false;
75
76 return !!s->write_packet;
77 }