From: Aki Tuomi Date: Mon, 13 May 2013 13:23:11 +0000 (+0300) Subject: Fixed IPSECKEY record handling X-Git-Tag: auth-3.3-rc1~58^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1cafb9582bb0dc0efec8f271c630e200d0431e74;p=pdns Fixed IPSECKEY record handling --- diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 8aef60eba..29585f75d 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -156,13 +156,111 @@ boilerplate_conv(KX, ns_t_kx, conv.xfrLabel(d_exchanger, false); ) -boilerplate_conv(IPSECKEY, 45, /* ns_t_ipsec */ - conv.xfr8BitInt(d_preference); +//boilerplate_conv(IPSECKEY, 45, /* ns_t_ipsec */ +/* conv.xfr8BitInt(d_preference); conv.xfr8BitInt(d_gatewaytype); conv.xfr8BitInt(d_algorithm); conv.xfrLabel(d_gateway, false); conv.xfrBlob(d_publickey); ) +*/ + +IPSECKEYRecordContent::DNSRecordContent* IPSECKEYRecordContent::make(const DNSRecord& dr, PacketReader& pr) +{ + return new IPSECKEYRecordContent(dr, pr); +} +IPSECKEYRecordContent::IPSECKEYRecordContent(const DNSRecord& dr, PacketReader& pr) : DNSRecordContent(ns_t_ipseckey) +{ + doRecordCheck(dr); xfrPacket(pr); +} +IPSECKEYRecordContent::DNSRecordContent* IPSECKEYRecordContent::make(const string& zonedata) +{ + return new IPSECKEYRecordContent(zonedata); +} +void IPSECKEYRecordContent::toPacket(DNSPacketWriter& pw) +{ + this->xfrPacket(pw); +} +void IPSECKEYRecordContent::report(void) { + regist(1, ns_t_ipseckey, &IPSECKEYRecordContent::make, &IPSECKEYRecordContent::make, "IPSECKEY"); +} +void IPSECKEYRecordContent::unreport(void) { + unregist(1, ns_t_ipseckey); +} +IPSECKEYRecordContent::IPSECKEYRecordContent(const std::string& zoneData) : DNSRecordContent(ns_t_ipseckey) { + try { + RecordTextReader rtr(zoneData); + xfrPacket(rtr); + } catch(RecordTextException& rtr) { + throw MOADNSException("Parsing record content: "+std::string(rtr.what())); + } +} + +std::string IPSECKEYRecordContent::getZoneRepresentation() const { + std::string ret; + RecordTextWriter conv(ret); + conv.xfr8BitInt(d_preference); + conv.xfr8BitInt(d_gatewaytype); + conv.xfr8BitInt(d_algorithm); + + // now we need to determine values + switch(d_gatewaytype) { + case 0: // no gateway + break; + case 1: // IPv4 GW + conv.xfrIP(d_ip4); + break; + case 2: // IPv6 GW + conv.xfrIP6(d_ip6); + break; + case 3: // DNS label + conv.xfrLabel(d_gateway, false); + }; + + switch(d_algorithm) { + case 0: + break; + default: + conv.xfrBlob(d_publickey); + } + return ret; +}; + +template +void IPSECKEYRecordContent::xfrPacket(Convertor& conv) +{ + conv.xfr8BitInt(d_preference); + conv.xfr8BitInt(d_gatewaytype); + conv.xfr8BitInt(d_algorithm); + + // now we need to determine values + switch(d_gatewaytype) { + case 0: // NO KEY + break; + case 1: // IPv4 GW + conv.xfrIP(d_ip4); + break; + case 2: // IPv6 GW + conv.xfrIP6(d_ip6); + break; + case 3: // DNS label + conv.xfrLabel(d_gateway, false); + break; + default: + throw MOADNSException("Parsing record content: invalid gateway type"); + }; + + switch(d_algorithm) { + case 0: + break; + case 1: + case 2: + conv.xfrBlob(d_publickey); + break; + default: + throw MOADNSException("Parsing record content: invalid algorithm type"); + } +} boilerplate_conv(DHCID, 49, conv.xfrBlob(d_content); diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index a8cfb5245..c60d3824e 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -98,6 +98,8 @@ public: private: uint8_t d_preference, d_gatewaytype, d_algorithm; string d_gateway, d_publickey; + uint32_t d_ip4; + string d_ip6; }; class DHCIDRecordContent : public DNSRecordContent