/* * Called after most socket or tun/tap operations, via the inline * function check_status(). * * Decide if we should print an error message, and see if we can * extract any useful info from the error, such as a Path MTU hint * from the OS. */ void x_check_status (int status, const char *description, struct link_socket *sock, struct tuntap *tt) { const int my_errno = openvpn_errno (); const char *extended_msg = NULL; msg (x_cs_verbose_level, "%s %s returned %d", sock ? proto2ascii (sock->info.proto, true) : "", description, status); if (status < 0) { struct gc_arena gc = gc_new (); #if EXTENDED_SOCKET_ERROR_CAPABILITY /* get extended socket error message and possible PMTU hint from OS */ if (sock) { int mtu; extended_msg = format_extended_socket_error (sock->sd, &mtu, &gc); if (mtu > 0 && sock->mtu != mtu) { sock->mtu = mtu; sock->info.mtu_changed = true; } } #elif defined(WIN32) /* get possible driver error from TAP-Windows driver */ extended_msg = tap_win_getinfo (tt, &gc); #endif if (!ignore_sys_error (my_errno)) { if (extended_msg) msg (x_cs_info_level, "%s %s [%s]: %s (code=%d)", description, sock ? proto2ascii (sock->info.proto, true) : "", extended_msg, strerror_ts (my_errno, &gc), my_errno); else msg (x_cs_info_level, "%s %s: %s (code=%d)", description, sock ? proto2ascii (sock->info.proto, true) : "", strerror_ts (my_errno, &gc), my_errno); if (x_cs_err_delay_ms) platform_sleep_milliseconds (x_cs_err_delay_ms); } gc_free (&gc); } }
/* * Print statistics. * * Triggered by SIGUSR2 or F2 on Windows. */ void print_status(const struct context *c, struct status_output *so) { struct gc_arena gc = gc_new(); status_reset(so); status_printf(so, "OpenVPN STATISTICS"); status_printf(so, "Updated,%s", time_string(0, 0, false, &gc)); status_printf(so, "TUN/TAP read bytes," counter_format, c->c2.tun_read_bytes); status_printf(so, "TUN/TAP write bytes," counter_format, c->c2.tun_write_bytes); status_printf(so, "TCP/UDP read bytes," counter_format, c->c2.link_read_bytes); status_printf(so, "TCP/UDP write bytes," counter_format, c->c2.link_write_bytes); status_printf(so, "Auth read bytes," counter_format, c->c2.link_read_bytes_auth); #ifdef USE_COMP if (c->c2.comp_context) { comp_print_stats(c->c2.comp_context, so); } #endif #ifdef PACKET_TRUNCATION_CHECK status_printf(so, "TUN read truncations," counter_format, c->c2.n_trunc_tun_read); status_printf(so, "TUN write truncations," counter_format, c->c2.n_trunc_tun_write); status_printf(so, "Pre-encrypt truncations," counter_format, c->c2.n_trunc_pre_encrypt); status_printf(so, "Post-decrypt truncations," counter_format, c->c2.n_trunc_post_decrypt); #endif #ifdef _WIN32 if (tuntap_defined(c->c1.tuntap)) { status_printf(so, "TAP-WIN32 driver status,\"%s\"", tap_win_getinfo(c->c1.tuntap, &gc)); } #endif status_printf(so, "END"); status_flush(so); gc_free(&gc); }