iPXE
open.c File Reference

Data transfer interface opening. More...

#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <ipxe/xfer.h>
#include <ipxe/uri.h>
#include <ipxe/socket.h>
#include <ipxe/open.h>

Go to the source code of this file.

Functions

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

Detailed Description

Data transfer interface opening.

Definition in file open.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ 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 48 of file open.c.

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

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 68 of file open.c.

68 {
69 struct uri_opener *opener;
70 struct uri *resolved_uri;
71 int rc;
72
73 /* Resolve URI */
74 resolved_uri = resolve_uri ( cwuri, uri );
75 if ( ! resolved_uri ) {
76 rc = -ENOMEM;
77 goto err_resolve_uri;
78 }
79
80 /* Check that URI has a scheme */
81 if ( ! uri_is_absolute ( resolved_uri ) ) {
82 DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
83 "non-absolute URI\n", INTF_DBG ( intf ) );
84 rc = -ENOTSUP;
85 goto err_absolute;
86 }
87
88 /* Find opener which supports this URI scheme */
89 opener = xfer_uri_opener ( resolved_uri->scheme );
90 if ( ! opener ) {
91 DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
92 "unsupported URI scheme \"%s\"\n",
93 INTF_DBG ( intf ), resolved_uri->scheme );
94 rc = -ENOTSUP;
95 goto err_opener;
96 }
97
98 /* Call opener */
99 DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening %s URI\n",
100 INTF_DBG ( intf ), resolved_uri->scheme );
101 if ( ( rc = opener->open ( intf, resolved_uri ) ) != 0 ) {
102 DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " could not open: "
103 "%s\n", INTF_DBG ( intf ), strerror ( rc ) );
104 goto err_open;
105 }
106
107 err_open:
108 err_opener:
109 err_absolute:
110 uri_put ( resolved_uri );
111 err_resolve_uri:
112 return rc;
113}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
struct uri * cwuri
Current working URI.
Definition cwuri.c:39
#define DBGC(...)
Definition compiler.h:530
#define ENOMEM
Not enough space.
Definition errno.h:578
#define ENOTSUP
Operation not supported.
Definition errno.h:633
#define INTF_DBG(intf)
printf() arguments for representing an object interface
Definition interface.h:293
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition interface.h:282
#define INTF_FMT
printf() format string for INTF_DBG()
Definition interface.h:285
struct uri_opener * xfer_uri_opener(const char *scheme)
Find opener for URI scheme.
Definition open.c:48
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
int(* open)(struct interface *intf, struct uri *uri)
Open URI.
Definition open.h:61
A Uniform Resource Identifier.
Definition uri.h:65
const char * scheme
Scheme.
Definition uri.h:69
struct uri * resolve_uri(const struct uri *base_uri, struct uri *relative_uri)
Resolve base+relative URI.
Definition uri.c:696
static int uri_is_absolute(const struct uri *uri)
URI is an absolute URI.
Definition uri.h:136
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition uri.h:206

References cwuri, DBGC, ENOMEM, ENOTSUP, INTF_COL, INTF_DBG, INTF_FMT, uri_opener::open, rc, resolve_uri(), uri::scheme, strerror(), uri_is_absolute(), 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 125 of file open.c.

126 {
127 struct uri *uri;
128 int rc;
129
130 DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening URI %s\n",
131 INTF_DBG ( intf ), uri_string );
132
133 uri = parse_uri ( uri_string );
134 if ( ! uri )
135 return -ENOMEM;
136
137 rc = xfer_open_uri ( intf, uri );
138
139 uri_put ( uri );
140 return rc;
141}
int xfer_open_uri(struct interface *intf, struct uri *uri)
Open URI.
Definition open.c:68
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition uri.c:297

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_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 152 of file open.c.

153 {
154 struct socket_opener *opener;
155
156 DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening (%s,%s) socket\n",
158 socket_family_name ( peer->sa_family ) );
159
161 if ( opener->semantics == semantics )
162 return opener->open ( intf, peer, local );
163 }
164
165 DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
166 "unsupported socket type (%s,%s)\n",
168 socket_family_name ( peer->sa_family ) );
169 return -ENOTSUP;
170}
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:1
#define SOCKET_OPENERS
Socket opener table.
Definition open.h:86
static const char * socket_semantics_name(int semantics)
Name communication semantics.
Definition socket.h:46
static const char * socket_family_name(int family)
Name address family.
Definition socket.h:76
A socket opener.
Definition open.h:71
int(* open)(struct interface *intf, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition open.h:81
int semantics
Communication semantics (e.g.
Definition open.h:73

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 180 of file open.c.

180 {
181 switch ( type ) {
182 case LOCATION_URI_STRING: {
183 const char *uri_string = va_arg ( args, const char * );
184
185 return xfer_open_uri_string ( intf, uri_string ); }
186 case LOCATION_URI: {
187 struct uri *uri = va_arg ( args, struct uri * );
188
189 return xfer_open_uri ( intf, uri ); }
190 case LOCATION_SOCKET: {
191 int semantics = va_arg ( args, int );
192 struct sockaddr *peer = va_arg ( args, struct sockaddr * );
193 struct sockaddr *local = va_arg ( args, struct sockaddr * );
194
195 return xfer_open_socket ( intf, semantics, peer, local ); }
196 default:
197 DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to "
198 "open unsupported location type %d\n",
199 INTF_DBG ( intf ), type );
200 return -ENOTSUP;
201 }
202}
uint32_t type
Operating system type.
Definition ena.h:1
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition open.c:152
int xfer_open_uri_string(struct interface *intf, const char *uri_string)
Open URI string.
Definition open.c:125
@ LOCATION_SOCKET
Location is a socket.
Definition open.h:44
@ LOCATION_URI
Location is a URI.
Definition open.h:28
@ LOCATION_URI_STRING
Location is a URI string.
Definition open.h:35
#define va_arg(ap, type)
Definition stdarg.h:9
Generalized socket address structure.
Definition socket.h:97

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 212 of file open.c.

212 {
213 va_list args;
214 int rc;
215
216 va_start ( args, type );
217 rc = xfer_vopen ( intf, type, args );
218 va_end ( args );
219 return rc;
220}
int xfer_vopen(struct interface *intf, int type, va_list args)
Open location.
Definition open.c:180
#define va_end(ap)
Definition stdarg.h:10
#define va_start(ap, last)
Definition stdarg.h:8
__builtin_va_list va_list
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 234 of file open.c.

234 {
235
236 /* Close existing connection */
237 intf_restart ( intf, 0 );
238
239 /* Open new location */
240 return xfer_vopen ( intf, type, args );
241}
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition interface.c:344

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

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