mirror of https://github.com/secdev/scapy.git
Merge pull request #871 from guedou/Issue_#614
Fix more specific routes processing
This commit is contained in:
commit
4372edb1d1
|
@ -165,7 +165,7 @@ def set_promisc(s,iff,val=1):
|
|||
s.setsockopt(SOL_PACKET, cmd, mreq)
|
||||
|
||||
|
||||
def get_alias_address(iface_name, ip_mask):
|
||||
def get_alias_address(iface_name, ip_mask, gw_str):
|
||||
"""
|
||||
Get the correct source IP address of an interface alias
|
||||
"""
|
||||
|
@ -208,7 +208,7 @@ def get_alias_address(iface_name, ip_mask):
|
|||
# Check if the source address is included in the network
|
||||
if (ifaddr & msk) == ip_mask:
|
||||
sck.close()
|
||||
return (ifaddr & msk, msk, "0.0.0.0", ifname,
|
||||
return (ifaddr & msk, msk, gw_str, ifname,
|
||||
scapy.utils.ltoa(ifaddr))
|
||||
|
||||
sck.close()
|
||||
|
@ -258,14 +258,17 @@ def read_routes():
|
|||
dst_int = socket.htonl(int(dst, 16)) & 0xffffffff
|
||||
msk_int = socket.htonl(int(msk, 16)) & 0xffffffff
|
||||
ifaddr_int = struct.unpack("!I", ifreq[20:24])[0]
|
||||
gw_str = scapy.utils.inet_ntoa(struct.pack("I", int(gw, 16)))
|
||||
|
||||
if ifaddr_int & msk_int != dst_int:
|
||||
tmp_route = get_alias_address(iff, dst_int)
|
||||
tmp_route = get_alias_address(iff, dst_int, gw_str)
|
||||
if tmp_route:
|
||||
routes.append(tmp_route)
|
||||
else:
|
||||
routes.append((dst_int, msk_int, gw_str, iff, ifaddr))
|
||||
|
||||
else:
|
||||
routes.append((dst_int, msk_int,
|
||||
scapy.utils.inet_ntoa(struct.pack("I", int(gw, 16))),
|
||||
iff, ifaddr))
|
||||
routes.append((dst_int, msk_int, gw_str, iff, ifaddr))
|
||||
|
||||
f.close()
|
||||
return routes
|
||||
|
|
|
@ -85,7 +85,7 @@ x is not None and ICMP in x and x[ICMP].type == 0
|
|||
#select.select([socket],[],[],2)
|
||||
#_flush_fd(socket.ins)
|
||||
|
||||
= Interface aliases
|
||||
= Interface aliases & sub-interfaces
|
||||
~ linux needs_root
|
||||
|
||||
import os
|
||||
|
@ -96,8 +96,18 @@ exit_status = os.system("ifconfig scapy0:0 inet 198.51.100.1/24 up")
|
|||
exit_status = os.system("ip addr show scapy0")
|
||||
print(get_if_list())
|
||||
conf.route.resync()
|
||||
exit_status = os.system("ip link del name dev scapy0")
|
||||
print(conf.route.routes)
|
||||
assert(conf.route.route("198.51.100.254") == ("scapy0", "198.51.100.1", "0.0.0.0"))
|
||||
route_alias = (3325256704, 4294967040, "0.0.0.0", "scapy0", "198.51.100.1")
|
||||
assert(route_alias in conf.route.routes)
|
||||
exit_status = os.system("ip link add link scapy0 name scapy0.42 type vlan id 42")
|
||||
exit_status = os.system("ip addr add 203.0.113.42/24 dev scapy0.42")
|
||||
exit_status = os.system("ip link set scapy0.42 up")
|
||||
exit_status = os.system("ip route add 192.0.2.43/32 via 203.0.113.41")
|
||||
print(get_if_list())
|
||||
conf.route.resync()
|
||||
print(conf.route.routes)
|
||||
assert(conf.route.route("192.0.2.43") == ("scapy0.42", "203.0.113.42", "203.0.113.41"))
|
||||
route_specific = (3221226027, 4294967295, "203.0.113.41", "scapy0.42", "203.0.113.42")
|
||||
assert(route_specific in conf.route.routes)
|
||||
exit_status = os.system("ip link del name dev scapy0")
|
||||
|
|
Loading…
Reference in New Issue