luci-mod-network: restrict peerdns option to protocols that implemenent it

Only some supported protocol extensions honour the `peerdns` options.

Fixes: 
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2022-11-15 01:44:28 +01:00
parent 20b765c77b
commit 2be01cbfcb

View file

@ -228,6 +228,22 @@ function get_netmask(s, use_cfgvalue) {
return subnetmask; return subnetmask;
} }
function has_peerdns(proto) {
switch (proto) {
case 'dhcp':
case 'qmi':
case 'ppp':
case 'pppoe':
case 'pppoa':
case 'pptp':
case 'openvpn':
case 'sstp':
return true;
}
return false;
}
var cbiRichListValue = form.ListValue.extend({ var cbiRichListValue = form.ListValue.extend({
renderWidget: function(section_id, option_index, cfgvalue) { renderWidget: function(section_id, option_index, cfgvalue) {
var choices = this.transformChoices(); var choices = this.transformChoices();
@ -936,13 +952,13 @@ return view.extend({
o = nettools.replaceOption(s, 'advanced', form.Flag, 'defaultroute', _('Use default gateway'), _('If unchecked, no default route is configured')); o = nettools.replaceOption(s, 'advanced', form.Flag, 'defaultroute', _('Use default gateway'), _('If unchecked, no default route is configured'));
o.default = o.enabled; o.default = o.enabled;
if (protoval != 'static') { if (has_peerdns(protoval)) {
o = nettools.replaceOption(s, 'advanced', form.Flag, 'peerdns', _('Use DNS servers advertised by peer'), _('If unchecked, the advertised DNS server addresses are ignored')); o = nettools.replaceOption(s, 'advanced', form.Flag, 'peerdns', _('Use DNS servers advertised by peer'), _('If unchecked, the advertised DNS server addresses are ignored'));
o.default = o.enabled; o.default = o.enabled;
} }
o = nettools.replaceOption(s, 'advanced', form.DynamicList, 'dns', _('Use custom DNS servers')); o = nettools.replaceOption(s, 'advanced', form.DynamicList, 'dns', _('Use custom DNS servers'));
if (protoval != 'static') if (has_peerdns(protoval))
o.depends('peerdns', '0'); o.depends('peerdns', '0');
o.datatype = 'ipaddr'; o.datatype = 'ipaddr';