fw4.uc: fix zone helper assignment
[project/firewall4.git] / root / usr / share / ucode / fw4.uc
index 64439504be49a33566fa43fc49f38a49d9acdbb8..a3384466538fe1298da55611b6294527f46bc7c7 100644 (file)
@@ -462,17 +462,15 @@ return {
                                for (let device in zone.related_physdevs)
                                        push(devices, ...resolve_lower_devices(devstatus, device, true));
 
-                       if (length(devices)) {
-                               devices = sort(uniq(devices));
+                       devices = sort(uniq(devices));
 
-                               if (nft_try_hw_offload(devices))
-                                       return devices;
+                       if (length(devices) && 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;
+                       this.warn('Hardware flow offloading unavailable, falling back to software offloading');
+                       this.state.defaults.flow_offloading_hw = false;
 
-                               devices = [];
-                       }
+                       devices = [];
                }
 
                for (let zone in this.zones())
@@ -840,6 +838,7 @@ return {
                                        return null;
 
                                m = to_mask(b, length(a) == 16);
+                               b = max(-1, b);
                        }
 
                        return [{
@@ -1239,26 +1238,21 @@ return {
        },
 
        parse_date: function(val) {
-               let m = match(val, /^([0-9-]+)T([0-9:]+)$/);
-               let d = m ? match(m[1], /^([0-9]{1,4})(-([0-9]{1,2})(-([0-9]{1,2}))?)?$/) : null;
-               let t = this.parse_time(m[2]);
-
-               d[3] ||= 1;
-               d[5] ||= 1;
+               let d = match(val, /^([0-9]{4})(-([0-9]{1,2})(-([0-9]{1,2})(T([0-9:]+))?)?)?$/);
 
-               if (d == null || d[1] < 1970 || d[1] > 2038 || d[3] < 1 || d[3] > 12 || d[5] < 1 || d[5] > 31)
+               if (d == null || d[1] < 1970 || d[1] > 2038 || d[3] > 12 || d[5] > 31)
                        return null;
 
-               if (m[2] && !t)
+               let t = this.parse_time(d[7] ?? "0");
+
+               if (t == null)
                        return null;
 
                return {
                        year:  +d[1],
-                       month: +d[3],
-                       day:   +d[5],
-                       hour:  t ? +t[1] : 0,
-                       min:   t ? +t[3] : 0,
-                       sec:   t ? +t[5] : 0
+                       month: +d[3] || 1,
+                       day:   +d[5] || 1,
+                       ...t
                };
        },
 
@@ -1644,6 +1638,10 @@ return {
                return sprintf('"%04d-%02d-%02d"', stamp.year, stamp.month, stamp.day);
        },
 
+       datestamp: function(stamp) {
+               return exists(stamp, 'hour') ? this.datetime(stamp) : this.date(stamp);
+       },
+
        time: function(stamp) {
                return sprintf('"%02d:%02d:%02d"', stamp.hour, stamp.min, stamp.sec);
        },
@@ -1883,9 +1881,12 @@ return {
                        this.warn_section(data, "is disabled, ignoring section");
                        return;
                }
-               else if (zone.helper && !zone.helper.available) {
-                       this.warn_section(data, `uses unavailable ct helper '${zone.helper.name}', ignoring section`);
-                       return;
+
+               for (let helper in zone.helper) {
+                       if (!helper.available) {
+                               this.warn_section(data, `uses unavailable ct helper '${zone.helper.name}', ignoring section`);
+                               return;
+                       }
                }
 
                if (zone.mtu_fix && this.kernel < 0x040a0000) {