Move HAproxy exceptions into their own class, and downgrade HAproxy errors since they are handled

This commit is contained in:
2024-06-01 12:55:27 +10:00
parent 73cf421739
commit 38795b83bf
12 changed files with 37 additions and 32 deletions

View File

@@ -6,6 +6,8 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use App\Classes\Sock\Exception\{HAproxyException,SocketException};
/**
* Class SocketClient
*
@@ -57,34 +59,26 @@ final class SocketClient {
if (config('fido.haproxy')) {
Log::debug(sprintf('%s:+ HAPROXY connection host [%s] on port [%d] (%s)',self::LOGKEY,$this->address_remote,$this->port_remote,$this->type));
if ($this->read(5,12) !== "\x0d\x0a\x0d\x0a\x00\x0d\x0aQUIT\x0a") {
Log::error(sprintf('%s:! Failed to initialise HAPROXY connection',self::LOGKEY));
throw new SocketException(SocketException::CANT_CONNECT,'Failed to initialise HAPROXY connection');
}
if ($this->read(5,12) !== "\x0d\x0a\x0d\x0a\x00\x0d\x0aQUIT\x0a")
throw new HAproxyException('Failed to initialise HAPROXY connection');
// Version/Command
$vc = $this->read_ch(5);
if (($x=($vc>>4)&0x7) !== 2) {
Log::error(sprintf('%s:! HAPROXY version [%d] is not handled',self::LOGKEY,$x));
throw new SocketException(SocketException::CANT_CONNECT,'Unknown HAPROXY version');
}
if (($x=($vc>>4)&0x7) !== 2)
throw new HAproxyException(sprintf('Unknown HAPROXY version [%d]',$x));
switch ($x=($vc&0x7)) {
// HAPROXY internal
case 0:
Log::debug(sprintf('%s:! HAPROXY internal health-check',self::LOGKEY));
throw new SocketException(SocketException::CANT_CONNECT,'Healthcheck');
throw new HAproxyException('HAPROXY internal health-check');
// PROXY connection
case 1:
break;
default:
Log::error(sprintf('%s:! HAPROXY command [%d] is not handled',self::LOGKEY,$x));
throw new SocketException(SocketException::CANT_CONNECT,'Unknown HAPROXY command');
throw new HAproxyException(sprintf('HAPROXY command [%d] is not handled',$x));
}
// Protocol/Address Family
@@ -101,8 +95,7 @@ final class SocketClient {
break;
default:
Log::error(sprintf('%s:! HAPROXY protocol [%d] is not handled',self::LOGKEY,$x));
throw new SocketException(SocketException::CANT_CONNECT,'Unknown HAPROXY protocol');
throw new HAproxyException(sprintf('HAPROXY protocol [%d] is not handled',$x));
}
switch ($x=($pa&0x7)) {
@@ -110,8 +103,7 @@ final class SocketClient {
break;
default:
Log::error(sprintf('%s:! HAPROXY address family [%d] is not handled',self::LOGKEY,$x));
throw new SocketException(SocketException::CANT_CONNECT,'Unknown HAPROXY address family');
throw new HAproxyException(sprintf('HAPROXY address family [%d] is not handled',$x));
}
$len = Arr::get(unpack('n',$this->read(5,2)),1);
@@ -126,8 +118,7 @@ final class SocketClient {
$dst = inet_ntop($this->read(5,16));
} else {
Log::error(sprintf('%s:! HAPROXY address len [%d:%d] is not handled',self::LOGKEY,$p,$len));
throw new SocketException(SocketException::CANT_CONNECT,'Unknown HAPROXY address length');
throw new HAproxyException(sprintf('HAPROXY address len [%d:%d] is not handled',$p,$len));
}
$src_port = unpack('n',$this->read(5,2));