limit netlink message size during delete operation
RFC PATCH 1/1 limit netlink message size during delete operation
Hello,
When working on the flush issue, I've observed that the deletion message was containing the whole the rule definition. This seems to be useless as only table, chain and handle number are used to delete a rule.
The following patchset introduces a new function in libnftables to be able to only put only these identifiers in the deletion message.
BR,
Signature · 2 lines
Eric Leblond <[email protected]> Blog: https://home.regit.org/
PATCH 1/1 src: add function nft_rule_nlmsg_build_id
This patch adds a new function nft_rule_nlmsg_build_id which can be used to only dump the identifiers of a rule to the netlink message. This allow to limit the size of the messages when doing some deletion operation where the other parameters are not used.
--- include/libnftables/rule.h | 1 + src/libnftables.map | 1 + src/rule.c | 14 ++++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-)
include/libnftables/rule.h +1 -0
@@ -40,6 +40,7 @@ uint64_t nft_rule_attr_get_u64(const struct nft_rule *r, uint16_t attr);void nft_rule_add_expr (struct nft_rule *r,struct nft_rule_expr *expr); +void nft_rule_nlmsg_build_id (struct nlmsghdr *nlh,struct nft_rule *t);void nft_rule_nlmsg_build_payload (struct nlmsghdr *nlh,struct nft_rule *t);enum {
src/libnftables.map +1 -0
@@ -72,6 +72,7 @@ global: nft_rule_parse; nft_rule_snprintf; nft_rule_nlmsg_build_hdr; + nft_rule_nlmsg_build_id; nft_rule_nlmsg_build_payload; nft_rule_nlmsg_parse; nft_rule_add_expr;
src/rule.c +10 -4
@@ -248,11 +248,8 @@ nft_rule_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, }EXPORT_SYMBOL (nft_rule_nlmsg_build_hdr); -void nft_rule_nlmsg_build_payload (struct nlmsghdr *nlh,struct nft_rule *r) +void nft_rule_nlmsg_build_id (struct nlmsghdr *nlh,struct nft_rule *r) { -struct nft_rule_expr *expr; -struct nlattr *nest; -if (r->flags & (1 <<NFT_RULE_ATTR_TABLE ))mnl_attr_put_strz (nlh,NFTA_RULE_TABLE , r->table);if (r->flags & (1 <<NFT_RULE_ATTR_CHAIN ))
@@ -261,6 +258,15 @@ void nft_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_rule *r)mnl_attr_put_u64 (nlh,NFTA_RULE_HANDLE ,htobe64 (r->handle));if (r->flags & (1 <<NFT_RULE_ATTR_POSITION ))mnl_attr_put_u64 (nlh,NFTA_RULE_POSITION ,htobe64 (r->position)); +} +EXPORT_SYMBOL (nft_rule_nlmsg_build_id); + +void nft_rule_nlmsg_build_payload (struct nlmsghdr *nlh,struct nft_rule *r) +{ +struct nft_rule_expr *expr; +struct nlattr *nest; + +nft_rule_nlmsg_build_id (nlh, r);if (!list_empty (&r->expr_list)) { nest =mnl_attr_nest_start (nlh,NFTA_RULE_EXPRESSIONS );
Signature · 1 line
1.8.4.rc3
PATCH 1/1 netlink: use build_id to lower message size
In reply to Eric LeblondTHis patch makes use of the new nft_rule_nlmsg_build_id function from libnftables for the delete operation. This lower the size of the netlink message sent to kernel when flushing the rules.
--- src/mnl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/mnl.c +1 -1
@@ -292,7 +292,7 @@ int mnl_nft_rule_batch_del(struct nft_rule *nlr, unsigned int flags,nft_rule_attr_get_u32 (nlr,NFT_RULE_ATTR_FAMILY ), NLM_F_ACK, seqnum); -nft_rule_nlmsg_build_payload (nlh, nlr); +nft_rule_nlmsg_build_id (nlh, nlr);if (!mnl_nlmsg_batch_next (batch))mnl_batch_page_add ();
Signature · 1 line
1.8.4.rc3
Pablo Neira Ayuso
maintainerRe: [nftables PATCH] netlink: use build_id to lower message size
Quoted 3 lines · Eric Leblond
THis patch makes use of the new
nft_rule_nlmsg_build_idfunction from libnftables for the delete operation. This lower the size of the netlink message sent to kernel when flushing the rules.
I think we can simplify the flush operation with a small change in nf_tables_delrule. The idea is to delete all rule if no chain is specified.
The current approach is pretty time consuming, as we have to fetch the ruleset from the kernel, iterate over it and build the message to delete them.
Would you send me patches to follow this approach?