proto: fix feature detection of installed protocol handlers
[project/luci.git] / protocols / 6x4 / luasrc / model / network / proto_6x4.lua
1 --[[
2 LuCI - Network model - 6to4 & 6in4 protocol extension
3
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 ]]--
19
20 local netmod = luci.model.network
21
22 local _, p
23 for _, p in ipairs({"6in4", "6to4"}) do
24
25 local proto = netmod:register_protocol(p)
26
27 function proto.get_i18n(self)
28 if p == "6in4" then
29 return luci.i18n.translate("IPv6-in-IPv4 (RFC4213)")
30 elseif p == "6to4" then
31 return luci.i18n.translate("IPv6-over-IPv4")
32 end
33 end
34
35 function proto.ifname(self)
36 return p .. "-" .. self.sid
37 end
38
39 function proto.opkg_package(self)
40 return p
41 end
42
43 function proto.is_installed(self)
44 return nixio.fs.access("/lib/netifd/proto/" .. p .. ".sh")
45 end
46
47 function proto.is_floating(self)
48 return true
49 end
50
51 function proto.is_virtual(self)
52 return true
53 end
54
55 function proto.get_interfaces(self)
56 return nil
57 end
58
59 function proto.contains_interface(self, ifname)
60 return (netmod:ifnameof(ifc) == self:ifname())
61 end
62
63 netmod:register_pattern_virtual("^%s-%%w" % p)
64 end