iPXE
Data Structures | Defines | 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...

Defines

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

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.
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_named_socket (struct interface *intf, int semantics, struct sockaddr *peer, const char *name, struct sockaddr *local)
 Open named socket.
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.h.


Define Documentation

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

URI opener table.

Definition at line 64 of file open.h.

Referenced by xfer_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.

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

Socket opener table.

Definition at line 87 of file open.h.

Referenced by xfer_open_socket().

struct socket_opener udp_ipv6_socket_opener __socket_opener   __table_entry ( SOCKET_OPENERS, 01 )

Register a socket opener.

UDP IPv6 socket opener.

TCP IPv6 socket opener.

Ping IPv6 socket opener.

Definition at line 90 of file open.h.


Enumeration Type Documentation

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.

     {
        /** Location is a URI
         *
         * Parameter list for open() is:
         *
         * struct uri *uri;
         */
        LOCATION_URI = 1,
        /** Location is a URI string
         *
         * Parameter list for open() is:
         *
         * const char *uri_string;
         */
        LOCATION_URI_STRING,
        /** Location is a socket
         *
         * Parameter list for open() is:
         *
         * int semantics;
         * struct sockaddr *peer;
         * struct sockaddr *local;
         */
        LOCATION_SOCKET,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
struct uri_opener* xfer_uri_opener ( const char *  scheme) [read]

Find opener for URI scheme.

Parameters:
schemeURI scheme
Return values:
openerOpener, or NULL

Definition at line 46 of file open.c.

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

Referenced by netboot(), and xfer_open_uri().

                                                           {
        struct uri_opener *opener;

        for_each_table_entry ( opener, URI_OPENERS ) {
                if ( strcmp ( scheme, opener->scheme ) == 0 )
                        return opener;
        }
        return NULL;
}
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 66 of file open.c.

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().

                                                              {
        struct uri_opener *opener;
        struct uri *resolved_uri;
        int rc;

        /* Resolve URI */
        resolved_uri = resolve_uri ( cwuri, uri );
        if ( ! resolved_uri ) {
                rc = -ENOMEM;
                goto err_resolve_uri;
        }

        /* Find opener which supports this URI scheme */
        opener = xfer_uri_opener ( resolved_uri->scheme );
        if ( ! opener ) {
                DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
                       "unsupported URI scheme \"%s\"\n",
                       INTF_DBG ( intf ), resolved_uri->scheme );
                rc = -ENOTSUP;
                goto err_opener;
        }

        /* Call opener */
        DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening %s URI\n",
               INTF_DBG ( intf ), resolved_uri->scheme );
        if ( ( rc = opener->open ( intf, resolved_uri ) ) != 0 ) {
                DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " could not open: "
                       "%s\n", INTF_DBG ( intf ), strerror ( rc ) );
                goto err_open;
        }

 err_open:
 err_opener:
        uri_put ( resolved_uri );
 err_resolve_uri:
        return rc;
}
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 114 of file open.c.

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().

                                                    {
        struct uri *uri;
        int rc;

        DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening URI %s\n",
               INTF_DBG ( intf ), uri_string );

        uri = parse_uri ( uri_string );
        if ( ! uri )
                return -ENOMEM;

        rc = xfer_open_uri ( intf, uri );

        uri_put ( uri );
        return rc;
}
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.

References DBGC, ENOMEM, named_socket::have_local, intf_init(), intf_plug_plug(), named_socket::local, memcpy(), NULL, rc, ref_init, ref_put, named_socket::refcnt, resolv(), named_socket::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().

                                                      {
        struct named_socket *named;
        int rc;

        /* Allocate and initialise structure */
        named = zalloc ( sizeof ( *named ) );
        if ( ! named )
                return -ENOMEM;
        ref_init ( &named->refcnt, NULL );
        intf_init ( &named->xfer, &named_xfer_desc, &named->refcnt );
        intf_init ( &named->resolv, &named_resolv_desc, &named->refcnt );
        named->semantics = semantics;
        if ( local ) {
                memcpy ( &named->local, local, sizeof ( named->local ) );
                named->have_local = 1;
        }

        DBGC ( named, "NAMED %p opening \"%s\"\n",
               named, name );

        /* Start name resolution */
        if ( ( rc = resolv ( &named->resolv, name, peer ) ) != 0 )
                goto err;

        /* Attach parent interface, mortalise self, and return */
        intf_plug_plug ( &named->xfer, xfer );
        ref_put ( &named->refcnt );
        return 0;

 err:
        ref_put ( &named->refcnt );
        return rc;
}
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 141 of file open.c.

References DBGC, ENOTSUP, socket_opener::family, for_each_table_entry, INTF_COL, INTF_DBG, INTF_FMT, socket_opener::open, sockaddr::sa_family, 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().

                                                                       {
        struct socket_opener *opener;

        DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " opening (%s,%s) socket\n",
               INTF_DBG ( intf ), socket_semantics_name ( semantics ),
               socket_family_name ( peer->sa_family ) );

        for_each_table_entry ( opener, SOCKET_OPENERS ) {
                if ( ( opener->semantics == semantics ) &&
                     ( opener->family == peer->sa_family ) ) {
                        return opener->open ( intf, peer, local );
                }
        }

        DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to open "
               "unsupported socket type (%s,%s)\n",
               INTF_DBG ( intf ), socket_semantics_name ( semantics ),
               socket_family_name ( peer->sa_family ) );
        return -ENOTSUP;
}
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 171 of file open.c.

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

Referenced by xfer_open(), and xfer_vreopen().

                                                                  {
        switch ( type ) {
        case LOCATION_URI_STRING: {
                const char *uri_string = va_arg ( args, const char * );

                return xfer_open_uri_string ( intf, uri_string ); }
        case LOCATION_URI: {
                struct uri *uri = va_arg ( args, struct uri * );

                return xfer_open_uri ( intf, uri ); }
        case LOCATION_SOCKET: {
                int semantics = va_arg ( args, int );
                struct sockaddr *peer = va_arg ( args, struct sockaddr * );
                struct sockaddr *local = va_arg ( args, struct sockaddr * );

                return xfer_open_socket ( intf, semantics, peer, local ); }
        default:
                DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " attempted to "
                       "open unsupported location type %d\n",
                       INTF_DBG ( intf ), type );
                return -ENOTSUP;
        }
}
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 203 of file open.c.

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

Referenced by efi_download_start().

                                                        {
        va_list args;
        int rc;

        va_start ( args, type );
        rc = xfer_vopen ( intf, type, args );
        va_end ( args );
        return rc;
}
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 225 of file open.c.

References intf_restart(), and xfer_vopen().

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

                                                                    {

        /* Close existing connection */
        intf_restart ( intf, 0 );

        /* Open new location */
        return xfer_vopen ( intf, type, args );
}