Line data Source code
1 : #ifndef HEADER_fd_src_waltz_resolv_fd_adns_h 2 : #define HEADER_fd_src_waltz_resolv_fd_adns_h 3 : 4 : /* fd_adns is a non-blocking IPv4 DNS client, for resolving hostnames 5 : from a tile run loop (inside the seccomp sandbox) without ever 6 : blocking on the network. Queries for all outstanding names are in 7 : flight concurrently on a single UDP socket. 8 : 9 : Requests are queued with fd_adns_resolve and completions are polled 10 : out of fd_adns_advance, which the owner calls periodically (it only 11 : performs syscalls while requests are outstanding). Names 12 : satisfiable locally (IPv4 literals, /etc/hosts) complete on the 13 : next advance. Requires fd_netdb_open_fds to have been called 14 : (before the sandbox). */ 15 : 16 : #include "../../util/fd_util_base.h" 17 : #include "../fd_fqdn.h" 18 : 19 0 : #define FD_ADNS_MAGIC (0xF17EDA2CEADD5000) /* FIREDANCE ADNS V0 */ 20 : 21 : /* Max addresses delivered per name. */ 22 0 : #define FD_ADNS_ADDR_MAX (8UL) 23 : 24 : struct fd_adns_result { 25 : ulong req_id; /* caller's cookie from fd_adns_resolve */ 26 : int err; /* 0 on success, else FD_EAI_* (FD_EAI_AGAIN if all 27 : attempts timed out; the caller may re-queue) */ 28 : ulong addr_cnt; /* >=1 on success, 0 on error */ 29 : uint addrs[ FD_ADNS_ADDR_MAX ]; /* network byte order */ 30 : }; 31 : 32 : typedef struct fd_adns_result fd_adns_result_t; 33 : 34 : struct fd_adns_private; 35 : typedef struct fd_adns_private fd_adns_t; 36 : 37 : extern FD_TL ushort fd_adns_ns_port; 38 : 39 : FD_PROTOTYPES_BEGIN 40 : 41 : FD_FN_CONST ulong 42 : fd_adns_align( void ); 43 : 44 : FD_FN_CONST ulong 45 : fd_adns_footprint( ulong max_reqs ); 46 : 47 : void * 48 : fd_adns_new( void * shmem, 49 : ulong max_reqs, 50 : int epoll_fd ); 51 : 52 : fd_adns_t * 53 : fd_adns_join( void * shadns ); 54 : 55 : void * 56 : fd_adns_leave( fd_adns_t * adns ); 57 : 58 : /* fd_adns_delete closes the client's UDP socket (required if the 59 : owner must not carry stray fds into a sandbox). */ 60 : 61 : void * 62 : fd_adns_delete( void * shadns ); 63 : 64 : /* Queue name (cstr fitting in FD_FQDN_BUF_MAX bytes) for resolution. 65 : req_id is an opaque cookie returned with the result. Returns 0 on 66 : success, -1 if the request table is full. */ 67 : 68 : int 69 : fd_adns_resolve( fd_adns_t * adns, 70 : char const * name, 71 : ulong req_id ); 72 : 73 : /* Drive I/O forward (send due (re)tries, receive answers, expire 74 : requests that exhausted their attempts) and pop one completed 75 : request into *result. Returns 1 if a result was popped, 0 if 76 : nothing has completed. Call repeatedly until 0 to drain. */ 77 : 78 : int 79 : fd_adns_advance( fd_adns_t * adns, 80 : long now, 81 : fd_adns_result_t * result ); 82 : 83 : /* fd_adns_next_deadline returns the earliest wallclock at which a 84 : pending request (re)sends, or LONG_MAX if none is pending. */ 85 : 86 : long 87 : fd_adns_next_deadline( fd_adns_t const * adns ); 88 : 89 : FD_PROTOTYPES_END 90 : 91 : #endif /* HEADER_fd_src_waltz_resolv_fd_adns_h */