diff --git a/include/SNMP.h b/include/SNMP.h index a0283f061e..be6fa1ece7 100644 --- a/include/SNMP.h +++ b/include/SNMP.h @@ -39,7 +39,7 @@ class SNMP { int snmp_read_response(lua_State* vm, u_int timeout); public: - SNMP(u_int8_t version = 1 /* SNMPv2c */); + SNMP(); ~SNMP(); void send_snmp_request(char *agent_host, char *community, bool isGetNext, diff --git a/include/ntop_defines.h b/include/ntop_defines.h index e8d23c3457..5f7331ef21 100644 --- a/include/ntop_defines.h +++ b/include/ntop_defines.h @@ -468,6 +468,7 @@ #define CONST_HOST_FLOW_VICTIM_ALERT_THRESHOLD_KEY "flow_victim_threshold" #define CONST_RUNTIME_PREFS_NBOX_INTEGRATION "ntopng.prefs.nbox_integration" /* 0 / 1 */ #define CONST_RUNTIME_PREFS_LOGGING_LEVEL "ntopng.prefs.logging_level" +#define CONST_RUNTIME_PREFS_SNMP_PROTO_VERSION "ntopng.prefs.default_snmp_version" #define CONST_RUNTIME_PREFS_IFACE_FLOW_COLLECTION "ntopng.prefs.dynamic_flow_collection_mode" /* {"none", "vlan", "probe_ip","ingress_iface_idx"} */ #define CONST_RUNTIME_PREFS_LAN_INTERFACE "ntopng.prefs.network.lan_if" #define CONST_RUNTIME_PREFS_WAN_INTERFACE "ntopng.prefs.network.wan_if" diff --git a/scripts/locales/en.lua b/scripts/locales/en.lua index fd10464294..7f87bb9669 100644 --- a/scripts/locales/en.lua +++ b/scripts/locales/en.lua @@ -781,6 +781,8 @@ local en = { " will be created an RRD with ingress/egress bytes.", default_snmp_community_title = "Default SNMP Community", default_snmp_community_description = "The default SNMP community is used when trying to walk the SNMP MIB of a selected local host that has not been configured through the SNMP devices page.", + default_snmp_proto_version_title = "Default SNMP Version", + default_snmp_proto_version_description = "The default SNMP protocol version.", nbox_integration = "nBox Integration", toggle_nbox_integration_title = "Enable nBox Support", toggle_nbox_integration_description = "Enable sending ntopng requests (e.g., to download pcap files) to an nBox. Pcap requests are issued ".. diff --git a/scripts/lua/admin/prefs.lua b/scripts/lua/admin/prefs.lua index 70394162da..1149431ae8 100644 --- a/scripts/lua/admin/prefs.lua +++ b/scripts/lua/admin/prefs.lua @@ -292,7 +292,7 @@ function printExternalAlertsReport() local retVal = multipleTableButtonPrefs(subpage_active.entries["slack_notification_severity_preference"].title, subpage_active.entries["slack_notification_severity_preference"].description, labels, values, "only_errors", "primary", "slack_notification_severity_preference", - "ntopng.prefs.alerts.slack_alert_severity", nil, nil, nil, nil, showElements and showSlackNotificationPrefs) + "ntopng.prefs.alerts.slack_alert_severity", nil, nil, nil, nil, showElements and showSlackNotificationPrefs) prefsInputFieldPrefs(subpage_active.entries["sender_username"].title, subpage_active.entries["sender_username"].description, "ntopng.prefs.alerts.", "sender_username", @@ -973,6 +973,12 @@ function printSnmp() disabled = not info["version.enterprise_edition"], }) + local t_labels = {"v1", "v2c"} + local t_values = {"0", "1"} + + multipleTableButtonPrefs(subpage_active.entries["default_snmp_proto_version"].title, subpage_active.entries["default_snmp_proto_version"].description, + t_labels, t_values, "0", "primary", "default_snmp_version", "ntopng.prefs.default_snmp_version") + prefsInputFieldPrefs(subpage_active.entries["default_snmp_community"].title, subpage_active.entries["default_snmp_community"].description, "ntopng.prefs.", "default_snmp_community", diff --git a/scripts/lua/modules/http_lint.lua b/scripts/lua/modules/http_lint.lua index 3ce0118977..df023888bb 100644 --- a/scripts/lua/modules/http_lint.lua +++ b/scripts/lua/modules/http_lint.lua @@ -693,6 +693,12 @@ local function validateInterfaceConfMode(m) return validateChoice({"dhcp", "static"}, m) end +-- ################################################################# + +local function validateSNMPversion(m) + return validateChoice({"0", "1"}, m) +end + -- ################################################################# -- NOTE: Put here al the parameters to validate @@ -842,6 +848,7 @@ local known_parameters = { ["zoom"] = validateZoom, -- a graph zoom specifier ["community"] = validateSingleWord, -- SNMP community ["default_snmp_community"] = validateSingleWord, -- Default SNMP community for non-SNMP-configured local hosts + ["default_snmp_version"] = validateSNMPversion, -- Default SNMP protocol version ["snmp_port_idx"] = validateNumber, -- SNMP port index ["snmp_recache" ] = validateBool, -- forces SNMP queries to be re-executed and cached ["request_discovery" ] = validateBool, -- forces device discovery to be re-cached diff --git a/scripts/lua/modules/prefs_menu.lua b/scripts/lua/modules/prefs_menu.lua index 514cf3c9ef..9aa11d0c03 100644 --- a/scripts/lua/modules/prefs_menu.lua +++ b/scripts/lua/modules/prefs_menu.lua @@ -199,6 +199,9 @@ local menu_subpages = { }, default_snmp_community = { title = i18n("prefs.default_snmp_community_title"), description = i18n("prefs.default_snmp_community_description"), + }, default_snmp_proto_version = { + title = i18n("prefs.default_snmp_proto_version_title"), + description = i18n("prefs.default_snmp_proto_version_description"), }, }}, {id="nbox", label=i18n("prefs.nbox_integration"), advanced=true, pro_only=true, disabled=false, entries={ toggle_nbox_integration = { diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index 848c1c653f..4d8a4c0a87 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -4665,7 +4665,8 @@ void NetworkInterface::getnDPIProtocols(lua_State *vm, ndpi_protocol_category_t for(i=0; i<(int)ndpi_struct->ndpi_num_supported_protocols; i++) { char buf[8]; - if(((filter == (u_int8_t)-1) || ndpi_struct->proto_defaults[i].protoCategory == filter) && + if((((u_int8_t)filter == (u_int8_t)-1) + || ndpi_struct->proto_defaults[i].protoCategory == filter) && (!skip_critical || !Utils::isCriticalNetworkProtocol(i))) { snprintf(buf, sizeof(buf), "%d", i); lua_push_str_table_entry(vm, ndpi_struct->proto_defaults[i].protoName, buf); diff --git a/src/SNMP.cpp b/src/SNMP.cpp index 20bb4f54ad..ae953bd546 100644 --- a/src/SNMP.cpp +++ b/src/SNMP.cpp @@ -29,12 +29,17 @@ extern "C" { /* ******************************* */ -SNMP::SNMP(u_int8_t version) { +SNMP::SNMP() { + char version[4] = { '\0' }; + + ntop->getRedis()->get((char*)CONST_RUNTIME_PREFS_SNMP_PROTO_VERSION, version, sizeof(version)); + if((udp_sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) throw("Unable to start network discovery"); - + Utils::maximizeSocketBuffer(udp_sock, true /* RX */, 2 /* MB */); - snmp_version = version; + snmp_version = atoi(version); + if(snmp_version > 1 /* v2c */) snmp_version = 1; } /* ******************************* */