Compare commits

..

No commits in common. "bee7e5d64a5d1c885dd8fae2986f45a6c85cc1d8" and "179233385b520dccd753734550f26f0b30120744" have entirely different histories.

3 changed files with 64 additions and 137 deletions

View File

@ -31,7 +31,7 @@ REDIS_PASSWORD=
REDIS_PORT=6379 REDIS_PORT=6379
MAIL_DRIVER=smtp MAIL_DRIVER=smtp
MAIL_HOST=smtp MAIL_HOST=mail.dege.lan
MAIL_PORT=25 MAIL_PORT=25
MAIL_USERNAME= MAIL_USERNAME=
MAIL_PASSWORD= MAIL_PASSWORD=
@ -49,7 +49,6 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
FIDO_DIR=fido FIDO_DIR=fido
FIDO_PACKET_KEEP= FIDO_PACKET_KEEP=
FIDO_STRICT=false FIDO_STRICT=false
FIDO_HAPROXY=false
FILESYSTEM_DISK=s3 FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID= AWS_ACCESS_KEY_ID=
@ -62,9 +61,3 @@ AWS_USE_PATH_STYLE_ENDPOINT=true
MATRIX_SERVER= MATRIX_SERVER=
MATRIX_AS_TOKEN= MATRIX_AS_TOKEN=
MATRIX_HS_TOKEN= MATRIX_HS_TOKEN=
FIDO_DNS_NS=
FIDO_IP_AAAA=
FIDO_AAAA_ORDER=
FIDO_IP_A=
FIDO_A_ORDER=

View File

@ -59,55 +59,9 @@ final class SocketClient {
if ((! $originate) && config('fido.haproxy')) { if ((! $originate) && 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)); Log::debug(sprintf('%s:+ HAPROXY connection host [%s] on port [%d] (%s)',self::LOGKEY,$this->address_remote,$this->port_remote,$this->type));
if (($x=$this->read(5,6)) === 'PROXY ') if ($this->read(5,12) !== "\x0d\x0a\x0d\x0a\x00\x0d\x0aQUIT\x0a")
$vers = 1;
elseif (($x === "\x0d\x0a\x0d\x0a\x00\x0d") && ($this->read('5,6') === "\x0aQUIT\x0a"))
$vers = 2;
else
throw new HAproxyException('Failed to initialise HAPROXY connection'); throw new HAproxyException('Failed to initialise HAPROXY connection');
switch ($vers) {
case 1:
// Protocol/Address Family
switch ($x=$this->read(5,5)) {
case 'TCP4 ':
$p = 4;
break;
case 'TCP6 ':
$p = 6;
break;
default:
throw new HAproxyException(sprintf('HAPROXY protocol [%d] is not handled',$x));
}
$read = $this->read(5,104-11);
// IPv4
if (($p === 4) || ($p === 6)) {
$parse = collect(sscanf($read,'%s %s %s %s'));
$src = Arr::get($parse,0);
$dst = Arr::get($parse,1);
$src_port = (int)Arr::get($parse,2);
$dst_port = (int)Arr::get($parse,3);
$len = $parse->map(fn($item)=>strlen($item))->sum()+3;
// The last 2 chars should be "\r\n"
if (($x=substr($read,$len)) !== "\r\n")
throw new HAproxyException(sprintf('HAPROXY parsing failed for version [%d] [%s] (%s)',$p,$read,hex_dump($x)));
} else {
throw new HAproxyException(sprintf('HAPROXY version [%d] is not handled [%s]',$p,$read));
}
$this->port_remote = $src_port;
break;
case 2:
// Version/Command // Version/Command
$vc = $this->read_ch(5); $vc = $this->read_ch(5);
@ -129,6 +83,7 @@ final class SocketClient {
// Protocol/Address Family // Protocol/Address Family
$pa = $this->read_ch(5); $pa = $this->read_ch(5);
$p = NULL;
switch ($x=($pa>>4)&0x7) { switch ($x=($pa>>4)&0x7) {
case 1: // AF_INET case 1: // AF_INET
@ -139,7 +94,8 @@ final class SocketClient {
$p = 6; $p = 6;
break; break;
default:
throw new HAproxyException(sprintf('HAPROXY protocol [%d] is not handled',$x));
} }
switch ($x=($pa&0x7)) { switch ($x=($pa&0x7)) {
@ -166,24 +122,17 @@ final class SocketClient {
} }
$src_port = unpack('n',$this->read(5,2)); $src_port = unpack('n',$this->read(5,2));
$dst_port = Arr::get(unpack('n',$this->read(5,2)),1); $dst_port = unpack('n',$this->read(5,2));
$this->port_remote = Arr::get($src_port,1);
break;
default:
throw new HAproxyException('Failed to initialise HAPROXY connection');
}
$this->address_remote = $src; $this->address_remote = $src;
$this->port_remote = Arr::get($src_port,1);
Log::debug(sprintf('%s:- HAPROXY src [%s:%d] dst [%s:%d]', Log::debug(sprintf('%s:- HAPROXY src [%s:%d] dst [%s:%d]',
self::LOGKEY, self::LOGKEY,
$this->address_remote, $this->address_remote,
$this->port_remote, $this->port_remote,
$dst, $dst,
$dst_port, Arr::get($dst_port,1),
)); ));
} }
@ -241,8 +190,7 @@ final class SocketClient {
{ {
Log::info(sprintf('%s:+ Creating connection to [%s:%d]',self::LOGKEY,$address,$port)); Log::info(sprintf('%s:+ Creating connection to [%s:%d]',self::LOGKEY,$address,$port));
$type = collect(config('fido.ip')) $sort = collect(['AAAA','A']);
->filter(fn($item)=>$item['enabled']);
if (filter_var($address,FILTER_VALIDATE_IP)) if (filter_var($address,FILTER_VALIDATE_IP))
$resolved = collect([[ $resolved = collect([[
@ -251,9 +199,9 @@ final class SocketClient {
]]); ]]);
else else
// We only look at AAAA/A records // We only look at AAAA/A records
$resolved = collect(dns_get_record($address,$type->map(fn($item)=>$item['type'])->sum())) $resolved = collect(dns_get_record($address,DNS_AAAA|DNS_A))
->filter(fn($item)=>$type->has(Arr::get($item,'type'))) ->filter(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')) !== FALSE; })
->sort(fn($a,$b)=>$type->get(Arr::get($a,'type'))['order'] < $type->get(Arr::get($b,'type'))['order']); ->sort(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')); });
if (! $resolved->count()) if (! $resolved->count())
throw new SocketException(SocketException::CANT_CONNECT,sprintf('%s doesnt resolved to an IPv4/IPv6 address',$address)); throw new SocketException(SocketException::CANT_CONNECT,sprintf('%s doesnt resolved to an IPv4/IPv6 address',$address));

View File

@ -43,18 +43,4 @@ return [
'down' => 35, 'down' => 35,
'delist' => 45, 'delist' => 45,
], ],
// IP Address Resolution preferences
'ip' => [
'AAAA' => [
'enabled' => env('FIDO_IP_AAAA',false),
'order' => env('FIDO_AAAA_ORDER',2),
'type' => DNS_AAAA,
],
'A' => [
'enabled' => env('FIDO_IP_A',TRUE),
'order' => env('FIDO_A_ORDER',1),
'type' => DNS_A,
],
],
]; ];