From 076e5d4fc00eb8f3691afec40567024e64bfe387 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 7 Jan 2016 15:15:23 +0100 Subject: [PATCH] document various toStringWithPort and getPort() functions, and add them to examples --- docs/markdown/recursor/scripting.md | 7 +++++-- pdns/README-dnsdist.md | 2 ++ pdns/dnsdistconf.lua | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/markdown/recursor/scripting.md b/docs/markdown/recursor/scripting.md index b1cae513d..e57f1f7bc 100644 --- a/docs/markdown/recursor/scripting.md +++ b/docs/markdown/recursor/scripting.md @@ -65,7 +65,7 @@ find it [here](https://github.com/PowerDNS/pdns/blob/master/pdns/powerdns-exampl In the 4.x API, addresses and DNS Names are not passed as strings but as native objects. This allows for easy checking against netmasks and domain sets. It also means that to print such names, the `:toString` -method must be used. +method must be used (or even `:toStringWithPort` for addresses). Comparing IP addresses and DNSNames is not done with '==' but with the `:equal` method. @@ -178,7 +178,7 @@ A minimal sample script: ``` function nxdomain(dq) print("Intercepting NXDOMAIN for: ",dq.qname:toString()) - if dq.qtype == pdns.A + if dq.qtype == pdns.A then dq.rcode=0 -- make it a normal answer dq:addAnswer(pdns.A, "192.168.1.1") @@ -224,6 +224,9 @@ it against a NetmaskGroup as described above. To compare the address (so not the port) of two ComboAddresses, use `:equal`. +To convert an address to human-friendly representation, use `:toString()` or `:toStringWithPort()`. To +get only the port number, use `:getPort()`. + ### Metrics You can custom metrics which will be shown in the output of 'rec_control get-all' and sent to the metrics server over the Carbon protocol, and also appear in the JSON HTTP API. diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index 735807782..ed8dd20e0 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -847,7 +847,9 @@ instantiate a server with additional parameters * Advanced functions for writing your own policies and hooks * ComboAddress related: * `newCA(address)`: return a new ComboAddress + * `getPort()`: return the port number * `tostring()`: return in human-friendly format + * `tostringWithPort()`: return in human-friendly format, with port number * DNSName related: * `newDNSName(name)`: make a DNSName based on this .-terminated name * member `isPartOf(dnsname)`: is this dnsname part of that dnsname diff --git a/pdns/dnsdistconf.lua b/pdns/dnsdistconf.lua index bdb37edf3..35aee47d6 100644 --- a/pdns/dnsdistconf.lua +++ b/pdns/dnsdistconf.lua @@ -55,6 +55,7 @@ truncateNMG:addMask("fe80::/16") print(string.format("Have %d entries in truncate NMG", truncateNMG:size())) function blockFilter(remote, qname, qtype, dh) + print(string.format("Got query from %s, (%s) port number: %d", remote:tostring(), remote:tostringWithPort(), remote:getPort())) if(qtype==255 or truncateNMG:match(remote)) then -- print("any query, tc=1") -- 2.40.0