diff mbox series

[RFC,net-next,2/4] tools/net/ynl: Extract message encoding into _encode_message()

Message ID 20240225174619.18990-3-donald.hunter@gmail.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series tools/net/ynl: Add batch operations for nftables | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
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: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
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: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 30 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Donald Hunter Feb. 25, 2024, 5:46 p.m. UTC
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 mbox series

Patch

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)