1
0
Fork 0
forked from mirror/openwrt

netifd/wifi-scripts: use shared global connection for ubus

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau 2025-09-17 12:27:31 +02:00
parent 6834c19e41
commit bd80c05c11
3 changed files with 13 additions and 15 deletions

View file

@ -1,6 +1,6 @@
import * as uci from "uci";
import * as uloop from "uloop";
import * as libubus from "ubus";
import * as ubus from "ubus";
import { access, dirname } from "fs";
function ex_handler(e)
@ -9,9 +9,8 @@ function ex_handler(e)
}
uloop.guard(ex_handler);
libubus.guard(ex_handler);
ubus.guard(ex_handler);
let ubus = netifd.ubus = libubus.connect();
let wireless;
function uci_ctx()

View file

@ -1,5 +1,5 @@
'use strict';
import * as libubus from "ubus";
import * as ubus from "ubus";
import * as uloop from "uloop";
import { is_equal } from "./utils.uc";
import { access } from "fs";
@ -465,22 +465,22 @@ function wdev_set_data(wdev, vif, vlan, data)
let cur = wdev;
let cur_type = "device";
if (!config)
return libubus.STATUS_INVALID_ARGUMENT;
return ubus.STATUS_INVALID_ARGUMENT;
if (vif) {
cur = vif = config.interfaces[vif];
if (!vif)
return libubus.STATUS_NOT_FOUND;
return ubus.STATUS_NOT_FOUND;
cur_type = "vif";
}
if (vlan) {
if (!vif)
return libubus.STATUS_INVALID_ARGUMENT;
return ubus.STATUS_INVALID_ARGUMENT;
cur = vlan = vif.vlans[vlan];
if (!vlan)
return libubus.STATUS_NOT_FOUND;
return ubus.STATUS_NOT_FOUND;
cur_type = "vlan";
}
@ -504,7 +504,7 @@ function notify(req)
switch (req.args.command) {
case NOTIFY_CMD_UP:
if (vif || vlan || this.state != "setup")
return libubus.STATUS_INVALID_ARGUMENT;
return ubus.STATUS_INVALID_ARGUMENT;
return wdev_mark_up(this);
case NOTIFY_CMD_SET_DATA:
@ -522,7 +522,7 @@ function notify(req)
this.retry = DEFAULT_RETRY;
return 0;
default:
return libubus.STATUS_INVALID_ARGUMENT;
return ubus.STATUS_INVALID_ARGUMENT;
}
}

View file

@ -1,6 +1,6 @@
'use strict';
import * as libubus from "ubus";
import * as ubus from "ubus";
import { realpath } from "fs";
import {
handler_load, handler_attributes,
@ -9,7 +9,6 @@ import {
} from "./utils.uc";
import * as wdev from "./wireless-device.uc";
let ubus = netifd.ubus;
let wireless = netifd.wireless = {
handlers: {},
devices: {},
@ -348,7 +347,7 @@ function wdev_call(req, cb)
if (dev) {
dev = wireless.devices[dev];
if (!dev)
return libubus.STATUS_NOT_FOUND;
return ubus.STATUS_NOT_FOUND;
return cb(dev);
}
@ -459,11 +458,11 @@ const ubus_obj = {
call: function(req) {
let dev = req.args.device;
if (!dev)
return libubus.STATUS_INVALID_ARGUMENT;
return ubus.STATUS_INVALID_ARGUMENT;
dev = wireless.devices[dev];
if (!dev)
return libubus.STATUS_NOT_FOUND;
return ubus.STATUS_NOT_FOUND;
return dev.notify(req);
}