From db97ab228dea9088e6597dec30196fb891464656 Mon Sep 17 00:00:00 2001 From: Bart De Schuymer Date: Thu, 1 Sep 2005 20:37:07 +0000 Subject: [PATCH] try to use ebtablesd/ebtablesu scheme --- Makefile | 5 ++-- ebtables-restore | 71 +++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 00e377d..7d74f8a 100644 --- a/Makefile +++ b/Makefile @@ -112,13 +112,14 @@ daemon: ebtablesd ebtablesu tmp1:=$(shell printf $(BINDIR) | sed 's/\//\\\//g') tmp2:=$(shell printf $(SYSCONFIGDIR) | sed 's/\//\\\//g') +tmp3:=$(shell printf $(PIPE) | sed 's/\//\\\//g') .PHONY: scripts scripts: ebtables-save ebtables-restore ebtables.sysv ebtables-config cat ebtables-save | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-save_ install -m 0755 -o root -g root ebtables-save_ $(BINDIR)/ebtables-save - cat ebtables-restore | sed 's/__EXEC_PATH__/$(tmp1)/g' > ebtables-restore_ + cat ebtables-restore | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__PIPE__/$(tmp3)/g' > ebtables-restore_ install -m 0755 -o root -g root ebtables-restore_ $(BINDIR)/ebtables-restore - cat ebtables.sysv | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__SYSCONFIG__/$(tmp2)/g'> ebtables.sysv_ + cat ebtables.sysv | sed 's/__EXEC_PATH__/$(tmp1)/g' | sed 's/__SYSCONFIG__/$(tmp2)/g' > ebtables.sysv_ install -m 0755 -o root -g root ebtables.sysv_ $(INITDIR)/ebtables cat ebtables-config | sed 's/__SYSCONFIG__/$(tmp1)/g' > ebtables-config_ install -m 0600 -o root -g root ebtables-config_ $(SYSCONFIGDIR)/ebtables-config diff --git a/ebtables-restore b/ebtables-restore index abe049d..7c2ea88 100644 --- a/ebtables-restore +++ b/ebtables-restore @@ -9,6 +9,7 @@ use strict; my $ebtables = "__EXEC_PATH__/ebtables"; my $table = ""; my $rc; +my $child; my $line; # ============================== @@ -34,20 +35,58 @@ sub check_chain { } # ============================== -unless (-x $ebtables) { print "ERROR: $ebtables isn't executable\n"; exit -1; }; +if (-x "__EXEC_PATH__/ebtablesd" && -x "__EXEC_PATH__/ebtablesu") { + `killall ebtablesd 2>/dev/null`; + $child = fork(); + if ($child == 0) { + $rc = `__EXEC_PATH__/ebtablesd`; + if (!($rc eq "")) { + exit -1; + } + exit 0; + } + $ebtables = "__EXEC_PATH__/ebtablesu"; + while (!(-e "__PIPE__")) { + if ((kill 0) < $child) { + exit -1; + } + } +} else { + unless (-x $ebtables) { print "ERROR: $ebtables isn't executable\n"; exit -1; }; +} + $line = 0; while(<>) { $line++; if(m/^#/) { next; }; if(m/^$/) { next; }; + if ($ebtables eq "__EXEC_PATH__/ebtablesu") { + if ((kill 0) < $child) { + exit -1; + } + } if(m/^\*(.*)/) { - if (defined($ENV{'EBTABLES_SAVE_COUNTER'}) && !($ENV{'EBTABLES_SAVE_COUNTER'} eq "yes") && !($table eq "") ) { - $rc = `$ebtables -t $table -Z`; - unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + if (!($table eq "")) { + if (!defined($ENV{'EBTABLES_SAVE_COUNTER'}) || !($ENV{'EBTABLES_SAVE_COUNTER'} eq "yes")) { + $rc = `$ebtables -t $table -Z`; + unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + } + if ($ebtables eq "__EXEC_PATH__/ebtablesu") { + $rc = `$ebtables commit $table`; + $rc = `$ebtables free $table`; + unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + } } $table = $1; - $rc = `$ebtables -t filter --init-table`; - unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + if ($ebtables eq "__EXEC_PATH__/ebtablesu") { + $rc = `$ebtables open $table`; + unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + $rc = `$ebtables -F`; + unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + } else { + $rc = `$ebtables -t filter --init-table`; + unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + } next; } if(m/^\:(.*?)\s(.*)/) { @@ -59,7 +98,21 @@ while(<>) { $rc = `$ebtables -t $table $_`; unless($? == 0) {print "ERROR(line $line): $rc\n"; exit -1}; } -if (defined($ENV{'EBTABLES_SAVE_COUNTER'}) && !($ENV{'EBTABLES_SAVE_COUNTER'} eq "yes") && !($table eq "")) { - $rc = `$ebtables -t $table -Z`; - unless($? == 0) {print "ERROR: '-t $table -Z' failed\n"; exit -1}; + +if (!($table eq "")) { + if (!defined($ENV{'EBTABLES_SAVE_COUNTER'}) || !($ENV{'EBTABLES_SAVE_COUNTER'} eq "yes")) { + $rc = `$ebtables -t $table -Z`; + unless($? == 0) {print "ERROR: '-t $table -Z' failed\n"; exit -1}; + } + if ($ebtables eq "__EXEC_PATH__/ebtablesu") { + $rc = `$ebtables commit $table`; + unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + } +} + +if ($ebtables eq "__EXEC_PATH__/ebtablesu") { + $rc = `$ebtables quit`; + unless($? == 0) {print "ERROR: $rc\n"; exit -1}; + waitpid($child,0); + exit 0; } -- 2.7.4