OpenVPN
Macros | Functions
push_util.c File Reference
#include "push.h"
#include "buffer.h"
#include "multi.h"
Include dependency graph for push_util.c:

Go to the source code of this file.

Macros

#define RETURN_UPDATE_STATUS(n_sent)
 

Functions

int process_incoming_push_update (struct context *c, 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 int find_first_comma_of_next_bundle (const char *str, int 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 int safe_cap)
 
static bool send_single_push_update (struct context *c, struct buffer *msgs, unsigned int *option_types_found)
 
int send_push_update (struct multi_context *m, const void *target, const char *msg, const push_update_type type, const int 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:106

Definition at line 277 of file push_util.c.

Function Documentation

◆ find_first_comma_of_next_bundle()

static int find_first_comma_of_next_bundle ( const char *  str,
int  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 int  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_incoming_push_update()

int process_incoming_push_update ( struct context c,
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.
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 function is called by the message sender (server).
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 13 of file push_util.c.

References apply_push_options(), buf_read_u8(), context::c2, context_2::es, context::options, 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()

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

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.

Definition at line 187 of file push_util.c.

References context::c2, multi_instance::context, gc, gc_free(), gc_malloc(), gc_new(), multi_instance::halt, hash_iterator_free(), hash_iterator_init(), hash_iterator_next(), options::ifconfig_ipv6_local, options::ifconfig_local, multi_context::iter, buffer::len, lookup_by_cid(), M_CLIENT, message_splitter(), msg, OPT_P_UP, context::options, tls_multi::peer_id, push_update_cmd, send_single_push_update(), context_2::tls_multi, update_vhash(), 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 context c,
struct buffer msgs,
unsigned int *  option_types_found 
)
static