Skip to contentSkip to conversation

expire module issue

DISCUSSION Bryan Cardillo 3 participants 3 messages Jul 6, 2005 – Jul 25, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

I'm having a problem with the expire module I submitted a few days (weeks, maybe?) ago. The observed behavior is that expired rules cannot be deleted from built-in chains. I think the issue is related to deleting a rule (ipt_entry) without fixing hook_entry / underflow to reflect the deleted rule.

My understanding of hook_entry / underflow is limited, so maybe someone can enlighten me. For those who haven't studied the code, the basic idea is to approximate `iptables -D' for the expired rule. So, the pseudo-code goes something like this:

nf_getsockopt(IPT_GET_INFO) nf_getsockopt(IPT_GET_ENTRIES)
for each entry in (entries)
if (not(is_expired(entry)))
copy(replace->entries[i++], entry)
nf_setsockopt(IPT_REPLACE)

now, this works fine for user-defined chains with no jumps, but thats it. I've tried adding code to subtract the size of the expired entries from hook_entries which are past the entry address. this gets me past the hook_entry check in do_replace, only to get flagged as a loop in mark_source_chains.

I've been using the iptables libiptc code as a guide for implementing the rule deletion, but since this is strictly a deletion, I'd rather not put the entire ruleset parsing and compilation code in the kernel ;) Any ideas how I can patch up hook_entry / underflow appropriately? Is this even the problem?

Cheers,
Bryan Cardillo
Penn Bioinformatics Core
University of Pennsylvania
[email protected]

#1 lore raw
Quoted 6 lines · Bryan Cardillo

I've been using the iptables libiptc code as a guide for implementing the rule deletion, but since this is strictly a deletion, I'd rather not put the entire ruleset parsing and compilation code in the kernel ;) Any ideas how I can patch up hook_entry / underflow appropriately? Is this even the problem?

It sounds like it could be the source of your problem, yes. The reason why the linnux kernel has no support for parsing/compiling the ruleset was not an artificial one... so you're basically tryign what was intended not to work ;)

Unfortunately I don't have the time to analyze your code and/or the associated problem :(

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#2 lore raw
In reply to Bryan Cardillo
Quoted 6 lines · Bryan Cardillo

I'm having a problem with the expire module I submitted a few days (weeks, maybe?) ago. The observed behavior is that expired rules cannot be deleted from built-in chains. I think the issue is related to deleting a rule (ipt_entry) without fixing hook_entry / underflow to reflect the deleted rule.

...

Quoted 6 lines

I've been using the iptables libiptc code as a guide for implementing the rule deletion, but since this is strictly a deletion, I'd rather not put the entire ruleset parsing and compilation code in the kernel ;) Any ideas how I can patch up hook_entry / underflow appropriately? Is this even the problem?

Oh my, I've been just _looking_ at that library recently and I think this
way of modifing the tables is a very bad idea. IMO it's very similar to doing a binary patch on an executable, not something to be attempted in kernel space.

I would suggest you don't even try. :-)

Instead, how about leaving the rule behind in the table but when it
expires add an IPT_F_UNMATCHABLE flag to the rule (in ipt_entry.ip.flags)
The next time iptables is used to modify the table have _it_ skip the rule and delete it for you.

That should be the only cost and as a normal 'use case' would have new rules being added steadly the undeleted expired rules would be purged pretty quickly.

An advantage would be that until that next modify you could still see the counters on expired rules. (Plus no fixups of course :)

PS: You won't lke this, but, it appears possible to have calls jumping
to the middle of a chain. I'd guess that's what the 'high performance' rule generating programs do. This makes it _exactly_ like an executable; you can strip symbols too!

Signature · 2 lines
Rob.                          (Robert de Bath <robert$ @ debath.co.uk>)
                                             <http://www.debath.co.uk/>