Blame SOURCES/0019-src-pass-struct-nft_ctx-through-struct-netlink_ctx.patch

34625f
From da71df5d7e2602279cfe713be01bd402c699cd4e Mon Sep 17 00:00:00 2001
34625f
From: Pablo Neira Ayuso <pablo@netfilter.org>
34625f
Date: Mon, 22 Oct 2018 21:18:19 +0200
34625f
Subject: [PATCH] src: pass struct nft_ctx through struct netlink_ctx
34625f
34625f
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
34625f
(cherry picked from commit 2dc07bcd7eaa56369dff01b596acf010308007d3)
34625f
34625f
Conflicts:
34625f
	src/evaluate.c
34625f
	src/mnl.c
34625f
	src/nfnl_osf.c
34625f
	src/rule.c
34625f
-> Missing osf support
34625f
-> Missing cleanups
34625f
34625f
Signed-off-by: Phil Sutter <psutter@redhat.com>
34625f
---
34625f
 include/netlink.h         |   9 +--
34625f
 include/rule.h            |  10 ++-
34625f
 src/evaluate.c            |  51 +++++----------
34625f
 src/libnftables.c         |   8 +--
34625f
 src/mnl.c                 |  22 +++----
34625f
 src/monitor.c             |  52 ++++++++--------
34625f
 src/netlink.c             |  47 +++++++-------
34625f
 src/netlink_delinearize.c |   4 +-
34625f
 src/rule.c                | 128 ++++++++++++++++++--------------------
34625f
 9 files changed, 147 insertions(+), 184 deletions(-)
34625f
34625f
diff --git a/include/netlink.h b/include/netlink.h
34625f
index d153e2be03ac5..31465ff16822e 100644
34625f
--- a/include/netlink.h
34625f
+++ b/include/netlink.h
34625f
@@ -35,26 +35,21 @@ extern const struct location netlink_location;
34625f
 /** 
34625f
  * struct netlink_ctx
34625f
  *
34625f
+ * @nft:	nftables context
34625f
  * @msgs:	message queue
34625f
  * @list:	list of parsed rules/chains/tables
34625f
  * @set:	current set
34625f
  * @data:	pointer to pass data to callback
34625f
  * @seqnum:	sequence number
34625f
- * @octx:	output context
34625f
- * @debug_mask:	display debugging information
34625f
- * @cache:	cache context
34625f
  */
34625f
 struct netlink_ctx {
34625f
-	struct mnl_socket	*nf_sock;
34625f
+	struct nft_ctx		*nft;
34625f
 	struct list_head	*msgs;
34625f
 	struct list_head	list;
34625f
 	struct set		*set;
34625f
 	const void		*data;
34625f
 	uint32_t		seqnum;
34625f
 	struct nftnl_batch	*batch;
34625f
-	unsigned int		debug_mask;
34625f
-	struct output_ctx	*octx;
34625f
-	struct nft_cache	*cache;
34625f
 };
34625f
 
34625f
 extern struct nftnl_table *alloc_nftnl_table(const struct handle *h);
34625f
diff --git a/include/rule.h b/include/rule.h
34625f
index b1d15c8725813..12c2984a14362 100644
34625f
--- a/include/rule.h
34625f
+++ b/include/rule.h
34625f
@@ -574,12 +574,10 @@ extern struct error_record *rule_postprocess(struct rule *rule);
34625f
 struct netlink_ctx;
34625f
 extern int do_command(struct netlink_ctx *ctx, struct cmd *cmd);
34625f
 
34625f
-extern int cache_update(struct mnl_socket *nf_sock, struct nft_cache *cache,
34625f
-			enum cmd_ops cmd, struct list_head *msgs, unsigned int debug_flag,
34625f
-			struct output_ctx *octx);
34625f
-extern void cache_flush(struct mnl_socket *nf_sock, struct nft_cache *cache,
34625f
-			enum cmd_ops cmd, struct list_head *msgs,
34625f
-			unsigned int debug_mask, struct output_ctx *octx);
34625f
+extern int cache_update(struct nft_ctx *ctx, enum cmd_ops cmd,
34625f
+			struct list_head *msgs);
34625f
+extern void cache_flush(struct nft_ctx *ctx, enum cmd_ops cmd,
34625f
+			struct list_head *msgs);
34625f
 extern void cache_release(struct nft_cache *cache);
34625f
 
34625f
 enum udata_type {
34625f
diff --git a/src/evaluate.c b/src/evaluate.c
34625f
index 5e9c6328fc692..809920748c0a9 100644
34625f
--- a/src/evaluate.c
34625f
+++ b/src/evaluate.c
34625f
@@ -184,8 +184,7 @@ static int expr_evaluate_symbol(struct eval_ctx *ctx, struct expr **expr)
34625f
 		}
34625f
 		break;
34625f
 	case SYMBOL_SET:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, ctx->cmd->op,
34625f
-				   ctx->msgs, ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, ctx->cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -2895,8 +2894,7 @@ static int rule_translate_index(struct eval_ctx *ctx, struct rule *rule)
34625f
 	int ret;
34625f
 
34625f
 	/* update cache with CMD_LIST so that rules are fetched, too */
34625f
-	ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, CMD_LIST,
34625f
-			ctx->msgs, ctx->nft->debug_mask, &ctx->nft->output);
34625f
+	ret = cache_update(ctx->nft, CMD_LIST, ctx->msgs);
34625f
 	if (ret < 0)
34625f
 		return ret;
34625f
 
34625f
@@ -3088,15 +3086,13 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 
34625f
 	switch (cmd->obj) {
34625f
 	case CMD_OBJ_SETELEM:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op,
34625f
-				   ctx->msgs, ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
 		return setelem_evaluate(ctx, &cmd->expr);
34625f
 	case CMD_OBJ_SET:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op,
34625f
-				   ctx->msgs, ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -3106,8 +3102,7 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 		handle_merge(&cmd->rule->handle, &cmd->handle);
34625f
 		return rule_evaluate(ctx, cmd->rule);
34625f
 	case CMD_OBJ_CHAIN:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op,
34625f
-				   ctx->msgs, ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -3115,8 +3110,7 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 	case CMD_OBJ_TABLE:
34625f
 		return table_evaluate(ctx, cmd->table);
34625f
 	case CMD_OBJ_FLOWTABLE:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op,
34625f
-				   ctx->msgs, ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -3138,8 +3132,7 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 
34625f
 	switch (cmd->obj) {
34625f
 	case CMD_OBJ_SETELEM:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op,
34625f
-				   ctx->msgs, ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -3165,8 +3158,7 @@ static int cmd_evaluate_get(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 	struct set *set;
34625f
 	int ret;
34625f
 
34625f
-	ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-			   ctx->nft->debug_mask, &ctx->nft->output);
34625f
+	ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 	if (ret < 0)
34625f
 		return ret;
34625f
 
34625f
@@ -3215,8 +3207,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 	struct set *set;
34625f
 	int ret;
34625f
 
34625f
-	ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-			   ctx->nft->debug_mask, &ctx->nft->output);
34625f
+	ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 	if (ret < 0)
34625f
 		return ret;
34625f
 
34625f
@@ -3313,8 +3304,7 @@ static int cmd_evaluate_reset(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 {
34625f
 	int ret;
34625f
 
34625f
-	ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-			   ctx->nft->debug_mask, &ctx->nft->output);
34625f
+	ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 	if (ret < 0)
34625f
 		return ret;
34625f
 
34625f
@@ -3343,8 +3333,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 
34625f
 	switch (cmd->obj) {
34625f
 	case CMD_OBJ_RULESET:
34625f
-		cache_flush(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-			    ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		cache_flush(ctx->nft, cmd->op, ctx->msgs);
34625f
 		break;
34625f
 	case CMD_OBJ_TABLE:
34625f
 		/* Flushing a table does not empty the sets in the table nor remove
34625f
@@ -3354,8 +3343,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 		/* Chains don't hold sets */
34625f
 		break;
34625f
 	case CMD_OBJ_SET:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-				   ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -3371,8 +3359,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 					 strerror(ENOENT));
34625f
 		return 0;
34625f
 	case CMD_OBJ_MAP:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-				   ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -3388,8 +3375,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 					 strerror(ENOENT));
34625f
 		return 0;
34625f
 	case CMD_OBJ_METER:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-				   ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -3417,8 +3403,7 @@ static int cmd_evaluate_rename(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 
34625f
 	switch (cmd->obj) {
34625f
 	case CMD_OBJ_CHAIN:
34625f
-		ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op,
34625f
-				   ctx->msgs, ctx->nft->debug_mask, &ctx->nft->output);
34625f
+		ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -3517,8 +3502,7 @@ static int cmd_evaluate_monitor(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 	uint32_t event;
34625f
 	int ret;
34625f
 
34625f
-	ret = cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-			   ctx->nft->debug_mask, &ctx->nft->output);
34625f
+	ret = cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 	if (ret < 0)
34625f
 		return ret;
34625f
 
34625f
@@ -3543,8 +3527,7 @@ static int cmd_evaluate_export(struct eval_ctx *ctx, struct cmd *cmd)
34625f
 		return cmd_error(ctx, &cmd->location,
34625f
 				 "this output type is not supported");
34625f
 
34625f
-	return cache_update(ctx->nft->nf_sock, &ctx->nft->cache, cmd->op, ctx->msgs,
34625f
-			    ctx->nft->debug_mask, &ctx->nft->output);
34625f
+	return cache_update(ctx->nft, cmd->op, ctx->msgs);
34625f
 }
34625f
 
34625f
 static int cmd_evaluate_import(struct eval_ctx *ctx, struct cmd *cmd)
34625f
diff --git a/src/libnftables.c b/src/libnftables.c
34625f
index 91af169ca7190..848c9cba65657 100644
34625f
--- a/src/libnftables.c
34625f
+++ b/src/libnftables.c
34625f
@@ -40,10 +40,7 @@ static int nft_netlink(struct nft_ctx *nft,
34625f
 		ctx.msgs = msgs;
34625f
 		ctx.seqnum = cmd->seqnum = mnl_seqnum_alloc(&seqnum);
34625f
 		ctx.batch = batch;
34625f
-		ctx.octx = &nft->output;
34625f
-		ctx.nf_sock = nf_sock;
34625f
-		ctx.cache = &nft->cache;
34625f
-		ctx.debug_mask = nft->debug_mask;
34625f
+		ctx.nft = nft;
34625f
 		init_list_head(&ctx.list);
34625f
 		ret = do_command(&ctx, cmd);
34625f
 		if (ret < 0) {
34625f
@@ -480,8 +477,7 @@ int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
34625f
 	LIST_HEAD(cmds);
34625f
 	int rc;
34625f
 
34625f
-	rc = cache_update(nft->nf_sock, &nft->cache, CMD_INVALID, &msgs,
34625f
-			  nft->debug_mask, &nft->output);
34625f
+	rc = cache_update(nft, CMD_INVALID, &msgs);
34625f
 	if (rc < 0)
34625f
 		return -1;
34625f
 
34625f
diff --git a/src/mnl.c b/src/mnl.c
34625f
index 42eacab74e4e0..fd89ee7f28aaf 100644
34625f
--- a/src/mnl.c
34625f
+++ b/src/mnl.c
34625f
@@ -51,13 +51,13 @@ nft_mnl_recv(struct netlink_ctx *ctx, uint32_t portid,
34625f
 	char buf[NFT_NLMSG_MAXSIZE];
34625f
 	int ret;
34625f
 
34625f
-	ret = mnl_socket_recvfrom(ctx->nf_sock, buf, sizeof(buf));
34625f
+	ret = mnl_socket_recvfrom(ctx->nft->nf_sock, buf, sizeof(buf));
34625f
 	while (ret > 0) {
34625f
 		ret = mnl_cb_run(buf, ret, ctx->seqnum, portid, cb, cb_data);
34625f
 		if (ret <= 0)
34625f
 			goto out;
34625f
 
34625f
-		ret = mnl_socket_recvfrom(ctx->nf_sock, buf, sizeof(buf));
34625f
+		ret = mnl_socket_recvfrom(ctx->nft->nf_sock, buf, sizeof(buf));
34625f
 	}
34625f
 out:
34625f
 	if (ret < 0 && errno == EAGAIN)
34625f
@@ -70,13 +70,13 @@ static int
34625f
 nft_mnl_talk(struct netlink_ctx *ctx, const void *data, unsigned int len,
34625f
 	     int (*cb)(const struct nlmsghdr *nlh, void *data), void *cb_data)
34625f
 {
34625f
-	uint32_t portid = mnl_socket_get_portid(ctx->nf_sock);
34625f
+	uint32_t portid = mnl_socket_get_portid(ctx->nft->nf_sock);
34625f
 
34625f
-	if (ctx->debug_mask & NFT_DEBUG_MNL)
34625f
-		mnl_nlmsg_fprintf(ctx->octx->output_fp, data, len,
34625f
+	if (ctx->nft->debug_mask & NFT_DEBUG_MNL)
34625f
+		mnl_nlmsg_fprintf(ctx->nft->output.output_fp, data, len,
34625f
 				  sizeof(struct nfgenmsg));
34625f
 
34625f
-	if (mnl_socket_sendto(ctx->nf_sock, data, len) < 0)
34625f
+	if (mnl_socket_sendto(ctx->nft->nf_sock, data, len) < 0)
34625f
 		return -1;
34625f
 
34625f
 	return nft_mnl_recv(ctx, portid, cb, cb_data);
34625f
@@ -225,23 +225,23 @@ static ssize_t mnl_nft_socket_sendmsg(const struct netlink_ctx *ctx)
34625f
 	};
34625f
 	uint32_t i;
34625f
 
34625f
-	mnl_set_sndbuffer(ctx->nf_sock, ctx->batch);
34625f
+	mnl_set_sndbuffer(ctx->nft->nf_sock, ctx->batch);
34625f
 	nftnl_batch_iovec(ctx->batch, iov, iov_len);
34625f
 
34625f
 	for (i = 0; i < iov_len; i++) {
34625f
-		if (ctx->debug_mask & NFT_DEBUG_MNL) {
34625f
-			mnl_nlmsg_fprintf(ctx->octx->output_fp,
34625f
+		if (ctx->nft->debug_mask & NFT_DEBUG_MNL) {
34625f
+			mnl_nlmsg_fprintf(ctx->nft->output.output_fp,
34625f
 					  iov[i].iov_base, iov[i].iov_len,
34625f
 					  sizeof(struct nfgenmsg));
34625f
 		}
34625f
 	}
34625f
 
34625f
-	return sendmsg(mnl_socket_get_fd(ctx->nf_sock), &msg, 0);
34625f
+	return sendmsg(mnl_socket_get_fd(ctx->nft->nf_sock), &msg, 0);
34625f
 }
34625f
 
34625f
 int mnl_batch_talk(struct netlink_ctx *ctx, struct list_head *err_list)
34625f
 {
34625f
-	struct mnl_socket *nl = ctx->nf_sock;
34625f
+	struct mnl_socket *nl = ctx->nft->nf_sock;
34625f
 	int ret, fd = mnl_socket_get_fd(nl), portid = mnl_socket_get_portid(nl);
34625f
 	char rcv_buf[MNL_SOCKET_BUFFER_SIZE];
34625f
 	fd_set readfds;
34625f
diff --git a/src/monitor.c b/src/monitor.c
34625f
index 213c40d119b4c..14ccbc5fe04ca 100644
34625f
--- a/src/monitor.c
34625f
+++ b/src/monitor.c
34625f
@@ -40,7 +40,7 @@
34625f
 #include <iface.h>
34625f
 #include <json.h>
34625f
 
34625f
-#define nft_mon_print(monh, ...) nft_print(monh->ctx->octx, __VA_ARGS__)
34625f
+#define nft_mon_print(monh, ...) nft_print(&monh->ctx->nft->output, __VA_ARGS__)
34625f
 
34625f
 static struct nftnl_table *netlink_table_alloc(const struct nlmsghdr *nlh)
34625f
 {
34625f
@@ -214,7 +214,7 @@ static int netlink_events_table_cb(const struct nlmsghdr *nlh, int type,
34625f
 
34625f
 		nft_mon_print(monh, "%s %s", family2str(t->handle.family),
34625f
 			      t->handle.table.name);
34625f
-		if (monh->ctx->octx->handle > 0)
34625f
+		if (monh->ctx->nft->output.handle > 0)
34625f
 			nft_mon_print(monh, " # handle %" PRIu64 "",
34625f
 				      t->handle.handle.id);
34625f
 		break;
34625f
@@ -245,7 +245,7 @@ static int netlink_events_chain_cb(const struct nlmsghdr *nlh, int type,
34625f
 
34625f
 		switch (type) {
34625f
 		case NFT_MSG_NEWCHAIN:
34625f
-			chain_print_plain(c, monh->ctx->octx);
34625f
+			chain_print_plain(c, &monh->ctx->nft->output);
34625f
 			break;
34625f
 		case NFT_MSG_DELCHAIN:
34625f
 			nft_mon_print(monh, "chain %s %s %s",
34625f
@@ -292,7 +292,7 @@ static int netlink_events_set_cb(const struct nlmsghdr *nlh, int type,
34625f
 
34625f
 		switch (type) {
34625f
 		case NFT_MSG_NEWSET:
34625f
-			set_print_plain(set, monh->ctx->octx);
34625f
+			set_print_plain(set, &monh->ctx->nft->output);
34625f
 			break;
34625f
 		case NFT_MSG_DELSET:
34625f
 			nft_mon_print(monh, "set %s %s %s", family,
34625f
@@ -386,7 +386,7 @@ static int netlink_events_setelem_cb(const struct nlmsghdr *nlh, int type,
34625f
 	family = nftnl_set_get_u32(nls, NFTNL_SET_FAMILY);
34625f
 	cmd = netlink_msg2cmd(type);
34625f
 
34625f
-	set = set_lookup_global(family, table, setname, monh->cache);
34625f
+	set = set_lookup_global(family, table, setname, &monh->ctx->nft->cache);
34625f
 	if (set == NULL) {
34625f
 		fprintf(stderr, "W: Received event for an unknown set.");
34625f
 		goto out;
34625f
@@ -417,7 +417,7 @@ static int netlink_events_setelem_cb(const struct nlmsghdr *nlh, int type,
34625f
 			goto out;
34625f
 		}
34625f
 		if (netlink_delinearize_setelem(nlse, dummyset,
34625f
-						monh->cache) < 0) {
34625f
+						&monh->ctx->nft->cache) < 0) {
34625f
 			set_free(dummyset);
34625f
 			nftnl_set_elems_iter_destroy(nlsei);
34625f
 			goto out;
34625f
@@ -435,7 +435,7 @@ static int netlink_events_setelem_cb(const struct nlmsghdr *nlh, int type,
34625f
 	case NFTNL_OUTPUT_DEFAULT:
34625f
 		nft_mon_print(monh, "%s element %s %s %s ",
34625f
 			      cmd, family2str(family), table, setname);
34625f
-		expr_print(dummyset->init, monh->ctx->octx);
34625f
+		expr_print(dummyset->init, &monh->ctx->nft->output);
34625f
 		break;
34625f
 	case NFTNL_OUTPUT_JSON:
34625f
 		dummyset->handle.family = family;
34625f
@@ -477,7 +477,7 @@ static int netlink_events_obj_cb(const struct nlmsghdr *nlh, int type,
34625f
 
34625f
 		switch (type) {
34625f
 		case NFT_MSG_NEWOBJ:
34625f
-			obj_print_plain(obj, monh->ctx->octx);
34625f
+			obj_print_plain(obj, &monh->ctx->nft->output);
34625f
 			break;
34625f
 		case NFT_MSG_DELOBJ:
34625f
 			nft_mon_print(monh, "%s %s %s %s",
34625f
@@ -513,7 +513,8 @@ static int netlink_events_rule_cb(const struct nlmsghdr *nlh, int type,
34625f
 
34625f
 	nlr = netlink_rule_alloc(nlh);
34625f
 	r = netlink_delinearize_rule(monh->ctx, nlr);
34625f
-	nlr_for_each_set(nlr, rule_map_decompose_cb, NULL, monh->cache);
34625f
+	nlr_for_each_set(nlr, rule_map_decompose_cb, NULL,
34625f
+			 &monh->ctx->nft->cache);
34625f
 	cmd = netlink_msg2cmd(type);
34625f
 
34625f
 	switch (monh->format) {
34625f
@@ -528,7 +529,7 @@ static int netlink_events_rule_cb(const struct nlmsghdr *nlh, int type,
34625f
 
34625f
 		switch (type) {
34625f
 		case NFT_MSG_NEWRULE:
34625f
-			rule_print(r, monh->ctx->octx);
34625f
+			rule_print(r, &monh->ctx->nft->output);
34625f
 
34625f
 			break;
34625f
 		case NFT_MSG_DELRULE:
34625f
@@ -557,7 +558,7 @@ static void netlink_events_cache_addtable(struct netlink_mon_handler *monh,
34625f
 	t = netlink_delinearize_table(monh->ctx, nlt);
34625f
 	nftnl_table_free(nlt);
34625f
 
34625f
-	table_add_hash(t, monh->cache);
34625f
+	table_add_hash(t, &monh->ctx->nft->cache);
34625f
 }
34625f
 
34625f
 static void netlink_events_cache_deltable(struct netlink_mon_handler *monh,
34625f
@@ -571,7 +572,7 @@ static void netlink_events_cache_deltable(struct netlink_mon_handler *monh,
34625f
 	h.family = nftnl_table_get_u32(nlt, NFTNL_TABLE_FAMILY);
34625f
 	h.table.name  = nftnl_table_get_str(nlt, NFTNL_TABLE_NAME);
34625f
 
34625f
-	t = table_lookup(&h, monh->cache);
34625f
+	t = table_lookup(&h, &monh->ctx->nft->cache);
34625f
 	if (t == NULL)
34625f
 		goto out;
34625f
 
34625f
@@ -601,7 +602,7 @@ static void netlink_events_cache_addset(struct netlink_mon_handler *monh,
34625f
 		goto out;
34625f
 	s->init = set_expr_alloc(monh->loc, s);
34625f
 
34625f
-	t = table_lookup(&s->handle, monh->cache);
34625f
+	t = table_lookup(&s->handle, &monh->ctx->nft->cache);
34625f
 	if (t == NULL) {
34625f
 		fprintf(stderr, "W: Unable to cache set: table not found.\n");
34625f
 		set_free(s);
34625f
@@ -628,7 +629,7 @@ static void netlink_events_cache_addsetelem(struct netlink_mon_handler *monh,
34625f
 	table   = nftnl_set_get_str(nls, NFTNL_SET_TABLE);
34625f
 	setname = nftnl_set_get_str(nls, NFTNL_SET_NAME);
34625f
 
34625f
-	set = set_lookup_global(family, table, setname, monh->cache);
34625f
+	set = set_lookup_global(family, table, setname, &monh->ctx->nft->cache);
34625f
 	if (set == NULL) {
34625f
 		fprintf(stderr,
34625f
 			"W: Unable to cache set_elem. Set not found.\n");
34625f
@@ -641,7 +642,8 @@ static void netlink_events_cache_addsetelem(struct netlink_mon_handler *monh,
34625f
 
34625f
 	nlse = nftnl_set_elems_iter_next(nlsei);
34625f
 	while (nlse != NULL) {
34625f
-		if (netlink_delinearize_setelem(nlse, set, monh->cache) < 0) {
34625f
+		if (netlink_delinearize_setelem(nlse, set,
34625f
+						&monh->ctx->nft->cache) < 0) {
34625f
 			fprintf(stderr,
34625f
 				"W: Unable to cache set_elem. "
34625f
 				"Delinearize failed.\n");
34625f
@@ -668,7 +670,7 @@ static void netlink_events_cache_delsets(struct netlink_mon_handler *monh,
34625f
 	struct nftnl_rule *nlr = netlink_rule_alloc(nlh);
34625f
 
34625f
 	nlr_for_each_set(nlr, netlink_events_cache_delset_cb, NULL,
34625f
-			 monh->cache);
34625f
+			 &monh->ctx->nft->cache);
34625f
 	nftnl_rule_free(nlr);
34625f
 }
34625f
 
34625f
@@ -691,7 +693,7 @@ static void netlink_events_cache_addobj(struct netlink_mon_handler *monh,
34625f
 	if (obj == NULL)
34625f
 		goto out;
34625f
 
34625f
-	t = table_lookup(&obj->handle, monh->cache);
34625f
+	t = table_lookup(&obj->handle, &monh->ctx->nft->cache);
34625f
 	if (t == NULL) {
34625f
 		fprintf(stderr, "W: Unable to cache object: table not found.\n");
34625f
 		obj_free(obj);
34625f
@@ -721,7 +723,7 @@ static void netlink_events_cache_delobj(struct netlink_mon_handler *monh,
34625f
 	type	 = nftnl_obj_get_u32(nlo, NFTNL_OBJ_TYPE);
34625f
 	h.handle.id	= nftnl_obj_get_u64(nlo, NFTNL_OBJ_HANDLE);
34625f
 
34625f
-	t = table_lookup(&h, monh->cache);
34625f
+	t = table_lookup(&h, &monh->ctx->nft->cache);
34625f
 	if (t == NULL) {
34625f
 		fprintf(stderr, "W: Unable to cache object: table not found.\n");
34625f
 		goto out;
34625f
@@ -835,7 +837,7 @@ static int netlink_events_newgen_cb(const struct nlmsghdr *nlh, int type,
34625f
 		nft_mon_print(monh, "# new generation %d", genid);
34625f
 		if (pid >= 0) {
34625f
 			nft_mon_print(monh, " by process %d", pid);
34625f
-			if (!monh->ctx->octx->numeric)
34625f
+			if (!monh->ctx->nft->output.numeric)
34625f
 				nft_mon_print(monh, " (%s)", name);
34625f
 		}
34625f
 		nft_mon_print(monh, "\n");
34625f
@@ -850,7 +852,7 @@ static int netlink_events_cb(const struct nlmsghdr *nlh, void *data)
34625f
 	uint16_t type = NFNL_MSG_TYPE(nlh->nlmsg_type);
34625f
 	struct netlink_mon_handler *monh = (struct netlink_mon_handler *)data;
34625f
 
34625f
-	netlink_events_debug(type, monh->debug_mask);
34625f
+	netlink_events_debug(type, monh->ctx->nft->debug_mask);
34625f
 	netlink_events_cache_update(monh, nlh, type);
34625f
 
34625f
 	if (!(monh->monitor_flags & (1 << type)))
34625f
@@ -901,11 +903,9 @@ int netlink_echo_callback(const struct nlmsghdr *nlh, void *data)
34625f
 		.loc = &netlink_location,
34625f
 		.monitor_flags = 0xffffffff,
34625f
 		.cache_needed = true,
34625f
-		.cache = ctx->cache,
34625f
-		.debug_mask = ctx->debug_mask,
34625f
 	};
34625f
 
34625f
-	if (!echo_monh.ctx->octx->echo)
34625f
+	if (!echo_monh.ctx->nft->output.echo)
34625f
 		return MNL_CB_OK;
34625f
 
34625f
 	return netlink_events_cb(nlh, &echo_monh);
34625f
@@ -929,7 +929,7 @@ int netlink_monitor(struct netlink_mon_handler *monhandler,
34625f
 			return -1;
34625f
 	}
34625f
 
34625f
-	return mnl_nft_event_listener(nf_sock, monhandler->debug_mask,
34625f
-				      monhandler->ctx->octx, netlink_events_cb,
34625f
-				      monhandler);
34625f
+	return mnl_nft_event_listener(nf_sock, monhandler->ctx->nft->debug_mask,
34625f
+				      &monhandler->ctx->nft->output,
34625f
+				      netlink_events_cb, monhandler);
34625f
 }
34625f
diff --git a/src/netlink.c b/src/netlink.c
34625f
index 4fd3f2dfefced..e16eb504fdef8 100644
34625f
--- a/src/netlink.c
34625f
+++ b/src/netlink.c
34625f
@@ -42,7 +42,7 @@
34625f
 #include <erec.h>
34625f
 #include <iface.h>
34625f
 
34625f
-#define nft_mon_print(monh, ...) nft_print(monh->ctx->octx, __VA_ARGS__)
34625f
+#define nft_mon_print(monh, ...) nft_print(&monh->ctx->nft->output, __VA_ARGS__)
34625f
 
34625f
 const struct input_descriptor indesc_netlink = {
34625f
 	.name	= "netlink",
34625f
@@ -475,10 +475,8 @@ int netlink_replace_rule_batch(struct netlink_ctx *ctx, const struct cmd *cmd)
34625f
 	struct nftnl_rule *nlr;
34625f
 	int err, flags = 0;
34625f
 
34625f
-	if (ctx->octx->echo) {
34625f
-		err = cache_update(ctx->nf_sock, ctx->cache,
34625f
-				   CMD_INVALID, ctx->msgs,
34625f
-				   ctx->debug_mask, ctx->octx);
34625f
+	if (ctx->nft->output.echo) {
34625f
+		err = cache_update(ctx->nft, CMD_INVALID, ctx->msgs);
34625f
 		if (err < 0)
34625f
 			return err;
34625f
 
34625f
@@ -507,9 +505,9 @@ int netlink_del_rule_batch(struct netlink_ctx *ctx, const struct cmd *cmd)
34625f
 
34625f
 void netlink_dump_rule(const struct nftnl_rule *nlr, struct netlink_ctx *ctx)
34625f
 {
34625f
-	FILE *fp = ctx->octx->output_fp;
34625f
+	FILE *fp = ctx->nft->output.output_fp;
34625f
 
34625f
-	if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
+	if (!(ctx->nft->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
 		return;
34625f
 
34625f
 	nftnl_rule_fprintf(fp, nlr, 0, 0);
34625f
@@ -575,9 +573,9 @@ static int netlink_flush_rules(struct netlink_ctx *ctx, const struct cmd *cmd)
34625f
 
34625f
 void netlink_dump_chain(const struct nftnl_chain *nlc, struct netlink_ctx *ctx)
34625f
 {
34625f
-	FILE *fp = ctx->octx->output_fp;
34625f
+	FILE *fp = ctx->nft->output.output_fp;
34625f
 
34625f
-	if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
+	if (!(ctx->nft->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
 		return;
34625f
 
34625f
 	nftnl_chain_fprintf(fp, nlc, 0, 0);
34625f
@@ -837,9 +835,9 @@ static const struct datatype *dtype_map_from_kernel(enum nft_data_types type)
34625f
 
34625f
 void netlink_dump_set(const struct nftnl_set *nls, struct netlink_ctx *ctx)
34625f
 {
34625f
-	FILE *fp = ctx->octx->output_fp;
34625f
+	FILE *fp = ctx->nft->output.output_fp;
34625f
 
34625f
-	if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
+	if (!(ctx->nft->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
 		return;
34625f
 
34625f
 	nftnl_set_fprintf(fp, nls, 0, 0);
34625f
@@ -1291,7 +1289,7 @@ out:
34625f
 static int list_setelem_cb(struct nftnl_set_elem *nlse, void *arg)
34625f
 {
34625f
 	struct netlink_ctx *ctx = arg;
34625f
-	return netlink_delinearize_setelem(nlse, ctx->set, ctx->cache);
34625f
+	return netlink_delinearize_setelem(nlse, ctx->set, &ctx->nft->cache);
34625f
 }
34625f
 
34625f
 int netlink_list_setelems(struct netlink_ctx *ctx, const struct handle *h,
34625f
@@ -1362,9 +1360,9 @@ int netlink_get_setelem(struct netlink_ctx *ctx, const struct handle *h,
34625f
 
34625f
 void netlink_dump_obj(struct nftnl_obj *nln, struct netlink_ctx *ctx)
34625f
 {
34625f
-	FILE *fp = ctx->octx->output_fp;
34625f
+	FILE *fp = ctx->nft->output.output_fp;
34625f
 
34625f
-	if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
+	if (!(ctx->nft->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
 		return;
34625f
 
34625f
 	nftnl_obj_fprintf(fp, nln, 0, 0);
34625f
@@ -1476,9 +1474,9 @@ static struct nftnl_flowtable *alloc_nftnl_flowtable(const struct handle *h,
34625f
 static void netlink_dump_flowtable(struct nftnl_flowtable *flo,
34625f
 				   struct netlink_ctx *ctx)
34625f
 {
34625f
-	FILE *fp = ctx->octx->output_fp;
34625f
+	FILE *fp = ctx->nft->output.output_fp;
34625f
 
34625f
-	if (!(ctx->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
+	if (!(ctx->nft->debug_mask & NFT_DEBUG_NETLINK) || !fp)
34625f
 		return;
34625f
 
34625f
 	nftnl_flowtable_fprintf(fp, flo, 0, 0);
34625f
@@ -1930,16 +1928,17 @@ int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
34625f
 	case NFT_TRACETYPE_RULE:
34625f
 		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_LL_HEADER) ||
34625f
 		    nftnl_trace_is_set(nlt, NFTNL_TRACE_NETWORK_HEADER))
34625f
-			trace_print_packet(nlt, monh->ctx->octx);
34625f
+			trace_print_packet(nlt, &monh->ctx->nft->output);
34625f
 
34625f
 		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_RULE_HANDLE))
34625f
-			trace_print_rule(nlt, monh->ctx->octx, monh->cache);
34625f
+			trace_print_rule(nlt, &monh->ctx->nft->output,
34625f
+					 &monh->ctx->nft->cache);
34625f
 		break;
34625f
 	case NFT_TRACETYPE_POLICY:
34625f
-		trace_print_hdr(nlt, monh->ctx->octx);
34625f
+		trace_print_hdr(nlt, &monh->ctx->nft->output);
34625f
 
34625f
 		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_POLICY)) {
34625f
-			trace_print_policy(nlt, monh->ctx->octx);
34625f
+			trace_print_policy(nlt, &monh->ctx->nft->output);
34625f
 			nft_mon_print(monh, " ");
34625f
 		}
34625f
 
34625f
@@ -1947,14 +1946,14 @@ int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
34625f
 			trace_print_expr(nlt, NFTNL_TRACE_MARK,
34625f
 					 meta_expr_alloc(&netlink_location,
34625f
 							 NFT_META_MARK),
34625f
-					 monh->ctx->octx);
34625f
+					 &monh->ctx->nft->output);
34625f
 		nft_mon_print(monh, "\n");
34625f
 		break;
34625f
 	case NFT_TRACETYPE_RETURN:
34625f
-		trace_print_hdr(nlt, monh->ctx->octx);
34625f
+		trace_print_hdr(nlt, &monh->ctx->nft->output);
34625f
 
34625f
 		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_VERDICT)) {
34625f
-			trace_print_verdict(nlt, monh->ctx->octx);
34625f
+			trace_print_verdict(nlt, &monh->ctx->nft->output);
34625f
 			nft_mon_print(monh, " ");
34625f
 		}
34625f
 
34625f
@@ -1962,7 +1961,7 @@ int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
34625f
 			trace_print_expr(nlt, NFTNL_TRACE_MARK,
34625f
 					 meta_expr_alloc(&netlink_location,
34625f
 							 NFT_META_MARK),
34625f
-					 monh->ctx->octx);
34625f
+					 &monh->ctx->nft->output);
34625f
 		nft_mon_print(monh, "\n");
34625f
 		break;
34625f
 	}
34625f
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
34625f
index ae84512c56f3a..bf990e9e979d5 100644
34625f
--- a/src/netlink_delinearize.c
34625f
+++ b/src/netlink_delinearize.c
34625f
@@ -2508,7 +2508,7 @@ struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
34625f
 
34625f
 	memset(&_ctx, 0, sizeof(_ctx));
34625f
 	_ctx.msgs = ctx->msgs;
34625f
-	_ctx.debug_mask = ctx->debug_mask;
34625f
+	_ctx.debug_mask = ctx->nft->debug_mask;
34625f
 
34625f
 	memset(&h, 0, sizeof(h));
34625f
 	h.family = nftnl_rule_get_u32(nlr, NFTNL_RULE_FAMILY);
34625f
@@ -2520,7 +2520,7 @@ struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
34625f
 		h.position.id = nftnl_rule_get_u64(nlr, NFTNL_RULE_POSITION);
34625f
 
34625f
 	pctx->rule = rule_alloc(&netlink_location, &h);
34625f
-	pctx->table = table_lookup(&h, ctx->cache);
34625f
+	pctx->table = table_lookup(&h, &ctx->nft->cache);
34625f
 	assert(pctx->table != NULL);
34625f
 
34625f
 	if (nftnl_rule_is_set(nlr, NFTNL_RULE_USERDATA)) {
34625f
diff --git a/src/rule.c b/src/rule.c
34625f
index 3b5468d00e79c..6acfa3ac1695c 100644
34625f
--- a/src/rule.c
34625f
+++ b/src/rule.c
34625f
@@ -86,7 +86,7 @@ static int cache_init_objects(struct netlink_ctx *ctx, enum cmd_ops cmd)
34625f
 	struct set *set;
34625f
 	int ret;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		ret = netlink_list_sets(ctx, &table->handle);
34625f
 		list_splice_tail_init(&ctx->list, &table->sets);
34625f
 
34625f
@@ -141,7 +141,7 @@ static int cache_init(struct netlink_ctx *ctx, enum cmd_ops cmd)
34625f
 	};
34625f
 	int ret;
34625f
 
34625f
-	ret = cache_init_tables(ctx, &handle, ctx->cache);
34625f
+	ret = cache_init_tables(ctx, &handle, &ctx->nft->cache);
34625f
 	if (ret < 0)
34625f
 		return ret;
34625f
 	ret = cache_init_objects(ctx, cmd);
34625f
@@ -151,20 +151,18 @@ static int cache_init(struct netlink_ctx *ctx, enum cmd_ops cmd)
34625f
 	return 0;
34625f
 }
34625f
 
34625f
-int cache_update(struct mnl_socket *nf_sock, struct nft_cache *cache,
34625f
-		 enum cmd_ops cmd, struct list_head *msgs, unsigned int debug_mask,
34625f
-		 struct output_ctx *octx)
34625f
+int cache_update(struct nft_ctx *nft, enum cmd_ops cmd, struct list_head *msgs)
34625f
 {
34625f
 	uint16_t genid;
34625f
 	int ret;
34625f
 	struct netlink_ctx ctx = {
34625f
 		.list		= LIST_HEAD_INIT(ctx.list),
34625f
-		.nf_sock	= nf_sock,
34625f
-		.cache		= cache,
34625f
+		.nft		= nft,
34625f
 		.msgs		= msgs,
34625f
-		.debug_mask	= debug_mask,
34625f
-		.octx		= octx,
34625f
+		.nft		= nft,
34625f
 	};
34625f
+	struct mnl_socket *nf_sock = nft->nf_sock;
34625f
+	struct nft_cache *cache = &nft->cache;
34625f
 
34625f
 replay:
34625f
 	ctx.seqnum = cache->seqnum++;
34625f
@@ -197,18 +195,14 @@ static void __cache_flush(struct list_head *table_list)
34625f
 	}
34625f
 }
34625f
 
34625f
-void cache_flush(struct mnl_socket *nf_sock, struct nft_cache *cache,
34625f
-		 enum cmd_ops cmd, struct list_head *msgs,
34625f
-		 unsigned int debug_mask, struct output_ctx *octx)
34625f
+void cache_flush(struct nft_ctx *nft, enum cmd_ops cmd, struct list_head *msgs)
34625f
 {
34625f
 	struct netlink_ctx ctx = {
34625f
 		.list		= LIST_HEAD_INIT(ctx.list),
34625f
-		.nf_sock	= nf_sock,
34625f
-		.cache		= cache,
34625f
+		.nft		= nft,
34625f
 		.msgs		= msgs,
34625f
-		.debug_mask	= debug_mask,
34625f
-		.octx		= octx,
34625f
 	};
34625f
+	struct nft_cache *cache = &nft->cache;
34625f
 
34625f
 	__cache_flush(&cache->list);
34625f
 	cache->genid = netlink_genid_get(&ctx;;
34625f
@@ -1121,12 +1115,12 @@ static int do_add_setelems(struct netlink_ctx *ctx, struct cmd *cmd,
34625f
 	struct table *table;
34625f
 	struct set *set;
34625f
 
34625f
-	table = table_lookup(h, ctx->cache);
34625f
+	table = table_lookup(h, &ctx->nft->cache);
34625f
 	set = set_lookup(table, h->set.name);
34625f
 
34625f
 	if (set->flags & NFT_SET_INTERVAL &&
34625f
 	    set_to_intervals(ctx->msgs, set, init, true,
34625f
-			     ctx->debug_mask, set->automerge) < 0)
34625f
+			     ctx->nft->debug_mask, set->automerge) < 0)
34625f
 		return -1;
34625f
 
34625f
 	return __do_add_setelems(ctx, h, set, init, flags);
34625f
@@ -1140,7 +1134,7 @@ static int do_add_set(struct netlink_ctx *ctx, const struct cmd *cmd,
34625f
 	if (set->init != NULL) {
34625f
 		if (set->flags & NFT_SET_INTERVAL &&
34625f
 		    set_to_intervals(ctx->msgs, set, set->init, true,
34625f
-				     ctx->debug_mask, set->automerge) < 0)
34625f
+				     ctx->nft->debug_mask, set->automerge) < 0)
34625f
 			return -1;
34625f
 	}
34625f
 	if (netlink_add_set_batch(ctx, cmd, flags) < 0)
34625f
@@ -1156,11 +1150,10 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl)
34625f
 {
34625f
 	uint32_t flags = excl ? NLM_F_EXCL : 0;
34625f
 
34625f
-	if (ctx->octx->echo) {
34625f
+	if (ctx->nft->output.echo) {
34625f
 		int ret;
34625f
 
34625f
-		ret = cache_update(ctx->nf_sock, ctx->cache, cmd->obj,
34625f
-				   ctx->msgs, ctx->debug_mask, ctx->octx);
34625f
+		ret = cache_update(ctx->nft, cmd->obj, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -1206,11 +1199,10 @@ static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 {
34625f
 	uint32_t flags = 0;
34625f
 
34625f
-	if (ctx->octx->echo) {
34625f
+	if (ctx->nft->output.echo) {
34625f
 		int ret;
34625f
 
34625f
-		ret = cache_update(ctx->nf_sock, ctx->cache, cmd->obj,
34625f
-				   ctx->msgs, ctx->debug_mask, ctx->octx);
34625f
+		ret = cache_update(ctx->nft, cmd->obj, ctx->msgs);
34625f
 		if (ret < 0)
34625f
 			return ret;
34625f
 
34625f
@@ -1233,12 +1225,12 @@ static int do_delete_setelems(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	struct table *table;
34625f
 	struct set *set;
34625f
 
34625f
-	table = table_lookup(h, ctx->cache);
34625f
+	table = table_lookup(h, &ctx->nft->cache);
34625f
 	set = set_lookup(table, h->set.name);
34625f
 
34625f
 	if (set->flags & NFT_SET_INTERVAL &&
34625f
 	    set_to_intervals(ctx->msgs, set, expr, false,
34625f
-			     ctx->debug_mask, set->automerge) < 0)
34625f
+			     ctx->nft->debug_mask, set->automerge) < 0)
34625f
 		return -1;
34625f
 
34625f
 	if (netlink_delete_setelems_batch(ctx, cmd) < 0)
34625f
@@ -1278,7 +1270,7 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 static int do_command_export(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 {
34625f
 	struct nftnl_ruleset *rs;
34625f
-	FILE *fp = ctx->octx->output_fp;
34625f
+	FILE *fp = ctx->nft->output.output_fp;
34625f
 
34625f
 	do {
34625f
 		rs = netlink_dump_ruleset(ctx, &cmd->handle, &cmd->location);
34625f
@@ -1288,7 +1280,7 @@ static int do_command_export(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 
34625f
 	nftnl_ruleset_fprintf(fp, rs, cmd->markup->format, NFTNL_OF_EVENT_NEW);
34625f
 
34625f
-	nft_print(ctx->octx, "\n");
34625f
+	nft_print(&ctx->nft->output, "\n");
34625f
 
34625f
 	nftnl_ruleset_free(rs);
34625f
 	return 0;
34625f
@@ -1319,7 +1311,7 @@ static int do_command_import(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 static int do_list_table(struct netlink_ctx *ctx, struct cmd *cmd,
34625f
 			 struct table *table)
34625f
 {
34625f
-	table_print(table, ctx->octx);
34625f
+	table_print(table, &ctx->nft->output);
34625f
 	return 0;
34625f
 }
34625f
 
34625f
@@ -1333,12 +1325,12 @@ static int do_list_sets(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	struct table *table;
34625f
 	struct set *set;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
 
34625f
-		nft_print(ctx->octx, "table %s %s {\n",
34625f
+		nft_print(&ctx->nft->output, "table %s %s {\n",
34625f
 			  family2str(table->handle.family),
34625f
 			  table->handle.table.name);
34625f
 
34625f
@@ -1353,11 +1345,11 @@ static int do_list_sets(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 			if (cmd->obj == CMD_OBJ_MAPS &&
34625f
 			    !(set->flags & NFT_SET_MAP))
34625f
 				continue;
34625f
-			set_print_declaration(set, &opts, ctx->octx);
34625f
-			nft_print(ctx->octx, "%s}%s", opts.tab, opts.nl);
34625f
+			set_print_declaration(set, &opts, &ctx->nft->output);
34625f
+			nft_print(&ctx->nft->output, "%s}%s", opts.tab, opts.nl);
34625f
 		}
34625f
 
34625f
-		nft_print(ctx->octx, "}\n");
34625f
+		nft_print(&ctx->nft->output, "}\n");
34625f
 	}
34625f
 	return 0;
34625f
 }
34625f
@@ -1588,14 +1580,14 @@ static int do_list_obj(struct netlink_ctx *ctx, struct cmd *cmd, uint32_t type)
34625f
 	struct table *table;
34625f
 	struct obj *obj;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
 
34625f
 		if (cmd->handle.table.name != NULL &&
34625f
 		    !strcmp(cmd->handle.table.name, table->handle.table.name)) {
34625f
-			nft_print(ctx->octx, "table %s %s {\n",
34625f
+			nft_print(&ctx->nft->output, "table %s %s {\n",
34625f
 				  family2str(table->handle.family),
34625f
 				  cmd->handle.table.name);
34625f
 		} else
34625f
@@ -1607,10 +1599,10 @@ static int do_list_obj(struct netlink_ctx *ctx, struct cmd *cmd, uint32_t type)
34625f
 			     strcmp(cmd->handle.obj.name, obj->handle.obj.name)))
34625f
 				continue;
34625f
 
34625f
-			obj_print_declaration(obj, &opts, ctx->octx);
34625f
+			obj_print_declaration(obj, &opts, &ctx->nft->output);
34625f
 		}
34625f
 
34625f
-		nft_print(ctx->octx, "}\n");
34625f
+		nft_print(&ctx->nft->output, "}\n");
34625f
 	}
34625f
 	return 0;
34625f
 }
34625f
@@ -1705,21 +1697,21 @@ static int do_list_flowtables(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	struct flowtable *flowtable;
34625f
 	struct table *table;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
 
34625f
-		nft_print(ctx->octx, "table %s %s {\n",
34625f
+		nft_print(&ctx->nft->output, "table %s %s {\n",
34625f
 			  family2str(table->handle.family),
34625f
 			  table->handle.table.name);
34625f
 
34625f
 		list_for_each_entry(flowtable, &table->flowtables, list) {
34625f
-			flowtable_print_declaration(flowtable, &opts, ctx->octx);
34625f
-			nft_print(ctx->octx, "%s}%s", opts.tab, opts.nl);
34625f
+			flowtable_print_declaration(flowtable, &opts, &ctx->nft->output);
34625f
+			nft_print(&ctx->nft->output, "%s}%s", opts.tab, opts.nl);
34625f
 		}
34625f
 
34625f
-		nft_print(ctx->octx, "}\n");
34625f
+		nft_print(&ctx->nft->output, "}\n");
34625f
 	}
34625f
 	return 0;
34625f
 }
34625f
@@ -1729,7 +1721,7 @@ static int do_list_ruleset(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	unsigned int family = cmd->handle.family;
34625f
 	struct table *table;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (family != NFPROTO_UNSPEC &&
34625f
 		    table->handle.family != family)
34625f
 			continue;
34625f
@@ -1750,12 +1742,12 @@ static int do_list_tables(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 {
34625f
 	struct table *table;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
 
34625f
-		nft_print(ctx->octx, "table %s %s\n",
34625f
+		nft_print(&ctx->nft->output, "table %s %s\n",
34625f
 			  family2str(table->handle.family),
34625f
 			  table->handle.table.name);
34625f
 	}
34625f
@@ -1776,17 +1768,17 @@ static int do_list_chain(struct netlink_ctx *ctx, struct cmd *cmd,
34625f
 {
34625f
 	struct chain *chain;
34625f
 
34625f
-	table_print_declaration(table, ctx->octx);
34625f
+	table_print_declaration(table, &ctx->nft->output);
34625f
 
34625f
 	list_for_each_entry(chain, &table->chains, list) {
34625f
 		if (chain->handle.family != cmd->handle.family ||
34625f
 		    strcmp(cmd->handle.chain.name, chain->handle.chain.name) != 0)
34625f
 			continue;
34625f
 
34625f
-		chain_print(chain, ctx->octx);
34625f
+		chain_print(chain, &ctx->nft->output);
34625f
 	}
34625f
 
34625f
-	nft_print(ctx->octx, "}\n");
34625f
+	nft_print(&ctx->nft->output, "}\n");
34625f
 
34625f
 	return 0;
34625f
 }
34625f
@@ -1796,18 +1788,18 @@ static int do_list_chains(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	struct table *table;
34625f
 	struct chain *chain;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
 
34625f
-		table_print_declaration(table, ctx->octx);
34625f
+		table_print_declaration(table, &ctx->nft->output);
34625f
 
34625f
 		list_for_each_entry(chain, &table->chains, list) {
34625f
-			chain_print_declaration(chain, ctx->octx);
34625f
-			nft_print(ctx->octx, "\t}\n");
34625f
+			chain_print_declaration(chain, &ctx->nft->output);
34625f
+			nft_print(&ctx->nft->output, "\t}\n");
34625f
 		}
34625f
-		nft_print(ctx->octx, "}\n");
34625f
+		nft_print(&ctx->nft->output, "}\n");
34625f
 	}
34625f
 
34625f
 	return 0;
34625f
@@ -1816,9 +1808,9 @@ static int do_list_chains(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 static void __do_list_set(struct netlink_ctx *ctx, struct cmd *cmd,
34625f
 			  struct table *table, struct set *set)
34625f
 {
34625f
-	table_print_declaration(table, ctx->octx);
34625f
-	set_print(set, ctx->octx);
34625f
-	nft_print(ctx->octx, "}\n");
34625f
+	table_print_declaration(table, &ctx->nft->output);
34625f
+	set_print(set, &ctx->nft->output);
34625f
+	nft_print(&ctx->nft->output, "}\n");
34625f
 }
34625f
 
34625f
 static int do_list_set(struct netlink_ctx *ctx, struct cmd *cmd,
34625f
@@ -1839,11 +1831,11 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 {
34625f
 	struct table *table = NULL;
34625f
 
34625f
-	if (ctx->octx->json)
34625f
+	if (ctx->nft->output.json)
34625f
 		return do_command_list_json(ctx, cmd);
34625f
 
34625f
 	if (cmd->handle.table.name != NULL)
34625f
-		table = table_lookup(&cmd->handle, ctx->cache);
34625f
+		table = table_lookup(&cmd->handle, &ctx->nft->cache);
34625f
 
34625f
 	switch (cmd->obj) {
34625f
 	case CMD_OBJ_TABLE:
34625f
@@ -1925,7 +1917,7 @@ static int do_command_get(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	struct table *table = NULL;
34625f
 
34625f
 	if (cmd->handle.table.name != NULL)
34625f
-		table = table_lookup(&cmd->handle, ctx->cache);
34625f
+		table = table_lookup(&cmd->handle, &ctx->nft->cache);
34625f
 
34625f
 	switch (cmd->obj) {
34625f
 	case CMD_OBJ_SETELEM:
34625f
@@ -1964,7 +1956,7 @@ static int do_command_reset(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 
34625f
 	ret = netlink_reset_objs(ctx, cmd, type, dump);
34625f
 	list_for_each_entry_safe(obj, next, &ctx->list, list) {
34625f
-		table = table_lookup(&obj->handle, ctx->cache);
34625f
+		table = table_lookup(&obj->handle, &ctx->nft->cache);
34625f
 		list_move(&obj->list, &table->objs);
34625f
 	}
34625f
 	if (ret < 0)
34625f
@@ -1994,7 +1986,7 @@ static int do_command_flush(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 
34625f
 static int do_command_rename(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 {
34625f
-	struct table *table = table_lookup(&cmd->handle, ctx->cache);
34625f
+	struct table *table = table_lookup(&cmd->handle, &ctx->nft->cache);
34625f
 	struct chain *chain;
34625f
 
34625f
 	switch (cmd->obj) {
34625f
@@ -2034,8 +2026,8 @@ static int do_command_monitor(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 		.format		= cmd->monitor->format,
34625f
 		.ctx		= ctx,
34625f
 		.loc		= &cmd->location,
34625f
-		.cache		= ctx->cache,
34625f
-		.debug_mask	= ctx->debug_mask,
34625f
+		.cache		= &ctx->nft->cache,
34625f
+		.debug_mask	= ctx->nft->debug_mask,
34625f
 	};
34625f
 
34625f
 	monhandler.cache_needed = need_cache(cmd);
34625f
@@ -2044,7 +2036,7 @@ static int do_command_monitor(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 		struct chain *chain;
34625f
 		int ret;
34625f
 
34625f
-		list_for_each_entry(t, &ctx->cache->list, list) {
34625f
+		list_for_each_entry(t, &ctx->nft->cache.list, list) {
34625f
 			list_for_each_entry(s, &t->sets, list)
34625f
 				s->init = set_expr_alloc(&cmd->location, s);
34625f
 
34625f
@@ -2070,7 +2062,7 @@ static int do_command_monitor(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 		}
34625f
 	}
34625f
 
34625f
-	return netlink_monitor(&monhandler, ctx->nf_sock);
34625f
+	return netlink_monitor(&monhandler, ctx->nft->nf_sock);
34625f
 }
34625f
 
34625f
 static int do_command_describe(struct netlink_ctx *ctx, struct cmd *cmd,
34625f
@@ -2129,7 +2121,7 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	case CMD_MONITOR:
34625f
 		return do_command_monitor(ctx, cmd);
34625f
 	case CMD_DESCRIBE:
34625f
-		return do_command_describe(ctx, cmd, ctx->octx);
34625f
+		return do_command_describe(ctx, cmd, &ctx->nft->output);
34625f
 	default:
34625f
 		BUG("invalid command object type %u\n", cmd->obj);
34625f
 	}
34625f
-- 
34625f
2.19.0
34625f