1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include "hash-funcs.h"
5 
6 typedef struct DnsStubListenerExtra DnsStubListenerExtra;
7 
8 typedef enum DnsStubListenerMode {
9         DNS_STUB_LISTENER_NO,
10         DNS_STUB_LISTENER_UDP = 1 << 0,
11         DNS_STUB_LISTENER_TCP = 1 << 1,
12         DNS_STUB_LISTENER_YES = DNS_STUB_LISTENER_UDP | DNS_STUB_LISTENER_TCP,
13         _DNS_STUB_LISTENER_MODE_MAX,
14         _DNS_STUB_LISTENER_MODE_INVALID = -EINVAL,
15 } DnsStubListenerMode;
16 
17 #include "resolved-manager.h"
18 
19 struct DnsStubListenerExtra {
20         Manager *manager;
21 
22         DnsStubListenerMode mode;
23 
24         int family;
25         union in_addr_union address;
26         uint16_t port;
27 
28         sd_event_source *udp_event_source;
29         sd_event_source *tcp_event_source;
30 
31         Hashmap *queries_by_packet;
32 };
33 
34 extern const struct hash_ops dns_stub_listener_extra_hash_ops;
35 
36 int dns_stub_listener_extra_new(Manager *m, DnsStubListenerExtra **ret);
37 DnsStubListenerExtra *dns_stub_listener_extra_free(DnsStubListenerExtra *p);
dns_stub_listener_extra_port(DnsStubListenerExtra * p)38 static inline uint16_t dns_stub_listener_extra_port(DnsStubListenerExtra *p) {
39         assert(p);
40 
41         return p->port > 0 ? p->port : 53;
42 }
43 
44 void manager_dns_stub_stop(Manager *m);
45 int manager_dns_stub_start(Manager *m);
46 
47 const char* dns_stub_listener_mode_to_string(DnsStubListenerMode p) _const_;
48 DnsStubListenerMode dns_stub_listener_mode_from_string(const char *s) _pure_;
49