aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/snmp/src/manager/snmpm.erl28
-rw-r--r--lib/snmp/src/manager/snmpm_config.erl81
-rw-r--r--lib/snmp/src/manager/snmpm_net_if.erl4
-rw-r--r--lib/snmp/src/manager/snmpm_net_if_mt.erl4
-rw-r--r--lib/snmp/src/misc/snmp_conf.erl44
5 files changed, 97 insertions, 64 deletions
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:
%% <IP-address>:<Port>-<Version>
-%% 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;