Skip to contentSkip to conversation

ipt_account update

PATCH In review Piotr Gasidło 2 participants 2 messages Jul 16, 2004 – Jul 23, 2004 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipt_account update

Hello,

I've recently updated ipt_account match.

Changes in 0.1.6:
- rewritted locking
- removed 32-bit statistics, only 64-bit are available, new names for tables in procfs (no _32 and _64 postfix)
- added --ashort switch to create "short" tables (only sum of all traffic, no individual protocol statistics)
- counters can be changed (loaded) using procfs

Updated documentation (polish but also english) will be soon available on my homepage.

Please apply patch to CVS.

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
extensions/libipt_account.c +53 -19
diff -uNr iptables.clean/extensions/libipt_account.c iptables.1/extensions/libipt_account.c
@@ -2,7 +2,7 @@
  * accounting match helper (libipt_account.c)
  * (C) 2003,2004 by Piotr Gasidło ([email protected])
  *
- * Version: 0.1.5
+ * Version: 0.1.6
  *
  * This software is distributed under the terms of GNU GPL
  */
@@ -31,15 +31,18 @@
 			"--aname name\n"
 			"	defines name of list where statistics will be kept. If no is\n"
 			"	specified DEFAULT will be used.\n"
-
+			"--ashort\n"
+			"       table will colect only short statistics (only total counters\n"
+			"       without splitting it into protocols.\n"
 	, 
 	IPTABLES_VERSION);
 };
 
 static struct option opts[] = {
-	{ "aaddr", 1, NULL, 201 },
-	{ "aname", 1, NULL, 202 },
-	{ 0 }
+	{ .name = "aaddr",  .has_arg = 1, .flag = NULL, .val = 201 },
+	{ .name = "aname",  .has_arg = 1, .flag = NULL, .val = 202 },
+	{ .name = "ashort", .has_arg = 0, .flag = NULL, .val = 203 },
+	{ .name = 0, .has_arg = 0, .flag = 0, .val = 0 }
 };
 
 /* Helper functions for parse_network */
@@ -139,6 +142,26 @@
 	
 }
 
+/* validate netmask */
+inline int valid_netmask(u_int32_t netmask) {
+	while (netmask & 0x80000000)
+		netmask <<= 1;
+	if (netmask != 0)
+		return 0;
+        return 1;
+}
+
+/* validate network/netmask pair */
+inline int valid_network_and_netmask(struct t_ipt_account_info *info) {
+	if (!valid_netmask(info->netmask))
+		return 0;
+	if ((info->network & info->netmask) != info->network)
+		return 0;
+	return 1;
+}
+
+
+
 /* Function initializes match */
 static void init(struct ipt_entry_match *match, 
 		 unsigned int *nfcache) {
@@ -149,6 +172,7 @@
 
 	/* set default table name to DEFAULT */
 	strncpy(info->name, "DEFAULT", IPT_ACCOUNT_NAME_LEN);
+	info->shortlisting = 0;
 	
 }
 
@@ -166,7 +190,9 @@
 		
 		/* --aaddr */
 		case 201:
-			parse_network(optarg, info);			
+			parse_network(optarg, info);
+			if (!valid_network_and_netmask(info))
+				exit_error(PARAMETER_PROBLEM, "account: wrong network/netmask");
 			*flags = 1;
 			break;
 			
@@ -175,8 +201,12 @@
 			if (strlen(optarg) < IPT_ACCOUNT_NAME_LEN)
 				strncpy(info->name, optarg, IPT_ACCOUNT_NAME_LEN);
 			else
-				exit_error(PARAMETER_PROBLEM, "account: Too long list name");			
+				exit_error(PARAMETER_PROBLEM, "account: Too long table name");			
 			break;	
+		/* --ashort */
+		case 203:
+			info->shortlisting = 1;
+			break;
 		default:
 			return 0;			
 	}
@@ -204,6 +234,8 @@
 	      );
 	
 	printf("name: %s ", info->name);
+	if (info->shortlisting)
+		printf("short-listing ");
 }
 
 /* Function used for saving rule containing account match */
@@ -219,21 +251,23 @@
 	       );
 	
 	printf("--aname %s ", info->name);
+	if (info->shortlisting)
+		printf("--ashort ");
 }
 	
 static struct iptables_match account = {
-	NULL,			/* struct iptables_match *next; */
-	"account",		/* ipt_chainlabel name; */
-	IPTABLES_VERSION,	/* const char *version; */
-	IPT_ALIGN(sizeof(struct t_ipt_account_info)),		/* Size of match data. */
-	IPT_ALIGN(sizeof(struct t_ipt_account_info)),		/* Size of match data relevent for userspace comparison purposes */
-	&help,			/* Function which prints out usage message. */
-	&init,			/* Initialize the match. */
-	&parse,			/* Function which parses command options; returns true if it ate an option */
-	&final_check,		/* Final check; exit if not ok. */
-	&print,			/* Prints out the match iff non-NULL: put space at end */
-	&save,			/* Saves the match info in parsable form to stdout. */
-	opts			/* Pointer to list of extra command-line options */
+	.next = NULL,
+	.name = "account",
+	.version = IPTABLES_VERSION,
+	.size = IPT_ALIGN(sizeof(struct t_ipt_account_info)),
+	.userspacesize = IPT_ALIGN(sizeof(struct t_ipt_account_info)),
+	.help = &help,
+	.init = &init,
+	.parse = &parse,
+	.final_check = &final_check,
+	.print = &print,
+	.save = &save,
+	.extra_opts = opts
 };
 
 /* Function which registers match */
ACCOUNT/linux/Documentation/Configure.help.ladd +0 -19
diff -uNr patch-o-matic-ng.clean/ACCOUNT/linux/Documentation/Configure.help.ladd patch-o-matic-ng.1/ACCOUNT/linux/Documentation/Configure.help.ladd
@@ -1,19 +0,0 @@
-CONFIG_IP_NF_TARGET_ULOG
-ACCOUNT target support
-CONFIG_IP_NF_TARGET_ACCOUNT
-
-  The ACCOUNT target is a high performance accounting system for local networks.
-  It takes two parameters: --addr network/netmask and --tname NAME.
-
-  --addr is the subnet which is accounted for
-  --tname is the table name where the information is stored
-
-  The data can be queried later using the libipt_ACCOUNT userspace library
-  or by the "iptaccount" tool which is part of the libipt_ACCOUNT package.
-
-  A special subnet is "0.0.0.0/0": All data is stored in the src_bytes
-  and src_packets structure of slot "0". This is useful if you want
-  to account the overall traffic to/from your internet provider.
-
-  If you want to compile it as a module, say M here and read
-  Documentation/modules.txt.  If unsure, say `N'.
account/help +31 -3
diff -uNr patch-o-matic-ng.clean/account/help patch-o-matic-ng.1/account/help
@@ -1,5 +1,33 @@
-This match is used for accounting traffic.
+This match is used for accounting traffic for all hosts in
+defined network/netmask. 
 
-Short options are available by using 'iptables -m account -h'
-Official Website: <http://www.barbara.eu.org/~quaker/ipt_account/>
+Features:
+- long (one counter per protocol TCP/UDP/IMCP/Other) and short statistics
+- one iptables rule for all hosts in network/netmask
+- loading/saving counters (by reading/writting to procfs entries)
 
+Example usage:
+
+account traffic for/to 192.168.0.0/24 network into table mynetwork:
+
+# iptables -A FORWARD -m account --aname mynetwork --aaddr 192.168.0.0/24
+
+account traffic for/to WWW serwer for 192.168.0.0/24 network into table 
+  mywwwserver:
+
+# iptables -A INPUT -p tcp --dport 80 
+  -m account --aname mywwwserver --aaddr 192.168.0.0/24 --ashort
+# iptables -A OUTPUT -p tcp --sport 80
+  -m account --aname mywwwserver --aaddr 192.168.0.0/24 --ashort    
+  
+read counters:
+
+# cat /proc/net/ipt_account/mynetwork
+# cat /proc/net/ipt_account/mywwwserver
+
+set counters:
+
+# echo "ip = 192.168.0.1 packets_src = 0" > /proc/net/ipt_account/mywwserver
+  
+Webpage: 
+  http://www.barbara.eu.org/~quaker/ipt_account/  
account/info +0 -1
diff -uNr patch-o-matic-ng.clean/account/info patch-o-matic-ng.1/account/info
@@ -1,4 +1,3 @@
 Author: Piotr Gasido <[email protected]>
 Status: working
 Repository: extra
-Requires: linux < 2.6.0
account/linux/Documentation/Configure.help.ladd +47 -0

48 lines not on this page · raw message

account/linux/include/linux/netfilter_ipv4/ipt_account.h +7 -2
diff -uNr patch-o-matic-ng.clean/account/linux/include/linux/netfilter_ipv4/ipt_account.h patch-o-matic-ng.1/account/linux/include/linux/netfilter_ipv4/ipt_account.h
@@ -1,8 +1,8 @@
 /* 
  * accounting match (ipt_account.c)
- * (C) 2003,2004 by Piotr Gasidło ([email protected])
+ * (C) 2003,2004 by Piotr Gasidlo ([email protected])
  *
- * Version: 0.1.5
+ * Version: 0.1.6
  *
  * This software is distributed under the terms of GNU GPL
  */
@@ -12,10 +12,15 @@
 
 #define IPT_ACCOUNT_NAME_LEN 64
 
+#define IPT_ACCOUNT_NAME "ipt_account"
+#define IPT_ACCOUNT_VERSION  "0.1.6"
+
 struct t_ipt_account_info {
 	char name[IPT_ACCOUNT_NAME_LEN];
 	u_int32_t network;
 	u_int32_t netmask;
+	int shortlisting:1;
 };
 
 #endif
+
account/linux/net/ipv4/netfilter/Config.in.ladd +4 -1
diff -uNr patch-o-matic-ng.clean/account/linux/net/ipv4/netfilter/Config.in.ladd patch-o-matic-ng.1/account/linux/net/ipv4/netfilter/Config.in.ladd
@@ -1,2 +1,5 @@
   dep_tristate '  TOS match support' CONFIG_IP_NF_MATCH_TOS $CONFIG_IP_NF_IPTABLES
-  dep_tristate '  account match support' CONFIG_IP_NF_MATCH_ACCOUNT $CONFIG_IP_NF_IPTABLES
+  dep_tristate '  account match support' CONFIG_IP_NF_MATCH_ACCOUNT $CONFIG_IP_NF_IPTABLES $CONFIG_PROC_FS
+  if [ "$CONFIG_IP_NF_MATCH_ACCOUNT" != "n" ]; then 
+    bool '    account debugging output' CONFIG_IP_NF_MATCH_ACCOUNT_DEBUG
+  fi
account/linux/net/ipv4/netfilter/ipt_account.c +668 -361

1,257 lines not on this page · raw message

account/linux-2.6/include/linux/netfilter_ipv4/ipt_account.h +26 -0
diff -uNr patch-o-matic-ng.clean/account/linux-2.6/include/linux/netfilter_ipv4/ipt_account.h patch-o-matic-ng.1/account/linux-2.6/include/linux/netfilter_ipv4/ipt_account.h
@@ -0,0 +1,26 @@
+/* 
+ * accounting match (ipt_account.c)
+ * (C) 2003,2004 by Piotr Gasidlo ([email protected])
+ *
+ * Version: 0.1.6
+ *
+ * This software is distributed under the terms of GNU GPL
+ */
+
+#ifndef _IPT_ACCOUNT_H_
+#define _IPT_ACCOUNT_H_
+
+#define IPT_ACCOUNT_NAME_LEN 64
+
+#define IPT_ACCOUNT_NAME "ipt_account"
+#define IPT_ACCOUNT_VERSION  "0.1.6"
+
+struct t_ipt_account_info {
+	char name[IPT_ACCOUNT_NAME_LEN];
+	u_int32_t network;
+	u_int32_t netmask;
+	int shortlisting:1;
+};
+
+#endif
+
account/linux-2.6/net/ipv4/netfilter/Kconfig.ladd +47 -0

47 lines not on this page · raw message

account/linux-2.6/net/ipv4/netfilter/Makefile.ladd +2 -0
diff -uNr patch-o-matic-ng.clean/account/linux-2.6/net/ipv4/netfilter/Makefile.ladd patch-o-matic-ng.1/account/linux-2.6/net/ipv4/netfilter/Makefile.ladd
@@ -0,0 +1,2 @@
+obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
+obj-$(CONFIG_IP_NF_MATCH_ACCOUNT) += ipt_account.o
account/linux-2.6/net/ipv4/netfilter/ipt_account.c +922 -0

922 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Piotr Gasid?o

Hello,

I've recently updated ipt_account match.

patch applied.

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.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