iPXE
Defines | Functions
oncrpc_iob.h File Reference

SUN ONC RPC protocol. More...

#include <stdint.h>
#include <string.h>
#include <ipxe/iobuf.h>
#include <ipxe/refcnt.h>
#include <ipxe/oncrpc.h>

Go to the source code of this file.

Defines

#define oncrpc_iob_add_string(buf, str)
 Add a string to the end of an I/O buffer.
#define oncrpc_iob_get_int(buf)
 Get a 32 bits integer from the beginning of an I/O buffer.
#define oncrpc_iob_get_int64(buf)
 Get a 64 bits integer from the beginning of an I/O buffer.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
size_t oncrpc_iob_add_fields (struct io_buffer *io_buf, const struct oncrpc_field fields[])
size_t oncrpc_iob_add_array (struct io_buffer *io_buf, size_t length, const void *data)
 Add an array of bytes to the end of an I/O buffer.
size_t oncrpc_iob_add_intarray (struct io_buffer *io_buf, size_t length, const uint32_t *array)
 Add an int array to the end of an I/O buffer.
size_t oncrpc_iob_add_cred (struct io_buffer *io_buf, const struct oncrpc_cred *cred)
 Add credential information to the end of an I/O buffer.
size_t oncrpc_iob_get_cred (struct io_buffer *io_buf, struct oncrpc_cred *cred)
 Get credential information from the beginning of an I/O buffer.
static size_t oncrpc_iob_add_int (struct io_buffer *io_buf, uint32_t val)
 Add a 32 bits integer to the end of an I/O buffer.
static size_t oncrpc_iob_add_int64 (struct io_buffer *io_buf, uint64_t val)
 Add a 64 bits integer to the end of an I/O buffer.

Detailed Description

SUN ONC RPC protocol.

Definition in file oncrpc_iob.h.


Define Documentation

#define oncrpc_iob_add_string (   buf,
  str 
)
Value:
( { \
        const char * _str = (str); \
        oncrpc_iob_add_array ( (buf), strlen ( _str ), _str ); \
} )

Add a string to the end of an I/O buffer.

Parameters:
io_bufI/O buffer
valString
Return values:
sizeSize of the data written

Definition at line 25 of file oncrpc_iob.h.

Referenced by oncrpc_iob_add_fields().

#define oncrpc_iob_get_int (   buf)
Value:
( { \
        uint32_t *_val; \
        _val = (buf)->data; \
        iob_pull ( (buf), sizeof ( uint32_t ) ); \
        ntohl ( *_val ); \
} )

Get a 32 bits integer from the beginning of an I/O buffer.

Parameters:
bufI/O buffer
Return values:
intInteger

Definition at line 38 of file oncrpc_iob.h.

Referenced by mount_get_mnt_reply(), nfs_get_lookup_reply(), nfs_get_read_reply(), nfs_get_readlink_reply(), nfs_iob_get_fh(), oncrpc_get_reply(), oncrpc_iob_get_cred(), and portmap_get_getport_reply().

#define oncrpc_iob_get_int64 (   buf)
Value:
( { \
        uint64_t *_val; \
        _val = (buf)->data; \
        iob_pull ( (buf), sizeof ( uint64_t ) ); \
        ntohll ( *_val ); \
} )

Get a 64 bits integer from the beginning of an I/O buffer.

Parameters:
bufI/O buffer
Return values:
intInteger

Definition at line 52 of file oncrpc_iob.h.

Referenced by nfs_get_read_reply().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
size_t oncrpc_iob_add_fields ( struct io_buffer io_buf,
const struct oncrpc_field  fields[] 
)

Definition at line 44 of file oncrpc_iob.c.

References oncrpc_field_value::array, oncrpc_field_value::cred, oncrpc_field_value::int32, oncrpc_field_value::int64, oncrpc_field_value::intarray, oncrpc_field_value::length, oncrpc_array, oncrpc_int32, oncrpc_int64, oncrpc_intarray, oncrpc_iob_add_array(), oncrpc_iob_add_cred(), oncrpc_iob_add_int(), oncrpc_iob_add_int64(), oncrpc_iob_add_intarray(), oncrpc_iob_add_string, oncrpc_none, oncrpc_str, oncrpc_field_value::ptr, oncrpc_field_value::str, oncrpc_field::type, and oncrpc_field::value.

Referenced by oncrpc_call(), and oncrpc_iob_add_cred().

                                                                    {
        size_t i;
        size_t s = 0;

        struct oncrpc_field f;

        if ( ! io_buf )
                return 0;

        for ( i = 0; fields[i].type != oncrpc_none; i++ ) {
                f = fields[i];
                switch ( f.type ) {
                case oncrpc_int32:
                        s += oncrpc_iob_add_int ( io_buf, f.value.int32 );
                        break;

                case oncrpc_int64:
                        s += oncrpc_iob_add_int64 ( io_buf, f.value.int64 );
                        break;

                case oncrpc_str:
                        s += oncrpc_iob_add_string ( io_buf, f.value.str );
                        break;

                case oncrpc_array:
                        s += oncrpc_iob_add_array ( io_buf,
                                                    f.value.array.length,
                                                    f.value.array.ptr );
                        break;

                case oncrpc_intarray:
                        s += oncrpc_iob_add_intarray ( io_buf,
                                                       f.value.intarray.length,
                                                       f.value.intarray.ptr );
                        break;

                case oncrpc_cred:
                        s += oncrpc_iob_add_cred ( io_buf, f.value.cred);
                        break;

                default:
                        return s;
                }
        }

        return s;
}
size_t oncrpc_iob_add_array ( struct io_buffer io_buf,
size_t  length,
const void *  data 
)

Add an array of bytes to the end of an I/O buffer.

Parameters:
io_bufI/O buffer
valString
Return values:
sizeSize of the data written

In the ONC RPC protocol, every data is four byte paded, we add padding when necessary by using oncrpc_align()

Definition at line 103 of file oncrpc_iob.c.

References iob_put, length, memcpy(), memset(), oncrpc_align, and oncrpc_iob_add_int().

Referenced by oncrpc_iob_add_fields().

                                                 {
        size_t padding = oncrpc_align ( length ) - length;

        oncrpc_iob_add_int ( io_buf, length );
        memcpy ( iob_put ( io_buf, length ), data, length );
        memset ( iob_put ( io_buf, padding ), 0, padding );

        return length + padding + sizeof ( uint32_t );
}
size_t oncrpc_iob_add_intarray ( struct io_buffer io_buf,
size_t  length,
const uint32_t array 
)

Add an int array to the end of an I/O buffer.

Parameters:
io_bufI/O buffer
lengthLength od the array
valInt array
Return values:
sizeSize of the data written

Definition at line 122 of file oncrpc_iob.c.

References length, and oncrpc_iob_add_int().

Referenced by oncrpc_iob_add_fields().

                                                         {
        size_t                  i;

        oncrpc_iob_add_int ( io_buf, length );

        for ( i = 0; i < length; ++i )
                oncrpc_iob_add_int ( io_buf, array[i] );

        return ( ( length + 1 ) * sizeof ( uint32_t ) );
}
size_t oncrpc_iob_add_cred ( struct io_buffer io_buf,
const struct oncrpc_cred cred 
)

Add credential information to the end of an I/O buffer.

Parameters:
io_bufI/O buffer
credCredential information
Return values:
sizeSize of the data written

Definition at line 141 of file oncrpc_iob.c.

References oncrpc_cred_sys::aux_gid, oncrpc_cred_sys::aux_gid_len, container_of, oncrpc_cred::flavor, oncrpc_cred_sys::gid, oncrpc_cred_sys::hostname, oncrpc_cred::length, ONCRPC_AUTH_NONE, ONCRPC_AUTH_SYS, ONCRPC_FIELD, ONCRPC_FIELD_END, oncrpc_iob_add_fields(), ONCRPC_SUBFIELD, oncrpc_cred_sys::stamp, and oncrpc_cred_sys::uid.

Referenced by oncrpc_iob_add_fields().

                                                              {
        struct oncrpc_cred_sys  *syscred;
        size_t                  s;

        struct oncrpc_field credfields[] = {
                ONCRPC_FIELD ( int32, cred->flavor ),
                ONCRPC_FIELD ( int32, cred->length ),
                ONCRPC_FIELD_END,
        };

        if ( ! io_buf || ! cred )
                return 0;

        s  = oncrpc_iob_add_fields ( io_buf, credfields);

        switch ( cred->flavor ) {
        case ONCRPC_AUTH_NONE:
                break;

        case ONCRPC_AUTH_SYS:
                syscred = container_of ( cred, struct oncrpc_cred_sys,
                                         credential );

                struct oncrpc_field syscredfields[] = {
                        ONCRPC_FIELD ( int32, syscred->stamp ),
                        ONCRPC_FIELD ( str, syscred->hostname ),
                        ONCRPC_FIELD ( int32, syscred->uid ),
                        ONCRPC_FIELD ( int32, syscred->gid ),
                        ONCRPC_SUBFIELD ( intarray, syscred->aux_gid_len,
                                          syscred->aux_gid ),
                        ONCRPC_FIELD_END,
                };

                s += oncrpc_iob_add_fields ( io_buf, syscredfields );
                break;
        }

        return s;
}
size_t oncrpc_iob_get_cred ( struct io_buffer io_buf,
struct oncrpc_cred cred 
)

Get credential information from the beginning of an I/O buffer.

Parameters:
io_bufI/O buffer
credStruct where the information will be saved
Return values:
sizeSize of the data read

Definition at line 189 of file oncrpc_iob.c.

References io_buffer::data, oncrpc_cred::flavor, iob_pull, oncrpc_cred::length, NULL, and oncrpc_iob_get_int.

                                                        {
        if ( cred == NULL )
                return * ( uint32_t * ) io_buf->data;

        cred->flavor = oncrpc_iob_get_int ( io_buf );
        cred->length = oncrpc_iob_get_int ( io_buf );

        iob_pull ( io_buf, cred->length );

        return ( 2 * sizeof ( uint32_t ) + cred->length );
}
static size_t oncrpc_iob_add_int ( struct io_buffer io_buf,
uint32_t  val 
) [inline, static]

Add a 32 bits integer to the end of an I/O buffer.

Parameters:
io_bufI/O buffer
valInteger
Return values:
sizeSize of the data written

Definition at line 83 of file oncrpc_iob.h.

References htonl, and iob_put.

Referenced by nfs_iob_add_fh(), oncrpc_iob_add_array(), oncrpc_iob_add_fields(), and oncrpc_iob_add_intarray().

                                                         {
        * ( uint32_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonl ( val );
        return ( sizeof ( val) );
}
static size_t oncrpc_iob_add_int64 ( struct io_buffer io_buf,
uint64_t  val 
) [inline, static]

Add a 64 bits integer to the end of an I/O buffer.

Parameters:
io_bufI/O buffer
valInteger
Return values:
sizeSize of the data written

Definition at line 96 of file oncrpc_iob.h.

References htonll, and iob_put.

Referenced by oncrpc_iob_add_fields().

                                                           {
        * ( uint64_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonll ( val );
        return ( sizeof ( val) );
}