aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2014-05-07 08:43:07 +0200
committerRaimo Niskanen <[email protected]>2014-07-25 12:15:14 +0200
commit382e91a930b3d20d4e4cce14ea6c3cbc7e4397d7 (patch)
tree5dfcd9909a5024315b8010d41e1b7309a50b5328
parent89ca2960d421a43bced0a9f228a62b8ab3089663 (diff)
downloadotp-382e91a930b3d20d4e4cce14ea6c3cbc7e4397d7.tar.gz
otp-382e91a930b3d20d4e4cce14ea6c3cbc7e4397d7.tar.bz2
otp-382e91a930b3d20d4e4cce14ea6c3cbc7e4397d7.zip
Rewrite agent to use {Domain,Address} tuples as far as possible
-rw-r--r--lib/snmp/src/agent/snmpa_mpd.erl57
-rw-r--r--lib/snmp/src/agent/snmpa_net_if.erl262
-rw-r--r--lib/snmp/src/agent/snmpa_net_if_filter.erl25
-rw-r--r--lib/snmp/src/agent/snmpa_network_interface_filter.erl17
-rw-r--r--lib/snmp/src/manager/snmpm_config.erl6
-rw-r--r--lib/snmp/src/manager/snmpm_net_if.erl2
-rw-r--r--lib/snmp/src/manager/snmpm_net_if_mt.erl2
-rw-r--r--lib/snmp/src/misc/snmp_conf.erl6
8 files changed, 205 insertions, 172 deletions
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