From 8333e25c71ceb5421bae8a6385e5a0a031fc9433 Mon Sep 17 00:00:00 2001 From: NOYB Date: Mon, 16 Jan 2017 13:52:06 -0800 Subject: Status / Interfaces - Relinquish DHCP Lease Send gratuitous DHCP release message to server. Dependency: To fully relinquish the DHCP lease, the "RELEASE" reason needs to be added to the /sbin/dhclient-script. s/EXPIRE|FAIL)/EXPIRE|FAIL|RELEASE)/ Without the 'RELEASE' reason, the DHCP release message will still be sent to the server, however the local dhclient leases will not reflect the relinquishment. Therefore, DHCP renewal will do a DHCP request for the previous address rather than doing a DHCP discovery and being more likely to be assigned a different address. --- src/usr/local/www/status_interfaces.php | 37 ++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'src/usr/local/www/status_interfaces.php') diff --git a/src/usr/local/www/status_interfaces.php b/src/usr/local/www/status_interfaces.php index ae589b9..d08add9 100644 --- a/src/usr/local/www/status_interfaces.php +++ b/src/usr/local/www/status_interfaces.php @@ -69,6 +69,9 @@ require_once("filter.inc"); if ($_POST['ifdescr'] && $_POST['submit']) { $interface = $_POST['ifdescr']; if ($_POST['status'] == "up") { + if ($_POST['relinquish_lease']) { + dhcp_relinquish_lease($_POST['if'], $_POST['ifdescr'], $_POST['ipv']); + } interface_bring_down($interface); } else { interface_configure($interface); @@ -85,6 +88,7 @@ $formtemplate = '
' '' . '%s' . '' . + '%s' . '
'; // Display a term/definition pair @@ -96,17 +100,28 @@ function showDef($show, $term, $def) { } // Display a term/definition pair with a button -function showDefBtn($show, $term, $def, $ifdescr, $btnlbl) { +function showDefBtn($show, $term, $def, $ifdescr, $btnlbl, $chkbox_relinquish_lease) { global $formtemplate; if ($show) { print('
' . $term . '
'); print('
'); - printf($formtemplate, $term, $ifdescr, $show, htmlspecialchars($def) . ' ', $btnlbl, $btnlbl); + printf($formtemplate, $term, $ifdescr, $show, htmlspecialchars($def) . ' ', $btnlbl, $btnlbl, $chkbox_relinquish_lease); print('
'); } } +// Relinquish the DHCP lease from the server. +function dhcp_relinquish_lease($if, $ifdescr, $ipv) { + $leases_db = '/var/db/dhclient.leases.' . $if; + $conf_file = '/var/etc/dhclient_'.$ifdescr.'.conf'; + $script_file = '/sbin/dhclient-script'; + + if (file_exists($leases_db) && file_exists($script_file)) { + mwexec('/usr/local/sbin/dhclient -'.$ipv.' -d -r -lf '.$leases_db.' -cf '.$conf_file.' -sf '.$script_file); + } +} + $pgtitle = array(gettext("Status"), gettext("Interfaces")); $shortcut_section = "interfaces"; include("head.inc"); @@ -116,6 +131,12 @@ $ifdescrs = get_configured_interface_with_descr(false, true); foreach ($ifdescrs as $ifdescr => $ifname): $ifinfo = get_interface_info($ifdescr); $mac_man = load_mac_manufacturer_table(); + + $chkbox_relinquish_lease = '   ' . + ' ' . gettext("Relinquish Lease") . + ''; + $chkbox_relinquish_lease_v4 = $chkbox_relinquish_lease . ''; + $chkbox_relinquish_lease_v6 = $chkbox_relinquish_lease . ''; ?>
@@ -124,12 +145,12 @@ foreach ($ifdescrs as $ifdescr => $ifname):