Skip to content

Commit

Permalink
Rewrote part of H3C's NasPortToIfIndex subroutine to fix behaviour fo… (
Browse files Browse the repository at this point in the history
#8062)

* Reworte part of H3C's NasPortToIfIndex subroutine to fix behaviour for stacked Comware v7 switches

* Fixed function dependency
  • Loading branch information
bmp96 authored Nov 26, 2024
1 parent 316b9a7 commit 42bbb2e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/pf/Switch/H3C/Comware_v7.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,58 @@ This module is currently only a placeholder, see L<pf::Switch::H3C>.
use strict;
use warnings;

use POSIX;

use base ('pf::Switch::H3C::Comware_v5');


sub description { 'Comware v7' }

=head1 SUBROUTINES
=over
=item NasPortToIfIndex
Translate RADIUS NAS-Port into switch's ifIndex.
=cut

sub NasPortToIfIndex {
my ($self, $nas_port) = @_;
my $logger = $self->logger;

# 4096 NAS-Port slots are reserved per physical ports,
# I'm assuming that each client will get a +1 so I translate all of them into the same ifIndex
# Also there's a large offset (16781312), 4096 * (4096 + 1)
# VLAN ID are last 3 nibbles ────────────────┐
# Port is next 2 nibbles ────────────┐ │
# Subslot is next 1 nibble ──────────┐ │ │
# Slot is next 2 nibbles ───────┐ │ │ │
# Example: 33575422 --to hex--> (02)(0)(05)(1FE)
my $nas_port_no_vlan = floor($nas_port / $THREECOM::NAS_PORTS_PER_PORT_RANGE);
my $slot = floor($nas_port_no_vlan / $THREECOM::NAS_PORTS_PER_PORT_RANGE);
my $port = $nas_port_no_vlan - $THREECOM::NAS_PORTS_PER_PORT_RANGE * $slot;
my $ifIndex = $port + $THREECOM::IFINDEX_OFFSET_PER_SLOT * ($slot - 1);
if ($ifIndex > 0) {

# TODO we should think about caching or pre-computation here
$ifIndex = $self->getIfIndexForThisDot1dBasePort($ifIndex);

# return if defined and an int
return $ifIndex if (defined($ifIndex) && $ifIndex =~ /^\d+$/);
}

# error reporting
$logger->warn(
"Unknown NAS-Port format. ifIndex translation could have failed. "
. "VLAN re-assignment and switch/port accounting will be affected."
);
return $nas_port;
}

=back
=head1 AUTHOR
Inverse inc. <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions lib/pf/Switch/constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ Used for NAS-Port to ifIndex translation

Readonly::Scalar our $NAS_PORT_OFFSET => 16781312;
Readonly::Scalar our $NAS_PORTS_PER_PORT_RANGE => 4096;
Readonly::Scalar our $IFINDEX_OFFSET_PER_SLOT => 65;

=head1 BROCADE
Expand Down

0 comments on commit 42bbb2e

Please sign in to comment.