From 4c1e79bf4582e19cd7b4225fb867b4f088895294 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Wed, 8 Jul 2015 13:42:37 +0200 Subject: Truncate potentially large terms passed to diameter_lib:log/4 Last visited in commit 00584303. --- lib/diameter/src/base/diameter_peer_fsm.erl | 7 ++++++- lib/diameter/src/base/diameter_watchdog.erl | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/diameter/src/base/diameter_peer_fsm.erl b/lib/diameter/src/base/diameter_peer_fsm.erl index 2255d0a76b..a9ee4940a3 100644 --- a/lib/diameter/src/base/diameter_peer_fsm.erl +++ b/lib/diameter/src/base/diameter_peer_fsm.erl @@ -319,7 +319,7 @@ handle_info(T, #state{} = State) -> ?LOG(stop, Reason), {stop, {shutdown, Reason}, State}; stop -> - ?LOG(stop, T), + ?LOG(stop, truncate(T)), {stop, {shutdown, T}, State} catch exit: {diameter_codec, encode, T} = Reason -> @@ -355,6 +355,11 @@ code_change(_, State, _) -> %% --------------------------------------------------------------------------- %% --------------------------------------------------------------------------- +truncate({'DOWN' = T, _, process, Pid, _}) -> + {T, Pid}; +truncate(T) -> + T. + putr(Key, Val) -> put({?MODULE, Key}, Val). diff --git a/lib/diameter/src/base/diameter_watchdog.erl b/lib/diameter/src/base/diameter_watchdog.erl index de9c4bca33..55c303dec2 100644 --- a/lib/diameter/src/base/diameter_watchdog.erl +++ b/lib/diameter/src/base/diameter_watchdog.erl @@ -245,11 +245,16 @@ handle_info(T, #watchdog{} = State) -> event(T, State, S), %% before 'watchdog' {noreply, S}; stop -> - ?LOG(stop, T), + ?LOG(stop, truncate(T)), event(T, State, State#watchdog{status = down}), {stop, {shutdown, T}, State} end. +truncate({'DOWN' = T, _, process, Pid, _}) -> + {T, Pid}; +truncate(T) -> + T. + close({'DOWN', _, process, TPid, {shutdown, Reason}}, #watchdog{transport = TPid, parent = Pid}) -> -- cgit v1.2.3 From 80420620b67216b67e90affc5fe35505207254a3 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Wed, 8 Jul 2015 15:07:15 +0200 Subject: Correct inaccurate doc The warning report was removed in commit 00584303. --- lib/diameter/doc/src/diameter.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/diameter/doc/src/diameter.xml b/lib/diameter/doc/src/diameter.xml index ea175a58b8..cb628f9529 100644 --- a/lib/diameter/doc/src/diameter.xml +++ b/lib/diameter/doc/src/diameter.xml @@ -1231,9 +1231,7 @@ is not the length of the message in question, as received over the transport interface documented in &man_transport;.

-If exit then a warning report is emitted and the parent of the -transport process in question exits, which causes the transport -process itself to exit as described in &man_transport;. +If exit then the transport process in question exits. If handle then the message is processed as usual, a resulting &app_handle_request; or &app_handle_answer; callback (if one takes place) indicating the 5015 error (DIAMETER_INVALID_MESSAGE_LENGTH). -- cgit v1.2.3 From abd6c7494f973eb91c6a582f3370e9896d28992b Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 29 Jun 2015 09:09:13 +0200 Subject: Don't flag AVP as missing as a consequence of decode error The decode of an incoming Diameter message uses the record representation to determine whether or not an AVP has been received with the expected arity, the number of AVPs in each field following decode being compared with the arity specified in the message grammar. The problem with this is that decode failure isn't reflected in the record representation, so that an AVP can be appended to the errors field of a diameter_packet record despite an entry for the same AVP already existing. This isn't a fault as much as a misleading error indication, but now only append AVPs that aren't already represented. --- lib/diameter/include/diameter_gen.hrl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/diameter/include/diameter_gen.hrl b/lib/diameter/include/diameter_gen.hrl index e8ffe7f92c..0b36389088 100644 --- a/lib/diameter/include/diameter_gen.hrl +++ b/lib/diameter/include/diameter_gen.hrl @@ -185,9 +185,10 @@ decode_avps(Name, Recs) -> = lists:foldl(fun(T,A) -> decode(Name, T, A) end, {[], {newrec(Name), []}}, Recs), - {Rec, Avps, Failed ++ missing(Rec, Name)}. -%% Append 5005 errors so that a 5014 for the same AVP will take -%% precedence in a Result-Code/Failed-AVP setting. + {Rec, Avps, Failed ++ missing(Rec, Name, Failed)}. +%% Append 5005 errors so that errors are reported in the order +%% encountered. Failed-AVP should typically contain the first +%% encountered error accordg to the RFC. newrec(Name) -> '#new-'(name2rec(Name)). @@ -202,10 +203,18 @@ newrec(Name) -> %% Vendor-Id if applicable. The value field of the missing AVP %% should be of correct minimum length and contain zeroes. +missing(Rec, Name, Failed) -> + [{5005, A} || #diameter_avp{code = MC, vendor_id = MV} = A + <- missing(Rec, Name), + lists:all(fun({_, #diameter_avp{code = C, vendor_id = V}}) -> + MC /= C orelse MV /= V + end, + Failed)]. + missing(Rec, Name) -> - [{5005, empty_avp(F)} || F <- '#info-'(element(1, Rec), fields), - A <- [avp_arity(Name, F)], - false <- [have_arity(A, '#get-'(F, Rec))]]. + [empty_avp(F) || F <- '#info-'(element(1, Rec), fields), + A <- [avp_arity(Name, F)], + not have_arity(A, '#get-'(F, Rec))]. %% Maximum arities have already been checked in building the record. -- cgit v1.2.3 From 16aaa29b7ce40596520d563b6f4a8e0aeba7b085 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Tue, 7 Jul 2015 09:58:21 +0200 Subject: Don't traverse errors list unnecessarily when detecting missing AVPs Since the list can potentially be long. --- lib/diameter/include/diameter_gen.hrl | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/diameter/include/diameter_gen.hrl b/lib/diameter/include/diameter_gen.hrl index 0b36389088..79b8e6ecde 100644 --- a/lib/diameter/include/diameter_gen.hrl +++ b/lib/diameter/include/diameter_gen.hrl @@ -201,20 +201,19 @@ newrec(Name) -> %% Failed-AVP AVP SHOULD be included in the message. The Failed-AVP %% AVP MUST contain an example of the missing AVP complete with the %% Vendor-Id if applicable. The value field of the missing AVP -%% should be of correct minimum length and contain zeroes. +%% should be of correct minimum length and contain zeros. missing(Rec, Name, Failed) -> - [{5005, A} || #diameter_avp{code = MC, vendor_id = MV} = A - <- missing(Rec, Name), - lists:all(fun({_, #diameter_avp{code = C, vendor_id = V}}) -> - MC /= C orelse MV /= V - end, - Failed)]. - -missing(Rec, Name) -> - [empty_avp(F) || F <- '#info-'(element(1, Rec), fields), - A <- [avp_arity(Name, F)], - not have_arity(A, '#get-'(F, Rec))]. + Avps = lists:foldl(fun({_, #diameter_avp{code = C, vendor_id = V}}, A) -> + sets:add_element({C,V}, A) + end, + sets:new(), + Failed), + [{5005, A} || F <- '#info-'(element(1, Rec), fields), + not have_arity(avp_arity(Name, F), '#get-'(F, Rec)), + #diameter_avp{code = C, vendor_id = V} + = A <- [empty_avp(F)], + not sets:is_element({C,V}, Avps)]. %% Maximum arities have already been checked in building the record. -- cgit v1.2.3