| 1 | package SNMP::Info::CiscoAuthFramework; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Exporter; | ||
| 6 | use SNMP::Info; | ||
| 7 | |||
| 8 | @SNMP::Info::CiscoAuthFramework::ISA = qw/SNMP::Info Exporter/; | ||
| 9 | @SNMP::Info::CiscoAuthFramework::EXPORT_OK = qw//; | ||
| 10 | |||
| 11 | our ($VERSION, %MIBS, %FUNCS, %GLOBALS, %MUNGE); | ||
| 12 | |||
| 13 | $VERSION = '3.985003'; | ||
| 14 | |||
| 15 | %MIBS = ( | ||
| 16 | 'CISCO-AUTH-FRAMEWORK-MIB' => 'ciscoAuthFrameworkMIB', | ||
| 17 | ); | ||
| 18 | |||
| 19 | %GLOBALS = (); | ||
| 20 | |||
| 21 | %FUNCS = ( | ||
| 22 | # CISCO-AUTH-FRAMEWORK-MIB::cafSessionTable | ||
| 23 | 'caf_session_auth_vlan' => 'cafSessionAuthVlan', | ||
| 24 | ); | ||
| 25 | |||
| 26 | %MUNGE = (); | ||
| 27 | |||
| 28 | sub i_auth_vlan_membership { | ||
| 29 | my $auth = shift; | ||
| 30 | |||
| 31 | my $sessions = $auth->caf_session_auth_vlan() || {}; | ||
| 32 | |||
| 33 | # Table methods in SNMP::Info normally return a hash reference. | ||
| 34 | # Be defensive in case the underlying implementation changes or | ||
| 35 | # returns an unexpected value. | ||
| 36 | return {} unless ref $sessions eq 'HASH'; | ||
| 37 | |||
| 38 | my %seen; | ||
| 39 | my %membership; | ||
| 40 | |||
| 41 | foreach my $index (keys %{$sessions}) { | ||
| 42 | next unless defined $index; | ||
| 43 | |||
| 44 | # cafSessionTable is indexed by: | ||
| 45 | # ifIndex + IMPLIED cafSessionId | ||
| 46 | # | ||
| 47 | # SNMP::Info represents the complete SNMP table index as a | ||
| 48 | # dot-separated string. We only need the leading ifIndex here. | ||
| 49 | my ($ifindex) = split /\./, $index, 2; | ||
| 50 | |||
| 51 | my $vlan = $sessions->{$index}; | ||
| 52 | |||
| 53 | next unless defined $ifindex && $ifindex =~ /^\d+$/; | ||
| 54 | next unless defined $vlan && $vlan =~ /^\d+$/; | ||
| 55 | |||
| 56 | # cafSessionAuthVlan uses VlanIndexOrZero. | ||
| 57 | # A value of 0 means that no authorized VLAN was applied. | ||
| 58 | next if $vlan == 0; | ||
| 59 | |||
| 60 | # Multiple authentication sessions may exist on the same | ||
| 61 | # interface and several sessions may use the same VLAN. | ||
| 62 | # Store the data as a set first to avoid duplicates. | ||
| 63 | $seen{$ifindex}{$vlan} = 1; | ||
| 64 | } | ||
| 65 | |||
| 66 | foreach my $ifindex (keys %seen) { | ||
| 67 | $membership{$ifindex} = [ | ||
| 68 | sort { $a <=> $b } keys %{ $seen{$ifindex} } | ||
| 69 | ]; | ||
| 70 | } | ||
| 71 | |||
| 72 | return \%membership; | ||
| 73 | } | ||
| 74 | |||
| 75 | 1; | ||
| 76 | |||
| 77 | __END__ |