mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-08-21 16:31:14 +02:00

Add a Python-based tool for translating XDR specifications into XDR encoder and decoder functions written in the Linux kernel's C coding style. The generator attempts to match the usual C coding style of the Linux kernel's SunRPC consumers. This approach is similar to the netlink code generator in tools/net/ynl . The maintainability benefits of machine-generated XDR code include: - Stronger type checking - Reduces the number of bugs introduced by human error - Makes the XDR code easier to audit and analyze - Enables rapid prototyping of new RPC-based protocols - Hardens the layering between protocol logic and marshaling - Makes it easier to add observability on demand - Unit tests might be built for both the tool and (automatically) for the generated code In addition, converting the XDR layer to use memory-safe languages such as Rust will be easier if much of the code can be converted automatically. Tested-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
37 lines
962 B
Plaintext
37 lines
962 B
Plaintext
/* Sample XDR specification from RFC 1832 Section 5.5 */
|
|
|
|
const MAXUSERNAME = 32; /* max length of a user name */
|
|
const MAXFILELEN = 65535; /* max length of a file */
|
|
const MAXNAMELEN = 255; /* max length of a file name */
|
|
|
|
/*
|
|
* Types of files:
|
|
*/
|
|
enum filekind {
|
|
TEXT = 0, /* ascii data */
|
|
DATA = 1, /* raw data */
|
|
EXEC = 2 /* executable */
|
|
};
|
|
|
|
/*
|
|
* File information, per kind of file:
|
|
*/
|
|
union filetype switch (filekind kind) {
|
|
case TEXT:
|
|
void; /* no extra information */
|
|
case DATA:
|
|
string creator<MAXNAMELEN>; /* data creator */
|
|
case EXEC:
|
|
string interpretor<MAXNAMELEN>; /* program interpretor */
|
|
};
|
|
|
|
/*
|
|
* A complete file:
|
|
*/
|
|
struct file {
|
|
string filename<MAXNAMELEN>; /* name of file */
|
|
filetype type; /* info about file */
|
|
string owner<MAXUSERNAME>; /* owner of file */
|
|
opaque data<MAXFILELEN>; /* file data */
|
|
};
|