Skip to content

Commit

Permalink
Added auto run of eradius:modules_ready/1
Browse files Browse the repository at this point in the history
  • Loading branch information
vk committed Sep 6, 2021
1 parent 55631e2 commit dec5445
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
19 changes: 14 additions & 5 deletions src/ergw_aaa_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

start(_StartType, _StartArgs) ->
case ergw_aaa_sup:start_link() of
{ok, _} = Ret ->
prometheus_declare(),
Ret;
Other ->
Other
{ok, _} = Ret ->
prometheus_declare(),
maybe_load_radius_callback(),
Ret;
Other ->
Other
end.

stop(_State) ->
Expand All @@ -36,3 +37,11 @@ prometheus_declare() ->
prometheus_gauge:declare([{name, aaa_sessions_total},
{labels, [handler, state]},
{help, "AAA sessions"}]).

maybe_load_radius_callback() ->
case application:get_env(eradius, radius_callback, false) of
false ->
ok;
Callback ->
ok = eradius:modules_ready([Callback])
end.
20 changes: 10 additions & 10 deletions src/ergw_aaa_radius_handler.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% Copyright 2016-2019, Travelping GmbH <info@travelping.com>
%% Copyright 2016-2021, Travelping GmbH <info@travelping.com>

%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License
Expand All @@ -22,24 +22,24 @@
%%===================================================================
%% API
%%===================================================================
radius_request(#radius_request{cmd=discreq, attrs=Attrs}, _NasProp, _Args) ->
#{?Acct_Session_Id := HexSessionId} = maps:from_list([{Id, V} || {#attribute{id=Id}, V} <- Attrs]),
radius_request(#radius_request{cmd = discreq, attrs = Attrs} = Req, _NasProp, _Args) ->
#{?Acct_Session_Id := HexSessionId} = maps:from_list([{Id, V} || {#attribute{id = Id}, V} <- Attrs]),
Cmd = case ergw_aaa_session_reg:lookup(to_session_id(HexSessionId)) of
Session when is_pid(Session) ->
%% NOTE : Strictly speaking 'ASR' is a wrong name for radius disconnect.
%% It may be considered in the future to rename the ergw API to
%% something more generic (which may require change in termination
%% cause mapping as well).
ergw_aaa_session:request(Session, ergw_aaa_radius, {?API, 'ASR'}, #{}),
%% NOTE : Strictly speaking 'ASR' is a wrong name for radius disconnect.
%% It may be considered in the future to rename the ergw API to
%% something more generic (which may require change in termination
%% cause mapping as well).
ergw_aaa_session:request(Session, ergw_aaa_radius, {?API, 'ASR'}, #{}),
discack;
_ ->
discnak
end,
{reply, #radius_request{cmd=Cmd}};
{reply, Req#radius_request{cmd = Cmd}};

radius_request(#radius_request{}=Request, _NasProp, _Args) ->
?LOG(warning, "Unhandled radius request: ~p", [Request]),
noreply.
{reply, Request}.

to_session_id(HexSessionId) ->
H = fun(N) when N < 58 -> N - 48;
Expand Down
9 changes: 0 additions & 9 deletions test/radius_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ check_stats_per_testcase() ->
compat() ->
[{doc, "Check that the old API is still working"}].
compat(Config) ->
eradius_test_handler:ready(),

{ok, Session} = ergw_aaa_session_sup:new_session(self(),
#{'Framed-IP-Address' => {10,10,10,10}}),
Expand Down Expand Up @@ -161,7 +160,6 @@ simple_normal_terminate(Config) ->
disconnect_request() ->
[{doc, "Check if we can terminate a session with a disconnect request"}].
disconnect_request(Config) ->
eradius_test_handler:ready(),

{ok, Session} = ergw_aaa_session_sup:new_session(self(),
#{'Framed-IP-Address' => {10,10,10,10}}),
Expand Down Expand Up @@ -198,7 +196,6 @@ disconnect_request(Config) ->
accounting() ->
[{doc, "Check that we can successfully send ACR's and get ACA's"}].
accounting(Config) ->
eradius_test_handler:ready(),

{ok, Session} = ergw_aaa_session_sup:new_session(self(),
#{'Framed-IP-Address' => {10,10,10,10}}),
Expand All @@ -225,7 +222,6 @@ accounting(Config) ->
accounting_async() ->
[{doc, "Check that Start / Stop msg work in async mode"}].
accounting_async(Config) ->
eradius_test_handler:ready(),
OrigApps = set_service_pars([{async, true}, {retries, 1}, {timeout, 1000}]),

{ok, Session} = ergw_aaa_session_sup:new_session(self(),
Expand Down Expand Up @@ -267,7 +263,6 @@ accounting_async(Config) ->
attrs_3gpp() ->
[{doc, "Check encoding of 3GPP attributes"}].
attrs_3gpp(Config) ->
eradius_test_handler:ready(),

Attrs = #{
'3GPP-GGSN-Address' => {199,255,4,125},
Expand Down Expand Up @@ -318,7 +313,6 @@ attrs_3gpp(Config) ->
avp_filter() ->
[{doc, "AVP filter"}].
avp_filter(Config) ->
eradius_test_handler:ready(),

%% turn avp_filter into internal format...
Opts = ergw_aaa_radius:validate_procedure(default, all, all,
Expand All @@ -343,7 +337,6 @@ avp_filter(Config) ->
vendor_dicts() ->
[{doc, "Vendor Dicts"}].
vendor_dicts(Config) ->
eradius_test_handler:ready(),

%% turn avp_filter into internal format...
Opts = ergw_aaa_radius:validate_procedure(default, all, all,
Expand Down Expand Up @@ -386,7 +379,6 @@ vendor_dicts(Config) ->
terminate() ->
[{doc, "Simulate unexpected owner termiantion"}].
terminate(Config) ->
eradius_test_handler:ready(),

{ok, Session} = ergw_aaa_session_sup:new_session(
self(),
Expand Down Expand Up @@ -435,7 +427,6 @@ add_opts(Map, [{Par, Val}| T]) ->
add_opts(Map1, T).

simple(Config, Opts) ->
eradius_test_handler:ready(),

{ok, Session} = ergw_aaa_session_sup:new_session(
self(),
Expand Down

0 comments on commit dec5445

Please sign in to comment.