mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Don't contact ip6.yunohost if we can know right away that there's no IPv6 at all on the system
This commit is contained in:
parent
040bc1d09f
commit
61ef67252e
2 changed files with 18 additions and 5 deletions
|
@ -106,7 +106,7 @@ class IPDiagnoser(Diagnoser):
|
||||||
|
|
||||||
# If we are indeed connected in ipv4 or ipv6, we should find a default route
|
# If we are indeed connected in ipv4 or ipv6, we should find a default route
|
||||||
routes = check_output("ip -%s route" % protocol).split("\n")
|
routes = check_output("ip -%s route" % protocol).split("\n")
|
||||||
if not [r for r in routes if r.startswith("default")]:
|
if not any(r.startswith("default") for r in routes):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# We use the resolver file as a list of well-known, trustable (ie not google ;)) IPs that we can ping
|
# We use the resolver file as a list of well-known, trustable (ie not google ;)) IPs that we can ping
|
||||||
|
|
|
@ -18,10 +18,12 @@
|
||||||
along with this program; if not, see http://www.gnu.org/licenses
|
along with this program; if not, see http://www.gnu.org/licenses
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import logging
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import logging
|
||||||
|
|
||||||
from moulinette.utils.network import download_text
|
from moulinette.utils.network import download_text
|
||||||
|
from moulinette.utils.process import check_output
|
||||||
|
|
||||||
logger = logging.getLogger('yunohost.utils.network')
|
logger = logging.getLogger('yunohost.utils.network')
|
||||||
|
|
||||||
|
@ -36,6 +38,17 @@ def get_public_ip(protocol=4):
|
||||||
else:
|
else:
|
||||||
raise ValueError("invalid protocol version")
|
raise ValueError("invalid protocol version")
|
||||||
|
|
||||||
|
# We can know that ipv6 is not available directly if this file does not exists
|
||||||
|
if protocol == 6 and not os.path.exists("/proc/net/if_inet6"):
|
||||||
|
logger.debug("IPv6 appears not at all available on the system, so assuming there's no IP address for that version")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If we are indeed connected in ipv4 or ipv6, we should find a default route
|
||||||
|
routes = check_output("ip -%s route" % protocol).split("\n")
|
||||||
|
if not any(r.startswith("default") for r in routes):
|
||||||
|
logger.debug("No default route for IPv%s, so assuming there's no IP address for that version" % protocol)
|
||||||
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return download_text(url, timeout=30).strip()
|
return download_text(url, timeout=30).strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -47,7 +60,7 @@ def get_network_interfaces():
|
||||||
|
|
||||||
# Get network devices and their addresses (raw infos from 'ip addr')
|
# Get network devices and their addresses (raw infos from 'ip addr')
|
||||||
devices_raw = {}
|
devices_raw = {}
|
||||||
output = subprocess.check_output('ip addr show'.split())
|
output = check_output('ip addr show')
|
||||||
for d in re.split(r'^(?:[0-9]+: )', output, flags=re.MULTILINE):
|
for d in re.split(r'^(?:[0-9]+: )', output, flags=re.MULTILINE):
|
||||||
# Extract device name (1) and its addresses (2)
|
# Extract device name (1) and its addresses (2)
|
||||||
m = re.match(r'([^\s@]+)(?:@[\S]+)?: (.*)', d, flags=re.DOTALL)
|
m = re.match(r'([^\s@]+)(?:@[\S]+)?: (.*)', d, flags=re.DOTALL)
|
||||||
|
@ -62,7 +75,7 @@ def get_network_interfaces():
|
||||||
|
|
||||||
def get_gateway():
|
def get_gateway():
|
||||||
|
|
||||||
output = subprocess.check_output('ip route show'.split())
|
output = check_output('ip route show')
|
||||||
m = re.search(r'default via (.*) dev ([a-z]+[0-9]?)', output)
|
m = re.search(r'default via (.*) dev ([a-z]+[0-9]?)', output)
|
||||||
if not m:
|
if not m:
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Add table
Reference in a new issue