Skip to content

Commit

Permalink
SNMP fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed Oct 14, 2024
1 parent 4f3d192 commit d1aa001
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions server.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

typedef struct
{
uint32_t iscsiSsnCmdPDUs; // 1.3.6.1.2.1.142.1.10.2.1.1
uint32_t iscsiInstSsnFailures; // 1.3.6.1.2.1.142.1.1.1.1.10
uint32_t iscsiInstSsnFormatErrors; // 1.3.6.1.2.1.142.1.1.2.1.3
uint32_t iscsiInstSsnDigestErrors; // 1.3.6.1.2.1.142.1.1.2.1.1
uint64_t iscsiSsnCmdPDUs; // 1.3.6.1.2.1.142.1.10.2.1.1
uint64_t iscsiInstSsnFailures; // 1.3.6.1.2.1.142.1.1.1.1.10
uint64_t iscsiInstSsnFormatErrors; // 1.3.6.1.2.1.142.1.1.2.1.3
uint64_t iscsiInstSsnDigestErrors; // 1.3.6.1.2.1.142.1.1.2.1.1
uint64_t iscsiSsnTxDataOctets; // 1.3.6.1.2.1.142.1.10.2.1.3
uint64_t iscsiSsnRxDataOctets; // 1.3.6.1.2.1.142.1.10.2.1.4
uint32_t iscsiTgtLoginAccepts; // 1.3.6.1.2.1.142.1.6.2.1.1
uint32_t iscsiTgtLogoutNormals; // 1.3.6.1.2.1.142.1.6.3.1.1
uint64_t iscsiTgtLoginAccepts; // 1.3.6.1.2.1.142.1.6.2.1.1
uint64_t iscsiTgtLogoutNormals; // 1.3.6.1.2.1.142.1.6.3.1.1
} iscsi_stats_t;

class server
Expand Down
26 changes: 13 additions & 13 deletions snmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@
void init_snmp(snmp **const snmp_, snmp_data **const snmp_data_, io_stats_t *const ios, iscsi_stats_t *const is, std::function<int(void *)> get_percentage_diskspace, void *const gpd_context, int *const cpu_usage, int *const ram_free_kb, std::atomic_bool *const stop, const int port)
{
*snmp_data_ = new snmp_data();
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.2", "iESP" );
(*snmp_data_)->register_oid("1.3.6.1.2.1.1.1.0", "iESP" );
//(*snmp_data_)->register_oid("1.3.6.1.2.1.1.2.0", new snmp_data_type_oid("1.3.6.1.4.1.57850.1"));
(*snmp_data_)->register_oid("1.3.6.1.2.1.1.3.0", new snmp_data_type_running_since());
(*snmp_data_)->register_oid("1.3.6.1.2.1.1.4.0", "Folkert van Heusden <[email protected]>");
(*snmp_data_)->register_oid("1.3.6.1.2.1.1.5.0", "iESP");
(*snmp_data_)->register_oid("1.3.6.1.2.1.1.6.0", "The Netherlands, Europe, Earth");
(*snmp_data_)->register_oid("1.3.6.1.2.1.1.7.0", snmp_integer::si_integer, 254);
(*snmp_data_)->register_oid("1.3.6.1.2.1.1.8.0", snmp_integer::si_integer, 0);
(*snmp_data_)->register_oid("1.3.6.1.2.1.1.8.0", snmp_integer::si_ticks, 0);
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.1.1.10", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiInstSsnFailures));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.2.1.1", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiInstSsnDigestErrors));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.2.1.3", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiInstSsnFormatErrors));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.6.2.1.1", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiTgtLoginAccepts));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.6.3.1.1", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiTgtLogoutNormals));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.1", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter32, &is->iscsiSsnCmdPDUs));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.3", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &is->iscsiSsnTxDataOctets));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.4", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &is->iscsiSsnRxDataOctets));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.11.54", new snmp_data_type_stats_uint32_t(&ios->io_wait));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.2", "iESP" );
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.100.1", snmp_integer::snmp_integer_type::si_integer, 1);
#if defined(ARDUINO)
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.100.2", version_str);
#endif
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.100.3", __DATE__);
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.100.1", snmp_integer::snmp_integer_type::si_integer, 1);

(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.3", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &ios->bytes_read ));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.4", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &ios->bytes_written));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.5", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &ios->n_reads ));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.13.15.1.1.6", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &ios->n_writes ));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.11.54", new snmp_data_type_stats_uint32_t(&ios->io_wait));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.1.1.10", new snmp_data_type_stats_uint32_t(&is->iscsiInstSsnFailures));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.1", new snmp_data_type_stats_uint32_t(&is->iscsiSsnCmdPDUs));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.6.2.1.1", new snmp_data_type_stats_uint32_t(&is->iscsiTgtLoginAccepts));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.6.3.1.1", new snmp_data_type_stats_uint32_t(&is->iscsiTgtLogoutNormals));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.2.1.1", new snmp_data_type_stats_uint32_t(&is->iscsiInstSsnDigestErrors));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.3", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &is->iscsiSsnTxDataOctets));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.10.2.1.4", new snmp_data_type_stats(snmp_integer::snmp_integer_type::si_counter64, &is->iscsiSsnRxDataOctets));
(*snmp_data_)->register_oid("1.3.6.1.2.1.142.1.1.2.1.3", new snmp_data_type_stats_uint32_t(&is->iscsiInstSsnFormatErrors));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.4.11.0", new snmp_data_type_stats_int(ram_free_kb));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.9.1.9.1", new snmp_data_type_stats_int_callback(get_percentage_diskspace, gpd_context));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.11.9.0", new snmp_data_type_stats_int(cpu_usage));
(*snmp_data_)->register_oid("1.3.6.1.4.1.2021.4.11.0", new snmp_data_type_stats_int(ram_free_kb));

*snmp_ = new snmp(*snmp_data_, stop, port);
}
28 changes: 14 additions & 14 deletions snmp/snmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ uint64_t snmp::get_INTEGER(const uint8_t *p, const size_t length)
uint64_t v = 0;

if (length > 8)
DOLOG(logging::ll_error, "SNMP::get_INTEGER", "-", "truncated (%zu bytes)\n", length);
DOLOG(logging::ll_error, "SNMP::get_INTEGER", "-", "truncated (%zu bytes)", length);

for(size_t i=0; i<length; i++) {
v <<= 8;
Expand All @@ -85,7 +85,7 @@ uint64_t snmp::get_INTEGER(const uint8_t *p, const size_t length)
bool snmp::get_type_length(const uint8_t *p, const size_t len, uint8_t *const type, uint8_t *const length)
{
if (len < 2) {
DOLOG(logging::ll_error, "snmp::get_type_length", "-", "length < 2\n");
DOLOG(logging::ll_error, "snmp::get_type_length", "-", "length < 2");
return false;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ bool snmp::get_OID(const uint8_t *p, const size_t length, std::string *const oid
}

if (v) {
DOLOG(logging::ll_error, "snmp::get_OID", "-", "object identifier did not properly terminate\n");
DOLOG(logging::ll_error, "snmp::get_OID", "-", "object identifier did not properly terminate");
return false;
}

Expand All @@ -137,7 +137,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids
return false;

if (pdu_type != 0x02) { // expecting an integer here)
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "ID-type is not integer\n");
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "ID-type is not integer");
return false;
}

Expand All @@ -151,7 +151,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids
return false;

if (pdu_type != 0x02) { // expecting an integer here)
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "error-type is not integer\n");
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "error-type is not integer");
return false;
}

Expand All @@ -166,7 +166,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids
return false;

if (pdu_type != 0x02) { // expecting an integer here)
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "error-index is not integer\n");
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "error-index is not integer");
return false;
}

Expand All @@ -179,7 +179,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids
// varbind list sequence
uint8_t type_vb_list = *p++;
if (type_vb_list != 0x30) {
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "expecting varbind list sequence, got %02x\n", type_vb_list);
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "expecting varbind list sequence, got %02x", type_vb_list);
return false;
}
uint8_t len_vb_list = *p++;
Expand All @@ -191,7 +191,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids
uint8_t seq_length = *pnt++;

if (&pnt[seq_length] > &p[len_vb_list]) {
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "length field out of bounds (PDU)\n");
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "length field out of bounds (PDU)");
return false;
}

Expand All @@ -200,7 +200,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids
pnt += seq_length;
}
else {
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "unexpected/invalid type %02x\n", seq_type);
DOLOG(logging::ll_error, "SNMP::process_PDU", "-", "unexpected/invalid type %02x", seq_type);
return false;
}
}
Expand All @@ -211,7 +211,7 @@ bool snmp::process_PDU(const uint8_t *p, const size_t len, oid_req_t *const oids
bool snmp::process_BER(const uint8_t *p, const size_t len, oid_req_t *const oids_req, const bool is_getnext, const int is_top)
{
if (len < 2) {
DOLOG(logging::ll_error, "SNMP::process_BER", "-", "BER too small\n");
DOLOG(logging::ll_error, "SNMP::process_BER", "-", "BER too small");
return false;
}

Expand All @@ -224,7 +224,7 @@ bool snmp::process_BER(const uint8_t *p, const size_t len, oid_req_t *const oids
uint8_t length = *pnt++;

if (&pnt[length] > &p[len]) {
DOLOG(logging::ll_error, "SNMP::process_BER", "-", "length field out of bounds (BER)\n");
DOLOG(logging::ll_error, "SNMP::process_BER", "-", "length field out of bounds (BER)");
return false;
}

Expand Down Expand Up @@ -293,7 +293,7 @@ bool snmp::process_BER(const uint8_t *p, const size_t len, oid_req_t *const oids
pnt += length;
}
else {
DOLOG(logging::ll_error, "SNMP::process_BER", "-", "invalid type %02x\n", type);
DOLOG(logging::ll_error, "SNMP::process_BER", "-", "invalid type %02x", type);
return false;
}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ void snmp::gen_reply(oid_req_t & oids_req, uint8_t **const packet_out, size_t *c

varbind->add(new snmp_oid(e));

DOLOG(logging::ll_error, "SNMP:process_BER", "-", "requested: %s\n", e.c_str());
DOLOG(logging::ll_debug, "SNMP:process_BER", "-", "requested: %s", e.c_str());

std::optional<snmp_elem *> rc = sd->find_by_oid(e);

Expand All @@ -351,7 +351,7 @@ void snmp::gen_reply(oid_req_t & oids_req, uint8_t **const packet_out, size_t *c
varbind->add(new snmp_null());
}
else {
DOLOG(logging::ll_error, "SNMP::process_BER", "-", "requested %s not found, returning null\n", e.c_str());
DOLOG(logging::ll_info, "SNMP::process_BER", "-", "requested %s not found, returning null", e.c_str());

// FIXME snmp_null?
varbind->add(new snmp_null());
Expand Down
2 changes: 1 addition & 1 deletion snmp/snmp_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ snmp_elem * snmp_data_type_static::get_data()
if (is_string)
return new snmp_octet_string(reinterpret_cast<const uint8_t *>(data.c_str()), data.size());

return new snmp_integer(snmp_integer::si_integer, data_int);
return new snmp_integer(type, data_int);
}

snmp_data_type_stats::snmp_data_type_stats(const snmp_integer::snmp_integer_type type, uint64_t *const counter) :
Expand Down

0 comments on commit d1aa001

Please sign in to comment.