* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
#include <lwres/context.h>
#include <lwres/lwpacket.h>
#include <lwres/platform.h>
/*! \file lwres/lwres.h */
* Each opcode has two structures and three functions which operate on each
* structure. For example, using the "no operation/ping" opcode as an
* <ul><li>lwres_nooprequest_t:
* lwres_nooprequest_render() takes a lwres_nooprequest_t and
* and renders it into wire format, storing the allocated
* buffer information in a passed-in buffer. When this buffer
* is no longer needed, it must be freed by
* lwres_context_freemem(). All other memory used by the
* caller must be freed manually, including the
* lwres_nooprequest_t passed in.<br /><br />
* lwres_nooprequest_parse() takes a wire format message and
* breaks it out into a lwres_nooprequest_t. The structure
* must be freed via lwres_nooprequest_free() when it is no longer
* lwres_nooprequest_free() releases into the lwres_context_t
* any space allocated during parsing.</li>
* <li>lwres_noopresponse_t:
* The functions used are similar to the three used for
* requests, just with different names.</li></ul>
* Typically, the client will use request_render, response_parse, and
* response_free, while the daemon will use request_parse, response_render,
* The basic flow of a typical client is:
* \li fill in a request_t, and call the render function.
* \li Transmit the buffer returned to the daemon.
* \li Wait for a response.
* \li When a response is received, parse it into a response_t.
* \li free the request buffer using lwres_context_freemem().
* \li free the response structure and its associated buffer using
#define LWRES_UDP_PORT 921 /*%< UDP Port Number */
#define LWRES_RECVLENGTH 16384 /*%< Maximum Packet Length */
#define LWRES_ADDR_MAXLEN 16 /*%< changing this breaks ABI */
#define LWRES_RESOLV_CONF "/etc/resolv.conf" /*%< Location of resolv.conf */
/*% DNSSEC is not required (input). Only relevant to rrset queries. */
#define LWRES_FLAG_TRUSTNOTREQUIRED 0x00000001U
/*% The data was crypto-verified with DNSSEC (output). */
#define LWRES_FLAG_SECUREDATA 0x00000002U
#define LWRES_OPCODE_NOOP 0x00000000U
/*% lwres_nooprequest_t */
/*% lwres_noopresponse_t */
/*% get addresses by name */
#define LWRES_OPCODE_GETADDRSBYNAME 0x00010001U
typedef struct lwres_addr lwres_addr_t;
typedef LWRES_LIST(lwres_addr_t) lwres_addrlist_t;
unsigned char address[LWRES_ADDR_MAXLEN];
LWRES_LINK(lwres_addr_t) link;
/*% lwres_gabnrequest_t */
/*% lwres_gabnresponse_t */
/*! if base != NULL, it will be freed when this structure is freed. */
/*% get name by address */
#define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
/*% lwres_gnbarequest_t */
/*% lwres_gnbaresponse_t */
/*! if base != NULL, it will be freed when this structure is freed. */
#define LWRES_OPCODE_GETRDATABYNAME 0x00010003U
/*% lwres_grbnrequest_t */
/*% lwres_grbnresponse_t */
/*% if base != NULL, it will be freed when this structure is freed. */
/*% Used by lwres_getrrsetbyname() */
#define LWRDATA_VALIDATED 0x00000001
#define LWRES_CONFMAXNAMESERVERS 3 /*%< max 3 "nameserver" entries */
#define LWRES_CONFMAXLWSERVERS 1 /*%< max 1 "lwserver" entry */
#define LWRES_CONFMAXSEARCH 8 /*%< max 8 domains in "search" entry */
#define LWRES_CONFMAXLINELEN 256 /*%< max size of a line */
#define LWRES_CONFMAXSORTLIST 10 /*%< max 10 */
lwres_addr_t nameservers[LWRES_CONFMAXNAMESERVERS];
uint8_t nsnext; /*%< index for next free slot */
lwres_addr_t lwservers[LWRES_CONFMAXLWSERVERS];
uint8_t lwnext; /*%< index for next free slot */
char *search[LWRES_CONFMAXSEARCH];
uint8_t searchnxt; /*%< index for next free slot */
/*% mask has a non-zero 'family' and 'length' if set */
} sortlist[LWRES_CONFMAXSORTLIST];
uint8_t resdebug; /*%< non-zero if 'options debug' set */
uint8_t ndots; /*%< set to n in 'options ndots:n' */
uint8_t no_tld_query; /*%< non-zero if 'options no_tld_query' */
int32_t attempts; /*%< set to n in 'options attempts:n' */
int32_t timeout; /*%< set to n in 'options timeout:n' */
#define LWRES_ADDRTYPE_V4 0x00000001U /*%< ipv4 */
#define LWRES_ADDRTYPE_V6 0x00000002U /*%< ipv6 */
#define LWRES_MAX_ALIASES 16 /*%< max # of aliases */
#define LWRES_MAX_ADDRS 64 /*%< max # of addrs */
/*% This is in host byte order. */
LIBLWRES_EXTERNAL_DATA extern uint16_t lwres_udp_port;
LIBLWRES_EXTERNAL_DATA extern const char *lwres_resolv_conf;
lwres_gabnrequest_render(lwres_context_t *ctx, lwres_gabnrequest_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
lwres_gabnrequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_lwpacket_t *pkt, lwres_gabnrequest_t **structp);
lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_gabnresponse_t **structp);
lwres_gabnrequest_free(lwres_context_t *ctx, lwres_gabnrequest_t **structp);
* Frees any dynamically allocated memory for this structure.
* ctx != NULL, and be a context returned via lwres_context_create().
* structp != NULL && *structp != NULL.
* All memory allocated by this structure will be returned to the
* system via the context's free function.
lwres_gabnresponse_free(lwres_context_t *ctx, lwres_gabnresponse_t **structp);
* Frees any dynamically allocated memory for this structure.
* ctx != NULL, and be a context returned via lwres_context_create().
* structp != NULL && *structp != NULL.
* All memory allocated by this structure will be returned to the
* system via the context's free function.
lwres_gnbarequest_render(lwres_context_t *ctx, lwres_gnbarequest_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
lwres_gnbaresponse_render(lwres_context_t *ctx, lwres_gnbaresponse_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
lwres_gnbarequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_lwpacket_t *pkt, lwres_gnbarequest_t **structp);
lwres_gnbaresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_gnbaresponse_t **structp);
lwres_gnbarequest_free(lwres_context_t *ctx, lwres_gnbarequest_t **structp);
* Frees any dynamically allocated memory for this structure.
* ctx != NULL, and be a context returned via lwres_context_create().
* structp != NULL && *structp != NULL.
* All memory allocated by this structure will be returned to the
* system via the context's free function.
lwres_gnbaresponse_free(lwres_context_t *ctx, lwres_gnbaresponse_t **structp);
* Frees any dynamically allocated memory for this structure.
* ctx != NULL, and be a context returned via lwres_context_create().
* structp != NULL && *structp != NULL.
* All memory allocated by this structure will be returned to the
* system via the context's free function.
lwres_grbnrequest_render(lwres_context_t *ctx, lwres_grbnrequest_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
lwres_grbnresponse_render(lwres_context_t *ctx, lwres_grbnresponse_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
lwres_grbnrequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_lwpacket_t *pkt, lwres_grbnrequest_t **structp);
lwres_grbnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_grbnresponse_t **structp);
lwres_grbnrequest_free(lwres_context_t *ctx, lwres_grbnrequest_t **structp);
* Frees any dynamically allocated memory for this structure.
* ctx != NULL, and be a context returned via lwres_context_create().
* structp != NULL && *structp != NULL.
* All memory allocated by this structure will be returned to the
* system via the context's free function.
lwres_grbnresponse_free(lwres_context_t *ctx, lwres_grbnresponse_t **structp);
* Frees any dynamically allocated memory for this structure.
* ctx != NULL, and be a context returned via lwres_context_create().
* structp != NULL && *structp != NULL.
* All memory allocated by this structure will be returned to the
* system via the context's free function.
lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
* Allocate space and render into wire format a noop request packet.
* ctx != NULL, and be a context returned via lwres_context_create().
* b != NULL, and points to a lwres_buffer_t. The contents of the
* buffer structure will be initialized to contain the wire-format
* Caller needs to fill in parts of "pkt" before calling:
* serial, maxrecv, result.
* Returns 0 on success, non-zero on failure.
* On successful return, *b will contain data about the wire-format
* packet. It can be transmitted in any way, including lwres_sendblock().
lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req,
lwres_lwpacket_t *pkt, lwres_buffer_t *b);
lwres_nooprequest_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_lwpacket_t *pkt, lwres_nooprequest_t **structp);
* Parse a noop request. Note that to get here, the lwpacket must have
* already been parsed and removed by the caller, otherwise it would be
* pretty hard for it to know this is the right function to call.
* The function verifies bits of the header, but does not modify it.
lwres_noopresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
lwres_noopresponse_t **structp);
lwres_nooprequest_free(lwres_context_t *ctx, lwres_nooprequest_t **structp);
lwres_noopresponse_free(lwres_context_t *ctx, lwres_noopresponse_t **structp);
* Frees any dynamically allocated memory for this structure.
* ctx != NULL, and be a context returned via lwres_context_create().
* structp != NULL && *structp != NULL.
* All memory allocated by this structure will be returned to the
* system via the context's free function.
lwres_conf_parse(lwres_context_t *ctx, const char *filename);
* parses a resolv.conf-format file and stores the results in the structure
* filename != NULL && strlen(filename) > 0