luci-proto-gre: Protocol extension for GRE tunnels
[oweals/luci.git] / protocols / luci-proto-gre / htdocs / luci-static / resources / protocol / grev6tap.js
1 'use strict';
2 'require form';
3 'require network';
4 'require tools.widgets as widgets';
5
6 network.registerPatternVirtual(/^gre6t-.+$/);
7
8 return network.registerProtocol('grev6tap', {
9         getI18n: function() {
10                 return _('GRETAP tunnel over IPv6');
11         },
12
13         getIfname: function() {
14                 return this._ubus('l3_device') || 'gre6t-%s'.format(this.sid);
15         },
16
17         getOpkgPackage: function() {
18                 return 'gre';
19         },
20
21         isFloating: function() {
22                 return true;
23         },
24
25         isVirtual: function() {
26                 return true;
27         },
28
29         getDevices: function() {
30                 return null;
31         },
32
33         containsDevice: function(ifname) {
34                 return (network.getIfnameOf(ifname) == this.getIfname());
35         },
36
37         renderFormOptions: function(s) {
38                 var o;
39
40                 // -- general ---------------------------------------------------------------------
41
42                 o = s.taboption('general', form.Value, 'peer6addr', _("Remote IPv6 address or FQDN"), _("The IPv6 address or the fully-qualified domain name of the remote tunnel end."));
43                 o.optional = false;
44                 o.datatype = 'or(hostname,ip6addr("nomask"))';
45
46                 o = s.taboption('general', form.Value, 'ip6addr', _("Local IPv6 address"), _("The local IPv6 address over which the tunnel is created (optional)."));
47                 o.optional = true;
48                 o.datatype = 'ip6addr("nomask")';
49
50                 o = s.taboption('general', widgets.NetworkSelect, 'weakif', _("Source interface"), _("Logical network from which to select the local endpoint if local IPv6 address is empty and no WAN IPv6 is available (optional)."));
51                 o.exclude = s.section;
52                 o.nocreate = true;
53                 o.optional = true;
54
55                 o = s.taboption('general', widgets.NetworkSelect, 'network', _("Network interface"), _("Logical network to which the tunnel will be added (bridged) (optional)."));
56                 o.exclude = s.section;
57                 o.nocreate = true;
58                 o.optional = true;
59
60                 // -- advanced ---------------------------------------------------------------------
61
62                 o = s.taboption('advanced', widgets.NetworkSelect, 'tunlink', _("Bind interface"), _("Bind the tunnel to this interface (optional)."));
63                 o.exclude = s.section;
64                 o.nocreate = true;
65                 o.optional = true;
66
67                 o = s.taboption('advanced', form.Value, 'mtu', _("Override MTU"), _("Specify an MTU (Maximum Transmission Unit) other than the default (1280 bytes) (optional)."));
68                 o.optional = true;
69                 o.placeholder = 1280;
70                 o.datatype = 'range(68, 9200)';
71
72                 o = s.taboption('advanced', form.Value, 'ttl', _("Override TTL"), _("Specify a TTL (Time to Live) for the encapsulating packet other than the default (64) (optional)."));
73                 o.optional = true;
74                 o.placeholder = 64;
75                 o.datatype = 'min(1)';
76
77                 o = s.taboption('advanced', form.Value, 'tos', _('Traffic Class'), _("Specify a Traffic Class. Can be either <code>inherit</code> (the outer header inherits the value of the inner header) or an hexadecimal value starting with <code>0x</code> (optional)."));
78                 o.optional = true;
79                 o.validate = function(section_id, value) {
80                         if (value.length > 0 && !value.match(/^0x[a-fA-F0-9]{1,2}$/) && !value.match(/^inherit$/i))
81                                 return _('Invalid value');
82
83                         return true;
84                 };
85
86                 o = s.taboption('advanced', form.Flag, 'nohostroute', _("No host route"), _("Do not create host route to peer (optional)."));
87                 o.optional = true;
88
89                 o = s.taboption('advanced', form.Value, 'ikey', _("Incoming key"), _("Key for incoming packets (optional)."));
90                 o.optional = true;
91                 o.datatype = 'integer';
92
93                 o = s.taboption('advanced', form.Value, 'okey', _("Outgoing key"), _("Key for outgoing packets (optinal)."));
94                 o.optional = true;
95                 o.datatype = 'integer';
96
97                 s.taboption('advanced', form.Flag, 'icsum', _("Incoming checksum"), _("Require incoming checksum (optional)."));
98                 s.taboption('advanced', form.Flag, 'ocsum', _("Outgoing checksum"), _("Compute outgoing checksum (optional)."));
99                 s.taboption('advanced', form.Flag, 'iseqno', _("Incoming serialization"), _("Require incoming packets serialization (optional)."));
100                 s.taboption('advanced', form.Flag, 'oseqno', _("Outgoing serialization"), _("Perform outgoing packets serialization (optional)."));
101
102         }
103 });