Skip to content

JDWX DNSQuery Notifier

JDW edited this page Jul 17, 2022 · 1 revision

JDWX\DNSQuery\Notifier

The main dynamic DNS notifier class.

This class provides functions to handle DNS notify requests as defined by RFC 1996.

This is separate from the Resolver class, as while the underlying protocol is the same, the functionality is completely different.

Generally, query (recursive) lookups are done against caching server, while notify requests are done against authoritative servers.

Constants

VERSION

const VERSION = '2.0.0'

RESOLV_CONF

const RESOLV_CONF = '/etc/resolv.conf'

Properties

packet

private  packet
  • Visibility: private

authSignature

protected  authSignature = null
  • Visibility: protected

dnsPort

protected  dnsPort = 53
  • Visibility: protected

dnssec

protected  dnssec = false
  • Visibility: protected

dnssecADFlag

protected  dnssecADFlag = false
  • Visibility: protected

dnssecCDFlag

protected  dnssecCDFlag = false
  • Visibility: protected

dnssecPayloadSize

protected  dnssecPayloadSize = 4000
  • Visibility: protected

domain

protected  domain = ''
  • Visibility: protected

lastException

protected  lastException = null
  • Visibility: protected

lastExceptionList

protected  lastExceptionList = []
  • Visibility: protected

localAddress

protected  localAddress = ''
  • Visibility: protected

localPort

protected  localPort
  • Visibility: protected

nsRandom

protected  nsRandom = false
  • Visibility: protected

searchList

protected  searchList = []
  • Visibility: protected

timeout

protected  timeout = 5
  • Visibility: protected

transportManager

protected  transportManager
  • Visibility: protected

useResolvOptions

protected  useResolvOptions = false
  • Visibility: protected

useTCP

protected  useTCP = false
  • Visibility: protected

nameServers

private  nameServers = []
  • Visibility: private

Methods

__construct

mixed JDWX\DNSQuery\BaseQuery::__construct(array|string|null i_nameServers, ?string i_resolvConf)

Constructor - base constructor for the Notifier, Resolver and Updater

Arguments

  • i_nameServers array|string|null
  • i_resolvConf ?string

add

bool JDWX\DNSQuery\Notifier::add(\JDWX\DNSQuery\RR\RR rr)

3.7 - Add RR to notify

  • Visibility: public

Arguments

notify

bool JDWX\DNSQuery\Notifier::notify(?\JDWX\DNSQuery\Packet\ResponsePacket response)

executes the notify request

  • Visibility: public

Arguments

  • response ?\JDWX\DNSQuery\Packet\ResponsePacket - contains a reference to the response object after running

packet

\JDWX\DNSQuery\Packet\RequestPacket JDWX\DNSQuery\Notifier::packet()

returns the current internal packet object.

  • Visibility: public

_checkName

void JDWX\DNSQuery\Notifier::_checkName(string name)

checks that the given name matches the name for the zone we're notifying

  • Visibility: private

Arguments

  • name string - The name to be checked.

expandIPv6

string JDWX\DNSQuery\BaseQuery::expandIPv6(string i_address)

formats the given IPv6 address as a fully expanded IPv6 address

Arguments

  • i_address string - the IPv6 address to expand

expandUint32

string JDWX\DNSQuery\BaseQuery::expandUint32(int i_int)

PHP doesn't support unsigned integers, but many of the RRs return unsigned values (like SOA), so there is the possibility that the value will overrun on 32bit systems, and you'll end up with a negative value.

64bit systems are not affected, as their PHP_INT_MAX value should be 64bit (ie 9223372036854775807)

This function returns a negative integer value, as a string, with the correct unsigned value.

Arguments

  • i_int int - the unsigned integer value to check

isIPv4

bool JDWX\DNSQuery\BaseQuery::isIPv4(string i_address)

returns true/false if the given address is a valid IPv4 address

Arguments

  • i_address string - the IPv4 address to check

isIPv6

bool JDWX\DNSQuery\BaseQuery::isIPv6(string i_address)

returns true/false if the given address is a valid IPv6 address

Arguments

  • i_address string - the IPv6 address to check

closeSockets

void JDWX\DNSQuery\BaseQuery::closeSockets()

give users access to close all open sockets on the resolver object; resetting each array, calls the destructor on the Socket object, which calls the close() method on each object.

getNameServers

string[] JDWX\DNSQuery\BaseQuery::getNameServers()

Gets the currently-configured name servers or loads them from the default resolv.conf if none are specified.

setDNSPort

static JDWX\DNSQuery\BaseQuery::setDNSPort(int i_dnsPort)

Set the DNS server port to use. (Default is 53 for both TCP and UDP DNS.)

Arguments

  • i_dnsPort int

setDNSSEC

static JDWX\DNSQuery\BaseQuery::setDNSSEC(bool i_dnssec)

Request DNSSEC values, by setting the DO flag to 1; this actually makes the resolver add an OPT RR to the additional section, and sets the DO flag in this RR to 1

Arguments

  • i_dnssec bool - Whether to use DNSSEC.

setDNSSECADFlag

static JDWX\DNSQuery\BaseQuery::setDNSSECADFlag(bool i_dnssecADFlag)

set the DNSSEC AD (Authentic Data) bit on/off; the AD bit on the request side was previously undefined, and resolvers we instructed to always clear the AD bit when sending a request.

RFC6840 section 5.7 defines setting the AD bit in the query as a signal to the server that it wants the value of the AD bit, without needed to request all the DNSSEC data via the DO bit.

Arguments

  • i_dnssecADFlag bool

setDNSSECCDFlag

static JDWX\DNSQuery\BaseQuery::setDNSSECCDFlag(bool i_dnssecCDFlag)

set the DNSSEC CD (Checking Disabled) bit on/off; turning this off means that the DNS resolver will perform its own signature validation so the DNS servers simply pass through all the details.

Arguments

  • i_dnssecCDFlag bool

setDNSSECPayloadSize

static JDWX\DNSQuery\BaseQuery::setDNSSECPayloadSize(int i_dnssecPayloadSize)

the EDNS(0) UDP payload size to use when making DNSSEC requests see RFC 4035 section 4.1 - EDNS Support.

there are some different ideas on the suggested size to support; but it seems to be "at least" 1220 bytes, but SHOULD support 4000 bytes. If this is not set, the default is 4000 bytes.

Arguments

  • i_dnssecPayloadSize int - Payload size in bytes.

setLocalAddress

static JDWX\DNSQuery\BaseQuery::setLocalAddress(string i_localHost)

Set the local IP address to use. (Default is empty, which means to use the default local IP address.)

Arguments

  • i_localHost string

setLocalPort

static JDWX\DNSQuery\BaseQuery::setLocalPort(int i_localPort)

Set the local port to use. (Default is 0, which means to use a local port selected by the OS.)

Arguments

  • i_localPort int - Local port value to use

setNameServer

mixed JDWX\DNSQuery\BaseQuery::setNameServer(string i_nameServer)

Shortcut to set a single name server.

Arguments

  • i_nameServer string - IPv4 or IPv6 address of the desired name server

setNameServers

mixed JDWX\DNSQuery\BaseQuery::setNameServers(string[] i_nameServers)

Sets the name servers to be used, specified as IPv4 or IPv6 addresses.

Arguments

  • i_nameServers string[] - a list of IPv4 or IPv6 addresses

setRandomizeNameServers

static JDWX\DNSQuery\BaseQuery::setRandomizeNameServers(bool i_randomize)

Set whether to randomize the name server list. (Default is false.)

Arguments

  • i_randomize bool - True to randomize the name server list, false to not randomize

setTimeout

static JDWX\DNSQuery\BaseQuery::setTimeout(int i_timeout)

Set the timeout value to use for socket connections. (Default is 5 seconds.)

Arguments

  • i_timeout int - Timeout value in seconds.

setUseResolvOptions

static JDWX\DNSQuery\BaseQuery::setUseResolvOptions(bool i_useResolvOptions)

Set whether to use options found in resolv.conf if one is parsed.

Note that this will not affect the use of the resolv.conf file if it is loaded from the constructor. So if you want this option, set it and then manually call useResolvConf().

Arguments

  • i_useResolvOptions bool - Whether to use options found in resolv.conf

setUseTCP

static JDWX\DNSQuery\BaseQuery::setUseTCP(bool i_useTCP)

Default to using TCP for requests. (TCP will always be used for large requests or AXFR requests.)

Arguments

  • i_useTCP bool - Whether to use TCP for requests by default.

signSIG0

void JDWX\DNSQuery\BaseQuery::signSIG0(\JDWX\DNSQuery\RR\SIG|string i_filename)

Add a SIG RR object for authentication.

Arguments

  • i_filename JDWX\DNSQuery\RR\SIG|string - a signature or the name of a file to load the signature from.

signTSIG

void JDWX\DNSQuery\BaseQuery::signTSIG(\JDWX\DNSQuery\RR\TSIG|string i_keyName, string i_signature, string i_algorithm)

Add a TSIG RR object for authentication

Arguments

  • i_keyName JDWX\DNSQuery\RR\TSIG|string - Key name to use for the TSIG RR
  • i_signature string - Key to sign the request.
  • i_algorithm string - Algorithm to use

useResolvConf

static JDWX\DNSQuery\BaseQuery::useResolvConf(?string i_resolvConf)

sets the name servers to be used, specified as IPv4 or IPv6 addresses

Arguments

  • i_resolvConf ?string - Filename to parse in the resolv.conf format or null to use the default resolv.conf file

sendPacket

\JDWX\DNSQuery\Packet\ResponsePacket JDWX\DNSQuery\BaseQuery::sendPacket(\JDWX\DNSQuery\Packet\RequestPacket i_request, bool i_useTCP)

Sends a RequestPacket

Arguments

parseOptions

void JDWX\DNSQuery\BaseQuery::parseOptions(string i_options)

parses the options line from a resolv.conf file; we don't support all the options yet, and using them is optional.

Arguments

  • i_options string - The "options" string from the resolv.conf file.

sendTCPRequest

\JDWX\DNSQuery\Packet\ResponsePacket JDWX\DNSQuery\BaseQuery::sendTCPRequest(string i_ns, string i_data, bool i_axfr)

sends a DNS request using TCP

Arguments

  • i_ns string - Name server to use for the request
  • i_data string - Raw DNS packet data
  • i_axfr bool - Whether this is a zone transfer request

sendUDPRequest

\JDWX\DNSQuery\Packet\ResponsePacket JDWX\DNSQuery\BaseQuery::sendUDPRequest(string i_ns, string i_data)

sends a DNS request using UDP

Arguments

  • i_ns string - the name server to use for the request
  • i_data string - the raw DNS packet data
Clone this wiki locally