OpenSDN source code
bind_util.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <boost/algorithm/string/join.hpp>
7 #include <boost/assign/list_of.hpp>
8 #include <boost/regex.hpp>
9 #include <bind/bind_util.h>
10 
11 using namespace boost::assign;
13 
14 DnsTypeMap g_dns_type_map = map_list_of<std::string, uint16_t>
15  ("A", 1)
16  ("NS", 2)
17  ("CNAME", 5)
18  ("SOA", 6)
19  ("PTR", 0x0C)
20  ("MX", 0x0F)
21  ("TXT", 0x10)
22  ("AAAA", 0x1C)
23  ("SRV", 0x21)
24  ("ANY", 0xFF);
25 
26 DnsTypeNumMap g_dns_type_num_map = map_list_of<uint16_t, std::string>
27  (DNS_A_RECORD, "A")
28  (DNS_NS_RECORD, "NS")
29  (DNS_CNAME_RECORD, "CNAME")
30  (DNS_TYPE_SOA, "SOA")
31  (DNS_PTR_RECORD, "PTR")
32  (DNS_MX_RECORD, "MX")
33  (DNS_TXT_RECORD, "TXT")
34  (DNS_AAAA_RECORD, "AAAA")
35  (DNS_SRV_RECORD, "SRV")
36  (DNS_TYPE_ANY, "ANY");
37 
38 DnsTypeNumMap g_dns_class_num_map = map_list_of<uint16_t, std::string>
39  (DNS_CLASS_IN, "IN")
40  (DNS_CLASS_NONE, "None")
41  (DNS_CLASS_ANY, "Any");
42 
43 DnsResponseMap g_dns_response_map = map_list_of<uint16_t, std::string>
44  (0, "No error")
45  (1, "Format error")
46  (2, "Server failure")
47  (3, "Non-existent domain")
48  (4, "Not implemented")
49  (5, "Query refused")
50  (6, "Name exists when it should not")
51  (7, "RR Set Exists when it should not")
52  (8, "RR Set that should exist does not")
53  (9, "Not Authorized")
54  (10, "Name not contained in zone")
55  (16, "Bad OPT Version")
56  (17, "Key not recognized")
57  (18, "Signature out of time window")
58  (19, "Bad TKEY Mode")
59  (20, "Duplicate key name")
60  (21, "Algorithm not supported")
61  (22, "Bad truncation")
62  (4095, "Invalid response code");
63 
64 std::string DnsItem::ToString() const {
65  return BindUtil::DnsClass(eclass) + "/" +
66  BindUtil::DnsType(type) + "/" + name + "/" + data + ";";
67 }
68 
69 bool Subnet::operator< (const Subnet &rhs) const {
70  if (prefix.is_v4()) {
71  if (rhs.prefix.is_v4()) {
72  Ip4Address me = prefix.to_v4(),
73  they = rhs.prefix.to_v4();
74  if (me != they) {
75  return me < they;
76  }
77  return plen < rhs.plen;
78  } else {
79  // IPv4 goes before IPv6 and garbage
80  return true;
81  }
82  } else if (prefix.is_v6()) {
83  if (rhs.prefix.is_v6()) {
84  Ip6Address me = prefix.to_v6(),
85  they = rhs.prefix.to_v6();
86  if (me != they)
87  return me < they;
88  return plen < rhs.plen;
89  } else {
90  // IPv4 goes before IPv6, IPv6 goes before garbage
91  return !rhs.prefix.is_v4();
92  }
93  } else {
94  // Garbage always sorts towards the end
95  return false;
96  }
97 }
98 
99 bool Subnet::Contains(const IpAddress &addr) const {
100  if (prefix.is_v4() && addr.is_v4()) {
101  return IsIp4SubnetMember(addr.to_v4(), prefix.to_v4(), plen);
102  } else if (prefix.is_v6() && addr.is_v6()) {
103  return IsIp6SubnetMember(addr.to_v6(), prefix.to_v6(), plen);
104  } else {
105  return false;
106  }
107 }
108 
109 void Subnet::GetReverseZones(ZoneList &zones) const {
110  BindUtil::GetReverseZoneList(prefix, plen, zones);
111 }
112 
113 uint16_t BindUtil::DnsClass(const std::string &cl) {
114  if (cl == "IN")
115  return DNS_CLASS_IN;
116  return DNS_CLASS_ANY;
117 }
118 
119 std::string BindUtil::DnsClass(uint16_t cl) {
120  DnsTypeNumIter iter = g_dns_class_num_map.find(cl);
121  if (iter == g_dns_class_num_map.end())
122  return integerToString(cl);
123  return iter->second;
124 }
125 
126 uint16_t BindUtil::DnsType(const std::string &tp) {
127  DnsTypeIter iter = g_dns_type_map.find(tp);
128  if (iter == g_dns_type_map.end())
129  return -1;
130  return iter->second;
131 }
132 
133 std::string BindUtil::DnsType(uint16_t tp) {
134  DnsTypeNumIter iter = g_dns_type_num_map.find(tp);
135  if (iter == g_dns_type_num_map.end())
136  return integerToString(tp);
137  return iter->second;
138 }
139 
140 const std::string &BindUtil::DnsResponseCode(uint16_t code) {
141  DnsResponseIter iter = g_dns_response_map.find(code);
142  if (iter == g_dns_response_map.end())
143  return DnsResponseCode(4095);
144  return iter->second;
145 }
146 
147 uint8_t *BindUtil::AddName(uint8_t *ptr, const std::string &addr,
148  uint16_t plen, uint16_t offset, uint16_t &length) {
149  std::size_t size = addr.size();
150  std::size_t cur_pos = 0;
151  std::size_t prev_pos = 0;
152  while (cur_pos < size && cur_pos != std::string::npos) {
153  if (offset && !plen) {
154  ptr = WriteShort(ptr, offset);
155  length += 2;
156  return ptr;
157  }
158  std::size_t len;
159  cur_pos = addr.find('.', prev_pos);
160  if (cur_pos == std::string::npos)
161  len = size - prev_pos;
162  else
163  len = cur_pos - prev_pos;
164 
165  *ptr = len;
166  memcpy(ptr + 1, addr.substr(prev_pos, len).data(), len);
167  ptr += len + 1;
168  plen = (plen > len) ? plen - len - 1 : 0;
169 
170  prev_pos = cur_pos + 1;
171  length += len + 1;
172  }
173  ptr = WriteByte(ptr, 0);
174  length++;
175 
176  return ptr;
177 }
178 
179 uint8_t *BindUtil::AddQuestionSection(uint8_t *ptr, const std::string &name,
180  uint16_t type, uint16_t cl,
181  uint16_t &length) {
182  ptr = AddName(ptr, name, 0, 0, length);
183  ptr = WriteShort(ptr, type);
184  ptr = WriteShort(ptr, cl);
185  length += 4;
186 
187  return ptr;
188 }
189 
190 uint8_t *BindUtil::AddData(uint8_t *ptr, const DnsItem &item,
191  uint16_t &length) {
192  boost::system::error_code ec;
193 
194  if (item.type == DNS_A_RECORD) {
195  ptr = WriteShort(ptr, 4);
196  ptr = WriteWord(ptr, boost::asio::ip::address_v4::from_string(
197  item.data, ec).to_ulong());
198  length += 2 + 4;
199  } else if (item.type == DNS_AAAA_RECORD) {
200  ptr = WriteShort(ptr, 16);
201  boost::asio::ip::address_v6 addr =
202  boost::asio::ip::address_v6::from_string(item.data, ec);
203  if (ec.value()) {
204  memset(ptr, 0, 16);
205  } else {
206  memcpy(ptr, addr.to_bytes().data(), 16);
207  }
208  ptr += 16;
209  length += 2 + 16;
210  } else if(item.type == DNS_TYPE_SOA) {
211  uint16_t data_len = DataLength(item.soa.ns_plen, item.soa.ns_offset,
212  item.soa.primary_ns.size()) +
213  DataLength(item.soa.mailbox_plen,
214  item.soa.mailbox_offset,
215  item.soa.mailbox.size()) + 20;
216  ptr = WriteShort(ptr, data_len);
217  ptr = AddName(ptr, item.soa.primary_ns, item.soa.ns_plen,
218  item.soa.ns_offset, length);
219  ptr = AddName(ptr, item.soa.mailbox, item.soa.mailbox_plen,
220  item.soa.mailbox_offset, length);
221  ptr = WriteWord(ptr, item.soa.serial);
222  ptr = WriteWord(ptr, item.soa.refresh);
223  ptr = WriteWord(ptr, item.soa.retry);
224  ptr = WriteWord(ptr, item.soa.expiry);
225  ptr = WriteWord(ptr, item.soa.ttl);
226  length += 2 + 20;
227  } else if(item.type == DNS_PTR_RECORD ||
228  item.type == DNS_CNAME_RECORD ||
229  item.type == DNS_NS_RECORD) {
230  uint16_t data_len = DataLength(item.data_plen, item.data_offset,
231  item.data.size());
232  ptr = WriteShort(ptr, data_len);
233  ptr = AddName(ptr, item.data, item.data_plen, item.data_offset, length);
234  length += 2;
235  } else if (item.type == DNS_MX_RECORD) {
236  uint16_t data_len = 2 + DataLength(item.data_plen, item.data_offset,
237  item.data.size());
238  ptr = WriteShort(ptr, data_len);
239  // An MX record has 16 bit preference followed by host name
240  ptr = WriteShort(ptr, item.priority);
241  ptr = AddName(ptr, item.data, item.data_plen, item.data_offset, length);
242  length += 2 + 2;
243  } else if (item.type == DNS_SRV_RECORD) {
244  uint16_t data_len = 6 + DataLength(item.srv.hn_plen, item.srv.hn_offset,
245  item.srv.hostname.size());
246  ptr = WriteShort(ptr, data_len);
247  ptr = WriteShort(ptr, item.srv.priority);
248  ptr = WriteShort(ptr, item.srv.weight);
249  ptr = WriteShort(ptr, item.srv.port);
250  ptr = AddName(ptr, item.srv.hostname, item.srv.hn_plen,
251  item.srv.hn_offset, length);
252  length += 2 + 6;
253  } else {
254  // TXT and other record types are handled here.
255  // TODO: In case a record type has domain name and name is compressed
256  // in the message that is being read, it may lead to problem if the
257  // offset in the message we send doesnt match with the offset in the
258  // message that is received. Each such message has to be handled
259  // as a different case here.
260  uint16_t size = item.data.size();
261  ptr = WriteShort(ptr, size);
262  if (size) {
263  memcpy(ptr, item.data.c_str(), size);
264  ptr += size;
265  }
266  length += 2 + size;
267  }
268 
269  return ptr;
270 }
271 
272 uint8_t *BindUtil::AddAnswerSection(uint8_t *ptr, const DnsItem &item,
273  uint16_t &length) {
274  ptr = AddName(ptr, item.name, item.name_plen, item.name_offset, length);
275  ptr = WriteShort(ptr, item.type);
276  ptr = WriteShort(ptr, item.eclass);
277  ptr = WriteWord(ptr, item.ttl);
278  length += 2 + 2 + 4;
279  ptr = AddData(ptr, item, length);
280 
281  return ptr;
282 }
283 
284 uint8_t *BindUtil::AddAdditionalSection(uint8_t *ptr, const std::string name,
285  uint16_t type, uint16_t cl,
286  uint32_t ttl, const std::string &data,
287  uint16_t &length) {
288  ptr = AddQuestionSection(ptr, name, type, cl, length);
289  ptr = WriteWord(ptr, ttl);
290  ptr = WriteShort(ptr, data.size() + 1);
291 
292  // adding the domain name as it is, without replacing '.' with length
293  ptr = WriteByte(ptr, data.size());
294  memcpy(ptr, data.data(), data.size());
295  ptr += data.size();
296  length += 4 + 2 + 1 + data.size();
297 
298  return ptr;
299 }
300 
301 uint8_t *BindUtil::AddUpdate(uint8_t *ptr, const DnsItem &item,
302  uint16_t cl, uint32_t ttl, uint16_t &length) {
303  ptr = AddQuestionSection(ptr, item.name, item.type, cl, length);
304  ptr = WriteWord(ptr, ttl);
305  length += 4;
306  ptr = AddData(ptr, item, length);
307 
308  return ptr;
309 }
310 
311 bool BindUtil::ReadName(uint8_t *dns, uint16_t dnslen, int *remlen,
312  std::string &name, uint16_t &plen, uint16_t &offset) {
313  if (*remlen <= 0) {
314  return false;
315  }
316 
317  uint8_t *ptr = dns + (dnslen - *remlen);
318  std::size_t len = *ptr;
319  while (len) {
320  if ((len & 0xC0) == 0xC0) {
321  plen = name.size() ? name.size() - 1 : 0;
322  if (ReadShort(dns, dnslen, remlen, offset) == false)
323  return false;
324  int offset_remlen = dnslen - (offset & ~0xC000);
325  uint16_t dummy;
326  return ReadName(dns, dnslen, &offset_remlen, name, dummy, dummy);
327  } else {
328  *remlen -= (len + 1);
329  if (*remlen < 0) {
330  return false;
331  }
332  name.append((char *)ptr+1, len);
333  ptr += len + 1;
334  len = *ptr;
335  if (len)
336  name.append(".");
337  }
338  }
339 
340  *remlen -= 1;
341  return true;
342 }
343 
344 bool BindUtil::ReadData(uint8_t *dns, uint16_t dnslen, int *remlen,
345  DnsItem &item) {
346  uint16_t length;
347  if (ReadShort(dns, dnslen, remlen, length) == false)
348  return false;
349 
350  boost::system::error_code ec;
351  if (item.type == DNS_A_RECORD) {
352  uint32_t ip;
353  if (ReadWord(dns, dnslen, remlen, ip) == false)
354  return false;
355  boost::asio::ip::address_v4 addr(ip);
356  item.data = addr.to_string(ec);
357  return true;
358  } else if(item.type == DNS_AAAA_RECORD) {
359  if (*remlen < 16) {
360  return false;
361  }
362  uint8_t *ptr = dns + (dnslen - *remlen);
363  boost::asio::ip::address_v6::bytes_type ip;
364  memcpy(&ip[0], ptr, 16);
365  boost::asio::ip::address_v6 addr(ip);
366  item.data = addr.to_string(ec);
367  *remlen -= 16;
368  return true;
369  } else if(item.type == DNS_TYPE_SOA) {
370  if (ReadName(dns, dnslen, remlen, item.soa.primary_ns,
371  item.soa.ns_plen, item.soa.ns_offset) == false)
372  return false;
373  if (ReadName(dns, dnslen, remlen, item.soa.mailbox,
374  item.soa.mailbox_plen, item.soa.mailbox_offset) == false)
375  return false;
376  if (ReadWord(dns, dnslen, remlen, item.soa.serial) == false)
377  return false;
378  if (ReadWord(dns, dnslen, remlen, item.soa.refresh) == false)
379  return false;
380  if (ReadWord(dns, dnslen, remlen, item.soa.retry) == false)
381  return false;
382  if (ReadWord(dns, dnslen, remlen, item.soa.expiry) == false)
383  return false;
384  return ReadWord(dns, dnslen, remlen, item.soa.ttl);
385  } else if(item.type == DNS_PTR_RECORD ||
386  item.type == DNS_CNAME_RECORD ||
387  item.type == DNS_NS_RECORD) {
388  return ReadName(dns, dnslen, remlen, item.data, item.data_plen, item.data_offset);
389  } else if(item.type == DNS_MX_RECORD) {
390  if (ReadShort(dns, dnslen, remlen, item.priority) == false)
391  return false;
392  return ReadName(dns, dnslen, remlen, item.data, item.data_plen, item.data_offset);
393  } else if (item.type == DNS_SRV_RECORD) {
394  if (ReadShort(dns, dnslen, remlen, item.srv.priority) == false)
395  return false;
396  if (ReadShort(dns, dnslen, remlen, item.srv.weight) == false)
397  return false;
398  if (ReadShort(dns, dnslen, remlen, item.srv.port) == false)
399  return false;
400  return ReadName(dns, dnslen, remlen, item.srv.hostname,
401  item.srv.hn_plen, item.srv.hn_offset);
402  } else {
403  // TXT and other record types are handled here.
404  // TODO: In case a record type has domain name and name is compressed
405  // in the message that is being read, it may lead to problem if the
406  // offset in the message we send doesnt match with the offset in the
407  // message that is received. Each such message has to be handled
408  // as a different case here.
409  if (*remlen < length) {
410  return false;
411  }
412  uint8_t *ptr = dns + (dnslen - *remlen);
413  item.data.assign((const char *)ptr, length);
414  *remlen -= length;
415  return true;
416  }
417 
418  DNS_BIND_TRACE(DnsBindError,
419  "Unsupported data type in DNS response : " << item.type);
420  return false;
421 }
422 
423 bool BindUtil::ReadQuestionEntry(uint8_t *dns, uint16_t dnslen, int *remlen,
424  DnsItem &item) {
425  if (ReadName(dns, dnslen, remlen, item.name, item.name_plen,
426  item.name_offset) == false)
427  return false;
428 
429  if (ReadShort(dns, dnslen, remlen, item.type) == false)
430  return false;
431 
432  return ReadShort(dns, dnslen, remlen, item.eclass);
433 }
434 
435 bool BindUtil::ReadAnswerEntry(uint8_t *dns, uint16_t dnslen, int *remlen,
436  DnsItem &item) {
437  if (ReadQuestionEntry(dns, dnslen, remlen, item) == false)
438  return false;
439 
440  if (ReadWord(dns, dnslen, remlen, item.ttl) == false)
441  return false;
442 
443  return ReadData(dns, dnslen, remlen, item);
444 }
445 
446 bool BindUtil::ParseDnsQuery(uint8_t *dns, uint16_t dnslen, uint16_t *parsed_length,
447  DnsItems &items) {
448  uint16_t xid = 0;
449  *parsed_length = 0;
450  if (dnslen <= sizeof(dnshdr)) {
451  DNS_BIND_TRACE(DnsBindError,
452  "Invalid DNS Query with header missing - dropping it");
453  return false;
454  }
455 
456  dnshdr *hdr = (dnshdr *) dns;
457  xid = ntohs(hdr->xid);
458  uint16_t ques_rrcount = ntohs(hdr->ques_rrcount);
459 
460  int remlen = dnslen - sizeof(dnshdr);
461  for (unsigned int i = 0; i < ques_rrcount; ++i) {
462  DnsItem item;
463  item.offset = (dnslen - remlen) | 0xC000;
464  if (ReadQuestionEntry(dns, dnslen, &remlen, item) == false) {
465  DNS_BIND_TRACE(DnsBindError, "DNS Query Parse error in question "
466  "section - xid : " << xid << " - dropping it");
467  return false;
468  }
469  items.push_back(item);
470  }
471 
472  *parsed_length = dnslen - remlen;
473  return true;
474 
475 }
476 
477 bool BindUtil::ParseDnsResponse(uint8_t *dns, uint16_t dnslen, uint16_t &xid,
478  dns_flags &flags, DnsItems &ques, DnsItems &ans,
479  DnsItems &auth, DnsItems &add) {
480  if (dnslen < sizeof(dnshdr)) {
481  DNS_BIND_TRACE(DnsBindError,
482  "Invalid DNS Response with header missing - dropping it");
483  return false;
484  }
485 
486  dnshdr *hdr = (dnshdr *) dns;
487  xid = ntohs(hdr->xid);
488  flags = hdr->flags;
489 
490  uint16_t ques_rrcount = ntohs(hdr->ques_rrcount);
491  uint16_t ans_rrcount = ntohs(hdr->ans_rrcount);
492  uint16_t auth_rrcount = ntohs(hdr->auth_rrcount);
493  uint16_t add_rrcount = ntohs(hdr->add_rrcount);
494 
495  int remlen = dnslen - sizeof(dnshdr);
496  std::string errmsg;
497 
498  // question section
499  for (unsigned int i = 0; i < ques_rrcount; ++i) {
500  DnsItem item;
501  if (ReadQuestionEntry(dns, dnslen, &remlen, item) == false) {
502  errmsg = "Parse error in question section";
503  goto error;
504  }
505  ques.push_back(item);
506  }
507 
508  // answer section
509  for (unsigned int i = 0; i < ans_rrcount; ++i) {
510  DnsItem item;
511  if (ReadAnswerEntry(dns, dnslen, &remlen, item) == false) {
512  errmsg = "Parse error in answer section";
513  goto error;
514  }
515  ans.push_back(item);
516  }
517 
518  // authority section
519  for (unsigned int i = 0; i < auth_rrcount; ++i) {
520  DnsItem item;
521  if (ReadAnswerEntry(dns, dnslen, &remlen, item) == false) {
522  errmsg = "Parse error in authority section";
523  goto error;
524  }
525  auth.push_back(item);
526  }
527 
528  // additional section
529  for (unsigned int i = 0; i < add_rrcount; ++i) {
530  DnsItem item;
531  if (ReadAnswerEntry(dns, dnslen, &remlen, item) == false) {
532  errmsg = "Parse error in additional section";
533  goto error;
534  }
535  add.push_back(item);
536  }
537 
538  return true;
539 
540 error:
541  DNS_BIND_TRACE(DnsBindError,
542  "Invalid DNS response : " << errmsg <<
543  " xid : " << xid << " - dropping it");
544  return false;
545 }
546 
547 bool BindUtil::ParseDnsUpdate(uint8_t *dns, uint16_t dnslen,
548  DnsUpdateData &data) {
549  if (dnslen <= sizeof(dnshdr)) {
550  DNS_BIND_TRACE(DnsBindError, "Invalid DNS Update with header missing "
551  "- dropping it");
552  return false;
553  }
554 
555  dnshdr *hdr = (dnshdr *) dns;
556  uint16_t zone_count = ntohs(hdr->ques_rrcount);
557  uint16_t prereq_count = ntohs(hdr->ans_rrcount);
558  uint16_t update_count = ntohs(hdr->auth_rrcount);
559  uint16_t xid = ntohs(hdr->xid);
560 
561  if (zone_count != 1) {
562  DNS_BIND_TRACE(DnsBindError,
563  "Invalid zone count in Update request : " << zone_count);
564  return false;
565  }
566 
567  if (prereq_count != 0) {
568  // Not supporting pre-requisites now
569  DNS_BIND_TRACE(DnsBindError, "Update has pre-requisites, " <<
570  "which is not supported; dropping the request");
571  return false;
572  }
573 
574  int remlen = dnslen - sizeof(dnshdr);
575  std::string errmsg;
576 
577  // Read zone
578  uint16_t zone_type, zone_class, plen, offset;
579  if (ReadName(dns, dnslen, &remlen, data.zone, plen, offset) == false ||
580  ReadShort(dns, dnslen, &remlen, zone_type) == false ||
581  ReadShort(dns, dnslen, &remlen, zone_class) == false) {
582  errmsg = "Parse error in reading zone";
583  goto error;
584  }
585 
586  // Read Updates
587  for (unsigned int i = 0; i < update_count; ++i) {
588  DnsItem item;
589  if (ReadName(dns, dnslen, &remlen, item.name, plen, offset) == false ||
590  ReadShort(dns, dnslen, &remlen, item.type) == false ||
591  ReadShort(dns, dnslen, &remlen, item.eclass) == false ||
592  ReadWord(dns, dnslen, &remlen, item.ttl) == false ||
593  ReadData(dns, dnslen, &remlen, item) == false) {
594  errmsg = "Parse error";
595  goto error;
596  }
597  data.items.push_back(item);
598  }
599 
600  return true;
601 
602 error:
603  DNS_BIND_TRACE(DnsBindError,
604  "Invalid DNS Update : " << errmsg <<
605  " xid : " << xid << " - dropping it");
606  return false;
607 }
608 
609 void BindUtil::BuildDnsHeader(dnshdr *dns, uint16_t xid, DnsReq req,
610  DnsOpcode op, bool rd, bool ra, uint8_t ret,
611  uint16_t ques_count) {
612  dns->xid = htons(xid);
613  dns->flags.req = req;
614  dns->flags.op = op;
615  dns->flags.auth = 0;
616  dns->flags.trunc = 0;
617  dns->flags.rd = rd;
618  dns->flags.ra = ra;
619  dns->flags.res = 0;
620  dns->flags.ad = 0;
621  dns->flags.cd = 0;
622  dns->flags.ret = ret;
623  dns->ques_rrcount = htons(ques_count);
624  dns->ans_rrcount = 0;
625  dns->auth_rrcount = 0;
626  dns->add_rrcount = 0;
627 }
628 
629 int BindUtil::BuildDnsQuery(uint8_t *buf, uint16_t xid,
630  const std::string &domain,
631  const DnsItems &items) {
632  dnshdr *dns = (dnshdr *) buf;
633  BuildDnsHeader(dns, xid, DNS_QUERY_REQUEST, DNS_OPCODE_QUERY,
634  1, 0, 0, items.size());
635 
636  // TODO : can be optimised to reuse any names using offsets
637  uint16_t len = sizeof(dnshdr);
638  uint8_t *ques = (uint8_t *) (dns + 1);
639  for (DnsItems::const_iterator it = items.begin(); it != items.end(); ++it) {
640  ques = AddQuestionSection(ques, (*it).name, (*it).type,
641  (*it).eclass, len);
642  }
643 
644  if (!domain.empty()) {
645  dns->add_rrcount = htons(1);
646  std::string view = "view=" + domain;
647  ques = AddAdditionalSection(ques, "view", DNS_TXT_RECORD, DNS_CLASS_IN,
648  0, view, len);
649  }
650 
651  return len;
652 }
653 
654 int BindUtil::BuildDnsUpdate(uint8_t *buf, Operation op, uint16_t xid,
655  const std::string &domain,
656  const std::string &zone,
657  const DnsItems &items) {
658  dnshdr *dns = (dnshdr *) buf;
659  BuildDnsHeader(dns, xid, DNS_QUERY_REQUEST, DNS_OPCODE_UPDATE, 0, 0, 0, 1);
660  // dns->ques_rrcount = htons(1); // Number of zones
661  // dns->ans_rrcount = 0; // Number of Prerequisites
662  dns->auth_rrcount = htons(items.size()); // Number of Updates
663  dns->add_rrcount = htons(1); // Number of Additional RRs
664 
665  // Add zone
666  uint16_t len = sizeof(dnshdr);
667  uint8_t *ptr = (uint8_t *) (dns + 1);
668  ptr = AddQuestionSection(ptr, zone, DNS_TYPE_SOA, DNS_CLASS_IN, len);
669 
670  // Add Updates
671  switch (op) {
672  case ADD_UPDATE:
673  case CHANGE_UPDATE:
674  for (DnsItems::const_iterator it = items.begin();
675  it != items.end(); ++it) {
676  ptr = AddUpdate(ptr, *it, (*it).eclass, (*it).ttl, len);
677  }
678  break;
679 
680  case DELETE_UPDATE:
681  for (DnsItems::const_iterator it = items.begin();
682  it != items.end(); ++it) {
683  ptr = AddUpdate(ptr, *it, DNS_CLASS_NONE, 0, len);
684  }
685  break;
686 
687  default:
688  assert(0);
689  }
690 
691  // Add Additional RRs
692  std::string view = "view=" + domain;
693  ptr = AddAdditionalSection(ptr, "view", DNS_TXT_RECORD, DNS_CLASS_IN,
694  0, view, len);
695 
696  return len;
697 }
698 
699 bool BindUtil::IsReverseZoneV4(const std::string &name) {
700  // According to the docs, boost::regex is thread-safe. Compile once then.
701  static boost::regex in_addr_arpa("(?:[0-9]+\\.){1,4}in-addr\\.arpa\\.?",
702  boost::regex::perl | boost::regex::icase);
703  return boost::regex_match(name, in_addr_arpa);
704 }
705 
706 bool BindUtil::IsReverseZoneV6(const std::string &name) {
707  static boost::regex ip6_arpa("(?:[0-9a-f]\\.){1,32}ip6\\.arpa\\.?",
708  boost::regex::perl | boost::regex::icase);
709  return boost::regex_match(name, ip6_arpa);
710 }
711 
712 bool BindUtil::IsReverseZone(const std::string &name) {
714 }
715 
716 bool BindUtil::IsIP(const std::string &name, IpAddress &addr) {
717  boost::system::error_code ec;
718  addr = boost::asio::ip::address::from_string(name, ec);
719  return !ec.value();
720 }
721 
722 inline uint8_t BindUtil::GetNibble(const Ip6Address::bytes_type &addr, size_t bit)
723 {
724  assert((bit >> 3) < 16);
725  uint8_t buf = addr[bit >> 3];
726  return ((bit & 0x7) ? (buf & 0xF) : (buf >> 4));
727 }
728 
729 // Takes nibbles up to (but not necessarily including) plen and builds
730 // ip6.arpa zone name suffix for them. The caller is responsible for
731 // prefixing it with remaining plen bits when plen is not a multiply of 4.
732 std::string BindUtil::BuildIp6ArpaSuffix(const Ip6Address::bytes_type &addr,
733  uint32_t plen) {
734  std::vector<std::string> items;
735  uint8_t buf;
736 
737  for (size_t i = 0; i < (plen >> 2); i++) {
738  buf = GetNibble(addr, i << 2);
739  std::stringstream str;
740  str << std::hex << static_cast<unsigned int>(buf);
741  items.push_back(str.str());
742  }
743 
744  std::reverse(items.begin(), items.end());
745  items.push_back("ip6.arpa");
746  return boost::algorithm::join(items, ".");
747 }
748 
749 // Get list of reverse zones, given a subnet
750 void BindUtil::GetReverseZoneList(const Ip4Address &mask, uint32_t plen,
751  ZoneList &zones) {
752  uint32_t addr = mask.to_ulong();
753  std::string zone_name = "in-addr.arpa.";
754  while (plen >= 8) {
755  std::stringstream str;
756  str << (addr >> 24);
757  zone_name = str.str() + "." + zone_name;
758  addr = addr << 8;
759  plen -= 8;
760  }
761  if (plen == 0) {
762  // when prefix len is a multiple of 8, add only one reverse zone
763  zones.push_back(zone_name);
764  return;
765  }
766  for (int j = 0; j <= (0xFF >> plen); j++) {
767  // when prefix len is not a multiple of 8, add reverse zones for all
768  // addresses upto the nearest 8 byte boundary for the prefix len. For
769  // example, a /22 prefix results in 4 reverse zones.
770  uint32_t last = (addr >> 24) + j;
771  std::stringstream str;
772  str << last;
773  std::string rev_zone_name = str.str() + "." + zone_name;
774  zones.push_back(rev_zone_name);
775  }
776 }
777 
778 void BindUtil::GetReverseZoneList(const Ip6Address &mask, uint32_t plen,
779  ZoneList &zones) {
780  Ip6Address::bytes_type addr = mask.to_bytes();
781  std::string zone_name;
782  uint8_t buf;
783 
784  if (!plen || plen > 128)
785  return;
786 
787  zone_name = BindUtil::BuildIp6ArpaSuffix(addr, plen) + ".";
788 
789  uint32_t bits_rem = plen & 0x3;
790  // Prefix doesn't end on nibble boundary
791  if (bits_rem) {
792  buf = BindUtil::GetNibble(addr, plen - bits_rem);
793  for (int j = 0; j <= (0xF >> bits_rem); j++) {
794  std::stringstream str;
795  str << std::hex << static_cast<unsigned int>(buf + j)
796  << "." << zone_name;
797  zones.push_back(str.str());
798  }
799  } else {
800  zones.push_back(zone_name);
801  }
802 }
803 
804 void BindUtil::GetReverseZoneList(const IpAddress &mask, uint32_t plen,
805  ZoneList &zones) {
806  if (mask.is_v4()) {
807  GetReverseZoneList(mask.to_v4(), plen, zones);
808  } else if (mask.is_v6()) {
809  GetReverseZoneList(mask.to_v6(), plen, zones);
810  }
811 }
812 
813 void BindUtil::GetReverseZone(const Ip4Address &ip, uint32_t plen,
814  std::string &zone) {
815  uint32_t addr = ip.to_ulong();
816  zone = "in-addr.arpa";
817  while (plen >= 8) {
818  std::stringstream str;
819  str << (addr >> 24);
820  zone = str.str() + "." + zone;
821  addr = addr << 8;
822  plen -= 8;
823  }
824  if (plen == 0) {
825  return;
826  }
827  // when prefix len is not a multiple of 8, add extra byte from the addr
828  std::stringstream str;
829  str << (addr >> 24);
830  zone = str.str() + "." + zone;
831 }
832 
833 void BindUtil::GetReverseZone(const Ip6Address &ip, uint32_t plen,
834  std::string &zone) {
835  Ip6Address::bytes_type addr = ip.to_bytes();
836  uint8_t buf;
837 
838  if (!plen || plen > 128)
839  return;
840 
841  zone = BindUtil::BuildIp6ArpaSuffix(addr, plen);
842 
843  uint32_t bits_rem = plen & 0x3;
844  // Add the trailing nibble
845  if (bits_rem) {
846  buf = BindUtil::GetNibble(addr, plen - bits_rem);
847  std::stringstream str;
848  str << std::hex << static_cast<unsigned int>(buf) << "." << zone;
849  zone = str.str();
850  }
851 }
852 
853 void BindUtil::GetReverseZone(const IpAddress &addr, uint32_t plen,
854  std::string &zone) {
855  if (addr.is_v4()) {
856  GetReverseZone(addr.to_v4(), plen, zone);
857  } else if (addr.is_v6()) {
858  GetReverseZone(addr.to_v6(), plen, zone);
859  }
860 }
861 
862 bool BindUtil::GetAddrFromPtrName(std::string &ptr_name, Ip4Address &ip) {
863  uint32_t addr = 0;
864  uint8_t dot;
865  uint32_t num;
866  if (!BindUtil::IsReverseZoneV4(ptr_name))
867  return false;
868  std::stringstream str(ptr_name);
869  if (str.peek() == '.')
870  str >> dot;
871  int count = 0;
872  while (count < 4) {
873  if (str.peek() == 'i')
874  break;
875  str >> num;
876  str >> dot;
877  addr |= (num << (8 * count));
878  count++;
879  }
880  while (count++ < 4)
881  addr = addr << 8;
882  ip = Ip4Address(addr);
883  return true;
884 }
885 
886 bool BindUtil::GetAddrFromPtrName(std::string &ptr_name, Ip6Address &ip) {
887  Ip6Address::bytes_type addr;
888  BOOST_ASSERT(addr.size() == 16);
889 
890  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
891  typedef boost::array<uint8_t, 32> nibbles;
892 
893  if (!BindUtil::IsReverseZoneV6(ptr_name))
894  return false;
895 
896  tokenizer tok(ptr_name, boost::char_separator<char>("."));
897  nibbles nib;
898 
899  tokenizer::const_iterator tok_it = tok.begin();
900  nibbles::iterator nib_it = nib.begin();
901  for (; tok_it != tok.end() && nib_it != nib.end(); ++tok_it, ++nib_it) {
902  std::stringstream str(*tok_it);
903  unsigned int buf;
904 
905  // found ip6.arpa
906  if (!(str >> std::hex >> buf))
907  break;
908 
909  *nib_it = static_cast<uint8_t>(buf);
910  }
911 
912  std::fill(addr.begin(), addr.end(), 0);
913 
914  std::reverse_iterator<nibbles::const_iterator> r_nib_it(nib_it);
915  Ip6Address::bytes_type::iterator addr_it = addr.begin();
916 
917  // the most significant nibble is #0 thus always even
918  bool odd_nib = false;
919  // we should never get past addr.end() as nib.size() is 2 * 16
920  for (; r_nib_it != nib.rend(); ++r_nib_it) {
921  if (odd_nib) {
922  *addr_it |= (*r_nib_it & 0xF);
923  ++addr_it;
924  } else {
925  *addr_it |= (*r_nib_it << 4);
926  }
927  odd_nib = !odd_nib;
928  }
929 
930  ip = Ip6Address(addr);
931  return true;
932 }
933 
934 bool BindUtil::GetAddrFromPtrName(std::string &ptr_name,
935  IpAddress &ip) {
936  std::string name = boost::to_lower_copy(ptr_name);
937  std::size_t pos;
938 
939  pos = name.find(".in-addr.arpa");
940  if (pos != std::string::npos) {
941  Ip4Address out;
942  bool success = BindUtil::GetAddrFromPtrName(ptr_name, out);
943  if (success)
944  ip = out;
945  return success;
946  }
947 
948  pos = name.find(".ip6.arpa");
949  if (pos != std::string::npos) {
950  Ip6Address out;
951  bool success = BindUtil::GetAddrFromPtrName(ptr_name, out);
952  if (success)
953  ip = out;
954  return success;
955  }
956 
957  return false;
958 }
959 
960 std::string BindUtil::GetPtrNameFromAddr(const Ip4Address &ip) {
961  std::stringstream str;
962  for (int i = 0; i < 4; i++) {
963  str << ((ip.to_ulong() >> (i * 8)) & 0xFF) << ".";
964  }
965  str << "in-addr.arpa";
966  return str.str();
967 }
968 
969 std::string BindUtil::GetPtrNameFromAddr(const Ip6Address &ip6) {
970  std::stringstream str;
971  // we start with nibble #31 which is always odd
972  bool odd_nibble = true;
973 
974  Ip6Address::bytes_type addr = ip6.to_bytes();
975  Ip6Address::bytes_type::reverse_iterator it = addr.rbegin();
976  while (it != addr.rend()) {
977  unsigned int buf;
978  if (odd_nibble) {
979  buf = (*it & 0xF);
980  } else {
981  buf = (*it >> 4);
982  ++it;
983  }
984  str << std::hex << buf << '.';
985  odd_nibble = !odd_nibble;
986  }
987  str << "ip6.arpa";
988 
989  return str.str();
990 }
991 
992 std::string BindUtil::GetFQDN(const std::string &name, const std::string &domain,
993  const std::string &match) {
994  if (name.find(match, 0) == std::string::npos)
995  return name + "." + domain;
996  else
997  return name;
998 }
999 
1000 bool BindUtil::HasSpecialChars(const std::string &name) {
1001  for (unsigned int i = 0; i < name.size(); ++i) {
1002  uint8_t c = name[i];
1003  if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
1004  (c >= '0' && c <= '9') || (c == '-') || (c == '.')))
1005  return true;
1006  }
1007  return false;
1008 }
1009 
1010 void BindUtil::RemoveSpecialChars(std::string &name) {
1011  for (unsigned int i = 0; i < name.size(); ++i) {
1012  uint8_t c = name[i];
1013  if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
1014  (c >= '0' && c <= '9') || (c == '-') || (c == '.')))
1015  name[i] = '-';
1016  }
1017 }
1018 
1019 void DnsNameEncoder::AddName(std::string &name, uint16_t curr_msg_offset,
1020  uint16_t &name_plen, uint16_t &name_offset) {
1021  name_plen = 0;
1022  name_offset = 0;
1023  std::size_t pos = 0;
1024  while (pos < name.size()) {
1025  std::string str = name.substr(pos);
1026  if(IsPresent(str, name_offset)) {
1027  name_plen = pos ? pos - 1 : 0;
1028  break;
1029  }
1030 
1031  pos = name.find('.', pos + 1);
1032  if (pos == std::string::npos)
1033  break;
1034  pos++;
1035  }
1036  if (pos > 0)
1037  names_.push_back(Name(name, curr_msg_offset));
1038 }
1039 
1040 bool DnsNameEncoder::IsPresent(std::string &name, uint16_t &name_offset) {
1041  for (unsigned int i = 0; i < names_.size(); i++) {
1042  if (names_[i].name == name) {
1043  name_offset = names_[i].offset;
1044  return true;
1045  }
1046  }
1047  return false;
1048 }
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
bool IsIp6SubnetMember(const Ip6Address &ip, const Ip6Address &subnet, uint8_t plen)
Definition: address_util.cc:30
bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip, uint16_t plen)
Definition: address_util.cc:20
SandeshTraceBufferPtr DnsBindTraceBuf(SandeshTraceBufferCreate("DnsBind", 2000))
DnsTypeNumMap g_dns_class_num_map
Definition: bind_util.cc:38
DnsTypeMap g_dns_type_map
Definition: bind_util.cc:14
DnsTypeNumMap g_dns_type_num_map
Definition: bind_util.cc:26
DnsResponseMap g_dns_response_map
Definition: bind_util.cc:43
std::map< uint16_t, std::string >::const_iterator DnsResponseIter
Definition: bind_util.h:73
#define DNS_SRV_RECORD
Definition: bind_util.h:45
#define DNS_TXT_RECORD
Definition: bind_util.h:43
#define DNS_A_RECORD
Definition: bind_util.h:37
std::list< DnsItem > DnsItems
Definition: bind_util.h:202
#define DNS_BIND_TRACE(obj, arg)
Definition: bind_util.h:22
#define DNS_TYPE_ANY
Definition: bind_util.h:46
#define DNS_PTR_RECORD
Definition: bind_util.h:41
DnsReq
Definition: bind_util.h:56
@ DNS_QUERY_REQUEST
Definition: bind_util.h:57
#define DNS_NS_RECORD
Definition: bind_util.h:38
std::map< std::string, uint16_t > DnsTypeMap
Definition: bind_util.h:68
std::map< uint16_t, std::string > DnsResponseMap
Definition: bind_util.h:72
#define DNS_CLASS_ANY
Definition: bind_util.h:33
#define DNS_TYPE_SOA
Definition: bind_util.h:40
std::map< uint16_t, std::string > DnsTypeNumMap
Definition: bind_util.h:70
#define DNS_CNAME_RECORD
Definition: bind_util.h:39
#define DNS_MX_RECORD
Definition: bind_util.h:42
#define DNS_CLASS_IN
Definition: bind_util.h:32
#define DNS_AAAA_RECORD
Definition: bind_util.h:44
DnsOpcode
Definition: bind_util.h:61
@ DNS_OPCODE_UPDATE
Definition: bind_util.h:65
@ DNS_OPCODE_QUERY
Definition: bind_util.h:62
std::vector< std::string > ZoneList
Definition: bind_util.h:259
#define DNS_CLASS_NONE
Definition: bind_util.h:34
std::map< std::string, uint16_t >::const_iterator DnsTypeIter
Definition: bind_util.h:69
std::map< uint16_t, std::string >::const_iterator DnsTypeNumIter
Definition: bind_util.h:71
static bool HasSpecialChars(const std::string &name)
Definition: bind_util.cc:1000
static const std::string & DnsResponseCode(uint16_t code)
Definition: bind_util.cc:140
static bool ReadName(uint8_t *dns, uint16_t dnslen, int *remlen, std::string &name, uint16_t &plen, uint16_t &offset)
Definition: bind_util.cc:311
static uint8_t * AddAnswerSection(uint8_t *ptr, const DnsItem &item, uint16_t &length)
Definition: bind_util.cc:272
static int BuildDnsQuery(uint8_t *buf, uint16_t xid, const std::string &domain, const DnsItems &items)
Definition: bind_util.cc:629
static bool ParseDnsUpdate(uint8_t *dns, uint16_t dnslen, DnsUpdateData &data)
Definition: bind_util.cc:547
static std::string GetPtrNameFromAddr(const Ip4Address &ip)
Definition: bind_util.cc:960
static void GetReverseZone(const Ip4Address &addr, uint32_t plen, std::string &zone)
Definition: bind_util.cc:813
static void RemoveSpecialChars(std::string &name)
Definition: bind_util.cc:1010
static uint8_t GetNibble(const Ip6Address::bytes_type &addr, size_t bit)
Definition: bind_util.cc:722
static bool IsReverseZone(const std::string &name)
Definition: bind_util.cc:712
static uint16_t DnsType(const std::string &tp)
Definition: bind_util.cc:126
static uint8_t * AddQuestionSection(uint8_t *ptr, const std::string &name, uint16_t type, uint16_t cl, uint16_t &length)
Definition: bind_util.cc:179
static bool GetAddrFromPtrName(std::string &ptr_name, IpAddress &mask)
Definition: bind_util.cc:934
static void GetReverseZoneList(const IpAddress &mask, uint32_t plen, ZoneList &zones)
Definition: bind_util.cc:804
static void BuildDnsHeader(dnshdr *dns, uint16_t xid, DnsReq req, DnsOpcode op, bool rd, bool ra, uint8_t ret, uint16_t ques_count)
Definition: bind_util.cc:609
static uint16_t DnsClass(const std::string &cl)
Definition: bind_util.cc:113
static uint8_t * AddName(uint8_t *ptr, const std::string &addr, uint16_t plen, uint16_t offset, uint16_t &length)
Definition: bind_util.cc:147
static std::string BuildIp6ArpaSuffix(const Ip6Address::bytes_type &addr, uint32_t plen)
Definition: bind_util.cc:732
static bool IsReverseZoneV4(const std::string &name)
Definition: bind_util.cc:699
static bool IsIP(const std::string &name, IpAddress &addr)
Definition: bind_util.cc:716
static bool ReadQuestionEntry(uint8_t *dns, uint16_t dnslen, int *remlen, DnsItem &item)
Definition: bind_util.cc:423
static bool ReadAnswerEntry(uint8_t *dns, uint16_t dnslen, int *remlen, DnsItem &item)
Definition: bind_util.cc:435
static uint8_t * AddUpdate(uint8_t *ptr, const DnsItem &item, uint16_t cl, uint32_t ttl, uint16_t &length)
Definition: bind_util.cc:301
static bool ParseDnsResponse(uint8_t *dns, uint16_t dnslen, uint16_t &xid, dns_flags &flags, DnsItems &ques, DnsItems &ans, DnsItems &auth, DnsItems &add)
Definition: bind_util.cc:477
static bool IsReverseZoneV6(const std::string &name)
Definition: bind_util.cc:706
static int BuildDnsUpdate(uint8_t *buf, Operation op, uint16_t xid, const std::string &domain, const std::string &zone, const DnsItems &items)
Definition: bind_util.cc:654
static bool ReadData(uint8_t *dns, uint16_t dnslen, int *remlen, DnsItem &item)
Definition: bind_util.cc:344
static uint8_t * AddData(uint8_t *ptr, const DnsItem &item, uint16_t &length)
Definition: bind_util.cc:190
static std::string GetFQDN(const std::string &name, const std::string &domain, const std::string &match)
Definition: bind_util.cc:992
static uint8_t * AddAdditionalSection(uint8_t *ptr, const std::string name, uint16_t type, uint16_t cl, uint32_t ttl, const std::string &data, uint16_t &length)
Definition: bind_util.cc:284
static bool ParseDnsQuery(uint8_t *dns, uint16_t dnslen, uint16_t *parsed_length, DnsItems &items)
Definition: bind_util.cc:446
bool IsPresent(std::string &name, uint16_t &name_offset)
Definition: bind_util.cc:1040
void AddName(std::string &name, uint16_t curr_msg_offset, uint16_t &name_plen, uint16_t &name_offset)
Definition: bind_util.cc:1019
uint8_t type
Definition: load_balance.h:2
static bool regex_match(const std::string &input, const regex &regex)
Definition: regex.h:35
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:19
SandeshTraceBufferPtr SandeshTraceBufferCreate(const std::string &buf_name, size_t buf_size, bool trace_enable=true)
Definition: sandesh_trace.h:47
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:20
uint16_t priority
Definition: bind_util.h:153
uint16_t data_plen
Definition: bind_util.h:157
std::string name
Definition: bind_util.h:159
uint16_t eclass
Definition: bind_util.h:150
uint16_t name_offset
Definition: bind_util.h:156
DnsSOAData soa
Definition: bind_util.h:163
uint16_t type
Definition: bind_util.h:151
DnsSRVData srv
Definition: bind_util.h:164
std::string ToString() const
Definition: bind_util.cc:64
uint32_t ttl
Definition: bind_util.h:152
uint16_t data_offset
Definition: bind_util.h:158
uint16_t name_plen
Definition: bind_util.h:155
uint16_t offset
Definition: bind_util.h:154
std::string data
Definition: bind_util.h:162
uint16_t ns_plen
Definition: bind_util.h:116
uint16_t ns_offset
Definition: bind_util.h:117
uint32_t retry
Definition: bind_util.h:122
uint32_t refresh
Definition: bind_util.h:121
std::string primary_ns
Definition: bind_util.h:114
std::string mailbox
Definition: bind_util.h:115
uint16_t mailbox_offset
Definition: bind_util.h:119
uint32_t serial
Definition: bind_util.h:120
uint32_t ttl
Definition: bind_util.h:124
uint16_t mailbox_plen
Definition: bind_util.h:118
uint32_t expiry
Definition: bind_util.h:123
uint16_t port
Definition: bind_util.h:141
uint16_t hn_offset
Definition: bind_util.h:144
uint16_t hn_plen
Definition: bind_util.h:143
uint16_t weight
Definition: bind_util.h:140
std::string hostname
Definition: bind_util.h:142
uint16_t priority
Definition: bind_util.h:139
DnsItems items
Definition: bind_util.h:217
std::string zone
Definition: bind_util.h:216
bool operator<(const Subnet &rhs) const
Definition: bind_util.cc:69
IpAddress prefix
Definition: bind_util.h:262
bool Contains(const IpAddress &addr) const
Definition: bind_util.cc:99
uint32_t plen
Definition: bind_util.h:263
void GetReverseZones(ZoneList &zones) const
Definition: bind_util.cc:109
uint8_t ret
Definition: bind_util.h:82
uint8_t cd
Definition: bind_util.h:83
uint8_t ra
Definition: bind_util.h:86
uint8_t rd
Definition: bind_util.h:77
uint8_t auth
Definition: bind_util.h:79
uint8_t res
Definition: bind_util.h:85
uint8_t trunc
Definition: bind_util.h:78
uint8_t op
Definition: bind_util.h:80
uint8_t ad
Definition: bind_util.h:84
uint8_t req
Definition: bind_util.h:81
uint16_t add_rrcount
Definition: bind_util.h:109
dns_flags flags
Definition: bind_util.h:105
uint16_t auth_rrcount
Definition: bind_util.h:108
uint16_t ques_rrcount
Definition: bind_util.h:106
uint16_t xid
Definition: bind_util.h:104
uint16_t ans_rrcount
Definition: bind_util.h:107
boost::tokenizer< boost::char_separator< char > > tokenizer