Add support for register-dns through interactive service
PATCH 1/1 Add support for register-dns through interactive service
The call to the service returns promptly after delegating the job to a thread, before the task is completed. In the thread, "net stop dnscache", "net start dnscache", "ipconfig /flushdns" and "ipconfig /register-dns" are executed in that order.
Parallel execution of these commands is prevented by a lock that is common to all connections started by the service.
Note: "net stop .." is used instead of "sc stop.." as the latter can return before the service has fully stopped (in STOP_PENDING state), causing the subsequent start to fail.
--- include/openvpn-msg.h | 3 +- src/openvpn/tun.c | 35 ++++++++- src/openvpnserv/interactive.c | 156 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+), 2 deletions(-)
include/openvpn-msg.h +2 -1
@@ -37,7 +37,8 @@ typedef enum { msg_del_nbt_cfg, msg_flush_neighbors, msg_add_block_dns, - msg_del_block_dns + msg_del_block_dns, + msg_register_dns } message_type_t; typedef struct {
src/openvpn/tun.c +34 -1
@@ -5101,10 +5101,43 @@ fork_dhcp_action (struct tuntap *tt) } } +static void +register_dns_service (const struct tuntap *tt) +{ +DWORD len; +HANDLE msg_channel = tt->options.msg_channel; +ack_message_t ack; +struct gc_arena gc =gc_new (); + +message_header_t rdns = { msg_register_dns,sizeof (message_header_t),0 }; + +if (!WriteFile (msg_channel, &rdns,sizeof (rdns), &len,NULL ) || + !ReadFile (msg_channel, &ack,sizeof (ack), &len,NULL )) + { +msg (M_WARN ,"Register_dns: could not talk to service: %s [status=0x%lx]" , +strerror_win32 (GetLastError (), &gc),GetLastError ()); + } + +else if (ack.error_number !=NO_ERROR ) + { +msg (M_WARN ,"Register_dns failed using service: %s [status=0x%x]" , +strerror_win32 (ack.error_number, &gc), ack.error_number); + } + +else +msg (M_INFO ,"Register_dns request sent to the service" ); + +gc_free (&gc); +} +void fork_register_dns_action (struct tuntap *tt) { -if (tt && tt->options.register_dns) +if (tt && tt->options.register_dns && tt->options.msg_channel) + { +register_dns_service (tt); + } +else if (tt && tt->options.register_dns) {struct gc_arena gc =gc_new ();struct buffer cmd =alloc_buf_gc (256 , &gc);
src/openvpnserv/interactive.c +156 -0
186 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Hi,
Motivated by the discussion on "forgotten" patches, here is a reminder for review time..
http://thread.gmane.org/gmane.network.openvpn.devel/11354
Thanks,
Selva
ACK. Thanks a lot, and sorry for the delay in reviewing.
I've stared at the code, and it looks good to me (very clean code, if I may say so :-) ) - the openvpn code is definitely good, the iservice code "looks reasonable", though I might be missing some windows intricacies.
Compile-tested on my mingw test environment, but have not run it yet - I'm going to be lazy and wait for Samuli's build snapshot.
Your patch has been applied to the master branch.
commit 3e42a558103e4e3f45ed28ccb761cefed20e8247 (master)
Author: Selva Nair Date: Thu Mar 10 23:47:26 2016 -0500
Add support for register-dns through interactive service
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/11354
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering