iPXE
Functions
oncrpc_iob.c File Reference

SUN ONC RPC protocol. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/socket.h>
#include <ipxe/tcpip.h>
#include <ipxe/in.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/uri.h>
#include <ipxe/features.h>
#include <ipxe/oncrpc.h>
#include <ipxe/oncrpc_iob.h>

Go to the source code of this file.

Functions

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

Detailed Description

SUN ONC RPC protocol.

Definition in file oncrpc_iob.c.

Function Documentation

◆ oncrpc_iob_add_fields()

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.

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

References f, oncrpc_array, oncrpc_cred, 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, and oncrpc_field::type.

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

104  {
105  size_t padding = oncrpc_align ( length ) - length;
106 
107  oncrpc_iob_add_int ( io_buf, length );
108  memcpy ( iob_put ( io_buf, length ), data, length );
109  memset ( iob_put ( io_buf, padding ), 0, padding );
110 
111  return length + padding + sizeof ( uint32_t );
112 }
u16 length
Definition: sky2.h:9
#define iob_put(iobuf, len)
Definition: iobuf.h:120
#define oncrpc_align(size)
Enusure that size is a multiple of four.
Definition: oncrpc.h:35
void * memcpy(void *dest, const void *src, size_t len) __nonnull
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
unsigned int uint32_t
Definition: stdint.h:12
uint8_t data[48]
Additional event data.
Definition: ena.h:22
void * memset(void *dest, int character, size_t len) __nonnull

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

123  {
124  size_t i;
125 
126  oncrpc_iob_add_int ( io_buf, length );
127 
128  for ( i = 0; i < length; ++i )
129  oncrpc_iob_add_int ( io_buf, array[i] );
130 
131  return ( ( length + 1 ) * sizeof ( uint32_t ) );
132 }
u16 length
Definition: sky2.h:9
uint32_t array
Array number.
Definition: edd.h:30
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
unsigned int uint32_t
Definition: stdint.h:12

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

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

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

190  {
191  if ( cred == NULL )
192  return * ( uint32_t * ) io_buf->data;
193 
194  cred->flavor = oncrpc_iob_get_int ( io_buf );
195  cred->length = oncrpc_iob_get_int ( io_buf );
196 
197  iob_pull ( io_buf, cred->length );
198 
199  return ( 2 * sizeof ( uint32_t ) + cred->length );
200 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
#define oncrpc_iob_get_int(buf)
Get a 32 bits integer from the beginning of an I/O buffer.
Definition: oncrpc_iob.h:38
uint32_t flavor
Definition: oncrpc.h:47
unsigned int uint32_t
Definition: stdint.h:12
void * data
Start of data.
Definition: iobuf.h:48
uint32_t length
Definition: oncrpc.h:48
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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