Line data Source code
1 : #ifndef HEADER_fd_src_waltz_resolv_fd_lookup_h
2 : #define HEADER_fd_src_waltz_resolv_fd_lookup_h
3 :
4 : #include <stdint.h>
5 : #include <stddef.h>
6 : #include <features.h>
7 : #include <netinet/in.h>
8 : #include "fd_netdb.h"
9 : #include "../fd_fqdn.h"
10 :
11 : struct aibuf {
12 : fd_addrinfo_t ai;
13 : union sa {
14 : struct sockaddr_in sin;
15 : struct sockaddr_in6 sin6;
16 : } sa;
17 : short slot, ref;
18 : };
19 :
20 : struct address {
21 : int family;
22 : uint scopeid;
23 : uchar addr[16];
24 : int sortkey;
25 : };
26 :
27 18 : #define MAXNS 3
28 :
29 : struct fd_resolvconf {
30 : struct address ns[MAXNS];
31 : uint nns, attempts, ndots;
32 : uint timeout;
33 : };
34 :
35 : typedef struct fd_resolvconf fd_resolvconf_t;
36 :
37 : /* The limit of 48 results is a non-sharp bound on the number of addresses
38 : * that can fit in one 512-byte DNS packet full of v4 results and a second
39 : * packet full of v6 results. Due to headers, the actual limit is lower. */
40 72 : #define MAXADDRS 48
41 :
42 : __attribute__((__visibility__("hidden"))) int
43 : fd_lookup_name( struct address buf[ static MAXADDRS ],
44 : char canon[ static FD_FQDN_BUF_MAX ],
45 : const char * name,
46 : int family,
47 : int flags );
48 :
49 : __attribute__((__visibility__("hidden"))) int
50 : fd_lookup_ipliteral( struct address buf[ static 1 ],
51 : const char * name,
52 : int family );
53 :
54 : __attribute__((__visibility__("hidden"))) int
55 : fd_get_resolv_conf( fd_resolvconf_t * );
56 :
57 : __attribute__((__visibility__("hidden"))) int
58 : fd_res_msend_rc( int,
59 : uchar const * const *,
60 : int const *,
61 : uchar * const *,
62 : int *,
63 : int,
64 : fd_resolvconf_t const * );
65 :
66 : __attribute__((__visibility__("hidden"))) int
67 : fd_dns_parse( uchar const *,
68 : int,
69 : int (*)( void *,
70 : int,
71 : void const *,
72 : int,
73 : void const *,
74 : int ),
75 : void * );
76 :
77 : /* Firedancer extension: non-blocking IPv4 resolution primitives, used
78 : by fd_adns. See fd_lookup_name.c. */
79 :
80 18 : #define FD_DNS_QUERY_MTU (280)
81 :
82 : /* fd_dns_ip4_local resolves name without network I/O (IPv4 literal or
83 : /etc/hosts). Writes up to addr_max addresses (network byte order)
84 : to addrs. Returns the count (>0), 0 if the name needs DNS, or an
85 : FD_EAI_* error. */
86 :
87 : __attribute__((__visibility__("hidden"))) int
88 : fd_dns_ip4_local( char const * name,
89 : uint * addrs,
90 : ulong addr_max );
91 :
92 : /* fd_dns_ip4_query builds an A-record query packet for name. Returns
93 : the packet length, or FD_EAI_NONAME on a malformed name. Bytes 0-1
94 : of the packet are the (randomized) query id; answers echo it. */
95 :
96 : __attribute__((__visibility__("hidden"))) int
97 : fd_dns_ip4_query( char const * name,
98 : uchar query[ static FD_DNS_QUERY_MTU ] );
99 :
100 : /* fd_dns_ip4_answer parses a DNS answer packet. Writes up to addr_max
101 : A records (network byte order) to addrs and returns the count, or an
102 : FD_EAI_* error (FD_EAI_AGAIN on SERVFAIL/short packet). */
103 :
104 : __attribute__((__visibility__("hidden"))) int
105 : fd_dns_ip4_answer( uchar const * answer,
106 : ulong answer_sz,
107 : uint * addrs,
108 : ulong addr_max );
109 :
110 : /* fd_dns_nameservers loads the configured IPv4 nameservers from
111 : /etc/resolv.conf (falling back to 127.0.0.1). Returns the count
112 : written to addrs (network byte order), or FD_EAI_SYSTEM. If
113 : opt_timeout/opt_attempts are non-NULL they receive the resolv.conf
114 : options (or their defaults). */
115 :
116 : __attribute__((__visibility__("hidden"))) int
117 : fd_dns_nameservers( uint * addrs,
118 : ulong addr_max,
119 : uint * opt_timeout,
120 : uint * opt_attempts );
121 :
122 : /* Firedancer extension: pre-opened file descriptors */
123 :
124 : extern FD_TL int fd_etc_hosts_fd;
125 : extern FD_TL int fd_etc_resolv_conf_fd;
126 :
127 : #endif /* HEADER_fd_src_waltz_resolv_fd_lookup_h */
|