Skip to contentSkip to conversation

ipt_recent 0.3.0 --rttl still doesn't work (I made a patch instead, can't wait)

PATCH per j 2 participants 2 messages Mar 3, 2003

lore
Share & tools
lore

per j

author
#0 lore raw

I've played around with -j TTL and no it doesn't have to do with the TTL mangled in the FORWARD chain because all my rules with -m recent are in INPUT chain or the beginning of the FORWARD chain before ACCEPT.

I tried out the ipt_recent-0.3.0 release and the problem still exists. I turned on debug and found out r_list[location].ttl is always the same and doesn't even come close to the ttl value stored in the recent list.

I got pretty fussed up patching and re-patching my kernel and your latest release still didn't fix the --rttl problem. Finally I spend quite some time reviewing your source code. Your code on the IPT_RECENT_TTL section doesn't do a single thing because the location variable in r_list[location] doesn't change when hash_result is incremented. I tried adding location = hash_table[hash_result] in the while loop, but that caused kernel panic. I rewrote the whole IPT_RECENT_TTL code and now my tests for TTL matching works. I fixed it!

Also I fixed the (unreported) problem with ttl not being set zero when manually adding ip addresses into the recent list with a for loop in a bash script - eg. for blah_ip in bleh; do echo blah_ip > recentlist; done. Somehow the ttl value is non-zero but all the entires added into the recent list have that same non-zero ttl value. However, doing echo xx.xx.xx.xx > recentlist in the command-line does properly set ttl zero. I wonder why it behaves well when not in a script.

After some tests, I am confident that the following patch to the ipt_recent-0.3.0 source code will fix the --rttl and non-zero ttl problem in userctl. It works for me.

Apologies for posting code here as I've not yet signed up at the developer-list, but let me know if you see any errors.

------------------------------------------------

ipt_recent.c renamed from ipt_recent.c.orig +0 -0
@@ -266,6 +266,7 @@
 
	skb.nh.iph->saddr = addr;
	skb.nh.iph->daddr = addr;
+	skb.nh.iph->ttl = 0;	// ttl happens to be randomly assigned, make sure it is 0.
	match(&skb,NULL,NULL,&info,0,NULL,sizeof(info),NULL);
	kfree(skb.nh.iph);

@@ -354,21 +355,9 @@

	orig_hash_result = hash_result = hash_func(addr,ip_list_hash_size);
	/* Hash entry at this result used */

- /* Check for TTL match if requested. If TTL is zero then a match would never
- * happen, so match regardless of existing TTL in that case. Zero means the
- * entry was added via the /proc interface anyway, so we will just use the
- * first TTL we get for that IP address. */
- if(info->check_set & IPT_RECENT_TTL) {
- while(hash_table[hash_result] != -1 && !(r_list[hash_table[hash_result]].addr == addr &&
- (!r_list[location].ttl || r_list[location].ttl == ttl))) {
- /* Collision in hash table */
- hash_result = (hash_result + 1) % ip_list_hash_size;
- }
- } else {
- while(hash_table[hash_result] != -1 && r_list[hash_table[hash_result]].addr != addr) {
- /* Collision in hash table */
- hash_result = (hash_result + 1) % ip_list_hash_size;
- }
+ while(hash_table[hash_result] != -1 && r_list[hash_table[hash_result]].addr != addr) {
+ /* Collision in hash table */

+		hash_result = (hash_result + 1) % ip_list_hash_size;
	}

	if(hash_table[hash_result] == -1 && !(info->check_set & IPT_RECENT_SET)) {
@@ -459,6 +448,20 @@
				if(hits_found >= info->hit_count) ans = !info->invert; else ans = 
info->invert;
			}
		}

+ /* Check for TTL match if requested. If TTL is zero then a match would never
+ * happen, so match regardless of existing TTL in that case. Zero means the
+ * entry was added via the /proc interface anyway, so we will just use the
+ * first TTL we get for that IP address. */
+ /* IPT_RECENT_TTL -> !ttl match -> ans = info->invert
+ * TTL match section fix by bluecloud <cloudatcu teydotseeohem>
+ * [aka perj8AThotmailDOTcom on the mailing list] */
+ if(info->check_set & IPT_RECENT_TTL && r_list[location].ttl && r_list[location].ttl != ttl) {
+ // TTL did not match
+ ans = info->invert;
+ }
+ if(debug && IPT_RECENT_TTL) printk(KERN_INFO "RECENT_TTL: match(): rttl:%u,ttl:%u \n",
+ r_list[location].ttl,

+				ttl);
		if(debug) {
			if(ans)
				printk(KERN_INFO "RECENT_NAME: match(): match addr: %u\n",addr);

---------------------------------------------------

Quoted 23 lines · * per j ([email protected]) wrote:
Quoted 1 line

Have you got any luck fixing the --rttl bug? It's already been a

couple

Quoted 2 lines

weeks since the last post. I tried to go around this problem with no success. I don't want to put all my rules into one chain, the INPUT

chain,

Quoted 3 lines

to get it to work and prefer separate chains to make my firewall rules easier to maintain. Apparently --rttl doesn't work when --set is on a different chain on the filter table. That's the problem.

Ok, coming back to this issue I'm pretty sure I have an idea as to what the problem is. It's pretty simple, really, the TTL is going to change somewhere while in the kernel. Probably in the routing logic. This means that in PREROUTING the TTL is one thing but in FORWARD (after being routed) it's been decremented by one.

The 'solution' to this problem would really be for the recent module to always go with the initial TTL and detect if the routing logic has been called or not to decide if it needs to increment the TTL to get back to the original TTL. Unfortunately at the moment I'm not sure if that will be very easy or not but I'll look around and see if I can't make this work.

Quoted 2 lines

Stephen
<< attach3 >>

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail

707719e9ad9c64d30c8273e9c9a405ba patch-ctl-rtt-ipt_recent.c-0.3.0.bz2

#1 lore raw
Quoted 3 lines · * per j ([email protected]) wrote:

I've played around with -j TTL and no it doesn't have to do with the TTL mangled in the FORWARD chain because all my rules with -m recent are in INPUT chain or the beginning of the FORWARD chain before ACCEPT.

If your patch is against 0.3.0 then it may very well matter since your patch doesn't remove the 'if(out) ttl++;' line from 0.3.0. Could you check for that?

Quoted 3 lines

I tried out the ipt_recent-0.3.0 release and the problem still exists. I turned on debug and found out r_list[location].ttl is always the same and doesn't even come close to the ttl value stored in the recent list.

Yeah, that's an old bug from when I switched to using hash tables apparently. I believe that *should* read:
while(hash_table[hash_result] != -1 && !(r_list[hash_table[hash_result]].addr == addr &&

	(!r_list[hash_table[hash_result]].ttl || r_list[hash_table[hash_result]].ttl != ttl))) {

Instead. Note that I also had to invert the ttl check, it should be considered a collision when the ttl doesn't match and matching ttl has been requested.

Quoted 8 lines

I got pretty fussed up patching and re-patching my kernel and your latest release still didn't fix the --rttl problem. Finally I spend quite some time reviewing your source code. Your code on the IPT_RECENT_TTL section doesn't do a single thing because the location variable in r_list[location] doesn't change when hash_result is incremented. I tried adding location = hash_table[hash_result] in the while loop, but that caused kernel panic. I rewrote the whole IPT_RECENT_TTL code and now my tests for TTL matching works. I fixed it!

Unfortunately what you did doesn't really work. The goal of doing the TTL match is to differentiate between IP addresses based on their TTL so that they are really considered two seperate entities. What you've done is to only allow one TTL value per IP address, whichever TTL came first. So, for example:

10.10.0.1 sends to router, TTL == 32
10.10.0.1 gets added to recent list with ttl == 32
10.10.0.1 sends to router, TTL == 25
10.10.0.1 gets 'found' in the hash table but then fails the TTL match

10.10.0.1 with TTL of 25 will therefore never make it into the recent list, which is wrong. Instead of just picking the first TTL and going with that these two need to be treated seperately as if they were two different IP addresses.

If you could try the above changes I'd like to hear if they work for you or not. I'll try and find some time to really test the TTL code soon.

Quoted 2 lines

Also I fixed the (unreported) problem with ttl not being set zero when manually adding ip addresses into the recent list with a for loop in a bash

Thanks, added that into my local version.

Stephen