From 9aecd61a2f81cdb1ad9a3aa2836ce6f067588ce1 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 25 Oct 2024 23:28:39 +1100 Subject: [PATCH] Add configuration items to determine DNS records returned and sort order --- .env.example | 6 ++++++ app/Classes/Sock/SocketClient.php | 9 +++++---- config/fido.php | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 022a987..b4af561 100644 --- a/.env.example +++ b/.env.example @@ -61,3 +61,9 @@ AWS_USE_PATH_STYLE_ENDPOINT=true MATRIX_SERVER= MATRIX_AS_TOKEN= MATRIX_HS_TOKEN= + +FIDO_DNS_NS= +FIDO_IP_AAAA= +FIDO_AAAA_ORDER= +FIDO_IP_A= +FIDO_A_ORDER= diff --git a/app/Classes/Sock/SocketClient.php b/app/Classes/Sock/SocketClient.php index a3f051c..1b2aa50 100644 --- a/app/Classes/Sock/SocketClient.php +++ b/app/Classes/Sock/SocketClient.php @@ -190,7 +190,8 @@ final class SocketClient { { Log::info(sprintf('%s:+ Creating connection to [%s:%d]',self::LOGKEY,$address,$port)); - $sort = collect(['AAAA','A']); + $type = collect(config('fido.ip')) + ->filter(fn($item)=>$item['enabled']); if (filter_var($address,FILTER_VALIDATE_IP)) $resolved = collect([[ @@ -199,9 +200,9 @@ final class SocketClient { ]]); else // We only look at AAAA/A records - $resolved = collect(dns_get_record($address,DNS_AAAA|DNS_A)) - ->filter(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')) !== FALSE; }) - ->sort(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')); }); + $resolved = collect(dns_get_record($address,$type->map(fn($item)=>$item['type'])->sum())) + ->filter(fn($item)=>$type->has(Arr::get($item,'type'))) + ->sort(fn($a,$b)=>$type->get(Arr::get($a,'type'))['order'] < $type->get(Arr::get($b,'type'))['order']); if (! $resolved->count()) throw new SocketException(SocketException::CANT_CONNECT,sprintf('%s doesnt resolved to an IPv4/IPv6 address',$address)); diff --git a/config/fido.php b/config/fido.php index 13d02e6..9503fd1 100644 --- a/config/fido.php +++ b/config/fido.php @@ -43,4 +43,18 @@ return [ 'down' => 35, '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, + ], + ], ]; \ No newline at end of file