Skip to contentSkip to conversation

parser_json: Rewrite echo support

PATCH Applied Phil Sutter 2 participants 2 messages Apr 2, 2019 – Apr 3, 2019 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 parser_json: Rewrite echo support

Instead of guessing which object to update with retrieved handle, introduce a list containing struct cmd <-> json_t associations. Upon batch commit, allocated cmd objects are assigned a unique netlink sequence number. Monitor events contain that number as well, so they may be associated to the cmd object which triggered them. Using json_cmd_assoc list the event may in turn be associated to the input's JSON object which should receive the handle value.

This also fixes incorrect behaviour if JSON input contained "insert" commands.

Fixes bb32d8db9a125 ("JSON: Add support for echo option")
---
 py/nftables.py              |   3 +
 src/parser_json.c           | 283 ++++++++++++------------------------
 tests/json_echo/run-test.py | 206 ++++++++++++++++++--------
 3 files changed, 243 insertions(+), 249 deletions(-)
py/nftables.py +3 -0
index 6891cb1ce177b..f07163573f9a6 100644
@@ -106,6 +106,9 @@ class Nftables:
         self.nft_ctx_buffer_output(self.__ctx)
         self.nft_ctx_buffer_error(self.__ctx)
 
+    def __del__(self):
+        self.nft_ctx_free(self.__ctx)
+
     def __get_output_flag(self, name):
         flag = self.output_flags[name]
         return self.nft_ctx_output_get_flags(self.__ctx) & flag
src/parser_json.c +95 -188

326 lines not on this page · raw message

tests/json_echo/run-test.py +145 -61

264 lines not on this page · raw message

Signature · 1 line
2.21.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Phil Sutter

Instead of guessing which object to update with retrieved handle, introduce a list containing struct cmd <-> json_t associations. Upon batch commit, allocated cmd objects are assigned a unique netlink sequence number. Monitor events contain that number as well, so they may be associated to the cmd object which triggered them. Using json_cmd_assoc list the event may in turn be associated to the input's JSON object which should receive the handle value.

This also fixes incorrect behaviour if JSON input contained "insert" commands.

Applied, thanks Phil!