#rpc #remote-procedure #xdr #sun #protocols #networking #onc

onc-rpc

Open Network Computing / Sun RPC types and fast serialisation

8 releases

0.3.0 May 13, 2024
0.2.5 May 10, 2024
0.2.3 Jun 22, 2021
0.2.2 Jan 1, 2021
0.1.0 Jun 9, 2020

#232 in Encoding

Download history 14069/week @ 2024-08-14 13343/week @ 2024-08-21 12358/week @ 2024-08-28 13455/week @ 2024-09-04 13954/week @ 2024-09-11 13991/week @ 2024-09-18 15099/week @ 2024-09-25 12168/week @ 2024-10-02 15032/week @ 2024-10-09 11601/week @ 2024-10-16 11684/week @ 2024-10-23 11441/week @ 2024-10-30 13119/week @ 2024-11-06 11425/week @ 2024-11-13 12711/week @ 2024-11-20 10579/week @ 2024-11-27

50,052 downloads per month

BSD-3-Clause

105KB
2K SLoC

crates.io docs.rs

ONC RPC

This crate implements the Open Network Computing Remote Procedure Call system (originally known as the Sun RPC system) as described in RFC 1831 and RFC 5531.

  • Zero copy deserialisation
  • Support for serialisation buffer reuse and pooling
  • Only safe Rust code
  • No heap allocations
  • Simple, descriptive, one-to-one types matching the RFCs

Example

use onc_rpc::{
    auth::{AuthFlavor, AuthUnixParams},
    CallBody,
    MessageType,
    RpcMessage,
};

// Add RPC call authentication.
let auth_params = AuthUnixParams::new(
	42,										// Stamp
	"bananas.local",						// Machine name
	501,									// UID
	501,									// GID
	None,									// No additional GIDs
);

// Build a dummy byte payload.
let payload = vec![42, 42, 42, 42];

// Construct the actual RPC message.
let msg = RpcMessage::new(
    4242,
    MessageType::Call(CallBody::new(
        100000, 							// Program number
        42,									// Program version
        13,									// Procedure number
        AuthFlavor::AuthUnix(auth_params),	// Credentials
        AuthFlavor::AuthNone(None),			// Response verifier
        &payload,
    )),
);

// Serialise the RPC message, or serialise_into() to reuse buffers.
let network_buffer = msg.serialise().expect("serialise message");

// And do something with it!

Limitations

I had no use for the following, however PRs to extend this crate are happily accepted :)

  • No support for fragmented messages
  • No support for the deprecated and trivially broken Diffie-Hellman authentication flavor
  • No defined GSS / Kerberos auth flavor types

The auth flavors not included in this crate can still be used as the flavor discriminant and associated opaque data is available in the application layer - this crate just lacks pre-defined types to describe them.

Future development

Currently a buffer has to be passed to serialise the complete message into a continuous memory region - it would be nicer to support vectorised I/O to provide zero-copy serialisation too.

Fuzzing

Included in the fuzz/ directory is a deserialisation fuzzer that attempts to decode arbitrary inputs, and if successful serialises the resulting message and compares the result with the input.

Install cargo fuzz and invoke the fuzzer with cargo fuzz run parse_serialise -- -jobs=30 for parallelised workers.

Dependencies

~0.5–1MB
~21K SLoC