|
|
911625 |
From 58d8baa70172bb9862276ac5f542248c88d3faf4 Mon Sep 17 00:00:00 2001
|
|
|
911625 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
911625 |
Date: Wed, 24 Jun 2020 18:48:14 +0200
|
|
|
911625 |
Subject: [PATCH] JSON: Improve performance of json_events_cb()
|
|
|
911625 |
|
|
|
911625 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1835300
|
|
|
911625 |
Upstream Status: nftables commit c96c7da272e33
|
|
|
911625 |
|
|
|
911625 |
commit c96c7da272e33a34770c4de4e3e50f7ed264672e
|
|
|
911625 |
Author: Phil Sutter <phil@nwl.cc>
|
|
|
911625 |
Date: Wed May 13 16:29:51 2020 +0200
|
|
|
911625 |
|
|
|
911625 |
JSON: Improve performance of json_events_cb()
|
|
|
911625 |
|
|
|
911625 |
The function tries to insert handles into JSON input for echo option.
|
|
|
911625 |
Yet there may be nothing to do if the given netlink message doesn't
|
|
|
911625 |
contain a handle, e.g. if it is an 'add element' command. Calling
|
|
|
911625 |
seqnum_to_json() is pointless overhead in that case, and if input is
|
|
|
911625 |
large this overhead is significant. Better wait with that call until
|
|
|
911625 |
after checking if the message is relevant at all.
|
|
|
911625 |
|
|
|
911625 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
911625 |
Acked-by: Eric Garver <eric@garver.life>
|
|
|
911625 |
---
|
|
|
911625 |
src/parser_json.c | 9 ++++++---
|
|
|
911625 |
1 file changed, 6 insertions(+), 3 deletions(-)
|
|
|
911625 |
|
|
|
911625 |
diff --git a/src/parser_json.c b/src/parser_json.c
|
|
|
911625 |
index c48faa8..ce8e566 100644
|
|
|
911625 |
--- a/src/parser_json.c
|
|
|
911625 |
+++ b/src/parser_json.c
|
|
|
911625 |
@@ -3845,12 +3845,15 @@ static uint64_t handle_from_nlmsg(const struct nlmsghdr *nlh)
|
|
|
911625 |
}
|
|
|
911625 |
int json_events_cb(const struct nlmsghdr *nlh, struct netlink_mon_handler *monh)
|
|
|
911625 |
{
|
|
|
911625 |
- json_t *tmp, *json = seqnum_to_json(nlh->nlmsg_seq);
|
|
|
911625 |
uint64_t handle = handle_from_nlmsg(nlh);
|
|
|
911625 |
+ json_t *tmp, *json;
|
|
|
911625 |
void *iter;
|
|
|
911625 |
|
|
|
911625 |
- /* might be anonymous set, ignore message */
|
|
|
911625 |
- if (!json || !handle)
|
|
|
911625 |
+ if (!handle)
|
|
|
911625 |
+ return MNL_CB_OK;
|
|
|
911625 |
+
|
|
|
911625 |
+ json = seqnum_to_json(nlh->nlmsg_seq);
|
|
|
911625 |
+ if (!json)
|
|
|
911625 |
return MNL_CB_OK;
|
|
|
911625 |
|
|
|
911625 |
tmp = json_object_get(json, "add");
|
|
|
911625 |
--
|
|
|
8ff5ad |
2.31.1
|
|
|
911625 |
|