DNS server now responds to SRV and TXT records
This commit is contained in:
parent
073d95f605
commit
62f0c1a909
@ -8,7 +8,7 @@ use Illuminate\Support\Str;
|
|||||||
use App\Classes\Protocol as BaseProtocol;
|
use App\Classes\Protocol as BaseProtocol;
|
||||||
use App\Classes\Sock\SocketClient;
|
use App\Classes\Sock\SocketClient;
|
||||||
use App\Http\Controllers\DomainController;
|
use App\Http\Controllers\DomainController;
|
||||||
use App\Models\{Address,Domain};
|
use App\Models\{Address,Domain,Mailer};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Respond to DNS queries and provide addresses to FTN nodes.
|
* Respond to DNS queries and provide addresses to FTN nodes.
|
||||||
@ -164,9 +164,28 @@ final class DNS extends BaseProtocol
|
|||||||
case self::DNS_TYPE_CNAME:
|
case self::DNS_TYPE_CNAME:
|
||||||
case self::DNS_TYPE_A:
|
case self::DNS_TYPE_A:
|
||||||
case self::DNS_TYPE_AAAA:
|
case self::DNS_TYPE_AAAA:
|
||||||
|
case self::DNS_TYPE_SRV:
|
||||||
|
case self::DNS_TYPE_TXT:
|
||||||
Log::info(sprintf('%s:= Looking for record [%s] for [%s]',self::LOGKEY,$this->query->type,$this->query->domain));
|
Log::info(sprintf('%s:= Looking for record [%s] for [%s]',self::LOGKEY,$this->query->type,$this->query->domain));
|
||||||
|
|
||||||
$labels = clone($this->query->labels);
|
$labels = clone($this->query->labels);
|
||||||
|
$mailer = '';
|
||||||
|
|
||||||
|
// If this is a SRV record query
|
||||||
|
if ($this->query->type === self::DNS_TYPE_SRV) {
|
||||||
|
switch ($labels->first()) {
|
||||||
|
case '_binkp':
|
||||||
|
if ($labels->skip(1)->first() !== '_tcp')
|
||||||
|
return $this->reply(self::DNS_NAMEERR);
|
||||||
|
|
||||||
|
$labels->shift(2);
|
||||||
|
$mailer = Mailer::where('name','BINKP')->singleOrFail();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return $this->reply(self::DNS_NAMEERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// First check that it is a query we can answer
|
// First check that it is a query we can answer
|
||||||
// First label should be p.. or f..
|
// First label should be p.. or f..
|
||||||
@ -207,9 +226,33 @@ final class DNS extends BaseProtocol
|
|||||||
|
|
||||||
Log::info(sprintf('%s:= Returning [%s] for DNS query [%s]',self::LOGKEY,$ao->system->address,$ao->ftn));
|
Log::info(sprintf('%s:= Returning [%s] for DNS query [%s]',self::LOGKEY,$ao->system->address,$ao->ftn));
|
||||||
|
|
||||||
return $this->reply(
|
switch ($this->query->type) {
|
||||||
self::DNS_NOERROR,
|
case self::DNS_TYPE_SRV:
|
||||||
[serialize($this->domain_split($ao->system->address)) => self::DNS_TYPE_CNAME]);
|
if ($xx=$ao->system->mailers->where('id',$mailer->id)->pop()) {
|
||||||
|
return $this->reply(
|
||||||
|
self::DNS_NOERROR,
|
||||||
|
[serialize([
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
$xx->pivot->port,
|
||||||
|
$this->domain_split($ao->system->address),
|
||||||
|
]) => self::DNS_TYPE_SRV]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return $this->nameerr();
|
||||||
|
}
|
||||||
|
|
||||||
|
case self::DNS_TYPE_TXT:
|
||||||
|
return $this->reply(
|
||||||
|
self::DNS_NOERROR,
|
||||||
|
[serialize($ao->system->name) => self::DNS_TYPE_TXT]);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return $this->reply(
|
||||||
|
self::DNS_NOERROR,
|
||||||
|
[serialize($this->domain_split($ao->system->address)) => self::DNS_TYPE_CNAME]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Other attributes return NOTIMPL
|
// Other attributes return NOTIMPL
|
||||||
default:
|
default:
|
||||||
@ -378,6 +421,16 @@ final class DNS extends BaseProtocol
|
|||||||
$a .= pack('NNNNN',$ars[2],$ars[3],$ars[4],$ars[5],$ars[6]);
|
$a .= pack('NNNNN',$ars[2],$ars[3],$ars[4],$ars[5],$ars[6]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case self::DNS_TYPE_SRV:
|
||||||
|
$a .= pack('nnn',$ars[0],$ars[1],$ars[2]);
|
||||||
|
$a .= $ars[3];
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case self::DNS_TYPE_TXT:
|
||||||
|
$a .= pack('C',strlen($ars)).$ars;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reply .= pack('n',strlen($a)).$a;
|
$reply .= pack('n',strlen($a)).$a;
|
||||||
|
Loading…
Reference in New Issue
Block a user