diff options
author | PiBa-NL <pba_2k3@yahoo.com> | 2017-06-24 20:09:21 +0200 |
---|---|---|
committer | PiBa-NL <pba_2k3@yahoo.com> | 2017-06-24 20:09:21 +0200 |
commit | 29fa6f0f46ba039a67a93c00a08bcaecc3935b78 (patch) | |
tree | 25d6b8169ea1c88b833841b17a5f6989239fca17 /src/etc | |
parent | 05ae852482def5fce3f87bc2d61f07de53cec39a (diff) | |
download | pfsense-29fa6f0f46ba039a67a93c00a08bcaecc3935b78.zip pfsense-29fa6f0f46ba039a67a93c00a08bcaecc3935b78.tar.gz |
gateway monitoring, give apinger some time to properly 'initialize' before using its results
Diffstat (limited to 'src/etc')
-rw-r--r-- | src/etc/inc/gwlb.inc | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/src/etc/inc/gwlb.inc b/src/etc/inc/gwlb.inc index 1e927f5..55f3135 100644 --- a/src/etc/inc/gwlb.inc +++ b/src/etc/inc/gwlb.inc @@ -323,26 +323,44 @@ function get_dpinger_status($gwname, $detailed = false) { log_error("dpinger: status socket {$proc['socket']} not found"); return false; } - - $fp = stream_socket_client("unix://{$proc['socket']}", $errno, $errstr, 10); - if (!$fp) { - log_error(sprintf(gettext('dpinger: cannot connect to status socket %1$s - %2$s (%3$s)'), $proc['socket'], $errstr, $errno)); - return false; - } - - $status = ''; - while (!feof($fp)) { - $status .= fgets($fp, 1024); + $timeoutcounter = 0; + while (true) { + $fp = stream_socket_client("unix://{$proc['socket']}", $errno, $errstr, 10); + if (!$fp) { + log_error(sprintf(gettext('dpinger: cannot connect to status socket %1$s - %2$s (%3$s)'), $proc['socket'], $errstr, $errno)); + return false; + } + + $status = ''; + while (!feof($fp)) { + $status .= fgets($fp, 1024); + } + fclose($fp); + + $r = array(); + list( + $r['gwname'], + $r['latency_avg'], + $r['latency_stddev'], + $r['loss'] + ) = explode(' ', preg_replace('/\n/', '', $status)); + + // dpinger returns '<gwname> 0 0 0' when queried directly after it starts. + // while a latency of 0 and a loss of 0 would be perfect, in a real world it doesnt happen. + // or does it, anyone? if so we must 'detect' the initialization period differently.. + $ready = $r['latency_stddev'] != '0' || $r['loss'] != '0'; + + if ($ready) { + break; + } else { + $timeoutcounter++; + if ($timeoutcounter > 300) { + log_error(sprintf(gettext('dpinger: timeout while retrieving status for gateway %s'), $gwname)); + return false; + } + usleep(10000); + } } - fclose($fp); - - $r = array(); - list( - $r['gwname'], - $r['latency_avg'], - $r['latency_stddev'], - $r['loss'] - ) = explode(' ', preg_replace('/\n/', '', $status)); $r['srcip'] = $proc['srcip']; $r['targetip'] = $proc['targetip']; |