VirtualBox

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

Last change on this file since 72439 was 72439, checked in by vboxsync, 7 years ago

HostDnsService: Don't store a reference to the virtualbox object in
the monitor.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: HostDnsService.h 72439 2018-06-04 22:05:25Z 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 const HostDnsInformation &getInfo() const;
65
66 protected:
67 explicit HostDnsMonitor(bool fThreaded = false);
68 virtual ~HostDnsMonitor();
69
70 void setInfo(const HostDnsInformation &);
71
72 /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
73 void monitorThreadInitializationDone();
74 virtual void monitorThreadShutdown() = 0;
75 virtual int monitorWorker() = 0;
76
77 private:
78 static DECLCALLBACK(int) threadMonitoringRoutine(RTTHREAD, void *);
79 void pollGlobalExtraData();
80
81 protected:
82 mutable RTCLockMtx m_LockMtx;
83
84 public:
85 struct Data;
86 Data *m;
87};
88
89/**
90 * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
91 */
92class HostDnsMonitorProxy
93{
94 public:
95 HostDnsMonitorProxy();
96 ~HostDnsMonitorProxy();
97 void init(VirtualBox *virtualbox);
98 void notify() const;
99
100 VirtualBox *getVirtualBox() const;
101
102 HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
103 HRESULT GetDomainName(com::Utf8Str *pDomainName);
104 HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
105
106 bool operator==(PCHostDnsMonitorProxy&);
107
108 private:
109 void updateInfo();
110
111 private:
112 mutable RTCLockMtx m_LockMtx;
113
114 private:
115 struct Data;
116 Data *m;
117};
118
119# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
120class HostDnsServiceDarwin : public HostDnsMonitor
121{
122 public:
123 HostDnsServiceDarwin();
124 ~HostDnsServiceDarwin();
125 virtual HRESULT init(HostDnsMonitorProxy *proxy);
126
127 protected:
128 virtual void monitorThreadShutdown();
129 virtual int monitorWorker();
130
131 private:
132 HRESULT updateInfo();
133 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
134 struct Data;
135 Data *m;
136};
137# endif
138# if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
139class HostDnsServiceWin : public HostDnsMonitor
140{
141 public:
142 HostDnsServiceWin();
143 ~HostDnsServiceWin();
144 virtual HRESULT init(HostDnsMonitorProxy *proxy);
145
146 protected:
147 virtual void monitorThreadShutdown();
148 virtual int monitorWorker();
149
150 private:
151 HRESULT updateInfo();
152
153 private:
154 struct Data;
155 Data *m;
156};
157# endif
158# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \
159 || defined(DOXYGEN_RUNNING)
160class HostDnsServiceResolvConf: public HostDnsMonitor
161{
162 public:
163 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsMonitor(fThreaded), m(NULL) {}
164 virtual ~HostDnsServiceResolvConf();
165 virtual HRESULT init(HostDnsMonitorProxy *proxy, const char *aResolvConfFileName);
166 const std::string& resolvConf() const;
167
168 protected:
169 HRESULT readResolvConf();
170 /* While not all hosts supports Hosts DNS change notifiaction
171 * default implementation offers return VERR_IGNORE.
172 */
173 virtual void monitorThreadShutdown() {}
174 virtual int monitorWorker() {return VERR_IGNORED;}
175
176 protected:
177 struct Data;
178 Data *m;
179};
180# if defined(RT_OS_SOLARIS) || defined(DOXYGEN_RUNNING)
181/**
182 * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
183 */
184class HostDnsServiceSolaris : public HostDnsServiceResolvConf
185{
186 public:
187 HostDnsServiceSolaris(){}
188 ~HostDnsServiceSolaris(){}
189 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
190 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
191 }
192};
193
194# endif
195# if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
196class HostDnsServiceLinux : public HostDnsServiceResolvConf
197{
198 public:
199 HostDnsServiceLinux():HostDnsServiceResolvConf(true){}
200 virtual ~HostDnsServiceLinux();
201 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
202 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
203 }
204
205 protected:
206 virtual void monitorThreadShutdown();
207 virtual int monitorWorker();
208};
209
210# endif
211# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
212class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
213{
214 public:
215 HostDnsServiceFreebsd(){}
216 ~HostDnsServiceFreebsd(){}
217 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
218 return HostDnsServiceResolvConf::init(proxy, "/etc/resolv.conf");
219 }
220};
221
222# endif
223# if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
224class HostDnsServiceOs2 : public HostDnsServiceResolvConf
225{
226 public:
227 HostDnsServiceOs2(){}
228 ~HostDnsServiceOs2(){}
229 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
230 virtual HRESULT init(HostDnsMonitorProxy *proxy) {
231 return HostDnsServiceResolvConf::init(proxy, "\\MPTN\\ETC\\RESOLV2");
232 }
233};
234
235# endif
236# endif
237
238#endif /* !___H_DNSHOSTSERVICE */
Note: See TracBrowser for help on using the repository browser.

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