VirtualBox

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

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

Main/HostDnsService: if VBoxInternal2/HostDNSOrderIgnore global
extradata is set to a value other than "0", don't send notification
when only the order of nameservers changed.

  • 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 55223 2015-04-13 18:06:30Z 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.215389.xyz. 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
77 protected:
78 mutable RTCLockMtx m_LockMtx;
79
80 public:
81 struct Data;
82 Data *m;
83};
84
85/**
86 * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
87 */
88class HostDnsMonitorProxy
89{
90 public:
91 HostDnsMonitorProxy();
92 ~HostDnsMonitorProxy();
93 void init(const HostDnsMonitor *aMonitor, VirtualBox *virtualbox);
94 void notify() const;
95
96 HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
97 HRESULT GetDomainName(com::Utf8Str *pDomainName);
98 HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
99
100 bool operator==(PCHostDnsMonitorProxy&);
101
102 private:
103 void updateInfo();
104
105 private:
106 mutable RTCLockMtx m_LockMtx;
107
108 private:
109 struct Data;
110 Data *m;
111};
112
113# ifdef RT_OS_DARWIN
114class HostDnsServiceDarwin : public HostDnsMonitor
115{
116 public:
117 HostDnsServiceDarwin();
118 ~HostDnsServiceDarwin();
119 virtual HRESULT init(VirtualBox *virtualbox);
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# ifdef RT_OS_WINDOWS
133class HostDnsServiceWin : public HostDnsMonitor
134{
135 public:
136 HostDnsServiceWin();
137 ~HostDnsServiceWin();
138 virtual HRESULT init(VirtualBox *virtualbox);
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)
153class HostDnsServiceResolvConf: public HostDnsMonitor
154{
155 public:
156 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsMonitor(fThreaded), m(NULL) {}
157 virtual ~HostDnsServiceResolvConf();
158 virtual HRESULT init(VirtualBox *virtualbox, const char *aResolvConfFileName);
159 const std::string& resolvConf() const;
160
161 protected:
162 HRESULT readResolvConf();
163 /* While not all hosts supports Hosts DNS change notifiaction
164 * default implementation offers return VERR_IGNORE.
165 */
166 virtual void monitorThreadShutdown() {}
167 virtual int monitorWorker() {return VERR_IGNORED;}
168
169 protected:
170 struct Data;
171 Data *m;
172};
173# if defined(RT_OS_SOLARIS)
174/**
175 * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
176 */
177class HostDnsServiceSolaris : public HostDnsServiceResolvConf
178{
179 public:
180 HostDnsServiceSolaris(){}
181 ~HostDnsServiceSolaris(){}
182 virtual HRESULT init(VirtualBox *virtualbox) {
183 return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
184 }
185};
186
187# elif defined(RT_OS_LINUX)
188class HostDnsServiceLinux : public HostDnsServiceResolvConf
189{
190 public:
191 HostDnsServiceLinux():HostDnsServiceResolvConf(true){}
192 virtual ~HostDnsServiceLinux();
193 virtual HRESULT init(VirtualBox *virtualbox) {
194 return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
195 }
196
197 protected:
198 virtual void monitorThreadShutdown();
199 virtual int monitorWorker();
200};
201
202# elif defined(RT_OS_FREEBSD)
203class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
204{
205 public:
206 HostDnsServiceFreebsd(){}
207 ~HostDnsServiceFreebsd(){}
208 virtual HRESULT init(VirtualBox *virtualbox) {
209 return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
210 }
211};
212
213# elif defined(RT_OS_OS2)
214class HostDnsServiceOs2 : public HostDnsServiceResolvConf
215{
216 public:
217 HostDnsServiceOs2(){}
218 ~HostDnsServiceOs2(){}
219 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
220 virtual HRESULT init(VirtualBox *virtualbox) {
221 return HostDnsServiceResolvConf::init(virtualbox, "\\MPTN\\ETC\\RESOLV2");
222 }
223};
224
225# endif
226# endif
227
228#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