Don't increase master refcount on expectations
Subsystems (2)
PATCH 1/1 Don't increase master refcount on expectations
As it's been discussed [1][2]. We shouldn't increase the master conntrack refcount for non-fulfilled conntracks. During the conntrack destruction, the expectations are always killed before the conntrack itself, this guarantees that there won't be any orphan expectation.
[1]https://lists.netfilter.org/pipermail/netfilter-devel/2005-August/020783.html [2]https://lists.netfilter.org/pipermail/netfilter-devel/2005-August/020904.html
net/ipv4/netfilter/ip_conntrack_core.c +4 -4
@@ -934,6 +934,9 @@write_unlock_bh (&ip_conntrack_lock); } +/* We don't increase the master conntrack refcount for non-fulfilled +* conntracks. During the conntrack destruction, the expectations are +* always killed before the conntrack itself */ struct ip_conntrack_expect *ip_conntrack_expect_alloc (struct ip_conntrack *me) {struct ip_conntrack_expect *new;
@@ -944,17 +947,14 @@return NULL ; } new->master = me; -atomic_inc (&new->master->ct_general.use);atomic_set (&new->use,1 );return new; }void ip_conntrack_expect_put (struct ip_conntrack_expect *exp) { -if (atomic_dec_and_test (&exp->use)) { -ip_conntrack_put (exp->master); +if (atomic_dec_and_test (&exp->use))kmem_cache_free (ip_conntrack_expect_cachep, exp); - } }static void ip_conntrack_expect_insert (struct ip_conntrack_expect *exp)
Dear Pablo:
According to issues concerning how to manage refcount which relate master and its children once expected,please refer to the following link,which suggesting patch remove_expectations(),and that's where the problem first was issued. [1]https://lists.netfilter.org/pipermail/netfilter-devel/2003-November/01310 5.html
The scenario is that then I had a custom solution which takes advantage on helper-expectation framewrok.According to this scenario,a master will expect many children simultaniously.And not only each child's first packet which fullfill the expect relies on its master for nat decision,but also the scenario relies on the master for decision made on itself while one of its children's replying packet reaches.And each children's replying packet will not only put itself but also remove its conntrack.So the scenarion raises 2 problems:
1.Then without responsing from netfilter,All I can do is but doing some custimized work to ip_conntrack_put the master to prevent the master from hanging forever.(After quite a period, they patched the context.) 2.After All expects being fullfilled,it is still nacessary that the master be referenced.So it looks reserving a refcount on the master after the fullfillment doesn't push things too far.
So,my opinion is if it is necessary to keep refcount after fullfillment?And,I suggest that my past suggestion be referrenced.
Your sincerely
Jesse
----- Original Message -----
From: "Pablo Neira" <[email protected]>
To: "Netfilter Development Mailinglist" <[email protected]>
Cc: "Harald Welte" <[email protected]>; "Patrick McHardy" <[email protected]>; "Yasuyuki Kozakai" <[email protected]>
Sent: Friday, August 26, 2005 4:45 AM
Subject: [PATCH] Don't increase master refcount on expectations
Quoted 6 lines
As it's been discussed [1][2]. We shouldn't increase the master conntrack refcount for non-fulfilled conntracks. During the conntrack destruction, the expectations are always killed before the conntrack itself, this guarantees that there won't be any orphan expectation.
[1]https://lists.netfilter.org/pipermail/netfilter-devel/2005-August/020783. html
Quoted 1 line
[2]https://lists.netfilter.org/pipermail/netfilter-devel/2005-August/020904. html
Quoted 3 lines
Signed-off-by Pablo Neira Ayuso <[email protected]>
----------------------------------------------------------------------------
----
Quoted 3 lines
Index:
netfilter-2.6.14/net/ipv4/netfilter/ip_conntrack_core.c
===================================================================
---netfilter-2.6.14.orig/net/ipv4/netfilter/ip_conntrack_core.c
2005-08-20 18:19:44.000000000 +0200
Quoted 1 line
+++
netfilter-2.6.14/net/ipv4/netfilter/ip_conntrack_core.c2005-08-20
18:27:59.000000000 +0200
net/ipv4/netfilter/ip_conntrack_core.c line 940
Quoted 8 lines
net/ipv4/netfilter/ip_conntrack_core.c +3
-0@@ -934,6 +934,9 @@write_unlock_bh (&ip_conntrack_lock); } +/* We don't increase the master conntrack refcount for non-fulfilled +* conntracks. During the conntrack destruction, the expectations are +* always killed before the conntrack itself */ struct ip_conntrack_expect *ip_conntrack_expect_alloc(struct ip_conntrack
*me)
Quoted 22 lines
net/ipv4/netfilter/ip_conntrack_core.c +1
-4{struct ip_conntrack_expect *new;@@ -944,17 +947,14 @@return NULL ; } new->master = me; -atomic_inc (&new->master->ct_general.use);atomic_set (&new->use,1 );return new; }void ip_conntrack_expect_put (struct ip_conntrack_expect *exp) { -if (atomic_dec_and_test (&exp->use)) { -ip_conntrack_put (exp->master); +if (atomic_dec_and_test (&exp->use))kmem_cache_free (ip_conntrack_expect_cachep, exp); - } }static void ip_conntrack_expect_insert (struct ip_conntrack_expect *exp)
Patrick McHardy
AppliedQuoted 1 line · Pablo Neira
As it's been discussed [1][2]. We shouldn't increase the master conntrack refcount for non-fulfilled conntracks. During the conntrack destruction, the expectations are always killed before the conntrack itself, this guarantees that there won't be any orphan expectation.
Applied, thanks. Is it correct that this also fixes the untriggerable deadlock Yasuyuki noticed?
From: Patrick McHardy <[email protected]>
Subject: Re: [PATCH] Don't increase master refcount on expectations
Date: Sun, 04 Sep 2005 19:47:43 +0200
Quoted 8 lines
Quoted 4 lines · Pablo Neira
As it's been discussed [1][2]. We shouldn't increase the master conntrack refcount for non-fulfilled conntracks. During the conntrack destruction, the expectations are always killed before the conntrack itself, this guarantees that there won't be any orphan expectation.
Applied, thanks. Is it correct that this also fixes the untriggerable deadlock Yasuyuki noticed?
As far as I read, yes.
BTW, I'll send patches on this for nf_conntrack.
-----------------------------------------------------------------
Yasuyuki Kozakai @ USAGI Project <[email protected]>
Hi,
From: "JessePeng" <[email protected]>
Date: Fri, 26 Aug 2005 20:33:27 +0800
Quoted 15 lines
The scenario is that then I had a custom solution which takes advantage on helper-expectation framewrok.According to this scenario,a master will expect many children simultaniously.And not only each child's first packet which fullfill the expect relies on its master for nat decision,but also the scenario relies on the master for decision made on itself while one of its children's replying packet reaches.And each children's replying packet will not only put itself but also remove its conntrack.So the scenarion raises 2 problems:
1.Then without responsing from netfilter,All I can do is but doing some custimized work toip_conntrack_putthe master to prevent the master from hanging forever.(After quite a period, they patched the context.) 2.After All expects being fullfilled,it is still nacessary that the master be referenced.So it looks reserving a refcount on the master after the fullfillment doesn't push things too far.
Quoted 2 lines
So,my opinion is if it is necessary to keep refcount after fullfillment?And,I suggest that my past suggestion be referrenced.
Well, it's questionable that I correctly understand your scenario, but I think there is no problem. 1. As Pablo said, expectations in list are destroyed by its master before master is destroyed, so ip_conntrack_put() doesn't cause problem. And because the refcount of master conntrack is incremented when the expected packets arrived, master conntrack can be kept after that. See init_conntrack() in detail.
Regards,
-----------------------------------------------------------------
Yasuyuki Kozakai @ USAGI Project <[email protected]>
Dear Yasuyuki
Quoted 5 lines
Well, it's questionable that I correctly understand your scenario, but I think there is no problem. 1. As Pablo said, expectations in list are destroyed by its master before master is destroyed, so
ip_conntrack_put()doesn't cause problem. And because the refcount of master conntrack is incremented when the expected packets arrived, master conntrack can be
kept
Quoted 1 line
after that. See
init_conntrack()in detail.
Anyway,thanks for your reply!
Your sincerely
Jesse