netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ebtables-save: Do string processing in perl instead of shell
@ 2025-09-27 13:00 Johannes Truschnigg
  2025-09-27 13:00 ` [PATCH] Don't shell out for getting current date and table names Johannes Truschnigg
  2025-09-30 10:21 ` ebtables-save: Do string processing in perl instead of shell Florian Westphal
  0 siblings, 2 replies; 6+ messages in thread
From: Johannes Truschnigg @ 2025-09-27 13:00 UTC (permalink / raw)
  To: netfilter-devel


I realize ebtables is kind of in a deep slumber, but maybe you still
want to consider merging this small improvement.

The other day I spent some time debugging a system that relies on
ebtables and will probably keep doing so for the forseeable future
(Proxmox PVE).

Its cluster config sync mechanism spawns ebtables-save in a loop each
few seconds, and the existing code (that superfluously forks to execute
sh, grep, cut, and sed...) annoyingly garbled execsnoop output for me,
so I decided to scratch that particular itch.

Thanks for your your consideration, and for all the good stuff in the
netfilter ecosystem! :)

- Johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Don't shell out for getting current date and table names
  2025-09-27 13:00 ebtables-save: Do string processing in perl instead of shell Johannes Truschnigg
@ 2025-09-27 13:00 ` Johannes Truschnigg
  2025-09-30 10:21 ` ebtables-save: Do string processing in perl instead of shell Florian Westphal
  1 sibling, 0 replies; 6+ messages in thread
From: Johannes Truschnigg @ 2025-09-27 13:00 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Johannes Truschnigg

Also use a sane timestamp format (ISO 8601) in the output.
---
 ebtables-save.in | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/ebtables-save.in b/ebtables-save.in
index 17924a2..4438050 100644
--- a/ebtables-save.in
+++ b/ebtables-save.in
@@ -7,11 +7,14 @@
 # It can be used to store active configuration to /etc/sysconfig/ebtables
 
 use strict;
+use POSIX qw(strftime);
 my $table;
 my $ebtables = "@sbindir@/ebtables";
 my $cnt = "";
-my $version = "1.0";
+my $version = "1.1";
 my $table_name;
+my $modulesfh;
+my @tables;
 
 # ========================================================
 # Process filter table
@@ -50,11 +53,21 @@ sub process_table {
 # ========================================================
 
 unless (-x $ebtables) { exit -1 };
-print "# Generated by ebtables-save v$version (legacy) on " . `date`;
+
+open $modulesfh, '<', '/proc/modules' or die "Failed to open /proc/modules: $!";
+while( my $line = <$modulesfh>) {
+    if($line =~ /^ebtable_([^ ]+)/) {
+        push @tables, $1;
+    }
+}
+close $modulesfh;
+
+printf("# Generated by ebtables-save v$version (legacy) on %s\n", strftime("%a %FT%TZ", gmtime));
 if (defined($ENV{'EBTABLES_SAVE_COUNTER'}) && $ENV{'EBTABLES_SAVE_COUNTER'} eq "yes") {
     $cnt = "--Lc";
 }
-foreach $table_name (split("\n", `grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//`)) {
+
+foreach $table_name (@tables) {
     $table =`$ebtables -t $table_name -L $cnt`;
     unless ($? == 0) { print $table; exit -1 };
     &process_table($table);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: ebtables-save: Do string processing in perl instead of shell
  2025-09-27 13:00 ebtables-save: Do string processing in perl instead of shell Johannes Truschnigg
  2025-09-27 13:00 ` [PATCH] Don't shell out for getting current date and table names Johannes Truschnigg
@ 2025-09-30 10:21 ` Florian Westphal
  2025-09-30 18:06   ` Johannes Truschnigg
  1 sibling, 1 reply; 6+ messages in thread
From: Florian Westphal @ 2025-09-30 10:21 UTC (permalink / raw)
  To: Johannes Truschnigg; +Cc: netfilter-devel

Johannes Truschnigg <johannes@truschnigg.info> wrote:
> want to consider merging this small improvement.

Would you mind resending this with a Signed-off-by tag?
(git commit --amend -s)

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: ebtables-save: Do string processing in perl instead of shell
  2025-09-30 10:21 ` ebtables-save: Do string processing in perl instead of shell Florian Westphal
@ 2025-09-30 18:06   ` Johannes Truschnigg
  2025-09-30 18:06     ` [PATCH v2] Don't shell out for getting current date and table names Johannes Truschnigg
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Truschnigg @ 2025-09-30 18:06 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Johannes Truschnigg


Certainly - I hope this fits the bill! :)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Don't shell out for getting current date and table names
  2025-09-30 18:06   ` Johannes Truschnigg
@ 2025-09-30 18:06     ` Johannes Truschnigg
  2025-09-30 19:13       ` Florian Westphal
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Truschnigg @ 2025-09-30 18:06 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Johannes Truschnigg

Also use a sane timestamp format (ISO 8601) in the output.

Signed-off-by: Johannes Truschnigg <johannes@truschnigg.info>
---
 ebtables-save.in | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/ebtables-save.in b/ebtables-save.in
index 17924a2..4438050 100644
--- a/ebtables-save.in
+++ b/ebtables-save.in
@@ -7,11 +7,14 @@
 # It can be used to store active configuration to /etc/sysconfig/ebtables
 
 use strict;
+use POSIX qw(strftime);
 my $table;
 my $ebtables = "@sbindir@/ebtables";
 my $cnt = "";
-my $version = "1.0";
+my $version = "1.1";
 my $table_name;
+my $modulesfh;
+my @tables;
 
 # ========================================================
 # Process filter table
@@ -50,11 +53,21 @@ sub process_table {
 # ========================================================
 
 unless (-x $ebtables) { exit -1 };
-print "# Generated by ebtables-save v$version (legacy) on " . `date`;
+
+open $modulesfh, '<', '/proc/modules' or die "Failed to open /proc/modules: $!";
+while( my $line = <$modulesfh>) {
+    if($line =~ /^ebtable_([^ ]+)/) {
+        push @tables, $1;
+    }
+}
+close $modulesfh;
+
+printf("# Generated by ebtables-save v$version (legacy) on %s\n", strftime("%a %FT%TZ", gmtime));
 if (defined($ENV{'EBTABLES_SAVE_COUNTER'}) && $ENV{'EBTABLES_SAVE_COUNTER'} eq "yes") {
     $cnt = "--Lc";
 }
-foreach $table_name (split("\n", `grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//`)) {
+
+foreach $table_name (@tables) {
     $table =`$ebtables -t $table_name -L $cnt`;
     unless ($? == 0) { print $table; exit -1 };
     &process_table($table);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] Don't shell out for getting current date and table names
  2025-09-30 18:06     ` [PATCH v2] Don't shell out for getting current date and table names Johannes Truschnigg
@ 2025-09-30 19:13       ` Florian Westphal
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2025-09-30 19:13 UTC (permalink / raw)
  To: Johannes Truschnigg; +Cc: netfilter-devel

Johannes Truschnigg <johannes@truschnigg.info> wrote:
> Also use a sane timestamp format (ISO 8601) in the output.

Applied, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-30 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-27 13:00 ebtables-save: Do string processing in perl instead of shell Johannes Truschnigg
2025-09-27 13:00 ` [PATCH] Don't shell out for getting current date and table names Johannes Truschnigg
2025-09-30 10:21 ` ebtables-save: Do string processing in perl instead of shell Florian Westphal
2025-09-30 18:06   ` Johannes Truschnigg
2025-09-30 18:06     ` [PATCH v2] Don't shell out for getting current date and table names Johannes Truschnigg
2025-09-30 19:13       ` Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).