#include "dnswriter.hh"
#include "dnsname.hh"
#include "pdnsexception.hh"
+#include "iputils.hh"
/** DNS records have three representations:
1) in the packet
xfrBlob(val, 16);
}
+ void xfrCAWithoutPort(uint8_t version, ComboAddress &val) {
+ string blob;
+ if (version == 4) xfrBlob(blob, 4);
+ else if (version == 6) xfrBlob(blob, 16);
+ else throw runtime_error("invalid IP protocol");
+ val = makeComboAddressFromRaw(version, blob);
+ }
+
+ void xfrCAPort(ComboAddress &val) {
+ uint16_t port;
+ xfr16BitInt(port);
+ val.sin4.sin_port = port;
+ }
+
void xfrTime(uint32_t& val)
{
xfr32BitInt(val);
}
+
ComboAddress ARecordContent::getCA(int port) const
{
ComboAddress ret;
boilerplate_conv(AAAA, QType::AAAA, conv.xfrIP6(d_ip6); );
+boilerplate_conv(XPF, QType::XPF, conv.xfr8BitInt(d_version);
+ conv.xfr8BitInt(d_protocol);
+ conv.xfrCAWithoutPort(d_version, d_src);
+ conv.xfrCAWithoutPort(d_version, d_dst);
+ conv.xfrCAPort(d_src);
+ conv.xfrCAPort(d_dst));
+
boilerplate_conv(NS, QType::NS, conv.xfrName(d_content, true));
boilerplate_conv(PTR, QType::PTR, conv.xfrName(d_content, true));
boilerplate_conv(CNAME, QType::CNAME, conv.xfrName(d_content, true));
DLVRecordContent::report();
DNSRecordContent::regist(QClass::ANY, QType::TSIG, &TSIGRecordContent::make, &TSIGRecordContent::make, "TSIG");
DNSRecordContent::regist(QClass::ANY, QType::TKEY, &TKEYRecordContent::make, &TKEYRecordContent::make, "TKEY");
+ XPFRecordContent::report();
//TSIGRecordContent::report();
OPTRecordContent::report();
EUI48RecordContent::report();
#include <set>
#include <bitset>
#include "namespaces.hh"
+#include "iputils.hh"
#define includeboilerplate(RNAME) RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr); \
RNAME##RecordContent(const string& zoneData); \
string d_ip6; // why??
};
+class XPFRecordContent : public DNSRecordContent
+{
+public:
+ XPFRecordContent(uint8_t protocol, const ComboAddress& src, const ComboAddress& dst);
+ includeboilerplate(XPF);
+
+ uint8_t d_version;
+ uint8_t d_protocol;
+ ComboAddress d_src;
+ ComboAddress d_dst;
+};
+
class MXRecordContent : public DNSRecordContent
{
public:
#include "dns.hh"
#include "dnsname.hh"
#include "namespaces.hh"
+#include "iputils.hh"
#include <arpa/inet.h>
{
xfrBlob(val,16);
}
+
+ void xfrCAWithoutPort(uint8_t version, ComboAddress &val)
+ {
+ if (version == 4) xfrIP(val.sin4.sin_addr.s_addr);
+ else if (version == 6) {
+ string blob;
+ blob.assign((const char*)val.sin6.sin6_addr.s6_addr, 16);
+ xfrBlob(blob, 16);
+ }
+ else throw runtime_error("invalid IP protocol");
+ }
+
+ void xfrCAPort(ComboAddress &val)
+ {
+ uint16_t port;
+ port = val.sin4.sin_port;
+ xfr16BitInt(port);
+ }
+
void xfrTime(const uint32_t& val)
{
xfr32BitInt(val);
string toString() const
{
char host[1024];
- if(sin4.sin_family && !getnameinfo((struct sockaddr*) this, getSocklen(), host, sizeof(host),0, 0, NI_NUMERICHOST))
+ int retval;
+ if(sin4.sin_family && !(retval = getnameinfo((struct sockaddr*) this, getSocklen(), host, sizeof(host),0, 0, NI_NUMERICHOST)))
return host;
else
- return "invalid";
+ return "invalid "+string(gai_strerror(retval));
}
string toStringWithPort() const
return address;
}
+inline ComboAddress makeComboAddressFromRaw(uint8_t version, const string &str)
+{
+ ComboAddress address;
+ size_t len;
+
+ if (version == 4) { len = 4; address.sin4.sin_family=AF_INET; }
+ else if (version == 6) { len = 16; address.sin4.sin_family=AF_INET6; }
+ else throw NetmaskException("invalid address family");
+ if(str.size() != len) throw NetmaskException("invalid raw address length");
+ memcpy(&address.sin4.sin_addr, str.c_str(), len);
+
+ return address;
+}
+
/** This class represents a netmask and can be queried to see if a certain
IP address is matched by this mask */
class Netmask
CAA=257,
DLV=32769,
ADDR=65400,
- ALIAS=65401
+ ALIAS=65401,
+ XPF=65422
};
typedef pair<string,uint16_t> namenum;
qtype_insert("DLV", 32769);
qtype_insert("ADDR", 65400);
qtype_insert("ALIAS", 65401);
+ qtype_insert("XPF", 65422);
}
} initializer;
d_pos += len;
}
+void RecordTextReader::xfrCAWithoutPort(uint8_t version, ComboAddress &val)
+{
+ if (version == 4) {
+ uint32_t ip;
+ xfrIP(ip);
+ val = makeComboAddressFromRaw(4, string((const char*) &ip, 4));
+ }
+ else if (version == 6) {
+ string ip;
+ xfrIP6(ip);
+ val = makeComboAddressFromRaw(6, ip);
+ }
+ else throw RecordTextException("invalid address family");
+}
+
+void RecordTextReader::xfrCAPort(ComboAddress &val)
+{
+ uint16_t port;
+ xfr16BitInt(port);
+ val.sin4.sin_port = port;
+}
+
bool RecordTextReader::eof()
{
return d_pos==d_end;
d_string += std::string(addrbuf);
}
+void RecordTextWriter::xfrCAWithoutPort(uint8_t version, ComboAddress &val)
+{
+ string ip = val.toString();
+
+ if(!d_string.empty())
+ d_string.append(1,' ');
+
+ d_string += ip;
+}
+
+void RecordTextWriter::xfrCAPort(ComboAddress &val)
+{
+ xfr16BitInt(val.sin4.sin_port);
+}
+
void RecordTextWriter::xfrTime(const uint32_t& val)
{
if(!d_string.empty())
#include "namespaces.hh"
#include "dnsname.hh"
+#include "iputils.hh"
class RecordTextException : public runtime_error
{
void xfrType(uint16_t& val);
void xfrIP(uint32_t& val);
void xfrIP6(std::string& val);
+ void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
+ void xfrCAPort(ComboAddress &val);
void xfrTime(uint32_t& val);
void xfrName(DNSName& val, bool compress=false, bool noDot=false);
void xfr8BitInt(const uint8_t& val);
void xfrIP(const uint32_t& val);
void xfrIP6(const std::string& val);
+ void xfrCAWithoutPort(uint8_t version, ComboAddress &val);
+ void xfrCAPort(ComboAddress &val);
void xfrTime(const uint32_t& val);
void xfrBase32HexBlob(const string& val);
google-alias IN ALIAS google-public-dns-a.google.com.
;
host-for-auto-ptr IN A 192.0.2.1
+;
+xpf IN XPF 4 17 1.2.3.4 5.6.7.8 43707 52445
+xpf6 IN XPF 6 17 1:2:3:4:5:6:7:8 f:e:d:c:b:a:9:8 43707 52445
\ No newline at end of file