From ca6f014207b87b8cfe80570446cede1aee2aca49 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 10 Nov 2016 14:46:25 +0100 Subject: [PATCH] Do not connect GNS3 to remote server via 169.254.X.X --- gns3server/controller/compute.py | 3 +++ tests/controller/test_compute.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index a5be84ce..70d4b0bd 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -601,6 +601,9 @@ class Compute: # Skip if no ip or no netmask (vbox when stopped set a null netmask) if len(this_interface["ip_address"]) == 0 or this_interface["netmask"] is None: continue + # Ignore 169.254 network because it's for Windows special purpose + if this_interface["ip_address"].startswith("169.254."): + continue this_network = ipaddress.ip_network("{}/{}".format(this_interface["ip_address"], this_interface["netmask"]), strict=False) diff --git a/tests/controller/test_compute.py b/tests/controller/test_compute.py index 12a07609..86f9a2cc 100644 --- a/tests/controller/test_compute.py +++ b/tests/controller/test_compute.py @@ -457,3 +457,29 @@ def test_get_ip_on_same_subnet(controller, async_run): ] with pytest.raises(ValueError): async_run(compute1.get_ip_on_same_subnet(compute2)) + + # Ignore 169.254 network because it's for Windows special purpose + compute2 = Compute("compute2", host="192.168.1.2", controller=controller) + compute1 = Compute("compute1", host="192.168.2.1", controller=controller) + compute1._interfaces_cache = [ + { + "ip_address": "127.0.0.1", + "netmask": "255.255.255.255" + }, + { + "ip_address": "169.254.1.1", + "netmask": "255.255.0.0" + }, + ] + compute2._interfaces_cache = [ + { + "ip_address": "127.0.0.1", + "netmask": "255.255.255.255" + }, + { + "ip_address": "169.254.2.1", + "netmask": "255.255.0.0" + }, + ] + with pytest.raises(ValueError): + assert async_run(compute1.get_ip_on_same_subnet(compute2))