4 'require tools.widgets as widgets';
6 network.registerPatternVirtual(/^map-.+$/);
7 network.registerErrorCode('INVALID_MAP_RULE', _('MAP rule is invalid'));
8 network.registerErrorCode('NO_MATCHING_PD', _('No matching prefix delegation'));
9 network.registerErrorCode('UNSUPPORTED_TYPE', _('Unsupported MAP type'));
11 return network.registerProtocol('map', {
13 return _('MAP / LW4over6');
16 getIfname: function() {
17 return this._ubus('l3_device') || 'map-%s'.format(this.sid);
20 getOpkgPackage: function() {
24 isFloating: function() {
28 isVirtual: function() {
32 getDevices: function() {
36 containsDevice: function(ifname) {
37 return (network.getIfnameOf(ifname) == this.getIfname());
40 renderFormOptions: function(s) {
43 o = s.taboption('general', form.ListValue, 'type', _('Type'));
44 o.value('map-e', 'MAP-E');
45 o.value('map-t', 'MAP-T');
46 o.value('lw4o6', 'LW4over6');
48 o = s.taboption('general', form.Value, 'peeraddr', _('BR / DMR / AFTR'));
50 o.datatype = 'ip6addr';
52 o = s.taboption('general', form.Value, 'ipaddr', _('IPv4 prefix'));
53 o.datatype = 'ip4addr';
55 o = s.taboption('general', form.Value, 'ip4prefixlen', _('IPv4 prefix length'), _('The length of the IPv4 prefix in bits, the remainder is used in the IPv6 addresses.'));
57 o.datatype = 'range(0,32)';
59 o = s.taboption('general', form.Value, 'ip6prefix', _('IPv6 prefix'), _('The IPv6 prefix assigned to the provider, usually ends with <code>::</code>'));
61 o.datatype = 'ip6addr';
63 o = s.taboption('general', form.Value, 'ip6prefixlen', _('IPv6 prefix length'), _('The length of the IPv6 prefix in bits'));
65 o.datatype = 'range(0,64)';
67 o = s.taboption('general', form.Value, 'ealen', _('EA-bits length'));
68 o.datatype = 'range(0,48)';
70 o = s.taboption('general', form.Value, 'psidlen', _('PSID-bits length'));
71 o.datatype = 'range(0,16)';
73 o = s.taboption('general', form.Value, 'offset', _('PSID offset'));
74 o.datatype = 'range(0,16)';
76 o = s.taboption('advanced', widgets.NetworkSelect, 'tunlink', _('Tunnel Link'));
78 o.exclude = s.section;
80 o = s.taboption('advanced', form.Flag, 'defaultroute', _('Default gateway'), _('If unchecked, no default route is configured'));
81 o.default = o.enabled;
83 o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric'));
85 o.datatype = 'uinteger';
86 o.depends('defaultroute', '1');
88 o = s.taboption('advanced', form.Value, 'ttl', _('Use TTL on tunnel interface'));
90 o.datatype = 'range(1,255)';
92 o = s.taboption('advanced', form.Value, 'mtu', _('Use MTU on tunnel interface'));
93 o.placeholder = '1280';
94 o.datatype = 'max(9200)';