You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

103 lines
3.3 KiB

  1. /*
  2. * This file is part of PowerDNS or dnsdist.
  3. * Copyright -- PowerDNS.COM B.V. and its contributors
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * In addition, for the avoidance of any doubt, permission is granted to
  10. * link this program with OpenSSL and to (re)distribute the binaries
  11. * produced as the result of such linking.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #pragma once
  23. #include <string>
  24. #include <map>
  25. #include <vector>
  26. #include <inttypes.h>
  27. #include <sys/un.h>
  28. #include <signal.h>
  29. #include <pthread.h>
  30. #include "iputils.hh"
  31. #include "dnsname.hh"
  32. #include "sholder.hh"
  33. #include <atomic>
  34. extern GlobalStateHolder<SuffixMatchNode> g_dontThrottleNames;
  35. extern GlobalStateHolder<NetmaskGroup> g_dontThrottleNetmasks;
  36. /** this class is used both to send and answer channel commands to the PowerDNS Recursor */
  37. class RecursorControlChannel
  38. {
  39. public:
  40. RecursorControlChannel();
  41. ~RecursorControlChannel();
  42. int listen(const std::string& filename);
  43. void connect(const std::string& path, const std::string& filename);
  44. uint64_t getStat(const std::string& name);
  45. void send(const std::string& msg, const std::string* remote=nullptr, unsigned int timeout=5);
  46. std::string recv(std::string* remote=0, unsigned int timeout=5);
  47. int d_fd;
  48. static volatile sig_atomic_t stop;
  49. private:
  50. struct sockaddr_un d_local;
  51. };
  52. class RecursorControlParser
  53. {
  54. public:
  55. RecursorControlParser()
  56. {
  57. }
  58. static void nop(void){}
  59. typedef void func_t(void);
  60. std::string getAnswer(const std::string& question, func_t** func);
  61. };
  62. enum class StatComponent { API, Carbon, RecControl, SNMP };
  63. struct StatsMapEntry {
  64. std::string d_prometheusName;
  65. std::string d_value;
  66. };
  67. typedef std::map<std::string, StatsMapEntry> StatsMap;
  68. StatsMap getAllStatsMap(StatComponent component);
  69. extern std::mutex g_carbon_config_lock;
  70. std::vector<std::pair<DNSName, uint16_t> >* pleaseGetQueryRing();
  71. std::vector<std::pair<DNSName, uint16_t> >* pleaseGetServfailQueryRing();
  72. std::vector<std::pair<DNSName, uint16_t> >* pleaseGetBogusQueryRing();
  73. std::vector<ComboAddress>* pleaseGetRemotes();
  74. std::vector<ComboAddress>* pleaseGetServfailRemotes();
  75. std::vector<ComboAddress>* pleaseGetBogusRemotes();
  76. std::vector<ComboAddress>* pleaseGetLargeAnswerRemotes();
  77. std::vector<ComboAddress>* pleaseGetTimeouts();
  78. DNSName getRegisteredName(const DNSName& dom);
  79. std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName);
  80. optional<uint64_t> getStatByName(const std::string& name);
  81. bool isStatBlacklisted(StatComponent component, const std::string& name);
  82. void blacklistStat(StatComponent component, const string& name);
  83. void blacklistStats(StatComponent component, const string& stats);
  84. void registerAllStats();
  85. void doExitGeneric(bool nicely);
  86. void doExit();
  87. void doExitNicely();