mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 16:14:40 +00:00
IPv6 Router Advertisements, add advanced options, closes https://github.com/opnsense/core/issues/3366
This commit is contained in:
parent
658e3d0092
commit
c0fe5ceff4
@ -264,6 +264,11 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = array())
|
||||
$radvdconf .= "\tAdvSendAdvert on;\n";
|
||||
$radvdconf .= sprintf("\tMinRtrAdvInterval %s;\n", !empty($dhcpv6ifconf['ramininterval']) ? $dhcpv6ifconf['ramininterval'] : '200');
|
||||
$radvdconf .= sprintf("\tMaxRtrAdvInterval %s;\n", !empty($dhcpv6ifconf['ramaxinterval']) ? $dhcpv6ifconf['ramaxinterval'] : '600');
|
||||
foreach (array('AdvDefaultLifetime', 'AdvValidLifetime', 'AdvPreferredLifetime', 'AdvRDNSSLifetime', 'AdvDNSSLLifetime') as $opt) {
|
||||
if (!empty($dhcpv6ifconf[$opt])) {
|
||||
$radvdconf .= sprintf("\t%s %s;\n", $opt, $dhcpv6ifconf[$opt]);
|
||||
}
|
||||
}
|
||||
$radvdconf .= sprintf("\tAdvLinkMTU %s;\n", !empty($mtu) ? $mtu : 1280);
|
||||
|
||||
switch ($dhcpv6ifconf['rapriority']) {
|
||||
@ -352,6 +357,9 @@ function dhcpd_radvd_configure($verbose = false, $blacklist = array())
|
||||
if (!empty($dhcpv6ifconf['rainterface'])) {
|
||||
$radvdconf .= "\t\tRemoveRoute off;\n";
|
||||
}
|
||||
if (!empty($dhcpv6ifconf['AdvRouteLifetime'])) {
|
||||
$radvdconf .= "\t\tAdvRouteLifetime {$dhcpv6ifconf['AdvRouteLifetime']};\n";
|
||||
}
|
||||
$radvdconf .= "\t};\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,11 @@ require_once("services.inc");
|
||||
require_once("interfaces.inc");
|
||||
require_once("plugins.inc.d/dhcpd.inc");
|
||||
|
||||
function val_int_in_range($value, $min, $max) {
|
||||
return (((string)(int)$value) == $value) && $value >= $min && $value < $max;
|
||||
}
|
||||
|
||||
$advanced_options = array('AdvDefaultLifetime', 'AdvValidLifetime', 'AdvPreferredLifetime', 'AdvRDNSSLifetime', 'AdvDNSSLLifetime', 'AdvRouteLifetime');
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
if (!empty($_GET['if']) && !empty($config['interfaces'][$_GET['if']])) {
|
||||
$if = $_GET['if'];
|
||||
@ -45,6 +50,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
|
||||
$pconfig = array();
|
||||
$config_copy_fieldsnames = array('ramode', 'rapriority', 'rainterface', 'ramininterval', 'ramaxinterval', 'radomainsearchlist');
|
||||
$config_copy_fieldsnames = array_merge($advanced_options, $config_copy_fieldsnames);
|
||||
foreach ($config_copy_fieldsnames as $fieldname) {
|
||||
if (isset($config['dhcpdv6'][$if][$fieldname])) {
|
||||
$pconfig[$fieldname] = $config['dhcpdv6'][$if][$fieldname];
|
||||
@ -107,13 +113,34 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_numericint($pconfig['ramaxinterval']) || $pconfig['ramaxinterval'] < 4 || $pconfig['ramaxinterval'] > 1800) {
|
||||
if (!val_int_in_range($pconfig['ramaxinterval'], 4, 1800)) {
|
||||
$input_errors[] = sprintf(gettext('Maximum interval must be between %s and %s seconds.'), 4, 1800);
|
||||
// chain this validation, we use the former value for calculation */
|
||||
} elseif (!is_numericint($pconfig['ramininterval']) || $pconfig['ramininterval'] < 3 || $pconfig['ramininterval'] > intval($pconfig['ramaxinterval'] * 0.75)) {
|
||||
$input_errors[] = sprintf(gettext('Minimum interval must be between %s and %s seconds.'), 3, intval($pconfig['ramaxinterval'] * 0.75));
|
||||
} else {
|
||||
if (!val_int_in_range($pconfig['ramininterval'], 3, intval($pconfig['ramaxinterval'] * 0.75))) {
|
||||
$input_errors[] = sprintf(gettext('Minimum interval must be between %s and %s seconds.'), 3, intval($pconfig['ramaxinterval'] * 0.75));
|
||||
}
|
||||
if (!empty($pconfig['AdvDefaultLifetime']) && !val_int_in_range($pconfig['AdvDefaultLifetime'], $pconfig['ramaxinterval'], 9000)) {
|
||||
$input_errors[] = sprintf(gettext('AdvDefaultLifetime must be between %s and %s seconds.'), $pconfig['ramaxinterval'], 9000);
|
||||
}
|
||||
if (!empty($pconfig['AdvValidLifetime']) && !val_int_in_range($pconfig['AdvValidLifetime'], 1, 4294967295)) {
|
||||
$input_errors[] = sprintf(gettext('AdvValidLifetime must be between %s and %s seconds.'), 1, 4294967295);
|
||||
}
|
||||
if (!empty($pconfig['AdvPreferredLifetime']) && !val_int_in_range($pconfig['AdvPreferredLifetime'], 1, 4294967295)) {
|
||||
$input_errors[] = sprintf(gettext('AdvPreferredLifetime must be between %s and %s seconds.'), 1, 4294967295);
|
||||
}
|
||||
if (!empty($pconfig['AdvRDNSSLifetime']) && !val_int_in_range($pconfig['AdvRDNSSLifetime'], $pconfig['ramaxinterval'], $pconfig['ramaxinterval'] * 2)) {
|
||||
$input_errors[] = sprintf(gettext('AdvRDNSSLifetime must be between %s and %s seconds.'), $pconfig['ramaxinterval'], $pconfig['ramaxinterval'] * 2);
|
||||
}
|
||||
if (!empty($pconfig['AdvDNSSLLifetime']) && !val_int_in_range($pconfig['AdvDNSSLLifetime'], $pconfig['ramaxinterval'], $pconfig['ramaxinterval'] * 2)) {
|
||||
$input_errors[] = sprintf(gettext('AdvDNSSLLifetime must be between %s and %s seconds.'), $pconfig['ramaxinterval'], $pconfig['ramaxinterval'] * 2);
|
||||
}
|
||||
if (!empty($pconfig['AdvRouteLifetime']) && !val_int_in_range($pconfig['AdvRouteLifetime'], 1, 4294967295)) {
|
||||
$input_errors[] = sprintf(gettext('AdvRouteLifetime must be between %s and %s seconds.'), 1, 4294967295);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (count($input_errors) == 0) {
|
||||
config_read_array('dhcpdv6', $if);
|
||||
|
||||
@ -151,6 +178,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
unset($config['dhcpdv6'][$if]['raroutes']);
|
||||
}
|
||||
|
||||
foreach ($advanced_options as $advopt) {
|
||||
if (isset($pconfig[$advopt]) && $pconfig[$advopt] != "") {
|
||||
$config['dhcpdv6'][$if][$advopt] = $pconfig[$advopt];
|
||||
} elseif (isset($config['dhcpdv6'][$if][$advopt])) {
|
||||
unset($config['dhcpdv6'][$if][$advopt]);
|
||||
}
|
||||
}
|
||||
|
||||
write_config();
|
||||
dhcpd_radvd_configure();
|
||||
$savemsg = get_std_save_message();
|
||||
@ -194,6 +229,14 @@ include("head.inc");
|
||||
}
|
||||
$(".act-removerow").click(removeRow);
|
||||
$(".act-addrow").click(addRow);
|
||||
if ($("#has_advanced").val() != "" ) {
|
||||
$(".advanced_opt").show();
|
||||
}
|
||||
$("#show_advanced_opt").click(function(e){
|
||||
e.preventDefault();
|
||||
$(".advanced_opt").show();
|
||||
$(this).closest('tr').hide();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -386,9 +429,31 @@ include("head.inc");
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$has_advanced = false;
|
||||
foreach ($advanced_options as $advopt):
|
||||
$has_advanced = ($has_advanced || !empty($pconfig[$advopt]));?>
|
||||
<tr style="display:none;" class="advanced_opt">
|
||||
<td><i class="fa fa-info-circle text-muted"></i> <?=$advopt;?></td>
|
||||
<td>
|
||||
<input name="<?=$advopt;?>" type="text" id="<?=$advopt;?>" value="<?=!empty($pconfig[$advopt]) ? $pconfig[$advopt] :"" ;?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
if (!$has_advanced):?>
|
||||
<tr>
|
||||
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Advanced");?></td>
|
||||
<td>
|
||||
<button id="show_advanced_opt" class="btn btn-xs btn-default"><?= gettext('Show advanced options') ?></button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;?>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<input id="has_advanced" type="hidden" value="<?=$has_advanced ? "X": "";?>">
|
||||
<input name="if" type="hidden" value="<?=$if;?>" />
|
||||
<input name="Submit" type="submit" class="formbtn btn btn-primary" value="<?=html_safe(gettext('Save'));?>" />
|
||||
</td>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user