Skip to content

Commit

Permalink
Add openconnect_set_loglevel()
Browse files Browse the repository at this point in the history
Profiling shows that in the VPN mainloop we were translating debug
messages we didn't even print. Stop that.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jan 31, 2015
1 parent e1a2dad commit 04d713f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion libopenconnect.map.in
Expand Up @@ -32,7 +32,6 @@ OPENCONNECT_5.0 {
openconnect_set_cancel_fd;
openconnect_set_cert_expiry_warning;
openconnect_set_client_cert;
openconnect_set_compression_mode;
openconnect_set_csd_environ;
openconnect_set_dpd;
openconnect_set_hostname;
Expand Down Expand Up @@ -62,6 +61,11 @@ OPENCONNECT_5.0 {
openconnect_vpninfo_new;
};

OPENCONNECT_5_1 {
global:
openconnect_set_compression_mode;
openconnect_set_loglevel;
} OPENCONNECT_5.0;

OPENCONNECT_PRIVATE {
global: @SYMVER_TIME@ @SYMVER_GETLINE@ @SYMVER_JAVA@ @SYMVER_ASPRINTF@ @SYMVER_VASPRINTF@ @SYMVER_WIN32_STRERROR@
Expand Down
7 changes: 7 additions & 0 deletions library.c
Expand Up @@ -82,6 +82,7 @@ struct openconnect_info *openconnect_vpninfo_new(const char *useragent,
vpninfo->progress = progress;
vpninfo->cbdata = privdata ? : vpninfo;
vpninfo->xmlpost = 1;
vpninfo->verbose = PRG_TRACE;
openconnect_set_reported_os(vpninfo, NULL);

if (!vpninfo->localname || !vpninfo->useragent)
Expand Down Expand Up @@ -129,6 +130,12 @@ void openconnect_set_juniper(struct openconnect_info *vpninfo)
#endif
}

void openconnect_set_loglevel(struct openconnect_info *vpninfo,
int level)
{
vpninfo->verbose = level;
}

int openconnect_setup_dtls(struct openconnect_info *vpninfo,
int attempt_period)

Expand Down
2 changes: 2 additions & 0 deletions main.c
Expand Up @@ -1505,6 +1505,8 @@ int main(int argc, char **argv)
}
#endif

openconnect_set_loglevel(vpninfo, verbose);

while (1) {
ret = openconnect_mainloop(vpninfo, reconnect_timeout, RECONNECT_INTERVAL_MIN);
if (ret)
Expand Down
6 changes: 5 additions & 1 deletion openconnect-internal.h
Expand Up @@ -579,6 +579,7 @@ struct openconnect_info {

const char *quit_reason;

int verbose;
void *cbdata;
openconnect_validate_peer_cert_vfn validate_peer_cert;
openconnect_write_new_config_vfn write_new_config;
Expand Down Expand Up @@ -633,7 +634,10 @@ struct openconnect_info {
#define AC_PKT_COMPRESSED 8 /* Compressed data */
#define AC_PKT_TERM_SERVER 9 /* Server kick */

#define vpn_progress(vpninfo, ...) (vpninfo)->progress((vpninfo)->cbdata, __VA_ARGS__)
#define vpn_progress(_v, lvl, ...) do { \
if ((_v)->verbose >= (lvl)) \
(_v)->progress((vpninfo)->cbdata, lvl, __VA_ARGS__); \
} while(0)
#define vpn_perror(vpninfo, msg) vpn_progress((vpninfo), PRG_ERR, "%s: %s\n", (msg), strerror(errno));

/****************************************************************************/
Expand Down
5 changes: 4 additions & 1 deletion openconnect.h
Expand Up @@ -33,7 +33,7 @@

/*
* API version 5.1:
* - Add openconnect_set_compression_mode().
* - Add openconnect_set_compression_mode(), openconnect_set_loglevel()
*
* API version 5.0:
* - Remove OPENCONNECT_X509 and openconnect_get_peer_cert().
Expand Down Expand Up @@ -544,6 +544,9 @@ typedef void (*openconnect_protect_socket_vfn) (void *privdata, int fd);
void openconnect_set_protect_socket_handler(struct openconnect_info *vpninfo,
openconnect_protect_socket_vfn protect_socket);

void openconnect_set_loglevel(struct openconnect_info *vpninfo,
int level);

/* Callback for obtaining traffic stats via OC_CMD_STATS.
*/
typedef void (*openconnect_stats_vfn) (void *privdata, const struct oc_stats *stats);
Expand Down

0 comments on commit 04d713f

Please sign in to comment.