summaryrefslogtreecommitdiff
path: root/src/leap/base/checks.py
diff options
context:
space:
mode:
authorantialias <antialias@leap.se>2012-09-28 18:15:47 -0400
committerantialias <antialias@leap.se>2012-09-28 18:15:47 -0400
commit202345940e12d4633c5d46d5ed21c3a433573d48 (patch)
tree7ec77cca7a68c2acccf0c8ff02e5d9a42d0b5d74 /src/leap/base/checks.py
parent3fd7b55de96484e02accb991fb2c0c3ce0aa9883 (diff)
Added check that default route is tun0.
Diffstat (limited to 'src/leap/base/checks.py')
-rw-r--r--src/leap/base/checks.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/leap/base/checks.py b/src/leap/base/checks.py
index c5438b09..a775e162 100644
--- a/src/leap/base/checks.py
+++ b/src/leap/base/checks.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
+import logging
import platform
import ping
@@ -8,6 +9,7 @@ import requests
from leap.base import constants
from leap.base import exceptions
+logger = logging.getLogger(name=__name__)
class LeapNetworkChecker(object):
"""
@@ -22,6 +24,7 @@ class LeapNetworkChecker(object):
self.error = None # ?
# for MVS
+ checker.check_tunnel_default_interface()
checker.check_internet_connection()
checker.is_internet_up()
checker.ping_gateway()
@@ -40,11 +43,35 @@ class LeapNetworkChecker(object):
else:
error = "Provider server appears to be down."
raise exceptions.NoInternetConnection(error)
+ logger.debug('Network appears to be up.')
def is_internet_up(self):
iface, gateway = self.get_default_interface_gateway()
self.ping_gateway(self)
+ def check_tunnel_default_interface(self):
+ """
+ Raises an TunnelNotDefaultRouteError
+ (including when no routes are present)
+ """
+ if not platform.system() == "Linux":
+ raise NotImplementedError
+
+ f = open("/proc/net/route")
+ route_table = f.readlines()
+ f.close()
+ #toss out header
+ route_table.pop(0)
+
+ if not route_table:
+ raise exceptions.TunnelNotDefaultRouteError()
+
+ line = route_table.pop(0)
+ iface, destination = line.split('\t')[0:2]
+ if not destination == '00000000' or not iface == 'tun0':
+ raise exceptions.TunnelNotDefaultRouteError()
+
+
def get_default_interface_gateway(self):
"""only impletemented for linux so far."""
if not platform.system() == "Linux":