Restrict the list of available Ethernet/TAP adapters. Fixes #352.

This commit is contained in:
grossmj 2018-03-15 16:33:23 +07:00
parent fb3bcf3b8f
commit 08493871a5
3 changed files with 12 additions and 1 deletions

View File

@ -39,6 +39,9 @@ user = gns3
; Password for HTTP authentication. ; Password for HTTP authentication.
password = gns3 password = gns3
; Only allow these interfaces to be used by GNS3, for the Cloud node for example (Linux/OSX only)
allowed_interfaces = eth0,eth1
[VPCS] [VPCS]
; VPCS executable location, default: search in PATH ; VPCS executable location, default: search in PATH
;vpcs_path = vpcs ;vpcs_path = vpcs

View File

@ -110,7 +110,7 @@ class Cloud(BaseNode):
if ports != self._ports_mapping: if ports != self._ports_mapping:
if len(self._nios) > 0: if len(self._nios) > 0:
raise NodeError("Can't modify a cloud that is already connected.") raise NodeError("Cannot modify a cloud that is already connected.")
port_number = 0 port_number = 0
for port in ports: for port in ports:

View File

@ -23,6 +23,8 @@ import socket
import struct import struct
import psutil import psutil
from gns3server.config import Config
if psutil.version_info < (3, 0, 0): if psutil.version_info < (3, 0, 0):
raise Exception("psutil version should >= 3.0.0. If you are under Ubuntu/Debian install gns3 via apt instead of pip") raise Exception("psutil version should >= 3.0.0. If you are under Ubuntu/Debian install gns3 via apt instead of pip")
@ -198,8 +200,14 @@ def interfaces():
results = [] results = []
if not sys.platform.startswith("win"): if not sys.platform.startswith("win"):
allowed_interfaces = Config.instance().get_section_config("Server").get("allowed_interfaces", None)
if allowed_interfaces:
allowed_interfaces = allowed_interfaces.split(',')
net_if_addrs = psutil.net_if_addrs() net_if_addrs = psutil.net_if_addrs()
for interface in sorted(net_if_addrs.keys()): for interface in sorted(net_if_addrs.keys()):
if allowed_interfaces and interface not in allowed_interfaces:
log.warning("Interface '{}' is not allowed to be used on this server".format(interface))
continue
ip_address = "" ip_address = ""
mac_address = "" mac_address = ""
netmask = "" netmask = ""