interfaces: also set PCP value on IPv4 DHCP traffic

This requires to set up the VLAN priority field of the
DHCPv4 settings as well as removing the vlan-pcp option
which is redundant now.  This way we have a simpler
approach to finding the correct value while not borrowing
from IPv6 or parsing the advanced options for vlan-pcp.

Leaving the old vlan-pcp in place should not matter.
The last value is ours and this one should be used.

PR: https://forum.opnsense.org/index.php?topic=33376.0
This commit is contained in:
Franco Fichtner 2023-04-09 16:58:02 +02:00 committed by Franco Fichtner
parent f4081dfcdf
commit d195cd2e8a
3 changed files with 38 additions and 9 deletions

View File

@ -393,19 +393,21 @@ function filter_core_rules_system($fw, $defaults)
break;
case "dhcp":
$fw->registerFilterRule(
5,
array('protocol' => 'udp', 'direction' => 'in', 'quick' => false, 'from_port' => 67, 'to_port' => 68,
'#ref' => "interfaces.php?if=" . $intf . "#type",
'interface' => $intf, 'descr' => 'allow DHCP client on ' . $intfinfo['descr']),
$defaults['pass']
);
$fw->registerFilterRule(
5,
array('protocol' => 'udp', 'direction' => 'out', 'quick' => false, 'from_port' => 68, 'to_port' => 67,
1,
array('protocol' => 'udp', 'direction' => 'in', 'from_port' => 67, 'to_port' => 68,
'#ref' => "interfaces.php?if=" . $intf . "#type",
'interface' => $intf, 'descr' => 'allow DHCP client on ' . $intfinfo['descr']),
$defaults['pass']
);
$dhcpv4_opts = [
'protocol' => 'udp','direction' => 'out', 'from_port' => 68, 'to_port' => 67,
'#ref' => "interfaces.php?if=" . $intf . "#type",
'interface' => $intf, 'descr' => 'allow DHCP client on ' . $intfinfo['descr'],
];
if (isset($intfinfo['dhcpvlanprio'])) {
$dhcpv4_opts['set-prio'] = $intfinfo['dhcpvlanprio'];
}
$fw->registerFilterRule(1, $dhcpv4_opts, $defaults['pass']);
break;
default:
if (isset($config['dhcpd'][$intf]['enable'])) {

View File

@ -3149,6 +3149,10 @@ EOD;
$dhclientconf .= " reject {$wancfg['dhcprejectfrom']};\n";
}
if (isset($wancfg['dhcpvlanprio'])) {
$dhclientconf .= " vlan-pcp {$wancfg['dhcpvlanprio']};\n";
}
$dhclientconf .= "}\n";
// DHCP Config File Advanced
@ -3255,6 +3259,9 @@ function DHCP_Config_File_Advanced($interface, $wancfg, $wanif)
if (is_ipaddrv4($wancfg['dhcprejectfrom'])) {
$dhclientconf .= "\treject {$wancfg['dhcprejectfrom']};\n";
}
if (isset($wancfg['dhcpvlanprio'])) {
$dhclientconf .= "\tvlan-pcp {$wancfg['dhcpvlanprio']};\n";
}
$dhclientconf .= "}\n";
$dhclientconf = DHCP_Config_File_Substitutions($wancfg, $wanif, $dhclientconf);

View File

@ -395,6 +395,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
'dhcp6vlanprio',
'dhcphostname',
'dhcprejectfrom',
'dhcpvlanprio',
'disablechecksumoffloading',
'disablelargereceiveoffloading',
'disablesegmentationoffloading',
@ -1073,6 +1074,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (empty($pconfig['dhcpoverridemtu'])) {
$new_config['dhcphonourmtu'] = true;
}
if (isset($pconfig['dhcpvlanprio']) && $pconfig['dhcpvlanprio'] !== '') {
$new_config['dhcpvlanprio'] = $pconfig['dhcpvlanprio'];
}
break;
case "ppp":
$new_config['if'] = $pconfig['type'] . $pconfig['ptpid'];
@ -2302,6 +2306,22 @@ include("head.inc");
</div>
</td>
</tr>
<tr class="dhcp_basic dhcp_advanced">
<td><a id="help_for_dhcpvlanprio" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?= gettext('Use VLAN priority') ?></td>
<td>
<select name="dhcpvlanprio">
<option value="" <?= "{$pconfig['dhcpvlanprio']}" === '' ? 'selected="selected"' : '' ?>><?= gettext('Disabled') ?></option>
<?php
foreach (interfaces_vlan_priorities() as $pcp => $priority): ?>
<option value="<?= html_safe($pcp) ?>" <?= "{$pconfig['dhcpvlanprio']}" === "$pcp" ? 'selected="selected"' : '' ?>><?= htmlspecialchars($priority) ?></option>
<?php
endforeach ?>
</select>
<div class="hidden" data-for="help_for_dhcpvlanprio">
<?= gettext('Certain ISPs may require that DHCPv4 requests are sent with a specific VLAN priority.') ?>
</div>
</td>
</tr>
<tr class="dhcp_advanced">
<td><a id="help_for_dhcpprotocol_timing" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Protocol Timing"); ?></td>
<td>