Skip to content

Commit 466c9b3

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: prepare nft audit for set element compaction
nftables audit log format emits the number of added/deleted rules, sets, set elements and so on, to userspace: table=t1 family=2 entries=4 op=nft_register_set ~~~~~~~~~ At this time, the 'entries' key is the number of transactions that will be applied. The upcoming set element compression will coalesce subsequent adds/deletes to the same set requests in the same transaction request to conseve memory. Without this patch, we'd under-report the number of altered elements. Increment the audit counter by the number of elements to keep the reported entries value the same. Without this, nft_audit.sh selftest fails because the recorded (expected) entries key is smaller than the expected one. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent a8ee6b9 commit 466c9b3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10398,9 +10398,24 @@ static void nf_tables_commit_audit_free(struct list_head *adl)
1039810398
}
1039910399
}
1040010400

10401+
/* nft audit emits the number of elements that get added/removed/updated,
10402+
* so NEW/DELSETELEM needs to increment based on the total elem count.
10403+
*/
10404+
static unsigned int nf_tables_commit_audit_entrycount(const struct nft_trans *trans)
10405+
{
10406+
switch (trans->msg_type) {
10407+
case NFT_MSG_NEWSETELEM:
10408+
case NFT_MSG_DELSETELEM:
10409+
return nft_trans_container_elem(trans)->nelems;
10410+
}
10411+
10412+
return 1;
10413+
}
10414+
1040110415
static void nf_tables_commit_audit_collect(struct list_head *adl,
10402-
struct nft_table *table, u32 op)
10416+
const struct nft_trans *trans, u32 op)
1040310417
{
10418+
const struct nft_table *table = trans->table;
1040410419
struct nft_audit_data *adp;
1040510420

1040610421
list_for_each_entry(adp, adl, list) {
@@ -10410,7 +10425,7 @@ static void nf_tables_commit_audit_collect(struct list_head *adl,
1041010425
WARN_ONCE(1, "table=%s not expected in commit list", table->name);
1041110426
return;
1041210427
found:
10413-
adp->entries++;
10428+
adp->entries += nf_tables_commit_audit_entrycount(trans);
1041410429
if (!adp->op || adp->op > op)
1041510430
adp->op = op;
1041610431
}
@@ -10569,7 +10584,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
1056910584

1057010585
nft_ctx_update(&ctx, trans);
1057110586

10572-
nf_tables_commit_audit_collect(&adl, table, trans->msg_type);
10587+
nf_tables_commit_audit_collect(&adl, trans, trans->msg_type);
1057310588
switch (trans->msg_type) {
1057410589
case NFT_MSG_NEWTABLE:
1057510590
if (nft_trans_table_update(trans)) {

0 commit comments

Comments
 (0)