Skip to content

Commit

Permalink
Add send_control_channel_string_dowork variant
Browse files Browse the repository at this point in the history
The send_control_channel_string_dowork variant does not schedule
the sending of the actual and can be used where struct context is not
available.
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg18092.html

Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
schwabe authored and cron2 committed Jan 16, 2019
1 parent 801be38 commit 1000d5e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
43 changes: 23 additions & 20 deletions src/openvpn/forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,42 +464,45 @@ check_connection_established_dowork(struct context *c)
}
}

/*
* Send a string to remote over the TLS control channel.
* Used for push/pull messages, passing username/password,
* etc.
*/
bool
send_control_channel_string_dowork(struct tls_multi *multi,
const char *str, int msglevel)
{
struct gc_arena gc = gc_new();
bool stat;

/* buffered cleartext write onto TLS control channel */
stat = tls_send_payload(multi, (uint8_t *) str, strlen(str) + 1);

msg(msglevel, "SENT CONTROL [%s]: '%s' (status=%d)",
tls_common_name(multi, false),
sanitize_control_message(str, &gc),
(int) stat);

gc_free(&gc);
return stat;
}

bool
send_control_channel_string(struct context *c, const char *str, int msglevel)
{
if (c->c2.tls_multi)
{
struct gc_arena gc = gc_new();
bool stat;

/* buffered cleartext write onto TLS control channel */
stat = tls_send_payload(c->c2.tls_multi, (uint8_t *) str, strlen(str) + 1);

bool ret = send_control_channel_string_dowork(c->c2.tls_multi,
str, msglevel);
/*
* Reschedule tls_multi_process.
* NOTE: in multi-client mode, usually the below two statements are
* insufficient to reschedule the client instance object unless
* multi_schedule_context_wakeup(m, mi) is also called.
*/

interval_action(&c->c2.tmp_int);
context_immediate_reschedule(c); /* ZERO-TIMEOUT */

msg(msglevel, "SENT CONTROL [%s]: '%s' (status=%d)",
tls_common_name(c->c2.tls_multi, false),
sanitize_control_message(str, &gc),
(int) stat);

gc_free(&gc);
return stat;
return ret;
}
return true;
}

/*
* Add routes.
*/
Expand Down
31 changes: 30 additions & 1 deletion src/openvpn/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,36 @@ void process_outgoing_tun(struct context *c);

/**************************************************************************/

bool send_control_channel_string(struct context *c, const char *str, int msglevel);
/*
* Send a string to remote over the TLS control channel.
* Used for push/pull messages, passing username/password,
* etc.
* @param c - The context structure of the VPN tunnel associated with
* the packet.
* @param str - The message to be sent
* @param msglevel - Message level to use for logging
*/
bool
send_control_channel_string(struct context *c, const char *str, int msglevel);

/*
* Send a string to remote over the TLS control channel.
* Used for push/pull messages, passing username/password,
* etc.
*
* This variant does not schedule the actual sending of the message
* The caller needs to ensure that it is scheduled or call
* send_control_channel_string
*
* @param multi - The tls_multi structure of the VPN tunnel associated
* with the packet.
* @param str - The message to be sent
* @param msglevel - Message level to use for logging
*/

bool
send_control_channel_string_dowork(struct tls_multi *multi,
const char *str, int msglevel);

#define PIPV4_PASSTOS (1<<0)
#define PIP_MSSFIX (1<<1) /* v4 and v6 */
Expand Down

0 comments on commit 1000d5e

Please sign in to comment.