1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
*
* (C) 2013-22 - ntop.org
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef _SNMP_H_
#define _SNMP_H_
#include "ntop_includes.h"
#define SNMP_MAX_NUM_OIDS 10
#ifdef HAVE_LIBSNMP
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#endif
/* ******************************* */
typedef enum {
snmp_get_pdu = 0,
snmp_get_next_pdu,
snmp_get_bulk_pdu,
snmp_set_pdu,
} snmp_pdu_primitive;
#ifdef HAVE_LIBSNMP
class SNMPSession {
public:
struct snmp_session session;
void *session_ptr;
SNMPSession();
~SNMPSession();
};
#endif
class SNMP {
private:
u_int snmp_version;
bool batch_mode;
#ifdef HAVE_LIBSNMP
std::vector<SNMPSession*> sessions;
/* Variables below are used for the async check */
lua_State* vm;
#else
int udp_sock;
u_int32_t request_id;
#endif
void 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,
char *oid[SNMP_MAX_NUM_OIDS],
char value_types[SNMP_MAX_NUM_OIDS],
char *values[SNMP_MAX_NUM_OIDS],
bool _batch_mode);
#ifdef HAVE_LIBSNMP
int snmpv3_get_fctn(lua_State* vm, snmp_pdu_primitive pduType,
bool skip_first_param, bool _batch_mode);
#endif
int snmp_get_fctn(lua_State* vm, snmp_pdu_primitive pduType,
bool skip_first_param, bool _batch_mode);
int snmp_read_response(lua_State* vm, u_int timeout);
public:
SNMP();
~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,
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,
char *auth_protocol,
char *auth_passphrase,
char *privacy_protocol,
char *privacy_passphrase,
snmp_pdu_primitive pduType,
char *oid[SNMP_MAX_NUM_OIDS],
char value_types[SNMP_MAX_NUM_OIDS],
char *values[SNMP_MAX_NUM_OIDS],
bool _batch_mode);
#endif
void 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);
int get(lua_State* vm, bool skip_first_param);
int getnext(lua_State* vm, bool skip_first_param);
int getnextbulk(lua_State* vm, bool skip_first_param);
int set(lua_State* vm, bool skip_first_param);
};
#endif /* _SNMP_H_ */
|