Skip to contentSkip to conversation

ctnetlink loop

DISCUSSION David Miller 3 participants 3 messages Dec 8, 2010 – Dec 9, 2010

Subsystems (3)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

Holger, this replay -EAGAIN loop in nfnetlink processing was added by Pablo to handle module loading properly, I think. So it might not be safe to just unilaterally remove it.

See:

commit e6a7d3c04f8fe49099521e6dc9a46b0272381f2f

Author: Pablo Neira Ayuso <[email protected]>
Date:   Tue Oct 14 11:58:31 2008 -0700

netfilter: ctnetlink: remove bogus module dependency between ctnetlink and nf_nat

This patch removes the module dependency between ctnetlink and nf_nat by means of an indirect call that is initialized when nf_nat is loaded. Now, nf_conntrack_netlink only requires nf_conntrack and nfnetlink.

This patch puts nfnetlink_parse_nat_setup_hook into the nf_conntrack_core to avoid dependencies between ctnetlink, nf_conntrack_ipv4 and nf_conntrack_ipv6.

This patch also introduces the function ctnetlink_change_nat that is only invoked from the creation path. Actually, the nat handling cannot be invoked from the update path since this is not allowed. By introducing this function, we remove the useless nat handling in the update path and we avoid deadlock-prone code.

This patch also adds the required EAGAIN logic for nfnetlink.

include/linux/netfilter/nfnetlink.h +3 -0
index 0d8424f..7d8e045 100644
@@ -78,6 +78,9 @@ extern int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group,
 			  int echo);
 extern int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags);
 
+extern void nfnl_lock(void);
+extern void nfnl_unlock(void);
+
 #define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
 	MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
 
include/net/netfilter/nf_nat_core.h +8 -0
index f29eeb9..5868406 100644
@@ -25,4 +25,12 @@ static inline int nf_nat_initialized(struct nf_conn *ct,
 	else
 		return test_bit(IPS_DST_NAT_DONE_BIT, &ct->status);
 }
+
+struct nlattr;
+
+extern int
+(*nfnetlink_parse_nat_setup_hook)(struct nf_conn *ct,
+				  enum nf_nat_manip_type manip,
+				  struct nlattr *attr);
+
 #endif /* _NF_NAT_CORE_H */
net/ipv4/netfilter/nf_nat_core.c +97 -0

119 lines not on this page · raw message

net/netfilter/nf_conntrack_core.c +7 -0
index 27de3c7..622d7c6 100644
@@ -38,9 +38,16 @@
 #include <net/netfilter/nf_conntrack_core.h>
 #include <net/netfilter/nf_conntrack_extend.h>
 #include <net/netfilter/nf_conntrack_acct.h>
+#include <net/netfilter/nf_nat.h>
 
 #define NF_CONNTRACK_VERSION	"0.5.0"
 
+unsigned int
+(*nfnetlink_parse_nat_setup_hook)(struct nf_conn *ct,
+				  enum nf_nat_manip_type manip,
+				  struct nlattr *attr) __read_mostly;
+EXPORT_SYMBOL_GPL(nfnetlink_parse_nat_setup_hook);
+
 DEFINE_SPINLOCK(nf_conntrack_lock);
 EXPORT_SYMBOL_GPL(nf_conntrack_lock);
 
net/netfilter/nf_conntrack_netlink.c +61 -90

181 lines not on this page · raw message

net/netfilter/nfnetlink.c +9 -3
index b75c9c4..4739f9f 100644
@@ -44,15 +44,17 @@ static struct sock *nfnl = NULL;
 static const struct nfnetlink_subsystem *subsys_table[NFNL_SUBSYS_COUNT];
 static DEFINE_MUTEX(nfnl_mutex);
 
-static inline void nfnl_lock(void)
+void nfnl_lock(void)
 {
 	mutex_lock(&nfnl_mutex);
 }
+EXPORT_SYMBOL_GPL(nfnl_lock);
 
-static inline void nfnl_unlock(void)
+void nfnl_unlock(void)
 {
 	mutex_unlock(&nfnl_mutex);
 }
+EXPORT_SYMBOL_GPL(nfnl_unlock);
 
 int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n)
 {
@@ -132,6 +134,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 		return 0;
 
 	type = nlh->nlmsg_type;
+replay:
 	ss = nfnetlink_get_subsys(type);
 	if (!ss) {
 #ifdef CONFIG_KMOD
@@ -165,7 +168,10 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 		} else
 			return -EINVAL;
 
-		return nc->call(nfnl, skb, nlh, cda);
+		err = nc->call(nfnl, skb, nlh, cda);
+		if (err == -EAGAIN)
+			goto replay;
+		return err;
 	}
 }
 
#1 lore raw

Hi,

Quoted 3 lines

Holger, this replay -EAGAIN loop in nfnetlink processing was added by Pablo to handle module loading properly, I think. So it might not be safe to just unilaterally remove it.

thanks for your reply!

Pablo, do we really need the replay loop really? I now have several boxes with problems due to this replay. 'perf report' always gives me something like:

18.88% ulogd [kernel]
[k] __nla_put
10.73% ulogd [kernel]
[k] nla_parse
8.72% ulogd [kernel]
[k] __nla_reserve
6.64% ulogd [kernel]
[k] nla_put
5.14% ulogd [kernel]
[k] validate_nla
5.03% ulogd [kernel]
[k] pskb_expand_head
4.92% ulogd [kernel]
[k] ctnetlink_fill_info [nf_conntrack_netlink]
3.07% ulogd [kernel]
[k] skb_put
3.03% ulogd [kernel]
[k] ctnetlink_dump_counters [nf_conntrack

And 'strace' shows me that ulogd is stuck in its 'select' call.

/holger

#2 lore raw
Quoted 9 lines · Holger Eitzenberger

Hi,

Quoted 3 lines

Holger, this replay -EAGAIN loop in nfnetlink processing was added by Pablo to handle module loading properly, I think. So it might not be safe to just unilaterally remove it.

thanks for your reply!

Pablo, do we really need the replay loop really?

Yes, we need it for the on-demand module loading.

Quoted 23 lines

I now have several
boxes with problems due to this replay. 'perf report' always gives me something like:

18.88% ulogd [kernel]
[k] __nla_put
10.73% ulogd [kernel]
[k] nla_parse
8.72% ulogd [kernel]
[k] __nla_reserve
6.64% ulogd [kernel]
[k] nla_put
5.14% ulogd [kernel]
[k] validate_nla
5.03% ulogd [kernel]
[k] pskb_expand_head
4.92% ulogd [kernel]
[k] ctnetlink_fill_info [nf_conntrack_netlink]
3.07% ulogd [kernel]
[k] skb_put
3.03% ulogd [kernel]
[k] ctnetlink_dump_counters [nf_conntrack

Quoted 1 line

And 'strace' shows me that ulogd is stuck in its 'select' call.

Sorry, I missed your previous emails. Why do you think that this related to -EAGAIN in nfnetlink?