diff mbox series

[net-next,1/4] ynl: support be16 in schemas

Message ID 20230318002340.1306356-2-sdf@google.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series ynl: fill in some gaps of ethtool spec | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers warning 2 maintainers not CCed: corbet@lwn.net linux-doc@vger.kernel.org
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 57 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Stanislav Fomichev March 18, 2023, 12:23 a.m. UTC
Used by ethtool spec.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 Documentation/netlink/genetlink-c.yaml      | 2 +-
 Documentation/netlink/genetlink-legacy.yaml | 4 ++--
 Documentation/netlink/genetlink.yaml        | 2 +-
 tools/net/ynl/lib/ynl.py                    | 7 +++++++
 4 files changed, 11 insertions(+), 4 deletions(-)

Comments

Jakub Kicinski March 18, 2023, 4:18 a.m. UTC | #1
On Fri, 17 Mar 2023 17:23:37 -0700 Stanislav Fomichev wrote:
> ynl: support be16 in schemas

https://docs.kernel.org/next/userspace-api/netlink/specs.html#byte-order

byte-order: big-endian

Looks like it's slightly supported in ynl-gen-c but indeed the CLI 
lib doesn't have the parsing, yet.
Stanislav Fomichev March 20, 2023, 6:03 p.m. UTC | #2
On Fri, Mar 17, 2023 at 9:18 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Fri, 17 Mar 2023 17:23:37 -0700 Stanislav Fomichev wrote:
> > ynl: support be16 in schemas
>
> https://docs.kernel.org/next/userspace-api/netlink/specs.html#byte-order
>
> byte-order: big-endian
>
> Looks like it's slightly supported in ynl-gen-c but indeed the CLI
> lib doesn't have the parsing, yet.

Didn't know about this, will try to convert.
diff mbox series

Patch

diff --git a/Documentation/netlink/genetlink-c.yaml b/Documentation/netlink/genetlink-c.yaml
index 8e8c17b0a6c6..1b057fc9326c 100644
--- a/Documentation/netlink/genetlink-c.yaml
+++ b/Documentation/netlink/genetlink-c.yaml
@@ -148,7 +148,7 @@  additionalProperties: False
               name:
                 type: string
               type: &attr-type
-                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
+                enum: [ unused, pad, flag, binary, u8, u16, be16, u32, u64, s32, s64,
                         string, nest, array-nest, nest-type-value ]
               doc:
                 description: Documentation of the attribute.
diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index 5dc6f1c07a97..3796d8be9045 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -119,7 +119,7 @@  additionalProperties: False
               name:
                 type: string
               type:
-                enum: [ u8, u16, u32, u64, s8, s16, s32, s64, string ]
+                enum: [ u8, u16, be16, u32, u64, s8, s16, s32, s64, string ]
               len:
                 $ref: '#/$defs/len-or-define'
         # End genetlink-legacy
@@ -171,7 +171,7 @@  additionalProperties: False
               name:
                 type: string
               type: &attr-type
-                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
+                enum: [ unused, pad, flag, binary, u8, u16, be16, u32, u64, s32, s64,
                         string, nest, array-nest, nest-type-value ]
               doc:
                 description: Documentation of the attribute.
diff --git a/Documentation/netlink/genetlink.yaml b/Documentation/netlink/genetlink.yaml
index d8b2cdeba058..a143221c3d2e 100644
--- a/Documentation/netlink/genetlink.yaml
+++ b/Documentation/netlink/genetlink.yaml
@@ -121,7 +121,7 @@  additionalProperties: False
               name:
                 type: string
               type: &attr-type
-                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
+                enum: [ unused, pad, flag, binary, u8, u16, be16, u32, u64, s32, s64,
                         string, nest, array-nest, nest-type-value ]
               doc:
                 description: Documentation of the attribute.
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 90764a83c646..21c015911803 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -81,6 +81,9 @@  from .nlspec import SpecFamily
     def as_u16(self):
         return struct.unpack("H", self.raw)[0]
 
+    def as_be16(self):
+        return struct.unpack(">H", self.raw)[0]
+
     def as_u32(self):
         return struct.unpack("I", self.raw)[0]
 
@@ -334,6 +337,8 @@  genl_family_name_to_id = None
                 attr_payload += self._add_attr(attr['nested-attributes'], subname, subvalue)
         elif attr["type"] == 'flag':
             attr_payload = b''
+        elif attr["type"] == 'be16':
+            attr_payload = struct.pack(">H", int(value))
         elif attr["type"] == 'u32':
             attr_payload = struct.pack("I", int(value))
         elif attr["type"] == 'string':
@@ -371,6 +376,8 @@  genl_family_name_to_id = None
                 decoded = subdict
             elif attr_spec['type'] == 'u8':
                 decoded = attr.as_u8()
+            elif attr_spec['type'] == 'be16':
+                decoded = attr.as_be16()
             elif attr_spec['type'] == 'u32':
                 decoded = attr.as_u32()
             elif attr_spec['type'] == 'u64':