LCOV - code coverage report
Current view: top level - waltz/resolv - fd_adns.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 2 2 100.0 %
Date: 2026-08-20 04:31:44 Functions: 0 0 -

          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             : 
      18          12 : #define FD_ADNS_MAGIC (0xF17EDA2CEADD5000) /* FIREDANCE ADNS V0 */
      19             : 
      20             : /* Max addresses delivered per name. */
      21          30 : #define FD_ADNS_ADDR_MAX (8UL)
      22             : 
      23             : struct fd_adns_result {
      24             :   ulong req_id;   /* caller's cookie from fd_adns_resolve */
      25             :   int   err;      /* 0 on success, else FD_EAI_* (FD_EAI_AGAIN if all
      26             :                      attempts timed out; the caller may re-queue) */
      27             :   ulong addr_cnt; /* >=1 on success, 0 on error */
      28             :   uint  addrs[ FD_ADNS_ADDR_MAX ]; /* network byte order */
      29             : };
      30             : 
      31             : typedef struct fd_adns_result fd_adns_result_t;
      32             : 
      33             : struct fd_adns_private;
      34             : typedef struct fd_adns_private fd_adns_t;
      35             : 
      36             : extern FD_TL ushort fd_adns_ns_port;
      37             : 
      38             : FD_PROTOTYPES_BEGIN
      39             : 
      40             : FD_FN_CONST ulong
      41             : fd_adns_align( void );
      42             : 
      43             : FD_FN_CONST ulong
      44             : fd_adns_footprint( ulong max_reqs );
      45             : 
      46             : void *
      47             : fd_adns_new( void * shmem,
      48             :              ulong  max_reqs );
      49             : 
      50             : fd_adns_t *
      51             : fd_adns_join( void * shadns );
      52             : 
      53             : void *
      54             : fd_adns_leave( fd_adns_t * adns );
      55             : 
      56             : /* fd_adns_delete closes the client's UDP socket (required if the
      57             :    owner must not carry stray fds into a sandbox). */
      58             : 
      59             : void *
      60             : fd_adns_delete( void * shadns );
      61             : 
      62             : /* Queue name (cstr, <=255 chars) for resolution.  req_id is an opaque
      63             :    cookie returned with the result.  Returns 0 on success, -1 if the
      64             :    request table is full. */
      65             : 
      66             : int
      67             : fd_adns_resolve( fd_adns_t *  adns,
      68             :                  char const * name,
      69             :                  ulong        req_id );
      70             : 
      71             : /* Drive I/O forward (send due (re)tries, receive answers, expire
      72             :    requests that exhausted their attempts) and pop one completed
      73             :    request into *result.  Returns 1 if a result was popped, 0 if
      74             :    nothing has completed.  Call repeatedly until 0 to drain. */
      75             : 
      76             : int
      77             : fd_adns_advance( fd_adns_t *        adns,
      78             :                  long               now,
      79             :                  fd_adns_result_t * result );
      80             : 
      81             : FD_PROTOTYPES_END
      82             : 
      83             : #endif /* HEADER_fd_src_waltz_resolv_fd_adns_h */

Generated by: LCOV version 1.14