Skip to content

Commit 1c97c87

Browse files
committed
Improve logging in RADIUS server and client
This commit provides the following improvements for the logging: 1. Switch to info from debug in the logging messages for the incoming requests and outgoing responses. There is no big sense in these messages anyway if everything is normal but more useful during debugging process. 2. Add logging to the RADIUS client if hostname can not be resolved. The log messages are added only to the place where we handle secondary/failover RADIUS servers to not spam with such messages. 3. Remove additional log message for the outgoing response. We already have such message from the point 1 which has everything what the removed message had except the RADIUS server name.
1 parent 25c5474 commit 1c97c87

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/eradius_client.erl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ send_request({Host, Port, Secret}, Request, Options)
6969
send_request({Host, Port, Secret}, Request, Options)
7070
when ?GOOD_CMD(Request) andalso is_list(Host) ->
7171
IP = get_ip(Host),
72-
send_request({IP, Port, Secret}, Request, Options);
72+
send_request({IP, Port, Secret}, Request, Options)
7373
send_request({IP, Port, Secret}, Request, Options) when ?GOOD_CMD(Request) andalso is_tuple(IP) ->
7474
TS1 = erlang:monotonic_time(),
7575
ServerName = proplists:get_value(server_name, Options, undefined),
@@ -435,8 +435,12 @@ store_upstream_servers(Server) ->
435435
store_radius_server_from_pool(Addr, Port, Retries) when is_tuple(Addr) and is_integer(Port) and is_integer(Retries) ->
436436
ets:insert(?MODULE, {{Addr, Port}, Retries, Retries});
437437
store_radius_server_from_pool(Addr, Port, Retries) when is_list(Addr) and is_integer(Port) and is_integer(Retries) ->
438-
IP = get_ip(Addr),
439-
ets:insert(?MODULE, {{IP, Port}, Retries, Retries});
438+
try
439+
IP = get_ip(Addr),
440+
ets:insert(?MODULE, {{IP, Port}, Retries, Retries})
441+
catch error:badarg ->
442+
?LOG(error, "Can't resolve hostname - ~p", [Addr])
443+
end;
440444
store_radius_server_from_pool(Addr, Port, Retries) ->
441445
?LOG(error, "bad RADIUS upstream server specified in RADIUS servers pool configuration ~p", [{Addr, Port, Retries}]),
442446
error(badarg).
@@ -630,6 +634,7 @@ find_suitable_peer([{Host, Port, Secret, Opts} | Pool]) when is_list(Host) ->
630634
IP = get_ip(Host),
631635
find_suitable_peer([{IP, Port, Secret, Opts} | Pool])
632636
catch _:_ ->
637+
?LOG(error, "Can't resolve hostname - ~p", [Host]),
633638
% can't resolve ip by some reasons, just ignore it
634639
find_suitable_peer(Pool)
635640
end;

src/eradius_server.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ handle_request({HandlerMod, HandlerArg}, NasProp = #nas_prop{secret = Secret, na
301301
case eradius_lib:decode_request(EncRequest, Secret) of
302302
Request = #radius_request{} ->
303303
Sender = {ServerIP, Port, Request#radius_request.reqid},
304-
?LOG(info, "~s", [eradius_log:collect_message(Sender, Request)],
304+
?LOG(debug, "~s", [eradius_log:collect_message(Sender, Request)],
305305
maps:from_list(eradius_log:collect_meta(Sender, Request))),
306306
eradius_log:write_request(Sender, Request),
307307
apply_handler_mod(HandlerMod, HandlerArg, Request, NasProp);
@@ -336,7 +336,7 @@ apply_handler_mod(HandlerMod, HandlerArg, Request, NasProp) ->
336336
EncReply = eradius_lib:encode_reply(Request#radius_request{cmd = ReplyCmd, attrs = ReplyAttrs,
337337
msg_hmac = Request#radius_request.msg_hmac or MsgHMAC or (size(EAPmsg) > 0),
338338
eap_msg = EAPmsg}),
339-
?LOG(info, "~s", [eradius_log:collect_message(Sender, Reply)],
339+
?LOG(debug, "~s", [eradius_log:collect_message(Sender, Reply)],
340340
maps:from_list(eradius_log:collect_meta(Sender, Reply))),
341341
eradius_log:write_request(Sender, Reply),
342342
{reply, EncReply, {Request#radius_request.cmd, ReplyCmd}, Request};

0 commit comments

Comments
 (0)