Skip to content
Snippets Groups Projects
Commit 823bd4bd authored by Guillaume Valadon's avatar Guillaume Valadon Committed by Guillaume Valadon
Browse files

Unit tests fixed to test Route() methods on Windows

parent b368c0d8
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ from scapy.consts import LOOPBACK_NAME ...@@ -12,6 +12,7 @@ from scapy.consts import LOOPBACK_NAME
from scapy.utils import atol,ltoa,itom from scapy.utils import atol,ltoa,itom
from scapy.config import conf from scapy.config import conf
from scapy.error import Scapy_Exception,warning from scapy.error import Scapy_Exception,warning
from scapy.arch import WINDOWS
############################## ##############################
## Routing/Interfaces stuff ## ## Routing/Interfaces stuff ##
...@@ -89,7 +90,10 @@ class Route: ...@@ -89,7 +90,10 @@ class Route:
for i, route in enumerate(self.routes): for i, route in enumerate(self.routes):
net, msk, gw, iface, addr = route net, msk, gw, iface, addr = route
if iface != iff: if WINDOWS:
if iff.guid != iface.guid:
continue
elif iff != iface:
continue continue
if gw == '0.0.0.0': if gw == '0.0.0.0':
self.routes[i] = (the_net,the_msk,gw,iface,the_addr) self.routes[i] = (the_net,the_msk,gw,iface,the_addr)
...@@ -103,8 +107,12 @@ class Route: ...@@ -103,8 +107,12 @@ class Route:
self.invalidate_cache() self.invalidate_cache()
new_routes=[] new_routes=[]
for rt in self.routes: for rt in self.routes:
if rt[3] != iff: if WINDOWS:
new_routes.append(rt) if iff.guid == rt[3].guid:
continue
elif iff == rt[3]:
continue
new_routes.append(rt)
self.routes=new_routes self.routes=new_routes
def ifadd(self, iff, addr): def ifadd(self, iff, addr):
...@@ -157,9 +165,15 @@ class Route: ...@@ -157,9 +165,15 @@ class Route:
def get_if_bcast(self, iff): def get_if_bcast(self, iff):
for net, msk, gw, iface, addr in self.routes: for net, msk, gw, iface, addr in self.routes:
if (iff == iface and net != 0L): if net == 0:
bcast = atol(addr)|(~msk&0xffffffffL); # FIXME: check error in atol() continue
return ltoa(bcast); if WINDOWS:
if iff.guid != iface.guid:
continue
elif iff != iface:
continue
bcast = atol(addr)|(~msk&0xffffffffL); # FIXME: check error in atol()
return ltoa(bcast)
warning("No broadcast address found for iface %s\n" % iff); warning("No broadcast address found for iface %s\n" % iff);
conf.route=Route() conf.route=Route()
......
...@@ -51,6 +51,8 @@ get_if_raw_addr(get_dummy_interface()) ...@@ -51,6 +51,8 @@ get_if_raw_addr(get_dummy_interface())
get_if_list() get_if_list()
get_if_raw_addr6(conf.iface6)
= Test read_routes6() - default output = Test read_routes6() - default output
routes6 = read_routes6() routes6 = read_routes6()
...@@ -7368,16 +7370,19 @@ in6_getscope("::1") == IPV6_ADDR_LOOPBACK ...@@ -7368,16 +7370,19 @@ in6_getscope("::1") == IPV6_ADDR_LOOPBACK
= make_route() = make_route()
r4 = Route() r4 = Route()
len_r4 = len(r4.routes) tmp_route = r4.make_route(host="10.12.13.14")
r4.make_route(host="10.12.13.14") == (168561934, 4294967295L, '0.0.0.0', LOOPBACK_NAME, '0.0.0.0') (tmp_route[0], tmp_route[1], tmp_route[2]) == (168561934, 4294967295L, '0.0.0.0')
r4.make_route(net="10.12.13.0/24") == (168561920, 4294967040L, '0.0.0.0', LOOPBACK_NAME, '0.0.0.0')
r4.make_route(net="10.12.0.0/16", dev=get_dummy_interface()) == (168558592, 4294901760L, '0.0.0.0', get_dummy_interface(), '0.0.0.0') tmp_route = r4.make_route(net="10.12.13.0/24")
(tmp_route[0], tmp_route[1], tmp_route[2]) == (168561920, 4294967040L, '0.0.0.0')
= add() & delt() = add() & delt()
r4.add(net="192.168.1.0/24", gw="1.2.3.4", dev=get_dummy_interface()) r4 = Route()
len_r4 = len(r4.routes)
r4.add(net="192.168.1.0/24", gw="1.2.3.4")
len(r4.routes) == len_r4 + 1 len(r4.routes) == len_r4 + 1
r4.delt(net="192.168.1.0/24", gw="1.2.3.4", dev=get_dummy_interface()) r4.delt(net="192.168.1.0/24", gw="1.2.3.4")
len(r4.routes) == len_r4 len(r4.routes) == len_r4
= ifchange() = ifchange()
...@@ -7393,10 +7398,16 @@ len(r4.routes) == len_r4 ...@@ -7393,10 +7398,16 @@ len(r4.routes) == len_r4
= ifadd() & get_if_bcast() = ifadd() & get_if_bcast()
r4 = Route()
len_r4 = len(r4.routes)
r4.ifadd(get_dummy_interface(), "1.2.3.4/24") r4.ifadd(get_dummy_interface(), "1.2.3.4/24")
len(r4.routes) == len_r4 +1
r4.get_if_bcast(get_dummy_interface()) == "1.2.3.255" r4.get_if_bcast(get_dummy_interface()) == "1.2.3.255"
r4.ifdel(get_dummy_interface()) r4.ifdel(get_dummy_interface())
print len(r4.routes), len_r4
len(r4.routes) == len_r4 len(r4.routes) == len_r4
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment