esockd_cidr

This commit is contained in:
Feng Lee 2016-05-23 15:21:04 +08:00
parent 820806d4f0
commit 40264564af
1 changed files with 7 additions and 7 deletions

View File

@ -108,9 +108,8 @@ load(Fd, {ok, Line}, Clients) when is_list(Line) ->
[#mqtt_auth_clientid{client_id = ClientId} | Clients]; [#mqtt_auth_clientid{client_id = ClientId} | Clients];
[ClientId, IpAddr0] -> [ClientId, IpAddr0] ->
IpAddr = string:strip(IpAddr0, right, $\n), IpAddr = string:strip(IpAddr0, right, $\n),
Range = esockd_access:range(IpAddr),
[#mqtt_auth_clientid{client_id = list_to_binary(ClientId), [#mqtt_auth_clientid{client_id = list_to_binary(ClientId),
ipaddr = {IpAddr, Range}}|Clients]; ipaddr = esockd_cidr:parse(IpAddr, true)} | Clients];
BadLine -> BadLine ->
lager:error("BadLine in clients.config: ~s", [BadLine]), lager:error("BadLine in clients.config: ~s", [BadLine]),
Clients Clients
@ -123,11 +122,12 @@ load(Fd, eof, Clients) ->
check_clientid_only(ClientId, IpAddr) -> check_clientid_only(ClientId, IpAddr) ->
case mnesia:dirty_read(?AUTH_CLIENTID_TAB, ClientId) of case mnesia:dirty_read(?AUTH_CLIENTID_TAB, ClientId) of
[] -> {error, clientid_not_found}; [] ->
[#?AUTH_CLIENTID_TAB{ipaddr = undefined}] -> ok; {error, clientid_not_found};
[#?AUTH_CLIENTID_TAB{ipaddr = {_, {Start, End}}}] -> [#?AUTH_CLIENTID_TAB{ipaddr = undefined}] ->
I = esockd_access:atoi(IpAddr), ok;
case I >= Start andalso I =< End of [#?AUTH_CLIENTID_TAB{ipaddr = CIDR}] ->
case esockd_cidr:match(IpAddr, CIDR) of
true -> ok; true -> ok;
false -> {error, wrong_ipaddr} false -> {error, wrong_ipaddr}
end end