iPXE
Data Structures | Macros | Enumerations | Functions
open.h File Reference

Data transfer interface opening. More...

#include <stdarg.h>
#include <ipxe/tables.h>
#include <ipxe/socket.h>

Go to the source code of this file.

Data Structures

struct  uri_opener
 A URI opener. More...
 
struct  socket_opener
 A socket opener. More...
 

Macros

#define URI_OPENERS   __table ( struct uri_opener, "uri_openers" )
 URI opener table. More...
 
#define __uri_opener   __table_entry ( URI_OPENERS, 01 )
 Register a URI opener. More...
 
#define SOCKET_OPENERS   __table ( struct socket_opener, "socket_openers" )
 Socket opener table. More...
 
#define __socket_opener   __table_entry ( SOCKET_OPENERS, 01 )
 Register a socket opener. More...
 

Enumerations

enum  { LOCATION_URI = 1, LOCATION_URI_STRING, LOCATION_SOCKET }
 Location types. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
struct uri_openerxfer_uri_opener (const char *scheme)
 Find opener for URI scheme. More...
 
int xfer_open_uri (struct interface *intf, struct uri *uri)
 Open URI. More...
 
int xfer_open_uri_string (struct interface *intf, const char *uri_string)
 Open URI string. More...
 
int xfer_open_named_socket (struct interface *intf, int semantics, struct sockaddr *peer, const char *name, struct sockaddr *local)
 Open named socket. More...
 
int xfer_open_socket (struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
 Open socket. More...
 
int xfer_vopen (struct interface *intf, int type, va_list args)
 Open location. More...
 
int xfer_open (struct interface *intf, int type,...)
 Open location. More...
 
int xfer_vreopen (struct interface *intf, int type, va_list args)
 Reopen location. More...
 

Detailed Description

Data transfer interface opening.

Definition in file open.h.

Macro Definition Documentation

◆ URI_OPENERS

#define URI_OPENERS   __table ( struct uri_opener, "uri_openers" )

URI opener table.

Definition at line 64 of file open.h.

◆ __uri_opener

struct uri_opener mtftp_uri_opener __uri_opener   __table_entry ( URI_OPENERS, 01 )

Register a URI opener.

MTFTP URI opener.

TFTM URI opener.

Definition at line 67 of file open.h.

◆ SOCKET_OPENERS

#define SOCKET_OPENERS   __table ( struct socket_opener, "socket_openers" )

Socket opener table.

Definition at line 85 of file open.h.

◆ __socket_opener

#define __socket_opener   __table_entry ( SOCKET_OPENERS, 01 )

Register a socket opener.

Definition at line 88 of file open.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Location types.

Enumerator
LOCATION_URI 

Location is a URI.

   Parameter list for open() is:

   struct uri *uri;
LOCATION_URI_STRING 

Location is a URI string.

   Parameter list for open() is:

   const char *uri_string;
LOCATION_SOCKET 

Location is a socket.

   Parameter list for open() is:

   int semantics;
   struct sockaddr *peer;
   struct sockaddr *local;

Definition at line 20 of file open.h.

20  {
21  /** Location is a URI
22  *
23  * Parameter list for open() is:
24  *
25  * struct uri *uri;
26  */
27  LOCATION_URI = 1,
28  /** Location is a URI string
29  *
30  * Parameter list for open() is:
31  *
32  * const char *uri_string;
33  */
35  /** Location is a socket
36  *
37  * Parameter list for open() is:
38  *
39  * int semantics;
40  * struct sockaddr *peer;
41  * struct sockaddr *local;
42  */
44 };
Location is a socket.
Definition: open.h:43
Location is a URI string.
Definition: open.h:34
Location is a URI.
Definition: open.h:27

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ xfer_uri_opener()

struct uri_opener* xfer_uri_opener ( const char *  scheme)

Find opener for URI scheme.

Parameters
schemeURI scheme
Return values
openerOpener, or NULL

Definition at line 47 of file open.c.

47  {
48  struct uri_opener *opener;
49 
50  for_each_table_entry ( opener, URI_OPENERS ) {
51  if ( strcasecmp ( scheme, opener->scheme ) == 0 )
52  return opener;
53  }
54  return NULL;
55 }
#define URI_OPENERS
URI opener table.
Definition: open.h:64
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
const char * scheme
URI protocol name.
Definition: open.h:53
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
A URI opener.
Definition: open.h:47
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References for_each_table_entry, NULL, uri_opener::scheme, strcasecmp(), and URI_OPENERS.

Referenced by netboot(), and xfer_open_uri().

◆ xfer_open_uri()

int xfer_open_uri ( struct interface intf,
struct uri uri 
)

Open URI.

Parameters
intfData transfer interface
uriURI
Return values
rcReturn status code

The URI will be regarded as being relative to the current working URI (see churi()).

Definition at line 67 of file open.c.

67  {
68  struct uri_opener *opener;
69  struct uri *resolved_uri;
70  int rc;
71 
72  /* Resolve URI */
73  resolved_uri = resolve_uri ( cwuri, uri );
74  if ( ! resolved_uri ) {
75  rc = -ENOMEM;
76  goto err_resolve_uri;
77  }
78 
79  /* Find opener which supports this URI scheme */
80  opener = xfer_uri_opener ( resolved_uri->scheme );
81  if ( ! opener ) {
82  DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
83  "unsupported URI scheme \"%s\"\n",
84  INTF_DBG ( intf ), resolved_uri->scheme );
85  rc = -ENOTSUP;
86  goto err_opener;
87  }
88 
89  /* Call opener */
90  DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening %s URI\n",
91  INTF_DBG ( intf ), resolved_uri->scheme );
92  if ( ( rc = opener->open ( intf, resolved_uri ) ) != 0 ) {
93  DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " could not open: "
94  "%s\n", INTF_DBG ( intf ), strerror ( rc ) );
95  goto err_open;
96  }
97 
98  err_open:
99  err_opener:
100  uri_put ( resolved_uri );
101  err_resolve_uri:
102  return rc;
103 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define INTF_DBG(intf)
printf() arguments for representing an object interface
Definition: interface.h:292
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:281
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define ENOMEM
Not enough space.
Definition: errno.h:534
const char * scheme
Scheme.
Definition: uri.h:68
int(* open)(struct interface *intf, struct uri *uri)
Open URI.
Definition: open.h:60
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A Uniform Resource Identifier.
Definition: uri.h:64
struct uri_opener * xfer_uri_opener(const char *scheme)
Find opener for URI scheme.
Definition: open.c:47
struct uri * resolve_uri(const struct uri *base_uri, struct uri *relative_uri)
Resolve base+relative URI.
Definition: uri.c:694
struct uri * cwuri
Current working URI.
Definition: cwuri.c:38
A URI opener.
Definition: open.h:47
#define INTF_FMT
printf() format string for INTF_DBG()
Definition: interface.h:284

References cwuri, DBGC, ENOMEM, ENOTSUP, INTF_COL, INTF_DBG, INTF_FMT, uri_opener::open, rc, resolve_uri(), uri::scheme, strerror(), uri_put(), and xfer_uri_opener().

Referenced by create_downloader(), efi_pxe_tftp_open(), pxe_tftp_open(), sanpath_open(), xfer_open_uri_string(), and xfer_vopen().

◆ xfer_open_uri_string()

int xfer_open_uri_string ( struct interface intf,
const char *  uri_string 
)

Open URI string.

Parameters
intfData transfer interface
uri_stringURI string (e.g. "http://ipxe.org/kernel")
Return values
rcReturn status code

The URI will be regarded as being relative to the current working URI (see churi()).

Definition at line 115 of file open.c.

116  {
117  struct uri *uri;
118  int rc;
119 
120  DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening URI %s\n",
121  INTF_DBG ( intf ), uri_string );
122 
123  uri = parse_uri ( uri_string );
124  if ( ! uri )
125  return -ENOMEM;
126 
127  rc = xfer_open_uri ( intf, uri );
128 
129  uri_put ( uri );
130  return rc;
131 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define INTF_DBG(intf)
printf() arguments for representing an object interface
Definition: interface.h:292
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
int xfer_open_uri(struct interface *intf, struct uri *uri)
Open URI.
Definition: open.c:67
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:281
#define DBGC(...)
Definition: compiler.h:505
#define ENOMEM
Not enough space.
Definition: errno.h:534
A Uniform Resource Identifier.
Definition: uri.h:64
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition: uri.c:296
#define INTF_FMT
printf() format string for INTF_DBG()
Definition: interface.h:284

References DBGC, ENOMEM, INTF_COL, INTF_DBG, INTF_FMT, parse_uri(), rc, uri_put(), and xfer_open_uri().

Referenced by open(), validator_start_download(), validator_start_ocsp(), and xfer_vopen().

◆ xfer_open_named_socket()

int xfer_open_named_socket ( struct interface xfer,
int  semantics,
struct sockaddr peer,
const char *  name,
struct sockaddr local 
)

Open named socket.

Parameters
semanticsCommunication semantics (e.g. SOCK_STREAM)
peerPeer socket address to complete
nameName to resolve
localLocal socket address, or NULL
Return values
rcReturn status code

Definition at line 402 of file resolv.c.

404  {
405  struct named_socket *named;
406  int rc;
407 
408  /* Allocate and initialise structure */
409  named = zalloc ( sizeof ( *named ) );
410  if ( ! named )
411  return -ENOMEM;
412  ref_init ( &named->refcnt, NULL );
413  intf_init ( &named->xfer, &named_xfer_desc, &named->refcnt );
414  intf_init ( &named->resolv, &named_resolv_desc, &named->refcnt );
415  named->semantics = semantics;
416  if ( local ) {
417  memcpy ( &named->local, local, sizeof ( named->local ) );
418  named->have_local = 1;
419  }
420 
421  DBGC ( named, "NAMED %p opening \"%s\"\n",
422  named, name );
423 
424  /* Start name resolution */
425  if ( ( rc = resolv ( &named->resolv, name, peer ) ) != 0 )
426  goto err;
427 
428  /* Attach parent interface, mortalise self, and return */
429  intf_plug_plug ( &named->xfer, xfer );
430  ref_put ( &named->refcnt );
431  return 0;
432 
433  err:
434  ref_put ( &named->refcnt );
435  return rc;
436 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
struct interface xfer
Data transfer interface.
Definition: resolv.c:306
int semantics
Communication semantics (e.g.
Definition: resolv.c:310
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct refcnt refcnt
Reference counter.
Definition: resolv.c:304
int have_local
Stored local socket address exists.
Definition: resolv.c:314
#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
static struct interface_descriptor named_resolv_desc
Named socket opener resolver interface descriptor.
Definition: resolv.c:389
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct sockaddr local
Stored local socket address, if applicable.
Definition: resolv.c:312
A named socket.
Definition: resolv.c:302
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct interface resolv
Name resolution interface.
Definition: resolv.c:308
int resolv(struct interface *resolv, const char *name, struct sockaddr *sa)
Start name resolution.
Definition: resolv.c:257
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12
static struct interface_descriptor named_xfer_desc
Named socket opener data transfer interface descriptor.
Definition: resolv.c:347
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References DBGC, ENOMEM, named_socket::have_local, intf_init(), intf_plug_plug(), named_socket::local, memcpy(), name, named_resolv_desc, named_xfer_desc, NULL, peer, rc, ref_init, ref_put, named_socket::refcnt, named_socket::resolv, resolv(), named_socket::semantics, named_socket::xfer, and zalloc().

Referenced by apply_syslogs_settings(), create_pinger(), ftp_open(), http_connect(), iscsi_open_connection(), nfs_connect(), slam_open(), start_ntp(), tcp_open_uri(), tftp_reopen(), and udp_open_uri().

◆ xfer_open_socket()

int xfer_open_socket ( struct interface intf,
int  semantics,
struct sockaddr peer,
struct sockaddr local 
)

Open socket.

Parameters
intfData transfer interface
semanticsCommunication semantics (e.g. SOCK_STREAM)
peerPeer socket address
localLocal socket address, or NULL
Return values
rcReturn status code

Definition at line 142 of file open.c.

143  {
144  struct socket_opener *opener;
145 
146  DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening (%s,%s) socket\n",
148  socket_family_name ( peer->sa_family ) );
149 
151  if ( opener->semantics == semantics )
152  return opener->open ( intf, peer, local );
153  }
154 
155  DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
156  "unsupported socket type (%s,%s)\n",
158  socket_family_name ( peer->sa_family ) );
159  return -ENOTSUP;
160 }
static const char * socket_semantics_name(int semantics)
Name communication semantics.
Definition: socket.h:45
#define INTF_DBG(intf)
printf() arguments for representing an object interface
Definition: interface.h:292
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:281
#define DBGC(...)
Definition: compiler.h:505
int semantics
Communication semantics (e.g.
Definition: open.h:72
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define SOCKET_OPENERS
Socket opener table.
Definition: open.h:85
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
static const char * socket_family_name(int family)
Name address family.
Definition: socket.h:75
int(* open)(struct interface *intf, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.h:80
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12
#define INTF_FMT
printf() format string for INTF_DBG()
Definition: interface.h:284
A socket opener.
Definition: open.h:70

References DBGC, ENOTSUP, for_each_table_entry, INTF_COL, INTF_DBG, INTF_FMT, socket_opener::open, peer, socket_opener::semantics, socket_family_name(), SOCKET_OPENERS, and socket_semantics_name().

Referenced by apply_syslog_settings(), dns_resolv(), ftp_reply(), peerdisc_socket_open(), slam_open(), start_dhcp(), start_dhcpv6(), start_pxebs(), tftp_reopen_mc(), and xfer_vopen().

◆ xfer_vopen()

int xfer_vopen ( struct interface intf,
int  type,
va_list  args 
)

Open location.

Parameters
intfData transfer interface
typeLocation type
argsRemaining arguments depend upon location type
Return values
rcReturn status code

Definition at line 170 of file open.c.

170  {
171  switch ( type ) {
172  case LOCATION_URI_STRING: {
173  const char *uri_string = va_arg ( args, const char * );
174 
175  return xfer_open_uri_string ( intf, uri_string ); }
176  case LOCATION_URI: {
177  struct uri *uri = va_arg ( args, struct uri * );
178 
179  return xfer_open_uri ( intf, uri ); }
180  case LOCATION_SOCKET: {
181  int semantics = va_arg ( args, int );
182  struct sockaddr *peer = va_arg ( args, struct sockaddr * );
183  struct sockaddr *local = va_arg ( args, struct sockaddr * );
184 
185  return xfer_open_socket ( intf, semantics, peer, local ); }
186  default:
187  DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to "
188  "open unsupported location type %d\n",
189  INTF_DBG ( intf ), type );
190  return -ENOTSUP;
191  }
192 }
#define INTF_DBG(intf)
printf() arguments for representing an object interface
Definition: interface.h:292
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.c:142
int xfer_open_uri(struct interface *intf, struct uri *uri)
Open URI.
Definition: open.c:67
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:281
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define va_arg(ap, type)
Definition: stdarg.h:8
Generalized socket address structure.
Definition: socket.h:96
Location is a socket.
Definition: open.h:43
Location is a URI string.
Definition: open.h:34
Location is a URI.
Definition: open.h:27
uint32_t type
Operating system type.
Definition: ena.h:12
A Uniform Resource Identifier.
Definition: uri.h:64
struct mschapv2_challenge peer
Peer challenge.
Definition: mschapv2.h:12
int xfer_open_uri_string(struct interface *intf, const char *uri_string)
Open URI string.
Definition: open.c:115
#define INTF_FMT
printf() format string for INTF_DBG()
Definition: interface.h:284

References DBGC, ENOTSUP, INTF_COL, INTF_DBG, INTF_FMT, LOCATION_SOCKET, LOCATION_URI, LOCATION_URI_STRING, peer, type, va_arg, xfer_open_socket(), xfer_open_uri(), and xfer_open_uri_string().

Referenced by xfer_open(), and xfer_vreopen().

◆ xfer_open()

int xfer_open ( struct interface intf,
int  type,
  ... 
)

Open location.

Parameters
intfData transfer interface
typeLocation type
...Remaining arguments depend upon location type
Return values
rcReturn status code

Definition at line 202 of file open.c.

202  {
203  va_list args;
204  int rc;
205 
206  va_start ( args, type );
207  rc = xfer_vopen ( intf, type, args );
208  va_end ( args );
209  return rc;
210 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
uint32_t type
Operating system type.
Definition: ena.h:12
__builtin_va_list va_list
Definition: stdarg.h:6
int xfer_vopen(struct interface *intf, int type, va_list args)
Open location.
Definition: open.c:170
#define va_start(ap, last)
Definition: stdarg.h:7

References rc, type, va_end, va_start, and xfer_vopen().

Referenced by efi_download_start().

◆ xfer_vreopen()

int xfer_vreopen ( struct interface intf,
int  type,
va_list  args 
)

Reopen location.

Parameters
intfData transfer interface
typeLocation type
argsRemaining arguments depend upon location type
Return values
rcReturn status code

This will close the existing connection and open a new connection using xfer_vopen(). It is intended to be used as a .vredirect method handler.

Definition at line 224 of file open.c.

224  {
225 
226  /* Close existing connection */
227  intf_restart ( intf, 0 );
228 
229  /* Open new location */
230  return xfer_vopen ( intf, type, args );
231 }
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:343
uint32_t type
Operating system type.
Definition: ena.h:12
int xfer_vopen(struct interface *intf, int type, va_list args)
Open location.
Definition: open.c:170

References intf_restart(), type, and xfer_vopen().

Referenced by downloader_vredirect(), iscsi_vredirect(), and xfer_vredirect().