iPXE
Data Structures | Macros | Functions | Variables
dns.c File Reference

DNS protocol. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/refcnt.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/resolv.h>
#include <ipxe/retry.h>
#include <ipxe/tcpip.h>
#include <ipxe/settings.h>
#include <ipxe/features.h>
#include <ipxe/job.h>
#include <ipxe/dhcp.h>
#include <ipxe/dhcpv6.h>
#include <ipxe/dns.h>

Go to the source code of this file.

Data Structures

struct  dns_server
 A DNS server list. More...
 
struct  dns_request
 A DNS request. More...
 

Macros

#define ENXIO_NO_RECORD   __einfo_error ( EINFO_ENXIO_NO_RECORD )
 
#define EINFO_ENXIO_NO_RECORD   __einfo_uniqify ( EINFO_ENXIO, 0x01, "DNS name does not exist" )
 
#define ENXIO_NO_NAMESERVER   __einfo_error ( EINFO_ENXIO_NO_NAMESERVER )
 
#define EINFO_ENXIO_NO_NAMESERVER   __einfo_uniqify ( EINFO_ENXIO, 0x02, "No DNS servers available" )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FEATURE (FEATURE_PROTOCOL, "DNS", DHCP_EB_FEATURE_DNS, 1)
 
int dns_encode (const char *string, struct dns_name *name)
 Encode a DNS name using RFC1035 encoding. More...
 
static int dns_label (struct dns_name *name, size_t offset)
 Find start of valid label within an RFC1035-encoded DNS name. More...
 
int dns_decode (struct dns_name *name, char *data, size_t len)
 Decode RFC1035-encoded DNS name. More...
 
int dns_compare (struct dns_name *first, struct dns_name *second)
 Compare DNS names for equality. More...
 
int dns_copy (struct dns_name *src, struct dns_name *dst)
 Copy a DNS name. More...
 
int dns_skip (struct dns_name *name)
 Skip RFC1035-encoded DNS name. More...
 
static int dns_skip_search (struct dns_name *name)
 Skip RFC1035-encoded DNS name in search list. More...
 
static const char * dns_name (struct dns_name *name)
 Transcribe DNS name (for debugging) More...
 
static const char * dns_type (uint16_t type)
 Name a DNS query type (for debugging) More...
 
static void dns_done (struct dns_request *dns, int rc)
 Mark DNS request as complete. More...
 
static void dns_resolved (struct dns_request *dns)
 Mark DNS request as resolved and complete. More...
 
static int dns_question (struct dns_request *dns)
 Construct DNS question. More...
 
static int dns_send_packet (struct dns_request *dns)
 Send DNS query. More...
 
static void dns_timer_expired (struct retry_timer *timer, int fail)
 Handle DNS (re)transmission timer expiry. More...
 
static int dns_xfer_deliver (struct dns_request *dns, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Receive new data. More...
 
static void dns_xfer_close (struct dns_request *dns, int rc)
 Receive new data. More...
 
static int dns_progress (struct dns_request *dns, struct job_progress *progress)
 Report job progress. More...
 
static int dns_resolv (struct interface *resolv, const char *name, struct sockaddr *sa)
 Resolve name using DNS. More...
 
struct resolver dns_resolver __resolver (RESOLV_NORMAL)
 DNS name resolver. More...
 
static int format_dnssl_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format DNS search list setting. More...
 
const struct setting dns_setting __setting (SETTING_IP4_EXTRA, dns)
 IPv4 DNS server setting. More...
 
const struct setting dns6_setting __setting (SETTING_IP6_EXTRA, dns6)
 IPv6 DNS server setting. More...
 
const struct setting dnssl_setting __setting (SETTING_IP_EXTRA, dnssl)
 DNS search list. More...
 
static void apply_dns_servers (void)
 Apply DNS server addresses. More...
 
static void apply_dns_search (void)
 Apply DNS search list. More...
 
static int apply_dns_settings (void)
 Apply DNS settings. More...
 

Variables

static struct dns_server dns4
 IPv4 DNS server list. More...
 
static struct dns_server dns6
 IPv6 DNS server list. More...
 
static unsigned int dns_count
 Total number of DNS servers. More...
 
static unsigned int dns_index
 Current DNS server index. More...
 
static struct dns_name dns_search
 The DNS search list. More...
 
static struct interface_operation dns_socket_operations []
 DNS socket interface operations. More...
 
static struct interface_descriptor dns_socket_desc
 DNS socket interface descriptor. More...
 
static struct interface_operation dns_resolv_op []
 DNS resolver interface operations. More...
 
static struct interface_descriptor dns_resolv_desc
 DNS resolver interface descriptor. More...
 
const struct setting_type setting_type_dnssl __setting_type
 A DNS search list setting type. More...
 
struct settings_applicator dns_applicator __settings_applicator
 DNS settings applicator. More...
 

Detailed Description

DNS protocol.

Definition in file dns.c.

Macro Definition Documentation

◆ ENXIO_NO_RECORD

#define ENXIO_NO_RECORD   __einfo_error ( EINFO_ENXIO_NO_RECORD )

Definition at line 59 of file dns.c.

◆ EINFO_ENXIO_NO_RECORD

#define EINFO_ENXIO_NO_RECORD   __einfo_uniqify ( EINFO_ENXIO, 0x01, "DNS name does not exist" )

Definition at line 60 of file dns.c.

◆ ENXIO_NO_NAMESERVER

#define ENXIO_NO_NAMESERVER   __einfo_error ( EINFO_ENXIO_NO_NAMESERVER )

Definition at line 62 of file dns.c.

◆ EINFO_ENXIO_NO_NAMESERVER

#define EINFO_ENXIO_NO_NAMESERVER   __einfo_uniqify ( EINFO_ENXIO, 0x02, "No DNS servers available" )

Definition at line 63 of file dns.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FEATURE()

FEATURE ( FEATURE_PROTOCOL  ,
"DNS"  ,
DHCP_EB_FEATURE_DNS  ,
 
)

◆ dns_encode()

int dns_encode ( const char *  string,
struct dns_name name 
)

Encode a DNS name using RFC1035 encoding.

Parameters
stringDNS name as a string
nameDNS name to fill in
Return values
lenLength of DNS name, or negative error

Definition at line 103 of file dns.c.

103  {
104  uint8_t *start = ( name->data + name->offset );
105  uint8_t *end = ( name->data + name->len );
106  uint8_t *dst = start;
107  size_t len = 0;
108  char c;
109 
110  /* Encode name */
111  while ( ( c = *(string++) ) ) {
112 
113  /* Handle '.' separators */
114  if ( c == '.' ) {
115 
116  /* Reject consecutive '.' */
117  if ( ( len == 0 ) && ( dst != start ) )
118  return -EINVAL;
119 
120  /* Terminate if this is the trailing '.' */
121  if ( *string == '\0' )
122  break;
123 
124  /* Reject initial non-terminating '.' */
125  if ( len == 0 )
126  return -EINVAL;
127 
128  /* Reset length */
129  len = 0;
130 
131  } else {
132 
133  /* Increment length */
134  len++;
135 
136  /* Check for overflow */
137  if ( len > DNS_MAX_LABEL_LEN )
138  return -EINVAL;
139  }
140 
141  /* Copy byte, update length */
142  if ( ++dst < end ) {
143  *dst = c;
144  dst[-len] = len;
145  }
146  }
147 
148  /* Add terminating root marker */
149  if ( len )
150  dst++;
151  if ( dst < end )
152  *dst = '\0';
153  dst++;
154 
155  return ( dst - start );
156 }
uint32_t c
Definition: md4.c:30
#define EINVAL
Invalid argument.
Definition: errno.h:428
const char * name
Definition: ath9k_hw.c:1984
#define DNS_MAX_LABEL_LEN
Maximum length of a single DNS label.
Definition: dns.h:53
uint32_t start
Starting offset.
Definition: netvsc.h:12
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
uint32_t end
Ending offset.
Definition: netvsc.h:18

References c, DNS_MAX_LABEL_LEN, EINVAL, end, len, name, and start.

Referenced by apply_dns_search(), dns_encode_fail_okx(), dns_encode_okx(), and dns_resolv().

◆ dns_label()

static int dns_label ( struct dns_name name,
size_t  offset 
)
static

Find start of valid label within an RFC1035-encoded DNS name.

Parameters
nameDNS name
offsetCurrent offset
Return values
offsetOffset of label, or negative error

Definition at line 165 of file dns.c.

165  {
166  const uint8_t *byte;
167  const uint16_t *word;
168  size_t len;
169  size_t ptr;
170 
171  while ( 1 ) {
172 
173  /* Fail if we have overrun the DNS name */
174  if ( ( offset + sizeof ( *byte) ) > name->len )
175  return -EINVAL;
176  byte = ( name->data + offset );
177 
178  /* Follow compression pointer, if applicable */
179  if ( DNS_IS_COMPRESSED ( *byte ) ) {
180 
181  /* Fail if we have overrun the DNS name */
182  if ( ( offset + sizeof ( *word ) ) > name->len )
183  return -EINVAL;
184  word = ( name->data + offset );
185 
186  /* Extract pointer to new offset */
187  ptr = DNS_COMPRESSED_OFFSET ( ntohs ( *word ) );
188 
189  /* Fail if pointer does not point backwards.
190  * (This guarantees termination of the
191  * function.)
192  */
193  if ( ptr >= offset )
194  return -EINVAL;
195 
196  /* Continue from new offset */
197  offset = ptr;
198  continue;
199  }
200 
201  /* Fail if we have overrun the DNS name */
202  len = *byte;
203  if ( ( offset + sizeof ( *byte ) + len ) > name->len )
204  return -EINVAL;
205 
206  /* We have a valid label */
207  return offset;
208  }
209 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
const char * name
Definition: ath9k_hw.c:1984
unsigned short uint16_t
Definition: stdint.h:11
#define DNS_COMPRESSED_OFFSET(word)
Extract DNS compression pointer.
Definition: dns.h:42
#define ntohs(value)
Definition: byteswap.h:136
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned char uint8_t
Definition: stdint.h:10
unsigned char byte
Definition: smc9000.h:38
#define DNS_IS_COMPRESSED(byte)
Test for a DNS compression pointer.
Definition: dns.h:34
uint32_t len
Length.
Definition: ena.h:14
unsigned short word
Definition: smc9000.h:39

References DNS_COMPRESSED_OFFSET, DNS_IS_COMPRESSED, EINVAL, len, name, ntohs, and offset.

Referenced by dns_compare(), dns_copy(), dns_decode(), and dns_skip().

◆ dns_decode()

int dns_decode ( struct dns_name name,
char *  data,
size_t  len 
)

Decode RFC1035-encoded DNS name.

Parameters
nameDNS name
dataOutput buffer
lenLength of output buffer
Return values
lenLength of decoded DNS name, or negative error

Definition at line 219 of file dns.c.

219  {
220  unsigned int recursion_limit = name->len; /* Generous upper bound */
221  int offset = name->offset;
222  const uint8_t *label;
223  size_t decoded_len = 0;
224  size_t label_len;
225  size_t copy_len;
226 
227  while ( recursion_limit-- ) {
228 
229  /* Find valid DNS label */
230  offset = dns_label ( name, offset );
231  if ( offset < 0 )
232  return offset;
233 
234  /* Terminate if we have reached the root */
235  label = ( name->data + offset );
236  label_len = *(label++);
237  if ( label_len == 0 ) {
238  if ( decoded_len < len )
239  *data = '\0';
240  return decoded_len;
241  }
242 
243  /* Prepend '.' if applicable */
244  if ( decoded_len && ( decoded_len++ < len ) )
245  *(data++) = '.';
246 
247  /* Copy label to output buffer */
248  copy_len = ( ( decoded_len < len ) ? ( len - decoded_len ) : 0);
249  if ( copy_len > label_len )
250  copy_len = label_len;
251  memcpy ( data, label, copy_len );
252  data += copy_len;
253  decoded_len += label_len;
254 
255  /* Move to next label */
256  offset += ( sizeof ( *label ) + label_len );
257  }
258 
259  /* Recursion limit exceeded */
260  return -EINVAL;
261 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
const char * name
Definition: ath9k_hw.c:1984
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
static int dns_label(struct dns_name *name, size_t offset)
Find start of valid label within an RFC1035-encoded DNS name.
Definition: dns.c:165
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References data, dns_label(), EINVAL, len, memcpy(), name, and offset.

Referenced by dns_decode_fail_okx(), dns_decode_okx(), dns_list_okx(), dns_name(), dns_progress(), and format_dnssl_setting().

◆ dns_compare()

int dns_compare ( struct dns_name first,
struct dns_name second 
)

Compare DNS names for equality.

Parameters
firstFirst DNS name
secondSecond DNS name
Return values
rcReturn status code

Definition at line 270 of file dns.c.

270  {
271  unsigned int recursion_limit = first->len; /* Generous upper bound */
272  int first_offset = first->offset;
273  int second_offset = second->offset;
274  const uint8_t *first_label;
275  const uint8_t *second_label;
276  size_t label_len;
277  size_t len;
278 
279  while ( recursion_limit-- ) {
280 
281  /* Find valid DNS labels */
282  first_offset = dns_label ( first, first_offset );
283  if ( first_offset < 0 )
284  return first_offset;
285  second_offset = dns_label ( second, second_offset );
286  if ( second_offset < 0 )
287  return second_offset;
288 
289  /* Compare label lengths */
290  first_label = ( first->data + first_offset );
291  second_label = ( second->data + second_offset );
292  label_len = *(first_label++);
293  if ( label_len != *(second_label++) )
294  return -ENOENT;
295  len = ( sizeof ( *first_label ) + label_len );
296 
297  /* Terminate if we have reached the root */
298  if ( label_len == 0 )
299  return 0;
300 
301  /* Compare label contents (case-insensitively) */
302  while ( label_len-- ) {
303  if ( tolower ( *(first_label++) ) !=
304  tolower ( *(second_label++) ) )
305  return -ENOENT;
306  }
307 
308  /* Move to next labels */
309  first_offset += len;
310  second_offset += len;
311  }
312 
313  /* Recursion limit exceeded */
314  return -EINVAL;
315 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
static __always_inline int off_t userptr_t second
Definition: efi_uaccess.h:80
#define ENOENT
No such file or directory.
Definition: errno.h:514
static int tolower(int character)
Convert character to lower case.
Definition: ctype.h:97
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
static int dns_label(struct dns_name *name, size_t offset)
Find start of valid label within an RFC1035-encoded DNS name.
Definition: dns.c:165
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References dns_label(), EINVAL, ENOENT, first, len, second, and tolower().

Referenced by dns_compare_fail_okx(), dns_compare_okx(), and dns_xfer_deliver().

◆ dns_copy()

int dns_copy ( struct dns_name src,
struct dns_name dst 
)

Copy a DNS name.

Parameters
srcSource DNS name
dstDestination DNS name
Return values
lenLength of copied DNS name, or negative error

Definition at line 324 of file dns.c.

324  {
325  unsigned int recursion_limit = src->len; /* Generous upper bound */
326  int src_offset = src->offset;
327  size_t dst_offset = dst->offset;
328  const uint8_t *label;
329  size_t label_len;
330  size_t copy_len;
331  size_t len;
332 
333  while ( recursion_limit-- ) {
334 
335  /* Find valid DNS label */
336  src_offset = dns_label ( src, src_offset );
337  if ( src_offset < 0 )
338  return src_offset;
339 
340  /* Copy as an uncompressed label */
341  label = ( src->data + src_offset );
342  label_len = *label;
343  len = ( sizeof ( *label ) + label_len );
344  copy_len = ( ( dst_offset < dst->len ) ?
345  ( dst->len - dst_offset ) : 0 );
346  if ( copy_len > len )
347  copy_len = len;
348  memcpy ( ( dst->data + dst_offset ), label, copy_len );
349  src_offset += len;
350  dst_offset += len;
351 
352  /* Terminate if we have reached the root */
353  if ( label_len == 0 )
354  return ( dst_offset - dst->offset );
355  }
356 
357  /* Recursion limit exceeded */
358  return -EINVAL;
359 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
void * data
Start of data.
Definition: dns.h:21
void * memcpy(void *dest, const void *src, size_t len) __nonnull
size_t offset
Offset of name within data.
Definition: dns.h:23
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
static int dns_label(struct dns_name *name, size_t offset)
Find start of valid label within an RFC1035-encoded DNS name.
Definition: dns.c:165
size_t len
Total length of data.
Definition: dns.h:25

References dns_name::data, dns_label(), EINVAL, len, dns_name::len, memcpy(), dns_name::offset, and src.

Referenced by dns_copy_fail_okx(), dns_copy_okx(), dns_question(), and dns_xfer_deliver().

◆ dns_skip()

int dns_skip ( struct dns_name name)

Skip RFC1035-encoded DNS name.

Parameters
nameDNS name
Return values
offsetOffset to next name, or negative error

Definition at line 367 of file dns.c.

367  {
368  unsigned int recursion_limit = name->len; /* Generous upper bound */
369  int offset = name->offset;
370  int prev_offset;
371  const uint8_t *label;
372  size_t label_len;
373 
374  while ( recursion_limit-- ) {
375 
376  /* Find valid DNS label */
377  prev_offset = offset;
378  offset = dns_label ( name, prev_offset );
379  if ( offset < 0 )
380  return offset;
381 
382  /* Terminate if we have reached a compression pointer */
383  if ( offset != prev_offset )
384  return ( prev_offset + sizeof ( uint16_t ) );
385 
386  /* Skip this label */
387  label = ( name->data + offset );
388  label_len = *label;
389  offset += ( sizeof ( *label ) + label_len );
390 
391  /* Terminate if we have reached the root */
392  if ( label_len == 0 )
393  return offset;
394  }
395 
396  /* Recursion limit exceeded */
397  return -EINVAL;
398 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
const char * name
Definition: ath9k_hw.c:1984
unsigned short uint16_t
Definition: stdint.h:11
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned char uint8_t
Definition: stdint.h:10
static int dns_label(struct dns_name *name, size_t offset)
Find start of valid label within an RFC1035-encoded DNS name.
Definition: dns.c:165

References dns_label(), EINVAL, name, and offset.

Referenced by dns_list_okx(), dns_skip_search(), and dns_xfer_deliver().

◆ dns_skip_search()

static int dns_skip_search ( struct dns_name name)
static

Skip RFC1035-encoded DNS name in search list.

Parameters
nameDNS name
Return values
offsetOffset to next non-empty name, or negative error

Definition at line 406 of file dns.c.

406  {
407  int offset;
408 
409  /* Find next name */
410  offset = dns_skip ( name );
411  if ( offset < 0 )
412  return offset;
413 
414  /* Skip over any subsequent empty names (e.g. due to padding
415  * bytes used in the NDP DNSSL option).
416  */
417  while ( ( offset < ( ( int ) name->len ) ) &&
418  ( *( ( uint8_t * ) ( name->data + offset ) ) == 0 ) ) {
419  offset++;
420  }
421 
422  return offset;
423 }
const char * name
Definition: ath9k_hw.c:1984
int dns_skip(struct dns_name *name)
Skip RFC1035-encoded DNS name.
Definition: dns.c:367
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned char uint8_t
Definition: stdint.h:10

References dns_skip(), name, and offset.

Referenced by apply_dns_settings(), dns_xfer_deliver(), and format_dnssl_setting().

◆ dns_name()

static const char* dns_name ( struct dns_name name)
static

Transcribe DNS name (for debugging)

Parameters
nameDNS name
Return values
stringTranscribed DNS name

Definition at line 431 of file dns.c.

431  {
432  static char buf[256];
433  int len;
434 
435  len = dns_decode ( name, buf, ( sizeof ( buf ) - 1 /* NUL */ ) );
436  return ( ( len < 0 ) ? "<INVALID>" : buf );
437 }
const char * name
Definition: ath9k_hw.c:1984
uint32_t len
Length.
Definition: ena.h:14
int dns_decode(struct dns_name *name, char *data, size_t len)
Decode RFC1035-encoded DNS name.
Definition: dns.c:219

References dns_decode(), len, and name.

◆ dns_type()

static const char* dns_type ( uint16_t  type)
static

Name a DNS query type (for debugging)

Parameters
typeQuery type (in network byte order)
Return values
nameType name

Definition at line 445 of file dns.c.

445  {
446  switch ( type ) {
447  case htons ( DNS_TYPE_A ): return "A";
448  case htons ( DNS_TYPE_AAAA ): return "AAAA";
449  case htons ( DNS_TYPE_CNAME ): return "CNAME";
450  default: return "<UNKNOWN>";
451  }
452 }
#define DNS_TYPE_CNAME
Type of a DNS "NAME" record.
Definition: dns.h:129
uint8_t type
Type.
Definition: ena.h:16
#define DNS_TYPE_A
Type of a DNS "A" record.
Definition: dns.h:107
#define DNS_TYPE_AAAA
Type of a DNS "AAAA" record.
Definition: dns.h:118
return
Definition: natsemi.h:326
#define htons(value)
Definition: byteswap.h:135

References DNS_TYPE_A, DNS_TYPE_AAAA, DNS_TYPE_CNAME, htons, and type.

Referenced by dns_question(), dns_send_packet(), and dns_xfer_deliver().

◆ dns_done()

static void dns_done ( struct dns_request dns,
int  rc 
)
static

Mark DNS request as complete.

Parameters
dnsDNS request
rcReturn status code

Definition at line 502 of file dns.c.

502  {
503 
504  /* Stop the retry timer */
505  stop_timer ( &dns->timer );
506 
507  /* Shut down interfaces */
508  intf_shutdown ( &dns->socket, rc );
509  intf_shutdown ( &dns->resolv, rc );
510 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
struct interface resolv
Name resolution interface.
Definition: dns.c:459
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
struct interface socket
Data transfer interface.
Definition: dns.c:461
struct retry_timer timer
Retry timer.
Definition: dns.c:463

References intf_shutdown(), rc, dns_request::resolv, dns_request::socket, stop_timer(), and dns_request::timer.

Referenced by dns_resolved(), dns_timer_expired(), dns_xfer_close(), and dns_xfer_deliver().

◆ dns_resolved()

static void dns_resolved ( struct dns_request dns)
static

Mark DNS request as resolved and complete.

Parameters
dnsDNS request
rcReturn status code

Definition at line 518 of file dns.c.

518  {
519 
520  DBGC ( dns, "DNS %p found address %s\n",
521  dns, sock_ntoa ( &dns->address.sa ) );
522 
523  /* Return resolved address */
524  resolv_done ( &dns->resolv, &dns->address.sa );
525 
526  /* Mark operation as complete */
527  dns_done ( dns, 0 );
528 }
static void dns_done(struct dns_request *dns, int rc)
Mark DNS request as complete.
Definition: dns.c:502
void resolv_done(struct interface *intf, struct sockaddr *sa)
Name resolved.
Definition: resolv.c:55
#define DBGC(...)
Definition: compiler.h:505
struct sockaddr sa
Definition: dns.c:467
struct interface resolv
Name resolution interface.
Definition: dns.c:459
const char * sock_ntoa(struct sockaddr *sa)
Transcribe socket address.
Definition: socket.c:42
union dns_request::@4 address
Socket address to fill in with resolved address.

References dns_request::address, DBGC, dns_done(), dns_request::resolv, resolv_done(), dns_request::sa, and sock_ntoa().

Referenced by dns_xfer_deliver().

◆ dns_question()

static int dns_question ( struct dns_request dns)
static

Construct DNS question.

Parameters
dnsDNS request
Return values
rcReturn status code

Definition at line 536 of file dns.c.

536  {
537  static struct dns_name search_root = {
538  .data = "",
539  .len = 1,
540  };
541  struct dns_name *search = &dns->search;
542  int len;
543  size_t offset;
544 
545  /* Use root suffix if search list is empty */
546  if ( search->offset == search->len )
547  search = &search_root;
548 
549  /* Overwrite current suffix */
550  dns->name.offset = dns->offset;
551  len = dns_copy ( search, &dns->name );
552  if ( len < 0 )
553  return len;
554 
555  /* Sanity check */
556  offset = ( dns->name.offset + len );
557  if ( offset > dns->name.len ) {
558  DBGC ( dns, "DNS %p name is too long\n", dns );
559  return -EINVAL;
560  }
561 
562  /* Construct question */
563  dns->question = ( ( ( void * ) &dns->buf ) + offset );
564  dns->question->qtype = dns->qtype;
565  dns->question->qclass = htons ( DNS_CLASS_IN );
566 
567  /* Store length */
568  dns->len = ( offset + sizeof ( *(dns->question) ) );
569 
570  /* Restore name */
571  dns->name.offset = offsetof ( typeof ( dns->buf ), name );
572 
573  /* Reset query ID */
574  dns->buf.query.id = 0;
575 
576  DBGC2 ( dns, "DNS %p question is %s type %s\n", dns,
577  dns_name ( &dns->name ), dns_type ( dns->question->qtype ) );
578 
579  return 0;
580 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
size_t offset
Offset of search suffix within current query.
Definition: dns.c:489
const char * name
Definition: ath9k_hw.c:1984
struct dns_question * question
Question within current query.
Definition: dns.c:485
#define DBGC(...)
Definition: compiler.h:505
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
void * data
Start of data.
Definition: dns.h:21
static const char * dns_type(uint16_t type)
Name a DNS query type (for debugging)
Definition: dns.c:445
uint16_t qtype
Query type.
Definition: dns.h:86
An RFC1035-encoded DNS name.
Definition: dns.h:19
struct dns_request::@5 buf
Buffer for current query.
size_t len
Length of current query.
Definition: dns.c:487
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
size_t offset
Offset of name within data.
Definition: dns.h:23
struct dns_header query
Query header.
Definition: dns.c:476
int dns_copy(struct dns_name *src, struct dns_name *dst)
Copy a DNS name.
Definition: dns.c:324
char name[DNS_MAX_NAME_LEN]
Name buffer.
Definition: dns.c:478
uint16_t qclass
Query class.
Definition: dns.h:88
uint16_t id
Query identifier.
Definition: dns.h:67
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct dns_name search
Search list.
Definition: dns.c:491
#define DNS_CLASS_IN
DNS class "IN".
Definition: dns.h:92
uint16_t qtype
Initial query type.
Definition: dns.c:472
size_t len
Total length of data.
Definition: dns.h:25
#define htons(value)
Definition: byteswap.h:135

References dns_request::buf, dns_name::data, DBGC, DBGC2, DNS_CLASS_IN, dns_copy(), dns_type(), EINVAL, htons, dns_header::id, len, dns_name::len, dns_request::len, dns_request::name, name, dns_name::offset, offset, dns_request::offset, offsetof, dns_question::qclass, dns_question::qtype, dns_request::qtype, dns_request::query, dns_request::question, and dns_request::search.

◆ dns_send_packet()

static int dns_send_packet ( struct dns_request dns)
static

Send DNS query.

Parameters
dnsDNS request
Return values
rcReturn status code

Definition at line 588 of file dns.c.

588  {
589  struct dns_header *query = &dns->buf.query;
590  union {
591  struct sockaddr sa;
592  struct sockaddr_tcpip st;
593  struct sockaddr_in sin;
594  struct sockaddr_in6 sin6;
595  } nameserver;
596  struct xfer_metadata meta;
597  unsigned int index;
598 
599  /* Start retransmission timer */
600  start_timer ( &dns->timer );
601 
602  /* Construct DNS server address */
603  memset ( &nameserver, 0, sizeof ( nameserver ) );
604  nameserver.st.st_port = htons ( DNS_PORT );
605  if ( ! dns_count ) {
606  DBGC ( dns, "DNS %p lost DNS servers mid query\n", dns );
607  return -EINVAL;
608  }
609  index = ( dns_index % dns_count );
610  if ( index < dns6.count ) {
611  nameserver.sin6.sin6_family = AF_INET6;
612  memcpy ( &nameserver.sin6.sin6_addr, &dns6.in6[index],
613  sizeof ( nameserver.sin6.sin6_addr ) );
614  } else {
615  nameserver.sin.sin_family = AF_INET;
616  nameserver.sin.sin_addr = dns4.in[index - dns6.count];
617  }
618 
619  /* Construct metadata */
620  memset ( &meta, 0, sizeof ( meta ) );
621  meta.dest = &nameserver.sa;
622 
623  /* Generate query identifier if applicable */
624  if ( ! query->id )
625  query->id = random();
626 
627  /* Send query */
628  DBGC ( dns, "DNS %p sending %s query ID %#04x for %s type %s\n", dns,
629  sock_ntoa ( &nameserver.sa ), ntohs ( query->id ),
630  dns_name ( &dns->name ), dns_type ( dns->question->qtype ) );
631 
632  /* Send the data */
633  return xfer_deliver_raw_meta ( &dns->socket, query, dns->len, &meta );
634 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
TCP/IP socket address.
Definition: tcpip.h:75
Data transfer metadata.
Definition: xfer.h:22
#define AF_INET6
IPv6 Internet addresses.
Definition: socket.h:64
struct dns_question * question
Question within current query.
Definition: dns.c:485
A DNS packet header.
Definition: dns.h:65
int xfer_deliver_raw_meta(struct interface *intf, const void *data, size_t len, struct xfer_metadata *meta)
Deliver datagram as raw data.
Definition: xfer.c:267
static struct dns_server dns4
IPv4 DNS server list.
Definition: dns.c:82
struct in_addr * in
IPv4 addresses.
Definition: dns.c:71
#define DBGC(...)
Definition: compiler.h:505
struct sockaddr_in6 sin6
Definition: syslog.c:58
IPv4 socket address.
Definition: in.h:82
#define ntohs(value)
Definition: byteswap.h:136
unsigned int count
Number of servers.
Definition: dns.c:78
#define DNS_PORT
DNS server port.
Definition: dns.h:16
static unsigned int dns_count
Total number of DNS servers.
Definition: dns.c:88
static const char * dns_type(uint16_t type)
Name a DNS query type (for debugging)
Definition: dns.c:445
struct sockaddr_tcpip st
Definition: syslog.c:56
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint16_t qtype
Query type.
Definition: dns.h:86
An RFC1035-encoded DNS name.
Definition: dns.h:19
struct dns_request::@5 buf
Buffer for current query.
size_t len
Length of current query.
Definition: dns.c:487
struct sockaddr sa
Definition: syslog.c:55
int meta(WINDOW *, bool)
Generalized socket address structure.
Definition: socket.h:96
struct dns_header query
Query header.
Definition: dns.c:476
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:30
void start_timer(struct retry_timer *timer)
Start timer.
Definition: retry.c:93
char name[DNS_MAX_NAME_LEN]
Name buffer.
Definition: dns.c:478
struct interface socket
Data transfer interface.
Definition: dns.c:461
const char * sock_ntoa(struct sockaddr *sa)
Transcribe socket address.
Definition: socket.c:42
uint16_t id
Query identifier.
Definition: dns.h:67
struct retry_timer timer
Retry timer.
Definition: dns.c:463
static unsigned int dns_index
Current DNS server index.
Definition: dns.c:91
IPv6 socket address.
Definition: in.h:115
struct sockaddr_in sin
Definition: syslog.c:57
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
struct in6_addr * in6
IPv6 addresses.
Definition: dns.c:73
#define htons(value)
Definition: byteswap.h:135
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
static struct dns_server dns6
IPv6 DNS server list.
Definition: dns.c:85
void * memset(void *dest, int character, size_t len) __nonnull

References AF_INET, AF_INET6, dns_request::buf, dns_server::count, DBGC, dns4, dns6, dns_count, dns_index, DNS_PORT, dns_type(), EINVAL, htons, dns_header::id, dns_server::in, dns_server::in6, index, dns_request::len, memcpy(), memset(), meta(), dns_request::name, ntohs, dns_question::qtype, dns_request::query, dns_request::question, random(), sa, sin, sin6, sock_ntoa(), dns_request::socket, st, start_timer(), dns_request::timer, and xfer_deliver_raw_meta().

Referenced by dns_timer_expired(), and dns_xfer_deliver().

◆ dns_timer_expired()

static void dns_timer_expired ( struct retry_timer timer,
int  fail 
)
static

Handle DNS (re)transmission timer expiry.

Parameters
timerRetry timer
failFailure indicator

Definition at line 642 of file dns.c.

642  {
643  struct dns_request *dns =
644  container_of ( timer, struct dns_request, timer );
645 
646  /* Terminate DNS request on failure */
647  if ( fail ) {
648  dns_done ( dns, -ETIMEDOUT );
649  return;
650  }
651 
652  /* Move to next DNS server if this is a retransmission */
653  if ( dns->buf.query.id )
654  dns_index++;
655 
656  /* Send DNS query */
657  dns_send_packet ( dns );
658 }
static void dns_done(struct dns_request *dns, int rc)
Mark DNS request as complete.
Definition: dns.c:502
A timer.
Definition: timer.h:28
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct dns_request::@5 buf
Buffer for current query.
static int dns_send_packet(struct dns_request *dns)
Send DNS query.
Definition: dns.c:588
struct dns_header query
Query header.
Definition: dns.c:476
A DNS request.
Definition: dns.c:455
uint16_t id
Query identifier.
Definition: dns.h:67
static unsigned int dns_index
Current DNS server index.
Definition: dns.c:91
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References dns_request::buf, container_of, dns_done(), dns_index, dns_send_packet(), ETIMEDOUT, dns_header::id, and dns_request::query.

Referenced by dns_resolv().

◆ dns_xfer_deliver()

static int dns_xfer_deliver ( struct dns_request dns,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
)
static

Receive new data.

Parameters
dnsDNS request
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 668 of file dns.c.

670  {
671  struct dns_header *response = iobuf->data;
672  struct dns_header *query = &dns->buf.query;
673  unsigned int qtype = dns->question->qtype;
674  struct dns_name buf;
675  union dns_rr *rr;
676  int offset;
677  size_t answer_offset;
678  size_t next_offset;
679  size_t rdlength;
680  size_t name_len;
681  int rc;
682 
683  /* Sanity check */
684  if ( iob_len ( iobuf ) < sizeof ( *response ) ) {
685  DBGC ( dns, "DNS %p received underlength packet length %zd\n",
686  dns, iob_len ( iobuf ) );
687  rc = -EINVAL;
688  goto done;
689  }
690 
691  /* Check response ID matches query ID */
692  if ( response->id != query->id ) {
693  DBGC ( dns, "DNS %p received unexpected response ID %#04x "
694  "(wanted %d)\n", dns, ntohs ( response->id ),
695  ntohs ( query->id ) );
696  rc = -EINVAL;
697  goto done;
698  }
699  DBGC ( dns, "DNS %p received response ID %#04x\n",
700  dns, ntohs ( response->id ) );
701 
702  /* Check that we have exactly one question */
703  if ( response->qdcount != htons ( 1 ) ) {
704  DBGC ( dns, "DNS %p received response with %d questions\n",
705  dns, ntohs ( response->qdcount ) );
706  rc = -EINVAL;
707  goto done;
708  }
709 
710  /* Skip question section */
711  buf.data = iobuf->data;
712  buf.offset = sizeof ( *response );
713  buf.len = iob_len ( iobuf );
714  offset = dns_skip ( &buf );
715  if ( offset < 0 ) {
716  rc = offset;
717  DBGC ( dns, "DNS %p received response with malformed "
718  "question: %s\n", dns, strerror ( rc ) );
719  goto done;
720  }
721  answer_offset = ( offset + sizeof ( struct dns_question ) );
722 
723  /* Search through response for useful answers. Do this
724  * multiple times, to take advantage of useful nameservers
725  * which send us e.g. the CNAME *and* the A record for the
726  * pointed-to name.
727  */
728  for ( buf.offset = answer_offset ; buf.offset != buf.len ;
729  buf.offset = next_offset ) {
730 
731  /* Check for valid name */
732  offset = dns_skip ( &buf );
733  if ( offset < 0 ) {
734  rc = offset;
735  DBGC ( dns, "DNS %p received response with malformed "
736  "answer: %s\n", dns, strerror ( rc ) );
737  goto done;
738  }
739 
740  /* Check for sufficient space for resource record */
741  rr = ( buf.data + offset );
742  if ( ( offset + sizeof ( rr->common ) ) > buf.len ) {
743  DBGC ( dns, "DNS %p received response with underlength "
744  "RR\n", dns );
745  rc = -EINVAL;
746  goto done;
747  }
748  rdlength = ntohs ( rr->common.rdlength );
749  next_offset = ( offset + sizeof ( rr->common ) + rdlength );
750  if ( next_offset > buf.len ) {
751  DBGC ( dns, "DNS %p received response with underlength "
752  "RR\n", dns );
753  rc = -EINVAL;
754  goto done;
755  }
756 
757  /* Skip non-matching names */
758  if ( dns_compare ( &buf, &dns->name ) != 0 ) {
759  DBGC2 ( dns, "DNS %p ignoring response for %s type "
760  "%s\n", dns, dns_name ( &buf ),
761  dns_type ( rr->common.type ) );
762  continue;
763  }
764 
765  /* Handle answer */
766  switch ( rr->common.type ) {
767 
768  case htons ( DNS_TYPE_AAAA ):
769 
770  /* Found the target AAAA record */
771  if ( rdlength < sizeof ( dns->address.sin6.sin6_addr )){
772  DBGC ( dns, "DNS %p received response with "
773  "underlength AAAA\n", dns );
774  rc = -EINVAL;
775  goto done;
776  }
778  memcpy ( &dns->address.sin6.sin6_addr,
779  &rr->aaaa.in6_addr,
780  sizeof ( dns->address.sin6.sin6_addr ) );
781  dns_resolved ( dns );
782  rc = 0;
783  goto done;
784 
785  case htons ( DNS_TYPE_A ):
786 
787  /* Found the target A record */
788  if ( rdlength < sizeof ( dns->address.sin.sin_addr ) ) {
789  DBGC ( dns, "DNS %p received response with "
790  "underlength A\n", dns );
791  rc = -EINVAL;
792  goto done;
793  }
794  dns->address.sin.sin_family = AF_INET;
795  dns->address.sin.sin_addr = rr->a.in_addr;
796  dns_resolved ( dns );
797  rc = 0;
798  goto done;
799 
800  case htons ( DNS_TYPE_CNAME ):
801 
802  /* Terminate the operation if we recurse too far */
803  if ( ++dns->recursion > DNS_MAX_CNAME_RECURSION ) {
804  DBGC ( dns, "DNS %p recursion exceeded\n",
805  dns );
806  rc = -ELOOP;
807  dns_done ( dns, rc );
808  goto done;
809  }
810 
811  /* Found a CNAME record; update query and recurse */
812  buf.offset = ( offset + sizeof ( rr->cname ) );
813  DBGC ( dns, "DNS %p found CNAME %s\n",
814  dns, dns_name ( &buf ) );
815  dns->search.offset = dns->search.len;
816  name_len = dns_copy ( &buf, &dns->name );
817  dns->offset = ( offsetof ( typeof ( dns->buf ), name ) +
818  name_len - 1 /* Strip root label */ );
819  if ( ( rc = dns_question ( dns ) ) != 0 ) {
820  dns_done ( dns, rc );
821  goto done;
822  }
823  next_offset = answer_offset;
824  break;
825 
826  default:
827  DBGC ( dns, "DNS %p got unknown record type %d\n",
828  dns, ntohs ( rr->common.type ) );
829  break;
830  }
831  }
832 
833  /* Stop the retry timer. After this point, each code path
834  * must either restart the timer by calling dns_send_packet(),
835  * or mark the DNS operation as complete by calling
836  * dns_done()
837  */
838  stop_timer ( &dns->timer );
839 
840  /* Determine what to do next based on the type of query we
841  * issued and the response we received
842  */
843  switch ( qtype ) {
844 
845  case htons ( DNS_TYPE_AAAA ):
846  /* We asked for an AAAA record and got nothing; try
847  * the A.
848  */
849  DBGC ( dns, "DNS %p found no AAAA record; trying A\n", dns );
850  dns->question->qtype = htons ( DNS_TYPE_A );
851  dns_send_packet ( dns );
852  rc = 0;
853  goto done;
854 
855  case htons ( DNS_TYPE_A ):
856  /* We asked for an A record and got nothing;
857  * try the CNAME.
858  */
859  DBGC ( dns, "DNS %p found no A record; trying CNAME\n", dns );
860  dns->question->qtype = htons ( DNS_TYPE_CNAME );
861  dns_send_packet ( dns );
862  rc = 0;
863  goto done;
864 
865  case htons ( DNS_TYPE_CNAME ):
866  /* We asked for a CNAME record. If we got a response
867  * (i.e. if the next AAAA/A query is already set up),
868  * then issue it.
869  */
870  if ( qtype == dns->qtype ) {
871  dns_send_packet ( dns );
872  rc = 0;
873  goto done;
874  }
875 
876  /* If we have already reached the end of the search list,
877  * then terminate lookup.
878  */
879  if ( dns->search.offset == dns->search.len ) {
880  DBGC ( dns, "DNS %p found no CNAME record\n", dns );
881  rc = -ENXIO_NO_RECORD;
882  dns_done ( dns, rc );
883  goto done;
884  }
885 
886  /* Move to next entry in search list. This can never fail,
887  * since we have already used this entry.
888  */
889  DBGC ( dns, "DNS %p found no CNAME record; trying next "
890  "suffix\n", dns );
891  dns->search.offset = dns_skip_search ( &dns->search );
892  if ( ( rc = dns_question ( dns ) ) != 0 ) {
893  dns_done ( dns, rc );
894  goto done;
895  }
896  dns_send_packet ( dns );
897  goto done;
898 
899  default:
900  assert ( 0 );
901  rc = -EINVAL;
902  dns_done ( dns, rc );
903  goto done;
904  }
905 
906  done:
907  /* Free I/O buffer */
908  free_iob ( iobuf );
909  return rc;
910 }
struct dns_rr_common common
Common fields.
Definition: dns.h:140
#define EINVAL
Invalid argument.
Definition: errno.h:428
#define DNS_TYPE_CNAME
Type of a DNS "NAME" record.
Definition: dns.h:129
size_t offset
Offset of search suffix within current query.
Definition: dns.c:489
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
uint16_t qdcount
Number of question records.
Definition: dns.h:71
#define AF_INET6
IPv6 Internet addresses.
Definition: socket.h:64
struct dns_question * question
Question within current query.
Definition: dns.c:485
int dns_skip(struct dns_name *name)
Skip RFC1035-encoded DNS name.
Definition: dns.c:367
static void dns_done(struct dns_request *dns, int rc)
Mark DNS request as complete.
Definition: dns.c:502
A DNS packet header.
Definition: dns.h:65
uint16_t type
Type.
Definition: dns.h:97
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
struct sockaddr_in6 sin6
Definition: syslog.c:58
struct in6_addr in6_addr
IPv6 address.
Definition: dns.h:125
struct in_addr in_addr
IPv4 address.
Definition: dns.h:114
#define ntohs(value)
Definition: byteswap.h:136
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
sa_family_t sin_family
Socket address family (part of struct sockaddr)
Definition: in.h:87
#define ELOOP
Too many levels of symbolic links.
Definition: errno.h:448
static const char * dns_type(uint16_t type)
Name a DNS query type (for debugging)
Definition: dns.c:445
#define DNS_TYPE_A
Type of a DNS "A" record.
Definition: dns.h:107
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A DNS resource record.
Definition: dns.h:138
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint16_t qtype
Query type.
Definition: dns.h:86
An RFC1035-encoded DNS name.
Definition: dns.h:19
struct dns_request::@5 buf
Buffer for current query.
struct sockaddr_in6 sin6
Definition: dns.c:469
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static int dns_send_packet(struct dns_request *dns)
Send DNS query.
Definition: dns.c:588
size_t offset
Offset of name within data.
Definition: dns.h:23
#define DNS_TYPE_AAAA
Type of a DNS "AAAA" record.
Definition: dns.h:118
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
struct dns_header query
Query header.
Definition: dns.c:476
int dns_copy(struct dns_name *src, struct dns_name *dst)
Copy a DNS name.
Definition: dns.c:324
#define DNS_MAX_CNAME_RECURSION
Maximum depth of CNAME recursion.
Definition: dns.h:62
struct dns_rr_a a
"A" record
Definition: dns.h:142
#define ENXIO_NO_RECORD
Definition: dns.c:59
char name[DNS_MAX_NAME_LEN]
Name buffer.
Definition: dns.c:478
struct in_addr sin_addr
IPv4 address.
Definition: in.h:98
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
A DNS question.
Definition: dns.h:84
struct dns_rr_aaaa aaaa
"AAAA" record
Definition: dns.h:144
uint16_t id
Query identifier.
Definition: dns.h:67
#define DBGC2(...)
Definition: compiler.h:522
static int dns_skip_search(struct dns_name *name)
Skip RFC1035-encoded DNS name in search list.
Definition: dns.c:406
void * data
Start of data.
Definition: iobuf.h:48
struct dns_name search
Search list.
Definition: dns.c:491
struct retry_timer timer
Retry timer.
Definition: dns.c:463
int dns_compare(struct dns_name *first, struct dns_name *second)
Compare DNS names for equality.
Definition: dns.c:270
sa_family_t sin6_family
Socket address family (part of struct sockaddr)
Definition: in.h:120
struct sockaddr_in sin
Definition: syslog.c:57
size_t len
Total length of data.
Definition: dns.h:25
struct sockaddr_in sin
Definition: dns.c:468
union dns_request::@4 address
Socket address to fill in with resolved address.
uint16_t rdlength
Resource data length.
Definition: dns.h:103
#define htons(value)
Definition: byteswap.h:135
struct bofm_section_header done
Definition: bofm_test.c:46
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
struct in6_addr sin6_addr
IPv6 address.
Definition: in.h:132
if(natsemi->flags &NATSEMI_64BIT) return 1
struct dns_rr_cname cname
"CNAME" record
Definition: dns.h:146
static void dns_resolved(struct dns_request *dns)
Mark DNS request as resolved and complete.
Definition: dns.c:518

References dns_rr::a, dns_rr::aaaa, dns_request::address, AF_INET, AF_INET6, assert(), dns_request::buf, dns_rr::cname, dns_rr::common, dns_name::data, io_buffer::data, DBGC, DBGC2, dns_compare(), dns_copy(), dns_done(), DNS_MAX_CNAME_RECURSION, dns_resolved(), dns_send_packet(), dns_skip(), dns_skip_search(), dns_type(), DNS_TYPE_A, DNS_TYPE_AAAA, DNS_TYPE_CNAME, done, EINVAL, ELOOP, ENXIO_NO_RECORD, free_iob(), htons, dns_header::id, dns_rr_aaaa::in6_addr, dns_rr_a::in_addr, iob_len(), dns_name::len, memcpy(), dns_request::name, name, ntohs, dns_name::offset, offset, dns_request::offset, offsetof, dns_header::qdcount, dns_question::qtype, dns_request::qtype, dns_request::query, dns_request::question, rc, dns_rr_common::rdlength, dns_request::recursion, dns_request::search, dns_request::sin, dns_request::sin6, sockaddr_in6::sin6_addr, sockaddr_in6::sin6_family, sockaddr_in::sin_addr, sockaddr_in::sin_family, stop_timer(), strerror(), dns_request::timer, and dns_rr_common::type.

◆ dns_xfer_close()

static void dns_xfer_close ( struct dns_request dns,
int  rc 
)
static

Receive new data.

Parameters
dnsDNS request
rcReason for close

Definition at line 918 of file dns.c.

918  {
919 
920  if ( ! rc )
921  rc = -ECONNABORTED;
922 
923  dns_done ( dns, rc );
924 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void dns_done(struct dns_request *dns, int rc)
Mark DNS request as complete.
Definition: dns.c:502
#define ECONNABORTED
Connection aborted.
Definition: errno.h:353

References dns_done(), ECONNABORTED, and rc.

◆ dns_progress()

static int dns_progress ( struct dns_request dns,
struct job_progress progress 
)
static

Report job progress.

Parameters
dnsDNS request
progressProgress report to fill in
Return values
ongoing_rcOngoing job status code (if known)

Definition at line 933 of file dns.c.

934  {
935  int len;
936 
937  /* Show current question as progress message */
938  len = dns_decode ( &dns->name, progress->message,
939  ( sizeof ( progress->message ) - 1 /* NUL */ ) );
940  if ( len < 0 ) {
941  /* Ignore undecodable names */
942  progress->message[0] = '\0';
943  }
944 
945  return 0;
946 }
char message[32]
Message (optional)
Definition: job.h:32
char name[DNS_MAX_NAME_LEN]
Name buffer.
Definition: dns.c:478
uint32_t len
Length.
Definition: ena.h:14
int dns_decode(struct dns_name *name, char *data, size_t len)
Decode RFC1035-encoded DNS name.
Definition: dns.c:219

References dns_decode(), len, job_progress::message, and dns_request::name.

◆ dns_resolv()

static int dns_resolv ( struct interface resolv,
const char *  name,
struct sockaddr sa 
)
static

Resolve name using DNS.

Parameters
resolvName resolution interface
nameName to resolve
saSocket address to fill in
Return values
rcReturn status code

Definition at line 976 of file dns.c.

977  {
978  struct dns_request *dns;
979  struct dns_header *query;
980  size_t search_len;
981  int name_len;
982  int rc;
983 
984  /* Fail immediately if no DNS servers */
985  if ( dns_count == 0 ) {
986  DBG ( "DNS not attempting to resolve \"%s\": "
987  "no DNS servers\n", name );
989  goto err_no_nameserver;
990  }
991 
992  /* Determine whether or not to use search list */
993  search_len = ( strchr ( name, '.' ) ? 0 : dns_search.len );
994 
995  /* Allocate DNS structure */
996  dns = zalloc ( sizeof ( *dns ) + search_len );
997  if ( ! dns ) {
998  rc = -ENOMEM;
999  goto err_alloc_dns;
1000  }
1001  ref_init ( &dns->refcnt, NULL );
1002  intf_init ( &dns->resolv, &dns_resolv_desc, &dns->refcnt );
1003  intf_init ( &dns->socket, &dns_socket_desc, &dns->refcnt );
1004  timer_init ( &dns->timer, dns_timer_expired, &dns->refcnt );
1005  memcpy ( &dns->address.sa, sa, sizeof ( dns->address.sa ) );
1006  dns->search.data = ( ( ( void * ) dns ) + sizeof ( *dns ) );
1007  dns->search.len = search_len;
1008  memcpy ( dns->search.data, dns_search.data, search_len );
1009 
1010  /* Determine initial query type */
1011  dns->qtype = ( ( dns6.count != 0 ) ?
1012  htons ( DNS_TYPE_AAAA ) : htons ( DNS_TYPE_A ) );
1013 
1014  /* Construct query */
1015  query = &dns->buf.query;
1016  query->flags = htons ( DNS_FLAG_RD );
1017  query->qdcount = htons ( 1 );
1018  dns->name.data = &dns->buf;
1019  dns->name.offset = offsetof ( typeof ( dns->buf ), name );
1020  dns->name.len = offsetof ( typeof ( dns->buf ), padding );
1021  name_len = dns_encode ( name, &dns->name );
1022  if ( name_len < 0 ) {
1023  rc = name_len;
1024  goto err_encode;
1025  }
1026  dns->offset = ( offsetof ( typeof ( dns->buf ), name ) +
1027  name_len - 1 /* Strip root label */ );
1028  if ( ( rc = dns_question ( dns ) ) != 0 )
1029  goto err_question;
1030 
1031  /* Open UDP connection */
1032  if ( ( rc = xfer_open_socket ( &dns->socket, SOCK_DGRAM,
1033  NULL, NULL ) ) != 0 ) {
1034  DBGC ( dns, "DNS %p could not open socket: %s\n",
1035  dns, strerror ( rc ) );
1036  goto err_open_socket;
1037  }
1038 
1039  /* Start timer to trigger first packet */
1040  start_timer_nodelay ( &dns->timer );
1041 
1042  /* Attach parent interface, mortalise self, and return */
1043  intf_plug_plug ( &dns->resolv, resolv );
1044  ref_put ( &dns->refcnt );
1045  return 0;
1046 
1047  err_open_socket:
1048  err_question:
1049  err_encode:
1050  ref_put ( &dns->refcnt );
1051  err_alloc_dns:
1052  err_no_nameserver:
1053  return rc;
1054 }
size_t offset
Offset of search suffix within current query.
Definition: dns.c:489
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
uint16_t qdcount
Number of question records.
Definition: dns.h:71
#define ENXIO_NO_NAMESERVER
Definition: dns.c:62
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
A DNS packet header.
Definition: dns.h:65
#define DNS_FLAG_RD
Recursion desired flag.
Definition: dns.h:81
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.c:142
static void dns_timer_expired(struct retry_timer *timer, int fail)
Handle DNS (re)transmission timer expiry.
Definition: dns.c:642
#define SOCK_DGRAM
Definition: socket.h:29
#define DBGC(...)
Definition: compiler.h:505
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
void * data
Start of data.
Definition: dns.h:21
unsigned int count
Number of servers.
Definition: dns.c:78
static unsigned int dns_count
Total number of DNS servers.
Definition: dns.c:88
struct refcnt refcnt
Reference counter.
Definition: dns.c:457
#define DNS_TYPE_A
Type of a DNS "A" record.
Definition: dns.h:107
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct dns_name dns_search
The DNS search list.
Definition: dns.c:94
struct dns_request::@5 buf
Buffer for current query.
struct sockaddr sa
Definition: syslog.c:55
struct sockaddr sa
Definition: dns.c:467
#define DNS_TYPE_AAAA
Type of a DNS "AAAA" record.
Definition: dns.h:118
struct interface resolv
Name resolution interface.
Definition: dns.c:459
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
uint16_t flags
Flags.
Definition: dns.h:69
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:271
struct dns_header query
Query header.
Definition: dns.c:476
int dns_encode(const char *string, struct dns_name *name)
Encode a DNS name using RFC1035 encoding.
Definition: dns.c:103
A DNS request.
Definition: dns.c:455
char name[DNS_MAX_NAME_LEN]
Name buffer.
Definition: dns.c:478
struct interface socket
Data transfer interface.
Definition: dns.c:461
A DNS question.
Definition: dns.h:84
static struct interface_descriptor dns_socket_desc
DNS socket interface descriptor.
Definition: dns.c:955
struct dns_name search
Search list.
Definition: dns.c:491
struct retry_timer timer
Retry timer.
Definition: dns.c:463
uint16_t qtype
Initial query type.
Definition: dns.c:472
static struct interface_descriptor dns_resolv_desc
DNS resolver interface descriptor.
Definition: dns.c:965
int resolv(struct interface *resolv, const char *name, struct sockaddr *sa)
Start name resolution.
Definition: resolv.c:257
size_t len
Total length of data.
Definition: dns.h:25
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:190
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union dns_request::@4 address
Socket address to fill in with resolved address.
#define htons(value)
Definition: byteswap.h:135
static struct dns_server dns6
IPv6 DNS server list.
Definition: dns.c:85
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References dns_request::address, dns_request::buf, dns_server::count, dns_name::data, DBG, DBGC, dns6, dns_count, dns_encode(), DNS_FLAG_RD, dns_resolv_desc, dns_search, dns_socket_desc, dns_timer_expired(), DNS_TYPE_A, DNS_TYPE_AAAA, ENOMEM, ENXIO_NO_NAMESERVER, dns_header::flags, htons, intf_init(), intf_plug_plug(), dns_name::len, memcpy(), dns_request::name, name, NULL, dns_request::offset, offsetof, dns_header::qdcount, dns_request::qtype, dns_request::query, rc, ref_init, ref_put, dns_request::refcnt, dns_request::resolv, resolv(), sa, dns_request::sa, dns_request::search, SOCK_DGRAM, dns_request::socket, start_timer_nodelay(), strchr(), strerror(), dns_request::timer, xfer_open_socket(), and zalloc().

◆ __resolver()

struct resolver dns_resolver __resolver ( RESOLV_NORMAL  )

DNS name resolver.

◆ format_dnssl_setting()

static int format_dnssl_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
)
static

Format DNS search list setting.

Parameters
typeSetting type
rawRaw setting value
raw_lenLength of raw setting value
bufBuffer to contain formatted value
lenLength of buffer
Return values
lenLength of formatted value, or negative error

Definition at line 1079 of file dns.c.

1081  {
1082  struct dns_name name = {
1083  .data = ( ( void * ) raw ),
1084  .len = raw_len,
1085  };
1086  size_t remaining = len;
1087  size_t total = 0;
1088  int name_len;
1089 
1090  while ( name.offset < raw_len ) {
1091 
1092  /* Decode name */
1093  remaining = ( ( total < len ) ? ( len - total ) : 0 );
1094  name_len = dns_decode ( &name, ( buf + total ), remaining );
1095  if ( name_len < 0 )
1096  return name_len;
1097  total += name_len;
1098 
1099  /* Move to next name */
1100  name.offset = dns_skip_search ( &name );
1101 
1102  /* Add separator if applicable */
1103  if ( name.offset != raw_len ) {
1104  if ( total < len )
1105  buf[total] = ' ';
1106  total++;
1107  }
1108  }
1109 
1110  return total;
1111 }
const char * name
Definition: ath9k_hw.c:1984
An RFC1035-encoded DNS name.
Definition: dns.h:19
static size_t raw_len
Definition: base16.h:50
uint32_t len
Length.
Definition: ena.h:14
static int dns_skip_search(struct dns_name *name)
Skip RFC1035-encoded DNS name in search list.
Definition: dns.c:406
__be32 raw[7]
Definition: CIB_PRM.h:28
int dns_decode(struct dns_name *name, char *data, size_t len)
Decode RFC1035-encoded DNS name.
Definition: dns.c:219

References dns_decode(), dns_skip_search(), len, name, raw, and raw_len.

◆ __setting() [1/3]

const struct setting dns_setting __setting ( SETTING_IP4_EXTRA  ,
dns   
)

IPv4 DNS server setting.

◆ __setting() [2/3]

const struct setting dns6_setting __setting ( SETTING_IP6_EXTRA  ,
dns6   
)

IPv6 DNS server setting.

◆ __setting() [3/3]

const struct setting dnssl_setting __setting ( SETTING_IP_EXTRA  ,
dnssl   
)

DNS search list.

◆ apply_dns_servers()

static void apply_dns_servers ( void  )
static

Apply DNS server addresses.

Definition at line 1148 of file dns.c.

1148  {
1149  int len;
1150 
1151  /* Free existing server addresses */
1152  free ( dns4.data );
1153  free ( dns6.data );
1154  dns4.data = NULL;
1155  dns6.data = NULL;
1156  dns4.count = 0;
1157  dns6.count = 0;
1158 
1159  /* Fetch DNS server addresses */
1160  len = fetch_raw_setting_copy ( NULL, &dns_setting, &dns4.data );
1161  if ( len >= 0 )
1162  dns4.count = ( len / sizeof ( dns4.in[0] ) );
1163  len = fetch_raw_setting_copy ( NULL, &dns6_setting, &dns6.data );
1164  if ( len >= 0 )
1165  dns6.count = ( len / sizeof ( dns6.in6[0] ) );
1166  dns_count = ( dns4.count + dns6.count );
1167 }
static struct dns_server dns4
IPv4 DNS server list.
Definition: dns.c:82
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition: settings.c:825
struct in_addr * in
IPv4 addresses.
Definition: dns.c:71
unsigned int count
Number of servers.
Definition: dns.c:78
static unsigned int dns_count
Total number of DNS servers.
Definition: dns.c:88
void * data
Raw data.
Definition: dns.c:75
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct in6_addr * in6
IPv6 addresses.
Definition: dns.c:73
static struct dns_server dns6
IPv6 DNS server list.
Definition: dns.c:85

References dns_server::count, dns_server::data, dns4, dns6, dns_count, fetch_raw_setting_copy(), free, dns_server::in, dns_server::in6, len, and NULL.

Referenced by apply_dns_settings().

◆ apply_dns_search()

static void apply_dns_search ( void  )
static

Apply DNS search list.

Definition at line 1173 of file dns.c.

1173  {
1174  char *localdomain;
1175  int len;
1176 
1177  /* Free existing search list */
1178  free ( dns_search.data );
1179  memset ( &dns_search, 0, sizeof ( dns_search ) );
1180 
1181  /* Fetch DNS search list */
1182  len = fetch_raw_setting_copy ( NULL, &dnssl_setting, &dns_search.data );
1183  if ( len >= 0 ) {
1184  dns_search.len = len;
1185  return;
1186  }
1187 
1188  /* If no DNS search list exists, try to fetch the local domain */
1189  fetch_string_setting_copy ( NULL, &domain_setting, &localdomain );
1190  if ( localdomain ) {
1191  len = dns_encode ( localdomain, &dns_search );
1192  if ( len >= 0 ) {
1193  dns_search.data = malloc ( len );
1194  if ( dns_search.data ) {
1195  dns_search.len = len;
1196  dns_encode ( localdomain, &dns_search );
1197  }
1198  }
1199  free ( localdomain );
1200  return;
1201  }
1202 }
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition: settings.c:825
void * data
Start of data.
Definition: dns.h:21
static struct dns_name dns_search
The DNS search list.
Definition: dns.c:94
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:877
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
int dns_encode(const char *string, struct dns_name *name)
Encode a DNS name using RFC1035 encoding.
Definition: dns.c:103
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
uint32_t len
Length.
Definition: ena.h:14
size_t len
Total length of data.
Definition: dns.h:25
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
void * memset(void *dest, int character, size_t len) __nonnull

References dns_name::data, dns_encode(), dns_search, fetch_raw_setting_copy(), fetch_string_setting_copy(), free, len, dns_name::len, malloc(), memset(), and NULL.

Referenced by apply_dns_settings().

◆ apply_dns_settings()

static int apply_dns_settings ( void  )
static

Apply DNS settings.

Return values
rcReturn status code

Definition at line 1209 of file dns.c.

1209  {
1210  void *dbgcol = &dns_count;
1211 
1212  /* Fetch DNS server address */
1214  if ( DBG_EXTRA && ( dns_count != 0 ) ) {
1215  union {
1216  struct sockaddr sa;
1217  struct sockaddr_in sin;
1218  struct sockaddr_in6 sin6;
1219  } u;
1220  unsigned int i;
1221 
1222  DBGC2 ( dbgcol, "DNS servers:" );
1223  for ( i = 0 ; i < dns6.count ; i++ ) {
1224  u.sin6.sin6_family = AF_INET6;
1225  memcpy ( &u.sin6.sin6_addr, &dns6.in6[i],
1226  sizeof ( u.sin6.sin6_addr ) );
1227  DBGC2 ( dbgcol, " %s", sock_ntoa ( &u.sa ) );
1228  }
1229  for ( i = 0 ; i < dns4.count ; i++ ) {
1230  u.sin.sin_family = AF_INET;
1231  u.sin.sin_addr = dns4.in[i];
1232  DBGC2 ( dbgcol, " %s", sock_ntoa ( &u.sa ) );
1233  }
1234  DBGC2 ( dbgcol, "\n" );
1235  }
1236 
1237  /* Fetch DNS search list */
1238  apply_dns_search();
1239  if ( DBG_EXTRA && ( dns_search.len != 0 ) ) {
1240  struct dns_name name;
1241  int offset;
1242 
1243  DBGC2 ( dbgcol, "DNS search list:" );
1244  memcpy ( &name, &dns_search, sizeof ( name ) );
1245  while ( name.offset != name.len ) {
1246  DBGC2 ( dbgcol, " %s", dns_name ( &name ) );
1247  offset = dns_skip_search ( &name );
1248  if ( offset < 0 )
1249  break;
1250  name.offset = offset;
1251  }
1252  DBGC2 ( dbgcol, "\n" );
1253  }
1254 
1255  return 0;
1256 }
const char * name
Definition: ath9k_hw.c:1984
#define AF_INET6
IPv6 Internet addresses.
Definition: socket.h:64
static void apply_dns_servers(void)
Apply DNS server addresses.
Definition: dns.c:1148
static struct dns_server dns4
IPv4 DNS server list.
Definition: dns.c:82
struct in_addr * in
IPv4 addresses.
Definition: dns.c:71
struct sockaddr_in6 sin6
Definition: syslog.c:58
IPv4 socket address.
Definition: in.h:82
unsigned int count
Number of servers.
Definition: dns.c:78
static unsigned int dns_count
Total number of DNS servers.
Definition: dns.c:88
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct dns_name dns_search
The DNS search list.
Definition: dns.c:94
An RFC1035-encoded DNS name.
Definition: dns.h:19
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
struct sockaddr sa
Definition: syslog.c:55
Generalized socket address structure.
Definition: socket.h:96
static void apply_dns_search(void)
Apply DNS search list.
Definition: dns.c:1173
const char * sock_ntoa(struct sockaddr *sa)
Transcribe socket address.
Definition: socket.c:42
#define DBGC2(...)
Definition: compiler.h:522
static int dns_skip_search(struct dns_name *name)
Skip RFC1035-encoded DNS name in search list.
Definition: dns.c:406
union @17 u
IPv6 socket address.
Definition: in.h:115
#define DBG_EXTRA
Definition: compiler.h:319
struct sockaddr_in sin
Definition: syslog.c:57
size_t len
Total length of data.
Definition: dns.h:25
struct in6_addr * in6
IPv6 addresses.
Definition: dns.c:73
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
static struct dns_server dns6
IPv6 DNS server list.
Definition: dns.c:85

References AF_INET, AF_INET6, apply_dns_search(), apply_dns_servers(), dns_server::count, DBG_EXTRA, DBGC2, dns4, dns6, dns_count, dns_search, dns_skip_search(), dns_server::in, dns_server::in6, dns_name::len, memcpy(), name, offset, sa, sin, sin6, sock_ntoa(), and u.

Variable Documentation

◆ dns4

struct dns_server dns4
static

IPv4 DNS server list.

Definition at line 82 of file dns.c.

Referenced by apply_dns_servers(), apply_dns_settings(), and dns_send_packet().

◆ dns6

struct dns_server dns6
static

IPv6 DNS server list.

Definition at line 85 of file dns.c.

Referenced by apply_dns_servers(), apply_dns_settings(), dns_resolv(), and dns_send_packet().

◆ dns_count

unsigned int dns_count
static

Total number of DNS servers.

Definition at line 88 of file dns.c.

Referenced by apply_dns_servers(), apply_dns_settings(), dns_resolv(), and dns_send_packet().

◆ dns_index

unsigned int dns_index
static

Current DNS server index.

Definition at line 91 of file dns.c.

Referenced by dns_send_packet(), and dns_timer_expired().

◆ dns_search

struct dns_name dns_search
static

The DNS search list.

Definition at line 94 of file dns.c.

Referenced by apply_dns_search(), apply_dns_settings(), and dns_resolv().

◆ dns_socket_operations

struct interface_operation dns_socket_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void dns_xfer_close(struct dns_request *dns, int rc)
Receive new data.
Definition: dns.c:918
static int dns_xfer_deliver(struct dns_request *dns, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Receive new data.
Definition: dns.c:668
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193
A DNS request.
Definition: dns.c:455

DNS socket interface operations.

Definition at line 949 of file dns.c.

◆ dns_socket_desc

struct interface_descriptor dns_socket_desc
static
Initial value:
=
static struct interface_operation dns_socket_operations[]
DNS socket interface operations.
Definition: dns.c:949
A DNS request.
Definition: dns.c:455
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80

DNS socket interface descriptor.

Definition at line 955 of file dns.c.

Referenced by dns_resolv().

◆ dns_resolv_op

struct interface_operation dns_resolv_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void dns_done(struct dns_request *dns, int rc)
Mark DNS request as complete.
Definition: dns.c:502
static int dns_progress(struct dns_request *dns, struct job_progress *progress)
Report job progress.
Definition: dns.c:933
Job progress.
Definition: job.h:15
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
A DNS request.
Definition: dns.c:455

DNS resolver interface operations.

Definition at line 959 of file dns.c.

◆ dns_resolv_desc

struct interface_descriptor dns_resolv_desc
static
Initial value:
=
A DNS request.
Definition: dns.c:455
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
static struct interface_operation dns_resolv_op[]
DNS resolver interface operations.
Definition: dns.c:959
int resolv(struct interface *resolv, const char *name, struct sockaddr *sa)
Start name resolution.
Definition: resolv.c:257

DNS resolver interface descriptor.

Definition at line 965 of file dns.c.

Referenced by dns_resolv().

◆ __setting_type

const struct setting_type setting_type_dnssl __setting_type
Initial value:
= {
.name = "dnssl",
}
static int format_dnssl_setting(const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
Format DNS search list setting.
Definition: dns.c:1079

A DNS search list setting type.

A string setting type.

Definition at line 1114 of file dns.c.

◆ __settings_applicator

struct settings_applicator dns_applicator __settings_applicator
Initial value:
= {
}
static int apply_dns_settings(void)
Apply DNS settings.
Definition: dns.c:1209

DNS settings applicator.

Definition at line 1259 of file dns.c.