Skip to content

Commit

Permalink
Fix association id of unordered send setopts in diameter_sctp
Browse files Browse the repository at this point in the history
The call to inet:setopts/2 to request unordered delivery did not set
assoc_id, and gen_sctp(3) documents the default 0 in this case as
meaning the whole endpoint, which was not the intention. The result was
either too much unordered or too little, depending on the use case, but
exactly what the behaviour is on different OSes is a little unclear.
What's clear is that it was wrong.

RFC 6458 defines constants SCTP_FUTURE_ASSOC, SCTP_CURRENT_ASSOC, and
SCTP_ALL_ASSOC here:

  https://tools.ietf.org/html/rfc6458#section-7.2

It doesn't assign numeric values however, so 0 in gen_sctp doesn't
necessarily have the same meaning as the 0 that Linux (for one) defines
as SCTP_FUTURE_ASSOC for example. Besides, association ids are
documented as opaque by gen_sctp(3), so even setting 0 explicitly is
questionable. Better to simply specify the association id that gen_sctp
has communicated in the sctp_assoc_change comm_up event.

Last visited in commit d382952. Originally bungled in commit 0447bd6.

Thanks to Andreas Schultz.
  • Loading branch information
Anders Svensson committed May 4, 2021
1 parent da9acf2 commit 1cf6476
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/diameter/src/transport/diameter_sctp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -813,23 +813,25 @@ recv(#transport{rotate = B} = S)
recv(#transport{rotate = 0,
streams = {_,OS},
socket = Sock,
assoc_id = Id,
unordered = B}
= S) ->
ok = unordered(Sock, OS, B),
ok = unordered(Sock, Id, OS, B),
S#transport{rotate = 1 < OS};

recv(#transport{rotate = N} = S) ->
S#transport{rotate = N-1}.

%% unordered/3
%% unordered/4

unordered(Sock, OS, B)
unordered(Sock, Id, OS, B)
when B;
is_integer(B), OS =< B ->
inet:setopts(Sock, [{sctp_default_send_param,
#sctp_sndrcvinfo{flags = [unordered]}}]);
#sctp_sndrcvinfo{flags = [unordered],
assoc_id = Id}}]);

unordered(_, OS, B)
unordered(_, _, OS, B)
when not B;
is_integer(B), B < OS ->
ok.
Expand Down

0 comments on commit 1cf6476

Please sign in to comment.