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:
Thibaut VARÈNE
2023-05-22 16:48:20 +02:00
committed by John Crispin
parent 23073a8ae5
commit 3384986bef

View File

@@ -167,15 +167,34 @@ return {
include('redir.uc', { redir_location: ctx.query_string.userurl });
else
include('allow.uc', ctx);
//data.radius.reply['WISPr-Bandwidth-Max-Up'] = "20000000";
//data.radius.reply['WISPr-Bandwidth-Max-Down'] = "10000000";
if (data?.radius?.reply && (+data.radius.reply['WISPr-Bandwidth-Max-Up'] && +data.radius.reply['WISPr-Bandwidth-Max-Down']))
ctx.ubus.call('ratelimit', 'client_set', {
device: ctx.device,
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']),
});
this.ratelimit_client(ctx, data);
},
// 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,
address: ctx.mac,
};
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