edns.c File Reference

This file contains functions for base EDNS options. More...

#include "config.h"
#include "util/edns.h"
#include "util/config_file.h"
#include "util/netevent.h"
#include "util/net_help.h"
#include "util/regional.h"
#include "util/rfc_1982.h"
#include "util/siphash.h"
#include "util/data/msgparse.h"
#include "util/data/msgreply.h"
#include "sldns/sbuffer.h"

Functions

struct edns_stringsedns_strings_create (void)
 Create structure to hold EDNS strings. More...
 
void edns_strings_delete (struct edns_strings *edns_strings)
 Delete EDNS strings structure. More...
 
static int edns_strings_client_insert (struct edns_strings *edns_strings, struct sockaddr_storage *addr, socklen_t addrlen, int net, const char *string)
 
int edns_strings_apply_cfg (struct edns_strings *edns_strings, struct config_file *config)
 Add configured EDNS strings. More...
 
struct edns_string_addredns_string_addr_lookup (rbtree_type *tree, struct sockaddr_storage *addr, socklen_t addrlen)
 Find string for address. More...
 
uint8_t * edns_cookie_server_hash (const uint8_t *in, const uint8_t *secret, int v4, uint8_t *hash)
 Compute the interoperable DNS cookie (RFC9018) hash. More...
 
void edns_cookie_server_write (uint8_t *buf, const uint8_t *secret, int v4, uint32_t timestamp)
 Write an interoperable DNS server cookie (RFC9018). More...
 
enum edns_cookie_val_status edns_cookie_server_validate (const uint8_t *cookie, size_t cookie_len, const uint8_t *secret, size_t secret_len, int v4, const uint8_t *hash_input, uint32_t now)
 Validate an interoperable DNS cookie (RFC9018). More...
 

Detailed Description

This file contains functions for base EDNS options.

Function Documentation

◆ edns_strings_create()

struct edns_strings* edns_strings_create ( void  )

Create structure to hold EDNS strings.

Returns
: newly created edns_strings, NULL on alloc failure.

References edns_strings_delete(), edns_strings::region, and regional_create().

Referenced by ub_ctx_create_nopipe().

◆ edns_strings_delete()

void edns_strings_delete ( struct edns_strings edns_strings)

Delete EDNS strings structure.

Parameters
edns_stringsstruct to delete

References edns_strings::region, and regional_destroy().

Referenced by daemon_delete(), edns_strings_create(), and ub_ctx_create().

◆ edns_strings_apply_cfg()

int edns_strings_apply_cfg ( struct edns_strings edns_strings,
struct config_file config 
)

Add configured EDNS strings.

Parameters
edns_stringsedns strings to apply config to
configstruct containing EDNS strings configuration
Returns
0 on error

References addr_tree_init(), edns_strings::client_strings, config_file::edns_client_strings, log_assert, log_err(), netblockstrtoaddr(), config_str2list::next, edns_strings::region, regional_free_all(), config_str2list::str, and config_str2list::str2.

Referenced by context_finalize().

◆ edns_string_addr_lookup()

struct edns_string_addr* edns_string_addr_lookup ( rbtree_type tree,
struct sockaddr_storage *  addr,
socklen_t  addrlen 
)

Find string for address.

Parameters
treetree containing EDNS strings per address prefix.
addraddress to use for tree lookup
addrlenlength of address
Returns
: matching tree node, NULL otherwise

References addr_tree_lookup().

Referenced by outnet_serviced_query().

◆ edns_cookie_server_hash()

uint8_t* edns_cookie_server_hash ( const uint8_t *  in,
const uint8_t *  secret,
int  v4,
uint8_t *  hash 
)

Compute the interoperable DNS cookie (RFC9018) hash.

Parameters
inbuffer input for the hash generation. It needs to be: Client Cookie | Version | Reserved | Timestamp | Client-IP
secretthe server secret; implicit length of 16 octets.
v4if the client IP is v4 or v6.
hashbuffer to write the hash to. return a pointer to the hash.

References siphash().

◆ edns_cookie_server_write()

void edns_cookie_server_write ( uint8_t *  buf,
const uint8_t *  secret,
int  v4,
uint32_t  timestamp 
)

Write an interoperable DNS server cookie (RFC9018).

Parameters
bufbuffer to write to. It should have a size of at least 32 octets as it doubles as the output buffer and the hash input buffer. The first 8 octets are expected to be the Client Cookie and will be left untouched. The next 8 octets will be written with Version | Reserved | Timestamp. The next 4 or 16 octets are expected to be the IPv4 or the IPv6 address based on the v4 flag. Thus the first 20 or 32 octets, based on the v4 flag, will be used as the hash input. The server hash (8 octets) will be written after the first 16 octets; overwriting the address information. The caller expects a complete, 24 octet long cookie in the buffer.
secretthe server secret; implicit length of 16 octets.
v4if the client IP is v4 or v6.
timestampthe timestamp to use.

◆ edns_cookie_server_validate()

enum edns_cookie_val_status edns_cookie_server_validate ( const uint8_t *  cookie,
size_t  cookie_len,
const uint8_t *  secret,
size_t  secret_len,
int  v4,
const uint8_t *  hash_input,
uint32_t  now 
)

Validate an interoperable DNS cookie (RFC9018).

Parameters
cookiepointer to the cookie data.
cookie_lenthe length of the cookie data.
secretpointer to the server secret.
secret_lenthe length of the secret.
v4if the client IP is v4 or v6.
hash_inputpointer to the hash input for validation. It needs to be: Client Cookie | Version | Reserved | Timestamp | Client-IP
nowthe current time. return edns_cookie_val_status with the cookie validation status i.e., <=0 for invalid, else valid.