5 'require tools.widgets as widgets';
7 network
.registerPatternVirtual(/^relay-.+$/);
9 var RelayDevicePrototype
= {
10 __init__: function(ifname
, network
) {
12 this.network
= network
;
15 _aggregateDevices: function(fn
, first
) {
16 var devices
= this.network
? this.network
.getDevices() : [],
19 for (var i
= 0; i
< devices
.length
; i
++) {
20 var v
= devices
[i
][fn
].apply(devices
[i
]);
30 return first
? null : [ rv
, devices
.length
];
33 getPorts: function() { return this.network
? this.network
.getDevices() : [] },
35 getType: function() { return 'tunnel' },
36 getTypeI18n: function() { return _('Relay Bridge') },
38 getShortName: function() {
39 return '%s "%h"'.format(_('Relay'), this.ifname
);
43 var res
= this._aggregateDevices('isUp');
44 return (res
[1] > 0 && res
[0] == res
[1]);
47 getTXBytes: function() { return this._aggregateDevices('getTXBytes')[0] },
48 getRXBytes: function() { return this._aggregateDevices('getRXBytes')[0] },
49 getTXPackets: function() { return this._aggregateDevices('getTXPackets')[0] },
50 getRXPackets: function() { return this._aggregateDevices('getRXPackets')[0] },
52 getMAC: function() { return this._aggregateDevices('getMAC', true) },
54 getIPAddrs: function() {
55 var ipaddr
= this.network
? L
.toArray(uci
.get('network', this.network
.getName(), 'ipaddr'))[0] : null;
56 return (ipaddr
!= null ? [ ipaddr
] : []);
59 getIP6Addrs: function() { return [] }
62 return network
.registerProtocol('relay', {
64 return _('Relay bridge');
67 getIfname: function() {
68 return 'relay-%s'.format(this.sid
);
71 getOpkgPackage: function() {
75 isFloating: function() {
79 isVirtual: function() {
83 containsDevice: function(ifname
) {
84 return (network
.getIfnameOf(ifname
) == this.getIfname());
88 var dev
= this.getDevice();
89 return (dev
? dev
.isUp() : false);
92 getDevice: function() {
93 return network
.instantiateDevice(this.sid
, this, RelayDevicePrototype
);
96 getDevices: function() {
100 var networkNames
= L
.toArray(uci
.get('network', this.sid
, 'network')),
101 deviceNames
= L
.toArray(uci
.get('network', this.sid
, 'ifname')),
105 for (var i
= 0; i
< networkNames
.length
; i
++) {
106 var net
= network
.instantiateNetwork(networkNames
[i
]),
107 dev
= net
? net
.getDevice() : null;
110 devices
[dev
.getName()] = dev
;
113 for (var i
= 0; i
< deviceNames
.length
; i
++) {
114 var dev
= network
.getDevice(deviceNames
[i
]);
117 devices
[dev
.getName()] = dev
;
120 deviceNames
= Object
.keys(devices
);
123 for (var i
= 0; i
< deviceNames
.length
; i
++)
124 rv
.push(devices
[deviceNames
[i
]]);
131 getUptime: function() {
132 var networkNames
= L
.toArray(uci
.get('network', this.sid
, 'network')),
135 for (var i
= 0; i
< networkNames
.length
; i
++) {
136 var net
= network
.instantiateNetwork(networkNames
[i
]);
138 uptime
= Math
.max(uptime
, net
.getUptime());
144 getErrors: function() {
148 renderFormOptions: function(s
) {
151 o
= s
.taboption('general', form
.Value
, 'ipaddr', _('Local IPv4 address'), _('Address to access local relay bridge'));
152 o
.datatype
= 'ip4addr("nomask")';
154 o
= s
.taboption('general', widgets
.NetworkSelect
, 'network', _('Relay between networks'));
155 o
.exclude
= s
.section
;
161 o
= s
.taboption('advanced', form
.Flag
, 'forward_bcast', _('Forward broadcast traffic'));
162 o
.default = o
.enabled
;
164 o
= s
.taboption('advanced', form
.Flag
, 'forward_dhcp', _('Forward DHCP traffic'));
165 o
.default = o
.enabled
;
167 o
= s
.taboption('advanced', form
.Value
, 'gateway', _('Use DHCP gateway'), _('Override the gateway in DHCP responses'));
168 o
.datatype
= 'ip4addr("nomask")';
169 o
.depends('forward_dhcp', '1');
171 o
= s
.taboption('advanced', form
.Value
, 'expiry', _('Host expiry timeout'), _('Specifies the maximum amount of seconds after which hosts are presumed to be dead'));
172 o
.placeholder
= '30';
173 o
.datatype
= 'min(1)';
175 o
= s
.taboption('advanced', form
.Value
, 'retry', _('ARP retry threshold'), _('Specifies the maximum amount of failed ARP requests until hosts are presumed to be dead'));
177 o
.datatype
= 'min(1)';
179 o
= s
.taboption('advanced', form
.Value
, 'table', _('Use routing table'), _('Override the table used for internal routes'));
180 o
.placeholder
= '16800';
181 o
.datatype
= 'range(0,65535)';