iPXE
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

Macros

#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)
#define ONCRPC_SUBFIELD(type, args...)
#define ONCRPC_FIELD_END   { oncrpc_none, { } }
#define oncrpc_align(size)
 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.

Macro Definition Documentation

◆ ONCRPC_VERS

#define ONCRPC_VERS   2

ONC RCP Version.

Definition at line 17 of file oncrpc.h.

Referenced by oncrpc_call().

◆ ONCRPC_AUTH_NONE

#define ONCRPC_AUTH_NONE   0

ONC RPC Null Authentication.

Definition at line 20 of file oncrpc.h.

Referenced by oncrpc_iob_add_cred().

◆ ONCRPC_AUTH_SYS

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

◆ ONCRPC_HEADER_SIZE

#define ONCRPC_HEADER_SIZE   ( 11 * sizeof ( uint32_t ) )

Size of an ONC RPC header.

Definition at line 26 of file oncrpc.h.

◆ ONCRPC_FIELD

#define ONCRPC_FIELD ( type,
value )
Value:
{ oncrpc_ ## type, { .type = value } }
pseudo_bit_t value[0x00020]
Definition arbel.h:2
uint32_t type
Operating system type.
Definition ena.h:1

Definition at line 28 of file oncrpc.h.

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

◆ ONCRPC_SUBFIELD

#define ONCRPC_SUBFIELD ( type,
args... )
Value:
{ oncrpc_ ## type, { .type = { args } } }

Definition at line 29 of file oncrpc.h.

29#define ONCRPC_SUBFIELD( type, args... ) \
30 { oncrpc_ ## type, { .type = { args } } }

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

◆ ONCRPC_FIELD_END

#define ONCRPC_FIELD_END   { oncrpc_none, { } }

◆ oncrpc_align

#define oncrpc_align ( size)
Value:
( ( (size) + 3 ) & ~3 )
uint16_t size
Buffer size.
Definition dwmac.h: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().

◆ oncrpc_strlen

#define oncrpc_strlen ( str)
Value:
( oncrpc_align ( strlen ( str ) ) + \
sizeof ( uint32_t ) )
unsigned int uint32_t
Definition stdint.h:12
#define oncrpc_align(size)
Enusure that size is a multiple of four.
Definition oncrpc.h:35
size_t strlen(const char *src)
Get length of string.
Definition string.c:244

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.

43#define oncrpc_strlen( str ) ( oncrpc_align ( strlen ( str ) ) + \
44 sizeof ( uint32_t ) )

Referenced by oncrpc_compute_size(), and oncrpc_init_cred_sys().

Enumeration Type Documentation

◆ oncrpc_field_type

Enumerator
oncrpc_none 
oncrpc_int32 
oncrpc_int64 
oncrpc_str 
oncrpc_array 
oncrpc_intarray 
oncrpc_cred 

Definition at line 80 of file oncrpc.h.

80 {
81 oncrpc_none = 0,
88};
@ 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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ oncrpc_init_cred_sys()

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 86 of file oncrpc.c.

86 {
87 if ( ! auth_sys )
88 return -EINVAL;
89
90 fetch_string_setting_copy ( NULL, &hostname_setting,
91 &auth_sys->hostname );
92 if ( ! auth_sys->hostname )
93 if ( ! ( auth_sys->hostname = strdup ( product_short_name ) ) )
94 return -ENOMEM;
95
96 auth_sys->uid = fetch_uintz_setting ( NULL, &uid_setting );
97 auth_sys->gid = fetch_uintz_setting ( NULL, &uid_setting );
98 auth_sys->aux_gid_len = 0;
99 auth_sys->stamp = 0;
100
102 auth_sys->credential.length = 16 +
103 oncrpc_strlen ( auth_sys->hostname );
104
105 return 0;
106}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
#define EINVAL
Invalid argument.
Definition errno.h:472
#define ENOMEM
Not enough space.
Definition errno.h:578
#define oncrpc_strlen(str)
Calculate the length of a string, including padding bytes.
Definition oncrpc.h:43
#define ONCRPC_AUTH_SYS
ONC RPC System Authentication (also called UNIX Authentication).
Definition oncrpc.h:23
unsigned long fetch_uintz_setting(struct settings *settings, const struct setting *setting)
Fetch value of unsigned integer setting, or zero.
Definition settings.c:1079
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition settings.c:874
char * strdup(const char *src)
Duplicate string.
Definition string.c:425
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
struct oncrpc_cred credential
Definition oncrpc.h:52
uint32_t flavor
Definition oncrpc.h:47
uint32_t length
Definition oncrpc.h:48
const char product_short_name[]
Product short name string.
Definition version.c:78

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

◆ oncrpc_init_session()

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 117 of file oncrpc.c.

120 {
121 if ( ! session )
122 return;
123
124 session->rpc_id = rand();
125 session->credential = credential;
126 session->verifier = verifier;
127 session->prog_name = prog_name;
128 session->prog_vers = prog_vers;
129}
static int rand(void)
Definition stdlib.h:61
struct oncrpc_cred * credential
Definition oncrpc.h:73
uint32_t prog_name
Definition oncrpc.h:76
struct oncrpc_cred * verifier
Definition oncrpc.h:74
uint32_t rpc_id
Definition oncrpc.h:75
uint32_t prog_vers
Definition oncrpc.h:77

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

◆ oncrpc_call()

int oncrpc_call ( struct interface * intf,
struct oncrpc_session * session,
uint32_t proc_name,
const struct oncrpc_field fields[] )

Definition at line 131 of file oncrpc.c.

132 {
133 size_t frame_size;
134 struct io_buffer *io_buf;
135
136 if ( ! session )
137 return -EINVAL;
138
139 struct oncrpc_field header[] = {
140 ONCRPC_FIELD ( int32, 0 ),
141 ONCRPC_FIELD ( int32, ++session->rpc_id ),
144 ONCRPC_FIELD ( int32, session->prog_name ),
145 ONCRPC_FIELD ( int32, session->prog_vers ),
146 ONCRPC_FIELD ( int32, proc_name ),
147 ONCRPC_FIELD ( cred, session->credential ),
148 ONCRPC_FIELD ( cred, session->verifier ),
150 };
151
152 frame_size = oncrpc_compute_size ( header );
153 frame_size += oncrpc_compute_size ( fields );
154
155 io_buf = xfer_alloc_iob ( intf, frame_size );
156 if ( ! io_buf )
157 return -ENOBUFS;
158
159 header[0].value.int32 = SET_LAST_FRAME ( frame_size -
160 sizeof ( uint32_t ) );
161
162 oncrpc_iob_add_fields ( io_buf, header );
163 oncrpc_iob_add_fields ( io_buf, fields );
164
165 return xfer_deliver_iob ( intf, iob_disown ( io_buf ) );
166}
struct ena_llq_option header
Header locations.
Definition ena.h:5
#define ENOBUFS
No buffer space available.
Definition errno.h:542
int32_t int32
Definition stdint.h:32
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition iobuf.h:277
#define SET_LAST_FRAME(x)
Set most significant bit to 1.
Definition oncrpc.c:51
#define ONCRPC_CALL
Definition oncrpc.c:54
size_t oncrpc_compute_size(const struct oncrpc_field fields[])
Definition oncrpc.c:168
#define ONCRPC_FIELD_END
Definition oncrpc.h:32
#define ONCRPC_VERS
ONC RCP Version.
Definition oncrpc.h:17
#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:46
A persistent I/O buffer.
Definition iobuf.h:98
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition xfer.c:159
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition xfer.c:256

References oncrpc_session::credential, EINVAL, ENOBUFS, header, 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_session::verifier, xfer_alloc_iob(), and xfer_deliver_iob().

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

◆ oncrpc_compute_size()

size_t oncrpc_compute_size ( const struct oncrpc_field fields[])

Definition at line 168 of file oncrpc.c.

168 {
169
170 size_t i;
171 size_t size = 0;
172
173 for ( i = 0; fields[i].type != oncrpc_none; i++ ) {
174 switch ( fields[i].type ) {
175 case oncrpc_int32:
176 size += sizeof ( uint32_t );
177 break;
178
179 case oncrpc_int64:
180 size += sizeof ( uint64_t );
181 break;
182
183 case oncrpc_str:
184 size += oncrpc_strlen ( fields[i].value.str );
185 break;
186
187 case oncrpc_array:
188 size += oncrpc_align ( fields[i].value.array.length );
189 size += sizeof ( uint32_t );
190 break;
191
192 case oncrpc_intarray:
193 size += sizeof ( uint32_t ) *
194 fields[i].value.intarray.length;
195 size += sizeof ( uint32_t );
196 break;
197
198 case oncrpc_cred:
199 size += fields[i].value.cred->length;
200 size += 2 * sizeof ( uint32_t );
201 break;
202
203 default:
204 return size;
205 }
206 }
207
208 return size;
209}
unsigned long long uint64_t
Definition stdint.h:13
union oncrpc_field_value value
Definition oncrpc.h:109
enum oncrpc_field_type type
Definition oncrpc.h:108
const struct oncrpc_cred * cred
Definition oncrpc.h:104

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

◆ oncrpc_get_reply()

int oncrpc_get_reply ( struct oncrpc_session * session,
struct oncrpc_reply * reply,
struct io_buffer * io_buf )

Variable Documentation

◆ oncrpc_auth_none

struct oncrpc_cred oncrpc_auth_none
extern

AUTH NONE authentication flavor.

Definition at line 58 of file oncrpc.c.

58 {
59 .flavor = ONCRPC_AUTH_NONE,
60 .length = 0
61};
#define ONCRPC_AUTH_NONE
ONC RPC Null Authentication.
Definition oncrpc.h:20

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