Skip to contentSkip to conversation

ipt_account fixup

PATCH Applied Piotr Gasidło 2 participants 2 messages May 9, 2005 – May 17, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipt_account fixup

Hello,

Little changes to ipt_account:
- added time field,
- better error handling in __init,
- new module parameters handling in 2.6.x version

Please apply.

Signature · 4 lines
Piotr 'QuakeR' Gasidło, BOFH @ pandora.barbara.eu.org
############## sending lusers to /dev/null since 1998
##### Waiting for tomorrow, for a little ray of light
### Waiting for tomorrow just to see your smile again
account/linux/net/ipv4/netfilter/ipt_account.c +22 -8
diff -uNr patch-o-matic-ng.orig/account/linux/net/ipv4/netfilter/ipt_account.c patch-o-matic-ng/account/linux/net/ipv4/netfilter/ipt_account.c
@@ -453,10 +453,12 @@
 	unsigned int *bucket = (unsigned int *)v;
 
 	u_int32_t address = table->network + *bucket;
+	struct timespec last;
 
 	if (!table->shortlisting) {
+		jiffies_to_timespec(jiffies - table->ip_list.l[*bucket].time, &last);
 		seq_printf(s,
-				"ip = %u.%u.%u.%u bytes_src = %llu %llu %llu %llu %llu packets_src = %llu %llu %llu %llu %llu bytes_dest = %llu %llu %llu %llu %llu packets_dest = %llu %llu %llu %llu %llu\n",
+				"ip = %u.%u.%u.%u bytes_src = %llu %llu %llu %llu %llu packets_src = %llu %llu %llu %llu %llu bytes_dest = %llu %llu %llu %llu %llu packets_dest = %llu %llu %llu %llu %llu time = %lu\n",
 				HIPQUAD(address),
 				table->ip_list.l[*bucket].src.b_all,
 				table->ip_list.l[*bucket].src.b_tcp,
@@ -477,16 +479,19 @@
 				table->ip_list.l[*bucket].dest.p_tcp,
 				table->ip_list.l[*bucket].dest.p_udp,
 				table->ip_list.l[*bucket].dest.p_icmp,
-				table->ip_list.l[*bucket].dest.p_other
+				table->ip_list.l[*bucket].dest.p_other,
+				last.tv_sec
 			);
 	} else {
+		jiffies_to_timespec(jiffies - table->ip_list.s[*bucket].time, &last);
 		seq_printf(s,
-				"ip = %u.%u.%u.%u bytes_src = %llu packets_src = %llu bytes_dest = %llu packets_dest = %llu\n",
+				"ip = %u.%u.%u.%u bytes_src = %llu packets_src = %llu bytes_dest = %llu packets_dest = %llu time = %lu\n",
 				HIPQUAD(address),
 				table->ip_list.s[*bucket].src.b_all,
 				table->ip_list.s[*bucket].src.p_all,
 				table->ip_list.s[*bucket].dest.b_all,
-				table->ip_list.s[*bucket].dest.p_all
+				table->ip_list.s[*bucket].dest.p_all,
+				last.tv_sec
 			  );
 	}
 	return 0;
@@ -891,25 +896,34 @@
 
 static int __init init(void) 
 {
+	int err;
+	
 	dprintk(KERN_INFO IPT_ACCOUNT_NAME ": __init() entered.\n");
 	printk(version);	
 	/* check params */
 	if (netmask > 32 || netmask < 0) {
 		printk(KERN_INFO "account: Wrong netmask given by netmask parameter (%i). Valid is 32 to 0.\n", netmask);
-		return -EINVAL;
+		err = -EINVAL;
+		goto doexit;
 	}
 
 	/* create /proc/net/ipt_account directory */
 	proc_net_ipt_account = proc_mkdir("ipt_account", proc_net);
 	if (!proc_net_ipt_account) {		
 		printk(KERN_INFO IPT_ACCOUNT_NAME ": checkentry() failed to create procfs entry.\n");
-		return -EINVAL; /* was -ENOMEM */
+		err = -ENOMEM;
+		goto doexit;
 	}
 	proc_net_ipt_account->owner = THIS_MODULE;
 	
+	err = ipt_register_match(&account_match);
+	if (err) {
+		printk(KERN_INFO IPT_ACCOUNT_NAME ": checkentry() failed to register match.\n");
+		remove_proc_entry("ipt_account", proc_net);
+	}
+doexit:
 	dprintk(KERN_INFO IPT_ACCOUNT_NAME ": __init() left.\n");
-
-	return ipt_register_match(&account_match);
+	return err;
 }
 
 static void __exit fini(void) 
account/linux-2.6/net/ipv4/netfilter/ipt_account.c +30 -16

131 lines not on this page · raw message

#1 lore raw
Quoted 8 lines · Piotr Gasid³o

Hello,

Little changes to ipt_account:
- added time field,
- better error handling in __init,
- new module parameters handling in 2.6.x version

Please apply.

Applied, thanks.