Add luci
[librecmc/librecmc.git] / package / luci / applications / luci-app-firewall / luasrc / model / cbi / firewall / zones.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local ds = require "luci.dispatcher"
5 local fw = require "luci.model.firewall"
6 local fs = require "nixio.fs"
7
8 local m, s, o, p, i, v
9
10 m = Map("firewall",
11         translate("Firewall - Zone Settings"),
12         translate("The firewall creates zones over your network interfaces to control network traffic flow."))
13
14 fw.init(m.uci)
15
16 s = m:section(TypedSection, "defaults", translate("General Settings"))
17 s.anonymous = true
18 s.addremove = false
19
20 s:option(Flag, "syn_flood", translate("Enable SYN-flood protection"))
21
22 o = s:option(Flag, "drop_invalid", translate("Drop invalid packets"))
23
24 p = {
25         s:option(ListValue, "input", translate("Input")),
26         s:option(ListValue, "output", translate("Output")),
27         s:option(ListValue, "forward", translate("Forward"))
28 }
29
30 for i, v in ipairs(p) do
31         v:value("REJECT", translate("reject"))
32         v:value("DROP", translate("drop"))
33         v:value("ACCEPT", translate("accept"))
34 end
35
36 -- Netfilter flow offload support
37
38 local offload = fs.access("/sys/module/xt_FLOWOFFLOAD/refcnt")
39
40 if offload then
41         s:option(DummyValue, "offload_advice",
42                 translate("Routing/NAT Offloading"),
43                 translate("Experimental feature. Not fully compatible with QoS/SQM."))
44
45         o = s:option(Flag, "flow_offloading",
46                 translate("Software flow offloading"),
47                 translate("Software based offloading for routing/NAT"))
48         o.optional = true
49
50         o = s:option(Flag, "flow_offloading_hw",
51                 translate("Hardware flow offloading"),
52                 translate("Requires hardware NAT support. Implemented at least for mt7621"))
53         o.optional = true
54         o:depends( "flow_offloading", 1)
55 end
56
57 -- Firewall zones
58
59 s = m:section(TypedSection, "zone", translate("Zones"))
60 s.template = "cbi/tblsection"
61 s.anonymous = true
62 s.addremove = true
63 s.extedit   = ds.build_url("admin", "network", "firewall", "zones", "%s")
64
65 function s.create(self)
66         local z = fw:new_zone()
67         if z then
68                 luci.http.redirect(
69                         ds.build_url("admin", "network", "firewall", "zones", z.sid)
70                 )
71         end
72 end
73
74 function s.remove(self, section)
75         return fw:del_zone(section)
76 end
77
78 o = s:option(DummyValue, "_info", translate("Zone ⇒ Forwardings"))
79 o.template = "cbi/firewall_zoneforwards"
80 o.cfgvalue = function(self, section)
81         return self.map:get(section, "name")
82 end
83
84 p = {
85         s:option(ListValue, "input", translate("Input")),
86         s:option(ListValue, "output", translate("Output")),
87         s:option(ListValue, "forward", translate("Forward"))
88 }
89
90 for i, v in ipairs(p) do
91         v:value("REJECT", translate("reject"))
92         v:value("DROP", translate("drop"))
93         v:value("ACCEPT", translate("accept"))
94 end
95
96 s:option(Flag, "masq", translate("Masquerading"))
97 s:option(Flag, "mtu_fix", translate("MSS clamping"))
98
99 return m