rule: larger number of error locations
Pablo Neira Ayuso
maintainerPATCH 1/2 rule: larger number of error locations
Statically store up to 32 locations per command, if the number of locations is larger than 32, then skip rather than hit assertion.
Revisit this later to dynamically store location per command using a hashtable.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/rule.h | 2 +- src/rule.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
include/rule.h +1 -1
@@ -666,7 +666,7 @@ 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 +#define NFT_NLATTR_LOC_MAX 32/** * struct cmd - command statement
src/rule.c +3 -1
@@ -1475,7 +1475,9 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,void cmd_add_loc (struct cmd *cmd,uint16_t offset,struct location *loc) { -assert (cmd->num_attrs <NFT_NLATTR_LOC_MAX ); +if (cmd->num_attrs >NFT_NLATTR_LOC_MAX ) +return ; + cmd->attr[cmd->num_attrs].offset = offset; cmd->attr[cmd->num_attrs].location = loc; cmd->num_attrs++;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 2/2 src: improve rule error reporting
Kernel provides information regarding expression since 83d9dcba06c5 ("netfilter: nf_tables: extended netlink error reporting for expressions").
A common mistake is to reference a chain which does not exist, e.g.
# nft add rule x y jump test
Error: Could not process rule: No such file or directory
add rule x y jump test
^^^^Use the existing netlink extended error reporting infrastructure to provide better error reporting as in the example above.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/netlink.h | 27 ++++++- src/mnl.c | 65 ++++++++++++++- src/netlink_linearize.c | 171 ++++++++++++++++++++++++++-------------- 3 files changed, 201 insertions(+), 62 deletions(-)
include/netlink.h +25 -2
@@ -123,9 +123,11 @@ extern struct expr *netlink_alloc_data(const struct location *loc, enum nft_registers dreg);extern int netlink_list_rules (struct netlink_ctx *ctx,const struct handle *h); + +struct netlink_linearize_ctx ;extern void netlink_linearize_rule (struct netlink_ctx *ctx, -struct nftnl_rule *nlr, -const struct rule *rule); +const struct rule *rule, +struct netlink_linearize_ctx *lctx);extern struct rule *netlink_delinearize_rule (struct netlink_ctx *ctx,struct nftnl_rule *r);
@@ -215,4 +217,25 @@ enum nft_data_types dtype_map_to_kernel(const struct datatype *dtype);void expr_handler_init (void );void expr_handler_exit (void ); +void netlink_linearize_init (struct netlink_linearize_ctx *lctx, +struct nftnl_rule *nlr); +void netlink_linearize_fini (struct netlink_linearize_ctx *lctx); + +struct netlink_linearize_ctx { +struct nftnl_rule *nlr; +unsigned int reg_low; +struct list_head *expr_loc_htable; +}; + +#define NFT_EXPR_LOC_HSIZE 128 + +struct nft_expr_loc { +struct list_head hlist; +const struct nftnl_expr *nle; +struct location loc; +}; + +struct nft_expr_loc *nft_expr_loc_find (const struct nftnl_expr *nle, +struct netlink_linearize_ctx *ctx); +#endif /* NFTABLES_NETLINK_H */
src/mnl.c +63 -2
117 lines not on this page · raw message
src/netlink_linearize.c +113 -58
474 lines not on this page · raw message
Signature · 1 line
2.20.1