VirtualBox

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

Last change on this file since 55457 was 55278, checked in by vboxsync, 10 years ago

Main/HostDnsService: Poll for VBoxInternal2/HostDNSOrderIgnore global extradata change, at most every 30 seconds, and only if there is new DNS information. This helps greatly with enabling/disabling this feature, as previously one had to ensure that VBoxSVC was terminated/re-started.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: HostDnsService.h 55278 2015-04-15 11:27:50Z vboxsync $ */
2/** @file
3 * Host DNS listener.
4 */
5
6/*
7 * Copyright (C) 2005-2012 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 std::vector<std::string> servers;
39 std::string domain;
40 std::vector<std::string> searchList;
41 bool equals(const HostDnsInformation &, bool fDNSOrderIgnore = false) const;
42};
43
44/**
45 * This class supposed to be a real DNS monitor object it should be singleton,
46 * it lifecycle starts and ends together with VBoxSVC.
47 */
48class HostDnsMonitor
49{
50 public:
51 static const HostDnsMonitor *getHostDnsMonitor(VirtualBox *virtualbox);
52 static void shutdown();
53
54 void addMonitorProxy(PCHostDnsMonitorProxy) const;
55 void releaseMonitorProxy(PCHostDnsMonitorProxy) const;
56 const HostDnsInformation &getInfo() const;
57 /* @note: method will wait till client call
58 HostDnsService::monitorThreadInitializationDone() */
59 virtual HRESULT init(VirtualBox *virtualbox);
60
61 protected:
62 explicit HostDnsMonitor(bool fThreaded = false);
63 virtual ~HostDnsMonitor();
64
65 void setInfo(const HostDnsInformation &);
66
67 /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
68 void monitorThreadInitializationDone();
69 virtual void monitorThreadShutdown() = 0;
70 virtual int monitorWorker() = 0;
71
72 private:
73 HostDnsMonitor(const HostDnsMonitor &);
74 HostDnsMonitor& operator= (const HostDnsMonitor &);
75 static int threadMonitoringRoutine(RTTHREAD, void *);
76 void pollGlobalExtraData();
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(const HostDnsMonitor *aMonitor, VirtualBox *virtualbox);
95 void notify() const;
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 bool operator==(PCHostDnsMonitorProxy&);
102
103 private:
104 void updateInfo();
105
106 private:
107 mutable RTCLockMtx m_LockMtx;
108
109 private:
110 struct Data;
111 Data *m;
112};
113
114# ifdef RT_OS_DARWIN
115class HostDnsServiceDarwin : public HostDnsMonitor
116{
117 public:
118 HostDnsServiceDarwin();
119 ~HostDnsServiceDarwin();
120 virtual HRESULT init(VirtualBox *virtualbox);
121
122 protected:
123 virtual void monitorThreadShutdown();
124 virtual int monitorWorker();
125
126 private:
127 HRESULT updateInfo();
128 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
129 struct Data;
130 Data *m;
131};
132# endif
133# ifdef RT_OS_WINDOWS
134class HostDnsServiceWin : public HostDnsMonitor
135{
136 public:
137 HostDnsServiceWin();
138 ~HostDnsServiceWin();
139 virtual HRESULT init(VirtualBox *virtualbox);
140
141 protected:
142 virtual void monitorThreadShutdown();
143 virtual int monitorWorker();
144
145 private:
146 HRESULT updateInfo();
147
148 private:
149 struct Data;
150 Data *m;
151};
152# endif
153# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
154class HostDnsServiceResolvConf: public HostDnsMonitor
155{
156 public:
157 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsMonitor(fThreaded), m(NULL) {}
158 virtual ~HostDnsServiceResolvConf();
159 virtual HRESULT init(VirtualBox *virtualbox, 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)
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(VirtualBox *virtualbox) {
184 return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
185 }
186};
187
188# elif defined(RT_OS_LINUX)
189class HostDnsServiceLinux : public HostDnsServiceResolvConf
190{
191 public:
192 HostDnsServiceLinux():HostDnsServiceResolvConf(true){}
193 virtual ~HostDnsServiceLinux();
194 virtual HRESULT init(VirtualBox *virtualbox) {
195 return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
196 }
197
198 protected:
199 virtual void monitorThreadShutdown();
200 virtual int monitorWorker();
201};
202
203# elif defined(RT_OS_FREEBSD)
204class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
205{
206 public:
207 HostDnsServiceFreebsd(){}
208 ~HostDnsServiceFreebsd(){}
209 virtual HRESULT init(VirtualBox *virtualbox) {
210 return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
211 }
212};
213
214# elif defined(RT_OS_OS2)
215class HostDnsServiceOs2 : public HostDnsServiceResolvConf
216{
217 public:
218 HostDnsServiceOs2(){}
219 ~HostDnsServiceOs2(){}
220 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
221 virtual HRESULT init(VirtualBox *virtualbox) {
222 return HostDnsServiceResolvConf::init(virtualbox, "\\MPTN\\ETC\\RESOLV2");
223 }
224};
225
226# endif
227# endif
228
229#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