iPXE
oncrpc.h
Go to the documentation of this file.
00001 #ifndef _IPXE_ONCRPC_H
00002 #define _IPXE_ONCRPC_H
00003 
00004 #include <stdint.h>
00005 #include <ipxe/interface.h>
00006 #include <ipxe/iobuf.h>
00007 
00008 /** @file
00009  *
00010  * SUN ONC RPC protocol.
00011  *
00012  */
00013 
00014 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00015 
00016 /** ONC RCP Version */
00017 #define ONCRPC_VERS 2
00018 
00019 /** ONC RPC Null Authentication */
00020 #define ONCRPC_AUTH_NONE 0
00021 
00022 /** ONC RPC System Authentication (also called UNIX Authentication) */
00023 #define ONCRPC_AUTH_SYS  1
00024 
00025 /** Size of an ONC RPC header */
00026 #define ONCRPC_HEADER_SIZE ( 11 * sizeof ( uint32_t ) )
00027 
00028 #define ONCRPC_FIELD( type, value ) { oncrpc_ ## type, { .type = value } }
00029 #define ONCRPC_SUBFIELD( type, args... ) \
00030         { oncrpc_ ## type, { .type = { args } } }
00031 
00032 #define ONCRPC_FIELD_END { oncrpc_none, { } }
00033 
00034 /** Enusure that size is a multiple of four */
00035 #define oncrpc_align( size ) ( ( (size) + 3 ) & ~3 )
00036 
00037 /**
00038  * Calculate the length of a string, including padding bytes.
00039  *
00040  * @v str               String
00041  * @ret size            Length of the padded string
00042  */
00043 #define oncrpc_strlen( str ) ( oncrpc_align ( strlen ( str ) ) + \
00044                                sizeof ( uint32_t ) )
00045 
00046 struct oncrpc_cred {
00047         uint32_t               flavor;
00048         uint32_t               length;
00049 };
00050 
00051 struct oncrpc_cred_sys {
00052         struct oncrpc_cred     credential;
00053         uint32_t               stamp;
00054         char                   *hostname;
00055         uint32_t               uid;
00056         uint32_t               gid;
00057         uint32_t               aux_gid_len;
00058         uint32_t               aux_gid[16];
00059 };
00060 
00061 struct oncrpc_reply
00062 {
00063         struct oncrpc_cred      *verifier;
00064         uint32_t                rpc_id;
00065         uint32_t                reply_state;
00066         uint32_t                accept_state;
00067         uint32_t                frame_size;
00068         struct io_buffer        *data;
00069 };
00070 
00071 struct oncrpc_session {
00072         struct oncrpc_reply     pending_reply;
00073         struct oncrpc_cred      *credential;
00074         struct oncrpc_cred      *verifier;
00075         uint32_t                rpc_id;
00076         uint32_t                prog_name;
00077         uint32_t                prog_vers;
00078 };
00079 
00080 enum oncrpc_field_type {
00081         oncrpc_none = 0,
00082         oncrpc_int32,
00083         oncrpc_int64,
00084         oncrpc_str,
00085         oncrpc_array,
00086         oncrpc_intarray,
00087         oncrpc_cred,
00088 };
00089 
00090 union oncrpc_field_value {
00091         struct {
00092                 size_t           length;
00093                 const void       *ptr;
00094         }                        array;
00095 
00096         struct {
00097                 size_t           length;
00098                 const uint32_t   *ptr;
00099         }                        intarray;
00100 
00101         int64_t                  int64;
00102         int32_t                  int32;
00103         const char               *str;
00104         const struct oncrpc_cred *cred;
00105 };
00106 
00107 struct oncrpc_field {
00108         enum oncrpc_field_type       type;
00109         union oncrpc_field_value     value;
00110 };
00111 
00112 extern struct oncrpc_cred oncrpc_auth_none;
00113 
00114 int oncrpc_init_cred_sys ( struct oncrpc_cred_sys *auth_sys );
00115 void oncrpc_init_session ( struct oncrpc_session *session,
00116                            struct oncrpc_cred *credential,
00117                            struct oncrpc_cred *verifier, uint32_t prog_name,
00118                            uint32_t prog_vers );
00119 
00120 int oncrpc_call ( struct interface *intf, struct oncrpc_session *session,
00121                   uint32_t proc_name, const struct oncrpc_field fields[] );
00122 
00123 size_t oncrpc_compute_size ( const struct oncrpc_field fields[] );
00124 
00125 int oncrpc_get_reply ( struct oncrpc_session *session,
00126                        struct oncrpc_reply *reply, struct io_buffer *io_buf );
00127 
00128 #endif /* _IPXE_ONCRPC_H */