diff mbox series

[RFC,net-next,3/4] tools/net/ynl: Add batch message encoding for nftables

Message ID 20240225174619.18990-4-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, 29 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
The nftables families use batch operations for create, update and delete
operations. For ops that have 'is-batch: true' wrap them in begin-batch
and end-batch messages.

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
 tools/net/ynl/lib/ynl.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index c6fc9588c235..3a4af3c5a6a7 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -841,6 +841,12 @@  class YnlFamily(SpecFamily):
         msg = _genl_msg_finalize(msg)
         return msg
 
+    def _encode_batch_message(self, name, nl_flags, req_seq):
+        msg = self.yaml.get('operations').get(name)
+        op = self.ops[msg['operation']]
+        params = msg['parameters']
+        return self._encode_message(op, params, nl_flags, req_seq)
+
     def _op(self, method, vals, flags=None, dump=False):
         op = self.ops[method]
 
@@ -851,7 +857,16 @@  class YnlFamily(SpecFamily):
             nl_flags |= Netlink.NLM_F_DUMP
 
         req_seq = random.randint(1024, 65535)
-        msg = self._encode_message(op, vals, nl_flags, req_seq)
+        msg = b''
+
+        is_batch = op['do']['request'].get('is-batch', False)
+        if is_batch:
+            msg += self._encode_batch_message('begin-batch', nl_flags, req_seq)
+
+        msg += self._encode_message(op, vals, nl_flags, req_seq)
+
+        if is_batch:
+            msg += self._encode_batch_message('end-batch', nl_flags, req_seq)
 
         self.sock.send(msg, 0)