]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-stream.h
resolved: respond to local resolver requests on 127.0.0.53:53
[thirdparty/systemd.git] / src / resolve / resolved-dns-stream.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2014 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "socket-util.h"
23
24 typedef struct DnsStream DnsStream;
25
26 #include "resolved-dns-packet.h"
27 #include "resolved-dns-transaction.h"
28
29 /* Streams are used by three subsystems:
30 *
31 * 1. The normal transaction logic when doing a DNS or LLMNR lookup via TCP
32 * 2. The LLMNR logic when accepting a TCP-based lookup
33 * 3. The DNS stub logic when accepting a TCP-based lookup
34 */
35
36 struct DnsStream {
37 Manager *manager;
38 int n_ref;
39
40 DnsProtocol protocol;
41
42 int fd;
43 union sockaddr_union peer;
44 socklen_t peer_salen;
45 union sockaddr_union local;
46 socklen_t local_salen;
47 int ifindex;
48 uint32_t ttl;
49 bool identified;
50
51 sd_event_source *io_event_source;
52 sd_event_source *timeout_event_source;
53
54 be16_t write_size, read_size;
55 DnsPacket *write_packet, *read_packet;
56 size_t n_written, n_read;
57
58 int (*on_packet)(DnsStream *s);
59 int (*complete)(DnsStream *s, int error);
60
61 DnsTransaction *transaction; /* when used by the transaction logic */
62 DnsQuery *query; /* when used by the DNS stub logic */
63
64 LIST_FIELDS(DnsStream, streams);
65 };
66
67 int dns_stream_new(Manager *m, DnsStream **s, DnsProtocol protocol, int fd);
68 DnsStream *dns_stream_unref(DnsStream *s);
69 DnsStream *dns_stream_ref(DnsStream *s);
70
71 int dns_stream_write_packet(DnsStream *s, DnsPacket *p);
72
73 static inline bool DNS_STREAM_QUEUED(DnsStream *s) {
74 assert(s);
75
76 if (s->fd < 0) /* already stopped? */
77 return false;
78
79 return !!s->write_packet;
80 }