xdrgen: Reject out-of-range program, version, and procedure numbersRFC 5531 assigns only unsigned constants to program, version, andprocedure numbers (Section 12.3) and encodes each as an unsigned
xdrgen: Reject out-of-range program, version, and procedure numbersRFC 5531 assigns only unsigned constants to program, version, andprocedure numbers (Section 12.3) and encodes each as an unsigned32-bit integer (Section 9), so a valid number falls within[0, 2**32 - 1]. RFC 4506 Section 6.2 permits a signed decimal constantfor XDR constants in general and sets no ceiling on magnitude, so thegrammar accepts an out-of-range value without complaint. It reachesgenerated code -- a negative procedure number emerges as an enumeratorsuch as "FOO = -5", valid C that compiles cleanly even though the wirefield is an unsigned 32-bit integer. Thus the xdrgen front end is theonly place that can reject the malformed value.Extend the semantic checks to require each program, version, andprocedure number to fall within [0, 2**32 - 1].Link: https://patch.msgid.link/20260712203451.124902-6-cel@kernel.orgSigned-off-by: Chuck Lever <cel@kernel.org>
show more ...
tools: Add xdrgenAdd a Python-based tool for translating XDR specifications into XDRencoder and decoder functions written in the Linux kernel's C codingstyle. The generator attempts to match the
tools: Add xdrgenAdd a Python-based tool for translating XDR specifications into XDRencoder and decoder functions written in the Linux kernel's C codingstyle. The generator attempts to match the usual C coding style ofthe Linux kernel's SunRPC consumers.This approach is similar to the netlink code generator intools/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 codeIn addition, converting the XDR layer to use memory-safe languagessuch as Rust will be easier if much of the code can be convertedautomatically.Tested-by: Jeff Layton <jlayton@kernel.org>Signed-off-by: Chuck Lever <chuck.lever@oracle.com>