From 8169f482fd0bb6d711e571e01e565bcc3165469d Mon Sep 17 00:00:00 2001 From: Vladislav Grigoryev Date: Sat, 18 Nov 2023 20:55:45 +0300 Subject: [PATCH] luci-app-firewall: allow redirects using ip family any Allow creating redirects using IP family `any`. This helps redirect both IPv4 and IPv6 traffic. It is used to intercept traffic on the router. Signed-off-by: Vladislav Grigoryev --- .../luci-static/resources/view/firewall/forwards.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js index 4b8e6bf604..70713be599 100644 --- a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js +++ b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js @@ -9,7 +9,7 @@ 'require tools.widgets as widgets'; function rule_proto_txt(s, ctHelpers) { - var family = (uci.get('firewall', s, 'family') || '').toLowerCase().replace(/^(?:any|\*)$/, ''); + var family = (uci.get('firewall', s, 'family') || '').toLowerCase().replace(/^(?:all|\*)$/, 'any'); var dip = uci.get('firewall', s, 'dest_ip') || ''; var proto = L.toArray(uci.get('firewall', s, 'proto')).filter(function(p) { return (p != '*' && p != 'any' && p != 'all'); @@ -38,8 +38,8 @@ function rule_proto_txt(s, ctHelpers) { } : null; return fwtool.fmt(_('Incoming %{ipv6?%{ipv4?IPv4 and IPv6:IPv6}:IPv4}%{proto?, protocol %{proto#%{next?, }%{item.types?%{item.name}ICMP with types %{item.types#%{next?, }%{item}}:%{item.name}}}}%{mark?, mark %{mark.val}}%{helper?, helper %{helper.inv?%{helper.val}:%{helper.val}}}'), { - ipv4: ((!family && dip.indexOf(':') == -1) || family == 'ipv4'), - ipv6: ((!family && dip.indexOf(':') != -1) || (!family && !dip) || family == 'ipv6'), + ipv4: ((!family && dip.indexOf(':') == -1) || family == 'any' || (!family && !dip) || family == 'ipv4'), + ipv6: ((!family && dip.indexOf(':') != -1) || family == 'any' || family == 'ipv6'), proto: proto, helper: h, mark: f @@ -101,7 +101,7 @@ function validate_opt_family(m, section_id, opt) { var dip = dopt.formvalue(section_id) || '', fm = fmopt.formvalue(section_id) || ''; - if (fm == '' || (fm == 'ipv6' && (dip.indexOf(':') != -1 || dip == '')) || (fm == 'ipv4' && dip.indexOf(':') == -1)) + if (fm == '' || (fm == 'any' && dip == '') || (fm == 'ipv6' && (dip.indexOf(':') != -1 || dip == '')) || (fm == 'ipv4' && dip.indexOf(':') == -1)) return true; return _('Address family, Internal IP address must match'); @@ -187,14 +187,17 @@ return view.extend({ o = s.taboption('general', form.ListValue, 'family', _('Restrict to address family')); o.modalonly = true; o.rmempty = true; + o.value('any', _('IPv4 and IPv6')); o.value('ipv4', _('IPv4 only')); o.value('ipv6', _('IPv6 only')); o.value('', _('automatic')); // infer from zone or used IP addresses o.cfgvalue = function(section_id) { var val = this.map.data.get(this.map.config, section_id, 'family'); - if (!val || val == 'any' || val == 'all' || val == '*') + if (!val) return ''; + else if (val == 'any' || val == 'all' || val == '*') + return 'any'; else if (val == 'inet' || String(val).indexOf('4') != -1) return 'ipv4'; else if (String(val).indexOf('6') != -1) -- 2.30.2