2
0

gretap.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. 'require form';
  3. 'require network';
  4. 'require tools.widgets as widgets';
  5. network.registerPatternVirtual(/^gre4t-.+$/);
  6. return network.registerProtocol('gretap', {
  7. getI18n: function() {
  8. return _('GRETAP tunnel over IPv4');
  9. },
  10. getIfname: function() {
  11. return this._ubus('l3_device') || 'gre4t-%s'.format(this.sid);
  12. },
  13. getOpkgPackage: function() {
  14. return 'gre';
  15. },
  16. isFloating: function() {
  17. return true;
  18. },
  19. isVirtual: function() {
  20. return true;
  21. },
  22. getDevices: function() {
  23. return null;
  24. },
  25. containsDevice: function(ifname) {
  26. return (network.getIfnameOf(ifname) == this.getIfname());
  27. },
  28. renderFormOptions: function(s) {
  29. var o;
  30. // -- general ---------------------------------------------------------------------
  31. o = s.taboption('general', form.Value, 'peeraddr', _("Remote IPv4 address or FQDN"), _("The IPv4 address or the fully-qualified domain name of the remote tunnel end."));
  32. o.optional = false;
  33. o.datatype = 'or(hostname,ip4addr("nomask"))';
  34. o = s.taboption('general', form.Value, 'ipaddr', _("Local IPv4 address"), _("The local IPv4 address over which the tunnel is created (optional)."));
  35. o.optional = true;
  36. o.datatype = 'ip4addr("nomask")';
  37. o.load = function(section_id) {
  38. return network.getWANNetworks().then(L.bind(function(nets) {
  39. if (nets.length)
  40. this.placeholder = nets[0].getIPAddr();
  41. return form.Value.prototype.load.apply(this, [section_id]);
  42. }, this));
  43. };
  44. o = s.taboption('general', widgets.NetworkSelect, 'network', _("Network interface"), _("Logical network to which the tunnel will be added (bridged) (optional)."));
  45. o.exclude = s.section;
  46. o.nocreate = true;
  47. o.optional = true;
  48. // -- advanced ---------------------------------------------------------------------
  49. o = s.taboption('advanced', widgets.NetworkSelect, 'tunlink', _("Bind interface"), _("Bind the tunnel to this interface (optional)."));
  50. o.exclude = s.section;
  51. o.nocreate = true;
  52. o.optional = true;
  53. o = s.taboption('advanced', form.Value, 'mtu', _("Override MTU"), _("Specify an MTU (Maximum Transmission Unit) other than the default (1280 bytes) (optional)."));
  54. o.optional = true;
  55. o.placeholder = 1280;
  56. o.datatype = 'range(68, 9200)';
  57. 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)."));
  58. o.optional = true;
  59. o.placeholder = 64;
  60. o.datatype = 'min(1)';
  61. o = s.taboption('advanced', form.Value, 'tos', _("Override TOS"), _("Specify a TOS (Type of Service). Can be <code>inherit</code> (the outer header inherits the value of the inner header) or an hexadecimal value <code>00..FF</code> (optional)."));
  62. o.optional = true;
  63. o.validate = function(section_id, value) {
  64. if (value.length > 0 && !value.match(/^[a-f0-9]{1,2}$/i) && !value.match(/^inherit$/i))
  65. return _("Invalid TOS value, expected 00..FF or inherit");
  66. return true;
  67. };
  68. o = s.taboption('advanced', form.Flag, 'df', _("Don't Fragment"), _("Enable the DF (Don't Fragment) flag of the encapsulating packets."));
  69. o.default = o.enabled;
  70. o = s.taboption('advanced', form.Flag, 'nohostroute', _("No host route"), _("Do not create host route to peer (optional)."));
  71. o.optional = true;
  72. o = s.taboption('advanced', form.Flag, 'multicast', _("Multicast"), _("Enable support for multicast traffic (optional)."));
  73. o.optional = true;
  74. o = s.taboption('advanced', form.Value, 'ikey', _("Incoming key"), _("Key for incoming packets (optional)."));
  75. o.optional = true;
  76. o.datatype = 'integer';
  77. o = s.taboption('advanced', form.Value, 'okey', _("Outgoing key"), _("Key for outgoing packets (optional)."));
  78. o.optional = true;
  79. o.datatype = 'integer';
  80. s.taboption('advanced', form.Flag, 'icsum', _("Incoming checksum"), _("Require incoming checksum (optional)."));
  81. s.taboption('advanced', form.Flag, 'ocsum', _("Outgoing checksum"), _("Compute outgoing checksum (optional)."));
  82. s.taboption('advanced', form.Flag, 'iseqno', _("Incoming serialization"), _("Require incoming packets serialization (optional)."));
  83. s.taboption('advanced', form.Flag, 'oseqno', _("Outgoing serialization"), _("Perform outgoing packets serialization (optional)."));
  84. }
  85. });