nf_conntrack allocation issue
Subsystems (2)
I've added these three patches to fix the allocation problems. I don't want to add the new module option introduced by Jozsef's patch since the current situation is just ridiculous, we need to search for both helpers and expectations twice for every new connection, so this needs to be redesigned anyway.
It seems to work fine in some quick testing. This was the last problem I'm aware of, so I'm probably going to push all patches soon.
Last thing is the helper renaming, any objections to prefix all helpers with nf_conntrack_helper_?
[NETFILTER]: nf_conntrack: automatic helper assignment for expectations
Some helpers (namely H.323) manually assign further helpers to expected connections. This is not possible with nf_conntrack anymore since we need to know whether a helper is used at allocation time.
Handle the helper assignment centrally, which allows to perform the correct allocation and as a nice side effect eliminates the need for the H.323 helper to fiddle with nf_conntrack_lock.
Mid term the allocation scheme really needs to be redesigned since we do both the helper and expectation lookup _twice_ for every new connection.
---
commit fa7ba8735f8bdcc47b2ca5d11c1b8ec6fb7ae241
tree ddcc58530cfeded09283ffd6659c6a44aaaeb294
parent 35d1fac7ef0f6a79e41f86af6d28036570dc21b9
author Patrick McHardy <[email protected]> Thu, 30 Nov 2006 16:23:42 +0100 committer Patrick McHardy <[email protected]> Thu, 30 Nov 2006 16:23:42 +0100
include/net/netfilter/nf_conntrack_expect.h | 3 +++ net/netfilter/nf_conntrack_core.c | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +3 -0
@@ -22,6 +22,9 @@ struct nf_conntrack_expectvoid (*expectfn)(struct nf_conn *new,struct nf_conntrack_expect *this); +/* Helper to assign to new connection */ +struct nf_conntrack_helper *helper; +/* The conntrack of the master connection */ struct nf_conn *master;
net/netfilter/nf_conntrack_core.c +14 -5
@@ -545,10 +545,10 @@ static int early_drop(struct list_head *static struct nf_conn *__nf_conntrack_alloc (const struct nf_conntrack_tuple *orig,const struct nf_conntrack_tuple *repl, -const struct nf_conntrack_l3proto *l3proto) +const struct nf_conntrack_l3proto *l3proto, +u_int32_t features) {struct nf_conn *conntrack =NULL ; -u_int32_t features =0 ;struct nf_conntrack_helper *helper;if (unlikely (!nf_conntrack_hash_rnd_initted)) {
@@ -574,7 +574,7 @@ __nf_conntrack_alloc(const struct nf_con }/* find features needed by this conntrack. */ - features = l3proto->get_features (orig); + features |= l3proto->get_features (orig);/* FIXME: protect helper list per RCU */ read_lock_bh (&nf_conntrack_lock);
@@ -624,7 +624,7 @@ struct nf_conn *nf_conntrack_alloc(conststruct nf_conntrack_l3proto *l3proto; l3proto =__nf_ct_l3proto_find (orig->src.l3num); -return __nf_conntrack_alloc (orig, repl, l3proto); +return __nf_conntrack_alloc (orig, repl, l3proto,0 ); }void nf_conntrack_free (struct nf_conn *conntrack)
@@ -649,13 +649,20 @@ init_conntrack(const struct nf_conntrackstruct nf_conn *conntrack;struct nf_conntrack_tuple repl_tuple;struct nf_conntrack_expect *exp; +u_int32_t features =0 ;if (!nf_ct_invert_tuple (&repl_tuple, tuple, l3proto, l4proto)) {DEBUGP ("Can't invert tuple.\n" );return NULL ; } - conntrack =__nf_conntrack_alloc (tuple, &repl_tuple, l3proto); +read_lock_bh (&nf_conntrack_lock); + exp =__nf_conntrack_expect_find (tuple); +if (exp && exp->helper) + features =NF_CT_F_HELP ; +read_unlock_bh (&nf_conntrack_lock); + + conntrack =__nf_conntrack_alloc (tuple, &repl_tuple, l3proto, features);if (conntrack ==NULL ||IS_ERR (conntrack)) {DEBUGP ("Can't allocate conntrack.\n" );return (struct nf_conntrack_tuple_hash *)conntrack;
@@ -676,6 +683,8 @@ init_conntrack(const struct nf_conntrack/* Welcome, Mr. Bond. We've been expecting you... */ __set_bit (IPS_EXPECTED_BIT , &conntrack->status); conntrack->master = exp->master; +if (exp->helper) +nfct_help (conntrack)->helper = exp->helper;#ifdef CONFIG_NF_CONNTRACK_MARK conntrack->mark = exp->master->mark;#endif
net/netfilter/nf_conntrack_core.c +2 -1
@@ -579,7 +579,8 @@ __nf_conntrack_alloc(const struct nf_con/* FIXME: protect helper list per RCU */ read_lock_bh (&nf_conntrack_lock); helper =__nf_ct_helper_find (repl); -if (helper) +/* NAT might want to assign a helper later */ +if (helper || features &NF_CT_F_NAT ) features |=NF_CT_F_HELP ;read_unlock_bh (&nf_conntrack_lock);
net/netfilter/nf_conntrack_core.c +1 -1
@@ -866,7 +866,7 @@ void nf_conntrack_alter_reply(struct nf_NF_CT_DUMP_TUPLE (newreply); conntrack->tuplehash[IP_CT_DIR_REPLY ].tuple = *newreply; -if (!conntrack->master && help->expecting ==0 ) +if (!conntrack->master && help && help->expecting ==0 ) help->helper =__nf_ct_helper_find (newreply);write_unlock_bh (&nf_conntrack_lock); }
net/ipv4/netfilter/nf_nat_h323.c +2 -19
@@ -324,18 +324,6 @@ static int nat_t120(struct sk_buff **pskreturn 0 ; } -/**************************************************************************** -* This conntrack expect function replaces nf_conntrack_h245_expect() -* which was set by nf_conntrack_helper_h323.c. It calls both -* nf_nat_follow_master() and nf_conntrack_h245_expect() -****************************************************************************/ -static void ip_nat_h245_expect (struct nf_conn *new, -struct nf_conntrack_expect *this) -{ -nf_nat_follow_master (new, this); -nf_conntrack_h245_expect (new, this); -} -/****************************************************************************/ static int nat_h245(struct sk_buff **pskb, struct nf_conn *ct, enum ip_conntrack_info ctinfo,
@@ -349,7 +337,7 @@ static int nat_h245(struct sk_buff **psk/* Set expectations for NAT */ exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port; - exp->expectfn = ip_nat_h245_expect; + exp->expectfn = nf_nat_follow_master; exp->dir = !dir;/* Check existing expects */
@@ -399,7 +387,7 @@ static void ip_nat_q931_expect(struct nfif (this->tuple.src.u3.ip !=0 ) {/* Only accept calls from GK */ nf_nat_follow_master (new, this); - goto out; +return ; }/* This must be a fresh one. */
@@ -420,9 +408,6 @@ static void ip_nat_q931_expect(struct nf/* hook doesn't matter, but it has to do destination manip */ nf_nat_setup_info (new, &range,NF_IP_PRE_ROUTING ); - - out: -nf_conntrack_q931_expect (new, this); }/****************************************************************************/
@@ -510,8 +495,6 @@ static void ip_nat_callforwarding_expect/* hook doesn't matter, but it has to do destination manip */ nf_nat_setup_info (new, &range,NF_IP_PRE_ROUTING ); - -nf_conntrack_q931_expect (new, this); }/****************************************************************************/
net/netfilter/nf_conntrack_helper_h323.c +10 -50
168 lines not on this page · raw message
From: Patrick McHardy <[email protected]>
Date: Thu, 30 Nov 2006 16:45:19 +0100
Quoted 5 lines
I've added these three patches to fix the allocation problems. I don't want to add the new module option introduced by Jozsef's patch since the current situation is just ridiculous, we need to search for both helpers and expectations twice for every new connection, so this needs to be redesigned anyway.
I agree.
Quoted 6 lines
It seems to work fine in some quick testing. This was the last problem I'm aware of, so I'm probably going to push all patches soon.
Last thing is the helper renaming, any objections to prefix all helpers with
nf_conntrack_helper_?
no objection.
-- Yasuyuki Kozakai
Hi Patrick,
Quoted 3 lines · Patrick McHardy
I've added these three patches to fix the allocation problems. I don't want to add the new module option introduced by Jozsef's patch since the current situation is just ridiculous,
In your patch the part
net/netfilter/nf_conntrack_core.c +2 -1
@@ -579,7 +579,8 @@ __nf_conntrack_alloc(const struct nf_con/* FIXME: protect helper list per RCU */ read_lock_bh (&nf_conntrack_lock); helper =__nf_ct_helper_find (repl); -if (helper) +/* NAT might want to assign a helper later */ +if (helper || features &NF_CT_F_NAT ) features |=NF_CT_F_HELP ;read_unlock_bh (&nf_conntrack_lock);
means that in the IPv4+NAT case we loose what we wanted to gain by the features, i.e. for IPv4 with NAT all conntrack entries will be full sized.
Quoted 2 lines
we need to search for both helpers and expectations twice for every new connection, so this needs to be redesigned anyway.
As I see this is the price we pay for the features.
What disturbs me is that by the patch segment above, in spite of the features we does not gain anything in memory footprint. And the only reason for this is that we execute an internal helper lookup after (D)NAT, which can *possibly* change the helper (and which is a nice feature).
In order not to loose practically the features in the IPv4+NAT case I added the 'keep_helper' module parameter. Because - I think - the typical DNAT setups do not rely on the second helper lookup, the good default value were '1', i.e. do not waste time on looking up the helper again after DNAT *and* in the new structure keep the features. The backward compatibility would dictate that the default value is '0'.
I do not argue for the module parameter. But let us do not throw away the features in the case of the most usual configuration in the present days.
Quoted 2 lines
Last thing is the helper renaming, any objections to prefix all helpers with
nf_conntrack_helper_?
Fine, that'll make the code more clear.
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 16 lines · Jozsef Kadlecsik
Hi Patrick,
In your patch the part
net/netfilter/nf_conntrack_core.c +2
-1@@ -579,7 +579,8 @@ __nf_conntrack_alloc(const struct nf_con/* FIXME: protect helper list per RCU */ read_lock_bh (&nf_conntrack_lock); helper =__nf_ct_helper_find (repl); -if (helper) +/* NAT might want to assign a helper later */ +if (helper || features &NF_CT_F_NAT ) features |=NF_CT_F_HELP ;read_unlock_bh (&nf_conntrack_lock);
Quoted 2 lines
means that in the IPv4+NAT case we loose what we wanted to gain by the features, i.e. for IPv4 with NAT all conntrack entries will be full sized.
Yes - actually that part is similar to your patch besides the keep_helper option.
Quoted 5 lines
Quoted 2 lines
we need to search for both helpers and expectations twice for every new connection, so this needs to be redesigned anyway.
As I see this is the price we pay for the features.
I see it as a sign of serious misfit of the allocation scheme. The helper and expectation lookups both really suck performance wise already, doing them twice is just horrible.
Quoted 12 lines
What disturbs me is that by the patch segment above, in spite of the features we does not gain anything in memory footprint. And the only reason for this is that we execute an internal helper lookup after (D)NAT, which can *possibly* change the helper (and which is a nice feature).
In order not to loose practically the features in the IPv4+NAT case I added the '
keep_helper' module parameter. Because - I think - the typical DNAT setups do not rely on the second helper lookup, the good default value were '1', i.e. do not waste time on looking up the helper again after DNAT *and* in the new structure keep the features. The backward compatibility would dictate that the default value is '0'.
Quoted 2 lines
I do not argue for the module parameter. But let us do not throw away the features in the case of the most usual configuration in the present days.
The reason why I didn't want to add it is that IMO the allocation scheme needs to be redesigned anyway, so when we do it we might end up with a module parameter we had for two months and need to carry around forever. We can still add it any time we want, but for now my priority is to get it right (i.e. working properly, not optimized) without doing anything we might regret later. Module parameters for rather obscure internal stuff tend not to get used anyway, so most users don't loose anything.
On Fri, 1 Dec 2006, Patrick McHardy wrote:
[...]
Quoted 8 lines
The reason why I didn't want to add it is that IMO the allocation scheme needs to be redesigned anyway, so when we do it we might end up with a module parameter we had for two months and need to carry around forever. We can still add it any time we want, but for now my priority is to get it right (i.e. working properly, not optimized) without doing anything we might regret later. Module parameters for rather obscure internal stuff tend not to get used anyway, so most users don't loose anything.
You're right. And that double lookup is truly horrid, we'll have to find a way to eliminate.
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 5 lines · Jozsef Kadlecsik
Quoted 2 lines
Last thing is the helper renaming, any objections to prefix all helpers with
nf_conntrack_helper_?Fine, that'll make the code more clear.
Actually I only wanted to rename the files because I kept getting annoyed by tab completion on the pptp and H.323 helpers requiring 5 interactions. Prefixing everything with nf_conntrack_helper_ turned out quite ugly (way too long), so I now did the opposite and renamed PPTP and H.323 to be more consistent with the other helpers.