From: "mrbff (Code Review)" Date: Thu, 10 Jul 2025 08:11:20 +0000 In-Reply-To: References: Reply-To: marco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277..., gert@...1296... Message-ID: <14163fcabf24d1b2dc910c01be04c541572be837-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="zVzL+KwvwLU="; 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: plaisthos , flichtenheld , stipa Cc: openvpn-devel --zVzL+KwvwLU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, mrbff, plaisthos= , stipa. Hello cron2, flichtenheld, plaisthos, stipa, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/869?usp=3Demail to look at the new patch set (#10). 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, via cid, via common name, via address) and send a PUSH_UPDATE control messa= ge to update some options. Change-Id: Ie82bcc7a8e583de9156b185d71d1a323ed8df3fc Signed-off-by: Marco Baffo --- 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/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 10 files changed, 895 insertions(+), 6 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/69/869/10 diff --git a/CMakeLists.txt b/CMakeLists.txt index 54cf503..1381e03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -861,6 +861,7 @@ 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..58393da 100644 --- a/doc/management-notes.txt +++ b/doc/management-notes.txt @@ -1028,6 +1028,51 @@ 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" + +COMMAND -- push-update-cn (OpenVPN 2.7 or higher) +---------------------------------------------------- +Same as push-update-broad but target the clients based on the provided com= mon name +(usually just one client per common name is permitted except if "duplicate= -cn" option is used). + +Example + push-update-cid Client0 "route 10.10.10.1 255.255.255.255, -dns, ?tun-mt= u 1400" + +COMMAND -- push-update-addr (OpenVPN 2.7 or higher) +---------------------------------------------------- +Same as push-update-broad but target only the client(s) connecting from the +provided address (real address). Support both IPv4 and IPv6. + +Example + push-update-addr 9.9.9.9 1234 "route 10.10.10.1 255.255.255.255, -dns, ?= tun-mtu 1400" + OUTPUT FORMAT ------------- diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 8836e79..251b076 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -24,7 +24,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif - #include "syshead.h" #ifdef ENABLE_MANAGEMENT @@ -42,6 +41,7 @@ #include "manage.h" #include "openvpn.h" #include "dco.h" +#include "push.h" #include "memdbg.h" @@ -124,6 +124,11 @@ 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 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, "push-update-cn CN options : Send an update message to t= he client(s) with the specified Common Name."); + msg(M_CLIENT, "push-update-addr ip port options : Send an update messa= ge to the client(s) connecting from the provided address."); msg(M_CLIENT, "END"); } @@ -1335,6 +1340,154 @@ } static void +man_push_update(struct management *man, const char **p, const push_update_= type type) +{ + if (type =3D=3D UPT_BROADCAST) + { + if (!man->persist.callback.push_update_broadcast) + { + man_command_unsupported("push-update-broad"); + return; + } + + const bool status =3D (*man->persist.callback.push_update_broadcas= t)(man->persist.callback.arg, p[1]); + + if (status) + { + msg(M_CLIENT, "SUCCESS: push-update-broad command succeeded"); + } + else + { + msg(M_CLIENT, "ERROR: push-update-broad command failed"); + } + } + 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; + } + + const bool status =3D (*man->persist.callback.push_update_by_cid)(= man->persist.callback.arg, cid, p[2]); + + if (status) + { + msg(M_CLIENT, "SUCCESS: push-update-cid command succeeded"); + } + else + { + msg(M_CLIENT, "ERROR: push-update-cid command failed"); + } + } + else if (type =3D=3D UPT_BY_CN) + { + if (!man->persist.callback.push_update_by_cn) + { + man_command_unsupported("push-update-cn"); + return; + } + + const bool status =3D (*man->persist.callback.push_update_by_cn)(m= an->persist.callback.arg, p[1], p[2]); + + if (status) + { + msg(M_CLIENT, "SUCCESS: push-update-cn command succeeded"); + } + else + { + msg(M_CLIENT, "ERROR: push-update-cn command failed"); + } + } + else if (type =3D=3D UPT_BY_ADDR) + { + if (!man->persist.callback.push_update_by_addr) + { + man_command_unsupported("push-update-addr"); + return; + } + + const char *ip_str =3D p[1]; + const char *port_str =3D p[2]; + const char *options =3D p[3]; + + if (!strlen(ip_str) || !strlen(port_str)) + { + msg(M_CLIENT, "ERROR: push-update-addr parse"); + return; + } + + struct addrinfo *res =3D NULL; + int port =3D atoi(port_str); + + if (port < 1 || port > 65535) + { + msg(M_CLIENT, "ERROR: port number is out of range: %s", port_s= tr); + return; + } + + int status =3D openvpn_getaddrinfo(GETADDR_MSG_VIRT_OUT, ip_str, p= ort_str, 0, NULL, AF_UNSPEC, &res); + + if (status !=3D 0 || !res) + { + msg(M_CLIENT, "ERROR: error resolving address: %s (%s)", ip_st= r, gai_strerror(status)); + return; + } + + struct addrinfo *rp; + bool found_client =3D false; + + /* Iterate through resolved addresses */ + for (rp =3D res; rp !=3D NULL; rp =3D rp->ai_next) + { + struct openvpn_sockaddr saddr; + struct mroute_addr maddr; + + CLEAR(saddr); + switch (rp->ai_family) + { + case AF_INET: + saddr.addr.in4 =3D *((struct sockaddr_in *)rp->ai_addr= ); + break; + + case AF_INET6: + saddr.addr.in6 =3D *((struct sockaddr_in6 *)rp->ai_add= r); + break; + + default: + continue; + } + + if (!mroute_extract_openvpn_sockaddr(&maddr, &saddr, true)) + { + continue; + } + + if ((*man->persist.callback.push_update_by_addr)(man->persist.= callback.arg, &maddr, options)) + { + msg(M_CLIENT, "SUCCESS: push-update sent to %s:%d", ip_str= , port); + found_client =3D true; + break; + } + } + + if (!found_client) + { + msg(M_CLIENT, "ERROR: no client found at address %s:%d", ip_st= r, port); + } + freeaddrinfo(res); + } +} + +static void man_dispatch_command(struct management *man, struct status_output *so, con= st char **p, const int nparms) { struct gc_arena gc =3D gc_new(); @@ -1656,6 +1809,34 @@ 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); + } + } + else if (streq(p[0], "push-update-cn")) + { + if (man_need(man, p, 2, 0)) + { + man_push_update(man, p, UPT_BY_CN); + } + } + else if (streq(p[0], "push-update-addr")) + { + if (man_need(man, p, 3, 0)) + { + man_push_update(man, p, UPT_BY_ADDR); + } + } #if 1 else if (streq(p[0], "test")) { diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index eb19a4e..fd7cb11 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -44,7 +44,6 @@ #define MF_EXTERNAL_KEY_PSSPAD (1<<16) #define MF_EXTERNAL_KEY_DIGEST (1<<17) - #ifdef ENABLE_MANAGEMENT #include "misc.h" @@ -205,6 +204,10 @@ #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); + bool (*push_update_by_cn)(void *arg, const char *cn, const char *optio= ns); + bool (*push_update_by_addr)(void *arg, const struct mroute_addr *maddr= , const char *options); }; /* diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 7f0d890..67a7a79 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -4072,7 +4072,7 @@ } } -static struct multi_instance * +struct multi_instance * lookup_by_cid(struct multi_context *m, const unsigned long cid) { if (m) @@ -4220,6 +4220,10 @@ 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; + cb.push_update_by_cn =3D management_callback_send_push_update_by_c= n; + cb.push_update_by_addr =3D management_callback_send_push_update_by= _addr; management_set_callback(management, &cb); } #endif /* ifdef ENABLE_MANAGEMENT */ @@ -4344,3 +4348,51 @@ 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 (inet_pton(AF_INET, mi->context.options.ifconfig_local, &addr) =3D= =3D 1) + { + in_addr_t new_ip =3D addr.s_addr; + + if (mi->context.options.ifconfig_local && (!old_ip || strcmp(old_i= p, mi->context.options.ifconfig_local))) + { + /* Add new, remove old if exist */ + multi_learn_in_addr_t(m, mi, new_ip, 0, true); + } + } + + /* TO DO: + * else if (old_ip && !mi->context.options.ifconfig_local) + * { + * // remove old ip + * } + */ + + if (inet_pton(AF_INET6, mi->context.options.ifconfig_ipv6_local, &new_= ipv6) =3D=3D 1) + { + if (mi->context.options.ifconfig_ipv6_local && (!old_ipv6 || strcm= p(old_ipv6, mi->context.options.ifconfig_ipv6_local))) + { + /* Add new, remove old if exist */ + multi_learn_in6_addr(m, mi, new_ipv6, 0, true); + } + } + + /* TO DO: + * else if (old_ipv6 && !mi->context.options.ifconfig_ipv6_local) + * { + * // remove old IPv6 + * } + */ +} diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 40f7519..4841075 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -710,5 +710,13 @@ */ 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/push.h b/src/openvpn/push.h index 18dfcd8..e67c3ac 100644 --- a/src/openvpn/push.h +++ b/src/openvpn/push.h @@ -42,6 +42,16 @@ #define PUSH_OPT_TO_REMOVE (1<<0) #define PUSH_OPT_OPTIONAL (1<<1) +/* Push-update message sender modes */ +typedef enum { + UPT_BROADCAST =3D 0, + UPT_BY_ADDR =3D 1, + UPT_BY_CN =3D 2, +#ifdef ENABLE_MANAGEMENT + UPT_BY_CID =3D 3 +#endif +} push_update_type; + int process_incoming_push_request(struct context *c); /** @@ -134,4 +144,33 @@ void receive_auth_pending(struct context *c, const struct buffer *buffer); +/** + * @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); + +#ifdef ENABLE_MANAGEMENT + +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); + +bool management_callback_send_push_update_by_cn(void *arg, const char *cn,= const char *options); + +bool management_callback_send_push_update_by_addr(void *arg, const struct = mroute_addr *maddr, 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 b4d1e8b..1739510 100644 --- a/src/openvpn/push_util.c +++ b/src/openvpn/push_util.c @@ -3,6 +3,8 @@ #endif #include "push.h" +#include "multi.h" +#include "ssl_verify.h" int process_incoming_push_update(struct context *c, @@ -42,3 +44,293 @@ return ret; } + +/** + * 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 asseble the final message */ +static char * +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; + char *ret =3D gc_malloc((src_len + sizeof(push_update_cmd) + con_len += 2) * sizeof(char), true, gc); + int i =3D sizeof(push_update_cmd) -1; + + strcpy(ret, push_update_cmd); + ret[i++] =3D ','; + strcpy(&ret[i], src); + if (continuation) + { + i +=3D src_len; + strcpy(&ret[i], continuation); + } + return ret; +} + +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(char *str, char **msgs, struct gc_arena *gc, const int sa= fe_cap) +{ + if (!str || !*str) + { + return false; + } + + 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; +} + +/* It actually send the already divided messagge to one single client */ +static bool +send_single_push_update(struct context *c, char **msgs, unsigned int *opti= on_types_found) +{ + if (!msgs[0] || !*msgs[0]) + { + return false; + } + int i =3D 0; + struct gc_arena gc =3D gc_new(); + + while (msgs[i] && *msgs[i]) + { + struct buffer buf =3D alloc_buf_gc(strlen(msgs[i]), &gc); + + buf_write(&buf, msgs[i], strlen(msgs[i])); + if (!send_control_channel_string(c, msgs[i], D_PUSH)) + { + return false; + } + i++; + + /* After sending the control message, we update the options server= -side in the client's context */ + buf_string_compare_advance(&buf, push_update_cmd); + if (process_incoming_push_update(c, pull_permission_mask(c), optio= n_types_found, &buf) =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); + } + } + gc_free(&gc); + 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); + char **msgs =3D gc_malloc(sizeof(char *) * (msgs_num + 1), true, &gc); + unsigned int option_types_found =3D 0; + + msgs[msgs_num] =3D NULL; + if (!message_splitter(gc_strdup(msg, &gc), msgs, &gc, safe_cap)) + { + gc_free(&gc); + return -EINVAL; + } + +#ifdef ENABLE_MANAGEMENT + 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; + } + } +#endif /* ifdef ENABLE_MANAGEMENT */ + + 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; + } + if (type =3D=3D UPT_BY_ADDR && !mroute_addr_equal(target, &curr_mi= ->real)) + { + continue; + } + else if (type =3D=3D UPT_BY_CN) + { + const char *curr_cn =3D tls_common_name(curr_mi->context.c2.tl= s_multi, false); + if (strcmp(curr_cn, target)) + { + continue; + } + } + /* Either we found a matching client or type is UPT_BROADCAST so w= e 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; +} + +#ifdef ENABLE_MANAGEMENT +#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 ret =3D send_push_update(arg, &cid, options, UPT_BY_CID, PUSH_BUND= LE_SIZE); + + if (ret =3D=3D -ENOENT) + { + msg(M_CLIENT, "ERROR: no client found with CID: %lu", cid); + } + + return (ret > 0); +} + +bool +management_callback_send_push_update_by_cn(void *arg, const char *cn, cons= t char *options) +{ + int n_sent =3D send_push_update(arg, cn, options, UPT_BY_CN, PUSH_BUND= LE_SIZE); + + RETURN_UPDATE_STATUS(n_sent); +} + +bool +management_callback_send_push_update_by_addr(void *arg, const struct mrout= e_addr *maddr, const char *options) +{ + int n_sent =3D send_push_update(arg, maddr, options, UPT_BY_ADDR, PUSH= _BUNDLE_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 b24e03c..9a40512 100644 --- a/tests/unit_tests/openvpn/Makefile.am +++ b/tests/unit_tests/openvpn/Makefile.am @@ -343,4 +343,5 @@ $(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 \ No newline at end of file + $(top_srcdir)/src/openvpn/otime.c \ + $(top_srcdir)/src/openvpn/list.c \ No newline at end of file diff --git a/tests/unit_tests/openvpn/test_push_update_msg.c b/tests/unit_t= ests/openvpn/test_push_update_msg.c index d0876bc..c65dd08 100644 --- a/tests/unit_tests/openvpn/test_push_update_msg.c +++ b/tests/unit_tests/openvpn/test_push_update_msg.c @@ -8,6 +8,7 @@ #include #include "push.h" #include "options_util.h" +#include "multi.h" /* mocks */ @@ -37,6 +38,12 @@ } bool +options_postprocess_pull(struct options *options, struct env_set *es) +{ + return true; +} + +bool apply_push_options(struct context *c, struct options *options, struct buffer *buf, @@ -94,6 +101,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 @@ -124,7 +174,6 @@ free_buf(&buf); } - static void test_incoming_push_message_error2(void **state) { @@ -209,6 +258,211 @@ 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 "Voil=C3=A0! In view, a humble vaudevillian veteran = cast vicariously as both victim and villain by the vicissitudes" + " of Fate. This visage no mere veneer of vanity is a v= estige of the vox populi now vacant vanished. However this" + " valorous visitation of a by-gone vexation stands viv= ified and has vowed to vanquish these venal and virulent" + " vermin vanguarding vice and vouchsafing the violentl= y vicious and voracious violation of volition. The only" + " verdict is vengeance; a vendetta held as a votive no= t in vain for the value and veracity of such shall one" + " day vindicate the vigilant and the virtuous. Verily = this vichyssoise of verbiage veers most verbose so let" + " me simply add that it is my very good honor to meet = you and you may call me V."; + +#define PUSH_BUNDLE_SIZE_TEST 184 + +void +update_vhash(struct multi_context *m, struct multi_instance *mi, const cha= r *old_ip, const char *old_ipv6) +{ + /* Just a mock */ +} + +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) { @@ -238,7 +492,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: 10 Gerrit-Owner: mrbff Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: stipa Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-Attention: stipa Gerrit-Attention: mrbff Gerrit-MessageType: newpatchset --zVzL+KwvwLU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, mrbff, plais= thos, stipa.

mrbff uploaded patch set #10 to this change.

View Change

PUSH_UPDATE message sender: enabling the server to send PUSH_UPDATE cont=
rol messages

Using the management interface you can now target one o= r more clients (via broadcast,
via cid, via common name, via address) an= d send a PUSH_UPDATE control message
to update some options.

Chan= ge-Id: Ie82bcc7a8e583de9156b185d71d1a323ed8df3fc
Signed-off-by: Marco Ba= ffo <marco@...2726...>
---
M CMakeLists.txt
M doc/management= -notes.txt
M src/openvpn/manage.c
M src/openvpn/manage.h
M src/ope= nvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.h
M src/open= vpn/push_util.c
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_t= ests/openvpn/test_push_update_msg.c
10 files changed, 895 insertions(+),= 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn r=
efs/changes/69/869/10
diff --git a/CMakeLists.txt b/CMakeLists.txt<=
/span>
index 54cf503..1381e03 100644
--- a/CMakeLi= sts.txt
+++ b/CMakeLists.txt
@@ -861,6 +861= ,7 @@
src/openvpn/push_util.c
s= rc/openvpn/options_util.c
src/openvpn/otime.c<= br>+ src/openvpn/list.c<= /span>
)

if (TARGE= T test_argv)
diff --git a/doc/management-notes.txt b/doc/ma= nagement-notes.txt
index f1d2930..58393da 100644
= --- a/doc/management-notes.txt
+++ b/doc/management-n= otes.txt
@@ -1028,6 +1028,51 @@
stored out= side of the filesystem (e.g. in Mac OS X Keychain)
with Op= enVPN 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&quo= t;, "redirect-gateway", "redirect-private",
<= span style=3D"color: hsl(120, 100%, 40%);">+"route", "route-= gateway", "route-ipv6", "route-metric", "topo= logy",

+"tu= n-mtu", "keepalive". When a valid option is pushed, the rece= iving client will
+de= lete every previous value and set new value, so the update of the option wi= ll
+not be increment= al even when theoretically possible (ex. with "redirect-gateway")= .
+The '-' sy= mbol 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 o= ption's update is optional
+so if the client do not support it, that option will just be ign= ored without
+making = fail the entire command. The '-' and '?' symbols can be use= d together.
+<= br>+Option Format Ex.+ `-?option`, `-option`, `?op= tion parameters` are valid formats,
+ `?-option` is not a valid format.
+
+Example
+
+COMMAND -- push-update-ci= d (OpenVPN 2.7 or higher)
+----------------------------------------------------
+Same as push-update-broad but you mu= st target a single client using client id.
+
+Example
+ push-u= pdate-cid 42 "route 10.10.10.1 255.255.255.255, -dns, ?tun-mtu 1400&qu= ot;
+
+COMMAND -- push-update-cn (OpenVPN = 2.7 or higher)

+-----= -----------------------------------------------
+Same as push-update-broad but target the client= s based on the provided common name
+(usually just one client per common name is permitted excep= t if "duplicate-cn" option is used).
+
+Example
+ pu= sh-update-cid Client0 "route 10.10.10.1 255.255.255.255, -dns, ?tun-mt= u 1400"
+=
+COMMAND -- push-update-add= r (OpenVPN 2.7 or higher)
+----------------------------------------------------
+Same as push-update-broad but target= only the client(s) connecting from the
+provided address (real address). Support both IPv4 and = IPv6.
+
+Example
+ push-update-addr 9.9.9.9 1234 "route 1= 0.10.10.1 255.255.255.255, -dns, ?tun-mtu 1400"
+
OUTPUT FORMAT -------------

diff --git a/src/op= envpn/manage.c b/src/openvpn/manage.c
index 8836e79..251b07= 6 100644
--- a/src/openvpn/manage.c
+++ b/s= rc/openvpn/manage.c
@@ -24,7 +24,6 @@
#ifd= ef HAVE_CONFIG_H
#include "config.h"
<= span> #endif
- #include "syshead.h"

= #ifdef ENABLE_MANAGEMENT
@@ -42,6 +41,7 @@
= #include "manage.h"
#include "openvpn.h&qu= ot;
#include "dco.h"
+#include "push.h"

#include "memdbg.h"

<= span>@@ -124,6 +124,11 @@

msg(M_CLIENT, "username= type u : Enter username u for a queried OpenVPN username.");
msg(M_CLIENT, "verb [n] : Set log ve= rbosity level to n, or show if n is absent.");
ms= g(M_CLIENT, "version [n] : Set client's version to n or= show current version of daemon.");
+ msg(M_CLIENT, "push-update-broad options : Br= oadcast a message to update the specified options.");
+ msg(M_CLIENT, " = Ex. push-update-broad \"route something, -dns\"&q= uot;);
+ msg(M_CLI= ENT, "push-update-cid CID options : Send an update message to the clie= nt identified by CID.");
+ msg(M_CLIENT, "push-update-cn CN options : Send an updat= e message to the client(s) with the specified Common Name.");+ msg(M_CLIENT, "push= -update-addr ip port options : Send an update message to the client(s) conn= ecting from the provided address.");
msg(M_CLIENT= , "END");
}

@@= -1335,6 +1340,154 @@
}

= static void
+man_pus= h_update(struct management *man, const char **p, const push_update_type typ= e)
+{
+ if (type =3D=3D UPT_BROADCAST)<= /span>
+ {
+ if (!man->persist.callb= ack.push_update_broadcast)

+ {
+ = man_command_unsupported("push-update-broad");
= + return;
= + }
+
+ const bool status =3D (*man->persist.callback.pu= sh_update_broadcast)(man->persist.callback.arg, p[1]);
+
+ if (status)
+ {
+ msg(M_CLIENT, "SUCCESS: push-update-broad command= succeeded");
+ = }
+ els= e
+ {+ msg(M_CLIENT, &q= uot;ERROR: push-update-broad command failed");
+ }
+ }
+ else if (type =3D=3D UPT_BY_CID)
+ {
+ if (!man->persist.callback.push_update_by_cid)
+ {
+ man_command_unsupporte= d("push-update-cid");

+ return;
+ }
+
+ unsigned = long cid =3D 0;
+

+ if (!parse_cid(= p[1], &cid))
+ = {
+ m= sg(M_CLIENT, "ERROR: push-update-cid fail during cid parsing");
+ return;
+ }
<= span style=3D"color: hsl(120, 100%, 40%);">+

+ const bool status =3D (*man->persist.ca= llback.push_update_by_cid)(man->persist.callback.arg, cid, p[2]);=
+
+ if (status)
+ {
+ msg(M_CLIENT, "SUCCESS: push-update-ci= d command succeeded");
+ }
+ = else
+ {=
+ msg(M_C= LIENT, "ERROR: push-update-cid command failed");
+ }
+ }
+ else if (type =3D=3D UPT_BY_CN)
+ {
+ if (!man->persist.callback.push_update_by_cn)
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ man_command_unsuppo= rted("push-update-cn");

+ return;
+ }
+
+ const b= ool status =3D (*man->persist.callback.push_update_by_cn)(man->persis= t.callback.arg, p[1], p[2]);
+
+ if= (status)
+ {<= /span>
+ msg(M_CL= IENT, "SUCCESS: push-update-cn command succeeded");
+ }

+ else
+ {
+ msg(M_CLIENT, "ERROR: push-update-cn comm= and failed");
+ = }
+ }
+ else if (type =3D=3D = UPT_BY_ADDR)
+ {
+ if (!man->= persist.callback.push_update_by_addr)
+ {
+ man_command_unsupported("push-update-addr");<= /span>
+ return;<= /span>
+ }
= +
+ const char *ip_str =3D p[1];
+ const char *port_str =3D= p[2];

+ const= char *options =3D p[3];
+
+ if (!s= trlen(ip_str) || !strlen(port_str))
+ {
+ msg(M_CLIENT, "ERROR: push-update-addr parse");=
+ return;=
+ }+
+ struct addrinfo *res =3D NULL;+ int port =3D atoi(por= t_str);
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (port < 1 || port= > 65535)

+ = {
+ msg(M= _CLIENT, "ERROR: port number is out of range: %s", port_str);
+ return;
+ }
+

+ int status =3D openvpn_getaddrinfo(GETADDR_M= SG_VIRT_OUT, ip_str, port_str, 0, NULL, AF_UNSPEC, &res);
+

+ if (status !=3D 0 || !res)
+ {
+ msg(M_CLIENT, "ERROR: error re= solving address: %s (%s)", ip_str, gai_strerror(status));
+ return;

+ }

+
+ struct addrinfo *rp;
+ bool found_client =3D false;
+

+ /* Iterate through resolved addresses */
+ for (rp =3D res;= rp !=3D NULL; rp =3D rp->ai_next)
+ {
+ struct openvpn_sockaddr saddr;
+ struct mroute_addr maddr;=
+
+ CLEAR(saddr);
+ switch (rp->ai_family)
+ {<= br>+ case AF_INE= T:
+ = saddr.addr.in4 =3D *((struct sockaddr_in *)rp->ai_addr);
+ break;
+
+ case AF_INET6:
+ saddr.addr.in= 6 =3D *((struct sockaddr_in6 *)rp->ai_addr);

+ break;
+
+ default:
+ continue;
+ }
+
+ if (!mroute_extract_openvpn_sockaddr(&maddr, &sad= dr, true))
+ = {
+ = continue;
+ = }
+
+ if ((*man->persist.= callback.push_update_by_addr)(man->persist.callback.arg, &maddr, opt= ions))

+ {=
+ msg= (M_CLIENT, "SUCCESS: push-update sent to %s:%d", ip_str, port);
+ found= _client =3D true;
+ = break;
= + }
+ = }
+
+ if (!found_client)
<= br>+ {
+ msg(M_CLIENT, "ERROR= : no client found at address %s:%d", ip_str, port);
+ }
+ freeaddrinfo(res);
+ }
+}
+
+static void
man_dispatch_command(struct management *man, struct status_outp= ut *so, const char **p, const int nparms)
{
struct gc_arena gc =3D gc_new();

@@ -1656,6 +1809,34= @@
man_remote(man, p);
= }
}
+ else if (streq(p[0], "push-update-broad"))
= + {
+ if (man_need(man, p, 1, 0))+ {
+ man_push_update(man, p, UP= T_BROADCAST);
+ = }
+ }
= + else if (streq(p[0], "= ;push-update-cid"))
+ {
+ i= f (man_need(man, p, 2, 0))
+ {
+ = man_push_update(man, p, UPT_BY_CID);
+ }
+ }
+ else if (streq(p[0], "push-update-cn"))
+ {
+ if (man_need(man, p, 2, 0))
+ {
+ man_push_update(man, p, UPT_BY_CN);=
+ }+ }
+ else if (streq(p[0], "push-updat= e-addr"))
+ {=
+ if (man_nee= d(man, p, 3, 0))
+ = {
+ m= an_push_update(man, p, UPT_BY_ADDR);
+ }
+ }
#if 1
else if (streq(p[0= ], "test"))
{
diff --git a/s= rc/openvpn/manage.h b/src/openvpn/manage.h
index eb19a4e..f= d7cb11 100644
--- a/src/openvpn/manage.h
++= + b/src/openvpn/manage.h
@@ -44,7 +44,6 @@
= #define MF_EXTERNAL_KEY_PSSPAD (1<<16)
#define= MF_EXTERNAL_KEY_DIGEST (1<<17)

-
#ifdef ENABLE_MANA= GEMENT

#include "misc.h"
@@ -205,6 +204,10 @@
#endif
= unsigned int (*remote_entry_count)(void *arg);
bool = (*remote_entry_get)(void *arg, unsigned int index, char **remote);+ bool (*push_update_broad= cast)(void *arg, const char *options);
+ bool (*push_update_by_cid)(void *arg, unsigned long = cid, const char *options);
+ bool (*push_update_by_cn)(void *arg, const char *cn, const char = *options);
+ bool = (*push_update_by_addr)(void *arg, const struct mroute_addr *maddr, const ch= ar *options);
};

/*
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c<= br>index 7f0d890..67a7a79 100644
--- a/src/openvpn/mu= lti.c
+++ b/src/openvpn/multi.c
@@ -4072,7 = +4072,7 @@
}
}

-static struct multi_instan= ce *
+struct multi_in= stance *
lookup_by_cid(struct multi_context *m, const unsi= gned long cid)
{
if (m)
@@ -4220,6 +4220,10 @@
cb.client_auth =3D manag= ement_client_auth;
cb.client_pending_auth =3D mana= gement_client_pending_auth;
cb.get_peer_info =3D m= anagement_get_peer_info;
+ cb.push_update_broadcast =3D management_callback_send_push_upd= ate_broadcast;
+ = cb.push_update_by_cid =3D management_callback_send_push_update_by_cid;
+ cb.push_updat= e_by_cn =3D management_callback_send_push_update_by_cn;
+ cb.push_update_by_addr =3D mana= gement_callback_send_push_update_by_addr;
manageme= nt_set_callback(management, &cb);
}
#endif /* ifdef ENABLE_MANAGEMENT */

@@ -4344,3 +4348,51= @@
close_instance(top);

<= span> }
+
<= span style=3D"color: hsl(120, 100%, 40%);">+/**
+ * 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 se= rver. This function should be called after a push-update
+ * and old_ip/old_ipv6 are the previou= s addresses of the client in
+ * ctx->options.ifconfig_local and ctx->options.ifconfig_ipv= 6_local.
+ */<= br>+void
+update_vhash(struct multi_context *m, str= uct multi_instance *mi, const char *old_ip, const char *old_ipv6)+{
+ struct in_addr addr;
+ struct in6_addr new_ipv6;
<= span style=3D"color: hsl(120, 100%, 40%);">+
+ if (inet_pton(AF_INET, mi->context.options.= ifconfig_local, &addr) =3D=3D 1)
+ {
+
+ if (mi->context.options.ifconfig_local && (!old_ip= || strcmp(old_ip, mi->context.options.ifconfig_local)))
+ {
+ /* Add new, remove old if exist *= /
+ multi_= learn_in_addr_t(m, mi, new_ip, 0, true);
+ }
+ }
+
+ /* TO DO:+ * else if (old_ip &= ;& !mi->context.options.ifconfig_local)
+ * {
+ * // remove old ip
+ * }
+ */
+
+ if (inet_pt= on(AF_INET6, mi->context.options.ifconfig_ipv6_local, &new_ipv6) =3D= =3D 1)
+ {<= br>+ if (mi->context.= options.ifconfig_ipv6_local && (!old_ipv6 || strcmp(old_ipv6, mi-&g= t;context.options.ifconfig_ipv6_local)))
+ {
+ /* Add new, remove old if exist */
+ multi_learn_in6_addr(m, m= i, new_ipv6, 0, true);
+ }
+
+ /* TO DO:
+ * else if (old_ipv6 && !mi->c= ontext.options.ifconfig_ipv6_local)
+ * {
+ * // remove old IPv6
+ * }
+ */
+}

diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h<= br>index 40f7519..4841075 100644
--- a/src/openvpn/mu= lti.h
+++ b/src/openvpn/multi.h
@@ -710,5 += 710,13 @@
*/
void multi_assign_peer_id(s= truct multi_context *m, struct multi_instance *mi);

+#ifdef ENABLE_MANAGEMENT<= /span>
+struct multi_instanc= e *
+lookup_by_cid(st= ruct 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 /* MULTI_H */
diff --= git a/src/openvpn/push.h b/src/openvpn/push.h
index 18dfcd8= ..e67c3ac 100644
--- a/src/openvpn/push.h
+= ++ b/src/openvpn/push.h
@@ -42,6 +42,16 @@
= #define PUSH_OPT_TO_REMOVE (1<<0)
#define PUSH_OPT_= OPTIONAL (1<<1)

+/* Push-update message sender modes */
+typedef enum {
+ UPT_BROADCAST =3D 0,
+ UPT_BY_ADDR =3D 1,
+ UPT_BY_CN =3D 2,

+#ifdef ENABLE_MANAGEMENT
<= br>+ UPT_BY_CID =3D 3=
+#endif
+} push_update_type;
+
int process_incoming_= push_request(struct context *c);

/**
@@ -134,4 +144,33 @@
void
re= ceive_auth_pending(struct context *c, const struct buffer *buffer);<= br>
+/**
+ * @brief A function to s= end a PUSH_UPDATE control message from server to client(s).
+ *

+ * @param m the multi_context, contains all the clie= nts connected to this server.
+ * @param target the target to which to send the message. It shou= ld 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_B= Y_CN`,

+ * an `unsign= ed long *` if `type =3D=3D UPT_BY_CID`.
+ * @param msg a string containing the options to send.<= /span>
+ * @param type the w= ay to address the message (broadcast, by cid, by cn, by address).+ * @param push_bundle_size th= e maximum size of a bundle of pushed option. Just use PUSH_BUNDLE_SIZE macr= o.
+ * @return the nu= mber of clients to which the message was sent.
+ */
+int
+send_= push_update(struct multi_context *m, const void *target, const char *msg, c= onst push_update_type type, const int push_bundle_size);
+
+#ifdef ENABLE_MANAGEMENT
+
+bool management_callback_send_push_update_broadcast(void *arg, const ch= ar *options);
+
+bool management_callback_= send_push_update_by_cid(void *arg, unsigned long cid, const char *options);=
+
+bool management_callback_send_push_upd= ate_by_cn(void *arg, const char *cn, const char *options);
+
+bool management_callback_send_push_update_by_addr(void = *arg, const struct mroute_addr *maddr, const char *options);
+

+#endif /* ifdef ENABLE_MANAGEMENT*/
+
#endif /* ifndef PU= SH_H */
diff --git a/src/openvpn/push_util.c b/src/openvpn/= push_util.c
index b4d1e8b..1739510 100644
-= -- a/src/openvpn/push_util.c
+++ b/src/openvpn/push_util.c<= /span>
@@ -3,6 +3,8 @@
#endif

#include "push.h"
+#include "multi.h"
+#include "ssl_verify.h"<= br>
int
process_incoming_push_upda= te(struct context *c,
@@ -42,3 +44,293 @@
=
return ret;
}
+
+/**
+ = * 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 in= t
+find_first_comma_o= f_next_bundle(const char *str, int ix)
+{
= + while (ix > 0)
+ if = (str[ix] =3D=3D ',')
+ {
+ = return ix;
+ }
+ = ix--;
+ }+ return 0;
+}

+
+/* Allocate memory and asseble the final message */
+static char *
+forge_msg(const char *src, const char *contin= uation, struct gc_arena *gc)
+{
+ int s= rc_len =3D strlen(src);
+ int con_len =3D continuation ? strlen(continuation) : 0;
= + char *ret =3D gc_malloc((s= rc_len + sizeof(push_update_cmd) + con_len + 2) * sizeof(char), true, gc);<= /span>
+ int i =3D sizeof= (push_update_cmd) -1;
+
+ strcpy(ret, p= ush_update_cmd);
+ = ret[i++] =3D ',';
+ strcpy(&ret[i], src);
+ if (continuation)
+ {
+ i +=3D src_len;
+ strcpy(&ret[i], continuation);
+ }
+ return ret;
+}
+
+static char *<= br>+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 messag= ge (if necessay) and fill msgs with the message chunks.
+ * Return `false` on failure an `true` = on success.
+ */
+static bool
+message_splitter(char *str, char= **msgs, struct gc_arena *gc, const int safe_cap)

+{
+ if (!str || !*str)
+ {
= + return false;
+
= + 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 a= ny message */
+ = 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<= br>+ {
+ msgs[im] =3D forg= e_msg(str, NULL, gc);

+ }
+ = i =3D strlen(str);
+ }
+ = str =3D &str[i];
+ im++;
+= }
+ return tru= e;
+}
+

+/* It actually send the already divided messagge to on= e single client */
+s= tatic bool
+send_sing= le_push_update(struct context *c, char **msgs, unsigned int *option_types_f= ound)
+{
+ if (!msgs[0] || !*msgs[0])
+ {
+ return false;

+ }

+ int i =3D 0;
+ struct gc_arena gc =3D gc_new();
+

+ while (msgs[i] && *msgs[i])
+ {
+ struct buffer buf =3D alloc_buf_gc(str= len(msgs[i]), &gc);
+
+ buf_wri= te(&buf, msgs[i], strlen(msgs[i]));
+ if (!send_control_channel_string(c, msgs[i], D_= PUSH))
+ {
+ return fals= e;
+ }<= br>+ i++;
+

+ /* After sending the control message, we upda= te the options server-side in the client's context */
+ buf_string_compare_advance(&a= mp;buf, push_update_cmd);
+ if (process_incoming_push_update(c, pull_permission_mask(c), = option_types_found, &buf) =3D=3D PUSH_MSG_ERROR)
+ {
+ msg(M_WARN, "Failed to process pus= h update message sent to client ID: %u",
+ c->c2.tls_multi ? c->c2.tls= _multi->peer_id : UINT32_MAX);
+ continue;
+ }
+ c->options.push_option_types_found |=3D *option_types_foun= d;
+ if (!opti= ons_postprocess_pull(&c->options, c->c2.es))
+ {
+ msg(M_WARN, "Failed to post-proce= ss push update message sent to client ID: %u",
+ c->c2.tls_multi ? c-&g= t;c2.tls_multi->peer_id : UINT32_MAX);
+ }
+ }
+ = gc_free(&gc);
+= return true;
+}
+
+int
+send_push_update(struct multi_context *m, const void *ta= rget, const char *msg, const push_update_type type, const int push_bundle_s= ize)
+{
+ if (!msg || !*msg || !m
+ || (!target &= & type !=3D UPT_BROADCAST))
+ {
+ = return -EINVAL;
+ }
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ struct gc_arena gc =3D gc_n= ew();

+ /* extra s= pace for possible trailing ifconfig and push-continuation */
+ const int extra =3D 84 + sizeo= f(push_update_cmd);
+= /* push_bundle_size is the maximum size of a message, so if the message=
+ * we want to s= end exceeds that size we have to split it into smaller messages */+ const int safe_cap =3D p= ush_bundle_size - extra;
+ int msgs_num =3D (strlen(msg) / safe_cap) + ((strlen(msg) % safe_c= ap) !=3D 0);
+ cha= r **msgs =3D gc_malloc(sizeof(char *) * (msgs_num + 1), true, &gc);
+ unsigned int option= _types_found =3D 0;
+=
+ msgs[msgs_num] = =3D NULL;
+ if (!m= essage_splitter(gc_strdup(msg, &gc), msgs, &gc, safe_cap))+ {
+ gc_free(&gc);
+ return -EINVAL;

<= span style=3D"color: hsl(120, 100%, 40%);">+ }
+
+#ifdef ENABLE_MANAGEMENT
+ if (type =3D=3D UPT_BY_CID)
+ {
+ struct multi_instance *mi =3D lookup_by_cid(m, *((uns= igned long *)target));
+ if (!mi)=
+ {+ return -ENOENT;
+ }
<= span style=3D"color: hsl(120, 100%, 40%);">+

+ const char *old_ip =3D mi->context.opti= ons.ifconfig_local;
+= const char *old_ipv6 =3D mi->context.options.ifconfig_ipv6_local= ;
+ if (!mi-&g= t;halt
+ &= amp;& send_single_push_update(&mi->context, msgs, &option_ty= pes_found))
+ = {
+ if (op= tion_types_found & OPT_P_UP)
+ {
+ update_vhash(m, mi, old_ip, old_ipv6);
+ }
+ gc_free(&gc);+ return 1;<= br>+ }
+ else
+ {
+ gc_free(&gc);
+ return 0;
+ }
+ }
+#endif /* ifdef ENABLE_MANAGEMENT */
+
+ int count =3D 0;
+ struct hash_iterator hi;
+ const struct hash_element *he;
+
+ hash_iterator_init(m->iter, &hi);
+ while ((he =3D hash_iterator_ne= xt(&hi)))
+ {<= /span>
+ struct multi= _instance *curr_mi =3D he->value;
+
+ = if (curr_mi->halt)
+ {
+ = continue;
+= }
+ if= (type =3D=3D UPT_BY_ADDR && !mroute_addr_equal(target, &curr_m= i->real))
+ = {
+ conti= nue;
+ }

+ else if (type =3D= =3D UPT_BY_CN)
+ = {
+ con= st char *curr_cn =3D tls_common_name(curr_mi->context.c2.tls_multi, fals= e);
+ if (= strcmp(curr_cn, target))
+ {
+ = continue;
+ }
+ = }
+ /* = Either we found a matching client or type is UPT_BROADCAST so we update eve= ry 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_local;=
+ if (!send_single_p= ush_update(&curr_mi->context, msgs, &option_types_found))=
+ {
+ msg(M_CLIENT, "ERRO= R: Peer ID: %u has not been updated",
+ curr_mi->context.c2.tls_multi ? c= urr_mi->context.c2.tls_multi->peer_id : UINT32_MAX);
+ continue;
+ }
+ if (option_types_found & OPT_P_U= P)
+ {<= br>+ update_vhash(m,= curr_mi, old_ip, old_ipv6);
+ }
+ = count++;
+ = }
+
+ hash_iterator_free(&hi);

+ gc_free(&gc);

+ return count;
+}
+
+#ifdef ENABLE_MANAGEMENT
+#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(vo= id *arg, const char *options)
+{
+ int = n_sent =3D send_push_update(arg, NULL, options, UPT_BROADCAST, PUSH_BUNDLE_= SIZE);
+
+ RETURN_UPDATE_STATUS(n_sent)= ;
+}
+
+bool
+management_callback_send_push_update_by_cid(void *arg, unsigned long c= id, const char *options)
+{
+ int ret = =3D send_push_update(arg, &cid, options, UPT_BY_CID, PUSH_BUNDLE_SIZE);=
+
+ if (ret =3D=3D -ENOENT)
= + {
+ msg(M_CLIENT, "ERROR: no client= found with CID: %lu", cid);
+ }
+=
+ return (ret >= ; 0);
+}
+
+bool
+management_callback_send_push_update_by_cn(void *arg, const char *= cn, const char *options)
+{
+ int n_sen= t =3D send_push_update(arg, cn, options, UPT_BY_CN, PUSH_BUNDLE_SIZE);

+
+ RETURN_UPDATE_STATUS(n_sent);<= br>+}
+
+bool
+mana= gement_callback_send_push_update_by_addr(void *arg, const struct mroute_add= r *maddr, const char *options)
+{
+ int= n_sent =3D send_push_update(arg, maddr, options, UPT_BY_ADDR, PUSH_BUNDLE_= SIZE);
+
+ RETURN_UPDATE_STATUS(n_sent)= ;
+}
+#endif /* ifdef ENABLE_MANAGEMENT */=
diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/= unit_tests/openvpn/Makefile.am
index b24e03c..9a40512 10064= 4
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -343,4 +343= ,5 @@
$(top_srcdir)/src/openvpn/platform.c \
$(top_srcdir)/src/openvpn/push_util.c \
$(top_srcdi= r)/src/openvpn/options_util.c \
- $(top_srcdir)/src/openvpn/otime.c
\ No newline a= t end of file
+ $(top= _srcdir)/src/openvpn/otime.c \
+ $(top_srcdir)/src/openvpn/list.c
\ No newline a= t end of file
diff --git a/tests/unit_tests/openvpn/test_pu= sh_update_msg.c b/tests/unit_tests/openvpn/test_push_update_msg.cindex d0876bc..c65dd08 100644
--- a/tests/unit_tests= /openvpn/test_push_update_msg.c
+++ b/tests/unit_tests/open= vpn/test_push_update_msg.c
@@ -8,6 +8,7 @@
= #include <cmocka.h>
#include "push.h"
#include "options_util.h"
+#include "multi.h"
=
/* mocks */

@@ -37,6 += 38,12 @@
}

bool<= br>+options_postprocess_pull(st= ruct options *options, struct env_set *es)
+{
+ return true;
+}
+
+bool

apply_push_op= tions(struct context *c,
struct options= *options,
struct buffer *buf,@@ -94,6 +101,49 @@
}
}

+const c= har *
+tls_common_nam= e(const struct tls_multi *multi, const bool null)
+{
+ return NULL;
+}
++#ifndef ENABLE_MANAGEMENT

+bool
+send_control_channel_string(struct co= ntext *c, const char *str, int msglevel)
+{
+= }
+#else /* ifndef E= NABLE_MANAGEMENT */
+= char **res;
+int i;
+
+bool
+send_control_channel_string(struct context *c, const ch= ar *str, int msglevel)
+ if (res &am= p;& 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 */
<= br> static void
@@ -124,7 +174,6 @@
= free_buf(&buf);
}

-

static void=
test_incoming_push_message_error2(void **state)
= {
@@ -209,6 +258,211 @@
free_buf(&= ;buf);
}

+#ifdef ENABLE_MANAGEMENT
+char *r0[] =3D {
+ "PUSH_UPDATE,redirect-gateway local,rout= e 192.168.1.0 255.255.255.0"
+};
+cha= r *r1[] =3D {
+ &q= uot;PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalala= lalalalalalalaf,push-continuation 2",
+ "PUSH_UPDATE, akakakakakakakakakakakaf, dhc= p-option DNS 8.8.8.8,redirect-gateway local,push-continuation 2",

+ "PUSH_UPDATE,ro= ute 192.168.1.0 255.255.255.0,push-continuation 1"
+};
+char *r3[] =3D {
+ "PUSH_UPDATE,,,"
+};
+char *r4[] =3D {
+ "PUSH_UPDATE,-dhcp-option, blablalalalalalalalalalalalalf, = lalalalalalalalalalalalalalaf,push-continuation 2",
+ "PUSH_UPDATE, akakakakakakaka= kakakakaf,dhcp-option DNS 8.8.8.8, redirect-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, blab= lalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation= 2",
+ "= PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gat= eway local,push-continuation 2",
+ "PUSH_UPDATE, route 192.168.1.0 255.255.255.0,pu= sh-continuation 1"
+};
+char *r6[] = =3D {
+ "PUSH= _UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalala= lalalaf,push-continuation 2",
+ "PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option= DNS 8.8.8.8, redirect-gateway 10.10.10.10,,push-continuation 2",
+ "PUSH_UPDATE, r= oute 192.168.1.0 255.255.255.0,,push-continuation 1"
+};
+char *r7[] =3D {
+ "PUSH_UPDATE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,push-continuation 2&q= uot;,
+ "PUSH= _UPDATE,,,,,,,,,,,,,,,,,,,push-continuation 1"
+};
+char *r8[] =3D {
+ "PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalala= lalf, lalalalalalalalalalalalalalaf,push-continuation 2",
+ "PUSH_UPDATE, akakakaka= kakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway\n local,push-cont= inuation 2",

+ = "PUSH_UPDATE,route 192.168.1.0 255.255.255.0\n\n\n,push-continuation= 1"
+};+char *r9[] =3D {
<= span style=3D"color: hsl(120, 100%, 40%);">+ "PUSH_UPDATE,,"
+};
+
+
+c= onst char *msg0 =3D "redirect-gateway local,route 192.168.1.0 255.255.= 255.0";
+const c= har *msg1 =3D "-dhcp-option,blablalalalalalalalalalalalalf, lalalalala= lalalalalalalalalaf,"
+ " akakakakakakakakakakakaf, dhcp-option DNS = 8.8.8.8,redirect-gateway local,route 192.168.1.0 255.255.255.0";
+const char *msg2 =3D &quo= t;";
+const char= *msg3 =3D ",,";
+const char *msg4 =3D "-dhcp-option, blablalalalalalalalalalalal= alf, lalalalalalalalalalalalalalaf,"
+ " akakakakakakakakakakakaf,dh= cp-option DNS 8.8.8.8, redirect-gateway local, route 192.168.1.0 255.255.25= 5.0,";
+const ch= ar *msg5 =3D ",-dhcp-option, blablalalalalalalalalalalalalf, lalalalal= alalalalalalalalalaf,"
+ " akakakakakakakakakakakaf,dhcp-option DNS = 8.8.8.8, redirect-gateway local, route 192.168.1.0 255.255.255.0";
+const char *msg6 =3D &q= uot;-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalala= laf, akakakakakakakakakakakaf,"
+ " dhcp-option DNS 8.8.8.8, redirec= t-gateway 10.10.10.10,, route 192.168.1.0 255.255.255.0,";
<= span style=3D"color: hsl(120, 100%, 40%);">+const char *msg7 =3D ",,,,= ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= ,,,,,,,,,,,,,,,,,,,,,,,,,,,";

+const char *msg8 =3D "-dhcp-option,blablalalalalalalala= lalalalalf, lalalalalalalalalalalalalalaf, akakakakakakakakakakakaf,"<= /span>
+ &= quot; dhcp-option DNS 8.8.8.8,redirect-gateway\n local,route 192.168.1.0 25= 5.255.255.0\n\n\n";
+const char *msg9 =3D ",";
+const char *msg10 =3D "Voil=C3=A0! In view, a hum= ble vaudevillian veteran cast vicariously as both victim and villain by the= vicissitudes"
+= " of Fate. This visage no mere veneer of vanity is= a vestige of the vox populi now vacant vanished. However this"=
+ "= valorous visitation of a by-gone vexation stands vivified and has vowed to= vanquish these venal and virulent"
+ " vermin vanguarding vice and= vouchsafing the violently vicious and voracious violation of volition. The= only"
+ = " verdict is vengeance; a vendetta held as a votive not in= vain for the value and veracity of such shall one"
+ " day vindica= te the vigilant and the virtuous. Verily this vichyssoise of verbiage veers= most verbose so let"
+ " me simply add that it is my very good hon= or to meet you and you may call me V.";
+
+#define PUSH_BUNDLE_SIZE_TEST 184
+
= +void
+update_vhash(s= truct multi_context *m, struct multi_instance *mi, const char *old_ip, cons= t char *old_ipv6)
+{<= /span>
+ /* Just a mock *= /
+}
+
+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_BUNDLE_SIZE_TEST), 1);
+}
+static void
+test_send_push_msg1(void **state)
+{
+ i =3D 0;
+ = res =3D r1;
+ s= truct multi_context *m =3D *state;
+ const unsigned long cid =3D 0;
+ assert_int_equal(send_push_update(m, &= ;cid, msg1, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
+}
+
+sta= tic void
+test_send_p= ush_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 lo= ng cid =3D 0;
+ as= sert_int_equal(send_push_update(m, &cid, msg3, UPT_BY_CID, PUSH_BUNDLE_= 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_pus= h_update(m, &cid, msg4, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);<= br>+}
+
+static void
+{
+ = i =3D 0;
+ res = =3D r5;
+ struct m= ulti_context *m =3D *state;
+ const unsigned long cid =3D 0;
+ assert_int_equal(send_push_update(m, &cid, m= sg5, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
+}
+
+static void<= /span>
+test_send_push_msg6(= void **state)
+{
+ i =3D 0;
<= span style=3D"color: hsl(120, 100%, 40%);">+ res =3D r6;

+ struct multi_context *m =3D *st= ate;

+ const unsig= ned long cid =3D 0;
+= assert_int_equal(send_push_update(m, &cid, msg6, UPT_BY_CID, PUSH_B= UNDLE_SIZE_TEST), 1);
+}
+
+static void

+test_send_push_msg7(void **state)<= br>+{
+ 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, &am= p;cid, msg8, UPT_BY_CID, PUSH_BUNDLE_SIZE_TEST), 1);
+}
+
+sta= tic void
+test_send_p= ush_msg9(void **state)
+ i =3D 0;
+ res =3D r9;=
+ struct multi_context *= m =3D *state;
+ co= nst unsigned long cid =3D 0;
+ assert_int_equal(send_push_update(m, &cid, msg9, UPT_BY_CI= D, PUSH_BUNDLE_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 ci= d =3D 0;
+ assert_= int_equal(send_push_update(m, &cid, msg10, UPT_BY_CID, PUSH_BUNDLE_SIZE= _TEST), -EINVAL);
+}<= /span>
+
+#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, siz= eof(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->ins= tances);
+ free(m)= ;
+ return 0;
+}
+#endif /* ifdef ENABLE_MANAGEMENT */
+
static= int
setup(void **state)
{
@@ -238,7 +492,20 @@

cmocka_unit_test_setup_tear= down(test_incoming_push_message_1, setup, teardown),
= cmocka_unit_test_setup_teardown(test_incoming_push_message_bad_format, s= etup, teardown),
cmocka_unit_test_setup_teardown(t= est_incoming_push_message_mix, setup, teardown),
- cmocka_unit_test_setup_teardown(test_inc= oming_push_message_mix2, setup, teardown)
+ cmocka_unit_test_setup_teardown(test_incoming= _push_message_mix2, setup, teardown),
+#ifdef ENABLE_MANAGEMENT
+ cmocka_unit_test_setup_teardown(test_send_pu= sh_msg0, setup2, teardown2),
+ cmocka_unit_test_setup_teardown(test_send_push_msg1, setup= 2, teardown2),
+ = cmocka_unit_test_setup_teardown(test_send_push_msg2, setup2, teardown2),=
+ cmocka_unit= _test_setup_teardown(test_send_push_msg3, setup2, teardown2),
+ cmocka_unit_test_setup_te= ardown(test_send_push_msg4, setup2, teardown2),

+ cmocka_unit_test_setup_teardown(test_se= nd_push_msg5, setup2, teardown2),
+ cmocka_unit_test_setup_teardown(test_send_push_msg6, = setup2, teardown2),
+= cmocka_unit_test_setup_teardown(test_send_push_msg7, setup2, teardo= wn2),
+ cmocka= _unit_test_setup_teardown(test_send_push_msg8, setup2, teardown2),+ cmocka_unit_test_set= up_teardown(test_send_push_msg9, setup2, teardown2),
+ cmocka_unit_test_setup_teardown(t= est_send_push_msg10, setup2, teardown2)
+#endif
};
=
return cmocka_run_group_tests(tests, NULL, NULL);
=

To view, visit change 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: 10
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-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: stipa <lstipakov@...1663...= .>
Gerrit-Attention: mrbff <marco@...2726...&g= t;
Gerrit-MessageType: newpatchset
--zVzL+KwvwLU=--