Add remote-count and remote-entry query via management
PATCH 1/2 Add remote-count and remote-entry query via management
From: Selva Nair <[email protected]...>
Selecting the remote host via the management iterface (management-query-remote) provides a restrictive user experience as there is no easy way to tabulate all available remote entries and show a list to the user to choose from. Fix that.
Two new commands for querying the management interface are added:
(i) remote-entry-count : returns the number of remotes specified in the config file. Example result:
>REMOTE-ENTRY-COUNT:10
(ii) remote-entry-get index : returns the remote entry at index in
the form index,host,port,protocol. Example result for index = 2:
>REMOTE-ENTRY:2,ovpn.example.com,1194,udp
See also management-notes.txt
--- Changes.rst | 5 ++++ doc/management-notes.txt | 22 +++++++++++++++++ src/openvpn/init.c | 36 ++++++++++++++++++++++++++++ src/openvpn/manage.c | 52 ++++++++++++++++++++++++++++++++++++++++ src/openvpn/manage.h | 3 ++- 5 files changed, 117 insertions(+), 1 deletion(-)
Changes.rst +5 -0
@@ -4,6 +4,11 @@ Overview of changes in 2.6 New features ------------ +New management commands to enumerate and list remote entries + Use ``remote-entry-count`` and ``remote-entry-get index`` + commands from the management interface to get the number of + remote entries and the entry at index respectively. + Keying Material Exporters (RFC 5705) based key generation As part of the cipher negotiation OpenVPN will automatically prefer the RFC5705 based key material generation to the current custom
doc/management-notes.txt +22 -0
@@ -897,6 +897,28 @@ the 10.0.0.0/8 netblock is allowed: 10.10.0.1. Also, the client may not interact with external IP addresses using an "unknown" protocol (i.e. one that is not IPv4 or ARP). +COMMAND -- remote-entry-count (OpenVPN 2.6+ management version > 3) +------------------------------------------------------------------- + +Retrieve available number of remote host/port entries + +Example: + + remote-entry-count + >REMOTE-ENTRY-COUNT:5 + +COMMAND -- remote-entry-get (OpenVPN 2.6+ management version > 3) +------------------------------------------------------------------ + +Retrieve remote entry (host, port and protocol) by index. + +Example: + + remote-entgry-get 1 + REMOTE-ENTRY:1,vpn.example.com,1194,udp + +The protocol could be tcp-client or udp on client. + COMMAND -- remote (OpenVPN AS 2.1.5/OpenVPN 2.3 or higher) --------------------------------------------
src/openvpn/init.c +36 -0
@@ -330,6 +330,41 @@ management_callback_send_cc_message(void *arg,return status; } +static bool +management_callback_remote_entry (void *arg,unsigned *count,char **remote) +{ +assert (arg); +assert (count); + +struct context *c = (struct context *) arg; +struct connection_list *l = c->options.connection_list; +bool ret = true; + +if (!remote)/* query is for the count of entries */ + { + *count = l->len; + } +else if (*count < l->len)/* the query is for entry with index = count */ + { +struct connection_entry *ce = l->array[*count]; +const char *proto =proto2ascii (ce->proto, ce->af, false); + +/* space for output including 2 commas and a nul */ +int len =strlen (ce->remote) +strlen (ce->remote_port) +strlen (proto) +2 +1 ; +char *out =malloc (len); +check_malloc_return (out); + +openvpn_snprintf (out, len,"%s,%s,%s" , ce->remote, ce->remote_port, proto); + *remote = out; + } +else + { + ret = false; +msg (M_WARN ,"Invalid arguments in management query for remote entry: count = %u" , *count); + } +return ret; +} +static bool management_callback_remote_cmd (void *arg,const char **p) {
@@ -3944,6 +3979,7 @@ init_management_callback_p2p(struct context *c)#ifdef TARGET_ANDROID cb.network_change = management_callback_network_change;#endif + cb.remote_entry = management_callback_remote_entry; management_set_callback(management, &cb); }#endif
src/openvpn/manage.c +52 -0
70 lines not on this page · raw message
src/openvpn/manage.h +2 -1
@@ -31,7 +31,7 @@#include "socket.h" #include "mroute.h" -#define MANAGEMENT_VERSION 3 +#define MANAGEMENT_VERSION 4#define MANAGEMENT_N_PASSWORD_RETRIES 3#define MANAGEMENT_LOG_HISTORY_INITIAL_SIZE 100#define MANAGEMENT_ECHO_BUFFER_SIZE 100
@@ -186,6 +186,7 @@ struct management_callback#ifdef TARGET_ANDROID int (*network_change)(void *arg,bool samenetwork);#endif +bool (*remote_entry) (void *arg,unsigned *count,char **remote); };/*
Signature · 1 line
2.20.1
PATCH 2/2 Permit unlimited connection entries and remotes
From: Selva Nair <[email protected]...>
Currently we allow a max of 64 connection entries and remotes. A larger number would allow users with 100's of independent config files for different end points of same provider to consolidate them to connection entries.
--- Changes.rst | 2 ++ src/openvpn/options.c | 34 ++++++++++++++++++++++++++++------ src/openvpn/options.h | 6 ++++-- 3 files changed, 34 insertions(+), 8 deletions(-)
Changes.rst +2 -0
@@ -4,6 +4,8 @@ Overview of changes in 2.6 New features ------------ +Support unlimited number of connection entries and remote entries + New management commands to enumerate and list remote entries Use ``remote-entry-count`` and ``remote-entry-get index`` commands from the management interface to get the number of
src/openvpn/options.c +28 -6
@@ -889,6 +889,14 @@ init_options(struct options *o, const bool init_gc)void uninit_options (struct options *o) { +if (o->connection_list) { +free (o->connection_list->array); +CLEAR (*o->connection_list); + } +if (o->remote_list) { +free (o->remote_list->array); +CLEAR (*o->remote_list); + }if (o->gc_owned) {gc_free (&o->gc);
@@ -1947,10 +1955,17 @@ alloc_connection_entry(struct options *options, const int msglevel)struct connection_list *l =alloc_connection_list_if_undef (options);struct connection_entry *e; -if (l->len >=CONNECTION_LIST_SIZE ) +if (l->len == l->capacity) { -msg (msglevel,"Maximum number of 'connection' options (%d) exceeded" ,CONNECTION_LIST_SIZE ); -return NULL ; +int capacity = l->capacity +CONNECTION_LIST_SIZE ; +struct connection_entry **ce =realloc (l->array, capacity*sizeof (struct connection_entry *)); +if (ce ==NULL ) + { +msg (msglevel,"Unable to process more connection options: out of memory. Number of entries = %d" , l->len); +return NULL ; + } + l->array = ce; + l->capacity = capacity; } ALLOC_OBJ_GC(e, struct connection_entry, &options->gc); l->array[l->len++] = e;
@@ -1973,10 +1988,17 @@ alloc_remote_entry(struct options *options, const int msglevel)struct remote_list *l =alloc_remote_list_if_undef (options);struct remote_entry *e; -if (l->len >=CONNECTION_LIST_SIZE ) +if (l->len == l->capacity) { -msg (msglevel,"Maximum number of 'remote' options (%d) exceeded" ,CONNECTION_LIST_SIZE ); -return NULL ; +int capacity = l->capacity +CONNECTION_LIST_SIZE ; +struct remote_entry **re =realloc (l->array, capacity*sizeof (struct remote_entry *)); +if (re ==NULL ) + { +msg (msglevel,"Unable to process more remote options: out of memory. Number of entries = %d" , l->len); +return NULL ; + } + l->array = re; + l->capacity = capacity; } ALLOC_OBJ_GC(e, struct remote_entry, &options->gc); l->array[l->len++] = e;
src/openvpn/options.h +4 -2
@@ -168,15 +168,17 @@ struct remote_entrystruct connection_list { +int capacity;int len;int current; -struct connection_entry *array[CONNECTION_LIST_SIZE ]; +struct connection_entry **array; };struct remote_list { +int capacity;int len; -struct remote_entry *array[CONNECTION_LIST_SIZE ]; +struct remote_entry **array; };enum vlan_acceptable_frames
Signature · 1 line
2.20.1
Re: [Openvpn-devel] [PATCH 2/2] Permit unlimited connection entries and remotes
Hi,
Quoted 8 lines · On Wed, Aug 25, 2021 at 12:01:22AM -0400, [email protected]... wrote:
From: Selva Nair <[email protected]...>
Currently we allow a max of 64 connection entries and remotes. A larger number would allow users with 100's of independent config files for different end points of same provider to consolidate them to connection entries.
Signed-off-by Selva Nair <[email protected]...>
The combination of this with the previous patch sounds quite useful (= no longer distribute multiple different .ovpn for tcp/udp/... but have them all in the same file).
I assume support in the UI is also already brewing :-)
There is one catch: I assume that this conflicts heavily with the SRV patch (due to that one also changing connection entry handling), and the SRV patch is overdue for final review and merging - thus, when coming back to *this* patch, it might need a rebase.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH 2/2] Permit unlimited connection entries and remotes
Hi,
Quoted 10 lines · Gert Doering
Hi,
Quoted 7 lines · On Wed, Aug 25, 2021 at 12:01:22AM -0400, [email protected]... wrote:
From: Selva Nair <[email protected]...>
Currently we allow a max of 64 connection entries and remotes. A larger number would allow users with 100's of independent config files for different end points of same provider to consolidate them to connection entries.
Quoted 8 lines
Quoted 1 line
Signed-off-by Selva Nair <[email protected]...>The combination of this with the previous patch sounds quite useful (= no longer distribute multiple different .ovpn for tcp/udp/... but have them all in the same file).
I assume support in the UI is also already brewing :-)
Yes, that's the plan..
Quoted 4 lines
There is one catch: I assume that this conflicts heavily with the SRV patch (due to that one also changing connection entry handling), and the SRV patch is overdue for final review and merging - thus, when coming back to *this* patch, it might need a rebase.
I think, either way it would be a simple rebase. This one against the SRV patch or the other way.
Any idea why "options_preprocess_verify_ce()", which is called for each connection-entry, contains many checks that apply to common, non-ce-specific options? This causes some warnings like "using management without password is strongly discouraged.." printed once for every connection entry -- 100 times if you have 100 entries.
Selva
Quoted 27 lines
src/openvpn/init.c +25
-0+static bool +management_callback_remote_entry (void *arg,unsigned *count,char **remote) +{ +assert (arg); +assert (count); + +struct context *c = (struct context *) arg; +struct connection_list *l = c->options.connection_list; +bool ret = true; + +if (!remote)/* query is for the count of entries */ + { + *count = l->len; + } +else if (*count < l->len)/* the query is for entry with index = count */ + { +struct connection_entry *ce = l->array[*count]; +const char *proto =proto2ascii (ce->proto, ce->af, false); + +/* space for output including 2 commas and a nul */ +int len =strlen (ce->remote) +strlen (ce->remote_port) +strlen (proto) +2 +1 ; +char *out =malloc (len); +check_malloc_return (out); + +openvpn_snprintf (out, len,"%s,%s,%s" , ce->remote, ce->remote_port, proto);
src/openvpn/init.c management_callback_send_cc_message(void *arg, · line 367
Quoted 10 lines
src/openvpn/init.c +10
-0+ *remote = out; + } +else + { + ret = false; +msg (M_WARN ,"Invalid arguments in management query for remote entry: count = %u" , *count); + } +return ret; +} +
I am not sure mixing two related but different functions into one function has any real advantages. A function that just returns the count would simplify that function and this function.
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 840
Quoted 7 lines
src/openvpn/manage.c +7
-0+static void +man_remote_entry_count (struct management *man) +{ +unsigned count =0 ; +if (man->persist.callback.remote_entry) + { + (*man->persist.callback.remote_entry)(man->persist.callback.arg, &count,NULL );
The return value is not used here, this might upset some compilers.
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 847
Quoted 7 lines
src/openvpn/manage.c +7
-0+msg (M_CLIENT ,">REMOTE-ENTRY-COUNT:%u" , count); + } +else + { +msg (M_CLIENT ,"ERROR: The remote-entry-count command is not supported by the current daemon mode" ); + } +}
At some point we should do a helper function that does this boilerplate code that we copy&paste here over and over.
Arne
Hi
Quoted 38 lines · Arne Schwabe
Review
Quoted 4 lines
(quoted diff) +2
-0+static bool +management_callback_remote_entry(void *arg, unsigned *count, char**remote)
src/openvpn/init.c management_callback_send_cc_message(void *arg,
Quoted 13 lines
src/openvpn/init.c +13
-0+{ +assert (arg); +assert (count); + +struct context *c = (struct context *) arg; +struct connection_list *l = c->options.connection_list; +bool ret = true; + +if (!remote)/* query is for the count of entries */ + { + *count = l->len; + } +else if (*count < l->len)/* the query is for entry with index = count */
src/openvpn/init.c management_callback_send_cc_message(void *arg,
Quoted 6 lines
src/openvpn/init.c +6
-0+ { +struct connection_entry *ce = l->array[*count]; +const char *proto =proto2ascii (ce->proto, ce->af, false); + +/* space for output including 2 commas and a nul */ + int len = strlen(ce->remote) + strlen(ce->remote_port) +strlen(proto) + 2 + 1;
src/openvpn/init.c management_callback_send_cc_message(void *arg,
Quoted 4 lines
src/openvpn/init.c +4
-0+char *out =malloc (len); +check_malloc_return (out); + + openvpn_snprintf(out, len, "%s,%s,%s", ce->remote,
ce->remote_port, proto);src/openvpn/init.c management_callback_send_cc_message(void *arg,
Quoted 6 lines
src/openvpn/init.c +6
-0+ *remote = out; + } +else + { + ret = false; + msg(M_WARN, "Invalid arguments in management query for remoteentry: count = %u", *count);
Quoted 9 lines
src/openvpn/init.c management_callback_send_cc_message(void *arg, · line 367
Quoted 4 lines
src/openvpn/init.c +4
-0+ } +return ret; +} +I am not sure mixing two related but different functions into one function has any real advantages. A function that just returns the count would simplify that function and this function.
Makes sense. v2 is coming.
Quoted 10 lines
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 848
Quoted 7 lines
src/openvpn/manage.c +7
-0+static void +man_remote_entry_count (struct management *man) +{ +unsigned count =0 ; +if (man->persist.callback.remote_entry) + { +(*man->persist.callback.remote_entry)(man->persist.callback.arg, &count, NULL);
Quoted 2 lines
The return value is not used here, this might upset some compilers.
The above will fix that too.
Quoted 6 lines
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index)
Quoted 6 lines
src/openvpn/manage.c +5
-0+msg (M_CLIENT ,">REMOTE-ENTRY-COUNT:%u" , count); + } +else + { + msg(M_CLIENT, "ERROR: The remote-entry-count command is not
Quoted 7 lines
supported by the current daemon mode");
Review
Quoted 2 lines
(quoted diff) +2
-0+ } +}At some point we should do a helper function that does this boilerplate code that we copy&paste here over and over.
Actually this else could be possibly eliminated as, in this case, the callback is not conditionally compiled in. Unlike things like pkcs11-id support. Will check and simplify.
Thanks,
Selva
Quoted 6 lines
Actually this else could be possibly eliminated as, in this case, the callback is not conditionally compiled in. Unlike things like pkcs11-id support. Will check and simplify.
I think in client vs server mode the management interface is still different enough that many of these are actually needed.
Arne
PATCH v2 1/3 Add remote-count and remote-entry query via management
In reply to [email protected]...From: Selva Nair <[email protected]...>
Selecting the remote host via the management iterface (management-query-remote) provides a restrictive user experience as there is no easy way to tabulate all available remote entries and show a list to the user to choose from. Fix that.
Two new commands for querying the management interface are added:
(i) remote-entry-count : returns the number of remotes specified in the config file. Example result:
>REMOTE-ENTRY-COUNT:10
(ii) remote-entry-get index : returns the remote entry at index in
the form index,host,port,protocol. Example result for index = 2:
>REMOTE-ENTRY:2,ovpn.example.com,1194,udp
v2: use independent callback functions for the two commands
See also management-notes.txt
--- Changes.rst | 5 ++++ doc/management-notes.txt | 22 +++++++++++++++++ src/openvpn/init.c | 43 ++++++++++++++++++++++++++++++++ src/openvpn/manage.c | 53 ++++++++++++++++++++++++++++++++++++++++ src/openvpn/manage.h | 4 ++- 5 files changed, 126 insertions(+), 1 deletion(-)
Changes.rst +5 -0
@@ -4,6 +4,11 @@ Overview of changes in 2.6 New features ------------ +New management commands to enumerate and list remote entries + Use ``remote-entry-count`` and ``remote-entry-get index`` + commands from the management interface to get the number of + remote entries and the entry at index respectively. + Keying Material Exporters (RFC 5705) based key generation As part of the cipher negotiation OpenVPN will automatically prefer the RFC5705 based key material generation to the current custom
doc/management-notes.txt +22 -0
@@ -897,6 +897,28 @@ the 10.0.0.0/8 netblock is allowed: 10.10.0.1. Also, the client may not interact with external IP addresses using an "unknown" protocol (i.e. one that is not IPv4 or ARP). +COMMAND -- remote-entry-count (OpenVPN 2.6+ management version > 3) +------------------------------------------------------------------- + +Retrieve available number of remote host/port entries + +Example: + + remote-entry-count + >REMOTE-ENTRY-COUNT:5 + +COMMAND -- remote-entry-get (OpenVPN 2.6+ management version > 3) +------------------------------------------------------------------ + +Retrieve remote entry (host, port and protocol) by index. + +Example: + + remote-entgry-get 1 + REMOTE-ENTRY:1,vpn.example.com,1194,udp + +The protocol could be tcp-client or udp on client. + COMMAND -- remote (OpenVPN AS 2.1.5/OpenVPN 2.3 or higher) --------------------------------------------
src/openvpn/init.c +43 -0
55 lines not on this page · raw message
src/openvpn/manage.c +53 -0
71 lines not on this page · raw message
src/openvpn/manage.h +3 -1
@@ -31,7 +31,7 @@#include "socket.h" #include "mroute.h" -#define MANAGEMENT_VERSION 3 +#define MANAGEMENT_VERSION 4#define MANAGEMENT_N_PASSWORD_RETRIES 3#define MANAGEMENT_LOG_HISTORY_INITIAL_SIZE 100#define MANAGEMENT_ECHO_BUFFER_SIZE 100
@@ -186,6 +186,8 @@ struct management_callback#ifdef TARGET_ANDROID int (*network_change)(void *arg,bool samenetwork);#endif +unsigned int (*remote_entry_count)(void *arg); +bool (*remote_entry_get)(void *arg,unsigned int index,char **remote); };/*
Signature · 1 line
2.20.1
PATCH v2 2/3 Permit unlimited connection entries and remotes
From: Selva Nair <[email protected]...>
Currently we allow a max of 64 connection entries and remotes. A larger number would allow users with 100's of independent config files for different end points of same provider to consolidate them to connection entries.
--- Changes.rst | 2 ++ src/openvpn/options.c | 34 ++++++++++++++++++++++++++++------ src/openvpn/options.h | 6 ++++-- 3 files changed, 34 insertions(+), 8 deletions(-)
Changes.rst +2 -0
@@ -4,6 +4,8 @@ Overview of changes in 2.6 New features ------------ +Support unlimited number of connection entries and remote entries + New management commands to enumerate and list remote entries Use ``remote-entry-count`` and ``remote-entry-get index`` commands from the management interface to get the number of
src/openvpn/options.c +28 -6
@@ -889,6 +889,14 @@ init_options(struct options *o, const bool init_gc)void uninit_options (struct options *o) { +if (o->connection_list) { +free (o->connection_list->array); +CLEAR (*o->connection_list); + } +if (o->remote_list) { +free (o->remote_list->array); +CLEAR (*o->remote_list); + }if (o->gc_owned) {gc_free (&o->gc);
@@ -1947,10 +1955,17 @@ alloc_connection_entry(struct options *options, const int msglevel)struct connection_list *l =alloc_connection_list_if_undef (options);struct connection_entry *e; -if (l->len >=CONNECTION_LIST_SIZE ) +if (l->len == l->capacity) { -msg (msglevel,"Maximum number of 'connection' options (%d) exceeded" ,CONNECTION_LIST_SIZE ); -return NULL ; +int capacity = l->capacity +CONNECTION_LIST_SIZE ; +struct connection_entry **ce =realloc (l->array, capacity*sizeof (struct connection_entry *)); +if (ce ==NULL ) + { +msg (msglevel,"Unable to process more connection options: out of memory. Number of entries = %d" , l->len); +return NULL ; + } + l->array = ce; + l->capacity = capacity; } ALLOC_OBJ_GC(e, struct connection_entry, &options->gc); l->array[l->len++] = e;
@@ -1973,10 +1988,17 @@ alloc_remote_entry(struct options *options, const int msglevel)struct remote_list *l =alloc_remote_list_if_undef (options);struct remote_entry *e; -if (l->len >=CONNECTION_LIST_SIZE ) +if (l->len == l->capacity) { -msg (msglevel,"Maximum number of 'remote' options (%d) exceeded" ,CONNECTION_LIST_SIZE ); -return NULL ; +int capacity = l->capacity +CONNECTION_LIST_SIZE ; +struct remote_entry **re =realloc (l->array, capacity*sizeof (struct remote_entry *)); +if (re ==NULL ) + { +msg (msglevel,"Unable to process more remote options: out of memory. Number of entries = %d" , l->len); +return NULL ; + } + l->array = re; + l->capacity = capacity; } ALLOC_OBJ_GC(e, struct remote_entry, &options->gc); l->array[l->len++] = e;
src/openvpn/options.h +4 -2
@@ -168,15 +168,17 @@ struct remote_entrystruct connection_list { +int capacity;int len;int current; -struct connection_entry *array[CONNECTION_LIST_SIZE ]; +struct connection_entry **array; };struct remote_list { +int capacity;int len; -struct remote_entry *array[CONNECTION_LIST_SIZE ]; +struct remote_entry **array; };enum vlan_acceptable_frames
Signature · 1 line
2.20.1
Re: [Openvpn-devel] [PATCH v2 2/3] Permit unlimited connection entries and remotes
Hi,
While implementing this feature in the GUI, I have come across some limitations of management-query-remote:
(i) Using a remote selected by the user from a list requires skipping several remotes and accepting when the right one is reached. This is very slow when there are more than a dozen remote entries: about ~1 second per command.
Solution: Extend "remote SKIP" to take an optional parameter to skip "n" entries by one command.
Use of "remote MOD" is not useful here as it does not support change of protocol. It also has some "misbehaviour" due to the way resolved addresses are cached.
(ii) remote-entry-get introduced here needs to be extended to support requesting multiple or all remote entries in one command.
Please ignore the current version. v3 is coming.
Selva
Re: [Openvpn-devel] [PATCH v2 2/3] Permit unlimited connection entries and remotes
Hi,
As this patch set is not getting any attention, I guess the need for this is not clear enough from the commit messages. To be blunt, --management-query-remote is pretty useless the way it stands. Let me explain:
(1) It queries the user with one remote at a time taking about 1 second per query. With 100 remotes, if the user wants to select the 100th one, a UI has to show 100 popups and take ~100 seconds.
So one wants two things in good UI
(i) show a list of all available remotes to the user (ii) have a way to jump to a remote that user chooses
For (i) one could scan the config and make a list but I'll come to why that doesn't work in a minute. Consider (ii) first: we currently have an option to skip remotes one by one or send a MOD request where the host and port can be changed. Skipping one by one is very slow, and MOD doesn't allow change of protocol. So, if the 100th item that user chooses is TCP and all other 99 are UDP, we have to wait until we get prompted with the right one. There are other reasons why MOD doesn't work but I want to keep this mail simple.
Thus, we want a way to skip "N" remotes by one command (say skip 99, get prompted with the 100th which we accept). One of the three patches in this set does that.
Now back to (i) about making a list. For "SKIP N" to work, the UI and the core must have an identical view of the list -- especially the order of entries. If remote-random is in use, the only way to assure that is by making the list by querying the core. Even otherwise independently parsing the list from the config is not the right approach when identity of content is important.
This, hopefully, justifies the patch that allows the UI to query the core for a list of remotes and their indices.
The third patch is to relax the restriction on the number of remote entries and connection lists. Currently it's hard coded to 64, there is no reason why we can't allow 100 or even 1000 remote entries.
From experience, I know that patches that languish stay like that for months if not years. Please, either review and ACK or hate it at first sight and NAK. Or ask for clarification. A patch for the GUI is waiting for the fate of this.
Thanks,
Selva
Quoted 24 lines · Selva Nair
Hi,
While implementing this feature in the GUI, I have come across some limitations of management-query-remote:
(i) Using a remote selected by the user from a list requires skipping several remotes and accepting when the right one is reached. This is very slow when there are more than a dozen remote entries: about ~1 second per command.
Solution: Extend "remote SKIP" to take an optional parameter to skip "n" entries by one command.
Use of "remote MOD" is not useful here as it does not support change of protocol. It also has some "misbehaviour" due to the way resolved addresses are cached.
(ii) remote-entry-get introduced here needs to be extended to support requesting multiple or all remote entries in one command.
Please ignore the current version. v3 is coming.
Selva
PATCH v2 3/3 Use a template for "unsupported management commands" error
In reply to [email protected]...From: Selva Nair <[email protected]...>
The message
"ERROR: The 'foo' commmand is not supported by current daemon mode" is repeatedly used in manage.c. Move it to a function for uniformity in messaging.
--- src/openvpn/manage.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
src/openvpn/manage.c +20 -14
@@ -447,6 +447,12 @@ man_signal(struct management *man, const char *name) } } +static void +man_command_unsupported (const char *command_name) +{ +msg (M_CLIENT ,"ERROR: The '%s' command is not supported by the current daemon mode" , command_name); +} +static void man_status (struct management *man,const int version,struct status_output *so) {
@@ -456,7 +462,7 @@ man_status(struct management *man, const int version, struct status_output *so) }else { -msg (M_CLIENT ,"ERROR: The 'status' command is not supported by the current daemon mode" ); +man_command_unsupported ("status" ); } }
@@ -572,7 +578,7 @@ man_kill(struct management *man, const char *victim) }else { -msg (M_CLIENT ,"ERROR: The 'kill' command is not supported by the current daemon mode" ); +man_command_unsupported ("kill" ); }gc_free (&gc);
@@ -777,7 +783,7 @@ man_net(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The 'net' command is not supported by the current daemon mode" ); +man_command_unsupported ("net" ); } }
@@ -799,7 +805,7 @@ man_send_cc_message(struct management *man, const char *message, const char *par }else { -msg (M_CLIENT ,"ERROR: This command is not supported by the current daemon mode" ); +man_command_unsupported ("cr-repsonse" ); } }#ifdef ENABLE_PKCS11
@@ -842,7 +848,7 @@ man_remote_entry_count(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The remote-entry-count command is not supported by the current daemon mode" ); +man_command_unsupported ("remote-entry-count" ); } }
@@ -865,7 +871,7 @@ man_remote_entry_get(struct management *man, unsigned int index) }else { -msg (M_CLIENT ,"ERROR: The remote-entry command is not supported by the current daemon mode" ); +man_command_unsupported ("remote-entry-get" ); }free (remote);
@@ -956,7 +962,7 @@ in_extra_dispatch(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The client-auth command is not supported by the current daemon mode" ); +man_command_unsupported ("client-auth" ); }break ;
@@ -980,7 +986,7 @@ in_extra_dispatch(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The client-pf command is not supported by the current daemon mode" ); +man_command_unsupported ("client-pf" ); }break ;
@@ -1065,7 +1071,7 @@ man_client_pending_auth(struct management *man, const char *cid_str, }else { -msg (M_CLIENT ,"ERROR: The client-pending-auth command is not supported by the current daemon mode" ); +man_command_unsupported ("client-pending-auth" ); } } }
@@ -1116,7 +1122,7 @@ man_client_deny(struct management *man, const char *cid_str, const char *kid_str }else { -msg (M_CLIENT ,"ERROR: The client-deny command is not supported by the current daemon mode" ); +man_command_unsupported ("client-deny" ); } } }
@@ -1141,7 +1147,7 @@ man_client_kill(struct management *man, const char *cid_str, const char *kill_ms }else { -msg (M_CLIENT ,"ERROR: The client-kill command is not supported by the current daemon mode" ); +man_command_unsupported ("client-kill" ); } } }
@@ -1156,7 +1162,7 @@ man_client_n_clients(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The nclients command is not supported by the current daemon mode" ); +man_command_unsupported ("nclients" ); } }
@@ -1280,7 +1286,7 @@ man_proxy(struct management *man, const char **p) }else { -msg (M_CLIENT ,"ERROR: The proxy command is not supported by the current daemon mode" ); +man_command_unsupported ("proxy" ); } }
@@ -1301,7 +1307,7 @@ man_remote(struct management *man, const char **p) }else { -msg (M_CLIENT ,"ERROR: The remote command is not supported by the current daemon mode" ); +man_command_unsupported ("remote" ); } }
Signature · 1 line
2.20.1
Re: [Openvpn-devel] [PATCH v2 3/3] Use a template for "unsupported management commands" error
Am 25.08.21 um 23:02 schrieb [email protected]...:
Quoted 7 lines
From: Selva Nair <[email protected]...>
The message
"ERROR: The 'foo' commmand is not supported by current daemon mode" is repeatedly used inmanage.c. Move it to a function for uniformity in messaging.
This patch currently has a conflict since PF code was removed. I will let Gert decide if he wants to adjust the patch or a rebased v3.
Arne
PATCH v3 1/3 Add remote-count and remote-entry query via management
In reply to [email protected]...From: Selva Nair <[email protected]...>
Selecting the remote host via the management iterface (management-query-remote) provides a restrictive user experience as there is no easy way to tabulate all available remote entries and show a list to the user to choose from. Fix that.
Two new commands for querying the management interface are added:
(i) remote-entry-count : returns the number of remotes specified in the config file. Example result:
10
END
(ii) remote-entry-get i [j]: returns the remote entry at index i
in the form index,host,port,protocol. Or, if j is present all entries from index i to j-1 are returned, one per line.
Example result for i = 2:
2,ovpn.example.com,1194,udp
END
Example result for i = 2, j = 4
2,ovpn.example.com,1194,udp
3,ovpn.example.com,443,tcp-client
END
remote-entry-get all: returns all remote entries.
v2: use independent callback functions for the two commands
v3: return results as 0 or more lines terminated by END, as done
for all other similar commands. v1 was fashioned after pkcs11-id-count and pkcs11-id-get which uses a format not consistent with the rest of the management commands.
See also management-notes.txt
--- Changes.rst | 5 +++ doc/management-notes.txt | 60 ++++++++++++++++++++++++++++++++++ src/openvpn/init.c | 44 +++++++++++++++++++++++++ src/openvpn/manage.c | 70 ++++++++++++++++++++++++++++++++++++++++ src/openvpn/manage.h | 4 ++- 5 files changed, 182 insertions(+), 1 deletion(-)
Changes.rst +5 -0
@@ -4,6 +4,11 @@ Overview of changes in 2.6 New features ------------ +New management commands to enumerate and list remote entries + Use ``remote-entry-count`` and ``remote-entry-get`` + commands from the management interface to get the number of + remote entries and the entries themselves. + Keying Material Exporters (RFC 5705) based key generation As part of the cipher negotiation OpenVPN will automatically prefer the RFC5705 based key material generation to the current custom
doc/management-notes.txt +60 -0
66 lines not on this page · raw message
src/openvpn/init.c +44 -0
56 lines not on this page · raw message
src/openvpn/manage.c +70 -0
88 lines not on this page · raw message
src/openvpn/manage.h +3 -1
@@ -31,7 +31,7 @@#include "socket.h" #include "mroute.h" -#define MANAGEMENT_VERSION 3 +#define MANAGEMENT_VERSION 4#define MANAGEMENT_N_PASSWORD_RETRIES 3#define MANAGEMENT_LOG_HISTORY_INITIAL_SIZE 100#define MANAGEMENT_ECHO_BUFFER_SIZE 100
@@ -186,6 +186,8 @@ struct management_callback#ifdef TARGET_ANDROID int (*network_change)(void *arg,bool samenetwork);#endif +unsigned int (*remote_entry_count)(void *arg); +bool (*remote_entry_get)(void *arg,unsigned int index,char **remote); };/*
Signature · 1 line
2.20.1
PATCH v3 2/3 Permit unlimited connection entries and remotes
From: Selva Nair <[email protected]...>
Currently we allow a max of 64 connection entries and remotes. A larger number would allow users with 100's of independent config files for different end points of same provider to consolidate them to connection entries.
v2,v3: no change
--- Changes.rst | 2 ++ src/openvpn/options.c | 34 ++++++++++++++++++++++++++++------ src/openvpn/options.h | 6 ++++-- 3 files changed, 34 insertions(+), 8 deletions(-)
Changes.rst +2 -0
@@ -4,6 +4,8 @@ Overview of changes in 2.6 New features ------------ +Support unlimited number of connection entries and remote entries + New management commands to enumerate and list remote entries Use ``remote-entry-count`` and ``remote-entry-get`` commands from the management interface to get the number of
src/openvpn/options.c +28 -6
@@ -888,6 +888,14 @@ init_options(struct options *o, const bool init_gc)void uninit_options (struct options *o) { +if (o->connection_list) { +free (o->connection_list->array); +CLEAR (*o->connection_list); + } +if (o->remote_list) { +free (o->remote_list->array); +CLEAR (*o->remote_list); + }if (o->gc_owned) {gc_free (&o->gc);
@@ -1946,10 +1954,17 @@ alloc_connection_entry(struct options *options, const int msglevel)struct connection_list *l =alloc_connection_list_if_undef (options);struct connection_entry *e; -if (l->len >=CONNECTION_LIST_SIZE ) +if (l->len == l->capacity) { -msg (msglevel,"Maximum number of 'connection' options (%d) exceeded" ,CONNECTION_LIST_SIZE ); -return NULL ; +int capacity = l->capacity +CONNECTION_LIST_SIZE ; +struct connection_entry **ce =realloc (l->array, capacity*sizeof (struct connection_entry *)); +if (ce ==NULL ) + { +msg (msglevel,"Unable to process more connection options: out of memory. Number of entries = %d" , l->len); +return NULL ; + } + l->array = ce; + l->capacity = capacity; } ALLOC_OBJ_GC(e, struct connection_entry, &options->gc); l->array[l->len++] = e;
@@ -1972,10 +1987,17 @@ alloc_remote_entry(struct options *options, const int msglevel)struct remote_list *l =alloc_remote_list_if_undef (options);struct remote_entry *e; -if (l->len >=CONNECTION_LIST_SIZE ) +if (l->len == l->capacity) { -msg (msglevel,"Maximum number of 'remote' options (%d) exceeded" ,CONNECTION_LIST_SIZE ); -return NULL ; +int capacity = l->capacity +CONNECTION_LIST_SIZE ; +struct remote_entry **re =realloc (l->array, capacity*sizeof (struct remote_entry *)); +if (re ==NULL ) + { +msg (msglevel,"Unable to process more remote options: out of memory. Number of entries = %d" , l->len); +return NULL ; + } + l->array = re; + l->capacity = capacity; } ALLOC_OBJ_GC(e, struct remote_entry, &options->gc); l->array[l->len++] = e;
src/openvpn/options.h +4 -2
@@ -168,15 +168,17 @@ struct remote_entrystruct connection_list { +int capacity;int len;int current; -struct connection_entry *array[CONNECTION_LIST_SIZE ]; +struct connection_entry **array; };struct remote_list { +int capacity;int len; -struct remote_entry *array[CONNECTION_LIST_SIZE ]; +struct remote_entry **array; };enum vlan_acceptable_frames
Signature · 1 line
2.20.1
Re: [Openvpn-devel] [PATCH v3 2/3] Permit unlimited connection entries and remotes
Am 08.09.21 um 00:31 schrieb [email protected]...:
Quoted 10 lines
From: Selva Nair <[email protected]...>
Currently we allow a max of 64 connection entries and remotes. A larger number would allow users with 100's of independent config files for different end points of same provider to consolidate them to connection entries.
v2,v3: no change
Signed-off-by Selva Nair <[email protected]...>
We are now increasing by multiple of 64 entries. While a bit wasteful and we could have used smaller increments, the memory lost here is not really a concern.
Arne
[Openvpn-devel] [PATCH applied] Re: Permit unlimited connection entries and remotes
In reply to [email protected]...The patch needed a bit of convincing to go in (context change in options.h, and braces-in-the-wrong-line). Fixed.
Tested with a config with 200 somewhat random remote lines - without the patch
Options error: Maximum number of 'remote' options (64) exceeded
and with the patch "it just works"...
remote-entry-count
206
END
remote-entry-get 200 999
200,1195.server.org,1195,udp
201,1196.server.org,1196,udp
202,1197.server.org,1197,udp
203,1198.server.org,1198,udp
204,1199.server.org,1199,udp
205,1200.server.org,1200,udp
END(I did not try 100s of <connection>)
That said, I'm not convinced we really need to print
2022-12-27 10:16:56 WARNING: Using --management on a TCP port WITHOUT passwords is STRONGLY discouraged and considered insecure
for every single --remote... but that's a different issue, not caused by *this* patch.
Your patch has been applied to the master branch.
commit 4954beb618e8bf2dc756019d5a36040d791a8f38 (master) commit ceba452ee44439b426b786325db2b4e1b1c8b663 (release/2.6)
Author: Selva Nair Date: Tue Sep 7 18:31:25 2021 -0400
Permit unlimited connection entries and remotes
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22816.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 3/3 Use a template for "unsupported management commands" error
In reply to [email protected]...From: Selva Nair <[email protected]...>
The message
"ERROR: The 'foo' commmand is not supported by current daemon mode" is repeatedly used in manage.c. Move it to a function for uniformity in messaging.
v3, v3: no change
--- src/openvpn/manage.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
src/openvpn/manage.c +20 -14
@@ -447,6 +447,12 @@ man_signal(struct management *man, const char *name) } } +static void +man_command_unsupported (const char *command_name) +{ +msg (M_CLIENT ,"ERROR: The '%s' command is not supported by the current daemon mode" , command_name); +} +static void man_status (struct management *man,const int version,struct status_output *so) {
@@ -456,7 +462,7 @@ man_status(struct management *man, const int version, struct status_output *so) }else { -msg (M_CLIENT ,"ERROR: The 'status' command is not supported by the current daemon mode" ); +man_command_unsupported ("status" ); } }
@@ -572,7 +578,7 @@ man_kill(struct management *man, const char *victim) }else { -msg (M_CLIENT ,"ERROR: The 'kill' command is not supported by the current daemon mode" ); +man_command_unsupported ("kill" ); }gc_free (&gc);
@@ -777,7 +783,7 @@ man_net(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The 'net' command is not supported by the current daemon mode" ); +man_command_unsupported ("net" ); } }
@@ -799,7 +805,7 @@ man_send_cc_message(struct management *man, const char *message, const char *par }else { -msg (M_CLIENT ,"ERROR: This command is not supported by the current daemon mode" ); +man_command_unsupported ("cr-repsonse" ); } }#ifdef ENABLE_PKCS11
@@ -843,7 +849,7 @@ man_remote_entry_count(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The remote-entry-count command is not supported by the current daemon mode" ); +man_command_unsupported ("remote-entry-count" ); } }
@@ -884,7 +890,7 @@ man_remote_entry_get(struct management *man, const char *p1, const char *p2) }else { -msg (M_CLIENT ,"ERROR: The remote-entry command is not supported by the current daemon mode" ); +man_command_unsupported ("remote-entry-get" ); } }
@@ -973,7 +979,7 @@ in_extra_dispatch(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The client-auth command is not supported by the current daemon mode" ); +man_command_unsupported ("client-auth" ); }break ;
@@ -997,7 +1003,7 @@ in_extra_dispatch(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The client-pf command is not supported by the current daemon mode" ); +man_command_unsupported ("client-pf" ); }break ;
@@ -1082,7 +1088,7 @@ man_client_pending_auth(struct management *man, const char *cid_str, }else { -msg (M_CLIENT ,"ERROR: The client-pending-auth command is not supported by the current daemon mode" ); +man_command_unsupported ("client-pending-auth" ); } } }
@@ -1133,7 +1139,7 @@ man_client_deny(struct management *man, const char *cid_str, const char *kid_str }else { -msg (M_CLIENT ,"ERROR: The client-deny command is not supported by the current daemon mode" ); +man_command_unsupported ("client-deny" ); } } }
@@ -1158,7 +1164,7 @@ man_client_kill(struct management *man, const char *cid_str, const char *kill_ms }else { -msg (M_CLIENT ,"ERROR: The client-kill command is not supported by the current daemon mode" ); +man_command_unsupported ("client-kill" ); } } }
@@ -1173,7 +1179,7 @@ man_client_n_clients(struct management *man) }else { -msg (M_CLIENT ,"ERROR: The nclients command is not supported by the current daemon mode" ); +man_command_unsupported ("nclients" ); } }
@@ -1297,7 +1303,7 @@ man_proxy(struct management *man, const char **p) }else { -msg (M_CLIENT ,"ERROR: The proxy command is not supported by the current daemon mode" ); +man_command_unsupported ("proxy" ); } }
@@ -1318,7 +1324,7 @@ man_remote(struct management *man, const char **p) }else { -msg (M_CLIENT ,"ERROR: The remote command is not supported by the current daemon mode" ); +man_command_unsupported ("remote" ); } }
Signature · 1 line
2.20.1
Re: [Openvpn-devel] [PATCH v3 3/3] Use a template for "unsupported management commands" error
Am 08.09.21 um 00:31 schrieb [email protected]...:
Quoted 8 lines
From: Selva Nair <[email protected]...>
The message
"ERROR: The 'foo' commmand is not supported by current daemon mode" is repeatedly used inmanage.c. Move it to a function for uniformity in messaging.v3, v3: no change
This patch currently has a conflict since PF code was removed. I will let Gert decide if he wants to adjust the patch or a rebased v4.
Re: [Openvpn-devel] [PATCH v3 3/3] Use a template for "unsupported management commands" error
Hi,
Quoted 8 lines · Arne Schwabe
Am 08.09.21 um 00:31 schrieb [email protected]...:
Quoted 7 lines
From: Selva Nair <[email protected]...>
The message
"ERROR: The 'foo' commmand is not supported by current daemon mode" is repeatedly used inmanage.c. Move it to a function for uniformity in messaging.
Quoted 6 lines
Quoted 1 line
v3, v3: no change
Acked-by Arne Schwabe <[email protected]...>This patch currently has a conflict since PF code was removed. I will let Gert decide if he wants to adjust the patch or a rebased v4.
This patch set was left way too long out in the sun to dry... I will adjust this ("remove the hunk that deals with client-pf"), trivial enough.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...[Openvpn-devel] [PATCH applied] Re: Use a template for 'unsupported management commands' error
In reply to [email protected]...Removed the hunk related to "client-pf". The rest went in just fine.
Verified with my favourite "why does this not work at --management-hold time?" new command :-)
Quoted 1 line
HOLD:Waiting for hold release:0
remote-entry-count
ERROR: The 'remote-entry-count' command is not supported by the current daemon mode
Your patch has been applied to the master and release/2.6 branch.
commit caf1b9030f28a984a0e12dd87b128b428d3683f0 (master) commit cad95bcc564e06dc53ec88e9ec4f529146569c0d (release/2.6)
Author: Selva Nair Date: Tue Sep 7 18:31:26 2021 -0400
Use a template for 'unsupported management commands' error
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22814.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Am 08.09.21 um 00:31 schrieb [email protected]...:
Quoted 3 lines
From: Selva Nair <[email protected]...>
Selecting the remote host via the management iterface
*sigh* I reviewed the v2 instead of the v3 but the typo is still here :P
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 840
Quoted 7 lines
src/openvpn/manage.c +7
-0+static void +man_remote_entry_count (struct management *man) +{ +unsigned count =0 ; +if (man->persist.callback.remote_entry_count) + { + count = (*man->persist.callback.remote_entry_count)(man->persist.callback.arg);
We could use C99 style here.
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 850
Quoted 10 lines
src/openvpn/manage.c +10
-0+msg (M_CLIENT ,"%u" , count); +msg (M_CLIENT ,"END" ); + } +else + { +msg (M_CLIENT ,"ERROR: The remote-entry-count command is not supported by the current daemon mode" ); + } +} + +#define min (a,b) ((a) < (b) ? (a) : (b))
We already have min_int and min_uint in integer.h. For consistency I would prefer using those instead of adding a macro.
Quoted 6 lines
src/openvpn/manage.c +6
-0+ +static void +man_remote_entry_get (struct management *man,const char *p1,const char *p2) +{ +ASSERT (p1); +
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 866
Quoted 10 lines
src/openvpn/manage.c +10
-0+if (man->persist.callback.remote_entry_get + && man->persist.callback.remote_entry_count) + { +bool res; +unsigned int from, to; +unsigned int count = (*man->persist.callback.remote_entry_count)(man->persist.callback.arg); + + from = (unsigned int )atoi (p1); + to = p2? (unsigned int )atoi (p2) : from +1 ; +
We probably want a space after p2.
I know this has been very long and we are very close to 2.6 so
Maybe we can do a follow up patch to fix the mentioned small issues.
Hi
Quoted 55 lines · Arne Schwabe
Am 08.09.21 um 00:31 schrieb [email protected]...:
Quoted 3 lines
From: Selva Nair <[email protected]...>
Selecting the remote host via the management iterface
*sigh* I reviewed the v2 instead of the v3 but the typo is still here :P
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index)
Quoted 7 lines
src/openvpn/manage.c +7
-0+static void +man_remote_entry_count (struct management *man) +{ +unsigned count =0 ; +if (man->persist.callback.remote_entry_count) + { + count =(*man->persist.callback.remote_entry_count)(man->persist.callback.arg);
We could use C99 style here.
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index)
Quoted 6 lines
src/openvpn/manage.c +6
-0+msg (M_CLIENT ,"%u" , count); +msg (M_CLIENT ,"END" ); + } +else + { + msg(M_CLIENT, "ERROR: The remote-entry-count command is notsupported by the current daemon mode");
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 850
Quoted 4 lines
src/openvpn/manage.c +4
-0+ } +} + +#define min (a,b) ((a) < (b) ? (a) : (b))We already have
min_intandmin_uintininteger.h. For consistency I would prefer using those instead of adding a macro.src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index)
Quoted 3 lines
src/openvpn/manage.c +3
-0+ +static void +man_remote_entry_get(struct management *man, const char *p1, const char*p2)
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index)
Quoted 9 lines
src/openvpn/manage.c +9
-0+{ +ASSERT (p1); + +if (man->persist.callback.remote_entry_get + && man->persist.callback.remote_entry_count) + { +bool res; +unsigned int from, to; + unsigned int count =(*man->persist.callback.remote_entry_count)(man->persist.callback.arg);
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 866
Quoted 4 lines
src/openvpn/manage.c +4
-0+ + from = (unsigned int )atoi (p1); + to = p2? (unsigned int )atoi (p2) : from +1 ; +We probably want a space after p2.
Quoted 4 lines
I know this has been very long and we are very close to 2.6 so
Acked-by Arne Schwabe <[email protected]...>
Thanks..
Quoted 3 lines
Maybe we can do a follow up patch to fix the mentioned small issues.
Will do as a followup or in the rebased pachc depending what Gert asks for.
Would it be too much to ask for a review of this one too ?
https://patchwork.openvpn.net/project/openvpn2/patch/[email protected].../
Selva
Hi,
Quoted 5 lines · Selva Nair
Quoted 5 lines
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 850
Quoted 2 lines
src/openvpn/manage.c +2
-0+ +#define min (a,b) ((a) < (b) ? (a) : (b))We already have
min_intandmin_uintininteger.h. For consistency I would prefer using those instead of adding a macro.
Unfortunately, this is more than "just an extra macro" - it breaks our MSVC builds due to the windows equivalent of -Werr and macro redefinition...
https://github.com/OpenVPN/openvpn/actions/runs/3786194652/jobs/6436868937
D:\a\openvpn\openvpn\src\openvpn\manage.c(862,1): warning C4005: 'min': macro redefinition [D:\a\openvpn\openvpn\src\openvpn\openvpn.vcxproj] D:\a\openvpn\openvpn\src\openvpn\manage.c(862,1): error C2220: the following warning is treated as an error [D:\a\openvpn\openvpn\src\openvpn\openvpn.vcxproj]
(not sure why it calls out "the following warning" when it talks about the one before it? but anyway)
this came a bit unexpected, so it's been pushed out already...
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...I had conflicts in doc/management-notes.txt (the context leading to this in the patch is way different, and not in my tree?!), and uncrustify had some whitespace complaints - fixed the conflict, and the complaints.
Stare-at-code looks reasonable ("and it has an ACK from Arne").
I have tested this (with a small .ovpn with only a handful of remotes in), and it seems to do what it says on the lid.
One thing that confuses me slightly - either I am holding this wrong, or I don't understand how this is supposed to work...
- I run the client with --management-hold
- connect to the management interface
- try remote-entry-count ...
Quoted 2 lines
INFO:OpenVPN Management Interface Version 4 -- type 'help' for more info HOLD:Waiting for hold release:0
remote-entry-count
ERROR: The remote-entry-count command is not supported by the current daemon mode
- do a hold release (openvpn connects to the first remote now), then try again...
hold release
SUCCESS: hold release succeeded
remote-entry-count
5
END
- looking at the code confirms that cb.remote_entry_count + *get is only initialized (init_management_callback_p2p()) when OpenVPN starts, well, initializing the actual P2P instance - so the code does what it is told, but I wonder if this feature should not help the GUI select one of the configs *before* OpenVPN starts connecting to the first remote?
Your patch has been applied to the master and release/2.6 branch.
commit 125263804701f9e62a5a27587e4ea6afdb21f54d ( master) commit 5503b45e6666cc7a3f10dd1e6fb406ca487489bd (HEAD -> release/2.6)
Author: Selva Nair Date: Tue Sep 7 18:31:24 2021 -0400
Add remote-count and remote-entry query via management
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22815.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Hi,
Quoted 5 lines · Selva Nair
Quoted 5 lines
Quoted 5 lines
src/openvpn/manage.c man_pkcs11_id_get(struct management *man, const int index) · line 850
Quoted 2 lines
src/openvpn/manage.c +2
-0+ +#define min (a,b) ((a) < (b) ? (a) : (b))We already have
min_intandmin_uintininteger.h. For consistency I would prefer using those instead of adding a macro.
Unfortunately, this is more than "just an extra macro" - it breaks our
Quoted 2 lines
MSVC builds due to the windows equivalent of -Werr and macro redefinition...
https://github.com/OpenVPN/openvpn/actions/runs/3786194652/jobs/6436868937
Sorry about that -- I did not check MSVC build.
Looks like a fix is already in. Thanks Arne.
One thing that confuses me slightly - either I am holding this wrong, or
Quoted 13 lines
I don't understand how this is supposed to work...
- I run the client with --management-hold
- connect to the management interface
- try remote-entry-count ...Quoted 1 line
INFO:OpenVPN Management Interface Version 4 -- type 'help' for more
info
Quoted 1 line
HOLD:Waiting for hold release:0
remote-entry-count
ERROR: The remote-entry-count command is not supported by the current
daemon mode
Quoted 9 lines
- do a hold release (openvpn connects to the first remote now), then try again...
hold release
SUCCESS: hold release succeeded
remote-entry-count
5
END
My test implementation in the GUI constructs the list when first >REMOTE query is received. If there is no >REMOTE from the daemon, the feature is not used. That works.
That said, making these commands work from management-hold would have been nice, but looked harder to implement -- we need a callback to get the context in management.c, but callbacks are initialized late.
Selva
Hi,
Quoted 3 lines · Selva Nair
My test implementation in the GUI constructs the list when first >REMOTE query is received. If there is no >REMOTE from the daemon, the feature is not used. That works.
So what's the magic --option to make openvpn query for >REMOTE?
(My understanding of the management interface details is limited... I just happen to stumble across things here and there :-) )
Quoted 3 lines
That said, making these commands work from management-hold would have been nice, but looked harder to implement -- we need a callback to get the context in
management.c, but callbacks are initialized late.
Yes, definitely looked like it. But if OpenVPN queries for >REMOTE voluntarily ("if more than one option exists"), that sounds good enough.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Quoted 9 lines · Gert Doering
Hi,
Quoted 3 lines · Selva Nair
My test implementation in the GUI constructs the list when first >REMOTE query is received. If there is no >REMOTE from the daemon, the feature is not used. That works.
So what's the magic --option to make openvpn query for >REMOTE?
--management-query-remote
Quoted 11 lines
(My understanding of the management interface details is limited... I just happen to stumble across things here and there :-) )
Quoted 1 line
That said, making these commands work from management-hold would have
been
Quoted 2 lines
nice, but looked harder to implement -- we need a callback to get the context in
management.c, but callbacks are initialized late.Yes, definitely looked like it. But if OpenVPN queries for >REMOTE voluntarily ("if more than one option exists"), that sounds good enough.
Yet undecided whether we should include this option from the GUI, or require the user to add this to the config. Unlike management-query-passwords adding this option always has the side effect of querying for remote. That may annoy/burden some users who want to leave it to the daemon via remote-random or use the first that works or whatever.
Or, we could always add this option, and just accept the first prompt if the user does not want this feature.
Selva
First sorry for completely forgetting about this patch series.
Am 25.08.21 um 23:02 schrieb [email protected]...:
Quoted 3 lines
From: Selva Nair <[email protected]...>
Selecting the remote host via the management iterface
Typo in interface
Quoted 10 lines
src/openvpn/init.c +10
-0+ +static bool +management_callback_remote_entry_get (void *arg,unsigned int index,char **remote) +{ +assert (arg); +assert (remote); + +struct context *c = (struct context *) arg; +struct connection_list *l = c->options.connection_list; +bool ret = true;
src/openvpn/init.c management_callback_send_cc_message(void *arg, · line 360
Quoted 10 lines
src/openvpn/init.c +10
-0+ +if (index < l->len) + { +struct connection_entry *ce = l->array[index]; +const char *proto =proto2ascii (ce->proto, ce->af, false); + +/* space for output including 2 commas and a nul */ +int len =strlen (ce->remote) +strlen (ce->remote_port) +strlen (proto) +2 +1 ; +char *out =malloc (len); +check_malloc_return (out);
Not sure that we need to exit the program here instead of of return false but the error is so seldom that it does not really matter. Using gc_arena would have been also a bit nicer but not too problematic.
src/openvpn/init.c management_callback_send_cc_message(void *arg, · line 371
Quoted 11 lines
src/openvpn/init.c +11
-0+ +openvpn_snprintf (out, len,"%s,%s,%s" , ce->remote, ce->remote_port, proto); + *remote = out; + } +else + { + ret = false; +msg (M_WARN ,"Out of bounds index in management query for remote entry: index = %u" , index); + } + +return ret;
I feel we could eliminate ret variable here and just do return true and return false from the true branches of the if.
There are minor things that could be improved but the current state is still acceptable.