Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DOCSIS-ConfigFile CPAN distribution.

Report information
The Basics
Id: 72511
Status: resolved
Priority: 0/
Queue: DOCSIS-ConfigFile

People
Owner: Nobody in particular
Requestors: velladecin [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.61
Fixed in: (no value)



Subject: ObjectId + MTA hashing
Hi Jan, Hope you're having a great Friday! There is couple of things that could be added to DOCSIS::ConfigFile. Please use those at your discretion/convenience. In our MTA configs we use lines like SnmpMibObject snmpTargetAddrTDomain.'.' ObjectID .1.3.6.1.6.1.1 ; which are not provided for by the existing module. Patches (encode|decode).patch fix that Also the MTA config needs 'pktcMtaDevProvConfigHash' which is a md5, or sha1 hash of the config before this line is added. As this, according to spec, is only needed when 'When the MTA SNMP Enrollment mechanism is not in use...' this can be achieved by adding a second parameter to DOCSIS::ConfigFile->encode ([], 'md5|sh1'). If second parameter is not added then the method behaves as before. Patch configFile.patch fixes that. I have done some limited testing and all seems ok, however, shall i find some discrepancies i will let you know ASAP. Have a great w'end v.v.
Subject: encode.patch
--- /usr/lib/perl5/vendor_perl/5.8.8/DOCSIS/ConfigFile/Encode.pm 2011-10-04 06:54:16.000000000 +1100 +++ Encode.pm 2011-11-14 17:40:31.000000000 +1100 @@ -53,6 +53,7 @@ INTEGER => [ 0x02, \&int ], STRING => [ 0x04, \&string ], NULLOBJ => [ 0x05, sub {} ], + OBJECTID => [ 0x06, \&objectid ], IPADDRESS => [ 0x40, \&ip ], COUNTER => [ 0x41, \&uint ], UNSIGNED => [ 0x42, \&uint ], @@ -351,6 +352,20 @@ confess "ether({ value => $string }) is invalid"; } +=head2 objectid + +Encodes MIB number as value of C<OBJECTID> +can be in format: 1.2.3.4, .1.2.3.4 + +=cut + +sub objectid +{ + my $oid = _test_value (objectid => $_[0], qr{^\.?\d+(\.\d+)+$}); + $oid =~ s/^\.//; + return _snmp_oid ($oid); +} + =head2 string Returns a list of bytes representing the C<$str>. Will use
Subject: configFile.patch
--- /usr/lib/perl5/vendor_perl/5.8.8/DOCSIS/ConfigFile.pm 2011-10-04 06:58:40.000000000 +1100 +++ ConfigFile.pm 2011-11-14 17:29:12.000000000 +1100 @@ -87,6 +87,7 @@ use Carp qw/ carp confess /; use Digest::MD5; use Digest::HMAC_MD5; +use Digest::SHA1 qw(sha1_hex); use DOCSIS::ConfigFile::Syminfo; use DOCSIS::ConfigFile::Decode; use DOCSIS::ConfigFile::Encode; @@ -296,21 +297,56 @@ example input. For other structures, see the table generated by L<DOCSIS::ConfigFile::Syminfo/dump_symbol_tree>. +When enconding MTA config files another arugment is accepted: + + $binary_str = $self->encode([ { ... }, ... ], 'md5|sha1'); + +As 'pktcMtaDevProvConfigHash' does not need to be included in the config at all +times this param is optional. Only two variants are accpted - MD5, or SHA1 +The algorithm will then be used to define value for 'pktcMtaDevProvConfigHash' +and this line will be added just above 'MtaConfigDelimiter' closing tag resulting in + + MtaConfigDelimiter 1; + ... + SnmpMibObject enterprises.4491.2.2.1.1.2.7.0 HexString 0x1a2b3c4d5e6f... ; + MtaConfigDelimiter 255; + =cut sub encode { my $self = shift; my $config = shift || '__undefined_input__'; + my $algo = shift; if(ref $config ne 'ARRAY') { confess 'Usage: $self->encode( ArrayRef[HashRef] )'; } + if ($algo and $algo !~ /^(?:md5|sha1)$/i) { + confess "Usage: $self->encode( ArrayRef[HashRef], 'md5|sha1' )"; + } + $algo = lc $algo if $algo; + $self->{'cmts_mic'} = {}; $self->{'binstring'} = $self->_encode_loop($config) || q(); if(grep { $_->{'name'} eq 'MtaConfigDelimiter' } @$config) { $self->{'_MtaConfigDelimiter'} = 1; # for internal usage + + if ($self->{binstring} and $algo) + { + my $hash = $algo eq 'md5' + ? md5_hex $self->{binstring} + : sha1_hex $self->{binstring}; + + if ($hash) + { + splice @$config, $#{$config}, 0, + { name => 'SnmpMibObject', value => { oid => '1.3.6.1.4.1.4491.2.2.1.1.2.7.0', type => 'STRING', value => "0x${hash}" }}; + + $self->{binstring} = $self->_encode_loop ($config) || q(); + } + } } else { $self->{'_DefaultConfigDelimiter'} = 1; # for internal usage
Subject: decode.patch
--- /usr/lib/perl5/vendor_perl/5.8.8/DOCSIS/ConfigFile/Decode.pm 2011-10-04 06:54:16.000000000 +1100 +++ Decode.pm 2011-11-14 17:44:41.000000000 +1100 @@ -57,6 +57,7 @@ 0x02 => [ 'INTEGER', \&int ], 0x04 => [ 'STRING', \&string, ], 0x05 => [ 'NULLOBJ', sub {} ], + 0x06 => [ 'OBJECTID', \&objectid, ], 0x40 => [ 'IPADDRESS', \&ip ], 0x41 => [ 'COUNTER', \&uint ], 0x42 => [ 'UNSIGNED', \&uint ], @@ -327,6 +328,17 @@ return join '', unpack 'H2' x $length, $bin; } +=head2 objectid + +Will unpack input string of OID format: 1.2.3.4.5 + +=cut + +sub objectid +{ + return _snmp_oid (\$_[0], length $_[0]); +} + =head2 string Returns human-readable string, where special characters are "uri encoded".
Would you mind forking me at github and send me a pull request? https://github.com/jhthorsen/docsis-configfile
New version uploaded to cpan: DOCSIS-ConfigFile-0.63. I wish I had some unittests as well, but I'm applying this patch since the issue is getting too old.