private void OnEventImpl(ref NativeMethods.ovpn3_event oe) { if (oe.name != "CONNECTED" || (oe.data.ToInt64() == 0)) { return; } NativeMethods.ovpn3_connection_data connectionData = Marshal.PtrToStructure <NativeMethods.ovpn3_connection_data>(oe.data); LogsManager.Instance.Debug("CONNECTED: defined={0}, user={1}, serverHost={2}, serverPort={3}, serverProto={4}, serverIp={5}, vpnIp4={6}, vpnIp6={7}, gw4={8}, gw6={9}, clientIp={10}, tunName={11}", connectionData.defined, connectionData.user, connectionData.serverHost, connectionData.serverPort, connectionData.serverProto, connectionData.serverIp, connectionData.vpnIp4, connectionData.vpnIp6, connectionData.gw4, connectionData.gw6, connectionData.clientIp, connectionData.tunName); }
private void OnEvent(ref NativeMethods.EddieLibraryEvent oe) { try { switch (oe.type) { case NativeMethods.EventType.MESSAGE: case NativeMethods.EventType.INFO: { EddieLogger.Info("{0}: {1}", oe.name, oe.info); } break; case NativeMethods.EventType.WARN: { EddieLogger.Warning("OpenVPN {0}: {1}", oe.name, oe.info); } break; case NativeMethods.EventType.ERROR: case NativeMethods.EventType.FATAL_ERROR: { if (IgnoredError(oe.name)) { EddieLogger.Warning("OpenVPN {0}: {1}", oe.name, oe.info); } else { // It seems OpenVPN is having BIG troubles with the connection // In order to prevent worse conditions, try to lock the VPN (in case it is possible) EddieLogger.Error("OpenVPN3 Fatal Error {0}: {1}", oe.name, oe.info); NetworkStatusChanged(VPNAction.LOCK); vpnService.DoChangeStatus(VPN.Status.LOCKED); AlertNotification(vpnService.Resources.GetString(Resource.String.connection_vpn_error)); } } break; case NativeMethods.EventType.FORMAL_WARNING: { if (IgnoredError(oe.name)) { EddieLogger.Warning("OpenVPN {0}: {1}", oe.name, oe.info); } else { // It seems OpenVPN is having troubles with the connection // In order to prevent worse conditions, lock the VPN EddieLogger.Error("OpenVPN3 {0}: {1}", oe.name, oe.info); NetworkStatusChanged(VPNAction.LOCK); vpnService.DoChangeStatus(VPN.Status.LOCKED); AlertNotification(vpnService.Resources.GetString(Resource.String.connection_vpn_formal_warning)); } } break; case NativeMethods.EventType.TUN_ERROR: case NativeMethods.EventType.CLIENT_RESTART: case NativeMethods.EventType.AUTH_FAILED: case NativeMethods.EventType.CERT_VERIFY_FAIL: case NativeMethods.EventType.TLS_VERSION_MIN: case NativeMethods.EventType.CLIENT_HALT: case NativeMethods.EventType.CLIENT_SETUP: case NativeMethods.EventType.CONNECTION_TIMEOUT: case NativeMethods.EventType.INACTIVE_TIMEOUT: case NativeMethods.EventType.DYNAMIC_CHALLENGE: case NativeMethods.EventType.PROXY_NEED_CREDS: case NativeMethods.EventType.PROXY_ERROR: case NativeMethods.EventType.TUN_SETUP_FAILED: case NativeMethods.EventType.TUN_IFACE_CREATE: case NativeMethods.EventType.TUN_IFACE_DISABLED: case NativeMethods.EventType.EPKI_ERROR: case NativeMethods.EventType.EPKI_INVALID_ALIAS: { // These OpenVPN events may cause a fatal error // In order to prevent worse conditions, lock the VPN EddieLogger.Error("OpenVPN {0}: {1}", oe.name, oe.info); NetworkStatusChanged(VPNAction.LOCK); vpnService.DoChangeStatus(VPN.Status.LOCKED); AlertNotification(vpnService.Resources.GetString(Resource.String.connection_vpn_formal_warning)); } break; case NativeMethods.EventType.CONNECTED: { if (oe.data.ToInt64() != 0) { NativeMethods.ovpn3_connection_data connectionData = Marshal.PtrToStructure <NativeMethods.ovpn3_connection_data>(oe.data); EddieLogger.Info("CONNECTED: defined={0}, user={1}, serverHost={2}, serverPort={3}, serverProto={4}, serverIp={5}, vpnIp4={6}, vpnIp6={7}, gw4={8}, gw6={9}, clientIp={10}, tunName={11}", connectionData.defined, connectionData.user, connectionData.serverHost, connectionData.serverPort, connectionData.serverProto, connectionData.serverIp, connectionData.vpnIp4, connectionData.vpnIp6, connectionData.gw4, connectionData.gw6, connectionData.clientIp, connectionData.tunName); } } break; case NativeMethods.EventType.TRANSPORT_ERROR: case NativeMethods.EventType.RELAY_ERROR: case NativeMethods.EventType.DISCONNECTED: { EddieLogger.Warning("OpenVPN {0} - {1}: {2}", oe.type, oe.name, oe.info); } break; default: { EddieLogger.Debug("OpenVPN Event: type={0}, name={1}, info={2}, data={3}", oe.type, oe.name, oe.info, oe.data.ToString()); } break; } } catch (Exception e) { EddieLogger.Error("OnEvent", e); } }