ucentral-event: add wired events

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-02-20 12:03:32 +01:00
parent 60f6565d18
commit 993ff2624e
3 changed files with 32 additions and 3 deletions

View File

@@ -2,5 +2,6 @@
"ssh",
"health","health.dns", "health.dhcp", "health.radius", "health.memory",
"client", "client.join", "client.leave", "client.key-mismatch",
"wifi", "wifi.start", "wifi.stop"
"wifi", "wifi.start", "wifi.stop",
"wired", "wired.carrier-up", "wired.carrier-down"
]

View File

@@ -7,6 +7,14 @@ import * as libuci from 'uci';
import * as uloop from 'uloop';
import * as nl80211 from 'nl80211';
import * as rtnl from 'rtnl';
import * as fs from 'fs';
let capab = {};
let capabfile = fs.open("/etc/ucentral/capabilities.json", "r");
if (capabfile) {
capab = json(capabfile.read("all"));
capabfile.close();
}
uloop.init();
@@ -20,6 +28,7 @@ let log_subscriber;
let ratelimit = false;
let config;
let wan_ports;
let carrier = {};
function config_load() {
uci.load('event');
@@ -255,8 +264,27 @@ function nl_cb(msg) {
event('client', 'leave', payload);
}
function ifname_lookup(prefix, ifname, list) {
let idx = index(list, ifname);
if (idx < 0)
return;
return prefix + (idx + 1);
}
function rtnl_cb(msg) {
printf('%.J\n', msg);
if (!exists(msg.msg, "carrier"))
return;
let name = ifname_lookup('LAN', msg.msg?.ifname, capab.network?.lan);
if (!name)
name = ifname_lookup('WAN', msg.msg?.ifname, capab.network?.wan);
if (name) {
let verb = msg.msg.carrier ? 'carrier-up' : 'carrier-down';
if (carrier[name] == verb)
return;
carrier[name] = verb;
event('wired', verb, { name });
}
}
let ubus_methods = {

View File

@@ -81,7 +81,7 @@
"types": [ "ssh", "health", "wifi" ]
},
"realtime": {
"types": [ "client.join", "client.leave", "client.key-mismatch" ]
"types": [ "client.join", "client.leave", "client.key-mismatch", "wired" ]
},
"health": {
"interval": 120