]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
connections.cgi: Parse conntrack table without loading it all first
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Apr 2024 11:43:49 +0000 (13:43 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Aug 2024 12:26:53 +0000 (14:26 +0200)
We used to load the entire table into memory which is very unnecessary
because we can parse it one line at a time.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/connections.cgi

index 97761eb20c3e0a3813ccb033d9ec93086e22eee9..ad7c69beba44c32b57aa127aaa5e9d2a0478f9a2 100644 (file)
@@ -44,11 +44,6 @@ my @colour=();
 my %netsettings=();
 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
 
-# Read and sort the connection tracking table
-open(CONNTRACK, "/usr/local/bin/getconntracktable | sort -k 5,5 --numeric-sort --reverse |") or die "Unable to read conntrack table";
-my @conntrack = <CONNTRACK>;
-close(CONNTRACK);
-
 # Collect data for the @network array.
 
 # Add Firewall Localhost 127.0.0.1
@@ -363,7 +358,11 @@ print <<END;
                </tr>
 END
 
-foreach my $line (@conntrack) {
+# Read and sort the connection tracking table
+open(CONNTRACK, "/usr/local/bin/getconntracktable | sort -k 5,5 --numeric-sort --reverse |")
+       or die "Unable to read conntrack table";
+
+foreach my $line (<CONNTRACK>) {
        my @conn = split(' ', $line);
 
        # The first bit is the l3 protocol.
@@ -572,6 +571,8 @@ foreach my $line (@conntrack) {
 END
 }
 
+close(CONNTRACK);
+
 # Close the main table.
 print "</table>";