esockd_cidr

This commit is contained in:
Feng Lee 2016-05-23 15:20:56 +08:00
parent b90a8adbba
commit 820806d4f0
1 changed files with 4 additions and 6 deletions

View File

@ -19,7 +19,7 @@
-include("emqttd.hrl").
-type who() :: all | binary() |
{ipaddr, esockd_access:cidr()} |
{ipaddr, esockd_cidr:cidr_string()} |
{client, binary()} |
{user, binary()}.
@ -51,8 +51,7 @@ compile({A, Who, Access, TopicFilters}) when ?ALLOW_DENY(A) ->
compile(who, all) ->
all;
compile(who, {ipaddr, CIDR}) ->
{Start, End} = esockd_access:range(CIDR),
{ipaddr, {CIDR, Start, End}};
{ipaddr, esockd_cidr:parse(CIDR, true)};
compile(who, {client, all}) ->
{client, all};
compile(who, {client, ClientId}) ->
@ -107,9 +106,8 @@ match_who(#mqtt_client{username = Username}, {user, Username}) ->
true;
match_who(#mqtt_client{peername = undefined}, {ipaddr, _Tup}) ->
false;
match_who(#mqtt_client{peername = {IP, _}}, {ipaddr, {_CDIR, Start, End}}) ->
I = esockd_access:atoi(IP),
I >= Start andalso I =< End;
match_who(#mqtt_client{peername = {IP, _}}, {ipaddr, CIDR}) ->
esockd_cidr:match(IP, CIDR);
match_who(Client, {'and', Conds}) when is_list(Conds) ->
lists:foldl(fun(Who, Allow) ->
match_who(Client, Who) andalso Allow