aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp/src/misc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/snmp/src/misc')
-rw-r--r--lib/snmp/src/misc/snmp_conf.erl207
-rw-r--r--lib/snmp/src/misc/snmp_config.erl20
-rw-r--r--lib/snmp/src/misc/snmp_misc.erl11
3 files changed, 224 insertions, 14 deletions
diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl
index 4d2f5d8f92..cb5b3bbfbd 100644
--- a/lib/snmp/src/misc/snmp_conf.erl
+++ b/lib/snmp/src/misc/snmp_conf.erl
@@ -37,7 +37,13 @@
check_timer/1,
- check_ip/1, check_taddress/1,
+ check_domain/1,
+ 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_packet_size/1,
@@ -52,8 +58,10 @@
-define(SNMP_USE_V3, true).
--include("snmp_types.hrl").
--include("SNMP-FRAMEWORK-MIB.hrl").
+-include_lib("snmp/include/snmp_types.hrl").
+-include_lib("snmp/include/SNMP-FRAMEWORK-MIB.hrl").
+-include_lib("snmp/include/TRANSPORT-ADDRESS-MIB.hrl").
+-include_lib("snmp/include/SNMPv2-TM.hrl").
-define(VMODULE,"CONF").
-include("snmp_verbosity.hrl").
@@ -338,15 +346,96 @@ check_sec_level(BadSecLevel) ->
%% ---------
-check_taddress(X) when is_list(X) andalso (length(X) =:= 6) ->
+check_tdomain(TDomain) ->
+ SupportedTDomains =
+ [
+ ?snmpUDPDomain,
+ ?transportDomainUdpIpv4,
+ ?transportDomainUdpIpv6
+ ],
+ AllTDomains =
+ [
+ ?transportDomainUdpIpv4,
+ ?transportDomainUdpIpv6,
+ ?transportDomainUdpIpv4z,
+ ?transportDomainUdpIpv6z,
+ ?transportDomainTcpIpv4,
+ ?transportDomainTcpIpv6,
+ ?transportDomainTcpIpv4z,
+ ?transportDomainTcpIpv6z,
+ ?transportDomainSctpIpv4,
+ ?transportDomainSctpIpv6,
+ ?transportDomainSctpIpv4z,
+ ?transportDomainSctpIpv6z,
+ ?transportDomainLocal,
+ ?transportDomainUdpDns,
+ ?transportDomainTcpDns,
+ ?transportDomainSctpDns
+ ],
+ case lists:member(TDomain, SupportedTDomains) of
+ true ->
+ ok;
+ false ->
+ case lists:member(TDomain, AllTDomains) of
+ true ->
+ error({unsupported_tdomain, TDomain});
+ false ->
+ error({unknown_tdomain, TDomain})
+ end
+ end.
+
+
+%% ---------
+
+mk_tdomain(snmpUDPDomain) ->
+ ?snmpUDPDomain;
+mk_tdomain(transportDomainUdpIpv4) ->
+ ?transportDomainUdpIpv4;
+mk_tdomain(transportDomainUdpIpv6) ->
+ ?transportDomainUdpIpv6;
+mk_tdomain(BadDomain) ->
+ error({bad_domain, BadDomain}).
+
+
+%% ---------
+
+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 ->
ok;
false ->
error({invalid_taddress, X})
end;
-check_taddress(X) ->
- error({invalid_taddress, X}).
+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 ->
+ ok;
+ false ->
+ error({invalid_taddress, X})
+ end;
+check_taddress(transportDomainUdpIpv6, X) ->
+ error({invalid_taddress, X});
+
+check_taddress(BadDomain, _X) ->
+ error({invalid_tdomain, BadDomain}).
+
%% ---------
@@ -385,15 +474,115 @@ do_check_timer(WaitFor, Factor, Incr, Retry) ->
%% ---------
-check_ip(X) when is_list(X) andalso (length(X) =:= 4) ->
+check_domain(Domain) ->
+ SupportedDomains =
+ [
+ snmpUDPDomain,
+ transportDomainUdpIpv4,
+ transportDomainUdpIpv6
+ ],
+ AllDomains =
+ [
+ transportDomainUdpIpv4,
+ transportDomainUdpIpv6,
+ transportDomainUdpIpv4z,
+ transportDomainUdpIpv6z,
+ transportDomainTcpIpv4,
+ transportDomainTcpIpv6,
+ transportDomainTcpIpv4z,
+ transportDomainTcpIpv6z,
+ transportDomainSctpIpv4,
+ transportDomainSctpIpv6,
+ transportDomainSctpIpv4z,
+ transportDomainSctpIpv6z,
+ transportDomainLocal,
+ transportDomainUdpDns,
+ transportDomainTcpDns,
+ transportDomainSctpDns
+ ],
+ case lists:member(Domain, SupportedDomains) of
+ true ->
+ ok;
+ false ->
+ case lists:member(Domain, AllDomains) of
+ true ->
+ error({unsupported_domain, Domain});
+ false ->
+ error({unknown_domain, Domain})
+ end
+ end.
+
+
+%% ---------
+
+%% The values of Ip and Port has both been checked at this
+%% point, so we dont need to do that again.
+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}).
+
+
+%% ---------
+
+which_domain(Ip) when is_list(Ip) andalso (length(Ip) =:= 4) ->
+ transportDomainUdpIpv4;
+which_domain(Ip) when is_tuple(Ip) andalso (size(Ip) =:= 4) ->
+ transportDomainUdpIpv4;
+which_domain(Ip) when is_list(Ip) andalso (length(Ip) =:= 8) ->
+ transportDomainUdpIpv6;
+which_domain(Ip) when is_tuple(Ip) andalso (size(Ip) =:= 8) ->
+ transportDomainUdpIpv6.
+
+
+%% ---------
+
+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 ->
ok;
false ->
error({invalid_ip_address, X})
end;
-check_ip(X) ->
- error({invalid_ip_address, X}).
+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 ->
+ ok;
+ false ->
+ error({invalid_ip_address, X})
+ end;
+check_ip(transportDomainUdpIpv6, X) ->
+ error({invalid_ip_address, X});
+
+check_ip(BadDomain, _X) ->
+ error({invalid_domain, BadDomain}).
+
%% ---------
diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl
index 25350e08cb..813942225e 100644
--- a/lib/snmp/src/misc/snmp_config.erl
+++ b/lib/snmp/src/misc/snmp_config.erl
@@ -491,6 +491,9 @@ config_agent_snmp(Dir, Vsns) ->
Host = host(),
AgentIP = ask("5. IP address for the agent (only used as id ~n"
" when sending traps)", Host, fun verify_address/1),
+ %% We intentionally skip TDomain...
+ %% If the user wish to use IPv6, the user must create an dummy entry here
+ %% and then manually edit these entries later.
ManagerIP = ask("6. IP address for the manager (only this manager ~n"
" will have access to the agent, traps are sent ~n"
" to this one)", Host, fun verify_address/1),
@@ -1062,9 +1065,19 @@ verify_sec_type(ST) -> {error, "invalid security type: " ++ ST}.
verify_address(A) ->
- case (catch snmp_misc:ip(A)) of
+ verify_address(A, snmpUDPDomain).
+
+verify_address(A, snmpUDPDomain = _Domain) ->
+ do_verify_address(A, inet);
+verify_address(A, transportDomainUdpIpv4 = _Domain) ->
+ do_verify_address(A, inet);
+verify_address(A, transportDomainUdpIpv6 = _Domain) ->
+ do_verify_address(A, inet6).
+
+do_verify_address(A, Family) ->
+ case (catch snmp_misc:ip(A, Family)) of
{ok, IP} ->
- {ok, tuple_to_list(IP)};
+ {ok, tuple_to_list(IP)};
{error, _} ->
{error, "invalid address: " ++ A};
_E ->
@@ -1721,10 +1734,12 @@ write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP,
Hdr = header() ++ Comment,
F = fun(v1 = Vsn, Acc) ->
[{mk_ip(ManagerIp, Vsn),
+ snmp_target_mib:default_domain(),
ManagerIp, UDP, 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,
"std_trap", mk_param(Vsn), "", [], 2048},
{lists:flatten(io_lib:format("~s.2",[mk_ip(ManagerIp, Vsn)])),
@@ -1732,6 +1747,7 @@ write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP,
"std_inform", mk_param(Vsn), "", [], 2048}| Acc];
(v3 = Vsn, Acc) ->
[{mk_ip(ManagerIp, Vsn),
+ snmp_target_mib:default_domain(),
ManagerIp, UDP, Timeout, RetryCount,
"std_trap", mk_param(Vsn), "", [], 2048},
{lists:flatten(io_lib:format("~s.3",[mk_ip(ManagerIp, Vsn)])),
diff --git a/lib/snmp/src/misc/snmp_misc.erl b/lib/snmp/src/misc/snmp_misc.erl
index 1b535743a4..6adef06ab9 100644
--- a/lib/snmp/src/misc/snmp_misc.erl
+++ b/lib/snmp/src/misc/snmp_misc.erl
@@ -40,7 +40,7 @@
get_option/2,
get_option/3,
get_sec_level/1,
- ip/1,
+ ip/1, ip/2,
is_auth/1,
is_BitString/1,
is_oid/1,
@@ -347,10 +347,15 @@ bits_to_int([Kibble|Ks],Kibbles,Res) ->
%%----------------------------------------------------------------------
-%% Returns: {ok, {int(),int(),int(),int()}} | {error, Reason}
+%% Returns: {ok, {int(),int(),int(),int()}} |
+%% {ok, {int(),int(),int(),int()},int(),int(),int(),int()} |
+%% {error, Reason}
%%----------------------------------------------------------------------
ip(Host) ->
- inet:getaddr(Host, inet).
+ ip(Host, inet).
+
+ip(Host, Family) ->
+ inet:getaddr(Host, Family).
ensure_trailing_dir_delimiter([]) -> "/";
ensure_trailing_dir_delimiter(DirSuggestion) ->