Re: Byte counters zeroed when creating/deleting chain

Bart De Schuymer <[email protected]>
Newsgroups gmane.linux.network.bridge.ebtables.devel
Message-ID <[email protected]>
> > I noticed that when creating or deleting user-defined chains in ebtables,
> > the byte and packet counters for previously added rules are zeroed.
>
> Yes, it's a bug. Renaming or deleting a chain will have the same result.

Fixed in the CVS.
This is the patch:

--- ebtables-v2.0.4/ebtables.c	Sat May 24 23:34:22 2003
+++ ebtables-v2.0.5-pre/ebtables.c	Sat Jun 14 15:15:01 2003
@@ -927,12 +927,34 @@ static void list_rules()
 	}
 }
 
+static void counters_nochange()
+{
+	int i;
+
+	replace.num_counters = replace.nentries;
+	if (replace.nentries) {
+		/*
+		 * '+ 1' for the CNT_END
+		 */
+		if (!(replace.counterchanges = (unsigned short *) malloc(
+		   (replace.nentries + 1) * sizeof(unsigned short))))
+			print_memory();
+		/*
+		 * done nothing special to the rules
+		 */
+		for (i = 0; i < replace.nentries; i++)
+			replace.counterchanges[i] = CNT_NORM;
+		replace.counterchanges[replace.nentries] = CNT_END;
+	}
+	else
+		replace.counterchanges = NULL;
+}
+
 /*
  * execute command P
  */
 static void change_policy(int policy)
 {
-	int i;
 	struct ebt_u_entries *entries = to_chain();
 
 	/*
@@ -940,25 +962,8 @@ static void change_policy(int policy)
 	 */
 	if (entries->policy != policy) {
 		entries->policy = policy;
-		replace.num_counters = replace.nentries;
-		if (replace.nentries) {
-			/*
-			 * '+ 1' for the CNT_END
-			 */
-			if (!(replace.counterchanges = (unsigned short *) malloc(
-			   (replace.nentries + 1) * sizeof(unsigned short))))
-				print_memory();
-			/*
-			 * done nothing special to the rules
-			 */
-			for (i = 0; i < replace.nentries; i++)
-				replace.counterchanges[i] = CNT_NORM;
-			replace.counterchanges[replace.nentries] = CNT_END;
-		}
-		else
-			replace.counterchanges = NULL;
-	}
-	else
+		counters_nochange();
+	} else
 		exit(0);
 }
 
@@ -1727,6 +1732,7 @@ int main(int argc, char *argv[])
 				while (*cl2)
 					cl2 = &((*cl2)->next);
 				*cl2 = cl;
+				counters_nochange();
 				break;
 			}
 			if ((replace.selected_hook = get_hooknr(optarg)) == -1)
@@ -1746,6 +1752,7 @@ int main(int argc, char *argv[])
 					   , argv[optind]);
 				entries = to_chain();
 				strcpy(entries->name, argv[optind]);
+				counters_nochange();
 				optind++;
 				break;
 			}
@@ -1760,7 +1767,8 @@ int main(int argc, char *argv[])
 				 * one we're deleting
 				 */
 				check_for_references(replace.selected_hook - NF_BR_NUMHOOKS);
-				flush_chains();
+				if (flush_chains() == -1)
+					counters_nochange();
 				entries = to_chain();
 				cl2 = &(replace.udc);
 				while ((*cl2)->udc != entries)



-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.