aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/test/diameter_util.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-03-30 16:29:02 +0200
committerAnders Svensson <[email protected]>2017-06-11 16:30:35 +0200
commit1df74351286b6cd0e2b673fdf07f7219244ce9a7 (patch)
treeb3c82af8c828656260d097f9ae3304e7be653733 /lib/diameter/test/diameter_util.erl
parent111261d15df900bedd544ba1fab3a5880abda70a (diff)
downloadotp-1df74351286b6cd0e2b673fdf07f7219244ce9a7.tar.gz
otp-1df74351286b6cd0e2b673fdf07f7219244ce9a7.tar.bz2
otp-1df74351286b6cd0e2b673fdf07f7219244ce9a7.zip
Work around SCTP quirks on sparc-sun-solaris2.10
This addresses the testcase failures mentioned in the parent commit, which has been on account of the behaviour below, in which connect fails on the loopback address. Work around it by finding/using another address if possible. $ erl Erlang/OTP 20 [DEVELOPMENT] [erts-9.0] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false] [sharing-preserving] Eshell V9.0 (abort with ^G) 1> {ok, LP} = gen_sctp:open(). {ok,#Port<0.439>} 2> gen_sctp:listen(LP, true). ok 3> inet:socknames(LP). {ok,[{{10,67,16,178},36506},{{127,0,0,1},36506}]} 4> {ok, S} = gen_sctp:open([{ip, {127,0,0,1}}]). {ok,#Port<0.443>} 5> gen_sctp:connect_init(S, {127,0,0,1}, 36506, []). {error,eaddrnotavail} 6> gen_sctp:connect_init(S, {10,67,16,178}, 36506, []). {error,eaddrnotavail} 7> gen_sctp:close(S). ok 8> f(S). ok 9> {ok, S} = gen_sctp:open(). {ok,#Port<0.444>} 10> gen_sctp:connect_init(S, {127,0,0,1}, 36506, []). ok Even the following has been seen on at least one host, so that success of gen_sctp:open/0 is no guarantee. $ ifconfig -a4 lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 bge0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 2 inet 10.67.16.180 netmask ffffff00 broadcast 10.67.16.255 $ erl Erlang/OTP 20 [DEVELOPMENT] [erts-9.0] [source] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false] Eshell V9.0 (abort with ^G) 1> {ok, S} = gen_sctp:open(), 1> gen_sctp:connect(S, {127,0,0,1}, 3868, []). {error,eafnosupport} 2> gen_sctp:connect(S, {10,67,16,180}, 3868, []). {error,eafnosupport}
Diffstat (limited to 'lib/diameter/test/diameter_util.erl')
-rw-r--r--lib/diameter/test/diameter_util.erl50
1 files changed, 36 insertions, 14 deletions
diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl
index 37fcbbc267..8df5c907d0 100644
--- a/lib/diameter/test/diameter_util.erl
+++ b/lib/diameter/test/diameter_util.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -32,7 +32,8 @@
foldl/3,
scramble/1,
unique_string/0,
- have_sctp/0]).
+ have_sctp/0,
+ ip4/0]).
%% diameter-specific
-export([lport/2,
@@ -197,8 +198,11 @@ unique_string() ->
have_sctp() ->
case gen_sctp:open() of
{ok, Sock} ->
+ RC = gen_sctp:connect(Sock, ip4(), 3868, []),
gen_sctp:close(Sock),
- true;
+ %% Connect has been seen to return eafnosupport on at least
+ %% one SunOS 10 Sparc host, for reasons unknown.
+ RC /= {error, eafnosupport};
{error, E} when E == eprotonosupport;
E == esocktnosupport -> %% fail on any other reason
false
@@ -361,7 +365,8 @@ tmod(any) ->
opts(Prot, T) ->
tmo(T, lists:append([[{transport_module, M}, {transport_config, C}]
|| M <- tmod(Prot),
- C <- [cfg(M,T) ++ cfg(M) ++ cfg(T)]])).
+ C <- [buf(M,T) ++ [{ip, addr(M)}, {port, 0}]
+ ++ remote(M,T)]])).
tmo(listen, Opts) ->
Opts;
@@ -377,21 +382,38 @@ tmo([M, C | Opts]) ->
%% Listening SCTP socket need larger-than-default buffers to avoid
%% resends on some platforms (eg. SLES 11).
-cfg(diameter_sctp, listen) ->
+buf(diameter_sctp, listen) ->
[{recbuf, 1 bsl 16}, {sndbuf, 1 bsl 16}];
-
-cfg(_, _) ->
+buf(_, _) ->
[].
-cfg(M)
- when M == diameter_tcp;
- M == diameter_sctp ->
- [{ip, ?ADDR}, {port, 0}];
+addr(diameter_tcp) ->
+ {127,0,0,1};
+addr(diameter_sctp) ->
+ ip4().
-cfg(listen) ->
+remote(_, listen) ->
[{accept, M} || M <- [{256,0,0,1}, ["256.0.0.1", ["^.+$"]]]];
-cfg(PortNr) ->
- [{raddr, ?ADDR}, {rport, PortNr}].
+remote(Mod, PortNr) ->
+ [{raddr, addr(Mod)}, {rport, PortNr}].
+
+%% Try to use something other than the loopback address where this
+%% address is known to be problematic for gen_sctp.
+ip4() ->
+ try
+ "sparc-sun-solaris2.10" = erlang:system_info(system_architecture),
+ {ok, List} = inet:getifaddrs(),
+ hd(lists:flatmap(fun ip4/1, List))
+ catch
+ error:_ ->
+ ?ADDR
+ end.
+
+ip4({_, Opts}) ->
+ {flags, Flags} = lists:keyfind(flags, 1, Opts),
+ [A || lists:member(up, Flags),
+ not lists:member(loopback, Flags),
+ {addr, {_,_,_,_} = A} <- Opts].
%% ---------------------------------------------------------------------------
%% info/0