Skip to contentSkip to conversation

Set IPv6 DNS servers using interactive service

PATCH In review Selva Nair 2 participants 4 messages Nov 24, 2016

lore
Share & tools
lore

Selva Nair

author
#0 lore raw

PATCH 1/1 Set IPv6 DNS servers using interactive service

- Any existing addresses are deleted before adding
- On close_tun all addresses are deleted (only if any were added)

---
 doc/openvpn.8                 |   2 +-
 include/openvpn-msg.h         |   7 +-
 src/openvpn/tun.c             |  72 +++++++++++++++++-
 src/openvpnserv/Makefile.am   |   2 +-
 src/openvpnserv/common.c      |  12 +++
 src/openvpnserv/interactive.c | 173 ++++++++++++++++++++++++++++++++++++++++++
 src/openvpnserv/service.h     |   3 +
 7 files changed, 264 insertions(+), 7 deletions(-)
doc/openvpn.8 +1 -1
index ffb0f7d..28df268 100644
@@ -5686,7 +5686,7 @@ this option to set secondary DNS server addresses.
 Set primary domain name server IPv6 address.  Repeat
 this option to set secondary DNS server IPv6 addresses.
 
-Note: currently this is handled using netsh and requires admin rights (the
+Note: currently this is handled using netsh (the
 existing DHCP code can only do IPv4 DHCP, and that protocol only
 permits IPv4 addresses anywhere).  The option will be put into the
 environment, so an
include/openvpn-msg.h +3 -4
index 4c13acf..f7fbdd2 100644
@@ -79,10 +79,9 @@ typedef struct {
   message_header_t header;
   interface_t iface;
   char domains[512];
-  struct in_addr primary_ipv4;
-  struct in_addr secondary_ipv4;
-  struct in_addr6 primary_ipv6;
-  struct in_addr6 secondary_ipv6;
+  short family;
+  int addr_len;
+  inet_address_t addr[4]; /* support up to 4 dns addresses */
 } dns_cfg_message_t;
 
 typedef struct {
src/openvpn/tun.c +71 -1

90 lines not on this page · raw message

src/openvpnserv/Makefile.am +1 -1
index 3521a34..58ecd91 100644
@@ -26,7 +26,7 @@ openvpnserv_CFLAGS = \
 	-municode -D_UNICODE \
 	-UNTDDI_VERSION -U_WIN32_WINNT \
 	-D_WIN32_WINNT=_WIN32_WINNT_VISTA
-openvpnserv_LDADD = -ladvapi32 -luserenv -liphlpapi -lfwpuclnt -lrpcrt4 -lshlwapi -lnetapi32 -lws2_32
+openvpnserv_LDADD = -ladvapi32 -luserenv -liphlpapi -lfwpuclnt -lrpcrt4 -lshlwapi -lnetapi32 -lws2_32 -lntdll
 endif
 
 openvpnserv_SOURCES = \
src/openvpnserv/common.c +12 -0
index dba4724..eafee20 100644
@@ -216,3 +216,15 @@ MsgToEventLog (DWORD flags, LPCTSTR format, ...)
 
   return error;
 }
+
+/* Convert a utf8 string to utf16. Caller should free the result */
+wchar_t *
+utf8to16 (const char *utf8)
+{
+  int n = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
+  wchar_t *utf16 = malloc (n * sizeof (wchar_t));
+  if (!utf16)
+    return NULL;
+  MultiByteToWideChar (CP_UTF8, 0, utf8, -1, utf16, n);
+  return utf16;
+}
src/openvpnserv/interactive.c +173 -0

209 lines not on this page · raw message

src/openvpnserv/service.h +3 -0
index 94bfb07..c5d745f 100644
@@ -89,4 +89,7 @@ BOOL ReportStatusToSCMgr (SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status)
 LPCTSTR GetLastErrorText ();
 DWORD MsgToEventLog (DWORD flags, LPCTSTR lpszMsg, ...);
 
+/* Convert a utf8 string to utf16. Caller should free the result */
+wchar_t *utf8to16 (const char *utf8);
+
 #endif
Signature · 1 line
2.1.4
#1 lore raw

ACK. Code looks reasonable, and it passes compilation.

I have not been able to actually TEST it due to scheduling conflicts today, but I'm taking that risk, based on "it looks good, it affects windows only, and unless the code is activated by *pushing* a DNS6 option, it will not affect existing setups at all".

In case someone wonders whether changing struct dns_cfg_message_t is safe - it is, because we never had a "v4 DNS message" yet, that struct was completely unused (and the new one is theoretically multi-protocol capable, though not "mixed mode").

I did a small code fix, though - the netsh_dns_cmd() always reset "err = 0" at the end:

+ err = ExecCommand (argv0, cmdline, timeout);
+
+out:

+  err = 0;
+  free (cmdline);
+  return err;

+}

.. which did not make sense, so I removed the "err = 0" line.

Your patch has been applied to the master branch.

commit c098016a22e90575e9c3e7c27d7b457ed9d1b5d3

Author: Selva Nair
Date:   Wed Nov 23 22:35:27 2016 -0500
     Set IPv6 DNS servers using interactive service

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg13222.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

author
#2 lore raw
Quoted 7 lines · Gert Doering
src/openvpnserv/interactive.c +5 -0
+out:
+  err = 0;
+  free (cmdline);
+  return err;
+}

.. which did not make sense, so I removed the "err = 0" line.

Good catch. That was a left over from testing ...

Selva

#3 lore raw
In reply to Gert Doering

Hi,

Quoted 6 lines · Gert Doering

ACK. Code looks reasonable, and it passes compilation.

I have not been able to actually TEST it due to scheduling conflicts today, but I'm taking that risk, based on "it looks good, it affects windows only, and unless the code is activated by *pushing* a DNS6 option, it will not affect existing setups at all".

Tested!

It was a bit more work than expected as my test machine was in an... uh... "slightly messy" state, with a gui that crashed when trying to talk to the service pipe, and stuff... but tested both "netsh.exe direct" and "via service", and both produced the expected output in "ipconfig /all".

Yay :-)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...