LCOV - code coverage report
Current view: top level - dns/mgr - dns_oper.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 35 38 92.1 %
Date: 2026-06-11 01:56:02 Functions: 32 35 91.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef __dns_oper_h__
       6             : #define __dns_oper_h__
       7             : 
       8             : #include <list>
       9             : #include <map>
      10             : #include <set>
      11             : 
      12             : #include <boost/function.hpp>
      13             : #include <boost/shared_ptr.hpp>
      14             : #include <boost/scoped_ptr.hpp>
      15             : 
      16             : #include "ifmap/ifmap_link.h"
      17             : #include "ifmap/ifmap_table.h"
      18             : #include "ifmap/ifmap_node_proxy.h"
      19             : #include "vnc_cfg_types.h"
      20             : #include "cmn/dns_types.h"
      21             : 
      22             : class IFMapNodeProxy;
      23             : struct IpamConfig;
      24             : struct VirtualDnsConfig;
      25             : struct VirtualDnsRecordConfig;
      26             : 
      27             : struct DnsConfig {
      28             :     std::string name_;
      29             :     mutable uint8_t flags_;
      30             : 
      31             :     enum DnsConfigEvent {
      32             :         CFG_ADD,
      33             :         CFG_CHANGE,
      34             :         CFG_DELETE,
      35             :     };
      36             : 
      37             :     enum DnsConfigFlags {
      38             :         DnsConfigValid = 1 << 0,        // DnsManager received the config
      39             :         DnsConfigNotified = 1 << 1,     // DnsManager installed the config
      40             :         DnsConfigDeleteMarked = 1 << 2, // Config is deleted
      41             :         DnsConfigErrorLogged = 1 << 3,  // Config error logged
      42             :     };
      43             : 
      44          59 :     void MarkValid() { flags_ |= DnsConfigValid; }
      45         655 :     bool IsValid() const { return (flags_ & DnsConfigValid); }
      46           0 :     void ClearValid() { flags_ &= ~DnsConfigValid; }
      47          42 :     void MarkNotified() const { flags_ |= DnsConfigNotified; }
      48         391 :     bool IsNotified() const { return (flags_ & DnsConfigNotified); }
      49          99 :     void ClearNotified() const { flags_ &= ~DnsConfigNotified; }
      50          63 :     void MarkDelete() { flags_ |= DnsConfigDeleteMarked; }
      51         649 :     bool IsDeleted() const { return (flags_ & DnsConfigDeleteMarked); }
      52           5 :     void ClearDelete() { flags_ &= ~DnsConfigDeleteMarked; }
      53           0 :     void MarkErrorLogged() { flags_ |= DnsConfigErrorLogged; }
      54           0 :     bool IsErrorLogged() const { return (flags_ & DnsConfigErrorLogged); }
      55             : 
      56          58 :     DnsConfig(const std::string &name) : name_(name), flags_(0) {}
      57         940 :     const std::string &GetName() const { return name_; }
      58             : 
      59             :     typedef boost::function<void(const DnsConfig *,
      60             :                                  DnsConfig::DnsConfigEvent)> Callback;
      61             :     typedef boost::function<void(const Subnet &, const VirtualDnsConfig *,
      62             :                                  DnsConfig::DnsConfigEvent)> ZoneCallback;
      63             :     static Callback VdnsCallback;
      64             :     static Callback VdnsRecordCallback;
      65             :     static ZoneCallback VdnsZoneCallback;
      66             :     static const std::string EventString[];
      67          72 :     static const std::string &ToEventString(DnsConfigEvent ev) {
      68          72 :         return EventString[ev];
      69             :     }
      70             : 
      71             : };
      72             : 
      73             : struct VnniConfig : public DnsConfig {
      74             :     typedef std::map<std::string, VnniConfig *> DataMap;
      75             :     typedef std::pair<std::string, VnniConfig *> DataPair;
      76             : 
      77             :     Subnets subnets_;
      78             :     IpamConfig *ipam_;
      79             :     static DataMap vnni_config_;
      80             : 
      81             :     VnniConfig(IFMapNode *node);
      82             :     ~VnniConfig();
      83             :     bool operator <(VnniConfig &rhs) const {
      84             :         return (GetName() < rhs.GetName());
      85             :     }
      86             : 
      87             :     void OnAdd(IFMapNode *node);
      88             :     void OnDelete();
      89             :     void OnChange(IFMapNode *node);
      90             : 
      91             :     void UpdateIpam(IFMapNode *node);
      92         238 :     Subnets &GetSubnets() { return subnets_; }
      93             :     void FindSubnets(IFMapNode *node, Subnets &subnets);
      94             :     bool NotifySubnets(Subnets &old_nets, Subnets &new_nets,
      95             :                        VirtualDnsConfig *vdns);
      96             : 
      97             :     static VnniConfig *Find(std::string name);
      98             : };
      99             : 
     100             : struct IpamConfig : public DnsConfig {
     101             :     typedef std::set<VnniConfig *> VnniList;
     102             :     typedef std::map<std::string, IpamConfig *> DataMap;
     103             :     typedef std::pair<std::string, IpamConfig *> DataPair;
     104             : 
     105             :     autogen::IpamType rec_;
     106             :     VirtualDnsConfig *virtual_dns_;
     107             :     VnniList vnni_list_;
     108             :     static DataMap ipam_config_;
     109             : 
     110             :     IpamConfig(IFMapNode *node);
     111             :     ~IpamConfig();
     112             : 
     113             :     void OnAdd(IFMapNode *node);
     114             :     void OnDelete();
     115             :     void OnChange(IFMapNode *node);
     116             : 
     117             :     void Add(VirtualDnsConfig *vdns);
     118             :     void Delete();
     119             :     void Notify(DnsConfig::DnsConfigEvent ev);
     120             : 
     121             :     bool GetObject(IFMapNode *node, autogen::IpamType &data);
     122          16 :     void AddVnni(VnniConfig *vnni) { vnni_list_.insert(vnni); }
     123           7 :     void DelVnni(VnniConfig *vnni) { vnni_list_.erase(vnni); }
     124          49 :     std::string &GetVirtualDnsName() {
     125          49 :         return rec_.ipam_dns_server.virtual_dns_server_name;
     126             :     }
     127         153 :     VirtualDnsConfig *GetVirtualDns() { return virtual_dns_; }
     128         160 :     const VnniList &GetVnniList() const { return vnni_list_; }
     129             : 
     130             :     void Trace(const std::string &ev);
     131             : 
     132             :     static IpamConfig *Find(std::string name);
     133             :     static void AssociateIpamVdns(VirtualDnsConfig *vdns);
     134             : };
     135             : 
     136             : struct VirtualDnsConfig : public DnsConfig {
     137             :     typedef std::set<IpamConfig *> IpamList;
     138             :     typedef std::set<VirtualDnsRecordConfig *> VDnsRec;
     139             :     typedef std::map<std::string, VirtualDnsConfig *> DataMap;
     140             :     typedef std::pair<std::string, VirtualDnsConfig *> DataPair;
     141             : 
     142             :     autogen::VirtualDnsType rec_;
     143             :     autogen::VirtualDnsType old_rec_;
     144             :     VDnsRec virtual_dns_records_;
     145             :     IpamList ipams_;
     146             :     static DataMap virt_dns_config_;
     147             : 
     148             :     VirtualDnsConfig(IFMapNode *node);
     149             :     VirtualDnsConfig(const std::string &name);
     150             :     ~VirtualDnsConfig();
     151             :     void OnAdd(IFMapNode *node);
     152             :     void OnDelete();
     153             :     void OnChange(IFMapNode *node);
     154             : 
     155             :     void AddRecord(VirtualDnsRecordConfig *record);
     156             :     void DelRecord(VirtualDnsRecordConfig *record);
     157          11 :     void AddIpam(IpamConfig *ipam) { ipams_.insert(ipam); }
     158          11 :     void DelIpam(IpamConfig *ipam) { ipams_.erase(ipam); }
     159         263 :     const IpamList &GetIpamList() const { return ipams_; }
     160          80 :     autogen::VirtualDnsType GetVDns() const { return rec_; }
     161             : 
     162             :     bool GetObject(IFMapNode *node, autogen::VirtualDnsType &data);
     163             :     bool GetSubnet(const IpAddress &addr, Subnet &subnet) const;
     164             :     void NotifyPendingDnsRecords();
     165             :     bool HasChanged();
     166             : 
     167             :     void VirtualDnsTrace(VirtualDnsTraceData &rec);
     168             :     void Trace(const std::string &ev);
     169             : 
     170             :     std::string GetViewName() const;
     171             :     std::string GetNextDns() const;
     172         663 :     std::string GetDomainName() const { return rec_.domain_name; }
     173          16 :     std::string GetOldDomainName() const { return old_rec_.domain_name; }
     174         217 :     std::string GetRecordOrder() const { return rec_.record_order; }
     175         669 :     bool IsExternalVisible() const { return rec_.external_visible; }
     176         233 :     bool IsReverseResolutionEnabled() const { return rec_.reverse_resolution; }
     177           8 :     bool HasReverseResolutionChanged() const {
     178           8 :         return rec_.reverse_resolution != old_rec_.reverse_resolution;
     179             :     }
     180             :     bool DynamicUpdatesEnabled() const;
     181         206 :     int GetTtl() const { return rec_.default_ttl_seconds; }
     182         105 :     int GetNegativeCacheTtl() const { return rec_.soa_record.negative_cache_ttl_seconds; }
     183             : 
     184             :     static VirtualDnsConfig *Find(std::string name);
     185          75 :     static DataMap &GetVirtualDnsMap() { return virt_dns_config_; }
     186             : };
     187             : 
     188             : struct VirtualDnsRecordConfig : public DnsConfig {
     189             :     typedef std::map<std::string, VirtualDnsRecordConfig *> DataMap;
     190             :     typedef std::pair<std::string, VirtualDnsRecordConfig *> DataPair;
     191             : 
     192             :     enum Source {
     193             :         Config,
     194             :         Agent
     195             :     };
     196             : 
     197             :     DnsItem rec_;
     198             :     VirtualDnsConfig *virt_dns_;
     199             :     std::string virtual_dns_name_;
     200             :     Source src_;
     201             :     static DataMap virt_dns_rec_config_;
     202             : 
     203             :     VirtualDnsRecordConfig(IFMapNode *node);
     204             :     VirtualDnsRecordConfig(const std::string &name,
     205             :                            const std::string &vdns_name, const DnsItem &item);
     206             :     ~VirtualDnsRecordConfig();
     207             :     void OnAdd(IFMapNode *node = NULL);
     208             :     void OnDelete();
     209             :     void OnChange(IFMapNode *node);
     210             :     void OnChange(const DnsItem &new_rec);
     211             :     bool UpdateVdns(IFMapNode *node);
     212             : 
     213             :     bool CanNotify();
     214             :     bool HasChanged(DnsItem &rhs);
     215             :     bool OnlyTtlChange(DnsItem &rhs);
     216             :     autogen::VirtualDnsType GetVDns() const;
     217          98 :     const DnsItem &GetRecord() const { return rec_; }
     218             :     std::string GetViewName() const;
     219         109 :     VirtualDnsConfig *GetVirtualDns() const { return virt_dns_; }
     220             :     bool GetObject(IFMapNode *node, DnsItem &item);
     221             : 
     222             :     void VirtualDnsRecordTrace(VirtualDnsRecordTraceData &rec);
     223             :     void Trace(const std::string &ev);
     224             : 
     225             :     static VirtualDnsRecordConfig *Find(std::string name);
     226             :     static void UpdateVirtualDns(VirtualDnsConfig *vdns);
     227             : };
     228             : 
     229             : struct GlobalQosConfig : public DnsConfig {
     230             :     GlobalQosConfig(IFMapNode *node);
     231             :     ~GlobalQosConfig();
     232             : 
     233             :     void OnAdd(IFMapNode *node);
     234             :     void OnDelete();
     235             :     void OnChange(IFMapNode *node);
     236             :     void SetDscp();
     237             :     static GlobalQosConfig *Find(const std::string &name);
     238             : 
     239             :     uint8_t control_dscp_;
     240             :     uint8_t analytics_dscp_;
     241             :     static GlobalQosConfig *singleton_;
     242             : };
     243             : #endif // __dns_oper_h__

Generated by: LCOV version 1.14