… | |
… | |
20 | |
20 | |
21 | There are currently the following limitations when using this module: |
21 | There are currently the following limitations when using this module: |
22 | |
22 | |
23 | =over 4 |
23 | =over 4 |
24 | |
24 | |
|
|
25 | =item overriding internal functions might cause the module to |
|
|
26 | malfunction with future versions of Net::SNMP |
|
|
27 | |
25 | =item only leading dots for oids are supported |
28 | =item only leading dots for oids are supported |
26 | |
|
|
27 | =item error handling is currently broken (but parse errors will be detected) |
|
|
28 | |
29 | |
29 | =item error messages will be simpler/different |
30 | =item error messages will be simpler/different |
30 | |
31 | |
31 | =item oid components are limited to unsigned 32 bit integers |
|
|
32 | |
|
|
33 | =item translation will be ignored (all values will be delivered "raw") |
32 | =item translation will be ignored (all values will be delivered "raw") |
34 | |
|
|
35 | =item a 64 bit perl is required |
|
|
36 | |
33 | |
37 | =item a moderately modern (>= C99) C compiler is required |
34 | =item a moderately modern (>= C99) C compiler is required |
38 | |
35 | |
39 | =item only tested with 5.10 |
36 | =item only tested with 5.10, no intentions to port to older perls |
40 | |
37 | |
41 | =item duplicate OIDs are not supported |
38 | =item duplicate OIDs are not supported |
42 | |
39 | |
43 | =item REPORT PDUs are not supported |
40 | =item REPORT PDUs are not supported |
44 | |
41 | |
… | |
… | |
51 | use strict qw(vars subs); |
48 | use strict qw(vars subs); |
52 | no warnings; |
49 | no warnings; |
53 | |
50 | |
54 | use Guard; |
51 | use Guard; |
55 | |
52 | |
|
|
53 | use Net::SNMP (); |
56 | use Net::SNMP::PDU (); |
54 | use Net::SNMP::PDU (); |
57 | use Net::SNMP::Message (); |
55 | use Net::SNMP::Message (); |
58 | use Net::SNMP::MessageProcessing (); |
56 | use Net::SNMP::MessageProcessing (); |
59 | |
57 | |
60 | our $VERSION; |
58 | our $VERSION; |
61 | our $old_prepare; |
59 | our $old_prepare; |
62 | |
60 | |
63 | BEGIN { |
61 | BEGIN { |
64 | $VERSION = '0.01'; |
62 | $VERSION = '0.02'; |
65 | |
63 | |
66 | $old_prepare = \&Net::SNMP::MessageProcessing::prepare_data_elements; |
64 | $old_prepare = \&Net::SNMP::MessageProcessing::prepare_data_elements; |
67 | |
65 | |
68 | # this overrides many methods inside |
66 | # this overrides many methods inside |
69 | require XSLoader; |
67 | require XSLoader; |
… | |
… | |
76 | set_msg $msg, $msg->{_buffer}; |
74 | set_msg $msg, $msg->{_buffer}; |
77 | scope_guard \&clr_msg; |
75 | scope_guard \&clr_msg; |
78 | &$old_prepare |
76 | &$old_prepare |
79 | } |
77 | } |
80 | |
78 | |
|
|
79 | package Net::SNMP::Message; |
|
|
80 | |
|
|
81 | Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
|
|
82 | Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
|
|
83 | Net::SNMP::XS::set_type NULL , \&_process_null; |
|
|
84 | Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier; |
|
|
85 | Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence; |
|
|
86 | Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress; |
|
|
87 | Net::SNMP::XS::set_type COUNTER , \&_process_counter; |
|
|
88 | Net::SNMP::XS::set_type GAUGE , \&_process_gauge; |
|
|
89 | Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks; |
|
|
90 | Net::SNMP::XS::set_type OPAQUE , \&_process_opaque; |
|
|
91 | Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64; |
|
|
92 | Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject; |
|
|
93 | Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance; |
|
|
94 | Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview; |
|
|
95 | Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request; |
|
|
96 | Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request; |
|
|
97 | Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response; |
|
|
98 | Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request; |
|
|
99 | Net::SNMP::XS::set_type TRAP , \&_process_trap; |
|
|
100 | Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request; |
|
|
101 | Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request; |
|
|
102 | Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap; |
|
|
103 | Net::SNMP::XS::set_type REPORT , \&_process_report; |
|
|
104 | |
|
|
105 | package Net::SNMP::PDU; |
|
|
106 | |
|
|
107 | # var_bind_list hardcodes oid_lext_sort. *sigh* |
|
|
108 | # we copy it 1:1, except for using oid_lex_sort. |
|
|
109 | |
|
|
110 | sub var_bind_list |
81 | { |
111 | { |
82 | package Net::SNMP::Message; |
112 | my ($this, $vbl, $types) = @_; |
83 | |
113 | |
84 | Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
114 | return if defined($this->{_error}); |
85 | Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
115 | |
86 | Net::SNMP::XS::set_type NULL , \&_process_null; |
116 | if (@_ > 1) { |
87 | Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier; |
117 | # The VarBindList HASH is being updated from an external |
88 | Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence; |
118 | # source. We need to update the VarBind names ARRAY to |
89 | Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress; |
119 | # correspond to the new keys of the HASH. If the updated |
90 | Net::SNMP::XS::set_type COUNTER , \&_process_counter; |
120 | # information is valid, we will use lexicographical ordering |
91 | Net::SNMP::XS::set_type GAUGE , \&_process_gauge; |
121 | # for the ARRAY entries since we do not have a PDU to use |
92 | Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks; |
122 | # to determine the ordering. The ASN.1 types HASH is also |
93 | Net::SNMP::XS::set_type OPAQUE , \&_process_opaque; |
123 | # updated here if a cooresponding HASH is passed. We double |
94 | Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64; |
124 | # check the mapping by populating the hash with the keys of |
95 | Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject; |
125 | # the VarBindList HASH. |
96 | Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance; |
126 | |
97 | Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview; |
127 | if (!defined($vbl) || (ref($vbl) ne 'HASH')) { |
98 | Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request; |
128 | |
99 | Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request; |
129 | $this->{_var_bind_list} = undef; |
100 | Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response; |
130 | $this->{_var_bind_names} = []; |
101 | Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request; |
131 | $this->{_var_bind_types} = undef; |
102 | Net::SNMP::XS::set_type TRAP , \&_process_trap; |
132 | |
103 | Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request; |
133 | } else { |
104 | Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request; |
134 | |
105 | Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap; |
135 | $this->{_var_bind_list} = $vbl; |
106 | Net::SNMP::XS::set_type REPORT , \&_process_report; |
136 | |
|
|
137 | @{$this->{_var_bind_names}} = Net::SNMP::oid_lex_sort keys %$vbl; |
|
|
138 | |
|
|
139 | if (!defined($types) || (ref($types) ne 'HASH')) { |
|
|
140 | $types = {}; |
|
|
141 | } |
|
|
142 | |
|
|
143 | map { |
|
|
144 | $this->{_var_bind_types}->{$_} = |
|
|
145 | exists($types->{$_}) ? $types->{$_} : undef; |
|
|
146 | } keys(%{$vbl}); |
|
|
147 | |
|
|
148 | } |
|
|
149 | |
|
|
150 | } |
|
|
151 | |
|
|
152 | $this->{_var_bind_list}; |
107 | } |
153 | } |
108 | |
154 | |
109 | 1; |
155 | 1; |
110 | |
156 | |
111 | =head1 AUTHOR |
157 | =head1 AUTHOR |