mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2025-11-01 02:48:18 +00:00
uspot: support ChilliSpot radius ratelimits
This commit introduces a helper function "ratelimit_client()", invoked
from allow_client(), which parses the radius reply for known
ratelimiting attributes:
- WISPr-Bandwidth-Max-{Up,Down}
- ChilliSpot-Bandwidth-Max-{Up,Down}
WISPr attributes are expressed in bits/s, ChilliSpot in kbits/s.
If none of the attributes are present, the function is a NOP.
If any of the -Up or -Down is missing, the corresponding limit is not
set. NB: ratelimit currently does not support setting only up OR down
ratelimiting if defaults are not set.
Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
This commit is contained in:
committed by
John Crispin
parent
23073a8ae5
commit
3384986bef
@@ -167,15 +167,34 @@ return {
|
|||||||
include('redir.uc', { redir_location: ctx.query_string.userurl });
|
include('redir.uc', { redir_location: ctx.query_string.userurl });
|
||||||
else
|
else
|
||||||
include('allow.uc', ctx);
|
include('allow.uc', ctx);
|
||||||
//data.radius.reply['WISPr-Bandwidth-Max-Up'] = "20000000";
|
|
||||||
//data.radius.reply['WISPr-Bandwidth-Max-Down'] = "10000000";
|
this.ratelimit_client(ctx, data);
|
||||||
if (data?.radius?.reply && (+data.radius.reply['WISPr-Bandwidth-Max-Up'] && +data.radius.reply['WISPr-Bandwidth-Max-Down']))
|
},
|
||||||
ctx.ubus.call('ratelimit', 'client_set', {
|
|
||||||
|
// ratelimit a client from radius reply attributes
|
||||||
|
ratelimit_client: function(ctx, data) {
|
||||||
|
if (!(data?.radius?.reply))
|
||||||
|
return;
|
||||||
|
|
||||||
|
let reply = data.radius.reply;
|
||||||
|
|
||||||
|
// check known attributes - WISPr: bps, ChiliSpot: kbps
|
||||||
|
let maxup = reply['WISPr-Bandwidth-Max-Up'] || reply['ChilliSpot-Bandwidth-Max-Up']*1000;
|
||||||
|
let maxdown = reply['WISPr-Bandwidth-Max-Down'] || reply['ChilliSpot-Bandwidth-Max-Down']*1000;
|
||||||
|
|
||||||
|
if (!(+maxdown || +maxup))
|
||||||
|
return;
|
||||||
|
|
||||||
|
let args = {
|
||||||
device: ctx.device,
|
device: ctx.device,
|
||||||
address: ctx.mac,
|
address: ctx.mac,
|
||||||
rate_egress: sprintf('%s', data.radius.reply['WISPr-Bandwidth-Max-Down']),
|
};
|
||||||
rate_ingress: sprintf('%s', data.radius.reply['WISPr-Bandwidth-Max-Up']),
|
if (+maxdown)
|
||||||
});
|
args.rate_egress = sprintf('%s', maxdown);
|
||||||
|
if (+maxup)
|
||||||
|
args.rate_ingress = sprintf('%s', maxup);
|
||||||
|
|
||||||
|
ctx.ubus.call('ratelimit', 'client_set', args);
|
||||||
},
|
},
|
||||||
|
|
||||||
// put a client back into pre-auth state
|
// put a client back into pre-auth state
|
||||||
|
|||||||
Reference in New Issue
Block a user