Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 public INetworkInterface GetBestInterface(string hardwareIdToExclude)
 {
     return(GetByLocalAddress(NetworkUtil.GetBestInterfaceIp(hardwareIdToExclude)));
 }
Ejemplo n.º 5
0
 public IPAddress LocalIpAddress()
 {
     return(NetworkUtil.GetBestInterfaceIp(_currentNetworkInterface.HardwareId));
 }
Ejemplo n.º 6
0
 public IPAddress LocalIpAddress()
 {
     return(NetworkUtil.GetBestInterfaceIp(_config.OpenVpn.TapAdapterId));
 }
Ejemplo n.º 7
0
 public IPAddress LocalIpAddress()
 {
     return(NetworkUtil.GetBestInterfaceIp());
 }
Ejemplo n.º 8
0
 public IPAddress LocalIpAddress()
 {
     return(NetworkUtil.GetBestInterfaceIp(_config.GetHardwareId(_serviceSettings.OpenVpnAdapter)));
 }