xdrgen: Fix opaque and string encoders for unbounded membersThe variable-length opaque and string encoder templates emit anunconditional bound check, "if (value->NAME.len > MAXSIZE) returnfalse".
xdrgen: Fix opaque and string encoders for unbounded membersThe variable-length opaque and string encoder templates emit anunconditional bound check, "if (value->NAME.len > MAXSIZE) returnfalse". XDR represents an unbounded specifier (opaque foo<>, stringfoo<>) as a maxsize of 0, so for an unbounded member the checkdegenerates to "len > 0" and the generated encoder refuses everynon-empty value.The decoder does not share this defect. It delegates toxdrgen_decode_opaque() and xdrgen_decode_string(), which treat amaxlen of 0 as unbounded and skip the length check. The siblingvariable-length array templates already guard their bound checkwith maxsize != "0".Guard the bound check the same way in each affected template -- thestruct and pointer forms of both the opaque and string encoders --so an unbounded member encodes a payload of any length while abounded member keeps its limit.An explicit zero-length bound (foo<0>) parses to the same maxsize of0 and so also skips the check; xdrgen does not distinguish it fromthe unbounded form, matching the decoder and the array encoders.Fixes: 4b132aacb076 ("tools: Add xdrgen")Link: https://patch.msgid.link/20260712193122.116845-6-cel@kernel.orgSigned-off-by: Chuck Lever <cel@kernel.org>
show more ...
xdrgen: Don't generate unnecessary semicolonThe Jinja2 templates add a semicolon at the end of every function.The C language does not require this punctuation.Signed-off-by: Chuck Lever <chuck.l
xdrgen: Don't generate unnecessary semicolonThe Jinja2 templates add a semicolon at the end of every function.The C language does not require this punctuation.Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
xdrgen: Fix code generated for counted arraysWhen an XDR counted array has a maximum element count, xdrgen addsa bounds check to the encoder or decoder for that type. But in caseswhere the .x pro
xdrgen: Fix code generated for counted arraysWhen an XDR counted array has a maximum element count, xdrgen addsa bounds check to the encoder or decoder for that type. But in caseswhere the .x provides no maximum element count, such asstruct notify4 { /* composed from notify_type4 or notify_deviceid_type4 */ bitmap4 notify_mask; notifylist4 notify_vals;};struct CB_NOTIFY4args { stateid4 cna_stateid; nfs_fh4 cna_fh; notify4 cna_changes<>;};xdrgen is supposed to omit that bounds check. Some of the Jinja2templates handle that correctly, but a few are incorrect and leavethe bounds check in place with a maximum of zero, which causesencoding/decoding of that type to fail unconditionally.Reported-by: Jeff Layton <jlayton@kernel.org>Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
xdrgen: Rename "variable-length strings"I misread RFC 4506. The built-in data type is called simply"string", as there is no fixed-length variety.Signed-off-by: Chuck Lever <chuck.lever@oracle.co
xdrgen: Rename "variable-length strings"I misread RFC 4506. The built-in data type is called simply"string", as there is no fixed-length variety.Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
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>