iPXE
Data Structures | Macros | Functions
resolv.h File Reference

Name resolution. More...

#include <ipxe/interface.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  resolver
 A name resolver. More...
 

Macros

#define RESOLV_NUMERIC   01
 Numeric resolver priority. More...
 
#define RESOLV_NORMAL   02
 Normal resolver priority. More...
 
#define RESOLVERS   __table ( struct resolver, "resolvers" )
 Resolvers table. More...
 
#define __resolver(resolv_order)   __table_entry ( RESOLVERS, resolv_order )
 Register as a name resolver. More...
 
#define resolv_done_TYPE(object_type)   typeof ( void ( object_type, struct sockaddr *sa ) )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void resolv_done (struct interface *intf, struct sockaddr *sa)
 Name resolved. More...
 
int resolv (struct interface *resolv, const char *name, struct sockaddr *sa)
 Start name resolution. More...
 

Detailed Description

Name resolution.

Definition in file resolv.h.

Macro Definition Documentation

◆ RESOLV_NUMERIC

#define RESOLV_NUMERIC   01

Numeric resolver priority.

Definition at line 33 of file resolv.h.

◆ RESOLV_NORMAL

#define RESOLV_NORMAL   02

Normal resolver priority.

Definition at line 36 of file resolv.h.

◆ RESOLVERS

#define RESOLVERS   __table ( struct resolver, "resolvers" )

Resolvers table.

Definition at line 39 of file resolv.h.

◆ __resolver

#define __resolver (   resolv_order)    __table_entry ( RESOLVERS, resolv_order )

Register as a name resolver.

Definition at line 42 of file resolv.h.

◆ resolv_done_TYPE

#define resolv_done_TYPE (   object_type)    typeof ( void ( object_type, struct sockaddr *sa ) )

Definition at line 45 of file resolv.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ resolv_done()

void resolv_done ( struct interface intf,
struct sockaddr sa 
)

Name resolved.

Parameters
intfObject interface
saCompleted socket address (if successful)

Definition at line 55 of file resolv.c.

55  {
56  struct interface *dest;
57  resolv_done_TYPE ( void * ) *op =
58  intf_get_dest_op ( intf, resolv_done, &dest );
59  void *object = intf_object ( dest );
60 
61  DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " resolv_done\n",
62  INTF_INTF_DBG ( intf, dest ) );
63 
64  if ( op ) {
65  op ( object, sa );
66  } else {
67  /* Default is to ignore resolutions */
68  }
69 
70  intf_put ( dest );
71 }
#define INTF_INTF_FMT
printf() format string for INTF_INTF_DBG()
Definition: interface.h:240
struct sockaddr sa
Definition: dns.c:68
void resolv_done(struct interface *intf, struct sockaddr *sa)
Name resolved.
Definition: resolv.c:55
#define INTF_INTF_DBG(intf, dest)
printf() arguments for representing an object interface pair
Definition: interface.h:249
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:226
#define DBGC(...)
Definition: compiler.h:505
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:154
An object interface.
Definition: interface.h:109
static void * dest
Definition: strings.h:176
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:144
#define resolv_done_TYPE(object_type)
Definition: resolv.h:45
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:214

References DBGC, dest, INTF_COL, intf_get_dest_op, INTF_INTF_DBG, INTF_INTF_FMT, intf_object(), intf_put(), op, resolv_done(), resolv_done_TYPE, and sa.

Referenced by dns_resolved(), numeric_step(), and resolv_done().

◆ resolv()

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

Start name resolution.

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

Definition at line 257 of file resolv.c.

258  {
259  struct resolv_mux *mux;
260  size_t name_len = ( strlen ( name ) + 1 );
261  int rc;
262 
263  /* Allocate and initialise structure */
264  mux = zalloc ( sizeof ( *mux ) + name_len );
265  if ( ! mux )
266  return -ENOMEM;
267  ref_init ( &mux->refcnt, NULL );
268  intf_init ( &mux->parent, &resmux_parent_desc, &mux->refcnt );
269  intf_init ( &mux->child, &resmux_child_desc, &mux->refcnt );
270  mux->resolver = table_start ( RESOLVERS );
271  if ( sa )
272  memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
273  memcpy ( mux->name, name, name_len );
274 
275  DBGC ( mux, "RESOLV %p attempting to resolve \"%s\"\n", mux, name );
276 
277  /* Start first resolver in chain. There will always be at
278  * least one resolver (the numeric resolver), so no need to
279  * check for the zero-resolvers-available case.
280  */
281  if ( ( rc = resmux_try ( mux ) ) != 0 )
282  goto err;
283 
284  /* Attach parent interface, mortalise self, and return */
285  intf_plug_plug ( &mux->parent, resolv );
286  ref_put ( &mux->refcnt );
287  return 0;
288 
289  err:
290  ref_put ( &mux->refcnt );
291  return rc;
292 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
struct resolver * resolver
Current child resolver.
Definition: resolv.c:149
struct sockaddr sa
Definition: dns.c:68
#define table_start(table)
Get start of linker table.
Definition: tables.h:271
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
#define DBGC(...)
Definition: compiler.h:505
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
A name resolution multiplexer.
Definition: resolv.c:140
struct sockaddr sa
Socket address to complete.
Definition: resolv.c:152
struct interface parent
Parent name resolution interface.
Definition: resolv.c:144
static int resmux_try(struct resolv_mux *mux)
Try current child name resolver.
Definition: resolv.c:166
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
char name[0]
Name to be resolved.
Definition: resolv.c:157
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static struct interface_descriptor resmux_child_desc
Name resolution multiplexer child interface descriptor.
Definition: resolv.c:235
size_t strlen(const char *src)
Get length of string.
Definition: string.c:213
struct refcnt refcnt
Reference counter.
Definition: resolv.c:142
int resolv(struct interface *resolv, const char *name, struct sockaddr *sa)
Start name resolution.
Definition: resolv.c:257
static struct interface_descriptor resmux_parent_desc
Name resolution multiplexer parent interface descriptor.
Definition: resolv.c:245
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
struct interface child
Child name resolution interface.
Definition: resolv.c:147
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define RESOLVERS
Resolvers table.
Definition: resolv.h:39
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References resolv_mux::child, DBGC, ENOMEM, intf_init(), intf_plug_plug(), memcpy(), resolv_mux::name, name, NULL, resolv_mux::parent, rc, ref_init, ref_put, resolv_mux::refcnt, resmux_child_desc, resmux_parent_desc, resmux_try(), resolv(), resolv_mux::resolver, RESOLVERS, resolv_mux::sa, sa, strlen(), table_start, and zalloc().

Referenced by comboot_resolv(), dns_resolv(), numeric_resolv(), resolv(), resolv_setting(), and xfer_open_named_socket().