OpenVPN
Macros | Functions
push_util.c File Reference
#include "push.h"
#include "buffer.h"
#include "multi.h"
#include "ssl_util.h"
Include dependency graph for push_util.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RETURN_UPDATE_STATUS(n_sent)
 

Functions

int process_push_update (struct context *c, struct options *o, unsigned int permission_mask, unsigned int *option_types_found, struct buffer *buf, bool msg_sender)
 Handles the receiving of a push-update message and applies updates to the specified options.
 
static size_t find_first_comma_of_next_bundle (const char *str, size_t ix)
 Return index of last , or 0 if it didn't find any.
 
static struct buffer forge_msg (const char *src, const char *continuation, struct gc_arena *gc)
 
static char * gc_strdup (const char *src, struct gc_arena *gc)
 
static bool message_splitter (const char *s, struct buffer *msgs, struct gc_arena *gc, const size_t safe_cap)
 
static bool send_single_push_update (struct multi_context *m, struct multi_instance *mi, struct buffer *msgs)
 
static bool support_push_update (struct multi_instance *mi)
 
static int send_push_update (struct multi_context *m, const void *target, const char *msg, const push_update_type type, const size_t push_bundle_size)
 A function to send a PUSH_UPDATE control message from server to client(s).
 
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)
 

Macro Definition Documentation

◆ RETURN_UPDATE_STATUS

#define RETURN_UPDATE_STATUS (   n_sent)
Value:
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)
#define M_CLIENT
Definition error.h:108

Definition at line 341 of file push_util.c.

Function Documentation

◆ find_first_comma_of_next_bundle()

static size_t find_first_comma_of_next_bundle ( const char *  str,
size_t  ix 
)
static

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

Definition at line 55 of file push_util.c.

Referenced by message_splitter().

◆ forge_msg()

static struct buffer forge_msg ( const char *  src,
const char *  continuation,
struct gc_arena gc 
)
static

Definition at line 70 of file push_util.c.

References alloc_buf_gc(), buf_printf(), gc, buffer::len, and push_update_cmd.

Referenced by message_splitter().

◆ gc_strdup()

static char * gc_strdup ( const char *  src,
struct gc_arena gc 
)
static

Definition at line 82 of file push_util.c.

References gc, gc_malloc(), and buffer::len.

Referenced by message_splitter().

◆ management_callback_send_push_update_broadcast()

bool management_callback_send_push_update_broadcast ( void *  arg,
const char *  options 
)

◆ management_callback_send_push_update_by_cid()

bool management_callback_send_push_update_by_cid ( void *  arg,
unsigned long  cid,
const char *  options 
)

◆ message_splitter()

static bool message_splitter ( const char *  s,
struct buffer msgs,
struct gc_arena gc,
const size_t  safe_cap 
)
static

Definition at line 94 of file push_util.c.

References find_first_comma_of_next_bundle(), forge_msg(), gc, gc_strdup(), i, and buffer::len.

Referenced by send_push_update().

◆ process_push_update()

int process_push_update ( struct context c,
struct options o,
unsigned int  permission_mask,
unsigned int *  option_types_found,
struct buffer buf,
bool  msg_sender 
)

Handles the receiving of a push-update message and applies updates to the specified options.

This function processes a push-update message, validating its content and applying updates to the options specified in the message. It also handles split messages if the complete message has not yet been received.

Parameters
cThe context for the operation.
oThe options structure to be updated with the received push options.
permission_maskThe permission mask specifying which options are allowed to be pulled.
option_types_foundA pointer to a variable that will be filled with the types of options found in the message.
bufA buffer containing the received message.
msg_senderA boolean indicating if the message is being processed on the client (false) or on the server (true).
Returns
  • PUSH_MSG_UPDATE: The message was processed successfully, and the updates were applied.
  • PUSH_MSG_CONTINUATION: The message is a fragment of a larger message, and the program is waiting for the final part.
  • PUSH_MSG_ERROR: An error occurred during message processing, or the message is invalid.

Definition at line 14 of file push_util.c.

References apply_push_options(), buf_read_u8(), context::c2, context_2::es, options::push_continuation, PUSH_MSG_CONTINUATION, PUSH_MSG_ERROR, PUSH_MSG_UPDATE, and throw_signal_soft().

Referenced by process_incoming_push_msg(), and send_single_push_update().

◆ send_push_update()

static int send_push_update ( struct multi_context m,
const void *  target,
const char *  msg,
const push_update_type  type,
const size_t  push_bundle_size 
)
static

A function to send a PUSH_UPDATE control message from server to client(s).

Parameters
mthe multi_context, contains all the clients connected to this server.
targetthe target to which to send the message. It should be: NULL if type == UPT_BROADCAST, a mroute_addr * if type == UPT_BY_ADDR, a char * if type == UPT_BY_CN, an unsigned long * if type == UPT_BY_CID.
msga string containing the options to send.
typethe way to address the message (broadcast, by cid, by cn, by address).
push_bundle_sizethe maximum size of a bundle of pushed option. Just use PUSH_BUNDLE_SIZE macro.
Returns
The number of clients to which the message was sent. Might return < 0 in case of error.

Definition at line 252 of file push_util.c.

References ASSERT, context::c2, multi_instance::context, dco_enabled(), gc, gc_free(), gc_malloc(), gc_new(), multi_instance::halt, hash_iterator_free(), hash_iterator_init(), hash_iterator_next(), multi_context::iter, buffer::len, lookup_by_cid(), M_CLIENT, M_WARN, message_splitter(), msg, tls_multi::peer_id, push_update_cmd, send_single_push_update(), support_push_update(), context_2::tls_multi, UPT_BROADCAST, UPT_BY_CID, and hash_element::value.

Referenced by management_callback_send_push_update_broadcast(), management_callback_send_push_update_by_cid(), test_send_push_msg0(), test_send_push_msg1(), test_send_push_msg10(), test_send_push_msg2(), test_send_push_msg3(), test_send_push_msg4(), test_send_push_msg5(), test_send_push_msg6(), test_send_push_msg7(), test_send_push_msg8(), and test_send_push_msg9().

◆ send_single_push_update()

static bool send_single_push_update ( struct multi_context m,
struct multi_instance mi,
struct buffer msgs 
)
static

◆ support_push_update()

static bool support_push_update ( struct multi_instance mi)
static