From f5da7a6016f833ce81885c3daa66dfa52466be3c Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Thu, 7 Nov 2024 21:22:34 +0100 Subject: [PATCH] luci-base: implement Virtual Routing and Forwarding (VRF) options VRF in netifd is now in main. See: https://github.com/openwrt/netifd/pull/38/ https://github.com/openwrt/openwrt/commit/15c2ca0a834752cc9505751fc6d2f51861d34dfd VRF netifd management was added to 24.10 in https://github.com/openwrt/openwrt/pull/19125 Signed-off-by: Paul Donald --- .../luci-static/resources/icons/vrf.svg | 1 + .../resources/icons/vrf_disabled.svg | 1 + .../htdocs/luci-static/resources/network.js | 6 +++ .../luci-base/root/usr/share/rpcd/ucode/luci | 45 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 modules/luci-base/htdocs/luci-static/resources/icons/vrf.svg create mode 100644 modules/luci-base/htdocs/luci-static/resources/icons/vrf_disabled.svg diff --git a/modules/luci-base/htdocs/luci-static/resources/icons/vrf.svg b/modules/luci-base/htdocs/luci-static/resources/icons/vrf.svg new file mode 100644 index 0000000000..96ca4a7a56 --- /dev/null +++ b/modules/luci-base/htdocs/luci-static/resources/icons/vrf.svg @@ -0,0 +1 @@ + diff --git a/modules/luci-base/htdocs/luci-static/resources/icons/vrf_disabled.svg b/modules/luci-base/htdocs/luci-static/resources/icons/vrf_disabled.svg new file mode 100644 index 0000000000..7fc94520f4 --- /dev/null +++ b/modules/luci-base/htdocs/luci-static/resources/icons/vrf_disabled.svg @@ -0,0 +1 @@ + diff --git a/modules/luci-base/htdocs/luci-static/resources/network.js b/modules/luci-base/htdocs/luci-static/resources/network.js index f7c3d4b7e5..a04f4fce9e 100644 --- a/modules/luci-base/htdocs/luci-static/resources/network.js +++ b/modules/luci-base/htdocs/luci-static/resources/network.js @@ -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'); diff --git a/modules/luci-base/root/usr/share/rpcd/ucode/luci b/modules/luci-base/root/usr/share/rpcd/ucode/luci index e104225d0f..d32694788a 100644 --- a/modules/luci-base/root/usr/share/rpcd/ucode/luci +++ b/modules/luci-base/root/usr/share/rpcd/ucode/luci @@ -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 }; + } } };