aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp/src/agent
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2014-05-20 15:15:43 +0200
committerRaimo Niskanen <[email protected]>2014-07-25 12:15:16 +0200
commitcc1ab998ce905cd673c7ea14ee4e31ddb2412350 (patch)
treeee74e4790f89a8282d077458ee9d1af472d8a914 /lib/snmp/src/agent
parentc1104d6708917d7ec0b3b77340242b679ee10122 (diff)
downloadotp-cc1ab998ce905cd673c7ea14ee4e31ddb2412350.tar.gz
otp-cc1ab998ce905cd673c7ea14ee4e31ddb2412350.tar.bz2
otp-cc1ab998ce905cd673c7ea14ee4e31ddb2412350.zip
Don't encode IPv6 address into v1 trap and fix legacy arguments to snmpa_network_interface_filter functions
Diffstat (limited to 'lib/snmp/src/agent')
-rw-r--r--lib/snmp/src/agent/snmpa_mpd.erl18
-rw-r--r--lib/snmp/src/agent/snmpa_net_if.erl48
-rw-r--r--lib/snmp/src/agent/snmpa_trap.erl87
3 files changed, 115 insertions, 38 deletions
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,