… | |
… | |
8 | |
8 | |
9 | my $ber = ber_decode $buf, $Convert::BER::XS::SNMP_PROFILE |
9 | my $ber = ber_decode $buf, $Convert::BER::XS::SNMP_PROFILE |
10 | or die "unable to decode SNMP message"; |
10 | or die "unable to decode SNMP message"; |
11 | |
11 | |
12 | # The above results in a data structure consisting of |
12 | # The above results in a data structure consisting of |
13 | # (class, tag, # constructed, data) |
13 | # (class, tag, flags, data) |
14 | # tuples. Below is such a message, SNMPv1 trap |
14 | # tuples. Below is such a message, SNMPv1 trap |
15 | # with a Cisco mac change notification. |
15 | # with a Cisco mac change notification. |
16 | # Did you know that Cisco is in the news almost |
16 | # Did you know that Cisco is in the news almost |
17 | # every week because of some backdoor password |
17 | # every week because of some backdoor password |
18 | # or other extremely stupid security bug? |
18 | # or other extremely stupid security bug? |
… | |
… | |
134 | |
134 | |
135 | Constants only relevant to SNMP. These are the tag values used by SNMP in |
135 | Constants only relevant to SNMP. These are the tag values used by SNMP in |
136 | the C<ASN_APPLICATION> namespace and have the exact numerical value as in |
136 | the C<ASN_APPLICATION> namespace and have the exact numerical value as in |
137 | BER/RFC 2578. |
137 | BER/RFC 2578. |
138 | |
138 | |
139 | SNMP_IPADDRESS SNMP_COUNTER32 SNMP_UNSIGNED32 SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64 |
139 | SNMP_IPADDRESS SNMP_COUNTER32 SNMP_UNSIGNED32 SNMP_GAUGE32 |
|
|
140 | SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64 |
140 | |
141 | |
141 | =item C<:decode> |
142 | =item C<:decode> |
142 | |
143 | |
143 | C<ber_decode> and the match helper functions: |
144 | C<ber_decode> and the match helper functions: |
144 | |
145 | |
… | |
… | |
303 | a ease-of-use exception, they usually also accept C<undef> instead of a |
304 | a ease-of-use exception, they usually also accept C<undef> instead of a |
304 | tuple reference, in which case they silently fail to match. |
305 | tuple reference, in which case they silently fail to match. |
305 | |
306 | |
306 | =over |
307 | =over |
307 | |
308 | |
308 | =item $bool = ber_is $tuple, $class, $tag, $constructed, $data |
309 | =item $bool = ber_is $tuple, $class, $tag, $flags, $data |
309 | |
310 | |
310 | This takes a BER C<$tuple> and matches its elements against the provided |
311 | This takes a BER C<$tuple> and matches its elements against the provided |
311 | values, all of which are optional - values that are either missing or |
312 | values, all of which are optional - values that are either missing or |
312 | C<undef> will be ignored, the others will be matched exactly (e.g. as if |
313 | C<undef> will be ignored, the others will be matched exactly (e.g. as if |
313 | you used C<==> or C<eq> (for C<$data>)). |
314 | you used C<==> or C<eq> (for C<$data>)). |
… | |
… | |
393 | use Exporter qw(import); |
394 | use Exporter qw(import); |
394 | |
395 | |
395 | our $VERSION; |
396 | our $VERSION; |
396 | |
397 | |
397 | BEGIN { |
398 | BEGIN { |
398 | $VERSION = 0.8; |
399 | $VERSION = 0.9; |
399 | XSLoader::load __PACKAGE__, $VERSION; |
400 | XSLoader::load __PACKAGE__, $VERSION; |
400 | } |
401 | } |
401 | |
402 | |
402 | our %EXPORT_TAGS = ( |
403 | our %EXPORT_TAGS = ( |
403 | const_index => [qw( |
404 | const_index => [qw( |
… | |
… | |
417 | BER_TYPE_BYTES BER_TYPE_UTF8 BER_TYPE_UCS2 BER_TYPE_UCS4 BER_TYPE_INT |
418 | BER_TYPE_BYTES BER_TYPE_UTF8 BER_TYPE_UCS2 BER_TYPE_UCS4 BER_TYPE_INT |
418 | BER_TYPE_OID BER_TYPE_RELOID BER_TYPE_NULL BER_TYPE_BOOL BER_TYPE_REAL |
419 | BER_TYPE_OID BER_TYPE_RELOID BER_TYPE_NULL BER_TYPE_BOOL BER_TYPE_REAL |
419 | BER_TYPE_IPADDRESS BER_TYPE_CROAK |
420 | BER_TYPE_IPADDRESS BER_TYPE_CROAK |
420 | )], |
421 | )], |
421 | const_snmp => [qw( |
422 | const_snmp => [qw( |
422 | SNMP_IPADDRESS SNMP_COUNTER32 SNMP_UNSIGNED32 SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64 |
423 | SNMP_IPADDRESS SNMP_COUNTER32 SNMP_GAUGE32 SNMP_UNSIGNED32 |
|
|
424 | SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64 |
423 | )], |
425 | )], |
424 | decode => [qw( |
426 | decode => [qw( |
425 | ber_decode |
427 | ber_decode |
426 | ber_is ber_is_seq ber_is_int ber_is_oid |
428 | ber_is ber_is_seq ber_is_int ber_is_oid |
427 | )], |
429 | )], |
… | |
… | |
582 | C<BER_TYPE_BYTES>. When you don't want that but instead prefer a hard |
584 | C<BER_TYPE_BYTES>. When you don't want that but instead prefer a hard |
583 | error for some types, then C<BER_TYPE_CROAK> is for you. |
585 | error for some types, then C<BER_TYPE_CROAK> is for you. |
584 | |
586 | |
585 | =back |
587 | =back |
586 | |
588 | |
|
|
589 | =head2 Example Profile |
|
|
590 | |
|
|
591 | The following creates a profile suitable for SNMP - it's exactly identical |
|
|
592 | to the C<$Convert::BER::XS::SNMP_PROFILE> profile. |
|
|
593 | |
|
|
594 | our $SNMP_PROFILE = new Convert::BER::XS::Profile; |
|
|
595 | |
|
|
596 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
|
|
597 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
|
|
598 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
|
|
599 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
|
|
600 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); |
|
|
601 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
|
|
602 | |
587 | =cut |
603 | =cut |
588 | |
604 | |
589 | our $DEFAULT_PROFILE = new Convert::BER::XS::Profile; |
605 | our $DEFAULT_PROFILE = new Convert::BER::XS::Profile; |
590 | our $SNMP_PROFILE = new Convert::BER::XS::Profile; |
606 | |
|
|
607 | $DEFAULT_PROFILE->_set_default; |
591 | |
608 | |
592 | # additional SNMP application types |
609 | # additional SNMP application types |
|
|
610 | our $SNMP_PROFILE = new Convert::BER::XS::Profile; |
|
|
611 | |
593 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
612 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
594 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
613 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
595 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
614 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
596 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
615 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
597 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); |
616 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); |
598 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
617 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
599 | |
618 | |
600 | $DEFAULT_PROFILE->_set_default; |
|
|
601 | |
|
|
602 | 1; |
619 | 1; |
603 | |
620 | |
604 | =head2 LIMITATIONS/NOTES |
621 | =head2 LIMITATIONS/NOTES |
605 | |
622 | |
606 | This module can only en-/decode 64 bit signed and unsigned integers, and |
623 | This module can only en-/decode 64 bit signed and unsigned integers, and |
… | |
… | |
619 | Constructed strings are decoded just fine, but there should be a way to |
636 | Constructed strings are decoded just fine, but there should be a way to |
620 | join them for convenience. |
637 | join them for convenience. |
621 | |
638 | |
622 | REAL values are not supported and will currently croak. |
639 | REAL values are not supported and will currently croak. |
623 | |
640 | |
|
|
641 | The encoder and decoder tend to accept more formats than should be |
|
|
642 | strictly supported. |
|
|
643 | |
624 | This module has undergone little to no testing so far. |
644 | This module has undergone little to no testing so far. |
625 | |
645 | |
626 | =head2 ITHREADS SUPPORT |
646 | =head2 ITHREADS SUPPORT |
627 | |
647 | |
628 | This module is unlikely to work when the (officially discouraged) ithreads |
648 | This module is unlikely to work when the (officially discouraged) ithreads |