public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel•org>
To: davem@davemloft•net
Cc: netdev@vger•kernel.org, edumazet@google•com, pabeni@redhat•com,
	donald.hunter@gmail•com, Jakub Kicinski <kuba@kernel•org>
Subject: [PATCH net-next 1/5] tools: ynl: allow passing binary data
Date: Wed, 23 Aug 2023 17:30:52 -0700	[thread overview]
Message-ID: <20230824003056.1436637-2-kuba@kernel.org> (raw)
In-Reply-To: <20230824003056.1436637-1-kuba@kernel.org>

Recent changes made us assume that input for binary data is in hex.
When using YNL as a Python library it's possible to pass in raw bytes.
Bring the ability to do that back.

Signed-off-by: Jakub Kicinski <kuba@kernel•org>
---
 tools/net/ynl/lib/ynl.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 6951bcc7efdc..fa4f1c28efc5 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -410,7 +410,12 @@ genl_family_name_to_id = None
         elif attr["type"] == 'string':
             attr_payload = str(value).encode('ascii') + b'\x00'
         elif attr["type"] == 'binary':
-            attr_payload = bytes.fromhex(value)
+            if isinstance(value, bytes):
+                attr_payload = value
+            elif isinstance(value, str):
+                attr_payload = bytes.fromhex(value)
+            else:
+                raise Exception(f'Unknown type for binary attribute, value: {value}')
         elif attr['type'] in NlAttr.type_formats:
             format = NlAttr.get_format(attr['type'], attr.byte_order)
             attr_payload = format.pack(int(value))
-- 
2.41.0


  reply	other threads:[~2023-08-24  0:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24  0:30 [PATCH net-next 0/5] tools: ynl: handful of forward looking updates Jakub Kicinski
2023-08-24  0:30 ` Jakub Kicinski [this message]
2023-08-24 13:09   ` [PATCH net-next 1/5] tools: ynl: allow passing binary data Donald Hunter
2023-08-24  0:30 ` [PATCH net-next 2/5] tools: ynl-gen: set length of binary fields Jakub Kicinski
2023-08-24 13:16   ` Donald Hunter
2023-08-24  0:30 ` [PATCH net-next 3/5] tools: ynl-gen: fix collecting global policy attrs Jakub Kicinski
2023-08-24 13:11   ` Donald Hunter
2023-08-24  0:30 ` [PATCH net-next 4/5] tools: ynl-gen: support empty attribute lists Jakub Kicinski
2023-08-24 13:10   ` Donald Hunter
2023-08-24  0:30 ` [PATCH net-next 5/5] netlink: specs: fix indent in fou Jakub Kicinski
2023-08-24 13:17   ` Donald Hunter
2023-08-25  2:10 ` [PATCH net-next 0/5] tools: ynl: handful of forward looking updates patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230824003056.1436637-2-kuba@kernel.org \
    --to=kuba@kernel$(echo .)org \
    --cc=davem@davemloft$(echo .)net \
    --cc=donald.hunter@gmail$(echo .)com \
    --cc=edumazet@google$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=pabeni@redhat$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox