Skip to content

Commit

Permalink
Added SNMP_MSG_REPORT support (#8766)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Oct 25, 2024
1 parent 9cf8d56 commit 42a6d07
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 83 deletions.
8 changes: 4 additions & 4 deletions include/SNMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SNMP {
#endif
u_int8_t getbulk_max_num_repetitions;

void send_snmp_request(char *agent_host, u_int version, char *community,
bool send_snmp_request(char *agent_host, u_int version, char *community,
char *level, char *username, char *auth_protocol,
char *auth_passphrase, char *privacy_protocol,
char *privacy_passphrase, snmp_pdu_primitive pduType,
Expand All @@ -70,13 +70,13 @@ class SNMP {

#ifdef HAVE_LIBSNMP
void handle_async_response(struct snmp_pdu *pdu, const char *agent_ip);
void send_snmp_set_request(char *agent_host, char *community,
bool send_snmp_set_request(char *agent_host, char *community,
snmp_pdu_primitive pduType, u_int version,
char *oid[SNMP_MAX_NUM_OIDS],
char value_types[SNMP_MAX_NUM_OIDS],
char *values[SNMP_MAX_NUM_OIDS]);

void send_snmpv3_request(char *agent_host, char *level, char *username,
bool send_snmpv3_request(char *agent_host, char *level, char *username,
char *auth_protocol, char *auth_passphrase,
char *privacy_protocol, char *privacy_passphrase,
snmp_pdu_primitive pduType,
Expand All @@ -85,7 +85,7 @@ class SNMP {
char *values[SNMP_MAX_NUM_OIDS], bool _batch_mode);
#endif

void send_snmpv1v2c_request(char *agent_host, char *community,
bool send_snmpv1v2c_request(char *agent_host, char *community,
snmp_pdu_primitive pduType, u_int version,
char *oid[SNMP_MAX_NUM_OIDS], bool _batch_mode);
void snmp_fetch_responses(lua_State *vm, u_int timeout);
Expand Down
1 change: 1 addition & 0 deletions src/Flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ void Flow::deferredInitialization() {
/* Add client gateway */
if (srv_mac && !srv_mac->isNull() && !srv_host->isLocalHost()) {
LocalHost *lh = (LocalHost *)cli_host;

lh->setRouterMac(srv_mac);
}
}
Expand Down
31 changes: 17 additions & 14 deletions src/LuaEngineNtop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4570,7 +4570,8 @@ static int ntop_snmpv3_batch_get(lua_State *vm) {
char *oid[SNMP_MAX_NUM_OIDS] = {NULL};
char value_types[SNMP_MAX_NUM_OIDS];
SNMP *snmp;

bool ret;

ntop->getTrace()->traceEvent(TRACE_DEBUG, "%s() called", __FUNCTION__);

if (!curr_iface)
Expand Down Expand Up @@ -4605,19 +4606,21 @@ static int ntop_snmpv3_batch_get(lua_State *vm) {
getLuaVMUservalue(vm, snmpBatch) = snmp;
}

snmp->send_snmpv3_request(
(char *)lua_tostring(vm, 1), /* agent_host */
(char *)lua_tostring(vm, 2), /* level */
(char *)lua_tostring(vm, 3), /* username */
(char *)lua_tostring(vm, 4), /* auth_protocol */
(char *)lua_tostring(vm, 5), /* auth_passphrase */
(char *)lua_tostring(vm, 6), /* privacy_protocol */
(char *)lua_tostring(vm, 7), /* privacy_passphrase */
snmp_get_pdu, oid, /* oid */
value_types, NULL, true /* batch */);

lua_pushnil(vm);
return (ntop_lua_return_value(vm, __FUNCTION__, CONST_LUA_OK));
ret = snmp->send_snmpv3_request((char *)lua_tostring(vm, 1), /* agent_host */
(char *)lua_tostring(vm, 2), /* level */
(char *)lua_tostring(vm, 3), /* username */
(char *)lua_tostring(vm, 4), /* auth_protocol */
(char *)lua_tostring(vm, 5), /* auth_passphrase */
(char *)lua_tostring(vm, 6), /* privacy_protocol */
(char *)lua_tostring(vm, 7), /* privacy_passphrase */
snmp_get_pdu, oid, /* oid */
value_types, NULL, true /* batch */);

if(ret) {
lua_pushnil(vm);
return (ntop_lua_return_value(vm, __FUNCTION__, CONST_LUA_OK));
} else
return (ntop_lua_return_value(vm, __FUNCTION__, CONST_LUA_ERROR));
#else
return (ntop_lua_return_value(vm, __FUNCTION__, CONST_LUA_ERROR));
#endif
Expand Down
11 changes: 3 additions & 8 deletions src/Mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,9 @@ void Mac::lua(lua_State *vm, bool show_details, bool asListElement) {
/* *************************************** */

bool Mac::isNull() const {
u_int8_t zero_mac[3] = {0};

/*
We need to compare only the manufacturer (3 byets instead of 6)
as there might be variations of 00:00:00:00:00:00
such as 00:00:00:00:01:01 that are basically alike
*/
return (!memcmp(mac, zero_mac, sizeof(zero_mac)));
u_int8_t zero_mac[6] = { 0 };

return (memcmp(mac, zero_mac, sizeof(zero_mac)) == 0 ? true : false);
}

/* *************************************** */
Expand Down
Loading

0 comments on commit 42a6d07

Please sign in to comment.