return fields;
}
-function determine_device_type(devname) {
- let uevent = fs.open(`/sys/class/net/${devname}/uevent`),
- devtype = null;
-
- if (uevent) {
- let line;
-
- while ((line = uevent.read('line')) != null) {
- let m = match(line, /^DEVTYPE=(\w+)/);
-
- if (m) {
- devtype = m[1];
- break;
- }
- }
-
- uevent.close();
- }
-
- return devtype;
-}
-
-function resolve_lower_devices(devname) {
- switch (determine_device_type(devname)) {
- case null:
- return [];
-
- case 'vlan':
- case 'bridge':
- let dir = fs.opendir(`/sys/class/net/${devname}`);
- let lower = [];
-
- if (dir) {
+function resolve_lower_devices(devstatus, devname, require_hwoffload) {
+ let dir = fs.opendir(`/sys/class/net/${devname}`);
+ let devs = [];
+
+ if (dir) {
+ switch (devstatus[devname]?.devtype) {
+ case 'vlan':
+ case 'bridge':
let e;
while ((e = dir.read()) != null)
if (index(e, "lower_") === 0)
- push(lower, ...resolve_lower_devices(substr(e, 6)));
+ push(devs, ...resolve_lower_devices(devstatus, substr(e, 6), require_hwoffload));
- dir.close();
- }
+ break;
+
+ default:
+ if (!require_hwoffload || devstatus[devname]?.["hw-tc-offload"])
+ push(devs, devname);
- return lower;
+ break;
+ }
- default:
- return [ devname ];
+ dir.close();
}
+
+ return devs;
}
function nft_json_command(...args) {
},
resolve_offload_devices: function() {
+ if (!this.default_option("flow_offloading"))
+ return [];
+
+ let devstatus = null;
let devices = [];
+ let bus = ubus.connect();
- if (this.default_option("flow_offloading")) {
+ if (bus) {
+ devstatus = bus.call("network.device", "status") || {};
+ bus.disconnect();
+ }
+
+ if (this.default_option("flow_offloading_hw")) {
for (let zone in this.zones())
for (let device in zone.related_physdevs)
- push(devices, ...resolve_lower_devices(device));
+ push(devices, ...resolve_lower_devices(devstatus, device, true));
if (length(devices)) {
devices = sort(uniq(devices));
- if (this.default_option("flow_offloading_hw") && !nft_try_hw_offload(devices)) {
- this.warn('Hardware flow offloading unavailable, falling back to software offloading');
- this.state.defaults.flow_offloading_hw = false;
- }
+ if (nft_try_hw_offload(devices))
+ return devices;
+
+ this.warn('Hardware flow offloading unavailable, falling back to software offloading');
+ this.state.defaults.flow_offloading_hw = false;
+
+ devices = [];
}
}
- return devices;
+ for (let zone in this.zones())
+ for (let device in zone.related_physdevs)
+ push(devices, ...resolve_lower_devices(devstatus, device, false));
+
+ return sort(uniq(devices));
},
check_set_types: function() {
[!] Section @defaults[0] specifies unknown option 'unknown_defaults_option'
[!] Section @rule[9] (Test-Deprecated-Rule-Option) option '_name' is deprecated by fw4
[!] Section @rule[9] (Test-Deprecated-Rule-Option) specifies unknown option 'unknown_rule_option'
-[call] fs.open path </sys/class/net/br-lan/uevent> mode <null>
+[call] ctx.call object <network.device> method <status> args <null>
[call] fs.opendir path </sys/class/net/br-lan>
-[call] fs.open path </sys/class/net/eth0/uevent> mode <null>
-[call] fs.open path </sys/class/net/eth1/uevent> mode <null>
+[call] fs.opendir path </sys/class/net/eth0>
+[call] fs.opendir path </sys/class/net/eth1>
[call] system command </usr/sbin/nft -c '
add table inet fw4-hw-offload-test;
add flowtable inet fw4-hw-offload-test ft {