Skip to content

Commit

Permalink
Removed DNSResourceRecord. Records in DNS are now managed completely …
Browse files Browse the repository at this point in the history
…by DNS::Resource.
  • Loading branch information
mfontanini committed Jan 22, 2014
1 parent 6d7e065 commit c5404a6
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 702 deletions.
2 changes: 0 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ libtins_la_SOURCES=src/arp.cpp \
src/dhcp.cpp \
src/dhcpv6.cpp \
src/dns.cpp \
src/dns_record.cpp \
src/dot3.cpp \
src/dot1q.cpp \
src/eapol.cpp \
Expand Down Expand Up @@ -71,7 +70,6 @@ libtins_HEADERS = include/internals.h \
include/small_uint.h \
include/ip.h \
include/ipsec.h \
include/dns_record.h \
include/eapol.h \
include/tcp_stream.h \
include/pppoe.h \
Expand Down
25 changes: 9 additions & 16 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ libtins_la_LIBADD =
am__dirstamp = $(am__leading_dot)dirstamp
am_libtins_la_OBJECTS = src/arp.lo src/bootp.lo \
src/handshake_capturer.lo src/stp.lo src/pppoe.lo \
src/crypto.lo src/dhcp.lo src/dhcpv6.lo src/dns.lo \
src/dns_record.lo src/dot3.lo src/dot1q.lo src/eapol.lo \
src/ethernetII.lo src/icmp.lo src/icmpv6.lo src/internals.lo \
src/ip_reassembler.lo src/ip.lo src/ip_address.lo src/ipv6.lo \
src/ipv6_address.lo src/ipsec.lo src/llc.lo src/loopback.lo \
src/network_interface.lo src/packet_sender.lo \
src/packet_writer.lo src/ppi.lo src/pdu.lo src/radiotap.lo \
src/address_range.lo src/rawpdu.lo src/rsn_information.lo \
src/sll.lo src/snap.lo src/sniffer.lo src/tcp.lo \
src/tcp_stream.lo src/udp.lo src/utils.lo \
src/crypto.lo src/dhcp.lo src/dhcpv6.lo src/dns.lo src/dot3.lo \
src/dot1q.lo src/eapol.lo src/ethernetII.lo src/icmp.lo \
src/icmpv6.lo src/internals.lo src/ip_reassembler.lo src/ip.lo \
src/ip_address.lo src/ipv6.lo src/ipv6_address.lo src/ipsec.lo \
src/llc.lo src/loopback.lo src/network_interface.lo \
src/packet_sender.lo src/packet_writer.lo src/ppi.lo \
src/pdu.lo src/radiotap.lo src/address_range.lo src/rawpdu.lo \
src/rsn_information.lo src/sll.lo src/snap.lo src/sniffer.lo \
src/tcp.lo src/tcp_stream.lo src/udp.lo src/utils.lo \
src/dot11/dot11_base.lo src/dot11/dot11_data.lo \
src/dot11/dot11_mgmt.lo src/dot11/dot11_beacon.lo \
src/dot11/dot11_assoc.lo src/dot11/dot11_auth.lo \
Expand Down Expand Up @@ -309,7 +308,6 @@ libtins_la_SOURCES = src/arp.cpp \
src/dhcp.cpp \
src/dhcpv6.cpp \
src/dns.cpp \
src/dns_record.cpp \
src/dot3.cpp \
src/dot1q.cpp \
src/eapol.cpp \
Expand Down Expand Up @@ -359,7 +357,6 @@ libtins_HEADERS = include/internals.h \
include/small_uint.h \
include/ip.h \
include/ipsec.h \
include/dns_record.h \
include/eapol.h \
include/tcp_stream.h \
include/pppoe.h \
Expand Down Expand Up @@ -522,7 +519,6 @@ src/crypto.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dhcp.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dhcpv6.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dns.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dns_record.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dot3.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dot1q.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/eapol.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
Expand Down Expand Up @@ -601,8 +597,6 @@ mostlyclean-compile:
-rm -f src/dhcpv6.lo
-rm -f src/dns.$(OBJEXT)
-rm -f src/dns.lo
-rm -f src/dns_record.$(OBJEXT)
-rm -f src/dns_record.lo
-rm -f src/dot11/dot11_assoc.$(OBJEXT)
-rm -f src/dot11/dot11_assoc.lo
-rm -f src/dot11/dot11_auth.$(OBJEXT)
Expand Down Expand Up @@ -696,7 +690,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dhcp.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dhcpv6.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dns.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dns_record.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dot1q.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dot3.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/eapol.Plo@am__quote@
Expand Down
157 changes: 72 additions & 85 deletions include/dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "macros.h"
#include "pdu.h"
#include "endianness.h"
#include "dns_record.h"

namespace Tins {
class IPv4Address;
Expand Down Expand Up @@ -200,24 +199,34 @@ namespace Tins {
*/
class Resource {
public:
Resource(const std::string &nm, const std::string &ad,
uint16_t t, uint16_t c, uint32_t tt)
: dname_(nm), addr_(ad), type_(t), qclass_(c), ttl_(tt) {}
/**
* Constructs a Resource object.
*
* \param dname The domain name for which this records
* provides an answer.
* \param data The resource's payload.
* \param type The type of this record.
* \param rclass The class of this record.
* \param ttl The time-to-live of this record.
*/
Resource(const std::string &dname, const std::string &data,
uint16_t type, uint16_t rclass, uint32_t ttl)
: dname_(dname), data_(data), type_(type), qclass_(rclass), ttl_(ttl) {}

Resource() : type_(), qclass_(), ttl_() {}

/**
* \brief Getter for the dname field.
* \brief Getter for the domain name field.
*
* This returns the domain name for which this record
* provides an answer.
*/
const std::string &dname() const { return dname_; }

/**
* Getter for the type field.
* Getter for the data field.
*/
const std::string &data() const { return addr_; }
const std::string &data() const { return data_; }

/**
* Getter for the query type field.
Expand All @@ -233,8 +242,52 @@ namespace Tins {
* Getter for the type field.
*/
uint32_t ttl() const { return ttl_; }

/**
* Setter for the domain name field.
*/
void dname(const std::string &data) {
dname_ = data;
}

/**
* \brief Setter for the data field.
*
* The data will be encoded properly by the DNS class before
* being added to this packet. That means that if the type is
* A or AAAA, it will be properly encoded as an IPv4 or
* IPv6 address.
*
* The same happens for records that contain domain names,
* such as NS or CNAME. This data will be encoded using
* DNS domain name encoding.
*/
void data(const std::string &data) {
data_ = data;
}

/**
* Setter for the type field.
*/
void type(uint16_t data) {
type_ = data;
}

/**
* Setter for the class field.
*/
void query_class(uint16_t data) {
qclass_ = data;
}

/**
* Setter for the time-to-live field.
*/
void ttl(uint16_t data) {
ttl_ = data;
}
private:
std::string dname_, addr_;
std::string dname_, data_;
uint16_t type_, qclass_;
uint32_t ttl_;
};
Expand Down Expand Up @@ -482,79 +535,25 @@ namespace Tins {
void add_query(const Query &query);

/**
* \brief Add a query response.
*
* \param name The resolved name.
* \param type The type of this answer.
* \param qclass The class of this answer.
* \param ttl The time-to-live of this answer.
* \param ip The ip address of the resolved name.
*/
void add_answer(const std::string &name,
const DNSResourceRecord::info &info, address_type ip);

/**
* \brief Add a query response.
*
* \param name The resolved name.
* \param type The type of this answer.
* \param qclass The class of this answer.
* \param ttl The time-to-live of this answer.
* \param ip The ip address of the resolved name.
*/
void add_answer(const std::string &name,
const DNSResourceRecord::info &info, address_v6_type ip);

/**
* \brief Add a query response.
* \brief Add an answer resource record.
*
* \param name The resolved name.
* \param type The type of this answer.
* \param qclass The class of this answer.
* \param ttl The time-to-live of this answer.
* \param dname The domain of the resolved name.
* \param resource The resource to be added.
*/
void add_answer(const std::string &name,
const DNSResourceRecord::info &info, const std::string &dname);

/**
* \brief Add a query response.
*
* \param name The resolved name.
* \param type The type of this answer.
* \param qclass The class of this answer.
* \param ttl The time-to-live of this answer.
* \param data The data of this option.
* \param sz The size of the data.
*/
void add_answer(const std::string &name,
const DNSResourceRecord::info &info, const uint8_t *data, uint32_t sz);

void add_answer(const Resource &resource);

/**
* \brief Add an authority record.
* \brief Add an authority resource record.
*
* \param name The resolved name.
* \param type The type of this record.
* \param qclass The class of this record.
* \param ttl The time-to-live of this record.
* \param data The data of this option.
* \param sz The size of the data.
* \param resource The resource to be added.
*/
void add_authority(const std::string &name,
const DNSResourceRecord::info &info, const uint8_t *data, uint32_t sz);
void add_authority(const Resource &resource);

/**
* \brief Add an additional record.
* \brief Add an additional resource record.
*
* \param name The resolved name.
* \param type The type of this record.
* \param qclass The class of this record.
* \param ttl The time-to-live of this record.
* \param ip The ip address of the resolved name.
* \param resource The resource to be added.
*/
void add_additional(const std::string &name,
const DNSResourceRecord::info &info, const uint8_t *data, uint32_t sz);

void add_additional(const Resource &resource);

/**
* \brief Getter for this PDU's DNS queries.
Expand Down Expand Up @@ -616,17 +615,6 @@ namespace Tins {
DNS *clone() const {
return new DNS(*this);
}

/**
* Helper function to create a resource record information.
*
* \param type The type of the query.
* \param qclass The class of the query.
* \param ttl The time-to-live of the query.
*/
static DNSResourceRecord::info make_info(QueryType type, QueryClass qclass, uint32_t ttl) {
return DNSResourceRecord::info((uint16_t)type, (uint16_t)qclass, ttl);
}
private:
TINS_BEGIN_PACK
struct dnshdr {
Expand Down Expand Up @@ -672,8 +660,7 @@ namespace Tins {
static void inline_convert_v4(uint32_t value, char *output);
static bool contains_dname(uint16_t type);
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
void add_record(const std::string &name, const DNSResourceRecord::info &info,
const uint8_t *data, uint32_t sz, const sections_type &sections);
void add_record(const Resource &resource, const sections_type &sections);

dnshdr dns;
byte_array records_data;
Expand Down
Loading

0 comments on commit c5404a6

Please sign in to comment.