Re: ebtables -X does not delete all unused chains
Bart De Schuymer <[email protected]>
| Newsgroups | gmane.linux.network.bridge.ebtables.devel |
|---|---|
| Message-ID | <[email protected]> |
Op ma, 31-07-2006 te 10:03 -0600, schreef Alberto Treviño: > Needless to say I am playing with ebtables and I am finding a few bugs. > I don't know if the developers will be happy or if they will get tired > of all my bug reports. :-) I'm not trying to make the developer's life > difficult. I promise. The period before I release the stable version is the ideal time to find and report bugs. Thanks, I appreciate it. > I am running 2.0.8-rc2 + segfault patch. I am writing a script to > program my bridge rules. At the beginning of the script I have the > following commands: > > ebtables -F > ebtables -X > > In theory, ebtables should flush all the chains in the default table and > remove all unused user-defined chains. I found the -X command, > however, is not deleting all the user-defined chains. It only deletes > the odd-numbered ones (as given in the list) and the even ones remain > intact. Here is the example, starting from scratch: The attached patch should fix it. Apply in the same way as before (on top of the previous patch). cheers, Bart ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Ebtables-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ebtables-devel
patch.diff
(text/x-patch, 1.7 KB)
--- ebtables2/libebtc.c.old 2006-07-31 21:37:39.000000000 +0200
+++ ebtables2/libebtc.c 2006-07-31 21:40:51.000000000 +0200
@@ -838,7 +838,8 @@ void ebt_new_chain(struct ebt_u_replace
new->kernel_start = NULL;
}
-static void ebt_delete_a_chain(struct ebt_u_replace *replace, int chain, int print_err)
+/* returns -1 if the chain is referenced, 0 on success */
+static int ebt_delete_a_chain(struct ebt_u_replace *replace, int chain, int print_err)
{
int tmp = replace->selected_chain;
/* If the chain is referenced, don't delete it,
@@ -846,7 +847,7 @@ static void ebt_delete_a_chain(struct eb
* one we're deleting */
replace->selected_chain = chain;
if (ebt_check_for_references(replace, print_err))
- return;
+ return -1;
decrease_chain_jumps(replace);
ebt_flush_chains(replace);
replace->selected_chain = tmp;
@@ -854,20 +855,22 @@ static void ebt_delete_a_chain(struct eb
free(replace->chains[chain]);
memmove(replace->chains+chain, replace->chains+chain+1, (replace->num_chains-chain-1)*sizeof(void *));
replace->num_chains--;
+ return 0;
}
/* Selected_chain == -1: delete all non-referenced udc
* selected_chain < NF_BR_NUMHOOKS is illegal */
void ebt_delete_chain(struct ebt_u_replace *replace)
{
- int i;
-
if (replace->selected_chain != -1 && replace->selected_chain < NF_BR_NUMHOOKS)
ebt_print_bug("You can't remove a standard chain");
- if (replace->selected_chain == -1)
- for (i = NF_BR_NUMHOOKS; i < replace->num_chains; i++)
- ebt_delete_a_chain(replace, i, 0);
- else
+ if (replace->selected_chain == -1) {
+ int i = NF_BR_NUMHOOKS;
+
+ while (i < replace->num_chains)
+ if (ebt_delete_a_chain(replace, i, 0))
+ i++;
+ } else
ebt_delete_a_chain(replace, replace->selected_chain, 1);
}