LCOV - code coverage report
Current view: top level - vnsw/agent/services - dns_handler.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 0 9 0.0 %
Date: 2026-06-04 02:06:09 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef vnsw_agent_dns_handler_hpp
       6             : #define vnsw_agent_dns_handler_hpp
       7             : 
       8             : #include <mutex>
       9             : 
      10             : #include "pkt/proto_handler.h"
      11             : #include "vnc_cfg_types.h"
      12             : #include "bind/bind_util.h"
      13             : #include "bind/bind_resolver.h"
      14             : 
      15             : #define DEFAULT_DNS_TTL 120
      16             : 
      17             : typedef boost::asio::ip::udp boost_udp;
      18             : 
      19             : class AgentDnsXmppChannel;
      20             : class VmInterface;
      21             : class Timer;
      22             : 
      23             : class DnsHandler : public ProtoHandler {
      24             : public:
      25             :     typedef boost::function<void(const boost::system::error_code&,
      26             :                                 boost_udp::resolver::iterator)> ResolveHandler;
      27             :     typedef std::vector<boost_udp::resolver *> ResolvList;
      28             :     static const uint32_t max_items_per_xmpp_msg = 20;
      29             : 
      30             :     struct QueryKey {
      31           0 :         QueryKey(const Interface *i, uint16_t x) : itf(i), xid(x) {}
      32           0 :         bool operator<(const QueryKey &rhs) const {
      33           0 :             if (itf != rhs.itf)
      34           0 :                 return itf < rhs.itf;
      35           0 :             return xid < rhs.xid;
      36             :         }
      37             : 
      38             :         const Interface *itf;
      39             :         uint16_t xid;
      40             :     };
      41             : 
      42             :     enum Action {
      43             :         NONE,
      44             :         DNS_QUERY,
      45             :         DNS_UPDATE
      46             :     };
      47             : 
      48             :     DnsHandler(Agent *agent, boost::shared_ptr<PktInfo> info,
      49             :                boost::asio::io_context &io);
      50             :     virtual ~DnsHandler();
      51             :     bool Run();
      52             :     bool TimerExpiry(uint16_t xid);
      53             :     void DefaultDnsResolveHandler(const boost::system::error_code &error,
      54             :                                   boost_udp::resolver::iterator it,
      55             :                                   DnsItems::iterator item);
      56             : 
      57             : private:
      58             :     friend class DnsTest;
      59             : 
      60             :     bool HandleRequest();
      61             :     bool HandleDefaultDnsRequest(const VmInterface *vmitf);
      62             :     void DefaultDnsSendResponse();
      63             :     bool HandleVirtualDnsRequest(const VmInterface *vmitf);
      64             :     bool ResolveLinkLocalRequest(DnsItems::iterator &item,
      65             :                                  DnsItems *linklocal_items) const;
      66             :     bool ResolveAllLinkLocalRequests();
      67             :     void BuildDnsResolvers();
      68             :     void BuildDefaultDnsResolvers();
      69             :     bool HandleMessage();
      70             :     bool HandleDefaultDnsResponse();
      71             :     bool HandleBindResponse();
      72             :     bool HandleUpdateResponse();
      73             :     bool HandleRetryExpiry();
      74             :     bool HandleUpdate();
      75             :     bool HandleModifyVdns();
      76             :     bool UpdateAll();
      77             :     void SendXmppUpdate(AgentDnsXmppChannel *channel, DnsUpdateData *xmpp_data);
      78             :     void ParseQuery();
      79             :     void Resolve(dns_flags flags, const DnsItems &ques, DnsItems &ans,
      80             :                  DnsItems &auth, DnsItems &add);
      81             :     void SendDnsResponse();
      82             :     void UpdateQueryNames();
      83             :     void UpdateOffsets(DnsItem &item, bool name_update_required);
      84             :     void UpdateGWAddress(DnsItem &item);
      85             :     void Update(InterTaskMsg *msg);
      86             :     void DelUpdate(InterTaskMsg *msg);
      87             :     void UpdateStats();
      88             :     void GetDomainName(const VmInterface *vm_itf, std::string *domain_name) const;
      89             :     bool GetDomainNameFromDhcp(std::vector<autogen::DhcpOptionType> &options,
      90             :                                std::string *domain_name) const;
      91             :     void GetBaseName(const std::string &name, std::string *base) const;
      92             :     std::string DnsItemsToString(DnsItems &items) const;
      93             :     void HandleInvalidBindResponse(DnsHandler *handler, dns_flags flags,
      94             :                                    const DnsItems &ques, DnsItems &ans,
      95             :                                    DnsItems &auth, DnsItems &add, uint16_t xid);
      96             :     bool NeedRetryForNextServer(uint16_t code);
      97             :     bool SendToDefaultServer();
      98           0 :     bool DefaultMethodInUse() { return default_method_; }
      99           0 :     uint8_t curr_index() { return curr_index_; }
     100           0 :     uint8_t last_index() { return def_dns_resolvers_.size() - 1; }
     101           0 :     void IncrCurrIndex() { curr_index_++; }
     102             : 
     103             :     dnshdr  *dns_;
     104             :     uint8_t *resp_ptr_;
     105             :     uint16_t dns_resp_size_;
     106             :     uint16_t xid_;
     107             :     Action action_;
     108             :     QueryKey *rkey_;
     109             :     struct DnsResolverInfo {
     110             :         boost::asio::ip::udp::endpoint ep_;
     111             :         uint32_t retries_;
     112             :         Timer *timer_;
     113             :     };
     114             :     std::vector<DnsResolverInfo *> dns_resolvers_;
     115             :     std::vector<DnsResolverInfo *> def_dns_resolvers_;
     116             :     std::string ipam_name_;
     117             :     std::string domain_name_;
     118             :     autogen::IpamType ipam_type_;
     119             :     autogen::VirtualDnsType vdns_type_;
     120             :     DnsItems items_;
     121             :     DnsItems linklocal_items_;
     122             :     DnsNameEncoder name_encoder_;
     123             :     bool query_name_update_;
     124             :     uint16_t query_name_update_len_;   // num bytes added in the query section
     125             :     uint16_t pend_req_;
     126             :     ResolvList resolv_list_;
     127             :     std::mutex mutex_;
     128             :     bool default_method_;
     129             :     uint8_t curr_index_;
     130             :     bool SendDnsQuery(DnsResolverInfo *resolver, uint16_t xid);
     131             : 
     132             :     DISALLOW_COPY_AND_ASSIGN(DnsHandler);
     133             : };
     134             : 
     135             : #endif // vnsw_agent_dns_handler_hpp

Generated by: LCOV version 1.14