parser_json: Rewrite echo support
Phil Sutter
reviewerPATCH 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.
--- 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
@@ -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
Quoted 10 lines · Phil Sutter
Instead of guessing which object to update with retrieved handle, introduce a list containing struct cmd <->
json_tassociations. 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. Usingjson_cmd_assoclist 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!