From f8aec603aa7e9dad1316079d42c7efcc52b773fa Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 17 Feb 2020 22:38:13 +0100 Subject: src: initial extended netlink error reporting This patch correlates the in-kernel extended netlink error offset and the location information. Assuming 'foo' table does not exist, then error reporting shows: # nft delete table foo Error: Could not process rule: No such file or directory delete table foo ^^^ Similarly, if table uniquely identified by handle '1234' does not exist, then error reporting shows: # nft delete table handle 1234 Error: Could not process rule: No such file or directory delete table handle 1234 ^^^^ Assuming 'bar' chain does not exists in the kernel, while 'foo' does: # nft delete chain foo bar Error: Could not process rule: No such file or directory delete chain foo bar ^^^ This also gives us a hint when adding rules: # nft add rule ip foo bar counter Error: Could not process rule: No such file or directory add rule ip foo bar counter ^^^ This is based on ("src: basic support for extended netlink errors") from Florian Westphal, posted in 2018, with no netlink offset correlation support. Signed-off-by: Pablo Neira Ayuso --- include/rule.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/rule.h') diff --git a/include/rule.h b/include/rule.h index c232221e..ced63f3e 100644 --- a/include/rule.h +++ b/include/rule.h @@ -635,6 +635,8 @@ struct monitor { struct monitor *monitor_alloc(uint32_t format, uint32_t type, const char *event); void monitor_free(struct monitor *m); +#define NFT_NLATTR_LOC_MAX 8 + /** * struct cmd - command statement * @@ -666,6 +668,11 @@ struct cmd { struct markup *markup; struct obj *object; }; + struct { + uint16_t offset; + struct location *location; + } attr[NFT_NLATTR_LOC_MAX]; + int num_attrs; const void *arg; }; @@ -678,6 +685,8 @@ extern struct cmd *cmd_alloc_obj_ct(enum cmd_ops op, int type, const struct location *loc, struct obj *obj); extern void cmd_free(struct cmd *cmd); +void cmd_add_loc(struct cmd *cmd, uint16_t offset, struct location *loc); + #include #include -- cgit v1.2.3