]>
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 | |
623a4c97 LP |
8 | ***/ |
9 | ||
10 | #include "socket-util.h" | |
11 | ||
12 | typedef struct DnsStream DnsStream; | |
13 | ||
ec2c5e43 LP |
14 | #include "resolved-dns-packet.h" |
15 | #include "resolved-dns-transaction.h" | |
07f264e4 | 16 | #include "resolved-manager.h" |
623a4c97 | 17 | |
b30bf55d LP |
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 | ||
623a4c97 LP |
25 | struct DnsStream { |
26 | Manager *manager; | |
b30bf55d | 27 | int n_ref; |
623a4c97 LP |
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; | |
b914e211 | 38 | bool identified; |
623a4c97 | 39 | |
91ccab1e IT |
40 | /* only when using TCP fast open */ |
41 | union sockaddr_union tfo_address; | |
42 | socklen_t tfo_salen; | |
43 | ||
623a4c97 LP |
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; | |
98767d75 | 50 | OrderedSet *write_queue; |
623a4c97 LP |
51 | |
52 | int (*on_packet)(DnsStream *s); | |
53 | int (*complete)(DnsStream *s, int error); | |
54 | ||
98767d75 IT |
55 | LIST_HEAD(DnsTransaction, transactions); /* when used by the transaction logic */ |
56 | DnsServer *server; /* when used by the transaction logic */ | |
b30bf55d | 57 | DnsQuery *query; /* when used by the DNS stub logic */ |
623a4c97 LP |
58 | |
59 | LIST_FIELDS(DnsStream, streams); | |
60 | }; | |
61 | ||
91ccab1e | 62 | int dns_stream_new(Manager *m, DnsStream **s, DnsProtocol protocol, int fd, const union sockaddr_union *tfo_address); |
b30bf55d LP |
63 | DnsStream *dns_stream_unref(DnsStream *s); |
64 | DnsStream *dns_stream_ref(DnsStream *s); | |
623a4c97 | 65 | |
98767d75 IT |
66 | DEFINE_TRIVIAL_CLEANUP_FUNC(DnsStream*, dns_stream_unref); |
67 | ||
623a4c97 | 68 | int dns_stream_write_packet(DnsStream *s, DnsPacket *p); |
b30bf55d LP |
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 | } |