iPXE
Data Structures | Defines | Enumerations | Functions | Variables
oncrpc.h File Reference

SUN ONC RPC protocol. More...

#include <stdint.h>
#include <ipxe/interface.h>
#include <ipxe/iobuf.h>

Go to the source code of this file.

Data Structures

struct  oncrpc_cred
struct  oncrpc_cred_sys
struct  oncrpc_reply
struct  oncrpc_session
union  oncrpc_field_value
struct  oncrpc_field

Defines

#define ONCRPC_VERS   2
 ONC RCP Version.
#define ONCRPC_AUTH_NONE   0
 ONC RPC Null Authentication.
#define ONCRPC_AUTH_SYS   1
 ONC RPC System Authentication (also called UNIX Authentication)
#define ONCRPC_HEADER_SIZE   ( 11 * sizeof ( uint32_t ) )
 Size of an ONC RPC header.
#define ONCRPC_FIELD(type, value)   { oncrpc_ ## type, { .type = value } }
#define ONCRPC_SUBFIELD(type, args...)   { oncrpc_ ## type, { .type = { args } } }
#define ONCRPC_FIELD_END   { oncrpc_none, { } }
#define oncrpc_align(size)   ( ( (size) + 3 ) & ~3 )
 Enusure that size is a multiple of four.
#define oncrpc_strlen(str)
 Calculate the length of a string, including padding bytes.

Enumerations

enum  oncrpc_field_type {
  oncrpc_none = 0, oncrpc_int32, oncrpc_int64, oncrpc_str,
  oncrpc_array, oncrpc_intarray, oncrpc_cred
}

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int oncrpc_init_cred_sys (struct oncrpc_cred_sys *auth_sys)
 Initialize an ONC RPC AUTH SYS credential structure.
void oncrpc_init_session (struct oncrpc_session *session, struct oncrpc_cred *credential, struct oncrpc_cred *verifier, uint32_t prog_name, uint32_t prog_vers)
 Prepare an ONC RPC session structure to be used by the ONC RPC layer.
int oncrpc_call (struct interface *intf, struct oncrpc_session *session, uint32_t proc_name, const struct oncrpc_field fields[])
size_t oncrpc_compute_size (const struct oncrpc_field fields[])
int oncrpc_get_reply (struct oncrpc_session *session, struct oncrpc_reply *reply, struct io_buffer *io_buf)

Variables

struct oncrpc_cred oncrpc_auth_none
 AUTH NONE authentication flavor.

Detailed Description

SUN ONC RPC protocol.

Definition in file oncrpc.h.


Define Documentation

#define ONCRPC_VERS   2

ONC RCP Version.

Definition at line 17 of file oncrpc.h.

Referenced by oncrpc_call().

#define ONCRPC_AUTH_NONE   0

ONC RPC Null Authentication.

Definition at line 20 of file oncrpc.h.

Referenced by oncrpc_iob_add_cred().

#define ONCRPC_AUTH_SYS   1

ONC RPC System Authentication (also called UNIX Authentication)

Definition at line 23 of file oncrpc.h.

Referenced by oncrpc_init_cred_sys(), and oncrpc_iob_add_cred().

#define ONCRPC_HEADER_SIZE   ( 11 * sizeof ( uint32_t ) )

Size of an ONC RPC header.

Definition at line 26 of file oncrpc.h.

#define ONCRPC_FIELD (   type,
  value 
)    { oncrpc_ ## type, { .type = value } }
#define ONCRPC_SUBFIELD (   type,
  args... 
)    { oncrpc_ ## type, { .type = { args } } }

Definition at line 29 of file oncrpc.h.

Referenced by nfs_lookup(), nfs_read(), nfs_readlink(), and oncrpc_iob_add_cred().

#define ONCRPC_FIELD_END   { oncrpc_none, { } }
#define oncrpc_align (   size)    ( ( (size) + 3 ) & ~3 )

Enusure that size is a multiple of four.

Definition at line 35 of file oncrpc.h.

Referenced by oncrpc_compute_size(), and oncrpc_iob_add_array().

#define oncrpc_strlen (   str)
Value:
( oncrpc_align ( strlen ( str ) ) + \
                               sizeof ( uint32_t ) )

Calculate the length of a string, including padding bytes.

Parameters:
strString
Return values:
sizeLength of the padded string

Definition at line 43 of file oncrpc.h.

Referenced by oncrpc_compute_size(), and oncrpc_init_cred_sys().


Enumeration Type Documentation

Enumerator:
oncrpc_none 
oncrpc_int32 
oncrpc_int64 
oncrpc_str 
oncrpc_array 
oncrpc_intarray 
oncrpc_cred 

Definition at line 80 of file oncrpc.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int oncrpc_init_cred_sys ( struct oncrpc_cred_sys auth_sys)

Initialize an ONC RPC AUTH SYS credential structure.

Parameters:
auth_sysThe structure to initialize

The hostname field is filled with the value of the hostname setting, if the hostname setting is empty, PRODUCT_SHORT_NAME (usually "iPXE") is used instead.

Definition at line 84 of file oncrpc.c.

References oncrpc_cred_sys::aux_gid_len, oncrpc_cred_sys::credential, EINVAL, ENOMEM, fetch_string_setting_copy(), fetch_uintz_setting(), oncrpc_cred::flavor, oncrpc_cred_sys::gid, oncrpc_cred_sys::hostname, oncrpc_cred::length, NULL, ONCRPC_AUTH_SYS, oncrpc_strlen, product_short_name, oncrpc_cred_sys::stamp, strdup(), and oncrpc_cred_sys::uid.

Referenced by nfs_open().

                                                              {
        if ( ! auth_sys )
                return -EINVAL;

        fetch_string_setting_copy ( NULL, &hostname_setting,
                                    &auth_sys->hostname );
        if ( ! auth_sys->hostname )
                if ( ! ( auth_sys->hostname = strdup ( product_short_name ) ) )
                        return -ENOMEM;

        auth_sys->uid         = fetch_uintz_setting ( NULL, &uid_setting );
        auth_sys->gid         = fetch_uintz_setting ( NULL, &uid_setting );
        auth_sys->aux_gid_len = 0;
        auth_sys->stamp       = 0;

        auth_sys->credential.flavor = ONCRPC_AUTH_SYS;
        auth_sys->credential.length = 16 +
                                      oncrpc_strlen ( auth_sys->hostname );

        return 0;
}
void oncrpc_init_session ( struct oncrpc_session session,
struct oncrpc_cred credential,
struct oncrpc_cred verifier,
uint32_t  prog_name,
uint32_t  prog_vers 
)

Prepare an ONC RPC session structure to be used by the ONC RPC layer.

Parameters:
sessionONC RPC session
credentialCredential structure pointer
verifierVerifier structure pointer
prog_nameONC RPC program number
prog_versONC RPC program version number

Definition at line 115 of file oncrpc.c.

References oncrpc_session::credential, oncrpc_session::prog_name, oncrpc_session::prog_vers, rand(), oncrpc_session::rpc_id, and oncrpc_session::verifier.

Referenced by mount_init_session(), nfs_init_session(), and portmap_init_session().

                                                {
        if ( ! session )
                return;

        session->rpc_id     = rand();
        session->credential = credential;
        session->verifier   = verifier;
        session->prog_name  = prog_name;
        session->prog_vers  = prog_vers;
}
int oncrpc_call ( struct interface intf,
struct oncrpc_session session,
uint32_t  proc_name,
const struct oncrpc_field  fields[] 
)

Definition at line 129 of file oncrpc.c.

References alloc_iob(), oncrpc_session::credential, EINVAL, ENOBUFS, oncrpc_field_value::int32, iob_disown, ONCRPC_CALL, oncrpc_compute_size(), ONCRPC_FIELD, ONCRPC_FIELD_END, oncrpc_iob_add_fields(), ONCRPC_VERS, oncrpc_session::prog_name, oncrpc_session::prog_vers, oncrpc_session::rpc_id, SET_LAST_FRAME, oncrpc_field::value, oncrpc_session::verifier, and xfer_deliver_iob().

Referenced by mount_mnt(), mount_umnt(), nfs_lookup(), nfs_read(), nfs_readlink(), and portmap_getport().

                                                                           {
        size_t           frame_size;
        struct io_buffer *io_buf;

        if ( ! session )
                return -EINVAL;

        struct oncrpc_field header[] = {
                ONCRPC_FIELD ( int32, 0 ),
                ONCRPC_FIELD ( int32, ++session->rpc_id ),
                ONCRPC_FIELD ( int32, ONCRPC_CALL ),
                ONCRPC_FIELD ( int32, ONCRPC_VERS ),
                ONCRPC_FIELD ( int32, session->prog_name ),
                ONCRPC_FIELD ( int32, session->prog_vers ),
                ONCRPC_FIELD ( int32, proc_name ),
                ONCRPC_FIELD ( cred, session->credential ),
                ONCRPC_FIELD ( cred, session->verifier ),
                ONCRPC_FIELD_END,
        };

        frame_size  = oncrpc_compute_size ( header );
        frame_size += oncrpc_compute_size ( fields );

        io_buf = alloc_iob ( frame_size );
        if ( ! io_buf )
                return -ENOBUFS;

        header[0].value.int32 = SET_LAST_FRAME ( frame_size -
                                                 sizeof ( uint32_t ) );

        oncrpc_iob_add_fields ( io_buf, header );
        oncrpc_iob_add_fields ( io_buf, fields );

        return xfer_deliver_iob ( intf, iob_disown ( io_buf ) );
}
size_t oncrpc_compute_size ( const struct oncrpc_field  fields[])

Definition at line 166 of file oncrpc.c.

References oncrpc_field_value::cred, oncrpc_cred::length, oncrpc_align, oncrpc_array, oncrpc_int32, oncrpc_int64, oncrpc_intarray, oncrpc_none, oncrpc_str, oncrpc_strlen, size, oncrpc_field::type, type, oncrpc_field::value, and value.

Referenced by oncrpc_call().

                                                                  {

        size_t i;
        size_t size = 0;

        for ( i = 0; fields[i].type != oncrpc_none; i++ ) {
                switch ( fields[i].type ) {
                case oncrpc_int32:
                        size += sizeof ( uint32_t );
                        break;

                case oncrpc_int64:
                        size += sizeof ( uint64_t );
                        break;

                case oncrpc_str:
                        size += oncrpc_strlen ( fields[i].value.str );
                        break;

                case oncrpc_array:
                        size += oncrpc_align ( fields[i].value.array.length );
                        size += sizeof ( uint32_t );
                        break;

                case oncrpc_intarray:
                        size += sizeof ( uint32_t ) *
                                fields[i].value.intarray.length;
                        size += sizeof ( uint32_t );
                        break;

                case oncrpc_cred:
                        size += fields[i].value.cred->length;
                        size += 2 * sizeof ( uint32_t );
                        break;

                default:
                        return size;
                }
        }

        return size;
}
int oncrpc_get_reply ( struct oncrpc_session session,
struct oncrpc_reply reply,
struct io_buffer io_buf 
)

Variable Documentation

AUTH NONE authentication flavor.

Definition at line 56 of file oncrpc.c.

Referenced by mount_init_session(), nfs_init_session(), oncrpc_get_reply(), and portmap_init_session().