7 'require tools.widgets as widgets';
10 callOffloadSupport: rpc.declare({
12 method: 'offload_support',
13 expect: { offload_support: false }
16 callConntrackHelpers: rpc.declare({
18 method: 'conntrack_helpers',
19 expect: { helpers: [] }
24 this.callOffloadSupport(),
25 this.callConntrackHelpers()
29 render: function(data) {
30 var hasOffloading = data[0],
34 m = new form.Map('firewall', _('Firewall - Zone Settings'),
35 _('The firewall creates zones over your network interfaces to control network traffic flow.'));
37 s = m.section(form.TypedSection, 'defaults', _('General Settings'));
41 o = s.option(form.Flag, 'syn_flood', _('Enable SYN-flood protection'));
42 o = s.option(form.Flag, 'drop_invalid', _('Drop invalid packets'));
45 s.option(form.ListValue, 'input', _('Input')),
46 s.option(form.ListValue, 'output', _('Output')),
47 s.option(form.ListValue, 'forward', _('Forward'))
50 for (var i = 0; i < p.length; i++) {
51 p[i].value('REJECT', _('reject'));
52 p[i].value('DROP', _('drop'));
53 p[i].value('ACCEPT', _('accept'));
56 /* Netfilter flow offload support */
59 s = m.section(form.TypedSection, 'defaults', _('Routing/NAT Offloading'),
60 _('Experimental feature. Not fully compatible with QoS/SQM.'));
65 o = s.option(form.Flag, 'flow_offloading',
66 _('Software flow offloading'),
67 _('Software based offloading for routing/NAT'));
70 o = s.option(form.Flag, 'flow_offloading_hw',
71 _('Hardware flow offloading'),
72 _('Requires hardware NAT support. Implemented at least for mt7621'));
74 o.depends('flow_offloading', '1');
78 s = m.section(form.GridSection, 'zone', _('Zones'));
83 s.tab('general', _('General Settings'));
84 s.tab('advanced', _('Advanced Settings'));
85 s.tab('conntrack', _('Conntrack Settings'));
86 s.tab('extra', _('Extra iptables arguments'));
88 o = s.taboption('general', form.DummyValue, '_generalinfo');
91 o.cfgvalue = function(section_id) {
92 var name = uci.get('firewall', section_id, 'name');
94 return _('This section defines common properties of %q. The <em>input</em> and <em>output</em> options set the default policies for traffic entering and leaving this zone while the <em>forward</em> option describes the policy for forwarded traffic between different networks within the zone. <em>Covered networks</em> specifies which available networks are members of this zone.')
95 .replace(/%s/g, name).replace(/%q/g, '"' + name + '"');
98 o = s.taboption('general', form.Value, 'name', _('Name'));
99 o.placeholder = _('Unnamed zone');
101 o.datatype = 'and(uciname,maxlength(11))';
102 o.write = function(section_id, formvalue) {
103 var cfgvalue = this.cfgvalue(section_id);
105 if (cfgvalue != formvalue)
106 return firewall.renameZone(cfgvalue, formvalue);
109 o = s.option(widgets.ZoneForwards, '_info', _('Zone ⇒ Forwardings'));
112 o.cfgvalue = function(section_id) {
113 return uci.get('firewall', section_id, 'name');
117 s.taboption('general', form.ListValue, 'input', _('Input')),
118 s.taboption('general', form.ListValue, 'output', _('Output')),
119 s.taboption('general', form.ListValue, 'forward', _('Forward'))
122 for (var i = 0; i < p.length; i++) {
123 p[i].value('REJECT', _('reject'));
124 p[i].value('DROP', _('drop'));
125 p[i].value('ACCEPT', _('accept'));
126 p[i].editable = true;
129 o = s.taboption('general', form.Flag, 'masq', _('Masquerading'));
132 o = s.taboption('general', form.Flag, 'mtu_fix', _('MSS clamping'));
135 o = s.taboption('general', widgets.NetworkSelect, 'network', _('Covered networks'));
138 o.write = function(section_id, formvalue) {
139 var name = uci.get('firewall', section_id, 'name'),
140 cfgvalue = this.cfgvalue(section_id);
142 if (typeof(cfgvalue) == 'string' && Array.isArray(formvalue) && (cfgvalue == formvalue.join(' ')))
145 var tasks = [ firewall.getZone(name) ];
147 if (Array.isArray(formvalue))
148 for (var i = 0; i < formvalue.length; i++) {
149 var netname = formvalue[i];
150 tasks.push(network.getNetwork(netname).then(function(net) {
151 return net || network.addNetwork(netname, { 'proto': 'none' });
155 return Promise.all(tasks).then(function(zone_networks) {
156 if (zone_networks[0])
157 for (var i = 1; i < zone_networks.length; i++)
158 zone_networks[0].addNetwork(zone_networks[i].getName());
161 o.remove = function(section_id) {
162 return uci.set('firewall', section_id, 'network', ' ');
165 o = s.taboption('advanced', form.DummyValue, '_advancedinfo');
168 o.cfgvalue = function(section_id) {
169 var name = uci.get('firewall', section_id, 'name');
171 return _('The options below control the forwarding policies between this zone (%s) and other zones. <em>Destination zones</em> cover forwarded traffic <strong>originating from %q</strong>. <em>Source zones</em> match forwarded traffic from other zones <strong>targeted at %q</strong>. The forwarding rule is <em>unidirectional</em>, e.g. a forward from lan to wan does <em>not</em> imply a permission to forward from wan to lan as well.')
175 o = s.taboption('advanced', widgets.DeviceSelect, 'device', _('Covered devices'), _('Use this option to classify zone traffic by raw, non-<em>uci</em> managed network devices.'));
179 o = s.taboption('advanced', form.DynamicList, 'subnet', _('Covered subnets'), _('Use this option to classify zone traffic by source or destination subnet instead of networks or devices.'));
180 o.datatype = 'neg(cidr)';
184 o = s.taboption('advanced', form.ListValue, 'family', _('Restrict to address family'));
185 o.value('', _('IPv4 and IPv6'));
186 o.value('ipv4', _('IPv4 only'));
187 o.value('ipv6', _('IPv6 only'));
190 o = s.taboption('advanced', form.DynamicList, 'masq_src', _('Restrict Masquerading to given source subnets'));
191 o.depends('family', '');
192 o.depends('family', 'ipv4');
193 o.datatype = 'list(neg(or(uciname,hostname,ipmask4)))';
194 o.placeholder = '0.0.0.0/0';
197 o = s.taboption('advanced', form.DynamicList, 'masq_dest', _('Restrict Masquerading to given destination subnets'));
198 o.depends('family', '');
199 o.depends('family', 'ipv4');
200 o.datatype = 'list(neg(or(uciname,hostname,ipmask4)))';
201 o.placeholder = '0.0.0.0/0';
204 o = s.taboption('conntrack', form.Flag, 'conntrack', _('Force connection tracking'), _('Prevent the installation of <em>NOTRACK</em> rules which would bypass connection tracking.'));
207 o = s.taboption('conntrack', form.Flag, 'masq_allow_invalid', _('Allow "invalid" traffic'), _('Do not install extra rules to reject forwarded traffic with conntrack state <em>invalid</em>. This may be required for complex asymmetric route setups.'));
210 o = s.taboption('conntrack', form.Flag, 'auto_helper', _('Automatic helper assignment'), _('Automatically assign conntrack helpers based on traffic protocol and port'));
211 o.default = o.enabled;
214 o = s.taboption('conntrack', form.MultiValue, 'helper', _('Conntrack helpers'), _('Explicitly choses allowed connection tracking helpers for zone traffic'));
215 o.depends('auto_helper', '0');
217 for (var i = 0; i < ctHelpers.length; i++)
218 o.value(ctHelpers[i].name, '<span class="hide-close">%s (%s)</span><span class="hide-open">%s</span>'.format(ctHelpers[i].description, ctHelpers[i].name.toUpperCase(), ctHelpers[i].name.toUpperCase()));
220 o = s.taboption('advanced', form.Flag, 'log', _('Enable logging on this zone'));
223 o = s.taboption('advanced', form.Value, 'log_limit', _('Limit log messages'));
224 o.depends('log', '1');
225 o.placeholder = '10/minute';
228 o = s.taboption('extra', form.DummyValue, '_extrainfo');
231 o.cfgvalue = function(section_id) {
232 return _('Passing raw iptables arguments to source and destination traffic classification rules allows to match packets based on other criteria than interfaces or subnets. These options should be used with extreme care as invalid values could render the firewall ruleset broken, completely exposing all services.');
235 o = s.taboption('extra', form.Value, 'extra_src', _('Extra source arguments'), _('Additional raw <em>iptables</em> arguments to classify zone source traffic, e.g. <code>-p tcp --sport 443</code> to only match inbound HTTPS traffic.'));
237 o.cfgvalue = function(section_id) {
238 return uci.get('firewall', section_id, 'extra_src') || uci.get('firewall', section_id, 'extra');
240 o.write = function(section_id, value) {
241 uci.unset('firewall', section_id, 'extra');
242 uci.set('firewall', section_id, 'extra_src', value);
245 o = s.taboption('extra', form.Value, 'extra_dest', _('Extra destination arguments'), _('Additional raw <em>iptables</em> arguments to classify zone destination traffic, e.g. <code>-p tcp --dport 443</code> to only match outbound HTTPS traffic.'));
247 o.cfgvalue = function(section_id) {
248 return uci.get('firewall', section_id, 'extra_dest') || uci.get('firewall', section_id, 'extra_src') || uci.get('firewall', section_id, 'extra');
250 o.write = function(section_id, value) {
251 uci.unset('firewall', section_id, 'extra');
252 uci.set('firewall', section_id, 'extra_dest', value);
255 o = s.taboption('general', form.DummyValue, '_forwardinfo');
258 o.cfgvalue = function(section_id) {
259 return _('The options below control the forwarding policies between this zone (%s) and other zones. <em>Destination zones</em> cover forwarded traffic <strong>originating from %q</strong>. <em>Source zones</em> match forwarded traffic from other zones <strong>targeted at %q</strong>. The forwarding rule is <em>unidirectional</em>, e.g. a forward from lan to wan does <em>not</em> imply a permission to forward from wan to lan as well.')
260 .format(uci.get('firewall', section_id, 'name'));
263 out = o = s.taboption('general', widgets.ZoneSelect, 'out', _('Allow forward to <em>destination zones</em>:'));
267 o.filter = function(section_id, value) {
268 return (uci.get('firewall', section_id, 'name') != value);
270 o.cfgvalue = function(section_id) {
271 var out = (this.option == 'out'),
272 zone = this.lookupZone(uci.get('firewall', section_id, 'name')),
273 fwds = zone.getForwardingsBy(out ? 'src' : 'dest'),
276 for (var i = 0; i < fwds.length; i++)
277 value.push(out ? fwds[i].getDestination() : fwds[i].getSource());
281 o.write = o.remove = function(section_id, formvalue) {
282 var out = (this.option == 'out'),
283 zone = this.lookupZone(uci.get('firewall', section_id, 'name')),
284 fwds = zone.getForwardingsBy(out ? 'src' : 'dest');
286 if (formvalue == null)
289 if (Array.isArray(formvalue)) {
290 for (var i = 0; i < fwds.length; i++) {
291 var cmp = out ? fwds[i].getDestination() : fwds[i].getSource();
292 if (!formvalue.filter(function(d) { return d == cmp }).length)
293 zone.deleteForwarding(fwds[i]);
296 for (var i = 0; i < formvalue.length; i++)
298 zone.addForwardingTo(formvalue[i]);
300 zone.addForwardingFrom(formvalue[i]);
304 inp = o = s.taboption('general', widgets.ZoneSelect, 'in', _('Allow forward from <em>source zones</em>:'));
308 o.write = o.remove = out.write;
309 o.filter = out.filter;
310 o.cfgvalue = out.cfgvalue;