VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/HostDnsService.h@ 72919

Last change on this file since 72919 was 72547, checked in by vboxsync, 6 years ago

HostDnsService: don't cache HostDnsInformation in the monitor.
Move polling of the extradata and lax comparison logic to the proxy.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/* $Id: HostDnsService.h 72547 2018-06-13 15:50:39Z vboxsync $ */
2/** @file
3 * Host DNS listener.
4 */
5
6/*
7 * Copyright (C) 2005-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___H_DNSHOSTSERVICE
19#define ___H_DNSHOSTSERVICE
20#include "VirtualBoxBase.h"
21
22#include <iprt/cdefs.h>
23#include <iprt/types.h>
24#include <iprt/cpp/lock.h>
25
26#include <list>
27#include <vector>
28
29typedef std::list<com::Utf8Str> Utf8StrList;
30typedef Utf8StrList::iterator Utf8StrListIterator;
31
32class HostDnsMonitorProxy;
33typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
34
35class HostDnsInformation
36{
37 public:
38 static const uint32_t IGNORE_SERVER_ORDER = RT_BIT_32(0);
39 static const uint32_t IGNORE_SUFFIXES = RT_BIT_32(1);
40
41 public:
42 std::vector<std::string> servers;
43 std::string domain;
44 std::vector<std::string> searchList;
45 bool equals(const HostDnsInformation &, uint32_t fLaxComparison = 0) const;
46};
47
48/**
49 * This class supposed to be a real DNS monitor object it should be singleton,
50 * it lifecycle starts and ends together with VBoxSVC.
51 */
52class HostDnsMonitor
53{
54 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsMonitor);
55
56 public:
57 static HostDnsMonitor *createHostDnsMonitor();
58 static void shutdown();
59
60 /* @note: method will wait till client call
61 HostDnsService::monitorThreadInitializationDone() */
62 virtual HRESULT init(HostDnsMonitorProxy *proxy);
63
64 protected:
65 explicit HostDnsMonitor(bool fThreaded = false);
66 virtual ~HostDnsMonitor();
67
68 void setInfo(const HostDnsInformation &);
69
70 /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
71 void monitorThreadInitializationDone();
72 virtual void monitorThreadShutdown() = 0;
73 virtual int monitorWorker() = 0;
74
75 private:
76 static DECLCALLBACK(int) threadMonitoringRoutine(RTTHREAD, void *);
77
78 protected:
79 mutable RTCLockMtx m_LockMtx;
80
81 public:
82 struct Data;
83 Data *m;
84};
85
86/**
87 * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
88 */
89class HostDnsMonitorProxy
90{
91 public:
92 HostDnsMonitorProxy();
93 ~HostDnsMonitorProxy();
94 void init(VirtualBox *virtualbox);
95 void notify(const HostDnsInformation &info);
96
97 HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
98 HRESULT GetDomainName(com::Utf8Str *pDomainName);
99 HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
100
101 private:
102 void pollGlobalExtraData();
103 bool updateInfo(const HostDnsInformation &info);
104
105 private:
106 mutable RTCLockMtx m_LockMtx;
107
108 private:
109 struct Data;
110 Data *m;
111};
112
113# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
114class HostDnsServiceDarwin : public HostDnsMonitor
115{
116 public:
117 HostDnsServiceDarwin();
118 ~HostDnsServiceDarwin();
119 virtual HRESULT init(HostDnsMonitorProxy *proxy);
120
121 protected:
122 virtual void monitorThreadShutdown();
123 virtual int monitorWorker();
124
125 private:
126 HRESULT updateInfo();
127 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
128 struct Data;
129 Data *m;
130};
131# endif
132# if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
133class HostDnsServiceWin : public HostDnsMonitor
134{
135 public:
136 HostDnsServiceWin();
137 ~HostDnsServiceWin();
138 virtual HRESULT init(HostDnsMonitorProxy *proxy);
139
140 protected:
141 virtual void monitorThreadShutdown();
142 virtual int monitorWorker();
143
144 private:
145 HRESULT updateInfo();
146
147 private:
148 struct Data;
149 Data *m;
150};
151# endif
152# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \
153 || defined(DOXYGEN_RUNNING)
154class HostDnsServiceResolvConf: public HostDnsMonitor
155{
156 public:
157 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsMonitor(fThreaded), m(NULL) {}
158 virtual ~HostDnsServiceResolvConf();
159 virtual HRESULT init(HostDnsMonitorProxy *proxy, const char *aResolvConfFileName);
160 const std::string& resolvConf() const;
161
162 protected:
163 HRESULT readResolvConf();
164 /* While not all hosts supports Hosts DNS change notifiaction
165 * default implementation offers return VERR_IGNORE.
166 */
167 virtual void monitorThreadShutdown() {}
168 virtual int monitorWorker() {return VERR_IGNORED;}
169
170 protected:
171 struct Data;
172 Data *m;
173};
174# if defined(RT_OS_SOLARIS) || defined(DOXYGEN_RUNNING)
175/**
176 * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
177 */
178class HostDnsServiceSolaris : public HostDnsServiceResolvConf
179{
180 public:
181 HostDnsServiceSolaris(){}
182 ~HostDnsServiceSolaris(){}
183 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
184 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
185 }
186};
187
188# endif
189# if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
190class HostDnsServiceLinux : public HostDnsServiceResolvConf
191{
192 public:
193 HostDnsServiceLinux():HostDnsServiceResolvConf(true){}
194 virtual ~HostDnsServiceLinux();
195 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
196 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
197 }
198
199 protected:
200 virtual void monitorThreadShutdown();
201 virtual int monitorWorker();
202};
203
204# endif
205# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
206class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
207{
208 public:
209 HostDnsServiceFreebsd(){}
210 ~HostDnsServiceFreebsd(){}
211 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
212 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
213 }
214};
215
216# endif
217# if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
218class HostDnsServiceOs2 : public HostDnsServiceResolvConf
219{
220 public:
221 HostDnsServiceOs2(){}
222 ~HostDnsServiceOs2(){}
223 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
224 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
225 return HostDnsServiceResolvConf::init(proxy, "\\MPTN\\ETC\\RESOLV2");
226 }
227};
228
229# endif
230# endif
231
232#endif /* !___H_DNSHOSTSERVICE */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette