Commit c02820c4 authored by Franco Fichtner's avatar Franco Fichtner

services: add route features to RA

(cherry picked from commit 99973edc)
(cherry picked from commit 95158547)
parent 9a88a088
...@@ -195,12 +195,20 @@ function services_radvd_configure($blacklist = array()) ...@@ -195,12 +195,20 @@ function services_radvd_configure($blacklist = array())
$radvdconf .= "\troute ::/0 {\n"; $radvdconf .= "\troute ::/0 {\n";
$radvdconf .= "\t\tRemoveRoute off;\n"; $radvdconf .= "\t\tRemoveRoute off;\n";
$radvdconf .= "\t};\n"; $radvdconf .= "\t};\n";
} else { } elseif (empty($dhcpv6ifconf['ranodefault'])) {
$radvdconf .= "\troute ::/0 {\n"; $radvdconf .= "\troute ::/0 {\n";
$radvdconf .= "\t\tRemoveRoute on;\n"; $radvdconf .= "\t\tRemoveRoute on;\n";
$radvdconf .= "\t};\n"; $radvdconf .= "\t};\n";
} }
if (!empty($dhcpv6ifconf['raroutes'])) {
foreach (explode(',', $dhcpv6ifconf['raroutes']) as $raroute) {
$radvdconf .= "\troute {$raroute} {\n";
$radvdconf .= "\t\tRemoveRoute on;\n";
$radvdconf .= "\t};\n";
}
}
/* add DNS servers */ /* add DNS servers */
$dnslist_tmp = array(); $dnslist_tmp = array();
if (isset($dhcpv6ifconf['rasamednsasdhcp6']) && !empty($dhcpv6ifconf['dnsserver'][0])) { if (isset($dhcpv6ifconf['rasamednsasdhcp6']) && !empty($dhcpv6ifconf['dnsserver'][0])) {
......
...@@ -58,9 +58,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -58,9 +58,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
// boolean // boolean
$pconfig['rasamednsasdhcp6'] = isset($config['dhcpdv6'][$if]['rasamednsasdhcp6']); $pconfig['rasamednsasdhcp6'] = isset($config['dhcpdv6'][$if]['rasamednsasdhcp6']);
if (empty($config['dhcpdv6'][$if]['ranosend'])) { $pconfig['rasend'] = empty($config['dhcpdv6'][$if]['ranosend']) ? true : null;
$pconfig['rasend'] = true; $pconfig['radefault'] = empty($config['dhcpdv6'][$if]['ranodefault']) ? true : null;
}
// defaults // defaults
if (empty($pconfig['ramininterval'])) { if (empty($pconfig['ramininterval'])) {
...@@ -73,6 +72,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -73,6 +72,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// arrays // arrays
$pconfig['radns1'] = !empty($config['dhcpdv6'][$if]['radnsserver'][0]) ? $config['dhcpdv6'][$if]['radnsserver'][0] : null; $pconfig['radns1'] = !empty($config['dhcpdv6'][$if]['radnsserver'][0]) ? $config['dhcpdv6'][$if]['radnsserver'][0] : null;
$pconfig['radns2'] = !empty($config['dhcpdv6'][$if]['radnsserver'][1]) ? $config['dhcpdv6'][$if]['radnsserver'][1] : null; $pconfig['radns2'] = !empty($config['dhcpdv6'][$if]['radnsserver'][1]) ? $config['dhcpdv6'][$if]['radnsserver'][1] : null;
// csvs
if (!empty($config['dhcpdv6'][$if]['raroutes'])) {
$pconfig['raroutes'] = explode(',', $config['dhcpdv6'][$if]['raroutes']);
} else {
$pconfig['raroutes'] = array();
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['if']) && !empty($config['interfaces'][$_POST['if']])) { if (!empty($_POST['if']) && !empty($config['interfaces'][$_POST['if']])) {
$if = $_POST['if']; $if = $_POST['if'];
...@@ -82,6 +88,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -82,6 +88,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$input_errors = array(); $input_errors = array();
$pconfig = $_POST; $pconfig = $_POST;
$pconfig['raroutes'] = array();
foreach ($pconfig['route_address'] as $idx => $address) {
if (!empty($address)) {
$route = "{$address}/{$pconfig['route_bits'][$idx]}";
if (!is_subnetv6($route)) {
$input_errors[] = sprintf(gettext('An invalid subnet route was supplied: %s'), $route);
}
$pconfig['raroutes'][] = $route;
}
}
if ((!empty($pconfig['radns1']) && !is_ipaddrv6($pconfig['radns1'])) || ($pconfig['radns2'] && !is_ipaddrv6($pconfig['radns2']))) { if ((!empty($pconfig['radns1']) && !is_ipaddrv6($pconfig['radns1'])) || ($pconfig['radns2'] && !is_ipaddrv6($pconfig['radns2']))) {
$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary DNS servers."); $input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary DNS servers.");
} }
...@@ -120,6 +137,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -120,6 +137,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
unset($config['dhcpdv6'][$if]['ranosend']); unset($config['dhcpdv6'][$if]['ranosend']);
} }
# flipped in GUI on purpose
if (empty($pconfig['radefault'])) {
$config['dhcpdv6'][$if]['ranodefault'] = true;
} elseif (isset($config['dhcpdv6'][$if]['ranodefault'])) {
unset($config['dhcpdv6'][$if]['ranodefault']);
}
$config['dhcpdv6'][$if]['radomainsearchlist'] = $pconfig['radomainsearchlist']; $config['dhcpdv6'][$if]['radomainsearchlist'] = $pconfig['radomainsearchlist'];
$config['dhcpdv6'][$if]['radnsserver'] = array(); $config['dhcpdv6'][$if]['radnsserver'] = array();
if (!empty($pconfig['radns1'])) { if (!empty($pconfig['radns1'])) {
...@@ -130,6 +154,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -130,6 +154,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
$config['dhcpdv6'][$if]['rasamednsasdhcp6'] = !empty($pconfig['rasamednsasdhcp6']); $config['dhcpdv6'][$if]['rasamednsasdhcp6'] = !empty($pconfig['rasamednsasdhcp6']);
if (count($pconfig['raroutes'])) {
$config['dhcpdv6'][$if]['raroutes'] = implode(',', $pconfig['raroutes']);
} elseif (isset($config['dhcpdv6'][$if]['raroutes'])) {
unset($config['dhcpdv6'][$if]['raroutes']);
}
write_config(); write_config();
services_radvd_configure(); services_radvd_configure();
$savemsg = get_std_save_message(); $savemsg = get_std_save_message();
...@@ -152,23 +182,27 @@ include("head.inc"); ...@@ -152,23 +182,27 @@ include("head.inc");
*/ */
function removeRow() { function removeRow() {
if ( $('#maintable > tbody > tr').length == 1 ) { if ( $('#maintable > tbody > tr').length == 1 ) {
$('#maintable > tbody > tr:last > td > input').each(function(){ $('#maintable > tbody > tr:last > td > input').each(function () { $(this).val(""); });
$(this).val("");
});
} else { } else {
$(this).parent().parent().remove(); $(this).parent().parent().remove();
} }
} }
// add new detail record // add new detail record
$("#addNew").click(function(){ function addRow() {
// copy last row and reset values // copy last row and reset values
$('#maintable > tbody > tr:last > td > label').removeClass('act-addrow').addClass('act-removerow');
$('#maintable > tbody > tr:last > td > label').unbind('click');
$('#maintable > tbody > tr:last > td > label').click(removeRow);
$('#maintable > tbody > tr:last > td > label > span:first').removeClass('fa-plus').addClass('fa-minus');
$('#maintable > tbody').append('<tr>'+$('#maintable > tbody > tr:last').html()+'</tr>'); $('#maintable > tbody').append('<tr>'+$('#maintable > tbody > tr:last').html()+'</tr>');
$('#maintable > tbody > tr:last > td > input').each(function(){ $('#maintable > tbody > tr:last > td > input').each(function () { $(this).val(""); });
$(this).val(""); $('#maintable > tbody > tr:last > td > label').removeClass('act-removerow').addClass('act-addrow');
}); $('#maintable > tbody > tr:last > td > label').unbind('click');
$(".act-removerow").click(removeRow); $('#maintable > tbody > tr:last > td > label').click(addRow);
}); $('#maintable > tbody > tr:last > td > label > span:first').removeClass('fa-minus').addClass('fa-plus');
}
$(".act-removerow").click(removeRow); $(".act-removerow").click(removeRow);
$(".act-addrow").click(addRow);
}); });
</script> </script>
...@@ -270,8 +304,75 @@ include("head.inc"); ...@@ -270,8 +304,75 @@ include("head.inc");
</td> </td>
</tr> </tr>
<?php <?php
endif;?> endif ?>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?= gettext('Advertise Default Gateway') ?></td>
<td>
<input id="radefault" name="radefault" type="checkbox" value="yes" <?= !empty($pconfig['radefault']) ? 'checked="checked"' : '' ?>/>
</td>
</tr>
<tr>
<td><a id="help_for_raroutes" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?= gettext('Advertise Routes') ?></td>
<td>
<table class="table table-striped table-condensed" id="maintable">
<thead>
<tr>
<th></th>
<th><?= gettext('Prefix') ?></th>
<th><?= gettext('Length') ?></th>
</tr>
</thead>
<tbody>
<?php
$pconfig['raroutes'][] = '';
foreach($pconfig['raroutes'] as $item):
$parts = explode('/', $item);
if (count($parts) > 1) {
$sn_bits = intval($parts[1]);
} else {
$sn_bits = null;
}
$sn_address = $parts[0];
?>
<tr>
<td>
<?php
if (!empty($item)): ?>
<label class="act-removerow btn btn-default btn-xs">
<span class="fa fa-minus"></span>
<span class="sr-only"><?= gettext('Remove') ?></span>
</label>
<?php
else: ?>
<label class="act-addrow btn btn-default btn-xs">
<span class="fa fa-plus"></span>
<span class="sr-only"><?= gettext('Add') ?></span>
</label>
<?php
endif ?>
</td>
<td>
<input name="route_address[]" type="text" value="<?=$sn_address;?>" />
</td>
<td>
<select name="route_bits[]">
<?php
for ($i = 128; $i >= 0; $i -= 1): ?>
<option value="<?= $i ?>" <?= $sn_bits === $i ? 'selected="selected"' : '' ?>><?= $i ?></option>
<?php
endfor ?>
</select>
</td>
</tr>
<?php
endforeach ?>
</tbody>
</table>
<div class="hidden" for="help_for_raroutes">
<?= gettext('Routes are specified in CIDR format. The prefix of a route definition should be network prefix; it can be used to advertise more specific routes to the hosts.') ?>
</div>
</td>
</tr>
<tr> <tr>
<td><a id="help_for_radns" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DNS servers");?></td> <td><a id="help_for_radns" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DNS servers");?></td>
<td> <td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment