public bool ApplyNetworkSettings(NetworkSettingsConfig settingsConfig) { uint tapInterfaceIndex = GetTapInterfaceIndex(); if (tapInterfaceIndex == 0) { return(false); } try { string localInterfaceIp = NetworkUtil.GetBestInterfaceIp(_config.OpenVpn.TapAdapterId).ToString(); NetworkUtil.SetLowestTapMetric(tapInterfaceIndex); NetworkUtil.DeleteDefaultGatewayForIface(tapInterfaceIndex, localInterfaceIp); if (settingsConfig.AddDefaultGatewayForTap) { NetworkUtil.AddDefaultGatewayForIface(tapInterfaceIndex, localInterfaceIp); } } catch (NetworkUtilException e) { _logger.Error("Failed to apply network settings. Error code: " + e.Code); return(false); } return(true); }
private void AddDefaultGateway() { try { var localInterfaceIp = NetworkUtil.GetBestInterfaceIp(_tapAdapterId).ToString(); var tapInterface = _networkInterfaces.Interface(_tapAdapterDescription); var parseResult = Guid.TryParse(tapInterface.Id, out var guid); if (!parseResult) { return; } NetworkUtil.DeleteDefaultGatewayForIface(guid, localInterfaceIp); NetworkUtil.AddDefaultGatewayForIface(guid, localInterfaceIp); } catch (NetworkUtilException e) { _logger.Error("Add default TAP gateway failed. Error code: " + e.Code); } }
private void ApplyNetworkSettings() { var tapGuid = GetTapGuid(); if (tapGuid == null) { return; } try { var localInterfaceIp = NetworkUtil.GetBestInterfaceIp(_tapAdapterId).ToString(); NetworkUtil.DeleteDefaultGatewayForIface(tapGuid.Value, localInterfaceIp); NetworkUtil.AddDefaultGatewayForIface(tapGuid.Value, localInterfaceIp); NetworkUtil.SetLowestTapMetric(tapGuid.Value); } catch (NetworkUtilException e) { _logger.Error("Failed to apply network settings. Error code: " + e.Code); } }