Esempio n. 1
0
 public virtual Json FetchUrl(Json request)
 {
     return(null);
 }
Esempio n. 2
0
 public virtual void OnJsonNetworkInfo(Json jNetworkInfo)
 {
 }
Esempio n. 3
0
 public virtual void OnJsonRouteList(Json jRoutesList)
 {
 }
Esempio n. 4
0
        public Json Compute(ConnectionActive connectionActive)
        {
            Json jRoute = new Json();

            jRoute["address"].Value = Address.ToCIDR();

            if (Gateway == "vpn_gateway")
            {
                jRoute["interface"].Value = connectionActive.InterfaceId;
                IpAddresses vpnGateways = connectionActive.OpenVpnProfileWithPush.ExtractGateway();
                if (Address.IsV4)
                {
                    if (vpnGateways.OnlyIPv4.Count == 0)
                    {
                        Engine.Instance.Logs.LogWarning("Unable to compute route for " + Address.ToCIDR() + ": IPv4 VPN gateway not available.");
                        return(null);
                    }
                    else
                    {
                        jRoute["gateway"].Value = vpnGateways.OnlyIPv4.First.Address;
                    }
                }
                else if (Address.IsV6)
                {
                    if (vpnGateways.OnlyIPv6.Count == 0)
                    {
                        Engine.Instance.Logs.LogVerbose("Unable to compute route for " + Address.ToCIDR() + ": IPv6 VPN gateway not available.");
                        return(null);
                    }
                    else
                    {
                        jRoute["gateway"].Value = vpnGateways.OnlyIPv6.First.Address;
                    }
                }
                else
                {
                    return(null);
                }
            }
            else if (Gateway == "net_gateway")
            {
                if (Address.IsV4)
                {
                    IpAddress netGateway = Engine.Instance.GetDefaultGatewayIPv4();
                    if (netGateway == null)
                    {
                        Engine.Instance.Logs.LogWarning("Unable to compute route for " + Address.ToCIDR() + ": IPv4 Net gateway not available.");
                        return(null);
                    }
                    else
                    {
                        jRoute["gateway"].Value   = netGateway.Address;
                        jRoute["interface"].Value = Engine.Instance.GetDefaultInterfaceIPv4();
                    }
                }
                else if (Address.IsV6)
                {
                    IpAddress netGateway = Engine.Instance.GetDefaultGatewayIPv6();
                    if (netGateway == null)
                    {
                        Engine.Instance.Logs.LogVerbose("Unable to compute route for " + Address.ToCIDR() + ": IPv6 Net gateway not available.");
                        return(null);
                    }
                    else
                    {
                        jRoute["gateway"].Value   = netGateway.Address;
                        jRoute["interface"].Value = Engine.Instance.GetDefaultInterfaceIPv6();
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                // ClodoTemp: Unsupported on Windows for now, we need the interface.
                IpAddress ip = new IpAddress(Gateway);
                if (ip.Valid == false)
                {
                    Engine.Instance.Logs.LogWarning("Gateway " + Gateway + " invalid.");
                    return(null);
                }
                else if ((Address.IsV4) && (ip.IsV6))
                {
                    Engine.Instance.Logs.LogWarning("Gateway " + Gateway + " is IPv6 but used for IPv4 address.");
                    return(null);
                }
                else if ((Address.IsV6) && (ip.IsV4))
                {
                    Engine.Instance.Logs.LogWarning("Gateway " + Gateway + " is IPv4 but used for IPv6 address.");
                    return(null);
                }
                else
                {
                    jRoute["gateway"].Value = ip.Address;
                }
            }

            return(jRoute);
        }