]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xdrgen: XDR width for variable-length opaque
authorChuck Lever <chuck.lever@oracle.com>
Thu, 3 Oct 2024 18:54:36 +0000 (14:54 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 11 Nov 2024 18:42:02 +0000 (13:42 -0500)
The byte size of a variable-length opaque is conveyed in an unsigned
integer. If there is a specified maximum size, that is included in
the type's widths list.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
tools/net/sunrpc/xdrgen/xdr_ast.py

index 9fe7fa688caaf631cca2545c8c521399c0416694..94cdcfb36e775781790810ba8da293d85b8d0b36 100644 (file)
@@ -148,6 +148,21 @@ class _XdrVariableLengthOpaque(_XdrDeclaration):
     maxsize: str
     template: str = "variable_length_opaque"
 
+    def max_width(self) -> int:
+        """Return width of type in XDR_UNITS"""
+        return 1 + xdr_quadlen(self.maxsize)
+
+    def symbolic_width(self) -> List:
+        """Return list containing XDR width of type's components"""
+        widths = ["XDR_unsigned_int"]
+        if self.maxsize != "0":
+            widths.append("XDR_QUADLEN(" + self.maxsize + ")")
+        return widths
+
+    def __post_init__(self):
+        max_widths[self.name] = self.max_width()
+        symbolic_widths[self.name] = self.symbolic_width()
+
 
 @dataclass
 class _XdrString(_XdrDeclaration):