From 6cbdcaf5bb806bd9a647bf20847162d8b43445ed Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 21 Feb 2019 10:06:19 +0100 Subject: [PATCH] OpenVPN: track interface disconnect Setup disconnection callback and use it to properly track management interface availability. Change-Id: I11b8bc71c1e9cbbf992ee3b7c1c9aae6e6f697e0 Requires: libosmo-netif I905adb2d6191216551a3bcdcd1aec1f96f01612a Related: SYS#2655 --- src/client.h | 2 +- src/osysmon_openvpn.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/client.h b/src/client.h index d878450..a14019e 100644 --- a/src/client.h +++ b/src/client.h @@ -15,7 +15,7 @@ struct host_cfg { /* name of this client */ const char *name; /* remote host/IP */ - const char *remote_host; + char *remote_host; /* remote port */ uint16_t remote_port; }; diff --git a/src/osysmon_openvpn.c b/src/osysmon_openvpn.c index 135a532..148e3b8 100644 --- a/src/osysmon_openvpn.c +++ b/src/osysmon_openvpn.c @@ -113,12 +113,26 @@ static struct openvpn_client *openvpn_client_find_or_make(const struct osysmon_s return NULL; } +static int disconnect_cb(struct osmo_stream_cli *conn) +{ + struct openvpn_client *vpn = osmo_stream_cli_get_data(conn); + + update_name(vpn->rem_cfg, "management interface unavailable"); + vpn->connected = false; + talloc_free(vpn->tun_ip); + talloc_free(vpn->rem_cfg->remote_host); + vpn->tun_ip = NULL; + vpn->rem_cfg->remote_host = NULL; + + return 0; +} + static int connect_cb(struct osmo_stream_cli *conn) { struct openvpn_client *vpn = osmo_stream_cli_get_data(conn); update_name(vpn->rem_cfg, "management interface incompatible"); - vpn->connected = true; /* FIXME: there's no callback for lost connection to drop this flag */ + vpn->connected = true; return 0; } @@ -174,6 +188,7 @@ static bool openvpn_client_create(struct osysmon_state *os, const char *name, co osmo_stream_cli_set_reconnect_timeout(vpn->mgmt, 60); osmo_stream_cli_set_read_cb(vpn->mgmt, read_cb); osmo_stream_cli_set_connect_cb(vpn->mgmt, connect_cb); + osmo_stream_cli_set_disconnect_cb(vpn->mgmt, disconnect_cb); if (osmo_stream_cli_open(vpn->mgmt) < 0) { OVPN_LOG(vpn->rem_cfg, vpn, "failed to connect to management interface\n"); @@ -261,7 +276,6 @@ static int openvpn_client_poll(struct openvpn_client *vpn, struct value_node *pa if (remote) value_node_add(vn_host, "remote", remote); - /* FIXME: there's no way to check client state so this might be triggered even while it's reconnecting */ if (vpn->connected) { /* re-trigger state command */ msgb_printf(msg, "state\n"); osmo_stream_cli_send(vpn->mgmt, msg);