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

84 {
85 if ( ! auth_sys )
86 return -EINVAL;
87
88 fetch_string_setting_copy ( NULL, &hostname_setting,
89 &auth_sys->hostname );
90 if ( ! auth_sys->hostname )
91 if ( ! ( auth_sys->hostname = strdup ( product_short_name ) ) )
92 return -ENOMEM;
93
94 auth_sys->uid = fetch_uintz_setting ( NULL, &uid_setting );
95 auth_sys->gid = fetch_uintz_setting ( NULL, &uid_setting );
96 auth_sys->aux_gid_len = 0;
97 auth_sys->stamp = 0;
98
100 auth_sys->credential.length = 16 +
101 oncrpc_strlen ( auth_sys->hostname );
102
103 return 0;
104}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ENOMEM
Not enough space.
Definition errno.h:535
#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:1069
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:394
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:77

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

118 {
119 if ( ! session )
120 return;
121
122 session->rpc_id = rand();
123 session->credential = credential;
124 session->verifier = verifier;
125 session->prog_name = prog_name;
126 session->prog_vers = prog_vers;
127}
static int rand(void)
Definition stdlib.h:60
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 129 of file oncrpc.c.

130 {
131 size_t frame_size;
132 struct io_buffer *io_buf;
133
134 if ( ! session )
135 return -EINVAL;
136
137 struct oncrpc_field header[] = {
138 ONCRPC_FIELD ( int32, 0 ),
139 ONCRPC_FIELD ( int32, ++session->rpc_id ),
142 ONCRPC_FIELD ( int32, session->prog_name ),
143 ONCRPC_FIELD ( int32, session->prog_vers ),
144 ONCRPC_FIELD ( int32, proc_name ),
145 ONCRPC_FIELD ( cred, session->credential ),
146 ONCRPC_FIELD ( cred, session->verifier ),
148 };
149
150 frame_size = oncrpc_compute_size ( header );
151 frame_size += oncrpc_compute_size ( fields );
152
153 io_buf = xfer_alloc_iob ( intf, frame_size );
154 if ( ! io_buf )
155 return -ENOBUFS;
156
157 header[0].value.int32 = SET_LAST_FRAME ( frame_size -
158 sizeof ( uint32_t ) );
159
160 oncrpc_iob_add_fields ( io_buf, header );
161 oncrpc_iob_add_fields ( io_buf, fields );
162
163 return xfer_deliver_iob ( intf, iob_disown ( io_buf ) );
164}
struct ena_llq_option header
Header locations.
Definition ena.h:5
#define ENOBUFS
No buffer space available.
Definition errno.h:499
int32_t int32
Definition stdint.h:32
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition iobuf.h:217
#define SET_LAST_FRAME(x)
Set most significant bit to 1.
Definition oncrpc.c:49
#define ONCRPC_CALL
Definition oncrpc.c:52
size_t oncrpc_compute_size(const struct oncrpc_field fields[])
Definition oncrpc.c:166
#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:38
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 166 of file oncrpc.c.

166 {
167
168 size_t i;
169 size_t size = 0;
170
171 for ( i = 0; fields[i].type != oncrpc_none; i++ ) {
172 switch ( fields[i].type ) {
173 case oncrpc_int32:
174 size += sizeof ( uint32_t );
175 break;
176
177 case oncrpc_int64:
178 size += sizeof ( uint64_t );
179 break;
180
181 case oncrpc_str:
182 size += oncrpc_strlen ( fields[i].value.str );
183 break;
184
185 case oncrpc_array:
186 size += oncrpc_align ( fields[i].value.array.length );
187 size += sizeof ( uint32_t );
188 break;
189
190 case oncrpc_intarray:
191 size += sizeof ( uint32_t ) *
192 fields[i].value.intarray.length;
193 size += sizeof ( uint32_t );
194 break;
195
196 case oncrpc_cred:
197 size += fields[i].value.cred->length;
198 size += 2 * sizeof ( uint32_t );
199 break;
200
201 default:
202 return size;
203 }
204 }
205
206 return size;
207}
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 56 of file oncrpc.c.

56 {
57 .flavor = ONCRPC_AUTH_NONE,
58 .length = 0
59};
#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().