iPXE
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.

Macros

#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.

Macro Definition Documentation

◆ oncrpc_iob_add_string

#define oncrpc_iob_add_string ( buf,
str )
Value:
( { \
const char * _str = (str); \
oncrpc_iob_add_array ( (buf), strlen ( _str ), _str ); \
} )
size_t strlen(const char *src)
Get length of string.
Definition string.c:244

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.

25#define oncrpc_iob_add_string( buf, str ) \
26( { \
27 const char * _str = (str); \
28 oncrpc_iob_add_array ( (buf), strlen ( _str ), _str ); \
29} )

Referenced by oncrpc_iob_add_fields().

◆ oncrpc_iob_get_int

#define oncrpc_iob_get_int ( buf)
Value:
( { \
uint32_t *_val; \
_val = (buf)->data; \
iob_pull ( (buf), sizeof ( uint32_t ) ); \
ntohl ( *_val ); \
} )
unsigned int uint32_t
Definition stdint.h:12
uint8_t data[48]
Additional event data.
Definition ena.h:11

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.

38#define oncrpc_iob_get_int( buf ) \
39( { \
40 uint32_t *_val; \
41 _val = (buf)->data; \
42 iob_pull ( (buf), sizeof ( uint32_t ) ); \
43 ntohl ( *_val ); \
44} )

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

◆ oncrpc_iob_get_int64

#define oncrpc_iob_get_int64 ( buf)
Value:
( { \
uint64_t *_val; \
_val = (buf)->data; \
iob_pull ( (buf), sizeof ( uint64_t ) ); \
ntohll ( *_val ); \
} )
unsigned long long uint64_t
Definition stdint.h:13

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.

52#define oncrpc_iob_get_int64( buf ) \
53( { \
54 uint64_t *_val; \
55 _val = (buf)->data; \
56 iob_pull ( (buf), sizeof ( uint64_t ) ); \
57 ntohll ( *_val ); \
58} )

Referenced by nfs_get_read_reply().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ oncrpc_iob_add_fields()

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

Definition at line 46 of file oncrpc_iob.c.

47 {
48 size_t i;
49 size_t s = 0;
50
51 struct oncrpc_field f;
52
53 if ( ! io_buf )
54 return 0;
55
56 for ( i = 0; fields[i].type != oncrpc_none; i++ ) {
57 f = fields[i];
58 switch ( f.type ) {
59 case oncrpc_int32:
60 s += oncrpc_iob_add_int ( io_buf, f.value.int32 );
61 break;
62
63 case oncrpc_int64:
64 s += oncrpc_iob_add_int64 ( io_buf, f.value.int64 );
65 break;
66
67 case oncrpc_str:
68 s += oncrpc_iob_add_string ( io_buf, f.value.str );
69 break;
70
71 case oncrpc_array:
72 s += oncrpc_iob_add_array ( io_buf,
73 f.value.array.length,
74 f.value.array.ptr );
75 break;
76
77 case oncrpc_intarray:
78 s += oncrpc_iob_add_intarray ( io_buf,
79 f.value.intarray.length,
80 f.value.intarray.ptr );
81 break;
82
83 case oncrpc_cred:
84 s += oncrpc_iob_add_cred ( io_buf, f.value.cred);
85 break;
86
87 default:
88 return s;
89 }
90 }
91
92 return s;
93}
@ oncrpc_none
Definition oncrpc.h:81
@ oncrpc_str
Definition oncrpc.h:84
@ oncrpc_int64
Definition oncrpc.h:83
@ oncrpc_array
Definition oncrpc.h:85
@ oncrpc_intarray
Definition oncrpc.h:86
@ oncrpc_int32
Definition oncrpc.h:82
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.
Definition oncrpc_iob.c:105
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.
Definition oncrpc_iob.c:124
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.
Definition oncrpc_iob.c:143
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.
Definition oncrpc_iob.h:96
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.
Definition oncrpc_iob.h:83
#define oncrpc_iob_add_string(buf, str)
Add a string to the end of an I/O buffer.
Definition oncrpc_iob.h:25
enum oncrpc_field_type type
Definition oncrpc.h:108

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

◆ oncrpc_iob_add_array()

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 105 of file oncrpc_iob.c.

106 {
107 size_t padding = oncrpc_align ( length ) - length;
108
109 oncrpc_iob_add_int ( io_buf, length );
110 memcpy ( iob_put ( io_buf, length ), data, length );
111 memset ( iob_put ( io_buf, padding ), 0, padding );
112
113 return length + padding + sizeof ( uint32_t );
114}
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
#define iob_put(iobuf, len)
Definition iobuf.h:125
#define oncrpc_align(size)
Enusure that size is a multiple of four.
Definition oncrpc.h:35
u16 length
Definition sky2.h:1

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

Referenced by oncrpc_iob_add_fields().

◆ oncrpc_iob_add_intarray()

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 124 of file oncrpc_iob.c.

125 {
126 size_t i;
127
128 oncrpc_iob_add_int ( io_buf, length );
129
130 for ( i = 0; i < length; ++i )
131 oncrpc_iob_add_int ( io_buf, array[i] );
132
133 return ( ( length + 1 ) * sizeof ( uint32_t ) );
134}
uint32_t array
Array number.
Definition edd.h:1

References array, length, and oncrpc_iob_add_int().

Referenced by oncrpc_iob_add_fields().

◆ oncrpc_iob_add_cred()

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 143 of file oncrpc_iob.c.

144 {
145 struct oncrpc_cred_sys *syscred;
146 size_t s;
147
148 struct oncrpc_field credfields[] = {
149 ONCRPC_FIELD ( int32, cred->flavor ),
150 ONCRPC_FIELD ( int32, cred->length ),
152 };
153
154 if ( ! io_buf || ! cred )
155 return 0;
156
157 s = oncrpc_iob_add_fields ( io_buf, credfields);
158
159 switch ( cred->flavor ) {
160 case ONCRPC_AUTH_NONE:
161 break;
162
163 case ONCRPC_AUTH_SYS:
164 syscred = container_of ( cred, struct oncrpc_cred_sys,
165 credential );
166
167 struct oncrpc_field syscredfields[] = {
168 ONCRPC_FIELD ( int32, syscred->stamp ),
169 ONCRPC_FIELD ( str, syscred->hostname ),
170 ONCRPC_FIELD ( int32, syscred->uid ),
171 ONCRPC_FIELD ( int32, syscred->gid ),
172 ONCRPC_SUBFIELD ( intarray, syscred->aux_gid_len,
173 syscred->aux_gid ),
175 };
176
177 s += oncrpc_iob_add_fields ( io_buf, syscredfields );
178 break;
179 }
180
181 return s;
182}
int32_t int32
Definition stdint.h:32
#define ONCRPC_AUTH_NONE
ONC RPC Null Authentication.
Definition oncrpc.h:20
#define ONCRPC_FIELD_END
Definition oncrpc.h:32
#define ONCRPC_SUBFIELD(type, args...)
Definition oncrpc.h:29
#define ONCRPC_FIELD(type, value)
Definition oncrpc.h:28
#define ONCRPC_AUTH_SYS
ONC RPC System Authentication (also called UNIX Authentication)
Definition oncrpc.h:23
size_t oncrpc_iob_add_fields(struct io_buffer *io_buf, const struct oncrpc_field fields[])
Definition oncrpc_iob.c:46
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
uint32_t aux_gid[16]
Definition oncrpc.h:58
uint32_t uid
Definition oncrpc.h:55
uint32_t aux_gid_len
Definition oncrpc.h:57
char * hostname
Definition oncrpc.h:54
uint32_t stamp
Definition oncrpc.h:53
uint32_t gid
Definition oncrpc.h:56
uint32_t flavor
Definition oncrpc.h:47
uint32_t length
Definition oncrpc.h:48

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

◆ oncrpc_iob_get_cred()

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 191 of file oncrpc_iob.c.

192 {
193 if ( cred == NULL )
194 return * ( uint32_t * ) io_buf->data;
195
196 cred->flavor = oncrpc_iob_get_int ( io_buf );
197 cred->length = oncrpc_iob_get_int ( io_buf );
198
199 iob_pull ( io_buf, cred->length );
200
201 return ( 2 * sizeof ( uint32_t ) + cred->length );
202}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define iob_pull(iobuf, len)
Definition iobuf.h:107
#define oncrpc_iob_get_int(buf)
Get a 32 bits integer from the beginning of an I/O buffer.
Definition oncrpc_iob.h:38
void * data
Start of data.
Definition iobuf.h:53

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

◆ oncrpc_iob_add_int()

size_t oncrpc_iob_add_int ( struct io_buffer * io_buf,
uint32_t val )
inlinestatic

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.

84 {
85 * ( uint32_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonl ( val );
86 return ( sizeof ( val) );
87}
#define htonl(value)
Definition byteswap.h:134
void __asmcall int val
Definition setjmp.h:12

References htonl, iob_put, and val.

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

◆ oncrpc_iob_add_int64()

size_t oncrpc_iob_add_int64 ( struct io_buffer * io_buf,
uint64_t val )
inlinestatic

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.

97 {
98 * ( uint64_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonll ( val );
99 return ( sizeof ( val) );
100}
#define htonll(value)
Definition byteswap.h:132

References htonll, iob_put, and val.

Referenced by oncrpc_iob_add_fields().