luci-base: implement Virtual Routing and Forwarding (VRF) options

VRF in netifd is now in main. See:
https://github.com/openwrt/netifd/pull/38/
15c2ca0a83

VRF netifd management was added to 24.10 in
https://github.com/openwrt/openwrt/pull/19125

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
pull/7484/merge
Paul Donald 2024-11-07 21:22:34 +01:00
parent b44f141e37
commit f5da7a6016
No known key found for this signature in database
GPG Key ID: 3FC4A933962871D2
4 changed files with 53 additions and 0 deletions

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 13 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@ -2956,6 +2956,7 @@ Device = baseclass.extend(/** @lends LuCI.network.Device.prototype */ {
* - `bridge` if it is a bridge device (e.g. `br-lan`)
* - `tunnel` if it is a tun or tap device (e.g. `tun0`)
* - `vlan` if it is a vlan device (e.g. `eth0.1`)
* - `vrf` if it is a Virtual Routing and Forwarding type (e.g. `vrf0`)
* - `switch` if it is a switch device (e.g.`eth1` connected to switch0)
* - `ethernet` for all other device types
*/
@ -2978,6 +2979,8 @@ Device = baseclass.extend(/** @lends LuCI.network.Device.prototype */ {
return 'vlan';
else if (this.config.type == 'bridge')
return 'bridge';
else if (this.config.type == 'vrf')
return 'vrf';
else
return 'ethernet';
},
@ -3032,6 +3035,9 @@ Device = baseclass.extend(/** @lends LuCI.network.Device.prototype */ {
case 'bridge':
return _('Bridge');
case 'vrf':
return _('Virtual Routing and Forwarding (VRF)');
case 'switch':
return (_state.netdevs[this.device] && _state.netdevs[this.device].devtype == 'dsa')
? _('Switch port') : _('Ethernet Switch');

View File

@ -17,6 +17,34 @@ function shellquote(s) {
return `'${replace(s, "'", "'\\''")}'`;
}
function callPackageVersionCheck(pkg) {
let version = "";
if ( access('/bin/opkg') ) {
// <= v24.10
let fd = popen('opkg list-installed ' + pkg + ' 2>/dev/null');
if (fd) {
const re = regexp('^' + pkg + ' - (.+)$', 's');
const m = match(fd.read('all'), re);
version = m?.[1];
fd.close();
}
}
else if ( access('/usr/bin/apk') ) {
// > v24.10
let fd = popen('apk list -I ' + pkg + ' 2>/dev/null');
if (fd) {
const re = regexp('^' + pkg + '-(.+)$', 's');
const m = match(fd.read('all'), re);
version = m?.[1];
fd.close();
}
}
return version;
}
const methods = {
getVersion: {
call: function(request) {
@ -210,6 +238,8 @@ const methods = {
relayd: access('/usr/sbin/relayd') == true,
apk: access('/usr/bin/apk') == true,
wifi: access('/sbin/wifi') == true,
vrf: access('/sys/module/vrf/refcnt') == true, // vrf.ko is loaded
netifd_vrf: false,
};
const wifi_features = [ 'eap', '11ac', '11ax', '11be', '11r', 'acs', 'sae', 'owe', 'suiteb192', 'wep', 'wps', 'ocv' ];
@ -243,6 +273,9 @@ const methods = {
fd.close();
}
// This check can be removed after v25 release
result.netifd_vrf = match(callPackageVersionCheck('netifd'), /^20[0-9][0-9]/s)?.[0] >= 2025;
fd = popen('ipset --help 2>/dev/null');
if (fd) {
@ -585,6 +618,18 @@ const methods = {
return { result: ports };
}
},
packageVersionCheck: {
args: { name: 'netifd' },
call: function(request) {
let version = "";
const pkg = request?.args?.name;
version = callPackageVersionCheck(pkg);
return { result: version };
}
}
};