Skip to content

Commit a0ddbc3

Browse files
authored
Merge pull request #1172 from guedou/ipv6_route_ll
IPv6 use conf.iface when selecting the source link-local address
2 parents 46bf315 + f3a856d commit a0ddbc3

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

scapy/layers/inet6.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class IPv6(_IPv6GuessPayload, Packet, IPTools):
414414
DestIP6Field("dst", "::1") ]
415415

416416
def route(self):
417+
"""Used to select the L2 address"""
417418
dst = self.dst
418419
if isinstance(dst,Gen):
419420
dst = next(iter(dst))

scapy/route6.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ def route(self, dst, dev=None):
197197
dst = socket.getaddrinfo(savedst, None, socket.AF_INET6)[0][-1][0]
198198
# TODO : Check if name resolution went well
199199

200+
# Use the default interface while dealing with link-local addresses
201+
if dev is None and (in6_islladdr(dst) or in6_ismlladdr(dst)):
202+
dev = conf.iface
203+
200204
# Deal with dev-specific request for cache search
201205
k = dst
202206
if dev is not None:

test/linux.uts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,24 @@ assert(got_lo_device)
172172

173173
exit_status = os.system("ip link del dev scapy_lo")
174174
assert(exit_status == 0)
175+
176+
= IPv6 link-local address selection
177+
178+
from mock import patch
179+
bck_conf_route6_routes = conf.route6.routes
180+
conf.route6.routes = [('fe80::', 64, '::', 'scapy0', ['fe80::e039:91ff:fe79:1910'], 256)]
181+
bck_conf_iface = conf.iface
182+
conf.iface = "scapy0"
183+
with patch("scapy.layers.l2.get_if_hwaddr") as mgih:
184+
mgih.return_value = 'e2:39:91:79:19:10'
185+
p = Ether()/IPv6(dst="ff02::1")/ICMPv6NIQueryName(data="ff02::1")
186+
print(p.sprintf("%Ether.src% > %Ether.dst%\n%IPv6.src% > %IPv6.dst%"))
187+
ip6_ll_address = 'fe80::e039:91ff:fe79:1910'
188+
print(p[IPv6].src, ip6_ll_address)
189+
assert p[IPv6].src == ip6_ll_address
190+
mac_address = 'e2:39:91:79:19:10'
191+
print(p[Ether].src, mac_address)
192+
assert p[Ether].src == mac_address
193+
194+
conf.route6.routes = bck_conf_route6_routes
195+
conf.iface = bck_conf_iface

test/regression.uts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,8 @@ raw(defragment6(l)) == b'`\x00\x00\x00\x0f\xb4\x06@\x00\x00\x00\x00\x00\x00\x00\
34633463
+ Test Route6 class
34643464

34653465
= Route6 - Route6 flushing
3466+
conf_iface = conf.iface
3467+
conf.iface = "eth0"
34663468
conf.route6.routes=[
34673469
( '::1', 128, '::', 'lo', ['::1'], 1),
34683470
( 'fe80::20f:1fff:feca:4650', 128, '::', 'lo', ['::1'], 1)]
@@ -3480,6 +3482,7 @@ conf.route6.routes=[
34803482
( '::', 0, 'fe80::20f:34ff:fe8a:8aa1', 'eth0', ['2001:db8:0:4444:20f:1fff:feca:4650', '2002:db8:0:4444:20f:1fff:feca:4650'], 1)
34813483
]
34823484
conf.route6.route("2002::1") == ('eth0', '2002:db8:0:4444:20f:1fff:feca:4650', 'fe80::20f:34ff:fe8a:8aa1') and conf.route6.route("2001::1") == ('eth0', '2001:db8:0:4444:20f:1fff:feca:4650', 'fe80::20f:34ff:fe8a:8aa1') and conf.route6.route("fe80::20f:1fff:feab:4870") == ('eth0', 'fe80::20f:1fff:feca:4650', '::') and conf.route6.route("::1") == ('lo', '::1', '::') and conf.route6.route("::") == ('eth0', '2001:db8:0:4444:20f:1fff:feca:4650', 'fe80::20f:34ff:fe8a:8aa1') and conf.route6.route('ff00::') == ('eth0', '2001:db8:0:4444:20f:1fff:feca:4650', 'fe80::20f:34ff:fe8a:8aa1')
3485+
conf.iface = conf_iface
34833486
conf.route6.resync()
34843487
if not len(conf.route6.routes):
34853488
# IPv6 seems disabled. Force a route to ::1

0 commit comments

Comments
 (0)