Skip to contentSkip to conversation

netfilter: nfnetlink_hook: use the sequence number of the request message

PATCH New Pablo Neira Ayuso 1 participant 2 messages Aug 3, 2021

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 netfilter: nfnetlink_hook: use the sequence number of the request message

The sequence number allows to correlate the netlink reply message (as part of the dump) with the original request message.

The cb->seq field is internally used to detect an interference (update) of the hook list during the netlink dump, do not use it as sequence number in the netlink dump header.

Fixes e2cf17d3774c ("netfilter: add new hook nfnl subsystem")
---
 net/netfilter/nfnetlink_hook.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nfnetlink_hook.c +2 -1
index 30fe94477f8d..f204752ba4a4 100644
@@ -262,7 +262,8 @@ static int nfnl_hook_dump(struct sk_buff *nlskb,
 	ops = nf_hook_entries_get_hook_ops(e);
 
 	for (; i < e->num_hook_entries; i++) {
-		err = nfnl_hook_dump_one(nlskb, ctx, ops[i], cb->seq);
+		err = nfnl_hook_dump_one(nlskb, ctx, ops[i],
+					 cb->nlh->nlmsg_seq);
 		if (err)
 			break;
 	}
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 2/2 netfilter: nfnetlink_hook: Use same family as request message

Use the same family as the request message, for consistency. The netlink payload provides sufficient information to describe the hook object, including the family.

This makes it easier to userspace to correlate the hooks are that visited by the packets for a certain family.

Fixes e2cf17d3774c ("netfilter: add new hook nfnl subsystem")
---
 net/netfilter/nfnetlink_hook.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_hook.c +3 -3
index f204752ba4a4..52324ca26d9b 100644
@@ -113,7 +113,7 @@ static int nfnl_hook_put_nft_chain_info(struct sk_buff *nlskb,
 static int nfnl_hook_dump_one(struct sk_buff *nlskb,
 			      const struct nfnl_dump_hook_data *ctx,
 			      const struct nf_hook_ops *ops,
-			      unsigned int seq)
+			      int family, unsigned int seq)
 {
 	u16 event = nfnl_msg_type(NFNL_SUBSYS_HOOK, NFNL_MSG_HOOK_GET);
 	unsigned int portid = NETLINK_CB(nlskb).portid;
@@ -124,7 +124,7 @@ static int nfnl_hook_dump_one(struct sk_buff *nlskb,
 	char *module_name;
 #endif
 	nlh = nfnl_msg_put(nlskb, portid, seq, event,
-			   NLM_F_MULTI, ops->pf, NFNETLINK_V0, 0);
+			   NLM_F_MULTI, family, NFNETLINK_V0, 0);
 	if (!nlh)
 		goto nla_put_failure;
 
@@ -262,7 +262,7 @@ static int nfnl_hook_dump(struct sk_buff *nlskb,
 	ops = nf_hook_entries_get_hook_ops(e);
 
 	for (; i < e->num_hook_entries; i++) {
-		err = nfnl_hook_dump_one(nlskb, ctx, ops[i],
+		err = nfnl_hook_dump_one(nlskb, ctx, ops[i], family,
 					 cb->nlh->nlmsg_seq);
 		if (err)
 			break;
Signature · 1 line
2.20.1