From bb32d8db9a125d9676f87866e48ffbf0221ec16a Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 26 Oct 2018 15:01:38 +0200 Subject: JSON: Add support for echo option The basic principle is to not return a JSON object freshly created from netlink responses, but just update the existing user-provided one to make sure callers get back exactly what they expect. To achieve that, keep the parsed JSON object around in a global variable ('cur_root') and provide a custom callback to insert handles into it from received netlink messages. The tricky bit here is updating rules since unique identification is problematic. Therefore drop possibly present handles from input and later assume updates are received in order so the first rule not having a handle set is the right one. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- include/netlink.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/netlink.h') diff --git a/include/netlink.h b/include/netlink.h index 5ff129ed..a8528d59 100644 --- a/include/netlink.h +++ b/include/netlink.h @@ -55,6 +55,12 @@ struct netlink_ctx { extern struct nftnl_expr *alloc_nft_expr(const char *name); extern void alloc_setelem_cache(const struct expr *set, struct nftnl_set *nls); +extern struct nftnl_table *netlink_table_alloc(const struct nlmsghdr *nlh); +extern struct nftnl_chain *netlink_chain_alloc(const struct nlmsghdr *nlh); +extern struct nftnl_set *netlink_set_alloc(const struct nlmsghdr *nlh); +extern struct nftnl_obj *netlink_obj_alloc(const struct nlmsghdr *nlh); +extern struct nftnl_rule *netlink_rule_alloc(const struct nlmsghdr *nlh); + struct nft_data_linearize { uint32_t len; uint32_t value[4]; -- cgit v1.2.3