From f427d68dbca5ed9941b3bc01be1c4d81417c134f Mon Sep 17 00:00:00 2001 From: jim-p Date: Mon, 3 Jun 2019 12:47:51 -0400 Subject: [PATCH] Teach dhcrelay about upstream and downstream interfaces. Fixes #9466 No config changes or UI changes, it is handled automatically. --- src/etc/inc/services.inc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index c15373e649..32bcec875e 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -1747,6 +1747,7 @@ function services_dhcrelay_configure() { $iflist = get_configured_interface_list(); + $dhcrelayifs = array(); $dhcifaces = explode(",", $dhcrelaycfg['interface']); foreach ($dhcifaces as $dhcrelayif) { if (!isset($iflist[$dhcrelayif]) || @@ -1758,6 +1759,7 @@ function services_dhcrelay_configure() { $dhcrelayifs[] = get_real_interface($dhcrelayif); } } + $dhcrelayifs = array_unique($dhcrelayifs); /* * In order for the relay to work, it needs to be active @@ -1768,22 +1770,31 @@ function services_dhcrelay_configure() { log_error(gettext("No destination IP has been configured!")); return; } - + $srvifaces = array(); foreach ($srvips as $srcidx => $srvip) { $destif = guess_interface_from_ip($srvip); if (!empty($destif)) { - $dhcrelayifs[] = $destif; + $srvifaces[] = $destif; } } - $dhcrelayifs = array_unique($dhcrelayifs); + $srvifaces = array_unique($srvifaces); + + /* The server interface(s) should not be in this list */ + $dhcrelayifs = array_diff($dhcrelayifs, $srvifaces); /* fire up dhcrelay */ if (empty($dhcrelayifs)) { - log_error(gettext("No suitable interface found for running dhcrelay!")); + log_error(gettext("No suitable downstream interfaces found for running dhcrelay!")); + return; /* XXX */ + } + if (empty($srvifaces)) { + log_error(gettext("No suitable upstream interfaces found for running dhcrelay!")); return; /* XXX */ } - $cmd = "/usr/local/sbin/dhcrelay -i " . implode(" -i ", $dhcrelayifs); + $cmd = "/usr/local/sbin/dhcrelay"; + $cmd .= " -id " . implode(" -id ", $dhcrelayifs); + $cmd .= " -iu " . implode(" -iu ", $srvifaces); if (isset($dhcrelaycfg['agentoption'])) { $cmd .= " -a -m replace";