LCOV - code coverage report
Current view: top level - dns/bind - named_config.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 13 14 92.9 %
Date: 2026-11-09 02:10:49 Functions: 5 7 71.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef dns_named_config_h_
       7             : #define dns_named_config_h_
       8             : 
       9             : #include <iostream>
      10             : #include <fstream>
      11             : #include <set>
      12             : #include <string>
      13             : #include <base/timer.h>
      14             : 
      15             : class BindStatus {
      16             : public:
      17             :     static const uint32_t kBindStatusTimeout = 2 * 1000;
      18             :     static const uint32_t kInitTimeout = 200;
      19             :     enum Event {
      20             :         Up,
      21             :         Down
      22             :     };
      23             :     typedef boost::function<void(Event)> BindEventHandler;
      24             : 
      25             :     BindStatus(BindEventHandler handler);
      26             :     virtual ~BindStatus();
      27             :     bool SetTrigger();
      28         124 :     bool IsUp() { return (named_pid_ != (uint32_t) -1); }
      29             : 
      30             : private:
      31             :     friend class DnsBindTest;
      32             :     friend class DnsManagerTest;
      33             : 
      34             :     bool IsBindPid(uint32_t pid);
      35             :     bool CheckBindStatus();
      36             : 
      37             :     uint32_t named_pid_;
      38             :     BindEventHandler handler_;
      39             :     Timer *status_timer_;
      40             :     bool change_timeout_;
      41             : 
      42             :     DISALLOW_COPY_AND_ASSIGN(BindStatus);
      43             : };
      44             : 
      45             : class NamedConfig {
      46             : public:
      47             :     // map of zone name to list of views to which they belong
      48             :     typedef std::map<std::string, std::string> ZoneViewMap;
      49             :     typedef std::pair<std::string, std::string> ZoneViewPair;
      50             : 
      51             :     static const std::string NamedZoneFileSuffix;
      52             :     static const std::string NamedZoneNSPrefix;
      53             :     static const std::string NamedZoneMXPrefix;
      54             :     static const char pid_file_name[];
      55             :     static const char sessionkey_file_name[];
      56             :     static const int NameWidth = 30;
      57             :     static const int NumberWidth = 10;
      58             :     static const int TypeWidth = 4;
      59             : 
      60             :     struct Defaults {
      61             :         static const int GlobalTTL = 86400;
      62             :         static const int Serial = 54;
      63             :         static const int Refresh = 10800;
      64             :         static const int Retry = 900;
      65             :         static const int Expire = 604800;
      66             :         static const int Minimum = 86400;
      67             :     };
      68             : 
      69          15 :     NamedConfig(const std::string& named_config_dir,
      70             :                 const std::string& named_config_file,
      71             :                 const std::string& named_log_file,
      72             :                 const std::string& rndc_config_file,
      73             :                 const std::string& rndc_secret,
      74          15 :                 const std::string& named_max_cache_size) :
      75          30 :         file_(), named_log_file_(named_log_file), rndc_secret_(rndc_secret),
      76          15 :         named_max_cache_size_(named_max_cache_size),
      77          45 :         reset_flag_(false), all_zone_files_(false) {
      78          15 :             named_config_dir_ = named_config_dir + "/";
      79          15 :             named_config_file_ = named_config_dir_ + named_config_file;
      80          15 :             rndc_config_file_ = named_config_dir_ + rndc_config_file;
      81          15 :     }
      82             : 
      83          15 :     virtual ~NamedConfig() { singleton_ = NULL; }
      84          76 :     static NamedConfig *GetNamedConfigObject() { return singleton_; }
      85             :     static void Init(const std::string& named_config_dir,
      86             :                      const std::string& named_config_file,
      87             :                      const std::string& named_log_file,
      88             :                      const std::string& rndc_config_file,
      89             :                      const std::string& rndc_secret,
      90             :                      const std::string& named_max_cache_size);
      91             :     static void Shutdown();
      92             :     void Reset();
      93             :     virtual void AddView(const VirtualDnsConfig *vdns);
      94             :     virtual void ChangeView(const VirtualDnsConfig *vdns);
      95             :     virtual void DelView(const VirtualDnsConfig *vdns);
      96             :     virtual void AddAllViews();
      97             :     virtual void AddZone(const Subnet &subnet, const VirtualDnsConfig *vdns);
      98             :     virtual void DelZone(const Subnet &subnet, const VirtualDnsConfig *vdns);
      99             : 
     100             :     virtual void UpdateNamedConf(const VirtualDnsConfig *updated_vdns = NULL);
     101             :     void RemoveZoneFiles(const VirtualDnsConfig *vdns, ZoneList &zones);
     102             :     virtual std::string GetZoneFileName(const std::string &vdns,
     103             :                                         const std::string &name);
     104             :     virtual std::string GetZoneFilePath(const std::string &vdns,
     105             :                                         const std::string &name);
     106           0 :     virtual std::string GetResolveFile() { return "/etc/resolv.conf"; }
     107             :     std::string GetPidFilePath();
     108             :     std::string GetSessionKeyFilePath();
     109             :     const std::string &named_config_dir() const { return named_config_dir_; }
     110          15 :     const std::string &named_config_file() const { return named_config_file_; }
     111             :     const std::string &named_sessionkey_file() const {
     112             :         return named_sessionkey_file_;
     113             :     }
     114             : 
     115             : protected:
     116             :     void CreateRndcConf();
     117             :     void CreateNamedConf(const VirtualDnsConfig *updated_vdns);
     118             :     void WriteOptionsConfig();
     119             :     void WriteRndcConfig();
     120             :     void WriteLoggingConfig();
     121             :     void WriteViewConfig(const VirtualDnsConfig *updated_vdns);
     122             :     void WriteDefaultView(ZoneViewMap &zone_view_map);
     123             :     void WriteZone(const std::string &vdns, const std::string &name,
     124             :                    bool is_master, bool is_rr, const std::string &next_dns);
     125             :     void AddZoneFiles(ZoneList &zones, const VirtualDnsConfig *vdns);
     126             :     void RemoveZoneFile(const VirtualDnsConfig *vdns, std::string &zone);
     127             :     void RemoveReverseZoneFiles(const VirtualDnsConfig *vdns);
     128             :     std::string GetZoneNSName(const std::string domain_name);
     129             :     std::string GetZoneMXName(const std::string domain_name);
     130             :     void CreateZoneFile(std::string &zone_name,
     131             :                         const VirtualDnsConfig *vdns, bool ns);
     132             :     void MakeZoneList(const VirtualDnsConfig *vdns_config, ZoneList &zones);
     133             :     void MakeReverseZoneList(const VirtualDnsConfig *vdns_config,
     134             :                              ZoneList &zones);
     135             :     void GetDefaultForwarders();
     136             : 
     137             :     std::ofstream file_;
     138             :     std::string named_config_file_;
     139             :     std::string named_config_dir_;
     140             :     std::string named_sessionkey_file_;
     141             :     std::string named_log_file_;
     142             :     std::string rndc_config_file_;
     143             :     std::string rndc_secret_;
     144             :     std::string named_max_cache_size_;
     145             :     std::string default_forwarders_;
     146             :     bool reset_flag_;
     147             :     bool all_zone_files_;
     148             :     static NamedConfig *singleton_;
     149             : };
     150             : 
     151             : #endif // dns_named_config_h_

Generated by: LCOV version 1.14