Skip to contentSkip to conversation

nefilter: nfnetlink: add nfnetlink_set_err and use it in ctnetlink

PATCH In review Pablo Neira Ayuso 2 participants 4 messages Mar 5, 2009 – Mar 16, 2009

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 nefilter: nfnetlink: add nfnetlink_set_err and use it in ctnetlink

This patch adds nfnetlink_set_err() to propagate the error to netlink broadcast listener in case of memory allocation errors in the message building.

---

 include/linux/netfilter/nfnetlink.h  |    1 +
 net/netfilter/nf_conntrack_netlink.c |    2 ++
 net/netfilter/nfnetlink.c            |    6 ++++++
 net/netlink/af_netlink.c             |    1 +
 4 files changed, 10 insertions(+), 0 deletions(-)
include/linux/netfilter/nfnetlink.h +1 -0
index 7d8e045..97ade6c 100644
@@ -76,6 +76,7 @@ extern int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);
 extern int nfnetlink_has_listeners(unsigned int group);
 extern int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, 
 			  int echo);
+extern void nfnetlink_set_err(u32 group, int error);
 extern int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags);
 
 extern void nfnl_lock(void);
net/netfilter/nf_conntrack_netlink.c +2 -0
index c9db6ec..02ee8e1 100644
@@ -619,6 +619,7 @@ static int ctnetlink_conntrack_event(struct notifier_block *this,
 nla_put_failure:
 	rcu_read_unlock();
 nlmsg_failure:
+	nfnetlink_set_err(group, -ENOBUFS);
 	kfree_skb(skb);
 	return NOTIFY_DONE;
 }
@@ -1643,6 +1644,7 @@ static int ctnetlink_expect_event(struct notifier_block *this,
 nla_put_failure:
 	rcu_read_unlock();
 nlmsg_failure:
+	nfnetlink_set_err(0, -ENOBUFS);
 	kfree_skb(skb);
 	return NOTIFY_DONE;
 }
net/netfilter/nfnetlink.c +6 -0
index 9c0ba17..cd85c56 100644
@@ -113,6 +113,12 @@ int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo)
 }
 EXPORT_SYMBOL_GPL(nfnetlink_send);
 
+void nfnetlink_set_err(u32 group, int error)
+{
+	netlink_set_err(nfnl, 0, group, error);
+}
+EXPORT_SYMBOL_GPL(nfnetlink_set_err);
+
 int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags)
 {
 	return netlink_unicast(nfnl, skb, pid, flags);
net/netlink/af_netlink.c +1 -0
index 09e5008..dc93836 100644
@@ -1118,6 +1118,7 @@ void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
 
 	read_unlock(&nl_table_lock);
 }
+EXPORT_SYMBOL(netlink_set_err);
 
 /* must be called with netlink table grabbed */
 static void netlink_update_socket_mc(struct netlink_sock *nlk,
#1 lore raw

net/netfilter/nfnetlink.c int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo) · line 120

Quoted 9 lines · Pablo Neira Ayuso

This patch adds nfnetlink_set_err() to propagate the error to netlink broadcast listener in case of memory allocation errors in the message building.

net/netfilter/nfnetlink.c +5 -0
+void nfnetlink_set_err(u32 group, int error)
+{
+	netlink_set_err(nfnl, 0, group, error);
+}
+EXPORT_SYMBOL_GPL(nfnetlink_set_err);

Please make the pid argument controllable by the caller as well. This is necessary to avoid double error notifications when an error occurs in response to a user-request triggering notifications.

author maintainer
#2 lore raw
Quoted 5 lines · Patrick McHardy
Quoted 3 lines · Pablo Neira Ayuso

This patch adds nfnetlink_set_err() to propagate the error to netlink broadcast listener in case of memory allocation errors in the message building.

Quoted 9 lines

net/netfilter/nfnetlink.c int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo) · line 120

Quoted 5 lines
net/netfilter/nfnetlink.c +5 -0
+void nfnetlink_set_err(u32 group, int error)
+{
+    netlink_set_err(nfnl, 0, group, error);
+}
+EXPORT_SYMBOL_GPL(nfnetlink_set_err);

Please make the pid argument controllable by the caller as well. This is necessary to avoid double error notifications when an error occurs in response to a user-request triggering notifications.

OK, I'll add it, but the pid passed as argument will be zero by now. Note that, in the current code, user-requests ignore notification errors, so there is no chance to get double error notifications.

I have another patch here to propagate errors of user-requests that result in failing notifications, then the pid parameter in nfnetlink_set_err() will be useful. That patch also includes the use of NETLINK_BROADCAST_ERROR. I'll send you that patch soon.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#3 lore raw
Quoted 14 lines · Pablo Neira Ayuso
Quoted 12 lines · Patrick McHardy

net/netfilter/nfnetlink.c int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo) · line 120

Quoted 8 lines · Pablo Neira Ayuso

This patch adds nfnetlink_set_err() to propagate the error to netlink broadcast listener in case of memory allocation errors in the message building.

net/netfilter/nfnetlink.c +5 -0
+void nfnetlink_set_err(u32 group, int error)
+{
+    netlink_set_err(nfnl, 0, group, error);
+}
+EXPORT_SYMBOL_GPL(nfnetlink_set_err);

Please make the pid argument controllable by the caller as well. This is necessary to avoid double error notifications when an error occurs in response to a user-request triggering notifications.

Quoted 3 lines

OK, I'll add it, but the pid passed as argument will be zero by now. Note that, in the current code, user-requests ignore notification errors, so there is no chance to get double error notifications.

I know. I have the same function in my nftables tree though (but requiring the pid-argument), so we might as well add it in a future-proof way.

Quoted 4 lines

I have another patch here to propagate errors of user-requests that result in failing notifications, then the pid parameter in nfnetlink_set_err() will be useful. That patch also includes the use of NETLINK_BROADCAST_ERROR. I'll send you that patch soon.

Thanks.