From 1f3afa8143d9aabc178b6fbcd09a693fc105065a Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Fri, 19 Apr 2013 15:29:19 +0200 Subject: Remove the "coding: utf-8" comment from all Erlang source files --- lib/snmp/src/manager/snmpm_conf.erl | 3 +-- lib/snmp/test/snmp_agent_test.erl | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index 03dbd028f7..5e2d9fdbf6 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -1,8 +1,7 @@ -%% -*- coding: utf-8 -*- %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2012. All Rights Reserved. +%% Copyright Ericsson AB 2006-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 09e1eb25a9..519ee4ddf9 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -1,8 +1,7 @@ -%% -*- coding: utf-8 -*- %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2012. All Rights Reserved. +%% Copyright Ericsson AB 2003-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in -- cgit v1.2.3 From e5875001247e6a6ac4f474157a51a8c54f94ae49 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Thu, 14 Mar 2013 16:01:25 +0100 Subject: Convert XML files to UTF-8 --- lib/snmp/doc/src/book.xml | 4 ++-- lib/snmp/doc/src/fascicules.xml | 2 +- lib/snmp/doc/src/notes.xml | 2 +- lib/snmp/doc/src/notes_history.xml | 4 ++-- lib/snmp/doc/src/part.xml | 4 ++-- lib/snmp/doc/src/part_notes.xml | 4 ++-- lib/snmp/doc/src/part_notes_history.xml | 4 ++-- lib/snmp/doc/src/ref_man.xml | 4 ++-- lib/snmp/doc/src/snmp.xml | 4 ++-- lib/snmp/doc/src/snmp_advanced_agent.xml | 4 ++-- lib/snmp/doc/src/snmp_agent_config_files.xml | 4 ++-- lib/snmp/doc/src/snmp_agent_funct_descr.xml | 4 ++-- lib/snmp/doc/src/snmp_agent_netif.xml | 4 ++-- lib/snmp/doc/src/snmp_app.xml | 4 ++-- lib/snmp/doc/src/snmp_app_a.xml | 4 ++-- lib/snmp/doc/src/snmp_app_b.xml | 4 ++-- lib/snmp/doc/src/snmp_audit_trail_log.xml | 4 ++-- lib/snmp/doc/src/snmp_community_mib.xml | 4 ++-- lib/snmp/doc/src/snmp_config.xml | 4 ++-- lib/snmp/doc/src/snmp_def_instr_functions.xml | 4 ++-- lib/snmp/doc/src/snmp_framework_mib.xml | 4 ++-- lib/snmp/doc/src/snmp_generic.xml | 4 ++-- lib/snmp/doc/src/snmp_impl_example_agent.xml | 4 ++-- lib/snmp/doc/src/snmp_impl_example_manager.xml | 4 ++-- lib/snmp/doc/src/snmp_index.xml | 4 ++-- lib/snmp/doc/src/snmp_instr_functions.xml | 4 ++-- lib/snmp/doc/src/snmp_intro.xml | 4 ++-- lib/snmp/doc/src/snmp_manager_config_files.xml | 4 ++-- lib/snmp/doc/src/snmp_manager_funct_descr.xml | 4 ++-- lib/snmp/doc/src/snmp_manager_netif.xml | 4 ++-- lib/snmp/doc/src/snmp_mib_compiler.xml | 4 ++-- lib/snmp/doc/src/snmp_notification_mib.xml | 4 ++-- lib/snmp/doc/src/snmp_pdus.xml | 4 ++-- lib/snmp/doc/src/snmp_standard_mib.xml | 4 ++-- lib/snmp/doc/src/snmp_target_mib.xml | 4 ++-- lib/snmp/doc/src/snmp_user_based_sm_mib.xml | 4 ++-- lib/snmp/doc/src/snmp_view_based_acm_mib.xml | 4 ++-- lib/snmp/doc/src/snmpa.xml | 4 ++-- lib/snmp/doc/src/snmpa_conf.xml | 4 ++-- lib/snmp/doc/src/snmpa_discovery_handler.xml | 4 ++-- lib/snmp/doc/src/snmpa_error.xml | 4 ++-- lib/snmp/doc/src/snmpa_error_io.xml | 4 ++-- lib/snmp/doc/src/snmpa_error_logger.xml | 4 ++-- lib/snmp/doc/src/snmpa_error_report.xml | 4 ++-- lib/snmp/doc/src/snmpa_local_db.xml | 4 ++-- lib/snmp/doc/src/snmpa_mpd.xml | 4 ++-- lib/snmp/doc/src/snmpa_network_interface.xml | 4 ++-- lib/snmp/doc/src/snmpa_network_interface_filter.xml | 4 ++-- lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml | 4 ++-- lib/snmp/doc/src/snmpa_notification_filter.xml | 4 ++-- lib/snmp/doc/src/snmpa_supervisor.xml | 4 ++-- lib/snmp/doc/src/snmpc.xml | 4 ++-- lib/snmp/doc/src/snmpc_cmd.xml | 4 ++-- lib/snmp/doc/src/snmpm.xml | 4 ++-- lib/snmp/doc/src/snmpm_conf.xml | 4 ++-- lib/snmp/doc/src/snmpm_mpd.xml | 4 ++-- lib/snmp/doc/src/snmpm_network_interface.xml | 4 ++-- lib/snmp/doc/src/snmpm_network_interface_filter.xml | 4 ++-- lib/snmp/doc/src/snmpm_user.xml | 4 ++-- 59 files changed, 116 insertions(+), 116 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/book.xml b/lib/snmp/doc/src/book.xml index 2897d25d55..a5c054142f 100644 --- a/lib/snmp/doc/src/book.xml +++ b/lib/snmp/doc/src/book.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/fascicules.xml b/lib/snmp/doc/src/fascicules.xml index 0678195e07..37feca543f 100644 --- a/lib/snmp/doc/src/fascicules.xml +++ b/lib/snmp/doc/src/fascicules.xml @@ -1,4 +1,4 @@ - + diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 5222922848..2dcfbcaef4 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -1,4 +1,4 @@ - + diff --git a/lib/snmp/doc/src/notes_history.xml b/lib/snmp/doc/src/notes_history.xml index 023717cd7c..62c6782fd7 100644 --- a/lib/snmp/doc/src/notes_history.xml +++ b/lib/snmp/doc/src/notes_history.xml @@ -1,10 +1,10 @@ - +
- 20042012 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/part.xml b/lib/snmp/doc/src/part.xml index 603ddc7a62..e68872347d 100644 --- a/lib/snmp/doc/src/part.xml +++ b/lib/snmp/doc/src/part.xml @@ -1,10 +1,10 @@ - +
- 19962009 + 19962013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/part_notes.xml b/lib/snmp/doc/src/part_notes.xml index 6d00e5b7e3..f716ac10c2 100644 --- a/lib/snmp/doc/src/part_notes.xml +++ b/lib/snmp/doc/src/part_notes.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/part_notes_history.xml b/lib/snmp/doc/src/part_notes_history.xml index bebd33e81b..3c1cacbede 100644 --- a/lib/snmp/doc/src/part_notes_history.xml +++ b/lib/snmp/doc/src/part_notes_history.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/ref_man.xml b/lib/snmp/doc/src/ref_man.xml index 92e8927f6d..94968fb0b7 100644 --- a/lib/snmp/doc/src/ref_man.xml +++ b/lib/snmp/doc/src/ref_man.xml @@ -1,10 +1,10 @@ - +
- 19962011 + 19962013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp.xml b/lib/snmp/doc/src/snmp.xml index 3e6610891f..301939cbe0 100644 --- a/lib/snmp/doc/src/snmp.xml +++ b/lib/snmp/doc/src/snmp.xml @@ -1,10 +1,10 @@ - +
- 19962012 + 19962013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_advanced_agent.xml b/lib/snmp/doc/src/snmp_advanced_agent.xml index 6600206c2d..4323b05858 100644 --- a/lib/snmp/doc/src/snmp_advanced_agent.xml +++ b/lib/snmp/doc/src/snmp_advanced_agent.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_agent_config_files.xml b/lib/snmp/doc/src/snmp_agent_config_files.xml index bd5c537522..a24f82f005 100644 --- a/lib/snmp/doc/src/snmp_agent_config_files.xml +++ b/lib/snmp/doc/src/snmp_agent_config_files.xml @@ -1,10 +1,10 @@ - +
- 19972011 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_agent_funct_descr.xml b/lib/snmp/doc/src/snmp_agent_funct_descr.xml index 9a1bf28ab1..1c89ddea22 100644 --- a/lib/snmp/doc/src/snmp_agent_funct_descr.xml +++ b/lib/snmp/doc/src/snmp_agent_funct_descr.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_agent_netif.xml b/lib/snmp/doc/src/snmp_agent_netif.xml index 8f1d860d58..fccfc8857a 100644 --- a/lib/snmp/doc/src/snmp_agent_netif.xml +++ b/lib/snmp/doc/src/snmp_agent_netif.xml @@ -1,10 +1,10 @@ - +
- 19972011 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_app.xml b/lib/snmp/doc/src/snmp_app.xml index 62dfa515d1..39c62a7ebc 100644 --- a/lib/snmp/doc/src/snmp_app.xml +++ b/lib/snmp/doc/src/snmp_app.xml @@ -1,10 +1,10 @@ - +
- 19972012 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_app_a.xml b/lib/snmp/doc/src/snmp_app_a.xml index 5192279a45..e2733b0e82 100644 --- a/lib/snmp/doc/src/snmp_app_a.xml +++ b/lib/snmp/doc/src/snmp_app_a.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_app_b.xml b/lib/snmp/doc/src/snmp_app_b.xml index 536a4b5c6f..f7c70f3e0c 100644 --- a/lib/snmp/doc/src/snmp_app_b.xml +++ b/lib/snmp/doc/src/snmp_app_b.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_audit_trail_log.xml b/lib/snmp/doc/src/snmp_audit_trail_log.xml index 9a49a0175b..c8abeabe87 100644 --- a/lib/snmp/doc/src/snmp_audit_trail_log.xml +++ b/lib/snmp/doc/src/snmp_audit_trail_log.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_community_mib.xml b/lib/snmp/doc/src/snmp_community_mib.xml index 5e7bca3e27..c5065bc319 100644 --- a/lib/snmp/doc/src/snmp_community_mib.xml +++ b/lib/snmp/doc/src/snmp_community_mib.xml @@ -1,10 +1,10 @@ - +
- 19992011 + 19992013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_config.xml b/lib/snmp/doc/src/snmp_config.xml index eec53162a1..3c6c661913 100644 --- a/lib/snmp/doc/src/snmp_config.xml +++ b/lib/snmp/doc/src/snmp_config.xml @@ -1,10 +1,10 @@ - +
- 19972012 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_def_instr_functions.xml b/lib/snmp/doc/src/snmp_def_instr_functions.xml index f88469aeae..20d2180c2d 100644 --- a/lib/snmp/doc/src/snmp_def_instr_functions.xml +++ b/lib/snmp/doc/src/snmp_def_instr_functions.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_framework_mib.xml b/lib/snmp/doc/src/snmp_framework_mib.xml index 38fb531d3e..3b4eb52ec2 100644 --- a/lib/snmp/doc/src/snmp_framework_mib.xml +++ b/lib/snmp/doc/src/snmp_framework_mib.xml @@ -1,10 +1,10 @@ - +
- 19992009 + 19992013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_generic.xml b/lib/snmp/doc/src/snmp_generic.xml index 79a22323d9..d4c65ba832 100644 --- a/lib/snmp/doc/src/snmp_generic.xml +++ b/lib/snmp/doc/src/snmp_generic.xml @@ -1,10 +1,10 @@ - +
- 19962012 + 19962013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_impl_example_agent.xml b/lib/snmp/doc/src/snmp_impl_example_agent.xml index 3bba6467ed..1260d7d432 100644 --- a/lib/snmp/doc/src/snmp_impl_example_agent.xml +++ b/lib/snmp/doc/src/snmp_impl_example_agent.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_impl_example_manager.xml b/lib/snmp/doc/src/snmp_impl_example_manager.xml index edc1f3998e..03ea54b1bf 100644 --- a/lib/snmp/doc/src/snmp_impl_example_manager.xml +++ b/lib/snmp/doc/src/snmp_impl_example_manager.xml @@ -1,10 +1,10 @@ - +
- 20062009 + 20062013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_index.xml b/lib/snmp/doc/src/snmp_index.xml index cd241820e8..5d333e2fec 100644 --- a/lib/snmp/doc/src/snmp_index.xml +++ b/lib/snmp/doc/src/snmp_index.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_instr_functions.xml b/lib/snmp/doc/src/snmp_instr_functions.xml index 32a1844554..dcfaf145d3 100644 --- a/lib/snmp/doc/src/snmp_instr_functions.xml +++ b/lib/snmp/doc/src/snmp_instr_functions.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_intro.xml b/lib/snmp/doc/src/snmp_intro.xml index b01bfdd88f..663e269e4b 100644 --- a/lib/snmp/doc/src/snmp_intro.xml +++ b/lib/snmp/doc/src/snmp_intro.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_manager_config_files.xml b/lib/snmp/doc/src/snmp_manager_config_files.xml index c2ef3cd2c7..486ef7c170 100644 --- a/lib/snmp/doc/src/snmp_manager_config_files.xml +++ b/lib/snmp/doc/src/snmp_manager_config_files.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_manager_funct_descr.xml b/lib/snmp/doc/src/snmp_manager_funct_descr.xml index db4ab9bf15..65a2ec069d 100644 --- a/lib/snmp/doc/src/snmp_manager_funct_descr.xml +++ b/lib/snmp/doc/src/snmp_manager_funct_descr.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_manager_netif.xml b/lib/snmp/doc/src/snmp_manager_netif.xml index 169e20d10b..757ed32880 100644 --- a/lib/snmp/doc/src/snmp_manager_netif.xml +++ b/lib/snmp/doc/src/snmp_manager_netif.xml @@ -1,10 +1,10 @@ - +
- 20042012 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_mib_compiler.xml b/lib/snmp/doc/src/snmp_mib_compiler.xml index 63af19f479..db0d7a344e 100644 --- a/lib/snmp/doc/src/snmp_mib_compiler.xml +++ b/lib/snmp/doc/src/snmp_mib_compiler.xml @@ -1,10 +1,10 @@ - +
- 19972009 + 19972013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_notification_mib.xml b/lib/snmp/doc/src/snmp_notification_mib.xml index d1d83570d1..963fffe98c 100644 --- a/lib/snmp/doc/src/snmp_notification_mib.xml +++ b/lib/snmp/doc/src/snmp_notification_mib.xml @@ -1,10 +1,10 @@ - +
- 19982009 + 19982013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_pdus.xml b/lib/snmp/doc/src/snmp_pdus.xml index 6c323c3ad9..2051ab291b 100644 --- a/lib/snmp/doc/src/snmp_pdus.xml +++ b/lib/snmp/doc/src/snmp_pdus.xml @@ -1,10 +1,10 @@ - +
- 19962009 + 19962013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_standard_mib.xml b/lib/snmp/doc/src/snmp_standard_mib.xml index e8dea46f32..7c9bfdb6fe 100644 --- a/lib/snmp/doc/src/snmp_standard_mib.xml +++ b/lib/snmp/doc/src/snmp_standard_mib.xml @@ -1,10 +1,10 @@ - +
- 19962009 + 19962013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_target_mib.xml b/lib/snmp/doc/src/snmp_target_mib.xml index d5151d41de..be6fa15c73 100644 --- a/lib/snmp/doc/src/snmp_target_mib.xml +++ b/lib/snmp/doc/src/snmp_target_mib.xml @@ -1,10 +1,10 @@ - +
- 19982011 + 19982013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_user_based_sm_mib.xml b/lib/snmp/doc/src/snmp_user_based_sm_mib.xml index 7485e5af57..e4eec88c57 100644 --- a/lib/snmp/doc/src/snmp_user_based_sm_mib.xml +++ b/lib/snmp/doc/src/snmp_user_based_sm_mib.xml @@ -1,10 +1,10 @@ - +
- 19992009 + 19992013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_view_based_acm_mib.xml b/lib/snmp/doc/src/snmp_view_based_acm_mib.xml index d595f6b93b..0e6e7144b4 100644 --- a/lib/snmp/doc/src/snmp_view_based_acm_mib.xml +++ b/lib/snmp/doc/src/snmp_view_based_acm_mib.xml @@ -1,10 +1,10 @@ - +
- 19992010 + 19992013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index 86fde03205..7133cb08cc 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -1,10 +1,10 @@ - +
- 20042012 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_conf.xml b/lib/snmp/doc/src/snmpa_conf.xml index a533c179ee..99a56cd601 100644 --- a/lib/snmp/doc/src/snmpa_conf.xml +++ b/lib/snmp/doc/src/snmpa_conf.xml @@ -1,10 +1,10 @@ - +
- 20062011 + 20062013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_discovery_handler.xml b/lib/snmp/doc/src/snmpa_discovery_handler.xml index 47814221aa..309a21ec32 100644 --- a/lib/snmp/doc/src/snmpa_discovery_handler.xml +++ b/lib/snmp/doc/src/snmpa_discovery_handler.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_error.xml b/lib/snmp/doc/src/snmpa_error.xml index 4dbafdfbb7..2cc44a9e79 100644 --- a/lib/snmp/doc/src/snmpa_error.xml +++ b/lib/snmp/doc/src/snmpa_error.xml @@ -1,10 +1,10 @@ - +
- 20022010 + 20022013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_error_io.xml b/lib/snmp/doc/src/snmpa_error_io.xml index 33fbfac20c..fc90db4bf9 100644 --- a/lib/snmp/doc/src/snmpa_error_io.xml +++ b/lib/snmp/doc/src/snmpa_error_io.xml @@ -1,10 +1,10 @@ - +
- 20022009 + 20022013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_error_logger.xml b/lib/snmp/doc/src/snmpa_error_logger.xml index 06382a6057..b2bf1c4181 100644 --- a/lib/snmp/doc/src/snmpa_error_logger.xml +++ b/lib/snmp/doc/src/snmpa_error_logger.xml @@ -1,10 +1,10 @@ - +
- 19962009 + 19962013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_error_report.xml b/lib/snmp/doc/src/snmpa_error_report.xml index 421202bade..f58287da08 100644 --- a/lib/snmp/doc/src/snmpa_error_report.xml +++ b/lib/snmp/doc/src/snmpa_error_report.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_local_db.xml b/lib/snmp/doc/src/snmpa_local_db.xml index c077bc96d8..e617aa0893 100644 --- a/lib/snmp/doc/src/snmpa_local_db.xml +++ b/lib/snmp/doc/src/snmpa_local_db.xml @@ -1,10 +1,10 @@ - +
- 19962009 + 19962013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_mpd.xml b/lib/snmp/doc/src/snmpa_mpd.xml index 202e6b5661..c5ab0a0520 100644 --- a/lib/snmp/doc/src/snmpa_mpd.xml +++ b/lib/snmp/doc/src/snmpa_mpd.xml @@ -1,10 +1,10 @@ - +
- 19992010 + 19992013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_network_interface.xml b/lib/snmp/doc/src/snmpa_network_interface.xml index a986343a4f..5fc51b1e53 100644 --- a/lib/snmp/doc/src/snmpa_network_interface.xml +++ b/lib/snmp/doc/src/snmpa_network_interface.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_network_interface_filter.xml b/lib/snmp/doc/src/snmpa_network_interface_filter.xml index bff0a24879..e08a26ed92 100644 --- a/lib/snmp/doc/src/snmpa_network_interface_filter.xml +++ b/lib/snmp/doc/src/snmpa_network_interface_filter.xml @@ -1,10 +1,10 @@ - +
- 20072012 + 20072013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml b/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml index c52479f76a..aff71688b6 100644 --- a/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml +++ b/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml @@ -1,11 +1,11 @@ - +
2008 - 2009 + 2013 Ericsson AB, All Rights Reserved diff --git a/lib/snmp/doc/src/snmpa_notification_filter.xml b/lib/snmp/doc/src/snmpa_notification_filter.xml index c3b300ecab..accce286bd 100644 --- a/lib/snmp/doc/src/snmpa_notification_filter.xml +++ b/lib/snmp/doc/src/snmpa_notification_filter.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_supervisor.xml b/lib/snmp/doc/src/snmpa_supervisor.xml index 89b4eb8d54..8fc178b97b 100644 --- a/lib/snmp/doc/src/snmpa_supervisor.xml +++ b/lib/snmp/doc/src/snmpa_supervisor.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpc.xml b/lib/snmp/doc/src/snmpc.xml index 61d19251c5..8eb490d391 100644 --- a/lib/snmp/doc/src/snmpc.xml +++ b/lib/snmp/doc/src/snmpc.xml @@ -1,10 +1,10 @@ - +
- 20042011 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpc_cmd.xml b/lib/snmp/doc/src/snmpc_cmd.xml index 971f8a3cff..e14b9f8e25 100644 --- a/lib/snmp/doc/src/snmpc_cmd.xml +++ b/lib/snmp/doc/src/snmpc_cmd.xml @@ -1,10 +1,10 @@ - +
- 20112011 + 20112013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index 07fdd208ff..a964a93a41 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -1,10 +1,10 @@ - +
- 20042012 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_conf.xml b/lib/snmp/doc/src/snmpm_conf.xml index 177e29faa3..0cc9ff3379 100644 --- a/lib/snmp/doc/src/snmpm_conf.xml +++ b/lib/snmp/doc/src/snmpm_conf.xml @@ -1,10 +1,10 @@ - +
- 20062009 + 20062013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_mpd.xml b/lib/snmp/doc/src/snmpm_mpd.xml index 030c79e0e6..ad72fd7bc0 100644 --- a/lib/snmp/doc/src/snmpm_mpd.xml +++ b/lib/snmp/doc/src/snmpm_mpd.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_network_interface.xml b/lib/snmp/doc/src/snmpm_network_interface.xml index 33eb736b8f..6cf7bd6ed7 100644 --- a/lib/snmp/doc/src/snmpm_network_interface.xml +++ b/lib/snmp/doc/src/snmpm_network_interface.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_network_interface_filter.xml b/lib/snmp/doc/src/snmpm_network_interface_filter.xml index 4dc133dd71..f0526269b3 100644 --- a/lib/snmp/doc/src/snmpm_network_interface_filter.xml +++ b/lib/snmp/doc/src/snmpm_network_interface_filter.xml @@ -1,10 +1,10 @@ - +
- 20072012 + 20072013 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_user.xml b/lib/snmp/doc/src/snmpm_user.xml index 1823e0c815..e36e1c6461 100644 --- a/lib/snmp/doc/src/snmpm_user.xml +++ b/lib/snmp/doc/src/snmpm_user.xml @@ -1,10 +1,10 @@ - +
- 20042009 + 20042013 Ericsson AB. All Rights Reserved. -- cgit v1.2.3 From a31c7b2eb22d15f1ca6c2d6bca257faa2315fcf7 Mon Sep 17 00:00:00 2001 From: Stefan Zegenhagen Date: Mon, 10 Jun 2013 11:07:00 +0200 Subject: SNMP/VACM: bugfix for vacmViewTreeFamilyMask Dear all, it's almost a year since I sent the patch attached to this e-mail, and I just found out that I have not yet gotten a response to it. I would consider this patch important because it fixes an issue with the interpretation of data that might be critical for SNMPv3 operation. I confirmed at that time that erlangs interpretation of vacmViewTreeFamilyMask is indeed not interoperable with other SNMP stacks. Kind regards, > > > the implementation of SNMP-VIEW-BASED-ACM.mib assumes that the input for > > > vacmViewTreeFamilyMask is an OID consisting of 1's and 0's only to form > > > the mask. However, the MIB states that the input should be a bitstring. > > > > > > The OID representation of the mask is useful in the code as it speeds up > > > time-critical code paths when checking access permissions for EACH SNMP > > > access. Reading/writing the view mask objects is less time-critical. > > > > > > Therefore, to fix the issue, convert between OID representation and > > > bitstring when the vacmViewTreeFamilyMask objects are accessed. This is > > > done by the patch attached to this e-mail. > > > I'm very sorry for the troubles that I am causing but it seems that the > previous version of the patch did more than it should: the OID-bitstring > conversion was also applied to other tables in the same MIB on > get/get-next requests. > > The version of the patch that is attached to this e-mail restricts the > OID-bitstring conversion to vacmViewTreeFamilyMask alone. -- Dr. Stefan Zegenhagen arcutronix GmbH Garbsener Landstr. 10 30419 Hannover Germany Tel: +49 511 277-2734 Fax: +49 511 277-2709 Email: stefan.zegenhagen@arcutronix.com Web: www.arcutronix.com *Synchronize the Ethernet* General Managers: Dipl. Ing. Juergen Schroeder, Dr. Josef Gfrerer - Legal Form: GmbH, Registered office: Hannover, HRB 202442, Amtsgericht Hannover; Ust-Id: DE257551767. Please consider the environment before printing this message. >From aa2acfb8a0b5ae05fc5ba982d78ee5607384a2be Mon Sep 17 00:00:00 2001 From: Stefan Zegenhagen Date: Wed, 1 Aug 2012 09:56:15 +0200 Subject: [PATCH] bugfix for vacmViewTreeFamilyMask The vacmViewTreeFamilyMask is defined to be a bit string in the MIB, not an OID. However, the MIB implementation assumed the latter, effectively rendering all attempts to read/set masks via SNMP unsuccessful. Since the mask is used in hot paths (e.g. access permission checks for each SNMP operation, the OID representation of the mask has benefits (e.g. faster processing). Therefore, convert the bitstring to/from its OID representation when reading/setting any mask object. --- lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 91 ++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 6 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl index ad9540e886..0acef780f8 100644 --- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl +++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl @@ -957,9 +957,9 @@ verify_vacmViewTreeFamilyTable_col(?vacmViewTreeFamilyMask, Mask) -> null -> []; [] -> []; _ -> - case (catch snmp_conf:check_oid(Mask)) of + case (catch check_mask(Mask)) of ok -> - Mask; + mask2oid(Mask); _ -> wrongValue(?vacmViewTreeFamilyMask) end @@ -975,7 +975,54 @@ verify_vacmViewTreeFamilyTable_col(?vacmViewTreeFamilyType, Type) -> end; verify_vacmViewTreeFamilyTable_col(_, Val) -> Val. - + + +check_mask([]) -> + ok; +check_mask([Head | Tail]) when is_integer(Head) -> +% we can cause exception here because the caller catches + if + Head > -1 andalso Head < 256 -> + check_mask(Tail) + end. + +% internally (for easier computations), the mask is stored +% as OID and not as bit-field. Therefore, we have to convert +% the bitstring to a list of integers before storing it. +mask2oid(Mask) -> + Func = fun(Byte) -> + % what's a nice syntax for extracting bits + % from a byte??? + <> = <>, + [A, B, C, D, E, F, G, H] + end, + lists:flatten(lists:map(Func, Mask)). + +oid2mask(Oid) -> + % convert all suboids to either 1 or 0 for sure + Func = fun + (0) -> 0; + (_) -> 1 + end, + oid2mask(lists:map(Func, Oid), []). + +oid2mask([], Mask) -> + % end-of-list, return bitstring + lists:reverse(Mask); +oid2mask(Oid, Mask) -> + % check whether we've got at least 8 sub-identifiers. if not, + % extend with 1's until there are enough to fill a byte + NOid = case length(Oid) of + Small when Small < 8 -> + Oid ++ lists:duplicate(8-Small, 1); + _ -> + Oid + end, + % extract sufficient suboids for 8 bits + [A, B, C, D, E, F, G, H | Tail] = NOid, + <> = <>, + oid2mask(Tail, [Byte | Mask]). + table_next(Name, RestOid) -> snmp_generic:table_next(db(Name), RestOid). @@ -1014,11 +1061,43 @@ stc(vacmSecurityToGroupTable) -> ?vacmSecurityToGroupStorageType; stc(vacmViewTreeFamilyTable) -> ?vacmViewTreeFamilyStorageType. next(Name, RowIndex, Cols) -> - snmp_generic:handle_table_next(db(Name), RowIndex, Cols, - fa(Name), foi(Name), noc(Name)). + Ans = snmp_generic:handle_table_next(db(Name), RowIndex, Cols, + fa(Name), foi(Name), noc(Name)), + patch_next(Name, Ans). get(Name, RowIndex, Cols) -> - snmp_generic:handle_table_get(db(Name), RowIndex, Cols, foi(Name)). + Ans = snmp_generic:handle_table_get(db(Name), RowIndex, Cols, foi(Name)), + patch(Name, Cols, Ans). + + +patch(Name, Cols, Ans) when is_list(Ans) -> + % function to patch returned values + Func = fun + ({Col, {value, Val}}) -> {value, do_patch(Name, Col, Val)}; + ({_, Other}) -> Other + end, + % merge column numbers and return values. there must be as much + % return values as there are columns requested + Tmp = lists:zip(Cols, Ans), + % and patch all values + lists:map(Func, Tmp); +patch(_, _, Ans) -> + Ans. + +patch_next(Name, Ans) when is_list(Ans) -> + Func = fun + ({[C | _] = Idx, Val}) -> {Idx, do_patch(Name, C, Val)}; + (Other) -> Other + end, + lists:map(Func, Ans); +patch_next(_, Ans) -> + Ans. + +do_patch(vacmViewTreeFamilyTable, ?vacmViewTreeFamilyMask, Val) -> + oid2mask(Val); +do_patch(_, _, Val) -> + Val. + wrongValue(V) -> throw({wrongValue, V}). -- cgit v1.2.3 From 7147e7a36b8a22ba6345356aa786029bab66f4e6 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 3 Jul 2013 09:39:40 +0200 Subject: [snmp/agent] Local DB counter increment wrap error The counter increment function in the local-db was incorrect. It did not handle counter wrap correctly. OTP-11192 --- lib/snmp/doc/src/notes.xml | 58 +++++++++++++++++++++++++++++++++++ lib/snmp/src/agent/snmpa_local_db.erl | 2 +- lib/snmp/src/app/snmp.appup.src | 20 ++++++++++++ lib/snmp/vsn.mk | 2 +- 4 files changed, 80 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 80de9738f1..40e761b2af 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,64 @@
+
+ SNMP Development Toolkit 4.24.1 +

Version 4.24.1 supports code replacement in runtime from/to + version 4.24, 4.23.1 and 4.23.

+ +
+ Improvements and new features +

-

+ + + +
+ +
+ Fixed Bugs and Malfunctions + + + + +

[agent] The counter increment function in the local-db was + incorrect. It did not handle counter wrap correctly.

+

Own Id: OTP-11192

+
+ +
+ +
+ +
+ Incompatibilities +

-

+ + +
+ +
+ +
SNMP Development Toolkit 4.24

Version 4.24 supports code replacement in runtime from/to diff --git a/lib/snmp/src/agent/snmpa_local_db.erl b/lib/snmp/src/agent/snmpa_local_db.erl index 2c0cad807a..5198c6ec4e 100644 --- a/lib/snmp/src/agent/snmpa_local_db.erl +++ b/lib/snmp/src/agent/snmpa_local_db.erl @@ -583,7 +583,7 @@ handle_cast({variable_inc, Name, Db, N}, State) -> {value, Val} -> Val; _ -> 0 end, - insert(Db, Name, M+N rem 4294967296, State), + insert(Db, Name, (M+N) rem 4294967296, State), {noreply, State}; handle_cast({verbosity,Verbosity}, State) -> diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 7ffa4a725d..53de57efd3 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -17,18 +17,38 @@ %% %CopyrightEnd% %% + {"%VSN%", %% ----- U p g r a d e ------------------------------------------------------- +%% Instruction examples: +%% {restart_application, snmp} +%% {load_module, snmp_pdus, soft_purge, soft_purge, []} +%% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} +%% {add_module, snmpm_net_if_mt} + [ + {"4.24", + [ + {update, snmpa_local_db, soft, soft_purge, soft_purge, []} + ] + }, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ], %% ------D o w n g r a d e --------------------------------------------------- +%% Instruction examples: +%% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} + [ + {"4.24", + [ + {update, snmpa_local_db, soft, soft_purge, soft_purge, []} + ] + }, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ] diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 0e48e7ea56..e987649e11 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.24 +SNMP_VSN = 4.24.1 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From a6ba7a3327b146d8472b154cc8ba4544f9d4d0fe Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 25 Jun 2013 12:38:17 +0200 Subject: [snmp/agent] Cleanup, renaming, appup, proper version and release notes Add utility functions for checking view masks. Code cleanup, function renaming and comment fix (%% instead of %). Also updated the mask check in the vacm config file check function. Finally, release notes and some cosmetic changes to the agent config-file(s) user guide chapter. --- lib/snmp/doc/src/notes.xml | 74 +++++++ lib/snmp/doc/src/snmp_agent_config_files.xml | 260 ++++++++++++------------- lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 206 +++++++++++--------- lib/snmp/src/app/snmp.appup.src | 12 ++ lib/snmp/src/misc/snmp_conf.erl | 35 +++- lib/snmp/vsn.mk | 2 +- 6 files changed, 355 insertions(+), 234 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 80de9738f1..9f668bf28a 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,80 @@

+
+ SNMP Development Toolkit 4.24.1 +

Version 4.24.1 supports code replacement in runtime from/to + version 4.24, 4.23.1 and 4.23.

+ +
+ Improvements and new features +

-

+ + + +
+ +
+ Fixed Bugs and Malfunctions + + + + +

[agent] Reading the value of the vacmViewTreeFamilyMask returns + it in the wrong (internal bitlist) format.

+

The vacmViewTreeFamilyMask is defined as a bit string in the MIB + (OCTET STRING). Internally a bitlist (list of 1's and 0's, + see vacm config file + for more info) is used. + However, the MIB implementation assumed the latter, effectively + rendering all attempts to read/set masks via SNMP unsuccessful.

+

Since the mask is used in hot paths (e.g. access permission checks + for each SNMP operation, the bitlist representation of the mask has + benefits (e.g. faster processing). Reading/writing the view mask + objects is less time-critical. Therefore, to fix the issue, convert + between the bitlist (internal) representation and bitstring + (external) when the vacmViewTreeFamilyMask objects are accessed.

+

Also, the check of the vacm config file was invalid with + regard to the mask value. It was assumed to be a proper oid, which + is not strictly the case (see bitlist above).

+

Own Id: OTP-11177

+

Stefan Zegenhagen

+
+ +
+ +
+ +
+ Incompatibilities +

-

+ + +
+ +
+ +
SNMP Development Toolkit 4.24

Version 4.24 supports code replacement in runtime from/to diff --git a/lib/snmp/doc/src/snmp_agent_config_files.xml b/lib/snmp/doc/src/snmp_agent_config_files.xml index bd5c537522..866b00b77b 100644 --- a/lib/snmp/doc/src/snmp_agent_config_files.xml +++ b/lib/snmp/doc/src/snmp_agent_config_files.xml @@ -4,7 +4,7 @@

- 19972011 + 19972013 Ericsson AB. All Rights Reserved. @@ -32,13 +32,15 @@ snmp_agent_config_files.xml

All configuration data must be included in configuration files - that are located in the configuration directory. The name of this - directory is given in the config_dir configuration - parameter. These files are read at start-up, and are used to - initialize the SNMPv2-MIB or STANDARD-MIB, SNMP-FRAMEWORK-MIB, - SNMP-MPD-MIB, SNMP-VIEW-BASED-ACM-MIB, SNMP-COMMUNITY-MIB, - SNMP-USER-BASED-SM-MIB, SNMP-TARGET-MIB and SNMP-NOTIFICATION-MIB - (refer to the Management of the Agent for a description of the MIBs).

+ that are located in the configuration directory. The name of this + directory is given in the config_dir configuration + parameter. These files are read at start-up, and are used to + initialize the SNMPv2-MIB or STANDARD-MIB, SNMP-FRAMEWORK-MIB, + SNMP-MPD-MIB, SNMP-VIEW-BASED-ACM-MIB, SNMP-COMMUNITY-MIB, + SNMP-USER-BASED-SM-MIB, SNMP-TARGET-MIB and SNMP-NOTIFICATION-MIB + (refer to the + Management of the Agent + for a description of the MIBs).

The files are:

@@ -79,35 +81,35 @@

The directory where the configuration files are found is given as - a parameter to the agent.

+ a parameter to the agent.

The entry format in all files are Erlang terms, separated by a - '.' and a newline. In the following sections, the - formats of these terms are described. Comments may be specified as - ordinary Erlang comments.

+ '.' and a newline. In the following sections, the + formats of these terms are described. Comments may be specified as + ordinary Erlang comments.

Syntax errors in these files are discovered and reported with the - function config_err/2 of the error report module at start-up.

- + function config_err/2 of the error report module at start-up.

+ + +
- Agent Information

The agent information should be stored in a file called - agent.conf. -

-

Each entry is a tuple of size two: -

+ agent.conf.

+

Each entry is a tuple of size two:

{AgentVariable, Value}.

- AgentVariable is one of the variables is - SNMP-FRAMEWORK-MIB or one of the internal variables - intAgentUDPPort, which defines which UDP port the agent - listens to, or intAgentIpAddress, which defines the IP - address of the agent. + +

AgentVariable is one of the variables is + SNMP-FRAMEWORK-MIB or one of the internal variables + intAgentUDPPort, which defines which UDP port the agent + listens to, or intAgentIpAddress, which defines the IP + address of the agent.

- Value is the value for the variable. + +

Value is the value for the variable.

-

The following example shows a agent.conf file: -

+

The following example shows a agent.conf file:

 {intAgentUDPPort, 4000}.
 {intAgentIpAddress,[141,213,11,24]}.
@@ -115,49 +117,47 @@
 {snmpEngineMaxPacketSize, 484}.
     

The value of snmpEngineID is a string, which for a - deployed agent should have a very specific structure. See - RFC 2271/2571 for details. -

+ deployed agent should have a very specific structure. See + RFC 2271/2571 for details.

+ +
- Contexts

The context information should be stored in a file called - context.conf. The default context "" - need not be present. -

+ context.conf. The default context "" + need not be present.

Each row defines a context in the agent. This information is - used in the table vacmContextTable in the - SNMP-VIEW-BASED-ACM-MIB. -

-

Each entry is a term: -

+ used in the table vacmContextTable in the + SNMP-VIEW-BASED-ACM-MIB.

+

Each entry is a term:

ContextName.

- ContextName is a string. + +

ContextName is a string.

+ +
- System Information

The system information should be stored in a file called - standard.conf. -

-

Each entry is a tuple of size two: -

+ standard.conf.

+

Each entry is a tuple of size two:

{SystemVariable, Value}.

- SystemVariable is one of the variables in the - system group, or snmpEnableAuthenTraps. + +

SystemVariable is one of the variables in the + system group, or snmpEnableAuthenTraps.

- Value is the value for the variable. + +

Value is the value for the variable.

-

The following example shows a valid standard.conf file: -

+

The following example shows a valid standard.conf file:

 {sysDescr, "Erlang SNMP agent"}.
 {sysObjectID, [1,2,3]}.
@@ -167,59 +167,60 @@
 {snmpEnableAuthenTraps, enabled}.
     

A value must be provided for all variables, which lack default - values in the MIB. -

+ values in the MIB.

+ +
- Communities

The community information should be stored in a file called - community.conf. It must be present if the agent is - configured for SNMPv1 or SNMPv2c. -

+ community.conf. It must be present if the agent is + configured for SNMPv1 or SNMPv2c.

An SNMP community is a relationship between an SNMP agent and a set of SNMP managers that defines authentication, access control and proxy characteristics.

The corresponding table is snmpCommunityTable in the - SNMP-COMMUNITY-MIB.

+ SNMP-COMMUNITY-MIB.

Each entry is a term:

-

{CommunityIndex, CommunityName, SecurityName, ContextName, TransportTag}.

+

{CommunityIndex, CommunityName, SecurityName, ContextName, TransportTag}.

- CommunityIndex is a non-empty string. + +

CommunityIndex is a non-empty string.

- CommunityName is a string. + +

CommunityName is a string.

- SecurityName is a string. + +

SecurityName is a string.

- ContextName is a string. + +

ContextName is a string.

- TransportTag is a string. + +

TransportTag is a string.

+ +
- MIB Views for VACM

The information about MIB Views for VACM should be stored in a - file called - vacm.conf. -

+ file called vacm.conf.

The corresponding tables are vacmSecurityToGroupTable, - vacmAccessTable and vacmViewTreeFamilyTable in the - SNMP-VIEW-BASED-ACM-MIB. -

+ vacmAccessTable and vacmViewTreeFamilyTable in the + SNMP-VIEW-BASED-ACM-MIB.

Each entry is one of the terms, one entry corresponds to one - row in one of the tables. -

+ row in one of the tables.

{vacmSecurityToGroup, SecModel, SecName, GroupName}.

{vacmAccess, GroupName, Prefix, SecModel, SecLevel, Match, ReadView, WriteView, NotifyView}.

{vacmViewTreeFamily, ViewIndex, ViewSubtree, ViewStatus, ViewMask}.

SecModel is any, v1, v2c, or - usm.

+ usm.

SecName is a string.

@@ -232,7 +233,7 @@

SecLevel is noAuthNoPriv, authNoPriv, - or authPriv

+ or authPriv

Match is prefix or exact.

@@ -244,8 +245,7 @@

WriteView is a string.

-

NotifyView is a string. -

+

NotifyView is a string.

ViewIndex is an integer.

@@ -258,33 +258,29 @@

ViewMask is either null or a list of ones and - zeros. Ones nominate that an exact match is used for this - sub-identifier. Zeros are wild-cards which match any - sub-identifier. If the mask is shorter than the sub-tree, the - tail is regarded as all ones. null is shorthand for a - mask with all ones.

+ zeros. Ones nominate that an exact match is used for this + sub-identifier. Zeros are wild-cards which match any + sub-identifier. If the mask is shorter than the sub-tree, the + tail is regarded as all ones. null is shorthand for a + mask with all ones.

+ +
- Security data for USM

The information about Security data for USM should be stored in a - file called - usm.conf, which must be present if the agent is configured - for SNMPv3. -

+ file called usm.conf, which must be present if the agent is + configured for SNMPv3.

The corresponding table is usmUserTable in the - SNMP-USER-BASED-SM-MIB. -

-

Each entry is a term: -

+ SNMP-USER-BASED-SM-MIB.

+

Each entry is a term:

{EngineID, UserName, SecName, Clone, AuthP, AuthKeyC, OwnAuthKeyC, PrivP, PrivKeyC, OwnPrivKeyC, Public, AuthKey, PrivKey}.

-

EngineID is a string. -

+

EngineID is a string.

UserName is a string.

@@ -297,7 +293,7 @@

AuthP is a usmNoAuthProtocol, - usmHMACMD5AuthProtocol, or usmHMACSHAAuthProtocol.

+ usmHMACMD5AuthProtocol, or usmHMACSHAAuthProtocol.

AuthKeyC is a string.

@@ -307,7 +303,7 @@

PrivP is a usmNoPrivProtocol, - usmDESPrivProtocol or usmAesCfb128Protocol.

+ usmDESPrivProtocol or usmAesCfb128Protocol.

PrivKeyC is a string.

@@ -319,66 +315,59 @@

Public is a string.

-

AuthKey is a list (of integer). This is the User's secret - localized authentication key. It is not visible in the MIB. The length - of this key needs to be 16 if usmHMACMD5AuthProtocol is used, and - 20 if usmHMACSHAAuthProtocol is used.

+

AuthKey is a list (of integer). This is the User's secret + localized authentication key. It is not visible in the MIB. The length + of this key needs to be 16 if usmHMACMD5AuthProtocol is used, + and 20 if usmHMACSHAAuthProtocol is used.

PrivKey is a list (of integer). This is the User's secret - localized encryption key. It is not visible in the MIB. The length - of this key needs to be 16 if usmDESPrivProtocol or - usmAesCfb128Protocol is used. -

+ localized encryption key. It is not visible in the MIB. The length + of this key needs to be 16 if usmDESPrivProtocol or + usmAesCfb128Protocol is used.

+ +
- Notify Definitions

The information about Notify Definitions should be stored in a - file called - notify.conf. -

+ file called notify.conf.

The corresponding table is snmpNotifyTable in the - SNMP-NOTIFICATION-MIB. -

-

Each entry is a term: -

+ SNMP-NOTIFICATION-MIB.

+

Each entry is a term:

{NotifyName, Tag, Type}.

-

NotifyName is a unique non-empty string. -

+

NotifyName is a unique non-empty string.

-

Tag is a string. -

+

Tag is a string.

-

Type is trap or inform. -

+

Type is trap or inform.

+ +
- Target Address Definitions

The information about Target Address Definitions should be - stored in a file called target_addr.conf.

+ stored in a file called target_addr.conf.

The corresponding tables are snmpTargetAddrTable in the - SNMP-TARGET-MIB and snmpTargetAddrExtTable in the - SNMP-COMMUNITY-MIB.

+ SNMP-TARGET-MIB and snmpTargetAddrExtTable in the + SNMP-COMMUNITY-MIB.

Each entry is a term:

{TargetName, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId}.

or

{TargetName, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

or

-{TargetName, Domain, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

+{TargetName, Domain, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

-

TargetName is a unique non-empty string. -

+

TargetName is a unique non-empty string.

Domain is one of the atoms: @@ -414,40 +403,37 @@

Note that if EngineId has the value discovery, - the agent cannot send - inform messages to that manager until it has performed the - discovery process with that manager.

+ the agent cannot send + inform messages to that manager until it has performed the + discovery process with that manager.

+ +
- Target Parameters Definitions

The information about Target Parameters Definitions should be - stored in a file called target_params.conf.

+ stored in a file called target_params.conf.

The corresponding table is snmpTargetParamsTable in the - SNMP-TARGET-MIB.

+ SNMP-TARGET-MIB.

Each entry is a term:

{ParamsName, MPModel, SecurityModel, SecurityName, SecurityLevel}.

-

ParamsName is a unique non-empty string. -

+

ParamsName is a unique non-empty string.

MPModel is v1, v2c or v3

-

SecurityModel is v1, v2c, or usm. -

+

SecurityModel is v1, v2c, or usm.

-

SecurityName is a string. -

+

SecurityName is a string.

SecurityLevel is noAuthNoPriv, authNoPriv - or authPriv. -

+ or authPriv.

diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl index 0acef780f8..c0177b1cea 100644 --- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl +++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2012. All Rights Reserved. +%% Copyright Ericsson AB 1999-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -49,6 +49,14 @@ -endif. +-type internal_view_mask() :: null | [internal_view_mask_element()]. +-type internal_view_mask_element() :: 0 | 1. + +-type external_view_mask() :: octet_string(). % At most length of 16 octet +-type octet_string() :: [octet()]. +-type octet() :: byte(). + + %%----------------------------------------------------------------- %% Func: configure/1 %% Args: Dir is the directory where the configuration files are found. @@ -160,14 +168,7 @@ check_vacm({vacmViewTreeFamily, ViewName, Tree, Type, Mask}) -> {ok, TypeVal} = snmp_conf:check_atom(Type, [{included, ?view_included}, {excluded, ?view_excluded}]), - MaskVal = - case (catch snmp_conf:check_atom(Mask, [{null, []}])) of - {error, _} -> - snmp_conf:check_oid(Mask), - Mask; - {ok, X} -> - X - end, + {ok, MaskVal} = snmp_conf:check_imask(Mask), Vacm = {ViewName, Tree, MaskVal, TypeVal, ?'StorageType_nonVolatile', ?'RowStatus_active'}, {ok, {vacmViewTreeFamily, Vacm}}; @@ -194,8 +195,8 @@ init_tabs(Sec2Group, Access, View) -> ok. init_sec2group_table([Row | T]) -> -%% ?vtrace("init security-to-group table: " -%% "~n Row: ~p",[Row]), + %% ?vtrace("init security-to-group table: " + %% "~n Row: ~p",[Row]), Key1 = element(1, Row), Key2 = element(2, Row), Key = [Key1, length(Key2) | Key2], @@ -953,13 +954,23 @@ verify_vacmViewTreeFamilyTable_col(?vacmViewTreeFamilySubtree, Tree) -> wrongValue(?vacmViewTreeFamilySubtree) end; verify_vacmViewTreeFamilyTable_col(?vacmViewTreeFamilyMask, Mask) -> + %% Mask here is in the "external" format. That is, according + %% to the MIB, which means that its an OCTET STRING of max 16 + %% octets. + %% We however store the mask as a list of 1's (exact) and + %% 0's (wildcard), which means we have to convert the mask. case Mask of - null -> []; - [] -> []; + %% The Mask can only have this value if the vacmViewTreeFamilyTable + %% is called locally! + null -> + []; + [] -> + []; _ -> - case (catch check_mask(Mask)) of - ok -> - mask2oid(Mask); + %% Check and convert to our internal format + case check_mask(Mask) of + {ok, IMask} -> + IMask; _ -> wrongValue(?vacmViewTreeFamilyMask) end @@ -975,53 +986,60 @@ verify_vacmViewTreeFamilyTable_col(?vacmViewTreeFamilyType, Type) -> end; verify_vacmViewTreeFamilyTable_col(_, Val) -> Val. + +check_mask(Mask) when is_list(Mask) andalso (length(Mask) =< 16) -> + try + begin + {ok, emask2imask(Mask)} + end + catch + throw:{error, _} -> + {error, {bad_mask, Mask}}; + T:E -> + {error, {bad_mask, Mask, T, E}} + end; +check_mask(BadMask) -> + {error, {bad_mask, BadMask}}. + +-spec emask2imask(EMask :: external_view_mask()) -> + IMask :: internal_view_mask(). + +%% Convert an External Mask (OCTET STRING) to Internal Mask (list of 0 or 1) +emask2imask(EMask) -> + lists:flatten([octet2bits(Octet) || Octet <- EMask]). + +octet2bits(Octet) + when is_integer(Octet) andalso (Octet >= 16#00) andalso (16#FF >= Octet) -> + <> = <>, + [A, B, C, D, E, F, G, H]; +octet2bits(BadOctet) -> + throw({error, {bad_octet, BadOctet}}). + +-spec imask2emask(IMask :: internal_view_mask()) -> + EMask :: external_view_mask(). + +%% Convert an Internal Mask (list of 0 or 1) to External Mask (OCTET STRING) +imask2emask(IMask) -> + imask2emask(IMask, []). + +imask2emask([], EMask) -> + lists:reverse(EMask); +imask2emask(IMask, EMask) -> + %% Make sure we have atleast 8 bits + %% (maybe extend with 1's) + IMask2 = + case length(IMask) of + Small when Small < 8 -> + IMask ++ lists:duplicate(8-Small, 1); + _ -> + IMask + end, + %% Extract 8 bits + [A, B, C, D, E, F, G, H | IMaskRest] = IMask2, + <> = <>, + imask2emask(IMaskRest, [Octet | EMask]). -check_mask([]) -> - ok; -check_mask([Head | Tail]) when is_integer(Head) -> -% we can cause exception here because the caller catches - if - Head > -1 andalso Head < 256 -> - check_mask(Tail) - end. - -% internally (for easier computations), the mask is stored -% as OID and not as bit-field. Therefore, we have to convert -% the bitstring to a list of integers before storing it. -mask2oid(Mask) -> - Func = fun(Byte) -> - % what's a nice syntax for extracting bits - % from a byte??? - <> = <>, - [A, B, C, D, E, F, G, H] - end, - lists:flatten(lists:map(Func, Mask)). - -oid2mask(Oid) -> - % convert all suboids to either 1 or 0 for sure - Func = fun - (0) -> 0; - (_) -> 1 - end, - oid2mask(lists:map(Func, Oid), []). - -oid2mask([], Mask) -> - % end-of-list, return bitstring - lists:reverse(Mask); -oid2mask(Oid, Mask) -> - % check whether we've got at least 8 sub-identifiers. if not, - % extend with 1's until there are enough to fill a byte - NOid = case length(Oid) of - Small when Small < 8 -> - Oid ++ lists:duplicate(8-Small, 1); - _ -> - Oid - end, - % extract sufficient suboids for 8 bits - [A, B, C, D, E, F, G, H | Tail] = NOid, - <> = <>, - oid2mask(Tail, [Byte | Mask]). table_next(Name, RestOid) -> @@ -1061,42 +1079,40 @@ stc(vacmSecurityToGroupTable) -> ?vacmSecurityToGroupStorageType; stc(vacmViewTreeFamilyTable) -> ?vacmViewTreeFamilyStorageType. next(Name, RowIndex, Cols) -> - Ans = snmp_generic:handle_table_next(db(Name), RowIndex, Cols, - fa(Name), foi(Name), noc(Name)), - patch_next(Name, Ans). + Result = snmp_generic:handle_table_next(db(Name), RowIndex, Cols, + fa(Name), foi(Name), noc(Name)), + externalize_next(Name, Result). get(Name, RowIndex, Cols) -> - Ans = snmp_generic:handle_table_get(db(Name), RowIndex, Cols, foi(Name)), - patch(Name, Cols, Ans). - - -patch(Name, Cols, Ans) when is_list(Ans) -> - % function to patch returned values - Func = fun - ({Col, {value, Val}}) -> {value, do_patch(Name, Col, Val)}; - ({_, Other}) -> Other - end, - % merge column numbers and return values. there must be as much - % return values as there are columns requested - Tmp = lists:zip(Cols, Ans), - % and patch all values - lists:map(Func, Tmp); -patch(_, _, Ans) -> - Ans. - -patch_next(Name, Ans) when is_list(Ans) -> - Func = fun - ({[C | _] = Idx, Val}) -> {Idx, do_patch(Name, C, Val)}; - (Other) -> Other - end, - lists:map(Func, Ans); -patch_next(_, Ans) -> - Ans. - -do_patch(vacmViewTreeFamilyTable, ?vacmViewTreeFamilyMask, Val) -> - oid2mask(Val); -do_patch(_, _, Val) -> - Val. + Result = snmp_generic:handle_table_get(db(Name), RowIndex, Cols, + foi(Name)), + externalize_get(Name, Cols, Result). + + +externalize_next(Name, Result) when is_list(Result) -> + F = fun({[Col | _] = Idx, Val}) -> {Idx, externalize(Name, Col, Val)}; + (Other) -> Other + end, + [F(R) || R <- Result]; +externalize_next(_, Result) -> + Result. + + +externalize_get(Name, Cols, Result) when is_list(Result) -> + %% Patch returned values + F = fun({Col, {value, Val}}) -> {value, externalize(Name, Col, Val)}; + ({_, Other}) -> Other + end, + %% Merge column numbers and return values. there must be as much + %% return values as there are columns requested. And then patch all values + [F(R) || R <- lists:zip(Cols, Result)]; +externalize_get(_, _, Result) -> + Result. + +externalize(vacmViewTreeFamilyTable, ?vacmViewTreeFamilyMask, Val) -> + imask2emask(Val); +externalize(_, _, Val) -> + Val. wrongValue(V) -> throw({wrongValue, V}). diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 7ffa4a725d..106fed749d 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -22,6 +22,12 @@ %% ----- U p g r a d e ------------------------------------------------------- [ + {"4.24", + [ + {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmp_conf]} + ] + }, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ], @@ -29,6 +35,12 @@ %% ------D o w n g r a d e --------------------------------------------------- [ + {"4.24", + [ + {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmp_conf]} + ] + }, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ] diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index e1e7fab57b..46625989d5 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -50,6 +50,7 @@ check_packet_size/1, check_oid/1, + check_imask/1, check_emask/1, check_mp_model/1, check_sec_model/1, check_sec_model/2, check_sec_model/3, @@ -488,6 +489,7 @@ do_check_timer(WaitFor, Factor, Incr, Retry) -> check_integer(Retry, {gte, 0}), ok. + %% --------- all_domains() -> @@ -616,6 +618,37 @@ check_oid(X) -> error({invalid_object_identifier, X}). +%% --------- + +%% Check a (view) mask in the internal form (all 0 and 1): +check_imask(null) -> + {ok, []}; +check_imask(IMask) when is_list(IMask) -> + do_check_imask(IMask), + {ok, IMask}. + +do_check_imask([0|IMask]) -> + do_check_imask(IMask); +do_check_imask([1|IMask]) -> + do_check_imask(IMask); +do_check_imask([X|_]) -> + error({invalid_internal_mask_element, X}). + + +%% Check a (view) mask in the external form (according to MIB, +%% an OCTET STRING of at most length 16). +check_emask(EMask) when is_list(EMask) andalso (length(EMask) =< 16) -> + do_check_emask(EMask). + +do_check_emask([]) -> + ok; +do_check_emask([X|EMask]) + when is_integer(X) andalso (X >= 16#00) andalso (X =< 16#FF) -> + do_check_emask(EMask); +do_check_emask([X|_]) -> + error({invalid_external_mask_element, X}). + + %% --------- all_integer([H|T]) when is_integer(H) -> all_integer(T); diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 0e48e7ea56..e987649e11 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.24 +SNMP_VSN = 4.24.1 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 16a21b95103ca20df2cd61cc5f0d32de72c28480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 16 Jul 2013 16:12:16 +0200 Subject: snmp: Silence debug in tests --- lib/snmp/test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index 546d46a002..f22b7ea8ee 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -86,7 +86,7 @@ RELSYSDIR = $(RELEASE_PATH)/snmp_test # SNMP FLAGS # ---------------------------------------------------- ifeq ($(SNMP_DEBUG),) - SNMP_DEBUG = d + # SNMP_DEBUG = d endif ifeq ($(SNMP_DEBUG),e) -- cgit v1.2.3 From 622952a654c2c8dd6ada8e0001343dfe2bce72e2 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 2 Aug 2013 15:35:54 +0200 Subject: [snmp/agent] Improved loading and unload of MIBs Improved the documentation of the loading and unloading of MIBs (plural). also added functions for loading and unloading a single mib. OTP-11216 --- lib/snmp/doc/src/notes.xml | 67 ++++++++++++++++++++++++++++++ lib/snmp/doc/src/snmpa.xml | 75 +++++++++++++++++++++++++++++----- lib/snmp/src/agent/snmpa.erl | 70 ++++++++++++++++++++++++++++--- lib/snmp/src/agent/snmpa_agent.erl | 32 +++++++++++++-- lib/snmp/src/agent/snmpa_mib.erl | 49 ++++++++++++++++------ lib/snmp/src/app/snmp.appup.src | 24 ++++++++++- lib/snmp/test/snmp_agent_mibs_test.erl | 22 +++++++--- lib/snmp/test/snmp_agent_test.erl | 74 ++++++++++++++++++--------------- lib/snmp/test/snmp_agent_test_lib.erl | 74 ++++++++++++++++----------------- lib/snmp/vsn.mk | 2 +- 10 files changed, 378 insertions(+), 111 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 21c417f0c1..8ba2161a9d 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,73 @@
+
+ SNMP Development Toolkit 4.24.2 +

Version 4.24.2 supports code replacement in runtime from/to + version 4.24.1, 4.24, 4.23.1 and 4.23.

+ +
+ Improvements and new features + + + + +

[agent] Improved documentation for the functions for + loading and unloading mibs, + see load_mibs and + unload_mibs for + more info.

+

Also added new functions for loading and unloading a single mib, + see load_mib and + unload_mib for + more info.

+

Own Id: OTP-11216

+
+ +
+ +
+ +
+ Fixed Bugs and Malfunctions +

-

+ + + +
+ +
+ Incompatibilities +

-

+ + +
+ +
+ +
SNMP Development Toolkit 4.24.1

Version 4.24.1 supports code replacement in runtime from/to diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index 86fde03205..77146f3a89 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -245,29 +245,75 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} This function is used to convert to the old (pre-4.4) info format.

+ + + + + + load_mib(Mib) -> ok | {error, Reason} + load_mib(Agent, Mib) -> ok | {error, Reason} + Load single MIB into the agent + + Agent = pid() | atom() + MibName = string() + Reason = already_loaded | term() + + +

Load a single Mib into an agent. The MibName + is the name of the Mib, including the path to where the compiled + mib is found. For example:

+ + Dir = code:priv_dir(my_app) ++ "/mibs/", + snmpa:load_mib(snmp_master_agent, Dir ++ "MY-MIB"). + +
load_mibs(Mibs) -> ok | {error, Reason} - load_mibs(Agent,Mibs) -> ok | {error, Reason} + load_mibs(Mibs, Force) -> ok | {error, Reason} + load_mibs(Agent, Mibs) -> ok | {error, Reason} + load_mibs(Agent, Mibs, Force) -> ok | {error, Reason} Load MIBs into the agent Agent = pid() | atom() Mibs = [MibName] + Force = boolean() MibName = string() - Reason = term() + Reason = {'load aborted at', MibName, InternalReason} + InternalReason = already_loaded | term() -

Loads Mibs into an agent. If the agent cannot load - all MIBs, it will indicate where loading was aborted. The - MibName is the name of the Mib, including the path to - where the compiled mib is found. For example,

- +

Load Mibs into an agent. If the agent cannot load all + MIBs (the default value of the Force argument is false), + it will indicate where loading was aborted. The MibName + is the name of the Mib, including the path to where the compiled + mib is found. For example,

+ Dir = code:priv_dir(my_app) ++ "/mibs/", snmpa:load_mibs(snmp_master_agent, [Dir ++ "MY-MIB"]). +

If Force = true then the agent will continue attempting + to load each mib even after failing to load a previous mib. Use with + care.

+ + +
+
+ + + unload_mib(Mib) -> ok | {error, Reason} + unload_mib(Agent, Mib) -> ok | {error, Reason} + Unload single MIB from the agent + + Agent = pid() | atom() + MibName = string() + Reason = not_loaded | term() + + +

Unload a single Mib from an agent.

@@ -275,16 +321,25 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} unload_mibs(Mibs) -> ok | {error, Reason} - unload_mibs(Agent,Mibs) -> ok | {error, Reason} + unload_mibs(Mibs, Force) -> ok | {error, Reason} + unload_mibs(Agent, Mibs) -> ok | {error, Reason} + unload_mibs(Agent, Mibs, Force) -> ok | {error, Reason} Unload MIBs from the agent Agent = pid() | atom() Mibs = [MibName] + Force = boolean() MibName = string() + Reason = {'unload aborted at', MibName, InternalReason} + InternalReason = not_loaded | term() -

Unloads MIBs into an agent. If it cannot unload all MIBs, - it will indicate where unloading was aborted.

+

Unload Mibs from an agent. If it cannot unload all MIBs + (the default value of the Force argument is false), + it will indicate where unloading was aborted.

+

If Force = true then the agent will continue attempting + to unload each mib even after failing to unload a previous mib. + Use with care.

diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 14b93439df..a95e41ea42 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -39,8 +39,10 @@ enum_to_int/2, enum_to_int/3, info/0, info/1, old_info_format/1, - load_mibs/1, load_mibs/2, - unload_mibs/1, unload_mibs/2, + load_mib/1, load_mib/2, + load_mibs/1, load_mibs/2, load_mibs/3, + unload_mib/1, unload_mib/2, + unload_mibs/1, unload_mibs/2, unload_mibs/3, which_mibs/0, which_mibs/1, whereis_mib/1, whereis_mib/2, dump_mibs/0, dump_mibs/1, @@ -300,19 +302,75 @@ backup(Agent, BackupDir) -> dump_mibs() -> snmpa_agent:dump_mibs(snmp_master_agent). dump_mibs(File) -> snmpa_agent:dump_mibs(snmp_master_agent, File). + +load_mib(Mib) -> + load_mib(snmp_master_agent, Mib). + +-spec load_mib(Agent :: pid() | atom(), Mib :: string()) -> + ok | {error, Reason :: already_loaded | term()}. + +load_mib(Agent, Mib) -> + case load_mibs(Agent, [Mib]) of + {error, {'load aborted at', Mib, Reason}} -> + {error, Reason}; + Else -> + Else + end. + load_mibs(Mibs) -> - load_mibs(snmp_master_agent, Mibs). + load_mibs(snmp_master_agent, Mibs, false). load_mibs(Agent, Mibs) when is_list(Mibs) -> - snmpa_agent:load_mibs(Agent, Mibs). + snmpa_agent:load_mibs(Agent, Mibs, false); +load_mibs(Mibs, Force) + when is_list(Mibs) andalso ((Force =:= true) orelse (Force =:= false)) -> + load_mibs(snmp_master_agent, Mibs, Force). + +-spec load_mibs(Agent :: pid() | atom(), + Mibs :: [MibName :: string()], + Force :: boolean()) -> + ok | {error, {'load aborted at', MibName :: string(), InternalReason :: already_loaded | term()}}. + +load_mibs(Agent, Mibs, Force) + when is_list(Mibs) andalso ((Force =:= true) orelse (Force =:= false)) -> + snmpa_agent:load_mibs(Agent, Mibs, Force). + + +unload_mib(Mib) -> + unload_mib(snmp_master_agent, Mib). + +-spec unload_mib(Agent :: pid() | atom(), Mib :: string()) -> + ok | {error, Reason :: not_loaded | term()}. + +unload_mib(Agent, Mib) -> + case unload_mibs(Agent, [Mib]) of + {error, {'unload aborted at', Mib, Reason}} -> + {error, Reason}; + Else -> + Else + end. unload_mibs(Mibs) -> - unload_mibs(snmp_master_agent, Mibs). + unload_mibs(snmp_master_agent, Mibs, false). unload_mibs(Agent, Mibs) when is_list(Mibs) -> - snmpa_agent:unload_mibs(Agent, Mibs). + snmpa_agent:unload_mibs(Agent, Mibs); +unload_mibs(Mibs, Force) + when is_list(Mibs) andalso ((Force =:= true) orelse (Force =:= false)) -> + unload_mibs(snmp_master_agent, Mibs, Force). + +-spec unload_mibs(Agent :: pid() | atom(), + Mibs :: [MibName :: string()], + Force :: boolean()) -> + ok | {error, {'unload aborted at', MibName :: string(), InternalReason :: not_loaded | term()}}. + +unload_mibs(Agent, Mibs, Force) + when is_list(Mibs) andalso ((Force =:= true) orelse (Force =:= false)) -> + snmpa_agent:unload_mibs(Agent, Mibs, Force). + which_mibs() -> which_mibs(snmp_master_agent). which_mibs(Agent) -> snmpa_agent:which_mibs(Agent). + whereis_mib(Mib) -> whereis_mib(snmp_master_agent, Mib). whereis_mib(Agent, Mib) when is_atom(Mib) -> diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index c267ce5a70..9bed6e554e 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -28,7 +28,8 @@ %% External exports -export([start_link/4, start_link/5, stop/1]). -export([subagent_set/2, - load_mibs/2, unload_mibs/2, which_mibs/1, whereis_mib/2, info/1, + load_mibs/3, unload_mibs/3, + which_mibs/1, whereis_mib/2, info/1, register_subagent/3, unregister_subagent/2, send_notification/3, register_notification_filter/5, @@ -71,7 +72,8 @@ handle_pdu/8, worker/2, worker_loop/1, do_send_trap/7, do_send_trap/8]). %% --export([handle_pdu/7]). +-export([handle_pdu/7, + load_mibs/2, unload_mibs/2]). %% -include("snmpa_internal.hrl"). @@ -528,12 +530,22 @@ subagent_set(SubAgent, Arguments) -> %% Called by administrator (not agent; deadlock would occur) +%% load_mibs(Agent, Mibs) -> - call(Agent, {load_mibs, Mibs}). + load_mibs(Agent, Mibs, false). +%% + +load_mibs(Agent, Mibs, Force) -> + call(Agent, {load_mibs, Mibs, Force}). %% Called by administrator (not agent; deadlock would occur) +%% unload_mibs(Agent, Mibs) -> - call(Agent, {unload_mibs, Mibs}). + unload_mibs(Agent, Mibs, false). +%% + +unload_mibs(Agent, Mibs, Force) -> + call(Agent, {unload_mibs, Mibs, Force}). which_mibs(Agent) -> call(Agent, which_mibs). @@ -1216,13 +1228,25 @@ handle_call({unregister_subagent, SubTreeOid}, _From, S) -> end, {reply, Reply, S}; +%% handle_call({load_mibs, Mibs}, _From, S) -> ?vlog("load mibs ~p", [Mibs]), {reply, snmpa_mib:load_mibs(get(mibserver), Mibs), S}; +%% + +handle_call({load_mibs, Mibs, Force}, _From, S) -> + ?vlog("[~w] load mibs ~p", [Force, Mibs]), + {reply, snmpa_mib:load_mibs(get(mibserver), Mibs, Force), S}; +%% handle_call({unload_mibs, Mibs}, _From, S) -> ?vlog("unload mibs ~p", [Mibs]), {reply, snmpa_mib:unload_mibs(get(mibserver), Mibs), S}; +%% + +handle_call({unload_mibs, Mibs, Force}, _From, S) -> + ?vlog("[~w] unload mibs ~p", [Force, Mibs]), + {reply, snmpa_mib:unload_mibs(get(mibserver), Mibs, Force), S}; handle_call(which_mibs, _From, S) -> ?vlog("which mibs", []), diff --git a/lib/snmp/src/agent/snmpa_mib.erl b/lib/snmp/src/agent/snmpa_mib.erl index 031309b990..5b523447c5 100644 --- a/lib/snmp/src/agent/snmpa_mib.erl +++ b/lib/snmp/src/agent/snmpa_mib.erl @@ -26,7 +26,7 @@ %% External exports -export([start_link/3, stop/1, lookup/2, next/3, which_mib/2, which_mibs/1, whereis_mib/2, - load_mibs/2, unload_mibs/2, + load_mibs/3, unload_mibs/3, register_subagent/3, unregister_subagent/2, info/1, info/2, verbosity/2, dump/1, dump/2, backup/2, @@ -39,6 +39,10 @@ which_cache_size/1 ]). +%% +-export([load_mibs/2, unload_mibs/2]). +%% + %% Internal exports -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). @@ -182,19 +186,32 @@ next(MibServer, Oid, MibView) -> %%---------------------------------------------------------------------- %% Purpose: Loads mibs into the mib process. %% Args: Mibs is a list of Filenames (compiled mibs). +%% Force is a boolean %% Returns: ok | {error, Reason} %%---------------------------------------------------------------------- + +%% load_mibs(MibServer, Mibs) -> - call(MibServer, {load_mibs, Mibs}). + load_mibs(MibServer, Mibs, false). +%% + +load_mibs(MibServer, Mibs, Force) -> + call(MibServer, {load_mibs, Mibs, Force}). %%---------------------------------------------------------------------- %% Purpose: Loads mibs into the mib process. %% Args: Mibs is a list of Filenames (compiled mibs). +%% Force is a boolean %% Returns: ok | {error, Reason} %%---------------------------------------------------------------------- +%% unload_mibs(MibServer, Mibs) -> - call(MibServer, {unload_mibs, Mibs}). + unload_mibs(MibServer, Mibs, false). +%% + +unload_mibs(MibServer, Mibs, Force) -> + call(MibServer, {unload_mibs, Mibs, Force}). %%---------------------------------------------------------------------- @@ -323,10 +340,6 @@ do_init(Prio, Mibs, Opts) -> %% Returns: {ok, NewMibData} | {'aborted at', Mib, NewData, Reason} %% Args: Operation is load_mib | unload_mib. %%---------------------------------------------------------------------- -mib_operations(Mod, Operation, Mibs, Data, MeOverride, TeOverride) -> - mib_operations(Mod, Operation, Mibs, Data, MeOverride, TeOverride, false). - - mib_operations(_Mod, _Operation, [], Data, _MeOverride, _TeOverride, _Force) -> {ok, Data}; mib_operations(Mod, Operation, [Mib|Mibs], Data0, MeOverride, TeOverride, Force) -> @@ -451,18 +464,23 @@ handle_call({next, Oid, MibView}, _From, ?vdebug("next -> Reply: ~p", [Reply]), {reply, Reply, NewState}; -handle_call({load_mibs, Mibs}, _From, +%% +handle_call({load_mibs, Mibs}, From, State) -> + handle_call({load_mibs, Mibs, false}, From, State); +%% + +handle_call({load_mibs, Mibs, Force}, _From, #state{data = Data, teo = TeOverride, meo = MeOverride, cache = Cache, data_mod = Mod} = State) -> - ?vlog("load mibs ~p",[Mibs]), + ?vlog("[~w] load mibs ~p", [Force, Mibs]), %% Invalidate cache NewCache = maybe_invalidate_cache(Cache), {NData, Reply} = case (catch mib_operations(Mod, load_mib, Mibs, Data, - MeOverride, TeOverride)) of + MeOverride, TeOverride, Force)) of {'aborted at', Mib, NewData, Reason} -> ?vlog("aborted at ~p for reason ~p",[Mib,Reason]), {NewData, {error, {'load aborted at', Mib, Reason}}}; @@ -472,19 +490,24 @@ handle_call({load_mibs, Mibs}, _From, Mod:sync(NData), {reply, Reply, State#state{data = NData, cache = NewCache}}; -handle_call({unload_mibs, Mibs}, _From, +%% +handle_call({unload_mibs, Mibs}, From, State) -> + handle_call({unload_mibs, Mibs, false}, From, State); +%% + +handle_call({unload_mibs, Mibs, Force}, _From, #state{data = Data, teo = TeOverride, meo = MeOverride, cache = Cache, data_mod = Mod} = State) -> - ?vlog("unload mibs ~p",[Mibs]), + ?vlog("[~w] unload mibs ~p", [Force, Mibs]), %% Invalidate cache NewCache = maybe_invalidate_cache(Cache), %% Unload mib(s) {NData, Reply} = case (catch mib_operations(Mod, unload_mib, Mibs, Data, - MeOverride, TeOverride)) of + MeOverride, TeOverride, Force)) of {'aborted at', Mib, NewData, Reason} -> ?vlog("aborted at ~p for reason ~p", [Mib,Reason]), {NewData, {error, {'unload aborted at', Mib, Reason}}}; diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 16b626111b..6edcf7e833 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -29,12 +29,22 @@ %% {add_module, snmpm_net_if_mt} [ + {"4.24.1", + [ + {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_mib, soft, soft_purge, soft_purge, []} + ] + }, {"4.24", [ {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []} + {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_mib, soft, soft_purge, soft_purge, []} ] }, {"4.23.1", [{restart_application, snmp}]}, @@ -47,12 +57,22 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"4.24.1", + [ + {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_mib, soft, soft_purge, soft_purge, []} + ] + }, {"4.24", [ {load_module, snmp_conf, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmp_conf]}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []} + {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, + {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_mib, soft, soft_purge, soft_purge, []} ] }, {"4.23.1", [{restart_application, snmp}]}, diff --git a/lib/snmp/test/snmp_agent_mibs_test.erl b/lib/snmp/test/snmp_agent_mibs_test.erl index 248fe7d83e..f7dae64e3f 100644 --- a/lib/snmp/test/snmp_agent_mibs_test.erl +++ b/lib/snmp/test/snmp_agent_mibs_test.erl @@ -238,6 +238,8 @@ start_and_stop(Config) when is_list(Config) -> load_unload(suite) -> []; load_unload(Config) when is_list(Config) -> + ?DBG("load_unload -> start", []), + Prio = normal, Verbosity = log, MibDir = ?config(data_dir, Config), @@ -253,8 +255,10 @@ load_unload(Config) when is_list(Config) -> ?line ok = load_mibs(MibsPid, MibDir, ["Test2"]), ?line ok = verify_loaded_mibs(MibsPid, MibDir, ["Test2"]), - ?DBG("load_unload -> load one already loaded mib", []), - ?line {error, _} = load_mibs(MibsPid, MibDir, ["Test2"]), + ?DBG("load_unload -> try load one *already loaded* mib", []), + EMib = join(MibDir, "Test2"), + ?line {error, {'load aborted at', EMib, already_loaded}} = + load_mibs(MibsPid, MibDir, ["Test2"]), ?DBG("load_unload -> load 2 not already loaded mibs", []), ?line ok = load_mibs(MibsPid, MibDir, ["TestTrap", "TestTrapv2"]), @@ -266,7 +270,8 @@ load_unload(Config) when is_list(Config) -> ?line ok = verify_loaded_mibs(MibsPid, MibDir, ["TestTrap", "TestTrapv2"]), ?DBG("load_unload -> try unload two loaded mibs and one not loaded", []), - ?line {error, _} = unload_mibs(MibsPid, ["TestTrap","Test2","TestTrapv2"]), + ?line {error, {'unload aborted at', "Test2", not_loaded}} = + unload_mibs(MibsPid, ["TestTrap","Test2","TestTrapv2"]), ?line ok = verify_loaded_mibs(MibsPid, MibDir, ["TestTrapv2"]), ?DBG("load_unload -> unload the remaining loaded mib", []), @@ -279,6 +284,7 @@ load_unload(Config) when is_list(Config) -> ?DBG("load_unload -> stop symbolic store", []), ?line sym_stop(), + ?DBG("load_unload -> done", []), ok. @@ -691,10 +697,16 @@ mibs_info(Pid) -> load_mibs(Pid, Dir, Mibs0) -> Mibs = [join(Dir, Mib) || Mib <- Mibs0], - snmpa_mib:load_mibs(Pid, Mibs). + Res = snmpa_mib:load_mibs(Pid, Mibs), + %% ?DBG("load_mibs -> " + %% "~n Res: ~p", [Res]), + Res. unload_mibs(Pid, Mibs) -> - snmpa_mib:unload_mibs(Pid, Mibs). + Res = snmpa_mib:unload_mibs(Pid, Mibs), + %% ?DBG("unload_mibs -> " + %% "~n Res: ~p", [Res]), + Res. verify_loaded_mibs(Pid, Dir, ExpectedMibs0) -> ExpectedMibs = [join(Dir, Mib) || Mib <- ExpectedMibs0], diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 6fe97ccd25..7e683e315a 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -554,7 +554,7 @@ init_per_suite(Config0) when is_list(Config0) -> %% Mib-dirs MibDir = snmp_test_lib:lookup(data_dir, Config2), - StdMibDir = filename:join([code:priv_dir(snmp), "mibs"]), + StdMibDir = join([code:priv_dir(snmp), "mibs"]), Config3 = [{mib_dir, MibDir}, {std_mib_dir, StdMibDir} | Config2], @@ -748,21 +748,21 @@ init_per_testcase2(Case, Config) -> CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config), %% Create agent top-dir(s) - AgentTopDir = filename:join([CaseTopDir, agent]), + AgentTopDir = join([CaseTopDir, agent]), ok = file:make_dir(AgentTopDir), - AgentConfDir = filename:join([AgentTopDir, config]), + AgentConfDir = join([AgentTopDir, config]), ok = file:make_dir(AgentConfDir), - AgentDbDir = filename:join([AgentTopDir, db]), + AgentDbDir = join([AgentTopDir, db]), ok = file:make_dir(AgentDbDir), - AgentLogDir = filename:join([AgentTopDir, log]), + AgentLogDir = join([AgentTopDir, log]), ok = file:make_dir(AgentLogDir), %% Create sub-agent top-dir(s) - SubAgentTopDir = filename:join([CaseTopDir, sub_agent]), + SubAgentTopDir = join([CaseTopDir, sub_agent]), ok = file:make_dir(SubAgentTopDir), %% Create manager top-dir(s) - ManagerTopDir = filename:join([CaseTopDir, manager]), + ManagerTopDir = join([CaseTopDir, manager]), ok = file:make_dir(ManagerTopDir), [{case_top_dir, CaseTopDir}, @@ -1738,19 +1738,19 @@ init_case(Config) -> load_master(Mib) -> ?DBG("load_master -> entry with" "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). + snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety + ok = snmpa:load_mib(snmp_master_agent, join(get(mib_dir), Mib)). load_master_std(Mib) -> ?DBG("load_master_std -> entry with" "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). + snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety + ok = snmpa:load_mib(snmp_master_agent, join(get(std_mib_dir), Mib)). unload_master(Mib) -> ?DBG("unload_master -> entry with" "~n Mib: ~p", [Mib]), - ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). + ok = snmpa:unload_mib(snmp_master_agent, Mib). loaded_mibs() -> ?DBG("loaded_mibs -> entry",[]), @@ -2155,11 +2155,11 @@ subagent(Config) when is_list(Config) -> try_test(unreg_test), ?P1("Loading previous subagent mib in master and testing..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]), + ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas1")), try_test(load_test), ?P1("Unloading previous subagent mib in master and testing..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]), + ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas1")), try_test(unreg_test), ?P1("Testing register subagent..."), rpc:call(SaNode, snmp, register_subagent, @@ -2355,11 +2355,11 @@ sa_register(Config) when is_list(Config) -> ?P1("Unloading Klas1..."), ?DBG("sa_register -> unload mibs", []), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + snmpa:unload_mib(SA, join(MibDir, "Klas1")), ?P1("Loading SA-MIB..."), ?DBG("sa_register -> unload mibs", []), - snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]), + snmpa:load_mib(SA, join(MibDir, "SA-MIB")), ?P1("register subagent..."), ?DBG("sa_register -> register subagent", []), @@ -2578,7 +2578,7 @@ next_across_sa(Config) when is_list(Config) -> ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), ?P1("Loading another subagent mib (Klas1)..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]), + ?line ok = snmpa:load_mib(SA, MibDir ++ "Klas1"), ?P1("register subagent..."), rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]), @@ -2590,7 +2590,7 @@ next_across_sa(Config) when is_list(Config) -> try_test(next_across_sa_test), ?P1("Unloading mib (Klas1)"), - snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]), + snmpa:unload_mib(SA, join(MibDir, "Klas1")), rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]), try_test(unreg_test), @@ -2631,25 +2631,25 @@ undo(Config) when is_list(Config) -> ?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"), ?P1("Load Klas3 & Klas4..."), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas3")), + ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas4")), ?P1("Testing undo phase at master agent..."), try_test(undo_test), try_test(api_test2), ?P1("Unload Klas3..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]), + ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas3")), ?P1("Testing bad return values from instrum. funcs..."), try_test(bad_return), ?P1("Unload Klas4..."), - ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas4")), ?P1("Testing undo phase at subagent..."), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]), - ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]), + ?line ok = snmpa:load_mib(SA, join(MibDir, "Klas3")), + ?line ok = snmpa:load_mib(SA, join(MibDir, "Klas4")), ?line ok = snmpa:register_subagent(MA, ?klas3, SA), ?line ok = snmpa:register_subagent(MA, ?klas4, SA), try_test(undo_test), @@ -6247,8 +6247,8 @@ otp_4394_config(AgentConfDir, MgrDir, Ip0) -> "OTP-4394 test"), ?line case update_usm(Vsn, AgentConfDir) of true -> - ?line copy_file(filename:join(AgentConfDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), + ?line copy_file(join(AgentConfDir, "usm.conf"), + join(MgrDir, "usm.conf")), ?line update_usm_mgr(Vsn, MgrDir); false -> ?line ok @@ -6407,11 +6407,11 @@ otp8395({init, Config}) when is_list(Config) -> %% AgentDbDir = ?config(agent_db_dir, Config), - AgentMnesiaDir = filename:join([AgentDbDir, "mnesia"]), + AgentMnesiaDir = join([AgentDbDir, "mnesia"]), mnesia_init(AgentNode, AgentMnesiaDir), %% SubAgentDir = ?config(sub_agent_dir, Config), - %% SubAgentMnesiaDir = filename:join([SubAgentDir, "mnesia"]), + %% SubAgentMnesiaDir = join([SubAgentDir, "mnesia"]), %% mnesia_init(SubAgentNode, SubAgentMnesiaDir), %% ok = mnesia_create_schema(AgentNode, [AgentNode, SubAgentNode]), @@ -6541,7 +6541,7 @@ otp8395(Config) when is_list(Config) -> ?SLEEP(1000), AgentNode = ?config(agent_node, Config), AgentLogDir = ?config(agent_log_dir, Config), - OutFile = filename:join([AgentLogDir, "otp8395.txt"]), + OutFile = join([AgentLogDir, "otp8395.txt"]), {ok, LogInfo} = rpc:call(AgentNode, snmpa, log_info, []), ?DBG("otp8395 -> LogInfo: ~p", [LogInfo]), @@ -6579,7 +6579,7 @@ otp9884({init, Config}) when is_list(Config) -> %% AgentDbDir = ?config(agent_db_dir, Config), - AgentMnesiaDir = filename:join([AgentDbDir, "mnesia"]), + AgentMnesiaDir = join([AgentDbDir, "mnesia"]), mnesia_init(AgentNode, AgentMnesiaDir), mnesia_create_schema(AgentNode, [AgentNode]), @@ -6609,8 +6609,8 @@ otp9884({init, Config}) when is_list(Config) -> ManagerConfDir = ?config(manager_top_dir, Config), AgentConfDir = ?config(agent_conf_dir, Config), AgentTopDir = ?config(agent_top_dir, Config), - AgentBkpDir1 = filename:join([AgentTopDir, backup1]), - AgentBkpDir2 = filename:join([AgentTopDir, backup2]), + AgentBkpDir1 = join([AgentTopDir, backup1]), + AgentBkpDir2 = join([AgentTopDir, backup2]), ok = file:make_dir(AgentBkpDir1), ok = file:make_dir(AgentBkpDir2), AgentBkpDirs = [AgentBkpDir1, AgentBkpDir2], @@ -7105,7 +7105,7 @@ display_log(Config) -> {value, {_, Node}} -> LogDir = Dir, Mibs = [], - OutFile = filename:join(LogDir, "snmpa_log.txt"), + OutFile = join(LogDir, "snmpa_log.txt"), p("~n" "=========================" " < Audit Trail Log > " @@ -7252,6 +7252,14 @@ lists_key1search(Key, List) when is_atom(Key) -> %% regs() -> %% lists:sort(registered()). +%% ------ + +join(Parts) -> + filename:join(Parts). + +join(Dir, File) -> + filename:join(Dir, File). + %% ------ diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 7e4b713e56..122289c28e 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -139,31 +139,31 @@ init_all(Config) when is_list(Config) -> SuiteTopDir = ?config(snmp_suite_top_dir, Config), ?DBG("init_all -> SuiteTopDir ~p", [SuiteTopDir]), - AgentDir = filename:join(SuiteTopDir, "agent/"), + AgentDir = join(SuiteTopDir, "agent/"), ?line ok = file:make_dir(AgentDir), ?DBG("init_all -> AgentDir ~p", [AgentDir]), - AgentDbDir = filename:join(AgentDir, "db/"), + AgentDbDir = join(AgentDir, "db/"), ?line ok = file:make_dir(AgentDbDir), ?DBG("init_all -> AgentDbDir ~p", [AgentDbDir]), - AgentLogDir = filename:join(AgentDir, "log/"), + AgentLogDir = join(AgentDir, "log/"), ?line ok = file:make_dir(AgentLogDir), ?DBG("init_all -> AgentLogDir ~p", [AgentLogDir]), - AgentConfDir = filename:join(AgentDir, "conf/"), + AgentConfDir = join(AgentDir, "conf/"), ?line ok = file:make_dir(AgentConfDir), ?DBG("init_all -> AgentConfDir ~p", [AgentConfDir]), - MgrDir = filename:join(SuiteTopDir, "mgr/"), + MgrDir = join(SuiteTopDir, "mgr/"), ?line ok = file:make_dir(MgrDir), ?DBG("init_all -> MgrDir ~p", [MgrDir]), - SaDir = filename:join(SuiteTopDir, "sa/"), + SaDir = join(SuiteTopDir, "sa/"), ?line ok = file:make_dir(SaDir), ?DBG("init_all -> SaDir ~p", [SaDir]), - SaDbDir = filename:join(SaDir, "db/"), + SaDbDir = join(SaDir, "db/"), ?line ok = file:make_dir(SaDbDir), ?DBG("init_all -> SaDbDir ~p", [SaDbDir]), @@ -183,11 +183,11 @@ init_all(Config) when is_list(Config) -> ?DBG("init_all -> application mnesia: set_env dir",[]), ?line application_controller:set_env(mnesia, dir, - filename:join(AgentDbDir, "Mnesia1")), + join(AgentDbDir, "Mnesia1")), ?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]), ?line rpc:call(SaNode, application_controller, set_env, - [mnesia, dir, filename:join(SaDir, "Mnesia2")]), + [mnesia, dir, join(SaDir, "Mnesia2")]), ?DBG("init_all -> create mnesia schema",[]), ?line ok = mnesia:create_schema([SaNode, node()]), @@ -253,7 +253,7 @@ init_case(Config) when is_list(Config) -> MibDir = ?config(mib_dir, Config), put(mib_dir, MibDir), - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + StdM = join(code:priv_dir(snmp), "mibs") ++ "/", put(std_mib_dir, StdM), MgrDir = ?config(mgr_dir, Config), @@ -341,7 +341,7 @@ run(Mod, Func, Args, Opts) -> Crypto = ?CRYPTO_START(), ?DBG("run -> Crypto: ~p", [Crypto]), catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case - StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/", + StdM = join(code:priv_dir(snmp), "mibs") ++ "/", Vsn = get(vsn), ?DBG("run -> config:" "~n M: ~p" @@ -763,7 +763,7 @@ start_subagent(SaNode, RegTree, Mib) -> MA = whereis(snmp_master_agent), ?DBG("start_subagent -> MA: ~p", [MA]), MibDir = get(mib_dir), - Mib1 = join(MibDir,Mib), + Mib1 = join(MibDir, Mib), Mod = snmpa_supervisor, Func = start_sub_agent, Args = [MA, RegTree, [Mib1]], @@ -800,28 +800,25 @@ mibs(StdMibDir,MibDir) -> join(MibDir, "Test2.bin"), join(MibDir, "TestTrapv2.bin")]. -join(D,F) -> - filename:join(D,F). - %% --- various mib load/unload functions --- load_master(Mib) -> ?DBG("load_master -> entry with" "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]). + snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety + ok = snmpa:load_mib(snmp_master_agent, join(get(mib_dir), Mib)). load_master_std(Mib) -> ?DBG("load_master_std -> entry with" "~n Mib: ~p", [Mib]), - snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety - ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]). + snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety + ok = snmpa:load_mibs(snmp_master_agent, join(get(std_mib_dir), Mib)). unload_master(Mib) -> ?DBG("unload_master -> entry with" "~n Mib: ~p", [Mib]), - ok = snmpa:unload_mibs(snmp_master_agent, [Mib]). + ok = snmpa:unload_mib(snmp_master_agent, Mib). loaded_mibs() -> ?DBG("loaded_mibs -> entry",[]), @@ -1383,8 +1380,8 @@ config(Vsns, MgrDir, AgentConfDir, MIp, AIp) -> "test"), ?line case update_usm(Vsns, AgentConfDir) of true -> - ?line copy_file(filename:join(AgentConfDir, "usm.conf"), - filename:join(MgrDir, "usm.conf")), + ?line copy_file(join(AgentConfDir, "usm.conf"), + join(MgrDir, "usm.conf")), ?line update_usm_mgr(Vsns, MgrDir); false -> ?line ok @@ -1403,9 +1400,9 @@ delete_files(Config) -> delete_files(_AgentFiles, []) -> ok; delete_files(AgentDir, [DirName|DirNames]) -> - Dir = filename:join(AgentDir, DirName), + Dir = join(AgentDir, DirName), {ok, Files} = file:list_dir(Dir), - lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end, + lists:foreach(fun(FName) -> file:delete(join(Dir, FName)) end, Files), delete_files(AgentDir, DirNames). @@ -1481,8 +1478,8 @@ update_usm_mgr(Vsns, Dir) -> end. rewrite_usm_mgr(Dir, ShaKey, DesKey) -> - ?line ok = file:rename(filename:join(Dir,"usm.conf"), - filename:join(Dir,"usm.old")), + ?line ok = file:rename(join(Dir,"usm.conf"), + join(Dir,"usm.old")), Conf = [{"agentEngine", "newUser", "newUser", zeroDotZero, usmHMACSHAAuthProtocol, "", "", usmDESPrivProtocol, "", "", "", ShaKey, DesKey}, @@ -1492,8 +1489,8 @@ rewrite_usm_mgr(Dir, ShaKey, DesKey) -> ok = snmp_config:write_agent_usm_config(Dir, "", Conf). reset_usm_mgr(Dir) -> - ?line ok = file:rename(filename:join(Dir,"usm.old"), - filename:join(Dir,"usm.conf")). + ?line ok = file:rename(join(Dir,"usm.old"), + join(Dir,"usm.conf")). update_community([v3], _Dir) -> @@ -1526,7 +1523,7 @@ write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> rewrite_target_addr_conf(Dir, NewPort) -> ?DBG("rewrite_target_addr_conf -> entry with" "~n NewPort: ~p", [NewPort]), - TAFile = filename:join(Dir, "target_addr.conf"), + TAFile = join(Dir, "target_addr.conf"), case file:read_file_info(TAFile) of {ok, _} -> ok; @@ -1546,8 +1543,8 @@ rewrite_target_addr_conf(Dir, NewPort) -> ?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]), - ?line ok = file:rename(filename:join(Dir,"target_addr.conf"), - filename:join(Dir,"target_addr.old")), + ?line ok = file:rename(join(Dir,"target_addr.conf"), + join(Dir,"target_addr.old")), ?line ok = snmp_config:write_agent_target_addr_config(Dir, "", NewAddrs). @@ -1565,8 +1562,8 @@ rewrite_target_addr_conf2(_NewPort,O) -> O. reset_target_addr_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir, "target_addr.old"), - filename:join(Dir, "target_addr.conf")). + ?line ok = file:rename(join(Dir, "target_addr.old"), + join(Dir, "target_addr.conf")). write_target_params_conf(Dir, Vsns) -> F = fun(v1) -> {"target_v1", v1, v1, "all-rights", noAuthNoPriv}; @@ -1578,14 +1575,14 @@ write_target_params_conf(Dir, Vsns) -> rewrite_target_params_conf(Dir, SecName, SecLevel) when is_list(SecName) andalso is_atom(SecLevel) -> - ?line ok = file:rename(filename:join(Dir,"target_params.conf"), - filename:join(Dir,"target_params.old")), + ?line ok = file:rename(join(Dir,"target_params.conf"), + join(Dir,"target_params.old")), Conf = [{"target_v3", v3, usm, SecName, SecLevel}], snmp_config:write_agent_target_params_config(Dir, "", Conf). reset_target_params_conf(Dir) -> - ?line ok = file:rename(filename:join(Dir,"target_params.old"), - filename:join(Dir,"target_params.conf")). + ?line ok = file:rename(join(Dir,"target_params.old"), + join(Dir,"target_params.conf")). write_notify_conf(Dir) -> Conf = [{"standard trap", "std_trap", trap}, @@ -1648,6 +1645,9 @@ rpc(Node, F, A) -> rpc:call(Node, snmpa, F, A). +join(Dir, File) -> + filename:join(Dir, File). + %% await_pdu(To) -> %% await_response(To, pdu). %% diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index e987649e11..2164121e86 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.24.1 +SNMP_VSN = 4.24.2 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From ffe1e03bf636f6d57715e82a00edb065d2b6ff40 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 2 Sep 2013 11:27:08 +0200 Subject: [snmp/agent] Fixed doc broken link to gen_server --- lib/snmp/doc/src/snmpa_mib_data.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/snmpa_mib_data.xml b/lib/snmp/doc/src/snmpa_mib_data.xml index ff07a03b98..c1ea0a91f9 100644 --- a/lib/snmp/doc/src/snmpa_mib_data.xml +++ b/lib/snmp/doc/src/snmpa_mib_data.xml @@ -380,7 +380,7 @@

Perform a code-change (upgrade or downgrade).

See - gen_server + gen_server for more info regarding the Vsn and Extra arguments.

-- cgit v1.2.3 From d7ce2d9b68ba83e46100a97aaf56c0ca09899525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 6 Sep 2013 10:03:56 +0200 Subject: Convert some notes.xml files from latin-1 to utf-8 In the master branch, the encoding for most xml files have been changed from latin-1 to utf-8. The problem is, that the corresponding files in the maint branch still are encoded in latin-1, and that a merge from maint to master may bring in characters encoded in latin-1 into a notes.xml file declared to be in utf-8. To fix the problem once and for all (for the files involved), we'll need to re-encode the files files utf-8 in maint, and then merge to master. Noticed-by: Magnus Henoch --- lib/snmp/doc/src/notes.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 21c417f0c1..8c4452fb9e 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -1,4 +1,4 @@ - + @@ -147,7 +147,7 @@ mib storage. At present there are three simple modules (snmpa_mib_storage_ets, snmpa_mib_storage_dets and - snmpa_mib_storage_mnesia) implementíng this behaviour, + snmpa_mib_storage_mnesia) implementing this behaviour, provided with the app.

A config option for the (agent) mib storage -- cgit v1.2.3 From 7558861af77de9405decc8d88b2c799e15f266da Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 10 Sep 2013 10:18:53 +0200 Subject: [snmp/manager] Improve handling of unexpected/invalid snmpm_user callbacks Improved handling of unexpected return values from snmpm_user callback functions. Violations of the documented API (crashes or invalid return values) will now result in an error message. Updated doc for snmpm_user bahaviour and some other stuff. Add more (common) type defs. Update manager example. Fixed manager test(s). Fixed unused vars in (manager) test suite. Make test user follow defined behaviour. --- lib/snmp/doc/src/notes.xml | 85 +++++++++++++ lib/snmp/doc/src/snmpm_user.xml | 187 ++++++++++++++++------------- lib/snmp/examples/ex2/snmp_ex2_manager.erl | 9 +- lib/snmp/src/app/snmp.appup.src | 42 +++++++ lib/snmp/src/app/snmp.erl | 52 +++++++- lib/snmp/src/app/snmp_internal.hrl | 4 +- lib/snmp/src/manager/snmpm.erl | 27 ++++- lib/snmp/src/manager/snmpm_server.erl | 184 ++++++++++++++++++++-------- lib/snmp/src/manager/snmpm_user.erl | 173 ++++++++++++++------------ lib/snmp/test/snmp_manager_test.erl | 66 +++++----- lib/snmp/test/snmp_manager_user.erl | 17 ++- lib/snmp/test/snmp_test_manager.erl | 20 ++- lib/snmp/vsn.mk | 2 +- 13 files changed, 614 insertions(+), 254 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 21c417f0c1..646e3027d6 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,91 @@

+
+ SNMP Development Toolkit 4.25 +

Version 4.25 supports code replacement in runtime from/to + version 4.24.1, 4.24, 4.23.1 and 4.23.

+ +
+ Improvements and new features + + + + +

[manager] Improved handling of unexpected return values from + snmpm_user + callback functions.

+

Violations of the documented API (crashes or invalid return + values) will now result in an error message.

+

Own Id: OTP-11307

+
+ +
+ +
+ +
+ Fixed Bugs and Malfunctions +

-

+ + + +
+ +
+ Incompatibilities + + + + +

[manager] The + snmpm_user + callback functions are no longer allowed to "return" via + exit or throw.

+

Own Id: OTP-11307

+
+ +
+
+ +
+ +
SNMP Development Toolkit 4.24.1

Version 4.24.1 supports code replacement in runtime from/to diff --git a/lib/snmp/doc/src/snmpm_user.xml b/lib/snmp/doc/src/snmpm_user.xml index 1823e0c815..cb2deab976 100644 --- a/lib/snmp/doc/src/snmpm_user.xml +++ b/lib/snmp/doc/src/snmpm_user.xml @@ -1,10 +1,10 @@ - +

- 20042009 + 20042013 Ericsson AB. All Rights Reserved. @@ -56,40 +56,59 @@

handle_report/3

+ +

handle_invalid_result/2

+

The semantics of them and their exact signatures are explained - below.

-

Note that if an agent is registered using the old, no longer - documented, functions (using Addr and Port), the old variant of the - callback functions, handle_pdu, handle_trap, handle_inform and - handle_report, will be called.

+ below.

+

Some of the function has no defined return value (void()), + they can ofcourse return anythyng. But the functions that do have + specified return value(s) must adhere to this. None of the + functions can use exit of throw to return.

- + + +
+ DATA TYPES + + +
+ - handle_error(ReqId, Reason, UserData) -> Reply + handle_error(ReqId, Reason, UserData) -> void() Handle error ReqId = integer() Reason = {unexpected_pdu, SnmpInfo} | {invalid_sec_info, SecInfo, SnmpInfo} | {empty_message, Addr, Port} | term() + SnmpInfo = snmp_gen_info() + SecInfo = term() Addr = ip_address() Port = integer() UserData = term() - Reply = ignore

This function is called when the manager needs to - communicate an "asynchronous" error, to the user: - e.g. failure to send an asynchronous message (i.e. encoding - error), a received message was discarded due to security - error, the manager failed to generate a response message to - a received inform-request, or when receiving an unexpected - PDU from an agent (could be an expired async request).

-

If ReqId is less then 0, it means that this - information was not available to the manager (that info was - never retrieved before the message was discarded). -

+ communicate an "asynchronous" error to the user: + e.g. failure to send an asynchronous message (i.e. encoding + error), a received message was discarded due to security + error, the manager failed to generate a response message to + a received inform-request, or when receiving an unexpected + PDU from an agent (could be an expired async request).

+

If ReqId is less then 0, it means that this + information was not available to the manager (that info was + never retrieved before the message was discarded).

For SnmpInfo see handle_agent below.

@@ -104,22 +123,22 @@ Port = integer() Type = pdu | trap | report | inform SnmpInfo = SnmpPduInfo | SnmpTrapInfo | SnmpReportInfo | SnmpInformInfo - ErrorStatus = atom() - ErrorIndex = integer() - Varbinds = [varbind()] - varbind() = #varbind + SnmpPduInfo = snmp_gen_info() + SnmpTrapInfo = snmp_v1_trap_info() + SnmpReportInfo = snmp_gen_info() + SnmpInformInfo = snmp_gen_info() UserData = term() - Reply = ignore | {register, UserId, TargetName, agent_info()} + Reply = ignore | {register, UserId, TargetName, AgentConfig} UserId = term() TargetName = target_name() - agent_info() = [{agent_info_item(), agent_info_value()}] + AgentConfig = [agent_config()] -

This function is called when a message is received from an - unknown agent.

+

This function is called when a message is received from an + unknown agent.

Note that this will always be the default user that is called.

-

For more info about the agent_info(), see - register_agent.

+

For more info about the agent_config(), see + register_agent.

The arguments Type and SnmpInfo relates in the following way:

@@ -148,7 +167,7 @@

The only user which would return - {register, UserId, TargetName, agent_info()} is the + {register, UserId, TargetName, AgentConfig} is the default user.

@@ -156,18 +175,13 @@
- handle_pdu(TargetName, ReqId, SnmpPduInfo, UserData) -> Reply + handle_pdu(TargetName, ReqId, SnmpPduInfo, UserData) -> void() Handle the reply to an asynchronous request TargetName = target_name() ReqId = term() - SnmpPduInfo = {ErrorStatus, ErrorIndex, Varbinds} - ErrorStatus = atom() - ErrorIndex = integer() - Varbinds = [varbind()] - varbind() = #varbind + SnmpPduInfo = snmp_gen_info() UserData = term() - Reply = ignore

Handle the reply to an asynchronous request, such as @@ -186,27 +200,19 @@ Handle a trap/notification message TargetName = TargetName2 = target_name() - SnmpTrapInfo = {Enteprise, Generic, Spec, Timestamp, Varbinds} | {ErrorStatus, ErrorIndex, Varbinds} - Enterprise = oid() - Generic = integer() - Spec = integer() - Timestamp = integer() - ErrorStatus = atom() - ErrorIndex = integer() - Varbinds = [varbind()] - varbind() = #varbind + SnmpTrapInfo = snmp_v1_trap_info() | snmp_gen_info() UserData = term() - Reply = ignore | unregister | {register, UserId, TargetName2, agent_info()} + Reply = ignore | unregister | {register, UserId, TargetName2, AgentConfig} UserId = term() - agent_info() = [{agent_info_item(), agent_info_value()}] + AgentConfig = [agent_config()]

Handle a trap/notification message from an agent.

-

For more info about the agent_info(), see - register_agent

+

For more info about the agent_config(), see + register_agent

The only user which would return - {register, UserId, TargetName2, agent_info()} is the - default user.

+ {register, UserId, TargetName2, agent_info()} is the + default user.

@@ -217,29 +223,25 @@ Handle a inform message TargetName = TargetName2 = target_name() - SnmpInformInfo = {ErrorStatus, ErrorIndex, Varbinds} - ErrorStatus = atom() - ErrorIndex = integer() - Varbinds = [varbind()] - varbind() = #varbind + SnmpInformInfo = snmp_gen_info() UserData = term() - Reply = ignore | unregister | {register, UserId, TargetName2, agent_info()} + Reply = ignore | no_reply | unregister | {register, UserId, TargetName2, AgentConfig} UserId = term() - agent_info() = [{agent_info_item(), agent_info_value()}] + AgentConfig = [agent_config()]

Handle a inform message.

-

For more info about the agent_info(), see - register_agent

+

For more info about the agent_config(), see + register_agent

The only user which would return - {register, UserId, TargetName2, agent_info()} is the - default user.

-

If the - inform request behaviour - configuration option is set to user or - {user, integer()}, the response (acknowledgment) to this - inform-request will be sent when this function returns.

- + {register, UserId, TargetName2, AgentConfig} is the + default user.

+

If the + inform request behaviour + configuration option is set to user or + {user, integer()}, the response (acknowledgment) to this + inform-request will be sent when this function returns.

+
@@ -251,23 +253,46 @@ TargetName = TargetName2 = target_name() Addr = ip_address() Port = integer() - SnmpReportInfo = {ErrorStatus, ErrorIndex, Varbinds} - ErrorStatus = atom() - ErrorIndex = integer() - Varbinds = [varbind()] - varbind() = #varbind + SnmpReportInfo = snmp_gen_info() UserData = term() - Reply = ignore | unregister | {register, UserId, TargetName2, agent_info()} + Reply = ignore | unregister | {register, UserId, TargetName2, AgentConfig} UserId = term() - agent_info() = [{agent_info_item(), agent_info_value()}] + AgentConfig = [agent_config()]

Handle a report message.

-

For more info about the agent_info(), see - register_agent

+

For more info about the agent_config(), see + register_agent

The only user which would return - {register, UserId, TargetName2, agent_info()} is the - default user.

+ {register, UserId, TargetName2, AgentConfig} is the + default user.

+ + +
+ + + + handle_invalid_result(IN, OUT) -> void() + Handle a report message + + IN = {Func, Args} + Func = atom() + Args = list() + OUT = {crash, CrashInfo} | {result, InvalidResult} + CrashInfo = {ErrorType, Error, Stacktrace} + ErrorType = atom() + Error = term() + Stacktrace = list() + InvalidResult = term() + + +

If any of the other callback functions crashes + (exit, throw or a plain crash) or return an invalid result (if a valid + return has been specified), this function is called. + The purpose is to allow the user handle this + error (for instance to issue an error report).

+

IN reprecents the function called (and its arguments). + OUT represents the unexpected/invalid result.

diff --git a/lib/snmp/examples/ex2/snmp_ex2_manager.erl b/lib/snmp/examples/ex2/snmp_ex2_manager.erl index 1b247d713d..a9dcc09b77 100644 --- a/lib/snmp/examples/ex2/snmp_ex2_manager.erl +++ b/lib/snmp/examples/ex2/snmp_ex2_manager.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2012. All Rights Reserved. +%% Copyright Ericsson AB 2006-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -43,7 +43,8 @@ handle_pdu/4, handle_trap/3, handle_inform/3, - handle_report/3]). + handle_report/3, + handle_invalid_result/3]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, @@ -406,5 +407,9 @@ handle_report(TargetName, SnmpReport, Server) when is_pid(Server) -> report_callback(Server, handle_inform, {TargetName, SnmpReport}), ok. +handle_invalid_result(In, Out, Server) when is_pid(Server) -> + report_callback(Server, handle_invalid_result, {In, Out}), + ok. + report_callback(Pid, Tag, Info) -> Pid ! {snmp_callback, Tag, Info}. diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 16b626111b..7bd50c2c4d 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -29,11 +29,32 @@ %% {add_module, snmpm_net_if_mt} [ + {"4.24.2", + [ + {load_module, snmp, soft_purge, soft_purge, []}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm_user, soft_purge, soft_purge, [snmp, snmpm]}, + {load_module, snmpm_user_default, soft_purge, soft_purge, [snmpm_user]}, + {update, snmpm_server, soft, soft_purge, soft_purge, [snmpm_user]} + ] + }, + {"4.24.1", + [ + {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_mib, soft, soft_purge, soft_purge, []} + ] + }, {"4.24", [ + {load_module, snmp, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm_user, soft_purge, soft_purge, [snmp, snmpm]}, + {load_module, snmpm_user_default, soft_purge, soft_purge, [snmpm_user]}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmp_conf]}, + {update, snmpm_server, soft, soft_purge, soft_purge, [snmpm_user]}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []} ] }, @@ -47,11 +68,32 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"4.24.2", + [ + {load_module, snmp, soft_purge, soft_purge, []}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm_user, soft_purge, soft_purge, [snmp, snmpm]}, + {load_module, snmpm_user_default, soft_purge, soft_purge, [snmpm_user]}, + {update, snmpm_server, soft, soft_purge, soft_purge, [snmpm_user]} + ] + }, + {"4.24.1", + [ + {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, + {update, snmpa_mib, soft, soft_purge, soft_purge, []} + ] + }, {"4.24", [ + {load_module, snmp, soft_purge, soft_purge, []}, {load_module, snmp_conf, soft_purge, soft_purge, []}, + {load_module, snmpm, soft_purge, soft_purge, [snmp]}, + {load_module, snmpm_user, soft_purge, soft_purge, [snmp, snmpm]}, + {load_module, snmpm_user_default, soft_purge, soft_purge, [snmpm_user]}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, [snmp_conf]}, + {update, snmpm_server, soft, soft_purge, soft_purge, [snmpm_user]}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []} ] }, diff --git a/lib/snmp/src/app/snmp.erl b/lib/snmp/src/app/snmp.erl index 1bb562654a..a37979f5eb 100644 --- a/lib/snmp/src/app/snmp.erl +++ b/lib/snmp/src/app/snmp.erl @@ -91,8 +91,30 @@ ]). -export_type([ + snmp_timer/0, + + engine_id/0, + tdomain/0, + community/0, + mms/0, + version/0, + sec_model/0, + sec_name/0, + sec_level/0, + oid/0, - + varbind/0, + ivarbind/0, + asn1_type/0, + table_info/0, + variable_info/0, + me/0, + trap/0, + notification/0, + pdu/0, + trappdu/0, + mib/0, + void/0 ]). @@ -149,14 +171,38 @@ -define(APPLICATION, snmp). +-include_lib("snmp/include/snmp_types.hrl"). %%----------------------------------------------------------------- %% Types %%----------------------------------------------------------------- --type oid() :: [non_neg_integer()]. --type void() :: term(). +-type snmp_timer() :: #snmp_incr_timer{}. + +-type engine_id() :: string(). +-type tdomain() :: transportDomainUdpIpv4 | transportDomainUdpIpv6. +-type community() :: string(). +-type mms() :: non_neg_integer(). +-type version() :: v1 | v2 | v3. +-type sec_model() :: any | v1 | v2c | usm. +-type sec_name() :: string(). +-type sec_level() :: noAuthNoPriv | authNoPriv | authPriv. + +-type oid() :: [non_neg_integer()]. +-type varbind() :: #varbind{}. +-type ivarbind() :: #ivarbind{}. +-type asn1_type() :: #asn1_type{}. +-type table_info() :: #table_info{}. +-type variable_info() :: #variable_info{}. +-type me() :: #me{}. +-type trap() :: #trap{}. +-type notification() :: #notification{}. +-type mib() :: #mib{}. +-type pdu() :: #pdu{}. +-type trappdu() :: #trappdu{}. + +-type void() :: term(). %%----------------------------------------------------------------- diff --git a/lib/snmp/src/app/snmp_internal.hrl b/lib/snmp/src/app/snmp_internal.hrl index 5ff715e0b7..f04fa4dd53 100644 --- a/lib/snmp/src/app/snmp_internal.hrl +++ b/lib/snmp/src/app/snmp_internal.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2009. All Rights Reserved. +%% Copyright Ericsson AB 2006-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -24,6 +24,8 @@ -define(APPLICATION, snmp). -endif. +-define(STACK(), erlang:get_stacktrace()). + -define(snmp_info(C, F, A), ?snmp_msg(info_msg, C, F, A)). -define(snmp_warning(C, F, A), ?snmp_msg(warning_msg, C, F, A)). -define(snmp_error(C, F, A), ?snmp_msg(error_msg, C, F, A)). diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 6ac0115dad..8bfca76a1c 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2012. All Rights Reserved. +%% Copyright Ericsson AB 2004-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -111,6 +111,12 @@ -export([start_link/3, snmpm_start_verify/2, snmpm_start_verify/3]). -export([target_name/1, target_name/2]). +-export_type([ + register_timeout/0, + agent_config/0, + target_name/0 + ]). + -include_lib("snmp/src/misc/snmp_debug.hrl"). -include_lib("snmp/include/snmp_types.hrl"). @@ -121,6 +127,25 @@ -define(DEFAULT_AGENT_PORT, 161). +%%----------------------------------------------------------------- +%% Types +%%----------------------------------------------------------------- + +-type register_timeout() :: pos_integer() | snmp:snmp_timer(). +-type agent_config() :: {engine_id, snmp:engine_id()} | % Mandatory + {address, inet:ip_address()} | % Mandatory + {port, inet:port_number()} | % Optional + {tdomain, snmp:tdomain()} | % Optional + {community, snmp:community()} | % Optional + {timeout, register_timeout()} | % Optional + {max_message_size, snmp:mms()} | % Optional + {version, snmp:version()} | % Optional + {sec_moduel, snmp:sec_model()} | % Optional + {sec_name, snmp:sec_name()} | % Optional + {sec_level, snmp:sec_level()}. % Optional +-type target_name() :: string(). + + %% This function is called when the snmp application %% starts. start_link(Opts, normal, []) -> diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 61d22362cc..9c79df2748 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -488,7 +488,7 @@ cancel_async_request(UserId, ReqId) -> %% discovery(UserId, BAddr, Port, Config, Expire, ExtraInfo) -> %% call({discovery, self(), UserId, BAddr, Port, Config, Expire, ExtraInfo}). - + verbosity(Verbosity) -> case ?vvalidate(Verbosity) of Verbosity -> @@ -1851,7 +1851,17 @@ handle_snmp_error(Addr, Port, ReqId, Reason, State) -> handle_error(_UserId, Mod, Reason, ReqId, Data, _State) -> ?vtrace("handle_error -> entry when" "~n Mod: ~p", [Mod]), - F = fun() -> (catch Mod:handle_error(ReqId, Reason, Data)) end, + F = fun() -> + try + begin + Mod:handle_error(ReqId, Reason, Data) + end + catch + T:E -> + CallbackArgs = [ReqId, Reason, Data], + handle_invalid_result(handle_error, CallbackArgs, T, E) + end + end, handle_callback(F), ok. @@ -2031,7 +2041,15 @@ handle_pdu(_UserId, Mod, target_name = _RegType, TargetName, _Addr, _Port, ?vtrace("handle_pdu(target_name) -> entry when" "~n Mod: ~p", [Mod]), F = fun() -> - (catch Mod:handle_pdu(TargetName, ReqId, SnmpResponse, Data)) + try + begin + Mod:handle_pdu(TargetName, ReqId, SnmpResponse, Data) + end + catch + T:E -> + CallbackArgs = [TargetName, ReqId, SnmpResponse, Data], + handle_invalid_result(handle_pdu, CallbackArgs, T, E) + end end, handle_callback(F), ok; @@ -2064,8 +2082,37 @@ do_handle_agent(DefUserId, DefMod, SnmpInfo, DefData, State) -> ?vdebug("do_handle_agent -> entry when" "~n DefUserId: ~p", [DefUserId]), - case (catch DefMod:handle_agent(Addr, Port, Type, SnmpInfo, DefData)) of - {'EXIT', {undef, _}} when Type =:= pdu -> + try DefMod:handle_agent(Addr, Port, Type, SnmpInfo, DefData) of + {register, UserId2, TargetName, Config} -> + ?vtrace("do_handle_agent -> register: " + "~n UserId2: ~p" + "~n TargetName: ~p" + "~n Config: ~p", + [UserId2, TargetName, Config]), + Config2 = ensure_present([{address, Addr}, {port, Port}], Config), + Config3 = [{reg_type, target_name} | Config2], + case snmpm_config:register_agent(UserId2, + TargetName, Config3) of + ok -> + ok; + {error, Reason} -> + error_msg("failed registering agent - " + "handling agent " + "~p <~p,~p>: ~n~w", + [TargetName, Addr, Port, Reason]), + ok + end; + + ignore -> + ?vdebug("do_handle_agent -> ignore", []), + ok; + + InvalidResult -> + CallbackArgs = [Addr, Port, Type, SnmpInfo, DefData], + handle_invalid_result(handle_agent, CallbackArgs, InvalidResult) + + catch + error:{undef, _} when Type =:= pdu -> %% Maybe, still on the old API ?vdebug("do_handle_agent -> maybe still on the old api", []), case (catch DefMod:handle_agent(Addr, Port, SnmpInfo, DefData)) of @@ -2113,10 +2160,10 @@ do_handle_agent(DefUserId, DefMod, ok end; - {'EXIT', {undef, _}} -> + error:{undef, _} -> %% If the user does not implement the new API (but the %% old), then this clause catches all non-pdu handle_agent - %% calls. These calls was previously never made,so we make + %% calls. These calls was previously never made, so we make %% a best-effert call (using reg-type target_name) to the %% various callback functions, and leave it to the user to %% figure out @@ -2148,31 +2195,11 @@ do_handle_agent(DefUserId, DefMod, "regarding agent " "<~p,~p>: ~n~w", [Type, Addr, Port, SnmpInfo]) end; - - {register, UserId2, TargetName, Config} -> - ?vtrace("do_handle_agent -> register: " - "~n UserId2: ~p" - "~n TargetName: ~p" - "~n Config: ~p", - [UserId2, TargetName, Config]), - Config2 = ensure_present([{address, Addr}, {port, Port}], Config), - Config3 = [{reg_type, target_name} | Config2], - case snmpm_config:register_agent(UserId2, - TargetName, Config3) of - ok -> - ok; - {error, Reason} -> - error_msg("failed registering agent - " - "handling agent " - "~p <~p,~p>: ~n~w", - [TargetName, Addr, Port, Reason]), - ok - end; - _Ignore -> - ?vdebug("do_handle_agent -> ignore", []), - ok - + T:E -> + CallbackArgs = [Addr, Port, Type, SnmpInfo, DefData], + handle_invalid_result(handle_agent, CallbackArgs, T, E) + end. ensure_present([], Config) -> @@ -2305,15 +2332,17 @@ do_handle_trap(UserId, Mod, RegType, Target, Addr, Port, SnmpTrapInfo, Data, _State) -> ?vdebug("do_handle_trap -> entry with" "~n UserId: ~p", [UserId]), - HandleTrap = + {HandleTrap, CallbackArgs} = case RegType of target_name -> - fun() -> Mod:handle_trap(Target, SnmpTrapInfo, Data) end; + {fun() -> Mod:handle_trap(Target, SnmpTrapInfo, Data) end, + [Target, SnmpTrapInfo, Data]}; addr_port -> - fun() -> Mod:handle_trap(Addr, Port, SnmpTrapInfo, Data) end + {fun() -> Mod:handle_trap(Addr, Port, SnmpTrapInfo, Data) end, + [Addr, Port, SnmpTrapInfo, Data]} end, - case (catch HandleTrap()) of + try HandleTrap() of {register, UserId2, Config} -> ?vtrace("do_handle_trap -> register: " "~n UserId2: ~p" @@ -2362,9 +2391,17 @@ do_handle_trap(UserId, Mod, [Addr, Port, Reason]), ok end; - _Ignore -> + ignore -> ?vtrace("do_handle_trap -> ignore", []), - ok + ok; + + InvalidResult -> + handle_invalid_result(handle_trap, CallbackArgs, InvalidResult) + + catch + T:E -> + handle_invalid_result(handle_trap, CallbackArgs, T, E) + end. @@ -2465,16 +2502,18 @@ do_handle_inform(UserId, Mod, Ref, RegType, Target, Addr, Port, SnmpInform, Data, State) -> ?vdebug("do_handle_inform -> entry with" "~n UserId: ~p", [UserId]), - HandleInform = + {HandleInform, CallbackArgs} = case RegType of target_name -> - fun() -> Mod:handle_inform(Target, SnmpInform, Data) end; + {fun() -> Mod:handle_inform(Target, SnmpInform, Data) end, + [Target, SnmpInform, Data]}; addr_port -> - fun() -> Mod:handle_inform(Addr, Port, SnmpInform, Data) end + {fun() -> Mod:handle_inform(Addr, Port, SnmpInform, Data) end, + [Addr, Port, SnmpInform, Data]} end, Rep = - case (catch HandleInform()) of + try HandleInform() of {register, UserId2, Config} -> ?vtrace("do_handle_inform -> register: " "~n UserId2: ~p" @@ -2494,6 +2533,7 @@ do_handle_inform(UserId, Mod, Ref, [Target2, Addr, Port, Reason]), reply end; + {register, UserId2, Target2, Config} -> ?vtrace("do_handle_inform -> register: " "~n UserId2: ~p" @@ -2512,6 +2552,7 @@ do_handle_inform(UserId, Mod, Ref, [Target2, Addr, Port, Reason]), reply end; + unregister -> ?vtrace("do_handle_inform -> unregister", []), case snmpm_config:unregister_agent(UserId, @@ -2525,12 +2566,25 @@ do_handle_inform(UserId, Mod, Ref, [Addr, Port, Reason]), reply end; + no_reply -> ?vtrace("do_handle_inform -> no_reply", []), no_reply; - _Ignore -> + + ignore -> ?vtrace("do_handle_inform -> ignore", []), + reply; + + InvalidResult -> + handle_invalid_result(handle_inform, CallbackArgs, + InvalidResult), reply + + catch + T:E -> + handle_invalid_result(handle_inform, CallbackArgs, T, E), + reply + end, handle_inform_response(Rep, Ref, Addr, Port, State), ok. @@ -2760,15 +2814,17 @@ do_handle_report(UserId, Mod, RegType, Target, Addr, Port, SnmpReport, Data, _State) -> ?vdebug("do_handle_report -> entry with" "~n UserId: ~p", [UserId]), - HandleReport = + {HandleReport, CallbackArgs} = case RegType of target_name -> - fun() -> Mod:handle_report(Target, SnmpReport, Data) end; + {fun() -> Mod:handle_report(Target, SnmpReport, Data) end, + [Target, SnmpReport, Data]}; addr_port -> - fun() -> Mod:handle_report(Addr, Port, SnmpReport, Data) end + {fun() -> Mod:handle_report(Addr, Port, SnmpReport, Data) end, + [Addr, Port, SnmpReport, Data]} end, - case (catch HandleReport()) of + try HandleReport() of {register, UserId2, Config} -> ?vtrace("do_handle_report -> register: " "~n UserId2: ~p" @@ -2788,6 +2844,7 @@ do_handle_report(UserId, Mod, [Addr, Port, Reason]), ok end; + {register, UserId2, Target2, Config} -> ?vtrace("do_handle_report -> register: " "~n UserId2: ~p" @@ -2806,6 +2863,7 @@ do_handle_report(UserId, Mod, [Target2, Addr, Port, Reason]), reply end; + unregister -> ?vtrace("do_handle_trap -> unregister", []), case snmpm_config:unregister_agent(UserId, @@ -2819,9 +2877,20 @@ do_handle_report(UserId, Mod, [Addr, Port, Reason]), ok end; - _Ignore -> + + ignore -> ?vtrace("do_handle_report -> ignore", []), - ok + ok; + + InvalidResult -> + handle_invalid_result(handle_report, CallbackArgs, InvalidResult), + reply + + catch + T:E -> + handle_invalid_result(handle_report, CallbackArgs, T, E), + reply + end. @@ -2835,6 +2904,25 @@ handle_callback(F) -> end). + +handle_invalid_result(Func, Args, T, E) -> + Stacktrace = ?STACK(), + error_msg("Callback function failed: " + "~n Function: ~p" + "~n Args: ~p" + "~n Error Type: ~p" + "~n Error: ~p" + "~n Stacktrace: ~p", + [Func, Args, T, E, Stacktrace]). + +handle_invalid_result(Func, Args, InvalidResult) -> + error_msg("Callback function returned invalid result: " + "~n Function: ~p" + "~n Args: ~p" + "~n Invalid result: ~p", + [Func, Args, InvalidResult]). + + handle_down(MonRef) -> (catch do_handle_down(MonRef)). diff --git a/lib/snmp/src/manager/snmpm_user.erl b/lib/snmp/src/manager/snmpm_user.erl index 78aa560b2e..e6b0b6943e 100644 --- a/lib/snmp/src/manager/snmpm_user.erl +++ b/lib/snmp/src/manager/snmpm_user.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -19,79 +19,100 @@ -module(snmpm_user). --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{handle_error, 3}, - {handle_agent, 5}, - {handle_pdu, 4}, - {handle_trap, 3}, - {handle_inform, 3}, - {handle_report, 3}]; -behaviour_info(_) -> - undefined. - - -%% handle_error(ReqId, Reason, UserData) -> Reply -%% ReqId -> integer() -%% Reason -> term() -%% UserData -> term() (supplied when the user register) -%% Reply -> ignore - -%% handle_agent(Addr, Port, Type, SnmpInfo, UserData) -> Reply -%% Addr -> term() -%% Port -> integer() -%% Type -> pdu | trap | inform | report -%% SnmpInfo -> {ErrorStatus, ErrorIndex, Varbinds} -%% UserId -> term() -%% ErrorStatus -> atom() -%% ErrorIndex -> integer() -%% Varbinds -> [varbind()] -%% UserData -> term() (supplied when the user register) -%% Reply -> ignore | {register, UserId, agent_info()} -%% agent_info() -> [{agent_info_item(), agent_info_value()}] -%% This is the same info as in update_agent_info/4 - -%% handle_pdu(TargetName, ReqId, SnmpResponse, UserData) -> Reply -%% TargetName -> target_name() -%% ReqId -> term() (returned when calling ag(...), ...) -%% SnmpResponse -> {ErrorStatus, ErrorIndex, Varbinds} -%% ErrorStatus -> atom() -%% ErrorIndex -> integer() -%% Varbinds -> [varbind()] -%% UserData -> term() (supplied when the user register) -%% Reply -> ignore - -%% handle_trap(TargetName, SnmpTrapInfo, UserData) -> Reply -%% TargetName -> target_name() -%% SnmpTrapInfo -> {Enteprise, Generic, Spec, Timestamp, Varbinds} | -%% {ErrorStatus, ErrorIndex, Varbinds} -%% Enteprise -> oid() -%% Generic -> integer() -%% Spec -> integer() -%% Timestamp -> integer() -%% ErrorStatus -> atom() -%% ErrorIndex -> integer() -%% Varbinds -> [varbind()] -%% UserData -> term() (supplied when the user register) -%% Reply -> ignore | unregister | {register, UserId, agent_info()} - -%% handle_inform(TargetName, SnmpInform, UserData) -> Reply -%% TargetName -> target_name() -%% SnmpInform -> {ErrorStatus, ErrorIndex, Varbinds} -%% ErrorStatus -> atom() -%% ErrorIndex -> integer() -%% Varbinds -> [varbind()] -%% UserData -> term() (supplied when the user register) -%% Reply -> ignore | unregister | {register, UserId, agent_info()} -%% - -%% handle_report(TargetName, SnmpReport, UserData) -> Reply -%% TargetName -> target_name() -%% SnmpReport -> {ErrorStatus, ErrorIndex, Varbinds} -%% ErrorStatus -> integer() -%% ErrorIndex -> integer() -%% Varbinds -> [varbind()] -%% UserData -> term() (supplied when the user register) -%% Reply -> ignore | unregister | {register, UserId, agent_info()} +-export_type([ + snmp_gen_info/0, + snmp_v1_trap_info/0 + ]). + +-type snmp_gen_info() :: {ErrorStatus :: atom(), + ErrorIndex :: pos_integer(), + Varbinds :: [snmp:varbind()]}. +-type snmp_v1_trap_info() :: {Enteprise :: snmp:oid(), + Generic :: integer(), + Spec :: integer(), + Timestamp :: integer(), + Varbinds :: [snmp:varbind()]}. +-type ip_address() :: inet:ip_address(). +-type port_number() :: inet:port_number(). + + +%% *** handle_error *** +%% An "asynchronous" error has been detected + +-callback handle_error(ReqId :: integer(), + Reason :: {unexpected_pdu, SnmpInfo :: snmp_gen_info()} | + {invalid_sec_info, SecInfo :: term(), SnmpInfo :: snmp_gen_info()} | + {empty_message, Addr :: ip_address(), Port :: port_number()} | + term(), + UserData :: term()) -> + snmp:void(). + + +%% *** handle_agent *** +%% A message was received from an unknown agent + +-callback handle_agent(Addr :: term(), + Port :: pos_integer(), + Type :: pdu | trap | inform | report, + SnmpInfo :: snmp_gen_info() | snmp_v1_trap_info(), + UserData :: term()) -> + Reply :: ignore | + {register, + UserId :: term(), + RTargetName :: snmpm:target_name(), + AgentConfig :: [snmpm:agent_config()]}. + + +%% *** handle_pdu *** +%% Handle the reply to an async request (such as get, get-next and set). + +-callback handle_pdu(TargetName :: snmpm:target_name(), + ReqId :: term(), + SnmpResponse :: snmp_gen_info(), + UserData :: term()) -> + snmp:void(). + + +%% *** handle_trap *** +%% Handle a trap/notification message received from an agent + +-callback handle_trap(TargetName :: snmpm:target_name(), + SnmpTrapInfo :: snmp_gen_info() | snmp_v1_trap_info(), + UserData :: term()) -> + Reply :: ignore | + unregister | + {register, + UserId :: term(), + RTargetName :: snmpm:target_name(), + AgentConfig :: [snmpm:agent_config()]}. + + +%% *** handle_inform *** +%% Handle a inform message received from an agent + +-callback handle_inform(TargetName :: snmpm:target_name(), + SnmpInform :: snmp_gen_info(), + UserData :: term()) -> + Reply :: ignore | no_reply | + unregister | + {register, + UserId :: term(), + RTargetName :: snmpm:target_name(), + AgentConfig :: [snmpm:agent_config()]}. + + +%% *** handle_report *** +%% Handle a report message received from an agent + +-callback handle_report(TargetName :: snmpm:target_name(), + SnmpReport :: snmp_gen_info(), + UserData :: term()) -> + Reply :: ignore | + unregister | + {register, + UserId :: term(), + RTargetName :: snmpm:target_name(), + AgentConfig :: [snmpm:agent_config()]}. + + diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index dedbae5ce4..5fe18980bc 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2012. All Rights Reserved. +%% Copyright Ericsson AB 2003-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -1615,10 +1615,10 @@ simple_sync_get1(Config) when is_list(Config) -> ok. do_simple_sync_get(Node, Addr, Port, Oids) -> - ?line {ok, Reply, Rem} = mgr_user_sync_get(Node, Addr, Port, Oids), + ?line {ok, Reply, _Rem} = mgr_user_sync_get(Node, Addr, Port, Oids), ?DBG("~n Reply: ~p" - "~n Rem: ~w", [Reply, Rem]), + "~n Rem: ~w", [Reply, _Rem]), %% verify that the operation actually worked: %% The order should be the same, so no need to seach @@ -1682,10 +1682,10 @@ do_simple_sync_get2(Config, Get, PostVerify) -> do_simple_sync_get2(Node, TargetName, Oids, Get, PostVerify) when is_function(Get, 3) andalso is_function(PostVerify, 0) -> - ?line {ok, Reply, Rem} = Get(Node, TargetName, Oids), + ?line {ok, Reply, _Rem} = Get(Node, TargetName, Oids), ?DBG("~n Reply: ~p" - "~n Rem: ~w", [Reply, Rem]), + "~n Rem: ~w", [Reply, _Rem]), %% verify that the operation actually worked: %% The order should be the same, so no need to seach @@ -2061,10 +2061,10 @@ simple_sync_get_next1(Config) when is_list(Config) -> do_simple_get_next(N, Node, Addr, Port, Oids, Verify) -> p("issue get-next command ~w", [N]), case mgr_user_sync_get_next(Node, Addr, Port, Oids) of - {ok, Reply, Rem} -> + {ok, Reply, _Rem} -> ?DBG("get-next ok:" "~n Reply: ~p" - "~n Rem: ~w", [Reply, Rem]), + "~n Rem: ~w", [Reply, _Rem]), Verify(Reply); Error -> @@ -2217,10 +2217,10 @@ do_simple_sync_get_next2(Config, GetNext, PostVerify) do_simple_get_next(N, Node, TargetName, Oids, Verify, GetNext, PostVerify) -> p("issue get-next command ~w", [N]), case GetNext(Node, TargetName, Oids) of - {ok, Reply, Rem} -> + {ok, Reply, _Rem} -> ?DBG("get-next ok:" "~n Reply: ~p" - "~n Rem: ~w", [Reply, Rem]), + "~n Rem: ~w", [Reply, _Rem]), PostVerify(Verify(Reply)); Error -> @@ -2551,10 +2551,10 @@ simple_sync_set1(Config) when is_list(Config) -> do_simple_set1(Node, Addr, Port, VAVs) -> [SysName, SysLoc] = value_of_vavs(VAVs), - ?line {ok, Reply, Rem} = mgr_user_sync_set(Node, Addr, Port, VAVs), + ?line {ok, Reply, _Rem} = mgr_user_sync_set(Node, Addr, Port, VAVs), ?DBG("~n Reply: ~p" - "~n Rem: ~w", [Reply, Rem]), + "~n Rem: ~w", [Reply, _Rem]), %% verify that the operation actually worked: %% The order should be the same, so no need to seach @@ -2631,10 +2631,10 @@ do_simple_sync_set2(Config, Set, PostVerify) do_simple_set2(Node, TargetName, VAVs, Set, PostVerify) -> [SysName, SysLoc] = value_of_vavs(VAVs), - ?line {ok, Reply, Rem} = Set(Node, TargetName, VAVs), + ?line {ok, Reply, _Rem} = Set(Node, TargetName, VAVs), ?DBG("~n Reply: ~p" - "~n Rem: ~w", [Reply, Rem]), + "~n Rem: ~w", [Reply, _Rem]), %% verify that the operation actually worked: %% The order should be the same, so no need to seach @@ -3026,10 +3026,10 @@ fl(L) -> do_simple_get_bulk1(N, Node, Addr, Port, NonRep, MaxRep, Oids, Verify) -> p("issue get-bulk command ~w", [N]), case mgr_user_sync_get_bulk(Node, Addr, Port, NonRep, MaxRep, Oids) of - {ok, Reply, Rem} -> + {ok, Reply, _Rem} -> ?DBG("get-bulk ok:" "~n Reply: ~p" - "~n Rem: ~w", [Reply, Rem]), + "~n Rem: ~w", [Reply, _Rem]), Verify(Reply); Error -> @@ -3213,10 +3213,10 @@ do_simple_get_bulk2(N, is_function(PostVerify) -> p("issue get-bulk command ~w", [N]), case GetBulk(NonRep, MaxRep, Oids) of - {ok, Reply, Rem} -> + {ok, Reply, _Rem} -> ?DBG("get-bulk ok:" "~n Reply: ~p" - "~n Rem: ~w", [Reply, Rem]), + "~n Rem: ~w", [Reply, _Rem]), PostVerify(Verify(Reply)); Error -> @@ -5609,11 +5609,11 @@ init_mgr_user_data1(Conf) -> [{address, Addr}, {port, Port}, {engine_id, "agentEngine"}]), - Agents = mgr_user_which_own_agents(Node), - ?DBG("Own agents: ~p", [Agents]), + _Agents = mgr_user_which_own_agents(Node), + ?DBG("Own agents: ~p", [_Agents]), - ?line {ok, DefAgentConf} = mgr_user_agent_info(Node, TargetName, all), - ?DBG("Default agent config: ~n~p", [DefAgentConf]), + ?line {ok, _DefAgentConf} = mgr_user_agent_info(Node, TargetName, all), + ?DBG("Default agent config: ~n~p", [_DefAgentConf]), ?line ok = mgr_user_update_agent_info(Node, TargetName, community, "all-rights"), @@ -5624,8 +5624,8 @@ init_mgr_user_data1(Conf) -> ?line ok = mgr_user_update_agent_info(Node, TargetName, max_message_size, 1024), - ?line {ok, AgentConf} = mgr_user_agent_info(Node, TargetName, all), - ?DBG("Updated agent config: ~n~p", [AgentConf]), + ?line {ok, _AgentConf} = mgr_user_agent_info(Node, TargetName, all), + ?DBG("Updated agent config: ~n~p", [_AgentConf]), Conf. init_mgr_user_data2(Conf) -> @@ -5639,11 +5639,11 @@ init_mgr_user_data2(Conf) -> [{address, Addr}, {port, Port}, {engine_id, "agentEngine"}]), - Agents = mgr_user_which_own_agents(Node), - ?DBG("Own agents: ~p", [Agents]), + _Agents = mgr_user_which_own_agents(Node), + ?DBG("Own agents: ~p", [_Agents]), - ?line {ok, DefAgentConf} = mgr_user_agent_info(Node, TargetName, all), - ?DBG("Default agent config: ~n~p", [DefAgentConf]), + ?line {ok, _DefAgentConf} = mgr_user_agent_info(Node, TargetName, all), + ?DBG("Default agent config: ~n~p", [_DefAgentConf]), ?line ok = mgr_user_update_agent_info(Node, TargetName, community, "all-rights"), @@ -5652,8 +5652,8 @@ init_mgr_user_data2(Conf) -> ?line ok = mgr_user_update_agent_info(Node, TargetName, max_message_size, 1024), - ?line {ok, AgentConf} = mgr_user_agent_info(Node, TargetName, all), - ?DBG("Updated agent config: ~n~p", [AgentConf]), + ?line {ok, _AgentConf} = mgr_user_agent_info(Node, TargetName, all), + ?DBG("Updated agent config: ~n~p", [_AgentConf]), Conf. fin_mgr_user_data1(Conf) -> @@ -5853,12 +5853,12 @@ mgr_user_name_to_oid(Node, Name) -> start_manager(Node, Vsns, Config) -> start_manager(Node, Vsns, Config, []). -start_manager(Node, Vsns, Conf0, Opts) -> +start_manager(Node, Vsns, Conf0, _Opts) -> ?DBG("start_manager -> entry with" "~n Node: ~p" "~n Vsns: ~p" "~n Conf0: ~p" - "~n Opts: ~p", [Node, Vsns, Conf0, Opts]), + "~n Opts: ~p", [Node, Vsns, Conf0, _Opts]), AtlDir = ?config(manager_log_dir, Conf0), ConfDir = ?config(manager_conf_dir, Conf0), @@ -5908,12 +5908,12 @@ stop_manager(Node, Conf) -> start_agent(Node, Vsns, Config) -> start_agent(Node, Vsns, Config, []). -start_agent(Node, Vsns, Conf0, Opts) -> +start_agent(Node, Vsns, Conf0, _Opts) -> ?DBG("start_agent -> entry with" "~n Node: ~p" "~n Vsns: ~p" "~n Conf0: ~p" - "~n Opts: ~p", [Node, Vsns, Conf0, Opts]), + "~n Opts: ~p", [Node, Vsns, Conf0, _Opts]), AtlDir = ?config(agent_log_dir, Conf0), ConfDir = ?config(agent_conf_dir, Conf0), diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index 4e789bbaec..ddbe156130 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2012. All Rights Reserved. +%% Copyright Ericsson AB 2005-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -681,6 +681,15 @@ loop(#state{parent = Parent, id = Id} = S) -> Parent ! {async_event, TargetName, {report, SnmpReport}}, loop(S); + {handle_invalid_result, _Pid, In, Out} -> + d("loop -> received invalid result callback from manager for " + "~n In: ~p", + "~n Out: ~p", [In, Out]), + info("received invalid result message: " + "~n In: ~p" + "~n Out: ~p", [In, Out]), + loop(S); + {'EXIT', Parent, Reason} -> d("received exit signal from parent: ~n~p", [Reason]), info("received exit signal from parent: ~n~p", [Reason]), @@ -770,7 +779,7 @@ handle_pdu(TargetName, ReqId, SnmpResponse, UserPid) -> handle_trap(TargetName, SnmpTrap, UserPid) -> UserPid ! {handle_trap, self(), TargetName, SnmpTrap}, - ok. + ignore. handle_inform(TargetName, SnmpInform, UserPid) -> UserPid ! {handle_inform, self(), TargetName, SnmpInform}, @@ -778,12 +787,12 @@ handle_inform(TargetName, SnmpInform, UserPid) -> {handle_inform_no_response, TargetName} -> no_reply; {handle_inform_response, TargetName} -> - ok + ignore end. handle_report(TargetName, SnmpReport, UserPid) -> UserPid ! {handle_report, self(), TargetName, SnmpReport}, - ok. + ignore. %%---------------------------------------------------------------------- diff --git a/lib/snmp/test/snmp_test_manager.erl b/lib/snmp/test/snmp_test_manager.erl index 1f3383a7a8..925ae77ab5 100644 --- a/lib/snmp/test/snmp_test_manager.erl +++ b/lib/snmp/test/snmp_test_manager.erl @@ -47,7 +47,8 @@ handle_pdu/4, handle_trap/3, handle_inform/3, - handle_report/3 + handle_report/3, + handle_invalid_result/3 ]). @@ -279,12 +280,18 @@ handle_info({snmp_inform, TargetName, Info, Pid}, handle_info({snmp_report, TargetName, Info, Pid}, #state{parent = P} = State) -> info_msg("received snmp report: " - "~n TargetName: ~p" - "~n Info: ~p", [TargetName, Info]), + "~n TargetName: ~p" + "~n Info: ~p", [TargetName, Info]), Pid ! {snmp_report_reply, ignore, self()}, P ! {snmp_report, TargetName, Info}, {noreply, State}; +handle_info({snmp_invalid_result, In, Out}, State) -> + error_msg("Callback failure: " + "~n In: ~p" + "~n Out: ~p", [In, Out]), + {noreply, State}; + handle_info(Info, State) -> error_msg("received unknown info: " "~n Info: ~p", [Info]), @@ -369,7 +376,12 @@ handle_report(TargetName, SnmpInfo, Pid) -> after 10000 -> ignore end. - + + +handle_invalid_result(In, Out, Pid) -> + Pid ! {snmp_invalid_result, In, Out}, + ignore. + %%---------------------------------------------------------------------- diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index e987649e11..70f7c2b19a 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.24.1 +SNMP_VSN = 4.25 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From c83c236f6a0a1a5299376e40db57e7b7527cbac7 Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Fri, 20 Sep 2013 14:23:35 -0400 Subject: [snmp/agent] enable SNMP to create missing database directories Add {db_init_error, create_db_and_dir} option to SNMP manager and agent. This allows them to create any missing parent directories for db_dir, rather than treating any missing directories as a fatal error. The default for db_init_error, which is terminate, is unchanged. Add create_db_and_dir to the documentation. Add new tests to verify that using create_db_and_dir results in missing parent directories being created. --- lib/snmp/doc/src/snmp_app.xml | 7 ++- lib/snmp/doc/src/snmp_config.xml | 9 ++-- lib/snmp/src/agent/snmpa_local_db.erl | 6 +++ lib/snmp/src/agent/snmpa_supervisor.erl | 2 +- lib/snmp/src/manager/snmpm_config.erl | 31 ++++++++++--- lib/snmp/test/snmp_agent_test.erl | 72 +++++++++++++++++++++++++++++- lib/snmp/test/snmp_manager_config_test.erl | 41 +++++++++++++++-- 7 files changed, 153 insertions(+), 15 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/snmp_app.xml b/lib/snmp/doc/src/snmp_app.xml index e5a05342c1..9ede75b943 100644 --- a/lib/snmp/doc/src/snmp_app.xml +++ b/lib/snmp/doc/src/snmp_app.xml @@ -763,12 +763,15 @@ - db_init_error() = terminate | create + db_init_error() = terminate | create | create_db_and_dir

Defines what to do if the agent or manager is unable to open an existing database file. terminate means that the agent/manager will terminate and create means that the - agent/manager will remove the faulty file(s) and create new ones.

+ agent/manager will remove the faulty file(s) and create new ones, + and create_db_and_dir means that the agent/manager will + create the database file along with any missing parent directories + for the database file.

Default is terminate.

diff --git a/lib/snmp/doc/src/snmp_config.xml b/lib/snmp/doc/src/snmp_config.xml index 61ee7f00ee..30b46e6aa8 100644 --- a/lib/snmp/doc/src/snmp_config.xml +++ b/lib/snmp/doc/src/snmp_config.xml @@ -792,12 +792,15 @@ in so far as it will be converted to the new format if found. - db_init_error() = terminate | create + db_init_error() = terminate | create | create_db_and_dir

Defines what to do if the agent is unable to open an existing database file. terminate means that the - agent/manager will terminate and create means that the - agent/manager will remove the faulty file(s) and create new ones.

+ agent/manager will terminate, create means that the + agent/manager will remove the faulty file(s) and create new ones, + and create_db_and_dir means that the agent/manager will + create the database file along with any missing parent directories + for the database file.

Default is terminate.

diff --git a/lib/snmp/src/agent/snmpa_local_db.erl b/lib/snmp/src/agent/snmpa_local_db.erl index 5198c6ec4e..a1e41257ce 100644 --- a/lib/snmp/src/agent/snmpa_local_db.erl +++ b/lib/snmp/src/agent/snmpa_local_db.erl @@ -191,6 +191,12 @@ dets_open(DbDir, DbInitError, Opts) -> end end; _ -> + case DbInitError of + create_db_and_dir -> + ok = filelib:ensure_dir(Filename); + _ -> + ok + end, case do_dets_open(Name, Filename, Opts) of {ok, Dets} -> ?vdebug("dets open done",[]), diff --git a/lib/snmp/src/agent/snmpa_supervisor.erl b/lib/snmp/src/agent/snmpa_supervisor.erl index aebcdbaa84..77ed54bee4 100644 --- a/lib/snmp/src/agent/snmpa_supervisor.erl +++ b/lib/snmp/src/agent/snmpa_supervisor.erl @@ -356,7 +356,7 @@ init([AgentType, Opts]) -> SymStoreSpec = worker_spec(snmpa_symbolic_store, SymStoreArgs, Restart, 2000), - LdbArgs = [Prio, DbDir, LdbOpts], + LdbArgs = [Prio, DbDir, DbInitError, LdbOpts], LocalDbSpec = worker_spec(snmpa_local_db, LdbArgs, Restart, 5000), diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 736debe544..2101ad46e1 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1215,6 +1215,12 @@ dets_open(Dir, DbInitError, Repair, AutoSave) -> end end; _ -> + case DbInitError of + create_db_and_dir -> + ok = filelib:ensure_dir(Filename); + _ -> + ok + end, case do_dets_open(Name, Filename, Repair, AutoSave) of {ok, _Dets} -> ok; @@ -1316,7 +1322,14 @@ verify_option({server, ServerOpts}) -> verify_server_opts(ServerOpts); verify_option({note_store, NoteStoreOpts}) -> verify_note_store_opts(NoteStoreOpts); -verify_option({config, ConfOpts}) -> +verify_option({config, ConfOpts0}) -> + %% Make sure any db_dir option is first in the options list to make it + %% easier to check if the db_init_error option specifies that a missing + %% db_dir should be created. + ConfOpts = case lists:keytake(db_dir, 1, ConfOpts0) of + false -> ConfOpts0; + {value, Result, OtherOpts} -> [Result|OtherOpts] + end, verify_config_opts(ConfOpts); verify_option({versions, Vsns}) -> verify_versions(Vsns); @@ -1365,7 +1378,12 @@ verify_config_opts([{dir, Dir}|Opts]) -> verify_conf_dir(Dir), verify_config_opts(Opts); verify_config_opts([{db_dir, Dir}|Opts]) -> - verify_conf_db_dir(Dir), + case lists:keyfind(db_init_error, 1, Opts) of + {db_init_error, create_db_and_dir} -> + verify_conf_db_dir(Dir, false); + _ -> + verify_conf_db_dir(Dir, true) + end, verify_config_opts(Opts); verify_config_opts([{db_init_error, DbInitErr}|Opts]) -> verify_conf_db_init_error(DbInitErr), @@ -1443,7 +1461,7 @@ verify_conf_dir(Dir) -> error({invalid_conf_dir, Dir}) end. -verify_conf_db_dir(Dir) -> +verify_conf_db_dir(Dir, true) -> case (catch verify_dir(Dir)) of ok -> ok; @@ -1451,13 +1469,16 @@ verify_conf_db_dir(Dir) -> error({invalid_conf_db_dir, Dir, Reason}); _ -> error({invalid_conf_db_dir, Dir}) - end. - + end; +verify_conf_db_dir(_Dir, false) -> + ok. verify_conf_db_init_error(terminate) -> ok; verify_conf_db_init_error(create) -> ok; +verify_conf_db_init_error(create_db_and_dir) -> + ok; verify_conf_db_init_error(InvalidDbInitError) -> error({invalid_conf_db_init_error, InvalidDbInitError}). diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 7e683e315a..b7d34eb198 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -34,6 +34,7 @@ %% all_tcs - misc app_info/1, info_test/1, + create_local_db_dir/1, %% all_tcs - test_v1 simple/1, @@ -1506,7 +1507,8 @@ finish_misc(Config) -> misc_cases() -> [ app_info, - info_test + info_test, + create_local_db_dir ]. app_info(suite) -> []; @@ -1539,7 +1541,75 @@ app_dir(App) -> "undefined" end. +create_local_db_dir(Config) when is_list(Config) -> + ?P(create_local_db_dir), + DataDir = snmp_test_lib:lookup(data_dir, Config), + T = erlang:now(), + [As,Bs,Cs] = [integer_to_list(I) || I <- tuple_to_list(T)], + DbDir = filename:join([DataDir, As, Bs, Cs]), + ok = del_dir(DbDir, 3), + Name = list_to_atom(atom_to_list(create_local_db_dir) + ++"-"++As++"-"++Bs++"-"++Cs), + Pa = filename:dirname(code:which(?MODULE)), + {ok,Node} = ?t:start_node(Name, slave, [{args, "-pa "++Pa}]), + + %% first start with a nonexisting DbDir + Fun1 = fun() -> + false = filelib:is_dir(DbDir), + process_flag(trap_exit,true), + {error, {error, {failed_open_dets, {file_error, _, _}}}} = + snmpa_local_db:start_link(normal, DbDir, [{verbosity,trace}]), + false = filelib:is_dir(DbDir), + {ok, not_found} + end, + {ok, not_found} = nodecall(Node, Fun1), + %% now start with a nonexisting DbDir but pass the + %% create_local_db_dir option as well + Fun2 = fun() -> + false = filelib:is_dir(DbDir), + process_flag(trap_exit,true), + {ok, _Pid} = + snmpa_local_db:start_link(normal, DbDir, + create_db_and_dir, [{verbosity,trace}]), + snmpa_local_db:stop(), + true = filelib:is_dir(DbDir), + {ok, found} + end, + {ok, found} = nodecall(Node, Fun2), + %% cleanup + ?t:stop_node(Node), + ok = del_dir(DbDir, 3), + ok. + +nodecall(Node, Fun) -> + Parent = self(), + Ref = make_ref(), + spawn_link(Node, + fun() -> + Res = Fun(), + unlink(Parent), + Parent ! {Ref, Res} + end), + receive + {Ref, Res} -> + Res + end. +del_dir(_Dir, 0) -> + ok; +del_dir(Dir, Depth) -> + case filelib:is_dir(Dir) of + true -> + {ok, Files} = file:list_dir(Dir), + lists:map(fun(F) -> + Nm = filename:join(Dir,F), + ok = file:delete(Nm) + end, Files), + ok = file:del_dir(Dir), + del_dir(filename:dirname(Dir), Depth-1); + false -> + ok + end. %v1_cases() -> [loop_mib]; v1_cases() -> diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index 3192fe1b40..a2733cd043 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -57,6 +57,7 @@ start_with_invalid_users_conf_file1/1, start_with_invalid_agents_conf_file1/1, start_with_invalid_usm_conf_file1/1, + start_with_create_db_and_dir_opt/1, @@ -139,8 +140,13 @@ init_per_testcase(Case, Config) when is_list(Config) -> file:make_dir(MgrTopDir = filename:join(CaseTopDir, "manager/")), ?line ok = file:make_dir(MgrConfDir = filename:join(MgrTopDir, "conf/")), - ?line ok = - file:make_dir(MgrDbDir = filename:join(MgrTopDir, "db/")), + MgrDbDir = filename:join(MgrTopDir, "db/"), + case Case of + start_with_create_db_and_dir_opt -> + ok; + _ -> + ?line ok = file:make_dir(MgrDbDir) + end, ?line ok = file:make_dir(MgrLogDir = filename:join(MgrTopDir, "log/")), [{case_top_dir, CaseTopDir}, @@ -174,6 +180,7 @@ groups() -> start_without_mandatory_opts2, start_with_all_valid_opts, start_with_unknown_opts, start_with_incorrect_opts, + start_with_create_db_and_dir_opt, start_with_invalid_manager_conf_file1, start_with_invalid_users_conf_file1, start_with_invalid_agents_conf_file1, @@ -332,7 +339,8 @@ start_with_all_valid_opts(Conf) when is_list(Conf) -> {no_reuse, false}]}], ServerOpts = [{timeout, 10000}, {verbosity, trace}], NoteStoreOpts = [{timeout, 20000}, {verbosity, trace}], - ConfigOpts = [{dir, ConfDir}, {verbosity, trace}, {db_dir, DbDir}], + ConfigOpts = [{dir, ConfDir}, {verbosity, trace}, + {db_dir, DbDir}, {db_init_error, create}], Mibs = [join(StdMibDir, "SNMP-NOTIFICATION-MIB"), join(StdMibDir, "SNMP-USER-BASED-SM-MIB")], Prio = normal, @@ -1674,7 +1682,34 @@ start_with_invalid_usm_conf_file1(Conf) when is_list(Conf) -> %% --- %% +start_with_create_db_and_dir_opt(suite) -> []; +start_with_create_db_and_dir_opt(doc) -> + "Start the snmp manager config process with the\n" + "create_db_and_dir option."; +start_with_create_db_and_dir_opt(Conf) when is_list(Conf) -> + put(tname, swcdado), + p("start"), + process_flag(trap_exit, true), + ConfDir = ?config(manager_conf_dir, Conf), + DbDir = ?config(manager_db_dir, Conf), + true = not filelib:is_dir(DbDir) and not filelib:is_file(DbDir), + write_manager_conf(ConfDir), + + p("verify nonexistent db_dir"), + ConfigOpts01 = [{verbosity,trace}, {dir, ConfDir}, {db_dir, DbDir}], + {error, Reason01} = config_start([{config, ConfigOpts01}]), + p("nonexistent db_dir res: ~p", [Reason01]), + {invalid_conf_db_dir, _, not_found} = Reason01, + p("verify nonexistent db_dir gets created"), + ConfigOpts02 = [{db_init_error, create_db_and_dir} | ConfigOpts01], + {ok, _Pid} = config_start([{config, ConfigOpts02}]), + true = filelib:is_dir(DbDir), + p("verified: nonexistent db_dir was correctly created"), + ok = config_stop(), + + p("done"), + ok. %% %% --- -- cgit v1.2.3 From a224a65376006e3228f2a1f394c1304a55beced5 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 24 Sep 2013 15:07:21 +0200 Subject: [snmp] Update the config utility function for db-init-error Update the config utility function (a simple cli for generating the snmp config files) to handle the new db_init_error value (create_db_and_dir). OTP-11352 --- lib/snmp/src/misc/snmp_config.erl | 187 ++++++++++++++++++++++---------------- 1 file changed, 107 insertions(+), 80 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 945b8719fc..a222f842e5 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -233,16 +233,18 @@ config_agent_sys() -> fun verify_verbosity/1), DbDir = ask("5. Database directory (absolute path)?", DefDir, fun verify_dir/1), - MibStorageType = ask("6. Mib storage type (ets/dets/mnesia)?", "ets", + DbInitError = ask("6. How to handle DB init error?", + "terminate", fun verify_db_init_error/1), + MibStorageType = ask("7. Mib storage type (ets/dets/mnesia)?", "ets", fun verify_mib_storage_type/1), MibStorage = case MibStorageType of ets -> [{module, snmpa_mib_storage_ets}]; dets -> - DetsDir = ask("6b. Mib storage directory (absolute path)?", + DetsDir = ask("7b. Mib storage directory (absolute path)?", DbDir, fun verify_dir/1), - DetsAction = ask("6c. Mib storage [dets] database start " + DetsAction = ask("7c. Mib storage [dets] database start " "action " "(default/clear/keep)?", "default", fun verify_mib_storage_action/1), @@ -257,7 +259,7 @@ config_agent_sys() -> end; mnesia -> Nodes = [], - MnesiaAction = ask("6b. Mib storage [mnesia] database start " + MnesiaAction = ask("7b. Mib storage [mnesia] database start " "action " "(default/clear/keep)?", "default", fun verify_mib_storage_action/1), @@ -275,80 +277,80 @@ config_agent_sys() -> %% Here we should ask about mib-server data module, %% but as we only have one at the moment... - TargetCacheVerb = ask("7. Target cache verbosity " + TargetCacheVerb = ask("8. Target cache verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - SymStoreVerb = ask("8. Symbolic store verbosity " + SymStoreVerb = ask("9. Symbolic store verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - LocalDbVerb = ask("9. Local DB verbosity " + LocalDbVerb = ask("10. Local DB verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - LocalDbRepair = ask("10. Local DB repair (true/false/force)?", "true", + LocalDbRepair = ask("11. Local DB repair (true/false/force)?", "true", fun verify_dets_repair/1), - LocalDbAutoSave = ask("11. Local DB auto save (infinity/milli seconds)?", + LocalDbAutoSave = ask("12. Local DB auto save (infinity/milli seconds)?", "5000", fun verify_dets_auto_save/1), - ErrorMod = ask("12. Error report module?", "snmpa_error_logger", fun verify_module/1), - Type = ask("13. Agent type (master/sub)?", "master", + ErrorMod = ask("13. Error report module?", "snmpa_error_logger", fun verify_module/1), + Type = ask("14. Agent type (master/sub)?", "master", fun verify_agent_type/1), AgentConfig = case Type of master -> - MasterAgentVerb = ask("14. Master-agent verbosity " + MasterAgentVerb = ask("15. Master-agent verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - ForceLoad = ask("15. Shall the agent re-read the " + ForceLoad = ask("16. Shall the agent re-read the " "configuration files during startup ~n" " (and ignore the configuration " "database) (true/false)?", "true", fun verify_bool/1), - MultiThreaded = ask("16. Multi threaded agent (true/false)?", + MultiThreaded = ask("17. Multi threaded agent (true/false)?", "false", fun verify_bool/1), - MeOverride = ask("17. Check for duplicate mib entries when " + MeOverride = ask("18. Check for duplicate mib entries when " "installing a mib (true/false)?", "false", fun verify_bool/1), - TrapOverride = ask("18. Check for duplicate trap names when " + TrapOverride = ask("19. Check for duplicate trap names when " "installing a mib (true/false)?", "false", fun verify_bool/1), - MibServerVerb = ask("19. Mib server verbosity " + MibServerVerb = ask("20. Mib server verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - MibServerCache = ask("20. Mib server cache " + MibServerCache = ask("21. Mib server cache " "(true/false)?", "true", fun verify_bool/1), - NoteStoreVerb = ask("21. Note store verbosity " + NoteStoreVerb = ask("22. Note store verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - NoteStoreTimeout = ask("22. Note store GC timeout?", "30000", + NoteStoreTimeout = ask("23. Note store GC timeout?", "30000", fun verify_timeout/1), ATL = - case ask("23. Shall the agent use an audit trail log " + case ask("24. Shall the agent use an audit trail log " "(y/n)?", "n", fun verify_yes_or_no/1) of yes -> - ATLType = ask("23b. Audit trail log type " + ATLType = ask("24b. Audit trail log type " "(write/read_write)?", "read_write", fun verify_atl_type/1), - ATLDir = ask("23c. Where to store the " + ATLDir = ask("24c. Where to store the " "audit trail log?", DefDir, fun verify_dir/1), - ATLMaxFiles = ask("23d. Max number of files?", + ATLMaxFiles = ask("24d. Max number of files?", "10", fun verify_pos_integer/1), - ATLMaxBytes = ask("23e. Max size (in bytes) " + ATLMaxBytes = ask("24e. Max size (in bytes) " "of each file?", "10240", fun verify_pos_integer/1), ATLSize = {ATLMaxBytes, ATLMaxFiles}, - ATLRepair = ask("23f. Audit trail log repair " + ATLRepair = ask("24f. Audit trail log repair " "(true/false/truncate/snmp_repair)?", "true", fun verify_atl_repair/1), - ATLSeqNo = ask("23g. Audit trail log " + ATLSeqNo = ask("24g. Audit trail log " "sequence-numbering (true/false)?", "false", fun verify_atl_seqno/1), @@ -360,33 +362,33 @@ config_agent_sys() -> no -> [] end, - NetIfVerb = ask("24. Network interface verbosity " + NetIfVerb = ask("25. Network interface verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - NetIfMod = ask("25. Which network interface module shall be used?", + NetIfMod = ask("26. Which network interface module shall be used?", "snmpa_net_if", fun verify_module/1), NetIfOpts = case NetIfMod of snmpa_net_if -> NetIfBindTo = - ask("25a. Bind the agent IP address " + ask("26a. Bind the agent IP address " "(true/false)?", "false", fun verify_bool/1), NetIfNoReuse = - ask("25b. Shall the agents " + ask("26b. Shall the agents " "IP address " "and port be not reusable " "(true/false)?", "false", fun verify_bool/1), NetIfReqLimit = - ask("25c. Agent request limit " + ask("26c. Agent request limit " "(used for flow control) " "(infinity/pos integer)?", "infinity", fun verify_netif_req_limit/1), NetIfRecbuf = - case ask("25d. Receive buffer size of the " + case ask("26d. Receive buffer size of the " "agent (in bytes) " "(default/pos integer)?", "default", @@ -397,7 +399,7 @@ config_agent_sys() -> [{recbuf, RecBufSz}] end, NetIfSndbuf = - case ask("25e. Send buffer size of the agent " + case ask("26e. Send buffer size of the agent " "(in bytes) (default/pos integer)?", "default", fun verify_netif_sndbuf/1) of @@ -407,7 +409,7 @@ config_agent_sys() -> [{sndbuf, SndBufSz}] end, NetIfFilter = - case ask("25f. Do you wish to specify a " + case ask("26f. Do you wish to specify a " "network interface filter module " "(or use default)", "default", fun verify_module/1) of @@ -426,18 +428,18 @@ config_agent_sys() -> NetIf = [{module, NetIfMod}, {verbosity, NetIfVerb}, {options, NetIfOpts}], - TermDiscoEnable = ask("26a. Allow terminating discovery " + TermDiscoEnable = ask("27. Allow terminating discovery " "(true/false)?", "true", fun verify_bool/1), TermDiscoConf = case TermDiscoEnable of true -> TermDiscoStage2 = - ask("26b. Second stage behaviour " + ask("27a. Second stage behaviour " "(discovery/plain)?", "discovery", fun verify_term_disco_behaviour/1), TermDiscoTrigger = - ask("26c. Trigger username " + ask("27b. Trigger username " "(default/a string)?", "default", fun verify_term_disco_trigger_username/1), [{enable, TermDiscoEnable}, @@ -448,7 +450,7 @@ config_agent_sys() -> {stage2, discovery}, {trigger_username, ""}] end, - OrigDiscoEnable = ask("27a. Allow originating discovery " + OrigDiscoEnable = ask("28. Allow originating discovery " "(true/false)?", "true", fun verify_bool/1), OrigDiscoConf = @@ -471,7 +473,7 @@ config_agent_sys() -> {verbosity, NoteStoreVerb}]}, {net_if, NetIf}] ++ ATL; sub -> - SubAgentVerb = ask("14. Sub-agent verbosity " + SubAgentVerb = ask("15. Sub-agent verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), @@ -480,11 +482,12 @@ config_agent_sys() -> {config, [{dir, ConfigDir}]}] end, SysConfig = - [{priority, Prio}, - {versions, Vsns}, - {db_dir, DbDir}, - {mib_storage, MibStorage}, - {target_cache, [{verbosity, TargetCacheVerb}]}, + [{priority, Prio}, + {versions, Vsns}, + {db_dir, DbDir}, + {db_init_error, DbInitError}, + {mib_storage, MibStorage}, + {target_cache, [{verbosity, TargetCacheVerb}]}, {symbolic_store, [{verbosity, SymStoreVerb}]}, {local_db, [{repair, LocalDbRepair}, {auto_save, LocalDbAutoSave}, @@ -630,19 +633,21 @@ config_manager_sys() -> fun verify_verbosity/1), ConfigDbDir = ask("5. Database directory (absolute path)?", DefDir, fun verify_dir/1), - ConfigDbRepair = ask("6. Database repair " + ConfigDbInitError = ask("6. How to handle DB init error?", + "terminate", fun verify_db_init_error/1), + ConfigDbRepair = ask("7. Database repair " "(true/false/force)?", "true", fun verify_dets_repair/1), - ConfigDbAutoSave = ask("7. Database auto save " + ConfigDbAutoSave = ask("8. Database auto save " "(infinity/milli seconds)?", "5000", fun verify_dets_auto_save/1), IRB = - case ask("8. Inform request behaviour (auto/user)?", + case ask("9. Inform request behaviour (auto/user)?", "auto", fun verify_irb/1) of auto -> auto; user -> - case ask("8b. Use default GC timeout" + case ask("9b. Use default GC timeout" "(default/seconds)?", "default", fun verify_irb_user/1) of default -> @@ -651,31 +656,31 @@ config_manager_sys() -> {user, IrbGcTo} end end, - ServerVerb = ask("9. Server verbosity " + ServerVerb = ask("10. Server verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - ServerTimeout = ask("10. Server GC timeout?", "30000", + ServerTimeout = ask("11. Server GC timeout?", "30000", fun verify_timeout/1), - NoteStoreVerb = ask("11. Note store verbosity " + NoteStoreVerb = ask("12. Note store verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - NoteStoreTimeout = ask("12. Note store GC timeout?", "30000", + NoteStoreTimeout = ask("13. Note store GC timeout?", "30000", fun verify_timeout/1), - NetIfMod = ask("13. Which network interface module shall be used?", + NetIfMod = ask("14. Which network interface module shall be used?", "snmpm_net_if", fun verify_module/1), - NetIfVerb = ask("14. Network interface verbosity " + NetIfVerb = ask("15. Network interface verbosity " "(silence/info/log/debug/trace)?", "silence", fun verify_verbosity/1), - NetIfBindTo = ask("15. Bind the manager IP address " + NetIfBindTo = ask("16. Bind the manager IP address " "(true/false)?", "false", fun verify_bool/1), - NetIfNoReuse = ask("16. Shall the manager IP address and port " + NetIfNoReuse = ask("17. Shall the manager IP address and port " "be not reusable (true/false)?", "false", fun verify_bool/1), NetIfRecbuf = - case ask("17. Receive buffer size of the manager (in bytes) " + case ask("18. Receive buffer size of the manager (in bytes) " "(default/pos integer)?", "default", fun verify_netif_recbuf/1) of default -> @@ -684,7 +689,7 @@ config_manager_sys() -> [{recbuf, RecBufSz}] end, NetIfSndbuf = - case ask("18. Send buffer size of the manager (in bytes) " + case ask("19. Send buffer size of the manager (in bytes) " "(default/pos integer)?", "default", fun verify_netif_sndbuf/1) of default -> @@ -700,28 +705,28 @@ config_manager_sys() -> {verbosity, NetIfVerb}, {options, NetIfOpts}], ATL = - case ask("19. Shall the manager use an audit trail log " + case ask("20. Shall the manager use an audit trail log " "(y/n)?", "n", fun verify_yes_or_no/1) of yes -> - ATLType = ask("19b. Audit trail log type " + ATLType = ask("20b. Audit trail log type " "(write/read_write)?", "read_write", fun verify_atl_type/1), - ATLDir = ask("19c. Where to store the " + ATLDir = ask("20c. Where to store the " "audit trail log?", DefDir, fun verify_dir/1), - ATLMaxFiles = ask("19d. Max number of files?", + ATLMaxFiles = ask("20d. Max number of files?", "10", fun verify_pos_integer/1), - ATLMaxBytes = ask("19e. Max size (in bytes) " + ATLMaxBytes = ask("20e. Max size (in bytes) " "of each file?", "10240", fun verify_pos_integer/1), ATLSize = {ATLMaxBytes, ATLMaxFiles}, - ATLRepair = ask("19f. Audit trail log repair " + ATLRepair = ask("20f. Audit trail log repair " "(true/false/truncate/snmp_repair)?", "true", fun verify_atl_repair/1), - ATLSeqNo = ask("19g. Audit trail log sequence-numbering " + ATLSeqNo = ask("20g. Audit trail log sequence-numbering " "(true/false)?", "false", fun verify_atl_seqno/1), [{audit_trail_log, [{type, ATLType}, @@ -733,14 +738,14 @@ config_manager_sys() -> [] end, DefUser = - case ask("20. Do you wish to assign a default user [yes] or use~n" + case ask("21. Do you wish to assign a default user [yes] or use~n" " the default settings [no] (y/n)?", "n", fun verify_yes_or_no/1) of yes -> - DefUserMod = ask("20b. Default user module?", + DefUserMod = ask("21b. Default user module?", "snmpm_user_default", fun verify_module/1), - DefUserData = ask("20c. Default user data?", "undefined", + DefUserData = ask("21c. Default user data?", "undefined", fun verify_user_data/1), [{def_user_mod, DefUserMod}, {def_user_data, DefUserData}]; @@ -750,11 +755,12 @@ config_manager_sys() -> SysConfig = [{priority, Prio}, {versions, Vsns}, - {config, [{dir, ConfigDir}, - {verbosity, ConfigVerb}, - {db_dir, ConfigDbDir}, - {repair, ConfigDbRepair}, - {auto_save, ConfigDbAutoSave}]}, + {config, [{dir, ConfigDir}, + {db_dir, ConfigDbDir}, + {db_init_error, ConfigDbInitError}, + {repair, ConfigDbRepair}, + {auto_save, ConfigDbAutoSave}, + {verbosity, ConfigVerb}]}, {inform_request_behaviour, IRB}, {mibs, []}, {server, [{timeout, ServerTimeout}, @@ -1069,6 +1075,16 @@ verify_dir(Dir) -> _E -> {error, "invalid directory (not absolute): " ++ Dir} end. + + +verify_db_init_error("terminate") -> + {ok, true}; +verify_db_init_error("create") -> + {ok, create}; +verify_db_init_error("create_db_and_dir") -> + {ok, create_db_and_dir}; +verify_db_init_error(R) -> + {error, "invalid DB init error: " ++ R}. verify_notif_type("trap") -> {ok, trap}; @@ -1164,13 +1180,20 @@ verify_dets_auto_save(I0) -> %% I know that this is a little of the edge, but... +verify_module(M) when is_atom(M) -> + {ok, M}; +verify_module(M0) when is_list(M0) -> + {ok, list_to_atom(M0)}; verify_module(M0) -> - case (catch list_to_atom(M0)) of - M when is_atom(M) -> - {ok, M}; - _ -> - {error, "invalid module: " ++ M0} - end. + {error, lists:flatten(io_lib:format("invalid module: ~p", [M0]))}. + +%% verify_module(M0) -> +%% case (catch list_to_atom(M0)) of +%% M when is_atom(M) -> +%% {ok, M}; +%% _ -> +%% {error, "invalid module: " ++ M0} +%% end. verify_agent_type("master") -> @@ -2168,6 +2191,8 @@ write_sys_config_file_agent_opt(Fid, {config, Opts}) -> ok = io:format(Fid, "}", []); write_sys_config_file_agent_opt(Fid, {db_dir, Dir}) -> ok = io:format(Fid, " {db_dir, \"~s\"}", [Dir]); +write_sys_config_file_agent_opt(Fid, {db_init_error, Action}) -> + ok = io:format(Fid, " {db_init_error, ~w}", [Action]); write_sys_config_file_agent_opt(Fid, {mib_storage, ets}) -> ok = io:format(Fid, " {mib_storage, ets}", []); write_sys_config_file_agent_opt(Fid, {mib_storage, {dets, Dir}}) -> @@ -2344,6 +2369,8 @@ write_sys_config_file_manager_config_opt(Fid, {dir, Dir}) -> ok = io:format(Fid, "{dir, \"~s\"}", [Dir]); write_sys_config_file_manager_config_opt(Fid, {db_dir, Dir}) -> ok = io:format(Fid, "{db_dir, \"~s\"}", [Dir]); +write_sys_config_file_manager_config_opt(Fid, {db_init_error, Action}) -> + ok = io:format(Fid, "{db_init_error, ~w}", [Action]); write_sys_config_file_manager_config_opt(Fid, {repair, Rep}) -> ok = io:format(Fid, "{repair, ~w}", [Rep]); write_sys_config_file_manager_config_opt(Fid, {auto_save, As}) -> -- cgit v1.2.3 From bf552c9138427070b1e17c6fc92f8972d8aef112 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 24 Sep 2013 11:55:21 +0200 Subject: [snmp] Add proper version, release nodes and appup Also fixed copyright end date. OTP-11352 --- lib/snmp/doc/src/notes.xml | 71 ++++++++++++++++++++++++++++++ lib/snmp/src/agent/snmpa_local_db.erl | 2 +- lib/snmp/src/app/snmp.appup.src | 42 +++--------------- lib/snmp/test/snmp_manager_config_test.erl | 2 +- lib/snmp/vsn.mk | 2 +- 5 files changed, 80 insertions(+), 39 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 7514c52dda..2b0daf897b 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,77 @@
+
+ SNMP Development Toolkit 4.25 +

Version 4.25 supports code replacement in runtime from/to + version 4.24.2, 4.24.1, 4.24, 4.23.1 and 4.23.

+ +
+ Improvements and new features + + + + +

Enable SNMP to create missing database directories.

+

Add + + {db_init_error, create_db_and_dir} option to SNMP + manager + and + agent. + This allows them to create any missing parent directories for + db_dir, rather than treating any missing directories + as a fatal error. + The default for db_init_error, which is terminate, + is unchanged.

+

Steve Vinoski

+

Own Id: OTP-11352

+
+ +
+ +
+ +
+ Fixed Bugs and Malfunctions +

-

+ + + +
+ +
+ Incompatibilities +

-

+ + +
+ +
+ +
SNMP Development Toolkit 4.24.2

Version 4.24.2 supports code replacement in runtime from/to diff --git a/lib/snmp/src/agent/snmpa_local_db.erl b/lib/snmp/src/agent/snmpa_local_db.erl index a1e41257ce..f991244287 100644 --- a/lib/snmp/src/agent/snmpa_local_db.erl +++ b/lib/snmp/src/agent/snmpa_local_db.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 6edcf7e833..e1bf7692b3 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -29,24 +29,9 @@ %% {add_module, snmpm_net_if_mt} [ - {"4.24.1", - [ - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, - {"4.24", - [ - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, - [snmp_conf]}, - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, + {"4.24.2", [{restart_application, snmp}]}, + {"4.24.1", [{restart_application, snmp}]}, + {"4.24", [{restart_application, snmp}]}, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ], @@ -57,24 +42,9 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ - {"4.24.1", - [ - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, - {"4.24", - [ - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, - [snmp_conf]}, - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, + {"4.24.2", [{restart_application, snmp}]}, + {"4.24.1", [{restart_application, snmp}]}, + {"4.24", [{restart_application, snmp}]}, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ] diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index a2733cd043..7b9924b83c 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2012. All Rights Reserved. +%% Copyright Ericsson AB 2004-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 2164121e86..70f7c2b19a 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.24.2 +SNMP_VSN = 4.25 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 7c65cac86c44c5f01d2d4fb9e24509e8cdbda313 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Wed, 9 Oct 2013 12:01:26 +0200 Subject: {snmp] Fixed include depend --- lib/snmp/src/app/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/Makefile b/lib/snmp/src/app/Makefile index 716add8b9e..b8cc4b8754 100644 --- a/lib/snmp/src/app/Makefile +++ b/lib/snmp/src/app/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2003-2012. All Rights Reserved. +# Copyright Ericsson AB 2003-2013. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -79,6 +79,8 @@ endif # FLAGS # ---------------------------------------------------- +ERL_COMPILE_FLAGS += -pa $(ERL_TOP)/lib/snmp/ebin + ifeq ($(WARN_UNUSED_VARS),true) ERL_COMPILE_FLAGS += +warn_unused_vars endif -- cgit v1.2.3 From 8402f78061bf0cb3283bd0028b98746ef730fe4a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 11 Oct 2013 12:13:52 +0200 Subject: [snmp] Add (atl) log conversion block option It is now possible to request that the Audit Trail Log should be blocked during conversion (log_to_txt or log_to_io). This could be usefull when coverting a large log (when there is a chance it may otherwise wrap during conversion). --- lib/snmp/src/agent/snmpa.erl | 195 ++++++++++++++++++++++++++++++++--- lib/snmp/src/app/snmp.erl | 73 ++++++++++--- lib/snmp/src/manager/snmpm.erl | 192 +++++++++++++++++++++++++++++++--- lib/snmp/src/misc/snmp_log.erl | 182 ++++++++++++++++++++++++++------ lib/snmp/src/misc/snmp_verbosity.erl | 4 +- lib/snmp/test/snmp_log_test.erl | 67 ++++++------ 6 files changed, 609 insertions(+), 104 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index a95e41ea42..3804966e61 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -85,11 +85,10 @@ -export([add_agent_caps/2, del_agent_caps/1, get_agent_caps/0]). %% Audit Trail Log functions --export([log_to_txt/1, - log_to_txt/2, log_to_txt/3, log_to_txt/4, - log_to_txt/5, log_to_txt/6, log_to_txt/7, - log_to_io/1, log_to_io/2, log_to_io/3, - log_to_io/4, log_to_io/5, log_to_io/6, +-export([log_to_txt/1, log_to_txt/2, log_to_txt/3, log_to_txt/4, + log_to_txt/5, log_to_txt/6, log_to_txt/7, log_to_txt/8, + log_to_io/1, log_to_io/2, log_to_io/3, log_to_io/4, + log_to_io/5, log_to_io/6, log_to_io/7, log_info/0, change_log_size/1, get_log_type/0, get_log_type/1, @@ -872,43 +871,207 @@ get_agent_caps() -> %%% Audit Trail Log functions %%%----------------------------------------------------------------- +-spec log_to_txt(LogDir :: snmp:dir()) -> + snmp:void(). + log_to_txt(LogDir) -> log_to_txt(LogDir, []). + +-spec log_to_txt(LogDir :: snmp:dir(), + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()]) -> + snmp:void(). + +log_to_txt(LogDir, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + Mibs = [], + OutFile = "snmpa_log.txt", + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); + log_to_txt(LogDir, Mibs) -> + Block = false, OutFile = "snmpa_log.txt", LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile). + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + OutFile = "snmpa_log.txt", + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile) -> + Block = false, + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, Block) + when ((Block =:= true) orelse (Block =:= false)) -> LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile). + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName) -> + Block = false, + LogFile = ?audit_trail_log_file, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, LogName, Block) + when ((Block =:= true) orelse (Block =:= false)) -> LogFile = ?audit_trail_log_file, - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile). + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile). + Block = false, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Start :: snmp_log:log_time()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start). + Block = false, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Block :: boolean(), + Start :: snmp_log:log_time()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Start :: snmp_log:log_time(), + Stop :: snmp_log:log_time()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) + when ((Block =:= true) orelse (Block =:= false)) -> + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start); + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop). + Block = false, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Block :: boolean(), + Start :: snmp_log:log_time(), + Stop :: snmp_log:log_time()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop) -> + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). log_to_io(LogDir) -> log_to_io(LogDir, []). + +log_to_io(LogDir, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + Mibs = [], + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs) -> + Block = false, LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, - snmp:log_to_io(LogDir, Mibs, LogName, LogFile). + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). + +log_to_io(LogDir, Mibs, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName) -> + Block = false, + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). + +log_to_io(LogDir, Mibs, LogName, Block) + when ((Block =:= true) orelse (Block =:= false)) -> LogFile = ?audit_trail_log_file, - snmp:log_to_io(LogDir, Mibs, LogName, LogFile). + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName, LogFile) -> - snmp:log_to_io(LogDir, Mibs, LogName, LogFile). + Block = false, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> - snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Start). + Block = false, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) + when ((Block =:= true) orelse (Block =:= false)) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start); log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> - snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop). + Block = false, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). log_info() -> diff --git a/lib/snmp/src/app/snmp.erl b/lib/snmp/src/app/snmp.erl index 1bb562654a..967afa0e08 100644 --- a/lib/snmp/src/app/snmp.erl +++ b/lib/snmp/src/app/snmp.erl @@ -49,8 +49,8 @@ read_mib/1, - log_to_txt/5, log_to_txt/6, log_to_txt/7, - log_to_io/4, log_to_io/5, log_to_io/6, + log_to_txt/5, log_to_txt/6, log_to_txt/7, log_to_txt/8, + log_to_io/4, log_to_io/5, log_to_io/6, log_to_io/7, change_log_size/2, octet_string_to_bits/1, bits_to_octet_string/1, @@ -91,7 +91,10 @@ ]). -export_type([ + dir/0, + oid/0, + mib_name/0, void/0 ]). @@ -155,8 +158,10 @@ %% Types %%----------------------------------------------------------------- --type oid() :: [non_neg_integer()]. --type void() :: term(). +-type oid() :: [non_neg_integer()]. +-type void() :: term(). +-type dir() :: string(). +-type mib_name() :: string(). %%----------------------------------------------------------------- @@ -854,18 +859,60 @@ read_mib(FileName) -> %%%----------------------------------------------------------------- log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> - snmp_log:log_to_txt(LogName, LogFile, LogDir, Mibs, OutFile). + Block = false, + Start = null, + Stop = null, + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + Start = null, + Stop = null, + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> - snmp_log:log_to_txt(LogName, LogFile, LogDir, Mibs, OutFile, Start). + Block = false, + Stop = null, + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) + when ((Block =:= true) orelse (Block =:= false)) -> + Stop = null, + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> - snmp_log:log_to_txt(LogName, LogFile, LogDir, Mibs, OutFile, Start, Stop). + Block = false, + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop) -> + snmp_log:log_to_txt(LogName, Block, LogFile, LogDir, Mibs, OutFile, + Start, Stop). + log_to_io(LogDir, Mibs, LogName, LogFile) -> - snmp_log:log_to_io(LogName, LogFile, LogDir, Mibs). + Block = false, + Start = null, + Stop = null, + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + Start = null, + Stop = null, + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop); log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> - snmp_log:log_to_io(LogName, LogFile, LogDir, Mibs, Start). + Block = false, + Stop = null, + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) + when ((Block =:= true) orelse (Block =:= false)) -> + Stop = null, + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop); log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> - snmp_log:log_to_io(LogName, LogFile, LogDir, Mibs, Start, Stop). + Block = false, + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> + snmp_log:log_to_io(LogName, Block, LogFile, LogDir, Mibs, Start, Stop). change_log_size(LogName, NewSize) -> snmp_log:change_size(LogName, NewSize). @@ -878,12 +925,12 @@ change_log_size(LogName, NewSize) -> %% Usage: erl -s snmp str_apply '{Mod,Func,ArgList}' str_apply([Atom]) -> Str = atom_to_list(Atom), - {Mod,Func,Args} = to_erlang_term(Str), - apply(Mod,Func,Args). + {Mod, Func, Args} = to_erlang_term(Str), + apply(Mod, Func, Args). to_erlang_term(String) -> {ok, Tokens, _} = erl_scan:string(lists:append([String, ". "])), - {ok,Term} = erl_parse:parse_term(Tokens), + {ok, Term} = erl_parse:parse_term(Tokens), Term. diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 6ac0115dad..a749153ece 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2012. All Rights Reserved. +%% Copyright Ericsson AB 2004-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -75,11 +75,10 @@ %% %% Logging - log_to_txt/1, - log_to_txt/2, log_to_txt/3, log_to_txt/4, - log_to_txt/5, log_to_txt/6, log_to_txt/7, - log_to_io/1, log_to_io/2, log_to_io/3, - log_to_io/4, log_to_io/5, log_to_io/6, + log_to_txt/1, log_to_txt/2, log_to_txt/3, log_to_txt/4, + log_to_txt/5, log_to_txt/6, log_to_txt/7, log_to_txt/8, + log_to_io/1, log_to_io/2, log_to_io/3, log_to_io/4, + log_to_io/5, log_to_io/6, log_to_io/7, change_log_size/1, get_log_type/0, set_log_type/1, @@ -762,43 +761,204 @@ cancel_async_request(UserId, ReqId) -> %%% Audit Trail Log functions (for backward compatibility) %%%----------------------------------------------------------------- +-spec log_to_txt(LogDir :: snmp:dir()) -> + snmp:void(). + log_to_txt(LogDir) -> log_to_txt(LogDir, []). + +-spec log_to_txt(LogDir :: snmp:dir(), + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()]) -> + snmp:void(). + +log_to_txt(LogDir, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + Mibs = [], + OutFile = "snmpm_log.txt", + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs) -> + Block = false, + OutFile = "snmpm_log.txt", + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, Block) + when ((Block =:= true) orelse (Block =:= false)) -> OutFile = "snmpm_log.txt", LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile). + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile) -> + Block = false, + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, Block) + when ((Block =:= true) orelse (Block =:= false)) -> LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile). + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName) -> + Block = false, LogFile = ?audit_trail_log_file, - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile). + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, LogName, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + LogFile = ?audit_trail_log_file, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile). + Block = false, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Block :: boolean()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Start :: snmp_log:log_time()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start). + Block = false, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Block :: boolean(), + Start :: snmp_log:log_time()) -> + snmp:void(); + (LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Start :: snmp_log:log_time(), + Stop :: snmp_log:log_time()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) + when ((Block =:= true) orelse (Block =:= false)) -> + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> - snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop). + Block = false, + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). + +-spec log_to_txt(LogDir :: snmp:dir(), + Mibs :: [snmp:mib_name()], + OutFile :: file:filename(), + LogName :: string(), + LogFile :: string(), + Block :: boolean(), + Start :: snmp_log:log_time(), + Stop :: snmp_log:log_time()) -> + snmp:void(). + +log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop) -> + snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). log_to_io(LogDir) -> log_to_io(LogDir, []). + +log_to_io(LogDir, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + Mibs = [], + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs) -> LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile). + +log_to_io(LogDir, Mibs, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + LogName = ?audit_trail_log_name, + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName) -> + Block = false, LogFile = ?audit_trail_log_file, - snmp:log_to_io(LogDir, Mibs, LogName, LogFile). + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). + +log_to_io(LogDir, Mibs, LogName, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + LogFile = ?audit_trail_log_file, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName, LogFile) -> - snmp:log_to_io(LogDir, Mibs, LogName, LogFile). + Block = false, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block) + when ((Block =:= true) orelse (Block =:= false)) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> - snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Start). + Block = false, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) + when ((Block =:= true) orelse (Block =:= false)) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start); log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> - snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop). + Block = false, + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). + +log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> + snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). change_log_size(NewSize) -> diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index a8c5df0b64..04ce2c0530 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2012. All Rights Reserved. +%% Copyright Ericsson AB 1997-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -24,8 +24,8 @@ create/4, create/5, create/6, open/1, open/2, change_size/2, close/1, sync/1, info/1, log/4, - log_to_txt/5, log_to_txt/6, log_to_txt/7, - log_to_io/4, log_to_io/5, log_to_io/6 + log_to_txt/6, log_to_txt/7, log_to_txt/8, + log_to_io/5, log_to_io/6, log_to_io/7 ]). -export([ upgrade/1, upgrade/2, @@ -34,7 +34,17 @@ -export([ validate/1, validate/2 ]). +%% +-export([ + log_to_txt/5, + log_to_io/4 + ]). +%% +-export_type([ + log/0, + log_time/0 + ]). -define(SNMP_USE_V3, true). -include("snmp_types.hrl"). @@ -48,6 +58,17 @@ -record(snmp_log, {id, seqno}). +%%----------------------------------------------------------------- +%% Types +%%----------------------------------------------------------------- + +-opaque log() :: #snmp_log{}. +-type log_time() :: null | + calendar:datetime() | + {local_time, calendar:datetime()} | + {universal_time, calendar:datetime()}. + + %% -------------------------------------------------------------------- %% Exported functions %% -------------------------------------------------------------------- @@ -322,6 +343,11 @@ validate_loop(Error, _Log, _Write, _PrevTS, _PrevSN) -> %% log(Log, Packet, Addr, Port) %%----------------------------------------------------------------- +-spec log(Log :: log(), + Packet :: binary() | {v3_header(), ScopedPDU :: list()}, + Addr :: inet:ip_address(), + Port :: inet:port_number()) -> + ok | {error, Reason :: term()}. log(#snmp_log{id = Log, seqno = SeqNo}, Packet, Addr, Port) -> ?vtrace("log -> entry with" @@ -378,53 +404,86 @@ do_change_size(Log, NewSize) -> %% -- log_to_txt --- +%% log_to_txt(Log, FileName, Dir, Mibs, TextFile) -> - log_to_txt(Log, FileName, Dir, Mibs, TextFile, null, null). + log_to_txt(Log, false, FileName, Dir, Mibs, TextFile). +%% +log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile) + when ((Block =:= true) orelse (Block =:= false)) -> + log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, null, null); +%% log_to_txt(Log, FileName, Dir, Mibs, TextFile, Start) -> - log_to_txt(Log, FileName, Dir, Mibs, TextFile, Start, null). - -log_to_txt(Log, FileName, Dir, Mibs, TextFile, Start, Stop) - when is_list(Mibs) andalso is_list(TextFile) -> + log_to_txt(Log, false, FileName, Dir, Mibs, TextFile, Start, null). +%% + +log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start) + when ((Block =:= true) orelse (Block =:= false)) -> + log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start, null); +%% +log_to_txt(Log, FileName, Dir, Mibs, TextFile, Start, Stop) -> + log_to_txt(Log, false, FileName, Dir, Mibs, TextFile, Start, Stop). +%% + +log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start, Stop) + when (((Block =:= true) orelse (Block =:= false)) andalso + is_list(Mibs) andalso is_list(TextFile)) -> ?vtrace("log_to_txt -> entry with" "~n Log: ~p" + "~n Block: ~p" "~n FileName: ~p" "~n Dir: ~p" "~n Mibs: ~p" "~n TextFile: ~p" "~n Start: ~p" "~n Stop: ~p", - [Log, FileName, Dir, Mibs, TextFile, Start, Stop]), + [Log, Block, FileName, Dir, Mibs, TextFile, Start, Stop]), File = filename:join(Dir, FileName), Converter = fun(L) -> do_log_to_file(L, TextFile, Mibs, Start, Stop) end, - log_convert(Log, File, Converter). + log_convert(Log, Block, File, Converter). %% -- log_to_io --- +%% log_to_io(Log, FileName, Dir, Mibs) -> - log_to_io(Log, FileName, Dir, Mibs, null, null). + log_to_io(Log, false, FileName, Dir, Mibs, null, null). +%% +log_to_io(Log, Block, FileName, Dir, Mibs) + when ((Block =:= true) orelse (Block =:= false)) -> + log_to_io(Log, Block, FileName, Dir, Mibs, null, null); +%% log_to_io(Log, FileName, Dir, Mibs, Start) -> - log_to_io(Log, FileName, Dir, Mibs, Start, null). - -log_to_io(Log, FileName, Dir, Mibs, Start, Stop) + log_to_io(Log, false, FileName, Dir, Mibs, Start, null). +%% + +log_to_io(Log, Block, FileName, Dir, Mibs, Start) + when ((Block =:= true) orelse (Block =:= false)) -> + log_to_io(Log, Block, FileName, Dir, Mibs, Start, null); +%% +log_to_io(Log, FileName, Dir, Mibs, Start, Stop) -> + log_to_io(Log, false, FileName, Dir, Mibs, Start, Stop). +%% + +log_to_io(Log, Block, FileName, Dir, Mibs, Start, Stop) when is_list(Mibs) -> ?vtrace("log_to_io -> entry with" "~n Log: ~p" + "~n Block: ~p" "~n FileName: ~p" "~n Dir: ~p" "~n Mibs: ~p" "~n Start: ~p" "~n Stop: ~p", - [Log, FileName, Dir, Mibs, Start, Stop]), + [Log, Block, FileName, Dir, Mibs, Start, Stop]), File = filename:join(Dir, FileName), Converter = fun(L) -> do_log_to_io(L, Mibs, Start, Stop) end, - log_convert(Log, File, Converter). + log_convert(Log, Block, File, Converter). %% -------------------------------------------------------------------- @@ -433,53 +492,118 @@ log_to_io(Log, FileName, Dir, Mibs, Start, Stop) %% -- log_convert --- -log_convert(#snmp_log{id = Log}, File, Converter) -> - do_log_convert(Log, File, Converter); -log_convert(Log, File, Converter) -> - do_log_convert(Log, File, Converter). +log_convert(#snmp_log{id = Log}, Block, File, Converter) -> + do_log_convert(Log, Block, File, Converter); +log_convert(Log, Block, File, Converter) -> + do_log_convert(Log, Block, File, Converter). -do_log_convert(Log, File, Converter) -> +do_log_convert(Log, Block, File, Converter) -> %% ?vtrace("do_log_converter -> entry with" - %% "~n Log: ~p" - %% "~n File: ~p" - %% "~n disk_log:info(Log): ~p", [Log, File, disk_log:info(Log)]), + %% "~n Log: ~p" + %% "~n Block: ~p" + %% "~n File: ~p" + %% "~n disk_log:info(Log): ~p", + %% [Log, Block, File, disk_log:info(Log)]), + Verbosity = get(verbosity), {Pid, Ref} = erlang:spawn_monitor( fun() -> - Result = do_log_convert2(Log, File, Converter), + put(sname, lc), + put(verbosity, Verbosity), + Result = do_log_convert2(Log, Block, File, Converter), exit(Result) end), receive {'DOWN', Ref, process, Pid, Result} -> %% ?vtrace("do_log_converter -> received result" - %% "~n Result: ~p" + %% "~n Result: ~p" %% "~n disk_log:info(Log): ~p", %% [Result, disk_log:info(Log)]), Result end. -do_log_convert2(Log, File, Converter) -> +do_log_convert2(Log, Block, File, Converter) -> + + %% ?vtrace("do_log_converter2 -> entry with" + %% "~n Log: ~p" + %% "~n Block: ~p" + %% "~n File: ~p" + %% "~n disk_log:info(Log): ~p", + %% [Log, Block, File, disk_log:info(Log)]), + %% First check if the caller process has already opened the %% log, because if we close an already open log we will cause %% a runtime error. + case is_owner(Log) of true -> - Converter(Log); + ?vtrace("do_log_converter2 -> convert an already owned log", []), + maybe_block(Log, Block), + Res = Converter(Log), + maybe_unblock(Log, Block), + Res; false -> %% Not yet member of the ruling party, apply for membership... + ?vtrace("do_log_converter2 -> convert log", []), case log_open(Log, File) of {ok, _} -> + ?vtrace("do_log_converter2 -> " + "convert (the now opened) log", []), + maybe_block(Log, Block), Res = Converter(Log), + maybe_unblock(Log, Block), disk_log:close(Log), Res; {error, {name_already_open, _}} -> - Converter(Log); + ?vtrace("do_log_converter2 -> " + "convert (an already opened) log", []), + maybe_block(Log, Block), + Res = Converter(Log), + maybe_unblock(Log, Block), + Res; {error, Reason} -> + ?vinfo("do_log_converter2 -> " + "failed converting log - open failed: " + "~n Reason: ~p", [Reason]), {error, {Log, Reason}} end end. +maybe_block(_Log, false = _Block) -> + %% ?vtrace("maybe_block(false) -> entry", []), + ok; +maybe_block(Log, true = _Block) -> + %% ?vtrace("maybe_block(true) -> entry when" + %% "~n Log Status: ~p", [log_status(Log)]), + Res = disk_log:block(Log, true), + %% ?vtrace("maybe_block(true) -> " + %% "~n Log Status: ~p" + %% "~n Res: ~p", [log_status(Log), Res]), + Res. + +maybe_unblock(_Log, false = _Block) -> + %% ?vtrace("maybe_unblock(false) -> entry", []), + ok; +maybe_unblock(Log, true = _Block) -> + %% ?vtrace("maybe_unblock(true) -> entry when" + %% "~n Log Status: ~p", [log_status(Log)]), + Res = disk_log:unblock(Log), + %% ?vtrace("maybe_unblock(true) -> " + %% "~n Log Status: ~p" + %% "~n Res: ~p", [log_status(Log), Res]), + Res. + +log_status(Log) -> + Info = disk_log:info(Log), + case lists:keysearch(status, 1, Info) of + {value, {status, Status}} -> + Status; + false -> + undefined + end. + + %% -- do_log_to_text --- do_log_to_file(Log, TextFile, Mibs, Start, Stop) -> diff --git a/lib/snmp/src/misc/snmp_verbosity.erl b/lib/snmp/src/misc/snmp_verbosity.erl index df5986b7bc..e5ff3daf91 100644 --- a/lib/snmp/src/misc/snmp_verbosity.erl +++ b/lib/snmp/src/misc/snmp_verbosity.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2012. All Rights Reserved. +%% Copyright Ericsson AB 2000-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -148,6 +148,8 @@ image_of_sname(mnifl) -> "M-NET-IF-LOGGER"; image_of_sname(mnifw) -> io_lib:format("M-NET-IF-worker(~p)", [self()]); image_of_sname(mconf) -> "M-CONF"; +image_of_sname(lc) -> io_lib:format("LOG-CONVERTER(~p)", [self()]); + image_of_sname(mgr) -> "MGR"; image_of_sname(mgr_misc) -> "MGR_MISC"; diff --git a/lib/snmp/test/snmp_log_test.erl b/lib/snmp/test/snmp_log_test.erl index e9345b44cc..cbd843b8fe 100644 --- a/lib/snmp/test/snmp_log_test.erl +++ b/lib/snmp/test/snmp_log_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2012. All Rights Reserved. +%% Copyright Ericsson AB 2003-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -365,7 +365,7 @@ log_to_io1(Config) when is_list(Config) -> display_info(Info), ?DBG("log_to_io1 -> do the convert to io (stdout)", []), - ? line ok = snmp_log:log_to_io(Log, File, Dir, []), + ? line ok = snmp:log_to_io(Dir, [], Name, File, false), ?DBG("log_to_io1 -> close log", []), ?line ok = snmp_log:close(Log), @@ -377,7 +377,7 @@ log_to_io1(Config) when is_list(Config) -> %%====================================================================== %% Start a logger-process that logs messages with a certain interval. %% Start a reader-process that reads messages from the log at a certain -%% point of time. +%% point in time. log_to_io2(suite) -> []; log_to_io2(doc) -> "Log to io from a different process than which " @@ -414,13 +414,13 @@ log_to_io2(Config) when is_list(Config) -> log_reader_log_to(Reader, fun() -> I = disk_log:info(Log), - R = snmp_log:log_to_io(Log, File, Dir, []), + R = snmp:log_to_io(Dir, [], Name, File, true), {R, I} end), case Res of - {ok, Info} -> - ?DBG("log_to_io2 -> ~n Info: ~p", [Info]), + {ok, _Info} -> + ?DBG("log_to_io2 -> ~n Info: ~p", [_Info]), ok; {Error, Info} -> ?DBG("log_to_io2 -> log to io failed: " @@ -520,14 +520,21 @@ log_to_txt(Name, SeqNoGen, Config) when is_list(Config) -> ?line {ok, Info} = snmp_log:info(Log), display_info(Info), - Out1 = join(Dir, "snmp_text-1.txt"), - ?DBG("log_to_txt -> do the convert to a text file when" - "~n Out1: ~p", [Out1]), - ?line ok = snmp:log_to_txt(Dir, [], Out1, Log, File), + Out1a = join(Dir, "snmp_text-1-unblocked.txt"), + ?DBG("log_to_txt -> do the convert to a text file (~s) unblocked", [Out1a]), + ?line ok = snmp:log_to_txt(Dir, [], Out1a, Log, File, false), + + ?line {ok, #file_info{size = Size1a}} = file:read_file_info(Out1a), + ?DBG("log_to_txt -> text file size: ~p", [Size1a]), + validate_size(Size1a), - ?line {ok, #file_info{size = Size1}} = file:read_file_info(Out1), - ?DBG("log_to_txt -> text file size: ~p", [Size1]), - validate_size(Size1), + Out1b = join(Dir, "snmp_text-1-blocked.txt"), + ?DBG("log_to_txt -> do the convert to a text file (~s) blocked", [Out1b]), + ?line ok = snmp:log_to_txt(Dir, [], Out1b, Log, File, true), + + ?line {ok, #file_info{size = Size1b}} = file:read_file_info(Out1b), + ?DBG("log_to_txt -> text file size: ~p", [Size1b]), + validate_size(Size1b, {eq, Size1a}), Out2 = join(Dir, "snmp_text-2.txt"), ?DBG("log_to_txt -> do the convert to a text file when" @@ -538,7 +545,7 @@ log_to_txt(Name, SeqNoGen, Config) when is_list(Config) -> ?line {ok, #file_info{size = Size2}} = file:read_file_info(Out2), ?DBG("log_to_txt -> text file size: ~p", [Size2]), - validate_size(Size2, {le, Size1}), + validate_size(Size2, {le, Size1a}), %% Calculate new start / stop times... GStart = calendar:datetime_to_gregorian_seconds(Start), @@ -568,7 +575,7 @@ log_to_txt(Name, SeqNoGen, Config) when is_list(Config) -> ?line {ok, #file_info{size = Size3}} = file:read_file_info(Out3), ?DBG("log_to_txt -> text file size: ~p", [Size3]), - validate_size(Size3, {l, Size1}), + validate_size(Size3, {l, Size1a}), ?DBG("log_to_txt -> close log", []), ?line ok = snmp_log:close(Log), @@ -637,8 +644,8 @@ log_to_txt3(Config) when is_list(Config) -> end), case Res of - {ok, Info} -> - ?DBG("log_to_txt3 -> ~n Info: ~p", [Info]), + {ok, _Info} -> + ?DBG("log_to_txt3 -> ~n Info: ~p", [_Info]), ?line {ok, #file_info{size = FileSize}} = file:read_file_info(TxtFile), ?DBG("log_to_txt3 -> text file size: ~p", [FileSize]), @@ -667,6 +674,8 @@ validate_size(_) -> validate_size(0, _) -> ?FAIL(invalid_size); +validate_size(A, {eq, A}) -> + ok; validate_size(A, {le, B}) when A =< B -> ok; validate_size(A, {l, B}) when A < B -> @@ -695,11 +704,11 @@ log_writer_start(Name, File, Size, Repair) -> log_writer_stop(Pid) -> Pid ! {stop, self()}, - T1 = t(), + _T1 = t(), receive {'EXIT', Pid, normal} -> - T2 = t(), - ?DBG("it took ~w ms to stop the writer", [T2 - T1]), + _T2 = t(), + ?DBG("it took ~w ms to stop the writer", [_T2 - _T1]), ok after 60000 -> Msg = receive Any -> Any after 0 -> nothing end, @@ -712,11 +721,11 @@ log_writer_info(Pid) -> log_writer_sleep(Pid, Time) -> Pid ! {sleep, Time, self()}, - T1 = t(), + _T1 = t(), receive {sleeping, Pid} -> - T2 = t(), - ?DBG("it took ~w ms to put the writer to sleep", [T2 - T1]), + _T2 = t(), + ?DBG("it took ~w ms to put the writer to sleep", [_T2 - _T1]), ok; {'EXIT', Pid, Reason} -> {error, Reason} @@ -784,11 +793,11 @@ lp(F, A) -> log_reader_start() -> Pid = spawn_link(?MODULE, log_reader_main, [self()]), - T1 = t(), + _T1 = t(), receive {started, Pid} -> - T2 = t(), - ?DBG("it took ~w ms to start the reader", [T2 - T1]), + _T2 = t(), + ?DBG("it took ~w ms to start the reader", [_T2 - _T1]), {ok, Pid}; {'EXIT', Pid, Reason} -> {error, Reason} @@ -798,11 +807,11 @@ log_reader_start() -> log_reader_stop(Pid) -> Pid ! {stop, self()}, - T1 = t(), + _T1 = t(), receive {'EXIT', Pid, normal} -> - T2 = t(), - ?DBG("it took ~w ms to put the reader to eleep", [T2 - T1]), + _T2 = t(), + ?DBG("it took ~w ms to put the reader to eleep", [_T2 - _T1]), ok after 1000 -> Msg = receive Any -> Any after 0 -> nothing end, -- cgit v1.2.3 From 08b6fcf4c00deb2efb7ddb759b430ab7effa3cc8 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 11 Oct 2013 13:06:19 +0200 Subject: [snmp] Updated release notes, ref man, appup and assigned proper version --- lib/snmp/doc/src/notes.xml | 72 +++++++++++++++++++++++++++++++++++++++++ lib/snmp/doc/src/snmpa.xml | 48 +++++++++++++++++---------- lib/snmp/doc/src/snmpm.xml | 45 ++++++++++++++++---------- lib/snmp/src/app/snmp.appup.src | 42 ++++-------------------- lib/snmp/src/misc/snmp_log.erl | 22 +++++-------- lib/snmp/vsn.mk | 2 +- 6 files changed, 146 insertions(+), 85 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 7514c52dda..1b954a5294 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,78 @@

+
+ SNMP Development Toolkit 4.25 +

Version 4.25 supports code replacement in runtime from/to + version 2.24.2, 4.24.1, 4.24, 4.23.1 and 4.23.

+ +
+ Improvements and new features + + + + +

Add (atl) log conversion block option.

+

It is now possible to request that the Audit Trail Log should + be blocked during conversion (log_to_txt or log_to_io). + This could be usefull when coverting a large log (when there is + a chance it may otherwise wrap during conversion).

+

See + agent + log_to_txt and + log_to_io and also + manager + log_to_txt and + log_to_io + for details.

+

Own Id: OTP-11396

+

Own Id: seq12433

+
+ +
+ +
+ +
+ Fixed Bugs and Malfunctions +

-

+ + + +
+ +
+ Incompatibilities +

-

+ + +
+ +
+ +
SNMP Development Toolkit 4.24.2

Version 4.24.2 supports code replacement in runtime from/to diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index 77146f3a89..29e8869401 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -4,7 +4,7 @@

- 20042012 + 20042013 Ericsson AB. All Rights Reserved. @@ -557,32 +557,39 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} log_to_txt(LogDir) - log_to_txt(LogDir, Mibs) - log_to_txt(LogDir, Mibs, OutFile) -> ok | {error, Reason} - log_to_txt(LogDir, Mibs, OutFile, LogName) -> ok | {error, Reason} - log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> ok | {error, Reason} - log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> ok | {error, Reason} + log_to_txt(LogDir, Block | Mibs) + log_to_txt(LogDir, Mibs, Block | OutFile) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, Block | LogName) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, Block | LogFile) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block | Start) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) -> ok | {error, Reason} log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop) -> ok | {error, Reason} Convert an Audit Trail Log to text format LogDir = string() Mibs = [MibName] MibName = string() + Block = block() OutFile = string() LogName = string() LogFile = string() - Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()} + Start = Stop = null | calendar:datetime() | {local_time, calendar:datetime()} | {universal_time, calendar:datetime()} Reason = disk_log_open_error() | file_open_error() | term() disk_log_open_error() = {LogName, term()} file_open_error() = {OutFile, term()}

Converts an Audit Trail Log to a readable text file. - OutFile defaults to "./snmpa_log.txt". - LogName defaults to "snmpa_log". - LogFile defaults to "snmpa.log". - See snmp:log_to_txt - for more info.

+ OutFile defaults to "./snmpa_log.txt". + LogName defaults to "snmpa_log". + LogFile defaults to "snmpa.log".

+

The Block option indicates if the log should be blocked + during conversion. This could be usefull when converting large + logs (when otherwise the log could wrap during conversion). + Defaults to false.

+

See snmp:log_to_txt + for more info.

@@ -590,19 +597,22 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} log_to_io(LogDir) -> ok | {error, Reason} - log_to_io(LogDir, Mibs) -> ok | {error, Reason} - log_to_io(LogDir, Mibs, LogName) -> ok | {error, Reason} - log_to_io(LogDir, Mibs, LogName, LogFile) -> ok | {error, Reason} - log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> ok | {error, Reason} + log_to_io(LogDir, Block | Mibs) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, Block | LogName) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, Block | LogFile) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Block | Start) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) -> ok | {error, Reason} log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> ok | {error, Reason} Convert an Audit Trail Log to text format LogDir = string() Mibs = [MibName] MibName = string() + Block = block() LogName = string() LogFile = string() - Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()} + Start = Stop = null | calendar:datetime() | {local_time, calendar:datetime()} | {universal_time, calendar:datetime()} Reason = disk_log_open_error() | file_open_error() | term() disk_log_open_error() = {LogName, term()} file_open_error() = {OutFile, term()} @@ -612,6 +622,10 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} prints it on stdio. LogName defaults to "snmpa_log". LogFile defaults to "snmpa.log". +

The Block option indicates if the log should be blocked + during conversion. This could be usefull when converting large + logs (when otherwise the log could wrap during conversion). + Defaults to false.

See snmp:log_to_io for more info.

diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index 07fdd208ff..f7b7e6220e 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -4,7 +4,7 @@
- 20042012 + 20042013 Ericsson AB. All Rights Reserved. @@ -1209,32 +1209,40 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 - log_to_txt(LogDir, Mibs) - log_to_txt(LogDir, Mibs, OutFile) -> ok | {error, Reason} - log_to_txt(LogDir, Mibs, OutFile, LogName) -> ok | {error, Reason} - log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> ok | {error, Reason} - log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> ok | {error, Reason} + log_to_txt(LogDir) + log_to_txt(LogDir, Block | Mibs) + log_to_txt(LogDir, Mibs, Block | OutFile) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, Block | LogName) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, Block | LogFile) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block | Start) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) -> ok | {error, Reason} log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop) -> ok | {error, Reason} Convert an Audit Trail Log to text format LogDir = string() Mibs = [MibName] MibName = string() + Block = block() OutFile = string() LogName = string() LogFile = string() - Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()} + Start = Stop = null | calendar:datetime() | {local_time, calendar:datetime()} | {universal_time, calendar:datetime()} Reason = disk_log_open_error() | file_open_error() | term() disk_log_open_error() = {LogName, term()} file_open_error() = {OutFile, term()}

Converts an Audit Trail Log to a readable text file. - OutFile defaults to "./snmpm_log.txt". - LogName defaults to "snmpm_log". - LogFile defaults to "snmpm.log". - See snmp:log_to_txt - for more info.

+ OutFile defaults to "./snmpm_log.txt". + LogName defaults to "snmpm_log". + LogFile defaults to "snmpm.log". +

The Block option indicates if the log should be blocked + during conversion. This could be usefull when converting large + logs (when otherwise the log could wrap during conversion). + Defaults to false.

+ See snmp:log_to_txt + for more info.

@@ -1242,20 +1250,23 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 log_to_io(LogDir) -> ok | {error, Reason} + log_to_io(LogDir, Block | Mibs) -> ok | {error, Reason} log_to_io(LogDir, Mibs) -> ok | {error, Reason} - log_to_io(LogDir, Mibs) -> ok | {error, Reason} - log_to_io(LogDir, Mibs, LogName) -> ok | {error, Reason} - log_to_io(LogDir, Mibs, LogName, LogFile) -> ok | {error, Reason} - log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, Block | LogName) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, Block | LogFile) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Block | Start) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) -> ok | {error, Reason} log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> ok | {error, Reason} Convert an Audit Trail Log to text format LogDir = string() Mibs = [MibName] MibName = string() + Block = block() LogName = string() LogFile = string() - Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()} + Start = Stop = null | calendar:datetime() | {local_time, calendar:datetime()} | {universal_time, calendar:datetime()} Reason = disk_log_open_error() | file_open_error() | term() disk_log_open_error() = {LogName, term()} file_open_error() = {OutFile, term()} diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 6edcf7e833..e1bf7692b3 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -29,24 +29,9 @@ %% {add_module, snmpm_net_if_mt} [ - {"4.24.1", - [ - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, - {"4.24", - [ - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, - [snmp_conf]}, - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, + {"4.24.2", [{restart_application, snmp}]}, + {"4.24.1", [{restart_application, snmp}]}, + {"4.24", [{restart_application, snmp}]}, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ], @@ -57,24 +42,9 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ - {"4.24.1", - [ - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, - {"4.24", - [ - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, - [snmp_conf]}, - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, + {"4.24.2", [{restart_application, snmp}]}, + {"4.24.1", [{restart_application, snmp}]}, + {"4.24", [{restart_application, snmp}]}, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ] diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index 04ce2c0530..de03c97281 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -343,12 +343,6 @@ validate_loop(Error, _Log, _Write, _PrevTS, _PrevSN) -> %% log(Log, Packet, Addr, Port) %%----------------------------------------------------------------- --spec log(Log :: log(), - Packet :: binary() | {v3_header(), ScopedPDU :: list()}, - Addr :: inet:ip_address(), - Port :: inet:port_number()) -> - ok | {error, Reason :: term()}. - log(#snmp_log{id = Log, seqno = SeqNo}, Packet, Addr, Port) -> ?vtrace("log -> entry with" "~n Log: ~p" @@ -594,14 +588,14 @@ maybe_unblock(Log, true = _Block) -> %% "~n Res: ~p", [log_status(Log), Res]), Res. -log_status(Log) -> - Info = disk_log:info(Log), - case lists:keysearch(status, 1, Info) of - {value, {status, Status}} -> - Status; - false -> - undefined - end. +%% log_status(Log) -> +%% Info = disk_log:info(Log), +%% case lists:keysearch(status, 1, Info) of +%% {value, {status, Status}} -> +%% Status; +%% false -> +%% undefined +%% end. %% -- do_log_to_text --- diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 2164121e86..70f7c2b19a 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.24.2 +SNMP_VSN = 4.25 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 7d2a1248d82027b5b0e91f4f7c2cdfa5814a3590 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 11 Oct 2013 14:42:31 +0200 Subject: [snmp] Commented out (currently) unused upgrade/downgrade function --- lib/snmp/src/agent/snmpa_symbolic_store.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_symbolic_store.erl b/lib/snmp/src/agent/snmpa_symbolic_store.erl index 00178f4bcd..a922d62ba8 100644 --- a/lib/snmp/src/agent/snmpa_symbolic_store.erl +++ b/lib/snmp/src/agent/snmpa_symbolic_store.erl @@ -642,10 +642,10 @@ code_change(_Vsn, S, _Extra) -> {ok, S}. -stop_backup_server(undefined) -> - ok; -stop_backup_server({Pid, _}) when is_pid(Pid) -> - exit(Pid, kill). +%% stop_backup_server(undefined) -> +%% ok; +%% stop_backup_server({Pid, _}) when is_pid(Pid) -> +%% exit(Pid, kill). -- cgit v1.2.3 From a803a95c00f89932d2cfd7a7b424aad05fa276b8 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 17 Oct 2013 17:45:54 +0200 Subject: [snmp] Wrong block cypher type used for AES Wrong block cypher type used for AES ('aes_cbf128' instead of 'aes_cfb128') when performing AES block encrypt/decrypt which breaks SNMP usmAesCfb128Protocol in agent and manager. OTP-11412 --- lib/snmp/doc/src/notes.xml | 68 +++++++++++++++++++++++++++++++++++++++++ lib/snmp/src/app/snmp.appup.src | 42 ++++--------------------- lib/snmp/src/misc/snmp_usm.erl | 15 ++++++--- lib/snmp/vsn.mk | 2 +- 4 files changed, 86 insertions(+), 41 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 7514c52dda..7155402ab1 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,74 @@
+
+ SNMP Development Toolkit 4.25 +

Version 4.25 supports code replacement in runtime from/to + version 4.24.2, 4.24.1, 4.24, 4.23.1 and 4.23.

+ +
+ Improvements and new features +

-

+ + + +
+ +
+ Fixed Bugs and Malfunctions + + + + +

Wrong block cypher type used for AES ('aes_cbf128' + instead of 'aes_cfb128') when performing AES block + encrypt/decrypt which breaks SNMP usmAesCfb128Protocol + in agent and manager.

+

Own Id: OTP-11412

+
+ +
+ +
+ +
+ Incompatibilities +

-

+ + +
+ +
+ +
SNMP Development Toolkit 4.24.2

Version 4.24.2 supports code replacement in runtime from/to diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 6edcf7e833..e1bf7692b3 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -29,24 +29,9 @@ %% {add_module, snmpm_net_if_mt} [ - {"4.24.1", - [ - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, - {"4.24", - [ - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, - [snmp_conf]}, - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, + {"4.24.2", [{restart_application, snmp}]}, + {"4.24.1", [{restart_application, snmp}]}, + {"4.24", [{restart_application, snmp}]}, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ], @@ -57,24 +42,9 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ - {"4.24.1", - [ - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, - {"4.24", - [ - {load_module, snmp_conf, soft_purge, soft_purge, []}, - {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, - [snmp_conf]}, - {load_module, snmpa, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, - {update, snmpa_agent, soft, soft_purge, soft_purge, [snmpa_agent]}, - {update, snmpa_mib, soft, soft_purge, soft_purge, []} - ] - }, + {"4.24.2", [{restart_application, snmp}]}, + {"4.24.1", [{restart_application, snmp}]}, + {"4.24", [{restart_application, snmp}]}, {"4.23.1", [{restart_application, snmp}]}, {"4.23", [{restart_application, snmp}]} ] diff --git a/lib/snmp/src/misc/snmp_usm.erl b/lib/snmp/src/misc/snmp_usm.erl index 67e3476816..0c57f535cd 100644 --- a/lib/snmp/src/misc/snmp_usm.erl +++ b/lib/snmp/src/misc/snmp_usm.erl @@ -42,6 +42,9 @@ -define(i32(Int), (Int bsr 24) band 255, (Int bsr 16) band 255, (Int bsr 8) band 255, Int band 255). +-define(BLOCK_CIPHER_AES, aes_cfb128). +-define(BLOCK_CIPHER_DES, des_cbc). + %%----------------------------------------------------------------- %% Func: passwd2localized_key/3 @@ -210,7 +213,8 @@ des_encrypt(PrivKey, Data, SaltFun) -> IV = list_to_binary(snmp_misc:str_xor(PreIV, Salt)), TailLen = (8 - (length(Data) rem 8)) rem 8, Tail = mk_tail(TailLen), - EncData = crypto:block_encrypt(des_cbc, DesKey, IV, [Data,Tail]), + EncData = crypto:block_encrypt(?BLOCK_CIPHER_DES, + DesKey, IV, [Data,Tail]), {ok, binary_to_list(EncData), Salt}. des_decrypt(PrivKey, MsgPrivParams, EncData) @@ -224,7 +228,8 @@ des_decrypt(PrivKey, MsgPrivParams, EncData) Salt = MsgPrivParams, IV = list_to_binary(snmp_misc:str_xor(PreIV, Salt)), %% Whatabout errors here??? E.g. not a mulitple of 8! - Data = binary_to_list(crypto:block_decrypt(des_cbc, DesKey, IV, EncData)), + Data = binary_to_list(crypto:block_decrypt(?BLOCK_CIPHER_DES, + DesKey, IV, EncData)), Data2 = snmp_pdus:strip_encrypted_scoped_pdu_data(Data), {ok, Data2}; des_decrypt(PrivKey, BadMsgPrivParams, EncData) -> @@ -242,7 +247,8 @@ aes_encrypt(PrivKey, Data, SaltFun) -> EngineBoots = snmp_framework_mib:get_engine_boots(), EngineTime = snmp_framework_mib:get_engine_time(), IV = list_to_binary([?i32(EngineBoots), ?i32(EngineTime) | Salt]), - EncData = crypto:block_encrypt(aes_cbf128, AesKey, IV, Data), + EncData = crypto:block_encrypt(?BLOCK_CIPHER_AES, + AesKey, IV, Data), {ok, binary_to_list(EncData), Salt}. aes_decrypt(PrivKey, MsgPrivParams, EncData, EngineBoots, EngineTime) @@ -251,7 +257,8 @@ aes_decrypt(PrivKey, MsgPrivParams, EncData, EngineBoots, EngineTime) Salt = MsgPrivParams, IV = list_to_binary([?i32(EngineBoots), ?i32(EngineTime) | Salt]), %% Whatabout errors here??? E.g. not a mulitple of 8! - Data = binary_to_list(crypto:block_decrypt(aes_cbf128, AesKey, IV, EncData)), + Data = binary_to_list(crypto:block_decrypt(?BLOCK_CIPHER_AES, + AesKey, IV, EncData)), Data2 = snmp_pdus:strip_encrypted_scoped_pdu_data(Data), {ok, Data2}. diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 2164121e86..70f7c2b19a 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.24.2 +SNMP_VSN = 4.25 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 300803837926d0bb28829f313fad07f757188d41 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 18 Oct 2013 11:32:25 +0200 Subject: [snmp/manager] Incorrect use of EngineBoots and EngineTime when encrypting When performing the AES encryption, invalid values for the EngineBoots and EngineTime was used. The values of the local agent was used, which would have produced some values if an agent was actually running. If not it would have caused a crash. OTP-11413 --- lib/snmp/doc/src/notes.xml | 9 +++++++++ lib/snmp/src/agent/snmpa_mpd.erl | 4 ++-- lib/snmp/src/agent/snmpa_usm.erl | 10 ++++++++-- lib/snmp/src/manager/snmpm_usm.erl | 14 ++++++++++---- lib/snmp/src/misc/snmp_usm.erl | 8 ++++---- 5 files changed, 33 insertions(+), 12 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 7155402ab1..977af3ffb2 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -77,6 +77,15 @@

Own Id: OTP-11412

+ +

[manager] When performing the AES encryption, invalid values for + the EngineBoots and EngineTime was used.

+

The values of the local agent was used, which would have produced + some values if an agent was actually running. + If not it would have caused a crash.

+

Own Id: OTP-11413

+
+
diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index 2d37ea56f0..11ae806866 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2012. All Rights Reserved. +%% Copyright Ericsson AB 1997-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -657,7 +657,7 @@ generate_response_msg(Vsn, RePdu, Type, ?SEC_USM -> snmpa_usm end, - SecEngineID = LocalEngineID, + SecEngineID = LocalEngineID, % 3.1.1a ?vtrace("generate_response_msg -> SecEngineID: ~w", [SecEngineID]), case (catch SecModule:generate_outgoing_msg(Message, SecEngineID, diff --git a/lib/snmp/src/agent/snmpa_usm.erl b/lib/snmp/src/agent/snmpa_usm.erl index 6f54307f9f..719ea4e356 100644 --- a/lib/snmp/src/agent/snmpa_usm.erl +++ b/lib/snmp/src/agent/snmpa_usm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2011. All Rights Reserved. +%% Copyright Ericsson AB 1999-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -16,6 +16,9 @@ %% %% %CopyrightEnd% %% +%% AES: RFC 3826 +%% + -module(snmpa_usm). %% Avoid warning for local function error/1 clashing with autoimported BIF. @@ -652,7 +655,10 @@ get_des_salt() -> [?i32(EngineBoots), ?i32(SaltInt)]. aes_encrypt(PrivKey, Data) -> - snmp_usm:aes_encrypt(PrivKey, Data, fun get_aes_salt/0). + EngineBoots = snmp_framework_mib:get_engine_boots(), + EngineTime = snmp_framework_mib:get_engine_time(), + snmp_usm:aes_encrypt(PrivKey, Data, fun get_aes_salt/0, + EngineBoots, EngineTime). aes_decrypt(PrivKey, UsmSecParams, EncData) -> #usmSecurityParameters{msgPrivacyParameters = PrivParams, diff --git a/lib/snmp/src/manager/snmpm_usm.erl b/lib/snmp/src/manager/snmpm_usm.erl index 497d6d6102..0a8a6436a3 100644 --- a/lib/snmp/src/manager/snmpm_usm.erl +++ b/lib/snmp/src/manager/snmpm_usm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -19,6 +19,9 @@ %%----------------------------------------------------------------- %% This module implements the User Based Security Model for SNMP, %% as defined in rfc2274. +%% +%% AES: RFC 3826 +%% %%----------------------------------------------------------------- -module(snmpm_usm). @@ -416,11 +419,14 @@ get_des_salt() -> [?i32(EngineBoots), ?i32(SaltInt)]. aes_encrypt(PrivKey, Data) -> - snmp_usm:aes_encrypt(PrivKey, Data, fun get_aes_salt/0). + EngineBoots = get_engine_boots(), + EngineTime = get_engine_time(), + snmp_usm:aes_encrypt(PrivKey, Data, fun get_aes_salt/0, + EngineBoots, EngineTime). aes_decrypt(PrivKey, UsmSecParams, EncData) -> - #usmSecurityParameters{msgPrivacyParameters = MsgPrivParams, - msgAuthoritativeEngineTime = EngineTime, + #usmSecurityParameters{msgPrivacyParameters = MsgPrivParams, + msgAuthoritativeEngineTime = EngineTime, msgAuthoritativeEngineBoots = EngineBoots} = UsmSecParams, snmp_usm:aes_decrypt(PrivKey, MsgPrivParams, EncData, diff --git a/lib/snmp/src/misc/snmp_usm.erl b/lib/snmp/src/misc/snmp_usm.erl index 0c57f535cd..32198deb8b 100644 --- a/lib/snmp/src/misc/snmp_usm.erl +++ b/lib/snmp/src/misc/snmp_usm.erl @@ -16,6 +16,8 @@ %% %% %CopyrightEnd% %% +%% AES: RFC 3826 +%% -module(snmp_usm). @@ -24,7 +26,7 @@ -export([passwd2localized_key/3, localize_key/3]). -export([auth_in/4, auth_out/4, set_msg_auth_params/3]). -export([des_encrypt/3, des_decrypt/3]). --export([aes_encrypt/3, aes_decrypt/5]). +-export([aes_encrypt/5, aes_decrypt/5]). -define(SNMP_USE_V3, true). @@ -241,11 +243,9 @@ des_decrypt(PrivKey, BadMsgPrivParams, EncData) -> throw({error, {bad_msgPrivParams, PrivKey, BadMsgPrivParams, EncData}}). -aes_encrypt(PrivKey, Data, SaltFun) -> +aes_encrypt(PrivKey, Data, SaltFun, EngineBoots, EngineTime) -> AesKey = PrivKey, Salt = SaltFun(), - EngineBoots = snmp_framework_mib:get_engine_boots(), - EngineTime = snmp_framework_mib:get_engine_time(), IV = list_to_binary([?i32(EngineBoots), ?i32(EngineTime) | Salt]), EncData = crypto:block_encrypt(?BLOCK_CIPHER_AES, AesKey, IV, Data), -- cgit v1.2.3 From 57abd27ee8e189791c4d97ef86de6136c4924b52 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 31 Oct 2013 17:03:02 +0100 Subject: [snmp] Improving ATL handling of corrupt logs When converting an Audit Trail Log to text a corrupt log entry could cause the entire conversion to fail. Also, for a log with sequence numbers, failing to decode a log entry would cause the conversion to fail (not because of the failed decode, but because of the failure to write the error message). OTP-11453 --- lib/snmp/doc/src/notes.xml | 62 ++++++++ lib/snmp/src/app/snmp.appup.src | 40 +++-- lib/snmp/src/misc/snmp_log.erl | 276 ++++++++++++++++++++++++++--------- lib/snmp/src/misc/snmp_verbosity.erl | 14 +- lib/snmp/vsn.mk | 2 +- 5 files changed, 309 insertions(+), 85 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 8d280fb3a1..8320b8762e 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,68 @@
+
+ SNMP Development Toolkit 4.22.3 +

Version 4.22.3 supports code replacement in runtime from/to + version 4.22.2, 4.22.1, 4.22, + 4.21.7 4.21.6 4.21.5, 4.21.4, 4.21.3, 4.21.2, 4.21.1 and 4.21.

+ +
+ Improvements and new features +

-

+ + + +
+ +
+ Fixed Bugs and Malfunctions + + + + +

When converting an Audit Trail Log to text a corrupt + log entry could cause the entire conversion to fail.

+

Also, for a log with sequence numbers, failing to + decode a log entry would cause the conversion to fail + (not because of the failed decode, but because of the + failure to write the error message).

+

Own Id: OTP-111453

+

Aux Id: Seq 12459

+
+ +
+ +
+ +
+ Incompatibilities +

-

+
+ +
+ +
SNMP Development Toolkit 4.22.2

Version 4.22.2 supports code replacement in runtime from/to diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 39e154d463..daf8496670 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2012. All Rights Reserved. +%% Copyright Ericsson AB 1999-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -22,13 +22,24 @@ %% ----- U p g r a d e ------------------------------------------------------- [ + {"4.22.2", + [ + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []} + ] + }, {"4.22.1", [ + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []} ] }, {"4.22", [ {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, + [snmp_verbosity]}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmp_pdus, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmp_user_based_sm_mib, soft_purge, soft_purge, []} @@ -51,7 +62,7 @@ {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, {load_module, snmpa, soft_purge, soft_purge, [snmp]}, {load_module, snmpm, soft_purge, soft_purge, [snmp]}, - {load_module, snmp_log, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, @@ -80,7 +91,7 @@ {load_module, snmpa, soft_purge, soft_purge, [snmp]}, {load_module, snmpm, soft_purge, soft_purge, [snmp]}, {load_module, snmp_log, soft_purge, soft_purge, []}, - {load_module, snmp_verbosity, soft_purge, soft_purge, []}, + {load_module, snmp_verbosity, soft_purge, soft_purge, [snmp_verbosity]}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, {update, snmpa_local_db, soft, soft_purge, soft_purge, []}, @@ -105,7 +116,7 @@ {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, {load_module, snmpm, soft_purge, soft_purge, [snmp]}, - {load_module, snmp_log, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, @@ -137,7 +148,7 @@ {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, {load_module, snmpm, soft_purge, soft_purge, [snmp]}, - {load_module, snmp_log, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, @@ -173,7 +184,7 @@ {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, {load_module, snmpm, soft_purge, soft_purge, [snmp]}, - {load_module, snmp_log, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, @@ -209,7 +220,7 @@ {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, {load_module, snmpm, soft_purge, soft_purge, [snmp]}, - {load_module, snmp_log, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, @@ -247,7 +258,7 @@ {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, {load_module, snmpm, soft_purge, soft_purge, [snmp]}, - {load_module, snmp_log, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, @@ -286,7 +297,7 @@ {load_module, snmp, soft_purge, soft_purge, [snmp_log]}, {load_module, snmpm, soft_purge, soft_purge, [snmp]}, - {load_module, snmp_log, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmpm_mpd, soft_purge, soft_purge, []}, @@ -316,13 +327,24 @@ %% ------D o w n g r a d e --------------------------------------------------- [ + {"4.22.2", + [ + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []} + ] + }, {"4.22.1", [ + {load_module, snmp_log, soft_purge, soft_purge, [snmp_verbosity]}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []} ] }, {"4.22", [ {load_module, snmpm, soft_purge, soft_purge, []}, + {load_module, snmp_log, soft_purge, soft_purge, + [snmp_verbosity]}, + {load_module, snmp_verbosity, soft_purge, soft_purge, []}, {load_module, snmp_pdus, soft_purge, soft_purge, []}, {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, []}, {load_module, snmp_user_based_sm_mib, soft_purge, soft_purge, []} diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index a8c5df0b64..a365e8c8ed 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2012. All Rights Reserved. +%% Copyright Ericsson AB 1997-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -16,6 +16,7 @@ %% %% %CopyrightEnd% %% +%% -module(snmp_log). @@ -397,6 +398,8 @@ log_to_txt(Log, FileName, Dir, Mibs, TextFile, Start, Stop) [Log, FileName, Dir, Mibs, TextFile, Start, Stop]), File = filename:join(Dir, FileName), Converter = fun(L) -> + ?vtrace("log_to_txt:fun -> entry with" + "~n L: ~p", [L]), do_log_to_file(L, TextFile, Mibs, Start, Stop) end, log_convert(Log, File, Converter). @@ -422,6 +425,8 @@ log_to_io(Log, FileName, Dir, Mibs, Start, Stop) [Log, FileName, Dir, Mibs, Start, Stop]), File = filename:join(Dir, FileName), Converter = fun(L) -> + ?vtrace("log_to_io:fun -> entry with" + "~n L: ~p", [L]), do_log_to_io(L, Mibs, Start, Stop) end, log_convert(Log, File, Converter). @@ -439,22 +444,25 @@ log_convert(Log, File, Converter) -> do_log_convert(Log, File, Converter). do_log_convert(Log, File, Converter) -> - %% ?vtrace("do_log_converter -> entry with" - %% "~n Log: ~p" - %% "~n File: ~p" - %% "~n disk_log:info(Log): ~p", [Log, File, disk_log:info(Log)]), + ?vtrace("do_log_converter -> entry with" + "~n Log: ~p" + "~n File: ~p", [Log, File]), + Verbosity = get(verbosity), {Pid, Ref} = erlang:spawn_monitor( fun() -> + put(sname, "LOG-CONVERTER"), + put(verbosity, Verbosity), + erlang:process_flag(trap_exit, true), + ?vlog("begin converting", []), Result = do_log_convert2(Log, File, Converter), + ?vlog("convert result: ~p", [Result]), exit(Result) end), receive {'DOWN', Ref, process, Pid, Result} -> - %% ?vtrace("do_log_converter -> received result" - %% "~n Result: ~p" - %% "~n disk_log:info(Log): ~p", - %% [Result, disk_log:info(Log)]), + ?vtrace("do_log_converter -> received result" + "~n Result: ~p", [Result]), Result end. @@ -462,19 +470,31 @@ do_log_convert2(Log, File, Converter) -> %% First check if the caller process has already opened the %% log, because if we close an already open log we will cause %% a runtime error. + ?vtrace("do_log_convert2 -> entry - check if owner", []), case is_owner(Log) of true -> + ?vtrace("do_log_convert2 -> owner - now convert", []), Converter(Log); false -> %% Not yet member of the ruling party, apply for membership... + ?vtrace("do_log_convert2 -> not owner - open", []), case log_open(Log, File) of {ok, _} -> + ?vdebug("do_log_convert2 -> opened - now convert", []), Res = Converter(Log), + ?vtrace("do_log_convert2 -> converted - now close", []), disk_log:close(Log), + ?vtrace("do_log_convert2 -> closed - done", []), Res; {error, {name_already_open, _}} -> - Converter(Log); + ?vdebug("do_log_convert2 -> " + "already opened - now convert", []), + Res = Converter(Log), + ?vtrace("do_log_convert2 -> converted - done", []), + Res; {error, Reason} -> + ?vinfo("do_log_convert2 -> failed open: " + "~n Reason: ~p", [Reason]), {error, {Log, Reason}} end end. @@ -483,50 +503,93 @@ do_log_convert2(Log, File, Converter) -> %% -- do_log_to_text --- do_log_to_file(Log, TextFile, Mibs, Start, Stop) -> + ?vtrace("do_log_to_txt -> entry with" + "~n Log: ~p" + "~n TextFile: ~p" + "~n Start: ~p" + "~n Stop: ~p", [Log, TextFile, Start, Stop]), case file:open(TextFile, [write]) of {ok, Fd} -> + ?vtrace("do_log_to_txt -> outfile created - create mini MIB", []), MiniMib = snmp_mini_mib:create(Mibs), + ?vtrace("do_log_to_txt -> mini-MIB created - begin conversion", []), Write = fun(X) -> + ?vtrace("do_log_to_txt:fun -> " + "entry - try format", []), case format_msg(X, MiniMib, Start, Stop) of {ok, S} -> + ?vtrace("do_log_to_txt:fun -> " + "formated - now write", []), io:format(Fd, "~s", [S]); _ -> + ?vdebug("do_log_to_txt:fun -> " + "format failed", []), ok end end, Res = (catch loop(disk_log:chunk(Log, start), Log, Write)), + ?vtrace("do_log_to_txt -> converted - now delete mini-MIB", []), snmp_mini_mib:delete(MiniMib), + ?vtrace("do_log_to_txt -> " + "mini-MIB closed - now close output file", []), file:close(Fd), + ?vtrace("do_log_to_txt -> done", []), Res; {error, Reason} -> + ?vinfo("failed opening output file: " + "~n TestFile: ~p" + "~n Reason: ~p", [TextFile, Reason]), {error, {TextFile, Reason}} end. do_log_to_io(Log, Mibs, Start, Stop) -> + ?vtrace("do_log_to_io -> entry with" + "~n Log: ~p" + "~n Mibs: ~p" + "~n Start: ~p" + "~n Stop: ~p", [Log, Mibs, Start, Stop]), MiniMib = snmp_mini_mib:create(Mibs), + ?vtrace("do_log_to_io -> mini-MIB created - begin conversion", []), Write = fun(X) -> + ?vtrace("do_log_to_io:fun -> entry", []), case format_msg(X, MiniMib, Start, Stop) of {ok, S} -> + ?vtrace("do_log_to_io:fun -> " + "formated - now write", []), io:format("~s", [S]); _ -> + ?vdebug("do_log_to_io:fun -> " + "format failed", []), ok end end, (catch loop(disk_log:chunk(Log, start), Log, Write)), + ?vtrace("do_log_to_io -> converted - now delete mini-MIB", []), snmp_mini_mib:delete(MiniMib), + ?vtrace("do_log_to_io -> done", []), ok. loop(eof, _Log, _Write) -> + ?vtrace("loop -> entry when eof", []), ok; -loop({error, _} = Error, _Log, _Write) -> +loop({error, _Reason} = Error, _Log, _Write) -> + ?vtrace("loop -> entry with error" + "~n Reason: ~p", [_Reason]), Error; loop({Cont, Terms}, Log, Write) -> - case (catch lists:foreach(Write, Terms)) of + ?vtrace("loop -> entry with terms" + "~n Cont: ~p" + "~n length(Terms): ~p", [Cont, length(Terms)]), + case (catch lists:foreach(Write, Terms)) of {'EXIT', Reason} -> + ?vtrace("loop -> failure while writing terms" + "~n Reason: ~p", [Reason]), {error, Reason}; - _ -> + _X -> + ?vtrace("loop -> terms written" + "~n X: ~p", [_X]), loop(disk_log:chunk(Log, Cont), Log, Write) end; loop({Cont, Terms, BadBytes}, Log, Write) -> @@ -539,6 +602,8 @@ loop({Cont, Terms, BadBytes}, Log, Write) -> loop(disk_log:chunk(Log, Cont), Log, Write) end; loop(Error, _Log, _Write) -> + ?vtrace("loop -> entry with unknown" + "~n Error: ~p", [Error]), Error. @@ -553,14 +618,17 @@ format_msg(Entry, Mib, Start, Stop) -> %% This is an old-style entry, that never had the sequence-number do_format_msg({Timestamp, Packet, {Addr, Port}}, Mib) -> + ?vdebug("do_format_msg -> old style log entry", []), do_format_msg(Timestamp, Packet, Addr, Port, Mib); %% This is the format without sequence-number do_format_msg({Timestamp, Packet, Addr, Port}, Mib) -> + ?vdebug("do_format_msg -> log entry without seqno", []), do_format_msg(Timestamp, Packet, Addr, Port, Mib); %% This is the format with sequence-number do_format_msg({Timestamp, SeqNo, Packet, Addr, Port}, Mib) -> + ?vdebug("do_format_msg -> log entry with seqno", []), do_format_msg(Timestamp, SeqNo, Packet, Addr, Port, Mib); %% This is crap... @@ -568,103 +636,165 @@ do_format_msg(_, _) -> format_tab("** unknown entry in log file\n\n", []). do_format_msg(TimeStamp, {V3Hdr, ScopedPdu}, Addr, Port, Mib) -> + ?vtrace("do_format_msg -> entry with" + "~n Timestamp: ~p" + "~n Addr: ~p" + "~n Port: ~p" + "~n => Try decode scoped pdu", + [TimeStamp, Addr, Port]), case (catch snmp_pdus:dec_scoped_pdu(ScopedPdu)) of ScopedPDU when is_record(ScopedPDU, scopedPdu) -> + ?vtrace("do_format_msg -> scoped pdu decoded" + "~n ScopedPDU: ~p", [ScopedPDU]), Msg = #message{version = 'version-3', vsn_hdr = V3Hdr, data = ScopedPDU}, f(ts2str(TimeStamp), "", Msg, Addr, Port, Mib); + {'EXIT', Reason} -> - format_tab("** error in log file at ~s from ~p:~w ~p\n\n", + ?vinfo("Failed decoding scoped pdu: " + "~n V3Hdr: ~w" + "~n ScopedPdu: ~w" + "~n Reason: ~p", [V3Hdr, ScopedPdu, Reason]), + format_tab("** error in log file at ~s from ~s:~w ~p\n\n", [ts2str(TimeStamp), ip(Addr), Port, Reason]) end; + do_format_msg(TimeStamp, Packet, Addr, Port, Mib) -> + ?vtrace("do_format_msg -> entry with" + "~n Timestamp: ~p" + "~n Addr: ~p" + "~n Port: ~p" + "~n => Try decode packet", + [TimeStamp, Addr, Port]), case (catch snmp_pdus:dec_message(binary_to_list(Packet))) of - Msg when is_record(Msg, message) -> + #message{data = Data} = Msg when (is_record(Data, scopedPdu) orelse + is_record(Data, pdu) orelse + is_record(Data, trappdu)) -> + ?vtrace("do_format_msg -> packet decoded" + "~n Msg: ~p", [Msg]), f(ts2str(TimeStamp), "", Msg, Addr, Port, Mib); + + #message{version = Vsn, + vsn_hdr = VsnHdr} = Msg -> + ?vinfo("Message not fully decoded: " + "~n Msg: ~p", [Msg]), + Reason = + lists:flatten( + io_lib:format("Message not fully decoded: " + "Vsn = ~p, VsnHdr = ~w", [Vsn, VsnHdr])), + format_tab("** error in log file ~s from ~s:~w => " + "\n ~s\n\n", + [ts2str(TimeStamp), ip(Addr), Port, Reason]); + {'EXIT', Reason} -> + ?vinfo("Failed decoding packet: " + "~n Packet: ~w" + "~n Reason: ~p", [Packet, Reason]), format_tab("** error in log file ~p\n\n", [Reason]) end. do_format_msg(TimeStamp, SeqNo, {V3Hdr, ScopedPdu}, Addr, Port, Mib) -> + ?vtrace("do_format_msg -> entry with" + "~n Timestamp: ~p" + "~n SeqNo: ~p" + "~n Addr: ~p" + "~n Port: ~p" + "~n => Try decode scoped pdu", + [TimeStamp, SeqNo, Addr, Port]), case (catch snmp_pdus:dec_scoped_pdu(ScopedPdu)) of ScopedPDU when is_record(ScopedPDU, scopedPdu) -> + ?vtrace("do_format_msg -> scoped pdu decoded" + "~n ScopedPDU: ~p", [ScopedPDU]), Msg = #message{version = 'version-3', vsn_hdr = V3Hdr, data = ScopedPDU}, f(ts2str(TimeStamp), sn2str(SeqNo), Msg, Addr, Port, Mib); + {'EXIT', Reason} -> - format_tab("** error in log file at ~s from ~p:~w ~p\n\n", + ?vinfo("Failed decoding scoped pdu: " + "~n V3Hdr: ~w" + "~n ScopedPdu: ~w" + "~n Reason: ~p", [V3Hdr, ScopedPdu, Reason]), + format_tab("** error in log file at ~s~s from ~s:~w ~p\n\n", [ts2str(TimeStamp), sn2str(SeqNo), ip(Addr), Port, Reason]) end; do_format_msg(TimeStamp, SeqNo, Packet, Addr, Port, Mib) -> + ?vtrace("do_format_msg -> entry with" + "~n Timestamp: ~p" + "~n SeqNo: ~p" + "~n Addr: ~p" + "~n Port: ~p" + "~n => Try decode message", + [TimeStamp, SeqNo, Addr, Port]), case (catch snmp_pdus:dec_message(binary_to_list(Packet))) of - Msg when is_record(Msg, message) -> + #message{data = Data} = Msg when (is_record(Data, scopedPdu) orelse + is_record(Data, pdu) orelse + is_record(Data, trappdu)) -> + ?vtrace("do_format_msg -> message decoded" + "~n Msg: ~p", [Msg]), f(ts2str(TimeStamp), sn2str(SeqNo), Msg, Addr, Port, Mib); + + #message{version = Vsn, + vsn_hdr = VsnHdr} = Msg -> + ?vinfo("Message not fully decoded: " + "~n Msg: ~p", [Msg]), + Reason = + lists:flatten( + io_lib:format("Message not fully decoded: " + "Vsn = ~p, VsnHdr = ~w", [Vsn, VsnHdr])), + format_tab("** error in log file ~s~s from ~s:~w => " + "\n ~s\n\n", + [ts2str(TimeStamp), sn2str(SeqNo), + ip(Addr), Port, Reason]); + {'EXIT', Reason} -> - format_tab("** error in log file ~s from ~p:~w ~p\n\n", + ?vinfo("Failed decoding packet: " + "~n Packet: ~w" + "~n Reason: ~p", [Packet, Reason]), + format_tab("** error in log file ~s (~s) from ~s:~w ~p\n\n", [ts2str(TimeStamp), sn2str(SeqNo), ip(Addr), Port, Reason]) end. -%% format_msg({TimeStamp, {V3Hdr, ScopedPdu}, {Addr, Port}}, -%% Mib, Start, Stop) -> -%% format_msg({TimeStamp, {V3Hdr, ScopedPdu}, Addr, Port}, -%% Mib, Start, Stop); -%% format_msg({TimeStamp, {V3Hdr, ScopedPdu}, Addr, Port}, -%% Mib, Start, Stop) -> -%% case timestamp_filter(TimeStamp, Start, Stop) of -%% true -> -%% case (catch snmp_pdus:dec_scoped_pdu(ScopedPdu)) of -%% ScopedPDU when record(ScopedPDU, scopedPdu) -> -%% Msg = #message{version = 'version-3', -%% vsn_hdr = V3Hdr, -%% data = ScopedPDU}, -%% f(ts2str(TimeStamp), Msg, Addr, Port, Mib); -%% {'EXIT', Reason} -> -%% format_tab("** error in log file at ~s from ~p:~w ~p\n\n", -%% [ts2str(TimeStamp), ip(Addr), Port, Reason]) -%% end; -%% false -> -%% ignore -%% end; -%% format_msg({TimeStamp, Packet, {Addr, Port}}, Mib, Start, Stop) -> -%% format_msg({TimeStamp, Packet, Addr, Port}, Mib, Start, Stop); -%% format_msg({TimeStamp, Packet, Addr, Port}, Mib, Start, Stop) -> -%% case timestamp_filter(TimeStamp, Start, Stop) of -%% true -> -%% case (catch snmp_pdus:dec_message(binary_to_list(Packet))) of -%% Msg when record(Msg, message) -> -%% f(ts2str(TimeStamp), Msg, Addr, Port, Mib); -%% {'EXIT', Reason} -> -%% format_tab("** error in log file ~p\n\n", [Reason]) -%% end; -%% false -> -%% ignore -%% end; -%% format_msg(_, _Mib, _Start, _Stop) -> -%% format_tab("** unknown entry in log file\n\n", []). - f(TimeStamp, SeqNo, #message{version = Vsn, vsn_hdr = VsnHdr, data = Data}, Addr, Port, Mib) -> - Str = format_pdu(Data, Mib), - HdrStr = format_header(Vsn, VsnHdr), - case get_type(Data) of - trappdu -> - f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - 'snmpv2-trap' -> - f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - 'inform-request' -> - f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - 'get-response' -> - f_response(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - report -> - f_report(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - _ -> - f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) + try + begin + Str = format_pdu(Data, Mib), + HdrStr = format_header(Vsn, VsnHdr), + case get_type(Data) of + trappdu -> + f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); + 'snmpv2-trap' -> + f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); + 'inform-request' -> + f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); + 'get-response' -> + f_response(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); + report -> + f_report(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); + _ -> + f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) + end + end + catch + T:E -> + ?vinfo("Failed formating log entry" + "~n TimeStamp: ~p" + "~n SeqNo: ~p" + "~n Data: ~p" + "~n Vsn: ~p" + "~n VsnHdr: ~p" + "~n Addr: ~p" + "~n Port: ~p" + "~n Error Type: ~w" + "~n Error: ~p", + [TimeStamp, SeqNo, Data, Vsn, VsnHdr, Addr, Port, T, E]), + format_tab("** error while formating log entry ~p\n\n", [{T, E}]) end. f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> @@ -691,7 +821,7 @@ f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> %% Convert a timestamp 2-tupple to a printable string %% ts2str({Local,Universal}) -> - dat2str(Local) ++ " , " ++ dat2str(Universal); + lists:flatten(dat2str(Local) ++ " , " ++ dat2str(Universal)); ts2str(_) -> "". @@ -788,7 +918,7 @@ get_type(#pdu{type = Type}) -> ip({A,B,C,D}) -> - io_lib:format("~w.~w.~w.~w", [A,B,C,D]). + lists:flatten(io_lib:format("~w.~w.~w.~w", [A,B,C,D])). diff --git a/lib/snmp/src/misc/snmp_verbosity.erl b/lib/snmp/src/misc/snmp_verbosity.erl index df5986b7bc..8c4fe3fcb0 100644 --- a/lib/snmp/src/misc/snmp_verbosity.erl +++ b/lib/snmp/src/misc/snmp_verbosity.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2012. All Rights Reserved. +%% Copyright Ericsson AB 2000-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -152,7 +152,17 @@ image_of_sname(mgr) -> "MGR"; image_of_sname(mgr_misc) -> "MGR_MISC"; image_of_sname(undefined) -> ""; -image_of_sname(V) -> lists:flatten(io_lib:format("~p",[V])). +image_of_sname(S) when is_list(S) -> + %% The assumption is that its a printable string, + %% but just in case it is some other list... + try lists:flatten(io_lib:format("~s", [S])) of + L -> + L + catch + _:_ -> + lists:flatten(io_lib:format("~p", [S])) + end; +image_of_sname(V) -> lists:flatten(io_lib:format("~p", [V])). validate(info) -> info; diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 5d3c393bcc..8a4d9c14c0 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.22.2 +SNMP_VSN = 4.22.3 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 1508a71c3ec41347e6e34c57671028f2e4640680 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 19 Nov 2013 12:41:02 +0100 Subject: [snmp] Cleanup and changed atl conversion block default Changed the default value for the Audit Trail Log conversion to true. Also some cleanup. OTP-11396 --- lib/snmp/doc/src/snmp.xml | 80 +++++++++++++++++++++-------------------- lib/snmp/doc/src/snmpa.xml | 8 ++--- lib/snmp/doc/src/snmpm.xml | 12 ++++--- lib/snmp/src/agent/snmpa.erl | 25 ++++++------- lib/snmp/src/app/snmp.erl | 16 ++++----- lib/snmp/src/manager/snmpm.erl | 21 +++++------ lib/snmp/src/misc/snmp_log.erl | 17 ++++----- lib/snmp/test/snmp_log_test.erl | 10 +++--- 8 files changed, 100 insertions(+), 89 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/snmp.xml b/lib/snmp/doc/src/snmp.xml index 3e6610891f..97b479385c 100644 --- a/lib/snmp/doc/src/snmp.xml +++ b/lib/snmp/doc/src/snmp.xml @@ -341,8 +341,9 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> ok | {error, Reason} - log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> ok | {error, Reason} - log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block | Start) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Block | Stop) -> ok | {error, Reason} + log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop, Block) -> ok | {error, Reason} Convert an Audit Trail Log to text format LogDir = string() @@ -352,53 +353,56 @@ LogName = string() LogFile = string() Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()} + Block = boolean() Reason = term() -

Converts an Audit Trail Log to a readable text file, where - each item has a trailing TAB character, and any TAB - character in the body of an item has been replaced by ESC - TAB. -

+

Converts an Audit Trail Log to a readable text file, where + each item has a trailing TAB character, and any TAB + character in the body of an item has been replaced by ESC + TAB.

The function can be used on a running system, or by copying - the entire log directory and calling this function. SNMP - must be running in order to provide MIB information. -

+ the entire log directory and calling this function. SNMP + must be running in order to provide MIB information.

LogDir is the name of the directory where the audit - trail log is stored. - Mibs is a list of Mibs to be used. The function uses - the information in the Mibs to convert for example object - identifiers to their symbolic name. - OutFile is the name of the generated text-file. - LogName is the name of the log, - LogFile is the name of the log file. - Start is the start (first) date and time from which - log events will be converted and - Stop is the stop (last) date and time to which log - events will be converted. -

-

The format of an audit trail log text item is as follows: -

-

Tag Addr - Community [TimeStamp] Vsn

- PDU

-

where Tag is request, response, - report, trap or inform; Addr is - IP:Port (or comma space separated list of such); - Community is the community parameter (SNMP version - v1 and v2), or SecLevel:"AuthEngineID":"UserName" - (SNMP v3); TimeStamp is a date and time stamp, - and Vsn is the SNMP version. PDU is a textual - version of the protocol data unit. There is a new line - between Vsn and PDU.

- + trail log is stored. + Mibs is a list of Mibs to be used. The function uses + the information in the Mibs to convert for example object + identifiers to their symbolic name. + OutFile is the name of the generated text-file. + LogName is the name of the log, + LogFile is the name of the log file. + Start is the start (first) date and time from which + log events will be converted and + Stop is the stop (last) date and time to which log + events will be converted. + The Block argument indicates if the log should be blocked + during conversion. This could be usefull when converting large + logs (when otherwise the log could wrap during conversion). + Defaults to true. +

+

The format of an audit trail log text item is as follows:

+

Tag Addr - Community [TimeStamp] Vsn

+ PDU

+

where Tag is request, response, + report, trap or inform; Addr is + IP:Port (or comma space separated list of such); + Community is the community parameter (SNMP version + v1 and v2), or SecLevel:"AuthEngineID":"UserName" + (SNMP v3); TimeStamp is a date and time stamp, + and Vsn is the SNMP version. PDU is a textual + version of the protocol data unit. There is a new line + between Vsn and PDU.

+ log_to_io(LogDir, Mibs, LogName, LogFile) -> ok | {error, Reason} - log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> ok | {error, Reason} - log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Block | Start) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Start, Block | Stop) -> ok | {error, Reason} + log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop, Block) -> ok | {error, Reason} Convert an Audit Trail Log to text format LogDir = string() diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index 29e8869401..cc8681e5c8 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -570,7 +570,7 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} LogDir = string() Mibs = [MibName] MibName = string() - Block = block() + Block = boolean() OutFile = string() LogName = string() LogFile = string() @@ -587,7 +587,7 @@ notification_delivery_info() = #snmpa_notification_delivery_info{}

The Block option indicates if the log should be blocked during conversion. This could be usefull when converting large logs (when otherwise the log could wrap during conversion). - Defaults to false.

+ Defaults to true.

See snmp:log_to_txt for more info.

@@ -609,7 +609,7 @@ notification_delivery_info() = #snmpa_notification_delivery_info{} LogDir = string() Mibs = [MibName] MibName = string() - Block = block() + Block = boolean() LogName = string() LogFile = string() Start = Stop = null | calendar:datetime() | {local_time, calendar:datetime()} | {universal_time, calendar:datetime()} @@ -625,7 +625,7 @@ notification_delivery_info() = #snmpa_notification_delivery_info{}

The Block option indicates if the log should be blocked during conversion. This could be usefull when converting large logs (when otherwise the log could wrap during conversion). - Defaults to false.

+ Defaults to true.

See snmp:log_to_io for more info.

diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index f7b7e6220e..a0a1b5716d 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -1223,7 +1223,7 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 LogDir = string() Mibs = [MibName] MibName = string() - Block = block() + Block = boolean() OutFile = string() LogName = string() LogFile = string() @@ -1237,10 +1237,10 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 OutFile defaults to "./snmpm_log.txt". LogName defaults to "snmpm_log". LogFile defaults to "snmpm.log". -

The Block option indicates if the log should be blocked +

The Block argument indicates if the log should be blocked during conversion. This could be usefull when converting large logs (when otherwise the log could wrap during conversion). - Defaults to false.

+ Defaults to true.

See snmp:log_to_txt for more info.

@@ -1263,7 +1263,7 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 LogDir = string() Mibs = [MibName] MibName = string() - Block = block() + Block = boolean() LogName = string() LogFile = string() Start = Stop = null | calendar:datetime() | {local_time, calendar:datetime()} | {universal_time, calendar:datetime()} @@ -1276,6 +1276,10 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1 prints it on stdio. LogName defaults to "snmpm_log". LogFile defaults to "snmpm.log". +

The Block argument indicates if the log should be blocked + during conversion. This could be usefull when converting large + logs (when otherwise the log could wrap during conversion). + Defaults to true.

See snmp:log_to_io for more info.

diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 3804966e61..aea63effe6 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -129,7 +129,8 @@ -include("snmpa_internal.hrl"). -include_lib("snmp/include/snmp_types.hrl"). % type of me needed. --define(DISCO_EXTRA_INFO, undefined). +-define(DISCO_EXTRA_INFO, undefined). +-define(ATL_BLOCK_DEFAULT, true). %%----------------------------------------------------------------- @@ -893,7 +894,7 @@ log_to_txt(LogDir, Block) snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, OutFile = "snmpa_log.txt", LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, @@ -915,7 +916,7 @@ log_to_txt(LogDir, Mibs, Block) LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). @@ -937,7 +938,7 @@ log_to_txt(LogDir, Mibs, OutFile, Block) LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). @@ -959,7 +960,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, Block) LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). -spec log_to_txt(LogDir :: snmp:dir(), @@ -981,7 +982,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block) when ((Block =:= true) orelse (Block =:= false)) -> snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start). -spec log_to_txt(LogDir :: snmp:dir(), @@ -1006,7 +1007,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). -spec log_to_txt(LogDir :: snmp:dir(), @@ -1033,7 +1034,7 @@ log_to_io(LogDir, Block) LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). @@ -1044,7 +1045,7 @@ log_to_io(LogDir, Mibs, Block) LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). @@ -1053,21 +1054,21 @@ log_to_io(LogDir, Mibs, LogName, Block) LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName, LogFile) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). log_to_io(LogDir, Mibs, LogName, LogFile, Block) when ((Block =:= true) orelse (Block =:= false)) -> snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start). log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) when ((Block =:= true) orelse (Block =:= false)) -> snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start); log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> diff --git a/lib/snmp/src/app/snmp.erl b/lib/snmp/src/app/snmp.erl index 967afa0e08..16ccee9612 100644 --- a/lib/snmp/src/app/snmp.erl +++ b/lib/snmp/src/app/snmp.erl @@ -150,8 +150,8 @@ {get_agent_caps, 0, eventually}]). --define(APPLICATION, snmp). - +-define(APPLICATION, snmp). +-define(ATL_BLOCK_DEFAULT, true). %%----------------------------------------------------------------- @@ -859,7 +859,7 @@ read_mib(FileName) -> %%%----------------------------------------------------------------- log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, Start = null, Stop = null, log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). @@ -870,7 +870,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block) Stop = null, log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, Stop = null, log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). @@ -879,7 +879,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) Stop = null, log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop) -> @@ -888,7 +888,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop) -> log_to_io(LogDir, Mibs, LogName, LogFile) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, Start = null, Stop = null, log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). @@ -899,7 +899,7 @@ log_to_io(LogDir, Mibs, LogName, LogFile, Block) Stop = null, log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop); log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, Stop = null, log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). @@ -908,7 +908,7 @@ log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) Stop = null, log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop); log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index a749153ece..379abe933e 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -118,6 +118,7 @@ -include("snmp_verbosity.hrl"). -define(DEFAULT_AGENT_PORT, 161). +-define(ATL_BLOCK_DEFAULT, true). %% This function is called when the snmp application @@ -782,7 +783,7 @@ log_to_txt(LogDir, Block) LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, OutFile = "snmpm_log.txt", LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, @@ -804,7 +805,7 @@ log_to_txt(LogDir, Mibs, Block) LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, LogName = ?audit_trail_log_name, LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). @@ -826,7 +827,7 @@ log_to_txt(LogDir, Mibs, OutFile, Block) LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). @@ -848,7 +849,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, Block) LogFile = ?audit_trail_log_file, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block). -spec log_to_txt(LogDir :: snmp:dir(), @@ -870,7 +871,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block) when ((Block =:= true) orelse (Block =:= false)) -> snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start). -spec log_to_txt(LogDir :: snmp:dir(), @@ -894,7 +895,7 @@ log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) when ((Block =:= true) orelse (Block =:= false)) -> snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start); log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop). -spec log_to_txt(LogDir :: snmp:dir(), @@ -931,7 +932,7 @@ log_to_io(LogDir, Mibs, Block) LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). @@ -940,21 +941,21 @@ log_to_io(LogDir, Mibs, LogName, Block) LogFile = ?audit_trail_log_file, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName, LogFile) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block). log_to_io(LogDir, Mibs, LogName, LogFile, Block) when ((Block =:= true) orelse (Block =:= false)) -> snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block); log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start). log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) when ((Block =:= true) orelse (Block =:= false)) -> snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start); log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> - Block = false, + Block = ?ATL_BLOCK_DEFAULT, snmp:log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop). log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index de03c97281..ce3af66f88 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -52,8 +52,9 @@ -define(VMODULE,"LOG"). -include("snmp_verbosity.hrl"). --define(LOG_FORMAT, internal). --define(LOG_TYPE, wrap). +-define(LOG_FORMAT, internal). +-define(LOG_TYPE, wrap). +-define(BLOCK_DEFAULT, true). -record(snmp_log, {id, seqno}). @@ -400,7 +401,7 @@ do_change_size(Log, NewSize) -> %% log_to_txt(Log, FileName, Dir, Mibs, TextFile) -> - log_to_txt(Log, false, FileName, Dir, Mibs, TextFile). + log_to_txt(Log, ?BLOCK_DEFAULT, FileName, Dir, Mibs, TextFile). %% log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile) @@ -408,7 +409,7 @@ log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile) log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, null, null); %% log_to_txt(Log, FileName, Dir, Mibs, TextFile, Start) -> - log_to_txt(Log, false, FileName, Dir, Mibs, TextFile, Start, null). + log_to_txt(Log, ?BLOCK_DEFAULT, FileName, Dir, Mibs, TextFile, Start, null). %% log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start) @@ -416,7 +417,7 @@ log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start) log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start, null); %% log_to_txt(Log, FileName, Dir, Mibs, TextFile, Start, Stop) -> - log_to_txt(Log, false, FileName, Dir, Mibs, TextFile, Start, Stop). + log_to_txt(Log, ?BLOCK_DEFAULT, FileName, Dir, Mibs, TextFile, Start, Stop). %% log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start, Stop) @@ -443,7 +444,7 @@ log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start, Stop) %% log_to_io(Log, FileName, Dir, Mibs) -> - log_to_io(Log, false, FileName, Dir, Mibs, null, null). + log_to_io(Log, ?BLOCK_DEFAULT, FileName, Dir, Mibs, null, null). %% log_to_io(Log, Block, FileName, Dir, Mibs) @@ -451,7 +452,7 @@ log_to_io(Log, Block, FileName, Dir, Mibs) log_to_io(Log, Block, FileName, Dir, Mibs, null, null); %% log_to_io(Log, FileName, Dir, Mibs, Start) -> - log_to_io(Log, false, FileName, Dir, Mibs, Start, null). + log_to_io(Log, ?BLOCK_DEFAULT, FileName, Dir, Mibs, Start, null). %% log_to_io(Log, Block, FileName, Dir, Mibs, Start) @@ -459,7 +460,7 @@ log_to_io(Log, Block, FileName, Dir, Mibs, Start) log_to_io(Log, Block, FileName, Dir, Mibs, Start, null); %% log_to_io(Log, FileName, Dir, Mibs, Start, Stop) -> - log_to_io(Log, false, FileName, Dir, Mibs, Start, Stop). + log_to_io(Log, ?BLOCK_DEFAULT, FileName, Dir, Mibs, Start, Stop). %% log_to_io(Log, Block, FileName, Dir, Mibs, Start, Stop) diff --git a/lib/snmp/test/snmp_log_test.erl b/lib/snmp/test/snmp_log_test.erl index cbd843b8fe..fb7285110f 100644 --- a/lib/snmp/test/snmp_log_test.erl +++ b/lib/snmp/test/snmp_log_test.erl @@ -331,7 +331,7 @@ log_to_io1(doc) -> "Log to io from the same process that opened " log_to_io1(Config) when is_list(Config) -> p(log_to_io1), put(sname,l2i1), - put(verbosity,trace), + put(verbosity,debug), ?DBG("log_to_io1 -> start", []), Dir = ?config(log_dir, Config), Name = "snmp_test_l2i1", @@ -386,7 +386,7 @@ log_to_io2(Config) when is_list(Config) -> process_flag(trap_exit, true), p(log_to_io2), put(sname, l2i2), - put(verbosity,trace), + put(verbosity,debug), ?DBG("log_to_io2 -> start", []), Dir = ?config(log_dir, Config), Name = "snmp_test_l2i2", @@ -445,7 +445,7 @@ log_to_txt1(suite) -> []; log_to_txt1(Config) when is_list(Config) -> p(log_to_txt1), put(sname,l2t1), - put(verbosity,trace), + put(verbosity,debug), ?DBG("log_to_txt1 -> start", []), Name = "snmp_test_l2t1", @@ -463,7 +463,7 @@ log_to_txt2(suite) -> []; log_to_txt2(Config) when is_list(Config) -> p(log_to_txt2), put(sname,l2t2), - put(verbosity,trace), + put(verbosity,debug), ?DBG("log_to_txt2 -> start", []), Name = "snmp_test_l2t2", @@ -600,7 +600,7 @@ log_to_txt3(Config) when is_list(Config) -> process_flag(trap_exit, true), p(log_to_txt3), put(sname,l2t3), - put(verbosity,trace), + put(verbosity,debug), ?DBG("log_to_txt3 -> start", []), Dir = ?config(log_dir, Config), Name = "snmp_test_l2t3", -- cgit v1.2.3 From 470478847dcf03a88a517d281a25c3c92e9ae129 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 8 Oct 2013 16:34:38 +0200 Subject: Fix (unicode) debug info in test cases --- lib/snmp/test/snmp_agent_test.erl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 50336fcf6e..89a6ce1253 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -1524,11 +1524,11 @@ app_info(Config) when is_list(Config) -> false -> "undefined" end, - io:format("Root dir: ~s~n" - "SNMP: Application dir: ~s~n" - " Application ver: ~s~n" - "SSL: Application dir: ~s~n" - "CRYPTO: Application dir: ~s~n", + io:format("Root dir: ~ts~n" + "SNMP: Application dir: ~ts~n" + " Application ver: ~ts~n" + "SSL: Application dir: ~ts~n" + "CRYPTO: Application dir: ~ts~n", [code:root_dir(), SnmpDir, AppVsn, SslDir, CryptoDir]), ok. -- cgit v1.2.3 From 4853c542b6388decab8ae958f500ed155a641de5 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 27 Jan 2014 16:21:43 +0100 Subject: [snmp] Assigned proper version, updated release notes and appup OTP-10877 OTP-10907 --- lib/snmp/doc/src/notes.xml | 76 ++++++++++++++++++++++++++++++++++++++++- lib/snmp/src/app/snmp.appup.src | 12 +++---- lib/snmp/vsn.mk | 4 +-- 3 files changed, 82 insertions(+), 10 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index d213b67052..ab5514e550 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -4,7 +4,7 @@
- 19962013 + 19962014 Ericsson AB. All Rights Reserved. @@ -33,6 +33,80 @@
+
+ SNMP Development Toolkit 4.25.0.1 +

Version 4.25.0.1 supports code replacement in runtime from/to + version 4.25, 4.24.2, 4.24.1 and 4.24.

+ +
+ Improvements and new features + + + + +

Updated doc files to utf8.

+

Own Id: OTP-10907

+
+ + +

Fixed test suite to support UTF-8 paths.

+

Own Id: OTP-10877

+
+ +
+ +
+ +
+ Fixed Bugs and Malfunctions +

-

+ + + +
+ +
+ Incompatibilities +

-

+ + +
+ +
+ +
SNMP Development Toolkit 4.25

Version 4.25 supports code replacement in runtime from/to diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index fa4b72ab68..babc33e6a5 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2013. All Rights Reserved. +%% Copyright Ericsson AB 1999-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -28,11 +28,10 @@ %% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} %% {add_module, snmpm_net_if_mt} [ + {"4.25", [{restart_application, snmp}]}, {"4.24.2", [{restart_application, snmp}]}, {"4.24.1", [{restart_application, snmp}]}, - {"4.24", [{restart_application, snmp}]}, - {"4.23.1", [{restart_application, snmp}]}, - {"4.23", [{restart_application, snmp}]} + {"4.24", [{restart_application, snmp}]} ], %% ------D o w n g r a d e --------------------------------------------------- @@ -41,11 +40,10 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"4.25", [{restart_application, snmp}]}, {"4.24.2", [{restart_application, snmp}]}, {"4.24.1", [{restart_application, snmp}]}, - {"4.24", [{restart_application, snmp}]}, - {"4.23.1", [{restart_application, snmp}]}, - {"4.23", [{restart_application, snmp}]} + {"4.24", [{restart_application, snmp}]} ] }. diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 70f7c2b19a..533e313bdb 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2013. All Rights Reserved. +# Copyright Ericsson AB 1997-2014. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.25 +SNMP_VSN = 4.25.0.1 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 841addf5d64a3b4775cd1d0a5aa4bf04ec4ef95e Mon Sep 17 00:00:00 2001 From: Tobias Schlager Date: Tue, 18 Feb 2014 12:33:31 +0100 Subject: Add test suites performing app and appup file checks Add the mentioned test suites for *all* library and touched non-library applications. --- lib/snmp/test/snmp_appup_test.erl | 491 +------------------------------------- 1 file changed, 3 insertions(+), 488 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_appup_test.erl b/lib/snmp/test/snmp_appup_test.erl index 99994a2410..021d42a978 100644 --- a/lib/snmp/test/snmp_appup_test.erl +++ b/lib/snmp/test/snmp_appup_test.erl @@ -63,33 +63,9 @@ end_per_group(_GroupName, Config) -> init_per_suite(suite) -> []; init_per_suite(doc) -> []; init_per_suite(Config) when is_list(Config) -> - PrivDir = ?config(priv_dir, Config), - TopDir = filename:join(PrivDir, appup), - case file:make_dir(TopDir) of - ok -> - ok; - Error -> - fail({failed_creating_subsuite_top_dir, Error}) - end, - AppFile = file_name(?APPLICATION, ".app"), - AppupFile = file_name(?APPLICATION, ".appup"), - [{app_file, AppFile}, - {appup_file, AppupFile}, - {appup_topdir, TopDir} | Config]. + Config. -file_name(App, Ext) -> - Env = init:get_arguments(), - LibDir = - case lists:keysearch(clearcase, 1, Env) of - false -> - code:lib_dir(App); - _ -> - ".." - end, - filename:join([LibDir, "ebin", atom_to_list(App) ++ Ext]). - - end_per_suite(suite) -> []; end_per_suite(doc) -> []; end_per_suite(Config) when is_list(Config) -> @@ -108,467 +84,6 @@ end_per_testcase(_Case, Config) when is_list(Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -appup_file(suite) -> - []; -appup_file(doc) -> - "Perform a simple check of the appup file"; +%% Perform a simple check of the appup file appup_file(Config) when is_list(Config) -> - AppupFile = key1search(appup_file, Config), - AppFile = key1search(app_file, Config), - Modules = modules(AppFile), - check_appup(AppupFile, Modules). - -modules(File) -> - case file:consult(File) of - {ok, [{application,snmp,Info}]} -> - case lists:keysearch(modules,1,Info) of - {value, {modules, Modules}} -> - Modules; - false -> - fail({bad_appinfo, Info}) - end; - Error -> - fail({bad_appfile, Error, File}) - end. - - -check_appup(AppupFile, Modules) -> - case file:consult(AppupFile) of - {ok, [{V, UpFrom, DownTo}]} -> - check_appup(V, UpFrom, DownTo, Modules); - Else -> - fail({bad_appupfile, Else}) - end. - - -check_appup(V, UpFrom, DownTo, Modules) -> - check_version(V), - check_depends(up, UpFrom, Modules), - check_depends(down, DownTo, Modules), - check_module_subset(up, UpFrom), - check_module_subset(down, DownTo), - ok. - -check_depends(_, [], _) -> - ok; -check_depends(UpDown, [Dep|Deps], Modules) -> - check_depend(UpDown, Dep, Modules), - check_depends(UpDown, Deps, Modules). - - -check_depend(up = UpDown, {add_application, ?APPLICATION} = Instr, Modules) -> - d("check_instructions(~w) -> entry with" - "~n Instruction: ~p" - "~n Modules: ~p", [UpDown, Instr, Modules]), - ok; -check_depend(down = UpDown, {remove_application, ?APPLICATION} = Instr, - Modules) -> - d("check_instructions(~w) -> entry with" - "~n Instruction: ~p" - "~n Modules: ~p", [UpDown, Instr, Modules]), - ok; -check_depend(UpDown, {V, Instructions}, Modules) -> - d("check_instructions(~w) -> entry with" - "~n V: ~p" - "~n Modules: ~p", [UpDown, V, Modules]), - check_version(V), - case check_instructions(UpDown, - Instructions, Instructions, [], [], Modules) of - {_Good, []} -> - ok; - {_, Bad} -> - fail({bad_instructions, Bad, UpDown}) - end. - - -check_instructions(_, [], _, Good, Bad, _) -> - {lists:reverse(Good), lists:reverse(Bad)}; -check_instructions(UpDown, [Instr|Instrs], AllInstr, Good, Bad, Modules) -> - d("check_instructions(~w) -> entry with" - "~n Instr: ~p", [UpDown,Instr]), - case (catch check_instruction(UpDown, Instr, AllInstr, Modules)) of - ok -> - check_instructions(UpDown, Instrs, AllInstr, - [Instr|Good], Bad, Modules); - {error, Reason} -> - check_instructions(UpDown, Instrs, AllInstr, Good, - [{Instr, Reason}|Bad], Modules) - end; -check_instructions(UpDown, Instructions, _, _, _, _) -> - fail({bad_instructions, {UpDown, Instructions}}). - -check_instruction(_, {restart_application, ?APPLICATION}, _, _Modules) -> - d("check_instruction -> entry when restart_application instruction"), - ok; - -%% A new module is added -check_instruction(up, {add_module, Module}, _, Modules) - when is_atom(Module) -> - d("check_instruction -> entry when up-add_module instruction with" - "~n Module: ~p", [Module]), - check_module(Module, Modules); - -%% An old module is re-added -check_instruction(down, {add_module, Module}, _, Modules) - when is_atom(Module) -> - d("check_instruction -> entry when down-add_module instruction with" - "~n Module: ~p", [Module]), - case (catch check_module(Module, Modules)) of - {error, {unknown_module, Module, Modules}} -> - ok; - ok -> - error({existing_readded_module, Module}) - end; - -check_instruction(up, {delete_module, Module}, _, Modules) - when is_atom(Module) -> - d("check_instruction -> entry when up-delete_module instruction with" - "~n Module: ~p", [Module]), - case (catch check_module(Module, Modules)) of - {error, {unknown_module, Module, Modules}} -> - ok; - ok -> - error({module_cannot_be_deleted, Module}) - end; - -%% An new module is deleted -check_instruction(down, {delete_module, Module}, _, Modules) - when is_atom(Module) -> - d("check_instruction -> entry when down-delete_module instruction with" - "~n Module: ~p", [Module]), - check_module(Module, Modules); - -%% Removing a module on upgrade: -%% - the module has been removed from the app-file. -%% - check that no module depends on this (removed) module -check_instruction(up, {remove, {Module, Pre, Post}}, _, Modules) - when is_atom(Module) and is_atom(Pre) and is_atom(Post) -> - d("check_instruction -> entry when up-remove instruction with" - "~n Module: ~p" - "~n Pre: ~p" - "~n Post: ~p", [Module, Pre, Post]), - case (catch check_module(Module, Modules)) of - {error, {unknown_module, Module, Modules}} -> - check_purge(Pre), - check_purge(Post); - ok -> - error({existing_removed_module, Module}) - end; - -%% Removing a module on downgrade: the module exist -%% in the app-file. -check_instruction(down, {remove, {Module, Pre, Post}}, AllInstr, Modules) - when is_atom(Module) and is_atom(Pre) and is_atom(Post) -> - d("check_instruction -> entry when down-remove instruction with" - "~n Module: ~p" - "~n Pre: ~p" - "~n Post: ~p", [Module, Pre, Post]), - case (catch check_module(Module, Modules)) of - ok -> - check_purge(Pre), - check_purge(Post), - check_no_remove_depends(Module, AllInstr); - {error, {unknown_module, Module, Modules}} -> - error({nonexisting_removed_module, Module}) - end; - -check_instruction(_, {load_module, Module, Pre, Post, Depend}, - AllInstr, Modules) - when is_atom(Module) and - is_atom(Pre) and - is_atom(Post) and - is_list(Depend) -> - d("check_instruction -> entry when load_module instruction with" - "~n Module: ~p" - "~n Pre: ~p" - "~n Post: ~p" - "~n Depend: ~p", [Module, Pre, Post, Depend]), - check_module(Module, Modules), - check_module_depend(Module, Depend, Modules), - check_module_depend(Module, Depend, updated_modules(AllInstr, [])), - check_purge(Pre), - check_purge(Post); - -check_instruction(_, {update, Module, Change, Pre, Post, Depend}, - AllInstr, Modules) - when is_atom(Module) and - is_atom(Pre) and - is_atom(Post) and - is_list(Depend) -> - d("check_instruction -> entry when update instruction with" - "~n Module: ~p" - "~n Change: ~p" - "~n Pre: ~p" - "~n Post: ~p" - "~n Depend: ~p", [Module, Change, Pre, Post, Depend]), - check_module(Module, Modules), - check_module_depend(Module, Depend, Modules), - check_module_depend(Module, Depend, updated_modules(AllInstr, [])), - check_change(Change), - check_purge(Pre), - check_purge(Post); - -check_instruction(_, {update, Module, supervisor}, _, Modules) - when is_atom(Module) -> - d("check_instruction -> entry when supervisor update instruction with" - "~n Module: ~p", [Module]), - check_module(Module, Modules); - -check_instruction(_, {apply, {Module, Function, Args}}, _, _Modules) - when is_atom(Module) and is_atom(Function) and is_list(Args) -> - d("check_instruction -> entry when apply instruction with" - "~n Module: ~p" - "~n Function: ~p" - "~n Args: ~p", [Module, Function, Args]), - check_apply(Module, Function, Args); - -check_instruction(_, Instr, _AllInstr, _Modules) -> - error({error, {unknown_instruction, Instr}}). - -%% If Module X depends on Module Y, then module Y must have an update -%% instruction of some sort (otherwise the depend is faulty). -updated_modules([], Modules) -> - d("updated_modules -> entry when done with" - "~n Modules: ~p", [Modules]), - Modules; -updated_modules([Instr|Instrs], Modules) -> - d("updated_modules -> entry with" - "~n Instr: ~p" - "~n Modules: ~p", [Instr,Modules]), - case instruction_module(Instr) of - {module, Module} -> - d("updated_modules -> Module: ~p", [Module]), - updated_modules(Instrs, [Module|Modules]); - no_module -> - updated_modules(Instrs, Modules) - end. - -instruction_module({add_module, Module}) -> - {module, Module}; -instruction_module({delete_module, Module}) -> - {module, Module}; -instruction_module({remove, {Module, _, _}}) -> - {module, Module}; -instruction_module({load_module, Module, _, _, _}) -> - {module, Module}; -instruction_module({update, Module, _, _, _, _}) -> - {module, Module}; -instruction_module({update, Module, _}) -> - {module, Module}; -instruction_module({apply, {_, _, _}}) -> - no_module; -instruction_module(Instr) -> - d("instruction_module -> entry when unknown instruction with" - "~n Instr: ~p", [Instr]), - error({error, {unknown_instruction, Instr}}). - - -%% Check that the modules handled in an instruction set for version X -%% is a subset of the instruction set for version X-1. -check_module_subset(Direction, Instructions) -> - d("check_module_subset(~w) -> entry when" - "~n Instructions: ~p", [Direction,Instructions]), - do_check_module_subset(modules_of(Instructions)). - -do_check_module_subset([]) -> - ok; -do_check_module_subset([_]) -> - ok; -do_check_module_subset([{_V1, Mods1}|T]) -> - d("do_check_module_subset -> entry with" - "~n V1: ~s" - "~n Mods1: ~p", [_V1, Mods1]), - {V2, Mods2} = hd(T), - d("do_check_module_subset -> " - "~n V2: ~s" - "~n Mods2: ~p", [V2, Mods2]), - %% Check that the modules in V1 is a subset of V2 - case do_check_module_subset2(Mods1, Mods2) of - ok -> - do_check_module_subset(T); - {error, Modules} -> - fail({subset_missing_instructions, V2, Modules}) - end. - -do_check_module_subset2(_Mods1, [{restart_application, ?APPLICATION}]) -> - ok; -do_check_module_subset2(Mods1, Mods2) -> - do_check_module_subset2(Mods1, Mods2, []). - -do_check_module_subset2([], _, []) -> - ok; -do_check_module_subset2([], _, Acc) -> - {error, lists:reverse(Acc)}; -do_check_module_subset2([Mod|Mods], Mods2, Acc) -> - case lists:member(Mod, Mods2) of - true -> - do_check_module_subset2(Mods, Mods2, Acc); - false -> - do_check_module_subset2(Mods, Mods2, [Mod|Acc]) - end. - - -modules_of(Instructions) -> - modules_of(Instructions, []). - -modules_of([], Acc) -> - lists:reverse(Acc); -modules_of([{_V,[{restart_application, ?APPLICATION}]}|T], Acc) -> - modules_of(T, Acc); -modules_of([{V,Instructions}|T], Acc) -> - Mods = modules_of2(Instructions, []), - modules_of(T, [{V, Mods}|Acc]). - -modules_of2([], Acc) -> - lists:reverse(Acc); -modules_of2([Instr|Instructions], Acc) -> - d("module_of -> entry with" - "~n Instr: ~p", [Instr]), - case module_of(Instr) of - {value, Mod} -> - d("module_of -> Mod: ~p", [Mod]), - modules_of2(Instructions, [Mod|Acc]); - false -> - modules_of2(Instructions, Acc) - end. - -module_of({add_module, Module}) -> - {value, Module}; -module_of({delete_module, Module}) -> - {value, Module}; -module_of({remove, {Module, _Pre, _Post}}) -> - {value, Module}; -module_of({load_module, Module, _Pre, _Post, _Depend}) -> - {value, Module}; -module_of({update, Module, _Change, _Pre, _Post, _Depend}) -> - {value, Module}; -module_of({update, Module, supervisor}) -> - {value, Module}; -module_of(_) -> - false. - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -check_version(V) when is_list(V) -> - ok; -check_version(V) -> - error({bad_version, V}). - - -check_module(M, Modules) when is_atom(M) -> - case lists:member(M, Modules) of - true -> - ok; - false -> - error({unknown_module, M, Modules}) - end; -check_module(M, _) -> - error({bad_module, M}). - - -check_module_depend(M, [], _) when is_atom(M) -> - ok; -check_module_depend(M, Deps, Modules) when is_atom(M) and is_list(Deps) -> - case [Dep || Dep <- Deps, lists:member(Dep, Modules) == false] of - [] -> - ok; - Unknown -> - error({unknown_depend_modules, Unknown}) - end; -check_module_depend(_M, D, _Modules) -> - error({bad_depend, D}). - - -check_no_remove_depends(_Module, []) -> - ok; -check_no_remove_depends(Module, [Instr|Instrs]) -> - check_no_remove_depend(Module, Instr), - check_no_remove_depends(Module, Instrs). - -check_no_remove_depend(Module, {load_module, Mod, _Pre, _Post, Depend}) -> - case lists:member(Module, Depend) of - true -> - error({removed_module_in_depend, load_module, Mod, Module}); - false -> - ok - end; -check_no_remove_depend(Module, {update, Mod, _Change, _Pre, _Post, Depend}) -> - case lists:member(Module, Depend) of - true -> - error({removed_module_in_depend, update, Mod, Module}); - false -> - ok - end; -check_no_remove_depend(_, _) -> - ok. - - -check_change(soft) -> - ok; -check_change({advanced, _Something}) -> - ok; -check_change(Change) -> - error({bad_change, Change}). - - -check_purge(soft_purge) -> - ok; -check_purge(brutal_purge) -> - ok; -check_purge(Purge) -> - error({bad_purge, Purge}). - -check_apply(Module, Function, Args) -> - case (catch Module:module_info()) of - Info when is_list(Info) -> - check_exported(Function, Args, Info); - {'EXIT', {undef, _}} -> - error({not_existing_module, Module}) - end. - -check_exported(Function, Args, Info) -> - case lists:keysearch(exports, 1, Info) of - {value, {exports, FuncList}} -> - Arity = length(Args), - Arities = [A || {F, A} <- FuncList, F == Function], - case lists:member(Arity, Arities) of - true -> - ok; - false -> - fail({not_exported_function, Function, Arity}) - end; - _ -> - error({bad_export, Info}) - end. - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -error(Reason) -> - throw({error, Reason}). - -fail(Reason) -> - exit({suite_failed, Reason}). - -key1search(Key, L) -> - case lists:keysearch(Key, 1, L) of - undefined -> - fail({not_found, Key, L}); - {value, {Key, Value}} -> - Value - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -d(F) -> - d(F, []). - -d(F, A) -> - d(true, F, A). - -d(true, F, A) -> - io:format(F ++ "~n", A); -d(_, _, _) -> - ok. - + ok = ?t:appup_test(snmp). -- cgit v1.2.3 From bcfc2e4770123f067c346d96b11d9382ff2b6bcc Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 13 Mar 2014 16:17:40 +0100 Subject: [snmp/agent] Fixed the loop_mib test cases --- lib/snmp/test/Makefile | 4 +- lib/snmp/test/snmp_agent_test.erl | 91 ++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 46 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index f22b7ea8ee..7bc9dd07d4 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -93,10 +93,10 @@ ifeq ($(SNMP_DEBUG),e) SNMP_FLAGS += -Dsnmp_error endif ifeq ($(SNMP_DEBUG),l) - SNMP_FLAGS += -Dsnmp_log + SNMP_FLAGS += -Dsnmp_error -Dsnmp_log endif ifeq ($(SNMP_DEBUG),d) - SNMP_FLAGS += -Dsnmp_debug + SNMP_FLAGS += -Dsnmp_error -Dsnmp_log -Dsnmp_debug endif ifeq ($(DONT_USE_TS),true) diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 89a6ce1253..84fa1af71d 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -19,10 +19,6 @@ -module(snmp_agent_test). -%% TODO -%% * Test fault-tolerance (kill master etc) -%% - -export([ all/0, groups/0, @@ -41,7 +37,7 @@ v1_processing/1, big/1, big2/1, - loop_mib/1, + loop_mib_1/1, api/1, subagent/1, mnesia/1, @@ -394,8 +390,9 @@ usm_read/0, usm_del_user/0, usm_bad/0, - loop_mib_1/0, - loop_mib_2/0, + loop_mib_1_test/0, + loop_mib_2_test/0, + loop_mib_3_test/0, otp_1129_i/1, otp_1162_test/0, otp_1131_test/0, @@ -1173,7 +1170,7 @@ mse_simple(X) -> ?P(mse_simple), simple(X). mse_v1_processing(X) -> ?P(mse_v1_processing), v1_processing(X). mse_big(X) -> ?P(mse_big), big(X). mse_big2(X) -> ?P(mse_big2), big2(X). -mse_loop_mib(X) -> ?P(mse_loop_mib), loop_mib(X). +mse_loop_mib(X) -> ?P(mse_loop_mib), loop_mib_1(X). mse_api(X) -> ?P(mse_api), api(X). mse_sa_register(X) -> ?P(mse_sa_register), sa_register(X). mse_v1_trap(X) -> ?P(mse_v1_trap), v1_trap(X). @@ -1194,7 +1191,7 @@ msd_simple(X) -> ?P(msd_simple), simple(X). msd_v1_processing(X) -> ?P(msd_v1_processing), v1_processing(X). msd_big(X) -> ?P(msd_big), big(X). msd_big2(X) -> ?P(msd_big2), big2(X). -msd_loop_mib(X) -> ?P(msd_loop_mib), loop_mib(X). +msd_loop_mib(X) -> ?P(msd_loop_mib), loop_mib_1(X). msd_api(X) -> ?P(msd_api), api(X). msd_sa_register(X) -> ?P(msd_sa_register), sa_register(X). msd_v1_trap(X) -> ?P(msd_v1_trap), v1_trap(X). @@ -1215,7 +1212,7 @@ msm_simple(X) -> ?P(msm_simple), simple(X). msm_v1_processing(X) -> ?P(msm_v1_processing), v1_processing(X). msm_big(X) -> ?P(msm_big2), big(X). msm_big2(X) -> ?P(msm_loop_mib), big2(X). -msm_loop_mib(X) -> ?P(msm_loop_mib), loop_mib(X). +msm_loop_mib(X) -> ?P(msm_loop_mib), loop_mib_1(X). msm_api(X) -> ?P(msm_api), api(X). msm_sa_register(X) -> ?P(msm_sa_register), sa_register(X). msm_v1_trap(X) -> ?P(msm_v1_trap), v1_trap(X). @@ -1618,7 +1615,7 @@ v1_cases() -> v1_processing, big, big2, - loop_mib, + loop_mib_1, api, subagent, mnesia, @@ -5516,46 +5513,48 @@ usm_bad() -> %% works. %% Load all std mibs that are not loaded by default. %%----------------------------------------------------------------- -loop_mib(suite) -> []; -loop_mib(Config) when is_list(Config) -> - ?P(loop_mib), - ?LOG("loop_mib -> initiate case",[]), +loop_mib_1(suite) -> []; +loop_mib_1(Config) when is_list(Config) -> + ?P(loop_mib_1), + ?LOG("loop_mib_1 -> initiate case",[]), %% snmpa:verbosity(master_agent,debug), %% snmpa:verbosity(mib_server,info), {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib -> ~n" + ?DBG("loop_mib_1 -> ~n" "\tSaNode: ~p~n" "\tMgrNode: ~p~n" "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), - ?DBG("loop_mib -> load mib SNMP-COMMUNITY-MIB",[]), + ?DBG("loop_mib_1 -> load mib SNMP-COMMUNITY-MIB",[]), ?line load_master_std("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> load mib SNMP-MPD-MIB",[]), + ?DBG("loop_mib_1 -> load mib SNMP-MPD-MIB",[]), ?line load_master_std("SNMP-MPD-MIB"), - ?DBG("loop_mib -> load mib SNMP-TARGET-MIB",[]), + ?DBG("loop_mib_1 -> load mib SNMP-TARGET-MIB",[]), ?line load_master_std("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> load mib SNMP-NOTIFICATION-MIB",[]), + ?DBG("loop_mib_1 -> load mib SNMP-NOTIFICATION-MIB",[]), ?line load_master_std("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> load mib SNMP-FRAMEWORK-MIB",[]), + ?DBG("loop_mib_1 -> load mib SNMP-FRAMEWORK-MIB",[]), ?line load_master_std("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?DBG("loop_mib_1 -> load mib SNMP-VIEW-BASED-ACM-MIB",[]), ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - ?DBG("loop_mib -> try",[]), - try_test(loop_mib_1), - ?DBG("loop_mib -> unload mib SNMP-COMMUNITY-MIB",[]), + ?DBG("loop_mib_1 -> try",[]), + + try_test(loop_mib_1_test), + + ?DBG("loop_mib_1 -> unload mib SNMP-COMMUNITY-MIB",[]), ?line unload_master("SNMP-COMMUNITY-MIB"), - ?DBG("loop_mib -> unload mib SNMP-MPD-MIB",[]), + ?DBG("loop_mib_1 -> unload mib SNMP-MPD-MIB",[]), ?line unload_master("SNMP-MPD-MIB"), - ?DBG("loop_mib -> unload mib SNMP-TARGET-MIB",[]), + ?DBG("loop_mib_1 -> unload mib SNMP-TARGET-MIB",[]), ?line unload_master("SNMP-TARGET-MIB"), - ?DBG("loop_mib -> unload mib SNMP-NOTIFICATION-MIB",[]), + ?DBG("loop_mib_1 -> unload mib SNMP-NOTIFICATION-MIB",[]), ?line unload_master("SNMP-NOTIFICATION-MIB"), - ?DBG("loop_mib -> unload mib SNMP-FRAMEWORK-MIB",[]), + ?DBG("loop_mib_1 -> unload mib SNMP-FRAMEWORK-MIB",[]), ?line unload_master("SNMP-FRAMEWORK-MIB"), - ?DBG("loop_mib -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), + ?DBG("loop_mib_1 -> unload mib SNMP-VIEW-BASED-ACM-MIB",[]), ?line unload_master("SNMP-VIEW-BASED-ACM-MIB"), %% snmpa:verbosity(master_agent,log), %% snmpa:verbosity(mib_server,silence), - ?LOG("loop_mib -> done",[]). + ?LOG("loop_mib_1 -> done",[]). loop_mib_2(suite) -> []; @@ -5563,7 +5562,7 @@ loop_mib_2(Config) when is_list(Config) -> ?P(loop_mib_2), ?LOG("loop_mib_2 -> initiate case",[]), {SaNode, MgrNode, MibDir} = init_case(Config), - ?DBG("loop_mib_2 -> ~n" + ?DBG("do_loop_mib_2 -> ~n" "\tSaNode: ~p~n" "\tMgrNode: ~p~n" "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), @@ -5574,7 +5573,9 @@ loop_mib_2(Config) when is_list(Config) -> ?line load_master_std("SNMP-NOTIFICATION-MIB"), ?line load_master_std("SNMP-FRAMEWORK-MIB"), ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), - try_test(loop_mib_2), + + try_test(loop_mib_2_test), + ?DBG("loop_mib_2 -> unload mibs",[]), ?line unload_master("SNMP-COMMUNITY-MIB"), ?line unload_master("SNMP-MPD-MIB"), @@ -5600,7 +5601,7 @@ loop_mib_3(Config) when is_list(Config) -> ?line load_master_std("SNMP-VIEW-BASED-ACM-MIB"), ?line load_master_std("SNMP-USER-BASED-SM-MIB"), - try_test(loop_mib_2), + try_test(loop_mib_3_test), ?DBG("loop_mib_3 -> unload mibs",[]), ?line unload_master("SNMP-TARGET-MIB"), @@ -5611,17 +5612,16 @@ loop_mib_3(Config) when is_list(Config) -> %% Req. As many mibs all possible -loop_mib_1() -> - ?DBG("loop_mib_1 -> entry",[]), +loop_mib_1_test() -> + ?DBG("loop_mib_1_test -> entry",[]), N = loop_it_1([1,1], 0), io:format(user, "found ~w varibles\n", [N]), ?line N = if N < 100 -> 100; true -> N end. - loop_it_1(Oid, N) -> - ?DBG("loop_it_1 -> entry with~n" + ?DBG("loop_it_1_test -> entry with~n" "\tOid: ~p~n" "\tN: ~p",[Oid,N]), case get_next_req([Oid]) of @@ -5630,11 +5630,11 @@ loop_it_1(Oid, N) -> error_index = 0, varbinds = [#varbind{oid = NOid, value = Value}]} when NOid > Oid -> - ?DBG("loop_it_1 -> " + ?DBG("loop_it_1_test -> " "~n NOid: ~p" "~n Value: ~p",[NOid, Value]), ?line [Value2] = get_req(1, [NOid]), % must not be same - ?DBG("loop_it_1 -> " + ?DBG("loop_it_1_test -> " "~n Value2: ~p",[Value2]), loop_it_1(NOid, N+1); @@ -5648,7 +5648,7 @@ loop_it_1(Oid, N) -> error_status = noSuchName, error_index = 1, varbinds = [_]} -> - ?DBG("loop_it_1 -> done: ~p",[N]), + ?DBG("loop_it_1_test -> done: ~p",[N]), N; #pdu{type = 'get-response', @@ -5669,14 +5669,13 @@ loop_it_1(Oid, N) -> %% Req. As many mibs all possible -loop_mib_2() -> - ?DBG("loop_mib_1 -> entry",[]), +loop_mib_2_test() -> + ?DBG("loop_mib_2_test -> entry",[]), N = loop_it_2([1,1], 0), io:format(user, "found ~w varibles\n", [N]), ?line N = if N < 100 -> 100; true -> N end. - loop_it_2(Oid, N) -> ?DBG("loop_it_2 -> entry with" @@ -5744,6 +5743,10 @@ loop_it_2(Oid, N) -> end. +loop_mib_3_test() -> + ?DBG("loop_mib_3_test -> entry",[]), + loop_mib_2_test(). + %%%----------------------------------------------------------------- %%% Testing of reported bugs and other tickets. -- cgit v1.2.3 From 3e8aa3462a151d6b528bab917bfa7b4aab021ba5 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 14 Mar 2014 18:41:23 +0100 Subject: [snmp/agent] Fixed request id generation When testing the agent, it is started and then used for a series (v1, v2, v3, ...) of tests. But the individual test cases are use one instance of the test manager. Because of this, the requerst id cannot be a counter starting from 1 or any counter for that matter. Instead every request id was generated using random. But this is obiously not a guarantee fo uniqueness, it merely makes it unlikely that the request ids will be reused. To get around this problem (without having to rewrite the entire agent test suite) a simple (global) counter server is introduced. It is started at the start of the agent test suite (init_per_suite) and stopped at the end (end_per_suite). --- lib/snmp/test/modules.mk | 3 +- lib/snmp/test/snmp_agent_test.erl | 13 +++ lib/snmp/test/snmp_test_mgr.erl | 3 +- lib/snmp/test/snmp_test_mgr_counter_server.erl | 152 +++++++++++++++++++++++++ 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 lib/snmp/test/snmp_test_mgr_counter_server.erl (limited to 'lib/snmp') diff --git a/lib/snmp/test/modules.mk b/lib/snmp/test/modules.mk index 3d658bf8e8..fd8315ec4d 100644 --- a/lib/snmp/test/modules.mk +++ b/lib/snmp/test/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2012. All Rights Reserved. +# Copyright Ericsson AB 2004-2014. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -42,6 +42,7 @@ TEST_UTIL_MODULES = \ snmp_test_manager \ snmp_test_mgr \ snmp_test_mgr_misc \ + snmp_test_mgr_counter_server \ sa \ klas3 \ test1 \ diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 84fa1af71d..a6571548d6 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -555,6 +555,8 @@ init_per_suite(Config0) when is_list(Config0) -> Config3 = [{mib_dir, MibDir}, {std_mib_dir, StdMibDir} | Config2], + snmp_test_mgr_counter_server:start(), + ?DBG("init_per_suite -> end with" "~n Config3: ~p", [Config3]), @@ -565,6 +567,17 @@ end_per_suite(Config) when is_list(Config) -> ?DBG("end_per_suite -> entry with" "~n Config: ~p", [Config]), + case snmp_test_mgr_counter_server:stop() of + {ok, Counters} -> + ?DBG("end_per_suite -> sucessfully stopped counter server" + "~n Counters: ~p", [Counters]); + + {error, Reason} -> + ?DBG("end_per_suite -> failed stopping counter server" + "~n Reason: ~p", [Reason]) + end, + + ?DBG("end_per_suite -> end", []), Config. diff --git a/lib/snmp/test/snmp_test_mgr.erl b/lib/snmp/test/snmp_test_mgr.erl index 40fcbce8f1..d4eb00ff91 100644 --- a/lib/snmp/test/snmp_test_mgr.erl +++ b/lib/snmp/test/snmp_test_mgr.erl @@ -657,7 +657,8 @@ make_vb(Oid) -> #varbind{oid = Oid, variabletype = 'NULL', value = 'NULL'}. make_request_id() -> - random:uniform(16#FFFFFFF-1). + %% random:uniform(16#FFFFFFF-1). + snmp_test_mgr_counter_server:increment(mgr_request_id, 1, 1, 2147483647). echo_pdu(PDU, MiniMIB) -> io:format("~s", [snmp_misc:format_pdu(PDU, MiniMIB)]). diff --git a/lib/snmp/test/snmp_test_mgr_counter_server.erl b/lib/snmp/test/snmp_test_mgr_counter_server.erl new file mode 100644 index 0000000000..db31e0380b --- /dev/null +++ b/lib/snmp/test/snmp_test_mgr_counter_server.erl @@ -0,0 +1,152 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2014-2014. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +%% +%% The reason for this (test) counter server is that the +%% agent test suite is implemented in such a way that the +%% agent is started once and then used for several test cases. +%% Each request is given a request id which *was* generated using +%% random! It is therefor possible, although unlikely, that a +%% request may get a request id that has recently been used, +%% which will cause the agent to silently reject the request. +%% For this reason, we start this server at the start of the +%% agent suite and stop it at the end and all request ids are +%% generated by this server. +%% + +-module(snmp_test_mgr_counter_server). + +-export([start/0, stop/0, increment/4]). + +-define(SERVER, ?MODULE). +-define(TAB, snmp_test_mgr_counter_tab). + + +%%%------------------------------------------------------------------- +%%% API +%%%------------------------------------------------------------------- + +-spec start() -> ok. + +start() -> + Parent = self(), + ReqIdServer = spawn(fun() -> init(Parent) end), + receive + {ReqIdServer, ok} -> + ok; + {ReqIdServer, {error, Reason}} -> + exit({failed_starting_counter_server, Reason}) + after 5000 -> + exit(ReqIdServer, kill), % Cleanup, just in case + exit({failed_starting_counter_server, timeout}) + end. + +-spec stop() -> {ok, Counters :: list()} | {error, Reason :: term()}. + +stop() -> + request(stop). + + +-spec increment(Counter :: atom(), + Initial :: non_neg_integer(), + Increment :: pos_integer(), + Max :: pos_integer()) -> + Next :: pos_integer(). + +increment(Counter, Initial, Increment, Max) -> + Request = {increment, Counter, Initial, Increment, Max}, + case request(Request) of + {ok, ReqId} -> + ReqId; + {error, Reason} -> + exit(Reason) + end. + + +request(Request) -> + Id = make_ref(), + Msg = {self(), Id, Request}, + try + begin + global:send(?SERVER, Msg), + receive + {reply, Id, Reply} -> + {ok, Reply} + end + end + catch + T:E -> + {error, {T, E}} + end. + + +%%%------------------------------------------------------------------- +%%% Internal functions +%%%------------------------------------------------------------------- + +init(Parent) -> + p("starting"), + case global:register_name(?SERVER, self()) of + yes -> + p("name registration ok"), + Parent ! {self(), ok}; + no -> + p("name registration failed"), + Parent ! {self(), registration_failed}, + exit(registration_failed) + end, + ets:new(?TAB, [set, named_table, {keypos, 1}]), + loop(). + +loop() -> + receive + {From, Id, {increment, Counter, Initial, Increment, Max}} -> + Position = 2, + Threshold = Max, + SetValue = Initial, + UpdateOp = {Position, Increment, Threshold, SetValue}, + NextVal = + try ets:update_counter(?TAB, Counter, UpdateOp) of + Next when is_integer(Next) -> + p("increment ~w: (next) ~w", [Counter, Next]), + Next + catch + error:badarg -> + %% Oups, first time + p("increment ~w: (initial) ~w", [Counter, Initial]), + ets:insert(?TAB, {Counter, Initial}), + Initial + end, + From ! {reply, Id, NextVal}, + loop(); + + {From, Id, stop} -> + p("stop"), + Counters = ets:tab2list(?TAB), + From ! {reply, Id, Counters}, + exit(normal) + end. + + +p(F) -> + p(F, []). + +p(F, A) -> + io:format("*** [~s] COUNTER-SERVER [~w] " ++ F ++ "~n", + [snmp_test_lib:formated_timestamp(), self() | A]). -- cgit v1.2.3 From 66280266a4b9147ea683836e2409a2ad1f2a78af Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 26 Feb 2014 11:24:06 +0100 Subject: Change encoding for XML files to utf-8 These are some files that were erronously missed earlier: erts/doc/src/time_correction.xml lib/crypto/doc/src/crypto_app.xml lib/snmp/doc/src/snmpa_mib_data.xml lib/snmp/doc/src/snmpa_mib_storage.xml --- lib/snmp/doc/src/snmpa_mib_data.xml | 4 ++-- lib/snmp/doc/src/snmpa_mib_storage.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/snmpa_mib_data.xml b/lib/snmp/doc/src/snmpa_mib_data.xml index c1ea0a91f9..95a33e603e 100644 --- a/lib/snmp/doc/src/snmpa_mib_data.xml +++ b/lib/snmp/doc/src/snmpa_mib_data.xml @@ -1,10 +1,10 @@ - +

- 20132013 + 20132014 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_mib_storage.xml b/lib/snmp/doc/src/snmpa_mib_storage.xml index a857ce79e8..791fbc80fe 100644 --- a/lib/snmp/doc/src/snmpa_mib_storage.xml +++ b/lib/snmp/doc/src/snmpa_mib_storage.xml @@ -1,10 +1,10 @@ - +
- 20132013 + 20132014 Ericsson AB. All Rights Reserved. -- cgit v1.2.3 From be9af84e6aed398a0be6cb2a17daabfca5a70779 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Mon, 17 Mar 2014 15:59:54 +0100 Subject: [snmp/manager] Verify success for app start and stop in test cases When starting and stopping apps verify success. If failure to start or stop app force failure of test case or init/fin of test case. Also, be more verbose regarding stop results during test case finish. --- lib/snmp/test/snmp_manager_test.erl | 143 +++++++++++++++++++++++++++--------- 1 file changed, 109 insertions(+), 34 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 5fe18980bc..ab757bc166 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2013. All Rights Reserved. +%% Copyright Ericsson AB 2003-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -5328,9 +5328,14 @@ init_manager(AutoInform, Config) -> fin_manager(Config) -> Node = ?config(manager_node, Config), - stop_manager(Node, Config), - fin_crypto(Node), - stop_node(Node), + StopMgrRes = stop_manager(Node), + StopCryptoRes = fin_crypto(Node), + StopNode = stop_node(Node), + p("fin_agent -> stop apps and (mgr node ~p) node results: " + "~n SNMP Mgr: ~p" + "~n Crypto: ~p" + "~n Node: ~p", + [Node, StopMgrRes, StopCryptoRes, StopNode]), Config. @@ -5385,10 +5390,16 @@ init_agent(Config) -> fin_agent(Config) -> Node = ?config(agent_node, Config), - stop_agent(Node, Config), - fin_crypto(Node), - fin_mnesia(Node), - stop_node(Node), + StopAgentRes = stop_agent(Node), + StopCryptoRes = fin_crypto(Node), + StopMnesiaRes = fin_mnesia(Node), + StopNode = stop_node(Node), + p("fin_agent -> stop apps and (agent node ~p) node results: " + "~n SNMP Agent: ~p" + "~n Crypto: ~p" + "~n Mnesia: ~p" + "~n Node: ~p", + [Node, StopAgentRes, StopCryptoRes, StopMnesiaRes, StopNode]), Config. init_mnesia(Node, Dir) -> @@ -5434,25 +5445,89 @@ fin_crypto(Node) -> %% -- Misc application wrapper functions -- -load_app(Node, App) when (Node =:= node()) andalso is_atom(App) -> - application:load(App); -load_app(Node, App) when is_atom(App) -> - rcall(Node, application, load, [App]). - -start_app(Node, App) when (Node =:= node()) andalso is_atom(App) -> - application:start(App); +load_app(Node, App) -> + VerifySuccess = fun(ok) -> + ok; + ({error, {already_loaded, LoadedApp}}) when (LoadedApp =:= App) -> + ok; + ({error, Reason}) -> + p("failed loading app ~w on ~p: " + "~n ~p", [App, Node, Reason]), + ?FAIL({failed_load, Node, App, Reason}) + end, + do_load_app(Node, App, VerifySuccess). + +do_load_app(Node, App, VerifySuccess) + when (Node =:= node()) andalso is_atom(App) -> + %% Local app + exec(fun() -> application:load(App) end, VerifySuccess); +do_load_app(Node, App, VerifySuccess) -> + %% Remote app + exec(fun() -> rcall(Node, application, load, [App]) end, VerifySuccess). + + start_app(Node, App) -> - rcall(Node, application, start, [App]). + VerifySuccess = fun(ok) -> + ok; + ({error, {already_started, LoadedApp}}) when (LoadedApp =:= App) -> + ok; + ({error, Reason}) -> + p("failed starting app ~w on ~p: " + "~n ~p", [App, Node, Reason]), + ?FAIL({failed_start, Node, App, Reason}) + end, + start_app(Node, App, VerifySuccess). + +start_app(Node, App, VerifySuccess) + when (Node =:= node()) andalso is_atom(App) -> + exec(fun() -> application:start(App) end, VerifySuccess); +start_app(Node, App, VerifySuccess) -> + exec(fun() -> rcall(Node, application, start, [App]) end, VerifySuccess). + + +stop_app(Node, App) -> + VerifySuccess = fun(ok) -> + ok; + ({error, {not_started, LoadedApp}}) when (LoadedApp =:= App) -> + ok; + ({error, Reason}) -> + p("failed stopping app ~w on ~p: " + "~n ~p", [App, Node, Reason]), + ?FAIL({failed_stop, Node, App, Reason}) + end, + stop_app(Node, App, VerifySuccess). + +stop_app(Node, App, VerifySuccess) + when (Node =:= node()) andalso is_atom(App) -> + exec(fun() -> application:stop(App) end, VerifySuccess); +stop_app(Node, App, VerifySuccess) when is_atom(App) -> + exec(fun() -> rcall(Node, application, stop, [App]) end, VerifySuccess). + + +set_app_env(Node, App, Key, Val) -> + VerifySuccess = fun(ok) -> + ok; + ({error, Reason}) -> + p("failed setting app ~w env on ~p" + "~n Key: ~p" + "~n Val: ~p" + "~n Reason: ~p" + "~n ~p", [App, Node, Key, Val, Reason]), + ?FAIL({failed_set_app_env, + Node, App, Key, Val, Reason}) + end, + set_app_env(Node, App, Key, Val, VerifySuccess). + +set_app_env(Node, App, Key, Val, VerifySuccess) + when (Node =:= node()) andalso is_atom(App) -> + exec(fun() -> application:set_env(App, Key, Val) end, VerifySuccess); +set_app_env(Node, App, Key, Val, VerifySuccess) when is_atom(App) -> + exec(fun() -> rcall(Node, application, set_env, [App, Key, Val]) end, + VerifySuccess). -stop_app(Node, App) when (Node =:= node()) andalso is_atom(App) -> - application:stop(App); -stop_app(Node, App) when is_atom(App) -> - rcall(Node, application, stop, [App]). -set_app_env(Node, App, Key, Val) when (Node =:= node()) andalso is_atom(App) -> - application:set_env(App, Key, Val); -set_app_env(Node, App, Key, Val) when is_atom(App) -> - rcall(Node, application, set_env, [App, Key, Val]). +exec(Cmd, VerifySuccess) -> + VerifySuccess(Cmd()). %% -- Misc snmp wrapper functions -- @@ -5900,9 +5975,9 @@ start_manager(Node, Vsns, Conf0, _Opts) -> Conf0. -stop_manager(Node, Conf) -> - stop_snmp(Node), - Conf. +stop_manager(Node) -> + stop_snmp(Node). + %% -- Misc agent wrapper functions -- @@ -5951,9 +6026,8 @@ start_agent(Node, Vsns, Conf0, _Opts) -> ?line ok = start_snmp(Node), Conf0. -stop_agent(Node, Conf) -> - stop_snmp(Node), - Conf. +stop_agent(Node) -> + stop_snmp(Node). agent_load_mib(Node, Mib) -> rcall(Node, snmpa, load_mibs, [[Mib]]). @@ -6015,17 +6089,18 @@ stop_node(Node) -> rpc:cast(Node, erlang, halt, []), await_stopped(Node, 5). -await_stopped(_, 0) -> +await_stopped(Node, 0) -> + p("await_stopped -> ~p still exist: giving up", [Node]), ok; await_stopped(Node, N) -> Nodes = erlang:nodes(), case lists:member(Node, Nodes) of true -> - ?DBG("[~w] ~p still exist", [N, Node]), + p("await_stopped -> ~p still exist: ~w", [Node, N]), ?SLEEP(1000), await_stopped(Node, N-1); false -> - ?DBG("[~w] ~p gone", [N, Node]), + p("await_stopped -> ~p gone: ~w", [Node, N]), ok end. @@ -6271,7 +6346,7 @@ p(F, A) -> p(TName, F, A) -> io:format("*** [~w][~s] ***" - "~n" ++ F ++ "~n", [TName, formated_timestamp()|A]). + "~n " ++ F ++ "~n", [TName, formated_timestamp()|A]). formated_timestamp() -> snmp_test_lib:formated_timestamp(). -- cgit v1.2.3 From 29b3afb4fa0bc2050ab7e3d2e5e0315c30eb060c Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 18 Mar 2014 15:31:31 +0100 Subject: [snmp/agent] CLeanup - unused vars and use of deprecated funcs --- lib/snmp/test/snmp_agent_test.erl | 208 ++++++++++++++++++---------------- lib/snmp/test/snmp_agent_test_lib.erl | 22 ++-- 2 files changed, 124 insertions(+), 106 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index a6571548d6..2a9f2e842d 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -543,8 +543,9 @@ groups() -> init_per_suite(Config0) when is_list(Config0) -> - ?DBG("init_per_suite -> entry with" - "~n Config0: ~p", [Config0]), + p("init_per_suite -> entry with" + "~n Config: ~p" + "~n Nodes: ~p", [Config0, erlang:nodes()]), Config1 = snmp_test_lib:init_suite_top_dir(?MODULE, Config0), Config2 = snmp_test_lib:fix_data_dir(Config1), @@ -557,27 +558,30 @@ init_per_suite(Config0) when is_list(Config0) -> snmp_test_mgr_counter_server:start(), - ?DBG("init_per_suite -> end with" - "~n Config3: ~p", [Config3]), + p("init_per_suite -> end when" + "~n Config: ~p" + "~n Nodes: ~p", [Config3, erlang:nodes()]), Config3. end_per_suite(Config) when is_list(Config) -> - ?DBG("end_per_suite -> entry with" - "~n Config: ~p", [Config]), + p("end_per_suite -> entry with" + "~n Config: ~p" + "~n Nodes: ~p", [Config, erlang:nodes()]), case snmp_test_mgr_counter_server:stop() of - {ok, Counters} -> - ?DBG("end_per_suite -> sucessfully stopped counter server" - "~n Counters: ~p", [Counters]); + {ok, _Counters} -> + p("end_per_suite -> sucessfully stopped counter server" + "~n Counters: ~p", [_Counters]); {error, Reason} -> - ?DBG("end_per_suite -> failed stopping counter server" - "~n Reason: ~p", [Reason]) + p("end_per_suite -> failed stopping counter server" + "~n Reason: ~p", [Reason]) end, - ?DBG("end_per_suite -> end", []), + p("end_per_suite -> end when" + "~n Nodes: ~p", [erlang:nodes()]), Config. @@ -685,10 +689,16 @@ end_per_group(_GroupName, Config) -> %% ---- Init Per TestCase ---- init_per_testcase(Case, Config) when is_list(Config) -> - ?DBG("init_per_testcase -> entry with" - "~n Config: ~p", [Config]), + p("init_per_testcase -> entry with" + "~n Config: ~p" + "~n Nodes: ~p", [Config, erlang:nodes()]), + + Result = init_per_testcase1(Case, Config), - init_per_testcase1(Case, Config). + p("init_per_testcase -> done when" + "~n Result: ~p" + "~n Nodes: ~p", [Result, erlang:nodes()]), + Result. init_per_testcase1(otp8395 = Case, Config) when is_list(Config) -> ?DBG("init_per_testcase1 -> entry with" @@ -729,12 +739,18 @@ init_per_testcase1(_Case, Config) when is_list(Config) -> %% ---- End Per TestCase ---- end_per_testcase(Case, Config) when is_list(Config) -> - ?DBG("end_per_testcase -> entry with" - "~n Config: ~p", [Config]), + p("end_per_testcase -> entry with" + "~n Config: ~p" + "~n Nodes: ~p", [Config, erlang:nodes()]), display_log(Config), - end_per_testcase1(Case, Config). + Result = end_per_testcase1(Case, Config), + + p("end_per_testcase -> done with" + "~n Result: ~p" + "~n Nodes: ~p", [Result, erlang:nodes()]), + Result. end_per_testcase1(otp8395, Config) when is_list(Config) -> otp8395({fin, Config}); @@ -2105,9 +2121,9 @@ await_dummy_manager_started(Pid) -> {ok,Pid,Port}; {'EXIT', Pid, Reason} -> {error, Pid, Reason}; - O -> + _O -> ?LOG("dummy_manager_start -> received unknown message:" - "~n ~p",[O]), + "~n ~p",[_O]), await_dummy_manager_started(Pid) end. @@ -2130,16 +2146,16 @@ dummy_manager_send_trap2(Pid) -> dummy_manager_await_trap2_ack() -> ?DBG("dummy_manager_await_trap2 -> entry",[]), receive - {received_trap,Trap} -> - ?LOG("dummy_manager_await_trap2 -> received trap: ~p",[Trap]), + {received_trap, _Trap} -> + ?LOG("dummy_manager_await_trap2 -> received trap: ~p", [_Trap]), %% Note: %% Without this sleep the v2_inform_i testcase failes! There %% is no relation between these two test cases as far as I %% able to figure out... ?SLEEP(60000), ok; - O -> - ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[O]), + _O -> + ?ERR("dummy_manager_await_trap2 -> unexpected message: ~p",[_O]), ok after 10000 -> ?ERR("dummy_manager_await_trap2 -> timeout",[]), @@ -2165,32 +2181,34 @@ dummy_manager_loop(P,S,MA) -> "~n Trap: ~p",[Trap]), snmpa:send_trap(MA, Trap, "standard trap"), dummy_manager_loop(P,S,MA); - {udp, _UdpId, Ip, UdpPort, Bytes} -> + {udp, _UdpId, _Ip, _UdpPort, Bytes} -> ?LOG("dummy_manager_loop -> received upd message" "~n from: ~p:~p" "~n size: ~p", - [Ip, UdpPort, dummy_manager_message_sz(Bytes)]), + [_Ip, _UdpPort, dummy_manager_message_sz(Bytes)]), R = dummy_manager_handle_message(Bytes), - ?DBG("dummy_manager_loop -> R: ~p",[R]), + ?DBG("dummy_manager_loop -> R: ~p", [R]), P ! R, - dummy_manager_loop(P,S,MA); + dummy_manager_loop(P, S, MA); stop -> ?DBG("dummy_manager_loop -> received stop request",[]), P ! {dummy_manager_stopping, self()}, gen_udp:close(S), exit(normal); - O -> + _O -> ?LOG("dummy_manager_loop -> received unknown message:" - "~n ~p",[O]), - dummy_manager_loop(P,S,MA) + "~n ~p", [_O]), + dummy_manager_loop(P, S, MA) end. +-ifdef(snmp_log). dummy_manager_message_sz(B) when is_binary(B) -> size(B); dummy_manager_message_sz(L) when is_list(L) -> length(L); dummy_manager_message_sz(_) -> undefined. +-endif. dummy_manager_handle_message(Bytes) -> case (catch snmp_pdus:dec_message(Bytes)) of @@ -3408,11 +3426,11 @@ simple_standard_test() -> db_notify_client(suite) -> []; db_notify_client(Config) when is_list(Config) -> ?P(db_notify_client), - {SaNode, MgrNode, MibDir} = init_case(Config), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), ?DBG("db_notify_client -> case initiated: " "~n SaNode: ~p" "~n MgrNode: ~p" - "~n MibDir: ~p", [SaNode, MgrNode, MibDir]), + "~n MibDir: ~p", [_SaNode, _MgrNode, _MibDir]), ?DBG("db_notify_client -> maximize verbosity", []), snmpa_local_db:verbosity(trace), Self = self(), @@ -4163,8 +4181,8 @@ ma_v2_inform1(MA) -> CmdExp = fun(ok) -> ok; - ({ok, Val}) -> - ?DBG("ma_v2_inform -> [cmd2] Val: ~p", [Val]), + ({ok, _Val}) -> + ?DBG("ma_v2_inform -> [cmd2] Val: ~p", [_Val]), ok; ({error, Id, Extra}) -> {error, {unexpected, Id, Extra}}; @@ -4199,10 +4217,10 @@ ma_v2_inform1(MA) -> CmdSnmpTargets = fun(T) -> receive - {snmp_targets, T, [Addr]} -> + {snmp_targets, T, [_Addr]} -> ?DBG("ma_v2_inform1 -> " "received expected snmp_targets " - "~n with receiver: ~p",[Addr]), + "~n with receiver: ~p", [_Addr]), ok; {snmp_targets, T, Addrs} -> ?ERR("ma_v2_inform1 -> " @@ -4220,16 +4238,16 @@ ma_v2_inform1(MA) -> Cmd06 = fun() -> receive - {snmp_notification, Tag03, {got_response, Addr}} -> + {snmp_notification, Tag03, {got_response, _Addr}} -> ?DBG("ma_v2_inform1 -> " "received expected snmp_notification " - "[with manager response] from: ~n ~p",[Addr]), + "[with manager response] from: ~n ~p", [_Addr]), ok; - {snmp_notification, Tag03, {no_response, Addr}} -> + {snmp_notification, Tag03, {no_response, _Addr}} -> ?ERR("ma_v2_inform1 -> " "received unexpected snmp_notification " "[without manager response] from: ~n ~p", - [Addr]), + [_Addr]), {error, no_response} after 20000 -> @@ -4259,16 +4277,16 @@ ma_v2_inform1(MA) -> Cmd10 = fun() -> receive - {snmp_notification, Tag07, {got_response, Addr}} -> + {snmp_notification, Tag07, {got_response, _Addr}} -> ?ERR("ma_v2_inform1 -> " "received unexpected snmp_notification " - "[with manager response] from: ~n ~p", [Addr]), + "[with manager response] from: ~n ~p", [_Addr]), {error, got_response}; - {snmp_notification, Tag07, {no_response, Addr}} -> + {snmp_notification, Tag07, {no_response, _Addr}} -> ?DBG("ma_v2_inform1 -> " "received expected snmp_notification " "[without manager response] from: ~n ~p", - [Addr]), + [_Addr]), ok after 240000 -> @@ -4312,8 +4330,8 @@ ma_v2_inform2(MA) -> CmdExp = fun(ok) -> ok; - ({ok, Val}) -> - ?DBG("ma_v2_inform -> [cmd2] Val: ~p", [Val]), + ({ok, _Val}) -> + ?DBG("ma_v2_inform -> [cmd2] Val: ~p", [_Val]), ok; ({error, Id, Extra}) -> {error, {unexpected, Id, Extra}}; @@ -4393,8 +4411,8 @@ ma_v2_inform3(MA) -> "~n send notification: testTrapv22", [MA]), CmdExpectInform = - fun(No, Response) -> - ?DBG("CmdExpectInform -> ~p: ~n~p", [No, Response]), + fun(_No, Response) -> + ?DBG("CmdExpectInform -> ~p: ~n~p", [_No, Response]), ?expect2({inform, Response}, [{[sysUpTime, 0], any}, {[snmpTrapOID, 0], ?system ++ [0,1]}]) @@ -4403,8 +4421,8 @@ ma_v2_inform3(MA) -> CmdExp = fun(ok) -> ok; - ({ok, Val}) -> - ?DBG("CmdExp -> Val: ~p", [Val]), + ({ok, _Val}) -> + ?DBG("CmdExp -> Val: ~p", [_Val]), ok; ({error, Id, Extra}) -> {error, {unexpected, Id, Extra}}; @@ -4515,17 +4533,17 @@ delivery_info(Tag, Address, DeliveryResult, Extra) -> command_handler([]) -> ok; -command_handler([{No, Desc, Cmd}|Rest]) -> - ?LOG("command_handler -> command ~w: ~n ~s", [No, Desc]), +command_handler([{_No, _Desc, Cmd}|Rest]) -> + ?LOG("command_handler -> command ~w: ~n ~s", [_No, _Desc]), case (catch Cmd()) of ok -> - ?LOG("command_handler -> ~w: ok",[No]), + ?LOG("command_handler -> ~w: ok", [_No]), command_handler(Rest); {error, Reason} -> - ?ERR("command_handler -> ~w error: ~n~p",[No, Reason]), + ?ERR("command_handler -> ~w error: ~n~p", [_No, Reason]), ?line ?FAIL(Reason); Error -> - ?ERR("command_handler -> ~w unexpected: ~n~p",[No, Error]), + ?ERR("command_handler -> ~w unexpected: ~n~p", [_No, Error]), ?line ?FAIL({unexpected_command_result, Error}) end. @@ -5532,11 +5550,11 @@ loop_mib_1(Config) when is_list(Config) -> ?LOG("loop_mib_1 -> initiate case",[]), %% snmpa:verbosity(master_agent,debug), %% snmpa:verbosity(mib_server,info), - {SaNode, MgrNode, MibDir} = init_case(Config), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), ?DBG("loop_mib_1 -> ~n" "\tSaNode: ~p~n" "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + "\tMibDir: ~p", [_SaNode, _MgrNode, _MibDir]), ?DBG("loop_mib_1 -> load mib SNMP-COMMUNITY-MIB",[]), ?line load_master_std("SNMP-COMMUNITY-MIB"), ?DBG("loop_mib_1 -> load mib SNMP-MPD-MIB",[]), @@ -5574,11 +5592,11 @@ loop_mib_2(suite) -> []; loop_mib_2(Config) when is_list(Config) -> ?P(loop_mib_2), ?LOG("loop_mib_2 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), ?DBG("do_loop_mib_2 -> ~n" "\tSaNode: ~p~n" "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + "\tMibDir: ~p", [_SaNode, _MgrNode, _MibDir]), ?DBG("loop_mib_2 -> load mibs",[]), ?line load_master_std("SNMP-COMMUNITY-MIB"), ?line load_master_std("SNMP-MPD-MIB"), @@ -5603,11 +5621,11 @@ loop_mib_3(suite) -> []; loop_mib_3(Config) when is_list(Config) -> ?P(loop_mib_3), ?LOG("loop_mib_3 -> initiate case",[]), - {SaNode, MgrNode, MibDir} = init_case(Config), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), ?DBG("loop_mib_3 -> ~n" "\tSaNode: ~p~n" "\tMgrNode: ~p~n" - "\tMibDir: ~p",[SaNode, MgrNode, MibDir]), + "\tMibDir: ~p", [_SaNode, _MgrNode, _MibDir]), ?DBG("loop_mib_3 -> load mibs",[]), ?line load_master_std("SNMP-TARGET-MIB"), ?line load_master_std("SNMP-NOTIFICATION-MIB"), @@ -5642,13 +5660,13 @@ loop_it_1(Oid, N) -> error_status = noError, error_index = 0, varbinds = [#varbind{oid = NOid, - value = Value}]} when NOid > Oid -> + value = _Value}]} when NOid > Oid -> ?DBG("loop_it_1_test -> " "~n NOid: ~p" - "~n Value: ~p",[NOid, Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same + "~n Value: ~p", [NOid, _Value]), + ?line [_Value2] = get_req(1, [NOid]), % must not be same ?DBG("loop_it_1_test -> " - "~n Value2: ~p",[Value2]), + "~n Value2: ~p", [_Value2]), loop_it_1(NOid, N+1); #pdu{type = 'get-response', @@ -5698,22 +5716,22 @@ loop_it_2(Oid, N) -> #pdu{type = 'get-response', error_status = noError, error_index = 0, - varbinds = [#varbind{oid = NOid, value = endOfMibView}]} -> + varbinds = [#varbind{oid = _NOid, value = endOfMibView}]} -> ?DBG("loop_it_2 -> " - "~n NOid: ~p",[NOid]), + "~n NOid: ~p", [_NOid]), N; #pdu{type = 'get-response', error_status = noError, error_index = 0, varbinds = [#varbind{oid = NOid, - value = Value}]} when NOid > Oid -> + value = _Value}]} when NOid > Oid -> ?DBG("loop_it_2 -> " "~n NOid: ~p" - "~n Value: ~p",[NOid, Value]), - ?line [Value2] = get_req(1, [NOid]), % must not be same + "~n Value: ~p", [NOid, _Value]), + ?line [_Value2] = get_req(1, [NOid]), % must not be same ?DBG("loop_it_2 -> " - "~n Value2: ~p",[Value2]), + "~n Value2: ~p", [_Value2]), loop_it_2(NOid, N+1); #pdu{type = 'get-response', @@ -6627,16 +6645,16 @@ otp8395(Config) when is_list(Config) -> AgentNode = ?config(agent_node, Config), AgentLogDir = ?config(agent_log_dir, Config), OutFile = join([AgentLogDir, "otp8395.txt"]), - {ok, LogInfo} = rpc:call(AgentNode, snmpa, log_info, []), - ?DBG("otp8395 -> LogInfo: ~p", [LogInfo]), + {ok, _LogInfo} = rpc:call(AgentNode, snmpa, log_info, []), + ?DBG("otp8395 -> LogInfo: ~p", [_LogInfo]), %% SyncRes = rpc:call(AgentNode, snmp, log_sync, [?audit_trail_log_name]), %% ?DBG("otp8395 -> SyncRes: ~p", [SyncRes]), ok = agent_log_validation(AgentNode), - LTTRes = + _LTTRes = rpc:call(AgentNode, snmpa, log_to_txt, [AgentLogDir, [], OutFile]), - ?DBG("otp8395 -> LTTRes: ~p", [LTTRes]), + ?DBG("otp8395 -> LTTRes: ~p", [_LTTRes]), ?SLEEP(1000), ?DBG("otp8395 -> done", []), @@ -6957,10 +6975,10 @@ stop_stdalone_agent(Pid) when (node(Pid) =/= node()) -> MRef = erlang:monitor(process, Pid), rpc:call(node(Pid), ?MODULE, stop_stdalone_agent, [Pid]), receive - {'DOWN', MRef, process, Pid, Info} -> + {'DOWN', MRef, process, Pid, _Info} -> ?DBG("received expected DOWN message " "regarding snmp agent supervisor: " - "~n Info: ~p", [Info]), + "~n Info: ~p", [_Info]), ok after 5000 -> ?DBG("no DOWN message " @@ -7019,9 +7037,9 @@ do_info(MaNode) -> tree_size_bytes, db_memory]}], verify_info(Info, Keys), - OldInfo = snmpa:old_info_format(Info), - ?DBG("info_test1 -> OldInfo: ~n~p", [OldInfo]), - verify_old_info(OldInfo), + %% OldInfo = snmpa:old_info_format(Info), + %% ?DBG("info_test1 -> OldInfo: ~n~p", [OldInfo]), + %% verify_old_info(OldInfo), ok. verify_info([], []) -> @@ -7064,20 +7082,20 @@ verify_subinfo(Info0, [Key|Keys]) -> verify_subinfo(Info, Keys) end. -verify_old_info(Info) -> - Keys = [vsns, subagents, loaded_mibs, - tree_size_bytes, process_memory, db_memory], - verify_old_info(Keys, Info). - -verify_old_info([], _) -> - ok; -verify_old_info([Key|Keys], Info) -> - case lists:keymember(Key, 1, Info) of - true -> - verify_old_info(Keys, Info); - false -> - ?FAIL({missing_old_info, Key}) - end. +%% verify_old_info(Info) -> +%% Keys = [vsns, subagents, loaded_mibs, +%% tree_size_bytes, process_memory, db_memory], +%% verify_old_info(Keys, Info). + +%% verify_old_info([], _) -> +%% ok; +%% verify_old_info([Key|Keys], Info) -> +%% case lists:keymember(Key, 1, Info) of +%% true -> +%% verify_old_info(Keys, Info); +%% false -> +%% ?FAIL({missing_old_info, Key}) +%% end. %% Index String - string used in index is(S) -> [length(S) | S]. diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 122289c28e..d7109253f7 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -299,10 +299,10 @@ call(N,M,F,A) -> "~n Loc: ~p", [Rn, Loc]), put(test_server_loc, Loc), exit(Rn); - {done, Ret, Zed} -> + {done, Ret, _Zed} -> ?DBG("call -> done:" "~n Ret: ~p" - "~n Zed: ~p", [Ret, Zed]), + "~n Zed: ~p", [Ret, _Zed]), case Ret of {error, Reason} -> exit(Reason); @@ -338,8 +338,8 @@ run(Mod, Func, Args, Opts) -> CtxEngineID = snmp_misc:get_option(context_engine_id, Opts, EngineID), Community = snmp_misc:get_option(community, Opts, "all-rights"), ?DBG("run -> start crypto app",[]), - Crypto = ?CRYPTO_START(), - ?DBG("run -> Crypto: ~p", [Crypto]), + _CryptoRes = ?CRYPTO_START(), + ?DBG("run -> Crypto: ~p", [_CryptoRes]), catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case StdM = join(code:priv_dir(snmp), "mibs") ++ "/", Vsn = get(vsn), @@ -676,9 +676,9 @@ stop_agent(Config) when is_list(Config) -> (catch process_info(Sup)), (catch process_info(Par))]), - Info = agent_info(Sup), + _Info = agent_info(Sup), ?DBG("stop_agent -> Agent info: " - "~n ~p", [Info]), + "~n ~p", [_Info]), stop_sup(Sup, Par), @@ -1303,10 +1303,10 @@ get_req(Id, Vars) -> {ok, Val} -> ?DBG("get_req -> response: ~p",[Val]), Val; - {error, _, {ExpFmt, ExpArg}, {ActFmt, ActArg}} -> + {error, _, {_ExpFmt, ExpArg}, {_ActFmt, ActArg}} -> ?DBG("get_req -> error for ~p: " - "~n " ++ ExpFmt ++ - "~n " ++ ActFmt, + "~n " ++ _ExpFmt ++ + "~n " ++ _ActFmt, [Id] ++ ExpArg ++ ActArg), exit({unexpected_response, ExpArg, ActArg}); Error -> @@ -1527,9 +1527,9 @@ rewrite_target_addr_conf(Dir, NewPort) -> case file:read_file_info(TAFile) of {ok, _} -> ok; - {error, R} -> + {error, _R} -> ?ERR("failure reading file info of " - "target address config file: ~p",[R]), + "target address config file: ~p", [_R]), ok end, -- cgit v1.2.3 From 7bc03971cfe09a2acbcd3bdaef1069af6272b127 Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Mon, 10 Mar 2014 17:11:58 +0100 Subject: Bump versions and ensure that all are "normal" versions Ensure all are "normal" versions according to the new version scheme introduced in OTP 17.0 --- lib/snmp/vsn.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 533e313bdb..04c3cc9392 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.25.0.1 +SNMP_VSN = 4.25.1 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 22ff87a0c8db877e3ce53b6ff915dcc6a75c5c0c Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Mon, 10 Mar 2014 17:15:38 +0100 Subject: Introduce runtime_dependencies in .app files Most dependencies introduced are exactly the dependencies to other applications found by xref. That is, there might be real dependencies missing. There might also be pure debug dependencies listed that probably should be removed. Each application has to be manually inspected in order to ensure that all real dependencies are listed. All dependencies introduced are to application versions used in OTP 17.0. This since the previously used version scheme wasn't designed for this, and in order to minimize the work of introducing the dependencies. --- lib/snmp/src/app/snmp.app.src | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.app.src b/lib/snmp/src/app/snmp.app.src index 904d17954b..cbd292e4c3 100644 --- a/lib/snmp/src/app/snmp.app.src +++ b/lib/snmp/src/app/snmp.app.src @@ -136,4 +136,6 @@ %% configuration and use), and in that case mnesia must also be started, %% before snmp. {applications, [kernel, stdlib]}, - {mod, {snmp_app, []}}]}. + {mod, {snmp_app, []}}, + {runtime_dependencies, ["stdlib-2.0","runtime_tools-1.8.14","mnesia-4.12", + "kernel-3.0","erts-6.0","crypto-3.3"]}]}. -- cgit v1.2.3 From d083434f32b47fcdb185162ec1039bfa728c591b Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 18 Mar 2014 14:23:37 +0100 Subject: [snmp/manager] Add some more error handling when starting Add some more error handling (a try catch block) when starting both manager and agent. --- lib/snmp/test/snmp_manager_test.erl | 194 ++++++++++++++++++++++++------------ 1 file changed, 133 insertions(+), 61 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index ab757bc166..3a654a2805 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -139,6 +139,8 @@ -define(NS_TIMEOUT, 10000). +-define(DEFAULT_MNESIA_DEBUG, none). + %%---------------------------------------------------------------------- %% Records @@ -173,7 +175,9 @@ end_per_suite(Config) when is_list(Config) -> init_per_testcase(Case, Config) when is_list(Config) -> - io:format(user, "~n~n*** INIT ~w:~w ***~n~n", [?MODULE,Case]), + io:format(user, "~n~n*** INIT ~w:~w ***~n~n", [?MODULE, Case]), + p(Case, "init_per_testcase begin when" + "~n Nodes: ~p~n~n", [erlang:nodes()]), %% This version of the API, based on Addr and Port, has been deprecated DeprecatedApiCases = [ @@ -187,16 +191,25 @@ init_per_testcase(Case, Config) when is_list(Config) -> simple_async_get_bulk1, misc_async1 ], - case lists:member(Case, DeprecatedApiCases) of - true -> - %% ?SKIP(api_no_longer_supported); - {skip, api_no_longer_supported}; - false -> - init_per_testcase2(Case, Config) - end. + Result = + case lists:member(Case, DeprecatedApiCases) of + true -> + %% ?SKIP(api_no_longer_supported); + {skip, api_no_longer_supported}; + false -> + init_per_testcase2(Case, Config) + end, + p(Case, "init_per_testcase end when" + "~n Nodes: ~p" + "~n Result: ~p" + "~n~n", [Result, erlang:nodes()]), + Result. init_per_testcase2(Case, Config) -> - ?DBG("init_per_testcase2 -> ~p", [erlang:nodes()]), + ?DBG("init_per_testcase2 -> " + "~n Case: ~p" + "~n Config: ~p" + "~n Nodes: ~p", [Case, Config, erlang:nodes()]), CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config), @@ -314,6 +327,8 @@ init_per_testcase3(Case, Config) -> end. end_per_testcase(Case, Config) when is_list(Config) -> + p(Case, "end_per_testcase begin when" + "~n Nodes: ~p~n~n", [erlang:nodes()]), ?DBG("fin [~w] Nodes [1]: ~p", [Case, erlang:nodes()]), Dog = ?config(watchdog, Config), ?WD_STOP(Dog), @@ -322,6 +337,8 @@ end_per_testcase(Case, Config) when is_list(Config) -> ?DBG("fin [~w] Nodes [2]: ~p", [Case, erlang:nodes()]), %% TopDir = ?config(top_dir, Conf2), %% ?DEL_DIR(TopDir), + p(Case, "end_per_testcase end when" + "~n Nodes: ~p~n~n", [erlang:nodes()]), Conf2. end_per_testcase2(Case, Config) -> @@ -428,10 +445,10 @@ groups() -> {request_tests, [], [ {group, get_tests}, - {group, get_next_tests}, + {group, get_next_tests}, {group, set_tests}, - {group, bulk_tests}, - {group, misc_request_tests} + {group, bulk_tests}, + {group, misc_request_tests} ] }, {request_tests_mt, [], @@ -5303,29 +5320,49 @@ init_manager(AutoInform, Config) -> ?line Node = start_manager_node(), + %% The point with this (try catch block) is to be + %% able to do some cleanup in case we fail to + %% start some of the apps. That is, if we fail to + %% start the apps (mnesia, crypto and snmp agent) + %% we stop the (agent) node! - %% -- - %% Start and initiate crypto on manager node - %% - - ?line ok = init_crypto(Node), + try + begin - %% - %% Write manager config - %% + %% -- + %% Start and initiate crypto on manager node + %% + + ?line ok = init_crypto(Node), + + %% + %% Write manager config + %% + + ?line ok = write_manager_config(Config), + + IRB = case AutoInform of + true -> + auto; + _ -> + user + end, + Conf = [{manager_node, Node}, {irb, IRB} | Config], + Vsns = [v1,v2,v3], + start_manager(Node, Vsns, Conf) + end + catch + T:E -> + StackTrace = ?STACK(), + p("Failure during manager start: " + "~n Error Type: ~p" + "~n Error: ~p" + "~n StackTrace: ~p", [T, E, StackTrace]), + %% And now, *try* to cleanup + (catch stop_node(Node)), + ?FAIL({failed_starting_manager, T, E, StackTrace}) + end. - ?line ok = write_manager_config(Config), - - IRB = case AutoInform of - true -> - auto; - _ -> - user - end, - Conf = [{manager_node, Node}, {irb, IRB} | Config], - Vsns = [v1,v2,v3], - start_manager(Node, Vsns, Conf). - fin_manager(Config) -> Node = ?config(manager_node, Config), StopMgrRes = stop_manager(Node), @@ -5357,36 +5394,57 @@ init_agent(Config) -> ?line Node = start_agent_node(), + %% The point with this (try catch block) is to be + %% able to do some cleanup in case we fail to + %% start some of the apps. That is, if we fail to + %% start the apps (mnesia, crypto and snmp agent) + %% we stop the (agent) node! - %% -- - %% Start and initiate mnesia on agent node - %% - - ?line ok = init_mnesia(Node, Dir), - - - %% -- - %% Start and initiate crypto on agent node - %% - - ?line ok = init_crypto(Node), - - - %% - %% Write agent config - %% - - Vsns = [v1,v2], - ?line ok = write_agent_config(Vsns, Config), - - Conf = [{agent_node, Node}, - {mib_dir, MibDir} | Config], + try + begin + + %% -- + %% Start and initiate mnesia on agent node + %% + + ?line ok = init_mnesia(Node, Dir, ?config(mnesia_debug, Config)), + + + %% -- + %% Start and initiate crypto on agent node + %% + + ?line ok = init_crypto(Node), + + + %% + %% Write agent config + %% + + Vsns = [v1,v2], + ?line ok = write_agent_config(Vsns, Config), + + Conf = [{agent_node, Node}, + {mib_dir, MibDir} | Config], - %% - %% Start the agent - %% - - start_agent(Node, Vsns, Conf). + %% + %% Start the agent + %% + + start_agent(Node, Vsns, Conf) + end + catch + T:E -> + StackTrace = ?STACK(), + p("Failure during agent start: " + "~n Error Type: ~p" + "~n Error: ~p" + "~n StackTrace: ~p", [T, E, StackTrace]), + %% And now, *try* to cleanup + (catch stop_node(Node)), + ?FAIL({failed_starting_agent, T, E, StackTrace}) + end. + fin_agent(Config) -> Node = ?config(agent_node, Config), @@ -5402,13 +5460,27 @@ fin_agent(Config) -> [Node, StopAgentRes, StopCryptoRes, StopMnesiaRes, StopNode]), Config. -init_mnesia(Node, Dir) -> +init_mnesia(Node, Dir, MnesiaDebug) + when ((MnesiaDebug =/= none) andalso + (MnesiaDebug =/= debug) andalso (MnesiaDebug =/= trace)) -> + init_mnesia(Node, Dir, ?DEFAULT_MNESIA_DEBUG); +init_mnesia(Node, Dir, MnesiaDebug) -> ?DBG("init_mnesia -> load application mnesia", []), ?line ok = load_mnesia(Node), ?DBG("init_mnesia -> application mnesia: set_env dir: ~n~p",[Dir]), ?line ok = set_mnesia_env(Node, dir, filename:join(Dir, "mnesia")), + %% Just in case, only set (known to be) valid values for debug + if + ((MnesiaDebug =:= debug) orelse (MnesiaDebug =:= trace)) -> + ?DBG("init_mnesia -> application mnesia: set_env debug: ~w", + [MnesiaDebug]), + ?line ok = set_mnesia_env(Node, debug, MnesiaDebug); + true -> + ok + end, + ?DBG("init_mnesia -> create mnesia schema",[]), ?line case create_schema(Node) of ok -> -- cgit v1.2.3 From f719d0fe308f00b85f92c29d7cdf9b0dc20d98a2 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Mon, 7 Apr 2014 19:52:48 +0200 Subject: Update release notes --- lib/snmp/doc/src/notes.xml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index ab5514e550..06674095f2 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,7 +33,36 @@
-
+
SNMP 4.25.1 + +
Fixed Bugs and Malfunctions + + +

+ Application upgrade (appup) files are corrected for the + following applications:

+

+ asn1, common_test, compiler, crypto, debugger, + dialyzer, edoc, eldap, erl_docgen, et, eunit, gs, hipe, + inets, observer, odbc, os_mon, otp_mibs, parsetools, + percept, public_key, reltool, runtime_tools, ssh, + syntax_tools, test_server, tools, typer, webtool, wx, + xmerl

+

+ A new test utility for testing appup files is added to + test_server. This is now used by most applications in + OTP.

+

+ (Thanks to Tobias Schlager)

+

+ Own Id: OTP-11744

+
+
+
+ +
+ +
SNMP Development Toolkit 4.25.0.1

Version 4.25.0.1 supports code replacement in runtime from/to version 4.25, 4.24.2, 4.24.1 and 4.24.

-- cgit v1.2.3 From eadc39c5356692d8a093b835d884c8e11faf4c73 Mon Sep 17 00:00:00 2001 From: Colton Date: Fri, 11 Apr 2014 07:56:41 -0500 Subject: Fix badmatch error when trying to start_link an snmp_test_manager Was previously unable to start_link an snmp_test_manager due to a badmatch occurring on line 133. See traceback here: http://pastebin.com/1eNYkGTz Edit snmp_test_manager.erl to only expect the atom ok when it was in turn start_linking an snmpm server. Also remove reference to no longer existing Pid variable. Lastly remove the mgr key from the State record, as after these changes it was no longer being used. --- lib/snmp/test/snmp_test_manager.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_test_manager.erl b/lib/snmp/test/snmp_test_manager.erl index 925ae77ab5..6d8673eecd 100644 --- a/lib/snmp/test/snmp_test_manager.erl +++ b/lib/snmp/test/snmp_test_manager.erl @@ -56,7 +56,7 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]). --record(state, {mgr, parent, req, agent_target_name}). +-record(state, {parent, req, agent_target_name}). -define(SERVER, ?MODULE). -define(USER, ?MODULE). @@ -130,10 +130,10 @@ init([Parent, Opts]) -> do_init(Opts) -> {MgrDir, MgrConf, MgrOpts, AgentTargetName, AgentConf} = parse_opts(Opts), ok = snmp_config:write_manager_config(MgrDir, "", MgrConf), - {ok, Pid} = snmpm:start_link(MgrOpts), + ok = snmpm:start_link(MgrOpts), ok = snmpm:register_user(?USER, ?MODULE, self()), ok = snmpm:register_agent(?USER, AgentTargetName, AgentConf), - {ok, #state{mgr = Pid, agent_target_name = AgentTargetName}}. + {ok, #state{agent_target_name = AgentTargetName}}. parse_opts(Opts) -> -- cgit v1.2.3 From 768a6d38597b8bedf6551ad2e6472b2965765dd2 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 9 Apr 2014 10:29:00 +0200 Subject: Rewrite agent configuration parsing --- lib/snmp/src/agent/snmp_community_mib.erl | 71 +++-- lib/snmp/src/agent/snmp_framework_mib.erl | 55 ++-- lib/snmp/src/agent/snmp_notification_mib.erl | 24 +- lib/snmp/src/agent/snmp_standard_mib.erl | 23 +- lib/snmp/src/agent/snmp_target_mib.erl | 172 +++++++---- lib/snmp/src/agent/snmp_user_based_sm_mib.erl | 14 +- lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 23 +- lib/snmp/src/agent/snmpa_conf.erl | 96 ++++-- lib/snmp/src/agent/snmpa_mpd.erl | 39 ++- lib/snmp/src/manager/snmpm_config.erl | 10 +- lib/snmp/src/misc/snmp_conf.erl | 406 +++++++++++++++++++------ lib/snmp/src/misc/snmp_config.erl | 143 ++++++--- lib/snmp/test/snmp_agent_test_lib.erl | 26 +- 13 files changed, 793 insertions(+), 309 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_community_mib.erl b/lib/snmp/src/agent/snmp_community_mib.erl index 7bdd500727..12a0ec97c2 100644 --- a/lib/snmp/src/agent/snmp_community_mib.erl +++ b/lib/snmp/src/agent/snmp_community_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2012. All Rights Reserved. +%% Copyright Ericsson AB 1999-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -31,6 +31,7 @@ -include("snmpa_internal.hrl"). -include("SNMP-COMMUNITY-MIB.hrl"). -include("SNMP-TARGET-MIB.hrl"). +-include("SNMPv2-TM.hrl"). -include("SNMPv2-TC.hrl"). -include("snmp_types.hrl"). @@ -129,10 +130,11 @@ read_community_config_files(Dir) -> [FileName, D, Reason]), ok end, - Filter = fun(Comms) -> Comms end, - Check = fun(Entry) -> check_community(Entry) end, + Order = fun snmp_conf:no_order/2, + Filter = fun snmp_conf:no_filter/1, + Check = fun(Entry, State) -> {check_community(Entry), State} end, [Comms] = - snmp_conf:read_files(Dir, [{Gen, Filter, Check, "community.conf"}]), + snmp_conf:read_files(Dir, [{FileName, Gen, Order, Check, Filter}]), Comms. check_community({Index, CommunityName, SecName, CtxName, TransportTag}) -> @@ -192,7 +194,7 @@ add_community(Idx, CommName, SecName, EngineId, CtxName, TransportTag) -> do_add_community(Community). do_add_community(Community) -> - case (catch check_community(Community)) of + try check_community(Community) of {ok, Row} -> Key = element(1, Row), case table_cre_row(snmpCommunityTable, Key, Row) of @@ -201,11 +203,12 @@ do_add_community(Community) -> {ok, Key}; false -> {error, create_failed} - end; + end + catch {error, Reason} -> {error, Reason}; - Error -> - {error, Error} + Class:Reason -> + {error, {Class, Reason, erlang:get_stacktrace()}} end. %% FIXME: does not work with mnesia @@ -506,7 +509,12 @@ snmpTargetAddrExtTable(get_next, RowIndex, Cols) -> NCols = conv1(Cols), conv2(next(snmpTargetAddrExtTable, RowIndex, NCols)); snmpTargetAddrExtTable(set, RowIndex, Cols0) -> - case (catch verify_snmpTargetAddrExtTable_cols(Cols0, [])) of + case + (catch verify_snmpTargetAddrExtTable_cols( + Cols0, + get_snmpTargetAddrTDomain(RowIndex, Cols0), + [])) + of {ok, Cols} -> NCols = conv3(Cols), snmp_generic:table_func(set, RowIndex, NCols, @@ -515,7 +523,11 @@ snmpTargetAddrExtTable(set, RowIndex, Cols0) -> Error end; snmpTargetAddrExtTable(is_set_ok, RowIndex, Cols0) -> - case (catch verify_snmpTargetAddrExtTable_cols(Cols0, [])) of + case (catch verify_snmpTargetAddrExtTable_cols( + Cols0, + get_snmpTargetAddrTDomain(RowIndex, Cols0), + [])) + of {ok, Cols} -> NCols = conv3(Cols), snmp_generic:table_func(is_set_ok, RowIndex, NCols, @@ -525,29 +537,49 @@ snmpTargetAddrExtTable(is_set_ok, RowIndex, Cols0) -> end. -verify_snmpTargetAddrExtTable_cols([], Cols) -> + +get_snmpTargetAddrTDomain(RowIndex, Col) -> + case + get( + snmpTargetAddrTable, RowIndex, + [?snmpTargetAddrRowStatus,?snmpTargetAddrTDomain]) + of + [{value,?snmpTargetAddrRowStatus_active},ValueTDomain] -> + case ValueTDomain of + {value,TDomain} -> + TDomain; + _ -> + ?snmpUDPDomain + end; + _ -> + wrongValue(Col) + end. + + + +verify_snmpTargetAddrExtTable_cols([], _TDomain, Cols) -> {ok, lists:reverse(Cols)}; -verify_snmpTargetAddrExtTable_cols([{Col, Val0}|Cols], Acc) -> - Val = verify_snmpTargetAddrExtTable_col(Col, Val0), - verify_snmpTargetAddrExtTable_cols(Cols, [{Col, Val}|Acc]). +verify_snmpTargetAddrExtTable_cols([{Col, Val0}|Cols], TDomain, Acc) -> + Val = verify_snmpTargetAddrExtTable_col(Col, TDomain, Val0), + verify_snmpTargetAddrExtTable_cols(Cols, TDomain, [{Col, Val}|Acc]). -verify_snmpTargetAddrExtTable_col(?snmpTargetAddrTMask, []) -> +verify_snmpTargetAddrExtTable_col(?snmpTargetAddrTMask, _TDomain, []) -> []; -verify_snmpTargetAddrExtTable_col(?snmpTargetAddrTMask, TMask) -> - case (catch snmp_conf:check_taddress(TMask)) of +verify_snmpTargetAddrExtTable_col(?snmpTargetAddrTMask, TDomain, TMask) -> + case (catch snmp_conf:check_taddress(TDomain, TMask)) of ok -> TMask; _ -> wrongValue(?snmpTargetAddrTMask) end; -verify_snmpTargetAddrExtTable_col(?snmpTargetAddrMMS, MMS) -> +verify_snmpTargetAddrExtTable_col(?snmpTargetAddrMMS, _TDomain, MMS) -> case (catch snmp_conf:check_packet_size(MMS)) of ok -> MMS; _ -> wrongValue(?snmpTargetAddrMMS) end; -verify_snmpTargetAddrExtTable_col(_, Val) -> +verify_snmpTargetAddrExtTable_col(_, _TDomain, Val) -> Val. db(snmpTargetAddrExtTable) -> db(snmpTargetAddrTable); @@ -583,6 +615,7 @@ conv3([{Idx, Val}|T]) -> [{Idx+10, Val} | conv3(T)]; conv3([]) -> []. + get(Name, RowIndex, Cols) -> snmp_generic:handle_table_get(db(Name), RowIndex, Cols, foi(Name)). diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index cc191bd956..84f39df228 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2012. All Rights Reserved. +%% Copyright Ericsson AB 1999-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -51,7 +51,7 @@ set_engine_boots/1, set_engine_time/1, table_next/2, check_status/3]). -export([add_context/1, delete_context/1]). --export([check_agent/1, check_context/1]). +-export([check_agent/1, check_agent/2, check_context/1, order_agent/2]). %%----------------------------------------------------------------- @@ -115,23 +115,22 @@ do_configure(Dir) -> read_internal_config_files(Dir) -> ?vdebug("read context config file",[]), - Gen = fun(D, Reason) -> - convert_context(D, Reason) - end, - Filter = fun(Contexts) -> Contexts end, - Check = fun(Entry) -> check_context(Entry) end, - [Ctxs] = snmp_conf:read_files(Dir, [{Gen, Filter, Check, "context.conf"}]), + Gen = fun gen_context/2, + Order = fun snmp_conf:no_order/2, + Filter = fun snmp_conf:no_filter/1, + Check = fun(Entry, State) -> {check_context(Entry), State} end, + [Ctxs] = + snmp_conf:read_files + (Dir, [{"context.conf", Gen, Order, Check, Filter}]), Ctxs. - read_agent(Dir) -> ?vdebug("read agent config file", []), - FileName = "agent.conf", - Check = fun(Entry) -> check_agent(Entry) end, + FileName = "agent.conf", File = filename:join(Dir, FileName), - Agent = + Agent = try - snmp_conf:read(File, Check) + snmp_conf:read(File, fun order_agent/2, fun check_agent/2) catch throw:{error, Reason} -> error({failed_reading_config_file, Dir, FileName, Reason}) @@ -155,14 +154,15 @@ sort_agent(L) -> %%----------------------------------------------------------------- %% Generate a context.conf file. %%----------------------------------------------------------------- -convert_context(Dir, _Reason) -> +gen_context(Dir, _Reason) -> config_err("missing context.conf file => generating a default file", []), File = filename:join(Dir, "context.conf"), case file:open(File, [write]) of {ok, Fid} -> ok = io:format(Fid, "~s\n", [context_header()]), ok = io:format(Fid, "%% The default context\n\"\".\n", []), - file:close(Fid); + file:close(Fid), + []; {error, Reason} -> file:delete(File), error({failed_creating_file, File, Reason}) @@ -196,9 +196,21 @@ check_context(Context) -> %% Agent %% {Name, Value}. %%----------------------------------------------------------------- -check_agent({intAgentIpAddress, Value}) -> +check_agent({intAgentTransportDomain, D}, Domain) -> + case Domain of + undefined -> + {snmp_conf:check_domain(D), D}; + _ -> + error({invalid_agent_attribute, D}) + end; +check_agent({intAgentTransportAddress, Address}, Domain) -> + {snmp_conf:check_address(Domain, Address), Domain}; +check_agent(Entry, Domain) -> + {check_agent(Entry), Domain}. + +check_agent({intAgentIpAddress, Value}) -> % Obsoleted snmp_conf:check_ip(Value); -check_agent({intAgentUDPPort, Value}) -> +check_agent({intAgentUDPPort, Value}) -> % Obsoleted snmp_conf:check_integer(Value); %% This one is kept for backwards compatibility check_agent({intAgentMaxPacketSize, Value}) -> @@ -210,6 +222,15 @@ check_agent({snmpEngineID, Value}) -> check_agent(X) -> error({invalid_agent_attribute, X}). +%% Ordering function to sort intAgentTransportDomain first +%% hence before intAgentTransportAddress +order_agent({intAgentTransportDomain, _}, {intAgentTransportDomain, _}) -> + true; %% Less than or equal +order_agent(_, {intAgentTransportDomain, _}) -> + false; %% Greater than +order_agent(_, _) -> + true. %% Less than or equal + maybe_create_table(Name) -> case snmpa_local_db:table_exists(db(Name)) of diff --git a/lib/snmp/src/agent/snmp_notification_mib.erl b/lib/snmp/src/agent/snmp_notification_mib.erl index 37e09f5d3e..31c7735226 100644 --- a/lib/snmp/src/agent/snmp_notification_mib.erl +++ b/lib/snmp/src/agent/snmp_notification_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2012. All Rights Reserved. +%% Copyright Ericsson AB 1998-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -106,17 +106,19 @@ do_reconfigure(Dir) -> read_notify_config_files(Dir) -> ?vdebug("read notify config file",[]), FileName = "notify.conf", - Gen = fun(D, Reason) -> - info_msg("failed reading config file ~s" - "~n Config Dir: ~s" - "~n Reason: ~p", - [FileName, D, Reason]), - ok - end, - Filter = fun(Notifs) -> Notifs end, - Check = fun(Entry) -> check_notify(Entry) end, + Gen = + fun (D, Reason) -> + info_msg("failed reading config file ~s" + "~n Config Dir: ~s" + "~n Reason: ~p", + [FileName, D, Reason]), + ok + end, + Order = fun snmp_conf:no_order/2, + Filter = fun snmp_conf:no_filter/1, + Check = fun (Entry, State) -> {check_notify(Entry), State} end, [Notifs] = - snmp_conf:read_files(Dir, [{Gen, Filter, Check, "notify.conf"}]), + snmp_conf:read_files(Dir, [{FileName, Gen, Order, Check, Filter}]), Notifs. check_notify({Name, Tag, Type}) -> diff --git a/lib/snmp/src/agent/snmp_standard_mib.erl b/lib/snmp/src/agent/snmp_standard_mib.erl index 766b75022b..aace3fd413 100644 --- a/lib/snmp/src/agent/snmp_standard_mib.erl +++ b/lib/snmp/src/agent/snmp_standard_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -152,16 +152,19 @@ do_reconfigure(Dir) -> %%----------------------------------------------------------------- read_standard(Dir) -> ?vdebug("check standard config file",[]), - FileName = "standard.conf", - Gen = fun(D, Reason) -> - throw({error, {failed_reading_config_file, - D, FileName, - list_dir(Dir), Reason}}) - end, - Filter = fun(Standard) -> sort_standard(Standard) end, - Check = fun(Entry) -> check_standard(Entry) end, + FileName = "standard.conf", + Gen = + fun (D, Reason) -> + throw( + {error, + {failed_reading_config_file, + D, FileName, list_dir(Dir), Reason}}) + end, + Order = fun snmp_conf:no_order/2, + Check = fun (Entry, State) -> {check_standard(Entry), State} end, + Filter = fun sort_standard/1, [Standard] = - snmp_conf:read_files(Dir, [{Gen, Filter, Check, FileName}]), + snmp_conf:read_files(Dir, [{FileName, Gen, Order, Check, Filter}]), Standard. list_dir(Dir) -> diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index b01d536caa..6dd3b6e23a 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2012. All Rights Reserved. +%% Copyright Ericsson AB 1998-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -133,18 +133,22 @@ do_reconfigure(Dir) -> read_target_config_files(Dir) -> ?vdebug("check target address and parameter config file(s)",[]), - TAGen = fun(_D, _Reason) -> ok end, - TAFilter = fun(Addr) -> Addr end, - TACheck = fun(Entry) -> check_target_addr(Entry) end, - TPGen = fun(_D, _Reason) -> ok end, - TPFilter = fun(Params) -> Params end, - TPCheck = fun(Entry) -> check_target_params(Entry) end, + TAName = "target_addr.conf", + TACheck = fun (Entry, State) -> {check_target_addr(Entry), State} end, + + TPName = "target_params.conf", + TPCheck = fun (Entry, State) -> {check_target_params(Entry), State} end, + + NoGen = fun snmp_conf:no_gen/2, + NoOrder = fun snmp_conf:no_order/2, + NoFilter = fun snmp_conf:no_filter/1, [Addrs, Params] = - snmp_conf:read_files(Dir, - [{TAGen, TAFilter, TACheck, "target_addr.conf"}, - {TPGen, TPFilter, TPCheck, "target_params.conf"}]), + snmp_conf:read_files( + Dir, + [{TAName, NoGen, NoOrder, TACheck, NoFilter}, + {TPName, NoGen, NoOrder, TPCheck, NoFilter}]), {Addrs, Params}. @@ -154,80 +158,142 @@ read_target_config_files(Dir) -> %% TMask, MMS} %%----------------------------------------------------------------- -check_target_addr({Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, - Params, EngineId, TMask, MMS}) -> +check_target_addr( + {Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, Params, + EngineId, TMask, MMS}) -> % Arity 11 + Address = {Ip, Udp}, + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId, TMask, MMS); +check_target_addr( + {Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId, TMask, MMS}) % Arity 10 + when is_atom(Domain) -> + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId, TMask, MMS); +check_target_addr( + {Name, Ip, Udp, Timeout, RetryCount, TagList, Params, + EngineId, TMask, MMS}) -> % Arity 10 + Domain = default_domain(), + Address = {Ip, Udp}, + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId, TMask, MMS); +check_target_addr( + {Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId}) % Arity 8 + when is_atom(Domain) -> + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId); +check_target_addr( + {Name, Ip, Udp, Timeout, RetryCount, TagList, Params, + EngineId}) -> % Arity 8 + Domain = default_domain(), + Address = {Ip, Udp}, + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId); +%% Use dummy engine id if the old style is found +check_target_addr( + {Name, Domain, Address, Timeout, RetryCount, TagList, Params}) % Arity 7 + when is_atom(Domain) -> + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params); +check_target_addr( + {Name, Ip, Udp, Timeout, RetryCount, TagList, Params}) -> % Arity 7 + Domain = default_domain(), + Address = {Ip, Udp}, + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params); +%% Use dummy engine id if the old style is found +check_target_addr( + {Name, Domain, Address, Timeout, RetryCount, TagList, Params, + TMask, MMS}) % Arity 9 + when is_atom(Domain) -> + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, TMask, MMS); +check_target_addr( + {Name, Ip, Udp, Timeout, RetryCount, TagList, Params, + TMask, MMS}) -> % Arity 9 + Domain = default_domain(), + Address = {Ip, Udp}, + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, TMask, MMS); +check_target_addr(X) -> + error({invalid_target_addr, X}). + +check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params) -> % Arity 7 + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + "dummy"). +%% +check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId) -> % Arity 8 + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId, [], 2048). +%% +check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + TMask, MMS) -> % Arity 9 + check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + "dummy", TMask, MMS). +%% +check_target_addr( + Name, Domain, Address, Timeout, RetryCount, TagList, Params, + EngineId, Mask, MMS) -> % Arity 10 ?vtrace("check target address with:" "~n Name: ~s" "~n Domain: ~p" - "~n Ip: ~p" - "~n Udp: ~p" + "~n Address: ~p" "~n Timeout: ~p" "~n RetryCount: ~p" "~n TagList: ~p" "~n Params: ~p" "~n EngineId: ~p" - "~n TMask: ~p" + "~n Mask: ~p" "~n MMS: ~p", - [Name, - Domain, Ip, Udp, + [Name, Domain, Address, Timeout, RetryCount, - TagList, Params, EngineId, TMask, MMS]), + TagList, Params, EngineId, Mask, MMS]), snmp_conf:check_string(Name,{gt,0}), snmp_conf:check_domain(Domain), - snmp_conf:check_ip(Domain, Ip), - snmp_conf:check_integer(Udp, {gt, 0}), + snmp_conf:check_address(Domain, Address), snmp_conf:check_integer(Timeout, {gte, 0}), snmp_conf:check_integer(RetryCount, {gte,0}), snmp_conf:check_string(TagList), snmp_conf:check_string(Params), check_engine_id(EngineId), - TAddress = snmp_conf:mk_taddress(Domain, Ip, Udp), + check_mask(Domain, Mask), TDomain = snmp_conf:mk_tdomain(Domain), - check_tmask(TDomain, TMask, TAddress), + TAddress = snmp_conf:mk_taddress(Domain, Address), + TMask = snmp_conf:mk_taddress(Domain, Mask), snmp_conf:check_packet_size(MMS), ?vtrace("check target address done",[]), Addr = {Name, TDomain, TAddress, Timeout, RetryCount, TagList, Params, ?'StorageType_nonVolatile', ?'RowStatus_active', EngineId, TMask, MMS}, % Values for Augmenting table in SNMP-COMMUNITY-MIB - {ok, Addr}; -check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, - Params, EngineId, TMask, MMS}) -> - Domain = default_domain(), - check_target_addr({Name, - Domain, Ip, Udp, - Timeout, RetryCount, TagList, - Params, EngineId, TMask, MMS}); -check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, Params, - EngineId}) -> - check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, - Params, EngineId, [], 2048}); -%% Use dummy engine id if the old style is found -check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, Params}) -> - check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, - Params, "dummy", [], 2048}); -%% Use dummy engine id if the old style is found -check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, Params, - TMask, MMS}) -> - check_target_addr({Name, Ip, Udp, Timeout, RetryCount, TagList, - Params, "dummy", TMask, MMS}); -check_target_addr(X) -> - error({invalid_target_addr, X}). - + {ok, Addr}. check_engine_id(discovery) -> ok; check_engine_id(EngineId) -> snmp_conf:check_string(EngineId). - -check_tmask(_TDomain, [], _TAddress) -> +check_mask(_Domain, []) -> ok; -check_tmask(TDomain, TMask, TAddress) when length(TMask) =:= length(TAddress) -> - snmp_conf:check_taddress(TDomain, TMask); -check_tmask(_TDomain, TMask, _TAddr) -> - throw({error, {invalid_tmask, TMask}}). - +check_mask(Domain, Mask) -> + try snmp_conf:check_address(Domain, Mask) + catch + {error, {invalid_address, Info}} -> + {error, {invalid_mask, Info}} + end. %%----------------------------------------------------------------- %% TargetParams diff --git a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl index 223d3f7218..69dce337ba 100644 --- a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl +++ b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2013. All Rights Reserved. +%% Copyright Ericsson AB 1999-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -137,18 +137,20 @@ do_reconfigure(Dir) -> read_usm_config_files(Dir) -> ?vdebug("read usm config file",[]), - Gen = fun(D, Reason) -> generate_usm(D, Reason) end, - Filter = fun(Usms) -> Usms end, - Check = fun(Entry) -> check_usm(Entry) end, + Gen = fun (D, Reason) -> generate_usm(D, Reason) end, + Order = fun snmp_conf:no_order/2, + Check = fun (Entry, State) -> {check_usm(Entry), State} end, + Filter = fun snmp_conf:no_filter/1, [Usms] = - snmp_conf:read_files(Dir, [{Gen, Filter, Check, "usm.conf"}]), + snmp_conf:read_files(Dir, [{"usm.conf", Gen, Order, Check, Filter}]), Usms. generate_usm(Dir, _Reason) -> info_msg("Incomplete configuration. Generating empty usm.conf.", []), USMFile = filename:join(Dir, "usm.conf"), - ok = file:write_file(USMFile, list_to_binary([])). + ok = file:write_file(USMFile, list_to_binary([])), + []. check_usm({EngineID, Name, SecName, Clone, AuthP, AuthKeyC, OwnAuthKeyC, diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl index c0177b1cea..722bd7ac5b 100644 --- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl +++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2013. All Rights Reserved. +%% Copyright Ericsson AB 1999-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -123,15 +123,18 @@ do_reconfigure(Dir) -> read_vacm_config_files(Dir) -> ?vdebug("read vacm config file",[]), - Gen = fun(_D, _Reason) -> ok end, - Filter = fun(Vacms) -> - Sec2Group = [X || {vacmSecurityToGroup, X} <- Vacms], - Access = [X || {vacmAccess, X} <- Vacms], - View = [X || {vacmViewTreeFamily, X} <- Vacms], - {Sec2Group, Access, View} - end, - Check = fun(Entry) -> check_vacm(Entry) end, - [Vacms] = snmp_conf:read_files(Dir, [{Gen, Filter, Check, "vacm.conf"}]), + Gen = fun snmp_conf:no_gen/2, + Order = fun snmp_conf:no_order/2, + Check = fun (Entry, State) -> {check_vacm(Entry), State} end, + Filter = + fun (Vacms) -> + Sec2Group = [X || {vacmSecurityToGroup, X} <- Vacms], + Access = [X || {vacmAccess, X} <- Vacms], + View = [X || {vacmViewTreeFamily, X} <- Vacms], + {Sec2Group, Access, View} + end, + [Vacms] = + snmp_conf:read_files(Dir, [{"vacm.conf", Gen, Order, Check, Filter}]), Vacms. %%----------------------------------------------------------------- diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index c17a6abbd7..a405987c8a 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2011. All Rights Reserved. +%% Copyright Ericsson AB 2006-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -123,21 +123,24 @@ append_agent_config(Dir, Conf) read_agent_config(Dir) -> - Verify = fun(Entry) -> verify_agent_conf_entry(Entry) end, - read_config_file(Dir, "agent.conf", Verify). + Order = fun snmp_framework_mib:order_agent/2, + Check = fun check_agent_conf_entry/2, + read_config_file(Dir, "agent.conf", Order, Check). - -verify_agent_conf([]) -> + +verify_agent_conf(Conf) -> + verify_agent_conf(Conf, undefined). +%% +verify_agent_conf([], _) -> ok; -verify_agent_conf([H|T]) -> - verify_agent_conf_entry(H), - verify_agent_conf(T); -verify_agent_conf(X) -> +verify_agent_conf([H|T], State) -> + {_, NewState} = check_agent_conf_entry(H, State), + verify_agent_conf(T, NewState); +verify_agent_conf(X, _) -> error({bad_agent_config, X}). -verify_agent_conf_entry(Entry) -> - ok = snmp_framework_mib:check_agent(Entry), - ok. +check_agent_conf_entry(Entry, State) -> + {ok, _NewState} = snmp_framework_mib:check_agent(Entry, State). write_agent_conf(Fd, "", Conf) -> write_agent_conf(Fd, Conf); @@ -204,8 +207,12 @@ append_context_config(Dir, Conf) read_context_config(Dir) -> - Verify = fun(Entry) -> verify_context_conf_entry(Entry) end, - read_config_file(Dir, "context.conf", Verify). + Order = fun snmp_conf:no_order/2, + Verify = + fun (Entry, State) -> + {verify_context_conf_entry(Entry), State} + end, + read_config_file(Dir, "context.conf", Order, Verify). verify_context_conf([]) -> @@ -286,8 +293,12 @@ append_community_config(Dir, Conf) read_community_config(Dir) -> - Verify = fun(Entry) -> verify_community_conf_entry(Entry) end, - read_config_file(Dir, "community.conf", Verify). + Order = fun snmp_conf:no_order/2, + Verify = + fun (Entry, State) -> + {verify_community_conf_entry(Entry), State} + end, + read_config_file(Dir, "community.conf", Order, Verify). verify_community_conf([]) -> @@ -358,8 +369,12 @@ append_standard_config(Dir, Conf) read_standard_config(Dir) -> - Verify = fun(Entry) -> verify_standard_conf_entry(Entry) end, - read_config_file(Dir, "standard.conf", Verify). + Order = fun snmp_conf:no_order/2, + Verify = + fun (Entry, State) -> + {verify_standard_conf_entry(Entry), State} + end, + read_config_file(Dir, "standard.conf", Order, Verify). verify_standard_conf([]) -> @@ -520,8 +535,12 @@ append_target_addr_config(Dir, Conf) read_target_addr_config(Dir) -> - Verify = fun(Entry) -> verify_target_addr_conf_entry(Entry) end, - read_config_file(Dir, "target_addr.conf", Verify). + Order = fun snmp_conf:no_order/2, + Verify = + fun (Entry, State) -> + {verify_target_addr_conf_entry(Entry), State} + end, + read_config_file(Dir, "target_addr.conf", Order, Verify). verify_target_addr_conf([]) -> @@ -626,8 +645,12 @@ append_target_params_config(Dir, Conf) read_target_params_config(Dir) -> - Verify = fun(Entry) -> verify_target_params_conf_entry(Entry) end, - read_config_file(Dir, "target_params.conf", Verify). + Order = fun snmp_conf:no_order/2, + Verify = + fun (Entry, State) -> + {verify_target_params_conf_entry(Entry), State} + end, + read_config_file(Dir, "target_params.conf", Order, Verify). verify_target_params_conf([]) -> @@ -698,8 +721,12 @@ append_notify_config(Dir, Conf) read_notify_config(Dir) -> - Verify = fun(Entry) -> verify_notify_conf_entry(Entry) end, - read_config_file(Dir, "notify.conf", Verify). + Order = fun snmp_conf:no_order/2, + Verify = + fun (Entry, State) -> + {verify_notify_conf_entry(Entry), State} + end, + read_config_file(Dir, "notify.conf", Order, Verify). verify_notify_conf([]) -> @@ -794,8 +821,12 @@ append_usm_config(Dir, Conf) read_usm_config(Dir) -> - Verify = fun(Entry) -> verify_usm_conf_entry(Entry) end, - read_config_file(Dir, "usm.conf", Verify). + Order = fun snmp_conf:no_order/2, + Verify = + fun (Entry, State) -> + {verify_usm_conf_entry(Entry), State} + end, + read_config_file(Dir, "usm.conf", Order, Verify). verify_usm_conf([]) -> @@ -903,8 +934,12 @@ append_vacm_config(Dir, Conf) read_vacm_config(Dir) -> - Verify = fun(Entry) -> verify_vacm_conf_entry(Entry) end, - read_config_file(Dir, "vacm.conf", Verify). + Order = fun snmp_conf:no_order/2, + Verify = + fun (Entry, State) -> + {verify_vacm_conf_entry(Entry), State} + end, + read_config_file(Dir, "vacm.conf", Order, Verify). verify_vacm_conf([]) -> @@ -958,8 +993,8 @@ write_config_file(Dir, File, Verify, Write) -> append_config_file(Dir, File, Verify, Write) -> snmp_config:append_config_file(Dir, File, Verify, Write). -read_config_file(Dir, File, Verify) -> - snmp_config:read_config_file(Dir, File, Verify). +read_config_file(Dir, File, Order, Check) -> + snmp_config:read_config_file(Dir, File, Order, Check). %% ---- config file utility functions ---- @@ -972,6 +1007,5 @@ header() -> "~2.2.0w:~2.2.0w:~2.2.0w\n", [?MODULE, ?version, Y, Mo, D, H, Mi, S]). - error(R) -> throw({error, R}). diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index 11ae806866..9bb4556788 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2013. All Rights Reserved. +%% Copyright Ericsson AB 1997-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -183,11 +183,30 @@ discarded_pdu(Variable) -> inc(Variable). %%----------------------------------------------------------------- %% Handles a Community based message (v1 or v2c). %%----------------------------------------------------------------- -v1_v2c_proc(Vsn, NoteStore, Community, Domain, - {Ip, Udp}, LocalEngineID, - Data, HS, Log, Packet) -> +v1_v2c_proc( + Vsn, NoteStore, Community, Domain, Address, + LocalEngineID, Data, HS, Log, Packet) -> + try snmp_conf:check_domain(Domain) of + ok -> + try snmp_conf:check_address(Domain, Address) of + ok -> + v1_v2c_proc_dec( + Vsn, NoteStore, Community, Domain, Address, + LocalEngineID, Data, HS, Log, Packet) + catch + _ -> + {discarded, {badarg, Address}} + end + catch + _ -> + {discarded, {badarg, Domain}} + end. + +v1_v2c_proc_dec( + Vsn, NoteStore, Community, Domain, Address, + LocalEngineID, Data, HS, Log, Packet) -> TDomain = snmp_conf:mk_tdomain(Domain), - TAddress = snmp_conf:mk_taddress(Domain, Ip, Udp), + TAddress = snmp_conf:mk_taddress(Domain, Address), AgentMS = get_engine_max_message_size(LocalEngineID), MgrMS = snmp_community_mib:get_target_addr_ext_mms(TDomain, TAddress), PduMS = case MgrMS of @@ -214,7 +233,7 @@ v1_v2c_proc(Vsn, NoteStore, Community, Domain, case Pdu#pdu.type of 'set-request' -> %% Check if this message has already been processed - Key = {agent, Ip, ReqId}, + Key = {agent, {Domain, Address}, ReqId}, case snmp_note_store:get_note(NoteStore, Key) of undefined -> %% Set the processed note _after_ pdu processing. @@ -236,13 +255,7 @@ v1_v2c_proc(Vsn, NoteStore, Community, Domain, {discarded, Reason}; _TrapPdu -> {discarded, trap_pdu} - end; -v1_v2c_proc(_Vsn, _NoteStore, _Community, snmpUDPDomain, TAddress, - _LocalEngineID, _Data, _HS, _Log, _Packet) -> - {discarded, {badarg, TAddress}}; -v1_v2c_proc(_Vsn, _NoteStore, _Community, TDomain, _TAddress, - _LocalEngineID, _Data, _HS, _Log, _Packet) -> - {discarded, {badarg, TDomain}}. + end. sec_model('version-1') -> ?SEC_V1; sec_model('version-2') -> ?SEC_V2C. diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 2101ad46e1..43d394e9d9 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -1666,7 +1666,7 @@ init_agent_default(Item, Val) when Item =/= user_id -> read_agents_config_file(Dir) -> - Check = fun(C) -> check_agent_config2(C) end, + Check = fun(C, S) -> {check_agent_config2(C), S} end, case read_file(Dir, "agents.conf", Check, []) of {ok, Conf} -> Conf; @@ -1837,7 +1837,7 @@ verify_agent2([Bad|_], _VerifiedConf) -> read_users_config_file(Dir) -> - Check = fun(C) -> check_user_config(C) end, + Check = fun(C, S) -> {check_user_config(C), S} end, case read_file(Dir, "users.conf", Check, []) of {ok, Conf} -> Conf; @@ -1950,7 +1950,7 @@ verify_user_agent_config(Conf) -> end. read_usm_config_file(Dir) -> - Check = fun(C) -> check_usm_user_config(C) end, + Check = fun(C, S) -> {check_usm_user_config(C), S} end, case read_file(Dir, "usm.conf", Check, []) of {ok, Conf} -> Conf; @@ -2139,7 +2139,7 @@ is_crypto_supported(Func) -> read_manager_config_file(Dir) -> - Check = fun(Conf) -> check_manager_config(Conf) end, + Check = fun(Conf, State) -> {check_manager_config(Conf), State} end, case read_file(Dir, "manager.conf", Check) of {ok, Conf} -> ?d("read_manager_config_file -> ok: " diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 46625989d5..c52b4bb6fb 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -25,7 +25,8 @@ %% External exports %% Avoid warning for local function error/1 clashing with autoimported BIF. -compile({no_auto_import,[error/1]}). --export([read_files/2, read/2]). +-export([read_files/2, no_gen/2, no_order/2, no_filter/1]). +-export([read/2, read/3]). %% Basic (type) check functions -export([check_mandatory/2, @@ -43,9 +44,10 @@ check_tdomain/1, mk_tdomain/1, which_domain/1, - check_ip/1, check_ip/2, - check_taddress/1, check_taddress/2, - mk_taddress/3, + check_ip/1, check_ip/2, + check_address/2, + check_taddress/2, + mk_taddress/2, mk_taddress/3, check_packet_size/1, @@ -70,17 +72,53 @@ -include("snmp_verbosity.hrl"). +-define(is_word(P), (((P) band (bnot 65535)) =:= 0)). +-define(is_word(P0, P1), ((((P0) bor (P1)) band (bnot 255)) =:= 0)). + +mk_word(B0, B1) -> ((B0) bsl 8) bor (B1). +mk_bytes(W) -> [(W) bsr 8,(W) band 255]. + +-define( + is_ipv4_addr(A0, A1, A2, A3), + ((((A0) bor (A1) bor (A2) bor (A3)) band (bnot 255)) =:= 0)). + +-define( + is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), + ((((A0) bor (A1) bor (A2) bor (A3) bor (A4) bor (A5) bor (A6) bor (A7)) + band (bnot 65535)) =:= 0)). +-define( + is_ipv6_addr( + A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15), + ((((A0) bor (A1) bor (A2) bor (A3) bor + (A4) bor (A5) bor (A6) bor (A7) bor + (A8) bor (A9) bor (A10) bor (A11) bor + (A12) bor (A13) bor (A14) bor (A15)) + band (bnot 65535)) =:= 0)). + + %%----------------------------------------------------------------- %% read_files(Dir, Files) -> Configs %% Dir - string() - Full path to the config dir. -%% Files - [{Gen, Filter, Check, FileName}] +%% Files - [{FileName, Gen, Order, Check, Filter}] +%% FileName - string() - Name of the config file. %% Gen - function/2 - In case of failure when reading the config file, %% this function is called to either generate a %% default file or issue the error. -%% Filter - function/1 - Filters all the config entries read from the file -%% Check - function/1 - Check each entry as they are read from the file. -%% FileName - string() - Name of the config file. +%% Returns a generated config list corresponding +%% to the written file. +%% (Dir, Error) -> Configs. +%% Order - function/2 - An ordering function that is used to process +%% the read config entries using lists:sort/2. +%% Returns true if arg 1 compares less than or +%% equal to arg 2, false otherwise. +%% Check - function/2 - Check each entry as they are read from the file. +%% (Entry, State) -> +%% {ok,NewState} | {{ok,NewEntry},NewState} | +%% throw(Error) +%% State =:= 'undefined' the first time. +%% Filter - function/1 - Process all the config entries read from the file +%% (Configs) -> [config_entry()]. %% Configs - [config_entry()] %% config_entry() - term() @@ -89,24 +127,122 @@ read_files(Dir, Files) when is_list(Dir) andalso is_list(Files) -> read_files(_Dir, [], Res) -> lists:reverse(Res); -read_files(Dir, [{Gen, Filter, Check, FileName}|Files], Res) - when is_function(Filter) andalso - is_function(Check) andalso - is_list(FileName) -> - ?vdebug("read_files -> entry with" - "~n FileName: ~p", [FileName]), +read_files(Dir, [{FileName, Gen, Order, Check, Filter}|Files], Res) + when is_list(FileName), + is_function(Gen), + is_function(Order), + is_function(Check), + is_function(Filter) -> + ?vdebug("read_files -> entry with~n" + " FileName: ~p", [FileName]), File = filename:join(Dir, FileName), - case file:read_file_info(File) of - {ok, _} -> - Confs = read(File, Check), - read_files(Dir, Files, [Filter(Confs)|Res]); - {error, R} -> - ?vlog("failed reading file info for ~s: " - "~n ~p", [FileName, R]), - Gen(Dir, R), - read_files(Dir, Files, [Filter([])|Res]) + Confs = + case file:read_file_info(File) of + {ok,_} -> + read(File, Order, Check); + {error, R} -> + ?vlog("failed reading file info for ~s: ~n" + " ~p", [FileName, R]), + Gen(Dir, R) + end, + read_files(Dir, Files, [Filter(Confs)|Res]). +%% %% +%% %% XXX remove +%% %% +%% %% read_files(Dir, Files) -> Configs +%% %% Dir - string() - Full path to the config dir. +%% %% Files - [{Gen, Filter, Check, FileName}] +%% %% Gen - function/2 - In case of failure when reading the config file, +%% %% this function is called to either generate a +%% %% default file or issue the error. +%% %% Filter - function/1 - Filters all the config entries read from the file +%% %% Check - function/1 - Check each entry as they are read from the file. +%% %% FileName - string() - Name of the config file. +%% %% Configs - [config_entry()] +%% %% config_entry() - term() +%% +%% read_files(Dir, [{Gen, Filter, Check, FileName}|Files], Res) +%% when is_function(Filter) andalso +%% is_function(Check) andalso +%% is_list(FileName) -> +%% ?vdebug("read_files -> entry with" +%% "~n FileName: ~p", [FileName]), +%% File = filename:join(Dir, FileName), +%% case file:read_file_info(File) of +%% {ok, _} -> +%% Confs = read(File, Check), +%% read_files(Dir, Files, [Filter(Confs)|Res]); +%% {error, R} -> +%% ?vlog("failed reading file info for ~s: " +%% "~n ~p", [FileName, R]), +%% Gen(Dir, R), +%% read_files(Dir, Files, [Filter([])|Res]) +%% end. + +no_gen(_Dir, _R) -> []. +no_order(_, _) -> true. +no_filter(X) -> X. + + + +%% Ret. Res | exit(Reason) +read(File, Order, Check) when is_function(Order), is_function(Check) -> + ?vdebug("read -> entry with~n" + " File: ~p", [File]), + Fd = open_file(File), + read_fd(File, Order, Check, Fd, 1, []). + +read_fd(File, Order, Check, Fd, StartLine, Res) -> + case do_read(Fd, "", StartLine) of + {ok, Row, EndLine} -> + ?vtrace("read_fd ->~n" + " Row: ~p~n" + " EndLine: ~p", [Row,EndLine]), + read_fd( + File, Order, Check, Fd, EndLine, + [{StartLine, Row, EndLine}|Res]); + {error, Error, EndLine} -> + ?vtrace("read_fd -> read failure:~n" + " Error: ~p~n" + " EndLine: ~p", [Error,EndLine]), + file:close(Fd), + error({failed_reading, File, StartLine, EndLine, Error}); + {eof, _EndLine} -> + Lines = + lists:sort( + fun ({_, RowA, _}, {_, RowB, _}) -> + Order(RowA, RowB) + end, + lists:reverse(Res)), + read_check(File, Check, Lines, undefined, []) end. +read_check(_, _, [], _, Res) -> + lists:reverse(Res); +read_check(File, Check, [{StartLine, Row, EndLine}|Lines], State, Res) -> + try Check(Row, State) of + {ok, NewState} -> + ?vtrace("read_check -> ok", []), + read_check(File, Check, Lines, NewState, [Row|Res]); + {{ok, NewRow}, NewState} -> + ?vtrace("read_check -> ok:~n" + " NewRow: ~p~n", [NewRow]), + read_check(File, Check, Lines, NewState, [NewRow|Res]) + catch + {error, Reason} -> + ?vtrace("read_check -> error:~n" + " Reason: ~p", [Reason]), + error({failed_check, File, StartLine, EndLine, Reason}); + Class:Reason -> + Error = {Class,Reason,erlang:get_stacktrace()}, + ?vtrace("read_check -> failure:~n" + " Error: ~p", [Error]), + error({failed_check, File, StartLine, EndLine, Error}) + end. + + + +%% XXX remove %% Ret. Res | exit(Reason) read(File, Check) when is_function(Check) -> @@ -155,11 +291,11 @@ loop(Fd, Res, Check, StartLine, File) -> "~n Error: ~p", [Error]), {error, {failed_check, File, StartLine, EndLine, Error}} end; - {error, EndLine, Error} -> + {error, Error, EndLine} -> ?vtrace("loop -> read failure: " "~n Error: ~p", [Error]), {error, {failed_reading, File, StartLine, EndLine, Error}}; - eof -> + {eof, _EndLine} -> {ok, Res} end. @@ -171,12 +307,8 @@ do_read(Io, Prompt, StartLine) -> {ok, Term} -> {ok, Term, EndLine}; {error, {Line, erl_parse, Error}} -> - {error, Line, {parse_error, Error}} + {error, {parse_error, Error}, Line} end; - {error,E,EndLine} -> - {error, EndLine, E}; - {eof, _EndLine} -> - eof; Other -> Other end. @@ -384,7 +516,7 @@ all_tdomains() -> check_tdomain(TDomain) -> SupportedTDomains = [ - ?snmpUDPDomain, + ?snmpUDPDomain, % Legacy ?transportDomainUdpIpv4, ?transportDomainUdpIpv6 ], @@ -416,40 +548,38 @@ mk_tdomain(BadDomain) -> %% --------- -check_taddress(X) -> - check_taddress(snmpUDPDomain, X). +%% XXX remove +%% check_taddress(X) -> +%% check_taddress(snmpUDPDomain, X). check_taddress(?snmpUDPDomain, X) -> check_taddress(transportDomainUdpIpv4, X); check_taddress(snmpUDPDomain, X) -> check_taddress(transportDomainUdpIpv4, X); - +%% check_taddress(?transportDomainUdpIpv4, X) -> check_taddress(transportDomainUdpIpv4, X); -check_taddress(transportDomainUdpIpv4, X) - when is_list(X) andalso (length(X) =:= 6) -> - case (catch all_integer(X)) of - true -> +check_taddress(transportDomainUdpIpv4, X) -> + case X of + [A0,A1,A2,A3,P0,P1] + when ?is_ipv4_addr(A0, A1, A2, A3), ?is_word(P0, P1) -> ok; - false -> + _ -> error({invalid_taddress, X}) end; -check_taddress(transportDomainUdpIpv4, X) -> - error({invalid_taddress, X}); - +%% check_taddress(?transportDomainUdpIpv6, X) -> check_taddress(transportDomainUdpIpv6, X); -check_taddress(transportDomainUdpIpv6, X) - when is_list(X) andalso (length(X) =:= 10) -> - case (catch all_integer(X)) of - true -> +check_taddress(transportDomainUdpIpv6, X) -> + case X of + [A0,A1,A2,A3,A4,A5,A6,A7,P0,P1] + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), + ?is_word(P0, P1) -> ok; - false -> + _ -> error({invalid_taddress, X}) end; -check_taddress(transportDomainUdpIpv6, X) -> - error({invalid_taddress, X}); - +%% check_taddress(BadDomain, _X) -> error({invalid_tdomain, BadDomain}). @@ -512,31 +642,65 @@ all_domains() -> transportDomainSctpDns ]. +check_domain(snmpUDPDomain) -> ok; +check_domain(transportDomainUdpIpv4) -> ok; +check_domain(transportDomainUdpIpv6) -> ok; check_domain(Domain) -> - SupportedDomains = - [ - snmpUDPDomain, - transportDomainUdpIpv4, - transportDomainUdpIpv6 - ], - AllDomains = all_domains(), - case lists:member(Domain, SupportedDomains) of + case lists:member(Domain, all_domains()) of true -> - ok; + error({unsupported_domain, Domain}); false -> - case lists:member(Domain, AllDomains) of - true -> - error({unsupported_domain, Domain}); - false -> - error({unknown_domain, Domain}) - end + error({unknown_domain, Domain}) end. - + %% --------- -%% The values of Ip and Port has both been checked at this +%% The values of Domain, Ip and Port has both been checked at this %% point, so we dont need to do that again. + +mk_taddress(snmpUDPDomain, Address) -> + mk_taddress(transportDomainUdpIpv4, Address); +mk_taddress(transportDomainUdpIpv4, {Ip, Port}) when is_list(Ip) -> + Ip ++ mk_bytes(Port); +mk_taddress(transportDomainUdpIpv4, {Ip, Port}) when is_tuple(Ip) -> + tuple_to_list(Ip) ++ mk_bytes(Port); +mk_taddress(transportDomainUdpIpv4, IpPort) when is_list(IpPort) -> + IpPort; % Should be length 6 +mk_taddress(transportDomainUdpIpv6, {Ip, Port}) when is_list(Ip) -> + Ip ++ mk_bytes(Port); +mk_taddress(transportDomainUdpIpv6, {Ip, Port}) when is_tuple(Ip) -> + tuple_to_list(Ip) ++ mk_bytes(Port); +mk_taddress(transportDomainUdpIpv6, IpPort) when is_list(IpPort) -> + case IpPort of + [A0,A1,A2,A3,A4,A5,A6,A7,P] -> + [A0,A1,A2,A3,A4,A5,A6,A7] ++ mk_bytes(P); + [A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,P0,P1] -> + [mk_word(A0, A1),mk_word(A2, A3), + mk_word(A4, A5),mk_word(A6, A7), + mk_word(A8, A9),mk_word(A10, A11), + mk_word(A12, A13),mk_word(A14, A15),P0,P1]; + _ -> + IpPort % Should already be 8 words and 2 bytes hence length 10 + end; +mk_taddress(Domain, Address) when is_atom(Domain) -> + erlang:error(badarg, [Domain,Address]); +%% +%% These are just for convenience +mk_taddress(?snmpUDPDomain, Address) -> + mk_taddress(snmpUDPDomain, Address); +mk_taddress(?transportDomainUdpIpv4, Address) -> + mk_taddress(transportDomainUdpIpv4, Address); +mk_taddress(?transportDomainUdpIpv6, Address) -> + mk_taddress(transportDomainUdpIpv6, Address); +%% Bad domain +mk_taddress(BadDomain, _) -> + error({bad_domain, BadDomain}). + + + +%% XXX remove + mk_taddress(snmpUDPDomain, Ip, Port) -> mk_taddress(transportDomainUdpIpv4, Ip, Port); mk_taddress(transportDomainUdpIpv4, Ip, Port) when is_list(Ip) -> @@ -547,7 +711,7 @@ mk_taddress(transportDomainUdpIpv6, Ip, Port) when is_list(Ip) -> Ip ++ [Port div 256, Port rem 256]; mk_taddress(transportDomainUdpIpv6 = Domain, Ip, Port) when is_tuple(Ip) -> mk_taddress(Domain, tuple_to_list(Ip), Port); - +%% %% These are just for convenience mk_taddress(?snmpUDPDomain, Ip, Port) -> mk_taddress(snmpUDPDomain, Ip, Port); @@ -555,7 +719,7 @@ mk_taddress(?transportDomainUdpIpv4, Ip, Port) -> mk_taddress(transportDomainUdpIpv4, Ip, Port); mk_taddress(?transportDomainUdpIpv6, Ip, Port) -> mk_taddress(transportDomainUdpIpv6, Ip, Port); - +%% %% Bad domain mk_taddress(BadDomain, _Ip, _Port) -> error({bad_domain, BadDomain}). @@ -563,47 +727,113 @@ mk_taddress(BadDomain, _Ip, _Port) -> %% --------- -which_domain(Ip) when is_list(Ip) andalso (length(Ip) =:= 4) -> +%% XXX remove + +which_domain([A0,A1,A2,A3]) when ?is_ipv4_addr(A0, A1, A2, A3) -> transportDomainUdpIpv4; -which_domain(Ip) when is_tuple(Ip) andalso (size(Ip) =:= 4) -> +which_domain({A0,A1,A2,A3}) when ?is_ipv4_addr(A0, A1, A2, A3) -> transportDomainUdpIpv4; -which_domain(Ip) when is_list(Ip) andalso (length(Ip) =:= 8) -> +which_domain([A0,A1,A2,A3,A4,A5,A6,A7]) + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7) -> transportDomainUdpIpv6; -which_domain(Ip) when is_tuple(Ip) andalso (size(Ip) =:= 8) -> +which_domain({A0, A1, A2, A3, A4, A5, A6, A7}) + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7) -> transportDomainUdpIpv6. %% --------- +%% XXX remove + check_ip(X) -> check_ip(snmpUDPDomain, X). check_ip(snmpUDPDomain, X) -> check_ip(transportDomainUdpIpv4, X); -check_ip(transportDomainUdpIpv4, X) when is_list(X) andalso (length(X) =:= 4) -> - case (catch all_integer(X)) of - true -> +check_ip(transportDomainUdpIpv4, X) -> + case X of + [A,B,C,D] when ?is_ipv4_addr(A, B, C, D) -> ok; - false -> + _ -> error({invalid_ip_address, X}) end; -check_ip(transportDomainUdpIpv4, X) -> - error({invalid_ip_address, X}); - -check_ip(transportDomainUdpIpv6, X) when is_list(X) andalso (length(X) =:= 8) -> - case (catch all_integer(X)) of - true -> +check_ip(transportDomainUdpIpv6, X) -> + case X of + [A,B,C,D,E,F,G,H] + when ?is_ipv6_addr(A, B, C, D, E, F, G, H) -> ok; - false -> + [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P] + when ?is_ipv6_addr( + A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> + ok; + _ -> error({invalid_ip_address, X}) end; -check_ip(transportDomainUdpIpv6, X) -> - error({invalid_ip_address, X}); - +%% check_ip(BadDomain, _X) -> error({invalid_domain, BadDomain}). +%% --------- + +%% Check a configuration term field from a file to see if it +%% can be fed to mk_taddress/2. + +check_address(Domain, Address) + when Domain =:= snmpUDPDomain; + Domain =:= transportDomainUdpIpv4 -> + case Address of + %% Erlang native format + {{A0, A1, A2, A3}, P} + when ?is_ipv4_addr(A0, A1, A2, A3), ?is_word(P) -> + ok; + %% Erlangish format + {[A0,A1,A2,A3], P} + when ?is_ipv4_addr(A0, A1, A2, A3), ?is_word(P) -> + ok; + %% SNMP standards format + [A0,A1,A2,A3,P0,P1] + when ?is_ipv4_addr(A0, A1, A2, A3), ?is_word(P0, P1) -> + ok; + _ -> + error({invalid_address, {Domain, Address}}) + end; +check_address(transportDomainUdpIpv6 = Domain, Address) -> + case Address of + %% Erlang native format + {{A0, A1, A2, A3, A4, A5, A6, A7}, P} + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), + ?is_word(P) -> + ok; + %% Erlangish format + {[A0,A1,A2,A3,A4,A5,A6,A7], P} + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), + ?is_word(P) -> + ok; + %% Erlang friendly list format + [A0,A1,A2,A3,A4,A5,A6,A7,P] + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), + ?is_word(P) -> + ok; + %% Strange hybrid format with port as bytes + [A0,A1,A2,A3,A4,A5,A6,A7,P0,P1] + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), + ?is_word(P0, P1) -> + ok; + %% SNMP standards format + [A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,P0,P1] + when ?is_ipv6_addr( + A0, A1, A2, A3, A4, A5, A6, A7, + A8, A9, A10, A11, A12, A13, A14, A15), + ?is_word(P0, P1) -> + ok; + _ -> + error({invalid_address, {Domain, Address}}) + end; +check_address(BadDomain, _) -> + error({invalid_domain, BadDomain}). + + %% --------- diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index a222f842e5..ec6b2ac7e4 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -26,7 +26,8 @@ -compile({no_auto_import,[error/1]}). -export([config/0]). --export([write_config_file/4, append_config_file/4, read_config_file/3]). +-export([write_config_file/4, append_config_file/4, + read_config_file/3, read_config_file/4]). -export([write_agent_snmp_files/7, write_agent_snmp_files/12, @@ -2471,7 +2472,9 @@ append_config_file(Dir, FileName, Verify, Write) throw:Error -> Error; T:E -> - {error, {failed_append, Dir, FileName, T, E}} + {error, + {failed_append, Dir, FileName, + {T, E, erlang:get_stacktrace()}}} end. do_append_config_file(Dir, FileName, Verify, Write) -> @@ -2500,59 +2503,131 @@ file_write_and_close(Write, Fd, Dir, FileName) -> end. +%% XXX remove +read_config_file(Dir, FileName, Verify) -> + read_config_file( + Dir, FileName, fun snmp_conf:no_order/2, + fun (Term, State) -> + {Verify(Term), State} + end). + -spec read_config_file(Dir :: string(), - FileName :: string(), - Verify :: verify_config_entry_function()) -> + FileName :: string(), + Order :: function(), + Verify :: function()) -> {ok, Config :: list()} | {error, Reason :: term()}. -read_config_file(Dir, FileName, Verify) - when is_list(Dir) andalso is_list(FileName) andalso is_function(Verify) -> - (catch do_read_config_file(Dir, FileName, Verify)). - -do_read_config_file(Dir, FileName, Verify) -> +read_config_file(Dir, FileName, Order, Check) + when is_list(Dir), is_list(FileName), + is_function(Order), is_function(Check) -> case file:open(filename:join(Dir, FileName), [read]) of {ok, Fd} -> - Result = read_loop(Fd, [], Verify, 1), - file:close(Fd), - Result; + try + {ok, + verify_lines( + lists:sort( + fun ({_, T1, _}, {_, T2, _}) -> + Order(T1, T2) + end, + read_lines(Fd, [], 1)), + Check, undefined, [])} + catch + Error -> + {error, Error} + after + file:close(Fd) + end; {error, Reason} -> {error, {Reason, FileName}} end. -read_loop(Fd, Acc, Check, StartLine) -> - case read_term(Fd, StartLine) of +read_lines(Fd, Acc, StartLine) -> + case read_and_parse_term(Fd, StartLine) of {ok, Term, EndLine} -> - case (catch Check(Term)) of - ok -> - read_loop(Fd, [Term | Acc], Check, EndLine); - {error, Reason} -> - {error, {failed_check, StartLine, EndLine, Reason}}; - Error -> - {error, {failed_check, StartLine, EndLine, Error}} - end; - {error, EndLine, Error} -> - {error, {failed_reading, StartLine, EndLine, Error}}; - eof -> - {ok, lists:reverse(Acc)} + read_lines(Fd, [{StartLine, Term, EndLine}|Acc], EndLine); + {error, Error, EndLine} -> + throw({failed_reading, StartLine, EndLine, Error}); + {eof, _EndLine} -> + lists:reverse(Acc) end. - -read_term(Fd, StartLine) -> + +read_and_parse_term(Fd, StartLine) -> case io:request(Fd, {get_until, "", erl_scan, tokens, [StartLine]}) of {ok, Tokens, EndLine} -> case erl_parse:parse_term(Tokens) of {ok, Term} -> {ok, Term, EndLine}; {error, {Line, erl_parse, Error}} -> - {error, Line, {parse_error, Error}} + {error, {parse_error, Error}, Line} end; - {error, E, EndLine} -> - {error, EndLine, E}; - {eof, _EndLine} -> - eof; Other -> Other end. +verify_lines([], _, Acc, _) -> + list:reverse(Acc); +verify_lines( + [{StartLine, Term, EndLine}|Lines], State, Acc, Check) -> + try Check(Term, State) of + {ok, NewState} -> + verify_lines(Lines, NewState, [Term|Acc], Check); + {{ok, NewTerm}, NewState} -> + verify_lines(Lines, NewState, [NewTerm|Acc], Check) + catch + {error, Reason} -> + throw({failed_check, StartLine, EndLine, Reason}); + C:R -> + S = erlang:get_stacktrace(), + throw({failed_check, StartLine, EndLine, {C, R, S}}) + end. + + +%% XXX remove + +%% do_read_config_file(Dir, FileName, Verify) -> +%% case file:open(filename:join(Dir, FileName), [read]) of +%% {ok, Fd} -> +%% Result = read_loop(Fd, [], Verify, 1), +%% file:close(Fd), +%% Result; +%% {error, Reason} -> +%% {error, {Reason, FileName}} +%% end. + +%% read_loop(Fd, Acc, Check, StartLine) -> +%% case read_term(Fd, StartLine) of +%% {ok, Term, EndLine} -> +%% case (catch Check(Term)) of +%% ok -> +%% read_loop(Fd, [Term | Acc], Check, EndLine); +%% {error, Reason} -> +%% {error, {failed_check, StartLine, EndLine, Reason}}; +%% Error -> +%% {error, {failed_check, StartLine, EndLine, Error}} +%% end; +%% {error, EndLine, Error} -> +%% {error, {failed_reading, StartLine, EndLine, Error}}; +%% eof -> +%% {ok, lists:reverse(Acc)} +%% end. + +%% read_term(Fd, StartLine) -> +%% case io:request(Fd, {get_until, "", erl_scan, tokens, [StartLine]}) of +%% {ok, Tokens, EndLine} -> +%% case erl_parse:parse_term(Tokens) of +%% {ok, Term} -> +%% {ok, Term, EndLine}; +%% {error, {Line, erl_parse, Error}} -> +%% {error, Line, {parse_error, Error}} +%% end; +%% {error, E, EndLine} -> +%% {error, EndLine, E}; +%% {eof, _EndLine} -> +%% eof; +%% Other -> +%% Other +%% end. + agent_snmp_mk_secret(Alg, Passwd, EngineID) -> snmp_usm:passwd2localized_key(Alg, Passwd, EngineID). diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index d7109253f7..bfedd7558c 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2013. All Rights Reserved. +%% Copyright Ericsson AB 2005-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -1375,9 +1375,9 @@ config(Vsns, MgrDir, AgentConfDir, MIp, AIp) -> "~n MIp: ~p" "~n AIp: ~p", [Vsns, MgrDir, AgentConfDir, MIp, AIp]), - ?line snmp_config:write_agent_snmp_files(AgentConfDir, Vsns, - MIp, ?TRAP_UDP, AIp, 4000, - "test"), + ?line ok = + snmp_config:write_agent_snmp_files( + AgentConfDir, Vsns, MIp, ?TRAP_UDP, AIp, 4000, "test"), ?line case update_usm(Vsns, AgentConfDir) of true -> ?line copy_file(join(AgentConfDir, "usm.conf"), @@ -1486,7 +1486,7 @@ rewrite_usm_mgr(Dir, ShaKey, DesKey) -> {"mgrEngine", "newUser", "newUser", zeroDotZero, usmHMACSHAAuthProtocol, "", "", usmDESPrivProtocol, "", "", "", ShaKey, DesKey}], - ok = snmp_config:write_agent_usm_config(Dir, "", Conf). + ?line ok = snmp_config:write_agent_usm_config(Dir, "", Conf). reset_usm_mgr(Dir) -> ?line ok = file:rename(join(Dir,"usm.old"), @@ -1512,13 +1512,15 @@ update_vacm(_Vsn, Dir) -> write_community_conf(Dir, Conf) -> - snmp_config:write_agent_community_config(Dir, "", Conf). + ?line ok = snmp_config:write_agent_community_config(Dir, "", Conf). write_target_addr_conf(Dir, Conf) -> - snmp_config:write_agent_target_addr_config(Dir, "", Conf). + ?line ok = snmp_config:write_agent_target_addr_config(Dir, "", Conf). write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> - snmp_config:write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, Vsns). + ?line ok = + snmp_config:write_agent_snmp_target_addr_conf( + Dir, ManagerIp, UDP, Vsns). rewrite_target_addr_conf(Dir, NewPort) -> ?DBG("rewrite_target_addr_conf -> entry with" @@ -1571,14 +1573,14 @@ write_target_params_conf(Dir, Vsns) -> (v3) -> {"target_v3", v3, usm, "all-rights", noAuthNoPriv} end, Conf = [F(Vsn) || Vsn <- Vsns], - snmp_config:write_agent_target_params_config(Dir, "", Conf). + ?line ok = snmp_config:write_agent_target_params_config(Dir, "", Conf). rewrite_target_params_conf(Dir, SecName, SecLevel) when is_list(SecName) andalso is_atom(SecLevel) -> ?line ok = file:rename(join(Dir,"target_params.conf"), join(Dir,"target_params.old")), Conf = [{"target_v3", v3, usm, SecName, SecLevel}], - snmp_config:write_agent_target_params_config(Dir, "", Conf). + ?line ok = snmp_config:write_agent_target_params_config(Dir, "", Conf). reset_target_params_conf(Dir) -> ?line ok = file:rename(join(Dir,"target_params.old"), @@ -1587,12 +1589,12 @@ reset_target_params_conf(Dir) -> write_notify_conf(Dir) -> Conf = [{"standard trap", "std_trap", trap}, {"standard inform", "std_inform", inform}], - snmp_config:write_agent_notify_config(Dir, "", Conf). + ?line ok = snmp_config:write_agent_notify_config(Dir, "", Conf). write_view_conf(Dir) -> Conf = [{2, [1,3,6], included, null}, {2, ?tDescr_instance, excluded, null}], - snmp_config:write_agent_view_config(Dir, "", Conf). + ?line ok = snmp_config:write_agent_view_config(Dir, "", Conf). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -- cgit v1.2.3 From 7bc7e5821ea0614ca82467bf0349f82b61d89971 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 11 Apr 2014 16:14:00 +0200 Subject: wip --- lib/snmp/src/agent/snmp_framework_mib.erl | 9 +- lib/snmp/src/agent/snmp_target_mib.erl | 22 +- lib/snmp/src/agent/snmpa_conf.erl | 2 +- lib/snmp/src/agent/snmpa_mpd.erl | 16 +- lib/snmp/src/manager/snmpm_config.erl | 642 ++++++++++++++---------------- lib/snmp/src/manager/snmpm_mpd.erl | 69 ++-- lib/snmp/src/misc/snmp_conf.erl | 381 ++++++++++-------- 7 files changed, 560 insertions(+), 581 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 84f39df228..51f8c46d19 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -197,12 +197,7 @@ check_context(Context) -> %% {Name, Value}. %%----------------------------------------------------------------- check_agent({intAgentTransportDomain, D}, Domain) -> - case Domain of - undefined -> - {snmp_conf:check_domain(D), D}; - _ -> - error({invalid_agent_attribute, D}) - end; + {snmp_conf:check_domain(D), D}; check_agent({intAgentTransportAddress, Address}, Domain) -> {snmp_conf:check_address(Domain, Address), Domain}; check_agent(Entry, Domain) -> @@ -224,7 +219,7 @@ check_agent(X) -> %% Ordering function to sort intAgentTransportDomain first %% hence before intAgentTransportAddress -order_agent({intAgentTransportDomain, _}, {intAgentTransportDomain, _}) -> +order_agent({Name, _}, {Name, _}) -> true; %% Less than or equal order_agent(_, {intAgentTransportDomain, _}) -> false; %% Greater than diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index 6dd3b6e23a..cff1e253c3 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -263,16 +263,16 @@ check_target_addr( TagList, Params, EngineId, Mask, MMS]), snmp_conf:check_string(Name,{gt,0}), snmp_conf:check_domain(Domain), - snmp_conf:check_address(Domain, Address), + NAddress = snmp_conf:check_address(Domain, Address), snmp_conf:check_integer(Timeout, {gte, 0}), snmp_conf:check_integer(RetryCount, {gte,0}), snmp_conf:check_string(TagList), snmp_conf:check_string(Params), check_engine_id(EngineId), - check_mask(Domain, Mask), + NMask = check_mask(Domain, Mask), TDomain = snmp_conf:mk_tdomain(Domain), - TAddress = snmp_conf:mk_taddress(Domain, Address), - TMask = snmp_conf:mk_taddress(Domain, Mask), + TAddress = snmp_conf:mk_taddress(Domain, NAddress), + TMask = snmp_conf:mk_taddress(Domain, NMask), snmp_conf:check_packet_size(MMS), ?vtrace("check target address done",[]), Addr = {Name, TDomain, TAddress, Timeout, @@ -286,13 +286,21 @@ check_engine_id(discovery) -> check_engine_id(EngineId) -> snmp_conf:check_string(EngineId). +check_address(Domain, Address) -> + case snmp_conf:check_address(Domain, Address) of + ok -> + Address; + {ok, FixedAddress} -> + FixedAddress + end. + check_mask(_Domain, []) -> - ok; + []; check_mask(Domain, Mask) -> - try snmp_conf:check_address(Domain, Mask) + try check_address(Domain, Mask) catch {error, {invalid_address, Info}} -> - {error, {invalid_mask, Info}} + error({invalid_mask, Info}) end. %%----------------------------------------------------------------- diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index a405987c8a..f055f89880 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -140,7 +140,7 @@ verify_agent_conf(X, _) -> error({bad_agent_config, X}). check_agent_conf_entry(Entry, State) -> - {ok, _NewState} = snmp_framework_mib:check_agent(Entry, State). + snmp_framework_mib:check_agent(Entry, State). write_agent_conf(Fd, "", Conf) -> write_agent_conf(Fd, Conf); diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index 9bb4556788..2db98d9fc2 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -186,12 +186,12 @@ discarded_pdu(Variable) -> inc(Variable). v1_v2c_proc( Vsn, NoteStore, Community, Domain, Address, LocalEngineID, Data, HS, Log, Packet) -> - try snmp_conf:check_domain(Domain) of - ok -> - try snmp_conf:check_address(Domain, Address) of - ok -> + try snmp_conf:mk_tdomain(Domain) of + TDomain -> + try snmp_conf:mk_taddress(Domain, Address) of + TAddress -> v1_v2c_proc_dec( - Vsn, NoteStore, Community, Domain, Address, + Vsn, NoteStore, Community, TDomain, TAddress, LocalEngineID, Data, HS, Log, Packet) catch _ -> @@ -203,10 +203,8 @@ v1_v2c_proc( end. v1_v2c_proc_dec( - Vsn, NoteStore, Community, Domain, Address, + Vsn, NoteStore, Community, TDomain, TAddress, LocalEngineID, Data, HS, Log, Packet) -> - TDomain = snmp_conf:mk_tdomain(Domain), - TAddress = snmp_conf:mk_taddress(Domain, Address), AgentMS = get_engine_max_message_size(LocalEngineID), MgrMS = snmp_community_mib:get_target_addr_ext_mms(TDomain, TAddress), PduMS = case MgrMS of @@ -233,7 +231,7 @@ v1_v2c_proc_dec( case Pdu#pdu.type of 'set-request' -> %% Check if this message has already been processed - Key = {agent, {Domain, Address}, ReqId}, + Key = {agent, {TDomain, TAddress}, ReqId}, case snmp_note_store:get_note(NoteStore, Key) of undefined -> %% Set the processed note _after_ pdu processing. diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 43d394e9d9..af2262d988 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -335,27 +335,17 @@ register_agent(UserId, TargetName, Config0) %% is not present %% 3) Check that there are no invalid or erroneous configs %% 4) Check that the manager is capable of using the selected version - case verify_agent_config(Config0) of - {ok, Config} -> - call({register_agent, UserId, TargetName, Config}); - Error -> - Error - end. - - -verify_agent_config(Conf0) -> try - begin - verify_mandatory(Conf0, [engine_id, address, reg_type]), - verify_invalid(Conf0, [user_id]), - Conf = verify_agent_config3(Conf0), - Vsns = versions(), - Vsn = which_version(Conf), - verify_version(Vsn, Vsns), - {ok, Conf} - end + verify_mandatory(Config0, [engine_id, reg_type]), + verify_oneof(Config0, [address, taddress]), + verify_invalid(Config0, [user_id]), + Config = verify_agent(Config0), + Vsns = versions(), + Vsn = which_version(Config), + verify_version(Vsn, Vsns), + call({register_agent, UserId, TargetName, Config}) catch - throw:Error -> + Error -> Error end. @@ -381,37 +371,9 @@ verify_version(Vsn, Vsns) -> ok; false -> Reason = {version_not_supported_by_manager, Vsn, Vsns}, - throw({error, Reason}) - end. - -verify_agent_config3(Conf0) -> - %% Fix (transport) address and domain - {TDomain, Conf1} = - case lists:keysearch(tdomain, 1, Conf0) of - {value, {tdomain, Dom}} -> - {Dom, Conf0}; - false -> - Dom = default_transport_domain(), - {Dom, [{tdomain, Dom} | Conf0]} - end, - Conf2 = case lists:keysearch(address, 1, Conf1) of - {value, {address, Address}} -> - lists:keyreplace(address, 1, Conf1, - {address, {TDomain, Address}}); - false -> - %% This is a mandatory config option, - %% a later test will detect this - Conf1 - end, - case verify_agent2(Conf2) of - {ok, Conf} -> - Conf; - {error, _} = ERROR -> - throw(ERROR) + error(Reason) end. -verify_agent_config2(Conf) -> - verify_agent2(Conf). unregister_agent(UserId, TargetName) -> @@ -444,7 +406,7 @@ agent_info(TargetName, Item) -> [] -> {error, not_found} end. - + agent_info(Addr0, Port, Item) -> Addr = normalize_address(Addr0), do_agent_info(Addr, Port, Item). @@ -474,38 +436,6 @@ which_agents(UserId) -> [TargetName || [TargetName] <- Agents]. -verify_agent_info(TargetName, Info0) -> - try - begin - verify_invalid(Info0, [user_id]), - %% Check if address is part of the list and - %% if so update it with the domain info. - Info = - case lists:keysearch(address, 1, Info0) of - {value, {address, Addr}} -> - %% If domain is part of the info, then use it. - %% If not, lookup what is already stored for - %% this agent and use that. - Domain = - case lists:keysearch(tdomain, 1, Info0) of - {value, {tdomain, Dom}} -> - Dom; - false -> - {ok, Dom} = - agent_info(TargetName, tdomain), - Dom - end, - Addr2 = {Domain, Addr}, - lists:keyreplace(address, 1, Info0, {address, Addr2}); - false -> - Info0 - end, - verify_agent2(Info) - end - catch - throw:Error -> - Error - end. update_agent_info(UserId, TargetName, Info) -> call({update_agent_info, UserId, TargetName, Info}). @@ -1666,8 +1596,8 @@ init_agent_default(Item, Val) when Item =/= user_id -> read_agents_config_file(Dir) -> - Check = fun(C, S) -> {check_agent_config2(C), S} end, - case read_file(Dir, "agents.conf", Check, []) of + Verify = fun check_agent_config2/1, + case read_file(Dir, "agents.conf", Verify, []) of {ok, Conf} -> Conf; Error -> @@ -1691,119 +1621,44 @@ check_agent_config2(Agent) -> end. %% For backward compatibility -check_agent_config({UserId, - TargetName, - Community, - Ip, Port, - EngineId, - Timeout, MaxMessageSize, - Version, SecModel, SecName, SecLevel}) -> +check_agent_config( + {UserId, TargetName, Community, Ip, Port, + EngineId, Timeout, MaxMessageSize, + Version, SecModel, SecName, SecLevel}) -> TDomain = default_transport_domain(), - check_agent_config({UserId, - TargetName, - Community, - TDomain, Ip, Port, - EngineId, - Timeout, MaxMessageSize, - Version, SecModel, SecName, SecLevel}); - -check_agent_config({UserId, - TargetName, - Community, - TDomain, Ip, Port, - EngineId, - Timeout, MaxMessageSize, - Version, SecModel, SecName, SecLevel}) -> - ?vtrace("check_agent_config -> entry with" - "~n UserId: ~p" - "~n TargetName: ~p" - "~n Community: ~p" - "~n TDomain: ~p" - "~n Ip: ~p" - "~n Port: ~p" - "~n EngineId: ~p" - "~n Timeout: ~p" - "~n MaxMessageSize: ~p" - "~n Version: ~p" - "~n SecModel: ~p" - "~n SecName: ~p" - "~n SecLevel: ~p", - [UserId, TargetName, Community, - TDomain, Ip, Port, - EngineId, Timeout, MaxMessageSize, - Version, SecModel, SecName, SecLevel]), - Addr = normalize_address(TDomain, Ip), - ?vtrace("check_agent_config -> Addr: ~p", [Addr]), - Agent = {UserId, - TargetName, - Community, - TDomain, Addr, Port, - EngineId, - Timeout, MaxMessageSize, - Version, SecModel, SecName, SecLevel}, - {ok, verify_agent(Agent)}; + check_agent_config( + UserId, TargetName, Community, TDomain, {Ip, Port}, + EngineId, Timeout, MaxMessageSize, + Version, SecModel, SecName, SecLevel); +check_agent_config( + {UserId, TargetName, Community, TDomain, Ip, Port, + EngineId, Timeout, MaxMessageSize, + Version, SecModel, SecName, SecLevel}) -> + check_agent_config( + UserId, TargetName, Community, TDomain, {Ip, Port}, + EngineId, Timeout, MaxMessageSize, + Version, SecModel, SecName, SecLevel); check_agent_config(Agent) -> error({bad_agent_config, Agent}). - -init_agents_config([]) -> - ok; -init_agents_config([Agent|Agents]) -> - init_agent_config(Agent), - init_agents_config(Agents). - -init_agent_config({_UserId, ?DEFAULT_TARGETNAME = TargetName, _Config}) -> - throw({error, {invalid_target_name, TargetName}}); -init_agent_config({UserId, TargetName, Config}) -> - case handle_register_agent(UserId, TargetName, Config) of - ok -> - ok; - Error -> - throw(Error) - end. - - -%% For backward compatibility -verify_agent({UserId, - TargetName, - Comm, - Ip, Port, - EngineId, - Timeout, MMS, - Version, SecModel, SecName, SecLevel}) -> - TDomain = default_transport_domain(), - verify_agent({UserId, - TargetName, - Comm, - TDomain, Ip, Port, - EngineId, - Timeout, MMS, - Version, SecModel, SecName, SecLevel}); - -verify_agent({UserId, - TargetName, - Comm, - TDomain, Ip, Port, - EngineId, - Timeout, MMS, - Version, SecModel, SecName, SecLevel}) -> - ?vdebug("verify_agent -> entry with" +check_agent_config( + UserId, TargetName, Comm, TDomain, TAddress, + EngineId, Timeout, MMS, + Version, SecModel, SecName, SecLevel) -> + ?vdebug("check_agent_config -> entry with" "~n UserId: ~p" "~n TargetName: ~p", [UserId, TargetName]), snmp_conf:check_string(TargetName, {gt, 0}), - snmp_conf:check_integer(Port, {gt, 0}), %% Note that the order of Conf *is* important. %% Some properties may depend on others, so that %% in order to verify one property, another must %% be already verified (and present). An example - %% of this is the property 'address', for which + %% of this is the property 'taddress', for which %% the property tdomain is needed. - Conf0 = + Conf = [{reg_type, target_name}, {tdomain, TDomain}, - %% This should be taddress, but what the*... - {address, {TDomain, Ip}}, - {port, Port}, + {taddress, TAddress}, {community, Comm}, {engine_id, EngineId}, {timeout, Timeout}, @@ -1813,32 +1668,148 @@ verify_agent({UserId, {sec_name, SecName}, {sec_level, SecLevel} ], - case verify_agent2(Conf0) of - {ok, Conf} -> - {UserId, TargetName, Conf, Version}; - Err -> - throw(Err) + {ok, {UserId, TargetName, verify_agent(Conf), Version}}. + + + +init_agents_config([]) -> + ok; +init_agents_config([Agent|Agents]) -> + init_agent_config(Agent), + init_agents_config(Agents). + +init_agent_config({_UserId, ?DEFAULT_TARGETNAME = TargetName, _Config}) -> + error({invalid_target_name, TargetName}); +init_agent_config({UserId, TargetName, Config}) -> + case handle_register_agent(UserId, TargetName, Config) of + ok -> + ok; + Error -> + throw(Error) end. -verify_agent2(Conf) -> - verify_agent2(Conf, []). -verify_agent2([], VerifiedConf) -> - {ok, VerifiedConf}; -verify_agent2([{Item, Val0}|Items], VerifiedConf) -> - case verify_val(Item, Val0) of - {ok, Val} -> - verify_agent2(Items, [{Item, Val} | VerifiedConf]); - Err -> - Err + +%% Sort tdomain first +order_agent({Item, _}, {Item, _}) -> + true; %% Less than or equal +order_agent(_, {tdomain, _}) -> + false; %% Greater than +order_agent(_, _) -> + true. %% Less than or equal + +verify_agent(Conf) -> + verify_agent(lists:sort(fun order_agent/2, Conf), []). + +verify_agent([], VerifiedConf) -> + list:reverse(VerifiedConf); +verify_agent([{_Item, _} = Entry|Conf], VerifiedConf) -> +%% verify_invalid(VerifiedConf, [_Item]), % Check for duplicate + verify_agent(Conf, VerifiedConf, Entry); +verify_agent([Bad|_], _VerifiedConf) -> + error({bad_agent_config, Bad}). + +verify_agent(Conf, VerifiedConf, {taddress = Item, TAddress} = Entry) -> + verify_invalid(VerifiedConf, [address,port]), + {TDomain, VC} = + case lists:keysearch(tdomain, 1, VerifiedConf) of + {value, {tdomain,TD}} -> + {TD, VerifiedConf}; + _ -> + %% Insert tdomain since it is missing + TD = default_transport_domain(), + {TD, [{tdomain, TD}|VerifiedConf]} + end, + case snmp_conf:check_address(TDomain, TAddress) of + ok -> + verify_agent(Conf, [Entry|VC]); + {ok, NAddress} -> + verify_agent(Conf, [{Item, NAddress}|VC]) + end; +verify_agent(Conf, VerifiedConf, {address = Item, Address} = Entry) -> + verify_invalid(VerifiedConf, [taddress]), + {TDomain, VC} = + case lists:keysearch(tdomain, 1, VerifiedConf) of + {value, {tdomain,TD}} -> + {TD, VerifiedConf}; + _ -> + %% Insert tdomain since it is missing + TD = default_transport_domain(), + {TD, [{tdomain, TD}|VerifiedConf]} + end, + FakePort = make_ref(), + case snmp_conf:check_address(TDomain, Address, FakePort) of + ok -> + verify_agent(Conf, [Entry|VC]); + {ok, {NAddress,FakePort}} -> + verify_agent(Conf, [{Item, NAddress}|VC]); + {ok, _} -> + error({invalid_address, {TDomain, Address}}) + end; +verify_agent(Conf, VerifiedConf, {port, Port} = Entry) -> + verify_invalid(VerifiedConf, [taddress]), + ok = snmp_conf:check_address(snmpUDPDomain, {{0, 0, 0, 0}, Port}), + verify_agent(Conf, [Entry|VerifiedConf]); +verify_agent(Conf, VerifiedConf, {Item, Val} = Entry) -> + case verify_agent_entry(Item, Val) of + ok -> + verify_agent(Conf, [Entry|VerifiedConf]); + {ok, NewVal} -> + verify_agent(Conf, [{Item, NewVal}|VerifiedConf]) + end. + +verify_agent_entry(user_id, _UserId) -> + ok; +verify_agent_entry(reg_type, RegType) -> + if + RegType =:= addr_port; + RegType =:= target_name -> + ok; + true -> + error({bad_reg_type, RegType}) + end; +verify_agent_entry(tdomain, TDomain) -> + snmp_conf:check_domain(TDomain); +verify_agent_entry(community, Comm) -> + snmp_conf:check_string(Comm); +verify_agent_entry(engine_id, EngineId) -> + case EngineId of + discovery -> + ok; + _ -> + snmp_conf:check_string(EngineId) + end; +verify_agent_entry(timeout, Timeout) -> + snmp_conf:check_timer(Timeout); +verify_agent_entry(max_message_size, MMS) -> + snmp_conf:check_packet_size(MMS); +verify_agent_entry(version, V) -> + if + V =:= v1; + V =:= v2; + V =:= v3 -> + ok; + true -> + error({bad_version, V}) end; -verify_agent2([Bad|_], _VerifiedConf) -> - {error, {bad_agent_config, Bad}}. +verify_agent_entry(sec_model, Model) -> + snmp_conf:check_sec_model(Model); +verify_agent_entry(sec_name, Name) -> + try snmp_conf:check_string(Name) + catch + _ -> + error({bad_sec_name, Name}) + end; +verify_agent_entry(sec_level, Level) -> + snmp_conf:check_sec_level(Level); +verify_agent_entry(Item, _) -> + error({unknown_item, Item}). + read_users_config_file(Dir) -> - Check = fun(C, S) -> {check_user_config(C), S} end, - case read_file(Dir, "users.conf", Check, []) of + Verify = fun check_user_config/1, + case read_file(Dir, "users.conf", Verify, []) of {ok, Conf} -> Conf; Error -> @@ -1864,15 +1835,12 @@ check_user_config({Id, Mod, Data, DefaultAgentConfig} = _User) case (catch verify_user_behaviour(Mod)) of ok -> ?vtrace("check_user_config -> user behaviour verified", []), - case verify_user_agent_config(DefaultAgentConfig) of - {ok, DefAgentConf} -> - ?vtrace("check_user_config -> " - "user agent (default) config verified", []), - User2 = {Id, Mod, Data, DefAgentConf}, - {ok, User2}; - {error, Reason} -> - error({bad_default_agent_config, Reason}) - end; + DefAgentConf = + verify_default_agent_config(DefaultAgentConfig), + ?vtrace("check_user_config -> " + "user agent (default) config verified", []), + User2 = {Id, Mod, Data, DefAgentConf}, + {ok, User2}; Error -> throw(Error) end; @@ -1904,7 +1872,7 @@ init_user_config(User) -> error_msg("user config check failed: " "~n~w~n~w", [User, Reason]) end. - + verify_user({Id, UserMod, UserData}) -> verify_user({Id, UserMod, UserData, []}); verify_user({Id, UserMod, UserData, DefaultAgentConfig}) @@ -1917,15 +1885,19 @@ verify_user({Id, UserMod, UserData, DefaultAgentConfig}) [Id, UserMod, UserData, DefaultAgentConfig]), case (catch verify_user_behaviour(UserMod)) of ok -> - case verify_user_agent_config(DefaultAgentConfig) of - {ok, DefAgentConf} -> - Config = default_agent_config(DefAgentConf), - {ok, #user{id = Id, - mod = UserMod, - data = UserData, - default_agent_config = Config}}; - {error, Reason} -> - error({bad_default_agent_config, Reason}) + try + Config = + default_agent_config( + verify_default_agent_config(DefaultAgentConfig)), + {ok, #user{id = Id, + mod = UserMod, + data = UserData, + default_agent_config = Config}} + catch + Error -> + ?vdebug("verify_user default_agent_config -> throw" + "~n Error: ~p", [Error]), + error({bad_default_agent_config, Error}) end; Error -> throw(Error) @@ -1936,22 +1908,22 @@ verify_user({Id, _UserMod, _UserData, DefaultAgentConfig}) verify_user({Id, _, _, _}) -> {error, {bad_user_id, Id}}. -verify_user_agent_config(Conf) -> +verify_default_agent_config(Conf) -> try - begin - verify_invalid(Conf, [user_id, engine_id, address]), - verify_agent_config2(Conf) - end + verify_invalid( + Conf, + [user_id, engine_id, address, tdomain, taddress]), + verify_agent(Conf) catch - throw:Error -> - ?vdebug("verify_user_agent_config -> throw" + Error -> + ?vdebug("verify_default_agent_config -> throw" "~n Error: ~p", [Error]), - Error + error({bad_default_agent_config, Error}) end. read_usm_config_file(Dir) -> - Check = fun(C, S) -> {check_usm_user_config(C), S} end, - case read_file(Dir, "usm.conf", Check, []) of + Verify = fun check_usm_user_config/1, + case read_file(Dir, "usm.conf", Verify, []) of {ok, Conf} -> Conf; Error -> @@ -2139,8 +2111,8 @@ is_crypto_supported(Func) -> read_manager_config_file(Dir) -> - Check = fun(Conf, State) -> {check_manager_config(Conf), State} end, - case read_file(Dir, "manager.conf", Check) of + Verify = fun check_manager_config/1, + case read_file(Dir, "manager.conf", Verify) of {ok, Conf} -> ?d("read_manager_config_file -> ok: " "~n Conf: ~p", [Conf]), @@ -2218,44 +2190,80 @@ ensure_manager_config(Confs, [{Key,_} = DefKeyVal|Defs]) -> -read_file(Dir, FileName, Check, Default) -> +read_file(Dir, FileName, Verify, Default) -> File = filename:join(Dir, FileName), case file:read_file_info(File) of {ok, _} -> - case (catch do_read(File, Check)) of - {ok, Conf} -> - {ok, Conf}; - Error -> - ?vtrace("read_file -> read failed:" - "~n Error: ~p", [Error]), - Error - end; - {error, Reason} -> + read_file(File, Verify); + {error, Reason} -> ?vlog("failed reading config from ~s: ~p", [FileName, Reason]), {ok, Default} end. -read_file(Dir, FileName, Check) -> +read_file(Dir, FileName, Verify) -> File = filename:join(Dir, FileName), case file:read_file_info(File) of {ok, _} -> - case (catch do_read(File, Check)) of - {ok, Conf} -> - ?vtrace("read_file -> read ok" - "~n Conf: ~p", [Conf]), - {ok, Conf}; - Error -> - ?vtrace("read_file -> read failed:" - "~n Error: ~p", [Error]), - Error - end; + read_file(File, Verify); {error, Reason} -> error_msg("failed reading config from ~s: ~p", [FileName, Reason]), {error, {failed_reading, FileName, Reason}} end. -do_read(File, Check) -> - {ok, snmp_conf:read(File, Check)}. +read_file(File, Verify) -> + Check = fun (Config, State) -> {Verify(Config), State} end, + try snmp_conf:read(File, Check) of + Conf -> + ?vtrace("read_file -> read ok" + "~n Conf: ~p", [Conf]), + {ok, Conf} + catch + Error -> + ?vtrace("read_file -> read failed:" + "~n Error: ~p", [Error]), + Error + end. + +%% XXX remove + +%% read_file(Dir, FileName, Check, Default) -> +%% File = filename:join(Dir, FileName), +%% case file:read_file_info(File) of +%% {ok, _} -> +%% case (catch do_read(File, Check)) of +%% {ok, Conf} -> +%% {ok, Conf}; +%% Error -> +%% ?vtrace("read_file -> read failed:" +%% "~n Error: ~p", [Error]), +%% Error +%% end; +%% {error, Reason} -> +%% ?vlog("failed reading config from ~s: ~p", [FileName, Reason]), +%% {ok, Default} +%% end. + +%% read_file(Dir, FileName, Check) -> +%% File = filename:join(Dir, FileName), +%% case file:read_file_info(File) of +%% {ok, _} -> +%% case (catch do_read(File, Check)) of +%% {ok, Conf} -> +%% ?vtrace("read_file -> read ok" +%% "~n Conf: ~p", [Conf]), +%% {ok, Conf}; +%% Error -> +%% ?vtrace("read_file -> read failed:" +%% "~n Error: ~p", [Error]), +%% Error +%% end; +%% {error, Reason} -> +%% error_msg("failed reading config from ~s: ~p", [FileName, Reason]), +%% {error, {failed_reading, FileName, Reason}} +%% end. + +%% do_read(File, Check) -> +%% {ok, snmp_conf:read(File, Check)}. %%-------------------------------------------------------------------- @@ -2795,13 +2803,24 @@ handle_update_agent_info(TargetName, Info0) -> "~n TargetName: ~p" "~n Info0: ~p", [TargetName, Info0]), %% Verify info - try verify_agent_info(TargetName, Info0) of - {ok, Info} -> - do_update_agent_info(TargetName, Info); - Error -> - Error + try + verify_invalid(Info0, [user_id]), + %% If domain is part of the info, then use it. + %% If not, lookup what is already stored for + %% this agent and use that. + Info = + case lists:keysearch(tdomain, 1, Info0) of + {value, {tdomain, _}} -> + Info0; + false -> + {ok, TDomain} = + agent_info(TargetName, tdomain), + [{tdomain, TDomain}|Info0] + end, + verify_agent(Info), + do_update_agent_info(TargetName, Info) catch - throw:Error -> + Error -> Error; T:E -> {error, {failed_info_verification, Info0, T, E}} @@ -2997,7 +3016,7 @@ verify_mandatory(Conf, [Mand|Mands]) -> true -> verify_mandatory(Conf, Mands); false -> - throw({error, {missing_mandatory_config, Mand}}) + error({missing_mandatory_config, Mand}) end. verify_invalid(_, []) -> @@ -3007,99 +3026,22 @@ verify_invalid(Conf, [Inv|Invs]) -> false -> verify_invalid(Conf, Invs); true -> - throw({error, {illegal_config, Inv}}) + error({illegal_config, Inv}) end. - -verify_val(user_id, UserId) -> - {ok, UserId}; -verify_val(reg_type, RegType) - when (RegType =:= addr_port) orelse (RegType =:= target_name) -> - {ok, RegType}; -verify_val(tdomain = Item, snmpUDPDomain = _Domain) -> - verify_val(Item, transportDomainUdpIpv4); -verify_val(tdomain, Domain) -> - case lists:member(Domain, ?SUPPORTED_DOMAINS) of +verify_oneof(Conf, [Mand|Mands]) -> + case lists:keymember(Mand, 1, Conf) of true -> - {ok, Domain}; + ok; false -> - case lists:member(Domain, snmp_conf:all_domains()) of - true -> - error({unsupported_domain, Domain}); - false -> - error({unknown_domain, Domain}) + case Mands of + [] -> + error({missing_mandatory_config, Mand}); + _ -> + verify_oneof(Conf, Mands) end - end; -verify_val(address, {Domain, Addr0}) -> - case normalize_address(Domain, Addr0) of - {_A1, _A2, _A3, _A4} = Addr -> - {ok, Addr}; - {_A1, _A2, _A3, _A4, _A5, _A6, _A7, _A8} = Addr -> - {ok, Addr}; - _ when is_list(Addr0) -> - case (catch snmp_conf:check_ip(Addr0)) of - ok -> - {ok, list_to_tuple(Addr0)}; - Err -> - Err - end; - _ -> - error({bad_address, Addr0}) - end; -verify_val(address, BadAddress) -> - error({bad_address, BadAddress}); -verify_val(port, Port) -> - case (catch snmp_conf:check_integer(Port, {gt, 0})) of - ok -> - {ok, Port}; - Err -> - Err - end; -verify_val(community, Comm) -> - case (catch snmp_conf:check_string(Comm)) of - ok -> - {ok, Comm}; - Err -> - Err - end; -verify_val(engine_id, discovery = EngineId) -> - {ok, EngineId}; -verify_val(engine_id, EngineId) -> - case (catch snmp_conf:check_string(EngineId)) of - ok -> - {ok, EngineId}; - Err -> - Err - end; -verify_val(timeout, Timeout) -> - (catch snmp_conf:check_timer(Timeout)); -verify_val(max_message_size, MMS) -> - case (catch snmp_conf:check_packet_size(MMS)) of - ok -> - {ok, MMS}; - Err -> - Err - end; -verify_val(version, V) - when (V =:= v1) orelse (V =:= v2) orelse (V =:= v3) -> - {ok, V}; -verify_val(version, BadVersion) -> - error({bad_version, BadVersion}); -verify_val(sec_model, Model) -> - (catch snmp_conf:check_sec_model(Model)); -verify_val(sec_name, Name) when is_list(Name) -> - case (catch snmp_conf:check_string(Name)) of - ok -> - {ok, Name}; - Err -> - Err - end; -verify_val(sec_name, BadName) -> - error({bad_sec_name, BadName}); -verify_val(sec_level, Level) -> - (catch snmp_conf:check_sec_level(Level)); -verify_val(Item, _) -> - {error, {unknown_item, Item}}. + end. + %%%------------------------------------------------------------------- diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl index 953c94ab54..fe5ed6b755 100644 --- a/lib/snmp/src/manager/snmpm_mpd.erl +++ b/lib/snmp/src/manager/snmpm_mpd.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2012. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -93,7 +93,9 @@ reset(#state{v3 = V3}) -> %% section 4.2.1 in rfc2272) %%----------------------------------------------------------------- process_msg(Msg, Domain, Addr, Port, State, NoteStore, Logger) -> + process_msg(Msg, Domain, {Addr, Port}, State, NoteStore, Logger). +process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> inc(snmpInPkts), case (catch snmp_pdus:dec_message_only(binary_to_list(Msg))) of @@ -102,17 +104,17 @@ process_msg(Msg, Domain, Addr, Port, State, NoteStore, Logger) -> #message{version = 'version-1', vsn_hdr = Community, data = Data} when State#state.v1 =:= true -> HS = ?empty_msg_size + length(Community), - process_v1_v2c_msg('version-1', NoteStore, Msg, - Domain, Addr, Port, - Community, Data, HS, Logger); + process_v1_v2c_msg( + 'version-1', NoteStore, Msg, Domain, Address, + Community, Data, HS, Logger); %% Version 2 #message{version = 'version-2', vsn_hdr = Community, data = Data} when State#state.v2c =:= true -> HS = ?empty_msg_size + length(Community), - process_v1_v2c_msg('version-2', NoteStore, Msg, - Domain, Addr, Port, - Community, Data, HS, Logger); + process_v1_v2c_msg( + 'version-2', NoteStore, Msg, Domain, Address, + Community, Data, HS, Logger); %% Version 3 #message{version = 'version-3', vsn_hdr = H, data = Data} @@ -122,7 +124,7 @@ process_msg(Msg, Domain, Addr, Port, State, NoteStore, Logger) -> "~n msgFlags: ~p" "~n msgSecModel: ~p", [H#v3_hdr.msgID,H#v3_hdr.msgFlags,H#v3_hdr.msgSecurityModel]), - process_v3_msg(NoteStore, Msg, H, Data, Addr, Port, Logger); + process_v3_msg(NoteStore, Msg, H, Data, Address, Logger); %% Crap {'EXIT', {bad_version, Vsn}} -> @@ -148,32 +150,27 @@ process_msg(Msg, Domain, Addr, Port, State, NoteStore, Logger) -> %%----------------------------------------------------------------- %% Handles a Community based message (v1 or v2c). %%----------------------------------------------------------------- -process_v1_v2c_msg(Vsn, _NoteStore, Msg, Domain, - Addr, Port, - Community, Data, HS, Log) -> +process_v1_v2c_msg( + Vsn, _NoteStore, Msg, Domain, Address, Community, Data, HS, Log) -> ?vdebug("process_v1_v2c_msg -> entry with" "~n Vsn: ~p" "~n Domain: ~p" - "~n Addr: ~p" - "~n Port: ~p" + "~n Address: ~p" "~n Community: ~p" - "~n HS: ~p", [Vsn, Domain, Addr, Port, Community, HS]), - + "~n HS: ~p", [Vsn, Domain, Address, Community, HS]), + {TDomain, TAddress} = try - begin - TD = snmp_conf:mk_tdomain(Domain), - TA = snmp_conf:mk_taddress(Domain, Addr, Port), - {TD, TA} - end + {snmp_conf:mk_tdomain(Domain), + snmp_conf:mk_taddress(Domain, Address)} catch throw:{error, TReason} -> throw({discarded, {badarg, Domain, TReason}}) end, Max = get_max_message_size(), - AgentMax = get_agent_max_message_size(Addr, Port), + AgentMax = get_agent_max_message_size(Address), PduMS = pdu_ms(Max, AgentMax, HS), ?vtrace("process_v1_v2c_msg -> PduMS: ~p", [PduMS]), @@ -213,13 +210,12 @@ sec_model('version-2') -> ?SEC_V2C. %% Handles a SNMPv3 Message, following the procedures in rfc2272, %% section 4.2 and 7.2 %%----------------------------------------------------------------- -process_v3_msg(NoteStore, Msg, Hdr, Data, Addr, Port, Log) -> +process_v3_msg(NoteStore, Msg, Hdr, Data, Address, Log) -> + ?vdebug( + "process_v3_msg -> entry with~n" + " Hdr: ~p~n" + " Address: ~p", [Hdr, Address]), - ?vdebug("process_v3_msg -> entry with" - "~n Hdr: ~p" - "~n Addr: ~p" - "~n Port: ~p", [Hdr, Addr, Port]), - %% 7.2.3 #v3_hdr{msgID = MsgID, msgMaxSize = MMS, @@ -352,8 +348,8 @@ process_v3_msg(NoteStore, Msg, Hdr, Data, Addr, Port, Log) -> %% 4.2.2.1.1 - we don't handle proxys yet => we only %% handle CtxEngineID to ourselves %% Check that we actually know of an agent with this - %% CtxEngineID and Addr/Port - case is_known_engine_id(CtxEngineID, Addr, Port) of + %% CtxEngineID and Address + case is_known_engine_id(CtxEngineID, Address) of true -> ?vtrace("and the agent EngineID (~p) " "is know to us", [CtxEngineID]), @@ -866,7 +862,7 @@ get_max_message_size() -> end. %% The the MMS of the agent -get_agent_max_message_size(Addr, Port) -> +get_agent_max_message_size({Addr, Port}) -> case snmpm_config:get_agent_engine_max_message_size(Addr, Port) of {ok, MMS} -> MMS; @@ -874,6 +870,14 @@ get_agent_max_message_size(Addr, Port) -> ?vlog("unknown agent: ~w:~w", [Addr, Port]), get_max_message_size() end. +%% get_agent_max_message_size(Addr, Port) -> +%% case snmpm_config:get_agent_engine_max_message_size(Addr, Port) of +%% {ok, MMS} -> +%% MMS; +%% _Error -> +%% ?vlog("unknown agent: ~w:~w", [Addr, Port]), +%% get_max_message_size() +%% end. %% Get "our" (manager) engine id get_engine_id() -> @@ -888,9 +892,12 @@ get_engine_id() -> get_agent_engine_id(Name) -> snmpm_config:get_agent_engine_id(Name). -is_known_engine_id(EngineID, Addr, Port) -> +is_known_engine_id(EngineID, {Addr, Port}) -> snmpm_config:is_known_engine_id(EngineID, Addr, Port). +%% is_known_engine_id(EngineID, Addr, Port) -> +%% snmpm_config:is_known_engine_id(EngineID, Addr, Port). + % get_agent_engine_id(Addr, Port) -> % case snmpm_config:get_agent_engine_id(Addr, Port) of % {ok, Id} -> diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index c52b4bb6fb..f85f1d3828 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -45,9 +45,9 @@ mk_tdomain/1, which_domain/1, check_ip/1, check_ip/2, - check_address/2, + check_address/2, check_address/3, check_taddress/2, - mk_taddress/2, mk_taddress/3, + mk_taddress/2, check_packet_size/1, @@ -146,38 +146,8 @@ read_files(Dir, [{FileName, Gen, Order, Check, Filter}|Files], Res) Gen(Dir, R) end, read_files(Dir, Files, [Filter(Confs)|Res]). -%% %% -%% %% XXX remove -%% %% -%% %% read_files(Dir, Files) -> Configs -%% %% Dir - string() - Full path to the config dir. -%% %% Files - [{Gen, Filter, Check, FileName}] -%% %% Gen - function/2 - In case of failure when reading the config file, -%% %% this function is called to either generate a -%% %% default file or issue the error. -%% %% Filter - function/1 - Filters all the config entries read from the file -%% %% Check - function/1 - Check each entry as they are read from the file. -%% %% FileName - string() - Name of the config file. -%% %% Configs - [config_entry()] -%% %% config_entry() - term() -%% -%% read_files(Dir, [{Gen, Filter, Check, FileName}|Files], Res) -%% when is_function(Filter) andalso -%% is_function(Check) andalso -%% is_list(FileName) -> -%% ?vdebug("read_files -> entry with" -%% "~n FileName: ~p", [FileName]), -%% File = filename:join(Dir, FileName), -%% case file:read_file_info(File) of -%% {ok, _} -> -%% Confs = read(File, Check), -%% read_files(Dir, Files, [Filter(Confs)|Res]); -%% {error, R} -> -%% ?vlog("failed reading file info for ~s: " -%% "~n ~p", [FileName, R]), -%% Gen(Dir, R), -%% read_files(Dir, Files, [Filter([])|Res]) -%% end. + + no_gen(_Dir, _R) -> []. no_order(_, _) -> true. @@ -185,6 +155,9 @@ no_filter(X) -> X. +read(File, Check) -> + read(File, fun no_order/2, Check). + %% Ret. Res | exit(Reason) read(File, Order, Check) when is_function(Order), is_function(Check) -> ?vdebug("read -> entry with~n" @@ -240,80 +213,29 @@ read_check(File, Check, [{StartLine, Row, EndLine}|Lines], State, Res) -> error({failed_check, File, StartLine, EndLine, Error}) end. - - -%% XXX remove - -%% Ret. Res | exit(Reason) -read(File, Check) when is_function(Check) -> - ?vdebug("read -> entry with" - "~n File: ~p", [File]), - - Fd = open_file(File), - - case loop(Fd, [], Check, 1, File) of - {error, Reason} -> - file:close(Fd), - error(Reason); - {ok, Res} -> - file:close(Fd), - Res - end. - open_file(File) -> case file:open(File, [read]) of - {ok, Fd} -> - Fd; - {error, Reason} -> - error({failed_open, File, Reason}) - end. - -loop(Fd, Res, Check, StartLine, File) -> - case do_read(Fd, "", StartLine) of - {ok, Row, EndLine} -> - ?vtrace("loop -> " - "~n Row: ~p" - "~n EndLine: ~p", [Row, EndLine]), - case (catch Check(Row)) of - ok -> - ?vtrace("loop -> ok", []), - loop(Fd, [Row | Res], Check, EndLine, File); - {ok, NewRow} -> - ?vtrace("loop -> ok: " - "~n NewRow: ~p", [NewRow]), - loop(Fd, [NewRow | Res], Check, EndLine, File); - {error, Reason} -> - ?vtrace("loop -> check error: " - "~n Reason: ~p", [Reason]), - {error, {failed_check, File, StartLine, EndLine, Reason}}; - Error -> - ?vtrace("loop -> check failure: " - "~n Error: ~p", [Error]), - {error, {failed_check, File, StartLine, EndLine, Error}} - end; - {error, Error, EndLine} -> - ?vtrace("loop -> read failure: " - "~n Error: ~p", [Error]), - {error, {failed_reading, File, StartLine, EndLine, Error}}; - {eof, _EndLine} -> - {ok, Res} + {ok, Fd} -> + Fd; + {error, Reason} -> + error({failed_open, File, Reason}) end. - do_read(Io, Prompt, StartLine) -> case io:request(Io, {get_until,Prompt,erl_scan,tokens,[StartLine]}) of - {ok, Toks, EndLine} -> - case erl_parse:parse_term(Toks) of - {ok, Term} -> - {ok, Term, EndLine}; - {error, {Line, erl_parse, Error}} -> - {error, {parse_error, Error}, Line} - end; - Other -> - Other + {ok, Toks, EndLine} -> + case erl_parse:parse_term(Toks) of + {ok, Term} -> + {ok, Term, EndLine}; + {error, {Line, erl_parse, Error}} -> + {error, {parse_error, Error}, Line} + end; + Other -> + Other end. + %%----------------------------------------------------------------- @@ -657,34 +579,12 @@ check_domain(Domain) -> %% --------- %% The values of Domain, Ip and Port has both been checked at this -%% point, so we dont need to do that again. - -mk_taddress(snmpUDPDomain, Address) -> +%% point, so we dont need to do that again, but this function is +%% also used on incoming packets from net_if so a little +%% check that net_if does not supply bad arguments is in order. +%% +mk_taddress(snmpUDPDomain, Address) -> % Legacy mk_taddress(transportDomainUdpIpv4, Address); -mk_taddress(transportDomainUdpIpv4, {Ip, Port}) when is_list(Ip) -> - Ip ++ mk_bytes(Port); -mk_taddress(transportDomainUdpIpv4, {Ip, Port}) when is_tuple(Ip) -> - tuple_to_list(Ip) ++ mk_bytes(Port); -mk_taddress(transportDomainUdpIpv4, IpPort) when is_list(IpPort) -> - IpPort; % Should be length 6 -mk_taddress(transportDomainUdpIpv6, {Ip, Port}) when is_list(Ip) -> - Ip ++ mk_bytes(Port); -mk_taddress(transportDomainUdpIpv6, {Ip, Port}) when is_tuple(Ip) -> - tuple_to_list(Ip) ++ mk_bytes(Port); -mk_taddress(transportDomainUdpIpv6, IpPort) when is_list(IpPort) -> - case IpPort of - [A0,A1,A2,A3,A4,A5,A6,A7,P] -> - [A0,A1,A2,A3,A4,A5,A6,A7] ++ mk_bytes(P); - [A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,P0,P1] -> - [mk_word(A0, A1),mk_word(A2, A3), - mk_word(A4, A5),mk_word(A6, A7), - mk_word(A8, A9),mk_word(A10, A11), - mk_word(A12, A13),mk_word(A14, A15),P0,P1]; - _ -> - IpPort % Should already be 8 words and 2 bytes hence length 10 - end; -mk_taddress(Domain, Address) when is_atom(Domain) -> - erlang:error(badarg, [Domain,Address]); %% %% These are just for convenience mk_taddress(?snmpUDPDomain, Address) -> @@ -693,36 +593,96 @@ mk_taddress(?transportDomainUdpIpv4, Address) -> mk_taddress(transportDomainUdpIpv4, Address); mk_taddress(?transportDomainUdpIpv6, Address) -> mk_taddress(transportDomainUdpIpv6, Address); +%% +mk_taddress(transportDomainUdpIpv4 = Domain, Address) -> + case Address of + {Ip, Port} when tuple_size(Ip) =:= 4, is_integer(Port) -> + tuple_to_list(Ip) ++ mk_bytes(Port); + _ -> + erlang:error(badarg, [Domain,Address]) + end; +mk_taddress(transportDomainUdpIpv6 = Domain, Address) -> + case Address of + {Ip, Port} + when tuple_size(Ip) =:= 8, is_integer(Port) -> + tuple_to_list(Ip) ++ mk_bytes(Port); + _ -> + erlang:error(badarg, [Domain,Address]) + end; %% Bad domain mk_taddress(BadDomain, _) -> error({bad_domain, BadDomain}). -%% XXX remove +%% mk_taddress(snmpUDPDomain, Address) -> +%% mk_taddress(transportDomainUdpIpv4, Address); +%% %% mk_taddress(transportDomainUdpIpv4, {Ip, Port}) when is_list(Ip) -> +%% %% Ip ++ mk_bytes(Port); +%% mk_taddress(transportDomainUdpIpv4, {Ip, Port}) +%% when tuple_size(Ip) =:= 4 -> +%% tuple_to_list(Ip) ++ mk_bytes(Port); +%% %% mk_taddress(transportDomainUdpIpv4, IpPort) when is_list(IpPort) -> +%% %% IpPort; % Should be length 6 +%% %% mk_taddress(transportDomainUdpIpv6, {Ip, Port}) when is_list(Ip) -> +%% %% Ip ++ mk_bytes(Port); +%% mk_taddress(transportDomainUdpIpv6, {Ip, Port}) +%% when tuple_size(Ip) == 8 -> +%% tuple_to_list(Ip) ++ mk_bytes(Port); +%% %% mk_taddress(transportDomainUdpIpv6, IpPort) when is_list(IpPort) -> +%% %% case IpPort of +%% %% [A0,A1,A2,A3,A4,A5,A6,A7,P] -> +%% %% [A0,A1,A2,A3,A4,A5,A6,A7] ++ mk_bytes(P); +%% %% [A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,P0,P1] -> +%% %% [mk_word(A0, A1),mk_word(A2, A3), +%% %% mk_word(A4, A5),mk_word(A6, A7), +%% %% mk_word(A8, A9),mk_word(A10, A11), +%% %% mk_word(A12, A13),mk_word(A14, A15),P0,P1]; +%% %% _ -> +%% %% IpPort % Should already be 8 words and 2 bytes hence length 10 +%% %% end; +%% mk_taddress(Domain, []) -> %% Used for empty mask +%% []; +%% mk_taddress(Domain, Address) -> +%% erlang:error(badarg, [Domain,Address]); +%% %% +%% %% These are just for convenience +%% mk_taddress(?snmpUDPDomain, Address) -> +%% mk_taddress(snmpUDPDomain, Address); +%% mk_taddress(?transportDomainUdpIpv4, Address) -> +%% mk_taddress(transportDomainUdpIpv4, Address); +%% mk_taddress(?transportDomainUdpIpv6, Address) -> +%% mk_taddress(transportDomainUdpIpv6, Address); +%% %% Bad domain +%% mk_taddress(BadDomain, _) -> +%% error({bad_domain, BadDomain}). -mk_taddress(snmpUDPDomain, Ip, Port) -> - mk_taddress(transportDomainUdpIpv4, Ip, Port); -mk_taddress(transportDomainUdpIpv4, Ip, Port) when is_list(Ip) -> - Ip ++ [Port div 256, Port rem 256]; -mk_taddress(transportDomainUdpIpv4 = Domain, Ip, Port) when is_tuple(Ip) -> - mk_taddress(Domain, tuple_to_list(Ip), Port); -mk_taddress(transportDomainUdpIpv6, Ip, Port) when is_list(Ip) -> - Ip ++ [Port div 256, Port rem 256]; -mk_taddress(transportDomainUdpIpv6 = Domain, Ip, Port) when is_tuple(Ip) -> - mk_taddress(Domain, tuple_to_list(Ip), Port); -%% -%% These are just for convenience -mk_taddress(?snmpUDPDomain, Ip, Port) -> - mk_taddress(snmpUDPDomain, Ip, Port); -mk_taddress(?transportDomainUdpIpv4, Ip, Port) -> - mk_taddress(transportDomainUdpIpv4, Ip, Port); -mk_taddress(?transportDomainUdpIpv6, Ip, Port) -> - mk_taddress(transportDomainUdpIpv6, Ip, Port); -%% -%% Bad domain -mk_taddress(BadDomain, _Ip, _Port) -> - error({bad_domain, BadDomain}). + + +%% %% XXX remove + +%% mk_taddress(snmpUDPDomain, Ip, Port) -> +%% mk_taddress(transportDomainUdpIpv4, Ip, Port); +%% mk_taddress(transportDomainUdpIpv4, Ip, Port) when is_list(Ip) -> +%% Ip ++ [Port div 256, Port rem 256]; +%% mk_taddress(transportDomainUdpIpv4 = Domain, Ip, Port) when is_tuple(Ip) -> +%% mk_taddress(Domain, tuple_to_list(Ip), Port); +%% mk_taddress(transportDomainUdpIpv6, Ip, Port) when is_list(Ip) -> +%% Ip ++ [Port div 256, Port rem 256]; +%% mk_taddress(transportDomainUdpIpv6 = Domain, Ip, Port) when is_tuple(Ip) -> +%% mk_taddress(Domain, tuple_to_list(Ip), Port); +%% %% +%% %% These are just for convenience +%% mk_taddress(?snmpUDPDomain, Ip, Port) -> +%% mk_taddress(snmpUDPDomain, Ip, Port); +%% mk_taddress(?transportDomainUdpIpv4, Ip, Port) -> +%% mk_taddress(transportDomainUdpIpv4, Ip, Port); +%% mk_taddress(?transportDomainUdpIpv6, Ip, Port) -> +%% mk_taddress(transportDomainUdpIpv6, Ip, Port); +%% %% +%% %% Bad domain +%% mk_taddress(BadDomain, _Ip, _Port) -> +%% error({bad_domain, BadDomain}). %% --------- @@ -779,59 +739,128 @@ check_ip(BadDomain, _X) -> %% Check a configuration term field from a file to see if it %% can be fed to mk_taddress/2. -check_address(Domain, Address) +check_address(Domain, Address, DefaultPort) -> + case check_address_ip(Domain, Address) of + false -> + case check_address_ip_port(Domain, Address) of + false -> + error({invalid_address, {Domain, Address}}); + true -> + {ok, Address}; + FixedAddress -> + {ok, FixedAddress} + end; + true -> + {ok, {Address, DefaultPort}}; + FixedIp -> + {ok, {FixedIp, DefaultPort}} + end. + +check_address(Domain, Address) -> + case check_address_ip_port(Domain, Address) of + false -> + error({invalid_address, {Domain, Address}}); + true -> + {ok, Address}; + FixedAddress -> + {ok, FixedAddress} + end. + +%% -> IP +check_address_ip(Domain, Address) when Domain =:= snmpUDPDomain; Domain =:= transportDomainUdpIpv4 -> case Address of %% Erlang native format - {{A0, A1, A2, A3}, P} - when ?is_ipv4_addr(A0, A1, A2, A3), ?is_word(P) -> - ok; + {A0, A1, A2, A3} + when ?is_ipv4_addr(A0, A1, A2, A3) -> + true; %% Erlangish format - {[A0,A1,A2,A3], P} - when ?is_ipv4_addr(A0, A1, A2, A3), ?is_word(P) -> - ok; + [A0,A1,A2,A3] + when ?is_ipv4_addr(A0, A1, A2, A3) -> + {A0, A1, A2, A3}; + _ -> + false + end; +check_address_ip(transportDomainUdpIpv6, Address) -> + case Address of + %% Erlang native format + {A0, A1, A2, A3, A4, A5, A6, A7} + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7) -> + true; + %% Erlangish format + [A0,A1,A2,A3,A4,A5,A6,A7] + when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7) -> + {A0, A1, A2, A3, A4, A5, A6, A7}; + %% SNMP standards format + [A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15] + when ?is_ipv6_addr( + A0, A1, A2, A3, A4, A5, A6, A7, + A8, A9, A10, A11, A12, A13, A14, A15) -> + {mk_word(A0, A1), mk_word(A2, A3), + mk_word(A4, A5), mk_word(A6, A7), + mk_word(A8, A9), mk_word(A10, A11), + mk_word(A12, A13), mk_word(A14, A15)}; + _ -> + false + end. + +%% -> {IP, Port} +check_address_ip_port(Domain, Address) + when Domain =:= snmpUDPDomain; + Domain =:= transportDomainUdpIpv4 -> + case Address of + {IP, Port} when ?is_word(Port) -> + case check_address_ip(Domain, IP) of + false -> + false; + true -> + Address; + FixedIP -> + {FixedIP, Port} + end; %% SNMP standards format [A0,A1,A2,A3,P0,P1] when ?is_ipv4_addr(A0, A1, A2, A3), ?is_word(P0, P1) -> - ok; + {{A0, A1, A2, A3}, mk_word(P0, P1)}; _ -> - error({invalid_address, {Domain, Address}}) + false end; -check_address(transportDomainUdpIpv6 = Domain, Address) -> +check_address_ip_port(transportDomainUdpIpv6 = Domain, Address) -> case Address of - %% Erlang native format - {{A0, A1, A2, A3, A4, A5, A6, A7}, P} - when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), - ?is_word(P) -> - ok; - %% Erlangish format - {[A0,A1,A2,A3,A4,A5,A6,A7], P} - when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), - ?is_word(P) -> - ok; + {IP, Port} when ?is_word(Port) -> + case check_address_ip(Domain, IP) of + false -> + false; + true -> + Address; + FixedIP -> + {FixedIP, Port} + end; %% Erlang friendly list format [A0,A1,A2,A3,A4,A5,A6,A7,P] when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), ?is_word(P) -> - ok; + {{A0, A1, A2, A3, A4, A5, A6, A7}, P}; %% Strange hybrid format with port as bytes [A0,A1,A2,A3,A4,A5,A6,A7,P0,P1] when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7), ?is_word(P0, P1) -> - ok; + {{A0, A1, A2, A3, A4, A5, A6, A7}, mk_word(P0, P1)}; %% SNMP standards format [A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,P0,P1] when ?is_ipv6_addr( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15), ?is_word(P0, P1) -> - ok; + {{mk_word(A0, A1), mk_word(A2, A3), + mk_word(A4, A5), mk_word(A6, A7), + mk_word(A8, A9), mk_word(A10, A11), + mk_word(A12, A13), mk_word(A14, A15)}, + mk_word(P0, P1)}; _ -> - error({invalid_address, {Domain, Address}}) - end; -check_address(BadDomain, _) -> - error({invalid_domain, BadDomain}). + false + end. -- cgit v1.2.3 From 373d9fa059875a2d68251c485968d3aa78e830b4 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 17 Apr 2014 16:29:51 +0200 Subject: wip-all-regression-tests-but-one-manager --- lib/snmp/src/agent/snmp_target_mib.erl | 15 ++++++++------- lib/snmp/src/manager/snmpm_config.erl | 19 +++++++++++-------- lib/snmp/src/misc/snmp_conf.erl | 16 ++++++++++------ lib/snmp/src/misc/snmp_config.erl | 4 +++- lib/snmp/test/snmp_agent_test_lib.erl | 7 +++++-- lib/snmp/test/snmp_conf_test.erl | 6 +++--- lib/snmp/test/snmp_manager_config_test.erl | 18 +++++++++--------- lib/snmp/test/snmp_manager_test.erl | 2 +- 8 files changed, 50 insertions(+), 37 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index cff1e253c3..3bcfd469e6 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -263,7 +263,7 @@ check_target_addr( TagList, Params, EngineId, Mask, MMS]), snmp_conf:check_string(Name,{gt,0}), snmp_conf:check_domain(Domain), - NAddress = snmp_conf:check_address(Domain, Address), + NAddress = check_address(Domain, Address), snmp_conf:check_integer(Timeout, {gte, 0}), snmp_conf:check_integer(RetryCount, {gte,0}), snmp_conf:check_string(TagList), @@ -290,19 +290,20 @@ check_address(Domain, Address) -> case snmp_conf:check_address(Domain, Address) of ok -> Address; - {ok, FixedAddress} -> - FixedAddress + {ok, NAddress} -> + NAddress end. -check_mask(_Domain, []) -> - []; +check_mask(_Domain, [] = Mask) -> + Mask; check_mask(Domain, Mask) -> try check_address(Domain, Mask) catch - {error, {invalid_address, Info}} -> - error({invalid_mask, Info}) + {error, {bad_address, Info}} -> + error({bad_mask, Info}) end. + %%----------------------------------------------------------------- %% TargetParams %% {Name, MPModel, SecurityModel, SecurityName, SecurityLevel} diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index af2262d988..ea962575d5 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1702,7 +1702,10 @@ verify_agent(Conf) -> verify_agent(lists:sort(fun order_agent/2, Conf), []). verify_agent([], VerifiedConf) -> - list:reverse(VerifiedConf); + Ret = lists:reverse(VerifiedConf), + ?vdebug("verify_agent -> returns:~n" + " ~p", [Ret]), + Ret; verify_agent([{_Item, _} = Entry|Conf], VerifiedConf) -> %% verify_invalid(VerifiedConf, [_Item]), % Check for duplicate verify_agent(Conf, VerifiedConf, Entry); @@ -1744,11 +1747,11 @@ verify_agent(Conf, VerifiedConf, {address = Item, Address} = Entry) -> {ok, {NAddress,FakePort}} -> verify_agent(Conf, [{Item, NAddress}|VC]); {ok, _} -> - error({invalid_address, {TDomain, Address}}) + error({bad_address, {TDomain, Address}}) end; verify_agent(Conf, VerifiedConf, {port, Port} = Entry) -> verify_invalid(VerifiedConf, [taddress]), - ok = snmp_conf:check_address(snmpUDPDomain, {{0, 0, 0, 0}, Port}), + _ = snmp_conf:check_address(snmpUDPDomain, {{0, 0, 0, 0}, Port}), verify_agent(Conf, [Entry|VerifiedConf]); verify_agent(Conf, VerifiedConf, {Item, Val} = Entry) -> case verify_agent_entry(Item, Val) of @@ -1846,7 +1849,7 @@ check_user_config({Id, Mod, Data, DefaultAgentConfig} = _User) end; check_user_config({Id, _Mod, _Data, DefaultAgentConfig}) when (Id =/= ?DEFAULT_USER) -> - {error, {bad_default_agent_config, DefaultAgentConfig}}; + error({bad_default_agent_config, DefaultAgentConfig}); check_user_config({Id, _Mod, _Data, _DefaultAgentConfig}) -> error({bad_user_id, Id}); check_user_config(User) -> @@ -2146,7 +2149,7 @@ check_manager_config({engine_id, EngineID}) -> check_manager_config({max_message_size, Max}) -> snmp_conf:check_integer(Max, {gte, 484}); check_manager_config(Conf) -> - {error, {unknown_config, Conf}}. + error({unknown_config, Conf}). check_mandatory_manager_config(Conf) -> @@ -2709,7 +2712,7 @@ handle_register_agent(UserId, TargetName, Config) -> %% dirty crossref stuff ?vtrace("handle_register_agent -> lookup address", []), {ok, Addr} = agent_info(TargetName, address), - ?vtrace("handle_register_agent -> Addr: ~p, lookup Port", + ?vtrace("handle_register_agent -> Addr: ~p, lookup Port", [Addr]), {ok, Port} = agent_info(TargetName, port), ?vtrace("handle_register_agent -> register cross-ref fix", []), @@ -2737,7 +2740,7 @@ handle_register_agent(UserId, TargetName, Config) -> do_handle_register_agent(_TargetName, []) -> ok; do_handle_register_agent(TargetName, [{Item, Val}|Rest]) -> - ?vtrace("handle_register_agent -> entry with" + ?vtrace("do_handle_register_agent -> entry with" "~n TargetName: ~p" "~n Item: ~p" "~n Val: ~p" @@ -2746,7 +2749,7 @@ do_handle_register_agent(TargetName, [{Item, Val}|Rest]) -> ok -> do_handle_register_agent(TargetName, Rest); {error, Reason} -> - ?vtrace("handle_register_agent -> failed updating ~p" + ?vtrace("do_handle_register_agent -> failed updating ~p" "~n Item: ~p" "~n Reason: ~p", [Item, Reason]), ets:match_delete(snmpm_agent_table, {TargetName, '_'}), diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index f85f1d3828..3fefe3e8cd 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -596,6 +596,8 @@ mk_taddress(?transportDomainUdpIpv6, Address) -> %% mk_taddress(transportDomainUdpIpv4 = Domain, Address) -> case Address of + [] -> % Empty mask + []; {Ip, Port} when tuple_size(Ip) =:= 4, is_integer(Port) -> tuple_to_list(Ip) ++ mk_bytes(Port); _ -> @@ -603,6 +605,8 @@ mk_taddress(transportDomainUdpIpv4 = Domain, Address) -> end; mk_taddress(transportDomainUdpIpv6 = Domain, Address) -> case Address of + [] -> % Empty mask + []; {Ip, Port} when tuple_size(Ip) =:= 8, is_integer(Port) -> tuple_to_list(Ip) ++ mk_bytes(Port); @@ -710,14 +714,14 @@ check_ip(X) -> check_ip(snmpUDPDomain, X) -> check_ip(transportDomainUdpIpv4, X); -check_ip(transportDomainUdpIpv4, X) -> +check_ip(transportDomainUdpIpv4 = Domain, X) -> case X of [A,B,C,D] when ?is_ipv4_addr(A, B, C, D) -> ok; _ -> - error({invalid_ip_address, X}) + error({bad_address, {Domain, X}}) end; -check_ip(transportDomainUdpIpv6, X) -> +check_ip(transportDomainUdpIpv6 = Domain, X) -> case X of [A,B,C,D,E,F,G,H] when ?is_ipv6_addr(A, B, C, D, E, F, G, H) -> @@ -727,7 +731,7 @@ check_ip(transportDomainUdpIpv6, X) -> A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> ok; _ -> - error({invalid_ip_address, X}) + error({bad_address, {Domain, X}}) end; %% check_ip(BadDomain, _X) -> @@ -744,7 +748,7 @@ check_address(Domain, Address, DefaultPort) -> false -> case check_address_ip_port(Domain, Address) of false -> - error({invalid_address, {Domain, Address}}); + error({bad_address, {Domain, Address}}); true -> {ok, Address}; FixedAddress -> @@ -759,7 +763,7 @@ check_address(Domain, Address, DefaultPort) -> check_address(Domain, Address) -> case check_address_ip_port(Domain, Address) of false -> - error({invalid_address, {Domain, Address}}); + error({bad_address, {Domain, Address}}); true -> {ok, Address}; FixedAddress -> diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index ec6b2ac7e4..12467a1abf 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -2446,7 +2446,9 @@ write_config_file(Dir, FileName, Verify, Write) throw:Error -> Error; T:E -> - {error, {failed_write, Dir, FileName, T, E}} + {error, + {failed_write, Dir, FileName, + {T, E, erlang:get_stacktrace()}}} end. diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index bfedd7558c..050ae0126d 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -1536,8 +1536,11 @@ rewrite_target_addr_conf(Dir, NewPort) -> end, ?line [TrapAddr|Addrs] = - snmp_conf:read(TAFile, - fun(R) -> rewrite_target_addr_conf_check(R) end), + snmp_conf:read( + TAFile, + fun(R, S) -> + {rewrite_target_addr_conf_check(R),S} + end), ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), diff --git a/lib/snmp/test/snmp_conf_test.erl b/lib/snmp/test/snmp_conf_test.erl index c4341d8d7e..5c8acb48a5 100644 --- a/lib/snmp/test/snmp_conf_test.erl +++ b/lib/snmp/test/snmp_conf_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2010. All Rights Reserved. +%% Copyright Ericsson AB 2003-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -401,7 +401,7 @@ check_taddress(Config) when is_list(Config) -> ok. verify_taddress(Val) -> - case (catch snmp_conf:check_taddress(Val)) of + case (catch snmp_conf:check_taddress(snmpUDPDomain, Val)) of {error, Reason} -> ?FAIL({verify_taddress, Val, Reason}); ok -> @@ -409,7 +409,7 @@ verify_taddress(Val) -> end. verify_not_taddress(Val) -> - case (catch snmp_conf:check_taddress(Val)) of + case (catch snmp_conf:check_taddress(snmpUDPDomain, Val)) of ok -> ?FAIL({verify_taddress, Val}); {error, _Reason} -> diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index 7b9924b83c..3cdb2cfcbe 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -693,7 +693,7 @@ start_with_invalid_manager_conf_file1(Conf) when is_list(Conf) -> "arne_anka", "4001", "500", "\"bmkEngine\""), ?line {error, Reason12} = config_start(Opts), p("start failed (as expected): ~p", [Reason12]), - ?line {failed_check, _, _, 2, {invalid_ip_address, _}} = Reason12, + ?line {failed_check, _, _, 2, {bad_address, _}} = Reason12, await_config_not_running(), %% -- @@ -702,7 +702,7 @@ start_with_invalid_manager_conf_file1(Conf) when is_list(Conf) -> "9999", "4001", "500", "\"bmkEngine\""), ?line {error, Reason13} = config_start(Opts), p("start failed (as expected): ~p", [Reason13]), - ?line {failed_check, _, _, 2, {invalid_ip_address, _}} = Reason13, + ?line {failed_check, _, _, 2, {bad_address, _}} = Reason13, await_config_not_running(), %% -- @@ -1073,7 +1073,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> case config_start(Opts) of {error, Reason53} -> p("start failed (as expected): ~p", [Reason53]), - ?line {failed_check, _, _, _, {invalid_ip_address, _}} = Reason53, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason53, await_config_not_running(); OK_53 -> exit({error, {unexpected_success, "53", OK_53}}) @@ -1086,7 +1086,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> case config_start(Opts) of {error, Reason54} -> p("start failed (as expected): ~p", [Reason54]), - ?line {failed_check, _, _, _, {invalid_ip_address, _}} = Reason54, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason54, await_config_not_running(); OK_54 -> exit({error, {unexpected_success, "54", OK_54}}) @@ -1098,7 +1098,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> write_agents_conf(ConfDir, [Agent55]), ?line {error, Reason55} = config_start(Opts), p("start failed (as expected): ~p", [Reason55]), - ?line {failed_check, _, _, _, {invalid_ip_address, _}} = Reason55, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason55, await_config_not_running(), %% -- @@ -1107,7 +1107,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> write_agents_conf(ConfDir, [Agent61]), ?line {error, Reason61} = config_start(Opts), p("start failed (as expected): ~p", [Reason61]), - ?line {failed_check, _, _, _, {invalid_integer, _}} = Reason61, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason61, await_config_not_running(), %% -- @@ -1116,7 +1116,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> write_agents_conf(ConfDir, [Agent62]), ?line {error, Reason62} = config_start(Opts), p("start failed (as expected): ~p", [Reason62]), - ?line {failed_check, _, _, _, {invalid_integer, _}} = Reason62, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason62, await_config_not_running(), %% -- @@ -1125,7 +1125,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> write_agents_conf(ConfDir, [Agent63]), ?line {error, Reason63} = config_start(Opts), p("start failed (as expected): ~p", [Reason63]), - ?line {failed_check, _, _, _, {invalid_integer, _}} = Reason63, + ?line {failed_check, _, _, _, {bad_address, _}} = Reason63, await_config_not_running(), %% -- diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 3a654a2805..90f9ef2026 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -1508,7 +1508,7 @@ register_agent3(Config) when is_list(Config) -> TargetName2 = "agent3", ?line ok = mgr_register_agent(ManagerNode, user_alfa, TargetName2, [{tdomain, transportDomainUdpIpv6}, - {address, LocalHost}, + {address, {0,0,0,0,0,0,0,1}}, {port, 5002}, {engine_id, "agentEngineId-2"}]), TargetName3 = "agent4", -- cgit v1.2.3 From 16b194c40f8a9ce2e12b82afd7d44bc782a80795 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 25 Apr 2014 16:26:13 +0200 Subject: wip --- lib/snmp/src/manager/snmpm_config.erl | 662 +++++++++++++++++++++------------- lib/snmp/src/misc/snmp_conf.erl | 52 ++- lib/snmp/test/snmp_agent_test_lib.erl | 6 +- 3 files changed, 449 insertions(+), 271 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index ea962575d5..61f402111e 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -190,7 +190,11 @@ register_user(UserId, UserMod, UserData, DefaultAgentConfig) when (UserId =/= ?DEFAULT_USER) andalso is_list(DefaultAgentConfig) -> case (catch verify_user_behaviour(UserMod)) of ok -> - Config = default_agent_config(DefaultAgentConfig), + {ok, SystemDefaultAgentConfig} = agent_info(), + Config = + ensure_config(SystemDefaultAgentConfig, + DefaultAgentConfig), +%% Config = default_agent_config(DefaultAgentConfig), call({register_user, UserId, UserMod, UserData, Config}); Error -> Error @@ -201,19 +205,19 @@ register_user(UserId, _UserMod, _UserData, DefaultAgentConfig) register_user(UserId, _, _, _) -> {error, {bad_user_id, UserId}}. -default_agent_config(DefaultAgentConfig) -> - {ok, SystemDefaultAgentConfig} = agent_info(), - default_agent_config(SystemDefaultAgentConfig, DefaultAgentConfig). - -default_agent_config([], DefaultAgentConfig) -> - DefaultAgentConfig; -default_agent_config([{Key, _} = Entry|T], DefaultAgentConfig) -> - case lists:keysearch(Key, 1, DefaultAgentConfig) of - {value, _} -> - default_agent_config(T, DefaultAgentConfig); - false -> - default_agent_config(T, [Entry|DefaultAgentConfig]) - end. +%% default_agent_config(DefaultAgentConfig) -> +%% {ok, SystemDefaultAgentConfig} = agent_info(), +%% default_agent_config(SystemDefaultAgentConfig, DefaultAgentConfig). + +%% default_agent_config([], DefaultAgentConfig) -> +%% DefaultAgentConfig; +%% default_agent_config([{Key, _} = Entry|T], DefaultAgentConfig) -> +%% case lists:keymember(Key, 1, DefaultAgentConfig) of +%% true -> +%% default_agent_config(T, DefaultAgentConfig); +%% false -> +%% default_agent_config(T, [Entry|DefaultAgentConfig]) +%% end. verify_user_behaviour(UserMod) -> @@ -282,7 +286,7 @@ do_user_info(_UserId, BadItem) -> %% :- %% This is intended for backward compatibility and therefor has %% only support for IPv4 addresses and *no* other transport domain. -mk_target_name(Addr0, Port, Config) when is_list(Config) -> +mk_target_name(Addr, Port, Config) when is_list(Config) -> Version = case lists:keysearch(version, 1, Config) of {value, {_, V}} -> @@ -290,16 +294,13 @@ mk_target_name(Addr0, Port, Config) when is_list(Config) -> false -> select_lowest_supported_version() end, - case normalize_address(Addr0) of + case normalize_address(Addr) of {A, B, C, D} -> lists:flatten( io_lib:format("~w.~w.~w.~w:~w-~w", [A, B, C, D, Port, Version])); - [A, B, C, D] -> - lists:flatten( - io_lib:format("~w.~w.~w.~w:~w-~w", [A, B, C, D, Port, Version])); _ -> lists:flatten( - io_lib:format("~p:~w-~w", [Addr0, Port, Version])) + io_lib:format("~p:~w-~w", [Addr, Port, Version])) end. select_lowest_supported_version() -> @@ -337,9 +338,9 @@ register_agent(UserId, TargetName, Config0) %% 4) Check that the manager is capable of using the selected version try verify_mandatory(Config0, [engine_id, reg_type]), - verify_oneof(Config0, [address, taddress]), - verify_invalid(Config0, [user_id]), - Config = verify_agent(Config0), + verify_someof(Config0, [address, taddress]), + verify_illegal(Config0, [user_id]), + Config = verify_agent_config(Config0), Vsns = versions(), Vsn = which_version(Config), verify_version(Vsn, Vsns), @@ -380,9 +381,8 @@ unregister_agent(UserId, TargetName) -> call({unregister_agent, UserId, TargetName}). %% This is the old style agent unregistration (using Addr and Port). -unregister_agent(UserId, Addr0, Port) -> - Addr = normalize_address(Addr0), - case do_agent_info(Addr, Port, target_name) of +unregister_agent(UserId, Addr, Port) -> + case do_agent_info(normalize_address(Addr), Port, target_name) of {ok, TargetName} -> unregister_agent(UserId, TargetName); Error -> @@ -407,9 +407,8 @@ agent_info(TargetName, Item) -> {error, not_found} end. -agent_info(Addr0, Port, Item) -> - Addr = normalize_address(Addr0), - do_agent_info(Addr, Port, Item). +agent_info(Addr, Port, Item) -> + do_agent_info(normalize_address(Addr), Port, Item). do_agent_info(Addr, Port, target_name = Item) -> case ets:lookup(snmpm_agent_table, {Addr, Port, Item}) of @@ -427,6 +426,19 @@ do_agent_info(Addr, Port, Item) -> end. +ensure_agent_info(_, [], Info) -> + Info; +ensure_agent_info(TargetName, [Item|Items], Info) -> + case lists:keymember(Item, 1, Info) of + true -> + ensure_agent_info(TargetName, Items, Info); + false -> + {ok, Value} = agent_info(TargetName, Item), + ensure_agent_info(TargetName, Items, [{Item, Value}|Info]) + end. + + + which_agents() -> which_agents('_'). @@ -670,7 +682,7 @@ verify_usm_user_config(EngineID, Name, Config) -> try begin verify_mandatory(Config, []), - verify_invalid(Config, [engine_id, name]), + verify_illegal(Config, [engine_id, name]), verify_usm_user_config2(EngineID, Name, Config) end catch @@ -1003,7 +1015,11 @@ do_init(Opts) -> %% -- Prio (optional) -- Prio = get_opt(priority, Opts, normal), ets:insert(snmpm_config_table, {prio, Prio}), - process_flag(priority, Prio), + try process_flag(priority, Prio) + catch + error:badarg -> + error({invalid_priority,Prio}) + end, %% -- Server (optional) -- ServerOpts = get_opt(server, Opts, []), @@ -1436,7 +1452,9 @@ verify_versions([]) -> ok; verify_versions([Vsn|Vsns]) -> verify_version(Vsn), - verify_versions(Vsns). + verify_versions(Vsns); +verify_versions(Vsns) -> + error({invalid_versions, Vsns}). verify_version(v1) -> ok; @@ -1559,65 +1577,94 @@ init_agent_default() -> %% The purpose of the default_agent is only to have a place %% to store system wide default values related to agents. %% + AgentDefaultConfig = + [{port, ?DEFAULT_AGENT_PORT}, % Port + {timeout, 10000}, % Timeout + {max_message_size, 484}, % Max message (packet) size + {version, v2}, % MPModel + {sec_model, v2c}, % SecModel + {sec_name, "initial"}, % SecName + {sec_level, noAuthPriv}, % SecLevel + {community, "all-rigthts"}], % Community + do_update_agent_info(default_agent, AgentDefaultConfig). - %% Port - init_agent_default(port, ?DEFAULT_AGENT_PORT), +%% %% Port +%% init_agent_default(port, ?DEFAULT_AGENT_PORT), - %% Timeout - init_agent_default(timeout, 10000), +%% %% Timeout +%% init_agent_default(timeout, 10000), - %% Max message (packet) size - init_agent_default(max_message_size, 484), +%% %% Max message (packet) size +%% init_agent_default(max_message_size, 484), - %% MPModel - init_agent_default(version, v2), +%% %% MPModel +%% init_agent_default(version, v2), - %% SecModel - init_agent_default(sec_model, v2c), +%% %% SecModel +%% init_agent_default(sec_model, v2c), - %% SecName - init_agent_default(sec_name, "initial"), +%% %% SecName +%% init_agent_default(sec_name, "initial"), - %% SecLevel - init_agent_default(sec_level, noAuthNoPriv), +%% %% SecLevel +%% init_agent_default(sec_level, noAuthNoPriv), - %% Community - init_agent_default(community, "all-rights"), - ok. +%% %% Community +%% init_agent_default(community, "all-rights"), +%% ok. -init_agent_default(Item, Val) when Item =/= user_id -> - case do_update_agent_info(default_agent, Item, Val) of - ok -> - ok; - {error, Reason} -> - error(Reason) - end. +%% init_agent_default(Item, Val) when Item =/= user_id -> +%% case do_update_agent_info(default_agent, Item, Val) of +%% ok -> +%% ok; +%% {error, Reason} -> +%% error(Reason) +%% end. +%% read_agents_config_file(Dir) -> +%% Verify = fun check_agent_config2/1, +%% case read_file(Dir, "agents.conf", Verify, []) of +%% {ok, Conf} -> +%% Conf; +%% Error -> +%% ?vlog("agent config error: ~p", [Error]), +%% throw(Error) +%% end. + +%% check_agent_config2(Agent) -> +%% case (catch check_agent_config(Agent)) of +%% {ok, {UserId, TargetName, Conf, Version}} -> +%% {ok, Vsns} = system_info(versions), +%% case lists:member(Version, Vsns) of +%% true -> +%% {ok, {UserId, TargetName, Conf}}; +%% false -> +%% error({version_not_supported_by_manager, +%% Version, Vsns}) +%% end; +%% Err -> +%% throw(Err) +%% end. read_agents_config_file(Dir) -> - Verify = fun check_agent_config2/1, - case read_file(Dir, "agents.conf", Verify, []) of - {ok, Conf} -> - Conf; - Error -> + Order = fun snmp_conf:no_order/2, + Check = fun check_agent_config/2, + try read_file(Dir, "agents.conf", Order, Check, []) + catch + throw:Error -> ?vlog("agent config error: ~p", [Error]), - throw(Error) + erlang:raise(throw, Error, erlang:get_stacktrace()) end. -check_agent_config2(Agent) -> - case (catch check_agent_config(Agent)) of - {ok, {UserId, TargetName, Conf, Version}} -> - {ok, Vsns} = system_info(versions), - case lists:member(Version, Vsns) of - true -> - {ok, {UserId, TargetName, Conf}}; - false -> - error({version_not_supported_by_manager, - Version, Vsns}) - end; - Err -> - throw(Err) +check_agent_config(Agent, State) -> + {ok, {UserId, TargetName, Conf, Version}} = check_agent_config(Agent), + {ok, Vsns} = system_info(versions), + case lists:member(Version, Vsns) of + true -> + {{ok, {UserId, TargetName, Conf}}, State}; + false -> + error({version_not_supported_by_manager, Version, Vsns}) end. %% For backward compatibility @@ -1668,7 +1715,7 @@ check_agent_config( {sec_name, SecName}, {sec_level, SecLevel} ], - {ok, {UserId, TargetName, verify_agent(Conf), Version}}. + {ok, {UserId, TargetName, verify_agent_config(Conf), Version}}. @@ -1690,30 +1737,63 @@ init_agent_config({UserId, TargetName, Config}) -> -%% Sort tdomain first -order_agent({Item, _}, {Item, _}) -> - true; %% Less than or equal -order_agent(_, {tdomain, _}) -> - false; %% Greater than -order_agent(_, _) -> - true. %% Less than or equal +%% Sort tdomain first then port to ensure both comes before taddress +order_agent({Item1, _}, {Item2, _}) -> + if Item1 == Item2 -> + true; % Item1 == Item2 + Item2 =:= tdomain -> + false; % Item1 > tdomain + Item2 =:= port -> + if Item1 =:= tdomain -> + true; % tdomain < port + true -> + false % Item1 > port + end; + true -> + true % Item1 < Item 2 + end. -verify_agent(Conf) -> - verify_agent(lists:sort(fun order_agent/2, Conf), []). +fix_agent_config(Conf) -> + ?vdebug("fix_agent_config -> entry with~n~n" + " Conf: ~p", [Conf]), + fix_agent_config(lists:sort(fun order_agent/2, Conf), []). -verify_agent([], VerifiedConf) -> +fix_agent_config([], FixedConf) -> + Ret = lists:reverse(FixedConf), + ?vdebug("fix_agent_config -> returns:~n" + " ~p", [Ret]), + Ret; +fix_agent_config([{taddress = Item, Address} = Entry|Conf], FixedConf) -> + {value, {tdomain, TDomain}} = lists:keysearch(tdomain, 1, FixedConf), + {value, {port, DefaultPort}} = lists:keysearch(port, 1, FixedConf), + case snmp_conf:check_address(TDomain, Address, DefaultPort) of + ok -> + fix_agent_config(Conf, [Entry|FixedConf]); + {ok, NAddress} -> + fix_agent_config(Conf, [{Item, NAddress}|FixedConf]) + end; +fix_agent_config([Entry|Conf], FixedConf) -> + fix_agent_config(Conf, [Entry|FixedConf]). + + + +verify_agent_config(Conf) -> + verify_agent_config(lists:sort(fun order_agent/2, Conf), []). + +verify_agent_config([], VerifiedConf) -> Ret = lists:reverse(VerifiedConf), - ?vdebug("verify_agent -> returns:~n" + ?vdebug("verify_agent_config -> returns:~n" " ~p", [Ret]), Ret; -verify_agent([{_Item, _} = Entry|Conf], VerifiedConf) -> -%% verify_invalid(VerifiedConf, [_Item]), % Check for duplicate - verify_agent(Conf, VerifiedConf, Entry); -verify_agent([Bad|_], _VerifiedConf) -> +verify_agent_config([{Item, _} = Entry|Conf], VerifiedConf) -> + verify_illegal(VerifiedConf, [Item]), % Duplicates are hereby illegal + verify_agent_config(Conf, VerifiedConf, Entry); +verify_agent_config([Bad|_], _VerifiedConf) -> error({bad_agent_config, Bad}). -verify_agent(Conf, VerifiedConf, {taddress = Item, TAddress} = Entry) -> - verify_invalid(VerifiedConf, [address,port]), +verify_agent_config( + Conf, VerifiedConf, {taddress = Item, Address} = Entry) -> + verify_illegal(VerifiedConf, [address]), {TDomain, VC} = case lists:keysearch(tdomain, 1, VerifiedConf) of {value, {tdomain,TD}} -> @@ -1723,42 +1803,36 @@ verify_agent(Conf, VerifiedConf, {taddress = Item, TAddress} = Entry) -> TD = default_transport_domain(), {TD, [{tdomain, TD}|VerifiedConf]} end, - case snmp_conf:check_address(TDomain, TAddress) of + case snmp_conf:check_address(TDomain, Address, 0) of ok -> - verify_agent(Conf, [Entry|VC]); + verify_agent_config(Conf, [Entry|VC]); {ok, NAddress} -> - verify_agent(Conf, [{Item, NAddress}|VC]) + verify_agent_config(Conf, [{Item, NAddress}|VC]) end; -verify_agent(Conf, VerifiedConf, {address = Item, Address} = Entry) -> - verify_invalid(VerifiedConf, [taddress]), +verify_agent_config(Conf, VerifiedConf, {address, Address}) -> + Item = taddress, + verify_illegal(VerifiedConf, [Item]), {TDomain, VC} = case lists:keysearch(tdomain, 1, VerifiedConf) of - {value, {tdomain,TD}} -> + {value, {tdomain, TD}} -> {TD, VerifiedConf}; _ -> %% Insert tdomain since it is missing TD = default_transport_domain(), {TD, [{tdomain, TD}|VerifiedConf]} end, - FakePort = make_ref(), - case snmp_conf:check_address(TDomain, Address, FakePort) of + case snmp_conf:check_address(TDomain, Address, 0) of ok -> - verify_agent(Conf, [Entry|VC]); - {ok, {NAddress,FakePort}} -> - verify_agent(Conf, [{Item, NAddress}|VC]); - {ok, _} -> - error({bad_address, {TDomain, Address}}) + verify_agent_config(Conf, [{Item, Address}|VC]); + {ok, NAddress} -> + verify_agent_config(Conf, [{Item, NAddress}|VC]) end; -verify_agent(Conf, VerifiedConf, {port, Port} = Entry) -> - verify_invalid(VerifiedConf, [taddress]), - _ = snmp_conf:check_address(snmpUDPDomain, {{0, 0, 0, 0}, Port}), - verify_agent(Conf, [Entry|VerifiedConf]); -verify_agent(Conf, VerifiedConf, {Item, Val} = Entry) -> +verify_agent_config(Conf, VerifiedConf, {Item, Val} = Entry) -> case verify_agent_entry(Item, Val) of ok -> - verify_agent(Conf, [Entry|VerifiedConf]); + verify_agent_config(Conf, [Entry|VerifiedConf]); {ok, NewVal} -> - verify_agent(Conf, [{Item, NewVal}|VerifiedConf]) + verify_agent_config(Conf, [{Item, NewVal}|VerifiedConf]) end. verify_agent_entry(user_id, _UserId) -> @@ -1773,6 +1847,8 @@ verify_agent_entry(reg_type, RegType) -> end; verify_agent_entry(tdomain, TDomain) -> snmp_conf:check_domain(TDomain); +verify_agent_entry(port, Port) -> + snmp_conf:check_port(Port); verify_agent_entry(community, Comm) -> snmp_conf:check_string(Comm); verify_agent_entry(engine_id, EngineId) -> @@ -1810,17 +1886,26 @@ verify_agent_entry(Item, _) -> +%% read_users_config_file(Dir) -> +%% Verify = fun check_user_config/1, +%% case read_file(Dir, "users.conf", Verify, []) of +%% {ok, Conf} -> +%% Conf; +%% Error -> +%% ?vlog("failure reading users config file: ~n ~p", [Error]), +%% throw(Error) +%% end. + read_users_config_file(Dir) -> - Verify = fun check_user_config/1, - case read_file(Dir, "users.conf", Verify, []) of - {ok, Conf} -> - Conf; - Error -> + Order = fun snmp_conf:no_order/2, + Check = fun (User, State) -> {check_user_config(User), State} end, + try read_file(Dir, "users.conf", Order, Check, []) + catch + throw:Error -> ?vlog("failure reading users config file: ~n ~p", [Error]), - throw(Error) + erlang:raise(throw, Error, erlang:get_stacktrace()) end. - check_user_config({Id, Mod, Data}) -> ?vtrace("check_user_config -> entry with" "~n Id: ~p" @@ -1889,9 +1974,14 @@ verify_user({Id, UserMod, UserData, DefaultAgentConfig}) case (catch verify_user_behaviour(UserMod)) of ok -> try + {ok, SystemDefaultAgentConfig} = agent_info(), Config = - default_agent_config( + ensure_config( + SystemDefaultAgentConfig, verify_default_agent_config(DefaultAgentConfig)), +%% Config = +%% default_agent_config( +%% verify_default_agent_config(DefaultAgentConfig)), {ok, #user{id = Id, mod = UserMod, data = UserData, @@ -1913,10 +2003,10 @@ verify_user({Id, _, _, _}) -> verify_default_agent_config(Conf) -> try - verify_invalid( + verify_illegal( Conf, [user_id, engine_id, address, tdomain, taddress]), - verify_agent(Conf) + verify_agent_config(Conf) catch Error -> ?vdebug("verify_default_agent_config -> throw" @@ -1924,14 +2014,19 @@ verify_default_agent_config(Conf) -> error({bad_default_agent_config, Error}) end. +%% read_usm_config_file(Dir) -> +%% Verify = fun check_usm_user_config/1, +%% case read_file(Dir, "usm.conf", Verify, []) of +%% {ok, Conf} -> +%% Conf; +%% Error -> +%% throw(Error) +%% end. + read_usm_config_file(Dir) -> - Verify = fun check_usm_user_config/1, - case read_file(Dir, "usm.conf", Verify, []) of - {ok, Conf} -> - Conf; - Error -> - throw(Error) - end. + Order = fun snmp_conf:no_order/2, + Check = fun (User, State) -> {check_usm_user_config(User), State} end, + read_file(Dir, "usm.conf", Order, Check, []). %% Identity-function check_usm_user_config({EngineId, Name, @@ -2113,21 +2208,38 @@ is_crypto_supported(Func) -> snmp_misc:is_crypto_supported(Func). +%% read_manager_config_file(Dir) -> +%% Verify = fun check_manager_config/1, +%% case read_file(Dir, "manager.conf", Verify) of +%% {ok, Conf} -> +%% ?d("read_manager_config_file -> ok: " +%% "~n Conf: ~p", [Conf]), +%% %% If the address is not specified, then we assume +%% %% it should be the local host. +%% %% If the address is not possible to determine +%% %% that way, then we give up... +%% verify_mandatory(Conf, [port,engine_id,max_message_size]), +%% ensure_config(default_manager_config(), Conf); +%% %% check_mandatory_manager_config(Conf), +%% %% ensure_manager_config(Conf); +%% Error -> +%% throw(Error) +%% end. + read_manager_config_file(Dir) -> - Verify = fun check_manager_config/1, - case read_file(Dir, "manager.conf", Verify) of - {ok, Conf} -> - ?d("read_manager_config_file -> ok: " - "~n Conf: ~p", [Conf]), - %% If the address is not specified, then we assume - %% it should be the local host. - %% If the address is not possible to determine - %% that way, then we give up... - check_mandatory_manager_config(Conf), - ensure_manager_config(Conf); - Error -> - throw(Error) - end. + Order = fun snmp_conf:no_order/2, + Check = fun (Entry, State) -> {check_manager_config(Entry), State} end, + Conf = read_file(Dir, "manager.conf", Order, Check), + ?d("read_manager_config_file -> ok: " + "~n Conf: ~p", [Conf]), + %% If the address is not specified, then we assume + %% it should be the local host. + %% If the address is not possible to determine + %% that way, then we give up... + verify_mandatory(Conf, [port,engine_id,max_message_size]), + ensure_config(default_manager_config(), Conf). + + default_manager_config() -> {ok, HostName} = inet:gethostname(), @@ -2152,33 +2264,33 @@ check_manager_config(Conf) -> error({unknown_config, Conf}). -check_mandatory_manager_config(Conf) -> - Mand = [port, engine_id, max_message_size], - check_mandatory_manager_config(Mand, Conf). +%% check_mandatory_manager_config(Conf) -> +%% Mand = [port, engine_id, max_message_size], +%% check_mandatory_manager_config(Mand, Conf). -check_mandatory_manager_config([], _Conf) -> - ok; -check_mandatory_manager_config([Item|Mand], Conf) -> - case lists:keysearch(Item, 1, Conf) of - false -> - error({missing_mandatory_manager_config, Item}); - _ -> - check_mandatory_manager_config(Mand, Conf) - end. +%% check_mandatory_manager_config([], _Conf) -> +%% ok; +%% check_mandatory_manager_config([Item|Mand], Conf) -> +%% case lists:keysearch(Item, 1, Conf) of +%% false -> +%% error({missing_mandatory_manager_config, Item}); +%% _ -> +%% check_mandatory_manager_config(Mand, Conf) +%% end. -ensure_manager_config(Confs) -> - ensure_manager_config(Confs, default_manager_config()). - -ensure_manager_config(Confs, []) -> - Confs; -ensure_manager_config(Confs, [{Key,_} = DefKeyVal|Defs]) -> - case lists:keysearch(Key, 1, Confs) of - false -> - ensure_manager_config([DefKeyVal|Confs], Defs); - {value, _Conf} -> - ensure_manager_config(Confs, Defs) - end. +%% ensure_manager_config(Confs) -> +%% ensure_manager_config(Confs, default_manager_config()). + +%% ensure_manager_config(Confs, []) -> +%% Confs; +%% ensure_manager_config(Confs, [{Key,_} = DefKeyVal|Defs]) -> +%% case lists:keysearch(Key, 1, Confs) of +%% false -> +%% ensure_manager_config([DefKeyVal|Confs], Defs); +%% {value, _Conf} -> +%% ensure_manager_config(Confs, Defs) +%% end. % ensure_manager_config([], Defs, Confs) -> % Confs ++ Defs; @@ -2191,41 +2303,61 @@ ensure_manager_config(Confs, [{Key,_} = DefKeyVal|Defs]) -> % ensure_manager_config(Confs, Defs, [Conf|Acc]) % end. - - -read_file(Dir, FileName, Verify, Default) -> - File = filename:join(Dir, FileName), - case file:read_file_info(File) of - {ok, _} -> - read_file(File, Verify); - {error, Reason} -> +read_file(Dir, FileName, Order, Check, Default) -> + try snmp_conf:read(filename:join(Dir, FileName), Order, Check) + catch + {error, Reason} when element(1, Reason) =:= failed_open -> ?vlog("failed reading config from ~s: ~p", [FileName, Reason]), - {ok, Default} + Default end. -read_file(Dir, FileName, Verify) -> - File = filename:join(Dir, FileName), - case file:read_file_info(File) of - {ok, _} -> - read_file(File, Verify); - {error, Reason} -> +read_file(Dir, FileName, Order, Check) -> + try snmp_conf:read(filename:join(Dir, FileName), Order, Check) + catch + throw:{error, Reason} = Error + when element(1, Reason) =:= failed_open -> error_msg("failed reading config from ~s: ~p", [FileName, Reason]), - {error, {failed_reading, FileName, Reason}} + erlang:raise(throw, Error, erlang:get_stacktrace()) end. -read_file(File, Verify) -> - Check = fun (Config, State) -> {Verify(Config), State} end, - try snmp_conf:read(File, Check) of - Conf -> - ?vtrace("read_file -> read ok" - "~n Conf: ~p", [Conf]), - {ok, Conf} - catch - Error -> - ?vtrace("read_file -> read failed:" - "~n Error: ~p", [Error]), - Error - end. + + + + + +%% read_file(Dir, FileName, Verify, Default) -> +%% File = filename:join(Dir, FileName), +%% case file:read_file_info(File) of +%% {ok, _} -> +%% read_file(File, Verify); +%% {error, Reason} -> +%% ?vlog("failed reading config from ~s: ~p", [FileName, Reason]), +%% {ok, Default} +%% end. + +%% read_file(Dir, FileName, Verify) -> +%% File = filename:join(Dir, FileName), +%% case file:read_file_info(File) of +%% {ok, _} -> +%% read_file(File, Verify); +%% {error, Reason} -> +%% error_msg("failed reading config from ~s: ~p", [FileName, Reason]), +%% {error, {failed_reading, FileName, Reason}} +%% end. + +%% read_file(File, Verify) -> +%% Check = fun (Config, State) -> {Verify(Config), State} end, +%% try snmp_conf:read(File, Check) of +%% Conf -> +%% ?vtrace("read_file -> read ok" +%% "~n Conf: ~p", [Conf]), +%% {ok, Conf} +%% catch +%% Error -> +%% ?vtrace("read_file -> read failed:" +%% "~n Error: ~p", [Error]), +%% Error +%% end. %% XXX remove @@ -2695,30 +2827,48 @@ handle_register_agent(UserId, TargetName, Config) -> "~n Config: ~p", [UserId, TargetName, Config]), case (catch agent_info(TargetName, user_id)) of {error, _} -> - ?vtrace("handle_register_agent -> user_id not found in config", []), + ?vtrace( + "handle_register_agent -> user_id not found in config", []), case ets:lookup(snmpm_user_table, UserId) of [#user{default_agent_config = DefConfig}] -> - ?vtrace("handle_register_agent -> " - "~n DefConfig: ~p", [DefConfig]), - %% First, insert this users default config - ?vtrace("handle_register_agent -> store default config", []), - do_handle_register_agent(TargetName, DefConfig), - %% Second, insert the config for this agent - ?vtrace("handle_register_agent -> store config", []), - do_handle_register_agent(TargetName, - [{user_id, UserId}|Config]), + ?vtrace("handle_register_agent ->~n" + " DefConfig: ~p", [DefConfig]), + FixedConfig = + fix_agent_config(ensure_config(DefConfig, Config)), + ?vtrace("handle_register_agent ->~n" + " FixedConfig: ~p", [FixedConfig]), + do_handle_register_agent( + TargetName, [{user_id, UserId}|FixedConfig]), %% - %% And now for some (backward compatibillity) + %% And now for some (backward compatibillity) %% dirty crossref stuff - ?vtrace("handle_register_agent -> lookup address", []), - {ok, Addr} = agent_info(TargetName, address), - ?vtrace("handle_register_agent -> Addr: ~p, lookup Port", - [Addr]), - {ok, Port} = agent_info(TargetName, port), - ?vtrace("handle_register_agent -> register cross-ref fix", []), - ets:insert(snmpm_agent_table, + {value, {taddress, {Addr, Port}}} = + lists:keysearch(taddress, 1, FixedConfig), + ?vtrace( + "handle_register_agent -> register cross-ref fix", []), + ets:insert(snmpm_agent_table, {{Addr, Port, target_name}, TargetName}), %% + +%% %% First, insert this users default config +%% ?vtrace("handle_register_agent -> store default config", []), +%% do_handle_register_agent(TargetName, DefConfig), +%% %% Second, insert the config for this agent +%% ?vtrace("handle_register_agent -> store config", []), +%% do_handle_register_agent(TargetName, +%% [{user_id, UserId}|Config]), +%% %% +%% %% And now for some (backward compatibillity) +%% %% dirty crossref stuff +%% ?vtrace("handle_register_agent -> lookup taddress", []), +%% {ok, {Addr, Port} = TAddress} = +%% agent_info(TargetName, taddress), +%% ?vtrace("handle_register_agent -> taddress: ~p", +%% [TAddress]), +%% ?vtrace("handle_register_agent -> register cross-ref fix", []), +%% ets:insert(snmpm_agent_table, +%% {{Addr, Port, target_name}, TargetName}), +%% %% ok; _ -> {error, {not_found, UserId}} @@ -2773,8 +2923,7 @@ handle_unregister_agent(UserId, TargetName) -> %% %% And now for some (backward compatibillity) %% dirty crossref stuff - {ok, Addr} = agent_info(TargetName, address), - {ok, Port} = agent_info(TargetName, port), + {ok, {Addr, Port}} = agent_info(TargetName, taddress), ets:delete(snmpm_agent_table, {Addr, Port, target_name}), %% ets:match_delete(snmpm_agent_table, {{TargetName, '_'}, '_'}), @@ -2801,32 +2950,26 @@ handle_update_agent_info(UserId, TargetName, Info) -> Error end. -handle_update_agent_info(TargetName, Info0) -> +handle_update_agent_info(TargetName, Info) -> ?vtrace("handle_update_agent_info -> entry with" "~n TargetName: ~p" - "~n Info0: ~p", [TargetName, Info0]), + "~n Info: ~p", [TargetName, Info]), %% Verify info try - verify_invalid(Info0, [user_id]), - %% If domain is part of the info, then use it. + verify_illegal(Info, [user_id]), + %% If port or domain is part of the info, then use it. %% If not, lookup what is already stored for %% this agent and use that. - Info = - case lists:keysearch(tdomain, 1, Info0) of - {value, {tdomain, _}} -> - Info0; - false -> - {ok, TDomain} = - agent_info(TargetName, tdomain), - [{tdomain, TDomain}|Info0] - end, - verify_agent(Info), - do_update_agent_info(TargetName, Info) - catch + do_update_agent_info( + TargetName, + fix_agent_config( + verify_agent_config( + ensure_agent_info(TargetName, [port,tdomain], Info)))) + catch Error -> Error; T:E -> - {error, {failed_info_verification, Info0, T, E}} + {error, {failed_info_verification, Info, T, E}} end. handle_update_agent_info(UserId, TargetName, Item, Val) -> @@ -2838,6 +2981,9 @@ handle_update_agent_info(UserId, TargetName, Item, Val) -> handle_update_agent_info(TargetName, [{Item, Val}]). do_update_agent_info(TargetName, Info) -> + ?vtrace("do_update_agent_info -> entry with~n" + " TargetName: ~p~n" + " Info: ~p", [TargetName,Info]), InsertItem = fun({Item, Val}) -> ets:insert(snmpm_agent_table, {{TargetName, Item}, Val}) @@ -3022,17 +3168,17 @@ verify_mandatory(Conf, [Mand|Mands]) -> error({missing_mandatory_config, Mand}) end. -verify_invalid(_, []) -> +verify_illegal(_, []) -> ok; -verify_invalid(Conf, [Inv|Invs]) -> +verify_illegal(Conf, [Inv|Invs]) -> case lists:member(Inv, Conf) of false -> - verify_invalid(Conf, Invs); + verify_illegal(Conf, Invs); true -> error({illegal_config, Inv}) end. -verify_oneof(Conf, [Mand|Mands]) -> +verify_someof(Conf, [Mand|Mands]) -> case lists:keymember(Mand, 1, Conf) of true -> ok; @@ -3041,10 +3187,20 @@ verify_oneof(Conf, [Mand|Mands]) -> [] -> error({missing_mandatory_config, Mand}); _ -> - verify_oneof(Conf, Mands) + verify_someof(Conf, Mands) end end. +ensure_config([], Config) -> + Config; +ensure_config([Default|Defaults], Config) -> + case lists:keymember(element(1, Default), 1, Config) of + true -> + ensure_config(Defaults, Config); + false -> + ensure_config(Defaults, [Default|Config]) + end. + %%%------------------------------------------------------------------- @@ -3203,30 +3359,16 @@ init_mini_mib_elems(MibName, [_|T], Res) -> %%---------------------------------------------------------------------- normalize_address(Addr) -> - normalize_address(snmpUDPDomain, Addr). - -normalize_address(snmpUDPDomain, Addr) -> - normalize_address(transportDomainUdpIpv4, Addr); - -normalize_address(Domain, Addr) -> - case inet:getaddr(Addr, td2fam(Domain)) of - {ok, Addr2} -> - Addr2; - _ when is_list(Addr) -> - case (catch snmp_conf:check_ip(Domain, Addr)) of - ok -> - list_to_tuple(Addr); - _ -> - Addr - end; + try snmp_conf:check_address_no_port(snmpUDPDomain, Addr) of + ok -> + Addr; + {ok, NAddr} -> + NAddr + catch _ -> - Addr + Addr end. -td2fam(transportDomainUdpIpv4) -> inet; -td2fam(transportDomainUdpIpv6) -> inet6. - - %%---------------------------------------------------------------------- call(Req) -> diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 3fefe3e8cd..d8a19c7137 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -45,6 +45,7 @@ mk_tdomain/1, which_domain/1, check_ip/1, check_ip/2, + check_address_no_port/2, check_port/1, check_address/2, check_address/3, check_taddress/2, mk_taddress/2, @@ -155,7 +156,8 @@ no_filter(X) -> X. -read(File, Check) -> +read(File, Verify) -> + Check = fun (Row, State) -> {Verify(Row), State} end, read(File, fun no_order/2, Check). %% Ret. Res | exit(Reason) @@ -740,32 +742,70 @@ check_ip(BadDomain, _X) -> %% --------- +%% check_address_default_port(Domain, Address) -> +%% case check_address_ip(Domain, Address) of +%% false -> +%% case check_address_ip_port(Domain, Address) of +%% false -> +%% error({bad_address, {Domain, Address}}); +%% _ -> +%% ok +%% end; +%% _ -> +%% ok +%% end. + +check_address_no_port(Domain, Address) -> + case check_address_ip(Domain, Address) of + false -> + error({bad_address, {Domain, Address}}); + true -> + ok; + FixedIP -> + {ok, FixedIP} + end. + +check_port(Port) when ?is_word(Port) -> + ok; +check_port(Port) -> + error({bad_port, Port}). + %% Check a configuration term field from a file to see if it -%% can be fed to mk_taddress/2. +%% can be fixed to be fed to mk_taddress/2. check_address(Domain, Address, DefaultPort) -> + %% If Address does not contain Port or contains Port =:= 0 + %% create an address containing DefaultPort case check_address_ip(Domain, Address) of false -> case check_address_ip_port(Domain, Address) of false -> error({bad_address, {Domain, Address}}); true -> - {ok, Address}; + case Address of + {IP, 0} -> + {ok, {IP, DefaultPort}}; + _ -> + ok + end; + {FixedIP, 0} -> + {ok, {FixedIP, DefaultPort}}; FixedAddress -> {ok, FixedAddress} end; true -> {ok, {Address, DefaultPort}}; - FixedIp -> - {ok, {FixedIp, DefaultPort}} + FixedIP -> + {ok, {FixedIP, DefaultPort}} end. check_address(Domain, Address) -> + %% Address has to contain Port case check_address_ip_port(Domain, Address) of false -> error({bad_address, {Domain, Address}}); true -> - {ok, Address}; + ok; FixedAddress -> {ok, FixedAddress} end. diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 050ae0126d..e12a282a34 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -1536,11 +1536,7 @@ rewrite_target_addr_conf(Dir, NewPort) -> end, ?line [TrapAddr|Addrs] = - snmp_conf:read( - TAFile, - fun(R, S) -> - {rewrite_target_addr_conf_check(R),S} - end), + snmp_conf:read(TAFile, fun rewrite_target_addr_conf_check/1), ?DBG("rewrite_target_addr_conf -> TrapAddr: ~p",[TrapAddr]), -- cgit v1.2.3 From abbd9936144da7bcff9b4819785e597455ac7f35 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 30 Apr 2014 16:47:05 +0200 Subject: wip: Rewrite manager net_if process --- lib/snmp/src/manager/snmpm.erl | 33 +- lib/snmp/src/manager/snmpm_config.erl | 116 +++-- lib/snmp/src/manager/snmpm_mpd.erl | 2 +- lib/snmp/src/manager/snmpm_net_if.erl | 291 ++++++------ lib/snmp/src/manager/snmpm_net_if_filter.erl | 52 ++- lib/snmp/src/manager/snmpm_net_if_mt.erl | 306 +++++++------ lib/snmp/src/manager/snmpm_server.erl | 660 ++++++++++++++------------- lib/snmp/src/manager/snmpm_user.erl | 23 +- lib/snmp/src/manager/snmpm_user_default.erl | 16 +- lib/snmp/src/misc/snmp_conf.erl | 59 +-- lib/snmp/test/snmp_manager_test.erl | 2 +- 11 files changed, 844 insertions(+), 716 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index c97b635fc6..cf272c5504 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -379,21 +379,26 @@ register_agent(UserId, Addr) -> register_agent(UserId, Addr, ?DEFAULT_AGENT_PORT, []). %% Backward compatibility -register_agent(UserId, Addr, Port, Config0) -> +register_agent(UserId, Domain, Address, Config0) when is_atom(Domain) -> case lists:keymember(target_name, 1, Config0) of false -> - TargetName = mk_target_name(Addr, Port, Config0), - Config = [{reg_type, addr_port}, - {address, Addr}, {port, Port} | Config0], + TargetName = mk_target_name(Domain, Address, Config0), + Config = + [{reg_type, addr_port}, + {tdomain, Domain}, {taddress, Address} | Config0], do_register_agent(UserId, TargetName, ensure_engine_id(Config)); true -> {value, {_, TargetName}} = lists:keysearch(target_name, 1, Config0), Config1 = lists:keydelete(target_name, 1, Config0), - Config2 = [{reg_type, addr_port}, - {address, Addr}, {port, Port} | Config1], + Config2 = + [{reg_type, addr_port}, + {tdomain, Domain}, {taddress, Address} | Config1], register_agent(UserId, TargetName, ensure_engine_id(Config2)) - end. + end; +register_agent(UserId, Ip, Port, Config) when is_integer(Port) -> + {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + register_agent(UserId, Domain, Address, Config). unregister_agent(UserId, TargetName) when is_list(TargetName) -> snmpm_config:unregister_agent(UserId, TargetName); @@ -402,8 +407,8 @@ unregister_agent(UserId, TargetName) when is_list(TargetName) -> unregister_agent(UserId, Addr) -> unregister_agent(UserId, Addr, ?DEFAULT_AGENT_PORT). -unregister_agent(UserId, Addr, Port) -> - case target_name(Addr, Port) of +unregister_agent(UserId, DomainIp, AddressPort) -> + case target_name(DomainIp, AddressPort) of {ok, TargetName} -> unregister_agent(UserId, TargetName); Error -> @@ -1264,11 +1269,11 @@ format_vb_value(Prefix, _Type, Val) -> %% --- Internal utility functions --- %% -target_name(Addr) -> - target_name(Addr, ?DEFAULT_AGENT_PORT). +target_name(Ip) -> + target_name(Ip, ?DEFAULT_AGENT_PORT). -target_name(Addr, Port) -> - snmpm_config:agent_info(Addr, Port, target_name). +target_name(DomainIp, AddressPort) -> + snmpm_config:agent_info(DomainIp, AddressPort, target_name). mk_target_name(Addr, Port, Config) -> snmpm_config:mk_target_name(Addr, Port, Config). diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 61f402111e..088f0c7fc8 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -286,7 +286,8 @@ do_user_info(_UserId, BadItem) -> %% :- %% This is intended for backward compatibility and therefor has %% only support for IPv4 addresses and *no* other transport domain. -mk_target_name(Addr, Port, Config) when is_list(Config) -> +mk_target_name(Domain, Address, Config) + when is_atom(Domain), is_list(Config) -> Version = case lists:keysearch(version, 1, Config) of {value, {_, V}} -> @@ -294,15 +295,27 @@ mk_target_name(Addr, Port, Config) when is_list(Config) -> false -> select_lowest_supported_version() end, - case normalize_address(Addr) of - {A, B, C, D} -> + try fix_address(Domain, Address) of + {{A, B, C, D}, P} -> lists:flatten( - io_lib:format("~w.~w.~w.~w:~w-~w", [A, B, C, D, Port, Version])); - _ -> + io_lib:format( + "~w.~w.~w.~w:~w-~w", + [A, B, C, D, P, Version])); + {{A, B, C, D, E, F, G, H}, P} -> lists:flatten( - io_lib:format("~p:~w-~w", [Addr, Port, Version])) - end. - + io_lib:format( + "[~.16b:~.16b:~.16b:~.16b:~.16b:~.16b:~.16b:~.16b]:~w-~w", + [A, B, C, D, E, F, G, H, P, Version])) + catch + _ -> + lists:flatten( + io_lib:format("~p-~w", [Address, Version])) + end; +mk_target_name(Ip, Port, Config) + when is_integer(Port), is_list(Config) -> + {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + mk_target_name(Domain, Address, Config). + select_lowest_supported_version() -> {ok, Versions} = system_info(versions), select_lowest_supported_version([v1, v2, v3], Versions). @@ -381,14 +394,33 @@ unregister_agent(UserId, TargetName) -> call({unregister_agent, UserId, TargetName}). %% This is the old style agent unregistration (using Addr and Port). -unregister_agent(UserId, Addr, Port) -> - case do_agent_info(normalize_address(Addr), Port, target_name) of +unregister_agent(UserId, Domain, Address) when is_atom(Domain) -> + try fix_address(Domain, Address) of + NAddress -> + do_unregister_agent(UserId, Domain, NAddress) + catch + _ -> + {error, not_found} + end; +unregister_agent(UserId, Ip, Port) when is_integer(Port) -> + try snmp_conf:fix_domain_address(Ip, Port) of + {Domain, Address} -> + do_unregister_agent(UserId, Domain, Address) + catch + _ -> + {error, not_found} + end. + +do_unregister_agent(UserId, Domain, Address) -> + case do_agent_info(Domain, Address, target_name) of {ok, TargetName} -> unregister_agent(UserId, TargetName); Error -> Error end. + + agent_info() -> agent_info(?DEFAULT_TARGETNAME, all). @@ -407,18 +439,32 @@ agent_info(TargetName, Item) -> {error, not_found} end. -agent_info(Addr, Port, Item) -> - do_agent_info(normalize_address(Addr), Port, Item). +agent_info(Domain, Address, Item) when is_atom(Domain) -> + try fix_address(Domain, Address) of + NAddress -> + do_agent_info(Domain, NAddress, Item) + catch + _ -> + {error, not_found} + end; +agent_info(Ip, Port, Item) -> + try snmp_conf:fix_domain_address(Ip, Port) of + {Domain, Address} -> + do_agent_info(Domain, Address, Item) + catch + _ -> + {error, not_found} + end. -do_agent_info(Addr, Port, target_name = Item) -> - case ets:lookup(snmpm_agent_table, {Addr, Port, Item}) of +do_agent_info(Domain, Address, target_name = Item) -> + case ets:lookup(snmpm_agent_table, {Domain, Address, Item}) of [{_, Val}] -> {ok, Val}; [] -> {error, not_found} end; -do_agent_info(Addr, Port, Item) -> - case do_agent_info(Addr, Port, target_name) of +do_agent_info(Domain, Address, Item) -> + case do_agent_info(Domain, Address, target_name) of {ok, TargetName} -> agent_info(TargetName, Item); Error -> @@ -1672,24 +1718,24 @@ check_agent_config( {UserId, TargetName, Community, Ip, Port, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}) -> - TDomain = default_transport_domain(), + {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), check_agent_config( - UserId, TargetName, Community, TDomain, {Ip, Port}, + UserId, TargetName, Community, Domain, Address, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel); check_agent_config( - {UserId, TargetName, Community, TDomain, Ip, Port, + {UserId, TargetName, Community, Domain, Ip, Port, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}) -> check_agent_config( - UserId, TargetName, Community, TDomain, {Ip, Port}, + UserId, TargetName, Community, Domain, {Ip, Port}, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel); check_agent_config(Agent) -> error({bad_agent_config, Agent}). check_agent_config( - UserId, TargetName, Comm, TDomain, TAddress, + UserId, TargetName, Comm, Domain, Address, EngineId, Timeout, MMS, Version, SecModel, SecName, SecLevel) -> ?vdebug("check_agent_config -> entry with" @@ -1704,8 +1750,8 @@ check_agent_config( %% the property tdomain is needed. Conf = [{reg_type, target_name}, - {tdomain, TDomain}, - {taddress, TAddress}, + {tdomain, Domain}, + {taddress, Address}, {community, Comm}, {engine_id, EngineId}, {timeout, Timeout}, @@ -2842,12 +2888,14 @@ handle_register_agent(UserId, TargetName, Config) -> %% %% And now for some (backward compatibillity) %% dirty crossref stuff - {value, {taddress, {Addr, Port}}} = + {value, {_, Domain}} = + lists:keysearch(tdomain, 1, FixedConfig), + {value, {_, Address}} = lists:keysearch(taddress, 1, FixedConfig), ?vtrace( "handle_register_agent -> register cross-ref fix", []), ets:insert(snmpm_agent_table, - {{Addr, Port, target_name}, TargetName}), + {{Domain, Address, target_name}, TargetName}), %% %% %% First, insert this users default config @@ -2923,8 +2971,9 @@ handle_unregister_agent(UserId, TargetName) -> %% %% And now for some (backward compatibillity) %% dirty crossref stuff - {ok, {Addr, Port}} = agent_info(TargetName, taddress), - ets:delete(snmpm_agent_table, {Addr, Port, target_name}), + {ok, Domain} = agent_info(TargetName, tdomain), + {ok, Address} = agent_info(TargetName, taddress), + ets:delete(snmpm_agent_table, {Domain, Address, target_name}), %% ets:match_delete(snmpm_agent_table, {{TargetName, '_'}, '_'}), ok; @@ -3358,15 +3407,12 @@ init_mini_mib_elems(MibName, [_|T], Res) -> %%---------------------------------------------------------------------- -normalize_address(Addr) -> - try snmp_conf:check_address_no_port(snmpUDPDomain, Addr) of +fix_address(Domain, Address) -> + case snmp_conf:check_address(Domain, Address) of ok -> - Addr; - {ok, NAddr} -> - NAddr - catch - _ -> - Addr + Address; + {ok, NAddress} -> + NAddress end. %%---------------------------------------------------------------------- diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl index fe5ed6b755..27f0336bc1 100644 --- a/lib/snmp/src/manager/snmpm_mpd.erl +++ b/lib/snmp/src/manager/snmpm_mpd.erl @@ -21,7 +21,7 @@ -export([init/1, - process_msg/7, + process_msg/7, process_msg/6, generate_msg/5, generate_response_msg/4, next_msg_id/0, diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index 4d6bd9aa33..39e239f2a2 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -27,9 +27,9 @@ -export([ start_link/2, stop/1, - send_pdu/6, % Backward compatibillity - send_pdu/7, % Backward compatibillity - send_pdu/8, + send_pdu/6, % Backward compatibility + send_pdu/7, % Partly backward compatibility + send_pdu/8, % Backward compatibility inform_response/4, @@ -99,30 +99,31 @@ start_link(Server, NoteStore) -> stop(Pid) -> call(Pid, stop). -send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port) -> - send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ?DEFAULT_EXTRA_INFO). - -send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo) -> +send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort) -> + send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort, ?DEFAULT_EXTRA_INFO). + +send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo) + when is_record(Pdu, pdu), is_atom(Domain) -> + ?d("send_pdu -> entry with~n" + " Pid: ~p~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain: ~p~n" + " Address: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Address]), + cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}); +send_pdu(Pid, Pdu, Vsn, MsgData, Ip, Port, ExtraInfo) -> Domain = snmpm_config:default_transport_domain(), - send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo). - -send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo) - when is_record(Pdu, pdu) -> - ?d("send_pdu -> entry with" - "~n Pid: ~p" - "~n Pdu: ~p" - "~n Vsn: ~p" - "~n MsgData: ~p" - "~n Domain: ~p" - "~n Addr: ~p" - "~n Port: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Addr, Port]), - cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}). + send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). + +send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> + send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). note_store(Pid, NoteStore) -> call(Pid, {note_store, NoteStore}). -inform_response(Pid, Ref, Addr, Port) -> - cast(Pid, {inform_response, Ref, Addr, Port}). +inform_response(Pid, Ref, Domain, Address) -> + cast(Pid, {inform_response, Ref, Domain, Address}). info(Pid) -> call(Pid, info). @@ -386,25 +387,24 @@ handle_call(Req, From, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}, +handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}, State) -> - ?vlog("received send_pdu message with" - "~n Pdu: ~p" - "~n Vsn: ~p" - "~n MsgData: ~p" - "~n Domain: ~p" - "~n Addr: ~p" - "~n Port: ~p", [Pdu, Vsn, MsgData, Domain, Addr, Port]), - maybe_process_extra_info(ExtraInfo), - maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State), + ?vlog("received send_pdu message with~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain: ~p~n" + " Address: ~p", [Pdu, Vsn, MsgData, Domain, Address]), + maybe_process_extra_info(ExtraInfo), + maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State), {noreply, State}; -handle_cast({inform_response, Ref, Addr, Port}, State) -> - ?vlog("received inform_response message with" - "~n Ref: ~p" - "~n Addr: ~p" - "~n Port: ~p", [Ref, Addr, Port]), - handle_inform_response(Ref, Addr, Port, State), +handle_cast({inform_response, Ref, Domain, Address}, State) -> + ?vlog("received inform_response message with~n" + " Ref: ~p~n" + " Domain: ~p~n" + " Address: ~p", [Ref, Domain, Address]), + handle_inform_response(Ref, Domain, Address, State), {noreply, State}; handle_cast(filter_reset, State) -> @@ -425,7 +425,8 @@ handle_cast(Msg, State) -> %%-------------------------------------------------------------------- handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> ?vlog("received ~w bytes from ~p:~p [~w]", [size(Bytes), Ip, Port, Sock]), - maybe_handle_recv_msg(Ip, Port, Bytes, State), + {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + maybe_handle_recv_msg(Domain, Address, Bytes, State), {noreply, State}; handle_info(inform_response_gc, State) -> @@ -531,48 +532,49 @@ code_change(_Vsn, State, _Extra) -> %%% Internal functions %%%------------------------------------------------------------------- -maybe_handle_recv_msg(Addr, Port, Bytes, #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv(Addr, Port)) of +maybe_handle_recv_msg( + Domain, Address, Bytes, #state{filter = FilterMod} = State) -> + case (catch FilterMod:accept_recv(Domain, Address)) of false -> %% Drop the received packet inc(netIfMsgInDrops), ok; _ -> - handle_recv_msg(Addr, Port, Bytes, State) + handle_recv_msg(Domain, Address, Bytes, State) end. -handle_recv_msg(Addr, Port, Bytes, #state{server = Pid}) +handle_recv_msg(Domain, Address, Bytes, #state{server = Pid}) when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> - Pid ! {snmp_error, {empty_message, Addr, Port}, Addr, Port}, + Pid ! {snmp_error, {empty_message, Domain, Address}, Domain, Address}, ok; -handle_recv_msg(Addr, Port, Bytes, - #state{server = Pid, - note_store = NoteStore, - mpd_state = MpdState, - sock = Sock, - log = Log} = State) -> - Domain = snmp_conf:which_domain(Addr), % What the ****... - Logger = logger(Log, read, Addr, Port), - case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, Port, +handle_recv_msg( + Domain, Address, Bytes, + #state{server = Pid, + note_store = NoteStore, + mpd_state = MpdState, + sock = Sock, + log = Log} = State) -> + Logger = logger(Log, read, Domain, Address), + case (catch snmpm_mpd:process_msg(Bytes, Domain, Address, MpdState, NoteStore, Logger)) of {ok, Vsn, Pdu, MS, ACM} -> - maybe_handle_recv_pdu(Addr, Port, Vsn, Pdu, MS, ACM, + maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, MS, ACM, Logger, State); {discarded, Reason, Report} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Addr, Port}, - maybe_udp_send(State#state.filter, Sock, Addr, Port, Report), + Pid ! {snmp_error, ErrorInfo, Domain, Address}, + maybe_udp_send(State#state.filter, Sock, Domain, Address, Report), ok; {discarded, Reason} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Addr, Port}, + Pid ! {snmp_error, ErrorInfo, Domain, Address}, ok; Error -> @@ -582,88 +584,93 @@ handle_recv_msg(Addr, Port, Bytes, end. -maybe_handle_recv_pdu(Addr, Port, - Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, - Logger, - #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv_pdu(Addr, Port, Type)) of +maybe_handle_recv_pdu( + Domain, Address, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, + #state{filter = FilterMod} = State) -> + case (catch FilterMod:accept_recv_pdu(Domain, Address, Type)) of false -> inc(netIfPduInDrops), ok; _ -> - handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State) + handle_recv_pdu( + Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) end; -maybe_handle_recv_pdu(Addr, Port, Vsn, Trap, PduMS, ACM, Logger, - #state{filter = FilterMod} = State) +maybe_handle_recv_pdu( + Domain, Address, Vsn, Trap, PduMS, ACM, Logger, + #state{filter = FilterMod} = State) when is_record(Trap, trappdu) -> - case (catch FilterMod:accept_recv_pdu(Addr, Port, trappdu)) of + case (catch FilterMod:accept_recv_pdu(Domain, Address, trappdu)) of false -> inc(netIfPduInDrops), ok; _ -> - handle_recv_pdu(Addr, Port, Vsn, Trap, PduMS, ACM, Logger, State) + handle_recv_pdu( + Domain, Address, Vsn, Trap, PduMS, ACM, Logger, State) end; -maybe_handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State) -> - handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State). - - -handle_recv_pdu(Addr, Port, - Vsn, #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, - Logger, #state{server = Pid, irb = IRB} = State) -> - handle_inform_request(IRB, Pid, Vsn, Pdu, ACM, - Addr, Port, Logger, State); -handle_recv_pdu(Addr, Port, - _Vsn, #pdu{type = report} = Pdu, _PduMS, ok, - _Logger, - #state{server = Pid} = _State) -> +maybe_handle_recv_pdu( + Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) -> + handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State). + + +handle_recv_pdu( + Domain, Address, Vsn, + #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, Logger, + #state{server = Pid, irb = IRB} = State) -> + handle_inform_request( + IRB, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State); +handle_recv_pdu( + Domain, Address, _Vsn, + #pdu{type = report} = Pdu, _PduMS, ok, _Logger, + #state{server = Pid} = _State) -> ?vtrace("received report - ok", []), - Pid ! {snmp_report, {ok, Pdu}, Addr, Port}; -handle_recv_pdu(Addr, Port, - _Vsn, #pdu{type = report} = Pdu, _PduMS, - {error, ReqId, Reason}, - _Logger, - #state{server = Pid} = _State) -> + Pid ! {snmp_report, {ok, Pdu}, Domain, Address}; +handle_recv_pdu( + Domain, Address, _Vsn, + #pdu{type = report} = Pdu, _PduMS, {error, ReqId, Reason}, _Logger, + #state{server = Pid} = _State) -> ?vtrace("received report - error", []), - Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Addr, Port}; -handle_recv_pdu(Addr, Port, - _Vsn, #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, - _Logger, - #state{server = Pid} = _State) -> + Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Address}; +handle_recv_pdu( + Domain, Address, _Vsn, + #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, _Logger, + #state{server = Pid} = _State) -> ?vtrace("received snmpv2-trap", []), - Pid ! {snmp_trap, Pdu, Addr, Port}; -handle_recv_pdu(Addr, Port, - _Vsn, Trap, _PduMS, _ACM, - _Logger, - #state{server = Pid} = _State) when is_record(Trap, trappdu) -> + Pid ! {snmp_trap, Pdu, Domain, Address}; +handle_recv_pdu( + Domain, Address, _Vsn, Trap, _PduMS, _ACM, _Logger, + #state{server = Pid} = _State) when is_record(Trap, trappdu) -> ?vtrace("received trappdu", []), - Pid ! {snmp_trap, Trap, Addr, Port}; -handle_recv_pdu(Addr, Port, - _Vsn, Pdu, _PduMS, _ACM, - _Logger, - #state{server = Pid} = _State) when is_record(Pdu, pdu) -> + Pid ! {snmp_trap, Trap, Domain, Address}; +handle_recv_pdu( + Domain, Address, _Vsn, Pdu, _PduMS, _ACM, _Logger, + #state{server = Pid} = _State) when is_record(Pdu, pdu) -> ?vtrace("received pdu", []), - Pid ! {snmp_pdu, Pdu, Addr, Port}; -handle_recv_pdu(_Addr, _Port, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> + Pid ! {snmp_pdu, Pdu, Domain, Address}; +handle_recv_pdu( + _Domain, _Address, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> ?vlog("received unexpected pdu: " - "~n Pdu: ~p" - "~n ACM: ~p", [Pdu, ACM]). + "~n Pdu: ~p" + "~n ACM: ~p", [Pdu, ACM]). -handle_inform_request(auto, Pid, Vsn, Pdu, ACM, Addr, Port, Logger, State) -> +handle_inform_request( + auto, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State) -> ?vtrace("received inform-request (true)", []), - Pid ! {snmp_inform, ignore, Pdu, Addr, Port}, + Pid ! {snmp_inform, ignore, Pdu, Domain, Address}, RePdu = make_response_pdu(Pdu), - maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, Logger, State); -handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, - ACM, Addr, Port, _Logger, _State) -> + maybe_send_inform_response( + RePdu, Vsn, ACM, Domain, Address, Logger, State); +handle_inform_request( + {user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, + ACM, Domain, Address, _Logger, _State) -> ?vtrace("received inform-request (false)", []), - Pid ! {snmp_inform, ReqId, Pdu, Addr, Port}, + Pid ! {snmp_inform, ReqId, Pdu, Domain, Address}, %% Before we go any further, we need to check that we have not %% already received this message (possible resend). - Key = {ReqId, Addr, Port}, + Key = {ReqId, Domain, Address}, case ets:lookup(snmpm_inform_request_table, Key) of [_] -> %% OK, we already know about this. We assume this @@ -676,14 +683,14 @@ handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, Rec = {Key, Expire, {Vsn, ACM, RePdu}}, ets:insert(snmpm_inform_request_table, Rec) end. - -handle_inform_response(Ref, Addr, Port, State) -> - Key = {Ref, Addr, Port}, + +handle_inform_response(Ref, Domain, Address, State) -> + Key = {Ref, Domain, Address}, case ets:lookup(snmpm_inform_request_table, Key) of [{Key, _, {Vsn, ACM, RePdu}}] -> - Logger = logger(State#state.log, read, Addr, Port), + Logger = logger(State#state.log, read, Domain, Address), ets:delete(snmpm_inform_request_table, Key), - maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, + maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, State); [] -> %% Already acknowledged, or the user was to slow to reply... @@ -691,24 +698,26 @@ handle_inform_response(Ref, Addr, Port, State) -> end, ok. -maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, Logger, - #state{server = Pid, - sock = Sock, +maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, + #state{server = Pid, + sock = Sock, filter = FilterMod}) -> - case (catch FilterMod:accept_send_pdu(Addr, Port, pdu_type_of(RePdu))) of + case (catch FilterMod:accept_send_pdu( + Domain, Address, pdu_type_of(RePdu))) + of false -> inc(netIfPduOutDrops), ok; _ -> case snmpm_mpd:generate_response_msg(Vsn, RePdu, ACM, Logger) of {ok, Msg} -> - maybe_udp_send(FilterMod, Sock, Addr, Port, Msg); + maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); {discarded, Reason} -> ?vlog("failed generating response message:" "~n Reason: ~p", [Reason]), ReqId = RePdu#pdu.request_id, ErrorInfo = {failed_generating_response, {RePdu, Reason}}, - Pid ! {snmp_error, ReqId, ErrorInfo, Addr, Port}, + Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Address}, ok end end. @@ -743,28 +752,28 @@ irgc_stop(Ref) -> (catch erlang:cancel_timer(Ref)). -maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, +maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_send_pdu(Addr, Port, pdu_type_of(Pdu))) of + case (catch FilterMod:accept_send_pdu(Domain, Address, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), ok; _ -> - handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State) + handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State) end. -handle_send_pdu(Pdu, Vsn, MsgData, _Domain, Addr, Port, +handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, #state{server = Pid, note_store = NoteStore, sock = Sock, log = Log, filter = FilterMod}) -> - Logger = logger(Log, write, Addr, Port), + Logger = logger(Log, write, Domain, Address), case (catch snmpm_mpd:generate_msg(Vsn, NoteStore, Pdu, MsgData, Logger)) of {ok, Msg} -> ?vtrace("handle_send_pdu -> message generated", []), - maybe_udp_send(FilterMod, Sock, Addr, Port, Msg); + maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); {discarded, Reason} -> ?vlog("PDU not sent: " "~n PDU: ~p" @@ -774,28 +783,28 @@ handle_send_pdu(Pdu, Vsn, MsgData, _Domain, Addr, Port, end. -maybe_udp_send(FilterMod, Sock, Addr, Port, Msg) -> - case (catch FilterMod:accept_send(Addr, Port)) of +maybe_udp_send(FilterMod, Sock, Domain, {Ip, Port} = Address, Msg) -> + case (catch FilterMod:accept_send(Domain, Address)) of false -> inc(netIfMsgOutDrops), ok; _ -> - udp_send(Sock, Addr, Port, Msg) + udp_send(Sock, Ip, Port, Msg) end. -udp_send(Sock, Addr, Port, Msg) -> - case (catch gen_udp:send(Sock, Addr, Port, Msg)) of +udp_send(Sock, Ip, Port, Msg) -> + case (catch gen_udp:send(Sock, Ip, Port, Msg)) of ok -> ?vdebug("sent ~w bytes to ~w:~w [~w]", - [sz(Msg), Addr, Port, Sock]), + [sz(Msg), Ip, Port, Sock]), ok; {error, Reason} -> error_msg("failed sending message to ~p:~p: " - "~n ~p",[Addr, Port, Reason]); + "~n ~p",[Ip, Port, Reason]); Error -> error_msg("failed sending message to ~p:~p: " - "~n ~p",[Addr, Port, Error]) + "~n ~p",[Ip, Port, Error]) end. sz(B) when is_binary(B) -> @@ -1029,15 +1038,15 @@ t() -> %% ------------------------------------------------------------------- -logger(undefined, _Type, _Addr, _Port) -> +logger(undefined, _Type, _Domain, _Address) -> fun(_) -> ok end; -logger({Log, Types}, Type, Addr, Port) -> +logger({Log, Types}, Type, Domain, Address) -> case lists:member(Type, Types) of true -> fun(Msg) -> - snmp_log:log(Log, Msg, Addr, Port) + snmp_log:log(Log, Msg, Domain, Address) end; false -> fun(_) -> diff --git a/lib/snmp/src/manager/snmpm_net_if_filter.erl b/lib/snmp/src/manager/snmpm_net_if_filter.erl index eb0c6efb11..54b87a772a 100644 --- a/lib/snmp/src/manager/snmpm_net_if_filter.erl +++ b/lib/snmp/src/manager/snmpm_net_if_filter.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009. All Rights Reserved. +%% Copyright Ericsson AB 2009-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -25,29 +25,51 @@ -include("snmp_debug.hrl"). +accept_recv(Domain, _Address) when is_atom(Domain) -> + ?d("accept_recv -> entry with~n" + " Domain: ~p~n" + " Address: ~p", [Domain, _Address]), + true; accept_recv(_Addr, _Port) -> - ?d("accept_recv -> entry with" - "~n Addr: ~p" - "~n Port: ~p", [_Addr, _Port]), + ?d("accept_recv -> entry with~n" + " Addr: ~p~n" + " Port: ~p", [_Addr, _Port]), true. +accept_send(Domain, _Address) when is_atom(Domain) -> + ?d("accept_send -> entry with~n" + " Domain: ~p~n" + " Address: ~p", [Domain, _Address]), + true; accept_send(_Addr, _Port) -> - ?d("accept_send -> entry with" - "~n Addr: ~p" - "~n Port: ~p", [_Addr, _Port]), + ?d("accept_send -> entry with~n" + " Addr: ~p~n" + " Port: ~p", [_Addr, _Port]), true. +accept_recv_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> + ?d("accept_recv_pdu -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " PduType: ~p", [Domain, _Address, _PduType]), + true; accept_recv_pdu(_Addr, _Port, _PduType) -> - ?d("accept_recv_pdu -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n PduType: ~p", [_Addr, _Port, _PduType]), + ?d("accept_recv_pdu -> entry with~n" + " Addr: ~p~n" + " Port: ~p~n" + " PduType: ~p", [_Addr, _Port, _PduType]), true. +accept_send_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> + ?d("accept_send_pdu -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " PduType: ~p", [Domain, _Address, _PduType]), + true; accept_send_pdu(_Addr, _Port, _PduType) -> - ?d("accept_send_pdu -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n PduType: ~p", [_Addr, _Port, _PduType]), + ?d("accept_send_pdu -> entry with~n" + " Addr: ~p~n" + " Port: ~p~n" + " PduType: ~p", [_Addr, _Port, _PduType]), true. diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 3e87f6a7fb..a04cfba2c1 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2012. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -27,9 +27,9 @@ -export([ start_link/2, stop/1, - send_pdu/6, % Backward compatibillity - send_pdu/7, % Backward compatibillity - send_pdu/8, + send_pdu/6, % Backward compatibility + send_pdu/7, % Partly backward compatibility + send_pdu/8, % Backward compatibility inform_response/4, @@ -99,30 +99,31 @@ start_link(Server, NoteStore) -> stop(Pid) -> call(Pid, stop). -send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port) -> - send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ?DEFAULT_EXTRA_INFO). - -send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo) -> +send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort) -> + send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort, ?DEFAULT_EXTRA_INFO). + +send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo) + when is_record(Pdu, pdu), is_atom(Domain) -> + ?d("send_pdu -> entry with~n" + " Pid: ~p~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain: ~p~n" + " Address: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Address]), + cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}); +send_pdu(Pid, Pdu, Vsn, MsgData, Ip, Port, ExtraInfo) -> Domain = snmpm_config:default_transport_domain(), - send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo). - -send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo) - when is_record(Pdu, pdu) -> - ?d("send_pdu -> entry with" - "~n Pid: ~p" - "~n Pdu: ~p" - "~n Vsn: ~p" - "~n MsgData: ~p" - "~n Domain: ~p" - "~n Addr: ~p" - "~n Port: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Addr, Port]), - cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}). + send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo). + +send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> + send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). note_store(Pid, NoteStore) -> call(Pid, {note_store, NoteStore}). -inform_response(Pid, Ref, Addr, Port) -> - cast(Pid, {inform_response, Ref, Addr, Port}). +inform_response(Pid, Ref, Domain, Address) -> + cast(Pid, {inform_response, Ref, Domain, Address}). info(Pid) -> call(Pid, info). @@ -396,25 +397,24 @@ handle_call(Req, From, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo}, +handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}, State) -> - ?vlog("received send_pdu message with" - "~n Pdu: ~p" - "~n Vsn: ~p" - "~n MsgData: ~p" - "~n Domain: ~p" - "~n Addr: ~p" - "~n Port: ~p", [Pdu, Vsn, MsgData, Domain, Addr, Port]), + ?vlog("received send_pdu message with~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain: ~p~n" + " Address: ~p", [Pdu, Vsn, MsgData, Domain, Address]), maybe_process_extra_info(ExtraInfo), - handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State), + handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State), {noreply, State}; -handle_cast({inform_response, Ref, Addr, Port}, State) -> - ?vlog("received inform_response message with" - "~n Ref: ~p" - "~n Addr: ~p" - "~n Port: ~p", [Ref, Addr, Port]), - handle_inform_response(Ref, Addr, Port, State), +handle_cast({inform_response, Ref, Domain, Address}, State) -> + ?vlog("received inform_response message with~n" + " Ref: ~p~n" + " Domain: ~p~n" + " Address: ~p", [Ref, Domain, Address]), + handle_inform_response(Ref, Domain, Address, State), {noreply, State}; handle_cast(filter_reset, State) -> @@ -435,7 +435,8 @@ handle_cast(Msg, State) -> %%-------------------------------------------------------------------- handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> ?vlog("received ~w bytes from ~p:~p", [size(Bytes), Ip, Port]), - handle_udp(Ip, Port, Bytes, State), + {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + handle_udp(Domain, Address, Bytes, State), {noreply, State}; handle_info(inform_response_gc, State) -> @@ -500,60 +501,62 @@ code_change(_Vsn, State, _Extra) -> %%% Internal functions %%%------------------------------------------------------------------- -handle_udp(Addr, Port, Bytes, State) -> +handle_udp(Domain, Address, Bytes, State) -> Verbosity = get(verbosity), spawn_opt(fun() -> Log = worker_init(State, Verbosity), - Res = (catch maybe_handle_recv_msg( - Addr, Port, Bytes, - State#state{log = Log})), - worker_exit(udp, {Addr, Port}, Res) + Res = + (catch maybe_handle_recv_msg( + Domain, Address, Bytes, + State#state{log = Log})), + worker_exit(udp, {Domain, Address}, Res) end, [monitor]). -maybe_handle_recv_msg(Addr, Port, Bytes, #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv(Addr, Port)) of +maybe_handle_recv_msg( + Domain, Address, Bytes, #state{filter = FilterMod} = State) -> + case (catch FilterMod:accept_recv(Domain, Address)) of false -> %% Drop the received packet inc(netIfMsgInDrops), ok; _ -> - handle_recv_msg(Addr, Port, Bytes, State) + handle_recv_msg(Domain, Address, Bytes, State) end. -handle_recv_msg(Addr, Port, Bytes, #state{server = Pid}) +handle_recv_msg(Domain, Address, Bytes, #state{server = Pid}) when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> - Pid ! {snmp_error, {empty_message, Addr, Port}, Addr, Port}, + Pid ! {snmp_error, {empty_message, Domain, Address}, Domain, Address}, ok; -handle_recv_msg(Addr, Port, Bytes, - #state{server = Pid, - note_store = NoteStore, - mpd_state = MpdState, - sock = Sock, - log = Log} = State) -> - Domain = snmp_conf:which_domain(Addr), % What the ****... - Logger = logger(Log, read, Addr, Port), - case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, Port, +handle_recv_msg( + Domain, Address, Bytes, + #state{server = Pid, + note_store = NoteStore, + mpd_state = MpdState, + sock = Sock, + log = Log} = State) -> + Logger = logger(Log, read, Domain, Address), + case (catch snmpm_mpd:process_msg(Bytes, Domain, Address, MpdState, NoteStore, Logger)) of {ok, Vsn, Pdu, MS, ACM} -> - maybe_handle_recv_pdu(Addr, Port, Vsn, Pdu, MS, ACM, + maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, MS, ACM, Logger, State); {discarded, Reason, Report} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Addr, Port}, - maybe_udp_send(State#state.filter, Sock, Addr, Port, Report), + Pid ! {snmp_error, ErrorInfo, Domain, Address}, + maybe_udp_send(State#state.filter, Sock, Domain, Address, Report), ok; {discarded, Reason} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Addr, Port}, + Pid ! {snmp_error, ErrorInfo, Domain, Address}, ok; Error -> @@ -563,94 +566,98 @@ handle_recv_msg(Addr, Port, Bytes, end. -maybe_handle_recv_pdu(Addr, Port, - Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, - Logger, - #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv_pdu(Addr, Port, Type)) of +maybe_handle_recv_pdu( + Domain, Address, Vsn, + #pdu{type = Type} = Pdu, PduMS, ACM, Logger, + #state{filter = FilterMod} = State) -> + case (catch FilterMod:accept_recv_pdu(Domain, Address, Type)) of false -> inc(netIfPduInDrops), ok; _ -> - handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State) + handle_recv_pdu( + Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) end; -maybe_handle_recv_pdu(Addr, Port, Vsn, Trap, PduMS, ACM, Logger, - #state{filter = FilterMod} = State) +maybe_handle_recv_pdu( + Domain, Address, Vsn, Trap, PduMS, ACM, Logger, + #state{filter = FilterMod} = State) when is_record(Trap, trappdu) -> - case (catch FilterMod:accept_recv_pdu(Addr, Port, trappdu)) of + case (catch FilterMod:accept_recv_pdu(Domain, Address, trappdu)) of false -> inc(netIfPduInDrops), ok; _ -> - handle_recv_pdu(Addr, Port, Vsn, Trap, PduMS, ACM, Logger, State) + handle_recv_pdu( + Domain, Address, Vsn, Trap, PduMS, ACM, Logger, State) end; -maybe_handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State) -> - handle_recv_pdu(Addr, Port, Vsn, Pdu, PduMS, ACM, Logger, State). - - -handle_recv_pdu(Addr, Port, - Vsn, #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, - Logger, #state{server = Pid, irb = IRB} = State) -> - handle_inform_request(IRB, Pid, Vsn, Pdu, ACM, - Addr, Port, Logger, State); -handle_recv_pdu(Addr, Port, - _Vsn, #pdu{type = report} = Pdu, _PduMS, ok, - _Logger, - #state{server = Pid} = _State) -> +maybe_handle_recv_pdu( + Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) -> + handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State). + + +handle_recv_pdu( + Domain, Address, Vsn, + #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, Logger, + #state{server = Pid, irb = IRB} = State) -> + handle_inform_request( + IRB, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State); +handle_recv_pdu( + Domain, Address, _Vsn, + #pdu{type = report} = Pdu, _PduMS, ok, _Logger, + #state{server = Pid} = _State) -> ?vtrace("received report - ok", []), - Pid ! {snmp_report, {ok, Pdu}, Addr, Port}, + Pid ! {snmp_report, {ok, Pdu}, Domain, Address}, ok; -handle_recv_pdu(Addr, Port, +handle_recv_pdu(Domain, Address, _Vsn, #pdu{type = report} = Pdu, _PduMS, {error, ReqId, Reason}, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - error", []), - Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Addr, Port}, + Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Address}, ok; -handle_recv_pdu(Addr, Port, - _Vsn, #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, - _Logger, - #state{server = Pid} = _State) -> +handle_recv_pdu( + Domain, Address, _Vsn, + #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, _Logger, + #state{server = Pid} = _State) -> ?vtrace("received snmpv2-trap", []), - Pid ! {snmp_trap, Pdu, Addr, Port}, + Pid ! {snmp_trap, Pdu, Domain, Address}, ok; -handle_recv_pdu(Addr, Port, - _Vsn, Trap, _PduMS, _ACM, - _Logger, - #state{server = Pid} = _State) when is_record(Trap, trappdu) -> +handle_recv_pdu( + Domain, Address, _Vsn, Trap, _PduMS, _ACM, _Logger, + #state{server = Pid} = _State) when is_record(Trap, trappdu) -> ?vtrace("received trappdu", []), - Pid ! {snmp_trap, Trap, Addr, Port}, + Pid ! {snmp_trap, Trap, Domain, Address}, ok; -handle_recv_pdu(Addr, Port, - _Vsn, Pdu, _PduMS, _ACM, - _Logger, - #state{server = Pid} = _State) when is_record(Pdu, pdu) -> +handle_recv_pdu( + Domain, Address, _Vsn, Pdu, _PduMS, _ACM, _Logger, + #state{server = Pid} = _State) when is_record(Pdu, pdu) -> ?vtrace("received pdu", []), - Pid ! {snmp_pdu, Pdu, Addr, Port}, + Pid ! {snmp_pdu, Pdu, Domain, Address}, ok; -handle_recv_pdu(_Addr, _Port, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> +handle_recv_pdu( + _Domain, _Address, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> ?vlog("received unexpected pdu: " "~n Pdu: ~p" "~n ACM: ~p", [Pdu, ACM]), ok. -handle_inform_request(auto, Pid, Vsn, Pdu, ACM, Addr, Port, Logger, State) -> +handle_inform_request(auto, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State) -> ?vtrace("received inform-request (true)", []), - Pid ! {snmp_inform, ignore, Pdu, Addr, Port}, + Pid ! {snmp_inform, ignore, Pdu, Domain, Address}, RePdu = make_response_pdu(Pdu), - maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, Logger, State); + maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, State); handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, - ACM, Addr, Port, _Logger, _State) -> + ACM, Domain, Address, _Logger, _State) -> ?vtrace("received inform-request (false)", []), - Pid ! {snmp_inform, ReqId, Pdu, Addr, Port}, + Pid ! {snmp_inform, ReqId, Pdu, Domain, Address}, %% Before we go any further, we need to check that we have not %% already received this message (possible resend). - Key = {ReqId, Addr, Port}, + Key = {ReqId, Domain, Address}, case ets:lookup(snmpm_inform_request_table, Key) of [_] -> %% OK, we already know about this. We assume this @@ -665,27 +672,27 @@ handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, end, ok. -handle_inform_response(Ref, Addr, Port, State) -> +handle_inform_response(Ref, Domain, Address, State) -> Verbosity = get(verbosity), spawn_opt(fun() -> Log = worker_init(State, Verbosity), Res = (catch do_handle_inform_response( Ref, - Addr, Port, + Domain, Address, State#state{log = Log})), - worker_exit(inform_reponse, {Addr, Port}, Res) + worker_exit(inform_response, {Domain, Address}, Res) end, [monitor]). -do_handle_inform_response(Ref, Addr, Port, State) -> - Key = {Ref, Addr, Port}, +do_handle_inform_response(Ref, Domain, Address, State) -> + Key = {Ref, Domain, Address}, case ets:lookup(snmpm_inform_request_table, Key) of [{Key, _, {Vsn, ACM, RePdu}}] -> - Logger = logger(State#state.log, read, Addr, Port), + Logger = logger(State#state.log, read, Domain, Address), ets:delete(snmpm_inform_request_table, Key), - maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, + maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, State); [] -> %% Already acknowledged, or the user was to slow to reply... @@ -693,24 +700,26 @@ do_handle_inform_response(Ref, Addr, Port, State) -> end, ok. -maybe_send_inform_response(RePdu, Vsn, ACM, Addr, Port, Logger, +maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, #state{server = Pid, sock = Sock, filter = FilterMod}) -> - case (catch FilterMod:accept_send_pdu(Addr, Port, pdu_type_of(RePdu))) of + case (catch FilterMod:accept_send_pdu( + Domain, Address, pdu_type_of(RePdu))) + of false -> inc(netIfPduOutDrops), ok; _ -> case snmpm_mpd:generate_response_msg(Vsn, RePdu, ACM, Logger) of {ok, Msg} -> - maybe_udp_send(FilterMod, Sock, Addr, Port, Msg); + maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); {discarded, Reason} -> ?vlog("failed generating response message:" "~n Reason: ~p", [Reason]), ReqId = RePdu#pdu.request_id, ErrorInfo = {failed_generating_response, {RePdu, Reason}}, - Pid ! {snmp_error, ReqId, ErrorInfo, Addr, Port}, + Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Address}, ok end end. @@ -745,40 +754,40 @@ irgc_stop(Ref) -> (catch erlang:cancel_timer(Ref)). -handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State) -> +handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State) -> Verbosity = get(verbosity), spawn_opt(fun() -> Log = worker_init(State, Verbosity), Res = (catch maybe_handle_send_pdu( Pdu, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, State#state{log = Log})), - worker_exit(send_pdu, {Domain, Addr, Port}, Res) + worker_exit(send_pdu, {Domain, Address}, Res) end, [monitor]). -maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, +maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_send_pdu(Addr, Port, pdu_type_of(Pdu))) of + case (catch FilterMod:accept_send_pdu(Domain, Address, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), ok; _ -> - do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, Port, State) + do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State) end. -do_handle_send_pdu(Pdu, Vsn, MsgData, _Domain, Addr, Port, +do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, #state{server = Pid, note_store = NoteStore, sock = Sock, log = Log, filter = FilterMod}) -> - Logger = logger(Log, write, Addr, Port), + Logger = logger(Log, write, Domain, Address), case (catch snmpm_mpd:generate_msg(Vsn, NoteStore, Pdu, MsgData, Logger)) of {ok, Msg} -> ?vtrace("do_handle_send_pdu -> message generated", []), - maybe_udp_send(FilterMod, Sock, Addr, Port, Msg); + maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); {discarded, Reason} -> ?vlog("PDU not sent: " "~n PDU: ~p" @@ -788,29 +797,29 @@ do_handle_send_pdu(Pdu, Vsn, MsgData, _Domain, Addr, Port, end. -maybe_udp_send(FilterMod, Sock, Addr, Port, Msg) -> - case (catch FilterMod:accept_send(Addr, Port)) of +maybe_udp_send(FilterMod, Sock, Domain, {Ip, Port} = Address, Msg) -> + case (catch FilterMod:accept_send(Domain, Address)) of false -> inc(netIfMsgOutDrops), ok; _ -> - udp_send(Sock, Addr, Port, Msg) + udp_send(Sock, Ip, Port, Msg) end. -udp_send(Sock, Addr, Port, Msg) -> - case (catch gen_udp:send(Sock, Addr, Port, Msg)) of +udp_send(Sock, Ip, Port, Msg) -> + case (catch gen_udp:send(Sock, Ip, Port, Msg)) of ok -> ?vdebug("sent ~w bytes to ~w:~w [~w]", - [sz(Msg), Addr, Port, Sock]), + [sz(Msg), Ip, Port, Sock]), ok; {error, Reason} -> error_msg("failed sending message to ~p:~p: " - "~n ~p",[Addr, Port, Reason]), + "~n ~p", [Ip, Port, Reason]), ok; Error -> error_msg("failed sending message to ~p:~p: " - "~n ~p",[Addr, Port, Error]), + "~n ~p", [Ip, Port, Error]), ok end. @@ -1036,20 +1045,20 @@ worker_exit(Tag, Info, Result) -> handle_worker_exit(_, {_, _, ok}) -> ok; -handle_worker_exit(Pid, {udp, {Addr, Port}, ExitStatus}) -> +handle_worker_exit(Pid, {udp, {Domain, Address}, ExitStatus}) -> warning_msg("Worker process (~p) terminated " "while processing (incomming) message from ~w:~w: " - "~n~p", [Pid, Addr, Port, ExitStatus]), + "~n~p", [Pid, Domain, Address, ExitStatus]), ok; -handle_worker_exit(Pid, {send_pdu, {Domain, Addr, Port}, ExitStatus}) -> +handle_worker_exit(Pid, {send_pdu, {Domain, Address}, ExitStatus}) -> warning_msg("Worker process (~p) terminated " - "while processing (outgoing) pdu for [~w] ~w:~w: " - "~n~p", [Pid, Domain, Addr, Port, ExitStatus]), + "while processing (outgoing) pdu for [~w] ~w: " + "~n~p", [Pid, Domain, Address, ExitStatus]), ok; -handle_worker_exit(Pid, {inform_response, {Addr, Port}, ExitStatus}) -> +handle_worker_exit(Pid, {inform_response, {Domain, Address}, ExitStatus}) -> warning_msg("Worker process (~p) terminated " "while processing (outgoing) inform response for ~w:~w: " - "~n~p", [Pid, Addr, Port, ExitStatus]), + "~n~p", [Pid, Domain, Address, ExitStatus]), ok; handle_worker_exit(_, _) -> ok. @@ -1095,15 +1104,15 @@ t() -> %% ------------------------------------------------------------------- -logger(undefined, _Type, _Addr, _Port) -> +logger(undefined, _Type, _Domain, _Address) -> fun(_) -> ok end; -logger({_Name, Log, Types}, Type, Addr, Port) -> +logger({_Name, Log, Types}, Type, Domain, Address) -> case lists:member(Type, Types) of true -> fun(Msg) -> - snmp_log:log(Log, Msg, Addr, Port) + snmp_log:log(Log, Msg, Domain, Address) end; false -> fun(_) -> @@ -1256,4 +1265,3 @@ call(Pid, Req, Timeout) -> cast(Pid, Msg) -> gen_server:cast(Pid, Msg). - diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index 9c79df2748..b3389ef96c 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -163,8 +163,7 @@ reg_type, target, domain, - addr, - port, + address, type, data, ref, @@ -1033,14 +1032,14 @@ handle_info({snmp_error, Pdu, Reason}, State) -> handle_snmp_error(Pdu, Reason, State), {noreply, State}; -handle_info({snmp_error, Reason, Addr, Port}, State) -> +handle_info({snmp_error, Reason, Domain, Address}, State) -> ?vlog("received snmp_error message", []), - handle_snmp_error(Addr, Port, -1, Reason, State), + handle_snmp_error(Domain, Address, -1, Reason, State), {noreply, State}; -handle_info({snmp_error, ReqId, Reason, Addr, Port}, State) -> +handle_info({snmp_error, ReqId, Reason, Domain, Address}, State) -> ?vlog("received snmp_error message", []), - handle_snmp_error(Addr, Port, ReqId, Reason, State), + handle_snmp_error(Domain, Address, ReqId, Reason, State), {noreply, State}; %% handle_info({snmp_error, ReqId, Pdu, Reason, Addr, Port}, State) -> @@ -1049,30 +1048,30 @@ handle_info({snmp_error, ReqId, Reason, Addr, Port}, State) -> %% {noreply, State}; -handle_info({snmp_pdu, Pdu, Addr, Port}, State) -> +handle_info({snmp_pdu, Pdu, Domain, Address}, State) -> ?vlog("received snmp_pdu message", []), - handle_snmp_pdu(Pdu, Addr, Port, State), + handle_snmp_pdu(Pdu, Domain, Address, State), {noreply, State}; -handle_info({snmp_trap, Trap, Addr, Port}, State) -> +handle_info({snmp_trap, Trap, Domain, Address}, State) -> ?vlog("received snmp_trap message", []), - handle_snmp_trap(Trap, Addr, Port, State), + handle_snmp_trap(Trap, Domain, Address, State), {noreply, State}; -handle_info({snmp_inform, Ref, Pdu, Addr, Port}, State) -> +handle_info({snmp_inform, Ref, Pdu, Domain, Address}, State) -> ?vlog("received snmp_inform message", []), - handle_snmp_inform(Ref, Pdu, Addr, Port, State), + handle_snmp_inform(Ref, Pdu, Domain, Address, State), {noreply, State}; -handle_info({snmp_report, {ok, Pdu}, Addr, Port}, State) -> - handle_snmp_report(Pdu, Addr, Port, State), +handle_info({snmp_report, {ok, Pdu}, Domain, Address}, State) -> + handle_snmp_report(Pdu, Domain, Address, State), {noreply, State}; -handle_info({snmp_report, {error, ReqId, Info, Pdu}, Addr, Port}, State) -> - handle_snmp_report(ReqId, Pdu, Info, Addr, Port, State), +handle_info({snmp_report, {error, ReqId, Info, Pdu}, Domain, Address}, State) -> + handle_snmp_report(ReqId, Pdu, Info, Domain, Address, State), {noreply, State}; @@ -1176,11 +1175,11 @@ handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> "~n From: ~p", [Pid, UserId, TargetName, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> + {ok, RegType, Domain, Address, Vsn, MsgData} -> ?vtrace("handle_sync_get -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_request(Oids, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, Extra, State), ?vdebug("handle_sync_get -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1193,8 +1192,7 @@ handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> reg_type = RegType, target = TargetName, domain = Domain, - addr = Addr, - port = Port, + address = Address, type = get, data = MsgData, ref = Ref, @@ -1230,11 +1228,11 @@ handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, "~n From: ~p", [Pid, UserId, TargetName, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> + {ok, RegType, Domain, Address, Vsn, MsgData} -> ?vtrace("handle_sync_get_next -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_next_request(Oids, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, Extra, State), ?vdebug("handle_sync_get_next -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1247,12 +1245,11 @@ handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, reg_type = RegType, target = TargetName, domain = Domain, - addr = Addr, - port = Port, + address = Address, type = get_next, data = MsgData, ref = Ref, - mon = MonRef, + mon = MonRef, from = From}, ets:insert(snmpm_request_table, Req), ok; @@ -1290,11 +1287,11 @@ handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, "~n From: ~p", [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> + {ok, RegType, Domain, Address, Vsn, MsgData} -> ?vtrace("handle_sync_get_bulk -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_bulk_request(Oids, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, NonRep, MaxRep, Extra, State), ?vdebug("handle_sync_get_bulk -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1307,8 +1304,7 @@ handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, reg_type = RegType, target = TargetName, domain = Domain, - addr = Addr, - port = Port, + address = Address, type = get_bulk, data = MsgData, ref = Ref, @@ -1346,11 +1342,11 @@ handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> "~n From: ~p", [Pid, UserId, TargetName, VarsAndVals, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> + {ok, RegType, Domain, Address, Vsn, MsgData} -> ?vtrace("handle_sync_set -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, Extra, State), ?vdebug("handle_sync_set -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1363,8 +1359,7 @@ handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> reg_type = RegType, target = TargetName, domain = Domain, - addr = Addr, - port = Port, + address = Address, type = set, data = MsgData, ref = Ref, @@ -1400,11 +1395,11 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> + {ok, RegType, Domain, Address, Vsn, MsgData} -> ?vtrace("handle_async_get -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_request(Oids, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, Extra, State), ?vdebug("handle_async_get -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_TIMEOUT(SendOpts), @@ -1413,8 +1408,7 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - addr = Addr, - port = Port, + address = Address, type = get, data = MsgData, expire = t() + Expire}, @@ -1450,11 +1444,11 @@ handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> + {ok, RegType, Domain, Address, Vsn, MsgData} -> ?vtrace("handle_async_get_next -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_next_request(Oids, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, Extra, State), ?vdebug("handle_async_get_next -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_NEXT_TIMEOUT(SendOpts), @@ -1463,8 +1457,7 @@ handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - addr = Addr, - port = Port, + address = Address, type = get_next, data = MsgData, expire = t() + Expire}, @@ -1507,11 +1500,11 @@ handle_async_get_bulk(Pid, "~n SendOpts: ~p", [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> + {ok, RegType, Domain, Address, Vsn, MsgData} -> ?vtrace("handle_async_get_bulk -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_bulk_request(Oids, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, NonRep, MaxRep, Extra, State), ?vdebug("handle_async_get_bulk -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_BULK_TIMEOUT(SendOpts), @@ -1520,8 +1513,7 @@ handle_async_get_bulk(Pid, reg_type = RegType, target = TargetName, domain = Domain, - addr = Addr, - port = Port, + address = Address, type = get_bulk, data = MsgData, expire = t() + Expire}, @@ -1556,11 +1548,11 @@ handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, VarsAndVals, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Addr, Port, Vsn, MsgData} -> + {ok, RegType, Domain, Address, Vsn, MsgData} -> ?vtrace("handle_async_set -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Domain, Addr, Port, + Domain, Address, Extra, State), ?vdebug("handle_async_set -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_SET_TIMEOUT(SendOpts), @@ -1569,8 +1561,7 @@ handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - addr = Addr, - port = Port, + address = Address, type = set, data = MsgData, expire = t() + Expire}, @@ -1808,15 +1799,15 @@ handle_snmp_error(CrapError, Reason, _State) -> "~n~p~n~p", [CrapError, Reason]), ok. -handle_snmp_error(Addr, Port, ReqId, Reason, State) -> +handle_snmp_error(Domain, Address, ReqId, Reason, State) -> - ?vtrace("handle_snmp_error -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n ReqId: ~p" - "~n Reason: ~p", [Addr, Port, ReqId, Reason]), + ?vtrace("handle_snmp_error -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " ReqId: ~p~n" + " Reason: ~p", [Domain, Address, ReqId, Reason]), - case snmpm_config:get_agent_user_id(Addr, Port) of + case snmpm_config:get_agent_user_id(Domain, Address) of {ok, UserId} -> case snmpm_config:user_info(UserId) of {ok, UserMod, UserData} -> @@ -1831,7 +1822,7 @@ handle_snmp_error(Addr, Port, ReqId, Reason, State) -> error_msg("failed retreiving the default user " "info handling snmp error " "<~p,~p>: ~n~w~n~w", - [Addr, Port, ReqId, Reason]) + [Domain, Address, ReqId, Reason]) end end; _Error -> @@ -1843,7 +1834,7 @@ handle_snmp_error(Addr, Port, ReqId, Reason, State) -> error_msg("failed retreiving the default user " "info handling snmp error " "<~p,~p>: ~n~w~n~w", - [Addr, Port, ReqId, Reason]) + [Domain, Address, ReqId, Reason]) end end. @@ -1867,12 +1858,12 @@ handle_error(_UserId, Mod, Reason, ReqId, Data, _State) -> handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, - Addr, Port, State) -> + Domain, Address, State) -> - ?vtrace("handle_snmp_pdu(get-response) -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n Pdu: ~p", [Addr, Port, Pdu]), + ?vtrace("handle_snmp_pdu(get-response) -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " Pdu: ~p", [Domain, Address, Pdu]), case ets:lookup(snmpm_request_table, ReqId) of @@ -1902,9 +1893,10 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, SnmpResponse = {EStatus, EIndex, Varbinds2}, case snmpm_config:user_info(UserId) of {ok, UserMod, UserData} -> - handle_pdu(UserId, UserMod, - RegType, Target, Addr, Port, - ReqId, SnmpResponse, UserData, State), + handle_pdu( + UserId, UserMod, + RegType, Target, Domain, Address, + ReqId, SnmpResponse, UserData, State), maybe_delete(Disco, ReqId); _Error -> %% reply to outstanding request, for which there is no @@ -1912,15 +1904,16 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, %% Therefor send it to the default user case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> - handle_pdu(DefUserId, DefMod, - RegType, Target, Addr, Port, - ReqId, SnmpResponse, DefData, State), + handle_pdu( + DefUserId, DefMod, + RegType, Target, Domain, Address, + ReqId, SnmpResponse, DefData, State), maybe_delete(Disco, ReqId); Error -> error_msg("failed retreiving the default user " "info handling pdu from " "~p <~p,~p>: ~n~w~n~w", - [Target, Addr, Port, Error, Pdu]) + [Target, Domain, Address, Error, Pdu]) end end; @@ -1974,7 +1967,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, varbinds = Varbinds} = Pdu, Varbinds2 = fix_vbs_BITS(Varbinds), SnmpInfo = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_id(Addr, Port) of + case snmpm_config:get_agent_user_id(Domain, Address) of {ok, UserId} -> %% A very late reply or a reply to a request %% that has been cancelled. @@ -1999,7 +1992,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, "user info handling (old) " "pdu from " "<~p,~p>: ~n~w~n~w", - [Addr, Port, Error, Pdu]) + [Domain, Address, Error, Pdu]) end end; @@ -2016,28 +2009,30 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, "no agent info found", []), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> - handle_agent(DefUserId, DefMod, - Addr, Port, - pdu, ignore, - SnmpInfo, DefData, State); + handle_agent( + DefUserId, DefMod, + Domain, Address, + pdu, ignore, + SnmpInfo, DefData, State); Error -> error_msg("failed retreiving the default user " "info handling (old) pdu when no user " "found from " "<~p,~p>: ~n~w~n~w", - [Addr, Port, Error, Pdu]) + [Domain, Address, Error, Pdu]) end end end; -handle_snmp_pdu(CrapPdu, Addr, Port, _State) -> +handle_snmp_pdu(CrapPdu, Domain, Address, _State) -> error_msg("received crap (snmp) Pdu from ~w:~w =>" - "~p", [Addr, Port, CrapPdu]), + "~p", [Domain, Address, CrapPdu]), ok. -handle_pdu(_UserId, Mod, target_name = _RegType, TargetName, _Addr, _Port, - ReqId, SnmpResponse, Data, _State) -> +handle_pdu( + _UserId, Mod, target_name = _RegType, TargetName, _Domain, _Address, + ReqId, SnmpResponse, Data, _State) -> ?vtrace("handle_pdu(target_name) -> entry when" "~n Mod: ~p", [Mod]), F = fun() -> @@ -2053,43 +2048,47 @@ handle_pdu(_UserId, Mod, target_name = _RegType, TargetName, _Addr, _Port, end, handle_callback(F), ok; -handle_pdu(_UserId, Mod, addr_port = _RegType, _TargetName, Addr, Port, - ReqId, SnmpResponse, Data, _State) -> +handle_pdu( + _UserId, Mod, addr_port = _RegType, _TargetName, _Domain, Address, + ReqId, SnmpResponse, Data, _State) -> ?vtrace("handle_pdu(addr_port) -> entry when" "~n Mod: ~p", [Mod]), F = fun() -> - (catch Mod:handle_pdu(Addr, Port, ReqId, SnmpResponse, Data)) + {Ip, Port} = Address, + (catch Mod:handle_pdu(Ip, Port, ReqId, SnmpResponse, Data)) end, handle_callback(F), ok. -handle_agent(UserId, Mod, Addr, Port, Type, Ref, SnmpInfo, Data, State) -> +handle_agent(UserId, Mod, Domain, Address, Type, Ref, SnmpInfo, Data, State) -> ?vtrace("handle_agent -> entry when" "~n UserId: ~p" "~n Type: ~p" "~n Mod: ~p", [UserId, Type, Mod]), F = fun() -> - do_handle_agent(UserId, Mod, Addr, Port, + do_handle_agent(UserId, Mod, Domain, Address, Type, Ref, SnmpInfo, Data, State) end, handle_callback(F), ok. do_handle_agent(DefUserId, DefMod, - Addr, Port, + Domain, Address, Type, Ref, SnmpInfo, DefData, State) -> ?vdebug("do_handle_agent -> entry when" "~n DefUserId: ~p", [DefUserId]), - try DefMod:handle_agent(Addr, Port, Type, SnmpInfo, DefData) of + try DefMod:handle_agent(Domain, Address, Type, SnmpInfo, DefData) of {register, UserId2, TargetName, Config} -> ?vtrace("do_handle_agent -> register: " "~n UserId2: ~p" "~n TargetName: ~p" "~n Config: ~p", [UserId2, TargetName, Config]), - Config2 = ensure_present([{address, Addr}, {port, Port}], Config), + Config2 = + ensure_present( + [{tdomain, Domain}, {taddress, Address}], Config), Config3 = [{reg_type, target_name} | Config2], case snmpm_config:register_agent(UserId2, TargetName, Config3) of @@ -2099,7 +2098,7 @@ do_handle_agent(DefUserId, DefMod, error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Addr, Port, Reason]), + [TargetName, Domain, Address, Reason]), ok end; @@ -2108,31 +2107,33 @@ do_handle_agent(DefUserId, DefMod, ok; InvalidResult -> - CallbackArgs = [Addr, Port, Type, SnmpInfo, DefData], + CallbackArgs = [Domain, Address, Type, SnmpInfo, DefData], handle_invalid_result(handle_agent, CallbackArgs, InvalidResult) catch error:{undef, _} when Type =:= pdu -> %% Maybe, still on the old API ?vdebug("do_handle_agent -> maybe still on the old api", []), - case (catch DefMod:handle_agent(Addr, Port, SnmpInfo, DefData)) of + {Ip, Port} = Address, + case (catch DefMod:handle_agent(Ip, Port, SnmpInfo, DefData)) of {register, UserId2, Config} -> ?vtrace("do_handle_agent -> register: " "~n UserId2: ~p" "~n Config: ~p", [UserId2, Config]), - TargetName = mk_target_name(Addr, Port, Config), - Config2 = [{reg_type, addr_port}, - {address, Addr}, - {port, Port} | Config], - case snmpm_config:register_agent(UserId2, - TargetName, Config2) of + TargetName = mk_target_name(Domain, Address, Config), + Config2 = + ensure_present( + [{tdomain, Domain}, {taddress, Address}], Config), + Config3 = [{reg_type, addr_port} | Config2], + case snmpm_config:register_agent( + UserId2, TargetName, Config3) of ok -> ok; {error, Reason} -> error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Addr, Port, Reason]), + [TargetName, Domain, Address, Reason]), ok end; {register, UserId2, TargetName, Config} -> @@ -2141,18 +2142,19 @@ do_handle_agent(DefUserId, DefMod, "~n TargetName: ~p" "~n Config: ~p", [UserId2, TargetName, Config]), - Config2 = ensure_present([{address, Addr}, {port, Port}], - Config), + Config2 = + ensure_present( + [{tdomain, Domain}, {taddress, Address}], Config), Config3 = [{reg_type, target_name} | Config2], - case snmpm_config:register_agent(UserId2, - TargetName, Config3) of + case snmpm_config:register_agent( + UserId2, TargetName, Config3) of ok -> ok; {error, Reason} -> error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Addr, Port, Reason]), + [TargetName, Domain, Address, Reason]), ok end; _Ignore -> @@ -2170,34 +2172,38 @@ do_handle_agent(DefUserId, DefMod, %% Backward compatibillity crap RegType = target_name, - Target = mk_target_name(Addr, Port, default_agent_config()), + Target = mk_target_name(Domain, Address, default_agent_config()), case Type of report -> SnmpInform = SnmpInfo, - handle_report(DefUserId, DefMod, - RegType, Target, Addr, Port, - SnmpInform, DefData, State); + handle_report( + DefUserId, DefMod, + RegType, Target, Domain, Address, + SnmpInform, DefData, State); inform -> SnmpInform = SnmpInfo, - handle_inform(DefUserId, DefMod, Ref, - RegType, Target, Addr, Port, - SnmpInform, DefData, State); + handle_inform( + DefUserId, DefMod, Ref, + RegType, Target, Domain, Address, + SnmpInform, DefData, State); trap -> SnmpTrapInfo = SnmpInfo, - handle_trap(DefUserId, DefMod, - RegType, Target, Addr, Port, - SnmpTrapInfo, DefData, State); + handle_trap( + DefUserId, DefMod, + RegType, Target, Domain, Address, + SnmpTrapInfo, DefData, State); _ -> - error_msg("failed delivering ~w info to default user - " - "regarding agent " - "<~p,~p>: ~n~w", [Type, Addr, Port, SnmpInfo]) + error_msg( + "failed delivering ~w info to default user - " + "regarding agent " + "<~p,~p>: ~n~w", [Type, Domain, Address, SnmpInfo]) end; T:E -> - CallbackArgs = [Addr, Port, Type, SnmpInfo, DefData], + CallbackArgs = [Domain, Address, Type, SnmpInfo, DefData], handle_invalid_result(handle_agent, CallbackArgs, T, E) end. @@ -2215,50 +2221,51 @@ ensure_present([{Key, _Val} = Elem|Ensure], Config) -> %% Retrieve user info for this agent. %% If this is an unknown agent, then use the default user -handle_snmp_trap(#trappdu{enterprise = Enteprise, - generic_trap = Generic, - specific_trap = Spec, - time_stamp = Timestamp, - varbinds = Varbinds} = Trap, - Addr, Port, State) -> - - ?vtrace("handle_snmp_trap [trappdu] -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n Trap: ~p", [Addr, Port, Trap]), +handle_snmp_trap( + #trappdu{enterprise = Enteprise, + generic_trap = Generic, + specific_trap = Spec, + time_stamp = Timestamp, + varbinds = Varbinds} = Trap, Domain, Address, State) -> + + ?vtrace("handle_snmp_trap [trappdu] -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " Trap: ~p", [Domain, Address, Trap]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpTrapInfo = {Enteprise, Generic, Spec, Timestamp, Varbinds2}, - do_handle_snmp_trap(SnmpTrapInfo, Addr, Port, State); + do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State); handle_snmp_trap(#pdu{error_status = EStatus, error_index = EIndex, varbinds = Varbinds} = Trap, - Addr, Port, State) -> + Domain, Address, State) -> - ?vtrace("handle_snmp_trap [pdu] -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n Trap: ~p", [Addr, Port, Trap]), + ?vtrace("handle_snmp_trap [pdu] -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " Trap: ~p", [Domain, Address, Trap]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpTrapInfo = {EStatus, EIndex, Varbinds2}, - do_handle_snmp_trap(SnmpTrapInfo, Addr, Port, State); + do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State); -handle_snmp_trap(CrapTrap, Addr, Port, _State) -> +handle_snmp_trap(CrapTrap, Domain, Address, _State) -> error_msg("received crap (snmp) trap from ~w:~w =>" - "~p", [Addr, Port, CrapTrap]), + "~p", [Domain, Address, CrapTrap]), ok. -do_handle_snmp_trap(SnmpTrapInfo, Addr, Port, State) -> - case snmpm_config:get_agent_user_info(Addr, Port) of +do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> + case snmpm_config:get_agent_user_info(Domain, Address) of {ok, UserId, Target, RegType} -> ?vtrace("handle_snmp_trap -> found user: ~p", [UserId]), case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> - handle_trap(UserId, Mod, - RegType, Target, Addr, Port, - SnmpTrapInfo, Data, State); + handle_trap( + UserId, Mod, + RegType, Target, Domain, Address, + SnmpTrapInfo, Data, State); Error1 -> %% User no longer exists, unregister agent @@ -2270,66 +2277,72 @@ do_handle_snmp_trap(SnmpTrapInfo, Addr, Port, State) -> %% Try use the default user case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> - handle_agent(DefUserId, DefMod, - Addr, Port, - trap, ignore, - SnmpTrapInfo, DefData, State); + handle_agent( + DefUserId, DefMod, + Domain, Address, + trap, ignore, + SnmpTrapInfo, DefData, State); Error2 -> - error_msg("failed retreiving the default " - "user info handling report from " - "~p <~p,~p>: ~n~w~n~w", - [Target, Addr, Port, - Error2, SnmpTrapInfo]) + error_msg( + "failed retreiving the default " + "user info handling report from " + "~p <~p,~p>: ~n~w~n~w", + [Target, Domain, Address, + Error2, SnmpTrapInfo]) end; Error3 -> %% Failed unregister agent, %% now its getting messy... - warning_msg("failed unregister agent ~p <~p,~p> " - "belonging to non-existing " - "user ~p, handling trap: " - "~n Error: ~w" - "~n Trap info: ~w", - [Target, Addr, Port, UserId, - Error3, SnmpTrapInfo]) + warning_msg( + "failed unregister agent ~p <~p,~p> " + "belonging to non-existing " + "user ~p, handling trap: " + "~n Error: ~w" + "~n Trap info: ~w", + [Target, Domain, Address, UserId, + Error3, SnmpTrapInfo]) end end; Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[trap] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Addr, Port, Error4]), + "~n ~p", [Domain, Address, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> - handle_agent(DefUserId, DefMod, - Addr, Port, - trap, ignore, - SnmpTrapInfo, DefData, State); + handle_agent( + DefUserId, DefMod, + Domain, Address, + trap, ignore, + SnmpTrapInfo, DefData, State); Error5 -> - error_msg("failed retreiving " - "the default user info handling trap from " - "<~p,~p>: ~n~w~n~w", - [Addr, Port, Error5, SnmpTrapInfo]) + error_msg( + "failed retreiving " + "the default user info handling trap from " + "<~p,~p>: ~n~w~n~w", + [Domain, Address, Error5, SnmpTrapInfo]) end end, ok. -handle_trap(UserId, Mod, - RegType, Target, Addr, Port, SnmpTrapInfo, Data, State) -> +handle_trap( + UserId, Mod, RegType, Target, Domain, Address, SnmpTrapInfo, Data, State) -> ?vtrace("handle_trap -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> - do_handle_trap(UserId, Mod, - RegType, Target, Addr, Port, - SnmpTrapInfo, Data, State) + do_handle_trap( + UserId, Mod, + RegType, Target, Domain, Address, + SnmpTrapInfo, Data, State) end, handle_callback(F), ok. -do_handle_trap(UserId, Mod, - RegType, Target, Addr, Port, SnmpTrapInfo, Data, _State) -> +do_handle_trap( + UserId, Mod, RegType, Target, Domain, Address, SnmpTrapInfo, Data, _State) -> ?vdebug("do_handle_trap -> entry with" "~n UserId: ~p", [UserId]), {HandleTrap, CallbackArgs} = @@ -2338,8 +2351,9 @@ do_handle_trap(UserId, Mod, {fun() -> Mod:handle_trap(Target, SnmpTrapInfo, Data) end, [Target, SnmpTrapInfo, Data]}; addr_port -> - {fun() -> Mod:handle_trap(Addr, Port, SnmpTrapInfo, Data) end, - [Addr, Port, SnmpTrapInfo, Data]} + {Ip, Port} = Address, + {fun() -> Mod:handle_trap(Ip, Port, SnmpTrapInfo, Data) end, + [Ip, Port, SnmpTrapInfo, Data]} end, try HandleTrap() of @@ -2347,9 +2361,10 @@ do_handle_trap(UserId, Mod, ?vtrace("do_handle_trap -> register: " "~n UserId2: ~p" "~n Config: ~p", [UserId2, Config]), - Target2 = mk_target_name(Addr, Port, Config), - Config2 = [{reg_type, target_name}, - {address, Addr}, {port, Port} | Config], + Target2 = mk_target_name(Domain, Address, Config), + Config2 = + [{reg_type, target_name}, + {tdomain, Domain}, {taddress, Address} | Config], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> ok; @@ -2357,7 +2372,7 @@ do_handle_trap(UserId, Mod, error_msg("failed registering agent " "handling trap " "<~p,~p>: ~n~w", - [Addr, Port, Reason]), + [Domain, Address, Reason]), ok end; {register, UserId2, Target2, Config} -> @@ -2375,20 +2390,19 @@ do_handle_trap(UserId, Mod, error_msg("failed registering agent " "handling trap " "~p <~p,~p>: ~n~w", - [Target2, Addr, Port, Reason]), + [Target2, Domain, Address, Reason]), reply end; unregister -> ?vtrace("do_handle_trap -> unregister", []), - case snmpm_config:unregister_agent(UserId, - Addr, Port) of + case snmpm_config:unregister_agent(UserId, Domain, Address) of ok -> ok; {error, Reason} -> error_msg("failed unregistering agent " "handling trap " "<~p,~p>: ~n~w", - [Addr, Port, Reason]), + [Domain, Address, Reason]), ok end; ignore -> @@ -2405,28 +2419,30 @@ do_handle_trap(UserId, Mod, end. -handle_snmp_inform(Ref, - #pdu{error_status = EStatus, - error_index = EIndex, - varbinds = Varbinds} = Pdu, Addr, Port, State) -> +handle_snmp_inform( + Ref, + #pdu{error_status = EStatus, + error_index = EIndex, + varbinds = Varbinds} = Pdu, Domain, Address, State) -> - ?vtrace("handle_snmp_inform -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n Pdu: ~p", [Addr, Port, Pdu]), + ?vtrace("handle_snmp_inform -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " Pdu: ~p", [Domain, Address, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpInform = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_info(Addr, Port) of + case snmpm_config:get_agent_user_info(Domain, Address) of {ok, UserId, Target, RegType} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> ?vdebug("[inform] callback handle_inform with: " "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), - handle_inform(UserId, Mod, Ref, - RegType, Target, Addr, Port, - SnmpInform, Data, State); + handle_inform( + UserId, Mod, Ref, + RegType, Target, Domain, Address, + SnmpInform, Data, State); Error1 -> %% User no longer exists, unregister agent case snmpm_config:unregister_agent(UserId, Target) of @@ -2437,15 +2453,16 @@ handle_snmp_inform(Ref, "~n ~p", [UserId, Error1]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> - handle_agent(DefUserId, DefMod, - Addr, Port, - inform, Ref, - SnmpInform, DefData, State); + handle_agent( + DefUserId, DefMod, + Domain, Address, + inform, Ref, + SnmpInform, DefData, State); Error2 -> error_msg("failed retreiving the default " "user info handling inform from " "~p <~p,~p>: ~n~w~n~w", - [Target, Addr, Port, + [Target, Domain, Address, Error2, Pdu]) end; Error3 -> @@ -2456,7 +2473,7 @@ handle_snmp_inform(Ref, "user ~p, handling inform: " "~n Error: ~w" "~n Pdu: ~w", - [Target, Addr, Port, UserId, + [Target, Domain, Address, UserId, Error3, Pdu]) end end; @@ -2464,42 +2481,46 @@ handle_snmp_inform(Ref, Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[inform] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Addr, Port, Error4]), + "~n ~p", [Domain, Address, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> - handle_agent(DefUserId, DefMod, - Addr, Port, - inform, Ref, - SnmpInform, DefData, State); + handle_agent( + DefUserId, DefMod, + Domain, Address, + inform, Ref, + SnmpInform, DefData, State); Error5 -> error_msg("failed retreiving " "the default user info handling inform from " "<~p,~p>: ~n~w~n~w", - [Addr, Port, Error5, Pdu]) + [Domain, Address, Error5, Pdu]) end end, ok; -handle_snmp_inform(_Ref, CrapInform, Addr, Port, _State) -> +handle_snmp_inform(_Ref, CrapInform, Domain, Address, _State) -> error_msg("received crap (snmp) inform from ~w:~w =>" - "~p", [Addr, Port, CrapInform]), + "~p", [Domain, Address, CrapInform]), ok. -handle_inform(UserId, Mod, Ref, - RegType, Target, Addr, Port, SnmpInform, Data, State) -> +handle_inform( + UserId, Mod, Ref, + RegType, Target, Domain, Address, SnmpInform, Data, State) -> ?vtrace("handle_inform -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> - do_handle_inform(UserId, Mod, Ref, - RegType, Target, Addr, Port, SnmpInform, - Data, State) + do_handle_inform( + UserId, Mod, Ref, + RegType, Target, Domain, Address, SnmpInform, + Data, State) end, handle_callback(F), ok. -do_handle_inform(UserId, Mod, Ref, - RegType, Target, Addr, Port, SnmpInform, Data, State) -> +do_handle_inform( + UserId, Mod, Ref, + RegType, Target, Domain, Address, SnmpInform, Data, State) -> ?vdebug("do_handle_inform -> entry with" "~n UserId: ~p", [UserId]), {HandleInform, CallbackArgs} = @@ -2508,8 +2529,9 @@ do_handle_inform(UserId, Mod, Ref, {fun() -> Mod:handle_inform(Target, SnmpInform, Data) end, [Target, SnmpInform, Data]}; addr_port -> - {fun() -> Mod:handle_inform(Addr, Port, SnmpInform, Data) end, - [Addr, Port, SnmpInform, Data]} + {Ip, Port} = Address, + {fun() -> Mod:handle_inform(Ip, Port, SnmpInform, Data) end, + [Ip, Port, SnmpInform, Data]} end, Rep = @@ -2520,9 +2542,11 @@ do_handle_inform(UserId, Mod, Ref, "~n Config: ~p", [UserId2, Config]), %% The only user which would do this is the %% default user - Target2 = mk_target_name(Addr, Port, Config), - Config2 = [{reg_type, target_name}, - {address, Addr}, {port, Port} | Config], + Target2 = mk_target_name(Domain, Address, Config), + Config2 = + [{reg_type, target_name} | + ensure_present( + [{tdomain, Domain}, {taddress, Address}], Config)], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> reply; @@ -2530,7 +2554,7 @@ do_handle_inform(UserId, Mod, Ref, error_msg("failed registering agent " "handling inform " "~p <~p,~p>: ~n~w", - [Target2, Addr, Port, Reason]), + [Target2, Domain, Address, Reason]), reply end; @@ -2549,21 +2573,21 @@ do_handle_inform(UserId, Mod, Ref, error_msg("failed registering agent " "handling inform " "~p <~p,~p>: ~n~w", - [Target2, Addr, Port, Reason]), + [Target2, Domain, Address, Reason]), reply end; unregister -> ?vtrace("do_handle_inform -> unregister", []), - case snmpm_config:unregister_agent(UserId, - Addr, Port) of + case snmpm_config:unregister_agent( + UserId, Domain, Address) of ok -> reply; {error, Reason} -> error_msg("failed unregistering agent " "handling inform " "<~p,~p>: ~n~w", - [Addr, Port, Reason]), + [Domain, Address, Reason]), reply end; @@ -2576,8 +2600,8 @@ do_handle_inform(UserId, Mod, Ref, reply; InvalidResult -> - handle_invalid_result(handle_inform, CallbackArgs, - InvalidResult), + handle_invalid_result( + handle_inform, CallbackArgs, InvalidResult), reply catch @@ -2586,31 +2610,34 @@ do_handle_inform(UserId, Mod, Ref, reply end, - handle_inform_response(Rep, Ref, Addr, Port, State), + handle_inform_response(Rep, Ref, Domain, Address, State), ok. -handle_inform_response(_, ignore, _Addr, _Port, _State) -> +handle_inform_response(_, ignore, _Domain, _Address, _State) -> ignore; -handle_inform_response(no_reply, _Ref, _Addr, _Port, _State) -> +handle_inform_response(no_reply, _Ref, _Domain, _Address, _State) -> no_reply; -handle_inform_response(_, Ref, Addr, Port, - #state{net_if = Pid, net_if_mod = Mod}) -> +handle_inform_response( + _, Ref, Domain, Address, + #state{net_if = Pid, net_if_mod = Mod}) -> ?vdebug("handle_inform -> response", []), - (catch Mod:inform_response(Pid, Ref, Addr, Port)). + (catch Mod:inform_response(Pid, Ref, Domain, Address)). -handle_snmp_report(#pdu{error_status = EStatus, - error_index = EIndex, - varbinds = Varbinds} = Pdu, Addr, Port, State) -> +handle_snmp_report( + #pdu{error_status = EStatus, + error_index = EIndex, + varbinds = Varbinds} = Pdu, + Domain, Address, State) -> - ?vtrace("handle_snmp_report -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n Pdu: ~p", [Addr, Port, Pdu]), + ?vtrace("handle_snmp_report -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " Pdu: ~p", [Domain, Address, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpReport = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_info(Addr, Port) of + case snmpm_config:get_agent_user_info(Domain, Address) of {ok, UserId, Target, RegType} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> @@ -2620,7 +2647,7 @@ handle_snmp_report(#pdu{error_status = EStatus, "~n ~p" "~n ~p", [UserId, Mod, Target, SnmpReport]), handle_report(UserId, Mod, - RegType, Target, Addr, Port, + RegType, Target, Domain, Address, SnmpReport, Data, State); Error1 -> %% User no longer exists, unregister agent @@ -2633,7 +2660,7 @@ handle_snmp_report(#pdu{error_status = EStatus, case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent(DefUserId, DefMod, - Addr, Port, + Domain, Address, report, ignore, SnmpReport, DefData, State); @@ -2641,7 +2668,7 @@ handle_snmp_report(#pdu{error_status = EStatus, error_msg("failed retreiving the default " "user info handling report from " "~p <~p,~p>: ~n~w~n~w", - [Target, Addr, Port, + [Target, Domain, Address, Error2, Pdu]) end; Error3 -> @@ -2652,7 +2679,7 @@ handle_snmp_report(#pdu{error_status = EStatus, "user ~p, handling report: " "~n Error: ~w" "~n Report: ~w", - [Target, Addr, Port, UserId, + [Target, Domain, Address, UserId, Error3, Pdu]) end end; @@ -2660,25 +2687,25 @@ handle_snmp_report(#pdu{error_status = EStatus, Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[report] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Addr, Port, Error4]), + "~n ~p", [Domain, Address, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent(DefUserId, DefMod, - Addr, Port, + Domain, Address, report, ignore, SnmpReport, DefData, State); Error5 -> error_msg("failed retreiving " "the default user info handling report from " "<~p,~p>: ~n~w~n~w", - [Addr, Port, Error5, Pdu]) + [Domain, Address, Error5, Pdu]) end end, ok; -handle_snmp_report(CrapReport, Addr, Port, _State) -> +handle_snmp_report(CrapReport, Domain, Address, _State) -> error_msg("received crap (snmp) report from ~w:~w =>" - "~p", [Addr, Port, CrapReport]), + "~p", [Domain, Address, CrapReport]), ok. %% This could be from a failed get-request, so we might have a user @@ -2686,20 +2713,20 @@ handle_snmp_report(CrapReport, Addr, Port, _State) -> %% get-response (except for tha data which is different). Otherwise, %% we handle it as an error (reported via the handle_error callback %% function). -handle_snmp_report(ReqId, - #pdu{error_status = EStatus, - error_index = EIndex, - varbinds = Varbinds} = Pdu, - {ReportReason, Info} = Rep, - Addr, Port, State) - when is_integer(ReqId) -> - - ?vtrace("handle_snmp_report -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n ReqId: ~p" - "~n Rep: ~p" - "~n Pdu: ~p", [Addr, Port, ReqId, Rep, Pdu]), +handle_snmp_report( + ReqId, + #pdu{error_status = EStatus, + error_index = EIndex, + varbinds = Varbinds} = Pdu, + {ReportReason, Info} = Rep, + Domain, Address, State) when is_integer(ReqId) -> + + ?vtrace("handle_snmp_report -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " ReqId: ~p~n" + " Rep: ~p~n" + " Pdu: ~p", [Domain, Address, ReqId, Rep, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpReport = {EStatus, EIndex, Varbinds2}, @@ -2744,7 +2771,7 @@ handle_snmp_report(ReqId, %% Either not a sync request or no such request. Either %% way, this is error info, so handle it as such. - case snmpm_config:get_agent_user_id(Addr, Port) of + case snmpm_config:get_agent_user_id(Domain, Address) of {ok, UserId} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> @@ -2768,7 +2795,7 @@ handle_snmp_report(ReqId, "default user " "info handling report from " "<~p,~p>: ~n~w~n~w~n~w", - [Addr, Port, Error, + [Domain, Address, Error, ReqId, Reason]) end end; @@ -2776,7 +2803,7 @@ handle_snmp_report(ReqId, %% Unknown agent, pass it on to the default user ?vlog("[report] failed retreiving user id for " "agent <~p,~p>: " - "~n ~p", [Addr, Port, Error]), + "~n ~p", [Domain, Address, Error]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_error(DefUserId, DefMod, Reason, ReqId, @@ -2786,32 +2813,36 @@ handle_snmp_report(ReqId, "the default user info handling " "report from " "<~p,~p>: ~n~w~n~w~n~w", - [Addr, Port, Error, ReqId, Reason]) + [Domain, Address, Error, ReqId, Reason]) end end end, ok; -handle_snmp_report(CrapReqId, CrapReport, CrapInfo, Addr, Port, _State) -> - error_msg("received crap (snmp) report from ~w:~w =>" - "~n~p~n~p~n~p", [Addr, Port, CrapReqId, CrapReport, CrapInfo]), +handle_snmp_report(CrapReqId, CrapReport, CrapInfo, Domain, Address, _State) -> + error_msg( + "received crap (snmp) report from ~w:~w =>" + "~n~p~n~p~n~p", + [Domain, Address, CrapReqId, CrapReport, CrapInfo]), ok. -handle_report(UserId, Mod, RegType, Target, Addr, Port, +handle_report(UserId, Mod, RegType, Target, Domain, Address, SnmpReport, Data, State) -> ?vtrace("handle_report -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> - do_handle_report(UserId, Mod, RegType, Target, Addr, Port, - SnmpReport, Data, State) + do_handle_report( + UserId, Mod, RegType, Target, Domain, Address, + SnmpReport, Data, State) end, handle_callback(F), ok. -do_handle_report(UserId, Mod, - RegType, Target, Addr, Port, SnmpReport, Data, _State) -> +do_handle_report( + UserId, Mod, RegType, Target, Domain, Address, + SnmpReport, Data, _State) -> ?vdebug("do_handle_report -> entry with" "~n UserId: ~p", [UserId]), {HandleReport, CallbackArgs} = @@ -2820,8 +2851,9 @@ do_handle_report(UserId, Mod, {fun() -> Mod:handle_report(Target, SnmpReport, Data) end, [Target, SnmpReport, Data]}; addr_port -> - {fun() -> Mod:handle_report(Addr, Port, SnmpReport, Data) end, - [Addr, Port, SnmpReport, Data]} + {Ip, Port} = Address, + {fun() -> Mod:handle_report(Ip, Port, SnmpReport, Data) end, + [Ip, Port, SnmpReport, Data]} end, try HandleReport() of @@ -2831,17 +2863,18 @@ do_handle_report(UserId, Mod, "~n Config: ~p", [UserId2, Config]), %% The only user which would do this is the %% default user - Target2 = mk_target_name(Addr, Port, Config), - Config2 = [{reg_type, target_name}, - {address, Addr}, {port, Port} | Config], + Target2 = mk_target_name(Domain, Address, Config), + Config2 = + [{reg_type, target_name}, + {tdomain, Domain}, {taddress, Address} | Config], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> ok; {error, Reason} -> error_msg("failed registering agent " "handling report " - "<~p,~p>: ~n~w", - [Addr, Port, Reason]), + "<~p,~p>: ~n~w", + [Domain, Address, Reason]), ok end; @@ -2860,21 +2893,20 @@ do_handle_report(UserId, Mod, error_msg("failed registering agent " "handling report " "~p <~p,~p>: ~n~w", - [Target2, Addr, Port, Reason]), + [Target2, Domain, Address, Reason]), reply end; unregister -> ?vtrace("do_handle_trap -> unregister", []), - case snmpm_config:unregister_agent(UserId, - Addr, Port) of + case snmpm_config:unregister_agent(UserId, Domain, Address) of ok -> ok; {error, Reason} -> error_msg("failed unregistering agent " "handling report " "<~p,~p>: ~n~w", - [Addr, Port, Reason]), + [Domain, Address, Reason]), ok end; @@ -3012,50 +3044,49 @@ do_gc(Key, Now) -> %% %%---------------------------------------------------------------------- -send_get_request(Oids, Vsn, MsgData, Domain, Addr, Port, ExtraInfo, +send_get_request(Oids, Vsn, MsgData, Domain, Address, ExtraInfo, #state{net_if = NetIf, net_if_mod = Mod, mini_mib = MiniMIB}) -> Pdu = make_pdu(get, Oids, MiniMIB), - ?vtrace("send_get_request -> send get-request:" - "~n Mod: ~p" - "~n NetIf: ~p" - "~n Pdu: ~p" - "~n Vsn: ~p" - "~n MsgData: ~p" - "~n Domain: ~p" - "~n Addr: ~p" - "~n Port: ~p", - [Mod, NetIf, Pdu, Vsn, MsgData, Domain, Addr, Port]), + ?vtrace("send_get_request -> send get-request:~n" + " Mod: ~p~n" + " NetIf: ~p~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain: ~p~n" + " Address: ~p~n", + [Mod, NetIf, Pdu, Vsn, MsgData, Domain, Address]), Res = (catch Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, - Domain, Addr, Port, ExtraInfo)), + Domain, Address, ExtraInfo)), ?vtrace("send_get_request -> send result:" "~n ~p", [Res]), Pdu#pdu.request_id. -send_get_next_request(Oids, Vsn, MsgData, Domain, Addr, Port, ExtraInfo, +send_get_next_request(Oids, Vsn, MsgData, Domain, Address, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(get_next, Oids, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo), Pdu#pdu.request_id. -send_get_bulk_request(Oids, Vsn, MsgData, Domain, Addr, Port, +send_get_bulk_request(Oids, Vsn, MsgData, Domain, Address, NonRep, MaxRep, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(bulk, {NonRep, MaxRep, Oids}, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo), Pdu#pdu.request_id. -send_set_request(VarsAndVals, Vsn, MsgData, Domain, Addr, Port, ExtraInfo, +send_set_request(VarsAndVals, Vsn, MsgData, Domain, Address, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(set, VarsAndVals, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, Port, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo), Pdu#pdu.request_id. %% send_discovery(Vsn, MsgData, Addr, Port, ExtraInfo, @@ -3291,10 +3322,9 @@ agent_data(TargetName, SendOpts) -> {Comm, SecModel} end, Domain = agent_data_item(tdomain, TargetName), - Addr = agent_data_item(address, TargetName), - Port = agent_data_item(port, TargetName), + Address = agent_data_item(taddress, TargetName), RegType = agent_data_item(reg_type, TargetName), - {ok, RegType, Domain, Addr, Port, version(Version), MsgData}; + {ok, RegType, Domain, Address, version(Version), MsgData}; Error -> Error end. @@ -3440,9 +3470,9 @@ maybe_demonitor(MonRef) -> t() -> {A,B,C} = erlang:now(), A*1000000000+B*1000+(C div 1000). - -mk_target_name(Addr, Port, Config) -> - snmpm_config:mk_target_name(Addr, Port, Config). + +mk_target_name(Domain, Address, Config) -> + snmpm_config:mk_target_name(Domain, Address, Config). default_agent_config() -> case snmpm_config:agent_info() of diff --git a/lib/snmp/src/manager/snmpm_user.erl b/lib/snmp/src/manager/snmpm_user.erl index e6b0b6943e..8e5a874f77 100644 --- a/lib/snmp/src/manager/snmpm_user.erl +++ b/lib/snmp/src/manager/snmpm_user.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -39,20 +39,25 @@ %% *** handle_error *** %% An "asynchronous" error has been detected --callback handle_error(ReqId :: integer(), - Reason :: {unexpected_pdu, SnmpInfo :: snmp_gen_info()} | - {invalid_sec_info, SecInfo :: term(), SnmpInfo :: snmp_gen_info()} | - {empty_message, Addr :: ip_address(), Port :: port_number()} | - term(), - UserData :: term()) -> +-callback handle_error( + ReqId :: integer(), + Reason :: {unexpected_pdu, SnmpInfo :: snmp_gen_info()} | + {invalid_sec_info, + SecInfo :: term(), + SnmpInfo :: snmp_gen_info()} | + {empty_message, + TransportDomain :: atom(), + {Addr :: ip_address(), Port :: port_number()}} | + term(), + UserData :: term()) -> snmp:void(). %% *** handle_agent *** %% A message was received from an unknown agent --callback handle_agent(Addr :: term(), - Port :: pos_integer(), +-callback handle_agent(Domain :: atom(), + Address :: term(), Type :: pdu | trap | inform | report, SnmpInfo :: snmp_gen_info() | snmp_v1_trap_info(), UserData :: term()) -> diff --git a/lib/snmp/src/manager/snmpm_user_default.erl b/lib/snmp/src/manager/snmpm_user_default.erl index 015198cb76..b827713f27 100644 --- a/lib/snmp/src/manager/snmpm_user_default.erl +++ b/lib/snmp/src/manager/snmpm_user_default.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -36,13 +36,13 @@ handle_error(ReqId, Reason, UserData) -> ignore. -handle_agent(Addr, Port, Type, SnmpInfo, UserData) -> - info("received handle_agent:" - "~n Addr: ~p" - "~n Port: ~p" - "~n Type: ~p" - "~n SnmpInfo: ~p" - "~n UserData: ~p", [Addr, Port, Type, SnmpInfo, UserData]), +handle_agent(Domain, Address, Type, SnmpInfo, UserData) -> + info("received handle_agent:~n" + " Domain: ~p~n" + " Address: ~p~n" + " Type: ~p~n" + " SnmpInfo: ~p~n" + " UserData: ~p", [Domain, Address, Type, SnmpInfo, UserData]), ignore. diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index d8a19c7137..105652cdda 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -45,7 +45,8 @@ mk_tdomain/1, which_domain/1, check_ip/1, check_ip/2, - check_address_no_port/2, check_port/1, + check_port/1, + fix_domain_address/2, check_address/2, check_address/3, check_taddress/2, mk_taddress/2, @@ -693,19 +694,25 @@ mk_taddress(BadDomain, _) -> %% --------- -%% XXX remove +%% XXX remove, when net_if handles one socket per transport domain -which_domain([A0,A1,A2,A3]) when ?is_ipv4_addr(A0, A1, A2, A3) -> +which_domain([A0,A1,A2,A3]) + when ?is_ipv4_addr(A0, A1, A2, A3) -> transportDomainUdpIpv4; -which_domain({A0,A1,A2,A3}) when ?is_ipv4_addr(A0, A1, A2, A3) -> +which_domain({A0, A1, A2, A3}) + when ?is_ipv4_addr(A0, A1, A2, A3) -> transportDomainUdpIpv4; which_domain([A0,A1,A2,A3,A4,A5,A6,A7]) when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7) -> transportDomainUdpIpv6; +which_domain([A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15]) + when ?is_ipv6_addr( + A0, A1, A2, A3, A4, A5, A6, A7, + A8, A9, A10, A11, A12, A13, A14, A15) -> + transportDomainUdpIpv6; which_domain({A0, A1, A2, A3, A4, A5, A6, A7}) when ?is_ipv6_addr(A0, A1, A2, A3, A4, A5, A6, A7) -> transportDomainUdpIpv6. - %% --------- @@ -742,34 +749,30 @@ check_ip(BadDomain, _X) -> %% --------- -%% check_address_default_port(Domain, Address) -> -%% case check_address_ip(Domain, Address) of -%% false -> -%% case check_address_ip_port(Domain, Address) of -%% false -> -%% error({bad_address, {Domain, Address}}); -%% _ -> -%% ok -%% end; -%% _ -> -%% ok -%% end. - -check_address_no_port(Domain, Address) -> - case check_address_ip(Domain, Address) of - false -> - error({bad_address, {Domain, Address}}); - true -> - ok; - FixedIP -> - {ok, FixedIP} - end. - check_port(Port) when ?is_word(Port) -> ok; check_port(Port) -> error({bad_port, Port}). +fix_domain_address(IP, Port) when ?is_word(Port) -> + case check_address_ip(transportDomainUdpIpv4, IP) of + false -> + case check_address_ip(transportDomainUdpIpv6, IP) of + false -> + error({bad_address, {transportDomainUdpIpv4, {IP, Port}}}); + true -> + {transportDomainUdpIpv6, {IP, Port}}; + FixedIP -> + {transportDomainUdpIpv6, {FixedIP, Port}} + end; + true -> + {transportDomainUdpIpv4, {IP, Port}}; + FixedIP -> + {transportDomainUdpIpv4, {FixedIP, Port}} + end; +fix_domain_address(IP, Port) -> + error({bad_address, {transportDomainUdpIpv4, {IP, Port}}}). + %% Check a configuration term field from a file to see if it %% can be fixed to be fed to mk_taddress/2. diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 90f9ef2026..52b58ecea8 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -5074,7 +5074,7 @@ inform_swarm_collector(N) -> inform_swarm_collector(N, SentAckCnt, RecvCnt, RespCnt, _) when ((N == SentAckCnt) and (N == RespCnt) and - (N >= RecvCnt)) -> + (N =< RecvCnt)) -> p("inform_swarm_collector -> done when" "~n N: ~w" "~n SentAckCnt: ~w" -- cgit v1.2.3 From 89ca2960d421a43bced0a9f228a62b8ab3089663 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 2 May 2014 16:47:52 +0200 Subject: wip: passes all regression tests --- lib/snmp/src/agent/snmpa_agent.erl | 9 +- lib/snmp/src/agent/snmpa_mpd.erl | 4 +- lib/snmp/src/agent/snmpa_net_if.erl | 336 +++++++++++++---------------- lib/snmp/src/agent/snmpa_net_if_filter.erl | 50 +++-- lib/snmp/test/klas3.erl | 12 +- lib/snmp/test/snmp_agent_test.erl | 8 +- 6 files changed, 205 insertions(+), 214 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index 9bed6e554e..dadd9d7ccd 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -2512,10 +2512,11 @@ handle_mib_of(MibServer, Oid) -> %% Func: process_msg/7 %% Returns: RePdu %%----------------------------------------------------------------- -process_msg(MibView, Vsn, Pdu, PduMS, Community, {Ip, Udp}, ContextName, - GbMaxVBs) -> +process_msg( + MibView, Vsn, Pdu, PduMS, Community, + SourceAddress, ContextName, GbMaxVBs) -> #pdu{request_id = ReqId} = Pdu, - put(snmp_address, {tuple_to_list(Ip), Udp}), + put(snmp_address, SourceAddress), put(snmp_request_id, ReqId), put(snmp_community, Community), put(snmp_context, ContextName), diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index 2db98d9fc2..c189a4eae2 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -1010,7 +1010,7 @@ generate_discovery_msg(NoteStore, {TDomain, TAddress}, InitialUserName, ContextName, Timeout) -> - {ok, {_Domain, Address}} = transform_taddr(TDomain, TAddress), + {ok, {Domain, Address}} = transform_taddr(TDomain, TAddress), %% 7.1.7 ?vdebug("generate_discovery_msg -> 7.1.7 (~w)", [ManagerEngineID]), @@ -1052,7 +1052,7 @@ generate_discovery_msg(NoteStore, {TDomain, TAddress}, %% Log(Packet), inc_snmp_out_vars(Pdu), ?vdebug("generate_discovery_msg -> done", []), - {Packet, Address}; + {Domain, Address, Packet}; Error -> throw(Error) diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 79c85a6e4e..dac172ea11 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -129,7 +129,14 @@ init(Prio, NoteStore, MasterAgent, Parent, Opts) -> case (catch do_init(Prio, NoteStore, MasterAgent, Parent, Opts)) of {ok, State} -> proc_lib:init_ack({ok, self()}), - loop(State); + try loop(State) + catch C:E -> + S = erlang:get_stacktrace(), + error_msg( + "loop/1 EXCEPTION ~w:~w~n" + " ~p", [C,E,S]), + erlang:raise(C, E, S) + end; {error, Reason} -> config_err("failed starting net-if: ~n~p", [Reason]), proc_lib:init_ack({error, Reason}); @@ -252,24 +259,24 @@ create_filter(BadOpts) -> log({_, []}, _, _, _, _) -> ok; -log({Log, Types}, 'set-request', Packet, Addr, Port) -> +log({Log, Types}, 'set-request', Packet, Domain, Address) -> case lists:member(write, Types) of true -> - snmp_log:log(Log, Packet, Addr, Port); + snmp_log:log(Log, Packet, Domain, Address); false -> ok end; -log({Log, Types}, _, Packet, Addr, Port) -> +log({Log, Types}, _, Packet, Domain, Address) -> case lists:member(read, Types) of true -> - snmp_log:log(Log, Packet, Addr, Port); + snmp_log:log(Log, Packet, Domain, Address); false -> ok end; log(_, _, _, _, _) -> ok. - - + + gen_udp_open(Port, Opts) -> case init:get_argument(snmp_fd) of {ok, [[FdStr]]} -> @@ -290,7 +297,8 @@ loop(S) -> receive {udp, _UdpId, Ip, Port, Packet} -> ?vlog("got paket from ~w:~w",[Ip,Port]), - NewS = maybe_handle_recv(S, Ip, Port, Packet), + {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + NewS = maybe_handle_recv(S, Domain, Address, Packet), loop(NewS); {info, ReplyRef, Pid} -> @@ -510,18 +518,18 @@ update_req_counter_outgoing(#state{limit = Limit, rcnt = RCnt} = S, maybe_handle_recv(#state{usock = Sock, filter = FilterMod} = S, - Ip, Port, Packet) -> - case (catch FilterMod:accept_recv(Ip, Port)) of + Domain, Address, Packet) -> + case (catch FilterMod:accept_recv(Domain, Address)) of false -> %% Drop the received packet inc(netIfMsgInDrops), active_once(Sock), S; _ -> - handle_recv(S, Ip, Port, Packet) + handle_recv(S, Domain, Address, Packet) end. -handle_discovery_response(_Ip, _Port, #pdu{request_id = ReqId} = Pdu, +handle_discovery_response(_Domain, _Address, #pdu{request_id = ReqId} = Pdu, ManagerEngineId, #state{usock = Sock, reqs = Reqs} = S) -> case lists:keysearch(ReqId, 1, S#state.reqs) of @@ -538,26 +546,24 @@ handle_discovery_response(_Ip, _Port, #pdu{request_id = ReqId} = Pdu, handle_recv(#state{usock = Sock, mpd_state = MpdState, note_store = NS, - log = Log} = S, Ip, Port, Packet) -> + log = Log} = S, Domain, Address, Packet) -> put(n1, erlang:now()), LogF = fun(Type, Data) -> - log(Log, Type, Data, Ip, Port) + log(Log, Type, Data, Domain, Address) end, - Domain = snmp_conf:which_domain(Ip), % What the ****... - case (catch snmpa_mpd:process_packet(Packet, - Domain, {Ip, Port}, - MpdState, NS, LogF)) of + case (catch snmpa_mpd:process_packet( + Packet, Domain, Address, MpdState, NS, LogF)) of {ok, _Vsn, Pdu, _PduMS, {discovery, ManagerEngineId}} -> - handle_discovery_response(Ip, Port, Pdu, ManagerEngineId, S); + handle_discovery_response(Domain, Address, Pdu, ManagerEngineId, S); {ok, _Vsn, Pdu, _PduMS, discovery} -> - handle_discovery_response(Ip, Port, Pdu, undefined, S); + handle_discovery_response(Domain, Address, Pdu, undefined, S); {ok, Vsn, Pdu, PduMS, ACMData} -> ?vlog("got pdu ~s", [?vapply(snmp_misc, format, [256, "~w", [Pdu]])]), - %% handle_recv_pdu(Ip, Port, Vsn, Pdu, PduMS, ACMData, S); - maybe_handle_recv_pdu(Ip, Port, Vsn, Pdu, PduMS, ACMData, S); + %% handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S); + maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S); {discarded, Reason} -> ?vlog("packet discarded for reason: ~s", @@ -569,12 +575,14 @@ handle_recv(#state{usock = Sock, ?vlog("sending report for reason: " "~n ~s", [?vapply(snmp_misc, format, [256, "~w", [Reason]])]), + {Ip, Port} = Address, (catch udp_send(S#state.usock, Ip, Port, ReportPacket)), active_once(Sock), S; {discovery, ReportPacket} -> ?vlog("sending discovery report", []), + {Ip, Port} = Address, (catch udp_send(S#state.usock, Ip, Port, ReportPacket)), active_once(Sock), S; @@ -586,65 +594,72 @@ handle_recv(#state{usock = Sock, S end. -maybe_handle_recv_pdu(Ip, Port, Vsn, #pdu{type = Type} = Pdu, PduMS, ACMData, - #state{usock = Sock, filter = FilterMod} = S) -> - case (catch FilterMod:accept_recv_pdu(Ip, Port, Type)) of +maybe_handle_recv_pdu( + Domain, Address, Vsn, + #pdu{type = Type} = Pdu, PduMS, ACMData, + #state{usock = Sock, filter = FilterMod} = S) -> + case (catch FilterMod:accept_recv_pdu(Domain, Address, Type)) of false -> inc(netIfPduInDrops), active_once(Sock), ok; _ -> - handle_recv_pdu(Ip, Port, Vsn, Pdu, PduMS, ACMData, S) + handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S) end; -maybe_handle_recv_pdu(Ip, Port, Vsn, Pdu, PduMS, ACMData, S) -> - handle_recv_pdu(Ip, Port, Vsn, Pdu, PduMS, ACMData, S). +maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S) -> + handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S). -handle_recv_pdu(Ip, Port, Vsn, #pdu{type = 'get-response'} = Pdu, - _PduMS, _ACMData, #state{usock = Sock} = S) -> +handle_recv_pdu( + Domain, Address, Vsn, + #pdu{type = 'get-response'} = Pdu, _PduMS, _ACMData, + #state{usock = Sock} = S) -> active_once(Sock), - handle_response(Vsn, Pdu, {Ip, Port}, S), + handle_response(Vsn, Pdu, {Domain, Address}, S), S; -handle_recv_pdu(Ip, Port, Vsn, #pdu{request_id = Rid, type = Type} = Pdu, +handle_recv_pdu(Domain, Address, Vsn, #pdu{request_id = Rid, type = Type} = Pdu, PduMS, ACMData, #state{master_agent = Pid} = S) when ((Type =:= 'get-request') orelse (Type =:= 'get-next-request') orelse (Type =:= 'get-bulk-request')) -> ?vtrace("handle_recv_pdu -> received get (~w)", [Type]), - Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, {Ip, Port}, []}, + SourceAddress = {Domain, Address}, + Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, SourceAddress, []}, update_req_counter_incomming(S, Rid); -handle_recv_pdu(Ip, Port, Vsn, Pdu, PduMS, ACMData, +handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, #state{usock = Sock, master_agent = Pid} = S) -> ?vtrace("handle_recv_pdu -> received other request", []), active_once(Sock), - Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, {Ip, Port}, []}, + SourceAddress = {Domain, Address}, + Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, SourceAddress, []}, S. -maybe_handle_reply_pdu(#state{filter = FilterMod} = S, Vsn, - #pdu{request_id = Rid} = Pdu, - Type, ACMData, {Ip, Port} = Dest) -> +maybe_handle_reply_pdu( + #state{filter = FilterMod} = S, Vsn, + #pdu{request_id = Rid} = Pdu, + Type, ACMData, DestinationAddress) -> S1 = update_req_counter_outgoing(S, Rid), - case (catch FilterMod:accept_send_pdu([{Ip, Port}], Type)) of + case (catch FilterMod:accept_send_pdu([DestinationAddress], Type)) of false -> inc(netIfPduOutDrops), ok; _ -> - handle_reply_pdu(S1, Vsn, Pdu, Type, ACMData, Dest) + handle_reply_pdu(S1, Vsn, Pdu, Type, ACMData, DestinationAddress) end, S1. handle_reply_pdu(#state{log = Log, usock = Sock, filter = FilterMod}, - Vsn, Pdu, Type, ACMData, {Ip, Port}) -> + Vsn, Pdu, Type, ACMData, {Domain, Address}) -> LogF = fun(Type2, Data) -> - log(Log, Type2, Data, Ip, Port) + log(Log, Type2, Data, Domain, Address) end, case (catch snmpa_mpd:generate_response_msg(Vsn, Pdu, Type, ACMData, LogF)) of {ok, Packet} -> ?vinfo("time in agent: ~w mysec", [time_in_agent()]), - maybe_udp_send(FilterMod, Sock, Ip, Port, Packet); + maybe_udp_send(FilterMod, Sock, Domain, Address, Packet); {discarded, Reason} -> ?vlog("handle_reply_pdu -> " "~n reply discarded for reason: ~s", @@ -652,79 +667,68 @@ handle_reply_pdu(#state{log = Log, ok; {'EXIT', Reason} -> user_err("failed generating response message: " - "~nPDU: ~w~n~w", [Pdu, Reason]) + "~nPDU: ~p~n~p", [Pdu, Reason]) end. - -process_taddrs(To) -> - process_taddrs(To, []). -process_taddrs([], Acc) -> - lists:reverse(Acc); -%% v3 -process_taddrs([{{_Domain, AddrAndPort}, _SecData}|T], Acc) -> - process_taddrs(T, [AddrAndPort|Acc]); -%% v1 & v2 -process_taddrs([{_Domain, AddrAndPort}|T], Acc) -> - process_taddrs(T, [AddrAndPort|Acc]). -merge_taddrs(To1, To2) -> - merge_taddrs(To1, To2, []). +maybe_handle_send_pdu( + #state{filter = FilterMod} = S, + Vsn, Pdu, MsgData, To0, From) -> -merge_taddrs([], _To2, Acc) -> - lists:reverse(Acc); -%% v3 -merge_taddrs([{{_, AddrAndPort}, _} = H|To1], To2, Acc) -> - case lists:member(AddrAndPort, To2) of - true -> - merge_taddrs(To1, To2, [H|Acc]); - false -> - merge_taddrs(To1, To2, Acc) - end; -%% v1 & v2 -merge_taddrs([{_, AddrAndPort} = H|To1], To2, Acc) -> - case lists:member(AddrAndPort, To2) of - true -> - merge_taddrs(To1, To2, [H|Acc]); - false -> - merge_taddrs(To1, To2, Acc) - end; -merge_taddrs([_Crap|To1], To2, Acc) -> - merge_taddrs(To1, To2, Acc). - - -maybe_handle_send_pdu(#state{filter = FilterMod} = S, - Vsn, Pdu, MsgData, To0, From) -> + ?vtrace("maybe_handle_send_pdu -> entry with~n" + " FilterMod: ~p~n" + " To0: ~p", [FilterMod, To0]), - ?vtrace("maybe_handle_send_pdu -> entry with" - "~n FilterMod: ~p" - "~n To0: ~p", [FilterMod, To0]), + To = snmpa_mpd:process_taddrs(To0), + Destinations = + [case T of + {{Domain, _Address} = Destination, _SecData} + when is_atom(Domain) -> % v3 + Destination; + {Domain, _Address} = Destination + when is_atom(Domain) -> % v1 & v2 + Destination + end || T <- To], - To1 = snmpa_mpd:process_taddrs(To0), - To2 = process_taddrs(To1), - - case (catch FilterMod:accept_send_pdu(To2, pdu_type_of(Pdu))) of + case (catch FilterMod:accept_send_pdu( + Destinations, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), ok; true -> - handle_send_pdu(S, Vsn, Pdu, MsgData, To1, From); - To3 when is_list(To3) -> - To4 = merge_taddrs(To1, To3), - ?vtrace("maybe_handle_send_pdu -> To4: " - "~n ~p", [To4]), - handle_send_pdu(S, Vsn, Pdu, MsgData, To4, From); - _ -> - handle_send_pdu(S, Vsn, Pdu, MsgData, To1, From) + handle_send_pdu(S, Vsn, Pdu, MsgData, To, From); + FilteredDestinations when is_list(FilteredDestinations) -> + MergedTo = + [T || T <- To, + case T of + {{Dom, _Addr} = Dest, _SData} + when is_atom(Dom) -> % v3 + lists:member( + Dest, FilteredDestinations); + {Dom, _Addr} = Dest + when is_atom(Dom) -> % v1 & v2 + lists:member( + Dest, FilteredDestinations) + end], + ?vtrace("maybe_handle_send_pdu -> MergedTo:~n" + " ~p", [MergedTo]), + handle_send_pdu(S, Vsn, Pdu, MsgData, MergedTo, From); + Other -> + error_msg( + "FilterMod:accept_send_pdu/2 returned: ~p", [Other]), + handle_send_pdu(S, Vsn, Pdu, MsgData, To, From) end. -handle_send_pdu(#state{note_store = NS} = S, Vsn, Pdu, MsgData, To, From) -> +handle_send_pdu( + #state{note_store = NS} = S, Vsn, Pdu, MsgData, To, From) -> - ?vtrace("handle_send_pdu -> entry with" - "~n Pdu: ~p" - "~n To: ~p", [Pdu, To]), + ?vtrace("handle_send_pdu -> entry with~n" + " Pdu: ~p~n" + " To: ~p", [Pdu, To]), - case (catch snmpa_mpd:generate_msg(Vsn, NS, Pdu, MsgData, To)) of + case (catch snmpa_mpd:generate_msg( + Vsn, NS, Pdu, MsgData, To)) of {ok, Addresses} -> handle_send_pdu(S, Pdu, Addresses); {discarded, Reason} -> @@ -733,7 +737,7 @@ handle_send_pdu(#state{note_store = NS} = S, Vsn, Pdu, MsgData, To, From) -> ok; {'EXIT', Reason} -> user_err("failed generating message: " - "~nPDU: ~w~n~w", [Pdu, Reason]), + "~nPDU: ~p~n~p", [Pdu, Reason]), ok end, case From of @@ -742,15 +746,20 @@ handle_send_pdu(#state{note_store = NS} = S, Vsn, Pdu, MsgData, To, From) -> Pid -> ?vtrace("link to ~p and add to request list", [Pid]), link(Pid), - NReqs = snmp_misc:keyreplaceadd(Pid, 2, S#state.reqs, - {Pdu#pdu.request_id, From}), + NReqs = snmp_misc:keyreplaceadd( + Pid, 2, S#state.reqs, {Pdu#pdu.request_id, From}), S#state{reqs = NReqs} end. -handle_send_discovery(#state{note_store = NS} = S, - Pdu, MsgData, - To, From) -> +handle_send_discovery( + #state{note_store = NS, + log = Log, + usock = Sock, + reqs = Reqs} = S, + #pdu{type = Type, + request_id = ReqId} = Pdu, + MsgData, To, From) -> ?vtrace("handle_send_discovery -> entry with" "~n Pdu: ~p" @@ -759,32 +768,24 @@ handle_send_discovery(#state{note_store = NS} = S, "~n From: ~p", [Pdu, MsgData, To, From]), case (catch snmpa_mpd:generate_discovery_msg(NS, Pdu, MsgData, To)) of - {ok, {Packet, {Ip, Port}}} -> - handle_send_discovery(S, Pdu, Packet, Ip, Port, From); + {ok, {Domain, Address, Packet}} -> + log(Log, Type, Packet, Domain, Address), + {Ip, Port} = Address, + udp_send(Sock, Ip, Port, Packet), + ?vtrace("handle_send_discovery -> sent (~w)", [ReqId]), + NReqs = snmp_misc:keyreplaceadd(From, 2, Reqs, {ReqId, From}), + S#state{reqs = NReqs}; {discarded, Reason} -> ?vlog("handle_send_discovery -> " "~n Discovery PDU ~p not sent due to ~p", [Pdu, Reason]), ok; {'EXIT', Reason} -> user_err("failed generating discovery message: " - "~n PDU: ~w" - "~n Reason: ~w", [Pdu, Reason]), + "~n PDU: ~p" + "~n Reason: ~p", [Pdu, Reason]), ok end. -handle_send_discovery(#state{log = Log, - usock = Sock, - reqs = Reqs} = S, - #pdu{type = Type, - request_id = ReqId}, - Packet, Ip, Port, From) - when is_binary(Packet) -> - log(Log, Type, Packet, Ip, Port), - udp_send(Sock, Ip, Port, Packet), - ?vtrace("handle_send_discovery -> sent (~w)", [ReqId]), - NReqs = snmp_misc:keyreplaceadd(From, 2, Reqs, {ReqId, From}), - S#state{reqs = NReqs}. - handle_send_pdu(S, #pdu{type = Type} = Pdu, Addresses) -> handle_send_pdu(S, Type, Pdu, Addresses); @@ -806,61 +807,23 @@ handle_send_pdu(S, Type, Pdu, Addresses) -> handle_send_pdu1(#state{log = Log, usock = Sock, filter = FilterMod}, Type, Addresses) -> - SendFun = - fun({snmpUDPDomain, {Ip, Port}, Packet}) - when is_binary(Packet) -> - ?vdebug("[snmpUDPDomain] sending packet:" - "~n size: ~p" - "~n to: ~p:~p", - [sz(Packet), Ip, Port]), - maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); - - ({snmpUDPDomain, {Ip, Port}, {Packet, _LogData}}) - when is_binary(Packet) -> - ?vdebug("[snmpUDPDomain] sending encrypted packet:" - "~n size: ~p" - "~n to: ~p:~p", - [sz(Packet), Ip, Port]), - maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); - - ({transportDomainUdpIpv4, {Ip, Port}, Packet}) - when is_binary(Packet) -> - ?vdebug("[transportDomainUdpIpv4] sending packet:" - "~n size: ~p" - "~n to: ~p:~p", - [sz(Packet), Ip, Port]), - maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); - - ({transportDomainUdpIpv4, {Ip, Port}, {Packet, _LogData}}) - when is_binary(Packet) -> - ?vdebug("[transportDomainUdpIpv4] sending encrypted packet:" - "~n size: ~p" - "~n to: ~p:~p", - [sz(Packet), Ip, Port]), - maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); - - ({transportDomainUdpIpv6, {Ip, Port}, Packet}) - when is_binary(Packet) -> - ?vdebug("[transportDomainUdpIpv6] sending packet:" - "~n size: ~p" - "~n to: ~p:~p", - [sz(Packet), Ip, Port]), - maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); - - ({transportDomainUdpIpv6, {Ip, Port}, {Packet, _LogData}}) - when is_binary(Packet) -> - ?vdebug("[transportDomainUdpIpv6] sending encrypted packet:" - "~n size: ~p" - "~n to: ~p:~p", - [sz(Packet), Ip, Port]), - maybe_udp_send(FilterMod, Log, Type, Sock, Ip, Port, Packet); - - (_X) -> - ?vlog("** bad res: ~p", [_X]), - ok - end, - lists:foreach(SendFun, Addresses). - + lists:foreach( + fun ({Domain, Address, Packet}) when is_binary(Packet) -> + ?vdebug( + "[~w] sending packet:~n" + " size: ~p~n" + " to: ~p", [Domain, sz(Packet), Address]), + maybe_udp_send( + FilterMod, Log, Type, Sock, Domain, Address, Packet); + ({Domain, Address, {Packet, _LogData}}) when is_binary(Packet) -> + ?vdebug( + "[~w] sending encrypted packet:~n" + " size: ~p~n" + " to: ~p", [Domain, sz(Packet), Address]), + maybe_udp_send( + FilterMod, Log, Type, Sock, Domain, Address, Packet) + end, + Addresses). handle_response(Vsn, Pdu, From, S) -> case lists:keysearch(Pdu#pdu.request_id, 1, S#state.reqs) of @@ -873,26 +836,27 @@ handle_response(Vsn, Pdu, From, S) -> "~n No receiver available for response pdu", []) end. -maybe_udp_send(FilterMod, Sock, Ip, Port, Packet) -> - case (catch FilterMod:accept_send(Ip, Port)) of +maybe_udp_send(FilterMod, Sock, Domain, Address, Packet) -> + case (catch FilterMod:accept_send(Domain, Address)) of false -> inc(netIfMsgOutDrops), ok; _ -> + {Ip, Port} = Address, (catch udp_send(Sock, Ip, Port, Packet)) end. -maybe_udp_send(FilterMod, AtLog, Type, Sock, Ip, Port, Packet) -> - case (catch FilterMod:accept_send(Ip, Port)) of +maybe_udp_send(FilterMod, AtLog, Type, Sock, Domain, Address, Packet) -> + case (catch FilterMod:accept_send(Domain, Address)) of false -> inc(netIfMsgOutDrops), ok; _ -> - log(AtLog, Type, Packet, Ip, Port), + log(AtLog, Type, Packet, Domain, Address), + {Ip, Port} = Address, (catch udp_send(Sock, Ip, Port, Packet)) end. - udp_send(UdpId, AgentIp, UdpPort, B) -> case (catch gen_udp:send(UdpId, AgentIp, UdpPort, B)) of {error, emsgsize} -> diff --git a/lib/snmp/src/agent/snmpa_net_if_filter.erl b/lib/snmp/src/agent/snmpa_net_if_filter.erl index 989f7c95b3..871c4f05da 100644 --- a/lib/snmp/src/agent/snmpa_net_if_filter.erl +++ b/lib/snmp/src/agent/snmpa_net_if_filter.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2009. All Rights Reserved. +%% Copyright Ericsson AB 2007-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -25,28 +25,44 @@ -include("snmp_debug.hrl"). -accept_recv(_Addr, _Port) -> - ?d("accept_recv -> entry with" - "~n Addr: ~p" - "~n Port: ~p", [_Addr, _Port]), +accept_recv(Domain, _Address) when is_atom(Domain) -> + ?d("accept_recv -> entry with~n" + " Domain: ~p~n" + " Address: ~p", [Domain, _Address]), + true; +accept_recv(_Addr, Port) when is_integer(Port) -> + ?d("accept_recv -> entry with~n" + " Addr: ~p~n" + " Port: ~p", [_Addr, Port]), true. -accept_send(_Addr, _Port) -> - ?d("accept_send -> entry with" - "~n Addr: ~p" - "~n Port: ~p", [_Addr, _Port]), +accept_send(Domain, _Address) when is_atom(Domain) -> + ?d("accept_send -> entry with~n" + " Domain: ~p~n" + " Address: ~p", [Domain, _Address]), + true; +accept_send(_Addr, Port) when is_integer(Port) -> + ?d("accept_send -> entry with~n" + " Addr: ~p~n" + " Port: ~p", [_Addr, Port]), true. -accept_recv_pdu(_Addr, _Port, _PduType) -> - ?d("accept_recv_pdu -> entry with" - "~n Addr: ~p" - "~n Port: ~p" - "~n PduType: ~p", [_Addr, _Port, _PduType]), +accept_recv_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> + ?d("accept_recv -> entry with~n" + " Domain: ~p~n" + " Address: ~p~n" + " PduType: ~p", [Domain, _Address, _PduType]), + true; +accept_recv_pdu(_Addr, Port, _PduType) when is_integer(Port) -> + ?d("accept_recv_pdu -> entry with~n" + " Addr: ~p~n" + " Port: ~p~n" + " PduType: ~p", [_Addr, Port, _PduType]), true. accept_send_pdu(_Targets, _PduType) -> - ?d("accept_send_pdu -> entry with" - "~n Targets: ~p" - "~n PduType: ~p", [_Targets, _PduType]), + ?d("accept_send_pdu -> entry with~n" + " Targets: ~p~n" + " PduType: ~p", [_Targets, _PduType]), true. diff --git a/lib/snmp/test/klas3.erl b/lib/snmp/test/klas3.erl index ec78d19dbb..4c7c03e2ca 100644 --- a/lib/snmp/test/klas3.erl +++ b/lib/snmp/test/klas3.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% Copyright Ericsson AB 1997-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -67,8 +67,11 @@ fname(get) -> end, case snmpa:current_address() of {value, {[_A,_B,_C,_D], E}} when is_integer(E) -> ok; - {value, _} -> throw("bad_ip"); - _ -> throw("bad_adr") + {value, {D, _}} when is_atom(D) -> ok; + {value, Ip} -> + throw(format_string("bad_ip: ~p", [Ip])); + Other -> + throw(format_string("bad_adr: ~p", [Other])) end, case snmpa:current_net_if_data() of {value, []} -> ok; @@ -160,3 +163,6 @@ ftab2(get_next, [9], _Cols) -> % bad return value io:format("** Here comes Error Report get_next 3 bad return~n"), [{[1,5],1},{[2,5],3},{[2,6],3}]. + +format_string(Format, Args) -> + lists:flatten(io_lib:format(Format, Args)). diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 2a9f2e842d..bcc89b93de 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2013. All Rights Reserved. +%% Copyright Ericsson AB 2003-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -1794,7 +1794,11 @@ init_v3(Config) when is_list(Config) -> Ip = ?config(ip, Config), ?line ok = config([v3], MgrDir, AgentConfDir, tuple_to_list(Ip), tuple_to_list(Ip)), - [{vsn, v3} | start_v3_agent(Config)]. + Opts = + [{master_agent_verbosity, trace}, + {agent_verbosity, trace}, + {net_if_verbosity, trace}], + [{vsn, v3} | start_v3_agent(Config, Opts)]. finish_v3(Config) when is_list(Config) -> delete_tables(), -- cgit v1.2.3 From 382e91a930b3d20d4e4cce14ea6c3cbc7e4397d7 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 7 May 2014 08:43:07 +0200 Subject: Rewrite agent to use {Domain,Address} tuples as far as possible --- lib/snmp/src/agent/snmpa_mpd.erl | 57 +++-- lib/snmp/src/agent/snmpa_net_if.erl | 262 +++++++++++---------- lib/snmp/src/agent/snmpa_net_if_filter.erl | 25 +- .../src/agent/snmpa_network_interface_filter.erl | 17 +- lib/snmp/src/manager/snmpm_config.erl | 6 +- lib/snmp/src/manager/snmpm_net_if.erl | 2 +- lib/snmp/src/manager/snmpm_net_if_mt.erl | 2 +- lib/snmp/src/misc/snmp_conf.erl | 6 +- 8 files changed, 205 insertions(+), 172 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index c189a4eae2..3caed27c42 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -20,7 +20,7 @@ -export([init/1, reset/0, inc/1, counters/0, discarded_pdu/1, - process_packet/6, process_packet/7, + process_packet/5, process_packet/6, process_packet/7, generate_response_msg/5, generate_response_msg/6, generate_msg/5, generate_msg/6, generate_discovery_msg/4, @@ -113,22 +113,30 @@ reset() -> % length(snmp_pdus:enc_message(M)) + 4. %%----------------------------------------------------------------- -%% Func: process_packet(Packet, TDomain, TAddress, State, Log) -> +%% Func: process_packet(Packet, Domain, Address, State, Log) -> %% {ok, SnmpVsn, Pdu, PduMS, ACMData} | {discarded, Reason} %% Types: Packet = binary() -%% TDomain = snmpUDPDomain | transportDomain() -%% TAddress = {Ip, Udp} (*but* depends on TDomain) +%% Domain = snmpUDPDomain | transportDomain() +%% Address = {Ip, Udp} (*but* depends on Domain) %% State = #state %% Purpose: This is the main Message Dispatching function. (see %% section 4.2.1 in rfc2272) %%----------------------------------------------------------------- -process_packet(Packet, TDomain, TAddress, State, NoteStore, Log) -> +process_packet(Packet, From, State, NoteStore, Log) -> LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, - process_packet(Packet, TDomain, TAddress, LocalEngineID, - State, NoteStore, Log). - -process_packet(Packet, TDomain, TAddress, LocalEngineID, - State, NoteStore, Log) -> + process_packet(Packet, From, LocalEngineID, State, NoteStore, Log). + +process_packet( + Packet, Domain, Address, LocalEngineID, State, NoteStore, Log) -> + From = {Domain, Address}, + process_packet(Packet, From, LocalEngineID, State, NoteStore, Log). + +process_packet(Packet, Domain, Address, State, NoteStore, Log) + when is_atom(Domain) -> + LocalEngineID = ?DEFAULT_LOCAL_ENGINE_ID, + From = {Domain, Address}, + process_packet(Packet, From, LocalEngineID, State, NoteStore, Log); +process_packet(Packet, From, LocalEngineID, State, NoteStore, Log) -> inc(snmpInPkts), case catch snmp_pdus:dec_message_only(binary_to_list(Packet)) of @@ -136,17 +144,17 @@ process_packet(Packet, TDomain, TAddress, LocalEngineID, when State#state.v1 =:= true -> ?vlog("v1, community: ~s", [Community]), HS = ?empty_msg_size + length(Community), - v1_v2c_proc('version-1', NoteStore, Community, - TDomain, TAddress, - LocalEngineID, Data, HS, Log, Packet); + v1_v2c_proc( + 'version-1', NoteStore, Community, From, + LocalEngineID, Data, HS, Log, Packet); #message{version = 'version-2', vsn_hdr = Community, data = Data} when State#state.v2c =:= true -> ?vlog("v2c, community: ~s", [Community]), HS = ?empty_msg_size + length(Community), - v1_v2c_proc('version-2', NoteStore, Community, - TDomain, TAddress, - LocalEngineID, Data, HS, Log, Packet); + v1_v2c_proc( + 'version-2', NoteStore, Community, From, + LocalEngineID, Data, HS, Log, Packet); #message{version = 'version-3', vsn_hdr = V3Hdr, data = Data} when State#state.v3 =:= true -> @@ -154,9 +162,9 @@ process_packet(Packet, TDomain, TAddress, LocalEngineID, [V3Hdr#v3_hdr.msgID, V3Hdr#v3_hdr.msgFlags, V3Hdr#v3_hdr.msgSecurityModel]), - v3_proc(NoteStore, Packet, - TDomain, TAddress, - LocalEngineID, V3Hdr, Data, Log); + v3_proc( + NoteStore, Packet, From, + LocalEngineID, V3Hdr, Data, Log); {'EXIT', {bad_version, Vsn}} -> ?vtrace("exit: bad version: ~p",[Vsn]), @@ -184,7 +192,7 @@ discarded_pdu(Variable) -> inc(Variable). %% Handles a Community based message (v1 or v2c). %%----------------------------------------------------------------- v1_v2c_proc( - Vsn, NoteStore, Community, Domain, Address, + Vsn, NoteStore, Community, {Domain, Address}, LocalEngineID, Data, HS, Log, Packet) -> try snmp_conf:mk_tdomain(Domain) of TDomain -> @@ -263,8 +271,7 @@ sec_model('version-2') -> ?SEC_V2C. %% Handles a SNMPv3 Message, following the procedures in rfc2272, %% section 4.2 and 7.2 %%----------------------------------------------------------------- -v3_proc(NoteStore, Packet, _TDomain, _TAddress, LocalEngineID, - V3Hdr, Data, Log) -> +v3_proc(NoteStore, Packet, _From, LocalEngineID, V3Hdr, Data, Log) -> case (catch v3_proc(NoteStore, Packet, LocalEngineID, V3Hdr, Data, Log)) of {'EXIT', Reason} -> exit(Reason); @@ -1182,6 +1189,9 @@ mk_v1_v2_packet_list([{Domain, Addr} | T], %% Sending from default UDP port inc_snmp_out_vars(Pdu), Entry = {Domain, Addr, Packet}, + %% It would be cleaner to return {To, Packet} to not + %% break the abstraction for an address on the + %% {Domain, Address} format. mk_v1_v2_packet_list(T, Packet, Len, Pdu, [Entry | Acc]). @@ -1288,6 +1298,9 @@ mk_v3_packet_entry(NoteStore, Domain, Addr, req_id = Pdu#pdu.request_id}, snmp_note_store:set_note(NoteStore, 1500, CacheKey, CacheVal), inc_snmp_out_vars(Pdu), + %% It would be cleaner to return {To, Packet} to not + %% break the abstraction for an address on the + %% {Domain, Address} format. {ok, {Domain, Addr, Data}} end. diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index dac172ea11..59d88517c9 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -257,6 +257,9 @@ create_filter(BadOpts) -> throw({error, {bad_filter_opts, BadOpts}}). +log(LogTypes, Req, Packet, {Domain, Address}) -> + log(LogTypes, Req, Packet, Domain, Address). + log({_, []}, _, _, _, _) -> ok; log({Log, Types}, 'set-request', Packet, Domain, Address) -> @@ -297,8 +300,8 @@ loop(S) -> receive {udp, _UdpId, Ip, Port, Packet} -> ?vlog("got paket from ~w:~w",[Ip,Port]), - {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), - NewS = maybe_handle_recv(S, Domain, Address, Packet), + From = snmp_conf:ip_port_to_domaddr(Ip, Port), + NewS = maybe_handle_recv(S, From, Packet), loop(NewS); {info, ReplyRef, Pid} -> @@ -307,47 +310,55 @@ loop(S) -> loop(S); %% response (to get/get_next/get_bulk/set requests) - {snmp_response, Vsn, RePdu, Type, ACMData, Dest, []} -> + {snmp_response, Vsn, RePdu, Type, ACMData, To, []} -> ?vlog("reply pdu: " "~n ~s", [?vapply(snmp_misc, format, [256, "~w", [RePdu]])]), - NewS = maybe_handle_reply_pdu(S, Vsn, RePdu, Type, ACMData, Dest), + NewS = maybe_handle_reply_pdu(S, Vsn, RePdu, Type, ACMData, To), loop(NewS); %% Traps/notification - {send_pdu, Vsn, Pdu, MsgData, To} -> - ?vdebug("send pdu: " - "~n Pdu: ~p" - "~n To: ~p", [Pdu, To]), - NewS = maybe_handle_send_pdu(S, Vsn, Pdu, MsgData, To, undefined), + {send_pdu, Vsn, Pdu, MsgData, TDomAddrs} -> + ?vdebug("send pdu:~n" + " Pdu: ~p~n" + " TDomAddrs: ~p", [Pdu, TDomAddrs]), + NewS = + maybe_handle_send_pdu( + S, Vsn, Pdu, MsgData, TDomAddrs, undefined), loop(NewS); %% We dont use the extra-info at this time, ... - {send_pdu, Vsn, Pdu, MsgData, To, _ExtraInfo} -> - ?vdebug("send pdu: " - "~n Pdu: ~p" - "~n To: ~p", [Pdu, To]), - NewS = maybe_handle_send_pdu(S, Vsn, Pdu, MsgData, To, undefined), + {send_pdu, Vsn, Pdu, MsgData, TDomAddrs, _ExtraInfo} -> + ?vdebug("send pdu:~n" + " Pdu: ~p~n" + " TDomAddrs: ~p", [Pdu, TDomAddrs]), + NewS = + maybe_handle_send_pdu( + S, Vsn, Pdu, MsgData, TDomAddrs, undefined), loop(NewS); %% Informs - {send_pdu_req, Vsn, Pdu, MsgData, To, From} -> - ?vdebug("send pdu request: " - "~n Pdu: ~p" - "~n To: ~p" - "~n From: ~p", - [Pdu, To, toname(From)]), - NewS = maybe_handle_send_pdu(S, Vsn, Pdu, MsgData, To, From), + {send_pdu_req, Vsn, Pdu, MsgData, TDomAddrs, From} -> + ?vdebug("send pdu request:~n" + " Pdu: ~p~n" + " TDomAddrs: ~p~n" + " From: ~p", + [Pdu, TDomAddrs, toname(From)]), + NewS = + maybe_handle_send_pdu( + S, Vsn, Pdu, MsgData, TDomAddrs, From), loop(NewS); %% We dont use the extra-info at this time, ... - {send_pdu_req, Vsn, Pdu, MsgData, To, From, _ExtraInfo} -> - ?vdebug("send pdu request: " - "~n Pdu: ~p" - "~n To: ~p" - "~n From: ~p", - [Pdu, To, toname(From)]), - NewS = maybe_handle_send_pdu(S, Vsn, Pdu, MsgData, To, From), + {send_pdu_req, Vsn, Pdu, MsgData, TDomAddrs, From, _ExtraInfo} -> + ?vdebug("send pdu request:~n" + " Pdu: ~p~n" + " TDomAddrs: ~p~n" + " From: ~p", + [Pdu, TDomAddrs, toname(From)]), + NewS = + maybe_handle_send_pdu( + S, Vsn, Pdu, MsgData, TDomAddrs, From), loop(NewS); %% Discovery Inform @@ -517,19 +528,19 @@ update_req_counter_outgoing(#state{limit = Limit, rcnt = RCnt} = S, S#state{rcnt = NewRCnt}. -maybe_handle_recv(#state{usock = Sock, filter = FilterMod} = S, - Domain, Address, Packet) -> - case (catch FilterMod:accept_recv(Domain, Address)) of +maybe_handle_recv( + #state{usock = Sock, filter = FilterMod} = S, From, Packet) -> + case (catch FilterMod:accept_recv(From)) of false -> %% Drop the received packet inc(netIfMsgInDrops), active_once(Sock), S; _ -> - handle_recv(S, Domain, Address, Packet) + handle_recv(S, From, Packet) end. -handle_discovery_response(_Domain, _Address, #pdu{request_id = ReqId} = Pdu, +handle_discovery_response(_From, #pdu{request_id = ReqId} = Pdu, ManagerEngineId, #state{usock = Sock, reqs = Reqs} = S) -> case lists:keysearch(ReqId, 1, S#state.reqs) of @@ -543,27 +554,29 @@ handle_discovery_response(_Domain, _Address, #pdu{request_id = ReqId} = Pdu, S end. -handle_recv(#state{usock = Sock, - mpd_state = MpdState, - note_store = NS, - log = Log} = S, Domain, Address, Packet) -> +handle_recv( + #state{usock = Sock, + mpd_state = MpdState, + note_store = NS, + log = Log} = S, From, Packet) -> put(n1, erlang:now()), - LogF = fun(Type, Data) -> - log(Log, Type, Data, Domain, Address) - end, + LogF = + fun(Type, Data) -> + log(Log, Type, Data, From) + end, case (catch snmpa_mpd:process_packet( - Packet, Domain, Address, MpdState, NS, LogF)) of + Packet, From, MpdState, NS, LogF)) of {ok, _Vsn, Pdu, _PduMS, {discovery, ManagerEngineId}} -> - handle_discovery_response(Domain, Address, Pdu, ManagerEngineId, S); + handle_discovery_response(From, Pdu, ManagerEngineId, S); {ok, _Vsn, Pdu, _PduMS, discovery} -> - handle_discovery_response(Domain, Address, Pdu, undefined, S); + handle_discovery_response(From, Pdu, undefined, S); {ok, Vsn, Pdu, PduMS, ACMData} -> ?vlog("got pdu ~s", [?vapply(snmp_misc, format, [256, "~w", [Pdu]])]), - %% handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S); - maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S); + %% handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S); + maybe_handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S); {discarded, Reason} -> ?vlog("packet discarded for reason: ~s", @@ -575,14 +588,14 @@ handle_recv(#state{usock = Sock, ?vlog("sending report for reason: " "~n ~s", [?vapply(snmp_misc, format, [256, "~w", [Reason]])]), - {Ip, Port} = Address, + {_Domain, {Ip, Port}} = From, (catch udp_send(S#state.usock, Ip, Port, ReportPacket)), active_once(Sock), S; {discovery, ReportPacket} -> ?vlog("sending discovery report", []), - {Ip, Port} = Address, + {_Domain, {Ip, Port}} = From, (catch udp_send(S#state.usock, Ip, Port, ReportPacket)), active_once(Sock), S; @@ -595,71 +608,67 @@ handle_recv(#state{usock = Sock, end. maybe_handle_recv_pdu( - Domain, Address, Vsn, + From, Vsn, #pdu{type = Type} = Pdu, PduMS, ACMData, #state{usock = Sock, filter = FilterMod} = S) -> - case (catch FilterMod:accept_recv_pdu(Domain, Address, Type)) of + case (catch FilterMod:accept_recv_pdu(From, Type)) of false -> inc(netIfPduInDrops), active_once(Sock), ok; _ -> - handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S) + handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S) end; -maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S) -> - handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, S). +maybe_handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S) -> + handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S). handle_recv_pdu( - Domain, Address, Vsn, + From, Vsn, #pdu{type = 'get-response'} = Pdu, _PduMS, _ACMData, #state{usock = Sock} = S) -> active_once(Sock), - handle_response(Vsn, Pdu, {Domain, Address}, S), + handle_response(Vsn, Pdu, From, S), S; -handle_recv_pdu(Domain, Address, Vsn, #pdu{request_id = Rid, type = Type} = Pdu, +handle_recv_pdu(From, Vsn, #pdu{request_id = Rid, type = Type} = Pdu, PduMS, ACMData, #state{master_agent = Pid} = S) when ((Type =:= 'get-request') orelse (Type =:= 'get-next-request') orelse (Type =:= 'get-bulk-request')) -> ?vtrace("handle_recv_pdu -> received get (~w)", [Type]), - SourceAddress = {Domain, Address}, - Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, SourceAddress, []}, + Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, From, []}, update_req_counter_incomming(S, Rid); -handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACMData, +handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, #state{usock = Sock, master_agent = Pid} = S) -> ?vtrace("handle_recv_pdu -> received other request", []), active_once(Sock), - SourceAddress = {Domain, Address}, - Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, SourceAddress, []}, + Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, From, []}, S. maybe_handle_reply_pdu( #state{filter = FilterMod} = S, Vsn, #pdu{request_id = Rid} = Pdu, - Type, ACMData, DestinationAddress) -> + Type, ACMData, To) -> S1 = update_req_counter_outgoing(S, Rid), - case (catch FilterMod:accept_send_pdu([DestinationAddress], Type)) of + case (catch FilterMod:accept_send_pdu([To], Type)) of false -> inc(netIfPduOutDrops), ok; _ -> - handle_reply_pdu(S1, Vsn, Pdu, Type, ACMData, DestinationAddress) + handle_reply_pdu(S1, Vsn, Pdu, Type, ACMData, To) end, S1. -handle_reply_pdu(#state{log = Log, - usock = Sock, - filter = FilterMod}, - Vsn, Pdu, Type, ACMData, {Domain, Address}) -> - LogF = fun(Type2, Data) -> - log(Log, Type2, Data, Domain, Address) - end, +handle_reply_pdu(#state{log = Log} = S, Vsn, Pdu, Type, ACMData, To) -> + LogF = + fun(Type2, Data) -> + log(Log, Type2, Data, To) + end, case (catch snmpa_mpd:generate_response_msg(Vsn, Pdu, Type, ACMData, LogF)) of {ok, Packet} -> ?vinfo("time in agent: ~w mysec", [time_in_agent()]), - maybe_udp_send(FilterMod, Sock, Domain, Address, Packet); + maybe_udp_send(S, To, Packet); {discarded, Reason} -> ?vlog("handle_reply_pdu -> " "~n reply discarded for reason: ~s", @@ -674,63 +683,63 @@ handle_reply_pdu(#state{log = Log, maybe_handle_send_pdu( #state{filter = FilterMod} = S, - Vsn, Pdu, MsgData, To0, From) -> + Vsn, Pdu, MsgData, TDomAddrSecs, From) -> ?vtrace("maybe_handle_send_pdu -> entry with~n" " FilterMod: ~p~n" - " To0: ~p", [FilterMod, To0]), + " TDomAddrSecs: ~p", [FilterMod, TDomAddrSecs]), - To = snmpa_mpd:process_taddrs(To0), - Destinations = - [case T of - {{Domain, _Address} = Destination, _SecData} + DomAddrSecs = snmpa_mpd:process_taddrs(TDomAddrSecs), + DomAddrs = + [case DAS of + {{Domain, _Address} = DomAddr, _SecData} when is_atom(Domain) -> % v3 - Destination; - {Domain, _Address} = Destination + DomAddr; + {Domain, _Address} = DomAddr when is_atom(Domain) -> % v1 & v2 - Destination - end || T <- To], + DomAddr + end || DAS <- DomAddrSecs], case (catch FilterMod:accept_send_pdu( - Destinations, pdu_type_of(Pdu))) of + DomAddrs, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), ok; true -> - handle_send_pdu(S, Vsn, Pdu, MsgData, To, From); - FilteredDestinations when is_list(FilteredDestinations) -> - MergedTo = - [T || T <- To, - case T of - {{Dom, _Addr} = Dest, _SData} - when is_atom(Dom) -> % v3 + handle_send_pdu(S, Vsn, Pdu, MsgData, DomAddrSecs, From); + FilteredDomAddrs when is_list(FilteredDomAddrs) -> + MergedDomAddrSecs = + [DAS || DAS <- DomAddrSecs, + case DAS of + {{Domain, _Address} = DomAddr, _SData} + when is_atom(Domain) -> % v3 lists:member( - Dest, FilteredDestinations); - {Dom, _Addr} = Dest - when is_atom(Dom) -> % v1 & v2 + DomAddr, FilteredDomAddrs); + {Domain, _Address} = DomAddr + when is_atom(Domain) -> % v1 & v2 lists:member( - Dest, FilteredDestinations) + DomAddr, FilteredDomAddrs) end], - ?vtrace("maybe_handle_send_pdu -> MergedTo:~n" - " ~p", [MergedTo]), - handle_send_pdu(S, Vsn, Pdu, MsgData, MergedTo, From); + ?vtrace("maybe_handle_send_pdu -> MergedDomAddrSecs:~n" + " ~p", [MergedDomAddrSecs]), + handle_send_pdu(S, Vsn, Pdu, MsgData, MergedDomAddrSecs, From); Other -> error_msg( "FilterMod:accept_send_pdu/2 returned: ~p", [Other]), - handle_send_pdu(S, Vsn, Pdu, MsgData, To, From) + handle_send_pdu(S, Vsn, Pdu, MsgData, DomAddrSecs, From) end. handle_send_pdu( - #state{note_store = NS} = S, Vsn, Pdu, MsgData, To, From) -> + #state{note_store = NS} = S, Vsn, Pdu, MsgData, DomAddrSecs, From) -> ?vtrace("handle_send_pdu -> entry with~n" - " Pdu: ~p~n" - " To: ~p", [Pdu, To]), + " Pdu: ~p~n" + " DomAddrSecs: ~p", [Pdu, DomAddrSecs]), case (catch snmpa_mpd:generate_msg( - Vsn, NS, Pdu, MsgData, To)) of + Vsn, NS, Pdu, MsgData, DomAddrSecs)) of {ok, Addresses} -> - handle_send_pdu(S, Pdu, Addresses); + do_handle_send_pdu(S, Pdu, Addresses); {discarded, Reason} -> ?vlog("handle_send_pdu -> " "~n PDU ~p not sent due to ~p", [Pdu, Reason]), @@ -787,13 +796,13 @@ handle_send_discovery( end. -handle_send_pdu(S, #pdu{type = Type} = Pdu, Addresses) -> - handle_send_pdu(S, Type, Pdu, Addresses); -handle_send_pdu(S, Trap, Addresses) -> - handle_send_pdu(S, trappdu, Trap, Addresses). +do_handle_send_pdu(S, #pdu{type = Type} = Pdu, Addresses) -> + do_handle_send_pdu(S, Type, Pdu, Addresses); +do_handle_send_pdu(S, Trap, Addresses) -> + do_handle_send_pdu(S, trappdu, Trap, Addresses). -handle_send_pdu(S, Type, Pdu, Addresses) -> - case (catch handle_send_pdu1(S, Type, Addresses)) of +do_handle_send_pdu(S, Type, Pdu, Addresses) -> + case (catch do_handle_send_pdu1(S, Type, Addresses)) of {Reason, Sz} -> error_msg("Cannot send message " "~n size: ~p" @@ -803,25 +812,23 @@ handle_send_pdu(S, Type, Pdu, Addresses) -> _ -> ok end. - -handle_send_pdu1(#state{log = Log, - usock = Sock, - filter = FilterMod}, Type, Addresses) -> + +do_handle_send_pdu1(S, Type, Addresses) -> lists:foreach( fun ({Domain, Address, Packet}) when is_binary(Packet) -> ?vdebug( "[~w] sending packet:~n" " size: ~p~n" " to: ~p", [Domain, sz(Packet), Address]), - maybe_udp_send( - FilterMod, Log, Type, Sock, Domain, Address, Packet); - ({Domain, Address, {Packet, _LogData}}) when is_binary(Packet) -> + To = {Domain, Address}, + maybe_udp_send(S, To, Packet); + ({Domain, Address, {Packet, LogData}}) when is_binary(Packet) -> ?vdebug( "[~w] sending encrypted packet:~n" " size: ~p~n" " to: ~p", [Domain, sz(Packet), Address]), - maybe_udp_send( - FilterMod, Log, Type, Sock, Domain, Address, Packet) + To = {Domain, Address}, + maybe_udp_send(S, To, Packet, Type, LogData) end, Addresses). @@ -836,24 +843,31 @@ handle_response(Vsn, Pdu, From, S) -> "~n No receiver available for response pdu", []) end. -maybe_udp_send(FilterMod, Sock, Domain, Address, Packet) -> - case (catch FilterMod:accept_send(Domain, Address)) of +maybe_udp_send( + #state{usock = Sock, + filter = FilterMod}, To, Packet) -> + case (catch FilterMod:accept_send(To)) of false -> inc(netIfMsgOutDrops), ok; _ -> - {Ip, Port} = Address, + %% XXX should be some kind of lookup of domain to socket + {_Domain, {Ip, Port}} = To, (catch udp_send(Sock, Ip, Port, Packet)) end. -maybe_udp_send(FilterMod, AtLog, Type, Sock, Domain, Address, Packet) -> - case (catch FilterMod:accept_send(Domain, Address)) of +maybe_udp_send( + #state{log = Log, + usock = Sock, + filter = FilterMod}, To, Packet, Type, _LogData) -> + case (catch FilterMod:accept_send(To)) of false -> inc(netIfMsgOutDrops), ok; _ -> - log(AtLog, Type, Packet, Domain, Address), - {Ip, Port} = Address, + log(Log, Type, Packet, To), + %% XXX should be some kind of lookup of domain to socket + {_Domain, {Ip, Port}} = To, (catch udp_send(Sock, Ip, Port, Packet)) end. diff --git a/lib/snmp/src/agent/snmpa_net_if_filter.erl b/lib/snmp/src/agent/snmpa_net_if_filter.erl index 871c4f05da..e71abc4ac6 100644 --- a/lib/snmp/src/agent/snmpa_net_if_filter.erl +++ b/lib/snmp/src/agent/snmpa_net_if_filter.erl @@ -18,41 +18,46 @@ %% -module(snmpa_net_if_filter). --export([accept_recv/2, - accept_send/2, - accept_recv_pdu/3, - accept_send_pdu/2]). +%% New behaviour +-export([accept_recv/1, accept_send/1, accept_recv_pdu/2]). +%% Common signature for both old and new behaviour +-export([accept_send_pdu/2]). +%% Old behaviour +-export([accept_recv/2, accept_send/2, accept_recv_pdu/3]). -include("snmp_debug.hrl"). -accept_recv(Domain, _Address) when is_atom(Domain) -> +accept_recv({Domain, _Address}) when is_atom(Domain) -> ?d("accept_recv -> entry with~n" " Domain: ~p~n" " Address: ~p", [Domain, _Address]), - true; + true. +%% accept_recv(_Addr, Port) when is_integer(Port) -> ?d("accept_recv -> entry with~n" " Addr: ~p~n" " Port: ~p", [_Addr, Port]), true. -accept_send(Domain, _Address) when is_atom(Domain) -> +accept_send({Domain, _Address}) when is_atom(Domain) -> ?d("accept_send -> entry with~n" " Domain: ~p~n" " Address: ~p", [Domain, _Address]), - true; + true. +%% accept_send(_Addr, Port) when is_integer(Port) -> ?d("accept_send -> entry with~n" " Addr: ~p~n" " Port: ~p", [_Addr, Port]), true. -accept_recv_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> +accept_recv_pdu({Domain, _Address}, _PduType) when is_atom(Domain) -> ?d("accept_recv -> entry with~n" " Domain: ~p~n" " Address: ~p~n" " PduType: ~p", [Domain, _Address, _PduType]), - true; + true. +%% accept_recv_pdu(_Addr, Port, _PduType) when is_integer(Port) -> ?d("accept_recv_pdu -> entry with~n" " Addr: ~p~n" diff --git a/lib/snmp/src/agent/snmpa_network_interface_filter.erl b/lib/snmp/src/agent/snmpa_network_interface_filter.erl index 6fa131beee..3fa83db874 100644 --- a/lib/snmp/src/agent/snmpa_network_interface_filter.erl +++ b/lib/snmp/src/agent/snmpa_network_interface_filter.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2009. All Rights Reserved. +%% Copyright Ericsson AB 2007-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -23,28 +23,29 @@ behaviour_info(callbacks) -> - [{accept_recv, 2}, - {accept_send, 2}, - {accept_recv_pdu, 3}, + [{accept_recv, 1}, + {accept_send, 1}, + {accept_recv_pdu, 2}, {accept_send_pdu, 2}]; behaviour_info(_) -> undefined. -%% accept_recv(address(), port()) -> boolean() +%% accept_recv({domain(), address()}) -> boolean() %% Called at the receiption of a message %% (before *any* processing has been done). %% -%% accept_send(address(), port()) -> boolean() +%% accept_send({domain(), address()}) -> boolean() %% Called before the sending of a message %% (after *all* processing has been done). %% -%% accept_recv_pdu(Addr, Port, pdu_type()) -> boolean() +%% accept_recv_pdu({domain(), address()}, pdu_type()) -> boolean() %% Called after the basic message processing (MPD) has been done, %% but before the pdu is handed over to the master-agent for %% primary processing. %% -%% accept_send_pdu(Targets, pdu_type()) -> boolean() | NewTargets +%% accept_send_pdu([{domain(), address()}, ...] = Targets, pdu_type()) -> +%% boolean() | NewTargets %% Called before the basic message processing (MPD) is done, %% when a pdu has been received from the master-agent. %% diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 088f0c7fc8..69a6b4a3a9 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -313,7 +313,7 @@ mk_target_name(Domain, Address, Config) end; mk_target_name(Ip, Port, Config) when is_integer(Port), is_list(Config) -> - {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + {Domain, Address} = snmp_conf:ip_port_to_domaddr(Ip, Port), mk_target_name(Domain, Address, Config). select_lowest_supported_version() -> @@ -403,7 +403,7 @@ unregister_agent(UserId, Domain, Address) when is_atom(Domain) -> {error, not_found} end; unregister_agent(UserId, Ip, Port) when is_integer(Port) -> - try snmp_conf:fix_domain_address(Ip, Port) of + try snmp_conf:ip_port_to_domaddr(Ip, Port) of {Domain, Address} -> do_unregister_agent(UserId, Domain, Address) catch @@ -448,7 +448,7 @@ agent_info(Domain, Address, Item) when is_atom(Domain) -> {error, not_found} end; agent_info(Ip, Port, Item) -> - try snmp_conf:fix_domain_address(Ip, Port) of + try snmp_conf:ip_port_to_domaddr(Ip, Port) of {Domain, Address} -> do_agent_info(Domain, Address, Item) catch diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index 39e239f2a2..e7167cdb6b 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -425,7 +425,7 @@ handle_cast(Msg, State) -> %%-------------------------------------------------------------------- handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> ?vlog("received ~w bytes from ~p:~p [~w]", [size(Bytes), Ip, Port, Sock]), - {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + {Domain, Address} = snmp_conf:ip_port_to_domaddr(Ip, Port), maybe_handle_recv_msg(Domain, Address, Bytes, State), {noreply, State}; diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index a04cfba2c1..594bc44474 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -435,7 +435,7 @@ handle_cast(Msg, State) -> %%-------------------------------------------------------------------- handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> ?vlog("received ~w bytes from ~p:~p", [size(Bytes), Ip, Port]), - {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + {Domain, Address} = snmp_conf:ip_port_to_domaddr(Ip, Port), handle_udp(Domain, Address, Bytes, State), {noreply, State}; diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 105652cdda..0d17c66455 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -46,7 +46,7 @@ which_domain/1, check_ip/1, check_ip/2, check_port/1, - fix_domain_address/2, + ip_port_to_domaddr/2, check_address/2, check_address/3, check_taddress/2, mk_taddress/2, @@ -754,7 +754,7 @@ check_port(Port) when ?is_word(Port) -> check_port(Port) -> error({bad_port, Port}). -fix_domain_address(IP, Port) when ?is_word(Port) -> +ip_port_to_domaddr(IP, Port) when ?is_word(Port) -> case check_address_ip(transportDomainUdpIpv4, IP) of false -> case check_address_ip(transportDomainUdpIpv6, IP) of @@ -770,7 +770,7 @@ fix_domain_address(IP, Port) when ?is_word(Port) -> FixedIP -> {transportDomainUdpIpv4, {FixedIP, Port}} end; -fix_domain_address(IP, Port) -> +ip_port_to_domaddr(IP, Port) -> error({bad_address, {transportDomainUdpIpv4, {IP, Port}}}). %% Check a configuration term field from a file to see if it -- cgit v1.2.3 From d2002049e348f1da8d011fe5f628484ec909ec41 Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Thu, 24 Apr 2014 17:05:03 +0200 Subject: snmp: Add IPV6 tests --- lib/snmp/test/snmp_agent_test.erl | 279 +++++++++++++++++++--------------- lib/snmp/test/snmp_agent_test_lib.erl | 9 +- lib/snmp/test/snmp_manager_test.erl | 27 +++- lib/snmp/test/snmp_test_lib.erl | 7 +- lib/snmp/test/snmp_test_lib.hrl | 19 +-- 5 files changed, 202 insertions(+), 139 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index bcc89b93de..e4cac71fec 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -297,7 +297,11 @@ %% tickets2 otp8395/1, - otp9884/1 + otp9884/1, + + %% IPV6 + ipv6_processing/1, + ipv6_trap/1 ]). @@ -537,7 +541,8 @@ groups() -> {tickets1, [], tickets1_cases()}, {tickets2, [], tickets2_cases()}, {otp4394, [], [otp_4394]}, - {otp7157, [], [otp_7157]} + {otp7157, [], [otp_7157]}, + {ipv6, [], [ipv6_processing, ipv6_trap]} ]. @@ -634,6 +639,13 @@ init_per_group(mib_storage_dets = GroupName, Config) -> init_mib_storage_dets(snmp_test_lib:init_group_top_dir(GroupName, Config)); init_per_group(mib_storage_ets = GroupName, Config) -> init_mib_storage_ets(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(ipv6 = GroupName, Config) -> + case ct:require(ipv6_hosts) of + ok -> + ipv6_init(snmp_test_lib:init_group_top_dir(GroupName, Config)); + _ -> + {skip, "Host does not support IPV6"} + end; init_per_group(GroupName, Config) -> snmp_test_lib:init_group_top_dir(GroupName, Config). @@ -728,6 +740,16 @@ init_per_testcase1(v3_inform_i = _Case, Config) when is_list(Config) -> "~n Config: ~p", [_Case, Config]), Dog = ?WD_START(?MINS(10)), [{watchdog, Dog} | Config ]; +init_per_testcase1(ipv6_processing = Case, Config) when is_list(Config) -> + ?DBG("init_per_testcase1 -> entry with" + "~n Case: ~p" + "~n Config: ~p", [Case, Config]), + ipv6_processing({init, init_per_testcase2(Case, Config)}); +init_per_testcase1(ipv6_trap = Case, Config) when is_list(Config) -> + ?DBG("init_per_testcase1 -> entry with" + "~n Case: ~p" + "~n Config: ~p", [Case, Config]), + ipv6_trap({init, init_per_testcase2(Case, Config)}); init_per_testcase1(_Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" "~n Case: ~p" @@ -812,7 +834,8 @@ cases() -> {group, test_v3}, {group, test_multi_threaded}, {group, mib_storage}, - {group, tickets1} + {group, tickets1}, + {group, ipv6} ]. @@ -6382,7 +6405,9 @@ otp_4394_config(AgentConfDir, MgrDir, Ip0) -> ?line write_notify_conf(AgentConfDir), ok. - +ipv6_init(Config) when is_list(Config) -> + Opts = [], + [{vsn, v1} | start_v1_agent(Config, Opts)]. otp_4394_finish(Config) when is_list(Config) -> ?DBG("finish_otp_4394 -> entry", []), @@ -6670,126 +6695,12 @@ otp8395(Config) when is_list(Config) -> otp9884({init, Config}) when is_list(Config) -> ?DBG("otp9884(init) -> entry with" "~n Config: ~p", [Config]), - - %% -- - %% Start nodes - %% - - {ok, AgentNode} = start_node(agent), - - %% We don't use a manager in this test but the (common) config - %% function takes an argument that is derived from this - {ok, ManagerNode} = start_node(manager), - - %% -- - %% Mnesia init - %% - - AgentDbDir = ?config(agent_db_dir, Config), - AgentMnesiaDir = join([AgentDbDir, "mnesia"]), - mnesia_init(AgentNode, AgentMnesiaDir), - - mnesia_create_schema(AgentNode, [AgentNode]), - - mnesia_start(AgentNode), - - %% -- - %% Host & IP - %% - - AgentHost = ?HOSTNAME(AgentNode), - ManagerHost = ?HOSTNAME(ManagerNode), - - Host = snmp_test_lib:hostname(), - Ip = ?LOCALHOST(), - {ok, AgentIP0} = snmp_misc:ip(AgentHost), - AgentIP = tuple_to_list(AgentIP0), - {ok, ManagerIP0} = snmp_misc:ip(ManagerHost), - ManagerIP = tuple_to_list(ManagerIP0), - - - %% -- - %% Write agent config - %% - - Vsns = [v1], - ManagerConfDir = ?config(manager_top_dir, Config), - AgentConfDir = ?config(agent_conf_dir, Config), - AgentTopDir = ?config(agent_top_dir, Config), - AgentBkpDir1 = join([AgentTopDir, backup1]), - AgentBkpDir2 = join([AgentTopDir, backup2]), - ok = file:make_dir(AgentBkpDir1), - ok = file:make_dir(AgentBkpDir2), - AgentBkpDirs = [AgentBkpDir1, AgentBkpDir2], - snmp_agent_test_lib:config(Vsns, - ManagerConfDir, AgentConfDir, - ManagerIP, AgentIP), - - - %% -- - %% Start the agent - %% - - Config2 = start_agent([{host, Host}, - {ip, Ip}, - {agent_node, AgentNode}, - {agent_host, AgentHost}, - {agent_ip, AgentIP}, - {agent_backup_dirs, AgentBkpDirs}|Config]), - - %% -- - %% Create watchdog - %% - - Dog = ?WD_START(?MINS(1)), - - [{watchdog, Dog} | Config2]; + init_v1_agent([{ipfamily, inet} | Config]); otp9884({fin, Config}) when is_list(Config) -> ?DBG("otp9884(fin) -> entry with" "~n Config: ~p", [Config]), - - AgentNode = ?config(agent_node, Config), - ManagerNode = ?config(manager_node, Config), - - %% - - %% Stop agent (this is the nice way to do it, - %% so logs and files can be closed in the proper way). - %% - - AgentSup = ?config(agent_sup, Config), - ?DBG("otp9884(fin) -> stop (stand-alone) agent: ~p", [AgentSup]), - stop_stdalone_agent(AgentSup), - - %% - - %% Stop mnesia - %% - ?DBG("otp9884(fin) -> stop mnesia", []), - mnesia_stop(AgentNode), - - - %% - - %% Stop the agent node - %% - - ?DBG("otp9884(fin) -> stop agent node", []), - stop_node(AgentNode), - - - %% SubAgentNode = ?config(sub_agent_node, Config), - %% stop_node(SubAgentNode), - - - %% - - %% Stop the manager node - %% - - ?DBG("otp9884(fin) -> stop manager node", []), - stop_node(ManagerNode), - - Dog = ?config(watchdog, Config), - ?WD_STOP(Dog), - lists:keydelete(watchdog, 1, Config); + fin_v1_agent(Config); otp9884(doc) -> "OTP-9884 - Simlutaneous backup call should not work. "; @@ -6849,7 +6760,23 @@ otp9884_await_backup_completion(First, Second) end; otp9884_await_backup_completion(First, Second) -> throw({error, {bad_completion, First, Second}}). +%%----------------------------------------------------------------- +ipv6_processing({init, Config}) when is_list(Config)-> + init_v1_agent([{ipfamily, inet6} | Config]); +ipv6_processing({fin, Config}) when is_list(Config) -> + fin_v1_agent(Config); +ipv6_processing(Config) when is_list(Config) -> + v1_processing(Config). + +%%----------------------------------------------------------------- + +ipv6_trap({init, Config}) when is_list(Config)-> + init_v1_agent([{ipfamily, inet6} | Config]); +ipv6_trap({fin, Config}) when is_list(Config) -> + fin_v1_agent(Config); +ipv6_trap(Config) when is_list(Config) -> + v1_trap(Config). %%----------------------------------------------------------------- @@ -7391,3 +7318,115 @@ p(F, A) -> formated_timestamp() -> snmp_test_lib:formated_timestamp(). + +init_v1_agent(Config) -> + %% -- + %% Start nodes + %% + + {ok, AgentNode} = start_node(agent), + + %% We don't use a manager in this test but the (common) config + %% function takes an argument that is derived from this + {ok, ManagerNode} = start_node(manager), + + %% -- + %% Mnesia init + %% + + AgentDbDir = ?config(agent_db_dir, Config), + AgentMnesiaDir = join([AgentDbDir, "mnesia"]), + mnesia_init(AgentNode, AgentMnesiaDir), + + mnesia_create_schema(AgentNode, [AgentNode]), + + mnesia_start(AgentNode), + + %% -- + %% Host & IP + %% + + AgentHost = ?HOSTNAME(AgentNode), + ManagerHost = ?HOSTNAME(ManagerNode), + + Host = snmp_test_lib:hostname(), + Ip = ?LOCALHOST(?config(ipfamily, Config)), + {ok, AgentIP0} = snmp_misc:ip(AgentHost), + AgentIP = tuple_to_list(AgentIP0), + {ok, ManagerIP0} = snmp_misc:ip(ManagerHost), + ManagerIP = tuple_to_list(ManagerIP0), + + + %% -- + %% Write agent config + %% + + Vsns = [v1], + ManagerConfDir = ?config(manager_top_dir, Config), + AgentConfDir = ?config(agent_conf_dir, Config), + AgentTopDir = ?config(agent_top_dir, Config), + AgentBkpDir1 = join([AgentTopDir, backup1]), + AgentBkpDir2 = join([AgentTopDir, backup2]), + ok = file:make_dir(AgentBkpDir1), + ok = file:make_dir(AgentBkpDir2), + AgentBkpDirs = [AgentBkpDir1, AgentBkpDir2], + snmp_agent_test_lib:config(Vsns, + ManagerConfDir, AgentConfDir, + ManagerIP, AgentIP), + + + %% -- + %% Start the agent + %% + + Config2 = start_agent([{host, Host}, + {ip, Ip}, + {agent_node, AgentNode}, + {agent_host, AgentHost}, + {agent_ip, AgentIP}, + {agent_backup_dirs, AgentBkpDirs}|Config]), + + %% -- + %% Create watchdog + %% + + Dog = ?WD_START(?MINS(1)), + + [{watchdog, Dog} | Config2]. + +fin_v1_agent(Config) -> + AgentNode = ?config(agent_node, Config), + ManagerNode = ?config(manager_node, Config), + + %% - + %% Stop agent (this is the nice way to do it, + %% so logs and files can be closed in the proper way). + %% + + AgentSup = ?config(agent_sup, Config), + stop_stdalone_agent(AgentSup), + + %% - + %% Stop mnesia + %% + mnesia_stop(AgentNode), + + + %% - + %% Stop the agent node + %% + stop_node(AgentNode), + + + %% SubAgentNode = ?config(sub_agent_node, Config), + %% stop_node(SubAgentNode), + + + %% - + %% Stop the manager node + %% + stop_node(ManagerNode), + + Dog = ?config(watchdog, Config), + ?WD_STOP(Dog), + lists:keydelete(watchdog, 1, Config). diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index e12a282a34..6061732879 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -232,13 +232,14 @@ init_case(Config) when is_list(Config) -> MgrNode = ?config(snmp_mgr, Config), MasterNode = ?config(snmp_master, Config), %% MasterNode = node(), - + IpFamily = proplists:get_value(ipfamily, Config, inet), + SaHost = ?HOSTNAME(SaNode), MgrHost = ?HOSTNAME(MgrNode), MasterHost = ?HOSTNAME(MasterNode), - {ok, MasterIP} = snmp_misc:ip(MasterHost), - {ok, MIP} = snmp_misc:ip(MgrHost), - {ok, SIP} = snmp_misc:ip(SaHost), + {ok, MasterIP} = snmp_misc:ip(MasterHost, IpFamily), + {ok, MIP} = snmp_misc:ip(MgrHost, IpFamily), + {ok, SIP} = snmp_misc:ip(SaHost, IpFamily), put(mgr_node, MgrNode), diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 52b58ecea8..3e152e6ad4 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -241,8 +241,10 @@ init_per_testcase2(Case, Config) -> AgLogDir = filename:join(AgTopDir, "log/"), ?line ok = file:make_dir(AgLogDir), + Family = proplists:get_value(ipfamily, Config, inet), + Conf = [{watchdog, ?WD_START(?MINS(5))}, - {ip, ?LOCALHOST()}, + {ip, ?LOCALHOST(Family)}, {case_top_dir, CaseTopDir}, {agent_dir, AgTopDir}, {agent_conf_dir, AgConfDir}, @@ -410,7 +412,8 @@ all() -> {group, event_tests}, {group, event_tests_mt}, discovery, - {group, tickets} + {group, tickets}, + {group, ipv6} ]. groups() -> @@ -545,7 +548,15 @@ groups() -> [ otp8395_1 ] + }, + {ipv6, [], + [ + simple_sync_get3, + inform1 + ] } + + ]. init_per_group(request_tests_mt = GroupName, Config) -> @@ -556,10 +567,16 @@ init_per_group(event_tests_mt = GroupName, Config) -> snmp_test_lib:init_group_top_dir( GroupName, [{manager_net_if_module, snmpm_net_if_mt} | Config]); +init_per_group(ipv6 = GroupName, Config) -> + case ct:require(ipv6_hosts) of + ok -> + ipv6_init(snmp_test_lib:init_group_top_dir(GroupName, Config)); + _ -> + {skip, "Host does not support IPV6"} + end; init_per_group(GroupName, Config) -> snmp_test_lib:init_group_top_dir(GroupName, Config). - - + end_per_group(_GroupName, Config) -> %% Do we really need to do this? lists:keydelete(snmp_group_top_dir, 1, Config). @@ -6426,3 +6443,5 @@ formated_timestamp() -> %% p(TName, F, A) -> %% io:format("~w -> " ++ F ++ "~n", [TName|A]). +ipv6_init(Config) when is_list(Config) -> + [{ipfamily, inet6} | Config]. diff --git a/lib/snmp/test/snmp_test_lib.erl b/lib/snmp/test/snmp_test_lib.erl index fbb891e40d..5e611340a3 100644 --- a/lib/snmp/test/snmp_test_lib.erl +++ b/lib/snmp/test/snmp_test_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2002-2013. All Rights Reserved. +%% Copyright Ericsson AB 2002-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -22,7 +22,7 @@ -include_lib("kernel/include/file.hrl"). --export([hostname/0, hostname/1, localhost/0, os_type/0, sz/1, +-export([hostname/0, hostname/1, localhost/0, localhost/1, os_type/0, sz/1, display_suite_info/1]). -export([non_pc_tc_maybe_skip/4, os_based_skip/1]). -export([fix_data_dir/1, @@ -60,6 +60,9 @@ from(_H, []) -> []. localhost() -> {ok, Ip} = snmp_misc:ip(net_adm:localhost()), Ip. +localhost(Family) -> + {ok, Ip} = snmp_misc:ip(net_adm:localhost(), Family), + Ip. sz(L) when is_list(L) -> length(L); diff --git a/lib/snmp/test/snmp_test_lib.hrl b/lib/snmp/test/snmp_test_lib.hrl index 8cc3f75dc5..9b7609b831 100644 --- a/lib/snmp/test/snmp_test_lib.hrl +++ b/lib/snmp/test/snmp_test_lib.hrl @@ -1,5 +1,5 @@ %% -%% 2002-2008 +%% 2002-2014 %% Ericsson AB, All Rights Reserved %% %% @@ -32,14 +32,15 @@ -define(APPLICATION, snmp). -endif. --define(SCONF(K,D,C), snmp_test_lib:set_config(K,D,C)). --define(GCONF(K,C), snmp_test_lib:get_config(K,C)). --define(RCONF(K,C,V), snmp_test_lib:replace_config(K,C,V)). --define(HOSTNAME(N), snmp_test_lib:hostname(N)). --define(LOCALHOST(), snmp_test_lib:localhost()). --define(SZ(X), snmp_test_lib:sz(X)). --define(OSTYPE(), snmp_test_lib:os_type()). --define(DISPLAY_SUITE_INFO(), snmp_test_lib:display_suite_info(?MODULE)). +-define(SCONF(K,D,C), snmp_test_lib:set_config(K,D,C)). +-define(GCONF(K,C), snmp_test_lib:get_config(K,C)). +-define(RCONF(K,C,V), snmp_test_lib:replace_config(K,C,V)). +-define(HOSTNAME(N), snmp_test_lib:hostname(N)). +-define(LOCALHOST(), snmp_test_lib:localhost()). +-define(LOCALHOST(Family), snmp_test_lib:localhost(Family)). +-define(SZ(X), snmp_test_lib:sz(X)). +-define(OSTYPE(), snmp_test_lib:os_type()). +-define(DISPLAY_SUITE_INFO(), snmp_test_lib:display_suite_info(?MODULE)). %% - Test case macros - -- cgit v1.2.3 From 100b3345793043d50f90619c25123dc4d218e5cd Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 8 May 2014 16:16:03 +0200 Subject: fix agent configuration details --- lib/snmp/src/agent/snmp_framework_mib.erl | 51 ++++----- lib/snmp/src/agent/snmpa_conf.erl | 55 ++++++---- lib/snmp/src/agent/snmpa_net_if.erl | 14 ++- lib/snmp/src/misc/snmp_conf.erl | 111 ++++++++++++-------- lib/snmp/src/misc/snmp_config.erl | 167 ++++++++++++++++++++---------- 5 files changed, 254 insertions(+), 144 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 51f8c46d19..0b439aa5f1 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -41,6 +41,7 @@ -compile({no_auto_import,[error/1]}). -export([init/0, configure/1]). -export([intContextTable/1, intContextTable/3, + intAgentTransportDomain/1, intAgentUDPPort/1, intAgentIpAddress/1, snmpEngineID/1, snmpEngineBoots/1, @@ -128,27 +129,20 @@ read_agent(Dir) -> ?vdebug("read agent config file", []), FileName = "agent.conf", File = filename:join(Dir, FileName), - Agent = + Conf0 = try snmp_conf:read(File, fun order_agent/2, fun check_agent/2) catch throw:{error, Reason} -> error({failed_reading_config_file, Dir, FileName, Reason}) end, - sort_agent(Agent). - - -%%----------------------------------------------------------------- -%% Make sure that each mandatory agent attribute is present, and -%% provide default values for the other non-present attributes. -%%----------------------------------------------------------------- -sort_agent(L) -> - Mand = [{intAgentIpAddress, mandatory}, - {intAgentUDPPort, mandatory}, - {snmpEngineMaxMessageSize, mandatory}, - {snmpEngineID, mandatory}], - {ok, L2} = snmp_conf:check_mandatory(L, Mand), - lists:keysort(1, L2). + Mand = + [{intAgentIpAddress, mandatory}, + {intAgentUDPPort, mandatory}, + {snmpEngineMaxMessageSize, mandatory}, + {snmpEngineID, mandatory}], + {ok, Conf} = snmp_conf:check_mandatory(Conf0, Mand), + Conf. %%----------------------------------------------------------------- @@ -198,14 +192,17 @@ check_context(Context) -> %%----------------------------------------------------------------- check_agent({intAgentTransportDomain, D}, Domain) -> {snmp_conf:check_domain(D), D}; -check_agent({intAgentTransportAddress, Address}, Domain) -> - {snmp_conf:check_address(Domain, Address), Domain}; +check_agent({intAgentIpAddress, Value}, D) -> + Domain = + case D of + undefined -> snmp_target_mib:default_domain(); + _ -> D + end, + {snmp_conf:check_ip(Domain, Value), Domain}; check_agent(Entry, Domain) -> {check_agent(Entry), Domain}. -check_agent({intAgentIpAddress, Value}) -> % Obsoleted - snmp_conf:check_ip(Value); -check_agent({intAgentUDPPort, Value}) -> % Obsoleted +check_agent({intAgentUDPPort, Value}) -> snmp_conf:check_integer(Value); %% This one is kept for backwards compatibility check_agent({intAgentMaxPacketSize, Value}) -> @@ -218,13 +215,14 @@ check_agent(X) -> error({invalid_agent_attribute, X}). %% Ordering function to sort intAgentTransportDomain first -%% hence before intAgentTransportAddress +%% hence before intAgentIpAddress order_agent({Name, _}, {Name, _}) -> true; %% Less than or equal -order_agent(_, {intAgentTransportDomain, _}) -> +order_agent({_, _}, {intAgentTransportDomain, _}) -> false; %% Greater than -order_agent(_, _) -> - true. %% Less than or equal +order_agent({A, _}, {B, _}) -> + A =< B. + maybe_create_table(Name) -> @@ -398,6 +396,11 @@ intAgentUDPPort(Op) -> intAgentIpAddress(Op) -> snmp_generic:variable_func(Op, db(intAgentIpAddress)). +intAgentTransportDomain(Op) -> + snmp_generic:variable_func(Op, db(intAgentTransportDomain)). + + + snmpEngineID(print) -> VarAndValue = [{snmpEngineID, snmpEngineID(get)}], snmpa_mib_lib:print_variables(VarAndValue); diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index f055f89880..b05590a504 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -154,6 +154,8 @@ write_agent_conf(Fd, [H|T]) -> do_write_agent_conf(Fd, H), write_agent_conf(Fd, T). +do_write_agent_conf(Fd, {intAgentTransportDomain = Tag, Val}) -> + io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_agent_conf(Fd, {intAgentIpAddress = Tag, Val}) -> io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_agent_conf(Fd, {intAgentUDPPort = Tag, Val} ) -> @@ -566,29 +568,36 @@ write_target_addr_conf(Fd, Conf) -> lists:foreach(Fun, Conf), ok. -do_write_target_addr_conf(Fd, - {Name, - Ip, Udp, - Timeout, RetryCount, TagList, - ParamsName, EngineId, - TMask, MaxMessageSize}) -> - Domain = snmp_target_mib:default_domain(), - do_write_target_addr_conf(Fd, - {Name, - Domain, Ip, Udp, - Timeout, RetryCount, TagList, - ParamsName, EngineId, - TMask, MaxMessageSize}); -do_write_target_addr_conf(Fd, - {Name, - Domain, Ip, Udp, - Timeout, RetryCount, TagList, - ParamsName, EngineId, - TMask, MaxMessageSize}) -> - io:format(Fd, - "{\"~s\", ~w, ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, - ParamsName, EngineId, TMask, MaxMessageSize]); +do_write_target_addr_conf( + Fd, + {Name, Ip, Udp, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}) + when is_integer(Udp) -> + Domain = snmp_target_mib:default_domain(), + Address = {Ip, Udp}, + do_write_target_addr_conf( + Fd, + {Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}); +do_write_target_addr_conf( + Fd, + {Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}) + when is_atom(Domain) -> + io:format( + Fd, + "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize]); +do_write_target_addr_conf( + Fd, + {Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}) -> + Address = {Ip, Udp}, + do_write_target_addr_conf( + Fd, + {Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}); do_write_target_addr_conf(_Fd, Crap) -> error({bad_target_addr_config, Crap}). diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 59d88517c9..96211fc5f4 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -112,6 +112,14 @@ get_address() -> {value, IPAddress} = snmp_framework_mib:intAgentIpAddress(get), IPAddress. +get_domain() -> + case snmp_framework_mib:intAgentTransportDomain(get) of + {value, Domain} -> + Domain; + genErr -> + snmpUDPDomain + end. + filter_reset(Pid) -> Pid ! filter_reset. @@ -155,6 +163,8 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> ?vlog("starting",[]), %% -- Port and address -- + Domain = get_domain(), + ?vdebug("domain: ~w",[Domain]), UDPPort = get_port(), ?vdebug("port: ~w",[UDPPort]), IPAddress = get_address(), @@ -181,7 +191,9 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> IPOpts2 = ip_opt_no_reuse_address(Opts), IPOpts3 = ip_opt_recbuf(Opts), IPOpts4 = ip_opt_sndbuf(Opts), - IPOpts = [binary | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4], + IPOpts = + [binary, snmp_conf:tdomain_to_family(Domain) + | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4], ?vdebug("open socket with options: ~w",[IPOpts]), case gen_udp_open(UDPPort, IPOpts) of {ok, Sock} -> diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 0d17c66455..0cad61e5c8 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -31,33 +31,34 @@ %% Basic (type) check functions -export([check_mandatory/2, check_integer/1, check_integer/2, - + check_string/1, check_string/2, - check_atom/2, + check_atom/2, check_timer/1, - all_domains/0, - check_domain/1, - all_tdomains/0, - check_tdomain/1, - mk_tdomain/1, - which_domain/1, + all_domains/0, + check_domain/1, + all_tdomains/0, + check_tdomain/1, + mk_tdomain/1, + tdomain_to_family/1, + which_domain/1, check_ip/1, check_ip/2, check_port/1, ip_port_to_domaddr/2, check_address/2, check_address/3, check_taddress/2, mk_taddress/2, - - check_packet_size/1, + + check_packet_size/1, check_oid/1, - check_imask/1, check_emask/1, - - check_mp_model/1, - check_sec_model/1, check_sec_model/2, check_sec_model/3, + check_imask/1, check_emask/1, + + check_mp_model/1, + check_sec_model/1, check_sec_model/2, check_sec_model/3, check_sec_level/1, all_integer/1 @@ -471,6 +472,22 @@ mk_tdomain(BadDomain) -> error({bad_domain, BadDomain}). +%% --------- + +tdomain_to_family(snmpUDPDomain) -> + inet; +tdomain_to_family(transportDomainUdpIpv4) -> + inet; +tdomain_to_family(transportDomainUdpIpv6) -> + inet6; +tdomain_to_family(?transportDomainUdpIpv4) -> + inet; +tdomain_to_family(?transportDomainUdpIpv6) -> + inet6; +tdomain_to_family(BadDomain) -> + error({bad_domain, BadDomain}). + + %% --------- %% XXX remove @@ -716,35 +733,43 @@ which_domain({A0, A1, A2, A3, A4, A5, A6, A7}) %% --------- -%% XXX remove - check_ip(X) -> check_ip(snmpUDPDomain, X). -check_ip(snmpUDPDomain, X) -> - check_ip(transportDomainUdpIpv4, X); -check_ip(transportDomainUdpIpv4 = Domain, X) -> - case X of - [A,B,C,D] when ?is_ipv4_addr(A, B, C, D) -> - ok; - _ -> - error({bad_address, {Domain, X}}) - end; -check_ip(transportDomainUdpIpv6 = Domain, X) -> - case X of - [A,B,C,D,E,F,G,H] - when ?is_ipv6_addr(A, B, C, D, E, F, G, H) -> - ok; - [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P] - when ?is_ipv6_addr( - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> +check_ip(Domain, IP) -> + case check_address_ip(Domain, IP) of + false -> + error({bad_address, {Domain, IP}}); + true -> ok; - _ -> - error({bad_address, {Domain, X}}) - end; -%% -check_ip(BadDomain, _X) -> - error({invalid_domain, BadDomain}). + FixedIP -> + {ok, FixedIP} + end. + +%% check_ip(snmpUDPDomain, X) -> +%% check_ip(transportDomainUdpIpv4, X); +%% check_ip(transportDomainUdpIpv4 = Domain, X) -> +%% case X of +%% [A,B,C,D] when ?is_ipv4_addr(A, B, C, D) -> +%% ok; +%% _ -> +%% error({bad_address, {Domain, X}}) +%% end; +%% check_ip(transportDomainUdpIpv6 = Domain, X) -> +%% case X of +%% [A,B,C,D,E,F,G,H] +%% when ?is_ipv6_addr(A, B, C, D, E, F, G, H) -> +%% ok; +%% [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P] +%% when ?is_ipv6_addr( +%% A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> +%% ok; +%% _ -> +%% error({bad_address, {Domain, X}}) +%% end; +%% %% +%% check_ip(BadDomain, _X) -> +%% error({invalid_domain, BadDomain}). %% --------- @@ -850,7 +875,9 @@ check_address_ip(transportDomainUdpIpv6, Address) -> mk_word(A12, A13), mk_word(A14, A15)}; _ -> false - end. + end; +check_address_ip(BadDomain, _) -> + error({bad_domain, BadDomain}). %% -> {IP, Port} check_address_ip_port(Domain, Address) @@ -907,7 +934,9 @@ check_address_ip_port(transportDomainUdpIpv6 = Domain, Address) -> mk_word(P0, P1)}; _ -> false - end. + end; +check_address_ip_port(BadDomain, _) -> + error({bad_domain, BadDomain}). diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 12467a1abf..5dffed8068 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -30,6 +30,7 @@ read_config_file/3, read_config_file/4]). -export([write_agent_snmp_files/7, write_agent_snmp_files/12, + write_agent_snmp_files/6, write_agent_snmp_files/11, write_agent_snmp_conf/5, write_agent_snmp_context_conf/1, @@ -568,11 +569,9 @@ config_agent_snmp(Dir, Vsns) -> end, NT end, - case (catch write_agent_snmp_files(Dir, - Vsns, ManagerIP, TrapUdp, - AgentIP, AgentUDP, - SysName, NotifType, SecType, - Passwd, EngineID, MMS)) of + case (catch write_agent_snmp_files( + Dir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUDP, SysName, + NotifType, SecType, Passwd, EngineID, MMS)) of ok -> i("~n- - - - - - - - - - - - -"), i("Info: 1. SecurityName \"initial\" has noAuthNoPriv read access~n" @@ -1581,35 +1580,63 @@ remove_newline(Str) -> %% File generation %%====================================================================== +write_agent_snmp_files( + Dir, Vsns, Domain, ManagerAddr, AgentAddr, SysName) + when is_list(Dir), + is_list(Vsns), + is_atom(Domain), + is_list(SysName) -> + write_agent_snmp_files( + Dir, Vsns, Domain, ManagerAddr, AgentAddr, SysName, + "trap", none, "", "agentEngine", 484). + %%---------------------------------------------------------------------- %% Dir: string() (ex: "../conf/") %% ManagerIP, AgentIP: [int(),int(),int(),int()] %% TrapUdp, AgentUDP: integer() %% SysName: string() %%---------------------------------------------------------------------- -write_agent_snmp_files(Dir, Vsns, ManagerIP, TrapUdp, - AgentIP, AgentUDP, SysName) - when is_list(Dir) andalso - is_list(Vsns) andalso - is_list(ManagerIP) andalso - is_integer(TrapUdp) andalso - is_list(AgentIP) andalso - is_integer(AgentUDP) andalso +write_agent_snmp_files( + Dir, Vsns, ManagerIP, TrapUDP, AgentIP, AgentUDP, SysName) + when is_list(Dir) andalso + is_list(Vsns) andalso + is_list(ManagerIP) andalso + is_integer(TrapUDP) andalso + is_list(AgentIP) andalso + is_integer(AgentUDP) andalso is_list(SysName) -> - write_agent_snmp_files(Dir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUDP, - SysName, "trap", none, "", "agentEngine", 484). + write_agent_snmp_files( + Dir, Vsns, ManagerIP, TrapUDP, AgentIP, AgentUDP, SysName, + "trap", none, "", "agentEngine", 484). %% %% ----- Agent config files generator functions ----- %% -write_agent_snmp_files(Dir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUDP, - SysName, NotifType, SecType, Passwd, EngineID, MMS) -> +write_agent_snmp_files( + Dir, Vsns, Domain, ManagerAddr, AgentAddr, SysName, + NotifType, SecType, Passwd, EngineID, MMS) -> + write_agent_snmp_conf(Dir, Domain, AgentAddr, EngineID, MMS), + write_agent_snmp_context_conf(Dir), + write_agent_snmp_community_conf(Dir), + write_agent_snmp_standard_conf(Dir, SysName), + write_agent_snmp_target_addr_conf(Dir, Domain, ManagerAddr, Vsns), + write_agent_snmp_target_params_conf(Dir, Vsns), + write_agent_snmp_notify_conf(Dir, NotifType), + write_agent_snmp_usm_conf(Dir, Vsns, EngineID, SecType, Passwd), + write_agent_snmp_vacm_conf(Dir, Vsns, SecType), + ok. + +write_agent_snmp_files( + Dir, Vsns, ManagerIP, TrapUDP, AgentIP, AgentUDP, SysName, + NotifType, SecType, Passwd, EngineID, MMS) -> + Domain = snmp_target_mib:default_domain(), + ManagerAddr = {ManagerIP, TrapUDP}, write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS), write_agent_snmp_context_conf(Dir), write_agent_snmp_community_conf(Dir), write_agent_snmp_standard_conf(Dir, SysName), - write_agent_snmp_target_addr_conf(Dir, ManagerIP, TrapUdp, Vsns), + write_agent_snmp_target_addr_conf(Dir, Domain, ManagerAddr, Vsns), write_agent_snmp_target_params_conf(Dir, Vsns), write_agent_snmp_notify_conf(Dir, NotifType), write_agent_snmp_usm_conf(Dir, Vsns, EngineID, SecType, Passwd), @@ -1617,11 +1644,32 @@ write_agent_snmp_files(Dir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUDP, ok. + %% %% ------ [agent] agent.conf ------ %% -write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS) -> + +write_agent_snmp_conf(Dir, Domain, AgentAddr, EngineID, MMS) + when is_atom(Domain) -> + {AgentIP, AgentUDP} = AgentAddr, + Conf = + [{intAgentTransportDomain, Domain}, + {intAgentUDPPort, AgentUDP}, + {intAgentIpAddress, AgentIP}, + {snmpEngineID, EngineID}, + {snmpEngineMaxMessageSize, MMS}], + do_write_agent_snmp_conf(Dir, Conf); +write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS) + when is_integer(AgentUDP) -> + Conf = + [{intAgentUDPPort, AgentUDP}, + {intAgentIpAddress, AgentIP}, + {snmpEngineID, EngineID}, + {snmpEngineMaxMessageSize, MMS}], + do_write_agent_snmp_conf(Dir, Conf). + +do_write_agent_snmp_conf(Dir, Conf) -> Comment = "%% This file defines the Agent local configuration info\n" "%% The data is inserted into the snmpEngine* variables defined\n" @@ -1636,11 +1684,7 @@ write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS) -> "%% {snmpEngineID, \"agentEngine\"}.\n" "%% {snmpEngineMaxMessageSize, 484}.\n" "%%\n\n", - Hdr = header() ++ Comment, - Conf = [{intAgentUDPPort, AgentUDP}, - {intAgentIpAddress, AgentIP}, - {snmpEngineID, EngineID}, - {snmpEngineMaxMessageSize, MMS}], + Hdr = header() ++ Comment, write_agent_config(Dir, Hdr, Conf). write_agent_config(Dir, Hdr, Conf) -> @@ -1746,17 +1790,22 @@ update_agent_standard_config(Dir, Conf) -> %% ------ target_addr.conf ------ %% -write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> +write_agent_snmp_target_addr_conf(Dir, Domain, Addr, Vsns) + when is_atom(Domain) -> Timeout = 1500, RetryCount = 3, - write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, - Timeout, RetryCount, - Vsns). - -write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, - Timeout, RetryCount, - Vsns) -> - Comment = + write_agent_snmp_target_addr_conf( + Dir, Domain, Addr, Timeout, RetryCount, Vsns); +write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, Vsns) + when is_integer(UDP) -> + Domain = snmp_target_mib:default_domain(), + Addr = {ManagerIp, UDP}, + write_agent_snmp_target_addr_conf(Dir, Domain, Addr, Vsns). + +write_agent_snmp_target_addr_conf( + Dir, Domain, Addr, Timeout, RetryCount, Vsns) + when is_atom(Domain) -> + Comment = "%% This file defines the target address parameters.\n" "%% The data is inserted into the snmpTargetAddrTable defined\n" "%% in SNMP-TARGET-MIB, and in the snmpTargetAddrExtTable defined\n" @@ -1776,35 +1825,37 @@ write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, "%%\n\n", Hdr = header() ++ Comment, F = fun(v1 = Vsn, Acc) -> - [{mk_ip(ManagerIp, Vsn), - snmp_target_mib:default_domain(), - ManagerIp, UDP, Timeout, RetryCount, + [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}| Acc]; (v2 = Vsn, Acc) -> - [{mk_ip(ManagerIp, Vsn), - snmp_target_mib:default_domain(), - ManagerIp, UDP, Timeout, RetryCount, + [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten(io_lib:format("~s.2",[mk_ip(ManagerIp, Vsn)])), - ManagerIp, UDP, Timeout, RetryCount, + {lists:flatten(io_lib:format("~s.2",[mk_name(Addr, Vsn)])), + Domain, Addr, Timeout, RetryCount, "std_inform", mk_param(Vsn), "", [], 2048}| Acc]; (v3 = Vsn, Acc) -> - [{mk_ip(ManagerIp, Vsn), - snmp_target_mib:default_domain(), - ManagerIp, UDP, Timeout, RetryCount, + [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten(io_lib:format("~s.3",[mk_ip(ManagerIp, Vsn)])), - ManagerIp, UDP, Timeout, RetryCount, + {lists:flatten(io_lib:format("~s.3",[mk_name(Addr, Vsn)])), + Domain, Addr, Timeout, RetryCount, "std_inform", mk_param(Vsn), "mgrEngine", [], 2048}| Acc] end, Conf = lists:foldl(F, [], Vsns), - write_agent_target_addr_config(Dir, Hdr, Conf). + write_agent_target_addr_config(Dir, Hdr, Conf); +write_agent_snmp_target_addr_conf( + Dir, ManagerIp, UDP, Timeout, RetryCount, Vsns) when is_integer(UDP) -> + Domain = snmp_target_mib:default_domain(), + Addr = {ManagerIp, UDP}, + write_agent_snmp_target_addr_conf( + Dir, Domain, Addr, Timeout, RetryCount, Vsns). mk_param(Vsn) -> lists:flatten(io_lib:format("target_~w", [Vsn])). -mk_ip([A,B,C,D], Vsn) -> - lists:flatten(io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn])). +mk_name({[A,B,C,D], _}, Vsn) -> + lists:flatten(io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn])); +mk_name(Address, Vsn) -> + lists:flatten(io_lib:format("~w ~w", [Address,Vsn])). write_agent_target_addr_config(Dir, Hdr, Conf) -> snmpa_conf:write_target_addr_config(Dir, Hdr, Conf). @@ -2438,14 +2489,20 @@ write_config_file(Dir, FileName, Verify, Write) is_list(FileName) andalso is_function(Verify) andalso is_function(Write)) -> - try - begin - do_write_config_file(Dir, FileName, Verify, Write) - end + try do_write_config_file(Dir, FileName, Verify, Write) of + ok -> + ok; + Other -> + d("File write of ~s returned: ~p~n", [FileName,Other]) catch throw:Error -> + S = erlang:get_stacktrace(), + d("File write of ~s throwed: ~p~n ~p~n", [FileName,Error,S]), Error; T:E -> + S = erlang:get_stacktrace(), + d("File write of ~s exception: ~p:~p~n ~p~n", + [FileName,T,E,S]), {error, {failed_write, Dir, FileName, {T, E, erlang:get_stacktrace()}}} @@ -2652,8 +2709,8 @@ ensure_started(App) -> %% ------------------------------------------------------------------------- -% d(F, A) -> -% i("DBG: " ++ F, A). +d(F, A) -> + i("DBG: " ++ F, A). i(F) -> i(F, []). -- cgit v1.2.3 From 36426bcc894853dfd38a4d8db7b4971934df9692 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 9 May 2014 13:54:21 +0200 Subject: Go back to passing (Domain, Addr) to net_if filters --- lib/snmp/src/agent/snmp_framework_mib.erl | 17 +- lib/snmp/src/agent/snmpa_net_if.erl | 271 +++++++++++++++++---- lib/snmp/src/agent/snmpa_net_if_filter.erl | 23 +- .../src/agent/snmpa_network_interface_filter.erl | 6 +- lib/snmp/src/agent/snmpa_trap.erl | 101 +++++--- lib/snmp/src/misc/snmp_pdus.erl | 17 +- 6 files changed, 331 insertions(+), 104 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 0b439aa5f1..fb52f90852 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -190,15 +190,22 @@ check_context(Context) -> %% Agent %% {Name, Value}. %%----------------------------------------------------------------- -check_agent({intAgentTransportDomain, D}, Domain) -> +check_agent({intAgentTransportDomain, D}, _Domain) -> {snmp_conf:check_domain(D), D}; -check_agent({intAgentIpAddress, Value}, D) -> +check_agent({intAgentIpAddress = Tag, Value}, D) -> Domain = case D of - undefined -> snmp_target_mib:default_domain(); - _ -> D + undefined -> + snmp_target_mib:default_domain(); + _ -> + D end, - {snmp_conf:check_ip(Domain, Value), Domain}; + {case snmp_conf:check_ip(Domain, Value) of + ok -> + ok; + {ok, FixedIp} -> + {ok, {Tag, FixedIp}} + end, Domain}; check_agent(Entry, Domain) -> {check_agent(Entry), Domain}. diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 96211fc5f4..53eebb1728 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -46,7 +46,8 @@ debug = false, limit = infinity, rcnt = [], - filter}). + filter, + use_tdomain = false}). -ifndef(default_verbosity). -define(default_verbosity,silence). @@ -165,6 +166,13 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> %% -- Port and address -- Domain = get_domain(), ?vdebug("domain: ~w",[Domain]), + UseTDomain = + case Domain of + snmpUDPDomain -> + false; + _ -> + true + end, UDPPort = get_port(), ?vdebug("port: ~w",[UDPPort]), IPAddress = get_address(), @@ -208,7 +216,8 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> usock_opts = IPOpts, log = Log, limit = Limit, - filter = FilterMod}, + filter = FilterMod, + use_tdomain = UseTDomain}, ?vdebug("started with MpdState: ~p", [MpdState]), {ok, S}; {error, Reason} -> @@ -541,14 +550,39 @@ update_req_counter_outgoing(#state{limit = Limit, rcnt = RCnt} = S, maybe_handle_recv( - #state{usock = Sock, filter = FilterMod} = S, From, Packet) -> - case (catch FilterMod:accept_recv(From)) of + #state{usock = Sock, filter = FilterMod, use_tdomain = UseTDomain} = S, + {Domain, Addr} = From, Packet) -> + case + try + case UseTDomain of + true -> + FilterMod:accept_recv(Domain, Addr); + false -> + {Ip, Port} = Addr, + FilterMod:accept_recv(Ip, Port) + end + catch + Class:Exception -> + error_msg( + "FilterMod:accept_recv/2 crashed for ~p: ~w:~w~n ~p", + [From,Class,Exception,erlang:get_stacktrace()]), + true + end + of false -> %% Drop the received packet inc(netIfMsgInDrops), active_once(Sock), S; - _ -> + Other -> + case Other of + true -> + ok; + _ -> + error_msg( + "FilterMod:accept_recv/2 returned: ~p for ~p", + [Other,From]) + end, handle_recv(S, From, Packet) end. @@ -620,15 +654,40 @@ handle_recv( end. maybe_handle_recv_pdu( - From, Vsn, + {Domain, Addr} = From, Vsn, #pdu{type = Type} = Pdu, PduMS, ACMData, - #state{usock = Sock, filter = FilterMod} = S) -> - case (catch FilterMod:accept_recv_pdu(From, Type)) of + #state{usock = Sock, filter = FilterMod, use_tdomain = UseTDomain} = S) -> + case + try + case UseTDomain of + true -> + FilterMod:accept_recv_pdu(Domain, Addr, Type); + false -> + {Ip, Port} = Addr, + FilterMod:accept_recv_pdu(Ip, Port, Type) + end + catch + Class:Exception -> + error_msg( + "FilterMod:accept_recv_pdu/3 crashed for ~p, ~p: ~w:~w~n" + " ~p", + [From,Type,Class,Exception,erlang:get_stacktrace()]), + true + end + of false -> inc(netIfPduInDrops), active_once(Sock), ok; - _ -> + Other -> + case Other of + true -> + ok; + _ -> + error_msg( + "FilterMod:accept_recv_pdu/3 returned: ~p for ~p, ~p", + [Other,From,Type]) + end, handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S) end; maybe_handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S) -> @@ -658,15 +717,40 @@ handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, maybe_handle_reply_pdu( - #state{filter = FilterMod} = S, Vsn, + #state{filter = FilterMod, use_tdomain = UseTDomain} = S, Vsn, #pdu{request_id = Rid} = Pdu, - Type, ACMData, To) -> + Type, ACMData, {_Domain, Addr} = To) -> S1 = update_req_counter_outgoing(S, Rid), - case (catch FilterMod:accept_send_pdu([To], Type)) of + Addresses = + case UseTDomain of + true -> + [To]; + false -> + [Addr] + end, + case + try + FilterMod:accept_send_pdu(Addresses, Type) + catch + Class:Exception -> + error_msg( + "FilterMod:accept_send_pdu(~p, ~p) crashed: ~w:~w~n ~p", + [Addresses,Type,Class,Exception,erlang:get_stacktrace()]), + true + end + of false -> inc(netIfPduOutDrops), ok; - _ -> + Other -> + case Other of + true -> + ok; + _ -> + error_msg( + "FilterMod:accept_send_pdu(~p, ~p) returned: ~p", + [Addresses,Type,Other]) + end, handle_reply_pdu(S1, Vsn, Pdu, Type, ACMData, To) end, S1. @@ -694,7 +778,7 @@ handle_reply_pdu(#state{log = Log} = S, Vsn, Pdu, Type, ACMData, To) -> maybe_handle_send_pdu( - #state{filter = FilterMod} = S, + #state{filter = FilterMod, use_tdomain = UseTDomain} = S, Vsn, Pdu, MsgData, TDomAddrSecs, From) -> ?vtrace("maybe_handle_send_pdu -> entry with~n" @@ -702,42 +786,77 @@ maybe_handle_send_pdu( " TDomAddrSecs: ~p", [FilterMod, TDomAddrSecs]), DomAddrSecs = snmpa_mpd:process_taddrs(TDomAddrSecs), - DomAddrs = - [case DAS of - {{Domain, _Address} = DomAddr, _SecData} - when is_atom(Domain) -> % v3 - DomAddr; - {Domain, _Address} = DomAddr - when is_atom(Domain) -> % v1 & v2 - DomAddr + AddressesToFilter = + [case UseTDomain of + true -> + case DAS of + {{Domain, _Address} = DomAddr, _SecData} + when is_atom(Domain) -> % v3 + DomAddr; + {Domain, _Address} = DomAddr + when is_atom(Domain) -> % v1 & v2 + DomAddr + end; + false -> + case DAS of + {{Domain, Address}, _SecData} + when is_atom(Domain) -> % v3 + Address; + {Domain, Address} + when is_atom(Domain) -> % v1 & v2 + Address + end end || DAS <- DomAddrSecs], - - case (catch FilterMod:accept_send_pdu( - DomAddrs, pdu_type_of(Pdu))) of + Type = pdu_type_of(Pdu), + + case + try FilterMod:accept_send_pdu(AddressesToFilter, Type) + catch + Class:Exception -> + error_msg( + "FilterMod:accept_send_pdu(~p, ~p) crashed: ~w:~w~n ~p", + [AddressesToFilter,Type, + Class,Exception,erlang:get_stacktrace()]), + true + end + of false -> inc(netIfPduOutDrops), ok; true -> handle_send_pdu(S, Vsn, Pdu, MsgData, DomAddrSecs, From); - FilteredDomAddrs when is_list(FilteredDomAddrs) -> + FilteredAddresses when is_list(FilteredAddresses) -> MergedDomAddrSecs = - [DAS || DAS <- DomAddrSecs, - case DAS of - {{Domain, _Address} = DomAddr, _SData} - when is_atom(Domain) -> % v3 - lists:member( - DomAddr, FilteredDomAddrs); - {Domain, _Address} = DomAddr - when is_atom(Domain) -> % v1 & v2 - lists:member( - DomAddr, FilteredDomAddrs) - end], + [DAS || + DAS <- DomAddrSecs, + lists:member( + case UseTDomain of + true -> + case DAS of + {{Domain, _Address} = DomAddr, _SData} + when is_atom(Domain) -> % v3 + DomAddr; + {Domain, _Address} = DomAddr + when is_atom(Domain) -> % v1 & v2 + DomAddr + end; + false -> + case DAS of + {{Domain, Address}, _SData} + when is_atom(Domain) -> % v3 + Address; + {Domain, Address} + when is_atom(Domain) -> % v1 & v2 + Address + end + end, FilteredAddresses)], ?vtrace("maybe_handle_send_pdu -> MergedDomAddrSecs:~n" " ~p", [MergedDomAddrSecs]), handle_send_pdu(S, Vsn, Pdu, MsgData, MergedDomAddrSecs, From); Other -> error_msg( - "FilterMod:accept_send_pdu/2 returned: ~p", [Other]), + "FilterMod:accept_send_pdu(~p, ~p) returned: ~p", + [AddressesToFilter,Type,Other]), handle_send_pdu(S, Vsn, Pdu, MsgData, DomAddrSecs, From) end. @@ -856,31 +975,81 @@ handle_response(Vsn, Pdu, From, S) -> end. maybe_udp_send( - #state{usock = Sock, - filter = FilterMod}, To, Packet) -> - case (catch FilterMod:accept_send(To)) of + #state{usock = Sock, filter = FilterMod, use_tdomain = UseTDomain}, + {Domain, Addr} = To, Packet) -> + case + try + case UseTDomain of + true -> + FilterMod:accept_send(Domain, Addr); + false -> + {Ip, Port} = Addr, + FilterMod:accept_send(Ip, Port) + end + catch + Class:Exception -> + error_msg( + "FilterMod:accept_send/2 crashed for ~p: ~w:~w~n ~p", + [To,Class,Exception,erlang:get_stacktrace()]), + true + end + of false -> inc(netIfMsgOutDrops), ok; - _ -> + Other -> + case Other of + true -> + ok; + _ -> + error_msg( + "FilterMod:accept_send/2 returned: ~p for ~p", + [Other,To]) + end, %% XXX should be some kind of lookup of domain to socket - {_Domain, {Ip, Port}} = To, - (catch udp_send(Sock, Ip, Port, Packet)) + {SockIp, SockPort} = Addr, + (catch udp_send(Sock, SockIp, SockPort, Packet)) end. maybe_udp_send( - #state{log = Log, - usock = Sock, - filter = FilterMod}, To, Packet, Type, _LogData) -> - case (catch FilterMod:accept_send(To)) of + #state{log = Log, + usock = Sock, + filter = FilterMod, + use_tdomain = UseTDomain}, + {Domain, Addr} = To, Packet, Type, _LogData) -> + case + try + case UseTDomain of + true -> + FilterMod:accept_send(Domain, Addr); + false -> + {Ip, Port} = Addr, + FilterMod:accept_send(Ip, Port) + end + catch + Class:Exception -> + error_msg( + "FilterMod:accept_send/2 crashed for ~p: ~w:~w~n ~p", + [To,Class,Exception,erlang:get_stacktrace()]), + true + end + of false -> inc(netIfMsgOutDrops), ok; - _ -> + Other -> + case Other of + true -> + ok; + _ -> + error_msg( + "FilterMod:accept_send/2 returned: ~p for ~p", + [Other,To]) + end, log(Log, Type, Packet, To), %% XXX should be some kind of lookup of domain to socket - {_Domain, {Ip, Port}} = To, - (catch udp_send(Sock, Ip, Port, Packet)) + {SockIp, SockPort} = Addr, + (catch udp_send(Sock, SockIp, SockPort, Packet)) end. udp_send(UdpId, AgentIp, UdpPort, B) -> diff --git a/lib/snmp/src/agent/snmpa_net_if_filter.erl b/lib/snmp/src/agent/snmpa_net_if_filter.erl index e71abc4ac6..dd77b143d0 100644 --- a/lib/snmp/src/agent/snmpa_net_if_filter.erl +++ b/lib/snmp/src/agent/snmpa_net_if_filter.erl @@ -18,46 +18,39 @@ %% -module(snmpa_net_if_filter). -%% New behaviour --export([accept_recv/1, accept_send/1, accept_recv_pdu/2]). -%% Common signature for both old and new behaviour --export([accept_send_pdu/2]). -%% Old behaviour --export([accept_recv/2, accept_send/2, accept_recv_pdu/3]). +%% Behaviour +-export([accept_recv/2, accept_send/2, accept_recv_pdu/3, accept_send_pdu/2]). -include("snmp_debug.hrl"). -accept_recv({Domain, _Address}) when is_atom(Domain) -> +accept_recv(Domain, _Address) when is_atom(Domain) -> ?d("accept_recv -> entry with~n" " Domain: ~p~n" " Address: ~p", [Domain, _Address]), - true. -%% + true; accept_recv(_Addr, Port) when is_integer(Port) -> ?d("accept_recv -> entry with~n" " Addr: ~p~n" " Port: ~p", [_Addr, Port]), true. -accept_send({Domain, _Address}) when is_atom(Domain) -> +accept_send(Domain, _Address) when is_atom(Domain) -> ?d("accept_send -> entry with~n" " Domain: ~p~n" " Address: ~p", [Domain, _Address]), - true. -%% + true; accept_send(_Addr, Port) when is_integer(Port) -> ?d("accept_send -> entry with~n" " Addr: ~p~n" " Port: ~p", [_Addr, Port]), true. -accept_recv_pdu({Domain, _Address}, _PduType) when is_atom(Domain) -> +accept_recv_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> ?d("accept_recv -> entry with~n" " Domain: ~p~n" " Address: ~p~n" " PduType: ~p", [Domain, _Address, _PduType]), - true. -%% + true; accept_recv_pdu(_Addr, Port, _PduType) when is_integer(Port) -> ?d("accept_recv_pdu -> entry with~n" " Addr: ~p~n" diff --git a/lib/snmp/src/agent/snmpa_network_interface_filter.erl b/lib/snmp/src/agent/snmpa_network_interface_filter.erl index 3fa83db874..90aa54a271 100644 --- a/lib/snmp/src/agent/snmpa_network_interface_filter.erl +++ b/lib/snmp/src/agent/snmpa_network_interface_filter.erl @@ -23,9 +23,9 @@ behaviour_info(callbacks) -> - [{accept_recv, 1}, - {accept_send, 1}, - {accept_recv_pdu, 2}, + [{accept_recv, 2}, + {accept_send, 2}, + {accept_recv_pdu, 3}, {accept_send_pdu, 2}]; behaviour_info(_) -> undefined. diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index b9a2496341..a2d821c099 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -1045,7 +1045,7 @@ deliver_recv(#snmpa_notification_delivery_info{tag = Tag, "~n DeliveryResult: ~p" "~n TAddr: ~p" "", [Tag, Mod, Extra, DeliveryResult, TAddr]), - Addr = transform_taddr(TAddr), + [Addr] = transform_taddrs([TAddr]), (catch Mod:delivery_info(Tag, Addr, DeliveryResult, Extra)); deliver_recv({Tag, Receiver}, MsgId, Result) -> ?vtrace("deliver_recv -> entry with" @@ -1072,35 +1072,80 @@ deliver_recv(Else, _MsgId, _Result) -> [Else]), user_err("snmpa: bad receiver, ~w\n", [Else]). -transform_taddrs(Addrs) -> - [transform_taddr(Addr) || Addr <- Addrs]. +transform_taddrs(TAddrs) -> + UseTDomain = + case snmp_framework_mib:intAgentTransportDomain(get) of + {value,snmpUDPDomain} -> + false; + {value,_} -> + true; + genErr -> + false + end, + DomAddrs = [transform_taddr(TAddr) || TAddr <- TAddrs], + case UseTDomain of + true -> + DomAddrs; + false -> + [Addr || {_Domain, Addr} <- DomAddrs] + end. -transform_taddr({?snmpUDPDomain, [A1, A2, A3, A4, P1, P2]}) -> % v2 - Addr = {A1, A2, A3, A4}, - Port = P1 bsl 8 + P2, - {Addr, Port}; -transform_taddr({?transportDomainUdpIpv4, [A1, A2, A3, A4, P1, P2]}) -> % v2 - Addr = {A1, A2, A3, A4}, - Port = P1 bsl 8 + P2, - {Addr, Port}; -transform_taddr({?transportDomainUdpIpv6, - [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]}) -> % v2 - Addr = {A1, A2, A3, A4, A5, A6, A7, A8}, +%% v2 +transform_taddr({?snmpUDPDomain, Addr}) -> + transform_taddr(transportDomainIdpIpv4, Addr); +transform_taddr({?transportDomainUdpIpv4, Addr}) -> + transform_taddr(transportDomainUdpIpv4, Addr); +transform_taddr({?transportDomainUdpIpv6, Addr}) -> + transform_taddr(transportDomainUdpIpv6, Addr); +%% v3 +transform_taddr({{?snmpUDPDomain, Addr}, _MsgData}) -> + transform_taddr(transportDomainUdpIpv4, Addr); +transform_taddr({{?transportDomainUdpIpv4, Addr}, _MsgData}) -> + transform_taddr(transportDomainUdpIpv4, Addr); +transform_taddr({{?transportDomainUdpIpv6, Addr}, _MsgData}) -> + transform_taddr(transportDomainUdpIpv6, Addr). + +transform_taddr( + transportDomainUdpIpv4 = Domain, + [A1,A2,A3,A4,P1,P2]) -> + Ip = {A1, A2, A3, A4}, Port = P1 bsl 8 + P2, - {Addr, Port}; -transform_taddr({{?snmpUDPDomain, [A1, A2, A3, A4, P1, P2]}, _MsgData}) -> % v3 - Addr = {A1, A2, A3, A4}, + {Domain, {Ip, Port}}; +transform_taddr( + transportDomainUdpIpv6 = Domain, + [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]) -> + Ip = {A1, A2, A3, A4, A5, A6, A7, A8}, Port = P1 bsl 8 + P2, - {Addr, Port}; -transform_taddr({{?transportDomainUdpIpv4, [A1, A2, A3, A4, P1, P2]}, _MsgData}) -> % v3 - Addr = {A1, A2, A3, A4}, - Port = P1 bsl 8 + P2, - {Addr, Port}; -transform_taddr({{?transportDomainUdpIpv6, - [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]}, _MsgData}) -> % v3 - Addr = {A1, A2, A3, A4, A5, A6, A7, A8}, - Port = P1 bsl 8 + P2, - {Addr, Port}. + {Domain, {Ip, Port}}. + + +%% transform_taddr({?snmpUDPDomain, [A1, A2, A3, A4, P1, P2]}) -> % v2 +%% Addr = {A1, A2, A3, A4}, +%% Port = P1 bsl 8 + P2, +%% {Addr, Port}; +%% transform_taddr({?transportDomainUdpIpv4, [A1, A2, A3, A4, P1, P2]}) -> % v2 +%% Addr = {A1, A2, A3, A4}, +%% Port = P1 bsl 8 + P2, +%% {Addr, Port}; +%% transform_taddr({?transportDomainUdpIpv6, +%% [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]}) -> % v2 +%% Addr = {A1, A2, A3, A4, A5, A6, A7, A8}, +%% Port = P1 bsl 8 + P2, +%% {Addr, Port}; +%% transform_taddr({{?snmpUDPDomain, [A1, A2, A3, A4, P1, P2]}, _MsgData}) -> % v3 +%% Addr = {A1, A2, A3, A4}, +%% Port = P1 bsl 8 + P2, +%% {Addr, Port}; +%% transform_taddr({{?transportDomainUdpIpv4, [A1, A2, A3, A4, P1, P2]}, _MsgData}) -> % v3 +%% Addr = {A1, A2, A3, A4}, +%% Port = P1 bsl 8 + P2, +%% {Addr, Port}; +%% transform_taddr({{?transportDomainUdpIpv6, +%% [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]}, _MsgData}) -> % v3 +%% Addr = {A1, A2, A3, A4, A5, A6, A7, A8}, +%% Port = P1 bsl 8 + P2, +%% {Addr, Port}. + check_all_varbinds(#notification{oid = Oid}, Vbs, MibView) -> diff --git a/lib/snmp/src/misc/snmp_pdus.erl b/lib/snmp/src/misc/snmp_pdus.erl index 15156f7467..a780fee7a3 100644 --- a/lib/snmp/src/misc/snmp_pdus.erl +++ b/lib/snmp/src/misc/snmp_pdus.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -664,7 +664,20 @@ enc_value('BITS', Val) -> enc_oct_str_tag(bits_to_str(Val)); enc_value('OBJECT IDENTIFIER', Val) -> enc_oid_tag(Val); -enc_value('IpAddress', Val) -> +enc_value('IpAddress', {A, B, C, D}) -> + enc_value('IpAddress', [A,B,C,D]); +enc_value('IpAddress', {A, B, C, D, E, F, G, H}) -> + enc_value( + 'IpAddress', + [A bsr 8, A band 255, + B bsr 8, B band 255, + C bsr 8, C band 255, + D bsr 8, D band 255, + E bsr 8, E band 255, + F bsr 8, F band 255, + G bsr 8, G band 255, + H bsr 8, H band 255]); +enc_value('IpAddress', Val) when is_list(Val) -> Bytes2 = enc_oct_str_notag(Val), Len2 = elength(length(Bytes2)), lists:append([64 | Len2],Bytes2); -- cgit v1.2.3 From 79bfddd5d49d26f45c9813738f7c29e8e3afee19 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 14 May 2014 09:26:57 +0200 Subject: Bugfix: argument order to internal function verify_lines/4 --- lib/snmp/src/misc/snmp_config.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 5dffed8068..b1a99accf2 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -2623,15 +2623,15 @@ read_and_parse_term(Fd, StartLine) -> Other end. -verify_lines([], _, Acc, _) -> +verify_lines([], _, _, Acc) -> list:reverse(Acc); verify_lines( - [{StartLine, Term, EndLine}|Lines], State, Acc, Check) -> + [{StartLine, Term, EndLine}|Lines], Check, State, Acc) -> try Check(Term, State) of {ok, NewState} -> - verify_lines(Lines, NewState, [Term|Acc], Check); + verify_lines(Lines, Check, NewState, [Term|Acc]); {{ok, NewTerm}, NewState} -> - verify_lines(Lines, NewState, [NewTerm|Acc], Check) + verify_lines(Lines, Check, NewState, [NewTerm|Acc]) catch {error, Reason} -> throw({failed_check, StartLine, EndLine, Reason}); -- cgit v1.2.3 From b012122510b88bd752652bbd400cc03e68c45a7e Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 14 May 2014 13:17:06 +0200 Subject: bugfix: Call to non-existing module 'list' --- lib/snmp/src/misc/snmp_config.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index b1a99accf2..7e52d68fa1 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -2624,7 +2624,7 @@ read_and_parse_term(Fd, StartLine) -> end. verify_lines([], _, _, Acc) -> - list:reverse(Acc); + lists:reverse(Acc); verify_lines( [{StartLine, Term, EndLine}|Lines], Check, State, Acc) -> try Check(Term, State) of -- cgit v1.2.3 From 9a955974c52baa62ca7283f86257ddca59d4dfd3 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 14 May 2014 08:22:23 +0200 Subject: wip: Fix agent logging --- lib/snmp/src/agent/snmpa_agent.erl | 10 +- lib/snmp/src/agent/snmpa_mpd.erl | 30 +++-- lib/snmp/src/agent/snmpa_net_if.erl | 262 +++++++++++++++++------------------- lib/snmp/src/misc/snmp_conf.erl | 15 ++- lib/snmp/src/misc/snmp_config.erl | 4 +- lib/snmp/src/misc/snmp_log.erl | 187 ++++++++++++++++--------- lib/snmp/test/snmp_conf_test.erl | 2 + 7 files changed, 285 insertions(+), 225 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index dadd9d7ccd..6d3f1cca4a 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -2516,7 +2516,15 @@ process_msg( MibView, Vsn, Pdu, PduMS, Community, SourceAddress, ContextName, GbMaxVBs) -> #pdu{request_id = ReqId} = Pdu, - put(snmp_address, SourceAddress), + put( + snmp_address, + case SourceAddress of + {Domain, _} when is_atom(Domain) -> + SourceAddress; + {Ip, Port} when is_integer(Port) -> + %% Legacy transport domain + {tuple_to_list(Ip), Port} + end), put(snmp_request_id, ReqId), put(snmp_community, Community), put(snmp_context, ContextName), diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index 3caed27c42..dbd57b732c 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -192,24 +192,28 @@ discarded_pdu(Variable) -> inc(Variable). %% Handles a Community based message (v1 or v2c). %%----------------------------------------------------------------- v1_v2c_proc( - Vsn, NoteStore, Community, {Domain, Address}, + Vsn, NoteStore, Community, From, LocalEngineID, Data, HS, Log, Packet) -> - try snmp_conf:mk_tdomain(Domain) of - TDomain -> - try snmp_conf:mk_taddress(Domain, Address) of - TAddress -> - v1_v2c_proc_dec( - Vsn, NoteStore, Community, TDomain, TAddress, - LocalEngineID, Data, HS, Log, Packet) - catch - _ -> - {discarded, {badarg, Address}} - end + try + case From of + {D, A} when is_atom(D) -> + {snmp_conf:mk_tdomain(D), + snmp_conf:mk_taddress(D, A)}; + {_, P} = A when is_integer(P) -> + {snmp_conf:mk_tdomain(), + snmp_conf:mk_taddress(A)} + end + of + {TDomain, TAddress} -> + v1_v2c_proc_dec( + Vsn, NoteStore, Community, TDomain, TAddress, + LocalEngineID, Data, HS, Log, Packet) catch _ -> - {discarded, {badarg, Domain}} + {discarded, {badarg, From}} end. + v1_v2c_proc_dec( Vsn, NoteStore, Community, TDomain, TAddress, LocalEngineID, Data, HS, Log, Packet) -> diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 53eebb1728..42e93bff65 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -28,6 +28,7 @@ -export([system_continue/3, system_terminate/4, system_code_change/4]). -export([init/5]). -export([filter_reset/1]). +-export([format_address/1]). -include("snmp_types.hrl"). -include("snmpa_internal.hrl"). @@ -47,7 +48,7 @@ limit = infinity, rcnt = [], filter, - use_tdomain = false}). + domain = snmpUDPDomain}). -ifndef(default_verbosity). -define(default_verbosity,silence). @@ -166,13 +167,6 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> %% -- Port and address -- Domain = get_domain(), ?vdebug("domain: ~w",[Domain]), - UseTDomain = - case Domain of - snmpUDPDomain -> - false; - _ -> - true - end, UDPPort = get_port(), ?vdebug("port: ~w",[UDPPort]), IPAddress = get_address(), @@ -187,7 +181,7 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> ?vdebug("Limit: ~w", [Limit]), FilterOpts = get_filter_opts(Opts), FilterMod = create_filter(FilterOpts), - ?vdebug("FilterMod: ~w", [FilterMod]), + ?vdebug("FilterMod: ~w FilterOpts: ~p", [FilterMod,FilterOpts]), %% -- Audit trail log Log = create_log(), @@ -202,7 +196,6 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> IPOpts = [binary, snmp_conf:tdomain_to_family(Domain) | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4], - ?vdebug("open socket with options: ~w",[IPOpts]), case gen_udp_open(UDPPort, IPOpts) of {ok, Sock} -> MpdState = snmpa_mpd:init(Vsns), @@ -217,7 +210,7 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> log = Log, limit = Limit, filter = FilterMod, - use_tdomain = UseTDomain}, + domain = Domain}, ?vdebug("started with MpdState: ~p", [MpdState]), {ok, S}; {error, Reason} -> @@ -278,50 +271,69 @@ create_filter(BadOpts) -> throw({error, {bad_filter_opts, BadOpts}}). -log(LogTypes, Req, Packet, {Domain, Address}) -> - log(LogTypes, Req, Packet, Domain, Address). - -log({_, []}, _, _, _, _) -> +log({_, []}, _, _, _) -> ok; -log({Log, Types}, 'set-request', Packet, Domain, Address) -> +log({Log, Types}, 'set-request', Packet, Address) -> case lists:member(write, Types) of true -> - snmp_log:log(Log, Packet, Domain, Address); + snmp_log:log(Log, Packet, format_address(Address)); false -> ok end; -log({Log, Types}, _, Packet, Domain, Address) -> +log({Log, Types}, _, Packet, Address) -> case lists:member(read, Types) of true -> - snmp_log:log(Log, Packet, Domain, Address); + snmp_log:log(Log, Packet, format_address(Address)); false -> ok - end; -log(_, _, _, _, _) -> - ok. + end. +%% log(_, _, _, _, _) -> +%% ok. + +format_address({snmpUDPDomain, {_Ip, Port} = Addr}) when is_integer(Port) -> + format_address(Addr); +format_address({transportDomainUdpIpv4, {Ip, Port}}) -> + format_address("udpIpv4/~s:~w", [inet:ntoa(Ip), Port]); +format_address({transportDomainUdpIpv6, {Ip, Port}}) -> + format_address("udpIpv6/[~s]:~w", [inet:ntoa(Ip), Port]); +format_address({Ip, Port}) when is_integer(Port) -> + format_address("~s:~w", [inet:ntoa(Ip), Port]). + +format_address(Format, Args) -> + iolist_to_binary(io_lib:format(Format, Args)). + gen_udp_open(Port, Opts) -> case init:get_argument(snmp_fd) of {ok, [[FdStr]]} -> Fd = list_to_integer(FdStr), + ?vdebug("gen_udp_open(~p, ~p) Fd: ~p",[Port,Opts,Fd]), gen_udp:open(0, [{fd, Fd}|Opts]); error -> case init:get_argument(snmpa_fd) of {ok, [[FdStr]]} -> Fd = list_to_integer(FdStr), + ?vdebug("gen_udp_open(~p, ~p) Fd: ~p",[Port,Opts,Fd]), gen_udp:open(0, [{fd, Fd}|Opts]); error -> + ?vdebug("gen_udp_open(~p, ~p)",[Port,Opts]), gen_udp:open(Port, Opts) end end. -loop(S) -> +loop(#state{domain = Domain} = S) -> receive {udp, _UdpId, Ip, Port, Packet} -> ?vlog("got paket from ~w:~w",[Ip,Port]), - From = snmp_conf:ip_port_to_domaddr(Ip, Port), + From = + case Domain of + snmpUDPDomain -> + {Ip, Port}; + _ -> + {Domain, {Ip, Port}} + end, NewS = maybe_handle_recv(S, From, Packet), loop(NewS); @@ -550,22 +562,15 @@ update_req_counter_outgoing(#state{limit = Limit, rcnt = RCnt} = S, maybe_handle_recv( - #state{usock = Sock, filter = FilterMod, use_tdomain = UseTDomain} = S, - {Domain, Addr} = From, Packet) -> + #state{usock = Sock, filter = FilterMod} = S, From, Packet) -> + {From_1, From_2} = From, case - try - case UseTDomain of - true -> - FilterMod:accept_recv(Domain, Addr); - false -> - {Ip, Port} = Addr, - FilterMod:accept_recv(Ip, Port) - end + try FilterMod:accept_recv(From_1, From_2) catch Class:Exception -> error_msg( - "FilterMod:accept_recv/2 crashed for ~p: ~w:~w~n ~p", - [From,Class,Exception,erlang:get_stacktrace()]), + "FilterMod:accept_recv(~p, ~p) crashed: ~w:~w~n ~p", + [From_1,From_2,Class,Exception,erlang:get_stacktrace()]), true end of @@ -580,8 +585,8 @@ maybe_handle_recv( ok; _ -> error_msg( - "FilterMod:accept_recv/2 returned: ~p for ~p", - [Other,From]) + "FilterMod:accept_recv(~p, ~p) returned: ~p", + [From_1,From_2,Other]) end, handle_recv(S, From, Packet) end. @@ -634,15 +639,13 @@ handle_recv( ?vlog("sending report for reason: " "~n ~s", [?vapply(snmp_misc, format, [256, "~w", [Reason]])]), - {_Domain, {Ip, Port}} = From, - (catch udp_send(S#state.usock, Ip, Port, ReportPacket)), + (catch udp_send(S#state.usock, From, ReportPacket)), active_once(Sock), S; {discovery, ReportPacket} -> ?vlog("sending discovery report", []), - {_Domain, {Ip, Port}} = From, - (catch udp_send(S#state.usock, Ip, Port, ReportPacket)), + (catch udp_send(S#state.usock, From, ReportPacket)), active_once(Sock), S; @@ -654,24 +657,19 @@ handle_recv( end. maybe_handle_recv_pdu( - {Domain, Addr} = From, Vsn, + From, Vsn, #pdu{type = Type} = Pdu, PduMS, ACMData, - #state{usock = Sock, filter = FilterMod, use_tdomain = UseTDomain} = S) -> + #state{usock = Sock, filter = FilterMod} = S) -> + {From_1, From_2} = From, case - try - case UseTDomain of - true -> - FilterMod:accept_recv_pdu(Domain, Addr, Type); - false -> - {Ip, Port} = Addr, - FilterMod:accept_recv_pdu(Ip, Port, Type) - end + try FilterMod:accept_recv_pdu(From_1, From_2, Type) catch Class:Exception -> error_msg( - "FilterMod:accept_recv_pdu/3 crashed for ~p, ~p: ~w:~w~n" + "FilterMod:accept_recv_pdu(~p, ~p, ~p) crashed: ~w:~w~n" " ~p", - [From,Type,Class,Exception,erlang:get_stacktrace()]), + [From_1,From_2,Type,Class,Exception, + erlang:get_stacktrace()]), true end of @@ -685,13 +683,11 @@ maybe_handle_recv_pdu( ok; _ -> error_msg( - "FilterMod:accept_recv_pdu/3 returned: ~p for ~p, ~p", - [Other,From,Type]) + "FilterMod:accept_recv_pdu(~p, ~p, ~p) returned: ~p", + [From_1,From_2,Type,Other]) end, handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S) - end; -maybe_handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S) -> - handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S). + end. handle_recv_pdu( From, Vsn, @@ -717,17 +713,12 @@ handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, maybe_handle_reply_pdu( - #state{filter = FilterMod, use_tdomain = UseTDomain} = S, Vsn, + #state{filter = FilterMod} = S, Vsn, #pdu{request_id = Rid} = Pdu, - Type, ACMData, {_Domain, Addr} = To) -> + Type, ACMData, To) -> + S1 = update_req_counter_outgoing(S, Rid), - Addresses = - case UseTDomain of - true -> - [To]; - false -> - [Addr] - end, + Addresses = [To], case try FilterMod:accept_send_pdu(Addresses, Type) @@ -778,7 +769,7 @@ handle_reply_pdu(#state{log = Log} = S, Vsn, Pdu, Type, ACMData, To) -> maybe_handle_send_pdu( - #state{filter = FilterMod, use_tdomain = UseTDomain} = S, + #state{filter = FilterMod, domain = Domain} = S, Vsn, Pdu, MsgData, TDomAddrSecs, From) -> ?vtrace("maybe_handle_send_pdu -> entry with~n" @@ -787,24 +778,24 @@ maybe_handle_send_pdu( DomAddrSecs = snmpa_mpd:process_taddrs(TDomAddrSecs), AddressesToFilter = - [case UseTDomain of - true -> + [case Domain of + snmpUDPDomain -> case DAS of - {{Domain, _Address} = DomAddr, _SecData} - when is_atom(Domain) -> % v3 - DomAddr; - {Domain, _Address} = DomAddr - when is_atom(Domain) -> % v1 & v2 - DomAddr + {{Dom, Addr}, _SecData} + when is_atom(Dom) -> % v3 + Addr; + {Dom, Addr} + when is_atom(Dom) -> % v1 & v2 + Addr end; - false -> + _ -> case DAS of - {{Domain, Address}, _SecData} - when is_atom(Domain) -> % v3 - Address; - {Domain, Address} - when is_atom(Domain) -> % v1 & v2 - Address + {{Dom, _Addr} = DomAddr, _SecData} + when is_atom(Dom) -> % v3 + DomAddr; + {Dom, _Addr} = DomAddr + when is_atom(Dom) -> % v1 & v2 + DomAddr end end || DAS <- DomAddrSecs], Type = pdu_type_of(Pdu), @@ -830,24 +821,24 @@ maybe_handle_send_pdu( [DAS || DAS <- DomAddrSecs, lists:member( - case UseTDomain of + case Domain of + snmpUDPDomain -> + case DAS of + {{Dom, Addr}, _SData} + when is_atom(Dom) -> % v3 + Addr; + {Dom, Addr} + when is_atom(Dom) -> % v1 & v2 + Addr + end; true -> case DAS of - {{Domain, _Address} = DomAddr, _SData} - when is_atom(Domain) -> % v3 + {{Dom, _Addr} = DomAddr, _SData} + when is_atom(Dom) -> % v3 DomAddr; - {Domain, _Address} = DomAddr - when is_atom(Domain) -> % v1 & v2 + {Dom, _Addr} = DomAddr + when is_atom(Dom) -> % v1 & v2 DomAddr - end; - false -> - case DAS of - {{Domain, Address}, _SData} - when is_atom(Domain) -> % v3 - Address; - {Domain, Address} - when is_atom(Domain) -> % v1 & v2 - Address end end, FilteredAddresses)], ?vtrace("maybe_handle_send_pdu -> MergedDomAddrSecs:~n" @@ -909,9 +900,8 @@ handle_send_discovery( case (catch snmpa_mpd:generate_discovery_msg(NS, Pdu, MsgData, To)) of {ok, {Domain, Address, Packet}} -> - log(Log, Type, Packet, Domain, Address), - {Ip, Port} = Address, - udp_send(Sock, Ip, Port, Packet), + log(Log, Type, Packet, {Domain, Address}), + udp_send(Sock, {Domain, Address}, Packet), ?vtrace("handle_send_discovery -> sent (~w)", [ReqId]), NReqs = snmp_misc:keyreplaceadd(From, 2, Reqs, {ReqId, From}), S#state{reqs = NReqs}; @@ -975,22 +965,16 @@ handle_response(Vsn, Pdu, From, S) -> end. maybe_udp_send( - #state{usock = Sock, filter = FilterMod, use_tdomain = UseTDomain}, - {Domain, Addr} = To, Packet) -> + #state{usock = Sock, filter = FilterMod}, + To, Packet) -> + {To_1, To_2} = To, case - try - case UseTDomain of - true -> - FilterMod:accept_send(Domain, Addr); - false -> - {Ip, Port} = Addr, - FilterMod:accept_send(Ip, Port) - end + try FilterMod:accept_send(To_1, To_2) catch Class:Exception -> error_msg( - "FilterMod:accept_send/2 crashed for ~p: ~w:~w~n ~p", - [To,Class,Exception,erlang:get_stacktrace()]), + "FilterMod:accept_send(~p, ~p) crashed: ~w:~w~n ~p", + [To_1,To_2,Class,Exception,erlang:get_stacktrace()]), true end of @@ -1003,34 +987,26 @@ maybe_udp_send( ok; _ -> error_msg( - "FilterMod:accept_send/2 returned: ~p for ~p", - [Other,To]) + "FilterMod:accept_send(~p, ~p) returned: ~p", + [To_1,To_2,Other]) end, %% XXX should be some kind of lookup of domain to socket - {SockIp, SockPort} = Addr, - (catch udp_send(Sock, SockIp, SockPort, Packet)) + (catch udp_send(Sock, To, Packet)) end. maybe_udp_send( #state{log = Log, usock = Sock, - filter = FilterMod, - use_tdomain = UseTDomain}, - {Domain, Addr} = To, Packet, Type, _LogData) -> + filter = FilterMod}, + To, Packet, Type, _LogData) -> + {To_1, To_2} = To, case - try - case UseTDomain of - true -> - FilterMod:accept_send(Domain, Addr); - false -> - {Ip, Port} = Addr, - FilterMod:accept_send(Ip, Port) - end + try FilterMod:accept_send(To_1, To_2) catch Class:Exception -> error_msg( - "FilterMod:accept_send/2 crashed for ~p: ~w:~w~n ~p", - [To,Class,Exception,erlang:get_stacktrace()]), + "FilterMod:accept_send(~p, ~p) crashed for: ~w:~w~n ~p", + [To_1,To_2,Class,Exception,erlang:get_stacktrace()]), true end of @@ -1043,28 +1019,34 @@ maybe_udp_send( ok; _ -> error_msg( - "FilterMod:accept_send/2 returned: ~p for ~p", - [Other,To]) + "FilterMod:accept_send(~p, ~p) returned: ~p", + [To_1,To_2,Other]) end, log(Log, Type, Packet, To), - %% XXX should be some kind of lookup of domain to socket - {SockIp, SockPort} = Addr, - (catch udp_send(Sock, SockIp, SockPort, Packet)) + (catch udp_send(Sock, To, Packet)) end. -udp_send(UdpId, AgentIp, UdpPort, B) -> - case (catch gen_udp:send(UdpId, AgentIp, UdpPort, B)) of +udp_send(UdpId, To, B) -> + %% XXX should be some kind of lookup of domain to socket + {Ip, Port} = + case To of + {Domain, Addr} when is_atom(Domain) -> + Addr; + {_, P} = Addr when is_integer(P) -> + Addr + end, + case (catch gen_udp:send(UdpId, Ip, Port, B)) of {error, emsgsize} -> %% From this message we cannot recover, so exit sending loop throw({emsgsize, sz(B)}); {error, ErrorReason} -> error_msg("[error] cannot send message " "(destination: ~p:~p, size: ~p, reason: ~p)", - [AgentIp, UdpPort, sz(B), ErrorReason]); + [Ip, Port, sz(B), ErrorReason]); {'EXIT', ExitReason} -> error_msg("[exit] cannot send message " "(destination: ~p:~p, size: ~p, reason: ~p)", - [AgentIp, UdpPort, sz(B), ExitReason]); + [Ip, Port, sz(B), ExitReason]); _ -> ok end. @@ -1275,7 +1257,7 @@ get_counters([Counter|Counters], Acc) -> ip_opt_bind_to_ip_address(Opts, Ip) -> case get_bind_to_ip_address(Opts) of true -> - [{ip, list_to_tuple(Ip)}]; + [{ip, Ip}]; _ -> [] end. diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 0cad61e5c8..bf1a025457 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -42,7 +42,7 @@ check_domain/1, all_tdomains/0, check_tdomain/1, - mk_tdomain/1, + mk_tdomain/0, mk_tdomain/1, tdomain_to_family/1, which_domain/1, check_ip/1, check_ip/2, @@ -50,7 +50,7 @@ ip_port_to_domaddr/2, check_address/2, check_address/3, check_taddress/2, - mk_taddress/2, + mk_taddress/1, mk_taddress/2, check_packet_size/1, @@ -462,6 +462,9 @@ check_tdomain(TDomain) -> %% --------- +mk_tdomain() -> + mk_tdomain(snmpUDPDomain). + mk_tdomain(snmpUDPDomain) -> mk_tdomain(transportDomainUdpIpv4); mk_tdomain(transportDomainUdpIpv4) -> @@ -598,14 +601,14 @@ check_domain(Domain) -> %% --------- +mk_taddress(Address) -> + mk_taddress(snmpUDPDomain, Address). + %% The values of Domain, Ip and Port has both been checked at this %% point, so we dont need to do that again, but this function is %% also used on incoming packets from net_if so a little %% check that net_if does not supply bad arguments is in order. %% -mk_taddress(snmpUDPDomain, Address) -> % Legacy - mk_taddress(transportDomainUdpIpv4, Address); -%% %% These are just for convenience mk_taddress(?snmpUDPDomain, Address) -> mk_taddress(snmpUDPDomain, Address); @@ -614,6 +617,8 @@ mk_taddress(?transportDomainUdpIpv4, Address) -> mk_taddress(?transportDomainUdpIpv6, Address) -> mk_taddress(transportDomainUdpIpv6, Address); %% +mk_taddress(snmpUDPDomain, Address) -> % Legacy + mk_taddress(transportDomainUdpIpv4, Address); mk_taddress(transportDomainUdpIpv4 = Domain, Address) -> case Address of [] -> % Empty mask diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 7e52d68fa1..6d0f14237e 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -1588,7 +1588,7 @@ write_agent_snmp_files( is_list(SysName) -> write_agent_snmp_files( Dir, Vsns, Domain, ManagerAddr, AgentAddr, SysName, - "trap", none, "", "agentEngine", 484). + trap, none, "", "agentEngine", 484). %%---------------------------------------------------------------------- %% Dir: string() (ex: "../conf/") @@ -1607,7 +1607,7 @@ write_agent_snmp_files( is_list(SysName) -> write_agent_snmp_files( Dir, Vsns, ManagerIP, TrapUDP, AgentIP, AgentUDP, SysName, - "trap", none, "", "agentEngine", 484). + trap, none, "", "agentEngine", 484). %% %% ----- Agent config files generator functions ----- diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index ae28df37fa..b3596909cd 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2012. All Rights Reserved. +%% Copyright Ericsson AB 1997-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -23,7 +23,7 @@ -export([ create/4, create/5, create/6, open/1, open/2, change_size/2, close/1, sync/1, info/1, - log/4, + log/3, log/4, log_to_txt/6, log_to_txt/7, log_to_txt/8, log_to_io/5, log_to_io/6, log_to_io/7 ]). @@ -344,12 +344,20 @@ validate_loop(Error, _Log, _Write, _PrevTS, _PrevSN) -> %% log(Log, Packet, Addr, Port) %%----------------------------------------------------------------- -log(#snmp_log{id = Log, seqno = SeqNo}, Packet, Addr, Port) -> +log(#snmp_log{id = Log, seqno = SeqNo}, Packet, AddrStr) -> + ?vtrace( + "log -> entry with~n" + " Log: ~p~n" + " AddrStr: ~s", [Log, AddrStr]), + Entry = make_entry(SeqNo, Packet, AddrStr), + disk_log:alog(Log, Entry). + +log(#snmp_log{id = Log, seqno = SeqNo}, Packet, Ip, Port) -> ?vtrace("log -> entry with" "~n Log: ~p" - "~n Addr: ~p" - "~n Port: ~p", [Log, Addr, Port]), - Entry = make_entry(SeqNo, Packet, Addr, Port), + "~n Ip: ~p" + "~n Port: ~p", [Log, Ip, Port]), + Entry = make_entry(SeqNo, Packet, Ip, Port), %% io:format("log -> " %% "~n Entry: ~p" %% "~n Info: ~p" @@ -361,18 +369,35 @@ log(#snmp_log{id = Log, seqno = SeqNo}, Packet, Addr, Port) -> %% "~n", [Res, disk_log:info(Log)]), %% disk_log:sync(Log), Res. - -make_entry(SeqNoGen, Packet, Addr, Port) -> + +make_entry(SeqNoGen, Packet, AddrStr) + when is_integer(Packet); + is_tuple(AddrStr) -> + erlang:error(badarg, [SeqNoGen, Packet, AddrStr]); +make_entry(SeqNoGen, Packet, AddrStr) -> + try next_seqno(SeqNoGen) of + disabled -> + {timestamp(), Packet, AddrStr}; + {ok, NextSeqNo} when is_integer(NextSeqNo) -> + {timestamp(), NextSeqNo, Packet, AddrStr} + catch + _:_ -> + {timestamp(), Packet, AddrStr} + end. + +make_entry(SeqNoGen, Packet, Ip, Port) when is_integer(Packet) -> + erlang:error(badarg, [SeqNoGen, Packet, Ip, Port]); +make_entry(SeqNoGen, Packet, Ip, Port) -> try next_seqno(SeqNoGen) of disabled -> - {timestamp(), Packet, Addr, Port}; - {ok, NextSeqNo} -> - {timestamp(), NextSeqNo, Packet, Addr, Port} + {timestamp(), Packet, Ip, Port}; + {ok, NextSeqNo} when is_integer(NextSeqNo) -> + {timestamp(), NextSeqNo, Packet, Ip, Port} catch _:_ -> - {timestamp(), Packet, Addr, Port} + {timestamp(), Packet, Ip, Port} end. next_seqno({M, F, A}) -> @@ -674,60 +699,68 @@ format_msg(Entry, Mib, Start, Stop) -> end. %% This is an old-style entry, that never had the sequence-number -do_format_msg({Timestamp, Packet, {Addr, Port}}, Mib) -> - do_format_msg(Timestamp, Packet, Addr, Port, Mib); +do_format_msg({Timestamp, Packet, {Ip, Port}}, Mib) -> + do_format_msg(Timestamp, Packet, ipPort2Str(Ip, Port), Mib); +%% This is the format without sequence-number +do_format_msg({Timestamp, Packet, AddrStr}, Mib) -> + do_format_msg(Timestamp, Packet, AddrStr, Mib); +%% This is the format with sequence-number +do_format_msg({Timestamp, SeqNo, Packet, AddrStr}, Mib) + when is_integer(SeqNo) -> + do_format_msg(Timestamp, Packet, AddrStr, Mib); %% This is the format without sequence-number -do_format_msg({Timestamp, Packet, Addr, Port}, Mib) -> - do_format_msg(Timestamp, Packet, Addr, Port, Mib); +do_format_msg({Timestamp, Packet, Ip, Port}, Mib) -> + do_format_msg(Timestamp, Packet, ipPort2Str(Ip, Port), Mib); %% This is the format with sequence-number -do_format_msg({Timestamp, SeqNo, Packet, Addr, Port}, Mib) -> - do_format_msg(Timestamp, SeqNo, Packet, Addr, Port, Mib); +do_format_msg({Timestamp, SeqNo, Packet, Ip, Port}, Mib) -> + do_format_msg(Timestamp, SeqNo, Packet, ipPort2Str(Ip, Port), Mib); %% This is crap... do_format_msg(_, _) -> format_tab("** unknown entry in log file\n\n", []). -do_format_msg(TimeStamp, {V3Hdr, ScopedPdu}, Addr, Port, Mib) -> +do_format_msg(TimeStamp, {V3Hdr, ScopedPdu}, AddrStr, Mib) -> case (catch snmp_pdus:dec_scoped_pdu(ScopedPdu)) of ScopedPDU when is_record(ScopedPDU, scopedPdu) -> Msg = #message{version = 'version-3', vsn_hdr = V3Hdr, data = ScopedPDU}, - f(ts2str(TimeStamp), "", Msg, Addr, Port, Mib); + f(ts2str(TimeStamp), "", Msg, AddrStr, Mib); {'EXIT', Reason} -> - format_tab("** error in log file at ~s from ~p:~w ~p\n\n", - [ts2str(TimeStamp), ip(Addr), Port, Reason]) + format_tab( + "** error in log file at ~s from ~s ~p\n\n", + [ts2str(TimeStamp), AddrStr, Reason]) end; -do_format_msg(TimeStamp, Packet, Addr, Port, Mib) -> +do_format_msg(TimeStamp, Packet, AddrStr, Mib) -> case (catch snmp_pdus:dec_message(binary_to_list(Packet))) of Msg when is_record(Msg, message) -> - f(ts2str(TimeStamp), "", Msg, Addr, Port, Mib); + f(ts2str(TimeStamp), "", Msg, AddrStr, Mib); {'EXIT', Reason} -> format_tab("** error in log file ~p\n\n", [Reason]) end. -do_format_msg(TimeStamp, SeqNo, {V3Hdr, ScopedPdu}, Addr, Port, Mib) -> +do_format_msg(TimeStamp, SeqNo, {V3Hdr, ScopedPdu}, AddrStr, Mib) -> case (catch snmp_pdus:dec_scoped_pdu(ScopedPdu)) of ScopedPDU when is_record(ScopedPDU, scopedPdu) -> Msg = #message{version = 'version-3', vsn_hdr = V3Hdr, data = ScopedPDU}, - f(ts2str(TimeStamp), sn2str(SeqNo), Msg, Addr, Port, Mib); + f(ts2str(TimeStamp), sn2str(SeqNo), Msg, AddrStr, Mib); {'EXIT', Reason} -> - format_tab("** error in log file at ~s from ~p:~w ~p\n\n", - [ts2str(TimeStamp), sn2str(SeqNo), - ip(Addr), Port, Reason]) + format_tab( + "** error in log file at ~s from ~s ~p\n\n", + [ts2str(TimeStamp), sn2str(SeqNo), AddrStr, Reason]) end; -do_format_msg(TimeStamp, SeqNo, Packet, Addr, Port, Mib) -> +do_format_msg(TimeStamp, SeqNo, Packet, AddrStr, Mib) -> case (catch snmp_pdus:dec_message(binary_to_list(Packet))) of Msg when is_record(Msg, message) -> - f(ts2str(TimeStamp), sn2str(SeqNo), Msg, Addr, Port, Mib); + f(ts2str(TimeStamp), sn2str(SeqNo), Msg, AddrStr, Mib); {'EXIT', Reason} -> - format_tab("** error in log file ~s from ~p:~w ~p\n\n", - [ts2str(TimeStamp), sn2str(SeqNo), - ip(Addr), Port, Reason]) + format_tab( + "** error in log file ~s from ~s ~p\n\n", + [ts2str(TimeStamp), sn2str(SeqNo), AddrStr, Reason]) end. @@ -771,44 +804,70 @@ do_format_msg(TimeStamp, SeqNo, Packet, Addr, Port, Mib) -> f(TimeStamp, SeqNo, #message{version = Vsn, vsn_hdr = VsnHdr, data = Data}, - Addr, Port, Mib) -> + AddrStr, Mib) -> Str = format_pdu(Data, Mib), HdrStr = format_header(Vsn, VsnHdr), - case get_type(Data) of - trappdu -> - f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - 'snmpv2-trap' -> - f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - 'inform-request' -> - f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - 'get-response' -> - f_response(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - report -> - f_report(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); - _ -> - f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) - end. + Class = + case get_type(Data) of + trappdu -> + trap; + 'snmpv2-trap' -> + trap; + 'inform-request' -> + inform; + 'get-response' -> + response; + report -> + report; + _ -> + request + end, + format_tab( + "~w ~s - ~s [~s]~s ~w\n~s", + [Class, AddrStr, HdrStr, TimeStamp, SeqNo, Vsn, Str]). + +%% f(TimeStamp, SeqNo, +%% #message{version = Vsn, vsn_hdr = VsnHdr, data = Data}, +%% Addr, Port, Mib) -> +%% Str = format_pdu(Data, Mib), +%% HdrStr = format_header(Vsn, VsnHdr), +%% case get_type(Data) of +%% trappdu -> +%% f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); +%% 'snmpv2-trap' -> +%% f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); +%% 'inform-request' -> +%% f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); +%% 'get-response' -> +%% f_response(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); +%% report -> +%% f_report(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port); +%% _ -> +%% f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) +%% end. -f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> - format_tab("request ~s:~w - ~s [~s]~s ~w\n~s", - [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). +%% f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> +%% format_tab("request ~s:~w - ~s [~s]~s ~w\n~s", +%% [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). -f_response(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> - format_tab("response ~s:~w - ~s [~s]~s ~w\n~s", - [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). +%% f_response(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> +%% format_tab("response ~s:~w - ~s [~s]~s ~w\n~s", +%% [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). -f_report(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> - format_tab("report ~s:~w - ~s [~s]~s ~w\n~s", - [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). +%% f_report(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> +%% format_tab("report ~s:~w - ~s [~s]~s ~w\n~s", +%% [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). -f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> - format_tab("trap ~s:~w - ~s [~s]~s ~w\n~s", - [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). +%% f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> +%% format_tab("trap ~s:~w - ~s [~s]~s ~w\n~s", +%% [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). -f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> - format_tab("inform ~s:~w - ~s [~s]~s ~w\n~s", - [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). +%% f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) -> +%% format_tab("inform ~s:~w - ~s [~s]~s ~w\n~s", +%% [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). +ipPort2Str(Ip, Port) -> + io_lib:format("~s:~w", [ip(Ip), Port]). %% Convert a timestamp 2-tupple to a printable string %% diff --git a/lib/snmp/test/snmp_conf_test.erl b/lib/snmp/test/snmp_conf_test.erl index 5c8acb48a5..7f5d11c0e7 100644 --- a/lib/snmp/test/snmp_conf_test.erl +++ b/lib/snmp/test/snmp_conf_test.erl @@ -373,6 +373,8 @@ verify_ip(Val) -> case (catch snmp_conf:check_ip(Val)) of {error, Reason} -> ?FAIL({verify_ip, Val, Reason}); + {ok, _} -> + ok; ok -> ok end. -- cgit v1.2.3 From c1104d6708917d7ec0b3b77340242b679ee10122 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 16 May 2014 15:11:05 +0200 Subject: wip: Testcase feedback --- lib/snmp/src/agent/snmp_framework_mib.erl | 2 ++ lib/snmp/src/agent/snmp_generic.erl | 30 ++++++++++++++++++++++++++---- lib/snmp/src/agent/snmpa_local_db.erl | 6 +++++- lib/snmp/src/misc/snmp_conf.erl | 2 ++ 4 files changed, 35 insertions(+), 5 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index fb52f90852..6589ace949 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -227,6 +227,8 @@ order_agent({Name, _}, {Name, _}) -> true; %% Less than or equal order_agent({_, _}, {intAgentTransportDomain, _}) -> false; %% Greater than +order_agent({intAgentTransportDomain, _}, {_, _}) -> + true; %% Less than or equal order_agent({A, _}, {B, _}) -> A =< B. diff --git a/lib/snmp/src/agent/snmp_generic.erl b/lib/snmp/src/agent/snmp_generic.erl index 06afa68d96..3195ca2500 100644 --- a/lib/snmp/src/agent/snmp_generic.erl +++ b/lib/snmp/src/agent/snmp_generic.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -414,7 +414,12 @@ table_check_status(NameDb, Col, ?'RowStatus_createAndGo', RowIndex, Cols) -> % side effect free and we only use the result temporary. case catch snmpa_local_db:table_construct_row( NameDb, RowIndex, ?'RowStatus_createAndGo', Cols) of - {'EXIT', _} -> + {'EXIT', _Reason} -> + ?vtrace( + "failed construct row (createAndGo): " + " n Reason: ~p" + " n Stack: ~p", + [_Reason, erlang:get_stacktrace()]), {noCreation, Col}; % Bad RowIndex Row -> case lists:member(noinit, tuple_to_list(Row)) of @@ -431,7 +436,12 @@ table_check_status(NameDb, Col, ?'RowStatus_createAndWait', RowIndex, Cols) -> false -> case catch snmpa_local_db:table_construct_row( NameDb, RowIndex, ?'RowStatus_createAndGo', Cols) of - {'EXIT', _} -> + {'EXIT', _Reason} -> + ?vtrace( + "failed construct row (createAndWait): " + " n Reason: ~p" + " n Stack: ~p", + [_Reason, erlang:get_stacktrace()]), {noCreation, Col}; % Bad RowIndex _Row -> {noError, 0} @@ -711,7 +721,19 @@ find_col(Col, [_H | T]) -> find_col(Col, T). try_apply(nofunc, _) -> {noError, 0}; -try_apply(F, Args) -> apply(F, Args). +try_apply(F, Args) -> maybe_verbose_apply(F, Args). + +maybe_verbose_apply(M, Args) -> + case get(verbosity) of + false -> + apply(M, Args); + _ -> + ?vlog("~n apply: ~w,~p~n", [M,Args]), + Res = apply(M,Args), + ?vlog("~n returned: ~p", [Res]), + Res + end. + table_info({Name, _Db}) -> case snmpa_symbolic_store:table_info(Name) of diff --git a/lib/snmp/src/agent/snmpa_local_db.erl b/lib/snmp/src/agent/snmpa_local_db.erl index f991244287..292c370d51 100644 --- a/lib/snmp/src/agent/snmpa_local_db.erl +++ b/lib/snmp/src/agent/snmpa_local_db.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -1011,6 +1011,10 @@ table_construct_row(Name, RowIndex, Status, Cols) -> defvals = Defs, status_col = StatusCol, first_own_index = FirstOwnIndex, not_accessible = NoAccs} = snmp_generic:table_info(Name), + ?vtrace( + "table_construct_row Indexes: ~p~n" + " RowIndex: ~p", + [Indexes, RowIndex]), Keys = snmp_generic:split_index_to_keys(Indexes, RowIndex), OwnKeys = snmp_generic:get_own_indexes(FirstOwnIndex, Keys), Row = OwnKeys ++ snmp_generic:table_create_rest(length(OwnKeys) + 1, diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index bf1a025457..594cfce705 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -191,6 +191,8 @@ read_fd(File, Order, Check, Fd, StartLine, Res) -> Order(RowA, RowB) end, lists:reverse(Res)), + ?vtrace("read_fd to read_check ->~n" + " Lines: ~p", [Lines]), read_check(File, Check, Lines, undefined, []) end. -- cgit v1.2.3 From cc1ab998ce905cd673c7ea14ee4e31ddb2412350 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 20 May 2014 15:15:43 +0200 Subject: Don't encode IPv6 address into v1 trap and fix legacy arguments to snmpa_network_interface_filter functions --- lib/snmp/src/agent/snmpa_mpd.erl | 18 +++++++- lib/snmp/src/agent/snmpa_net_if.erl | 48 ++++++++++++-------- lib/snmp/src/agent/snmpa_trap.erl | 87 +++++++++++++++++++++++++++++-------- lib/snmp/src/misc/snmp_conf.erl | 13 ++++-- lib/snmp/src/misc/snmp_pdus.erl | 13 +----- 5 files changed, 126 insertions(+), 53 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index dbd57b732c..642b1f7fc5 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -1103,8 +1103,22 @@ transform_taddr(?transportDomainUdpIpv4, [A, B, C, D, P1, P2]) -> {ok, {Domain, Address}}; transform_taddr(?transportDomainUdpIpv4, BadAddr) -> {error, {bad_transportDomainUdpIpv4_address, BadAddr}}; -transform_taddr(?transportDomainUdpIpv6, - [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]) -> +transform_taddr( + ?transportDomainUdpIpv6, + [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, + P1, P2]) -> + Domain = transportDomainUdpIpv6, + Addr = + {(A1 bsl 8) bor A2, (A3 bsl 8) bor A4, + (A5 bsl 8) bor A6, (A7 bsl 8) bor A8, + (A9 bsl 8) bor A10, (A11 bsl 8) bor A12, + (A13 bsl 8) bor A14, (A15 bsl 8) bor A16}, + Port = P1 bsl 8 + P2, + Address = {Addr, Port}, + {ok, {Domain, Address}}; +transform_taddr( + ?transportDomainUdpIpv6, + [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]) -> Domain = transportDomainUdpIpv6, Addr = {A1, A2, A3, A4, A5, A6, A7, A8}, Port = P1 bsl 8 + P2, diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 42e93bff65..2c800db8b6 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -327,13 +327,7 @@ loop(#state{domain = Domain} = S) -> receive {udp, _UdpId, Ip, Port, Packet} -> ?vlog("got paket from ~w:~w",[Ip,Port]), - From = - case Domain of - snmpUDPDomain -> - {Ip, Port}; - _ -> - {Domain, {Ip, Port}} - end, + From = fix_filter_address(Domain, {Domain, {Ip, Port}}), NewS = maybe_handle_recv(S, From, Packet), loop(NewS); @@ -604,7 +598,7 @@ handle_discovery_response(_From, #pdu{request_id = ReqId} = Pdu, %% Ouch, timeout? resend? S end. - + handle_recv( #state{usock = Sock, mpd_state = MpdState, @@ -655,7 +649,7 @@ handle_recv( active_once(Sock), S end. - + maybe_handle_recv_pdu( From, Vsn, #pdu{type = Type} = Pdu, PduMS, ACMData, @@ -713,12 +707,13 @@ handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, maybe_handle_reply_pdu( - #state{filter = FilterMod} = S, Vsn, + #state{filter = FilterMod, domain = Domain} = S, Vsn, #pdu{request_id = Rid} = Pdu, Type, ACMData, To) -> S1 = update_req_counter_outgoing(S, Rid), - Addresses = [To], + %% Addresses = [To], + Addresses = [fix_filter_address(Domain, To)], case try FilterMod:accept_send_pdu(Addresses, Type) @@ -965,9 +960,10 @@ handle_response(Vsn, Pdu, From, S) -> end. maybe_udp_send( - #state{usock = Sock, filter = FilterMod}, + #state{usock = Sock, filter = FilterMod, domain = Domain}, To, Packet) -> - {To_1, To_2} = To, + %% {To_1, To_2} = To, + {To_1, To_2} = fix_filter_address(Domain, To), case try FilterMod:accept_send(To_1, To_2) catch @@ -995,11 +991,14 @@ maybe_udp_send( end. maybe_udp_send( - #state{log = Log, - usock = Sock, - filter = FilterMod}, + #state{ + log = Log, + usock = Sock, + filter = FilterMod, + domain = Domain}, To, Packet, Type, _LogData) -> - {To_1, To_2} = To, + %% {To_1, To_2} = To, + {To_1, To_2} = fix_filter_address(Domain, To), case try FilterMod:accept_send(To_1, To_2) catch @@ -1098,6 +1097,21 @@ active_once(Sock) -> inet:setopts(Sock, [{active, once}]). +%% If the agent uses legacy snmpUDPDomain e.g has not set +%% intAgentTransportDomain, then make sure +%% snmpa_network_interface_filter gets legacy arguments +%% to not break backwards compatibility. +%% +fix_filter_address(snmpUDPDomain, {Domain, Addr}) + when Domain =:= snmpUDPDomain; + Domain =:= transportDomainUdpIpv4 -> + Addr; +fix_filter_address(snmpUDPDomain, {_, Port} = Addr) + when is_integer(Port) -> + Addr; +fix_filter_address(_AgentDomain, Address) -> + Address. + %%%----------------------------------------------------------------- handle_set_log_type(#state{log = {Log, OldValue}} = State, NewType) diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index a2d821c099..ac0739860b 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -270,12 +270,13 @@ localise_type({VariableOid, Value}, Mib) when is_list(VariableOid) -> localise_type(X, _) -> X. %%----------------------------------------------------------------- -%% Func: make_v1_trap_pdu/4 +%% Func: make_v1_trap_pdu/5 %% Args: Enterprise = oid() %% Specific = integer() %% Varbinds is as returned from initiate_vars %% (but only {Oid, Type[, Value} permitted) %% SysUpTime = integer() +%% AgentIp = {A, B, C, D} %% Purpose: Make a #trappdu %% Checks the Varbinds to see that no symbolic names are %% present, and that each var has a type. Performs a get @@ -284,7 +285,7 @@ localise_type(X, _) -> X. %% Fails: yes %% NOTE: Executed at the MA %%----------------------------------------------------------------- -make_v1_trap_pdu(Enterprise, Specific, VarbindList, SysUpTime) -> +make_v1_trap_pdu(Enterprise, Specific, VarbindList, SysUpTime, AgentIp) -> {Enterp,Generic,Spec} = case Enterprise of ?snmp -> @@ -292,7 +293,6 @@ make_v1_trap_pdu(Enterprise, Specific, VarbindList, SysUpTime) -> _ -> {Enterprise,?enterpriseSpecific,Specific} end, - {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), #trappdu{enterprise = Enterp, agent_addr = AgentIp, generic_trap = Generic, @@ -369,6 +369,7 @@ send_trap(TrapRec, NotifyName, ContextName, Recv, Vbs, LocalEngineID, {tag, T}, {err, E}, {stacktrace, erlang:get_stacktrace()}], + ?vlog("snmpa_trap:send_trap exception: ~p", [Info]), {error, {failed_sending_trap, Info}} end. @@ -797,13 +798,32 @@ send_v1_trap(#trap{enterpriseoid = Enter, specificcode = Spec}, "~n ~p" "~n to" "~n ~p", [Enter, Spec, V1Res]), - TrapPdu = make_v1_trap_pdu(Enter, Spec, Vbs, SysUpTime), - AddrCommunities = mk_addr_communities(V1Res), - lists:foreach(fun({Community, Addrs}) -> - ?vtrace("send v1 trap pdu to ~p",[Addrs]), - NetIf ! {send_pdu, 'version-1', TrapPdu, - {community, Community}, Addrs, ExtraInfo} - end, AddrCommunities); + AgentDomain = + case snmp_framework_mib:intAgentTransportDomain(get) of + {value, AD} -> + AD; + genErr -> + snmp_target_mib:default_domain() + end, + case AgentDomain of + snmpUDPDomain -> + {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), + TrapPdu = make_v1_trap_pdu(Enter, Spec, Vbs, SysUpTime, AgentIp), + AddrCommunities = mk_addr_communities(V1Res), + lists:foreach( + fun ({Community, Addrs}) -> + ?vtrace("send v1 trap pdu to ~p",[Addrs]), + NetIf ! {send_pdu, 'version-1', TrapPdu, + {community, Community}, Addrs, ExtraInfo} + end, AddrCommunities); + _ -> + ?vtrace( + "snmpa_trap: can not send v1 trap with domain: ~w", + [AgentDomain]), + user_err( + "snmpa_trap: can not send v1 trap with domain: ~w", + [AgentDomain]) + end; send_v1_trap(#notification{oid = Oid}, V1Res, Vbs, ExtraInfo, NetIf, SysUpTime) -> %% Use alg. in rfc2089 to map a v2 trap to a v1 trap @@ -822,14 +842,33 @@ send_v1_trap(#notification{oid = Oid}, V1Res, Vbs, ExtraInfo, NetIf, {lists:reverse(First),Last} end end, - TrapPdu = make_v1_trap_pdu(Enter, Spec, NVbs, SysUpTime), - AddrCommunities = mk_addr_communities(V1Res), - lists:foreach(fun({Community, Addrs}) -> - ?vtrace("send v1 trap to ~p",[Addrs]), - NetIf ! {send_pdu, 'version-1', TrapPdu, - {community, Community}, Addrs, ExtraInfo} - end, AddrCommunities). - + AgentDomain = + case snmp_framework_mib:intAgentTransportDomain(get) of + {value, AD} -> + AD; + genErr -> + snmp_target_mib:default_domain() + end, + case AgentDomain of + snmpUDPDomain -> + {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), + TrapPdu = make_v1_trap_pdu(Enter, Spec, NVbs, SysUpTime, AgentIp), + AddrCommunities = mk_addr_communities(V1Res), + lists:foreach( + fun ({Community, Addrs}) -> + ?vtrace("send v1 trap to ~p",[Addrs]), + NetIf ! {send_pdu, 'version-1', TrapPdu, + {community, Community}, Addrs, ExtraInfo} + end, AddrCommunities); + _ -> + ?vtrace( + "snmpa_trap: can not send v1 trap with domain: ~w", + [AgentDomain]), + user_err( + "snmpa_trap: can not send v1 trap with domain: ~w", + [AgentDomain]) + end. + send_v2_trap(_TrapRec, [], _Vbs, _Recv, _ExtraInfo, _NetIf, _SysUpTime) -> ok; send_v2_trap(TrapRec, V2Res, Vbs, Recv, ExtraInfo, NetIf, SysUpTime) -> @@ -1116,9 +1155,19 @@ transform_taddr( [A1, A2, A3, A4, A5, A6, A7, A8, P1, P2]) -> Ip = {A1, A2, A3, A4, A5, A6, A7, A8}, Port = P1 bsl 8 + P2, + {Domain, {Ip, Port}}; +transform_taddr( + transportDomainUdpIpv6 = Domain, + [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, + P1, P2]) -> + Ip = + {(A1 bsl 8) bor A2, (A3 bsl 8) bor A4, + (A5 bsl 8) bor A6, (A7 bsl 8) bor A8, + (A9 bsl 8) bor A10, (A11 bsl 8) bor A12, + (A13 bsl 8) bor A14, (A15 bsl 8) bor A16}, + Port = P1 bsl 8 + P2, {Domain, {Ip, Port}}. - %% transform_taddr({?snmpUDPDomain, [A1, A2, A3, A4, P1, P2]}) -> % v2 %% Addr = {A1, A2, A3, A4}, %% Port = P1 bsl 8 + P2, diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 594cfce705..2d91cb1f55 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -634,9 +634,16 @@ mk_taddress(transportDomainUdpIpv6 = Domain, Address) -> case Address of [] -> % Empty mask []; - {Ip, Port} - when tuple_size(Ip) =:= 8, is_integer(Port) -> - tuple_to_list(Ip) ++ mk_bytes(Port); + {{A, B, C, D, E, F, G, H}, Port} -> + [A bsr 8, A band 255, + B bsr 8, B band 255, + C bsr 8, C band 255, + D bsr 8, D band 255, + E bsr 8, E band 255, + F bsr 8, F band 255, + G bsr 8, G band 255, + H bsr 8, H band 255, + Port bsr 8, Port band 255]; _ -> erlang:error(badarg, [Domain,Address]) end; diff --git a/lib/snmp/src/misc/snmp_pdus.erl b/lib/snmp/src/misc/snmp_pdus.erl index a780fee7a3..90fa4c0dea 100644 --- a/lib/snmp/src/misc/snmp_pdus.erl +++ b/lib/snmp/src/misc/snmp_pdus.erl @@ -174,7 +174,7 @@ dec_pdu_tag(168) -> dec_pdu([164 | Bytes]) -> % It's a trap Bytes2 = get_data_bytes(Bytes), {Enterprise, Rest1} = dec_oid_tag(Bytes2), - {{'IpAddress', AgentAddr}, Rest2} = dec_value(Rest1), + {{'IpAddress', [_, _, _, _] = AgentAddr}, Rest2} = dec_value(Rest1), {GenericTrap, Rest3} = dec_int_tag(Rest2), {SpecificTrap, Rest4} = dec_int_tag(Rest3), {{'TimeTicks', TimeStamp}, VBBytes} = dec_value(Rest4), @@ -666,17 +666,6 @@ enc_value('OBJECT IDENTIFIER', Val) -> enc_oid_tag(Val); enc_value('IpAddress', {A, B, C, D}) -> enc_value('IpAddress', [A,B,C,D]); -enc_value('IpAddress', {A, B, C, D, E, F, G, H}) -> - enc_value( - 'IpAddress', - [A bsr 8, A band 255, - B bsr 8, B band 255, - C bsr 8, C band 255, - D bsr 8, D band 255, - E bsr 8, E band 255, - F bsr 8, F band 255, - G bsr 8, G band 255, - H bsr 8, H band 255]); enc_value('IpAddress', Val) when is_list(Val) -> Bytes2 = enc_oct_str_notag(Val), Len2 = elength(length(Bytes2)), -- cgit v1.2.3 From e3f49c557c2cf0f4e98bbe538af4142167bac6ad Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 21 May 2014 14:33:50 +0200 Subject: Rewrite string representation of addresses and stop printing an error report when snmpa_net_if gets externally killed --- lib/snmp/src/agent/snmp_target_mib.erl | 31 ++--- lib/snmp/src/agent/snmpa_net_if.erl | 34 +++--- lib/snmp/src/misc/snmp_conf.erl | 199 ++++++++++++++++----------------- lib/snmp/src/misc/snmp_config.erl | 23 ++-- lib/snmp/src/misc/snmp_log.erl | 9 +- 5 files changed, 150 insertions(+), 146 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index 3bcfd469e6..932829e150 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -679,6 +679,20 @@ snmpTargetAddrTable(print) -> FOI = foi(Table), PrintRow = fun(Prefix, Row) -> + TDomain = element(?snmpTargetAddrTDomain, Row), + Domain = + try snmp_conf:tdomain_to_domain(TDomain) + catch + {error, {bad_tdomain, _}} -> + undefined + end, + TAddress = element(?snmpTargetAddrTAddress, Row), + AddrString = + try snmp_conf:mk_addr_string({Domain, TAddress}) + catch + {error, {bad_address, _}} -> + "-" + end, lists:flatten( io_lib:format("~sName: ~p" "~n~sTDomain: ~p (~w)" @@ -693,21 +707,8 @@ snmpTargetAddrTable(print) -> "~n~s[Ext] TMask: ~p" "~n~s[Ext] MMS: ~p", [Prefix, element(?snmpTargetAddrName, Row), - Prefix, element(?snmpTargetAddrTDomain, Row), - case element(?snmpTargetAddrTDomain, Row) of - ?snmpUDPDomain -> snmpUDPDomain; - ?transportDomainUdpIpv4 -> transportDomainUdpIpv4; - ?transportDomainUdpIpv6 -> transportDomainUdpIpv6; - _ -> undefined - end, - Prefix, element(?snmpTargetAddrTAddress, Row), - case element(?snmpTargetAddrTAddress, Row) of - [A,B,C,D,U1,U2] -> - lists:flatten( - io_lib:format("~w.~w.~w.~w:~w", - [A, B, C, D, U1 bsl 8 + U2])); - _ -> "-" - end, + Prefix, TDomain, Domain, + Prefix, TAddress, AddrString, Prefix, element(?snmpTargetAddrTimeout, Row), Prefix, element(?snmpTargetAddrRetryCount, Row), Prefix, element(?snmpTargetAddrTagList, Row), diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 2c800db8b6..71bb9cad2e 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -142,9 +142,16 @@ init(Prio, NoteStore, MasterAgent, Parent, Opts) -> try loop(State) catch C:E -> S = erlang:get_stacktrace(), - error_msg( - "loop/1 EXCEPTION ~w:~w~n" - " ~p", [C,E,S]), + Fmt = + "loop/1 EXCEPTION ~w:~w~n" + " ~p", + case C of + exit -> + %% Externally killed, root cause is elsewhere + info_msg(Fmt, [C, E, S]); + _ -> + error_msg(Fmt, [C, E, S]) + end, erlang:raise(C, E, S) end; {error, Reason} -> @@ -287,20 +294,9 @@ log({Log, Types}, _, Packet, Address) -> false -> ok end. -%% log(_, _, _, _, _) -> -%% ok. - -format_address({snmpUDPDomain, {_Ip, Port} = Addr}) when is_integer(Port) -> - format_address(Addr); -format_address({transportDomainUdpIpv4, {Ip, Port}}) -> - format_address("udpIpv4/~s:~w", [inet:ntoa(Ip), Port]); -format_address({transportDomainUdpIpv6, {Ip, Port}}) -> - format_address("udpIpv6/[~s]:~w", [inet:ntoa(Ip), Port]); -format_address({Ip, Port}) when is_integer(Port) -> - format_address("~s:~w", [inet:ntoa(Ip), Port]). -format_address(Format, Args) -> - iolist_to_binary(io_lib:format(Format, Args)). +format_address(Address) -> + iolist_to_binary(snmp_conf:mk_addr_string(Address)). @@ -712,7 +708,6 @@ maybe_handle_reply_pdu( Type, ACMData, To) -> S1 = update_req_counter_outgoing(S, Rid), - %% Addresses = [To], Addresses = [fix_filter_address(Domain, To)], case try @@ -962,7 +957,6 @@ handle_response(Vsn, Pdu, From, S) -> maybe_udp_send( #state{usock = Sock, filter = FilterMod, domain = Domain}, To, Packet) -> - %% {To_1, To_2} = To, {To_1, To_2} = fix_filter_address(Domain, To), case try FilterMod:accept_send(To_1, To_2) @@ -997,7 +991,6 @@ maybe_udp_send( filter = FilterMod, domain = Domain}, To, Packet, Type, _LogData) -> - %% {To_1, To_2} = To, {To_1, To_2} = fix_filter_address(Domain, To), case try FilterMod:accept_send(To_1, To_2) @@ -1358,6 +1351,9 @@ get_bind_to_ip_address(Opts) -> error_msg(F,A) -> ?snmpa_error("NET-IF server: " ++ F, A). +info_msg(F,A) -> + ?snmpa_info("NET-IF server: " ++ F, A). + %% --- user_err(F, A) -> diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 2d91cb1f55..eb71c55cf4 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -40,11 +40,13 @@ all_domains/0, check_domain/1, + domain_to_name/1, all_tdomains/0, check_tdomain/1, mk_tdomain/0, mk_tdomain/1, - tdomain_to_family/1, + tdomain_to_family/1, tdomain_to_domain/1, which_domain/1, + mk_addr_string/1, check_ip/1, check_ip/2, check_port/1, ip_port_to_domaddr/2, @@ -495,9 +497,17 @@ tdomain_to_family(BadDomain) -> %% --------- -%% XXX remove -%% check_taddress(X) -> -%% check_taddress(snmpUDPDomain, X). +tdomain_to_domain(?snmpUDPDomain) -> + snmpUDPDomain; +tdomain_to_domain(?transportDomainUdpIpv4) -> + transportDomainUdpIpv4; +tdomain_to_domain(?transportDomainUdpIpv6) -> + transportDomainUdpIpv6; +tdomain_to_domain(BadTDomain) -> + error({bad_tdomain, BadTDomain}). + + +%% --------- check_taddress(?snmpUDPDomain, X) -> check_taddress(transportDomainUdpIpv4, X); @@ -600,6 +610,42 @@ check_domain(Domain) -> error({unknown_domain, Domain}) end. +domain_to_name(snmpUDPDomain) -> + undefined; +domain_to_name(transportDomainUdpIpv4) -> + udpIpv4; +domain_to_name(transportDomainUdpIpv6) -> + udpIpv6; +domain_to_name(transportDomainUdpIpv4z) -> + udpIpv4z; +domain_to_name(transportDomainUdpIpv6z) -> + udpIpv6z; +domain_to_name(transportDomainTcpIpv4) -> + tcpIpv4; +domain_to_name(transportDomainTcpIpv6) -> + tcpIpv6; +domain_to_name(transportDomainTcpIpv4z) -> + tcpIpv4z; +domain_to_name(transportDomainTcpIpv6z) -> + tcpIpv6z; +domain_to_name(transportDomainSctpIpv4) -> + sctpIpv4; +domain_to_name(transportDomainSctpIpv6) -> + sctpIpv6; +domain_to_name(transportDomainSctpIpv4z) -> + sctpIpv4z; +domain_to_name(transportDomainSctpIpv6z) -> + sctpIpv6z; +domain_to_name(transportDomainLocal) -> + local; +domain_to_name(transportDomainUdpDns) -> + udpDns; +domain_to_name(transportDomainTcpDns) -> + tcpDns; +domain_to_name(transportDomainSctpDns) -> + sctpDns; +domain_to_name(BadDomain) -> + error({bad_domain, BadDomain}). %% --------- @@ -652,77 +698,6 @@ mk_taddress(BadDomain, _) -> error({bad_domain, BadDomain}). - -%% mk_taddress(snmpUDPDomain, Address) -> -%% mk_taddress(transportDomainUdpIpv4, Address); -%% %% mk_taddress(transportDomainUdpIpv4, {Ip, Port}) when is_list(Ip) -> -%% %% Ip ++ mk_bytes(Port); -%% mk_taddress(transportDomainUdpIpv4, {Ip, Port}) -%% when tuple_size(Ip) =:= 4 -> -%% tuple_to_list(Ip) ++ mk_bytes(Port); -%% %% mk_taddress(transportDomainUdpIpv4, IpPort) when is_list(IpPort) -> -%% %% IpPort; % Should be length 6 -%% %% mk_taddress(transportDomainUdpIpv6, {Ip, Port}) when is_list(Ip) -> -%% %% Ip ++ mk_bytes(Port); -%% mk_taddress(transportDomainUdpIpv6, {Ip, Port}) -%% when tuple_size(Ip) == 8 -> -%% tuple_to_list(Ip) ++ mk_bytes(Port); -%% %% mk_taddress(transportDomainUdpIpv6, IpPort) when is_list(IpPort) -> -%% %% case IpPort of -%% %% [A0,A1,A2,A3,A4,A5,A6,A7,P] -> -%% %% [A0,A1,A2,A3,A4,A5,A6,A7] ++ mk_bytes(P); -%% %% [A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,P0,P1] -> -%% %% [mk_word(A0, A1),mk_word(A2, A3), -%% %% mk_word(A4, A5),mk_word(A6, A7), -%% %% mk_word(A8, A9),mk_word(A10, A11), -%% %% mk_word(A12, A13),mk_word(A14, A15),P0,P1]; -%% %% _ -> -%% %% IpPort % Should already be 8 words and 2 bytes hence length 10 -%% %% end; -%% mk_taddress(Domain, []) -> %% Used for empty mask -%% []; -%% mk_taddress(Domain, Address) -> -%% erlang:error(badarg, [Domain,Address]); -%% %% -%% %% These are just for convenience -%% mk_taddress(?snmpUDPDomain, Address) -> -%% mk_taddress(snmpUDPDomain, Address); -%% mk_taddress(?transportDomainUdpIpv4, Address) -> -%% mk_taddress(transportDomainUdpIpv4, Address); -%% mk_taddress(?transportDomainUdpIpv6, Address) -> -%% mk_taddress(transportDomainUdpIpv6, Address); -%% %% Bad domain -%% mk_taddress(BadDomain, _) -> -%% error({bad_domain, BadDomain}). - - - -%% %% XXX remove - -%% mk_taddress(snmpUDPDomain, Ip, Port) -> -%% mk_taddress(transportDomainUdpIpv4, Ip, Port); -%% mk_taddress(transportDomainUdpIpv4, Ip, Port) when is_list(Ip) -> -%% Ip ++ [Port div 256, Port rem 256]; -%% mk_taddress(transportDomainUdpIpv4 = Domain, Ip, Port) when is_tuple(Ip) -> -%% mk_taddress(Domain, tuple_to_list(Ip), Port); -%% mk_taddress(transportDomainUdpIpv6, Ip, Port) when is_list(Ip) -> -%% Ip ++ [Port div 256, Port rem 256]; -%% mk_taddress(transportDomainUdpIpv6 = Domain, Ip, Port) when is_tuple(Ip) -> -%% mk_taddress(Domain, tuple_to_list(Ip), Port); -%% %% -%% %% These are just for convenience -%% mk_taddress(?snmpUDPDomain, Ip, Port) -> -%% mk_taddress(snmpUDPDomain, Ip, Port); -%% mk_taddress(?transportDomainUdpIpv4, Ip, Port) -> -%% mk_taddress(transportDomainUdpIpv4, Ip, Port); -%% mk_taddress(?transportDomainUdpIpv6, Ip, Port) -> -%% mk_taddress(transportDomainUdpIpv6, Ip, Port); -%% %% -%% %% Bad domain -%% mk_taddress(BadDomain, _Ip, _Port) -> -%% error({bad_domain, BadDomain}). - - %% --------- %% XXX remove, when net_if handles one socket per transport domain @@ -747,10 +722,54 @@ which_domain({A0, A1, A2, A3, A4, A5, A6, A7}) %% --------- +mk_addr_string({_IP, Port} = Addr) when is_integer(Port) -> + mk_addr_string({snmpUDPDomain, Addr}); +mk_addr_string({Domain, Addr}) when is_atom(Domain) -> + %% XXX There is only code for IP domains here + case check_address_ip(Domain, Addr) of + false -> + case check_address_ip_port(Domain, Addr) of + false -> + error({bad_address, {Domain, Addr}}); + true -> + {IP, Port} = Addr, + mk_addr_string_ntoa(Domain, IP, Port); + {IP, Port} -> + mk_addr_string_ntoa(Domain, IP, Port) + end; + true -> + mk_addr_string_ntoa(Domain, Addr); + IP -> + mk_addr_string_ntoa(Domain, IP) + end. + + +mk_addr_string_ntoa({_, _, _, _} = IP) -> + inet:ntoa(IP); +mk_addr_string_ntoa(IP) -> + lists:flatten(io_lib:format("[~s]", [inet:ntoa(IP)])). + +mk_addr_string_ntoa(Domain, IP) -> + case domain_to_name(Domain) of + undefined -> + mk_addr_string_ntoa(IP); + Name -> + lists:flatten( + io_lib:format("~w://~s", [Name, mk_addr_string_ntoa(IP)])) + end. + +mk_addr_string_ntoa(Domain, IP, Port) -> + lists:flatten( + io_lib:format( + "~s:~w", [mk_addr_string_ntoa(Domain, IP), Port])). + +%% --------- + check_ip(X) -> check_ip(snmpUDPDomain, X). check_ip(Domain, IP) -> + %% XXX There is only code for IP domains here case check_address_ip(Domain, IP) of false -> error({bad_address, {Domain, IP}}); @@ -760,31 +779,6 @@ check_ip(Domain, IP) -> {ok, FixedIP} end. -%% check_ip(snmpUDPDomain, X) -> -%% check_ip(transportDomainUdpIpv4, X); -%% check_ip(transportDomainUdpIpv4 = Domain, X) -> -%% case X of -%% [A,B,C,D] when ?is_ipv4_addr(A, B, C, D) -> -%% ok; -%% _ -> -%% error({bad_address, {Domain, X}}) -%% end; -%% check_ip(transportDomainUdpIpv6 = Domain, X) -> -%% case X of -%% [A,B,C,D,E,F,G,H] -%% when ?is_ipv6_addr(A, B, C, D, E, F, G, H) -> -%% ok; -%% [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P] -%% when ?is_ipv6_addr( -%% A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> -%% ok; -%% _ -> -%% error({bad_address, {Domain, X}}) -%% end; -%% %% -%% check_ip(BadDomain, _X) -> -%% error({invalid_domain, BadDomain}). - %% --------- @@ -794,6 +788,7 @@ check_port(Port) -> error({bad_port, Port}). ip_port_to_domaddr(IP, Port) when ?is_word(Port) -> + %% XXX There is only code for IP domains here case check_address_ip(transportDomainUdpIpv4, IP) of false -> case check_address_ip(transportDomainUdpIpv6, IP) of @@ -818,6 +813,8 @@ ip_port_to_domaddr(IP, Port) -> check_address(Domain, Address, DefaultPort) -> %% If Address does not contain Port or contains Port =:= 0 %% create an address containing DefaultPort + %% + %% XXX There is only code for IP domains here case check_address_ip(Domain, Address) of false -> case check_address_ip_port(Domain, Address) of @@ -843,6 +840,8 @@ check_address(Domain, Address, DefaultPort) -> check_address(Domain, Address) -> %% Address has to contain Port + %% + %% XXX There is only code for IP domains here case check_address_ip_port(Domain, Address) of false -> error({bad_address, {Domain, Address}}); diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 6d0f14237e..ac2b7b7778 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -1825,18 +1825,23 @@ write_agent_snmp_target_addr_conf( "%%\n\n", Hdr = header() ++ Comment, F = fun(v1 = Vsn, Acc) -> - [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, + [{mk_name(Domain, Addr, Vsn), + Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}| Acc]; (v2 = Vsn, Acc) -> - [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, + [{mk_name(Domain, Addr, Vsn), + Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten(io_lib:format("~s.2",[mk_name(Addr, Vsn)])), + {lists:flatten( + io_lib:format("~s.2",[mk_name(Domain, Addr, Vsn)])), Domain, Addr, Timeout, RetryCount, "std_inform", mk_param(Vsn), "", [], 2048}| Acc]; (v3 = Vsn, Acc) -> - [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, + [{mk_name(Domain, Addr, Vsn), + Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten(io_lib:format("~s.3",[mk_name(Addr, Vsn)])), + {lists:flatten( + io_lib:format("~s.3",[mk_name(Domain, Addr, Vsn)])), Domain, Addr, Timeout, RetryCount, "std_inform", mk_param(Vsn), "mgrEngine", [], 2048}| Acc] end, @@ -1852,10 +1857,10 @@ write_agent_snmp_target_addr_conf( mk_param(Vsn) -> lists:flatten(io_lib:format("target_~w", [Vsn])). -mk_name({[A,B,C,D], _}, Vsn) -> - lists:flatten(io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn])); -mk_name(Address, Vsn) -> - lists:flatten(io_lib:format("~w ~w", [Address,Vsn])). +mk_name(Domain, Addr, Vsn) -> + lists:flatten( + io_lib:format( + "~s ~w", [snmp_conf:mk_addr_string({Domain, Addr}), Vsn])). write_agent_target_addr_config(Dir, Hdr, Conf) -> snmpa_conf:write_target_addr_config(Dir, Hdr, Conf). diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index b3596909cd..a1fd392676 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -867,7 +867,8 @@ f(TimeStamp, SeqNo, %% [ip(Addr), Port, HdrStr, TimeStamp, SeqNo, Vsn, Str]). ipPort2Str(Ip, Port) -> - io_lib:format("~s:~w", [ip(Ip), Port]). + snmp_conf:mk_addr_string({Ip, Port}). + %% io_lib:format("~s:~w", [ip(Ip), Port]). %% Convert a timestamp 2-tupple to a printable string %% @@ -968,8 +969,10 @@ get_type(#pdu{type = Type}) -> Type. -ip({A,B,C,D}) -> - io_lib:format("~w.~w.~w.~w", [A,B,C,D]). +ip(Domain, Addr) -> + snmp_conf:mk_addr_string(Domain, Addr). +%% ip({A,B,C,D}) -> +%% io_lib:format("~w.~w.~w.~w", [A,B,C,D]). -- cgit v1.2.3 From aa8f929cb3810b2c5ed67b44392d26131857f8e6 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 21 May 2014 14:37:26 +0200 Subject: Write IPv6 test cases --- lib/snmp/test/snmp_agent_test.erl | 180 ++++++++++++++++++++++++++++------ lib/snmp/test/snmp_agent_test_lib.erl | 51 +++++++--- 2 files changed, 188 insertions(+), 43 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index e4cac71fec..6b8d0802d0 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -522,9 +522,13 @@ groups() -> {mib_storage_varm_mnesia, [], varm_mib_storage_mnesia_cases()}, {misc, [], misc_cases()}, {test_v1, [], v1_cases()}, + {test_v1_ipv6, [], v1_cases_ipv6()}, {test_v2, [], v2_cases()}, + {test_v2_ipv6, [], v2_cases_ipv6()}, {test_v1_v2, [], v1_v2_cases()}, + {test_v1_v2_ipv6, [], v1_v2_cases()}, {test_v3, [], v3_cases()}, + {test_v3_ipv6, [], v3_cases_ipv6()}, {test_multi_threaded, [], mt_cases()}, {multiple_reqs, [], mul_cases()}, {multiple_reqs_2, [], mul_cases_2()}, @@ -616,6 +620,14 @@ init_per_group(test_v2 = GroupName, Config) -> init_v2(snmp_test_lib:init_group_top_dir(GroupName, Config)); init_per_group(test_v1 = GroupName, Config) -> init_v1(snmp_test_lib:init_group_top_dir(GroupName, Config)); +init_per_group(test_v1_ipv6 = GroupName, Config) -> + init_per_group_ipv6(GroupName, Config, fun init_v1/1); +init_per_group(test_v2_ipv6 = GroupName, Config) -> + init_per_group_ipv6(GroupName, Config, fun init_v2/1); +init_per_group(test_v1_v2_ipv6 = GroupName, Config) -> + init_per_group_ipv6(GroupName, Config, fun init_v1_v2/1); +init_per_group(test_v3_ipv6 = GroupName, Config) -> + init_per_group_ipv6(GroupName, Config, fun init_v3/1); init_per_group(misc = GroupName, Config) -> init_misc(snmp_test_lib:init_group_top_dir(GroupName, Config)); init_per_group(mib_storage_varm_mnesia = GroupName, Config) -> @@ -649,6 +661,16 @@ init_per_group(ipv6 = GroupName, Config) -> init_per_group(GroupName, Config) -> snmp_test_lib:init_group_top_dir(GroupName, Config). +init_per_group_ipv6(GroupName, Config, Init) -> + case ct:require(ipv6_hosts) of + ok -> + Init( + snmp_test_lib:init_group_top_dir( + GroupName, [{ipfamily, inet6}|Config])); + _ -> + {skip, "Host does not support IPV6"} + end. + end_per_group(all_tcs, Config) -> finish_all(Config); end_per_group(otp7157, Config) -> @@ -667,31 +689,39 @@ end_per_group(multiple_reqs_3, Config) -> finish_mul(Config); end_per_group(test_multi_threaded, Config) -> finish_mt(Config); -end_per_group(test_v3, Config) -> +end_per_group(test_v3_ipv6, Config) -> + finish_v3(Config); +end_per_group(test_v1_v2_ipv6, Config) -> + finish_v1_v2(Config); +end_per_group(test_v2_ipv6, Config) -> + finish_v2(Config); +end_per_group(test_v1_ipv6, Config) -> + finish_v1(Config); +end_per_group(test_v3, Config) -> finish_v3(Config); -end_per_group(test_v1_v2, Config) -> +end_per_group(test_v1_v2, Config) -> finish_v1_v2(Config); -end_per_group(test_v2, Config) -> +end_per_group(test_v2, Config) -> finish_v2(Config); -end_per_group(test_v1, Config) -> +end_per_group(test_v1, Config) -> finish_v1(Config); -end_per_group(misc, Config) -> +end_per_group(misc, Config) -> finish_misc(Config); -end_per_group(mib_storage_varm_mnesia, Config) -> +end_per_group(mib_storage_varm_mnesia, Config) -> finish_varm_mib_storage_mnesia(Config); -end_per_group(mib_storage_varm_dets, Config) -> +end_per_group(mib_storage_varm_dets, Config) -> finish_varm_mib_storage_dets(Config); -end_per_group(mib_storage_size_check_mnesia, Config) -> +end_per_group(mib_storage_size_check_mnesia, Config) -> finish_size_check_msm(Config); -end_per_group(mib_storage_size_check_dets, Config) -> +end_per_group(mib_storage_size_check_dets, Config) -> finish_size_check_msd(Config); -end_per_group(mib_storage_size_check_ets, Config) -> +end_per_group(mib_storage_size_check_ets, Config) -> finish_size_check_mse(Config); -end_per_group(mib_storage_mnesia, Config) -> +end_per_group(mib_storage_mnesia, Config) -> finish_mib_storage_mnesia(Config); -end_per_group(mib_storage_dets, Config) -> +end_per_group(mib_storage_dets, Config) -> finish_mib_storage_dets(Config); -end_per_group(mib_storage_ets, Config) -> +end_per_group(mib_storage_ets, Config) -> finish_mib_storage_ets(Config); end_per_group(_GroupName, Config) -> Config. @@ -832,6 +862,10 @@ cases() -> {group, test_v2}, {group, test_v1_v2}, {group, test_v3}, + {group, test_v1_ipv6}, + {group, test_v2_ipv6}, + {group, test_v1_v2_ipv6}, + {group, test_v3_ipv6}, {group, test_multi_threaded}, {group, mib_storage}, {group, tickets1}, @@ -1685,14 +1719,40 @@ v1_cases() -> change_target_addr_config ]. +v1_cases_ipv6() -> + [ + simple, + v1_processing, + loop_mib, +%% big, +%% big2, + api, + subagent, +%% mnesia, +%% {group, multiple_reqs}, + sa_register, + v1_trap, +%% sa_error, + next_across_sa, + undo, +%% {group, reported_bugs}, + {group, standard_mibs}, + sparse_table, + cnt_64, + opaque, + change_target_addr_config + ]. + init_v1(Config) when is_list(Config) -> ?line SaNode = ?config(snmp_sa, Config), ?line create_tables(SaNode), ?line AgentConfDir = ?config(agent_conf_dir, Config), ?line MgrDir = ?config(mgr_dir, Config), ?line Ip = ?config(ip, Config), - ?line config([v1], MgrDir, AgentConfDir, - tuple_to_list(Ip), tuple_to_list(Ip)), + ?line IpFamily = ?config(ipfamily, Config), + ?line config( + [v1], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), [{vsn, v1} | start_v1_agent(Config)]. finish_v1(Config) when is_list(Config) -> @@ -1729,14 +1789,43 @@ v2_cases() -> v2_caps ]. +v2_cases_ipv6() -> + [ + simple_2, + v2_processing, +%% big_2, +%% big2_2, + loop_mib_2, + api_2, + subagent_2, +%% mnesia_2, +%% {group, multiple_reqs_2}, + sa_register_2, + v2_trap, + {group, v2_inform}, +%% sa_error_2, + next_across_sa_2, + undo_2, +%% {group, reported_bugs_2}, + {group, standard_mibs_2}, + v2_types, + implied, + sparse_table_2, + cnt_64_2, + opaque_2, + v2_caps + ]. + init_v2(Config) when is_list(Config) -> SaNode = ?config(snmp_sa, Config), create_tables(SaNode), AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - config([v2], MgrDir, AgentConfDir, - tuple_to_list(Ip), tuple_to_list(Ip)), + IpFamily = ?config(ipfamily, Config), + config( + [v2], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), [{vsn, v2} | start_v2_agent(Config)]. finish_v2(Config) when is_list(Config) -> @@ -1755,8 +1844,9 @@ init_v1_v2(Config) when is_list(Config) -> AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), + IpFamily = ?config(ipfamily, Config), config([v1,v2], MgrDir, AgentConfDir, - tuple_to_list(Ip), tuple_to_list(Ip)), + tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), [{vsn, bilingual} | start_bilingual_agent(Config)]. finish_v1_v2(Config) when is_list(Config) -> @@ -1794,6 +1884,34 @@ v3_cases() -> v2_caps_3 ]. +v3_cases_ipv6() -> + [ + simple_3, + v3_processing, +%% big_3, +%% big2_3, + api_3, + subagent_3, +%% mnesia_3, + loop_mib_3, +%% {group, multiple_reqs_3}, + sa_register_3, + v3_trap, + {group, v3_inform}, +%% sa_error_3, + next_across_sa_3, + undo_3, +%% {group, reported_bugs_3}, + {group, standard_mibs_3}, + {group, v3_security}, + v2_types_3, + implied_3, + sparse_table_3, + cnt_64_3, + opaque_3, + v2_caps_3 + ]. + init_v3(Config) when is_list(Config) -> %% Make sure crypto works, otherwise start_agent will fail %% and we will be stuck with a bunch of mnesia tables for @@ -1815,8 +1933,11 @@ init_v3(Config) when is_list(Config) -> AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - ?line ok = config([v3], MgrDir, AgentConfDir, - tuple_to_list(Ip), tuple_to_list(Ip)), + IpFamily = ?config(ipfamily, Config), + ?line ok = + config( + [v3], MgrDir, AgentConfDir, + tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), Opts = [{master_agent_verbosity, trace}, {agent_verbosity, trace}, @@ -6578,9 +6699,7 @@ otp8395({init, Config}) when is_list(Config) -> Vsns = [v1], AgentConfDir = ?config(agent_conf_dir, Config), ManagerConfDir = ?config(manager_top_dir, Config), - snmp_agent_test_lib:config(Vsns, - ManagerConfDir, AgentConfDir, - ManagerIP, AgentIP), + config(Vsns, ManagerConfDir, AgentConfDir, ManagerIP, AgentIP), %% -- @@ -7074,6 +7193,9 @@ delete_files(Config) -> config(Vsns, MgrDir, AgentDir, MIp, AIp) -> snmp_agent_test_lib:config(Vsns, MgrDir, AgentDir, MIp, AIp). +config(Vsns, MgrDir, AgentDir, MIp, AIp, IpFamily) -> + snmp_agent_test_lib:config(Vsns, MgrDir, AgentDir, MIp, AIp, IpFamily). + update_usm(Vsns, Dir) -> snmp_agent_test_lib:update_usm(Vsns, Dir). @@ -7350,10 +7472,10 @@ init_v1_agent(Config) -> ManagerHost = ?HOSTNAME(ManagerNode), Host = snmp_test_lib:hostname(), - Ip = ?LOCALHOST(?config(ipfamily, Config)), - {ok, AgentIP0} = snmp_misc:ip(AgentHost), + IpFamily = ?LOCALHOST(?config(ipfamily, Config)), + {ok, AgentIP0} = snmp_misc:ip(AgentHost, IpFamily), AgentIP = tuple_to_list(AgentIP0), - {ok, ManagerIP0} = snmp_misc:ip(ManagerHost), + {ok, ManagerIP0} = snmp_misc:ip(ManagerHost, IpFamily), ManagerIP = tuple_to_list(ManagerIP0), @@ -7370,9 +7492,7 @@ init_v1_agent(Config) -> ok = file:make_dir(AgentBkpDir1), ok = file:make_dir(AgentBkpDir2), AgentBkpDirs = [AgentBkpDir1, AgentBkpDir2], - snmp_agent_test_lib:config(Vsns, - ManagerConfDir, AgentConfDir, - ManagerIP, AgentIP), + config(Vsns, ManagerConfDir, AgentConfDir, ManagerIP, AgentIP, IpFamily), %% -- @@ -7380,7 +7500,7 @@ init_v1_agent(Config) -> %% Config2 = start_agent([{host, Host}, - {ip, Ip}, + {ip, IpFamily}, {agent_node, AgentNode}, {agent_host, AgentHost}, {agent_ip, AgentIP}, diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 6061732879..6925c16ffb 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -39,7 +39,7 @@ get_req/2, get_next_req/1, - config/5, + config/5, config/6, delete_files/1, copy_file/2, update_usm/2, @@ -1369,16 +1369,38 @@ stop_node(Node) -> %%%----------------------------------------------------------------- config(Vsns, MgrDir, AgentConfDir, MIp, AIp) -> + config(Vsns, MgrDir, AgentConfDir, MIp, AIp, inet). + +config(Vsns, MgrDir, AgentConfDir, MIp, AIp, IpFamily) -> ?LOG("config -> entry with" - "~n Vsns: ~p" - "~n MgrDir: ~p" - "~n AgentConfDir: ~p" - "~n MIp: ~p" - "~n AIp: ~p", - [Vsns, MgrDir, AgentConfDir, MIp, AIp]), - ?line ok = - snmp_config:write_agent_snmp_files( - AgentConfDir, Vsns, MIp, ?TRAP_UDP, AIp, 4000, "test"), + "~n Vsns: ~p" + "~n MgrDir: ~p" + "~n AgentConfDir: ~p" + "~n MIp: ~p" + "~n AIp: ~p" + "~n IpFamily: ~p", + [Vsns, MgrDir, AgentConfDir, MIp, AIp, IpFamily]), + ?line {Domain, ManagerAddr} = + case IpFamily of + inet6 -> + %% XXX Run IPv6 tests over IPv4 compatibility address + %% since the test manager needs to be rewritten to + %% handle IPv6 before we can improve this. + Ipv6Domain = transportDomainUdpIpv6, + AgentIpv6Addr = {mk_ipv6_ip(AIp), 4000}, + ManagerIpv6Addr = {mk_ipv6_ip(MIp), ?TRAP_UDP}, + ?line ok = + snmp_config:write_agent_snmp_files( + AgentConfDir, Vsns, + Ipv6Domain, ManagerIpv6Addr, AgentIpv6Addr, "test"), + {Ipv6Domain, ManagerIpv6Addr}; + _ -> + ?line ok = + snmp_config:write_agent_snmp_files( + AgentConfDir, Vsns, MIp, ?TRAP_UDP, AIp, 4000, "test"), + {snmpUDPDomain, {MIp, ?TRAP_UDP}} + end, + ?line case update_usm(Vsns, AgentConfDir) of true -> ?line copy_file(join(AgentConfDir, "usm.conf"), @@ -1389,11 +1411,14 @@ config(Vsns, MgrDir, AgentConfDir, MIp, AIp) -> end, ?line update_community(Vsns, AgentConfDir), ?line update_vacm(Vsns, AgentConfDir), - ?line write_target_addr_conf(AgentConfDir, MIp, ?TRAP_UDP, Vsns), + ?line write_target_addr_conf(AgentConfDir, Domain, ManagerAddr, Vsns), ?line write_target_params_conf(AgentConfDir, Vsns), ?line write_notify_conf(AgentConfDir), ok. +mk_ipv6_ip([A,B,C,D]) -> + [0,0,0,0,0,0,0,0,0,0,255,255,A,B,C,D]. + delete_files(Config) -> AgentDir = ?config(agent_dir, Config), delete_files(AgentDir, [db, conf]). @@ -1518,10 +1543,10 @@ write_community_conf(Dir, Conf) -> write_target_addr_conf(Dir, Conf) -> ?line ok = snmp_config:write_agent_target_addr_config(Dir, "", Conf). -write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> +write_target_addr_conf(Dir, Ip_or_Domain, Port_or_Addr, Vsns) -> ?line ok = snmp_config:write_agent_snmp_target_addr_conf( - Dir, ManagerIp, UDP, Vsns). + Dir, Ip_or_Domain, Port_or_Addr, Vsns). rewrite_target_addr_conf(Dir, NewPort) -> ?DBG("rewrite_target_addr_conf -> entry with" -- cgit v1.2.3 From 5b99573e288d3798414958975db41daf5509c0fb Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 21 May 2014 15:09:05 +0200 Subject: Fix log validation and fix some testcases --- lib/snmp/src/misc/snmp_log.erl | 19 +++++++++++++--- lib/snmp/test/snmp_agent_test.erl | 48 +++------------------------------------ 2 files changed, 19 insertions(+), 48 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index a1fd392676..4b22281b89 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -231,7 +231,20 @@ validate(Log, SeqNoReq) validate_seqno(PrevSN, SeqNo), {Timestamp, SeqNo}; - ({Timestamp, _Packet, _Addr, _Port}, {PrevTS, _PrevSN}) when SeqNoReq =:= true -> + ({Timestamp, SeqNo, _Packet, _AddrStr}, {PrevTS, PrevSN}) + when is_integer(SeqNo) -> + ?vtrace("validating log entry when" + "~n Timestamp: ~p" + "~n SeqNo: ~p" + "~n PrevTS: ~p" + "~n PrevSN: ~p", + [Timestamp, SeqNo, PrevTS, PrevSN]), + validate_timestamp(PrevTS, Timestamp), + validate_seqno(PrevSN, SeqNo), + {Timestamp, SeqNo}; + + ({Timestamp, _Packet, _Addr, _Port}, {PrevTS, _PrevSN}) + when SeqNoReq =:= true -> ?vtrace("validating log entry when" "~n Timestamp: ~p" "~n PrevTS: ~p", @@ -969,8 +982,8 @@ get_type(#pdu{type = Type}) -> Type. -ip(Domain, Addr) -> - snmp_conf:mk_addr_string(Domain, Addr). +%% ip(Domain, Addr) -> +%% snmp_conf:mk_addr_string(Domain, Addr). %% ip({A,B,C,D}) -> %% io_lib:format("~w.~w.~w.~w", [A,B,C,D]). diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 6b8d0802d0..9db2e67edd 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -297,12 +297,7 @@ %% tickets2 otp8395/1, - otp9884/1, - - %% IPV6 - ipv6_processing/1, - ipv6_trap/1 - + otp9884/1 ]). %% Internal exports @@ -545,8 +540,7 @@ groups() -> {tickets1, [], tickets1_cases()}, {tickets2, [], tickets2_cases()}, {otp4394, [], [otp_4394]}, - {otp7157, [], [otp_7157]}, - {ipv6, [], [ipv6_processing, ipv6_trap]} + {otp7157, [], [otp_7157]} ]. @@ -651,13 +645,6 @@ init_per_group(mib_storage_dets = GroupName, Config) -> init_mib_storage_dets(snmp_test_lib:init_group_top_dir(GroupName, Config)); init_per_group(mib_storage_ets = GroupName, Config) -> init_mib_storage_ets(snmp_test_lib:init_group_top_dir(GroupName, Config)); -init_per_group(ipv6 = GroupName, Config) -> - case ct:require(ipv6_hosts) of - ok -> - ipv6_init(snmp_test_lib:init_group_top_dir(GroupName, Config)); - _ -> - {skip, "Host does not support IPV6"} - end; init_per_group(GroupName, Config) -> snmp_test_lib:init_group_top_dir(GroupName, Config). @@ -770,16 +757,6 @@ init_per_testcase1(v3_inform_i = _Case, Config) when is_list(Config) -> "~n Config: ~p", [_Case, Config]), Dog = ?WD_START(?MINS(10)), [{watchdog, Dog} | Config ]; -init_per_testcase1(ipv6_processing = Case, Config) when is_list(Config) -> - ?DBG("init_per_testcase1 -> entry with" - "~n Case: ~p" - "~n Config: ~p", [Case, Config]), - ipv6_processing({init, init_per_testcase2(Case, Config)}); -init_per_testcase1(ipv6_trap = Case, Config) when is_list(Config) -> - ?DBG("init_per_testcase1 -> entry with" - "~n Case: ~p" - "~n Config: ~p", [Case, Config]), - ipv6_trap({init, init_per_testcase2(Case, Config)}); init_per_testcase1(_Case, Config) when is_list(Config) -> ?DBG("init_per_testcase -> entry with" "~n Case: ~p" @@ -868,8 +845,7 @@ cases() -> {group, test_v3_ipv6}, {group, test_multi_threaded}, {group, mib_storage}, - {group, tickets1}, - {group, ipv6} + {group, tickets1} ]. @@ -6881,24 +6857,6 @@ otp9884_await_backup_completion(First, Second) -> throw({error, {bad_completion, First, Second}}). %%----------------------------------------------------------------- -ipv6_processing({init, Config}) when is_list(Config)-> - init_v1_agent([{ipfamily, inet6} | Config]); -ipv6_processing({fin, Config}) when is_list(Config) -> - fin_v1_agent(Config); -ipv6_processing(Config) when is_list(Config) -> - v1_processing(Config). - -%%----------------------------------------------------------------- - -ipv6_trap({init, Config}) when is_list(Config)-> - init_v1_agent([{ipfamily, inet6} | Config]); -ipv6_trap({fin, Config}) when is_list(Config) -> - fin_v1_agent(Config); -ipv6_trap(Config) when is_list(Config) -> - v1_trap(Config). - -%%----------------------------------------------------------------- - agent_log_validation(Node) -> rpc:call(Node, ?MODULE, agent_log_validation, []). -- cgit v1.2.3 From 0408e4af1978177d7dee498ea3dced37aa56aefe Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 21 May 2014 16:01:49 +0200 Subject: Fix vsn.mk and clean out moot testcases --- lib/snmp/test/snmp_agent_test.erl | 10 +++++----- lib/snmp/vsn.mk | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 9db2e67edd..608a99062d 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -1707,16 +1707,16 @@ v1_cases_ipv6() -> %% mnesia, %% {group, multiple_reqs}, sa_register, - v1_trap, +%% v1_trap, % sends v1 trap %% sa_error, next_across_sa, undo, %% {group, reported_bugs}, - {group, standard_mibs}, + {group, standard_mibs}, % snmp_standard_mib still failing, sends v1 trap sparse_table, - cnt_64, - opaque, - change_target_addr_config +%% cnt_64, % sends v1 trap + opaque +%% change_target_addr_config % sends v1 trap ]. init_v1(Config) when is_list(Config) -> diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 04c3cc9392..533e313bdb 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.25.1 +SNMP_VSN = 4.25.0.1 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 827f952ce799f2051f60f0f8002d2e3908b2b5da Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 22 May 2014 10:06:51 +0200 Subject: Rewrite ordering functions for maintainability --- lib/snmp/src/agent/snmp_framework_mib.erl | 12 +++--------- lib/snmp/src/manager/snmpm_config.erl | 19 ++++--------------- lib/snmp/src/misc/snmp_conf.erl | 23 ++++++++++++++++++++++- 3 files changed, 29 insertions(+), 25 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 6589ace949..43c91bbbc8 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -222,15 +222,9 @@ check_agent(X) -> error({invalid_agent_attribute, X}). %% Ordering function to sort intAgentTransportDomain first -%% hence before intAgentIpAddress -order_agent({Name, _}, {Name, _}) -> - true; %% Less than or equal -order_agent({_, _}, {intAgentTransportDomain, _}) -> - false; %% Greater than -order_agent({intAgentTransportDomain, _}, {_, _}) -> - true; %% Less than or equal -order_agent({A, _}, {B, _}) -> - A =< B. +%% hence before intAgentIpAddress. Sort other entries on the key. +order_agent(EntryA, EntryB) -> + snmp_conf:keyorder(1, EntryA, EntryB, [intAgentTransportDomain | sort]). diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 69a6b4a3a9..36c7b914ac 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1783,21 +1783,10 @@ init_agent_config({UserId, TargetName, Config}) -> -%% Sort tdomain first then port to ensure both comes before taddress -order_agent({Item1, _}, {Item2, _}) -> - if Item1 == Item2 -> - true; % Item1 == Item2 - Item2 =:= tdomain -> - false; % Item1 > tdomain - Item2 =:= port -> - if Item1 =:= tdomain -> - true; % tdomain < port - true -> - false % Item1 > port - end; - true -> - true % Item1 < Item 2 - end. +%% Sort 'tdomain' first then 'port' to ensure both +%% sorts before 'taddress'. Keep the order of other items. +order_agent(ItemA, ItemB) -> + snmp_conf:keyorder(1, ItemA, ItemB, [tdomain, port]). fix_agent_config(Conf) -> ?vdebug("fix_agent_config -> entry with~n~n" diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index eb71c55cf4..0c9c755bf4 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -25,7 +25,7 @@ %% External exports %% Avoid warning for local function error/1 clashing with autoimported BIF. -compile({no_auto_import,[error/1]}). --export([read_files/2, no_gen/2, no_order/2, no_filter/1]). +-export([read_files/2, no_gen/2, no_order/2, no_filter/1, keyorder/4]). -export([read/2, read/3]). %% Basic (type) check functions @@ -158,6 +158,27 @@ no_gen(_Dir, _R) -> []. no_order(_, _) -> true. no_filter(X) -> X. +%% Order tuples on element N with Keys first in appearence order. +%% +%% An ordering function (A, B) shall return true iff +%% A is less than or equal to B i.e shall return +%% false iff A is to be ordered after B. +keyorder(N, A, B, _) when element(N, A) == element(N, B) -> + true; +keyorder(N, A, B, [Key | _]) + when tuple_size(A) >= 1, element(N, B) == Key -> + false; +keyorder(N, A, B, [Key | _]) + when element(N, A) == Key, tuple_size(B) >= 1 -> + true; +keyorder(N, A, B, [_ | Keys]) -> + keyorder(N, A, B, Keys); +keyorder(_, A, B, []) when tuple_size(A) >= 1, tuple_size(B) >= 1 -> + %% Do not order other keys + true; +keyorder(N, A, B, sort) -> + %% Order other keys according to standard sort order + element(N, A) =< element(N, B). read(File, Verify) -> -- cgit v1.2.3 From f8efe4ff765e9067172d70e0d93f15fb9f8bd98b Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 23 May 2014 17:23:49 +0200 Subject: Mend manager to pass regression tests --- lib/snmp/src/manager/snmpm.erl | 28 +++++++---- lib/snmp/src/manager/snmpm_config.erl | 81 ++++++++++++++++++++------------ lib/snmp/src/manager/snmpm_net_if.erl | 4 +- lib/snmp/src/manager/snmpm_net_if_mt.erl | 4 +- lib/snmp/src/misc/snmp_conf.erl | 44 ++++++++--------- 5 files changed, 97 insertions(+), 64 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index cf272c5504..8976322c4e 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -379,13 +379,13 @@ register_agent(UserId, Addr) -> register_agent(UserId, Addr, ?DEFAULT_AGENT_PORT, []). %% Backward compatibility -register_agent(UserId, Domain, Address, Config0) when is_atom(Domain) -> +register_agent(UserId, Domain, Addr, Config0) when is_atom(Domain) -> case lists:keymember(target_name, 1, Config0) of false -> - TargetName = mk_target_name(Domain, Address, Config0), + TargetName = mk_target_name(Domain, Addr, Config0), Config = [{reg_type, addr_port}, - {tdomain, Domain}, {taddress, Address} | Config0], + {tdomain, Domain}, {taddress, Addr} | Config0], do_register_agent(UserId, TargetName, ensure_engine_id(Config)); true -> {value, {_, TargetName}} = @@ -393,12 +393,19 @@ register_agent(UserId, Domain, Address, Config0) when is_atom(Domain) -> Config1 = lists:keydelete(target_name, 1, Config0), Config2 = [{reg_type, addr_port}, - {tdomain, Domain}, {taddress, Address} | Config1], + {tdomain, Domain}, {taddress, Addr} | Config1], register_agent(UserId, TargetName, ensure_engine_id(Config2)) end; register_agent(UserId, Ip, Port, Config) when is_integer(Port) -> - {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), - register_agent(UserId, Domain, Address, Config). + Domain = snmpm_config:default_transport_domain(), + Addr = + case snmp_conf:check_address(Domain, {Ip, Port}) of + ok -> + {Ip, Port}; + {ok, FixedAddr} -> + FixedAddr + end, + register_agent(UserId, Domain, Addr, Config). unregister_agent(UserId, TargetName) when is_list(TargetName) -> snmpm_config:unregister_agent(UserId, TargetName); @@ -1276,7 +1283,10 @@ target_name(DomainIp, AddressPort) -> snmpm_config:agent_info(DomainIp, AddressPort, target_name). mk_target_name(Addr, Port, Config) -> - snmpm_config:mk_target_name(Addr, Port, Config). + R = snmpm_config:mk_target_name(Addr, Port, Config), + p(?MODULE_STRING":mk_target_name(~p, ~p, ~p) -> ~p.~n", + [Addr, Port, Config, R]), + R. ensure_engine_id(Config) -> case lists:keymember(engine_id, 1, Config) of @@ -1292,5 +1302,5 @@ ensure_engine_id(Config) -> %% p(F) -> %% p(F, []). -%% p(F, A) -> -%% io:format("~w:" ++ F ++ "~n", [?MODULE | A]). +p(F, A) -> + io:format("~w:" ++ F ++ "~n", [?MODULE | A]). diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 36c7b914ac..e938a68ab0 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -165,7 +165,7 @@ %%%------------------------------------------------------------------- default_transport_domain() -> - transportDomainUdpIpv4. + snmpUDPDomain. start_link(Opts) -> @@ -284,9 +284,9 @@ do_user_info(_UserId, BadItem) -> %% A target-name constructed in this way is a string with the following: %% :- -%% This is intended for backward compatibility and therefor has +%% This is intended for backward compatibility and therefore has %% only support for IPv4 addresses and *no* other transport domain. -mk_target_name(Domain, Address, Config) +mk_target_name(Domain, Addr, Config) when is_atom(Domain), is_list(Config) -> Version = case lists:keysearch(version, 1, Config) of @@ -295,26 +295,34 @@ mk_target_name(Domain, Address, Config) false -> select_lowest_supported_version() end, - try fix_address(Domain, Address) of - {{A, B, C, D}, P} -> - lists:flatten( - io_lib:format( - "~w.~w.~w.~w:~w-~w", - [A, B, C, D, P, Version])); - {{A, B, C, D, E, F, G, H}, P} -> - lists:flatten( - io_lib:format( - "[~.16b:~.16b:~.16b:~.16b:~.16b:~.16b:~.16b:~.16b]:~w-~w", - [A, B, C, D, E, F, G, H, P, Version])) + try + lists:flatten( + io_lib:format( + "~s-~w", [snmp_conf:mk_addr_string({Domain, Addr}), Version])) catch _ -> lists:flatten( - io_lib:format("~p-~w", [Address, Version])) + io_lib:format("~p-~w", [Addr, Version])) end; mk_target_name(Ip, Port, Config) when is_integer(Port), is_list(Config) -> - {Domain, Address} = snmp_conf:ip_port_to_domaddr(Ip, Port), - mk_target_name(Domain, Address, Config). + Domain = default_transport_domain(), + try fix_address(Domain, {Ip, Port}) of + Address -> + mk_target_name(Domain, Address, Config) + catch + _ -> + Version = + case lists:keysearch(version, 1, Config) of + {value, {_, V}} -> + V; + false -> + select_lowest_supported_version() + end, + lists:flatten( + io_lib:format("~p:~w-~w", [Ip, Port, Version])) + end. + select_lowest_supported_version() -> {ok, Versions} = system_info(versions), @@ -403,8 +411,9 @@ unregister_agent(UserId, Domain, Address) when is_atom(Domain) -> {error, not_found} end; unregister_agent(UserId, Ip, Port) when is_integer(Port) -> - try snmp_conf:ip_port_to_domaddr(Ip, Port) of - {Domain, Address} -> + Domain = default_transport_domain(), + try fix_address(Domain, {Ip, Port}) of + Address -> do_unregister_agent(UserId, Domain, Address) catch _ -> @@ -444,19 +453,30 @@ agent_info(Domain, Address, Item) when is_atom(Domain) -> NAddress -> do_agent_info(Domain, NAddress, Item) catch - _ -> + _Thrown -> + p(?MODULE_STRING":agent_info(~p, ~p, ~p) throwed ~p at.~n" + " ~p", + [Domain, Address, Item, _Thrown, erlang:get_stacktrace()]), {error, not_found} end; agent_info(Ip, Port, Item) -> - try snmp_conf:ip_port_to_domaddr(Ip, Port) of - {Domain, Address} -> + p(?MODULE_STRING":agent_info(~p, ~p, ~p) entry~n", + [Ip, Port, Item]), + Domain = default_transport_domain(), + try fix_address(Domain, {Ip, Port}) of + Address -> do_agent_info(Domain, Address, Item) catch - _ -> + _Thrown -> + p(?MODULE_STRING":agent_info(~p, ~p, ~p) throwed ~p at.~n" + " ~p", + [Ip, Port, Item, _Thrown, erlang:get_stacktrace()]), {error, not_found} end. do_agent_info(Domain, Address, target_name = Item) -> + p(?MODULE_STRING":do_agent_info(~p, ~p, ~p) entry~n", + [Domain, Address, Item]), case ets:lookup(snmpm_agent_table, {Domain, Address, Item}) of [{_, Val}] -> {ok, Val}; @@ -464,6 +484,8 @@ do_agent_info(Domain, Address, target_name = Item) -> {error, not_found} end; do_agent_info(Domain, Address, Item) -> + p(?MODULE_STRING":do_agent_info(~p, ~p, ~p) entry~n", + [Domain, Address, Item]), case do_agent_info(Domain, Address, target_name) of {ok, TargetName} -> agent_info(TargetName, Item); @@ -1718,9 +1740,10 @@ check_agent_config( {UserId, TargetName, Community, Ip, Port, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}) -> - {Domain, Address} = snmp_conf:fix_domain_address(Ip, Port), + Domain = default_transport_domain(), + Addr = fix_address(Domain, {Ip, Port}), check_agent_config( - UserId, TargetName, Community, Domain, Address, + UserId, TargetName, Community, Domain, Addr, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel); check_agent_config( @@ -1735,7 +1758,7 @@ check_agent_config(Agent) -> error({bad_agent_config, Agent}). check_agent_config( - UserId, TargetName, Comm, Domain, Address, + UserId, TargetName, Comm, Domain, Addr, EngineId, Timeout, MMS, Version, SecModel, SecName, SecLevel) -> ?vdebug("check_agent_config -> entry with" @@ -1751,7 +1774,7 @@ check_agent_config( Conf = [{reg_type, target_name}, {tdomain, Domain}, - {taddress, Address}, + {taddress, Addr}, {community, Comm}, {engine_id, EngineId}, {timeout, Timeout}, @@ -3511,6 +3534,6 @@ error_msg(F, A) -> %% p(F) -> %% p(F, []). -%% p(F, A) -> -%% io:format("~w:" ++ F ++ "~n", [?MODULE | A]). +p(F, A) -> + io:format("~w:" ++ F ++ "~n", [?MODULE | A]). diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index e7167cdb6b..d7f17e0b7f 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -425,8 +425,8 @@ handle_cast(Msg, State) -> %%-------------------------------------------------------------------- handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> ?vlog("received ~w bytes from ~p:~p [~w]", [size(Bytes), Ip, Port, Sock]), - {Domain, Address} = snmp_conf:ip_port_to_domaddr(Ip, Port), - maybe_handle_recv_msg(Domain, Address, Bytes, State), + Domain = snmpm_config:default_transport_domain(), + maybe_handle_recv_msg(Domain, {Ip, Port}, Bytes, State), {noreply, State}; handle_info(inform_response_gc, State) -> diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 594bc44474..8dd3ef0111 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -435,8 +435,8 @@ handle_cast(Msg, State) -> %%-------------------------------------------------------------------- handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> ?vlog("received ~w bytes from ~p:~p", [size(Bytes), Ip, Port]), - {Domain, Address} = snmp_conf:ip_port_to_domaddr(Ip, Port), - handle_udp(Domain, Address, Bytes, State), + Domain = snmpm_config:default_transport_domain(), + handle_udp(Domain, {Ip, Port}, Bytes, State), {noreply, State}; handle_info(inform_response_gc, State) -> diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 0c9c755bf4..ea4686c91a 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -49,7 +49,7 @@ mk_addr_string/1, check_ip/1, check_ip/2, check_port/1, - ip_port_to_domaddr/2, +%% ip_port_to_domaddr/2, check_address/2, check_address/3, check_taddress/2, mk_taddress/1, mk_taddress/2, @@ -808,25 +808,25 @@ check_port(Port) when ?is_word(Port) -> check_port(Port) -> error({bad_port, Port}). -ip_port_to_domaddr(IP, Port) when ?is_word(Port) -> - %% XXX There is only code for IP domains here - case check_address_ip(transportDomainUdpIpv4, IP) of - false -> - case check_address_ip(transportDomainUdpIpv6, IP) of - false -> - error({bad_address, {transportDomainUdpIpv4, {IP, Port}}}); - true -> - {transportDomainUdpIpv6, {IP, Port}}; - FixedIP -> - {transportDomainUdpIpv6, {FixedIP, Port}} - end; - true -> - {transportDomainUdpIpv4, {IP, Port}}; - FixedIP -> - {transportDomainUdpIpv4, {FixedIP, Port}} - end; -ip_port_to_domaddr(IP, Port) -> - error({bad_address, {transportDomainUdpIpv4, {IP, Port}}}). +%% ip_port_to_domaddr(IP, Port) when ?is_word(Port) -> +%% %% XXX There is only code for IP domains here +%% case check_address_ip(transportDomainUdpIpv4, IP) of +%% false -> +%% case check_address_ip(transportDomainUdpIpv6, IP) of +%% false -> +%% error({bad_address, {transportDomainUdpIpv4, {IP, Port}}}); +%% true -> +%% {transportDomainUdpIpv6, {IP, Port}}; +%% FixedIP -> +%% {transportDomainUdpIpv6, {FixedIP, Port}} +%% end; +%% true -> +%% {transportDomainUdpIpv4, {IP, Port}}; +%% FixedIP -> +%% {transportDomainUdpIpv4, {FixedIP, Port}} +%% end; +%% ip_port_to_domaddr(IP, Port) -> +%% error({bad_address, {transportDomainUdpIpv4, {IP, Port}}}). %% Check a configuration term field from a file to see if it %% can be fixed to be fed to mk_taddress/2. @@ -923,7 +923,7 @@ check_address_ip_port(Domain, Address) false -> false; true -> - Address; + true; FixedIP -> {FixedIP, Port} end; @@ -941,7 +941,7 @@ check_address_ip_port(transportDomainUdpIpv6 = Domain, Address) -> false -> false; true -> - Address; + true; FixedIP -> {FixedIP, Port} end; -- cgit v1.2.3 From 20bb61e48a8370a4b5913d7d8e16a260bd3e31eb Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 27 May 2014 08:09:26 +0200 Subject: Mend write_config_file and append_config_file --- lib/snmp/src/agent/snmp_framework_mib.erl | 2 +- lib/snmp/src/agent/snmpa_conf.erl | 445 ++++++++++++------------------ lib/snmp/src/manager/snmpm_conf.erl | 234 +++++++--------- lib/snmp/src/manager/snmpm_config.erl | 38 ++- lib/snmp/src/misc/snmp_config.erl | 310 +++++++++++---------- 5 files changed, 476 insertions(+), 553 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 43c91bbbc8..4599f05f47 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -52,7 +52,7 @@ set_engine_boots/1, set_engine_time/1, table_next/2, check_status/3]). -export([add_context/1, delete_context/1]). --export([check_agent/1, check_agent/2, check_context/1, order_agent/2]). +-export([check_agent/2, check_context/1, order_agent/2]). %%----------------------------------------------------------------- diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index b05590a504..2569b01b55 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -108,40 +108,26 @@ write_agent_config(Dir, Conf) -> Hdr = header() ++ Comment, write_agent_config(Dir, Hdr, Conf). -write_agent_config(Dir, Hdr, Conf) +write_agent_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_agent_conf(Conf) end, - Write = fun(Fd) -> write_agent_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "agent.conf", Verify, Write). - + Order = fun snmp_framework_mib:order_agent/2, + Check = fun snmp_framework_mib:check_agent/2, + Write = fun (Fd, Entries) -> write_agent_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "agent.conf", Order, Check, Write, Conf). -append_agent_config(Dir, Conf) +append_agent_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_agent_conf(Conf) end, - Write = fun(Fd) -> write_agent_conf(Fd, Conf) end, - append_config_file(Dir, "agent.conf", Verify, Write). - + Order = fun snmp_framework_mib:order_agent/2, + Check = fun snmp_framework_mib:check_agent/2, + Write = fun write_agent_conf/2, + append_config_file(Dir, "agent.conf", Order, Check, Write, Conf). read_agent_config(Dir) -> Order = fun snmp_framework_mib:order_agent/2, - Check = fun check_agent_conf_entry/2, + Check = fun snmp_framework_mib:check_agent/2, read_config_file(Dir, "agent.conf", Order, Check). -verify_agent_conf(Conf) -> - verify_agent_conf(Conf, undefined). -%% -verify_agent_conf([], _) -> - ok; -verify_agent_conf([H|T], State) -> - {_, NewState} = check_agent_conf_entry(H, State), - verify_agent_conf(T, NewState); -verify_agent_conf(X, _) -> - error({bad_agent_config, X}). - -check_agent_conf_entry(Entry, State) -> - snmp_framework_mib:check_agent(Entry, State). - write_agent_conf(Fd, "", Conf) -> write_agent_conf(Fd, Conf); write_agent_conf(Fd, Hdr, Conf) -> @@ -196,38 +182,27 @@ write_context_config(Dir, Conf) -> write_context_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_context_conf(Conf) end, - Write = fun(Fd) -> write_context_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "context.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_context/2, + Write = fun (Fd, Entries) -> write_context_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "context.conf", Order, Check, Write, Conf). -append_context_config(Dir, Conf) +append_context_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_context_conf(Conf) end, - Write = fun(Fd) -> write_context_conf(Fd, Conf) end, - append_config_file(Dir, "context.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_context/2, + Write = fun write_context_conf/2, + append_config_file(Dir, "context.conf", Order, Check, Write, Conf). read_context_config(Dir) -> Order = fun snmp_conf:no_order/2, - Verify = - fun (Entry, State) -> - {verify_context_conf_entry(Entry), State} - end, - read_config_file(Dir, "context.conf", Order, Verify). + Check = fun check_context/2, + read_config_file(Dir, "context.conf", Order, Check). - -verify_context_conf([]) -> - ok; -verify_context_conf([H|T]) -> - verify_context_conf_entry(H), - verify_context_conf(T); -verify_context_conf(X) -> - error({error_context_config, X}). - -verify_context_conf_entry(Context) -> - {ok, _} = snmp_framework_mib:check_context(Context), - ok. + +check_context(Entry, State) -> + {check_ok(snmp_framework_mib:check_context(Entry)), + State}. write_context_conf(Fd, "", Conf) -> write_context_conf(Fd, Conf); @@ -280,40 +255,29 @@ write_community_config(Dir, Conf) -> Hdr = header() ++ Comment, write_community_config(Dir, Hdr, Conf). -write_community_config(Dir, Hdr, Conf) +write_community_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_community_conf(Conf) end, - Write = fun(Fd) -> write_community_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "community.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_community/2, + Write = fun (Fd, Entries) -> write_community_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "community.conf", Order, Check, Write, Conf). -append_community_config(Dir, Conf) +append_community_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_community_conf(Conf) end, - Write = fun(Fd) -> write_community_conf(Fd, Conf) end, - append_config_file(Dir, "community.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_community/2, + Write = fun write_community_conf/2, + append_config_file(Dir, "community.conf", Order, Check, Write, Conf). read_community_config(Dir) -> Order = fun snmp_conf:no_order/2, - Verify = - fun (Entry, State) -> - {verify_community_conf_entry(Entry), State} - end, - read_config_file(Dir, "community.conf", Order, Verify). + Check = fun check_community/2, + read_config_file(Dir, "community.conf", Order, Check). - -verify_community_conf([]) -> - ok; -verify_community_conf([H|T]) -> - verify_community_conf_entry(H), - verify_community_conf(T); -verify_community_conf(X) -> - error({invalid_community_config, X}). - -verify_community_conf_entry(Context) -> - {ok, _} = snmp_community_mib:check_community(Context), - ok. + +check_community(Entry, State) -> + {check_ok(snmp_community_mib:check_community(Entry)), + State}. write_community_conf(Fd, "", Conf) -> write_community_conf(Fd, Conf); @@ -322,14 +286,17 @@ write_community_conf(Fd, Hdr, Conf) -> write_community_conf(Fd, Conf). write_community_conf(Fd, Conf) -> - Fun = fun({Idx, Name, SecName, CtxName, TranspTag}) -> - io:format(Fd, "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", - [Idx, Name, SecName, CtxName, TranspTag]); + Fun = + fun({Idx, Name, SecName, CtxName, TranspTag}) -> + io:format( + Fd, + "{\"~s\", \"~s\", \"~s\", \"~s\", \"~s\"}.~n", + [Idx, Name, SecName, CtxName, TranspTag]); (Crap) -> - error({bad_community_config, Crap}) + error({bad_community_config, Crap}) end, lists:foreach(Fun, Conf). - + %% %% ------ standard.conf ------ @@ -356,44 +323,29 @@ write_standard_config(Dir, Conf) -> Hdr = header() ++ Comment, write_standard_config(Dir, Hdr, Conf). -write_standard_config(Dir, Hdr, Conf) +write_standard_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_standard_conf(Conf) end, - Write = fun(Fd) -> write_standard_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "standard.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_standard/2, + Write = fun (Fd, Entries) -> write_standard_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "standard.conf", Order, Check, Write, Conf). -append_standard_config(Dir, Conf) +append_standard_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_standard_conf(Conf) end, - Write = fun(Fd) -> write_standard_conf(Fd, Conf) end, - append_config_file(Dir, "standard.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_standard/2, + Write = fun write_standard_conf/2, + append_config_file(Dir, "standard.conf", Order, Check, Write, Conf). read_standard_config(Dir) -> Order = fun snmp_conf:no_order/2, - Verify = - fun (Entry, State) -> - {verify_standard_conf_entry(Entry), State} - end, - read_config_file(Dir, "standard.conf", Order, Verify). + Check = fun check_standard/2, + read_config_file(Dir, "standard.conf", Order, Check). - -verify_standard_conf([]) -> - ok; -verify_standard_conf([H|T]) -> - verify_standard_conf_entry(H), - verify_standard_conf(T); -verify_standard_conf(X) -> - error({bad_standard_config, X}). - -verify_standard_conf_entry(Std) -> - case snmp_standard_mib:check_standard(Std) of - ok -> - ok; - {ok, _} -> - ok - end. + +check_standard(Entry, State) -> + {check_ok(snmp_standard_mib:check_standard(Entry)), + State}. write_standard_conf(Fd, "", Conf) -> write_standard_conf(Fd, Conf); @@ -521,41 +473,29 @@ write_target_addr_config(Dir, Conf) -> Hdr = header() ++ Comment, write_target_addr_config(Dir, Hdr, Conf). -write_target_addr_config(Dir, Hdr, Conf) +write_target_addr_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_target_addr_conf(Conf) end, - Write = fun(Fd) -> write_target_addr_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "target_addr.conf", Verify, Write). - - + Order = fun snmp_conf:no_order/2, + Check = fun check_target_addr/2, + Write = fun (Fd, Entries) -> write_target_addr_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "target_addr.conf", Order, Check, Write, Conf). -append_target_addr_config(Dir, Conf) +append_target_addr_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_target_addr_conf(Conf) end, - Write = fun(Fd) -> write_target_addr_conf(Fd, Conf) end, - append_config_file(Dir, "target_addr.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_target_addr/2, + Write = fun write_target_addr_conf/2, + append_config_file(Dir, "target_addr.conf", Order, Check, Write, Conf). read_target_addr_config(Dir) -> Order = fun snmp_conf:no_order/2, - Verify = - fun (Entry, State) -> - {verify_target_addr_conf_entry(Entry), State} - end, - read_config_file(Dir, "target_addr.conf", Order, Verify). + Check = fun check_target_addr/2, + read_config_file(Dir, "target_addr.conf", Order, Check). - -verify_target_addr_conf([]) -> - ok; -verify_target_addr_conf([H|T]) -> - verify_target_addr_conf_entry(H), - verify_target_addr_conf(T); -verify_target_addr_conf(X) -> - error({bad_target_addr_config, X}). - -verify_target_addr_conf_entry(Entry) -> - {ok, _} = snmp_target_mib:check_target_addr(Entry), - ok. + +check_target_addr(Entry, State) -> + {check_ok(snmp_target_mib:check_target_addr(Entry)), + State}. write_target_addr_conf(Fd, "", Conf) -> write_target_addr_conf(Fd, Conf); @@ -641,38 +581,27 @@ write_target_params_config(Dir, Conf) -> write_target_params_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_target_params_conf(Conf) end, - Write = fun(Fd) -> write_target_params_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "target_params.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_target_params/2, + Write = fun (Fd, Entries) -> write_target_params_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "target_params.conf", Order, Check, Write, Conf). append_target_params_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_target_params_conf(Conf) end, - Write = fun(Fd) -> write_target_params_conf(Fd, Conf) end, - append_config_file(Dir, "target_params.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_target_params/2, + Write = fun write_target_params_conf/2, + append_config_file(Dir, "target_params.conf", Order, Check, Write, Conf). read_target_params_config(Dir) -> Order = fun snmp_conf:no_order/2, - Verify = - fun (Entry, State) -> - {verify_target_params_conf_entry(Entry), State} - end, - read_config_file(Dir, "target_params.conf", Order, Verify). + Check = fun check_target_params/2, + read_config_file(Dir, "target_params.conf", Order, Check). -verify_target_params_conf([]) -> - ok; -verify_target_params_conf([H|T]) -> - verify_target_params_conf_entry(H), - verify_target_params_conf(T); -verify_target_params_conf(X) -> - error({bad_target_params_config, X}). - -verify_target_params_conf_entry(Entry) -> - {ok, _} = snmp_target_mib:check_target_params(Entry), - ok. +check_target_params(Entry, State) -> + {check_ok(snmp_target_mib:check_target_params(Entry)), + State}. write_target_params_conf(Fd, "", Conf) -> write_target_params_conf(Fd, Conf); @@ -717,38 +646,27 @@ write_notify_config(Dir, Conf) -> write_notify_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_notify_conf(Conf) end, - Write = fun(Fd) -> write_notify_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "notify.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_notify/2, + Write = fun (Fd, Entries) -> write_notify_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "notify.conf", Order, Check, Write, Conf). append_notify_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_notify_conf(Conf) end, - Write = fun(Fd) -> write_notify_conf(Fd, Conf) end, - append_config_file(Dir, "notify.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_notify/2, + Write = fun write_notify_conf/2, + append_config_file(Dir, "notify.conf", Order, Check, Write, Conf). read_notify_config(Dir) -> Order = fun snmp_conf:no_order/2, - Verify = - fun (Entry, State) -> - {verify_notify_conf_entry(Entry), State} - end, - read_config_file(Dir, "notify.conf", Order, Verify). + Check = fun check_notify/2, + read_config_file(Dir, "notify.conf", Order, Check). -verify_notify_conf([]) -> - ok; -verify_notify_conf([H|T]) -> - verify_notify_conf_entry(H), - verify_notify_conf(T); -verify_notify_conf(X) -> - error({bad_notify_config, X}). - -verify_notify_conf_entry(Entry) -> - {ok, _} = snmp_notification_mib:check_notify(Entry), - ok. +check_notify(Entry, State) -> + {check_ok(snmp_notification_mib:check_notify(Entry)), + State}. write_notify_conf(Fd, "", Conf) -> write_notify_conf(Fd, Conf); @@ -817,38 +735,27 @@ write_usm_config(Dir, Conf) -> write_usm_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_usm_conf(Conf) end, - Write = fun(Fd) -> write_usm_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "usm.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_usm/2, + Write = fun (Fd, Entries) -> write_usm_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "usm.conf", Order, Check, Write, Conf). append_usm_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_usm_conf(Conf) end, - Write = fun(Fd) -> write_usm_conf(Fd, Conf) end, - append_config_file(Dir, "usm.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_usm/2, + Write = fun write_usm_conf/2, + append_config_file(Dir, "usm.conf", Order, Check, Write, Conf). read_usm_config(Dir) -> Order = fun snmp_conf:no_order/2, - Verify = - fun (Entry, State) -> - {verify_usm_conf_entry(Entry), State} - end, - read_config_file(Dir, "usm.conf", Order, Verify). + Check = fun check_usm/2, + read_config_file(Dir, "usm.conf", Order, Check). -verify_usm_conf([]) -> - ok; -verify_usm_conf([H|T]) -> - verify_usm_conf_entry(H), - verify_usm_conf(T); -verify_usm_conf(X) -> - error({bad_usm_conf, X}). - -verify_usm_conf_entry(Entry) -> - {ok, _} = snmp_user_based_sm_mib:check_usm(Entry), - ok. +check_usm(Entry, State) -> + {check_ok(snmp_user_based_sm_mib:check_usm(Entry)), + State}. write_usm_conf(Fd, "", Conf) -> write_usm_conf(Fd, Conf); @@ -860,11 +767,12 @@ write_usm_conf(Fd, Conf) -> Fun = fun(Entry) -> do_write_usm_conf(Fd, Entry) end, lists:foreach(Fun, Conf). -do_write_usm_conf(Fd, - {EngineID, UserName, SecName, Clone, - AuthP, AuthKeyC, OwnAuthKeyC, - PrivP, PrivKeyC, OwnPrivKeyC, - Public, AuthKey, PrivKey}) -> +do_write_usm_conf( + Fd, + {EngineID, UserName, SecName, Clone, + AuthP, AuthKeyC, OwnAuthKeyC, + PrivP, PrivKeyC, OwnPrivKeyC, + Public, AuthKey, PrivKey}) -> io:format(Fd, "{", []), io:format(Fd, "\"~s\", ", [EngineID]), io:format(Fd, "\"~s\", ", [UserName]), @@ -930,38 +838,27 @@ write_vacm_config(Dir, Conf) -> write_vacm_config(Dir, Hdr, Conf) when is_list(Dir) and is_list(Hdr) and is_list(Conf) -> - Verify = fun() -> verify_vacm_conf(Conf) end, - Write = fun(Fd) -> write_vacm_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, "vacm.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_vacm/2, + Write = fun (Fd, Entries) -> write_vacm_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, "vacm.conf", Order, Check, Write, Conf). append_vacm_config(Dir, Conf) when is_list(Dir) and is_list(Conf) -> - Verify = fun() -> verify_vacm_conf(Conf) end, - Write = fun(Fd) -> write_vacm_conf(Fd, Conf) end, - append_config_file(Dir, "vacm.conf", Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_vacm/2, + Write = fun write_vacm_conf/2, + append_config_file(Dir, "vacm.conf", Order, Check, Write, Conf). read_vacm_config(Dir) -> Order = fun snmp_conf:no_order/2, - Verify = - fun (Entry, State) -> - {verify_vacm_conf_entry(Entry), State} - end, - read_config_file(Dir, "vacm.conf", Order, Verify). + Check = fun check_vacm/2, + read_config_file(Dir, "vacm.conf", Order, Check). -verify_vacm_conf([]) -> - ok; -verify_vacm_conf([H|T]) -> - verify_vacm_conf_entry(H), - verify_vacm_conf(T); -verify_vacm_conf(X) -> - error({bad_vacm_conf, X}). - -verify_vacm_conf_entry(Entry) -> - {ok, _} = snmp_view_based_acm_mib:check_vacm(Entry), - ok. +check_vacm(Entry, State) -> + {check_ok(snmp_view_based_acm_mib:check_vacm(Entry)), + State}. write_vacm_conf(Fd, "", Conf) -> write_vacm_conf(Fd, Conf); @@ -973,34 +870,40 @@ write_vacm_conf(Fd, Conf) -> Fun = fun(Entry) -> do_write_vacm_conf(Fd, Entry) end, lists:foreach(Fun, Conf). -do_write_vacm_conf(Fd, - {vacmSecurityToGroup, - SecModel, SecName, GroupName}) -> - io:format(Fd, "{vacmSecurityToGroup, ~w, \"~s\", \"~s\"}.~n", - [SecModel, SecName, GroupName]); -do_write_vacm_conf(Fd, - {vacmAccess, - GroupName, Prefix, SecModel, SecLevel, Match, RV, WV, NV}) -> - io:format(Fd, "{vacmAccess, \"~s\", \"~s\", ~w, ~w, ~w, " - "\"~s\", \"~s\", \"~s\"}.~n", - [GroupName, Prefix, SecModel, SecLevel, - Match, RV, WV, NV]); -do_write_vacm_conf(Fd, - {vacmViewTreeFamily, - ViewIndex, ViewSubtree, ViewStatus, ViewMask}) -> - io:format(Fd, "{vacmViewTreeFamily, \"~s\", ~w, ~w, ~w}.~n", - [ViewIndex, ViewSubtree, ViewStatus, ViewMask]); +do_write_vacm_conf( + Fd, + {vacmSecurityToGroup, + SecModel, SecName, GroupName}) -> + io:format( + Fd, "{vacmSecurityToGroup, ~w, \"~s\", \"~s\"}.~n", + [SecModel, SecName, GroupName]); +do_write_vacm_conf( + Fd, + {vacmAccess, + GroupName, Prefix, SecModel, SecLevel, Match, RV, WV, NV}) -> + io:format( + Fd, "{vacmAccess, \"~s\", \"~s\", ~w, ~w, ~w, " + "\"~s\", \"~s\", \"~s\"}.~n", + [GroupName, Prefix, SecModel, SecLevel, + Match, RV, WV, NV]); +do_write_vacm_conf( + Fd, + {vacmViewTreeFamily, + ViewIndex, ViewSubtree, ViewStatus, ViewMask}) -> + io:format( + Fd, "{vacmViewTreeFamily, \"~s\", ~w, ~w, ~w}.~n", + [ViewIndex, ViewSubtree, ViewStatus, ViewMask]); do_write_vacm_conf(_Fd, Crap) -> error({bad_vacm_config, Crap}). %% ---- config file wrapper functions ---- -write_config_file(Dir, File, Verify, Write) -> - snmp_config:write_config_file(Dir, File, Verify, Write). +write_config_file(Dir, File, Order, Check, Write, Conf) -> + snmp_config:write_config_file(Dir, File, Order, Check, Write, Conf). -append_config_file(Dir, File, Verify, Write) -> - snmp_config:append_config_file(Dir, File, Verify, Write). +append_config_file(Dir, File, Order, Check, Write, Conf) -> + snmp_config:append_config_file(Dir, File, Order, Check, Write, Conf). read_config_file(Dir, File, Order, Check) -> snmp_config:read_config_file(Dir, File, Order, Check). @@ -1008,13 +911,19 @@ read_config_file(Dir, File, Order, Check) -> %% ---- config file utility functions ---- +check_ok(ok) -> + ok; +check_ok({ok, _}) -> + ok. + header() -> {Y,Mo,D} = date(), {H,Mi,S} = time(), - io_lib:format("%% This file was generated by " - "~w (version-~s) ~w-~2.2.0w-~2.2.0w " - "~2.2.0w:~2.2.0w:~2.2.0w\n", - [?MODULE, ?version, Y, Mo, D, H, Mi, S]). + io_lib:format( + "%% This file was generated by " + "~w (version-~s) ~w-~2.2.0w-~2.2.0w " + "~2.2.0w:~2.2.0w:~2.2.0w\n", + [?MODULE, ?version, Y, Mo, D, H, Mi, S]). error(R) -> throw({error, R}). diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index 5e2d9fdbf6..d2f9ba9c26 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2013. All Rights Reserved. +%% Copyright Ericsson AB 2006-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -78,43 +78,26 @@ write_manager_config(Dir, Conf) -> Hdr = header() ++ Comment, write_manager_config(Dir, Hdr, Conf). -write_manager_config(Dir, Hdr, Conf) - when is_list(Dir) andalso is_list(Hdr) andalso is_list(Conf) -> - Verify = fun() -> verify_manager_conf(Conf) end, - Write = fun(Fid) -> write_manager_conf(Fid, Hdr, Conf) end, - write_config_file(Dir, ?MANAGER_CONF_FILE, Verify, Write). - +write_manager_config(Dir, Hdr, Conf) + when is_list(Dir), is_list(Hdr), is_list(Conf) -> + Order = fun snmpm_config:order_manager_config/2, + Check = fun snmpm_config:check_manager_config/2, + Write = fun (Fd, Entries) -> write_manager_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, ?MANAGER_CONF_FILE, Order, Check, Write, Conf). append_manager_config(Dir, Conf) - when is_list(Dir) andalso is_list(Conf) -> - Verify = fun() -> verify_manager_conf(Conf) end, - Write = fun(Fid) -> write_manager_conf(Fid, Conf) end, - append_config_file(Dir, ?MANAGER_CONF_FILE, Verify, Write). - + when is_list(Dir), is_list(Conf) -> + Order = fun snmpm_config:order_manager_config/2, + Check = fun snmpm_config:check_manager_config/2, + Write = fun write_manager_conf/2, + append_config_file(Dir, ?MANAGER_CONF_FILE, Order, Check, Write, Conf). -read_manager_config(Dir) -> - Verify = fun(Entry) -> verify_manager_conf_entry(Entry) end, - read_config_file(Dir, ?MANAGER_CONF_FILE, Verify). +read_manager_config(Dir) when is_list(Dir) -> + Order = fun snmpm_config:order_manager_config/2, + Check = fun snmpm_config:check_manager_config/2, + read_config_file(Dir, ?MANAGER_CONF_FILE, Order, Check). -verify_manager_conf([]) -> - ok; -verify_manager_conf([H|T]) -> - verify_manager_conf_entry(H), - verify_manager_conf(T); -verify_manager_conf(X) -> - error({bad_manager_config, X}). - -verify_manager_conf_entry(Entry) -> - case snmpm_config:check_manager_config(Entry) of - ok -> - ok; -%% {ok, _} -> -%% ok; - Error -> - throw(Error) - end. - write_manager_conf(Fd, "", Conf) -> write_manager_conf(Fd, Conf); write_manager_conf(Fd, Hdr, Conf) -> @@ -167,36 +150,29 @@ write_users_config(Dir, Conf) -> Hdr = header() ++ Comment, write_users_config(Dir, Hdr, Conf). -write_users_config(Dir, Hdr, Conf) +write_users_config(Dir, Hdr, Conf) when is_list(Dir) andalso is_list(Hdr) andalso is_list(Conf) -> - Verify = fun() -> verify_users_conf(Conf) end, - Write = fun(Fd) -> write_users_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, ?USERS_CONF_FILE, Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_user_config/2, + Write = fun (Fd, Entries) -> write_users_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, ?USERS_CONF_FILE, Order, Check, Write, Conf). -append_users_config(Dir, Conf) +append_users_config(Dir, Conf) when is_list(Dir) andalso is_list(Conf) -> - Verify = fun() -> verify_users_conf(Conf) end, - Write = fun(Fd) -> write_users_conf(Fd, Conf) end, - append_config_file(Dir, ?USERS_CONF_FILE, Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_user_config/2, + Write = fun write_users_conf/2, + append_config_file(Dir, ?USERS_CONF_FILE, Order, Check, Write, Conf). read_users_config(Dir) when is_list(Dir) -> - Verify = fun(Entry) -> verify_users_conf_entry(Entry) end, - read_config_file(Dir, ?USERS_CONF_FILE, Verify). + Order = fun snmp_conf:no_order/2, + Check = fun check_user_config/2, + read_config_file(Dir, ?USERS_CONF_FILE, Order, Check). - -verify_users_conf([]) -> - ok; -verify_users_conf([H|T]) -> - verify_users_conf_entry(H), - verify_users_conf(T); -verify_users_conf(X) -> - error({bad_users_conf, X}). - -verify_users_conf_entry(Entry) -> - {ok, _} = snmpm_config:check_user_config(Entry), - ok. + +check_user_config(Entry, State) -> + {check_ok(snmpm_config:check_user_config(Entry)), + State}. write_users_conf(Fd, "", Conf) -> write_users_conf(Fd, Conf); @@ -239,36 +215,29 @@ write_agents_config(Dir, Conf) -> Hdr = header() ++ Comment, write_agents_config(Dir, Hdr, Conf). -write_agents_config(Dir, Hdr, Conf) +write_agents_config(Dir, Hdr, Conf) when is_list(Dir) andalso is_list(Hdr) andalso is_list(Conf) -> - Verify = fun() -> verify_agents_conf(Conf) end, - Write = fun(Fd) -> write_agents_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, ?AGENTS_CONF_FILE, Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_agent_config/2, + Write = fun (Fd, Entries) -> write_agents_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, ?AGENTS_CONF_FILE, Order, Check, Write, Conf). -append_agents_config(Dir, Conf) +append_agents_config(Dir, Conf) when is_list(Dir) andalso is_list(Conf) -> - Verify = fun() -> verify_agents_conf(Conf) end, - Write = fun(Fd) -> write_agents_conf(Fd, Conf) end, - append_config_file(Dir, ?AGENTS_CONF_FILE, Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_agent_config/2, + Write = fun write_agents_conf/2, + append_config_file(Dir, ?AGENTS_CONF_FILE, Order, Check, Write, Conf). read_agents_config(Dir) -> - Verify = fun(Entry) -> verify_agents_conf_entry(Entry) end, - read_config_file(Dir, ?AGENTS_CONF_FILE, Verify). + Order = fun snmp_conf:no_order/2, + Check = fun check_agent_config/2, + read_config_file(Dir, ?AGENTS_CONF_FILE, Order, Check). -verify_agents_conf([]) -> - ok; -verify_agents_conf([H|T]) -> - verify_agents_conf_entry(H), - verify_agents_conf(T); -verify_agents_conf(X) -> - error({bad_agents_config, X}). - -verify_agents_conf_entry(Entry) -> - {ok, _} = snmpm_config:check_agent_config(Entry), - ok. +check_agent_config(Entry, State) -> + {check_ok(snmpm_config:check_agent_config(Entry)), + State}. write_agents_conf(Fd, "", Conf) -> write_agents_conf(Fd, Conf); @@ -282,13 +251,15 @@ write_agents_conf(Fd, [H|T]) -> do_write_agents_conf(Fd, H), write_agents_conf(Fd, T). -do_write_agents_conf(Fd, - {UserId, - TargetName, Comm, Ip, Port, EngineID, - Timeout, MaxMessageSize, Version, - SecModel, SecName, SecLevel} = _A) -> - io:format(Fd, - "{~w, \"~s\", \"~s\", ~w, ~w, \"~s\", ~w, ~w, ~w, ~w, \"~s\", ~w}.~n", [UserId, TargetName, Comm, Ip, Port, EngineID, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel]); +do_write_agents_conf( + Fd, + {UserId, TargetName, Comm, Ip, Port, EngineID, + Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel} = _A) -> + io:format( + Fd, + "{~w, \"~s\", \"~s\", ~w, ~w, \"~s\", ~w, ~w, ~w, ~w, \"~s\", ~w}.~n", + [UserId, TargetName, Comm, Ip, Port, EngineID, + Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel]); do_write_agents_conf(_Fd, Crap) -> error({bad_agents_config, Crap}). @@ -314,37 +285,30 @@ write_usm_config(Dir, Conf) -> Hdr = header() ++ Comment, write_usm_config(Dir, Hdr, Conf). -write_usm_config(Dir, Hdr, Conf) +write_usm_config(Dir, Hdr, Conf) when is_list(Dir) andalso is_list(Hdr) andalso is_list(Conf) -> - Verify = fun() -> verify_usm_conf(Conf) end, - Write = fun(Fd) -> write_usm_conf(Fd, Hdr, Conf) end, - write_config_file(Dir, ?USM_USERS_CONF_FILE, Verify, Write). + Order = fun snmp_conf:no_order/2, + Check = fun check_usm_user_config/2, + Write = fun (Fd, Entries) -> write_usm_conf(Fd, Hdr, Entries) end, + write_config_file(Dir, ?USM_USERS_CONF_FILE, Order, Check, Write, Conf). - -append_usm_config(Dir, Conf) +append_usm_config(Dir, Conf) when is_list(Dir) andalso is_list(Conf) -> - Verify = fun() -> verify_usm_conf(Conf) end, - Write = fun(Fd) -> write_usm_conf(Fd, Conf) end, - append_config_file(Dir, ?USM_USERS_CONF_FILE, Verify, Write). - + Order = fun snmp_conf:no_order/2, + Check = fun check_usm_user_config/2, + Write = fun write_usm_conf/2, + append_config_file(Dir, ?USM_USERS_CONF_FILE, Order, Check, Write, Conf). read_usm_config(Dir) when is_list(Dir) -> - Verify = fun(Entry) -> verify_usm_conf_entry(Entry) end, - read_config_file(Dir, ?USM_USERS_CONF_FILE, Verify). + Order = fun snmp_conf:no_order/2, + Check = fun check_usm_user_config/2, + read_config_file(Dir, ?USM_USERS_CONF_FILE, Order, Check). -verify_usm_conf([]) -> - ok; -verify_usm_conf([H|T]) -> - verify_usm_conf_entry(H), - verify_usm_conf(T); -verify_usm_conf(X) -> - error({bad_usm_conf, X}). - -verify_usm_conf_entry(Entry) -> - {ok, _} = snmpm_config:check_usm_user_config(Entry), - ok. +check_usm_user_config(Entry, State) -> + {check_ok(snmpm_config:check_usrm_user_config(Entry)), + State}. write_usm_conf(Fd, "", Conf) -> write_usm_conf(Fd, Conf); @@ -358,41 +322,49 @@ write_usm_conf(Fd, [H|T]) -> do_write_usm_conf(Fd, H), write_usm_conf(Fd, T). -do_write_usm_conf(Fd, - {EngineID, UserName, AuthP, AuthKey, PrivP, PrivKey}) -> - io:format(Fd, "{\"~s\", \"~s\", ~w, ~w, ~w, ~w}.~n", - [EngineID, UserName, AuthP, AuthKey, PrivP, PrivKey]); -do_write_usm_conf(Fd, - {EngineID, UserName, SecName, - AuthP, AuthKey, PrivP, PrivKey}) -> - io:format(Fd, "{\"~s\", \"~s\", \"~s\", í~w, ~w, ~w, ~w}.~n", - [EngineID, UserName, SecName, AuthP, AuthKey, PrivP, PrivKey]); +do_write_usm_conf( + Fd, + {EngineID, UserName, AuthP, AuthKey, PrivP, PrivKey}) -> + io:format( + Fd, "{\"~s\", \"~s\", ~w, ~w, ~w, ~w}.~n", + [EngineID, UserName, AuthP, AuthKey, PrivP, PrivKey]); +do_write_usm_conf( + Fd, + {EngineID, UserName, SecName, + AuthP, AuthKey, PrivP, PrivKey}) -> + io:format( + Fd, "{\"~s\", \"~s\", \"~s\", í~w, ~w, ~w, ~w}.~n", + [EngineID, UserName, SecName, AuthP, AuthKey, PrivP, PrivKey]); do_write_usm_conf(_Fd, Crap) -> error({bad_usm_conf, Crap}). %% ---- config file wrapper functions ---- -write_config_file(Dir, File, Verify, Write) -> - snmp_config:write_config_file(Dir, File, Verify, Write). - -append_config_file(Dir, File, Verify, Write) -> - snmp_config:append_config_file(Dir, File, Verify, Write). +write_config_file(Dir, File, Order, Check, Write, Conf) -> + snmp_config:write_config_file(Dir, File, Order, Check, Write, Conf). -read_config_file(Dir, File, Verify) -> - snmp_config:read_config_file(Dir, File, Verify). +append_config_file(Dir, File, Order, Check, Write, Conf) -> + snmp_config:append_config_file(Dir, File, Order, Check, Write, Conf). +read_config_file(Dir, File, Order, Check) -> + snmp_config:read_config_file(Dir, File, Order, Check). %% ---- config file utility functions ---- +check_ok(ok) -> + ok; +check_ok({ok, _}) -> + ok. + header() -> {Y,Mo,D} = date(), {H,Mi,S} = time(), - io_lib:format("%% This file was generated by " - "~w (version-~s) ~w-~2.2.0w-~2.2.0w " - "~2.2.0w:~2.2.0w:~2.2.0w\n", - [?MODULE, ?version, Y, Mo, D, H, Mi, S]). - + io_lib:format( + "%% This file was generated by " + "~w (version-~s) ~w-~2.2.0w-~2.2.0w " + "~2.2.0w:~2.2.0w:~2.2.0w\n", + [?MODULE, ?version, Y, Mo, D, H, Mi, S]). error(R) -> throw({error, R}). diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index e938a68ab0..b3500d7293 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -103,8 +103,10 @@ get_agent_mp_model/2 ]). --export([check_manager_config/1, - check_user_config/1, +-export([ + order_manager_config/2, + check_manager_config/2, + check_user_config/1, check_agent_config/1, check_usm_user_config/1]). @@ -2285,8 +2287,8 @@ is_crypto_supported(Func) -> %% end. read_manager_config_file(Dir) -> - Order = fun snmp_conf:no_order/2, - Check = fun (Entry, State) -> {check_manager_config(Entry), State} end, + Order = fun order_manager_config/2, + Check = fun check_manager_config/2, Conf = read_file(Dir, "manager.conf", Order, Check), ?d("read_manager_config_file -> ok: " "~n Conf: ~p", [Conf]), @@ -2309,11 +2311,31 @@ default_manager_config() -> "~n _Reason: ~p", [_Reason]), [] end. - -check_manager_config({address, Addr}) -> - snmp_conf:check_ip(Addr); + +order_manager_config(EntryA, EntryB) -> + snmp_conf:keyorder(1, EntryA, EntryB, [domain]). + +check_manager_config({domain, D}, _Domain) -> + {snmp_conf:check_domain(D), D}; +check_manager_config({address = Tag, Ip}, D) -> + Domain = + case D of + undefined -> + default_transport_domain(); + _ -> + D + end, + {case snmp_conf:check_ip(Domain, Ip) of + ok -> + ok; + {ok, FixedIp} -> + {ok, {Tag, FixedIp}} + end, Domain}; +check_manager_config(Entry, Domain) -> + {check_manager_config(Entry), Domain}. + check_manager_config({port, Port}) -> - snmp_conf:check_integer(Port, {gt, 0}); + snmp_conf:check_port(Port); check_manager_config({engine_id, EngineID}) -> snmp_conf:check_string(EngineID); check_manager_config({max_message_size, Max}) -> diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index ac2b7b7778..68d4aee97d 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -26,8 +26,9 @@ -compile({no_auto_import,[error/1]}). -export([config/0]). --export([write_config_file/4, append_config_file/4, - read_config_file/3, read_config_file/4]). +%%-export([write_config_file/4, append_config_file/4, read_config_file/4]). + +-export([write_config_file/6, append_config_file/6, read_config_file/4]). -export([write_agent_snmp_files/7, write_agent_snmp_files/12, write_agent_snmp_files/6, write_agent_snmp_files/11, @@ -92,9 +93,9 @@ ]). --export_type([void/0, - verify_config_entry_function/0, - verify_config_function/0, +-export_type([void/0, + order_config_entry_function/0, + check_config_entry_function/0, write_config_function/0]). @@ -2467,93 +2468,90 @@ header() -> [?MODULE, ?version, Y, Mo, D, H, Mi, S]). -%% *If* these functions are successfull, they successfully return anything -%% (which is ignored), but they fail with either a throw or an exit or -%% something similar. +%% *If* these functions are successfull, they successfully return +%% (value is ignored), but they fail preferably with +%% throw({error, Reason}). Other exceptions are also handled. -%% Verification of one config entry read from a file --type(verify_config_entry_function() :: - fun((Entry :: term()) -> ok | {error, Reason :: term()})). +%% Sorting order for config entries (see lists:sort/2) +-type(order_config_entry_function() :: + fun((term(), term()) -> boolean())). -%% Verification of config to be written --type(verify_config_function() :: - fun(() -> void())). +%% Check of config entries. Initial State is 'undefined' +-type(check_config_entry_function() :: + fun((Entry :: term(), State :: undefined | term()) -> + {ok | {ok, NewEntry :: term()}, NewState :: term()})). -%% Write config to file (as defined by Fd) --type(write_config_function() :: - fun((Fd :: file:io_device()) -> void())). +%% Write configuration entries to file descriptor Fd +-type(write_config_function() :: + fun((Fd :: file:io_device(), [Entry :: term()]) -> ok)). --spec write_config_file(Dir :: string(), - FileName :: string(), - Verify :: verify_config_function(), - Write :: write_config_function()) -> - ok | {error, Reason :: term()}. +-spec write_config_file( + Dir :: string(), + FileName :: string(), + Order :: order_config_entry_function(), + Check :: check_config_entry_function(), + Write :: write_config_function(), + Entries :: [term()]) -> + ok | {error, term()}. -write_config_file(Dir, FileName, Verify, Write) - when (is_list(Dir) andalso - is_list(FileName) andalso - is_function(Verify) andalso - is_function(Write)) -> - try do_write_config_file(Dir, FileName, Verify, Write) of - ok -> - ok; - Other -> - d("File write of ~s returned: ~p~n", [FileName,Other]) +write_config_file(Dir, FileName, Order, Check, Write, Entries) + when is_list(Dir), is_list(FileName), + is_function(Order), is_function(Check), is_function(Write), + is_list(Entries) -> + try + SortedEntries = lists:sort(Order, Entries), + _ = + lists:foldl( + fun (Entry, State) -> + case Check(Entry, State) of + {ok, NewState} -> + NewState; + {{ok, _}, NewState} -> + NewState + end + end, undefined, SortedEntries), + ok + of + _ -> + case file:open(filename:join(Dir, FileName), [write]) of + {ok, Fd} -> + write_config_file(Dir, FileName, Write, Entries, Fd); + Error -> + Error + end catch - throw:Error -> + Error -> S = erlang:get_stacktrace(), - d("File write of ~s throwed: ~p~n ~p~n", [FileName,Error,S]), + d("File write of ~s throwed: ~p~n ~p~n", + [FileName, Error, S]), Error; - T:E -> + C:E -> S = erlang:get_stacktrace(), d("File write of ~s exception: ~p:~p~n ~p~n", - [FileName,T,E,S]), - {error, - {failed_write, Dir, FileName, - {T, E, erlang:get_stacktrace()}}} - end. - - -do_write_config_file(Dir, FileName, Verify, Write) -> - Verify(), - case file:open(filename:join(Dir, FileName), [write]) of - {ok, Fd} -> - file_write_and_close(Write, Fd, Dir, FileName); - Error -> - Error + [FileName,C,E,S]), + {error, {failed_write, Dir, FileName, {C, E, S}}} end. -append_config_file(Dir, FileName, Verify, Write) - when (is_list(Dir) andalso - is_list(FileName) andalso - is_function(Verify) andalso - is_function(Write)) -> - try - begin - do_append_config_file(Dir, FileName, Verify, Write) - end +write_config_file(Dir, FileName, Write, Entries, Fd) -> + try Write(Fd, Entries) of + ok -> + close_config_file(Dir, FileName, Fd) catch - throw:Error -> - Error; - T:E -> - {error, - {failed_append, Dir, FileName, - {T, E, erlang:get_stacktrace()}}} - end. - -do_append_config_file(Dir, FileName, Verify, Write) -> - Verify(), - case file:open(filename:join(Dir, FileName), [read, write]) of - {ok, Fd} -> - file:position(Fd, eof), - file_write_and_close(Write, Fd, Dir, FileName); Error -> - Error + S = erlang:get_stacktrace(), + d("File write of ~s throwed: ~p~n ~p~n", + [FileName, Error, S]), + close_config_file(Dir, FileName, Fd), + Error; + C:E -> + S = erlang:get_stacktrace(), + d("File write of ~s exception: ~p:~p~n ~p~n", + [FileName,C,E,S]), + close_config_file(Dir, FileName, Fd), + {error, {failed_write, Dir, FileName, {C, E, S}}} end. - -file_write_and_close(Write, Fd, Dir, FileName) -> - ok = Write(Fd), +close_config_file(Dir, FileName, Fd) -> case file:sync(Fd) of ok -> case file:close(Fd) of @@ -2563,23 +2561,83 @@ file_write_and_close(Write, Fd, Dir, FileName) -> {error, {failed_closing, Dir, FileName, Reason}} end; {error, Reason} -> + _ = file:close(Fd), {error, {failed_syncing, Dir, FileName, Reason}} end. -%% XXX remove -read_config_file(Dir, FileName, Verify) -> - read_config_file( - Dir, FileName, fun snmp_conf:no_order/2, - fun (Term, State) -> - {Verify(Term), State} - end). --spec read_config_file(Dir :: string(), - FileName :: string(), - Order :: function(), - Verify :: function()) -> - {ok, Config :: list()} | {error, Reason :: term()}. +-spec append_config_file( + Dir :: string(), + FileName :: string(), + Order :: order_config_entry_function(), + Check :: check_config_entry_function(), + Write :: write_config_function(), + Entries :: [term()]) -> + ok | {error, term()}. + +append_config_file(Dir, FileName, Order, Check, Write, Entries) + when is_list(Dir), is_list(FileName), + is_function(Order), is_function(Check), is_function(Write), + is_list(Entries) -> + case file:open(filename:join(Dir, FileName), [read, write]) of + {ok, Fd} -> + append_config_file( + Dir, FileName, Order, Check, Write, Entries, Fd); + Error -> + Error + end. + +append_config_file(Dir, FileName, Order, Check, Write, Entries, Fd) -> + try + %% Verify the entries together with the file content + LinesInFileR = read_lines(Fd, [], 1), + StartLine = + case LinesInFileR of + [] -> + 1; + [{_, _, EndLine} | _] -> + EndLine + end, + LinesR = prepend_lines(LinesInFileR, Entries, StartLine), + SortedLines = sort_lines(lists:reverse(LinesR), Order), + _ = verify_lines(SortedLines, Check, undefined, []), + %% Append to the file + Write(Fd, Entries) + of + ok -> + close_config_file(Dir, FileName, Fd) + catch + Error -> + S = erlang:get_stacktrace(), + d("File append of ~s throwed: ~p~n ~p~n", + [FileName, Error, S]), + close_config_file(Dir, FileName, Fd), + Error; + C:E -> + S = erlang:get_stacktrace(), + d("File append of ~s exception: ~p:~p~n ~p~n", + [FileName,C,E,S]), + close_config_file(Dir, FileName, Fd), + {error, {failed_append, Dir, FileName, {C, E, S}}} + end. + +%% Fake line numbers, one per entry +prepend_lines(Lines, [], _) -> + Lines; +prepend_lines(Lines, [Entry | Entries], StartLine) -> + EndLine = StartLine + 1, + prepend_lines([{StartLine, Entry, EndLine} | Lines], Entries, EndLine). + + + +-spec read_config_file( + Dir :: string(), + FileName :: string(), + Order :: order_config_entry_function(), + Check :: check_config_entry_function()) -> + {ok, Config :: [Entry :: term()]} | + {error, Reason :: term()}. read_config_file(Dir, FileName, Order, Check) when is_list(Dir), is_list(FileName), @@ -2587,17 +2645,20 @@ read_config_file(Dir, FileName, Order, Check) case file:open(filename:join(Dir, FileName), [read]) of {ok, Fd} -> try - {ok, - verify_lines( - lists:sort( - fun ({_, T1, _}, {_, T2, _}) -> - Order(T1, T2) - end, - read_lines(Fd, [], 1)), - Check, undefined, [])} + Lines = lists:reverse(read_lines(Fd, [], 1)), + SortedLines = sort_lines(Lines, Order), + {ok, verify_lines(SortedLines, Check, undefined, [])} catch Error -> - {error, Error} + S = erlang:get_stacktrace(), + d("File read of ~s throwed: ~p~n ~p~n", + [FileName, Error, S]), + {error, Error}; + T:E -> + S = erlang:get_stacktrace(), + d("File read of ~s exception: ~p:~p~n ~p~n", + [FileName,T,E,S]), + {error, {failed_read, Dir, FileName, {T, E, S}}} after file:close(Fd) end; @@ -2612,7 +2673,7 @@ read_lines(Fd, Acc, StartLine) -> {error, Error, EndLine} -> throw({failed_reading, StartLine, EndLine, Error}); {eof, _EndLine} -> - lists:reverse(Acc) + Acc end. read_and_parse_term(Fd, StartLine) -> @@ -2628,6 +2689,12 @@ read_and_parse_term(Fd, StartLine) -> Other end. +sort_lines(Lines, Order) -> + lists:sort( + fun ({_, T1, _}, {_, T2, _}) -> + Order(T1, T2) + end, Lines). + verify_lines([], _, _, Acc) -> lists:reverse(Acc); verify_lines( @@ -2646,53 +2713,6 @@ verify_lines( end. -%% XXX remove - -%% do_read_config_file(Dir, FileName, Verify) -> -%% case file:open(filename:join(Dir, FileName), [read]) of -%% {ok, Fd} -> -%% Result = read_loop(Fd, [], Verify, 1), -%% file:close(Fd), -%% Result; -%% {error, Reason} -> -%% {error, {Reason, FileName}} -%% end. - -%% read_loop(Fd, Acc, Check, StartLine) -> -%% case read_term(Fd, StartLine) of -%% {ok, Term, EndLine} -> -%% case (catch Check(Term)) of -%% ok -> -%% read_loop(Fd, [Term | Acc], Check, EndLine); -%% {error, Reason} -> -%% {error, {failed_check, StartLine, EndLine, Reason}}; -%% Error -> -%% {error, {failed_check, StartLine, EndLine, Error}} -%% end; -%% {error, EndLine, Error} -> -%% {error, {failed_reading, StartLine, EndLine, Error}}; -%% eof -> -%% {ok, lists:reverse(Acc)} -%% end. - -%% read_term(Fd, StartLine) -> -%% case io:request(Fd, {get_until, "", erl_scan, tokens, [StartLine]}) of -%% {ok, Tokens, EndLine} -> -%% case erl_parse:parse_term(Tokens) of -%% {ok, Term} -> -%% {ok, Term, EndLine}; -%% {error, {Line, erl_parse, Error}} -> -%% {error, Line, {parse_error, Error}} -%% end; -%% {error, E, EndLine} -> -%% {error, EndLine, E}; -%% {eof, _EndLine} -> -%% eof; -%% Other -> -%% Other -%% end. - - agent_snmp_mk_secret(Alg, Passwd, EngineID) -> snmp_usm:passwd2localized_key(Alg, Passwd, EngineID). -- cgit v1.2.3 From 4dba07b435696393adbf582933f9b539be48b943 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 28 May 2014 16:26:34 +0200 Subject: Use IPv6 config in manager --- lib/snmp/src/manager/snmpm_conf.erl | 13 +- lib/snmp/src/manager/snmpm_config.erl | 28 ++- lib/snmp/src/manager/snmpm_mpd.erl | 22 +- lib/snmp/src/manager/snmpm_net_if.erl | 271 ++++++++++++-------- lib/snmp/src/manager/snmpm_net_if_filter.erl | 16 +- lib/snmp/src/manager/snmpm_server.erl | 362 +++++++++++++-------------- lib/snmp/src/misc/snmp_conf.erl | 2 + lib/snmp/src/misc/snmp_config.erl | 17 +- lib/snmp/test/snmp_manager_test.erl | 105 +++++--- 9 files changed, 481 insertions(+), 355 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index d2f9ba9c26..ed4cfd749e 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -110,14 +110,15 @@ write_manager_conf(Fd, [H|T]) -> do_write_manager_conf(Fd, H), write_manager_conf(Fd, T). -do_write_manager_conf(Fd, {address = Tag, Val}) -> +do_write_manager_conf(Fd, {Tag, Val}) + when Tag =:= domain; + Tag =:= address; + Tag =:= port; + Tag =:= max_message_size -> io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); -do_write_manager_conf(Fd, {port = Tag, Val} ) -> - io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); -do_write_manager_conf(Fd, {engine_id = Tag, Val} ) -> +do_write_manager_conf(Fd, {Tag, Val}) + when Tag =:= engine_id -> io:format(Fd, "{~w, \"~s\"}.~n", [Tag, Val]); -do_write_manager_conf(Fd, {max_message_size = Tag, Val} ) -> - io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_manager_conf(_Fd, Crap) -> error({bad_manager_config, Crap}). diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index b3500d7293..5ebd3a0662 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -2297,9 +2297,33 @@ read_manager_config_file(Dir) -> %% If the address is not possible to determine %% that way, then we give up... verify_mandatory(Conf, [port,engine_id,max_message_size]), - ensure_config(default_manager_config(), Conf). - + default_manager_config(Conf). +default_manager_config(Conf) -> + %% Ensure address of right family + case lists:keyfind(address, 1, Conf) of + false -> + Domain = + case lists:keyfind(domain, 1, Conf) of + false -> + default_transport_domain(); + {_, D} -> + D + end, + Family = snmp_conf:tdomain_to_family(Domain), + {ok, HostName} = inet:gethostname(), + case inet:getaddr(HostName, Family) of + {ok, Address} -> + [{address, Address} | Conf]; + {error, _Reason} -> + ?d("default_manager_config -> " + "failed getting ~w address for ~s:~n" + " _Reason: ~p", [Family, HostName, _Reason]), + Conf + end; + _ -> + Conf + end. default_manager_config() -> {ok, HostName} = inet:gethostname(), diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl index 27f0336bc1..521c496adb 100644 --- a/lib/snmp/src/manager/snmpm_mpd.erl +++ b/lib/snmp/src/manager/snmpm_mpd.erl @@ -92,10 +92,10 @@ reset(#state{v3 = V3}) -> %% Purpose: This is the main Message Dispatching function. (see %% section 4.2.1 in rfc2272) %%----------------------------------------------------------------- -process_msg(Msg, Domain, Addr, Port, State, NoteStore, Logger) -> - process_msg(Msg, Domain, {Addr, Port}, State, NoteStore, Logger). +process_msg(Msg, Domain, Ip, Port, State, NoteStore, Logger) -> + process_msg(Msg, Domain, {Ip, Port}, State, NoteStore, Logger). -process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> +process_msg(Msg, Domain, Addr, State, NoteStore, Logger) -> inc(snmpInPkts), case (catch snmp_pdus:dec_message_only(binary_to_list(Msg))) of @@ -105,7 +105,7 @@ process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> when State#state.v1 =:= true -> HS = ?empty_msg_size + length(Community), process_v1_v2c_msg( - 'version-1', NoteStore, Msg, Domain, Address, + 'version-1', NoteStore, Msg, Domain, Addr, Community, Data, HS, Logger); %% Version 2 @@ -113,7 +113,7 @@ process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> when State#state.v2c =:= true -> HS = ?empty_msg_size + length(Community), process_v1_v2c_msg( - 'version-2', NoteStore, Msg, Domain, Address, + 'version-2', NoteStore, Msg, Domain, Addr, Community, Data, HS, Logger); %% Version 3 @@ -124,7 +124,7 @@ process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> "~n msgFlags: ~p" "~n msgSecModel: ~p", [H#v3_hdr.msgID,H#v3_hdr.msgFlags,H#v3_hdr.msgSecurityModel]), - process_v3_msg(NoteStore, Msg, H, Data, Address, Logger); + process_v3_msg(NoteStore, Msg, H, Data, Addr, Logger); %% Crap {'EXIT', {bad_version, Vsn}} -> @@ -151,26 +151,26 @@ process_msg(Msg, Domain, Address, State, NoteStore, Logger) -> %% Handles a Community based message (v1 or v2c). %%----------------------------------------------------------------- process_v1_v2c_msg( - Vsn, _NoteStore, Msg, Domain, Address, Community, Data, HS, Log) -> + Vsn, _NoteStore, Msg, Domain, Addr, Community, Data, HS, Log) -> ?vdebug("process_v1_v2c_msg -> entry with" "~n Vsn: ~p" "~n Domain: ~p" - "~n Address: ~p" + "~n Addr: ~p" "~n Community: ~p" - "~n HS: ~p", [Vsn, Domain, Address, Community, HS]), + "~n HS: ~p", [Vsn, Domain, Addr, Community, HS]), {TDomain, TAddress} = try {snmp_conf:mk_tdomain(Domain), - snmp_conf:mk_taddress(Domain, Address)} + snmp_conf:mk_taddress(Domain, Addr)} catch throw:{error, TReason} -> throw({discarded, {badarg, Domain, TReason}}) end, Max = get_max_message_size(), - AgentMax = get_agent_max_message_size(Address), + AgentMax = get_agent_max_message_size(Addr), PduMS = pdu_ms(Max, AgentMax, HS), ?vtrace("process_v1_v2c_msg -> PduMS: ~p", [PduMS]), diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index d7f17e0b7f..860b0b83dd 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -55,11 +55,12 @@ %% -define(VMODULE,"NET_IF"). -include("snmp_verbosity.hrl"). --record(state, +-record(state, { server, note_store, - sock, + domain, + sock, mpd_state, log, irb = auto, % auto | {user, integer()} @@ -99,22 +100,22 @@ start_link(Server, NoteStore) -> stop(Pid) -> call(Pid, stop). -send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort) -> - send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort, ?DEFAULT_EXTRA_INFO). +send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port) -> + send_pdu( + Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port, ?DEFAULT_EXTRA_INFO). -send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo) - when is_record(Pdu, pdu), is_atom(Domain) -> +send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port, ExtraInfo) + when is_record(Pdu, pdu) -> ?d("send_pdu -> entry with~n" - " Pid: ~p~n" - " Pdu: ~p~n" - " Vsn: ~p~n" - " MsgData: ~p~n" - " Domain: ~p~n" - " Address: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Address]), - cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}); -send_pdu(Pid, Pdu, Vsn, MsgData, Ip, Port, ExtraInfo) -> - Domain = snmpm_config:default_transport_domain(), - send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). + " Pid: ~p~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain/IP: ~p~n" + " Addr/Port: ~p", + [Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port]), + {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), + cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}). send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). @@ -122,8 +123,9 @@ send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> note_store(Pid, NoteStore) -> call(Pid, {note_store, NoteStore}). -inform_response(Pid, Ref, Domain, Address) -> - cast(Pid, {inform_response, Ref, Domain, Address}). +inform_response(Pid, Ref, Domain_or_Ip, Addr_or_Port) -> + {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), + cast(Pid, {inform_response, Ref, Domain, Addr}). info(Pid) -> call(Pid, info). @@ -200,7 +202,14 @@ do_init(Server, NoteStore) -> BindTo = get_opt(Opts, bind_to, false), NoReuse = get_opt(Opts, no_reuse, false), {ok, Port} = snmpm_config:system_info(port), - {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, BindTo, NoReuse), + Domain = + case snmpm_config:system_info(domain) of + {ok, D} -> + D; + _ -> + snmpm_config:default_transport_domain() + end, + {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), %% Flow control -- FilterOpts = get_opt(Opts, filter, []), @@ -218,6 +227,7 @@ do_init(Server, NoteStore) -> State = #state{server = Server, note_store = NoteStore, mpd_state = MpdState, + domain = Domain, sock = Sock, log = Log, irb = IRB, @@ -228,18 +238,23 @@ do_init(Server, NoteStore) -> %% Open port -do_open_port(Port, SendSz, RecvSz, BindTo, NoReuse) -> - ?vtrace("do_open_port -> entry with" - "~n Port: ~p" - "~n SendSz: ~p" - "~n RecvSz: ~p" - "~n BindTo: ~p" - "~n NoReuse: ~p", [Port, SendSz, RecvSz, BindTo, NoReuse]), +do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> + ?vtrace("do_open_port -> entry with~n" + " Port: ~p~n" + " SendSz: ~p~n" + " RecvSz: ~p~n" + " Domain: ~p~n" + " BindTo: ~p~n" + " NoReuse: ~p", + [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), IpOpts1 = bind_to(BindTo), IpOpts2 = no_reuse(NoReuse), IpOpts3 = recbuf(RecvSz), IpOpts4 = sndbuf(SendSz), - IpOpts = [binary | IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], + IpOpts = + [binary, + snmp_conf:tdomain_to_family(Domain) | + IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], OpenRes = case init:get_argument(snmpm_fd) of {ok, [[FdStr]]} -> @@ -387,24 +402,24 @@ handle_call(Req, From, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}, +handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}, State) -> ?vlog("received send_pdu message with~n" " Pdu: ~p~n" " Vsn: ~p~n" " MsgData: ~p~n" " Domain: ~p~n" - " Address: ~p", [Pdu, Vsn, MsgData, Domain, Address]), + " Addr : ~p", [Pdu, Vsn, MsgData, Domain, Addr]), maybe_process_extra_info(ExtraInfo), - maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State), + maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State), {noreply, State}; -handle_cast({inform_response, Ref, Domain, Address}, State) -> +handle_cast({inform_response, Ref, Domain, Addr}, State) -> ?vlog("received inform_response message with~n" - " Ref: ~p~n" - " Domain: ~p~n" - " Address: ~p", [Ref, Domain, Address]), - handle_inform_response(Ref, Domain, Address, State), + " Ref: ~p~n" + " Domain: ~p~n" + " Addr: ~p", [Ref, Domain, Addr]), + handle_inform_response(Ref, Domain, Addr, State), {noreply, State}; handle_cast(filter_reset, State) -> @@ -423,9 +438,10 @@ handle_cast(Msg, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> +handle_info( + {udp, Sock, Ip, Port, Bytes}, + #state{sock = Sock, domain = Domain} = State) -> ?vlog("received ~w bytes from ~p:~p [~w]", [size(Bytes), Ip, Port, Sock]), - Domain = snmpm_config:default_transport_domain(), maybe_handle_recv_msg(Domain, {Ip, Port}, Bytes, State), {noreply, State}; @@ -533,48 +549,49 @@ code_change(_Vsn, State, _Extra) -> %%%------------------------------------------------------------------- maybe_handle_recv_msg( - Domain, Address, Bytes, #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv(Domain, Address)) of + Domain, Addr, Bytes, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv(Arg1, Arg2)) of false -> %% Drop the received packet inc(netIfMsgInDrops), ok; _ -> - handle_recv_msg(Domain, Address, Bytes, State) + handle_recv_msg(Domain, Addr, Bytes, State) end. -handle_recv_msg(Domain, Address, Bytes, #state{server = Pid}) +handle_recv_msg(Domain, Addr, Bytes, #state{server = Pid}) when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> - Pid ! {snmp_error, {empty_message, Domain, Address}, Domain, Address}, + Pid ! {snmp_error, {empty_message, Domain, Addr}, Domain, Addr}, ok; handle_recv_msg( - Domain, Address, Bytes, + Domain, Addr, Bytes, #state{server = Pid, note_store = NoteStore, mpd_state = MpdState, - sock = Sock, log = Log} = State) -> - Logger = logger(Log, read, Domain, Address), - case (catch snmpm_mpd:process_msg(Bytes, Domain, Address, + Logger = logger(Log, read, Domain, Addr), + case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, MpdState, NoteStore, Logger)) of {ok, Vsn, Pdu, MS, ACM} -> - maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, MS, ACM, + maybe_handle_recv_pdu(Domain, Addr, Vsn, Pdu, MS, ACM, Logger, State); {discarded, Reason, Report} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Address}, - maybe_udp_send(State#state.filter, Sock, Domain, Address, Report), + Pid ! {snmp_error, ErrorInfo, Domain, Addr}, + maybe_udp_send(Domain, Addr, Report, State), ok; {discarded, Reason} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Address}, + Pid ! {snmp_error, ErrorInfo, Domain, Addr}, ok; Error -> @@ -585,92 +602,93 @@ handle_recv_msg( maybe_handle_recv_pdu( - Domain, Address, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, - #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv_pdu(Domain, Address, Type)) of + Domain, Addr, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, Type)) of false -> inc(netIfPduInDrops), ok; _ -> handle_recv_pdu( - Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) + Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) end; maybe_handle_recv_pdu( - Domain, Address, Vsn, Trap, PduMS, ACM, Logger, - #state{filter = FilterMod} = State) + Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, + #state{filter = FilterMod, domain = ManagerDomain} = State) when is_record(Trap, trappdu) -> - case (catch FilterMod:accept_recv_pdu(Domain, Address, trappdu)) of + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, trappdu)) of false -> inc(netIfPduInDrops), ok; _ -> handle_recv_pdu( - Domain, Address, Vsn, Trap, PduMS, ACM, Logger, State) + Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, State) end; maybe_handle_recv_pdu( - Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) -> - handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State). + Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) -> + handle_recv_pdu(Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State). handle_recv_pdu( - Domain, Address, Vsn, + Domain, Addr, Vsn, #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, Logger, #state{server = Pid, irb = IRB} = State) -> handle_inform_request( - IRB, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State); + IRB, Pid, Vsn, Pdu, ACM, Domain, Addr, Logger, State); handle_recv_pdu( - Domain, Address, _Vsn, + Domain, Addr, _Vsn, #pdu{type = report} = Pdu, _PduMS, ok, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - ok", []), - Pid ! {snmp_report, {ok, Pdu}, Domain, Address}; + Pid ! {snmp_report, {ok, Pdu}, Domain, Addr}; handle_recv_pdu( - Domain, Address, _Vsn, + Domain, Addr, _Vsn, #pdu{type = report} = Pdu, _PduMS, {error, ReqId, Reason}, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - error", []), - Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Address}; + Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Addr}; handle_recv_pdu( - Domain, Address, _Vsn, + Domain, Addr, _Vsn, #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) -> ?vtrace("received snmpv2-trap", []), - Pid ! {snmp_trap, Pdu, Domain, Address}; + Pid ! {snmp_trap, Pdu, Domain, Addr}; handle_recv_pdu( - Domain, Address, _Vsn, Trap, _PduMS, _ACM, _Logger, + Domain, Addr, _Vsn, Trap, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Trap, trappdu) -> ?vtrace("received trappdu", []), - Pid ! {snmp_trap, Trap, Domain, Address}; + Pid ! {snmp_trap, Trap, Domain, Addr}; handle_recv_pdu( - Domain, Address, _Vsn, Pdu, _PduMS, _ACM, _Logger, + Domain, Addr, _Vsn, Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Pdu, pdu) -> ?vtrace("received pdu", []), - Pid ! {snmp_pdu, Pdu, Domain, Address}; + Pid ! {snmp_pdu, Pdu, Domain, Addr}; handle_recv_pdu( - _Domain, _Address, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> + _Domain, _Addr, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> ?vlog("received unexpected pdu: " "~n Pdu: ~p" "~n ACM: ~p", [Pdu, ACM]). handle_inform_request( - auto, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State) -> + auto, Pid, Vsn, Pdu, ACM, Domain, Addr, Logger, State) -> ?vtrace("received inform-request (true)", []), - Pid ! {snmp_inform, ignore, Pdu, Domain, Address}, + Pid ! {snmp_inform, ignore, Pdu, Domain, Addr}, RePdu = make_response_pdu(Pdu), - maybe_send_inform_response( - RePdu, Vsn, ACM, Domain, Address, Logger, State); + maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Addr, Logger, State); handle_inform_request( {user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, - ACM, Domain, Address, _Logger, _State) -> + ACM, Domain, Addr, _Logger, _State) -> ?vtrace("received inform-request (false)", []), - Pid ! {snmp_inform, ReqId, Pdu, Domain, Address}, + Pid ! {snmp_inform, ReqId, Pdu, Domain, Addr}, %% Before we go any further, we need to check that we have not %% already received this message (possible resend). - Key = {ReqId, Domain, Address}, + Key = {ReqId, Domain, Addr}, case ets:lookup(snmpm_inform_request_table, Key) of [_] -> %% OK, we already know about this. We assume this @@ -684,26 +702,28 @@ handle_inform_request( ets:insert(snmpm_inform_request_table, Rec) end. -handle_inform_response(Ref, Domain, Address, State) -> - Key = {Ref, Domain, Address}, +handle_inform_response(Ref, Domain, Addr, State) -> + Key = {Ref, Domain, Addr}, case ets:lookup(snmpm_inform_request_table, Key) of [{Key, _, {Vsn, ACM, RePdu}}] -> - Logger = logger(State#state.log, read, Domain, Address), + Logger = logger(State#state.log, read, Domain, Addr), ets:delete(snmpm_inform_request_table, Key), - maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, - Logger, State); + maybe_send_inform_response( + RePdu, Vsn, ACM, Domain, Addr, Logger, State); [] -> %% Already acknowledged, or the user was to slow to reply... ok end, ok. -maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, - #state{server = Pid, - sock = Sock, - filter = FilterMod}) -> +maybe_send_inform_response( + RePdu, Vsn, ACM, Domain, Addr, Logger, + #state{server = Pid, + filter = FilterMod, + domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), case (catch FilterMod:accept_send_pdu( - Domain, Address, pdu_type_of(RePdu))) + Arg1, Arg2, pdu_type_of(RePdu))) of false -> inc(netIfPduOutDrops), @@ -711,13 +731,13 @@ maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, _ -> case snmpm_mpd:generate_response_msg(Vsn, RePdu, ACM, Logger) of {ok, Msg} -> - maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); + maybe_udp_send(Domain, Addr, Msg, State); {discarded, Reason} -> ?vlog("failed generating response message:" "~n Reason: ~p", [Reason]), ReqId = RePdu#pdu.request_id, ErrorInfo = {failed_generating_response, {RePdu, Reason}}, - Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Address}, + Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Addr}, ok end end. @@ -752,28 +772,29 @@ irgc_stop(Ref) -> (catch erlang:cancel_timer(Ref)). -maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, - #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_send_pdu(Domain, Address, pdu_type_of(Pdu))) of +maybe_handle_send_pdu( + Pdu, Vsn, MsgData, Domain, Addr, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_send_pdu(Arg1, Arg2, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), ok; _ -> - handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State) + handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) end. -handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, - #state{server = Pid, - note_store = NoteStore, - sock = Sock, - log = Log, - filter = FilterMod}) -> - Logger = logger(Log, write, Domain, Address), - case (catch snmpm_mpd:generate_msg(Vsn, NoteStore, - Pdu, MsgData, Logger)) of +handle_send_pdu( + Pdu, Vsn, MsgData, Domain, Addr, + #state{server = Pid, + note_store = NoteStore, + log = Log} = State) -> + Logger = logger(Log, write, Domain, Addr), + case (catch snmpm_mpd:generate_msg( + Vsn, NoteStore, Pdu, MsgData, Logger)) of {ok, Msg} -> ?vtrace("handle_send_pdu -> message generated", []), - maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); + maybe_udp_send(Domain, Addr, Msg, State); {discarded, Reason} -> ?vlog("PDU not sent: " "~n PDU: ~p" @@ -783,12 +804,18 @@ handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, end. -maybe_udp_send(FilterMod, Sock, Domain, {Ip, Port} = Address, Msg) -> - case (catch FilterMod:accept_send(Domain, Address)) of +maybe_udp_send( + Domain, Addr, Msg, + #state{sock = Sock, filter = FilterMod, domain = ManagerDomain}) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_send(Arg1, Arg2)) of false -> inc(netIfMsgOutDrops), ok; _ -> + %% XXX There should be some kind of lookup of socket + %% from transport domain here + {Ip, Port} = Addr, udp_send(Sock, Ip, Port, Msg) end. @@ -998,6 +1025,26 @@ handle_set_log_type(State, _NewType) -> {State, {error, not_enabled}}. +%% If the manager uses legacy snmpUDPDomain e.g has not set +%% {domain, _}, then make sure snmpm_network_interface_filter +%% gets legacy arguments to not break backwards compatibility. +%% +fix_filter_address(snmpUDPDomain, {Domain, Addr}) + when Domain =:= snmpUDPDomain; + Domain =:= transportDomainUdpIpv4 -> + Addr; +fix_filter_address(_ManagerDomain, {Domain, _} = Address) + when is_atom(Domain) -> + Address; +fix_filter_address(snmpUDPDomain, {_, Port} = Addr) + when is_integer(Port) -> + Addr. + +address(Domain, Addr) when is_atom(Domain) -> + {Domain, Addr}; +address(Ip, Port) when is_integer(Port) -> + {snmpm_config:default_transport_domain(), {Ip, Port}}. + %% ------------------------------------------------------------------- make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> @@ -1038,15 +1085,17 @@ t() -> %% ------------------------------------------------------------------- -logger(undefined, _Type, _Domain, _Address) -> +logger(undefined, _Type, _Domain, _Addr) -> fun(_) -> ok end; -logger({Log, Types}, Type, Domain, Address) -> +logger({Log, Types}, Type, Domain, Addr) -> case lists:member(Type, Types) of true -> + AddrString = + iolist_to_binary(snmp_conf:mk_addr_string({Domain, Addr})), fun(Msg) -> - snmp_log:log(Log, Msg, Domain, Address) + snmp_log:log(Log, Msg, AddrString) end; false -> fun(_) -> diff --git a/lib/snmp/src/manager/snmpm_net_if_filter.erl b/lib/snmp/src/manager/snmpm_net_if_filter.erl index 54b87a772a..d96ae5c145 100644 --- a/lib/snmp/src/manager/snmpm_net_if_filter.erl +++ b/lib/snmp/src/manager/snmpm_net_if_filter.erl @@ -30,10 +30,10 @@ accept_recv(Domain, _Address) when is_atom(Domain) -> " Domain: ~p~n" " Address: ~p", [Domain, _Address]), true; -accept_recv(_Addr, _Port) -> +accept_recv(_Addr, Port) when is_integer(Port) -> ?d("accept_recv -> entry with~n" " Addr: ~p~n" - " Port: ~p", [_Addr, _Port]), + " Port: ~p", [_Addr, Port]), true. accept_send(Domain, _Address) when is_atom(Domain) -> @@ -41,10 +41,10 @@ accept_send(Domain, _Address) when is_atom(Domain) -> " Domain: ~p~n" " Address: ~p", [Domain, _Address]), true; -accept_send(_Addr, _Port) -> +accept_send(_Addr, Port) when is_integer(Port) -> ?d("accept_send -> entry with~n" " Addr: ~p~n" - " Port: ~p", [_Addr, _Port]), + " Port: ~p", [_Addr, Port]), true. accept_recv_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> @@ -53,11 +53,11 @@ accept_recv_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> " Address: ~p~n" " PduType: ~p", [Domain, _Address, _PduType]), true; -accept_recv_pdu(_Addr, _Port, _PduType) -> +accept_recv_pdu(_Addr, Port, _PduType) when is_integer(Port) -> ?d("accept_recv_pdu -> entry with~n" " Addr: ~p~n" " Port: ~p~n" - " PduType: ~p", [_Addr, _Port, _PduType]), + " PduType: ~p", [_Addr, Port, _PduType]), true. accept_send_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> @@ -66,10 +66,10 @@ accept_send_pdu(Domain, _Address, _PduType) when is_atom(Domain) -> " Address: ~p~n" " PduType: ~p", [Domain, _Address, _PduType]), true; -accept_send_pdu(_Addr, _Port, _PduType) -> +accept_send_pdu(_Addr, Port, _PduType) when is_integer(Port) -> ?d("accept_send_pdu -> entry with~n" " Addr: ~p~n" " Port: ~p~n" - " PduType: ~p", [_Addr, _Port, _PduType]), + " PduType: ~p", [_Addr, Port, _PduType]), true. diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index b3389ef96c..ece5dad082 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -1032,14 +1032,14 @@ handle_info({snmp_error, Pdu, Reason}, State) -> handle_snmp_error(Pdu, Reason, State), {noreply, State}; -handle_info({snmp_error, Reason, Domain, Address}, State) -> +handle_info({snmp_error, Reason, Domain, Addr}, State) -> ?vlog("received snmp_error message", []), - handle_snmp_error(Domain, Address, -1, Reason, State), + handle_snmp_error(Domain, Addr, -1, Reason, State), {noreply, State}; -handle_info({snmp_error, ReqId, Reason, Domain, Address}, State) -> +handle_info({snmp_error, ReqId, Reason, Domain, Addr}, State) -> ?vlog("received snmp_error message", []), - handle_snmp_error(Domain, Address, ReqId, Reason, State), + handle_snmp_error(Domain, Addr, ReqId, Reason, State), {noreply, State}; %% handle_info({snmp_error, ReqId, Pdu, Reason, Addr, Port}, State) -> @@ -1048,30 +1048,30 @@ handle_info({snmp_error, ReqId, Reason, Domain, Address}, State) -> %% {noreply, State}; -handle_info({snmp_pdu, Pdu, Domain, Address}, State) -> +handle_info({snmp_pdu, Pdu, Domain, Addr}, State) -> ?vlog("received snmp_pdu message", []), - handle_snmp_pdu(Pdu, Domain, Address, State), + handle_snmp_pdu(Pdu, Domain, Addr, State), {noreply, State}; -handle_info({snmp_trap, Trap, Domain, Address}, State) -> +handle_info({snmp_trap, Trap, Domain, Addr}, State) -> ?vlog("received snmp_trap message", []), - handle_snmp_trap(Trap, Domain, Address, State), + handle_snmp_trap(Trap, Domain, Addr, State), {noreply, State}; -handle_info({snmp_inform, Ref, Pdu, Domain, Address}, State) -> +handle_info({snmp_inform, Ref, Pdu, Domain, Addr}, State) -> ?vlog("received snmp_inform message", []), - handle_snmp_inform(Ref, Pdu, Domain, Address, State), + handle_snmp_inform(Ref, Pdu, Domain, Addr, State), {noreply, State}; -handle_info({snmp_report, {ok, Pdu}, Domain, Address}, State) -> - handle_snmp_report(Pdu, Domain, Address, State), +handle_info({snmp_report, {ok, Pdu}, Domain, Addr}, State) -> + handle_snmp_report(Pdu, Domain, Addr, State), {noreply, State}; -handle_info({snmp_report, {error, ReqId, Info, Pdu}, Domain, Address}, State) -> - handle_snmp_report(ReqId, Pdu, Info, Domain, Address, State), +handle_info({snmp_report, {error, ReqId, Info, Pdu}, Domain, Addr}, State) -> + handle_snmp_report(ReqId, Pdu, Info, Domain, Addr, State), {noreply, State}; @@ -1175,11 +1175,11 @@ handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> "~n From: ~p", [Pid, UserId, TargetName, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_sync_get -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_sync_get -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1192,7 +1192,7 @@ handle_sync_get(Pid, UserId, TargetName, Oids, SendOpts, From, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get, data = MsgData, ref = Ref, @@ -1228,11 +1228,11 @@ handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, "~n From: ~p", [Pid, UserId, TargetName, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_sync_get_next -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_next_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_sync_get_next -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1245,7 +1245,7 @@ handle_sync_get_next(Pid, UserId, TargetName, Oids, SendOpts, reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get_next, data = MsgData, ref = Ref, @@ -1287,11 +1287,11 @@ handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, "~n From: ~p", [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_sync_get_bulk -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_bulk_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, NonRep, MaxRep, Extra, State), ?vdebug("handle_sync_get_bulk -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1304,7 +1304,7 @@ handle_sync_get_bulk(Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts, reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get_bulk, data = MsgData, ref = Ref, @@ -1342,11 +1342,11 @@ handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> "~n From: ~p", [Pid, UserId, TargetName, VarsAndVals, From]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_sync_set -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_sync_set -> ReqId: ~p", [ReqId]), Msg = {sync_timeout, ReqId, From}, @@ -1359,7 +1359,7 @@ handle_sync_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, From, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = set, data = MsgData, ref = Ref, @@ -1395,11 +1395,11 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_async_get -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_async_get -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_TIMEOUT(SendOpts), @@ -1408,7 +1408,7 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get, data = MsgData, expire = t() + Expire}, @@ -1444,11 +1444,11 @@ handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_async_get_next -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_next_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_async_get_next -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_NEXT_TIMEOUT(SendOpts), @@ -1457,7 +1457,7 @@ handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get_next, data = MsgData, expire = t() + Expire}, @@ -1500,11 +1500,11 @@ handle_async_get_bulk(Pid, "~n SendOpts: ~p", [Pid, UserId, TargetName, NonRep, MaxRep, Oids, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_async_get_bulk -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_get_bulk_request(Oids, Vsn, MsgData, - Domain, Address, + Domain, Addr, NonRep, MaxRep, Extra, State), ?vdebug("handle_async_get_bulk -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_GET_BULK_TIMEOUT(SendOpts), @@ -1513,7 +1513,7 @@ handle_async_get_bulk(Pid, reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = get_bulk, data = MsgData, expire = t() + Expire}, @@ -1548,11 +1548,11 @@ handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> "~n SendOpts: ~p", [Pid, UserId, TargetName, VarsAndVals, SendOpts]), case agent_data(TargetName, SendOpts) of - {ok, RegType, Domain, Address, Vsn, MsgData} -> + {ok, RegType, Domain, Addr, Vsn, MsgData} -> ?vtrace("handle_async_set -> send a ~p message", [Vsn]), Extra = ?GET_EXTRA(SendOpts), ReqId = send_set_request(VarsAndVals, Vsn, MsgData, - Domain, Address, + Domain, Addr, Extra, State), ?vdebug("handle_async_set -> ReqId: ~p", [ReqId]), Expire = ?ASYNC_SET_TIMEOUT(SendOpts), @@ -1561,7 +1561,7 @@ handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> reg_type = RegType, target = TargetName, domain = Domain, - address = Address, + address = Addr, type = set, data = MsgData, expire = t() + Expire}, @@ -1799,15 +1799,15 @@ handle_snmp_error(CrapError, Reason, _State) -> "~n~p~n~p", [CrapError, Reason]), ok. -handle_snmp_error(Domain, Address, ReqId, Reason, State) -> +handle_snmp_error(Domain, Addr, ReqId, Reason, State) -> ?vtrace("handle_snmp_error -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" + " Addr: ~p~n" " ReqId: ~p~n" - " Reason: ~p", [Domain, Address, ReqId, Reason]), + " Reason: ~p", [Domain, Addr, ReqId, Reason]), - case snmpm_config:get_agent_user_id(Domain, Address) of + case snmpm_config:get_agent_user_id(Domain, Addr) of {ok, UserId} -> case snmpm_config:user_info(UserId) of {ok, UserMod, UserData} -> @@ -1822,7 +1822,7 @@ handle_snmp_error(Domain, Address, ReqId, Reason, State) -> error_msg("failed retreiving the default user " "info handling snmp error " "<~p,~p>: ~n~w~n~w", - [Domain, Address, ReqId, Reason]) + [Domain, Addr, ReqId, Reason]) end end; _Error -> @@ -1834,7 +1834,7 @@ handle_snmp_error(Domain, Address, ReqId, Reason, State) -> error_msg("failed retreiving the default user " "info handling snmp error " "<~p,~p>: ~n~w~n~w", - [Domain, Address, ReqId, Reason]) + [Domain, Addr, ReqId, Reason]) end end. @@ -1858,12 +1858,12 @@ handle_error(_UserId, Mod, Reason, ReqId, Data, _State) -> handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, - Domain, Address, State) -> + Domain, Addr, State) -> ?vtrace("handle_snmp_pdu(get-response) -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Pdu: ~p", [Domain, Address, Pdu]), + " Addr: ~p~n" + " Pdu: ~p", [Domain, Addr, Pdu]), case ets:lookup(snmpm_request_table, ReqId) of @@ -1895,7 +1895,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, {ok, UserMod, UserData} -> handle_pdu( UserId, UserMod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, ReqId, SnmpResponse, UserData, State), maybe_delete(Disco, ReqId); _Error -> @@ -1906,14 +1906,14 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, {ok, DefUserId, DefMod, DefData} -> handle_pdu( DefUserId, DefMod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, ReqId, SnmpResponse, DefData, State), maybe_delete(Disco, ReqId); Error -> error_msg("failed retreiving the default user " "info handling pdu from " "~p <~p,~p>: ~n~w~n~w", - [Target, Domain, Address, Error, Pdu]) + [Target, Domain, Addr, Error, Pdu]) end end; @@ -1967,7 +1967,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, varbinds = Varbinds} = Pdu, Varbinds2 = fix_vbs_BITS(Varbinds), SnmpInfo = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_id(Domain, Address) of + case snmpm_config:get_agent_user_id(Domain, Addr) of {ok, UserId} -> %% A very late reply or a reply to a request %% that has been cancelled. @@ -1992,7 +1992,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, "user info handling (old) " "pdu from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error, Pdu]) + [Domain, Addr, Error, Pdu]) end end; @@ -2011,7 +2011,7 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, pdu, ignore, SnmpInfo, DefData, State); Error -> @@ -2019,19 +2019,19 @@ handle_snmp_pdu(#pdu{type = 'get-response', request_id = ReqId} = Pdu, "info handling (old) pdu when no user " "found from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error, Pdu]) + [Domain, Addr, Error, Pdu]) end end end; -handle_snmp_pdu(CrapPdu, Domain, Address, _State) -> +handle_snmp_pdu(CrapPdu, Domain, Addr, _State) -> error_msg("received crap (snmp) Pdu from ~w:~w =>" - "~p", [Domain, Address, CrapPdu]), + "~p", [Domain, Addr, CrapPdu]), ok. handle_pdu( - _UserId, Mod, target_name = _RegType, TargetName, _Domain, _Address, + _UserId, Mod, target_name = _RegType, TargetName, _Domain, _Addr, ReqId, SnmpResponse, Data, _State) -> ?vtrace("handle_pdu(target_name) -> entry when" "~n Mod: ~p", [Mod]), @@ -2049,37 +2049,37 @@ handle_pdu( handle_callback(F), ok; handle_pdu( - _UserId, Mod, addr_port = _RegType, _TargetName, _Domain, Address, + _UserId, Mod, addr_port = _RegType, _TargetName, _Domain, Addr, ReqId, SnmpResponse, Data, _State) -> ?vtrace("handle_pdu(addr_port) -> entry when" "~n Mod: ~p", [Mod]), F = fun() -> - {Ip, Port} = Address, + {Ip, Port} = Addr, (catch Mod:handle_pdu(Ip, Port, ReqId, SnmpResponse, Data)) end, handle_callback(F), ok. -handle_agent(UserId, Mod, Domain, Address, Type, Ref, SnmpInfo, Data, State) -> +handle_agent(UserId, Mod, Domain, Addr, Type, Ref, SnmpInfo, Data, State) -> ?vtrace("handle_agent -> entry when" "~n UserId: ~p" "~n Type: ~p" "~n Mod: ~p", [UserId, Type, Mod]), F = fun() -> - do_handle_agent(UserId, Mod, Domain, Address, + do_handle_agent(UserId, Mod, Domain, Addr, Type, Ref, SnmpInfo, Data, State) end, handle_callback(F), ok. do_handle_agent(DefUserId, DefMod, - Domain, Address, + Domain, Addr, Type, Ref, SnmpInfo, DefData, State) -> ?vdebug("do_handle_agent -> entry when" "~n DefUserId: ~p", [DefUserId]), - try DefMod:handle_agent(Domain, Address, Type, SnmpInfo, DefData) of + try DefMod:handle_agent(Domain, Addr, Type, SnmpInfo, DefData) of {register, UserId2, TargetName, Config} -> ?vtrace("do_handle_agent -> register: " "~n UserId2: ~p" @@ -2088,7 +2088,7 @@ do_handle_agent(DefUserId, DefMod, [UserId2, TargetName, Config]), Config2 = ensure_present( - [{tdomain, Domain}, {taddress, Address}], Config), + [{tdomain, Domain}, {taddress, Addr}], Config), Config3 = [{reg_type, target_name} | Config2], case snmpm_config:register_agent(UserId2, TargetName, Config3) of @@ -2098,7 +2098,7 @@ do_handle_agent(DefUserId, DefMod, error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Domain, Address, Reason]), + [TargetName, Domain, Addr, Reason]), ok end; @@ -2107,23 +2107,23 @@ do_handle_agent(DefUserId, DefMod, ok; InvalidResult -> - CallbackArgs = [Domain, Address, Type, SnmpInfo, DefData], + CallbackArgs = [Domain, Addr, Type, SnmpInfo, DefData], handle_invalid_result(handle_agent, CallbackArgs, InvalidResult) catch error:{undef, _} when Type =:= pdu -> %% Maybe, still on the old API ?vdebug("do_handle_agent -> maybe still on the old api", []), - {Ip, Port} = Address, + {Ip, Port} = Addr, case (catch DefMod:handle_agent(Ip, Port, SnmpInfo, DefData)) of {register, UserId2, Config} -> ?vtrace("do_handle_agent -> register: " "~n UserId2: ~p" "~n Config: ~p", [UserId2, Config]), - TargetName = mk_target_name(Domain, Address, Config), + TargetName = mk_target_name(Domain, Addr, Config), Config2 = ensure_present( - [{tdomain, Domain}, {taddress, Address}], Config), + [{tdomain, Domain}, {taddress, Addr}], Config), Config3 = [{reg_type, addr_port} | Config2], case snmpm_config:register_agent( UserId2, TargetName, Config3) of @@ -2133,7 +2133,7 @@ do_handle_agent(DefUserId, DefMod, error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Domain, Address, Reason]), + [TargetName, Domain, Addr, Reason]), ok end; {register, UserId2, TargetName, Config} -> @@ -2144,7 +2144,7 @@ do_handle_agent(DefUserId, DefMod, [UserId2, TargetName, Config]), Config2 = ensure_present( - [{tdomain, Domain}, {taddress, Address}], Config), + [{tdomain, Domain}, {taddress, Addr}], Config), Config3 = [{reg_type, target_name} | Config2], case snmpm_config:register_agent( UserId2, TargetName, Config3) of @@ -2154,7 +2154,7 @@ do_handle_agent(DefUserId, DefMod, error_msg("failed registering agent - " "handling agent " "~p <~p,~p>: ~n~w", - [TargetName, Domain, Address, Reason]), + [TargetName, Domain, Addr, Reason]), ok end; _Ignore -> @@ -2172,38 +2172,38 @@ do_handle_agent(DefUserId, DefMod, %% Backward compatibillity crap RegType = target_name, - Target = mk_target_name(Domain, Address, default_agent_config()), + Target = mk_target_name(Domain, Addr, default_agent_config()), case Type of report -> SnmpInform = SnmpInfo, handle_report( DefUserId, DefMod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpInform, DefData, State); inform -> SnmpInform = SnmpInfo, handle_inform( DefUserId, DefMod, Ref, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpInform, DefData, State); trap -> SnmpTrapInfo = SnmpInfo, handle_trap( DefUserId, DefMod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpTrapInfo, DefData, State); _ -> error_msg( "failed delivering ~w info to default user - " "regarding agent " - "<~p,~p>: ~n~w", [Type, Domain, Address, SnmpInfo]) + "<~p,~p>: ~n~w", [Type, Domain, Addr, SnmpInfo]) end; T:E -> - CallbackArgs = [Domain, Address, Type, SnmpInfo, DefData], + CallbackArgs = [Domain, Addr, Type, SnmpInfo, DefData], handle_invalid_result(handle_agent, CallbackArgs, T, E) end. @@ -2226,45 +2226,45 @@ handle_snmp_trap( generic_trap = Generic, specific_trap = Spec, time_stamp = Timestamp, - varbinds = Varbinds} = Trap, Domain, Address, State) -> + varbinds = Varbinds} = Trap, Domain, Addr, State) -> ?vtrace("handle_snmp_trap [trappdu] -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Trap: ~p", [Domain, Address, Trap]), + " Addr: ~p~n" + " Trap: ~p", [Domain, Addr, Trap]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpTrapInfo = {Enteprise, Generic, Spec, Timestamp, Varbinds2}, - do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State); + do_handle_snmp_trap(SnmpTrapInfo, Domain, Addr, State); handle_snmp_trap(#pdu{error_status = EStatus, error_index = EIndex, varbinds = Varbinds} = Trap, - Domain, Address, State) -> + Domain, Addr, State) -> ?vtrace("handle_snmp_trap [pdu] -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Trap: ~p", [Domain, Address, Trap]), + " Addr: ~p~n" + " Trap: ~p", [Domain, Addr, Trap]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpTrapInfo = {EStatus, EIndex, Varbinds2}, - do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State); + do_handle_snmp_trap(SnmpTrapInfo, Domain, Addr, State); -handle_snmp_trap(CrapTrap, Domain, Address, _State) -> +handle_snmp_trap(CrapTrap, Domain, Addr, _State) -> error_msg("received crap (snmp) trap from ~w:~w =>" - "~p", [Domain, Address, CrapTrap]), + "~p", [Domain, Addr, CrapTrap]), ok. -do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> - case snmpm_config:get_agent_user_info(Domain, Address) of +do_handle_snmp_trap(SnmpTrapInfo, Domain, Addr, State) -> + case snmpm_config:get_agent_user_info(Domain, Addr) of {ok, UserId, Target, RegType} -> ?vtrace("handle_snmp_trap -> found user: ~p", [UserId]), case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> handle_trap( UserId, Mod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpTrapInfo, Data, State); Error1 -> @@ -2279,7 +2279,7 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, trap, ignore, SnmpTrapInfo, DefData, State); Error2 -> @@ -2287,7 +2287,7 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> "failed retreiving the default " "user info handling report from " "~p <~p,~p>: ~n~w~n~w", - [Target, Domain, Address, + [Target, Domain, Addr, Error2, SnmpTrapInfo]) end; Error3 -> @@ -2299,7 +2299,7 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> "user ~p, handling trap: " "~n Error: ~w" "~n Trap info: ~w", - [Target, Domain, Address, UserId, + [Target, Domain, Addr, UserId, Error3, SnmpTrapInfo]) end end; @@ -2307,12 +2307,12 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[trap] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Domain, Address, Error4]), + "~n ~p", [Domain, Addr, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, trap, ignore, SnmpTrapInfo, DefData, State); Error5 -> @@ -2320,21 +2320,21 @@ do_handle_snmp_trap(SnmpTrapInfo, Domain, Address, State) -> "failed retreiving " "the default user info handling trap from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error5, SnmpTrapInfo]) + [Domain, Addr, Error5, SnmpTrapInfo]) end end, ok. handle_trap( - UserId, Mod, RegType, Target, Domain, Address, SnmpTrapInfo, Data, State) -> + UserId, Mod, RegType, Target, Domain, Addr, SnmpTrapInfo, Data, State) -> ?vtrace("handle_trap -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> do_handle_trap( UserId, Mod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpTrapInfo, Data, State) end, handle_callback(F), @@ -2342,7 +2342,7 @@ handle_trap( do_handle_trap( - UserId, Mod, RegType, Target, Domain, Address, SnmpTrapInfo, Data, _State) -> + UserId, Mod, RegType, Target, Domain, Addr, SnmpTrapInfo, Data, _State) -> ?vdebug("do_handle_trap -> entry with" "~n UserId: ~p", [UserId]), {HandleTrap, CallbackArgs} = @@ -2351,7 +2351,7 @@ do_handle_trap( {fun() -> Mod:handle_trap(Target, SnmpTrapInfo, Data) end, [Target, SnmpTrapInfo, Data]}; addr_port -> - {Ip, Port} = Address, + {Ip, Port} = Addr, {fun() -> Mod:handle_trap(Ip, Port, SnmpTrapInfo, Data) end, [Ip, Port, SnmpTrapInfo, Data]} end, @@ -2361,10 +2361,10 @@ do_handle_trap( ?vtrace("do_handle_trap -> register: " "~n UserId2: ~p" "~n Config: ~p", [UserId2, Config]), - Target2 = mk_target_name(Domain, Address, Config), + Target2 = mk_target_name(Domain, Addr, Config), Config2 = [{reg_type, target_name}, - {tdomain, Domain}, {taddress, Address} | Config], + {tdomain, Domain}, {taddress, Addr} | Config], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> ok; @@ -2372,7 +2372,7 @@ do_handle_trap( error_msg("failed registering agent " "handling trap " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), ok end; {register, UserId2, Target2, Config} -> @@ -2390,19 +2390,19 @@ do_handle_trap( error_msg("failed registering agent " "handling trap " "~p <~p,~p>: ~n~w", - [Target2, Domain, Address, Reason]), + [Target2, Domain, Addr, Reason]), reply end; unregister -> ?vtrace("do_handle_trap -> unregister", []), - case snmpm_config:unregister_agent(UserId, Domain, Address) of + case snmpm_config:unregister_agent(UserId, Domain, Addr) of ok -> ok; {error, Reason} -> error_msg("failed unregistering agent " "handling trap " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), ok end; ignore -> @@ -2423,16 +2423,16 @@ handle_snmp_inform( Ref, #pdu{error_status = EStatus, error_index = EIndex, - varbinds = Varbinds} = Pdu, Domain, Address, State) -> + varbinds = Varbinds} = Pdu, Domain, Addr, State) -> ?vtrace("handle_snmp_inform -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Pdu: ~p", [Domain, Address, Pdu]), + " Addr: ~p~n" + " Pdu: ~p", [Domain, Addr, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpInform = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_info(Domain, Address) of + case snmpm_config:get_agent_user_info(Domain, Addr) of {ok, UserId, Target, RegType} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> @@ -2441,7 +2441,7 @@ handle_snmp_inform( "~n Mod: ~p", [UserId, Mod]), handle_inform( UserId, Mod, Ref, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpInform, Data, State); Error1 -> %% User no longer exists, unregister agent @@ -2455,14 +2455,14 @@ handle_snmp_inform( {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, inform, Ref, SnmpInform, DefData, State); Error2 -> error_msg("failed retreiving the default " "user info handling inform from " "~p <~p,~p>: ~n~w~n~w", - [Target, Domain, Address, + [Target, Domain, Addr, Error2, Pdu]) end; Error3 -> @@ -2473,7 +2473,7 @@ handle_snmp_inform( "user ~p, handling inform: " "~n Error: ~w" "~n Pdu: ~w", - [Target, Domain, Address, UserId, + [Target, Domain, Addr, UserId, Error3, Pdu]) end end; @@ -2481,38 +2481,38 @@ handle_snmp_inform( Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[inform] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Domain, Address, Error4]), + "~n ~p", [Domain, Addr, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent( DefUserId, DefMod, - Domain, Address, + Domain, Addr, inform, Ref, SnmpInform, DefData, State); Error5 -> error_msg("failed retreiving " "the default user info handling inform from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error5, Pdu]) + [Domain, Addr, Error5, Pdu]) end end, ok; -handle_snmp_inform(_Ref, CrapInform, Domain, Address, _State) -> +handle_snmp_inform(_Ref, CrapInform, Domain, Addr, _State) -> error_msg("received crap (snmp) inform from ~w:~w =>" - "~p", [Domain, Address, CrapInform]), + "~p", [Domain, Addr, CrapInform]), ok. handle_inform( UserId, Mod, Ref, - RegType, Target, Domain, Address, SnmpInform, Data, State) -> + RegType, Target, Domain, Addr, SnmpInform, Data, State) -> ?vtrace("handle_inform -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> do_handle_inform( UserId, Mod, Ref, - RegType, Target, Domain, Address, SnmpInform, + RegType, Target, Domain, Addr, SnmpInform, Data, State) end, handle_callback(F), @@ -2520,7 +2520,7 @@ handle_inform( do_handle_inform( UserId, Mod, Ref, - RegType, Target, Domain, Address, SnmpInform, Data, State) -> + RegType, Target, Domain, Addr, SnmpInform, Data, State) -> ?vdebug("do_handle_inform -> entry with" "~n UserId: ~p", [UserId]), {HandleInform, CallbackArgs} = @@ -2529,7 +2529,7 @@ do_handle_inform( {fun() -> Mod:handle_inform(Target, SnmpInform, Data) end, [Target, SnmpInform, Data]}; addr_port -> - {Ip, Port} = Address, + {Ip, Port} = Addr, {fun() -> Mod:handle_inform(Ip, Port, SnmpInform, Data) end, [Ip, Port, SnmpInform, Data]} end, @@ -2542,11 +2542,11 @@ do_handle_inform( "~n Config: ~p", [UserId2, Config]), %% The only user which would do this is the %% default user - Target2 = mk_target_name(Domain, Address, Config), + Target2 = mk_target_name(Domain, Addr, Config), Config2 = [{reg_type, target_name} | ensure_present( - [{tdomain, Domain}, {taddress, Address}], Config)], + [{tdomain, Domain}, {taddress, Addr}], Config)], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> reply; @@ -2554,7 +2554,7 @@ do_handle_inform( error_msg("failed registering agent " "handling inform " "~p <~p,~p>: ~n~w", - [Target2, Domain, Address, Reason]), + [Target2, Domain, Addr, Reason]), reply end; @@ -2573,21 +2573,21 @@ do_handle_inform( error_msg("failed registering agent " "handling inform " "~p <~p,~p>: ~n~w", - [Target2, Domain, Address, Reason]), + [Target2, Domain, Addr, Reason]), reply end; unregister -> ?vtrace("do_handle_inform -> unregister", []), case snmpm_config:unregister_agent( - UserId, Domain, Address) of + UserId, Domain, Addr) of ok -> reply; {error, Reason} -> error_msg("failed unregistering agent " "handling inform " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), reply end; @@ -2610,34 +2610,34 @@ do_handle_inform( reply end, - handle_inform_response(Rep, Ref, Domain, Address, State), + handle_inform_response(Rep, Ref, Domain, Addr, State), ok. -handle_inform_response(_, ignore, _Domain, _Address, _State) -> +handle_inform_response(_, ignore, _Domain, _Addr, _State) -> ignore; -handle_inform_response(no_reply, _Ref, _Domain, _Address, _State) -> +handle_inform_response(no_reply, _Ref, _Domain, _Addr, _State) -> no_reply; handle_inform_response( - _, Ref, Domain, Address, + _, Ref, Domain, Addr, #state{net_if = Pid, net_if_mod = Mod}) -> ?vdebug("handle_inform -> response", []), - (catch Mod:inform_response(Pid, Ref, Domain, Address)). + (catch Mod:inform_response(Pid, Ref, Domain, Addr)). handle_snmp_report( #pdu{error_status = EStatus, error_index = EIndex, varbinds = Varbinds} = Pdu, - Domain, Address, State) -> + Domain, Addr, State) -> ?vtrace("handle_snmp_report -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" - " Pdu: ~p", [Domain, Address, Pdu]), + " Addr: ~p~n" + " Pdu: ~p", [Domain, Addr, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpReport = {EStatus, EIndex, Varbinds2}, - case snmpm_config:get_agent_user_info(Domain, Address) of + case snmpm_config:get_agent_user_info(Domain, Addr) of {ok, UserId, Target, RegType} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> @@ -2647,7 +2647,7 @@ handle_snmp_report( "~n ~p" "~n ~p", [UserId, Mod, Target, SnmpReport]), handle_report(UserId, Mod, - RegType, Target, Domain, Address, + RegType, Target, Domain, Addr, SnmpReport, Data, State); Error1 -> %% User no longer exists, unregister agent @@ -2660,7 +2660,7 @@ handle_snmp_report( case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent(DefUserId, DefMod, - Domain, Address, + Domain, Addr, report, ignore, SnmpReport, DefData, State); @@ -2668,7 +2668,7 @@ handle_snmp_report( error_msg("failed retreiving the default " "user info handling report from " "~p <~p,~p>: ~n~w~n~w", - [Target, Domain, Address, + [Target, Domain, Addr, Error2, Pdu]) end; Error3 -> @@ -2679,7 +2679,7 @@ handle_snmp_report( "user ~p, handling report: " "~n Error: ~w" "~n Report: ~w", - [Target, Domain, Address, UserId, + [Target, Domain, Addr, UserId, Error3, Pdu]) end end; @@ -2687,25 +2687,25 @@ handle_snmp_report( Error4 -> %% Unknown agent, pass it on to the default user ?vlog("[report] failed retreiving user id for agent <~p,~p>: " - "~n ~p", [Domain, Address, Error4]), + "~n ~p", [Domain, Addr, Error4]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_agent(DefUserId, DefMod, - Domain, Address, + Domain, Addr, report, ignore, SnmpReport, DefData, State); Error5 -> error_msg("failed retreiving " "the default user info handling report from " "<~p,~p>: ~n~w~n~w", - [Domain, Address, Error5, Pdu]) + [Domain, Addr, Error5, Pdu]) end end, ok; -handle_snmp_report(CrapReport, Domain, Address, _State) -> +handle_snmp_report(CrapReport, Domain, Addr, _State) -> error_msg("received crap (snmp) report from ~w:~w =>" - "~p", [Domain, Address, CrapReport]), + "~p", [Domain, Addr, CrapReport]), ok. %% This could be from a failed get-request, so we might have a user @@ -2719,14 +2719,14 @@ handle_snmp_report( error_index = EIndex, varbinds = Varbinds} = Pdu, {ReportReason, Info} = Rep, - Domain, Address, State) when is_integer(ReqId) -> + Domain, Addr, State) when is_integer(ReqId) -> ?vtrace("handle_snmp_report -> entry with~n" " Domain: ~p~n" - " Address: ~p~n" + " Addr: ~p~n" " ReqId: ~p~n" " Rep: ~p~n" - " Pdu: ~p", [Domain, Address, ReqId, Rep, Pdu]), + " Pdu: ~p", [Domain, Addr, ReqId, Rep, Pdu]), Varbinds2 = fix_vbs_BITS(Varbinds), SnmpReport = {EStatus, EIndex, Varbinds2}, @@ -2771,7 +2771,7 @@ handle_snmp_report( %% Either not a sync request or no such request. Either %% way, this is error info, so handle it as such. - case snmpm_config:get_agent_user_id(Domain, Address) of + case snmpm_config:get_agent_user_id(Domain, Addr) of {ok, UserId} -> case snmpm_config:user_info(UserId) of {ok, Mod, Data} -> @@ -2795,7 +2795,7 @@ handle_snmp_report( "default user " "info handling report from " "<~p,~p>: ~n~w~n~w~n~w", - [Domain, Address, Error, + [Domain, Addr, Error, ReqId, Reason]) end end; @@ -2803,7 +2803,7 @@ handle_snmp_report( %% Unknown agent, pass it on to the default user ?vlog("[report] failed retreiving user id for " "agent <~p,~p>: " - "~n ~p", [Domain, Address, Error]), + "~n ~p", [Domain, Addr, Error]), case snmpm_config:user_info() of {ok, DefUserId, DefMod, DefData} -> handle_error(DefUserId, DefMod, Reason, ReqId, @@ -2813,35 +2813,35 @@ handle_snmp_report( "the default user info handling " "report from " "<~p,~p>: ~n~w~n~w~n~w", - [Domain, Address, Error, ReqId, Reason]) + [Domain, Addr, Error, ReqId, Reason]) end end end, ok; -handle_snmp_report(CrapReqId, CrapReport, CrapInfo, Domain, Address, _State) -> +handle_snmp_report(CrapReqId, CrapReport, CrapInfo, Domain, Addr, _State) -> error_msg( "received crap (snmp) report from ~w:~w =>" "~n~p~n~p~n~p", - [Domain, Address, CrapReqId, CrapReport, CrapInfo]), + [Domain, Addr, CrapReqId, CrapReport, CrapInfo]), ok. -handle_report(UserId, Mod, RegType, Target, Domain, Address, +handle_report(UserId, Mod, RegType, Target, Domain, Addr, SnmpReport, Data, State) -> ?vtrace("handle_report -> entry with" "~n UserId: ~p" "~n Mod: ~p", [UserId, Mod]), F = fun() -> do_handle_report( - UserId, Mod, RegType, Target, Domain, Address, + UserId, Mod, RegType, Target, Domain, Addr, SnmpReport, Data, State) end, handle_callback(F), ok. do_handle_report( - UserId, Mod, RegType, Target, Domain, Address, + UserId, Mod, RegType, Target, Domain, Addr, SnmpReport, Data, _State) -> ?vdebug("do_handle_report -> entry with" "~n UserId: ~p", [UserId]), @@ -2851,7 +2851,7 @@ do_handle_report( {fun() -> Mod:handle_report(Target, SnmpReport, Data) end, [Target, SnmpReport, Data]}; addr_port -> - {Ip, Port} = Address, + {Ip, Port} = Addr, {fun() -> Mod:handle_report(Ip, Port, SnmpReport, Data) end, [Ip, Port, SnmpReport, Data]} end, @@ -2863,10 +2863,10 @@ do_handle_report( "~n Config: ~p", [UserId2, Config]), %% The only user which would do this is the %% default user - Target2 = mk_target_name(Domain, Address, Config), + Target2 = mk_target_name(Domain, Addr, Config), Config2 = [{reg_type, target_name}, - {tdomain, Domain}, {taddress, Address} | Config], + {tdomain, Domain}, {taddress, Addr} | Config], case snmpm_config:register_agent(UserId2, Target2, Config2) of ok -> ok; @@ -2874,7 +2874,7 @@ do_handle_report( error_msg("failed registering agent " "handling report " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), ok end; @@ -2893,20 +2893,20 @@ do_handle_report( error_msg("failed registering agent " "handling report " "~p <~p,~p>: ~n~w", - [Target2, Domain, Address, Reason]), + [Target2, Domain, Addr, Reason]), reply end; unregister -> ?vtrace("do_handle_trap -> unregister", []), - case snmpm_config:unregister_agent(UserId, Domain, Address) of + case snmpm_config:unregister_agent(UserId, Domain, Addr) of ok -> ok; {error, Reason} -> error_msg("failed unregistering agent " "handling report " "<~p,~p>: ~n~w", - [Domain, Address, Reason]), + [Domain, Addr, Reason]), ok end; @@ -3044,7 +3044,7 @@ do_gc(Key, Now) -> %% %%---------------------------------------------------------------------- -send_get_request(Oids, Vsn, MsgData, Domain, Address, ExtraInfo, +send_get_request(Oids, Vsn, MsgData, Domain, Addr, ExtraInfo, #state{net_if = NetIf, net_if_mod = Mod, mini_mib = MiniMIB}) -> @@ -3056,37 +3056,37 @@ send_get_request(Oids, Vsn, MsgData, Domain, Address, ExtraInfo, " Vsn: ~p~n" " MsgData: ~p~n" " Domain: ~p~n" - " Address: ~p~n", - [Mod, NetIf, Pdu, Vsn, MsgData, Domain, Address]), + " Addr: ~p", + [Mod, NetIf, Pdu, Vsn, MsgData, Domain, Addr]), Res = (catch Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, - Domain, Address, ExtraInfo)), + Domain, Addr, ExtraInfo)), ?vtrace("send_get_request -> send result:" "~n ~p", [Res]), Pdu#pdu.request_id. -send_get_next_request(Oids, Vsn, MsgData, Domain, Address, ExtraInfo, +send_get_next_request(Oids, Vsn, MsgData, Domain, Addr, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(get_next, Oids, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo), Pdu#pdu.request_id. -send_get_bulk_request(Oids, Vsn, MsgData, Domain, Address, +send_get_bulk_request(Oids, Vsn, MsgData, Domain, Addr, NonRep, MaxRep, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(bulk, {NonRep, MaxRep, Oids}, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo), Pdu#pdu.request_id. -send_set_request(VarsAndVals, Vsn, MsgData, Domain, Address, ExtraInfo, +send_set_request(VarsAndVals, Vsn, MsgData, Domain, Addr, ExtraInfo, #state{mini_mib = MiniMIB, net_if = NetIf, net_if_mod = Mod}) -> Pdu = make_pdu(set, VarsAndVals, MiniMIB), - Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo), + Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo), Pdu#pdu.request_id. %% send_discovery(Vsn, MsgData, Addr, Port, ExtraInfo, @@ -3322,9 +3322,9 @@ agent_data(TargetName, SendOpts) -> {Comm, SecModel} end, Domain = agent_data_item(tdomain, TargetName), - Address = agent_data_item(taddress, TargetName), + Addr = agent_data_item(taddress, TargetName), RegType = agent_data_item(reg_type, TargetName), - {ok, RegType, Domain, Address, version(Version), MsgData}; + {ok, RegType, Domain, Addr, version(Version), MsgData}; Error -> Error end. @@ -3471,8 +3471,8 @@ t() -> {A,B,C} = erlang:now(), A*1000000000+B*1000+(C div 1000). -mk_target_name(Domain, Address, Config) -> - snmpm_config:mk_target_name(Domain, Address, Config). +mk_target_name(Domain, Addr, Config) -> + snmpm_config:mk_target_name(Domain, Addr, Config). default_agent_config() -> case snmpm_config:agent_info() of diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index ea4686c91a..82cbf42e35 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -508,6 +508,8 @@ tdomain_to_family(transportDomainUdpIpv4) -> inet; tdomain_to_family(transportDomainUdpIpv6) -> inet6; +tdomain_to_family(?snmpUDPDomain) -> + inet; tdomain_to_family(?transportDomainUdpIpv4) -> inet; tdomain_to_family(?transportDomainUdpIpv6) -> diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 68d4aee97d..38e248c326 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -2107,10 +2107,19 @@ write_manager_snmp_conf(Dir, IP, Port, MMS, EngineID) -> "%% {max_message_size, 484}.\n" "%%\n\n", Hdr = header() ++ Comment, - Conf = [{port, Port}, - {address, IP}, - {engine_id, EngineID}, - {max_message_size, MMS}], + Conf = + case Port of + {Addr, P} when is_integer(P), is_atom(IP) -> + Domain = IP, + [{domain, Domain}, + {port, P}, + {address, Addr}]; + _ when is_integer(Port) -> + [{port, Port}, + {address, IP}] + end ++ + [{engine_id, EngineID}, + {max_message_size, MMS}], write_manager_config(Dir, Hdr, Conf). write_manager_config(Dir, Hdr, Conf) -> diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 3e152e6ad4..685c4dc9be 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -244,6 +244,7 @@ init_per_testcase2(Case, Config) -> Family = proplists:get_value(ipfamily, Config, inet), Conf = [{watchdog, ?WD_START(?MINS(5))}, + {ipfamily, Family}, {ip, ?LOCALHOST(Family)}, {case_top_dir, CaseTopDir}, {agent_dir, AgTopDir}, @@ -413,7 +414,8 @@ all() -> {group, event_tests_mt}, discovery, {group, tickets}, - {group, ipv6} + {group, ipv6}, + {group, ipv6_mt} ]. groups() -> @@ -549,13 +551,18 @@ groups() -> otp8395_1 ] }, - {ipv6, [], + {ipv6, [], + [ + simple_sync_get3, + inform1 + ] + }, + {ipv6_mt, [], [ simple_sync_get3, inform1 ] } - ]. @@ -567,6 +574,8 @@ init_per_group(event_tests_mt = GroupName, Config) -> snmp_test_lib:init_group_top_dir( GroupName, [{manager_net_if_module, snmpm_net_if_mt} | Config]); +init_per_group(ipv6_mt, Config) -> + init_per_group(ipv6, [{manager_net_if_module, snmpm_net_if_mt} | Config]); init_per_group(ipv6 = GroupName, Config) -> case ct:require(ipv6_hosts) of ok -> @@ -5767,12 +5776,24 @@ fin_mgr_user(Conf) -> init_mgr_user_data1(Conf) -> Node = ?config(manager_node, Conf), TargetName = ?config(manager_agent_target_name, Conf), - Addr = ?config(ip, Conf), + IpFamily = ?config(ipfamily, Conf), + Ip = ?config(ip, Conf), Port = ?AGENT_PORT, - ?line ok = mgr_user_register_agent(Node, TargetName, - [{address, Addr}, - {port, Port}, - {engine_id, "agentEngine"}]), + ?line ok = + case IpFamily of + inet -> + mgr_user_register_agent( + Node, TargetName, + [{address, Ip}, + {port, Port}, + {engine_id, "agentEngine"}]); + inet6 -> + mgr_user_register_agent( + Node, TargetName, + [{tdomain, transportDomainUdpIpv6}, + {taddress, {Ip, Port}}, + {engine_id, "agentEngine"}]) + end, _Agents = mgr_user_which_own_agents(Node), ?DBG("Own agents: ~p", [_Agents]), @@ -5797,12 +5818,24 @@ init_mgr_user_data2(Conf) -> "~n Conf: ~p", [Conf]), Node = ?config(manager_node, Conf), TargetName = ?config(manager_agent_target_name, Conf), - Addr = ?config(ip, Conf), + IpFamily = ?config(ipfamily, Conf), + Ip = ?config(ip, Conf), Port = ?AGENT_PORT, - ?line ok = mgr_user_register_agent(Node, TargetName, - [{address, Addr}, - {port, Port}, - {engine_id, "agentEngine"}]), + ?line ok = + case IpFamily of + inet -> + mgr_user_register_agent( + Node, TargetName, + [{address, Ip}, + {port, Port}, + {engine_id, "agentEngine"}]); + inet6 -> + mgr_user_register_agent( + Node, TargetName, + [{tdomain, transportDomainUdpIpv6}, + {taddress, {Ip, Port}}, + {engine_id, "agentEngine"}]) + end, _Agents = mgr_user_which_own_agents(Node), ?DBG("Own agents: ~p", [_Agents]), @@ -6199,10 +6232,16 @@ await_stopped(Node, N) -> write_manager_config(Config) -> Dir = ?config(manager_conf_dir, Config), - Ip = ?config(ip, Config), - Addr = tuple_to_list(Ip), - snmp_config:write_manager_snmp_files(Dir, Addr, ?MGR_PORT, - ?MGR_MMS, ?MGR_ENGINE_ID, [], [], []). + Ip = tuple_to_list(?config(ip, Config)), + {Addr, Port} = + case ?config(ipfamily, Config) of + inet -> + {Ip, ?MGR_PORT}; + inet6 -> + {transportDomainUdpIpv6, {Ip, ?MGR_PORT}} + end, + snmp_config:write_manager_snmp_files( + Dir, Addr, Port, ?MGR_MMS, ?MGR_ENGINE_ID, [], [], []). write_manager_conf(Dir) -> Port = "5000", @@ -6231,25 +6270,27 @@ write_manager_conf(Dir, Str) -> write_agent_config(Vsns, Conf) -> Dir = ?config(agent_conf_dir, Conf), - Ip = ?config(ip, Conf), - ?line Addr = tuple_to_list(Ip), - ?line ok = write_agent_config_files(Dir, Vsns, Addr), + ?line Ip = tuple_to_list(?config(ip, Conf)), + ?line Domain = + case ?config(ipfamily, Conf) of + inet -> + snmpUDPDomain; + inet6 -> + transportDomainUdpIpv6 + end, + ?line ok = write_agent_config_files(Dir, Vsns, Domain, Ip), ?line ok = update_agent_usm(Vsns, Dir), ?line ok = update_agent_community(Vsns, Dir), ?line ok = update_agent_vacm(Vsns, Dir), - ?line ok = write_agent_target_addr_conf(Dir, Addr, Vsns), + ?line ok = write_agent_target_addr_conf(Dir, Domain, Ip, Vsns), ?line ok = write_agent_target_params_conf(Dir, Vsns), ?line ok = write_agent_notify_conf(Dir), ok. -write_agent_config_files(Dir, Vsns, Addr) -> - snmp_config:write_agent_snmp_files(Dir, Vsns, - Addr, ?MGR_PORT, - Addr, ?AGENT_PORT, - "mgr-test", "trap", - none, "", - ?AGENT_ENGINE_ID, - ?AGENT_MMS). +write_agent_config_files(Dir, Vsns, Domain, Ip) -> + snmp_config:write_agent_snmp_files( + Dir, Vsns, Domain, {Ip, ?MGR_PORT}, {Ip, ?AGENT_PORT}, "mgr-test", + trap, none, "", ?AGENT_ENGINE_ID, ?AGENT_MMS). update_agent_usm(Vsns, Dir) -> case lists:member(v3, Vsns) of @@ -6317,9 +6358,9 @@ update_agent_vacm(_Vsns, Dir) -> excluded, null}], snmp_config:update_agent_vacm_config(Dir, Conf). -write_agent_target_addr_conf(Dir, Addr, Vsns) -> - snmp_config:write_agent_snmp_target_addr_conf(Dir, Addr, ?MGR_PORT, - 300, 3, Vsns). +write_agent_target_addr_conf(Dir, Domain, Ip, Vsns) -> + snmp_config:write_agent_snmp_target_addr_conf( + Dir, Domain, {Ip, ?MGR_PORT}, 300, 3, Vsns). write_agent_target_params_conf(Dir, Vsns) -> F = fun(v1) -> {"target_v1", v1, v1, "all-rights", noAuthNoPriv}; -- cgit v1.2.3 From 41fe52bd9540307cdb6e2e4ba06d36b11c9fd6bd Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 19 Jun 2014 16:08:28 +0200 Subject: Add testcases and do related fixes --- lib/snmp/src/agent/snmpa_net_if.erl | 8 +- lib/snmp/src/manager/snmpm_mpd.erl | 9 +- lib/snmp/src/manager/snmpm_net_if_mt.erl | 398 ++++++++++++++++++------------- lib/snmp/test/snmp_manager_test.erl | 31 ++- 4 files changed, 256 insertions(+), 190 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 71bb9cad2e..875ea19097 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -28,7 +28,6 @@ -export([system_continue/3, system_terminate/4, system_code_change/4]). -export([init/5]). -export([filter_reset/1]). --export([format_address/1]). -include("snmp_types.hrl"). -include("snmpa_internal.hrl"). @@ -1099,11 +1098,12 @@ fix_filter_address(snmpUDPDomain, {Domain, Addr}) when Domain =:= snmpUDPDomain; Domain =:= transportDomainUdpIpv4 -> Addr; +fix_filter_address(_AgentDomain, {Domain, _} = Address) + when is_atom(Domain) -> + Address; fix_filter_address(snmpUDPDomain, {_, Port} = Addr) when is_integer(Port) -> - Addr; -fix_filter_address(_AgentDomain, Address) -> - Address. + Addr. %%%----------------------------------------------------------------- diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl index 521c496adb..f8a7441c0a 100644 --- a/lib/snmp/src/manager/snmpm_mpd.erl +++ b/lib/snmp/src/manager/snmpm_mpd.erl @@ -170,7 +170,7 @@ process_v1_v2c_msg( end, Max = get_max_message_size(), - AgentMax = get_agent_max_message_size(Addr), + AgentMax = get_agent_max_message_size(Domain, Addr), PduMS = pdu_ms(Max, AgentMax, HS), ?vtrace("process_v1_v2c_msg -> PduMS: ~p", [PduMS]), @@ -862,12 +862,13 @@ get_max_message_size() -> end. %% The the MMS of the agent -get_agent_max_message_size({Addr, Port}) -> - case snmpm_config:get_agent_engine_max_message_size(Addr, Port) of +get_agent_max_message_size(Domain, Addr) -> + case snmpm_config:get_agent_engine_max_message_size(Domain, Addr) of {ok, MMS} -> MMS; _Error -> - ?vlog("unknown agent: ~w:~w", [Addr, Port]), + ?vlog("unknown agent: ~s", + [snmp_conf:mk_addr_string({Domain, Addr})]), get_max_message_size() end. %% get_agent_max_message_size(Addr, Port) -> diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 8dd3ef0111..2937f5cc87 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -55,13 +55,14 @@ %% -define(VMODULE,"NET_IF"). -include("snmp_verbosity.hrl"). --record(state, +-record(state, { server, note_store, - sock, + domain, + sock, mpd_state, - log, + log, irb = auto, % auto | {user, integer()} irgc, filter @@ -99,22 +100,22 @@ start_link(Server, NoteStore) -> stop(Pid) -> call(Pid, stop). -send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort) -> - send_pdu(Pid, Pdu, Vsn, MsgData, DomainIp, AddrPort, ?DEFAULT_EXTRA_INFO). +send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port) -> + send_pdu( + Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port, ?DEFAULT_EXTRA_INFO). -send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo) - when is_record(Pdu, pdu), is_atom(Domain) -> +send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port, ExtraInfo) + when is_record(Pdu, pdu) -> ?d("send_pdu -> entry with~n" - " Pid: ~p~n" - " Pdu: ~p~n" - " Vsn: ~p~n" - " MsgData: ~p~n" - " Domain: ~p~n" - " Address: ~p", [Pid, Pdu, Vsn, MsgData, Domain, Address]), - cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}); -send_pdu(Pid, Pdu, Vsn, MsgData, Ip, Port, ExtraInfo) -> - Domain = snmpm_config:default_transport_domain(), - send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo). + " Pid: ~p~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain/IP: ~p~n" + " Addr/Port : ~p", + [Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port]), + {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), + cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}). send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). @@ -122,8 +123,9 @@ send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> note_store(Pid, NoteStore) -> call(Pid, {note_store, NoteStore}). -inform_response(Pid, Ref, Domain, Address) -> - cast(Pid, {inform_response, Ref, Domain, Address}). +inform_response(Pid, Ref, Domain_or_Ip, Addr_or_Port) -> + {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), + cast(Pid, {inform_response, Ref, Domain, Addr}). info(Pid) -> call(Pid, info). @@ -203,7 +205,14 @@ do_init(Server, NoteStore) -> BindTo = get_opt(Opts, bind_to, false), NoReuse = get_opt(Opts, no_reuse, false), {ok, Port} = snmpm_config:system_info(port), - {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, BindTo, NoReuse), + Domain = + case snmpm_config:system_info(domain) of + {ok, D} -> + D; + _ -> + snmpm_config:default_transport_domain() + end, + {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), %% Flow control -- FilterOpts = get_opt(Opts, filter, []), @@ -219,10 +228,11 @@ do_init(Server, NoteStore) -> init_counters(), %% -- We are done --- - State = #state{server = Server, - note_store = NoteStore, + State = #state{server = Server, + note_store = NoteStore, mpd_state = MpdState, - sock = Sock, + domain = Domain, + sock = Sock, log = Log, irb = IRB, irgc = IrGcRef, @@ -232,19 +242,24 @@ do_init(Server, NoteStore) -> %% Open port -do_open_port(Port, SendSz, RecvSz, BindTo, NoReuse) -> - ?vtrace("do_open_port -> entry with" - "~n Port: ~p" - "~n SendSz: ~p" - "~n RecvSz: ~p" - "~n BindTo: ~p" - "~n NoReuse: ~p", [Port, SendSz, RecvSz, BindTo, NoReuse]), +do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> + ?vtrace("do_open_port -> entry with~n" + " Port: ~p~n" + " SendSz: ~p~n" + " RecvSz: ~p~n" + " Domain: ~p~n" + " BindTo: ~p~n" + " NoReuse: ~p", + [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), IpOpts1 = bind_to(BindTo), IpOpts2 = no_reuse(NoReuse), IpOpts3 = recbuf(RecvSz), IpOpts4 = sndbuf(SendSz), - IpOpts = [binary | IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], - OpenRes = + IpOpts = + [binary, + snmp_conf:tdomain_to_family(Domain) | + IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], + OpenRes = case init:get_argument(snmpm_fd) of {ok, [[FdStr]]} -> Fd = list_to_integer(FdStr), @@ -397,24 +412,24 @@ handle_call(Req, From, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Address, ExtraInfo}, +handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}, State) -> ?vlog("received send_pdu message with~n" " Pdu: ~p~n" " Vsn: ~p~n" " MsgData: ~p~n" " Domain: ~p~n" - " Address: ~p", [Pdu, Vsn, MsgData, Domain, Address]), - maybe_process_extra_info(ExtraInfo), - handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State), + " Addr: ~p", [Pdu, Vsn, MsgData, Domain, Addr]), + maybe_process_extra_info(ExtraInfo), + handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State), {noreply, State}; -handle_cast({inform_response, Ref, Domain, Address}, State) -> +handle_cast({inform_response, Ref, Domain, Addr}, State) -> ?vlog("received inform_response message with~n" " Ref: ~p~n" " Domain: ~p~n" - " Address: ~p", [Ref, Domain, Address]), - handle_inform_response(Ref, Domain, Address, State), + " Addr: ~p", [Ref, Domain, Addr]), + handle_inform_response(Ref, Domain, Addr, State), {noreply, State}; handle_cast(filter_reset, State) -> @@ -433,9 +448,10 @@ handle_cast(Msg, State) -> %% {noreply, State, Timeout} | %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- -handle_info({udp, Sock, Ip, Port, Bytes}, #state{sock = Sock} = State) -> +handle_info( + {udp, Sock, Ip, Port, Bytes}, + #state{sock = Sock, domain = Domain} = State) -> ?vlog("received ~w bytes from ~p:~p", [size(Bytes), Ip, Port]), - Domain = snmpm_config:default_transport_domain(), handle_udp(Domain, {Ip, Port}, Bytes, State), {noreply, State}; @@ -501,62 +517,64 @@ code_change(_Vsn, State, _Extra) -> %%% Internal functions %%%------------------------------------------------------------------- -handle_udp(Domain, Address, Bytes, State) -> - Verbosity = get(verbosity), - spawn_opt(fun() -> - Log = worker_init(State, Verbosity), - Res = - (catch maybe_handle_recv_msg( - Domain, Address, Bytes, - State#state{log = Log})), - worker_exit(udp, {Domain, Address}, Res) - end, - [monitor]). - +handle_udp(Domain, Addr, Bytes, State) -> + Verbosity = get(verbosity), + spawn_opt( + fun() -> + Log = worker_init(State, Verbosity), + Res = + (catch maybe_handle_recv_msg( + Domain, Addr, Bytes, + State#state{log = Log})), + worker_exit(udp, {Domain, Addr}, Res) + end, + [monitor]). + maybe_handle_recv_msg( - Domain, Address, Bytes, #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv(Domain, Address)) of + Domain, Addr, Bytes, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv(Arg1, Arg2)) of false -> - %% Drop the received packet + %% Drop the received packet inc(netIfMsgInDrops), ok; _ -> - handle_recv_msg(Domain, Address, Bytes, State) + handle_recv_msg(Domain, Addr, Bytes, State) end. -handle_recv_msg(Domain, Address, Bytes, #state{server = Pid}) +handle_recv_msg(Domain, Addr, Bytes, #state{server = Pid}) when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> - Pid ! {snmp_error, {empty_message, Domain, Address}, Domain, Address}, + Pid ! {snmp_error, {empty_message, Domain, Addr}, Domain, Addr}, ok; handle_recv_msg( - Domain, Address, Bytes, + Domain, Addr, Bytes, #state{server = Pid, note_store = NoteStore, mpd_state = MpdState, - sock = Sock, log = Log} = State) -> - Logger = logger(Log, read, Domain, Address), - case (catch snmpm_mpd:process_msg(Bytes, Domain, Address, + Logger = logger(Log, read, Domain, Addr), + case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, MpdState, NoteStore, Logger)) of {ok, Vsn, Pdu, MS, ACM} -> - maybe_handle_recv_pdu(Domain, Address, Vsn, Pdu, MS, ACM, + maybe_handle_recv_pdu(Domain, Addr, Vsn, Pdu, MS, ACM, Logger, State); {discarded, Reason, Report} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Address}, - maybe_udp_send(State#state.filter, Sock, Domain, Address, Report), + Pid ! {snmp_error, ErrorInfo, Domain, Addr}, + maybe_udp_send(Domain, Addr, Report, State), ok; {discarded, Reason} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Address}, + Pid ! {snmp_error, ErrorInfo, Domain, Addr}, ok; Error -> @@ -567,97 +585,99 @@ handle_recv_msg( maybe_handle_recv_pdu( - Domain, Address, Vsn, - #pdu{type = Type} = Pdu, PduMS, ACM, Logger, - #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_recv_pdu(Domain, Address, Type)) of + Domain, Addr, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, Type)) of false -> inc(netIfPduInDrops), ok; _ -> handle_recv_pdu( - Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) + Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) end; maybe_handle_recv_pdu( - Domain, Address, Vsn, Trap, PduMS, ACM, Logger, - #state{filter = FilterMod} = State) + Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, + #state{filter = FilterMod, domain = ManagerDomain} = State) when is_record(Trap, trappdu) -> - case (catch FilterMod:accept_recv_pdu(Domain, Address, trappdu)) of + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, trappdu)) of false -> inc(netIfPduInDrops), ok; _ -> handle_recv_pdu( - Domain, Address, Vsn, Trap, PduMS, ACM, Logger, State) + Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, State) end; maybe_handle_recv_pdu( - Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State) -> - handle_recv_pdu(Domain, Address, Vsn, Pdu, PduMS, ACM, Logger, State). + Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) -> + handle_recv_pdu(Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State). handle_recv_pdu( - Domain, Address, Vsn, + Domain, Addr, Vsn, #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, Logger, #state{server = Pid, irb = IRB} = State) -> handle_inform_request( - IRB, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State); + IRB, Pid, Vsn, Pdu, ACM, Domain, Addr, Logger, State); handle_recv_pdu( - Domain, Address, _Vsn, + Domain, Addr, _Vsn, #pdu{type = report} = Pdu, _PduMS, ok, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - ok", []), - Pid ! {snmp_report, {ok, Pdu}, Domain, Address}, + Pid ! {snmp_report, {ok, Pdu}, Domain, Addr}, ok; -handle_recv_pdu(Domain, Address, - _Vsn, #pdu{type = report} = Pdu, _PduMS, - {error, ReqId, Reason}, - _Logger, - #state{server = Pid} = _State) -> +handle_recv_pdu( + Domain, Addr, _Vsn, + #pdu{type = report} = Pdu, _PduMS, {error, ReqId, Reason}, _Logger, + #state{server = Pid} = _State) -> ?vtrace("received report - error", []), - Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Address}, + Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Addr}, ok; handle_recv_pdu( - Domain, Address, _Vsn, + Domain, Addr, _Vsn, #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) -> ?vtrace("received snmpv2-trap", []), - Pid ! {snmp_trap, Pdu, Domain, Address}, + Pid ! {snmp_trap, Pdu, Domain, Addr}, ok; handle_recv_pdu( - Domain, Address, _Vsn, Trap, _PduMS, _ACM, _Logger, + Domain, Addr, _Vsn, Trap, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Trap, trappdu) -> ?vtrace("received trappdu", []), - Pid ! {snmp_trap, Trap, Domain, Address}, + Pid ! {snmp_trap, Trap, Domain, Addr}, ok; handle_recv_pdu( - Domain, Address, _Vsn, Pdu, _PduMS, _ACM, _Logger, + Domain, Addr, _Vsn, Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Pdu, pdu) -> ?vtrace("received pdu", []), - Pid ! {snmp_pdu, Pdu, Domain, Address}, + Pid ! {snmp_pdu, Pdu, Domain, Addr}, ok; handle_recv_pdu( - _Domain, _Address, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> + _Domain, _Addr, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> ?vlog("received unexpected pdu: " "~n Pdu: ~p" "~n ACM: ~p", [Pdu, ACM]), ok. -handle_inform_request(auto, Pid, Vsn, Pdu, ACM, Domain, Address, Logger, State) -> +handle_inform_request( + auto, Pid, Vsn, Pdu, ACM, Domain, Addr, Logger, State) -> ?vtrace("received inform-request (true)", []), - Pid ! {snmp_inform, ignore, Pdu, Domain, Address}, + Pid ! {snmp_inform, ignore, Pdu, Domain, Addr}, RePdu = make_response_pdu(Pdu), - maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, State); -handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, - ACM, Domain, Address, _Logger, _State) -> + maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Addr, Logger, State); +handle_inform_request( + {user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, + ACM, Domain, Addr, _Logger, _State) -> ?vtrace("received inform-request (false)", []), - Pid ! {snmp_inform, ReqId, Pdu, Domain, Address}, + Pid ! {snmp_inform, ReqId, Pdu, Domain, Addr}, %% Before we go any further, we need to check that we have not %% already received this message (possible resend). - Key = {ReqId, Domain, Address}, + Key = {ReqId, Domain, Addr}, case ets:lookup(snmpm_inform_request_table, Key) of [_] -> %% OK, we already know about this. We assume this @@ -671,41 +691,43 @@ handle_inform_request({user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, ets:insert(snmpm_inform_request_table, Rec) end, ok. - -handle_inform_response(Ref, Domain, Address, State) -> - Verbosity = get(verbosity), - spawn_opt(fun() -> - Log = worker_init(State, Verbosity), - Res = (catch do_handle_inform_response( - Ref, - Domain, Address, - State#state{log = Log})), - worker_exit(inform_response, {Domain, Address}, Res) - end, - [monitor]). - +handle_inform_response(Ref, Domain, Addr, State) -> + Verbosity = get(verbosity), + spawn_opt( + fun() -> + Log = worker_init(State, Verbosity), + Res = (catch do_handle_inform_response( + Ref, Domain, Addr, State#state{log = Log})), + worker_exit(inform_response, {Domain, Addr}, Res) + end, + [monitor]). -do_handle_inform_response(Ref, Domain, Address, State) -> - Key = {Ref, Domain, Address}, + + +do_handle_inform_response(Ref, Domain, Addr, State) -> + Key = {Ref, Domain, Addr}, case ets:lookup(snmpm_inform_request_table, Key) of [{Key, _, {Vsn, ACM, RePdu}}] -> - Logger = logger(State#state.log, read, Domain, Address), + Logger = logger(State#state.log, read, Domain, Addr), ets:delete(snmpm_inform_request_table, Key), - maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, - Logger, State); + maybe_send_inform_response( + RePdu, Vsn, ACM, Domain, Addr, Logger, State); [] -> %% Already acknowledged, or the user was to slow to reply... ok end, ok. -maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, - #state{server = Pid, - sock = Sock, - filter = FilterMod}) -> +maybe_send_inform_response( + RePdu, Vsn, ACM, Domain, Addr, Logger, + #state{server = Pid, + sock = Sock, + domain = ManagerDomain, + filter = FilterMod}) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), case (catch FilterMod:accept_send_pdu( - Domain, Address, pdu_type_of(RePdu))) + Arg1, Arg2, pdu_type_of(RePdu))) of false -> inc(netIfPduOutDrops), @@ -713,13 +735,14 @@ maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Address, Logger, _ -> case snmpm_mpd:generate_response_msg(Vsn, RePdu, ACM, Logger) of {ok, Msg} -> - maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); + maybe_udp_send( + Domain, Addr, Msg, Sock, FilterMod, ManagerDomain); {discarded, Reason} -> ?vlog("failed generating response message:" "~n Reason: ~p", [Reason]), ReqId = RePdu#pdu.request_id, ErrorInfo = {failed_generating_response, {RePdu, Reason}}, - Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Address}, + Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Addr}, ok end end. @@ -754,40 +777,42 @@ irgc_stop(Ref) -> (catch erlang:cancel_timer(Ref)). -handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State) -> - Verbosity = get(verbosity), - spawn_opt(fun() -> - Log = worker_init(State, Verbosity), - Res = (catch maybe_handle_send_pdu( - Pdu, Vsn, MsgData, - Domain, Address, - State#state{log = Log})), - worker_exit(send_pdu, {Domain, Address}, Res) - end, - [monitor]). - -maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, - #state{filter = FilterMod} = State) -> - case (catch FilterMod:accept_send_pdu(Domain, Address, pdu_type_of(Pdu))) of +handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) -> + Verbosity = get(verbosity), + spawn_opt( + fun() -> + Log = worker_init(State, Verbosity), + Res = (catch maybe_handle_send_pdu( + Pdu, Vsn, MsgData, + Domain, Addr, + State#state{log = Log})), + worker_exit(send_pdu, {Domain, Addr}, Res) + end, + [monitor]). + +maybe_handle_send_pdu( + Pdu, Vsn, MsgData, Domain, Addr, + #state{filter = FilterMod, domain = ManagerDomain} = State) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_send_pdu(Arg1, Arg2, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), ok; _ -> - do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, State) + do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) end. -do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, - #state{server = Pid, - note_store = NoteStore, - sock = Sock, - log = Log, - filter = FilterMod}) -> - Logger = logger(Log, write, Domain, Address), - case (catch snmpm_mpd:generate_msg(Vsn, NoteStore, - Pdu, MsgData, Logger)) of +do_handle_send_pdu( + Pdu, Vsn, MsgData, Domain, Addr, + #state{server = Pid, + note_store = NoteStore, + log = Log} = State) -> + Logger = logger(Log, write, Domain, Addr), + case (catch snmpm_mpd:generate_msg( + Vsn, NoteStore, Pdu, MsgData, Logger)) of {ok, Msg} -> ?vtrace("do_handle_send_pdu -> message generated", []), - maybe_udp_send(FilterMod, Sock, Domain, Address, Msg); + maybe_udp_send(Domain, Addr, Msg, State); {discarded, Reason} -> ?vlog("PDU not sent: " "~n PDU: ~p" @@ -796,13 +821,21 @@ do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Address, ok end. +maybe_udp_send( + Domain, Addr, Msg, + #state{sock = Sock, filter = FilterMod, domain = ManagerDomain}) -> + maybe_udp_send(Domain, Addr, Msg, Sock, FilterMod, ManagerDomain). -maybe_udp_send(FilterMod, Sock, Domain, {Ip, Port} = Address, Msg) -> - case (catch FilterMod:accept_send(Domain, Address)) of +maybe_udp_send(Domain, Addr, Msg, Sock, FilterMod, ManagerDomain) -> + {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + case (catch FilterMod:accept_send(Arg1, Arg2)) of false -> inc(netIfMsgOutDrops), ok; _ -> + %% XXX There should be some kind of lookup of socket + %% from transport domain here + {Ip, Port} = Addr, udp_send(Sock, Ip, Port, Msg) end. @@ -1045,25 +1078,48 @@ worker_exit(Tag, Info, Result) -> handle_worker_exit(_, {_, _, ok}) -> ok; -handle_worker_exit(Pid, {udp, {Domain, Address}, ExitStatus}) -> - warning_msg("Worker process (~p) terminated " - "while processing (incomming) message from ~w:~w: " - "~n~p", [Pid, Domain, Address, ExitStatus]), +handle_worker_exit(Pid, {udp, {Domain, Addr}, ExitStatus}) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (incomming) message from %s:~n" + "~p", [Pid, snmp_conf:mk_addr_string({Domain, Addr}), ExitStatus]), ok; -handle_worker_exit(Pid, {send_pdu, {Domain, Address}, ExitStatus}) -> - warning_msg("Worker process (~p) terminated " - "while processing (outgoing) pdu for [~w] ~w: " - "~n~p", [Pid, Domain, Address, ExitStatus]), +handle_worker_exit(Pid, {send_pdu, {Domain, Addr}, ExitStatus}) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (outgoing) pdu for %s:~n" + "~p", [Pid, snmp_conf:mk_addr_string({Domain, Addr}), ExitStatus]), ok; -handle_worker_exit(Pid, {inform_response, {Domain, Address}, ExitStatus}) -> - warning_msg("Worker process (~p) terminated " - "while processing (outgoing) inform response for ~w:~w: " - "~n~p", [Pid, Domain, Address, ExitStatus]), +handle_worker_exit(Pid, {inform_response, {Domain, Addr}, ExitStatus}) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (outgoing) inform response for %s:~n" + "~p", [Pid, snmp_conf:mk_addr_string({Domain, Addr}), ExitStatus]), ok; handle_worker_exit(_, _) -> ok. +%% If the manager uses legacy snmpUDPDomain e.g has not set +%% {domain, _}, then make sure snmpm_network_interface_filter +%% gets legacy arguments to not break backwards compatibility. +%% +fix_filter_address(snmpUDPDomain, {Domain, Addr}) + when Domain =:= snmpUDPDomain; + Domain =:= transportDomainUdpIpv4 -> + Addr; +fix_filter_address(_ManagerDomain, {Domain, _} = Address) + when is_atom(Domain) -> + Address; +fix_filter_address(snmpUDPDomain, {_, Port} = Addr) + when is_integer(Port) -> + Addr. + +address(Domain, Addr) when is_atom(Domain) -> + {Domain, Addr}; +address(Ip, Port) when is_integer(Port) -> + {snmpm_config:default_transport_domain(), {Ip, Port}}. + %% ------------------------------------------------------------------- make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> @@ -1104,15 +1160,17 @@ t() -> %% ------------------------------------------------------------------- -logger(undefined, _Type, _Domain, _Address) -> +logger(undefined, _Type, _Domain, _Addr) -> fun(_) -> ok end; -logger({_Name, Log, Types}, Type, Domain, Address) -> +logger({_Name, Log, Types}, Type, Domain, Addr) -> case lists:member(Type, Types) of true -> + AddrString = + iolist_to_binary(snmp_conf:mk_addr_string({Domain, Addr})), fun(Msg) -> - snmp_log:log(Log, Msg, Domain, Address) + snmp_log:log(Log, Msg, Domain, AddrString) end; false -> fun(_) -> diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 685c4dc9be..75560f8958 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -551,21 +551,28 @@ groups() -> otp8395_1 ] }, - {ipv6, [], - [ - simple_sync_get3, - inform1 - ] - }, - {ipv6_mt, [], - [ - simple_sync_get3, - inform1 - ] - } + {ipv6, [], ipv6_tests()}, + {ipv6_mt, [], ipv6_tests()} ]. +ipv6_tests() -> + [ + register_agent1, + simple_sync_get_next3, + simple_async_get2, + simple_sync_get3, + simple_async_get_next2, + simple_sync_set3, + simple_async_set2, + simple_sync_get_bulk2, + simple_async_get_bulk3, + misc_async2, + inform1, + inform_swarm + ]. + + init_per_group(request_tests_mt = GroupName, Config) -> snmp_test_lib:init_group_top_dir( GroupName, -- cgit v1.2.3 From 666559111508b65ab1379476b0d8c76c15e5700e Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 24 Jun 2014 15:54:48 +0200 Subject: Mend regression tests --- lib/snmp/test/snmp_agent_test.erl | 23 +++++++++++++++++------ lib/snmp/test/snmp_manager_config_test.erl | 5 +++-- lib/snmp/test/snmp_manager_test.erl | 12 ++++++++++-- 3 files changed, 30 insertions(+), 10 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 608a99062d..c13b64e8da 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -1725,7 +1725,7 @@ init_v1(Config) when is_list(Config) -> ?line AgentConfDir = ?config(agent_conf_dir, Config), ?line MgrDir = ?config(mgr_dir, Config), ?line Ip = ?config(ip, Config), - ?line IpFamily = ?config(ipfamily, Config), + ?line IpFamily = config_ipfamily(Config), ?line config( [v1], MgrDir, AgentConfDir, tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), @@ -1798,7 +1798,7 @@ init_v2(Config) when is_list(Config) -> AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - IpFamily = ?config(ipfamily, Config), + IpFamily = config_ipfamily(Config), config( [v2], MgrDir, AgentConfDir, tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), @@ -1820,7 +1820,7 @@ init_v1_v2(Config) when is_list(Config) -> AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - IpFamily = ?config(ipfamily, Config), + IpFamily = config_ipfamily(Config), config([v1,v2], MgrDir, AgentConfDir, tuple_to_list(Ip), tuple_to_list(Ip), IpFamily), [{vsn, bilingual} | start_bilingual_agent(Config)]. @@ -1909,7 +1909,7 @@ init_v3(Config) when is_list(Config) -> AgentConfDir = ?config(agent_conf_dir, Config), MgrDir = ?config(mgr_dir, Config), Ip = ?config(ip, Config), - IpFamily = ?config(ipfamily, Config), + IpFamily = config_ipfamily(Config), ?line ok = config( [v3], MgrDir, AgentConfDir, @@ -7430,7 +7430,8 @@ init_v1_agent(Config) -> ManagerHost = ?HOSTNAME(ManagerNode), Host = snmp_test_lib:hostname(), - IpFamily = ?LOCALHOST(?config(ipfamily, Config)), + IpFamily = config_ipfamily(Config), + Ip = ?LOCALHOST(IpFamily), {ok, AgentIP0} = snmp_misc:ip(AgentHost, IpFamily), AgentIP = tuple_to_list(AgentIP0), {ok, ManagerIP0} = snmp_misc:ip(ManagerHost, IpFamily), @@ -7458,7 +7459,7 @@ init_v1_agent(Config) -> %% Config2 = start_agent([{host, Host}, - {ip, IpFamily}, + {ip, Ip}, {agent_node, AgentNode}, {agent_host, AgentHost}, {agent_ip, AgentIP}, @@ -7508,3 +7509,13 @@ fin_v1_agent(Config) -> Dog = ?config(watchdog, Config), ?WD_STOP(Dog), lists:keydelete(watchdog, 1, Config). + + + +config_ipfamily(Config) -> + case ?config(ipfamily, Config) of + undefined -> + inet; + Value -> + Value + end. diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index 3cdb2cfcbe..2f5c68d14d 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -720,7 +720,8 @@ start_with_invalid_manager_conf_file1(Conf) when is_list(Conf) -> "[134,138,177,189]", "-1", "500", "\"bmkEngine\""), ?line {error, Reason22} = config_start(Opts), p("start failed (as expected): ~p", [Reason22]), - ?line {failed_check, _, _, 3, {invalid_integer, _}} = Reason22, + io:format("Reason22: ~p~n", [Reason22]), + ?line {failed_check, _, _, 3, {bad_port, _}} = Reason22, await_config_not_running(), %% -- @@ -729,7 +730,7 @@ start_with_invalid_manager_conf_file1(Conf) when is_list(Conf) -> "[134,138,177,189]", "\"kalle-anka\"", "500", "\"bmkEngine\""), ?line {error, Reason23} = config_start(Opts), p("start failed (as expected): ~p", [Reason23]), - ?line {failed_check, _, _, 3, {invalid_integer, _}} = Reason23, + ?line {failed_check, _, _, 3, {bad_port, _}} = Reason23, await_config_not_running(), %% -- diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 75560f8958..78352e59cf 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -581,8 +581,16 @@ init_per_group(event_tests_mt = GroupName, Config) -> snmp_test_lib:init_group_top_dir( GroupName, [{manager_net_if_module, snmpm_net_if_mt} | Config]); -init_per_group(ipv6_mt, Config) -> - init_per_group(ipv6, [{manager_net_if_module, snmpm_net_if_mt} | Config]); +init_per_group(ipv6_mt = GroupName, Config) -> + case ct:require(ipv6_hosts) of + ok -> + ipv6_init( + snmp_test_lib:init_group_top_dir( + GroupName, + [{manager_net_if_module, snmpm_net_if_mt} | Config])); + _ -> + {skip, "Host does not support IPV6"} + end; init_per_group(ipv6 = GroupName, Config) -> case ct:require(ipv6_hosts) of ok -> -- cgit v1.2.3 From f9a9d8e0dff57317e097dca852155de1c7c09142 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 24 Jun 2014 17:48:03 +0200 Subject: Mend loop_mib_* testcases --- lib/snmp/test/snmp_agent_test.erl | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index c13b64e8da..b181bf957d 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -37,7 +37,7 @@ v1_processing/1, big/1, big2/1, - loop_mib_1/1, + loop_mib_1/1, api/1, subagent/1, mnesia/1, @@ -389,9 +389,9 @@ usm_read/0, usm_del_user/0, usm_bad/0, - loop_mib_1_test/0, - loop_mib_2_test/0, - loop_mib_3_test/0, + loop_mib_1_test/0, + loop_mib_2_test/0, + loop_mib_3_test/0, otp_1129_i/1, otp_1162_test/0, otp_1131_test/0, @@ -898,8 +898,8 @@ start_v2_agent(Config) -> start_v2_agent(Config, Opts) -> snmp_agent_test_lib:start_v2_agent(Config, Opts). -start_v3_agent(Config) -> - snmp_agent_test_lib:start_v3_agent(Config). +%% start_v3_agent(Config) -> +%% snmp_agent_test_lib:start_v3_agent(Config). start_v3_agent(Config, Opts) -> snmp_agent_test_lib:start_v3_agent(Config, Opts). @@ -1669,7 +1669,7 @@ del_dir(Dir, Depth) -> ok end. -%v1_cases() -> [loop_mib]; +%v1_cases() -> [loop_mib_1]; v1_cases() -> [ simple, @@ -1677,7 +1677,7 @@ v1_cases() -> v1_processing, big, big2, - loop_mib_1, + loop_mib_1, api, subagent, mnesia, @@ -1699,7 +1699,7 @@ v1_cases_ipv6() -> [ simple, v1_processing, - loop_mib, + loop_mib_1, %% big, %% big2, api, @@ -5670,7 +5670,7 @@ usm_bad() -> %%----------------------------------------------------------------- loop_mib_1(suite) -> []; loop_mib_1(Config) when is_list(Config) -> - ?P(loop_mib_1), + ?P(loop_mib_1), ?LOG("loop_mib_1 -> initiate case",[]), %% snmpa:verbosity(master_agent,debug), %% snmpa:verbosity(mib_server,info), @@ -5678,7 +5678,7 @@ loop_mib_1(Config) when is_list(Config) -> ?DBG("loop_mib_1 -> ~n" "\tSaNode: ~p~n" "\tMgrNode: ~p~n" - "\tMibDir: ~p", [_SaNode, _MgrNode, _MibDir]), + "\tMibDir: ~p",[_SaNode, _MgrNode, _MibDir]), ?DBG("loop_mib_1 -> load mib SNMP-COMMUNITY-MIB",[]), ?line load_master_std("SNMP-COMMUNITY-MIB"), ?DBG("loop_mib_1 -> load mib SNMP-MPD-MIB",[]), @@ -6502,10 +6502,6 @@ otp_4394_config(AgentConfDir, MgrDir, Ip0) -> ?line write_notify_conf(AgentConfDir), ok. -ipv6_init(Config) when is_list(Config) -> - Opts = [], - [{vsn, v1} | start_v1_agent(Config, Opts)]. - otp_4394_finish(Config) when is_list(Config) -> ?DBG("finish_otp_4394 -> entry", []), C1 = stop_agent(Config), -- cgit v1.2.3 From c7d97f4d7a27bd6aca3b6335c90e6a51e28e6719 Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Wed, 25 Jun 2014 08:55:53 +0200 Subject: snmp: Add new test suite --- lib/snmp/test/Makefile | 4 +- lib/snmp/test/modules.mk | 1 + lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 235 ++++++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 lib/snmp/test/snmp_to_snmpnet_SUITE.erl (limited to 'lib/snmp') diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index 7bc9dd07d4..d2eca0b250 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2012. All Rights Reserved. +# Copyright Ericsson AB 1997-2014. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -36,7 +36,7 @@ VSN = $(SNMP_VSN) include modules.mk SNMP_ROOT = .. -SNMP_SUITE = snmp_SUITE +SNMP_SUITE = snmp_SUITE ERL_FILES = $(MODULES:%=%.erl) diff --git a/lib/snmp/test/modules.mk b/lib/snmp/test/modules.mk index fd8315ec4d..1bf08a9729 100644 --- a/lib/snmp/test/modules.mk +++ b/lib/snmp/test/modules.mk @@ -19,6 +19,7 @@ SUITE_MODULES = \ snmp_SUITE \ + snmp_to_snmpnet_SUITE \ snmp_app_test \ snmp_appup_test \ snmp_compiler_test \ diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl new file mode 100644 index 0000000000..4584ad75c2 --- /dev/null +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -0,0 +1,235 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2014-2014. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%% + +-module(snmp_to_snmpnet_SUITE). + +%% Note: This directive should only be used in test suites. +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("snmp/include/STANDARD-MIB.hrl"). + +-define(AGENT_ENGIN_ID, "ErlangSnmpAgent"). +-define(AGENT_PORT, 4000). +-define(DEFAULT_MAX_MESSAGE_SIZE, 484). +-define(SYS_DESC, "iso.3.6.1.2.1.1.1.0 = STRING: \"Erlang SNMP agent\"\n"). + +%%-------------------------------------------------------------------- +%% Common Test interface functions ----------------------------------- +%%-------------------------------------------------------------------- + +suite() -> [{ct_hooks,[ts_install_cth]}]. + +all() -> + [ + {group, ipv4}, + {group, ipv6} + ]. + +groups() -> + [{ipv4, [], ipv4_tests()}, + {ipv6, [], ipv6_tests()}, + {get, [], get_tests()}, + %%{trap, [], trap_tests()}, + {dual_ip, [], dual_ip_tests()}]. + +get_tests() -> + [erlang_agent_netsnmp_get]. +trap_tests() -> + [erlang_agent_netsnmp_trap]. +dual_ip_tests() -> + [erlang_agent_dual_ip_get]. +ipv4_tests() -> + [{group, get}]. +ipv6_tests() -> + [{group, get}, + {group, dual_ip} + ]. + +init_per_suite(Config) -> + case os:find_executable("snmpget") of + false -> + {skip, "snmpget not found"}; + _ -> + Config + end. + +end_per_suite(_Config) -> + ok. + +init_per_group(ipv6, Config) -> + case ct:require(ipv6_hosts) of + ok -> + Dir = ?config(priv_dir, Config), + Domain = transportDomainUdpIpv6, + {ok, Host} = inet:gethostname(), + {ok, IpAddr} = inet:getaddr(Host, inet6), + Versions = [v2], + agent_config(Dir, Domain, IpAddr, IpAddr, ?AGENT_PORT, Versions), + [{host, Host}, {port, ?AGENT_PORT}, + {snmp_versions, Versions}, {ip_version, ipv6} | Config]; + _ -> + {skip, "Host does not support IPV6"} + end; + +init_per_group(ipv4, Config) -> + Dir = ?config(priv_dir, Config), + Domain = transportDomainUdpIpv4, + {ok, Host} = inet:gethostname(), + {ok, IpAddr} = inet:getaddr(Host, inet), + Versions = [v2], + agent_config(Dir, Domain, IpAddr, IpAddr, ?AGENT_PORT, Versions), + [{host, Host}, {port, ?AGENT_PORT}, {snmp_versions, Versions}, + {ip_version, ipv4} | Config]; + +init_per_group(get, Config) -> + case os:find_executable("snmpget") of + false -> + {skip, "snmpget not found"}; + _ -> + Config + end; + +init_per_group(trap, Config) -> + case os:find_executable("snmptrapd") of + false -> + {skip, "snmptrapd not found"}; + _ -> + Config + end; +init_per_group(_, Config) -> + Config. + +end_per_group(_GroupName, Config) -> + Config. + +init_per_testcase(Case, Config) -> + end_per_testcase(Case, Config), + application:start(snmp), + application:load(snmp), + application:set_env(snmp, agent, app_env(Case, Config)), + snmp:start_agent(normal), + Config. + +end_per_testcase(_, Config) -> + application:stop(snmp), + Config. + +%%-------------------------------------------------------------------- +%% Test Cases -------------------------------------------------------- +%%-------------------------------------------------------------------- +erlang_agent_netsnmp_get() -> + [{doc,"Test that we can access erlang snmp agent " + "from snmpnet manager"}]. + +erlang_agent_netsnmp_get(Config) when is_list(Config) -> + Host = ?config(host, Config), + Port = ?config(port, Config), + IPVersion = ?config(ip_version, Config), + Versions = ?config(snmp_versions, Config), + + Cmd = "snmpget -c public " ++ net_snmp_version(Versions) ++ " " ++ + net_snmp_ip_version(IPVersion) ++ + Host ++ ":" ++ integer_to_list(Port) ++ + " " ++ oid_str(?sysDescr_instance), + net_snmp(Cmd, ?SYS_DESC). + +%%-------------------------------------------------------------------- +erlang_agent_dual_ip_get() -> + [{doc,"Test that we can access erlang snmp agent from both " + "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. +erlang_agent_dual_ip_get(Config) when is_list(Config) -> + erlang_agent_netsnmp_get([{ip_version, ipv4}]), + erlang_agent_netsnmp_get([{ip_version, ipv6}]). +%%-------------------------------------------------------------------- +erlang_agent_netsnmp_trap() -> + %% Host = ?config(host, Config), + %% Port = ?config(port, Config), + %% IPVersion = ?config(ip_version, Config), + %% Versions = ?config(snmp_versions, Config), + + Cmd = "", + net_snmp(Cmd, ""). + +%%-------------------------------------------------------------------- +%% Internal functions ------------------------------------------------ +%%-------------------------------------------------------------------- +net_snmp(Cmd, Expect) -> + SnmpNetPort = open_port({spawn, Cmd}, [stderr_to_stdout]), + receive + {SnmpNetPort, {data, Expect}} -> + ok; + Msg -> + ct:fail({{expected, {SnmpNetPort, {data, Expect}}}, + {got, Msg}}) + end. + +app_env(_Case, Config) -> + Dir = ?config(priv_dir, Config), + Vsns = ?config(snmp_versions, Config), + [{versions, Vsns}, + {agent_type, master}, + {agent_verbosity, trace}, + {db_dir, Dir}, + {audit_trail_log, [{type, read_write}, + {dir, Dir}, + {size, {10240, 10}}]}, + {config, [{dir, Dir}, + {force_load, false}, + {verbosity, trace}]}, + {local_db, [{repair, true}, + {verbosity, silence}]}, + {mib_server, [{verbosity, silence}]}, + {symbolic_store, [{verbosity, silence}]}, + {note_store, [{verbosity, silence}]}, + {net_if, [{verbosity, trace}]}]. + +oid_str([Int | Rest]) -> + oid_str(Rest, integer_to_list(Int)). + +oid_str([], Acc) -> + Acc; +oid_str([Int | Rest], Acc) -> + oid_str(Rest, Acc ++ "." ++ integer_to_list(Int)). + +agent_config(Dir, Domain, IpA, IpM, Port, Versions) -> + EngineID = ?AGENT_ENGIN_ID, + MMS = ?DEFAULT_MAX_MESSAGE_SIZE, + snmp_config:write_agent_snmp_conf(Dir, Domain, {IpA, Port}, + EngineID, MMS), + snmp_config:write_agent_snmp_context_conf(Dir), + snmp_config:write_agent_snmp_community_conf(Dir), + snmp_config:write_agent_snmp_standard_conf(Dir, "snmp_to_snmpnet_SUITE"), + snmp_config:write_agent_snmp_target_addr_conf(Dir, Domain, + IpM, Versions), + snmp_config:write_agent_snmp_target_params_conf(Dir, Versions), + snmp_config:write_agent_snmp_notify_conf(Dir, inform), + snmp_config:write_agent_snmp_vacm_conf(Dir, Versions, none). + +net_snmp_version([v3 | _]) -> + "-v3"; +net_snmp_version([v2 | _]) -> + "-v2c"; +net_snmp_version([v1 | _]) -> + "-v1". +net_snmp_ip_version(ipv4) -> + "udp:"; +net_snmp_ip_version(ipv6) -> + "udp6:". -- cgit v1.2.3 From 1ebfcb6f1f013e62aabc9935c878a55b788967a9 Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Fri, 27 Jun 2014 15:41:18 +0200 Subject: snmp: Add inform test --- lib/snmp/test/Makefile | 1 + lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 127 ++++++++++++--------- .../test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin | Bin 0 -> 3640 bytes .../test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib | 71 ++++++++++++ 4 files changed, 148 insertions(+), 51 deletions(-) create mode 100644 lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin create mode 100644 lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib (limited to 'lib/snmp') diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index d2eca0b250..a9bbe7fe62 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -239,6 +239,7 @@ release_tests_spec: opt $(INSTALL_DATA) $(RELTEST_FILES) $(COVER_SPEC_FILE) "$(RELSYSDIR)" chmod -R u+w "$(RELSYSDIR)" tar cf - snmp_test_data | (cd "$(RELSYSDIR)"; tar xf -) + tar cf - *_SUITE_data | (cd "$(RELSYSDIR)"; tar xf -) release_docs_spec: diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 4584ad75c2..e8dcffd361 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -27,7 +27,8 @@ -include_lib("snmp/include/STANDARD-MIB.hrl"). -define(AGENT_ENGIN_ID, "ErlangSnmpAgent"). --define(AGENT_PORT, 4000). +-define(AGENT_PORT, 4000). +-define(MANAGER_PORT, 8989). -define(DEFAULT_MAX_MESSAGE_SIZE, 484). -define(SYS_DESC, "iso.3.6.1.2.1.1.1.0 = STRING: \"Erlang SNMP agent\"\n"). @@ -44,33 +45,21 @@ all() -> ]. groups() -> - [{ipv4, [], ipv4_tests()}, - {ipv6, [], ipv6_tests()}, - {get, [], get_tests()}, - %%{trap, [], trap_tests()}, - {dual_ip, [], dual_ip_tests()}]. - -get_tests() -> - [erlang_agent_netsnmp_get]. -trap_tests() -> - [erlang_agent_netsnmp_trap]. -dual_ip_tests() -> - [erlang_agent_dual_ip_get]. -ipv4_tests() -> - [{group, get}]. -ipv6_tests() -> - [{group, get}, - {group, dual_ip} + [{ipv4, [], [{group, get}, + {group, inform} + ]}, + {ipv6, [], [{group, get}, + {group, inform}, + {group, dual_ip} + ]}, + {get, [], [erlang_agent_netsnmp_get]}, + {inform, [], [erlang_agent_netsnmp_inform]}, + {dual_ip, [], [erlang_agent_dual_ip_get]} ]. init_per_suite(Config) -> - case os:find_executable("snmpget") of - false -> - {skip, "snmpget not found"}; - _ -> - Config - end. - + [{agent_port, ?AGENT_PORT}, {manager_port, ?MANAGER_PORT} | Config]. + end_per_suite(_Config) -> ok. @@ -82,8 +71,8 @@ init_per_group(ipv6, Config) -> {ok, Host} = inet:gethostname(), {ok, IpAddr} = inet:getaddr(Host, inet6), Versions = [v2], - agent_config(Dir, Domain, IpAddr, IpAddr, ?AGENT_PORT, Versions), - [{host, Host}, {port, ?AGENT_PORT}, + agent_config(Dir, Domain, IpAddr, IpAddr, ?config(agent_port, Config), Versions), + [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv6} | Config]; _ -> {skip, "Host does not support IPV6"} @@ -95,11 +84,13 @@ init_per_group(ipv4, Config) -> {ok, Host} = inet:gethostname(), {ok, IpAddr} = inet:getaddr(Host, inet), Versions = [v2], - agent_config(Dir, Domain, IpAddr, IpAddr, ?AGENT_PORT, Versions), - [{host, Host}, {port, ?AGENT_PORT}, {snmp_versions, Versions}, + agent_config(Dir, Domain, IpAddr, {IpAddr, ?config(manager_port, Config)}, + ?config(agent_port, Config), Versions), + [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv4} | Config]; init_per_group(get, Config) -> + %% From Ubuntu package snmp case os:find_executable("snmpget") of false -> {skip, "snmpget not found"}; @@ -107,7 +98,8 @@ init_per_group(get, Config) -> Config end; -init_per_group(trap, Config) -> +init_per_group(inform, Config) -> + %% From Ubuntu package snmptrapfmt case os:find_executable("snmptrapd") of false -> {skip, "snmptrapd not found"}; @@ -121,12 +113,13 @@ end_per_group(_GroupName, Config) -> Config. init_per_testcase(Case, Config) -> + Dog = ct:timetrap(10000), end_per_testcase(Case, Config), application:start(snmp), application:load(snmp), application:set_env(snmp, agent, app_env(Case, Config)), snmp:start_agent(normal), - Config. + [{watchdog, Dog} | Config]. end_per_testcase(_, Config) -> application:stop(snmp), @@ -141,10 +134,10 @@ erlang_agent_netsnmp_get() -> erlang_agent_netsnmp_get(Config) when is_list(Config) -> Host = ?config(host, Config), - Port = ?config(port, Config), + Port = ?config(agent_port, Config), IPVersion = ?config(ip_version, Config), Versions = ?config(snmp_versions, Config), - + Cmd = "snmpget -c public " ++ net_snmp_version(Versions) ++ " " ++ net_snmp_ip_version(IPVersion) ++ Host ++ ":" ++ integer_to_list(Port) ++ @@ -159,26 +152,58 @@ erlang_agent_dual_ip_get(Config) when is_list(Config) -> erlang_agent_netsnmp_get([{ip_version, ipv4}]), erlang_agent_netsnmp_get([{ip_version, ipv6}]). %%-------------------------------------------------------------------- -erlang_agent_netsnmp_trap() -> - %% Host = ?config(host, Config), - %% Port = ?config(port, Config), - %% IPVersion = ?config(ip_version, Config), - %% Versions = ?config(snmp_versions, Config), +erlang_agent_netsnmp_inform(Config) when is_list(Config) -> + Host = ?config(host, Config), + IPVersion = ?config(ip_version, Config), + DataDir = ?config(data_dir, Config), + ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, "TestTrapv2")), - Cmd = "", - net_snmp(Cmd, ""). + Cmd = "snmptrapd -L o -M " ++ DataDir ++ + " --disableAuthorization=yes" ++ + " --snmpTrapdAddr=" ++ net_snmp_ip_version(IPVersion) ++ + Host ++ ":" ++ integer_to_list(?config(manager_port, Config)), + NetSnmpPort = net_snmp_trapd(Cmd), + snmpa:send_notification(snmp_master_agent, testTrapv22, + {erlang_agent_test, self()}), + net_snmp_log(NetSnmpPort), + receive + {snmp_targets, erlang_agent_test, Addresses} -> + ct:pal("Notification sent to: ~p~n", [Addresses]) + end, + receive + {snmp_notification, erlang_agent_test, {got_response, Address}} -> + ct:pal("Got respons from: ~p~n", [Address]), + ok; + {snmp_notification, erlang_agent_test, {no_response, _} = + NoResponse} -> + ct:fail(NoResponse) + end. + %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- net_snmp(Cmd, Expect) -> - SnmpNetPort = open_port({spawn, Cmd}, [stderr_to_stdout]), + NetSnmpPort = open_port({spawn, Cmd}, [stderr_to_stdout]), receive - {SnmpNetPort, {data, Expect}} -> + {NetSnmpPort, {data, Expect}} -> ok; Msg -> - ct:fail({{expected, {SnmpNetPort, {data, Expect}}}, + ct:fail({{expected, {NetSnmpPort, {data, Expect}}}, {got, Msg}}) + end, + catch erlang:port_close(NetSnmpPort). + +net_snmp_trapd(Cmd) -> + open_port({spawn, Cmd}, [stderr_to_stdout]). + +net_snmp_log(NetSnmpPort) -> + receive + {NetSnmpPort, {data, Data}} -> + ct:pal("Received from netsnmp: ~p~n", [Data]), + net_snmp_log(NetSnmpPort) + after 500 -> + catch erlang:port_close(NetSnmpPort) end. app_env(_Case, Config) -> @@ -212,16 +237,16 @@ oid_str([Int | Rest], Acc) -> agent_config(Dir, Domain, IpA, IpM, Port, Versions) -> EngineID = ?AGENT_ENGIN_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, - snmp_config:write_agent_snmp_conf(Dir, Domain, {IpA, Port}, + ok = snmp_config:write_agent_snmp_conf(Dir, Domain, {IpA, Port}, EngineID, MMS), - snmp_config:write_agent_snmp_context_conf(Dir), - snmp_config:write_agent_snmp_community_conf(Dir), - snmp_config:write_agent_snmp_standard_conf(Dir, "snmp_to_snmpnet_SUITE"), - snmp_config:write_agent_snmp_target_addr_conf(Dir, Domain, + ok = snmp_config:write_agent_snmp_context_conf(Dir), + ok = snmp_config:write_agent_snmp_community_conf(Dir), + ok = snmp_config:write_agent_snmp_standard_conf(Dir, "snmp_to_snmpnet_SUITE"), + ok = snmp_config:write_agent_snmp_target_addr_conf(Dir, Domain, IpM, Versions), - snmp_config:write_agent_snmp_target_params_conf(Dir, Versions), - snmp_config:write_agent_snmp_notify_conf(Dir, inform), - snmp_config:write_agent_snmp_vacm_conf(Dir, Versions, none). + ok = snmp_config:write_agent_snmp_target_params_conf(Dir, Versions), + ok = snmp_config:write_agent_snmp_notify_conf(Dir, inform), + ok = snmp_config:write_agent_snmp_vacm_conf(Dir, Versions, none). net_snmp_version([v3 | _]) -> "-v3"; diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin new file mode 100644 index 0000000000..9d0790498d Binary files /dev/null and b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin differ diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib new file mode 100644 index 0000000000..679ddc14b0 --- /dev/null +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib @@ -0,0 +1,71 @@ +TestTrapv2 DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE, + TimeTicks, Counter32, snmpModules, mib-2, enterprises, IpAddress, + Integer32 + FROM SNMPv2-SMI + DisplayString, TestAndIncr, TimeStamp, RowStatus, TruthValue, + TEXTUAL-CONVENTION + FROM SNMPv2-TC + MODULE-COMPLIANCE, OBJECT-GROUP, NOTIFICATION-GROUP + FROM SNMPv2-CONF + + system, snmp, ifIndex, ifAdminStatus, ifOperStatus + FROM RFC1213-MIB + snmpTraps + FROM SNMPv2-MIB; + +testTrapv2 MODULE-IDENTITY + LAST-UPDATED "9511090000Z" + ORGANIZATION "IETF SNMPv2 Working Group" + CONTACT-INFO + " Marshall T. Rose + + Postal: Dover Beach Consulting, Inc. + 420 Whisman Court + Mountain View, CA 94043-2186 + US + + Tel: +1 415 968 1052 + + E-mail: mrose@dbc.mtview.ca.us" + DESCRIPTION + "The MIB module for SNMPv2 entities." + REVISION "9304010000Z" + DESCRIPTION + "The initial revision of this MIB module was published as + RFC 1450." + ::= { system 100 } + + +tst OBJECT IDENTIFIER ::= { system 0 } + +testTrapv21 NOTIFICATION-TYPE + STATUS current + DESCRIPTION + "This trap is exactly the v2 correspondance of testTrap1 in + TestTrap mib." + ::= { snmp 1 } + +testTrapv22 NOTIFICATION-TYPE + STATUS current + DESCRIPTION + "This trap is exactly the v2 correspondance of testTrap2 in + TestTrap mib." + ::= { system 0 1 } + +linkUp NOTIFICATION-TYPE + OBJECTS { ifIndex, ifAdminStatus, ifOperStatus } + STATUS current + DESCRIPTION + "A linkUp trap signifies that the SNMPv2 entity, + acting in an agent role, has detected that the + ifOperStatus object for one of its communication links + has transitioned out of the down state." + ::= { snmpTraps 4 } + + + + +END -- cgit v1.2.3 From dfb5cf6e2406486eeb7fbd89bf9118a6411bd5f2 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 26 Jun 2014 10:50:24 +0200 Subject: Rewrite agent for IPv4 + IPv6 --- lib/snmp/src/agent/snmp_framework_mib.erl | 86 ++- lib/snmp/src/agent/snmp_target_mib.erl | 12 +- lib/snmp/src/agent/snmpa_conf.erl | 93 +-- lib/snmp/src/agent/snmpa_net_if.erl | 1020 +++++++++++++++++++---------- lib/snmp/src/agent/snmpa_trap.erl | 145 ++-- lib/snmp/src/misc/snmp_conf.erl | 8 +- lib/snmp/src/misc/snmp_config.erl | 12 +- lib/snmp/test/klas3.erl | 1 + 8 files changed, 899 insertions(+), 478 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 4599f05f47..3b33cae3ec 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -41,7 +41,7 @@ -compile({no_auto_import,[error/1]}). -export([init/0, configure/1]). -export([intContextTable/1, intContextTable/3, - intAgentTransportDomain/1, + intAgentTransportDomain/1, intAgentTransports/1, intAgentUDPPort/1, intAgentIpAddress/1, snmpEngineID/1, snmpEngineBoots/1, @@ -137,8 +137,9 @@ read_agent(Dir) -> error({failed_reading_config_file, Dir, FileName, Reason}) end, Mand = - [{intAgentIpAddress, mandatory}, - {intAgentUDPPort, mandatory}, + [{intAgentTransports, mandatory}, +%%% {intAgentIpAddress, mandatory}, +%%% {intAgentUDPPort, mandatory}, {snmpEngineMaxMessageSize, mandatory}, {snmpEngineID, mandatory}], {ok, Conf} = snmp_conf:check_mandatory(Conf0, Mand), @@ -190,27 +191,63 @@ check_context(Context) -> %% Agent %% {Name, Value}. %%----------------------------------------------------------------- -check_agent({intAgentTransportDomain, D}, _Domain) -> - {snmp_conf:check_domain(D), D}; -check_agent({intAgentIpAddress = Tag, Value}, D) -> - Domain = - case D of - undefined -> - snmp_target_mib:default_domain(); - _ -> - D - end, - {case snmp_conf:check_ip(Domain, Value) of +check_agent(Entry, undefined) -> + check_agent(Entry, {snmp_target_mib:default_domain(), undefined}); +check_agent({intAgentTransportDomain, Domain}, {_, Port}) -> + {snmp_conf:check_domain(Domain), {Domain, Port}}; +check_agent({intAgentUDPPort, Port}, {Domain, _}) -> + ok = snmp_conf:check_port(Port), + {ok, {Domain, Port}}; +check_agent({intAgentIpAddress, _}, {_, undefined}) -> + error({missing_mandatory, intAgentUDPPort}); +check_agent({intAgentIpAddress = Tag, Ip} = Entry, {Domain, Port} = State) -> + {case snmp_conf:check_ip(Domain, Ip) of ok -> - ok; + [Entry, {intAgentTransports, [{Domain, {Ip, Port}}]}]; {ok, FixedIp} -> - {ok, {Tag, FixedIp}} - end, Domain}; -check_agent(Entry, Domain) -> - {check_agent(Entry), Domain}. + [{Tag, Ip}, {intAgentTransports, [{Domain, {FixedIp, Port}}]}] + end, State}; +check_agent({intAgentTransports = Tag, Transports}, {_, Port} = State) -> + CheckedTransports = + [case + case Port of + undefined -> + snmp_conf:check_address(Domain, Address); + _ -> + snmp_conf:check_address(Domain, Address, Port) + end + of + ok -> + Transport; + {ok, FixedAddress} -> + {Domain, FixedAddress} + end + || {Domain, Address} = Transport <- Transports], + {{ok, {Tag, CheckedTransports}}, State}; +check_agent(Entry, State) -> + {check_agent(Entry), State}. + +%%% XXX remove +%%% +%%% check_agent({intAgentTransportDomain, D}, _Domain) -> +%%% {snmp_conf:check_domain(D), D}; +%%% check_agent({intAgentIpAddress = Tag, Value}, D) -> +%%% Domain = +%%% case D of +%%% undefined -> +%%% snmp_target_mib:default_domain(); +%%% _ -> +%%% D +%%% end, +%%% {case snmp_conf:check_ip(Domain, Value) of +%%% ok -> +%%% ok; +%%% {ok, FixedIp} -> +%%% {ok, {Tag, FixedIp}} +%%% end, Domain}; +%%% check_agent(Entry, Domain) -> +%%% {check_agent(Entry), Domain}. -check_agent({intAgentUDPPort, Value}) -> - snmp_conf:check_integer(Value); %% This one is kept for backwards compatibility check_agent({intAgentMaxPacketSize, Value}) -> snmp_conf:check_packet_size(Value); @@ -224,7 +261,9 @@ check_agent(X) -> %% Ordering function to sort intAgentTransportDomain first %% hence before intAgentIpAddress. Sort other entries on the key. order_agent(EntryA, EntryB) -> - snmp_conf:keyorder(1, EntryA, EntryB, [intAgentTransportDomain | sort]). + snmp_conf:keyorder( + 1, EntryA, EntryB, + [intAgentTransportDomain, intAgentUDPPort | sort]). @@ -402,6 +441,9 @@ intAgentIpAddress(Op) -> intAgentTransportDomain(Op) -> snmp_generic:variable_func(Op, db(intAgentTransportDomain)). +intAgentTransports(Op) -> + snmp_generic:variable_func(Op, db(intAgentTransports)). + snmpEngineID(print) -> diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index 932829e150..e916f17d6a 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -174,7 +174,8 @@ check_target_addr( EngineId, TMask, MMS); check_target_addr( {Name, Ip, Udp, Timeout, RetryCount, TagList, Params, - EngineId, TMask, MMS}) -> % Arity 10 + EngineId, TMask, MMS}) + when is_integer(Udp) -> % Arity 10 Domain = default_domain(), Address = {Ip, Udp}, check_target_addr( @@ -189,7 +190,8 @@ check_target_addr( EngineId); check_target_addr( {Name, Ip, Udp, Timeout, RetryCount, TagList, Params, - EngineId}) -> % Arity 8 + EngineId}) % Arity 8 + when is_integer(Udp) -> Domain = default_domain(), Address = {Ip, Udp}, check_target_addr( @@ -202,7 +204,8 @@ check_target_addr( check_target_addr( Name, Domain, Address, Timeout, RetryCount, TagList, Params); check_target_addr( - {Name, Ip, Udp, Timeout, RetryCount, TagList, Params}) -> % Arity 7 + {Name, Ip, Udp, Timeout, RetryCount, TagList, Params}) % Arity 7 + when is_integer(Udp) -> Domain = default_domain(), Address = {Ip, Udp}, check_target_addr( @@ -216,7 +219,8 @@ check_target_addr( Name, Domain, Address, Timeout, RetryCount, TagList, Params, TMask, MMS); check_target_addr( {Name, Ip, Udp, Timeout, RetryCount, TagList, Params, - TMask, MMS}) -> % Arity 9 + TMask, MMS}) % Arity 9 + when is_integer(Udp) -> Domain = default_domain(), Address = {Ip, Udp}, check_target_addr( diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index 2569b01b55..b4d32dc928 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -140,6 +140,8 @@ write_agent_conf(Fd, [H|T]) -> do_write_agent_conf(Fd, H), write_agent_conf(Fd, T). +do_write_agent_conf(Fd, {intAgentTransports = Tag, Val}) -> + io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_agent_conf(Fd, {intAgentTransportDomain = Tag, Val}) -> io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_agent_conf(Fd, {intAgentIpAddress = Tag, Val}) -> @@ -379,72 +381,35 @@ do_write_standard_conf(_Fd, Tag, Val) -> %% ------ target_addr.conf ------ %% -target_addr_entry(Name, - Ip, - TagList, - ParamsName, - EngineId) -> +target_addr_entry( + Name, Ip, TagList, ParamsName, EngineId) -> target_addr_entry(Name, Ip, TagList, ParamsName, EngineId, []). -target_addr_entry(Name, - Ip, - TagList, - ParamsName, - EngineId, - TMask) -> - target_addr_entry(Name, Ip, 162, TagList, - ParamsName, EngineId, - TMask, 2048). - -target_addr_entry(Name, - Ip, - Udp, - TagList, - ParamsName, - EngineId, - TMask, - MaxMessageSize) -> - target_addr_entry(Name, Ip, Udp, 1500, 3, TagList, - ParamsName, EngineId, - TMask, MaxMessageSize). - -target_addr_entry(Name, - Ip, - Udp, - Timeout, - RetryCount, - TagList, - ParamsName, - EngineId, - TMask, - MaxMessageSize) -> - target_addr_entry(Name, snmp_target_mib:default_domain(), Ip, Udp, - Timeout, RetryCount, TagList, - ParamsName, EngineId, - TMask, MaxMessageSize). - -target_addr_entry(Name, - Domain, - Ip, - Udp, - Timeout, - RetryCount, - TagList, - ParamsName, - EngineId, - TMask, - MaxMessageSize) -> - {Name, - Domain, - Ip, - Udp, - Timeout, - RetryCount, - TagList, - ParamsName, - EngineId, - TMask, - MaxMessageSize}. +target_addr_entry( + Name, Ip, TagList, ParamsName, + EngineId, TMask) -> + target_addr_entry( + Name, Ip, 162, TagList, ParamsName, + EngineId, TMask, 2048). + +target_addr_entry( + Name, Domain_or_Ip, Addr_or_Port, TagList, + ParamsName, EngineId, TMask, MaxMessageSize) -> + target_addr_entry( + Name, Domain_or_Ip, Addr_or_Port, 1500, 3, TagList, + ParamsName, EngineId, TMask, MaxMessageSize). + +target_addr_entry( + Name, Domain_or_Ip, Addr_or_Port, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize) -> + {Name, Domain_or_Ip, Addr_or_Port, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}. + +target_addr_entry( + Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, + ParamsName, EngineId,TMask, MaxMessageSize) -> + {Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}. write_target_addr_config(Dir, Conf) -> diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 875ea19097..f5fd377341 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -35,19 +35,27 @@ -include("snmp_debug.hrl"). -include("snmp_verbosity.hrl"). --record(state, {parent, - note_store, - master_agent, - usock, - usock_opts, - mpd_state, - log, - reqs = [], - debug = false, - limit = infinity, - rcnt = [], - filter, - domain = snmpUDPDomain}). +-record(state, + {parent, + note_store, + master_agent, + transports = [], +%% usock, +%% usock_opts, + mpd_state, + log, + reqs = [], + debug = false, + limit = infinity, +%% rcnt = [], + filter}). +%% domain = snmpUDPDomain}). + +-record(transport, + {socket, + domain = snmpUDPDomain, + opts = [], + req_refs = []}). -ifndef(default_verbosity). -define(default_verbosity,silence). @@ -105,21 +113,27 @@ get_request_limit(Pid) -> set_request_limit(Pid, NewLimit) -> call(Pid, {set_request_limit, NewLimit}). -get_port() -> - {value, UDPPort} = snmp_framework_mib:intAgentUDPPort(get), - UDPPort. +get_transports() -> + {value, Transports} = snmp_framework_mib:intAgentTransports(get), + Transports. -get_address() -> - {value, IPAddress} = snmp_framework_mib:intAgentIpAddress(get), - IPAddress. - -get_domain() -> - case snmp_framework_mib:intAgentTransportDomain(get) of - {value, Domain} -> - Domain; - genErr -> - snmpUDPDomain - end. +%%% XXX remove +%%% +%%% get_ip_port() -> +%%% {value, UDPPort} = snmp_framework_mib:intAgentUDPPort(get), +%%% UDPPort. +%%% +%%% get_address() -> +%%% {value, IPAddress} = snmp_framework_mib:intAgentIpAddress(get), +%%% IPAddress. +%%% +%%% get_domain() -> +%%% case snmp_framework_mib:intAgentTransportDomain(get) of +%%% {value, Domain} -> +%%% Domain; +%%% genErr -> +%%% snmpUDPDomain +%%% end. filter_reset(Pid) -> Pid ! filter_reset. @@ -170,13 +184,15 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> put(verbosity,get_verbosity(Opts)), ?vlog("starting",[]), - %% -- Port and address -- - Domain = get_domain(), - ?vdebug("domain: ~w",[Domain]), - UDPPort = get_port(), - ?vdebug("port: ~w",[UDPPort]), - IPAddress = get_address(), - ?vdebug("addr: ~w",[IPAddress]), +%%% XXX remove +%%% +%%% %% -- Port and address -- +%%% Domain = get_domain(), +%%% ?vdebug("domain: ~w",[Domain]), +%%% UDPPort = get_ip_port(), +%%% ?vdebug("port: ~w",[UDPPort]), +%%% IPAddress = get_address(), +%%% ?vdebug("addr: ~w",[IPAddress]), %% -- Versions -- Vsns = get_vsns(Opts), @@ -193,37 +209,73 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> Log = create_log(), ?vdebug("Log: ~w",[Log]), - - %% -- Socket -- - IPOpts1 = ip_opt_bind_to_ip_address(Opts, IPAddress), - IPOpts2 = ip_opt_no_reuse_address(Opts), - IPOpts3 = ip_opt_recbuf(Opts), - IPOpts4 = ip_opt_sndbuf(Opts), - IPOpts = - [binary, snmp_conf:tdomain_to_family(Domain) - | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4], - case gen_udp_open(UDPPort, IPOpts) of - {ok, Sock} -> + DomainAddresses = get_transports(), + ?vdebug("DomainAddresses: ~w",[DomainAddresses]), + try + [begin + SocketOpts = socket_opts(Domain, Address, Opts), + Socket = socket_open(Domain, SocketOpts), + active_once(Socket), + #transport{ + socket = Socket, + domain = Domain, + opts = SocketOpts} + end || {Domain, Address} <- DomainAddresses] + of + [] -> + ?vinfo("No transports configured: ~p", [DomainAddresses]), + {error, {no_transports,DomainAddresses}}; + Transports -> MpdState = snmpa_mpd:init(Vsns), - init_counters(), - active_once(Sock), + init_counters(), S = #state{parent = Parent, note_store = NoteStore, master_agent = MasterAgent, mpd_state = MpdState, - usock = Sock, - usock_opts = IPOpts, + transports = Transports, log = Log, limit = Limit, - filter = FilterMod, - domain = Domain}, + filter = FilterMod}, ?vdebug("started with MpdState: ~p", [MpdState]), - {ok, S}; - {error, Reason} -> - ?vinfo("Failed to open UDP socket: ~p", [Reason]), - {error, {udp_open, UDPPort, Reason}} + {ok, S} + catch + Error -> + ?vinfo("Failed to initialize socket(s): ~p", [Error]), + {error, Error} end. +%%% XXX remove +%%% +%%% %% -- Socket -- +%%% IPOpts1 = ip_opt_bind_to_ip_address(Opts, IPAddress), +%%% IPOpts2 = ip_opt_no_reuse_address(Opts), +%%% IPOpts3 = ip_opt_recbuf(Opts), +%%% IPOpts4 = ip_opt_sndbuf(Opts), +%%% IPOpts = +%%% [binary, snmp_conf:tdomain_to_family(Domain) +%%% | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4], +%%% case gen_udp_open(UDPPort, IPOpts) of +%%% {ok, Sock} -> +%%% MpdState = snmpa_mpd:init(Vsns), +%%% init_counters(), +%%% active_once(Sock), +%%% S = #state{parent = Parent, +%%% note_store = NoteStore, +%%% master_agent = MasterAgent, +%%% mpd_state = MpdState, +%%% usock = Sock, +%%% usock_opts = IPOpts, +%%% log = Log, +%%% limit = Limit, +%%% filter = FilterMod, +%%% domain = Domain}, +%%% ?vdebug("started with MpdState: ~p", [MpdState]), +%%% {ok, S}; +%%% {error, Reason} -> +%%% ?vinfo("Failed to open UDP socket: ~p", [Reason]), +%%% {error, {udp_open, UDPPort, Reason}} +%%% end. + create_log() -> case ets:lookup(snmp_agent_table, audit_trail_log) of @@ -298,33 +350,63 @@ format_address(Address) -> iolist_to_binary(snmp_conf:mk_addr_string(Address)). - -gen_udp_open(Port, Opts) -> +socket_open(snmpUDPDomain = Domain, [IpPort | Opts]) -> case init:get_argument(snmp_fd) of {ok, [[FdStr]]} -> Fd = list_to_integer(FdStr), - ?vdebug("gen_udp_open(~p, ~p) Fd: ~p",[Port,Opts,Fd]), - gen_udp:open(0, [{fd, Fd}|Opts]); + ?vdebug("socket_open(~p, [~p | ~p]) Fd: ~p", + [Domain, IpPort, Opts, Fd]), + gen_udp_open(IpPort, [{fd, Fd} | Opts]); error -> case init:get_argument(snmpa_fd) of {ok, [[FdStr]]} -> Fd = list_to_integer(FdStr), - ?vdebug("gen_udp_open(~p, ~p) Fd: ~p",[Port,Opts,Fd]), - gen_udp:open(0, [{fd, Fd}|Opts]); + ?vdebug("socket_open(~p, [~p | ~p]) Fd: ~p", + [Domain, IpPort, Opts, Fd]), + gen_udp_open(IpPort, [{fd, Fd} | Opts]); error -> - ?vdebug("gen_udp_open(~p, ~p)",[Port,Opts]), - gen_udp:open(Port, Opts) + ?vdebug("socket_open(~p, [~p | ~p])", + [Domain, IpPort, Opts]), + gen_udp_open(IpPort, Opts) end + end; +socket_open(Domain, [IpPort | Opts]) + when Domain =:= transportDomainUdpIpv4; + Domain =:= transportDomainUdpIpv6 -> + ?vdebug("socket_open(~p, [~p | ~p])", [Domain, IpPort, Opts]), + gen_udp_open(IpPort, Opts); +socket_open(Domain, Opts) -> + throw({socket_open, Domain, Opts}). + +gen_udp_open(IpPort, Opts) -> + case gen_udp:open(IpPort, Opts) of + {ok, Socket} -> + Socket; + {error, Reason} -> + throw({udp_open, IpPort, Reason}) end. -loop(#state{domain = Domain} = S) -> + +loop(#state{transports = Transports, limit = Limit, parent = Parent} = S) -> + ?vdebug("loop(~p)", [S]), receive - {udp, _UdpId, Ip, Port, Packet} -> - ?vlog("got paket from ~w:~w",[Ip,Port]), - From = fix_filter_address(Domain, {Domain, {Ip, Port}}), - NewS = maybe_handle_recv(S, From, Packet), - loop(NewS); + {udp, Socket, IpAddr, IpPort, Packet} = Msg when is_port(Socket) -> + ?vlog("got paket from ~w:~w on ~w", [IpAddr, IpPort, Socket]), + case lists:keyfind(Socket, #transport.socket, Transports) of + #transport{socket = Socket, domain = Domain} = Transport -> + From = + case Domain of + snmpUDPDomain -> + {IpAddr, IpPort}; + _ -> + {Domain, {IpAddr, IpPort}} + end, + loop(maybe_handle_recv(S, Transport, From, Packet)); + false -> + error_msg("Packet on unknown port: ~p", [Msg]), + loop(S) + end; {info, ReplyRef, Pid} -> Info = get_info(S), @@ -332,12 +414,35 @@ loop(#state{domain = Domain} = S) -> loop(S); %% response (to get/get_next/get_bulk/set requests) - {snmp_response, Vsn, RePdu, Type, ACMData, To, []} -> + {snmp_response, Vsn, RePdu, Type, ACMData, To, Extra} -> ?vlog("reply pdu: " "~n ~s", [?vapply(snmp_misc, format, [256, "~w", [RePdu]])]), - NewS = maybe_handle_reply_pdu(S, Vsn, RePdu, Type, ACMData, To), - loop(NewS); + {_, ReqRef} = lists:keyfind(request_ref, 1, Extra), + case + case + (Limit =/= infinity) andalso + select_transport_from_req_ref(ReqRef, Transports) + of + false -> + select_transport_from_domain( + address_to_domain(To), + Transports); + T -> + T + end + of + false -> + error_msg( + "Can not find transport for response PDU to: ~s", + [format_address(To)]), + loop(S); + Transport -> + NewS = update_req_counter_outgoing(S, Transport, ReqRef), + maybe_handle_reply_pdu( + NewS, Transport, Vsn, RePdu, Type, ACMData, To), + loop(NewS) + end; %% Traps/notification {send_pdu, Vsn, Pdu, MsgData, TDomAddrs} -> @@ -406,15 +511,34 @@ loop(#state{domain = Domain} = S) -> NewS = handle_send_discovery(S, Pdu, MsgData, To, From), loop(NewS); - {discarded_pdu, _Vsn, ReqId, _ACMData, Variable, _Extra} -> - ?vdebug("discard PDU: ~p", [Variable]), + {discarded_pdu, _Vsn, ReqId, _ACMData, Variable, Extra} -> + ?vdebug("discard PDU: ~p - ~p - ~p", + [Variable, Extra, Transports]), snmpa_mpd:discarded_pdu(Variable), - NewS = update_req_counter_outgoing(S, ReqId), - loop(NewS); + {_, ReqRef} = lists:keyfind(request_ref, 1, Extra), + if + Limit =:= infinity -> + %% The incoming PDU was not registered + loop(update_req_counter_outgoing(S, false, ReqRef)); + true -> + case + select_transport_from_req_ref(ReqRef, Transports) + of + false -> + error_msg( + "Can not find transport for discarded PDU: ~p", + [ReqId]), + loop(S); + Transport -> + loop( + update_req_counter_outgoing( + S, Transport, ReqRef)) + end + end; {get_log_type, ReplyRef, Pid} -> ?vdebug("get log type: ~p", []), - #state{log = {_, LogType}} = S, + {_, LogType} = S#state.log, Pid ! {ReplyRef, {ok, LogType}, self()}, loop(S); @@ -426,7 +550,6 @@ loop(#state{domain = Domain} = S) -> {get_request_limit, ReplyRef, Pid} -> ?vdebug("get request limit: ~p", []), - #state{limit = Limit} = S, Pid ! {ReplyRef, {ok, Limit}, self()}, loop(S); @@ -450,36 +573,50 @@ loop(#state{domain = Domain} = S) -> reset_counters(), loop(S); - {'EXIT', Parent, Reason} when Parent == S#state.parent -> + {'EXIT', Parent, Reason} -> ?vlog("parent (~p) exited: " "~n ~p", [Parent, Reason]), exit(Reason); - {'EXIT', Port, Reason} when Port == S#state.usock -> - UDPPort = get_port(), - NewS = - case gen_udp_open(UDPPort, S#state.usock_opts) of - {ok, Id} -> - error_msg("Port ~p exited for reason" - "~n ~p" - "~n Re-opened (~p)", [Port, Reason, Id]), - S#state{usock = Id}; - {error, ReopenReason} -> - error_msg("Port ~p exited for reason" - "~n ~p" - "~n Re-open failed with reason" - "~n ~p", - [Port, Reason, ReopenReason]), - ok - end, - loop(NewS); - - {'EXIT', Port, Reason} when is_port(Port) -> - error_msg("Exit message from port ~p for reason ~p~n", - [Port, Reason]), - loop(S); + {'EXIT', Socket, Reason} when is_port(Socket) -> + case lists:keyfind(Socket, #transport.socket, Transports) of + #transport{ + socket = Socket, + domain = Domain, + opts = SocketOpts, + req_refs = ReqRefs} = Transport -> + try socket_open(Domain, SocketOpts) of + NewSocket -> + error_msg( + "Socket ~p exited for reason" + "~n ~p" + "~n Re-opened (~p)", + [Socket, Reason, NewSocket]), + (length(ReqRefs) < Limit) andalso + active_once(NewSocket), + S#state{ + transports = + lists:keyreplace( + Socket, #transport.socket, Transports, + Transport#transport{socket = NewSocket})} + catch + ReopenReason -> + error_msg( + "Socket ~p exited for reason" + "~n ~p" + "~n Re-open failed with reason" + "~n ~p", + [Socket, Reason, ReopenReason]), + exit(ReopenReason) + end; + false -> + error_msg( + "Exit message from port ~p for reason ~p~n", + [Socket, Reason]), + loop(S) + end; - {'EXIT', Pid, Reason} -> + {'EXIT', Pid, Reason} when is_pid(Pid) -> ?vlog("~p exited: " "~n ~p", [Pid, Reason]), NewS = clear_reqs(Pid, S), @@ -487,71 +624,144 @@ loop(#state{domain = Domain} = S) -> {system, From, Msg} -> ?vdebug("system event ~p from ~p", [Msg, From]), - sys:handle_system_msg(Msg, From, S#state.parent, ?MODULE, [], S); + sys:handle_system_msg(Msg, From, Parent, ?MODULE, [], S); _ -> loop(S) end. -update_req_counter_incomming(#state{limit = infinity, usock = Sock} = S, _) -> - active_once(Sock), %% No limit so activate directly +update_req_counter_incoming( + #state{limit = infinity} = S, + #transport{socket = Socket}, + _ReqRef) -> + active_once(Socket), %% No limit so activate directly S; -update_req_counter_incomming(#state{limit = Limit, - rcnt = RCnt, - usock = Sock} = S, Rid) - when length(RCnt) + 1 == Limit -> +update_req_counter_incoming( + #state{limit = Limit} = S, + #transport{socket = Socket, req_refs = ReqRefs} = T, + ReqRef) when length(ReqRefs) + 1 >= Limit -> %% Ok, one more and we are at the limit. %% Just make sure we are not already processing this one... - case lists:member(Rid, RCnt) of + case lists:member(ReqRef, ReqRefs) of false -> %% We are at the limit, do _not_ activate socket - S#state{rcnt = [Rid|RCnt]}; + update_transport_req_refs(S, T, [ReqRef | ReqRefs]); true -> - active_once(Sock), + active_once(Socket), S end; -update_req_counter_incomming(#state{rcnt = RCnt, - usock = Sock} = S, Rid) -> - active_once(Sock), - case lists:member(Rid, RCnt) of +update_req_counter_incoming( + #state{} = S, + #transport{socket = Socket, req_refs = ReqRefs} = T, + ReqRef) -> + active_once(Socket), + case lists:member(ReqRef, ReqRefs) of false -> - S#state{rcnt = [Rid|RCnt]}; + update_transport_req_refs(S, T, [ReqRef | ReqRefs]); true -> S end. - -update_req_counter_outgoing(#state{limit = infinity} = S, _Rid) -> +update_transport_req_refs( + #state{transports = Transports} = S, + #transport{socket = Socket} = T, + ReqRefs) -> + S#state{ + transports = + lists:keyreplace( + Socket, #transport.socket, Transports, + T#transport{req_refs = ReqRefs})}. + +%%% XXX remove +%%% +%%% update_req_counter_incoming(#state{limit = infinity, usock = Sock} = S, _) -> +%%% active_once(Sock), %% No limit so activate directly +%%% S; +%%% update_req_counter_incoming(#state{limit = Limit, +%%% rcnt = RCnt, +%%% usock = Sock} = S, Rid) +%%% when length(RCnt) + 1 >= Limit -> +%%% %% Ok, one more and we are at the limit. +%%% %% Just make sure we are not already processing this one... +%%% case lists:member(Rid, RCnt) of +%%% false -> +%%% %% We are at the limit, do _not_ activate socket +%%% S#state{rcnt = [Rid|RCnt]}; +%%% true -> +%%% active_once(Sock), +%%% S +%%% end; +%%% update_req_counter_incoming(#state{rcnt = RCnt, +%%% usock = Sock} = S, Rid) -> +%%% active_once(Sock), +%%% case lists:member(Rid, RCnt) of +%%% false -> +%%% S#state{rcnt = [Rid|RCnt]}; +%%% true -> +%%% S +%%% end. + + +update_req_counter_outgoing( + #state{limit = infinity} = S, + _Transport, _ReqRef) -> %% Already activated (in the incoming function) S; -update_req_counter_outgoing(#state{limit = Limit, - rcnt = RCnt, - usock = Sock} = S, Rid) - when length(RCnt) == Limit -> - ?vtrace("handle_req_counter_outgoing(~w) -> entry with" - "~n Rid: ~w" - "~n length(RCnt): ~w", [Limit, Rid, length(RCnt)]), - case lists:delete(Rid, RCnt) of - NewRCnt when length(NewRCnt) < Limit -> +update_req_counter_outgoing( + #state{limit = Limit, transports = Transports} = S, + #transport{socket = Socket, req_refs = ReqRefs} = Transport, + ReqRef) -> + LengthReqRefs = length(ReqRefs), + ?vtrace("update_req_counter_outgoing() -> entry with~n" + " Limit: ~w~n" + " ReqRef: ~w~n" + " length(ReqRefs): ~w", [Limit, ReqRef, LengthReqRefs]), + NewReqRefs = lists:delete(ReqRef, ReqRefs), + (LengthReqRefs >= Limit) andalso (length(NewReqRefs) < Limit) andalso + begin ?vtrace("update_req_counter_outgoing -> " - "passed below limit: activate", []), - active_once(Sock), - S#state{rcnt = NewRCnt}; - _ -> - S - end; -update_req_counter_outgoing(#state{limit = Limit, rcnt = RCnt} = S, - Rid) -> - ?vtrace("handle_req_counter_outgoing(~w) -> entry with" - "~n Rid: ~w" - "~n length(RCnt): ~w", [Limit, Rid, length(RCnt)]), - NewRCnt = lists:delete(Rid, RCnt), - S#state{rcnt = NewRCnt}. + "passed below limit: activate", []), + active_once(Socket) + end, + S#state{ + transports = + snmp_misc:keyreplace( + Socket, #transport.socket, Transports, + Transport#transport{req_refs = NewReqRefs})}. + +%%% XXX remove +%%% +%%% update_req_counter_outgoing( +%%% #state{limit = Limit, +%%% rcnt = RCnt, +%%% usock = Sock} = S, Rid) +%%% when length(RCnt) >= Limit -> +%%% ?vtrace("handle_req_counter_outgoing(~w) -> entry with" +%%% "~n Rid: ~w" +%%% "~n length(RCnt): ~w", [Limit, Rid, length(RCnt)]), +%%% case lists:delete(Rid, RCnt) of +%%% NewRCnt when length(NewRCnt) < Limit -> +%%% ?vtrace("update_req_counter_outgoing -> " +%%% "passed below limit: activate", []), +%%% active_once(Sock), +%%% S#state{rcnt = NewRCnt}; +%%% _ -> +%%% S +%%% end; +%%% update_req_counter_outgoing(#state{limit = Limit, rcnt = RCnt} = S, +%%% Rid) -> +%%% ?vtrace("handle_req_counter_outgoing(~w) -> entry with" +%%% "~n Rid: ~w" +%%% "~n length(RCnt): ~w", [Limit, Rid, length(RCnt)]), +%%% NewRCnt = lists:delete(Rid, RCnt), +%%% S#state{rcnt = NewRCnt}. maybe_handle_recv( - #state{usock = Sock, filter = FilterMod} = S, From, Packet) -> + #state{filter = FilterMod} = S, + #transport{socket = Socket} = Transport, + From, Packet) -> {From_1, From_2} = From, case try FilterMod:accept_recv(From_1, From_2) @@ -566,7 +776,7 @@ maybe_handle_recv( false -> %% Drop the received packet inc(netIfMsgInDrops), - active_once(Sock), + active_once(Socket), S; Other -> case Other of @@ -577,28 +787,13 @@ maybe_handle_recv( "FilterMod:accept_recv(~p, ~p) returned: ~p", [From_1,From_2,Other]) end, - handle_recv(S, From, Packet) - end. - -handle_discovery_response(_From, #pdu{request_id = ReqId} = Pdu, - ManagerEngineId, - #state{usock = Sock, reqs = Reqs} = S) -> - case lists:keysearch(ReqId, 1, S#state.reqs) of - {value, {_, Pid}} -> - active_once(Sock), - Pid ! {snmp_discovery_response_received, Pdu, ManagerEngineId}, - NReqs = lists:keydelete(ReqId, 1, Reqs), - S#state{reqs = NReqs}; - _ -> - %% Ouch, timeout? resend? - S + handle_recv(S, Transport, From, Packet) end. handle_recv( - #state{usock = Sock, - mpd_state = MpdState, - note_store = NS, - log = Log} = S, From, Packet) -> + #state{mpd_state = MpdState, note_store = NS, log = Log} = S, + #transport{socket = Socket} = Transport, + From, Packet) -> put(n1, erlang:now()), LogF = fun(Type, Data) -> @@ -607,48 +802,72 @@ handle_recv( case (catch snmpa_mpd:process_packet( Packet, From, MpdState, NS, LogF)) of {ok, _Vsn, Pdu, _PduMS, {discovery, ManagerEngineId}} -> - handle_discovery_response(From, Pdu, ManagerEngineId, S); + handle_discovery_response( + S, Transport, From, Pdu, ManagerEngineId); {ok, _Vsn, Pdu, _PduMS, discovery} -> - handle_discovery_response(From, Pdu, undefined, S); + handle_discovery_response( + S, Transport, From, Pdu, undefined); {ok, Vsn, Pdu, PduMS, ACMData} -> ?vlog("got pdu ~s", [?vapply(snmp_misc, format, [256, "~w", [Pdu]])]), - %% handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S); - maybe_handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S); + %% handle_recv_pdu(S, Transport, From, Vsn, Pdu, PduMS, ACMData); + maybe_handle_recv_pdu( + S, Transport, From, Vsn, Pdu, PduMS, ACMData); {discarded, Reason} -> ?vlog("packet discarded for reason: ~s", [?vapply(snmp_misc, format, [256, "~w", [Reason]])]), - active_once(Sock), + active_once(Socket), S; {discarded, Reason, ReportPacket} -> ?vlog("sending report for reason: " "~n ~s", [?vapply(snmp_misc, format, [256, "~w", [Reason]])]), - (catch udp_send(S#state.usock, From, ReportPacket)), - active_once(Sock), + (catch udp_send(Socket, From, ReportPacket)), + active_once(Socket), S; {discovery, ReportPacket} -> ?vlog("sending discovery report", []), - (catch udp_send(S#state.usock, From, ReportPacket)), - active_once(Sock), + (catch udp_send(Socket, From, ReportPacket)), + active_once(Socket), S; Error -> error_msg("processing of received message failed: " "~n ~p", [Error]), - active_once(Sock), + active_once(Socket), + S + end. + +handle_discovery_response( + #state{reqs = Reqs} = S, + #transport{socket = Socket}, + _From, + #pdu{request_id = ReqId} = Pdu, + ManagerEngineId) -> + case lists:keyfind(ReqId, 1, S#state.reqs) of + {ReqId, Pid} -> + active_once(Socket), + Pid ! {snmp_discovery_response_received, Pdu, ManagerEngineId}, + %% XXX Strange... Reqs from this Pid should be reaped + %% at process exit by clear_reqs/2 so the following + %% should be redundant. + NReqs = lists:keydelete(ReqId, 1, Reqs), + S#state{reqs = NReqs}; + false -> + %% Ouch, timeout? resend? S end. maybe_handle_recv_pdu( + #state{filter = FilterMod} = S, + #transport{socket = Socket} = Transport, From, Vsn, - #pdu{type = Type} = Pdu, PduMS, ACMData, - #state{usock = Sock, filter = FilterMod} = S) -> + #pdu{type = Type} = Pdu, PduMS, ACMData) -> {From_1, From_2} = From, case try FilterMod:accept_recv_pdu(From_1, From_2, Type) @@ -664,8 +883,8 @@ maybe_handle_recv_pdu( of false -> inc(netIfPduInDrops), - active_once(Sock), - ok; + active_once(Socket), + S; Other -> case Other of true -> @@ -675,39 +894,72 @@ maybe_handle_recv_pdu( "FilterMod:accept_recv_pdu(~p, ~p, ~p) returned: ~p", [From_1,From_2,Type,Other]) end, - handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, S) + handle_recv_pdu(S, Transport, From, Vsn, Pdu, PduMS, ACMData) end. handle_recv_pdu( + #state{reqs = Reqs} = S, + #transport{socket = Socket}, From, Vsn, - #pdu{type = 'get-response'} = Pdu, _PduMS, _ACMData, - #state{usock = Sock} = S) -> - active_once(Sock), - handle_response(Vsn, Pdu, From, S), + #pdu{type = 'get-response', request_id = ReqId} = Pdu, + _PduMS, _ACMData) -> + active_once(Socket), + case lists:keyfind(ReqId, 1, Reqs) of + {ReqId, Pid} -> + ?vdebug("handle_recv_pdu -> " + "~n send response to receiver ~p", [Pid]), + Pid ! {snmp_response_received, Vsn, Pdu, From}; + false -> + ?vdebug("handle_recv_pdu -> " + "~n No receiver available for response pdu", []) + end, S; -handle_recv_pdu(From, Vsn, #pdu{request_id = Rid, type = Type} = Pdu, - PduMS, ACMData, #state{master_agent = Pid} = S) - when ((Type =:= 'get-request') orelse - (Type =:= 'get-next-request') orelse - (Type =:= 'get-bulk-request')) -> - ?vtrace("handle_recv_pdu -> received get (~w)", [Type]), - Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, From, []}, - update_req_counter_incomming(S, Rid); -handle_recv_pdu(From, Vsn, Pdu, PduMS, ACMData, - #state{usock = Sock, master_agent = Pid} = S) -> +%%% XXX remove +%%% +%%% handle_recv_pdu( +%%% #state{} = S, +%%% #transport{socket = Socket} = Transport, +%%% From, Vsn, +%%% #pdu{type = 'get-response'} = Pdu, +%%% _PduMS, _ACMData) -> +%%% active_once(Socket), +%%% handle_response(S, Pdu, From, Vsn), +%%% S; +handle_recv_pdu( + #state{master_agent = Pid} = S, + #transport{} = Transport, + From, Vsn, + #pdu{type = Type} = Pdu, + PduMS, ACMData) + when Type =:= 'set-request'; + Type =:= 'get-request'; + Type =:= 'get-next-request'; + Type =:= 'get-bulk-request' -> + ?vtrace("handle_recv_pdu -> received request (~w)", [Type]), + ReqRef = make_ref(), + Extra = [{request_ref, ReqRef}], + Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, From, Extra}, + NewS = update_req_counter_incoming(S, Transport, ReqRef), + ?vdebug("handle_recv_pdu -> ~p", [NewS]), + NewS; +handle_recv_pdu( + #state{master_agent = Pid} = S, + #transport{socket = Socket}, + From, Vsn, Pdu, PduMS, ACMData) -> ?vtrace("handle_recv_pdu -> received other request", []), - active_once(Sock), + active_once(Socket), Pid ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, From, []}, S. maybe_handle_reply_pdu( - #state{filter = FilterMod, domain = Domain} = S, Vsn, - #pdu{request_id = Rid} = Pdu, + #state{filter = FilterMod, transports = Transports} = S, + #transport{} = Transport, + Vsn, + #pdu{} = Pdu, Type, ACMData, To) -> - - S1 = update_req_counter_outgoing(S, Rid), - Addresses = [fix_filter_address(Domain, To)], + %% + Addresses = [fix_filter_address(Transports, To)], case try FilterMod:accept_send_pdu(Addresses, Type) @@ -715,7 +967,8 @@ maybe_handle_reply_pdu( Class:Exception -> error_msg( "FilterMod:accept_send_pdu(~p, ~p) crashed: ~w:~w~n ~p", - [Addresses,Type,Class,Exception,erlang:get_stacktrace()]), + [Addresses, Type, Class, Exception, + erlang:get_stacktrace()]), true end of @@ -731,11 +984,16 @@ maybe_handle_reply_pdu( "FilterMod:accept_send_pdu(~p, ~p) returned: ~p", [Addresses,Type,Other]) end, - handle_reply_pdu(S1, Vsn, Pdu, Type, ACMData, To) - end, - S1. + handle_reply_pdu(S, Transport, Vsn, Pdu, Type, ACMData, To) + end. -handle_reply_pdu(#state{log = Log} = S, Vsn, Pdu, Type, ACMData, To) -> +handle_reply_pdu( + #state{log = Log} = S, + #transport{} = Transport, + Vsn, + #pdu{} = Pdu, + Type, ACMData, To) -> + %% LogF = fun(Type2, Data) -> log(Log, Type2, Data, To) @@ -744,7 +1002,15 @@ handle_reply_pdu(#state{log = Log} = S, Vsn, Pdu, Type, ACMData, To) -> ACMData, LogF)) of {ok, Packet} -> ?vinfo("time in agent: ~w mysec", [time_in_agent()]), - maybe_udp_send(S, To, Packet); + try maybe_udp_send(S, Transport, To, Packet) + catch + {Reason, Sz} -> + error_msg("Cannot send message " + "~n size: ~p" + "~n reason: ~p" + "~n pdu: ~p", + [Sz, Reason, Pdu]) + end; {discarded, Reason} -> ?vlog("handle_reply_pdu -> " "~n reply discarded for reason: ~s", @@ -758,7 +1024,7 @@ handle_reply_pdu(#state{log = Log} = S, Vsn, Pdu, Type, ACMData, To) -> maybe_handle_send_pdu( - #state{filter = FilterMod, domain = Domain} = S, + #state{filter = FilterMod, transports = Transports} = S, Vsn, Pdu, MsgData, TDomAddrSecs, From) -> ?vtrace("maybe_handle_send_pdu -> entry with~n" @@ -767,26 +1033,15 @@ maybe_handle_send_pdu( DomAddrSecs = snmpa_mpd:process_taddrs(TDomAddrSecs), AddressesToFilter = - [case Domain of - snmpUDPDomain -> - case DAS of - {{Dom, Addr}, _SecData} - when is_atom(Dom) -> % v3 - Addr; - {Dom, Addr} - when is_atom(Dom) -> % v1 & v2 - Addr - end; - _ -> - case DAS of - {{Dom, _Addr} = DomAddr, _SecData} - when is_atom(Dom) -> % v3 - DomAddr; - {Dom, _Addr} = DomAddr - when is_atom(Dom) -> % v1 & v2 - DomAddr - end - end || DAS <- DomAddrSecs], + case is_legacy_transports(Transports) of + true -> + [fix_filter_legacy_mpd_address(DAS) + || DAS <- DomAddrSecs]; + false -> + [fix_filter_mpd_address(DAS) + || DAS <- DomAddrSecs] + end, + Type = pdu_type_of(Pdu), case @@ -806,33 +1061,24 @@ maybe_handle_send_pdu( true -> handle_send_pdu(S, Vsn, Pdu, MsgData, DomAddrSecs, From); FilteredAddresses when is_list(FilteredAddresses) -> - MergedDomAddrSecs = - [DAS || - DAS <- DomAddrSecs, - lists:member( - case Domain of - snmpUDPDomain -> - case DAS of - {{Dom, Addr}, _SData} - when is_atom(Dom) -> % v3 - Addr; - {Dom, Addr} - when is_atom(Dom) -> % v1 & v2 - Addr - end; - true -> - case DAS of - {{Dom, _Addr} = DomAddr, _SData} - when is_atom(Dom) -> % v3 - DomAddr; - {Dom, _Addr} = DomAddr - when is_atom(Dom) -> % v1 & v2 - DomAddr - end - end, FilteredAddresses)], - ?vtrace("maybe_handle_send_pdu -> MergedDomAddrSecs:~n" - " ~p", [MergedDomAddrSecs]), - handle_send_pdu(S, Vsn, Pdu, MsgData, MergedDomAddrSecs, From); + FilteredDomAddrSecs = + case is_legacy_transports(Transports) of + true -> + [DAS || + DAS <- DomAddrSecs, + lists:member( + fix_filter_legacy_mpd_address(DAS), + FilteredAddresses)]; + false -> + [DAS || + DAS <- DomAddrSecs, + lists:member( + fix_filter_mpd_address(DAS), + FilteredAddresses)] + end, + ?vtrace("maybe_handle_send_pdu -> FilteredDomAddrSecs:~n" + " ~p", [FilteredDomAddrSecs]), + handle_send_pdu(S, Vsn, Pdu, MsgData, FilteredDomAddrSecs, From); Other -> error_msg( "FilterMod:accept_send_pdu(~p, ~p) returned: ~p", @@ -841,8 +1087,9 @@ maybe_handle_send_pdu( end. handle_send_pdu( - #state{note_store = NS} = S, Vsn, Pdu, MsgData, DomAddrSecs, From) -> - + #state{note_store = NS} = S, + Vsn, Pdu, MsgData, DomAddrSecs, From) -> + %% ?vtrace("handle_send_pdu -> entry with~n" " Pdu: ~p~n" " DomAddrSecs: ~p", [Pdu, DomAddrSecs]), @@ -863,23 +1110,24 @@ handle_send_pdu( case From of undefined -> S; - Pid -> + Pid when is_pid(Pid) -> ?vtrace("link to ~p and add to request list", [Pid]), link(Pid), - NReqs = snmp_misc:keyreplaceadd( - Pid, 2, S#state.reqs, {Pdu#pdu.request_id, From}), + NReqs = + snmp_misc:keyreplaceadd( + Pid, 2, S#state.reqs, {Pdu#pdu.request_id, From}), S#state{reqs = NReqs} end. handle_send_discovery( - #state{note_store = NS, - log = Log, - usock = Sock, - reqs = Reqs} = S, - #pdu{type = Type, - request_id = ReqId} = Pdu, - MsgData, To, From) -> + #state{ + note_store = NS, + log = Log, + reqs = Reqs, + transports = Transports} = S, + #pdu{type = Type, request_id = ReqId} = Pdu, + MsgData, To, From) when is_pid(From) -> ?vtrace("handle_send_discovery -> entry with" "~n Pdu: ~p" @@ -889,20 +1137,28 @@ handle_send_discovery( case (catch snmpa_mpd:generate_discovery_msg(NS, Pdu, MsgData, To)) of {ok, {Domain, Address, Packet}} -> - log(Log, Type, Packet, {Domain, Address}), - udp_send(Sock, {Domain, Address}, Packet), - ?vtrace("handle_send_discovery -> sent (~w)", [ReqId]), - NReqs = snmp_misc:keyreplaceadd(From, 2, Reqs, {ReqId, From}), - S#state{reqs = NReqs}; + case select_transport_from_domain(Domain, Transports) of + false -> + error_msg( + "Can not find transport to: ~s", + [format_address(To)]), + S; + #transport{socket = Socket} -> + log(Log, Type, Packet, {Domain, Address}), + udp_send(Socket, {Domain, Address}, Packet), + ?vtrace("handle_send_discovery -> sent (~w)", [ReqId]), + NReqs = snmp_misc:keyreplaceadd(From, 2, Reqs, {ReqId, From}), + S#state{reqs = NReqs} + end; {discarded, Reason} -> ?vlog("handle_send_discovery -> " "~n Discovery PDU ~p not sent due to ~p", [Pdu, Reason]), - ok; + S; {'EXIT', Reason} -> user_err("failed generating discovery message: " "~n PDU: ~p" "~n Reason: ~p", [Pdu, Reason]), - ok + S end. @@ -912,18 +1168,20 @@ do_handle_send_pdu(S, Trap, Addresses) -> do_handle_send_pdu(S, trappdu, Trap, Addresses). do_handle_send_pdu(S, Type, Pdu, Addresses) -> - case (catch do_handle_send_pdu1(S, Type, Addresses)) of + try do_handle_send_pdu1(S, Type, Addresses) + catch {Reason, Sz} -> - error_msg("Cannot send message " - "~n size: ~p" - "~n reason: ~p" - "~n pdu: ~p", - [Sz, Reason, Pdu]); - _ -> - ok + error_msg( + "Can not send message~n" + " size: ~p~n" + " reason: ~p~n" + " pdu: ~p", + [Sz, Reason, Pdu]) end. -do_handle_send_pdu1(S, Type, Addresses) -> +do_handle_send_pdu1( + #state{transports = Transports} = S, + Type, Addresses) -> lists:foreach( fun ({Domain, Address, Packet}) when is_binary(Packet) -> ?vdebug( @@ -931,32 +1189,55 @@ do_handle_send_pdu1(S, Type, Addresses) -> " size: ~p~n" " to: ~p", [Domain, sz(Packet), Address]), To = {Domain, Address}, - maybe_udp_send(S, To, Packet); + case select_transport_from_domain(Domain, Transports) of + false -> + error_msg( + "Can not find transport~n" + " size: ~p~n" + " to: ~s", + [sz(Packet), To]); + Transport -> + maybe_udp_send(S, Transport, To, Packet) + end; ({Domain, Address, {Packet, LogData}}) when is_binary(Packet) -> ?vdebug( "[~w] sending encrypted packet:~n" " size: ~p~n" " to: ~p", [Domain, sz(Packet), Address]), To = {Domain, Address}, - maybe_udp_send(S, To, Packet, Type, LogData) + case select_transport_from_domain(Domain, Transports) of + false -> + error_msg( + "Can not find transport~n" + " size: ~p~n" + " to: ~s", + [sz(Packet), To]); + Transport -> + maybe_udp_send(S, Transport, To, Packet, Type, LogData) + end end, Addresses). -handle_response(Vsn, Pdu, From, S) -> - case lists:keysearch(Pdu#pdu.request_id, 1, S#state.reqs) of - {value, {_, Pid}} -> - ?vdebug("handle_response -> " - "~n send response to receiver ~p", [Pid]), - Pid ! {snmp_response_received, Vsn, Pdu, From}; - _ -> - ?vdebug("handle_response -> " - "~n No receiver available for response pdu", []) - end. +%%% XXX remove +%%% +%%% handle_response( +%%% #state{reqs = Reqs} = S, Pdu#pdu{request_id = ReqId}, From, Vsn) +%%% when is_pid(From) -> +%%% case lists:keyfind(ReqId, 1, S#state.reqs) of +%%% {ReqId, Pid} -> +%%% ?vdebug("handle_response -> " +%%% "~n send response to receiver ~p", [Pid]), +%%% Pid ! {snmp_response_received, Vsn, Pdu, From}; +%%% false -> +%%% ?vdebug("handle_response -> " +%%% "~n No receiver available for response pdu", []) +%%% end. maybe_udp_send( - #state{usock = Sock, filter = FilterMod, domain = Domain}, + #state{filter = FilterMod, transports = Transports}, + #transport{socket = Socket}, To, Packet) -> - {To_1, To_2} = fix_filter_address(Domain, To), + {To_1, To_2} = fix_filter_address(Transports, To), case try FilterMod:accept_send(To_1, To_2) catch @@ -979,25 +1260,21 @@ maybe_udp_send( "FilterMod:accept_send(~p, ~p) returned: ~p", [To_1,To_2,Other]) end, - %% XXX should be some kind of lookup of domain to socket - (catch udp_send(Sock, To, Packet)) + udp_send(Socket, To, Packet) end. maybe_udp_send( - #state{ - log = Log, - usock = Sock, - filter = FilterMod, - domain = Domain}, + #state{log = Log, filter = FilterMod, transports = Transports}, + #transport{socket = Socket}, To, Packet, Type, _LogData) -> - {To_1, To_2} = fix_filter_address(Domain, To), + {To_1, To_2} = fix_filter_address(Transports, To), case try FilterMod:accept_send(To_1, To_2) catch Class:Exception -> error_msg( "FilterMod:accept_send(~p, ~p) crashed for: ~w:~w~n ~p", - [To_1,To_2,Class,Exception,erlang:get_stacktrace()]), + [To_1, To_2, Class, Exception, erlang:get_stacktrace()]), true end of @@ -1014,32 +1291,33 @@ maybe_udp_send( [To_1,To_2,Other]) end, log(Log, Type, Packet, To), - (catch udp_send(Sock, To, Packet)) + udp_send(Socket, To, Packet) end. -udp_send(UdpId, To, B) -> - %% XXX should be some kind of lookup of domain to socket - {Ip, Port} = +udp_send(Socket, To, B) -> + {IpAddr, IpPort} = case To of {Domain, Addr} when is_atom(Domain) -> Addr; {_, P} = Addr when is_integer(P) -> Addr end, - case (catch gen_udp:send(UdpId, Ip, Port, B)) of + try gen_udp:send(Socket, IpAddr, IpPort, B) of {error, emsgsize} -> %% From this message we cannot recover, so exit sending loop throw({emsgsize, sz(B)}); {error, ErrorReason} -> error_msg("[error] cannot send message " "(destination: ~p:~p, size: ~p, reason: ~p)", - [Ip, Port, sz(B), ErrorReason]); - {'EXIT', ExitReason} -> - error_msg("[exit] cannot send message " - "(destination: ~p:~p, size: ~p, reason: ~p)", - [Ip, Port, sz(B), ExitReason]); - _ -> + [IpAddr, IpPort, sz(B), ErrorReason]); + ok -> ok + catch + error:ExitReason -> + error_msg("[exit] cannot send message " + "(destination: ~p:~p, size: ~p, reason: ~p, at: ~p)", + [IpAddr, IpPort, sz(B), ExitReason, + erlang:get_stacktrace()]) end. sz(L) when is_list(L) -> length(L); @@ -1089,21 +1367,74 @@ active_once(Sock) -> inet:setopts(Sock, [{active, once}]). +select_transport_from_req_ref(_, []) -> + false; +select_transport_from_req_ref( + ReqRef, + [#transport{req_refs = ReqRefs} = Transport | Transports]) -> + case lists:member(ReqRef, ReqRefs) of + true -> + Transport; + false -> + select_transport_from_req_ref(ReqRef, Transports) + end. + +select_transport_from_domain(Domain, Transports) when is_atom(Domain) -> + Pos = #transport.domain, + case lists:keyfind(Domain, Pos, Transports) of + #transport{domain = Domain} = Transport -> + Transport; + false when Domain == snmpUDPDomain -> + lists:keyfind(transportDomainUdpIpv4, Pos, Transports); + false when Domain == transportDomainUdpIpv4 -> + lists:keyfind(snmpUDPDomain, Pos, Transports); + false -> + false + end. + +address_to_domain({Domain, _Addr}) when is_atom(Domain) -> + Domain; +address_to_domain({_Ip, Port}) when is_integer(Port) -> + snmpUDPDomain. + %% If the agent uses legacy snmpUDPDomain e.g has not set %% intAgentTransportDomain, then make sure %% snmpa_network_interface_filter gets legacy arguments %% to not break backwards compatibility. %% -fix_filter_address(snmpUDPDomain, {Domain, Addr}) - when Domain =:= snmpUDPDomain; - Domain =:= transportDomainUdpIpv4 -> - Addr; -fix_filter_address(_AgentDomain, {Domain, _} = Address) - when is_atom(Domain) -> - Address; -fix_filter_address(snmpUDPDomain, {_, Port} = Addr) - when is_integer(Port) -> - Addr. +fix_filter_address(Transports, Address) -> + case is_legacy_transports(Transports) of + true -> + case Address of + {Domain, Addr} when is_atom(Domain) -> + Addr; + {_, IpPort} = Addr when is_integer(IpPort) -> + Addr + end; + false -> + Address + end. + +is_legacy_transports([#transport{domain = snmpUDPDomain}]) -> + true; +is_legacy_transports([#transport{} | _]) -> + false. + +fix_filter_legacy_mpd_address(Domain_Address_SecData) -> + case Domain_Address_SecData of + {{Domain, Addr}, _SecData} when is_atom(Domain) -> % v3 + Addr; + {Domain, Addr} when is_atom(Domain) -> % v1 & v2 + Addr + end. + +fix_filter_mpd_address(Domain_Address_SecData) -> + case Domain_Address_SecData of + {{Domain, _Addr} = Address, _SecData} when is_atom(Domain) -> % v3 + Address; + {Domain, _Addr} = Address when is_atom(Domain) -> % v1 & v2 + Address + end. %%%----------------------------------------------------------------- @@ -1261,6 +1592,35 @@ get_counters([Counter|Counters], Acc) -> %% ---------------------------------------------------------------- +socket_opts(Domain, {IpAddr, IpPort}, Opts) -> + [IpPort, % Picked off at socket open, separate argument + binary, + snmp_conf:tdomain_to_family(Domain) + | case get_bind_to_ip_address(Opts) of + true -> + [{ip, IpAddr}]; + _ -> + [] + end ++ + case get_no_reuse_address(Opts) of + false -> + [{reuseaddr, true}]; + _ -> + [] + end ++ + case get_recbuf(Opts) of + use_default -> + []; + Sz -> + [{recbuf, Sz}] + end ++ + case get_sndbuf(Opts) of + use_default -> + []; + Sz -> + [{sndbuf, Sz}] + end]. + ip_opt_bind_to_ip_address(Opts, Ip) -> case get_bind_to_ip_address(Opts) of true -> @@ -1378,14 +1738,14 @@ call(Pid, Req) -> %% ---------------------------------------------------------------- -get_info(#state{usock = Id, reqs = Reqs}) -> +get_info(#state{transports = Transports, reqs = Reqs}) -> ProcSize = proc_mem(self()), - PortInfo = get_port_info(Id), Counters = get_counters(), - [{reqs, Reqs}, - {counters, Counters}, - {process_memory, ProcSize}, - {port_info, PortInfo}]. + [{reqs, Reqs}, + {counters, Counters}, + {process_memory, ProcSize} + | [{port_info, get_port_info(Socket)} + || #transport{socket = Socket} <- Transports]]. proc_mem(P) when is_pid(P) -> case (catch erlang:process_info(P, memory)) of diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index ac0739860b..40956c40fb 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -790,42 +790,45 @@ send_trap_pdus([], ContextName, {TrapRec, Vbs}, send_v1_trap(_TrapRec, [], _Vbs, _ExtraInfo, _NetIf, _SysUpTime) -> ok; -send_v1_trap(#trap{enterpriseoid = Enter, specificcode = Spec}, - V1Res, Vbs, ExtraInfo, NetIf, SysUpTime) -> +send_v1_trap( + #trap{enterpriseoid = Enter, specificcode = Spec}, + V1Res, Vbs, ExtraInfo, NetIf, SysUpTime) -> ?vdebug("prepare to send v1 trap " "~n '~p'" "~n with" "~n ~p" "~n to" "~n ~p", [Enter, Spec, V1Res]), - AgentDomain = - case snmp_framework_mib:intAgentTransportDomain(get) of - {value, AD} -> - AD; - genErr -> - snmp_target_mib:default_domain() - end, - case AgentDomain of - snmpUDPDomain -> - {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), - TrapPdu = make_v1_trap_pdu(Enter, Spec, Vbs, SysUpTime, AgentIp), - AddrCommunities = mk_addr_communities(V1Res), - lists:foreach( - fun ({Community, Addrs}) -> - ?vtrace("send v1 trap pdu to ~p",[Addrs]), - NetIf ! {send_pdu, 'version-1', TrapPdu, - {community, Community}, Addrs, ExtraInfo} - end, AddrCommunities); - _ -> - ?vtrace( - "snmpa_trap: can not send v1 trap with domain: ~w", - [AgentDomain]), - user_err( - "snmpa_trap: can not send v1 trap with domain: ~w", - [AgentDomain]) - end; -send_v1_trap(#notification{oid = Oid}, V1Res, Vbs, ExtraInfo, NetIf, - SysUpTime) -> + do_send_v1_trap(Enter, Spec, V1Res, Vbs, ExtraInfo, NetIf, SysUpTime); +%%% AgentDomain = +%%% case snmp_framework_mib:intAgentTransportDomain(get) of +%%% {value, AD} -> +%%% AD; +%%% genErr -> +%%% snmp_target_mib:default_domain() +%%% end, +%%% case AgentDomain of +%%% snmpUDPDomain -> +%%% {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), +%%% TrapPdu = make_v1_trap_pdu(Enter, Spec, Vbs, SysUpTime, AgentIp), +%%% AddrCommunities = mk_addr_communities(V1Res), +%%% lists:foreach( +%%% fun ({Community, Addrs}) -> +%%% ?vtrace("send v1 trap pdu to ~p",[Addrs]), +%%% NetIf ! {send_pdu, 'version-1', TrapPdu, +%%% {community, Community}, Addrs, ExtraInfo} +%%% end, AddrCommunities); +%%% _ -> +%%% ?vtrace( +%%% "snmpa_trap: can not send v1 trap with domain: ~w", +%%% [AgentDomain]), +%%% user_err( +%%% "snmpa_trap: can not send v1 trap with domain: ~w", +%%% [AgentDomain]) +%%% end; +send_v1_trap( + #notification{oid = Oid}, + V1Res, Vbs, ExtraInfo, NetIf, SysUpTime) -> %% Use alg. in rfc2089 to map a v2 trap to a v1 trap % delete Counter64 objects from vbs ?vdebug("prepare to send v1 trap '~p'",[Oid]), @@ -842,32 +845,64 @@ send_v1_trap(#notification{oid = Oid}, V1Res, Vbs, ExtraInfo, NetIf, {lists:reverse(First),Last} end end, - AgentDomain = - case snmp_framework_mib:intAgentTransportDomain(get) of - {value, AD} -> - AD; - genErr -> - snmp_target_mib:default_domain() + do_send_v1_trap(Enter, Spec, V1Res, NVbs, ExtraInfo, NetIf, SysUpTime). + +do_send_v1_trap(Enter, Spec, V1Res, NVbs, ExtraInfo, NetIf, SysUpTime) -> + {value, Transports} = snmp_framework_mib:intAgentTransports(get), + {_Domain, {AgentIp, _AgentPort}} = + case lists:keyfind(snmpUDPDomain, 1, Transports) of + false -> + case lists:keyfind(transportDomainUdpIpv4, 1, Transports) of + false -> + ?vtrace( + "snmpa_trap: can not send v1 trap " + "without IPv4 domain: ~p", + [Transports]), + user_err( + "snmpa_trap: can not send v1 trap " + "without IPv4 domain: ~p", + [Transports]); + DomainAddr -> + DomainAddr + end; + DomainAddr -> + DomainAddr end, - case AgentDomain of - snmpUDPDomain -> - {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), - TrapPdu = make_v1_trap_pdu(Enter, Spec, NVbs, SysUpTime, AgentIp), - AddrCommunities = mk_addr_communities(V1Res), - lists:foreach( - fun ({Community, Addrs}) -> - ?vtrace("send v1 trap to ~p",[Addrs]), - NetIf ! {send_pdu, 'version-1', TrapPdu, - {community, Community}, Addrs, ExtraInfo} - end, AddrCommunities); - _ -> - ?vtrace( - "snmpa_trap: can not send v1 trap with domain: ~w", - [AgentDomain]), - user_err( - "snmpa_trap: can not send v1 trap with domain: ~w", - [AgentDomain]) - end. + TrapPdu = make_v1_trap_pdu(Enter, Spec, NVbs, SysUpTime, AgentIp), + AddrCommunities = mk_addr_communities(V1Res), + lists:foreach( + fun ({Community, Addrs}) -> + ?vtrace("send v1 trap to ~p",[Addrs]), + NetIf ! {send_pdu, 'version-1', TrapPdu, + {community, Community}, Addrs, ExtraInfo} + end, AddrCommunities). + +%%% AgentDomain = +%%% case snmp_framework_mib:intAgentTransportDomain(get) of +%%% {value, AD} -> +%%% AD; +%%% genErr -> +%%% snmp_target_mib:default_domain() +%%% end, +%%% case AgentDomain of +%%% snmpUDPDomain -> +%%% {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), +%%% TrapPdu = make_v1_trap_pdu(Enter, Spec, NVbs, SysUpTime, AgentIp), +%%% AddrCommunities = mk_addr_communities(V1Res), +%%% lists:foreach( +%%% fun ({Community, Addrs}) -> +%%% ?vtrace("send v1 trap to ~p",[Addrs]), +%%% NetIf ! {send_pdu, 'version-1', TrapPdu, +%%% {community, Community}, Addrs, ExtraInfo} +%%% end, AddrCommunities); +%%% _ -> +%%% ?vtrace( +%%% "snmpa_trap: can not send v1 trap with domain: ~w", +%%% [AgentDomain]), +%%% user_err( +%%% "snmpa_trap: can not send v1 trap with domain: ~w", +%%% [AgentDomain]) +%%% end. send_v2_trap(_TrapRec, [], _Vbs, _Recv, _ExtraInfo, _NetIf, _SysUpTime) -> ok; diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 82cbf42e35..f4483995cb 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -223,13 +223,17 @@ read_check(_, _, [], _, Res) -> lists:reverse(Res); read_check(File, Check, [{StartLine, Row, EndLine}|Lines], State, Res) -> try Check(Row, State) of + {Rows, NewState} when is_list(Rows) -> + ?vtrace("read_check -> ok:~n" + " Rows: ~p~n", [Rows]), + read_check(File, Check, Lines, NewState, Rows ++ Res); {ok, NewState} -> ?vtrace("read_check -> ok", []), - read_check(File, Check, Lines, NewState, [Row|Res]); + read_check(File, Check, Lines, NewState, [Row | Res]); {{ok, NewRow}, NewState} -> ?vtrace("read_check -> ok:~n" " NewRow: ~p~n", [NewRow]), - read_check(File, Check, Lines, NewState, [NewRow|Res]) + read_check(File, Check, Lines, NewState, [NewRow | Res]) catch {error, Reason} -> ?vtrace("read_check -> error:~n" diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 38e248c326..91240082f1 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -33,7 +33,7 @@ -export([write_agent_snmp_files/7, write_agent_snmp_files/12, write_agent_snmp_files/6, write_agent_snmp_files/11, - write_agent_snmp_conf/5, + write_agent_snmp_conf/4, write_agent_snmp_conf/5, write_agent_snmp_context_conf/1, write_agent_snmp_community_conf/1, write_agent_snmp_standard_conf/2, @@ -1650,6 +1650,12 @@ write_agent_snmp_files( %% ------ [agent] agent.conf ------ %% +write_agent_snmp_conf(Dir, Transports, EngineID, MMS) -> + Conf = + [{intAgentTransports, Transports}, + {snmpEngineID, EngineID}, + {snmpEngineMaxMessageSize, MMS}], + do_write_agent_snmp_conf(Dir, Conf). write_agent_snmp_conf(Dir, Domain, AgentAddr, EngineID, MMS) when is_atom(Domain) -> @@ -2513,6 +2519,8 @@ write_config_file(Dir, FileName, Order, Check, Write, Entries) lists:foldl( fun (Entry, State) -> case Check(Entry, State) of + {Ok, NewState} when is_list(Ok) -> + NewState; {ok, NewState} -> NewState; {{ok, _}, NewState} -> @@ -2709,6 +2717,8 @@ verify_lines([], _, _, Acc) -> verify_lines( [{StartLine, Term, EndLine}|Lines], Check, State, Acc) -> try Check(Term, State) of + {Terms, NewState} when is_list(Terms) -> + verify_lines(Lines, Check, NewState, Terms ++ Acc); {ok, NewState} -> verify_lines(Lines, Check, NewState, [Term|Acc]); {{ok, NewTerm}, NewState} -> diff --git a/lib/snmp/test/klas3.erl b/lib/snmp/test/klas3.erl index 4c7c03e2ca..4cbd852b2d 100644 --- a/lib/snmp/test/klas3.erl +++ b/lib/snmp/test/klas3.erl @@ -75,6 +75,7 @@ fname(get) -> end, case snmpa:current_net_if_data() of {value, []} -> ok; + {value, [{request_ref, R}]} when is_reference(R) -> ok; {value, _} -> throw("bad_nil"); _ -> throw("bad_nid") end, -- cgit v1.2.3 From 09451fa20a51ca198e6043505b033a9d24b497f6 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 30 Jun 2014 17:22:13 +0200 Subject: Silence logging from agent net_if at shutdown --- lib/snmp/src/agent/snmpa_net_if.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index f5fd377341..66964faed7 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -153,11 +153,12 @@ init(Prio, NoteStore, MasterAgent, Parent, Opts) -> {ok, State} -> proc_lib:init_ack({ok, self()}), try loop(State) - catch C:E -> - S = erlang:get_stacktrace(), + catch + C:E when C =/= exit, E =/= shutdown -> Fmt = "loop/1 EXCEPTION ~w:~w~n" " ~p", + S = erlang:get_stacktrace(), case C of exit -> %% Externally killed, root cause is elsewhere -- cgit v1.2.3 From d38674e8dd8224da8a66d77ca4f5a8073e01f794 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 1 Jul 2014 10:17:50 +0200 Subject: Add dual_ip tests in snmp_to_snmpnet_SUITE --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 70 ++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 18 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index e8dcffd361..3271b98ec3 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -68,12 +68,16 @@ init_per_group(ipv6, Config) -> ok -> Dir = ?config(priv_dir, Config), Domain = transportDomainUdpIpv6, + AgentPort = ?config(agent_port, Config), + ManagerPort = ?config(manager_port, Config), {ok, Host} = inet:gethostname(), {ok, IpAddr} = inet:getaddr(Host, inet6), + Transports = [{Domain, {IpAddr, AgentPort}}], + TrapAddr = {IpAddr, ManagerPort}, Versions = [v2], - agent_config(Dir, Domain, IpAddr, IpAddr, ?config(agent_port, Config), Versions), - [{host, Host}, - {snmp_versions, Versions}, {ip_version, ipv6} | Config]; + agent_config(Dir, Transports, Domain, TrapAddr, Versions), + [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv6} + | Config]; _ -> {skip, "Host does not support IPV6"} end; @@ -81,13 +85,36 @@ init_per_group(ipv6, Config) -> init_per_group(ipv4, Config) -> Dir = ?config(priv_dir, Config), Domain = transportDomainUdpIpv4, + AgentPort = ?config(agent_port, Config), + ManagerPort = ?config(manager_port, Config), {ok, Host} = inet:gethostname(), {ok, IpAddr} = inet:getaddr(Host, inet), + Transports = [{Domain, {IpAddr, AgentPort}}], + TrapAddr = {IpAddr, ManagerPort}, Versions = [v2], - agent_config(Dir, Domain, IpAddr, {IpAddr, ?config(manager_port, Config)}, - ?config(agent_port, Config), Versions), - [{host, Host}, {snmp_versions, Versions}, - {ip_version, ipv4} | Config]; + agent_config(Dir, Transports, Domain, TrapAddr, Versions), + [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv4} + | Config]; + +init_per_group(dual_ip, Config) -> + case ct:require(ipv6_hosts) of + ok -> + Dir = ?config(priv_dir, Config), + {ok, Host} = inet:gethostname(), + {ok, IPv4Addr} = inet:getaddr(Host, inet), + {ok, IPv6Addr} = inet:getaddr(Host, inet6), + Domain = snmpUDPDomain, + Transports = + [{Domain, {IPv4Addr, ?AGENT_PORT}}, + {transportDomainUdpIpv6, {IPv6Addr, ?AGENT_PORT}}], + TrapAddr = {IPv4Addr, 0}, + Versions = [v2], + agent_config(Dir, Transports, Domain, TrapAddr, Versions), + [{host, Host}, {port, ?AGENT_PORT}, {snmp_versions, Versions} + | Config]; + _ -> + {skip, "Host does not support IPV6"} + end; init_per_group(get, Config) -> %% From Ubuntu package snmp @@ -149,14 +176,16 @@ erlang_agent_dual_ip_get() -> [{doc,"Test that we can access erlang snmp agent from both " "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. erlang_agent_dual_ip_get(Config) when is_list(Config) -> - erlang_agent_netsnmp_get([{ip_version, ipv4}]), - erlang_agent_netsnmp_get([{ip_version, ipv6}]). + erlang_agent_netsnmp_get([{ip_version, ipv4} | Config]), + erlang_agent_netsnmp_get([{ip_version, ipv6} | Config]). %%-------------------------------------------------------------------- erlang_agent_netsnmp_inform(Config) when is_list(Config) -> Host = ?config(host, Config), IPVersion = ?config(ip_version, Config), DataDir = ?config(data_dir, Config), - ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, "TestTrapv2")), + ok = + snmpa:load_mib( + snmp_master_agent, filename:join(DataDir, "TestTrapv2")), Cmd = "snmptrapd -L o -M " ++ DataDir ++ " --disableAuthorization=yes" ++ @@ -173,7 +202,7 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> end, receive {snmp_notification, erlang_agent_test, {got_response, Address}} -> - ct:pal("Got respons from: ~p~n", [Address]), + ct:pal("Got response from: ~p~n", [Address]), ok; {snmp_notification, erlang_agent_test, {no_response, _} = NoResponse} -> @@ -185,6 +214,7 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> %%-------------------------------------------------------------------- net_snmp(Cmd, Expect) -> NetSnmpPort = open_port({spawn, Cmd}, [stderr_to_stdout]), + ct:pal("net_snmp started: ~s~n", [Cmd]), receive {NetSnmpPort, {data, Expect}} -> ok; @@ -195,7 +225,9 @@ net_snmp(Cmd, Expect) -> catch erlang:port_close(NetSnmpPort). net_snmp_trapd(Cmd) -> - open_port({spawn, Cmd}, [stderr_to_stdout]). + NetSnmpTrapdPort = open_port({spawn, Cmd}, [stderr_to_stdout]), + ct:pal("net_snmp_trapd started: ~s~n", [Cmd]), + NetSnmpTrapdPort. net_snmp_log(NetSnmpPort) -> receive @@ -234,16 +266,18 @@ oid_str([], Acc) -> oid_str([Int | Rest], Acc) -> oid_str(Rest, Acc ++ "." ++ integer_to_list(Int)). -agent_config(Dir, Domain, IpA, IpM, Port, Versions) -> +agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> EngineID = ?AGENT_ENGIN_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, - ok = snmp_config:write_agent_snmp_conf(Dir, Domain, {IpA, Port}, - EngineID, MMS), + ok = snmp_config:write_agent_snmp_conf(Dir, Transports, EngineID, MMS), ok = snmp_config:write_agent_snmp_context_conf(Dir), ok = snmp_config:write_agent_snmp_community_conf(Dir), - ok = snmp_config:write_agent_snmp_standard_conf(Dir, "snmp_to_snmpnet_SUITE"), - ok = snmp_config:write_agent_snmp_target_addr_conf(Dir, Domain, - IpM, Versions), + ok = + snmp_config:write_agent_snmp_standard_conf( + Dir, "snmp_to_snmpnet_SUITE"), + ok = + snmp_config:write_agent_snmp_target_addr_conf( + Dir, TargetDomain, TargetAddr, Versions), ok = snmp_config:write_agent_snmp_target_params_conf(Dir, Versions), ok = snmp_config:write_agent_snmp_notify_conf(Dir, inform), ok = snmp_config:write_agent_snmp_vacm_conf(Dir, Versions, none). -- cgit v1.2.3 From 81d2a6e1b13e944893377d93505523b8e7995e53 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 2 Jul 2014 15:38:01 +0200 Subject: Remove commented out code --- lib/snmp/src/agent/snmp_framework_mib.erl | 23 ---- lib/snmp/src/agent/snmpa_net_if.erl | 197 ++---------------------------- lib/snmp/src/agent/snmpa_trap.erl | 53 -------- 3 files changed, 9 insertions(+), 264 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 3b33cae3ec..922215ff00 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -138,8 +138,6 @@ read_agent(Dir) -> end, Mand = [{intAgentTransports, mandatory}, -%%% {intAgentIpAddress, mandatory}, -%%% {intAgentUDPPort, mandatory}, {snmpEngineMaxMessageSize, mandatory}, {snmpEngineID, mandatory}], {ok, Conf} = snmp_conf:check_mandatory(Conf0, Mand), @@ -227,27 +225,6 @@ check_agent({intAgentTransports = Tag, Transports}, {_, Port} = State) -> check_agent(Entry, State) -> {check_agent(Entry), State}. -%%% XXX remove -%%% -%%% check_agent({intAgentTransportDomain, D}, _Domain) -> -%%% {snmp_conf:check_domain(D), D}; -%%% check_agent({intAgentIpAddress = Tag, Value}, D) -> -%%% Domain = -%%% case D of -%%% undefined -> -%%% snmp_target_mib:default_domain(); -%%% _ -> -%%% D -%%% end, -%%% {case snmp_conf:check_ip(Domain, Value) of -%%% ok -> -%%% ok; -%%% {ok, FixedIp} -> -%%% {ok, {Tag, FixedIp}} -%%% end, Domain}; -%%% check_agent(Entry, Domain) -> -%%% {check_agent(Entry), Domain}. - %% This one is kept for backwards compatibility check_agent({intAgentMaxPacketSize, Value}) -> snmp_conf:check_packet_size(Value); diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 66964faed7..8f6706166b 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -117,24 +117,6 @@ get_transports() -> {value, Transports} = snmp_framework_mib:intAgentTransports(get), Transports. -%%% XXX remove -%%% -%%% get_ip_port() -> -%%% {value, UDPPort} = snmp_framework_mib:intAgentUDPPort(get), -%%% UDPPort. -%%% -%%% get_address() -> -%%% {value, IPAddress} = snmp_framework_mib:intAgentIpAddress(get), -%%% IPAddress. -%%% -%%% get_domain() -> -%%% case snmp_framework_mib:intAgentTransportDomain(get) of -%%% {value, Domain} -> -%%% Domain; -%%% genErr -> -%%% snmpUDPDomain -%%% end. - filter_reset(Pid) -> Pid ! filter_reset. @@ -185,16 +167,6 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> put(verbosity,get_verbosity(Opts)), ?vlog("starting",[]), -%%% XXX remove -%%% -%%% %% -- Port and address -- -%%% Domain = get_domain(), -%%% ?vdebug("domain: ~w",[Domain]), -%%% UDPPort = get_ip_port(), -%%% ?vdebug("port: ~w",[UDPPort]), -%%% IPAddress = get_address(), -%%% ?vdebug("addr: ~w",[IPAddress]), - %% -- Versions -- Vsns = get_vsns(Opts), ?vdebug("vsns: ~w",[Vsns]), @@ -245,38 +217,6 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) -> {error, Error} end. -%%% XXX remove -%%% -%%% %% -- Socket -- -%%% IPOpts1 = ip_opt_bind_to_ip_address(Opts, IPAddress), -%%% IPOpts2 = ip_opt_no_reuse_address(Opts), -%%% IPOpts3 = ip_opt_recbuf(Opts), -%%% IPOpts4 = ip_opt_sndbuf(Opts), -%%% IPOpts = -%%% [binary, snmp_conf:tdomain_to_family(Domain) -%%% | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4], -%%% case gen_udp_open(UDPPort, IPOpts) of -%%% {ok, Sock} -> -%%% MpdState = snmpa_mpd:init(Vsns), -%%% init_counters(), -%%% active_once(Sock), -%%% S = #state{parent = Parent, -%%% note_store = NoteStore, -%%% master_agent = MasterAgent, -%%% mpd_state = MpdState, -%%% usock = Sock, -%%% usock_opts = IPOpts, -%%% log = Log, -%%% limit = Limit, -%%% filter = FilterMod, -%%% domain = Domain}, -%%% ?vdebug("started with MpdState: ~p", [MpdState]), -%%% {ok, S}; -%%% {error, Reason} -> -%%% ?vinfo("Failed to open UDP socket: ~p", [Reason]), -%%% {error, {udp_open, UDPPort, Reason}} -%%% end. - create_log() -> case ets:lookup(snmp_agent_table, audit_trail_log) of @@ -664,53 +604,13 @@ update_req_counter_incoming( S end. -update_transport_req_refs( - #state{transports = Transports} = S, - #transport{socket = Socket} = T, - ReqRefs) -> - S#state{ - transports = - lists:keyreplace( - Socket, #transport.socket, Transports, - T#transport{req_refs = ReqRefs})}. - -%%% XXX remove -%%% -%%% update_req_counter_incoming(#state{limit = infinity, usock = Sock} = S, _) -> -%%% active_once(Sock), %% No limit so activate directly -%%% S; -%%% update_req_counter_incoming(#state{limit = Limit, -%%% rcnt = RCnt, -%%% usock = Sock} = S, Rid) -%%% when length(RCnt) + 1 >= Limit -> -%%% %% Ok, one more and we are at the limit. -%%% %% Just make sure we are not already processing this one... -%%% case lists:member(Rid, RCnt) of -%%% false -> -%%% %% We are at the limit, do _not_ activate socket -%%% S#state{rcnt = [Rid|RCnt]}; -%%% true -> -%%% active_once(Sock), -%%% S -%%% end; -%%% update_req_counter_incoming(#state{rcnt = RCnt, -%%% usock = Sock} = S, Rid) -> -%%% active_once(Sock), -%%% case lists:member(Rid, RCnt) of -%%% false -> -%%% S#state{rcnt = [Rid|RCnt]}; -%%% true -> -%%% S -%%% end. - - update_req_counter_outgoing( #state{limit = infinity} = S, _Transport, _ReqRef) -> %% Already activated (in the incoming function) S; update_req_counter_outgoing( - #state{limit = Limit, transports = Transports} = S, + #state{limit = Limit} = S, #transport{socket = Socket, req_refs = ReqRefs} = Transport, ReqRef) -> LengthReqRefs = length(ReqRefs), @@ -725,39 +625,18 @@ update_req_counter_outgoing( "passed below limit: activate", []), active_once(Socket) end, + update_transport_req_refs(S, Transport, NewReqRefs). + +update_transport_req_refs( + #state{transports = Transports} = S, + #transport{socket = Socket} = T, + ReqRefs) -> S#state{ transports = - snmp_misc:keyreplace( + lists:keyreplace( Socket, #transport.socket, Transports, - Transport#transport{req_refs = NewReqRefs})}. + T#transport{req_refs = ReqRefs})}. -%%% XXX remove -%%% -%%% update_req_counter_outgoing( -%%% #state{limit = Limit, -%%% rcnt = RCnt, -%%% usock = Sock} = S, Rid) -%%% when length(RCnt) >= Limit -> -%%% ?vtrace("handle_req_counter_outgoing(~w) -> entry with" -%%% "~n Rid: ~w" -%%% "~n length(RCnt): ~w", [Limit, Rid, length(RCnt)]), -%%% case lists:delete(Rid, RCnt) of -%%% NewRCnt when length(NewRCnt) < Limit -> -%%% ?vtrace("update_req_counter_outgoing -> " -%%% "passed below limit: activate", []), -%%% active_once(Sock), -%%% S#state{rcnt = NewRCnt}; -%%% _ -> -%%% S -%%% end; -%%% update_req_counter_outgoing(#state{limit = Limit, rcnt = RCnt} = S, -%%% Rid) -> -%%% ?vtrace("handle_req_counter_outgoing(~w) -> entry with" -%%% "~n Rid: ~w" -%%% "~n length(RCnt): ~w", [Limit, Rid, length(RCnt)]), -%%% NewRCnt = lists:delete(Rid, RCnt), -%%% S#state{rcnt = NewRCnt}. - maybe_handle_recv( #state{filter = FilterMod} = S, @@ -915,17 +794,6 @@ handle_recv_pdu( "~n No receiver available for response pdu", []) end, S; -%%% XXX remove -%%% -%%% handle_recv_pdu( -%%% #state{} = S, -%%% #transport{socket = Socket} = Transport, -%%% From, Vsn, -%%% #pdu{type = 'get-response'} = Pdu, -%%% _PduMS, _ACMData) -> -%%% active_once(Socket), -%%% handle_response(S, Pdu, From, Vsn), -%%% S; handle_recv_pdu( #state{master_agent = Pid} = S, #transport{} = Transport, @@ -1219,21 +1087,6 @@ do_handle_send_pdu1( end, Addresses). -%%% XXX remove -%%% -%%% handle_response( -%%% #state{reqs = Reqs} = S, Pdu#pdu{request_id = ReqId}, From, Vsn) -%%% when is_pid(From) -> -%%% case lists:keyfind(ReqId, 1, S#state.reqs) of -%%% {ReqId, Pid} -> -%%% ?vdebug("handle_response -> " -%%% "~n send response to receiver ~p", [Pid]), -%%% Pid ! {snmp_response_received, Vsn, Pdu, From}; -%%% false -> -%%% ?vdebug("handle_response -> " -%%% "~n No receiver available for response pdu", []) -%%% end. - maybe_udp_send( #state{filter = FilterMod, transports = Transports}, #transport{socket = Socket}, @@ -1622,38 +1475,6 @@ socket_opts(Domain, {IpAddr, IpPort}, Opts) -> [{sndbuf, Sz}] end]. -ip_opt_bind_to_ip_address(Opts, Ip) -> - case get_bind_to_ip_address(Opts) of - true -> - [{ip, Ip}]; - _ -> - [] - end. - -ip_opt_no_reuse_address(Opts) -> - case get_no_reuse_address(Opts) of - false -> - [{reuseaddr, true}]; - _ -> - [] - end. - -ip_opt_recbuf(Opts) -> - case get_recbuf(Opts) of - use_default -> - []; - Sz -> - [{recbuf, Sz}] - end. - -ip_opt_sndbuf(Opts) -> - case get_sndbuf(Opts) of - use_default -> - []; - Sz -> - [{sndbuf, Sz}] - end. - %% ---------------------------------------------------------------- diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index 40956c40fb..a79b150f57 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -800,32 +800,6 @@ send_v1_trap( "~n to" "~n ~p", [Enter, Spec, V1Res]), do_send_v1_trap(Enter, Spec, V1Res, Vbs, ExtraInfo, NetIf, SysUpTime); -%%% AgentDomain = -%%% case snmp_framework_mib:intAgentTransportDomain(get) of -%%% {value, AD} -> -%%% AD; -%%% genErr -> -%%% snmp_target_mib:default_domain() -%%% end, -%%% case AgentDomain of -%%% snmpUDPDomain -> -%%% {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), -%%% TrapPdu = make_v1_trap_pdu(Enter, Spec, Vbs, SysUpTime, AgentIp), -%%% AddrCommunities = mk_addr_communities(V1Res), -%%% lists:foreach( -%%% fun ({Community, Addrs}) -> -%%% ?vtrace("send v1 trap pdu to ~p",[Addrs]), -%%% NetIf ! {send_pdu, 'version-1', TrapPdu, -%%% {community, Community}, Addrs, ExtraInfo} -%%% end, AddrCommunities); -%%% _ -> -%%% ?vtrace( -%%% "snmpa_trap: can not send v1 trap with domain: ~w", -%%% [AgentDomain]), -%%% user_err( -%%% "snmpa_trap: can not send v1 trap with domain: ~w", -%%% [AgentDomain]) -%%% end; send_v1_trap( #notification{oid = Oid}, V1Res, Vbs, ExtraInfo, NetIf, SysUpTime) -> @@ -877,33 +851,6 @@ do_send_v1_trap(Enter, Spec, V1Res, NVbs, ExtraInfo, NetIf, SysUpTime) -> {community, Community}, Addrs, ExtraInfo} end, AddrCommunities). -%%% AgentDomain = -%%% case snmp_framework_mib:intAgentTransportDomain(get) of -%%% {value, AD} -> -%%% AD; -%%% genErr -> -%%% snmp_target_mib:default_domain() -%%% end, -%%% case AgentDomain of -%%% snmpUDPDomain -> -%%% {value, AgentIp} = snmp_framework_mib:intAgentIpAddress(get), -%%% TrapPdu = make_v1_trap_pdu(Enter, Spec, NVbs, SysUpTime, AgentIp), -%%% AddrCommunities = mk_addr_communities(V1Res), -%%% lists:foreach( -%%% fun ({Community, Addrs}) -> -%%% ?vtrace("send v1 trap to ~p",[Addrs]), -%%% NetIf ! {send_pdu, 'version-1', TrapPdu, -%%% {community, Community}, Addrs, ExtraInfo} -%%% end, AddrCommunities); -%%% _ -> -%%% ?vtrace( -%%% "snmpa_trap: can not send v1 trap with domain: ~w", -%%% [AgentDomain]), -%%% user_err( -%%% "snmpa_trap: can not send v1 trap with domain: ~w", -%%% [AgentDomain]) -%%% end. - send_v2_trap(_TrapRec, [], _Vbs, _Recv, _ExtraInfo, _NetIf, _SysUpTime) -> ok; send_v2_trap(TrapRec, V2Res, Vbs, Recv, ExtraInfo, NetIf, SysUpTime) -> -- cgit v1.2.3 From 1e67db678ea40e4b8a125da425c86fdfe7f1b986 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 2 Jul 2014 15:37:41 +0200 Subject: Use {ipv6_v6only, true} --- lib/snmp/src/agent/snmpa_net_if.erl | 11 ++++++++--- lib/snmp/src/app/snmp.appup.src | 4 ++++ lib/snmp/vsn.mk | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 8f6706166b..389c26834d 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -1448,9 +1448,14 @@ get_counters([Counter|Counters], Acc) -> socket_opts(Domain, {IpAddr, IpPort}, Opts) -> [IpPort, % Picked off at socket open, separate argument - binary, - snmp_conf:tdomain_to_family(Domain) - | case get_bind_to_ip_address(Opts) of + binary + | case snmp_conf:tdomain_to_family(Domain) of + inet6 = Family -> + [Family, {ipv6_v6only, true}]; + Family -> + [Family] + end ++ + case get_bind_to_ip_address(Opts) of true -> [{ip, IpAddr}]; _ -> diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index babc33e6a5..ae79e3c1d1 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -28,6 +28,8 @@ %% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} %% {add_module, snmpm_net_if_mt} [ + {"4.25.1", [{restart_application, snmp}]}, + {"4.25.0.1", [{restart_application, snmp}]}, {"4.25", [{restart_application, snmp}]}, {"4.24.2", [{restart_application, snmp}]}, {"4.24.1", [{restart_application, snmp}]}, @@ -40,6 +42,8 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"4.25.1", [{restart_application, snmp}]}, + {"4.25.0.1", [{restart_application, snmp}]}, {"4.25", [{restart_application, snmp}]}, {"4.24.2", [{restart_application, snmp}]}, {"4.24.1", [{restart_application, snmp}]}, diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 533e313bdb..fd10244386 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 4.25.0.1 +SNMP_VSN = 5.0 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 7e775edac0a5fa736046940d6b1776e238978804 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 3 Jul 2014 18:07:30 +0200 Subject: Improve dual stack test suite --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 261 ++++++++++++++------- .../snmp_to_snmpnet_SUITE_data/start_stop_wrapper | 47 ++++ 2 files changed, 229 insertions(+), 79 deletions(-) create mode 100755 lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 3271b98ec3..fa92beb6b1 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -30,7 +30,7 @@ -define(AGENT_PORT, 4000). -define(MANAGER_PORT, 8989). -define(DEFAULT_MAX_MESSAGE_SIZE, 484). --define(SYS_DESC, "iso.3.6.1.2.1.1.1.0 = STRING: \"Erlang SNMP agent\"\n"). +-define(SYS_DESC, <<"iso.3.6.1.2.1.1.1.0 = STRING: \"Erlang SNMP agent\"">>). %%-------------------------------------------------------------------- %% Common Test interface functions ----------------------------------- @@ -97,23 +97,30 @@ init_per_group(ipv4, Config) -> | Config]; init_per_group(dual_ip, Config) -> - case ct:require(ipv6_hosts) of - ok -> - Dir = ?config(priv_dir, Config), - {ok, Host} = inet:gethostname(), - {ok, IPv4Addr} = inet:getaddr(Host, inet), - {ok, IPv6Addr} = inet:getaddr(Host, inet6), - Domain = snmpUDPDomain, - Transports = - [{Domain, {IPv4Addr, ?AGENT_PORT}}, - {transportDomainUdpIpv6, {IPv6Addr, ?AGENT_PORT}}], - TrapAddr = {IPv4Addr, 0}, - Versions = [v2], - agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{host, Host}, {port, ?AGENT_PORT}, {snmp_versions, Versions} - | Config]; - _ -> - {skip, "Host does not support IPV6"} + case os:find_executable("snmpget") of + false -> + {skip, "snmpget not found"}; + Path -> + case ct:require(ipv6_hosts) of + ok -> + Dir = ?config(priv_dir, Config), + {ok, Host} = inet:gethostname(), + {ok, IPv4Addr} = inet:getaddr(Host, inet), + {ok, IPv6Addr} = inet:getaddr(Host, inet6), + Domain = snmpUDPDomain, + Transports = + [{Domain, {IPv4Addr, ?AGENT_PORT}}, + {transportDomainUdpIpv6, {IPv6Addr, ?AGENT_PORT}}], + TrapAddr = {IPv4Addr, 0}, + Versions = [v2], + agent_config( + Dir, Transports, Domain, TrapAddr, Versions), + [{host, Host}, {port, ?AGENT_PORT}, + {snmp_versions, Versions}, + {snmpget, Path} | Config]; + _ -> + {skip, "Host does not support IPV6"} + end end; init_per_group(get, Config) -> @@ -121,8 +128,8 @@ init_per_group(get, Config) -> case os:find_executable("snmpget") of false -> {skip, "snmpget not found"}; - _ -> - Config + Path -> + [{snmpget, Path} | Config] end; init_per_group(inform, Config) -> @@ -130,8 +137,8 @@ init_per_group(inform, Config) -> case os:find_executable("snmptrapd") of false -> {skip, "snmptrapd not found"}; - _ -> - Config + Path -> + [{snmptrapd, Path} | Config] end; init_per_group(_, Config) -> Config. @@ -139,19 +146,32 @@ init_per_group(_, Config) -> end_per_group(_GroupName, Config) -> Config. -init_per_testcase(Case, Config) -> +init_per_testcase(_Case, Config) -> Dog = ct:timetrap(10000), - end_per_testcase(Case, Config), - application:start(snmp), - application:load(snmp), - application:set_env(snmp, agent, app_env(Case, Config)), - snmp:start_agent(normal), + application:stop(snmp), + application:unload(snmp), [{watchdog, Dog} | Config]. end_per_testcase(_, Config) -> - application:stop(snmp), + case application:stop(snmp) of + ok -> + ok; + E1 -> + ct:pal("application:stop(snmp) -> ~p", [E1]) + end, + case application:unload(snmp) of + ok -> + ok; + E2 -> + ct:pal("application:unload(snmp) -> ~p", [E2]) + end, Config. +start_agent(Config) -> + ok = application:load(snmp), + ok = application:set_env(snmp, agent, app_env(Config)), + ok = application:start(snmp). + %%-------------------------------------------------------------------- %% Test Cases -------------------------------------------------------- %%-------------------------------------------------------------------- @@ -160,42 +180,46 @@ erlang_agent_netsnmp_get() -> "from snmpnet manager"}]. erlang_agent_netsnmp_get(Config) when is_list(Config) -> - Host = ?config(host, Config), - Port = ?config(agent_port, Config), - IPVersion = ?config(ip_version, Config), - Versions = ?config(snmp_versions, Config), - - Cmd = "snmpget -c public " ++ net_snmp_version(Versions) ++ " " ++ - net_snmp_ip_version(IPVersion) ++ - Host ++ ":" ++ integer_to_list(Port) ++ - " " ++ oid_str(?sysDescr_instance), - net_snmp(Cmd, ?SYS_DESC). + start_agent(Config), + ?SYS_DESC = snmpget(oid_str(?sysDescr_instance), Config), + ok. %%-------------------------------------------------------------------- erlang_agent_dual_ip_get() -> [{doc,"Test that we can access erlang snmp agent from both " "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. erlang_agent_dual_ip_get(Config) when is_list(Config) -> - erlang_agent_netsnmp_get([{ip_version, ipv4} | Config]), - erlang_agent_netsnmp_get([{ip_version, ipv6} | Config]). + start_agent(Config), + + OidStr = oid_str(?sysDescr_instance), + ?SYS_DESC = snmpget(OidStr, [{ip_version, ipv4} | Config]), + ?SYS_DESC = snmpget(OidStr, [{ip_version, ipv6} | Config]), + ok. + %%-------------------------------------------------------------------- erlang_agent_netsnmp_inform(Config) when is_list(Config) -> Host = ?config(host, Config), IPVersion = ?config(ip_version, Config), DataDir = ?config(data_dir, Config), + + start_agent(Config), ok = snmpa:load_mib( snmp_master_agent, filename:join(DataDir, "TestTrapv2")), - Cmd = "snmptrapd -L o -M " ++ DataDir ++ - " --disableAuthorization=yes" ++ - " --snmpTrapdAddr=" ++ net_snmp_ip_version(IPVersion) ++ - Host ++ ":" ++ integer_to_list(?config(manager_port, Config)), - - NetSnmpPort = net_snmp_trapd(Cmd), - snmpa:send_notification(snmp_master_agent, testTrapv22, - {erlang_agent_test, self()}), - net_snmp_log(NetSnmpPort), + SnmptrapdArgs = + ["-f", "-Lo", + "-M", DataDir, + "--disableAuthorization=yes", + "--snmpTrapdAddr=" ++ net_snmp_transport(IPVersion) ++ + Host ++ ":" ++ integer_to_list(?config(manager_port, Config))], + {ok, CheckMP} = re:compile("NET-SNMP version ", [anchored]), + ProgHandle = + start_program(snmptrapd, SnmptrapdArgs, CheckMP, Config), + + snmpa:send_notification( + snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), + receive {snmp_targets, erlang_agent_test, Addresses} -> ct:pal("Notification sent to: ~p~n", [Addresses]) @@ -207,38 +231,116 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> {snmp_notification, erlang_agent_test, {no_response, _} = NoResponse} -> ct:fail(NoResponse) - end. + end, + + stop_program(ProgHandle). %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- -net_snmp(Cmd, Expect) -> - NetSnmpPort = open_port({spawn, Cmd}, [stderr_to_stdout]), - ct:pal("net_snmp started: ~s~n", [Cmd]), - receive - {NetSnmpPort, {data, Expect}} -> - ok; - Msg -> - ct:fail({{expected, {NetSnmpPort, {data, Expect}}}, - {got, Msg}}) - end, - catch erlang:port_close(NetSnmpPort). - -net_snmp_trapd(Cmd) -> - NetSnmpTrapdPort = open_port({spawn, Cmd}, [stderr_to_stdout]), - ct:pal("net_snmp_trapd started: ~s~n", [Cmd]), - NetSnmpTrapdPort. - -net_snmp_log(NetSnmpPort) -> - receive - {NetSnmpPort, {data, Data}} -> - ct:pal("Received from netsnmp: ~p~n", [Data]), - net_snmp_log(NetSnmpPort) - after 500 -> - catch erlang:port_close(NetSnmpPort) +snmpget(OidStr, Config) -> + Versions = ?config(snmp_versions, Config), + IPVersion = ?config(ip_version, Config), + Host = ?config(host, Config), + Port = ?config(agent_port, Config), + + Args = + ["-c", "public", net_snmp_version(Versions), + net_snmp_transport(IPVersion) ++ + Host ++ ":" ++ integer_to_list(Port), + OidStr], + ProgHandle = start_program(snmpget, Args, none, Config), + {_, line, Line} = get_program_output(ProgHandle), + stop_program(ProgHandle), + Line. + + +start_program(Prog, Args, StartCheckMP, Config) -> + Path = ?config(Prog, Config), + DataDir = ?config(data_dir, Config), + StartWrapper = filename:join(DataDir, "start_stop_wrapper"), + Parent = self(), + Pid = + spawn_link( + fun () -> + run_program(Parent, StartWrapper, [Path | Args]) + end), + start_check(Pid, erlang:monitor(process, Pid), StartCheckMP). + +start_check(Pid, Mon, none) -> + {Pid, Mon}; +start_check(Pid, Mon, StartCheckMP) -> + receive + {Pid, line, Line} -> + case re:run(Line, StartCheckMP, [{capture, none}]) of + match -> + {Pid, Mon}; + nomatch -> + start_check(Pid, Mon, StartCheckMP) + end; + {'DOWN', Mon, _, _, Reason} -> + ct:fail("Prog ~p start failed: ~p", [Pid, Reason]) + end. + +get_program_output({Pid, Mon}) -> + receive + {Pid, _, _} = Msg -> + Msg; + {'DOWN', Mon, _, _, Reason} -> + ct:fail("Prog ~p crashed: ~p", [Pid, Reason]) end. -app_env(_Case, Config) -> +stop_program({Pid, _} = Handle) -> + Pid ! {self(), stop}, + wait_program_stop(Handle). + +wait_program_stop({Pid, Mon}) -> + receive + {Pid, exit, ExitStatus} -> + receive + {'DOWN', Mon, _, _, _} -> + ExitStatus + end; + {'DOWN', Mon, _, _, Reason} -> + ct:fail("Prog stop: ~p", [Reason]) + end. + +run_program(Parent, StartWrapper, ProgAndArgs) -> + Port = + open_port( + {spawn_executable, StartWrapper}, + [{args, ProgAndArgs}, binary, stderr_to_stdout, {line, 80}, + exit_status]), + ct:pal("Prog ~p started: ~p", [Port, ProgAndArgs]), + run_program_loop(Parent, Port, []). + +run_program_loop(Parent, Port, Buf) -> + receive + {Parent, stop} -> + true = port_command(Port, <<"stop\n">>), + ct:pal("Prog ~p stop", [Port]), + run_program_loop(Parent, Port, Buf); + {Port, {data, {Flag, Data}}} -> + case Flag of + eol -> + Line = iolist_to_binary(lists:reverse(Buf, Data)), + ct:pal("Prog ~p output: ~s", [Port, Line]), + Parent ! {self(), line, Line}, + run_program_loop(Parent, Port, []); + noeol -> + run_program_loop(Parent, Port, [Data | Buf]) + end; + {Port, {exit_status,ExitStatus}} -> + ct:pal("Prog ~p exit: ~p", [Port, ExitStatus]), + catch port_close(Port), + Parent ! {self(), exit, ExitStatus}; + Unexpected -> + ct:pal("run_program_loop Unexpected: ~p", [Unexpected]), + run_program_loop(Parent, Port, Buf) + end. + + +app_env(Config) -> Dir = ?config(priv_dir, Config), Vsns = ?config(snmp_versions, Config), [{versions, Vsns}, @@ -249,7 +351,7 @@ app_env(_Case, Config) -> {dir, Dir}, {size, {10240, 10}}]}, {config, [{dir, Dir}, - {force_load, false}, + {force_load, true}, {verbosity, trace}]}, {local_db, [{repair, true}, {verbosity, silence}]}, @@ -288,7 +390,8 @@ net_snmp_version([v2 | _]) -> "-v2c"; net_snmp_version([v1 | _]) -> "-v1". -net_snmp_ip_version(ipv4) -> + +net_snmp_transport(ipv4) -> "udp:"; -net_snmp_ip_version(ipv6) -> +net_snmp_transport(ipv6) -> "udp6:". diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper new file mode 100755 index 0000000000..f806ab5c12 --- /dev/null +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper @@ -0,0 +1,47 @@ +#! /bin/sh +## +## %CopyrightBegin% +## +## Copyright Ericsson AB 2014-2014. All Rights Reserved. +## +## The contents of this file are subject to the Erlang Public License, +## Version 1.1, (the "License"); you may not use this file except in +## compliance with the License. You should have received a copy of the +## Erlang Public License along with this software. If not, it can be +## retrieved online at http://www.erlang.org/. +## +## Software distributed under the License is distributed on an "AS IS" +## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +## the License for the specific language governing rights and limitations +## under the License. +## +## %CopyrightEnd% +## +# + +## Start the given executable, wait for stop command, +## stop the running executable and wait for exit. + +die () { + r=$? + echo "$0:" "$*" 1>&2 + exit $r +} + +test -x "$1" || die "Not Executable: $1" + +# Redirect stdin to make sure the stop command is read by us below +# and does not go to the executable +"$@" 0< /dev/null & +PID=$! + +# Wait for stop command +while read LINE; do + case :"$LINE" in + :"stop") + break;; + esac +done + +kill $PID +wait $PID -- cgit v1.2.3 From 3fe74b2d7d150078faed977ca79ddf96e3b2c000 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 4 Jul 2014 15:37:56 +0200 Subject: Write list of trap targets --- lib/snmp/src/misc/snmp_config.erl | 101 ++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 43 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 91240082f1..9e9865f3b5 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -37,8 +37,10 @@ write_agent_snmp_context_conf/1, write_agent_snmp_community_conf/1, write_agent_snmp_standard_conf/2, - write_agent_snmp_target_addr_conf/4, - write_agent_snmp_target_addr_conf/6, + write_agent_snmp_target_addr_conf/3, + write_agent_snmp_target_addr_conf/4, + write_agent_snmp_target_addr_conf/5, + write_agent_snmp_target_addr_conf/6, write_agent_snmp_target_params_conf/2, write_agent_snmp_notify_conf/2, write_agent_snmp_usm_conf/5, @@ -1797,21 +1799,18 @@ update_agent_standard_config(Dir, Conf) -> %% ------ target_addr.conf ------ %% -write_agent_snmp_target_addr_conf(Dir, Domain, Addr, Vsns) - when is_atom(Domain) -> - Timeout = 1500, - RetryCount = 3, +write_agent_snmp_target_addr_conf(Dir, Addresses, Vsns) -> + Timeout = 1500, + RetryCount = 3, write_agent_snmp_target_addr_conf( - Dir, Domain, Addr, Timeout, RetryCount, Vsns); -write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, Vsns) - when is_integer(UDP) -> - Domain = snmp_target_mib:default_domain(), - Addr = {ManagerIp, UDP}, - write_agent_snmp_target_addr_conf(Dir, Domain, Addr, Vsns). + Dir, Addresses, Timeout, RetryCount, Vsns). + +write_agent_snmp_target_addr_conf(Dir, Domain_or_Ip, Addr_or_Port, Vsns) -> + Addresses = [{Domain_or_Ip, Addr_or_Port}], + write_agent_snmp_target_addr_conf(Dir, Addresses, Vsns). write_agent_snmp_target_addr_conf( - Dir, Domain, Addr, Timeout, RetryCount, Vsns) - when is_atom(Domain) -> + Dir, Addresses, Timeout, RetryCount, Vsns) -> Comment = "%% This file defines the target address parameters.\n" "%% The data is inserted into the snmpTargetAddrTable defined\n" @@ -1831,43 +1830,59 @@ write_agent_snmp_target_addr_conf( "%% [127,0,0,0], 2048}.\n" "%%\n\n", Hdr = header() ++ Comment, - F = fun(v1 = Vsn, Acc) -> - [{mk_name(Domain, Addr, Vsn), - Domain, Addr, Timeout, RetryCount, - "std_trap", mk_param(Vsn), "", [], 2048}| Acc]; - (v2 = Vsn, Acc) -> - [{mk_name(Domain, Addr, Vsn), - Domain, Addr, Timeout, RetryCount, - "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten( - io_lib:format("~s.2",[mk_name(Domain, Addr, Vsn)])), - Domain, Addr, Timeout, RetryCount, - "std_inform", mk_param(Vsn), "", [], 2048}| Acc]; - (v3 = Vsn, Acc) -> - [{mk_name(Domain, Addr, Vsn), - Domain, Addr, Timeout, RetryCount, - "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten( - io_lib:format("~s.3",[mk_name(Domain, Addr, Vsn)])), - Domain, Addr, Timeout, RetryCount, - "std_inform", mk_param(Vsn), "mgrEngine", [], 2048}| Acc] - end, - Conf = lists:foldl(F, [], Vsns), - write_agent_target_addr_config(Dir, Hdr, Conf); + Conf = + lists:foldl( + fun ({Domain_or_Ip, Addr_or_Port} = Address, OuterAcc) -> + lists:foldl( + fun(v1 = Vsn, Acc) -> + [{mk_name(Address, Vsn), + Domain_or_Ip, Addr_or_Port, + Timeout, RetryCount, + "std_trap", mk_param(Vsn), "", + [], 2048}| Acc]; + (v2 = Vsn, Acc) -> + [{mk_name(Address, Vsn), + Domain_or_Ip, Addr_or_Port, + Timeout, RetryCount, + "std_trap", mk_param(Vsn), "", + [], 2048}, + {lists:flatten( + io_lib:format( + "~s.2", [mk_name(Address, Vsn)])), + Domain_or_Ip, Addr_or_Port, + Timeout, RetryCount, + "std_inform", mk_param(Vsn), "", + [], 2048}| Acc]; + (v3 = Vsn, Acc) -> + [{mk_name(Address, Vsn), + Domain_or_Ip, Addr_or_Port, + Timeout, RetryCount, + "std_trap", mk_param(Vsn), "", + [], 2048}, + {lists:flatten( + io_lib:format( + "~s.3", [mk_name(Address, Vsn)])), + Domain_or_Ip, Addr_or_Port, + Timeout, RetryCount, + "std_inform", mk_param(Vsn), "mgrEngine", + [], 2048} | Acc] + end, OuterAcc, Vsns) + end, [], Addresses), + write_agent_target_addr_config(Dir, Hdr, Conf). + write_agent_snmp_target_addr_conf( - Dir, ManagerIp, UDP, Timeout, RetryCount, Vsns) when is_integer(UDP) -> - Domain = snmp_target_mib:default_domain(), - Addr = {ManagerIp, UDP}, + Dir, Domain_or_Ip, Addr_or_Port, Timeout, RetryCount, Vsns) -> + Addresses = [{Domain_or_Ip, Addr_or_Port}], write_agent_snmp_target_addr_conf( - Dir, Domain, Addr, Timeout, RetryCount, Vsns). + Dir, Addresses, Timeout, RetryCount, Vsns). mk_param(Vsn) -> lists:flatten(io_lib:format("target_~w", [Vsn])). -mk_name(Domain, Addr, Vsn) -> +mk_name(Address, Vsn) -> lists:flatten( io_lib:format( - "~s ~w", [snmp_conf:mk_addr_string({Domain, Addr}), Vsn])). + "~s ~w", [snmp_conf:mk_addr_string(Address), Vsn])). write_agent_target_addr_config(Dir, Hdr, Conf) -> snmpa_conf:write_target_addr_config(Dir, Hdr, Conf). -- cgit v1.2.3 From 06c3bbdcff4af11aba54309bb09ecc3eed96d754 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 4 Jul 2014 15:38:53 +0200 Subject: Test inform to dual transports --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 148 +++++++++++++++++++++++--------- 1 file changed, 106 insertions(+), 42 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index fa92beb6b1..7a2b05c048 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -45,16 +45,22 @@ all() -> ]. groups() -> - [{ipv4, [], [{group, get}, - {group, inform} - ]}, - {ipv6, [], [{group, get}, - {group, inform}, - {group, dual_ip} - ]}, - {get, [], [erlang_agent_netsnmp_get]}, - {inform, [], [erlang_agent_netsnmp_inform]}, - {dual_ip, [], [erlang_agent_dual_ip_get]} + [{ipv4, [], + [{group, get}, + {group, inform} + ]}, + {ipv6, [], + [{group, get}, + {group, inform}, + {group, dual_ip} + ]}, + {get, [], + [erlang_agent_netsnmp_get]}, + {inform, [], + [erlang_agent_netsnmp_inform]}, + {dual_ip, [], + [erlang_agent_dual_ip_get, + erlang_agent_dual_ip_inform]} ]. init_per_suite(Config) -> @@ -81,7 +87,7 @@ init_per_group(ipv6, Config) -> _ -> {skip, "Host does not support IPV6"} end; - +%% init_per_group(ipv4, Config) -> Dir = ?config(priv_dir, Config), Domain = transportDomainUdpIpv4, @@ -95,51 +101,44 @@ init_per_group(ipv4, Config) -> agent_config(Dir, Transports, Domain, TrapAddr, Versions), [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv4} | Config]; - +%% init_per_group(dual_ip, Config) -> - case os:find_executable("snmpget") of - false -> - {skip, "snmpget not found"}; - Path -> + case find_executables([snmpget, snmptrapd], Config) of + NewConfig when is_list(NewConfig) -> case ct:require(ipv6_hosts) of ok -> Dir = ?config(priv_dir, Config), + Domain = transportDomainUdpIpv4, + AgentPort = ?config(agent_port, Config), + ManagerPort = ?config(manager_port, Config), {ok, Host} = inet:gethostname(), {ok, IPv4Addr} = inet:getaddr(Host, inet), {ok, IPv6Addr} = inet:getaddr(Host, inet6), - Domain = snmpUDPDomain, Transports = - [{Domain, {IPv4Addr, ?AGENT_PORT}}, - {transportDomainUdpIpv6, {IPv6Addr, ?AGENT_PORT}}], - TrapAddr = {IPv4Addr, 0}, + [{Domain, {IPv4Addr, AgentPort}}, + {transportDomainUdpIpv6, {IPv6Addr, AgentPort}}], + Targets = + [{Domain, {IPv4Addr, ManagerPort}}, + {transportDomainUdpIpv6, {IPv6Addr, ManagerPort}}], Versions = [v2], - agent_config( - Dir, Transports, Domain, TrapAddr, Versions), + agent_config(Dir, Transports, Targets, Versions), [{host, Host}, {port, ?AGENT_PORT}, - {snmp_versions, Versions}, - {snmpget, Path} | Config]; + {snmp_versions, Versions} + | NewConfig]; _ -> {skip, "Host does not support IPV6"} - end + end; + Other -> + Other end; - +%% init_per_group(get, Config) -> %% From Ubuntu package snmp - case os:find_executable("snmpget") of - false -> - {skip, "snmpget not found"}; - Path -> - [{snmpget, Path} | Config] - end; - + find_executables([snmpget], Config); +%% init_per_group(inform, Config) -> %% From Ubuntu package snmptrapfmt - case os:find_executable("snmptrapd") of - false -> - {skip, "snmptrapd not found"}; - Path -> - [{snmptrapd, Path} | Config] - end; + find_executables([snmptrapd], Config); init_per_group(_, Config) -> Config. @@ -167,6 +166,18 @@ end_per_testcase(_, Config) -> end, Config. +find_executables([], Config) -> + Config; +find_executables([Exec | Execs], Config) -> + case os:find_executable(atom_to_list(Exec)) of + false -> + {skip, Exec ++ " not found"}; + Path -> + find_executables( + Execs, + [{Exec, Path} | Config]) + end. + start_agent(Config) -> ok = application:load(snmp), ok = application:set_env(snmp, agent, app_env(Config)), @@ -213,9 +224,9 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> "--disableAuthorization=yes", "--snmpTrapdAddr=" ++ net_snmp_transport(IPVersion) ++ Host ++ ":" ++ integer_to_list(?config(manager_port, Config))], - {ok, CheckMP} = re:compile("NET-SNMP version ", [anchored]), + {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), ProgHandle = - start_program(snmptrapd, SnmptrapdArgs, CheckMP, Config), + start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -235,6 +246,56 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> stop_program(ProgHandle). +%%-------------------------------------------------------------------- +erlang_agent_dual_ip_inform(Config) when is_list(Config) -> + Host = ?config(host, Config), + ManagerPort = ?config(manager_port, Config), + DataDir = ?config(data_dir, Config), + + start_agent(Config), + ok = + snmpa:load_mib( + snmp_master_agent, filename:join(DataDir, "TestTrapv2")), + + ManagerPortStr = integer_to_list(ManagerPort), + SnmptrapdArgs = + ["-f", "-Lo", + "-M", DataDir, + "--disableAuthorization=yes", + "--snmpTrapdAddr=" ++ + net_snmp_transport(ipv4) ++ Host ++ ":" ++ ManagerPortStr ++ + "," ++ + net_snmp_transport(ipv6) ++ Host ++ ":" ++ ManagerPortStr], + {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), + ProgHandle = + start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config), + + snmpa:send_notification( + snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), + + receive + {snmp_targets, erlang_agent_test, Addresses} -> + ct:pal("Notification sent to: ~p~n", [Addresses]), + erlang_agent_dual_ip_inform_responses(Addresses) + end, + stop_program(ProgHandle). + +erlang_agent_dual_ip_inform_responses([]) -> + ok; +erlang_agent_dual_ip_inform_responses([Address | Addresses] = AAs) -> + receive + {snmp_notification, erlang_agent_test, + {got_response, Address}} -> + ct:pal("Got response from: ~p~n", [Address]), + erlang_agent_dual_ip_inform_responses(Addresses); + {snmp_notification, erlang_agent_test, + {no_response, _} = NoResponse} -> + ct:fail(NoResponse); + {snmp_notification, erlang_agent_test, _} = Unexpected -> + ct:pal("Unexpected response: ~p", [Unexpected]), + erlang_agent_dual_ip_inform_responses(AAs) + end. + %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- @@ -369,6 +430,9 @@ oid_str([Int | Rest], Acc) -> oid_str(Rest, Acc ++ "." ++ integer_to_list(Int)). agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> + agent_config(Dir, Transports, [{TargetDomain, TargetAddr}], Versions). +%% +agent_config(Dir, Transports, Targets, Versions) -> EngineID = ?AGENT_ENGIN_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, ok = snmp_config:write_agent_snmp_conf(Dir, Transports, EngineID, MMS), @@ -379,7 +443,7 @@ agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> Dir, "snmp_to_snmpnet_SUITE"), ok = snmp_config:write_agent_snmp_target_addr_conf( - Dir, TargetDomain, TargetAddr, Versions), + Dir, Targets, Versions), ok = snmp_config:write_agent_snmp_target_params_conf(Dir, Versions), ok = snmp_config:write_agent_snmp_notify_conf(Dir, inform), ok = snmp_config:write_agent_snmp_vacm_conf(Dir, Versions, none). -- cgit v1.2.3 From 8547d1fe580c714e15ab205d6b2635333ea380f8 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 23 Jul 2014 15:42:20 +0200 Subject: Improve external snmp commands args --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 120 ++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 52 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 7a2b05c048..78c3a53f89 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -16,7 +16,13 @@ %% %% %CopyrightEnd% %% -%% +%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% This test suite uses the following external programs: +%% snmpget From packet 'snmp' (in Ubuntu 12.04) +%% snmptrapd From packet 'snmpd' (in Ubuntu 12.04) +%% They originate from the Net-SNMP applications, see: +%% http://net-snmp.sourceforge.net/ + -module(snmp_to_snmpnet_SUITE). @@ -26,11 +32,14 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("snmp/include/STANDARD-MIB.hrl"). --define(AGENT_ENGIN_ID, "ErlangSnmpAgent"). +-define(AGENT_ENGINE_ID, "ErlangSnmpAgent"). -define(AGENT_PORT, 4000). -define(MANAGER_PORT, 8989). -define(DEFAULT_MAX_MESSAGE_SIZE, 484). --define(SYS_DESC, <<"iso.3.6.1.2.1.1.1.0 = STRING: \"Erlang SNMP agent\"">>). + +expected(?sysDescr_instance = Oid, get) -> + OidStr = oid_str(Oid), + iolist_to_binary([OidStr | " = STRING: \"Erlang SNMP agent\""]). %%-------------------------------------------------------------------- %% Common Test interface functions ----------------------------------- @@ -192,7 +201,9 @@ erlang_agent_netsnmp_get() -> erlang_agent_netsnmp_get(Config) when is_list(Config) -> start_agent(Config), - ?SYS_DESC = snmpget(oid_str(?sysDescr_instance), Config), + Oid = ?sysDescr_instance, + Expected = expected(Oid, get), + Expected = snmpget(Oid, Config), ok. %%-------------------------------------------------------------------- @@ -201,10 +212,10 @@ erlang_agent_dual_ip_get() -> "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. erlang_agent_dual_ip_get(Config) when is_list(Config) -> start_agent(Config), - - OidStr = oid_str(?sysDescr_instance), - ?SYS_DESC = snmpget(OidStr, [{ip_version, ipv4} | Config]), - ?SYS_DESC = snmpget(OidStr, [{ip_version, ipv6} | Config]), + Oid = ?sysDescr_instance, + Expected = expected(Oid, get), + Expected = snmpget(Oid, [{ip_version, ipv4} | Config]), + Expected = snmpget(Oid, [{ip_version, ipv6} | Config]), ok. %%-------------------------------------------------------------------- @@ -212,21 +223,14 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> Host = ?config(host, Config), IPVersion = ?config(ip_version, Config), DataDir = ?config(data_dir, Config), + Mib = "TestTrapv2", start_agent(Config), - ok = - snmpa:load_mib( - snmp_master_agent, filename:join(DataDir, "TestTrapv2")), - - SnmptrapdArgs = - ["-f", "-Lo", - "-M", DataDir, - "--disableAuthorization=yes", - "--snmpTrapdAddr=" ++ net_snmp_transport(IPVersion) ++ - Host ++ ":" ++ integer_to_list(?config(manager_port, Config))], - {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), - ProgHandle = - start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config), + ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), + + TrapAddr = net_snmp_transport(IPVersion) ++ Host ++ + ":" ++ integer_to_list(?config(manager_port, Config)), + ProgHandle = start_snmptrapd(Mib, TrapAddr, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -251,24 +255,17 @@ erlang_agent_dual_ip_inform(Config) when is_list(Config) -> Host = ?config(host, Config), ManagerPort = ?config(manager_port, Config), DataDir = ?config(data_dir, Config), + Mib = "TestTrapv2", start_agent(Config), - ok = - snmpa:load_mib( - snmp_master_agent, filename:join(DataDir, "TestTrapv2")), + ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), ManagerPortStr = integer_to_list(ManagerPort), - SnmptrapdArgs = - ["-f", "-Lo", - "-M", DataDir, - "--disableAuthorization=yes", - "--snmpTrapdAddr=" ++ - net_snmp_transport(ipv4) ++ Host ++ ":" ++ ManagerPortStr ++ - "," ++ - net_snmp_transport(ipv6) ++ Host ++ ":" ++ ManagerPortStr], - {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), - ProgHandle = - start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config), + TrapAddrs = + net_snmp_transport(ipv4) ++ Host ++ ":" ++ ManagerPortStr ++ + "," ++ + net_snmp_transport(ipv6) ++ Host ++ ":" ++ ManagerPortStr, + ProgHandle = start_snmptrapd(Mib, TrapAddrs, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -281,8 +278,14 @@ erlang_agent_dual_ip_inform(Config) when is_list(Config) -> stop_program(ProgHandle). erlang_agent_dual_ip_inform_responses([]) -> - ok; -erlang_agent_dual_ip_inform_responses([Address | Addresses] = AAs) -> + receive + {snmp_notification, erlang_agent_test, _} = Unexpected -> + ct:pal("Unexpected response: ~p", [Unexpected]), + erlang_agent_dual_ip_inform_responses([]) + after 0 -> + ok + end; +erlang_agent_dual_ip_inform_responses([Address | Addresses]) -> receive {snmp_notification, erlang_agent_test, {got_response, Address}} -> @@ -290,16 +293,13 @@ erlang_agent_dual_ip_inform_responses([Address | Addresses] = AAs) -> erlang_agent_dual_ip_inform_responses(Addresses); {snmp_notification, erlang_agent_test, {no_response, _} = NoResponse} -> - ct:fail(NoResponse); - {snmp_notification, erlang_agent_test, _} = Unexpected -> - ct:pal("Unexpected response: ~p", [Unexpected]), - erlang_agent_dual_ip_inform_responses(AAs) + ct:fail(NoResponse) end. %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- -snmpget(OidStr, Config) -> +snmpget(Oid, Config) -> Versions = ?config(snmp_versions, Config), IPVersion = ?config(ip_version, Config), Host = ?config(host, Config), @@ -307,14 +307,26 @@ snmpget(OidStr, Config) -> Args = ["-c", "public", net_snmp_version(Versions), - net_snmp_transport(IPVersion) ++ - Host ++ ":" ++ integer_to_list(Port), - OidStr], + "-m", "", + "-Cf", + net_snmp_transport(IPVersion)++Host++":"++ integer_to_list(Port), + oid_str(Oid)], ProgHandle = start_program(snmpget, Args, none, Config), {_, line, Line} = get_program_output(ProgHandle), stop_program(ProgHandle), Line. +start_snmptrapd(Mibs, TrapAddrs, Config) -> + DataDir = ?config(data_dir, Config), + MibDir = filename:join(code:lib_dir(snmp), "mibs"), + SnmptrapdArgs = + ["-f", "-Lo", "-C", + "-m", Mibs, + "-M", MibDir++":"++DataDir, + "--disableAuthorization=yes", + "--snmpTrapdAddr="++TrapAddrs], + {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), + start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config). start_program(Prog, Args, StartCheckMP, Config) -> Path = ?config(Prog, Config), @@ -421,19 +433,23 @@ app_env(Config) -> {note_store, [{verbosity, silence}]}, {net_if, [{verbosity, trace}]}]. -oid_str([Int | Rest]) -> - oid_str(Rest, integer_to_list(Int)). +oid_str([1 | Ints]) -> + "iso." ++ oid_str_tl(Ints); +oid_str(Ints) -> + oid_str_tl(Ints). -oid_str([], Acc) -> - Acc; -oid_str([Int | Rest], Acc) -> - oid_str(Rest, Acc ++ "." ++ integer_to_list(Int)). +oid_str_tl([]) -> + ""; +oid_str_tl([Int]) -> + integer_to_list(Int); +oid_str_tl([Int | Ints]) -> + integer_to_list(Int) ++ "." ++ oid_str_tl(Ints). agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> agent_config(Dir, Transports, [{TargetDomain, TargetAddr}], Versions). %% agent_config(Dir, Transports, Targets, Versions) -> - EngineID = ?AGENT_ENGIN_ID, + EngineID = ?AGENT_ENGINE_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, ok = snmp_config:write_agent_snmp_conf(Dir, Transports, EngineID, MMS), ok = snmp_config:write_agent_snmp_context_conf(Dir), -- cgit v1.2.3 From 99c1ea078124faac8062df3deb9a98d2be495a12 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 23 Jul 2014 17:27:47 +0200 Subject: Call new Net-SNMP test suite from top suite --- lib/snmp/test/snmp_SUITE.erl | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_SUITE.erl b/lib/snmp/test/snmp_SUITE.erl index 22b9c64588..6fabf6410f 100644 --- a/lib/snmp/test/snmp_SUITE.erl +++ b/lib/snmp/test/snmp_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2012. All Rights Reserved. +%% Copyright Ericsson AB 1997-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -80,7 +80,8 @@ groups() -> {group, note_store_test}]}, {agent, [], [{group, mibs_test}, {group, nfilter_test}, - {group, agent_test}]}, + {group, agent_test}, + {group, snmpnet_test}]}, {manager, [], [{group, manager_config_test}, {group, manager_user_test}, {group, manager_test}]}, @@ -95,6 +96,7 @@ groups() -> {mibs_test, [], [{snmp_agent_mibs_test, all}]}, {nfilter_test, [], [{snmp_agent_nfilter_test, all}]}, {agent_test, [], [{snmp_agent_test, all}]}, + {snmpnet_test, [], [{snmp_to_snmpnet_SUITE, all}]}, {manager_config_test, [], [{snmp_manager_config_test, all}]}, {manager_user_test, [], [{snmp_manager_user_test, all}]}, {manager_test, [], [{snmp_manager_test, all}]} @@ -107,15 +109,18 @@ init_per_group(GroupName, Config0) -> "~n GroupName: ~p" "~n Config0: ~p", [GroupName, Config0]), - %% Group name is not really the suite name - %% (but it is a good enough approximation), - %% but it does not matter since we only need - %% it to be unique. - snmp_test_lib:init_suite_top_dir(GroupName, Config0). - - + case GroupName of + snmpnet_test -> + Config0; + _ -> + %% Group name is not really the suite name + %% (but it is a good enough approximation), + %% but it does not matter since we only need + %% it to be unique. + snmp_test_lib:init_suite_top_dir(GroupName, Config0) + end. + +end_per_group(snmpnet_test, Config) -> + Config; end_per_group(_GroupName, Config) -> lists:keydelete(snmp_suite_top_dir, 1, Config). - - - -- cgit v1.2.3 From ad00eb19928f7056386a37e633a0b4e3d1f9442b Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 24 Jul 2014 13:52:10 +0200 Subject: Fix test manager in agent tests for IPv6 --- lib/snmp/test/snmp_agent_test.erl | 9 ++++-- lib/snmp/test/snmp_agent_test_lib.erl | 12 +++----- lib/snmp/test/snmp_test_mgr.erl | 36 +++++++++++++----------- lib/snmp/test/snmp_test_mgr_misc.erl | 52 +++++++++++++++++++---------------- 4 files changed, 60 insertions(+), 49 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index b181bf957d..9a9258aa91 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -653,7 +653,9 @@ init_per_group_ipv6(GroupName, Config, Init) -> ok -> Init( snmp_test_lib:init_group_top_dir( - GroupName, [{ipfamily, inet6}|Config])); + GroupName, + [{ipfamily, inet6}, + {ip, ?LOCALHOST(inet6)} | lists:keydelete(ip, 1, Config)])); _ -> {skip, "Host does not support IPV6"} end. @@ -6654,6 +6656,7 @@ otp8395({init, Config}) when is_list(Config) -> %% SubAgentHost = ?HPSTNAME(SubAgentNode), ManagerHost = ?HOSTNAME(ManagerNode), + IpFamily = inet, Host = snmp_test_lib:hostname(), Ip = ?LOCALHOST(), {ok, AgentIP0} = snmp_misc:ip(AgentHost), @@ -6671,7 +6674,7 @@ otp8395({init, Config}) when is_list(Config) -> Vsns = [v1], AgentConfDir = ?config(agent_conf_dir, Config), ManagerConfDir = ?config(manager_top_dir, Config), - config(Vsns, ManagerConfDir, AgentConfDir, ManagerIP, AgentIP), + config(Vsns, ManagerConfDir, AgentConfDir, ManagerIP, AgentIP, IpFamily), %% -- @@ -6680,6 +6683,7 @@ otp8395({init, Config}) when is_list(Config) -> Config2 = start_agent([{host, Host}, {ip, Ip}, + {ipfamily, IpFamily}, {agent_node, AgentNode}, {agent_host, AgentHost}, {agent_ip, AgentIP}, @@ -6759,6 +6763,7 @@ otp8395(Config) when is_list(Config) -> put(mib_dir, ?config(mib_dir, Config)), put(vsn, v1), put(master_host, ?config(agent_host, Config)), + put(ipfamily, ?config(ipfamily, Config)), try_test(simple_standard_test), ?SLEEP(1000), diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 6925c16ffb..333fe6eb66 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -251,6 +251,7 @@ init_case(Config) when is_list(Config) -> put(mip, tuple_to_list(MIP)), put(masterip, tuple_to_list(MasterIP)), put(sip, tuple_to_list(SIP)), + put(ipfamily, IpFamily), MibDir = ?config(mib_dir, Config), put(mib_dir, MibDir), @@ -359,6 +360,7 @@ run(Mod, Func, Args, Opts) -> {packet_server_debug,true}, {debug,true}, {agent, get(master_host)}, + {ipfamily, get(ipfamily)}, {agent_udp, 4000}, {trap_udp, 5000}, {recbuf,65535}, @@ -1383,12 +1385,9 @@ config(Vsns, MgrDir, AgentConfDir, MIp, AIp, IpFamily) -> ?line {Domain, ManagerAddr} = case IpFamily of inet6 -> - %% XXX Run IPv6 tests over IPv4 compatibility address - %% since the test manager needs to be rewritten to - %% handle IPv6 before we can improve this. Ipv6Domain = transportDomainUdpIpv6, - AgentIpv6Addr = {mk_ipv6_ip(AIp), 4000}, - ManagerIpv6Addr = {mk_ipv6_ip(MIp), ?TRAP_UDP}, + AgentIpv6Addr = {AIp, 4000}, + ManagerIpv6Addr = {MIp, ?TRAP_UDP}, ?line ok = snmp_config:write_agent_snmp_files( AgentConfDir, Vsns, @@ -1416,9 +1415,6 @@ config(Vsns, MgrDir, AgentConfDir, MIp, AIp, IpFamily) -> ?line write_notify_conf(AgentConfDir), ok. -mk_ipv6_ip([A,B,C,D]) -> - [0,0,0,0,0,0,0,0,0,0,255,255,A,B,C,D]. - delete_files(Config) -> AgentDir = ?config(agent_dir, Config), delete_files(AgentDir, [db, conf]). diff --git a/lib/snmp/test/snmp_test_mgr.erl b/lib/snmp/test/snmp_test_mgr.erl index d4eb00ff91..cf62edba1c 100644 --- a/lib/snmp/test/snmp_test_mgr.erl +++ b/lib/snmp/test/snmp_test_mgr.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -235,21 +235,23 @@ init({Options, CallerPid}) -> VsnHdrD = {Com, User, EngineId, CtxEngineId, mk_seclevel(SecLevel)}, io:format("[~w] ~p -> VsnHdrD: ~p~n", [?MODULE, self(), VsnHdrD]), + IpFamily = get_value(ipfamily, Options, inet), + io:format("[~w] ~p -> IpFamily: ~p~n", [?MODULE, self(), IpFamily]), AgIp = case snmp_misc:assq(agent, Options) of {value, Tuple4} when is_tuple(Tuple4) andalso (size(Tuple4) =:= 4) -> Tuple4; {value, Host} when is_list(Host) -> - {ok, Ip} = snmp_misc:ip(Host), + {ok, Ip} = snmp_misc:ip(Host, IpFamily), Ip end, io:format("[~w] ~p -> AgIp: ~p~n", [?MODULE, self(), AgIp]), Quiet = lists:member(quiet, Options), io:format("[~w] ~p -> Quiet: ~p~n", [?MODULE, self(), Quiet]), - PackServ = start_packet_server(Quiet, Options, CallerPid, - AgIp, Udp, TrapUdp, - VsnHdrD, Version, Dir, RecBufSz, - PacksDbg), + PackServ = + start_packet_server( + Quiet, Options, CallerPid, AgIp, Udp, TrapUdp, + VsnHdrD, Version, Dir, RecBufSz, PacksDbg, IpFamily), d("init -> packet server: ~p",[PackServ]), State = #state{parent = CallerPid, quiet = Quiet, @@ -263,23 +265,21 @@ init({Options, CallerPid}) -> end. start_packet_server(false, _Options, _CallerPid, AgIp, Udp, TrapUdp, - VsnHdrD, Version, Dir, RecBufSz, PacksDbg) -> + VsnHdrD, Version, Dir, RecBufSz, PacksDbg, IpFamily) -> d("start_packet_server -> entry", []), - ?PACK_SERV:start_link_packet({msg, self()}, - AgIp, Udp, TrapUdp, - VsnHdrD, Version, Dir, RecBufSz, - PacksDbg); + ?PACK_SERV:start_link_packet( + {msg, self()}, AgIp, Udp, TrapUdp, + VsnHdrD, Version, Dir, RecBufSz, PacksDbg, IpFamily); start_packet_server(true, Options, CallerPid, AgIp, Udp, TrapUdp, - VsnHdrD, Version, Dir, RecBufSz, PacksDbg) -> + VsnHdrD, Version, Dir, RecBufSz, PacksDbg, IpFamily) -> Type = get_value(receive_type, Options, pdu), d("start_packet_server -> entry with" "~n CallerPid: ~p" "~n when" "~n Type: ~p",[CallerPid, Type]), - ?PACK_SERV:start_link_packet({Type, CallerPid}, - AgIp, Udp, TrapUdp, - VsnHdrD, Version, Dir, RecBufSz, - PacksDbg). + ?PACK_SERV:start_link_packet( + {Type, CallerPid}, AgIp, Udp, TrapUdp, + VsnHdrD, Version, Dir, RecBufSz, PacksDbg, IpFamily). is_options_ok([{mibs,List}|Opts]) when is_list(List) -> is_options_ok(Opts); @@ -287,6 +287,10 @@ is_options_ok([quiet|Opts]) -> is_options_ok(Opts); is_options_ok([{agent,_}|Opts]) -> is_options_ok(Opts); +is_options_ok([{ipfamily,IpFamily}|Opts]) + when IpFamily =:= inet; + IpFamily =:= inet6 -> + is_options_ok(Opts); is_options_ok([{agent_udp,Int}|Opts]) when is_integer(Int) -> is_options_ok(Opts); is_options_ok([{trap_udp,Int}|Opts]) when is_integer(Int) -> diff --git a/lib/snmp/test/snmp_test_mgr_misc.erl b/lib/snmp/test/snmp_test_mgr_misc.erl index 5525c5c3ec..5274dcacd9 100644 --- a/lib/snmp/test/snmp_test_mgr_misc.erl +++ b/lib/snmp/test/snmp_test_mgr_misc.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -23,7 +23,7 @@ -module(snmp_test_mgr_misc). %% API --export([start_link_packet/8, start_link_packet/9, +-export([start_link_packet/8, start_link_packet/9, start_link_packet/10, stop/1, send_discovery_pdu/2, send_pdu/2, send_msg/4, send_bytes/2, @@ -31,7 +31,7 @@ get_pdu/1, set_pdu/2, format_hdr/1]). %% internal exports --export([init_packet/10]). +-export([init_packet/11]). -compile({no_auto_import, [error/2]}). @@ -42,22 +42,26 @@ %%---------------------------------------------------------------------- %% The InHandler process will receive messages on the form {snmp_pdu, Pdu}. %%---------------------------------------------------------------------- -start_link_packet(InHandler, - AgentIp, UdpPort, TrapUdp, - VsnHdr, Version, Dir, BufSz) -> - start_link_packet(InHandler, - AgentIp, UdpPort, TrapUdp, - VsnHdr, Version, Dir, BufSz, - false). - -start_link_packet(InHandler, - AgentIp, UdpPort, TrapUdp, - VsnHdr, Version, Dir, BufSz, - Dbg) when is_integer(UdpPort) -> - Args = [self(), InHandler, - AgentIp, UdpPort, TrapUdp, - VsnHdr, Version, Dir, BufSz, - Dbg], +start_link_packet( + InHandler, AgentIp, UdpPort, TrapUdp, VsnHdr, Version, Dir, BufSz) -> + start_link_packet( + InHandler, AgentIp, UdpPort, TrapUdp, VsnHdr, Version, Dir, BufSz, + false). + +start_link_packet( + InHandler, AgentIp, UdpPort, TrapUdp, VsnHdr, Version, Dir, BufSz, + Dbg) -> + start_link_packet( + InHandler, AgentIp, UdpPort, TrapUdp, VsnHdr, Version, Dir, BufSz, + Dbg, inet). + +start_link_packet( + InHandler, AgentIp, UdpPort, TrapUdp, VsnHdr, Version, Dir, BufSz, + Dbg, IpFamily) when is_integer(UdpPort) -> + Args = + [self(), + InHandler, AgentIp, UdpPort, TrapUdp, VsnHdr, Version, Dir, BufSz, + Dbg, IpFamily], proc_lib:start_link(?MODULE, init_packet, Args). stop(Pid) -> @@ -90,12 +94,14 @@ send_bytes(Bytes, PacketPid) -> %%-------------------------------------------------- %% The SNMP encode/decode process %%-------------------------------------------------- -init_packet(Parent, SnmpMgr, - AgentIp, UdpPort, TrapUdp, - VsnHdr, Version, Dir, BufSz, DbgOptions) -> +init_packet( + Parent, + SnmpMgr, AgentIp, UdpPort, TrapUdp, VsnHdr, Version, Dir, BufSz, + DbgOptions, IpFamily) -> put(sname, mgr_misc), init_debug(DbgOptions), - {ok, UdpId} = gen_udp:open(TrapUdp, [{recbuf,BufSz},{reuseaddr, true}]), + {ok, UdpId} = + gen_udp:open(TrapUdp, [{recbuf,BufSz}, {reuseaddr, true}, IpFamily]), put(msg_id, 1), proc_lib:init_ack(Parent, self()), init_usm(Version, Dir), -- cgit v1.2.3 From c5d0122795f8294478f0bafce53ef72c369fd2cc Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 28 Jul 2014 15:41:06 +0200 Subject: Fix call to non-existent function --- lib/snmp/src/manager/snmpm_conf.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index ed4cfd749e..888f19aec6 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -308,7 +308,7 @@ read_usm_config(Dir) check_usm_user_config(Entry, State) -> - {check_ok(snmpm_config:check_usrm_user_config(Entry)), + {check_ok(snmpm_config:check_usm_user_config(Entry)), State}. write_usm_conf(Fd, "", Conf) -> -- cgit v1.2.3 From 87301df2f4d22153364f11d1c07a5be1e9423c13 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 28 Jul 2014 16:32:55 +0200 Subject: Adjust test cases for daily builds --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 65 +++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 23 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 78c3a53f89..a54fb58117 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -91,7 +91,8 @@ init_per_group(ipv6, Config) -> TrapAddr = {IpAddr, ManagerPort}, Versions = [v2], agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv6} + [{snmp_versions, Versions}, {ip_version, ipv6}, + {trapaddrs, [IpAddr]} | Config]; _ -> {skip, "Host does not support IPV6"} @@ -108,7 +109,8 @@ init_per_group(ipv4, Config) -> TrapAddr = {IpAddr, ManagerPort}, Versions = [v2], agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv4} + [{snmp_versions, Versions}, {ip_version, ipv4}, + {trapaddrs, [IpAddr]} | Config]; %% init_per_group(dual_ip, Config) -> @@ -131,8 +133,8 @@ init_per_group(dual_ip, Config) -> {transportDomainUdpIpv6, {IPv6Addr, ManagerPort}}], Versions = [v2], agent_config(Dir, Transports, Targets, Versions), - [{host, Host}, {port, ?AGENT_PORT}, - {snmp_versions, Versions} + [{port, ?AGENT_PORT}, {snmp_versions, Versions}, + {trapaddrs, [IPv4Addr, IPv6Addr]} | NewConfig]; _ -> {skip, "Host does not support IPV6"} @@ -178,9 +180,26 @@ end_per_testcase(_, Config) -> find_executables([], Config) -> Config; find_executables([Exec | Execs], Config) -> - case os:find_executable(atom_to_list(Exec)) of + ExecStr = atom_to_list(Exec), + case os:find_executable(ExecStr) of false -> - {skip, Exec ++ " not found"}; + find_sys_executables( + Execs, Config, Exec, ExecStr, + [["usr", "local", "sbin"], + ["usr", "sbin"], + ["sbin"]]); + Path -> + find_executables( + Execs, + [{Exec, Path} | Config]) + end. + +find_sys_executables(_Execs, _Config, _Exec, ExecStr, []) -> + {skip, ExecStr ++ " not found"}; +find_sys_executables(Execs, Config, Exec, ExecStr, [Dir | Dirs]) -> + case os:find_executable(filename:join(["/" | Dir] ++ [ExecStr])) of + false -> + find_sys_executables(Execs, Config, Exec, ExecStr, Dirs); Path -> find_executables( Execs, @@ -220,17 +239,15 @@ erlang_agent_dual_ip_get(Config) when is_list(Config) -> %%-------------------------------------------------------------------- erlang_agent_netsnmp_inform(Config) when is_list(Config) -> - Host = ?config(host, Config), - IPVersion = ?config(ip_version, Config), - DataDir = ?config(data_dir, Config), + [TrapAddr | _] = ?config(trapaddrs, Config), + DataDir = ?config(data_dir, Config), Mib = "TestTrapv2", start_agent(Config), ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), - TrapAddr = net_snmp_transport(IPVersion) ++ Host ++ - ":" ++ integer_to_list(?config(manager_port, Config)), - ProgHandle = start_snmptrapd(Mib, TrapAddr, Config), + TrapAddrStr = net_snmp_addr_str(TrapAddr, ?config(manager_port, Config)), + ProgHandle = start_snmptrapd(Mib, TrapAddrStr, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -252,7 +269,7 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> %%-------------------------------------------------------------------- erlang_agent_dual_ip_inform(Config) when is_list(Config) -> - Host = ?config(host, Config), + [TrapAddr1, TrapAddr2 | _] = ?config(trapaddrs, Config), ManagerPort = ?config(manager_port, Config), DataDir = ?config(data_dir, Config), Mib = "TestTrapv2", @@ -260,11 +277,10 @@ erlang_agent_dual_ip_inform(Config) when is_list(Config) -> start_agent(Config), ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), - ManagerPortStr = integer_to_list(ManagerPort), TrapAddrs = - net_snmp_transport(ipv4) ++ Host ++ ":" ++ ManagerPortStr ++ + net_snmp_addr_str(TrapAddr1, ManagerPort) ++ "," ++ - net_snmp_transport(ipv6) ++ Host ++ ":" ++ ManagerPortStr, + net_snmp_addr_str(TrapAddr2, ManagerPort), ProgHandle = start_snmptrapd(Mib, TrapAddrs, Config), snmpa:send_notification( @@ -301,15 +317,14 @@ erlang_agent_dual_ip_inform_responses([Address | Addresses]) -> %%-------------------------------------------------------------------- snmpget(Oid, Config) -> Versions = ?config(snmp_versions, Config), - IPVersion = ?config(ip_version, Config), - Host = ?config(host, Config), + [TrapAddr | _] = ?config(trapaddrs, Config), Port = ?config(agent_port, Config), Args = ["-c", "public", net_snmp_version(Versions), "-m", "", "-Cf", - net_snmp_transport(IPVersion)++Host++":"++ integer_to_list(Port), + net_snmp_addr_str(TrapAddr, Port), oid_str(Oid)], ProgHandle = start_program(snmpget, Args, none, Config), {_, line, Line} = get_program_output(ProgHandle), @@ -471,7 +486,11 @@ net_snmp_version([v2 | _]) -> net_snmp_version([v1 | _]) -> "-v1". -net_snmp_transport(ipv4) -> - "udp:"; -net_snmp_transport(ipv6) -> - "udp6:". +net_snmp_addr_str(IPv4Addr, Port) when tuple_size(IPv4Addr) =:= 4 -> + "udp:" ++ + inet_parse:ntoa(IPv4Addr) ++ ":" ++ + integer_to_list(Port); +net_snmp_addr_str(IPv6Addr, Port) when tuple_size(IPv6Addr) =:= 8 -> + "udp6:[" ++ + inet_parse:ntoa(IPv6Addr) ++ "]:" ++ + integer_to_list(Port). -- cgit v1.2.3 From fbc5e6a9a58e6d923442e260003e0c6d554749d0 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 29 Jul 2014 11:11:10 +0200 Subject: Fix testcase for really dual ip --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 170 +++++++++++--------------------- 1 file changed, 59 insertions(+), 111 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index a54fb58117..69d54570ea 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -68,8 +68,8 @@ groups() -> {inform, [], [erlang_agent_netsnmp_inform]}, {dual_ip, [], - [erlang_agent_dual_ip_get, - erlang_agent_dual_ip_inform]} + [erlang_agent_netsnmp_get, + erlang_agent_netsnmp_inform]} ]. init_per_suite(Config) -> @@ -81,61 +81,20 @@ end_per_suite(_Config) -> init_per_group(ipv6, Config) -> case ct:require(ipv6_hosts) of ok -> - Dir = ?config(priv_dir, Config), - Domain = transportDomainUdpIpv6, - AgentPort = ?config(agent_port, Config), - ManagerPort = ?config(manager_port, Config), - {ok, Host} = inet:gethostname(), - {ok, IpAddr} = inet:getaddr(Host, inet6), - Transports = [{Domain, {IpAddr, AgentPort}}], - TrapAddr = {IpAddr, ManagerPort}, - Versions = [v2], - agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{snmp_versions, Versions}, {ip_version, ipv6}, - {trapaddrs, [IpAddr]} - | Config]; + init_per_group_ip([inet6], Config); _ -> {skip, "Host does not support IPV6"} end; %% init_per_group(ipv4, Config) -> - Dir = ?config(priv_dir, Config), - Domain = transportDomainUdpIpv4, - AgentPort = ?config(agent_port, Config), - ManagerPort = ?config(manager_port, Config), - {ok, Host} = inet:gethostname(), - {ok, IpAddr} = inet:getaddr(Host, inet), - Transports = [{Domain, {IpAddr, AgentPort}}], - TrapAddr = {IpAddr, ManagerPort}, - Versions = [v2], - agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{snmp_versions, Versions}, {ip_version, ipv4}, - {trapaddrs, [IpAddr]} - | Config]; + init_per_group_ip([inet], Config); %% init_per_group(dual_ip, Config) -> case find_executables([snmpget, snmptrapd], Config) of NewConfig when is_list(NewConfig) -> case ct:require(ipv6_hosts) of ok -> - Dir = ?config(priv_dir, Config), - Domain = transportDomainUdpIpv4, - AgentPort = ?config(agent_port, Config), - ManagerPort = ?config(manager_port, Config), - {ok, Host} = inet:gethostname(), - {ok, IPv4Addr} = inet:getaddr(Host, inet), - {ok, IPv6Addr} = inet:getaddr(Host, inet6), - Transports = - [{Domain, {IPv4Addr, AgentPort}}, - {transportDomainUdpIpv6, {IPv6Addr, AgentPort}}], - Targets = - [{Domain, {IPv4Addr, ManagerPort}}, - {transportDomainUdpIpv6, {IPv6Addr, ManagerPort}}], - Versions = [v2], - agent_config(Dir, Transports, Targets, Versions), - [{port, ?AGENT_PORT}, {snmp_versions, Versions}, - {trapaddrs, [IPv4Addr, IPv6Addr]} - | NewConfig]; + init_per_group_ip([inet, inet6], NewConfig); _ -> {skip, "Host does not support IPV6"} end; @@ -153,6 +112,29 @@ init_per_group(inform, Config) -> init_per_group(_, Config) -> Config. +init_per_group_ip(Families, Config) -> + Dir = ?config(priv_dir, Config), + AgentPort = ?config(agent_port, Config), + ManagerPort = ?config(manager_port, Config), + Versions = [v2], + {ok, Host} = inet:gethostname(), + Transports = + [begin + {ok, Addr} = inet:getaddr(Host, Family), + {domain(Family), {Addr, AgentPort}} + end || Family <- Families], + Targets = + [begin + {ok, Addr} = inet:getaddr(Host, Family), + {domain(Family), {Addr, ManagerPort}} + end || Family <- Families], + agent_config(Dir, Transports, Targets, Versions), + [{port, ?AGENT_PORT}, {snmp_versions, Versions}, + {transports, Transports}, {targets, Targets} + | Config]. + + + end_per_group(_GroupName, Config) -> Config. @@ -219,69 +201,23 @@ erlang_agent_netsnmp_get() -> "from snmpnet manager"}]. erlang_agent_netsnmp_get(Config) when is_list(Config) -> + Transports = ?config(transports, Config), start_agent(Config), Oid = ?sysDescr_instance, Expected = expected(Oid, get), - Expected = snmpget(Oid, Config), - ok. - -%%-------------------------------------------------------------------- -erlang_agent_dual_ip_get() -> - [{doc,"Test that we can access erlang snmp agent from both " - "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. -erlang_agent_dual_ip_get(Config) when is_list(Config) -> - start_agent(Config), - Oid = ?sysDescr_instance, - Expected = expected(Oid, get), - Expected = snmpget(Oid, [{ip_version, ipv4} | Config]), - Expected = snmpget(Oid, [{ip_version, ipv6} | Config]), + [Expected = snmpget(Oid, Transport, Config) + || Transport <- Transports], ok. %%-------------------------------------------------------------------- erlang_agent_netsnmp_inform(Config) when is_list(Config) -> - [TrapAddr | _] = ?config(trapaddrs, Config), - DataDir = ?config(data_dir, Config), - Mib = "TestTrapv2", - - start_agent(Config), - ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), - - TrapAddrStr = net_snmp_addr_str(TrapAddr, ?config(manager_port, Config)), - ProgHandle = start_snmptrapd(Mib, TrapAddrStr, Config), - - snmpa:send_notification( - snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), - - receive - {snmp_targets, erlang_agent_test, Addresses} -> - ct:pal("Notification sent to: ~p~n", [Addresses]) - end, - receive - {snmp_notification, erlang_agent_test, {got_response, Address}} -> - ct:pal("Got response from: ~p~n", [Address]), - ok; - {snmp_notification, erlang_agent_test, {no_response, _} = - NoResponse} -> - ct:fail(NoResponse) - end, - - stop_program(ProgHandle). - -%%-------------------------------------------------------------------- -erlang_agent_dual_ip_inform(Config) when is_list(Config) -> - [TrapAddr1, TrapAddr2 | _] = ?config(trapaddrs, Config), - ManagerPort = ?config(manager_port, Config), DataDir = ?config(data_dir, Config), Mib = "TestTrapv2", start_agent(Config), ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), - TrapAddrs = - net_snmp_addr_str(TrapAddr1, ManagerPort) ++ - "," ++ - net_snmp_addr_str(TrapAddr2, ManagerPort), - ProgHandle = start_snmptrapd(Mib, TrapAddrs, Config), + ProgHandle = start_snmptrapd(Mib, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -289,24 +225,24 @@ erlang_agent_dual_ip_inform(Config) when is_list(Config) -> receive {snmp_targets, erlang_agent_test, Addresses} -> ct:pal("Notification sent to: ~p~n", [Addresses]), - erlang_agent_dual_ip_inform_responses(Addresses) + erlang_agent_netsnmp_inform_responses(Addresses) end, stop_program(ProgHandle). -erlang_agent_dual_ip_inform_responses([]) -> +erlang_agent_netsnmp_inform_responses([]) -> receive {snmp_notification, erlang_agent_test, _} = Unexpected -> ct:pal("Unexpected response: ~p", [Unexpected]), - erlang_agent_dual_ip_inform_responses([]) + erlang_agent_netsnmp_inform_responses([]) after 0 -> ok end; -erlang_agent_dual_ip_inform_responses([Address | Addresses]) -> +erlang_agent_netsnmp_inform_responses([Address | Addresses]) -> receive {snmp_notification, erlang_agent_test, {got_response, Address}} -> ct:pal("Got response from: ~p~n", [Address]), - erlang_agent_dual_ip_inform_responses(Addresses); + erlang_agent_netsnmp_inform_responses(Addresses); {snmp_notification, erlang_agent_test, {no_response, _} = NoResponse} -> ct:fail(NoResponse) @@ -315,31 +251,30 @@ erlang_agent_dual_ip_inform_responses([Address | Addresses]) -> %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- -snmpget(Oid, Config) -> +snmpget(Oid, Transport, Config) -> Versions = ?config(snmp_versions, Config), - [TrapAddr | _] = ?config(trapaddrs, Config), - Port = ?config(agent_port, Config), Args = ["-c", "public", net_snmp_version(Versions), "-m", "", "-Cf", - net_snmp_addr_str(TrapAddr, Port), + net_snmp_addr_str(Transport), oid_str(Oid)], ProgHandle = start_program(snmpget, Args, none, Config), {_, line, Line} = get_program_output(ProgHandle), stop_program(ProgHandle), Line. -start_snmptrapd(Mibs, TrapAddrs, Config) -> +start_snmptrapd(Mibs, Config) -> DataDir = ?config(data_dir, Config), MibDir = filename:join(code:lib_dir(snmp), "mibs"), + Targets = ?config(targets, Config), SnmptrapdArgs = ["-f", "-Lo", "-C", "-m", Mibs, "-M", MibDir++":"++DataDir, "--disableAuthorization=yes", - "--snmpTrapdAddr="++TrapAddrs], + "--snmpTrapdAddr=" ++ net_snmp_addr_str(Targets)], {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config). @@ -486,11 +421,24 @@ net_snmp_version([v2 | _]) -> net_snmp_version([v1 | _]) -> "-v1". -net_snmp_addr_str(IPv4Addr, Port) when tuple_size(IPv4Addr) =:= 4 -> +domain(inet) -> + transportDomainUdpIpv4; +domain(inet6) -> + transportDomainUdpIpv6. + +net_snmp_addr_str([Target | Targets]) -> + net_snmp_addr_str(Target) ++ + case Targets of + [] -> + []; + [_ | _] -> + "," ++ net_snmp_addr_str(Targets) + end; +net_snmp_addr_str({transportDomainUdpIpv4, {Addr, Port}}) -> "udp:" ++ - inet_parse:ntoa(IPv4Addr) ++ ":" ++ + inet_parse:ntoa(Addr) ++ ":" ++ integer_to_list(Port); -net_snmp_addr_str(IPv6Addr, Port) when tuple_size(IPv6Addr) =:= 8 -> +net_snmp_addr_str({transportDomainUdpIpv6, {Addr, Port}}) -> "udp6:[" ++ - inet_parse:ntoa(IPv6Addr) ++ "]:" ++ + inet_parse:ntoa(Addr) ++ "]:" ++ integer_to_list(Port). -- cgit v1.2.3 From 010bbdacbab4d4bfff7a7c59968aa333f081e7c5 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 30 Jul 2014 10:10:38 +0200 Subject: Rearrange test suite group structure --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 83 ++++++++++++++------------------- 1 file changed, 36 insertions(+), 47 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 69d54570ea..6e9c57bce9 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -50,7 +50,8 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [ {group, ipv4}, - {group, ipv6} + {group, ipv6}, + {group, ipv4_ipv6} ]. groups() -> @@ -60,16 +61,17 @@ groups() -> ]}, {ipv6, [], [{group, get}, - {group, inform}, - {group, dual_ip} + {group, inform} + ]}, + {ipv4_ipv6, [], + [{group, get}, + {group, inform} ]}, + %% {get, [], [erlang_agent_netsnmp_get]}, {inform, [], - [erlang_agent_netsnmp_inform]}, - {dual_ip, [], - [erlang_agent_netsnmp_get, - erlang_agent_netsnmp_inform]} + [erlang_agent_netsnmp_inform]} ]. init_per_suite(Config) -> @@ -78,40 +80,31 @@ init_per_suite(Config) -> end_per_suite(_Config) -> ok. -init_per_group(ipv6, Config) -> - case ct:require(ipv6_hosts) of - ok -> - init_per_group_ip([inet6], Config); - _ -> - {skip, "Host does not support IPV6"} - end; -%% init_per_group(ipv4, Config) -> init_per_group_ip([inet], Config); -%% -init_per_group(dual_ip, Config) -> - case find_executables([snmpget, snmptrapd], Config) of - NewConfig when is_list(NewConfig) -> - case ct:require(ipv6_hosts) of - ok -> - init_per_group_ip([inet, inet6], NewConfig); - _ -> - {skip, "Host does not support IPV6"} - end; - Other -> - Other - end; +init_per_group(ipv6, Config) -> + init_per_group_ipv6([inet6], Config); +init_per_group(ipv4_ipv6, Config) -> + init_per_group_ipv6([inet, inet6], Config); %% init_per_group(get, Config) -> %% From Ubuntu package snmp - find_executables([snmpget], Config); -%% + find_executable(snmpget, Config); init_per_group(inform, Config) -> - %% From Ubuntu package snmptrapfmt - find_executables([snmptrapd], Config); + %% From Ubuntu package snmpd + find_executable(snmptrapd, Config); +%% init_per_group(_, Config) -> Config. +init_per_group_ipv6(Families, Config) -> + case ct:require(ipv6_hosts) of + ok -> + init_per_group_ip(Families, Config); + _ -> + {skip, "Host does not support IPV6"} + end. + init_per_group_ip(Families, Config) -> Dir = ?config(priv_dir, Config), AgentPort = ?config(agent_port, Config), @@ -159,33 +152,29 @@ end_per_testcase(_, Config) -> end, Config. -find_executables([], Config) -> - Config; -find_executables([Exec | Execs], Config) -> +find_executable(Exec, Config) -> ExecStr = atom_to_list(Exec), case os:find_executable(ExecStr) of false -> - find_sys_executables( - Execs, Config, Exec, ExecStr, + %% The sbin dirs are not in the PATH on all platforms... + find_sys_executable( + Exec, ExecStr, [["usr", "local", "sbin"], ["usr", "sbin"], - ["sbin"]]); + ["sbin"]], + Config); Path -> - find_executables( - Execs, - [{Exec, Path} | Config]) + [{Exec, Path} | Config] end. -find_sys_executables(_Execs, _Config, _Exec, ExecStr, []) -> +find_sys_executable(_Exec, ExecStr, [], _Config) -> {skip, ExecStr ++ " not found"}; -find_sys_executables(Execs, Config, Exec, ExecStr, [Dir | Dirs]) -> +find_sys_executable(Exec, ExecStr, [Dir | Dirs], Config) -> case os:find_executable(filename:join(["/" | Dir] ++ [ExecStr])) of false -> - find_sys_executables(Execs, Config, Exec, ExecStr, Dirs); + find_sys_executable(Exec, ExecStr, Dirs, Config); Path -> - find_executables( - Execs, - [{Exec, Path} | Config]) + [{Exec, Path} | Config] end. start_agent(Config) -> -- cgit v1.2.3 From 3cdb20acd5577fd37a10ac96f6ab37dd0952413f Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 5 Aug 2014 15:07:03 +0200 Subject: Fix misspelled community in manager --- lib/snmp/src/manager/snmpm_config.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 5ebd3a0662..013fefa4e2 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1655,7 +1655,7 @@ init_agent_default() -> {sec_model, v2c}, % SecModel {sec_name, "initial"}, % SecName {sec_level, noAuthPriv}, % SecLevel - {community, "all-rigthts"}], % Community + {community, "all-rights"}], % Community do_update_agent_info(default_agent, AgentDefaultConfig). %% %% Port -- cgit v1.2.3 From 948705328504ca78bce684ded56ce47d35a0068f Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 5 Aug 2014 15:08:12 +0200 Subject: Improve ct_snmp test cases --- lib/snmp/src/agent/snmp_community_mib.erl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_community_mib.erl b/lib/snmp/src/agent/snmp_community_mib.erl index 12a0ec97c2..4546c343b7 100644 --- a/lib/snmp/src/agent/snmp_community_mib.erl +++ b/lib/snmp/src/agent/snmp_community_mib.erl @@ -246,6 +246,10 @@ gc_tabs() -> %%----------------------------------------------------------------- community2vacm(Community, Addr) -> Idxs = ets:lookup(snmp_community_cache, Community), + ?vtrace("community2vacm ->~n" + " Community: ~p~n" + " Addr: ~p~n" + " Idxs: ~p", [Community, Addr, Idxs]), loop_c2v_rows(lists:keysort(2, Idxs), Addr). loop_c2v_rows([{_, CommunityIndex} | T], Addr) -> @@ -253,6 +257,9 @@ loop_c2v_rows([{_, CommunityIndex} | T], Addr) -> "~n CommunityIndex: ~p", [CommunityIndex]), case get_row(CommunityIndex) of {_Community, VacmParams, Tag} -> + ?vtrace("loop_c2v_rows ->~n" + " VacmParams: ~p~n" + " Tag: ~p", [VacmParams, Tag]), {TDomain, TAddr} = Addr, case snmp_target_mib:is_valid_tag(Tag, TDomain, TAddr) of true -> -- cgit v1.2.3 From e910f8568a4d19093f7ea8c6865367c3e73703f0 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 7 Aug 2014 17:31:10 +0200 Subject: Fix error printouts to not crash --- lib/snmp/src/agent/snmp_framework_mib.erl | 6 ++++-- lib/snmp/src/agent/snmpa_net_if.erl | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 922215ff00..9d3f7ef5e7 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -201,9 +201,11 @@ check_agent({intAgentIpAddress, _}, {_, undefined}) -> check_agent({intAgentIpAddress = Tag, Ip} = Entry, {Domain, Port} = State) -> {case snmp_conf:check_ip(Domain, Ip) of ok -> - [Entry, {intAgentTransports, [{Domain, {Ip, Port}}]}]; + [Entry, + {intAgentTransports, [{Domain, {Ip, Port}}]}]; {ok, FixedIp} -> - [{Tag, Ip}, {intAgentTransports, [{Domain, {FixedIp, Port}}]}] + [{Tag, FixedIp}, + {intAgentTransports, [{Domain, {FixedIp, Port}}]}] end, State}; check_agent({intAgentTransports = Tag, Transports}, {_, Port} = State) -> CheckedTransports = diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 389c26834d..840d56d563 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -1064,7 +1064,7 @@ do_handle_send_pdu1( "Can not find transport~n" " size: ~p~n" " to: ~s", - [sz(Packet), To]); + [sz(Packet), format_address(To)]); Transport -> maybe_udp_send(S, Transport, To, Packet) end; @@ -1080,7 +1080,7 @@ do_handle_send_pdu1( "Can not find transport~n" " size: ~p~n" " to: ~s", - [sz(Packet), To]); + [sz(Packet), format_address(To)]); Transport -> maybe_udp_send(S, Transport, To, Packet, Type, LogData) end -- cgit v1.2.3 From 3e871d69871fd30b4a3f97766bdaf6ea6b3cc092 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Thu, 7 Aug 2014 17:36:36 +0200 Subject: Update release notes --- lib/snmp/doc/src/notes.xml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 06674095f2..15efd47a1c 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,7 +33,29 @@
-
SNMP 4.25.1 +
SNMP 5.0 + +
Improvements and New Features + + +

+ SNMP has been improved to handle IPv6. The agent can + handle dual stack IPv4 + IPv6, but not yet the manager. + The documentation also still lags behind... If you do + such advanced stuff like writing a custom net_if module, + the interface for it has changed, but other than that + SNMP is backwards compatible.

+

+ *** POTENTIAL INCOMPATIBILITY ***

+

+ Own Id: OTP-12020 Aux Id: OTP-11518

+
+
+
+ +
+ +
SNMP 4.25.1
Fixed Bugs and Malfunctions -- cgit v1.2.3 From 215b2305cad4f1bc45fd33677198e3887d200869 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 8 Aug 2014 10:04:55 +0200 Subject: Rewrite manager net_if for IPv4+IPv6 --- lib/snmp/src/manager/snmpm_conf.erl | 1 + lib/snmp/src/manager/snmpm_config.erl | 372 ++++++-------------------- lib/snmp/src/manager/snmpm_net_if.erl | 490 +++++++++++++++++++++------------- lib/snmp/src/misc/snmp_config.erl | 40 ++- 4 files changed, 412 insertions(+), 491 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index 888f19aec6..e03d28a3e4 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -114,6 +114,7 @@ do_write_manager_conf(Fd, {Tag, Val}) when Tag =:= domain; Tag =:= address; Tag =:= port; + Tag =:= transports; Tag =:= max_message_size -> io:format(Fd, "{~w, ~w}.~n", [Tag, Val]); do_write_manager_conf(Fd, {Tag, Val}) diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 013fefa4e2..d147aabb0b 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1287,36 +1287,6 @@ verify_options(Opts, Mandatory) -> verify_mandatory_options(Opts, Mandatory), verify_options(Opts). -%% mandatory() -> [mand()] -%% mand() -> atom() | {atom, [atom()]} -verify_mandatory_options(_Opts, []) -> - ok; -verify_mandatory_options(Opts, [Mand|Mands]) -> - verify_mandatory_option(Opts, Mand), - verify_mandatory_options(Opts, Mands). - -verify_mandatory_option(Opts, {Mand, MandSubOpts}) -> - ?d("verify_mandatory_option -> entry with" - "~n Mand: ~p" - "~n MandSubObjs: ~p", [Mand, MandSubOpts]), - case lists:keysearch(Mand, 1, Opts) of - {value, {Mand, SubOpts}} -> - verify_mandatory_options(SubOpts, MandSubOpts); - false -> - ?d("missing mandatory option: ~w [~p]", [Mand, MandSubOpts]), - error({missing_mandatory, Mand, MandSubOpts}) - end; -verify_mandatory_option(Opts, Mand) -> - ?d("verify_mandatory_option -> entry with" - "~n Mand: ~p", [Mand]), - case lists:keymember(Mand, 1, Opts) of - true -> - ok; - false -> - ?d("missing mandatory option: ~w", [Mand]), - error({missing_mandatory, Mand}) - end. - verify_options([]) -> ?d("verify_options -> done", []), ok; @@ -1632,7 +1602,38 @@ verify_verbosity(Verbosity) -> _ -> error({invalid_verbosity, Verbosity}) end. + +%% mandatory() -> [mand()] +%% mand() -> atom() | {atom, [atom()]} +verify_mandatory_options(_Opts, []) -> + ok; +verify_mandatory_options(Opts, [Mand|Mands]) -> + verify_mandatory_option(Opts, Mand), + verify_mandatory_options(Opts, Mands). + +verify_mandatory_option(Opts, {Mand, MandSubOpts}) -> + ?d("verify_mandatory_option -> entry with" + "~n Mand: ~p" + "~n MandSubObjs: ~p", [Mand, MandSubOpts]), + case lists:keysearch(Mand, 1, Opts) of + {value, {Mand, SubOpts}} -> + verify_mandatory_options(SubOpts, MandSubOpts); + false -> + ?d("missing mandatory option: ~w [~p]", [Mand, MandSubOpts]), + error({missing_mandatory, Mand, MandSubOpts}) + end; +verify_mandatory_option(Opts, Mand) -> + ?d("verify_mandatory_option -> entry with" + "~n Mand: ~p", [Mand]), + case lists:keymember(Mand, 1, Opts) of + true -> + ok; + false -> + ?d("missing mandatory option: ~w", [Mand]), + error({missing_mandatory, Mand}) + end. + %% ------------------------------------------------------------------------ init_manager_config([]) -> @@ -1654,69 +1655,10 @@ init_agent_default() -> {version, v2}, % MPModel {sec_model, v2c}, % SecModel {sec_name, "initial"}, % SecName - {sec_level, noAuthPriv}, % SecLevel + {sec_level, noAuthNoPriv}, % SecLevel {community, "all-rights"}], % Community do_update_agent_info(default_agent, AgentDefaultConfig). -%% %% Port -%% init_agent_default(port, ?DEFAULT_AGENT_PORT), - -%% %% Timeout -%% init_agent_default(timeout, 10000), - -%% %% Max message (packet) size -%% init_agent_default(max_message_size, 484), - -%% %% MPModel -%% init_agent_default(version, v2), - -%% %% SecModel -%% init_agent_default(sec_model, v2c), - -%% %% SecName -%% init_agent_default(sec_name, "initial"), - -%% %% SecLevel -%% init_agent_default(sec_level, noAuthNoPriv), - -%% %% Community -%% init_agent_default(community, "all-rights"), -%% ok. - - -%% init_agent_default(Item, Val) when Item =/= user_id -> -%% case do_update_agent_info(default_agent, Item, Val) of -%% ok -> -%% ok; -%% {error, Reason} -> -%% error(Reason) -%% end. - -%% read_agents_config_file(Dir) -> -%% Verify = fun check_agent_config2/1, -%% case read_file(Dir, "agents.conf", Verify, []) of -%% {ok, Conf} -> -%% Conf; -%% Error -> -%% ?vlog("agent config error: ~p", [Error]), -%% throw(Error) -%% end. - -%% check_agent_config2(Agent) -> -%% case (catch check_agent_config(Agent)) of -%% {ok, {UserId, TargetName, Conf, Version}} -> -%% {ok, Vsns} = system_info(versions), -%% case lists:member(Version, Vsns) of -%% true -> -%% {ok, {UserId, TargetName, Conf}}; -%% false -> -%% error({version_not_supported_by_manager, -%% Version, Vsns}) -%% end; -%% Err -> -%% throw(Err) -%% end. - read_agents_config_file(Dir) -> Order = fun snmp_conf:no_order/2, Check = fun check_agent_config/2, @@ -1738,12 +1680,20 @@ check_agent_config(Agent, State) -> end. %% For backward compatibility +check_agent_config( + {UserId, TargetName, Community, Domain, Addr, + EngineId, Timeout, MaxMessageSize, + Version, SecModel, SecName, SecLevel}) when is_atom(Domain) -> + check_agent_config( + UserId, TargetName, Community, Domain, Addr, + EngineId, Timeout, MaxMessageSize, + Version, SecModel, SecName, SecLevel); check_agent_config( {UserId, TargetName, Community, Ip, Port, EngineId, Timeout, MaxMessageSize, - Version, SecModel, SecName, SecLevel}) -> + Version, SecModel, SecName, SecLevel}) when is_integer(Port) -> Domain = default_transport_domain(), - Addr = fix_address(Domain, {Ip, Port}), + Addr = {Ip, Port}, check_agent_config( UserId, TargetName, Community, Domain, Addr, EngineId, Timeout, MaxMessageSize, @@ -1752,8 +1702,9 @@ check_agent_config( {UserId, TargetName, Community, Domain, Ip, Port, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}) -> + Addr = {Ip, Port}, check_agent_config( - UserId, TargetName, Community, Domain, {Ip, Port}, + UserId, TargetName, Community, Domain, Addr, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel); check_agent_config(Agent) -> @@ -1776,7 +1727,7 @@ check_agent_config( Conf = [{reg_type, target_name}, {tdomain, Domain}, - {taddress, Addr}, + {taddress, fix_address(Domain, Addr)}, {community, Comm}, {engine_id, EngineId}, {timeout, Timeout}, @@ -1946,16 +1897,6 @@ verify_agent_entry(Item, _) -> -%% read_users_config_file(Dir) -> -%% Verify = fun check_user_config/1, -%% case read_file(Dir, "users.conf", Verify, []) of -%% {ok, Conf} -> -%% Conf; -%% Error -> -%% ?vlog("failure reading users config file: ~n ~p", [Error]), -%% throw(Error) -%% end. - read_users_config_file(Dir) -> Order = fun snmp_conf:no_order/2, Check = fun (User, State) -> {check_user_config(User), State} end, @@ -2074,14 +2015,6 @@ verify_default_agent_config(Conf) -> error({bad_default_agent_config, Error}) end. -%% read_usm_config_file(Dir) -> -%% Verify = fun check_usm_user_config/1, -%% case read_file(Dir, "usm.conf", Verify, []) of -%% {ok, Conf} -> -%% Conf; -%% Error -> -%% throw(Error) -%% end. read_usm_config_file(Dir) -> Order = fun snmp_conf:no_order/2, @@ -2268,24 +2201,6 @@ is_crypto_supported(Func) -> snmp_misc:is_crypto_supported(Func). -%% read_manager_config_file(Dir) -> -%% Verify = fun check_manager_config/1, -%% case read_file(Dir, "manager.conf", Verify) of -%% {ok, Conf} -> -%% ?d("read_manager_config_file -> ok: " -%% "~n Conf: ~p", [Conf]), -%% %% If the address is not specified, then we assume -%% %% it should be the local host. -%% %% If the address is not possible to determine -%% %% that way, then we give up... -%% verify_mandatory(Conf, [port,engine_id,max_message_size]), -%% ensure_config(default_manager_config(), Conf); -%% %% check_mandatory_manager_config(Conf), -%% %% ensure_manager_config(Conf); -%% Error -> -%% throw(Error) -%% end. - read_manager_config_file(Dir) -> Order = fun order_manager_config/2, Check = fun check_manager_config/2, @@ -2296,13 +2211,15 @@ read_manager_config_file(Dir) -> %% it should be the local host. %% If the address is not possible to determine %% that way, then we give up... - verify_mandatory(Conf, [port,engine_id,max_message_size]), + verify_someof(Conf, [port, transports]), + verify_mandatory(Conf, [engine_id, max_message_size]), default_manager_config(Conf). default_manager_config(Conf) -> - %% Ensure address of right family - case lists:keyfind(address, 1, Conf) of + %% Ensure valid transports entry + case lists:keyfind(transports, 1, Conf) of false -> + {port, Port} = lists:keyfind(port, 1, Conf), Domain = case lists:keyfind(domain, 1, Conf) of false -> @@ -2311,55 +2228,55 @@ default_manager_config(Conf) -> D end, Family = snmp_conf:tdomain_to_family(Domain), - {ok, HostName} = inet:gethostname(), - case inet:getaddr(HostName, Family) of + {ok, Hostname} = inet:gethostname(), + case inet:getaddr(Hostname, Family) of {ok, Address} -> - [{address, Address} | Conf]; + lists:sort( + fun order_manager_config/2, + [{transports, [{Domain, {Address, Port}}]} | Conf]); {error, _Reason} -> ?d("default_manager_config -> " "failed getting ~w address for ~s:~n" - " _Reason: ~p", [Family, HostName, _Reason]), + " _Reason: ~p", [Family, Hostname, _Reason]), Conf end; _ -> Conf end. -default_manager_config() -> - {ok, HostName} = inet:gethostname(), - case inet:getaddr(HostName, inet) of - {ok, A} -> - [{address, tuple_to_list(A)}]; - {error, _Reason} -> - ?d("default_manager_config -> failed getting address: " - "~n _Reason: ~p", [_Reason]), - [] - end. - order_manager_config(EntryA, EntryB) -> - snmp_conf:keyorder(1, EntryA, EntryB, [domain]). - -check_manager_config({domain, D}, _Domain) -> - {snmp_conf:check_domain(D), D}; -check_manager_config({address = Tag, Ip}, D) -> - Domain = - case D of - undefined -> - default_transport_domain(); - _ -> - D - end, + snmp_conf:keyorder(1, EntryA, EntryB, [domain, port]). + +check_manager_config(Entry, undefined) -> + check_manager_config(Entry, {default_transport_domain(), undefined}); +check_manager_config({domain, Domain}, {_, Port}) -> + {snmp_conf:check_domain(Domain), {Domain, Port}}; +check_manager_config({port, Port}, {Domain, _}) -> + {ok = snmp_conf:check_port(Port), {Domain, Port}}; +check_manager_config({address, _}, {_, undefined}) -> + error({missing_mandatory, port}); +check_manager_config({address = Tag, Ip} = Entry, {Domain, Port} = State) -> {case snmp_conf:check_ip(Domain, Ip) of ok -> - ok; + [Entry, + {transports, [{Domain, {Ip, Port}}]}]; {ok, FixedIp} -> - {ok, {Tag, FixedIp}} - end, Domain}; -check_manager_config(Entry, Domain) -> - {check_manager_config(Entry), Domain}. + [{Tag, FixedIp}, + {transports, [{Domain, {FixedIp, Port}}]}] + end, State}; +check_manager_config({transports = Tag, Transports}, State) -> + CheckedTransports = + [case snmp_conf:check_address(Domain, Address) of + ok -> + Transport; + {ok, FixedAddress} -> + {Domain, FixedAddress} + end + || {Domain, Address} = Transport <- Transports], + {{ok, {Tag, CheckedTransports}}, State}; +check_manager_config(Entry, State) -> + {check_manager_config(Entry), State}. -check_manager_config({port, Port}) -> - snmp_conf:check_port(Port); check_manager_config({engine_id, EngineID}) -> snmp_conf:check_string(EngineID); check_manager_config({max_message_size, Max}) -> @@ -2368,45 +2285,6 @@ check_manager_config(Conf) -> error({unknown_config, Conf}). -%% check_mandatory_manager_config(Conf) -> -%% Mand = [port, engine_id, max_message_size], -%% check_mandatory_manager_config(Mand, Conf). - -%% check_mandatory_manager_config([], _Conf) -> -%% ok; -%% check_mandatory_manager_config([Item|Mand], Conf) -> -%% case lists:keysearch(Item, 1, Conf) of -%% false -> -%% error({missing_mandatory_manager_config, Item}); -%% _ -> -%% check_mandatory_manager_config(Mand, Conf) -%% end. - - -%% ensure_manager_config(Confs) -> -%% ensure_manager_config(Confs, default_manager_config()). - -%% ensure_manager_config(Confs, []) -> -%% Confs; -%% ensure_manager_config(Confs, [{Key,_} = DefKeyVal|Defs]) -> -%% case lists:keysearch(Key, 1, Confs) of -%% false -> -%% ensure_manager_config([DefKeyVal|Confs], Defs); -%% {value, _Conf} -> -%% ensure_manager_config(Confs, Defs) -%% end. - -% ensure_manager_config([], Defs, Confs) -> -% Confs ++ Defs; -% ensure_manager_config(Confs0, [{Key, DefVal}|Defs], Acc) -> -% case lists:keysearch(Key, 1, Confs0) of -% false -> -% ensure_manager_config(Confs0, Defs, [{Key, DefVal}|Acc]); -% {value, Conf} -> -% Confs = lists:keydelete(Key, 1, Confs0), -% ensure_manager_config(Confs, Defs, [Conf|Acc]) -% end. - read_file(Dir, FileName, Order, Check, Default) -> try snmp_conf:read(filename:join(Dir, FileName), Order, Check) catch @@ -2424,87 +2302,6 @@ read_file(Dir, FileName, Order, Check) -> erlang:raise(throw, Error, erlang:get_stacktrace()) end. - - - - - -%% read_file(Dir, FileName, Verify, Default) -> -%% File = filename:join(Dir, FileName), -%% case file:read_file_info(File) of -%% {ok, _} -> -%% read_file(File, Verify); -%% {error, Reason} -> -%% ?vlog("failed reading config from ~s: ~p", [FileName, Reason]), -%% {ok, Default} -%% end. - -%% read_file(Dir, FileName, Verify) -> -%% File = filename:join(Dir, FileName), -%% case file:read_file_info(File) of -%% {ok, _} -> -%% read_file(File, Verify); -%% {error, Reason} -> -%% error_msg("failed reading config from ~s: ~p", [FileName, Reason]), -%% {error, {failed_reading, FileName, Reason}} -%% end. - -%% read_file(File, Verify) -> -%% Check = fun (Config, State) -> {Verify(Config), State} end, -%% try snmp_conf:read(File, Check) of -%% Conf -> -%% ?vtrace("read_file -> read ok" -%% "~n Conf: ~p", [Conf]), -%% {ok, Conf} -%% catch -%% Error -> -%% ?vtrace("read_file -> read failed:" -%% "~n Error: ~p", [Error]), -%% Error -%% end. - -%% XXX remove - -%% read_file(Dir, FileName, Check, Default) -> -%% File = filename:join(Dir, FileName), -%% case file:read_file_info(File) of -%% {ok, _} -> -%% case (catch do_read(File, Check)) of -%% {ok, Conf} -> -%% {ok, Conf}; -%% Error -> -%% ?vtrace("read_file -> read failed:" -%% "~n Error: ~p", [Error]), -%% Error -%% end; -%% {error, Reason} -> -%% ?vlog("failed reading config from ~s: ~p", [FileName, Reason]), -%% {ok, Default} -%% end. - -%% read_file(Dir, FileName, Check) -> -%% File = filename:join(Dir, FileName), -%% case file:read_file_info(File) of -%% {ok, _} -> -%% case (catch do_read(File, Check)) of -%% {ok, Conf} -> -%% ?vtrace("read_file -> read ok" -%% "~n Conf: ~p", [Conf]), -%% {ok, Conf}; -%% Error -> -%% ?vtrace("read_file -> read failed:" -%% "~n Error: ~p", [Error]), -%% Error -%% end; -%% {error, Reason} -> -%% error_msg("failed reading config from ~s: ~p", [FileName, Reason]), -%% {error, {failed_reading, FileName, Reason}} -%% end. - -%% do_read(File, Check) -> -%% {ok, snmp_conf:read(File, Check)}. - - %%-------------------------------------------------------------------- %% Func: handle_call/3 %% Returns: {reply, Reply, State} | @@ -3582,4 +3379,3 @@ error_msg(F, A) -> p(F, A) -> io:format("~w:" ++ F ++ "~n", [?MODULE | A]). - diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index 860b0b83dd..c4716dfd21 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -59,8 +59,9 @@ { server, note_store, - domain, - sock, +%% domain, +%% sock, + transports = [], mpd_state, log, irb = auto, % auto | {user, integer()} @@ -68,6 +69,9 @@ filter }). +-record(transport, + {socket, + domain = snmpUDPDomain}). -define(DEFAULT_FILTER_MODULE, snmpm_net_if_filter). -define(DEFAULT_FILTER_OPTS, [{module, ?DEFAULT_FILTER_MODULE}]). @@ -161,12 +165,17 @@ init([Server, NoteStore]) -> ?d("init -> entry with" "~n Server: ~p" "~n NoteStore: ~p", [Server, NoteStore]), - case (catch do_init(Server, NoteStore)) of + try do_init(Server, NoteStore) + catch {error, Reason} -> - {stop, Reason}; - {ok, State} -> - {ok, State} + {stop, Reason} end. + %% case (catch do_init(Server, NoteStore)) of + %% {error, Reason} -> + %% {stop, Reason}; + %% {ok, State} -> + %% {ok, State} + %% end. do_init(Server, NoteStore) -> process_flag(trap_exit, true), @@ -196,21 +205,6 @@ do_init(Server, NoteStore) -> {ok, IRB} = snmpm_config:system_info(net_if_irb), IrGcRef = irgc_start(IRB), - %% -- Socket -- - SndBuf = get_opt(Opts, sndbuf, default), - RecBuf = get_opt(Opts, recbuf, default), - BindTo = get_opt(Opts, bind_to, false), - NoReuse = get_opt(Opts, no_reuse, false), - {ok, Port} = snmpm_config:system_info(port), - Domain = - case snmpm_config:system_info(domain) of - {ok, D} -> - D; - _ -> - snmpm_config:default_transport_domain() - end, - {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), - %% Flow control -- FilterOpts = get_opt(Opts, filter, []), FilterMod = create_filter(FilterOpts), @@ -220,82 +214,197 @@ do_init(Server, NoteStore) -> {ok, ATL} = snmpm_config:system_info(audit_trail_log), Log = do_init_log(ATL), - %% -- Initiate counters --- - init_counters(), + {ok, DomainAddresses} = snmpm_config:system_info(transports), + ?vdebug("DomainAddresses: ~w",[DomainAddresses]), + CommonSocketOpts = common_socket_opts(Opts), + BindTo = get_opt(Opts, bind_to, false), + case + [begin + {IpPort, SocketOpts} = + socket_params(Domain, Address, BindTo, CommonSocketOpts), + Socket = socket_open(IpPort, SocketOpts), + #transport{socket = Socket, domain = Domain} + end || {Domain, Address} <- DomainAddresses] + of + [] -> + ?vinfo("No transports configured: ~p", [DomainAddresses]), + throw({error, {no_transports,DomainAddresses}}); + Transports -> + %% -- Initiate counters --- + init_counters(), + + %% -- We are done --- + State = #state{ + server = Server, + note_store = NoteStore, + mpd_state = MpdState, + transports = Transports, + log = Log, + irb = IRB, + irgc = IrGcRef, + filter = FilterMod}, + ?vdebug("started", []), + {ok, State} + end. - %% -- We are done --- - State = #state{server = Server, - note_store = NoteStore, - mpd_state = MpdState, - domain = Domain, - sock = Sock, - log = Log, - irb = IRB, - irgc = IrGcRef, - filter = FilterMod}, - ?vdebug("started", []), - {ok, State}. -%% Open port -do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> - ?vtrace("do_open_port -> entry with~n" - " Port: ~p~n" - " SendSz: ~p~n" - " RecvSz: ~p~n" - " Domain: ~p~n" - " BindTo: ~p~n" - " NoReuse: ~p", - [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), - IpOpts1 = bind_to(BindTo), - IpOpts2 = no_reuse(NoReuse), - IpOpts3 = recbuf(RecvSz), - IpOpts4 = sndbuf(SendSz), - IpOpts = - [binary, - snmp_conf:tdomain_to_family(Domain) | - IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], - OpenRes = - case init:get_argument(snmpm_fd) of - {ok, [[FdStr]]} -> - Fd = list_to_integer(FdStr), - gen_udp:open(0, [{fd, Fd}|IpOpts]); - error -> - gen_udp:open(Port, IpOpts) - end, - case OpenRes of + %% %% -- Socket -- + %% SndBuf = get_opt(Opts, sndbuf, default), + %% RecBuf = get_opt(Opts, recbuf, default), + %% BindTo = get_opt(Opts, bind_to, false), + %% NoReuse = get_opt(Opts, no_reuse, false), + + %% {ok, Port} = snmpm_config:system_info(port), + %% Domain = + %% case snmpm_config:system_info(domain) of + %% {ok, D} -> + %% D; + %% _ -> + %% snmpm_config:default_transport_domain() + %% end, + %% {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), + + %% %% -- Initiate counters --- + %% init_counters(), + + %% %% -- We are done --- + %% State = #state{server = Server, + %% note_store = NoteStore, + %% mpd_state = MpdState, + %% domain = Domain, + %% sock = Sock, + %% log = Log, + %% irb = IRB, + %% irgc = IrGcRef, + %% filter = FilterMod}, + %% ?vdebug("started", []), + %% {ok, State}. + + +%% %% Open port +%% do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> +%% ?vtrace("do_open_port -> entry with~n" +%% " Port: ~p~n" +%% " SendSz: ~p~n" +%% " RecvSz: ~p~n" +%% " Domain: ~p~n" +%% " BindTo: ~p~n" +%% " NoReuse: ~p", +%% [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), +%% IpOpts1 = bind_to(BindTo), +%% IpOpts2 = no_reuse(NoReuse), +%% IpOpts3 = recbuf(RecvSz), +%% IpOpts4 = sndbuf(SendSz), +%% IpOpts = +%% [binary, +%% snmp_conf:tdomain_to_family(Domain) | +%% IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], +%% OpenRes = +%% case init:get_argument(snmpm_fd) of +%% {ok, [[FdStr]]} -> +%% Fd = list_to_integer(FdStr), +%% gen_udp:open(0, [{fd, Fd}|IpOpts]); +%% error -> +%% gen_udp:open(Port, IpOpts) +%% end, +%% case OpenRes of +%% {error, _} = Error -> +%% throw(Error); +%% OK -> +%% OK +%% end. + +socket_open(IpPort, SocketOpts) -> + ?vtrace("socket_open -> entry with~n" + " IpPort: ~p~n" + " SocketOpts: ~p", [IpPort, SocketOpts]), + case gen_udp:open(IpPort, SocketOpts) of {error, _} = Error -> throw(Error); - OK -> - OK + {ok, Socket} -> + Socket end. -bind_to(true) -> - case snmpm_config:system_info(address) of - {ok, Addr} when is_list(Addr) -> - [{ip, list_to_tuple(Addr)}]; - {ok, Addr} -> - [{ip, Addr}]; +%% bind_to(true) -> +%% case snmpm_config:system_info(address) of +%% {ok, Addr} when is_list(Addr) -> +%% [{ip, list_to_tuple(Addr)}]; +%% {ok, Addr} -> +%% [{ip, Addr}]; +%% _ -> +%% [] +%% end; +%% bind_to(_) -> +%% []. + +socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) -> + Family = snmp_conf:tdomain_to_family(Domain), + SocketOpts = + case Family of + inet6 -> + [Family, {ipv6_v6only, true} | CommonSocketOpts]; + Family -> + [Family | CommonSocketOpts] + end, + case Family of + inet -> + case init:get_argument(snmp_fd) of + {ok, [[FdStr]]} -> + Fd = list_to_integer(FdStr), + case BindTo of + true -> + {IpPort, [{ip, IpAddr}, {fd, Fd} | SocketOpts]}; + _ -> + {0, [{fd, Fd} | SocketOpts]} + end; + error -> + {IpPort, [{ip, IpAddr} | SocketOpts]} + end; _ -> - [] - end; -bind_to(_) -> - []. - -no_reuse(false) -> - [{reuseaddr, true}]; -no_reuse(_) -> - []. - -recbuf(default) -> - []; -recbuf(Sz) -> - [{recbuf, Sz}]. + case BindTo of + true -> + {IpPort, [{ip, IpAddr} | SocketOpts]}; + _ -> + {IpPort, SocketOpts} + end + end. -sndbuf(default) -> - []; -sndbuf(Sz) -> - [{sndbuf, Sz}]. +common_socket_opts(Opts) -> + [binary + | case get_opt(Opts, sndbuf, default) of + default -> + []; + Sz -> + [{sndbuf, Sz}] + end ++ + case get_opt(Opts, recbuf, default) of + default -> + []; + Sz -> + [{sndbuf, Sz}] + end ++ + case get_opt(Opts, no_reuse, false) of + false -> + [{reuseaddr, true}]; + _ -> + [] + end]. + +%% no_reuse(false) -> +%% [{reuseaddr, true}]; +%% no_reuse(_) -> +%% []. + +%% recbuf(default) -> +%% []; +%% recbuf(Sz) -> +%% [{recbuf, Sz}]. + +%% sndbuf(default) -> +%% []; +%% sndbuf(Sz) -> +%% [{sndbuf, Sz}]. create_filter(Opts) when is_list(Opts) -> @@ -439,11 +548,20 @@ handle_cast(Msg, State) -> %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- handle_info( - {udp, Sock, Ip, Port, Bytes}, - #state{sock = Sock, domain = Domain} = State) -> - ?vlog("received ~w bytes from ~p:~p [~w]", [size(Bytes), Ip, Port, Sock]), - maybe_handle_recv_msg(Domain, {Ip, Port}, Bytes, State), - {noreply, State}; + {udp, Socket, IpAddr, IpPort, Bytes}, + #state{transports = Transports} = State) -> + Size = byte_size(Bytes), + case lists:keyfind(Socket, #transport.socket, Transports) of + #transport{socket = Socket, domain = Domain} -> + ?vlog("received ~w bytes from ~p:~p [~w]", + [Size, IpAddr, IpPort, Socket]), + maybe_handle_recv_msg(Domain, {IpAddr, IpPort}, Bytes, State), + {noreply, State}; + false -> + warning_msg("Received ~w bytes on unknown port: ~p from ~s", + [Size, Socket, format_address({IpAddr, IpPort})]), + {noreply, State} + end; handle_info(inform_response_gc, State) -> ?vlog("received inform_response_gc message", []), @@ -488,54 +606,6 @@ do_close_log(_) -> %% Returns: {ok, NewState} %%---------------------------------------------------------------------- -code_change({down, _Vsn}, OldState, downgrade_to_pre_4_14) -> - ?d("code_change(down, downgrade_to_pre_4_14) -> entry with" - "~n OldState: ~p", [OldState]), - #state{server = Server, - note_store = NoteStore, - sock = Sock, - mpd_state = MpdState, - log = {OldLog, Type}, - irb = IRB, - irgc = IRGC} = OldState, - NewLog = snmp_log:downgrade(OldLog), - State = - {state, Server, NoteStore, Sock, MpdState, {NewLog, Type}, IRB, IRGC}, - {ok, State}; - -code_change({down, _Vsn}, OldState, downgrade_to_pre_4_16) -> - ?d("code_change(down, downgrade_to_pre_4_16) -> entry with" - "~n OldState: ~p", [OldState]), - {OldLog, Type} = OldState#state.log, - NewLog = snmp_log:downgrade(OldLog), - State = OldState#state{log = {NewLog, Type}}, - {ok, State}; - -% upgrade -code_change(_Vsn, OldState, upgrade_from_pre_4_14) -> - ?d("code_change(up, upgrade_from_pre_4_14) -> entry with" - "~n OldState: ~p", [OldState]), - {state, Server, NoteStore, Sock, MpdState, {OldLog, Type}, IRB, IRGC} = - OldState, - NewLog = snmp_log:upgrade(OldLog), - State = #state{server = Server, - note_store = NoteStore, - sock = Sock, - mpd_state = MpdState, - log = {NewLog, Type}, - irb = IRB, - irgc = IRGC, - filter = ?DEFAULT_FILTER_MODULE}, - {ok, State}; - -code_change(_Vsn, OldState, upgrade_from_pre_4_16) -> - ?d("code_change(up, upgrade_from_pre_4_16) -> entry with" - "~n OldState: ~p", [OldState]), - {OldLog, Type} = OldState#state.log, - NewLog = snmp_log:upgrade(OldLog), - State = OldState#state{log = {NewLog, Type}}, - {ok, State}; - code_change(_Vsn, State, _Extra) -> ?d("code_change -> entry with" "~n Vsn: ~p" @@ -550,8 +620,8 @@ code_change(_Vsn, State, _Extra) -> maybe_handle_recv_msg( Domain, Addr, Bytes, - #state{filter = FilterMod, domain = ManagerDomain} = State) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{filter = FilterMod, transports = Transports} = State) -> + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_recv(Arg1, Arg2)) of false -> %% Drop the received packet @@ -569,10 +639,11 @@ handle_recv_msg(Domain, Addr, Bytes, #state{server = Pid}) handle_recv_msg( Domain, Addr, Bytes, - #state{server = Pid, - note_store = NoteStore, - mpd_state = MpdState, - log = Log} = State) -> + #state{ + server = Pid, + note_store = NoteStore, + mpd_state = MpdState, + log = Log} = State) -> Logger = logger(Log, read, Domain, Addr), case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, MpdState, NoteStore, Logger)) of @@ -603,8 +674,8 @@ handle_recv_msg( maybe_handle_recv_pdu( Domain, Addr, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, - #state{filter = FilterMod, domain = ManagerDomain} = State) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{filter = FilterMod, transports = Transports} = State) -> + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, Type)) of false -> inc(netIfPduInDrops), @@ -615,9 +686,9 @@ maybe_handle_recv_pdu( end; maybe_handle_recv_pdu( Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, - #state{filter = FilterMod, domain = ManagerDomain} = State) + #state{filter = FilterMod, transports = Transports} = State) when is_record(Trap, trappdu) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, trappdu)) of false -> inc(netIfPduInDrops), @@ -718,10 +789,11 @@ handle_inform_response(Ref, Domain, Addr, State) -> maybe_send_inform_response( RePdu, Vsn, ACM, Domain, Addr, Logger, - #state{server = Pid, - filter = FilterMod, - domain = ManagerDomain} = State) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{ + server = Pid, + filter = FilterMod, + transports = Transports} = State) -> + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_send_pdu( Arg1, Arg2, pdu_type_of(RePdu))) of @@ -774,8 +846,8 @@ irgc_stop(Ref) -> maybe_handle_send_pdu( Pdu, Vsn, MsgData, Domain, Addr, - #state{filter = FilterMod, domain = ManagerDomain} = State) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{filter = FilterMod, transports = Transports} = State) -> + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_send_pdu(Arg1, Arg2, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), @@ -786,9 +858,10 @@ maybe_handle_send_pdu( handle_send_pdu( Pdu, Vsn, MsgData, Domain, Addr, - #state{server = Pid, - note_store = NoteStore, - log = Log} = State) -> + #state{ + server = Pid, + note_store = NoteStore, + log = Log} = State) -> Logger = logger(Log, write, Domain, Addr), case (catch snmpm_mpd:generate_msg( Vsn, NoteStore, Pdu, MsgData, Logger)) of @@ -806,36 +879,52 @@ handle_send_pdu( maybe_udp_send( Domain, Addr, Msg, - #state{sock = Sock, filter = FilterMod, domain = ManagerDomain}) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{filter = FilterMod, transports = Transports}) -> + To = {Domain, Addr}, + {Arg1, Arg2} = fix_filter_address(Transports, To), case (catch FilterMod:accept_send(Arg1, Arg2)) of false -> inc(netIfMsgOutDrops), ok; _ -> - %% XXX There should be some kind of lookup of socket - %% from transport domain here - {Ip, Port} = Addr, - udp_send(Sock, Ip, Port, Msg) + case select_transport_from_domain(Domain, Transports) of + false -> + error_msg( + "Can not find transport~n" + " size: ~p~n" + " to: ~s", + [sz(Msg), format_address(To)]); + #transport{socket = Socket} -> + udp_send(Socket, Addr, Msg) + end end. - - -udp_send(Sock, Ip, Port, Msg) -> - case (catch gen_udp:send(Sock, Ip, Port, Msg)) of + +udp_send(Sock, To, Msg) -> + {IpAddr, IpPort} = + case To of + {Domain, Addr} when is_atom(Domain) -> + Addr; + {_, P} = Addr when is_integer(P) -> + Addr + end, + try gen_udp:send(Sock, IpAddr, IpPort, Msg) of ok -> ?vdebug("sent ~w bytes to ~w:~w [~w]", - [sz(Msg), Ip, Port, Sock]), + [sz(Msg), IpAddr, IpPort, Sock]), ok; {error, Reason} -> - error_msg("failed sending message to ~p:~p: " - "~n ~p",[Ip, Port, Reason]); - Error -> - error_msg("failed sending message to ~p:~p: " - "~n ~p",[Ip, Port, Error]) + error_msg("failed sending message to ~p:~p:~n" + " ~p",[IpAddr, IpPort, Reason]) + catch + error:Error -> + error_msg("failed sending message to ~p:~p:~n" + " error:~p~n" + " ~p", + [IpAddr, IpPort, Error, erlang:get_stacktrace()]) end. sz(B) when is_binary(B) -> - size(B); + byte_size(B); sz(L) when is_list(L) -> length(L); sz(_) -> @@ -1025,26 +1114,45 @@ handle_set_log_type(State, _NewType) -> {State, {error, not_enabled}}. +select_transport_from_domain(Domain, Transports) when is_atom(Domain) -> + Pos = #transport.domain, + case lists:keyfind(Domain, Pos, Transports) of + #transport{domain = Domain} = Transport -> + Transport; + false when Domain == snmpUDPDomain -> + lists:keyfind(transportDomainUdpIpv4, Pos, Transports); + false when Domain == transportDomainUdpIpv4 -> + lists:keyfind(snmpUDPDomain, Pos, Transports); + false -> + false + end. + %% If the manager uses legacy snmpUDPDomain e.g has not set %% {domain, _}, then make sure snmpm_network_interface_filter %% gets legacy arguments to not break backwards compatibility. %% -fix_filter_address(snmpUDPDomain, {Domain, Addr}) - when Domain =:= snmpUDPDomain; - Domain =:= transportDomainUdpIpv4 -> - Addr; -fix_filter_address(_ManagerDomain, {Domain, _} = Address) - when is_atom(Domain) -> - Address; -fix_filter_address(snmpUDPDomain, {_, Port} = Addr) - when is_integer(Port) -> - Addr. +fix_filter_address(Transports, Address) -> + DefaultDomain = snmpm_config:default_transport_domain(), + case Transports of + [#transport{domain = DefaultDomain}, DefaultDomain] -> + case Address of + {Domain, Addr} when is_atom(Domain) -> + Addr; + {_, IpPort} = Addr when is_integer(IpPort) -> + Addr + end; + _ -> + Address + end. address(Domain, Addr) when is_atom(Domain) -> {Domain, Addr}; address(Ip, Port) when is_integer(Port) -> {snmpm_config:default_transport_domain(), {Ip, Port}}. +format_address(Address) -> + iolist_to_binary(snmp_conf:mk_addr_string(Address)). + %% ------------------------------------------------------------------- make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> @@ -1130,10 +1238,11 @@ get_opt(Opts, Key, Def) -> %% ------------------------------------------------------------------- -get_info(#state{sock = Id}) -> +get_info(#state{transports = Transports}) -> ProcSize = proc_mem(self()), - PortInfo = get_port_info(Id), - [{process_memory, ProcSize}, {port_info, PortInfo}]. + [{process_memory, ProcSize} + | [{port_info, get_port_info(Socket)} + || #transport{socket = Socket} <- Transports]]. proc_mem(P) when is_pid(P) -> case (catch erlang:process_info(P, memory)) of @@ -1248,4 +1357,3 @@ call(Pid, Req, Timeout) -> cast(Pid, Msg) -> gen_server:cast(Pid, Msg). - diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 9e9865f3b5..0a50174adc 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -47,8 +47,8 @@ write_agent_snmp_vacm_conf/3, write_manager_snmp_files/8, - write_manager_snmp_conf/5, - write_manager_snmp_users_conf/2, + write_manager_snmp_conf/4, write_manager_snmp_conf/5, + write_manager_snmp_users_conf/2, write_manager_snmp_agents_conf/2, write_manager_snmp_usm_conf/2 @@ -2116,7 +2116,24 @@ write_manager_snmp_files(Dir, IP, Port, MMS, EngineID, %% ------ manager.conf ------ %% -write_manager_snmp_conf(Dir, IP, Port, MMS, EngineID) -> +write_manager_snmp_conf(Dir, Transports, MMS, EngineID) -> + Comment = +"%% This file defines the Manager local configuration info\n" +"%% Each row is a 2-tuple:\n" +"%% {Variable, Value}.\n" +"%% For example\n" +"%% {transports, [{transportDomainUdpIpv4, {{127,42,17,5}, 5000}}]}.\n" +"%% {engine_id, \"managerEngine\"}.\n" +"%% {max_message_size, 484}.\n" +"%%\n\n", + Hdr = header() ++ Comment, + Conf = + [{transports, Transports}, + {engine_id, EngineID}, + {max_message_size, MMS}], + write_manager_config(Dir, Hdr, Conf). + +write_manager_snmp_conf(Dir, Domain_or_IP, Addr_or_Port, MMS, EngineID) -> Comment = "%% This file defines the Manager local configuration info\n" "%% Each row is a 2-tuple:\n" @@ -2129,15 +2146,14 @@ write_manager_snmp_conf(Dir, IP, Port, MMS, EngineID) -> "%%\n\n", Hdr = header() ++ Comment, Conf = - case Port of - {Addr, P} when is_integer(P), is_atom(IP) -> - Domain = IP, - [{domain, Domain}, - {port, P}, - {address, Addr}]; - _ when is_integer(Port) -> - [{port, Port}, - {address, IP}] + case Addr_or_Port of + {IP, Port} when is_integer(Port), is_atom(Domain_or_IP) -> + [{domain, Domain_or_IP}, + {port, Port}, + {address, IP}]; + _ when is_integer(Addr_or_Port) -> + [{port, Addr_or_Port}, + {address, Domain_or_IP}] end ++ [{engine_id, EngineID}, {max_message_size, MMS}], -- cgit v1.2.3 From 39176f2ab7f07c676e797455000bc2dfc6bb751c Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 15 Aug 2014 15:10:33 +0200 Subject: Write manager IPv4+IPv6 test --- lib/snmp/test/snmp_manager_user.erl | 15 +- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 154 +++++++++++++++++---- .../test/snmp_to_snmpnet_SUITE_data/snmpd.conf | 12 ++ 3 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 lib/snmp/test/snmp_to_snmpnet_SUITE_data/snmpd.conf (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index ddbe156130..46c2b316be 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2013. All Rights Reserved. +%% Copyright Ericsson AB 2005-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -109,7 +109,18 @@ start_link(Parent, Id) -> proc_lib:start_link(?MODULE, main, [true, Parent, self(), Id]). stop() -> - cast(stop). + MRef = erlang:monitor(process, ?SERVER), + cast(stop), + receive {'DOWN', MRef, _, _, Info} -> + case Info of + noproc -> + ok; + noconnection -> + ok; + normal -> + ok + end + end. info() -> call(info). diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 6e9c57bce9..1c2e08dc41 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -19,6 +19,7 @@ %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% This test suite uses the following external programs: %% snmpget From packet 'snmp' (in Ubuntu 12.04) +%% snmpd From packet 'snmpd' (in Ubuntu 12.04) %% snmptrapd From packet 'snmpd' (in Ubuntu 12.04) %% They originate from the Net-SNMP applications, see: %% http://net-snmp.sourceforge.net/ @@ -33,6 +34,7 @@ -include_lib("snmp/include/STANDARD-MIB.hrl"). -define(AGENT_ENGINE_ID, "ErlangSnmpAgent"). +-define(MANAGER_ENGINE_ID, "ErlangSnmpManager"). -define(AGENT_PORT, 4000). -define(MANAGER_PORT, 8989). -define(DEFAULT_MAX_MESSAGE_SIZE, 484). @@ -56,22 +58,27 @@ all() -> groups() -> [{ipv4, [], - [{group, get}, - {group, inform} + [{group, snmpget}, + {group, snmptrapd}, + {group, snmpd} ]}, {ipv6, [], - [{group, get}, - {group, inform} + [{group, snmpget}, + {group, snmptrapd}, + {group, snmpd} ]}, {ipv4_ipv6, [], - [{group, get}, - {group, inform} + [{group, snmpget}, + {group, snmptrapd}, + {group, snmpd} ]}, %% - {get, [], + {snmpget, [], [erlang_agent_netsnmp_get]}, - {inform, [], - [erlang_agent_netsnmp_inform]} + {snmptrapd, [], + [erlang_agent_netsnmp_inform]}, + {snmpd, [], + [erlang_manager_netsnmp_get]} ]. init_per_suite(Config) -> @@ -87,12 +94,15 @@ init_per_group(ipv6, Config) -> init_per_group(ipv4_ipv6, Config) -> init_per_group_ipv6([inet, inet6], Config); %% -init_per_group(get, Config) -> +init_per_group(snmpget = Exec, Config) -> %% From Ubuntu package snmp - find_executable(snmpget, Config); -init_per_group(inform, Config) -> + init_per_group_agent(Exec, Config); +init_per_group(snmptrapd = Exec, Config) -> %% From Ubuntu package snmpd - find_executable(snmptrapd, Config); + init_per_group_agent(Exec, Config); +init_per_group(snmpd = Exec, Config) -> + %% From Ubuntu package snmp + init_per_group_manager(Exec, Config); %% init_per_group(_, Config) -> Config. @@ -106,10 +116,8 @@ init_per_group_ipv6(Families, Config) -> end. init_per_group_ip(Families, Config) -> - Dir = ?config(priv_dir, Config), AgentPort = ?config(agent_port, Config), ManagerPort = ?config(manager_port, Config), - Versions = [v2], {ok, Host} = inet:gethostname(), Transports = [begin @@ -121,10 +129,22 @@ init_per_group_ip(Families, Config) -> {ok, Addr} = inet:getaddr(Host, Family), {domain(Family), {Addr, ManagerPort}} end || Family <- Families], + [{transports, Transports}, {targets, Targets} | Config]. + +init_per_group_agent(Exec, Config) -> + Versions = [v2], + Dir = ?config(priv_dir, Config), + Transports = ?config(transports, Config), + Targets = ?config(targets, Config), agent_config(Dir, Transports, Targets, Versions), - [{port, ?AGENT_PORT}, {snmp_versions, Versions}, - {transports, Transports}, {targets, Targets} - | Config]. + find_executable(Exec, [{snmp_versions, Versions} | Config]). + +init_per_group_manager(Exec, Config) -> + Versions = [v2], + Dir = ?config(priv_dir, Config), + Targets = ?config(targets, Config), + manager_config(Dir, Targets), + find_executable(Exec, [{snmp_versions, Versions} | Config]). @@ -179,7 +199,12 @@ find_sys_executable(Exec, ExecStr, [Dir | Dirs], Config) -> start_agent(Config) -> ok = application:load(snmp), - ok = application:set_env(snmp, agent, app_env(Config)), + ok = application:set_env(snmp, agent, agent_app_env(Config)), + ok = application:start(snmp). + +start_manager(Config) -> + ok = application:load(snmp), + ok = application:set_env(snmp, manager, manager_app_env(Config)), ok = application:start(snmp). %%-------------------------------------------------------------------- @@ -198,6 +223,39 @@ erlang_agent_netsnmp_get(Config) when is_list(Config) -> || Transport <- Transports], ok. +%%-------------------------------------------------------------------- +erlang_manager_netsnmp_get() -> + [{doc,"Test that the erlang snmp manager can access snmpnet agent"}]. + +erlang_manager_netsnmp_get(Config) when is_list(Config) -> + Community = "happy-testing", + SysDescr = "Net-SNMP agent", + TargetName = "Target Net-SNMP agent", + Transports = ?config(transports, Config), + ProgHandle = start_snmpd(Community, SysDescr, Config), + start_manager(Config), + snmp_manager_user:start_link(self(), test_user), + [snmp_manager_user:register_agent( + TargetName++domain_suffix(Domain), + [{reg_type, target_name}, + {tdomain, Domain}, {taddress, Addr}, + {community, Community}, {engine_id, "EngineId"}, + {version, v2}, {sec_model, v2c}, {sec_level, noAuthNoPriv}]) + || {Domain, Addr} <- Transports], + Results = + [snmp_manager_user:sync_get( + TargetName++domain_suffix(Domain), + [?sysDescr_instance]) + || {Domain, _} <- Transports], + ct:pal("sync_get -> ~p", [Results]), + snmp_manager_user:stop(), + stop_program(ProgHandle), + [{ok, + {noError, 0, + [{varbind, ?sysDescr_instance, 'OCTET STRING', SysDescr,1}] }, + _} = R || R <- Results], + ok. + %%-------------------------------------------------------------------- erlang_agent_netsnmp_inform(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), @@ -267,7 +325,29 @@ start_snmptrapd(Mibs, Config) -> {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config). +start_snmpd(Community, SysDescr, Config) -> + DataDir = ?config(data_dir, Config), + Targets = ?config(targets, Config), + Transports = ?config(transports, Config), + Port = mk_port_number(), + CommunityArgs = + ["--rocommunity"++domain_suffix(Domain)++"=" + ++Community++" "++inet_parse:ntoa(Ip) + || {Domain, {Ip, _}} <- Targets], + SnmpdArgs = + ["-f", "-r", %"-Dverbose", + "-c", filename:join(DataDir, "snmpd.conf"), + "-C", "-Lo", + "-m", "", + "--sysDescr="++SysDescr, + "--agentXSocket=tcp:localhost:"++integer_to_list(Port)] + ++ CommunityArgs + ++ [net_snmp_addr_str(Transports)], + {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), + start_program(snmpd, SnmpdArgs, StartCheckMP, Config). + start_program(Prog, Args, StartCheckMP, Config) -> + ct:pal("Starting program: ~w ~p", [Prog, Args]), Path = ?config(Prog, Config), DataDir = ?config(data_dir, Config), StartWrapper = filename:join(DataDir, "start_stop_wrapper"), @@ -318,12 +398,13 @@ wait_program_stop({Pid, Mon}) -> end. run_program(Parent, StartWrapper, ProgAndArgs) -> + [Prog | _] = ProgAndArgs, Port = open_port( {spawn_executable, StartWrapper}, [{args, ProgAndArgs}, binary, stderr_to_stdout, {line, 80}, exit_status]), - ct:pal("Prog ~p started: ~p", [Port, ProgAndArgs]), + ct:pal("Prog ~p started: ~p", [Port, Prog]), run_program_loop(Parent, Port, []). run_program_loop(Parent, Port, Buf) -> @@ -352,7 +433,7 @@ run_program_loop(Parent, Port, Buf) -> end. -app_env(Config) -> +agent_app_env(Config) -> Dir = ?config(priv_dir, Config), Vsns = ?config(snmp_versions, Config), [{versions, Vsns}, @@ -372,6 +453,18 @@ app_env(Config) -> {note_store, [{verbosity, silence}]}, {net_if, [{verbosity, trace}]}]. +manager_app_env(Config) -> + Dir = ?config(priv_dir, Config), + Vsns = ?config(snmp_versions, Config), + [{versions, Vsns}, + {audit_trail_log, [{type, read_write}, + {dir, Dir}, + {size, {10240, 10}}]}, + {config, [{dir, Dir}, + {db_dir, Dir}, + {verbosity, trace}]} + ]. + oid_str([1 | Ints]) -> "iso." ++ oid_str_tl(Ints); oid_str(Ints) -> @@ -384,9 +477,6 @@ oid_str_tl([Int]) -> oid_str_tl([Int | Ints]) -> integer_to_list(Int) ++ "." ++ oid_str_tl(Ints). -agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> - agent_config(Dir, Transports, [{TargetDomain, TargetAddr}], Versions). -%% agent_config(Dir, Transports, Targets, Versions) -> EngineID = ?AGENT_ENGINE_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, @@ -403,6 +493,11 @@ agent_config(Dir, Transports, Targets, Versions) -> ok = snmp_config:write_agent_snmp_notify_conf(Dir, inform), ok = snmp_config:write_agent_snmp_vacm_conf(Dir, Versions, none). +manager_config(Dir, Targets) -> + EngineID = ?MANAGER_ENGINE_ID, + MMS = ?DEFAULT_MAX_MESSAGE_SIZE, + ok = snmp_config:write_manager_snmp_conf(Dir, Targets, MMS, EngineID). + net_snmp_version([v3 | _]) -> "-v3"; net_snmp_version([v2 | _]) -> @@ -431,3 +526,14 @@ net_snmp_addr_str({transportDomainUdpIpv6, {Addr, Port}}) -> "udp6:[" ++ inet_parse:ntoa(Addr) ++ "]:" ++ integer_to_list(Port). + +domain_suffix(transportDomainUdpIpv4) -> + ""; +domain_suffix(transportDomainUdpIpv6) -> + "6". + +mk_port_number() -> + {ok, Socket} = gen_udp:open(0, [{reuseaddr, true}]), + {ok, PortNum} = inet:port(Socket), + ok = gen_udp:close(Socket), + PortNum. diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE_data/snmpd.conf b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/snmpd.conf new file mode 100644 index 0000000000..2a5f31680f --- /dev/null +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/snmpd.conf @@ -0,0 +1,12 @@ +sysLocation On the lab network +sysContact otptest + +createUser myinternaluser SHA dropdead + +agentSecName myinternaluser + +master agentx + +[snmp] +noPersistentLoad yes +noPersistentSave yes -- cgit v1.2.3 From e1a6e43da5b249dd75e2baadd494921cf1684323 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 18 Aug 2014 15:17:45 +0200 Subject: Improve testcase test for IPv6 capable host --- lib/snmp/.gitignore | 3 +-- lib/snmp/test/snmp_agent_test.erl | 17 ++++++++++++----- lib/snmp/test/snmp_manager_test.erl | 23 ++++++++++++++++++----- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 10 ++++++++-- 4 files changed, 39 insertions(+), 14 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/.gitignore b/lib/snmp/.gitignore index 650c1d6865..aef73491a4 100644 --- a/lib/snmp/.gitignore +++ b/lib/snmp/.gitignore @@ -5,5 +5,4 @@ *.rej doc/index.html - - +mibs/.index diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 9a9258aa91..05c91c37a3 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -651,11 +651,18 @@ init_per_group(GroupName, Config) -> init_per_group_ipv6(GroupName, Config, Init) -> case ct:require(ipv6_hosts) of ok -> - Init( - snmp_test_lib:init_group_top_dir( - GroupName, - [{ipfamily, inet6}, - {ip, ?LOCALHOST(inet6)} | lists:keydelete(ip, 1, Config)])); + case gen_udp:open(0, [inet6]) of + {ok, S} -> + ok = gen_udp:close(S), + Init( + snmp_test_lib:init_group_top_dir( + GroupName, + [{ipfamily, inet6}, + {ip, ?LOCALHOST(inet6)} + | lists:keydelete(ip, 1, Config)])); + {error, _} -> + {skip, "Host seems to not support IPv6"} + end; _ -> {skip, "Host does not support IPV6"} end. diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 78352e59cf..fa90872172 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -584,17 +584,30 @@ init_per_group(event_tests_mt = GroupName, Config) -> init_per_group(ipv6_mt = GroupName, Config) -> case ct:require(ipv6_hosts) of ok -> - ipv6_init( - snmp_test_lib:init_group_top_dir( - GroupName, - [{manager_net_if_module, snmpm_net_if_mt} | Config])); + case gen_udp:open(0, [inet6]) of + {ok, S} -> + ok = gen_udp:close(S), + ipv6_init( + snmp_test_lib:init_group_top_dir( + GroupName, + [{manager_net_if_module, snmpm_net_if_mt} + | Config])); + {error, _} -> + {skip, "Host seems to not support IPv6"} + end; _ -> {skip, "Host does not support IPV6"} end; init_per_group(ipv6 = GroupName, Config) -> case ct:require(ipv6_hosts) of ok -> - ipv6_init(snmp_test_lib:init_group_top_dir(GroupName, Config)); + case gen_udp:open(0, [inet6]) of + {ok, S} -> + ok = gen_udp:close(S), + ipv6_init(snmp_test_lib:init_group_top_dir(GroupName, Config)); + {error, _} -> + {skip, "Host seems to not support IPv6"} + end; _ -> {skip, "Host does not support IPV6"} end; diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 1c2e08dc41..5ce9cf9e5c 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -110,9 +110,15 @@ init_per_group(_, Config) -> init_per_group_ipv6(Families, Config) -> case ct:require(ipv6_hosts) of ok -> - init_per_group_ip(Families, Config); + case gen_udp:open(0, [inet6]) of + {ok, S} -> + ok = gen_udp:close(S), + init_per_group_ip(Families, Config); + {error, _} -> + {skip, "Host seems to not support IPv6"} + end; _ -> - {skip, "Host does not support IPV6"} + {skip, "Test config ipv6_hosts is missing"} end. init_per_group_ip(Families, Config) -> -- cgit v1.2.3 From 0685f5c84f0f6ecfd8535d471d082271e77517c6 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 19 Aug 2014 10:22:46 +0200 Subject: Avoid test case known to fail --- lib/snmp/test/snmp_agent_test.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 05c91c37a3..b4770ad0a9 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -532,6 +532,7 @@ groups() -> {v3_inform, [], v3_inform_cases()}, {v3_security, [], v3_security_cases()}, {standard_mibs, [], standard_mibs_cases()}, + {standard_mibs_ipv6, [], standard_mibs_cases_ipv6()}, {standard_mibs_2, [], standard_mibs2_cases()}, {standard_mibs_3, [], standard_mibs3_cases()}, {reported_bugs, [], reported_bugs_cases()}, @@ -1721,7 +1722,7 @@ v1_cases_ipv6() -> next_across_sa, undo, %% {group, reported_bugs}, - {group, standard_mibs}, % snmp_standard_mib still failing, sends v1 trap + {group, standard_mibs_ipv6}, sparse_table, %% cnt_64, % sends v1 trap opaque @@ -4843,6 +4844,15 @@ standard_mibs_cases() -> snmp_view_based_acm_mib ]. +standard_mibs_cases_ipv6() -> + [ + %% snmp_standard_mib, % Sending v1 traps does not work over IPv6 + snmp_community_mib, + snmp_framework_mib, + snmp_target_mib, + snmp_notification_mib, + snmp_view_based_acm_mib + ]. %%----------------------------------------------------------------- %% For this test, the agent is configured for v1. -- cgit v1.2.3 From c49a434098b715b5d7d47ebcb1c2b9a22d0ee500 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 19 Aug 2014 15:42:49 +0200 Subject: Implement IPv4+IPv6 in MT manager --- lib/snmp/src/manager/snmpm_net_if_mt.erl | 799 ++++++++++++++++++++----------- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 16 +- 2 files changed, 535 insertions(+), 280 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 2937f5cc87..516a2f444a 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -59,8 +59,9 @@ { server, note_store, - domain, - sock, +%% domain, +%% sock, + transports = [], mpd_state, log, irb = auto, % auto | {user, integer()} @@ -68,6 +69,9 @@ filter }). +-record(transport, + {socket, + domain = snmpUDPDomain}). -define(DEFAULT_FILTER_MODULE, snmpm_net_if_filter). -define(DEFAULT_FILTER_OPTS, [{module, ?DEFAULT_FILTER_MODULE}]). @@ -107,12 +111,12 @@ send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port) -> send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port, ExtraInfo) when is_record(Pdu, pdu) -> ?d("send_pdu -> entry with~n" - " Pid: ~p~n" - " Pdu: ~p~n" - " Vsn: ~p~n" - " MsgData: ~p~n" - " Domain/IP: ~p~n" - " Addr/Port : ~p", + " Pid: ~p~n" + " Pdu: ~p~n" + " Vsn: ~p~n" + " MsgData: ~p~n" + " Domain/IP: ~p~n" + " Addr/Port: ~p", [Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port]), {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}). @@ -161,12 +165,17 @@ init([Server, NoteStore]) -> ?d("init -> entry with" "~n Server: ~p" "~n NoteStore: ~p", [Server, NoteStore]), - case (catch do_init(Server, NoteStore)) of + try do_init(Server, NoteStore) + catch {error, Reason} -> - {stop, Reason}; - {ok, State} -> - {ok, State} + {stop, Reason} end. + %% case (catch do_init(Server, NoteStore)) of + %% {error, Reason} -> + %% {stop, Reason}; + %% {ok, State} -> + %% {ok, State} + %% end. do_init(Server, NoteStore) -> process_flag(trap_exit, true), @@ -199,21 +208,6 @@ do_init(Server, NoteStore) -> {ok, IRB} = snmpm_config:system_info(net_if_irb), IrGcRef = irgc_start(IRB), - %% -- Socket -- - SndBuf = get_opt(Opts, sndbuf, default), - RecBuf = get_opt(Opts, recbuf, default), - BindTo = get_opt(Opts, bind_to, false), - NoReuse = get_opt(Opts, no_reuse, false), - {ok, Port} = snmpm_config:system_info(port), - Domain = - case snmpm_config:system_info(domain) of - {ok, D} -> - D; - _ -> - snmpm_config:default_transport_domain() - end, - {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), - %% Flow control -- FilterOpts = get_opt(Opts, filter, []), FilterMod = create_filter(FilterOpts), @@ -224,82 +218,197 @@ do_init(Server, NoteStore) -> Log = do_init_log(ATL), ?vdebug("Log: ~w", [Log]), - %% -- Initiate counters --- - init_counters(), - - %% -- We are done --- - State = #state{server = Server, - note_store = NoteStore, - mpd_state = MpdState, - domain = Domain, - sock = Sock, - log = Log, - irb = IRB, - irgc = IrGcRef, - filter = FilterMod}, - ?vdebug("started", []), - {ok, State}. + {ok, DomainAddresses} = snmpm_config:system_info(transports), + ?vdebug("DomainAddresses: ~w",[DomainAddresses]), + CommonSocketOpts = common_socket_opts(Opts), + BindTo = get_opt(Opts, bind_to, false), + case + [begin + {IpPort, SocketOpts} = + socket_params(Domain, Address, BindTo, CommonSocketOpts), + Socket = socket_open(IpPort, SocketOpts), + #transport{socket = Socket, domain = Domain} + end || {Domain, Address} <- DomainAddresses] + of + [] -> + ?vinfo("No transports configured: ~p", [DomainAddresses]), + throw({error, {no_transports,DomainAddresses}}); + Transports -> + %% -- Initiate counters --- + init_counters(), + + %% -- We are done --- + State = #state{ + server = Server, + note_store = NoteStore, + mpd_state = MpdState, + transports = Transports, + log = Log, + irb = IRB, + irgc = IrGcRef, + filter = FilterMod}, + ?vdebug("started", []), + {ok, State} + end. -%% Open port -do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> - ?vtrace("do_open_port -> entry with~n" - " Port: ~p~n" - " SendSz: ~p~n" - " RecvSz: ~p~n" - " Domain: ~p~n" - " BindTo: ~p~n" - " NoReuse: ~p", - [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), - IpOpts1 = bind_to(BindTo), - IpOpts2 = no_reuse(NoReuse), - IpOpts3 = recbuf(RecvSz), - IpOpts4 = sndbuf(SendSz), - IpOpts = - [binary, - snmp_conf:tdomain_to_family(Domain) | - IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], - OpenRes = - case init:get_argument(snmpm_fd) of - {ok, [[FdStr]]} -> - Fd = list_to_integer(FdStr), - gen_udp:open(0, [{fd, Fd}|IpOpts]); - error -> - gen_udp:open(Port, IpOpts) - end, - case OpenRes of + + %% %% -- Socket -- + %% SndBuf = get_opt(Opts, sndbuf, default), + %% RecBuf = get_opt(Opts, recbuf, default), + %% BindTo = get_opt(Opts, bind_to, false), + %% NoReuse = get_opt(Opts, no_reuse, false), + + %% {ok, Port} = snmpm_config:system_info(port), + %% Domain = + %% case snmpm_config:system_info(domain) of + %% {ok, D} -> + %% D; + %% _ -> + %% snmpm_config:default_transport_domain() + %% end, + %% {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), + + %% %% -- Initiate counters --- + %% init_counters(), + + %% %% -- We are done --- + %% State = #state{server = Server, + %% note_store = NoteStore, + %% mpd_state = MpdState, + %% domain = Domain, + %% sock = Sock, + %% log = Log, + %% irb = IRB, + %% irgc = IrGcRef, + %% filter = FilterMod}, + %% ?vdebug("started", []), + %% {ok, State}. + + +%% %% Open port +%% do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> +%% ?vtrace("do_open_port -> entry with~n" +%% " Port: ~p~n" +%% " SendSz: ~p~n" +%% " RecvSz: ~p~n" +%% " Domain: ~p~n" +%% " BindTo: ~p~n" +%% " NoReuse: ~p", +%% [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), +%% IpOpts1 = bind_to(BindTo), +%% IpOpts2 = no_reuse(NoReuse), +%% IpOpts3 = recbuf(RecvSz), +%% IpOpts4 = sndbuf(SendSz), +%% IpOpts = +%% [binary, +%% snmp_conf:tdomain_to_family(Domain) | +%% IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], +%% OpenRes = +%% case init:get_argument(snmpm_fd) of +%% {ok, [[FdStr]]} -> +%% Fd = list_to_integer(FdStr), +%% gen_udp:open(0, [{fd, Fd}|IpOpts]); +%% error -> +%% gen_udp:open(Port, IpOpts) +%% end, +%% case OpenRes of +%% {error, _} = Error -> +%% throw(Error); +%% OK -> +%% OK +%% end. + +socket_open(IpPort, SocketOpts) -> + ?vtrace("socket_open -> entry with~n" + " IpPort: ~p~n" + " SocketOpts: ~p", [IpPort, SocketOpts]), + case gen_udp:open(IpPort, SocketOpts) of {error, _} = Error -> throw(Error); - OK -> - OK + {ok, Socket} -> + Socket end. -bind_to(true) -> - case snmpm_config:system_info(address) of - {ok, Addr} when is_list(Addr) -> - [{ip, list_to_tuple(Addr)}]; - {ok, Addr} -> - [{ip, Addr}]; +%% bind_to(true) -> +%% case snmpm_config:system_info(address) of +%% {ok, Addr} when is_list(Addr) -> +%% [{ip, list_to_tuple(Addr)}]; +%% {ok, Addr} -> +%% [{ip, Addr}]; +%% _ -> +%% [] +%% end; +%% bind_to(_) -> +%% []. + +socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) -> + Family = snmp_conf:tdomain_to_family(Domain), + SocketOpts = + case Family of + inet6 -> + [Family, {ipv6_v6only, true} | CommonSocketOpts]; + Family -> + [Family | CommonSocketOpts] + end, + case Family of + inet -> + case init:get_argument(snmp_fd) of + {ok, [[FdStr]]} -> + Fd = list_to_integer(FdStr), + case BindTo of + true -> + {IpPort, [{ip, IpAddr}, {fd, Fd} | SocketOpts]}; + _ -> + {0, [{fd, Fd} | SocketOpts]} + end; + error -> + {IpPort, [{ip, IpAddr} | SocketOpts]} + end; _ -> - [] - end; -bind_to(_) -> - []. - -no_reuse(false) -> - [{reuseaddr, true}]; -no_reuse(_) -> - []. - -recbuf(default) -> - []; -recbuf(Sz) -> - [{recbuf, Sz}]. + case BindTo of + true -> + {IpPort, [{ip, IpAddr} | SocketOpts]}; + _ -> + {IpPort, SocketOpts} + end + end. -sndbuf(default) -> - []; -sndbuf(Sz) -> - [{sndbuf, Sz}]. +common_socket_opts(Opts) -> + [binary + | case get_opt(Opts, sndbuf, default) of + default -> + []; + Sz -> + [{sndbuf, Sz}] + end ++ + case get_opt(Opts, recbuf, default) of + default -> + []; + Sz -> + [{sndbuf, Sz}] + end ++ + case get_opt(Opts, no_reuse, false) of + false -> + [{reuseaddr, true}]; + _ -> + [] + end]. + +%% no_reuse(false) -> +%% [{reuseaddr, true}]; +%% no_reuse(_) -> +%% []. + +%% recbuf(default) -> +%% []; +%% recbuf(Sz) -> +%% [{recbuf, Sz}]. + +%% sndbuf(default) -> +%% []; +%% sndbuf(Sz) -> +%% [{sndbuf, Sz}]. create_filter(Opts) when is_list(Opts) -> @@ -338,7 +447,8 @@ do_init_log(true) -> Function = increment_counter, Args = [atl_seqno, Initial, Max], SeqNoGen = {Module, Function, Args}, - case snmp_log:create(Name, File, SeqNoGen, Size, Repair, true) of + case snmp_log:create( + Name, File, SeqNoGen, Size, Repair, true) of {ok, Log} -> ?vdebug("log created: ~w", [Log]), {Name, Log, Type}; @@ -356,8 +466,6 @@ do_init_log(true) -> end. -%% ---------------------------------------------------------------------- - %%-------------------------------------------------------------------- %% Func: handle_call/3 %% Returns: {reply, Reply, State} | @@ -449,11 +557,20 @@ handle_cast(Msg, State) -> %% {stop, Reason, State} (terminate/2 is called) %%-------------------------------------------------------------------- handle_info( - {udp, Sock, Ip, Port, Bytes}, - #state{sock = Sock, domain = Domain} = State) -> - ?vlog("received ~w bytes from ~p:~p", [size(Bytes), Ip, Port]), - handle_udp(Domain, {Ip, Port}, Bytes, State), - {noreply, State}; + {udp, Socket, IpAddr, IpPort, Bytes}, + #state{transports = Transports} = State) -> + Size = byte_size(Bytes), + case lists:keyfind(Socket, #transport.socket, Transports) of + #transport{socket = Socket, domain = Domain} -> + ?vlog("received ~w bytes from ~p:~p [~w]", + [Size, IpAddr, IpPort, Socket]), + handle_udp(Domain, {IpAddr, IpPort}, Bytes, State), + {noreply, State}; + false -> + warning_msg("Received ~w bytes on unknown port: ~p from ~s", + [Size, Socket, format_address({IpAddr, IpPort})]), + {noreply, State} + end; handle_info(inform_response_gc, State) -> ?vlog("received inform_response_gc message", []), @@ -466,11 +583,18 @@ handle_info({disk_log, _Node, Log, Info}, State) -> State2 = handle_disk_log(Log, Info, State), {noreply, State2}; -handle_info({'DOWN', _MRef, process, Pid, {net_if_worker, ExitStatus}}, +handle_info({'DOWN', _MRef, process, _Pid, {net_if_worker, _Result}}, State) -> - ?vdebug("received DOWN message from net_if-worker: " - "~n ExitStatus: ~p", [ExitStatus]), - handle_worker_exit(Pid, ExitStatus), + ?vdebug("received DOWN message from net_if worker [~w]: " + "~n Result: ~p", [_Pid, _Result]), + {noreply, State}; +handle_info( + {'DOWN', _MRef, process, Pid, + {net_if_worker, Failer, Class, Reason, Stacktrace} = _ExitStatus}, + State) -> + ?vdebug("received DOWN message from net_if worker [~w]: " + "~n ExitStatus: ~p", [Pid, _ExitStatus]), + Failer(Pid, Class, Reason, Stacktrace), {noreply, State}; handle_info(Info, State) -> @@ -512,99 +636,108 @@ code_change(_Vsn, State, _Extra) -> "~n Extra: ~p", [_Vsn, State, _Extra]), {ok, State}. - + %%%------------------------------------------------------------------- %%% Internal functions %%%------------------------------------------------------------------- handle_udp(Domain, Addr, Bytes, State) -> - Verbosity = get(verbosity), - spawn_opt( - fun() -> - Log = worker_init(State, Verbosity), - Res = - (catch maybe_handle_recv_msg( - Domain, Addr, Bytes, - State#state{log = Log})), - worker_exit(udp, {Domain, Addr}, Res) + worker( + fun (S) -> + maybe_handle_recv_msg(Domain, Addr, Bytes, S) end, - [monitor]). + fun (Pid, Class, Reason, Stacktrace) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (incomming) message from %s:~n" + "~w:~w at ~p", + [Pid, snmp_conf:mk_addr_string({Domain, Addr}), + Class, Reason, Stacktrace]) + end, + State). + + %% Verbosity = get(verbosity), + %% spawn_opt( + %% fun() -> + %% Log = worker_init(State, Verbosity), + %% Res = + %% (catch maybe_handle_recv_msg( + %% Domain, Addr, Bytes, + %% State#state{log = Log})), + %% worker_exit(udp, {Domain, Addr}, Res) + %% end, + %% [monitor]). maybe_handle_recv_msg( Domain, Addr, Bytes, - #state{filter = FilterMod, domain = ManagerDomain} = State) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{filter = FilterMod, transports = Transports} = State) -> + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_recv(Arg1, Arg2)) of false -> %% Drop the received packet - inc(netIfMsgInDrops), - ok; + inc(netIfMsgInDrops); _ -> handle_recv_msg(Domain, Addr, Bytes, State) - end. + end, + ok. handle_recv_msg(Domain, Addr, Bytes, #state{server = Pid}) when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> - Pid ! {snmp_error, {empty_message, Domain, Addr}, Domain, Addr}, - ok; - + Pid ! {snmp_error, {empty_message, Domain, Addr}, Domain, Addr}; +%% handle_recv_msg( Domain, Addr, Bytes, - #state{server = Pid, - note_store = NoteStore, - mpd_state = MpdState, - log = Log} = State) -> + #state{ + server = Pid, + note_store = NoteStore, + mpd_state = MpdState, + log = Log} = State) -> Logger = logger(Log, read, Domain, Addr), - case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, - MpdState, NoteStore, Logger)) of + case (catch snmpm_mpd:process_msg( + Bytes, Domain, Addr, MpdState, NoteStore, Logger)) of {ok, Vsn, Pdu, MS, ACM} -> - maybe_handle_recv_pdu(Domain, Addr, Vsn, Pdu, MS, ACM, - Logger, State); + maybe_handle_recv_pdu( + Domain, Addr, Vsn, Pdu, MS, ACM, Logger, State); {discarded, Reason, Report} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, Pid ! {snmp_error, ErrorInfo, Domain, Addr}, - maybe_udp_send(Domain, Addr, Report, State), - ok; + maybe_udp_send(Domain, Addr, Report, State); {discarded, Reason} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Addr}, - ok; + Pid ! {snmp_error, ErrorInfo, Domain, Addr}; Error -> error_msg("processing of received message failed: " - "~n ~p", [Error]), - ok + "~n ~p", [Error]) end. maybe_handle_recv_pdu( Domain, Addr, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, - #state{filter = FilterMod, domain = ManagerDomain} = State) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{filter = FilterMod, transports = Transports} = State) -> + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, Type)) of false -> - inc(netIfPduInDrops), - ok; + inc(netIfPduInDrops); _ -> handle_recv_pdu( Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) end; maybe_handle_recv_pdu( Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, - #state{filter = FilterMod, domain = ManagerDomain} = State) + #state{filter = FilterMod, transports = Transports} = State) when is_record(Trap, trappdu) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, trappdu)) of false -> - inc(netIfPduInDrops), - ok; + inc(netIfPduInDrops); _ -> handle_recv_pdu( Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, State) @@ -625,40 +758,34 @@ handle_recv_pdu( #pdu{type = report} = Pdu, _PduMS, ok, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - ok", []), - Pid ! {snmp_report, {ok, Pdu}, Domain, Addr}, - ok; + Pid ! {snmp_report, {ok, Pdu}, Domain, Addr}; handle_recv_pdu( Domain, Addr, _Vsn, #pdu{type = report} = Pdu, _PduMS, {error, ReqId, Reason}, _Logger, #state{server = Pid} = _State) -> ?vtrace("received report - error", []), - Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Addr}, - ok; + Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Addr}; handle_recv_pdu( Domain, Addr, _Vsn, #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) -> ?vtrace("received snmpv2-trap", []), - Pid ! {snmp_trap, Pdu, Domain, Addr}, - ok; + Pid ! {snmp_trap, Pdu, Domain, Addr}; handle_recv_pdu( Domain, Addr, _Vsn, Trap, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Trap, trappdu) -> ?vtrace("received trappdu", []), - Pid ! {snmp_trap, Trap, Domain, Addr}, - ok; + Pid ! {snmp_trap, Trap, Domain, Addr}; handle_recv_pdu( Domain, Addr, _Vsn, Pdu, _PduMS, _ACM, _Logger, #state{server = Pid} = _State) when is_record(Pdu, pdu) -> ?vtrace("received pdu", []), - Pid ! {snmp_pdu, Pdu, Domain, Addr}, - ok; + Pid ! {snmp_pdu, Pdu, Domain, Addr}; handle_recv_pdu( _Domain, _Addr, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> ?vlog("received unexpected pdu: " - "~n Pdu: ~p" - "~n ACM: ~p", [Pdu, ACM]), - ok. + "~n Pdu: ~p" + "~n ACM: ~p", [Pdu, ACM]). handle_inform_request( @@ -693,15 +820,29 @@ handle_inform_request( ok. handle_inform_response(Ref, Domain, Addr, State) -> - Verbosity = get(verbosity), - spawn_opt( - fun() -> - Log = worker_init(State, Verbosity), - Res = (catch do_handle_inform_response( - Ref, Domain, Addr, State#state{log = Log})), - worker_exit(inform_response, {Domain, Addr}, Res) + worker( + fun (S) -> + do_handle_inform_response(Ref, Domain, Addr, S) end, - [monitor]). + fun (Pid, Class, Reason, Stacktrace) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (outgoing) inform response for %s:~n" + "~w:~w at ~p", + [Pid, snmp_conf:mk_addr_string({Domain, Addr}), + Class, Reason, Stacktrace]) + end, + State). + + %% Verbosity = get(verbosity), + %% spawn_opt( + %% fun() -> + %% Log = worker_init(State, Verbosity), + %% Res = (catch do_handle_inform_response( + %% Ref, Domain, Addr, State#state{log = Log})), + %% worker_exit(inform_response, {Domain, Addr}, Res) + %% end, + %% [monitor]). @@ -721,11 +862,11 @@ do_handle_inform_response(Ref, Domain, Addr, State) -> maybe_send_inform_response( RePdu, Vsn, ACM, Domain, Addr, Logger, - #state{server = Pid, - sock = Sock, - domain = ManagerDomain, - filter = FilterMod}) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{ + server = Pid, + filter = FilterMod, + transports = Transports} = State) -> + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_send_pdu( Arg1, Arg2, pdu_type_of(RePdu))) of @@ -735,8 +876,7 @@ maybe_send_inform_response( _ -> case snmpm_mpd:generate_response_msg(Vsn, RePdu, ACM, Logger) of {ok, Msg} -> - maybe_udp_send( - Domain, Addr, Msg, Sock, FilterMod, ManagerDomain); + maybe_udp_send(Domain, Addr, Msg, State); {discarded, Reason} -> ?vlog("failed generating response message:" "~n Reason: ~p", [Reason]), @@ -778,22 +918,36 @@ irgc_stop(Ref) -> handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) -> - Verbosity = get(verbosity), - spawn_opt( - fun() -> - Log = worker_init(State, Verbosity), - Res = (catch maybe_handle_send_pdu( - Pdu, Vsn, MsgData, - Domain, Addr, - State#state{log = Log})), - worker_exit(send_pdu, {Domain, Addr}, Res) + worker( + fun (S) -> + maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, S) end, - [monitor]). + fun (Pid, Class, Reason, Stacktrace) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (outgoing) pdu for %s:~n" + "~w:~w at ~p", + [Pid, snmp_conf:mk_addr_string({Domain, Addr}), + Class, Reason, Stacktrace]) + end, + State). + + %% Verbosity = get(verbosity), + %% spawn_opt( + %% fun() -> + %% Log = worker_init(State, Verbosity), + %% Res = (catch maybe_handle_send_pdu( + %% Pdu, Vsn, MsgData, + %% Domain, Addr, + %% State#state{log = Log})), + %% worker_exit(send_pdu, {Domain, Addr}, Res) + %% end, + %% [monitor]). maybe_handle_send_pdu( Pdu, Vsn, MsgData, Domain, Addr, - #state{filter = FilterMod, domain = ManagerDomain} = State) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{filter = FilterMod, transports = Transports} = State) -> + {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_send_pdu(Arg1, Arg2, pdu_type_of(Pdu))) of false -> inc(netIfPduOutDrops), @@ -804,9 +958,10 @@ maybe_handle_send_pdu( do_handle_send_pdu( Pdu, Vsn, MsgData, Domain, Addr, - #state{server = Pid, - note_store = NoteStore, - log = Log} = State) -> + #state{ + server = Pid, + note_store = NoteStore, + log = Log} = State) -> Logger = logger(Log, write, Domain, Addr), case (catch snmpm_mpd:generate_msg( Vsn, NoteStore, Pdu, MsgData, Logger)) of @@ -821,43 +976,55 @@ do_handle_send_pdu( ok end. + maybe_udp_send( Domain, Addr, Msg, - #state{sock = Sock, filter = FilterMod, domain = ManagerDomain}) -> - maybe_udp_send(Domain, Addr, Msg, Sock, FilterMod, ManagerDomain). - -maybe_udp_send(Domain, Addr, Msg, Sock, FilterMod, ManagerDomain) -> - {Arg1, Arg2} = fix_filter_address(ManagerDomain, {Domain, Addr}), + #state{filter = FilterMod, transports = Transports}) -> + To = {Domain, Addr}, + {Arg1, Arg2} = fix_filter_address(Transports, To), case (catch FilterMod:accept_send(Arg1, Arg2)) of false -> inc(netIfMsgOutDrops), ok; _ -> - %% XXX There should be some kind of lookup of socket - %% from transport domain here - {Ip, Port} = Addr, - udp_send(Sock, Ip, Port, Msg) + case select_transport_from_domain(Domain, Transports) of + false -> + error_msg( + "Can not find transport~n" + " size: ~p~n" + " to: ~s", + [sz(Msg), format_address(To)]); + #transport{socket = Socket} -> + udp_send(Socket, Addr, Msg) + end end. - - -udp_send(Sock, Ip, Port, Msg) -> - case (catch gen_udp:send(Sock, Ip, Port, Msg)) of + +udp_send(Sock, To, Msg) -> + {IpAddr, IpPort} = + case To of + {Domain, Addr} when is_atom(Domain) -> + Addr; + {_, P} = Addr when is_integer(P) -> + Addr + end, + try gen_udp:send(Sock, IpAddr, IpPort, Msg) of ok -> ?vdebug("sent ~w bytes to ~w:~w [~w]", - [sz(Msg), Ip, Port, Sock]), + [sz(Msg), IpAddr, IpPort, Sock]), ok; {error, Reason} -> - error_msg("failed sending message to ~p:~p: " - "~n ~p", [Ip, Port, Reason]), - ok; - Error -> - error_msg("failed sending message to ~p:~p: " - "~n ~p", [Ip, Port, Error]), - ok + error_msg("failed sending message to ~p:~p:~n" + " ~p",[IpAddr, IpPort, Reason]) + catch + error:Error -> + error_msg("failed sending message to ~p:~p:~n" + " error:~p~n" + " ~p", + [IpAddr, IpPort, Error, erlang:get_stacktrace()]) end. sz(B) when is_binary(B) -> - size(B); + byte_size(B); sz(L) when is_list(L) -> length(L); sz(_) -> @@ -1047,79 +1214,152 @@ handle_set_log_type(State, _NewType) -> {State, {error, not_enabled}}. -%% ------------------------------------------------------------------- - -worker_init(#state{log = undefined = Log}, Verbosity) -> - worker_init2(Log, Verbosity); -worker_init(#state{log = {Name, Log, Type}}, Verbosity) -> - case snmp_log:open(Name, Log) of - {ok, NewLog} -> - worker_init2({Name, NewLog, Type}, Verbosity); - {error, Reason} -> - warning_msg("NetIf worker ~p failed opening ATL: " - "~n ~p", [self(), Reason]), - NewLog = undefined, - worker_init2({Name, NewLog, Type}, Verbosity) - end; -worker_init(State, Verbosity) -> - ?vinfo("worker_init -> entry with invalid data: " - "~n State: ~p" - "~n Verbosity: ~p", [State, Verbosity]), - exit({worker_init, State, Verbosity}). - -worker_init2(Log, Verbosity) -> - put(sname, mnifw), - put(verbosity, Verbosity), - Log. - - -worker_exit(Tag, Info, Result) -> - exit({net_if_worker, {Tag, Info, Result}}). - -handle_worker_exit(_, {_, _, ok}) -> - ok; -handle_worker_exit(Pid, {udp, {Domain, Addr}, ExitStatus}) -> - warning_msg( - "Worker process (~p) terminated " - "while processing (incomming) message from %s:~n" - "~p", [Pid, snmp_conf:mk_addr_string({Domain, Addr}), ExitStatus]), - ok; -handle_worker_exit(Pid, {send_pdu, {Domain, Addr}, ExitStatus}) -> - warning_msg( - "Worker process (~p) terminated " - "while processing (outgoing) pdu for %s:~n" - "~p", [Pid, snmp_conf:mk_addr_string({Domain, Addr}), ExitStatus]), - ok; -handle_worker_exit(Pid, {inform_response, {Domain, Addr}, ExitStatus}) -> - warning_msg( - "Worker process (~p) terminated " - "while processing (outgoing) inform response for %s:~n" - "~p", [Pid, snmp_conf:mk_addr_string({Domain, Addr}), ExitStatus]), - ok; -handle_worker_exit(_, _) -> - ok. - +select_transport_from_domain(Domain, Transports) when is_atom(Domain) -> + Pos = #transport.domain, + case lists:keyfind(Domain, Pos, Transports) of + #transport{domain = Domain} = Transport -> + Transport; + false when Domain == snmpUDPDomain -> + lists:keyfind(transportDomainUdpIpv4, Pos, Transports); + false when Domain == transportDomainUdpIpv4 -> + lists:keyfind(snmpUDPDomain, Pos, Transports); + false -> + false + end. %% If the manager uses legacy snmpUDPDomain e.g has not set %% {domain, _}, then make sure snmpm_network_interface_filter %% gets legacy arguments to not break backwards compatibility. %% -fix_filter_address(snmpUDPDomain, {Domain, Addr}) - when Domain =:= snmpUDPDomain; - Domain =:= transportDomainUdpIpv4 -> - Addr; -fix_filter_address(_ManagerDomain, {Domain, _} = Address) - when is_atom(Domain) -> - Address; -fix_filter_address(snmpUDPDomain, {_, Port} = Addr) - when is_integer(Port) -> - Addr. +fix_filter_address(Transports, Address) -> + DefaultDomain = snmpm_config:default_transport_domain(), + case Transports of + [#transport{domain = DefaultDomain}, DefaultDomain] -> + case Address of + {Domain, Addr} when is_atom(Domain) -> + Addr; + {_, IpPort} = Addr when is_integer(IpPort) -> + Addr + end; + _ -> + Address + end. address(Domain, Addr) when is_atom(Domain) -> {Domain, Addr}; address(Ip, Port) when is_integer(Port) -> {snmpm_config:default_transport_domain(), {Ip, Port}}. +format_address(Address) -> + iolist_to_binary(snmp_conf:mk_addr_string(Address)). + +%% ------------------------------------------------------------------- + +worker(Worker, Failer, State) -> + Verbosity = get(verbosity), + spawn_opt( + fun () -> + try + put(sname, mnifw), + put(verbosity, Verbosity), + Worker(worker_init(State)) + of + Result -> + %% Winds up in handle_info {'DOWN', ...} + erlang:exit({net_if_worker, Result}) + catch + Class:Reason -> + %% Winds up in handle_info {'DOWN', ...} + erlang:exit( + {net_if_worker, Failer, + Class, Reason, erlang:get_stacktrace()}) + end + end, + [monitor]). + +worker_init(#state{log = undefined} = State) -> + State; +worker_init(#state{log = {Name, Log, Type}} = State) -> + case snmp_log:open(Name, Log) of + {ok, NewLog} -> + State#state{log = {Name, NewLog, Type}}; + {error, Reason} -> + warning_msg("NetIf worker ~p failed opening ATL: " + "~n ~p", [self(), Reason]), + State#state{log = {Name, undefined, Type}} + end; +worker_init(State) -> + ?vinfo("worker_init -> entry with invalid data: " + "~n State: ~p", [State]), + erlang:error({worker_init, State}). + +%% worker_init2(Log, Verbosity) -> +%% put(sname, mnifw), +%% put(verbosity, Verbosity), +%% Log. + + +%% worker_exit(Tag, Info, Result) -> +%% exit({net_if_worker, {Tag, Info, Result}}). + +%% handle_worker_exit(_, {_, _, {Result}}) -> +%% Result; +%% handle_worker_exit( +%% Pid, {udp, {Domain, Addr}, {Class, Reason, Stacktrace}) -> +%% warning_msg( +%% "Worker process (~p) terminated " +%% "while processing (incomming) message from %s:~n" +%% "~w:~w at ~p", +%% [Pid, snmp_conf:mk_addr_string({Domain, Addr}), +%% Class, Reason, Stacktrace]), +%% ok; +%% handle_worker_exit( +%% Pid, {send_pdu, {Domain, Addr}, {Class, Reason, Stacktrace}) -> +%% warning_msg( +%% "Worker process (~p) terminated " +%% "while processing (outgoing) pdu for %s:~n" +%% "~w:~w at ~p", +%% [Pid, snmp_conf:mk_addr_string({Domain, Addr}), +%% Class, Reason, Stacktrace]), +%% ok; +%% handle_worker_exit( +%% Pid, {inform_response, {Domain, Addr}, {Class, Reason, Stacktrace}}) -> +%% warning_msg( +%% "Worker process (~p) terminated " +%% "while processing (outgoing) inform response for %s:~n" +%% "~w:~w at ~p", +%% [Pid, snmp_conf:mk_addr_string({Domain, Addr}), +%% Class, Reason, Stacktrace]), +%% ok; +%% handle_worker_exit(Pid, Term) -> +%% warning_msg( +%% "Worker process (~p) terminated for strange reason: ~p", +%% [Pid, Term]). + + +%% %% If the manager uses legacy snmpUDPDomain e.g has not set +%% %% {domain, _}, then make sure snmpm_network_interface_filter +%% %% gets legacy arguments to not break backwards compatibility. +%% %% +%% fix_filter_address(snmpUDPDomain, {Domain, Addr}) +%% when Domain =:= snmpUDPDomain; +%% Domain =:= transportDomainUdpIpv4 -> +%% Addr; +%% fix_filter_address(_ManagerDomain, {Domain, _} = Address) +%% when is_atom(Domain) -> +%% Address; +%% fix_filter_address(snmpUDPDomain, {_, Port} = Addr) +%% when is_integer(Port) -> +%% Addr. + +%% address(Domain, Addr) when is_atom(Domain) -> +%% {Domain, Addr}; +%% address(Ip, Port) when is_integer(Port) -> +%% {snmpm_config:default_transport_domain(), {Ip, Port}}. + +%% format_address(Address) -> +%% iolist_to_binary(snmp_conf:mk_addr_string(Address)). + %% ------------------------------------------------------------------- make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> @@ -1170,7 +1410,7 @@ logger({_Name, Log, Types}, Type, Domain, Addr) -> AddrString = iolist_to_binary(snmp_conf:mk_addr_string({Domain, Addr})), fun(Msg) -> - snmp_log:log(Log, Msg, Domain, AddrString) + snmp_log:log(Log, Msg, AddrString) end; false -> fun(_) -> @@ -1205,10 +1445,11 @@ get_opt(Opts, Key, Def) -> %% ------------------------------------------------------------------- -get_info(#state{sock = Id}) -> +get_info(#state{transports = Transports}) -> ProcSize = proc_mem(self()), - PortInfo = get_port_info(Id), - [{process_memory, ProcSize}, {port_info, PortInfo}]. + [{process_memory, ProcSize} + | [{port_info, get_port_info(Socket)} + || #transport{socket = Socket} <- Transports]]. proc_mem(P) when is_pid(P) -> case (catch erlang:process_info(P, memory)) of diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 5ce9cf9e5c..c514eafd7d 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -60,16 +60,19 @@ groups() -> [{ipv4, [], [{group, snmpget}, {group, snmptrapd}, + {group, snmpd_mt}, {group, snmpd} ]}, {ipv6, [], [{group, snmpget}, {group, snmptrapd}, + {group, snmpd_mt}, {group, snmpd} ]}, {ipv4_ipv6, [], [{group, snmpget}, {group, snmptrapd}, + {group, snmpd_mt}, {group, snmpd} ]}, %% @@ -77,6 +80,8 @@ groups() -> [erlang_agent_netsnmp_get]}, {snmptrapd, [], [erlang_agent_netsnmp_inform]}, + {snmpd_mt, [], + [erlang_manager_netsnmp_get]}, {snmpd, [], [erlang_manager_netsnmp_get]} ]. @@ -100,9 +105,16 @@ init_per_group(snmpget = Exec, Config) -> init_per_group(snmptrapd = Exec, Config) -> %% From Ubuntu package snmpd init_per_group_agent(Exec, Config); +init_per_group(snmpd_mt, Config) -> + %% From Ubuntu package snmp + init_per_group_manager( + snmpd, + [{manager_net_if_module, snmpm_net_if_mt} | Config]); init_per_group(snmpd = Exec, Config) -> %% From Ubuntu package snmp - init_per_group_manager(Exec, Config); + init_per_group_manager( + Exec, + [{manager_net_if_module, snmpm_net_if} | Config]); %% init_per_group(_, Config) -> Config. @@ -462,10 +474,12 @@ agent_app_env(Config) -> manager_app_env(Config) -> Dir = ?config(priv_dir, Config), Vsns = ?config(snmp_versions, Config), + NetIfModule = ?config(manager_net_if_module, Config), [{versions, Vsns}, {audit_trail_log, [{type, read_write}, {dir, Dir}, {size, {10240, 10}}]}, + {net_if, [{module, NetIfModule}]}, {config, [{dir, Dir}, {db_dir, Dir}, {verbosity, trace}]} -- cgit v1.2.3 From 037590364fe8b5a657563cd7d28a20d84ee8d99f Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 20 Aug 2014 12:15:46 +0200 Subject: Remove decommented code and clean up diff --- lib/snmp/src/manager/snmpm_net_if.erl | 154 ++++------------------ lib/snmp/src/manager/snmpm_net_if_mt.erl | 217 +------------------------------ 2 files changed, 28 insertions(+), 343 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index c4716dfd21..bdde8a5623 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -59,8 +59,6 @@ { server, note_store, -%% domain, -%% sock, transports = [], mpd_state, log, @@ -170,12 +168,6 @@ init([Server, NoteStore]) -> {error, Reason} -> {stop, Reason} end. - %% case (catch do_init(Server, NoteStore)) of - %% {error, Reason} -> - %% {stop, Reason}; - %% {ok, State} -> - %% {ok, State} - %% end. do_init(Server, NoteStore) -> process_flag(trap_exit, true), @@ -190,8 +182,8 @@ do_init(Server, NoteStore) -> %% -- Verbosity -- {ok, Verbosity} = snmpm_config:system_info(net_if_verbosity), - put(sname,mnif), - put(verbosity,Verbosity), + put(sname, mnif), + put(verbosity, Verbosity), ?vlog("starting", []), %% -- MPD -- @@ -246,74 +238,6 @@ do_init(Server, NoteStore) -> ?vdebug("started", []), {ok, State} end. - - - - %% %% -- Socket -- - %% SndBuf = get_opt(Opts, sndbuf, default), - %% RecBuf = get_opt(Opts, recbuf, default), - %% BindTo = get_opt(Opts, bind_to, false), - %% NoReuse = get_opt(Opts, no_reuse, false), - - %% {ok, Port} = snmpm_config:system_info(port), - %% Domain = - %% case snmpm_config:system_info(domain) of - %% {ok, D} -> - %% D; - %% _ -> - %% snmpm_config:default_transport_domain() - %% end, - %% {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), - - %% %% -- Initiate counters --- - %% init_counters(), - - %% %% -- We are done --- - %% State = #state{server = Server, - %% note_store = NoteStore, - %% mpd_state = MpdState, - %% domain = Domain, - %% sock = Sock, - %% log = Log, - %% irb = IRB, - %% irgc = IrGcRef, - %% filter = FilterMod}, - %% ?vdebug("started", []), - %% {ok, State}. - - -%% %% Open port -%% do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> -%% ?vtrace("do_open_port -> entry with~n" -%% " Port: ~p~n" -%% " SendSz: ~p~n" -%% " RecvSz: ~p~n" -%% " Domain: ~p~n" -%% " BindTo: ~p~n" -%% " NoReuse: ~p", -%% [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), -%% IpOpts1 = bind_to(BindTo), -%% IpOpts2 = no_reuse(NoReuse), -%% IpOpts3 = recbuf(RecvSz), -%% IpOpts4 = sndbuf(SendSz), -%% IpOpts = -%% [binary, -%% snmp_conf:tdomain_to_family(Domain) | -%% IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], -%% OpenRes = -%% case init:get_argument(snmpm_fd) of -%% {ok, [[FdStr]]} -> -%% Fd = list_to_integer(FdStr), -%% gen_udp:open(0, [{fd, Fd}|IpOpts]); -%% error -> -%% gen_udp:open(Port, IpOpts) -%% end, -%% case OpenRes of -%% {error, _} = Error -> -%% throw(Error); -%% OK -> -%% OK -%% end. socket_open(IpPort, SocketOpts) -> ?vtrace("socket_open -> entry with~n" @@ -326,18 +250,6 @@ socket_open(IpPort, SocketOpts) -> Socket end. -%% bind_to(true) -> -%% case snmpm_config:system_info(address) of -%% {ok, Addr} when is_list(Addr) -> -%% [{ip, list_to_tuple(Addr)}]; -%% {ok, Addr} -> -%% [{ip, Addr}]; -%% _ -> -%% [] -%% end; -%% bind_to(_) -> -%% []. - socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) -> Family = snmp_conf:tdomain_to_family(Domain), SocketOpts = @@ -391,21 +303,6 @@ common_socket_opts(Opts) -> [] end]. -%% no_reuse(false) -> -%% [{reuseaddr, true}]; -%% no_reuse(_) -> -%% []. - -%% recbuf(default) -> -%% []; -%% recbuf(Sz) -> -%% [{recbuf, Sz}]. - -%% sndbuf(default) -> -%% []; -%% sndbuf(Sz) -> -%% [{sndbuf, Sz}]. - create_filter(Opts) when is_list(Opts) -> case get_opt(Opts, module, ?DEFAULT_FILTER_MODULE) of @@ -419,6 +316,10 @@ create_filter(BadOpts) -> throw({error, {bad_filter_opts, BadOpts}}). +%% ---------------------------------------------------------------------- +%% Audit Trail Logger +%% ---------------------------------------------------------------------- + %% Open log do_init_log(false) -> ?vtrace("do_init_log(false) -> entry", []), @@ -439,8 +340,8 @@ do_init_log(true) -> Function = increment_counter, Args = [atl_seqno, Initial, Max], SeqNoGen = {Module, Function, Args}, - case snmp_log:create(Name, File, - SeqNoGen, Size, Repair, true) of + case snmp_log:create( + Name, File, SeqNoGen, Size, Repair, true) of {ok, Log} -> ?vdebug("log created: ~w", [Log]), {Log, Type}; @@ -518,7 +419,7 @@ handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}, " Vsn: ~p~n" " MsgData: ~p~n" " Domain: ~p~n" - " Addr : ~p", [Pdu, Vsn, MsgData, Domain, Addr]), + " Addr: ~p", [Pdu, Vsn, MsgData, Domain, Addr]), maybe_process_extra_info(ExtraInfo), maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State), {noreply, State}; @@ -625,18 +526,17 @@ maybe_handle_recv_msg( case (catch FilterMod:accept_recv(Arg1, Arg2)) of false -> %% Drop the received packet - inc(netIfMsgInDrops), - ok; + inc(netIfMsgInDrops); _ -> handle_recv_msg(Domain, Addr, Bytes, State) - end. + end, + ok. handle_recv_msg(Domain, Addr, Bytes, #state{server = Pid}) when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> - Pid ! {snmp_error, {empty_message, Domain, Addr}, Domain, Addr}, - ok; - + Pid ! {snmp_error, {empty_message, Domain, Addr}, Domain, Addr}; +%% handle_recv_msg( Domain, Addr, Bytes, #state{ @@ -645,30 +545,27 @@ handle_recv_msg( mpd_state = MpdState, log = Log} = State) -> Logger = logger(Log, read, Domain, Addr), - case (catch snmpm_mpd:process_msg(Bytes, Domain, Addr, - MpdState, NoteStore, Logger)) of + case (catch snmpm_mpd:process_msg( + Bytes, Domain, Addr, MpdState, NoteStore, Logger)) of {ok, Vsn, Pdu, MS, ACM} -> - maybe_handle_recv_pdu(Domain, Addr, Vsn, Pdu, MS, ACM, - Logger, State); + maybe_handle_recv_pdu( + Domain, Addr, Vsn, Pdu, MS, ACM, Logger, State); {discarded, Reason, Report} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, Pid ! {snmp_error, ErrorInfo, Domain, Addr}, - maybe_udp_send(Domain, Addr, Report, State), - ok; + maybe_udp_send(Domain, Addr, Report, State); {discarded, Reason} -> ?vdebug("discarded: ~p", [Reason]), ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Addr}, - ok; + Pid ! {snmp_error, ErrorInfo, Domain, Addr}; Error -> error_msg("processing of received message failed: " - "~n ~p", [Error]), - ok + "~n ~p", [Error]) end. @@ -678,8 +575,7 @@ maybe_handle_recv_pdu( {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, Type)) of false -> - inc(netIfPduInDrops), - ok; + inc(netIfPduInDrops); _ -> handle_recv_pdu( Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) @@ -691,8 +587,7 @@ maybe_handle_recv_pdu( {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, trappdu)) of false -> - inc(netIfPduInDrops), - ok; + inc(netIfPduInDrops); _ -> handle_recv_pdu( Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, State) @@ -809,8 +704,7 @@ maybe_send_inform_response( "~n Reason: ~p", [Reason]), ReqId = RePdu#pdu.request_id, ErrorInfo = {failed_generating_response, {RePdu, Reason}}, - Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Addr}, - ok + Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Addr} end end. diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 516a2f444a..8f2ed6d8cd 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -59,8 +59,6 @@ { server, note_store, -%% domain, -%% sock, transports = [], mpd_state, log, @@ -170,12 +168,6 @@ init([Server, NoteStore]) -> {error, Reason} -> {stop, Reason} end. - %% case (catch do_init(Server, NoteStore)) of - %% {error, Reason} -> - %% {stop, Reason}; - %% {ok, State} -> - %% {ok, State} - %% end. do_init(Server, NoteStore) -> process_flag(trap_exit, true), @@ -192,7 +184,7 @@ do_init(Server, NoteStore) -> %% -- Verbosity -- {ok, Verbosity} = snmpm_config:system_info(net_if_verbosity), - put(sname, mnif), + put(sname, mnif), put(verbosity, Verbosity), ?vlog("starting", []), @@ -251,74 +243,6 @@ do_init(Server, NoteStore) -> {ok, State} end. - - - %% %% -- Socket -- - %% SndBuf = get_opt(Opts, sndbuf, default), - %% RecBuf = get_opt(Opts, recbuf, default), - %% BindTo = get_opt(Opts, bind_to, false), - %% NoReuse = get_opt(Opts, no_reuse, false), - - %% {ok, Port} = snmpm_config:system_info(port), - %% Domain = - %% case snmpm_config:system_info(domain) of - %% {ok, D} -> - %% D; - %% _ -> - %% snmpm_config:default_transport_domain() - %% end, - %% {ok, Sock} = do_open_port(Port, SndBuf, RecBuf, Domain, BindTo, NoReuse), - - %% %% -- Initiate counters --- - %% init_counters(), - - %% %% -- We are done --- - %% State = #state{server = Server, - %% note_store = NoteStore, - %% mpd_state = MpdState, - %% domain = Domain, - %% sock = Sock, - %% log = Log, - %% irb = IRB, - %% irgc = IrGcRef, - %% filter = FilterMod}, - %% ?vdebug("started", []), - %% {ok, State}. - - -%% %% Open port -%% do_open_port(Port, SendSz, RecvSz, Domain, BindTo, NoReuse) -> -%% ?vtrace("do_open_port -> entry with~n" -%% " Port: ~p~n" -%% " SendSz: ~p~n" -%% " RecvSz: ~p~n" -%% " Domain: ~p~n" -%% " BindTo: ~p~n" -%% " NoReuse: ~p", -%% [Port, SendSz, RecvSz, Domain, BindTo, NoReuse]), -%% IpOpts1 = bind_to(BindTo), -%% IpOpts2 = no_reuse(NoReuse), -%% IpOpts3 = recbuf(RecvSz), -%% IpOpts4 = sndbuf(SendSz), -%% IpOpts = -%% [binary, -%% snmp_conf:tdomain_to_family(Domain) | -%% IpOpts1 ++ IpOpts2 ++ IpOpts3 ++ IpOpts4], -%% OpenRes = -%% case init:get_argument(snmpm_fd) of -%% {ok, [[FdStr]]} -> -%% Fd = list_to_integer(FdStr), -%% gen_udp:open(0, [{fd, Fd}|IpOpts]); -%% error -> -%% gen_udp:open(Port, IpOpts) -%% end, -%% case OpenRes of -%% {error, _} = Error -> -%% throw(Error); -%% OK -> -%% OK -%% end. - socket_open(IpPort, SocketOpts) -> ?vtrace("socket_open -> entry with~n" " IpPort: ~p~n" @@ -330,18 +254,6 @@ socket_open(IpPort, SocketOpts) -> Socket end. -%% bind_to(true) -> -%% case snmpm_config:system_info(address) of -%% {ok, Addr} when is_list(Addr) -> -%% [{ip, list_to_tuple(Addr)}]; -%% {ok, Addr} -> -%% [{ip, Addr}]; -%% _ -> -%% [] -%% end; -%% bind_to(_) -> -%% []. - socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) -> Family = snmp_conf:tdomain_to_family(Domain), SocketOpts = @@ -395,21 +307,6 @@ common_socket_opts(Opts) -> [] end]. -%% no_reuse(false) -> -%% [{reuseaddr, true}]; -%% no_reuse(_) -> -%% []. - -%% recbuf(default) -> -%% []; -%% recbuf(Sz) -> -%% [{recbuf, Sz}]. - -%% sndbuf(default) -> -%% []; -%% sndbuf(Sz) -> -%% [{sndbuf, Sz}]. - create_filter(Opts) when is_list(Opts) -> case get_opt(Opts, module, ?DEFAULT_FILTER_MODULE) of @@ -615,7 +512,7 @@ terminate(Reason, #state{log = Log, irgc = IrGcRef}) -> ok. -do_close_log({Log, _Type}) -> +do_close_log({_Name, Log, _Type}) -> (catch snmp_log:sync(Log)), (catch snmp_log:close(Log)), ok; @@ -656,19 +553,6 @@ handle_udp(Domain, Addr, Bytes, State) -> end, State). - %% Verbosity = get(verbosity), - %% spawn_opt( - %% fun() -> - %% Log = worker_init(State, Verbosity), - %% Res = - %% (catch maybe_handle_recv_msg( - %% Domain, Addr, Bytes, - %% State#state{log = Log})), - %% worker_exit(udp, {Domain, Addr}, Res) - %% end, - %% [monitor]). - - maybe_handle_recv_msg( Domain, Addr, Bytes, #state{filter = FilterMod, transports = Transports} = State) -> @@ -816,8 +700,7 @@ handle_inform_request( Expire = t() + To, Rec = {Key, Expire, {Vsn, ACM, RePdu}}, ets:insert(snmpm_inform_request_table, Rec) - end, - ok. + end. handle_inform_response(Ref, Domain, Addr, State) -> worker( @@ -834,18 +717,6 @@ handle_inform_response(Ref, Domain, Addr, State) -> end, State). - %% Verbosity = get(verbosity), - %% spawn_opt( - %% fun() -> - %% Log = worker_init(State, Verbosity), - %% Res = (catch do_handle_inform_response( - %% Ref, Domain, Addr, State#state{log = Log})), - %% worker_exit(inform_response, {Domain, Addr}, Res) - %% end, - %% [monitor]). - - - do_handle_inform_response(Ref, Domain, Addr, State) -> Key = {Ref, Domain, Addr}, case ets:lookup(snmpm_inform_request_table, Key) of @@ -882,8 +753,7 @@ maybe_send_inform_response( "~n Reason: ~p", [Reason]), ReqId = RePdu#pdu.request_id, ErrorInfo = {failed_generating_response, {RePdu, Reason}}, - Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Addr}, - ok + Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Addr} end end. @@ -932,18 +802,6 @@ handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) -> end, State). - %% Verbosity = get(verbosity), - %% spawn_opt( - %% fun() -> - %% Log = worker_init(State, Verbosity), - %% Res = (catch maybe_handle_send_pdu( - %% Pdu, Vsn, MsgData, - %% Domain, Addr, - %% State#state{log = Log})), - %% worker_exit(send_pdu, {Domain, Addr}, Res) - %% end, - %% [monitor]). - maybe_handle_send_pdu( Pdu, Vsn, MsgData, Domain, Addr, #state{filter = FilterMod, transports = Transports} = State) -> @@ -1293,73 +1151,6 @@ worker_init(State) -> "~n State: ~p", [State]), erlang:error({worker_init, State}). -%% worker_init2(Log, Verbosity) -> -%% put(sname, mnifw), -%% put(verbosity, Verbosity), -%% Log. - - -%% worker_exit(Tag, Info, Result) -> -%% exit({net_if_worker, {Tag, Info, Result}}). - -%% handle_worker_exit(_, {_, _, {Result}}) -> -%% Result; -%% handle_worker_exit( -%% Pid, {udp, {Domain, Addr}, {Class, Reason, Stacktrace}) -> -%% warning_msg( -%% "Worker process (~p) terminated " -%% "while processing (incomming) message from %s:~n" -%% "~w:~w at ~p", -%% [Pid, snmp_conf:mk_addr_string({Domain, Addr}), -%% Class, Reason, Stacktrace]), -%% ok; -%% handle_worker_exit( -%% Pid, {send_pdu, {Domain, Addr}, {Class, Reason, Stacktrace}) -> -%% warning_msg( -%% "Worker process (~p) terminated " -%% "while processing (outgoing) pdu for %s:~n" -%% "~w:~w at ~p", -%% [Pid, snmp_conf:mk_addr_string({Domain, Addr}), -%% Class, Reason, Stacktrace]), -%% ok; -%% handle_worker_exit( -%% Pid, {inform_response, {Domain, Addr}, {Class, Reason, Stacktrace}}) -> -%% warning_msg( -%% "Worker process (~p) terminated " -%% "while processing (outgoing) inform response for %s:~n" -%% "~w:~w at ~p", -%% [Pid, snmp_conf:mk_addr_string({Domain, Addr}), -%% Class, Reason, Stacktrace]), -%% ok; -%% handle_worker_exit(Pid, Term) -> -%% warning_msg( -%% "Worker process (~p) terminated for strange reason: ~p", -%% [Pid, Term]). - - -%% %% If the manager uses legacy snmpUDPDomain e.g has not set -%% %% {domain, _}, then make sure snmpm_network_interface_filter -%% %% gets legacy arguments to not break backwards compatibility. -%% %% -%% fix_filter_address(snmpUDPDomain, {Domain, Addr}) -%% when Domain =:= snmpUDPDomain; -%% Domain =:= transportDomainUdpIpv4 -> -%% Addr; -%% fix_filter_address(_ManagerDomain, {Domain, _} = Address) -%% when is_atom(Domain) -> -%% Address; -%% fix_filter_address(snmpUDPDomain, {_, Port} = Addr) -%% when is_integer(Port) -> -%% Addr. - -%% address(Domain, Addr) when is_atom(Domain) -> -%% {Domain, Addr}; -%% address(Ip, Port) when is_integer(Port) -> -%% {snmpm_config:default_transport_domain(), {Ip, Port}}. - -%% format_address(Address) -> -%% iolist_to_binary(snmp_conf:mk_addr_string(Address)). - %% ------------------------------------------------------------------- make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> -- cgit v1.2.3 From bdbd6849aa811faf20d5ce7d577a49612266209a Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 22 Aug 2014 12:09:03 +0200 Subject: Clean up config error handling and negative results --- lib/snmp/src/agent/snmp_target_mib.erl | 15 +++++++++++++++ lib/snmp/src/agent/snmpa_conf.erl | 23 ++++++++++++++--------- lib/snmp/src/manager/snmpm_config.erl | 7 ++++++- lib/snmp/src/misc/snmp_conf.erl | 8 +++++--- lib/snmp/src/misc/snmp_config.erl | 8 ++++++-- lib/snmp/test/snmp_manager_config_test.erl | 2 +- 6 files changed, 47 insertions(+), 16 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index e916f17d6a..df694ed16b 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -181,6 +181,10 @@ check_target_addr( check_target_addr( Name, Domain, Address, Timeout, RetryCount, TagList, Params, EngineId, TMask, MMS); +check_target_addr( + {_Name, Domain, Address, _Timeout, _RetryCount, _TagList, _Params, + _EngineId, _TMask, _MMS}) -> % Arity 10 + error({bad_address, {Domain, Address}}); check_target_addr( {Name, Domain, Address, Timeout, RetryCount, TagList, Params, EngineId}) % Arity 8 @@ -197,6 +201,10 @@ check_target_addr( check_target_addr( Name, Domain, Address, Timeout, RetryCount, TagList, Params, EngineId); +check_target_addr( + {_Name, Domain, Address, _Timeout, _RetryCount, _TagList, _Params, + _EngineId}) ->% Arity 8 + error({bad_address, {Domain, Address}}); %% Use dummy engine id if the old style is found check_target_addr( {Name, Domain, Address, Timeout, RetryCount, TagList, Params}) % Arity 7 @@ -210,6 +218,9 @@ check_target_addr( Address = {Ip, Udp}, check_target_addr( Name, Domain, Address, Timeout, RetryCount, TagList, Params); +check_target_addr( + {_Name, Domain, Address, _Timeout, _RetryCount, _TagList, _Params}) -> % Arity 7 + error({bad_address, {Domain, Address}}); %% Use dummy engine id if the old style is found check_target_addr( {Name, Domain, Address, Timeout, RetryCount, TagList, Params, @@ -225,6 +236,10 @@ check_target_addr( Address = {Ip, Udp}, check_target_addr( Name, Domain, Address, Timeout, RetryCount, TagList, Params, TMask, MMS); +check_target_addr( + {_Name, Domain, Address, _Timeout, _RetryCount, _TagList, _Params, + _TMask, _MMS}) -> % Arity 9 + error({bad_address, {Domain, Address}}); check_target_addr(X) -> error({invalid_target_addr, X}). diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index b4d32dc928..fe3f63c4ca 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -473,6 +473,16 @@ write_target_addr_conf(Fd, Conf) -> lists:foreach(Fun, Conf), ok. +do_write_target_addr_conf( + Fd, + {Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize}) + when is_atom(Domain) -> + io:format( + Fd, + "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", + [Name, Domain, Address, Timeout, RetryCount, TagList, + ParamsName, EngineId, TMask, MaxMessageSize]); do_write_target_addr_conf( Fd, {Name, Ip, Udp, Timeout, RetryCount, TagList, @@ -485,15 +495,10 @@ do_write_target_addr_conf( {Name, Domain, Address, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}); do_write_target_addr_conf( - Fd, - {Name, Domain, Address, Timeout, RetryCount, TagList, - ParamsName, EngineId, TMask, MaxMessageSize}) - when is_atom(Domain) -> - io:format( - Fd, - "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n", - [Name, Domain, Address, Timeout, RetryCount, TagList, - ParamsName, EngineId, TMask, MaxMessageSize]); + _Fd, + {_Name, Domain, Address, _Timeout, _RetryCount, _TagList, + _ParamsName, _EngineId, _TMask, _MaxMessageSize}) -> + error({bad_address, {Domain, Address}}); do_write_target_addr_conf( Fd, {Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index d147aabb0b..05d5ce72b1 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -461,7 +461,7 @@ agent_info(Domain, Address, Item) when is_atom(Domain) -> [Domain, Address, Item, _Thrown, erlang:get_stacktrace()]), {error, not_found} end; -agent_info(Ip, Port, Item) -> +agent_info(Ip, Port, Item) when is_integer(Port) -> p(?MODULE_STRING":agent_info(~p, ~p, ~p) entry~n", [Ip, Port, Item]), Domain = default_transport_domain(), @@ -1698,6 +1698,11 @@ check_agent_config( UserId, TargetName, Community, Domain, Addr, EngineId, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel); +check_agent_config( + {_UserId, _TargetName, _Community, Domain, Addr, + _EngineId, _Timeout, _MaxMessageSize, + _Version, _SecModel, _SecName, _SecLevel}) -> + error({bad_address, {Domain, Addr}}); check_agent_config( {UserId, TargetName, Community, Domain, Ip, Port, EngineId, Timeout, MaxMessageSize, diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index f4483995cb..153c8070c2 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -749,8 +749,6 @@ which_domain({A0, A1, A2, A3, A4, A5, A6, A7}) %% --------- -mk_addr_string({_IP, Port} = Addr) when is_integer(Port) -> - mk_addr_string({snmpUDPDomain, Addr}); mk_addr_string({Domain, Addr}) when is_atom(Domain) -> %% XXX There is only code for IP domains here case check_address_ip(Domain, Addr) of @@ -768,7 +766,11 @@ mk_addr_string({Domain, Addr}) when is_atom(Domain) -> mk_addr_string_ntoa(Domain, Addr); IP -> mk_addr_string_ntoa(Domain, IP) - end. + end; +mk_addr_string({_IP, Port} = Addr) when is_integer(Port) -> + mk_addr_string({snmpUDPDomain, Addr}); +mk_addr_string(Strange) -> + lists:flatten(io_lib:format("~w", [Strange])). mk_addr_string_ntoa({_, _, _, _} = IP) -> diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 0a50174adc..17dfcd70b4 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -1676,7 +1676,9 @@ write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS) {intAgentIpAddress, AgentIP}, {snmpEngineID, EngineID}, {snmpEngineMaxMessageSize, MMS}], - do_write_agent_snmp_conf(Dir, Conf). + do_write_agent_snmp_conf(Dir, Conf); +write_agent_snmp_conf(_Dir, Domain, AgentAddr, _EngineID, _MMS) -> + error({bad_address, {Domain, AgentAddr}}). do_write_agent_snmp_conf(Dir, Conf) -> Comment = @@ -2153,7 +2155,9 @@ write_manager_snmp_conf(Dir, Domain_or_IP, Addr_or_Port, MMS, EngineID) -> {address, IP}]; _ when is_integer(Addr_or_Port) -> [{port, Addr_or_Port}, - {address, Domain_or_IP}] + {address, Domain_or_IP}]; + _ -> + error({bad_address, {Domain_or_IP, Addr_or_Port}}) end ++ [{engine_id, EngineID}, {max_message_size, MMS}], diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index 2f5c68d14d..f37e957dae 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -1048,7 +1048,7 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> case config_start(Opts) of {error, Reason51} -> p("start failed (as expected): ~p", [Reason51]), - ?line {failed_check, _, _, _, {bad_address, _}} = Reason51, + ?line {failed_check, _, _, _, {bad_domain, _}} = Reason51, await_config_not_running(); OK_51 -> exit({error, {unexpected_success, "51", OK_51}}) -- cgit v1.2.3 From cc9fbe12c3e7c0c99462d72fe99ee9f29051353a Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 22 Aug 2014 12:12:29 +0200 Subject: Merge manager net_if_mt into net_if --- lib/snmp/src/manager/depend.mk | 5 +- lib/snmp/src/manager/snmpm_net_if.erl | 237 +++++- lib/snmp/src/manager/snmpm_net_if_mt.erl | 1340 +----------------------------- 3 files changed, 201 insertions(+), 1381 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/depend.mk b/lib/snmp/src/manager/depend.mk index 2e7783c8ed..60f61b0d3b 100644 --- a/lib/snmp/src/manager/depend.mk +++ b/lib/snmp/src/manager/depend.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2012. All Rights Reserved. +# Copyright Ericsson AB 2004-2014. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -50,10 +50,11 @@ $(EBIN)/snmpm_net_if.$(EMULATOR): \ snmpm_network_interface.erl $(EBIN)/snmpm_net_if_mt.$(EMULATOR): \ + snmpm_net_if_mt.erl \ ../../include/snmp_types.hrl \ ../misc/snmp_debug.hrl \ ../misc/snmp_verbosity.hrl \ - snmpm_net_if_mt.erl \ + snmpm_net_if.erl \ snmpm_network_interface.erl $(EBIN)/snmpm_server.$(EMULATOR): \ diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index bdde8a5623..cb72871177 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -17,7 +17,9 @@ %% %CopyrightEnd% %% +-ifndef(snmpm_net_if_mt). -module(snmpm_net_if). +-endif. -behaviour(gen_server). -behaviour(snmpm_network_interface). @@ -148,6 +150,64 @@ filter_reset(Pid) -> cast(Pid, filter_reset). +%%%------------------------------------------------------------------- +%%% Multi-thread manager +%%%------------------------------------------------------------------- + +-ifdef(snmpm_net_if_mt). + +%% This function is called through the macro below to +%% (in the not multithreaded case) avoid creating the +%% Failer/4 fun, and to avoid calling the Worker through a fun +%% (now it shall not be a fun, just a code snippet). + +worker(Worker, Failer, #state{log = Log} = State) -> + Verbosity = get(verbosity), + spawn_opt( + fun () -> + try + put(sname, mnifw), + put(verbosity, Verbosity), + NewState = + case do_reopen_log(Log) of + Log -> + State; + NewLog -> + State#state{log = NewLog} + end, + Worker(NewState) + of + Result -> + %% Winds up in handle_info {'DOWN', ...} + erlang:exit({net_if_worker, Result}) + catch + Class:Reason -> + %% Winds up in handle_info {'DOWN', ...} + erlang:exit( + {net_if_worker, Failer, + Class, Reason, erlang:get_stacktrace()}) + end + end, + [monitor]). +-define( + worker(S, Worker, Failer, State), + begin + worker( + fun (S) -> begin Worker end end, + begin Failer end, + (State)) + end). + +-else. + +-define( + worker(S, Worker, _Failer, State), + begin (S) = (State), begin Worker end end). + +-endif. + + + %%%------------------------------------------------------------------- %%% Callback functions from gen_server %%%------------------------------------------------------------------- @@ -168,6 +228,14 @@ init([Server, NoteStore]) -> {error, Reason} -> {stop, Reason} end. + +-ifdef(snmpm_net_if_mt). +%% This should really be protected, but it also needs to +%% be writable for the worker processes, so... +-define(inform_table_opts, [set, public, named_table, {keypos, 1}]). +-else. +-define(inform_table_opts, [set, protected, named_table, {keypos, 1}]). +-endif. do_init(Server, NoteStore) -> process_flag(trap_exit, true), @@ -177,8 +245,7 @@ do_init(Server, NoteStore) -> process_flag(priority, Prio), %% -- Create inform request table -- - ets:new(snmpm_inform_request_table, - [set, protected, named_table, {keypos, 1}]), + ets:new(snmpm_inform_request_table, ?inform_table_opts), %% -- Verbosity -- {ok, Verbosity} = snmpm_config:system_info(net_if_verbosity), @@ -189,6 +256,7 @@ do_init(Server, NoteStore) -> %% -- MPD -- {ok, Vsns} = snmpm_config:system_info(versions), MpdState = snmpm_mpd:init(Vsns), + ?vdebug("MpdState: ~w", [MpdState]), %% -- Module dependent options -- {ok, Opts} = snmpm_config:system_info(net_if_options), @@ -205,6 +273,7 @@ do_init(Server, NoteStore) -> %% -- Audit trail log --- {ok, ATL} = snmpm_config:system_info(audit_trail_log), Log = do_init_log(ATL), + ?vdebug("Log: ~w", [Log]), {ok, DomainAddresses} = snmpm_config:system_info(transports), ?vdebug("DomainAddresses: ~w",[DomainAddresses]), @@ -344,20 +413,65 @@ do_init_log(true) -> Name, File, SeqNoGen, Size, Repair, true) of {ok, Log} -> ?vdebug("log created: ~w", [Log]), - {Log, Type}; + {Name, Log, Type}; {error, Reason} -> throw({error, {failed_create_audit_log, Reason}}) end; _ -> case snmp_log:create(Name, File, Size, Repair, true) of {ok, Log} -> - {Log, Type}; + ?vdebug("log created: ~w", [Log]), + {Name, Log, Type}; {error, Reason} -> throw({error, {failed_create_audit_log, Reason}}) end end. - +-ifdef(snmpm_net_if_mt). +do_reopen_log(undefined) -> + undefined; +do_reopen_log({Name, Log, Type}) -> + case snmp_log:open(Name, Log) of + {ok, NewLog} -> + {Name, NewLog, Type}; + {error, Reason} -> + warning_msg( + "NetIf worker ~p failed to open ATL:~n" + " ~p", [self(), Reason]), + undefined + end. +-endif. + +%% Close log +do_close_log(undefined) -> + ok; +do_close_log({_Name, Log, _Type}) -> + (catch snmp_log:sync(Log)), + (catch snmp_log:close(Log)), + ok; +do_close_log(_) -> + ok. + +%% Log +logger(undefined, _Type, _Domain, _Addr) -> + fun(_) -> + ok + end; +logger({_Name, Log, Types}, Type, Domain, Addr) -> + case lists:member(Type, Types) of + true -> + AddrString = + iolist_to_binary(snmp_conf:mk_addr_string({Domain, Addr})), + fun(Msg) -> + snmp_log:log(Log, Msg, AddrString) + end; + false -> + fun(_) -> + ok + end + end. + + %%-------------------------------------------------------------------- %% Func: handle_call/3 %% Returns: {reply, Reply, State} | @@ -475,11 +589,42 @@ handle_info({disk_log, _Node, Log, Info}, State) -> State2 = handle_disk_log(Log, Info, State), {noreply, State2}; +handle_info({'DOWN', _, _, _, _} = Info, State) -> + handle_info_down(Info, State); + handle_info(Info, State) -> + handle_info_unknown(Info, State). + + +handle_info_unknown(Info, State) -> warning_msg("received unknown info: ~n~p", [Info]), {noreply, State}. +-ifdef(snmpm_net_if_mt). +handle_info_down( + {'DOWN', _MRef, process, _Pid, + {net_if_worker, _Result}}, + State) -> + ?vdebug("received DOWN message from net_if worker [~w]: " + "~n Result: ~p", [_Pid, _Result]), + {noreply, State}; +handle_info_down( + {'DOWN', _MRef, process, Pid, + {net_if_worker, Failer, Class, Reason, Stacktrace} = _ExitStatus}, + State) -> + ?vdebug("received DOWN message from net_if worker [~w]: " + "~n ExitStatus: ~p", [Pid, _ExitStatus]), + Failer(Pid, Class, Reason, Stacktrace), + {noreply, State}; +handle_info_down(Info, State) -> + handle_info_unknown(Info, State). +-else. +handle_info_down(Info, State) -> + handle_info_unknown(Info, State). +-endif. + + %%-------------------------------------------------------------------- %% Func: terminate/2 %% Purpose: Shutdown the server @@ -493,14 +638,6 @@ terminate(Reason, #state{log = Log, irgc = IrGcRef}) -> ok. -do_close_log({Log, _Type}) -> - (catch snmp_log:sync(Log)), - (catch snmp_log:close(Log)), - ok; -do_close_log(_) -> - ok. - - %%---------------------------------------------------------------------- %% Func: code_change/3 %% Purpose: Convert process state when code is changed @@ -519,7 +656,20 @@ code_change(_Vsn, State, _Extra) -> %%% Internal functions %%%------------------------------------------------------------------- -maybe_handle_recv_msg( +maybe_handle_recv_msg(Domain, Addr, Bytes, State) -> + ?worker( + S, maybe_handle_recv_msg_mt(Domain, Addr, Bytes, S), + fun (Pid, Class, Reason, Stacktrace) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (incomming) message from %s:~n" + "~w:~w at ~p", + [Pid, snmp_conf:mk_addr_string({Domain, Addr}), + Class, Reason, Stacktrace]) + end, + State). + +maybe_handle_recv_msg_mt( Domain, Addr, Bytes, #state{filter = FilterMod, transports = Transports} = State) -> {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), @@ -669,6 +819,19 @@ handle_inform_request( end. handle_inform_response(Ref, Domain, Addr, State) -> + ?worker( + S, handle_inform_response_mt(Ref, Domain, Addr, S), + fun (Pid, Class, Reason, Stacktrace) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (outgoing) inform response for %s:~n" + "~w:~w at ~p", + [Pid, snmp_conf:mk_addr_string({Domain, Addr}), + Class, Reason, Stacktrace]) + end, + State). + +handle_inform_response_mt(Ref, Domain, Addr, State) -> Key = {Ref, Domain, Addr}, case ets:lookup(snmpm_inform_request_table, Key) of [{Key, _, {Vsn, ACM, RePdu}}] -> @@ -737,18 +900,30 @@ irgc_stop(undefined) -> irgc_stop(Ref) -> (catch erlang:cancel_timer(Ref)). - -maybe_handle_send_pdu( +maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) -> + ?worker( + S, maybe_handle_send_pdu_mt(Pdu, Vsn, MsgData, Domain, Addr, S), + fun (Pid, Class, Reason, Stacktrace) -> + warning_msg( + "Worker process (~p) terminated " + "while processing (outgoing) pdu for %s:~n" + "~w:~w at ~p", + [Pid, snmp_conf:mk_addr_string({Domain, Addr}), + Class, Reason, Stacktrace]) + end, + State). + +maybe_handle_send_pdu_mt( Pdu, Vsn, MsgData, Domain, Addr, #state{filter = FilterMod, transports = Transports} = State) -> {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), case (catch FilterMod:accept_send_pdu(Arg1, Arg2, pdu_type_of(Pdu))) of false -> - inc(netIfPduOutDrops), - ok; + inc(netIfPduOutDrops); _ -> handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) - end. + end, + ok. handle_send_pdu( Pdu, Vsn, MsgData, Domain, Addr, @@ -766,8 +941,7 @@ handle_send_pdu( ?vlog("PDU not sent: " "~n PDU: ~p" "~n Reason: ~p", [Pdu, Reason]), - Pid ! {snmp_error, Pdu, Reason}, - ok + Pid ! {snmp_error, Pdu, Reason} end. @@ -1085,27 +1259,6 @@ t() -> A*1000000000+B*1000+(C div 1000). -%% ------------------------------------------------------------------- - -logger(undefined, _Type, _Domain, _Addr) -> - fun(_) -> - ok - end; -logger({Log, Types}, Type, Domain, Addr) -> - case lists:member(Type, Types) of - true -> - AddrString = - iolist_to_binary(snmp_conf:mk_addr_string({Domain, Addr})), - fun(Msg) -> - snmp_log:log(Log, Msg, AddrString) - end; - false -> - fun(_) -> - ok - end - end. - - %% ------------------------------------------------------------------- %% info_msg(F, A) -> diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 8f2ed6d8cd..62f6023657 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -17,1341 +17,7 @@ %% %CopyrightEnd% %% --module(snmpm_net_if_mt). - --behaviour(gen_server). --behaviour(snmpm_network_interface). - - -%% Network Interface callback functions --export([ - start_link/2, - stop/1, - send_pdu/6, % Backward compatibility - send_pdu/7, % Partly backward compatibility - send_pdu/8, % Backward compatibility - - inform_response/4, - - note_store/2, - - info/1, - verbosity/2, - %% system_info_updated/2, - get_log_type/1, set_log_type/2, - filter_reset/1 - ]). - -%% gen_server callbacks --export([init/1, handle_call/3, handle_cast/2, handle_info/2, - code_change/3, terminate/2]). - --define(SNMP_USE_V3, true). --include("snmp_types.hrl"). --include("snmpm_internal.hrl"). --include("snmpm_atl.hrl"). --include("snmp_debug.hrl"). - -%% -define(VMODULE,"NET_IF"). --include("snmp_verbosity.hrl"). - --record(state, - { - server, - note_store, - transports = [], - mpd_state, - log, - irb = auto, % auto | {user, integer()} - irgc, - filter - }). - --record(transport, - {socket, - domain = snmpUDPDomain}). - --define(DEFAULT_FILTER_MODULE, snmpm_net_if_filter). --define(DEFAULT_FILTER_OPTS, [{module, ?DEFAULT_FILTER_MODULE}]). - --ifdef(snmp_debug). --define(GS_START_LINK(Args), - gen_server:start_link(?MODULE, Args, [{debug,[trace]}])). --else. --define(GS_START_LINK(Args), - gen_server:start_link(?MODULE, Args, [])). --endif. - - --define(IRGC_TIMEOUT, timer:minutes(5)). - --define(ATL_SEQNO_INITIAL, 1). --define(ATL_SEQNO_MAX, 2147483647). - - -%%%------------------------------------------------------------------- -%%% API -%%%------------------------------------------------------------------- -start_link(Server, NoteStore) -> - ?d("start_link -> entry with" - "~n Server: ~p" - "~n NoteStore: ~p", [Server, NoteStore]), - Args = [Server, NoteStore], - ?GS_START_LINK(Args). - -stop(Pid) -> - call(Pid, stop). - -send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port) -> - send_pdu( - Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port, ?DEFAULT_EXTRA_INFO). - -send_pdu(Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port, ExtraInfo) - when is_record(Pdu, pdu) -> - ?d("send_pdu -> entry with~n" - " Pid: ~p~n" - " Pdu: ~p~n" - " Vsn: ~p~n" - " MsgData: ~p~n" - " Domain/IP: ~p~n" - " Addr/Port: ~p", - [Pid, Pdu, Vsn, MsgData, Domain_or_Ip, Addr_or_Port]), - {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), - cast(Pid, {send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}). - -send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Ip, Port, ExtraInfo) -> - send_pdu(Pid, Pdu, Vsn, MsgData, Domain, {Ip, Port}, ExtraInfo). - -note_store(Pid, NoteStore) -> - call(Pid, {note_store, NoteStore}). - -inform_response(Pid, Ref, Domain_or_Ip, Addr_or_Port) -> - {Domain, Addr} = address(Domain_or_Ip, Addr_or_Port), - cast(Pid, {inform_response, Ref, Domain, Addr}). - -info(Pid) -> - call(Pid, info). - -verbosity(Pid, V) -> - call(Pid, {verbosity, V}). - -%% system_info_updated(Pid, What) -> -%% call(Pid, {system_info_updated, What}). - -get_log_type(Pid) -> - call(Pid, get_log_type). - -set_log_type(Pid, NewType) -> - call(Pid, {set_log_type, NewType}). - -filter_reset(Pid) -> - cast(Pid, filter_reset). - - -%%%------------------------------------------------------------------- -%%% Callback functions from gen_server -%%%------------------------------------------------------------------- - -%%-------------------------------------------------------------------- -%% Func: init/1 -%% Returns: {ok, State} | -%% {ok, State, Timeout} | -%% ignore | -%% {stop, Reason} -%%-------------------------------------------------------------------- -init([Server, NoteStore]) -> - ?d("init -> entry with" - "~n Server: ~p" - "~n NoteStore: ~p", [Server, NoteStore]), - try do_init(Server, NoteStore) - catch - {error, Reason} -> - {stop, Reason} - end. - -do_init(Server, NoteStore) -> - process_flag(trap_exit, true), - - %% -- Prio -- - {ok, Prio} = snmpm_config:system_info(prio), - process_flag(priority, Prio), - - %% -- Create inform request table -- - %% This should really be protected, but it also needs to - %% be writable for the worker processes, so... - ets:new(snmpm_inform_request_table, - [set, public, named_table, {keypos, 1}]), - - %% -- Verbosity -- - {ok, Verbosity} = snmpm_config:system_info(net_if_verbosity), - put(sname, mnif), - put(verbosity, Verbosity), - ?vlog("starting", []), - - %% -- MPD -- - {ok, Vsns} = snmpm_config:system_info(versions), - MpdState = snmpm_mpd:init(Vsns), - ?vdebug("MpdState: ~w", [MpdState]), - - %% -- Module dependent options -- - {ok, Opts} = snmpm_config:system_info(net_if_options), - - %% -- Inform response behaviour -- - {ok, IRB} = snmpm_config:system_info(net_if_irb), - IrGcRef = irgc_start(IRB), - - %% Flow control -- - FilterOpts = get_opt(Opts, filter, []), - FilterMod = create_filter(FilterOpts), - ?vdebug("FilterMod: ~w", [FilterMod]), - - %% -- Audit trail log --- - {ok, ATL} = snmpm_config:system_info(audit_trail_log), - Log = do_init_log(ATL), - ?vdebug("Log: ~w", [Log]), - - {ok, DomainAddresses} = snmpm_config:system_info(transports), - ?vdebug("DomainAddresses: ~w",[DomainAddresses]), - CommonSocketOpts = common_socket_opts(Opts), - BindTo = get_opt(Opts, bind_to, false), - case - [begin - {IpPort, SocketOpts} = - socket_params(Domain, Address, BindTo, CommonSocketOpts), - Socket = socket_open(IpPort, SocketOpts), - #transport{socket = Socket, domain = Domain} - end || {Domain, Address} <- DomainAddresses] - of - [] -> - ?vinfo("No transports configured: ~p", [DomainAddresses]), - throw({error, {no_transports,DomainAddresses}}); - Transports -> - %% -- Initiate counters --- - init_counters(), - - %% -- We are done --- - State = #state{ - server = Server, - note_store = NoteStore, - mpd_state = MpdState, - transports = Transports, - log = Log, - irb = IRB, - irgc = IrGcRef, - filter = FilterMod}, - ?vdebug("started", []), - {ok, State} - end. - -socket_open(IpPort, SocketOpts) -> - ?vtrace("socket_open -> entry with~n" - " IpPort: ~p~n" - " SocketOpts: ~p", [IpPort, SocketOpts]), - case gen_udp:open(IpPort, SocketOpts) of - {error, _} = Error -> - throw(Error); - {ok, Socket} -> - Socket - end. - -socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) -> - Family = snmp_conf:tdomain_to_family(Domain), - SocketOpts = - case Family of - inet6 -> - [Family, {ipv6_v6only, true} | CommonSocketOpts]; - Family -> - [Family | CommonSocketOpts] - end, - case Family of - inet -> - case init:get_argument(snmp_fd) of - {ok, [[FdStr]]} -> - Fd = list_to_integer(FdStr), - case BindTo of - true -> - {IpPort, [{ip, IpAddr}, {fd, Fd} | SocketOpts]}; - _ -> - {0, [{fd, Fd} | SocketOpts]} - end; - error -> - {IpPort, [{ip, IpAddr} | SocketOpts]} - end; - _ -> - case BindTo of - true -> - {IpPort, [{ip, IpAddr} | SocketOpts]}; - _ -> - {IpPort, SocketOpts} - end - end. - -common_socket_opts(Opts) -> - [binary - | case get_opt(Opts, sndbuf, default) of - default -> - []; - Sz -> - [{sndbuf, Sz}] - end ++ - case get_opt(Opts, recbuf, default) of - default -> - []; - Sz -> - [{sndbuf, Sz}] - end ++ - case get_opt(Opts, no_reuse, false) of - false -> - [{reuseaddr, true}]; - _ -> - [] - end]. - - -create_filter(Opts) when is_list(Opts) -> - case get_opt(Opts, module, ?DEFAULT_FILTER_MODULE) of - ?DEFAULT_FILTER_MODULE = Mod -> - Mod; - Module -> - snmpm_network_interface_filter:verify(Module), - Module - end; -create_filter(BadOpts) -> - throw({error, {bad_filter_opts, BadOpts}}). - - -%% ---------------------------------------------------------------------- -%% Audit Trail Logger -%% ---------------------------------------------------------------------- - -%% Open log -do_init_log(false) -> - ?vtrace("do_init_log(false) -> entry", []), - undefined; -do_init_log(true) -> - ?vtrace("do_init_log(true) -> entry", []), - {ok, Type} = snmpm_config:system_info(audit_trail_log_type), - {ok, Dir} = snmpm_config:system_info(audit_trail_log_dir), - {ok, Size} = snmpm_config:system_info(audit_trail_log_size), - {ok, Repair} = snmpm_config:system_info(audit_trail_log_repair), - Name = ?audit_trail_log_name, - File = filename:absname(?audit_trail_log_file, Dir), - case snmpm_config:system_info(audit_trail_log_seqno) of - {ok, true} -> - Initial = ?ATL_SEQNO_INITIAL, - Max = ?ATL_SEQNO_MAX, - Module = snmpm_config, - Function = increment_counter, - Args = [atl_seqno, Initial, Max], - SeqNoGen = {Module, Function, Args}, - case snmp_log:create( - Name, File, SeqNoGen, Size, Repair, true) of - {ok, Log} -> - ?vdebug("log created: ~w", [Log]), - {Name, Log, Type}; - {error, Reason} -> - throw({error, {failed_create_audit_log, Reason}}) - end; - _ -> - case snmp_log:create(Name, File, Size, Repair, true) of - {ok, Log} -> - ?vdebug("log created: ~w", [Log]), - {Name, Log, Type}; - {error, Reason} -> - throw({error, {failed_create_audit_log, Reason}}) - end - end. - - -%%-------------------------------------------------------------------- -%% Func: handle_call/3 -%% Returns: {reply, Reply, State} | -%% {reply, Reply, State, Timeout} | -%% {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, Reply, State} | (terminate/2 is called) -%% {stop, Reason, State} (terminate/2 is called) -%%-------------------------------------------------------------------- -handle_call({verbosity, Verbosity}, _From, State) -> - ?vlog("received verbosity request", []), - put(verbosity, Verbosity), - {reply, ok, State}; - -%% handle_call({system_info_updated, What}, _From, State) -> -%% ?vlog("received system_info_updated request with What = ~p", [What]), -%% {NewState, Reply} = handle_system_info_updated(State, What), -%% {reply, Reply, NewState}; - -handle_call(get_log_type, _From, State) -> - ?vlog("received get-log-type request", []), - Reply = (catch handle_get_log_type(State)), - {reply, Reply, State}; - -handle_call({set_log_type, NewType}, _From, State) -> - ?vlog("received set-log-type request with NewType = ~p", [NewType]), - {NewState, Reply} = (catch handle_set_log_type(State, NewType)), - {reply, Reply, NewState}; - -handle_call({note_store, Pid}, _From, State) -> - ?vlog("received new note_store: ~w", [Pid]), - {reply, ok, State#state{note_store = Pid}}; - -handle_call(stop, _From, State) -> - ?vlog("received stop request", []), - Reply = ok, - {stop, normal, Reply, State}; - -handle_call(info, _From, State) -> - ?vlog("received info request", []), - Reply = get_info(State), - {reply, Reply, State}; - -handle_call(Req, From, State) -> - warning_msg("received unknown request (from ~p): ~n~p", [Req, From]), - {reply, {error, {invalid_request, Req}}, State}. - - -%%-------------------------------------------------------------------- -%% Func: handle_cast/2 -%% Returns: {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, State} (terminate/2 is called) -%%-------------------------------------------------------------------- -handle_cast({send_pdu, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo}, - State) -> - ?vlog("received send_pdu message with~n" - " Pdu: ~p~n" - " Vsn: ~p~n" - " MsgData: ~p~n" - " Domain: ~p~n" - " Addr: ~p", [Pdu, Vsn, MsgData, Domain, Addr]), - maybe_process_extra_info(ExtraInfo), - handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State), - {noreply, State}; - -handle_cast({inform_response, Ref, Domain, Addr}, State) -> - ?vlog("received inform_response message with~n" - " Ref: ~p~n" - " Domain: ~p~n" - " Addr: ~p", [Ref, Domain, Addr]), - handle_inform_response(Ref, Domain, Addr, State), - {noreply, State}; - -handle_cast(filter_reset, State) -> - ?vlog("received filter_reset message", []), - reset_counters(), - {noreply, State}; - -handle_cast(Msg, State) -> - warning_msg("received unknown message: ~n~p", [Msg]), - {noreply, State}. - - -%%-------------------------------------------------------------------- -%% Func: handle_info/2 -%% Returns: {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, State} (terminate/2 is called) -%%-------------------------------------------------------------------- -handle_info( - {udp, Socket, IpAddr, IpPort, Bytes}, - #state{transports = Transports} = State) -> - Size = byte_size(Bytes), - case lists:keyfind(Socket, #transport.socket, Transports) of - #transport{socket = Socket, domain = Domain} -> - ?vlog("received ~w bytes from ~p:~p [~w]", - [Size, IpAddr, IpPort, Socket]), - handle_udp(Domain, {IpAddr, IpPort}, Bytes, State), - {noreply, State}; - false -> - warning_msg("Received ~w bytes on unknown port: ~p from ~s", - [Size, Socket, format_address({IpAddr, IpPort})]), - {noreply, State} - end; - -handle_info(inform_response_gc, State) -> - ?vlog("received inform_response_gc message", []), - State2 = handle_inform_response_gc(State), - {noreply, State2}; - -handle_info({disk_log, _Node, Log, Info}, State) -> - ?vlog("received disk_log message: " - "~n Info: ~p", [Info]), - State2 = handle_disk_log(Log, Info, State), - {noreply, State2}; - -handle_info({'DOWN', _MRef, process, _Pid, {net_if_worker, _Result}}, - State) -> - ?vdebug("received DOWN message from net_if worker [~w]: " - "~n Result: ~p", [_Pid, _Result]), - {noreply, State}; -handle_info( - {'DOWN', _MRef, process, Pid, - {net_if_worker, Failer, Class, Reason, Stacktrace} = _ExitStatus}, - State) -> - ?vdebug("received DOWN message from net_if worker [~w]: " - "~n ExitStatus: ~p", [Pid, _ExitStatus]), - Failer(Pid, Class, Reason, Stacktrace), - {noreply, State}; - -handle_info(Info, State) -> - warning_msg("received unknown info: ~n~p", [Info]), - {noreply, State}. - - -%%-------------------------------------------------------------------- -%% Func: terminate/2 -%% Purpose: Shutdown the server -%% Returns: any (ignored by gen_server) -%%-------------------------------------------------------------------- -terminate(Reason, #state{log = Log, irgc = IrGcRef}) -> - ?vdebug("terminate: ~p", [Reason]), - irgc_stop(IrGcRef), - %% Close logs - do_close_log(Log), - ok. - - -do_close_log({_Name, Log, _Type}) -> - (catch snmp_log:sync(Log)), - (catch snmp_log:close(Log)), - ok; -do_close_log(_) -> - ok. - - -%%---------------------------------------------------------------------- -%% Func: code_change/3 -%% Purpose: Convert process state when code is changed -%% Returns: {ok, NewState} -%%---------------------------------------------------------------------- - -code_change(_Vsn, State, _Extra) -> - ?d("code_change -> entry with" - "~n Vsn: ~p" - "~n State: ~p" - "~n Extra: ~p", [_Vsn, State, _Extra]), - {ok, State}. - - -%%%------------------------------------------------------------------- -%%% Internal functions -%%%------------------------------------------------------------------- - -handle_udp(Domain, Addr, Bytes, State) -> - worker( - fun (S) -> - maybe_handle_recv_msg(Domain, Addr, Bytes, S) - end, - fun (Pid, Class, Reason, Stacktrace) -> - warning_msg( - "Worker process (~p) terminated " - "while processing (incomming) message from %s:~n" - "~w:~w at ~p", - [Pid, snmp_conf:mk_addr_string({Domain, Addr}), - Class, Reason, Stacktrace]) - end, - State). - -maybe_handle_recv_msg( - Domain, Addr, Bytes, - #state{filter = FilterMod, transports = Transports} = State) -> - {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), - case (catch FilterMod:accept_recv(Arg1, Arg2)) of - false -> - %% Drop the received packet - inc(netIfMsgInDrops); - _ -> - handle_recv_msg(Domain, Addr, Bytes, State) - end, - ok. - - -handle_recv_msg(Domain, Addr, Bytes, #state{server = Pid}) - when is_binary(Bytes) andalso (size(Bytes) =:= 0) -> - Pid ! {snmp_error, {empty_message, Domain, Addr}, Domain, Addr}; -%% -handle_recv_msg( - Domain, Addr, Bytes, - #state{ - server = Pid, - note_store = NoteStore, - mpd_state = MpdState, - log = Log} = State) -> - Logger = logger(Log, read, Domain, Addr), - case (catch snmpm_mpd:process_msg( - Bytes, Domain, Addr, MpdState, NoteStore, Logger)) of - - {ok, Vsn, Pdu, MS, ACM} -> - maybe_handle_recv_pdu( - Domain, Addr, Vsn, Pdu, MS, ACM, Logger, State); - - {discarded, Reason, Report} -> - ?vdebug("discarded: ~p", [Reason]), - ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Addr}, - maybe_udp_send(Domain, Addr, Report, State); - {discarded, Reason} -> - ?vdebug("discarded: ~p", [Reason]), - ErrorInfo = {failed_processing_message, Reason}, - Pid ! {snmp_error, ErrorInfo, Domain, Addr}; - - Error -> - error_msg("processing of received message failed: " - "~n ~p", [Error]) - end. - - -maybe_handle_recv_pdu( - Domain, Addr, Vsn, #pdu{type = Type} = Pdu, PduMS, ACM, Logger, - #state{filter = FilterMod, transports = Transports} = State) -> - {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), - case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, Type)) of - false -> - inc(netIfPduInDrops); - _ -> - handle_recv_pdu( - Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) - end; -maybe_handle_recv_pdu( - Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, - #state{filter = FilterMod, transports = Transports} = State) - when is_record(Trap, trappdu) -> - {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), - case (catch FilterMod:accept_recv_pdu(Arg1, Arg2, trappdu)) of - false -> - inc(netIfPduInDrops); - _ -> - handle_recv_pdu( - Domain, Addr, Vsn, Trap, PduMS, ACM, Logger, State) - end; -maybe_handle_recv_pdu( - Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State) -> - handle_recv_pdu(Domain, Addr, Vsn, Pdu, PduMS, ACM, Logger, State). - - -handle_recv_pdu( - Domain, Addr, Vsn, - #pdu{type = 'inform-request'} = Pdu, _PduMS, ACM, Logger, - #state{server = Pid, irb = IRB} = State) -> - handle_inform_request( - IRB, Pid, Vsn, Pdu, ACM, Domain, Addr, Logger, State); -handle_recv_pdu( - Domain, Addr, _Vsn, - #pdu{type = report} = Pdu, _PduMS, ok, _Logger, - #state{server = Pid} = _State) -> - ?vtrace("received report - ok", []), - Pid ! {snmp_report, {ok, Pdu}, Domain, Addr}; -handle_recv_pdu( - Domain, Addr, _Vsn, - #pdu{type = report} = Pdu, _PduMS, {error, ReqId, Reason}, _Logger, - #state{server = Pid} = _State) -> - ?vtrace("received report - error", []), - Pid ! {snmp_report, {error, ReqId, Reason, Pdu}, Domain, Addr}; -handle_recv_pdu( - Domain, Addr, _Vsn, - #pdu{type = 'snmpv2-trap'} = Pdu, _PduMS, _ACM, _Logger, - #state{server = Pid} = _State) -> - ?vtrace("received snmpv2-trap", []), - Pid ! {snmp_trap, Pdu, Domain, Addr}; -handle_recv_pdu( - Domain, Addr, _Vsn, Trap, _PduMS, _ACM, _Logger, - #state{server = Pid} = _State) when is_record(Trap, trappdu) -> - ?vtrace("received trappdu", []), - Pid ! {snmp_trap, Trap, Domain, Addr}; -handle_recv_pdu( - Domain, Addr, _Vsn, Pdu, _PduMS, _ACM, _Logger, - #state{server = Pid} = _State) when is_record(Pdu, pdu) -> - ?vtrace("received pdu", []), - Pid ! {snmp_pdu, Pdu, Domain, Addr}; -handle_recv_pdu( - _Domain, _Addr, _Vsn, Pdu, _PduMS, ACM, _Logger, _State) -> - ?vlog("received unexpected pdu: " - "~n Pdu: ~p" - "~n ACM: ~p", [Pdu, ACM]). - - -handle_inform_request( - auto, Pid, Vsn, Pdu, ACM, Domain, Addr, Logger, State) -> - ?vtrace("received inform-request (true)", []), - Pid ! {snmp_inform, ignore, Pdu, Domain, Addr}, - RePdu = make_response_pdu(Pdu), - maybe_send_inform_response(RePdu, Vsn, ACM, Domain, Addr, Logger, State); -handle_inform_request( - {user, To}, Pid, Vsn, #pdu{request_id = ReqId} = Pdu, - ACM, Domain, Addr, _Logger, _State) -> - ?vtrace("received inform-request (false)", []), - - Pid ! {snmp_inform, ReqId, Pdu, Domain, Addr}, - - %% Before we go any further, we need to check that we have not - %% already received this message (possible resend). - - Key = {ReqId, Domain, Addr}, - case ets:lookup(snmpm_inform_request_table, Key) of - [_] -> - %% OK, we already know about this. We assume this - %% is a resend. Either the agent is really eager or - %% the user has not answered yet. Bad user! - ok; - [] -> - RePdu = make_response_pdu(Pdu), - Expire = t() + To, - Rec = {Key, Expire, {Vsn, ACM, RePdu}}, - ets:insert(snmpm_inform_request_table, Rec) - end. - -handle_inform_response(Ref, Domain, Addr, State) -> - worker( - fun (S) -> - do_handle_inform_response(Ref, Domain, Addr, S) - end, - fun (Pid, Class, Reason, Stacktrace) -> - warning_msg( - "Worker process (~p) terminated " - "while processing (outgoing) inform response for %s:~n" - "~w:~w at ~p", - [Pid, snmp_conf:mk_addr_string({Domain, Addr}), - Class, Reason, Stacktrace]) - end, - State). - -do_handle_inform_response(Ref, Domain, Addr, State) -> - Key = {Ref, Domain, Addr}, - case ets:lookup(snmpm_inform_request_table, Key) of - [{Key, _, {Vsn, ACM, RePdu}}] -> - Logger = logger(State#state.log, read, Domain, Addr), - ets:delete(snmpm_inform_request_table, Key), - maybe_send_inform_response( - RePdu, Vsn, ACM, Domain, Addr, Logger, State); - [] -> - %% Already acknowledged, or the user was to slow to reply... - ok - end, - ok. - -maybe_send_inform_response( - RePdu, Vsn, ACM, Domain, Addr, Logger, - #state{ - server = Pid, - filter = FilterMod, - transports = Transports} = State) -> - {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), - case (catch FilterMod:accept_send_pdu( - Arg1, Arg2, pdu_type_of(RePdu))) - of - false -> - inc(netIfPduOutDrops), - ok; - _ -> - case snmpm_mpd:generate_response_msg(Vsn, RePdu, ACM, Logger) of - {ok, Msg} -> - maybe_udp_send(Domain, Addr, Msg, State); - {discarded, Reason} -> - ?vlog("failed generating response message:" - "~n Reason: ~p", [Reason]), - ReqId = RePdu#pdu.request_id, - ErrorInfo = {failed_generating_response, {RePdu, Reason}}, - Pid ! {snmp_error, ReqId, ErrorInfo, Domain, Addr} - end - end. - -handle_inform_response_gc(#state{irb = IRB} = State) -> - ets:safe_fixtable(snmpm_inform_request_table, true), - do_irgc(ets:first(snmpm_inform_request_table), t()), - ets:safe_fixtable(snmpm_inform_request_table, false), - State#state{irgc = irgc_start(IRB)}. - -%% We are deleting at the same time as we are traversing the table!!! -do_irgc('$end_of_table', _) -> - ok; -do_irgc(Key, Now) -> - Next = ets:next(snmpm_inform_request_table, Key), - case ets:lookup(snmpm_inform_request_table, Key) of - [{Key, BestBefore, _}] when BestBefore < Now -> - ets:delete(snmpm_inform_request_table, Key); - _ -> - ok - end, - do_irgc(Next, Now). - -irgc_start(auto) -> - undefined; -irgc_start(_) -> - erlang:send_after(?IRGC_TIMEOUT, self(), inform_response_gc). - -irgc_stop(undefined) -> - ok; -irgc_stop(Ref) -> - (catch erlang:cancel_timer(Ref)). - - -handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) -> - worker( - fun (S) -> - maybe_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, S) - end, - fun (Pid, Class, Reason, Stacktrace) -> - warning_msg( - "Worker process (~p) terminated " - "while processing (outgoing) pdu for %s:~n" - "~w:~w at ~p", - [Pid, snmp_conf:mk_addr_string({Domain, Addr}), - Class, Reason, Stacktrace]) - end, - State). - -maybe_handle_send_pdu( - Pdu, Vsn, MsgData, Domain, Addr, - #state{filter = FilterMod, transports = Transports} = State) -> - {Arg1, Arg2} = fix_filter_address(Transports, {Domain, Addr}), - case (catch FilterMod:accept_send_pdu(Arg1, Arg2, pdu_type_of(Pdu))) of - false -> - inc(netIfPduOutDrops), - ok; - _ -> - do_handle_send_pdu(Pdu, Vsn, MsgData, Domain, Addr, State) - end. - -do_handle_send_pdu( - Pdu, Vsn, MsgData, Domain, Addr, - #state{ - server = Pid, - note_store = NoteStore, - log = Log} = State) -> - Logger = logger(Log, write, Domain, Addr), - case (catch snmpm_mpd:generate_msg( - Vsn, NoteStore, Pdu, MsgData, Logger)) of - {ok, Msg} -> - ?vtrace("do_handle_send_pdu -> message generated", []), - maybe_udp_send(Domain, Addr, Msg, State); - {discarded, Reason} -> - ?vlog("PDU not sent: " - "~n PDU: ~p" - "~n Reason: ~p", [Pdu, Reason]), - Pid ! {snmp_error, Pdu, Reason}, - ok - end. - - -maybe_udp_send( - Domain, Addr, Msg, - #state{filter = FilterMod, transports = Transports}) -> - To = {Domain, Addr}, - {Arg1, Arg2} = fix_filter_address(Transports, To), - case (catch FilterMod:accept_send(Arg1, Arg2)) of - false -> - inc(netIfMsgOutDrops), - ok; - _ -> - case select_transport_from_domain(Domain, Transports) of - false -> - error_msg( - "Can not find transport~n" - " size: ~p~n" - " to: ~s", - [sz(Msg), format_address(To)]); - #transport{socket = Socket} -> - udp_send(Socket, Addr, Msg) - end - end. - -udp_send(Sock, To, Msg) -> - {IpAddr, IpPort} = - case To of - {Domain, Addr} when is_atom(Domain) -> - Addr; - {_, P} = Addr when is_integer(P) -> - Addr - end, - try gen_udp:send(Sock, IpAddr, IpPort, Msg) of - ok -> - ?vdebug("sent ~w bytes to ~w:~w [~w]", - [sz(Msg), IpAddr, IpPort, Sock]), - ok; - {error, Reason} -> - error_msg("failed sending message to ~p:~p:~n" - " ~p",[IpAddr, IpPort, Reason]) - catch - error:Error -> - error_msg("failed sending message to ~p:~p:~n" - " error:~p~n" - " ~p", - [IpAddr, IpPort, Error, erlang:get_stacktrace()]) - end. - -sz(B) when is_binary(B) -> - byte_size(B); -sz(L) when is_list(L) -> - length(L); -sz(_) -> - undefined. - - -handle_disk_log(_Log, {wrap, NoLostItems}, State) -> - ?vlog("Audit Trail Log - wrapped: ~w previously logged items where lost", - [NoLostItems]), - State; -handle_disk_log(_Log, {truncated, NoLostItems}, State) -> - ?vlog("Audit Trail Log - truncated: ~w items where lost when truncating", - [NoLostItems]), - State; -handle_disk_log(_Log, full, State) -> - error_msg("Failed to write to Audit Trail Log (full)", []), - State; -handle_disk_log(_Log, {error_status, ok}, State) -> - State; -handle_disk_log(_Log, {error_status, {error, Reason}}, State) -> - error_msg("Error status received from Audit Trail Log: " - "~n~p", [Reason]), - State; -handle_disk_log(_Log, _Info, State) -> - State. - - -%% mk_discovery_msg('version-3', Pdu, _VsnHdr, UserName) -> -%% ScopedPDU = #scopedPdu{contextEngineID = "", -%% contextName = "", -%% data = Pdu}, -%% Bytes = snmp_pdus:enc_scoped_pdu(ScopedPDU), -%% MsgID = get(msg_id), -%% put(msg_id,MsgID+1), -%% UsmSecParams = -%% #usmSecurityParameters{msgAuthoritativeEngineID = "", -%% msgAuthoritativeEngineBoots = 0, -%% msgAuthoritativeEngineTime = 0, -%% msgUserName = UserName, -%% msgPrivacyParameters = "", -%% msgAuthenticationParameters = ""}, -%% SecBytes = snmp_pdus:enc_usm_security_parameters(UsmSecParams), -%% PduType = Pdu#pdu.type, -%% Hdr = #v3_hdr{msgID = MsgID, -%% msgMaxSize = 1000, -%% msgFlags = snmp_misc:mk_msg_flags(PduType, 0), -%% msgSecurityModel = ?SEC_USM, -%% msgSecurityParameters = SecBytes}, -%% Msg = #message{version = 'version-3', vsn_hdr = Hdr, data = Bytes}, -%% case (catch snmp_pdus:enc_message_only(Msg)) of -%% {'EXIT', Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% L when list(L) -> -%% {Msg, L} -%% end; -%% mk_discovery_msg(Version, Pdu, {Com, _, _, _, _}, UserName) -> -%% Msg = #message{version = Version, vsn_hdr = Com, data = Pdu}, -%% case catch snmp_pdus:enc_message(Msg) of -%% {'EXIT', Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% L when list(L) -> -%% {Msg, L} -%% end. - - -%% mk_msg('version-3', Pdu, {Context, User, EngineID, CtxEngineId, SecLevel}, -%% MsgData) -> -%% %% Code copied from snmp_mpd.erl -%% {MsgId, SecName, SecData} = -%% if -%% tuple(MsgData), Pdu#pdu.type == 'get-response' -> -%% MsgData; -%% true -> -%% Md = get(msg_id), -%% put(msg_id, Md + 1), -%% {Md, User, []} -%% end, -%% ScopedPDU = #scopedPdu{contextEngineID = CtxEngineId, -%% contextName = Context, -%% data = Pdu}, -%% ScopedPDUBytes = snmp_pdus:enc_scoped_pdu(ScopedPDU), - -%% PduType = Pdu#pdu.type, -%% V3Hdr = #v3_hdr{msgID = MsgId, -%% msgMaxSize = 1000, -%% msgFlags = snmp_misc:mk_msg_flags(PduType, SecLevel), -%% msgSecurityModel = ?SEC_USM}, -%% Message = #message{version = 'version-3', vsn_hdr = V3Hdr, -%% data = ScopedPDUBytes}, -%% SecEngineID = case PduType of -%% 'get-response' -> snmp_framework_mib:get_engine_id(); -%% _ -> EngineID -%% end, -%% case catch snmp_usm:generate_outgoing_msg(Message, SecEngineID, -%% SecName, SecData, SecLevel) of -%% {'EXIT', Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% {error, Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% Packet -> -%% Packet -%% end; -%% mk_msg(Version, Pdu, {Com, _User, _EngineID, _Ctx, _SecLevel}, _SecData) -> -%% Msg = #message{version = Version, vsn_hdr = Com, data = Pdu}, -%% case catch snmp_pdus:enc_message(Msg) of -%% {'EXIT', Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% B when list(B) -> -%% B -%% end. - - -%% handle_system_info_updated(#state{log = {Log, _OldType}} = State, -%% audit_trail_log_type = _What) -> -%% %% Just to make sure, check that ATL is actually enabled -%% case snmpm_config:system_info(audit_trail_log) of -%% {ok, true} -> -%% {ok, Type} = snmpm_config:system_info(audit_trail_log_type), -%% NewState = State#state{log = {Log, Type}}, -%% {NewState, ok}; -%% _ -> -%% {State, {error, {adt_not_enabled}}} -%% end; -%% handle_system_info_updated(_State, _What) -> -%% ok. - -handle_get_log_type(#state{log = {_Log, Value}} = State) -> - %% Just to make sure, check that ATL is actually enabled - case snmpm_config:system_info(audit_trail_log) of - {ok, true} -> - Type = - case {lists:member(read, Value), lists:member(write, Value)} of - {true, true} -> - read_write; - {true, false} -> - read; - {false, true} -> - write; - {false, false} -> - throw({State, {error, {bad_atl_type, Value}}}) - end, - {ok, Type}; - _ -> - {error, not_enabled} - end; -handle_get_log_type(_State) -> - {error, not_enabled}. - -handle_set_log_type(#state{log = {Log, OldValue}} = State, NewType) -> - %% Just to make sure, check that ATL is actually enabled - case snmpm_config:system_info(audit_trail_log) of - {ok, true} -> - NewValue = - case NewType of - read -> - [read]; - write -> - [write]; - read_write -> - [read,write]; - _ -> - throw({State, {error, {bad_atl_type, NewType}}}) - end, - NewState = State#state{log = {Log, NewValue}}, - OldType = - case {lists:member(read, OldValue), - lists:member(write, OldValue)} of - {true, true} -> - read_write; - {true, false} -> - read; - {false, true} -> - write; - {false, false} -> - throw({State, {error, {bad_atl_type, OldValue}}}) - end, - {NewState, {ok, OldType}}; - _ -> - {State, {error, not_enabled}} - end; -handle_set_log_type(State, _NewType) -> - {State, {error, not_enabled}}. - - -select_transport_from_domain(Domain, Transports) when is_atom(Domain) -> - Pos = #transport.domain, - case lists:keyfind(Domain, Pos, Transports) of - #transport{domain = Domain} = Transport -> - Transport; - false when Domain == snmpUDPDomain -> - lists:keyfind(transportDomainUdpIpv4, Pos, Transports); - false when Domain == transportDomainUdpIpv4 -> - lists:keyfind(snmpUDPDomain, Pos, Transports); - false -> - false - end. - -%% If the manager uses legacy snmpUDPDomain e.g has not set -%% {domain, _}, then make sure snmpm_network_interface_filter -%% gets legacy arguments to not break backwards compatibility. -%% -fix_filter_address(Transports, Address) -> - DefaultDomain = snmpm_config:default_transport_domain(), - case Transports of - [#transport{domain = DefaultDomain}, DefaultDomain] -> - case Address of - {Domain, Addr} when is_atom(Domain) -> - Addr; - {_, IpPort} = Addr when is_integer(IpPort) -> - Addr - end; - _ -> - Address - end. - -address(Domain, Addr) when is_atom(Domain) -> - {Domain, Addr}; -address(Ip, Port) when is_integer(Port) -> - {snmpm_config:default_transport_domain(), {Ip, Port}}. - -format_address(Address) -> - iolist_to_binary(snmp_conf:mk_addr_string(Address)). - -%% ------------------------------------------------------------------- - -worker(Worker, Failer, State) -> - Verbosity = get(verbosity), - spawn_opt( - fun () -> - try - put(sname, mnifw), - put(verbosity, Verbosity), - Worker(worker_init(State)) - of - Result -> - %% Winds up in handle_info {'DOWN', ...} - erlang:exit({net_if_worker, Result}) - catch - Class:Reason -> - %% Winds up in handle_info {'DOWN', ...} - erlang:exit( - {net_if_worker, Failer, - Class, Reason, erlang:get_stacktrace()}) - end - end, - [monitor]). - -worker_init(#state{log = undefined} = State) -> - State; -worker_init(#state{log = {Name, Log, Type}} = State) -> - case snmp_log:open(Name, Log) of - {ok, NewLog} -> - State#state{log = {Name, NewLog, Type}}; - {error, Reason} -> - warning_msg("NetIf worker ~p failed opening ATL: " - "~n ~p", [self(), Reason]), - State#state{log = {Name, undefined, Type}} - end; -worker_init(State) -> - ?vinfo("worker_init -> entry with invalid data: " - "~n State: ~p", [State]), - erlang:error({worker_init, State}). - -%% ------------------------------------------------------------------- - -make_response_pdu(#pdu{request_id = ReqId, varbinds = Vbs}) -> - #pdu{type = 'get-response', - request_id = ReqId, - error_status = noError, - error_index = 0, - varbinds = Vbs}. - - -%% ---------------------------------------------------------------- - -pdu_type_of(#pdu{type = Type}) -> - Type; -pdu_type_of(TrapPdu) when is_record(TrapPdu, trappdu) -> - trap. - - -%% ------------------------------------------------------------------- - -%% At this point this function is used during testing -maybe_process_extra_info(?DEFAULT_EXTRA_INFO) -> - ok; -maybe_process_extra_info({?SNMPM_EXTRA_INFO_TAG, Fun}) - when is_function(Fun, 0) -> - (catch Fun()), - ok; -maybe_process_extra_info(_ExtraInfo) -> - ok. - - -%% ------------------------------------------------------------------- - -t() -> - {A,B,C} = erlang:now(), - A*1000000000+B*1000+(C div 1000). - - -%% ------------------------------------------------------------------- - -logger(undefined, _Type, _Domain, _Addr) -> - fun(_) -> - ok - end; -logger({_Name, Log, Types}, Type, Domain, Addr) -> - case lists:member(Type, Types) of - true -> - AddrString = - iolist_to_binary(snmp_conf:mk_addr_string({Domain, Addr})), - fun(Msg) -> - snmp_log:log(Log, Msg, AddrString) - end; - false -> - fun(_) -> - ok - end - end. - - -%% ------------------------------------------------------------------- - -%% info_msg(F, A) -> -%% ?snmpm_info("NET-IF server: " ++ F, A). - -warning_msg(F, A) -> - ?snmpm_warning("NET-IF server: " ++ F, A). - -error_msg(F, A) -> - ?snmpm_error("NET-IF server: " ++ F, A). - - - -%%%------------------------------------------------------------------- - -% get_opt(Key, Opts) -> -% ?vtrace("get option ~w", [Key]), -% snmp_misc:get_option(Key, Opts). - -get_opt(Opts, Key, Def) -> - ?vtrace("get option ~w with default ~p", [Key, Def]), - snmp_misc:get_option(Key, Opts, Def). - - -%% ------------------------------------------------------------------- - -get_info(#state{transports = Transports}) -> - ProcSize = proc_mem(self()), - [{process_memory, ProcSize} - | [{port_info, get_port_info(Socket)} - || #transport{socket = Socket} <- Transports]]. - -proc_mem(P) when is_pid(P) -> - case (catch erlang:process_info(P, memory)) of - {memory, Sz} when is_integer(Sz) -> - Sz; - _ -> - undefined - end. -%% proc_mem(_) -> -%% undefined. - - -get_port_info(Id) -> - PortInfo = - case (catch erlang:port_info(Id)) of - PI when is_list(PI) -> - [{port_info, PI}]; - _ -> - [] - end, - PortStatus = - case (catch prim_inet:getstatus(Id)) of - {ok, PS} -> - [{port_status, PS}]; - _ -> - [] - end, - PortAct = - case (catch inet:getopts(Id, [active])) of - {ok, PA} -> - [{port_act, PA}]; - _ -> - [] - end, - PortStats = - case (catch inet:getstat(Id)) of - {ok, Stat} -> - [{port_stats, Stat}]; - _ -> - [] - end, - IfList = - case (catch inet:getif(Id)) of - {ok, IFs} -> - [{interfaces, IFs}]; - _ -> - [] - end, - BufSz = - case (catch inet:getopts(Id, [recbuf, sndbuf, buffer])) of - {ok, Sz} -> - [{buffer_size, Sz}]; - _ -> - [] - end, - [{socket, Id}] ++ - IfList ++ - PortStats ++ - PortInfo ++ - PortStatus ++ - PortAct ++ - BufSz. - - -%%----------------------------------------------------------------- -%% Counter functions -%%----------------------------------------------------------------- -init_counters() -> - F = fun(Counter) -> maybe_create_counter(Counter) end, - lists:map(F, counters()). - -reset_counters() -> - F = fun(Counter) -> snmpm_config:reset_stats_counter(Counter) end, - lists:map(F, counters()). - -maybe_create_counter(Counter) -> - snmpm_config:maybe_cre_stats_counter(Counter, 0). - -counters() -> - [ - netIfMsgOutDrops, - netIfMsgInDrops, - netIfPduOutDrops, - netIfPduInDrops - ]. - -inc(Name) -> inc(Name, 1). -inc(Name, N) -> snmpm_config:incr_stats_counter(Name, N). - -%% get_counters() -> -%% Counters = counters(), -%% get_counters(Counters, []). - -%% get_counters([], Acc) -> -%% lists:reverse(Acc); -%% get_counters([Counter|Counters], Acc) -> -%% case snmpm_config:get_stats_counter(Counter) of -%% {ok, CounterVal} -> -%% get_counters(Counters, [{Counter, CounterVal}|Acc]); -%% _ -> -%% get_counters(Counters, Acc) -%% end. - - -%% ---------------------------------------------------------------- - -call(Pid, Req) -> - call(Pid, Req, infinity). - -call(Pid, Req, Timeout) -> - gen_server:call(Pid, Req, Timeout). - -cast(Pid, Msg) -> - gen_server:cast(Pid, Msg). +-define(snmpm_net_if_mt, true). +-module(snmpm_net_if_mt). +-include("snmpm_net_if.erl"). -- cgit v1.2.3 From 46f752b15205977cb1191c1693e942a499d351f9 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 25 Aug 2014 10:59:54 +0200 Subject: Raise timeout and see if testcases stabilize --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index c514eafd7d..2f96493ac5 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -170,7 +170,7 @@ end_per_group(_GroupName, Config) -> Config. init_per_testcase(_Case, Config) -> - Dog = ct:timetrap(10000), + Dog = ct:timetrap(20000), application:stop(snmp), application:unload(snmp), [{watchdog, Dog} | Config]. -- cgit v1.2.3 From 5bd1edc7b53dbcea6f63e0a7fb57925935e6b293 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 29 Aug 2014 11:19:52 +0200 Subject: Clean up some config warts --- lib/snmp/src/agent/snmp_framework_mib.erl | 34 ++++++++++++++----------- lib/snmp/src/agent/snmp_target_mib.erl | 33 +++++++++++++++--------- lib/snmp/src/agent/snmpa_conf.erl | 15 ++++++++++- lib/snmp/src/manager/snmpm_conf.erl | 7 +++--- lib/snmp/src/manager/snmpm_config.erl | 42 +++++++++++++++++++++++++------ lib/snmp/src/manager/snmpm_server.erl | 11 +++++++- 6 files changed, 103 insertions(+), 39 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 9d3f7ef5e7..6ff9224d34 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -207,22 +207,28 @@ check_agent({intAgentIpAddress = Tag, Ip} = Entry, {Domain, Port} = State) -> [{Tag, FixedIp}, {intAgentTransports, [{Domain, {FixedIp, Port}}]}] end, State}; -check_agent({intAgentTransports = Tag, Transports}, {_, Port} = State) -> +check_agent({intAgentTransports = Tag, Transports}, {_, Port} = State) + when is_list(Transports) -> CheckedTransports = - [case - case Port of - undefined -> - snmp_conf:check_address(Domain, Address); - _ -> - snmp_conf:check_address(Domain, Address, Port) - end - of - ok -> - Transport; - {ok, FixedAddress} -> - {Domain, FixedAddress} + [case Transport of + {Domain, Address} -> + case + case Port of + undefined -> + snmp_conf:check_address(Domain, Address); + _ -> + snmp_conf:check_address(Domain, Address, Port) + end + of + ok -> + Transport; + {ok, FixedAddress} -> + {Domain, FixedAddress} + end; + _ -> + error({bad_transport, Transport}) end - || {Domain, Address} = Transport <- Transports], + || Transport <- Transports], {{ok, {Tag, CheckedTransports}}, State}; check_agent(Entry, State) -> {check_agent(Entry), State}. diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index df694ed16b..ef9503cda8 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -306,7 +306,7 @@ check_engine_id(EngineId) -> snmp_conf:check_string(EngineId). check_address(Domain, Address) -> - case snmp_conf:check_address(Domain, Address) of + case snmp_conf:check_address(Domain, Address, 162) of ok -> Address; {ok, NAddress} -> @@ -316,7 +316,11 @@ check_address(Domain, Address) -> check_mask(_Domain, [] = Mask) -> Mask; check_mask(Domain, Mask) -> - try check_address(Domain, Mask) + try snmp_conf:check_address(Domain, Mask) of + ok -> + Mask; + {ok, NMask} -> + NMask catch {error, {bad_address, Info}} -> error({bad_mask, Info}) @@ -380,16 +384,21 @@ table_del_row(Tab, Key) -> snmpa_mib_lib:table_del_row(db(Tab), Key). -add_addr(Name, Ip, Port, Timeout, Retry, TagList, - Params, EngineId, TMask, MMS) -> - Domain = default_domain(), - add_addr(Name, Domain, Ip, Port, Timeout, Retry, TagList, - Params, EngineId, TMask, MMS). - -add_addr(Name, Domain, Ip, Port, Timeout, Retry, TagList, - Params, EngineId, TMask, MMS) -> - Addr = {Name, Domain, Ip, Port, Timeout, Retry, TagList, - Params, EngineId, TMask, MMS}, +add_addr( + Name, Domain_or_Ip, Addr_or_Port, Timeout, Retry, TagList, Params, + EngineId, TMask, MMS) -> + add_addr( + {Name, Domain_or_Ip, Addr_or_Port, Timeout, Retry, TagList, Params, + EngineId, TMask, MMS}). +%% +add_addr( + Name, Domain, Ip, Port, Timeout, Retry, TagList, Params, + EngineId, TMask, MMS) -> + add_addr( + {Name, Domain, Ip, Port, Timeout, Retry, TagList, Params, + EngineId, TMask, MMS}). +%% +add_addr(Addr) -> case (catch check_target_addr(Addr)) of {ok, Row} -> Key = element(1, Row), diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index fe3f63c4ca..534d0e447b 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -47,7 +47,7 @@ read_standard_config/1, %% target_addr.conf - target_addr_entry/5, target_addr_entry/6, + target_addr_entry/5, target_addr_entry/6, target_addr_entry/7, target_addr_entry/8, target_addr_entry/10, target_addr_entry/11, write_target_addr_config/2, write_target_addr_config/3, append_target_addr_config/2, @@ -385,6 +385,12 @@ target_addr_entry( Name, Ip, TagList, ParamsName, EngineId) -> target_addr_entry(Name, Ip, TagList, ParamsName, EngineId, []). +target_addr_entry( + Name, Domain, Addr, TagList, + ParamsName, EngineId) when is_atom(Domain) -> + target_addr_entry( + Name, Domain, Addr, TagList, + ParamsName, EngineId, []); target_addr_entry( Name, Ip, TagList, ParamsName, EngineId, TMask) -> @@ -392,6 +398,13 @@ target_addr_entry( Name, Ip, 162, TagList, ParamsName, EngineId, TMask, 2048). +target_addr_entry( + Name, Domain_or_Ip, Addr_or_Port, TagList, + ParamsName, EngineId, TMask) -> + target_addr_entry( + Name, Domain_or_Ip, Addr_or_Port, TagList, + ParamsName, EngineId, TMask, 2048). + target_addr_entry( Name, Domain_or_Ip, Addr_or_Port, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index e03d28a3e4..087ef6c6ea 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -200,9 +200,10 @@ do_write_users_conf(_Fd, Crap) -> %% ------ agents.conf ------ %% -agents_entry(UserId, TargetName, Comm, Ip, Port, EngineID, Timeout, - MaxMessageSize, Version, SecModel, SecName, SecLevel) -> - {UserId, TargetName, Comm, Ip, Port, EngineID, Timeout, +agents_entry( + UserId, TargetName, Comm, Domain_or_Ip, Addr_or_Port, EngineID, Timeout, + MaxMessageSize, Version, SecModel, SecName, SecLevel) -> + {UserId, TargetName, Comm, Domain_or_Ip, Addr_or_Port, EngineID, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}. diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 05d5ce72b1..940800fed4 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1816,7 +1816,11 @@ verify_agent_config( {TD, VerifiedConf}; _ -> %% Insert tdomain since it is missing - TD = default_transport_domain(), + %% Note: not default_transport_domain() since + %% taddress is the new format hence the application + %% should be tdomain aware and therefore addresses + %% on the Domain, Addr format should be used and understood. + TD = transportDomainUdpIpv4, {TD, [{tdomain, TD}|VerifiedConf]} end, case snmp_conf:check_address(TDomain, Address, 0) of @@ -2269,15 +2273,37 @@ check_manager_config({address = Tag, Ip} = Entry, {Domain, Port} = State) -> [{Tag, FixedIp}, {transports, [{Domain, {FixedIp, Port}}]}] end, State}; -check_manager_config({transports = Tag, Transports}, State) -> +check_manager_config({transports = Tag, Transports}, {_, Port} = State) + when is_list(Transports) -> CheckedTransports = - [case snmp_conf:check_address(Domain, Address) of - ok -> - Transport; - {ok, FixedAddress} -> - {Domain, FixedAddress} + [case Transport of + {Domain, Address} -> + case + case Port of + undefined -> + snmp_conf:check_address(Domain, Address); + _ -> + snmp_conf:check_address(Domain, Address, Port) + end + of + ok -> + Transport; + {ok, FixedAddress} -> + {Domain, FixedAddress} + end; + _Domain when Port =:= undefined-> + error({missing_mandatory, port}); + Domain -> + Family = snmp_conf:tdomain_to_family(Domain), + {ok, Hostname} = inet:gethostname(), + case inet:getaddr(Hostname, Family) of + {ok, IpAddr} -> + {Domain, {IpAddr, Port}}; + {error, _} -> + error({bad_address, {Domain, Hostname}}) + end end - || {Domain, Address} = Transport <- Transports], + || Transport <- Transports], {{ok, {Tag, CheckedTransports}}, State}; check_manager_config(Entry, State) -> {check_manager_config(Entry), State}. diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index ece5dad082..a75122d0bb 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -2079,7 +2079,16 @@ do_handle_agent(DefUserId, DefMod, SnmpInfo, DefData, State) -> ?vdebug("do_handle_agent -> entry when" "~n DefUserId: ~p", [DefUserId]), - try DefMod:handle_agent(Domain, Addr, Type, SnmpInfo, DefData) of + {Domain_or_Ip, Addr_or_Port} = + case Domain of + snmpUDPDomain -> + Addr; + _ -> + {Domain, Addr} + end, + try DefMod:handle_agent( + Domain_or_Ip, Addr_or_Port, Type, SnmpInfo, DefData) + of {register, UserId2, TargetName, Config} -> ?vtrace("do_handle_agent -> register: " "~n UserId2: ~p" -- cgit v1.2.3 From fcc898b0b296376167a2a2094d0a822090cfb20e Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 29 Aug 2014 16:41:44 +0200 Subject: Update documentation --- lib/snmp/doc/src/snmp_agent_config_files.xml | 56 +++++++++++++----- lib/snmp/doc/src/snmp_agent_netif.xml | 34 +++++------ lib/snmp/doc/src/snmp_manager_config_files.xml | 63 ++++++++++++++++---- lib/snmp/doc/src/snmp_manager_netif.xml | 45 +++++++++------ lib/snmp/doc/src/snmp_target_mib.xml | 22 ++++--- lib/snmp/doc/src/snmpa_conf.xml | 66 +++++++++++++++------ lib/snmp/doc/src/snmpa_mpd.xml | 67 +++++++++++++++++----- .../doc/src/snmpa_network_interface_filter.xml | 40 ++++++++----- .../snmpa_notification_delivery_info_receiver.xml | 32 ++++++----- lib/snmp/doc/src/snmpm.xml | 14 +++-- lib/snmp/doc/src/snmpm_conf.xml | 8 +-- lib/snmp/doc/src/snmpm_mpd.xml | 14 +++-- lib/snmp/doc/src/snmpm_network_interface.xml | 12 ++-- .../doc/src/snmpm_network_interface_filter.xml | 34 ++++++----- lib/snmp/doc/src/snmpm_user.xml | 15 +++-- 15 files changed, 355 insertions(+), 167 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/snmp_agent_config_files.xml b/lib/snmp/doc/src/snmp_agent_config_files.xml index 1e8e879814..1e938c0dc8 100644 --- a/lib/snmp/doc/src/snmp_agent_config_files.xml +++ b/lib/snmp/doc/src/snmp_agent_config_files.xml @@ -4,7 +4,7 @@
- 19972013 + 19972014 Ericsson AB. All Rights Reserved. @@ -102,20 +102,41 @@

AgentVariable is one of the variables is SNMP-FRAMEWORK-MIB or one of the internal variables intAgentUDPPort, which defines which UDP port the agent - listens to, or intAgentIpAddress, which defines the IP - address of the agent.

+ listens to, or intAgentTransports, which defines the + transport domains and addresses of the agent.

Value is the value for the variable.

-

The following example shows a agent.conf file:

+

The following example shows an agent.conf file:

 {intAgentUDPPort, 4000}.
-{intAgentIpAddress,[141,213,11,24]}.
+{intAgentTransports,
+ [{transportDomainUdpIpv4, {141,213,11,24}},
+  {transportDomainUdpIpv6, {0,0,0,0,0,0,0,1}}]}.
 {snmpEngineID, "mbj's engine"}.
 {snmpEngineMaxPacketSize, 484}.
     
+

The value of intAgentTransports is a list of + {Domain, Addr} tuples, where Domain + is either transportDomainUdpIpv4 or transportDomainUdpIpv6, + and Addr is the address in the domain. + Addr can be specified either as an + IpAddr or as an {IpAddr, IpPort} tuple. + IpAddr is either a regular Erlang/OTP + ip_address() + or a traditional SNMP integer list and IpPort is an integer. +

+ +

When the Addr value does not contain a port number, + the value of intAgentUDPPort is used.

+ +

The legacy and intermediate variables intAgentIpAddress + and intAgentTransportDomain are still supported so old + agent.conf files will work. +

+

The value of snmpEngineID is a string, which for a deployed agent should have a very specific structure. See RFC 2271/2571 for details.

@@ -362,9 +383,9 @@ SNMP-TARGET-MIB and snmpTargetAddrExtTable in the SNMP-COMMUNITY-MIB.

Each entry is a term:

-

{TargetName, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId}.

or

-{TargetName, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

or

-{TargetName, Domain, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

+

{TargetName, Domain, Addr, Timeout, RetryCount, TagList, ParamsName, EngineId}. +

or

+ {TargetName, Domain, Addr, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize}.

TargetName is a unique non-empty string.

@@ -374,11 +395,14 @@ transportDomainUdpIpv4 | transportDomainUdpIpv6.

-

Ip is a list of four or eight integers.

-
- -

Udp is an integer.

+

Addr is either an IpAddr or + an {IpAddr, IpPort} tuple. IpAddr is either + a regular Erlang/OTP + ip_address() + or a traditional SNMP integer list, and IpPort is an integer.

+

If IpPort is omitted 162 is used.

+

Timeout is an integer.

@@ -395,13 +419,17 @@

EngineId is a string or the atom discovery.

-

TMask is a list of integer() of size 0, - size 6 or size 10 (default: []).

+

TMask is specified just as Addr or as []. + Note in particular that using a list of 6 bytes for IPv4 + or 8 words plus 2 bytes for IPv6 are still valid address formats + so old configurations will work.

MaxMessageSize is an integer (default: 2048).

+

The old tuple formats with Ip address and Udp + port number found in old configurations still work.

Note that if EngineId has the value discovery, the agent cannot send inform messages to that manager until it has performed the diff --git a/lib/snmp/doc/src/snmp_agent_netif.xml b/lib/snmp/doc/src/snmp_agent_netif.xml index fccfc8857a..a9ce05e757 100644 --- a/lib/snmp/doc/src/snmp_agent_netif.xml +++ b/lib/snmp/doc/src/snmp_agent_netif.xml @@ -4,7 +4,7 @@

- 19972013 + 19972014 Ericsson AB. All Rights Reserved. @@ -51,7 +51,8 @@

It is also possible to write your own Net if process. The default Net if process is implemented in the module snmpa_net_if and - it uses UDP as the transport protocol. + it uses UDP as the transport protocol i.e the transport domains + transportDomainUdpIpv4 and/or transportDomainUdpIpv6.

This section describes how to write a Net if process.

@@ -70,6 +71,12 @@

The section Messages describes mandatory messages, which Net if must send and be able to receive.

+

In this section an Address field is a + {Domain, Addr} tuple where Domain is + transportDomainUdpIpv4 or transportDomainUdpIpv4, + and Addr is an + {IpAddr, + IpPort} tuple.

@@ -96,10 +103,7 @@ MasterAgent ! {snmp_pdu, Vsn, Pdu, PduMS, ACMData, From, Extra} in use. Normally this is returned from snmpa_mpd:process_packet (see Reference Manual). - From is the source address. If UDP over IP is - used, this should be a 2-tuple {IP, UDPport}, where - IP is a 4-tuple with the IP address, and UDPport - is an integer. + From is the source Address. Extra is any term the Net if process wishes to send to the agent. This term can be retrieved by the @@ -127,10 +131,7 @@ Pid ! {snmp_response_received, Vsn, Pdu, From} Pdu is the SNMP Pdu received - From is the source address. If UDP over IP is - used, this should be a 2-tuple {IP, UDPport}, where - IP is a 4-tuple with the IP address, and UDPport - is an integer. + From is the source Address.
@@ -168,10 +169,9 @@ Pid ! {snmp_response_received, Vsn, Pdu, From} (see Reference Manual).

-

To is the destination address. If UDP over IP - is used, this should be a 2-tuple {IP, UDPport}, - where IP is a 4-tuple with the IP address, and - UDPport is an integer.

+

To is the destination Address that comes + from the From field in the corresponding snmp_pdu + message previously sent to the MasterAgent.

Extra is the term that the Net if process @@ -230,7 +230,8 @@ Pid ! {snmp_response_received, Vsn, Pdu, From} SNMPv3, it is the context information.

-

To is a list of the destination addresses and +

To is a list of {Address, SecData} + tuples i.e the destination addresses and their corresponding security parameters. This value is normally sent to snmpa_mpd:generate_message/4.

@@ -268,7 +269,8 @@ Pid ! {snmp_response_received, Vsn, Pdu, From} SNMPv3, it is the context information.

-

To is a list of the destination addresses and +

To is a list of {Address, SecData} + tuples i.e the destination addresses and their corresponding security parameters. This value is normally sent to snmpa_mpd:generate_message/4.

diff --git a/lib/snmp/doc/src/snmp_manager_config_files.xml b/lib/snmp/doc/src/snmp_manager_config_files.xml index 486ef7c170..d8bd4b0f3a 100644 --- a/lib/snmp/doc/src/snmp_manager_config_files.xml +++ b/lib/snmp/doc/src/snmp_manager_config_files.xml @@ -4,7 +4,7 @@
- 20042013 + 20042014 Ericsson AB. All Rights Reserved. @@ -64,13 +64,42 @@

Variable is one of the following:

- -

address - which defines the IP address of the - manager. Default is local host.

-
+ +

transports - which defines the transport domains + and their addresses for the manager. Mandatory +

+

Value is a list of {Domain, Addr} tuples + or Domain atoms. +

+ + +

Domain is one of transportDomainUdpIpv4 + or transportDomainUdpIpv6.

+
+ +

Addr is for the currently supported domains + either an IpAddr or an {IpAddr, IpPort} + tuple.IpAddr is either a regular Erlang/OTP + + ip_address() or a traditional SNMP integer list + and IpPort is an integer. +

+

When Addr does not contain a port number, + the value of port is used. +

+

When a Addr is not specified i.e by + using only a Domain atom, the host's name + is resolved to find the IP address, and the value of + port is used. +

+
+
+

port - which defines which UDP port the manager uses - for communicating with agents. Mandatory.

+ for communicating with agents. + Mandatory if transports does not define + a port number for every transport.

engine_id - The SnmpEngineID as defined in @@ -87,11 +116,13 @@

+

The legacy and intermediate variables address and domain + are still supported so old configurations will work.

The following example shows a manager.conf file:

-{address,          [141,213,11,24]}.
-{port,             5000}.
+{transports,       [{transportDomainUdpIpv4, {{141,213,11,24}, 5000}},
+                    {transportDomainUdpIpv6, {{0,0,0,0,0,0,0,1}, 5000}}]}.
 {engine_id,        "mgrEngine"}.
 {max_message_size, 484}.
     
@@ -146,7 +177,7 @@

Each entry is a tuple:

-

{UserId, TargetName, Comm, Ip, Port, EngineID, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}.

+

{UserId, TargetName, Comm, Domain, Addr, EngineID, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}.

UserId is the identity of the manager user @@ -160,10 +191,17 @@

Comm is the community string (string).

-

Ip is the ip address of the agent (a list of four integers).

+

Domain is the transport domain, either + transportDomainUdpIpv4 or transportDomainUdpIpv6.

-

Port is the port number of the agent (integer).

+

Addr is the address in the transport domain, + either an {IpAddr, IpPort} tuple or a traditional SNMP + integer list containing port number. IpAddr is either + a regular Erlang/OTP + ip_address() + or a traditional SNMP integer list not containing port number, + and IpPort is an integer.

EngineID is the engine-id of the agent (string).

@@ -190,6 +228,9 @@ authPriv).

+

Legacy configurations using tuples without Domain element, + as well as with all TDomain, Ip and Port elements + still work.

diff --git a/lib/snmp/doc/src/snmp_manager_netif.xml b/lib/snmp/doc/src/snmp_manager_netif.xml index 757ed32880..97cedf00c0 100644 --- a/lib/snmp/doc/src/snmp_manager_netif.xml +++ b/lib/snmp/doc/src/snmp_manager_netif.xml @@ -4,7 +4,7 @@
- 20042013 + 20042014 Ericsson AB. All Rights Reserved. @@ -50,13 +50,14 @@

The snmp application provides two different modules, snmpm_net_if (the default) and snmpm_net_if_mt, - both uses the UDP as the transport protocol. The difference - between the two modules is that the latter is "multi-threaded", - i.e. for each message/request a new process is created that - process the message/request and then exits.

+ both uses UDP as the transport protocol i.e the transport domains + transportDomainUdpIpv4 and/or transportDomainUdpIpv6. + The difference between the two modules is that the latter is + "multi-threaded", i.e. for each message/request a new process + is created that processes the message/request and then exits.

-

It is also possible to write your own Net if process, - this section describes how to write a Net if processdo that.

+

It is also possible to write your own Net if process and + this section describes how to do that.

@@ -70,11 +71,17 @@

The section Messages describes mandatory messages, which Net if must send to the manager server process.

+

In this section a Domain field is the transport domain i.e + one of transportDomainUdpIpv4 or transportDomainUdpIpv6, + and an Addr field is an + {IpAddr, + IpPort} tuple.

+

Net if must send the following message when it receives an SNMP PDU from the network that is aimed for the MasterAgent:

-Server ! {snmp_pdu, Pdu, Addr, Port}
+Server ! {snmp_pdu, Pdu, Domain, Addr}
     
@@ -82,14 +89,14 @@ Server ! {snmp_pdu, Pdu, Addr, Port} snmp_types.hrl, with the SNMP request.

-

Addr is the source address.

+

Domain is the source transport domain.

-

Port is port number of the sender.

+

Addr is the source address.

-Server ! {snmp_trap, Trap, Addr, Port}
+Server ! {snmp_trap, Trap, Domain, Addr}
     
@@ -97,14 +104,14 @@ Server ! {snmp_trap, Trap, Addr, Port} as defined in snmp_types.hrl, with the SNMP request.

-

Addr is the source address.

+

Domain is the source transport domain.

-

Port is port number of the sender.

+

Addr is the source address.

-Server ! {snmp_inform, Ref, Pdu, PduMS, Addr, Port}
+Server ! {snmp_inform, Ref, Pdu, PduMS, Domain, Addr}
     
@@ -123,14 +130,14 @@ Server ! {snmp_inform, Ref, Pdu, PduMS, Addr, Port} snmp_types.hrl, with the SNMP request.

-

Addr is the source address.

+

Domain is the source transport domain.

-

Port is port number of the sender.

+

Addr is the source address.

-Server ! {snmp_report, Data, Addr, Port}
+Server ! {snmp_report, Data, Domain, Addr}
     
@@ -152,10 +159,10 @@ Server ! {snmp_report, Data, Addr, Port}

ReasonInfo is a term().

-

Addr is the source address.

+

Domain is the source transport domain.

-

Port is port number of the sender.

+

Addr is the source address.

diff --git a/lib/snmp/doc/src/snmp_target_mib.xml b/lib/snmp/doc/src/snmp_target_mib.xml index be6fa15c73..a076ff2d8e 100644 --- a/lib/snmp/doc/src/snmp_target_mib.xml +++ b/lib/snmp/doc/src/snmp_target_mib.xml @@ -4,7 +4,7 @@
- 19982013 + 19982014 Ericsson AB. All Rights Reserved. @@ -38,18 +38,18 @@ functions for the SNMP-TARGET-MIB, and functions for configuring the database.

The configuration files are described in the SNMP User's Manual.

+

Legacy API functions add_addr/10 that does not specify + transport domain, and add_addr/11 that has got separate + IpAddr and PortNumber arguments still work as before + for backwards compatibility reasons.

DATA TYPES - +

See the + data types in snmpa_conf.

@@ -129,20 +129,18 @@ transportAddressMask() = [integer()], length 0 (default), 6 (IPv4) or 10 (IPv6) - add_addr(Name, Ip, Port, Timeout, Retry, TagList, Params, EngineId, TMask, MMS) -> Ret - add_addr(Name, Domain, Ip, Port, Timeout, Retry, TagList, Params, EngineId, TMask, MMS) -> Ret + add_addr(Name, Domain, Addr, Timeout, Retry, TagList, Params, EngineId, TMask, MMS) -> Ret Add one target address definition Name = string() Domain = transportDomain() - Ip = transportAddressIPv4() | transportAddressIPv6() (depends on the value of Domain) - Port = integer() + Addr = transportAddress() % Default port is 162 Timeout = integer() Retry = integer() TagList = string() ParamsName = string() EngineId = string() - TMask = transportAddressMask() (depends on Domain) + TMask = transportAddressMask() % Depends on Domain MMS = integer() Ret = {ok, Key} | {error, Reason} Key = term() diff --git a/lib/snmp/doc/src/snmpa_conf.xml b/lib/snmp/doc/src/snmpa_conf.xml index 99a56cd601..2780cec156 100644 --- a/lib/snmp/doc/src/snmpa_conf.xml +++ b/lib/snmp/doc/src/snmpa_conf.xml @@ -4,7 +4,7 @@
- 20062013 + 20062014 Ericsson AB. All Rights Reserved. @@ -45,20 +45,56 @@ DATA TYPES +

For inet:ip4_address(), inet:ip6_address() + and inet:port_number(), see also + + inet:ip_address()

+ + agent_entry(Tag, Val) -> agent_entry() Create an agent entry - Tag = intAgentIpAddress | intAgentUDPPort | intAgentMaxPacketSize | snmpEngineMaxMessageSize | snmpEngineID + Tag = intAgentTransports | intAgentUDPPort | intAgentMaxPacketSize | snmpEngineMaxMessageSize | snmpEngineID Val = term() agent_entry() = term() @@ -390,17 +426,15 @@ transportAddressMask() = [integer()], length 0 (default), 6 (IPv4) or 10 (IPv6) - target_addr_entry(Name, Ip, TagList, ParamsName, EngineId) -> target_addr_entry() - target_addr_entry(Name, Ip, TagList, ParamsName, EngineId, TMask) -> target_addr_entry() - target_addr_entry(Name, Ip, Udp, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> target_addr_entry() - target_addr_entry(Name, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> target_addr_entry() - target_addr_entry(Name, Domain, Ip, Udp, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> target_addr_entry() + target_addr_entry(Name, Domain, Addr, TagList, ParamsName, EngineId) -> target_addr_entry() + target_addr_entry(Name, Domain, Addr, TagList, ParamsName, EngineId, TMask) -> target_addr_entry() + target_addr_entry(Name, Domain, Addr, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> target_addr_entry() + target_addr_entry(Name, Domain, Addr, Timeout, RetryCount, TagList, ParamsName, EngineId, TMask, MaxMessageSize) -> target_addr_entry() Create an target_addr entry Name = string() Domain = transportDomain() - Ip = transportAddressIPv4() | transportAddressIPv6() (depends on Domain) - Udp = integer() + Ip = transportAddress() (depends on Domain) Timeout = integer() RetryCount = integer() TagList = string() @@ -414,12 +448,12 @@ transportAddressMask() = [integer()], length 0 (default), 6 (IPv4) or 10 (IPv6)

Create an entry for the agent target_addr config file, target_addr.conf.

Name must be a non-empty string.

-

target_addr_entry/5 translates to the following call: - target_addr_entry(Name, Ip, TagList, ParamsName, EngineId).

target_addr_entry/6 translates to the following call: - target_addr_entry(Name, Ip, 162, TagList, ParamsName, EngineId, TMask, 2048).

+ target_addr_entry(Name, Domain, Addr, TagList, ParamsName, EngineId, []).

+

target_addr_entry/7 translates to the following call: + target_addr_entry(Name, Domain, Addr, TagList, ParamsName, EngineId, TMask, 2048).

target_addr_entry/8 translates to the following call: - target_addr_entry(Name, Ip, Udp, 1500, 3, TagList, ParamsName, EngineId, TMask, MaxMessageSize).

+ target_addr_entry(Name, Domain, Addr, 1500, 3, TagList, ParamsName, EngineId, TMask, MaxMessageSize).

See Target Address Definitions for more info.

diff --git a/lib/snmp/doc/src/snmpa_mpd.xml b/lib/snmp/doc/src/snmpa_mpd.xml index c5ab0a0520..518100d30c 100644 --- a/lib/snmp/doc/src/snmpa_mpd.xml +++ b/lib/snmp/doc/src/snmpa_mpd.xml @@ -4,7 +4,7 @@
- 19992013 + 19992014 Ericsson AB. All Rights Reserved. @@ -43,6 +43,12 @@ +
+ DATA TYPES +

See the + data types in snmpa_conf.

+
+ init(Vsns) -> mpd_state() @@ -63,16 +69,17 @@ - process_packet(Packet, TDomain, TAddress, State, NoteStore, Log) -> {ok, Vsn, Pdu, PduMS, ACMData} | {discarded, Reason} | {discovery, DiscoPacket} - process_packet(Packet, TDomain, TAddress, LocalEngineID, State, NoteStore, Log) -> {ok, Vsn, Pdu, PduMS, ACMData} | {discarded, Reason} | {discovery, DiscoPacket} + process_packet(Packet, From, State, NoteStore, Log) -> {ok, Vsn, Pdu, PduMS, ACMData} | {discarded, Reason} | {discovery, DiscoPacket} + process_packet(Packet, From, LocalEngineID, State, NoteStore, Log) -> {ok, Vsn, Pdu, PduMS, ACMData} | {discarded, Reason} | {discovery, DiscoPacket} Process a packet received from the network Packet = binary() - TDomain = snmpUDPDomain - TAddress = {Ip, Udp} + From = {TDomain, TAddr} + TDomain = transportDomainUdpIpv4 | transportDomainUdpIpv6 + TAddr = {IpAddr, IpPort} LocalEngineID = string() - Ip = {integer(), integer(), integer(), integer()} - Udp = integer() + IpAddr = inet:ip_address() + IpPort = inet:port_number() State = mpd_state() NoteStore = pid() Log = snmp_log() @@ -85,7 +92,7 @@

Processes an incoming packet. Performs authentication and - decryption as necessary. The return values should be passed the + decryption as necessary. The return values should be passed to the agent.

@@ -150,14 +157,20 @@ network.

MsgData is the message specific data used in - the SNMP message. This value is received in a send_pdu - or send_pdu_req message from the agent. In SNMPv1 and + the SNMP message. This value is received in a + send_pdu + or + + send_pdu_req + message from the agent. In SNMPv1 and SNMPv2c, this message data is the community string. In - SNMPv3, it is the context information. - To is a list of the destination addresses and + SNMPv3, it is the context information.

+

+ To is a list of destination addresses and their corresponding security parameters. This value is - also received from the requests mentioned above. -

+ received in the same message from the agent and then transformed + trough process_taddrs + before passed to this function.

Note that the use of the LocalEngineID argument is only intended @@ -166,6 +179,32 @@ (see SNMP-FRAMEWORK-MIB).

+ +
+
+ + + process_taddrs(TDests) -> Dests + Transform addresses from internal MIB format to a less internal + + + TDests = [TDest] + TDest = {{TDomain, TAddr}, SecData} | {TDomain, TAddr} + TDomain = term() % Not at tuple + TAddr = term() + SecData = term() + Dests = [Dest] + Dest = {{Domain, Addr}, SecData} | {Domain, Addr} + Domain = transportDomain() + Addr = transportAddress() % Depends on Domain + + +

Transforms addresses from internal MIB format to one + more useful to Agent Net if. +

+

See also generate_msg. +

+
diff --git a/lib/snmp/doc/src/snmpa_network_interface_filter.xml b/lib/snmp/doc/src/snmpa_network_interface_filter.xml index e08a26ed92..eb640e1bc3 100644 --- a/lib/snmp/doc/src/snmpa_network_interface_filter.xml +++ b/lib/snmp/doc/src/snmpa_network_interface_filter.xml @@ -4,7 +4,7 @@
- 20072013 + 20072014 Ericsson AB. All Rights Reserved. @@ -58,10 +58,10 @@ on two levels:

-

The first level is at the UDP entry / exit point, i.e. - immediately after the receipt of the message, before any message +

The first level is at the transport entry / exit point, i.e. + immediately after the receipt of the message before any message processing is done (accept_recv) and - immediately before sending the message, after all message + immediately before sending the message after all message processing is done (accept_send).

@@ -78,6 +78,12 @@ req_limit and the function register_notification_filter.

+

Legacy network interface filter modules used arguments on the form + (IpAddr, PortNumber,...) instead of + (Domain, Addr, ...), and if the SNMP agent is run without + changing the configuration to use transport domains + the network interface filter will still get + the old arguments and work as before.

@@ -88,15 +94,17 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' | 'set-request' | trap | 'get-bulk-request' | 'inform-request' | report +

See also the + data types in snmpa_conf.

- accept_recv(Ip, Port) -> boolean() + accept_recv(Domain, Addr) -> boolean() Shall the received message be accepted - Ip = ip_address() - Port = port() + Domain = transportDomain() + Addr = transportAddressWithPort()

Called at the reception of a message (before any processing @@ -107,11 +115,11 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' | - accept_send(Ip, Port) -> boolean() + accept_send(Domain, Addr) -> boolean() Shall the message be sent - Ip = ip_address() - Port = port() + Domain = transportDomain() + Addr = transportAddressWithPort()

Called before the sending of a message (after all processing @@ -122,11 +130,11 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' | - accept_recv_pdu(Ip, Port, PduType) -> boolean() + accept_recv_pdu(Domain, Addr, PduType) -> boolean() Shall the received pdu be accepted - Ip = ip_address() - Port = port() + Domain = transportDomain() + Addr = transportAddressWithPort() PduType = pdu_type() @@ -144,7 +152,9 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' | Targets = targets() targets() = [target()] - target() = {ip_address(), port()} + target() = {Domain, Addr} + Domain = transportDomain() + Addr = transportAddressWithPort() PduType = pdu_type() > 0 Reply = boolean() | NewTargets NewTargets = targets() @@ -155,7 +165,7 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' |

For the message to be discarded all together, the function must return false.

Note that it is possible for this function to filter out targets - (but not add its own) by returning an updated + (but not to add its own) by returning an updated Targets list (NewTargets).

diff --git a/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml b/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml index aff71688b6..814f02a14c 100644 --- a/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml +++ b/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml @@ -5,7 +5,7 @@
2008 - 2013 + 2014 Ericsson AB, All Rights Reserved @@ -45,22 +45,30 @@ must export the following functions:

-

delivery_targets/3

+

delivery_targets/3

-

delivery_info/4

+

delivery_info/4

The semantics of them and their exact signatures are explained below.

+

Legacy notification delivery information receiver modules + used a target argument on the form + {IpAddr, PortNumber} instead of + {Domain, Addr}, and if the SNMP Agent is run without + changing the configuration to use transport domains + the notification delivery information receiver will still get + the old arguments and work as before.

+
DATA TYPES - +

See the + data types in snmpa_conf.

+
@@ -71,10 +79,8 @@ address() = A 4-tuple Inform about target addresses Tag = term() - Targets = [target()] - target() = {Address, Port} - Address = address() - Port = integer() + Targets = [Target] + Target = {transportDomain(), transportAddressWithPort() Extra = term() @@ -94,10 +100,8 @@ address() = A 4-tuple Inform about delivery result Tag = term() - Target = target() - target() = {Address, Port} - Address = address() - Port = integer() + Targets = [Target] + Target = {transportDomain(), transportAddressWithPort() DeliveryResult = delivery_result() delivery_result() = no_response | got_response Extra = term() diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index dc8226bb87..ff90e49968 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -4,7 +4,7 @@
- 20042013 + 20042014 Ericsson AB. All Rights Reserved. @@ -69,6 +69,9 @@ sec_name() = string() sec_level() = noAuthNoPriv | authNoPriv | authPriv ]]> +

See also the + data types in snmpa_conf.

+
@@ -300,9 +303,9 @@ sec_level = noAuthNoPriv | authNoPriv | authPriv

The type of Val depends on Item:

Note that if no tdomain is given, the default value, transportDomainUdpIpv4, is used.

-

Note that if no port is given, the default value is used.

+

Note that if no port is given and if taddress does not + contain a port number, the default value is used.

diff --git a/lib/snmp/doc/src/snmpm_conf.xml b/lib/snmp/doc/src/snmpm_conf.xml index 0cc9ff3379..8635fb705b 100644 --- a/lib/snmp/doc/src/snmpm_conf.xml +++ b/lib/snmp/doc/src/snmpm_conf.xml @@ -4,7 +4,7 @@
- 20062013 + 20062014 Ericsson AB. All Rights Reserved. @@ -195,14 +195,14 @@ - agents_entry(UserId, TargetName, Comm, Ip, Port, EngineID, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel) -> agents_entry() + agents_entry(UserId, TargetName, Comm, Domain, Addr, EngineID, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel) -> agents_entry() Create an agents entry UserId = term() TargetName = string() Comm = string() - Ip = string() - Port = integer() + Domain = transportDomain() + Addr = transportAddress() EngineID = string() Timeout = integer() MaxMessageSize = integer() diff --git a/lib/snmp/doc/src/snmpm_mpd.xml b/lib/snmp/doc/src/snmpm_mpd.xml index ad72fd7bc0..c23b2b6833 100644 --- a/lib/snmp/doc/src/snmpm_mpd.xml +++ b/lib/snmp/doc/src/snmpm_mpd.xml @@ -4,7 +4,7 @@
- 20042013 + 20042014 Ericsson AB. All Rights Reserved. @@ -39,7 +39,12 @@ It is supposed to be used from a Network Interface process (Definition of Manager Net if).

+ +

Legacy API function process_msg/7 that has got separate + IpAddr and PortNumber arguments still works as before + for backwards compatibility reasons.

+ init_mpd(Vsns) -> mpd_state() @@ -58,13 +63,12 @@ - process_msg(Msg, TDomain, Addr, Port, State, NoteStore, Logger) -> {ok, Vsn, Pdu, PduMS, MsgData} | {discarded, Reason} + process_msg(Msg, Domain, Addr, State, NoteStore, Logger) -> {ok, Vsn, Pdu, PduMS, MsgData} | {discarded, Reason} Process a message received from the network Msg = binary() - TDomain = snmpUDPDomain - Addr = {integer(), integer(), integer(), integer()} - Port = integer() + Domain = transportDomainUdpIpv4 | transportDomainUdpIpv6 + Addr = {inet:ip_address(), inet:port_number()} State = mpd_state() NoteStore = pid() Logger = function() diff --git a/lib/snmp/doc/src/snmpm_network_interface.xml b/lib/snmp/doc/src/snmpm_network_interface.xml index 6cf7bd6ed7..bea6b46dc7 100644 --- a/lib/snmp/doc/src/snmpm_network_interface.xml +++ b/lib/snmp/doc/src/snmpm_network_interface.xml @@ -4,7 +4,7 @@
- 20042013 + 20042014 Ericsson AB. All Rights Reserved. @@ -69,6 +69,10 @@

The semantics of them and their exact signatures are explained below.

+

Legacy API function send_pdu/7 that has got separate + IpAddr and PortNumber arguments still works as before + for backwards compatibility reasons.

+ @@ -103,15 +107,15 @@ - send_pdu(Pid, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo) -> void() + send_pdu(Pid, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo) -> void() Request the network interface process to send this pdu Pid = pid() Pdu = pdu() Vsn = 'version-1' | 'version-2' | 'version-3' MsgData = term() - Addr = address() - Port = integer() + Domain = transportDomainUdpIpv4 | transportDomainUdpIpv6 + Addr = {inet:ip_address(), inet:port_number()} ExtraInfo = term() diff --git a/lib/snmp/doc/src/snmpm_network_interface_filter.xml b/lib/snmp/doc/src/snmpm_network_interface_filter.xml index f0526269b3..1ef4f29c0f 100644 --- a/lib/snmp/doc/src/snmpm_network_interface_filter.xml +++ b/lib/snmp/doc/src/snmpm_network_interface_filter.xml @@ -4,7 +4,7 @@
- 20072013 + 20072014 Ericsson AB. All Rights Reserved. @@ -76,6 +76,12 @@ The default filter accepts all messages.

A network interface filter can e.g. be used during testing or for load regulation.

+

Legacy network interface filter modules used arguments on the form + (IpAddr, PortNumber,...) instead of + (Domain, Addr, ...), and if the SNMP manager is run without + changing the configuration to use transport domains + the network interface filter will still get + the old arguments and work as before.

@@ -86,16 +92,18 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' | 'set-request' | trap | 'get-bulk-request' | 'inform-request' | report | trappdu +

See also the + data types in snmpa_conf.

- accept_recv(Addr, Port) -> boolean() + accept_recv(Domain, Addr) -> boolean() Shall the received message be accepted - Addr = ip_address() - Port = port() + Domain = transportDomain() + Addr = transportAddressWithPort()

Called at the reception of a message (before any processing @@ -107,11 +115,11 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' | - accept_send(Addr, Port) -> boolean() + accept_send(Domain, Addr) -> boolean() Shall the message be sent - Addr = ip_address() - Port = port() + Domain = transportDomain() + Addr = transportAddressWithPort()

Called before the sending of a message (after all processing @@ -123,11 +131,11 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' | - accept_recv_pdu(Addr, Port, PduType) -> boolean() + accept_recv_pdu(Domain, Addr, PduType) -> boolean() Shall the received pdu be accepted - Addr = ip_address() - Port = port() + Domain = transportDomain() + Addr = transportAddressWithPort() PduType = pdu_type() @@ -141,11 +149,11 @@ pdu_type() = 'get-request' | 'get-next-request' | 'get-response' | - accept_send_pdu(Addr, Port, PduType) -> boolean() + accept_send_pdu(Domain, Addr, PduType) -> boolean() Shall the pdu be sent - Addr = ip_address() - Port = port() + Domain = transportDomain() + Addr = transportAddressWithPort() PduType = pdu_type() > 0 diff --git a/lib/snmp/doc/src/snmpm_user.xml b/lib/snmp/doc/src/snmpm_user.xml index 6f412d90f8..a4492839cd 100644 --- a/lib/snmp/doc/src/snmpm_user.xml +++ b/lib/snmp/doc/src/snmpm_user.xml @@ -4,7 +4,7 @@

- 20042013 + 20042014 Ericsson AB. All Rights Reserved. @@ -63,10 +63,15 @@

The semantics of them and their exact signatures are explained below.

Some of the function has no defined return value (void()), - they can ofcourse return anythyng. But the functions that do have + they can of course return anything. But the functions that do have specified return value(s) must adhere to this. None of the functions can use exit of throw to return.

+

If the manager is not configured to use any particular + transport domain, the behaviour handle_agent/4 + will for backwards copmpatibility reasons be called with the old + IpAddr and PortNumber arguments

+ @@ -116,11 +121,11 @@ snmp_v1_trap_info() :: {Enteprise :: snmp:oid(), - handle_agent(Addr, Port, Type, SnmpInfo, UserData) -> Reply + handle_agent(Domain, Addr, Type, SnmpInfo, UserData) -> Reply Handle agent - Addr = ip_address() - Port = integer() + Domain = transportDomainUdpIpv4 | transportDomainUdpIpv6 + Addr = {inet:ip_address(), inet:port_number()} Type = pdu | trap | report | inform SnmpInfo = SnmpPduInfo | SnmpTrapInfo | SnmpReportInfo | SnmpInformInfo SnmpPduInfo = snmp_gen_info() -- cgit v1.2.3 From 8154921f48ad207ac292e83b9dade49ad0235e97 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 9 Sep 2014 11:57:39 +0200 Subject: Update .appup --- lib/snmp/src/app/snmp.appup.src | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index ae79e3c1d1..1cc1a17b1d 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -28,6 +28,7 @@ %% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} %% {add_module, snmpm_net_if_mt} [ + {"5.0", [{restart_application, snmp}]}, {"4.25.1", [{restart_application, snmp}]}, {"4.25.0.1", [{restart_application, snmp}]}, {"4.25", [{restart_application, snmp}]}, @@ -42,6 +43,7 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"5.0", [{restart_application, snmp}]}, {"4.25.1", [{restart_application, snmp}]}, {"4.25.0.1", [{restart_application, snmp}]}, {"4.25", [{restart_application, snmp}]}, -- cgit v1.2.3 From f1ec7172f48f16e399ae07db2260195432661d07 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 9 Sep 2014 14:53:06 +0200 Subject: Fix manager backwards compat for agent addr --- lib/snmp/src/manager/snmpm_config.erl | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 940800fed4..24adb8a47f 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -442,8 +442,31 @@ agent_info(TargetName, all) -> All -> {ok, [{Item, Val} || {{_, Item}, Val} <- All]} end; +%% Begin backwards compatibility +agent_info(TargetName, address) -> + case agent_info({TargetName, taddress}) of + {ok, Val} -> + {Addr, _} = Val, + {ok, Addr}; + _ -> + %% This should be redundant since 'taddress' should exist + agent_info({TargetName, address}) + end; +agent_info(TargetName, port) -> + case agent_info({TargetName, taddress}) of + {ok, Val} -> + {_, Port} = Val, + {ok, Port}; + _ -> + %% This should be redundant since 'taddress' should exist + agent_info({TargetName, port}) + end; +%% End backwards compatibility agent_info(TargetName, Item) -> - case ets:lookup(snmpm_agent_table, {TargetName, Item}) of + agent_info({TargetName, Item}). + +agent_info(Key) -> + case ets:lookup(snmpm_agent_table, Key) of [{_, Val}] -> {ok, Val}; [] -> -- cgit v1.2.3 From c8d593b389188dc2111015b56d6c218633804bef Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 9 Sep 2014 15:12:32 +0200 Subject: Remove debug printouts --- lib/snmp/src/manager/snmpm_config.erl | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index 24adb8a47f..5cab81baf6 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -479,29 +479,29 @@ agent_info(Domain, Address, Item) when is_atom(Domain) -> do_agent_info(Domain, NAddress, Item) catch _Thrown -> - p(?MODULE_STRING":agent_info(~p, ~p, ~p) throwed ~p at.~n" - " ~p", - [Domain, Address, Item, _Thrown, erlang:get_stacktrace()]), + %% p(?MODULE_STRING":agent_info(~p, ~p, ~p) throwed ~p at.~n" + %% " ~p", + %% [Domain, Address, Item, _Thrown, erlang:get_stacktrace()]), {error, not_found} end; agent_info(Ip, Port, Item) when is_integer(Port) -> - p(?MODULE_STRING":agent_info(~p, ~p, ~p) entry~n", - [Ip, Port, Item]), + %% p(?MODULE_STRING":agent_info(~p, ~p, ~p) entry~n", + %% [Ip, Port, Item]), Domain = default_transport_domain(), try fix_address(Domain, {Ip, Port}) of Address -> do_agent_info(Domain, Address, Item) catch _Thrown -> - p(?MODULE_STRING":agent_info(~p, ~p, ~p) throwed ~p at.~n" - " ~p", - [Ip, Port, Item, _Thrown, erlang:get_stacktrace()]), + %% p(?MODULE_STRING":agent_info(~p, ~p, ~p) throwed ~p at.~n" + %% " ~p", + %% [Ip, Port, Item, _Thrown, erlang:get_stacktrace()]), {error, not_found} end. do_agent_info(Domain, Address, target_name = Item) -> - p(?MODULE_STRING":do_agent_info(~p, ~p, ~p) entry~n", - [Domain, Address, Item]), + %% p(?MODULE_STRING":do_agent_info(~p, ~p, ~p) entry~n", + %% [Domain, Address, Item]), case ets:lookup(snmpm_agent_table, {Domain, Address, Item}) of [{_, Val}] -> {ok, Val}; @@ -509,8 +509,8 @@ do_agent_info(Domain, Address, target_name = Item) -> {error, not_found} end; do_agent_info(Domain, Address, Item) -> - p(?MODULE_STRING":do_agent_info(~p, ~p, ~p) entry~n", - [Domain, Address, Item]), + %% p(?MODULE_STRING":do_agent_info(~p, ~p, ~p) entry~n", + %% [Domain, Address, Item]), case do_agent_info(Domain, Address, target_name) of {ok, TargetName} -> agent_info(TargetName, Item); @@ -3431,5 +3431,5 @@ error_msg(F, A) -> %% p(F) -> %% p(F, []). -p(F, A) -> - io:format("~w:" ++ F ++ "~n", [?MODULE | A]). +%% p(F, A) -> +%% io:format("~w:" ++ F ++ "~n", [?MODULE | A]). -- cgit v1.2.3 From 2191e216a95d3cb41edd7ad2069e3b2d88b907e7 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Mon, 15 Sep 2014 12:00:20 +0200 Subject: Update version numbers --- lib/snmp/vsn.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index fd10244386..b436a79076 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.0 +SNMP_VSN = 5.1 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 950d808c97a4c5b579f4f1cc16b95f2d419d3505 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Mon, 15 Sep 2014 12:02:14 +0200 Subject: Update release notes --- lib/snmp/doc/src/notes.xml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 15efd47a1c..bbe6438f04 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,7 +33,24 @@
-
SNMP 5.0 +
SNMP 5.1 + +
Improvements and New Features + + +

+ The SNMP manager has been enhanced with dual stack + IPv4+IPv6, as the agent just was. The documentation is + also now updated for both the agent and the manager.

+

+ Own Id: OTP-12108 Aux Id: OTP-12020

+
+
+
+ +
+ +
SNMP 5.0
Improvements and New Features -- cgit v1.2.3 From 517a51c3e4ab49302daea27592e875fb09f3091b Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 30 Sep 2014 12:10:05 +0200 Subject: Honor bind_to for manager net_if family inet Bug reported by Pavel Baturko to erlang-bugs. --- lib/snmp/src/manager/snmpm_net_if.erl | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index cb72871177..b4cc165d2e 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -319,7 +319,7 @@ socket_open(IpPort, SocketOpts) -> Socket end. -socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) -> +socket_params(Domain, {IpAddr, IpPort} = Addr, BindTo, CommonSocketOpts) -> Family = snmp_conf:tdomain_to_family(Domain), SocketOpts = case Family of @@ -340,15 +340,18 @@ socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) -> {0, [{fd, Fd} | SocketOpts]} end; error -> - {IpPort, [{ip, IpAddr} | SocketOpts]} + socket_params(SocketOpts, Addr, BindTo) end; _ -> - case BindTo of - true -> - {IpPort, [{ip, IpAddr} | SocketOpts]}; - _ -> - {IpPort, SocketOpts} - end + socket_params(SocketOpts, Addr, BindTo) + end. +%% +socket_params(SocketOpts, {IpAddr, IpPort}, BindTo) -> + case BindTo of + true -> + {IpPort, [{ip, IpAddr} | SocketOpts]}; + _ -> + {IpPort, SocketOpts} end. common_socket_opts(Opts) -> -- cgit v1.2.3 From 6d37adcd745eca986446b0a7365feb76ead60e80 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 18 Sep 2014 17:00:17 +0200 Subject: Try to increase test case timeouts --- lib/snmp/test/snmp_test_mgr.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/snmp_test_mgr.erl b/lib/snmp/test/snmp_test_mgr.erl index cf62edba1c..8cb6ec588e 100644 --- a/lib/snmp/test/snmp_test_mgr.erl +++ b/lib/snmp/test/snmp_test_mgr.erl @@ -161,7 +161,7 @@ get_timeout() -> get_timeout(os:type()) end. -get_timeout(_) -> 3500. +get_timeout(_) -> 10000. % Trying to improve test results % 3500. %%---------------------------------------------------------------------- %% Receives a trap from the agent. -- cgit v1.2.3 From d24db992b68b04a7d284cd058376d98853b92daf Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 18 Jul 2014 13:58:44 +0200 Subject: [snmp/compiler] Refinement of type Opaque was not allowed MIB constructs such as "SYNTAX Opaque (SIZE(0..65535))" was previously not allowed, this has now been fixed. See the standard ALARM-MIB for eaxmple. --- lib/snmp/doc/src/notes.xml | 63 ++++++++++++++++++++++++++++++++++++++ lib/snmp/src/app/snmp.appup.src | 6 ++++ lib/snmp/src/compile/snmpc_lib.erl | 1 + lib/snmp/vsn.mk | 2 +- 4 files changed, 71 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index bbe6438f04..fd307ef824 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,6 +33,69 @@
+
+ SNMP Development Toolkit 5.1.1 +

Version 5.1.1 supports code replacement in runtime from/to + version 5.1.

+ +
+ Improvements and new features + + + + +

[compiler] Refinement of type Opaque was not allowed.

+

MIB constructs such as 'SYNTAX Opaque (SIZE(0..65535))' + was previously not allowed, + see the standard ALARM-MIB for eaxmple.

+

Own Id: OTP-12066

+

Aux Id: Seq 12669

+
+ +
+ +
+ +
+ Fixed Bugs and Malfunctions +

-

+ + + +
+ +
+ Incompatibilities +

-

+ + +
+
+ + +
SNMP 5.1
Improvements and New Features diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 1cc1a17b1d..e7e54f5b7e 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -28,9 +28,12 @@ %% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} %% {add_module, snmpm_net_if_mt} [ + {"5.1", [ % Only compiler changes + ]}, {"5.0", [{restart_application, snmp}]}, {"4.25.1", [{restart_application, snmp}]}, {"4.25.0.1", [{restart_application, snmp}]}, + {"4.25.0.0.1", [{restart_application, snmp}]}, {"4.25", [{restart_application, snmp}]}, {"4.24.2", [{restart_application, snmp}]}, {"4.24.1", [{restart_application, snmp}]}, @@ -43,9 +46,12 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"5.1", [ % Only compiler changes + ]}, {"5.0", [{restart_application, snmp}]}, {"4.25.1", [{restart_application, snmp}]}, {"4.25.0.1", [{restart_application, snmp}]}, + {"4.25.0.0.1", [{restart_application, snmp}]}, {"4.25", [{restart_application, snmp}]}, {"4.24.2", [{restart_application, snmp}]}, {"4.24.1", [{restart_application, snmp}]}, diff --git a/lib/snmp/src/compile/snmpc_lib.erl b/lib/snmp/src/compile/snmpc_lib.erl index 5a661cf194..0f6393eeef 100644 --- a/lib/snmp/src/compile/snmpc_lib.erl +++ b/lib/snmp/src/compile/snmpc_lib.erl @@ -139,6 +139,7 @@ allow_size_rfc1902('Integer32') -> true; allow_size_rfc1902('Unsigned32') -> true; allow_size_rfc1902('OCTET STRING') -> true; allow_size_rfc1902('Gauge32') -> true; +allow_size_rfc1902('Opaque') -> true; allow_size_rfc1902(_) -> false. guess_integer_type() -> diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index b436a79076..345cc790f2 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.1 +SNMP_VSN = 5.1.1 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 2801f3dae373f1cf22f8a7113f1a53cd242ed62f Mon Sep 17 00:00:00 2001 From: Zandra Hird Date: Fri, 10 Apr 2015 12:41:56 +0200 Subject: fix snmp_conf check imask bug This change is originally from John Heizenberg. --- lib/snmp/src/misc/snmp_conf.erl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 153c8070c2..c456ed3b9b 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -1004,6 +1004,8 @@ check_imask(IMask) when is_list(IMask) -> do_check_imask(IMask), {ok, IMask}. +do_check_imask([]) -> + ok; do_check_imask([0|IMask]) -> do_check_imask(IMask); do_check_imask([1|IMask]) -> -- cgit v1.2.3 From 2b69f31280d0146670bded9889bfa9e3c0ef3134 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 23 Apr 2015 15:04:08 +0200 Subject: Use port 0 with {fd,Fd}, use snmpm_fd in manager --- lib/snmp/src/agent/snmpa_net_if.erl | 67 ++++++++++++++++++----------------- lib/snmp/src/app/snmp.appup.src | 4 ++- lib/snmp/src/manager/snmpm_net_if.erl | 4 +-- lib/snmp/src/manager/snmpm_server.erl | 8 +++-- lib/snmp/vsn.mk | 4 +-- 5 files changed, 46 insertions(+), 41 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 840d56d563..1e580072ba 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -1447,38 +1447,39 @@ get_counters([Counter|Counters], Acc) -> %% ---------------------------------------------------------------- socket_opts(Domain, {IpAddr, IpPort}, Opts) -> - [IpPort, % Picked off at socket open, separate argument - binary - | case snmp_conf:tdomain_to_family(Domain) of - inet6 = Family -> - [Family, {ipv6_v6only, true}]; - Family -> - [Family] - end ++ - case get_bind_to_ip_address(Opts) of - true -> - [{ip, IpAddr}]; - _ -> - [] - end ++ - case get_no_reuse_address(Opts) of - false -> - [{reuseaddr, true}]; - _ -> - [] - end ++ - case get_recbuf(Opts) of - use_default -> - []; - Sz -> - [{recbuf, Sz}] - end ++ - case get_sndbuf(Opts) of - use_default -> - []; - Sz -> - [{sndbuf, Sz}] - end]. + case get_bind_to_ip_address(Opts) of + true -> + [IpPort, % Picked off at socket open, separate argument + binary, + {ip, IpAddr}]; + _ -> + [0, % Picked off at socket open, separate argument + binary] + end ++ + case snmp_conf:tdomain_to_family(Domain) of + inet6 = Family -> + [Family, {ipv6_v6only, true}]; + Family -> + [Family] + end ++ + case get_no_reuse_address(Opts) of + false -> + [{reuseaddr, true}]; + _ -> + [] + end ++ + case get_recbuf(Opts) of + use_default -> + []; + Sz -> + [{recbuf, Sz}] + end ++ + case get_sndbuf(Opts) of + use_default -> + []; + Sz -> + [{sndbuf, Sz}] + end. %% ---------------------------------------------------------------- diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index e7e54f5b7e..081163b368 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2014. All Rights Reserved. +%% Copyright Ericsson AB 1999-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -28,6 +28,7 @@ %% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} %% {add_module, snmpm_net_if_mt} [ + {"5.1.1", [{restart_application, snmp}]}, {"5.1", [ % Only compiler changes ]}, {"5.0", [{restart_application, snmp}]}, @@ -46,6 +47,7 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"5.1.1", [{restart_application, snmp}]}, {"5.1", [ % Only compiler changes ]}, {"5.0", [{restart_application, snmp}]}, diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index b4cc165d2e..0e1c51c609 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -330,7 +330,7 @@ socket_params(Domain, {IpAddr, IpPort} = Addr, BindTo, CommonSocketOpts) -> end, case Family of inet -> - case init:get_argument(snmp_fd) of + case init:get_argument(snmpm_fd) of {ok, [[FdStr]]} -> Fd = list_to_integer(FdStr), case BindTo of diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index a75122d0bb..8fc3359159 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -2116,7 +2116,8 @@ do_handle_agent(DefUserId, DefMod, ok; InvalidResult -> - CallbackArgs = [Domain, Addr, Type, SnmpInfo, DefData], + CallbackArgs = + [Domain_or_Ip, Addr_or_Port, Type, SnmpInfo, DefData], handle_invalid_result(handle_agent, CallbackArgs, InvalidResult) catch @@ -2212,7 +2213,8 @@ do_handle_agent(DefUserId, DefMod, end; T:E -> - CallbackArgs = [Domain, Addr, Type, SnmpInfo, DefData], + CallbackArgs = + [Domain_or_Ip, Addr_or_Port, Type, SnmpInfo, DefData], handle_invalid_result(handle_agent, CallbackArgs, T, E) end. diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 345cc790f2..67adf0a34f 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2014. All Rights Reserved. +# Copyright Ericsson AB 1997-2015. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.1.1 +SNMP_VSN = 5.1.2 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From e5228853fd16f9817bc26a82730c697fc0ecdf34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Fri, 24 Apr 2015 12:56:39 +0200 Subject: snmp: Change to random use crypto. Remove use of erlang:now --- lib/snmp/src/agent/snmp_shadow_table.erl | 9 +- lib/snmp/src/agent/snmp_standard_mib.erl | 7 +- lib/snmp/src/agent/snmp_target_mib.erl | 16 +-- lib/snmp/src/agent/snmp_user_based_sm_mib.erl | 31 +---- lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 8 +- lib/snmp/src/agent/snmpa_mpd.erl | 21 +--- lib/snmp/src/agent/snmpa_net_if.erl | 21 +--- lib/snmp/src/agent/snmpa_usm.erl | 12 +- lib/snmp/src/agent/snmpa_vacm.erl | 9 +- lib/snmp/src/manager/snmpm_mpd.erl | 18 +-- lib/snmp/src/manager/snmpm_net_if.erl | 138 +--------------------- lib/snmp/src/manager/snmpm_server.erl | 152 ++----------------------- lib/snmp/src/misc/snmp_misc.erl | 23 +--- lib/snmp/test/snmp_agent_test.erl | 86 ++------------ lib/snmp/test/snmp_app_test.erl | 90 +-------------- lib/snmp/test/snmp_appup_mgr.erl | 8 +- lib/snmp/test/snmp_conf_test.erl | 4 +- lib/snmp/test/snmp_log_test.erl | 29 ++--- lib/snmp/test/snmp_manager_config_test.erl | 8 +- lib/snmp/test/snmp_test_lib.erl | 13 +-- lib/snmp/test/snmp_test_lib.hrl | 15 +-- lib/snmp/test/snmp_test_mgr.erl | 8 +- 22 files changed, 102 insertions(+), 624 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_shadow_table.erl b/lib/snmp/src/agent/snmp_shadow_table.erl index 34543d542b..c4704e201b 100644 --- a/lib/snmp/src/agent/snmp_shadow_table.erl +++ b/lib/snmp/src/agent/snmp_shadow_table.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% Copyright Ericsson AB 1996-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -76,7 +76,7 @@ delete_time_stamp_table() -> end. update(Name, UpdateFunc, Interval) -> - CurrentTime = get_time(), + CurrentTime = snmp_misc:now(ms), case mnesia:dirty_read({time_stamp, Name}) of [#time_stamp{data = Expire}] when CurrentTime =< Expire -> ok; _ -> @@ -117,9 +117,6 @@ table_func(Op, RowIndex, Cols, update(Name, UpdateFunc, Interval), snmp_generic:table_func(Op, RowIndex, Cols, {Name, mnesia}). -get_time() -> - {M,S,U} = erlang:now(), - 1000000000 * M + 1000 * S + (U div 1000). %%----------------------------------------------------------------- %% Urrk. @@ -183,5 +180,3 @@ delete_table(Tab) -> error_msg(F, A) -> ?snmpa_error(F, A). - - diff --git a/lib/snmp/src/agent/snmp_standard_mib.erl b/lib/snmp/src/agent/snmp_standard_mib.erl index aace3fd413..53f733ae4e 100644 --- a/lib/snmp/src/agent/snmp_standard_mib.erl +++ b/lib/snmp/src/agent/snmp_standard_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -546,8 +546,9 @@ dummy(_Op) -> ok. %%----------------------------------------------------------------- snmp_set_serial_no(new) -> snmp_generic:variable_func(new, {snmpSetSerialNo, volatile}), - {A1,A2,A3} = erlang:now(), - random:seed(A1,A2,A3), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), Val = random:uniform(2147483648) - 1, snmp_generic:variable_func(set, Val, {snmpSetSerialNo, volatile}); diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index ef9503cda8..f66c54849f 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2014. All Rights Reserved. +%% Copyright Ericsson AB 1998-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -346,13 +346,6 @@ check_target_params(X) -> error({invalid_target_params, X}). - -%% maybe_create_table(Name) -> -%% case snmpa_local_db:table_exists(db(Name)) of -%% true -> ok; -%% _ -> snmpa_local_db:table_create(db(Name)) -%% end. - init_tabs(Addrs, Params) -> ?vdebug("create target address table",[]), AddrDB = db(snmpTargetAddrTable), @@ -679,8 +672,9 @@ snmpTargetSpinLock(print) -> snmpTargetSpinLock(new) -> snmp_generic:variable_func(new, {snmpTargetSpinLock, volatile}), - {A1,A2,A3} = erlang:now(), - random:seed(A1,A2,A3), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), Val = random:uniform(2147483648) - 1, snmp_generic:variable_func(set, Val, {snmpTargetSpinLock, volatile}); @@ -1080,5 +1074,3 @@ error(Reason) -> config_err(F, A) -> snmpa_error:config_err("[TARGET-MIB]: " ++ F, A). - - diff --git a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl index 69dce337ba..ce6dc21435 100644 --- a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl +++ b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2014. All Rights Reserved. +%% Copyright Ericsson AB 1999-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -439,8 +439,9 @@ usmUserSpinLock(print) -> usmUserSpinLock(new) -> snmp_generic:variable_func(new, {usmUserSpinLock, volatile}), - {A1,A2,A3} = erlang:now(), - random:seed(A1,A2,A3), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), Val = random:uniform(2147483648) - 1, snmp_generic:variable_func(set, Val, {usmUserSpinLock, volatile}); @@ -1191,29 +1192,7 @@ extract_new_key(Hash, OldKey, KeyChange) -> -define(i8(Int), Int band 255). mk_random(Len) when Len =< 20 -> - %% Use of yield(): - %% This will either schedule another process, or fail and invoke - %% the error_handler (in old versions). In either case, it is - %% safe to assume that now, reductions and garbage_collection have - %% changed in a non-deterministically way. - {_,_,A} = erlang:now(), - catch erlang:yield(), - {_,_,B} = erlang:now(), - catch erlang:yield(), - {_,_,C} = erlang:now(), - {D,_} = erlang:statistics(reductions), - {E,_} = erlang:statistics(runtime), - {F,_} = erlang:statistics(wall_clock), - {G,H,_} = erlang:statistics(garbage_collection), - catch erlang:yield(), - {_,_,C2} = erlang:now(), - {D2,_} = erlang:statistics(reductions), - {_,H2,_} = erlang:statistics(garbage_collection), - %% X(N) means we can use N bits from variable X: - %% A(16) B(16) C(16) D(16) E(8) F(16) G(8) H(16) - Rnd20 = [?i16(A),?i16(B),?i16(C),?i16(D),?i8(E),?i16(F), - ?i8(G),?i16(H),?i16(C2),?i16(D2),?i16(H2)], - lists:sublist(Rnd20, Len). + binary_to_list(crypto:strong_rand_bytes(Len)). split(0, Rest, FirstRev) -> {lists:reverse(FirstRev), Rest}; diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl index 722bd7ac5b..28e2bdbb96 100644 --- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl +++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2014. All Rights Reserved. +%% Copyright Ericsson AB 1999-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -845,8 +845,9 @@ vacmViewSpinLock(print) -> vacmViewSpinLock(new) -> snmp_generic:variable_func(new, volatile_db(vacmViewSpinLock)), - {A1,A2,A3} = erlang:now(), - random:seed(A1,A2,A3), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), Val = random:uniform(2147483648) - 1, snmp_generic:variable_func(set, Val, volatile_db(vacmViewSpinLock)); @@ -1133,4 +1134,3 @@ error(Reason) -> config_err(F, A) -> snmpa_error:config_err("[VIEW-BASED-ACM-MIB]: " ++ F, A). - diff --git a/lib/snmp/src/agent/snmpa_mpd.erl b/lib/snmp/src/agent/snmpa_mpd.erl index 642b1f7fc5..24007a4e63 100644 --- a/lib/snmp/src/agent/snmpa_mpd.erl +++ b/lib/snmp/src/agent/snmpa_mpd.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2014. All Rights Reserved. +%% Copyright Ericsson AB 1997-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -75,8 +75,9 @@ init(Vsns) -> ?vlog("init -> entry with" "~n Vsns: ~p", [Vsns]), - {A,B,C} = erlang:now(), - random:seed(A,B,C), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), ets:insert(snmp_agent_table, {msg_id, random:uniform(2147483647)}), ets:insert(snmp_agent_table, {req_id, random:uniform(2147483647)}), init_counters(), @@ -771,21 +772,7 @@ generate_v3_report_msg(MsgID, MsgSecurityModel, Data, LocalEngineID, ContextEngineID, ContextName, SecData}, LocalEngineID, Log). -%% req_id(#scopedPdu{data = #pdu{request_id = ReqId}}) -> -%% ?vtrace("Report ReqId: ~p",[ReqId]), -%% ReqId; -%% req_id(_) -> -%% 0. % RFC2572, 7.1.3.c.4 - -%% maybe_generate_discovery1_report_msg() -> -%% case (catch DiscoveryHandler:handle_discovery1(Ip, Udp, EngineId)) of -%% {ok, Entry} when is_record(Entry, snmp_discovery_data1) -> -%% ok; -%% ignore -> -%% ok; -%% {error, Reason} -> - %% Response to stage 1 discovery message (terminating, i.e. from the manager) generate_discovery1_report_msg(MsgID, MsgSecurityModel, SecName, SecLevel, diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 840d56d563..c05a85c07a 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -674,7 +674,7 @@ handle_recv( #state{mpd_state = MpdState, note_store = NS, log = Log} = S, #transport{socket = Socket} = Transport, From, Packet) -> - put(n1, erlang:now()), + put(n1, erlang:monotonic_time(micro_seconds)), LogF = fun(Type, Data) -> log(Log, Type, Data, From) @@ -1379,15 +1379,7 @@ do_close_log(_) -> %%% DEBUG FUNCTIONS %%%----------------------------------------------------------------- time_in_agent() -> - subtr(erlang:now(), get(n1)). - -subtr({X1,Y1,Z1}, {X1,Y1,Z2}) -> - Z1 - Z2; -subtr({X1,Y1,Z1}, {X1,Y2,Z2}) -> - ((Y1-Y2) * 1000000) + (Z1 - Z2); -subtr({X1,Y1,Z1}, {X2,Y2,Z2}) -> - ((X1 - X2) * 1000000000000) + ((Y1 - Y2) * 1000000) + (Z1 - Z2). - + erlang:monotonic_time(micro_seconds) - get(n1). %% ---------------------------------------------------------------- @@ -1637,10 +1629,3 @@ get_port_info(Id) -> %% ---------------------------------------------------------------- - -% i(F) -> -% i(F, []). - -% i(F, A) -> -% io:format("~p: " ++ F ++ "~n", [?MODULE|A]). - diff --git a/lib/snmp/src/agent/snmpa_usm.erl b/lib/snmp/src/agent/snmpa_usm.erl index 719ea4e356..c571e50517 100644 --- a/lib/snmp/src/agent/snmpa_usm.erl +++ b/lib/snmp/src/agent/snmpa_usm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2013. All Rights Reserved. +%% Copyright Ericsson AB 1999-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -645,8 +645,9 @@ get_des_salt() -> ets:insert(snmp_agent_table, {usm_des_salt, 0}), 0; _ -> % it doesn't exist, initialize - {A1,A2,A3} = erlang:now(), - random:seed(A1,A2,A3), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), R = random:uniform(4294967295), ets:insert(snmp_agent_table, {usm_des_salt, R}), R @@ -677,8 +678,9 @@ get_aes_salt() -> ets:insert(snmp_agent_table, {usm_aes_salt, 0}), 0; _ -> % it doesn't exist, initialize - {A1,A2,A3} = erlang:now(), - random:seed(A1,A2,A3), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), R = random:uniform(36893488147419103231), ets:insert(snmp_agent_table, {usm_aes_salt, R}), R diff --git a/lib/snmp/src/agent/snmpa_vacm.erl b/lib/snmp/src/agent/snmpa_vacm.erl index dadcf32543..281b2bd34a 100644 --- a/lib/snmp/src/agent/snmpa_vacm.erl +++ b/lib/snmp/src/agent/snmpa_vacm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2012. All Rights Reserved. +%% Copyright Ericsson AB 1999-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -305,8 +305,8 @@ dump_table() -> %% time dumping the table. unique_table_name(Pre) -> %% We want something that is guaranteed to be unique, - %% therefor we use erlang:now() instead of os:timestamp() - unique_table_name(Pre, erlang:now()). + %% therefor we use erlang:timestamp() instead of os:timestamp() + unique_table_name(Pre, erlang:timestamp()). unique_table_name(Pre, {_A, _B, C} = Now) -> {Date, Time} = calendar:now_to_datetime(Now), @@ -445,6 +445,3 @@ gc_tab(Oid) -> user_err(F, A) -> snmpa_error:user_err(F, A). - -% config_err(F, A) -> -% snmpa_error:config_err(F, A). diff --git a/lib/snmp/src/manager/snmpm_mpd.erl b/lib/snmp/src/manager/snmpm_mpd.erl index f8a7441c0a..5fc9d3655c 100644 --- a/lib/snmp/src/manager/snmpm_mpd.erl +++ b/lib/snmp/src/manager/snmpm_mpd.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -67,8 +67,9 @@ %%%----------------------------------------------------------------- init(Vsns) -> ?vdebug("init -> entry with ~p", [Vsns]), - {A,B,C} = erlang:now(), - random:seed(A,B,C), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), snmpm_config:cre_counter(msg_id, random:uniform(2147483647)), snmpm_config:cre_counter(req_id, random:uniform(2147483647)), init_counters(), @@ -896,17 +897,6 @@ get_agent_engine_id(Name) -> is_known_engine_id(EngineID, {Addr, Port}) -> snmpm_config:is_known_engine_id(EngineID, Addr, Port). -%% is_known_engine_id(EngineID, Addr, Port) -> -%% snmpm_config:is_known_engine_id(EngineID, Addr, Port). - -% get_agent_engine_id(Addr, Port) -> -% case snmpm_config:get_agent_engine_id(Addr, Port) of -% {ok, Id} -> -% Id; -% _Error -> -% "" -% end. - %%----------------------------------------------------------------- %% Sequence number (msg-id & req-id) functions diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index b4cc165d2e..5186db64ec 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -489,11 +489,6 @@ handle_call({verbosity, Verbosity}, _From, State) -> put(verbosity, Verbosity), {reply, ok, State}; -%% handle_call({system_info_updated, What}, _From, State) -> -%% ?vlog("received system_info_updated request with What = ~p", [What]), -%% {NewState, Reply} = handle_system_info_updated(State, What), -%% {reply, Reply, NewState}; - handle_call(get_log_type, _From, State) -> ?vlog("received get-log-type request", []), Reply = (catch handle_get_log_type(State)), @@ -816,7 +811,7 @@ handle_inform_request( ok; [] -> RePdu = make_response_pdu(Pdu), - Expire = t() + To, + Expire = snmp_misc:now(ms) + To, Rec = {Key, Expire, {Vsn, ACM, RePdu}}, ets:insert(snmpm_inform_request_table, Rec) end. @@ -876,7 +871,7 @@ maybe_send_inform_response( handle_inform_response_gc(#state{irb = IRB} = State) -> ets:safe_fixtable(snmpm_inform_request_table, true), - do_irgc(ets:first(snmpm_inform_request_table), t()), + do_irgc(ets:first(snmpm_inform_request_table), snmp_misc:now(ms)), ets:safe_fixtable(snmpm_inform_request_table, false), State#state{irgc = irgc_start(IRB)}. @@ -1023,110 +1018,6 @@ handle_disk_log(_Log, _Info, State) -> State. -%% mk_discovery_msg('version-3', Pdu, _VsnHdr, UserName) -> -%% ScopedPDU = #scopedPdu{contextEngineID = "", -%% contextName = "", -%% data = Pdu}, -%% Bytes = snmp_pdus:enc_scoped_pdu(ScopedPDU), -%% MsgID = get(msg_id), -%% put(msg_id,MsgID+1), -%% UsmSecParams = -%% #usmSecurityParameters{msgAuthoritativeEngineID = "", -%% msgAuthoritativeEngineBoots = 0, -%% msgAuthoritativeEngineTime = 0, -%% msgUserName = UserName, -%% msgPrivacyParameters = "", -%% msgAuthenticationParameters = ""}, -%% SecBytes = snmp_pdus:enc_usm_security_parameters(UsmSecParams), -%% PduType = Pdu#pdu.type, -%% Hdr = #v3_hdr{msgID = MsgID, -%% msgMaxSize = 1000, -%% msgFlags = snmp_misc:mk_msg_flags(PduType, 0), -%% msgSecurityModel = ?SEC_USM, -%% msgSecurityParameters = SecBytes}, -%% Msg = #message{version = 'version-3', vsn_hdr = Hdr, data = Bytes}, -%% case (catch snmp_pdus:enc_message_only(Msg)) of -%% {'EXIT', Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% L when list(L) -> -%% {Msg, L} -%% end; -%% mk_discovery_msg(Version, Pdu, {Com, _, _, _, _}, UserName) -> -%% Msg = #message{version = Version, vsn_hdr = Com, data = Pdu}, -%% case catch snmp_pdus:enc_message(Msg) of -%% {'EXIT', Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% L when list(L) -> -%% {Msg, L} -%% end. - - -%% mk_msg('version-3', Pdu, {Context, User, EngineID, CtxEngineId, SecLevel}, -%% MsgData) -> -%% %% Code copied from snmp_mpd.erl -%% {MsgId, SecName, SecData} = -%% if -%% tuple(MsgData), Pdu#pdu.type == 'get-response' -> -%% MsgData; -%% true -> -%% Md = get(msg_id), -%% put(msg_id, Md + 1), -%% {Md, User, []} -%% end, -%% ScopedPDU = #scopedPdu{contextEngineID = CtxEngineId, -%% contextName = Context, -%% data = Pdu}, -%% ScopedPDUBytes = snmp_pdus:enc_scoped_pdu(ScopedPDU), - -%% PduType = Pdu#pdu.type, -%% V3Hdr = #v3_hdr{msgID = MsgId, -%% msgMaxSize = 1000, -%% msgFlags = snmp_misc:mk_msg_flags(PduType, SecLevel), -%% msgSecurityModel = ?SEC_USM}, -%% Message = #message{version = 'version-3', vsn_hdr = V3Hdr, -%% data = ScopedPDUBytes}, -%% SecEngineID = case PduType of -%% 'get-response' -> snmp_framework_mib:get_engine_id(); -%% _ -> EngineID -%% end, -%% case catch snmp_usm:generate_outgoing_msg(Message, SecEngineID, -%% SecName, SecData, SecLevel) of -%% {'EXIT', Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% {error, Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% Packet -> -%% Packet -%% end; -%% mk_msg(Version, Pdu, {Com, _User, _EngineID, _Ctx, _SecLevel}, _SecData) -> -%% Msg = #message{version = Version, vsn_hdr = Com, data = Pdu}, -%% case catch snmp_pdus:enc_message(Msg) of -%% {'EXIT', Reason} -> -%% error("Encoding error. Pdu: ~w. Reason: ~w",[Pdu, Reason]), -%% error; -%% B when list(B) -> -%% B -%% end. - - -%% handle_system_info_updated(#state{log = {Log, _OldType}} = State, -%% audit_trail_log_type = _What) -> -%% %% Just to make sure, check that ATL is actually enabled -%% case snmpm_config:system_info(audit_trail_log) of -%% {ok, true} -> -%% {ok, Type} = snmpm_config:system_info(audit_trail_log_type), -%% NewState = State#state{log = {Log, Type}}, -%% {NewState, ok}; -%% _ -> -%% {State, {error, {adt_not_enabled}}} -%% end; -%% handle_system_info_updated(_State, _What) -> -%% ok. - handle_get_log_type(#state{log = {_Log, Value}} = State) -> %% Just to make sure, check that ATL is actually enabled case snmpm_config:system_info(audit_trail_log) of @@ -1255,13 +1146,6 @@ maybe_process_extra_info(_ExtraInfo) -> ok. -%% ------------------------------------------------------------------- - -t() -> - {A,B,C} = erlang:now(), - A*1000000000+B*1000+(C div 1000). - - %% ------------------------------------------------------------------- %% info_msg(F, A) -> @@ -1301,8 +1185,6 @@ proc_mem(P) when is_pid(P) -> _ -> undefined end. -%% proc_mem(_) -> -%% undefined. get_port_info(Id) -> @@ -1382,20 +1264,6 @@ counters() -> inc(Name) -> inc(Name, 1). inc(Name, N) -> snmpm_config:incr_stats_counter(Name, N). -%% get_counters() -> -%% Counters = counters(), -%% get_counters(Counters, []). - -%% get_counters([], Acc) -> -%% lists:reverse(Acc); -%% get_counters([Counter|Counters], Acc) -> -%% case snmpm_config:get_stats_counter(Counter) of -%% {ok, CounterVal} -> -%% get_counters(Counters, [{Counter, CounterVal}|Acc]); -%% _ -> -%% get_counters(Counters, Acc) -%% end. - %% ---------------------------------------------------------------- diff --git a/lib/snmp/src/manager/snmpm_server.erl b/lib/snmp/src/manager/snmpm_server.erl index a75122d0bb..3a37174d9e 100644 --- a/lib/snmp/src/manager/snmpm_server.erl +++ b/lib/snmp/src/manager/snmpm_server.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -467,27 +467,6 @@ cancel_async_request(UserId, ReqId) -> call({cancel_async_request, UserId, ReqId}). -%% discovery(UserId, BAddr) -> -%% discovery(UserId, BAddr, ?SNMP_AGENT_PORT, [], -%% ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO). - -%% discovery(UserId, BAddr, Config) when is_list(Config) -> -%% discovery(UserId, BAddr, ?SNMP_AGENT_PORT, Config, -%% ?DEFAULT_ASYNC_EXPIRE, ?EXTRA_INFO); - -%% discovery(UserId, BAddr, Expire) when is_integer(Expire) -> -%% discovery(UserId, BAddr, ?SNMP_AGENT_PORT, [], Expire, ?EXTRA_INFO). - -%% discovery(UserId, BAddr, Config, Expire) -> -%% discovery(UserId, BAddr, ?SNMP_AGENT_PORT, Config, Expire, ?EXTRA_INFO). - -%% discovery(UserId, BAddr, Port, Config, Expire) -> -%% discovery(UserId, BAddr, Port, Config, Expire, ?EXTRA_INFO). - -%% discovery(UserId, BAddr, Port, Config, Expire, ExtraInfo) -> -%% call({discovery, self(), UserId, BAddr, Port, Config, Expire, ExtraInfo}). - - verbosity(Verbosity) -> case ?vvalidate(Verbosity) of Verbosity -> @@ -927,14 +906,6 @@ handle_call({cancel_async_request, UserId, ReqId}, _From, State) -> {reply, Reply, State}; -%% handle_call({discovery, Pid, UserId, BAddr, Port, Config, Expire, ExtraInfo}, -%% _From, State) -> -%% ?vlog("received discovery request", []), -%% Reply = (catch handle_discovery(Pid, UserId, BAddr, Port, Config, -%% Expire, ExtraInfo, State)), -%% {reply, Reply, State}; - - handle_call({load_mib, Mib}, _From, State) -> ?vlog("received load_mib request", []), case snmpm_config:load_mib(Mib) of @@ -988,13 +959,6 @@ handle_call(is_started, _From, State) -> IsStarted = is_started(State), {reply, IsStarted, State}; -%% handle_call({system_info_updated, Target, What}, _From, State) -> -%% ?vlog("received system_info_updated request: " -%% "~n Target: ~p" -%% "~n What: ~p", [Target, What]), -%% Reply = handle_system_info_updated(State, Target, What), -%% {reply, Reply, State}; - handle_call(get_log_type, _From, State) -> ?vlog("received get_log_type request", []), Reply = handle_get_log_type(State), @@ -1042,11 +1006,6 @@ handle_info({snmp_error, ReqId, Reason, Domain, Addr}, State) -> handle_snmp_error(Domain, Addr, ReqId, Reason, State), {noreply, State}; -%% handle_info({snmp_error, ReqId, Pdu, Reason, Addr, Port}, State) -> -%% ?vlog("received snmp_error message", []), -%% handle_snmp_error(Pdu, ReqId, Reason, Addr, Port, State), -%% {noreply, State}; - handle_info({snmp_pdu, Pdu, Domain, Addr}, State) -> ?vlog("received snmp_pdu message", []), @@ -1411,7 +1370,7 @@ handle_async_get(Pid, UserId, TargetName, Oids, SendOpts, State) -> address = Addr, type = get, data = MsgData, - expire = t() + Expire}, + expire = snmp_misc:now(ms) + Expire}, ets:insert(snmpm_request_table, Req), gct_activate(State#state.gct), @@ -1460,7 +1419,7 @@ handle_async_get_next(Pid, UserId, TargetName, Oids, SendOpts, State) -> address = Addr, type = get_next, data = MsgData, - expire = t() + Expire}, + expire = snmp_misc:now(ms) + Expire}, ets:insert(snmpm_request_table, Req), gct_activate(State#state.gct), @@ -1516,7 +1475,7 @@ handle_async_get_bulk(Pid, address = Addr, type = get_bulk, data = MsgData, - expire = t() + Expire}, + expire = snmp_misc:now(ms) + Expire}, ets:insert(snmpm_request_table, Req), gct_activate(State#state.gct), {ok, ReqId}; @@ -1564,7 +1523,7 @@ handle_async_set(Pid, UserId, TargetName, VarsAndVals, SendOpts, State) -> address = Addr, type = set, data = MsgData, - expire = t() + Expire}, + expire = snmp_misc:now(ms) + Expire}, ets:insert(snmpm_request_table, Req), gct_activate(State#state.gct), @@ -1600,18 +1559,6 @@ handle_cancel_async_request(UserId, ReqId, _State) -> ?vlog("handle_cancel_async_request -> not found", []), {error, not_found} end. - - -%% handle_system_info_updated(#state{net_if = Pid, net_if_mod = Mod} = _State, -%% net_if = _Target, What) -> -%% case (catch Mod:system_info_updated(Pid, What)) of -%% {'EXIT', _} -> -%% {error, not_supported}; -%% Else -> -%% Else -%% end; -%% handle_system_info_updated(_State, Target, What) -> -%% {error, {bad_target, Target, What}}. handle_get_log_type(#state{net_if = Pid, net_if_mod = Mod}) -> case (catch Mod:get_log_type(Pid)) of @@ -1629,47 +1576,6 @@ handle_set_log_type(#state{net_if = Pid, net_if_mod = Mod}, NewType) -> Else end. - -%% handle_discovery(Pid, UserId, BAddr, Port, Config, Expire, ExtraInfo, State) -> -%% ?vtrace("handle_discovery -> entry with" -%% "~n Pid: ~p" -%% "~n UserId: ~p" -%% "~n BAddr: ~p" -%% "~n Port: ~p" -%% "~n Config: ~p" -%% "~n Expire: ~p", -%% [Pid, UserId, BAddr, Port, Config, Expire]), -%% case agent_data(default, default, "", Config) of -%% {ok, Addr, Port, Vsn, MsgData} -> -%% ?vtrace("handle_discovery -> send a ~p disco message", [Vsn]), -%% ReqId = send_discovery(Vsn, MsgData, BAddr, Port, ExtraInfo, -%% State), -%% ?vdebug("handle_discovery -> ReqId: ~p", [ReqId]), -%% MonRef = erlang:monitor(process, Pid), -%% ?vtrace("handle_discovery -> MonRef: ~p", [MonRef]), -%% Req = #request{id = ReqId, -%% user_id = UserId, -%% target = TargetName, -%% addr = BAddr, -%% port = Port, -%% type = get, -%% data = MsgData, -%% mon = MonRef, -%% discovery = true, -%% expire = t() + Expire}, -%% ets:insert(snmpm_request_table, Req), -%% gct_activate(State#state.gct), -%% {ok, ReqId}; - -%% Error -> -%% ?vinfo("failed retrieving agent data for discovery (get):" -%% "~n BAddr: ~p" -%% "~n Port: ~p" -%% "~n Error: ~p", [BAddr, Port, Error]), -%% Error -%% end. - - handle_sync_timeout(ReqId, From, State) -> ?vtrace("handle_sync_timeout -> entry with" "~n ReqId: ~p" @@ -1693,7 +1599,7 @@ handle_sync_timeout(ReqId, From, State) -> Req = Req0#request{ref = undefined, mon = undefined, from = undefined, - expire = t()}, + expire = snmp_misc:now(ms)}, ets:insert(snmpm_request_table, Req), gct_activate(State#state.gct), ok; @@ -3024,7 +2930,7 @@ cancel_timer(Ref) -> handle_gc(GCT) -> ets:safe_fixtable(snmpm_request_table, true), - case do_gc(ets:first(snmpm_request_table), t()) of + case do_gc(ets:first(snmpm_request_table), snmp_misc:now(ms)) of 0 -> gct_deactivate(GCT); _ -> @@ -3098,23 +3004,11 @@ send_set_request(VarsAndVals, Vsn, MsgData, Domain, Addr, ExtraInfo, Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Domain, Addr, ExtraInfo), Pdu#pdu.request_id. -%% send_discovery(Vsn, MsgData, Addr, Port, ExtraInfo, -%% #state{net_if = NetIf, -%% net_if_mod = Mod}) -> -%% Pdu = make_discovery_pdu(), -%% Mod:send_pdu(NetIf, Pdu, Vsn, MsgData, Addr, Port, ExtraInfo), -%% Pdu#pdu.request_id. - - %%---------------------------------------------------------------------- %% %%---------------------------------------------------------------------- -%% make_discovery_pdu() -> -%% Oids = [?sysObjectID_instance, ?sysDescr_instance, ?sysUpTime_instance], -%% make_pdu_impl(get, Oids). - make_pdu(set, VarsAndVals, MiniMIB) -> VBs = [var_and_value_to_varbind(VAV, MiniMIB) || VAV <- VarsAndVals], make_pdu_impl(set, VBs); @@ -3397,7 +3291,7 @@ gct_init(#gct{parent = Parent, timeout = Timeout} = State) -> gct(State, Timeout). gct(#gct{parent = Parent, state = active} = State, Timeout) -> - T = t(), + T = snmp_misc:now(ms), receive {stop, Parent} -> ok; @@ -3455,7 +3349,7 @@ gct(#gct{parent = Parent, state = idle} = State, Timeout) -> end. new_timeout(T1, T2) -> - case T1 - (t() - T2) of + case T1 - (snmp_misc:now(ms) - T2) of T when (T > 0) -> T; _ -> @@ -3475,11 +3369,6 @@ maybe_demonitor(undefined) -> maybe_demonitor(MonRef) -> erlang:demonitor(MonRef). -%% Time in milli seconds -t() -> - {A,B,C} = erlang:now(), - A*1000000000+B*1000+(C div 1000). - mk_target_name(Domain, Addr, Config) -> snmpm_config:mk_target_name(Domain, Addr, Config). @@ -3518,12 +3407,6 @@ call(Req) -> call(Req, To) -> gen_server:call(?SERVER, Req, To). -%% cast(Msg) -> -%% gen_server:cast(?SERVER, Msg). - -%% info_msg(F, A) -> -%% ?snmpm_info("Server: " ++ F, A). - warning_msg(F, A) -> ?snmpm_warning("Server: " ++ F, A). @@ -3599,20 +3482,3 @@ note_store_info(Pid) -> %%---------------------------------------------------------------------- - - -%%---------------------------------------------------------------------- -%% Debug -%%---------------------------------------------------------------------- - -% sz(L) when is_list(L) -> -% length(lists:flatten(L)); -% sz(B) when is_binary(B) -> -% size(B). - -%% p(F) -> -%% p(F, []). - -%% p(F, A) -> -%% io:format("~w:" ++ F ++ "~n", [?MODULE | A]). - diff --git a/lib/snmp/src/misc/snmp_misc.erl b/lib/snmp/src/misc/snmp_misc.erl index c36cee2a53..cc438977c9 100644 --- a/lib/snmp/src/misc/snmp_misc.erl +++ b/lib/snmp/src/misc/snmp_misc.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -101,21 +101,14 @@ sleep(Time) -> %% Returns time in ms = sec/1000 % now() -> now(ms). now(ms) -> - Now = erlang:now(), - element(1,Now)*1000000000+ - element(2,Now)*1000+ - (element(3,Now) div 1000); + erlang:monotonic_time(milli_seconds); + %% Returns time in cs = sec/100 now(cs) -> - Now = erlang:now(), - element(1,Now)*100000000+ - element(2,Now)*100+ - (element(3,Now) div 10000); + erlang:monotonic_time(100); + now(sec) -> - Now = erlang:now(), - element(1,Now)*1000000+ - element(2,Now)+ - (element(3,Now) div 1000000). + erlang:monotonic_time(seconds). is_crypto_supported(Alg) -> @@ -479,7 +472,3 @@ format_val('OBJECT IDENTIFIER', _, Val, MiniMib) -> io_lib:format("~w", [NVal]); format_val(_, _, Val, _MiniMib) -> io_lib:format("~p", [Val]). - - - - diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index b4770ad0a9..a28cdf6aca 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2014. All Rights Reserved. +%% Copyright Ericsson AB 2003-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -426,10 +426,6 @@ -include_lib("snmp/include/snmp_types.hrl"). -include_lib("snmp/src/agent/snmpa_atl.hrl"). -%% -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-VIEW-BASED-ACM-MIB.hrl"). -%% -include_lib("snmp/include/SNMP-USER-BASED-SM-MIB.hrl"). - -define(klas1, [1,3,6,1,2,1,7]). -define(klas2, [1,3,6,1,2,1,9]). @@ -1612,7 +1608,8 @@ app_dir(App) -> create_local_db_dir(Config) when is_list(Config) -> ?P(create_local_db_dir), DataDir = snmp_test_lib:lookup(data_dir, Config), - T = erlang:now(), + UName = erlang:unique_integer([positive]), + T = {UName, UName, UName}, [As,Bs,Cs] = [integer_to_list(I) || I <- tuple_to_list(T)], DbDir = filename:join([DataDir, As, Bs, Cs]), ok = del_dir(DbDir, 3), @@ -2448,10 +2445,6 @@ mul_cases() -> ]. -%% multiple_reqs_3(_X) -> -%% {req, [], {conf, init_mul, mul_cases_3(), finish_mul}}. - - mul_cases_2() -> [ mul_get_2, @@ -3200,19 +3193,18 @@ v1_get_next_p() -> %% 4.1.3:2 gn([[tTooBig]]), io:format("We currently don't handle tooBig correct!!!\n"), -% ?line ?expect3(tooBig, 0, [{[tTooBig], 'NULL'}]), + ?line ?expect3(tooBig, 0, any), %% 4.1.3:3 gn([[tGenErr1]]), -% ?line expect(40, genErr, 1, [{[tGenErr1], 'NULL'}]), + ?line ?expect3(genErr, 1, any), gn([[tGenErr2]]), -% ?line ?expect3(genErr, 1, [{[tGenErr2], 'NULL'}]), + ?line ?expect3(genErr, 1, any), gn([[sysDescr], [tGenErr3]]), -% ?line ?expect3(genErr, 2, [{[sysDescr], 'NULL'}, -% {[tGenErr3], 'NULL'}]). + ?line ?expect3(genErr, 2, any). v1_set_p() -> @@ -3451,8 +3443,7 @@ v2_set_p() -> %% Req. OLD-SNMPEA-MIB table_test() -> io:format("Testing simple get, next and set on communityTable...~n"), -%% {[147,214,36,45], "public", 2, readWrite}. -%% {[147,214,36,45], "standard trap", 2, read}. + Key1c3 = [intCommunityViewIndex,get(mip),is("public")], Key2c3 = [intCommunityViewIndex,get(mip),is("standard trap")], Key1c4 = [intCommunityAccess,get(mip),is("public")], @@ -3620,8 +3611,6 @@ notify(Pid, What) -> %% Req: system group, OLD-SNMPEA-MIB, Klas1 big_test() -> - %% put(sname, {?MODULE, big_test}), - %% put(verbosity, trace), ?DBG("big_test -> testing simple next/get/set @ master agent...",[]), simple_standard_test(), @@ -5691,8 +5680,7 @@ loop_mib_1(suite) -> []; loop_mib_1(Config) when is_list(Config) -> ?P(loop_mib_1), ?LOG("loop_mib_1 -> initiate case",[]), - %% snmpa:verbosity(master_agent,debug), - %% snmpa:verbosity(mib_server,info), + {_SaNode, _MgrNode, _MibDir} = init_case(Config), ?DBG("loop_mib_1 -> ~n" "\tSaNode: ~p~n" @@ -6643,7 +6631,6 @@ otp8395({init, Config}) when is_list(Config) -> %% {ok, AgentNode} = start_node(agent), - %% {ok, SubAgentNode} = start_node(sub_agent), {ok, ManagerNode} = start_node(manager), %% -- @@ -6654,16 +6641,9 @@ otp8395({init, Config}) when is_list(Config) -> AgentMnesiaDir = join([AgentDbDir, "mnesia"]), mnesia_init(AgentNode, AgentMnesiaDir), - %% SubAgentDir = ?config(sub_agent_dir, Config), - %% SubAgentMnesiaDir = join([SubAgentDir, "mnesia"]), - %% mnesia_init(SubAgentNode, SubAgentMnesiaDir), - - %% ok = mnesia_create_schema(AgentNode, [AgentNode, SubAgentNode]), - %% ok = mnesia:create_schema([AgentNode, SubAgentNode]), mnesia_create_schema(AgentNode, [AgentNode]), mnesia_start(AgentNode), - %% mnesia_start(SubAgentNode), %% -- %% Host & IP @@ -6749,11 +6729,6 @@ otp8395({fin, Config}) when is_list(Config) -> ?DBG("otp8395(fin) -> stop agent node", []), stop_node(AgentNode), - - %% SubAgentNode = ?config(sub_agent_node, Config), - %% stop_node(SubAgentNode), - - %% - %% Stop the manager node %% @@ -6970,20 +6945,6 @@ process_options(Defaults, _Opts) -> %% process_options(Defaults, Opts, []). Defaults. -%% process_options([], _Opts, Acc) -> -%% lists:reverse(Acc); -%% process_options([{Key, DefaultValue}|Defaults], Opts, Acc) -> -%% case lists:keysearch(Key, 1, Opts) of -%% {value, {Key, Value}} when is_list-> - - -%% snmp_app_env_init(Node, Entity, Conf) -> -%% rpc:call(Node, snmp_app_env_init, [Entity, Conf]). - -%% snmp_app_env_init(Entity, Conf) -> -%% application:unload(snmp), -%% application:load(snmp), -%% application:set_env(snmp, Entity, Conf). start_stdalone_agent(Node, Config) -> rpc:call(Node, ?MODULE, start_stdalone_agent, [Config]). @@ -7063,9 +7024,6 @@ do_info(MaNode) -> tree_size_bytes, db_memory]}], verify_info(Info, Keys), - %% OldInfo = snmpa:old_info_format(Info), - %% ?DBG("info_test1 -> OldInfo: ~n~p", [OldInfo]), - %% verify_old_info(OldInfo), ok. verify_info([], []) -> @@ -7107,21 +7065,6 @@ verify_subinfo(Info0, [Key|Keys]) -> Info -> verify_subinfo(Info, Keys) end. - -%% verify_old_info(Info) -> -%% Keys = [vsns, subagents, loaded_mibs, -%% tree_size_bytes, process_memory, db_memory], -%% verify_old_info(Keys, Info). - -%% verify_old_info([], _) -> -%% ok; -%% verify_old_info([Key|Keys], Info) -> -%% case lists:keymember(Key, 1, Info) of -%% true -> -%% verify_old_info(Keys, Info); -%% false -> -%% ?FAIL({missing_old_info, Key}) -%% end. %% Index String - string used in index is(S) -> [length(S) | S]. @@ -7184,8 +7127,6 @@ rewrite_usm_mgr(Dir, ShaKey, DesKey) -> reset_usm_mgr(Dir) -> snmp_agent_test_lib:reset_usm_mgr(Dir). -%% update_community(Vsns, Dir) -> -%% snmp_agent_test_lib:update_community(Vsns, Dir). update_vacm(Vsn, Dir) -> snmp_agent_test_lib:update_vacm(Vsn, Dir). @@ -7196,8 +7137,6 @@ write_community_conf(Dir, Conf) -> write_target_addr_conf(Dir, Conf) -> snmp_agent_test_lib:write_target_addr_conf(Dir, Conf). -%% write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> -%% snmp_agent_test_lib:write_target_addr_conf(Dir, ManagerIp, UDP, Vsns). rewrite_target_addr_conf(Dir, NewPort) -> snmp_agent_test_lib:rewrite_target_addr_conf(Dir, NewPort). @@ -7218,10 +7157,6 @@ reset_target_params_conf(Dir) -> write_notify_conf(Dir) -> snmp_agent_test_lib:write_notify_conf(Dir). -%% write_view_conf(Dir) -> -%% snmp_agent_test_lib:write_view_conf(Dir). - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% copy_file(From, To) -> @@ -7381,9 +7316,6 @@ lists_key1search(Key, List) when is_atom(Key) -> end. -%% regs() -> -%% lists:sort(registered()). - %% ------ join(Parts) -> diff --git a/lib/snmp/test/snmp_app_test.erl b/lib/snmp/test/snmp_app_test.erl index 9b13e7cf1a..1e68b4e2c8 100644 --- a/lib/snmp/test/snmp_app_test.erl +++ b/lib/snmp/test/snmp_app_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2012. All Rights Reserved. +%% Copyright Ericsson AB 2003-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -32,8 +32,6 @@ modules/1, exportall/1, app_depend/1, - undef_funcs/1, - start_and_stop_empty/1, start_and_stop_with_agent/1, @@ -59,7 +57,6 @@ all() -> modules, exportall, app_depend, - undef_funcs, {group, start_and_stop} ], Cases. @@ -131,9 +128,6 @@ end_per_suite(Config) when is_list(Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Test server callbacks -init_per_testcase(undef_funcs, Config) -> - Config2 = lists:keydelete(watchdog, 1, Config), - [{watchdog, ?WD_START(?MINS(10))} | Config2]; init_per_testcase(_Case, Config) -> Config. @@ -293,88 +287,6 @@ check_apps([App|Apps]) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -undef_funcs(suite) -> - []; -undef_funcs(doc) -> - []; -undef_funcs(Config) when is_list(Config) -> - App = snmp, - AppFile = key1search(app_file, Config), - Mods = key1search(modules, AppFile), - Root = code:root_dir(), - LibDir = code:lib_dir(App), - EbinDir = filename:join([LibDir,"ebin"]), - XRefTestName = undef_funcs_make_name(App, xref_test_name), - {ok, XRef} = xref:start(XRefTestName), - ok = xref:set_default(XRef, - [{verbose,false},{warnings,false}]), - XRefName = undef_funcs_make_name(App, xref_name), - {ok, XRefName} = xref:add_release(XRef, Root, {name,XRefName}), - {ok, App} = xref:replace_application(XRef, App, EbinDir), - {ok, Undefs} = xref:analyze(XRef, undefined_function_calls), - xref:stop(XRef), - analyze_undefined_function_calls(Undefs, Mods, []). - -valid_undef(crypto = CalledMod) -> - case (catch CalledMod:version()) of - Version when is_list(Version) -> - %% The called module was crypto and the version - %% function returns a valid value. - %% This means that the function is - %% actually undefined... - true; - _ -> - %% The called module was crypto but the version - %% function does *not* return a valid value. - %% This means the crypto was not actually not - %% build, which is an case snmp handles. - false - end; -valid_undef(_) -> - true. - - -analyze_undefined_function_calls([], _, []) -> - ok; -analyze_undefined_function_calls([], _, AppUndefs) -> - exit({suite_failed, {undefined_function_calls, AppUndefs}}); -analyze_undefined_function_calls([{{Mod, _F, _A}, _C} = AppUndef|Undefs], - AppModules, AppUndefs) -> - %% Check that this module is our's - case lists:member(Mod,AppModules) of - true -> - {Calling,Called} = AppUndef, - {Mod1,Func1,Ar1} = Calling, - {Mod2,Func2,Ar2} = Called, - %% If the called module is crypto, then we will *not* - %% fail if crypto is not built (since crypto is actually - %% not built for all platforms) - case valid_undef(Mod2) of - true -> - io:format("undefined function call: " - "~n ~w:~w/~w calls ~w:~w/~w~n", - [Mod1,Func1,Ar1,Mod2,Func2,Ar2]), - analyze_undefined_function_calls( - Undefs, AppModules, [AppUndef|AppUndefs]); - false -> - io:format("skipping ~p (calling ~w:~w/~w)~n", - [Mod, Mod2, Func2, Ar2]), - analyze_undefined_function_calls(Undefs, - AppModules, AppUndefs) - end; - false -> - io:format("dropping ~p~n", [Mod]), - analyze_undefined_function_calls(Undefs, AppModules, AppUndefs) - end. - -%% This function is used simply to avoid cut-and-paste errors later... -undef_funcs_make_name(App, PostFix) -> - list_to_atom(atom_to_list(App) ++ "_" ++ atom_to_list(PostFix)). - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/lib/snmp/test/snmp_appup_mgr.erl b/lib/snmp/test/snmp_appup_mgr.erl index 6648ce9dbe..b07f8b3c72 100644 --- a/lib/snmp/test/snmp_appup_mgr.erl +++ b/lib/snmp/test/snmp_appup_mgr.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2010. All Rights Reserved. +%% Copyright Ericsson AB 2003-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -140,7 +140,7 @@ handle_req(#agent{host = Host, port = Port}, Reqs) -> {ok, ReqId} = snmpm:ag(?USER_ID, Host, Port, Oids), p("issued get-request (~w) for: ~s", [ReqId, oid_descs(Descs)]), ReqTimer = erlang:send_after(?REQ_TIMEOUT, self(), {req_timeout, ReqId}), - {ReqId, erlang:now(), ReqTimer}. + {ReqId, erlang:monotonic_time(micro_seconds), ReqTimer}. oid_descs([]) -> []; @@ -163,7 +163,7 @@ handle_req_timeout(#state{ids = IDs0} = State, ReqId) -> handle_snmp(#state{ids = IDs0} = S, {error, ReqId, Reason}) -> case lists:keysearch(ReqId, 1, IDs0) of {value, {ReqId, T, Ref}} -> - Diff = timer:now_diff(erlang:now(), T), + Diff = erlang:monotonic_time(micro_seconds) - T, p("SNMP error regarding outstanding request after ~w microsec:" "~n ReqId: ~w" "~n Reason: ~w", [Diff, ReqId, Reason]), @@ -187,7 +187,7 @@ handle_snmp(State, {agent, Addr, Port, SnmpInfo}) -> handle_snmp(#state{ids = IDs0} = S, {pdu, Addr, Port, ReqId, SnmpResponse}) -> case lists:keysearch(ReqId, 1, IDs0) of {value, {ReqId, T, Ref}} -> - Diff = timer:now_diff(erlang:now(), T), + Diff = erlang:monotonic_time(micro_seconds) - T, p("SNMP pdu regarding outstanding request after ~w microsec:" "~n ReqId: ~w" "~n Addr: ~w" diff --git a/lib/snmp/test/snmp_conf_test.erl b/lib/snmp/test/snmp_conf_test.erl index 7f5d11c0e7..dacedf0847 100644 --- a/lib/snmp/test/snmp_conf_test.erl +++ b/lib/snmp/test/snmp_conf_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2014. All Rights Reserved. +%% Copyright Ericsson AB 2003-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -117,7 +117,7 @@ check_mandatory(Config) when is_list(Config) -> {b, mandatory}, {d, {value, 20202}}, {e, {value, "kalle"}}], - ?line {ok, L1} = verify_mandatory(A1, B1), + ?line {ok, _L1} = verify_mandatory(A1, B1), ?DBG("check_mandatory -> L1: ~p", [L1]), A2 = [{a, hej}, {c, 10}, {d, 10101}, {f, 10.88}], B2 = [{a, {value, hejsan}}, diff --git a/lib/snmp/test/snmp_log_test.erl b/lib/snmp/test/snmp_log_test.erl index fb7285110f..ed71dba23f 100644 --- a/lib/snmp/test/snmp_log_test.erl +++ b/lib/snmp/test/snmp_log_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2013. All Rights Reserved. +%% Copyright Ericsson AB 2003-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -633,11 +633,11 @@ log_to_txt3(Config) when is_list(Config) -> log_reader_log_to(Reader, fun() -> I = disk_log:info(Log), - T1 = t(), + T1 = snmp_misc:now(ms), R = snmp_log:log_to_txt(Log, LogFile, Dir, Mibs, TxtFile), - T2 = t(), - io:format(user, + T2 = snmp_misc:now(ms), + io:format(user, "Time converting file: ~w ms~n", [T2 - T1]), {R, I} @@ -704,10 +704,10 @@ log_writer_start(Name, File, Size, Repair) -> log_writer_stop(Pid) -> Pid ! {stop, self()}, - _T1 = t(), + _T1 = snmp_misc:now(ms), receive {'EXIT', Pid, normal} -> - _T2 = t(), + _T2 = snmp_misc:now(ms), ?DBG("it took ~w ms to stop the writer", [_T2 - _T1]), ok after 60000 -> @@ -721,10 +721,10 @@ log_writer_info(Pid) -> log_writer_sleep(Pid, Time) -> Pid ! {sleep, Time, self()}, - _T1 = t(), + _T1 = snmp_misc:now(ms), receive {sleeping, Pid} -> - _T2 = t(), + _T2 = snmp_misc:now(ms), ?DBG("it took ~w ms to put the writer to sleep", [_T2 - _T1]), ok; {'EXIT', Pid, Reason} -> @@ -793,10 +793,10 @@ lp(F, A) -> log_reader_start() -> Pid = spawn_link(?MODULE, log_reader_main, [self()]), - _T1 = t(), + _T1 = snmp_misc:now(ms), receive {started, Pid} -> - _T2 = t(), + _T2 = snmp_misc:now(ms), ?DBG("it took ~w ms to start the reader", [_T2 - _T1]), {ok, Pid}; {'EXIT', Pid, Reason} -> @@ -807,10 +807,10 @@ log_reader_start() -> log_reader_stop(Pid) -> Pid ! {stop, self()}, - _T1 = t(), + _T1 = snmp_misc:now(ms), receive {'EXIT', Pid, normal} -> - _T2 = t(), + _T2 = snmp_misc:now(ms), ?DBG("it took ~w ms to put the reader to eleep", [_T2 - _T1]), ok after 1000 -> @@ -1124,8 +1124,3 @@ join(D, F) -> p(Case) -> io:format(user, "test case: ~w~n", [Case]). - -%% Time in milli sec -t() -> - {A,B,C} = erlang:now(), - A*1000000000+B*1000+(C div 1000). diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index f37e957dae..ba674edce3 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -2169,7 +2169,6 @@ register_usm_user_using_function(Conf) when is_list(Conf) -> %% -- p("done"), ok. -%% ?SKIP(not_yet_implemented). %% @@ -2259,8 +2258,9 @@ create_and_increment(Conf) when is_list(Conf) -> ?line {ok, _Pid} = snmpm_config:start_link(Opts), %% Random init - {A,B,C} = erlang:now(), - random:seed(A,B,C), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), StartVal = random:uniform(2147483647), IncVal = 42, diff --git a/lib/snmp/test/snmp_test_lib.erl b/lib/snmp/test/snmp_test_lib.erl index 5e611340a3..72c7452ec4 100644 --- a/lib/snmp/test/snmp_test_lib.erl +++ b/lib/snmp/test/snmp_test_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2002-2014. All Rights Reserved. +%% Copyright Ericsson AB 2002-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -30,7 +30,7 @@ lookup/2, replace_config/3, set_config/3, get_config/2, get_config/3]). -export([fail/3, skip/3]). --export([millis/0, millis_diff/2, hours/1, minutes/1, seconds/1, sleep/1]). +-export([hours/1, minutes/1, seconds/1, sleep/1]). -export([flush_mqueue/0, trap_exit/0, trap_exit/1]). -export([ping/1, local_nodes/0, nodes_on/1]). -export([start_node/2]). @@ -334,14 +334,6 @@ skip(Reason, Module, Line) -> %% Time related function %% -millis() -> - erlang:now(). - -millis_diff(A,B) -> - T1 = (element(1,A)*1000000) + element(2,A) + (element(3,A)/1000000), - T2 = (element(1,B)*1000000) + element(2,B) + (element(3,B)/1000000), - T1 - T2. - hours(N) -> trunc(N * 1000 * 60 * 60). minutes(N) -> trunc(N * 1000 * 60). seconds(N) -> trunc(N * 1000). @@ -628,4 +620,3 @@ format_timestamp({_N1, _N2, N3} = Now) -> io_lib:format("~.4w:~.2.0w:~.2.0w ~.2.0w:~.2.0w:~.2.0w ~w", [YYYY,MM,DD,Hour,Min,Sec,round(N3/1000)]), lists:flatten(FormatDate). - diff --git a/lib/snmp/test/snmp_test_lib.hrl b/lib/snmp/test/snmp_test_lib.hrl index 9b7609b831..fd584880da 100644 --- a/lib/snmp/test/snmp_test_lib.hrl +++ b/lib/snmp/test/snmp_test_lib.hrl @@ -1,8 +1,8 @@ -%% -%% 2002-2014 -%% Ericsson AB, All Rights Reserved -%% -%% +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2002-2015. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the @@ -15,7 +15,7 @@ %% under the License. %% %% The Initial Developer of the Original Code is Ericsson AB. -%% +%% %CopyrightEnd% %% %%---------------------------------------------------------------------- %% Purpose: Define common macros for testing @@ -73,8 +73,6 @@ -endif. -define(SLEEP(MSEC), snmp_test_lib:sleep(MSEC)). --define(M(), snmp_test_lib:millis()). --define(MDIFF(A,B), snmp_test_lib:millis_diff(A,B)). %% - Process utility macros - @@ -149,4 +147,3 @@ -define(PRINT(P,F,A), snmp_test_lib:print(P,?MODULE,?LINE,F,A)). - diff --git a/lib/snmp/test/snmp_test_mgr.erl b/lib/snmp/test/snmp_test_mgr.erl index 8cb6ec588e..1bf7efc695 100644 --- a/lib/snmp/test/snmp_test_mgr.erl +++ b/lib/snmp/test/snmp_test_mgr.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -188,8 +188,9 @@ receive_trap(Timeout) -> init({Options, CallerPid}) -> put(sname, mgr), put(verbosity, debug), - {A1,A2,A3} = erlang:now(), - random:seed(A1,A2,A3), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), case (catch is_options_ok(Options)) of true -> put(debug, get_value(debug, Options, false)), @@ -1135,4 +1136,3 @@ d(_,_F,_A) -> formated_timestamp() -> snmp_test_lib:formated_timestamp(). - -- cgit v1.2.3 From 722357d7a23ee4a47277f05aa5fd593bc4de0db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Mon, 27 Apr 2015 09:39:16 +0200 Subject: snmp: Remove deprecated warning for erlang:now in snmp_verbority --- lib/snmp/src/misc/snmp_verbosity.erl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/misc/snmp_verbosity.erl b/lib/snmp/src/misc/snmp_verbosity.erl index f27c31db03..c9192158ef 100644 --- a/lib/snmp/src/misc/snmp_verbosity.erl +++ b/lib/snmp/src/misc/snmp_verbosity.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2012. All Rights Reserved. +%% Copyright Ericsson AB 2000-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -69,7 +69,7 @@ print2(_Verbosity,Format,Arguments) -> timestamp() -> - format_timestamp(now()). + format_timestamp(os:timestamp()). format_timestamp({_N1, _N2, N3} = Now) -> {Date, Time} = calendar:now_to_datetime(Now), @@ -162,4 +162,3 @@ validate(log) -> log; validate(debug) -> debug; validate(trace) -> trace; validate(_) -> silence. - -- cgit v1.2.3 From 4098e8fc7866c8b79cdd29230c181b6edb0a4889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Tue, 28 Apr 2015 15:08:42 +0200 Subject: snmp: Remove deprecated warning for erlang:now in snmpc --- lib/snmp/src/compile/snmpc.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/compile/snmpc.erl b/lib/snmp/src/compile/snmpc.erl index 2f065dddac..e7839c0792 100644 --- a/lib/snmp/src/compile/snmpc.erl +++ b/lib/snmp/src/compile/snmpc.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2013. All Rights Reserved. +%% Copyright Ericsson AB 1997-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -409,8 +409,9 @@ get_verbosity(Options) -> %%---------------------------------------------------------------------- init(From, MibFileName, Options) -> - {A,B,C} = now(), - random:seed(A,B,C), + random:seed(erlang:phash2([node()]), + erlang:monotonic_time(), + erlang:unique_integer()), put(options, Options), put(verbosity, get_verbosity(Options)), put(description, get_description(Options)), -- cgit v1.2.3 From 82e45c23a31ce2bf7bf4ac7ed9c9a4e6187f6574 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 30 Apr 2015 15:39:49 +0200 Subject: Improve agent fix as in manager --- lib/snmp/src/agent/snmpa_net_if.erl | 69 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index 1e580072ba..57d63bab5b 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -297,14 +297,14 @@ socket_open(snmpUDPDomain = Domain, [IpPort | Opts]) -> Fd = list_to_integer(FdStr), ?vdebug("socket_open(~p, [~p | ~p]) Fd: ~p", [Domain, IpPort, Opts, Fd]), - gen_udp_open(IpPort, [{fd, Fd} | Opts]); + gen_udp_open(0, [{fd, Fd} | Opts]); error -> case init:get_argument(snmpa_fd) of {ok, [[FdStr]]} -> Fd = list_to_integer(FdStr), ?vdebug("socket_open(~p, [~p | ~p]) Fd: ~p", [Domain, IpPort, Opts, Fd]), - gen_udp_open(IpPort, [{fd, Fd} | Opts]); + gen_udp_open(0, [{fd, Fd} | Opts]); error -> ?vdebug("socket_open(~p, [~p | ~p])", [Domain, IpPort, Opts]), @@ -1447,39 +1447,38 @@ get_counters([Counter|Counters], Acc) -> %% ---------------------------------------------------------------- socket_opts(Domain, {IpAddr, IpPort}, Opts) -> - case get_bind_to_ip_address(Opts) of - true -> - [IpPort, % Picked off at socket open, separate argument - binary, - {ip, IpAddr}]; - _ -> - [0, % Picked off at socket open, separate argument - binary] - end ++ - case snmp_conf:tdomain_to_family(Domain) of - inet6 = Family -> - [Family, {ipv6_v6only, true}]; - Family -> - [Family] - end ++ - case get_no_reuse_address(Opts) of - false -> - [{reuseaddr, true}]; - _ -> - [] - end ++ - case get_recbuf(Opts) of - use_default -> - []; - Sz -> - [{recbuf, Sz}] - end ++ - case get_sndbuf(Opts) of - use_default -> - []; - Sz -> - [{sndbuf, Sz}] - end. + [IpPort, % Picked off at socket open, separate argument + binary + | case snmp_conf:tdomain_to_family(Domain) of + inet6 = Family -> + [Family, {ipv6_v6only, true}]; + Family -> + [Family] + end ++ + case get_bind_to_ip_address(Opts) of + true -> + [{ip, IpAddr}]; + _ -> + [] + end ++ + case get_no_reuse_address(Opts) of + false -> + [{reuseaddr, true}]; + _ -> + [] + end ++ + case get_recbuf(Opts) of + use_default -> + []; + Sz -> + [{recbuf, Sz}] + end ++ + case get_sndbuf(Opts) of + use_default -> + []; + Sz -> + [{sndbuf, Sz}] + end]. %% ---------------------------------------------------------------- -- cgit v1.2.3 From 512f099b247b17b3145e90293167a4ba373b9471 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Wed, 6 May 2015 10:46:46 +0200 Subject: Prepare release --- lib/snmp/doc/src/notes.xml | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index fd307ef824..52022f59ff 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -33,7 +33,40 @@
-
+
SNMP 5.1.2 + +
Fixed Bugs and Malfunctions + + +

+ A bug in the SNMP Agent has been corrected; when opening + a port using the command line argument -snmpa_fd the Port + should be 0 when calling gen_udp:open.

+

+ A bug in the SNMP manager has been corrected; it should + not look at the -snmp_fd command line argument, but + instead at -snmpm_fd.

+

+ Own Id: OTP-12669 Aux Id: seq12841

+
+
+
+ + +
Improvements and New Features + + +

+ Improved cryptocraphic capability.

+

+ Own Id: OTP-12452

+
+
+
+ +
+ +
SNMP Development Toolkit 5.1.1

Version 5.1.1 supports code replacement in runtime from/to version 5.1.

-- cgit v1.2.3 From 2c2260044637b8acd706cf3a784568e27340e61e Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Tue, 19 May 2015 11:57:11 +0200 Subject: Update runtime_dependencies in application resource files Applications that use the new erl_anno module are depending on STDLIB 2.5. Note that CosNotification, Megaco, SNMP, Xmerl, and Parsetools use the erl_anno module via the Yecc parsers only (the header file in lib/parsetools/include/yeccpre.hrl calls the erl_anno module). HiPE does not call the erl_anno module, but uses an exported type. We have chosen to make HiPE dependent on the erl_anno module. --- lib/snmp/src/app/snmp.app.src | 4 ++-- lib/snmp/vsn.mk | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.app.src b/lib/snmp/src/app/snmp.app.src index cbd292e4c3..a55bb389ba 100644 --- a/lib/snmp/src/app/snmp.app.src +++ b/lib/snmp/src/app/snmp.app.src @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -137,5 +137,5 @@ %% before snmp. {applications, [kernel, stdlib]}, {mod, {snmp_app, []}}, - {runtime_dependencies, ["stdlib-2.0","runtime_tools-1.8.14","mnesia-4.12", + {runtime_dependencies, ["stdlib-2.5","runtime_tools-1.8.14","mnesia-4.12", "kernel-3.0","erts-6.0","crypto-3.3"]}]}. diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 67adf0a34f..14da37a225 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,6 +18,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.1.2 +SNMP_VSN = 5.2 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 8d4b54db1b4756ea52ebc72df76ae5f13e276d9a Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Mon, 25 May 2015 09:38:31 +0200 Subject: Update application versions --- lib/snmp/src/app/snmp.appup.src | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 081163b368..a21ff863be 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -28,6 +28,8 @@ %% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} %% {add_module, snmpm_net_if_mt} [ + {"5.1.2", [ % Only runtime dependencies change + ]}, {"5.1.1", [{restart_application, snmp}]}, {"5.1", [ % Only compiler changes ]}, @@ -47,6 +49,8 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"5.1.2", [ % Only runtime dependencies change + ]}, {"5.1.1", [{restart_application, snmp}]}, {"5.1", [ % Only compiler changes ]}, -- cgit v1.2.3 From 69dfa5599dc72db8addcad0f3b42a2b6716676ab Mon Sep 17 00:00:00 2001 From: Kirilll Zaborsky Date: Thu, 28 May 2015 18:20:12 +0300 Subject: Typo 'asynchroneous' fix --- lib/snmp/doc/src/snmp_app.xml | 2 +- lib/snmp/doc/src/snmp_config.xml | 2 +- lib/snmp/src/manager/snmpm.erl | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/snmp_app.xml b/lib/snmp/doc/src/snmp_app.xml index 86f0981988..e36908a5b9 100644 --- a/lib/snmp/doc/src/snmp_app.xml +++ b/lib/snmp/doc/src/snmp_app.xml @@ -587,7 +587,7 @@ ]]> -

Asynchroneous request cleanup time. For every requests, +

Asynchronous request cleanup time. For every requests, some info is stored internally, in order to be able to deliver the reply (when it arrives) to the proper destination. If the reply arrives, this info will be deleted. But if diff --git a/lib/snmp/doc/src/snmp_config.xml b/lib/snmp/doc/src/snmp_config.xml index 0ec8bb91cf..d1ee6545dd 100644 --- a/lib/snmp/doc/src/snmp_config.xml +++ b/lib/snmp/doc/src/snmp_config.xml @@ -616,7 +616,7 @@ in so far as it will be converted to the new format if found. ]]> -

Asynchroneous request cleanup time. For every requests, +

Asynchronous request cleanup time. For every requests, some info is stored internally, in order to be able to deliver the reply (when it arrives) to the proper destination. If the reply arrives, this info will be deleted. But if diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 8976322c4e..96e3d55b46 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -520,7 +520,7 @@ sync_get(UserId, TargetName, Context, Oids, Timeout, ExtraInfo) -> -%% --- asynchroneous get-request --- +%% --- asynchronous get-request --- %% %% The reply will be delivered to the user %% through a call to handle_pdu/5 @@ -588,7 +588,7 @@ sync_get_next(UserId, TargetName, Context, Oids, Timeout, ExtraInfo) -> %% -%% --- asynchroneous get_next-request --- +%% --- asynchronous get_next-request --- %% async_get_next2(UserId, TargetName, Oids) -> @@ -654,7 +654,7 @@ sync_set(UserId, TargetName, Context, VarsAndVals, Timeout, ExtraInfo) -> %% -%% --- asynchroneous set-request --- +%% --- asynchronous set-request --- %% async_set2(UserId, TargetName, VarsAndVals) -> @@ -746,7 +746,7 @@ sync_get_bulk(UserId, TargetName, NonRep, MaxRep, Context, Oids, Timeout, %% -%% --- asynchroneous get-bulk --- +%% --- asynchronous get-bulk --- %% async_get_bulk2(UserId, TargetName, NonRep, MaxRep, Oids) -> -- cgit v1.2.3 From 738c34d4bb8f1a3811acd00af8c6c12107f8315b Mon Sep 17 00:00:00 2001 From: Bruce Yinhe Date: Thu, 18 Jun 2015 11:31:02 +0200 Subject: Change license text to APLv2 --- lib/snmp/Makefile | 21 +++++++++++---------- lib/snmp/doc/src/Makefile | 21 +++++++++++---------- lib/snmp/doc/src/book.xml | 21 +++++++++++---------- lib/snmp/doc/src/files.mk | 21 +++++++++++---------- lib/snmp/doc/src/index.html.src | 21 +++++++++++---------- lib/snmp/doc/src/notes.xml | 21 +++++++++++---------- lib/snmp/doc/src/notes_history.xml | 21 +++++++++++---------- lib/snmp/doc/src/part.xml | 21 +++++++++++---------- lib/snmp/doc/src/part_notes.xml | 21 +++++++++++---------- lib/snmp/doc/src/part_notes_history.xml | 21 +++++++++++---------- lib/snmp/doc/src/ref_man.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_advanced_agent.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_agent_config_files.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_agent_funct_descr.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_agent_netif.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_app.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_app_a.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_app_b.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_audit_trail_log.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_community_mib.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_config.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_def_instr_functions.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_framework_mib.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_generic.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_impl_example_agent.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_impl_example_manager.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_index.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_instr_functions.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_intro.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_manager_config_files.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_manager_funct_descr.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_manager_netif.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_mib_compiler.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_notification_mib.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_pdus.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_standard_mib.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_target_mib.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_user_based_sm_mib.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmp_view_based_acm_mib.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_conf.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_discovery_handler.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_error.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_error_io.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_error_logger.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_error_report.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_local_db.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_mib_data.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_mib_storage.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_mpd.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_network_interface.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_network_interface_filter.xml | 19 ++++++++++--------- .../snmpa_notification_delivery_info_receiver.xml | 19 ++++++++++--------- lib/snmp/doc/src/snmpa_notification_filter.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpa_supervisor.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpc.xml | 19 ++++++++++--------- lib/snmp/doc/src/snmpc_cmd.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpm.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpm_conf.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpm_mpd.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpm_network_interface.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpm_network_interface_filter.xml | 21 +++++++++++---------- lib/snmp/doc/src/snmpm_user.xml | 21 +++++++++++---------- lib/snmp/examples/Makefile | 21 +++++++++++---------- lib/snmp/examples/ex1/Makefile | 21 +++++++++++---------- lib/snmp/examples/ex1/ex1.erl | 19 ++++++++++--------- lib/snmp/examples/ex2/Makefile | 21 +++++++++++---------- lib/snmp/examples/ex2/snmp_ex2_manager.erl | 21 +++++++++++---------- .../examples/ex2/snmp_ex2_simple_standard_test.erl | 21 +++++++++++---------- lib/snmp/examples/subdirs.mk | 21 +++++++++++---------- lib/snmp/include/SNMPv2-TC.hrl | 21 +++++++++++---------- lib/snmp/include/snmp_tables.hrl | 21 +++++++++++---------- lib/snmp/include/snmp_types.hrl | 21 +++++++++++---------- lib/snmp/mibs/Makefile.in | 21 +++++++++++---------- lib/snmp/priv/conf/Makefile | 21 +++++++++++---------- lib/snmp/priv/conf/agent/Makefile | 21 +++++++++++---------- lib/snmp/priv/conf/agent/files.mk | 21 +++++++++++---------- lib/snmp/priv/conf/manager/Makefile | 21 +++++++++++---------- lib/snmp/priv/conf/manager/files.mk | 21 +++++++++++---------- lib/snmp/priv/conf/subdirs.mk | 21 +++++++++++---------- lib/snmp/src/Makefile | 21 +++++++++++---------- lib/snmp/src/agent/Makefile | 21 +++++++++++---------- lib/snmp/src/agent/depend.mk | 21 +++++++++++---------- lib/snmp/src/agent/modules.mk | 21 +++++++++++---------- lib/snmp/src/agent/snmp_community_mib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_framework_mib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_generic.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_generic_mnesia.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_index.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_notification_mib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_shadow_table.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_standard_mib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_target_mib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_user_based_sm_mib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_acm.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_agent.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_agent_sup.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_app.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_atl.hrl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_authentication_service.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_conf.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_discovery_handler.erl | 21 +++++++++++---------- .../src/agent/snmpa_discovery_handler_default.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_error.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_error_io.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_error_logger.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_error_report.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_general_db.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_internal.hrl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_local_db.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_mib.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_mib_data.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_mib_data_ttln.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_mib_data_tttn.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_mib_lib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_mib_storage.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_mib_storage_dets.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_mib_storage_ets.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_misc_sup.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_mpd.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_net_if.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_net_if_filter.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_network_interface.erl | 21 +++++++++++---------- .../src/agent/snmpa_network_interface_filter.erl | 21 +++++++++++---------- .../snmpa_notification_delivery_info_receiver.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_notification_filter.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_set.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_set_lib.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_set_mechanism.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_supervisor.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_svbl.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_symbolic_store.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_target_cache.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_trap.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_usm.erl | 19 ++++++++++--------- lib/snmp/src/agent/snmpa_vacm.erl | 21 +++++++++++---------- lib/snmp/src/agent/snmpa_vacm.hrl | 21 +++++++++++---------- lib/snmp/src/app/Makefile | 21 +++++++++++---------- lib/snmp/src/app/depend.mk | 21 +++++++++++---------- lib/snmp/src/app/modules.mk | 21 +++++++++++---------- lib/snmp/src/app/snmp.app.src | 21 +++++++++++---------- lib/snmp/src/app/snmp.appup.src | 21 +++++++++++---------- lib/snmp/src/app/snmp.erl | 21 +++++++++++---------- lib/snmp/src/app/snmp_app.erl | 21 +++++++++++---------- lib/snmp/src/app/snmp_app_sup.erl | 21 +++++++++++---------- lib/snmp/src/app/snmp_internal.hrl | 21 +++++++++++---------- lib/snmp/src/compile/Makefile | 21 +++++++++++---------- lib/snmp/src/compile/depend.mk | 21 +++++++++++---------- lib/snmp/src/compile/modules.mk | 21 +++++++++++---------- lib/snmp/src/compile/snmpc.erl | 19 ++++++++++--------- lib/snmp/src/compile/snmpc.hrl | 21 +++++++++++---------- lib/snmp/src/compile/snmpc.src | 21 +++++++++++---------- lib/snmp/src/compile/snmpc_lib.erl | 19 ++++++++++--------- lib/snmp/src/compile/snmpc_lib.hrl | 21 +++++++++++---------- lib/snmp/src/compile/snmpc_mib_gram.yrl | 21 +++++++++++---------- lib/snmp/src/compile/snmpc_mib_to_hrl.erl | 21 +++++++++++---------- lib/snmp/src/compile/snmpc_misc.erl | 21 +++++++++++---------- lib/snmp/src/compile/snmpc_misc.hrl | 21 +++++++++++---------- lib/snmp/src/compile/snmpc_tok.erl | 21 +++++++++++---------- lib/snmp/src/manager/Makefile | 21 +++++++++++---------- lib/snmp/src/manager/depend.mk | 21 +++++++++++---------- lib/snmp/src/manager/modules.mk | 21 +++++++++++---------- lib/snmp/src/manager/snmpm.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_atl.hrl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_conf.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_config.erl | 19 ++++++++++--------- lib/snmp/src/manager/snmpm_internal.hrl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_misc_sup.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_mpd.erl | 19 ++++++++++--------- lib/snmp/src/manager/snmpm_net_if.erl | 19 ++++++++++--------- lib/snmp/src/manager/snmpm_net_if_filter.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_net_if_mt.erl | 19 ++++++++++--------- lib/snmp/src/manager/snmpm_network_interface.erl | 21 +++++++++++---------- .../src/manager/snmpm_network_interface_filter.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_server.erl | 19 ++++++++++--------- lib/snmp/src/manager/snmpm_server_sup.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_supervisor.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_user.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_user_default.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_user_old.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_usm.erl | 21 +++++++++++---------- lib/snmp/src/manager/snmpm_usm.hrl | 21 +++++++++++---------- lib/snmp/src/misc/Makefile | 21 +++++++++++---------- lib/snmp/src/misc/depend.mk | 21 +++++++++++---------- lib/snmp/src/misc/modules.mk | 21 +++++++++++---------- lib/snmp/src/misc/snmp_conf.erl | 21 +++++++++++---------- lib/snmp/src/misc/snmp_config.erl | 19 ++++++++++--------- lib/snmp/src/misc/snmp_debug.hrl | 21 +++++++++++---------- lib/snmp/src/misc/snmp_log.erl | 19 ++++++++++--------- lib/snmp/src/misc/snmp_mini_mib.erl | 21 +++++++++++---------- lib/snmp/src/misc/snmp_misc.erl | 21 +++++++++++---------- lib/snmp/src/misc/snmp_note_store.erl | 21 +++++++++++---------- lib/snmp/src/misc/snmp_pdus.erl | 19 ++++++++++--------- lib/snmp/src/misc/snmp_usm.erl | 19 ++++++++++--------- lib/snmp/src/misc/snmp_verbosity.erl | 21 +++++++++++---------- lib/snmp/src/misc/snmp_verbosity.hrl | 21 +++++++++++---------- lib/snmp/src/subdirs.mk | 21 +++++++++++---------- lib/snmp/subdirs.mk | 21 +++++++++++---------- lib/snmp/test/Makefile | 21 +++++++++++---------- lib/snmp/test/exp/snmp_agent_bl_test.erl | 21 +++++++++++---------- lib/snmp/test/exp/snmp_agent_ms_test.erl | 21 +++++++++++---------- lib/snmp/test/exp/snmp_agent_mt_test.erl | 21 +++++++++++---------- lib/snmp/test/exp/snmp_agent_v1_test.erl | 21 +++++++++++---------- lib/snmp/test/exp/snmp_agent_v2_test.erl | 21 +++++++++++---------- lib/snmp/test/exp/snmp_agent_v3_test.erl | 21 +++++++++++---------- lib/snmp/test/klas3.erl | 21 +++++++++++---------- lib/snmp/test/modules.mk | 19 ++++++++++--------- lib/snmp/test/sa.erl | 21 +++++++++++---------- lib/snmp/test/snmp_SUITE.erl | 21 +++++++++++---------- lib/snmp/test/snmp_agent_mibs_test.erl | 21 +++++++++++---------- lib/snmp/test/snmp_agent_nfilter_test.erl | 21 +++++++++++---------- lib/snmp/test/snmp_agent_test.erl | 19 ++++++++++--------- lib/snmp/test/snmp_agent_test_lib.erl | 19 ++++++++++--------- lib/snmp/test/snmp_app_test.erl | 21 +++++++++++---------- lib/snmp/test/snmp_appup_mgr.erl | 21 +++++++++++---------- lib/snmp/test/snmp_appup_test.erl | 21 +++++++++++---------- lib/snmp/test/snmp_compiler_test.erl | 19 ++++++++++--------- lib/snmp/test/snmp_conf_test.erl | 21 +++++++++++---------- lib/snmp/test/snmp_log_test.erl | 19 ++++++++++--------- lib/snmp/test/snmp_manager_config_test.erl | 19 ++++++++++--------- lib/snmp/test/snmp_manager_test.erl | 19 ++++++++++--------- lib/snmp/test/snmp_manager_user.erl | 21 +++++++++++---------- lib/snmp/test/snmp_manager_user_old.erl | 21 +++++++++++---------- lib/snmp/test/snmp_manager_user_test.erl | 19 ++++++++++--------- lib/snmp/test/snmp_manager_user_test_lib.erl | 21 +++++++++++---------- lib/snmp/test/snmp_note_store_test.erl | 21 +++++++++++---------- lib/snmp/test/snmp_pdus_test.erl | 19 ++++++++++--------- lib/snmp/test/snmp_test_lib.erl | 19 ++++++++++--------- lib/snmp/test/snmp_test_lib.hrl | 19 ++++++++++--------- lib/snmp/test/snmp_test_manager.erl | 21 +++++++++++---------- lib/snmp/test/snmp_test_mgr.erl | 19 ++++++++++--------- lib/snmp/test/snmp_test_mgr_counter_server.erl | 19 ++++++++++--------- lib/snmp/test/snmp_test_mgr_misc.erl | 19 ++++++++++--------- lib/snmp/test/snmp_test_server.erl | 21 +++++++++++---------- lib/snmp/test/snmp_test_suite.erl | 21 +++++++++++---------- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 19 ++++++++++--------- .../snmp_to_snmpnet_SUITE_data/start_stop_wrapper | 19 ++++++++++--------- lib/snmp/test/test1.erl | 21 +++++++++++---------- lib/snmp/test/test2.erl | 21 +++++++++++---------- lib/snmp/test/test_config/Makefile | 21 +++++++++++---------- lib/snmp/test/test_config/modules.mk | 19 ++++++++++--------- lib/snmp/test/test_config/snmp_test_config.erl | 19 ++++++++++--------- lib/snmp/vsn.mk | 19 ++++++++++--------- 247 files changed, 2671 insertions(+), 2424 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/Makefile b/lib/snmp/Makefile index ff6fad8ddc..ce739f3438 100644 --- a/lib/snmp/Makefile +++ b/lib/snmp/Makefile @@ -4,16 +4,17 @@ # # Copyright Ericsson AB 1996-2011. All Rights Reserved. # -# The contents of this file are subject to the Erlang Public License, -# Version 1.1, (the "License"); you may not use this file except in -# compliance with the License. You should have received a copy of the -# Erlang Public License along with this software. If not, it can be -# retrieved online at http://www.erlang.org/. -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # # %CopyrightEnd% diff --git a/lib/snmp/doc/src/Makefile b/lib/snmp/doc/src/Makefile index 6e55498669..6d5b005e3e 100644 --- a/lib/snmp/doc/src/Makefile +++ b/lib/snmp/doc/src/Makefile @@ -4,16 +4,17 @@ # # Copyright Ericsson AB 1997-2012. All Rights Reserved. # -# The contents of this file are subject to the Erlang Public License, -# Version 1.1, (the "License"); you may not use this file except in -# compliance with the License. You should have received a copy of the -# Erlang Public License along with this software. If not, it can be -# retrieved online at http://www.erlang.org/. -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # # %CopyrightEnd% diff --git a/lib/snmp/doc/src/book.xml b/lib/snmp/doc/src/book.xml index a5c054142f..68e87b8afe 100644 --- a/lib/snmp/doc/src/book.xml +++ b/lib/snmp/doc/src/book.xml @@ -8,16 +8,17 @@ Ericsson AB. All Rights Reserved. - The contents of this file are subject to the Erlang Public License, - Version 1.1, (the "License"); you may not use this file except in - compliance with the License. You should have received a copy of the - Erlang Public License along with this software. If not, it can be - retrieved online at http://www.erlang.org/. - - Software distributed under the License is distributed on an "AS IS" - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - the License for the specific language governing rights and limitations - under the License. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/lib/snmp/doc/src/files.mk b/lib/snmp/doc/src/files.mk index 91fd18ca85..fea8deee02 100644 --- a/lib/snmp/doc/src/files.mk +++ b/lib/snmp/doc/src/files.mk @@ -4,16 +4,17 @@ # # Copyright Ericsson AB 2001-2013. All Rights Reserved. # -# The contents of this file are subject to the Erlang Public License, -# Version 1.1, (the "License"); you may not use this file except in -# compliance with the License. You should have received a copy of the -# Erlang Public License along with this software. If not, it can be -# retrieved online at http://www.erlang.org/. -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # # %CopyrightEnd% diff --git a/lib/snmp/doc/src/index.html.src b/lib/snmp/doc/src/index.html.src index 7ad2140559..e1b6be4d1f 100644 --- a/lib/snmp/doc/src/index.html.src +++ b/lib/snmp/doc/src/index.html.src @@ -2,16 +2,17 @@ - ]]> + + ]]>

Defines the backend data module of the SNMP agent mib-server as defined by the @@ -476,24 +478,24 @@

Default module is snmpa_mib_data_tttn.

- - ]]> + + ]]>

Shall the agent utilize the mib server lookup cache or not.

Default is true (in which case the mibs_cache_opts() default values apply).

- - ]]> + + ]]>

mibs_cache_opt() = {autogc, mibs_cache_autogc()} | {gclimit, mibs_cache_gclimit()} | {age, mibs_cache_age()}

Defines options specific for the SNMP agent mib server cache.

For defaults see the options in mibs_cache_opt().

- - ]]> + + ]]>

Defines if the mib server shall perform cache gc automatically or leave it to the user (see @@ -501,8 +503,8 @@

Default is true.

- - 0 ]]> + + 0 ]]>

Defines how old the entries in the cache will be allowed to become before they are GC'ed (assuming GC is performed). @@ -511,8 +513,8 @@

Default is 10 timutes.

- - 0 | infinity ]]> + + 0 | infinity ]]>

When performing a GC, this is the max number of cache entries that will be deleted from the cache.

@@ -522,8 +524,8 @@

Default is 100.

- - ]]> + + ]]>

Defines an error report module, implementing the snmpa_error_report @@ -532,38 +534,38 @@

Default is snmpa_error_logger.

- - symbolic_store() = [symbolic_store_opt()] + + symbolic_store() = [symbolic_store_opt()]

symbolic_store_opt() = {verbosity, verbosity()}

Defines options specific for the SNMP agent symbolic store.

For defaults see the options in symbolic_store_opt().

- - target_cache() = [target_cache_opt()] + + target_cache() = [target_cache_opt()]

target_cache_opt() = {verbosity, verbosity()}

Defines options specific for the SNMP agent target cache.

For defaults see the options in target_cache_opt().

- - ]]> + + ]]>

agent_config_opt() = {dir, agent_config_dir()} | {force_load, force_load()} | {verbosity, verbosity()}

Defines specific config related options for the SNMP agent.

For defaults see the options in agent_config_opt().

- - ]]> + + ]]>

Defines where the SNMP agent configuration files are stored.

- - ]]> + + ]]>

If true the configuration files are re-read during start-up, and the contents of the configuration @@ -577,16 +579,16 @@

Manager specific config options and types:

- - ]]> + + ]]>

server_opt() = {timeout, server_timeout()} | {verbosity, verbosity()}

Specifies the options for the manager server process.

Default is silence.

- - ]]> + + ]]>

Asynchronous request cleanup time. For every requests, some info is stored internally, in order to be able to @@ -606,44 +608,44 @@

Default is 30000.

- - ]]> + + ]]>

manager_config_opt() = {dir, manager_config_dir()} | {db_dir, manager_db_dir()} | {db_init_error, db_init_error()} | {repair, manager_repair()} | {auto_save, manager_auto_save()} | {verbosity, verbosity()}

Defines specific config related options for the SNMP manager.

For defaults see the options in manager_config_opt().

- - ]]> + + ]]>

Defines where the SNMP manager configuration files are stored.

- - ]]> + + ]]>

Defines where the SNMP manager store persistent data.

- - ]]> + + ]]>

Defines the repair option for the persistent database (if and how the table is repaired when opened).

Default is true.

- - ]]> + + ]]>

The auto save interval. The table is flushed to disk whenever not accessed for this amount of time.

Default is 5000.

- - ]]> + + ]]>

This option defines how the manager will handle the sending of response (acknowledgment) to received inform-requests.

@@ -672,16 +674,16 @@

Default is auto.

- - ]]> + + ]]>

Specifies a list of MIBs (including path) and defines which MIBs are initially loaded into the SNMP manager.

Default is [].

- - ]]> + + ]]>

manager_net_if_opt() = {module, manager_net_if_module()} | {verbosity, verbosity()} | @@ -691,8 +693,8 @@

For defaults see the options in manager_net_if_opt().

- - ]]> + + ]]>

manager_net_if_option() = {bind_to, bind_to()} | {sndbuf, sndbuf()} | @@ -705,8 +707,8 @@

For defaults see the options in manager_net_if_option().

- - ]]> + + ]]>

The module which handles the network interface part for the SNMP manager. It must implement the @@ -714,8 +716,8 @@

Default is snmpm_net_if.

- - ]]> + + ]]>

manager_net_if_filter_option() = {module, manager_net_if_filter_module()}

These options are actually specific to the used module. @@ -725,8 +727,8 @@ manager_net_if_filter_option().

- - ]]> + + ]]>

Module which handles the network interface filter part for the SNMP manager. Must implement the @@ -734,16 +736,16 @@

Default is snmpm_net_if_filter.

- - ]]> + + ]]>

The module implementing the default user. See the snmpm_user behaviour.

Default is snmpm_user_default.

- - ]]> + + ]]>

Data for the default user. Passed to the user module when calling the callback functions.

@@ -754,8 +756,8 @@

Common config types:

- - restart_type() = permanent | transient | temporary + + restart_type() = permanent | transient | temporary

See supervisor documentation for more info.

@@ -763,8 +765,8 @@ for the manager.

- - db_init_error() = terminate | create | create_db_and_dir + + db_init_error() = terminate | create | create_db_and_dir

Defines what to do if the agent or manager is unable to open an existing database file. terminate means that the @@ -776,31 +778,31 @@

Default is terminate.

- - ]]> + + ]]>

Defines the Erlang priority for all SNMP processes.

Default is normal.

- - ]]> + + ]]>

version() = v1 | v2 | v3

Which SNMP versions shall be accepted/used.

Default is [v1,v2,v3].

- - ]]> + + ]]>

Verbosity for a SNMP process. This specifies now much debug info is printed.

Default is silence.

- - ]]> + + ]]>

If true, net_if binds to the IP address. If false, net_if listens on any IP address on the host @@ -808,8 +810,8 @@

Default is false.

- - ]]> + + ]]>

If true, net_if does not specify that the IP and port address should be reusable. If false, @@ -817,30 +819,30 @@

Default is false.

- - ]]> + + ]]>

Receive buffer size.

Default value is defined by gen_udp.

- - ]]> + + ]]>

Send buffer size.

Default value is defined by gen_udp.

- - ]]> + + ]]>

note_store_opt() = {timeout, note_store_timeout()} | {verbosity, verbosity()}

Specifies the start-up verbosity for the SNMP note store.

For defaults see the options in note_store_opt().

- - ]]> + + ]]>

Note cleanup time. When storing a note in the note store, each note is given lifetime. Every timeout the note_store @@ -850,8 +852,8 @@ - - ]]> + + ]]>

audit_trail_log_opt() = {type, atl_type()} | {dir, atl_dir()} | {size, atl_size()} | {repair, atl_repair()} | {seqno, atl_seqno()}

If present, this option specifies the options for the @@ -861,8 +863,8 @@

If not present, audit trail logging is not used.

- - ]]> + + ]]>

Specifies what type of an audit trail log should be used. The effect of the type is actually different for the the agent @@ -883,16 +885,16 @@

Default is read_write.

- - ]]> + + ]]>

Specifies where the audit trail log should be stored.

If audit_trail_log specifies that logging should take place, this parameter must be defined.

- - ]]> + + ]]>

Specifies the size of the audit trail log. This parameter is sent to disk_log.

@@ -900,8 +902,8 @@ take place, this parameter must be defined.

- - ]]> + + ]]>

Specifies if and how the audit trail log shall be repaired when opened. Unless this parameter has the value snmp_repair @@ -913,8 +915,8 @@

Default is true.

- - ]]> + + ]]>

Specifies if the audit trail log entries will be (sequence) numbered or not. The range of the sequence numbers are according diff --git a/lib/snmp/doc/src/snmp_config.xml b/lib/snmp/doc/src/snmp_config.xml index f10574a2a9..a085252d90 100644 --- a/lib/snmp/doc/src/snmp_config.xml +++ b/lib/snmp/doc/src/snmp_config.xml @@ -130,16 +130,16 @@

Agent specific config options and types:

- - ]]> + + ]]>

If master, one master agent is started. Otherwise, no agents are started.

Default is master.

- - ]]> + + ]]>

agent_discovery_opt() = {terminating, agent_terminating_discovery_opts()} | @@ -151,8 +151,8 @@

For defaults see the options in agent_discovery_opt().

- - ]]> + + ]]>

agent_terminating_discovery_opt() = {enable, boolean()} | @@ -169,8 +169,8 @@ - - ]]> + + ]]>

agent_originating_discovery_opt() = {enable, boolean()}

@@ -183,38 +183,38 @@
- - ]]> + + ]]>

If true, the agent is multi-threaded, with one thread for each get request.

Default is false.

- - ]]> + + ]]>

Defines where the SNMP agent internal db files are stored.

- - ]]> + + ]]>

Defines the maximum number of varbinds allowed in a Get-BULK response.

Default is 1000.

- - ]]> + + ]]>

local_db_opt() = {repair, agent_repair()} | {auto_save, agent_auto_save()} | {verbosity, verbosity()}

Defines options specific for the SNMP agent local database.

For defaults see the options in local_db_opt().

- - ]]> + + ]]>

When starting snmpa_local_db it always tries to open an existing database. If false, and some errors occur, a new @@ -224,16 +224,16 @@

Default is true.

- - ]]> + + ]]>

The auto save interval. The table is flushed to disk whenever not accessed for this amount of time.

Default is 5000.

- - ]]> + + ]]>

agent_net_if_option() = {module, agent_net_if_module()} | {verbosity, verbosity()} | @@ -243,8 +243,8 @@

For defaults see the options in agent_net_if_opt().

- - ]]> + + ]]>

Module which handles the network interface part for the SNMP agent. Must implement the @@ -252,8 +252,8 @@

Default is snmpa_net_if.

- - ]]> + + ]]>

agent_net_if_option() = {bind_to, bind_to()} | {sndbuf, sndbuf()} | @@ -267,15 +267,15 @@

For defaults see the options in agent_net_if_option().

- - ]]> + + ]]>

Max number of simultaneous requests handled by the agent.

Default is infinity.

- - ]]> + + ]]>

These options are actually specific to the used module. @@ -284,8 +284,8 @@

For defaults see the options in agent_net_if_filter_option().

- - ]]> + + ]]>

Module which handles the network interface filter part for the SNMP agent. Must implement the @@ -294,8 +294,8 @@

Default is snmpa_net_if_filter.

- - ]]> + + ]]>

Specifies a list of MIBs (including path) that defines which MIBs are initially loaded into the SNMP master agent.

@@ -309,8 +309,8 @@

Default is [].

- - ]]> + + ]]>

mib_storage_opt() = {module, mib_storage_module()} | {options, mib_storage_options()}

This option specifies how basic mib data is stored. @@ -319,8 +319,8 @@

Default is [{module, snmpa_mib_storage_ets}].

- - + +

Defines the mib storage module of the SNMP agent as defined by the snmpa_mib_storage @@ -334,8 +334,8 @@

Default module is snmpa_mib_storage_ets.

- - ]]> + + ]]>

This is implementattion depended. That is, it depends on the module. For each module a specific set of options are valid. @@ -429,8 +429,8 @@ This is the old format which is "supported", but not documented, in so far as it will be converted to the new format if found. - - ]]> + + ]]>

Specifies how info retrieved from the mibs will be stored.

If mib_storage is {ets, Dir}, the table will also be @@ -456,16 +456,16 @@ in so far as it will be converted to the new format if found. --> - - ]]> + + ]]>

mib_server_opt() = {mibentry_override, mibentry_override()} | {trapentry_override, trapentry_override()} | {verbosity, verbosity()} | {cache, mibs_cache()} | {data_module, mib_server_data_module()}

Defines options specific for the SNMP agent mib server.

For defaults see the options in mib_server_opt().

- - ]]> + + ]]>

If this value is false, then when loading a mib each mib- entry is checked prior to installation of the mib. @@ -474,8 +474,8 @@ in so far as it will be converted to the new format if found.

Default is false.

- - ]]> + + ]]>

If this value is false, then when loading a mib each trap is checked prior to installation of the mib. @@ -484,11 +484,13 @@ in so far as it will be converted to the new format if found.

Default is false.

- + - ]]> + + ]]>

Defines the backend data module of the SNMP agent mib-server as defined by the @@ -505,24 +507,24 @@ in so far as it will be converted to the new format if found.

Default module is snmpa_mib_data_tttn.

- - ]]> + + ]]>

Shall the agent utilize the mib server lookup cache or not.

Default is true (in which case the mibs_cache_opts() default values apply).

- - ]]> + + ]]>

mibs_cache_opt() = {autogc, mibs_cache_autogc()} | {gclimit, mibs_cache_gclimit()} | {age, mibs_cache_age()}

Defines options specific for the SNMP agent mib server cache.

For defaults see the options in mibs_cache_opt().

- - ]]> + + ]]>

Defines if the mib server shall perform cache gc automatically or leave it to the user (see @@ -530,8 +532,8 @@ in so far as it will be converted to the new format if found.

Default is true.

- - 0 ]]> + + 0 ]]>

Defines how old the entries in the cache will be allowed to become before they are GC'ed (assuming GC is performed). @@ -540,8 +542,8 @@ in so far as it will be converted to the new format if found.

Default is 10 timutes.

- - 0 | infinity ]]> + + 0 | infinity ]]>

When performing a GC, this is the max number of cache entries that will be deleted from the cache.

@@ -551,8 +553,8 @@ in so far as it will be converted to the new format if found.

Default is 100.

- - ]]> + + ]]>

Defines an error report module, implementing the snmpa_error_report @@ -561,38 +563,38 @@ in so far as it will be converted to the new format if found.

Default is snmpa_error_logger.

- - symbolic_store() = [symbolic_store_opt()] + + symbolic_store() = [symbolic_store_opt()]

symbolic_store_opt() = {verbosity, verbosity()}

Defines options specific for the SNMP agent symbolic store.

For defaults see the options in symbolic_store_opt().

- - target_cache() = [target_cache_opt()] + + target_cache() = [target_cache_opt()]

target_cache_opt() = {verbosity, verbosity()}

Defines options specific for the SNMP agent target cache.

For defaults see the options in target_cache_opt().

- - ]]> + + ]]>

agent_config_opt() = {dir, agent_config_dir()} | {force_load, force_load()} | {verbosity, verbosity()}

Defines specific config related options for the SNMP agent.

For defaults see the options in agent_config_opt().

- - ]]> + + ]]>

Defines where the SNMP agent configuration files are stored.

- - ]]> + + ]]>

If true the configuration files are re-read during start-up, and the contents of the configuration @@ -606,16 +608,16 @@ in so far as it will be converted to the new format if found.

Manager specific config options and types:

- - ]]> + + ]]>

server_opt() = {timeout, server_timeout()} | {verbosity, verbosity()}

Specifies the options for the manager server process.

Default is silence.

- - ]]> + + ]]>

Asynchronous request cleanup time. For every requests, some info is stored internally, in order to be able to @@ -635,44 +637,44 @@ in so far as it will be converted to the new format if found.

Default is 30000.

- - ]]> + + ]]>

manager_config_opt() = {dir, manager_config_dir()} | {db_dir, manager_db_dir()} | {db_init_error, db_init_error()} | {repair, manager_repair()} | {auto_save, manager_auto_save()} | {verbosity, verbosity()}

Defines specific config related options for the SNMP manager.

For defaults see the options in manager_config_opt().

- - ]]> + + ]]>

Defines where the SNMP manager configuration files are stored.

- - ]]> + + ]]>

Defines where the SNMP manager store persistent data.

- - ]]> + + ]]>

Defines the repair option for the persistent database (if and how the table is repaired when opened).

Default is true.

- - ]]> + + ]]>

The auto save interval. The table is flushed to disk whenever not accessed for this amount of time.

Default is 5000.

- - ]]> + + ]]>

This option defines how the manager will handle the sending of response (acknowledgment) to received inform-requests.

@@ -701,16 +703,16 @@ in so far as it will be converted to the new format if found.

Default is auto.

- - ]]> + + ]]>

Specifies a list of MIBs (including path) and defines which MIBs are initially loaded into the SNMP manager.

Default is [].

- - ]]> + + ]]>

manager_net_if_opt() = {module, manager_net_if_module()} | {verbosity, verbosity()} | @@ -720,8 +722,8 @@ in so far as it will be converted to the new format if found.

For defaults see the options in manager_net_if_opt().

- - ]]> + + ]]>

manager_net_if_option() = {bind_to, bind_to()} | {sndbuf, sndbuf()} | @@ -734,8 +736,8 @@ in so far as it will be converted to the new format if found.

For defaults see the options in manager_net_if_option().

- - ]]> + + ]]>

The module which handles the network interface part for the SNMP manager. It must implement the @@ -743,8 +745,8 @@ in so far as it will be converted to the new format if found.

Default is snmpm_net_if.

- - ]]> + + ]]>

manager_net_if_filter_option() = {module, manager_net_if_filter_module()}

These options are actually specific to the used module. @@ -754,8 +756,8 @@ in so far as it will be converted to the new format if found. manager_net_if_filter_option().

- - ]]> + + ]]>

Module which handles the network interface filter part for the SNMP manager. Must implement the @@ -763,16 +765,16 @@ in so far as it will be converted to the new format if found.

Default is snmpm_net_if_filter.

- - ]]> + + ]]>

The module implementing the default user. See the snmpm_user behaviour.

Default is snmpm_user_default.

- - ]]> + + ]]>

Data for the default user. Passed to the user when calling the callback functions.

@@ -783,8 +785,8 @@ in so far as it will be converted to the new format if found.

Common config types:

- - restart_type() = permanent | transient | temporary + + restart_type() = permanent | transient | temporary

See supervisor documentation for more info.

@@ -792,8 +794,8 @@ in so far as it will be converted to the new format if found. for the manager.

- - db_init_error() = terminate | create | create_db_and_dir + + db_init_error() = terminate | create | create_db_and_dir

Defines what to do if the agent is unable to open an existing database file. terminate means that the @@ -805,31 +807,31 @@ in so far as it will be converted to the new format if found.

Default is terminate.

- - ]]> + + ]]>

Defines the Erlang priority for all SNMP processes.

Default is normal.

- - ]]> + + ]]>

version() = v1 | v2 | v3

Which SNMP versions shall be accepted/used.

Default is [v1,v2,v3].

- - ]]> + + ]]>

Verbosity for a SNMP process. This specifies now much debug info is printed.

Default is silence.

- - ]]> + + ]]>

If true, net_if binds to the IP address. If false, net_if listens on any IP address on the host @@ -837,8 +839,8 @@ in so far as it will be converted to the new format if found.

Default is false.

- - ]]> + + ]]>

If true, net_if does not specify that the IP and port address should be reusable. If false, @@ -846,30 +848,30 @@ in so far as it will be converted to the new format if found.

Default is false.

- - ]]> + + ]]>

Receive buffer size.

Default value is defined by gen_udp.

- - ]]> + + ]]>

Send buffer size.

Default value is defined by gen_udp.

- - ]]> + + ]]>

note_store_opt() = {timeout, note_store_timeout()} | {verbosity, verbosity()}

Specifies the options for the SNMP note store.

For defaults see the options in note_store_opt().

- - ]]> + + ]]>

Note cleanup time. When storing a note in the note store, each note is given lifetime. Every timeout the note_store @@ -878,8 +880,8 @@ in so far as it will be converted to the new format if found.

Default is 30000.

- - ]]> + + ]]>

audit_trail_log_opt() = {type, atl_type()} | {dir, atl_dir()} | {size, atl_size()} | {repair, atl_repair()} | {seqno, atl_seqno()}

If present, this option specifies the options for the @@ -889,8 +891,8 @@ in so far as it will be converted to the new format if found.

If not present, audit trail logging is not used.

- - ]]> + + ]]>

Specifies what type of an audit trail log should be used. The effect of the type is actually different for the the agent @@ -911,16 +913,16 @@ in so far as it will be converted to the new format if found.

Default is read_write.

- - ]]> + + ]]>

Specifies where the audit trail log should be stored.

If audit_trail_log specifies that logging should take place, this parameter must be defined.

- - ]]> + + ]]>

Specifies the size of the audit trail log. This parameter is sent to disk_log.

@@ -928,8 +930,8 @@ in so far as it will be converted to the new format if found. take place, this parameter must be defined.

- - ]]> + + ]]>

Specifies if and how the audit trail log shall be repaired when opened. Unless this parameter has the value snmp_repair @@ -941,8 +943,8 @@ in so far as it will be converted to the new format if found.

Default is true.

- - ]]> + + ]]>

Specifies if the audit trail log entries will be (sequence) numbered or not. The range of the sequence numbers are according diff --git a/lib/snmp/doc/src/snmp_manager_netif.xml b/lib/snmp/doc/src/snmp_manager_netif.xml index 8454d03b17..98d4e7fd96 100644 --- a/lib/snmp/doc/src/snmp_manager_netif.xml +++ b/lib/snmp/doc/src/snmp_manager_netif.xml @@ -75,8 +75,7 @@

In this section a Domain field is the transport domain i.e one of transportDomainUdpIpv4 or transportDomainUdpIpv6, and an Addr field is an - {IpAddr, - IpPort} tuple.

+ {IpAddr,IpPort} tuple.

Net if must send the following message when it receives an SNMP PDU from the network that is aimed for the MasterAgent: diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index f205af6e88..c84eeec524 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -622,12 +622,12 @@ notification_delivery_info() = #snmpa_notification_delivery_info{}

Converts an Audit Trail Log to a readable format and prints it on stdio. LogName defaults to "snmpa_log". - LogFile defaults to "snmpa.log". + LogFile defaults to "snmpa.log".

The Block option indicates if the log should be blocked during conversion. This could be usefull when converting large logs (when otherwise the log could wrap during conversion). Defaults to true.

- See snmp:log_to_io +

See snmp:log_to_io for more info.

diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index b14c0e6afd..ab288fd020 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -1241,12 +1241,12 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Converts an Audit Trail Log to a readable text file. OutFile defaults to "./snmpm_log.txt". LogName defaults to "snmpm_log". - LogFile defaults to "snmpm.log". + LogFile defaults to "snmpm.log".

The Block argument indicates if the log should be blocked during conversion. This could be usefull when converting large logs (when otherwise the log could wrap during conversion). Defaults to true.

- See snmp:log_to_txt +

See snmp:log_to_txt for more info.

@@ -1280,12 +1280,12 @@ priv_key = [integer()] (length is 16 if priv = usmDESPrivProtocol | usmAesCfb1

Converts an Audit Trail Log to a readable format and prints it on stdio. LogName defaults to "snmpm_log". - LogFile defaults to "snmpm.log". + LogFile defaults to "snmpm.log".

The Block argument indicates if the log should be blocked during conversion. This could be usefull when converting large logs (when otherwise the log could wrap during conversion). Defaults to true.

- See snmp:log_to_io +

See snmp:log_to_io for more info.

-- cgit v1.2.3 From 75274f8ccca62b36aebf32040c432de221887867 Mon Sep 17 00:00:00 2001 From: Zandra Date: Fri, 11 Dec 2015 12:19:01 +0100 Subject: correct the snmp app up file --- lib/snmp/src/app/snmp.appup.src | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index f2936c0c1d..77418f920f 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -29,7 +29,7 @@ %% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} %% {add_module, snmpm_net_if_mt} [ - {"5.3", [{load_module, snmp_conf, soft_purge, soft_purge, []}]}, + {"5.2", [{load_module, snmp_conf, soft_purge, soft_purge, []}]}, {"5.1.2", [ % Only runtime dependencies change ]}, {"5.1.1", [{restart_application, snmp}]}, @@ -51,6 +51,7 @@ %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} [ + {"5.2", [{load_module, snmp_conf, soft_purge, soft_purge, []}]}, {"5.1.2", [ % Only runtime dependencies change ]}, {"5.1.1", [{restart_application, snmp}]}, -- cgit v1.2.3 From 4586435cd4ca0d3ad3aedd60f462aed8da589460 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Tue, 15 Dec 2015 09:43:08 +0100 Subject: Update version numbers --- lib/snmp/vsn.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index bf8e87fa0c..61a7d2207a 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -19,6 +19,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.2 +SNMP_VSN = 5.2.1 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From f4a0ae1736216feac5ae053610644bba2e12ed34 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Tue, 15 Dec 2015 09:45:27 +0100 Subject: Update release notes --- lib/snmp/doc/src/notes.xml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 94e73ddfca..9e7f13e126 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -34,7 +34,35 @@
-
SNMP 5.2 +
SNMP 5.2.1 + +
Fixed Bugs and Malfunctions + + +

+ Small documentation fixes

+

+ Own Id: OTP-13017

+
+
+
+ + +
Improvements and New Features + + +

+ Update configuration check of imask ( list of ones and + zeros) to allow the empty list.

+

+ Own Id: OTP-13101

+
+
+
+ +
+ +
SNMP 5.2
Improvements and New Features -- cgit v1.2.3 From 290dffee0f7af744c86d69234fb2d8ed1c4b8a6b Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Tue, 12 Jan 2016 10:20:41 +0100 Subject: Snmp agent vacmViewTreeFamily with non 'null' mask bugfix Adresses problems desciribed in http://erlang.org/pipermail/erlang-bugs/2015-April/004891.html http://erlang.org/pipermail/erlang-patches/2015-April/004766.html The original patch also suggested the following fix. However we need more information to be able to understand if this is correct or not, and it does not have priority at the moment for us to investigate. @@ -816,7 +816,7 @@ next_node(D, {tree, Tree, {table_entry, _MibName}}, "~n RevOidSoFar: ~p" "~n MibView: ~p", [size(Tree), Oid, RevOidSoFar, MibView]), OidSoFar = lists:reverse(RevOidSoFar), - case snmpa_acm:is_definitely_not_in_mib_view(OidSoFar, MibView) of + case snmpa_acm:is_definitely_not_in_mib_view(OidSoFar ++ Oid, MibView) of true -> ?vdebug("next_node(tree,table_entry) -> not in mib view",[]), false; --- lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 2 ++ lib/snmp/src/agent/snmpa_acm.erl | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl index 586b7c7171..9e6aa74d45 100644 --- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl +++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl @@ -34,6 +34,8 @@ %% Internal exports -export([check_vacm/1]). +%% +-export([emask2imask/1]). -include("snmp_types.hrl"). diff --git a/lib/snmp/src/agent/snmpa_acm.erl b/lib/snmp/src/agent/snmpa_acm.erl index 7327575846..0264c6a992 100644 --- a/lib/snmp/src/agent/snmpa_acm.erl +++ b/lib/snmp/src/agent/snmpa_acm.erl @@ -280,7 +280,7 @@ validate_mib_view(Oid, MibView) -> end. get_largest_family([{SubTree, Mask, Type} | T], Oid, Res) -> - case check_mask(Oid, SubTree, Mask) of + case check_mask(Oid, SubTree, snmp_view_based_acm_mib:emask2imask(Mask)) of true -> get_largest_family(T, Oid, add_res(length(SubTree), SubTree, Type, Res)); false -> get_largest_family(T, Oid, Res) @@ -345,7 +345,7 @@ validate_all_mib_view([], _MibView) -> %% intelligent. %%----------------------------------------------------------------- is_definitely_not_in_mib_view(Oid, [{SubTree, Mask,?view_included}|T]) -> - case check_maybe_mask(Oid, SubTree, Mask) of + case check_maybe_mask(Oid, SubTree, snmp_view_based_acm_mib:emask2imask(Mask)) of true -> false; false -> is_definitely_not_in_mib_view(Oid, T) end; -- cgit v1.2.3 From 6347b50048d721688bd0f7da2460a4d8f82275be Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Thu, 21 Jan 2016 11:39:06 +0100 Subject: snmp: Prepare for release As long as it is not prioritized to make an snmp_upgrade_SUITE it is not worth trying to do anything but restart_application --- lib/snmp/src/app/snmp.appup.src | 67 ++++++----------------------------------- 1 file changed, 10 insertions(+), 57 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 77418f920f..ca61782639 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -1,71 +1,24 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1999-2015. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%% -%% %CopyrightEnd% -%% - - +%% -*- erlang -*- {"%VSN%", %% ----- U p g r a d e ------------------------------------------------------- - %% Instruction examples: %% {restart_application, snmp} %% {load_module, snmp_pdus, soft_purge, soft_purge, []} %% {update, snmpa_local_db, soft, soft_purge, soft_purge, []} %% {add_module, snmpm_net_if_mt} [ - {"5.2", [{load_module, snmp_conf, soft_purge, soft_purge, []}]}, - {"5.1.2", [ % Only runtime dependencies change - ]}, - {"5.1.1", [{restart_application, snmp}]}, - {"5.1", [ % Only compiler changes - ]}, - {"5.0", [{restart_application, snmp}]}, - {"4.25.1", [{restart_application, snmp}]}, - {"4.25.0.1", [{restart_application, snmp}]}, - {"4.25.0.0.1", [{restart_application, snmp}]}, - {"4.25", [{restart_application, snmp}]}, - {"4.24.2", [{restart_application, snmp}]}, - {"4.24.1", [{restart_application, snmp}]}, - {"4.24", [{restart_application, snmp}]} - ], - + {<<"5\\..*">>, [{restart_application, snmp}]}, + {<<"4\\..*">>, [{restart_application, snmp}]} + ], + %% ------D o w n g r a d e --------------------------------------------------- - %% Instruction examples: %% {remove, {snmpm_net_if_mt, soft_purge, soft_purge}} - + [ - {"5.2", [{load_module, snmp_conf, soft_purge, soft_purge, []}]}, - {"5.1.2", [ % Only runtime dependencies change - ]}, - {"5.1.1", [{restart_application, snmp}]}, - {"5.1", [ % Only compiler changes - ]}, - {"5.0", [{restart_application, snmp}]}, - {"4.25.1", [{restart_application, snmp}]}, - {"4.25.0.1", [{restart_application, snmp}]}, - {"4.25.0.0.1", [{restart_application, snmp}]}, - {"4.25", [{restart_application, snmp}]}, - {"4.24.2", [{restart_application, snmp}]}, - {"4.24.1", [{restart_application, snmp}]}, - {"4.24", [{restart_application, snmp}]} - ] - -}. + {<<"5\\..*">>, [{restart_application, snmp}]}, + {<<"4\\..*">>, [{restart_application, snmp}]} + ] +}. -- cgit v1.2.3 From 03fcb7dabf8861e60ffab4121a909b347bccfec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 15 Feb 2016 15:33:12 +0100 Subject: Eliminate use of test_server.hrl and test_server_line.hrl As a first step to removing the test_server application as as its own separate application, change the inclusion of test_server.hrl to an inclusion of ct.hrl and remove the inclusion of test_server_line.hrl. --- lib/snmp/test/exp/snmp_agent_ms_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_mt_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_v1_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_v2_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_v3_test.erl | 2 +- lib/snmp/test/snmp_agent_mibs_test.erl | 2 +- lib/snmp/test/snmp_agent_nfilter_test.erl | 2 +- lib/snmp/test/snmp_agent_test.erl | 2 +- lib/snmp/test/snmp_agent_test_lib.erl | 2 +- lib/snmp/test/snmp_app_test.erl | 2 +- lib/snmp/test/snmp_compiler_test.erl | 2 +- lib/snmp/test/snmp_conf_test.erl | 2 +- lib/snmp/test/snmp_log_test.erl | 2 +- lib/snmp/test/snmp_manager_config_test.erl | 2 +- lib/snmp/test/snmp_manager_test.erl | 2 +- lib/snmp/test/snmp_manager_user.erl | 2 +- lib/snmp/test/snmp_manager_user_old.erl | 2 +- lib/snmp/test/snmp_manager_user_test.erl | 2 +- lib/snmp/test/snmp_manager_user_test_lib.erl | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/exp/snmp_agent_ms_test.erl b/lib/snmp/test/exp/snmp_agent_ms_test.erl index 3415fcc8e6..3010de0619 100644 --- a/lib/snmp/test/exp/snmp_agent_ms_test.erl +++ b/lib/snmp/test/exp/snmp_agent_ms_test.erl @@ -29,7 +29,7 @@ -define(application, snmp). -include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -define(SNMP_USE_V3, true). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/exp/snmp_agent_mt_test.erl b/lib/snmp/test/exp/snmp_agent_mt_test.erl index 89815e1044..71ae58baca 100644 --- a/lib/snmp/test/exp/snmp_agent_mt_test.erl +++ b/lib/snmp/test/exp/snmp_agent_mt_test.erl @@ -29,7 +29,7 @@ -define(application, snmp). -include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -define(SNMP_USE_V3, true). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/exp/snmp_agent_v1_test.erl b/lib/snmp/test/exp/snmp_agent_v1_test.erl index ec243747df..55045d536e 100644 --- a/lib/snmp/test/exp/snmp_agent_v1_test.erl +++ b/lib/snmp/test/exp/snmp_agent_v1_test.erl @@ -29,7 +29,7 @@ -define(application, snmp). -include_lib("kernel/include/file.hrl"). --include("test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -define(SNMP_USE_V3, true). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/exp/snmp_agent_v2_test.erl b/lib/snmp/test/exp/snmp_agent_v2_test.erl index ce95d0b5cd..6238a6c4bd 100644 --- a/lib/snmp/test/exp/snmp_agent_v2_test.erl +++ b/lib/snmp/test/exp/snmp_agent_v2_test.erl @@ -29,7 +29,7 @@ -define(application, snmp). -include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -define(SNMP_USE_V3, true). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/exp/snmp_agent_v3_test.erl b/lib/snmp/test/exp/snmp_agent_v3_test.erl index 1ba06209b2..af7cee9b96 100644 --- a/lib/snmp/test/exp/snmp_agent_v3_test.erl +++ b/lib/snmp/test/exp/snmp_agent_v3_test.erl @@ -29,7 +29,7 @@ -define(application, snmp). -include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -define(SNMP_USE_V3, true). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/snmp_agent_mibs_test.erl b/lib/snmp/test/snmp_agent_mibs_test.erl index a03c2b8534..2cbba14c74 100644 --- a/lib/snmp/test/snmp_agent_mibs_test.erl +++ b/lib/snmp/test/snmp_agent_mibs_test.erl @@ -31,7 +31,7 @@ %% Include files %%---------------------------------------------------------------------- --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -include_lib("snmp/include/snmp_types.hrl"). -include_lib("snmp/include/SNMP-COMMUNITY-MIB.hrl"). diff --git a/lib/snmp/test/snmp_agent_nfilter_test.erl b/lib/snmp/test/snmp_agent_nfilter_test.erl index 16a9903198..8aeef81333 100644 --- a/lib/snmp/test/snmp_agent_nfilter_test.erl +++ b/lib/snmp/test/snmp_agent_nfilter_test.erl @@ -26,7 +26,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 412d62c6a1..93968ede2e 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -421,7 +421,7 @@ -define(application, snmp). -include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -define(SNMP_USE_V3, true). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 8ea7b2e081..6f20254fcb 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -69,7 +69,7 @@ -export([wait/5, run/4]). -include_lib("kernel/include/file.hrl"). --include("test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -define(SNMP_USE_V3, true). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/snmp_app_test.erl b/lib/snmp/test/snmp_app_test.erl index 3b5b196ad6..6892d4aa93 100644 --- a/lib/snmp/test/snmp_app_test.erl +++ b/lib/snmp/test/snmp_app_test.erl @@ -45,7 +45,7 @@ -include_lib("kernel/include/file.hrl"). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). diff --git a/lib/snmp/test/snmp_compiler_test.erl b/lib/snmp/test/snmp_compiler_test.erl index c83c4e0fed..b08181191f 100644 --- a/lib/snmp/test/snmp_compiler_test.erl +++ b/lib/snmp/test/snmp_compiler_test.erl @@ -29,7 +29,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/snmp_conf_test.erl b/lib/snmp/test/snmp_conf_test.erl index 1d514cd1d2..73b471b107 100644 --- a/lib/snmp/test/snmp_conf_test.erl +++ b/lib/snmp/test/snmp_conf_test.erl @@ -27,7 +27,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -include_lib("snmp/include/STANDARD-MIB.hrl"). diff --git a/lib/snmp/test/snmp_log_test.erl b/lib/snmp/test/snmp_log_test.erl index b204522ee0..ae2581fb69 100644 --- a/lib/snmp/test/snmp_log_test.erl +++ b/lib/snmp/test/snmp_log_test.erl @@ -30,7 +30,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -define(SNMP_USE_V3, true). -include_lib("snmp/include/snmp_types.hrl"). diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index 47e150e8e8..8428b61e8a 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -32,7 +32,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -include_lib("snmp/src/manager/snmpm_usm.hrl"). diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index 3d05e5791f..a343dfdca7 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -32,7 +32,7 @@ %% Include files %%---------------------------------------------------------------------- --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -include("snmp_test_data/Test2.hrl"). diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index 256ea6a834..55b1e23b2e 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -31,7 +31,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include("test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). diff --git a/lib/snmp/test/snmp_manager_user_old.erl b/lib/snmp/test/snmp_manager_user_old.erl index 0f0f026eca..f317fa831c 100644 --- a/lib/snmp/test/snmp_manager_user_old.erl +++ b/lib/snmp/test/snmp_manager_user_old.erl @@ -30,7 +30,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include("test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). diff --git a/lib/snmp/test/snmp_manager_user_test.erl b/lib/snmp/test/snmp_manager_user_test.erl index a0cdcdef4d..64edfef4d5 100644 --- a/lib/snmp/test/snmp_manager_user_test.erl +++ b/lib/snmp/test/snmp_manager_user_test.erl @@ -27,7 +27,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). diff --git a/lib/snmp/test/snmp_manager_user_test_lib.erl b/lib/snmp/test/snmp_manager_user_test_lib.erl index a547f78efb..ea2c83a0da 100644 --- a/lib/snmp/test/snmp_manager_user_test_lib.erl +++ b/lib/snmp/test/snmp_manager_user_test_lib.erl @@ -30,7 +30,7 @@ %%---------------------------------------------------------------------- %% Include files %%---------------------------------------------------------------------- --include("test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include("snmp_test_lib.hrl"). -- cgit v1.2.3 From 4e1162bbdf88465a03da165c088ad1256b816956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 15 Feb 2016 16:04:32 +0100 Subject: Makefiles: Remove test_server from include path and code path Since no test suites includede test_server.hrl, there is no need to have test_server in the include path or code path. --- lib/snmp/test/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/snmp') diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index 3261982a32..8e895bc5b1 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -150,7 +150,6 @@ ERL_COMPILE_FLAGS += -I../../snmp/src/app \ -I../../snmp/src/misc \ -I../../snmp/src/agent \ -I../../snmp/src/manager \ - -I$(ERL_TOP)/lib/test_server/include \ -I../../snmp/include \ -Dsnmp_test_data=snmp_test_data \ -Dversion=\"$(VSN)$(PRE_VSN)\" \ -- cgit v1.2.3 From 0f8afe80c6582f7affd17f36dc9cb48cc7946713 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Mon, 14 Mar 2016 10:46:23 +0100 Subject: Prepare release --- lib/snmp/doc/src/notes.xml | 18 +++++++++++++++++- lib/snmp/vsn.mk | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 9e7f13e126..4693a744f5 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -34,7 +34,23 @@
-
SNMP 5.2.1 +
SNMP 5.2.2 + +
Fixed Bugs and Malfunctions + + +

+ Snmp agent now properly handles vacmViewTreeFamily + masks.

+

+ Own Id: OTP-13264

+
+
+
+ +
+ +
SNMP 5.2.1
Fixed Bugs and Malfunctions diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index 61a7d2207a..f60cbbfaa7 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -19,6 +19,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.2.1 +SNMP_VSN = 5.2.2 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 6664eed554974336909d3ffe03f20349cc4c38fd Mon Sep 17 00:00:00 2001 From: Henrik Nord Date: Tue, 15 Mar 2016 15:19:56 +0100 Subject: update copyright-year --- lib/snmp/Makefile | 2 +- lib/snmp/doc/src/Makefile | 2 +- lib/snmp/doc/src/book.xml | 2 +- lib/snmp/doc/src/files.mk | 2 +- lib/snmp/doc/src/notes.xml | 2 +- lib/snmp/doc/src/notes_history.xml | 2 +- lib/snmp/doc/src/part.xml | 2 +- lib/snmp/doc/src/part_notes.xml | 2 +- lib/snmp/doc/src/part_notes_history.xml | 2 +- lib/snmp/doc/src/ref_man.xml | 2 +- lib/snmp/doc/src/snmp.xml | 2 +- lib/snmp/doc/src/snmp_agent_config_files.xml | 2 +- lib/snmp/doc/src/snmp_agent_funct_descr.xml | 2 +- lib/snmp/doc/src/snmp_agent_netif.xml | 2 +- lib/snmp/doc/src/snmp_app.xml | 2 +- lib/snmp/doc/src/snmp_app_a.xml | 2 +- lib/snmp/doc/src/snmp_app_b.xml | 2 +- lib/snmp/doc/src/snmp_audit_trail_log.xml | 2 +- lib/snmp/doc/src/snmp_community_mib.xml | 2 +- lib/snmp/doc/src/snmp_config.xml | 2 +- lib/snmp/doc/src/snmp_def_instr_functions.xml | 2 +- lib/snmp/doc/src/snmp_framework_mib.xml | 2 +- lib/snmp/doc/src/snmp_generic.xml | 2 +- lib/snmp/doc/src/snmp_impl_example_agent.xml | 2 +- lib/snmp/doc/src/snmp_impl_example_manager.xml | 2 +- lib/snmp/doc/src/snmp_index.xml | 2 +- lib/snmp/doc/src/snmp_instr_functions.xml | 2 +- lib/snmp/doc/src/snmp_intro.xml | 2 +- lib/snmp/doc/src/snmp_manager_config_files.xml | 2 +- lib/snmp/doc/src/snmp_manager_funct_descr.xml | 2 +- lib/snmp/doc/src/snmp_manager_netif.xml | 2 +- lib/snmp/doc/src/snmp_mib_compiler.xml | 2 +- lib/snmp/doc/src/snmp_notification_mib.xml | 2 +- lib/snmp/doc/src/snmp_pdus.xml | 2 +- lib/snmp/doc/src/snmp_standard_mib.xml | 2 +- lib/snmp/doc/src/snmp_target_mib.xml | 2 +- lib/snmp/doc/src/snmp_user_based_sm_mib.xml | 2 +- lib/snmp/doc/src/snmp_view_based_acm_mib.xml | 2 +- lib/snmp/doc/src/snmpa.xml | 2 +- lib/snmp/doc/src/snmpa_conf.xml | 2 +- lib/snmp/doc/src/snmpa_discovery_handler.xml | 2 +- lib/snmp/doc/src/snmpa_error.xml | 2 +- lib/snmp/doc/src/snmpa_error_io.xml | 2 +- lib/snmp/doc/src/snmpa_error_logger.xml | 2 +- lib/snmp/doc/src/snmpa_error_report.xml | 2 +- lib/snmp/doc/src/snmpa_local_db.xml | 2 +- lib/snmp/doc/src/snmpa_mib_data.xml | 2 +- lib/snmp/doc/src/snmpa_mib_storage.xml | 2 +- lib/snmp/doc/src/snmpa_mpd.xml | 2 +- lib/snmp/doc/src/snmpa_network_interface.xml | 2 +- lib/snmp/doc/src/snmpa_network_interface_filter.xml | 2 +- lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml | 2 +- lib/snmp/doc/src/snmpa_notification_filter.xml | 2 +- lib/snmp/doc/src/snmpa_supervisor.xml | 2 +- lib/snmp/doc/src/snmpc.xml | 2 +- lib/snmp/doc/src/snmpc_cmd.xml | 2 +- lib/snmp/doc/src/snmpm.xml | 2 +- lib/snmp/doc/src/snmpm_conf.xml | 2 +- lib/snmp/doc/src/snmpm_mpd.xml | 2 +- lib/snmp/doc/src/snmpm_network_interface.xml | 2 +- lib/snmp/doc/src/snmpm_network_interface_filter.xml | 2 +- lib/snmp/doc/src/snmpm_user.xml | 2 +- lib/snmp/examples/Makefile | 2 +- lib/snmp/examples/ex1/Makefile | 2 +- lib/snmp/examples/ex2/Makefile | 2 +- lib/snmp/examples/ex2/snmp_ex2_manager.erl | 2 +- lib/snmp/examples/ex2/snmp_ex2_simple_standard_test.erl | 2 +- lib/snmp/examples/subdirs.mk | 2 +- lib/snmp/include/SNMPv2-TC.hrl | 2 +- lib/snmp/include/snmp_tables.hrl | 2 +- lib/snmp/include/snmp_types.hrl | 2 +- lib/snmp/mibs/Makefile.in | 2 +- lib/snmp/priv/conf/Makefile | 2 +- lib/snmp/priv/conf/agent/Makefile | 2 +- lib/snmp/priv/conf/agent/files.mk | 2 +- lib/snmp/priv/conf/manager/Makefile | 2 +- lib/snmp/priv/conf/manager/files.mk | 2 +- lib/snmp/priv/conf/subdirs.mk | 2 +- lib/snmp/src/Makefile | 2 +- lib/snmp/src/agent/Makefile | 2 +- lib/snmp/src/agent/depend.mk | 2 +- lib/snmp/src/agent/modules.mk | 2 +- lib/snmp/src/agent/snmp_community_mib.erl | 2 +- lib/snmp/src/agent/snmp_framework_mib.erl | 2 +- lib/snmp/src/agent/snmp_generic.erl | 2 +- lib/snmp/src/agent/snmp_generic_mnesia.erl | 2 +- lib/snmp/src/agent/snmp_index.erl | 2 +- lib/snmp/src/agent/snmp_notification_mib.erl | 2 +- lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 2 +- lib/snmp/src/agent/snmpa.erl | 2 +- lib/snmp/src/agent/snmpa_acm.erl | 2 +- lib/snmp/src/agent/snmpa_agent.erl | 2 +- lib/snmp/src/agent/snmpa_agent_sup.erl | 2 +- lib/snmp/src/agent/snmpa_app.erl | 2 +- lib/snmp/src/agent/snmpa_atl.hrl | 2 +- lib/snmp/src/agent/snmpa_authentication_service.erl | 2 +- lib/snmp/src/agent/snmpa_conf.erl | 2 +- lib/snmp/src/agent/snmpa_discovery_handler.erl | 2 +- lib/snmp/src/agent/snmpa_discovery_handler_default.erl | 2 +- lib/snmp/src/agent/snmpa_error.erl | 2 +- lib/snmp/src/agent/snmpa_error_io.erl | 2 +- lib/snmp/src/agent/snmpa_error_logger.erl | 2 +- lib/snmp/src/agent/snmpa_error_report.erl | 2 +- lib/snmp/src/agent/snmpa_general_db.erl | 2 +- lib/snmp/src/agent/snmpa_internal.hrl | 2 +- lib/snmp/src/agent/snmpa_local_db.erl | 2 +- lib/snmp/src/agent/snmpa_mib.erl | 2 +- lib/snmp/src/agent/snmpa_mib_data.erl | 2 +- lib/snmp/src/agent/snmpa_mib_data_ttln.erl | 2 +- lib/snmp/src/agent/snmpa_mib_data_tttn.erl | 2 +- lib/snmp/src/agent/snmpa_mib_lib.erl | 2 +- lib/snmp/src/agent/snmpa_mib_storage.erl | 2 +- lib/snmp/src/agent/snmpa_mib_storage_dets.erl | 2 +- lib/snmp/src/agent/snmpa_mib_storage_ets.erl | 2 +- lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl | 2 +- lib/snmp/src/agent/snmpa_misc_sup.erl | 2 +- lib/snmp/src/agent/snmpa_net_if_filter.erl | 2 +- lib/snmp/src/agent/snmpa_network_interface.erl | 2 +- lib/snmp/src/agent/snmpa_network_interface_filter.erl | 2 +- lib/snmp/src/agent/snmpa_notification_delivery_info_receiver.erl | 2 +- lib/snmp/src/agent/snmpa_notification_filter.erl | 2 +- lib/snmp/src/agent/snmpa_set.erl | 2 +- lib/snmp/src/agent/snmpa_set_lib.erl | 2 +- lib/snmp/src/agent/snmpa_set_mechanism.erl | 2 +- lib/snmp/src/agent/snmpa_supervisor.erl | 2 +- lib/snmp/src/agent/snmpa_svbl.erl | 2 +- lib/snmp/src/agent/snmpa_symbolic_store.erl | 2 +- lib/snmp/src/agent/snmpa_target_cache.erl | 2 +- lib/snmp/src/agent/snmpa_trap.erl | 2 +- lib/snmp/src/agent/snmpa_vacm.hrl | 2 +- lib/snmp/src/app/Makefile | 2 +- lib/snmp/src/app/depend.mk | 2 +- lib/snmp/src/app/modules.mk | 2 +- lib/snmp/src/app/snmp.erl | 2 +- lib/snmp/src/app/snmp_app.erl | 2 +- lib/snmp/src/app/snmp_app_sup.erl | 2 +- lib/snmp/src/app/snmp_internal.hrl | 2 +- lib/snmp/src/compile/Makefile | 2 +- lib/snmp/src/compile/depend.mk | 2 +- lib/snmp/src/compile/modules.mk | 2 +- lib/snmp/src/compile/snmpc.hrl | 2 +- lib/snmp/src/compile/snmpc.src | 2 +- lib/snmp/src/compile/snmpc_lib.erl | 2 +- lib/snmp/src/compile/snmpc_lib.hrl | 2 +- lib/snmp/src/compile/snmpc_mib_gram.yrl | 2 +- lib/snmp/src/compile/snmpc_mib_to_hrl.erl | 2 +- lib/snmp/src/compile/snmpc_misc.erl | 2 +- lib/snmp/src/compile/snmpc_misc.hrl | 2 +- lib/snmp/src/compile/snmpc_tok.erl | 2 +- lib/snmp/src/manager/Makefile | 2 +- lib/snmp/src/manager/depend.mk | 2 +- lib/snmp/src/manager/modules.mk | 2 +- lib/snmp/src/manager/snmpm.erl | 2 +- lib/snmp/src/manager/snmpm_atl.hrl | 2 +- lib/snmp/src/manager/snmpm_conf.erl | 2 +- lib/snmp/src/manager/snmpm_config.erl | 2 +- lib/snmp/src/manager/snmpm_internal.hrl | 2 +- lib/snmp/src/manager/snmpm_misc_sup.erl | 2 +- lib/snmp/src/manager/snmpm_net_if_filter.erl | 2 +- lib/snmp/src/manager/snmpm_net_if_mt.erl | 2 +- lib/snmp/src/manager/snmpm_network_interface.erl | 2 +- lib/snmp/src/manager/snmpm_network_interface_filter.erl | 2 +- lib/snmp/src/manager/snmpm_server_sup.erl | 2 +- lib/snmp/src/manager/snmpm_supervisor.erl | 2 +- lib/snmp/src/manager/snmpm_user.erl | 2 +- lib/snmp/src/manager/snmpm_user_default.erl | 2 +- lib/snmp/src/manager/snmpm_user_old.erl | 2 +- lib/snmp/src/manager/snmpm_usm.erl | 2 +- lib/snmp/src/manager/snmpm_usm.hrl | 2 +- lib/snmp/src/misc/Makefile | 2 +- lib/snmp/src/misc/depend.mk | 2 +- lib/snmp/src/misc/modules.mk | 2 +- lib/snmp/src/misc/snmp_conf.erl | 2 +- lib/snmp/src/misc/snmp_config.erl | 2 +- lib/snmp/src/misc/snmp_debug.hrl | 2 +- lib/snmp/src/misc/snmp_log.erl | 2 +- lib/snmp/src/misc/snmp_mini_mib.erl | 2 +- lib/snmp/src/misc/snmp_note_store.erl | 2 +- lib/snmp/src/misc/snmp_pdus.erl | 2 +- lib/snmp/src/misc/snmp_usm.erl | 2 +- lib/snmp/src/misc/snmp_verbosity.hrl | 2 +- lib/snmp/src/subdirs.mk | 2 +- lib/snmp/subdirs.mk | 2 +- lib/snmp/test/Makefile | 2 +- lib/snmp/test/exp/snmp_agent_bl_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_ms_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_mt_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_v1_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_v2_test.erl | 2 +- lib/snmp/test/exp/snmp_agent_v3_test.erl | 2 +- lib/snmp/test/klas3.erl | 2 +- lib/snmp/test/modules.mk | 2 +- lib/snmp/test/sa.erl | 2 +- lib/snmp/test/snmp_SUITE.erl | 2 +- lib/snmp/test/snmp_agent_mibs_test.erl | 2 +- lib/snmp/test/snmp_agent_nfilter_test.erl | 2 +- lib/snmp/test/snmp_agent_test.erl | 2 +- lib/snmp/test/snmp_agent_test_lib.erl | 2 +- lib/snmp/test/snmp_app_test.erl | 2 +- lib/snmp/test/snmp_appup_test.erl | 2 +- lib/snmp/test/snmp_compiler_test.erl | 2 +- lib/snmp/test/snmp_conf_test.erl | 2 +- lib/snmp/test/snmp_log_test.erl | 2 +- lib/snmp/test/snmp_manager_config_test.erl | 2 +- lib/snmp/test/snmp_manager_test.erl | 2 +- lib/snmp/test/snmp_manager_user.erl | 2 +- lib/snmp/test/snmp_manager_user_old.erl | 2 +- lib/snmp/test/snmp_manager_user_test.erl | 2 +- lib/snmp/test/snmp_manager_user_test_lib.erl | 2 +- lib/snmp/test/snmp_note_store_test.erl | 2 +- lib/snmp/test/snmp_pdus_test.erl | 2 +- lib/snmp/test/snmp_test_manager.erl | 2 +- lib/snmp/test/snmp_test_mgr_counter_server.erl | 2 +- lib/snmp/test/snmp_test_mgr_misc.erl | 2 +- lib/snmp/test/snmp_test_server.erl | 2 +- lib/snmp/test/snmp_test_suite.erl | 2 +- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 2 +- lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper | 2 +- lib/snmp/test/test1.erl | 2 +- lib/snmp/test/test2.erl | 2 +- lib/snmp/test/test_config/Makefile | 2 +- lib/snmp/test/test_config/modules.mk | 2 +- lib/snmp/test/test_config/snmp_test_config.erl | 2 +- lib/snmp/vsn.mk | 2 +- 224 files changed, 224 insertions(+), 224 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/Makefile b/lib/snmp/Makefile index ce739f3438..879f1b05c5 100644 --- a/lib/snmp/Makefile +++ b/lib/snmp/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1996-2011. All Rights Reserved. +# Copyright Ericsson AB 1996-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/doc/src/Makefile b/lib/snmp/doc/src/Makefile index 6d5b005e3e..9ea5dba0c5 100644 --- a/lib/snmp/doc/src/Makefile +++ b/lib/snmp/doc/src/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2012. All Rights Reserved. +# Copyright Ericsson AB 1997-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/doc/src/book.xml b/lib/snmp/doc/src/book.xml index 68e87b8afe..70d426453e 100644 --- a/lib/snmp/doc/src/book.xml +++ b/lib/snmp/doc/src/book.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/files.mk b/lib/snmp/doc/src/files.mk index fea8deee02..5aeae19105 100644 --- a/lib/snmp/doc/src/files.mk +++ b/lib/snmp/doc/src/files.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2001-2013. All Rights Reserved. +# Copyright Ericsson AB 2001-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 4693a744f5..b9dc5e4117 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -4,7 +4,7 @@
- 19962014 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/notes_history.xml b/lib/snmp/doc/src/notes_history.xml index a9726b97dc..cae9630ff9 100644 --- a/lib/snmp/doc/src/notes_history.xml +++ b/lib/snmp/doc/src/notes_history.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/part.xml b/lib/snmp/doc/src/part.xml index 5ce7c52918..5ac6dc3917 100644 --- a/lib/snmp/doc/src/part.xml +++ b/lib/snmp/doc/src/part.xml @@ -4,7 +4,7 @@
- 19962013 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/part_notes.xml b/lib/snmp/doc/src/part_notes.xml index 9535299d74..d149044169 100644 --- a/lib/snmp/doc/src/part_notes.xml +++ b/lib/snmp/doc/src/part_notes.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/part_notes_history.xml b/lib/snmp/doc/src/part_notes_history.xml index 1edc13e29e..aa5276dc94 100644 --- a/lib/snmp/doc/src/part_notes_history.xml +++ b/lib/snmp/doc/src/part_notes_history.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/ref_man.xml b/lib/snmp/doc/src/ref_man.xml index 1b381bc97b..b8559dda62 100644 --- a/lib/snmp/doc/src/ref_man.xml +++ b/lib/snmp/doc/src/ref_man.xml @@ -4,7 +4,7 @@
- 19962013 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp.xml b/lib/snmp/doc/src/snmp.xml index b8e8d43fc8..801193675c 100644 --- a/lib/snmp/doc/src/snmp.xml +++ b/lib/snmp/doc/src/snmp.xml @@ -4,7 +4,7 @@
- 19962013 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_agent_config_files.xml b/lib/snmp/doc/src/snmp_agent_config_files.xml index 1147ff81d5..e1a4c143cd 100644 --- a/lib/snmp/doc/src/snmp_agent_config_files.xml +++ b/lib/snmp/doc/src/snmp_agent_config_files.xml @@ -4,7 +4,7 @@
- 19972014 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_agent_funct_descr.xml b/lib/snmp/doc/src/snmp_agent_funct_descr.xml index 9d2226510e..fdcab79646 100644 --- a/lib/snmp/doc/src/snmp_agent_funct_descr.xml +++ b/lib/snmp/doc/src/snmp_agent_funct_descr.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_agent_netif.xml b/lib/snmp/doc/src/snmp_agent_netif.xml index 9583f1f521..a8dea5ab7b 100644 --- a/lib/snmp/doc/src/snmp_agent_netif.xml +++ b/lib/snmp/doc/src/snmp_agent_netif.xml @@ -4,7 +4,7 @@
- 19972014 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_app.xml b/lib/snmp/doc/src/snmp_app.xml index 39aac8e7d7..d5ac97ef15 100644 --- a/lib/snmp/doc/src/snmp_app.xml +++ b/lib/snmp/doc/src/snmp_app.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_app_a.xml b/lib/snmp/doc/src/snmp_app_a.xml index 551876ee92..c6d7ae2f53 100644 --- a/lib/snmp/doc/src/snmp_app_a.xml +++ b/lib/snmp/doc/src/snmp_app_a.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_app_b.xml b/lib/snmp/doc/src/snmp_app_b.xml index 263db2a791..2ef94f0fde 100644 --- a/lib/snmp/doc/src/snmp_app_b.xml +++ b/lib/snmp/doc/src/snmp_app_b.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_audit_trail_log.xml b/lib/snmp/doc/src/snmp_audit_trail_log.xml index c178a995f4..4fcdceb321 100644 --- a/lib/snmp/doc/src/snmp_audit_trail_log.xml +++ b/lib/snmp/doc/src/snmp_audit_trail_log.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_community_mib.xml b/lib/snmp/doc/src/snmp_community_mib.xml index 571ff7d197..61dea05950 100644 --- a/lib/snmp/doc/src/snmp_community_mib.xml +++ b/lib/snmp/doc/src/snmp_community_mib.xml @@ -4,7 +4,7 @@
- 19992013 + 19992016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_config.xml b/lib/snmp/doc/src/snmp_config.xml index a085252d90..6d4129dd06 100644 --- a/lib/snmp/doc/src/snmp_config.xml +++ b/lib/snmp/doc/src/snmp_config.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_def_instr_functions.xml b/lib/snmp/doc/src/snmp_def_instr_functions.xml index 2317f27196..3445648de2 100644 --- a/lib/snmp/doc/src/snmp_def_instr_functions.xml +++ b/lib/snmp/doc/src/snmp_def_instr_functions.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_framework_mib.xml b/lib/snmp/doc/src/snmp_framework_mib.xml index 9fba76baab..64e5df6ff5 100644 --- a/lib/snmp/doc/src/snmp_framework_mib.xml +++ b/lib/snmp/doc/src/snmp_framework_mib.xml @@ -4,7 +4,7 @@
- 19992013 + 19992016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_generic.xml b/lib/snmp/doc/src/snmp_generic.xml index 75271fb002..44762dec59 100644 --- a/lib/snmp/doc/src/snmp_generic.xml +++ b/lib/snmp/doc/src/snmp_generic.xml @@ -4,7 +4,7 @@
- 19962013 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_impl_example_agent.xml b/lib/snmp/doc/src/snmp_impl_example_agent.xml index 912f339e0d..a86006a0a7 100644 --- a/lib/snmp/doc/src/snmp_impl_example_agent.xml +++ b/lib/snmp/doc/src/snmp_impl_example_agent.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_impl_example_manager.xml b/lib/snmp/doc/src/snmp_impl_example_manager.xml index 789c6c169e..aca8d43c95 100644 --- a/lib/snmp/doc/src/snmp_impl_example_manager.xml +++ b/lib/snmp/doc/src/snmp_impl_example_manager.xml @@ -4,7 +4,7 @@
- 20062013 + 20062016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_index.xml b/lib/snmp/doc/src/snmp_index.xml index 74792629b6..646e9661a3 100644 --- a/lib/snmp/doc/src/snmp_index.xml +++ b/lib/snmp/doc/src/snmp_index.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_instr_functions.xml b/lib/snmp/doc/src/snmp_instr_functions.xml index 0dc76d3603..38512b72d0 100644 --- a/lib/snmp/doc/src/snmp_instr_functions.xml +++ b/lib/snmp/doc/src/snmp_instr_functions.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_intro.xml b/lib/snmp/doc/src/snmp_intro.xml index 691bc162ee..ec3f2af956 100644 --- a/lib/snmp/doc/src/snmp_intro.xml +++ b/lib/snmp/doc/src/snmp_intro.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_manager_config_files.xml b/lib/snmp/doc/src/snmp_manager_config_files.xml index ca7bc3bfb3..c7c423f5eb 100644 --- a/lib/snmp/doc/src/snmp_manager_config_files.xml +++ b/lib/snmp/doc/src/snmp_manager_config_files.xml @@ -4,7 +4,7 @@
- 20042014 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_manager_funct_descr.xml b/lib/snmp/doc/src/snmp_manager_funct_descr.xml index 30df618eb6..b2da01ae32 100644 --- a/lib/snmp/doc/src/snmp_manager_funct_descr.xml +++ b/lib/snmp/doc/src/snmp_manager_funct_descr.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_manager_netif.xml b/lib/snmp/doc/src/snmp_manager_netif.xml index 98d4e7fd96..0dcf2a0255 100644 --- a/lib/snmp/doc/src/snmp_manager_netif.xml +++ b/lib/snmp/doc/src/snmp_manager_netif.xml @@ -4,7 +4,7 @@
- 20042014 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_mib_compiler.xml b/lib/snmp/doc/src/snmp_mib_compiler.xml index ad93cc86c4..285d11fce9 100644 --- a/lib/snmp/doc/src/snmp_mib_compiler.xml +++ b/lib/snmp/doc/src/snmp_mib_compiler.xml @@ -4,7 +4,7 @@
- 19972013 + 19972016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_notification_mib.xml b/lib/snmp/doc/src/snmp_notification_mib.xml index cbb117d71a..d2e288ec15 100644 --- a/lib/snmp/doc/src/snmp_notification_mib.xml +++ b/lib/snmp/doc/src/snmp_notification_mib.xml @@ -4,7 +4,7 @@
- 19982013 + 19982016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_pdus.xml b/lib/snmp/doc/src/snmp_pdus.xml index 82900c2f59..1d086e6f48 100644 --- a/lib/snmp/doc/src/snmp_pdus.xml +++ b/lib/snmp/doc/src/snmp_pdus.xml @@ -4,7 +4,7 @@
- 19962013 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_standard_mib.xml b/lib/snmp/doc/src/snmp_standard_mib.xml index bc3abf5fa8..35efbba483 100644 --- a/lib/snmp/doc/src/snmp_standard_mib.xml +++ b/lib/snmp/doc/src/snmp_standard_mib.xml @@ -4,7 +4,7 @@
- 19962013 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_target_mib.xml b/lib/snmp/doc/src/snmp_target_mib.xml index fa85d586b9..c3bcd3b4e3 100644 --- a/lib/snmp/doc/src/snmp_target_mib.xml +++ b/lib/snmp/doc/src/snmp_target_mib.xml @@ -4,7 +4,7 @@
- 19982014 + 19982016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_user_based_sm_mib.xml b/lib/snmp/doc/src/snmp_user_based_sm_mib.xml index ffff1b6b4f..cc376ac118 100644 --- a/lib/snmp/doc/src/snmp_user_based_sm_mib.xml +++ b/lib/snmp/doc/src/snmp_user_based_sm_mib.xml @@ -4,7 +4,7 @@
- 19992013 + 19992016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmp_view_based_acm_mib.xml b/lib/snmp/doc/src/snmp_view_based_acm_mib.xml index bdd669b8b2..fdad735e71 100644 --- a/lib/snmp/doc/src/snmp_view_based_acm_mib.xml +++ b/lib/snmp/doc/src/snmp_view_based_acm_mib.xml @@ -4,7 +4,7 @@
- 19992013 + 19992016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa.xml b/lib/snmp/doc/src/snmpa.xml index c84eeec524..d756ff7a65 100644 --- a/lib/snmp/doc/src/snmpa.xml +++ b/lib/snmp/doc/src/snmpa.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_conf.xml b/lib/snmp/doc/src/snmpa_conf.xml index 2f9579261a..503e44a6a2 100644 --- a/lib/snmp/doc/src/snmpa_conf.xml +++ b/lib/snmp/doc/src/snmpa_conf.xml @@ -4,7 +4,7 @@
- 20062014 + 20062016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_discovery_handler.xml b/lib/snmp/doc/src/snmpa_discovery_handler.xml index ccc69112c1..0ea72a880c 100644 --- a/lib/snmp/doc/src/snmpa_discovery_handler.xml +++ b/lib/snmp/doc/src/snmpa_discovery_handler.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_error.xml b/lib/snmp/doc/src/snmpa_error.xml index cfebb36ed3..7cc4a3513d 100644 --- a/lib/snmp/doc/src/snmpa_error.xml +++ b/lib/snmp/doc/src/snmpa_error.xml @@ -4,7 +4,7 @@
- 20022013 + 20022016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_error_io.xml b/lib/snmp/doc/src/snmpa_error_io.xml index 908dcc974d..bcb2688646 100644 --- a/lib/snmp/doc/src/snmpa_error_io.xml +++ b/lib/snmp/doc/src/snmpa_error_io.xml @@ -4,7 +4,7 @@
- 20022013 + 20022016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_error_logger.xml b/lib/snmp/doc/src/snmpa_error_logger.xml index c39e07ed5f..4feb2e7f32 100644 --- a/lib/snmp/doc/src/snmpa_error_logger.xml +++ b/lib/snmp/doc/src/snmpa_error_logger.xml @@ -4,7 +4,7 @@
- 19962013 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_error_report.xml b/lib/snmp/doc/src/snmpa_error_report.xml index 5c91df9e57..282d9b4e59 100644 --- a/lib/snmp/doc/src/snmpa_error_report.xml +++ b/lib/snmp/doc/src/snmpa_error_report.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_local_db.xml b/lib/snmp/doc/src/snmpa_local_db.xml index feca939124..ac8d466ab3 100644 --- a/lib/snmp/doc/src/snmpa_local_db.xml +++ b/lib/snmp/doc/src/snmpa_local_db.xml @@ -4,7 +4,7 @@
- 19962013 + 19962016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_mib_data.xml b/lib/snmp/doc/src/snmpa_mib_data.xml index 1ef71d5cbe..1a73c9b634 100644 --- a/lib/snmp/doc/src/snmpa_mib_data.xml +++ b/lib/snmp/doc/src/snmpa_mib_data.xml @@ -4,7 +4,7 @@
- 20132014 + 20132016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_mib_storage.xml b/lib/snmp/doc/src/snmpa_mib_storage.xml index a4ce5891d2..58ce2167ec 100644 --- a/lib/snmp/doc/src/snmpa_mib_storage.xml +++ b/lib/snmp/doc/src/snmpa_mib_storage.xml @@ -4,7 +4,7 @@
- 20132014 + 20132016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_mpd.xml b/lib/snmp/doc/src/snmpa_mpd.xml index 4c2f12020b..a39c087c20 100644 --- a/lib/snmp/doc/src/snmpa_mpd.xml +++ b/lib/snmp/doc/src/snmpa_mpd.xml @@ -4,7 +4,7 @@
- 19992014 + 19992016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_network_interface.xml b/lib/snmp/doc/src/snmpa_network_interface.xml index ffa006768d..d4d4989e90 100644 --- a/lib/snmp/doc/src/snmpa_network_interface.xml +++ b/lib/snmp/doc/src/snmpa_network_interface.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_network_interface_filter.xml b/lib/snmp/doc/src/snmpa_network_interface_filter.xml index 0c26914c91..7cd08f8935 100644 --- a/lib/snmp/doc/src/snmpa_network_interface_filter.xml +++ b/lib/snmp/doc/src/snmpa_network_interface_filter.xml @@ -4,7 +4,7 @@
- 20072014 + 20072016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml b/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml index da0328402b..cbae158544 100644 --- a/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml +++ b/lib/snmp/doc/src/snmpa_notification_delivery_info_receiver.xml @@ -5,7 +5,7 @@
2008 - 2014 + 2016 Ericsson AB, All Rights Reserved diff --git a/lib/snmp/doc/src/snmpa_notification_filter.xml b/lib/snmp/doc/src/snmpa_notification_filter.xml index b2c9a0912e..0f16ba4440 100644 --- a/lib/snmp/doc/src/snmpa_notification_filter.xml +++ b/lib/snmp/doc/src/snmpa_notification_filter.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpa_supervisor.xml b/lib/snmp/doc/src/snmpa_supervisor.xml index d272118b04..86c6fbc350 100644 --- a/lib/snmp/doc/src/snmpa_supervisor.xml +++ b/lib/snmp/doc/src/snmpa_supervisor.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpc.xml b/lib/snmp/doc/src/snmpc.xml index fb526ee4dc..aba51bb500 100644 --- a/lib/snmp/doc/src/snmpc.xml +++ b/lib/snmp/doc/src/snmpc.xml @@ -4,7 +4,7 @@
- 20042013 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpc_cmd.xml b/lib/snmp/doc/src/snmpc_cmd.xml index 2c906a2a51..e4e710a58c 100644 --- a/lib/snmp/doc/src/snmpc_cmd.xml +++ b/lib/snmp/doc/src/snmpc_cmd.xml @@ -4,7 +4,7 @@
- 20112013 + 20112016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm.xml b/lib/snmp/doc/src/snmpm.xml index ab288fd020..4818aeb697 100644 --- a/lib/snmp/doc/src/snmpm.xml +++ b/lib/snmp/doc/src/snmpm.xml @@ -4,7 +4,7 @@
- 20042014 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_conf.xml b/lib/snmp/doc/src/snmpm_conf.xml index 815ad2e87a..a3097e5f7e 100644 --- a/lib/snmp/doc/src/snmpm_conf.xml +++ b/lib/snmp/doc/src/snmpm_conf.xml @@ -4,7 +4,7 @@
- 20062014 + 20062016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_mpd.xml b/lib/snmp/doc/src/snmpm_mpd.xml index 4efaafd578..08276e4b30 100644 --- a/lib/snmp/doc/src/snmpm_mpd.xml +++ b/lib/snmp/doc/src/snmpm_mpd.xml @@ -4,7 +4,7 @@
- 20042014 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_network_interface.xml b/lib/snmp/doc/src/snmpm_network_interface.xml index 6b4598ed88..73892aa2e8 100644 --- a/lib/snmp/doc/src/snmpm_network_interface.xml +++ b/lib/snmp/doc/src/snmpm_network_interface.xml @@ -4,7 +4,7 @@
- 20042014 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_network_interface_filter.xml b/lib/snmp/doc/src/snmpm_network_interface_filter.xml index 2706f6df09..742cd53fc6 100644 --- a/lib/snmp/doc/src/snmpm_network_interface_filter.xml +++ b/lib/snmp/doc/src/snmpm_network_interface_filter.xml @@ -4,7 +4,7 @@
- 20072014 + 20072016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/doc/src/snmpm_user.xml b/lib/snmp/doc/src/snmpm_user.xml index cb2ecb0c58..87ae1d224a 100644 --- a/lib/snmp/doc/src/snmpm_user.xml +++ b/lib/snmp/doc/src/snmpm_user.xml @@ -4,7 +4,7 @@
- 20042014 + 20042016 Ericsson AB. All Rights Reserved. diff --git a/lib/snmp/examples/Makefile b/lib/snmp/examples/Makefile index 854a6e6f8d..39ea5f74db 100644 --- a/lib/snmp/examples/Makefile +++ b/lib/snmp/examples/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/examples/ex1/Makefile b/lib/snmp/examples/ex1/Makefile index 2631fdd7ff..a3d02ea778 100644 --- a/lib/snmp/examples/ex1/Makefile +++ b/lib/snmp/examples/ex1/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1996-2012. All Rights Reserved. +# Copyright Ericsson AB 1996-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/examples/ex2/Makefile b/lib/snmp/examples/ex2/Makefile index 9259a59c46..624a1df2ee 100644 --- a/lib/snmp/examples/ex2/Makefile +++ b/lib/snmp/examples/ex2/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2006-2012. All Rights Reserved. +# Copyright Ericsson AB 2006-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/examples/ex2/snmp_ex2_manager.erl b/lib/snmp/examples/ex2/snmp_ex2_manager.erl index 38189fa518..939f9f2b4d 100644 --- a/lib/snmp/examples/ex2/snmp_ex2_manager.erl +++ b/lib/snmp/examples/ex2/snmp_ex2_manager.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2013. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/examples/ex2/snmp_ex2_simple_standard_test.erl b/lib/snmp/examples/ex2/snmp_ex2_simple_standard_test.erl index fecf817fa0..e8f748c337 100644 --- a/lib/snmp/examples/ex2/snmp_ex2_simple_standard_test.erl +++ b/lib/snmp/examples/ex2/snmp_ex2_simple_standard_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2010. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/examples/subdirs.mk b/lib/snmp/examples/subdirs.mk index 62cba219cd..b6a1709369 100644 --- a/lib/snmp/examples/subdirs.mk +++ b/lib/snmp/examples/subdirs.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/include/SNMPv2-TC.hrl b/lib/snmp/include/SNMPv2-TC.hrl index 54ead21a35..21797f9227 100644 --- a/lib/snmp/include/SNMPv2-TC.hrl +++ b/lib/snmp/include/SNMPv2-TC.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/include/snmp_tables.hrl b/lib/snmp/include/snmp_tables.hrl index 888539a282..d6fa00ca43 100644 --- a/lib/snmp/include/snmp_tables.hrl +++ b/lib/snmp/include/snmp_tables.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/include/snmp_types.hrl b/lib/snmp/include/snmp_types.hrl index 0a7379c790..ffe30996dc 100644 --- a/lib/snmp/include/snmp_types.hrl +++ b/lib/snmp/include/snmp_types.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/mibs/Makefile.in b/lib/snmp/mibs/Makefile.in index eea0d4aa63..2350194077 100644 --- a/lib/snmp/mibs/Makefile.in +++ b/lib/snmp/mibs/Makefile.in @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1996-2012. All Rights Reserved. +# Copyright Ericsson AB 1996-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/priv/conf/Makefile b/lib/snmp/priv/conf/Makefile index 854a6e6f8d..39ea5f74db 100644 --- a/lib/snmp/priv/conf/Makefile +++ b/lib/snmp/priv/conf/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/priv/conf/agent/Makefile b/lib/snmp/priv/conf/agent/Makefile index 5e9b922d04..e905f55999 100644 --- a/lib/snmp/priv/conf/agent/Makefile +++ b/lib/snmp/priv/conf/agent/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1996-2012. All Rights Reserved. +# Copyright Ericsson AB 1996-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/priv/conf/agent/files.mk b/lib/snmp/priv/conf/agent/files.mk index 8e6c80f3a2..bccf162ef5 100644 --- a/lib/snmp/priv/conf/agent/files.mk +++ b/lib/snmp/priv/conf/agent/files.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2001-2009. All Rights Reserved. +# Copyright Ericsson AB 2001-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/priv/conf/manager/Makefile b/lib/snmp/priv/conf/manager/Makefile index b88ed0a11c..27024c171f 100644 --- a/lib/snmp/priv/conf/manager/Makefile +++ b/lib/snmp/priv/conf/manager/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2012. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/priv/conf/manager/files.mk b/lib/snmp/priv/conf/manager/files.mk index 9ead147aff..db52a3712f 100644 --- a/lib/snmp/priv/conf/manager/files.mk +++ b/lib/snmp/priv/conf/manager/files.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/priv/conf/subdirs.mk b/lib/snmp/priv/conf/subdirs.mk index 7d8d40887f..c17f5db483 100644 --- a/lib/snmp/priv/conf/subdirs.mk +++ b/lib/snmp/priv/conf/subdirs.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/Makefile b/lib/snmp/src/Makefile index 854a6e6f8d..39ea5f74db 100644 --- a/lib/snmp/src/Makefile +++ b/lib/snmp/src/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/Makefile b/lib/snmp/src/agent/Makefile index 89037b3ea8..2943a4d550 100644 --- a/lib/snmp/src/agent/Makefile +++ b/lib/snmp/src/agent/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1996-2012. All Rights Reserved. +# Copyright Ericsson AB 1996-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/depend.mk b/lib/snmp/src/agent/depend.mk index e9964f5151..8eba50fa3b 100644 --- a/lib/snmp/src/agent/depend.mk +++ b/lib/snmp/src/agent/depend.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2013. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/modules.mk b/lib/snmp/src/agent/modules.mk index b2f1d5cc93..0f8615588a 100644 --- a/lib/snmp/src/agent/modules.mk +++ b/lib/snmp/src/agent/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2013. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmp_community_mib.erl b/lib/snmp/src/agent/snmp_community_mib.erl index dbd9f468d7..9fd7b30f9f 100644 --- a/lib/snmp/src/agent/snmp_community_mib.erl +++ b/lib/snmp/src/agent/snmp_community_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2014. All Rights Reserved. +%% Copyright Ericsson AB 1999-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index 80ebba6c90..7ea4f0ed97 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2014. All Rights Reserved. +%% Copyright Ericsson AB 1999-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmp_generic.erl b/lib/snmp/src/agent/snmp_generic.erl index ec6b7161ea..fc23e16ef1 100644 --- a/lib/snmp/src/agent/snmp_generic.erl +++ b/lib/snmp/src/agent/snmp_generic.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmp_generic_mnesia.erl b/lib/snmp/src/agent/snmp_generic_mnesia.erl index 051566e43d..131b9b0368 100644 --- a/lib/snmp/src/agent/snmp_generic_mnesia.erl +++ b/lib/snmp/src/agent/snmp_generic_mnesia.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmp_index.erl b/lib/snmp/src/agent/snmp_index.erl index 5e03c530f1..38b39a9b7e 100644 --- a/lib/snmp/src/agent/snmp_index.erl +++ b/lib/snmp/src/agent/snmp_index.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmp_notification_mib.erl b/lib/snmp/src/agent/snmp_notification_mib.erl index 15ecbcc5d9..3f1ba5d8b3 100644 --- a/lib/snmp/src/agent/snmp_notification_mib.erl +++ b/lib/snmp/src/agent/snmp_notification_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2014. All Rights Reserved. +%% Copyright Ericsson AB 1998-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl index 9e6aa74d45..02415e8036 100644 --- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl +++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2015. All Rights Reserved. +%% Copyright Ericsson AB 1999-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 7c70404e02..ff7be54283 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_acm.erl b/lib/snmp/src/agent/snmpa_acm.erl index 0264c6a992..de67df8a06 100644 --- a/lib/snmp/src/agent/snmpa_acm.erl +++ b/lib/snmp/src/agent/snmpa_acm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2011. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_agent.erl b/lib/snmp/src/agent/snmpa_agent.erl index bada50a820..458b88359b 100644 --- a/lib/snmp/src/agent/snmpa_agent.erl +++ b/lib/snmp/src/agent/snmpa_agent.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_agent_sup.erl b/lib/snmp/src/agent/snmpa_agent_sup.erl index f6f218366f..0a5116b2d0 100644 --- a/lib/snmp/src/agent/snmpa_agent_sup.erl +++ b/lib/snmp/src/agent/snmpa_agent_sup.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2013. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_app.erl b/lib/snmp/src/agent/snmpa_app.erl index 89d1efd0a1..86ff145e93 100644 --- a/lib/snmp/src/agent/snmpa_app.erl +++ b/lib/snmp/src/agent/snmpa_app.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_atl.hrl b/lib/snmp/src/agent/snmpa_atl.hrl index 06d36dbb06..d07c850891 100644 --- a/lib/snmp/src/agent/snmpa_atl.hrl +++ b/lib/snmp/src/agent/snmpa_atl.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_authentication_service.erl b/lib/snmp/src/agent/snmpa_authentication_service.erl index 36845c83b2..e4238a8384 100644 --- a/lib/snmp/src/agent/snmpa_authentication_service.erl +++ b/lib/snmp/src/agent/snmpa_authentication_service.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl index ebefa945c5..94325a8ed6 100644 --- a/lib/snmp/src/agent/snmpa_conf.erl +++ b/lib/snmp/src/agent/snmpa_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2014. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_discovery_handler.erl b/lib/snmp/src/agent/snmpa_discovery_handler.erl index 7f84601200..ffdd6aca1e 100644 --- a/lib/snmp/src/agent/snmpa_discovery_handler.erl +++ b/lib/snmp/src/agent/snmpa_discovery_handler.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009. All Rights Reserved. +%% Copyright Ericsson AB 2009-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_discovery_handler_default.erl b/lib/snmp/src/agent/snmpa_discovery_handler_default.erl index 89b30b3054..8bd8d1973e 100644 --- a/lib/snmp/src/agent/snmpa_discovery_handler_default.erl +++ b/lib/snmp/src/agent/snmpa_discovery_handler_default.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009. All Rights Reserved. +%% Copyright Ericsson AB 2009-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_error.erl b/lib/snmp/src/agent/snmpa_error.erl index 06d61de517..804c850593 100644 --- a/lib/snmp/src/agent/snmpa_error.erl +++ b/lib/snmp/src/agent/snmpa_error.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2002-2009. All Rights Reserved. +%% Copyright Ericsson AB 2002-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_error_io.erl b/lib/snmp/src/agent/snmpa_error_io.erl index 848869188f..e961d4b525 100644 --- a/lib/snmp/src/agent/snmpa_error_io.erl +++ b/lib/snmp/src/agent/snmpa_error_io.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2002-2009. All Rights Reserved. +%% Copyright Ericsson AB 2002-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_error_logger.erl b/lib/snmp/src/agent/snmpa_error_logger.erl index 50165d79cd..d52a3e48ac 100644 --- a/lib/snmp/src/agent/snmpa_error_logger.erl +++ b/lib/snmp/src/agent/snmpa_error_logger.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_error_report.erl b/lib/snmp/src/agent/snmpa_error_report.erl index 6f3508c8b7..8f28eac653 100644 --- a/lib/snmp/src/agent/snmpa_error_report.erl +++ b/lib/snmp/src/agent/snmpa_error_report.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_general_db.erl b/lib/snmp/src/agent/snmpa_general_db.erl index 7892a4c033..431302b6cc 100644 --- a/lib/snmp/src/agent/snmpa_general_db.erl +++ b/lib/snmp/src/agent/snmpa_general_db.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2010. All Rights Reserved. +%% Copyright Ericsson AB 2000-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_internal.hrl b/lib/snmp/src/agent/snmpa_internal.hrl index b340f0d262..fe3ba9f39e 100644 --- a/lib/snmp/src/agent/snmpa_internal.hrl +++ b/lib/snmp/src/agent/snmpa_internal.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2012. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_local_db.erl b/lib/snmp/src/agent/snmpa_local_db.erl index feab855b2e..eb67b9cd6f 100644 --- a/lib/snmp/src/agent/snmpa_local_db.erl +++ b/lib/snmp/src/agent/snmpa_local_db.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib.erl b/lib/snmp/src/agent/snmpa_mib.erl index 2f58922e2c..ab1098514c 100644 --- a/lib/snmp/src/agent/snmpa_mib.erl +++ b/lib/snmp/src/agent/snmpa_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib_data.erl b/lib/snmp/src/agent/snmpa_mib_data.erl index 5614a431d6..fcbc0465c8 100644 --- a/lib/snmp/src/agent/snmpa_mib_data.erl +++ b/lib/snmp/src/agent/snmpa_mib_data.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib_data_ttln.erl b/lib/snmp/src/agent/snmpa_mib_data_ttln.erl index 312372b41b..959230b1dd 100644 --- a/lib/snmp/src/agent/snmpa_mib_data_ttln.erl +++ b/lib/snmp/src/agent/snmpa_mib_data_ttln.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2013-2013. All Rights Reserved. +%% Copyright Ericsson AB 2013-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib_data_tttn.erl b/lib/snmp/src/agent/snmpa_mib_data_tttn.erl index 849c9b37d9..9b4493a03f 100644 --- a/lib/snmp/src/agent/snmpa_mib_data_tttn.erl +++ b/lib/snmp/src/agent/snmpa_mib_data_tttn.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib_lib.erl b/lib/snmp/src/agent/snmpa_mib_lib.erl index 3006b3c0a8..ecdf968458 100644 --- a/lib/snmp/src/agent/snmpa_mib_lib.erl +++ b/lib/snmp/src/agent/snmpa_mib_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2012. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib_storage.erl b/lib/snmp/src/agent/snmpa_mib_storage.erl index ea166ed79c..ed0607fb84 100644 --- a/lib/snmp/src/agent/snmpa_mib_storage.erl +++ b/lib/snmp/src/agent/snmpa_mib_storage.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2013-2013. All Rights Reserved. +%% Copyright Ericsson AB 2013-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib_storage_dets.erl b/lib/snmp/src/agent/snmpa_mib_storage_dets.erl index 53c69b8d45..2459b6bc3e 100644 --- a/lib/snmp/src/agent/snmpa_mib_storage_dets.erl +++ b/lib/snmp/src/agent/snmpa_mib_storage_dets.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2013-2013. All Rights Reserved. +%% Copyright Ericsson AB 2013-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib_storage_ets.erl b/lib/snmp/src/agent/snmpa_mib_storage_ets.erl index a2cceb2fa5..68dfa83247 100644 --- a/lib/snmp/src/agent/snmpa_mib_storage_ets.erl +++ b/lib/snmp/src/agent/snmpa_mib_storage_ets.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2013-2013. All Rights Reserved. +%% Copyright Ericsson AB 2013-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl b/lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl index 998743f133..5f66b2ed9f 100644 --- a/lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl +++ b/lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2013-2013. All Rights Reserved. +%% Copyright Ericsson AB 2013-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_misc_sup.erl b/lib/snmp/src/agent/snmpa_misc_sup.erl index 50570d508e..746405ec1d 100644 --- a/lib/snmp/src/agent/snmpa_misc_sup.erl +++ b/lib/snmp/src/agent/snmpa_misc_sup.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_net_if_filter.erl b/lib/snmp/src/agent/snmpa_net_if_filter.erl index 5f447ae5c7..1db8609eaf 100644 --- a/lib/snmp/src/agent/snmpa_net_if_filter.erl +++ b/lib/snmp/src/agent/snmpa_net_if_filter.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2014. All Rights Reserved. +%% Copyright Ericsson AB 2007-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_network_interface.erl b/lib/snmp/src/agent/snmpa_network_interface.erl index a9f17f274b..699fbde671 100644 --- a/lib/snmp/src/agent/snmpa_network_interface.erl +++ b/lib/snmp/src/agent/snmpa_network_interface.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_network_interface_filter.erl b/lib/snmp/src/agent/snmpa_network_interface_filter.erl index 3ad840e798..1524a6447b 100644 --- a/lib/snmp/src/agent/snmpa_network_interface_filter.erl +++ b/lib/snmp/src/agent/snmpa_network_interface_filter.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2014. All Rights Reserved. +%% Copyright Ericsson AB 2007-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_notification_delivery_info_receiver.erl b/lib/snmp/src/agent/snmpa_notification_delivery_info_receiver.erl index 29686ea757..aca90baf0e 100644 --- a/lib/snmp/src/agent/snmpa_notification_delivery_info_receiver.erl +++ b/lib/snmp/src/agent/snmpa_notification_delivery_info_receiver.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. +%% Copyright Ericsson AB 2008-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_notification_filter.erl b/lib/snmp/src/agent/snmpa_notification_filter.erl index 6eea857721..6300d450c7 100644 --- a/lib/snmp/src/agent/snmpa_notification_filter.erl +++ b/lib/snmp/src/agent/snmpa_notification_filter.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_set.erl b/lib/snmp/src/agent/snmpa_set.erl index fd99304991..9833d6fdcc 100644 --- a/lib/snmp/src/agent/snmpa_set.erl +++ b/lib/snmp/src/agent/snmpa_set.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_set_lib.erl b/lib/snmp/src/agent/snmpa_set_lib.erl index 2d14b719dd..57507a36e8 100644 --- a/lib/snmp/src/agent/snmpa_set_lib.erl +++ b/lib/snmp/src/agent/snmpa_set_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2011. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_set_mechanism.erl b/lib/snmp/src/agent/snmpa_set_mechanism.erl index b8bf3a9aa8..2f24f38092 100644 --- a/lib/snmp/src/agent/snmpa_set_mechanism.erl +++ b/lib/snmp/src/agent/snmpa_set_mechanism.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_supervisor.erl b/lib/snmp/src/agent/snmpa_supervisor.erl index 128c5f875d..cdb5ca840d 100644 --- a/lib/snmp/src/agent/snmpa_supervisor.erl +++ b/lib/snmp/src/agent/snmpa_supervisor.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_svbl.erl b/lib/snmp/src/agent/snmpa_svbl.erl index 53bbce7707..8955bed0f2 100644 --- a/lib/snmp/src/agent/snmpa_svbl.erl +++ b/lib/snmp/src/agent/snmpa_svbl.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_symbolic_store.erl b/lib/snmp/src/agent/snmpa_symbolic_store.erl index cffb6bcd1c..945a4e9a9c 100644 --- a/lib/snmp/src/agent/snmpa_symbolic_store.erl +++ b/lib/snmp/src/agent/snmpa_symbolic_store.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_target_cache.erl b/lib/snmp/src/agent/snmpa_target_cache.erl index 04d2a121ba..72caf72b33 100644 --- a/lib/snmp/src/agent/snmpa_target_cache.erl +++ b/lib/snmp/src/agent/snmpa_target_cache.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2013. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_trap.erl b/lib/snmp/src/agent/snmpa_trap.erl index eea2b05eb7..e75016f7ec 100644 --- a/lib/snmp/src/agent/snmpa_trap.erl +++ b/lib/snmp/src/agent/snmpa_trap.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/agent/snmpa_vacm.hrl b/lib/snmp/src/agent/snmpa_vacm.hrl index 20506f8715..527298e499 100644 --- a/lib/snmp/src/agent/snmpa_vacm.hrl +++ b/lib/snmp/src/agent/snmpa_vacm.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2009. All Rights Reserved. +%% Copyright Ericsson AB 1999-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/app/Makefile b/lib/snmp/src/app/Makefile index 7972d9549d..6f2b8a4077 100644 --- a/lib/snmp/src/app/Makefile +++ b/lib/snmp/src/app/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2003-2013. All Rights Reserved. +# Copyright Ericsson AB 2003-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/app/depend.mk b/lib/snmp/src/app/depend.mk index 4a9cc17490..bf213c2aec 100644 --- a/lib/snmp/src/app/depend.mk +++ b/lib/snmp/src/app/depend.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/app/modules.mk b/lib/snmp/src/app/modules.mk index fa42614a24..2bfd2d5c56 100644 --- a/lib/snmp/src/app/modules.mk +++ b/lib/snmp/src/app/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/app/snmp.erl b/lib/snmp/src/app/snmp.erl index 3c65f40bc7..df3933ea01 100644 --- a/lib/snmp/src/app/snmp.erl +++ b/lib/snmp/src/app/snmp.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/app/snmp_app.erl b/lib/snmp/src/app/snmp_app.erl index 8b948850dd..dbc1ec0b6d 100644 --- a/lib/snmp/src/app/snmp_app.erl +++ b/lib/snmp/src/app/snmp_app.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2013. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/app/snmp_app_sup.erl b/lib/snmp/src/app/snmp_app_sup.erl index 32b69b4bbf..eb89cc5b6d 100644 --- a/lib/snmp/src/app/snmp_app_sup.erl +++ b/lib/snmp/src/app/snmp_app_sup.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2009. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/app/snmp_internal.hrl b/lib/snmp/src/app/snmp_internal.hrl index 9a1bb4b67c..374767df15 100644 --- a/lib/snmp/src/app/snmp_internal.hrl +++ b/lib/snmp/src/app/snmp_internal.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2013. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/Makefile b/lib/snmp/src/compile/Makefile index 54f2e229b9..4093ffa9ca 100644 --- a/lib/snmp/src/compile/Makefile +++ b/lib/snmp/src/compile/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2012. All Rights Reserved. +# Copyright Ericsson AB 1997-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/depend.mk b/lib/snmp/src/compile/depend.mk index 427ad4cda3..57b7c19daf 100644 --- a/lib/snmp/src/compile/depend.mk +++ b/lib/snmp/src/compile/depend.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2013. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/modules.mk b/lib/snmp/src/compile/modules.mk index 547cc3438e..9ca5ebb95a 100644 --- a/lib/snmp/src/compile/modules.mk +++ b/lib/snmp/src/compile/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2011. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc.hrl b/lib/snmp/src/compile/snmpc.hrl index 9157ef13f0..b3c66f4f3d 100644 --- a/lib/snmp/src/compile/snmpc.hrl +++ b/lib/snmp/src/compile/snmpc.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2011. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc.src b/lib/snmp/src/compile/snmpc.src index 903b035d13..e64b6607c4 100644 --- a/lib/snmp/src/compile/snmpc.src +++ b/lib/snmp/src/compile/snmpc.src @@ -3,7 +3,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2008-2011. All Rights Reserved. +%% Copyright Ericsson AB 2008-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc_lib.erl b/lib/snmp/src/compile/snmpc_lib.erl index 3b1b1594c9..51690b6e7e 100644 --- a/lib/snmp/src/compile/snmpc_lib.erl +++ b/lib/snmp/src/compile/snmpc_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2013. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc_lib.hrl b/lib/snmp/src/compile/snmpc_lib.hrl index 0f65fc1820..8d76817cec 100644 --- a/lib/snmp/src/compile/snmpc_lib.hrl +++ b/lib/snmp/src/compile/snmpc_lib.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009-2011. All Rights Reserved. +%% Copyright Ericsson AB 2009-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc_mib_gram.yrl b/lib/snmp/src/compile/snmpc_mib_gram.yrl index b152f23d05..743c3a6550 100644 --- a/lib/snmp/src/compile/snmpc_mib_gram.yrl +++ b/lib/snmp/src/compile/snmpc_mib_gram.yrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2013. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc_mib_to_hrl.erl b/lib/snmp/src/compile/snmpc_mib_to_hrl.erl index e71530b40e..bc18afbdc9 100644 --- a/lib/snmp/src/compile/snmpc_mib_to_hrl.erl +++ b/lib/snmp/src/compile/snmpc_mib_to_hrl.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2011. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc_misc.erl b/lib/snmp/src/compile/snmpc_misc.erl index 68600bc97a..933d629746 100644 --- a/lib/snmp/src/compile/snmpc_misc.erl +++ b/lib/snmp/src/compile/snmpc_misc.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2009. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc_misc.hrl b/lib/snmp/src/compile/snmpc_misc.hrl index e09ec2712c..2df6d1863d 100644 --- a/lib/snmp/src/compile/snmpc_misc.hrl +++ b/lib/snmp/src/compile/snmpc_misc.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/compile/snmpc_tok.erl b/lib/snmp/src/compile/snmpc_tok.erl index 14f88cc9ae..9114cc90de 100644 --- a/lib/snmp/src/compile/snmpc_tok.erl +++ b/lib/snmp/src/compile/snmpc_tok.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/Makefile b/lib/snmp/src/manager/Makefile index 382f83b78e..0cc87492f1 100644 --- a/lib/snmp/src/manager/Makefile +++ b/lib/snmp/src/manager/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2012. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/depend.mk b/lib/snmp/src/manager/depend.mk index 651a6e537d..7d8f81f55a 100644 --- a/lib/snmp/src/manager/depend.mk +++ b/lib/snmp/src/manager/depend.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2014. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/modules.mk b/lib/snmp/src/manager/modules.mk index 0f13e26423..ea9b52d653 100644 --- a/lib/snmp/src/manager/modules.mk +++ b/lib/snmp/src/manager/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2012. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm.erl b/lib/snmp/src/manager/snmpm.erl index 446280b8bd..cf8c95d69f 100644 --- a/lib/snmp/src/manager/snmpm.erl +++ b/lib/snmp/src/manager/snmpm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_atl.hrl b/lib/snmp/src/manager/snmpm_atl.hrl index f407b399cf..988b75d9bd 100644 --- a/lib/snmp/src/manager/snmpm_atl.hrl +++ b/lib/snmp/src/manager/snmpm_atl.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_conf.erl b/lib/snmp/src/manager/snmpm_conf.erl index 0abc5ae88b..0421f49c88 100644 --- a/lib/snmp/src/manager/snmpm_conf.erl +++ b/lib/snmp/src/manager/snmpm_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2014. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_config.erl b/lib/snmp/src/manager/snmpm_config.erl index e5c0f27bd6..118cdcd1df 100644 --- a/lib/snmp/src/manager/snmpm_config.erl +++ b/lib/snmp/src/manager/snmpm_config.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_internal.hrl b/lib/snmp/src/manager/snmpm_internal.hrl index 72f277faf6..e917206f13 100644 --- a/lib/snmp/src/manager/snmpm_internal.hrl +++ b/lib/snmp/src/manager/snmpm_internal.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2011. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_misc_sup.erl b/lib/snmp/src/manager/snmpm_misc_sup.erl index 835216b30b..6ff82b322b 100644 --- a/lib/snmp/src/manager/snmpm_misc_sup.erl +++ b/lib/snmp/src/manager/snmpm_misc_sup.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_net_if_filter.erl b/lib/snmp/src/manager/snmpm_net_if_filter.erl index bcc9f97f4c..e5aef0756b 100644 --- a/lib/snmp/src/manager/snmpm_net_if_filter.erl +++ b/lib/snmp/src/manager/snmpm_net_if_filter.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009-2014. All Rights Reserved. +%% Copyright Ericsson AB 2009-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_net_if_mt.erl b/lib/snmp/src/manager/snmpm_net_if_mt.erl index 72bd69c612..238e212e14 100644 --- a/lib/snmp/src/manager/snmpm_net_if_mt.erl +++ b/lib/snmp/src/manager/snmpm_net_if_mt.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_network_interface.erl b/lib/snmp/src/manager/snmpm_network_interface.erl index dd4e762d84..d0f6f709d3 100644 --- a/lib/snmp/src/manager/snmpm_network_interface.erl +++ b/lib/snmp/src/manager/snmpm_network_interface.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_network_interface_filter.erl b/lib/snmp/src/manager/snmpm_network_interface_filter.erl index 604994756d..35bec4e7e7 100644 --- a/lib/snmp/src/manager/snmpm_network_interface_filter.erl +++ b/lib/snmp/src/manager/snmpm_network_interface_filter.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009. All Rights Reserved. +%% Copyright Ericsson AB 2009-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_server_sup.erl b/lib/snmp/src/manager/snmpm_server_sup.erl index e8c2790db3..842a5761ce 100644 --- a/lib/snmp/src/manager/snmpm_server_sup.erl +++ b/lib/snmp/src/manager/snmpm_server_sup.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2009. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_supervisor.erl b/lib/snmp/src/manager/snmpm_supervisor.erl index 5654c01c6a..c36bbe1bdd 100644 --- a/lib/snmp/src/manager/snmpm_supervisor.erl +++ b/lib/snmp/src/manager/snmpm_supervisor.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_user.erl b/lib/snmp/src/manager/snmpm_user.erl index 366e40cbb9..c0100d372f 100644 --- a/lib/snmp/src/manager/snmpm_user.erl +++ b/lib/snmp/src/manager/snmpm_user.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_user_default.erl b/lib/snmp/src/manager/snmpm_user_default.erl index f4f78d49b6..bc2b82a38b 100644 --- a/lib/snmp/src/manager/snmpm_user_default.erl +++ b/lib/snmp/src/manager/snmpm_user_default.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_user_old.erl b/lib/snmp/src/manager/snmpm_user_old.erl index c490421d6e..bc15ad445b 100644 --- a/lib/snmp/src/manager/snmpm_user_old.erl +++ b/lib/snmp/src/manager/snmpm_user_old.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009. All Rights Reserved. +%% Copyright Ericsson AB 2009-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_usm.erl b/lib/snmp/src/manager/snmpm_usm.erl index c7a28f5d68..7dd79e703a 100644 --- a/lib/snmp/src/manager/snmpm_usm.erl +++ b/lib/snmp/src/manager/snmpm_usm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/manager/snmpm_usm.hrl b/lib/snmp/src/manager/snmpm_usm.hrl index 7a0d225aff..38d4a1a07e 100644 --- a/lib/snmp/src/manager/snmpm_usm.hrl +++ b/lib/snmp/src/manager/snmpm_usm.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/Makefile b/lib/snmp/src/misc/Makefile index c71ecf994e..adc2c4858f 100644 --- a/lib/snmp/src/misc/Makefile +++ b/lib/snmp/src/misc/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2003-2012. All Rights Reserved. +# Copyright Ericsson AB 2003-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/depend.mk b/lib/snmp/src/misc/depend.mk index 3f8e6701b9..b2e0a92997 100644 --- a/lib/snmp/src/misc/depend.mk +++ b/lib/snmp/src/misc/depend.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/modules.mk b/lib/snmp/src/misc/modules.mk index c22f3604b7..ac42128724 100644 --- a/lib/snmp/src/misc/modules.mk +++ b/lib/snmp/src/misc/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2009. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 6264d79cec..513616a285 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 2b6bfdcb56..45661b71a7 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_debug.hrl b/lib/snmp/src/misc/snmp_debug.hrl index 86445893b6..6ed4af7d50 100644 --- a/lib/snmp/src/misc/snmp_debug.hrl +++ b/lib/snmp/src/misc/snmp_debug.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2009. All Rights Reserved. +%% Copyright Ericsson AB 2000-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index 09863dea60..767d801eee 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2014. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_mini_mib.erl b/lib/snmp/src/misc/snmp_mini_mib.erl index bc9596f64f..92de339001 100644 --- a/lib/snmp/src/misc/snmp_mini_mib.erl +++ b/lib/snmp/src/misc/snmp_mini_mib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2009. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_note_store.erl b/lib/snmp/src/misc/snmp_note_store.erl index 74bdd34931..606dd8ce4f 100644 --- a/lib/snmp/src/misc/snmp_note_store.erl +++ b/lib/snmp/src/misc/snmp_note_store.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2011. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_pdus.erl b/lib/snmp/src/misc/snmp_pdus.erl index 8045a94ff6..93f06749fd 100644 --- a/lib/snmp/src/misc/snmp_pdus.erl +++ b/lib/snmp/src/misc/snmp_pdus.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_usm.erl b/lib/snmp/src/misc/snmp_usm.erl index 8443b009d9..bae6bdec72 100644 --- a/lib/snmp/src/misc/snmp_usm.erl +++ b/lib/snmp/src/misc/snmp_usm.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/misc/snmp_verbosity.hrl b/lib/snmp/src/misc/snmp_verbosity.hrl index 950b5aa444..c79f4c3e88 100644 --- a/lib/snmp/src/misc/snmp_verbosity.hrl +++ b/lib/snmp/src/misc/snmp_verbosity.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2009. All Rights Reserved. +%% Copyright Ericsson AB 2000-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/src/subdirs.mk b/lib/snmp/src/subdirs.mk index e5a437ccfe..5f45fd2586 100644 --- a/lib/snmp/src/subdirs.mk +++ b/lib/snmp/src/subdirs.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2003-2009. All Rights Reserved. +# Copyright Ericsson AB 2003-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/subdirs.mk b/lib/snmp/subdirs.mk index caa4b8baf2..dd8af81d34 100644 --- a/lib/snmp/subdirs.mk +++ b/lib/snmp/subdirs.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2003-2009. All Rights Reserved. +# Copyright Ericsson AB 2003-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index 8e895bc5b1..a9142d911d 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2014. All Rights Reserved. +# Copyright Ericsson AB 1997-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/exp/snmp_agent_bl_test.erl b/lib/snmp/test/exp/snmp_agent_bl_test.erl index 186a1d0fec..af53f816f4 100644 --- a/lib/snmp/test/exp/snmp_agent_bl_test.erl +++ b/lib/snmp/test/exp/snmp_agent_bl_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2012. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/exp/snmp_agent_ms_test.erl b/lib/snmp/test/exp/snmp_agent_ms_test.erl index 3010de0619..e615e224dc 100644 --- a/lib/snmp/test/exp/snmp_agent_ms_test.erl +++ b/lib/snmp/test/exp/snmp_agent_ms_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2012. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/exp/snmp_agent_mt_test.erl b/lib/snmp/test/exp/snmp_agent_mt_test.erl index 71ae58baca..a9e68011ea 100644 --- a/lib/snmp/test/exp/snmp_agent_mt_test.erl +++ b/lib/snmp/test/exp/snmp_agent_mt_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2012. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/exp/snmp_agent_v1_test.erl b/lib/snmp/test/exp/snmp_agent_v1_test.erl index 55045d536e..98e29e55f7 100644 --- a/lib/snmp/test/exp/snmp_agent_v1_test.erl +++ b/lib/snmp/test/exp/snmp_agent_v1_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2012. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/exp/snmp_agent_v2_test.erl b/lib/snmp/test/exp/snmp_agent_v2_test.erl index 6238a6c4bd..c69904daf5 100644 --- a/lib/snmp/test/exp/snmp_agent_v2_test.erl +++ b/lib/snmp/test/exp/snmp_agent_v2_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2012. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/exp/snmp_agent_v3_test.erl b/lib/snmp/test/exp/snmp_agent_v3_test.erl index af7cee9b96..066a5a26fc 100644 --- a/lib/snmp/test/exp/snmp_agent_v3_test.erl +++ b/lib/snmp/test/exp/snmp_agent_v3_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2012. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/klas3.erl b/lib/snmp/test/klas3.erl index eb0c41bf77..9a5c388170 100644 --- a/lib/snmp/test/klas3.erl +++ b/lib/snmp/test/klas3.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2014. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/modules.mk b/lib/snmp/test/modules.mk index 16a570706a..87539f88f7 100644 --- a/lib/snmp/test/modules.mk +++ b/lib/snmp/test/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2014. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/sa.erl b/lib/snmp/test/sa.erl index 3e34fb2328..99e1ad55fd 100644 --- a/lib/snmp/test/sa.erl +++ b/lib/snmp/test/sa.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_SUITE.erl b/lib/snmp/test/snmp_SUITE.erl index 43f6b1abff..3b9219739b 100644 --- a/lib/snmp/test/snmp_SUITE.erl +++ b/lib/snmp/test/snmp_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2014. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_agent_mibs_test.erl b/lib/snmp/test/snmp_agent_mibs_test.erl index 2cbba14c74..4babffef43 100644 --- a/lib/snmp/test/snmp_agent_mibs_test.erl +++ b/lib/snmp/test/snmp_agent_mibs_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2013. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_agent_nfilter_test.erl b/lib/snmp/test/snmp_agent_nfilter_test.erl index 8aeef81333..64fdf20c3f 100644 --- a/lib/snmp/test/snmp_agent_nfilter_test.erl +++ b/lib/snmp/test/snmp_agent_nfilter_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 93968ede2e..8ae495bb1b 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2015. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index 6f20254fcb..66211d7105 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2014. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_app_test.erl b/lib/snmp/test/snmp_app_test.erl index 6892d4aa93..6e7e85d3b4 100644 --- a/lib/snmp/test/snmp_app_test.erl +++ b/lib/snmp/test/snmp_app_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2015. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_appup_test.erl b/lib/snmp/test/snmp_appup_test.erl index 47cbd5fe8c..aff1c7c782 100644 --- a/lib/snmp/test/snmp_appup_test.erl +++ b/lib/snmp/test/snmp_appup_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2011. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_compiler_test.erl b/lib/snmp/test/snmp_compiler_test.erl index b08181191f..2c8851c2a7 100644 --- a/lib/snmp/test/snmp_compiler_test.erl +++ b/lib/snmp/test/snmp_compiler_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2013. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_conf_test.erl b/lib/snmp/test/snmp_conf_test.erl index 73b471b107..6242fdeca3 100644 --- a/lib/snmp/test/snmp_conf_test.erl +++ b/lib/snmp/test/snmp_conf_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2015. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_log_test.erl b/lib/snmp/test/snmp_log_test.erl index ae2581fb69..8890b4b20d 100644 --- a/lib/snmp/test/snmp_log_test.erl +++ b/lib/snmp/test/snmp_log_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2015. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index 8428b61e8a..64d3134055 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2015. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_manager_test.erl b/lib/snmp/test/snmp_manager_test.erl index a343dfdca7..d17882e765 100644 --- a/lib/snmp/test/snmp_manager_test.erl +++ b/lib/snmp/test/snmp_manager_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2014. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_manager_user.erl b/lib/snmp/test/snmp_manager_user.erl index 55b1e23b2e..409f87cf40 100644 --- a/lib/snmp/test/snmp_manager_user.erl +++ b/lib/snmp/test/snmp_manager_user.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2014. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_manager_user_old.erl b/lib/snmp/test/snmp_manager_user_old.erl index f317fa831c..51b55da2e6 100644 --- a/lib/snmp/test/snmp_manager_user_old.erl +++ b/lib/snmp/test/snmp_manager_user_old.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2013. All Rights Reserved. +%% Copyright Ericsson AB 2010-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_manager_user_test.erl b/lib/snmp/test/snmp_manager_user_test.erl index 64edfef4d5..915249ec77 100644 --- a/lib/snmp/test/snmp_manager_user_test.erl +++ b/lib/snmp/test/snmp_manager_user_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_manager_user_test_lib.erl b/lib/snmp/test/snmp_manager_user_test_lib.erl index ea2c83a0da..8df7f1e662 100644 --- a/lib/snmp/test/snmp_manager_user_test_lib.erl +++ b/lib/snmp/test/snmp_manager_user_test_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_note_store_test.erl b/lib/snmp/test/snmp_note_store_test.erl index 902d37b0d7..94d400fb53 100644 --- a/lib/snmp/test/snmp_note_store_test.erl +++ b/lib/snmp/test/snmp_note_store_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% Copyright Ericsson AB 2004-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_pdus_test.erl b/lib/snmp/test/snmp_pdus_test.erl index bfbd031646..29a793ebcb 100644 --- a/lib/snmp/test/snmp_pdus_test.erl +++ b/lib/snmp/test/snmp_pdus_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2012. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_test_manager.erl b/lib/snmp/test/snmp_test_manager.erl index 294f0e8240..6ab5ce164c 100644 --- a/lib/snmp/test/snmp_test_manager.erl +++ b/lib/snmp/test/snmp_test_manager.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2013. All Rights Reserved. +%% Copyright Ericsson AB 2005-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_test_mgr_counter_server.erl b/lib/snmp/test/snmp_test_mgr_counter_server.erl index a72eefd6e5..697afdf799 100644 --- a/lib/snmp/test/snmp_test_mgr_counter_server.erl +++ b/lib/snmp/test/snmp_test_mgr_counter_server.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2014-2014. All Rights Reserved. +%% Copyright Ericsson AB 2014-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_test_mgr_misc.erl b/lib/snmp/test/snmp_test_mgr_misc.erl index 0a0e3be9aa..274fb5be26 100644 --- a/lib/snmp/test/snmp_test_mgr_misc.erl +++ b/lib/snmp/test/snmp_test_mgr_misc.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_test_server.erl b/lib/snmp/test/snmp_test_server.erl index 8b22d6943a..a77bdc142c 100644 --- a/lib/snmp/test/snmp_test_server.erl +++ b/lib/snmp/test/snmp_test_server.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2010. All Rights Reserved. +%% Copyright Ericsson AB 2003-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_test_suite.erl b/lib/snmp/test/snmp_test_suite.erl index 07c93d062c..539c6348a9 100644 --- a/lib/snmp/test/snmp_test_suite.erl +++ b/lib/snmp/test/snmp_test_suite.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% Copyright Ericsson AB 2008-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 95f4a7518b..ac9e37bc8b 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2014-2014. All Rights Reserved. +%% Copyright Ericsson AB 2014-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper index 8bd8e1ab4a..e10507cfbd 100755 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/start_stop_wrapper @@ -2,7 +2,7 @@ ## ## %CopyrightBegin% ## -## Copyright Ericsson AB 2014-2014. All Rights Reserved. +## Copyright Ericsson AB 2014-2016. All Rights Reserved. ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/test1.erl b/lib/snmp/test/test1.erl index 82555af11f..3337b265e6 100644 --- a/lib/snmp/test/test1.erl +++ b/lib/snmp/test/test1.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/test2.erl b/lib/snmp/test/test2.erl index 2bfae95c8d..c73a0930d6 100644 --- a/lib/snmp/test/test2.erl +++ b/lib/snmp/test/test2.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% Copyright Ericsson AB 1997-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/test_config/Makefile b/lib/snmp/test/test_config/Makefile index 6e78350e9f..1e53f51b83 100644 --- a/lib/snmp/test/test_config/Makefile +++ b/lib/snmp/test/test_config/Makefile @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2011. All Rights Reserved. +# Copyright Ericsson AB 1997-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/test_config/modules.mk b/lib/snmp/test/test_config/modules.mk index 64244be7fe..23475b63f8 100644 --- a/lib/snmp/test/test_config/modules.mk +++ b/lib/snmp/test/test_config/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2004-2010. All Rights Reserved. +# Copyright Ericsson AB 2004-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/snmp/test/test_config/snmp_test_config.erl b/lib/snmp/test/test_config/snmp_test_config.erl index 80fac0c772..89246f5b02 100644 --- a/lib/snmp/test/test_config/snmp_test_config.erl +++ b/lib/snmp/test/test_config/snmp_test_config.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2002-2010. All Rights Reserved. +%% Copyright Ericsson AB 2002-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index f60cbbfaa7..f58f6b6162 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2015. All Rights Reserved. +# Copyright Ericsson AB 1997-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. -- cgit v1.2.3 From bd64ad8e15d66e48b36dbe3584315dd5cfc8b59a Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Wed, 11 May 2016 17:22:23 +0200 Subject: Prepare release --- lib/snmp/doc/src/notes.xml | 17 ++++++++++++++++- lib/snmp/vsn.mk | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index b9dc5e4117..0f5c35b300 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -34,7 +34,22 @@
-
SNMP 5.2.2 +
SNMP 5.2.3 + +
Improvements and New Features + + +

+ Internal changes

+

+ Own Id: OTP-13551

+
+
+
+ +
+ +
SNMP 5.2.2
Fixed Bugs and Malfunctions diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index f58f6b6162..f95b428290 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -19,6 +19,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.2.2 +SNMP_VSN = 5.2.3 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 663e847459686604ea051f036a0e4caff18cea6f Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Thu, 12 May 2016 12:04:14 +0200 Subject: Revert "Prepare release" This reverts commit bd64ad8e15d66e48b36dbe3584315dd5cfc8b59a. --- lib/snmp/doc/src/notes.xml | 17 +---------------- lib/snmp/vsn.mk | 2 +- 2 files changed, 2 insertions(+), 17 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 0f5c35b300..b9dc5e4117 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -34,22 +34,7 @@
-
SNMP 5.2.3 - -
Improvements and New Features - - -

- Internal changes

-

- Own Id: OTP-13551

-
-
-
- -
- -
SNMP 5.2.2 +
SNMP 5.2.2
Fixed Bugs and Malfunctions diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index f95b428290..f58f6b6162 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -19,6 +19,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.2.3 +SNMP_VSN = 5.2.2 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From e020f75c10410a6943cd055bfa072a2641eab7da Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Thu, 2 Jun 2016 10:55:26 +0200 Subject: Prepare release --- lib/snmp/doc/src/notes.xml | 17 ++++++++++++++++- lib/snmp/vsn.mk | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index b9dc5e4117..0f5c35b300 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -34,7 +34,22 @@
-
SNMP 5.2.2 +
SNMP 5.2.3 + +
Improvements and New Features + + +

+ Internal changes

+

+ Own Id: OTP-13551

+
+
+
+ +
+ +
SNMP 5.2.2
Fixed Bugs and Malfunctions diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index f58f6b6162..f95b428290 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -19,6 +19,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.2.2 +SNMP_VSN = 5.2.3 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From c04cad3ba921deb086d19e2de2526af4854add75 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Thu, 2 Jun 2016 11:39:07 +0200 Subject: Revert "Prepare release" This reverts commit e020f75c10410a6943cd055bfa072a2641eab7da. --- lib/snmp/doc/src/notes.xml | 17 +---------------- lib/snmp/vsn.mk | 2 +- 2 files changed, 2 insertions(+), 17 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 0f5c35b300..b9dc5e4117 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -34,22 +34,7 @@
-
SNMP 5.2.3 - -
Improvements and New Features - - -

- Internal changes

-

- Own Id: OTP-13551

-
-
-
- -
- -
SNMP 5.2.2 +
SNMP 5.2.2
Fixed Bugs and Malfunctions diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index f95b428290..f58f6b6162 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -19,6 +19,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.2.3 +SNMP_VSN = 5.2.2 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3 From 6e51c6d19612d03abc81b86bb70b8d7da678ce5d Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Tue, 21 Jun 2016 15:12:41 +0200 Subject: Prepare release --- lib/snmp/doc/src/notes.xml | 17 ++++++++++++++++- lib/snmp/vsn.mk | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/snmp') diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index b9dc5e4117..0f5c35b300 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -34,7 +34,22 @@
-
SNMP 5.2.2 +
SNMP 5.2.3 + +
Improvements and New Features + + +

+ Internal changes

+

+ Own Id: OTP-13551

+
+
+
+ +
+ +
SNMP 5.2.2
Fixed Bugs and Malfunctions diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index f58f6b6162..f95b428290 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -19,6 +19,6 @@ # %CopyrightEnd% APPLICATION = snmp -SNMP_VSN = 5.2.2 +SNMP_VSN = 5.2.3 PRE_VSN = APP_VSN = "$(APPLICATION)-$(SNMP_VSN)$(PRE_VSN)" -- cgit v1.2.3