14#ifndef OPENVPN_TUN_MAC_MACDNS_WATCHDOG_H
15#define OPENVPN_TUN_MAC_MACDNS_WATCHDOG_H
49 const unsigned int flags_arg)
65 std::ostringstream
os;
66 os <<
"MacDNSAction: FLAGS=";
96 const unsigned int flags,
104 create.
add(create_action);
105 destroy.
add(destroy_action);
129 OPENVPN_LOG(
"MacDNSWatchdog::setdns: runloop undefined");
155 return config->to_string();
157 return std::string(
"UNDEF");
182 SCDynamicStoreContext context = {0,
this,
nullptr,
nullptr,
nullptr};
183 CF::DynamicStore ds(SCDynamicStoreCreate(kCFAllocatorDefault,
184 CFSTR(
"OpenVPN_MacDNSWatchdog"),
188 throw macdns_watchdog_error(
"SCDynamicStoreCreate");
190 if (!watched_keys.defined())
191 throw macdns_watchdog_error(
"watched_keys is undefined");
192 if (!SCDynamicStoreSetNotificationKeys(ds(),
195 throw macdns_watchdog_error(
"SCDynamicStoreSetNotificationKeys failed");
196 CF::RunLoopSource rls(SCDynamicStoreCreateRunLoopSource(kCFAllocatorDefault, ds(), 0));
198 throw macdns_watchdog_error(
"SCDynamicStoreCreateRunLoopSource failed");
199 CFRunLoopAddSource(CFRunLoopGetCurrent(), rls(), kCFRunLoopDefaultMode);
204 catch (
const std::exception &e)
206 OPENVPN_LOG(
"MacDNSWatchdog::thread_func exception: " << e.what());
211 static void callback_static(SCDynamicStoreRef store, CFArrayRef changedKeys,
void *arg)
217 void callback(SCDynamicStoreRef store, CFArrayRef changedKeys)
227 CFRunLoopTimerContext context = {0,
this,
nullptr,
nullptr,
nullptr};
233 OPENVPN_LOG(
"MacDNSWatchdog::schedule_push_timer: failed to create timer");
264 OPENVPN_LOG(
"MacDNSWatchdog: updated DNS settings");
266 catch (
const std::exception &e)
268 OPENVPN_LOG(
"MacDNSWatchdog::push_timer_callback exception: " << e.what());
const MacDNSWatchdog::Ptr parent
void execute(std::ostream &os) override
const MacDNS::Config::Ptr config
std::string to_string() const override
DNSAction(const MacDNSWatchdog::Ptr &parent_arg, const MacDNS::Config::Ptr &config_arg, const unsigned int flags_arg)
void callback(SCDynamicStoreRef store, CFArrayRef changedKeys)
RCPtr< MacDNSWatchdog > Ptr
virtual ~MacDNSWatchdog()
void cancel_push_timer_nolock()
bool setdns(const MacDNS::Config::Ptr &config, const unsigned int flags)
static void add_actions(const MacDNS::Config::Ptr &dns, const unsigned int flags, ActionList &create, ActionList &destroy)
std::mutex push_timer_lock
void push_timer_callback(CFRunLoopTimerRef timer)
static void push_timer_callback_static(CFRunLoopTimerRef timer, void *info)
std::string to_string() const
Log::Context::Wrapper logwrap
static void callback_static(SCDynamicStoreRef store, CFArrayRef changedKeys, void *arg)
MacDNS::Config::Ptr config_
void schedule_push_timer(const int seconds)
CF::Array dskey_array() const
bool setdns(const Config &config)
bool signal_network_reconfiguration()
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
#define OPENVPN_EXCEPTION(C)
#define OPENVPN_LOG(args)
Argument to construct a Context in a different thread.
Scoped RAII for the global_log pointer.
static const char config[]