I am humble in your presence and ask for forgiveness for writing such poor code. I humbly request 5 minutes of your meditation time.
I am currently trying to decode OSPF LSA's that I am retrieving from the OSPF MIB (ospfLsdbAdvertisement) via SNMP.
I have two networks running OSPF to test against and appear to have sucesfully managed to decode the LSA 20-byte header and Network LSA's using unpack.
(I must add that I am fairly new to unpack/pack).
However, I am experiencing some very odd behaviour and wondered if you could give me any hints or tips.
Here is the 20-byte OSPF LSA Header according to the RFC:
# 0 1 2 3 # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 +1 # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ++-+ # | LS age | Options | LS type + | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ++-+ # | Link State ID + | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ++-+ # | Advertising Router + | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ++-+ # | LS sequence number + | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ++-+ # | LS checksum | length + | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ++-+
Here is the function I am using to decode the header:**
** Note that it does do some enumeration and calls a couple of other functions that aren't shown.
sub decode_header { my $buff = shift; my %lsa; print dump_hex(substr($buff,0,20)); ($lsa{age}, $lsa{options}, $lsa{type}, $lsa{lsid}, $lsa{advRouter}, $lsa{seqNo}, $lsa{checksum}, $lsa{length}) = unpack('nCCNNNnn',$buff); $lsa{lsid} = N_to_dottedQuad($lsa{lsid}); $lsa{advRouter} = N_to_dottedQuad($lsa{advRouter}); $lsa{type} = $OSPF{LSTYPE}{$lsa{type}}; $lsa{options} = decode_lsa_options($lsa{options}); return \%lsa; }
If the results of the function are Data::Dumped I get something like the following:
Dump: [000] 00 05 22 01 AC 32 00 02 AC 32 00 02 80 20 FF 99 [016] 05 90 00 48 $VAR1 = { 'seqNo' => '2149646233', 'length' => 72, 'checksum' => 1424, 'advRouter' => '172.50.0.2', 'options' => '*|-|DC|-|-|-|E|*', 'lsid' => '172.50.0.2', 'type' => 'Router-LSA', 'age' => 5 };
This looks okay, some sniffing with Ethereal and checking of the standard mib variables have shown that this LSA appears to contain the correct checksum, advertising router and lsid etc. Oddly though, age never seems to be right for some reason...
However, this is where things start to get a little strange. A couple of our routers are using IP addresses with 10 as one of the octets. If the decoder comes across such a value it converts the 10 into 32 for some reason. Other octets within the IP address are represented correctly.
Consider the following example:-
[000] 00 00 22 02 20 01 01 02 20 01 FE 01 80 00 00 10 [016] 41 A5 00 20 $VAR1 = { 'seqNo' => '2147483664', 'length' => 32, 'checksum' => 16805, 'advRouter' => '32.1.254.1', 'options' => '*|-|DC|-|-|-|E|*', 'lsid' => '32.1.1.2', 'type' => 'Network-LSA', 'age' => '0' };
Both the LSID and advertising router should have 10 as their first octet. I've tried a number of things:
In light of the tests I presume it must be something with my unpack of the packet. If anyone can make any suggestions or give any advice that would be very much appreciated.
Regards, MattIn reply to Strange results from unpack when trying to decode OSPF LSA's from the OSPF MIB by mattedug
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |