Skip to content

Commit

Permalink
ratelimit: delete iface data when a radio gets restarted
Browse files Browse the repository at this point in the history
Fixes: WIFI-14050
Signed-off-by: John Crispin <john@phrozen.org>
  • Loading branch information
blogic committed Sep 17, 2024
1 parent cf59956 commit ddbf50b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 20 additions & 1 deletion feeds/ucentral/ratelimit/files/usr/bin/ratelimit
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function macfilter_del(iface, id) {
}

function linux_client_del(device, client) {
printf('-> linux_client_del\n');
let ifbdev = ifb_dev(device.name);
let id = client.id + 3;

Expand All @@ -72,6 +73,7 @@ function linux_client_del(device, client) {
}

function linux_client_set(device, client) {
printf('-> linux_client_set\n');
let ifbdev = ifb_dev(device.name);
let id = client.id + 3;

Expand All @@ -92,6 +94,7 @@ function linux_client_set(device, client) {
let ops = {
device: {
add: function(name) {
printf('-> device.add\n');
let ifbdev = ifb_dev(name);

qdisc_del(name);
Expand All @@ -109,22 +112,26 @@ let ops = {
return ret;
},
remove: function(name) {
printf('-> device.remove\n');
let ifbdev = ifb_dev(name);
qdisc_del(name);
ifb_del(name, ifbdev);
}
},
client: {
set: function(device, client) {
printf('-> client.set\n');
return linux_client_set(device, client);
},
remove: function(device, client) {
printf('-> client.remove\n');
linux_client_del(device, client);
}
}
};

function get_device(devices, name) {
printf('-> get_device\n');
let device = devices[name];

if (device)
Expand All @@ -145,13 +152,15 @@ function get_device(devices, name) {
}

function del_device(name) {
printf('-> del_device\n');
if (!devices[name])
return;
ops.device.remove(name);
delete devices[name];
}

function get_free_idx(list) {
printf('-> get_free_idx\n');
for (let i = 0; i < length(list); i++)
if (list[i] == null)
return i;
Expand All @@ -160,6 +169,8 @@ function get_free_idx(list) {
}

function del_client(device, address) {
printf('-> del_client\n');

let client = device.clients[address];

if (!client)
Expand All @@ -173,6 +184,7 @@ function del_client(device, address) {
}

function get_client(device, address) {
printf('-> get_client\n');
let client = device.clients[address];

if (client)
Expand All @@ -191,6 +203,7 @@ function get_client(device, address) {
}

function set_client(device, client, data) {
printf('-> set_client\n');
let update = false;

for (let key in data) {
Expand All @@ -214,6 +227,7 @@ function run_service() {
uctx.publish("ratelimit", {
flush: {
call: function(req) {
printf('-> flush\n');
defaults = {};
},
args: {
Expand All @@ -222,6 +236,7 @@ function run_service() {
},
defaults_set: {
call: function(req) {
printf('-> defaults_set\n');
let r_i = req.args.rate_ingress ?? req.args.rate;
let r_e = req.args.rate_egress ?? req.args.rate;
let name = req.args.name;
Expand All @@ -242,6 +257,7 @@ function run_service() {
},
client_set: {
call: function(req) {
printf('-> client_set\n');
let r_i = req.args.rate_ingress ?? req.args.rate;
let r_e = req.args.rate_egress ?? req.args.rate;

Expand Down Expand Up @@ -284,6 +300,7 @@ function run_service() {
},
client_delete: {
call: function(req) {
printf('-> client_delete\n');
if (!req.args.address)
return ubus.STATUS_INVALID_ARGUMENT;

Expand Down Expand Up @@ -311,6 +328,7 @@ function run_service() {
},
device_delete: {
call: function(req) {
printf('-> device_delete\n');
let name = req.args.device;

if (!name)
Expand All @@ -329,6 +347,7 @@ function run_service() {
},
reload: {
call: function(req) {
printf('-> reload\n');
let list = uctx.list();
for (let obj in list) {
if (!wildcard(obj, 'hostapd.wlan*'))
Expand Down Expand Up @@ -356,7 +375,7 @@ function run_service() {
},
dump: {
call: function(req) {
return devices;
return { devices, defaults };
},
args: {}
}
Expand Down
6 changes: 6 additions & 0 deletions feeds/ucentral/ucentral-event/files/ucentral-event
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ function hostapd_remove(path, obj) {
hostapd_event(ifname, 'stop');
printf('removing %s\n', path);
delete hostapd[ifname];
if (ratelimit) {
let msg = {
device: ifname,
};
ubus.call('ratelimit', 'device_delete', msg);
}
}

function hapd_subscriber_remove_cb(remove) {
Expand Down

0 comments on commit ddbf50b

Please sign in to comment.