Remove script-security warning
PATCH 1/5 Remove script-security warning
--- src/openvpn/init.c | 6 ------ 1 file changed, 6 deletions(-)
src/openvpn/init.c +0 -6
@@ -2480,12 +2480,6 @@ do_option_warnings (struct context *c)msg (M_WARN ,"NOTE: --connect-timeout option is not supported on this OS" );#endif -if (script_security >=SSEC_SCRIPTS ) -msg (M_WARN ,"NOTE: the current --script-security setting may allow this configuration to call user-defined scripts" ); -else if (script_security >=SSEC_PW_ENV ) -msg (M_WARN ,"WARNING: the current --script-security setting may allow passwords to be passed to scripts via environmental variables" ); -else -msg (M_WARN ,"NOTE: " PACKAGE_NAME " 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables" ); } static void
Signature · 1 line
1.7.9.5
PATCH 2/5 Allow routes to be set before opening tun, similar to ifconfig before opening tun
--- src/openvpn/init.c | 11 +++++++++-- src/openvpn/tun.h | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
src/openvpn/init.c +9 -2
@@ -1429,6 +1429,13 @@ do_open_tun (struct context *c)do_ifconfig (c->c1.tuntap, guess,TUN_MTU_SIZE (&c->c2.frame), c->c2.es); } +/* possibly add routes */ +if (ifconfig_order () ==ROUTE_BEFORE_TUN ) { +/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ +do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es); + } +/* open the tun device */ open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, c->c1.tuntap);
@@ -1460,7 +1467,7 @@ do_open_tun (struct context *c) c->c2.es);/* possibly add routes */ -if (!c->options.route_delay_defined) +if ((ifconfig_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined))do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap, c->plugins, c->c2.es);
@@ -1668,7 +1675,7 @@ do_up (struct context *c, bool pulled_options, unsigned int option_types_found)#endif /* if --route-delay was specified, start timer */ -if (c->options.route_delay_defined) +if ((ifconfig_order () ==ROUTE_AFTER_TUN ) && c->options.route_delay_defined) {event_timeout_init (&c->c2.route_wakeup, c->options.route_delay, now);event_timeout_init (&c->c2.route_wakeup_expire, c->options.route_delay + c->options.route_delay_window, now);
src/openvpn/tun.h +11 -0
@@ -297,6 +297,17 @@ ifconfig_order(void)#endif } +#define ROUTE_BEFORE_TUN 0 +#define ROUTE_AFTER_TUN 1 +#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN + +static inline int +route_order (void ) +{ +return ROUTE_ORDER_DEFAULT ; +} + +#ifdef WIN32 #define TUN_PASS_BUFFER
Signature · 1 line
1.7.9.5
PATCH 1/1 Allow routes to be set before opening tun, similar to ifconfig before opening tun
--- src/openvpn/init.c | 11 +++++++++-- src/openvpn/tun.h | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
src/openvpn/init.c +9 -2
@@ -1429,6 +1429,13 @@ do_open_tun (struct context *c)do_ifconfig (c->c1.tuntap, guess,TUN_MTU_SIZE (&c->c2.frame), c->c2.es); } +/* possibly add routes */ +if (route_order () ==ROUTE_BEFORE_TUN ) { +/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ +do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es); + } +/* open the tun device */ open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, c->c1.tuntap);
@@ -1460,7 +1467,7 @@ do_open_tun (struct context *c) c->c2.es);/* possibly add routes */ -if (!c->options.route_delay_defined) +if ((ifconfig_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined))do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap, c->plugins, c->c2.es);
@@ -1668,7 +1675,7 @@ do_up (struct context *c, bool pulled_options, unsigned int option_types_found)#endif /* if --route-delay was specified, start timer */ -if (c->options.route_delay_defined) +if ((ifconfig_order () ==ROUTE_AFTER_TUN ) && c->options.route_delay_defined) {event_timeout_init (&c->c2.route_wakeup, c->options.route_delay, now);event_timeout_init (&c->c2.route_wakeup_expire, c->options.route_delay + c->options.route_delay_window, now);
src/openvpn/tun.h +11 -0
@@ -297,6 +297,17 @@ ifconfig_order(void)#endif } +#define ROUTE_BEFORE_TUN 0 +#define ROUTE_AFTER_TUN 1 +#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN + +static inline int +route_order (void ) +{ +return ROUTE_ORDER_DEFAULT ; +} + +#ifdef WIN32 #define TUN_PASS_BUFFER
Signature · 1 line
1.7.9.5
Re: [Openvpn-devel] [PATCH] Allow routes to be set before opening tun, similar to ifconfig before opening tun
Hi Arne,
For the context, this ROUTE_BEFORE_TUN is required for the Android VPN API, right? Might be useful to put in the commit message. Furthermore two comments on the patch, which I've put inline:
Quoted 24 lines · Arne Schwabe
--- src/openvpn/init.c | 11 +++++++++-- src/openvpn/tun.h | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)src/openvpn/init.c +7
-0@@ -1429,6 +1429,13 @@ do_open_tun (struct context *c)do_ifconfig (c->c1.tuntap, guess,TUN_MTU_SIZE (&c->c2.frame), c->c2.es); } +/* possibly add routes */ +if (route_order () ==ROUTE_BEFORE_TUN ) { +/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ +do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es); + } +/* open the tun device */ open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, c->c1.tuntap);
src/openvpn/init.c do_open_tun (struct context *c) · line 1470
Quoted 5 lines
src/openvpn/init.c +1
-1@@ -1460,7 +1467,7 @@ do_open_tun (struct context *c) c->c2.es);/* possibly add routes */ -if (!c->options.route_delay_defined) +if ((ifconfig_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined))
Shouldn't this be route_order() ?
src/openvpn/init.c do_up (struct context *c, bool pulled_options, unsigned int option_types_found) · line 1678
Quoted 9 lines
src/openvpn/init.c +1
-1do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap, c->plugins, c->c2.es);@@ -1668,7 +1675,7 @@ do_up (struct context *c, bool pulled_options, unsigned int option_types_found)#endif /* if --route-delay was specified, start timer */ -if (c->options.route_delay_defined) +if ((ifconfig_order () ==ROUTE_AFTER_TUN ) && c->options.route_delay_defined)
Same goes here, I guess your mean route_order().
Quoted 15 lines
src/openvpn/init.c +0
-0{event_timeout_init (&c->c2.route_wakeup, c->options.route_delay, now);event_timeout_init (&c->c2.route_wakeup_expire, c->options.route_delay + c->options.route_delay_window, now);src/openvpn/tun.h +4
-0@@ -297,6 +297,17 @@ ifconfig_order(void)#endif } +#define ROUTE_BEFORE_TUN 0 +#define ROUTE_AFTER_TUN 1 +#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN +
src/openvpn/tun.h ifconfig_order(void) · line 313
Quoted 10 lines
src/openvpn/tun.h +7
-0+static inline int +route_order (void ) +{ +return ROUTE_ORDER_DEFAULT ; +} + +#ifdef WIN32 #define TUN_PASS_BUFFER
Regards,
-Steffan
PATCH 1/1 Allow routes to be set before opening tun, similar to ifconfig before opening tun
--- src/openvpn/init.c | 11 +++++++++-- src/openvpn/tun.h | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
src/openvpn/init.c +9 -2
@@ -1429,6 +1429,13 @@ do_open_tun (struct context *c)do_ifconfig (c->c1.tuntap, guess,TUN_MTU_SIZE (&c->c2.frame), c->c2.es); } +/* possibly add routes */ +if (route_order () ==ROUTE_BEFORE_TUN ) { +/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ +do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es); + } +/* open the tun device */ open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, c->c1.tuntap);
@@ -1460,7 +1467,7 @@ do_open_tun (struct context *c) c->c2.es);/* possibly add routes */ -if (!c->options.route_delay_defined) +if ((ifconfig_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined))do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap, c->plugins, c->c2.es);
@@ -1668,7 +1675,7 @@ do_up (struct context *c, bool pulled_options, unsigned int option_types_found)#endif /* if --route-delay was specified, start timer */ -if (c->options.route_delay_defined) +if ((ifconfig_order () ==ROUTE_AFTER_TUN ) && c->options.route_delay_defined) {event_timeout_init (&c->c2.route_wakeup, c->options.route_delay, now);event_timeout_init (&c->c2.route_wakeup_expire, c->options.route_delay + c->options.route_delay_window, now);
src/openvpn/tun.h +11 -0
@@ -297,6 +297,17 @@ ifconfig_order(void)#endif } +#define ROUTE_BEFORE_TUN 0 +#define ROUTE_AFTER_TUN 1 +#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN + +static inline int +route_order (void ) +{ +return ROUTE_ORDER_DEFAULT ; +} + +#ifdef WIN32 #define TUN_PASS_BUFFER
Signature · 1 line
1.7.9.5
PATCH 1/1 Allow routes to be set before opening tun, similar to ifconfig before opening tun
In reply to Steffan Karger--- src/openvpn/init.c | 11 +++++++++-- src/openvpn/tun.h | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
src/openvpn/init.c +9 -2
@@ -1429,6 +1429,13 @@ do_open_tun (struct context *c)do_ifconfig (c->c1.tuntap, guess,TUN_MTU_SIZE (&c->c2.frame), c->c2.es); } +/* possibly add routes */ +if (route_order () ==ROUTE_BEFORE_TUN ) { +/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ +do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es); + } +/* open the tun device */ open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, c->c1.tuntap);
@@ -1460,7 +1467,7 @@ do_open_tun (struct context *c) c->c2.es);/* possibly add routes */ -if (!c->options.route_delay_defined) +if ((route_order () ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined))do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, c->c1.tuntap, c->plugins, c->c2.es);
@@ -1668,7 +1675,7 @@ do_up (struct context *c, bool pulled_options, unsigned int option_types_found)#endif /* if --route-delay was specified, start timer */ -if (c->options.route_delay_defined) +if ((route_order () ==ROUTE_AFTER_TUN ) && c->options.route_delay_defined) {event_timeout_init (&c->c2.route_wakeup, c->options.route_delay, now);event_timeout_init (&c->c2.route_wakeup_expire, c->options.route_delay + c->options.route_delay_window, now);
src/openvpn/tun.h +11 -0
@@ -297,6 +297,17 @@ ifconfig_order(void)#endif } +#define ROUTE_BEFORE_TUN 0 +#define ROUTE_AFTER_TUN 1 +#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN + +static inline int +route_order (void ) +{ +return ROUTE_ORDER_DEFAULT ; +} + +#ifdef WIN32 #define TUN_PASS_BUFFER
Signature · 1 line
1.7.9.5
PATCH 3/5 add ability to send/receive file descriptors via management interface, only used in android so. For now under #ifdef ANDROID
In reply to Arne Schwabe--- src/openvpn/manage.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/openvpn/manage.h | 4 +++ 2 files changed, 92 insertions(+)
src/openvpn/manage.c +88 -0
@@ -1779,6 +1779,79 @@ man_io_error (struct management *man, const char *prefix)return false; } +#ifdef TARGET_ANDROID +static ssize_t write_fd (int fd,void *ptr,size_t nbytes,int flags,int sendfd) +{ +struct msghdr msg; +struct iovec iov[1 ]; + +union { +struct cmsghdr cm; +char control[CMSG_SPACE (sizeof (int ))]; + } control_un; +struct cmsghdr *cmptr; + + msg.msg_control = control_un.control; + msg.msg_controllen =sizeof (control_un.control); + + cmptr =CMSG_FIRSTHDR (&msg); + cmptr->cmsg_len =CMSG_LEN (sizeof (int )); + cmptr->cmsg_level =SOL_SOCKET ; + cmptr->cmsg_type =SCM_RIGHTS ; + *((int *)CMSG_DATA (cmptr)) = sendfd; + + msg.msg_name =NULL ; + msg.msg_namelen =0 ; + + iov[0 ].iov_base = ptr; + iov[0 ].iov_len = nbytes; + msg.msg_iov = iov; + msg.msg_iovlen =1 ; + +return (sendmsg (fd, &msg, flags)); +} + +static ssize_t read_fd (int fd,void *ptr,size_t nbytes,int flags,int *recvfd) +{ +struct msghdr msghdr; +struct iovec iov[1 ]; +ssize_t n; + +union { +struct cmsghdr cm; +char control[CMSG_SPACE (sizeof (int ))]; + } control_un; +struct cmsghdr *cmptr; + + msghdr.msg_control = control_un.control; + msghdr.msg_controllen =sizeof (control_un.control); + + msghdr.msg_name =NULL ; + msghdr.msg_namelen =0 ; + + iov[0 ].iov_base = ptr; + iov[0 ].iov_len = nbytes; + msghdr.msg_iov = iov; + msghdr.msg_iovlen =1 ; + +if ( (n =recvmsg (fd, &msghdr, flags)) <=0 ) +return (n); + +if ( (cmptr =CMSG_FIRSTHDR (&msghdr)) !=NULL && + cmptr->cmsg_len ==CMSG_LEN (sizeof (int ))) { +if (cmptr->cmsg_level !=SOL_SOCKET ) +msg (M_ERR ,"control level != SOL_SOCKET" ); +if (cmptr->cmsg_type !=SCM_RIGHTS ) +msg (M_ERR ,"control type != SCM_RIGHTS" ); + *recvfd = *((int *)CMSG_DATA (cmptr)); + }else + *recvfd =-1 ;/* descriptor was not passed */ + +return (n); +} +#endif + +static int man_read (struct management *man) {
@@ -1788,7 +1861,15 @@ man_read (struct management *man)unsigned char buf[256 ];int len =0 ; +#ifdef TARGET_ANDROID +int fd; + len =read_fd (man->connection.sd_cli, buf,sizeof (buf),MSG_NOSIGNAL , &fd); +if (fd >=0 ) + man->connection.lastfdreceived = fd; +#else len =recv (man->connection.sd_cli, buf,sizeof (buf),MSG_NOSIGNAL ); +#endif +if (len ==0 ) {man_reset_client_socket (man, false);
@@ -1865,6 +1946,13 @@ man_write (struct management *man)if (buf &&BLEN (buf)) {const int len =min_int (size_hint,BLEN (buf)); +#ifdef TARGET_ANDROID +if (man->connection.fdtosend >0 ) + { + sent =write_fd (man->connection.sd_cli,BPTR (buf), len,MSG_NOSIGNAL ,man->connection.fdtosend); + man->connection.fdtosend =-1 ; + } else +#endif sent =send (man->connection.sd_cli,BPTR (buf), len,MSG_NOSIGNAL );if (sent >=0 ) {
src/openvpn/manage.h +4 -0
@@ -299,6 +299,10 @@ struct man_connection {#ifdef MANAGMENT_EXTERNAL_KEY struct buffer_list *rsa_sig;#endif +#ifdef TARGET_ANDROID +int fdtosend; +int lastfdreceived; +#endif };struct management
Signature · 1 line
1.7.9.5
Re: [Openvpn-devel] [PATCH 3/5] add ability to send/receive file descriptors via management interface, only used in android so. For now under #ifdef ANDROID
Hi,
I think the code is fine, but I have some nags about the function names:
Quoted 2 lines · Arne Schwabe
src/openvpn/manage.c +2
-0+#ifdef TARGET_ANDROID +static ssize_t write_fd (int fd,void *ptr,size_t nbytes,int flags,int sendfd)
...
Quoted 1 line
+static
ssize_tread_fd(int fd, void *ptr, size_t nbytes, int flags, int *recvfd)
To make it somewhat easier to understand what these do (in the context of the caller), what do you think about renaming them to
man_send_with_fd()
and
man_recv_with_fd()
?
(man_ being the general prefix for "management specific functions", and send()/recv() being the normal function calls "without fd passing")
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]...PATCH 4/5 Android platform specific changes.
In reply to Arne SchwabeOn Android 4.0 (TARGET_ANDROID) the real opening of the tun is handled by the (Java) application controlling OpenVPN. Instead of calling ifconfig/route call the management to do the work. When running openvpn as root openvpn should be compiled as TARGET_LINUX
--- src/openvpn/options.c | 6 ++++ src/openvpn/route.c | 25 ++++++++++++-- src/openvpn/socket.c | 10 ++++++ src/openvpn/ssl.c | 2 ++ src/openvpn/syshead.h | 2 +- src/openvpn/tun.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++- src/openvpn/tun.h | 8 ++++- 7 files changed, 140 insertions(+), 5 deletions(-)
src/openvpn/options.c +6 -0
@@ -1125,7 +1125,9 @@ show_tuntap_options (const struct tuntap_options *o) }#endif +#endif +#if defined(WIN32 ) || defined(TARGET_ANDROID )static void dhcp_option_address_parse (const char *name,const char *parm,in_addr_t *array,int *len,int msglevel) {
@@ -5935,6 +5937,8 @@ add_option (struct options *options, to->ip_win32_type = index; to->ip_win32_defined = true; } +#endif +#if defined(WIN32 ) || defined(TARGET_ANDROID ) else if (streq (p[0], "dhcp-option") && p[1]) {struct tuntap_options *o = &options->tuntap_options;
@@ -5986,6 +5990,8 @@ add_option (struct options *options, } o->dhcp_options = true; } +#endif +#ifdef WIN32 else if (streq (p[0], "show-adapters")) {VERIFY_PERMISSION (OPT_P_GENERAL );
src/openvpn/route.c +23 -2
@@ -1342,6 +1342,17 @@ add_route (struct route *r,argv_msg (D_ROUTE , &argv); status =openvpn_execve_check (&argv, es,0 ,"ERROR: Linux route add command failed" ); +#elif defined (TARGET_ANDROID ) + +struct user_pass up; +struct buffer out =alloc_buf_gc (64 , &gc); + +buf_printf (&out,"%s %s" , network, netmask); + +strcpy (up.username,buf_bptr (&out)); +management_query_user_pass (management, &up ,"ROUTE" ,GET_USER_PASS_NEED_OK ,(void *)0 ); + +#elif defined (WIN32 ) {DWORD ai =TUN_ADAPTER_INDEX_INVALID ;
@@ -1616,6 +1627,15 @@ add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flaargv_msg (D_ROUTE , &argv); status =openvpn_execve_check (&argv, es,0 ,"ERROR: Linux route -6/-A inet6 add command failed" ); +#elif defined (TARGET_ANDROID ) +struct user_pass up; +struct buffer out =alloc_buf_gc (64 , &gc); + +buf_printf (&out,"%s/%d" , network, r6->netbits); + +strcpy (up.username,buf_bptr (&out)); +management_query_user_pass (management, &up ,"ROUTE6" ,GET_USER_PASS_NEED_OK ,(void *)0 ); +#elif defined (WIN32 )/* netsh interface ipv6 add route 2001:db8::/32 MyTunDevice */
@@ -1875,7 +1895,8 @@ delete_route (struct route *r,argv_msg (D_ROUTE , &argv);openvpn_execve_check (&argv, es,0 ,"ERROR: OpenBSD/NetBSD route delete command failed" ); - +#elif defined(TARGET_ANDROID ) +msg (M_NONFATAL ,"Sorry, deleting routes on Android is not possible. The VpnService API allows routes to be set on connect only." );#else msg (M_FATAL ,"Sorry, but I don't know how to do 'route' commands on this operating system. Try putting your routes in a --route-up script" );#endif
@@ -2425,7 +2446,7 @@ show_routes (int msglev) gc_free (&gc); } -#elif defined(TARGET_LINUX) +#elif defined(TARGET_LINUX) || defined(TARGET_ANDROID)void get_default_gateway (struct route_gateway_info *rgi)
src/openvpn/socket.c +10 -0
@@ -38,6 +38,7 @@#include "ps.h" #include "manage.h" #include "misc.h" +#include "manage.h" #include "memdbg.h"
@@ -725,6 +726,15 @@ create_socket (struct link_socket *sock) {ASSERT (0 ); } +#ifdef TARGET_ANDROID +struct user_pass up; +strcpy (up.username ,__func__); + management->connection.fdtosend = sock->sd; +management_query_user_pass (management, &up ,"PROTECTFD" ,GET_USER_PASS_NEED_OK ,(void *)0 ); + + +#endif + }/*
src/openvpn/ssl.c +2 -0
@@ -1797,6 +1797,8 @@ push_peer_info(struct buffer *buf, struct tls_session *session)buf_printf (&out,"IV_PLAT=netbsd\n" );#elif defined(TARGET_FREEBSD )buf_printf (&out,"IV_PLAT=freebsd\n" ); +#elif defined(TARGET_ANDROID ) +buf_printf (&out,"IV_PLAT=android\n" );#elif defined(WIN32 )buf_printf (&out,"IV_PLAT=win\n" );#endif
src/openvpn/syshead.h +1 -1
@@ -212,7 +212,7 @@#include <net/if_tap.h> #endif -#ifdef TARGET_LINUX +#if defined(TARGET_LINUX ) || defined (TARGET_ANDROID )#if defined(HAVE_NETINET_IF_ETHER_H )#include <netinet/if_ether.h>
src/openvpn/tun.c +91 -1
111 lines not on this page · raw message
src/openvpn/tun.h +7 -1
@@ -38,7 +38,7 @@#include "proto.h" #include "misc.h" -#ifdef WIN32 +#if defined(WIN32 ) || defined(TARGET_ANDROID )#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
@@ -292,6 +292,8 @@ ifconfig_order(void)return IFCONFIG_AFTER_TUN_OPEN ;#elif defined(WIN32 )return IFCONFIG_BEFORE_TUN_OPEN ; +#elif defined(TARGET_ANDROID ) +return IFCONFIG_BEFORE_TUN_OPEN ;#else return IFCONFIG_DEFAULT ;#endif
@@ -304,7 +306,11 @@ ifconfig_order(void)static inline int route_order (void ) { +#if defined(TARGET_ANDROID ) +return ROUTE_BEFORE_TUN ; +#else return ROUTE_ORDER_DEFAULT ; +#endif }
Signature · 1 line
1.7.9.5
Re: [Openvpn-devel] [PATCH 4/5] Android platform specific changes.
Hi,
src/openvpn/options.c show_tuntap_options (const struct tuntap_options *o) · line 1132
Quoted 12 lines · Arne Schwabe
index 05c6da2..9fdfd88 100644
src/openvpn/options.c +2
-0@@ -1125,7 +1125,9 @@ show_tuntap_options (const struct tuntap_options *o) }#endif +#endif +#if defined(WIN32 ) || defined(TARGET_ANDROID )static void dhcp_option_address_parse (const char *name,const char *parm,in_addr_t *array,int *len,int msglevel)
I'm not sure if I understand these bits, will have to look at the patched result. It looks a bit confusing why there would be anything you need to have "on WIN32 and Android, and nowhere else".
src/openvpn/options.c show_tuntap_options (const struct tuntap_options *o)
Quoted 11 lines
src/openvpn/options.c +11
-0+#elif defined (TARGET_ANDROID ) + +struct user_pass up; +struct buffer out =alloc_buf_gc (64 , &gc); + +buf_printf (&out,"%s %s" , network, netmask); + +strcpy (up.username,buf_bptr (&out)); +management_query_user_pass (management, &up ,"ROUTE" ,GET_USER_PASS_NEED_OK ,(void *)0 ); + +
But this is what I want to comment on. I can see what you're doing, and I'm fine with that - but I strongly don't like the resulting code - what do you think about hiding this behind a wrapper
management_android_control( management, buf_bptr(&out), "ROUTE" );
or such, which takes a "char *" or a "struct buffer *", and does the same thing internally? Having "struct user_pass" all over the code, using it as a generic "transport this string to the management interface" container will mightily confuse people looking for "ok, so what is this code doing, and what does it have to do with username and password queries on the management interface"?
src/openvpn/options.c
Quoted 2 lines
src/openvpn/options.c +2
-0+#elif defined(TARGET_ANDROID ) +msg (M_NONFATAL ,"Sorry, deleting routes on Android is not possible. The VpnService API allows routes to be set on connect only." );
For this message, I'm wondering how useful it is. Isn't this printed on *every* disconnect?
[..]
src/openvpn/options.c
Quoted 4 lines
src/openvpn/options.c +4
-0+if (tt->options.domain) { +strcpy (up.username , tt->options.domain); +management_query_user_pass (management, &up ,"DNSDOMAIN" ,GET_USER_PASS_NEED_OK ,(void *)0 ); + }
The wrapper mentioned above could even have a check for "if the pointer is NULL, silently don't do anything", so this would collapse to
management_android_control( management, tt->options.domain, "DNSDOMAIN" );
"just sayin'" :-)
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]...Re: [Openvpn-devel] [PATCH 4/5] Android platform specific changes.
Am 25.04.13 20:56, schrieb Gert Doering:
Quoted 12 lines
Hi,
Quoted 9 lines · Arne Schwabe
index 05c6da2..9fdfd88 100644
src/openvpn/options.c +1
-0@@ -1125,7 +1125,9 @@ show_tuntap_options (const struct tuntap_options *o) }#endif +#endif
Quoted 6 lines
src/openvpn/options.c show_tuntap_options (const struct tuntap_options *o) · line 1132
Quoted 3 lines
src/openvpn/options.c +1
-0+#if defined(WIN32 ) || defined(TARGET_ANDROID )static void dhcp_option_address_parse (const char *name,const char *parm,in_addr_t *array,int *len,int msglevel)I'm not sure if I understand these bits, will have to look at the patched result. It looks a bit confusing why there would be anything you need to have "on WIN32 and Android, and nowhere else".
The dhcp-options are only parsed currently if OpenVPN is compiled for windows. Since I want to support dhcp-options dns I need to enable these options. The tt->options.domain and tt->dns options which are used to pass DNS/Domain via management interface are only available when these options are parsed.
Quoted 16 lines
src/openvpn/options.c show_tuntap_options (const struct tuntap_options *o)
Quoted 12 lines
src/openvpn/options.c +11
-0+#elif defined (TARGET_ANDROID ) + +struct user_pass up; +struct buffer out =alloc_buf_gc (64 , &gc); + +buf_printf (&out,"%s %s" , network, netmask); + +strcpy (up.username,buf_bptr (&out)); +management_query_user_pass (management, &up ,"ROUTE" ,GET_USER_PASS_NEED_OK ,(void *)0 ); + +But this is what I want to comment on. I can see what you're doing, and I'm fine with that - but I strongly don't like the resulting code - what do you think about hiding this behind a wrapper
Quoted 8 lines
management_android_control( management, buf_bptr(&out), "ROUTE" );or such, which takes a "char *" or a "struct buffer *", and does the same thing internally? Having "struct
user_pass" all over the code, using it as a generic "transport this string to the management interface" container will mightily confuse people looking for "ok, so what is this code doing, and what does it have to do with username and password queries on the management interface"?
That is a good idea. I will update the patch with that.
Quoted 6 lines
src/openvpn/options.c
Quoted 2 lines
src/openvpn/options.c +2
-0+#elif defined(TARGET_ANDROID ) +msg (M_NONFATAL ,"Sorry, deleting routes on Android is not possible. The VpnService API allows routes to be set on connect only." );For this message, I'm wondering how useful it is. Isn't this printed on *every* disconnect?
[..]
Hm I could go for a better warning message. But this message not shown that often iirc. Have to check the code again. It over one year since I wrote that part :)
Quoted 4 lines
src/openvpn/options.c
Quoted 4 lines
src/openvpn/options.c +4
-0+if (tt->options.domain) { +strcpy (up.username , tt->options.domain); +management_query_user_pass (management, &up ,"DNSDOMAIN" ,GET_USER_PASS_NEED_OK ,(void *)0 ); + }
Quoted 8 lines
The wrapper mentioned above could even have a check for "if the pointer is NULL, silently don't do anything", so this would collapse to
management_android_control( management, tt->options.domain, "DNSDOMAIN" );"just sayin'" :-)
I will look into it.
Arne
PATCH 5/5 Emulate persist-tun on Android
In reply to Arne SchwabeOn Android changing the configuration of tun is not possible. So instead of reconfiguring the tun device, open a new tun device and close the old one if needed
--- src/openvpn/init.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
src/openvpn/init.c +17 -1
@@ -1402,8 +1402,19 @@ do_open_tun (struct context *c) c->c2.ipv4_tun = (!c->options.tun_ipv6 &&is_dev_type (c->options.dev, c->options.dev_type,"tun" )); +#ifndef TARGET_ANDROID if (!c->c1.tuntap) { +#endif + +#ifdef TARGET_ANDROID +/* If we emulate persist-tun on android we still have to open a new tun and +then close the old */ +int oldtunfd=-1 ; +if (c->c1.tuntap) + oldtunfd = c->c1.tuntap->fd; +#endif +/* initialize (but do not open) tun/tap object */ do_init_tun (c);
@@ -1439,7 +1450,10 @@ do_open_tun (struct context *c)/* open the tun device */ open_tun (c->options.dev, c->options.dev_type, c->options.dev_node, c->c1.tuntap); - +#ifdef TARGET_ANDROID +if (oldtunfd>=0 ) +close (oldtunfd); +#endif /* set the hardware address */ if (c->options.lladdr)set_lladdr (c->c1.tuntap->actual_name, c->options.lladdr, c->c2.es);
@@ -1481,6 +1495,7 @@ do_open_tun (struct context *c) ret = true; static_context = c; +#ifndef TARGET_ANDROID }else {
@@ -1503,6 +1518,7 @@ do_open_tun (struct context *c)"up" , c->c2.es); } +#endif gc_free (&gc);return ret; }
Signature · 1 line
1.7.9.5
Re: [Openvpn-devel] [PATCH 5/5] Emulate persist-tun on Android
Hi,
Quoted 1 line · Arne Schwabe
On Android changing the configuration of tun is not possible. So instead of reconfiguring the tun device, open a new tun device and close the old one if needed
I'm not sure I like this patch. Wouldn't it be easier to tackle this in options.c with an
#ifdef TARGET_ANDROID
msg(M_WARN, "notice: android cannot do --persist-tun, ignoring statement");#else
... old code here
#endif
(if you have to reopen the tun anyway) - or does persist-tun have other side effects that I'm overlooking?
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]...Re: [Openvpn-devel] [PATCH 5/5] Emulate persist-tun on Android
Am 25.04.13 20:58, schrieb Gert Doering:
Quoted 7 lines
Hi,
Quoted 1 line · Arne Schwabe
On Android changing the configuration of tun is not possible. So instead of reconfiguring the tun device, open a new tun device and close the old one if needed
I'm not sure I like this patch. Wouldn't it be easier to tackle this in
options.cwith an
Quoted 9 lines
#ifdef TARGET_ANDROID msg(M_WARN, "notice: android cannot do --persist-tun, ignoring statement");#else
... old code here
#endif(if you have to reopen the tun anyway) - or does persist-tun have other side effects that I'm overlooking?
Yes. Without persist-tun openvpn will close on disconnect and open tun on reconnect, i.e. allowing traffic to pass over the unecrypted channel. With persist-tun tun will be kept open and not allowing traffic to pass. Reconfiguring the interface on Android has be done by the close/open tun dance this patch does.
Arne