]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-stream.h
Merge pull request #8676 from keszybz/drop-license-boilerplate
[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
47 int (*on_packet)(DnsStream *s);
48 int (*complete)(DnsStream *s, int error);
49
50 DnsTransaction *transaction; /* when used by the transaction logic */
51 DnsQuery *query; /* when used by the DNS stub logic */
52
53 LIST_FIELDS(DnsStream, streams);
54 };
55
56 int dns_stream_new(Manager *m, DnsStream **s, DnsProtocol protocol, int fd);
57 DnsStream *dns_stream_unref(DnsStream *s);
58 DnsStream *dns_stream_ref(DnsStream *s);
59
60 int dns_stream_write_packet(DnsStream *s, DnsPacket *p);
61
62 static inline bool DNS_STREAM_QUEUED(DnsStream *s) {
63 assert(s);
64
65 if (s->fd < 0) /* already stopped? */
66 return false;
67
68 return !!s->write_packet;
69 }