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