From: Donald Hunter <donald.hunter@gmail.com>
To: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Jacob Keller <jacob.e.keller@intel.com>,
Jiri Pirko <jiri@resnulli.us>,
Stanislav Fomichev <sdf@google.com>
Cc: donald.hunter@redhat.com, Donald Hunter <donald.hunter@gmail.com>
Subject: [RFC net-next 2/4] tools/net/ynl: Extract message encoding into _encode_message()
Date: Sun, 25 Feb 2024 17:46:17 +0000 [thread overview]
Message-ID: <20240225174619.18990-3-donald.hunter@gmail.com> (raw)
In-Reply-To: <20240225174619.18990-1-donald.hunter@gmail.com>
Make the message encoding a separate method so that it can be reused for
encoding batch messages.
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
tools/net/ynl/lib/ynl.py | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index ac55aa5a3083..c6fc9588c235 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -831,6 +831,16 @@ class YnlFamily(SpecFamily):
return op['do']['request']['attributes'].copy()
+ def _encode_message(self, op, vals, nl_flags, req_seq):
+ msg = self.nlproto.message(nl_flags, op.req_value, 1, req_seq)
+ if op.fixed_header:
+ msg += self._encode_struct(op.fixed_header, vals)
+ search_attrs = SpaceAttrs(op.attr_set, vals)
+ for name, value in vals.items():
+ msg += self._add_attr(op.attr_set.name, name, value, search_attrs)
+ msg = _genl_msg_finalize(msg)
+ return msg
+
def _op(self, method, vals, flags=None, dump=False):
op = self.ops[method]
@@ -841,13 +851,7 @@ class YnlFamily(SpecFamily):
nl_flags |= Netlink.NLM_F_DUMP
req_seq = random.randint(1024, 65535)
- msg = self.nlproto.message(nl_flags, op.req_value, 1, req_seq)
- if op.fixed_header:
- msg += self._encode_struct(op.fixed_header, vals)
- search_attrs = SpaceAttrs(op.attr_set, vals)
- for name, value in vals.items():
- msg += self._add_attr(op.attr_set.name, name, value, search_attrs)
- msg = _genl_msg_finalize(msg)
+ msg = self._encode_message(op, vals, nl_flags, req_seq)
self.sock.send(msg, 0)
--
2.42.0
next prev parent reply other threads:[~2024-02-25 17:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-25 17:46 [RFC net-next 0/4] tools/net/ynl: Add batch operations for nftables Donald Hunter
2024-02-25 17:46 ` [RFC net-next 1/4] doc/netlink: Add batch op definitions to netlink-raw schema Donald Hunter
2024-02-27 16:11 ` Jakub Kicinski
2024-02-27 16:52 ` Donald Hunter
2024-02-27 17:13 ` Jakub Kicinski
2024-02-27 17:36 ` Donald Hunter
2024-02-27 17:49 ` Jakub Kicinski
2024-02-25 17:46 ` Donald Hunter [this message]
2024-02-25 17:46 ` [RFC net-next 3/4] tools/net/ynl: Add batch message encoding for nftables Donald Hunter
2024-02-25 17:46 ` [RFC net-next 4/4] doc/netlink/specs: Add draft nftables spec Donald Hunter
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=20240225174619.18990-3-donald.hunter@gmail.com \
--to=donald.hunter@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@redhat.com \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).