* flushing conntrack-table
@ 2005-03-11 23:34 Olaf Rempel
2005-03-12 0:51 ` Tobias DiPasquale
0 siblings, 1 reply; 2+ messages in thread
From: Olaf Rempel @ 2005-03-11 23:34 UTC (permalink / raw)
To: netfilter-devel
Hi list
I've build a modul to flush some/all conntracks from the ct-table, but have
some questions about the used functions and locking issues.
I'm sending a "search pattern" (proto + srcip/mask + sport-range + dstip/mask
+ dport-range) via ioctl (yeah, i know..) to the kernel, and delete all matching
conntracks.
As far as I understand, I don't need hold a lock while iterating over the
hash-buckets, only when accessing the list inside.
To actually delete a conntrack (via del_timer + ct->timeout.function) the code
must NOT hold the readlock, because death_by_timeout() grabs the writelock.
Correct?
idea 1:
if a matching tuple is found, abort the search, delete conntrack and restart
search in same bucket (assuming that there could be another matching tuple):
while (bucket < ip_conntrack_htable_size) {
struct ip_conntrack *ct = NULL;
READ_LOCK(&ip_conntrack_lock);
list_for_each_entry(hash_tuple, &ip_conntrack_hash[bucket], list) {
if (match_pattern(hash_tuple, pattern)) {
ct = tuplehash_to_ctrack(hash_tuple);
break;
}
}
READ_UNLOCK(&ip_conntrack_lock);
if (ct) {
if (del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
} else {
bucket++;
}
}
idea 2:
same as idea 1, but storing N matching conntracks in an array. if the array is
full, or the search in this bucket is complete then delete the found conntracks.
if array was full, restart search in same bucket else do next bucket.
N is small (~4), just to avoid search-restart in the same bucket with 2-3 matching
tuples. (don't know if it's needed)
idea 3:
use list_for_each_entry_safe(), when a matching tuple is found,
release the readlock, delete the conntrack, grab readlock, resume search:
READ_LOCK(&ip_conntrack_lock);
list_for_each_entry_safe(hash_tuple, tmp, &ip_conntrack_hash[bucket], list) {
if (match_pattern(hash_tuple, pattern)) {
ct = tuplehash_to_ctrack(hash_tuple);
READ_UNLOCK(&ip_conntrack_lock);
if (del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
READ_LOCK(&ip_conntrack_lock);
}
}
READ_UNLOCK(&ip_conntrack_lock);
I know I could do this with ctnetlink or something equal, but I want to try this
in kernel. The code from idea #2 works for me, but I just want to know if it's
a good way.
So, which of these ideas is "the best"?
Or am I missing something (== my code is crap :)
Olaf
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: flushing conntrack-table
2005-03-11 23:34 flushing conntrack-table Olaf Rempel
@ 2005-03-12 0:51 ` Tobias DiPasquale
0 siblings, 0 replies; 2+ messages in thread
From: Tobias DiPasquale @ 2005-03-12 0:51 UTC (permalink / raw)
To: Olaf Rempel; +Cc: netfilter-devel
On Sat, 12 Mar 2005 00:34:18 +0100, Olaf Rempel <razzor@kopf-tisch.de> wrote:
> I've build a modul to flush some/all conntracks from the ct-table, but have
> some questions about the used functions and locking issues.
>
> I'm sending a "search pattern" (proto + srcip/mask + sport-range + dstip/mask
> + dport-range) via ioctl (yeah, i know..) to the kernel, and delete all matching
> conntracks.
This is in fact what the kill parameter to ip_ct_selective_cleanup()
was designed for. Check out its definition in ip_conntrack_core.c and
its usage later on in that same file in the ip_conntrack_cleanup()
function.
--
[ Tobias DiPasquale ]
0x636f6465736c696e67657240676d61696c2e636f6d
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-03-12 0:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-11 23:34 flushing conntrack-table Olaf Rempel
2005-03-12 0:51 ` Tobias DiPasquale
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.