Coverage Report

Created: 2026-09-14 06:54

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