From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.haj.ipfire.org (localhost [IPv6:::1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4d7qVM3nLrz332m for ; Sat, 15 Nov 2025 10:09:15 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (Client CN "mail01.haj.ipfire.org", Issuer "R12" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4d7qVJ1MZQz332V for ; Sat, 15 Nov 2025 10:09:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4d7qVH6D9Hz2WV; Sat, 15 Nov 2025 10:09:11 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1763201352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=raoTcgPLI8DIR6kX+o9IbNsaMMfmmgokdWlXGY7OwHU=; b=PSLXKxlac498QQFc2MeoPVsPf/rRbpmZ83bWvnlRLKPwik1sB/mnQQADEw4Wp+MbplO8rJ AcLaxOmVU3+OoDBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1763201352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=raoTcgPLI8DIR6kX+o9IbNsaMMfmmgokdWlXGY7OwHU=; b=HJU9LSLy95eITQWd+DlOuRr2+zyrlMN0mK4lkrVA1EEnOUK5s5jsaEbbyUZ+RVjtDheinx duNCVEqrZutR6SGs4O7pteSFOBih/KuKpSMs43xA/q4DprLecBg8lG1wHSWIomrskISsow HQ/y+wj3eA5t+KES3HiUMSf5UeuBQ8qecNVGWsurrWjE3fq4/oG9sVj8VRWsMpnCzDhv1E a5/4LQvyXgY8TJ8foqb7suvJkBq1gS9J2oBK2T9Vhzz5fmL0ntKxrOCNCyG0xOsNxuW/4O ysS/nv8SeRTR30KzhsNAhGu+a2JcNBS/ARJTxWtpl3HLXw0HlfKwSzOcRSUXjw== From: Stefan Schantl To: development@lists.ipfire.org Cc: Stefan Schantl Subject: [PATCH 3/3] lldp.cgi: Show discovered peers in alphabetical order Date: Sat, 15 Nov 2025 11:07:58 +0100 Message-ID: <20251115100758.7039-3-stefan.schantl@ipfire.org> In-Reply-To: <20251115100758.7039-1-stefan.schantl@ipfire.org> References: <20251115100758.7039-1-stefan.schantl@ipfire.org> Precedence: list List-Id: List-Subscribe: , List-Unsubscribe: , List-Post: List-Help: Sender: Mail-Followup-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Schantl --- html/cgi-bin/lldp.cgi | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/html/cgi-bin/lldp.cgi b/html/cgi-bin/lldp.cgi index 194f4ec82..a1b1d4bf9 100644 --- a/html/cgi-bin/lldp.cgi +++ b/html/cgi-bin/lldp.cgi @@ -39,6 +39,9 @@ my @errormessages = (); my %settings = (); &General::readhash("${General::swroot}/lldp/settings", \%settings); +# Hash which will contain any discovered peers. +my %peerhash = (); + # Save on main page if ($cgiparams{"ACTION"} eq $Lang::tr{'save'}) { # Store whether enabled or not @@ -136,6 +139,14 @@ END # Fetch the interface object my $interface = $json->{"lldp"}[0]->{"interface"}; + # Loop through all detected peers and add their sent names as keys + # and their data as values to the peerhash. + foreach my $peer (@{ $interface}) { + my $name = &Header::escape($peer->{"chassis"}[0]->{"name"}[0]->{"value"}); + + $peerhash{$name} = $peer; + } + print < @@ -165,16 +176,17 @@ END END - foreach my $peer (@{ $interface }) { - my $intf = $peer->{"name"}; - my $proto = $peer->{"via"}; + # Sort the detected peers alphabetically and loop over them. + foreach my $peer (sort { $a cmp $b } keys %peerhash) { + my $intf = $peerhash{$peer}{"name"}; + my $proto = $peerhash{$peer}{"via"}; my $name = ""; my $descr = ""; my $port_name = ""; my $vlan_id = ""; # Fetch the chassis - foreach my $chassis (@{ $peer->{"chassis"} }) { + foreach my $chassis (@{ $peerhash{$peer}{"chassis"} }) { $name = &Header::escape( $chassis->{"name"}[0]->{"value"} );; @@ -187,12 +199,12 @@ END } # Fetch the port - foreach my $port (@{ $peer->{"port"} }) { + foreach my $port (@{ $peerhash{$peer}{"port"} }) { $port_name = $port->{"descr"}[0]->{"value"}; } # Fetch the VLAN - foreach my $vlan (@{ $peer->{"vlan"} }) { + foreach my $vlan (@{ $peerhash{$peer}{"vlan"} }) { $vlan_id = $vlan->{"vlan-id"}; } @@ -226,7 +238,7 @@ END } # Show a message if there are no neighbors - unless (scalar @{ $interface }) { + unless (keys %peerhash) { print < -- 2.47.3