From: "cron2 (Code Review)" Date: Wed, 3 Sep 2025 20:26:50 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., marco@...2726..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277... Message-ID: <5ce1d44ea6d0a0617c25687706d5059471479f62-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="KiFb7I8WPIo="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: PUSH_UPDATE message sender: enabling the server to send PUSH_UPDATE c... List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mrbff Cc: flichtenheld , stipa , plaisthos , openvpn-devel --KiFb7I8WPIo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/86= 9?usp=3Demail ) Change subject: PUSH_UPDATE message sender: enabling the server to send PUS= H_UPDATE control messages ...................................................................... PUSH_UPDATE message sender: enabling the server to send PUSH_UPDATE control= messages Using the management interface you can now target one or more clients (via broadcast or via cid) and send a PUSH_UPDATE control message to update some options. See doc/management-notes.txt for details. Change-Id: Ie82bcc7a8e583de9156b185d71d1a323ed8df3fc Signed-off-by: Marco Baffo Acked-by: Gert Doering Message-Id: <20250903164826.13284-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32= 807.html Signed-off-by: Gert Doering --- M CMakeLists.txt M doc/management-notes.txt M src/openvpn/manage.c M src/openvpn/manage.h M src/openvpn/multi.c M src/openvpn/multi.h M src/openvpn/options.c M src/openvpn/options_util.c M src/openvpn/push.c M src/openvpn/push.h M src/openvpn/push_util.c M tests/unit_tests/openvpn/Makefile.am M tests/unit_tests/openvpn/test_push_update_msg.c 13 files changed, 741 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35513e9..f027b01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -874,9 +874,10 @@ target_sources(test_push_update_msg PRIVATE tests/unit_tests/openvpn/mock_msg.c tests/unit_tests/openvpn/mock_get_random.c - src/openvpn/push_util.c - src/openvpn/options_util.c - src/openvpn/otime.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + src/openvpn/list.c ) if (TARGET test_argv) diff --git a/doc/management-notes.txt b/doc/management-notes.txt index f1d2930..1a5c311 100644 --- a/doc/management-notes.txt +++ b/doc/management-notes.txt @@ -1028,6 +1028,35 @@ stored outside of the filesystem (e.g. in Mac OS X Keychain) with OpenVPN via the management interface. +COMMAND -- push-update-broad (OpenVPN 2.7 or higher) +---------------------------------------------------- +Send a message to every connected client to update options at runtime. +The updatable options are: "block-ipv6", "block-outside-dns", "dhcp-option= ", +"dns", "ifconfig", "ifconfig-ipv6", "redirect-gateway", "redirect-private", +"route", "route-gateway", "route-ipv6", "route-metric", "topology", +"tun-mtu", "keepalive". When a valid option is pushed, the receiving clien= t will +delete every previous value and set new value, so the update of the option= will +not be incremental even when theoretically possible (ex. with "redirect-ga= teway"). +The '-' symbol in front of an option means the option should be removed. +When an option is used with '-', it cannot take any parameter. +The '?' symbol in front of an option means the option's update is optional +so if the client do not support it, that option will just be ignored witho= ut +making fail the entire command. The '-' and '?' symbols can be used togeth= er. + +Option Format Ex. + `-?option`, `-option`, `?option parameters` are valid formats, + `?-option` is not a valid format. + +Example + push-update-broad "route 10.10.10.1 255.255.255.255, -dns, ?tun-mtu 1400" + +COMMAND -- push-update-cid (OpenVPN 2.7 or higher) +---------------------------------------------------- +Same as push-update-broad but you must target a single client using client= id. + +Example + push-update-cid 42 "route 10.10.10.1 255.255.255.255, -dns, ?tun-mtu 140= 0" + OUTPUT FORMAT ------------- =20 diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 5b2a7de..114e4c6 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -41,6 +41,7 @@ #include "manage.h" #include "openvpn.h" #include "dco.h" +#include "push.h" #include "multi.h" #include "memdbg.h" @@ -132,8 +133,10 @@ msg(M_CLIENT, "test n : Produce n lines of output for = testing/debugging."); msg(M_CLIENT, "username type u : Enter username u for a queried= OpenVPN username."); msg(M_CLIENT, "verb [n] : Set log verbosity level to n, = or show if n is absent."); - msg(M_CLIENT, - "version [n] : Set client's version to n or show curren= t version of daemon."); + msg(M_CLIENT, "version [n] : Set client's version to n or s= how current version of daemon."); + msg(M_CLIENT, "push-update-broad options : Broadcast a message to upda= te the specified options."); + msg(M_CLIENT, " Ex. push-update-broad \"rou= te something, -dns\""); + msg(M_CLIENT, "push-update-cid CID options : Send an update message to= the client identified by CID."); msg(M_CLIENT, "END"); } @@ -1333,6 +1336,48 @@ } static void +man_push_update(struct management *man, const char **p, const push_update_= type type) +{ + bool status =3D false; + + if (type =3D=3D UPT_BROADCAST) + { + if (!man->persist.callback.push_update_broadcast) + { + man_command_unsupported("push-update-broad"); + return; + } + + status =3D (*man->persist.callback.push_update_broadcast)(man->per= sist.callback.arg, p[1]); + } + else if (type =3D=3D UPT_BY_CID) + { + if (!man->persist.callback.push_update_by_cid) + { + man_command_unsupported("push-update-cid"); + return; + } + + unsigned long cid =3D 0; + + if (!parse_cid(p[1], &cid)) + { + msg(M_CLIENT, "ERROR: push-update-cid fail during cid parsing"= ); + return; + } + + status =3D (*man->persist.callback.push_update_by_cid)(man->persis= t.callback.arg, cid, p[2]); + } + + if (status) + { + msg(M_CLIENT, "SUCCESS: push-update command succeeded"); + return; + } + msg(M_CLIENT, "ERROR: push-update command failed"); +} + +static void man_dispatch_command(struct management *man, struct status_output *so, con= st char **p, const int nparms) { @@ -1655,6 +1700,20 @@ man_remote(man, p); } } + else if (streq(p[0], "push-update-broad")) + { + if (man_need(man, p, 1, 0)) + { + man_push_update(man, p, UPT_BROADCAST); + } + } + else if (streq(p[0], "push-update-cid")) + { + if (man_need(man, p, 2, 0)) + { + man_push_update(man, p, UPT_BY_CID); + } + } #if 1 else if (streq(p[0], "test")) { diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index 0b064cf..0bce25e 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -43,7 +43,6 @@ #define MF_EXTERNAL_KEY_PSSPAD (1u << 16) #define MF_EXTERNAL_KEY_DIGEST (1u << 17) - #ifdef ENABLE_MANAGEMENT #include "misc.h" @@ -197,6 +196,8 @@ #endif unsigned int (*remote_entry_count)(void *arg); bool (*remote_entry_get)(void *arg, unsigned int index, char **remote); + bool (*push_update_broadcast)(void *arg, const char *options); + bool (*push_update_by_cid)(void *arg, unsigned long cid, const char *o= ptions); }; /* diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index f1abdbe..85975ff 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -3996,7 +3996,7 @@ } } -static struct multi_instance * +struct multi_instance * lookup_by_cid(struct multi_context *m, const unsigned long cid) { if (m) @@ -4137,6 +4137,8 @@ cb.client_auth =3D management_client_auth; cb.client_pending_auth =3D management_client_pending_auth; cb.get_peer_info =3D management_get_peer_info; + cb.push_update_broadcast =3D management_callback_send_push_update_= broadcast; + cb.push_update_by_cid =3D management_callback_send_push_update_by_= cid; management_set_callback(management, &cb); } #endif /* ifdef ENABLE_MANAGEMENT */ @@ -4261,3 +4263,47 @@ multi_top_free(&multi); close_instance(top); } + +/** + * Update the vhash with new IP/IPv6 addresses in the multi_context when a + * push-update message containing ifconfig/ifconfig-ipv6 options is sent + * from the server. This function should be called after a push-update + * and old_ip/old_ipv6 are the previous addresses of the client in + * ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. + */ +void +update_vhash(struct multi_context *m, struct multi_instance *mi, const cha= r *old_ip, const char *old_ipv6) +{ + struct in_addr addr; + struct in6_addr new_ipv6; + + if ((mi->context.options.ifconfig_local && (!old_ip || strcmp(old_ip, = mi->context.options.ifconfig_local))) + && inet_pton(AF_INET, mi->context.options.ifconfig_local, &addr) = =3D=3D 1) + { + in_addr_t new_ip =3D ntohl(addr.s_addr); + + /* Add new IP */ + multi_learn_in_addr_t(m, mi, new_ip, -1, true); + } + + /* TO DO: + * else if (old_ip) + * { + * // remove old IP + * } + */ + + if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 || strcmp(o= ld_ipv6, mi->context.options.ifconfig_ipv6_local))) + && inet_pton(AF_INET6, mi->context.options.ifconfig_ipv6_local, &n= ew_ipv6) =3D=3D 1) + { + /* Add new IPv6 */ + multi_learn_in6_addr(m, mi, new_ipv6, -1, true); + } + + /* TO DO: + * else if (old_ipv6) + * { + * // remove old IPv6 + * } + */ +} diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index e87e465..087c0e6 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -686,5 +686,12 @@ */ void multi_assign_peer_id(struct multi_context *m, struct multi_instance *= mi); +#ifdef ENABLE_MANAGEMENT +struct multi_instance * +lookup_by_cid(struct multi_context *m, const unsigned long cid); +#endif + +void +update_vhash(struct multi_context *m, struct multi_instance *mi, const cha= r *old_ip, const char *old_ipv6); #endif /* MULTI_H */ diff --git a/src/openvpn/options.c b/src/openvpn/options.c index a268b92..0616a17 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -5488,7 +5488,6 @@ { continue; /* Ignoring this option */ } - throw_signal_soft(SIGUSR1, "Offending option received from ser= ver"); return false; /* Cause push/pull error and stop push processin= g */ } diff --git a/src/openvpn/options_util.c b/src/openvpn/options_util.c index be1eefc..28f1f9e 100644 --- a/src/openvpn/options_util.c +++ b/src/openvpn/options_util.c @@ -236,11 +236,11 @@ { if (*flags & PUSH_OPT_OPTIONAL) { - msg(D_PUSH, "Pushed option is not updatable: '%s'. Ignoring.",= line); + msg(D_PUSH, "Pushed dispensable option is not updatable: '%s'.= Ignoring.", line); } else { - msg(M_WARN, "Pushed option is not updatable: '%s'. Restarting.= ", line); + msg(M_WARN, "Pushed option is not updatable: '%s'.", line); return false; } } diff --git a/src/openvpn/push.c b/src/openvpn/push.c index 4f6adfc..1ea7ed9 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -1073,6 +1073,10 @@ break; } } + else + { + throw_signal_soft(SIGUSR1, "Offending option received from ser= ver"); + } } else if (ch =3D=3D '\0') { @@ -1100,7 +1104,7 @@ } else if (honor_received_options && buf_string_compare_advance(&buf, pu= sh_update_cmd)) { - return process_incoming_push_update(c, permission_mask, option_typ= es_found, &buf); + return process_incoming_push_update(c, permission_mask, option_typ= es_found, &buf, false); } else { diff --git a/src/openvpn/push.h b/src/openvpn/push.h index 22b940f..8ffd0c2 100644 --- a/src/openvpn/push.h +++ b/src/openvpn/push.h @@ -41,6 +41,15 @@ #define PUSH_OPT_TO_REMOVE (1 << 0) #define PUSH_OPT_OPTIONAL (1 << 1) +#ifdef ENABLE_MANAGEMENT +/* Push-update message sender modes */ +typedef enum +{ + UPT_BROADCAST =3D 0, + UPT_BY_CID =3D 1 +} push_update_type; +#endif + int process_incoming_push_request(struct context *c); /** @@ -56,6 +65,7 @@ * @param option_types_found A pointer to a variable that will be filled w= ith the types of options * found in the message. * @param buf A buffer containing the received message. + * @param msg_sender A boolean indicating if function is called by the mes= sage sender (server). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the up= dates were applied. @@ -65,7 +75,8 @@ */ int process_incoming_push_update(struct context *c, unsigned int permissio= n_mask, - unsigned int *option_types_found, struct = buffer *buf); + unsigned int *option_types_found, struct = buffer *buf, + bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buff= er, bool honor_received_options, unsigned int pe= rmission_mask, @@ -127,4 +138,28 @@ */ void receive_auth_pending(struct context *c, const struct buffer *buffer); +#ifdef ENABLE_MANAGEMENT +/** + * @brief A function to send a PUSH_UPDATE control message from server to = client(s). + * + * @param m the multi_context, contains all the clients connected to this = server. + * @param target the target to which to send the message. It should be: + * `NULL` if `type =3D=3D UPT_BROADCAST`, + * a `mroute_addr *` if `type =3D=3D UPT_BY_ADDR`, + * a `char *` if `type =3D=3D UPT_BY_CN`, + * an `unsigned long *` if `type =3D=3D UPT_BY_CID`. + * @param msg a string containing the options to send. + * @param type the way to address the message (broadcast, by cid, by cn, b= y address). + * @param push_bundle_size the maximum size of a bundle of pushed option. = Just use PUSH_BUNDLE_SIZE macro. + * @return the number of clients to which the message was sent. + */ +int +send_push_update(struct multi_context *m, const void *target, const char *= msg, const push_update_type type, const int push_bundle_size); + +bool management_callback_send_push_update_broadcast(void *arg, const char = *options); + +bool management_callback_send_push_update_by_cid(void *arg, unsigned long = cid, const char *options); + +#endif /* ifdef ENABLE_MANAGEMENT*/ + #endif /* ifndef PUSH_H */ diff --git a/src/openvpn/push_util.c b/src/openvpn/push_util.c index 0862a74..bd3992b 100644 --- a/src/openvpn/push_util.c +++ b/src/openvpn/push_util.c @@ -3,10 +3,16 @@ #endif #include "push.h" +#include "buffer.h" + +#ifdef ENABLE_MANAGEMENT +#include "multi.h" +#endif int process_incoming_push_update(struct context *c, unsigned int permission_ma= sk, - unsigned int *option_types_found, struct buff= er *buf) + unsigned int *option_types_found, struct buff= er *buf, + bool msg_sender) { int ret =3D PUSH_MSG_ERROR; const uint8_t ch =3D buf_read_u8(buf); @@ -27,6 +33,10 @@ break; } } + else if (!msg_sender) + { + throw_signal_soft(SIGUSR1, "Offending option received from ser= ver"); + } } else if (ch =3D=3D '\0') { @@ -35,3 +45,260 @@ return ret; } + +#ifdef ENABLE_MANAGEMENT +/** + * Return index of last `,` or `0` if it didn't find any. + * If there is a comma at index `0` it's an error anyway + */ +static int +find_first_comma_of_next_bundle(const char *str, int ix) +{ + while (ix > 0) + { + if (str[ix] =3D=3D ',') + { + return ix; + } + ix--; + } + return 0; +} + +/* Allocate memory and assemble the final message */ +static struct buffer +forge_msg(const char *src, const char *continuation, struct gc_arena *gc) +{ + int src_len =3D strlen(src); + int con_len =3D continuation ? strlen(continuation) : 0; + struct buffer buf =3D alloc_buf_gc(src_len + sizeof(push_update_cmd) += con_len + 2, gc); + + buf_printf(&buf, "%s,%s%s", push_update_cmd, src, continuation ? conti= nuation : ""); + + return buf; +} + +static char * +gc_strdup(const char *src, struct gc_arena *gc) +{ + char *ret =3D gc_malloc((strlen(src) + 1) * sizeof(char), true, gc); + + strcpy(ret, src); + return ret; +} + +/* It split the messagge (if necessay) and fill msgs with the message chun= ks. + * Return `false` on failure an `true` on success. + */ +static bool +message_splitter(const char *s, struct buffer *msgs, struct gc_arena *gc, = const int safe_cap) +{ + if (!s || !*s) + { + return false; + } + + char *str =3D gc_strdup(s, gc); + int i =3D 0; + int im =3D 0; + + while (*str) + { + /* + ',' - '/0' */ + if (strlen(str) > safe_cap) + { + int ci =3D find_first_comma_of_next_bundle(str, safe_cap); + if (!ci) + { + /* if no commas were found go to fail, do not send any mes= sage */ + return false; + } + str[ci] =3D '\0'; + /* copy from i to (ci -1) */ + msgs[im] =3D forge_msg(str, ",push-continuation 2", gc); + i =3D ci + 1; + } + else + { + if (im) + { + msgs[im] =3D forge_msg(str, ",push-continuation 1", gc); + } + else + { + msgs[im] =3D forge_msg(str, NULL, gc); + } + i =3D strlen(str); + } + str =3D &str[i]; + im++; + } + return true; +} + +/* send the message(s) prepared to one single client */ +static bool +send_single_push_update(struct context *c, struct buffer *msgs, unsigned i= nt *option_types_found) +{ + if (!msgs[0].data || !*(msgs[0].data)) + { + return false; + } + int i =3D -1; + + while (msgs[++i].data && *(msgs[i].data)) + { + if (!send_control_channel_string(c, BSTR(&msgs[i]), D_PUSH)) + { + return false; + } + + /* After sending the control message, we update the options + * server-side in the client's context so pushed options like + * ifconfig/ifconfig-ipv6 can actually work. + * If we don't do that, packets arriving from the client with the + * new address will be rejected and packets for the new address + * will not be routed towards the client. + * For the same reason we later update the vhash too in + * `send_push_update()` function. + */ + buf_string_compare_advance(&msgs[i], push_update_cmd); + if (process_incoming_push_update(c, pull_permission_mask(c), optio= n_types_found, &msgs[i], true) =3D=3D PUSH_MSG_ERROR) + { + msg(M_WARN, "Failed to process push update message sent to cli= ent ID: %u", + c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX); + continue; + } + c->options.push_option_types_found |=3D *option_types_found; + if (!options_postprocess_pull(&c->options, c->c2.es)) + { + msg(M_WARN, "Failed to post-process push update message sent t= o client ID: %u", + c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX); + } + } + return true; +} + +int +send_push_update(struct multi_context *m, const void *target, const char *= msg, const push_update_type type, const int push_bundle_size) +{ + if (!msg || !*msg || !m + || (!target && type !=3D UPT_BROADCAST)) + { + return -EINVAL; + } + + struct gc_arena gc =3D gc_new(); + /* extra space for possible trailing ifconfig and push-continuation */ + const int extra =3D 84 + sizeof(push_update_cmd); + /* push_bundle_size is the maximum size of a message, so if the message + * we want to send exceeds that size we have to split it into smaller = messages */ + const int safe_cap =3D push_bundle_size - extra; + int msgs_num =3D (strlen(msg) / safe_cap) + ((strlen(msg) % safe_cap) = !=3D 0); + struct buffer *msgs =3D gc_malloc((msgs_num + 1) * sizeof(struct buffe= r), true, &gc); + + unsigned int option_types_found =3D 0; + + msgs[msgs_num].data =3D NULL; + if (!message_splitter(msg, msgs, &gc, safe_cap)) + { + gc_free(&gc); + return -EINVAL; + } + + if (type =3D=3D UPT_BY_CID) + { + struct multi_instance *mi =3D lookup_by_cid(m, *((unsigned long *)= target)); + + if (!mi) + { + return -ENOENT; + } + + const char *old_ip =3D mi->context.options.ifconfig_local; + const char *old_ipv6 =3D mi->context.options.ifconfig_ipv6_local; + if (!mi->halt + && send_single_push_update(&mi->context, msgs, &option_types_f= ound)) + { + if (option_types_found & OPT_P_UP) + { + update_vhash(m, mi, old_ip, old_ipv6); + } + gc_free(&gc); + return 1; + } + else + { + gc_free(&gc); + return 0; + } + } + + int count =3D 0; + struct hash_iterator hi; + const struct hash_element *he; + + hash_iterator_init(m->iter, &hi); + while ((he =3D hash_iterator_next(&hi))) + { + struct multi_instance *curr_mi =3D he->value; + + if (curr_mi->halt) + { + continue; + } + + /* Type is UPT_BROADCAST so we update every client */ + option_types_found =3D 0; + const char *old_ip =3D curr_mi->context.options.ifconfig_local; + const char *old_ipv6 =3D curr_mi->context.options.ifconfig_ipv6_lo= cal; + if (!send_single_push_update(&curr_mi->context, msgs, &option_type= s_found)) + { + msg(M_CLIENT, "ERROR: Peer ID: %u has not been updated", + curr_mi->context.c2.tls_multi ? curr_mi->context.c2.tls_mu= lti->peer_id : UINT32_MAX); + continue; + } + if (option_types_found & OPT_P_UP) + { + update_vhash(m, curr_mi, old_ip, old_ipv6); + } + count++; + } + + hash_iterator_free(&hi); + gc_free(&gc); + return count; +} + +#define RETURN_UPDATE_STATUS(n_sent) \ + do \ + { \ + if ((n_sent) > 0) \ + { \ + msg(M_CLIENT, "SUCCESS: %d client(s) updated", (n_sent)); \ + return true; \ + } \ + else \ + { \ + msg(M_CLIENT, "ERROR: no client updated"); \ + return false; \ + } \ + } while (0) + + +bool +management_callback_send_push_update_broadcast(void *arg, const char *opti= ons) +{ + int n_sent =3D send_push_update(arg, NULL, options, UPT_BROADCAST, PUS= H_BUNDLE_SIZE); + + RETURN_UPDATE_STATUS(n_sent); +} + +bool +management_callback_send_push_update_by_cid(void *arg, unsigned long cid, = const char *options) +{ + int n_sent =3D send_push_update(arg, &cid, options, UPT_BY_CID, PUSH_B= UNDLE_SIZE); + + RETURN_UPDATE_STATUS(n_sent); +} +#endif /* ifdef ENABLE_MANAGEMENT */ diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvp= n/Makefile.am index 7a7fec7..ec8cc69 100644 --- a/tests/unit_tests/openvpn/Makefile.am +++ b/tests/unit_tests/openvpn/Makefile.am @@ -337,7 +337,8 @@ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/push_util.c \ $(top_srcdir)/src/openvpn/options_util.c \ - $(top_srcdir)/src/openvpn/otime.c + $(top_srcdir)/src/openvpn/otime.c \ + $(top_srcdir)/src/openvpn/list.c socket_testdriver_CFLAGS =3D \ -I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/op= envpn \ diff --git a/tests/unit_tests/openvpn/test_push_update_msg.c b/tests/unit_t= ests/openvpn/test_push_update_msg.c index 0f4ad41..87329b1 100644 --- a/tests/unit_tests/openvpn/test_push_update_msg.c +++ b/tests/unit_tests/openvpn/test_push_update_msg.c @@ -8,9 +8,16 @@ #include #include "push.h" #include "options_util.h" +#include "multi.h" /* mocks */ +void +throw_signal_soft(const int signum, const char *signal_text) +{ + msg(M_WARN, "Offending option received from server"); +} + unsigned int pull_permission_mask(const struct context *c) { @@ -21,6 +28,18 @@ return flags; } +void +update_vhash(struct multi_context *m, struct multi_instance *mi, const cha= r *old_ip, const char *old_ipv6) +{ + return; +} + +bool +options_postprocess_pull(struct options *options, struct env_set *es) +{ + return true; +} + bool apply_push_options(struct context *c, struct options *options, struct buff= er *buf, unsigned int permission_mask, unsigned int *option_type= s_found, @@ -48,7 +67,6 @@ { continue; /* Ignoring this option */ } - msg(M_WARN, "Offending option received from server"); return false; /* Cause push/pull error and stop push proce= ssing */ } } @@ -77,7 +95,7 @@ } else if (honor_received_options && buf_string_compare_advance(&buf, pu= sh_update_cmd)) { - return process_incoming_push_update(c, permission_mask, option_typ= es_found, &buf); + return process_incoming_push_update(c, permission_mask, option_typ= es_found, &buf, false); } else { @@ -85,6 +103,49 @@ } } +const char * +tls_common_name(const struct tls_multi *multi, const bool null) +{ + return NULL; +} + +#ifndef ENABLE_MANAGEMENT +bool +send_control_channel_string(struct context *c, const char *str, int msglev= el) +{ + return true; +} +#else /* ifndef ENABLE_MANAGEMENT */ +char **res; +int i; + +bool +send_control_channel_string(struct context *c, const char *str, int msglev= el) +{ + if (res && res[i] && strcmp(res[i], str)) + { + printf("\n\nexpected: %s\n\n actual: %s\n\n", res[i], str); + return false; + } + i++; + return true; +} + +struct multi_instance * +lookup_by_cid(struct multi_context *m, const unsigned long cid) +{ + return *(m->instances); +} + +bool +mroute_extract_openvpn_sockaddr(struct mroute_addr *addr, + const struct openvpn_sockaddr *osaddr, + bool use_port) +{ + return true; +} +#endif /* ifndef ENABLE_MANAGEMENT */ + /* tests */ static void @@ -120,7 +181,6 @@ free_buf(&buf); } - static void test_incoming_push_message_error2(void **state) { @@ -219,6 +279,207 @@ free_buf(&buf); } +#ifdef ENABLE_MANAGEMENT +char *r0[] =3D { + "PUSH_UPDATE,redirect-gateway local,route 192.168.1.0 255.255.255.0" +}; +char *r1[] =3D { + "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalala= lalalalalalalalaf,push-continuation 2", + "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redire= ct-gateway local,push-continuation 2", + "PUSH_UPDATE,route 192.168.1.0 255.255.255.0,push-continuation 1" +}; +char *r3[] =3D { + "PUSH_UPDATE,,," +}; +char *r4[] =3D { + "PUSH_UPDATE,-dhcp-option, blablalalalalalalalalalalalalf, lalalalalal= alalalalalalalalaf,push-continuation 2", + "PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redire= ct-gateway local,push-continuation 2", + "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,,push-continuation 1" +}; +char *r5[] =3D { + "PUSH_UPDATE,,-dhcp-option, blablalalalalalalalalalalalalf, lalalalala= lalalalalalalalalaf,push-continuation 2", + "PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redire= ct-gateway local,push-continuation 2", + "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,push-continuation 1" +}; +char *r6[] =3D { + "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalala= lalalalalalalalaf,push-continuation 2", + "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8, redir= ect-gateway 10.10.10.10,,push-continuation 2", + "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,,push-continuation 1" +}; +char *r7[] =3D { + "PUSH_UPDATE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,push-continuation 2", + "PUSH_UPDATE,,,,,,,,,,,,,,,,,,,push-continuation 1" +}; +char *r8[] =3D { + "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalala= lalalalalalalalaf,push-continuation 2", + "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redire= ct-gateway\n local,push-continuation 2", + "PUSH_UPDATE,route 192.168.1.0 255.255.255.0\n\n\n,push-continuation 1" +}; +char *r9[] =3D { + "PUSH_UPDATE,," +}; + + +const char *msg0 =3D "redirect-gateway local,route 192.168.1.0 255.255.255= .0"; +const char *msg1 =3D "-dhcp-option,blablalalalalalalalalalalalalf, lalalal= alalalalalalalalalalaf," + " akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,red= irect-gateway local,route 192.168.1.0 255.255.255.0"; +const char *msg2 =3D ""; +const char *msg3 =3D ",,"; +const char *msg4 =3D "-dhcp-option, blablalalalalalalalalalalalalf, lalala= lalalalalalalalalalalaf," + " akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, red= irect-gateway local, route 192.168.1.0 255.255.255.0,"; +const char *msg5 =3D ",-dhcp-option, blablalalalalalalalalalalalalf, lalal= alalalalalalalalalalalaf," + " akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, red= irect-gateway local, route 192.168.1.0 255.255.255.0"; +const char *msg6 =3D "-dhcp-option,blablalalalalalalalalalalalalf, lalalal= alalalalalalalalalalaf, akakakakakakakakakakakaf," + " dhcp-option DNS 8.8.8.8, redirect-gateway 10.10.10.10= ,, route 192.168.1.0 255.255.255.0,"; +const char *msg7 =3D ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"; +const char *msg8 =3D "-dhcp-option,blablalalalalalalalalalalalalf, lalalal= alalalalalalalalalalaf, akakakakakakakakakakakaf," + " dhcp-option DNS 8.8.8.8,redirect-gateway\n local,rout= e 192.168.1.0 255.255.255.0\n\n\n"; +const char *msg9 =3D ","; + +const char *msg10 =3D "abandon ability able about above absent absorb abst= ract absurd abuse access accident account accuse achieve" + "acid acoustic acquire across act action actor actress= actual adapt add addict address adjust" + "baby bachelor bacon badge bag balance balcony ball ba= mboo banana banner bar barely bargain barrel base basic" + "basket battle beach bean beauty because become beef b= efore begin behave behind" + "cabbage cabin cable cactus cage cake call calm camera= camp can canal cancel candy cannon canoe canvas canyon" + "capable capital captain car carbon card cargo carpet = carry cart case" + "daisy damage damp dance danger daring dash daughter d= awn day deal debate debris decade december decide decline" + "decorate decrease deer defense define defy degree del= ay deliver demand demise denial"; + +#define PUSH_BUNDLE_SIZE_TEST 184 + +static void +test_send_push_msg0(void **state) +{ + i =3D 0; + res =3D r0; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg0, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} +static void +test_send_push_msg1(void **state) +{ + i =3D 0; + res =3D r1; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg1, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} + +static void +test_send_push_msg2(void **state) +{ + i =3D 0; + res =3D NULL; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg2, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), -EINVAL); +} + +static void +test_send_push_msg3(void **state) +{ + i =3D 0; + res =3D r3; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg3, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} + +static void +test_send_push_msg4(void **state) +{ + i =3D 0; + res =3D r4; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg4, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} + +static void +test_send_push_msg5(void **state) +{ + i =3D 0; + res =3D r5; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg5, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} + +static void +test_send_push_msg6(void **state) +{ + i =3D 0; + res =3D r6; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg6, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} + +static void +test_send_push_msg7(void **state) +{ + i =3D 0; + res =3D r7; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg7, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} + +static void +test_send_push_msg8(void **state) +{ + i =3D 0; + res =3D r8; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg8, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} + +static void +test_send_push_msg9(void **state) +{ + i =3D 0; + res =3D r9; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg9, UPT_BY_CID, PUSH_BUND= LE_SIZE_TEST), 1); +} + +static void +test_send_push_msg10(void **state) +{ + i =3D 0; + res =3D NULL; + struct multi_context *m =3D *state; + const unsigned long cid =3D 0; + assert_int_equal(send_push_update(m, &cid, msg10, UPT_BY_CID, PUSH_BUN= DLE_SIZE_TEST), -EINVAL); +} + +#undef PUSH_BUNDLE_SIZE_TEST + +static int +setup2(void **state) +{ + struct multi_context *m =3D calloc(1, sizeof(struct multi_context)); + m->instances =3D calloc(1, sizeof(struct multi_instance *)); + struct multi_instance *mi =3D calloc(1, sizeof(struct multi_instance)); + *(m->instances) =3D mi; + *state =3D m; + return 0; +} + +static int +teardown2(void **state) +{ + struct multi_context *m =3D *state; + free(*(m->instances)); + free(m->instances); + free(m); + return 0; +} +#endif /* ifdef ENABLE_MANAGEMENT */ + static int setup(void **state) { @@ -249,7 +510,20 @@ cmocka_unit_test_setup_teardown(test_incoming_push_message_1, setu= p, teardown), cmocka_unit_test_setup_teardown(test_incoming_push_message_bad_for= mat, setup, teardown), cmocka_unit_test_setup_teardown(test_incoming_push_message_mix, se= tup, teardown), - cmocka_unit_test_setup_teardown(test_incoming_push_message_mix2, s= etup, teardown) + cmocka_unit_test_setup_teardown(test_incoming_push_message_mix2, s= etup, teardown), +#ifdef ENABLE_MANAGEMENT + cmocka_unit_test_setup_teardown(test_send_push_msg0, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg1, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg2, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg3, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg4, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg5, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg6, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg7, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg8, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg9, setup2, teard= own2), + cmocka_unit_test_setup_teardown(test_send_push_msg10, setup2, tear= down2) +#endif }; return cmocka_run_group_tests(tests, NULL, NULL); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/869?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ie82bcc7a8e583de9156b185d71d1a323ed8df3fc Gerrit-Change-Number: 869 Gerrit-PatchSet: 26 Gerrit-Owner: mrbff Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: stipa Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --KiFb7I8WPIo= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

PUSH_UPDATE message sender: enabling the serve=
r to send PUSH_UPDATE control messages

Using the management interfac= e you can now target one or more clients
(via broadcast or via cid) and = send a PUSH_UPDATE control message
to update some options. See doc/mana= gement-notes.txt for details.

Change-Id: Ie82bcc7a8e583de9156b185d71= d1a323ed8df3fc
Signed-off-by: Marco Baffo <marco@...2726...>
Ac= ked-by: Gert Doering <gert@...1296...>
Message-Id: <20250903164= 826.13284-1-gert@...1296...>
URL: https://www.mail-archive.com/openvp= n-devel@lists.sourceforge.net/msg32807.html
Signed-off-by: Gert Doering = <gert@...1296...>
---
M CMakeLists.txt
M doc/management-note= s.txt
M src/openvpn/manage.c
M src/openvpn/manage.h
M src/openvpn/= multi.c
M src/openvpn/multi.h
M src/openvpn/options.c
M src/openvp= n/options_util.c
M src/openvpn/push.c
M src/openvpn/push.h
M src/o= penvpn/push_util.c
M tests/unit_tests/openvpn/Makefile.am
M tests/uni= t_tests/openvpn/test_push_update_msg.c
13 files changed, 741 insertions(= +), 18 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35513= e9..f027b01 100644
--- a/CMakeLists.txt
+++= b/CMakeLists.txt
@@ -874,9 +874,10 @@
= target_sources(test_push_update_msg PRIVATE
tests= /unit_tests/openvpn/mock_msg.c
tests/unit_tests/op= envpn/mock_get_random.c
- src/openvpn/push_util.c
- src/openvpn/options_util.c
- src/openvpn/otime.c
+ src/openvpn/push_util.c
+ src/openvpn/options_util.c
+ src/openvpn/otim= e.c
+ src/open= vpn/list.c
)

= if (TARGET test_argv)
diff --git a/doc/management-notes.t= xt b/doc/management-notes.txt
index f1d2930..1a5c311 100644=
--- a/doc/management-notes.txt
+++ b/doc/m= anagement-notes.txt
@@ -1028,6 +1028,35 @@
= stored outside of the filesystem (e.g. in Mac OS X Keychain)
with OpenVPN via the management interface.


= +COMMAND -- push-update-broad (= OpenVPN 2.7 or higher)
+Send a message to every connected clien= t to update options at runtime.
+The updatable options are: "block-ipv6", "block-= outside-dns", "dhcp-option",
+"dns", "ifconfig", "ifconf= ig-ipv6", "redirect-gateway", "redirect-private",<= /span>
+"route", &= quot;route-gateway", "route-ipv6", "route-metric",= "topology",
+delete every previous value and set new value, so the update of th= e option will
+not be= incremental even when theoretically possible (ex. with "redirect-gate= way").
+The '= ;-' symbol in front of an option means the option should be removed.
+When an option is used= with '-', it cannot take any parameter.
+The '?' symbol in front of an option m= eans the option's update is optional
+so if the client do not support it, that option will j= ust be ignored without
+
+Option Format Ex.=
+ `-?option`, `-opt= ion`, `?option parameters` are valid formats,
+ `?-option` is not a valid format.
+

+Example
+ push-update-broad "route 10.10.10.1 255.255.255.255, -dns= , ?tun-mtu 1400"
+
+COMMAND -- push-u= pdate-cid (OpenVPN 2.7 or higher)
+----------------------------------------------------+Same as push-update-broad bu= t you must target a single client using client id.
+
+Example
+= push-update-cid 42 "route 10.10.10.1 255.255.255.255, -dns, ?tun-mtu= 1400"
+<= br> OUTPUT FORMAT
-------------

diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 5b2a7de..114e4c6 100644
--- a/src/openvpn= /manage.c
+++ b/src/openvpn/manage.c
@@ -41= ,6 +41,7 @@
#include "manage.h"
= #include "openvpn.h"
#include "dco.h"=
+#include "push= .h"
#include "multi.h"

#include "memdbg.h"
@@ -132,8 +133= ,10 @@
msg(M_CLIENT, "test n : Pr= oduce n lines of output for testing/debugging.");
= msg(M_CLIENT, "username type u : Enter username u for a querie= d OpenVPN username.");
msg(M_CLIENT, "verb [= n] : Set log verbosity level to n, or show if n is absent.&qu= ot;);
- msg(M_CLIENT= ,
- "versio= n [n] : Set client's version to n or show current version of= daemon.");
+ = msg(M_CLIENT, "version [n] : Set client's version to n= or show current version of daemon.");
+ msg(M_CLIENT, "push-update-broad options := Broadcast a message to update the specified options.");
+ msg(M_CLIENT, " = Ex. push-update-broad \"route something, -dns\"= ;");

+ msg(M_= CLIENT, "push-update-cid CID options : Send an update message to the c= lient identified by CID.");
msg(M_CLIENT, "E= ND");
}

@@ -1333,6 = +1336,48 @@
}

static vo= id
+man_push_update(s= truct management *man, const char **p, const push_update_type type)<= br>+{
+ bool status =3D false;
+
+ if (type =3D=3D UPT_BROADCAST)
+ {
+ if (!man->persist.callback.push_update_broad= cast)
+ {
+ man_command_= unsupported("push-update-broad");
+ return;
+ }
+
+ = status =3D (*man->persist.callback.push_update_broadcast)(man->per= sist.callback.arg, p[1]);
+ }
+ else= if (type =3D=3D UPT_BY_CID)
+ {
+ = if (!man->persist.callback.push_update_by_cid)
+ {
+ man_command_unsupported("push-upda= te-cid");
+ = return;
+ = }
+
+ unsigned long cid =3D 0;
+
+ if (!parse_cid(p[1], &cid))<= /span>
+ {
= + msg(M_CLIENT, &quo= t;ERROR: push-update-cid fail during cid parsing");
+ return;
+ }
+
+ status =3D (*man->persist.callback.push_update_by_cid)(m= an->persist.callback.arg, cid, p[2]);
+ }
+
+ if (stat= us)
+ {
= + msg(M_CLIENT, "SU= CCESS: push-update command succeeded");
+ return;
+ }
+ msg(M_CLIENT, "ERROR: push-update command failed");
+}
+
+static void
man_dispatch_command(struct ma= nagement *man, struct status_output *so, const char **p,
= const int nparms)
{
@@= -1655,6 +1700,20 @@
man_remote(man, p);
}
}
+ else if (streq(p[0], "push-update-broad&q= uot;))
+ {<= br>+ if (man_need(man, p= , 1, 0))
+ {
+ man_push_= update(man, p, UPT_BROADCAST);
+ }
= + }
+ else if (= streq(p[0], "push-update-cid"))
+ {
+ if (man_need(man, p, 2, 0))
+ {
+ man_push_update(man, p, UPT_BY_CID);
+ }

+ }
#if 1
else if (streq(p[0], "test"))

{

diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h
index 0b064cf..0bce25e 100644
--- a/src/openvpn/= manage.h
+++ b/src/openvpn/manage.h
@@ -43,= 7 +43,6 @@
#define MF_EXTERNAL_KEY_PSSPAD (1u << = 16)
#define MF_EXTERNAL_KEY_DIGEST (1u << 17)

-=
#ifdef ENABLE_MANAGEMENT

#inc= lude "misc.h"
@@ -197,6 +196,8 @@
#endif

unsigned int (*remote_entry_count)(void *arg)= ;
bool (*remote_entry_get)(void *arg, unsigned int ind= ex, char **remote);
+= bool (*push_update_broadcast)(void *arg, const char *options);+ bool (*push_update_by_ci= d)(void *arg, unsigned long cid, const char *options);
};<= /span>

/*
diff --git a/src/open= vpn/multi.c b/src/openvpn/multi.c
index f1abdbe..85975ff 10= 0644
--- a/src/openvpn/multi.c
+++ b/src/op= envpn/multi.c
@@ -3996,7 +3996,7 @@
}<= /span>
}

-static struct multi_instance *
+struct multi_instance *
lookup_b= y_cid(struct multi_context *m, const unsigned long cid)
{<= /span>
if (m)
@@ -4137,6 +4137,8 @@ cb.client_auth =3D management_client_auth;
= cb.client_pending_auth =3D management_client_pending_auth;<= br> cb.get_peer_info =3D management_get_peer_info;
= + cb.push_update_broadca= st =3D management_callback_send_push_update_broadcast;
+ cb.push_update_by_cid =3D manage= ment_callback_send_push_update_by_cid;
management_= set_callback(management, &cb);
}
= #endif /* ifdef ENABLE_MANAGEMENT */
@@ -4261,3 +4263,47 @@=
multi_top_free(&multi);
clos= e_instance(top);
}
+
+/**=
+ * Update the vhash= with new IP/IPv6 addresses in the multi_context when a
+ * push-update message containing ifcon= fig/ifconfig-ipv6 options is sent
+ * from the server. This function should be called after a pu= sh-update
+ * and old= _ip/old_ipv6 are the previous addresses of the client in
+ * ctx->options.ifconfig_local and = ctx->options.ifconfig_ipv6_local.
+ */
= +void
+update_vhash(s= truct multi_context *m, struct multi_instance *mi, const char *old_ip, cons= t char *old_ipv6)
+{<= /span>
+ struct in_addr a= ddr;
+ struct in6_= addr new_ipv6;
+
+ if ((mi->context.= options.ifconfig_local && (!old_ip || strcmp(old_ip, mi->context= .options.ifconfig_local)))
+ && inet_pton(AF_INET, mi->context.options.ifconfi= g_local, &addr) =3D=3D 1)
+ {
+ = in_addr_t new_ip =3D ntohl(addr.s_addr);
+
+ /* Add new IP */
+ multi_learn_in_addr_t(m, mi, new_ip, -1, true);+ }
+
+ /* TO DO:
+ * else if (old_ip)
+ * {
+ * // remove old IP
+ * }
++ if ((mi->context.opti= ons.ifconfig_ipv6_local && (!old_ipv6 || strcmp(old_ipv6, mi->co= ntext.options.ifconfig_ipv6_local)))
+ && inet_pton(AF_INET6, mi->context.opti= ons.ifconfig_ipv6_local, &new_ipv6) =3D=3D 1)
+ {
+ /* Add new IPv6 */
+ multi_learn_in6_addr(m, mi, new_ipv6, -1, tr= ue);
+ }+
+ /* TO DO:
+ * else if (old_ipv6)
+ * {
+ * // remove old IPv6
+ * }
+ */
+}
diff --git a/src/openvpn/multi.h b/src/openvpn/mul= ti.h
index e87e465..087c0e6 100644
--- a/sr= c/openvpn/multi.h
+++ b/src/openvpn/multi.h
@@ -686,5 +686,12 @@

*/
void multi_assi= gn_peer_id(struct multi_context *m, struct multi_instance *mi);
<= span>

+#ifdef ENABLE= _MANAGEMENT
+struct m= ulti_instance *
+look= up_by_cid(struct multi_context *m, const unsigned long cid);
+#endif

+
+void
+update= _vhash(struct multi_context *m, struct multi_instance *mi, const char *old_= ip, const char *old_ipv6);

#endif /* MUL= TI_H */
diff --git a/src/openvpn/options.c b/src/openvpn/op= tions.c
index a268b92..0616a17 100644
--- a= /src/openvpn/options.c
+++ b/src/openvpn/options.c@@ -5488,7 +5488,6 @@
{
continue; /* Ignoring this option */

= }
- = throw_signal_soft(SIGUSR1, "Offending option received from server&qu= ot;);
return false; /* Cause push/pull error a= nd stop push processing */
}

diff --git a/src/openvpn/options_util.c b/src/openvpn/options_= util.c
index be1eefc..28f1f9e 100644
--- a/= src/openvpn/options_util.c
+++ b/src/openvpn/options_util.c=
@@ -236,11 +236,11 @@
{
if (*flags & PUSH_OPT_OPTIONAL)

{<= /span>
- msg(D_PUSH= , "Pushed option is not updatable: '%s'. Ignoring.", line= );
+ msg(D= _PUSH, "Pushed dispensable option is not updatable: '%s'. Igno= ring.", line);
}
els= e
{
- msg(M_WARN, "Pushed option is not updatable: '%= s'. Restarting.", line);
+ msg(M_WARN, "Pushed option is not updatable:= '%s'.", line);
return false;
}
}
diff --git a= /src/openvpn/push.c b/src/openvpn/push.c
index 4f6adfc..1ea= 7ed9 100644
--- a/src/openvpn/push.c
+++ b/= src/openvpn/push.c
@@ -1073,6 +1073,10 @@
= break;
}
= }
+ el= se
+ {<= br>+ throw_signal_so= ft(SIGUSR1, "Offending option received from server");
<= span style=3D"color: hsl(120, 100%, 40%);">+ }

= }
else if (ch =3D=3D '\0')
= {
@@ -1100,7 +1104,7 @@
}
= else if (honor_received_options && buf_string_compare_ad= vance(&buf, push_update_cmd))
{
- return process_incoming_push_upd= ate(c, permission_mask, option_types_found, &buf);
+ return process_incoming_push_upd= ate(c, permission_mask, option_types_found, &buf, false);
}

else
{
= diff --git a/src/openvpn/push.h b/src/openvpn/push.h
index = 22b940f..8ffd0c2 100644
--- a/src/openvpn/push.h
= +++ b/src/openvpn/push.h
@@ -41,6 +41,15 @@ #define PUSH_OPT_TO_REMOVE (1 << 0)
#define = PUSH_OPT_OPTIONAL (1 << 1)

+#ifdef ENABLE_MANAGEMENT
+/* Push-update message sender modes = */
+typedef enum
+{
+ UPT_BROADCAST =3D 0,
+ UPT_BY_CID =3D 1
+} push_update_type;

+#endif

+
int process_incoming_push_requ= est(struct context *c);

/**
@@ -56,6 +65,7 @@

* @param option_types_found A point= er to a variable that will be filled with the types of options
* found in the message.
*= @param buf A buffer containing the received message.
+ * @param msg_sender A boolean indicating= if function is called by the message sender (server).
*<= /span>
* @return
* - `PUSH_MSG_UPDATE`: The me= ssage was processed successfully, and the updates were applied.
<= span>@@ -65,7 +75,8 @@

*/

int process_incoming_push_update(struct context *c, unsigned int permis= sion_mask,
- = unsigned int *option_types_found, struct buffer *buf)= ;
+ = unsigned int *option_types_found, struct buffer *buf,=
+ = bool msg_sender);

int process_inc= oming_push_msg(struct context *c, const struct buffer *buffer,
bool honor_received_options, unsigned in= t permission_mask,
@@ -127,4 +138,28 @@
*= /
void receive_auth_pending(struct context *c, const struc= t buffer *buffer);

+#ifdef ENABLE_MANAGEMENT
+/**
+ * @brief A function to send a PUSH_UPDATE control message from serve= r to client(s).
+ *
+ * @param m the multi= _context, contains all the clients connected to this server.
+ * @param target the target to whi= ch to send the message. It should be:

+ * `NULL` if `type =3D=3D UPT_BROADCAST`,
+ * a `mroute_addr *` if `type =3D= =3D UPT_BY_ADDR`,
+ *= a `char *` if `type =3D=3D UPT_BY_CN`,
+ * an `unsigned long *` if `type =3D=3D UPT_BY_CID`.

+ * @param msg a string= containing the options to send.
+ * @param type the way to address the message (broadcast, by c= id, by cn, by address).
+ * @param push_bundle_size the maximum size of a bundle of pushed optio= n. Just use PUSH_BUNDLE_SIZE macro.
+ * @return the number of clients to which the message was s= ent.
+ */
<= span style=3D"color: hsl(120, 100%, 40%);">+int
+send_push_update(struct multi_context *m, const= void *target, const char *msg, const push_update_type type, const int push= _bundle_size);
+
+bool management_callback= _send_push_update_broadcast(void *arg, const char *options);
+

+bool management_callback_send_push_update_by_cid(void= *arg, unsigned long cid, const char *options);
+
+#endif /* ifdef ENABLE_MANAGEMENT*/
+
#endif /* ifndef PUSH_H */
diff --git a/src/openvpn/push_util.c b/src/openvpn/push_util.c
index 0862a74..bd3992b 100644
--- a/src/open= vpn/push_util.c
+++ b/src/openvpn/push_util.c
@@ -3,10 +3,16 @@

#endif

#include "push.h"

+#include "buffer.h"
+
+#ifdef ENABLE_MANAGEMENT
+#include "multi.h"
+#endif

int
<= span> process_incoming_push_update(struct context *c, unsigned int permissi= on_mask,
- = unsigned int *option_types_found, struct buffer *buf)
+ = unsigned int *option_types_found, struct buffer *buf,
+ bool msg= _sender)
{
int ret =3D PUSH_MSG_ERROR= ;
const uint8_t ch =3D buf_read_u8(buf);
@@ -27,6 +33,10 @@

break; }
}
+ else if (!msg_sender)
+ {
+ throw_signal_soft(SIGUSR1, "O= ffending option received from server");
+ }
}
= else if (ch =3D=3D '\0')
{
@@ -35,3 +45,260 @@

return ret;

}
+
+#ifdef ENABLE_MANAGEMEN= T
+/**
+ * Return index of last `,` or `0`= if it didn't find any.

+ * If there is a comma at index `0` it's an error anyway=
+ */
+static int
+find_first_comma_of_next_bundle(const char *str, i= nt ix)
+{
<= span style=3D"color: hsl(120, 100%, 40%);">+ while (ix > 0)+ {
+ if (str[ix] =3D=3D ',')
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ return ix;
+ }
+ ix--;
+ }
+ return 0;
+}
+=
+/* Allocate memory and ass= emble the final message */
+static struct buffer
+forge_msg(const char *src, const char *continuation, struct gc_aren= a *gc)
+{
<= span style=3D"color: hsl(120, 100%, 40%);">+ int src_len =3D strlen(src)= ;
+ int con_len = =3D continuation ? strlen(continuation) : 0;
+ struct buffer buf =3D alloc_buf_gc(src_len + s= izeof(push_update_cmd) + con_len + 2, gc);
+
+ buf_printf(&buf, "%s,%s%s", push_update_cmd, src, con= tinuation ? continuation : "");
+
+}=
+
+static char *
+gc_strdup(const char *src, struct gc_arena *= gc)
+{
+ char *ret =3D gc_malloc((strle= n(src) + 1) * sizeof(char), true, gc);
+
+= strcpy(ret, src);
+ return ret;
+}<= /span>
+
+/* It split the messagge (if necessay) = and fill msgs with the message chunks.
+ * Return `false` on failure an `true` on success.
+ */
+static bool
+message_splitter(const char *s, struct buffer *ms= gs, struct gc_arena *gc, const int safe_cap)
+{
+ if (!s || !*s)
+ {
+ = return false;
+ }<= /span>
+
+ char *str =3D gc_strdup(s, gc);
+ int i =3D 0;=
+ int im =3D 0;+
+ while (*str)
+ {
+ /* + ',' - '/0' */
+ if (strlen(str) > safe_cap)

+ {
+ int ci =3D find_firs= t_comma_of_next_bundle(str, safe_cap);
+ if (!ci)
+ {
+ /* if no commas were found go to fail, do not= send any message */
= + return false;
+ }
+ str[ci] =3D '\0';
+ /* copy from i to (ci -1) */
<= span style=3D"color: hsl(120, 100%, 40%);">+ msgs[im] =3D forge_= msg(str, ",push-continuation 2", gc);
+ i =3D ci + 1;
+ }
+ else
+ {
+ if (im)
+ {
= + msgs[im] =3D forge_msg(str, ",push-continuation 1&quo= t;, gc);
+ = }
+ else<= /span>
+ {=
+ msgs[im] = =3D forge_msg(str, NULL, gc);
+ }
+ i =3D strlen(str);
+ }
+ str =3D &str[i];
+ im++;
+ }
+ re= turn true;
+}<= br>+
+/* send the message(s) prepared to one single = client */
+static boo= l
+send_single_push_u= pdate(struct context *c, struct buffer *msgs, unsigned int *option_types_fo= und)
+{
+ if (!msgs[0].data || !*(msgs[= 0].data))

+ {
+ return false;

+ }
+ int i =3D -1;
+
+ while (msgs[++i].data && *(msgs[i].data))
+ {
+ if (!send_control_channel_str= ing(c, BSTR(&msgs[i]), D_PUSH))
+ {
+ return false;
+ }
+
+ /* After = sending the control message, we update the options
+ * server-side in the client's c= ontext so pushed options like
+ * ifconfig/ifconfig-ipv6 can actually work.
+ * If we don't do th= at, packets arriving from the client with the

+ * new address will be rejected and packe= ts for the new address
+ * For the same reason we later u= pdate the vhash too in
+ */
+ buf_string_compare_advance(&msgs[i], push_upda= te_cmd);
+ if = (process_incoming_push_update(c, pull_permission_mask(c), option_types_foun= d, &msgs[i], true) =3D=3D PUSH_MSG_ERROR)
+ {
+ msg(M_WARN, "Failed to process push update= message sent to client ID: %u",
+ c->c2.tls_multi ? c->c2.tls_multi-&= gt;peer_id : UINT32_MAX);
+ continue;
+ }
+ = c->options.push_option_types_found |=3D *option_types_found;
+ if (!options_post= process_pull(&c->options, c->c2.es))
+ {
+ msg(M_WARN, "Failed to post-process push = update message sent to client ID: %u",
+ c->c2.tls_multi ? c->c2.tls_m= ulti->peer_id : UINT32_MAX);
+ }
+ }
+ return t= rue;
+}
+

+int
+send_push_update(struct multi_context *m, const void *target, const = char *msg, const push_update_type type, const int push_bundle_size)<= br>+{
+ if (!msg || !*msg || !m
+ || (!target && type != =3D UPT_BROADCAST))
+= {
+ return= -EINVAL;
+ }
+
+ struct gc_arena gc =3D gc_new();
+ /* extra space for p= ossible trailing ifconfig and push-continuation */
+ const int extra =3D 84 + sizeof(push_upd= ate_cmd);
+ /* pus= h_bundle_size is the maximum size of a message, so if the message+ * we want to send exceed= s that size we have to split it into smaller messages */
+ const int safe_cap =3D push_bundle= _size - extra;
+ i= nt msgs_num =3D (strlen(msg) / safe_cap) + ((strlen(msg) % safe_cap) !=3D 0= );
+ struct buffer= *msgs =3D gc_malloc((msgs_num + 1) * sizeof(struct buffer), true, &gc)= ;
+
+ unsigned int option_types_found = =3D 0;
+
+ msgs[msgs_num].data =3D NULL= ;

+ if (!message_s= plitter(msg, msgs, &gc, safe_cap))
+ {
+ gc_free(&gc);
+ return -EINVAL;
+ }
= +
+ if (type =3D= =3D UPT_BY_CID)
+ = {
+ struct mul= ti_instance *mi =3D lookup_by_cid(m, *((unsigned long *)target));+
+ if (!mi)
+ {
+ return -ENOENT;
+ }
+
+ = const char *old_ip =3D mi->context.options.ifconfig_local;
+ const char *old_ipv6 =3D= mi->context.options.ifconfig_ipv6_local;

+ if (!mi->halt
+ && send_single_push_updat= e(&mi->context, msgs, &option_types_found))
+ {
+ if (option_types_found & OPT_P_UP)=
+ {
+ update_vh= ash(m, mi, old_ip, old_ipv6);
+ }
+ gc_free(&gc);
+ return 1;
+ }
+ else
+ = {
+ = gc_free(&gc);
+ = return 0;
= + }
+ }
+
+ int count =3D 0;
+ struct hash_iterator hi;
<= span style=3D"color: hsl(120, 100%, 40%);">+ const struct hash_element *= he;

+
+ hash_iterator_init(m->iter, = &hi);

+ while = ((he =3D hash_iterator_next(&hi)))
+ {
+ struct multi_instance *curr_mi =3D he->value;
+
+ if (curr_mi->halt)
+ {
+ continue;
+ }
+
+ = /* Type is UPT_BROADCAST so we update every client */
+ option_types_found =3D 0;
+ const char *ol= d_ip =3D curr_mi->context.options.ifconfig_local;
+ const char *old_ipv6 =3D curr_mi-= >context.options.ifconfig_ipv6_local;
+ if (!send_single_push_update(&curr_mi->= context, msgs, &option_types_found))
+ {
+ msg(M_CLIENT, "ERROR: Peer ID: %u has not been = updated",
+ = curr_mi->context.c2.tls_multi ? curr_mi->context.c2.tls_mu= lti->peer_id : UINT32_MAX);
+ continue;
+ }
+ {
+ update_vhash(m, curr_mi, old_ip, old_ipv6);=
+ }+ count++;
+ }

+
+ hash_iterator_free(&hi);
+ gc_free(&gc);
+ return count;
+}
+
+#define RETURN= _UPDATE_STATUS(n_sent) \
+ do = \
+ { = \
+ = if ((n_sent) > 0) \+ { = \
+ msg(M_CLIENT, "SUCCESS: %d client(= s) updated", (n_sent)); \
+ return true; = \
+ } = \
+ else = \
+ { = \
+ = msg(M_CLIENT, "ERROR: no client updated"); \=
+ return = false; \
+ } = \
+ } while (0)
+
+
<= span style=3D"color: hsl(120, 100%, 40%);">+bool
+management_callback_send_push_update_broadcast= (void *arg, const char *options)
+{
+ i= nt n_sent =3D send_push_update(arg, NULL, options, UPT_BROADCAST, PUSH_BUND= LE_SIZE);
++ RETURN_UPDATE_STATUS(n_se= nt);
+}
+
+bool
+management_callback_send_push_update_by_cid(void *arg, unsigned lon= g cid, const char *options)
+{
+ int n_= sent =3D send_push_update(arg, &cid, options, UPT_BY_CID, PUSH_BUNDLE_S= IZE);
+
+ RETURN_UPDATE_STATUS(n_sent);=
+}
+#endif /* ifdef ENABLE_MANAGEMENT */<= /span>
diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/u= nit_tests/openvpn/Makefile.am
index 7a7fec7..ec8cc69 100644=
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am

@@ -337,7 +337,= 8 @@
$(top_srcdir)/src/openvpn/platform.c \
$(top_srcdir)/src/openvpn/push_util.c \
$(top_srcdir= )/src/openvpn/options_util.c \
- $(top_srcdir)/src/openvpn/otime.c
+ $(top_srcdir)/src/openvpn/otime.c \
+ $(top_srcdir)/src/openvpn/list.c<= /span>

socket_testdriver_CFLAGS =3D \ -I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir= )/src/openvpn \
diff --git a/tests/unit_tests/openvpn/test_= push_update_msg.c b/tests/unit_tests/openvpn/test_push_update_msg.c<= br>index 0f4ad41..87329b1 100644
--- a/tests/unit_tes= ts/openvpn/test_push_update_msg.c
+++ b/tests/unit_tests/op= envpn/test_push_update_msg.c
@@ -8,9 +8,16 @@
#include <cmocka.h>
#include "push.h"<= /span>
#include "options_util.h"
+#include "multi.h"

/* mocks */

+void
+throw_signal_soft(const int signum, const char *signal_t= ext)
+{
+ msg(M_WARN, "Offending o= ption received from server");
+}
+
unsigned int
pull_permission_mask(const str= uct context *c)
{
@@ -21,6 +28,18 @@

return flags;
}
+void
+update_vhash(struct multi_context *m, str= uct multi_instance *mi, const char *old_ip, const char *old_ipv6)+{
+ return;
+}
+
+bool
+options_postprocess_pull(struct = options *options, struct env_set *es)
+{
+= return true;
+}
+
boo= l
apply_push_options(struct context *c, struct options *op= tions, struct buffer *buf,
unsigned int= permission_mask, unsigned int *option_types_found,
@@ -48,= 7 +67,6 @@
{
= continue; /* Ignoring this option */
= }
- m= sg(M_WARN, "Offending option received from server");
return false; /* Cause push/pull error and stop push p= rocessing */

}
}
@@ -77,7 +95,7 @@
}
e= lse if (honor_received_options && buf_string_compare_advance(&b= uf, push_update_cmd))
{
- return process_incoming_push_update(c, permi= ssion_mask, option_types_found, &buf);
+ return process_incoming_push_update(c, permi= ssion_mask, option_types_found, &buf, false);
}

else
{
@@ -85,6 +10= 3,49 @@
}
}
<= br>+const char *
+tls_common_name(const struct tls_m= ulti *multi, const bool null)
+{
+ retu= rn NULL;
+}+
+#ifndef ENABLE_MANAGEMENT
+bool
+send_control_channel_string(struct context *c, const cha= r *str, int msglevel)
+{
+ return true;=
+}
+#else /* ifndef ENABLE_MANAGEMENT */=
+char **res;<= br>+int i;
+
+bool
= +send_control_channel_string(struct context *c, const char *str, int msglev= el)
+{
+ if (res && res[i] &= ;& strcmp(res[i], str))
+ {
+ = printf("\n\nexpected: %s\n\n actual: %s\n\n", res[i], str);
+ return false;<= /span>
+ }
+ i++;

+ return true;
+}
+
+struct mul= ti_instance *
+lookup= _by_cid(struct multi_context *m, const unsigned long cid)
+{
+ return *(m->instances);
+}
+
+bool
+mroute_extract_openvp= n_sockaddr(struct mroute_addr *addr,
+ const struct openvpn_socka= ddr *osaddr,
+ = bool use_port)
+{
+ return true;
+}=
+#endif /* ifndef EN= ABLE_MANAGEMENT */
+<= /span>
/* tests */

static void=
@@ -120,7 +181,6 @@
free_buf(&buf= );
}

-
static void
test_incom= ing_push_message_error2(void **state)
{
@@= -219,6 +279,207 @@
free_buf(&buf);
}


+char *r0[] =3D {
+ "PUSH_UPDATE,redirect-gateway local,route 192.168.1.0 255.255= .255.0"
+};

+char *r1[] =3D {<= br>+ "PUSH_UPDATE,-dhcp= -option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-= continuation 2",
+ "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,= redirect-gateway local,push-continuation 2",
+ "PUSH_UPDATE,route 192.168.1.0 255.2= 55.255.0,push-continuation 1"
+};
+ch= ar *r3[] =3D {
+ &= quot;PUSH_UPDATE,,,"
+};
+char *r4[] = =3D {
+ "PUSH= _UPDATE,-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalal= alalalaf,push-continuation 2",
+ "PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option= DNS 8.8.8.8, redirect-gateway local,push-continuation 2",
<= span style=3D"color: hsl(120, 100%, 40%);">+ "PUSH_UPDATE, route 19= 2.168.1.0 255.255.255.0,,push-continuation 1"
+};
+char *r5[] =3D {
+ "PUSH_UPDATE,,-dhcp-option, blablalalalalalalalalalalal= alf, lalalalalalalalalalalalalalaf,push-continuation 2",
+ "PUSH_UPDATE, akakakakak= akakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local,push-continu= ation 2",
+ &= quot;PUSH_UPDATE, route 192.168.1.0 255.255.255.0,push-continuation 1"=
+};
+char *r6[] =3D {
+ "PUSH_UPDATE,-dhcp-option,blab= lalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation= 2",
+ "= PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8, redirect-ga= teway 10.10.10.10,,push-continuation 2",
+ "PUSH_UPDATE, route 192.168.1.0 255.255.= 255.0,,push-continuation 1"
+};
+char= *r7[] =3D {
+ &qu= ot;PUSH_UPDATE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,push-continuation 2",
+ "PUSH_UPDATE,,,,,,,,,,,,,,,,,,= ,push-continuation 1"
+};
+char *r8[]= =3D {
+ "PUS= H_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalal= alalalaf,push-continuation 2",
+ "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-optio= n DNS 8.8.8.8,redirect-gateway\n local,push-continuation 2",+ "PUSH_UPDATE,route 1= 92.168.1.0 255.255.255.0\n\n\n,push-continuation 1"
+};
+char *r9[] =3D {
+ "PUSH_UPDATE,,"
+};
+
++const char *msg0 =3D "r= edirect-gateway local,route 192.168.1.0 255.255.255.0";
+const char *msg1 =3D "-dhcp-o= ption,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"<= /span>
+ &= quot; akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway lo= cal,route 192.168.1.0 255.255.255.0";
+const char *msg2 =3D "";
+const char *msg3 =3D ",,";<= /span>
+const char *msg4 =3D= "-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalala= lalalaf,"
+ = " akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redi= rect-gateway local, route 192.168.1.0 255.255.255.0,";
+const char *msg5 =3D ",-dhcp-o= ption, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"=

+ = " akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway l= ocal, route 192.168.1.0 255.255.255.0";
+const char *msg6 =3D "-dhcp-option,blablalala= lalalalalalalalalalf, lalalalalalalalalalalalalalaf, akakakakakakakakakakak= af,"
+ = " dhcp-option DNS 8.8.8.8, redirect-gateway 10.10.10.10,, rou= te 192.168.1.0 255.255.255.0,";
+const char *msg7 =3D ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= ";
+const char *= msg8 =3D "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalal= alalalalalalaf, akakakakakakakakakakakaf,"
+ " dhcp-option DNS 8.8.8= .8,redirect-gateway\n local,route 192.168.1.0 255.255.255.0\n\n\n";
+const char *msg9 =3D &= quot;,";
+
+const char *msg10 =3D &qu= ot;abandon ability able about above absent absorb abstract absurd abuse acc= ess accident account accuse achieve"
+ "acid acoustic acquire acros= s act action actor actress actual adapt add addict address adjust"

+ &qu= ot;baby bachelor bacon badge bag balance balcony ball bamboo banana banner = bar barely bargain barrel base basic"
+ "basket battle beach bean b= eauty because become beef before begin behave behind"
+ "cabbage ca= bin cable cactus cage cake call calm camera camp can canal cancel candy can= non canoe canvas canyon"
+ "capable capital captain car carbon card= cargo carpet carry cart case"
+ "daisy damage damp dance danger da= ring dash daughter dawn day deal debate debris decade december decide decli= ne"
+ = "decorate decrease deer defense define defy degree delay deli= ver demand demise denial";
+
+#define= PUSH_BUNDLE_SIZE_TEST 184
+
+static void<= /span>
+test_send_push_msg0(= void **state)
+{

+ i =3D 0;
<= span style=3D"color: hsl(120, 100%, 40%);">+ res =3D r0;
+ struct multi_context *m =3D *st= ate;
+ const unsig= ned long cid =3D 0;
+= assert_int_equal(send_push_update(m, &cid, msg0, UPT_BY_CID, PUSH_B= UNDLE_SIZE_TEST), 1);
+}
+static void
+test_send_push_msg1(void= **state)
+{+ i =3D 0;
+ res =3D r1;

+ struct multi_context *m =3D *state;=
+ const unsigned = long cid =3D 0;
+ = assert_int_equal(send_push_update(m, &cid, msg1, UPT_BY_CID, PUSH_BUNDL= E_SIZE_TEST), 1);
+}<= /span>
+
+static void
+test_send_push_msg2(void **state)
+{

+ i =3D 0;
+ res =3D NULL;
+ struct multi_context *m =3D *state;
+ const unsigned long cid =3D 0;

+ assert_int_equal(send= _push_update(m, &cid, msg2, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), -EINVAL= );
+}
+
+static void
+test_send_push_msg3(void **state)
+{
+ i =3D 0;
+ res =3D r3;
+ = struct multi_context *m =3D *state;
+ const unsigned long cid =3D 0;
+ assert_int_equal(send_push_update(m, = &cid, msg3, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
+}
+
+s= tatic void
+test_send= _push_msg4(void **state)
+{
+ i =3D 0;<= /span>
+ res =3D r4;
+ struct multi_context= *m =3D *state;
+ = const unsigned long cid =3D 0;
+ assert_int_equal(send_push_update(m, &cid, msg4, UPT_BY_= CID, PUSH_BUNDLE_SIZE_TEST), 1);
+}
+
+static void
+test_send_push_msg5(void **state= )

+{
+ i =3D 0;
+ res =3D r5;
+ struct multi_context *m =3D *state;

+ const unsigned long c= id =3D 0;
+ assert= _int_equal(send_push_update(m, &cid, msg5, UPT_BY_CID, PUSH_BUNDLE_SIZE= _TEST), 1);
+}=
+
+static void
+test_send_push_msg6(void **state)
+{
+ i =3D 0;
+ res =3D r6;
+ struct multi_context *m =3D *state;
+ const unsigned long cid =3D 0;
+ assert_int_equal(send_push_up= date(m, &cid, msg6, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
<= span style=3D"color: hsl(120, 100%, 40%);">+}
+
+static void
+t= est_send_push_msg7(void **state)
+{
+ i= =3D 0;
+ res =3D = r7;
+ struct multi= _context *m =3D *state;
+ const unsigned long cid =3D 0;
+ assert_int_equal(send_push_update(m, &cid, msg7,= UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
+}
+static void
+test_send_push_msg8(void= **state)
+{+ i =3D 0;
+ res =3D r8;

+ struct multi_context *m =3D *state;=
+ const unsigned = long cid =3D 0;
+ = assert_int_equal(send_push_update(m, &cid, msg8, UPT_BY_CID, PUSH_BUNDL= E_SIZE_TEST), 1);
+}<= /span>
+
+static void
+test_send_push_msg9(void **state)
+{

+ i =3D 0;
+ res =3D r9;
+ struct multi_context *m =3D *state;
+ const unsigned long cid =3D 0;=
+ assert_int_equal(send_= push_update(m, &cid, msg9, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
+}
+
+static void
+test_send_push_msg10(void **state)
+{
+ i =3D 0;
+ = res =3D NULL;
+ s= truct multi_context *m =3D *state;
+ const unsigned long cid =3D 0;
+ assert_int_equal(send_push_update(m, &= ;cid, msg10, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), -EINVAL);
+}
+
+#undef PUSH_BUNDLE_SIZE_TEST
+
+static i= nt
+setup2(void **sta= te)
+{
+ struct multi_context *m =3D ca= lloc(1, sizeof(struct multi_context));

+ m->instances =3D calloc(1, sizeof(struct multi_in= stance *));
+ stru= ct multi_instance *mi =3D calloc(1, sizeof(struct multi_instance));<= br>+ *(m->instances) =3D = mi;
+ *state =3D m= ;
+ return 0;
+}
+
+static int
+teardown2(void **state)
+{
+ stru= ct multi_context *m =3D *state;
+ free(*(m->instances));
+ free(m->instances);
+ free(m);
+ return 0;
+}
+#e= ndif /* ifdef ENABLE_MANAGEMENT */
+
static int
setup(void **s= tate)
{
@@ -249,7 +510,20 @@
cmocka_unit_test_setup_teardown(test_incoming_push_message_1, s= etup, teardown),

cmocka_unit_test_setup_teardown(t= est_incoming_push_message_bad_format, setup, teardown),
= cmocka_unit_test_setup_teardown(test_incoming_push_message_mix, setup= , teardown),
- c= mocka_unit_test_setup_teardown(test_incoming_push_message_mix2, setup, tear= down)
+ cmocka= _unit_test_setup_teardown(test_incoming_push_message_mix2, setup, teardown)= ,
+#ifdef ENABLE_MANA= GEMENT
+ cmock= a_unit_test_setup_teardown(test_send_push_msg0, setup2, teardown2),<= br>+ cmocka_unit_test_se= tup_teardown(test_send_push_msg1, setup2, teardown2),
+ cmocka_unit_test_setup_teardown(t= est_send_push_msg2, setup2, teardown2),
+ cmocka_unit_test_setup_teardown(test_send_push_= msg3, setup2, teardown2),
+ cmocka_unit_test_setup_teardown(test_send_push_msg4, setup2, = teardown2),
+ = cmocka_unit_test_setup_teardown(test_send_push_msg5, setup2, teardown2),
+ cmocka_unit_te= st_setup_teardown(test_send_push_msg6, setup2, teardown2),
+ cmocka_unit_test_setup_teard= own(test_send_push_msg7, setup2, teardown2),
+ cmocka_unit_test_setup_teardown(test_send_= push_msg8, setup2, teardown2),
+ cmocka_unit_test_setup_teardown(test_send_push_msg9, set= up2, teardown2),
+ = cmocka_unit_test_setup_teardown(test_send_push_msg10, setup2, teardown= 2)
+#endif
= };

return cmocka_run_grou= p_tests(tests, NULL, NULL);

To view, vi= sit chang= e 869. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie82bcc7a8e583de9156b185d71d= 1a323ed8df3fc
Gerrit-Change-Number: 869
Gerrit-PatchSet: 26
Gerrit-Owner: mrbff <marco@...2726...> <= /div>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: stipa <lstipakov@...277...= >
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--KiFb7I8WPIo=--