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